aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile23
-rw-r--r--tools/accounting/Makefile1
-rw-r--r--tools/accounting/getdelays.c1
-rw-r--r--tools/arch/alpha/include/asm/barrier.h1
-rw-r--r--tools/arch/alpha/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/alpha/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/arc/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/arm/include/uapi/asm/kvm.h1
-rw-r--r--tools/arch/arm/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/arm/include/uapi/asm/perf_regs.h1
-rw-r--r--tools/arch/arm64/include/asm/barrier.h1
-rw-r--r--tools/arch/arm64/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/arm64/include/uapi/asm/kvm.h1
-rw-r--r--tools/arch/arm64/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/arm64/include/uapi/asm/perf_regs.h1
-rw-r--r--tools/arch/frv/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/frv/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/h8300/include/asm/bitsperlong.h1
-rw-r--r--tools/arch/h8300/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/hexagon/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/hexagon/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/ia64/include/asm/barrier.h1
-rw-r--r--tools/arch/ia64/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/ia64/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/m32r/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/m32r/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/microblaze/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/microblaze/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/mips/include/asm/barrier.h1
-rw-r--r--tools/arch/mips/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/mips/include/uapi/asm/kvm.h1
-rw-r--r--tools/arch/mips/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/mn10300/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/parisc/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/parisc/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/powerpc/include/asm/barrier.h1
-rw-r--r--tools/arch/powerpc/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/powerpc/include/uapi/asm/kvm.h1
-rw-r--r--tools/arch/powerpc/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/powerpc/include/uapi/asm/perf_regs.h1
-rw-r--r--tools/arch/s390/include/asm/barrier.h1
-rw-r--r--tools/arch/s390/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/s390/include/uapi/asm/kvm.h7
-rw-r--r--tools/arch/s390/include/uapi/asm/kvm_perf.h1
-rw-r--r--tools/arch/s390/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/s390/include/uapi/asm/sie.h1
-rw-r--r--tools/arch/score/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/score/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/sh/include/asm/barrier.h1
-rw-r--r--tools/arch/sh/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/sparc/include/asm/barrier.h1
-rw-r--r--tools/arch/sparc/include/asm/barrier_32.h1
-rw-r--r--tools/arch/sparc/include/asm/barrier_64.h1
-rw-r--r--tools/arch/sparc/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/sparc/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/tile/include/asm/barrier.h1
-rw-r--r--tools/arch/tile/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/tile/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/x86/include/asm/atomic.h3
-rw-r--r--tools/arch/x86/include/asm/barrier.h1
-rw-r--r--tools/arch/x86/include/asm/cmpxchg.h1
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h3
-rw-r--r--tools/arch/x86/include/asm/disabled-features.h4
-rw-r--r--tools/arch/x86/include/asm/rmwcc.h1
-rw-r--r--tools/arch/x86/include/asm/unistd_32.h1
-rw-r--r--tools/arch/x86/include/asm/unistd_64.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/bitsperlong.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/kvm.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/kvm_perf.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/mman.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/perf_regs.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/svm.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/unistd.h1
-rw-r--r--tools/arch/x86/include/uapi/asm/vmx.h1
-rw-r--r--tools/arch/x86/lib/memcpy_64.S4
-rw-r--r--tools/arch/x86/lib/memset_64.S1
-rw-r--r--tools/arch/xtensa/include/uapi/asm/mman.h1
-rw-r--r--tools/bpf/Makefile (renamed from tools/net/Makefile)19
-rw-r--r--tools/bpf/bpf_asm.c (renamed from tools/net/bpf_asm.c)0
-rw-r--r--tools/bpf/bpf_dbg.c (renamed from tools/net/bpf_dbg.c)0
-rw-r--r--tools/bpf/bpf_exp.l (renamed from tools/net/bpf_exp.l)0
-rw-r--r--tools/bpf/bpf_exp.y (renamed from tools/net/bpf_exp.y)0
-rw-r--r--tools/bpf/bpf_jit_disasm.c (renamed from tools/net/bpf_jit_disasm.c)3
-rw-r--r--tools/bpf/bpftool/Documentation/Makefile34
-rw-r--r--tools/bpf/bpftool/Documentation/bpftool-map.rst131
-rw-r--r--tools/bpf/bpftool/Documentation/bpftool-prog.rst150
-rw-r--r--tools/bpf/bpftool/Documentation/bpftool.rst56
-rw-r--r--tools/bpf/bpftool/Makefile92
-rw-r--r--tools/bpf/bpftool/bash-completion/bpftool354
-rw-r--r--tools/bpf/bpftool/common.c405
-rw-r--r--tools/bpf/bpftool/jit_disasm.c162
-rw-r--r--tools/bpf/bpftool/json_writer.c356
-rw-r--r--tools/bpf/bpftool/json_writer.h72
-rw-r--r--tools/bpf/bpftool/main.c331
-rw-r--r--tools/bpf/bpftool/main.h122
-rw-r--r--tools/bpf/bpftool/map.c899
-rw-r--r--tools/bpf/bpftool/prog.c672
-rw-r--r--tools/build/Makefile1
-rw-r--r--tools/build/Makefile.build1
-rw-r--r--tools/build/feature/Makefile1
-rw-r--r--tools/build/feature/test-all.c1
-rw-r--r--tools/build/feature/test-backtrace.c1
-rw-r--r--tools/build/feature/test-bionic.c1
-rw-r--r--tools/build/feature/test-bpf.c1
-rw-r--r--tools/build/feature/test-clang.cpp1
-rw-r--r--tools/build/feature/test-compile.c1
-rw-r--r--tools/build/feature/test-cplus-demangle.c1
-rw-r--r--tools/build/feature/test-cxx.cpp1
-rw-r--r--tools/build/feature/test-dwarf.c1
-rw-r--r--tools/build/feature/test-dwarf_getlocations.c1
-rw-r--r--tools/build/feature/test-get_cpuid.c1
-rw-r--r--tools/build/feature/test-glibc.c1
-rw-r--r--tools/build/feature/test-gtk2-infobar.c1
-rw-r--r--tools/build/feature/test-gtk2.c1
-rw-r--r--tools/build/feature/test-jvmti.c1
-rw-r--r--tools/build/feature/test-libaudit.c1
-rw-r--r--tools/build/feature/test-libbabeltrace.c1
-rw-r--r--tools/build/feature/test-libbfd.c1
-rw-r--r--tools/build/feature/test-libcrypto.c1
-rw-r--r--tools/build/feature/test-libdw-dwarf-unwind.c1
-rw-r--r--tools/build/feature/test-libelf-gelf_getnote.c1
-rw-r--r--tools/build/feature/test-libelf-getphdrnum.c1
-rw-r--r--tools/build/feature/test-libelf-getshdrstrndx.c1
-rw-r--r--tools/build/feature/test-libelf-mmap.c1
-rw-r--r--tools/build/feature/test-libelf.c1
-rw-r--r--tools/build/feature/test-libnuma.c1
-rw-r--r--tools/build/feature/test-libperl.c1
-rw-r--r--tools/build/feature/test-libpython-version.c1
-rw-r--r--tools/build/feature/test-libpython.c1
-rw-r--r--tools/build/feature/test-libslang.c1
-rw-r--r--tools/build/feature/test-libunwind-aarch64.c1
-rw-r--r--tools/build/feature/test-libunwind-arm.c1
-rw-r--r--tools/build/feature/test-libunwind-debug-frame-aarch64.c1
-rw-r--r--tools/build/feature/test-libunwind-debug-frame-arm.c1
-rw-r--r--tools/build/feature/test-libunwind-debug-frame.c1
-rw-r--r--tools/build/feature/test-libunwind-x86.c1
-rw-r--r--tools/build/feature/test-libunwind-x86_64.c1
-rw-r--r--tools/build/feature/test-libunwind.c1
-rw-r--r--tools/build/feature/test-llvm-version.cpp1
-rw-r--r--tools/build/feature/test-llvm.cpp1
-rw-r--r--tools/build/feature/test-lzma.c1
-rw-r--r--tools/build/feature/test-numa_num_possible_cpus.c1
-rw-r--r--tools/build/feature/test-pthread-attr-setaffinity-np.c1
-rw-r--r--tools/build/feature/test-sched_getcpu.c1
-rw-r--r--tools/build/feature/test-sdt.c1
-rw-r--r--tools/build/feature/test-stackprotector-all.c1
-rw-r--r--tools/build/feature/test-sync-compare-and-swap.c1
-rw-r--r--tools/build/feature/test-timerfd.c1
-rw-r--r--tools/build/feature/test-zlib.c1
-rw-r--r--tools/build/fixdep.c1
-rw-r--r--tools/build/tests/ex/Makefile1
-rw-r--r--tools/build/tests/ex/a.c1
-rw-r--r--tools/build/tests/ex/arch/e.c1
-rw-r--r--tools/build/tests/ex/arch/f.c1
-rw-r--r--tools/build/tests/ex/b.c1
-rw-r--r--tools/build/tests/ex/c.c1
-rw-r--r--tools/build/tests/ex/d.c1
-rw-r--r--tools/build/tests/ex/ex.c1
-rw-r--r--tools/build/tests/ex/inc.c1
-rwxr-xr-xtools/build/tests/run.sh1
-rw-r--r--tools/cgroup/Makefile1
-rw-r--r--tools/cgroup/cgroup_event_listener.c1
-rw-r--r--tools/firewire/Makefile1
-rw-r--r--tools/firewire/decode-fcp.c1
-rw-r--r--tools/firewire/list.h1
-rw-r--r--tools/firewire/nosy-dump.h1
-rw-r--r--tools/gpio/Makefile1
-rw-r--r--tools/gpio/gpio-utils.c17
-rw-r--r--tools/hv/Makefile1
-rwxr-xr-xtools/hv/hv_get_dhcp_info.sh1
-rwxr-xr-xtools/hv/hv_set_ifconfig.sh1
-rw-r--r--tools/hv/lsvmbus1
-rw-r--r--tools/iio/Makefile1
-rw-r--r--tools/include/asm-generic/atomic-gcc.h3
-rw-r--r--tools/include/asm-generic/bitops.h1
-rw-r--r--tools/include/asm-generic/bitops/__ffs.h1
-rw-r--r--tools/include/asm-generic/bitops/__fls.h1
-rw-r--r--tools/include/asm-generic/bitops/arch_hweight.h1
-rw-r--r--tools/include/asm-generic/bitops/atomic.h1
-rw-r--r--tools/include/asm-generic/bitops/const_hweight.h1
-rw-r--r--tools/include/asm-generic/bitops/find.h1
-rw-r--r--tools/include/asm-generic/bitops/fls.h1
-rw-r--r--tools/include/asm-generic/bitops/fls64.h1
-rw-r--r--tools/include/asm-generic/bitops/hweight.h1
-rw-r--r--tools/include/asm-generic/bitsperlong.h1
-rw-r--r--tools/include/asm-generic/hugetlb_encode.h34
-rw-r--r--tools/include/asm/alternative-asm.h1
-rw-r--r--tools/include/asm/atomic.h1
-rw-r--r--tools/include/asm/barrier.h1
-rw-r--r--tools/include/asm/bug.h1
-rw-r--r--tools/include/asm/export.h7
-rw-r--r--tools/include/linux/atomic.h1
-rw-r--r--tools/include/linux/bitmap.h1
-rw-r--r--tools/include/linux/bitops.h1
-rw-r--r--tools/include/linux/bug.h1
-rw-r--r--tools/include/linux/compiler-gcc.h1
-rw-r--r--tools/include/linux/compiler.h1
-rw-r--r--tools/include/linux/debug_locks.h1
-rw-r--r--tools/include/linux/err.h1
-rw-r--r--tools/include/linux/filter.h1
-rw-r--r--tools/include/linux/hardirq.h1
-rw-r--r--tools/include/linux/hashtable.h1
-rw-r--r--tools/include/linux/irqflags.h1
-rw-r--r--tools/include/linux/kallsyms.h1
-rw-r--r--tools/include/linux/kern_levels.h1
-rw-r--r--tools/include/linux/kernel.h1
-rw-r--r--tools/include/linux/kmemcheck.h9
-rw-r--r--tools/include/linux/list.h1
-rw-r--r--tools/include/linux/lockdep.h1
-rw-r--r--tools/include/linux/module.h1
-rw-r--r--tools/include/linux/poison.h6
-rw-r--r--tools/include/linux/rcu.h1
-rw-r--r--tools/include/linux/refcount.h1
-rw-r--r--tools/include/linux/spinlock.h1
-rw-r--r--tools/include/linux/stacktrace.h1
-rw-r--r--tools/include/linux/string.h1
-rw-r--r--tools/include/linux/stringify.h1
-rw-r--r--tools/include/linux/time64.h1
-rw-r--r--tools/include/linux/types.h1
-rw-r--r--tools/include/linux/unaligned/packed_struct.h1
-rw-r--r--tools/include/tools/be_byteshift.h1
-rw-r--r--tools/include/tools/endian.h1
-rw-r--r--tools/include/tools/le_byteshift.h1
-rw-r--r--tools/include/uapi/asm-generic/ioctls.h1
-rw-r--r--tools/include/uapi/asm-generic/mman-common.h16
-rw-r--r--tools/include/uapi/asm-generic/mman.h3
-rw-r--r--tools/include/uapi/drm/drm.h22
-rw-r--r--tools/include/uapi/drm/i915_drm.h52
-rw-r--r--tools/include/uapi/linux/bpf.h194
-rw-r--r--tools/include/uapi/linux/bpf_common.h1
-rw-r--r--tools/include/uapi/linux/fcntl.h1
-rw-r--r--tools/include/uapi/linux/hw_breakpoint.h1
-rw-r--r--tools/include/uapi/linux/kcmp.h27
-rw-r--r--tools/include/uapi/linux/kvm.h4
-rw-r--r--tools/include/uapi/linux/mman.h25
-rw-r--r--tools/include/uapi/linux/perf_event.h1
-rw-r--r--tools/include/uapi/linux/prctl.h200
-rw-r--r--tools/include/uapi/linux/sched.h1
-rw-r--r--tools/include/uapi/linux/stat.h1
-rw-r--r--tools/include/uapi/linux/vhost.h1
-rw-r--r--tools/include/uapi/sound/asound.h1
-rw-r--r--tools/kvm/kvm_stat/Makefile1
-rwxr-xr-xtools/kvm/kvm_stat/kvm_stat30
-rw-r--r--tools/laptop/dslm/Makefile1
-rw-r--r--tools/laptop/freefall/Makefile1
-rw-r--r--tools/leds/Makefile1
-rw-r--r--tools/leds/led_hw_brightness_mon.c1
-rw-r--r--tools/leds/uledmon.c1
-rw-r--r--tools/lib/api/Makefile1
-rw-r--r--tools/lib/api/cpu.c1
-rw-r--r--tools/lib/api/cpu.h1
-rw-r--r--tools/lib/api/debug-internal.h1
-rw-r--r--tools/lib/api/debug.c1
-rw-r--r--tools/lib/api/debug.h1
-rw-r--r--tools/lib/api/fd/array.h1
-rw-r--r--tools/lib/api/fs/fs.c1
-rw-r--r--tools/lib/api/fs/fs.h1
-rw-r--r--tools/lib/api/fs/tracing_path.c1
-rw-r--r--tools/lib/api/fs/tracing_path.h1
-rw-r--r--tools/lib/bpf/Makefile1
-rw-r--r--tools/lib/bpf/bpf.c89
-rw-r--r--tools/lib/bpf/bpf.h27
-rw-r--r--tools/lib/bpf/libbpf.c179
-rw-r--r--tools/lib/bpf/libbpf.h1
-rw-r--r--tools/lib/hweight.c1
-rw-r--r--tools/lib/lockdep/Makefile1
-rw-r--r--tools/lib/lockdep/common.c1
-rw-r--r--tools/lib/lockdep/include/liblockdep/common.h1
-rw-r--r--tools/lib/lockdep/include/liblockdep/mutex.h1
-rw-r--r--tools/lib/lockdep/include/liblockdep/rwlock.h1
-rw-r--r--tools/lib/lockdep/lockdep.c1
-rw-r--r--tools/lib/lockdep/preload.c1
-rwxr-xr-xtools/lib/lockdep/run_tests.sh1
-rw-r--r--tools/lib/lockdep/tests/AA.c1
-rw-r--r--tools/lib/lockdep/tests/ABA.c1
-rw-r--r--tools/lib/lockdep/tests/ABBA.c1
-rw-r--r--tools/lib/lockdep/tests/ABBA_2threads.c1
-rw-r--r--tools/lib/lockdep/tests/ABBCCA.c1
-rw-r--r--tools/lib/lockdep/tests/ABBCCDDA.c1
-rw-r--r--tools/lib/lockdep/tests/ABCABC.c1
-rw-r--r--tools/lib/lockdep/tests/ABCDBCDA.c1
-rw-r--r--tools/lib/lockdep/tests/ABCDBDDA.c1
-rw-r--r--tools/lib/lockdep/tests/WW.c1
-rw-r--r--tools/lib/lockdep/tests/common.h1
-rw-r--r--tools/lib/lockdep/tests/unlock_balance.c1
-rw-r--r--tools/lib/str_error_r.c1
-rw-r--r--tools/lib/string.c1
-rw-r--r--tools/lib/subcmd/Makefile1
-rw-r--r--tools/lib/subcmd/exec-cmd.c1
-rw-r--r--tools/lib/subcmd/exec-cmd.h1
-rw-r--r--tools/lib/subcmd/help.c1
-rw-r--r--tools/lib/subcmd/help.h1
-rw-r--r--tools/lib/subcmd/pager.c1
-rw-r--r--tools/lib/subcmd/pager.h1
-rw-r--r--tools/lib/subcmd/parse-options.c1
-rw-r--r--tools/lib/subcmd/parse-options.h1
-rw-r--r--tools/lib/subcmd/run-command.c1
-rw-r--r--tools/lib/subcmd/run-command.h1
-rw-r--r--tools/lib/subcmd/sigchain.c1
-rw-r--r--tools/lib/subcmd/sigchain.h1
-rw-r--r--tools/lib/subcmd/subcmd-config.c1
-rw-r--r--tools/lib/subcmd/subcmd-config.h1
-rw-r--r--tools/lib/subcmd/subcmd-util.h1
-rw-r--r--tools/lib/symbol/kallsyms.c1
-rw-r--r--tools/lib/symbol/kallsyms.h1
-rw-r--r--tools/lib/traceevent/Makefile1
-rw-r--r--tools/lib/traceevent/parse-filter.c6
-rw-r--r--tools/lib/traceevent/plugin_cfg80211.c1
-rw-r--r--tools/lib/traceevent/plugin_scsi.c1
-rw-r--r--tools/lib/traceevent/plugin_xen.c1
-rw-r--r--tools/lib/vsprintf.c1
-rwxr-xr-xtools/nfsd/inject_fault.sh1
-rw-r--r--tools/objtool/.gitignore2
-rw-r--r--tools/objtool/Documentation/stack-validation.txt6
-rw-r--r--tools/objtool/Makefile23
-rw-r--r--tools/objtool/arch/x86/Build10
-rw-r--r--tools/objtool/arch/x86/decode.c23
-rw-r--r--tools/objtool/arch/x86/include/asm/inat.h (renamed from tools/objtool/arch/x86/insn/inat.h)12
-rw-r--r--tools/objtool/arch/x86/include/asm/inat_types.h (renamed from tools/objtool/arch/x86/insn/inat_types.h)0
-rw-r--r--tools/objtool/arch/x86/include/asm/insn.h (renamed from tools/objtool/arch/x86/insn/insn.h)2
-rw-r--r--tools/objtool/arch/x86/include/asm/orc_types.h (renamed from tools/objtool/orc_types.h)0
-rw-r--r--tools/objtool/arch/x86/lib/inat.c (renamed from tools/objtool/arch/x86/insn/inat.c)2
-rw-r--r--tools/objtool/arch/x86/lib/insn.c (renamed from tools/objtool/arch/x86/insn/insn.c)4
-rw-r--r--tools/objtool/arch/x86/lib/x86-opcode-map.txt (renamed from tools/objtool/arch/x86/insn/x86-opcode-map.txt)0
-rw-r--r--tools/objtool/arch/x86/tools/gen-insn-attr-x86.awk (renamed from tools/objtool/arch/x86/insn/gen-insn-attr-x86.awk)1
-rw-r--r--tools/objtool/check.c59
-rw-r--r--tools/objtool/elf.c33
-rw-r--r--tools/objtool/objtool.c6
-rw-r--r--tools/objtool/orc.h2
-rwxr-xr-xtools/objtool/sync-check.sh29
-rw-r--r--tools/pci/pcitest.sh1
-rw-r--r--tools/pcmcia/Makefile1
-rw-r--r--tools/perf/Documentation/perf-list.txt11
-rw-r--r--tools/perf/Documentation/perf-record.txt6
-rw-r--r--tools/perf/Documentation/perf-report.txt3
-rw-r--r--tools/perf/Documentation/perf-sched.txt8
-rw-r--r--tools/perf/Documentation/perf-script.txt11
-rw-r--r--tools/perf/Documentation/perf-stat.txt7
-rw-r--r--tools/perf/Documentation/perf-top.txt3
-rw-r--r--tools/perf/MANIFEST87
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/Makefile.config6
-rw-r--r--tools/perf/Makefile.perf39
-rw-r--r--tools/perf/arch/arm/annotate/instructions.c4
-rw-r--r--tools/perf/arch/arm/include/dwarf-regs-table.h1
-rw-r--r--tools/perf/arch/arm/include/perf_regs.h1
-rw-r--r--tools/perf/arch/arm/tests/dwarf-unwind.c1
-rw-r--r--tools/perf/arch/arm/tests/regs_load.S1
-rw-r--r--tools/perf/arch/arm/util/unwind-libdw.c1
-rw-r--r--tools/perf/arch/arm/util/unwind-libunwind.c1
-rw-r--r--tools/perf/arch/arm64/Makefile1
-rw-r--r--tools/perf/arch/arm64/annotate/instructions.c4
-rw-r--r--tools/perf/arch/arm64/include/dwarf-regs-table.h1
-rw-r--r--tools/perf/arch/arm64/include/perf_regs.h1
-rw-r--r--tools/perf/arch/arm64/tests/dwarf-unwind.c1
-rw-r--r--tools/perf/arch/arm64/tests/regs_load.S1
-rw-r--r--tools/perf/arch/arm64/util/unwind-libunwind.c1
-rw-r--r--tools/perf/arch/common.c1
-rw-r--r--tools/perf/arch/common.h1
-rw-r--r--tools/perf/arch/powerpc/Makefile1
-rw-r--r--tools/perf/arch/powerpc/annotate/instructions.c5
-rw-r--r--tools/perf/arch/powerpc/include/arch-tests.h1
-rw-r--r--tools/perf/arch/powerpc/include/dwarf-regs-table.h1
-rw-r--r--tools/perf/arch/powerpc/include/perf_regs.h1
-rw-r--r--tools/perf/arch/powerpc/tests/arch-tests.c1
-rw-r--r--tools/perf/arch/powerpc/tests/dwarf-unwind.c1
-rw-r--r--tools/perf/arch/powerpc/tests/regs_load.S1
-rw-r--r--tools/perf/arch/powerpc/util/book3s_hcalls.h1
-rw-r--r--tools/perf/arch/powerpc/util/book3s_hv_exits.h1
-rw-r--r--tools/perf/arch/powerpc/util/header.c1
-rw-r--r--tools/perf/arch/powerpc/util/kvm-stat.c1
-rw-r--r--tools/perf/arch/powerpc/util/perf_regs.c1
-rw-r--r--tools/perf/arch/powerpc/util/unwind-libdw.c1
-rw-r--r--tools/perf/arch/s390/annotate/instructions.c5
-rw-r--r--tools/perf/arch/s390/include/dwarf-regs-table.h72
-rw-r--r--tools/perf/arch/s390/include/perf_regs.h95
-rw-r--r--tools/perf/arch/s390/util/Build4
-rw-r--r--tools/perf/arch/s390/util/auxtrace.c118
-rw-r--r--tools/perf/arch/s390/util/dwarf-regs.c12
-rw-r--r--tools/perf/arch/s390/util/machine.c1
-rw-r--r--tools/perf/arch/s390/util/sym-handling.c29
-rw-r--r--tools/perf/arch/s390/util/unwind-libdw.c63
-rw-r--r--tools/perf/arch/sh/include/dwarf-regs-table.h1
-rw-r--r--tools/perf/arch/sparc/include/dwarf-regs-table.h1
-rw-r--r--tools/perf/arch/x86/Makefile1
-rw-r--r--tools/perf/arch/x86/annotate/instructions.c15
-rwxr-xr-xtools/perf/arch/x86/entry/syscalls/syscalltbl.sh1
-rw-r--r--tools/perf/arch/x86/include/arch-tests.h2
-rw-r--r--tools/perf/arch/x86/include/dwarf-regs-table.h1
-rw-r--r--tools/perf/arch/x86/include/perf_regs.h1
-rw-r--r--tools/perf/arch/x86/tests/Build1
-rw-r--r--tools/perf/arch/x86/tests/arch-tests.c5
-rw-r--r--tools/perf/arch/x86/tests/dwarf-unwind.c1
-rw-r--r--tools/perf/arch/x86/tests/insn-x86-dat-32.c1
-rw-r--r--tools/perf/arch/x86/tests/insn-x86-dat-64.c1
-rw-r--r--tools/perf/arch/x86/tests/insn-x86-dat-src.c1
-rw-r--r--tools/perf/arch/x86/tests/insn-x86.c1
-rw-r--r--tools/perf/arch/x86/tests/intel-cqm.c1
-rw-r--r--tools/perf/arch/x86/tests/perf-time-to-tsc.c1
-rw-r--r--tools/perf/arch/x86/tests/rdpmc.c1
-rw-r--r--tools/perf/arch/x86/tests/regs_load.S1
-rw-r--r--tools/perf/arch/x86/util/group.c1
-rw-r--r--tools/perf/arch/x86/util/header.c1
-rw-r--r--tools/perf/arch/x86/util/kvm-stat.c1
-rw-r--r--tools/perf/arch/x86/util/perf_regs.c1
-rw-r--r--tools/perf/arch/x86/util/pmu.c1
-rw-r--r--tools/perf/arch/x86/util/tsc.c1
-rw-r--r--tools/perf/arch/x86/util/unwind-libdw.c1
-rw-r--r--tools/perf/arch/x86/util/unwind-libunwind.c1
-rw-r--r--tools/perf/arch/xtensa/include/dwarf-regs-table.h1
-rw-r--r--tools/perf/bench/bench.h1
-rw-r--r--tools/perf/bench/futex-hash.c1
-rw-r--r--tools/perf/bench/futex-lock-pi.c1
-rw-r--r--tools/perf/bench/futex-requeue.c1
-rw-r--r--tools/perf/bench/futex-wake-parallel.c1
-rw-r--r--tools/perf/bench/futex-wake.c1
-rw-r--r--tools/perf/bench/futex.h1
-rw-r--r--tools/perf/bench/mem-functions.c1
-rw-r--r--tools/perf/bench/mem-memcpy-arch.h1
-rw-r--r--tools/perf/bench/mem-memcpy-x86-64-asm-def.h1
-rw-r--r--tools/perf/bench/mem-memcpy-x86-64-asm.S1
-rw-r--r--tools/perf/bench/mem-memset-arch.h1
-rw-r--r--tools/perf/bench/mem-memset-x86-64-asm-def.h1
-rw-r--r--tools/perf/bench/mem-memset-x86-64-asm.S1
-rw-r--r--tools/perf/bench/numa.c1
-rw-r--r--tools/perf/bench/sched-messaging.c1
-rw-r--r--tools/perf/bench/sched-pipe.c1
-rw-r--r--tools/perf/builtin-annotate.c11
-rw-r--r--tools/perf/builtin-bench.c1
-rw-r--r--tools/perf/builtin-buildid-cache.c9
-rw-r--r--tools/perf/builtin-buildid-list.c17
-rw-r--r--tools/perf/builtin-c2c.c12
-rw-r--r--tools/perf/builtin-config.c23
-rw-r--r--tools/perf/builtin-data.c1
-rw-r--r--tools/perf/builtin-diff.c19
-rw-r--r--tools/perf/builtin-evlist.c13
-rw-r--r--tools/perf/builtin-help.c1
-rw-r--r--tools/perf/builtin-inject.c37
-rw-r--r--tools/perf/builtin-kmem.c14
-rw-r--r--tools/perf/builtin-kvm.c19
-rw-r--r--tools/perf/builtin-list.c8
-rw-r--r--tools/perf/builtin-lock.c13
-rw-r--r--tools/perf/builtin-mem.c14
-rw-r--r--tools/perf/builtin-record.c160
-rw-r--r--tools/perf/builtin-report.c15
-rw-r--r--tools/perf/builtin-sched.c29
-rw-r--r--tools/perf/builtin-script.c715
-rw-r--r--tools/perf/builtin-stat.c121
-rw-r--r--tools/perf/builtin-timechart.c18
-rw-r--r--tools/perf/builtin-top.c13
-rw-r--r--tools/perf/builtin-trace.c86
-rw-r--r--tools/perf/builtin-version.c1
-rw-r--r--tools/perf/builtin.h1
-rwxr-xr-xtools/perf/check-headers.sh8
-rw-r--r--tools/perf/jvmti/jvmti_agent.h1
-rw-r--r--tools/perf/jvmti/libjvmti.c1
-rw-r--r--tools/perf/perf-archive.sh1
-rw-r--r--tools/perf/perf-completion.sh1
-rw-r--r--tools/perf/perf-read-vdso.c1
-rw-r--r--tools/perf/perf-sys.h1
-rw-r--r--tools/perf/perf.c1
-rw-r--r--tools/perf/perf.h2
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwell/bdw-metrics.json164
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellde/bdwde-metrics.json164
-rw-r--r--tools/perf/pmu-events/arch/x86/broadwellx/bdx-metrics.json164
-rw-r--r--tools/perf/pmu-events/arch/x86/goldmontplus/cache.json1453
-rw-r--r--tools/perf/pmu-events/arch/x86/goldmontplus/frontend.json62
-rw-r--r--tools/perf/pmu-events/arch/x86/goldmontplus/memory.json38
-rw-r--r--tools/perf/pmu-events/arch/x86/goldmontplus/other.json98
-rw-r--r--tools/perf/pmu-events/arch/x86/goldmontplus/pipeline.json544
-rw-r--r--tools/perf/pmu-events/arch/x86/goldmontplus/virtual-memory.json218
-rw-r--r--tools/perf/pmu-events/arch/x86/haswell/hsw-metrics.json158
-rw-r--r--tools/perf/pmu-events/arch/x86/haswellx/hsx-metrics.json158
-rw-r--r--tools/perf/pmu-events/arch/x86/ivybridge/ivb-metrics.json164
-rw-r--r--tools/perf/pmu-events/arch/x86/ivytown/ivt-metrics.json164
-rw-r--r--tools/perf/pmu-events/arch/x86/jaketown/jkt-metrics.json140
-rw-r--r--tools/perf/pmu-events/arch/x86/mapfile.csv1
-rw-r--r--tools/perf/pmu-events/arch/x86/sandybridge/snb-metrics.json140
-rw-r--r--tools/perf/pmu-events/arch/x86/skylake/skl-metrics.json164
-rw-r--r--tools/perf/pmu-events/arch/x86/skylakex/skx-metrics.json164
-rw-r--r--tools/perf/pmu-events/jevents.c24
-rw-r--r--tools/perf/pmu-events/jevents.h3
-rw-r--r--tools/perf/pmu-events/jsmn.h1
-rw-r--r--tools/perf/pmu-events/json.h1
-rw-r--r--tools/perf/pmu-events/pmu-events.h2
-rwxr-xr-xtools/perf/python/tracepoint.py1
-rw-r--r--tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL1
-rwxr-xr-xtools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py1
-rw-r--r--tools/perf/scripts/python/event_analyzing_sample.py1
-rwxr-xr-xtools/perf/scripts/python/net_dropmonitor.py1
-rw-r--r--tools/perf/scripts/python/netdev-times.py1
-rwxr-xr-xtools/perf/scripts/python/stackcollapse.py1
-rw-r--r--tools/perf/scripts/python/stat-cpi.py1
-rw-r--r--tools/perf/tests/attr.c3
-rw-r--r--tools/perf/tests/attr.py7
-rw-r--r--tools/perf/tests/attr/base-record2
-rw-r--r--tools/perf/tests/attr/test-record-group1
-rw-r--r--tools/perf/tests/attr/test-record-group-sampling2
-rw-r--r--tools/perf/tests/attr/test-record-group11
-rw-r--r--tools/perf/tests/attr/test-stat-C01
-rw-r--r--tools/perf/tests/attr/test-stat-basic1
-rw-r--r--tools/perf/tests/attr/test-stat-default4
-rw-r--r--tools/perf/tests/attr/test-stat-detailed-18
-rw-r--r--tools/perf/tests/attr/test-stat-detailed-213
-rw-r--r--tools/perf/tests/attr/test-stat-detailed-313
-rw-r--r--tools/perf/tests/attr/test-stat-group2
-rw-r--r--tools/perf/tests/attr/test-stat-group12
-rw-r--r--tools/perf/tests/attr/test-stat-no-inherit1
-rw-r--r--tools/perf/tests/backward-ring-buffer.c1
-rw-r--r--tools/perf/tests/bitmap.c1
-rw-r--r--tools/perf/tests/bp_signal.c1
-rw-r--r--tools/perf/tests/bp_signal_overflow.c1
-rw-r--r--tools/perf/tests/builtin-test.c2
-rw-r--r--tools/perf/tests/clang.c1
-rw-r--r--tools/perf/tests/code-reading.c1
-rw-r--r--tools/perf/tests/cpumap.c1
-rw-r--r--tools/perf/tests/dso-data.c1
-rw-r--r--tools/perf/tests/dwarf-unwind.c1
-rw-r--r--tools/perf/tests/event-times.c1
-rw-r--r--tools/perf/tests/event_update.c1
-rw-r--r--tools/perf/tests/evsel-roundtrip-name.c1
-rw-r--r--tools/perf/tests/evsel-tp-sched.c1
-rw-r--r--tools/perf/tests/expr.c1
-rw-r--r--tools/perf/tests/fdarray.c1
-rw-r--r--tools/perf/tests/hists_common.c1
-rw-r--r--tools/perf/tests/hists_common.h1
-rw-r--r--tools/perf/tests/hists_cumulate.c1
-rw-r--r--tools/perf/tests/hists_filter.c1
-rw-r--r--tools/perf/tests/hists_link.c1
-rw-r--r--tools/perf/tests/hists_output.c1
-rw-r--r--tools/perf/tests/is_printable_array.c1
-rw-r--r--tools/perf/tests/keep-tracking.c1
-rw-r--r--tools/perf/tests/kmod-path.c1
-rw-r--r--tools/perf/tests/llvm.c1
-rw-r--r--tools/perf/tests/llvm.h1
-rw-r--r--tools/perf/tests/mmap-basic.c1
-rw-r--r--tools/perf/tests/mmap-thread-lookup.c3
-rw-r--r--tools/perf/tests/openat-syscall-all-cpus.c1
-rw-r--r--tools/perf/tests/openat-syscall-tp-fields.c1
-rw-r--r--tools/perf/tests/openat-syscall.c1
-rw-r--r--tools/perf/tests/parse-events.c1
-rw-r--r--tools/perf/tests/parse-no-sample-id-all.c1
-rw-r--r--tools/perf/tests/perf-hooks.c1
-rw-r--r--tools/perf/tests/perf-record.c1
-rwxr-xr-xtools/perf/tests/perf-targz-src-pkg1
-rw-r--r--tools/perf/tests/pmu.c1
-rw-r--r--tools/perf/tests/python-use.c1
-rw-r--r--tools/perf/tests/sample-parsing.c1
-rw-r--r--tools/perf/tests/sdt.c1
-rwxr-xr-xtools/perf/tests/shell/trace+probe_libc_inet_pton.sh9
-rw-r--r--tools/perf/tests/stat.c1
-rw-r--r--tools/perf/tests/sw-clock.c1
-rw-r--r--tools/perf/tests/switch-tracking.c1
-rw-r--r--tools/perf/tests/task-exit.c1
-rw-r--r--tools/perf/tests/tests.h1
-rw-r--r--tools/perf/tests/thread-map.c1
-rw-r--r--tools/perf/tests/thread-mg-share.c1
-rw-r--r--tools/perf/tests/topology.c23
-rw-r--r--tools/perf/tests/unit_number__scnprintf.c1
-rw-r--r--tools/perf/tests/vmlinux-kallsyms.c1
-rw-r--r--tools/perf/trace/beauty/Build2
-rw-r--r--tools/perf/trace/beauty/beauty.h19
-rw-r--r--tools/perf/trace/beauty/eventfd.c1
-rw-r--r--tools/perf/trace/beauty/flock.c1
-rw-r--r--tools/perf/trace/beauty/futex_op.c1
-rw-r--r--tools/perf/trace/beauty/kcmp.c44
-rwxr-xr-xtools/perf/trace/beauty/kcmp_type.sh10
-rwxr-xr-xtools/perf/trace/beauty/madvise_behavior.sh10
-rw-r--r--tools/perf/trace/beauty/mmap.c39
-rw-r--r--tools/perf/trace/beauty/mode_t.c1
-rw-r--r--tools/perf/trace/beauty/msg_flags.c1
-rw-r--r--tools/perf/trace/beauty/open_flags.c1
-rw-r--r--tools/perf/trace/beauty/perf_event_open.c1
-rw-r--r--tools/perf/trace/beauty/pid.c1
-rw-r--r--tools/perf/trace/beauty/prctl.c82
-rwxr-xr-xtools/perf/trace/beauty/prctl_option.sh17
-rw-r--r--tools/perf/trace/beauty/sched_policy.c1
-rw-r--r--tools/perf/trace/beauty/seccomp.c1
-rw-r--r--tools/perf/trace/beauty/signum.c1
-rw-r--r--tools/perf/trace/beauty/socket_type.c1
-rw-r--r--tools/perf/trace/beauty/waitid_options.c1
-rw-r--r--tools/perf/ui/browser.c1
-rw-r--r--tools/perf/ui/browser.h1
-rw-r--r--tools/perf/ui/browsers/annotate.c1
-rw-r--r--tools/perf/ui/browsers/header.c1
-rw-r--r--tools/perf/ui/browsers/hists.c181
-rw-r--r--tools/perf/ui/browsers/hists.h1
-rw-r--r--tools/perf/ui/browsers/map.c1
-rw-r--r--tools/perf/ui/browsers/map.h1
-rw-r--r--tools/perf/ui/browsers/scripts.c1
-rw-r--r--tools/perf/ui/gtk/annotate.c1
-rw-r--r--tools/perf/ui/gtk/browser.c1
-rw-r--r--tools/perf/ui/gtk/gtk.h1
-rw-r--r--tools/perf/ui/gtk/helpline.c1
-rw-r--r--tools/perf/ui/gtk/hists.c1
-rw-r--r--tools/perf/ui/gtk/progress.c1
-rw-r--r--tools/perf/ui/gtk/setup.c1
-rw-r--r--tools/perf/ui/gtk/util.c1
-rw-r--r--tools/perf/ui/helpline.c1
-rw-r--r--tools/perf/ui/helpline.h1
-rw-r--r--tools/perf/ui/hist.c10
-rw-r--r--tools/perf/ui/keysyms.h1
-rw-r--r--tools/perf/ui/libslang.h1
-rw-r--r--tools/perf/ui/progress.c7
-rw-r--r--tools/perf/ui/progress.h13
-rw-r--r--tools/perf/ui/setup.c1
-rw-r--r--tools/perf/ui/stdio/hist.c78
-rw-r--r--tools/perf/ui/tui/helpline.c1
-rw-r--r--tools/perf/ui/tui/progress.c33
-rw-r--r--tools/perf/ui/tui/setup.c1
-rw-r--r--tools/perf/ui/tui/tui.h1
-rw-r--r--tools/perf/ui/tui/util.c1
-rw-r--r--tools/perf/ui/ui.h1
-rw-r--r--tools/perf/ui/util.c1
-rw-r--r--tools/perf/ui/util.h1
-rw-r--r--tools/perf/util/Build3
-rwxr-xr-xtools/perf/util/PERF-VERSION-GEN1
-rw-r--r--tools/perf/util/annotate.c22
-rw-r--r--tools/perf/util/annotate.h1
-rw-r--r--tools/perf/util/auxtrace.c4
-rw-r--r--tools/perf/util/auxtrace.h4
-rw-r--r--tools/perf/util/block-range.c1
-rw-r--r--tools/perf/util/block-range.h1
-rw-r--r--tools/perf/util/bpf-loader.c1
-rw-r--r--tools/perf/util/bpf-loader.h1
-rw-r--r--tools/perf/util/bpf-prologue.c1
-rw-r--r--tools/perf/util/bpf-prologue.h1
-rw-r--r--tools/perf/util/build-id.c1
-rw-r--r--tools/perf/util/build-id.h1
-rw-r--r--tools/perf/util/c++/clang-c.h1
-rw-r--r--tools/perf/util/c++/clang-test.cpp1
-rw-r--r--tools/perf/util/c++/clang.cpp1
-rw-r--r--tools/perf/util/c++/clang.h1
-rw-r--r--tools/perf/util/cache.h1
-rw-r--r--tools/perf/util/callchain.c211
-rw-r--r--tools/perf/util/callchain.h7
-rw-r--r--tools/perf/util/cgroup.c1
-rw-r--r--tools/perf/util/cgroup.h1
-rw-r--r--tools/perf/util/cloexec.c1
-rw-r--r--tools/perf/util/cloexec.h1
-rw-r--r--tools/perf/util/color.c1
-rw-r--r--tools/perf/util/color.h1
-rw-r--r--tools/perf/util/comm.c19
-rw-r--r--tools/perf/util/comm.h1
-rw-r--r--tools/perf/util/compress.h1
-rw-r--r--tools/perf/util/config.c6
-rw-r--r--tools/perf/util/config.h1
-rw-r--r--tools/perf/util/counts.c1
-rw-r--r--tools/perf/util/counts.h1
-rw-r--r--tools/perf/util/cpumap.c1
-rw-r--r--tools/perf/util/cpumap.h1
-rw-r--r--tools/perf/util/ctype.c1
-rw-r--r--tools/perf/util/data-convert-bt.c12
-rw-r--r--tools/perf/util/data-convert-bt.h1
-rw-r--r--tools/perf/util/data-convert.h1
-rw-r--r--tools/perf/util/data.c96
-rw-r--r--tools/perf/util/data.h39
-rw-r--r--tools/perf/util/debug.c32
-rw-r--r--tools/perf/util/debug.h1
-rw-r--r--tools/perf/util/demangle-java.c1
-rw-r--r--tools/perf/util/demangle-java.h1
-rw-r--r--tools/perf/util/demangle-rust.c1
-rw-r--r--tools/perf/util/demangle-rust.h1
-rw-r--r--tools/perf/util/dso.c21
-rw-r--r--tools/perf/util/dso.h7
-rw-r--r--tools/perf/util/dump-insn.c1
-rw-r--r--tools/perf/util/dump-insn.h1
-rw-r--r--tools/perf/util/dwarf-regs.c1
-rw-r--r--tools/perf/util/env.c1
-rw-r--r--tools/perf/util/env.h1
-rw-r--r--tools/perf/util/event.c163
-rw-r--r--tools/perf/util/event.h4
-rw-r--r--tools/perf/util/evlist.c248
-rw-r--r--tools/perf/util/evlist.h78
-rw-r--r--tools/perf/util/evsel.c14
-rw-r--r--tools/perf/util/evsel.h5
-rw-r--r--tools/perf/util/evsel_fprintf.c38
-rw-r--r--tools/perf/util/expr.h1
-rw-r--r--tools/perf/util/find-vdso-map.c1
-rw-r--r--tools/perf/util/genelf.h1
-rwxr-xr-xtools/perf/util/generate-cmdlist.sh1
-rw-r--r--tools/perf/util/group.h1
-rw-r--r--tools/perf/util/header.c21
-rw-r--r--tools/perf/util/header.h1
-rw-r--r--tools/perf/util/help-unknown-cmd.c1
-rw-r--r--tools/perf/util/hist.c8
-rw-r--r--tools/perf/util/hist.h1
-rw-r--r--tools/perf/util/include/asm/asm-offsets.h1
-rw-r--r--tools/perf/util/include/asm/cpufeature.h1
-rw-r--r--tools/perf/util/include/asm/dwarf2.h1
-rw-r--r--tools/perf/util/include/asm/uaccess.h1
-rw-r--r--tools/perf/util/include/dwarf-regs.h1
-rw-r--r--tools/perf/util/include/linux/linkage.h1
-rw-r--r--tools/perf/util/intel-bts.c6
-rw-r--r--tools/perf/util/intel-pt-decoder/gen-insn-attr-x86.awk1
-rw-r--r--tools/perf/util/intel-pt.c6
-rw-r--r--tools/perf/util/intlist.h1
-rw-r--r--tools/perf/util/jit.h3
-rw-r--r--tools/perf/util/jitdump.c11
-rw-r--r--tools/perf/util/kvm-stat.h1
-rw-r--r--tools/perf/util/levenshtein.c1
-rw-r--r--tools/perf/util/levenshtein.h1
-rw-r--r--tools/perf/util/libunwind/arm64.c1
-rw-r--r--tools/perf/util/libunwind/x86_32.c1
-rw-r--r--tools/perf/util/llvm-utils.c1
-rw-r--r--tools/perf/util/llvm-utils.h1
-rw-r--r--tools/perf/util/lzma.c1
-rw-r--r--tools/perf/util/machine.c229
-rw-r--r--tools/perf/util/machine.h34
-rw-r--r--tools/perf/util/map.c35
-rw-r--r--tools/perf/util/map.h4
-rw-r--r--tools/perf/util/mem-events.c1
-rw-r--r--tools/perf/util/mem-events.h1
-rw-r--r--tools/perf/util/memswap.c1
-rw-r--r--tools/perf/util/memswap.h1
-rw-r--r--tools/perf/util/metricgroup.c490
-rw-r--r--tools/perf/util/metricgroup.h31
-rw-r--r--tools/perf/util/mmap.c352
-rw-r--r--tools/perf/util/mmap.h97
-rw-r--r--tools/perf/util/namespaces.c1
-rw-r--r--tools/perf/util/namespaces.h5
-rw-r--r--tools/perf/util/ordered-events.c1
-rw-r--r--tools/perf/util/ordered-events.h1
-rw-r--r--tools/perf/util/parse-branch-options.c1
-rw-r--r--tools/perf/util/parse-branch-options.h1
-rw-r--r--tools/perf/util/parse-events.c39
-rw-r--r--tools/perf/util/parse-events.h4
-rw-r--r--tools/perf/util/parse-events.l29
-rw-r--r--tools/perf/util/parse-regs-options.c1
-rw-r--r--tools/perf/util/parse-regs-options.h1
-rw-r--r--tools/perf/util/path.c1
-rw-r--r--tools/perf/util/path.h1
-rw-r--r--tools/perf/util/perf-hooks.c1
-rw-r--r--tools/perf/util/perf-hooks.h1
-rw-r--r--tools/perf/util/perf_regs.c1
-rw-r--r--tools/perf/util/perf_regs.h1
-rw-r--r--tools/perf/util/pmu.c112
-rw-r--r--tools/perf/util/pmu.h4
-rw-r--r--tools/perf/util/print_binary.c31
-rw-r--r--tools/perf/util/print_binary.h19
-rw-r--r--tools/perf/util/probe-event.h1
-rw-r--r--tools/perf/util/probe-file.c1
-rw-r--r--tools/perf/util/probe-file.h1
-rw-r--r--tools/perf/util/probe-finder.h1
-rw-r--r--tools/perf/util/pstack.c1
-rw-r--r--tools/perf/util/pstack.h1
-rw-r--r--tools/perf/util/python-ext-sources1
-rw-r--r--tools/perf/util/python.c1
-rw-r--r--tools/perf/util/quote.c1
-rw-r--r--tools/perf/util/quote.h1
-rw-r--r--tools/perf/util/rb_resort.h6
-rw-r--r--tools/perf/util/rblist.h1
-rw-r--r--tools/perf/util/record.c1
-rw-r--r--tools/perf/util/rwsem.c32
-rw-r--r--tools/perf/util/rwsem.h19
-rw-r--r--tools/perf/util/sane_ctype.h1
-rw-r--r--tools/perf/util/session.c49
-rw-r--r--tools/perf/util/session.h7
-rw-r--r--tools/perf/util/sort.c7
-rw-r--r--tools/perf/util/sort.h2
-rw-r--r--tools/perf/util/srcline.c297
-rw-r--r--tools/perf/util/srcline.h27
-rw-r--r--tools/perf/util/stat-shadow.c159
-rw-r--r--tools/perf/util/stat.c25
-rw-r--r--tools/perf/util/stat.h7
-rw-r--r--tools/perf/util/strbuf.c1
-rw-r--r--tools/perf/util/strbuf.h1
-rw-r--r--tools/perf/util/strfilter.c1
-rw-r--r--tools/perf/util/strfilter.h1
-rw-r--r--tools/perf/util/string.c1
-rw-r--r--tools/perf/util/string2.h1
-rw-r--r--tools/perf/util/strlist.h1
-rw-r--r--tools/perf/util/svghelper.h1
-rw-r--r--tools/perf/util/symbol-elf.c9
-rw-r--r--tools/perf/util/symbol-minimal.c1
-rw-r--r--tools/perf/util/symbol.c10
-rw-r--r--tools/perf/util/symbol.h6
-rw-r--r--tools/perf/util/symbol_fprintf.c1
-rw-r--r--tools/perf/util/syscalltbl.c2
-rw-r--r--tools/perf/util/syscalltbl.h1
-rw-r--r--tools/perf/util/target.h1
-rw-r--r--tools/perf/util/term.c1
-rw-r--r--tools/perf/util/term.h1
-rw-r--r--tools/perf/util/thread.c58
-rw-r--r--tools/perf/util/thread.h4
-rw-r--r--tools/perf/util/thread_map.c1
-rw-r--r--tools/perf/util/thread_map.h1
-rw-r--r--tools/perf/util/time-utils.c1
-rw-r--r--tools/perf/util/time-utils.h1
-rw-r--r--tools/perf/util/tool.h1
-rw-r--r--tools/perf/util/top.h2
-rw-r--r--tools/perf/util/trace-event-info.c1
-rw-r--r--tools/perf/util/trace-event-read.c1
-rw-r--r--tools/perf/util/trace-event.c1
-rw-r--r--tools/perf/util/trace-event.h1
-rw-r--r--tools/perf/util/trigger.h1
-rw-r--r--tools/perf/util/tsc.c1
-rw-r--r--tools/perf/util/tsc.h1
-rw-r--r--tools/perf/util/units.c1
-rw-r--r--tools/perf/util/units.h1
-rw-r--r--tools/perf/util/unwind-libdw.c1
-rw-r--r--tools/perf/util/unwind-libdw.h1
-rw-r--r--tools/perf/util/unwind-libunwind-local.c1
-rw-r--r--tools/perf/util/unwind-libunwind.c1
-rw-r--r--tools/perf/util/unwind.h1
-rw-r--r--tools/perf/util/usage.c1
-rw-r--r--tools/perf/util/util-cxx.h1
-rw-r--r--tools/perf/util/util.c17
-rw-r--r--tools/perf/util/util.h8
-rw-r--r--tools/perf/util/values.c1
-rw-r--r--tools/perf/util/values.h1
-rw-r--r--tools/perf/util/vdso.c5
-rw-r--r--tools/perf/util/vdso.h1
-rw-r--r--tools/perf/util/xyarray.c1
-rw-r--r--tools/perf/util/xyarray.h5
-rw-r--r--tools/perf/util/zlib.c2
-rw-r--r--tools/power/acpi/tools/acpidump/Makefile1
-rw-r--r--tools/power/acpi/tools/acpidump/apdump.c3
-rw-r--r--tools/power/acpi/tools/acpidump/apmain.c4
-rw-r--r--tools/power/cpupower/.gitignore3
-rw-r--r--tools/power/cpupower/Makefile8
-rw-r--r--tools/power/cpupower/bench/Makefile1
-rw-r--r--tools/power/cpupower/debug/i386/Makefile1
-rw-r--r--tools/power/cpupower/debug/kernel/Makefile1
-rw-r--r--tools/power/cpupower/debug/x86_64/Makefile1
-rw-r--r--tools/power/cpupower/lib/cpuidle.h1
-rw-r--r--tools/power/cpupower/lib/cpupower.h1
-rw-r--r--tools/power/cpupower/lib/cpupower_intern.h1
-rw-r--r--tools/power/cpupower/utils/builtin.h1
-rw-r--r--tools/power/cpupower/utils/cpufreq-info.c2
-rw-r--r--tools/power/cpupower/utils/cpuidle-set.c1
-rw-r--r--tools/power/cpupower/utils/helpers/amd.c1
-rw-r--r--tools/power/cpupower/utils/helpers/bitmask.c1
-rw-r--r--tools/power/cpupower/utils/helpers/bitmask.h1
-rw-r--r--tools/power/cpupower/utils/helpers/cpuid.c1
-rw-r--r--tools/power/cpupower/utils/helpers/misc.c1
-rw-r--r--tools/power/cpupower/utils/helpers/msr.c1
-rw-r--r--tools/power/cpupower/utils/helpers/pci.c1
-rw-r--r--tools/power/cpupower/utils/helpers/sysfs.h1
-rwxr-xr-xtools/power/cpupower/utils/version-gen.sh1
-rw-r--r--tools/power/pm-graph/Makefile1
-rw-r--r--tools/power/x86/turbostat/Makefile1
-rw-r--r--tools/power/x86/turbostat/turbostat.c10
-rw-r--r--tools/power/x86/x86_energy_perf_policy/Makefile1
-rw-r--r--tools/scripts/Makefile.arch1
-rw-r--r--tools/scripts/Makefile.include7
-rw-r--r--tools/spi/spidev_fdx.c1
-rw-r--r--tools/testing/fault-injection/failcmd.sh1
-rwxr-xr-xtools/testing/ktest/compare-ktest-sample.pl1
-rw-r--r--tools/testing/nvdimm/Kbuild2
-rw-r--r--tools/testing/nvdimm/Makefile1
-rw-r--r--tools/testing/nvdimm/config_check.c1
-rw-r--r--tools/testing/nvdimm/test/Kbuild1
-rw-r--r--tools/testing/nvdimm/test/nfit.c322
-rw-r--r--tools/testing/nvdimm/test/nfit_test.h52
-rw-r--r--tools/testing/radix-tree/Makefile1
-rw-r--r--tools/testing/radix-tree/linux.c1
-rw-r--r--tools/testing/radix-tree/linux/gfp.h1
-rw-r--r--tools/testing/radix-tree/linux/kernel.h1
-rw-r--r--tools/testing/radix-tree/linux/percpu.h1
-rw-r--r--tools/testing/radix-tree/linux/preempt.h1
-rw-r--r--tools/testing/radix-tree/linux/radix-tree.h1
-rw-r--r--tools/testing/radix-tree/linux/rcupdate.h1
-rw-r--r--tools/testing/radix-tree/linux/slab.h1
-rw-r--r--tools/testing/radix-tree/main.c1
-rw-r--r--tools/testing/radix-tree/multiorder.c2
-rw-r--r--tools/testing/radix-tree/regression.h1
-rw-r--r--tools/testing/radix-tree/regression1.c1
-rw-r--r--tools/testing/radix-tree/regression2.c1
-rw-r--r--tools/testing/radix-tree/regression3.c1
-rw-r--r--tools/testing/radix-tree/tag_check.c1
-rw-r--r--tools/testing/radix-tree/test.c1
-rw-r--r--tools/testing/radix-tree/test.h1
-rw-r--r--tools/testing/scatterlist/Makefile30
-rw-r--r--tools/testing/scatterlist/linux/mm.h125
-rw-r--r--tools/testing/scatterlist/main.c79
-rw-r--r--tools/testing/selftests/Makefile22
-rw-r--r--tools/testing/selftests/android/Makefile46
-rw-r--r--tools/testing/selftests/android/ion/.gitignore2
-rw-r--r--tools/testing/selftests/android/ion/Makefile16
-rw-r--r--tools/testing/selftests/android/ion/README101
-rw-r--r--tools/testing/selftests/android/ion/config4
-rw-r--r--tools/testing/selftests/android/ion/ion.h143
-rwxr-xr-xtools/testing/selftests/android/ion/ion_test.sh55
-rw-r--r--tools/testing/selftests/android/ion/ionapp_export.c135
-rw-r--r--tools/testing/selftests/android/ion/ionapp_import.c88
-rw-r--r--tools/testing/selftests/android/ion/ionutils.c259
-rw-r--r--tools/testing/selftests/android/ion/ionutils.h55
-rw-r--r--tools/testing/selftests/android/ion/ipcsocket.c227
-rw-r--r--tools/testing/selftests/android/ion/ipcsocket.h35
-rwxr-xr-xtools/testing/selftests/android/run.sh3
-rw-r--r--tools/testing/selftests/bpf/Makefile26
-rw-r--r--tools/testing/selftests/bpf/bpf_endian.h1
-rw-r--r--tools/testing/selftests/bpf/bpf_helpers.h70
-rw-r--r--tools/testing/selftests/bpf/bpf_util.h18
-rw-r--r--tools/testing/selftests/bpf/cgroup_helpers.c178
-rw-r--r--tools/testing/selftests/bpf/cgroup_helpers.h17
-rw-r--r--tools/testing/selftests/bpf/dev_cgroup.c60
-rw-r--r--tools/testing/selftests/bpf/include/uapi/linux/types.h1
-rw-r--r--tools/testing/selftests/bpf/sockmap_parse_prog.c3
-rw-r--r--tools/testing/selftests/bpf/sockmap_verdict_prog.c6
-rw-r--r--tools/testing/selftests/bpf/test_dev_cgroup.c93
-rwxr-xr-xtools/testing/selftests/bpf/test_kmod.sh1
-rw-r--r--tools/testing/selftests/bpf/test_lpm_map.c202
-rw-r--r--tools/testing/selftests/bpf/test_maps.c60
-rw-r--r--tools/testing/selftests/bpf/test_progs.c195
-rw-r--r--tools/testing/selftests/bpf/test_tag.c1
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c1504
-rw-r--r--tools/testing/selftests/bpf/test_verifier_log.c171
-rw-r--r--tools/testing/selftests/bpf/test_xdp_meta.c53
-rwxr-xr-xtools/testing/selftests/bpf/test_xdp_meta.sh51
-rw-r--r--tools/testing/selftests/breakpoints/Makefile9
-rw-r--r--tools/testing/selftests/breakpoints/breakpoint_test_arm64.c1
-rw-r--r--tools/testing/selftests/capabilities/Makefile1
-rw-r--r--tools/testing/selftests/capabilities/test_execve.c1
-rw-r--r--tools/testing/selftests/capabilities/validate_cap.c1
-rw-r--r--tools/testing/selftests/cpu-hotplug/Makefile1
-rw-r--r--tools/testing/selftests/cpu-hotplug/config1
-rwxr-xr-xtools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh1
-rw-r--r--tools/testing/selftests/cpufreq/Makefile1
-rwxr-xr-xtools/testing/selftests/cpufreq/cpu.sh1
-rwxr-xr-xtools/testing/selftests/cpufreq/cpufreq.sh1
-rwxr-xr-xtools/testing/selftests/cpufreq/governor.sh1
-rwxr-xr-xtools/testing/selftests/cpufreq/main.sh1
-rwxr-xr-xtools/testing/selftests/cpufreq/module.sh1
-rwxr-xr-xtools/testing/selftests/cpufreq/special-tests.sh1
-rwxr-xr-xtools/testing/selftests/drivers/gpu/drm_mm.sh1
-rwxr-xr-xtools/testing/selftests/drivers/gpu/i915.sh1
-rw-r--r--tools/testing/selftests/efivarfs/create-read.c1
-rwxr-xr-xtools/testing/selftests/efivarfs/efivarfs.sh1
-rw-r--r--tools/testing/selftests/efivarfs/open-unlink.c1
-rw-r--r--tools/testing/selftests/exec/Makefile1
-rw-r--r--tools/testing/selftests/exec/execveat.c27
-rw-r--r--tools/testing/selftests/filesystems/Makefile1
-rw-r--r--tools/testing/selftests/filesystems/dnotify_test.c1
-rwxr-xr-xtools/testing/selftests/firmware/fw_fallback.sh39
-rwxr-xr-xtools/testing/selftests/firmware/fw_filesystem.sh35
-rw-r--r--tools/testing/selftests/ftrace/Makefile1
-rw-r--r--tools/testing/selftests/ftrace/config4
-rwxr-xr-xtools/testing/selftests/ftrace/ftracetest7
-rw-r--r--tools/testing/selftests/ftrace/test.d/00basic/basic2.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/00basic/basic3.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/00basic/basic4.tc2
-rw-r--r--tools/testing/selftests/ftrace/test.d/event/event-enable.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/event/event-pid.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/event/toplevel-enable.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc6
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc5
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/func_traceonoff_triggers.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/instances/instance-event.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/instances/instance.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_maxactive.tc1
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/template1
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-eventonoff.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-filter.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-hist.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-multihist.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-stacktrace.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/trigger/trigger-traceonoff.tc3
-rw-r--r--tools/testing/selftests/futex/Makefile10
-rw-r--r--tools/testing/selftests/futex/functional/Makefile1
-rw-r--r--tools/testing/selftests/gpio/Makefile1
-rwxr-xr-xtools/testing/selftests/gpio/gpio-mockup-sysfs.sh1
-rwxr-xr-xtools/testing/selftests/gpio/gpio-mockup.sh1
-rw-r--r--tools/testing/selftests/ia64/Makefile1
-rw-r--r--tools/testing/selftests/intel_pstate/Makefile3
-rw-r--r--tools/testing/selftests/intel_pstate/aperf.c1
-rw-r--r--tools/testing/selftests/intel_pstate/msr.c1
-rwxr-xr-xtools/testing/selftests/intel_pstate/run.sh12
-rw-r--r--tools/testing/selftests/ipc/Makefile1
-rw-r--r--tools/testing/selftests/ipc/msgque.c1
-rw-r--r--tools/testing/selftests/kcmp/kcmp_test.c1
-rw-r--r--tools/testing/selftests/lib.mk52
-rwxr-xr-xtools/testing/selftests/lib/bitmap.sh1
-rwxr-xr-xtools/testing/selftests/lib/prime_numbers.sh1
-rwxr-xr-xtools/testing/selftests/lib/printf.sh1
-rw-r--r--tools/testing/selftests/locking/ww_mutex.sh1
-rw-r--r--tools/testing/selftests/media_tests/Makefile1
-rwxr-xr-xtools/testing/selftests/media_tests/bind_unbind_sample.sh1
-rwxr-xr-xtools/testing/selftests/media_tests/open_loop_test.sh1
-rw-r--r--tools/testing/selftests/membarrier/membarrier_test.c1
-rw-r--r--tools/testing/selftests/memfd/Makefile1
-rw-r--r--tools/testing/selftests/memfd/fuse_mnt.c1
-rw-r--r--tools/testing/selftests/memfd/fuse_test.c1
-rw-r--r--tools/testing/selftests/memfd/memfd_test.c5
-rwxr-xr-xtools/testing/selftests/memfd/run_fuse_test.sh1
-rwxr-xr-x[-rw-r--r--]tools/testing/selftests/memfd/run_tests.sh0
-rw-r--r--tools/testing/selftests/memory-hotplug/Makefile5
-rwxr-xr-xtools/testing/selftests/memory-hotplug/mem-on-off-test.sh1
-rw-r--r--tools/testing/selftests/mount/Makefile1
-rw-r--r--tools/testing/selftests/mount/unprivileged-remount-test.c1
-rw-r--r--tools/testing/selftests/mqueue/Makefile5
-rw-r--r--tools/testing/selftests/net/.gitignore1
-rw-r--r--tools/testing/selftests/net/Makefile7
-rw-r--r--tools/testing/selftests/net/msg_zerocopy.c2
-rwxr-xr-xtools/testing/selftests/net/netdevice.sh3
-rw-r--r--tools/testing/selftests/net/reuseaddr_conflict.c114
-rw-r--r--tools/testing/selftests/net/reuseport_bpf_cpu.c1
-rw-r--r--tools/testing/selftests/net/reuseport_bpf_numa.c1
-rw-r--r--tools/testing/selftests/net/reuseport_dualstack.c1
-rwxr-xr-xtools/testing/selftests/net/rtnetlink.sh271
-rwxr-xr-xtools/testing/selftests/net/run_afpackettests1
-rwxr-xr-xtools/testing/selftests/net/run_netsocktests1
-rw-r--r--tools/testing/selftests/net/socket.c1
-rwxr-xr-xtools/testing/selftests/net/test_bpf.sh1
-rw-r--r--tools/testing/selftests/networking/timestamping/Makefile1
-rw-r--r--tools/testing/selftests/networking/timestamping/hwtstamp_config.c1
-rw-r--r--tools/testing/selftests/networking/timestamping/rxtimestamp.c2
-rw-r--r--tools/testing/selftests/nsfs/owner.c1
-rw-r--r--tools/testing/selftests/nsfs/pidns.c1
-rw-r--r--tools/testing/selftests/powerpc/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/benchmarks/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/benchmarks/context_switch.c17
-rw-r--r--tools/testing/selftests/powerpc/cache_shape/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/copyloops/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/copyloops/asm/export.h1
-rw-r--r--tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h1
-rw-r--r--tools/testing/selftests/powerpc/copyloops/validate.c1
-rw-r--r--tools/testing/selftests/powerpc/dscr/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/dscr/dscr.h2
-rw-r--r--tools/testing/selftests/powerpc/dscr/dscr_default_test.c2
-rw-r--r--tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c6
-rw-r--r--tools/testing/selftests/powerpc/include/basic_asm.h1
-rw-r--r--tools/testing/selftests/powerpc/include/instructions.h1
-rw-r--r--tools/testing/selftests/powerpc/math/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/mm/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c1
-rw-r--r--tools/testing/selftests/powerpc/pmu/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/ptrace/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/signal/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/stringloops/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h1
-rw-r--r--tools/testing/selftests/powerpc/stringloops/memcmp.c1
-rw-r--r--tools/testing/selftests/powerpc/switch_endian/Makefile1
-rw-r--r--tools/testing/selftests/powerpc/switch_endian/check.S1
-rw-r--r--tools/testing/selftests/powerpc/switch_endian/common.h1
-rw-r--r--tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S1
-rw-r--r--tools/testing/selftests/powerpc/syscalls/ipc.h1
-rw-r--r--tools/testing/selftests/powerpc/tm/.gitignore1
-rw-r--r--tools/testing/selftests/powerpc/tm/Makefile4
-rw-r--r--tools/testing/selftests/powerpc/tm/tm-resched-dscr.c1
-rw-r--r--tools/testing/selftests/powerpc/tm/tm-syscall-asm.S1
-rw-r--r--tools/testing/selftests/powerpc/tm/tm-unavailable.c371
-rw-r--r--tools/testing/selftests/powerpc/tm/tm.h5
-rw-r--r--tools/testing/selftests/powerpc/vphn/test-vphn.c1
-rw-r--r--tools/testing/selftests/prctl/Makefile1
-rw-r--r--tools/testing/selftests/prctl/disable-tsc-ctxt-sw-stress-test.c1
-rw-r--r--tools/testing/selftests/prctl/disable-tsc-on-off-stress-test.c1
-rw-r--r--tools/testing/selftests/prctl/disable-tsc-test.c1
-rw-r--r--tools/testing/selftests/pstore/Makefile1
-rw-r--r--tools/testing/selftests/ptp/Makefile1
-rw-r--r--tools/testing/selftests/ptrace/peeksiginfo.c1
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/config_override.sh2
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/configcheck.sh2
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/configinit.sh2
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm-build.sh2
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh2
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm.sh4
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/parse-build.sh2
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/parse-torture.sh2
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/Makefile1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/include/linux/types.h1
-rwxr-xr-xtools/testing/selftests/rcutorture/formal/srcu-cbmc/modify_srcu.awk1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/assume.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h6
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/bug_on.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/combined_source.c1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/config.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/include_srcu.c1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/int_typedefs.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/locks.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/misc.c1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/percpu.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.c1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/simple_sync_srcu.c1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/workqueues.h1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/Makefile1
-rw-r--r--tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/test.c1
-rwxr-xr-xtools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/test_script.sh1
-rw-r--r--tools/testing/selftests/seccomp/.gitignore1
-rw-r--r--tools/testing/selftests/seccomp/Makefile19
-rw-r--r--tools/testing/selftests/seccomp/seccomp_benchmark.c99
-rw-r--r--tools/testing/selftests/seccomp/seccomp_bpf.c628
-rw-r--r--tools/testing/selftests/sigaltstack/sas.c5
-rw-r--r--tools/testing/selftests/splice/Makefile1
-rw-r--r--tools/testing/selftests/splice/default_file_splice_read.c1
-rwxr-xr-xtools/testing/selftests/splice/default_file_splice_read.sh1
-rwxr-xr-xtools/testing/selftests/static_keys/test_static_keys.sh1
-rw-r--r--tools/testing/selftests/sync/Makefile25
-rw-r--r--tools/testing/selftests/tc-testing/.gitignore1
-rw-r--r--tools/testing/selftests/tc-testing/creating-testcases/AddingTestCases.txt12
-rw-r--r--tools/testing/selftests/tc-testing/creating-testcases/example.json55
-rw-r--r--tools/testing/selftests/tc-testing/creating-testcases/template.json15
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/gact.json469
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/ife.json52
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/mirred.json223
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/police.json527
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/simple.json130
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/skbedit.json320
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json372
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/tests.json1165
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/filters/tests.json23
-rwxr-xr-xtools/testing/selftests/tc-testing/tdc.py52
-rwxr-xr-xtools/testing/selftests/tc-testing/tdc_batch.py62
-rw-r--r--tools/testing/selftests/tc-testing/tdc_config.py17
-rw-r--r--tools/testing/selftests/tc-testing/tdc_config_local_template.py23
-rw-r--r--tools/testing/selftests/tc-testing/tdc_helper.py5
-rw-r--r--tools/testing/selftests/timers/.gitignore2
-rw-r--r--tools/testing/selftests/timers/Makefile1
-rw-r--r--tools/testing/selftests/timers/set-timer-lat.c13
-rwxr-xr-xtools/testing/selftests/user/test_user_copy.sh1
-rw-r--r--tools/testing/selftests/vDSO/Makefile1
-rw-r--r--tools/testing/selftests/vDSO/vdso_test.c19
-rw-r--r--tools/testing/selftests/vm/.gitignore2
-rw-r--r--tools/testing/selftests/vm/Makefile2
-rw-r--r--tools/testing/selftests/vm/compaction_test.c1
-rw-r--r--tools/testing/selftests/vm/gup_benchmark.c91
-rw-r--r--tools/testing/selftests/vm/hugepage-mmap.c1
-rw-r--r--tools/testing/selftests/vm/hugepage-shm.c1
-rw-r--r--tools/testing/selftests/vm/map_hugetlb.c1
-rw-r--r--tools/testing/selftests/vm/mlock-random-test.c1
-rw-r--r--tools/testing/selftests/vm/mlock2-tests.c1
-rw-r--r--tools/testing/selftests/vm/mlock2.h1
-rw-r--r--tools/testing/selftests/vm/on-fault-limit.c1
-rwxr-xr-xtools/testing/selftests/vm/run_vmtests1
-rw-r--r--tools/testing/selftests/vm/thuge-gen.c1
-rw-r--r--tools/testing/selftests/vm/userfaultfd.c25
-rw-r--r--tools/testing/selftests/watchdog/Makefile8
-rw-r--r--tools/testing/selftests/watchdog/watchdog-test.c1
-rw-r--r--tools/testing/selftests/x86/5lvl.c177
-rw-r--r--tools/testing/selftests/x86/Makefile5
-rw-r--r--tools/testing/selftests/x86/entry_from_vm86.c89
-rw-r--r--tools/testing/selftests/x86/ioperm.c1
-rw-r--r--tools/testing/selftests/x86/iopl.c1
-rw-r--r--tools/testing/selftests/x86/ldt_gdt.c89
-rw-r--r--tools/testing/selftests/x86/mpx-debug.h1
-rw-r--r--tools/testing/selftests/x86/mpx-dig.c1
-rw-r--r--tools/testing/selftests/x86/mpx-hw.h5
-rw-r--r--tools/testing/selftests/x86/mpx-mm.h1
-rw-r--r--tools/testing/selftests/x86/pkey-helpers.h6
-rw-r--r--tools/testing/selftests/x86/protection_keys.c35
-rw-r--r--tools/testing/selftests/x86/ptrace_syscall.c1
-rw-r--r--tools/testing/selftests/x86/raw_syscall_helper_32.S1
-rw-r--r--tools/testing/selftests/x86/test_FCMOV.c1
-rw-r--r--tools/testing/selftests/x86/test_FCOMI.c1
-rw-r--r--tools/testing/selftests/x86/test_FISTTP.c1
-rw-r--r--tools/testing/selftests/x86/test_vdso.c1
-rw-r--r--tools/testing/selftests/zram/Makefile1
-rwxr-xr-xtools/testing/selftests/zram/zram.sh1
-rw-r--r--tools/testing/vsock/.gitignore2
-rw-r--r--tools/testing/vsock/Makefile9
-rw-r--r--tools/testing/vsock/README36
-rw-r--r--tools/testing/vsock/control.c219
-rw-r--r--tools/testing/vsock/control.h13
-rw-r--r--tools/testing/vsock/timeout.c64
-rw-r--r--tools/testing/vsock/timeout.h14
-rw-r--r--tools/testing/vsock/vsock_diag_test.c681
-rw-r--r--tools/thermal/tmon/Makefile19
-rw-r--r--tools/thermal/tmon/tmon.81
-rw-r--r--tools/usb/Makefile1
-rw-r--r--tools/usb/ffs-aio-example/multibuff/host_app/Makefile1
-rw-r--r--tools/usb/hcd-tests.sh1
-rw-r--r--tools/usb/usbip/Makefile.am4
-rwxr-xr-xtools/usb/usbip/cleanup.sh1
-rw-r--r--tools/usb/usbip/libsrc/Makefile.am1
-rw-r--r--tools/usb/usbip/libsrc/list.h1
-rw-r--r--tools/usb/usbip/libsrc/sysfs_utils.c1
-rw-r--r--tools/usb/usbip/libsrc/sysfs_utils.h1
-rw-r--r--tools/usb/usbip/libsrc/usbip_common.c1
-rw-r--r--tools/usb/usbip/libsrc/usbip_common.h1
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.c1
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.h1
-rw-r--r--tools/usb/usbip/src/Makefile.am1
-rw-r--r--tools/usb/usbip/src/usbip_network.h1
-rw-r--r--tools/virtio/Makefile1
-rw-r--r--tools/virtio/asm/barrier.h1
-rw-r--r--tools/virtio/linux/bug.h1
-rw-r--r--tools/virtio/linux/compiler.h1
-rw-r--r--tools/virtio/linux/dma-mapping.h1
-rw-r--r--tools/virtio/linux/err.h1
-rw-r--r--tools/virtio/linux/kernel.h1
-rw-r--r--tools/virtio/linux/module.h1
-rw-r--r--tools/virtio/linux/scatterlist.h1
-rw-r--r--tools/virtio/linux/slab.h1
-rw-r--r--tools/virtio/linux/uaccess.h1
-rw-r--r--tools/virtio/linux/virtio.h1
-rw-r--r--tools/virtio/linux/virtio_byteorder.h1
-rw-r--r--tools/virtio/linux/virtio_config.h1
-rw-r--r--tools/virtio/ringtest/Makefile1
-rw-r--r--tools/virtio/ringtest/main.h4
-rw-r--r--tools/virtio/ringtest/noring.c1
-rw-r--r--tools/virtio/ringtest/ptr_ring.c1
-rwxr-xr-xtools/virtio/ringtest/run-on-all.sh1
-rw-r--r--tools/virtio/uapi/linux/virtio_ring.h1
-rw-r--r--tools/virtio/virtio-trace/Makefile1
-rw-r--r--tools/virtio/virtio-trace/trace-agent.h1
-rw-r--r--tools/virtio/virtio_test.c1
-rw-r--r--tools/virtio/vringh_test.c1
-rw-r--r--tools/vm/Makefile1
-rw-r--r--tools/vm/page_owner_sort.c1
-rw-r--r--tools/vm/slabinfo.c12
-rw-r--r--tools/wmi/Makefile18
-rw-r--r--tools/wmi/dell-smbios-example.c210
1222 files changed, 24084 insertions, 3847 deletions
diff --git a/tools/Makefile b/tools/Makefile
index 9dfede37c8ff..be02c8b904db 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Some of the tools (perf) use same make variables 2# Some of the tools (perf) use same make variables
2# as in kernel build. 3# as in kernel build.
3export srctree= 4export srctree=
@@ -19,7 +20,7 @@ help:
19 @echo ' kvm_stat - top-like utility for displaying kvm statistics' 20 @echo ' kvm_stat - top-like utility for displaying kvm statistics'
20 @echo ' leds - LEDs tools' 21 @echo ' leds - LEDs tools'
21 @echo ' liblockdep - user-space wrapper for kernel locking-validator' 22 @echo ' liblockdep - user-space wrapper for kernel locking-validator'
22 @echo ' net - misc networking tools' 23 @echo ' bpf - misc BPF tools'
23 @echo ' perf - Linux performance measurement and analysis tool' 24 @echo ' perf - Linux performance measurement and analysis tool'
24 @echo ' selftests - various kernel selftests' 25 @echo ' selftests - various kernel selftests'
25 @echo ' spi - spi tools' 26 @echo ' spi - spi tools'
@@ -29,6 +30,7 @@ help:
29 @echo ' usb - USB testing tools' 30 @echo ' usb - USB testing tools'
30 @echo ' virtio - vhost test module' 31 @echo ' virtio - vhost test module'
31 @echo ' vm - misc vm tools' 32 @echo ' vm - misc vm tools'
33 @echo ' wmi - WMI interface examples'
32 @echo ' x86_energy_perf_policy - Intel energy policy tool' 34 @echo ' x86_energy_perf_policy - Intel energy policy tool'
33 @echo '' 35 @echo ''
34 @echo 'You can do:' 36 @echo 'You can do:'
@@ -57,7 +59,7 @@ acpi: FORCE
57cpupower: FORCE 59cpupower: FORCE
58 $(call descend,power/$@) 60 $(call descend,power/$@)
59 61
60cgroup firewire hv guest spi usb virtio vm net iio gpio objtool leds: FORCE 62cgroup firewire hv guest spi usb virtio vm bpf iio gpio objtool leds wmi: FORCE
61 $(call descend,$@) 63 $(call descend,$@)
62 64
63liblockdep: FORCE 65liblockdep: FORCE
@@ -91,8 +93,8 @@ kvm_stat: FORCE
91 93
92all: acpi cgroup cpupower gpio hv firewire liblockdep \ 94all: acpi cgroup cpupower gpio hv firewire liblockdep \
93 perf selftests spi turbostat usb \ 95 perf selftests spi turbostat usb \
94 virtio vm net x86_energy_perf_policy \ 96 virtio vm bpf x86_energy_perf_policy \
95 tmon freefall iio objtool kvm_stat 97 tmon freefall iio objtool kvm_stat wmi
96 98
97acpi_install: 99acpi_install:
98 $(call descend,power/$(@:_install=),install) 100 $(call descend,power/$(@:_install=),install)
@@ -100,7 +102,7 @@ acpi_install:
100cpupower_install: 102cpupower_install:
101 $(call descend,power/$(@:_install=),install) 103 $(call descend,power/$(@:_install=),install)
102 104
103cgroup_install firewire_install gpio_install hv_install iio_install perf_install spi_install usb_install virtio_install vm_install net_install objtool_install: 105cgroup_install firewire_install gpio_install hv_install iio_install perf_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install:
104 $(call descend,$(@:_install=),install) 106 $(call descend,$(@:_install=),install)
105 107
106liblockdep_install: 108liblockdep_install:
@@ -124,8 +126,9 @@ kvm_stat_install:
124install: acpi_install cgroup_install cpupower_install gpio_install \ 126install: acpi_install cgroup_install cpupower_install gpio_install \
125 hv_install firewire_install iio_install liblockdep_install \ 127 hv_install firewire_install iio_install liblockdep_install \
126 perf_install selftests_install turbostat_install usb_install \ 128 perf_install selftests_install turbostat_install usb_install \
127 virtio_install vm_install net_install x86_energy_perf_policy_install \ 129 virtio_install vm_install bpf_install x86_energy_perf_policy_install \
128 tmon_install freefall_install objtool_install kvm_stat_install 130 tmon_install freefall_install objtool_install kvm_stat_install \
131 wmi_install
129 132
130acpi_clean: 133acpi_clean:
131 $(call descend,power/acpi,clean) 134 $(call descend,power/acpi,clean)
@@ -133,7 +136,7 @@ acpi_clean:
133cpupower_clean: 136cpupower_clean:
134 $(call descend,power/cpupower,clean) 137 $(call descend,power/cpupower,clean)
135 138
136cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean net_clean iio_clean gpio_clean objtool_clean leds_clean: 139cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean:
137 $(call descend,$(@:_clean=),clean) 140 $(call descend,$(@:_clean=),clean)
138 141
139liblockdep_clean: 142liblockdep_clean:
@@ -169,8 +172,8 @@ build_clean:
169 172
170clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean \ 173clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean \
171 perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \ 174 perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \
172 vm_clean net_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ 175 vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
173 freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \ 176 freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \
174 gpio_clean objtool_clean leds_clean 177 gpio_clean objtool_clean leds_clean wmi_clean
175 178
176.PHONY: FORCE 179.PHONY: FORCE
diff --git a/tools/accounting/Makefile b/tools/accounting/Makefile
index 647c94a219bf..03687f19cbb1 100644
--- a/tools/accounting/Makefile
+++ b/tools/accounting/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CC := $(CROSS_COMPILE)gcc 2CC := $(CROSS_COMPILE)gcc
2CFLAGS := -I../../usr/include 3CFLAGS := -I../../usr/include
3 4
diff --git a/tools/accounting/getdelays.c b/tools/accounting/getdelays.c
index b5ca536e56a8..9f420d98b5fb 100644
--- a/tools/accounting/getdelays.c
+++ b/tools/accounting/getdelays.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* getdelays.c 2/* getdelays.c
2 * 3 *
3 * Utility to get per-pid and per-tgid delay accounting statistics 4 * Utility to get per-pid and per-tgid delay accounting statistics
diff --git a/tools/arch/alpha/include/asm/barrier.h b/tools/arch/alpha/include/asm/barrier.h
index 95df19c95482..da8d6457ed4f 100644
--- a/tools/arch/alpha/include/asm/barrier.h
+++ b/tools/arch/alpha/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_LINUX_ASM_ALPHA_BARRIER_H 2#ifndef __TOOLS_LINUX_ASM_ALPHA_BARRIER_H
2#define __TOOLS_LINUX_ASM_ALPHA_BARRIER_H 3#define __TOOLS_LINUX_ASM_ALPHA_BARRIER_H
3 4
diff --git a/tools/arch/alpha/include/uapi/asm/bitsperlong.h b/tools/arch/alpha/include/uapi/asm/bitsperlong.h
index ad57f7868203..6c5bf7d03f4e 100644
--- a/tools/arch/alpha/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/alpha/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_ALPHA_BITSPERLONG_H 2#ifndef __ASM_ALPHA_BITSPERLONG_H
2#define __ASM_ALPHA_BITSPERLONG_H 3#define __ASM_ALPHA_BITSPERLONG_H
3 4
diff --git a/tools/arch/alpha/include/uapi/asm/mman.h b/tools/arch/alpha/include/uapi/asm/mman.h
index e38b64c82b97..c317d3e6867a 100644
--- a/tools/arch/alpha/include/uapi/asm/mman.h
+++ b/tools/arch/alpha/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_ALPHA_UAPI_ASM_MMAN_FIX_H
3#define MADV_DODUMP 17 4#define MADV_DODUMP 17
diff --git a/tools/arch/arc/include/uapi/asm/mman.h b/tools/arch/arc/include/uapi/asm/mman.h
index aa3acd2aa9af..81f0f9bf0c25 100644
--- a/tools/arch/arc/include/uapi/asm/mman.h
+++ b/tools/arch/arc/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_ARC_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_ARC_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_ARC_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_ARC_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/arm/include/uapi/asm/kvm.h b/tools/arch/arm/include/uapi/asm/kvm.h
index 5db2d4c6a55f..1f57bbe82b6f 100644
--- a/tools/arch/arm/include/uapi/asm/kvm.h
+++ b/tools/arch/arm/include/uapi/asm/kvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * Copyright (C) 2012 - Virtual Open Systems and Columbia University 3 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
3 * Author: Christoffer Dall <c.dall@virtualopensystems.com> 4 * Author: Christoffer Dall <c.dall@virtualopensystems.com>
diff --git a/tools/arch/arm/include/uapi/asm/mman.h b/tools/arch/arm/include/uapi/asm/mman.h
index 478f699f56fd..a6d46321e330 100644
--- a/tools/arch/arm/include/uapi/asm/mman.h
+++ b/tools/arch/arm/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_ARM_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/arm/include/uapi/asm/perf_regs.h b/tools/arch/arm/include/uapi/asm/perf_regs.h
index ce59448458b2..a3c046174e6b 100644
--- a/tools/arch/arm/include/uapi/asm/perf_regs.h
+++ b/tools/arch/arm/include/uapi/asm/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _ASM_ARM_PERF_REGS_H 2#ifndef _ASM_ARM_PERF_REGS_H
2#define _ASM_ARM_PERF_REGS_H 3#define _ASM_ARM_PERF_REGS_H
3 4
diff --git a/tools/arch/arm64/include/asm/barrier.h b/tools/arch/arm64/include/asm/barrier.h
index a0483c8e0142..40bde6b23501 100644
--- a/tools/arch/arm64/include/asm/barrier.h
+++ b/tools/arch/arm64/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_AARCH64_BARRIER_H 2#ifndef _TOOLS_LINUX_ASM_AARCH64_BARRIER_H
2#define _TOOLS_LINUX_ASM_AARCH64_BARRIER_H 3#define _TOOLS_LINUX_ASM_AARCH64_BARRIER_H
3 4
diff --git a/tools/arch/arm64/include/uapi/asm/bitsperlong.h b/tools/arch/arm64/include/uapi/asm/bitsperlong.h
index fce9c2924fa3..485d60bee26c 100644
--- a/tools/arch/arm64/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/arm64/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * Copyright (C) 2012 ARM Ltd. 3 * Copyright (C) 2012 ARM Ltd.
3 * 4 *
diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h
index 9f3ca24bbcc6..51149ec75fe4 100644
--- a/tools/arch/arm64/include/uapi/asm/kvm.h
+++ b/tools/arch/arm64/include/uapi/asm/kvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * Copyright (C) 2012,2013 - ARM Ltd 3 * Copyright (C) 2012,2013 - ARM Ltd
3 * Author: Marc Zyngier <marc.zyngier@arm.com> 4 * Author: Marc Zyngier <marc.zyngier@arm.com>
diff --git a/tools/arch/arm64/include/uapi/asm/mman.h b/tools/arch/arm64/include/uapi/asm/mman.h
index 70fd3113710a..2ee288e447ec 100644
--- a/tools/arch/arm64/include/uapi/asm/mman.h
+++ b/tools/arch/arm64/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_ARM64_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/arm64/include/uapi/asm/perf_regs.h b/tools/arch/arm64/include/uapi/asm/perf_regs.h
index 172b8317ee49..d54daafa89e3 100644
--- a/tools/arch/arm64/include/uapi/asm/perf_regs.h
+++ b/tools/arch/arm64/include/uapi/asm/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _ASM_ARM64_PERF_REGS_H 2#ifndef _ASM_ARM64_PERF_REGS_H
2#define _ASM_ARM64_PERF_REGS_H 3#define _ASM_ARM64_PERF_REGS_H
3 4
diff --git a/tools/arch/frv/include/uapi/asm/bitsperlong.h b/tools/arch/frv/include/uapi/asm/bitsperlong.h
index 6dc0bb0c13b2..76da34b10f59 100644
--- a/tools/arch/frv/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/frv/include/uapi/asm/bitsperlong.h
@@ -1 +1,2 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#include <asm-generic/bitsperlong.h> 2#include <asm-generic/bitsperlong.h>
diff --git a/tools/arch/frv/include/uapi/asm/mman.h b/tools/arch/frv/include/uapi/asm/mman.h
index 5be78ac12464..5bc900b0bc78 100644
--- a/tools/arch/frv/include/uapi/asm/mman.h
+++ b/tools/arch/frv/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_FRV_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/h8300/include/asm/bitsperlong.h b/tools/arch/h8300/include/asm/bitsperlong.h
index e140e46729ac..fa1508337ffc 100644
--- a/tools/arch/h8300/include/asm/bitsperlong.h
+++ b/tools/arch/h8300/include/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __ASM_H8300_BITS_PER_LONG 2#ifndef __ASM_H8300_BITS_PER_LONG
2#define __ASM_H8300_BITS_PER_LONG 3#define __ASM_H8300_BITS_PER_LONG
3 4
diff --git a/tools/arch/h8300/include/uapi/asm/mman.h b/tools/arch/h8300/include/uapi/asm/mman.h
index 9d9ac54d3c5a..be7bbe0528d1 100644
--- a/tools/arch/h8300/include/uapi/asm/mman.h
+++ b/tools/arch/h8300/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_H8300_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/hexagon/include/uapi/asm/bitsperlong.h b/tools/arch/hexagon/include/uapi/asm/bitsperlong.h
index 4a658151383d..5adca0d26913 100644
--- a/tools/arch/hexagon/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/hexagon/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. 3 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
3 * 4 *
diff --git a/tools/arch/hexagon/include/uapi/asm/mman.h b/tools/arch/hexagon/include/uapi/asm/mman.h
index 102f3fae6085..cd59ba932b3a 100644
--- a/tools/arch/hexagon/include/uapi/asm/mman.h
+++ b/tools/arch/hexagon/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_HEXAGON_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/ia64/include/asm/barrier.h b/tools/arch/ia64/include/asm/barrier.h
index e4422b4b634e..d808ee0e77b5 100644
--- a/tools/arch/ia64/include/asm/barrier.h
+++ b/tools/arch/ia64/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copied from the kernel sources to tools/: 3 * Copied from the kernel sources to tools/:
3 * 4 *
diff --git a/tools/arch/ia64/include/uapi/asm/bitsperlong.h b/tools/arch/ia64/include/uapi/asm/bitsperlong.h
index ec4db3c970b7..1146d55563db 100644
--- a/tools/arch/ia64/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/ia64/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_IA64_BITSPERLONG_H 2#ifndef __ASM_IA64_BITSPERLONG_H
2#define __ASM_IA64_BITSPERLONG_H 3#define __ASM_IA64_BITSPERLONG_H
3 4
diff --git a/tools/arch/ia64/include/uapi/asm/mman.h b/tools/arch/ia64/include/uapi/asm/mman.h
index 1d6e5ac6442d..2a19bb1db4ab 100644
--- a/tools/arch/ia64/include/uapi/asm/mman.h
+++ b/tools/arch/ia64/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_IA64_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/m32r/include/uapi/asm/bitsperlong.h b/tools/arch/m32r/include/uapi/asm/bitsperlong.h
index 6dc0bb0c13b2..76da34b10f59 100644
--- a/tools/arch/m32r/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/m32r/include/uapi/asm/bitsperlong.h
@@ -1 +1,2 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#include <asm-generic/bitsperlong.h> 2#include <asm-generic/bitsperlong.h>
diff --git a/tools/arch/m32r/include/uapi/asm/mman.h b/tools/arch/m32r/include/uapi/asm/mman.h
index 1c29635bb73b..d19b82c9c290 100644
--- a/tools/arch/m32r/include/uapi/asm/mman.h
+++ b/tools/arch/m32r/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_M32R_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/microblaze/include/uapi/asm/bitsperlong.h b/tools/arch/microblaze/include/uapi/asm/bitsperlong.h
index 6dc0bb0c13b2..76da34b10f59 100644
--- a/tools/arch/microblaze/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/microblaze/include/uapi/asm/bitsperlong.h
@@ -1 +1,2 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#include <asm-generic/bitsperlong.h> 2#include <asm-generic/bitsperlong.h>
diff --git a/tools/arch/microblaze/include/uapi/asm/mman.h b/tools/arch/microblaze/include/uapi/asm/mman.h
index 005cd50b50e1..f3f2103fd02c 100644
--- a/tools/arch/microblaze/include/uapi/asm/mman.h
+++ b/tools/arch/microblaze/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_MICROBLAZE_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/mips/include/asm/barrier.h b/tools/arch/mips/include/asm/barrier.h
index 80f96f7556e3..0d1191523cd0 100644
--- a/tools/arch/mips/include/asm/barrier.h
+++ b/tools/arch/mips/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_MIPS_BARRIER_H 2#ifndef _TOOLS_LINUX_ASM_MIPS_BARRIER_H
2#define _TOOLS_LINUX_ASM_MIPS_BARRIER_H 3#define _TOOLS_LINUX_ASM_MIPS_BARRIER_H
3/* 4/*
diff --git a/tools/arch/mips/include/uapi/asm/bitsperlong.h b/tools/arch/mips/include/uapi/asm/bitsperlong.h
index 3e4c10a8e787..7268380d8d28 100644
--- a/tools/arch/mips/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/mips/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_MIPS_BITSPERLONG_H 2#ifndef __ASM_MIPS_BITSPERLONG_H
2#define __ASM_MIPS_BITSPERLONG_H 3#define __ASM_MIPS_BITSPERLONG_H
3 4
diff --git a/tools/arch/mips/include/uapi/asm/kvm.h b/tools/arch/mips/include/uapi/asm/kvm.h
index 6985eb59b085..d2714cc1cd93 100644
--- a/tools/arch/mips/include/uapi/asm/kvm.h
+++ b/tools/arch/mips/include/uapi/asm/kvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * This file is subject to the terms and conditions of the GNU General Public 3 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive 4 * License. See the file "COPYING" in the main directory of this archive
diff --git a/tools/arch/mips/include/uapi/asm/mman.h b/tools/arch/mips/include/uapi/asm/mman.h
index c02052965d50..de2206883abc 100644
--- a/tools/arch/mips/include/uapi/asm/mman.h
+++ b/tools/arch/mips/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_MIPS_UAPI_ASM_MMAN_FIX_H
3#define MADV_DODUMP 17 4#define MADV_DODUMP 17
diff --git a/tools/arch/mn10300/include/uapi/asm/mman.h b/tools/arch/mn10300/include/uapi/asm/mman.h
index c1ea36d83acc..b9360639974f 100644
--- a/tools/arch/mn10300/include/uapi/asm/mman.h
+++ b/tools/arch/mn10300/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_MN10300_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/parisc/include/uapi/asm/bitsperlong.h b/tools/arch/parisc/include/uapi/asm/bitsperlong.h
index e0a23c7bdd43..23ac7562927a 100644
--- a/tools/arch/parisc/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/parisc/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_PARISC_BITSPERLONG_H 2#ifndef __ASM_PARISC_BITSPERLONG_H
2#define __ASM_PARISC_BITSPERLONG_H 3#define __ASM_PARISC_BITSPERLONG_H
3 4
diff --git a/tools/arch/parisc/include/uapi/asm/mman.h b/tools/arch/parisc/include/uapi/asm/mman.h
index 286c0bd74573..1bd78758bde9 100644
--- a/tools/arch/parisc/include/uapi/asm/mman.h
+++ b/tools/arch/parisc/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_PARISC_UAPI_ASM_MMAN_FIX_H
3#define MADV_DODUMP 70 4#define MADV_DODUMP 70
diff --git a/tools/arch/powerpc/include/asm/barrier.h b/tools/arch/powerpc/include/asm/barrier.h
index b23aee8e6d90..a634da05bc97 100644
--- a/tools/arch/powerpc/include/asm/barrier.h
+++ b/tools/arch/powerpc/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copied from the kernel sources: 3 * Copied from the kernel sources:
3 * 4 *
diff --git a/tools/arch/powerpc/include/uapi/asm/bitsperlong.h b/tools/arch/powerpc/include/uapi/asm/bitsperlong.h
index 5f1659032c40..46ece3ecff31 100644
--- a/tools/arch/powerpc/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/powerpc/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_POWERPC_BITSPERLONG_H 2#ifndef __ASM_POWERPC_BITSPERLONG_H
2#define __ASM_POWERPC_BITSPERLONG_H 3#define __ASM_POWERPC_BITSPERLONG_H
3 4
diff --git a/tools/arch/powerpc/include/uapi/asm/kvm.h b/tools/arch/powerpc/include/uapi/asm/kvm.h
index 8cf8f0c96906..61d6049f4c1e 100644
--- a/tools/arch/powerpc/include/uapi/asm/kvm.h
+++ b/tools/arch/powerpc/include/uapi/asm/kvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * This program is free software; you can redistribute it and/or modify 3 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as 4 * it under the terms of the GNU General Public License, version 2, as
diff --git a/tools/arch/powerpc/include/uapi/asm/mman.h b/tools/arch/powerpc/include/uapi/asm/mman.h
index 761db43172fe..f33105bc5ca6 100644
--- a/tools/arch/powerpc/include/uapi/asm/mman.h
+++ b/tools/arch/powerpc/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_POWERPC_UAPI_ASM_MMAN_FIX_H
3#define MAP_DENYWRITE 0x0800 4#define MAP_DENYWRITE 0x0800
diff --git a/tools/arch/powerpc/include/uapi/asm/perf_regs.h b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
index 6a93209748a1..9e52c86ccbd3 100644
--- a/tools/arch/powerpc/include/uapi/asm/perf_regs.h
+++ b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_ASM_POWERPC_PERF_REGS_H 2#ifndef _UAPI_ASM_POWERPC_PERF_REGS_H
2#define _UAPI_ASM_POWERPC_PERF_REGS_H 3#define _UAPI_ASM_POWERPC_PERF_REGS_H
3 4
diff --git a/tools/arch/s390/include/asm/barrier.h b/tools/arch/s390/include/asm/barrier.h
index f85141266b92..5030c99f47d2 100644
--- a/tools/arch/s390/include/asm/barrier.h
+++ b/tools/arch/s390/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copied from the kernel sources: 3 * Copied from the kernel sources:
3 * 4 *
diff --git a/tools/arch/s390/include/uapi/asm/bitsperlong.h b/tools/arch/s390/include/uapi/asm/bitsperlong.h
index e351ea2ad43e..d2bb620119bf 100644
--- a/tools/arch/s390/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/s390/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_S390_BITSPERLONG_H 2#ifndef __ASM_S390_BITSPERLONG_H
2#define __ASM_S390_BITSPERLONG_H 3#define __ASM_S390_BITSPERLONG_H
3 4
diff --git a/tools/arch/s390/include/uapi/asm/kvm.h b/tools/arch/s390/include/uapi/asm/kvm.h
index 69d09c39bbcd..9ad172dcd912 100644
--- a/tools/arch/s390/include/uapi/asm/kvm.h
+++ b/tools/arch/s390/include/uapi/asm/kvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __LINUX_KVM_S390_H 2#ifndef __LINUX_KVM_S390_H
2#define __LINUX_KVM_S390_H 3#define __LINUX_KVM_S390_H
3/* 4/*
@@ -88,6 +89,12 @@ struct kvm_s390_io_adapter_req {
88/* kvm attributes for KVM_S390_VM_TOD */ 89/* kvm attributes for KVM_S390_VM_TOD */
89#define KVM_S390_VM_TOD_LOW 0 90#define KVM_S390_VM_TOD_LOW 0
90#define KVM_S390_VM_TOD_HIGH 1 91#define KVM_S390_VM_TOD_HIGH 1
92#define KVM_S390_VM_TOD_EXT 2
93
94struct kvm_s390_vm_tod_clock {
95 __u8 epoch_idx;
96 __u64 tod;
97};
91 98
92/* kvm attributes for KVM_S390_VM_CPU_MODEL */ 99/* kvm attributes for KVM_S390_VM_CPU_MODEL */
93/* processor related attributes are r/w */ 100/* processor related attributes are r/w */
diff --git a/tools/arch/s390/include/uapi/asm/kvm_perf.h b/tools/arch/s390/include/uapi/asm/kvm_perf.h
index 397282727e21..c36c97ffdc6f 100644
--- a/tools/arch/s390/include/uapi/asm/kvm_perf.h
+++ b/tools/arch/s390/include/uapi/asm/kvm_perf.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * Definitions for perf-kvm on s390 3 * Definitions for perf-kvm on s390
3 * 4 *
diff --git a/tools/arch/s390/include/uapi/asm/mman.h b/tools/arch/s390/include/uapi/asm/mman.h
index b03dea9e1f56..4ec32e4251a4 100644
--- a/tools/arch/s390/include/uapi/asm/mman.h
+++ b/tools/arch/s390/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_S390_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/s390/include/uapi/asm/sie.h b/tools/arch/s390/include/uapi/asm/sie.h
index 3ac634368939..6ca1e68d7103 100644
--- a/tools/arch/s390/include/uapi/asm/sie.h
+++ b/tools/arch/s390/include/uapi/asm/sie.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_ASM_S390_SIE_H 2#ifndef _UAPI_ASM_S390_SIE_H
2#define _UAPI_ASM_S390_SIE_H 3#define _UAPI_ASM_S390_SIE_H
3 4
diff --git a/tools/arch/score/include/uapi/asm/bitsperlong.h b/tools/arch/score/include/uapi/asm/bitsperlong.h
index 86ff337aa459..df48f2717da2 100644
--- a/tools/arch/score/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/score/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _ASM_SCORE_BITSPERLONG_H 2#ifndef _ASM_SCORE_BITSPERLONG_H
2#define _ASM_SCORE_BITSPERLONG_H 3#define _ASM_SCORE_BITSPERLONG_H
3 4
diff --git a/tools/arch/score/include/uapi/asm/mman.h b/tools/arch/score/include/uapi/asm/mman.h
index 2f8fb89944fd..b4bd195a8586 100644
--- a/tools/arch/score/include/uapi/asm/mman.h
+++ b/tools/arch/score/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_SCORE_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/sh/include/asm/barrier.h b/tools/arch/sh/include/asm/barrier.h
index c18fd7599b97..bde5221af282 100644
--- a/tools/arch/sh/include/asm/barrier.h
+++ b/tools/arch/sh/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copied from the kernel sources: 3 * Copied from the kernel sources:
3 * 4 *
diff --git a/tools/arch/sh/include/uapi/asm/mman.h b/tools/arch/sh/include/uapi/asm/mman.h
index 26504f6f060e..88c0e2930c47 100644
--- a/tools/arch/sh/include/uapi/asm/mman.h
+++ b/tools/arch/sh/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_SH_UAPI_ASM_MMAN_FIX_H
3#include <uapi/asm-generic/mman.h> 4#include <uapi/asm-generic/mman.h>
diff --git a/tools/arch/sparc/include/asm/barrier.h b/tools/arch/sparc/include/asm/barrier.h
index 8c017b3b1391..95d1618465a6 100644
--- a/tools/arch/sparc/include/asm/barrier.h
+++ b/tools/arch/sparc/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ___TOOLS_LINUX_ASM_SPARC_BARRIER_H 2#ifndef ___TOOLS_LINUX_ASM_SPARC_BARRIER_H
2#define ___TOOLS_LINUX_ASM_SPARC_BARRIER_H 3#define ___TOOLS_LINUX_ASM_SPARC_BARRIER_H
3#if defined(__sparc__) && defined(__arch64__) 4#if defined(__sparc__) && defined(__arch64__)
diff --git a/tools/arch/sparc/include/asm/barrier_32.h b/tools/arch/sparc/include/asm/barrier_32.h
index c5eadd0a7233..cc19ed1dde0b 100644
--- a/tools/arch/sparc/include/asm/barrier_32.h
+++ b/tools/arch/sparc/include/asm/barrier_32.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_PERF_SPARC_BARRIER_H 2#ifndef __TOOLS_PERF_SPARC_BARRIER_H
2#define __TOOLS_PERF_SPARC_BARRIER_H 3#define __TOOLS_PERF_SPARC_BARRIER_H
3 4
diff --git a/tools/arch/sparc/include/asm/barrier_64.h b/tools/arch/sparc/include/asm/barrier_64.h
index 9a7d7322c3f7..ba61344287d5 100644
--- a/tools/arch/sparc/include/asm/barrier_64.h
+++ b/tools/arch/sparc/include/asm/barrier_64.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_LINUX_SPARC64_BARRIER_H 2#ifndef __TOOLS_LINUX_SPARC64_BARRIER_H
2#define __TOOLS_LINUX_SPARC64_BARRIER_H 3#define __TOOLS_LINUX_SPARC64_BARRIER_H
3 4
diff --git a/tools/arch/sparc/include/uapi/asm/bitsperlong.h b/tools/arch/sparc/include/uapi/asm/bitsperlong.h
index b62dd907d7c3..3b4e61740b75 100644
--- a/tools/arch/sparc/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/sparc/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_ALPHA_BITSPERLONG_H 2#ifndef __ASM_ALPHA_BITSPERLONG_H
2#define __ASM_ALPHA_BITSPERLONG_H 3#define __ASM_ALPHA_BITSPERLONG_H
3 4
diff --git a/tools/arch/sparc/include/uapi/asm/mman.h b/tools/arch/sparc/include/uapi/asm/mman.h
index 8640525de991..38920eed8cbf 100644
--- a/tools/arch/sparc/include/uapi/asm/mman.h
+++ b/tools/arch/sparc/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_SPARC_UAPI_ASM_MMAN_FIX_H
3#define MAP_DENYWRITE 0x0800 4#define MAP_DENYWRITE 0x0800
diff --git a/tools/arch/tile/include/asm/barrier.h b/tools/arch/tile/include/asm/barrier.h
index 7d3692c3d4ac..7ad02a591b43 100644
--- a/tools/arch/tile/include/asm/barrier.h
+++ b/tools/arch/tile/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_TILE_BARRIER_H 2#ifndef _TOOLS_LINUX_ASM_TILE_BARRIER_H
2#define _TOOLS_LINUX_ASM_TILE_BARRIER_H 3#define _TOOLS_LINUX_ASM_TILE_BARRIER_H
3/* 4/*
diff --git a/tools/arch/tile/include/uapi/asm/bitsperlong.h b/tools/arch/tile/include/uapi/asm/bitsperlong.h
index 58c771f2af2f..57cca78c0fbb 100644
--- a/tools/arch/tile/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/tile/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved. 3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 * 4 *
diff --git a/tools/arch/tile/include/uapi/asm/mman.h b/tools/arch/tile/include/uapi/asm/mman.h
index 7116c4b928b3..65ec92925c6c 100644
--- a/tools/arch/tile/include/uapi/asm/mman.h
+++ b/tools/arch/tile/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
3#define MAP_DENYWRITE 0x0800 4#define MAP_DENYWRITE 0x0800
diff --git a/tools/arch/x86/include/asm/atomic.h b/tools/arch/x86/include/asm/atomic.h
index 328eeceec709..1f5e26aae9fc 100644
--- a/tools/arch/x86/include/asm/atomic.h
+++ b/tools/arch/x86/include/asm/atomic.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_X86_ATOMIC_H 2#ifndef _TOOLS_LINUX_ASM_X86_ATOMIC_H
2#define _TOOLS_LINUX_ASM_X86_ATOMIC_H 3#define _TOOLS_LINUX_ASM_X86_ATOMIC_H
3 4
@@ -24,7 +25,7 @@
24 */ 25 */
25static inline int atomic_read(const atomic_t *v) 26static inline int atomic_read(const atomic_t *v)
26{ 27{
27 return ACCESS_ONCE((v)->counter); 28 return READ_ONCE((v)->counter);
28} 29}
29 30
30/** 31/**
diff --git a/tools/arch/x86/include/asm/barrier.h b/tools/arch/x86/include/asm/barrier.h
index f366d8e550e4..8774dee27471 100644
--- a/tools/arch/x86/include/asm/barrier.h
+++ b/tools/arch/x86/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_X86_BARRIER_H 2#ifndef _TOOLS_LINUX_ASM_X86_BARRIER_H
2#define _TOOLS_LINUX_ASM_X86_BARRIER_H 3#define _TOOLS_LINUX_ASM_X86_BARRIER_H
3 4
diff --git a/tools/arch/x86/include/asm/cmpxchg.h b/tools/arch/x86/include/asm/cmpxchg.h
index f5253260f3cc..0ed9ca2766ad 100644
--- a/tools/arch/x86/include/asm/cmpxchg.h
+++ b/tools/arch/x86/include/asm/cmpxchg.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef TOOLS_ASM_X86_CMPXCHG_H 2#ifndef TOOLS_ASM_X86_CMPXCHG_H
2#define TOOLS_ASM_X86_CMPXCHG_H 3#define TOOLS_ASM_X86_CMPXCHG_H
3 4
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 8ea315a11fe0..793690fbda36 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _ASM_X86_CPUFEATURES_H 2#ifndef _ASM_X86_CPUFEATURES_H
2#define _ASM_X86_CPUFEATURES_H 3#define _ASM_X86_CPUFEATURES_H
3 4
@@ -196,6 +197,7 @@
196 197
197#define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */ 198#define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */
198#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */ 199#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */
200#define X86_FEATURE_SME ( 7*32+10) /* AMD Secure Memory Encryption */
199 201
200#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */ 202#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
201#define X86_FEATURE_INTEL_PT ( 7*32+15) /* Intel Processor Trace */ 203#define X86_FEATURE_INTEL_PT ( 7*32+15) /* Intel Processor Trace */
@@ -287,6 +289,7 @@
287#define X86_FEATURE_PFTHRESHOLD (15*32+12) /* pause filter threshold */ 289#define X86_FEATURE_PFTHRESHOLD (15*32+12) /* pause filter threshold */
288#define X86_FEATURE_AVIC (15*32+13) /* Virtual Interrupt Controller */ 290#define X86_FEATURE_AVIC (15*32+13) /* Virtual Interrupt Controller */
289#define X86_FEATURE_V_VMSAVE_VMLOAD (15*32+15) /* Virtual VMSAVE VMLOAD */ 291#define X86_FEATURE_V_VMSAVE_VMLOAD (15*32+15) /* Virtual VMSAVE VMLOAD */
292#define X86_FEATURE_VGIF (15*32+16) /* Virtual GIF */
290 293
291/* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 16 */ 294/* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 16 */
292#define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/ 295#define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
diff --git a/tools/arch/x86/include/asm/disabled-features.h b/tools/arch/x86/include/asm/disabled-features.h
index 5dff775af7cd..c10c9128f54e 100644
--- a/tools/arch/x86/include/asm/disabled-features.h
+++ b/tools/arch/x86/include/asm/disabled-features.h
@@ -21,11 +21,13 @@
21# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31)) 21# define DISABLE_K6_MTRR (1<<(X86_FEATURE_K6_MTRR & 31))
22# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31)) 22# define DISABLE_CYRIX_ARR (1<<(X86_FEATURE_CYRIX_ARR & 31))
23# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31)) 23# define DISABLE_CENTAUR_MCR (1<<(X86_FEATURE_CENTAUR_MCR & 31))
24# define DISABLE_PCID 0
24#else 25#else
25# define DISABLE_VME 0 26# define DISABLE_VME 0
26# define DISABLE_K6_MTRR 0 27# define DISABLE_K6_MTRR 0
27# define DISABLE_CYRIX_ARR 0 28# define DISABLE_CYRIX_ARR 0
28# define DISABLE_CENTAUR_MCR 0 29# define DISABLE_CENTAUR_MCR 0
30# define DISABLE_PCID (1<<(X86_FEATURE_PCID & 31))
29#endif /* CONFIG_X86_64 */ 31#endif /* CONFIG_X86_64 */
30 32
31#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS 33#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
@@ -49,7 +51,7 @@
49#define DISABLED_MASK1 0 51#define DISABLED_MASK1 0
50#define DISABLED_MASK2 0 52#define DISABLED_MASK2 0
51#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR) 53#define DISABLED_MASK3 (DISABLE_CYRIX_ARR|DISABLE_CENTAUR_MCR|DISABLE_K6_MTRR)
52#define DISABLED_MASK4 0 54#define DISABLED_MASK4 (DISABLE_PCID)
53#define DISABLED_MASK5 0 55#define DISABLED_MASK5 0
54#define DISABLED_MASK6 0 56#define DISABLED_MASK6 0
55#define DISABLED_MASK7 0 57#define DISABLED_MASK7 0
diff --git a/tools/arch/x86/include/asm/rmwcc.h b/tools/arch/x86/include/asm/rmwcc.h
index a6669bc06939..dc90c0c2fae3 100644
--- a/tools/arch/x86/include/asm/rmwcc.h
+++ b/tools/arch/x86/include/asm/rmwcc.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_X86_RMWcc 2#ifndef _TOOLS_LINUX_ASM_X86_RMWcc
2#define _TOOLS_LINUX_ASM_X86_RMWcc 3#define _TOOLS_LINUX_ASM_X86_RMWcc
3 4
diff --git a/tools/arch/x86/include/asm/unistd_32.h b/tools/arch/x86/include/asm/unistd_32.h
index 0e4312ffc945..60a89dba01b6 100644
--- a/tools/arch/x86/include/asm/unistd_32.h
+++ b/tools/arch/x86/include/asm/unistd_32.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __NR_perf_event_open 2#ifndef __NR_perf_event_open
2# define __NR_perf_event_open 336 3# define __NR_perf_event_open 336
3#endif 4#endif
diff --git a/tools/arch/x86/include/asm/unistd_64.h b/tools/arch/x86/include/asm/unistd_64.h
index dd56bb36132a..cb52a3a8b8fc 100644
--- a/tools/arch/x86/include/asm/unistd_64.h
+++ b/tools/arch/x86/include/asm/unistd_64.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __NR_perf_event_open 2#ifndef __NR_perf_event_open
2# define __NR_perf_event_open 298 3# define __NR_perf_event_open 298
3#endif 4#endif
diff --git a/tools/arch/x86/include/uapi/asm/bitsperlong.h b/tools/arch/x86/include/uapi/asm/bitsperlong.h
index 6e23c543cd80..f8a92e0009d6 100644
--- a/tools/arch/x86/include/uapi/asm/bitsperlong.h
+++ b/tools/arch/x86/include/uapi/asm/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_X86_BITSPERLONG_H 2#ifndef __ASM_X86_BITSPERLONG_H
2#define __ASM_X86_BITSPERLONG_H 3#define __ASM_X86_BITSPERLONG_H
3 4
diff --git a/tools/arch/x86/include/uapi/asm/kvm.h b/tools/arch/x86/include/uapi/asm/kvm.h
index c2824d02ba37..f3a960488eae 100644
--- a/tools/arch/x86/include/uapi/asm/kvm.h
+++ b/tools/arch/x86/include/uapi/asm/kvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _ASM_X86_KVM_H 2#ifndef _ASM_X86_KVM_H
2#define _ASM_X86_KVM_H 3#define _ASM_X86_KVM_H
3 4
diff --git a/tools/arch/x86/include/uapi/asm/kvm_perf.h b/tools/arch/x86/include/uapi/asm/kvm_perf.h
index 3bb964f88aa1..125cf5cdf6c5 100644
--- a/tools/arch/x86/include/uapi/asm/kvm_perf.h
+++ b/tools/arch/x86/include/uapi/asm/kvm_perf.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _ASM_X86_KVM_PERF_H 2#ifndef _ASM_X86_KVM_PERF_H
2#define _ASM_X86_KVM_PERF_H 3#define _ASM_X86_KVM_PERF_H
3 4
diff --git a/tools/arch/x86/include/uapi/asm/mman.h b/tools/arch/x86/include/uapi/asm/mman.h
index b73c1af8b1dd..8449778de2ed 100644
--- a/tools/arch/x86/include/uapi/asm/mman.h
+++ b/tools/arch/x86/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_X86_UAPI_ASM_MMAN_FIX_H
3#define MAP_32BIT 0x40 4#define MAP_32BIT 0x40
diff --git a/tools/arch/x86/include/uapi/asm/perf_regs.h b/tools/arch/x86/include/uapi/asm/perf_regs.h
index 3f2207bfd17b..f3329cabce5c 100644
--- a/tools/arch/x86/include/uapi/asm/perf_regs.h
+++ b/tools/arch/x86/include/uapi/asm/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _ASM_X86_PERF_REGS_H 2#ifndef _ASM_X86_PERF_REGS_H
2#define _ASM_X86_PERF_REGS_H 3#define _ASM_X86_PERF_REGS_H
3 4
diff --git a/tools/arch/x86/include/uapi/asm/svm.h b/tools/arch/x86/include/uapi/asm/svm.h
index 3725e145aa58..a9731f8a480f 100644
--- a/tools/arch/x86/include/uapi/asm/svm.h
+++ b/tools/arch/x86/include/uapi/asm/svm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI__SVM_H 2#ifndef _UAPI__SVM_H
2#define _UAPI__SVM_H 3#define _UAPI__SVM_H
3 4
diff --git a/tools/arch/x86/include/uapi/asm/unistd.h b/tools/arch/x86/include/uapi/asm/unistd.h
index a26df0d75cd0..30d7d04d72d6 100644
--- a/tools/arch/x86/include/uapi/asm/unistd.h
+++ b/tools/arch/x86/include/uapi/asm/unistd.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_ASM_X86_UNISTD_H 2#ifndef _UAPI_ASM_X86_UNISTD_H
2#define _UAPI_ASM_X86_UNISTD_H 3#define _UAPI_ASM_X86_UNISTD_H
3 4
diff --git a/tools/arch/x86/include/uapi/asm/vmx.h b/tools/arch/x86/include/uapi/asm/vmx.h
index 690a2dcf4078..f0b0c90dd398 100644
--- a/tools/arch/x86/include/uapi/asm/vmx.h
+++ b/tools/arch/x86/include/uapi/asm/vmx.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * vmx.h: VMX Architecture related definitions 3 * vmx.h: VMX Architecture related definitions
3 * Copyright (c) 2004, Intel Corporation. 4 * Copyright (c) 2004, Intel Corporation.
diff --git a/tools/arch/x86/lib/memcpy_64.S b/tools/arch/x86/lib/memcpy_64.S
index 98dcc112b363..9a53a06e5a3e 100644
--- a/tools/arch/x86/lib/memcpy_64.S
+++ b/tools/arch/x86/lib/memcpy_64.S
@@ -4,6 +4,7 @@
4#include <asm/errno.h> 4#include <asm/errno.h>
5#include <asm/cpufeatures.h> 5#include <asm/cpufeatures.h>
6#include <asm/alternative-asm.h> 6#include <asm/alternative-asm.h>
7#include <asm/export.h>
7 8
8/* 9/*
9 * We build a jump to memcpy_orig by default which gets NOPped out on 10 * We build a jump to memcpy_orig by default which gets NOPped out on
@@ -40,6 +41,8 @@ ENTRY(memcpy)
40 ret 41 ret
41ENDPROC(memcpy) 42ENDPROC(memcpy)
42ENDPROC(__memcpy) 43ENDPROC(__memcpy)
44EXPORT_SYMBOL(memcpy)
45EXPORT_SYMBOL(__memcpy)
43 46
44/* 47/*
45 * memcpy_erms() - enhanced fast string memcpy. This is faster and 48 * memcpy_erms() - enhanced fast string memcpy. This is faster and
@@ -274,6 +277,7 @@ ENTRY(memcpy_mcsafe_unrolled)
274 xorq %rax, %rax 277 xorq %rax, %rax
275 ret 278 ret
276ENDPROC(memcpy_mcsafe_unrolled) 279ENDPROC(memcpy_mcsafe_unrolled)
280EXPORT_SYMBOL_GPL(memcpy_mcsafe_unrolled)
277 281
278 .section .fixup, "ax" 282 .section .fixup, "ax"
279 /* Return -EFAULT for any failure */ 283 /* Return -EFAULT for any failure */
diff --git a/tools/arch/x86/lib/memset_64.S b/tools/arch/x86/lib/memset_64.S
index e1229ecd2a82..f8f3dc0a6690 100644
--- a/tools/arch/x86/lib/memset_64.S
+++ b/tools/arch/x86/lib/memset_64.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Copyright 2002 Andi Kleen, SuSE Labs */ 2/* Copyright 2002 Andi Kleen, SuSE Labs */
2 3
3#include <linux/linkage.h> 4#include <linux/linkage.h>
diff --git a/tools/arch/xtensa/include/uapi/asm/mman.h b/tools/arch/xtensa/include/uapi/asm/mman.h
index 4453195c450c..34dde6f44dae 100644
--- a/tools/arch/xtensa/include/uapi/asm/mman.h
+++ b/tools/arch/xtensa/include/uapi/asm/mman.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H 2#ifndef TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
2#define TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H 3#define TOOLS_ARCH_XTENSA_UAPI_ASM_MMAN_FIX_H
3#define MADV_DODUMP 17 4#define MADV_DODUMP 17
diff --git a/tools/net/Makefile b/tools/bpf/Makefile
index ddf888010652..07a6697466ef 100644
--- a/tools/net/Makefile
+++ b/tools/bpf/Makefile
@@ -1,8 +1,10 @@
1# SPDX-License-Identifier: GPL-2.0
1prefix = /usr 2prefix = /usr
2 3
3CC = gcc 4CC = gcc
4LEX = flex 5LEX = flex
5YACC = bison 6YACC = bison
7MAKE = make
6 8
7CFLAGS += -Wall -O2 9CFLAGS += -Wall -O2
8CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include 10CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
@@ -13,7 +15,7 @@ CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
13%.lex.c: %.l 15%.lex.c: %.l
14 $(LEX) -o $@ $< 16 $(LEX) -o $@ $<
15 17
16all : bpf_jit_disasm bpf_dbg bpf_asm 18all: bpf_jit_disasm bpf_dbg bpf_asm bpftool
17 19
18bpf_jit_disasm : CFLAGS += -DPACKAGE='bpf_jit_disasm' 20bpf_jit_disasm : CFLAGS += -DPACKAGE='bpf_jit_disasm'
19bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl 21bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl
@@ -26,10 +28,21 @@ bpf_asm : LDLIBS =
26bpf_asm : bpf_asm.o bpf_exp.yacc.o bpf_exp.lex.o 28bpf_asm : bpf_asm.o bpf_exp.yacc.o bpf_exp.lex.o
27bpf_exp.lex.o : bpf_exp.yacc.c 29bpf_exp.lex.o : bpf_exp.yacc.c
28 30
29clean : 31clean: bpftool_clean
30 rm -rf *.o bpf_jit_disasm bpf_dbg bpf_asm bpf_exp.yacc.* bpf_exp.lex.* 32 rm -rf *.o bpf_jit_disasm bpf_dbg bpf_asm bpf_exp.yacc.* bpf_exp.lex.*
31 33
32install : 34install: bpftool_install
33 install bpf_jit_disasm $(prefix)/bin/bpf_jit_disasm 35 install bpf_jit_disasm $(prefix)/bin/bpf_jit_disasm
34 install bpf_dbg $(prefix)/bin/bpf_dbg 36 install bpf_dbg $(prefix)/bin/bpf_dbg
35 install bpf_asm $(prefix)/bin/bpf_asm 37 install bpf_asm $(prefix)/bin/bpf_asm
38
39bpftool:
40 $(MAKE) -C bpftool
41
42bpftool_install:
43 $(MAKE) -C bpftool install
44
45bpftool_clean:
46 $(MAKE) -C bpftool clean
47
48.PHONY: bpftool FORCE
diff --git a/tools/net/bpf_asm.c b/tools/bpf/bpf_asm.c
index c15aef097b04..c15aef097b04 100644
--- a/tools/net/bpf_asm.c
+++ b/tools/bpf/bpf_asm.c
diff --git a/tools/net/bpf_dbg.c b/tools/bpf/bpf_dbg.c
index 4f254bcc4423..4f254bcc4423 100644
--- a/tools/net/bpf_dbg.c
+++ b/tools/bpf/bpf_dbg.c
diff --git a/tools/net/bpf_exp.l b/tools/bpf/bpf_exp.l
index bd83149e7be0..bd83149e7be0 100644
--- a/tools/net/bpf_exp.l
+++ b/tools/bpf/bpf_exp.l
diff --git a/tools/net/bpf_exp.y b/tools/bpf/bpf_exp.y
index 56ba1de50784..56ba1de50784 100644
--- a/tools/net/bpf_exp.y
+++ b/tools/bpf/bpf_exp.y
diff --git a/tools/net/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c
index 422d9abd666a..75bf526a0168 100644
--- a/tools/net/bpf_jit_disasm.c
+++ b/tools/bpf/bpf_jit_disasm.c
@@ -27,6 +27,7 @@
27#include <sys/klog.h> 27#include <sys/klog.h>
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <limits.h>
30 31
31#define CMD_ACTION_SIZE_BUFFER 10 32#define CMD_ACTION_SIZE_BUFFER 10
32#define CMD_ACTION_READ_ALL 3 33#define CMD_ACTION_READ_ALL 3
@@ -51,7 +52,7 @@ static void get_exec_path(char *tpath, size_t size)
51static void get_asm_insns(uint8_t *image, size_t len, int opcodes) 52static void get_asm_insns(uint8_t *image, size_t len, int opcodes)
52{ 53{
53 int count, i, pc = 0; 54 int count, i, pc = 0;
54 char tpath[256]; 55 char tpath[PATH_MAX];
55 struct disassemble_info info; 56 struct disassemble_info info;
56 disassembler_ftype disassemble; 57 disassembler_ftype disassemble;
57 bfd *bfdf; 58 bfd *bfdf;
diff --git a/tools/bpf/bpftool/Documentation/Makefile b/tools/bpf/bpftool/Documentation/Makefile
new file mode 100644
index 000000000000..bde77d7c4390
--- /dev/null
+++ b/tools/bpf/bpftool/Documentation/Makefile
@@ -0,0 +1,34 @@
1include ../../../scripts/Makefile.include
2include ../../../scripts/utilities.mak
3
4INSTALL ?= install
5RM ?= rm -f
6
7# Make the path relative to DESTDIR, not prefix
8ifndef DESTDIR
9prefix?=$(HOME)
10endif
11mandir ?= $(prefix)/share/man
12man8dir = $(mandir)/man8
13
14MAN8_RST = $(wildcard *.rst)
15
16_DOC_MAN8 = $(patsubst %.rst,%.8,$(MAN8_RST))
17DOC_MAN8 = $(addprefix $(OUTPUT),$(_DOC_MAN8))
18
19man: man8
20man8: $(DOC_MAN8)
21
22$(OUTPUT)%.8: %.rst
23 rst2man $< > $@
24
25clean:
26 $(call QUIET_CLEAN, Documentation) $(RM) $(DOC_MAN8)
27
28install: man
29 $(call QUIET_INSTALL, Documentation-man) \
30 $(INSTALL) -d -m 755 $(DESTDIR)$(man8dir); \
31 $(INSTALL) -m 644 $(DOC_MAN8) $(DESTDIR)$(man8dir);
32
33.PHONY: man man8 clean install
34.DEFAULT_GOAL := man
diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst b/tools/bpf/bpftool/Documentation/bpftool-map.rst
new file mode 100644
index 000000000000..9f51a268eb06
--- /dev/null
+++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst
@@ -0,0 +1,131 @@
1================
2bpftool-map
3================
4-------------------------------------------------------------------------------
5tool for inspection and simple manipulation of eBPF maps
6-------------------------------------------------------------------------------
7
8:Manual section: 8
9
10SYNOPSIS
11========
12
13 **bpftool** [*OPTIONS*] **map** *COMMAND*
14
15 *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
16
17 *COMMANDS* :=
18 { **show** | **dump** | **update** | **lookup** | **getnext** | **delete**
19 | **pin** | **help** }
20
21MAP COMMANDS
22=============
23
24| **bpftool** **map show** [*MAP*]
25| **bpftool** **map dump** *MAP*
26| **bpftool** **map update** *MAP* **key** *BYTES* **value** *VALUE* [*UPDATE_FLAGS*]
27| **bpftool** **map lookup** *MAP* **key** *BYTES*
28| **bpftool** **map getnext** *MAP* [**key** *BYTES*]
29| **bpftool** **map delete** *MAP* **key** *BYTES*
30| **bpftool** **map pin** *MAP* *FILE*
31| **bpftool** **map help**
32|
33| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
34| *VALUE* := { *BYTES* | *MAP* | *PROGRAM* }
35| *UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
36
37DESCRIPTION
38===========
39 **bpftool map show** [*MAP*]
40 Show information about loaded maps. If *MAP* is specified
41 show information only about given map, otherwise list all
42 maps currently loaded on the system.
43
44 Output will start with map ID followed by map type and
45 zero or more named attributes (depending on kernel version).
46
47 **bpftool map dump** *MAP*
48 Dump all entries in a given *MAP*.
49
50 **bpftool map update** *MAP* **key** *BYTES* **value** *VALUE* [*UPDATE_FLAGS*]
51 Update map entry for a given *KEY*.
52
53 *UPDATE_FLAGS* can be one of: **any** update existing entry
54 or add if doesn't exit; **exist** update only if entry already
55 exists; **noexist** update only if entry doesn't exist.
56
57 **bpftool map lookup** *MAP* **key** *BYTES*
58 Lookup **key** in the map.
59
60 **bpftool map getnext** *MAP* [**key** *BYTES*]
61 Get next key. If *key* is not specified, get first key.
62
63 **bpftool map delete** *MAP* **key** *BYTES*
64 Remove entry from the map.
65
66 **bpftool map pin** *MAP* *FILE*
67 Pin map *MAP* as *FILE*.
68
69 Note: *FILE* must be located in *bpffs* mount.
70
71 **bpftool map help**
72 Print short help message.
73
74OPTIONS
75=======
76 -h, --help
77 Print short generic help message (similar to **bpftool help**).
78
79 -v, --version
80 Print version number (similar to **bpftool version**).
81
82 -j, --json
83 Generate JSON output. For commands that cannot produce JSON, this
84 option has no effect.
85
86 -p, --pretty
87 Generate human-readable JSON output. Implies **-j**.
88
89 -f, --bpffs
90 Show file names of pinned maps.
91
92EXAMPLES
93========
94**# bpftool map show**
95::
96
97 10: hash name some_map flags 0x0
98 key 4B value 8B max_entries 2048 memlock 167936B
99
100**# bpftool map update id 10 key 13 00 07 00 value 02 00 00 00 01 02 03 04**
101
102**# bpftool map lookup id 10 key 0 1 2 3**
103
104::
105
106 key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
107
108
109**# bpftool map dump id 10**
110::
111
112 key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
113 key: 0d 00 07 00 value: 02 00 00 00 01 02 03 04
114 Found 2 elements
115
116**# bpftool map getnext id 10 key 0 1 2 3**
117::
118
119 key:
120 00 01 02 03
121 next key:
122 0d 00 07 00
123
124|
125| **# mount -t bpf none /sys/fs/bpf/**
126| **# bpftool map pin id 10 /sys/fs/bpf/map**
127| **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**
128
129SEE ALSO
130========
131 **bpftool**\ (8), **bpftool-prog**\ (8)
diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
new file mode 100644
index 000000000000..36e8d1c3c40d
--- /dev/null
+++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
@@ -0,0 +1,150 @@
1================
2bpftool-prog
3================
4-------------------------------------------------------------------------------
5tool for inspection and simple manipulation of eBPF progs
6-------------------------------------------------------------------------------
7
8:Manual section: 8
9
10SYNOPSIS
11========
12
13 **bpftool** [*OPTIONS*] **prog** *COMMAND*
14
15 *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
16
17 *COMMANDS* :=
18 { **show** | **dump xlated** | **dump jited** | **pin** | **help** }
19
20MAP COMMANDS
21=============
22
23| **bpftool** **prog show** [*PROG*]
24| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes**}]
25| **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}]
26| **bpftool** **prog pin** *PROG* *FILE*
27| **bpftool** **prog help**
28|
29| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
30
31DESCRIPTION
32===========
33 **bpftool prog show** [*PROG*]
34 Show information about loaded programs. If *PROG* is
35 specified show information only about given program, otherwise
36 list all programs currently loaded on the system.
37
38 Output will start with program ID followed by program type and
39 zero or more named attributes (depending on kernel version).
40
41 **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** }]
42 Dump eBPF instructions of the program from the kernel.
43 If *FILE* is specified image will be written to a file,
44 otherwise it will be disassembled and printed to stdout.
45
46 **opcodes** controls if raw opcodes will be printed.
47
48 **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** }]
49 Dump jited image (host machine code) of the program.
50 If *FILE* is specified image will be written to a file,
51 otherwise it will be disassembled and printed to stdout.
52
53 **opcodes** controls if raw opcodes will be printed.
54
55 **bpftool prog pin** *PROG* *FILE*
56 Pin program *PROG* as *FILE*.
57
58 Note: *FILE* must be located in *bpffs* mount.
59
60 **bpftool prog help**
61 Print short help message.
62
63OPTIONS
64=======
65 -h, --help
66 Print short generic help message (similar to **bpftool help**).
67
68 -v, --version
69 Print version number (similar to **bpftool version**).
70
71 -j, --json
72 Generate JSON output. For commands that cannot produce JSON, this
73 option has no effect.
74
75 -p, --pretty
76 Generate human-readable JSON output. Implies **-j**.
77
78 -f, --bpffs
79 Show file names of pinned programs.
80
81EXAMPLES
82========
83**# bpftool prog show**
84::
85
86 10: xdp name some_prog tag 005a3d2123620c8b
87 loaded_at Sep 29/20:11 uid 0
88 xlated 528B jited 370B memlock 4096B map_ids 10
89
90**# bpftool --json --pretty prog show**
91
92::
93
94 {
95 "programs": [{
96 "id": 10,
97 "type": "xdp",
98 "tag": "005a3d2123620c8b",
99 "loaded_at": "Sep 29/20:11",
100 "uid": 0,
101 "bytes_xlated": 528,
102 "jited": true,
103 "bytes_jited": 370,
104 "bytes_memlock": 4096,
105 "map_ids": [10
106 ]
107 }
108 ]
109 }
110
111|
112| **# bpftool prog dump xlated id 10 file /tmp/t**
113| **# ls -l /tmp/t**
114| -rw------- 1 root root 560 Jul 22 01:42 /tmp/t
115
116**# bpftool prog dum jited tag 005a3d2123620c8b**
117
118::
119
120 push %rbp
121 mov %rsp,%rbp
122 sub $0x228,%rsp
123 sub $0x28,%rbp
124 mov %rbx,0x0(%rbp)
125
126|
127| **# mount -t bpf none /sys/fs/bpf/**
128| **# bpftool prog pin id 10 /sys/fs/bpf/prog**
129| **# ls -l /sys/fs/bpf/**
130| -rw------- 1 root root 0 Jul 22 01:43 prog
131
132**# bpftool prog dum jited pinned /sys/fs/bpf/prog opcodes**
133
134::
135
136 push %rbp
137 55
138 mov %rsp,%rbp
139 48 89 e5
140 sub $0x228,%rsp
141 48 81 ec 28 02 00 00
142 sub $0x28,%rbp
143 48 83 ed 28
144 mov %rbx,0x0(%rbp)
145 48 89 5d 00
146
147
148SEE ALSO
149========
150 **bpftool**\ (8), **bpftool-map**\ (8)
diff --git a/tools/bpf/bpftool/Documentation/bpftool.rst b/tools/bpf/bpftool/Documentation/bpftool.rst
new file mode 100644
index 000000000000..926c03d5a8da
--- /dev/null
+++ b/tools/bpf/bpftool/Documentation/bpftool.rst
@@ -0,0 +1,56 @@
1================
2BPFTOOL
3================
4-------------------------------------------------------------------------------
5tool for inspection and simple manipulation of eBPF programs and maps
6-------------------------------------------------------------------------------
7
8:Manual section: 8
9
10SYNOPSIS
11========
12
13 **bpftool** [*OPTIONS*] *OBJECT* { *COMMAND* | **help** }
14
15 **bpftool** **batch file** *FILE*
16
17 **bpftool** **version**
18
19 *OBJECT* := { **map** | **program** }
20
21 *OPTIONS* := { { **-V** | **--version** } | { **-h** | **--help** }
22 | { **-j** | **--json** } [{ **-p** | **--pretty** }] }
23
24 *MAP-COMMANDS* :=
25 { **show** | **dump** | **update** | **lookup** | **getnext** | **delete**
26 | **pin** | **help** }
27
28 *PROG-COMMANDS* := { **show** | **dump jited** | **dump xlated** | **pin**
29 | **help** }
30
31DESCRIPTION
32===========
33 *bpftool* allows for inspection and simple modification of BPF objects
34 on the system.
35
36 Note that format of the output of all tools is not guaranteed to be
37 stable and should not be depended upon.
38
39OPTIONS
40=======
41 -h, --help
42 Print short help message (similar to **bpftool help**).
43
44 -v, --version
45 Print version number (similar to **bpftool version**).
46
47 -j, --json
48 Generate JSON output. For commands that cannot produce JSON, this
49 option has no effect.
50
51 -p, --pretty
52 Generate human-readable JSON output. Implies **-j**.
53
54SEE ALSO
55========
56 **bpftool-map**\ (8), **bpftool-prog**\ (8)
diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
new file mode 100644
index 000000000000..813826c50936
--- /dev/null
+++ b/tools/bpf/bpftool/Makefile
@@ -0,0 +1,92 @@
1include ../../scripts/Makefile.include
2
3include ../../scripts/utilities.mak
4
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8srctree := $(patsubst %/,%,$(dir $(srctree)))
9#$(info Determined 'srctree' to be $(srctree))
10endif
11
12ifneq ($(objtree),)
13#$(info Determined 'objtree' to be $(objtree))
14endif
15
16ifneq ($(OUTPUT),)
17#$(info Determined 'OUTPUT' to be $(OUTPUT))
18# Adding $(OUTPUT) as a directory to look for source files,
19# because use generated output files as sources dependency
20# for flex/bison parsers.
21VPATH += $(OUTPUT)
22export VPATH
23endif
24
25ifeq ($(V),1)
26 Q =
27else
28 Q = @
29endif
30
31BPF_DIR = $(srctree)/tools/lib/bpf/
32
33ifneq ($(OUTPUT),)
34 BPF_PATH=$(OUTPUT)
35else
36 BPF_PATH=$(BPF_DIR)
37endif
38
39LIBBPF = $(BPF_PATH)libbpf.a
40
41$(LIBBPF): FORCE
42 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)
43
44$(LIBBPF)-clean:
45 $(call QUIET_CLEAN, libbpf)
46 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
47
48prefix = /usr
49bash_compdir ?= $(prefix)/share/bash-completion/completions
50
51CC = gcc
52
53CFLAGS += -O2
54CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow
55CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/
56LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
57
58include $(wildcard *.d)
59
60all: $(OUTPUT)bpftool
61
62SRCS=$(wildcard *.c)
63OBJS=$(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
64
65$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
66 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
67
68$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
69 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
70
71$(OUTPUT)%.o: %.c
72 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
73
74clean: $(LIBBPF)-clean
75 $(call QUIET_CLEAN, bpftool)
76 $(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
77
78install:
79 install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
80 install -m 0755 -d $(bash_compdir)
81 install -m 0644 bash-completion/bpftool $(bash_compdir)
82
83doc:
84 $(Q)$(MAKE) -C Documentation/
85
86doc-install:
87 $(Q)$(MAKE) -C Documentation/ install
88
89FORCE:
90
91.PHONY: all clean FORCE
92.DEFAULT_GOAL := all
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
new file mode 100644
index 000000000000..7febee05c8e7
--- /dev/null
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -0,0 +1,354 @@
1# bpftool(8) bash completion -*- shell-script -*-
2#
3# Copyright (C) 2017 Netronome Systems, Inc.
4#
5# This software is dual licensed under the GNU General License
6# Version 2, June 1991 as shown in the file COPYING in the top-level
7# directory of this source tree or the BSD 2-Clause License provided
8# below. You have the option to license this software under the
9# complete terms of either license.
10#
11# The BSD 2-Clause License:
12#
13# Redistribution and use in source and binary forms, with or
14# without modification, are permitted provided that the following
15# conditions are met:
16#
17# 1. Redistributions of source code must retain the above
18# copyright notice, this list of conditions and the following
19# disclaimer.
20#
21# 2. Redistributions in binary form must reproduce the above
22# copyright notice, this list of conditions and the following
23# disclaimer in the documentation and/or other materials
24# provided with the distribution.
25#
26# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33# SOFTWARE.
34#
35# Author: Quentin Monnet <quentin.monnet@netronome.com>
36
37# Takes a list of words in argument; each one of them is added to COMPREPLY if
38# it is not already present on the command line. Returns no value.
39_bpftool_once_attr()
40{
41 local w idx found
42 for w in $*; do
43 found=0
44 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
45 if [[ $w == ${words[idx]} ]]; then
46 found=1
47 break
48 fi
49 done
50 [[ $found -eq 0 ]] && \
51 COMPREPLY+=( $( compgen -W "$w" -- "$cur" ) )
52 done
53}
54
55# Takes a list of words in argument; adds them all to COMPREPLY if none of them
56# is already present on the command line. Returns no value.
57_bpftool_one_of_list()
58{
59 local w idx
60 for w in $*; do
61 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
62 [[ $w == ${words[idx]} ]] && return 1
63 done
64 done
65 COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )
66}
67
68_bpftool_get_map_ids()
69{
70 COMPREPLY+=( $( compgen -W "$( bpftool -jp map 2>&1 | \
71 command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
72}
73
74_bpftool_get_prog_ids()
75{
76 COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
77 command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
78}
79
80_bpftool_get_prog_tags()
81{
82 COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
83 command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
84}
85
86# For bpftool map update: retrieve type of the map to update.
87_bpftool_map_update_map_type()
88{
89 local keyword ref
90 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
91 if [[ ${words[$((idx-2))]} == "update" ]]; then
92 keyword=${words[$((idx-1))]}
93 ref=${words[$((idx))]}
94 fi
95 done
96 [[ -z $ref ]] && return 0
97
98 local type
99 type=$(bpftool -jp map show $keyword $ref | \
100 command sed -n 's/.*"type": "\(.*\)",$/\1/p')
101 printf $type
102}
103
104_bpftool_map_update_get_id()
105{
106 # Is it the map to update, or a map to insert into the map to update?
107 # Search for "value" keyword.
108 local idx value
109 for (( idx=7; idx < ${#words[@]}-1; idx++ )); do
110 if [[ ${words[idx]} == "value" ]]; then
111 value=1
112 break
113 fi
114 done
115 [[ $value -eq 0 ]] && _bpftool_get_map_ids && return 0
116
117 # Id to complete is for a value. It can be either prog id or map id. This
118 # depends on the type of the map to update.
119 local type=$(_bpftool_map_update_map_type)
120 case $type in
121 array_of_maps|hash_of_maps)
122 _bpftool_get_map_ids
123 return 0
124 ;;
125 prog_array)
126 _bpftool_get_prog_ids
127 return 0
128 ;;
129 *)
130 return 0
131 ;;
132 esac
133}
134
135_bpftool()
136{
137 local cur prev words objword
138 _init_completion || return
139
140 # Deal with simplest keywords
141 case $prev in
142 help|key|opcodes)
143 return 0
144 ;;
145 tag)
146 _bpftool_get_prog_tags
147 return 0
148 ;;
149 file|pinned)
150 _filedir
151 return 0
152 ;;
153 batch)
154 COMPREPLY=( $( compgen -W 'file' -- "$cur" ) )
155 return 0
156 ;;
157 esac
158
159 # Search for object and command
160 local object command cmdword
161 for (( cmdword=1; cmdword < ${#words[@]}-1; cmdword++ )); do
162 [[ -n $object ]] && command=${words[cmdword]} && break
163 [[ ${words[cmdword]} != -* ]] && object=${words[cmdword]}
164 done
165
166 if [[ -z $object ]]; then
167 case $cur in
168 -*)
169 local c='--version --json --pretty'
170 COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
171 return 0
172 ;;
173 *)
174 COMPREPLY=( $( compgen -W "$( bpftool help 2>&1 | \
175 command sed \
176 -e '/OBJECT := /!d' \
177 -e 's/.*{//' \
178 -e 's/}.*//' \
179 -e 's/|//g' )" -- "$cur" ) )
180 COMPREPLY+=( $( compgen -W 'batch help' -- "$cur" ) )
181 return 0
182 ;;
183 esac
184 fi
185
186 [[ $command == help ]] && return 0
187
188 # Completion depends on object and command in use
189 case $object in
190 prog)
191 case $prev in
192 id)
193 _bpftool_get_prog_ids
194 return 0
195 ;;
196 esac
197
198 local PROG_TYPE='id pinned tag'
199 case $command in
200 show)
201 [[ $prev != "$command" ]] && return 0
202 COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
203 return 0
204 ;;
205 dump)
206 case $prev in
207 $command)
208 COMPREPLY+=( $( compgen -W "xlated jited" -- \
209 "$cur" ) )
210 return 0
211 ;;
212 xlated|jited)
213 COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
214 "$cur" ) )
215 return 0
216 ;;
217 *)
218 _bpftool_once_attr 'file'
219 COMPREPLY+=( $( compgen -W 'opcodes' -- \
220 "$cur" ) )
221 return 0
222 ;;
223 esac
224 ;;
225 pin)
226 if [[ $prev == "$command" ]]; then
227 COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
228 else
229 _filedir
230 fi
231 return 0
232 ;;
233 *)
234 [[ $prev == $object ]] && \
235 COMPREPLY=( $( compgen -W 'dump help pin show' -- \
236 "$cur" ) )
237 ;;
238 esac
239 ;;
240 map)
241 local MAP_TYPE='id pinned'
242 case $command in
243 show|dump)
244 case $prev in
245 $command)
246 COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
247 return 0
248 ;;
249 id)
250 _bpftool_get_map_ids
251 return 0
252 ;;
253 *)
254 return 0
255 ;;
256 esac
257 ;;
258 lookup|getnext|delete)
259 case $prev in
260 $command)
261 COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
262 return 0
263 ;;
264 id)
265 _bpftool_get_map_ids
266 return 0
267 ;;
268 key)
269 return 0
270 ;;
271 *)
272 _bpftool_once_attr 'key'
273 return 0
274 ;;
275 esac
276 ;;
277 update)
278 case $prev in
279 $command)
280 COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
281 return 0
282 ;;
283 id)
284 _bpftool_map_update_get_id
285 return 0
286 ;;
287 key)
288 return 0
289 ;;
290 value)
291 # We can have bytes, or references to a prog or a
292 # map, depending on the type of the map to update.
293 case $(_bpftool_map_update_map_type) in
294 array_of_maps|hash_of_maps)
295 local MAP_TYPE='id pinned'
296 COMPREPLY+=( $( compgen -W "$MAP_TYPE" \
297 -- "$cur" ) )
298 return 0
299 ;;
300 prog_array)
301 local PROG_TYPE='id pinned tag'
302 COMPREPLY+=( $( compgen -W "$PROG_TYPE" \
303 -- "$cur" ) )
304 return 0
305 ;;
306 *)
307 return 0
308 ;;
309 esac
310 return 0
311 ;;
312 *)
313 _bpftool_once_attr 'key'
314 local UPDATE_FLAGS='any exist noexist'
315 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
316 if [[ ${words[idx]} == 'value' ]]; then
317 # 'value' is present, but is not the last
318 # word i.e. we can now have UPDATE_FLAGS.
319 _bpftool_one_of_list "$UPDATE_FLAGS"
320 return 0
321 fi
322 done
323 for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
324 if [[ ${words[idx]} == 'key' ]]; then
325 # 'key' is present, but is not the last
326 # word i.e. we can now have 'value'.
327 _bpftool_once_attr 'value'
328 return 0
329 fi
330 done
331 return 0
332 ;;
333 esac
334 ;;
335 pin)
336 if [[ $prev == "$command" ]]; then
337 COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
338 else
339 _filedir
340 fi
341 return 0
342 ;;
343 *)
344 [[ $prev == $object ]] && \
345 COMPREPLY=( $( compgen -W 'delete dump getnext help \
346 lookup pin show update' -- "$cur" ) )
347 ;;
348 esac
349 ;;
350 esac
351} &&
352complete -F _bpftool bpftool
353
354# ex: ts=4 sw=4 et filetype=sh
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
new file mode 100644
index 000000000000..2bd3b280e6dd
--- /dev/null
+++ b/tools/bpf/bpftool/common.c
@@ -0,0 +1,405 @@
1/*
2 * Copyright (C) 2017 Netronome Systems, Inc.
3 *
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
8 *
9 * The BSD 2-Clause License:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34/* Author: Jakub Kicinski <kubakici@wp.pl> */
35
36#include <errno.h>
37#include <fts.h>
38#include <libgen.h>
39#include <mntent.h>
40#include <stdbool.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <unistd.h>
45#include <linux/limits.h>
46#include <linux/magic.h>
47#include <sys/mount.h>
48#include <sys/types.h>
49#include <sys/vfs.h>
50
51#include <bpf.h>
52
53#include "main.h"
54
55void p_err(const char *fmt, ...)
56{
57 va_list ap;
58
59 va_start(ap, fmt);
60 if (json_output) {
61 jsonw_start_object(json_wtr);
62 jsonw_name(json_wtr, "error");
63 jsonw_vprintf_enquote(json_wtr, fmt, ap);
64 jsonw_end_object(json_wtr);
65 } else {
66 fprintf(stderr, "Error: ");
67 vfprintf(stderr, fmt, ap);
68 fprintf(stderr, "\n");
69 }
70 va_end(ap);
71}
72
73void p_info(const char *fmt, ...)
74{
75 va_list ap;
76
77 if (json_output)
78 return;
79
80 va_start(ap, fmt);
81 vfprintf(stderr, fmt, ap);
82 fprintf(stderr, "\n");
83 va_end(ap);
84}
85
86static bool is_bpffs(char *path)
87{
88 struct statfs st_fs;
89
90 if (statfs(path, &st_fs) < 0)
91 return false;
92
93 return (unsigned long)st_fs.f_type == BPF_FS_MAGIC;
94}
95
96static int mnt_bpffs(const char *target, char *buff, size_t bufflen)
97{
98 bool bind_done = false;
99
100 while (mount("", target, "none", MS_PRIVATE | MS_REC, NULL)) {
101 if (errno != EINVAL || bind_done) {
102 snprintf(buff, bufflen,
103 "mount --make-private %s failed: %s",
104 target, strerror(errno));
105 return -1;
106 }
107
108 if (mount(target, target, "none", MS_BIND, NULL)) {
109 snprintf(buff, bufflen,
110 "mount --bind %s %s failed: %s",
111 target, target, strerror(errno));
112 return -1;
113 }
114
115 bind_done = true;
116 }
117
118 if (mount("bpf", target, "bpf", 0, "mode=0700")) {
119 snprintf(buff, bufflen, "mount -t bpf bpf %s failed: %s",
120 target, strerror(errno));
121 return -1;
122 }
123
124 return 0;
125}
126
127int open_obj_pinned(char *path)
128{
129 int fd;
130
131 fd = bpf_obj_get(path);
132 if (fd < 0) {
133 p_err("bpf obj get (%s): %s", path,
134 errno == EACCES && !is_bpffs(dirname(path)) ?
135 "directory not in bpf file system (bpffs)" :
136 strerror(errno));
137 return -1;
138 }
139
140 return fd;
141}
142
143int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type)
144{
145 enum bpf_obj_type type;
146 int fd;
147
148 fd = open_obj_pinned(path);
149 if (fd < 0)
150 return -1;
151
152 type = get_fd_type(fd);
153 if (type < 0) {
154 close(fd);
155 return type;
156 }
157 if (type != exp_type) {
158 p_err("incorrect object type: %s", get_fd_type_name(type));
159 close(fd);
160 return -1;
161 }
162
163 return fd;
164}
165
166int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
167{
168 char err_str[ERR_MAX_LEN];
169 unsigned int id;
170 char *endptr;
171 char *file;
172 char *dir;
173 int err;
174 int fd;
175
176 if (!is_prefix(*argv, "id")) {
177 p_err("expected 'id' got %s", *argv);
178 return -1;
179 }
180 NEXT_ARG();
181
182 id = strtoul(*argv, &endptr, 0);
183 if (*endptr) {
184 p_err("can't parse %s as ID", *argv);
185 return -1;
186 }
187 NEXT_ARG();
188
189 if (argc != 1)
190 usage();
191
192 fd = get_fd_by_id(id);
193 if (fd < 0) {
194 p_err("can't get prog by id (%u): %s", id, strerror(errno));
195 return -1;
196 }
197
198 err = bpf_obj_pin(fd, *argv);
199 if (!err)
200 goto out_close;
201
202 file = malloc(strlen(*argv) + 1);
203 strcpy(file, *argv);
204 dir = dirname(file);
205
206 if (errno != EPERM || is_bpffs(dir)) {
207 p_err("can't pin the object (%s): %s", *argv, strerror(errno));
208 goto out_free;
209 }
210
211 /* Attempt to mount bpffs, then retry pinning. */
212 err = mnt_bpffs(dir, err_str, ERR_MAX_LEN);
213 if (!err) {
214 err = bpf_obj_pin(fd, *argv);
215 if (err)
216 p_err("can't pin the object (%s): %s", *argv,
217 strerror(errno));
218 } else {
219 err_str[ERR_MAX_LEN - 1] = '\0';
220 p_err("can't mount BPF file system to pin the object (%s): %s",
221 *argv, err_str);
222 }
223
224out_free:
225 free(file);
226out_close:
227 close(fd);
228 return err;
229}
230
231const char *get_fd_type_name(enum bpf_obj_type type)
232{
233 static const char * const names[] = {
234 [BPF_OBJ_UNKNOWN] = "unknown",
235 [BPF_OBJ_PROG] = "prog",
236 [BPF_OBJ_MAP] = "map",
237 };
238
239 if (type < 0 || type >= ARRAY_SIZE(names) || !names[type])
240 return names[BPF_OBJ_UNKNOWN];
241
242 return names[type];
243}
244
245int get_fd_type(int fd)
246{
247 char path[PATH_MAX];
248 char buf[512];
249 ssize_t n;
250
251 snprintf(path, sizeof(path), "/proc/%d/fd/%d", getpid(), fd);
252
253 n = readlink(path, buf, sizeof(buf));
254 if (n < 0) {
255 p_err("can't read link type: %s", strerror(errno));
256 return -1;
257 }
258 if (n == sizeof(path)) {
259 p_err("can't read link type: path too long!");
260 return -1;
261 }
262
263 if (strstr(buf, "bpf-map"))
264 return BPF_OBJ_MAP;
265 else if (strstr(buf, "bpf-prog"))
266 return BPF_OBJ_PROG;
267
268 return BPF_OBJ_UNKNOWN;
269}
270
271char *get_fdinfo(int fd, const char *key)
272{
273 char path[PATH_MAX];
274 char *line = NULL;
275 size_t line_n = 0;
276 ssize_t n;
277 FILE *fdi;
278
279 snprintf(path, sizeof(path), "/proc/%d/fdinfo/%d", getpid(), fd);
280
281 fdi = fopen(path, "r");
282 if (!fdi) {
283 p_err("can't open fdinfo: %s", strerror(errno));
284 return NULL;
285 }
286
287 while ((n = getline(&line, &line_n, fdi))) {
288 char *value;
289 int len;
290
291 if (!strstr(line, key))
292 continue;
293
294 fclose(fdi);
295
296 value = strchr(line, '\t');
297 if (!value || !value[1]) {
298 p_err("malformed fdinfo!?");
299 free(line);
300 return NULL;
301 }
302 value++;
303
304 len = strlen(value);
305 memmove(line, value, len);
306 line[len - 1] = '\0';
307
308 return line;
309 }
310
311 p_err("key '%s' not found in fdinfo", key);
312 free(line);
313 fclose(fdi);
314 return NULL;
315}
316
317void print_hex_data_json(uint8_t *data, size_t len)
318{
319 unsigned int i;
320
321 jsonw_start_array(json_wtr);
322 for (i = 0; i < len; i++)
323 jsonw_printf(json_wtr, "\"0x%02hhx\"", data[i]);
324 jsonw_end_array(json_wtr);
325}
326
327int build_pinned_obj_table(struct pinned_obj_table *tab,
328 enum bpf_obj_type type)
329{
330 struct bpf_prog_info pinned_info = {};
331 struct pinned_obj *obj_node = NULL;
332 __u32 len = sizeof(pinned_info);
333 struct mntent *mntent = NULL;
334 enum bpf_obj_type objtype;
335 FILE *mntfile = NULL;
336 FTSENT *ftse = NULL;
337 FTS *fts = NULL;
338 int fd, err;
339
340 mntfile = setmntent("/proc/mounts", "r");
341 if (!mntfile)
342 return -1;
343
344 while ((mntent = getmntent(mntfile))) {
345 char *path[] = { mntent->mnt_dir, NULL };
346
347 if (strncmp(mntent->mnt_type, "bpf", 3) != 0)
348 continue;
349
350 fts = fts_open(path, 0, NULL);
351 if (!fts)
352 continue;
353
354 while ((ftse = fts_read(fts))) {
355 if (!(ftse->fts_info & FTS_F))
356 continue;
357 fd = open_obj_pinned(ftse->fts_path);
358 if (fd < 0)
359 continue;
360
361 objtype = get_fd_type(fd);
362 if (objtype != type) {
363 close(fd);
364 continue;
365 }
366 memset(&pinned_info, 0, sizeof(pinned_info));
367 err = bpf_obj_get_info_by_fd(fd, &pinned_info, &len);
368 if (err) {
369 close(fd);
370 continue;
371 }
372
373 obj_node = malloc(sizeof(*obj_node));
374 if (!obj_node) {
375 close(fd);
376 fts_close(fts);
377 fclose(mntfile);
378 return -1;
379 }
380
381 memset(obj_node, 0, sizeof(*obj_node));
382 obj_node->id = pinned_info.id;
383 obj_node->path = strdup(ftse->fts_path);
384 hash_add(tab->table, &obj_node->hash, obj_node->id);
385
386 close(fd);
387 }
388 fts_close(fts);
389 }
390 fclose(mntfile);
391 return 0;
392}
393
394void delete_pinned_obj_table(struct pinned_obj_table *tab)
395{
396 struct pinned_obj *obj;
397 struct hlist_node *tmp;
398 unsigned int bkt;
399
400 hash_for_each_safe(tab->table, bkt, tmp, obj, hash) {
401 hash_del(&obj->hash);
402 free(obj->path);
403 free(obj);
404 }
405}
diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c
new file mode 100644
index 000000000000..1551d3918d4c
--- /dev/null
+++ b/tools/bpf/bpftool/jit_disasm.c
@@ -0,0 +1,162 @@
1/*
2 * Based on:
3 *
4 * Minimal BPF JIT image disassembler
5 *
6 * Disassembles BPF JIT compiler emitted opcodes back to asm insn's for
7 * debugging or verification purposes.
8 *
9 * Copyright 2013 Daniel Borkmann <daniel@iogearbox.net>
10 * Licensed under the GNU General Public License, version 2.0 (GPLv2)
11 */
12
13#include <stdarg.h>
14#include <stdint.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <assert.h>
18#include <unistd.h>
19#include <string.h>
20#include <bfd.h>
21#include <dis-asm.h>
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <limits.h>
25
26#include "json_writer.h"
27#include "main.h"
28
29static void get_exec_path(char *tpath, size_t size)
30{
31 ssize_t len;
32 char *path;
33
34 snprintf(tpath, size, "/proc/%d/exe", (int) getpid());
35 tpath[size - 1] = 0;
36
37 path = strdup(tpath);
38 assert(path);
39
40 len = readlink(path, tpath, size - 1);
41 assert(len > 0);
42 tpath[len] = 0;
43
44 free(path);
45}
46
47static int oper_count;
48static int fprintf_json(void *out, const char *fmt, ...)
49{
50 va_list ap;
51 char *s;
52
53 va_start(ap, fmt);
54 if (!oper_count) {
55 int i;
56
57 s = va_arg(ap, char *);
58
59 /* Strip trailing spaces */
60 i = strlen(s) - 1;
61 while (s[i] == ' ')
62 s[i--] = '\0';
63
64 jsonw_string_field(json_wtr, "operation", s);
65 jsonw_name(json_wtr, "operands");
66 jsonw_start_array(json_wtr);
67 oper_count++;
68 } else if (!strcmp(fmt, ",")) {
69 /* Skip */
70 } else {
71 s = va_arg(ap, char *);
72 jsonw_string(json_wtr, s);
73 oper_count++;
74 }
75 va_end(ap);
76 return 0;
77}
78
79void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes)
80{
81 disassembler_ftype disassemble;
82 struct disassemble_info info;
83 int count, i, pc = 0;
84 char tpath[PATH_MAX];
85 bfd *bfdf;
86
87 if (!len)
88 return;
89
90 memset(tpath, 0, sizeof(tpath));
91 get_exec_path(tpath, sizeof(tpath));
92
93 bfdf = bfd_openr(tpath, NULL);
94 assert(bfdf);
95 assert(bfd_check_format(bfdf, bfd_object));
96
97 if (json_output)
98 init_disassemble_info(&info, stdout,
99 (fprintf_ftype) fprintf_json);
100 else
101 init_disassemble_info(&info, stdout,
102 (fprintf_ftype) fprintf);
103 info.arch = bfd_get_arch(bfdf);
104 info.mach = bfd_get_mach(bfdf);
105 info.buffer = image;
106 info.buffer_length = len;
107
108 disassemble_init_for_target(&info);
109
110 disassemble = disassembler(bfdf);
111 assert(disassemble);
112
113 if (json_output)
114 jsonw_start_array(json_wtr);
115 do {
116 if (json_output) {
117 jsonw_start_object(json_wtr);
118 oper_count = 0;
119 jsonw_name(json_wtr, "pc");
120 jsonw_printf(json_wtr, "\"0x%x\"", pc);
121 } else {
122 printf("%4x:\t", pc);
123 }
124
125 count = disassemble(pc, &info);
126 if (json_output) {
127 /* Operand array, was started in fprintf_json. Before
128 * that, make sure we have a _null_ value if no operand
129 * other than operation code was present.
130 */
131 if (oper_count == 1)
132 jsonw_null(json_wtr);
133 jsonw_end_array(json_wtr);
134 }
135
136 if (opcodes) {
137 if (json_output) {
138 jsonw_name(json_wtr, "opcodes");
139 jsonw_start_array(json_wtr);
140 for (i = 0; i < count; ++i)
141 jsonw_printf(json_wtr, "\"0x%02hhx\"",
142 (uint8_t)image[pc + i]);
143 jsonw_end_array(json_wtr);
144 } else {
145 printf("\n\t");
146 for (i = 0; i < count; ++i)
147 printf("%02x ",
148 (uint8_t)image[pc + i]);
149 }
150 }
151 if (json_output)
152 jsonw_end_object(json_wtr);
153 else
154 printf("\n");
155
156 pc += count;
157 } while (count > 0 && pc < len);
158 if (json_output)
159 jsonw_end_array(json_wtr);
160
161 bfd_close(bfdf);
162}
diff --git a/tools/bpf/bpftool/json_writer.c b/tools/bpf/bpftool/json_writer.c
new file mode 100644
index 000000000000..c6eef76322ae
--- /dev/null
+++ b/tools/bpf/bpftool/json_writer.c
@@ -0,0 +1,356 @@
1/*
2 * Simple streaming JSON writer
3 *
4 * This takes care of the annoying bits of JSON syntax like the commas
5 * after elements
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Authors: Stephen Hemminger <stephen@networkplumber.org>
13 */
14
15#include <stdio.h>
16#include <stdbool.h>
17#include <stdarg.h>
18#include <assert.h>
19#include <malloc.h>
20#include <inttypes.h>
21#include <stdint.h>
22
23#include "json_writer.h"
24
25struct json_writer {
26 FILE *out; /* output file */
27 unsigned depth; /* nesting */
28 bool pretty; /* optional whitepace */
29 char sep; /* either nul or comma */
30};
31
32/* indentation for pretty print */
33static void jsonw_indent(json_writer_t *self)
34{
35 unsigned i;
36 for (i = 0; i < self->depth; ++i)
37 fputs(" ", self->out);
38}
39
40/* end current line and indent if pretty printing */
41static void jsonw_eol(json_writer_t *self)
42{
43 if (!self->pretty)
44 return;
45
46 putc('\n', self->out);
47 jsonw_indent(self);
48}
49
50/* If current object is not empty print a comma */
51static void jsonw_eor(json_writer_t *self)
52{
53 if (self->sep != '\0')
54 putc(self->sep, self->out);
55 self->sep = ',';
56}
57
58
59/* Output JSON encoded string */
60/* Handles C escapes, does not do Unicode */
61static void jsonw_puts(json_writer_t *self, const char *str)
62{
63 putc('"', self->out);
64 for (; *str; ++str)
65 switch (*str) {
66 case '\t':
67 fputs("\\t", self->out);
68 break;
69 case '\n':
70 fputs("\\n", self->out);
71 break;
72 case '\r':
73 fputs("\\r", self->out);
74 break;
75 case '\f':
76 fputs("\\f", self->out);
77 break;
78 case '\b':
79 fputs("\\b", self->out);
80 break;
81 case '\\':
82 fputs("\\n", self->out);
83 break;
84 case '"':
85 fputs("\\\"", self->out);
86 break;
87 case '\'':
88 fputs("\\\'", self->out);
89 break;
90 default:
91 putc(*str, self->out);
92 }
93 putc('"', self->out);
94}
95
96/* Create a new JSON stream */
97json_writer_t *jsonw_new(FILE *f)
98{
99 json_writer_t *self = malloc(sizeof(*self));
100 if (self) {
101 self->out = f;
102 self->depth = 0;
103 self->pretty = false;
104 self->sep = '\0';
105 }
106 return self;
107}
108
109/* End output to JSON stream */
110void jsonw_destroy(json_writer_t **self_p)
111{
112 json_writer_t *self = *self_p;
113
114 assert(self->depth == 0);
115 fputs("\n", self->out);
116 fflush(self->out);
117 free(self);
118 *self_p = NULL;
119}
120
121void jsonw_pretty(json_writer_t *self, bool on)
122{
123 self->pretty = on;
124}
125
126/* Basic blocks */
127static void jsonw_begin(json_writer_t *self, int c)
128{
129 jsonw_eor(self);
130 putc(c, self->out);
131 ++self->depth;
132 self->sep = '\0';
133}
134
135static void jsonw_end(json_writer_t *self, int c)
136{
137 assert(self->depth > 0);
138
139 --self->depth;
140 if (self->sep != '\0')
141 jsonw_eol(self);
142 putc(c, self->out);
143 self->sep = ',';
144}
145
146
147/* Add a JSON property name */
148void jsonw_name(json_writer_t *self, const char *name)
149{
150 jsonw_eor(self);
151 jsonw_eol(self);
152 self->sep = '\0';
153 jsonw_puts(self, name);
154 putc(':', self->out);
155 if (self->pretty)
156 putc(' ', self->out);
157}
158
159void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
160{
161 jsonw_eor(self);
162 putc('"', self->out);
163 vfprintf(self->out, fmt, ap);
164 putc('"', self->out);
165}
166
167void jsonw_printf(json_writer_t *self, const char *fmt, ...)
168{
169 va_list ap;
170
171 va_start(ap, fmt);
172 jsonw_eor(self);
173 vfprintf(self->out, fmt, ap);
174 va_end(ap);
175}
176
177/* Collections */
178void jsonw_start_object(json_writer_t *self)
179{
180 jsonw_begin(self, '{');
181}
182
183void jsonw_end_object(json_writer_t *self)
184{
185 jsonw_end(self, '}');
186}
187
188void jsonw_start_array(json_writer_t *self)
189{
190 jsonw_begin(self, '[');
191}
192
193void jsonw_end_array(json_writer_t *self)
194{
195 jsonw_end(self, ']');
196}
197
198/* JSON value types */
199void jsonw_string(json_writer_t *self, const char *value)
200{
201 jsonw_eor(self);
202 jsonw_puts(self, value);
203}
204
205void jsonw_bool(json_writer_t *self, bool val)
206{
207 jsonw_printf(self, "%s", val ? "true" : "false");
208}
209
210void jsonw_null(json_writer_t *self)
211{
212 jsonw_printf(self, "null");
213}
214
215void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num)
216{
217 jsonw_printf(self, fmt, num);
218}
219
220#ifdef notused
221void jsonw_float(json_writer_t *self, double num)
222{
223 jsonw_printf(self, "%g", num);
224}
225#endif
226
227void jsonw_hu(json_writer_t *self, unsigned short num)
228{
229 jsonw_printf(self, "%hu", num);
230}
231
232void jsonw_uint(json_writer_t *self, uint64_t num)
233{
234 jsonw_printf(self, "%"PRIu64, num);
235}
236
237void jsonw_lluint(json_writer_t *self, unsigned long long int num)
238{
239 jsonw_printf(self, "%llu", num);
240}
241
242void jsonw_int(json_writer_t *self, int64_t num)
243{
244 jsonw_printf(self, "%"PRId64, num);
245}
246
247/* Basic name/value objects */
248void jsonw_string_field(json_writer_t *self, const char *prop, const char *val)
249{
250 jsonw_name(self, prop);
251 jsonw_string(self, val);
252}
253
254void jsonw_bool_field(json_writer_t *self, const char *prop, bool val)
255{
256 jsonw_name(self, prop);
257 jsonw_bool(self, val);
258}
259
260#ifdef notused
261void jsonw_float_field(json_writer_t *self, const char *prop, double val)
262{
263 jsonw_name(self, prop);
264 jsonw_float(self, val);
265}
266#endif
267
268void jsonw_float_field_fmt(json_writer_t *self,
269 const char *prop,
270 const char *fmt,
271 double val)
272{
273 jsonw_name(self, prop);
274 jsonw_float_fmt(self, fmt, val);
275}
276
277void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num)
278{
279 jsonw_name(self, prop);
280 jsonw_uint(self, num);
281}
282
283void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num)
284{
285 jsonw_name(self, prop);
286 jsonw_hu(self, num);
287}
288
289void jsonw_lluint_field(json_writer_t *self,
290 const char *prop,
291 unsigned long long int num)
292{
293 jsonw_name(self, prop);
294 jsonw_lluint(self, num);
295}
296
297void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num)
298{
299 jsonw_name(self, prop);
300 jsonw_int(self, num);
301}
302
303void jsonw_null_field(json_writer_t *self, const char *prop)
304{
305 jsonw_name(self, prop);
306 jsonw_null(self);
307}
308
309#ifdef TEST
310int main(int argc, char **argv)
311{
312 json_writer_t *wr = jsonw_new(stdout);
313
314 jsonw_start_object(wr);
315 jsonw_pretty(wr, true);
316 jsonw_name(wr, "Vyatta");
317 jsonw_start_object(wr);
318 jsonw_string_field(wr, "url", "http://vyatta.com");
319 jsonw_uint_field(wr, "downloads", 2000000ul);
320 jsonw_float_field(wr, "stock", 8.16);
321
322 jsonw_name(wr, "ARGV");
323 jsonw_start_array(wr);
324 while (--argc)
325 jsonw_string(wr, *++argv);
326 jsonw_end_array(wr);
327
328 jsonw_name(wr, "empty");
329 jsonw_start_array(wr);
330 jsonw_end_array(wr);
331
332 jsonw_name(wr, "NIL");
333 jsonw_start_object(wr);
334 jsonw_end_object(wr);
335
336 jsonw_null_field(wr, "my_null");
337
338 jsonw_name(wr, "special chars");
339 jsonw_start_array(wr);
340 jsonw_string_field(wr, "slash", "/");
341 jsonw_string_field(wr, "newline", "\n");
342 jsonw_string_field(wr, "tab", "\t");
343 jsonw_string_field(wr, "ff", "\f");
344 jsonw_string_field(wr, "quote", "\"");
345 jsonw_string_field(wr, "tick", "\'");
346 jsonw_string_field(wr, "backslash", "\\");
347 jsonw_end_array(wr);
348
349 jsonw_end_object(wr);
350
351 jsonw_end_object(wr);
352 jsonw_destroy(&wr);
353 return 0;
354}
355
356#endif
diff --git a/tools/bpf/bpftool/json_writer.h b/tools/bpf/bpftool/json_writer.h
new file mode 100644
index 000000000000..0fa2fb1b6351
--- /dev/null
+++ b/tools/bpf/bpftool/json_writer.h
@@ -0,0 +1,72 @@
1/*
2 * Simple streaming JSON writer
3 *
4 * This takes care of the annoying bits of JSON syntax like the commas
5 * after elements
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Authors: Stephen Hemminger <stephen@networkplumber.org>
13 */
14
15#ifndef _JSON_WRITER_H_
16#define _JSON_WRITER_H_
17
18#include <stdbool.h>
19#include <stdint.h>
20#include <stdarg.h>
21
22/* Opaque class structure */
23typedef struct json_writer json_writer_t;
24
25/* Create a new JSON stream */
26json_writer_t *jsonw_new(FILE *f);
27/* End output to JSON stream */
28void jsonw_destroy(json_writer_t **self_p);
29
30/* Cause output to have pretty whitespace */
31void jsonw_pretty(json_writer_t *self, bool on);
32
33/* Add property name */
34void jsonw_name(json_writer_t *self, const char *name);
35
36/* Add value */
37void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap);
38void jsonw_printf(json_writer_t *self, const char *fmt, ...);
39void jsonw_string(json_writer_t *self, const char *value);
40void jsonw_bool(json_writer_t *self, bool value);
41void jsonw_float(json_writer_t *self, double number);
42void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num);
43void jsonw_uint(json_writer_t *self, uint64_t number);
44void jsonw_hu(json_writer_t *self, unsigned short number);
45void jsonw_int(json_writer_t *self, int64_t number);
46void jsonw_null(json_writer_t *self);
47void jsonw_lluint(json_writer_t *self, unsigned long long int num);
48
49/* Useful Combinations of name and value */
50void jsonw_string_field(json_writer_t *self, const char *prop, const char *val);
51void jsonw_bool_field(json_writer_t *self, const char *prop, bool value);
52void jsonw_float_field(json_writer_t *self, const char *prop, double num);
53void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num);
54void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num);
55void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num);
56void jsonw_null_field(json_writer_t *self, const char *prop);
57void jsonw_lluint_field(json_writer_t *self, const char *prop,
58 unsigned long long int num);
59void jsonw_float_field_fmt(json_writer_t *self, const char *prop,
60 const char *fmt, double val);
61
62/* Collections */
63void jsonw_start_object(json_writer_t *self);
64void jsonw_end_object(json_writer_t *self);
65
66void jsonw_start_array(json_writer_t *self);
67void jsonw_end_array(json_writer_t *self);
68
69/* Override default exception handling */
70typedef void (jsonw_err_handler_fn)(const char *);
71
72#endif /* _JSON_WRITER_H_ */
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
new file mode 100644
index 000000000000..d6e4762170a4
--- /dev/null
+++ b/tools/bpf/bpftool/main.c
@@ -0,0 +1,331 @@
1/*
2 * Copyright (C) 2017 Netronome Systems, Inc.
3 *
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
8 *
9 * The BSD 2-Clause License:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34/* Author: Jakub Kicinski <kubakici@wp.pl> */
35
36#include <bfd.h>
37#include <ctype.h>
38#include <errno.h>
39#include <getopt.h>
40#include <linux/bpf.h>
41#include <linux/version.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45
46#include <bpf.h>
47
48#include "main.h"
49
50const char *bin_name;
51static int last_argc;
52static char **last_argv;
53static int (*last_do_help)(int argc, char **argv);
54json_writer_t *json_wtr;
55bool pretty_output;
56bool json_output;
57bool show_pinned;
58struct pinned_obj_table prog_table;
59struct pinned_obj_table map_table;
60
61void usage(void)
62{
63 last_do_help(last_argc - 1, last_argv + 1);
64
65 exit(-1);
66}
67
68static int do_help(int argc, char **argv)
69{
70 if (json_output) {
71 jsonw_null(json_wtr);
72 return 0;
73 }
74
75 fprintf(stderr,
76 "Usage: %s [OPTIONS] OBJECT { COMMAND | help }\n"
77 " %s batch file FILE\n"
78 " %s version\n"
79 "\n"
80 " OBJECT := { prog | map }\n"
81 " " HELP_SPEC_OPTIONS "\n"
82 "",
83 bin_name, bin_name, bin_name);
84
85 return 0;
86}
87
88static int do_version(int argc, char **argv)
89{
90 unsigned int version[3];
91
92 version[0] = LINUX_VERSION_CODE >> 16;
93 version[1] = LINUX_VERSION_CODE >> 8 & 0xf;
94 version[2] = LINUX_VERSION_CODE & 0xf;
95
96 if (json_output) {
97 jsonw_start_object(json_wtr);
98 jsonw_name(json_wtr, "version");
99 jsonw_printf(json_wtr, "\"%u.%u.%u\"",
100 version[0], version[1], version[2]);
101 jsonw_end_object(json_wtr);
102 } else {
103 printf("%s v%u.%u.%u\n", bin_name,
104 version[0], version[1], version[2]);
105 }
106 return 0;
107}
108
109int cmd_select(const struct cmd *cmds, int argc, char **argv,
110 int (*help)(int argc, char **argv))
111{
112 unsigned int i;
113
114 last_argc = argc;
115 last_argv = argv;
116 last_do_help = help;
117
118 if (argc < 1 && cmds[0].func)
119 return cmds[0].func(argc, argv);
120
121 for (i = 0; cmds[i].func; i++)
122 if (is_prefix(*argv, cmds[i].cmd))
123 return cmds[i].func(argc - 1, argv + 1);
124
125 help(argc - 1, argv + 1);
126
127 return -1;
128}
129
130bool is_prefix(const char *pfx, const char *str)
131{
132 if (!pfx)
133 return false;
134 if (strlen(str) < strlen(pfx))
135 return false;
136
137 return !memcmp(str, pfx, strlen(pfx));
138}
139
140void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep)
141{
142 unsigned char *data = arg;
143 unsigned int i;
144
145 for (i = 0; i < n; i++) {
146 const char *pfx = "";
147
148 if (!i)
149 /* nothing */;
150 else if (!(i % 16))
151 fprintf(f, "\n");
152 else if (!(i % 8))
153 fprintf(f, " ");
154 else
155 pfx = sep;
156
157 fprintf(f, "%s%02hhx", i ? pfx : "", data[i]);
158 }
159}
160
161static int do_batch(int argc, char **argv);
162
163static const struct cmd cmds[] = {
164 { "help", do_help },
165 { "batch", do_batch },
166 { "prog", do_prog },
167 { "map", do_map },
168 { "version", do_version },
169 { 0 }
170};
171
172static int do_batch(int argc, char **argv)
173{
174 unsigned int lines = 0;
175 char *n_argv[4096];
176 char buf[65536];
177 int n_argc;
178 FILE *fp;
179 int err;
180 int i;
181
182 if (argc < 2) {
183 p_err("too few parameters for batch");
184 return -1;
185 } else if (!is_prefix(*argv, "file")) {
186 p_err("expected 'file', got: %s", *argv);
187 return -1;
188 } else if (argc > 2) {
189 p_err("too many parameters for batch");
190 return -1;
191 }
192 NEXT_ARG();
193
194 fp = fopen(*argv, "r");
195 if (!fp) {
196 p_err("Can't open file (%s): %s", *argv, strerror(errno));
197 return -1;
198 }
199
200 if (json_output)
201 jsonw_start_array(json_wtr);
202 while (fgets(buf, sizeof(buf), fp)) {
203 if (strlen(buf) == sizeof(buf) - 1) {
204 errno = E2BIG;
205 break;
206 }
207
208 n_argc = 0;
209 n_argv[n_argc] = strtok(buf, " \t\n");
210
211 while (n_argv[n_argc]) {
212 n_argc++;
213 if (n_argc == ARRAY_SIZE(n_argv)) {
214 p_err("line %d has too many arguments, skip",
215 lines);
216 n_argc = 0;
217 break;
218 }
219 n_argv[n_argc] = strtok(NULL, " \t\n");
220 }
221
222 if (!n_argc)
223 continue;
224
225 if (json_output) {
226 jsonw_start_object(json_wtr);
227 jsonw_name(json_wtr, "command");
228 jsonw_start_array(json_wtr);
229 for (i = 0; i < n_argc; i++)
230 jsonw_string(json_wtr, n_argv[i]);
231 jsonw_end_array(json_wtr);
232 jsonw_name(json_wtr, "output");
233 }
234
235 err = cmd_select(cmds, n_argc, n_argv, do_help);
236
237 if (json_output)
238 jsonw_end_object(json_wtr);
239
240 if (err)
241 goto err_close;
242
243 lines++;
244 }
245
246 if (errno && errno != ENOENT) {
247 perror("reading batch file failed");
248 err = -1;
249 } else {
250 p_info("processed %d lines", lines);
251 err = 0;
252 }
253err_close:
254 fclose(fp);
255
256 if (json_output)
257 jsonw_end_array(json_wtr);
258
259 return err;
260}
261
262int main(int argc, char **argv)
263{
264 static const struct option options[] = {
265 { "json", no_argument, NULL, 'j' },
266 { "help", no_argument, NULL, 'h' },
267 { "pretty", no_argument, NULL, 'p' },
268 { "version", no_argument, NULL, 'V' },
269 { "bpffs", no_argument, NULL, 'f' },
270 { 0 }
271 };
272 int opt, ret;
273
274 last_do_help = do_help;
275 pretty_output = false;
276 json_output = false;
277 show_pinned = false;
278 bin_name = argv[0];
279
280 hash_init(prog_table.table);
281 hash_init(map_table.table);
282
283 while ((opt = getopt_long(argc, argv, "Vhpjf",
284 options, NULL)) >= 0) {
285 switch (opt) {
286 case 'V':
287 return do_version(argc, argv);
288 case 'h':
289 return do_help(argc, argv);
290 case 'p':
291 pretty_output = true;
292 /* fall through */
293 case 'j':
294 json_output = true;
295 break;
296 case 'f':
297 show_pinned = true;
298 break;
299 default:
300 usage();
301 }
302 }
303
304 argc -= optind;
305 argv += optind;
306 if (argc < 0)
307 usage();
308
309 if (json_output) {
310 json_wtr = jsonw_new(stdout);
311 if (!json_wtr) {
312 p_err("failed to create JSON writer");
313 return -1;
314 }
315 jsonw_pretty(json_wtr, pretty_output);
316 }
317
318 bfd_init();
319
320 ret = cmd_select(cmds, argc, argv, do_help);
321
322 if (json_output)
323 jsonw_destroy(&json_wtr);
324
325 if (show_pinned) {
326 delete_pinned_obj_table(&prog_table);
327 delete_pinned_obj_table(&map_table);
328 }
329
330 return ret;
331}
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
new file mode 100644
index 000000000000..9c191e222d6f
--- /dev/null
+++ b/tools/bpf/bpftool/main.h
@@ -0,0 +1,122 @@
1/*
2 * Copyright (C) 2017 Netronome Systems, Inc.
3 *
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
8 *
9 * The BSD 2-Clause License:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34/* Author: Jakub Kicinski <kubakici@wp.pl> */
35
36#ifndef __BPF_TOOL_H
37#define __BPF_TOOL_H
38
39/* BFD and kernel.h both define GCC_VERSION, differently */
40#undef GCC_VERSION
41#include <stdbool.h>
42#include <stdio.h>
43#include <linux/bpf.h>
44#include <linux/kernel.h>
45#include <linux/hashtable.h>
46
47#include "json_writer.h"
48
49#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr))
50
51#define NEXT_ARG() ({ argc--; argv++; if (argc < 0) usage(); })
52#define NEXT_ARGP() ({ (*argc)--; (*argv)++; if (*argc < 0) usage(); })
53#define BAD_ARG() ({ p_err("what is '%s'?\n", *argv); -1; })
54
55#define ERR_MAX_LEN 1024
56
57#define BPF_TAG_FMT "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
58
59#define HELP_SPEC_PROGRAM \
60 "PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }"
61#define HELP_SPEC_OPTIONS \
62 "OPTIONS := { {-j|--json} [{-p|--pretty}] | {-f|--bpffs} }"
63
64enum bpf_obj_type {
65 BPF_OBJ_UNKNOWN,
66 BPF_OBJ_PROG,
67 BPF_OBJ_MAP,
68};
69
70extern const char *bin_name;
71
72extern json_writer_t *json_wtr;
73extern bool json_output;
74extern bool show_pinned;
75extern struct pinned_obj_table prog_table;
76extern struct pinned_obj_table map_table;
77
78void p_err(const char *fmt, ...);
79void p_info(const char *fmt, ...);
80
81bool is_prefix(const char *pfx, const char *str);
82void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
83void usage(void) __attribute__((noreturn));
84
85struct pinned_obj_table {
86 DECLARE_HASHTABLE(table, 16);
87};
88
89struct pinned_obj {
90 __u32 id;
91 char *path;
92 struct hlist_node hash;
93};
94
95int build_pinned_obj_table(struct pinned_obj_table *table,
96 enum bpf_obj_type type);
97void delete_pinned_obj_table(struct pinned_obj_table *tab);
98
99struct cmd {
100 const char *cmd;
101 int (*func)(int argc, char **argv);
102};
103
104int cmd_select(const struct cmd *cmds, int argc, char **argv,
105 int (*help)(int argc, char **argv));
106
107int get_fd_type(int fd);
108const char *get_fd_type_name(enum bpf_obj_type type);
109char *get_fdinfo(int fd, const char *key);
110int open_obj_pinned(char *path);
111int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type);
112int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32));
113
114int do_prog(int argc, char **arg);
115int do_map(int argc, char **arg);
116
117int prog_parse_fd(int *argc, char ***argv);
118
119void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes);
120void print_hex_data_json(uint8_t *data, size_t len);
121
122#endif
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
new file mode 100644
index 000000000000..e2450c8e88e6
--- /dev/null
+++ b/tools/bpf/bpftool/map.c
@@ -0,0 +1,899 @@
1/*
2 * Copyright (C) 2017 Netronome Systems, Inc.
3 *
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
8 *
9 * The BSD 2-Clause License:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34/* Author: Jakub Kicinski <kubakici@wp.pl> */
35
36#include <assert.h>
37#include <ctype.h>
38#include <errno.h>
39#include <fcntl.h>
40#include <stdbool.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <unistd.h>
45#include <sys/types.h>
46#include <sys/stat.h>
47
48#include <bpf.h>
49
50#include "main.h"
51
52static const char * const map_type_name[] = {
53 [BPF_MAP_TYPE_UNSPEC] = "unspec",
54 [BPF_MAP_TYPE_HASH] = "hash",
55 [BPF_MAP_TYPE_ARRAY] = "array",
56 [BPF_MAP_TYPE_PROG_ARRAY] = "prog_array",
57 [BPF_MAP_TYPE_PERF_EVENT_ARRAY] = "perf_event_array",
58 [BPF_MAP_TYPE_PERCPU_HASH] = "percpu_hash",
59 [BPF_MAP_TYPE_PERCPU_ARRAY] = "percpu_array",
60 [BPF_MAP_TYPE_STACK_TRACE] = "stack_trace",
61 [BPF_MAP_TYPE_CGROUP_ARRAY] = "cgroup_array",
62 [BPF_MAP_TYPE_LRU_HASH] = "lru_hash",
63 [BPF_MAP_TYPE_LRU_PERCPU_HASH] = "lru_percpu_hash",
64 [BPF_MAP_TYPE_LPM_TRIE] = "lpm_trie",
65 [BPF_MAP_TYPE_ARRAY_OF_MAPS] = "array_of_maps",
66 [BPF_MAP_TYPE_HASH_OF_MAPS] = "hash_of_maps",
67 [BPF_MAP_TYPE_DEVMAP] = "devmap",
68 [BPF_MAP_TYPE_SOCKMAP] = "sockmap",
69};
70
71static unsigned int get_possible_cpus(void)
72{
73 static unsigned int result;
74 char buf[128];
75 long int n;
76 char *ptr;
77 int fd;
78
79 if (result)
80 return result;
81
82 fd = open("/sys/devices/system/cpu/possible", O_RDONLY);
83 if (fd < 0) {
84 p_err("can't open sysfs possible cpus");
85 exit(-1);
86 }
87
88 n = read(fd, buf, sizeof(buf));
89 if (n < 2) {
90 p_err("can't read sysfs possible cpus");
91 exit(-1);
92 }
93 close(fd);
94
95 if (n == sizeof(buf)) {
96 p_err("read sysfs possible cpus overflow");
97 exit(-1);
98 }
99
100 ptr = buf;
101 n = 0;
102 while (*ptr && *ptr != '\n') {
103 unsigned int a, b;
104
105 if (sscanf(ptr, "%u-%u", &a, &b) == 2) {
106 n += b - a + 1;
107
108 ptr = strchr(ptr, '-') + 1;
109 } else if (sscanf(ptr, "%u", &a) == 1) {
110 n++;
111 } else {
112 assert(0);
113 }
114
115 while (isdigit(*ptr))
116 ptr++;
117 if (*ptr == ',')
118 ptr++;
119 }
120
121 result = n;
122
123 return result;
124}
125
126static bool map_is_per_cpu(__u32 type)
127{
128 return type == BPF_MAP_TYPE_PERCPU_HASH ||
129 type == BPF_MAP_TYPE_PERCPU_ARRAY ||
130 type == BPF_MAP_TYPE_LRU_PERCPU_HASH;
131}
132
133static bool map_is_map_of_maps(__u32 type)
134{
135 return type == BPF_MAP_TYPE_ARRAY_OF_MAPS ||
136 type == BPF_MAP_TYPE_HASH_OF_MAPS;
137}
138
139static bool map_is_map_of_progs(__u32 type)
140{
141 return type == BPF_MAP_TYPE_PROG_ARRAY;
142}
143
144static void *alloc_value(struct bpf_map_info *info)
145{
146 if (map_is_per_cpu(info->type))
147 return malloc(info->value_size * get_possible_cpus());
148 else
149 return malloc(info->value_size);
150}
151
152static int map_parse_fd(int *argc, char ***argv)
153{
154 int fd;
155
156 if (is_prefix(**argv, "id")) {
157 unsigned int id;
158 char *endptr;
159
160 NEXT_ARGP();
161
162 id = strtoul(**argv, &endptr, 0);
163 if (*endptr) {
164 p_err("can't parse %s as ID", **argv);
165 return -1;
166 }
167 NEXT_ARGP();
168
169 fd = bpf_map_get_fd_by_id(id);
170 if (fd < 0)
171 p_err("get map by id (%u): %s", id, strerror(errno));
172 return fd;
173 } else if (is_prefix(**argv, "pinned")) {
174 char *path;
175
176 NEXT_ARGP();
177
178 path = **argv;
179 NEXT_ARGP();
180
181 return open_obj_pinned_any(path, BPF_OBJ_MAP);
182 }
183
184 p_err("expected 'id' or 'pinned', got: '%s'?", **argv);
185 return -1;
186}
187
188static int
189map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len)
190{
191 int err;
192 int fd;
193
194 fd = map_parse_fd(argc, argv);
195 if (fd < 0)
196 return -1;
197
198 err = bpf_obj_get_info_by_fd(fd, info, info_len);
199 if (err) {
200 p_err("can't get map info: %s", strerror(errno));
201 close(fd);
202 return err;
203 }
204
205 return fd;
206}
207
208static void print_entry_json(struct bpf_map_info *info, unsigned char *key,
209 unsigned char *value)
210{
211 jsonw_start_object(json_wtr);
212
213 if (!map_is_per_cpu(info->type)) {
214 jsonw_name(json_wtr, "key");
215 print_hex_data_json(key, info->key_size);
216 jsonw_name(json_wtr, "value");
217 print_hex_data_json(value, info->value_size);
218 } else {
219 unsigned int i, n;
220
221 n = get_possible_cpus();
222
223 jsonw_name(json_wtr, "key");
224 print_hex_data_json(key, info->key_size);
225
226 jsonw_name(json_wtr, "values");
227 jsonw_start_array(json_wtr);
228 for (i = 0; i < n; i++) {
229 jsonw_start_object(json_wtr);
230
231 jsonw_int_field(json_wtr, "cpu", i);
232
233 jsonw_name(json_wtr, "value");
234 print_hex_data_json(value + i * info->value_size,
235 info->value_size);
236
237 jsonw_end_object(json_wtr);
238 }
239 jsonw_end_array(json_wtr);
240 }
241
242 jsonw_end_object(json_wtr);
243}
244
245static void print_entry_plain(struct bpf_map_info *info, unsigned char *key,
246 unsigned char *value)
247{
248 if (!map_is_per_cpu(info->type)) {
249 bool single_line, break_names;
250
251 break_names = info->key_size > 16 || info->value_size > 16;
252 single_line = info->key_size + info->value_size <= 24 &&
253 !break_names;
254
255 printf("key:%c", break_names ? '\n' : ' ');
256 fprint_hex(stdout, key, info->key_size, " ");
257
258 printf(single_line ? " " : "\n");
259
260 printf("value:%c", break_names ? '\n' : ' ');
261 fprint_hex(stdout, value, info->value_size, " ");
262
263 printf("\n");
264 } else {
265 unsigned int i, n;
266
267 n = get_possible_cpus();
268
269 printf("key:\n");
270 fprint_hex(stdout, key, info->key_size, " ");
271 printf("\n");
272 for (i = 0; i < n; i++) {
273 printf("value (CPU %02d):%c",
274 i, info->value_size > 16 ? '\n' : ' ');
275 fprint_hex(stdout, value + i * info->value_size,
276 info->value_size, " ");
277 printf("\n");
278 }
279 }
280}
281
282static char **parse_bytes(char **argv, const char *name, unsigned char *val,
283 unsigned int n)
284{
285 unsigned int i = 0;
286 char *endptr;
287
288 while (i < n && argv[i]) {
289 val[i] = strtoul(argv[i], &endptr, 0);
290 if (*endptr) {
291 p_err("error parsing byte: %s", argv[i]);
292 return NULL;
293 }
294 i++;
295 }
296
297 if (i != n) {
298 p_err("%s expected %d bytes got %d", name, n, i);
299 return NULL;
300 }
301
302 return argv + i;
303}
304
305static int parse_elem(char **argv, struct bpf_map_info *info,
306 void *key, void *value, __u32 key_size, __u32 value_size,
307 __u32 *flags, __u32 **value_fd)
308{
309 if (!*argv) {
310 if (!key && !value)
311 return 0;
312 p_err("did not find %s", key ? "key" : "value");
313 return -1;
314 }
315
316 if (is_prefix(*argv, "key")) {
317 if (!key) {
318 if (key_size)
319 p_err("duplicate key");
320 else
321 p_err("unnecessary key");
322 return -1;
323 }
324
325 argv = parse_bytes(argv + 1, "key", key, key_size);
326 if (!argv)
327 return -1;
328
329 return parse_elem(argv, info, NULL, value, key_size, value_size,
330 flags, value_fd);
331 } else if (is_prefix(*argv, "value")) {
332 int fd;
333
334 if (!value) {
335 if (value_size)
336 p_err("duplicate value");
337 else
338 p_err("unnecessary value");
339 return -1;
340 }
341
342 argv++;
343
344 if (map_is_map_of_maps(info->type)) {
345 int argc = 2;
346
347 if (value_size != 4) {
348 p_err("value smaller than 4B for map in map?");
349 return -1;
350 }
351 if (!argv[0] || !argv[1]) {
352 p_err("not enough value arguments for map in map");
353 return -1;
354 }
355
356 fd = map_parse_fd(&argc, &argv);
357 if (fd < 0)
358 return -1;
359
360 *value_fd = value;
361 **value_fd = fd;
362 } else if (map_is_map_of_progs(info->type)) {
363 int argc = 2;
364
365 if (value_size != 4) {
366 p_err("value smaller than 4B for map of progs?");
367 return -1;
368 }
369 if (!argv[0] || !argv[1]) {
370 p_err("not enough value arguments for map of progs");
371 return -1;
372 }
373
374 fd = prog_parse_fd(&argc, &argv);
375 if (fd < 0)
376 return -1;
377
378 *value_fd = value;
379 **value_fd = fd;
380 } else {
381 argv = parse_bytes(argv, "value", value, value_size);
382 if (!argv)
383 return -1;
384 }
385
386 return parse_elem(argv, info, key, NULL, key_size, value_size,
387 flags, NULL);
388 } else if (is_prefix(*argv, "any") || is_prefix(*argv, "noexist") ||
389 is_prefix(*argv, "exist")) {
390 if (!flags) {
391 p_err("flags specified multiple times: %s", *argv);
392 return -1;
393 }
394
395 if (is_prefix(*argv, "any"))
396 *flags = BPF_ANY;
397 else if (is_prefix(*argv, "noexist"))
398 *flags = BPF_NOEXIST;
399 else if (is_prefix(*argv, "exist"))
400 *flags = BPF_EXIST;
401
402 return parse_elem(argv + 1, info, key, value, key_size,
403 value_size, NULL, value_fd);
404 }
405
406 p_err("expected key or value, got: %s", *argv);
407 return -1;
408}
409
410static int show_map_close_json(int fd, struct bpf_map_info *info)
411{
412 char *memlock;
413
414 memlock = get_fdinfo(fd, "memlock");
415 close(fd);
416
417 jsonw_start_object(json_wtr);
418
419 jsonw_uint_field(json_wtr, "id", info->id);
420 if (info->type < ARRAY_SIZE(map_type_name))
421 jsonw_string_field(json_wtr, "type",
422 map_type_name[info->type]);
423 else
424 jsonw_uint_field(json_wtr, "type", info->type);
425
426 if (*info->name)
427 jsonw_string_field(json_wtr, "name", info->name);
428
429 jsonw_name(json_wtr, "flags");
430 jsonw_printf(json_wtr, "%#x", info->map_flags);
431 jsonw_uint_field(json_wtr, "bytes_key", info->key_size);
432 jsonw_uint_field(json_wtr, "bytes_value", info->value_size);
433 jsonw_uint_field(json_wtr, "max_entries", info->max_entries);
434
435 if (memlock)
436 jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock));
437 free(memlock);
438
439 if (!hash_empty(map_table.table)) {
440 struct pinned_obj *obj;
441
442 jsonw_name(json_wtr, "pinned");
443 jsonw_start_array(json_wtr);
444 hash_for_each_possible(map_table.table, obj, hash, info->id) {
445 if (obj->id == info->id)
446 jsonw_string(json_wtr, obj->path);
447 }
448 jsonw_end_array(json_wtr);
449 }
450
451 jsonw_end_object(json_wtr);
452
453 return 0;
454}
455
456static int show_map_close_plain(int fd, struct bpf_map_info *info)
457{
458 char *memlock;
459
460 memlock = get_fdinfo(fd, "memlock");
461 close(fd);
462
463 printf("%u: ", info->id);
464 if (info->type < ARRAY_SIZE(map_type_name))
465 printf("%s ", map_type_name[info->type]);
466 else
467 printf("type %u ", info->type);
468
469 if (*info->name)
470 printf("name %s ", info->name);
471
472 printf("flags 0x%x\n", info->map_flags);
473 printf("\tkey %uB value %uB max_entries %u",
474 info->key_size, info->value_size, info->max_entries);
475
476 if (memlock)
477 printf(" memlock %sB", memlock);
478 free(memlock);
479
480 printf("\n");
481 if (!hash_empty(map_table.table)) {
482 struct pinned_obj *obj;
483
484 hash_for_each_possible(map_table.table, obj, hash, info->id) {
485 if (obj->id == info->id)
486 printf("\tpinned %s\n", obj->path);
487 }
488 }
489 return 0;
490}
491
492static int do_show(int argc, char **argv)
493{
494 struct bpf_map_info info = {};
495 __u32 len = sizeof(info);
496 __u32 id = 0;
497 int err;
498 int fd;
499
500 if (show_pinned)
501 build_pinned_obj_table(&map_table, BPF_OBJ_MAP);
502
503 if (argc == 2) {
504 fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
505 if (fd < 0)
506 return -1;
507
508 if (json_output)
509 return show_map_close_json(fd, &info);
510 else
511 return show_map_close_plain(fd, &info);
512 }
513
514 if (argc)
515 return BAD_ARG();
516
517 if (json_output)
518 jsonw_start_array(json_wtr);
519 while (true) {
520 err = bpf_map_get_next_id(id, &id);
521 if (err) {
522 if (errno == ENOENT)
523 break;
524 p_err("can't get next map: %s%s", strerror(errno),
525 errno == EINVAL ? " -- kernel too old?" : "");
526 return -1;
527 }
528
529 fd = bpf_map_get_fd_by_id(id);
530 if (fd < 0) {
531 p_err("can't get map by id (%u): %s",
532 id, strerror(errno));
533 return -1;
534 }
535
536 err = bpf_obj_get_info_by_fd(fd, &info, &len);
537 if (err) {
538 p_err("can't get map info: %s", strerror(errno));
539 close(fd);
540 return -1;
541 }
542
543 if (json_output)
544 show_map_close_json(fd, &info);
545 else
546 show_map_close_plain(fd, &info);
547 }
548 if (json_output)
549 jsonw_end_array(json_wtr);
550
551 return errno == ENOENT ? 0 : -1;
552}
553
554static int do_dump(int argc, char **argv)
555{
556 void *key, *value, *prev_key;
557 unsigned int num_elems = 0;
558 struct bpf_map_info info = {};
559 __u32 len = sizeof(info);
560 int err;
561 int fd;
562
563 if (argc != 2)
564 usage();
565
566 fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
567 if (fd < 0)
568 return -1;
569
570 if (map_is_map_of_maps(info.type) || map_is_map_of_progs(info.type)) {
571 p_err("Dumping maps of maps and program maps not supported");
572 close(fd);
573 return -1;
574 }
575
576 key = malloc(info.key_size);
577 value = alloc_value(&info);
578 if (!key || !value) {
579 p_err("mem alloc failed");
580 err = -1;
581 goto exit_free;
582 }
583
584 prev_key = NULL;
585 if (json_output)
586 jsonw_start_array(json_wtr);
587 while (true) {
588 err = bpf_map_get_next_key(fd, prev_key, key);
589 if (err) {
590 if (errno == ENOENT)
591 err = 0;
592 break;
593 }
594
595 if (!bpf_map_lookup_elem(fd, key, value)) {
596 if (json_output)
597 print_entry_json(&info, key, value);
598 else
599 print_entry_plain(&info, key, value);
600 } else {
601 if (json_output) {
602 jsonw_name(json_wtr, "key");
603 print_hex_data_json(key, info.key_size);
604 jsonw_name(json_wtr, "value");
605 jsonw_start_object(json_wtr);
606 jsonw_string_field(json_wtr, "error",
607 "can't lookup element");
608 jsonw_end_object(json_wtr);
609 } else {
610 p_info("can't lookup element with key: ");
611 fprint_hex(stderr, key, info.key_size, " ");
612 fprintf(stderr, "\n");
613 }
614 }
615
616 prev_key = key;
617 num_elems++;
618 }
619
620 if (json_output)
621 jsonw_end_array(json_wtr);
622 else
623 printf("Found %u element%s\n", num_elems,
624 num_elems != 1 ? "s" : "");
625
626exit_free:
627 free(key);
628 free(value);
629 close(fd);
630
631 return err;
632}
633
634static int do_update(int argc, char **argv)
635{
636 struct bpf_map_info info = {};
637 __u32 len = sizeof(info);
638 __u32 *value_fd = NULL;
639 __u32 flags = BPF_ANY;
640 void *key, *value;
641 int fd, err;
642
643 if (argc < 2)
644 usage();
645
646 fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
647 if (fd < 0)
648 return -1;
649
650 key = malloc(info.key_size);
651 value = alloc_value(&info);
652 if (!key || !value) {
653 p_err("mem alloc failed");
654 err = -1;
655 goto exit_free;
656 }
657
658 err = parse_elem(argv, &info, key, value, info.key_size,
659 info.value_size, &flags, &value_fd);
660 if (err)
661 goto exit_free;
662
663 err = bpf_map_update_elem(fd, key, value, flags);
664 if (err) {
665 p_err("update failed: %s", strerror(errno));
666 goto exit_free;
667 }
668
669exit_free:
670 if (value_fd)
671 close(*value_fd);
672 free(key);
673 free(value);
674 close(fd);
675
676 if (!err && json_output)
677 jsonw_null(json_wtr);
678 return err;
679}
680
681static int do_lookup(int argc, char **argv)
682{
683 struct bpf_map_info info = {};
684 __u32 len = sizeof(info);
685 void *key, *value;
686 int err;
687 int fd;
688
689 if (argc < 2)
690 usage();
691
692 fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
693 if (fd < 0)
694 return -1;
695
696 key = malloc(info.key_size);
697 value = alloc_value(&info);
698 if (!key || !value) {
699 p_err("mem alloc failed");
700 err = -1;
701 goto exit_free;
702 }
703
704 err = parse_elem(argv, &info, key, NULL, info.key_size, 0, NULL, NULL);
705 if (err)
706 goto exit_free;
707
708 err = bpf_map_lookup_elem(fd, key, value);
709 if (!err) {
710 if (json_output)
711 print_entry_json(&info, key, value);
712 else
713 print_entry_plain(&info, key, value);
714 } else if (errno == ENOENT) {
715 if (json_output) {
716 jsonw_null(json_wtr);
717 } else {
718 printf("key:\n");
719 fprint_hex(stdout, key, info.key_size, " ");
720 printf("\n\nNot found\n");
721 }
722 } else {
723 p_err("lookup failed: %s", strerror(errno));
724 }
725
726exit_free:
727 free(key);
728 free(value);
729 close(fd);
730
731 return err;
732}
733
734static int do_getnext(int argc, char **argv)
735{
736 struct bpf_map_info info = {};
737 __u32 len = sizeof(info);
738 void *key, *nextkey;
739 int err;
740 int fd;
741
742 if (argc < 2)
743 usage();
744
745 fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
746 if (fd < 0)
747 return -1;
748
749 key = malloc(info.key_size);
750 nextkey = malloc(info.key_size);
751 if (!key || !nextkey) {
752 p_err("mem alloc failed");
753 err = -1;
754 goto exit_free;
755 }
756
757 if (argc) {
758 err = parse_elem(argv, &info, key, NULL, info.key_size, 0,
759 NULL, NULL);
760 if (err)
761 goto exit_free;
762 } else {
763 free(key);
764 key = NULL;
765 }
766
767 err = bpf_map_get_next_key(fd, key, nextkey);
768 if (err) {
769 p_err("can't get next key: %s", strerror(errno));
770 goto exit_free;
771 }
772
773 if (json_output) {
774 jsonw_start_object(json_wtr);
775 if (key) {
776 jsonw_name(json_wtr, "key");
777 print_hex_data_json(key, info.key_size);
778 } else {
779 jsonw_null_field(json_wtr, "key");
780 }
781 jsonw_name(json_wtr, "next_key");
782 print_hex_data_json(nextkey, info.key_size);
783 jsonw_end_object(json_wtr);
784 } else {
785 if (key) {
786 printf("key:\n");
787 fprint_hex(stdout, key, info.key_size, " ");
788 printf("\n");
789 } else {
790 printf("key: None\n");
791 }
792 printf("next key:\n");
793 fprint_hex(stdout, nextkey, info.key_size, " ");
794 printf("\n");
795 }
796
797exit_free:
798 free(nextkey);
799 free(key);
800 close(fd);
801
802 return err;
803}
804
805static int do_delete(int argc, char **argv)
806{
807 struct bpf_map_info info = {};
808 __u32 len = sizeof(info);
809 void *key;
810 int err;
811 int fd;
812
813 if (argc < 2)
814 usage();
815
816 fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
817 if (fd < 0)
818 return -1;
819
820 key = malloc(info.key_size);
821 if (!key) {
822 p_err("mem alloc failed");
823 err = -1;
824 goto exit_free;
825 }
826
827 err = parse_elem(argv, &info, key, NULL, info.key_size, 0, NULL, NULL);
828 if (err)
829 goto exit_free;
830
831 err = bpf_map_delete_elem(fd, key);
832 if (err)
833 p_err("delete failed: %s", strerror(errno));
834
835exit_free:
836 free(key);
837 close(fd);
838
839 if (!err && json_output)
840 jsonw_null(json_wtr);
841 return err;
842}
843
844static int do_pin(int argc, char **argv)
845{
846 int err;
847
848 err = do_pin_any(argc, argv, bpf_map_get_fd_by_id);
849 if (!err && json_output)
850 jsonw_null(json_wtr);
851 return err;
852}
853
854static int do_help(int argc, char **argv)
855{
856 if (json_output) {
857 jsonw_null(json_wtr);
858 return 0;
859 }
860
861 fprintf(stderr,
862 "Usage: %s %s show [MAP]\n"
863 " %s %s dump MAP\n"
864 " %s %s update MAP key BYTES value VALUE [UPDATE_FLAGS]\n"
865 " %s %s lookup MAP key BYTES\n"
866 " %s %s getnext MAP [key BYTES]\n"
867 " %s %s delete MAP key BYTES\n"
868 " %s %s pin MAP FILE\n"
869 " %s %s help\n"
870 "\n"
871 " MAP := { id MAP_ID | pinned FILE }\n"
872 " " HELP_SPEC_PROGRAM "\n"
873 " VALUE := { BYTES | MAP | PROG }\n"
874 " UPDATE_FLAGS := { any | exist | noexist }\n"
875 " " HELP_SPEC_OPTIONS "\n"
876 "",
877 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
878 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
879 bin_name, argv[-2], bin_name, argv[-2]);
880
881 return 0;
882}
883
884static const struct cmd cmds[] = {
885 { "show", do_show },
886 { "help", do_help },
887 { "dump", do_dump },
888 { "update", do_update },
889 { "lookup", do_lookup },
890 { "getnext", do_getnext },
891 { "delete", do_delete },
892 { "pin", do_pin },
893 { 0 }
894};
895
896int do_map(int argc, char **argv)
897{
898 return cmd_select(cmds, argc, argv, do_help);
899}
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
new file mode 100644
index 000000000000..ad619b96c276
--- /dev/null
+++ b/tools/bpf/bpftool/prog.c
@@ -0,0 +1,672 @@
1/*
2 * Copyright (C) 2017 Netronome Systems, Inc.
3 *
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
8 *
9 * The BSD 2-Clause License:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34/* Author: Jakub Kicinski <kubakici@wp.pl> */
35
36#include <errno.h>
37#include <fcntl.h>
38#include <stdarg.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <time.h>
43#include <unistd.h>
44#include <sys/types.h>
45#include <sys/stat.h>
46
47#include <bpf.h>
48
49#include "main.h"
50#include "disasm.h"
51
52static const char * const prog_type_name[] = {
53 [BPF_PROG_TYPE_UNSPEC] = "unspec",
54 [BPF_PROG_TYPE_SOCKET_FILTER] = "socket_filter",
55 [BPF_PROG_TYPE_KPROBE] = "kprobe",
56 [BPF_PROG_TYPE_SCHED_CLS] = "sched_cls",
57 [BPF_PROG_TYPE_SCHED_ACT] = "sched_act",
58 [BPF_PROG_TYPE_TRACEPOINT] = "tracepoint",
59 [BPF_PROG_TYPE_XDP] = "xdp",
60 [BPF_PROG_TYPE_PERF_EVENT] = "perf_event",
61 [BPF_PROG_TYPE_CGROUP_SKB] = "cgroup_skb",
62 [BPF_PROG_TYPE_CGROUP_SOCK] = "cgroup_sock",
63 [BPF_PROG_TYPE_LWT_IN] = "lwt_in",
64 [BPF_PROG_TYPE_LWT_OUT] = "lwt_out",
65 [BPF_PROG_TYPE_LWT_XMIT] = "lwt_xmit",
66 [BPF_PROG_TYPE_SOCK_OPS] = "sock_ops",
67 [BPF_PROG_TYPE_SK_SKB] = "sk_skb",
68};
69
70static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
71{
72 struct timespec real_time_ts, boot_time_ts;
73 time_t wallclock_secs;
74 struct tm load_tm;
75
76 buf[--size] = '\0';
77
78 if (clock_gettime(CLOCK_REALTIME, &real_time_ts) ||
79 clock_gettime(CLOCK_BOOTTIME, &boot_time_ts)) {
80 perror("Can't read clocks");
81 snprintf(buf, size, "%llu", nsecs / 1000000000);
82 return;
83 }
84
85 wallclock_secs = (real_time_ts.tv_sec - boot_time_ts.tv_sec) +
86 nsecs / 1000000000;
87
88 if (!localtime_r(&wallclock_secs, &load_tm)) {
89 snprintf(buf, size, "%llu", nsecs / 1000000000);
90 return;
91 }
92
93 strftime(buf, size, "%b %d/%H:%M", &load_tm);
94}
95
96static int prog_fd_by_tag(unsigned char *tag)
97{
98 struct bpf_prog_info info = {};
99 __u32 len = sizeof(info);
100 unsigned int id = 0;
101 int err;
102 int fd;
103
104 while (true) {
105 err = bpf_prog_get_next_id(id, &id);
106 if (err) {
107 p_err("%s", strerror(errno));
108 return -1;
109 }
110
111 fd = bpf_prog_get_fd_by_id(id);
112 if (fd < 0) {
113 p_err("can't get prog by id (%u): %s",
114 id, strerror(errno));
115 return -1;
116 }
117
118 err = bpf_obj_get_info_by_fd(fd, &info, &len);
119 if (err) {
120 p_err("can't get prog info (%u): %s",
121 id, strerror(errno));
122 close(fd);
123 return -1;
124 }
125
126 if (!memcmp(tag, info.tag, BPF_TAG_SIZE))
127 return fd;
128
129 close(fd);
130 }
131}
132
133int prog_parse_fd(int *argc, char ***argv)
134{
135 int fd;
136
137 if (is_prefix(**argv, "id")) {
138 unsigned int id;
139 char *endptr;
140
141 NEXT_ARGP();
142
143 id = strtoul(**argv, &endptr, 0);
144 if (*endptr) {
145 p_err("can't parse %s as ID", **argv);
146 return -1;
147 }
148 NEXT_ARGP();
149
150 fd = bpf_prog_get_fd_by_id(id);
151 if (fd < 0)
152 p_err("get by id (%u): %s", id, strerror(errno));
153 return fd;
154 } else if (is_prefix(**argv, "tag")) {
155 unsigned char tag[BPF_TAG_SIZE];
156
157 NEXT_ARGP();
158
159 if (sscanf(**argv, BPF_TAG_FMT, tag, tag + 1, tag + 2,
160 tag + 3, tag + 4, tag + 5, tag + 6, tag + 7)
161 != BPF_TAG_SIZE) {
162 p_err("can't parse tag");
163 return -1;
164 }
165 NEXT_ARGP();
166
167 return prog_fd_by_tag(tag);
168 } else if (is_prefix(**argv, "pinned")) {
169 char *path;
170
171 NEXT_ARGP();
172
173 path = **argv;
174 NEXT_ARGP();
175
176 return open_obj_pinned_any(path, BPF_OBJ_PROG);
177 }
178
179 p_err("expected 'id', 'tag' or 'pinned', got: '%s'?", **argv);
180 return -1;
181}
182
183static void show_prog_maps(int fd, u32 num_maps)
184{
185 struct bpf_prog_info info = {};
186 __u32 len = sizeof(info);
187 __u32 map_ids[num_maps];
188 unsigned int i;
189 int err;
190
191 info.nr_map_ids = num_maps;
192 info.map_ids = ptr_to_u64(map_ids);
193
194 err = bpf_obj_get_info_by_fd(fd, &info, &len);
195 if (err || !info.nr_map_ids)
196 return;
197
198 if (json_output) {
199 jsonw_name(json_wtr, "map_ids");
200 jsonw_start_array(json_wtr);
201 for (i = 0; i < info.nr_map_ids; i++)
202 jsonw_uint(json_wtr, map_ids[i]);
203 jsonw_end_array(json_wtr);
204 } else {
205 printf(" map_ids ");
206 for (i = 0; i < info.nr_map_ids; i++)
207 printf("%u%s", map_ids[i],
208 i == info.nr_map_ids - 1 ? "" : ",");
209 }
210}
211
212static void print_prog_json(struct bpf_prog_info *info, int fd)
213{
214 char *memlock;
215
216 jsonw_start_object(json_wtr);
217 jsonw_uint_field(json_wtr, "id", info->id);
218 if (info->type < ARRAY_SIZE(prog_type_name))
219 jsonw_string_field(json_wtr, "type",
220 prog_type_name[info->type]);
221 else
222 jsonw_uint_field(json_wtr, "type", info->type);
223
224 if (*info->name)
225 jsonw_string_field(json_wtr, "name", info->name);
226
227 jsonw_name(json_wtr, "tag");
228 jsonw_printf(json_wtr, "\"" BPF_TAG_FMT "\"",
229 info->tag[0], info->tag[1], info->tag[2], info->tag[3],
230 info->tag[4], info->tag[5], info->tag[6], info->tag[7]);
231
232 if (info->load_time) {
233 char buf[32];
234
235 print_boot_time(info->load_time, buf, sizeof(buf));
236
237 /* Piggy back on load_time, since 0 uid is a valid one */
238 jsonw_string_field(json_wtr, "loaded_at", buf);
239 jsonw_uint_field(json_wtr, "uid", info->created_by_uid);
240 }
241
242 jsonw_uint_field(json_wtr, "bytes_xlated", info->xlated_prog_len);
243
244 if (info->jited_prog_len) {
245 jsonw_bool_field(json_wtr, "jited", true);
246 jsonw_uint_field(json_wtr, "bytes_jited", info->jited_prog_len);
247 } else {
248 jsonw_bool_field(json_wtr, "jited", false);
249 }
250
251 memlock = get_fdinfo(fd, "memlock");
252 if (memlock)
253 jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock));
254 free(memlock);
255
256 if (info->nr_map_ids)
257 show_prog_maps(fd, info->nr_map_ids);
258
259 if (!hash_empty(prog_table.table)) {
260 struct pinned_obj *obj;
261
262 jsonw_name(json_wtr, "pinned");
263 jsonw_start_array(json_wtr);
264 hash_for_each_possible(prog_table.table, obj, hash, info->id) {
265 if (obj->id == info->id)
266 jsonw_string(json_wtr, obj->path);
267 }
268 jsonw_end_array(json_wtr);
269 }
270
271 jsonw_end_object(json_wtr);
272}
273
274static void print_prog_plain(struct bpf_prog_info *info, int fd)
275{
276 char *memlock;
277
278 printf("%u: ", info->id);
279 if (info->type < ARRAY_SIZE(prog_type_name))
280 printf("%s ", prog_type_name[info->type]);
281 else
282 printf("type %u ", info->type);
283
284 if (*info->name)
285 printf("name %s ", info->name);
286
287 printf("tag ");
288 fprint_hex(stdout, info->tag, BPF_TAG_SIZE, "");
289 printf("\n");
290
291 if (info->load_time) {
292 char buf[32];
293
294 print_boot_time(info->load_time, buf, sizeof(buf));
295
296 /* Piggy back on load_time, since 0 uid is a valid one */
297 printf("\tloaded_at %s uid %u\n", buf, info->created_by_uid);
298 }
299
300 printf("\txlated %uB", info->xlated_prog_len);
301
302 if (info->jited_prog_len)
303 printf(" jited %uB", info->jited_prog_len);
304 else
305 printf(" not jited");
306
307 memlock = get_fdinfo(fd, "memlock");
308 if (memlock)
309 printf(" memlock %sB", memlock);
310 free(memlock);
311
312 if (info->nr_map_ids)
313 show_prog_maps(fd, info->nr_map_ids);
314
315 if (!hash_empty(prog_table.table)) {
316 struct pinned_obj *obj;
317
318 printf("\n");
319 hash_for_each_possible(prog_table.table, obj, hash, info->id) {
320 if (obj->id == info->id)
321 printf("\tpinned %s\n", obj->path);
322 }
323 }
324
325 printf("\n");
326}
327
328static int show_prog(int fd)
329{
330 struct bpf_prog_info info = {};
331 __u32 len = sizeof(info);
332 int err;
333
334 err = bpf_obj_get_info_by_fd(fd, &info, &len);
335 if (err) {
336 p_err("can't get prog info: %s", strerror(errno));
337 return -1;
338 }
339
340 if (json_output)
341 print_prog_json(&info, fd);
342 else
343 print_prog_plain(&info, fd);
344
345 return 0;
346}
347
348static int do_show(int argc, char **argv)
349{
350 __u32 id = 0;
351 int err;
352 int fd;
353
354 if (show_pinned)
355 build_pinned_obj_table(&prog_table, BPF_OBJ_PROG);
356
357 if (argc == 2) {
358 fd = prog_parse_fd(&argc, &argv);
359 if (fd < 0)
360 return -1;
361
362 return show_prog(fd);
363 }
364
365 if (argc)
366 return BAD_ARG();
367
368 if (json_output)
369 jsonw_start_array(json_wtr);
370 while (true) {
371 err = bpf_prog_get_next_id(id, &id);
372 if (err) {
373 if (errno == ENOENT) {
374 err = 0;
375 break;
376 }
377 p_err("can't get next program: %s%s", strerror(errno),
378 errno == EINVAL ? " -- kernel too old?" : "");
379 err = -1;
380 break;
381 }
382
383 fd = bpf_prog_get_fd_by_id(id);
384 if (fd < 0) {
385 p_err("can't get prog by id (%u): %s",
386 id, strerror(errno));
387 err = -1;
388 break;
389 }
390
391 err = show_prog(fd);
392 close(fd);
393 if (err)
394 break;
395 }
396
397 if (json_output)
398 jsonw_end_array(json_wtr);
399
400 return err;
401}
402
403static void print_insn(struct bpf_verifier_env *env, const char *fmt, ...)
404{
405 va_list args;
406
407 va_start(args, fmt);
408 vprintf(fmt, args);
409 va_end(args);
410}
411
412static void dump_xlated_plain(void *buf, unsigned int len, bool opcodes)
413{
414 struct bpf_insn *insn = buf;
415 bool double_insn = false;
416 unsigned int i;
417
418 for (i = 0; i < len / sizeof(*insn); i++) {
419 if (double_insn) {
420 double_insn = false;
421 continue;
422 }
423
424 double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW);
425
426 printf("% 4d: ", i);
427 print_bpf_insn(print_insn, NULL, insn + i, true);
428
429 if (opcodes) {
430 printf(" ");
431 fprint_hex(stdout, insn + i, 8, " ");
432 if (double_insn && i < len - 1) {
433 printf(" ");
434 fprint_hex(stdout, insn + i + 1, 8, " ");
435 }
436 printf("\n");
437 }
438 }
439}
440
441static void print_insn_json(struct bpf_verifier_env *env, const char *fmt, ...)
442{
443 unsigned int l = strlen(fmt);
444 char chomped_fmt[l];
445 va_list args;
446
447 va_start(args, fmt);
448 if (l > 0) {
449 strncpy(chomped_fmt, fmt, l - 1);
450 chomped_fmt[l - 1] = '\0';
451 }
452 jsonw_vprintf_enquote(json_wtr, chomped_fmt, args);
453 va_end(args);
454}
455
456static void dump_xlated_json(void *buf, unsigned int len, bool opcodes)
457{
458 struct bpf_insn *insn = buf;
459 bool double_insn = false;
460 unsigned int i;
461
462 jsonw_start_array(json_wtr);
463 for (i = 0; i < len / sizeof(*insn); i++) {
464 if (double_insn) {
465 double_insn = false;
466 continue;
467 }
468 double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW);
469
470 jsonw_start_object(json_wtr);
471 jsonw_name(json_wtr, "disasm");
472 print_bpf_insn(print_insn_json, NULL, insn + i, true);
473
474 if (opcodes) {
475 jsonw_name(json_wtr, "opcodes");
476 jsonw_start_object(json_wtr);
477
478 jsonw_name(json_wtr, "code");
479 jsonw_printf(json_wtr, "\"0x%02hhx\"", insn[i].code);
480
481 jsonw_name(json_wtr, "src_reg");
482 jsonw_printf(json_wtr, "\"0x%hhx\"", insn[i].src_reg);
483
484 jsonw_name(json_wtr, "dst_reg");
485 jsonw_printf(json_wtr, "\"0x%hhx\"", insn[i].dst_reg);
486
487 jsonw_name(json_wtr, "off");
488 print_hex_data_json((uint8_t *)(&insn[i].off), 2);
489
490 jsonw_name(json_wtr, "imm");
491 if (double_insn && i < len - 1)
492 print_hex_data_json((uint8_t *)(&insn[i].imm),
493 12);
494 else
495 print_hex_data_json((uint8_t *)(&insn[i].imm),
496 4);
497 jsonw_end_object(json_wtr);
498 }
499 jsonw_end_object(json_wtr);
500 }
501 jsonw_end_array(json_wtr);
502}
503
504static int do_dump(int argc, char **argv)
505{
506 struct bpf_prog_info info = {};
507 __u32 len = sizeof(info);
508 unsigned int buf_size;
509 char *filepath = NULL;
510 bool opcodes = false;
511 unsigned char *buf;
512 __u32 *member_len;
513 __u64 *member_ptr;
514 ssize_t n;
515 int err;
516 int fd;
517
518 if (is_prefix(*argv, "jited")) {
519 member_len = &info.jited_prog_len;
520 member_ptr = &info.jited_prog_insns;
521 } else if (is_prefix(*argv, "xlated")) {
522 member_len = &info.xlated_prog_len;
523 member_ptr = &info.xlated_prog_insns;
524 } else {
525 p_err("expected 'xlated' or 'jited', got: %s", *argv);
526 return -1;
527 }
528 NEXT_ARG();
529
530 if (argc < 2)
531 usage();
532
533 fd = prog_parse_fd(&argc, &argv);
534 if (fd < 0)
535 return -1;
536
537 if (is_prefix(*argv, "file")) {
538 NEXT_ARG();
539 if (!argc) {
540 p_err("expected file path");
541 return -1;
542 }
543
544 filepath = *argv;
545 NEXT_ARG();
546 } else if (is_prefix(*argv, "opcodes")) {
547 opcodes = true;
548 NEXT_ARG();
549 }
550
551 if (argc) {
552 usage();
553 return -1;
554 }
555
556 err = bpf_obj_get_info_by_fd(fd, &info, &len);
557 if (err) {
558 p_err("can't get prog info: %s", strerror(errno));
559 return -1;
560 }
561
562 if (!*member_len) {
563 p_info("no instructions returned");
564 close(fd);
565 return 0;
566 }
567
568 buf_size = *member_len;
569
570 buf = malloc(buf_size);
571 if (!buf) {
572 p_err("mem alloc failed");
573 close(fd);
574 return -1;
575 }
576
577 memset(&info, 0, sizeof(info));
578
579 *member_ptr = ptr_to_u64(buf);
580 *member_len = buf_size;
581
582 err = bpf_obj_get_info_by_fd(fd, &info, &len);
583 close(fd);
584 if (err) {
585 p_err("can't get prog info: %s", strerror(errno));
586 goto err_free;
587 }
588
589 if (*member_len > buf_size) {
590 p_err("too many instructions returned");
591 goto err_free;
592 }
593
594 if (filepath) {
595 fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
596 if (fd < 0) {
597 p_err("can't open file %s: %s", filepath,
598 strerror(errno));
599 goto err_free;
600 }
601
602 n = write(fd, buf, *member_len);
603 close(fd);
604 if (n != *member_len) {
605 p_err("error writing output file: %s",
606 n < 0 ? strerror(errno) : "short write");
607 goto err_free;
608 }
609 } else {
610 if (member_len == &info.jited_prog_len)
611 disasm_print_insn(buf, *member_len, opcodes);
612 else
613 if (json_output)
614 dump_xlated_json(buf, *member_len, opcodes);
615 else
616 dump_xlated_plain(buf, *member_len, opcodes);
617 }
618
619 free(buf);
620
621 return 0;
622
623err_free:
624 free(buf);
625 return -1;
626}
627
628static int do_pin(int argc, char **argv)
629{
630 int err;
631
632 err = do_pin_any(argc, argv, bpf_prog_get_fd_by_id);
633 if (!err && json_output)
634 jsonw_null(json_wtr);
635 return err;
636}
637
638static int do_help(int argc, char **argv)
639{
640 if (json_output) {
641 jsonw_null(json_wtr);
642 return 0;
643 }
644
645 fprintf(stderr,
646 "Usage: %s %s show [PROG]\n"
647 " %s %s dump xlated PROG [{ file FILE | opcodes }]\n"
648 " %s %s dump jited PROG [{ file FILE | opcodes }]\n"
649 " %s %s pin PROG FILE\n"
650 " %s %s help\n"
651 "\n"
652 " " HELP_SPEC_PROGRAM "\n"
653 " " HELP_SPEC_OPTIONS "\n"
654 "",
655 bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
656 bin_name, argv[-2], bin_name, argv[-2]);
657
658 return 0;
659}
660
661static const struct cmd cmds[] = {
662 { "show", do_show },
663 { "help", do_help },
664 { "dump", do_dump },
665 { "pin", do_pin },
666 { 0 }
667};
668
669int do_prog(int argc, char **argv)
670{
671 return cmd_select(cmds, argc, argv, do_help);
672}
diff --git a/tools/build/Makefile b/tools/build/Makefile
index 477f00eda591..5eb4b5ad79cb 100644
--- a/tools/build/Makefile
+++ b/tools/build/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ifeq ($(srctree),) 2ifeq ($(srctree),)
2srctree := $(patsubst %/,%,$(dir $(CURDIR))) 3srctree := $(patsubst %/,%,$(dir $(CURDIR)))
3srctree := $(patsubst %/,%,$(dir $(srctree))) 4srctree := $(patsubst %/,%,$(dir $(srctree)))
diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build
index c46b20e4ad87..cd72016c3cfa 100644
--- a/tools/build/Makefile.build
+++ b/tools/build/Makefile.build
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1### 2###
2# Main build makefile. 3# Main build makefile.
3# 4#
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index ee2546ddf028..96982640fbf8 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1FILES= \ 2FILES= \
2 test-all.bin \ 3 test-all.bin \
3 test-backtrace.bin \ 4 test-backtrace.bin \
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c
index b5cfc6445771..4112702e4aed 100644
--- a/tools/build/feature/test-all.c
+++ b/tools/build/feature/test-all.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * test-all.c: Try to build all the main testcases at once. 3 * test-all.c: Try to build all the main testcases at once.
3 * 4 *
diff --git a/tools/build/feature/test-backtrace.c b/tools/build/feature/test-backtrace.c
index 7124aa1dc8fb..e9ddd27c69c3 100644
--- a/tools/build/feature/test-backtrace.c
+++ b/tools/build/feature/test-backtrace.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <execinfo.h> 2#include <execinfo.h>
2#include <stdio.h> 3#include <stdio.h>
3 4
diff --git a/tools/build/feature/test-bionic.c b/tools/build/feature/test-bionic.c
index eac24e9513eb..4bcc9776504c 100644
--- a/tools/build/feature/test-bionic.c
+++ b/tools/build/feature/test-bionic.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <android/api-level.h> 2#include <android/api-level.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
index da2172ff9662..82070eadfc07 100644
--- a/tools/build/feature/test-bpf.c
+++ b/tools/build/feature/test-bpf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <asm/unistd.h> 2#include <asm/unistd.h>
2#include <linux/bpf.h> 3#include <linux/bpf.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/build/feature/test-clang.cpp b/tools/build/feature/test-clang.cpp
index e23c1b1f1b91..a2b3f092d2f0 100644
--- a/tools/build/feature/test-clang.cpp
+++ b/tools/build/feature/test-clang.cpp
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "clang/Basic/VirtualFileSystem.h" 2#include "clang/Basic/VirtualFileSystem.h"
2#include "clang/Driver/Driver.h" 3#include "clang/Driver/Driver.h"
3#include "clang/Frontend/TextDiagnosticPrinter.h" 4#include "clang/Frontend/TextDiagnosticPrinter.h"
diff --git a/tools/build/feature/test-compile.c b/tools/build/feature/test-compile.c
index c54e6551ae4c..9821b8271dee 100644
--- a/tools/build/feature/test-compile.c
+++ b/tools/build/feature/test-compile.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2int main(void) 3int main(void)
3{ 4{
diff --git a/tools/build/feature/test-cplus-demangle.c b/tools/build/feature/test-cplus-demangle.c
index 610c686e0009..2ba56474ab71 100644
--- a/tools/build/feature/test-cplus-demangle.c
+++ b/tools/build/feature/test-cplus-demangle.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1extern int printf(const char *format, ...); 2extern int printf(const char *format, ...);
2extern char *cplus_demangle(const char *, int); 3extern char *cplus_demangle(const char *, int);
3 4
diff --git a/tools/build/feature/test-cxx.cpp b/tools/build/feature/test-cxx.cpp
index b1dee9a31d6c..396aaedd2418 100644
--- a/tools/build/feature/test-cxx.cpp
+++ b/tools/build/feature/test-cxx.cpp
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <iostream> 2#include <iostream>
2#include <memory> 3#include <memory>
3 4
diff --git a/tools/build/feature/test-dwarf.c b/tools/build/feature/test-dwarf.c
index 3fc1801ce4a9..8d474bd7371b 100644
--- a/tools/build/feature/test-dwarf.c
+++ b/tools/build/feature/test-dwarf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <dwarf.h> 2#include <dwarf.h>
2#include <elfutils/libdw.h> 3#include <elfutils/libdw.h>
3#include <elfutils/version.h> 4#include <elfutils/version.h>
diff --git a/tools/build/feature/test-dwarf_getlocations.c b/tools/build/feature/test-dwarf_getlocations.c
index 70162699dd43..78fb4a1fa68c 100644
--- a/tools/build/feature/test-dwarf_getlocations.c
+++ b/tools/build/feature/test-dwarf_getlocations.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <elfutils/libdw.h> 3#include <elfutils/libdw.h>
3 4
diff --git a/tools/build/feature/test-get_cpuid.c b/tools/build/feature/test-get_cpuid.c
index d7a2c407130d..bb4f065f28a6 100644
--- a/tools/build/feature/test-get_cpuid.c
+++ b/tools/build/feature/test-get_cpuid.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <cpuid.h> 2#include <cpuid.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-glibc.c b/tools/build/feature/test-glibc.c
index 9367f7586676..9ab8e90e7b88 100644
--- a/tools/build/feature/test-glibc.c
+++ b/tools/build/feature/test-glibc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2 3
3#if !defined(__UCLIBC__) 4#if !defined(__UCLIBC__)
diff --git a/tools/build/feature/test-gtk2-infobar.c b/tools/build/feature/test-gtk2-infobar.c
index 397b4646d066..b1b716dd5733 100644
--- a/tools/build/feature/test-gtk2-infobar.c
+++ b/tools/build/feature/test-gtk2-infobar.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#pragma GCC diagnostic ignored "-Wstrict-prototypes" 2#pragma GCC diagnostic ignored "-Wstrict-prototypes"
2#include <gtk/gtk.h> 3#include <gtk/gtk.h>
3#pragma GCC diagnostic error "-Wstrict-prototypes" 4#pragma GCC diagnostic error "-Wstrict-prototypes"
diff --git a/tools/build/feature/test-gtk2.c b/tools/build/feature/test-gtk2.c
index 6bd80e509439..2aaf4bfc2055 100644
--- a/tools/build/feature/test-gtk2.c
+++ b/tools/build/feature/test-gtk2.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#pragma GCC diagnostic ignored "-Wstrict-prototypes" 2#pragma GCC diagnostic ignored "-Wstrict-prototypes"
2#include <gtk/gtk.h> 3#include <gtk/gtk.h>
3#pragma GCC diagnostic error "-Wstrict-prototypes" 4#pragma GCC diagnostic error "-Wstrict-prototypes"
diff --git a/tools/build/feature/test-jvmti.c b/tools/build/feature/test-jvmti.c
index 1c665f09b9d6..5cf31192f204 100644
--- a/tools/build/feature/test-jvmti.c
+++ b/tools/build/feature/test-jvmti.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <jvmti.h> 2#include <jvmti.h>
2#include <jvmticmlr.h> 3#include <jvmticmlr.h>
3 4
diff --git a/tools/build/feature/test-libaudit.c b/tools/build/feature/test-libaudit.c
index afc019f08641..f5b0863fa1ec 100644
--- a/tools/build/feature/test-libaudit.c
+++ b/tools/build/feature/test-libaudit.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libaudit.h> 2#include <libaudit.h>
2 3
3extern int printf(const char *format, ...); 4extern int printf(const char *format, ...);
diff --git a/tools/build/feature/test-libbabeltrace.c b/tools/build/feature/test-libbabeltrace.c
index 9cf802a04885..10bb69d55694 100644
--- a/tools/build/feature/test-libbabeltrace.c
+++ b/tools/build/feature/test-libbabeltrace.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2#include <babeltrace/ctf-writer/writer.h> 3#include <babeltrace/ctf-writer/writer.h>
3#include <babeltrace/ctf-ir/stream-class.h> 4#include <babeltrace/ctf-ir/stream-class.h>
diff --git a/tools/build/feature/test-libbfd.c b/tools/build/feature/test-libbfd.c
index 24059907e990..afa46b0465cd 100644
--- a/tools/build/feature/test-libbfd.c
+++ b/tools/build/feature/test-libbfd.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <bfd.h> 2#include <bfd.h>
2 3
3extern int printf(const char *format, ...); 4extern int printf(const char *format, ...);
diff --git a/tools/build/feature/test-libcrypto.c b/tools/build/feature/test-libcrypto.c
index bd79dc7f28d3..a98174e0569c 100644
--- a/tools/build/feature/test-libcrypto.c
+++ b/tools/build/feature/test-libcrypto.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <openssl/sha.h> 2#include <openssl/sha.h>
2#include <openssl/md5.h> 3#include <openssl/md5.h>
3 4
diff --git a/tools/build/feature/test-libdw-dwarf-unwind.c b/tools/build/feature/test-libdw-dwarf-unwind.c
index f676a3ff442a..ed03d9505609 100644
--- a/tools/build/feature/test-libdw-dwarf-unwind.c
+++ b/tools/build/feature/test-libdw-dwarf-unwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2#include <elfutils/libdwfl.h> 3#include <elfutils/libdwfl.h>
3 4
diff --git a/tools/build/feature/test-libelf-gelf_getnote.c b/tools/build/feature/test-libelf-gelf_getnote.c
index d78cf4d5271f..075d062fe841 100644
--- a/tools/build/feature/test-libelf-gelf_getnote.c
+++ b/tools/build/feature/test-libelf-gelf_getnote.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <gelf.h> 3#include <gelf.h>
3 4
diff --git a/tools/build/feature/test-libelf-getphdrnum.c b/tools/build/feature/test-libelf-getphdrnum.c
index d710459306c3..96a7f8d30a59 100644
--- a/tools/build/feature/test-libelf-getphdrnum.c
+++ b/tools/build/feature/test-libelf-getphdrnum.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libelf.h> 2#include <libelf.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-libelf-getshdrstrndx.c b/tools/build/feature/test-libelf-getshdrstrndx.c
index f0c3b47cce28..ae9f2fff5af0 100644
--- a/tools/build/feature/test-libelf-getshdrstrndx.c
+++ b/tools/build/feature/test-libelf-getshdrstrndx.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libelf.h> 2#include <libelf.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-libelf-mmap.c b/tools/build/feature/test-libelf-mmap.c
index 564427d7ef18..2c3ef81affe2 100644
--- a/tools/build/feature/test-libelf-mmap.c
+++ b/tools/build/feature/test-libelf-mmap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libelf.h> 2#include <libelf.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-libelf.c b/tools/build/feature/test-libelf.c
index 08db322d8957..905044127d56 100644
--- a/tools/build/feature/test-libelf.c
+++ b/tools/build/feature/test-libelf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libelf.h> 2#include <libelf.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-libnuma.c b/tools/build/feature/test-libnuma.c
index 4763d9cd587d..b3aa59f8b3cb 100644
--- a/tools/build/feature/test-libnuma.c
+++ b/tools/build/feature/test-libnuma.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <numa.h> 2#include <numa.h>
2#include <numaif.h> 3#include <numaif.h>
3 4
diff --git a/tools/build/feature/test-libperl.c b/tools/build/feature/test-libperl.c
index 8871f6a0fdb4..0415f437eb31 100644
--- a/tools/build/feature/test-libperl.c
+++ b/tools/build/feature/test-libperl.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <EXTERN.h> 2#include <EXTERN.h>
2#include <perl.h> 3#include <perl.h>
3 4
diff --git a/tools/build/feature/test-libpython-version.c b/tools/build/feature/test-libpython-version.c
index facea122d812..47714b942d4d 100644
--- a/tools/build/feature/test-libpython-version.c
+++ b/tools/build/feature/test-libpython-version.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <Python.h> 2#include <Python.h>
2 3
3#if PY_VERSION_HEX >= 0x03000000 4#if PY_VERSION_HEX >= 0x03000000
diff --git a/tools/build/feature/test-libpython.c b/tools/build/feature/test-libpython.c
index b24b28ad6324..0c1641b0d9a7 100644
--- a/tools/build/feature/test-libpython.c
+++ b/tools/build/feature/test-libpython.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <Python.h> 2#include <Python.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-libslang.c b/tools/build/feature/test-libslang.c
index 22ff22ed94d1..9cbff8d1df53 100644
--- a/tools/build/feature/test-libslang.c
+++ b/tools/build/feature/test-libslang.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <slang.h> 2#include <slang.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-libunwind-aarch64.c b/tools/build/feature/test-libunwind-aarch64.c
index fc03fb64e8c1..323803f49212 100644
--- a/tools/build/feature/test-libunwind-aarch64.c
+++ b/tools/build/feature/test-libunwind-aarch64.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind-aarch64.h> 2#include <libunwind-aarch64.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-libunwind-arm.c b/tools/build/feature/test-libunwind-arm.c
index 632d95ec641f..cb378b7d6866 100644
--- a/tools/build/feature/test-libunwind-arm.c
+++ b/tools/build/feature/test-libunwind-arm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind-arm.h> 2#include <libunwind-arm.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-libunwind-debug-frame-aarch64.c b/tools/build/feature/test-libunwind-debug-frame-aarch64.c
index 22844673fc26..36d6646c185e 100644
--- a/tools/build/feature/test-libunwind-debug-frame-aarch64.c
+++ b/tools/build/feature/test-libunwind-debug-frame-aarch64.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind-aarch64.h> 2#include <libunwind-aarch64.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-libunwind-debug-frame-arm.c b/tools/build/feature/test-libunwind-debug-frame-arm.c
index f98859684fee..8696e48e1268 100644
--- a/tools/build/feature/test-libunwind-debug-frame-arm.c
+++ b/tools/build/feature/test-libunwind-debug-frame-arm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind-arm.h> 2#include <libunwind-arm.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-libunwind-debug-frame.c b/tools/build/feature/test-libunwind-debug-frame.c
index 0ef8087a104a..efb55cdd8d01 100644
--- a/tools/build/feature/test-libunwind-debug-frame.c
+++ b/tools/build/feature/test-libunwind-debug-frame.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind.h> 2#include <libunwind.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-libunwind-x86.c b/tools/build/feature/test-libunwind-x86.c
index 3561edce305e..e5e0f6c89637 100644
--- a/tools/build/feature/test-libunwind-x86.c
+++ b/tools/build/feature/test-libunwind-x86.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind-x86.h> 2#include <libunwind-x86.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-libunwind-x86_64.c b/tools/build/feature/test-libunwind-x86_64.c
index 5add2517b2a1..62ae4db597dc 100644
--- a/tools/build/feature/test-libunwind-x86_64.c
+++ b/tools/build/feature/test-libunwind-x86_64.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind-x86_64.h> 2#include <libunwind-x86_64.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-libunwind.c b/tools/build/feature/test-libunwind.c
index 43b9369bcab7..53fd26614ff0 100644
--- a/tools/build/feature/test-libunwind.c
+++ b/tools/build/feature/test-libunwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <libunwind.h> 2#include <libunwind.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/build/feature/test-llvm-version.cpp b/tools/build/feature/test-llvm-version.cpp
index 896d31724568..8a091625446a 100644
--- a/tools/build/feature/test-llvm-version.cpp
+++ b/tools/build/feature/test-llvm-version.cpp
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <cstdio> 2#include <cstdio>
2#include "llvm/Config/llvm-config.h" 3#include "llvm/Config/llvm-config.h"
3 4
diff --git a/tools/build/feature/test-llvm.cpp b/tools/build/feature/test-llvm.cpp
index 455a332dc8a8..88a3d1bdd9f6 100644
--- a/tools/build/feature/test-llvm.cpp
+++ b/tools/build/feature/test-llvm.cpp
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "llvm/Support/ManagedStatic.h" 2#include "llvm/Support/ManagedStatic.h"
2#include "llvm/Support/raw_ostream.h" 3#include "llvm/Support/raw_ostream.h"
3#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH) 4#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
diff --git a/tools/build/feature/test-lzma.c b/tools/build/feature/test-lzma.c
index 95adc8ced3dd..78682bb01d57 100644
--- a/tools/build/feature/test-lzma.c
+++ b/tools/build/feature/test-lzma.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <lzma.h> 2#include <lzma.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-numa_num_possible_cpus.c b/tools/build/feature/test-numa_num_possible_cpus.c
index 2606e94b0659..573d07b9c570 100644
--- a/tools/build/feature/test-numa_num_possible_cpus.c
+++ b/tools/build/feature/test-numa_num_possible_cpus.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <numa.h> 2#include <numa.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-pthread-attr-setaffinity-np.c b/tools/build/feature/test-pthread-attr-setaffinity-np.c
index fdada5e8d454..38c71131c452 100644
--- a/tools/build/feature/test-pthread-attr-setaffinity-np.c
+++ b/tools/build/feature/test-pthread-attr-setaffinity-np.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdint.h> 2#include <stdint.h>
2#include <pthread.h> 3#include <pthread.h>
3#include <sched.h> 4#include <sched.h>
diff --git a/tools/build/feature/test-sched_getcpu.c b/tools/build/feature/test-sched_getcpu.c
index 9c6b4cbffb1c..e448deb4124c 100644
--- a/tools/build/feature/test-sched_getcpu.c
+++ b/tools/build/feature/test-sched_getcpu.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#ifndef _GNU_SOURCE 2#ifndef _GNU_SOURCE
2#define _GNU_SOURCE 3#define _GNU_SOURCE
3#endif 4#endif
diff --git a/tools/build/feature/test-sdt.c b/tools/build/feature/test-sdt.c
index e4531a6e80ea..22737b0dadc8 100644
--- a/tools/build/feature/test-sdt.c
+++ b/tools/build/feature/test-sdt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/sdt.h> 2#include <sys/sdt.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-stackprotector-all.c b/tools/build/feature/test-stackprotector-all.c
index c9f398d87868..c8a57194f9f2 100644
--- a/tools/build/feature/test-stackprotector-all.c
+++ b/tools/build/feature/test-stackprotector-all.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/feature/test-sync-compare-and-swap.c b/tools/build/feature/test-sync-compare-and-swap.c
index c34d4ca4af56..1e38d1930a97 100644
--- a/tools/build/feature/test-sync-compare-and-swap.c
+++ b/tools/build/feature/test-sync-compare-and-swap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdint.h> 2#include <stdint.h>
2 3
3volatile uint64_t x; 4volatile uint64_t x;
diff --git a/tools/build/feature/test-timerfd.c b/tools/build/feature/test-timerfd.c
index 8c5c083b4d3c..9c72c697a9df 100644
--- a/tools/build/feature/test-timerfd.c
+++ b/tools/build/feature/test-timerfd.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * test for timerfd functions used by perf-kvm-stat-live 3 * test for timerfd functions used by perf-kvm-stat-live
3 */ 4 */
diff --git a/tools/build/feature/test-zlib.c b/tools/build/feature/test-zlib.c
index e111fff6240e..da6c35794b93 100644
--- a/tools/build/feature/test-zlib.c
+++ b/tools/build/feature/test-zlib.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <zlib.h> 2#include <zlib.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/build/fixdep.c b/tools/build/fixdep.c
index 734d1547cbae..2501fea7aa3e 100644
--- a/tools/build/fixdep.c
+++ b/tools/build/fixdep.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * "Optimize" a list of dependencies as spit out by gcc -MD 3 * "Optimize" a list of dependencies as spit out by gcc -MD
3 * for the build framework. 4 * for the build framework.
diff --git a/tools/build/tests/ex/Makefile b/tools/build/tests/ex/Makefile
index 027d6c8a58a7..fee032e06a85 100644
--- a/tools/build/tests/ex/Makefile
+++ b/tools/build/tests/ex/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1export srctree := $(abspath ../../../..) 2export srctree := $(abspath ../../../..)
2export CC := gcc 3export CC := gcc
3export LD := ld 4export LD := ld
diff --git a/tools/build/tests/ex/a.c b/tools/build/tests/ex/a.c
index 851762798c83..66017a9f40b6 100644
--- a/tools/build/tests/ex/a.c
+++ b/tools/build/tests/ex/a.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2int a(void) 3int a(void)
3{ 4{
diff --git a/tools/build/tests/ex/arch/e.c b/tools/build/tests/ex/arch/e.c
index beaa4a1d7ba8..f6ef585b570c 100644
--- a/tools/build/tests/ex/arch/e.c
+++ b/tools/build/tests/ex/arch/e.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2int e(void) 3int e(void)
3{ 4{
diff --git a/tools/build/tests/ex/arch/f.c b/tools/build/tests/ex/arch/f.c
index 7c3e9e9da5b7..bffd9c67e9af 100644
--- a/tools/build/tests/ex/arch/f.c
+++ b/tools/build/tests/ex/arch/f.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2int f(void) 3int f(void)
3{ 4{
diff --git a/tools/build/tests/ex/b.c b/tools/build/tests/ex/b.c
index c24ff9ca9a97..2b29fb4d3c20 100644
--- a/tools/build/tests/ex/b.c
+++ b/tools/build/tests/ex/b.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2int b(void) 3int b(void)
3{ 4{
diff --git a/tools/build/tests/ex/c.c b/tools/build/tests/ex/c.c
index e216d0217499..a63b20ab83d5 100644
--- a/tools/build/tests/ex/c.c
+++ b/tools/build/tests/ex/c.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2int c(void) 3int c(void)
3{ 4{
diff --git a/tools/build/tests/ex/d.c b/tools/build/tests/ex/d.c
index 80dc0f06151b..e114e8dca0b6 100644
--- a/tools/build/tests/ex/d.c
+++ b/tools/build/tests/ex/d.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2int d(void) 3int d(void)
3{ 4{
diff --git a/tools/build/tests/ex/ex.c b/tools/build/tests/ex/ex.c
index 57de6074d252..3c02756ef912 100644
--- a/tools/build/tests/ex/ex.c
+++ b/tools/build/tests/ex/ex.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2int a(void); 3int a(void);
3int b(void); 4int b(void);
diff --git a/tools/build/tests/ex/inc.c b/tools/build/tests/ex/inc.c
index c20f1e9033a3..3636ab5bf339 100644
--- a/tools/build/tests/ex/inc.c
+++ b/tools/build/tests/ex/inc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#ifdef INCLUDE 2#ifdef INCLUDE
2#include "krava.h" 3#include "krava.h"
3#endif 4#endif
diff --git a/tools/build/tests/run.sh b/tools/build/tests/run.sh
index 44d2a0fade67..2c54e4d43546 100755
--- a/tools/build/tests/run.sh
+++ b/tools/build/tests/run.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3function test_ex { 4function test_ex {
4 make -C ex V=1 clean > ex.out 2>&1 5 make -C ex V=1 clean > ex.out 2>&1
diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile
index b4286196b763..860fa151640a 100644
--- a/tools/cgroup/Makefile
+++ b/tools/cgroup/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for cgroup tools 2# Makefile for cgroup tools
2 3
3CC = $(CROSS_COMPILE)gcc 4CC = $(CROSS_COMPILE)gcc
diff --git a/tools/cgroup/cgroup_event_listener.c b/tools/cgroup/cgroup_event_listener.c
index 4eb5507205c9..3d70dc831a76 100644
--- a/tools/cgroup/cgroup_event_listener.c
+++ b/tools/cgroup/cgroup_event_listener.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * cgroup_event_listener.c - Simple listener of cgroup events 3 * cgroup_event_listener.c - Simple listener of cgroup events
3 * 4 *
diff --git a/tools/firewire/Makefile b/tools/firewire/Makefile
index 81767adaae7d..67b6e9fca83c 100644
--- a/tools/firewire/Makefile
+++ b/tools/firewire/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1prefix = /usr 2prefix = /usr
2nosy-dump-version = 0.4 3nosy-dump-version = 0.4
3 4
diff --git a/tools/firewire/decode-fcp.c b/tools/firewire/decode-fcp.c
index e41223b6a4c8..b67ebc88434d 100644
--- a/tools/firewire/decode-fcp.c
+++ b/tools/firewire/decode-fcp.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/firewire-constants.h> 2#include <linux/firewire-constants.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/firewire/list.h b/tools/firewire/list.h
index 41f4bdadf634..6278d08e99e3 100644
--- a/tools/firewire/list.h
+++ b/tools/firewire/list.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1struct list { 2struct list {
2 struct list *next, *prev; 3 struct list *next, *prev;
3}; 4};
diff --git a/tools/firewire/nosy-dump.h b/tools/firewire/nosy-dump.h
index 3a4b5b33ba5d..69e5e594f284 100644
--- a/tools/firewire/nosy-dump.h
+++ b/tools/firewire/nosy-dump.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __nosy_dump_h__ 2#ifndef __nosy_dump_h__
2#define __nosy_dump_h__ 3#define __nosy_dump_h__
3 4
diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile
index b4401536cfa9..805a2c0cf4cd 100644
--- a/tools/gpio/Makefile
+++ b/tools/gpio/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1include ../scripts/Makefile.include 2include ../scripts/Makefile.include
2 3
3bindir ?= /usr/bin 4bindir ?= /usr/bin
diff --git a/tools/gpio/gpio-utils.c b/tools/gpio/gpio-utils.c
index b86a32d90d88..cf7e2f3419ee 100644
--- a/tools/gpio/gpio-utils.c
+++ b/tools/gpio/gpio-utils.c
@@ -76,7 +76,8 @@ int gpiotools_request_linehandle(const char *device_name, unsigned int *lines,
76 fd = open(chrdev_name, 0); 76 fd = open(chrdev_name, 0);
77 if (fd == -1) { 77 if (fd == -1) {
78 ret = -errno; 78 ret = -errno;
79 fprintf(stderr, "Failed to open %s\n", chrdev_name); 79 fprintf(stderr, "Failed to open %s, %s\n",
80 chrdev_name, strerror(errno));
80 goto exit_close_error; 81 goto exit_close_error;
81 } 82 }
82 83
@@ -92,8 +93,8 @@ int gpiotools_request_linehandle(const char *device_name, unsigned int *lines,
92 ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); 93 ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req);
93 if (ret == -1) { 94 if (ret == -1) {
94 ret = -errno; 95 ret = -errno;
95 fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", 96 fprintf(stderr, "Failed to issue %s (%d), %s\n",
96 ret); 97 "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno));
97 } 98 }
98 99
99exit_close_error: 100exit_close_error:
@@ -118,8 +119,9 @@ int gpiotools_set_values(const int fd, struct gpiohandle_data *data)
118 ret = ioctl(fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, data); 119 ret = ioctl(fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, data);
119 if (ret == -1) { 120 if (ret == -1) {
120 ret = -errno; 121 ret = -errno;
121 fprintf(stderr, "Failed to issue %s (%d)\n", 122 fprintf(stderr, "Failed to issue %s (%d), %s\n",
122 "GPIOHANDLE_SET_LINE_VALUES_IOCTL", ret); 123 "GPIOHANDLE_SET_LINE_VALUES_IOCTL", ret,
124 strerror(errno));
123 } 125 }
124 126
125 return ret; 127 return ret;
@@ -141,8 +143,9 @@ int gpiotools_get_values(const int fd, struct gpiohandle_data *data)
141 ret = ioctl(fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, data); 143 ret = ioctl(fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, data);
142 if (ret == -1) { 144 if (ret == -1) {
143 ret = -errno; 145 ret = -errno;
144 fprintf(stderr, "Failed to issue %s (%d)\n", 146 fprintf(stderr, "Failed to issue %s (%d), %s\n",
145 "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret); 147 "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret,
148 strerror(errno));
146 } 149 }
147 150
148 return ret; 151 return ret;
diff --git a/tools/hv/Makefile b/tools/hv/Makefile
index 0d1e61b81844..31503819454d 100644
--- a/tools/hv/Makefile
+++ b/tools/hv/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for Hyper-V tools 2# Makefile for Hyper-V tools
2 3
3CC = $(CROSS_COMPILE)gcc 4CC = $(CROSS_COMPILE)gcc
diff --git a/tools/hv/hv_get_dhcp_info.sh b/tools/hv/hv_get_dhcp_info.sh
index ccd3e9532764..c38686c44656 100755
--- a/tools/hv/hv_get_dhcp_info.sh
+++ b/tools/hv/hv_get_dhcp_info.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3# This example script retrieves the DHCP state of a given interface. 4# This example script retrieves the DHCP state of a given interface.
4# In the interest of keeping the KVP daemon code free of distro specific 5# In the interest of keeping the KVP daemon code free of distro specific
diff --git a/tools/hv/hv_set_ifconfig.sh b/tools/hv/hv_set_ifconfig.sh
index 735aafd64a3f..7ed9f85ef908 100755
--- a/tools/hv/hv_set_ifconfig.sh
+++ b/tools/hv/hv_set_ifconfig.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3# This example script activates an interface based on the specified 4# This example script activates an interface based on the specified
4# configuration. 5# configuration.
diff --git a/tools/hv/lsvmbus b/tools/hv/lsvmbus
index e8fecd61871f..353e56768df8 100644
--- a/tools/hv/lsvmbus
+++ b/tools/hv/lsvmbus
@@ -1,4 +1,5 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# SPDX-License-Identifier: GPL-2.0
2 3
3import os 4import os
4from optparse import OptionParser 5from optparse import OptionParser
diff --git a/tools/iio/Makefile b/tools/iio/Makefile
index d4d956020adf..a08e7a47d6a3 100644
--- a/tools/iio/Makefile
+++ b/tools/iio/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1include ../scripts/Makefile.include 2include ../scripts/Makefile.include
2 3
3bindir ?= /usr/bin 4bindir ?= /usr/bin
diff --git a/tools/include/asm-generic/atomic-gcc.h b/tools/include/asm-generic/atomic-gcc.h
index 5e9738f97bf3..4c1966f7c77a 100644
--- a/tools/include/asm-generic/atomic-gcc.h
+++ b/tools/include/asm-generic/atomic-gcc.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_ASM_GENERIC_ATOMIC_H 2#ifndef __TOOLS_ASM_GENERIC_ATOMIC_H
2#define __TOOLS_ASM_GENERIC_ATOMIC_H 3#define __TOOLS_ASM_GENERIC_ATOMIC_H
3 4
@@ -21,7 +22,7 @@
21 */ 22 */
22static inline int atomic_read(const atomic_t *v) 23static inline int atomic_read(const atomic_t *v)
23{ 24{
24 return ACCESS_ONCE((v)->counter); 25 return READ_ONCE((v)->counter);
25} 26}
26 27
27/** 28/**
diff --git a/tools/include/asm-generic/bitops.h b/tools/include/asm-generic/bitops.h
index 0304600121da..9bce3b56b5e7 100644
--- a/tools/include/asm-generic/bitops.h
+++ b/tools/include/asm-generic/bitops.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_ASM_GENERIC_BITOPS_H 2#ifndef __TOOLS_ASM_GENERIC_BITOPS_H
2#define __TOOLS_ASM_GENERIC_BITOPS_H 3#define __TOOLS_ASM_GENERIC_BITOPS_H
3 4
diff --git a/tools/include/asm-generic/bitops/__ffs.h b/tools/include/asm-generic/bitops/__ffs.h
index b3accfdf24b9..9d1310519497 100644
--- a/tools/include/asm-generic/bitops/__ffs.h
+++ b/tools/include/asm-generic/bitops/__ffs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS___FFS_H_ 2#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS___FFS_H_
2#define _TOOLS_LINUX_ASM_GENERIC_BITOPS___FFS_H_ 3#define _TOOLS_LINUX_ASM_GENERIC_BITOPS___FFS_H_
3 4
diff --git a/tools/include/asm-generic/bitops/__fls.h b/tools/include/asm-generic/bitops/__fls.h
index a60a7ccb6782..03f721a8a2b1 100644
--- a/tools/include/asm-generic/bitops/__fls.h
+++ b/tools/include/asm-generic/bitops/__fls.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _ASM_GENERIC_BITOPS___FLS_H_ 2#ifndef _ASM_GENERIC_BITOPS___FLS_H_
2#define _ASM_GENERIC_BITOPS___FLS_H_ 3#define _ASM_GENERIC_BITOPS___FLS_H_
3 4
diff --git a/tools/include/asm-generic/bitops/arch_hweight.h b/tools/include/asm-generic/bitops/arch_hweight.h
index 6a211f40665c..c2705e1d220d 100644
--- a/tools/include/asm-generic/bitops/arch_hweight.h
+++ b/tools/include/asm-generic/bitops/arch_hweight.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ 2#ifndef _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_
2#define _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ 3#define _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_
3 4
diff --git a/tools/include/asm-generic/bitops/atomic.h b/tools/include/asm-generic/bitops/atomic.h
index 68b8c1516c5a..21c41ccd1266 100644
--- a/tools/include/asm-generic/bitops/atomic.h
+++ b/tools/include/asm-generic/bitops/atomic.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_ATOMIC_H_ 2#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_ATOMIC_H_
2#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_ATOMIC_H_ 3#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_ATOMIC_H_
3 4
diff --git a/tools/include/asm-generic/bitops/const_hweight.h b/tools/include/asm-generic/bitops/const_hweight.h
index 0a7e06623470..149faeeeeaf2 100644
--- a/tools/include/asm-generic/bitops/const_hweight.h
+++ b/tools/include/asm-generic/bitops/const_hweight.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ 2#ifndef _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_
2#define _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ 3#define _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_
3 4
diff --git a/tools/include/asm-generic/bitops/find.h b/tools/include/asm-generic/bitops/find.h
index 5538ecdc964a..9311fadaaab2 100644
--- a/tools/include/asm-generic/bitops/find.h
+++ b/tools/include/asm-generic/bitops/find.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ 2#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_
2#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ 3#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_
3 4
diff --git a/tools/include/asm-generic/bitops/fls.h b/tools/include/asm-generic/bitops/fls.h
index 0576d1f42f43..753aecaab641 100644
--- a/tools/include/asm-generic/bitops/fls.h
+++ b/tools/include/asm-generic/bitops/fls.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _ASM_GENERIC_BITOPS_FLS_H_ 2#ifndef _ASM_GENERIC_BITOPS_FLS_H_
2#define _ASM_GENERIC_BITOPS_FLS_H_ 3#define _ASM_GENERIC_BITOPS_FLS_H_
3 4
diff --git a/tools/include/asm-generic/bitops/fls64.h b/tools/include/asm-generic/bitops/fls64.h
index b097cf8444e3..866f2b2304ff 100644
--- a/tools/include/asm-generic/bitops/fls64.h
+++ b/tools/include/asm-generic/bitops/fls64.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _ASM_GENERIC_BITOPS_FLS64_H_ 2#ifndef _ASM_GENERIC_BITOPS_FLS64_H_
2#define _ASM_GENERIC_BITOPS_FLS64_H_ 3#define _ASM_GENERIC_BITOPS_FLS64_H_
3 4
diff --git a/tools/include/asm-generic/bitops/hweight.h b/tools/include/asm-generic/bitops/hweight.h
index 290120c01a8e..3e681982bcd1 100644
--- a/tools/include/asm-generic/bitops/hweight.h
+++ b/tools/include/asm-generic/bitops/hweight.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_HWEIGHT_H_ 2#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_HWEIGHT_H_
2#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_HWEIGHT_H_ 3#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_HWEIGHT_H_
3 4
diff --git a/tools/include/asm-generic/bitsperlong.h b/tools/include/asm-generic/bitsperlong.h
index 45eca517efb3..8f2283052333 100644
--- a/tools/include/asm-generic/bitsperlong.h
+++ b/tools/include/asm-generic/bitsperlong.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __ASM_GENERIC_BITS_PER_LONG 2#ifndef __ASM_GENERIC_BITS_PER_LONG
2#define __ASM_GENERIC_BITS_PER_LONG 3#define __ASM_GENERIC_BITS_PER_LONG
3 4
diff --git a/tools/include/asm-generic/hugetlb_encode.h b/tools/include/asm-generic/hugetlb_encode.h
new file mode 100644
index 000000000000..e4732d3c2998
--- /dev/null
+++ b/tools/include/asm-generic/hugetlb_encode.h
@@ -0,0 +1,34 @@
1#ifndef _ASM_GENERIC_HUGETLB_ENCODE_H_
2#define _ASM_GENERIC_HUGETLB_ENCODE_H_
3
4/*
5 * Several system calls take a flag to request "hugetlb" huge pages.
6 * Without further specification, these system calls will use the
7 * system's default huge page size. If a system supports multiple
8 * huge page sizes, the desired huge page size can be specified in
9 * bits [26:31] of the flag arguments. The value in these 6 bits
10 * will encode the log2 of the huge page size.
11 *
12 * The following definitions are associated with this huge page size
13 * encoding in flag arguments. System call specific header files
14 * that use this encoding should include this file. They can then
15 * provide definitions based on these with their own specific prefix.
16 * for example:
17 * #define MAP_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
18 */
19
20#define HUGETLB_FLAG_ENCODE_SHIFT 26
21#define HUGETLB_FLAG_ENCODE_MASK 0x3f
22
23#define HUGETLB_FLAG_ENCODE_64KB (16 << HUGETLB_FLAG_ENCODE_SHIFT)
24#define HUGETLB_FLAG_ENCODE_512KB (19 << HUGETLB_FLAG_ENCODE_SHIFT)
25#define HUGETLB_FLAG_ENCODE_1MB (20 << HUGETLB_FLAG_ENCODE_SHIFT)
26#define HUGETLB_FLAG_ENCODE_2MB (21 << HUGETLB_FLAG_ENCODE_SHIFT)
27#define HUGETLB_FLAG_ENCODE_8MB (23 << HUGETLB_FLAG_ENCODE_SHIFT)
28#define HUGETLB_FLAG_ENCODE_16MB (24 << HUGETLB_FLAG_ENCODE_SHIFT)
29#define HUGETLB_FLAG_ENCODE_256MB (28 << HUGETLB_FLAG_ENCODE_SHIFT)
30#define HUGETLB_FLAG_ENCODE_1GB (30 << HUGETLB_FLAG_ENCODE_SHIFT)
31#define HUGETLB_FLAG_ENCODE_2GB (31 << HUGETLB_FLAG_ENCODE_SHIFT)
32#define HUGETLB_FLAG_ENCODE_16GB (34 << HUGETLB_FLAG_ENCODE_SHIFT)
33
34#endif /* _ASM_GENERIC_HUGETLB_ENCODE_H_ */
diff --git a/tools/include/asm/alternative-asm.h b/tools/include/asm/alternative-asm.h
index 2a4d1bfa2988..b54bd860dff6 100644
--- a/tools/include/asm/alternative-asm.h
+++ b/tools/include/asm/alternative-asm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_ASM_ALTERNATIVE_ASM_H 2#ifndef _TOOLS_ASM_ALTERNATIVE_ASM_H
2#define _TOOLS_ASM_ALTERNATIVE_ASM_H 3#define _TOOLS_ASM_ALTERNATIVE_ASM_H
3 4
diff --git a/tools/include/asm/atomic.h b/tools/include/asm/atomic.h
index 70794f538a86..8c9bfffd4191 100644
--- a/tools/include/asm/atomic.h
+++ b/tools/include/asm/atomic.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_LINUX_ASM_ATOMIC_H 2#ifndef __TOOLS_LINUX_ASM_ATOMIC_H
2#define __TOOLS_LINUX_ASM_ATOMIC_H 3#define __TOOLS_LINUX_ASM_ATOMIC_H
3 4
diff --git a/tools/include/asm/barrier.h b/tools/include/asm/barrier.h
index ac66ac594685..391d942536e5 100644
--- a/tools/include/asm/barrier.h
+++ b/tools/include/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#if defined(__i386__) || defined(__x86_64__) 2#if defined(__i386__) || defined(__x86_64__)
2#include "../../arch/x86/include/asm/barrier.h" 3#include "../../arch/x86/include/asm/barrier.h"
3#elif defined(__arm__) 4#elif defined(__arm__)
diff --git a/tools/include/asm/bug.h b/tools/include/asm/bug.h
index 4790f047a89c..bbd75ac8b202 100644
--- a/tools/include/asm/bug.h
+++ b/tools/include/asm/bug.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_ASM_BUG_H 2#ifndef _TOOLS_ASM_BUG_H
2#define _TOOLS_ASM_BUG_H 3#define _TOOLS_ASM_BUG_H
3 4
diff --git a/tools/include/asm/export.h b/tools/include/asm/export.h
new file mode 100644
index 000000000000..2cb1a0d83035
--- /dev/null
+++ b/tools/include/asm/export.h
@@ -0,0 +1,7 @@
1#ifndef _TOOLS_ASM_EXPORT_H
2#define _TOOLS_ASM_EXPORT_H
3
4#define EXPORT_SYMBOL(x)
5#define EXPORT_SYMBOL_GPL(x)
6
7#endif /* _TOOLS_ASM_EXPORT_H */
diff --git a/tools/include/linux/atomic.h b/tools/include/linux/atomic.h
index 9f21fc2b092b..00a6c4ca562b 100644
--- a/tools/include/linux/atomic.h
+++ b/tools/include/linux/atomic.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_LINUX_ATOMIC_H 2#ifndef __TOOLS_LINUX_ATOMIC_H
2#define __TOOLS_LINUX_ATOMIC_H 3#define __TOOLS_LINUX_ATOMIC_H
3 4
diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
index e8b9f518e36b..ca160270fdfa 100644
--- a/tools/include/linux/bitmap.h
+++ b/tools/include/linux/bitmap.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_BITOPS_H 2#ifndef _PERF_BITOPS_H
2#define _PERF_BITOPS_H 3#define _PERF_BITOPS_H
3 4
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index 969db1981868..acc704bd3998 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_BITOPS_H_ 2#ifndef _TOOLS_LINUX_BITOPS_H_
2#define _TOOLS_LINUX_BITOPS_H_ 3#define _TOOLS_LINUX_BITOPS_H_
3 4
diff --git a/tools/include/linux/bug.h b/tools/include/linux/bug.h
index 8e4a4f49135d..85f80258a15f 100644
--- a/tools/include/linux/bug.h
+++ b/tools/include/linux/bug.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_PERF_LINUX_BUG_H 2#ifndef _TOOLS_PERF_LINUX_BUG_H
2#define _TOOLS_PERF_LINUX_BUG_H 3#define _TOOLS_PERF_LINUX_BUG_H
3 4
diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h
index 3723b9f8f964..a3a4427441bf 100644
--- a/tools/include/linux/compiler-gcc.h
+++ b/tools/include/linux/compiler-gcc.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_COMPILER_H_ 2#ifndef _TOOLS_LINUX_COMPILER_H_
2#error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead." 3#error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
3#endif 4#endif
diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index d7a5604c38d7..07fd03c74a77 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_COMPILER_H_ 2#ifndef _TOOLS_LINUX_COMPILER_H_
2#define _TOOLS_LINUX_COMPILER_H_ 3#define _TOOLS_LINUX_COMPILER_H_
3 4
diff --git a/tools/include/linux/debug_locks.h b/tools/include/linux/debug_locks.h
index 61cc7f501168..72d595ce764a 100644
--- a/tools/include/linux/debug_locks.h
+++ b/tools/include/linux/debug_locks.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_DEBUG_LOCKS_H_ 2#ifndef _LIBLOCKDEP_DEBUG_LOCKS_H_
2#define _LIBLOCKDEP_DEBUG_LOCKS_H_ 3#define _LIBLOCKDEP_DEBUG_LOCKS_H_
3 4
diff --git a/tools/include/linux/err.h b/tools/include/linux/err.h
index abf0478a8fb2..7a8b61ad44cb 100644
--- a/tools/include/linux/err.h
+++ b/tools/include/linux/err.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_LINUX_ERR_H 2#ifndef __TOOLS_LINUX_ERR_H
2#define __TOOLS_LINUX_ERR_H 3#define __TOOLS_LINUX_ERR_H
3 4
diff --git a/tools/include/linux/filter.h b/tools/include/linux/filter.h
index 4ce25d43e8e3..c5e512da8d8a 100644
--- a/tools/include/linux/filter.h
+++ b/tools/include/linux/filter.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Linux Socket Filter Data Structures 3 * Linux Socket Filter Data Structures
3 */ 4 */
diff --git a/tools/include/linux/hardirq.h b/tools/include/linux/hardirq.h
index c8f3f8f58729..b25580b6a9be 100644
--- a/tools/include/linux/hardirq.h
+++ b/tools/include/linux/hardirq.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_LINUX_HARDIRQ_H_ 2#ifndef _LIBLOCKDEP_LINUX_HARDIRQ_H_
2#define _LIBLOCKDEP_LINUX_HARDIRQ_H_ 3#define _LIBLOCKDEP_LINUX_HARDIRQ_H_
3 4
diff --git a/tools/include/linux/hashtable.h b/tools/include/linux/hashtable.h
index 251eabf2a05e..434dd5ac6d71 100644
--- a/tools/include/linux/hashtable.h
+++ b/tools/include/linux/hashtable.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Statically sized hash table implementation 3 * Statically sized hash table implementation
3 * (C) 2012 Sasha Levin <levinsasha928@gmail.com> 4 * (C) 2012 Sasha Levin <levinsasha928@gmail.com>
diff --git a/tools/include/linux/irqflags.h b/tools/include/linux/irqflags.h
index df77669cfe1c..e734da3e5b33 100644
--- a/tools/include/linux/irqflags.h
+++ b/tools/include/linux/irqflags.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_LINUX_TRACE_IRQFLAGS_H_ 2#ifndef _LIBLOCKDEP_LINUX_TRACE_IRQFLAGS_H_
2#define _LIBLOCKDEP_LINUX_TRACE_IRQFLAGS_H_ 3#define _LIBLOCKDEP_LINUX_TRACE_IRQFLAGS_H_
3 4
diff --git a/tools/include/linux/kallsyms.h b/tools/include/linux/kallsyms.h
index 582cc1e5f3a4..89ca6fe257cc 100644
--- a/tools/include/linux/kallsyms.h
+++ b/tools/include/linux/kallsyms.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_LINUX_KALLSYMS_H_ 2#ifndef _LIBLOCKDEP_LINUX_KALLSYMS_H_
2#define _LIBLOCKDEP_LINUX_KALLSYMS_H_ 3#define _LIBLOCKDEP_LINUX_KALLSYMS_H_
3 4
diff --git a/tools/include/linux/kern_levels.h b/tools/include/linux/kern_levels.h
index 3b9bade28698..778ecb984480 100644
--- a/tools/include/linux/kern_levels.h
+++ b/tools/include/linux/kern_levels.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __KERN_LEVELS_H__ 2#ifndef __KERN_LEVELS_H__
2#define __KERN_LEVELS_H__ 3#define __KERN_LEVELS_H__
3 4
diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 77d2e94ca5df..0ad884452c5c 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_LINUX_KERNEL_H 2#ifndef __TOOLS_LINUX_KERNEL_H
2#define __TOOLS_LINUX_KERNEL_H 3#define __TOOLS_LINUX_KERNEL_H
3 4
diff --git a/tools/include/linux/kmemcheck.h b/tools/include/linux/kmemcheck.h
index 94d598bc6abe..ea32a7d3cf1b 100644
--- a/tools/include/linux/kmemcheck.h
+++ b/tools/include/linux/kmemcheck.h
@@ -1,8 +1 @@
1#ifndef _LIBLOCKDEP_LINUX_KMEMCHECK_H_ /* SPDX-License-Identifier: GPL-2.0 */
2#define _LIBLOCKDEP_LINUX_KMEMCHECK_H_
3
4static inline void kmemcheck_mark_initialized(void *address, unsigned int n)
5{
6}
7
8#endif
diff --git a/tools/include/linux/list.h b/tools/include/linux/list.h
index 1da423820ad4..b2fc48d5478c 100644
--- a/tools/include/linux/list.h
+++ b/tools/include/linux/list.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_LINUX_LIST_H 2#ifndef __TOOLS_LINUX_LIST_H
2#define __TOOLS_LINUX_LIST_H 3#define __TOOLS_LINUX_LIST_H
3 4
diff --git a/tools/include/linux/lockdep.h b/tools/include/linux/lockdep.h
index 8da3e8effafa..940c1b075659 100644
--- a/tools/include/linux/lockdep.h
+++ b/tools/include/linux/lockdep.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_LOCKDEP_H_ 2#ifndef _LIBLOCKDEP_LOCKDEP_H_
2#define _LIBLOCKDEP_LOCKDEP_H_ 3#define _LIBLOCKDEP_LOCKDEP_H_
3 4
diff --git a/tools/include/linux/module.h b/tools/include/linux/module.h
index 07055db296f3..2c999abf68e7 100644
--- a/tools/include/linux/module.h
+++ b/tools/include/linux/module.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_LINUX_MODULE_H_ 2#ifndef _LIBLOCKDEP_LINUX_MODULE_H_
2#define _LIBLOCKDEP_LINUX_MODULE_H_ 3#define _LIBLOCKDEP_LINUX_MODULE_H_
3 4
diff --git a/tools/include/linux/poison.h b/tools/include/linux/poison.h
index 51334edec506..9fdcd3eaac3b 100644
--- a/tools/include/linux/poison.h
+++ b/tools/include/linux/poison.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LINUX_POISON_H 2#ifndef _LINUX_POISON_H
2#define _LINUX_POISON_H 3#define _LINUX_POISON_H
3 4
@@ -14,6 +15,10 @@
14# define POISON_POINTER_DELTA 0 15# define POISON_POINTER_DELTA 0
15#endif 16#endif
16 17
18#ifdef __cplusplus
19#define LIST_POISON1 NULL
20#define LIST_POISON2 NULL
21#else
17/* 22/*
18 * These are non-NULL pointers that will result in page faults 23 * These are non-NULL pointers that will result in page faults
19 * under normal circumstances, used to verify that nobody uses 24 * under normal circumstances, used to verify that nobody uses
@@ -21,6 +26,7 @@
21 */ 26 */
22#define LIST_POISON1 ((void *) 0x100 + POISON_POINTER_DELTA) 27#define LIST_POISON1 ((void *) 0x100 + POISON_POINTER_DELTA)
23#define LIST_POISON2 ((void *) 0x200 + POISON_POINTER_DELTA) 28#define LIST_POISON2 ((void *) 0x200 + POISON_POINTER_DELTA)
29#endif
24 30
25/********** include/linux/timer.h **********/ 31/********** include/linux/timer.h **********/
26/* 32/*
diff --git a/tools/include/linux/rcu.h b/tools/include/linux/rcu.h
index 5080649dad04..7d02527e5bce 100644
--- a/tools/include/linux/rcu.h
+++ b/tools/include/linux/rcu.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_RCU_H_ 2#ifndef _LIBLOCKDEP_RCU_H_
2#define _LIBLOCKDEP_RCU_H_ 3#define _LIBLOCKDEP_RCU_H_
3 4
diff --git a/tools/include/linux/refcount.h b/tools/include/linux/refcount.h
index a0177c1f55b1..36cb29bc57c2 100644
--- a/tools/include/linux/refcount.h
+++ b/tools/include/linux/refcount.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_REFCOUNT_H 2#ifndef _TOOLS_LINUX_REFCOUNT_H
2#define _TOOLS_LINUX_REFCOUNT_H 3#define _TOOLS_LINUX_REFCOUNT_H
3 4
diff --git a/tools/include/linux/spinlock.h b/tools/include/linux/spinlock.h
index 417cda4f793f..4ed569fcb139 100644
--- a/tools/include/linux/spinlock.h
+++ b/tools/include/linux/spinlock.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __LINUX_SPINLOCK_H_ 2#ifndef __LINUX_SPINLOCK_H_
2#define __LINUX_SPINLOCK_H_ 3#define __LINUX_SPINLOCK_H_
3 4
diff --git a/tools/include/linux/stacktrace.h b/tools/include/linux/stacktrace.h
index 39aecc6b19d1..ae343ac35bfa 100644
--- a/tools/include/linux/stacktrace.h
+++ b/tools/include/linux/stacktrace.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_LINUX_STACKTRACE_H_ 2#ifndef _LIBLOCKDEP_LINUX_STACKTRACE_H_
2#define _LIBLOCKDEP_LINUX_STACKTRACE_H_ 3#define _LIBLOCKDEP_LINUX_STACKTRACE_H_
3 4
diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index a30fad536f52..6c3e2cc274c5 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_STRING_H_ 2#ifndef _TOOLS_LINUX_STRING_H_
2#define _TOOLS_LINUX_STRING_H_ 3#define _TOOLS_LINUX_STRING_H_
3 4
diff --git a/tools/include/linux/stringify.h b/tools/include/linux/stringify.h
index 841cec8ed525..60e2c187da2c 100644
--- a/tools/include/linux/stringify.h
+++ b/tools/include/linux/stringify.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __LINUX_STRINGIFY_H 2#ifndef __LINUX_STRINGIFY_H
2#define __LINUX_STRINGIFY_H 3#define __LINUX_STRINGIFY_H
3 4
diff --git a/tools/include/linux/time64.h b/tools/include/linux/time64.h
index df9265483d65..55fa644b95fd 100644
--- a/tools/include/linux/time64.h
+++ b/tools/include/linux/time64.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_TIME64_H 2#ifndef _TOOLS_LINUX_TIME64_H
2#define _TOOLS_LINUX_TIME64_H 3#define _TOOLS_LINUX_TIME64_H
3 4
diff --git a/tools/include/linux/types.h b/tools/include/linux/types.h
index 77a28a26a670..154eb4e3ca7c 100644
--- a/tools/include/linux/types.h
+++ b/tools/include/linux/types.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LINUX_TYPES_H_ 2#ifndef _TOOLS_LINUX_TYPES_H_
2#define _TOOLS_LINUX_TYPES_H_ 3#define _TOOLS_LINUX_TYPES_H_
3 4
diff --git a/tools/include/linux/unaligned/packed_struct.h b/tools/include/linux/unaligned/packed_struct.h
index c0d817de4df2..dbd93c7df2e1 100644
--- a/tools/include/linux/unaligned/packed_struct.h
+++ b/tools/include/linux/unaligned/packed_struct.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H 2#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
2#define _LINUX_UNALIGNED_PACKED_STRUCT_H 3#define _LINUX_UNALIGNED_PACKED_STRUCT_H
3 4
diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
index 84c17d836578..f7d1d1698938 100644
--- a/tools/include/tools/be_byteshift.h
+++ b/tools/include/tools/be_byteshift.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_BE_BYTESHIFT_H 2#ifndef _TOOLS_BE_BYTESHIFT_H
2#define _TOOLS_BE_BYTESHIFT_H 3#define _TOOLS_BE_BYTESHIFT_H
3 4
diff --git a/tools/include/tools/endian.h b/tools/include/tools/endian.h
index 8001194008da..c67888fd427e 100644
--- a/tools/include/tools/endian.h
+++ b/tools/include/tools/endian.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_ENDIAN_H 2#ifndef _TOOLS_ENDIAN_H
2#define _TOOLS_ENDIAN_H 3#define _TOOLS_ENDIAN_H
3 4
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
index 8fe9f2488ec7..dc8565f39717 100644
--- a/tools/include/tools/le_byteshift.h
+++ b/tools/include/tools/le_byteshift.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TOOLS_LE_BYTESHIFT_H 2#ifndef _TOOLS_LE_BYTESHIFT_H
2#define _TOOLS_LE_BYTESHIFT_H 3#define _TOOLS_LE_BYTESHIFT_H
3 4
diff --git a/tools/include/uapi/asm-generic/ioctls.h b/tools/include/uapi/asm-generic/ioctls.h
index 14baf9f23a14..040651735662 100644
--- a/tools/include/uapi/asm-generic/ioctls.h
+++ b/tools/include/uapi/asm-generic/ioctls.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_GENERIC_IOCTLS_H 2#ifndef __ASM_GENERIC_IOCTLS_H
2#define __ASM_GENERIC_IOCTLS_H 3#define __ASM_GENERIC_IOCTLS_H
3 4
diff --git a/tools/include/uapi/asm-generic/mman-common.h b/tools/include/uapi/asm-generic/mman-common.h
index 8c27db0c5c08..f8b134f5608f 100644
--- a/tools/include/uapi/asm-generic/mman-common.h
+++ b/tools/include/uapi/asm-generic/mman-common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_GENERIC_MMAN_COMMON_H 2#ifndef __ASM_GENERIC_MMAN_COMMON_H
2#define __ASM_GENERIC_MMAN_COMMON_H 3#define __ASM_GENERIC_MMAN_COMMON_H
3 4
@@ -16,6 +17,7 @@
16 17
17#define MAP_SHARED 0x01 /* Share changes */ 18#define MAP_SHARED 0x01 /* Share changes */
18#define MAP_PRIVATE 0x02 /* Changes are private */ 19#define MAP_PRIVATE 0x02 /* Changes are private */
20#define MAP_SHARED_VALIDATE 0x03 /* share + validate extension flags */
19#define MAP_TYPE 0x0f /* Mask for type of mapping */ 21#define MAP_TYPE 0x0f /* Mask for type of mapping */
20#define MAP_FIXED 0x10 /* Interpret addr exactly */ 22#define MAP_FIXED 0x10 /* Interpret addr exactly */
21#define MAP_ANONYMOUS 0x20 /* don't use a file */ 23#define MAP_ANONYMOUS 0x20 /* don't use a file */
@@ -58,20 +60,12 @@
58 overrides the coredump filter bits */ 60 overrides the coredump filter bits */
59#define MADV_DODUMP 17 /* Clear the MADV_DONTDUMP flag */ 61#define MADV_DODUMP 17 /* Clear the MADV_DONTDUMP flag */
60 62
63#define MADV_WIPEONFORK 18 /* Zero memory on fork, child only */
64#define MADV_KEEPONFORK 19 /* Undo MADV_WIPEONFORK */
65
61/* compatibility flags */ 66/* compatibility flags */
62#define MAP_FILE 0 67#define MAP_FILE 0
63 68
64/*
65 * When MAP_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
66 * This gives us 6 bits, which is enough until someone invents 128 bit address
67 * spaces.
68 *
69 * Assume these are all power of twos.
70 * When 0 use the default page size.
71 */
72#define MAP_HUGE_SHIFT 26
73#define MAP_HUGE_MASK 0x3f
74
75#define PKEY_DISABLE_ACCESS 0x1 69#define PKEY_DISABLE_ACCESS 0x1
76#define PKEY_DISABLE_WRITE 0x2 70#define PKEY_DISABLE_WRITE 0x2
77#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ 71#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\
diff --git a/tools/include/uapi/asm-generic/mman.h b/tools/include/uapi/asm-generic/mman.h
index 10fa7857777f..2dffcbf705b3 100644
--- a/tools/include/uapi/asm-generic/mman.h
+++ b/tools/include/uapi/asm-generic/mman.h
@@ -1,7 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __ASM_GENERIC_MMAN_H 2#ifndef __ASM_GENERIC_MMAN_H
2#define __ASM_GENERIC_MMAN_H 3#define __ASM_GENERIC_MMAN_H
3 4
4#include <uapi/asm-generic/mman-common.h> 5#include <asm-generic/mman-common.h>
5 6
6#define MAP_GROWSDOWN 0x0100 /* stack-like segment */ 7#define MAP_GROWSDOWN 0x0100 /* stack-like segment */
7#define MAP_DENYWRITE 0x0800 /* ETXTBSY */ 8#define MAP_DENYWRITE 0x0800 /* ETXTBSY */
diff --git a/tools/include/uapi/drm/drm.h b/tools/include/uapi/drm/drm.h
index 101593ab10ac..97677cd6964d 100644
--- a/tools/include/uapi/drm/drm.h
+++ b/tools/include/uapi/drm/drm.h
@@ -700,6 +700,7 @@ struct drm_prime_handle {
700 700
701struct drm_syncobj_create { 701struct drm_syncobj_create {
702 __u32 handle; 702 __u32 handle;
703#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0)
703 __u32 flags; 704 __u32 flags;
704}; 705};
705 706
@@ -718,6 +719,24 @@ struct drm_syncobj_handle {
718 __u32 pad; 719 __u32 pad;
719}; 720};
720 721
722#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)
723#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)
724struct drm_syncobj_wait {
725 __u64 handles;
726 /* absolute timeout */
727 __s64 timeout_nsec;
728 __u32 count_handles;
729 __u32 flags;
730 __u32 first_signaled; /* only valid when not waiting all */
731 __u32 pad;
732};
733
734struct drm_syncobj_array {
735 __u64 handles;
736 __u32 count_handles;
737 __u32 pad;
738};
739
721#if defined(__cplusplus) 740#if defined(__cplusplus)
722} 741}
723#endif 742#endif
@@ -840,6 +859,9 @@ extern "C" {
840#define DRM_IOCTL_SYNCOBJ_DESTROY DRM_IOWR(0xC0, struct drm_syncobj_destroy) 859#define DRM_IOCTL_SYNCOBJ_DESTROY DRM_IOWR(0xC0, struct drm_syncobj_destroy)
841#define DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD DRM_IOWR(0xC1, struct drm_syncobj_handle) 860#define DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD DRM_IOWR(0xC1, struct drm_syncobj_handle)
842#define DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE DRM_IOWR(0xC2, struct drm_syncobj_handle) 861#define DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE DRM_IOWR(0xC2, struct drm_syncobj_handle)
862#define DRM_IOCTL_SYNCOBJ_WAIT DRM_IOWR(0xC3, struct drm_syncobj_wait)
863#define DRM_IOCTL_SYNCOBJ_RESET DRM_IOWR(0xC4, struct drm_syncobj_array)
864#define DRM_IOCTL_SYNCOBJ_SIGNAL DRM_IOWR(0xC5, struct drm_syncobj_array)
843 865
844/** 866/**
845 * Device specific ioctls should only be in their respective headers 867 * Device specific ioctls should only be in their respective headers
diff --git a/tools/include/uapi/drm/i915_drm.h b/tools/include/uapi/drm/i915_drm.h
index 7ccbd6a2bbe0..9816590d3ad2 100644
--- a/tools/include/uapi/drm/i915_drm.h
+++ b/tools/include/uapi/drm/i915_drm.h
@@ -260,6 +260,8 @@ typedef struct _drm_i915_sarea {
260#define DRM_I915_GEM_CONTEXT_GETPARAM 0x34 260#define DRM_I915_GEM_CONTEXT_GETPARAM 0x34
261#define DRM_I915_GEM_CONTEXT_SETPARAM 0x35 261#define DRM_I915_GEM_CONTEXT_SETPARAM 0x35
262#define DRM_I915_PERF_OPEN 0x36 262#define DRM_I915_PERF_OPEN 0x36
263#define DRM_I915_PERF_ADD_CONFIG 0x37
264#define DRM_I915_PERF_REMOVE_CONFIG 0x38
263 265
264#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) 266#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
265#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH) 267#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -315,6 +317,8 @@ typedef struct _drm_i915_sarea {
315#define DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_GETPARAM, struct drm_i915_gem_context_param) 317#define DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_GETPARAM, struct drm_i915_gem_context_param)
316#define DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_SETPARAM, struct drm_i915_gem_context_param) 318#define DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_SETPARAM, struct drm_i915_gem_context_param)
317#define DRM_IOCTL_I915_PERF_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_OPEN, struct drm_i915_perf_open_param) 319#define DRM_IOCTL_I915_PERF_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_OPEN, struct drm_i915_perf_open_param)
320#define DRM_IOCTL_I915_PERF_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_ADD_CONFIG, struct drm_i915_perf_oa_config)
321#define DRM_IOCTL_I915_PERF_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_REMOVE_CONFIG, __u64)
318 322
319/* Allow drivers to submit batchbuffers directly to hardware, relying 323/* Allow drivers to submit batchbuffers directly to hardware, relying
320 * on the security mechanisms provided by hardware. 324 * on the security mechanisms provided by hardware.
@@ -431,6 +435,11 @@ typedef struct drm_i915_irq_wait {
431 */ 435 */
432#define I915_PARAM_HAS_EXEC_BATCH_FIRST 48 436#define I915_PARAM_HAS_EXEC_BATCH_FIRST 48
433 437
438/* Query whether DRM_I915_GEM_EXECBUFFER2 supports supplying an array of
439 * drm_i915_gem_exec_fence structures. See I915_EXEC_FENCE_ARRAY.
440 */
441#define I915_PARAM_HAS_EXEC_FENCE_ARRAY 49
442
434typedef struct drm_i915_getparam { 443typedef struct drm_i915_getparam {
435 __s32 param; 444 __s32 param;
436 /* 445 /*
@@ -812,6 +821,18 @@ struct drm_i915_gem_exec_object2 {
812 __u64 rsvd2; 821 __u64 rsvd2;
813}; 822};
814 823
824struct drm_i915_gem_exec_fence {
825 /**
826 * User's handle for a drm_syncobj to wait on or signal.
827 */
828 __u32 handle;
829
830#define I915_EXEC_FENCE_WAIT (1<<0)
831#define I915_EXEC_FENCE_SIGNAL (1<<1)
832#define __I915_EXEC_FENCE_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_SIGNAL << 1))
833 __u32 flags;
834};
835
815struct drm_i915_gem_execbuffer2 { 836struct drm_i915_gem_execbuffer2 {
816 /** 837 /**
817 * List of gem_exec_object2 structs 838 * List of gem_exec_object2 structs
@@ -826,7 +847,11 @@ struct drm_i915_gem_execbuffer2 {
826 __u32 DR1; 847 __u32 DR1;
827 __u32 DR4; 848 __u32 DR4;
828 __u32 num_cliprects; 849 __u32 num_cliprects;
829 /** This is a struct drm_clip_rect *cliprects */ 850 /**
851 * This is a struct drm_clip_rect *cliprects if I915_EXEC_FENCE_ARRAY
852 * is not set. If I915_EXEC_FENCE_ARRAY is set, then this is a
853 * struct drm_i915_gem_exec_fence *fences.
854 */
830 __u64 cliprects_ptr; 855 __u64 cliprects_ptr;
831#define I915_EXEC_RING_MASK (7<<0) 856#define I915_EXEC_RING_MASK (7<<0)
832#define I915_EXEC_DEFAULT (0<<0) 857#define I915_EXEC_DEFAULT (0<<0)
@@ -927,7 +952,14 @@ struct drm_i915_gem_execbuffer2 {
927 * element). 952 * element).
928 */ 953 */
929#define I915_EXEC_BATCH_FIRST (1<<18) 954#define I915_EXEC_BATCH_FIRST (1<<18)
930#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_BATCH_FIRST<<1)) 955
956/* Setting I915_FENCE_ARRAY implies that num_cliprects and cliprects_ptr
957 * define an array of i915_gem_exec_fence structures which specify a set of
958 * dma fences to wait upon or signal.
959 */
960#define I915_EXEC_FENCE_ARRAY (1<<19)
961
962#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_ARRAY<<1))
931 963
932#define I915_EXEC_CONTEXT_ID_MASK (0xffffffff) 964#define I915_EXEC_CONTEXT_ID_MASK (0xffffffff)
933#define i915_execbuffer2_set_context_id(eb2, context) \ 965#define i915_execbuffer2_set_context_id(eb2, context) \
@@ -1467,6 +1499,22 @@ enum drm_i915_perf_record_type {
1467 DRM_I915_PERF_RECORD_MAX /* non-ABI */ 1499 DRM_I915_PERF_RECORD_MAX /* non-ABI */
1468}; 1500};
1469 1501
1502/**
1503 * Structure to upload perf dynamic configuration into the kernel.
1504 */
1505struct drm_i915_perf_oa_config {
1506 /** String formatted like "%08x-%04x-%04x-%04x-%012x" */
1507 char uuid[36];
1508
1509 __u32 n_mux_regs;
1510 __u32 n_boolean_regs;
1511 __u32 n_flex_regs;
1512
1513 __u64 __user mux_regs_ptr;
1514 __u64 __user boolean_regs_ptr;
1515 __u64 __user flex_regs_ptr;
1516};
1517
1470#if defined(__cplusplus) 1518#if defined(__cplusplus)
1471} 1519}
1472#endif 1520#endif
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 461811e57140..4c223ab30293 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com 2/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
2 * 3 *
3 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
@@ -92,6 +93,7 @@ enum bpf_cmd {
92 BPF_PROG_GET_FD_BY_ID, 93 BPF_PROG_GET_FD_BY_ID,
93 BPF_MAP_GET_FD_BY_ID, 94 BPF_MAP_GET_FD_BY_ID,
94 BPF_OBJ_GET_INFO_BY_FD, 95 BPF_OBJ_GET_INFO_BY_FD,
96 BPF_PROG_QUERY,
95}; 97};
96 98
97enum bpf_map_type { 99enum bpf_map_type {
@@ -111,6 +113,7 @@ enum bpf_map_type {
111 BPF_MAP_TYPE_HASH_OF_MAPS, 113 BPF_MAP_TYPE_HASH_OF_MAPS,
112 BPF_MAP_TYPE_DEVMAP, 114 BPF_MAP_TYPE_DEVMAP,
113 BPF_MAP_TYPE_SOCKMAP, 115 BPF_MAP_TYPE_SOCKMAP,
116 BPF_MAP_TYPE_CPUMAP,
114}; 117};
115 118
116enum bpf_prog_type { 119enum bpf_prog_type {
@@ -129,6 +132,7 @@ enum bpf_prog_type {
129 BPF_PROG_TYPE_LWT_XMIT, 132 BPF_PROG_TYPE_LWT_XMIT,
130 BPF_PROG_TYPE_SOCK_OPS, 133 BPF_PROG_TYPE_SOCK_OPS,
131 BPF_PROG_TYPE_SK_SKB, 134 BPF_PROG_TYPE_SK_SKB,
135 BPF_PROG_TYPE_CGROUP_DEVICE,
132}; 136};
133 137
134enum bpf_attach_type { 138enum bpf_attach_type {
@@ -138,22 +142,53 @@ enum bpf_attach_type {
138 BPF_CGROUP_SOCK_OPS, 142 BPF_CGROUP_SOCK_OPS,
139 BPF_SK_SKB_STREAM_PARSER, 143 BPF_SK_SKB_STREAM_PARSER,
140 BPF_SK_SKB_STREAM_VERDICT, 144 BPF_SK_SKB_STREAM_VERDICT,
145 BPF_CGROUP_DEVICE,
141 __MAX_BPF_ATTACH_TYPE 146 __MAX_BPF_ATTACH_TYPE
142}; 147};
143 148
144#define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE 149#define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
145 150
146enum bpf_sockmap_flags { 151/* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
147 BPF_SOCKMAP_UNSPEC, 152 *
148 BPF_SOCKMAP_STRPARSER, 153 * NONE(default): No further bpf programs allowed in the subtree.
149 __MAX_BPF_SOCKMAP_FLAG 154 *
150}; 155 * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
151 156 * the program in this cgroup yields to sub-cgroup program.
152/* If BPF_F_ALLOW_OVERRIDE flag is used in BPF_PROG_ATTACH command 157 *
153 * to the given target_fd cgroup the descendent cgroup will be able to 158 * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
154 * override effective bpf program that was inherited from this cgroup 159 * that cgroup program gets run in addition to the program in this cgroup.
160 *
161 * Only one program is allowed to be attached to a cgroup with
162 * NONE or BPF_F_ALLOW_OVERRIDE flag.
163 * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
164 * release old program and attach the new one. Attach flags has to match.
165 *
166 * Multiple programs are allowed to be attached to a cgroup with
167 * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
168 * (those that were attached first, run first)
169 * The programs of sub-cgroup are executed first, then programs of
170 * this cgroup and then programs of parent cgroup.
171 * When children program makes decision (like picking TCP CA or sock bind)
172 * parent program has a chance to override it.
173 *
174 * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
175 * A cgroup with NONE doesn't allow any programs in sub-cgroups.
176 * Ex1:
177 * cgrp1 (MULTI progs A, B) ->
178 * cgrp2 (OVERRIDE prog C) ->
179 * cgrp3 (MULTI prog D) ->
180 * cgrp4 (OVERRIDE prog E) ->
181 * cgrp5 (NONE prog F)
182 * the event in cgrp5 triggers execution of F,D,A,B in that order.
183 * if prog F is detached, the execution is E,D,A,B
184 * if prog F and D are detached, the execution is E,A,B
185 * if prog F, E and D are detached, the execution is C,A,B
186 *
187 * All eligible programs are executed regardless of return code from
188 * earlier programs.
155 */ 189 */
156#define BPF_F_ALLOW_OVERRIDE (1U << 0) 190#define BPF_F_ALLOW_OVERRIDE (1U << 0)
191#define BPF_F_ALLOW_MULTI (1U << 1)
157 192
158/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the 193/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
159 * verifier will perform strict alignment checking as if the kernel 194 * verifier will perform strict alignment checking as if the kernel
@@ -181,6 +216,15 @@ enum bpf_sockmap_flags {
181/* Specify numa node during map creation */ 216/* Specify numa node during map creation */
182#define BPF_F_NUMA_NODE (1U << 2) 217#define BPF_F_NUMA_NODE (1U << 2)
183 218
219/* flags for BPF_PROG_QUERY */
220#define BPF_F_QUERY_EFFECTIVE (1U << 0)
221
222#define BPF_OBJ_NAME_LEN 16U
223
224/* Flags for accessing BPF object */
225#define BPF_F_RDONLY (1U << 3)
226#define BPF_F_WRONLY (1U << 4)
227
184union bpf_attr { 228union bpf_attr {
185 struct { /* anonymous struct used by BPF_MAP_CREATE command */ 229 struct { /* anonymous struct used by BPF_MAP_CREATE command */
186 __u32 map_type; /* one of enum bpf_map_type */ 230 __u32 map_type; /* one of enum bpf_map_type */
@@ -194,6 +238,7 @@ union bpf_attr {
194 __u32 numa_node; /* numa node (effective only if 238 __u32 numa_node; /* numa node (effective only if
195 * BPF_F_NUMA_NODE is set). 239 * BPF_F_NUMA_NODE is set).
196 */ 240 */
241 char map_name[BPF_OBJ_NAME_LEN];
197 }; 242 };
198 243
199 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ 244 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -216,11 +261,14 @@ union bpf_attr {
216 __aligned_u64 log_buf; /* user supplied buffer */ 261 __aligned_u64 log_buf; /* user supplied buffer */
217 __u32 kern_version; /* checked when prog_type=kprobe */ 262 __u32 kern_version; /* checked when prog_type=kprobe */
218 __u32 prog_flags; 263 __u32 prog_flags;
264 char prog_name[BPF_OBJ_NAME_LEN];
265 __u32 prog_ifindex; /* ifindex of netdev to prep for */
219 }; 266 };
220 267
221 struct { /* anonymous struct used by BPF_OBJ_* commands */ 268 struct { /* anonymous struct used by BPF_OBJ_* commands */
222 __aligned_u64 pathname; 269 __aligned_u64 pathname;
223 __u32 bpf_fd; 270 __u32 bpf_fd;
271 __u32 file_flags;
224 }; 272 };
225 273
226 struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */ 274 struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
@@ -248,6 +296,7 @@ union bpf_attr {
248 __u32 map_id; 296 __u32 map_id;
249 }; 297 };
250 __u32 next_id; 298 __u32 next_id;
299 __u32 open_flags;
251 }; 300 };
252 301
253 struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */ 302 struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
@@ -255,6 +304,15 @@ union bpf_attr {
255 __u32 info_len; 304 __u32 info_len;
256 __aligned_u64 info; 305 __aligned_u64 info;
257 } info; 306 } info;
307
308 struct { /* anonymous struct used by BPF_PROG_QUERY command */
309 __u32 target_fd; /* container object to query */
310 __u32 attach_type;
311 __u32 query_flags;
312 __u32 attach_flags;
313 __aligned_u64 prog_ids;
314 __u32 prog_cnt;
315 } query;
258} __attribute__((aligned(8))); 316} __attribute__((aligned(8)));
259 317
260/* BPF helper function descriptions: 318/* BPF helper function descriptions:
@@ -318,7 +376,7 @@ union bpf_attr {
318 * jump into another BPF program 376 * jump into another BPF program
319 * @ctx: context pointer passed to next program 377 * @ctx: context pointer passed to next program
320 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY 378 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
321 * @index: index inside array that selects specific program to run 379 * @index: 32-bit index inside array that selects specific program to run
322 * Return: 0 on success or negative error 380 * Return: 0 on success or negative error
323 * 381 *
324 * int bpf_clone_redirect(skb, ifindex, flags) 382 * int bpf_clone_redirect(skb, ifindex, flags)
@@ -368,9 +426,20 @@ union bpf_attr {
368 * int bpf_redirect(ifindex, flags) 426 * int bpf_redirect(ifindex, flags)
369 * redirect to another netdev 427 * redirect to another netdev
370 * @ifindex: ifindex of the net device 428 * @ifindex: ifindex of the net device
371 * @flags: bit 0 - if set, redirect to ingress instead of egress 429 * @flags:
372 * other bits - reserved 430 * cls_bpf:
373 * Return: TC_ACT_REDIRECT 431 * bit 0 - if set, redirect to ingress instead of egress
432 * other bits - reserved
433 * xdp_bpf:
434 * all bits - reserved
435 * Return: cls_bpf: TC_ACT_REDIRECT on success or TC_ACT_SHOT on error
436 * xdp_bfp: XDP_REDIRECT on success or XDP_ABORT on error
437 * int bpf_redirect_map(map, key, flags)
438 * redirect to endpoint in map
439 * @map: pointer to dev map
440 * @key: index in map to lookup
441 * @flags: --
442 * Return: XDP_REDIRECT on success or XDP_ABORT on error
374 * 443 *
375 * u32 bpf_get_route_realm(skb) 444 * u32 bpf_get_route_realm(skb)
376 * retrieve a dst's tclassid 445 * retrieve a dst's tclassid
@@ -548,12 +617,22 @@ union bpf_attr {
548 * int bpf_setsockopt(bpf_socket, level, optname, optval, optlen) 617 * int bpf_setsockopt(bpf_socket, level, optname, optval, optlen)
549 * Calls setsockopt. Not all opts are available, only those with 618 * Calls setsockopt. Not all opts are available, only those with
550 * integer optvals plus TCP_CONGESTION. 619 * integer optvals plus TCP_CONGESTION.
551 * Supported levels: SOL_SOCKET and IPROTO_TCP 620 * Supported levels: SOL_SOCKET and IPPROTO_TCP
621 * @bpf_socket: pointer to bpf_socket
622 * @level: SOL_SOCKET or IPPROTO_TCP
623 * @optname: option name
624 * @optval: pointer to option value
625 * @optlen: length of optval in bytes
626 * Return: 0 or negative error
627 *
628 * int bpf_getsockopt(bpf_socket, level, optname, optval, optlen)
629 * Calls getsockopt. Not all opts are available.
630 * Supported levels: IPPROTO_TCP
552 * @bpf_socket: pointer to bpf_socket 631 * @bpf_socket: pointer to bpf_socket
553 * @level: SOL_SOCKET or IPROTO_TCP 632 * @level: IPPROTO_TCP
554 * @optname: option name 633 * @optname: option name
555 * @optval: pointer to option value 634 * @optval: pointer to option value
556 * @optlen: length of optval in byes 635 * @optlen: length of optval in bytes
557 * Return: 0 or negative error 636 * Return: 0 or negative error
558 * 637 *
559 * int bpf_skb_adjust_room(skb, len_diff, mode, flags) 638 * int bpf_skb_adjust_room(skb, len_diff, mode, flags)
@@ -570,13 +649,34 @@ union bpf_attr {
570 * @map: pointer to sockmap 649 * @map: pointer to sockmap
571 * @key: key to lookup sock in map 650 * @key: key to lookup sock in map
572 * @flags: reserved for future use 651 * @flags: reserved for future use
573 * Return: SK_REDIRECT 652 * Return: SK_PASS
574 * 653 *
575 * int bpf_sock_map_update(skops, map, key, flags) 654 * int bpf_sock_map_update(skops, map, key, flags)
576 * @skops: pointer to bpf_sock_ops 655 * @skops: pointer to bpf_sock_ops
577 * @map: pointer to sockmap to update 656 * @map: pointer to sockmap to update
578 * @key: key to insert/update sock in map 657 * @key: key to insert/update sock in map
579 * @flags: same flags as map update elem 658 * @flags: same flags as map update elem
659 *
660 * int bpf_xdp_adjust_meta(xdp_md, delta)
661 * Adjust the xdp_md.data_meta by delta
662 * @xdp_md: pointer to xdp_md
663 * @delta: An positive/negative integer to be added to xdp_md.data_meta
664 * Return: 0 on success or negative on error
665 *
666 * int bpf_perf_event_read_value(map, flags, buf, buf_size)
667 * read perf event counter value and perf event enabled/running time
668 * @map: pointer to perf_event_array map
669 * @flags: index of event in the map or bitmask flags
670 * @buf: buf to fill
671 * @buf_size: size of the buf
672 * Return: 0 on success or negative error code
673 *
674 * int bpf_perf_prog_read_value(ctx, buf, buf_size)
675 * read perf prog attached perf event counter and enabled/running time
676 * @ctx: pointer to ctx
677 * @buf: buf to fill
678 * @buf_size: size of the buf
679 * Return : 0 on success or negative error code
580 */ 680 */
581#define __BPF_FUNC_MAPPER(FN) \ 681#define __BPF_FUNC_MAPPER(FN) \
582 FN(unspec), \ 682 FN(unspec), \
@@ -632,7 +732,11 @@ union bpf_attr {
632 FN(skb_adjust_room), \ 732 FN(skb_adjust_room), \
633 FN(redirect_map), \ 733 FN(redirect_map), \
634 FN(sk_redirect_map), \ 734 FN(sk_redirect_map), \
635 FN(sock_map_update), 735 FN(sock_map_update), \
736 FN(xdp_adjust_meta), \
737 FN(perf_event_read_value), \
738 FN(perf_prog_read_value), \
739 FN(getsockopt),
636 740
637/* integer value in 'imm' field of BPF_CALL instruction selects which helper 741/* integer value in 'imm' field of BPF_CALL instruction selects which helper
638 * function eBPF program intends to call 742 * function eBPF program intends to call
@@ -676,7 +780,9 @@ enum bpf_func_id {
676#define BPF_F_ZERO_CSUM_TX (1ULL << 1) 780#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
677#define BPF_F_DONT_FRAGMENT (1ULL << 2) 781#define BPF_F_DONT_FRAGMENT (1ULL << 2)
678 782
679/* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */ 783/* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
784 * BPF_FUNC_perf_event_read_value flags.
785 */
680#define BPF_F_INDEX_MASK 0xffffffffULL 786#define BPF_F_INDEX_MASK 0xffffffffULL
681#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK 787#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
682/* BPF_FUNC_perf_event_output for sk_buff input context. */ 788/* BPF_FUNC_perf_event_output for sk_buff input context. */
@@ -710,7 +816,7 @@ struct __sk_buff {
710 __u32 data_end; 816 __u32 data_end;
711 __u32 napi_id; 817 __u32 napi_id;
712 818
713 /* accessed by BPF_PROG_TYPE_sk_skb types */ 819 /* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
714 __u32 family; 820 __u32 family;
715 __u32 remote_ip4; /* Stored in network byte order */ 821 __u32 remote_ip4; /* Stored in network byte order */
716 __u32 local_ip4; /* Stored in network byte order */ 822 __u32 local_ip4; /* Stored in network byte order */
@@ -718,6 +824,9 @@ struct __sk_buff {
718 __u32 local_ip6[4]; /* Stored in network byte order */ 824 __u32 local_ip6[4]; /* Stored in network byte order */
719 __u32 remote_port; /* Stored in network byte order */ 825 __u32 remote_port; /* Stored in network byte order */
720 __u32 local_port; /* stored in host byte order */ 826 __u32 local_port; /* stored in host byte order */
827 /* ... here. */
828
829 __u32 data_meta;
721}; 830};
722 831
723struct bpf_tunnel_key { 832struct bpf_tunnel_key {
@@ -753,20 +862,23 @@ struct bpf_sock {
753 __u32 family; 862 __u32 family;
754 __u32 type; 863 __u32 type;
755 __u32 protocol; 864 __u32 protocol;
865 __u32 mark;
866 __u32 priority;
756}; 867};
757 868
758#define XDP_PACKET_HEADROOM 256 869#define XDP_PACKET_HEADROOM 256
759 870
760/* User return codes for XDP prog type. 871/* User return codes for XDP prog type.
761 * A valid XDP program must return one of these defined values. All other 872 * A valid XDP program must return one of these defined values. All other
762 * return codes are reserved for future use. Unknown return codes will result 873 * return codes are reserved for future use. Unknown return codes will
763 * in packet drop. 874 * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
764 */ 875 */
765enum xdp_action { 876enum xdp_action {
766 XDP_ABORTED = 0, 877 XDP_ABORTED = 0,
767 XDP_DROP, 878 XDP_DROP,
768 XDP_PASS, 879 XDP_PASS,
769 XDP_TX, 880 XDP_TX,
881 XDP_REDIRECT,
770}; 882};
771 883
772/* user accessible metadata for XDP packet hook 884/* user accessible metadata for XDP packet hook
@@ -775,12 +887,12 @@ enum xdp_action {
775struct xdp_md { 887struct xdp_md {
776 __u32 data; 888 __u32 data;
777 __u32 data_end; 889 __u32 data_end;
890 __u32 data_meta;
778}; 891};
779 892
780enum sk_action { 893enum sk_action {
781 SK_ABORTED = 0, 894 SK_DROP = 0,
782 SK_DROP, 895 SK_PASS,
783 SK_REDIRECT,
784}; 896};
785 897
786#define BPF_TAG_SIZE 8 898#define BPF_TAG_SIZE 8
@@ -793,6 +905,11 @@ struct bpf_prog_info {
793 __u32 xlated_prog_len; 905 __u32 xlated_prog_len;
794 __aligned_u64 jited_prog_insns; 906 __aligned_u64 jited_prog_insns;
795 __aligned_u64 xlated_prog_insns; 907 __aligned_u64 xlated_prog_insns;
908 __u64 load_time; /* ns since boottime */
909 __u32 created_by_uid;
910 __u32 nr_map_ids;
911 __aligned_u64 map_ids;
912 char name[BPF_OBJ_NAME_LEN];
796} __attribute__((aligned(8))); 913} __attribute__((aligned(8)));
797 914
798struct bpf_map_info { 915struct bpf_map_info {
@@ -802,6 +919,7 @@ struct bpf_map_info {
802 __u32 value_size; 919 __u32 value_size;
803 __u32 max_entries; 920 __u32 max_entries;
804 __u32 map_flags; 921 __u32 map_flags;
922 char name[BPF_OBJ_NAME_LEN];
805} __attribute__((aligned(8))); 923} __attribute__((aligned(8)));
806 924
807/* User bpf_sock_ops struct to access socket values and specify request ops 925/* User bpf_sock_ops struct to access socket values and specify request ops
@@ -851,9 +969,35 @@ enum {
851 BPF_SOCK_OPS_NEEDS_ECN, /* If connection's congestion control 969 BPF_SOCK_OPS_NEEDS_ECN, /* If connection's congestion control
852 * needs ECN 970 * needs ECN
853 */ 971 */
972 BPF_SOCK_OPS_BASE_RTT, /* Get base RTT. The correct value is
973 * based on the path and may be
974 * dependent on the congestion control
975 * algorithm. In general it indicates
976 * a congestion threshold. RTTs above
977 * this indicate congestion
978 */
854}; 979};
855 980
856#define TCP_BPF_IW 1001 /* Set TCP initial congestion window */ 981#define TCP_BPF_IW 1001 /* Set TCP initial congestion window */
857#define TCP_BPF_SNDCWND_CLAMP 1002 /* Set sndcwnd_clamp */ 982#define TCP_BPF_SNDCWND_CLAMP 1002 /* Set sndcwnd_clamp */
858 983
984struct bpf_perf_event_value {
985 __u64 counter;
986 __u64 enabled;
987 __u64 running;
988};
989
990#define BPF_DEVCG_ACC_MKNOD (1ULL << 0)
991#define BPF_DEVCG_ACC_READ (1ULL << 1)
992#define BPF_DEVCG_ACC_WRITE (1ULL << 2)
993
994#define BPF_DEVCG_DEV_BLOCK (1ULL << 0)
995#define BPF_DEVCG_DEV_CHAR (1ULL << 1)
996
997struct bpf_cgroup_dev_ctx {
998 __u32 access_type; /* (access << 16) | type */
999 __u32 major;
1000 __u32 minor;
1001};
1002
859#endif /* _UAPI__LINUX_BPF_H__ */ 1003#endif /* _UAPI__LINUX_BPF_H__ */
diff --git a/tools/include/uapi/linux/bpf_common.h b/tools/include/uapi/linux/bpf_common.h
index a5c220e0828f..18be90725ab0 100644
--- a/tools/include/uapi/linux/bpf_common.h
+++ b/tools/include/uapi/linux/bpf_common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI__LINUX_BPF_COMMON_H__ 2#ifndef _UAPI__LINUX_BPF_COMMON_H__
2#define _UAPI__LINUX_BPF_COMMON_H__ 3#define _UAPI__LINUX_BPF_COMMON_H__
3 4
diff --git a/tools/include/uapi/linux/fcntl.h b/tools/include/uapi/linux/fcntl.h
index ec69d55bcec7..6448cdd9a350 100644
--- a/tools/include/uapi/linux/fcntl.h
+++ b/tools/include/uapi/linux/fcntl.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_LINUX_FCNTL_H 2#ifndef _UAPI_LINUX_FCNTL_H
2#define _UAPI_LINUX_FCNTL_H 3#define _UAPI_LINUX_FCNTL_H
3 4
diff --git a/tools/include/uapi/linux/hw_breakpoint.h b/tools/include/uapi/linux/hw_breakpoint.h
index 2b65efd19a46..965e4d8606d8 100644
--- a/tools/include/uapi/linux/hw_breakpoint.h
+++ b/tools/include/uapi/linux/hw_breakpoint.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_LINUX_HW_BREAKPOINT_H 2#ifndef _UAPI_LINUX_HW_BREAKPOINT_H
2#define _UAPI_LINUX_HW_BREAKPOINT_H 3#define _UAPI_LINUX_HW_BREAKPOINT_H
3 4
diff --git a/tools/include/uapi/linux/kcmp.h b/tools/include/uapi/linux/kcmp.h
new file mode 100644
index 000000000000..481e103da78e
--- /dev/null
+++ b/tools/include/uapi/linux/kcmp.h
@@ -0,0 +1,27 @@
1#ifndef _UAPI_LINUX_KCMP_H
2#define _UAPI_LINUX_KCMP_H
3
4#include <linux/types.h>
5
6/* Comparison type */
7enum kcmp_type {
8 KCMP_FILE,
9 KCMP_VM,
10 KCMP_FILES,
11 KCMP_FS,
12 KCMP_SIGHAND,
13 KCMP_IO,
14 KCMP_SYSVSEM,
15 KCMP_EPOLL_TFD,
16
17 KCMP_TYPES,
18};
19
20/* Slot for KCMP_EPOLL_TFD */
21struct kcmp_epoll_slot {
22 __u32 efd; /* epoll file descriptor */
23 __u32 tfd; /* target file number */
24 __u32 toff; /* target offset within same numbered sequence */
25};
26
27#endif /* _UAPI_LINUX_KCMP_H */
diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h
index 6cd63c18708a..7e99999d6236 100644
--- a/tools/include/uapi/linux/kvm.h
+++ b/tools/include/uapi/linux/kvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef __LINUX_KVM_H 2#ifndef __LINUX_KVM_H
2#define __LINUX_KVM_H 3#define __LINUX_KVM_H
3 4
@@ -711,7 +712,8 @@ struct kvm_ppc_one_seg_page_size {
711struct kvm_ppc_smmu_info { 712struct kvm_ppc_smmu_info {
712 __u64 flags; 713 __u64 flags;
713 __u32 slb_size; 714 __u32 slb_size;
714 __u32 pad; 715 __u16 data_keys; /* # storage keys supported for data */
716 __u16 instr_keys; /* # storage keys supported for instructions */
715 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ]; 717 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
716}; 718};
717 719
diff --git a/tools/include/uapi/linux/mman.h b/tools/include/uapi/linux/mman.h
index 81d8edf11789..bfd5938fede6 100644
--- a/tools/include/uapi/linux/mman.h
+++ b/tools/include/uapi/linux/mman.h
@@ -1,7 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_LINUX_MMAN_H 2#ifndef _UAPI_LINUX_MMAN_H
2#define _UAPI_LINUX_MMAN_H 3#define _UAPI_LINUX_MMAN_H
3 4
4#include <uapi/asm/mman.h> 5#include <asm/mman.h>
6#include <asm-generic/hugetlb_encode.h>
5 7
6#define MREMAP_MAYMOVE 1 8#define MREMAP_MAYMOVE 1
7#define MREMAP_FIXED 2 9#define MREMAP_FIXED 2
@@ -10,4 +12,25 @@
10#define OVERCOMMIT_ALWAYS 1 12#define OVERCOMMIT_ALWAYS 1
11#define OVERCOMMIT_NEVER 2 13#define OVERCOMMIT_NEVER 2
12 14
15/*
16 * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
17 * size other than the default is desired. See hugetlb_encode.h.
18 * All known huge page size encodings are provided here. It is the
19 * responsibility of the application to know which sizes are supported on
20 * the running system. See mmap(2) man page for details.
21 */
22#define MAP_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
23#define MAP_HUGE_MASK HUGETLB_FLAG_ENCODE_MASK
24
25#define MAP_HUGE_64KB HUGETLB_FLAG_ENCODE_64KB
26#define MAP_HUGE_512KB HUGETLB_FLAG_ENCODE_512KB
27#define MAP_HUGE_1MB HUGETLB_FLAG_ENCODE_1MB
28#define MAP_HUGE_2MB HUGETLB_FLAG_ENCODE_2MB
29#define MAP_HUGE_8MB HUGETLB_FLAG_ENCODE_8MB
30#define MAP_HUGE_16MB HUGETLB_FLAG_ENCODE_16MB
31#define MAP_HUGE_256MB HUGETLB_FLAG_ENCODE_256MB
32#define MAP_HUGE_1GB HUGETLB_FLAG_ENCODE_1GB
33#define MAP_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB
34#define MAP_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB
35
13#endif /* _UAPI_LINUX_MMAN_H */ 36#endif /* _UAPI_LINUX_MMAN_H */
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 140ae638cfd6..362493a2f950 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1/* 2/*
2 * Performance events: 3 * Performance events:
3 * 4 *
diff --git a/tools/include/uapi/linux/prctl.h b/tools/include/uapi/linux/prctl.h
new file mode 100644
index 000000000000..a8d0759a9e40
--- /dev/null
+++ b/tools/include/uapi/linux/prctl.h
@@ -0,0 +1,200 @@
1#ifndef _LINUX_PRCTL_H
2#define _LINUX_PRCTL_H
3
4#include <linux/types.h>
5
6/* Values to pass as first argument to prctl() */
7
8#define PR_SET_PDEATHSIG 1 /* Second arg is a signal */
9#define PR_GET_PDEATHSIG 2 /* Second arg is a ptr to return the signal */
10
11/* Get/set current->mm->dumpable */
12#define PR_GET_DUMPABLE 3
13#define PR_SET_DUMPABLE 4
14
15/* Get/set unaligned access control bits (if meaningful) */
16#define PR_GET_UNALIGN 5
17#define PR_SET_UNALIGN 6
18# define PR_UNALIGN_NOPRINT 1 /* silently fix up unaligned user accesses */
19# define PR_UNALIGN_SIGBUS 2 /* generate SIGBUS on unaligned user access */
20
21/* Get/set whether or not to drop capabilities on setuid() away from
22 * uid 0 (as per security/commoncap.c) */
23#define PR_GET_KEEPCAPS 7
24#define PR_SET_KEEPCAPS 8
25
26/* Get/set floating-point emulation control bits (if meaningful) */
27#define PR_GET_FPEMU 9
28#define PR_SET_FPEMU 10
29# define PR_FPEMU_NOPRINT 1 /* silently emulate fp operations accesses */
30# define PR_FPEMU_SIGFPE 2 /* don't emulate fp operations, send SIGFPE instead */
31
32/* Get/set floating-point exception mode (if meaningful) */
33#define PR_GET_FPEXC 11
34#define PR_SET_FPEXC 12
35# define PR_FP_EXC_SW_ENABLE 0x80 /* Use FPEXC for FP exception enables */
36# define PR_FP_EXC_DIV 0x010000 /* floating point divide by zero */
37# define PR_FP_EXC_OVF 0x020000 /* floating point overflow */
38# define PR_FP_EXC_UND 0x040000 /* floating point underflow */
39# define PR_FP_EXC_RES 0x080000 /* floating point inexact result */
40# define PR_FP_EXC_INV 0x100000 /* floating point invalid operation */
41# define PR_FP_EXC_DISABLED 0 /* FP exceptions disabled */
42# define PR_FP_EXC_NONRECOV 1 /* async non-recoverable exc. mode */
43# define PR_FP_EXC_ASYNC 2 /* async recoverable exception mode */
44# define PR_FP_EXC_PRECISE 3 /* precise exception mode */
45
46/* Get/set whether we use statistical process timing or accurate timestamp
47 * based process timing */
48#define PR_GET_TIMING 13
49#define PR_SET_TIMING 14
50# define PR_TIMING_STATISTICAL 0 /* Normal, traditional,
51 statistical process timing */
52# define PR_TIMING_TIMESTAMP 1 /* Accurate timestamp based
53 process timing */
54
55#define PR_SET_NAME 15 /* Set process name */
56#define PR_GET_NAME 16 /* Get process name */
57
58/* Get/set process endian */
59#define PR_GET_ENDIAN 19
60#define PR_SET_ENDIAN 20
61# define PR_ENDIAN_BIG 0
62# define PR_ENDIAN_LITTLE 1 /* True little endian mode */
63# define PR_ENDIAN_PPC_LITTLE 2 /* "PowerPC" pseudo little endian */
64
65/* Get/set process seccomp mode */
66#define PR_GET_SECCOMP 21
67#define PR_SET_SECCOMP 22
68
69/* Get/set the capability bounding set (as per security/commoncap.c) */
70#define PR_CAPBSET_READ 23
71#define PR_CAPBSET_DROP 24
72
73/* Get/set the process' ability to use the timestamp counter instruction */
74#define PR_GET_TSC 25
75#define PR_SET_TSC 26
76# define PR_TSC_ENABLE 1 /* allow the use of the timestamp counter */
77# define PR_TSC_SIGSEGV 2 /* throw a SIGSEGV instead of reading the TSC */
78
79/* Get/set securebits (as per security/commoncap.c) */
80#define PR_GET_SECUREBITS 27
81#define PR_SET_SECUREBITS 28
82
83/*
84 * Get/set the timerslack as used by poll/select/nanosleep
85 * A value of 0 means "use default"
86 */
87#define PR_SET_TIMERSLACK 29
88#define PR_GET_TIMERSLACK 30
89
90#define PR_TASK_PERF_EVENTS_DISABLE 31
91#define PR_TASK_PERF_EVENTS_ENABLE 32
92
93/*
94 * Set early/late kill mode for hwpoison memory corruption.
95 * This influences when the process gets killed on a memory corruption.
96 */
97#define PR_MCE_KILL 33
98# define PR_MCE_KILL_CLEAR 0
99# define PR_MCE_KILL_SET 1
100
101# define PR_MCE_KILL_LATE 0
102# define PR_MCE_KILL_EARLY 1
103# define PR_MCE_KILL_DEFAULT 2
104
105#define PR_MCE_KILL_GET 34
106
107/*
108 * Tune up process memory map specifics.
109 */
110#define PR_SET_MM 35
111# define PR_SET_MM_START_CODE 1
112# define PR_SET_MM_END_CODE 2
113# define PR_SET_MM_START_DATA 3
114# define PR_SET_MM_END_DATA 4
115# define PR_SET_MM_START_STACK 5
116# define PR_SET_MM_START_BRK 6
117# define PR_SET_MM_BRK 7
118# define PR_SET_MM_ARG_START 8
119# define PR_SET_MM_ARG_END 9
120# define PR_SET_MM_ENV_START 10
121# define PR_SET_MM_ENV_END 11
122# define PR_SET_MM_AUXV 12
123# define PR_SET_MM_EXE_FILE 13
124# define PR_SET_MM_MAP 14
125# define PR_SET_MM_MAP_SIZE 15
126
127/*
128 * This structure provides new memory descriptor
129 * map which mostly modifies /proc/pid/stat[m]
130 * output for a task. This mostly done in a
131 * sake of checkpoint/restore functionality.
132 */
133struct prctl_mm_map {
134 __u64 start_code; /* code section bounds */
135 __u64 end_code;
136 __u64 start_data; /* data section bounds */
137 __u64 end_data;
138 __u64 start_brk; /* heap for brk() syscall */
139 __u64 brk;
140 __u64 start_stack; /* stack starts at */
141 __u64 arg_start; /* command line arguments bounds */
142 __u64 arg_end;
143 __u64 env_start; /* environment variables bounds */
144 __u64 env_end;
145 __u64 *auxv; /* auxiliary vector */
146 __u32 auxv_size; /* vector size */
147 __u32 exe_fd; /* /proc/$pid/exe link file */
148};
149
150/*
151 * Set specific pid that is allowed to ptrace the current task.
152 * A value of 0 mean "no process".
153 */
154#define PR_SET_PTRACER 0x59616d61
155# define PR_SET_PTRACER_ANY ((unsigned long)-1)
156
157#define PR_SET_CHILD_SUBREAPER 36
158#define PR_GET_CHILD_SUBREAPER 37
159
160/*
161 * If no_new_privs is set, then operations that grant new privileges (i.e.
162 * execve) will either fail or not grant them. This affects suid/sgid,
163 * file capabilities, and LSMs.
164 *
165 * Operations that merely manipulate or drop existing privileges (setresuid,
166 * capset, etc.) will still work. Drop those privileges if you want them gone.
167 *
168 * Changing LSM security domain is considered a new privilege. So, for example,
169 * asking selinux for a specific new context (e.g. with runcon) will result
170 * in execve returning -EPERM.
171 *
172 * See Documentation/prctl/no_new_privs.txt for more details.
173 */
174#define PR_SET_NO_NEW_PRIVS 38
175#define PR_GET_NO_NEW_PRIVS 39
176
177#define PR_GET_TID_ADDRESS 40
178
179#define PR_SET_THP_DISABLE 41
180#define PR_GET_THP_DISABLE 42
181
182/*
183 * Tell the kernel to start/stop helping userspace manage bounds tables.
184 */
185#define PR_MPX_ENABLE_MANAGEMENT 43
186#define PR_MPX_DISABLE_MANAGEMENT 44
187
188#define PR_SET_FP_MODE 45
189#define PR_GET_FP_MODE 46
190# define PR_FP_MODE_FR (1 << 0) /* 64b FP registers */
191# define PR_FP_MODE_FRE (1 << 1) /* 32b compatibility */
192
193/* Control the ambient capability set */
194#define PR_CAP_AMBIENT 47
195# define PR_CAP_AMBIENT_IS_SET 1
196# define PR_CAP_AMBIENT_RAISE 2
197# define PR_CAP_AMBIENT_LOWER 3
198# define PR_CAP_AMBIENT_CLEAR_ALL 4
199
200#endif /* _LINUX_PRCTL_H */
diff --git a/tools/include/uapi/linux/sched.h b/tools/include/uapi/linux/sched.h
index e2a6c7b3510b..30a9e51bbb1e 100644
--- a/tools/include/uapi/linux/sched.h
+++ b/tools/include/uapi/linux/sched.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_LINUX_SCHED_H 2#ifndef _UAPI_LINUX_SCHED_H
2#define _UAPI_LINUX_SCHED_H 3#define _UAPI_LINUX_SCHED_H
3 4
diff --git a/tools/include/uapi/linux/stat.h b/tools/include/uapi/linux/stat.h
index 17b10304c393..7b35e98d3c58 100644
--- a/tools/include/uapi/linux/stat.h
+++ b/tools/include/uapi/linux/stat.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _UAPI_LINUX_STAT_H 2#ifndef _UAPI_LINUX_STAT_H
2#define _UAPI_LINUX_STAT_H 3#define _UAPI_LINUX_STAT_H
3 4
diff --git a/tools/include/uapi/linux/vhost.h b/tools/include/uapi/linux/vhost.h
index 60180c0b5dc6..c51f8e5cc608 100644
--- a/tools/include/uapi/linux/vhost.h
+++ b/tools/include/uapi/linux/vhost.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
1#ifndef _LINUX_VHOST_H 2#ifndef _LINUX_VHOST_H
2#define _LINUX_VHOST_H 3#define _LINUX_VHOST_H
3/* Userspace interface for in-kernel virtio accelerators. */ 4/* Userspace interface for in-kernel virtio accelerators. */
diff --git a/tools/include/uapi/sound/asound.h b/tools/include/uapi/sound/asound.h
index 87bf30b182df..c227ccba60ae 100644
--- a/tools/include/uapi/sound/asound.h
+++ b/tools/include/uapi/sound/asound.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
1/* 2/*
2 * Advanced Linux Sound Architecture - ALSA - Driver 3 * Advanced Linux Sound Architecture - ALSA - Driver
3 * Copyright (c) 1994-2003 by Jaroslav Kysela <perex@perex.cz>, 4 * Copyright (c) 1994-2003 by Jaroslav Kysela <perex@perex.cz>,
diff --git a/tools/kvm/kvm_stat/Makefile b/tools/kvm/kvm_stat/Makefile
index 5b1cba57e3b3..c3e36c60d477 100644
--- a/tools/kvm/kvm_stat/Makefile
+++ b/tools/kvm/kvm_stat/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1include ../../scripts/Makefile.include 2include ../../scripts/Makefile.include
2include ../../scripts/utilities.mak 3include ../../scripts/utilities.mak
3BINDIR=usr/bin 4BINDIR=usr/bin
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 32283d88701a..217cf6f95c36 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -19,9 +19,11 @@ Three different ways of output formatting are available:
19 19
20The data is sampled from the KVM's debugfs entries and its perf events. 20The data is sampled from the KVM's debugfs entries and its perf events.
21""" 21"""
22from __future__ import print_function
22 23
23import curses 24import curses
24import sys 25import sys
26import locale
25import os 27import os
26import time 28import time
27import optparse 29import optparse
@@ -225,6 +227,8 @@ IOCTL_NUMBERS = {
225 'RESET': 0x00002403, 227 'RESET': 0x00002403,
226} 228}
227 229
230ENCODING = locale.getpreferredencoding(False)
231
228 232
229class Arch(object): 233class Arch(object):
230 """Encapsulates global architecture specific data. 234 """Encapsulates global architecture specific data.
@@ -666,7 +670,7 @@ class TracepointProvider(Provider):
666 """Returns 'event name: current value' for all enabled events.""" 670 """Returns 'event name: current value' for all enabled events."""
667 ret = defaultdict(int) 671 ret = defaultdict(int)
668 for group in self.group_leaders: 672 for group in self.group_leaders:
669 for name, val in group.read().iteritems(): 673 for name, val in group.read().items():
670 if name in self._fields: 674 if name in self._fields:
671 ret[name] += val 675 ret[name] += val
672 return ret 676 return ret
@@ -955,7 +959,7 @@ class Tui(object):
955 except: 959 except:
956 raise Exception 960 raise Exception
957 for line in child.stdout: 961 for line in child.stdout:
958 line = line.lstrip().split(' ', 1) 962 line = line.decode(ENCODING).lstrip().split(' ', 1)
959 # perform a sanity check before calling the more expensive 963 # perform a sanity check before calling the more expensive
960 # function to possibly extract the guest name 964 # function to possibly extract the guest name
961 if ' -name ' in line[1]: 965 if ' -name ' in line[1]:
@@ -1005,7 +1009,7 @@ class Tui(object):
1005 name = '' 1009 name = ''
1006 try: 1010 try:
1007 line = open('/proc/{}/cmdline' 1011 line = open('/proc/{}/cmdline'
1008 .format(pid), 'rb').read().split('\0') 1012 .format(pid), 'r').read().split('\0')
1009 parms = line[line.index('-name') + 1].split(',') 1013 parms = line[line.index('-name') + 1].split(',')
1010 while '' in parms: 1014 while '' in parms:
1011 # commas are escaped (i.e. ',,'), hence e.g. 'foo,bar' results 1015 # commas are escaped (i.e. ',,'), hence e.g. 'foo,bar' results
@@ -1170,7 +1174,7 @@ class Tui(object):
1170 .format(self.stats.fields_filter)) 1174 .format(self.stats.fields_filter))
1171 self.screen.addstr(3, 0, "New regex: ") 1175 self.screen.addstr(3, 0, "New regex: ")
1172 curses.echo() 1176 curses.echo()
1173 regex = self.screen.getstr() 1177 regex = self.screen.getstr().decode(ENCODING)
1174 curses.noecho() 1178 curses.noecho()
1175 if len(regex) == 0: 1179 if len(regex) == 0:
1176 self.stats.fields_filter = DEFAULT_REGEX 1180 self.stats.fields_filter = DEFAULT_REGEX
@@ -1204,7 +1208,7 @@ class Tui(object):
1204 1208
1205 curses.echo() 1209 curses.echo()
1206 self.screen.addstr(3, 0, "Pid [0 or pid]: ") 1210 self.screen.addstr(3, 0, "Pid [0 or pid]: ")
1207 pid = self.screen.getstr() 1211 pid = self.screen.getstr().decode(ENCODING)
1208 curses.noecho() 1212 curses.noecho()
1209 1213
1210 try: 1214 try:
@@ -1233,7 +1237,7 @@ class Tui(object):
1233 self.screen.addstr(2, 0, 'Change delay from %.1fs to ' % 1237 self.screen.addstr(2, 0, 'Change delay from %.1fs to ' %
1234 self._delay_regular) 1238 self._delay_regular)
1235 curses.echo() 1239 curses.echo()
1236 val = self.screen.getstr() 1240 val = self.screen.getstr().decode(ENCODING)
1237 curses.noecho() 1241 curses.noecho()
1238 1242
1239 try: 1243 try:
@@ -1273,7 +1277,7 @@ class Tui(object):
1273 self.print_all_gnames(7) 1277 self.print_all_gnames(7)
1274 curses.echo() 1278 curses.echo()
1275 self.screen.addstr(3, 0, "Guest [ENTER or guest]: ") 1279 self.screen.addstr(3, 0, "Guest [ENTER or guest]: ")
1276 gname = self.screen.getstr() 1280 gname = self.screen.getstr().decode(ENCODING)
1277 curses.noecho() 1281 curses.noecho()
1278 1282
1279 if not gname: 1283 if not gname:
@@ -1369,25 +1373,25 @@ def batch(stats):
1369 s = stats.get() 1373 s = stats.get()
1370 for key in sorted(s.keys()): 1374 for key in sorted(s.keys()):
1371 values = s[key] 1375 values = s[key]
1372 print '%-42s%10d%10d' % (key, values[0], values[1]) 1376 print('%-42s%10d%10d' % (key, values[0], values[1]))
1373 except KeyboardInterrupt: 1377 except KeyboardInterrupt:
1374 pass 1378 pass
1375 1379
1376 1380
1377def log(stats): 1381def log(stats):
1378 """Prints statistics as reiterating key block, multiple value blocks.""" 1382 """Prints statistics as reiterating key block, multiple value blocks."""
1379 keys = sorted(stats.get().iterkeys()) 1383 keys = sorted(stats.get().keys())
1380 1384
1381 def banner(): 1385 def banner():
1382 for k in keys: 1386 for k in keys:
1383 print '%s' % k, 1387 print(k, end=' ')
1384 print 1388 print()
1385 1389
1386 def statline(): 1390 def statline():
1387 s = stats.get() 1391 s = stats.get()
1388 for k in keys: 1392 for k in keys:
1389 print ' %9d' % s[k][1], 1393 print(' %9d' % s[k][1], end=' ')
1390 print 1394 print()
1391 line = 0 1395 line = 0
1392 banner_repeat = 20 1396 banner_repeat = 20
1393 while True: 1397 while True:
diff --git a/tools/laptop/dslm/Makefile b/tools/laptop/dslm/Makefile
index ff613b31730b..90f512c4e2bb 100644
--- a/tools/laptop/dslm/Makefile
+++ b/tools/laptop/dslm/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CC := $(CROSS_COMPILE)gcc 2CC := $(CROSS_COMPILE)gcc
2CFLAGS := -I../../usr/include 3CFLAGS := -I../../usr/include
3 4
diff --git a/tools/laptop/freefall/Makefile b/tools/laptop/freefall/Makefile
index 48c6c9328419..5f758c489a20 100644
--- a/tools/laptop/freefall/Makefile
+++ b/tools/laptop/freefall/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1PREFIX ?= /usr 2PREFIX ?= /usr
2SBINDIR ?= sbin 3SBINDIR ?= sbin
3INSTALL ?= install 4INSTALL ?= install
diff --git a/tools/leds/Makefile b/tools/leds/Makefile
index 078b666fd78b..c379af003807 100644
--- a/tools/leds/Makefile
+++ b/tools/leds/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for LEDs tools 2# Makefile for LEDs tools
2 3
3CC = $(CROSS_COMPILE)gcc 4CC = $(CROSS_COMPILE)gcc
diff --git a/tools/leds/led_hw_brightness_mon.c b/tools/leds/led_hw_brightness_mon.c
index 64642ccfe442..eb65ae988839 100644
--- a/tools/leds/led_hw_brightness_mon.c
+++ b/tools/leds/led_hw_brightness_mon.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * led_hw_brightness_mon.c 3 * led_hw_brightness_mon.c
3 * 4 *
diff --git a/tools/leds/uledmon.c b/tools/leds/uledmon.c
index 25cbc7acf50a..c15a39c1f271 100644
--- a/tools/leds/uledmon.c
+++ b/tools/leds/uledmon.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * uledmon.c 3 * uledmon.c
3 * 4 *
diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index 1e83e3c07448..a13e9c7f1fc5 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1include ../../scripts/Makefile.include 2include ../../scripts/Makefile.include
2include ../../scripts/utilities.mak # QUIET_CLEAN 3include ../../scripts/utilities.mak # QUIET_CLEAN
3 4
diff --git a/tools/lib/api/cpu.c b/tools/lib/api/cpu.c
index 8c6489356e3a..4af6d4b7aa07 100644
--- a/tools/lib/api/cpu.c
+++ b/tools/lib/api/cpu.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2 3
3#include "cpu.h" 4#include "cpu.h"
diff --git a/tools/lib/api/cpu.h b/tools/lib/api/cpu.h
index 81e9d3955961..90a102fb20de 100644
--- a/tools/lib/api/cpu.h
+++ b/tools/lib/api/cpu.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __API_CPU__ 2#ifndef __API_CPU__
2#define __API_CPU__ 3#define __API_CPU__
3 4
diff --git a/tools/lib/api/debug-internal.h b/tools/lib/api/debug-internal.h
index 188f7880eafe..80c783497d25 100644
--- a/tools/lib/api/debug-internal.h
+++ b/tools/lib/api/debug-internal.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __API_DEBUG_INTERNAL_H__ 2#ifndef __API_DEBUG_INTERNAL_H__
2#define __API_DEBUG_INTERNAL_H__ 3#define __API_DEBUG_INTERNAL_H__
3 4
diff --git a/tools/lib/api/debug.c b/tools/lib/api/debug.c
index 5fa5cf500a1f..69b1ba3d1ee3 100644
--- a/tools/lib/api/debug.c
+++ b/tools/lib/api/debug.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdarg.h> 3#include <stdarg.h>
3#include "debug.h" 4#include "debug.h"
diff --git a/tools/lib/api/debug.h b/tools/lib/api/debug.h
index a0872f68fc56..3684dd6e0c02 100644
--- a/tools/lib/api/debug.h
+++ b/tools/lib/api/debug.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __API_DEBUG_H__ 2#ifndef __API_DEBUG_H__
2#define __API_DEBUG_H__ 3#define __API_DEBUG_H__
3 4
diff --git a/tools/lib/api/fd/array.h b/tools/lib/api/fd/array.h
index 71287dddc05f..b39557d1a88f 100644
--- a/tools/lib/api/fd/array.h
+++ b/tools/lib/api/fd/array.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __API_FD_ARRAY__ 2#ifndef __API_FD_ARRAY__
2#define __API_FD_ARRAY__ 3#define __API_FD_ARRAY__
3 4
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index a7ecf8f469f4..b24afc0e6e81 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <ctype.h> 2#include <ctype.h>
2#include <errno.h> 3#include <errno.h>
3#include <limits.h> 4#include <limits.h>
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h
index 45605348461e..dda49deefb52 100644
--- a/tools/lib/api/fs/fs.h
+++ b/tools/lib/api/fs/fs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __API_FS__ 2#ifndef __API_FS__
2#define __API_FS__ 3#define __API_FS__
3 4
diff --git a/tools/lib/api/fs/tracing_path.c b/tools/lib/api/fs/tracing_path.c
index 3e606b9c443e..7b7fd0b18551 100644
--- a/tools/lib/api/fs/tracing_path.c
+++ b/tools/lib/api/fs/tracing_path.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#ifndef _GNU_SOURCE 2#ifndef _GNU_SOURCE
2# define _GNU_SOURCE 3# define _GNU_SOURCE
3#endif 4#endif
diff --git a/tools/lib/api/fs/tracing_path.h b/tools/lib/api/fs/tracing_path.h
index 3f233ac70b6f..0066f06cc381 100644
--- a/tools/lib/api/fs/tracing_path.h
+++ b/tools/lib/api/fs/tracing_path.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __API_FS_TRACING_PATH_H 2#ifndef __API_FS_TRACING_PATH_H
2#define __API_FS_TRACING_PATH_H 3#define __API_FS_TRACING_PATH_H
3 4
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index d2441db34740..4555304dc18e 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Most of this file is copied from tools/lib/traceevent/Makefile 2# Most of this file is copied from tools/lib/traceevent/Makefile
2 3
3BPF_VERSION = 0 4BPF_VERSION = 0
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 1d6907d379c9..5128677e4117 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -46,6 +46,8 @@
46# endif 46# endif
47#endif 47#endif
48 48
49#define min(x, y) ((x) < (y) ? (x) : (y))
50
49static inline __u64 ptr_to_u64(const void *ptr) 51static inline __u64 ptr_to_u64(const void *ptr)
50{ 52{
51 return (__u64) (unsigned long) ptr; 53 return (__u64) (unsigned long) ptr;
@@ -57,10 +59,11 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
57 return syscall(__NR_bpf, cmd, attr, size); 59 return syscall(__NR_bpf, cmd, attr, size);
58} 60}
59 61
60int bpf_create_map_node(enum bpf_map_type map_type, int key_size, 62int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
61 int value_size, int max_entries, __u32 map_flags, 63 int key_size, int value_size, int max_entries,
62 int node) 64 __u32 map_flags, int node)
63{ 65{
66 __u32 name_len = name ? strlen(name) : 0;
64 union bpf_attr attr; 67 union bpf_attr attr;
65 68
66 memset(&attr, '\0', sizeof(attr)); 69 memset(&attr, '\0', sizeof(attr));
@@ -70,6 +73,8 @@ int bpf_create_map_node(enum bpf_map_type map_type, int key_size,
70 attr.value_size = value_size; 73 attr.value_size = value_size;
71 attr.max_entries = max_entries; 74 attr.max_entries = max_entries;
72 attr.map_flags = map_flags; 75 attr.map_flags = map_flags;
76 memcpy(attr.map_name, name, min(name_len, BPF_OBJ_NAME_LEN - 1));
77
73 if (node >= 0) { 78 if (node >= 0) {
74 attr.map_flags |= BPF_F_NUMA_NODE; 79 attr.map_flags |= BPF_F_NUMA_NODE;
75 attr.numa_node = node; 80 attr.numa_node = node;
@@ -81,14 +86,23 @@ int bpf_create_map_node(enum bpf_map_type map_type, int key_size,
81int bpf_create_map(enum bpf_map_type map_type, int key_size, 86int bpf_create_map(enum bpf_map_type map_type, int key_size,
82 int value_size, int max_entries, __u32 map_flags) 87 int value_size, int max_entries, __u32 map_flags)
83{ 88{
84 return bpf_create_map_node(map_type, key_size, value_size, 89 return bpf_create_map_node(map_type, NULL, key_size, value_size,
85 max_entries, map_flags, -1); 90 max_entries, map_flags, -1);
86} 91}
87 92
88int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size, 93int bpf_create_map_name(enum bpf_map_type map_type, const char *name,
89 int inner_map_fd, int max_entries, 94 int key_size, int value_size, int max_entries,
95 __u32 map_flags)
96{
97 return bpf_create_map_node(map_type, name, key_size, value_size,
98 max_entries, map_flags, -1);
99}
100
101int bpf_create_map_in_map_node(enum bpf_map_type map_type, const char *name,
102 int key_size, int inner_map_fd, int max_entries,
90 __u32 map_flags, int node) 103 __u32 map_flags, int node)
91{ 104{
105 __u32 name_len = name ? strlen(name) : 0;
92 union bpf_attr attr; 106 union bpf_attr attr;
93 107
94 memset(&attr, '\0', sizeof(attr)); 108 memset(&attr, '\0', sizeof(attr));
@@ -99,6 +113,8 @@ int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size,
99 attr.inner_map_fd = inner_map_fd; 113 attr.inner_map_fd = inner_map_fd;
100 attr.max_entries = max_entries; 114 attr.max_entries = max_entries;
101 attr.map_flags = map_flags; 115 attr.map_flags = map_flags;
116 memcpy(attr.map_name, name, min(name_len, BPF_OBJ_NAME_LEN - 1));
117
102 if (node >= 0) { 118 if (node >= 0) {
103 attr.map_flags |= BPF_F_NUMA_NODE; 119 attr.map_flags |= BPF_F_NUMA_NODE;
104 attr.numa_node = node; 120 attr.numa_node = node;
@@ -107,19 +123,24 @@ int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size,
107 return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); 123 return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
108} 124}
109 125
110int bpf_create_map_in_map(enum bpf_map_type map_type, int key_size, 126int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name,
111 int inner_map_fd, int max_entries, __u32 map_flags) 127 int key_size, int inner_map_fd, int max_entries,
128 __u32 map_flags)
112{ 129{
113 return bpf_create_map_in_map_node(map_type, key_size, inner_map_fd, 130 return bpf_create_map_in_map_node(map_type, name, key_size,
114 max_entries, map_flags, -1); 131 inner_map_fd, max_entries, map_flags,
132 -1);
115} 133}
116 134
117int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, 135int bpf_load_program_name(enum bpf_prog_type type, const char *name,
118 size_t insns_cnt, const char *license, 136 const struct bpf_insn *insns,
119 __u32 kern_version, char *log_buf, size_t log_buf_sz) 137 size_t insns_cnt, const char *license,
138 __u32 kern_version, char *log_buf,
139 size_t log_buf_sz)
120{ 140{
121 int fd; 141 int fd;
122 union bpf_attr attr; 142 union bpf_attr attr;
143 __u32 name_len = name ? strlen(name) : 0;
123 144
124 bzero(&attr, sizeof(attr)); 145 bzero(&attr, sizeof(attr));
125 attr.prog_type = type; 146 attr.prog_type = type;
@@ -130,6 +151,7 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
130 attr.log_size = 0; 151 attr.log_size = 0;
131 attr.log_level = 0; 152 attr.log_level = 0;
132 attr.kern_version = kern_version; 153 attr.kern_version = kern_version;
154 memcpy(attr.prog_name, name, min(name_len, BPF_OBJ_NAME_LEN - 1));
133 155
134 fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 156 fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
135 if (fd >= 0 || !log_buf || !log_buf_sz) 157 if (fd >= 0 || !log_buf || !log_buf_sz)
@@ -143,6 +165,15 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
143 return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 165 return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
144} 166}
145 167
168int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
169 size_t insns_cnt, const char *license,
170 __u32 kern_version, char *log_buf,
171 size_t log_buf_sz)
172{
173 return bpf_load_program_name(type, NULL, insns, insns_cnt, license,
174 kern_version, log_buf, log_buf_sz);
175}
176
146int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, 177int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
147 size_t insns_cnt, int strict_alignment, 178 size_t insns_cnt, int strict_alignment,
148 const char *license, __u32 kern_version, 179 const char *license, __u32 kern_version,
@@ -260,6 +291,38 @@ int bpf_prog_detach(int target_fd, enum bpf_attach_type type)
260 return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); 291 return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr));
261} 292}
262 293
294int bpf_prog_detach2(int prog_fd, int target_fd, enum bpf_attach_type type)
295{
296 union bpf_attr attr;
297
298 bzero(&attr, sizeof(attr));
299 attr.target_fd = target_fd;
300 attr.attach_bpf_fd = prog_fd;
301 attr.attach_type = type;
302
303 return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr));
304}
305
306int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
307 __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt)
308{
309 union bpf_attr attr;
310 int ret;
311
312 bzero(&attr, sizeof(attr));
313 attr.query.target_fd = target_fd;
314 attr.query.attach_type = type;
315 attr.query.query_flags = query_flags;
316 attr.query.prog_cnt = *prog_cnt;
317 attr.query.prog_ids = ptr_to_u64(prog_ids);
318
319 ret = sys_bpf(BPF_PROG_QUERY, &attr, sizeof(attr));
320 if (attach_flags)
321 *attach_flags = attr.query.attach_flags;
322 *prog_cnt = attr.query.prog_cnt;
323 return ret;
324}
325
263int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, 326int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size,
264 void *data_out, __u32 *size_out, __u32 *retval, 327 void *data_out, __u32 *size_out, __u32 *retval,
265 __u32 *duration) 328 __u32 *duration)
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index b8ea5843c39e..6534889e2b2f 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -24,19 +24,28 @@
24#include <linux/bpf.h> 24#include <linux/bpf.h>
25#include <stddef.h> 25#include <stddef.h>
26 26
27int bpf_create_map_node(enum bpf_map_type map_type, int key_size, 27int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
28 int value_size, int max_entries, __u32 map_flags, 28 int key_size, int value_size, int max_entries,
29 int node); 29 __u32 map_flags, int node);
30int bpf_create_map_name(enum bpf_map_type map_type, const char *name,
31 int key_size, int value_size, int max_entries,
32 __u32 map_flags);
30int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, 33int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
31 int max_entries, __u32 map_flags); 34 int max_entries, __u32 map_flags);
32int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size, 35int bpf_create_map_in_map_node(enum bpf_map_type map_type, const char *name,
33 int inner_map_fd, int max_entries, 36 int key_size, int inner_map_fd, int max_entries,
34 __u32 map_flags, int node); 37 __u32 map_flags, int node);
35int bpf_create_map_in_map(enum bpf_map_type map_type, int key_size, 38int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name,
36 int inner_map_fd, int max_entries, __u32 map_flags); 39 int key_size, int inner_map_fd, int max_entries,
40 __u32 map_flags);
37 41
38/* Recommend log buffer size */ 42/* Recommend log buffer size */
39#define BPF_LOG_BUF_SIZE 65536 43#define BPF_LOG_BUF_SIZE 65536
44int bpf_load_program_name(enum bpf_prog_type type, const char *name,
45 const struct bpf_insn *insns,
46 size_t insns_cnt, const char *license,
47 __u32 kern_version, char *log_buf,
48 size_t log_buf_sz);
40int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, 49int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
41 size_t insns_cnt, const char *license, 50 size_t insns_cnt, const char *license,
42 __u32 kern_version, char *log_buf, 51 __u32 kern_version, char *log_buf,
@@ -57,6 +66,7 @@ int bpf_obj_get(const char *pathname);
57int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, 66int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type,
58 unsigned int flags); 67 unsigned int flags);
59int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); 68int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
69int bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type);
60int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, 70int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size,
61 void *data_out, __u32 *size_out, __u32 *retval, 71 void *data_out, __u32 *size_out, __u32 *retval,
62 __u32 *duration); 72 __u32 *duration);
@@ -65,5 +75,6 @@ int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
65int bpf_prog_get_fd_by_id(__u32 id); 75int bpf_prog_get_fd_by_id(__u32 id);
66int bpf_map_get_fd_by_id(__u32 id); 76int bpf_map_get_fd_by_id(__u32 id);
67int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len); 77int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len);
68 78int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
79 __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt);
69#endif 80#endif
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 35f6dfcdc565..5aa45f89da93 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -171,6 +171,7 @@ int libbpf_strerror(int err, char *buf, size_t size)
171struct bpf_program { 171struct bpf_program {
172 /* Index in elf obj file, for relocation use. */ 172 /* Index in elf obj file, for relocation use. */
173 int idx; 173 int idx;
174 char *name;
174 char *section_name; 175 char *section_name;
175 struct bpf_insn *insns; 176 struct bpf_insn *insns;
176 size_t insns_cnt; 177 size_t insns_cnt;
@@ -283,6 +284,7 @@ static void bpf_program__exit(struct bpf_program *prog)
283 prog->clear_priv = NULL; 284 prog->clear_priv = NULL;
284 285
285 bpf_program__unload(prog); 286 bpf_program__unload(prog);
287 zfree(&prog->name);
286 zfree(&prog->section_name); 288 zfree(&prog->section_name);
287 zfree(&prog->insns); 289 zfree(&prog->insns);
288 zfree(&prog->reloc_desc); 290 zfree(&prog->reloc_desc);
@@ -293,26 +295,27 @@ static void bpf_program__exit(struct bpf_program *prog)
293} 295}
294 296
295static int 297static int
296bpf_program__init(void *data, size_t size, char *name, int idx, 298bpf_program__init(void *data, size_t size, char *section_name, int idx,
297 struct bpf_program *prog) 299 struct bpf_program *prog)
298{ 300{
299 if (size < sizeof(struct bpf_insn)) { 301 if (size < sizeof(struct bpf_insn)) {
300 pr_warning("corrupted section '%s'\n", name); 302 pr_warning("corrupted section '%s'\n", section_name);
301 return -EINVAL; 303 return -EINVAL;
302 } 304 }
303 305
304 bzero(prog, sizeof(*prog)); 306 bzero(prog, sizeof(*prog));
305 307
306 prog->section_name = strdup(name); 308 prog->section_name = strdup(section_name);
307 if (!prog->section_name) { 309 if (!prog->section_name) {
308 pr_warning("failed to alloc name for prog %s\n", 310 pr_warning("failed to alloc name for prog under section %s\n",
309 name); 311 section_name);
310 goto errout; 312 goto errout;
311 } 313 }
312 314
313 prog->insns = malloc(size); 315 prog->insns = malloc(size);
314 if (!prog->insns) { 316 if (!prog->insns) {
315 pr_warning("failed to alloc insns for %s\n", name); 317 pr_warning("failed to alloc insns for prog under section %s\n",
318 section_name);
316 goto errout; 319 goto errout;
317 } 320 }
318 prog->insns_cnt = size / sizeof(struct bpf_insn); 321 prog->insns_cnt = size / sizeof(struct bpf_insn);
@@ -331,12 +334,12 @@ errout:
331 334
332static int 335static int
333bpf_object__add_program(struct bpf_object *obj, void *data, size_t size, 336bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
334 char *name, int idx) 337 char *section_name, int idx)
335{ 338{
336 struct bpf_program prog, *progs; 339 struct bpf_program prog, *progs;
337 int nr_progs, err; 340 int nr_progs, err;
338 341
339 err = bpf_program__init(data, size, name, idx, &prog); 342 err = bpf_program__init(data, size, section_name, idx, &prog);
340 if (err) 343 if (err)
341 return err; 344 return err;
342 345
@@ -350,8 +353,8 @@ bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
350 * is still valid, so don't need special treat for 353 * is still valid, so don't need special treat for
351 * bpf_close_object(). 354 * bpf_close_object().
352 */ 355 */
353 pr_warning("failed to alloc a new program '%s'\n", 356 pr_warning("failed to alloc a new program under section '%s'\n",
354 name); 357 section_name);
355 bpf_program__exit(&prog); 358 bpf_program__exit(&prog);
356 return -ENOMEM; 359 return -ENOMEM;
357 } 360 }
@@ -364,6 +367,54 @@ bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
364 return 0; 367 return 0;
365} 368}
366 369
370static int
371bpf_object__init_prog_names(struct bpf_object *obj)
372{
373 Elf_Data *symbols = obj->efile.symbols;
374 struct bpf_program *prog;
375 size_t pi, si;
376
377 for (pi = 0; pi < obj->nr_programs; pi++) {
378 char *name = NULL;
379
380 prog = &obj->programs[pi];
381
382 for (si = 0; si < symbols->d_size / sizeof(GElf_Sym) && !name;
383 si++) {
384 GElf_Sym sym;
385
386 if (!gelf_getsym(symbols, si, &sym))
387 continue;
388 if (sym.st_shndx != prog->idx)
389 continue;
390
391 name = elf_strptr(obj->efile.elf,
392 obj->efile.strtabidx,
393 sym.st_name);
394 if (!name) {
395 pr_warning("failed to get sym name string for prog %s\n",
396 prog->section_name);
397 return -LIBBPF_ERRNO__LIBELF;
398 }
399 }
400
401 if (!name) {
402 pr_warning("failed to find sym for prog %s\n",
403 prog->section_name);
404 return -EINVAL;
405 }
406
407 prog->name = strdup(name);
408 if (!prog->name) {
409 pr_warning("failed to allocate memory for prog sym %s\n",
410 name);
411 return -ENOMEM;
412 }
413 }
414
415 return 0;
416}
417
367static struct bpf_object *bpf_object__new(const char *path, 418static struct bpf_object *bpf_object__new(const char *path,
368 void *obj_buf, 419 void *obj_buf,
369 size_t obj_buf_sz) 420 size_t obj_buf_sz)
@@ -528,31 +579,6 @@ bpf_object__init_kversion(struct bpf_object *obj,
528 return 0; 579 return 0;
529} 580}
530 581
531static int
532bpf_object__validate_maps(struct bpf_object *obj)
533{
534 int i;
535
536 /*
537 * If there's only 1 map, the only error case should have been
538 * catched in bpf_object__init_maps().
539 */
540 if (!obj->maps || !obj->nr_maps || (obj->nr_maps == 1))
541 return 0;
542
543 for (i = 1; i < obj->nr_maps; i++) {
544 const struct bpf_map *a = &obj->maps[i - 1];
545 const struct bpf_map *b = &obj->maps[i];
546
547 if (b->offset - a->offset < sizeof(struct bpf_map_def)) {
548 pr_warning("corrupted map section in %s: map \"%s\" too small\n",
549 obj->path, a->name);
550 return -EINVAL;
551 }
552 }
553 return 0;
554}
555
556static int compare_bpf_map(const void *_a, const void *_b) 582static int compare_bpf_map(const void *_a, const void *_b)
557{ 583{
558 const struct bpf_map *a = _a; 584 const struct bpf_map *a = _a;
@@ -564,7 +590,7 @@ static int compare_bpf_map(const void *_a, const void *_b)
564static int 590static int
565bpf_object__init_maps(struct bpf_object *obj) 591bpf_object__init_maps(struct bpf_object *obj)
566{ 592{
567 int i, map_idx, nr_maps = 0; 593 int i, map_idx, map_def_sz, nr_maps = 0;
568 Elf_Scn *scn; 594 Elf_Scn *scn;
569 Elf_Data *data; 595 Elf_Data *data;
570 Elf_Data *symbols = obj->efile.symbols; 596 Elf_Data *symbols = obj->efile.symbols;
@@ -607,6 +633,15 @@ bpf_object__init_maps(struct bpf_object *obj)
607 if (!nr_maps) 633 if (!nr_maps)
608 return 0; 634 return 0;
609 635
636 /* Assume equally sized map definitions */
637 map_def_sz = data->d_size / nr_maps;
638 if (!data->d_size || (data->d_size % nr_maps) != 0) {
639 pr_warning("unable to determine map definition size "
640 "section %s, %d maps in %zd bytes\n",
641 obj->path, nr_maps, data->d_size);
642 return -EINVAL;
643 }
644
610 obj->maps = calloc(nr_maps, sizeof(obj->maps[0])); 645 obj->maps = calloc(nr_maps, sizeof(obj->maps[0]));
611 if (!obj->maps) { 646 if (!obj->maps) {
612 pr_warning("alloc maps for object failed\n"); 647 pr_warning("alloc maps for object failed\n");
@@ -639,7 +674,7 @@ bpf_object__init_maps(struct bpf_object *obj)
639 obj->efile.strtabidx, 674 obj->efile.strtabidx,
640 sym.st_name); 675 sym.st_name);
641 obj->maps[map_idx].offset = sym.st_value; 676 obj->maps[map_idx].offset = sym.st_value;
642 if (sym.st_value + sizeof(struct bpf_map_def) > data->d_size) { 677 if (sym.st_value + map_def_sz > data->d_size) {
643 pr_warning("corrupted maps section in %s: last map \"%s\" too small\n", 678 pr_warning("corrupted maps section in %s: last map \"%s\" too small\n",
644 obj->path, map_name); 679 obj->path, map_name);
645 return -EINVAL; 680 return -EINVAL;
@@ -653,12 +688,40 @@ bpf_object__init_maps(struct bpf_object *obj)
653 pr_debug("map %d is \"%s\"\n", map_idx, 688 pr_debug("map %d is \"%s\"\n", map_idx,
654 obj->maps[map_idx].name); 689 obj->maps[map_idx].name);
655 def = (struct bpf_map_def *)(data->d_buf + sym.st_value); 690 def = (struct bpf_map_def *)(data->d_buf + sym.st_value);
656 obj->maps[map_idx].def = *def; 691 /*
692 * If the definition of the map in the object file fits in
693 * bpf_map_def, copy it. Any extra fields in our version
694 * of bpf_map_def will default to zero as a result of the
695 * calloc above.
696 */
697 if (map_def_sz <= sizeof(struct bpf_map_def)) {
698 memcpy(&obj->maps[map_idx].def, def, map_def_sz);
699 } else {
700 /*
701 * Here the map structure being read is bigger than what
702 * we expect, truncate if the excess bits are all zero.
703 * If they are not zero, reject this map as
704 * incompatible.
705 */
706 char *b;
707 for (b = ((char *)def) + sizeof(struct bpf_map_def);
708 b < ((char *)def) + map_def_sz; b++) {
709 if (*b != 0) {
710 pr_warning("maps section in %s: \"%s\" "
711 "has unrecognized, non-zero "
712 "options\n",
713 obj->path, map_name);
714 return -EINVAL;
715 }
716 }
717 memcpy(&obj->maps[map_idx].def, def,
718 sizeof(struct bpf_map_def));
719 }
657 map_idx++; 720 map_idx++;
658 } 721 }
659 722
660 qsort(obj->maps, obj->nr_maps, sizeof(obj->maps[0]), compare_bpf_map); 723 qsort(obj->maps, obj->nr_maps, sizeof(obj->maps[0]), compare_bpf_map);
661 return bpf_object__validate_maps(obj); 724 return 0;
662} 725}
663 726
664static int bpf_object__elf_collect(struct bpf_object *obj) 727static int bpf_object__elf_collect(struct bpf_object *obj)
@@ -766,8 +829,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
766 pr_warning("Corrupted ELF file: index of strtab invalid\n"); 829 pr_warning("Corrupted ELF file: index of strtab invalid\n");
767 return LIBBPF_ERRNO__FORMAT; 830 return LIBBPF_ERRNO__FORMAT;
768 } 831 }
769 if (obj->efile.maps_shndx >= 0) 832 if (obj->efile.maps_shndx >= 0) {
770 err = bpf_object__init_maps(obj); 833 err = bpf_object__init_maps(obj);
834 if (err)
835 goto out;
836 }
837 err = bpf_object__init_prog_names(obj);
771out: 838out:
772 return err; 839 return err;
773} 840}
@@ -870,11 +937,12 @@ bpf_object__create_maps(struct bpf_object *obj)
870 struct bpf_map_def *def = &obj->maps[i].def; 937 struct bpf_map_def *def = &obj->maps[i].def;
871 int *pfd = &obj->maps[i].fd; 938 int *pfd = &obj->maps[i].fd;
872 939
873 *pfd = bpf_create_map(def->type, 940 *pfd = bpf_create_map_name(def->type,
874 def->key_size, 941 obj->maps[i].name,
875 def->value_size, 942 def->key_size,
876 def->max_entries, 943 def->value_size,
877 0); 944 def->max_entries,
945 def->map_flags);
878 if (*pfd < 0) { 946 if (*pfd < 0) {
879 size_t j; 947 size_t j;
880 int err = *pfd; 948 int err = *pfd;
@@ -982,7 +1050,7 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
982} 1050}
983 1051
984static int 1052static int
985load_program(enum bpf_prog_type type, struct bpf_insn *insns, 1053load_program(enum bpf_prog_type type, const char *name, struct bpf_insn *insns,
986 int insns_cnt, char *license, u32 kern_version, int *pfd) 1054 int insns_cnt, char *license, u32 kern_version, int *pfd)
987{ 1055{
988 int ret; 1056 int ret;
@@ -995,8 +1063,8 @@ load_program(enum bpf_prog_type type, struct bpf_insn *insns,
995 if (!log_buf) 1063 if (!log_buf)
996 pr_warning("Alloc log buffer for bpf loader error, continue without log\n"); 1064 pr_warning("Alloc log buffer for bpf loader error, continue without log\n");
997 1065
998 ret = bpf_load_program(type, insns, insns_cnt, license, 1066 ret = bpf_load_program_name(type, name, insns, insns_cnt, license,
999 kern_version, log_buf, BPF_LOG_BUF_SIZE); 1067 kern_version, log_buf, BPF_LOG_BUF_SIZE);
1000 1068
1001 if (ret >= 0) { 1069 if (ret >= 0) {
1002 *pfd = ret; 1070 *pfd = ret;
@@ -1021,9 +1089,9 @@ load_program(enum bpf_prog_type type, struct bpf_insn *insns,
1021 if (type != BPF_PROG_TYPE_KPROBE) { 1089 if (type != BPF_PROG_TYPE_KPROBE) {
1022 int fd; 1090 int fd;
1023 1091
1024 fd = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns, 1092 fd = bpf_load_program_name(BPF_PROG_TYPE_KPROBE, name,
1025 insns_cnt, license, kern_version, 1093 insns, insns_cnt, license,
1026 NULL, 0); 1094 kern_version, NULL, 0);
1027 if (fd >= 0) { 1095 if (fd >= 0) {
1028 close(fd); 1096 close(fd);
1029 ret = -LIBBPF_ERRNO__PROGTYPE; 1097 ret = -LIBBPF_ERRNO__PROGTYPE;
@@ -1067,8 +1135,8 @@ bpf_program__load(struct bpf_program *prog,
1067 pr_warning("Program '%s' is inconsistent: nr(%d) != 1\n", 1135 pr_warning("Program '%s' is inconsistent: nr(%d) != 1\n",
1068 prog->section_name, prog->instances.nr); 1136 prog->section_name, prog->instances.nr);
1069 } 1137 }
1070 err = load_program(prog->type, prog->insns, prog->insns_cnt, 1138 err = load_program(prog->type, prog->name, prog->insns,
1071 license, kern_version, &fd); 1139 prog->insns_cnt, license, kern_version, &fd);
1072 if (!err) 1140 if (!err)
1073 prog->instances.fds[0] = fd; 1141 prog->instances.fds[0] = fd;
1074 goto out; 1142 goto out;
@@ -1096,7 +1164,8 @@ bpf_program__load(struct bpf_program *prog,
1096 continue; 1164 continue;
1097 } 1165 }
1098 1166
1099 err = load_program(prog->type, result.new_insn_ptr, 1167 err = load_program(prog->type, prog->name,
1168 result.new_insn_ptr,
1100 result.new_insn_cnt, 1169 result.new_insn_cnt,
1101 license, kern_version, &fd); 1170 license, kern_version, &fd);
1102 1171
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 7959086eb9c9..6e20003109e0 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -207,6 +207,7 @@ struct bpf_map_def {
207 unsigned int key_size; 207 unsigned int key_size;
208 unsigned int value_size; 208 unsigned int value_size;
209 unsigned int max_entries; 209 unsigned int max_entries;
210 unsigned int map_flags;
210}; 211};
211 212
212/* 213/*
diff --git a/tools/lib/hweight.c b/tools/lib/hweight.c
index 0b859b884339..a16ebf515417 100644
--- a/tools/lib/hweight.c
+++ b/tools/lib/hweight.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/bitops.h> 2#include <linux/bitops.h>
2#include <asm/types.h> 3#include <asm/types.h>
3 4
diff --git a/tools/lib/lockdep/Makefile b/tools/lib/lockdep/Makefile
index ed9ace59d112..9b0ca3ad1ef3 100644
--- a/tools/lib/lockdep/Makefile
+++ b/tools/lib/lockdep/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# file format version 2# file format version
2FILE_VERSION = 1 3FILE_VERSION = 1
3 4
diff --git a/tools/lib/lockdep/common.c b/tools/lib/lockdep/common.c
index d1c89cc06f5f..5c3b58cce8a9 100644
--- a/tools/lib/lockdep/common.c
+++ b/tools/lib/lockdep/common.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stddef.h> 2#include <stddef.h>
2#include <stdbool.h> 3#include <stdbool.h>
3#include <linux/compiler.h> 4#include <linux/compiler.h>
diff --git a/tools/lib/lockdep/include/liblockdep/common.h b/tools/lib/lockdep/include/liblockdep/common.h
index 6e66277ec437..8862da80995a 100644
--- a/tools/lib/lockdep/include/liblockdep/common.h
+++ b/tools/lib/lockdep/include/liblockdep/common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_COMMON_H 2#ifndef _LIBLOCKDEP_COMMON_H
2#define _LIBLOCKDEP_COMMON_H 3#define _LIBLOCKDEP_COMMON_H
3 4
diff --git a/tools/lib/lockdep/include/liblockdep/mutex.h b/tools/lib/lockdep/include/liblockdep/mutex.h
index ee53a42818ca..a80ac39f966e 100644
--- a/tools/lib/lockdep/include/liblockdep/mutex.h
+++ b/tools/lib/lockdep/include/liblockdep/mutex.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_MUTEX_H 2#ifndef _LIBLOCKDEP_MUTEX_H
2#define _LIBLOCKDEP_MUTEX_H 3#define _LIBLOCKDEP_MUTEX_H
3 4
diff --git a/tools/lib/lockdep/include/liblockdep/rwlock.h b/tools/lib/lockdep/include/liblockdep/rwlock.h
index 4ec03f861551..a96c3bf0fef1 100644
--- a/tools/lib/lockdep/include/liblockdep/rwlock.h
+++ b/tools/lib/lockdep/include/liblockdep/rwlock.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_RWLOCK_H 2#ifndef _LIBLOCKDEP_RWLOCK_H
2#define _LIBLOCKDEP_RWLOCK_H 3#define _LIBLOCKDEP_RWLOCK_H
3 4
diff --git a/tools/lib/lockdep/lockdep.c b/tools/lib/lockdep/lockdep.c
index ced6d7443cea..6002fcf2f9bc 100644
--- a/tools/lib/lockdep/lockdep.c
+++ b/tools/lib/lockdep/lockdep.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/lockdep.h> 2#include <linux/lockdep.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/lib/lockdep/preload.c b/tools/lib/lockdep/preload.c
index 6a2d3c5d4e92..76245d16196d 100644
--- a/tools/lib/lockdep/preload.c
+++ b/tools/lib/lockdep/preload.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <pthread.h> 3#include <pthread.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/lib/lockdep/run_tests.sh b/tools/lib/lockdep/run_tests.sh
index f9b94098fc98..2e570a188f16 100755
--- a/tools/lib/lockdep/run_tests.sh
+++ b/tools/lib/lockdep/run_tests.sh
@@ -1,4 +1,5 @@
1#! /bin/bash 1#! /bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3make &> /dev/null 4make &> /dev/null
4 5
diff --git a/tools/lib/lockdep/tests/AA.c b/tools/lib/lockdep/tests/AA.c
index 18211a5f354f..63c7ce97bda3 100644
--- a/tools/lib/lockdep/tests/AA.c
+++ b/tools/lib/lockdep/tests/AA.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2 3
3int main(void) 4int main(void)
diff --git a/tools/lib/lockdep/tests/ABA.c b/tools/lib/lockdep/tests/ABA.c
index 0f782ff404ac..efa39b23f05d 100644
--- a/tools/lib/lockdep/tests/ABA.c
+++ b/tools/lib/lockdep/tests/ABA.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2 3
3void main(void) 4void main(void)
diff --git a/tools/lib/lockdep/tests/ABBA.c b/tools/lib/lockdep/tests/ABBA.c
index 07f0e29d5485..1460afd33d71 100644
--- a/tools/lib/lockdep/tests/ABBA.c
+++ b/tools/lib/lockdep/tests/ABBA.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2#include "common.h" 3#include "common.h"
3 4
diff --git a/tools/lib/lockdep/tests/ABBA_2threads.c b/tools/lib/lockdep/tests/ABBA_2threads.c
index cd807d736361..39325ef8a2ac 100644
--- a/tools/lib/lockdep/tests/ABBA_2threads.c
+++ b/tools/lib/lockdep/tests/ABBA_2threads.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <pthread.h> 3#include <pthread.h>
3 4
diff --git a/tools/lib/lockdep/tests/ABBCCA.c b/tools/lib/lockdep/tests/ABBCCA.c
index 843db09ac666..a54c1b2af118 100644
--- a/tools/lib/lockdep/tests/ABBCCA.c
+++ b/tools/lib/lockdep/tests/ABBCCA.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2#include "common.h" 3#include "common.h"
3 4
diff --git a/tools/lib/lockdep/tests/ABBCCDDA.c b/tools/lib/lockdep/tests/ABBCCDDA.c
index 33620e268f85..aa5d194e8869 100644
--- a/tools/lib/lockdep/tests/ABBCCDDA.c
+++ b/tools/lib/lockdep/tests/ABBCCDDA.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2#include "common.h" 3#include "common.h"
3 4
diff --git a/tools/lib/lockdep/tests/ABCABC.c b/tools/lib/lockdep/tests/ABCABC.c
index 3fee51e3a68a..b54a08e60416 100644
--- a/tools/lib/lockdep/tests/ABCABC.c
+++ b/tools/lib/lockdep/tests/ABCABC.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2#include "common.h" 3#include "common.h"
3 4
diff --git a/tools/lib/lockdep/tests/ABCDBCDA.c b/tools/lib/lockdep/tests/ABCDBCDA.c
index 427ba562c75b..a56742250d86 100644
--- a/tools/lib/lockdep/tests/ABCDBCDA.c
+++ b/tools/lib/lockdep/tests/ABCDBCDA.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2#include "common.h" 3#include "common.h"
3 4
diff --git a/tools/lib/lockdep/tests/ABCDBDDA.c b/tools/lib/lockdep/tests/ABCDBDDA.c
index 680c6cf3e919..238a3353f3c3 100644
--- a/tools/lib/lockdep/tests/ABCDBDDA.c
+++ b/tools/lib/lockdep/tests/ABCDBDDA.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2#include "common.h" 3#include "common.h"
3 4
diff --git a/tools/lib/lockdep/tests/WW.c b/tools/lib/lockdep/tests/WW.c
index d44f77d71029..eee88df7fc41 100644
--- a/tools/lib/lockdep/tests/WW.c
+++ b/tools/lib/lockdep/tests/WW.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/rwlock.h> 2#include <liblockdep/rwlock.h>
2 3
3void main(void) 4void main(void)
diff --git a/tools/lib/lockdep/tests/common.h b/tools/lib/lockdep/tests/common.h
index d89e94d47d86..3026c29ccb5c 100644
--- a/tools/lib/lockdep/tests/common.h
+++ b/tools/lib/lockdep/tests/common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIBLOCKDEP_TEST_COMMON_H 2#ifndef _LIBLOCKDEP_TEST_COMMON_H
2#define _LIBLOCKDEP_TEST_COMMON_H 3#define _LIBLOCKDEP_TEST_COMMON_H
3 4
diff --git a/tools/lib/lockdep/tests/unlock_balance.c b/tools/lib/lockdep/tests/unlock_balance.c
index 0bc62de686f7..34cf32f689de 100644
--- a/tools/lib/lockdep/tests/unlock_balance.c
+++ b/tools/lib/lockdep/tests/unlock_balance.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <liblockdep/mutex.h> 2#include <liblockdep/mutex.h>
2 3
3void main(void) 4void main(void)
diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
index 503ae072244c..d6d65537b0d9 100644
--- a/tools/lib/str_error_r.c
+++ b/tools/lib/str_error_r.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#undef _GNU_SOURCE 2#undef _GNU_SOURCE
2#include <string.h> 3#include <string.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/lib/string.c b/tools/lib/string.c
index a4246f14ded1..93b3d4b6feac 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * linux/tools/lib/string.c 3 * linux/tools/lib/string.c
3 * 4 *
diff --git a/tools/lib/subcmd/Makefile b/tools/lib/subcmd/Makefile
index 7e9f03c97e4c..95563b8e1ad7 100644
--- a/tools/lib/subcmd/Makefile
+++ b/tools/lib/subcmd/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1include ../../scripts/Makefile.include 2include ../../scripts/Makefile.include
2include ../../scripts/utilities.mak # QUIET_CLEAN 3include ../../scripts/utilities.mak # QUIET_CLEAN
3 4
diff --git a/tools/lib/subcmd/exec-cmd.c b/tools/lib/subcmd/exec-cmd.c
index 1ae833af1a4a..33e94fb83986 100644
--- a/tools/lib/subcmd/exec-cmd.c
+++ b/tools/lib/subcmd/exec-cmd.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/string.h> 3#include <linux/string.h>
3#include <sys/types.h> 4#include <sys/types.h>
diff --git a/tools/lib/subcmd/exec-cmd.h b/tools/lib/subcmd/exec-cmd.h
index 5d08bda31d90..aba591b8d254 100644
--- a/tools/lib/subcmd/exec-cmd.h
+++ b/tools/lib/subcmd/exec-cmd.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __SUBCMD_EXEC_CMD_H 2#ifndef __SUBCMD_EXEC_CMD_H
2#define __SUBCMD_EXEC_CMD_H 3#define __SUBCMD_EXEC_CMD_H
3 4
diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
index 0310520f918e..2859f107abc8 100644
--- a/tools/lib/subcmd/help.c
+++ b/tools/lib/subcmd/help.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/lib/subcmd/help.h b/tools/lib/subcmd/help.h
index 9bd4223dc722..355c066c8d49 100644
--- a/tools/lib/subcmd/help.h
+++ b/tools/lib/subcmd/help.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __SUBCMD_HELP_H 2#ifndef __SUBCMD_HELP_H
2#define __SUBCMD_HELP_H 3#define __SUBCMD_HELP_H
3 4
diff --git a/tools/lib/subcmd/pager.c b/tools/lib/subcmd/pager.c
index 6518bea926d6..5ba754d17952 100644
--- a/tools/lib/subcmd/pager.c
+++ b/tools/lib/subcmd/pager.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/select.h> 2#include <sys/select.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/lib/subcmd/pager.h b/tools/lib/subcmd/pager.h
index 623f5542d05d..f1a53cf29880 100644
--- a/tools/lib/subcmd/pager.h
+++ b/tools/lib/subcmd/pager.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __SUBCMD_PAGER_H 2#ifndef __SUBCMD_PAGER_H
2#define __SUBCMD_PAGER_H 3#define __SUBCMD_PAGER_H
3 4
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 2bd6fd0c1d40..f6a1babcbac4 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/string.h> 3#include <linux/string.h>
3#include <linux/types.h> 4#include <linux/types.h>
diff --git a/tools/lib/subcmd/parse-options.h b/tools/lib/subcmd/parse-options.h
index f054ca1b899d..92fdbe1519f6 100644
--- a/tools/lib/subcmd/parse-options.h
+++ b/tools/lib/subcmd/parse-options.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __SUBCMD_PARSE_OPTIONS_H 2#ifndef __SUBCMD_PARSE_OPTIONS_H
2#define __SUBCMD_PARSE_OPTIONS_H 3#define __SUBCMD_PARSE_OPTIONS_H
3 4
diff --git a/tools/lib/subcmd/run-command.c b/tools/lib/subcmd/run-command.c
index 911f83942723..5cdac2162532 100644
--- a/tools/lib/subcmd/run-command.c
+++ b/tools/lib/subcmd/run-command.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <unistd.h> 2#include <unistd.h>
2#include <sys/types.h> 3#include <sys/types.h>
3#include <sys/stat.h> 4#include <sys/stat.h>
diff --git a/tools/lib/subcmd/run-command.h b/tools/lib/subcmd/run-command.h
index fe2befea1e73..17d969c6add3 100644
--- a/tools/lib/subcmd/run-command.h
+++ b/tools/lib/subcmd/run-command.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __SUBCMD_RUN_COMMAND_H 2#ifndef __SUBCMD_RUN_COMMAND_H
2#define __SUBCMD_RUN_COMMAND_H 3#define __SUBCMD_RUN_COMMAND_H
3 4
diff --git a/tools/lib/subcmd/sigchain.c b/tools/lib/subcmd/sigchain.c
index 3537c348a18e..f0fe3dbef7f7 100644
--- a/tools/lib/subcmd/sigchain.c
+++ b/tools/lib/subcmd/sigchain.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <signal.h> 2#include <signal.h>
2#include "subcmd-util.h" 3#include "subcmd-util.h"
3#include "sigchain.h" 4#include "sigchain.h"
diff --git a/tools/lib/subcmd/sigchain.h b/tools/lib/subcmd/sigchain.h
index 0c919f2874ca..1ec663af43ea 100644
--- a/tools/lib/subcmd/sigchain.h
+++ b/tools/lib/subcmd/sigchain.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __SUBCMD_SIGCHAIN_H 2#ifndef __SUBCMD_SIGCHAIN_H
2#define __SUBCMD_SIGCHAIN_H 3#define __SUBCMD_SIGCHAIN_H
3 4
diff --git a/tools/lib/subcmd/subcmd-config.c b/tools/lib/subcmd/subcmd-config.c
index d017c728bd1b..84a7cf6c7878 100644
--- a/tools/lib/subcmd/subcmd-config.c
+++ b/tools/lib/subcmd/subcmd-config.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "subcmd-config.h" 2#include "subcmd-config.h"
2 3
3#define UNDEFINED "SUBCMD_HAS_NOT_BEEN_INITIALIZED" 4#define UNDEFINED "SUBCMD_HAS_NOT_BEEN_INITIALIZED"
diff --git a/tools/lib/subcmd/subcmd-config.h b/tools/lib/subcmd/subcmd-config.h
index cc8514030b5c..9024dc17d100 100644
--- a/tools/lib/subcmd/subcmd-config.h
+++ b/tools/lib/subcmd/subcmd-config.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_SUBCMD_CONFIG_H 2#ifndef __PERF_SUBCMD_CONFIG_H
2#define __PERF_SUBCMD_CONFIG_H 3#define __PERF_SUBCMD_CONFIG_H
3 4
diff --git a/tools/lib/subcmd/subcmd-util.h b/tools/lib/subcmd/subcmd-util.h
index 8fa5f036eff0..794a375dad36 100644
--- a/tools/lib/subcmd/subcmd-util.h
+++ b/tools/lib/subcmd/subcmd-util.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __SUBCMD_UTIL_H 2#ifndef __SUBCMD_UTIL_H
2#define __SUBCMD_UTIL_H 3#define __SUBCMD_UTIL_H
3 4
diff --git a/tools/lib/symbol/kallsyms.c b/tools/lib/symbol/kallsyms.c
index d270ac00613d..914cb8e3d40b 100644
--- a/tools/lib/symbol/kallsyms.c
+++ b/tools/lib/symbol/kallsyms.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <ctype.h> 2#include <ctype.h>
2#include "symbol/kallsyms.h" 3#include "symbol/kallsyms.h"
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/lib/symbol/kallsyms.h b/tools/lib/symbol/kallsyms.h
index 4071316a766e..bc40101d72c1 100644
--- a/tools/lib/symbol/kallsyms.h
+++ b/tools/lib/symbol/kallsyms.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TOOLS_KALLSYMS_H_ 2#ifndef __TOOLS_KALLSYMS_H_
2#define __TOOLS_KALLSYMS_H_ 1 3#define __TOOLS_KALLSYMS_H_ 1
3 4
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
index 9b8555ea3459..46cd5f871ad7 100644
--- a/tools/lib/traceevent/Makefile
+++ b/tools/lib/traceevent/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# trace-cmd version 2# trace-cmd version
2EP_VERSION = 1 3EP_VERSION = 1
3EP_PATCHLEVEL = 1 4EP_PATCHLEVEL = 1
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index 7c214ceb9386..315df0a70265 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -436,13 +436,13 @@ create_arg_exp(enum filter_exp_type etype)
436 return NULL; 436 return NULL;
437 437
438 arg->type = FILTER_ARG_EXP; 438 arg->type = FILTER_ARG_EXP;
439 arg->op.type = etype; 439 arg->exp.type = etype;
440 440
441 return arg; 441 return arg;
442} 442}
443 443
444static struct filter_arg * 444static struct filter_arg *
445create_arg_cmp(enum filter_exp_type etype) 445create_arg_cmp(enum filter_cmp_type ctype)
446{ 446{
447 struct filter_arg *arg; 447 struct filter_arg *arg;
448 448
@@ -452,7 +452,7 @@ create_arg_cmp(enum filter_exp_type etype)
452 452
453 /* Use NUM and change if necessary */ 453 /* Use NUM and change if necessary */
454 arg->type = FILTER_ARG_NUM; 454 arg->type = FILTER_ARG_NUM;
455 arg->op.type = etype; 455 arg->num.type = ctype;
456 456
457 return arg; 457 return arg;
458} 458}
diff --git a/tools/lib/traceevent/plugin_cfg80211.c b/tools/lib/traceevent/plugin_cfg80211.c
index ec57d0c1fbc2..8f8586912da7 100644
--- a/tools/lib/traceevent/plugin_cfg80211.c
+++ b/tools/lib/traceevent/plugin_cfg80211.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <string.h> 3#include <string.h>
3#include <inttypes.h> 4#include <inttypes.h>
diff --git a/tools/lib/traceevent/plugin_scsi.c b/tools/lib/traceevent/plugin_scsi.c
index 3727de48c8d5..5e750af2b461 100644
--- a/tools/lib/traceevent/plugin_scsi.c
+++ b/tools/lib/traceevent/plugin_scsi.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <string.h> 3#include <string.h>
3#include <inttypes.h> 4#include <inttypes.h>
diff --git a/tools/lib/traceevent/plugin_xen.c b/tools/lib/traceevent/plugin_xen.c
index 3a413eaada68..690173bfa13e 100644
--- a/tools/lib/traceevent/plugin_xen.c
+++ b/tools/lib/traceevent/plugin_xen.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
index 45f9a06daa56..e08ee147eab4 100644
--- a/tools/lib/vsprintf.c
+++ b/tools/lib/vsprintf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/nfsd/inject_fault.sh b/tools/nfsd/inject_fault.sh
index 06a399ac8b2f..10ceee64a09a 100755
--- a/tools/nfsd/inject_fault.sh
+++ b/tools/nfsd/inject_fault.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com> 4# Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com>
4# 5#
diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore
index d3102c865a95..914cff12899b 100644
--- a/tools/objtool/.gitignore
+++ b/tools/objtool/.gitignore
@@ -1,3 +1,3 @@
1arch/x86/insn/inat-tables.c 1arch/x86/lib/inat-tables.c
2objtool 2objtool
3fixdep 3fixdep
diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt
index 6a1af43862df..3995735a878f 100644
--- a/tools/objtool/Documentation/stack-validation.txt
+++ b/tools/objtool/Documentation/stack-validation.txt
@@ -194,10 +194,10 @@ they mean, and suggestions for how to fix them.
194 If it's a GCC-compiled .c file, the error may be because the function 194 If it's a GCC-compiled .c file, the error may be because the function
195 uses an inline asm() statement which has a "call" instruction. An 195 uses an inline asm() statement which has a "call" instruction. An
196 asm() statement with a call instruction must declare the use of the 196 asm() statement with a call instruction must declare the use of the
197 stack pointer in its output operand. For example, on x86_64: 197 stack pointer in its output operand. On x86_64, this means adding
198 the ASM_CALL_CONSTRAINT as an output constraint:
198 199
199 register void *__sp asm("rsp"); 200 asm volatile("call func" : ASM_CALL_CONSTRAINT);
200 asm volatile("call func" : "+r" (__sp));
201 201
202 Otherwise the stack frame may not get created before the call. 202 Otherwise the stack frame may not get created before the call.
203 203
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 6976c73e60c4..0f94af3ccaaa 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1include ../scripts/Makefile.include 2include ../scripts/Makefile.include
2include ../scripts/Makefile.arch 3include ../scripts/Makefile.arch
3 4
@@ -24,7 +25,9 @@ OBJTOOL_IN := $(OBJTOOL)-in.o
24 25
25all: $(OBJTOOL) 26all: $(OBJTOOL)
26 27
27INCLUDES := -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi 28INCLUDES := -I$(srctree)/tools/include \
29 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
30 -I$(srctree)/tools/objtool/arch/$(ARCH)/include
28WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed 31WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
29CFLAGS += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES) 32CFLAGS += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
30LDFLAGS += -lelf $(LIBSUBCMD) 33LDFLAGS += -lelf $(LIBSUBCMD)
@@ -40,22 +43,8 @@ include $(srctree)/tools/build/Makefile.include
40$(OBJTOOL_IN): fixdep FORCE 43$(OBJTOOL_IN): fixdep FORCE
41 @$(MAKE) $(build)=objtool 44 @$(MAKE) $(build)=objtool
42 45
43# Busybox's diff doesn't have -I, avoid warning in that case
44#
45$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) 46$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
46 @(diff -I 2>&1 | grep -q 'option requires an argument' && \ 47 @./sync-check.sh
47 test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
48 diff -I'^#include' arch/x86/insn/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
49 diff -I'^#include' arch/x86/insn/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
50 diff arch/x86/insn/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
51 diff arch/x86/insn/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \
52 diff -I'^#include' arch/x86/insn/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \
53 diff -I'^#include' arch/x86/insn/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \
54 diff -I'^#include' arch/x86/insn/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \
55 || echo "warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true
56 @(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
57 diff ../../arch/x86/include/asm/orc_types.h orc_types.h >/dev/null) \
58 || echo "warning: objtool: orc_types.h differs from kernel" >&2 )) || true
59 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@ 48 $(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
60 49
61 50
@@ -65,7 +54,7 @@ $(LIBSUBCMD): fixdep FORCE
65clean: 54clean:
66 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) 55 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
67 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 56 $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
68 $(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep 57 $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
69 58
70FORCE: 59FORCE:
71 60
diff --git a/tools/objtool/arch/x86/Build b/tools/objtool/arch/x86/Build
index debbdb0b5c43..b998412c017d 100644
--- a/tools/objtool/arch/x86/Build
+++ b/tools/objtool/arch/x86/Build
@@ -1,12 +1,12 @@
1objtool-y += decode.o 1objtool-y += decode.o
2 2
3inat_tables_script = arch/x86/insn/gen-insn-attr-x86.awk 3inat_tables_script = arch/x86/tools/gen-insn-attr-x86.awk
4inat_tables_maps = arch/x86/insn/x86-opcode-map.txt 4inat_tables_maps = arch/x86/lib/x86-opcode-map.txt
5 5
6$(OUTPUT)arch/x86/insn/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) 6$(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_script) $(inat_tables_maps)
7 $(call rule_mkdir) 7 $(call rule_mkdir)
8 $(Q)$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@ 8 $(Q)$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@
9 9
10$(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/insn/inat-tables.c 10$(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c
11 11
12CFLAGS_decode.o += -I$(OUTPUT)arch/x86/insn 12CFLAGS_decode.o += -I$(OUTPUT)arch/x86/lib
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 0e8c8ec4fd4e..8acfc47af70e 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -19,9 +19,9 @@
19#include <stdlib.h> 19#include <stdlib.h>
20 20
21#define unlikely(cond) (cond) 21#define unlikely(cond) (cond)
22#include "insn/insn.h" 22#include <asm/insn.h>
23#include "insn/inat.c" 23#include "lib/inat.c"
24#include "insn/insn.c" 24#include "lib/insn.c"
25 25
26#include "../../elf.h" 26#include "../../elf.h"
27#include "../../arch.h" 27#include "../../arch.h"
@@ -208,14 +208,14 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
208 break; 208 break;
209 209
210 case 0x89: 210 case 0x89:
211 if (rex == 0x48 && modrm == 0xe5) { 211 if (rex_w && !rex_r && modrm_mod == 3 && modrm_reg == 4) {
212 212
213 /* mov %rsp, %rbp */ 213 /* mov %rsp, reg */
214 *type = INSN_STACK; 214 *type = INSN_STACK;
215 op->src.type = OP_SRC_REG; 215 op->src.type = OP_SRC_REG;
216 op->src.reg = CFI_SP; 216 op->src.reg = CFI_SP;
217 op->dest.type = OP_DEST_REG; 217 op->dest.type = OP_DEST_REG;
218 op->dest.reg = CFI_BP; 218 op->dest.reg = op_to_cfi_reg[modrm_rm][rex_b];
219 break; 219 break;
220 } 220 }
221 221
@@ -284,11 +284,16 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
284 case 0x8d: 284 case 0x8d:
285 if (sib == 0x24 && rex_w && !rex_b && !rex_x) { 285 if (sib == 0x24 && rex_w && !rex_b && !rex_x) {
286 286
287 /* lea disp(%rsp), reg */
288 *type = INSN_STACK; 287 *type = INSN_STACK;
289 op->src.type = OP_SRC_ADD; 288 if (!insn.displacement.value) {
289 /* lea (%rsp), reg */
290 op->src.type = OP_SRC_REG;
291 } else {
292 /* lea disp(%rsp), reg */
293 op->src.type = OP_SRC_ADD;
294 op->src.offset = insn.displacement.value;
295 }
290 op->src.reg = CFI_SP; 296 op->src.reg = CFI_SP;
291 op->src.offset = insn.displacement.value;
292 op->dest.type = OP_DEST_REG; 297 op->dest.type = OP_DEST_REG;
293 op->dest.reg = op_to_cfi_reg[modrm_reg][rex_r]; 298 op->dest.reg = op_to_cfi_reg[modrm_reg][rex_r];
294 299
diff --git a/tools/objtool/arch/x86/insn/inat.h b/tools/objtool/arch/x86/include/asm/inat.h
index 125ecd2a300d..1c78580e58be 100644
--- a/tools/objtool/arch/x86/insn/inat.h
+++ b/tools/objtool/arch/x86/include/asm/inat.h
@@ -20,7 +20,7 @@
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * 21 *
22 */ 22 */
23#include "inat_types.h" 23#include <asm/inat_types.h>
24 24
25/* 25/*
26 * Internal bits. Don't use bitmasks directly, because these bits are 26 * Internal bits. Don't use bitmasks directly, because these bits are
@@ -97,6 +97,16 @@
97#define INAT_MAKE_GROUP(grp) ((grp << INAT_GRP_OFFS) | INAT_MODRM) 97#define INAT_MAKE_GROUP(grp) ((grp << INAT_GRP_OFFS) | INAT_MODRM)
98#define INAT_MAKE_IMM(imm) (imm << INAT_IMM_OFFS) 98#define INAT_MAKE_IMM(imm) (imm << INAT_IMM_OFFS)
99 99
100/* Identifiers for segment registers */
101#define INAT_SEG_REG_IGNORE 0
102#define INAT_SEG_REG_DEFAULT 1
103#define INAT_SEG_REG_CS 2
104#define INAT_SEG_REG_SS 3
105#define INAT_SEG_REG_DS 4
106#define INAT_SEG_REG_ES 5
107#define INAT_SEG_REG_FS 6
108#define INAT_SEG_REG_GS 7
109
100/* Attribute search APIs */ 110/* Attribute search APIs */
101extern insn_attr_t inat_get_opcode_attribute(insn_byte_t opcode); 111extern insn_attr_t inat_get_opcode_attribute(insn_byte_t opcode);
102extern int inat_get_last_prefix_id(insn_byte_t last_pfx); 112extern int inat_get_last_prefix_id(insn_byte_t last_pfx);
diff --git a/tools/objtool/arch/x86/insn/inat_types.h b/tools/objtool/arch/x86/include/asm/inat_types.h
index cb3c20ce39cf..cb3c20ce39cf 100644
--- a/tools/objtool/arch/x86/insn/inat_types.h
+++ b/tools/objtool/arch/x86/include/asm/inat_types.h
diff --git a/tools/objtool/arch/x86/insn/insn.h b/tools/objtool/arch/x86/include/asm/insn.h
index e23578c7b1be..b3e32b010ab1 100644
--- a/tools/objtool/arch/x86/insn/insn.h
+++ b/tools/objtool/arch/x86/include/asm/insn.h
@@ -21,7 +21,7 @@
21 */ 21 */
22 22
23/* insn_attr_t is defined in inat.h */ 23/* insn_attr_t is defined in inat.h */
24#include "inat.h" 24#include <asm/inat.h>
25 25
26struct insn_field { 26struct insn_field {
27 union { 27 union {
diff --git a/tools/objtool/orc_types.h b/tools/objtool/arch/x86/include/asm/orc_types.h
index 9c9dc579bd7d..9c9dc579bd7d 100644
--- a/tools/objtool/orc_types.h
+++ b/tools/objtool/arch/x86/include/asm/orc_types.h
diff --git a/tools/objtool/arch/x86/insn/inat.c b/tools/objtool/arch/x86/lib/inat.c
index e4bf28e6f4c7..c1f01a8e9f65 100644
--- a/tools/objtool/arch/x86/insn/inat.c
+++ b/tools/objtool/arch/x86/lib/inat.c
@@ -18,7 +18,7 @@
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * 19 *
20 */ 20 */
21#include "insn.h" 21#include <asm/insn.h>
22 22
23/* Attribute tables are generated from opcode map */ 23/* Attribute tables are generated from opcode map */
24#include "inat-tables.c" 24#include "inat-tables.c"
diff --git a/tools/objtool/arch/x86/insn/insn.c b/tools/objtool/arch/x86/lib/insn.c
index ca983e2bea8b..1088eb8f3a5f 100644
--- a/tools/objtool/arch/x86/insn/insn.c
+++ b/tools/objtool/arch/x86/lib/insn.c
@@ -23,8 +23,8 @@
23#else 23#else
24#include <string.h> 24#include <string.h>
25#endif 25#endif
26#include "inat.h" 26#include <asm/inat.h>
27#include "insn.h" 27#include <asm/insn.h>
28 28
29/* Verify next sizeof(t) bytes can be on the same instruction */ 29/* Verify next sizeof(t) bytes can be on the same instruction */
30#define validate_next(t, insn, n) \ 30#define validate_next(t, insn, n) \
diff --git a/tools/objtool/arch/x86/insn/x86-opcode-map.txt b/tools/objtool/arch/x86/lib/x86-opcode-map.txt
index 12e377184ee4..12e377184ee4 100644
--- a/tools/objtool/arch/x86/insn/x86-opcode-map.txt
+++ b/tools/objtool/arch/x86/lib/x86-opcode-map.txt
diff --git a/tools/objtool/arch/x86/insn/gen-insn-attr-x86.awk b/tools/objtool/arch/x86/tools/gen-insn-attr-x86.awk
index a3d2c62fd805..b02a36b2c14f 100644
--- a/tools/objtool/arch/x86/insn/gen-insn-attr-x86.awk
+++ b/tools/objtool/arch/x86/tools/gen-insn-attr-x86.awk
@@ -1,4 +1,5 @@
1#!/bin/awk -f 1#!/bin/awk -f
2# SPDX-License-Identifier: GPL-2.0
2# gen-insn-attr-x86.awk: Instruction attribute table generator 3# gen-insn-attr-x86.awk: Instruction attribute table generator
3# Written by Masami Hiramatsu <mhiramat@redhat.com> 4# Written by Masami Hiramatsu <mhiramat@redhat.com>
4# 5#
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f744617c9946..9b341584eb1b 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -267,12 +267,13 @@ static int decode_instructions(struct objtool_file *file)
267 &insn->immediate, 267 &insn->immediate,
268 &insn->stack_op); 268 &insn->stack_op);
269 if (ret) 269 if (ret)
270 return ret; 270 goto err;
271 271
272 if (!insn->type || insn->type > INSN_LAST) { 272 if (!insn->type || insn->type > INSN_LAST) {
273 WARN_FUNC("invalid instruction type %d", 273 WARN_FUNC("invalid instruction type %d",
274 insn->sec, insn->offset, insn->type); 274 insn->sec, insn->offset, insn->type);
275 return -1; 275 ret = -1;
276 goto err;
276 } 277 }
277 278
278 hash_add(file->insn_hash, &insn->hash, insn->offset); 279 hash_add(file->insn_hash, &insn->hash, insn->offset);
@@ -296,6 +297,10 @@ static int decode_instructions(struct objtool_file *file)
296 } 297 }
297 298
298 return 0; 299 return 0;
300
301err:
302 free(insn);
303 return ret;
299} 304}
300 305
301/* 306/*
@@ -1203,24 +1208,39 @@ static int update_insn_state(struct instruction *insn, struct insn_state *state)
1203 switch (op->src.type) { 1208 switch (op->src.type) {
1204 1209
1205 case OP_SRC_REG: 1210 case OP_SRC_REG:
1206 if (op->src.reg == CFI_SP && op->dest.reg == CFI_BP) { 1211 if (op->src.reg == CFI_SP && op->dest.reg == CFI_BP &&
1212 cfa->base == CFI_SP &&
1213 regs[CFI_BP].base == CFI_CFA &&
1214 regs[CFI_BP].offset == -cfa->offset) {
1215
1216 /* mov %rsp, %rbp */
1217 cfa->base = op->dest.reg;
1218 state->bp_scratch = false;
1219 }
1207 1220
1208 if (cfa->base == CFI_SP && 1221 else if (op->src.reg == CFI_SP &&
1209 regs[CFI_BP].base == CFI_CFA && 1222 op->dest.reg == CFI_BP && state->drap) {
1210 regs[CFI_BP].offset == -cfa->offset) {
1211 1223
1212 /* mov %rsp, %rbp */ 1224 /* drap: mov %rsp, %rbp */
1213 cfa->base = op->dest.reg; 1225 regs[CFI_BP].base = CFI_BP;
1214 state->bp_scratch = false; 1226 regs[CFI_BP].offset = -state->stack_size;
1215 } 1227 state->bp_scratch = false;
1228 }
1216 1229
1217 else if (state->drap) { 1230 else if (op->src.reg == CFI_SP && cfa->base == CFI_SP) {
1218 1231
1219 /* drap: mov %rsp, %rbp */ 1232 /*
1220 regs[CFI_BP].base = CFI_BP; 1233 * mov %rsp, %reg
1221 regs[CFI_BP].offset = -state->stack_size; 1234 *
1222 state->bp_scratch = false; 1235 * This is needed for the rare case where GCC
1223 } 1236 * does:
1237 *
1238 * mov %rsp, %rax
1239 * ...
1240 * mov %rax, %rsp
1241 */
1242 state->vals[op->dest.reg].base = CFI_CFA;
1243 state->vals[op->dest.reg].offset = -state->stack_size;
1224 } 1244 }
1225 1245
1226 else if (op->dest.reg == cfa->base) { 1246 else if (op->dest.reg == cfa->base) {
@@ -1737,11 +1757,14 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
1737 if (insn->dead_end) 1757 if (insn->dead_end)
1738 return 0; 1758 return 0;
1739 1759
1740 insn = next_insn; 1760 if (!next_insn) {
1741 if (!insn) { 1761 if (state.cfa.base == CFI_UNDEFINED)
1762 return 0;
1742 WARN("%s: unexpected end of section", sec->name); 1763 WARN("%s: unexpected end of section", sec->name);
1743 return 1; 1764 return 1;
1744 } 1765 }
1766
1767 insn = next_insn;
1745 } 1768 }
1746 1769
1747 return 0; 1770 return 0;
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6e9f980a7d26..24460155c82c 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -175,19 +175,20 @@ static int read_sections(struct elf *elf)
175 return -1; 175 return -1;
176 } 176 }
177 177
178 sec->data = elf_getdata(s, NULL); 178 if (sec->sh.sh_size != 0) {
179 if (!sec->data) { 179 sec->data = elf_getdata(s, NULL);
180 WARN_ELF("elf_getdata"); 180 if (!sec->data) {
181 return -1; 181 WARN_ELF("elf_getdata");
182 } 182 return -1;
183 183 }
184 if (sec->data->d_off != 0 || 184 if (sec->data->d_off != 0 ||
185 sec->data->d_size != sec->sh.sh_size) { 185 sec->data->d_size != sec->sh.sh_size) {
186 WARN("unexpected data attributes for %s", sec->name); 186 WARN("unexpected data attributes for %s",
187 return -1; 187 sec->name);
188 return -1;
189 }
188 } 190 }
189 191 sec->len = sec->sh.sh_size;
190 sec->len = sec->data->d_size;
191 } 192 }
192 193
193 /* sanity check, one more call to elf_nextscn() should return NULL */ 194 /* sanity check, one more call to elf_nextscn() should return NULL */
@@ -508,6 +509,7 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *base)
508 strcat(relaname, base->name); 509 strcat(relaname, base->name);
509 510
510 sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); 511 sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0);
512 free(relaname);
511 if (!sec) 513 if (!sec)
512 return NULL; 514 return NULL;
513 515
@@ -561,6 +563,7 @@ int elf_write(struct elf *elf)
561 struct section *sec; 563 struct section *sec;
562 Elf_Scn *s; 564 Elf_Scn *s;
563 565
566 /* Update section headers for changed sections: */
564 list_for_each_entry(sec, &elf->sections, list) { 567 list_for_each_entry(sec, &elf->sections, list) {
565 if (sec->changed) { 568 if (sec->changed) {
566 s = elf_getscn(elf->elf, sec->idx); 569 s = elf_getscn(elf->elf, sec->idx);
@@ -568,13 +571,17 @@ int elf_write(struct elf *elf)
568 WARN_ELF("elf_getscn"); 571 WARN_ELF("elf_getscn");
569 return -1; 572 return -1;
570 } 573 }
571 if (!gelf_update_shdr (s, &sec->sh)) { 574 if (!gelf_update_shdr(s, &sec->sh)) {
572 WARN_ELF("gelf_update_shdr"); 575 WARN_ELF("gelf_update_shdr");
573 return -1; 576 return -1;
574 } 577 }
575 } 578 }
576 } 579 }
577 580
581 /* Make sure the new section header entries get updated properly. */
582 elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY);
583
584 /* Write all changes to the file. */
578 if (elf_update(elf->elf, ELF_C_WRITE) < 0) { 585 if (elf_update(elf->elf, ELF_C_WRITE) < 0) {
579 WARN_ELF("elf_update"); 586 WARN_ELF("elf_update");
580 return -1; 587 return -1;
diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c
index 31e0f9143840..07f329919828 100644
--- a/tools/objtool/objtool.c
+++ b/tools/objtool/objtool.c
@@ -70,7 +70,7 @@ static void cmd_usage(void)
70 70
71 printf("\n"); 71 printf("\n");
72 72
73 exit(1); 73 exit(129);
74} 74}
75 75
76static void handle_options(int *argc, const char ***argv) 76static void handle_options(int *argc, const char ***argv)
@@ -86,9 +86,7 @@ static void handle_options(int *argc, const char ***argv)
86 break; 86 break;
87 } else { 87 } else {
88 fprintf(stderr, "Unknown option: %s\n", cmd); 88 fprintf(stderr, "Unknown option: %s\n", cmd);
89 fprintf(stderr, "\n Usage: %s\n", 89 cmd_usage();
90 objtool_usage_string);
91 exit(1);
92 } 90 }
93 91
94 (*argv)++; 92 (*argv)++;
diff --git a/tools/objtool/orc.h b/tools/objtool/orc.h
index a4139e386ef3..b0e92a6d0903 100644
--- a/tools/objtool/orc.h
+++ b/tools/objtool/orc.h
@@ -18,7 +18,7 @@
18#ifndef _ORC_H 18#ifndef _ORC_H
19#define _ORC_H 19#define _ORC_H
20 20
21#include "orc_types.h" 21#include <asm/orc_types.h>
22 22
23struct objtool_file; 23struct objtool_file;
24 24
diff --git a/tools/objtool/sync-check.sh b/tools/objtool/sync-check.sh
new file mode 100755
index 000000000000..1470e74e9d66
--- /dev/null
+++ b/tools/objtool/sync-check.sh
@@ -0,0 +1,29 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3
4FILES='
5arch/x86/lib/insn.c
6arch/x86/lib/inat.c
7arch/x86/lib/x86-opcode-map.txt
8arch/x86/tools/gen-insn-attr-x86.awk
9arch/x86/include/asm/insn.h
10arch/x86/include/asm/inat.h
11arch/x86/include/asm/inat_types.h
12arch/x86/include/asm/orc_types.h
13'
14
15check()
16{
17 local file=$1
18
19 diff $file ../../$file > /dev/null ||
20 echo "Warning: synced file at 'tools/objtool/$file' differs from latest kernel version at '$file'"
21}
22
23if [ ! -d ../../kernel ] || [ ! -d ../../tools ] || [ ! -d ../objtool ]; then
24 exit 0
25fi
26
27for i in $FILES; do
28 check $i
29done
diff --git a/tools/pci/pcitest.sh b/tools/pci/pcitest.sh
index 5442bbea4c22..77e8c85ef744 100644
--- a/tools/pci/pcitest.sh
+++ b/tools/pci/pcitest.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3echo "BAR tests" 4echo "BAR tests"
4echo 5echo
diff --git a/tools/pcmcia/Makefile b/tools/pcmcia/Makefile
index 81a7498c5cd9..eae24df1dbf5 100644
--- a/tools/pcmcia/Makefile
+++ b/tools/pcmcia/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CC := $(CROSS_COMPILE)gcc 2CC := $(CROSS_COMPILE)gcc
2CFLAGS := -I../../usr/include 3CFLAGS := -I../../usr/include
3 4
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index f709de54707b..e2a897ae3596 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -8,7 +8,8 @@ perf-list - List all symbolic event types
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|sdt|event_glob] 11'perf list' [--no-desc] [--long-desc]
12 [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]
12 13
13DESCRIPTION 14DESCRIPTION
14----------- 15-----------
@@ -47,6 +48,8 @@ counted. The following modifiers exist:
47 P - use maximum detected precise level 48 P - use maximum detected precise level
48 S - read sample value (PERF_SAMPLE_READ) 49 S - read sample value (PERF_SAMPLE_READ)
49 D - pin the event to the PMU 50 D - pin the event to the PMU
51 W - group is weak and will fallback to non-group if not schedulable,
52 only supported in 'perf stat' for now.
50 53
51The 'p' modifier can be used for specifying how precise the instruction 54The 'p' modifier can be used for specifying how precise the instruction
52address should be. The 'p' modifier can be specified multiple times: 55address should be. The 'p' modifier can be specified multiple times:
@@ -201,7 +204,7 @@ For example Intel Core CPUs typically have four generic performance counters
201for the core, plus three fixed counters for instructions, cycles and 204for the core, plus three fixed counters for instructions, cycles and
202ref-cycles. Some special events have restrictions on which counter they 205ref-cycles. Some special events have restrictions on which counter they
203can schedule, and may not support multiple instances in a single group. 206can schedule, and may not support multiple instances in a single group.
204When too many events are specified in the group none of them will not 207When too many events are specified in the group some of them will not
205be measured. 208be measured.
206 209
207Globally pinned events can limit the number of counters available for 210Globally pinned events can limit the number of counters available for
@@ -246,6 +249,10 @@ To limit the list use:
246 249
247. 'sdt' to list all Statically Defined Tracepoint events. 250. 'sdt' to list all Statically Defined Tracepoint events.
248 251
252. 'metric' to list metrics
253
254. 'metricgroup' to list metricgroups with metrics.
255
249. If none of the above is matched, it will apply the supplied glob to all 256. If none of the above is matched, it will apply the supplied glob to all
250 events, printing the ones that match. 257 events, printing the ones that match.
251 258
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index e397453e5a46..5a626ef666c2 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -8,8 +8,8 @@ perf-record - Run a command and record its profile into perf.data
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf record' [-e <EVENT> | --event=EVENT] [-l] [-a] <command> 11'perf record' [-e <EVENT> | --event=EVENT] [-a] <command>
12'perf record' [-e <EVENT> | --event=EVENT] [-l] [-a] -- <command> [<options>] 12'perf record' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>]
13 13
14DESCRIPTION 14DESCRIPTION
15----------- 15-----------
@@ -377,6 +377,8 @@ symbolic names, e.g. on x86, ax, si. To list the available registers use
377--intr-regs=\?. To name registers, pass a comma separated list such as 377--intr-regs=\?. To name registers, pass a comma separated list such as
378--intr-regs=ax,bx. The list of register is architecture dependent. 378--intr-regs=ax,bx. The list of register is architecture dependent.
379 379
380--user-regs::
381Capture user registers at sample time. Same arguments as -I.
380 382
381--running-time:: 383--running-time::
382Record running and enabled time for read events (:S) 384Record running and enabled time for read events (:S)
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 383a98d992ed..ddde2b54af57 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -434,7 +434,8 @@ include::itrace.txt[]
434 434
435--inline:: 435--inline::
436 If a callgraph address belongs to an inlined function, the inline stack 436 If a callgraph address belongs to an inlined function, the inline stack
437 will be printed. Each entry is function name or file/line. 437 will be printed. Each entry is function name or file/line. Enabled by
438 default, disable with --no-inline.
438 439
439include::callchain-overhead-calculation.txt[] 440include::callchain-overhead-calculation.txt[]
440 441
diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index a092a2499e8f..55b67338548e 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -106,6 +106,14 @@ OPTIONS for 'perf sched timehist'
106--max-stack:: 106--max-stack::
107 Maximum number of functions to display in backtrace, default 5. 107 Maximum number of functions to display in backtrace, default 5.
108 108
109-p=::
110--pid=::
111 Only show events for given process ID (comma separated list).
112
113-t=::
114--tid=::
115 Only show events for given thread ID (comma separated list).
116
109-s:: 117-s::
110--summary:: 118--summary::
111 Show only a summary of scheduling by thread with min, max, and average 119 Show only a summary of scheduling by thread with min, max, and average
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 18dfcfa38454..2811fcf684cb 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -116,8 +116,8 @@ OPTIONS
116--fields:: 116--fields::
117 Comma separated list of fields to print. Options are: 117 Comma separated list of fields to print. Options are:
118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, 118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119 srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff, 119 srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn,
120 callindent, insn, insnlen, synth, phys_addr. 120 brstackoff, callindent, insn, insnlen, synth, phys_addr.
121 Field list can be prepended with the type, trace, sw or hw, 121 Field list can be prepended with the type, trace, sw or hw,
122 to indicate to which event type the field list applies. 122 to indicate to which event type the field list applies.
123 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace 123 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -325,9 +325,14 @@ include::itrace.txt[]
325 Set the maximum number of program blocks to print with brstackasm for 325 Set the maximum number of program blocks to print with brstackasm for
326 each sample. 326 each sample.
327 327
328--per-event-dump::
329 Create per event files with a "perf.data.EVENT.dump" name instead of
330 printing to stdout, useful, for instance, for generating flamegraphs.
331
328--inline:: 332--inline::
329 If a callgraph address belongs to an inlined function, the inline stack 333 If a callgraph address belongs to an inlined function, the inline stack
330 will be printed. Each entry has function name and file/line. 334 will be printed. Each entry has function name and file/line. Enabled by
335 default, disable with --no-inline.
331 336
332SEE ALSO 337SEE ALSO
333-------- 338--------
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index c37d61682dfb..823fce7674bb 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -199,6 +199,13 @@ Aggregate counts per processor socket for system-wide mode measurements.
199--per-core:: 199--per-core::
200Aggregate counts per physical processor for system-wide mode measurements. 200Aggregate counts per physical processor for system-wide mode measurements.
201 201
202-M::
203--metrics::
204Print metrics or metricgroups specified in a comma separated list.
205For a group all metrics from the group are added.
206The events from the metrics are automatically measured.
207See perf list output for the possble metrics and metricgroups.
208
202-A:: 209-A::
203--no-aggr:: 210--no-aggr::
204Do not aggregate counts across all monitored CPUs. 211Do not aggregate counts across all monitored CPUs.
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index d864ea6fd367..4353262bc462 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -240,6 +240,9 @@ Default is to monitor all CPUS.
240--force:: 240--force::
241 Don't do ownership validation. 241 Don't do ownership validation.
242 242
243--num-thread-synthesize::
244 The number of threads to run when synthesizing events for existing processes.
245 By default, the number of threads equals to the number of online CPUs.
243 246
244INTERACTIVE PROMPTING KEYS 247INTERACTIVE PROMPTING KEYS
245-------------------------- 248--------------------------
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 62072822dc85..627b7cada144 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -1,34 +1,8 @@
1tools/perf 1tools/perf
2tools/arch/alpha/include/asm/barrier.h 2tools/arch
3tools/arch/arm/include/asm/barrier.h
4tools/arch/arm64/include/asm/barrier.h
5tools/arch/ia64/include/asm/barrier.h
6tools/arch/mips/include/asm/barrier.h
7tools/arch/powerpc/include/asm/barrier.h
8tools/arch/s390/include/asm/barrier.h
9tools/arch/sh/include/asm/barrier.h
10tools/arch/sparc/include/asm/barrier.h
11tools/arch/sparc/include/asm/barrier_32.h
12tools/arch/sparc/include/asm/barrier_64.h
13tools/arch/tile/include/asm/barrier.h
14tools/arch/x86/include/asm/barrier.h
15tools/arch/x86/include/asm/cmpxchg.h
16tools/arch/x86/include/asm/cpufeatures.h
17tools/arch/x86/include/asm/disabled-features.h
18tools/arch/x86/include/asm/required-features.h
19tools/arch/x86/include/uapi/asm/svm.h
20tools/arch/x86/include/uapi/asm/vmx.h
21tools/arch/x86/include/uapi/asm/kvm.h
22tools/arch/x86/include/uapi/asm/kvm_perf.h
23tools/arch/x86/lib/memcpy_64.S
24tools/arch/x86/lib/memset_64.S
25tools/arch/s390/include/uapi/asm/kvm_perf.h
26tools/arch/s390/include/uapi/asm/sie.h
27tools/arch/xtensa/include/asm/barrier.h
28tools/scripts 3tools/scripts
29tools/build 4tools/build
30tools/arch/x86/include/asm/atomic.h 5tools/include
31tools/arch/x86/include/asm/rmwcc.h
32tools/lib/traceevent 6tools/lib/traceevent
33tools/lib/api 7tools/lib/api
34tools/lib/bpf 8tools/lib/bpf
@@ -42,60 +16,3 @@ tools/lib/find_bit.c
42tools/lib/bitmap.c 16tools/lib/bitmap.c
43tools/lib/str_error_r.c 17tools/lib/str_error_r.c
44tools/lib/vsprintf.c 18tools/lib/vsprintf.c
45tools/include/asm/alternative-asm.h
46tools/include/asm/atomic.h
47tools/include/asm/barrier.h
48tools/include/asm/bug.h
49tools/include/asm-generic/atomic-gcc.h
50tools/include/asm-generic/barrier.h
51tools/include/asm-generic/bitops/arch_hweight.h
52tools/include/asm-generic/bitops/atomic.h
53tools/include/asm-generic/bitops/const_hweight.h
54tools/include/asm-generic/bitops/__ffs.h
55tools/include/asm-generic/bitops/__ffz.h
56tools/include/asm-generic/bitops/__fls.h
57tools/include/asm-generic/bitops/find.h
58tools/include/asm-generic/bitops/fls64.h
59tools/include/asm-generic/bitops/fls.h
60tools/include/asm-generic/bitops/hweight.h
61tools/include/asm-generic/bitops.h
62tools/include/linux/atomic.h
63tools/include/linux/bitops.h
64tools/include/linux/compiler.h
65tools/include/linux/compiler-gcc.h
66tools/include/linux/coresight-pmu.h
67tools/include/linux/bug.h
68tools/include/linux/filter.h
69tools/include/linux/hash.h
70tools/include/linux/kernel.h
71tools/include/linux/list.h
72tools/include/linux/log2.h
73tools/include/uapi/asm-generic/fcntl.h
74tools/include/uapi/asm-generic/ioctls.h
75tools/include/uapi/asm-generic/mman-common.h
76tools/include/uapi/asm-generic/mman.h
77tools/include/uapi/drm/drm.h
78tools/include/uapi/drm/i915_drm.h
79tools/include/uapi/linux/bpf.h
80tools/include/uapi/linux/bpf_common.h
81tools/include/uapi/linux/fcntl.h
82tools/include/uapi/linux/hw_breakpoint.h
83tools/include/uapi/linux/kvm.h
84tools/include/uapi/linux/mman.h
85tools/include/uapi/linux/perf_event.h
86tools/include/uapi/linux/sched.h
87tools/include/uapi/linux/stat.h
88tools/include/uapi/linux/vhost.h
89tools/include/uapi/sound/asound.h
90tools/include/linux/poison.h
91tools/include/linux/rbtree.h
92tools/include/linux/rbtree_augmented.h
93tools/include/linux/refcount.h
94tools/include/linux/string.h
95tools/include/linux/stringify.h
96tools/include/linux/types.h
97tools/include/linux/err.h
98tools/include/linux/bitmap.h
99tools/include/linux/time64.h
100tools/arch/*/include/uapi/asm/mman.h
101tools/arch/*/include/uapi/asm/perf_regs.h
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 32a64e619028..225454416ed5 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# 2#
2# This is a simple wrapper Makefile that calls the main Makefile.perf 3# This is a simple wrapper Makefile that calls the main Makefile.perf
3# with a -j option to do parallel builds 4# with a -j option to do parallel builds
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 63f534a0902f..ed65e82f034e 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -53,6 +53,10 @@ ifeq ($(SRCARCH),arm64)
53 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 53 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
54endif 54endif
55 55
56ifeq ($(ARCH),s390)
57 NO_PERF_REGS := 0
58endif
59
56ifeq ($(NO_PERF_REGS),0) 60ifeq ($(NO_PERF_REGS),0)
57 $(call detected,CONFIG_PERF_REGS) 61 $(call detected,CONFIG_PERF_REGS)
58endif 62endif
@@ -61,7 +65,7 @@ endif
61# Disable it on all other architectures in case libdw unwind 65# Disable it on all other architectures in case libdw unwind
62# support is detected in system. Add supported architectures 66# support is detected in system. Add supported architectures
63# to the check. 67# to the check.
64ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm powerpc)) 68ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm powerpc s390))
65 NO_LIBDW_DWARF_UNWIND := 1 69 NO_LIBDW_DWARF_UNWIND := 1
66endif 70endif
67 71
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 91ef44bfaf3e..68cf1360a3f3 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -173,7 +173,7 @@ AWK = awk
173# non-config cases 173# non-config cases
174config := 1 174config := 1
175 175
176NON_CONFIG_TARGETS := clean TAGS tags cscope help install-doc install-man install-html install-info install-pdf doc man html info pdf 176NON_CONFIG_TARGETS := clean python-clean TAGS tags cscope help install-doc install-man install-html install-info install-pdf doc man html info pdf
177 177
178ifdef MAKECMDGOALS 178ifdef MAKECMDGOALS
179ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),) 179ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
@@ -420,6 +420,13 @@ sndrv_pcm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/sndrv_pcm_ioctl.sh
420$(sndrv_pcm_ioctl_array): $(sndrv_pcm_hdr_dir)/asound.h $(sndrv_pcm_ioctl_tbl) 420$(sndrv_pcm_ioctl_array): $(sndrv_pcm_hdr_dir)/asound.h $(sndrv_pcm_ioctl_tbl)
421 $(Q)$(SHELL) '$(sndrv_pcm_ioctl_tbl)' $(sndrv_pcm_hdr_dir) > $@ 421 $(Q)$(SHELL) '$(sndrv_pcm_ioctl_tbl)' $(sndrv_pcm_hdr_dir) > $@
422 422
423kcmp_type_array := $(beauty_outdir)/kcmp_type_array.c
424kcmp_hdr_dir := $(srctree)/tools/include/uapi/linux/
425kcmp_type_tbl := $(srctree)/tools/perf/trace/beauty/kcmp_type.sh
426
427$(kcmp_type_array): $(kcmp_hdr_dir)/kcmp.h $(kcmp_type_tbl)
428 $(Q)$(SHELL) '$(kcmp_type_tbl)' $(kcmp_hdr_dir) > $@
429
423kvm_ioctl_array := $(beauty_ioctl_outdir)/kvm_ioctl_array.c 430kvm_ioctl_array := $(beauty_ioctl_outdir)/kvm_ioctl_array.c
424kvm_hdr_dir := $(srctree)/tools/include/uapi/linux 431kvm_hdr_dir := $(srctree)/tools/include/uapi/linux
425kvm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/kvm_ioctl.sh 432kvm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/kvm_ioctl.sh
@@ -441,6 +448,20 @@ perf_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/perf_ioctl.sh
441$(perf_ioctl_array): $(perf_hdr_dir)/perf_event.h $(perf_ioctl_tbl) 448$(perf_ioctl_array): $(perf_hdr_dir)/perf_event.h $(perf_ioctl_tbl)
442 $(Q)$(SHELL) '$(perf_ioctl_tbl)' $(perf_hdr_dir) > $@ 449 $(Q)$(SHELL) '$(perf_ioctl_tbl)' $(perf_hdr_dir) > $@
443 450
451madvise_behavior_array := $(beauty_outdir)/madvise_behavior_array.c
452madvise_hdr_dir := $(srctree)/tools/include/uapi/asm-generic/
453madvise_behavior_tbl := $(srctree)/tools/perf/trace/beauty/madvise_behavior.sh
454
455$(madvise_behavior_array): $(madvise_hdr_dir)/mman-common.h $(madvise_behavior_tbl)
456 $(Q)$(SHELL) '$(madvise_behavior_tbl)' $(madvise_hdr_dir) > $@
457
458prctl_option_array := $(beauty_outdir)/prctl_option_array.c
459prctl_hdr_dir := $(srctree)/tools/include/uapi/linux/
460prctl_option_tbl := $(srctree)/tools/perf/trace/beauty/prctl_option.sh
461
462$(prctl_option_array): $(prctl_hdr_dir)/prctl.h $(prctl_option_tbl)
463 $(Q)$(SHELL) '$(prctl_option_tbl)' $(prctl_hdr_dir) > $@
464
444all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) 465all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
445 466
446$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) $(LIBTRACEEVENT_DYNAMIC_LIST) 467$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) $(LIBTRACEEVENT_DYNAMIC_LIST)
@@ -539,9 +560,12 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc
539 $(pkey_alloc_access_rights_array) \ 560 $(pkey_alloc_access_rights_array) \
540 $(sndrv_pcm_ioctl_array) \ 561 $(sndrv_pcm_ioctl_array) \
541 $(sndrv_ctl_ioctl_array) \ 562 $(sndrv_ctl_ioctl_array) \
563 $(kcmp_type_array) \
542 $(kvm_ioctl_array) \ 564 $(kvm_ioctl_array) \
543 $(vhost_virtio_ioctl_array) \ 565 $(vhost_virtio_ioctl_array) \
544 $(perf_ioctl_array) 566 $(madvise_behavior_array) \
567 $(perf_ioctl_array) \
568 $(prctl_option_array)
545 569
546$(OUTPUT)%.o: %.c prepare FORCE 570$(OUTPUT)%.o: %.c prepare FORCE
547 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@ 571 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
@@ -802,7 +826,10 @@ config-clean:
802 $(call QUIET_CLEAN, config) 826 $(call QUIET_CLEAN, config)
803 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null 827 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
804 828
805clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean fixdep-clean 829python-clean:
830 $(python-clean)
831
832clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean fixdep-clean python-clean
806 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) 833 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
807 $(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 834 $(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
808 $(Q)$(RM) $(OUTPUT).config-detected 835 $(Q)$(RM) $(OUTPUT).config-detected
@@ -811,15 +838,17 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea
811 $(OUTPUT)util/intel-pt-decoder/inat-tables.c \ 838 $(OUTPUT)util/intel-pt-decoder/inat-tables.c \
812 $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c \ 839 $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c \
813 $(OUTPUT)pmu-events/pmu-events.c \ 840 $(OUTPUT)pmu-events/pmu-events.c \
841 $(OUTPUT)$(madvise_behavior_array) \
814 $(OUTPUT)$(drm_ioctl_array) \ 842 $(OUTPUT)$(drm_ioctl_array) \
815 $(OUTPUT)$(pkey_alloc_access_rights_array) \ 843 $(OUTPUT)$(pkey_alloc_access_rights_array) \
816 $(OUTPUT)$(sndrv_ctl_ioctl_array) \ 844 $(OUTPUT)$(sndrv_ctl_ioctl_array) \
817 $(OUTPUT)$(sndrv_pcm_ioctl_array) \ 845 $(OUTPUT)$(sndrv_pcm_ioctl_array) \
818 $(OUTPUT)$(kvm_ioctl_array) \ 846 $(OUTPUT)$(kvm_ioctl_array) \
847 $(OUTPUT)$(kcmp_type_array) \
819 $(OUTPUT)$(vhost_virtio_ioctl_array) \ 848 $(OUTPUT)$(vhost_virtio_ioctl_array) \
820 $(OUTPUT)$(perf_ioctl_array) 849 $(OUTPUT)$(perf_ioctl_array) \
850 $(OUTPUT)$(prctl_option_array)
821 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean 851 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
822 $(python-clean)
823 852
824# 853#
825# To provide FEATURE-DUMP into $(FEATURE_DUMP_COPY) 854# To provide FEATURE-DUMP into $(FEATURE_DUMP_COPY)
diff --git a/tools/perf/arch/arm/annotate/instructions.c b/tools/perf/arch/arm/annotate/instructions.c
index 1ce0872b1726..f64516d5b23e 100644
--- a/tools/perf/arch/arm/annotate/instructions.c
+++ b/tools/perf/arch/arm/annotate/instructions.c
@@ -1,3 +1,5 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/compiler.h>
1#include <sys/types.h> 3#include <sys/types.h>
2#include <regex.h> 4#include <regex.h>
3 5
@@ -23,7 +25,7 @@ static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, const c
23 return ops; 25 return ops;
24} 26}
25 27
26static int arm__annotate_init(struct arch *arch) 28static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
27{ 29{
28 struct arm_annotate *arm; 30 struct arm_annotate *arm;
29 int err; 31 int err;
diff --git a/tools/perf/arch/arm/include/dwarf-regs-table.h b/tools/perf/arch/arm/include/dwarf-regs-table.h
index f298d034c37b..5a45046fab72 100644
--- a/tools/perf/arch/arm/include/dwarf-regs-table.h
+++ b/tools/perf/arch/arm/include/dwarf-regs-table.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef DEFINE_DWARF_REGSTR_TABLE 2#ifdef DEFINE_DWARF_REGSTR_TABLE
2/* This is included in perf/util/dwarf-regs.c */ 3/* This is included in perf/util/dwarf-regs.c */
3 4
diff --git a/tools/perf/arch/arm/include/perf_regs.h b/tools/perf/arch/arm/include/perf_regs.h
index f619c9c5a4bf..ed20e0253e25 100644
--- a/tools/perf/arch/arm/include/perf_regs.h
+++ b/tools/perf/arch/arm/include/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_PERF_REGS_H 2#ifndef ARCH_PERF_REGS_H
2#define ARCH_PERF_REGS_H 3#define ARCH_PERF_REGS_H
3 4
diff --git a/tools/perf/arch/arm/tests/dwarf-unwind.c b/tools/perf/arch/arm/tests/dwarf-unwind.c
index 62eff847f91c..8cb347760233 100644
--- a/tools/perf/arch/arm/tests/dwarf-unwind.c
+++ b/tools/perf/arch/arm/tests/dwarf-unwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include "perf_regs.h" 3#include "perf_regs.h"
3#include "thread.h" 4#include "thread.h"
diff --git a/tools/perf/arch/arm/tests/regs_load.S b/tools/perf/arch/arm/tests/regs_load.S
index e09e983946fe..6e2495cc4517 100644
--- a/tools/perf/arch/arm/tests/regs_load.S
+++ b/tools/perf/arch/arm/tests/regs_load.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <linux/linkage.h> 2#include <linux/linkage.h>
2 3
3#define R0 0x00 4#define R0 0x00
diff --git a/tools/perf/arch/arm/util/unwind-libdw.c b/tools/perf/arch/arm/util/unwind-libdw.c
index bacfa00fca39..36ba4c69c3c5 100644
--- a/tools/perf/arch/arm/util/unwind-libdw.c
+++ b/tools/perf/arch/arm/util/unwind-libdw.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <elfutils/libdwfl.h> 2#include <elfutils/libdwfl.h>
2#include "../../util/unwind-libdw.h" 3#include "../../util/unwind-libdw.h"
3#include "../../util/perf_regs.h" 4#include "../../util/perf_regs.h"
diff --git a/tools/perf/arch/arm/util/unwind-libunwind.c b/tools/perf/arch/arm/util/unwind-libunwind.c
index 62c397ed3d97..3a550225dfaf 100644
--- a/tools/perf/arch/arm/util/unwind-libunwind.c
+++ b/tools/perf/arch/arm/util/unwind-libunwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2#include <errno.h> 3#include <errno.h>
3#include <libunwind.h> 4#include <libunwind.h>
diff --git a/tools/perf/arch/arm64/Makefile b/tools/perf/arch/arm64/Makefile
index eebe1ec9d2ee..91de4860faad 100644
--- a/tools/perf/arch/arm64/Makefile
+++ b/tools/perf/arch/arm64/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ifndef NO_DWARF 2ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 3PERF_HAVE_DWARF_REGS := 1
3endif 4endif
diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arch/arm64/annotate/instructions.c
index 8f1908756cb6..6688977e4ac7 100644
--- a/tools/perf/arch/arm64/annotate/instructions.c
+++ b/tools/perf/arch/arm64/annotate/instructions.c
@@ -1,3 +1,5 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/compiler.h>
1#include <sys/types.h> 3#include <sys/types.h>
2#include <regex.h> 4#include <regex.h>
3 5
@@ -25,7 +27,7 @@ static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const
25 return ops; 27 return ops;
26} 28}
27 29
28static int arm64__annotate_init(struct arch *arch) 30static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
29{ 31{
30 struct arm64_annotate *arm; 32 struct arm64_annotate *arm;
31 int err; 33 int err;
diff --git a/tools/perf/arch/arm64/include/dwarf-regs-table.h b/tools/perf/arch/arm64/include/dwarf-regs-table.h
index 36e375f5a211..177b2855f797 100644
--- a/tools/perf/arch/arm64/include/dwarf-regs-table.h
+++ b/tools/perf/arch/arm64/include/dwarf-regs-table.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef DEFINE_DWARF_REGSTR_TABLE 2#ifdef DEFINE_DWARF_REGSTR_TABLE
2/* This is included in perf/util/dwarf-regs.c */ 3/* This is included in perf/util/dwarf-regs.c */
3 4
diff --git a/tools/perf/arch/arm64/include/perf_regs.h b/tools/perf/arch/arm64/include/perf_regs.h
index 4e5af27e3fbf..baaa5e64a3fb 100644
--- a/tools/perf/arch/arm64/include/perf_regs.h
+++ b/tools/perf/arch/arm64/include/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_PERF_REGS_H 2#ifndef ARCH_PERF_REGS_H
2#define ARCH_PERF_REGS_H 3#define ARCH_PERF_REGS_H
3 4
diff --git a/tools/perf/arch/arm64/tests/dwarf-unwind.c b/tools/perf/arch/arm64/tests/dwarf-unwind.c
index cf04a4c91c59..e907f0f4c20c 100644
--- a/tools/perf/arch/arm64/tests/dwarf-unwind.c
+++ b/tools/perf/arch/arm64/tests/dwarf-unwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include "perf_regs.h" 3#include "perf_regs.h"
3#include "thread.h" 4#include "thread.h"
diff --git a/tools/perf/arch/arm64/tests/regs_load.S b/tools/perf/arch/arm64/tests/regs_load.S
index 025b46e579a6..07042511dca9 100644
--- a/tools/perf/arch/arm64/tests/regs_load.S
+++ b/tools/perf/arch/arm64/tests/regs_load.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <linux/linkage.h> 2#include <linux/linkage.h>
2 3
3.text 4.text
diff --git a/tools/perf/arch/arm64/util/unwind-libunwind.c b/tools/perf/arch/arm64/util/unwind-libunwind.c
index b415dfdbccca..002520d4036b 100644
--- a/tools/perf/arch/arm64/util/unwind-libunwind.c
+++ b/tools/perf/arch/arm64/util/unwind-libunwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2 3
3#ifndef REMOTE_UNWIND_LIBUNWIND 4#ifndef REMOTE_UNWIND_LIBUNWIND
diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index 6b40e9f01740..8c0cfeb55f8e 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <sys/utsname.h> 3#include <sys/utsname.h>
3#include "common.h" 4#include "common.h"
diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h
index 6b01c736b7d9..a1546509ad24 100644
--- a/tools/perf/arch/common.h
+++ b/tools/perf/arch/common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_PERF_COMMON_H 2#ifndef ARCH_PERF_COMMON_H
2#define ARCH_PERF_COMMON_H 3#define ARCH_PERF_COMMON_H
3 4
diff --git a/tools/perf/arch/powerpc/Makefile b/tools/perf/arch/powerpc/Makefile
index cc3930904d68..42dab7c8f508 100644
--- a/tools/perf/arch/powerpc/Makefile
+++ b/tools/perf/arch/powerpc/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ifndef NO_DWARF 2ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 3PERF_HAVE_DWARF_REGS := 1
3endif 4endif
diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/arch/powerpc/annotate/instructions.c
index 3c4004db81b9..a3f423c27cae 100644
--- a/tools/perf/arch/powerpc/annotate/instructions.c
+++ b/tools/perf/arch/powerpc/annotate/instructions.c
@@ -1,3 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/compiler.h>
3
1static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, const char *name) 4static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, const char *name)
2{ 5{
3 int i; 6 int i;
@@ -46,7 +49,7 @@ static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, con
46 return ops; 49 return ops;
47} 50}
48 51
49static int powerpc__annotate_init(struct arch *arch) 52static int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
50{ 53{
51 if (!arch->initialized) { 54 if (!arch->initialized) {
52 arch->initialized = true; 55 arch->initialized = true;
diff --git a/tools/perf/arch/powerpc/include/arch-tests.h b/tools/perf/arch/powerpc/include/arch-tests.h
index 84d8dedef2ed..1c7be75cbc78 100644
--- a/tools/perf/arch/powerpc/include/arch-tests.h
+++ b/tools/perf/arch/powerpc/include/arch-tests.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_TESTS_H 2#ifndef ARCH_TESTS_H
2#define ARCH_TESTS_H 3#define ARCH_TESTS_H
3 4
diff --git a/tools/perf/arch/powerpc/include/dwarf-regs-table.h b/tools/perf/arch/powerpc/include/dwarf-regs-table.h
index db4730f5585c..66dc015a733d 100644
--- a/tools/perf/arch/powerpc/include/dwarf-regs-table.h
+++ b/tools/perf/arch/powerpc/include/dwarf-regs-table.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef DEFINE_DWARF_REGSTR_TABLE 2#ifdef DEFINE_DWARF_REGSTR_TABLE
2/* This is included in perf/util/dwarf-regs.c */ 3/* This is included in perf/util/dwarf-regs.c */
3 4
diff --git a/tools/perf/arch/powerpc/include/perf_regs.h b/tools/perf/arch/powerpc/include/perf_regs.h
index c12f4e804f66..00e37b106913 100644
--- a/tools/perf/arch/powerpc/include/perf_regs.h
+++ b/tools/perf/arch/powerpc/include/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_PERF_REGS_H 2#ifndef ARCH_PERF_REGS_H
2#define ARCH_PERF_REGS_H 3#define ARCH_PERF_REGS_H
3 4
diff --git a/tools/perf/arch/powerpc/tests/arch-tests.c b/tools/perf/arch/powerpc/tests/arch-tests.c
index e24f46241f40..8c3fbd4af817 100644
--- a/tools/perf/arch/powerpc/tests/arch-tests.c
+++ b/tools/perf/arch/powerpc/tests/arch-tests.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include "tests/tests.h" 3#include "tests/tests.h"
3#include "arch-tests.h" 4#include "arch-tests.h"
diff --git a/tools/perf/arch/powerpc/tests/dwarf-unwind.c b/tools/perf/arch/powerpc/tests/dwarf-unwind.c
index 0bac3137ccbd..30cbbd6d5be0 100644
--- a/tools/perf/arch/powerpc/tests/dwarf-unwind.c
+++ b/tools/perf/arch/powerpc/tests/dwarf-unwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include "perf_regs.h" 3#include "perf_regs.h"
3#include "thread.h" 4#include "thread.h"
diff --git a/tools/perf/arch/powerpc/tests/regs_load.S b/tools/perf/arch/powerpc/tests/regs_load.S
index d76c9a32f327..36a20b0033f9 100644
--- a/tools/perf/arch/powerpc/tests/regs_load.S
+++ b/tools/perf/arch/powerpc/tests/regs_load.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <linux/linkage.h> 2#include <linux/linkage.h>
2 3
3/* Offset is based on macros from arch/powerpc/include/uapi/asm/ptrace.h. */ 4/* Offset is based on macros from arch/powerpc/include/uapi/asm/ptrace.h. */
diff --git a/tools/perf/arch/powerpc/util/book3s_hcalls.h b/tools/perf/arch/powerpc/util/book3s_hcalls.h
index 0dd6b7f2d44f..54cfa0530e86 100644
--- a/tools/perf/arch/powerpc/util/book3s_hcalls.h
+++ b/tools/perf/arch/powerpc/util/book3s_hcalls.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_PERF_BOOK3S_HV_HCALLS_H 2#ifndef ARCH_PERF_BOOK3S_HV_HCALLS_H
2#define ARCH_PERF_BOOK3S_HV_HCALLS_H 3#define ARCH_PERF_BOOK3S_HV_HCALLS_H
3 4
diff --git a/tools/perf/arch/powerpc/util/book3s_hv_exits.h b/tools/perf/arch/powerpc/util/book3s_hv_exits.h
index e68ba2da8970..853b95d1e139 100644
--- a/tools/perf/arch/powerpc/util/book3s_hv_exits.h
+++ b/tools/perf/arch/powerpc/util/book3s_hv_exits.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_PERF_BOOK3S_HV_EXITS_H 2#ifndef ARCH_PERF_BOOK3S_HV_EXITS_H
2#define ARCH_PERF_BOOK3S_HV_EXITS_H 3#define ARCH_PERF_BOOK3S_HV_EXITS_H
3 4
diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c
index 9aaa6f5a9347..7a4cf80c207a 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c
index 249723f0e6a9..596ad6aedaac 100644
--- a/tools/perf/arch/powerpc/util/kvm-stat.c
+++ b/tools/perf/arch/powerpc/util/kvm-stat.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include "util/kvm-stat.h" 3#include "util/kvm-stat.h"
3#include "util/parse-events.h" 4#include "util/parse-events.h"
diff --git a/tools/perf/arch/powerpc/util/perf_regs.c b/tools/perf/arch/powerpc/util/perf_regs.c
index f860dc411f69..ec50939b0418 100644
--- a/tools/perf/arch/powerpc/util/perf_regs.c
+++ b/tools/perf/arch/powerpc/util/perf_regs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <string.h> 3#include <string.h>
3#include <regex.h> 4#include <regex.h>
diff --git a/tools/perf/arch/powerpc/util/unwind-libdw.c b/tools/perf/arch/powerpc/util/unwind-libdw.c
index 3a24b3c43273..7a1f05ef2fc0 100644
--- a/tools/perf/arch/powerpc/util/unwind-libdw.c
+++ b/tools/perf/arch/powerpc/util/unwind-libdw.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <elfutils/libdwfl.h> 2#include <elfutils/libdwfl.h>
2#include "../../util/unwind-libdw.h" 3#include "../../util/unwind-libdw.h"
3#include "../../util/perf_regs.h" 4#include "../../util/perf_regs.h"
diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch/s390/annotate/instructions.c
index 745b4b1b8b21..e0e466c650df 100644
--- a/tools/perf/arch/s390/annotate/instructions.c
+++ b/tools/perf/arch/s390/annotate/instructions.c
@@ -1,3 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/compiler.h>
3
1static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *name) 4static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *name)
2{ 5{
3 struct ins_ops *ops = NULL; 6 struct ins_ops *ops = NULL;
@@ -19,7 +22,7 @@ static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *na
19 return ops; 22 return ops;
20} 23}
21 24
22static int s390__annotate_init(struct arch *arch) 25static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
23{ 26{
24 if (!arch->initialized) { 27 if (!arch->initialized) {
25 arch->initialized = true; 28 arch->initialized = true;
diff --git a/tools/perf/arch/s390/include/dwarf-regs-table.h b/tools/perf/arch/s390/include/dwarf-regs-table.h
index 9da74a933bd6..671553525f41 100644
--- a/tools/perf/arch/s390/include/dwarf-regs-table.h
+++ b/tools/perf/arch/s390/include/dwarf-regs-table.h
@@ -1,8 +1,72 @@
1#ifdef DEFINE_DWARF_REGSTR_TABLE 1/* SPDX-License-Identifier: GPL-2.0 */
2/* This is included in perf/util/dwarf-regs.c */ 2#ifndef S390_DWARF_REGS_TABLE_H
3#define S390_DWARF_REGS_TABLE_H
3 4
4static const char * const s390_regstr_tbl[] = { 5#define REG_DWARFNUM_NAME(reg, idx) [idx] = "%" #reg
6
7/*
8 * For reference, see DWARF register mapping:
9 * http://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_s390/x1542.html
10 */
11static const char * const s390_dwarf_regs[] = {
5 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", 12 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
6 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", 13 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
14 REG_DWARFNUM_NAME(f0, 16),
15 REG_DWARFNUM_NAME(f1, 20),
16 REG_DWARFNUM_NAME(f2, 17),
17 REG_DWARFNUM_NAME(f3, 21),
18 REG_DWARFNUM_NAME(f4, 18),
19 REG_DWARFNUM_NAME(f5, 22),
20 REG_DWARFNUM_NAME(f6, 19),
21 REG_DWARFNUM_NAME(f7, 23),
22 REG_DWARFNUM_NAME(f8, 24),
23 REG_DWARFNUM_NAME(f9, 28),
24 REG_DWARFNUM_NAME(f10, 25),
25 REG_DWARFNUM_NAME(f11, 29),
26 REG_DWARFNUM_NAME(f12, 26),
27 REG_DWARFNUM_NAME(f13, 30),
28 REG_DWARFNUM_NAME(f14, 27),
29 REG_DWARFNUM_NAME(f15, 31),
30 REG_DWARFNUM_NAME(c0, 32),
31 REG_DWARFNUM_NAME(c1, 33),
32 REG_DWARFNUM_NAME(c2, 34),
33 REG_DWARFNUM_NAME(c3, 35),
34 REG_DWARFNUM_NAME(c4, 36),
35 REG_DWARFNUM_NAME(c5, 37),
36 REG_DWARFNUM_NAME(c6, 38),
37 REG_DWARFNUM_NAME(c7, 39),
38 REG_DWARFNUM_NAME(c8, 40),
39 REG_DWARFNUM_NAME(c9, 41),
40 REG_DWARFNUM_NAME(c10, 42),
41 REG_DWARFNUM_NAME(c11, 43),
42 REG_DWARFNUM_NAME(c12, 44),
43 REG_DWARFNUM_NAME(c13, 45),
44 REG_DWARFNUM_NAME(c14, 46),
45 REG_DWARFNUM_NAME(c15, 47),
46 REG_DWARFNUM_NAME(a0, 48),
47 REG_DWARFNUM_NAME(a1, 49),
48 REG_DWARFNUM_NAME(a2, 50),
49 REG_DWARFNUM_NAME(a3, 51),
50 REG_DWARFNUM_NAME(a4, 52),
51 REG_DWARFNUM_NAME(a5, 53),
52 REG_DWARFNUM_NAME(a6, 54),
53 REG_DWARFNUM_NAME(a7, 55),
54 REG_DWARFNUM_NAME(a8, 56),
55 REG_DWARFNUM_NAME(a9, 57),
56 REG_DWARFNUM_NAME(a10, 58),
57 REG_DWARFNUM_NAME(a11, 59),
58 REG_DWARFNUM_NAME(a12, 60),
59 REG_DWARFNUM_NAME(a13, 61),
60 REG_DWARFNUM_NAME(a14, 62),
61 REG_DWARFNUM_NAME(a15, 63),
62 REG_DWARFNUM_NAME(pswm, 64),
63 REG_DWARFNUM_NAME(pswa, 65),
7}; 64};
8#endif 65
66#ifdef DEFINE_DWARF_REGSTR_TABLE
67/* This is included in perf/util/dwarf-regs.c */
68
69#define s390_regstr_tbl s390_dwarf_regs
70
71#endif /* DEFINE_DWARF_REGSTR_TABLE */
72#endif /* S390_DWARF_REGS_TABLE_H */
diff --git a/tools/perf/arch/s390/include/perf_regs.h b/tools/perf/arch/s390/include/perf_regs.h
new file mode 100644
index 000000000000..d2df54a6bc5a
--- /dev/null
+++ b/tools/perf/arch/s390/include/perf_regs.h
@@ -0,0 +1,95 @@
1#ifndef ARCH_PERF_REGS_H
2#define ARCH_PERF_REGS_H
3
4#include <stdlib.h>
5#include <linux/types.h>
6#include <../../../../arch/s390/include/uapi/asm/perf_regs.h>
7
8void perf_regs_load(u64 *regs);
9
10#define PERF_REGS_MASK ((1ULL << PERF_REG_S390_MAX) - 1)
11#define PERF_REGS_MAX PERF_REG_S390_MAX
12#define PERF_SAMPLE_REGS_ABI PERF_SAMPLE_REGS_ABI_64
13
14#define PERF_REG_IP PERF_REG_S390_PC
15#define PERF_REG_SP PERF_REG_S390_R15
16
17static inline const char *perf_reg_name(int id)
18{
19 switch (id) {
20 case PERF_REG_S390_R0:
21 return "R0";
22 case PERF_REG_S390_R1:
23 return "R1";
24 case PERF_REG_S390_R2:
25 return "R2";
26 case PERF_REG_S390_R3:
27 return "R3";
28 case PERF_REG_S390_R4:
29 return "R4";
30 case PERF_REG_S390_R5:
31 return "R5";
32 case PERF_REG_S390_R6:
33 return "R6";
34 case PERF_REG_S390_R7:
35 return "R7";
36 case PERF_REG_S390_R8:
37 return "R8";
38 case PERF_REG_S390_R9:
39 return "R9";
40 case PERF_REG_S390_R10:
41 return "R10";
42 case PERF_REG_S390_R11:
43 return "R11";
44 case PERF_REG_S390_R12:
45 return "R12";
46 case PERF_REG_S390_R13:
47 return "R13";
48 case PERF_REG_S390_R14:
49 return "R14";
50 case PERF_REG_S390_R15:
51 return "R15";
52 case PERF_REG_S390_FP0:
53 return "FP0";
54 case PERF_REG_S390_FP1:
55 return "FP1";
56 case PERF_REG_S390_FP2:
57 return "FP2";
58 case PERF_REG_S390_FP3:
59 return "FP3";
60 case PERF_REG_S390_FP4:
61 return "FP4";
62 case PERF_REG_S390_FP5:
63 return "FP5";
64 case PERF_REG_S390_FP6:
65 return "FP6";
66 case PERF_REG_S390_FP7:
67 return "FP7";
68 case PERF_REG_S390_FP8:
69 return "FP8";
70 case PERF_REG_S390_FP9:
71 return "FP9";
72 case PERF_REG_S390_FP10:
73 return "FP10";
74 case PERF_REG_S390_FP11:
75 return "FP11";
76 case PERF_REG_S390_FP12:
77 return "FP12";
78 case PERF_REG_S390_FP13:
79 return "FP13";
80 case PERF_REG_S390_FP14:
81 return "FP14";
82 case PERF_REG_S390_FP15:
83 return "FP15";
84 case PERF_REG_S390_MASK:
85 return "MASK";
86 case PERF_REG_S390_PC:
87 return "PC";
88 default:
89 return NULL;
90 }
91
92 return NULL;
93}
94
95#endif /* ARCH_PERF_REGS_H */
diff --git a/tools/perf/arch/s390/util/Build b/tools/perf/arch/s390/util/Build
index bd518b623d7a..4a233683c684 100644
--- a/tools/perf/arch/s390/util/Build
+++ b/tools/perf/arch/s390/util/Build
@@ -1,7 +1,9 @@
1libperf-y += header.o 1libperf-y += header.o
2libperf-y += sym-handling.o
3libperf-y += kvm-stat.o 2libperf-y += kvm-stat.o
4 3
5libperf-$(CONFIG_DWARF) += dwarf-regs.o 4libperf-$(CONFIG_DWARF) += dwarf-regs.o
5libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
6 6
7libperf-y += machine.o 7libperf-y += machine.o
8
9libperf-$(CONFIG_AUXTRACE) += auxtrace.o
diff --git a/tools/perf/arch/s390/util/auxtrace.c b/tools/perf/arch/s390/util/auxtrace.c
new file mode 100644
index 000000000000..6cb48e4cffd9
--- /dev/null
+++ b/tools/perf/arch/s390/util/auxtrace.c
@@ -0,0 +1,118 @@
1#include <stdbool.h>
2#include <linux/kernel.h>
3#include <linux/types.h>
4#include <linux/bitops.h>
5#include <linux/log2.h>
6
7#include "../../util/evlist.h"
8#include "../../util/auxtrace.h"
9#include "../../util/evsel.h"
10
11#define PERF_EVENT_CPUM_SF 0xB0000 /* Event: Basic-sampling */
12#define PERF_EVENT_CPUM_SF_DIAG 0xBD000 /* Event: Combined-sampling */
13#define DEFAULT_AUX_PAGES 128
14#define DEFAULT_FREQ 4000
15
16static void cpumsf_free(struct auxtrace_record *itr)
17{
18 free(itr);
19}
20
21static size_t cpumsf_info_priv_size(struct auxtrace_record *itr __maybe_unused,
22 struct perf_evlist *evlist __maybe_unused)
23{
24 return 0;
25}
26
27static int
28cpumsf_info_fill(struct auxtrace_record *itr __maybe_unused,
29 struct perf_session *session __maybe_unused,
30 struct auxtrace_info_event *auxtrace_info __maybe_unused,
31 size_t priv_size __maybe_unused)
32{
33 return 0;
34}
35
36static unsigned long
37cpumsf_reference(struct auxtrace_record *itr __maybe_unused)
38{
39 return 0;
40}
41
42static int
43cpumsf_recording_options(struct auxtrace_record *ar __maybe_unused,
44 struct perf_evlist *evlist __maybe_unused,
45 struct record_opts *opts)
46{
47 unsigned int factor = 1;
48 unsigned int pages;
49
50 opts->full_auxtrace = true;
51
52 /*
53 * The AUX buffer size should be set properly to avoid
54 * overflow of samples if it is not set explicitly.
55 * DEFAULT_AUX_PAGES is an proper size when sampling frequency
56 * is DEFAULT_FREQ. It is expected to hold about 1/2 second
57 * of sampling data. The size used for AUX buffer will scale
58 * according to the specified frequency and DEFAULT_FREQ.
59 */
60 if (!opts->auxtrace_mmap_pages) {
61 if (opts->user_freq != UINT_MAX)
62 factor = (opts->user_freq + DEFAULT_FREQ
63 - 1) / DEFAULT_FREQ;
64 pages = DEFAULT_AUX_PAGES * factor;
65 opts->auxtrace_mmap_pages = roundup_pow_of_two(pages);
66 }
67
68 return 0;
69}
70
71static int
72cpumsf_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused,
73 struct record_opts *opts __maybe_unused,
74 const char *str __maybe_unused)
75{
76 return 0;
77}
78
79/*
80 * auxtrace_record__init is called when perf record
81 * check if the event really need auxtrace
82 */
83struct auxtrace_record *auxtrace_record__init(struct perf_evlist *evlist,
84 int *err)
85{
86 struct auxtrace_record *aux;
87 struct perf_evsel *pos;
88 int diagnose = 0;
89
90 if (evlist->nr_entries == 0)
91 return NULL;
92
93 evlist__for_each_entry(evlist, pos) {
94 if (pos->attr.config == PERF_EVENT_CPUM_SF_DIAG) {
95 diagnose = 1;
96 break;
97 }
98 }
99
100 if (!diagnose)
101 return NULL;
102
103 /* sampling in diagnose mode. alloc aux buffer */
104 aux = zalloc(sizeof(*aux));
105 if (aux == NULL) {
106 *err = -ENOMEM;
107 return NULL;
108 }
109
110 aux->parse_snapshot_options = cpumsf_parse_snapshot_options;
111 aux->recording_options = cpumsf_recording_options;
112 aux->info_priv_size = cpumsf_info_priv_size;
113 aux->info_fill = cpumsf_info_fill;
114 aux->free = cpumsf_free;
115 aux->reference = cpumsf_reference;
116
117 return aux;
118}
diff --git a/tools/perf/arch/s390/util/dwarf-regs.c b/tools/perf/arch/s390/util/dwarf-regs.c
index 0469df02ee62..f47576ce13ea 100644
--- a/tools/perf/arch/s390/util/dwarf-regs.c
+++ b/tools/perf/arch/s390/util/dwarf-regs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Mapping of DWARF debug register numbers into register names. 3 * Mapping of DWARF debug register numbers into register names.
3 * 4 *
@@ -8,15 +9,10 @@
8 9
9#include <stddef.h> 10#include <stddef.h>
10#include <dwarf-regs.h> 11#include <dwarf-regs.h>
11 12#include <linux/kernel.h>
12#define NUM_GPRS 16 13#include "dwarf-regs-table.h"
13
14static const char *gpr_names[NUM_GPRS] = {
15 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
16 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
17};
18 14
19const char *get_arch_regstr(unsigned int n) 15const char *get_arch_regstr(unsigned int n)
20{ 16{
21 return (n >= NUM_GPRS) ? NULL : gpr_names[n]; 17 return (n >= ARRAY_SIZE(s390_dwarf_regs)) ? NULL : s390_dwarf_regs[n];
22} 18}
diff --git a/tools/perf/arch/s390/util/machine.c b/tools/perf/arch/s390/util/machine.c
index b9a95a1a8e69..0b2054007314 100644
--- a/tools/perf/arch/s390/util/machine.c
+++ b/tools/perf/arch/s390/util/machine.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <unistd.h> 2#include <unistd.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/perf/arch/s390/util/sym-handling.c b/tools/perf/arch/s390/util/sym-handling.c
deleted file mode 100644
index e103f6e46afe..000000000000
--- a/tools/perf/arch/s390/util/sym-handling.c
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 * Architecture specific ELF symbol handling and relocation mapping.
3 *
4 * Copyright 2017 IBM Corp.
5 * Author(s): Thomas Richter <tmricht@linux.vnet.ibm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License (version 2 only)
9 * as published by the Free Software Foundation.
10 */
11
12#include "symbol.h"
13
14#ifdef HAVE_LIBELF_SUPPORT
15bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
16{
17 if (ehdr.e_type == ET_EXEC)
18 return false;
19 return ehdr.e_type == ET_REL || ehdr.e_type == ET_DYN;
20}
21
22void arch__adjust_sym_map_offset(GElf_Sym *sym,
23 GElf_Shdr *shdr __maybe_unused,
24 struct map *map)
25{
26 if (map->type == MAP__FUNCTION)
27 sym->st_value += map->start;
28}
29#endif
diff --git a/tools/perf/arch/s390/util/unwind-libdw.c b/tools/perf/arch/s390/util/unwind-libdw.c
new file mode 100644
index 000000000000..387c698cdd1b
--- /dev/null
+++ b/tools/perf/arch/s390/util/unwind-libdw.c
@@ -0,0 +1,63 @@
1#include <linux/kernel.h>
2#include <elfutils/libdwfl.h>
3#include "../../util/unwind-libdw.h"
4#include "../../util/perf_regs.h"
5#include "../../util/event.h"
6#include "dwarf-regs-table.h"
7
8
9bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg)
10{
11 struct unwind_info *ui = arg;
12 struct regs_dump *user_regs = &ui->sample->user_regs;
13 Dwarf_Word dwarf_regs[ARRAY_SIZE(s390_dwarf_regs)];
14
15#define REG(r) ({ \
16 Dwarf_Word val = 0; \
17 perf_reg_value(&val, user_regs, PERF_REG_S390_##r); \
18 val; \
19})
20 /*
21 * For DWARF register mapping details,
22 * see also perf/arch/s390/include/dwarf-regs-table.h
23 */
24 dwarf_regs[0] = REG(R0);
25 dwarf_regs[1] = REG(R1);
26 dwarf_regs[2] = REG(R2);
27 dwarf_regs[3] = REG(R3);
28 dwarf_regs[4] = REG(R4);
29 dwarf_regs[5] = REG(R5);
30 dwarf_regs[6] = REG(R6);
31 dwarf_regs[7] = REG(R7);
32 dwarf_regs[8] = REG(R8);
33 dwarf_regs[9] = REG(R9);
34 dwarf_regs[10] = REG(R10);
35 dwarf_regs[11] = REG(R11);
36 dwarf_regs[12] = REG(R12);
37 dwarf_regs[13] = REG(R13);
38 dwarf_regs[14] = REG(R14);
39 dwarf_regs[15] = REG(R15);
40
41 dwarf_regs[16] = REG(FP0);
42 dwarf_regs[17] = REG(FP2);
43 dwarf_regs[18] = REG(FP4);
44 dwarf_regs[19] = REG(FP6);
45 dwarf_regs[20] = REG(FP1);
46 dwarf_regs[21] = REG(FP3);
47 dwarf_regs[22] = REG(FP5);
48 dwarf_regs[23] = REG(FP7);
49 dwarf_regs[24] = REG(FP8);
50 dwarf_regs[25] = REG(FP10);
51 dwarf_regs[26] = REG(FP12);
52 dwarf_regs[27] = REG(FP14);
53 dwarf_regs[28] = REG(FP9);
54 dwarf_regs[29] = REG(FP11);
55 dwarf_regs[30] = REG(FP13);
56 dwarf_regs[31] = REG(FP15);
57
58 dwarf_regs[64] = REG(MASK);
59 dwarf_regs[65] = REG(PC);
60
61 dwfl_thread_state_register_pc(thread, dwarf_regs[65]);
62 return dwfl_thread_state_registers(thread, 0, 32, dwarf_regs);
63}
diff --git a/tools/perf/arch/sh/include/dwarf-regs-table.h b/tools/perf/arch/sh/include/dwarf-regs-table.h
index 3a2deaf3dab4..900e69619970 100644
--- a/tools/perf/arch/sh/include/dwarf-regs-table.h
+++ b/tools/perf/arch/sh/include/dwarf-regs-table.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef DEFINE_DWARF_REGSTR_TABLE 2#ifdef DEFINE_DWARF_REGSTR_TABLE
2/* This is included in perf/util/dwarf-regs.c */ 3/* This is included in perf/util/dwarf-regs.c */
3 4
diff --git a/tools/perf/arch/sparc/include/dwarf-regs-table.h b/tools/perf/arch/sparc/include/dwarf-regs-table.h
index 12c07619002c..35ede84a6b0d 100644
--- a/tools/perf/arch/sparc/include/dwarf-regs-table.h
+++ b/tools/perf/arch/sparc/include/dwarf-regs-table.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef DEFINE_DWARF_REGSTR_TABLE 2#ifdef DEFINE_DWARF_REGSTR_TABLE
2/* This is included in perf/util/dwarf-regs.c */ 3/* This is included in perf/util/dwarf-regs.c */
3 4
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 9a628a24c5c9..d74eaa7aa927 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ifndef NO_DWARF 2ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 3PERF_HAVE_DWARF_REGS := 1
3endif 4endif
diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/arch/x86/annotate/instructions.c
index d84b72063a30..5bd1ba8c0282 100644
--- a/tools/perf/arch/x86/annotate/instructions.c
+++ b/tools/perf/arch/x86/annotate/instructions.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1static struct ins x86__instructions[] = { 2static struct ins x86__instructions[] = {
2 { .name = "add", .ops = &mov_ops, }, 3 { .name = "add", .ops = &mov_ops, },
3 { .name = "addl", .ops = &mov_ops, }, 4 { .name = "addl", .ops = &mov_ops, },
@@ -122,3 +123,17 @@ static int x86__cpuid_parse(struct arch *arch, char *cpuid)
122 123
123 return -1; 124 return -1;
124} 125}
126
127static int x86__annotate_init(struct arch *arch, char *cpuid)
128{
129 int err = 0;
130
131 if (arch->initialized)
132 return 0;
133
134 if (cpuid)
135 err = x86__cpuid_parse(arch, cpuid);
136
137 arch->initialized = true;
138 return err;
139}
diff --git a/tools/perf/arch/x86/entry/syscalls/syscalltbl.sh b/tools/perf/arch/x86/entry/syscalls/syscalltbl.sh
index 49a18b9ad9cf..029a72c20b19 100755
--- a/tools/perf/arch/x86/entry/syscalls/syscalltbl.sh
+++ b/tools/perf/arch/x86/entry/syscalls/syscalltbl.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3in="$1" 4in="$1"
4arch="$2" 5arch="$2"
diff --git a/tools/perf/arch/x86/include/arch-tests.h b/tools/perf/arch/x86/include/arch-tests.h
index 4e0b806a7a0f..c1bd979b957b 100644
--- a/tools/perf/arch/x86/include/arch-tests.h
+++ b/tools/perf/arch/x86/include/arch-tests.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_TESTS_H 2#ifndef ARCH_TESTS_H
2#define ARCH_TESTS_H 3#define ARCH_TESTS_H
3 4
@@ -8,7 +9,6 @@ struct test;
8int test__rdpmc(struct test *test __maybe_unused, int subtest); 9int test__rdpmc(struct test *test __maybe_unused, int subtest);
9int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest); 10int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest);
10int test__insn_x86(struct test *test __maybe_unused, int subtest); 11int test__insn_x86(struct test *test __maybe_unused, int subtest);
11int test__intel_cqm_count_nmi_context(struct test *test __maybe_unused, int subtest);
12 12
13#ifdef HAVE_DWARF_UNWIND_SUPPORT 13#ifdef HAVE_DWARF_UNWIND_SUPPORT
14struct thread; 14struct thread;
diff --git a/tools/perf/arch/x86/include/dwarf-regs-table.h b/tools/perf/arch/x86/include/dwarf-regs-table.h
index 9b5e5cbb4209..b9bd5dc9d4c0 100644
--- a/tools/perf/arch/x86/include/dwarf-regs-table.h
+++ b/tools/perf/arch/x86/include/dwarf-regs-table.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef DEFINE_DWARF_REGSTR_TABLE 2#ifdef DEFINE_DWARF_REGSTR_TABLE
2/* This is included in perf/util/dwarf-regs.c */ 3/* This is included in perf/util/dwarf-regs.c */
3 4
diff --git a/tools/perf/arch/x86/include/perf_regs.h b/tools/perf/arch/x86/include/perf_regs.h
index 7df517acfef8..7f6d538f8a89 100644
--- a/tools/perf/arch/x86/include/perf_regs.h
+++ b/tools/perf/arch/x86/include/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ARCH_PERF_REGS_H 2#ifndef ARCH_PERF_REGS_H
2#define ARCH_PERF_REGS_H 3#define ARCH_PERF_REGS_H
3 4
diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Build
index cbb7e978166b..8e2c5a38c3b9 100644
--- a/tools/perf/arch/x86/tests/Build
+++ b/tools/perf/arch/x86/tests/Build
@@ -5,4 +5,3 @@ libperf-y += arch-tests.o
5libperf-y += rdpmc.o 5libperf-y += rdpmc.o
6libperf-y += perf-time-to-tsc.o 6libperf-y += perf-time-to-tsc.o
7libperf-$(CONFIG_AUXTRACE) += insn-x86.o 7libperf-$(CONFIG_AUXTRACE) += insn-x86.o
8libperf-y += intel-cqm.o
diff --git a/tools/perf/arch/x86/tests/arch-tests.c b/tools/perf/arch/x86/tests/arch-tests.c
index 99d66191e56c..cc1802ff5410 100644
--- a/tools/perf/arch/x86/tests/arch-tests.c
+++ b/tools/perf/arch/x86/tests/arch-tests.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include "tests/tests.h" 3#include "tests/tests.h"
3#include "arch-tests.h" 4#include "arch-tests.h"
@@ -24,10 +25,6 @@ struct test arch_tests[] = {
24 }, 25 },
25#endif 26#endif
26 { 27 {
27 .desc = "Intel cqm nmi context read",
28 .func = test__intel_cqm_count_nmi_context,
29 },
30 {
31 .func = NULL, 28 .func = NULL,
32 }, 29 },
33 30
diff --git a/tools/perf/arch/x86/tests/dwarf-unwind.c b/tools/perf/arch/x86/tests/dwarf-unwind.c
index 7f209ce827bf..95036c7a59e8 100644
--- a/tools/perf/arch/x86/tests/dwarf-unwind.c
+++ b/tools/perf/arch/x86/tests/dwarf-unwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include "perf_regs.h" 3#include "perf_regs.h"
3#include "thread.h" 4#include "thread.h"
diff --git a/tools/perf/arch/x86/tests/insn-x86-dat-32.c b/tools/perf/arch/x86/tests/insn-x86-dat-32.c
index 3cbf6fad169f..fab3c6de73fa 100644
--- a/tools/perf/arch/x86/tests/insn-x86-dat-32.c
+++ b/tools/perf/arch/x86/tests/insn-x86-dat-32.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk 3 * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk
3 * from insn-x86-dat-src.c for inclusion by insn-x86.c 4 * from insn-x86-dat-src.c for inclusion by insn-x86.c
diff --git a/tools/perf/arch/x86/tests/insn-x86-dat-64.c b/tools/perf/arch/x86/tests/insn-x86-dat-64.c
index aa512fa944dd..c57f34603b9b 100644
--- a/tools/perf/arch/x86/tests/insn-x86-dat-64.c
+++ b/tools/perf/arch/x86/tests/insn-x86-dat-64.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk 3 * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk
3 * from insn-x86-dat-src.c for inclusion by insn-x86.c 4 * from insn-x86-dat-src.c for inclusion by insn-x86.c
diff --git a/tools/perf/arch/x86/tests/insn-x86-dat-src.c b/tools/perf/arch/x86/tests/insn-x86-dat-src.c
index 6cdb65d25b79..891415b10984 100644
--- a/tools/perf/arch/x86/tests/insn-x86-dat-src.c
+++ b/tools/perf/arch/x86/tests/insn-x86-dat-src.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file contains instructions for testing by the test titled: 3 * This file contains instructions for testing by the test titled:
3 * 4 *
diff --git a/tools/perf/arch/x86/tests/insn-x86.c b/tools/perf/arch/x86/tests/insn-x86.c
index b3860586a0c2..a5d24ae5810d 100644
--- a/tools/perf/arch/x86/tests/insn-x86.c
+++ b/tools/perf/arch/x86/tests/insn-x86.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/types.h> 2#include <linux/types.h>
2 3
3#include "debug.h" 4#include "debug.h"
diff --git a/tools/perf/arch/x86/tests/intel-cqm.c b/tools/perf/arch/x86/tests/intel-cqm.c
index 57f86b6e7d6f..90a4a8c58a62 100644
--- a/tools/perf/arch/x86/tests/intel-cqm.c
+++ b/tools/perf/arch/x86/tests/intel-cqm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "tests/tests.h" 2#include "tests/tests.h"
2#include "perf.h" 3#include "perf.h"
3#include "cloexec.h" 4#include "cloexec.h"
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 5dd7efb192ce..b59678e8c1e2 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/perf/arch/x86/tests/rdpmc.c b/tools/perf/arch/x86/tests/rdpmc.c
index 17fec30a0b31..7a11f02d6c6c 100644
--- a/tools/perf/arch/x86/tests/rdpmc.c
+++ b/tools/perf/arch/x86/tests/rdpmc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/perf/arch/x86/tests/regs_load.S b/tools/perf/arch/x86/tests/regs_load.S
index 60875d5c556c..bbe5a0d16e51 100644
--- a/tools/perf/arch/x86/tests/regs_load.S
+++ b/tools/perf/arch/x86/tests/regs_load.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <linux/linkage.h> 2#include <linux/linkage.h>
2 3
3#define AX 0 4#define AX 0
diff --git a/tools/perf/arch/x86/util/group.c b/tools/perf/arch/x86/util/group.c
index 37f92aa39a5d..e2f8034b8973 100644
--- a/tools/perf/arch/x86/util/group.c
+++ b/tools/perf/arch/x86/util/group.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include "api/fs/fs.h" 3#include "api/fs/fs.h"
3#include "util/group.h" 4#include "util/group.h"
diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c
index a74a48db26f5..33027c5e6f92 100644
--- a/tools/perf/arch/x86/util/header.c
+++ b/tools/perf/arch/x86/util/header.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
index bf817beca0a8..b32409a0e546 100644
--- a/tools/perf/arch/x86/util/kvm-stat.c
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include "../../util/kvm-stat.h" 3#include "../../util/kvm-stat.h"
3#include <asm/svm.h> 4#include <asm/svm.h>
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
index f95edebfb716..4b2caf6d48e7 100644
--- a/tools/perf/arch/x86/util/perf_regs.c
+++ b/tools/perf/arch/x86/util/perf_regs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <string.h> 3#include <string.h>
3#include <regex.h> 4#include <regex.h>
diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c
index 79fe07158d00..63a74c32ddc5 100644
--- a/tools/perf/arch/x86/util/pmu.c
+++ b/tools/perf/arch/x86/util/pmu.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2 3
3#include <linux/perf_event.h> 4#include <linux/perf_event.h>
diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index 2e5567c94e09..06bae7023a51 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdbool.h> 2#include <stdbool.h>
2#include <errno.h> 3#include <errno.h>
3 4
diff --git a/tools/perf/arch/x86/util/unwind-libdw.c b/tools/perf/arch/x86/util/unwind-libdw.c
index 38dc9bb2a7c9..fda8f4206ee4 100644
--- a/tools/perf/arch/x86/util/unwind-libdw.c
+++ b/tools/perf/arch/x86/util/unwind-libdw.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <elfutils/libdwfl.h> 2#include <elfutils/libdwfl.h>
2#include "../../util/unwind-libdw.h" 3#include "../../util/unwind-libdw.h"
3#include "../../util/perf_regs.h" 4#include "../../util/perf_regs.h"
diff --git a/tools/perf/arch/x86/util/unwind-libunwind.c b/tools/perf/arch/x86/util/unwind-libunwind.c
index 4f16661cbdbb..9c917f80c906 100644
--- a/tools/perf/arch/x86/util/unwind-libunwind.c
+++ b/tools/perf/arch/x86/util/unwind-libunwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2#ifndef REMOTE_UNWIND_LIBUNWIND 3#ifndef REMOTE_UNWIND_LIBUNWIND
3#include <errno.h> 4#include <errno.h>
diff --git a/tools/perf/arch/xtensa/include/dwarf-regs-table.h b/tools/perf/arch/xtensa/include/dwarf-regs-table.h
index aa0444a33fe6..d7c9f1fb4444 100644
--- a/tools/perf/arch/xtensa/include/dwarf-regs-table.h
+++ b/tools/perf/arch/xtensa/include/dwarf-regs-table.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef DEFINE_DWARF_REGSTR_TABLE 2#ifdef DEFINE_DWARF_REGSTR_TABLE
2/* This is included in perf/util/dwarf-regs.c */ 3/* This is included in perf/util/dwarf-regs.c */
3 4
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index 842ab2781cdc..6c9fcd757f31 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef BENCH_H 2#ifndef BENCH_H
2#define BENCH_H 3#define BENCH_H
3 4
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index fe16b310097f..58ae6ed8f38b 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com> 3 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com>
3 * 4 *
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index 73a1c44ea63c..08653ae8a8c4 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2015 Davidlohr Bueso. 3 * Copyright (C) 2015 Davidlohr Bueso.
3 */ 4 */
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index 41786cbea24c..1058c194608a 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com> 3 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com>
3 * 4 *
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 4ab12c8e016a..b4732dad9f89 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2015 Davidlohr Bueso. 3 * Copyright (C) 2015 Davidlohr Bueso.
3 * 4 *
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index 2fa49222ef8d..8c5c0b6b5c97 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com> 3 * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com>
3 * 4 *
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
index e44fd3239530..db4853f209c7 100644
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Glibc independent futex library for testing kernel functionality. 3 * Glibc independent futex library for testing kernel functionality.
3 * Shamelessly stolen from Darren Hart <dvhltc@us.ibm.com> 4 * Shamelessly stolen from Darren Hart <dvhltc@us.ibm.com>
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index fbd732b54047..0251dd348124 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * mem-memcpy.c 3 * mem-memcpy.c
3 * 4 *
diff --git a/tools/perf/bench/mem-memcpy-arch.h b/tools/perf/bench/mem-memcpy-arch.h
index 5aad2a9408b0..5bcaec5601a8 100644
--- a/tools/perf/bench/mem-memcpy-arch.h
+++ b/tools/perf/bench/mem-memcpy-arch.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2#ifdef HAVE_ARCH_X86_64_SUPPORT 3#ifdef HAVE_ARCH_X86_64_SUPPORT
3 4
diff --git a/tools/perf/bench/mem-memcpy-x86-64-asm-def.h b/tools/perf/bench/mem-memcpy-x86-64-asm-def.h
index 8c0c1a2770c8..50ae8bd58296 100644
--- a/tools/perf/bench/mem-memcpy-x86-64-asm-def.h
+++ b/tools/perf/bench/mem-memcpy-x86-64-asm-def.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2MEMCPY_FN(memcpy_orig, 3MEMCPY_FN(memcpy_orig,
3 "x86-64-unrolled", 4 "x86-64-unrolled",
diff --git a/tools/perf/bench/mem-memcpy-x86-64-asm.S b/tools/perf/bench/mem-memcpy-x86-64-asm.S
index f700369bb0f6..b43f8d2a34ec 100644
--- a/tools/perf/bench/mem-memcpy-x86-64-asm.S
+++ b/tools/perf/bench/mem-memcpy-x86-64-asm.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2/* Various wrappers to make the kernel .S file build in user-space: */ 3/* Various wrappers to make the kernel .S file build in user-space: */
3 4
diff --git a/tools/perf/bench/mem-memset-arch.h b/tools/perf/bench/mem-memset-arch.h
index 0d15786d9ae3..53f45482663f 100644
--- a/tools/perf/bench/mem-memset-arch.h
+++ b/tools/perf/bench/mem-memset-arch.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2#ifdef HAVE_ARCH_X86_64_SUPPORT 3#ifdef HAVE_ARCH_X86_64_SUPPORT
3 4
diff --git a/tools/perf/bench/mem-memset-x86-64-asm-def.h b/tools/perf/bench/mem-memset-x86-64-asm-def.h
index f02d028771d9..dac6d2b7c39b 100644
--- a/tools/perf/bench/mem-memset-x86-64-asm-def.h
+++ b/tools/perf/bench/mem-memset-x86-64-asm-def.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2MEMSET_FN(memset_orig, 3MEMSET_FN(memset_orig,
3 "x86-64-unrolled", 4 "x86-64-unrolled",
diff --git a/tools/perf/bench/mem-memset-x86-64-asm.S b/tools/perf/bench/mem-memset-x86-64-asm.S
index 58407aa24c1b..d550bd526162 100644
--- a/tools/perf/bench/mem-memset-x86-64-asm.S
+++ b/tools/perf/bench/mem-memset-x86-64-asm.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#define memset MEMSET /* don't hide glibc's memset() */ 2#define memset MEMSET /* don't hide glibc's memset() */
2#define altinstr_replacement text 3#define altinstr_replacement text
3#define globl p2align 4; .globl 4#define globl p2align 4; .globl
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index 469d65b21122..d95fdcc26f4b 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * numa.c 3 * numa.c
3 * 4 *
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index 4f961e74535b..f9d7641ae833 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * 3 *
3 * sched-messaging.c 4 * sched-messaging.c
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index a152737370c5..0591be008f2a 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * 3 *
3 * sched-pipe.c 4 * sched-pipe.c
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index c38373195c4a..f15731a3d438 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-annotate.c 3 * builtin-annotate.c
3 * 4 *
@@ -356,7 +357,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
356 } 357 }
357 358
358 if (total_nr_samples == 0) { 359 if (total_nr_samples == 0) {
359 ui__error("The %s file has no samples!\n", session->file->path); 360 ui__error("The %s file has no samples!\n", session->data->file.path);
360 goto out; 361 goto out;
361 } 362 }
362 363
@@ -400,7 +401,7 @@ int cmd_annotate(int argc, const char **argv)
400 .ordering_requires_timestamps = true, 401 .ordering_requires_timestamps = true,
401 }, 402 },
402 }; 403 };
403 struct perf_data_file file = { 404 struct perf_data data = {
404 .mode = PERF_DATA_MODE_READ, 405 .mode = PERF_DATA_MODE_READ,
405 }; 406 };
406 struct option options[] = { 407 struct option options[] = {
@@ -410,7 +411,7 @@ int cmd_annotate(int argc, const char **argv)
410 "only consider symbols in these dsos"), 411 "only consider symbols in these dsos"),
411 OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol", 412 OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol",
412 "symbol to annotate"), 413 "symbol to annotate"),
413 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), 414 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"),
414 OPT_INCR('v', "verbose", &verbose, 415 OPT_INCR('v', "verbose", &verbose,
415 "be more verbose (show symbol address, etc)"), 416 "be more verbose (show symbol address, etc)"),
416 OPT_BOOLEAN('q', "quiet", &quiet, "do now show any message"), 417 OPT_BOOLEAN('q', "quiet", &quiet, "do now show any message"),
@@ -482,9 +483,9 @@ int cmd_annotate(int argc, const char **argv)
482 if (quiet) 483 if (quiet)
483 perf_quiet_option(); 484 perf_quiet_option();
484 485
485 file.path = input_name; 486 data.file.path = input_name;
486 487
487 annotate.session = perf_session__new(&file, false, &annotate.tool); 488 annotate.session = perf_session__new(&data, false, &annotate.tool);
488 if (annotate.session == NULL) 489 if (annotate.session == NULL)
489 return -1; 490 return -1;
490 491
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index 445e62881254..17a6bcd01aa6 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-bench.c 3 * builtin-bench.c
3 * 4 *
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index e3eb6240ced0..3d354ba6e9c5 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-buildid-cache.c 3 * builtin-buildid-cache.c
3 * 4 *
@@ -311,7 +312,7 @@ int cmd_buildid_cache(int argc, const char **argv)
311 *kcore_filename = NULL; 312 *kcore_filename = NULL;
312 char sbuf[STRERR_BUFSIZE]; 313 char sbuf[STRERR_BUFSIZE];
313 314
314 struct perf_data_file file = { 315 struct perf_data data = {
315 .mode = PERF_DATA_MODE_READ, 316 .mode = PERF_DATA_MODE_READ,
316 }; 317 };
317 struct perf_session *session = NULL; 318 struct perf_session *session = NULL;
@@ -352,10 +353,10 @@ int cmd_buildid_cache(int argc, const char **argv)
352 nsi = nsinfo__new(ns_id); 353 nsi = nsinfo__new(ns_id);
353 354
354 if (missing_filename) { 355 if (missing_filename) {
355 file.path = missing_filename; 356 data.file.path = missing_filename;
356 file.force = force; 357 data.force = force;
357 358
358 session = perf_session__new(&file, false, NULL); 359 session = perf_session__new(&data, false, NULL);
359 if (session == NULL) 360 if (session == NULL)
360 return -1; 361 return -1;
361 } 362 }
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index fdaca16e0c74..78abbe8d9d5f 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-buildid-list.c 3 * builtin-buildid-list.c
3 * 4 *
@@ -50,10 +51,12 @@ static bool dso__skip_buildid(struct dso *dso, int with_hits)
50static int perf_session__list_build_ids(bool force, bool with_hits) 51static int perf_session__list_build_ids(bool force, bool with_hits)
51{ 52{
52 struct perf_session *session; 53 struct perf_session *session;
53 struct perf_data_file file = { 54 struct perf_data data = {
54 .path = input_name, 55 .file = {
55 .mode = PERF_DATA_MODE_READ, 56 .path = input_name,
56 .force = force, 57 },
58 .mode = PERF_DATA_MODE_READ,
59 .force = force,
57 }; 60 };
58 61
59 symbol__elf_init(); 62 symbol__elf_init();
@@ -63,7 +66,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
63 if (filename__fprintf_build_id(input_name, stdout) > 0) 66 if (filename__fprintf_build_id(input_name, stdout) > 0)
64 goto out; 67 goto out;
65 68
66 session = perf_session__new(&file, false, &build_id__mark_dso_hit_ops); 69 session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops);
67 if (session == NULL) 70 if (session == NULL)
68 return -1; 71 return -1;
69 72
@@ -71,7 +74,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
71 * We take all buildids when the file contains AUX area tracing data 74 * We take all buildids when the file contains AUX area tracing data
72 * because we do not decode the trace because it would take too long. 75 * because we do not decode the trace because it would take too long.
73 */ 76 */
74 if (!perf_data_file__is_pipe(&file) && 77 if (!perf_data__is_pipe(&data) &&
75 perf_header__has_feat(&session->header, HEADER_AUXTRACE)) 78 perf_header__has_feat(&session->header, HEADER_AUXTRACE))
76 with_hits = false; 79 with_hits = false;
77 80
@@ -79,7 +82,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
79 * in pipe-mode, the only way to get the buildids is to parse 82 * in pipe-mode, the only way to get the buildids is to parse
80 * the record stream. Buildids are stored as RECORD_HEADER_BUILD_ID 83 * the record stream. Buildids are stored as RECORD_HEADER_BUILD_ID
81 */ 84 */
82 if (with_hits || perf_data_file__is_pipe(&file)) 85 if (with_hits || perf_data__is_pipe(&data))
83 perf_session__process_events(session); 86 perf_session__process_events(session);
84 87
85 perf_session__fprintf_dsos_buildid(session, stdout, dso__skip_buildid, with_hits); 88 perf_session__fprintf_dsos_buildid(session, stdout, dso__skip_buildid, with_hits);
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 475999e48f66..17855c4626a0 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This is rewrite of original c2c tool introduced in here: 3 * This is rewrite of original c2c tool introduced in here:
3 * http://lwn.net/Articles/588866/ 4 * http://lwn.net/Articles/588866/
@@ -2523,7 +2524,7 @@ static int perf_c2c__report(int argc, const char **argv)
2523{ 2524{
2524 struct perf_session *session; 2525 struct perf_session *session;
2525 struct ui_progress prog; 2526 struct ui_progress prog;
2526 struct perf_data_file file = { 2527 struct perf_data data = {
2527 .mode = PERF_DATA_MODE_READ, 2528 .mode = PERF_DATA_MODE_READ,
2528 }; 2529 };
2529 char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT; 2530 char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
@@ -2572,8 +2573,8 @@ static int perf_c2c__report(int argc, const char **argv)
2572 if (!input_name || !strlen(input_name)) 2573 if (!input_name || !strlen(input_name))
2573 input_name = "perf.data"; 2574 input_name = "perf.data";
2574 2575
2575 file.path = input_name; 2576 data.file.path = input_name;
2576 file.force = symbol_conf.force; 2577 data.force = symbol_conf.force;
2577 2578
2578 err = setup_display(display); 2579 err = setup_display(display);
2579 if (err) 2580 if (err)
@@ -2591,7 +2592,7 @@ static int perf_c2c__report(int argc, const char **argv)
2591 goto out; 2592 goto out;
2592 } 2593 }
2593 2594
2594 session = perf_session__new(&file, 0, &c2c.tool); 2595 session = perf_session__new(&data, 0, &c2c.tool);
2595 if (session == NULL) { 2596 if (session == NULL) {
2596 pr_debug("No memory for session\n"); 2597 pr_debug("No memory for session\n");
2597 goto out; 2598 goto out;
@@ -2611,7 +2612,7 @@ static int perf_c2c__report(int argc, const char **argv)
2611 goto out_session; 2612 goto out_session;
2612 2613
2613 /* No pipe support at the moment. */ 2614 /* No pipe support at the moment. */
2614 if (perf_data_file__is_pipe(session->file)) { 2615 if (perf_data__is_pipe(session->data)) {
2615 pr_debug("No pipe support at the moment.\n"); 2616 pr_debug("No pipe support at the moment.\n");
2616 goto out_session; 2617 goto out_session;
2617 } 2618 }
@@ -2732,6 +2733,7 @@ static int perf_c2c__record(int argc, const char **argv)
2732 if (!perf_mem_events[j].supported) { 2733 if (!perf_mem_events[j].supported) {
2733 pr_err("failed: event '%s' not supported\n", 2734 pr_err("failed: event '%s' not supported\n",
2734 perf_mem_events[j].name); 2735 perf_mem_events[j].name);
2736 free(rec_argv);
2735 return -1; 2737 return -1;
2736 } 2738 }
2737 2739
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index a1d82e33282c..514f70f95b57 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-config.c 3 * builtin-config.c
3 * 4 *
@@ -34,8 +35,7 @@ static struct option config_options[] = {
34 OPT_END() 35 OPT_END()
35}; 36};
36 37
37static int set_config(struct perf_config_set *set, const char *file_name, 38static int set_config(struct perf_config_set *set, const char *file_name)
38 const char *var, const char *value)
39{ 39{
40 struct perf_config_section *section = NULL; 40 struct perf_config_section *section = NULL;
41 struct perf_config_item *item = NULL; 41 struct perf_config_item *item = NULL;
@@ -49,7 +49,6 @@ static int set_config(struct perf_config_set *set, const char *file_name,
49 if (!fp) 49 if (!fp)
50 return -1; 50 return -1;
51 51
52 perf_config_set__collect(set, file_name, var, value);
53 fprintf(fp, "%s\n", first_line); 52 fprintf(fp, "%s\n", first_line);
54 53
55 /* overwrite configvariables */ 54 /* overwrite configvariables */
@@ -161,6 +160,7 @@ int cmd_config(int argc, const char **argv)
161 struct perf_config_set *set; 160 struct perf_config_set *set;
162 char *user_config = mkpath("%s/.perfconfig", getenv("HOME")); 161 char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
163 const char *config_filename; 162 const char *config_filename;
163 bool changed = false;
164 164
165 argc = parse_options(argc, argv, config_options, config_usage, 165 argc = parse_options(argc, argv, config_options, config_usage,
166 PARSE_OPT_STOP_AT_NON_OPTION); 166 PARSE_OPT_STOP_AT_NON_OPTION);
@@ -231,15 +231,26 @@ int cmd_config(int argc, const char **argv)
231 goto out_err; 231 goto out_err;
232 } 232 }
233 } else { 233 } else {
234 if (set_config(set, config_filename, var, value) < 0) { 234 if (perf_config_set__collect(set, config_filename,
235 pr_err("Failed to set '%s=%s' on %s\n", 235 var, value) < 0) {
236 var, value, config_filename); 236 pr_err("Failed to add '%s=%s'\n",
237 var, value);
237 free(arg); 238 free(arg);
238 goto out_err; 239 goto out_err;
239 } 240 }
241 changed = true;
240 } 242 }
241 free(arg); 243 free(arg);
242 } 244 }
245
246 if (!changed)
247 break;
248
249 if (set_config(set, config_filename) < 0) {
250 pr_err("Failed to set the configs on %s\n",
251 config_filename);
252 goto out_err;
253 }
243 } 254 }
244 255
245 ret = 0; 256 ret = 0;
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 46cd8490baf4..dde25d4ca56d 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include "builtin.h" 3#include "builtin.h"
3#include "perf.h" 4#include "perf.h"
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 0cd4cf6a344b..d660cb7b222b 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-diff.c 3 * builtin-diff.c
3 * 4 *
@@ -47,7 +48,7 @@ struct diff_hpp_fmt {
47 48
48struct data__file { 49struct data__file {
49 struct perf_session *session; 50 struct perf_session *session;
50 struct perf_data_file file; 51 struct perf_data data;
51 int idx; 52 int idx;
52 struct hists *hists; 53 struct hists *hists;
53 struct diff_hpp_fmt fmt[PERF_HPP_DIFF__MAX_INDEX]; 54 struct diff_hpp_fmt fmt[PERF_HPP_DIFF__MAX_INDEX];
@@ -707,7 +708,7 @@ static void data__fprintf(void)
707 708
708 data__for_each_file(i, d) 709 data__for_each_file(i, d)
709 fprintf(stdout, "# [%d] %s %s\n", 710 fprintf(stdout, "# [%d] %s %s\n",
710 d->idx, d->file.path, 711 d->idx, d->data.file.path,
711 !d->idx ? "(Baseline)" : ""); 712 !d->idx ? "(Baseline)" : "");
712 713
713 fprintf(stdout, "#\n"); 714 fprintf(stdout, "#\n");
@@ -776,16 +777,16 @@ static int __cmd_diff(void)
776 int ret = -EINVAL, i; 777 int ret = -EINVAL, i;
777 778
778 data__for_each_file(i, d) { 779 data__for_each_file(i, d) {
779 d->session = perf_session__new(&d->file, false, &tool); 780 d->session = perf_session__new(&d->data, false, &tool);
780 if (!d->session) { 781 if (!d->session) {
781 pr_err("Failed to open %s\n", d->file.path); 782 pr_err("Failed to open %s\n", d->data.file.path);
782 ret = -1; 783 ret = -1;
783 goto out_delete; 784 goto out_delete;
784 } 785 }
785 786
786 ret = perf_session__process_events(d->session); 787 ret = perf_session__process_events(d->session);
787 if (ret) { 788 if (ret) {
788 pr_err("Failed to process %s\n", d->file.path); 789 pr_err("Failed to process %s\n", d->data.file.path);
789 goto out_delete; 790 goto out_delete;
790 } 791 }
791 792
@@ -1286,11 +1287,11 @@ static int data_init(int argc, const char **argv)
1286 return -ENOMEM; 1287 return -ENOMEM;
1287 1288
1288 data__for_each_file(i, d) { 1289 data__for_each_file(i, d) {
1289 struct perf_data_file *file = &d->file; 1290 struct perf_data *data = &d->data;
1290 1291
1291 file->path = use_default ? defaults[i] : argv[i]; 1292 data->file.path = use_default ? defaults[i] : argv[i];
1292 file->mode = PERF_DATA_MODE_READ, 1293 data->mode = PERF_DATA_MODE_READ,
1293 file->force = force, 1294 data->force = force,
1294 1295
1295 d->idx = i; 1296 d->idx = i;
1296 } 1297 }
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 6d210e40d611..e06e822ce634 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Builtin evlist command: Show the list of event selectors present 3 * Builtin evlist command: Show the list of event selectors present
3 * in a perf.data file. 4 * in a perf.data file.
@@ -21,14 +22,16 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
21{ 22{
22 struct perf_session *session; 23 struct perf_session *session;
23 struct perf_evsel *pos; 24 struct perf_evsel *pos;
24 struct perf_data_file file = { 25 struct perf_data data = {
25 .path = file_name, 26 .file = {
26 .mode = PERF_DATA_MODE_READ, 27 .path = file_name,
27 .force = details->force, 28 },
29 .mode = PERF_DATA_MODE_READ,
30 .force = details->force,
28 }; 31 };
29 bool has_tracepoint = false; 32 bool has_tracepoint = false;
30 33
31 session = perf_session__new(&file, 0, NULL); 34 session = perf_session__new(&data, 0, NULL);
32 if (session == NULL) 35 if (session == NULL)
33 return -1; 36 return -1;
34 37
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index dbe4e4153bcf..bd1fedef3d1c 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-help.c 3 * builtin-help.c
3 * 4 *
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 2b8032908fb2..16a28547ca86 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-inject.c 3 * builtin-inject.c
3 * 4 *
@@ -35,7 +36,7 @@ struct perf_inject {
35 bool strip; 36 bool strip;
36 bool jit_mode; 37 bool jit_mode;
37 const char *input_name; 38 const char *input_name;
38 struct perf_data_file output; 39 struct perf_data output;
39 u64 bytes_written; 40 u64 bytes_written;
40 u64 aux_id; 41 u64 aux_id;
41 struct list_head samples; 42 struct list_head samples;
@@ -52,7 +53,7 @@ static int output_bytes(struct perf_inject *inject, void *buf, size_t sz)
52{ 53{
53 ssize_t size; 54 ssize_t size;
54 55
55 size = perf_data_file__write(&inject->output, buf, sz); 56 size = perf_data__write(&inject->output, buf, sz);
56 if (size < 0) 57 if (size < 0)
57 return -errno; 58 return -errno;
58 59
@@ -145,7 +146,7 @@ static s64 perf_event__repipe_auxtrace(struct perf_tool *tool,
145 if (!inject->output.is_pipe) { 146 if (!inject->output.is_pipe) {
146 off_t offset; 147 off_t offset;
147 148
148 offset = lseek(inject->output.fd, 0, SEEK_CUR); 149 offset = lseek(inject->output.file.fd, 0, SEEK_CUR);
149 if (offset == -1) 150 if (offset == -1)
150 return -errno; 151 return -errno;
151 ret = auxtrace_index__auxtrace_event(&session->auxtrace_index, 152 ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
@@ -154,11 +155,11 @@ static s64 perf_event__repipe_auxtrace(struct perf_tool *tool,
154 return ret; 155 return ret;
155 } 156 }
156 157
157 if (perf_data_file__is_pipe(session->file) || !session->one_mmap) { 158 if (perf_data__is_pipe(session->data) || !session->one_mmap) {
158 ret = output_bytes(inject, event, event->header.size); 159 ret = output_bytes(inject, event, event->header.size);
159 if (ret < 0) 160 if (ret < 0)
160 return ret; 161 return ret;
161 ret = copy_bytes(inject, perf_data_file__fd(session->file), 162 ret = copy_bytes(inject, perf_data__fd(session->data),
162 event->auxtrace.size); 163 event->auxtrace.size);
163 } else { 164 } else {
164 ret = output_bytes(inject, event, 165 ret = output_bytes(inject, event,
@@ -637,8 +638,8 @@ static int __cmd_inject(struct perf_inject *inject)
637{ 638{
638 int ret = -EINVAL; 639 int ret = -EINVAL;
639 struct perf_session *session = inject->session; 640 struct perf_session *session = inject->session;
640 struct perf_data_file *file_out = &inject->output; 641 struct perf_data *data_out = &inject->output;
641 int fd = perf_data_file__fd(file_out); 642 int fd = perf_data__fd(data_out);
642 u64 output_data_offset; 643 u64 output_data_offset;
643 644
644 signal(SIGINT, sig_handler); 645 signal(SIGINT, sig_handler);
@@ -693,14 +694,14 @@ static int __cmd_inject(struct perf_inject *inject)
693 if (!inject->itrace_synth_opts.set) 694 if (!inject->itrace_synth_opts.set)
694 auxtrace_index__free(&session->auxtrace_index); 695 auxtrace_index__free(&session->auxtrace_index);
695 696
696 if (!file_out->is_pipe) 697 if (!data_out->is_pipe)
697 lseek(fd, output_data_offset, SEEK_SET); 698 lseek(fd, output_data_offset, SEEK_SET);
698 699
699 ret = perf_session__process_events(session); 700 ret = perf_session__process_events(session);
700 if (ret) 701 if (ret)
701 return ret; 702 return ret;
702 703
703 if (!file_out->is_pipe) { 704 if (!data_out->is_pipe) {
704 if (inject->build_ids) 705 if (inject->build_ids)
705 perf_header__set_feat(&session->header, 706 perf_header__set_feat(&session->header,
706 HEADER_BUILD_ID); 707 HEADER_BUILD_ID);
@@ -775,11 +776,13 @@ int cmd_inject(int argc, const char **argv)
775 .input_name = "-", 776 .input_name = "-",
776 .samples = LIST_HEAD_INIT(inject.samples), 777 .samples = LIST_HEAD_INIT(inject.samples),
777 .output = { 778 .output = {
778 .path = "-", 779 .file = {
779 .mode = PERF_DATA_MODE_WRITE, 780 .path = "-",
781 },
782 .mode = PERF_DATA_MODE_WRITE,
780 }, 783 },
781 }; 784 };
782 struct perf_data_file file = { 785 struct perf_data data = {
783 .mode = PERF_DATA_MODE_READ, 786 .mode = PERF_DATA_MODE_READ,
784 }; 787 };
785 int ret; 788 int ret;
@@ -789,7 +792,7 @@ int cmd_inject(int argc, const char **argv)
789 "Inject build-ids into the output stream"), 792 "Inject build-ids into the output stream"),
790 OPT_STRING('i', "input", &inject.input_name, "file", 793 OPT_STRING('i', "input", &inject.input_name, "file",
791 "input file name"), 794 "input file name"),
792 OPT_STRING('o', "output", &inject.output.path, "file", 795 OPT_STRING('o', "output", &inject.output.file.path, "file",
793 "output file name"), 796 "output file name"),
794 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat, 797 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat,
795 "Merge sched-stat and sched-switch for getting events " 798 "Merge sched-stat and sched-switch for getting events "
@@ -801,7 +804,7 @@ int cmd_inject(int argc, const char **argv)
801 "be more verbose (show build ids, etc)"), 804 "be more verbose (show build ids, etc)"),
802 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file", 805 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file",
803 "kallsyms pathname"), 806 "kallsyms pathname"),
804 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), 807 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"),
805 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts, 808 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts,
806 NULL, "opts", "Instruction Tracing options", 809 NULL, "opts", "Instruction Tracing options",
807 itrace_parse_synth_opts), 810 itrace_parse_synth_opts),
@@ -829,15 +832,15 @@ int cmd_inject(int argc, const char **argv)
829 return -1; 832 return -1;
830 } 833 }
831 834
832 if (perf_data_file__open(&inject.output)) { 835 if (perf_data__open(&inject.output)) {
833 perror("failed to create output file"); 836 perror("failed to create output file");
834 return -1; 837 return -1;
835 } 838 }
836 839
837 inject.tool.ordered_events = inject.sched_stat; 840 inject.tool.ordered_events = inject.sched_stat;
838 841
839 file.path = inject.input_name; 842 data.file.path = inject.input_name;
840 inject.session = perf_session__new(&file, true, &inject.tool); 843 inject.session = perf_session__new(&data, true, &inject.tool);
841 if (inject.session == NULL) 844 if (inject.session == NULL)
842 return -1; 845 return -1;
843 846
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 24ee68ecdd42..ae11e4c3516a 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "builtin.h" 2#include "builtin.h"
2#include "perf.h" 3#include "perf.h"
3 4
@@ -640,7 +641,6 @@ static const struct {
640 { "__GFP_ATOMIC", "_A" }, 641 { "__GFP_ATOMIC", "_A" },
641 { "__GFP_IO", "I" }, 642 { "__GFP_IO", "I" },
642 { "__GFP_FS", "F" }, 643 { "__GFP_FS", "F" },
643 { "__GFP_COLD", "CO" },
644 { "__GFP_NOWARN", "NWR" }, 644 { "__GFP_NOWARN", "NWR" },
645 { "__GFP_RETRY_MAYFAIL", "R" }, 645 { "__GFP_RETRY_MAYFAIL", "R" },
646 { "__GFP_NOFAIL", "NF" }, 646 { "__GFP_NOFAIL", "NF" },
@@ -654,7 +654,6 @@ static const struct {
654 { "__GFP_RECLAIMABLE", "RC" }, 654 { "__GFP_RECLAIMABLE", "RC" },
655 { "__GFP_MOVABLE", "M" }, 655 { "__GFP_MOVABLE", "M" },
656 { "__GFP_ACCOUNT", "AC" }, 656 { "__GFP_ACCOUNT", "AC" },
657 { "__GFP_NOTRACK", "NT" },
658 { "__GFP_WRITE", "WR" }, 657 { "__GFP_WRITE", "WR" },
659 { "__GFP_RECLAIM", "R" }, 658 { "__GFP_RECLAIM", "R" },
660 { "__GFP_DIRECT_RECLAIM", "DR" }, 659 { "__GFP_DIRECT_RECLAIM", "DR" },
@@ -1893,7 +1892,7 @@ int cmd_kmem(int argc, const char **argv)
1893{ 1892{
1894 const char * const default_slab_sort = "frag,hit,bytes"; 1893 const char * const default_slab_sort = "frag,hit,bytes";
1895 const char * const default_page_sort = "bytes,hit"; 1894 const char * const default_page_sort = "bytes,hit";
1896 struct perf_data_file file = { 1895 struct perf_data data = {
1897 .mode = PERF_DATA_MODE_READ, 1896 .mode = PERF_DATA_MODE_READ,
1898 }; 1897 };
1899 const struct option kmem_options[] = { 1898 const struct option kmem_options[] = {
@@ -1909,7 +1908,7 @@ int cmd_kmem(int argc, const char **argv)
1909 "page, order, migtype, gfp", parse_sort_opt), 1908 "page, order, migtype, gfp", parse_sort_opt),
1910 OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt), 1909 OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt),
1911 OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"), 1910 OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
1912 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), 1911 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"),
1913 OPT_CALLBACK_NOOPT(0, "slab", NULL, NULL, "Analyze slab allocator", 1912 OPT_CALLBACK_NOOPT(0, "slab", NULL, NULL, "Analyze slab allocator",
1914 parse_slab_opt), 1913 parse_slab_opt),
1915 OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator", 1914 OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator",
@@ -1949,9 +1948,9 @@ int cmd_kmem(int argc, const char **argv)
1949 return __cmd_record(argc, argv); 1948 return __cmd_record(argc, argv);
1950 } 1949 }
1951 1950
1952 file.path = input_name; 1951 data.file.path = input_name;
1953 1952
1954 kmem_session = session = perf_session__new(&file, false, &perf_kmem); 1953 kmem_session = session = perf_session__new(&data, false, &perf_kmem);
1955 if (session == NULL) 1954 if (session == NULL)
1956 return -1; 1955 return -1;
1957 1956
@@ -1983,7 +1982,8 @@ int cmd_kmem(int argc, const char **argv)
1983 1982
1984 if (perf_time__parse_str(&ptime, time_str) != 0) { 1983 if (perf_time__parse_str(&ptime, time_str) != 0) {
1985 pr_err("Invalid time string\n"); 1984 pr_err("Invalid time string\n");
1986 return -EINVAL; 1985 ret = -EINVAL;
1986 goto out_delete;
1987 } 1987 }
1988 1988
1989 if (!strcmp(argv[0], "stat")) { 1989 if (!strcmp(argv[0], "stat")) {
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index f309c3773522..0c36f2ac6a0e 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "builtin.h" 2#include "builtin.h"
2#include "perf.h" 3#include "perf.h"
3 4
@@ -34,7 +35,6 @@
34#include <termios.h> 35#include <termios.h>
35#include <semaphore.h> 36#include <semaphore.h>
36#include <signal.h> 37#include <signal.h>
37#include <pthread.h>
38#include <math.h> 38#include <math.h>
39 39
40static const char *get_filename_for_perf_kvm(void) 40static const char *get_filename_for_perf_kvm(void)
@@ -1068,10 +1068,12 @@ static int read_events(struct perf_kvm_stat *kvm)
1068 .namespaces = perf_event__process_namespaces, 1068 .namespaces = perf_event__process_namespaces,
1069 .ordered_events = true, 1069 .ordered_events = true,
1070 }; 1070 };
1071 struct perf_data_file file = { 1071 struct perf_data file = {
1072 .path = kvm->file_name, 1072 .file = {
1073 .mode = PERF_DATA_MODE_READ, 1073 .path = kvm->file_name,
1074 .force = kvm->force, 1074 },
1075 .mode = PERF_DATA_MODE_READ,
1076 .force = kvm->force,
1075 }; 1077 };
1076 1078
1077 kvm->tool = eops; 1079 kvm->tool = eops;
@@ -1359,7 +1361,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
1359 "perf kvm stat live [<options>]", 1361 "perf kvm stat live [<options>]",
1360 NULL 1362 NULL
1361 }; 1363 };
1362 struct perf_data_file file = { 1364 struct perf_data data = {
1363 .mode = PERF_DATA_MODE_WRITE, 1365 .mode = PERF_DATA_MODE_WRITE,
1364 }; 1366 };
1365 1367
@@ -1433,7 +1435,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
1433 /* 1435 /*
1434 * perf session 1436 * perf session
1435 */ 1437 */
1436 kvm->session = perf_session__new(&file, false, &kvm->tool); 1438 kvm->session = perf_session__new(&data, false, &kvm->tool);
1437 if (kvm->session == NULL) { 1439 if (kvm->session == NULL) {
1438 err = -1; 1440 err = -1;
1439 goto out; 1441 goto out;
@@ -1442,7 +1444,8 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
1442 perf_session__set_id_hdr_size(kvm->session); 1444 perf_session__set_id_hdr_size(kvm->session);
1443 ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true); 1445 ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true);
1444 machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target, 1446 machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target,
1445 kvm->evlist->threads, false, kvm->opts.proc_map_timeout); 1447 kvm->evlist->threads, false,
1448 kvm->opts.proc_map_timeout, 1);
1446 err = kvm_live_open_events(kvm); 1449 err = kvm_live_open_events(kvm);
1447 if (err) 1450 if (err)
1448 goto out; 1451 goto out;
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 4bf2cb4d25aa..ead221e49f00 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-list.c 3 * builtin-list.c
3 * 4 *
@@ -15,6 +16,7 @@
15#include "util/cache.h" 16#include "util/cache.h"
16#include "util/pmu.h" 17#include "util/pmu.h"
17#include "util/debug.h" 18#include "util/debug.h"
19#include "util/metricgroup.h"
18#include <subcmd/parse-options.h> 20#include <subcmd/parse-options.h>
19 21
20static bool desc_flag = true; 22static bool desc_flag = true;
@@ -79,6 +81,10 @@ int cmd_list(int argc, const char **argv)
79 long_desc_flag, details_flag); 81 long_desc_flag, details_flag);
80 else if (strcmp(argv[i], "sdt") == 0) 82 else if (strcmp(argv[i], "sdt") == 0)
81 print_sdt_events(NULL, NULL, raw_dump); 83 print_sdt_events(NULL, NULL, raw_dump);
84 else if (strcmp(argv[i], "metric") == 0)
85 metricgroup__print(true, false, NULL, raw_dump);
86 else if (strcmp(argv[i], "metricgroup") == 0)
87 metricgroup__print(false, true, NULL, raw_dump);
82 else if ((sep = strchr(argv[i], ':')) != NULL) { 88 else if ((sep = strchr(argv[i], ':')) != NULL) {
83 int sep_idx; 89 int sep_idx;
84 90
@@ -96,6 +102,7 @@ int cmd_list(int argc, const char **argv)
96 s[sep_idx] = '\0'; 102 s[sep_idx] = '\0';
97 print_tracepoint_events(s, s + sep_idx + 1, raw_dump); 103 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
98 print_sdt_events(s, s + sep_idx + 1, raw_dump); 104 print_sdt_events(s, s + sep_idx + 1, raw_dump);
105 metricgroup__print(true, true, s, raw_dump);
99 free(s); 106 free(s);
100 } else { 107 } else {
101 if (asprintf(&s, "*%s*", argv[i]) < 0) { 108 if (asprintf(&s, "*%s*", argv[i]) < 0) {
@@ -112,6 +119,7 @@ int cmd_list(int argc, const char **argv)
112 details_flag); 119 details_flag);
113 print_tracepoint_events(NULL, s, raw_dump); 120 print_tracepoint_events(NULL, s, raw_dump);
114 print_sdt_events(NULL, s, raw_dump); 121 print_sdt_events(NULL, s, raw_dump);
122 metricgroup__print(true, true, NULL, raw_dump);
115 free(s); 123 free(s);
116 } 124 }
117 } 125 }
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index ff98652484a7..6e0189df2b3b 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include "builtin.h" 4#include "builtin.h"
@@ -864,13 +865,15 @@ static int __cmd_report(bool display_info)
864 .namespaces = perf_event__process_namespaces, 865 .namespaces = perf_event__process_namespaces,
865 .ordered_events = true, 866 .ordered_events = true,
866 }; 867 };
867 struct perf_data_file file = { 868 struct perf_data data = {
868 .path = input_name, 869 .file = {
869 .mode = PERF_DATA_MODE_READ, 870 .path = input_name,
870 .force = force, 871 },
872 .mode = PERF_DATA_MODE_READ,
873 .force = force,
871 }; 874 };
872 875
873 session = perf_session__new(&file, false, &eops); 876 session = perf_session__new(&data, false, &eops);
874 if (!session) { 877 if (!session) {
875 pr_err("Initializing perf session failed\n"); 878 pr_err("Initializing perf session failed\n");
876 return -1; 879 return -1;
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 0f15634ef82c..506564651cda 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include <sys/types.h> 3#include <sys/types.h>
3#include <sys/stat.h> 4#include <sys/stat.h>
@@ -112,6 +113,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
112 if (!perf_mem_events[j].supported) { 113 if (!perf_mem_events[j].supported) {
113 pr_err("failed: event '%s' not supported\n", 114 pr_err("failed: event '%s' not supported\n",
114 perf_mem_events__name(j)); 115 perf_mem_events__name(j));
116 free(rec_argv);
115 return -1; 117 return -1;
116 } 118 }
117 119
@@ -235,13 +237,15 @@ static int process_sample_event(struct perf_tool *tool,
235 237
236static int report_raw_events(struct perf_mem *mem) 238static int report_raw_events(struct perf_mem *mem)
237{ 239{
238 struct perf_data_file file = { 240 struct perf_data data = {
239 .path = input_name, 241 .file = {
240 .mode = PERF_DATA_MODE_READ, 242 .path = input_name,
241 .force = mem->force, 243 },
244 .mode = PERF_DATA_MODE_READ,
245 .force = mem->force,
242 }; 246 };
243 int ret; 247 int ret;
244 struct perf_session *session = perf_session__new(&file, false, 248 struct perf_session *session = perf_session__new(&data, false,
245 &mem->tool); 249 &mem->tool);
246 250
247 if (session == NULL) 251 if (session == NULL)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 56f8142ff97f..3d7f33e19df2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-record.c 3 * builtin-record.c
3 * 4 *
@@ -66,7 +67,7 @@ struct record {
66 struct perf_tool tool; 67 struct perf_tool tool;
67 struct record_opts opts; 68 struct record_opts opts;
68 u64 bytes_written; 69 u64 bytes_written;
69 struct perf_data_file file; 70 struct perf_data data;
70 struct auxtrace_record *itr; 71 struct auxtrace_record *itr;
71 struct perf_evlist *evlist; 72 struct perf_evlist *evlist;
72 struct perf_session *session; 73 struct perf_session *session;
@@ -107,7 +108,7 @@ static bool switch_output_time(struct record *rec)
107 108
108static int record__write(struct record *rec, void *bf, size_t size) 109static int record__write(struct record *rec, void *bf, size_t size)
109{ 110{
110 if (perf_data_file__write(rec->session->file, bf, size) < 0) { 111 if (perf_data__write(rec->session->data, bf, size) < 0) {
111 pr_err("failed to write perf data, error: %m\n"); 112 pr_err("failed to write perf data, error: %m\n");
112 return -1; 113 return -1;
113 } 114 }
@@ -129,107 +130,12 @@ static int process_synthesized_event(struct perf_tool *tool,
129 return record__write(rec, event, event->header.size); 130 return record__write(rec, event, event->header.size);
130} 131}
131 132
132static int 133static int record__pushfn(void *to, void *bf, size_t size)
133backward_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
134{ 134{
135 struct perf_event_header *pheader; 135 struct record *rec = to;
136 u64 evt_head = head;
137 int size = mask + 1;
138
139 pr_debug2("backward_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
140 pheader = (struct perf_event_header *)(buf + (head & mask));
141 *start = head;
142 while (true) {
143 if (evt_head - head >= (unsigned int)size) {
144 pr_debug("Finished reading backward ring buffer: rewind\n");
145 if (evt_head - head > (unsigned int)size)
146 evt_head -= pheader->size;
147 *end = evt_head;
148 return 0;
149 }
150
151 pheader = (struct perf_event_header *)(buf + (evt_head & mask));
152
153 if (pheader->size == 0) {
154 pr_debug("Finished reading backward ring buffer: get start\n");
155 *end = evt_head;
156 return 0;
157 }
158
159 evt_head += pheader->size;
160 pr_debug3("move evt_head: %"PRIx64"\n", evt_head);
161 }
162 WARN_ONCE(1, "Shouldn't get here\n");
163 return -1;
164}
165
166static int
167rb_find_range(void *data, int mask, u64 head, u64 old,
168 u64 *start, u64 *end, bool backward)
169{
170 if (!backward) {
171 *start = old;
172 *end = head;
173 return 0;
174 }
175
176 return backward_rb_find_range(data, mask, head, start, end);
177}
178
179static int
180record__mmap_read(struct record *rec, struct perf_mmap *md,
181 bool overwrite, bool backward)
182{
183 u64 head = perf_mmap__read_head(md);
184 u64 old = md->prev;
185 u64 end = head, start = old;
186 unsigned char *data = md->base + page_size;
187 unsigned long size;
188 void *buf;
189 int rc = 0;
190
191 if (rb_find_range(data, md->mask, head,
192 old, &start, &end, backward))
193 return -1;
194
195 if (start == end)
196 return 0;
197 136
198 rec->samples++; 137 rec->samples++;
199 138 return record__write(rec, bf, size);
200 size = end - start;
201 if (size > (unsigned long)(md->mask) + 1) {
202 WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
203
204 md->prev = head;
205 perf_mmap__consume(md, overwrite || backward);
206 return 0;
207 }
208
209 if ((start & md->mask) + size != (end & md->mask)) {
210 buf = &data[start & md->mask];
211 size = md->mask + 1 - (start & md->mask);
212 start += size;
213
214 if (record__write(rec, buf, size) < 0) {
215 rc = -1;
216 goto out;
217 }
218 }
219
220 buf = &data[start & md->mask];
221 size = end - start;
222 start += size;
223
224 if (record__write(rec, buf, size) < 0) {
225 rc = -1;
226 goto out;
227 }
228
229 md->prev = head;
230 perf_mmap__consume(md, overwrite || backward);
231out:
232 return rc;
233} 139}
234 140
235static volatile int done; 141static volatile int done;
@@ -268,13 +174,13 @@ static int record__process_auxtrace(struct perf_tool *tool,
268 size_t len1, void *data2, size_t len2) 174 size_t len1, void *data2, size_t len2)
269{ 175{
270 struct record *rec = container_of(tool, struct record, tool); 176 struct record *rec = container_of(tool, struct record, tool);
271 struct perf_data_file *file = &rec->file; 177 struct perf_data *data = &rec->data;
272 size_t padding; 178 size_t padding;
273 u8 pad[8] = {0}; 179 u8 pad[8] = {0};
274 180
275 if (!perf_data_file__is_pipe(file)) { 181 if (!perf_data__is_pipe(data)) {
276 off_t file_offset; 182 off_t file_offset;
277 int fd = perf_data_file__fd(file); 183 int fd = perf_data__fd(data);
278 int err; 184 int err;
279 185
280 file_offset = lseek(fd, 0, SEEK_CUR); 186 file_offset = lseek(fd, 0, SEEK_CUR);
@@ -493,10 +399,10 @@ static int process_sample_event(struct perf_tool *tool,
493 399
494static int process_buildids(struct record *rec) 400static int process_buildids(struct record *rec)
495{ 401{
496 struct perf_data_file *file = &rec->file; 402 struct perf_data *data = &rec->data;
497 struct perf_session *session = rec->session; 403 struct perf_session *session = rec->session;
498 404
499 if (file->size == 0) 405 if (data->size == 0)
500 return 0; 406 return 0;
501 407
502 /* 408 /*
@@ -576,8 +482,7 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli
576 struct auxtrace_mmap *mm = &maps[i].auxtrace_mmap; 482 struct auxtrace_mmap *mm = &maps[i].auxtrace_mmap;
577 483
578 if (maps[i].base) { 484 if (maps[i].base) {
579 if (record__mmap_read(rec, &maps[i], 485 if (perf_mmap__push(&maps[i], evlist->overwrite, backward, rec, record__pushfn) != 0) {
580 evlist->overwrite, backward) != 0) {
581 rc = -1; 486 rc = -1;
582 goto out; 487 goto out;
583 } 488 }
@@ -640,14 +545,14 @@ static void record__init_features(struct record *rec)
640static void 545static void
641record__finish_output(struct record *rec) 546record__finish_output(struct record *rec)
642{ 547{
643 struct perf_data_file *file = &rec->file; 548 struct perf_data *data = &rec->data;
644 int fd = perf_data_file__fd(file); 549 int fd = perf_data__fd(data);
645 550
646 if (file->is_pipe) 551 if (data->is_pipe)
647 return; 552 return;
648 553
649 rec->session->header.data_size += rec->bytes_written; 554 rec->session->header.data_size += rec->bytes_written;
650 file->size = lseek(perf_data_file__fd(file), 0, SEEK_CUR); 555 data->size = lseek(perf_data__fd(data), 0, SEEK_CUR);
651 556
652 if (!rec->no_buildid) { 557 if (!rec->no_buildid) {
653 process_buildids(rec); 558 process_buildids(rec);
@@ -686,7 +591,7 @@ static int record__synthesize(struct record *rec, bool tail);
686static int 591static int
687record__switch_output(struct record *rec, bool at_exit) 592record__switch_output(struct record *rec, bool at_exit)
688{ 593{
689 struct perf_data_file *file = &rec->file; 594 struct perf_data *data = &rec->data;
690 int fd, err; 595 int fd, err;
691 596
692 /* Same Size: "2015122520103046"*/ 597 /* Same Size: "2015122520103046"*/
@@ -704,7 +609,7 @@ record__switch_output(struct record *rec, bool at_exit)
704 return -EINVAL; 609 return -EINVAL;
705 } 610 }
706 611
707 fd = perf_data_file__switch(file, timestamp, 612 fd = perf_data__switch(data, timestamp,
708 rec->session->header.data_offset, 613 rec->session->header.data_offset,
709 at_exit); 614 at_exit);
710 if (fd >= 0 && !at_exit) { 615 if (fd >= 0 && !at_exit) {
@@ -714,7 +619,7 @@ record__switch_output(struct record *rec, bool at_exit)
714 619
715 if (!quiet) 620 if (!quiet)
716 fprintf(stderr, "[ perf record: Dump %s.%s ]\n", 621 fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
717 file->path, timestamp); 622 data->file.path, timestamp);
718 623
719 /* Output tracking events */ 624 /* Output tracking events */
720 if (!at_exit) { 625 if (!at_exit) {
@@ -789,16 +694,16 @@ static int record__synthesize(struct record *rec, bool tail)
789{ 694{
790 struct perf_session *session = rec->session; 695 struct perf_session *session = rec->session;
791 struct machine *machine = &session->machines.host; 696 struct machine *machine = &session->machines.host;
792 struct perf_data_file *file = &rec->file; 697 struct perf_data *data = &rec->data;
793 struct record_opts *opts = &rec->opts; 698 struct record_opts *opts = &rec->opts;
794 struct perf_tool *tool = &rec->tool; 699 struct perf_tool *tool = &rec->tool;
795 int fd = perf_data_file__fd(file); 700 int fd = perf_data__fd(data);
796 int err = 0; 701 int err = 0;
797 702
798 if (rec->opts.tail_synthesize != tail) 703 if (rec->opts.tail_synthesize != tail)
799 return 0; 704 return 0;
800 705
801 if (file->is_pipe) { 706 if (data->is_pipe) {
802 err = perf_event__synthesize_features( 707 err = perf_event__synthesize_features(
803 tool, session, rec->evlist, process_synthesized_event); 708 tool, session, rec->evlist, process_synthesized_event);
804 if (err < 0) { 709 if (err < 0) {
@@ -863,7 +768,7 @@ static int record__synthesize(struct record *rec, bool tail)
863 768
864 err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads, 769 err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
865 process_synthesized_event, opts->sample_address, 770 process_synthesized_event, opts->sample_address,
866 opts->proc_map_timeout); 771 opts->proc_map_timeout, 1);
867out: 772out:
868 return err; 773 return err;
869} 774}
@@ -877,7 +782,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
877 struct machine *machine; 782 struct machine *machine;
878 struct perf_tool *tool = &rec->tool; 783 struct perf_tool *tool = &rec->tool;
879 struct record_opts *opts = &rec->opts; 784 struct record_opts *opts = &rec->opts;
880 struct perf_data_file *file = &rec->file; 785 struct perf_data *data = &rec->data;
881 struct perf_session *session; 786 struct perf_session *session;
882 bool disabled = false, draining = false; 787 bool disabled = false, draining = false;
883 int fd; 788 int fd;
@@ -903,20 +808,20 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
903 signal(SIGUSR2, SIG_IGN); 808 signal(SIGUSR2, SIG_IGN);
904 } 809 }
905 810
906 session = perf_session__new(file, false, tool); 811 session = perf_session__new(data, false, tool);
907 if (session == NULL) { 812 if (session == NULL) {
908 pr_err("Perf session creation failed.\n"); 813 pr_err("Perf session creation failed.\n");
909 return -1; 814 return -1;
910 } 815 }
911 816
912 fd = perf_data_file__fd(file); 817 fd = perf_data__fd(data);
913 rec->session = session; 818 rec->session = session;
914 819
915 record__init_features(rec); 820 record__init_features(rec);
916 821
917 if (forks) { 822 if (forks) {
918 err = perf_evlist__prepare_workload(rec->evlist, &opts->target, 823 err = perf_evlist__prepare_workload(rec->evlist, &opts->target,
919 argv, file->is_pipe, 824 argv, data->is_pipe,
920 workload_exec_failed_signal); 825 workload_exec_failed_signal);
921 if (err < 0) { 826 if (err < 0) {
922 pr_err("Couldn't run the workload!\n"); 827 pr_err("Couldn't run the workload!\n");
@@ -952,7 +857,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
952 if (!rec->evlist->nr_groups) 857 if (!rec->evlist->nr_groups)
953 perf_header__clear_feat(&session->header, HEADER_GROUP_DESC); 858 perf_header__clear_feat(&session->header, HEADER_GROUP_DESC);
954 859
955 if (file->is_pipe) { 860 if (data->is_pipe) {
956 err = perf_header__write_pipe(fd); 861 err = perf_header__write_pipe(fd);
957 if (err < 0) 862 if (err < 0)
958 goto out_child; 863 goto out_child;
@@ -1213,8 +1118,8 @@ out_child:
1213 samples[0] = '\0'; 1118 samples[0] = '\0';
1214 1119
1215 fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n", 1120 fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n",
1216 perf_data_file__size(file) / 1024.0 / 1024.0, 1121 perf_data__size(data) / 1024.0 / 1024.0,
1217 file->path, postfix, samples); 1122 data->file.path, postfix, samples);
1218 } 1123 }
1219 1124
1220out_delete_session: 1125out_delete_session:
@@ -1578,7 +1483,7 @@ static struct option __record_options[] = {
1578 OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu", 1483 OPT_STRING('C', "cpu", &record.opts.target.cpu_list, "cpu",
1579 "list of cpus to monitor"), 1484 "list of cpus to monitor"),
1580 OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"), 1485 OPT_U64('c', "count", &record.opts.user_interval, "event period to sample"),
1581 OPT_STRING('o', "output", &record.file.path, "file", 1486 OPT_STRING('o', "output", &record.data.file.path, "file",
1582 "output file name"), 1487 "output file name"),
1583 OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit, 1488 OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
1584 &record.opts.no_inherit_set, 1489 &record.opts.no_inherit_set,
@@ -1643,6 +1548,9 @@ static struct option __record_options[] = {
1643 OPT_CALLBACK_OPTARG('I', "intr-regs", &record.opts.sample_intr_regs, NULL, "any register", 1548 OPT_CALLBACK_OPTARG('I', "intr-regs", &record.opts.sample_intr_regs, NULL, "any register",
1644 "sample selected machine registers on interrupt," 1549 "sample selected machine registers on interrupt,"
1645 " use -I ? to list register names", parse_regs), 1550 " use -I ? to list register names", parse_regs),
1551 OPT_CALLBACK_OPTARG(0, "user-regs", &record.opts.sample_user_regs, NULL, "any register",
1552 "sample selected machine registers on interrupt,"
1553 " use -I ? to list register names", parse_regs),
1646 OPT_BOOLEAN(0, "running-time", &record.opts.running_time, 1554 OPT_BOOLEAN(0, "running-time", &record.opts.running_time,
1647 "Record running/enabled time of read (:S) events"), 1555 "Record running/enabled time of read (:S) events"),
1648 OPT_CALLBACK('k', "clockid", &record.opts, 1556 OPT_CALLBACK('k', "clockid", &record.opts,
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f9dff652dcbd..1394cd8d96f7 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-report.c 3 * builtin-report.c
3 * 4 *
@@ -257,7 +258,7 @@ static int report__setup_sample_type(struct report *rep)
257{ 258{
258 struct perf_session *session = rep->session; 259 struct perf_session *session = rep->session;
259 u64 sample_type = perf_evlist__combined_sample_type(session->evlist); 260 u64 sample_type = perf_evlist__combined_sample_type(session->evlist);
260 bool is_pipe = perf_data_file__is_pipe(session->file); 261 bool is_pipe = perf_data__is_pipe(session->data);
261 262
262 if (session->itrace_synth_opts->callchain || 263 if (session->itrace_synth_opts->callchain ||
263 (!is_pipe && 264 (!is_pipe &&
@@ -568,7 +569,7 @@ static int __cmd_report(struct report *rep)
568 int ret; 569 int ret;
569 struct perf_session *session = rep->session; 570 struct perf_session *session = rep->session;
570 struct perf_evsel *pos; 571 struct perf_evsel *pos;
571 struct perf_data_file *file = session->file; 572 struct perf_data *data = session->data;
572 573
573 signal(SIGINT, sig_handler); 574 signal(SIGINT, sig_handler);
574 575
@@ -637,7 +638,7 @@ static int __cmd_report(struct report *rep)
637 rep->nr_entries += evsel__hists(pos)->nr_entries; 638 rep->nr_entries += evsel__hists(pos)->nr_entries;
638 639
639 if (rep->nr_entries == 0) { 640 if (rep->nr_entries == 0) {
640 ui__error("The %s file has no samples!\n", file->path); 641 ui__error("The %s file has no samples!\n", data->file.path);
641 return 0; 642 return 0;
642 } 643 }
643 644
@@ -879,7 +880,7 @@ int cmd_report(int argc, const char **argv)
879 "Show inline function"), 880 "Show inline function"),
880 OPT_END() 881 OPT_END()
881 }; 882 };
882 struct perf_data_file file = { 883 struct perf_data data = {
883 .mode = PERF_DATA_MODE_READ, 884 .mode = PERF_DATA_MODE_READ,
884 }; 885 };
885 int ret = hists__init(); 886 int ret = hists__init();
@@ -940,11 +941,11 @@ int cmd_report(int argc, const char **argv)
940 input_name = "perf.data"; 941 input_name = "perf.data";
941 } 942 }
942 943
943 file.path = input_name; 944 data.file.path = input_name;
944 file.force = symbol_conf.force; 945 data.force = symbol_conf.force;
945 946
946repeat: 947repeat:
947 session = perf_session__new(&file, false, &report.tool); 948 session = perf_session__new(&data, false, &report.tool);
948 if (session == NULL) 949 if (session == NULL)
949 return -1; 950 return -1;
950 951
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 322b4def8411..83283fedb00f 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "builtin.h" 2#include "builtin.h"
2#include "perf.h" 3#include "perf.h"
3 4
@@ -1700,14 +1701,16 @@ static int perf_sched__read_events(struct perf_sched *sched)
1700 { "sched:sched_migrate_task", process_sched_migrate_task_event, }, 1701 { "sched:sched_migrate_task", process_sched_migrate_task_event, },
1701 }; 1702 };
1702 struct perf_session *session; 1703 struct perf_session *session;
1703 struct perf_data_file file = { 1704 struct perf_data data = {
1704 .path = input_name, 1705 .file = {
1705 .mode = PERF_DATA_MODE_READ, 1706 .path = input_name,
1706 .force = sched->force, 1707 },
1708 .mode = PERF_DATA_MODE_READ,
1709 .force = sched->force,
1707 }; 1710 };
1708 int rc = -1; 1711 int rc = -1;
1709 1712
1710 session = perf_session__new(&file, false, &sched->tool); 1713 session = perf_session__new(&data, false, &sched->tool);
1711 if (session == NULL) { 1714 if (session == NULL) {
1712 pr_debug("No Memory for session\n"); 1715 pr_debug("No Memory for session\n");
1713 return -1; 1716 return -1;
@@ -2902,10 +2905,12 @@ static int perf_sched__timehist(struct perf_sched *sched)
2902 const struct perf_evsel_str_handler migrate_handlers[] = { 2905 const struct perf_evsel_str_handler migrate_handlers[] = {
2903 { "sched:sched_migrate_task", timehist_migrate_task_event, }, 2906 { "sched:sched_migrate_task", timehist_migrate_task_event, },
2904 }; 2907 };
2905 struct perf_data_file file = { 2908 struct perf_data data = {
2906 .path = input_name, 2909 .file = {
2907 .mode = PERF_DATA_MODE_READ, 2910 .path = input_name,
2908 .force = sched->force, 2911 },
2912 .mode = PERF_DATA_MODE_READ,
2913 .force = sched->force,
2909 }; 2914 };
2910 2915
2911 struct perf_session *session; 2916 struct perf_session *session;
@@ -2930,7 +2935,7 @@ static int perf_sched__timehist(struct perf_sched *sched)
2930 2935
2931 symbol_conf.use_callchain = sched->show_callchain; 2936 symbol_conf.use_callchain = sched->show_callchain;
2932 2937
2933 session = perf_session__new(&file, false, &sched->tool); 2938 session = perf_session__new(&data, false, &sched->tool);
2934 if (session == NULL) 2939 if (session == NULL)
2935 return -ENOMEM; 2940 return -ENOMEM;
2936 2941
@@ -3363,6 +3368,10 @@ int cmd_sched(int argc, const char **argv)
3363 OPT_STRING(0, "time", &sched.time_str, "str", 3368 OPT_STRING(0, "time", &sched.time_str, "str",
3364 "Time span for analysis (start,stop)"), 3369 "Time span for analysis (start,stop)"),
3365 OPT_BOOLEAN(0, "state", &sched.show_state, "Show task state when sched-out"), 3370 OPT_BOOLEAN(0, "state", &sched.show_state, "Show task state when sched-out"),
3371 OPT_STRING('p', "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
3372 "analyze events only for given process id(s)"),
3373 OPT_STRING('t', "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
3374 "analyze events only for given thread id(s)"),
3366 OPT_PARENT(sched_options) 3375 OPT_PARENT(sched_options)
3367 }; 3376 };
3368 3377
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 3d4c3b5e1868..68f36dc0344f 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "builtin.h" 2#include "builtin.h"
2 3
3#include "perf.h" 4#include "perf.h"
@@ -88,6 +89,7 @@ enum perf_output_field {
88 PERF_OUTPUT_BRSTACKOFF = 1U << 24, 89 PERF_OUTPUT_BRSTACKOFF = 1U << 24,
89 PERF_OUTPUT_SYNTH = 1U << 25, 90 PERF_OUTPUT_SYNTH = 1U << 25,
90 PERF_OUTPUT_PHYS_ADDR = 1U << 26, 91 PERF_OUTPUT_PHYS_ADDR = 1U << 26,
92 PERF_OUTPUT_UREGS = 1U << 27,
91}; 93};
92 94
93struct output_option { 95struct output_option {
@@ -109,6 +111,7 @@ struct output_option {
109 {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, 111 {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
110 {.str = "period", .field = PERF_OUTPUT_PERIOD}, 112 {.str = "period", .field = PERF_OUTPUT_PERIOD},
111 {.str = "iregs", .field = PERF_OUTPUT_IREGS}, 113 {.str = "iregs", .field = PERF_OUTPUT_IREGS},
114 {.str = "uregs", .field = PERF_OUTPUT_UREGS},
112 {.str = "brstack", .field = PERF_OUTPUT_BRSTACK}, 115 {.str = "brstack", .field = PERF_OUTPUT_BRSTACK},
113 {.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM}, 116 {.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM},
114 {.str = "data_src", .field = PERF_OUTPUT_DATA_SRC}, 117 {.str = "data_src", .field = PERF_OUTPUT_DATA_SRC},
@@ -208,6 +211,51 @@ static struct {
208 }, 211 },
209}; 212};
210 213
214struct perf_evsel_script {
215 char *filename;
216 FILE *fp;
217 u64 samples;
218};
219
220static struct perf_evsel_script *perf_evsel_script__new(struct perf_evsel *evsel,
221 struct perf_data *data)
222{
223 struct perf_evsel_script *es = malloc(sizeof(*es));
224
225 if (es != NULL) {
226 if (asprintf(&es->filename, "%s.%s.dump", data->file.path, perf_evsel__name(evsel)) < 0)
227 goto out_free;
228 es->fp = fopen(es->filename, "w");
229 if (es->fp == NULL)
230 goto out_free_filename;
231 es->samples = 0;
232 }
233
234 return es;
235out_free_filename:
236 zfree(&es->filename);
237out_free:
238 free(es);
239 return NULL;
240}
241
242static void perf_evsel_script__delete(struct perf_evsel_script *es)
243{
244 zfree(&es->filename);
245 fclose(es->fp);
246 es->fp = NULL;
247 free(es);
248}
249
250static int perf_evsel_script__fprintf(struct perf_evsel_script *es, FILE *fp)
251{
252 struct stat st;
253
254 fstat(fileno(es->fp), &st);
255 return fprintf(fp, "[ perf script: Wrote %.3f MB %s (%" PRIu64 " samples) ]\n",
256 st.st_size / 1024.0 / 1024.0, es->filename, es->samples);
257}
258
211static inline int output_type(unsigned int type) 259static inline int output_type(unsigned int type)
212{ 260{
213 switch (type) { 261 switch (type) {
@@ -385,6 +433,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
385 PERF_OUTPUT_IREGS)) 433 PERF_OUTPUT_IREGS))
386 return -EINVAL; 434 return -EINVAL;
387 435
436 if (PRINT_FIELD(UREGS) &&
437 perf_evsel__check_stype(evsel, PERF_SAMPLE_REGS_USER, "UREGS",
438 PERF_OUTPUT_UREGS))
439 return -EINVAL;
440
388 if (PRINT_FIELD(PHYS_ADDR) && 441 if (PRINT_FIELD(PHYS_ADDR) &&
389 perf_evsel__check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR", 442 perf_evsel__check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR",
390 PERF_OUTPUT_PHYS_ADDR)) 443 PERF_OUTPUT_PHYS_ADDR))
@@ -493,51 +546,76 @@ out:
493 return 0; 546 return 0;
494} 547}
495 548
496static void print_sample_iregs(struct perf_sample *sample, 549static int perf_sample__fprintf_iregs(struct perf_sample *sample,
497 struct perf_event_attr *attr) 550 struct perf_event_attr *attr, FILE *fp)
498{ 551{
499 struct regs_dump *regs = &sample->intr_regs; 552 struct regs_dump *regs = &sample->intr_regs;
500 uint64_t mask = attr->sample_regs_intr; 553 uint64_t mask = attr->sample_regs_intr;
501 unsigned i = 0, r; 554 unsigned i = 0, r;
555 int printed = 0;
502 556
503 if (!regs) 557 if (!regs)
504 return; 558 return 0;
505 559
506 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { 560 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
507 u64 val = regs->regs[i++]; 561 u64 val = regs->regs[i++];
508 printf("%5s:0x%"PRIx64" ", perf_reg_name(r), val); 562 printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r), val);
509 } 563 }
564
565 return printed;
510} 566}
511 567
512static void print_sample_start(struct perf_sample *sample, 568static int perf_sample__fprintf_uregs(struct perf_sample *sample,
513 struct thread *thread, 569 struct perf_event_attr *attr, FILE *fp)
514 struct perf_evsel *evsel) 570{
571 struct regs_dump *regs = &sample->user_regs;
572 uint64_t mask = attr->sample_regs_user;
573 unsigned i = 0, r;
574 int printed = 0;
575
576 if (!regs || !regs->regs)
577 return 0;
578
579 printed += fprintf(fp, " ABI:%" PRIu64 " ", regs->abi);
580
581 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
582 u64 val = regs->regs[i++];
583 printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r), val);
584 }
585
586 return printed;
587}
588
589static int perf_sample__fprintf_start(struct perf_sample *sample,
590 struct thread *thread,
591 struct perf_evsel *evsel, FILE *fp)
515{ 592{
516 struct perf_event_attr *attr = &evsel->attr; 593 struct perf_event_attr *attr = &evsel->attr;
517 unsigned long secs; 594 unsigned long secs;
518 unsigned long long nsecs; 595 unsigned long long nsecs;
596 int printed = 0;
519 597
520 if (PRINT_FIELD(COMM)) { 598 if (PRINT_FIELD(COMM)) {
521 if (latency_format) 599 if (latency_format)
522 printf("%8.8s ", thread__comm_str(thread)); 600 printed += fprintf(fp, "%8.8s ", thread__comm_str(thread));
523 else if (PRINT_FIELD(IP) && symbol_conf.use_callchain) 601 else if (PRINT_FIELD(IP) && symbol_conf.use_callchain)
524 printf("%s ", thread__comm_str(thread)); 602 printed += fprintf(fp, "%s ", thread__comm_str(thread));
525 else 603 else
526 printf("%16s ", thread__comm_str(thread)); 604 printed += fprintf(fp, "%16s ", thread__comm_str(thread));
527 } 605 }
528 606
529 if (PRINT_FIELD(PID) && PRINT_FIELD(TID)) 607 if (PRINT_FIELD(PID) && PRINT_FIELD(TID))
530 printf("%5d/%-5d ", sample->pid, sample->tid); 608 printed += fprintf(fp, "%5d/%-5d ", sample->pid, sample->tid);
531 else if (PRINT_FIELD(PID)) 609 else if (PRINT_FIELD(PID))
532 printf("%5d ", sample->pid); 610 printed += fprintf(fp, "%5d ", sample->pid);
533 else if (PRINT_FIELD(TID)) 611 else if (PRINT_FIELD(TID))
534 printf("%5d ", sample->tid); 612 printed += fprintf(fp, "%5d ", sample->tid);
535 613
536 if (PRINT_FIELD(CPU)) { 614 if (PRINT_FIELD(CPU)) {
537 if (latency_format) 615 if (latency_format)
538 printf("%3d ", sample->cpu); 616 printed += fprintf(fp, "%3d ", sample->cpu);
539 else 617 else
540 printf("[%03d] ", sample->cpu); 618 printed += fprintf(fp, "[%03d] ", sample->cpu);
541 } 619 }
542 620
543 if (PRINT_FIELD(TIME)) { 621 if (PRINT_FIELD(TIME)) {
@@ -546,13 +624,15 @@ static void print_sample_start(struct perf_sample *sample,
546 nsecs -= secs * NSEC_PER_SEC; 624 nsecs -= secs * NSEC_PER_SEC;
547 625
548 if (nanosecs) 626 if (nanosecs)
549 printf("%5lu.%09llu: ", secs, nsecs); 627 printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs);
550 else { 628 else {
551 char sample_time[32]; 629 char sample_time[32];
552 timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time)); 630 timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time));
553 printf("%12s: ", sample_time); 631 printed += fprintf(fp, "%12s: ", sample_time);
554 } 632 }
555 } 633 }
634
635 return printed;
556} 636}
557 637
558static inline char 638static inline char
@@ -564,16 +644,17 @@ mispred_str(struct branch_entry *br)
564 return br->flags.predicted ? 'P' : 'M'; 644 return br->flags.predicted ? 'P' : 'M';
565} 645}
566 646
567static void print_sample_brstack(struct perf_sample *sample, 647static int perf_sample__fprintf_brstack(struct perf_sample *sample,
568 struct thread *thread, 648 struct thread *thread,
569 struct perf_event_attr *attr) 649 struct perf_event_attr *attr, FILE *fp)
570{ 650{
571 struct branch_stack *br = sample->branch_stack; 651 struct branch_stack *br = sample->branch_stack;
572 struct addr_location alf, alt; 652 struct addr_location alf, alt;
573 u64 i, from, to; 653 u64 i, from, to;
654 int printed = 0;
574 655
575 if (!(br && br->nr)) 656 if (!(br && br->nr))
576 return; 657 return 0;
577 658
578 for (i = 0; i < br->nr; i++) { 659 for (i = 0; i < br->nr; i++) {
579 from = br->entries[i].from; 660 from = br->entries[i].from;
@@ -586,38 +667,41 @@ static void print_sample_brstack(struct perf_sample *sample,
586 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt); 667 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
587 } 668 }
588 669
589 printf("0x%"PRIx64, from); 670 printed += fprintf(fp, " 0x%"PRIx64, from);
590 if (PRINT_FIELD(DSO)) { 671 if (PRINT_FIELD(DSO)) {
591 printf("("); 672 printed += fprintf(fp, "(");
592 map__fprintf_dsoname(alf.map, stdout); 673 printed += map__fprintf_dsoname(alf.map, fp);
593 printf(")"); 674 printed += fprintf(fp, ")");
594 } 675 }
595 676
596 printf("/0x%"PRIx64, to); 677 printed += fprintf(fp, "/0x%"PRIx64, to);
597 if (PRINT_FIELD(DSO)) { 678 if (PRINT_FIELD(DSO)) {
598 printf("("); 679 printed += fprintf(fp, "(");
599 map__fprintf_dsoname(alt.map, stdout); 680 printed += map__fprintf_dsoname(alt.map, fp);
600 printf(")"); 681 printed += fprintf(fp, ")");
601 } 682 }
602 683
603 printf("/%c/%c/%c/%d ", 684 printed += fprintf(fp, "/%c/%c/%c/%d ",
604 mispred_str( br->entries + i), 685 mispred_str( br->entries + i),
605 br->entries[i].flags.in_tx? 'X' : '-', 686 br->entries[i].flags.in_tx? 'X' : '-',
606 br->entries[i].flags.abort? 'A' : '-', 687 br->entries[i].flags.abort? 'A' : '-',
607 br->entries[i].flags.cycles); 688 br->entries[i].flags.cycles);
608 } 689 }
690
691 return printed;
609} 692}
610 693
611static void print_sample_brstacksym(struct perf_sample *sample, 694static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,
612 struct thread *thread, 695 struct thread *thread,
613 struct perf_event_attr *attr) 696 struct perf_event_attr *attr, FILE *fp)
614{ 697{
615 struct branch_stack *br = sample->branch_stack; 698 struct branch_stack *br = sample->branch_stack;
616 struct addr_location alf, alt; 699 struct addr_location alf, alt;
617 u64 i, from, to; 700 u64 i, from, to;
701 int printed = 0;
618 702
619 if (!(br && br->nr)) 703 if (!(br && br->nr))
620 return; 704 return 0;
621 705
622 for (i = 0; i < br->nr; i++) { 706 for (i = 0; i < br->nr; i++) {
623 707
@@ -634,37 +718,40 @@ static void print_sample_brstacksym(struct perf_sample *sample,
634 if (alt.map) 718 if (alt.map)
635 alt.sym = map__find_symbol(alt.map, alt.addr); 719 alt.sym = map__find_symbol(alt.map, alt.addr);
636 720
637 symbol__fprintf_symname_offs(alf.sym, &alf, stdout); 721 printed += symbol__fprintf_symname_offs(alf.sym, &alf, fp);
638 if (PRINT_FIELD(DSO)) { 722 if (PRINT_FIELD(DSO)) {
639 printf("("); 723 printed += fprintf(fp, "(");
640 map__fprintf_dsoname(alf.map, stdout); 724 printed += map__fprintf_dsoname(alf.map, fp);
641 printf(")"); 725 printed += fprintf(fp, ")");
642 } 726 }
643 putchar('/'); 727 printed += fprintf(fp, "%c", '/');
644 symbol__fprintf_symname_offs(alt.sym, &alt, stdout); 728 printed += symbol__fprintf_symname_offs(alt.sym, &alt, fp);
645 if (PRINT_FIELD(DSO)) { 729 if (PRINT_FIELD(DSO)) {
646 printf("("); 730 printed += fprintf(fp, "(");
647 map__fprintf_dsoname(alt.map, stdout); 731 printed += map__fprintf_dsoname(alt.map, fp);
648 printf(")"); 732 printed += fprintf(fp, ")");
649 } 733 }
650 printf("/%c/%c/%c/%d ", 734 printed += fprintf(fp, "/%c/%c/%c/%d ",
651 mispred_str( br->entries + i), 735 mispred_str( br->entries + i),
652 br->entries[i].flags.in_tx? 'X' : '-', 736 br->entries[i].flags.in_tx? 'X' : '-',
653 br->entries[i].flags.abort? 'A' : '-', 737 br->entries[i].flags.abort? 'A' : '-',
654 br->entries[i].flags.cycles); 738 br->entries[i].flags.cycles);
655 } 739 }
740
741 return printed;
656} 742}
657 743
658static void print_sample_brstackoff(struct perf_sample *sample, 744static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
659 struct thread *thread, 745 struct thread *thread,
660 struct perf_event_attr *attr) 746 struct perf_event_attr *attr, FILE *fp)
661{ 747{
662 struct branch_stack *br = sample->branch_stack; 748 struct branch_stack *br = sample->branch_stack;
663 struct addr_location alf, alt; 749 struct addr_location alf, alt;
664 u64 i, from, to; 750 u64 i, from, to;
751 int printed = 0;
665 752
666 if (!(br && br->nr)) 753 if (!(br && br->nr))
667 return; 754 return 0;
668 755
669 for (i = 0; i < br->nr; i++) { 756 for (i = 0; i < br->nr; i++) {
670 757
@@ -681,24 +768,26 @@ static void print_sample_brstackoff(struct perf_sample *sample,
681 if (alt.map && !alt.map->dso->adjust_symbols) 768 if (alt.map && !alt.map->dso->adjust_symbols)
682 to = map__map_ip(alt.map, to); 769 to = map__map_ip(alt.map, to);
683 770
684 printf("0x%"PRIx64, from); 771 printed += fprintf(fp, " 0x%"PRIx64, from);
685 if (PRINT_FIELD(DSO)) { 772 if (PRINT_FIELD(DSO)) {
686 printf("("); 773 printed += fprintf(fp, "(");
687 map__fprintf_dsoname(alf.map, stdout); 774 printed += map__fprintf_dsoname(alf.map, fp);
688 printf(")"); 775 printed += fprintf(fp, ")");
689 } 776 }
690 printf("/0x%"PRIx64, to); 777 printed += fprintf(fp, "/0x%"PRIx64, to);
691 if (PRINT_FIELD(DSO)) { 778 if (PRINT_FIELD(DSO)) {
692 printf("("); 779 printed += fprintf(fp, "(");
693 map__fprintf_dsoname(alt.map, stdout); 780 printed += map__fprintf_dsoname(alt.map, fp);
694 printf(")"); 781 printed += fprintf(fp, ")");
695 } 782 }
696 printf("/%c/%c/%c/%d ", 783 printed += fprintf(fp, "/%c/%c/%c/%d ",
697 mispred_str(br->entries + i), 784 mispred_str(br->entries + i),
698 br->entries[i].flags.in_tx ? 'X' : '-', 785 br->entries[i].flags.in_tx ? 'X' : '-',
699 br->entries[i].flags.abort ? 'A' : '-', 786 br->entries[i].flags.abort ? 'A' : '-',
700 br->entries[i].flags.cycles); 787 br->entries[i].flags.cycles);
701 } 788 }
789
790 return printed;
702} 791}
703#define MAXBB 16384UL 792#define MAXBB 16384UL
704 793
@@ -726,27 +815,26 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
726 * but the exit is not. Let the caller patch it up. 815 * but the exit is not. Let the caller patch it up.
727 */ 816 */
728 if (kernel != machine__kernel_ip(machine, end)) { 817 if (kernel != machine__kernel_ip(machine, end)) {
729 printf("\tblock %" PRIx64 "-%" PRIx64 " transfers between kernel and user\n", 818 pr_debug("\tblock %" PRIx64 "-%" PRIx64 " transfers between kernel and user\n", start, end);
730 start, end);
731 return -ENXIO; 819 return -ENXIO;
732 } 820 }
733 821
734 memset(&al, 0, sizeof(al)); 822 memset(&al, 0, sizeof(al));
735 if (end - start > MAXBB - MAXINSN) { 823 if (end - start > MAXBB - MAXINSN) {
736 if (last) 824 if (last)
737 printf("\tbrstack does not reach to final jump (%" PRIx64 "-%" PRIx64 ")\n", start, end); 825 pr_debug("\tbrstack does not reach to final jump (%" PRIx64 "-%" PRIx64 ")\n", start, end);
738 else 826 else
739 printf("\tblock %" PRIx64 "-%" PRIx64 " (%" PRIu64 ") too long to dump\n", start, end, end - start); 827 pr_debug("\tblock %" PRIx64 "-%" PRIx64 " (%" PRIu64 ") too long to dump\n", start, end, end - start);
740 return 0; 828 return 0;
741 } 829 }
742 830
743 thread__find_addr_map(thread, *cpumode, MAP__FUNCTION, start, &al); 831 thread__find_addr_map(thread, *cpumode, MAP__FUNCTION, start, &al);
744 if (!al.map || !al.map->dso) { 832 if (!al.map || !al.map->dso) {
745 printf("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); 833 pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
746 return 0; 834 return 0;
747 } 835 }
748 if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) { 836 if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) {
749 printf("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); 837 pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
750 return 0; 838 return 0;
751 } 839 }
752 840
@@ -759,36 +847,35 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
759 847
760 *is64bit = al.map->dso->is_64_bit; 848 *is64bit = al.map->dso->is_64_bit;
761 if (len <= 0) 849 if (len <= 0)
762 printf("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n", 850 pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
763 start, end); 851 start, end);
764 return len; 852 return len;
765} 853}
766 854
767static void print_jump(uint64_t ip, struct branch_entry *en, 855static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,
768 struct perf_insn *x, u8 *inbuf, int len, 856 struct perf_insn *x, u8 *inbuf, int len,
769 int insn) 857 int insn, FILE *fp)
770{ 858{
771 printf("\t%016" PRIx64 "\t%-30s\t#%s%s%s%s", 859 int printed = fprintf(fp, "\t%016" PRIx64 "\t%-30s\t#%s%s%s%s", ip,
772 ip, 860 dump_insn(x, ip, inbuf, len, NULL),
773 dump_insn(x, ip, inbuf, len, NULL), 861 en->flags.predicted ? " PRED" : "",
774 en->flags.predicted ? " PRED" : "", 862 en->flags.mispred ? " MISPRED" : "",
775 en->flags.mispred ? " MISPRED" : "", 863 en->flags.in_tx ? " INTX" : "",
776 en->flags.in_tx ? " INTX" : "", 864 en->flags.abort ? " ABORT" : "");
777 en->flags.abort ? " ABORT" : "");
778 if (en->flags.cycles) { 865 if (en->flags.cycles) {
779 printf(" %d cycles", en->flags.cycles); 866 printed += fprintf(fp, " %d cycles", en->flags.cycles);
780 if (insn) 867 if (insn)
781 printf(" %.2f IPC", (float)insn / en->flags.cycles); 868 printed += fprintf(fp, " %.2f IPC", (float)insn / en->flags.cycles);
782 } 869 }
783 putchar('\n'); 870 return printed + fprintf(fp, "\n");
784} 871}
785 872
786static void print_ip_sym(struct thread *thread, u8 cpumode, int cpu, 873static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
787 uint64_t addr, struct symbol **lastsym, 874 u8 cpumode, int cpu, struct symbol **lastsym,
788 struct perf_event_attr *attr) 875 struct perf_event_attr *attr, FILE *fp)
789{ 876{
790 struct addr_location al; 877 struct addr_location al;
791 int off; 878 int off, printed = 0;
792 879
793 memset(&al, 0, sizeof(al)); 880 memset(&al, 0, sizeof(al));
794 881
@@ -797,7 +884,7 @@ static void print_ip_sym(struct thread *thread, u8 cpumode, int cpu,
797 thread__find_addr_map(thread, cpumode, MAP__VARIABLE, 884 thread__find_addr_map(thread, cpumode, MAP__VARIABLE,
798 addr, &al); 885 addr, &al);
799 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) 886 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end)
800 return; 887 return 0;
801 888
802 al.cpu = cpu; 889 al.cpu = cpu;
803 al.sym = NULL; 890 al.sym = NULL;
@@ -805,37 +892,39 @@ static void print_ip_sym(struct thread *thread, u8 cpumode, int cpu,
805 al.sym = map__find_symbol(al.map, al.addr); 892 al.sym = map__find_symbol(al.map, al.addr);
806 893
807 if (!al.sym) 894 if (!al.sym)
808 return; 895 return 0;
809 896
810 if (al.addr < al.sym->end) 897 if (al.addr < al.sym->end)
811 off = al.addr - al.sym->start; 898 off = al.addr - al.sym->start;
812 else 899 else
813 off = al.addr - al.map->start - al.sym->start; 900 off = al.addr - al.map->start - al.sym->start;
814 printf("\t%s", al.sym->name); 901 printed += fprintf(fp, "\t%s", al.sym->name);
815 if (off) 902 if (off)
816 printf("%+d", off); 903 printed += fprintf(fp, "%+d", off);
817 putchar(':'); 904 printed += fprintf(fp, ":");
818 if (PRINT_FIELD(SRCLINE)) 905 if (PRINT_FIELD(SRCLINE))
819 map__fprintf_srcline(al.map, al.addr, "\t", stdout); 906 printed += map__fprintf_srcline(al.map, al.addr, "\t", fp);
820 putchar('\n'); 907 printed += fprintf(fp, "\n");
821 *lastsym = al.sym; 908 *lastsym = al.sym;
909
910 return printed;
822} 911}
823 912
824static void print_sample_brstackinsn(struct perf_sample *sample, 913static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
825 struct thread *thread, 914 struct thread *thread,
826 struct perf_event_attr *attr, 915 struct perf_event_attr *attr,
827 struct machine *machine) 916 struct machine *machine, FILE *fp)
828{ 917{
829 struct branch_stack *br = sample->branch_stack; 918 struct branch_stack *br = sample->branch_stack;
830 u64 start, end; 919 u64 start, end;
831 int i, insn, len, nr, ilen; 920 int i, insn, len, nr, ilen, printed = 0;
832 struct perf_insn x; 921 struct perf_insn x;
833 u8 buffer[MAXBB]; 922 u8 buffer[MAXBB];
834 unsigned off; 923 unsigned off;
835 struct symbol *lastsym = NULL; 924 struct symbol *lastsym = NULL;
836 925
837 if (!(br && br->nr)) 926 if (!(br && br->nr))
838 return; 927 return 0;
839 nr = br->nr; 928 nr = br->nr;
840 if (max_blocks && nr > max_blocks + 1) 929 if (max_blocks && nr > max_blocks + 1)
841 nr = max_blocks + 1; 930 nr = max_blocks + 1;
@@ -843,17 +932,17 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
843 x.thread = thread; 932 x.thread = thread;
844 x.cpu = sample->cpu; 933 x.cpu = sample->cpu;
845 934
846 putchar('\n'); 935 printed += fprintf(fp, "%c", '\n');
847 936
848 /* Handle first from jump, of which we don't know the entry. */ 937 /* Handle first from jump, of which we don't know the entry. */
849 len = grab_bb(buffer, br->entries[nr-1].from, 938 len = grab_bb(buffer, br->entries[nr-1].from,
850 br->entries[nr-1].from, 939 br->entries[nr-1].from,
851 machine, thread, &x.is64bit, &x.cpumode, false); 940 machine, thread, &x.is64bit, &x.cpumode, false);
852 if (len > 0) { 941 if (len > 0) {
853 print_ip_sym(thread, x.cpumode, x.cpu, 942 printed += ip__fprintf_sym(br->entries[nr - 1].from, thread,
854 br->entries[nr - 1].from, &lastsym, attr); 943 x.cpumode, x.cpu, &lastsym, attr, fp);
855 print_jump(br->entries[nr - 1].from, &br->entries[nr - 1], 944 printed += ip__fprintf_jump(br->entries[nr - 1].from, &br->entries[nr - 1],
856 &x, buffer, len, 0); 945 &x, buffer, len, 0, fp);
857 } 946 }
858 947
859 /* Print all blocks */ 948 /* Print all blocks */
@@ -879,13 +968,13 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
879 for (off = 0;; off += ilen) { 968 for (off = 0;; off += ilen) {
880 uint64_t ip = start + off; 969 uint64_t ip = start + off;
881 970
882 print_ip_sym(thread, x.cpumode, x.cpu, ip, &lastsym, attr); 971 printed += ip__fprintf_sym(ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
883 if (ip == end) { 972 if (ip == end) {
884 print_jump(ip, &br->entries[i], &x, buffer + off, len - off, insn); 973 printed += ip__fprintf_jump(ip, &br->entries[i], &x, buffer + off, len - off, insn, fp);
885 break; 974 break;
886 } else { 975 } else {
887 printf("\t%016" PRIx64 "\t%s\n", ip, 976 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", ip,
888 dump_insn(&x, ip, buffer + off, len - off, &ilen)); 977 dump_insn(&x, ip, buffer + off, len - off, &ilen));
889 if (ilen == 0) 978 if (ilen == 0)
890 break; 979 break;
891 insn++; 980 insn++;
@@ -898,9 +987,9 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
898 * has not been executed yet. 987 * has not been executed yet.
899 */ 988 */
900 if (br->entries[0].from == sample->ip) 989 if (br->entries[0].from == sample->ip)
901 return; 990 goto out;
902 if (br->entries[0].flags.abort) 991 if (br->entries[0].flags.abort)
903 return; 992 goto out;
904 993
905 /* 994 /*
906 * Print final block upto sample 995 * Print final block upto sample
@@ -908,58 +997,61 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
908 start = br->entries[0].to; 997 start = br->entries[0].to;
909 end = sample->ip; 998 end = sample->ip;
910 len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, true); 999 len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, true);
911 print_ip_sym(thread, x.cpumode, x.cpu, start, &lastsym, attr); 1000 printed += ip__fprintf_sym(start, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
912 if (len <= 0) { 1001 if (len <= 0) {
913 /* Print at least last IP if basic block did not work */ 1002 /* Print at least last IP if basic block did not work */
914 len = grab_bb(buffer, sample->ip, sample->ip, 1003 len = grab_bb(buffer, sample->ip, sample->ip,
915 machine, thread, &x.is64bit, &x.cpumode, false); 1004 machine, thread, &x.is64bit, &x.cpumode, false);
916 if (len <= 0) 1005 if (len <= 0)
917 return; 1006 goto out;
918 1007
919 printf("\t%016" PRIx64 "\t%s\n", sample->ip, 1008 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", sample->ip,
920 dump_insn(&x, sample->ip, buffer, len, NULL)); 1009 dump_insn(&x, sample->ip, buffer, len, NULL));
921 return; 1010 goto out;
922 } 1011 }
923 for (off = 0; off <= end - start; off += ilen) { 1012 for (off = 0; off <= end - start; off += ilen) {
924 printf("\t%016" PRIx64 "\t%s\n", start + off, 1013 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", start + off,
925 dump_insn(&x, start + off, buffer + off, len - off, &ilen)); 1014 dump_insn(&x, start + off, buffer + off, len - off, &ilen));
926 if (ilen == 0) 1015 if (ilen == 0)
927 break; 1016 break;
928 } 1017 }
1018out:
1019 return printed;
929} 1020}
930 1021
931static void print_sample_addr(struct perf_sample *sample, 1022static int perf_sample__fprintf_addr(struct perf_sample *sample,
932 struct thread *thread, 1023 struct thread *thread,
933 struct perf_event_attr *attr) 1024 struct perf_event_attr *attr, FILE *fp)
934{ 1025{
935 struct addr_location al; 1026 struct addr_location al;
936 1027 int printed = fprintf(fp, "%16" PRIx64, sample->addr);
937 printf("%16" PRIx64, sample->addr);
938 1028
939 if (!sample_addr_correlates_sym(attr)) 1029 if (!sample_addr_correlates_sym(attr))
940 return; 1030 goto out;
941 1031
942 thread__resolve(thread, &al, sample); 1032 thread__resolve(thread, &al, sample);
943 1033
944 if (PRINT_FIELD(SYM)) { 1034 if (PRINT_FIELD(SYM)) {
945 printf(" "); 1035 printed += fprintf(fp, " ");
946 if (PRINT_FIELD(SYMOFFSET)) 1036 if (PRINT_FIELD(SYMOFFSET))
947 symbol__fprintf_symname_offs(al.sym, &al, stdout); 1037 printed += symbol__fprintf_symname_offs(al.sym, &al, fp);
948 else 1038 else
949 symbol__fprintf_symname(al.sym, stdout); 1039 printed += symbol__fprintf_symname(al.sym, fp);
950 } 1040 }
951 1041
952 if (PRINT_FIELD(DSO)) { 1042 if (PRINT_FIELD(DSO)) {
953 printf(" ("); 1043 printed += fprintf(fp, " (");
954 map__fprintf_dsoname(al.map, stdout); 1044 printed += map__fprintf_dsoname(al.map, fp);
955 printf(")"); 1045 printed += fprintf(fp, ")");
956 } 1046 }
1047out:
1048 return printed;
957} 1049}
958 1050
959static void print_sample_callindent(struct perf_sample *sample, 1051static int perf_sample__fprintf_callindent(struct perf_sample *sample,
960 struct perf_evsel *evsel, 1052 struct perf_evsel *evsel,
961 struct thread *thread, 1053 struct thread *thread,
962 struct addr_location *al) 1054 struct addr_location *al, FILE *fp)
963{ 1055{
964 struct perf_event_attr *attr = &evsel->attr; 1056 struct perf_event_attr *attr = &evsel->attr;
965 size_t depth = thread_stack__depth(thread); 1057 size_t depth = thread_stack__depth(thread);
@@ -994,12 +1086,12 @@ static void print_sample_callindent(struct perf_sample *sample,
994 } 1086 }
995 1087
996 if (name) 1088 if (name)
997 len = printf("%*s%s", (int)depth * 4, "", name); 1089 len = fprintf(fp, "%*s%s", (int)depth * 4, "", name);
998 else if (ip) 1090 else if (ip)
999 len = printf("%*s%16" PRIx64, (int)depth * 4, "", ip); 1091 len = fprintf(fp, "%*s%16" PRIx64, (int)depth * 4, "", ip);
1000 1092
1001 if (len < 0) 1093 if (len < 0)
1002 return; 1094 return len;
1003 1095
1004 /* 1096 /*
1005 * Try to keep the output length from changing frequently so that the 1097 * Try to keep the output length from changing frequently so that the
@@ -1009,39 +1101,46 @@ static void print_sample_callindent(struct perf_sample *sample,
1009 spacing = round_up(len + 4, 32); 1101 spacing = round_up(len + 4, 32);
1010 1102
1011 if (len < spacing) 1103 if (len < spacing)
1012 printf("%*s", spacing - len, ""); 1104 len += fprintf(fp, "%*s", spacing - len, "");
1105
1106 return len;
1013} 1107}
1014 1108
1015static void print_insn(struct perf_sample *sample, 1109static int perf_sample__fprintf_insn(struct perf_sample *sample,
1016 struct perf_event_attr *attr, 1110 struct perf_event_attr *attr,
1017 struct thread *thread, 1111 struct thread *thread,
1018 struct machine *machine) 1112 struct machine *machine, FILE *fp)
1019{ 1113{
1114 int printed = 0;
1115
1020 if (PRINT_FIELD(INSNLEN)) 1116 if (PRINT_FIELD(INSNLEN))
1021 printf(" ilen: %d", sample->insn_len); 1117 printed += fprintf(fp, " ilen: %d", sample->insn_len);
1022 if (PRINT_FIELD(INSN)) { 1118 if (PRINT_FIELD(INSN)) {
1023 int i; 1119 int i;
1024 1120
1025 printf(" insn:"); 1121 printed += fprintf(fp, " insn:");
1026 for (i = 0; i < sample->insn_len; i++) 1122 for (i = 0; i < sample->insn_len; i++)
1027 printf(" %02x", (unsigned char)sample->insn[i]); 1123 printed += fprintf(fp, " %02x", (unsigned char)sample->insn[i]);
1028 } 1124 }
1029 if (PRINT_FIELD(BRSTACKINSN)) 1125 if (PRINT_FIELD(BRSTACKINSN))
1030 print_sample_brstackinsn(sample, thread, attr, machine); 1126 printed += perf_sample__fprintf_brstackinsn(sample, thread, attr, machine, fp);
1127
1128 return printed;
1031} 1129}
1032 1130
1033static void print_sample_bts(struct perf_sample *sample, 1131static int perf_sample__fprintf_bts(struct perf_sample *sample,
1034 struct perf_evsel *evsel, 1132 struct perf_evsel *evsel,
1035 struct thread *thread, 1133 struct thread *thread,
1036 struct addr_location *al, 1134 struct addr_location *al,
1037 struct machine *machine) 1135 struct machine *machine, FILE *fp)
1038{ 1136{
1039 struct perf_event_attr *attr = &evsel->attr; 1137 struct perf_event_attr *attr = &evsel->attr;
1040 unsigned int type = output_type(attr->type); 1138 unsigned int type = output_type(attr->type);
1041 bool print_srcline_last = false; 1139 bool print_srcline_last = false;
1140 int printed = 0;
1042 1141
1043 if (PRINT_FIELD(CALLINDENT)) 1142 if (PRINT_FIELD(CALLINDENT))
1044 print_sample_callindent(sample, evsel, thread, al); 1143 printed += perf_sample__fprintf_callindent(sample, evsel, thread, al, fp);
1045 1144
1046 /* print branch_from information */ 1145 /* print branch_from information */
1047 if (PRINT_FIELD(IP)) { 1146 if (PRINT_FIELD(IP)) {
@@ -1054,31 +1153,30 @@ static void print_sample_bts(struct perf_sample *sample,
1054 cursor = &callchain_cursor; 1153 cursor = &callchain_cursor;
1055 1154
1056 if (cursor == NULL) { 1155 if (cursor == NULL) {
1057 putchar(' '); 1156 printed += fprintf(fp, " ");
1058 if (print_opts & EVSEL__PRINT_SRCLINE) { 1157 if (print_opts & EVSEL__PRINT_SRCLINE) {
1059 print_srcline_last = true; 1158 print_srcline_last = true;
1060 print_opts &= ~EVSEL__PRINT_SRCLINE; 1159 print_opts &= ~EVSEL__PRINT_SRCLINE;
1061 } 1160 }
1062 } else 1161 } else
1063 putchar('\n'); 1162 printed += fprintf(fp, "\n");
1064 1163
1065 sample__fprintf_sym(sample, al, 0, print_opts, cursor, stdout); 1164 printed += sample__fprintf_sym(sample, al, 0, print_opts, cursor, fp);
1066 } 1165 }
1067 1166
1068 /* print branch_to information */ 1167 /* print branch_to information */
1069 if (PRINT_FIELD(ADDR) || 1168 if (PRINT_FIELD(ADDR) ||
1070 ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) && 1169 ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
1071 !output[type].user_set)) { 1170 !output[type].user_set)) {
1072 printf(" => "); 1171 printed += fprintf(fp, " => ");
1073 print_sample_addr(sample, thread, attr); 1172 printed += perf_sample__fprintf_addr(sample, thread, attr, fp);
1074 } 1173 }
1075 1174
1076 if (print_srcline_last) 1175 if (print_srcline_last)
1077 map__fprintf_srcline(al->map, al->addr, "\n ", stdout); 1176 printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp);
1078
1079 print_insn(sample, attr, thread, machine);
1080 1177
1081 printf("\n"); 1178 printed += perf_sample__fprintf_insn(sample, attr, thread, machine, fp);
1179 return printed + fprintf(fp, "\n");
1082} 1180}
1083 1181
1084static struct { 1182static struct {
@@ -1101,7 +1199,7 @@ static struct {
1101 {0, NULL} 1199 {0, NULL}
1102}; 1200};
1103 1201
1104static void print_sample_flags(u32 flags) 1202static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
1105{ 1203{
1106 const char *chars = PERF_IP_FLAG_CHARS; 1204 const char *chars = PERF_IP_FLAG_CHARS;
1107 const int n = strlen(PERF_IP_FLAG_CHARS); 1205 const int n = strlen(PERF_IP_FLAG_CHARS);
@@ -1128,9 +1226,9 @@ static void print_sample_flags(u32 flags)
1128 str[pos] = 0; 1226 str[pos] = 0;
1129 1227
1130 if (name) 1228 if (name)
1131 printf(" %-7s%4s ", name, in_tx ? "(x)" : ""); 1229 return fprintf(fp, " %-7s%4s ", name, in_tx ? "(x)" : "");
1132 else 1230
1133 printf(" %-11s ", str); 1231 return fprintf(fp, " %-11s ", str);
1134} 1232}
1135 1233
1136struct printer_data { 1234struct printer_data {
@@ -1139,40 +1237,40 @@ struct printer_data {
1139 bool is_printable; 1237 bool is_printable;
1140}; 1238};
1141 1239
1142static void 1240static int sample__fprintf_bpf_output(enum binary_printer_ops op,
1143print_sample_bpf_output_printer(enum binary_printer_ops op, 1241 unsigned int val,
1144 unsigned int val, 1242 void *extra, FILE *fp)
1145 void *extra)
1146{ 1243{
1147 unsigned char ch = (unsigned char)val; 1244 unsigned char ch = (unsigned char)val;
1148 struct printer_data *printer_data = extra; 1245 struct printer_data *printer_data = extra;
1246 int printed = 0;
1149 1247
1150 switch (op) { 1248 switch (op) {
1151 case BINARY_PRINT_DATA_BEGIN: 1249 case BINARY_PRINT_DATA_BEGIN:
1152 printf("\n"); 1250 printed += fprintf(fp, "\n");
1153 break; 1251 break;
1154 case BINARY_PRINT_LINE_BEGIN: 1252 case BINARY_PRINT_LINE_BEGIN:
1155 printf("%17s", !printer_data->line_no ? "BPF output:" : 1253 printed += fprintf(fp, "%17s", !printer_data->line_no ? "BPF output:" :
1156 " "); 1254 " ");
1157 break; 1255 break;
1158 case BINARY_PRINT_ADDR: 1256 case BINARY_PRINT_ADDR:
1159 printf(" %04x:", val); 1257 printed += fprintf(fp, " %04x:", val);
1160 break; 1258 break;
1161 case BINARY_PRINT_NUM_DATA: 1259 case BINARY_PRINT_NUM_DATA:
1162 printf(" %02x", val); 1260 printed += fprintf(fp, " %02x", val);
1163 break; 1261 break;
1164 case BINARY_PRINT_NUM_PAD: 1262 case BINARY_PRINT_NUM_PAD:
1165 printf(" "); 1263 printed += fprintf(fp, " ");
1166 break; 1264 break;
1167 case BINARY_PRINT_SEP: 1265 case BINARY_PRINT_SEP:
1168 printf(" "); 1266 printed += fprintf(fp, " ");
1169 break; 1267 break;
1170 case BINARY_PRINT_CHAR_DATA: 1268 case BINARY_PRINT_CHAR_DATA:
1171 if (printer_data->hit_nul && ch) 1269 if (printer_data->hit_nul && ch)
1172 printer_data->is_printable = false; 1270 printer_data->is_printable = false;
1173 1271
1174 if (!isprint(ch)) { 1272 if (!isprint(ch)) {
1175 printf("%c", '.'); 1273 printed += fprintf(fp, "%c", '.');
1176 1274
1177 if (!printer_data->is_printable) 1275 if (!printer_data->is_printable)
1178 break; 1276 break;
@@ -1182,154 +1280,154 @@ print_sample_bpf_output_printer(enum binary_printer_ops op,
1182 else 1280 else
1183 printer_data->is_printable = false; 1281 printer_data->is_printable = false;
1184 } else { 1282 } else {
1185 printf("%c", ch); 1283 printed += fprintf(fp, "%c", ch);
1186 } 1284 }
1187 break; 1285 break;
1188 case BINARY_PRINT_CHAR_PAD: 1286 case BINARY_PRINT_CHAR_PAD:
1189 printf(" "); 1287 printed += fprintf(fp, " ");
1190 break; 1288 break;
1191 case BINARY_PRINT_LINE_END: 1289 case BINARY_PRINT_LINE_END:
1192 printf("\n"); 1290 printed += fprintf(fp, "\n");
1193 printer_data->line_no++; 1291 printer_data->line_no++;
1194 break; 1292 break;
1195 case BINARY_PRINT_DATA_END: 1293 case BINARY_PRINT_DATA_END:
1196 default: 1294 default:
1197 break; 1295 break;
1198 } 1296 }
1297
1298 return printed;
1199} 1299}
1200 1300
1201static void print_sample_bpf_output(struct perf_sample *sample) 1301static int perf_sample__fprintf_bpf_output(struct perf_sample *sample, FILE *fp)
1202{ 1302{
1203 unsigned int nr_bytes = sample->raw_size; 1303 unsigned int nr_bytes = sample->raw_size;
1204 struct printer_data printer_data = {0, false, true}; 1304 struct printer_data printer_data = {0, false, true};
1205 1305 int printed = binary__fprintf(sample->raw_data, nr_bytes, 8,
1206 print_binary(sample->raw_data, nr_bytes, 8, 1306 sample__fprintf_bpf_output, &printer_data, fp);
1207 print_sample_bpf_output_printer, &printer_data);
1208 1307
1209 if (printer_data.is_printable && printer_data.hit_nul) 1308 if (printer_data.is_printable && printer_data.hit_nul)
1210 printf("%17s \"%s\"\n", "BPF string:", 1309 printed += fprintf(fp, "%17s \"%s\"\n", "BPF string:", (char *)(sample->raw_data));
1211 (char *)(sample->raw_data)); 1310
1311 return printed;
1212} 1312}
1213 1313
1214static void print_sample_spacing(int len, int spacing) 1314static int perf_sample__fprintf_spacing(int len, int spacing, FILE *fp)
1215{ 1315{
1216 if (len > 0 && len < spacing) 1316 if (len > 0 && len < spacing)
1217 printf("%*s", spacing - len, ""); 1317 return fprintf(fp, "%*s", spacing - len, "");
1318
1319 return 0;
1218} 1320}
1219 1321
1220static void print_sample_pt_spacing(int len) 1322static int perf_sample__fprintf_pt_spacing(int len, FILE *fp)
1221{ 1323{
1222 print_sample_spacing(len, 34); 1324 return perf_sample__fprintf_spacing(len, 34, fp);
1223} 1325}
1224 1326
1225static void print_sample_synth_ptwrite(struct perf_sample *sample) 1327static int perf_sample__fprintf_synth_ptwrite(struct perf_sample *sample, FILE *fp)
1226{ 1328{
1227 struct perf_synth_intel_ptwrite *data = perf_sample__synth_ptr(sample); 1329 struct perf_synth_intel_ptwrite *data = perf_sample__synth_ptr(sample);
1228 int len; 1330 int len;
1229 1331
1230 if (perf_sample__bad_synth_size(sample, *data)) 1332 if (perf_sample__bad_synth_size(sample, *data))
1231 return; 1333 return 0;
1232 1334
1233 len = printf(" IP: %u payload: %#" PRIx64 " ", 1335 len = fprintf(fp, " IP: %u payload: %#" PRIx64 " ",
1234 data->ip, le64_to_cpu(data->payload)); 1336 data->ip, le64_to_cpu(data->payload));
1235 print_sample_pt_spacing(len); 1337 return len + perf_sample__fprintf_pt_spacing(len, fp);
1236} 1338}
1237 1339
1238static void print_sample_synth_mwait(struct perf_sample *sample) 1340static int perf_sample__fprintf_synth_mwait(struct perf_sample *sample, FILE *fp)
1239{ 1341{
1240 struct perf_synth_intel_mwait *data = perf_sample__synth_ptr(sample); 1342 struct perf_synth_intel_mwait *data = perf_sample__synth_ptr(sample);
1241 int len; 1343 int len;
1242 1344
1243 if (perf_sample__bad_synth_size(sample, *data)) 1345 if (perf_sample__bad_synth_size(sample, *data))
1244 return; 1346 return 0;
1245 1347
1246 len = printf(" hints: %#x extensions: %#x ", 1348 len = fprintf(fp, " hints: %#x extensions: %#x ",
1247 data->hints, data->extensions); 1349 data->hints, data->extensions);
1248 print_sample_pt_spacing(len); 1350 return len + perf_sample__fprintf_pt_spacing(len, fp);
1249} 1351}
1250 1352
1251static void print_sample_synth_pwre(struct perf_sample *sample) 1353static int perf_sample__fprintf_synth_pwre(struct perf_sample *sample, FILE *fp)
1252{ 1354{
1253 struct perf_synth_intel_pwre *data = perf_sample__synth_ptr(sample); 1355 struct perf_synth_intel_pwre *data = perf_sample__synth_ptr(sample);
1254 int len; 1356 int len;
1255 1357
1256 if (perf_sample__bad_synth_size(sample, *data)) 1358 if (perf_sample__bad_synth_size(sample, *data))
1257 return; 1359 return 0;
1258 1360
1259 len = printf(" hw: %u cstate: %u sub-cstate: %u ", 1361 len = fprintf(fp, " hw: %u cstate: %u sub-cstate: %u ",
1260 data->hw, data->cstate, data->subcstate); 1362 data->hw, data->cstate, data->subcstate);
1261 print_sample_pt_spacing(len); 1363 return len + perf_sample__fprintf_pt_spacing(len, fp);
1262} 1364}
1263 1365
1264static void print_sample_synth_exstop(struct perf_sample *sample) 1366static int perf_sample__fprintf_synth_exstop(struct perf_sample *sample, FILE *fp)
1265{ 1367{
1266 struct perf_synth_intel_exstop *data = perf_sample__synth_ptr(sample); 1368 struct perf_synth_intel_exstop *data = perf_sample__synth_ptr(sample);
1267 int len; 1369 int len;
1268 1370
1269 if (perf_sample__bad_synth_size(sample, *data)) 1371 if (perf_sample__bad_synth_size(sample, *data))
1270 return; 1372 return 0;
1271 1373
1272 len = printf(" IP: %u ", data->ip); 1374 len = fprintf(fp, " IP: %u ", data->ip);
1273 print_sample_pt_spacing(len); 1375 return len + perf_sample__fprintf_pt_spacing(len, fp);
1274} 1376}
1275 1377
1276static void print_sample_synth_pwrx(struct perf_sample *sample) 1378static int perf_sample__fprintf_synth_pwrx(struct perf_sample *sample, FILE *fp)
1277{ 1379{
1278 struct perf_synth_intel_pwrx *data = perf_sample__synth_ptr(sample); 1380 struct perf_synth_intel_pwrx *data = perf_sample__synth_ptr(sample);
1279 int len; 1381 int len;
1280 1382
1281 if (perf_sample__bad_synth_size(sample, *data)) 1383 if (perf_sample__bad_synth_size(sample, *data))
1282 return; 1384 return 0;
1283 1385
1284 len = printf(" deepest cstate: %u last cstate: %u wake reason: %#x ", 1386 len = fprintf(fp, " deepest cstate: %u last cstate: %u wake reason: %#x ",
1285 data->deepest_cstate, data->last_cstate, 1387 data->deepest_cstate, data->last_cstate,
1286 data->wake_reason); 1388 data->wake_reason);
1287 print_sample_pt_spacing(len); 1389 return len + perf_sample__fprintf_pt_spacing(len, fp);
1288} 1390}
1289 1391
1290static void print_sample_synth_cbr(struct perf_sample *sample) 1392static int perf_sample__fprintf_synth_cbr(struct perf_sample *sample, FILE *fp)
1291{ 1393{
1292 struct perf_synth_intel_cbr *data = perf_sample__synth_ptr(sample); 1394 struct perf_synth_intel_cbr *data = perf_sample__synth_ptr(sample);
1293 unsigned int percent, freq; 1395 unsigned int percent, freq;
1294 int len; 1396 int len;
1295 1397
1296 if (perf_sample__bad_synth_size(sample, *data)) 1398 if (perf_sample__bad_synth_size(sample, *data))
1297 return; 1399 return 0;
1298 1400
1299 freq = (le32_to_cpu(data->freq) + 500) / 1000; 1401 freq = (le32_to_cpu(data->freq) + 500) / 1000;
1300 len = printf(" cbr: %2u freq: %4u MHz ", data->cbr, freq); 1402 len = fprintf(fp, " cbr: %2u freq: %4u MHz ", data->cbr, freq);
1301 if (data->max_nonturbo) { 1403 if (data->max_nonturbo) {
1302 percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10; 1404 percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10;
1303 len += printf("(%3u%%) ", percent); 1405 len += fprintf(fp, "(%3u%%) ", percent);
1304 } 1406 }
1305 print_sample_pt_spacing(len); 1407 return len + perf_sample__fprintf_pt_spacing(len, fp);
1306} 1408}
1307 1409
1308static void print_sample_synth(struct perf_sample *sample, 1410static int perf_sample__fprintf_synth(struct perf_sample *sample,
1309 struct perf_evsel *evsel) 1411 struct perf_evsel *evsel, FILE *fp)
1310{ 1412{
1311 switch (evsel->attr.config) { 1413 switch (evsel->attr.config) {
1312 case PERF_SYNTH_INTEL_PTWRITE: 1414 case PERF_SYNTH_INTEL_PTWRITE:
1313 print_sample_synth_ptwrite(sample); 1415 return perf_sample__fprintf_synth_ptwrite(sample, fp);
1314 break;
1315 case PERF_SYNTH_INTEL_MWAIT: 1416 case PERF_SYNTH_INTEL_MWAIT:
1316 print_sample_synth_mwait(sample); 1417 return perf_sample__fprintf_synth_mwait(sample, fp);
1317 break;
1318 case PERF_SYNTH_INTEL_PWRE: 1418 case PERF_SYNTH_INTEL_PWRE:
1319 print_sample_synth_pwre(sample); 1419 return perf_sample__fprintf_synth_pwre(sample, fp);
1320 break;
1321 case PERF_SYNTH_INTEL_EXSTOP: 1420 case PERF_SYNTH_INTEL_EXSTOP:
1322 print_sample_synth_exstop(sample); 1421 return perf_sample__fprintf_synth_exstop(sample, fp);
1323 break;
1324 case PERF_SYNTH_INTEL_PWRX: 1422 case PERF_SYNTH_INTEL_PWRX:
1325 print_sample_synth_pwrx(sample); 1423 return perf_sample__fprintf_synth_pwrx(sample, fp);
1326 break;
1327 case PERF_SYNTH_INTEL_CBR: 1424 case PERF_SYNTH_INTEL_CBR:
1328 print_sample_synth_cbr(sample); 1425 return perf_sample__fprintf_synth_cbr(sample, fp);
1329 break;
1330 default: 1426 default:
1331 break; 1427 break;
1332 } 1428 }
1429
1430 return 0;
1333} 1431}
1334 1432
1335struct perf_script { 1433struct perf_script {
@@ -1340,6 +1438,7 @@ struct perf_script {
1340 bool show_switch_events; 1438 bool show_switch_events;
1341 bool show_namespace_events; 1439 bool show_namespace_events;
1342 bool allocated; 1440 bool allocated;
1441 bool per_event_dump;
1343 struct cpu_map *cpus; 1442 struct cpu_map *cpus;
1344 struct thread_map *threads; 1443 struct thread_map *threads;
1345 int name_width; 1444 int name_width;
@@ -1361,7 +1460,7 @@ static int perf_evlist__max_name_len(struct perf_evlist *evlist)
1361 return max; 1460 return max;
1362} 1461}
1363 1462
1364static size_t data_src__printf(u64 data_src) 1463static int data_src__fprintf(u64 data_src, FILE *fp)
1365{ 1464{
1366 struct mem_info mi = { .data_src.val = data_src }; 1465 struct mem_info mi = { .data_src.val = data_src };
1367 char decode[100]; 1466 char decode[100];
@@ -1375,7 +1474,7 @@ static size_t data_src__printf(u64 data_src)
1375 if (maxlen < len) 1474 if (maxlen < len)
1376 maxlen = len; 1475 maxlen = len;
1377 1476
1378 return printf("%-*s", maxlen, out); 1477 return fprintf(fp, "%-*s", maxlen, out);
1379} 1478}
1380 1479
1381static void process_event(struct perf_script *script, 1480static void process_event(struct perf_script *script,
@@ -1386,14 +1485,18 @@ static void process_event(struct perf_script *script,
1386 struct thread *thread = al->thread; 1485 struct thread *thread = al->thread;
1387 struct perf_event_attr *attr = &evsel->attr; 1486 struct perf_event_attr *attr = &evsel->attr;
1388 unsigned int type = output_type(attr->type); 1487 unsigned int type = output_type(attr->type);
1488 struct perf_evsel_script *es = evsel->priv;
1489 FILE *fp = es->fp;
1389 1490
1390 if (output[type].fields == 0) 1491 if (output[type].fields == 0)
1391 return; 1492 return;
1392 1493
1393 print_sample_start(sample, thread, evsel); 1494 ++es->samples;
1495
1496 perf_sample__fprintf_start(sample, thread, evsel, fp);
1394 1497
1395 if (PRINT_FIELD(PERIOD)) 1498 if (PRINT_FIELD(PERIOD))
1396 printf("%10" PRIu64 " ", sample->period); 1499 fprintf(fp, "%10" PRIu64 " ", sample->period);
1397 1500
1398 if (PRINT_FIELD(EVNAME)) { 1501 if (PRINT_FIELD(EVNAME)) {
1399 const char *evname = perf_evsel__name(evsel); 1502 const char *evname = perf_evsel__name(evsel);
@@ -1401,33 +1504,33 @@ static void process_event(struct perf_script *script,
1401 if (!script->name_width) 1504 if (!script->name_width)
1402 script->name_width = perf_evlist__max_name_len(script->session->evlist); 1505 script->name_width = perf_evlist__max_name_len(script->session->evlist);
1403 1506
1404 printf("%*s: ", script->name_width, 1507 fprintf(fp, "%*s: ", script->name_width, evname ?: "[unknown]");
1405 evname ? evname : "[unknown]");
1406 } 1508 }
1407 1509
1408 if (print_flags) 1510 if (print_flags)
1409 print_sample_flags(sample->flags); 1511 perf_sample__fprintf_flags(sample->flags, fp);
1410 1512
1411 if (is_bts_event(attr)) { 1513 if (is_bts_event(attr)) {
1412 print_sample_bts(sample, evsel, thread, al, machine); 1514 perf_sample__fprintf_bts(sample, evsel, thread, al, machine, fp);
1413 return; 1515 return;
1414 } 1516 }
1415 1517
1416 if (PRINT_FIELD(TRACE)) 1518 if (PRINT_FIELD(TRACE)) {
1417 event_format__print(evsel->tp_format, sample->cpu, 1519 event_format__fprintf(evsel->tp_format, sample->cpu,
1418 sample->raw_data, sample->raw_size); 1520 sample->raw_data, sample->raw_size, fp);
1521 }
1419 1522
1420 if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH)) 1523 if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH))
1421 print_sample_synth(sample, evsel); 1524 perf_sample__fprintf_synth(sample, evsel, fp);
1422 1525
1423 if (PRINT_FIELD(ADDR)) 1526 if (PRINT_FIELD(ADDR))
1424 print_sample_addr(sample, thread, attr); 1527 perf_sample__fprintf_addr(sample, thread, attr, fp);
1425 1528
1426 if (PRINT_FIELD(DATA_SRC)) 1529 if (PRINT_FIELD(DATA_SRC))
1427 data_src__printf(sample->data_src); 1530 data_src__fprintf(sample->data_src, fp);
1428 1531
1429 if (PRINT_FIELD(WEIGHT)) 1532 if (PRINT_FIELD(WEIGHT))
1430 printf("%16" PRIu64, sample->weight); 1533 fprintf(fp, "%16" PRIu64, sample->weight);
1431 1534
1432 if (PRINT_FIELD(IP)) { 1535 if (PRINT_FIELD(IP)) {
1433 struct callchain_cursor *cursor = NULL; 1536 struct callchain_cursor *cursor = NULL;
@@ -1437,27 +1540,30 @@ static void process_event(struct perf_script *script,
1437 sample, NULL, NULL, scripting_max_stack) == 0) 1540 sample, NULL, NULL, scripting_max_stack) == 0)
1438 cursor = &callchain_cursor; 1541 cursor = &callchain_cursor;
1439 1542
1440 putchar(cursor ? '\n' : ' '); 1543 fputc(cursor ? '\n' : ' ', fp);
1441 sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, stdout); 1544 sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, fp);
1442 } 1545 }
1443 1546
1444 if (PRINT_FIELD(IREGS)) 1547 if (PRINT_FIELD(IREGS))
1445 print_sample_iregs(sample, attr); 1548 perf_sample__fprintf_iregs(sample, attr, fp);
1549
1550 if (PRINT_FIELD(UREGS))
1551 perf_sample__fprintf_uregs(sample, attr, fp);
1446 1552
1447 if (PRINT_FIELD(BRSTACK)) 1553 if (PRINT_FIELD(BRSTACK))
1448 print_sample_brstack(sample, thread, attr); 1554 perf_sample__fprintf_brstack(sample, thread, attr, fp);
1449 else if (PRINT_FIELD(BRSTACKSYM)) 1555 else if (PRINT_FIELD(BRSTACKSYM))
1450 print_sample_brstacksym(sample, thread, attr); 1556 perf_sample__fprintf_brstacksym(sample, thread, attr, fp);
1451 else if (PRINT_FIELD(BRSTACKOFF)) 1557 else if (PRINT_FIELD(BRSTACKOFF))
1452 print_sample_brstackoff(sample, thread, attr); 1558 perf_sample__fprintf_brstackoff(sample, thread, attr, fp);
1453 1559
1454 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT)) 1560 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
1455 print_sample_bpf_output(sample); 1561 perf_sample__fprintf_bpf_output(sample, fp);
1456 print_insn(sample, attr, thread, machine); 1562 perf_sample__fprintf_insn(sample, attr, thread, machine, fp);
1457 1563
1458 if (PRINT_FIELD(PHYS_ADDR)) 1564 if (PRINT_FIELD(PHYS_ADDR))
1459 printf("%16" PRIx64, sample->phys_addr); 1565 fprintf(fp, "%16" PRIx64, sample->phys_addr);
1460 printf("\n"); 1566 fprintf(fp, "\n");
1461} 1567}
1462 1568
1463static struct scripting_ops *scripting_ops; 1569static struct scripting_ops *scripting_ops;
@@ -1631,7 +1737,7 @@ static int process_comm_event(struct perf_tool *tool,
1631 sample->tid = event->comm.tid; 1737 sample->tid = event->comm.tid;
1632 sample->pid = event->comm.pid; 1738 sample->pid = event->comm.pid;
1633 } 1739 }
1634 print_sample_start(sample, thread, evsel); 1740 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1635 perf_event__fprintf(event, stdout); 1741 perf_event__fprintf(event, stdout);
1636 ret = 0; 1742 ret = 0;
1637out: 1743out:
@@ -1666,7 +1772,7 @@ static int process_namespaces_event(struct perf_tool *tool,
1666 sample->tid = event->namespaces.tid; 1772 sample->tid = event->namespaces.tid;
1667 sample->pid = event->namespaces.pid; 1773 sample->pid = event->namespaces.pid;
1668 } 1774 }
1669 print_sample_start(sample, thread, evsel); 1775 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1670 perf_event__fprintf(event, stdout); 1776 perf_event__fprintf(event, stdout);
1671 ret = 0; 1777 ret = 0;
1672out: 1778out:
@@ -1699,7 +1805,7 @@ static int process_fork_event(struct perf_tool *tool,
1699 sample->tid = event->fork.tid; 1805 sample->tid = event->fork.tid;
1700 sample->pid = event->fork.pid; 1806 sample->pid = event->fork.pid;
1701 } 1807 }
1702 print_sample_start(sample, thread, evsel); 1808 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1703 perf_event__fprintf(event, stdout); 1809 perf_event__fprintf(event, stdout);
1704 thread__put(thread); 1810 thread__put(thread);
1705 1811
@@ -1728,7 +1834,7 @@ static int process_exit_event(struct perf_tool *tool,
1728 sample->tid = event->fork.tid; 1834 sample->tid = event->fork.tid;
1729 sample->pid = event->fork.pid; 1835 sample->pid = event->fork.pid;
1730 } 1836 }
1731 print_sample_start(sample, thread, evsel); 1837 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1732 perf_event__fprintf(event, stdout); 1838 perf_event__fprintf(event, stdout);
1733 1839
1734 if (perf_event__process_exit(tool, event, sample, machine) < 0) 1840 if (perf_event__process_exit(tool, event, sample, machine) < 0)
@@ -1763,7 +1869,7 @@ static int process_mmap_event(struct perf_tool *tool,
1763 sample->tid = event->mmap.tid; 1869 sample->tid = event->mmap.tid;
1764 sample->pid = event->mmap.pid; 1870 sample->pid = event->mmap.pid;
1765 } 1871 }
1766 print_sample_start(sample, thread, evsel); 1872 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1767 perf_event__fprintf(event, stdout); 1873 perf_event__fprintf(event, stdout);
1768 thread__put(thread); 1874 thread__put(thread);
1769 return 0; 1875 return 0;
@@ -1794,7 +1900,7 @@ static int process_mmap2_event(struct perf_tool *tool,
1794 sample->tid = event->mmap2.tid; 1900 sample->tid = event->mmap2.tid;
1795 sample->pid = event->mmap2.pid; 1901 sample->pid = event->mmap2.pid;
1796 } 1902 }
1797 print_sample_start(sample, thread, evsel); 1903 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1798 perf_event__fprintf(event, stdout); 1904 perf_event__fprintf(event, stdout);
1799 thread__put(thread); 1905 thread__put(thread);
1800 return 0; 1906 return 0;
@@ -1820,7 +1926,7 @@ static int process_switch_event(struct perf_tool *tool,
1820 return -1; 1926 return -1;
1821 } 1927 }
1822 1928
1823 print_sample_start(sample, thread, evsel); 1929 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1824 perf_event__fprintf(event, stdout); 1930 perf_event__fprintf(event, stdout);
1825 thread__put(thread); 1931 thread__put(thread);
1826 return 0; 1932 return 0;
@@ -1831,6 +1937,65 @@ static void sig_handler(int sig __maybe_unused)
1831 session_done = 1; 1937 session_done = 1;
1832} 1938}
1833 1939
1940static void perf_script__fclose_per_event_dump(struct perf_script *script)
1941{
1942 struct perf_evlist *evlist = script->session->evlist;
1943 struct perf_evsel *evsel;
1944
1945 evlist__for_each_entry(evlist, evsel) {
1946 if (!evsel->priv)
1947 break;
1948 perf_evsel_script__delete(evsel->priv);
1949 evsel->priv = NULL;
1950 }
1951}
1952
1953static int perf_script__fopen_per_event_dump(struct perf_script *script)
1954{
1955 struct perf_evsel *evsel;
1956
1957 evlist__for_each_entry(script->session->evlist, evsel) {
1958 evsel->priv = perf_evsel_script__new(evsel, script->session->data);
1959 if (evsel->priv == NULL)
1960 goto out_err_fclose;
1961 }
1962
1963 return 0;
1964
1965out_err_fclose:
1966 perf_script__fclose_per_event_dump(script);
1967 return -1;
1968}
1969
1970static int perf_script__setup_per_event_dump(struct perf_script *script)
1971{
1972 struct perf_evsel *evsel;
1973 static struct perf_evsel_script es_stdout;
1974
1975 if (script->per_event_dump)
1976 return perf_script__fopen_per_event_dump(script);
1977
1978 es_stdout.fp = stdout;
1979
1980 evlist__for_each_entry(script->session->evlist, evsel)
1981 evsel->priv = &es_stdout;
1982
1983 return 0;
1984}
1985
1986static void perf_script__exit_per_event_dump_stats(struct perf_script *script)
1987{
1988 struct perf_evsel *evsel;
1989
1990 evlist__for_each_entry(script->session->evlist, evsel) {
1991 struct perf_evsel_script *es = evsel->priv;
1992
1993 perf_evsel_script__fprintf(es, stdout);
1994 perf_evsel_script__delete(es);
1995 evsel->priv = NULL;
1996 }
1997}
1998
1834static int __cmd_script(struct perf_script *script) 1999static int __cmd_script(struct perf_script *script)
1835{ 2000{
1836 int ret; 2001 int ret;
@@ -1852,8 +2017,16 @@ static int __cmd_script(struct perf_script *script)
1852 if (script->show_namespace_events) 2017 if (script->show_namespace_events)
1853 script->tool.namespaces = process_namespaces_event; 2018 script->tool.namespaces = process_namespaces_event;
1854 2019
2020 if (perf_script__setup_per_event_dump(script)) {
2021 pr_err("Couldn't create the per event dump files\n");
2022 return -1;
2023 }
2024
1855 ret = perf_session__process_events(script->session); 2025 ret = perf_session__process_events(script->session);
1856 2026
2027 if (script->per_event_dump)
2028 perf_script__exit_per_event_dump_stats(script);
2029
1857 if (debug_mode) 2030 if (debug_mode)
1858 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); 2031 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
1859 2032
@@ -2418,14 +2591,16 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
2418 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; 2591 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
2419 DIR *scripts_dir, *lang_dir; 2592 DIR *scripts_dir, *lang_dir;
2420 struct perf_session *session; 2593 struct perf_session *session;
2421 struct perf_data_file file = { 2594 struct perf_data data = {
2422 .path = input_name, 2595 .file = {
2423 .mode = PERF_DATA_MODE_READ, 2596 .path = input_name,
2597 },
2598 .mode = PERF_DATA_MODE_READ,
2424 }; 2599 };
2425 char *temp; 2600 char *temp;
2426 int i = 0; 2601 int i = 0;
2427 2602
2428 session = perf_session__new(&file, false, NULL); 2603 session = perf_session__new(&data, false, NULL);
2429 if (!session) 2604 if (!session)
2430 return -1; 2605 return -1;
2431 2606
@@ -2703,7 +2878,7 @@ int cmd_script(int argc, const char **argv)
2703 .ordering_requires_timestamps = true, 2878 .ordering_requires_timestamps = true,
2704 }, 2879 },
2705 }; 2880 };
2706 struct perf_data_file file = { 2881 struct perf_data data = {
2707 .mode = PERF_DATA_MODE_READ, 2882 .mode = PERF_DATA_MODE_READ,
2708 }; 2883 };
2709 const struct option options[] = { 2884 const struct option options[] = {
@@ -2739,7 +2914,7 @@ int cmd_script(int argc, const char **argv)
2739 "+field to add and -field to remove." 2914 "+field to add and -field to remove."
2740 "Valid types: hw,sw,trace,raw,synth. " 2915 "Valid types: hw,sw,trace,raw,synth. "
2741 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," 2916 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
2742 "addr,symoff,period,iregs,brstack,brstacksym,flags," 2917 "addr,symoff,period,iregs,uregs,brstack,brstacksym,flags,"
2743 "bpf-output,callindent,insn,insnlen,brstackinsn,synth,phys_addr", 2918 "bpf-output,callindent,insn,insnlen,brstackinsn,synth,phys_addr",
2744 parse_output_fields), 2919 parse_output_fields),
2745 OPT_BOOLEAN('a', "all-cpus", &system_wide, 2920 OPT_BOOLEAN('a', "all-cpus", &system_wide,
@@ -2771,6 +2946,8 @@ int cmd_script(int argc, const char **argv)
2771 "Show context switch events (if recorded)"), 2946 "Show context switch events (if recorded)"),
2772 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events, 2947 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
2773 "Show namespace events (if recorded)"), 2948 "Show namespace events (if recorded)"),
2949 OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
2950 "Dump trace output to files named by the monitored events"),
2774 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), 2951 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
2775 OPT_INTEGER(0, "max-blocks", &max_blocks, 2952 OPT_INTEGER(0, "max-blocks", &max_blocks,
2776 "Maximum number of code blocks to dump with brstackinsn"), 2953 "Maximum number of code blocks to dump with brstackinsn"),
@@ -2801,13 +2978,15 @@ int cmd_script(int argc, const char **argv)
2801 NULL 2978 NULL
2802 }; 2979 };
2803 2980
2981 perf_set_singlethreaded();
2982
2804 setup_scripting(); 2983 setup_scripting();
2805 2984
2806 argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage, 2985 argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
2807 PARSE_OPT_STOP_AT_NON_OPTION); 2986 PARSE_OPT_STOP_AT_NON_OPTION);
2808 2987
2809 file.path = input_name; 2988 data.file.path = input_name;
2810 file.force = symbol_conf.force; 2989 data.force = symbol_conf.force;
2811 2990
2812 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { 2991 if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) {
2813 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); 2992 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX);
@@ -2974,7 +3153,7 @@ int cmd_script(int argc, const char **argv)
2974 if (!script_name) 3153 if (!script_name)
2975 setup_pager(); 3154 setup_pager();
2976 3155
2977 session = perf_session__new(&file, false, &script.tool); 3156 session = perf_session__new(&data, false, &script.tool);
2978 if (session == NULL) 3157 if (session == NULL)
2979 return -1; 3158 return -1;
2980 3159
@@ -3015,7 +3194,8 @@ int cmd_script(int argc, const char **argv)
3015 machine__resolve_kernel_addr, 3194 machine__resolve_kernel_addr,
3016 &session->machines.host) < 0) { 3195 &session->machines.host) < 0) {
3017 pr_err("%s: failed to set libtraceevent function resolver\n", __func__); 3196 pr_err("%s: failed to set libtraceevent function resolver\n", __func__);
3018 return -1; 3197 err = -1;
3198 goto out_delete;
3019 } 3199 }
3020 3200
3021 if (generate_script_lang) { 3201 if (generate_script_lang) {
@@ -3029,7 +3209,7 @@ int cmd_script(int argc, const char **argv)
3029 goto out_delete; 3209 goto out_delete;
3030 } 3210 }
3031 3211
3032 input = open(file.path, O_RDONLY); /* input_name */ 3212 input = open(data.file.path, O_RDONLY); /* input_name */
3033 if (input < 0) { 3213 if (input < 0) {
3034 err = -errno; 3214 err = -errno;
3035 perror("failed to open file"); 3215 perror("failed to open file");
@@ -3075,7 +3255,8 @@ int cmd_script(int argc, const char **argv)
3075 /* needs to be parsed after looking up reference time */ 3255 /* needs to be parsed after looking up reference time */
3076 if (perf_time__parse_str(&script.ptime, script.time_str) != 0) { 3256 if (perf_time__parse_str(&script.ptime, script.time_str) != 0) {
3077 pr_err("Invalid time string\n"); 3257 pr_err("Invalid time string\n");
3078 return -EINVAL; 3258 err = -EINVAL;
3259 goto out_delete;
3079 } 3260 }
3080 3261
3081 err = __cmd_script(&script); 3262 err = __cmd_script(&script);
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 69523ed55894..59af5a8419e2 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -65,6 +65,7 @@
65#include "util/tool.h" 65#include "util/tool.h"
66#include "util/group.h" 66#include "util/group.h"
67#include "util/string2.h" 67#include "util/string2.h"
68#include "util/metricgroup.h"
68#include "asm/bug.h" 69#include "asm/bug.h"
69 70
70#include <linux/time64.h> 71#include <linux/time64.h>
@@ -133,6 +134,8 @@ static const char *smi_cost_attrs = {
133 134
134static struct perf_evlist *evsel_list; 135static struct perf_evlist *evsel_list;
135 136
137static struct rblist metric_events;
138
136static struct target target = { 139static struct target target = {
137 .uid = UINT_MAX, 140 .uid = UINT_MAX,
138}; 141};
@@ -172,7 +175,7 @@ static int print_free_counters_hint;
172 175
173struct perf_stat { 176struct perf_stat {
174 bool record; 177 bool record;
175 struct perf_data_file file; 178 struct perf_data data;
176 struct perf_session *session; 179 struct perf_session *session;
177 u64 bytes_written; 180 u64 bytes_written;
178 struct perf_tool tool; 181 struct perf_tool tool;
@@ -192,6 +195,11 @@ static struct perf_stat_config stat_config = {
192 .scale = true, 195 .scale = true,
193}; 196};
194 197
198static bool is_duration_time(struct perf_evsel *evsel)
199{
200 return !strcmp(evsel->name, "duration_time");
201}
202
195static inline void diff_timespec(struct timespec *r, struct timespec *a, 203static inline void diff_timespec(struct timespec *r, struct timespec *a,
196 struct timespec *b) 204 struct timespec *b)
197{ 205{
@@ -245,7 +253,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
245 * by attr->sample_type != 0, and we can't run it on 253 * by attr->sample_type != 0, and we can't run it on
246 * stat sessions. 254 * stat sessions.
247 */ 255 */
248 if (!(STAT_RECORD && perf_stat.file.is_pipe)) 256 if (!(STAT_RECORD && perf_stat.data.is_pipe))
249 attr->sample_type = PERF_SAMPLE_IDENTIFIER; 257 attr->sample_type = PERF_SAMPLE_IDENTIFIER;
250 258
251 /* 259 /*
@@ -287,7 +295,7 @@ static int process_synthesized_event(struct perf_tool *tool __maybe_unused,
287 struct perf_sample *sample __maybe_unused, 295 struct perf_sample *sample __maybe_unused,
288 struct machine *machine __maybe_unused) 296 struct machine *machine __maybe_unused)
289{ 297{
290 if (perf_data_file__write(&perf_stat.file, event, event->header.size) < 0) { 298 if (perf_data__write(&perf_stat.data, event, event->header.size) < 0) {
291 pr_err("failed to write perf data, error: %m\n"); 299 pr_err("failed to write perf data, error: %m\n");
292 return -1; 300 return -1;
293 } 301 }
@@ -407,6 +415,8 @@ static void process_interval(void)
407 pr_err("failed to write stat round event\n"); 415 pr_err("failed to write stat round event\n");
408 } 416 }
409 417
418 init_stats(&walltime_nsecs_stats);
419 update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000);
410 print_counters(&rs, 0, NULL); 420 print_counters(&rs, 0, NULL);
411} 421}
412 422
@@ -582,6 +592,32 @@ static bool perf_evsel__should_store_id(struct perf_evsel *counter)
582 return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID; 592 return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID;
583} 593}
584 594
595static struct perf_evsel *perf_evsel__reset_weak_group(struct perf_evsel *evsel)
596{
597 struct perf_evsel *c2, *leader;
598 bool is_open = true;
599
600 leader = evsel->leader;
601 pr_debug("Weak group for %s/%d failed\n",
602 leader->name, leader->nr_members);
603
604 /*
605 * for_each_group_member doesn't work here because it doesn't
606 * include the first entry.
607 */
608 evlist__for_each_entry(evsel_list, c2) {
609 if (c2 == evsel)
610 is_open = false;
611 if (c2->leader == leader) {
612 if (is_open)
613 perf_evsel__close(c2);
614 c2->leader = c2;
615 c2->nr_members = 0;
616 }
617 }
618 return leader;
619}
620
585static int __run_perf_stat(int argc, const char **argv) 621static int __run_perf_stat(int argc, const char **argv)
586{ 622{
587 int interval = stat_config.interval; 623 int interval = stat_config.interval;
@@ -592,7 +628,7 @@ static int __run_perf_stat(int argc, const char **argv)
592 size_t l; 628 size_t l;
593 int status = 0; 629 int status = 0;
594 const bool forks = (argc > 0); 630 const bool forks = (argc > 0);
595 bool is_pipe = STAT_RECORD ? perf_stat.file.is_pipe : false; 631 bool is_pipe = STAT_RECORD ? perf_stat.data.is_pipe : false;
596 struct perf_evsel_config_term *err_term; 632 struct perf_evsel_config_term *err_term;
597 633
598 if (interval) { 634 if (interval) {
@@ -618,6 +654,15 @@ static int __run_perf_stat(int argc, const char **argv)
618 evlist__for_each_entry(evsel_list, counter) { 654 evlist__for_each_entry(evsel_list, counter) {
619try_again: 655try_again:
620 if (create_perf_stat_counter(counter) < 0) { 656 if (create_perf_stat_counter(counter) < 0) {
657
658 /* Weak group failed. Reset the group. */
659 if ((errno == EINVAL || errno == EBADF) &&
660 counter->leader != counter &&
661 counter->weak_group) {
662 counter = perf_evsel__reset_weak_group(counter);
663 goto try_again;
664 }
665
621 /* 666 /*
622 * PPC returns ENXIO for HW counters until 2.6.37 667 * PPC returns ENXIO for HW counters until 2.6.37
623 * (behavior changed with commit b0a873e). 668 * (behavior changed with commit b0a873e).
@@ -674,10 +719,10 @@ try_again:
674 } 719 }
675 720
676 if (STAT_RECORD) { 721 if (STAT_RECORD) {
677 int err, fd = perf_data_file__fd(&perf_stat.file); 722 int err, fd = perf_data__fd(&perf_stat.data);
678 723
679 if (is_pipe) { 724 if (is_pipe) {
680 err = perf_header__write_pipe(perf_data_file__fd(&perf_stat.file)); 725 err = perf_header__write_pipe(perf_data__fd(&perf_stat.data));
681 } else { 726 } else {
682 err = perf_session__write_header(perf_stat.session, evsel_list, 727 err = perf_session__write_header(perf_stat.session, evsel_list,
683 fd, false); 728 fd, false);
@@ -800,7 +845,7 @@ static void print_noise(struct perf_evsel *evsel, double avg)
800 if (run_count == 1) 845 if (run_count == 1)
801 return; 846 return;
802 847
803 ps = evsel->priv; 848 ps = evsel->stats;
804 print_noise_pct(stddev_stats(&ps->res_stats[0]), avg); 849 print_noise_pct(stddev_stats(&ps->res_stats[0]), avg);
805} 850}
806 851
@@ -1199,7 +1244,7 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,
1199 1244
1200 perf_stat__print_shadow_stats(counter, uval, 1245 perf_stat__print_shadow_stats(counter, uval,
1201 first_shadow_cpu(counter, id), 1246 first_shadow_cpu(counter, id),
1202 &out); 1247 &out, &metric_events);
1203 if (!csv_output && !metric_only) { 1248 if (!csv_output && !metric_only) {
1204 print_noise(counter, noise); 1249 print_noise(counter, noise);
1205 print_running(run, ena); 1250 print_running(run, ena);
@@ -1222,8 +1267,7 @@ static void aggr_update_shadow(void)
1222 continue; 1267 continue;
1223 val += perf_counts(counter->counts, cpu, 0)->val; 1268 val += perf_counts(counter->counts, cpu, 0)->val;
1224 } 1269 }
1225 val = val * counter->scale; 1270 perf_stat__update_shadow_stats(counter, val,
1226 perf_stat__update_shadow_stats(counter, &val,
1227 first_shadow_cpu(counter, id)); 1271 first_shadow_cpu(counter, id));
1228 } 1272 }
1229 } 1273 }
@@ -1325,6 +1369,9 @@ static void print_aggr(char *prefix)
1325 ad.id = id = aggr_map->map[s]; 1369 ad.id = id = aggr_map->map[s];
1326 first = true; 1370 first = true;
1327 evlist__for_each_entry(evsel_list, counter) { 1371 evlist__for_each_entry(evsel_list, counter) {
1372 if (is_duration_time(counter))
1373 continue;
1374
1328 ad.val = ad.ena = ad.run = 0; 1375 ad.val = ad.ena = ad.run = 0;
1329 ad.nr = 0; 1376 ad.nr = 0;
1330 if (!collect_data(counter, aggr_cb, &ad)) 1377 if (!collect_data(counter, aggr_cb, &ad))
@@ -1384,7 +1431,7 @@ static void counter_aggr_cb(struct perf_evsel *counter, void *data,
1384 bool first __maybe_unused) 1431 bool first __maybe_unused)
1385{ 1432{
1386 struct caggr_data *cd = data; 1433 struct caggr_data *cd = data;
1387 struct perf_stat_evsel *ps = counter->priv; 1434 struct perf_stat_evsel *ps = counter->stats;
1388 1435
1389 cd->avg += avg_stats(&ps->res_stats[0]); 1436 cd->avg += avg_stats(&ps->res_stats[0]);
1390 cd->avg_enabled += avg_stats(&ps->res_stats[1]); 1437 cd->avg_enabled += avg_stats(&ps->res_stats[1]);
@@ -1468,6 +1515,8 @@ static void print_no_aggr_metric(char *prefix)
1468 if (prefix) 1515 if (prefix)
1469 fputs(prefix, stat_config.output); 1516 fputs(prefix, stat_config.output);
1470 evlist__for_each_entry(evsel_list, counter) { 1517 evlist__for_each_entry(evsel_list, counter) {
1518 if (is_duration_time(counter))
1519 continue;
1471 if (first) { 1520 if (first) {
1472 aggr_printout(counter, cpu, 0); 1521 aggr_printout(counter, cpu, 0);
1473 first = false; 1522 first = false;
@@ -1522,6 +1571,8 @@ static void print_metric_headers(const char *prefix, bool no_indent)
1522 1571
1523 /* Print metrics headers only */ 1572 /* Print metrics headers only */
1524 evlist__for_each_entry(evsel_list, counter) { 1573 evlist__for_each_entry(evsel_list, counter) {
1574 if (is_duration_time(counter))
1575 continue;
1525 os.evsel = counter; 1576 os.evsel = counter;
1526 out.ctx = &os; 1577 out.ctx = &os;
1527 out.print_metric = print_metric_header; 1578 out.print_metric = print_metric_header;
@@ -1530,7 +1581,8 @@ static void print_metric_headers(const char *prefix, bool no_indent)
1530 os.evsel = counter; 1581 os.evsel = counter;
1531 perf_stat__print_shadow_stats(counter, 0, 1582 perf_stat__print_shadow_stats(counter, 0,
1532 0, 1583 0,
1533 &out); 1584 &out,
1585 &metric_events);
1534 } 1586 }
1535 fputc('\n', stat_config.output); 1587 fputc('\n', stat_config.output);
1536} 1588}
@@ -1643,7 +1695,7 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)
1643 char buf[64], *prefix = NULL; 1695 char buf[64], *prefix = NULL;
1644 1696
1645 /* Do not print anything if we record to the pipe. */ 1697 /* Do not print anything if we record to the pipe. */
1646 if (STAT_RECORD && perf_stat.file.is_pipe) 1698 if (STAT_RECORD && perf_stat.data.is_pipe)
1647 return; 1699 return;
1648 1700
1649 if (interval) 1701 if (interval)
@@ -1668,12 +1720,18 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)
1668 print_aggr(prefix); 1720 print_aggr(prefix);
1669 break; 1721 break;
1670 case AGGR_THREAD: 1722 case AGGR_THREAD:
1671 evlist__for_each_entry(evsel_list, counter) 1723 evlist__for_each_entry(evsel_list, counter) {
1724 if (is_duration_time(counter))
1725 continue;
1672 print_aggr_thread(counter, prefix); 1726 print_aggr_thread(counter, prefix);
1727 }
1673 break; 1728 break;
1674 case AGGR_GLOBAL: 1729 case AGGR_GLOBAL:
1675 evlist__for_each_entry(evsel_list, counter) 1730 evlist__for_each_entry(evsel_list, counter) {
1731 if (is_duration_time(counter))
1732 continue;
1676 print_counter_aggr(counter, prefix); 1733 print_counter_aggr(counter, prefix);
1734 }
1677 if (metric_only) 1735 if (metric_only)
1678 fputc('\n', stat_config.output); 1736 fputc('\n', stat_config.output);
1679 break; 1737 break;
@@ -1681,8 +1739,11 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)
1681 if (metric_only) 1739 if (metric_only)
1682 print_no_aggr_metric(prefix); 1740 print_no_aggr_metric(prefix);
1683 else { 1741 else {
1684 evlist__for_each_entry(evsel_list, counter) 1742 evlist__for_each_entry(evsel_list, counter) {
1743 if (is_duration_time(counter))
1744 continue;
1685 print_counter(counter, prefix); 1745 print_counter(counter, prefix);
1746 }
1686 } 1747 }
1687 break; 1748 break;
1688 case AGGR_UNSET: 1749 case AGGR_UNSET:
@@ -1754,6 +1815,13 @@ static int enable_metric_only(const struct option *opt __maybe_unused,
1754 return 0; 1815 return 0;
1755} 1816}
1756 1817
1818static int parse_metric_groups(const struct option *opt,
1819 const char *str,
1820 int unset __maybe_unused)
1821{
1822 return metricgroup__parse_groups(opt, str, &metric_events);
1823}
1824
1757static const struct option stat_options[] = { 1825static const struct option stat_options[] = {
1758 OPT_BOOLEAN('T', "transaction", &transaction_run, 1826 OPT_BOOLEAN('T', "transaction", &transaction_run,
1759 "hardware transaction statistics"), 1827 "hardware transaction statistics"),
@@ -1819,6 +1887,9 @@ static const struct option stat_options[] = {
1819 "measure topdown level 1 statistics"), 1887 "measure topdown level 1 statistics"),
1820 OPT_BOOLEAN(0, "smi-cost", &smi_cost, 1888 OPT_BOOLEAN(0, "smi-cost", &smi_cost,
1821 "measure SMI cost"), 1889 "measure SMI cost"),
1890 OPT_CALLBACK('M', "metrics", &evsel_list, "metric/metric group list",
1891 "monitor specified metrics or metric groups (separated by ,)",
1892 parse_metric_groups),
1822 OPT_END() 1893 OPT_END()
1823}; 1894};
1824 1895
@@ -2334,20 +2405,20 @@ static void init_features(struct perf_session *session)
2334static int __cmd_record(int argc, const char **argv) 2405static int __cmd_record(int argc, const char **argv)
2335{ 2406{
2336 struct perf_session *session; 2407 struct perf_session *session;
2337 struct perf_data_file *file = &perf_stat.file; 2408 struct perf_data *data = &perf_stat.data;
2338 2409
2339 argc = parse_options(argc, argv, stat_options, stat_record_usage, 2410 argc = parse_options(argc, argv, stat_options, stat_record_usage,
2340 PARSE_OPT_STOP_AT_NON_OPTION); 2411 PARSE_OPT_STOP_AT_NON_OPTION);
2341 2412
2342 if (output_name) 2413 if (output_name)
2343 file->path = output_name; 2414 data->file.path = output_name;
2344 2415
2345 if (run_count != 1 || forever) { 2416 if (run_count != 1 || forever) {
2346 pr_err("Cannot use -r option with perf stat record.\n"); 2417 pr_err("Cannot use -r option with perf stat record.\n");
2347 return -1; 2418 return -1;
2348 } 2419 }
2349 2420
2350 session = perf_session__new(file, false, NULL); 2421 session = perf_session__new(data, false, NULL);
2351 if (session == NULL) { 2422 if (session == NULL) {
2352 pr_err("Perf session creation failed.\n"); 2423 pr_err("Perf session creation failed.\n");
2353 return -1; 2424 return -1;
@@ -2405,7 +2476,7 @@ int process_stat_config_event(struct perf_tool *tool,
2405 if (st->aggr_mode != AGGR_UNSET) 2476 if (st->aggr_mode != AGGR_UNSET)
2406 stat_config.aggr_mode = st->aggr_mode; 2477 stat_config.aggr_mode = st->aggr_mode;
2407 2478
2408 if (perf_stat.file.is_pipe) 2479 if (perf_stat.data.is_pipe)
2409 perf_stat_init_aggr_mode(); 2480 perf_stat_init_aggr_mode();
2410 else 2481 else
2411 perf_stat_init_aggr_mode_file(st); 2482 perf_stat_init_aggr_mode_file(st);
@@ -2513,10 +2584,10 @@ static int __cmd_report(int argc, const char **argv)
2513 input_name = "perf.data"; 2584 input_name = "perf.data";
2514 } 2585 }
2515 2586
2516 perf_stat.file.path = input_name; 2587 perf_stat.data.file.path = input_name;
2517 perf_stat.file.mode = PERF_DATA_MODE_READ; 2588 perf_stat.data.mode = PERF_DATA_MODE_READ;
2518 2589
2519 session = perf_session__new(&perf_stat.file, false, &perf_stat.tool); 2590 session = perf_session__new(&perf_stat.data, false, &perf_stat.tool);
2520 if (session == NULL) 2591 if (session == NULL)
2521 return -1; 2592 return -1;
2522 2593
@@ -2787,7 +2858,7 @@ int cmd_stat(int argc, const char **argv)
2787 * records, but the need to suppress the kptr_restrict messages in older 2858 * records, but the need to suppress the kptr_restrict messages in older
2788 * tools remain -acme 2859 * tools remain -acme
2789 */ 2860 */
2790 int fd = perf_data_file__fd(&perf_stat.file); 2861 int fd = perf_data__fd(&perf_stat.data);
2791 int err = perf_event__synthesize_kernel_mmap((void *)&perf_stat, 2862 int err = perf_event__synthesize_kernel_mmap((void *)&perf_stat,
2792 process_synthesized_event, 2863 process_synthesized_event,
2793 &perf_stat.session->machines.host); 2864 &perf_stat.session->machines.host);
@@ -2801,7 +2872,7 @@ int cmd_stat(int argc, const char **argv)
2801 pr_err("failed to write stat round event\n"); 2872 pr_err("failed to write stat round event\n");
2802 } 2873 }
2803 2874
2804 if (!perf_stat.file.is_pipe) { 2875 if (!perf_stat.data.is_pipe) {
2805 perf_stat.session->header.data_size += perf_stat.bytes_written; 2876 perf_stat.session->header.data_size += perf_stat.bytes_written;
2806 perf_session__write_header(perf_stat.session, evsel_list, fd, true); 2877 perf_session__write_header(perf_stat.session, evsel_list, fd, true);
2807 } 2878 }
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 4e2e61695986..813698a9b8c7 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1601,13 +1601,15 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
1601 { "syscalls:sys_exit_pselect6", process_exit_poll }, 1601 { "syscalls:sys_exit_pselect6", process_exit_poll },
1602 { "syscalls:sys_exit_select", process_exit_poll }, 1602 { "syscalls:sys_exit_select", process_exit_poll },
1603 }; 1603 };
1604 struct perf_data_file file = { 1604 struct perf_data data = {
1605 .path = input_name, 1605 .file = {
1606 .mode = PERF_DATA_MODE_READ, 1606 .path = input_name,
1607 .force = tchart->force, 1607 },
1608 .mode = PERF_DATA_MODE_READ,
1609 .force = tchart->force,
1608 }; 1610 };
1609 1611
1610 struct perf_session *session = perf_session__new(&file, false, 1612 struct perf_session *session = perf_session__new(&data, false,
1611 &tchart->tool); 1613 &tchart->tool);
1612 int ret = -EINVAL; 1614 int ret = -EINVAL;
1613 1615
@@ -1617,7 +1619,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
1617 symbol__init(&session->header.env); 1619 symbol__init(&session->header.env);
1618 1620
1619 (void)perf_header__process_sections(&session->header, 1621 (void)perf_header__process_sections(&session->header,
1620 perf_data_file__fd(session->file), 1622 perf_data__fd(session->data),
1621 tchart, 1623 tchart,
1622 process_header); 1624 process_header);
1623 1625
@@ -1732,8 +1734,10 @@ static int timechart__io_record(int argc, const char **argv)
1732 if (rec_argv == NULL) 1734 if (rec_argv == NULL)
1733 return -ENOMEM; 1735 return -ENOMEM;
1734 1736
1735 if (asprintf(&filter, "common_pid != %d", getpid()) < 0) 1737 if (asprintf(&filter, "common_pid != %d", getpid()) < 0) {
1738 free(rec_argv);
1736 return -ENOMEM; 1739 return -ENOMEM;
1740 }
1737 1741
1738 p = rec_argv; 1742 p = rec_argv;
1739 for (i = 0; i < common_args_nr; i++) 1743 for (i = 0; i < common_args_nr; i++)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index ee954bde7e3e..477a8699f0b5 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -958,8 +958,16 @@ static int __cmd_top(struct perf_top *top)
958 if (perf_session__register_idle_thread(top->session) < 0) 958 if (perf_session__register_idle_thread(top->session) < 0)
959 goto out_delete; 959 goto out_delete;
960 960
961 if (top->nr_threads_synthesize > 1)
962 perf_set_multithreaded();
963
961 machine__synthesize_threads(&top->session->machines.host, &opts->target, 964 machine__synthesize_threads(&top->session->machines.host, &opts->target,
962 top->evlist->threads, false, opts->proc_map_timeout); 965 top->evlist->threads, false,
966 opts->proc_map_timeout,
967 top->nr_threads_synthesize);
968
969 if (top->nr_threads_synthesize > 1)
970 perf_set_singlethreaded();
963 971
964 if (perf_hpp_list.socket) { 972 if (perf_hpp_list.socket) {
965 ret = perf_env__read_cpu_topology_map(&perf_env); 973 ret = perf_env__read_cpu_topology_map(&perf_env);
@@ -1112,6 +1120,7 @@ int cmd_top(int argc, const char **argv)
1112 }, 1120 },
1113 .max_stack = sysctl_perf_event_max_stack, 1121 .max_stack = sysctl_perf_event_max_stack,
1114 .sym_pcnt_filter = 5, 1122 .sym_pcnt_filter = 5,
1123 .nr_threads_synthesize = UINT_MAX,
1115 }; 1124 };
1116 struct record_opts *opts = &top.record_opts; 1125 struct record_opts *opts = &top.record_opts;
1117 struct target *target = &opts->target; 1126 struct target *target = &opts->target;
@@ -1221,6 +1230,8 @@ int cmd_top(int argc, const char **argv)
1221 OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy, 1230 OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
1222 "Show entries in a hierarchy"), 1231 "Show entries in a hierarchy"),
1223 OPT_BOOLEAN(0, "force", &symbol_conf.force, "don't complain, do it"), 1232 OPT_BOOLEAN(0, "force", &symbol_conf.force, "don't complain, do it"),
1233 OPT_UINTEGER(0, "num-thread-synthesize", &top.nr_threads_synthesize,
1234 "number of thread to run event synthesize"),
1224 OPT_END() 1235 OPT_END()
1225 }; 1236 };
1226 const char * const top_usage[] = { 1237 const char * const top_usage[] = {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 771ddab94bb0..f2757d38c7d7 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -578,7 +578,6 @@ static struct syscall_fmt {
578} syscall_fmts[] = { 578} syscall_fmts[] = {
579 { .name = "access", 579 { .name = "access",
580 .arg = { [1] = { .scnprintf = SCA_ACCMODE, /* mode */ }, }, }, 580 .arg = { [1] = { .scnprintf = SCA_ACCMODE, /* mode */ }, }, },
581 { .name = "arch_prctl", .alias = "prctl", },
582 { .name = "bpf", 581 { .name = "bpf",
583 .arg = { [0] = STRARRAY(cmd, bpf_cmd), }, }, 582 .arg = { [0] = STRARRAY(cmd, bpf_cmd), }, },
584 { .name = "brk", .hexret = true, 583 { .name = "brk", .hexret = true,
@@ -634,6 +633,12 @@ static struct syscall_fmt {
634#else 633#else
635 [2] = { .scnprintf = SCA_HEX, /* arg */ }, }, }, 634 [2] = { .scnprintf = SCA_HEX, /* arg */ }, }, },
636#endif 635#endif
636 { .name = "kcmp", .nr_args = 5,
637 .arg = { [0] = { .name = "pid1", .scnprintf = SCA_PID, },
638 [1] = { .name = "pid2", .scnprintf = SCA_PID, },
639 [2] = { .name = "type", .scnprintf = SCA_KCMP_TYPE, },
640 [3] = { .name = "idx1", .scnprintf = SCA_KCMP_IDX, },
641 [4] = { .name = "idx2", .scnprintf = SCA_KCMP_IDX, }, }, },
637 { .name = "keyctl", 642 { .name = "keyctl",
638 .arg = { [0] = STRARRAY(option, keyctl_options), }, }, 643 .arg = { [0] = STRARRAY(option, keyctl_options), }, },
639 { .name = "kill", 644 { .name = "kill",
@@ -703,6 +708,10 @@ static struct syscall_fmt {
703 [3] = { .scnprintf = SCA_INT, /* pkey */ }, }, }, 708 [3] = { .scnprintf = SCA_INT, /* pkey */ }, }, },
704 { .name = "poll", .timeout = true, }, 709 { .name = "poll", .timeout = true, },
705 { .name = "ppoll", .timeout = true, }, 710 { .name = "ppoll", .timeout = true, },
711 { .name = "prctl", .alias = "arch_prctl",
712 .arg = { [0] = { .scnprintf = SCA_PRCTL_OPTION, /* option */ },
713 [1] = { .scnprintf = SCA_PRCTL_ARG2, /* arg2 */ },
714 [2] = { .scnprintf = SCA_PRCTL_ARG3, /* arg3 */ }, }, },
706 { .name = "pread", .alias = "pread64", }, 715 { .name = "pread", .alias = "pread64", },
707 { .name = "preadv", .alias = "pread", }, 716 { .name = "preadv", .alias = "pread", },
708 { .name = "prlimit64", 717 { .name = "prlimit64",
@@ -985,6 +994,23 @@ size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg)
985 return printed; 994 return printed;
986} 995}
987 996
997size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size)
998{
999 size_t printed = scnprintf(bf, size, "%d", fd);
1000 struct thread *thread = machine__find_thread(trace->host, pid, pid);
1001
1002 if (thread) {
1003 const char *path = thread__fd_path(thread, fd, trace);
1004
1005 if (path)
1006 printed += scnprintf(bf + printed, size - printed, "<%s>", path);
1007
1008 thread__put(thread);
1009 }
1010
1011 return printed;
1012}
1013
988static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size, 1014static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size,
989 struct syscall_arg *arg) 1015 struct syscall_arg *arg)
990{ 1016{
@@ -1131,13 +1157,21 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
1131 1157
1132 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, 1158 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,
1133 evlist->threads, trace__tool_process, false, 1159 evlist->threads, trace__tool_process, false,
1134 trace->opts.proc_map_timeout); 1160 trace->opts.proc_map_timeout, 1);
1135 if (err) 1161 if (err)
1136 symbol__exit(); 1162 symbol__exit();
1137 1163
1138 return err; 1164 return err;
1139} 1165}
1140 1166
1167static void trace__symbols__exit(struct trace *trace)
1168{
1169 machine__exit(trace->host);
1170 trace->host = NULL;
1171
1172 symbol__exit();
1173}
1174
1141static int syscall__alloc_arg_fmts(struct syscall *sc, int nr_args) 1175static int syscall__alloc_arg_fmts(struct syscall *sc, int nr_args)
1142{ 1176{
1143 int idx; 1177 int idx;
@@ -1828,16 +1862,14 @@ out_dump:
1828 goto out_put; 1862 goto out_put;
1829} 1863}
1830 1864
1831static void bpf_output__printer(enum binary_printer_ops op, 1865static int bpf_output__printer(enum binary_printer_ops op,
1832 unsigned int val, void *extra) 1866 unsigned int val, void *extra __maybe_unused, FILE *fp)
1833{ 1867{
1834 FILE *output = extra;
1835 unsigned char ch = (unsigned char)val; 1868 unsigned char ch = (unsigned char)val;
1836 1869
1837 switch (op) { 1870 switch (op) {
1838 case BINARY_PRINT_CHAR_DATA: 1871 case BINARY_PRINT_CHAR_DATA:
1839 fprintf(output, "%c", isprint(ch) ? ch : '.'); 1872 return fprintf(fp, "%c", isprint(ch) ? ch : '.');
1840 break;
1841 case BINARY_PRINT_DATA_BEGIN: 1873 case BINARY_PRINT_DATA_BEGIN:
1842 case BINARY_PRINT_LINE_BEGIN: 1874 case BINARY_PRINT_LINE_BEGIN:
1843 case BINARY_PRINT_ADDR: 1875 case BINARY_PRINT_ADDR:
@@ -1850,13 +1882,15 @@ static void bpf_output__printer(enum binary_printer_ops op,
1850 default: 1882 default:
1851 break; 1883 break;
1852 } 1884 }
1885
1886 return 0;
1853} 1887}
1854 1888
1855static void bpf_output__fprintf(struct trace *trace, 1889static void bpf_output__fprintf(struct trace *trace,
1856 struct perf_sample *sample) 1890 struct perf_sample *sample)
1857{ 1891{
1858 print_binary(sample->raw_data, sample->raw_size, 8, 1892 binary__fprintf(sample->raw_data, sample->raw_size, 8,
1859 bpf_output__printer, trace->output); 1893 bpf_output__printer, NULL, trace->output);
1860} 1894}
1861 1895
1862static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel, 1896static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel,
@@ -2078,6 +2112,7 @@ static int trace__record(struct trace *trace, int argc, const char **argv)
2078 rec_argv[j++] = "syscalls:sys_enter,syscalls:sys_exit"; 2112 rec_argv[j++] = "syscalls:sys_enter,syscalls:sys_exit";
2079 else { 2113 else {
2080 pr_err("Neither raw_syscalls nor syscalls events exist.\n"); 2114 pr_err("Neither raw_syscalls nor syscalls events exist.\n");
2115 free(rec_argv);
2081 return -1; 2116 return -1;
2082 } 2117 }
2083 } 2118 }
@@ -2481,6 +2516,8 @@ out_disable:
2481 } 2516 }
2482 2517
2483out_delete_evlist: 2518out_delete_evlist:
2519 trace__symbols__exit(trace);
2520
2484 perf_evlist__delete(evlist); 2521 perf_evlist__delete(evlist);
2485 trace->evlist = NULL; 2522 trace->evlist = NULL;
2486 trace->live = false; 2523 trace->live = false;
@@ -2528,10 +2565,12 @@ static int trace__replay(struct trace *trace)
2528 const struct perf_evsel_str_handler handlers[] = { 2565 const struct perf_evsel_str_handler handlers[] = {
2529 { "probe:vfs_getname", trace__vfs_getname, }, 2566 { "probe:vfs_getname", trace__vfs_getname, },
2530 }; 2567 };
2531 struct perf_data_file file = { 2568 struct perf_data data = {
2532 .path = input_name, 2569 .file = {
2533 .mode = PERF_DATA_MODE_READ, 2570 .path = input_name,
2534 .force = trace->force, 2571 },
2572 .mode = PERF_DATA_MODE_READ,
2573 .force = trace->force,
2535 }; 2574 };
2536 struct perf_session *session; 2575 struct perf_session *session;
2537 struct perf_evsel *evsel; 2576 struct perf_evsel *evsel;
@@ -2554,7 +2593,7 @@ static int trace__replay(struct trace *trace)
2554 /* add tid to output */ 2593 /* add tid to output */
2555 trace->multiple_threads = true; 2594 trace->multiple_threads = true;
2556 2595
2557 session = perf_session__new(&file, false, &trace->tool); 2596 session = perf_session__new(&data, false, &trace->tool);
2558 if (session == NULL) 2597 if (session == NULL)
2559 return -1; 2598 return -1;
2560 2599
@@ -2730,20 +2769,23 @@ DEFINE_RESORT_RB(threads, (thread__nr_events(a->thread->priv) < thread__nr_event
2730 2769
2731static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) 2770static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp)
2732{ 2771{
2733 DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host);
2734 size_t printed = trace__fprintf_threads_header(fp); 2772 size_t printed = trace__fprintf_threads_header(fp);
2735 struct rb_node *nd; 2773 struct rb_node *nd;
2774 int i;
2736 2775
2737 if (threads == NULL) { 2776 for (i = 0; i < THREADS__TABLE_SIZE; i++) {
2738 fprintf(fp, "%s", "Error sorting output by nr_events!\n"); 2777 DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i);
2739 return 0;
2740 }
2741 2778
2742 resort_rb__for_each_entry(nd, threads) 2779 if (threads == NULL) {
2743 printed += trace__fprintf_thread(fp, threads_entry->thread, trace); 2780 fprintf(fp, "%s", "Error sorting output by nr_events!\n");
2781 return 0;
2782 }
2744 2783
2745 resort_rb__delete(threads); 2784 resort_rb__for_each_entry(nd, threads)
2785 printed += trace__fprintf_thread(fp, threads_entry->thread, trace);
2746 2786
2787 resort_rb__delete(threads);
2788 }
2747 return printed; 2789 return printed;
2748} 2790}
2749 2791
diff --git a/tools/perf/builtin-version.c b/tools/perf/builtin-version.c
index d25149456a2f..37019c5d675f 100644
--- a/tools/perf/builtin-version.c
+++ b/tools/perf/builtin-version.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "builtin.h" 2#include "builtin.h"
2#include "perf.h" 3#include "perf.h"
3#include <linux/compiler.h> 4#include <linux/compiler.h>
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index d4d19fe3d050..05745f3ce912 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef BUILTIN_H 2#ifndef BUILTIN_H
2#define BUILTIN_H 3#define BUILTIN_H
3 4
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 932fda54b8a6..77406d25e521 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -1,11 +1,14 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3HEADERS=' 4HEADERS='
4include/uapi/drm/drm.h 5include/uapi/drm/drm.h
5include/uapi/drm/i915_drm.h 6include/uapi/drm/i915_drm.h
6include/uapi/linux/fcntl.h 7include/uapi/linux/fcntl.h
8include/uapi/linux/kcmp.h
7include/uapi/linux/kvm.h 9include/uapi/linux/kvm.h
8include/uapi/linux/perf_event.h 10include/uapi/linux/perf_event.h
11include/uapi/linux/prctl.h
9include/uapi/linux/sched.h 12include/uapi/linux/sched.h
10include/uapi/linux/stat.h 13include/uapi/linux/stat.h
11include/uapi/linux/vhost.h 14include/uapi/linux/vhost.h
@@ -57,6 +60,11 @@ check () {
57} 60}
58 61
59 62
63# Check if we have the kernel headers (tools/perf/../../include), else
64# we're probably on a detached tarball, so no point in trying to check
65# differences.
66test -d ../../include || exit 0
67
60# simple diff check 68# simple diff check
61for i in $HEADERS; do 69for i in $HEADERS; do
62 check $i -B 70 check $i -B
diff --git a/tools/perf/jvmti/jvmti_agent.h b/tools/perf/jvmti/jvmti_agent.h
index c53a41f48b63..fe32d8344a82 100644
--- a/tools/perf/jvmti/jvmti_agent.h
+++ b/tools/perf/jvmti/jvmti_agent.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __JVMTI_AGENT_H__ 2#ifndef __JVMTI_AGENT_H__
2#define __JVMTI_AGENT_H__ 3#define __JVMTI_AGENT_H__
3 4
diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
index 6d710904c837..c62c9fc9a525 100644
--- a/tools/perf/jvmti/libjvmti.c
+++ b/tools/perf/jvmti/libjvmti.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <sys/types.h> 3#include <sys/types.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/perf/perf-archive.sh b/tools/perf/perf-archive.sh
index e91930620269..0cfb3e2cefef 100644
--- a/tools/perf/perf-archive.sh
+++ b/tools/perf/perf-archive.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# perf archive 3# perf archive
3# Arnaldo Carvalho de Melo <acme@redhat.com> 4# Arnaldo Carvalho de Melo <acme@redhat.com>
4 5
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 3ba80b2359cc..345f5d6e9ed5 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -1,4 +1,5 @@
1# perf bash and zsh completion 1# perf bash and zsh completion
2# SPDX-License-Identifier: GPL-2.0
2 3
3# Taken from git.git's completion script. 4# Taken from git.git's completion script.
4__my_reassemble_comp_words_by_ref() 5__my_reassemble_comp_words_by_ref()
diff --git a/tools/perf/perf-read-vdso.c b/tools/perf/perf-read-vdso.c
index 764e2547c25a..8c0ca0cc428f 100644
--- a/tools/perf/perf-read-vdso.c
+++ b/tools/perf/perf-read-vdso.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <string.h> 3#include <string.h>
3 4
diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index c11f0c76e90c..36673f98d66b 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_SYS_H 2#ifndef _PERF_SYS_H
2#define _PERF_SYS_H 3#define _PERF_SYS_H
3 4
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 2f19e03c5c40..62b13518bc6e 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * perf.c 3 * perf.c
3 * 4 *
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index dc442ba21bf6..2357f4ccc9c7 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_PERF_H 2#ifndef _PERF_PERF_H
2#define _PERF_PERF_H 3#define _PERF_PERF_H
3 4
@@ -65,6 +66,7 @@ struct record_opts {
65 unsigned int user_freq; 66 unsigned int user_freq;
66 u64 branch_stack; 67 u64 branch_stack;
67 u64 sample_intr_regs; 68 u64 sample_intr_regs;
69 u64 sample_user_regs;
68 u64 default_interval; 70 u64 default_interval;
69 u64 user_interval; 71 u64 user_interval;
70 size_t auxtrace_snapshot_size; 72 size_t auxtrace_snapshot_size;
diff --git a/tools/perf/pmu-events/arch/x86/broadwell/bdw-metrics.json b/tools/perf/pmu-events/arch/x86/broadwell/bdw-metrics.json
new file mode 100644
index 000000000000..00bfdb5c5acb
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/broadwell/bdw-metrics.json
@@ -0,0 +1,164 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , IDQ.MITE_UOPS / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 16 * ( ICACHE.HIT + ICACHE.MISSES ) / 4.0 ) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_EXECUTED.THREAD / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else UOPS_EXECUTED.CYCLES_GE_1_UOP_EXEC)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE.IFDATA_STALL - (( 14 * ITLB_MISSES.STLB_HIT + cpu@ITLB_MISSES.WALK_DURATION\\,cmask\\=1@ + 7* ITLB_MISSES.WALK_COMPLETED )) ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_UOPS_RETIRED.L1_MISS + mem_load_uops_retired.hit_lfb )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( cpu@l1d_pend_miss.pending_cycles\\,any\\=1@ / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( cpu@ITLB_MISSES.WALK_DURATION\\,cmask\\=1@ + cpu@DTLB_LOAD_MISSES.WALK_DURATION\\,cmask\\=1@ + cpu@DTLB_STORE_MISSES.WALK_DURATION\\,cmask\\=1@ + 7*(DTLB_STORE_MISSES.WALK_COMPLETED+DTLB_LOAD_MISSES.WALK_COMPLETED+ITLB_MISSES.WALK_COMPLETED)) / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Giga Floating Point Operations Per Second",
100 "MetricExpr": "(( 1*( FP_ARITH_INST_RETIRED.SCALAR_SINGLE + FP_ARITH_INST_RETIRED.SCALAR_DOUBLE ) + 2* FP_ARITH_INST_RETIRED.128B_PACKED_DOUBLE + 4*( FP_ARITH_INST_RETIRED.128B_PACKED_SINGLE + FP_ARITH_INST_RETIRED.256B_PACKED_DOUBLE ) + 8* FP_ARITH_INST_RETIRED.256B_PACKED_SINGLE )) / 1000000000 / duration_time",
101 "MetricGroup": "FLOPS;Summary",
102 "MetricName": "GFLOPs"
103 },
104 {
105 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
106 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
107 "MetricGroup": "Power",
108 "MetricName": "Turbo_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles where both hardware threads were active",
112 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
113 "MetricGroup": "SMT;Summary",
114 "MetricName": "SMT_2T_Utilization"
115 },
116 {
117 "BriefDescription": "Fraction of cycles spent in Kernel mode",
118 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
119 "MetricGroup": "Summary",
120 "MetricName": "Kernel_Utilization"
121 },
122 {
123 "BriefDescription": "C3 residency percent per core",
124 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Core_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per core",
130 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Core_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per core",
136 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Core_Residency"
139 },
140 {
141 "BriefDescription": "C2 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C2_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C3 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C3_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C6 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C6_Pkg_Residency"
157 },
158 {
159 "BriefDescription": "C7 residency percent per package",
160 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
161 "MetricGroup": "Power",
162 "MetricName": "C7_Pkg_Residency"
163 }
164]
diff --git a/tools/perf/pmu-events/arch/x86/broadwellde/bdwde-metrics.json b/tools/perf/pmu-events/arch/x86/broadwellde/bdwde-metrics.json
new file mode 100644
index 000000000000..49c5f123d811
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/broadwellde/bdwde-metrics.json
@@ -0,0 +1,164 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , IDQ.MITE_UOPS / ( UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY * 16 * ( ICACHE.HIT + ICACHE.MISSES ) / 4.0 ) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / INST_RETIRED.ANY / cycles",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / ( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_EXECUTED.THREAD / ( cpu@uops_executed.core\\,cmask\\=1@ / 2) if #SMT_on else UOPS_EXECUTED.CYCLES_GE_1_UOP_EXEC",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* ( RS_EVENTS.EMPTY_CYCLES - ICACHE.IFDATA_STALL - ( 14 * ITLB_MISSES.STLB_HIT + cpu@ITLB_MISSES.WALK_DURATION\\,cmask\\=1@ + 7* ITLB_MISSES.WALK_COMPLETED ) ) / RS_EVENTS.EMPTY_END",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_UOPS_RETIRED.L1_MISS + mem_load_uops_retired.hit_lfb )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / ( cpu@l1d_pend_miss.pending_cycles\\,any\\=1@ / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( cpu@ITLB_MISSES.WALK_DURATION\\,cmask\\=1@ + cpu@DTLB_LOAD_MISSES.WALK_DURATION\\,cmask\\=1@ + cpu@DTLB_STORE_MISSES.WALK_DURATION\\,cmask\\=1@ + 7*(DTLB_STORE_MISSES.WALK_COMPLETED+DTLB_LOAD_MISSES.WALK_COMPLETED+ITLB_MISSES.WALK_COMPLETED)) / ( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Giga Floating Point Operations Per Second",
100 "MetricExpr": "( 1*( FP_ARITH_INST_RETIRED.SCALAR_SINGLE + FP_ARITH_INST_RETIRED.SCALAR_DOUBLE ) + 2* FP_ARITH_INST_RETIRED.128B_PACKED_DOUBLE + 4*( FP_ARITH_INST_RETIRED.128B_PACKED_SINGLE + FP_ARITH_INST_RETIRED.256B_PACKED_DOUBLE ) + 8* FP_ARITH_INST_RETIRED.256B_PACKED_SINGLE ) / 1000000000 / duration_time",
101 "MetricGroup": "FLOPS;Summary",
102 "MetricName": "GFLOPs"
103 },
104 {
105 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
106 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
107 "MetricGroup": "Power",
108 "MetricName": "Turbo_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles where both hardware threads were active",
112 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
113 "MetricGroup": "SMT;Summary",
114 "MetricName": "SMT_2T_Utilization"
115 },
116 {
117 "BriefDescription": "Fraction of cycles spent in Kernel mode",
118 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
119 "MetricGroup": "Summary",
120 "MetricName": "Kernel_Utilization"
121 },
122 {
123 "BriefDescription": "C3 residency percent per core",
124 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Core_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per core",
130 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Core_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per core",
136 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Core_Residency"
139 },
140 {
141 "BriefDescription": "C2 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C2_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C3 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C3_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C6 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C6_Pkg_Residency"
157 },
158 {
159 "BriefDescription": "C7 residency percent per package",
160 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
161 "MetricGroup": "Power",
162 "MetricName": "C7_Pkg_Residency"
163 }
164]
diff --git a/tools/perf/pmu-events/arch/x86/broadwellx/bdx-metrics.json b/tools/perf/pmu-events/arch/x86/broadwellx/bdx-metrics.json
new file mode 100644
index 000000000000..5a7f1ec24200
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/broadwellx/bdx-metrics.json
@@ -0,0 +1,164 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , IDQ.MITE_UOPS / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 16 * ( ICACHE.HIT + ICACHE.MISSES ) / 4.0 ) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_EXECUTED.THREAD / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else UOPS_EXECUTED.CYCLES_GE_1_UOP_EXEC)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE.IFDATA_STALL - (( 14 * ITLB_MISSES.STLB_HIT + cpu@ITLB_MISSES.WALK_DURATION\\,cmask\\=1@ + 7* ITLB_MISSES.WALK_COMPLETED )) ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_UOPS_RETIRED.L1_MISS + mem_load_uops_retired.hit_lfb )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( cpu@l1d_pend_miss.pending_cycles\\,any\\=1@ / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( ITLB_MISSES.WALK_DURATION + DTLB_LOAD_MISSES.WALK_DURATION + DTLB_STORE_MISSES.WALK_DURATION + 7*(DTLB_STORE_MISSES.WALK_COMPLETED+DTLB_LOAD_MISSES.WALK_COMPLETED+ITLB_MISSES.WALK_COMPLETED) ) / (2*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles))",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Giga Floating Point Operations Per Second",
100 "MetricExpr": "(( 1*( FP_ARITH_INST_RETIRED.SCALAR_SINGLE + FP_ARITH_INST_RETIRED.SCALAR_DOUBLE ) + 2* FP_ARITH_INST_RETIRED.128B_PACKED_DOUBLE + 4*( FP_ARITH_INST_RETIRED.128B_PACKED_SINGLE + FP_ARITH_INST_RETIRED.256B_PACKED_DOUBLE ) + 8* FP_ARITH_INST_RETIRED.256B_PACKED_SINGLE )) / 1000000000 / duration_time",
101 "MetricGroup": "FLOPS;Summary",
102 "MetricName": "GFLOPs"
103 },
104 {
105 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
106 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
107 "MetricGroup": "Power",
108 "MetricName": "Turbo_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles where both hardware threads were active",
112 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
113 "MetricGroup": "SMT;Summary",
114 "MetricName": "SMT_2T_Utilization"
115 },
116 {
117 "BriefDescription": "Fraction of cycles spent in Kernel mode",
118 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
119 "MetricGroup": "Summary",
120 "MetricName": "Kernel_Utilization"
121 },
122 {
123 "BriefDescription": "C3 residency percent per core",
124 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Core_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per core",
130 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Core_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per core",
136 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Core_Residency"
139 },
140 {
141 "BriefDescription": "C2 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C2_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C3 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C3_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C6 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C6_Pkg_Residency"
157 },
158 {
159 "BriefDescription": "C7 residency percent per package",
160 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
161 "MetricGroup": "Power",
162 "MetricName": "C7_Pkg_Residency"
163 }
164]
diff --git a/tools/perf/pmu-events/arch/x86/goldmontplus/cache.json b/tools/perf/pmu-events/arch/x86/goldmontplus/cache.json
new file mode 100644
index 000000000000..b4791b443a66
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/goldmontplus/cache.json
@@ -0,0 +1,1453 @@
1[
2 {
3 "CollectPEBSRecord": "1",
4 "PublicDescription": "Counts memory requests originating from the core that miss in the L2 cache.",
5 "EventCode": "0x2E",
6 "Counter": "0,1,2,3",
7 "UMask": "0x41",
8 "PEBScounters": "0,1,2,3",
9 "EventName": "LONGEST_LAT_CACHE.MISS",
10 "PDIR_COUNTER": "na",
11 "SampleAfterValue": "200003",
12 "BriefDescription": "L2 cache request misses"
13 },
14 {
15 "CollectPEBSRecord": "1",
16 "PublicDescription": "Counts memory requests originating from the core that reference a cache line in the L2 cache.",
17 "EventCode": "0x2E",
18 "Counter": "0,1,2,3",
19 "UMask": "0x4f",
20 "PEBScounters": "0,1,2,3",
21 "EventName": "LONGEST_LAT_CACHE.REFERENCE",
22 "PDIR_COUNTER": "na",
23 "SampleAfterValue": "200003",
24 "BriefDescription": "L2 cache requests"
25 },
26 {
27 "CollectPEBSRecord": "1",
28 "PublicDescription": "Counts the number of demand and prefetch transactions that the L2 XQ rejects due to a full or near full condition which likely indicates back pressure from the intra-die interconnect (IDI) fabric. The XQ may reject transactions from the L2Q (non-cacheable requests), L2 misses and L2 write-back victims.",
29 "EventCode": "0x30",
30 "Counter": "0,1,2,3",
31 "UMask": "0x0",
32 "PEBScounters": "0,1,2,3",
33 "EventName": "L2_REJECT_XQ.ALL",
34 "PDIR_COUNTER": "na",
35 "SampleAfterValue": "200003",
36 "BriefDescription": "Requests rejected by the XQ"
37 },
38 {
39 "CollectPEBSRecord": "1",
40 "PublicDescription": "Counts the number of demand and L1 prefetcher requests rejected by the L2Q due to a full or nearly full condition which likely indicates back pressure from L2Q. It also counts requests that would have gone directly to the XQ, but are rejected due to a full or nearly full condition, indicating back pressure from the IDI link. The L2Q may also reject transactions from a core to insure fairness between cores, or to delay a core's dirty eviction when the address conflicts with incoming external snoops.",
41 "EventCode": "0x31",
42 "Counter": "0,1,2,3",
43 "UMask": "0x0",
44 "PEBScounters": "0,1,2,3",
45 "EventName": "CORE_REJECT_L2Q.ALL",
46 "PDIR_COUNTER": "na",
47 "SampleAfterValue": "200003",
48 "BriefDescription": "Requests rejected by the L2Q"
49 },
50 {
51 "CollectPEBSRecord": "1",
52 "PublicDescription": "Counts when a modified (dirty) cache line is evicted from the data L1 cache and needs to be written back to memory. No count will occur if the evicted line is clean, and hence does not require a writeback.",
53 "EventCode": "0x51",
54 "Counter": "0,1,2,3",
55 "UMask": "0x1",
56 "PEBScounters": "0,1,2,3",
57 "EventName": "DL1.REPLACEMENT",
58 "PDIR_COUNTER": "na",
59 "SampleAfterValue": "200003",
60 "BriefDescription": "L1 Cache evictions for dirty data"
61 },
62 {
63 "CollectPEBSRecord": "1",
64 "PublicDescription": "Counts cycles that fetch is stalled due to an outstanding ICache miss. That is, the decoder queue is able to accept bytes, but the fetch unit is unable to provide bytes due to an ICache miss. Note: this event is not the same as the total number of cycles spent retrieving instruction cache lines from the memory hierarchy.",
65 "EventCode": "0x86",
66 "Counter": "0,1,2,3",
67 "UMask": "0x2",
68 "PEBScounters": "0,1,2,3",
69 "EventName": "FETCH_STALL.ICACHE_FILL_PENDING_CYCLES",
70 "PDIR_COUNTER": "na",
71 "SampleAfterValue": "200003",
72 "BriefDescription": "Cycles code-fetch stalled due to an outstanding ICache miss."
73 },
74 {
75 "CollectPEBSRecord": "1",
76 "EventCode": "0xB7",
77 "Counter": "0,1,2,3",
78 "UMask": "0x1",
79 "PEBScounters": "0,1,2,3",
80 "EventName": "OFFCORE_RESPONSE",
81 "PDIR_COUNTER": "na",
82 "SampleAfterValue": "100007",
83 "BriefDescription": "Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)"
84 },
85 {
86 "PEBS": "2",
87 "CollectPEBSRecord": "2",
88 "PublicDescription": "Counts locked memory uops retired. This includes regular locks and bus locks. (To specifically count bus locks only, see the Offcore response event.) A locked access is one with a lock prefix, or an exchange to memory. See the SDM for a complete description of which memory load accesses are locks.",
89 "EventCode": "0xD0",
90 "Counter": "0,1,2,3",
91 "UMask": "0x21",
92 "PEBScounters": "0,1,2,3",
93 "EventName": "MEM_UOPS_RETIRED.LOCK_LOADS",
94 "SampleAfterValue": "200003",
95 "BriefDescription": "Locked load uops retired (Precise event capable)"
96 },
97 {
98 "PEBS": "2",
99 "CollectPEBSRecord": "2",
100 "PublicDescription": "Counts load uops retired where the data requested spans a 64 byte cache line boundary.",
101 "EventCode": "0xD0",
102 "Counter": "0,1,2,3",
103 "UMask": "0x41",
104 "PEBScounters": "0,1,2,3",
105 "EventName": "MEM_UOPS_RETIRED.SPLIT_LOADS",
106 "SampleAfterValue": "200003",
107 "BriefDescription": "Load uops retired that split a cache-line (Precise event capable)"
108 },
109 {
110 "PEBS": "2",
111 "CollectPEBSRecord": "2",
112 "PublicDescription": "Counts store uops retired where the data requested spans a 64 byte cache line boundary.",
113 "EventCode": "0xD0",
114 "Counter": "0,1,2,3",
115 "UMask": "0x42",
116 "PEBScounters": "0,1,2,3",
117 "EventName": "MEM_UOPS_RETIRED.SPLIT_STORES",
118 "SampleAfterValue": "200003",
119 "BriefDescription": "Stores uops retired that split a cache-line (Precise event capable)"
120 },
121 {
122 "PEBS": "2",
123 "CollectPEBSRecord": "2",
124 "PublicDescription": "Counts memory uops retired where the data requested spans a 64 byte cache line boundary.",
125 "EventCode": "0xD0",
126 "Counter": "0,1,2,3",
127 "UMask": "0x43",
128 "PEBScounters": "0,1,2,3",
129 "EventName": "MEM_UOPS_RETIRED.SPLIT",
130 "SampleAfterValue": "200003",
131 "BriefDescription": "Memory uops retired that split a cache-line (Precise event capable)"
132 },
133 {
134 "PEBS": "2",
135 "CollectPEBSRecord": "2",
136 "PublicDescription": "Counts the number of load uops retired.",
137 "EventCode": "0xD0",
138 "Counter": "0,1,2,3",
139 "UMask": "0x81",
140 "PEBScounters": "0,1,2,3",
141 "EventName": "MEM_UOPS_RETIRED.ALL_LOADS",
142 "SampleAfterValue": "200003",
143 "BriefDescription": "Load uops retired (Precise event capable)"
144 },
145 {
146 "PEBS": "2",
147 "CollectPEBSRecord": "2",
148 "PublicDescription": "Counts the number of store uops retired.",
149 "EventCode": "0xD0",
150 "Counter": "0,1,2,3",
151 "UMask": "0x82",
152 "PEBScounters": "0,1,2,3",
153 "EventName": "MEM_UOPS_RETIRED.ALL_STORES",
154 "SampleAfterValue": "200003",
155 "BriefDescription": "Store uops retired (Precise event capable)"
156 },
157 {
158 "PEBS": "2",
159 "CollectPEBSRecord": "2",
160 "PublicDescription": "Counts the number of memory uops retired that is either a loads or a store or both.",
161 "EventCode": "0xD0",
162 "Counter": "0,1,2,3",
163 "UMask": "0x83",
164 "PEBScounters": "0,1,2,3",
165 "EventName": "MEM_UOPS_RETIRED.ALL",
166 "SampleAfterValue": "200003",
167 "BriefDescription": "Memory uops retired (Precise event capable)"
168 },
169 {
170 "PEBS": "2",
171 "CollectPEBSRecord": "2",
172 "PublicDescription": "Counts load uops retired that hit the L1 data cache.",
173 "EventCode": "0xD1",
174 "Counter": "0,1,2,3",
175 "UMask": "0x1",
176 "PEBScounters": "0,1,2,3",
177 "EventName": "MEM_LOAD_UOPS_RETIRED.L1_HIT",
178 "SampleAfterValue": "200003",
179 "BriefDescription": "Load uops retired that hit L1 data cache (Precise event capable)"
180 },
181 {
182 "PEBS": "2",
183 "CollectPEBSRecord": "2",
184 "PublicDescription": "Counts load uops retired that hit in the L2 cache.",
185 "EventCode": "0xD1",
186 "Counter": "0,1,2,3",
187 "UMask": "0x2",
188 "PEBScounters": "0,1,2,3",
189 "EventName": "MEM_LOAD_UOPS_RETIRED.L2_HIT",
190 "SampleAfterValue": "200003",
191 "BriefDescription": "Load uops retired that hit L2 (Precise event capable)"
192 },
193 {
194 "PEBS": "2",
195 "CollectPEBSRecord": "2",
196 "PublicDescription": "Counts load uops retired that miss the L1 data cache.",
197 "EventCode": "0xD1",
198 "Counter": "0,1,2,3",
199 "UMask": "0x8",
200 "PEBScounters": "0,1,2,3",
201 "EventName": "MEM_LOAD_UOPS_RETIRED.L1_MISS",
202 "SampleAfterValue": "200003",
203 "BriefDescription": "Load uops retired that missed L1 data cache (Precise event capable)"
204 },
205 {
206 "PEBS": "2",
207 "CollectPEBSRecord": "2",
208 "PublicDescription": "Counts load uops retired that miss in the L2 cache.",
209 "EventCode": "0xD1",
210 "Counter": "0,1,2,3",
211 "UMask": "0x10",
212 "PEBScounters": "0,1,2,3",
213 "EventName": "MEM_LOAD_UOPS_RETIRED.L2_MISS",
214 "SampleAfterValue": "200003",
215 "BriefDescription": "Load uops retired that missed L2 (Precise event capable)"
216 },
217 {
218 "PEBS": "2",
219 "CollectPEBSRecord": "2",
220 "PublicDescription": "Counts load uops retired where the cache line containing the data was in the modified state of another core or modules cache (HITM). More specifically, this means that when the load address was checked by other caching agents (typically another processor) in the system, one of those caching agents indicated that they had a dirty copy of the data. Loads that obtain a HITM response incur greater latency than most is typical for a load. In addition, since HITM indicates that some other processor had this data in its cache, it implies that the data was shared between processors, or potentially was a lock or semaphore value. This event is useful for locating sharing, false sharing, and contended locks.",
221 "EventCode": "0xD1",
222 "Counter": "0,1,2,3",
223 "UMask": "0x20",
224 "PEBScounters": "0,1,2,3",
225 "EventName": "MEM_LOAD_UOPS_RETIRED.HITM",
226 "SampleAfterValue": "200003",
227 "BriefDescription": "Memory uop retired where cross core or cross module HITM occurred (Precise event capable)"
228 },
229 {
230 "PEBS": "2",
231 "CollectPEBSRecord": "2",
232 "PublicDescription": "Counts memory load uops retired where the data is retrieved from the WCB (or fill buffer), indicating that the load found its data while that data was in the process of being brought into the L1 cache. Typically a load will receive this indication when some other load or prefetch missed the L1 cache and was in the process of retrieving the cache line containing the data, but that process had not yet finished (and written the data back to the cache). For example, consider load X and Y, both referencing the same cache line that is not in the L1 cache. If load X misses cache first, it obtains and WCB (or fill buffer) and begins the process of requesting the data. When load Y requests the data, it will either hit the WCB, or the L1 cache, depending on exactly what time the request to Y occurs.",
233 "EventCode": "0xD1",
234 "Counter": "0,1,2,3",
235 "UMask": "0x40",
236 "PEBScounters": "0,1,2,3",
237 "EventName": "MEM_LOAD_UOPS_RETIRED.WCB_HIT",
238 "SampleAfterValue": "200003",
239 "BriefDescription": "Loads retired that hit WCB (Precise event capable)"
240 },
241 {
242 "PEBS": "2",
243 "CollectPEBSRecord": "2",
244 "PublicDescription": "Counts memory load uops retired where the data is retrieved from DRAM. Event is counted at retirement, so the speculative loads are ignored. A memory load can hit (or miss) the L1 cache, hit (or miss) the L2 cache, hit DRAM, hit in the WCB or receive a HITM response.",
245 "EventCode": "0xD1",
246 "Counter": "0,1,2,3",
247 "UMask": "0x80",
248 "PEBScounters": "0,1,2,3",
249 "EventName": "MEM_LOAD_UOPS_RETIRED.DRAM_HIT",
250 "SampleAfterValue": "200003",
251 "BriefDescription": "Loads retired that came from DRAM (Precise event capable)"
252 },
253 {
254 "CollectPEBSRecord": "1",
255 "PublicDescription": "Counts demand cacheable data reads of full cache lines have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
256 "EventCode": "0xB7",
257 "MSRValue": "0x0000010001",
258 "Counter": "0,1,2,3",
259 "UMask": "0x1",
260 "PEBScounters": "0,1,2,3",
261 "EventName": "OFFCORE_RESPONSE.DEMAND_DATA_RD.ANY_RESPONSE",
262 "PDIR_COUNTER": "na",
263 "MSRIndex": "0x1a6, 0x1a7",
264 "SampleAfterValue": "100007",
265 "BriefDescription": "Counts demand cacheable data reads of full cache lines have any transaction responses from the uncore subsystem.",
266 "Offcore": "1"
267 },
268 {
269 "CollectPEBSRecord": "1",
270 "PublicDescription": "Counts demand cacheable data reads of full cache lines hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
271 "EventCode": "0xB7",
272 "MSRValue": "0x0000040001",
273 "Counter": "0,1,2,3",
274 "UMask": "0x1",
275 "PEBScounters": "0,1,2,3",
276 "EventName": "OFFCORE_RESPONSE.DEMAND_DATA_RD.L2_HIT",
277 "PDIR_COUNTER": "na",
278 "MSRIndex": "0x1a6, 0x1a7",
279 "SampleAfterValue": "100007",
280 "BriefDescription": "Counts demand cacheable data reads of full cache lines hit the L2 cache.",
281 "Offcore": "1"
282 },
283 {
284 "CollectPEBSRecord": "1",
285 "PublicDescription": "Counts demand cacheable data reads of full cache lines true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
286 "EventCode": "0xB7",
287 "MSRValue": "0x0200000001",
288 "Counter": "0,1,2,3",
289 "UMask": "0x1",
290 "PEBScounters": "0,1,2,3",
291 "EventName": "OFFCORE_RESPONSE.DEMAND_DATA_RD.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
292 "PDIR_COUNTER": "na",
293 "MSRIndex": "0x1a6, 0x1a7",
294 "SampleAfterValue": "100007",
295 "BriefDescription": "Counts demand cacheable data reads of full cache lines true miss for the L2 cache with a snoop miss in the other processor module. ",
296 "Offcore": "1"
297 },
298 {
299 "CollectPEBSRecord": "1",
300 "PublicDescription": "Counts demand cacheable data reads of full cache lines miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
301 "EventCode": "0xB7",
302 "MSRValue": "0x1000000001",
303 "Counter": "0,1,2,3",
304 "UMask": "0x1",
305 "PEBScounters": "0,1,2,3",
306 "EventName": "OFFCORE_RESPONSE.DEMAND_DATA_RD.L2_MISS.HITM_OTHER_CORE",
307 "PDIR_COUNTER": "na",
308 "MSRIndex": "0x1a6, 0x1a7",
309 "SampleAfterValue": "100007",
310 "BriefDescription": "Counts demand cacheable data reads of full cache lines miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
311 "Offcore": "1"
312 },
313 {
314 "CollectPEBSRecord": "1",
315 "PublicDescription": "Counts demand cacheable data reads of full cache lines outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
316 "EventCode": "0xB7",
317 "MSRValue": "0x4000000001",
318 "Counter": "0,1,2,3",
319 "UMask": "0x1",
320 "PEBScounters": "0,1,2,3",
321 "EventName": "OFFCORE_RESPONSE.DEMAND_DATA_RD.OUTSTANDING",
322 "PDIR_COUNTER": "na",
323 "MSRIndex": "0x1a6",
324 "SampleAfterValue": "100007",
325 "BriefDescription": "Counts demand cacheable data reads of full cache lines outstanding, per cycle, from the time of the L2 miss to when any response is received.",
326 "Offcore": "1"
327 },
328 {
329 "CollectPEBSRecord": "1",
330 "PublicDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
331 "EventCode": "0xB7",
332 "MSRValue": "0x0000010002",
333 "Counter": "0,1,2,3",
334 "UMask": "0x1",
335 "PEBScounters": "0,1,2,3",
336 "EventName": "OFFCORE_RESPONSE.DEMAND_RFO.ANY_RESPONSE",
337 "PDIR_COUNTER": "na",
338 "MSRIndex": "0x1a6, 0x1a7",
339 "SampleAfterValue": "100007",
340 "BriefDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line have any transaction responses from the uncore subsystem.",
341 "Offcore": "1"
342 },
343 {
344 "CollectPEBSRecord": "1",
345 "PublicDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
346 "EventCode": "0xB7",
347 "MSRValue": "0x0000040002",
348 "Counter": "0,1,2,3",
349 "UMask": "0x1",
350 "PEBScounters": "0,1,2,3",
351 "EventName": "OFFCORE_RESPONSE.DEMAND_RFO.L2_HIT",
352 "PDIR_COUNTER": "na",
353 "MSRIndex": "0x1a6, 0x1a7",
354 "SampleAfterValue": "100007",
355 "BriefDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line hit the L2 cache.",
356 "Offcore": "1"
357 },
358 {
359 "CollectPEBSRecord": "1",
360 "PublicDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
361 "EventCode": "0xB7",
362 "MSRValue": "0x0200000002",
363 "Counter": "0,1,2,3",
364 "UMask": "0x1",
365 "PEBScounters": "0,1,2,3",
366 "EventName": "OFFCORE_RESPONSE.DEMAND_RFO.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
367 "PDIR_COUNTER": "na",
368 "MSRIndex": "0x1a6, 0x1a7",
369 "SampleAfterValue": "100007",
370 "BriefDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line true miss for the L2 cache with a snoop miss in the other processor module. ",
371 "Offcore": "1"
372 },
373 {
374 "CollectPEBSRecord": "1",
375 "PublicDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
376 "EventCode": "0xB7",
377 "MSRValue": "0x1000000002",
378 "Counter": "0,1,2,3",
379 "UMask": "0x1",
380 "PEBScounters": "0,1,2,3",
381 "EventName": "OFFCORE_RESPONSE.DEMAND_RFO.L2_MISS.HITM_OTHER_CORE",
382 "PDIR_COUNTER": "na",
383 "MSRIndex": "0x1a6, 0x1a7",
384 "SampleAfterValue": "100007",
385 "BriefDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
386 "Offcore": "1"
387 },
388 {
389 "CollectPEBSRecord": "1",
390 "PublicDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
391 "EventCode": "0xB7",
392 "MSRValue": "0x4000000002",
393 "Counter": "0,1,2,3",
394 "UMask": "0x1",
395 "PEBScounters": "0,1,2,3",
396 "EventName": "OFFCORE_RESPONSE.DEMAND_RFO.OUTSTANDING",
397 "PDIR_COUNTER": "na",
398 "MSRIndex": "0x1a6",
399 "SampleAfterValue": "100007",
400 "BriefDescription": "Counts demand reads for ownership (RFO) requests generated by a write to full data cache line outstanding, per cycle, from the time of the L2 miss to when any response is received.",
401 "Offcore": "1"
402 },
403 {
404 "CollectPEBSRecord": "1",
405 "PublicDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
406 "EventCode": "0xB7",
407 "MSRValue": "0x0000010004",
408 "Counter": "0,1,2,3",
409 "UMask": "0x1",
410 "PEBScounters": "0,1,2,3",
411 "EventName": "OFFCORE_RESPONSE.DEMAND_CODE_RD.ANY_RESPONSE",
412 "PDIR_COUNTER": "na",
413 "MSRIndex": "0x1a6, 0x1a7",
414 "SampleAfterValue": "100007",
415 "BriefDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache have any transaction responses from the uncore subsystem.",
416 "Offcore": "1"
417 },
418 {
419 "CollectPEBSRecord": "1",
420 "PublicDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
421 "EventCode": "0xB7",
422 "MSRValue": "0x0000040004",
423 "Counter": "0,1,2,3",
424 "UMask": "0x1",
425 "PEBScounters": "0,1,2,3",
426 "EventName": "OFFCORE_RESPONSE.DEMAND_CODE_RD.L2_HIT",
427 "PDIR_COUNTER": "na",
428 "MSRIndex": "0x1a6, 0x1a7",
429 "SampleAfterValue": "100007",
430 "BriefDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache hit the L2 cache.",
431 "Offcore": "1"
432 },
433 {
434 "CollectPEBSRecord": "1",
435 "PublicDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
436 "EventCode": "0xB7",
437 "MSRValue": "0x0200000004",
438 "Counter": "0,1,2,3",
439 "UMask": "0x1",
440 "PEBScounters": "0,1,2,3",
441 "EventName": "OFFCORE_RESPONSE.DEMAND_CODE_RD.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
442 "PDIR_COUNTER": "na",
443 "MSRIndex": "0x1a6, 0x1a7",
444 "SampleAfterValue": "100007",
445 "BriefDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache true miss for the L2 cache with a snoop miss in the other processor module. ",
446 "Offcore": "1"
447 },
448 {
449 "CollectPEBSRecord": "1",
450 "PublicDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
451 "EventCode": "0xB7",
452 "MSRValue": "0x1000000004",
453 "Counter": "0,1,2,3",
454 "UMask": "0x1",
455 "PEBScounters": "0,1,2,3",
456 "EventName": "OFFCORE_RESPONSE.DEMAND_CODE_RD.L2_MISS.HITM_OTHER_CORE",
457 "PDIR_COUNTER": "na",
458 "MSRIndex": "0x1a6, 0x1a7",
459 "SampleAfterValue": "100007",
460 "BriefDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
461 "Offcore": "1"
462 },
463 {
464 "CollectPEBSRecord": "1",
465 "PublicDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
466 "EventCode": "0xB7",
467 "MSRValue": "0x4000000004",
468 "Counter": "0,1,2,3",
469 "UMask": "0x1",
470 "PEBScounters": "0,1,2,3",
471 "EventName": "OFFCORE_RESPONSE.DEMAND_CODE_RD.OUTSTANDING",
472 "PDIR_COUNTER": "na",
473 "MSRIndex": "0x1a6",
474 "SampleAfterValue": "100007",
475 "BriefDescription": "Counts demand instruction cacheline and I-side prefetch requests that miss the instruction cache outstanding, per cycle, from the time of the L2 miss to when any response is received.",
476 "Offcore": "1"
477 },
478 {
479 "CollectPEBSRecord": "1",
480 "PublicDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
481 "EventCode": "0xB7",
482 "MSRValue": "0x0000010008",
483 "Counter": "0,1,2,3",
484 "UMask": "0x1",
485 "PEBScounters": "0,1,2,3",
486 "EventName": "OFFCORE_RESPONSE.COREWB.ANY_RESPONSE",
487 "PDIR_COUNTER": "na",
488 "MSRIndex": "0x1a6, 0x1a7",
489 "SampleAfterValue": "100007",
490 "BriefDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions have any transaction responses from the uncore subsystem.",
491 "Offcore": "1"
492 },
493 {
494 "CollectPEBSRecord": "1",
495 "PublicDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
496 "EventCode": "0xB7",
497 "MSRValue": "0x0000040008",
498 "Counter": "0,1,2,3",
499 "UMask": "0x1",
500 "PEBScounters": "0,1,2,3",
501 "EventName": "OFFCORE_RESPONSE.COREWB.L2_HIT",
502 "PDIR_COUNTER": "na",
503 "MSRIndex": "0x1a6, 0x1a7",
504 "SampleAfterValue": "100007",
505 "BriefDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions hit the L2 cache.",
506 "Offcore": "1"
507 },
508 {
509 "CollectPEBSRecord": "1",
510 "PublicDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
511 "EventCode": "0xB7",
512 "MSRValue": "0x0200000008",
513 "Counter": "0,1,2,3",
514 "UMask": "0x1",
515 "PEBScounters": "0,1,2,3",
516 "EventName": "OFFCORE_RESPONSE.COREWB.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
517 "PDIR_COUNTER": "na",
518 "MSRIndex": "0x1a6, 0x1a7",
519 "SampleAfterValue": "100007",
520 "BriefDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions true miss for the L2 cache with a snoop miss in the other processor module. ",
521 "Offcore": "1"
522 },
523 {
524 "CollectPEBSRecord": "1",
525 "PublicDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
526 "EventCode": "0xB7",
527 "MSRValue": "0x1000000008",
528 "Counter": "0,1,2,3",
529 "UMask": "0x1",
530 "PEBScounters": "0,1,2,3",
531 "EventName": "OFFCORE_RESPONSE.COREWB.L2_MISS.HITM_OTHER_CORE",
532 "PDIR_COUNTER": "na",
533 "MSRIndex": "0x1a6, 0x1a7",
534 "SampleAfterValue": "100007",
535 "BriefDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
536 "Offcore": "1"
537 },
538 {
539 "CollectPEBSRecord": "1",
540 "PublicDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
541 "EventCode": "0xB7",
542 "MSRValue": "0x4000000008",
543 "Counter": "0,1,2,3",
544 "UMask": "0x1",
545 "PEBScounters": "0,1,2,3",
546 "EventName": "OFFCORE_RESPONSE.COREWB.OUTSTANDING",
547 "PDIR_COUNTER": "na",
548 "MSRIndex": "0x1a6",
549 "SampleAfterValue": "100007",
550 "BriefDescription": "Counts the number of writeback transactions caused by L1 or L2 cache evictions outstanding, per cycle, from the time of the L2 miss to when any response is received.",
551 "Offcore": "1"
552 },
553 {
554 "CollectPEBSRecord": "1",
555 "PublicDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
556 "EventCode": "0xB7",
557 "MSRValue": "0x0000010010",
558 "Counter": "0,1,2,3",
559 "UMask": "0x1",
560 "PEBScounters": "0,1,2,3",
561 "EventName": "OFFCORE_RESPONSE.PF_L2_DATA_RD.ANY_RESPONSE",
562 "PDIR_COUNTER": "na",
563 "MSRIndex": "0x1a6, 0x1a7",
564 "SampleAfterValue": "100007",
565 "BriefDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher have any transaction responses from the uncore subsystem.",
566 "Offcore": "1"
567 },
568 {
569 "CollectPEBSRecord": "1",
570 "PublicDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
571 "EventCode": "0xB7",
572 "MSRValue": "0x0000040010",
573 "Counter": "0,1,2,3",
574 "UMask": "0x1",
575 "PEBScounters": "0,1,2,3",
576 "EventName": "OFFCORE_RESPONSE.PF_L2_DATA_RD.L2_HIT",
577 "PDIR_COUNTER": "na",
578 "MSRIndex": "0x1a6, 0x1a7",
579 "SampleAfterValue": "100007",
580 "BriefDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher hit the L2 cache.",
581 "Offcore": "1"
582 },
583 {
584 "CollectPEBSRecord": "1",
585 "PublicDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
586 "EventCode": "0xB7",
587 "MSRValue": "0x0200000010",
588 "Counter": "0,1,2,3",
589 "UMask": "0x1",
590 "PEBScounters": "0,1,2,3",
591 "EventName": "OFFCORE_RESPONSE.PF_L2_DATA_RD.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
592 "PDIR_COUNTER": "na",
593 "MSRIndex": "0x1a6, 0x1a7",
594 "SampleAfterValue": "100007",
595 "BriefDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher true miss for the L2 cache with a snoop miss in the other processor module. ",
596 "Offcore": "1"
597 },
598 {
599 "CollectPEBSRecord": "1",
600 "PublicDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
601 "EventCode": "0xB7",
602 "MSRValue": "0x1000000010",
603 "Counter": "0,1,2,3",
604 "UMask": "0x1",
605 "PEBScounters": "0,1,2,3",
606 "EventName": "OFFCORE_RESPONSE.PF_L2_DATA_RD.L2_MISS.HITM_OTHER_CORE",
607 "PDIR_COUNTER": "na",
608 "MSRIndex": "0x1a6, 0x1a7",
609 "SampleAfterValue": "100007",
610 "BriefDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
611 "Offcore": "1"
612 },
613 {
614 "CollectPEBSRecord": "1",
615 "PublicDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
616 "EventCode": "0xB7",
617 "MSRValue": "0x4000000010",
618 "Counter": "0,1,2,3",
619 "UMask": "0x1",
620 "PEBScounters": "0,1,2,3",
621 "EventName": "OFFCORE_RESPONSE.PF_L2_DATA_RD.OUTSTANDING",
622 "PDIR_COUNTER": "na",
623 "MSRIndex": "0x1a6",
624 "SampleAfterValue": "100007",
625 "BriefDescription": "Counts data cacheline reads generated by hardware L2 cache prefetcher outstanding, per cycle, from the time of the L2 miss to when any response is received.",
626 "Offcore": "1"
627 },
628 {
629 "CollectPEBSRecord": "1",
630 "PublicDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
631 "EventCode": "0xB7",
632 "MSRValue": "0x0000010020",
633 "Counter": "0,1,2,3",
634 "UMask": "0x1",
635 "PEBScounters": "0,1,2,3",
636 "EventName": "OFFCORE_RESPONSE.PF_L2_RFO.ANY_RESPONSE",
637 "PDIR_COUNTER": "na",
638 "MSRIndex": "0x1a6, 0x1a7",
639 "SampleAfterValue": "100007",
640 "BriefDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher have any transaction responses from the uncore subsystem.",
641 "Offcore": "1"
642 },
643 {
644 "CollectPEBSRecord": "1",
645 "PublicDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
646 "EventCode": "0xB7",
647 "MSRValue": "0x0000040020",
648 "Counter": "0,1,2,3",
649 "UMask": "0x1",
650 "PEBScounters": "0,1,2,3",
651 "EventName": "OFFCORE_RESPONSE.PF_L2_RFO.L2_HIT",
652 "PDIR_COUNTER": "na",
653 "MSRIndex": "0x1a6, 0x1a7",
654 "SampleAfterValue": "100007",
655 "BriefDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher hit the L2 cache.",
656 "Offcore": "1"
657 },
658 {
659 "CollectPEBSRecord": "1",
660 "PublicDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
661 "EventCode": "0xB7",
662 "MSRValue": "0x0200000020",
663 "Counter": "0,1,2,3",
664 "UMask": "0x1",
665 "PEBScounters": "0,1,2,3",
666 "EventName": "OFFCORE_RESPONSE.PF_L2_RFO.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
667 "PDIR_COUNTER": "na",
668 "MSRIndex": "0x1a6, 0x1a7",
669 "SampleAfterValue": "100007",
670 "BriefDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher true miss for the L2 cache with a snoop miss in the other processor module. ",
671 "Offcore": "1"
672 },
673 {
674 "CollectPEBSRecord": "1",
675 "PublicDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
676 "EventCode": "0xB7",
677 "MSRValue": "0x1000000020",
678 "Counter": "0,1,2,3",
679 "UMask": "0x1",
680 "PEBScounters": "0,1,2,3",
681 "EventName": "OFFCORE_RESPONSE.PF_L2_RFO.L2_MISS.HITM_OTHER_CORE",
682 "PDIR_COUNTER": "na",
683 "MSRIndex": "0x1a6, 0x1a7",
684 "SampleAfterValue": "100007",
685 "BriefDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
686 "Offcore": "1"
687 },
688 {
689 "CollectPEBSRecord": "1",
690 "PublicDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
691 "EventCode": "0xB7",
692 "MSRValue": "0x4000000020",
693 "Counter": "0,1,2,3",
694 "UMask": "0x1",
695 "PEBScounters": "0,1,2,3",
696 "EventName": "OFFCORE_RESPONSE.PF_L2_RFO.OUTSTANDING",
697 "PDIR_COUNTER": "na",
698 "MSRIndex": "0x1a6",
699 "SampleAfterValue": "100007",
700 "BriefDescription": "Counts reads for ownership (RFO) requests generated by L2 prefetcher outstanding, per cycle, from the time of the L2 miss to when any response is received.",
701 "Offcore": "1"
702 },
703 {
704 "CollectPEBSRecord": "1",
705 "PublicDescription": "Counts bus lock and split lock requests have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
706 "EventCode": "0xB7",
707 "MSRValue": "0x0000010400",
708 "Counter": "0,1,2,3",
709 "UMask": "0x1",
710 "PEBScounters": "0,1,2,3",
711 "EventName": "OFFCORE_RESPONSE.BUS_LOCKS.ANY_RESPONSE",
712 "PDIR_COUNTER": "na",
713 "MSRIndex": "0x1a6, 0x1a7",
714 "SampleAfterValue": "100007",
715 "BriefDescription": "Counts bus lock and split lock requests have any transaction responses from the uncore subsystem.",
716 "Offcore": "1"
717 },
718 {
719 "CollectPEBSRecord": "1",
720 "PublicDescription": "Counts bus lock and split lock requests hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
721 "EventCode": "0xB7",
722 "MSRValue": "0x0000040400",
723 "Counter": "0,1,2,3",
724 "UMask": "0x1",
725 "PEBScounters": "0,1,2,3",
726 "EventName": "OFFCORE_RESPONSE.BUS_LOCKS.L2_HIT",
727 "PDIR_COUNTER": "na",
728 "MSRIndex": "0x1a6, 0x1a7",
729 "SampleAfterValue": "100007",
730 "BriefDescription": "Counts bus lock and split lock requests hit the L2 cache.",
731 "Offcore": "1"
732 },
733 {
734 "CollectPEBSRecord": "1",
735 "PublicDescription": "Counts bus lock and split lock requests true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
736 "EventCode": "0xB7",
737 "MSRValue": "0x0200000400",
738 "Counter": "0,1,2,3",
739 "UMask": "0x1",
740 "PEBScounters": "0,1,2,3",
741 "EventName": "OFFCORE_RESPONSE.BUS_LOCKS.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
742 "PDIR_COUNTER": "na",
743 "MSRIndex": "0x1a6, 0x1a7",
744 "SampleAfterValue": "100007",
745 "BriefDescription": "Counts bus lock and split lock requests true miss for the L2 cache with a snoop miss in the other processor module. ",
746 "Offcore": "1"
747 },
748 {
749 "CollectPEBSRecord": "1",
750 "PublicDescription": "Counts bus lock and split lock requests miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
751 "EventCode": "0xB7",
752 "MSRValue": "0x1000000400",
753 "Counter": "0,1,2,3",
754 "UMask": "0x1",
755 "PEBScounters": "0,1,2,3",
756 "EventName": "OFFCORE_RESPONSE.BUS_LOCKS.L2_MISS.HITM_OTHER_CORE",
757 "PDIR_COUNTER": "na",
758 "MSRIndex": "0x1a6, 0x1a7",
759 "SampleAfterValue": "100007",
760 "BriefDescription": "Counts bus lock and split lock requests miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
761 "Offcore": "1"
762 },
763 {
764 "CollectPEBSRecord": "1",
765 "PublicDescription": "Counts bus lock and split lock requests outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
766 "EventCode": "0xB7",
767 "MSRValue": "0x4000000400",
768 "Counter": "0,1,2,3",
769 "UMask": "0x1",
770 "PEBScounters": "0,1,2,3",
771 "EventName": "OFFCORE_RESPONSE.BUS_LOCKS.OUTSTANDING",
772 "PDIR_COUNTER": "na",
773 "MSRIndex": "0x1a6",
774 "SampleAfterValue": "100007",
775 "BriefDescription": "Counts bus lock and split lock requests outstanding, per cycle, from the time of the L2 miss to when any response is received.",
776 "Offcore": "1"
777 },
778 {
779 "CollectPEBSRecord": "1",
780 "PublicDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
781 "EventCode": "0xB7",
782 "MSRValue": "0x0000010800",
783 "Counter": "0,1,2,3",
784 "UMask": "0x1",
785 "PEBScounters": "0,1,2,3",
786 "EventName": "OFFCORE_RESPONSE.FULL_STREAMING_STORES.ANY_RESPONSE",
787 "PDIR_COUNTER": "na",
788 "MSRIndex": "0x1a6, 0x1a7",
789 "SampleAfterValue": "100007",
790 "BriefDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes have any transaction responses from the uncore subsystem.",
791 "Offcore": "1"
792 },
793 {
794 "CollectPEBSRecord": "1",
795 "PublicDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
796 "EventCode": "0xB7",
797 "MSRValue": "0x0000040800",
798 "Counter": "0,1,2,3",
799 "UMask": "0x1",
800 "PEBScounters": "0,1,2,3",
801 "EventName": "OFFCORE_RESPONSE.FULL_STREAMING_STORES.L2_HIT",
802 "PDIR_COUNTER": "na",
803 "MSRIndex": "0x1a6, 0x1a7",
804 "SampleAfterValue": "100007",
805 "BriefDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes hit the L2 cache.",
806 "Offcore": "1"
807 },
808 {
809 "CollectPEBSRecord": "1",
810 "PublicDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
811 "EventCode": "0xB7",
812 "MSRValue": "0x0200000800",
813 "Counter": "0,1,2,3",
814 "UMask": "0x1",
815 "PEBScounters": "0,1,2,3",
816 "EventName": "OFFCORE_RESPONSE.FULL_STREAMING_STORES.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
817 "PDIR_COUNTER": "na",
818 "MSRIndex": "0x1a6, 0x1a7",
819 "SampleAfterValue": "100007",
820 "BriefDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes true miss for the L2 cache with a snoop miss in the other processor module. ",
821 "Offcore": "1"
822 },
823 {
824 "CollectPEBSRecord": "1",
825 "PublicDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
826 "EventCode": "0xB7",
827 "MSRValue": "0x1000000800",
828 "Counter": "0,1,2,3",
829 "UMask": "0x1",
830 "PEBScounters": "0,1,2,3",
831 "EventName": "OFFCORE_RESPONSE.FULL_STREAMING_STORES.L2_MISS.HITM_OTHER_CORE",
832 "PDIR_COUNTER": "na",
833 "MSRIndex": "0x1a6, 0x1a7",
834 "SampleAfterValue": "100007",
835 "BriefDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
836 "Offcore": "1"
837 },
838 {
839 "CollectPEBSRecord": "1",
840 "PublicDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
841 "EventCode": "0xB7",
842 "MSRValue": "0x4000000800",
843 "Counter": "0,1,2,3",
844 "UMask": "0x1",
845 "PEBScounters": "0,1,2,3",
846 "EventName": "OFFCORE_RESPONSE.FULL_STREAMING_STORES.OUTSTANDING",
847 "PDIR_COUNTER": "na",
848 "MSRIndex": "0x1a6",
849 "SampleAfterValue": "100007",
850 "BriefDescription": "Counts full cache line data writes to uncacheable write combining (USWC) memory region and full cache-line non-temporal writes outstanding, per cycle, from the time of the L2 miss to when any response is received.",
851 "Offcore": "1"
852 },
853 {
854 "CollectPEBSRecord": "1",
855 "PublicDescription": "Counts data cache lines requests by software prefetch instructions have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
856 "EventCode": "0xB7",
857 "MSRValue": "0x0000011000",
858 "Counter": "0,1,2,3",
859 "UMask": "0x1",
860 "PEBScounters": "0,1,2,3",
861 "EventName": "OFFCORE_RESPONSE.SW_PREFETCH.ANY_RESPONSE",
862 "PDIR_COUNTER": "na",
863 "MSRIndex": "0x1a6, 0x1a7",
864 "SampleAfterValue": "100007",
865 "BriefDescription": "Counts data cache lines requests by software prefetch instructions have any transaction responses from the uncore subsystem.",
866 "Offcore": "1"
867 },
868 {
869 "CollectPEBSRecord": "1",
870 "PublicDescription": "Counts data cache lines requests by software prefetch instructions hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
871 "EventCode": "0xB7",
872 "MSRValue": "0x0000041000",
873 "Counter": "0,1,2,3",
874 "UMask": "0x1",
875 "PEBScounters": "0,1,2,3",
876 "EventName": "OFFCORE_RESPONSE.SW_PREFETCH.L2_HIT",
877 "PDIR_COUNTER": "na",
878 "MSRIndex": "0x1a6, 0x1a7",
879 "SampleAfterValue": "100007",
880 "BriefDescription": "Counts data cache lines requests by software prefetch instructions hit the L2 cache.",
881 "Offcore": "1"
882 },
883 {
884 "CollectPEBSRecord": "1",
885 "PublicDescription": "Counts data cache lines requests by software prefetch instructions true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
886 "EventCode": "0xB7",
887 "MSRValue": "0x0200001000",
888 "Counter": "0,1,2,3",
889 "UMask": "0x1",
890 "PEBScounters": "0,1,2,3",
891 "EventName": "OFFCORE_RESPONSE.SW_PREFETCH.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
892 "PDIR_COUNTER": "na",
893 "MSRIndex": "0x1a6, 0x1a7",
894 "SampleAfterValue": "100007",
895 "BriefDescription": "Counts data cache lines requests by software prefetch instructions true miss for the L2 cache with a snoop miss in the other processor module. ",
896 "Offcore": "1"
897 },
898 {
899 "CollectPEBSRecord": "1",
900 "PublicDescription": "Counts data cache lines requests by software prefetch instructions miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
901 "EventCode": "0xB7",
902 "MSRValue": "0x1000001000",
903 "Counter": "0,1,2,3",
904 "UMask": "0x1",
905 "PEBScounters": "0,1,2,3",
906 "EventName": "OFFCORE_RESPONSE.SW_PREFETCH.L2_MISS.HITM_OTHER_CORE",
907 "PDIR_COUNTER": "na",
908 "MSRIndex": "0x1a6, 0x1a7",
909 "SampleAfterValue": "100007",
910 "BriefDescription": "Counts data cache lines requests by software prefetch instructions miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
911 "Offcore": "1"
912 },
913 {
914 "CollectPEBSRecord": "1",
915 "PublicDescription": "Counts data cache lines requests by software prefetch instructions outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
916 "EventCode": "0xB7",
917 "MSRValue": "0x4000001000",
918 "Counter": "0,1,2,3",
919 "UMask": "0x1",
920 "PEBScounters": "0,1,2,3",
921 "EventName": "OFFCORE_RESPONSE.SW_PREFETCH.OUTSTANDING",
922 "PDIR_COUNTER": "na",
923 "MSRIndex": "0x1a6",
924 "SampleAfterValue": "100007",
925 "BriefDescription": "Counts data cache lines requests by software prefetch instructions outstanding, per cycle, from the time of the L2 miss to when any response is received.",
926 "Offcore": "1"
927 },
928 {
929 "CollectPEBSRecord": "1",
930 "PublicDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
931 "EventCode": "0xB7",
932 "MSRValue": "0x0000012000",
933 "Counter": "0,1,2,3",
934 "UMask": "0x1",
935 "PEBScounters": "0,1,2,3",
936 "EventName": "OFFCORE_RESPONSE.PF_L1_DATA_RD.ANY_RESPONSE",
937 "PDIR_COUNTER": "na",
938 "MSRIndex": "0x1a6, 0x1a7",
939 "SampleAfterValue": "100007",
940 "BriefDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher have any transaction responses from the uncore subsystem.",
941 "Offcore": "1"
942 },
943 {
944 "CollectPEBSRecord": "1",
945 "PublicDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
946 "EventCode": "0xB7",
947 "MSRValue": "0x0000042000",
948 "Counter": "0,1,2,3",
949 "UMask": "0x1",
950 "PEBScounters": "0,1,2,3",
951 "EventName": "OFFCORE_RESPONSE.PF_L1_DATA_RD.L2_HIT",
952 "PDIR_COUNTER": "na",
953 "MSRIndex": "0x1a6, 0x1a7",
954 "SampleAfterValue": "100007",
955 "BriefDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher hit the L2 cache.",
956 "Offcore": "1"
957 },
958 {
959 "CollectPEBSRecord": "1",
960 "PublicDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
961 "EventCode": "0xB7",
962 "MSRValue": "0x0200002000",
963 "Counter": "0,1,2,3",
964 "UMask": "0x1",
965 "PEBScounters": "0,1,2,3",
966 "EventName": "OFFCORE_RESPONSE.PF_L1_DATA_RD.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
967 "PDIR_COUNTER": "na",
968 "MSRIndex": "0x1a6, 0x1a7",
969 "SampleAfterValue": "100007",
970 "BriefDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher true miss for the L2 cache with a snoop miss in the other processor module. ",
971 "Offcore": "1"
972 },
973 {
974 "CollectPEBSRecord": "1",
975 "PublicDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
976 "EventCode": "0xB7",
977 "MSRValue": "0x1000002000",
978 "Counter": "0,1,2,3",
979 "UMask": "0x1",
980 "PEBScounters": "0,1,2,3",
981 "EventName": "OFFCORE_RESPONSE.PF_L1_DATA_RD.L2_MISS.HITM_OTHER_CORE",
982 "PDIR_COUNTER": "na",
983 "MSRIndex": "0x1a6, 0x1a7",
984 "SampleAfterValue": "100007",
985 "BriefDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
986 "Offcore": "1"
987 },
988 {
989 "CollectPEBSRecord": "1",
990 "PublicDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
991 "EventCode": "0xB7",
992 "MSRValue": "0x4000002000",
993 "Counter": "0,1,2,3",
994 "UMask": "0x1",
995 "PEBScounters": "0,1,2,3",
996 "EventName": "OFFCORE_RESPONSE.PF_L1_DATA_RD.OUTSTANDING",
997 "PDIR_COUNTER": "na",
998 "MSRIndex": "0x1a6",
999 "SampleAfterValue": "100007",
1000 "BriefDescription": "Counts data cache line reads generated by hardware L1 data cache prefetcher outstanding, per cycle, from the time of the L2 miss to when any response is received.",
1001 "Offcore": "1"
1002 },
1003 {
1004 "CollectPEBSRecord": "1",
1005 "PublicDescription": "Counts any data writes to uncacheable write combining (USWC) memory region have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1006 "EventCode": "0xB7",
1007 "MSRValue": "0x0000014800",
1008 "Counter": "0,1,2,3",
1009 "UMask": "0x1",
1010 "PEBScounters": "0,1,2,3",
1011 "EventName": "OFFCORE_RESPONSE.STREAMING_STORES.ANY_RESPONSE",
1012 "PDIR_COUNTER": "na",
1013 "MSRIndex": "0x1a6, 0x1a7",
1014 "SampleAfterValue": "100007",
1015 "BriefDescription": "Counts any data writes to uncacheable write combining (USWC) memory region have any transaction responses from the uncore subsystem.",
1016 "Offcore": "1"
1017 },
1018 {
1019 "CollectPEBSRecord": "1",
1020 "PublicDescription": "Counts any data writes to uncacheable write combining (USWC) memory region hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1021 "EventCode": "0xB7",
1022 "MSRValue": "0x0000044800",
1023 "Counter": "0,1,2,3",
1024 "UMask": "0x1",
1025 "PEBScounters": "0,1,2,3",
1026 "EventName": "OFFCORE_RESPONSE.STREAMING_STORES.L2_HIT",
1027 "PDIR_COUNTER": "na",
1028 "MSRIndex": "0x1a6, 0x1a7",
1029 "SampleAfterValue": "100007",
1030 "BriefDescription": "Counts any data writes to uncacheable write combining (USWC) memory region hit the L2 cache.",
1031 "Offcore": "1"
1032 },
1033 {
1034 "CollectPEBSRecord": "1",
1035 "PublicDescription": "Counts any data writes to uncacheable write combining (USWC) memory region true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1036 "EventCode": "0xB7",
1037 "MSRValue": "0x0200004800",
1038 "Counter": "0,1,2,3",
1039 "UMask": "0x1",
1040 "PEBScounters": "0,1,2,3",
1041 "EventName": "OFFCORE_RESPONSE.STREAMING_STORES.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
1042 "PDIR_COUNTER": "na",
1043 "MSRIndex": "0x1a6, 0x1a7",
1044 "SampleAfterValue": "100007",
1045 "BriefDescription": "Counts any data writes to uncacheable write combining (USWC) memory region true miss for the L2 cache with a snoop miss in the other processor module. ",
1046 "Offcore": "1"
1047 },
1048 {
1049 "CollectPEBSRecord": "1",
1050 "PublicDescription": "Counts any data writes to uncacheable write combining (USWC) memory region miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1051 "EventCode": "0xB7",
1052 "MSRValue": "0x1000004800",
1053 "Counter": "0,1,2,3",
1054 "UMask": "0x1",
1055 "PEBScounters": "0,1,2,3",
1056 "EventName": "OFFCORE_RESPONSE.STREAMING_STORES.L2_MISS.HITM_OTHER_CORE",
1057 "PDIR_COUNTER": "na",
1058 "MSRIndex": "0x1a6, 0x1a7",
1059 "SampleAfterValue": "100007",
1060 "BriefDescription": "Counts any data writes to uncacheable write combining (USWC) memory region miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
1061 "Offcore": "1"
1062 },
1063 {
1064 "CollectPEBSRecord": "1",
1065 "PublicDescription": "Counts any data writes to uncacheable write combining (USWC) memory region outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1066 "EventCode": "0xB7",
1067 "MSRValue": "0x4000004800",
1068 "Counter": "0,1,2,3",
1069 "UMask": "0x1",
1070 "PEBScounters": "0,1,2,3",
1071 "EventName": "OFFCORE_RESPONSE.STREAMING_STORES.OUTSTANDING",
1072 "PDIR_COUNTER": "na",
1073 "MSRIndex": "0x1a6",
1074 "SampleAfterValue": "100007",
1075 "BriefDescription": "Counts any data writes to uncacheable write combining (USWC) memory region outstanding, per cycle, from the time of the L2 miss to when any response is received.",
1076 "Offcore": "1"
1077 },
1078 {
1079 "CollectPEBSRecord": "1",
1080 "PublicDescription": "Counts requests to the uncore subsystem have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1081 "EventCode": "0xB7",
1082 "MSRValue": "0x0000018000",
1083 "Counter": "0,1,2,3",
1084 "UMask": "0x1",
1085 "PEBScounters": "0,1,2,3",
1086 "EventName": "OFFCORE_RESPONSE.ANY_REQUEST.ANY_RESPONSE",
1087 "PDIR_COUNTER": "na",
1088 "MSRIndex": "0x1a6, 0x1a7",
1089 "SampleAfterValue": "100007",
1090 "BriefDescription": "Counts requests to the uncore subsystem have any transaction responses from the uncore subsystem.",
1091 "Offcore": "1"
1092 },
1093 {
1094 "CollectPEBSRecord": "1",
1095 "PublicDescription": "Counts requests to the uncore subsystem hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1096 "EventCode": "0xB7",
1097 "MSRValue": "0x0000048000",
1098 "Counter": "0,1,2,3",
1099 "UMask": "0x1",
1100 "PEBScounters": "0,1,2,3",
1101 "EventName": "OFFCORE_RESPONSE.ANY_REQUEST.L2_HIT",
1102 "PDIR_COUNTER": "na",
1103 "MSRIndex": "0x1a6, 0x1a7",
1104 "SampleAfterValue": "100007",
1105 "BriefDescription": "Counts requests to the uncore subsystem hit the L2 cache.",
1106 "Offcore": "1"
1107 },
1108 {
1109 "CollectPEBSRecord": "1",
1110 "PublicDescription": "Counts requests to the uncore subsystem true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1111 "EventCode": "0xB7",
1112 "MSRValue": "0x0200008000",
1113 "Counter": "0,1,2,3",
1114 "UMask": "0x1",
1115 "PEBScounters": "0,1,2,3",
1116 "EventName": "OFFCORE_RESPONSE.ANY_REQUEST.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
1117 "PDIR_COUNTER": "na",
1118 "MSRIndex": "0x1a6, 0x1a7",
1119 "SampleAfterValue": "100007",
1120 "BriefDescription": "Counts requests to the uncore subsystem true miss for the L2 cache with a snoop miss in the other processor module. ",
1121 "Offcore": "1"
1122 },
1123 {
1124 "CollectPEBSRecord": "1",
1125 "PublicDescription": "Counts requests to the uncore subsystem miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1126 "EventCode": "0xB7",
1127 "MSRValue": "0x1000008000",
1128 "Counter": "0,1,2,3",
1129 "UMask": "0x1",
1130 "PEBScounters": "0,1,2,3",
1131 "EventName": "OFFCORE_RESPONSE.ANY_REQUEST.L2_MISS.HITM_OTHER_CORE",
1132 "PDIR_COUNTER": "na",
1133 "MSRIndex": "0x1a6, 0x1a7",
1134 "SampleAfterValue": "100007",
1135 "BriefDescription": "Counts requests to the uncore subsystem miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
1136 "Offcore": "1"
1137 },
1138 {
1139 "CollectPEBSRecord": "1",
1140 "PublicDescription": "Counts requests to the uncore subsystem outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1141 "EventCode": "0xB7",
1142 "MSRValue": "0x4000008000",
1143 "Counter": "0,1,2,3",
1144 "UMask": "0x1",
1145 "PEBScounters": "0,1,2,3",
1146 "EventName": "OFFCORE_RESPONSE.ANY_REQUEST.OUTSTANDING",
1147 "PDIR_COUNTER": "na",
1148 "MSRIndex": "0x1a6",
1149 "SampleAfterValue": "100007",
1150 "BriefDescription": "Counts requests to the uncore subsystem outstanding, per cycle, from the time of the L2 miss to when any response is received.",
1151 "Offcore": "1"
1152 },
1153 {
1154 "CollectPEBSRecord": "1",
1155 "PublicDescription": "Counts data reads generated by L1 or L2 prefetchers have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1156 "EventCode": "0xB7",
1157 "MSRValue": "0x0000013010",
1158 "Counter": "0,1,2,3",
1159 "UMask": "0x1",
1160 "PEBScounters": "0,1,2,3",
1161 "EventName": "OFFCORE_RESPONSE.ANY_PF_DATA_RD.ANY_RESPONSE",
1162 "PDIR_COUNTER": "na",
1163 "MSRIndex": "0x1a6, 0x1a7",
1164 "SampleAfterValue": "100007",
1165 "BriefDescription": "Counts data reads generated by L1 or L2 prefetchers have any transaction responses from the uncore subsystem.",
1166 "Offcore": "1"
1167 },
1168 {
1169 "CollectPEBSRecord": "1",
1170 "PublicDescription": "Counts data reads generated by L1 or L2 prefetchers hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1171 "EventCode": "0xB7",
1172 "MSRValue": "0x0000043010",
1173 "Counter": "0,1,2,3",
1174 "UMask": "0x1",
1175 "PEBScounters": "0,1,2,3",
1176 "EventName": "OFFCORE_RESPONSE.ANY_PF_DATA_RD.L2_HIT",
1177 "PDIR_COUNTER": "na",
1178 "MSRIndex": "0x1a6, 0x1a7",
1179 "SampleAfterValue": "100007",
1180 "BriefDescription": "Counts data reads generated by L1 or L2 prefetchers hit the L2 cache.",
1181 "Offcore": "1"
1182 },
1183 {
1184 "CollectPEBSRecord": "1",
1185 "PublicDescription": "Counts data reads generated by L1 or L2 prefetchers true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1186 "EventCode": "0xB7",
1187 "MSRValue": "0x0200003010",
1188 "Counter": "0,1,2,3",
1189 "UMask": "0x1",
1190 "PEBScounters": "0,1,2,3",
1191 "EventName": "OFFCORE_RESPONSE.ANY_PF_DATA_RD.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
1192 "PDIR_COUNTER": "na",
1193 "MSRIndex": "0x1a6, 0x1a7",
1194 "SampleAfterValue": "100007",
1195 "BriefDescription": "Counts data reads generated by L1 or L2 prefetchers true miss for the L2 cache with a snoop miss in the other processor module. ",
1196 "Offcore": "1"
1197 },
1198 {
1199 "CollectPEBSRecord": "1",
1200 "PublicDescription": "Counts data reads generated by L1 or L2 prefetchers miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1201 "EventCode": "0xB7",
1202 "MSRValue": "0x1000003010",
1203 "Counter": "0,1,2,3",
1204 "UMask": "0x1",
1205 "PEBScounters": "0,1,2,3",
1206 "EventName": "OFFCORE_RESPONSE.ANY_PF_DATA_RD.L2_MISS.HITM_OTHER_CORE",
1207 "PDIR_COUNTER": "na",
1208 "MSRIndex": "0x1a6, 0x1a7",
1209 "SampleAfterValue": "100007",
1210 "BriefDescription": "Counts data reads generated by L1 or L2 prefetchers miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
1211 "Offcore": "1"
1212 },
1213 {
1214 "CollectPEBSRecord": "1",
1215 "PublicDescription": "Counts data reads generated by L1 or L2 prefetchers outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1216 "EventCode": "0xB7",
1217 "MSRValue": "0x4000003010",
1218 "Counter": "0,1,2,3",
1219 "UMask": "0x1",
1220 "PEBScounters": "0,1,2,3",
1221 "EventName": "OFFCORE_RESPONSE.ANY_PF_DATA_RD.OUTSTANDING",
1222 "PDIR_COUNTER": "na",
1223 "MSRIndex": "0x1a6",
1224 "SampleAfterValue": "100007",
1225 "BriefDescription": "Counts data reads generated by L1 or L2 prefetchers outstanding, per cycle, from the time of the L2 miss to when any response is received.",
1226 "Offcore": "1"
1227 },
1228 {
1229 "CollectPEBSRecord": "1",
1230 "PublicDescription": "Counts data reads (demand & prefetch) have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1231 "EventCode": "0xB7",
1232 "MSRValue": "0x0000013091",
1233 "Counter": "0,1,2,3",
1234 "UMask": "0x1",
1235 "PEBScounters": "0,1,2,3",
1236 "EventName": "OFFCORE_RESPONSE.ANY_DATA_RD.ANY_RESPONSE",
1237 "PDIR_COUNTER": "na",
1238 "MSRIndex": "0x1a6, 0x1a7",
1239 "SampleAfterValue": "100007",
1240 "BriefDescription": "Counts data reads (demand & prefetch) have any transaction responses from the uncore subsystem.",
1241 "Offcore": "1"
1242 },
1243 {
1244 "CollectPEBSRecord": "1",
1245 "PublicDescription": "Counts data reads (demand & prefetch) hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1246 "EventCode": "0xB7",
1247 "MSRValue": "0x0000043091",
1248 "Counter": "0,1,2,3",
1249 "UMask": "0x1",
1250 "PEBScounters": "0,1,2,3",
1251 "EventName": "OFFCORE_RESPONSE.ANY_DATA_RD.L2_HIT",
1252 "PDIR_COUNTER": "na",
1253 "MSRIndex": "0x1a6, 0x1a7",
1254 "SampleAfterValue": "100007",
1255 "BriefDescription": "Counts data reads (demand & prefetch) hit the L2 cache.",
1256 "Offcore": "1"
1257 },
1258 {
1259 "CollectPEBSRecord": "1",
1260 "PublicDescription": "Counts data reads (demand & prefetch) true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1261 "EventCode": "0xB7",
1262 "MSRValue": "0x0200003091",
1263 "Counter": "0,1,2,3",
1264 "UMask": "0x1",
1265 "PEBScounters": "0,1,2,3",
1266 "EventName": "OFFCORE_RESPONSE.ANY_DATA_RD.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
1267 "PDIR_COUNTER": "na",
1268 "MSRIndex": "0x1a6, 0x1a7",
1269 "SampleAfterValue": "100007",
1270 "BriefDescription": "Counts data reads (demand & prefetch) true miss for the L2 cache with a snoop miss in the other processor module. ",
1271 "Offcore": "1"
1272 },
1273 {
1274 "CollectPEBSRecord": "1",
1275 "PublicDescription": "Counts data reads (demand & prefetch) miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1276 "EventCode": "0xB7",
1277 "MSRValue": "0x1000003091",
1278 "Counter": "0,1,2,3",
1279 "UMask": "0x1",
1280 "PEBScounters": "0,1,2,3",
1281 "EventName": "OFFCORE_RESPONSE.ANY_DATA_RD.L2_MISS.HITM_OTHER_CORE",
1282 "PDIR_COUNTER": "na",
1283 "MSRIndex": "0x1a6, 0x1a7",
1284 "SampleAfterValue": "100007",
1285 "BriefDescription": "Counts data reads (demand & prefetch) miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
1286 "Offcore": "1"
1287 },
1288 {
1289 "CollectPEBSRecord": "1",
1290 "PublicDescription": "Counts data reads (demand & prefetch) outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1291 "EventCode": "0xB7",
1292 "MSRValue": "0x4000003091",
1293 "Counter": "0,1,2,3",
1294 "UMask": "0x1",
1295 "PEBScounters": "0,1,2,3",
1296 "EventName": "OFFCORE_RESPONSE.ANY_DATA_RD.OUTSTANDING",
1297 "PDIR_COUNTER": "na",
1298 "MSRIndex": "0x1a6",
1299 "SampleAfterValue": "100007",
1300 "BriefDescription": "Counts data reads (demand & prefetch) outstanding, per cycle, from the time of the L2 miss to when any response is received.",
1301 "Offcore": "1"
1302 },
1303 {
1304 "CollectPEBSRecord": "1",
1305 "PublicDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1306 "EventCode": "0xB7",
1307 "MSRValue": "0x0000010022",
1308 "Counter": "0,1,2,3",
1309 "UMask": "0x1",
1310 "PEBScounters": "0,1,2,3",
1311 "EventName": "OFFCORE_RESPONSE.ANY_RFO.ANY_RESPONSE",
1312 "PDIR_COUNTER": "na",
1313 "MSRIndex": "0x1a6, 0x1a7",
1314 "SampleAfterValue": "100007",
1315 "BriefDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) have any transaction responses from the uncore subsystem.",
1316 "Offcore": "1"
1317 },
1318 {
1319 "CollectPEBSRecord": "1",
1320 "PublicDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1321 "EventCode": "0xB7",
1322 "MSRValue": "0x0000040022",
1323 "Counter": "0,1,2,3",
1324 "UMask": "0x1",
1325 "PEBScounters": "0,1,2,3",
1326 "EventName": "OFFCORE_RESPONSE.ANY_RFO.L2_HIT",
1327 "PDIR_COUNTER": "na",
1328 "MSRIndex": "0x1a6, 0x1a7",
1329 "SampleAfterValue": "100007",
1330 "BriefDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) hit the L2 cache.",
1331 "Offcore": "1"
1332 },
1333 {
1334 "CollectPEBSRecord": "1",
1335 "PublicDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1336 "EventCode": "0xB7",
1337 "MSRValue": "0x0200000022",
1338 "Counter": "0,1,2,3",
1339 "UMask": "0x1",
1340 "PEBScounters": "0,1,2,3",
1341 "EventName": "OFFCORE_RESPONSE.ANY_RFO.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
1342 "PDIR_COUNTER": "na",
1343 "MSRIndex": "0x1a6, 0x1a7",
1344 "SampleAfterValue": "100007",
1345 "BriefDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) true miss for the L2 cache with a snoop miss in the other processor module. ",
1346 "Offcore": "1"
1347 },
1348 {
1349 "CollectPEBSRecord": "1",
1350 "PublicDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1351 "EventCode": "0xB7",
1352 "MSRValue": "0x1000000022",
1353 "Counter": "0,1,2,3",
1354 "UMask": "0x1",
1355 "PEBScounters": "0,1,2,3",
1356 "EventName": "OFFCORE_RESPONSE.ANY_RFO.L2_MISS.HITM_OTHER_CORE",
1357 "PDIR_COUNTER": "na",
1358 "MSRIndex": "0x1a6, 0x1a7",
1359 "SampleAfterValue": "100007",
1360 "BriefDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
1361 "Offcore": "1"
1362 },
1363 {
1364 "CollectPEBSRecord": "1",
1365 "PublicDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1366 "EventCode": "0xB7",
1367 "MSRValue": "0x4000000022",
1368 "Counter": "0,1,2,3",
1369 "UMask": "0x1",
1370 "PEBScounters": "0,1,2,3",
1371 "EventName": "OFFCORE_RESPONSE.ANY_RFO.OUTSTANDING",
1372 "PDIR_COUNTER": "na",
1373 "MSRIndex": "0x1a6",
1374 "SampleAfterValue": "100007",
1375 "BriefDescription": "Counts reads for ownership (RFO) requests (demand & prefetch) outstanding, per cycle, from the time of the L2 miss to when any response is received.",
1376 "Offcore": "1"
1377 },
1378 {
1379 "CollectPEBSRecord": "1",
1380 "PublicDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) have any transaction responses from the uncore subsystem. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1381 "EventCode": "0xB7",
1382 "MSRValue": "0x00000132b7",
1383 "Counter": "0,1,2,3",
1384 "UMask": "0x1",
1385 "PEBScounters": "0,1,2,3",
1386 "EventName": "OFFCORE_RESPONSE.ANY_READ.ANY_RESPONSE",
1387 "PDIR_COUNTER": "na",
1388 "MSRIndex": "0x1a6, 0x1a7",
1389 "SampleAfterValue": "100007",
1390 "BriefDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) have any transaction responses from the uncore subsystem.",
1391 "Offcore": "1"
1392 },
1393 {
1394 "CollectPEBSRecord": "1",
1395 "PublicDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) hit the L2 cache. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1396 "EventCode": "0xB7",
1397 "MSRValue": "0x00000432b7",
1398 "Counter": "0,1,2,3",
1399 "UMask": "0x1",
1400 "PEBScounters": "0,1,2,3",
1401 "EventName": "OFFCORE_RESPONSE.ANY_READ.L2_HIT",
1402 "PDIR_COUNTER": "na",
1403 "MSRIndex": "0x1a6, 0x1a7",
1404 "SampleAfterValue": "100007",
1405 "BriefDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) hit the L2 cache.",
1406 "Offcore": "1"
1407 },
1408 {
1409 "CollectPEBSRecord": "1",
1410 "PublicDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) true miss for the L2 cache with a snoop miss in the other processor module. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1411 "EventCode": "0xB7",
1412 "MSRValue": "0x02000032b7",
1413 "Counter": "0,1,2,3",
1414 "UMask": "0x1",
1415 "PEBScounters": "0,1,2,3",
1416 "EventName": "OFFCORE_RESPONSE.ANY_READ.L2_MISS.SNOOP_MISS_OR_NO_SNOOP_NEEDED",
1417 "PDIR_COUNTER": "na",
1418 "MSRIndex": "0x1a6, 0x1a7",
1419 "SampleAfterValue": "100007",
1420 "BriefDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) true miss for the L2 cache with a snoop miss in the other processor module. ",
1421 "Offcore": "1"
1422 },
1423 {
1424 "CollectPEBSRecord": "1",
1425 "PublicDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) miss the L2 cache with a snoop hit in the other processor module, data forwarding is required. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1426 "EventCode": "0xB7",
1427 "MSRValue": "0x10000032b7",
1428 "Counter": "0,1,2,3",
1429 "UMask": "0x1",
1430 "PEBScounters": "0,1,2,3",
1431 "EventName": "OFFCORE_RESPONSE.ANY_READ.L2_MISS.HITM_OTHER_CORE",
1432 "PDIR_COUNTER": "na",
1433 "MSRIndex": "0x1a6, 0x1a7",
1434 "SampleAfterValue": "100007",
1435 "BriefDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) miss the L2 cache with a snoop hit in the other processor module, data forwarding is required.",
1436 "Offcore": "1"
1437 },
1438 {
1439 "CollectPEBSRecord": "1",
1440 "PublicDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) outstanding, per cycle, from the time of the L2 miss to when any response is received. Requires MSR_OFFCORE_RESP[0,1] to specify request type and response. (duplicated for both MSRs)",
1441 "EventCode": "0xB7",
1442 "MSRValue": "0x40000032b7",
1443 "Counter": "0,1,2,3",
1444 "UMask": "0x1",
1445 "PEBScounters": "0,1,2,3",
1446 "EventName": "OFFCORE_RESPONSE.ANY_READ.OUTSTANDING",
1447 "PDIR_COUNTER": "na",
1448 "MSRIndex": "0x1a6",
1449 "SampleAfterValue": "100007",
1450 "BriefDescription": "Counts data read, code read, and read for ownership (RFO) requests (demand & prefetch) outstanding, per cycle, from the time of the L2 miss to when any response is received.",
1451 "Offcore": "1"
1452 }
1453] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/goldmontplus/frontend.json b/tools/perf/pmu-events/arch/x86/goldmontplus/frontend.json
new file mode 100644
index 000000000000..a7878965ceab
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/goldmontplus/frontend.json
@@ -0,0 +1,62 @@
1[
2 {
3 "CollectPEBSRecord": "1",
4 "PublicDescription": "Counts requests to the Instruction Cache (ICache) for one or more bytes in an ICache Line and that cache line is in the ICache (hit). The event strives to count on a cache line basis, so that multiple accesses which hit in a single cache line count as one ICACHE.HIT. Specifically, the event counts when straight line code crosses the cache line boundary, or when a branch target is to a new line, and that cache line is in the ICache. This event counts differently than Intel processors based on Silvermont microarchitecture.",
5 "EventCode": "0x80",
6 "Counter": "0,1,2,3",
7 "UMask": "0x1",
8 "PEBScounters": "0,1,2,3",
9 "EventName": "ICACHE.HIT",
10 "PDIR_COUNTER": "na",
11 "SampleAfterValue": "200003",
12 "BriefDescription": "References per ICache line that are available in the ICache (hit). This event counts differently than Intel processors based on Silvermont microarchitecture"
13 },
14 {
15 "CollectPEBSRecord": "1",
16 "PublicDescription": "Counts requests to the Instruction Cache (ICache) for one or more bytes in an ICache Line and that cache line is not in the ICache (miss). The event strives to count on a cache line basis, so that multiple accesses which miss in a single cache line count as one ICACHE.MISS. Specifically, the event counts when straight line code crosses the cache line boundary, or when a branch target is to a new line, and that cache line is not in the ICache. This event counts differently than Intel processors based on Silvermont microarchitecture.",
17 "EventCode": "0x80",
18 "Counter": "0,1,2,3",
19 "UMask": "0x2",
20 "PEBScounters": "0,1,2,3",
21 "EventName": "ICACHE.MISSES",
22 "PDIR_COUNTER": "na",
23 "SampleAfterValue": "200003",
24 "BriefDescription": "References per ICache line that are not available in the ICache (miss). This event counts differently than Intel processors based on Silvermont microarchitecture"
25 },
26 {
27 "CollectPEBSRecord": "1",
28 "PublicDescription": "Counts requests to the Instruction Cache (ICache) for one or more bytes in an ICache Line. The event strives to count on a cache line basis, so that multiple fetches to a single cache line count as one ICACHE.ACCESS. Specifically, the event counts when accesses from straight line code crosses the cache line boundary, or when a branch target is to a new line.\r\nThis event counts differently than Intel processors based on Silvermont microarchitecture.",
29 "EventCode": "0x80",
30 "Counter": "0,1,2,3",
31 "UMask": "0x3",
32 "PEBScounters": "0,1,2,3",
33 "EventName": "ICACHE.ACCESSES",
34 "PDIR_COUNTER": "na",
35 "SampleAfterValue": "200003",
36 "BriefDescription": "References per ICache line. This event counts differently than Intel processors based on Silvermont microarchitecture"
37 },
38 {
39 "CollectPEBSRecord": "1",
40 "PublicDescription": "Counts the number of times the Microcode Sequencer (MS) starts a flow of uops from the MSROM. It does not count every time a uop is read from the MSROM. The most common case that this counts is when a micro-coded instruction is encountered by the front end of the machine. Other cases include when an instruction encounters a fault, trap, or microcode assist of any sort that initiates a flow of uops. The event will count MS startups for uops that are speculative, and subsequently cleared by branch mispredict or a machine clear.",
41 "EventCode": "0xE7",
42 "Counter": "0,1,2,3",
43 "UMask": "0x1",
44 "PEBScounters": "0,1,2,3",
45 "EventName": "MS_DECODED.MS_ENTRY",
46 "PDIR_COUNTER": "na",
47 "SampleAfterValue": "200003",
48 "BriefDescription": "MS decode starts"
49 },
50 {
51 "CollectPEBSRecord": "1",
52 "PublicDescription": "Counts the number of times the prediction (from the predecode cache) for instruction length is incorrect.",
53 "EventCode": "0xE9",
54 "Counter": "0,1,2,3",
55 "UMask": "0x1",
56 "PEBScounters": "0,1,2,3",
57 "EventName": "DECODE_RESTRICTION.PREDECODE_WRONG",
58 "PDIR_COUNTER": "na",
59 "SampleAfterValue": "200003",
60 "BriefDescription": "Decode restrictions due to predicting wrong instruction length"
61 }
62] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/goldmontplus/memory.json b/tools/perf/pmu-events/arch/x86/goldmontplus/memory.json
new file mode 100644
index 000000000000..91e0815f3ffb
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/goldmontplus/memory.json
@@ -0,0 +1,38 @@
1[
2 {
3 "PEBS": "2",
4 "CollectPEBSRecord": "2",
5 "PublicDescription": "Counts when a memory load of a uop spans a page boundary (a split) is retired.",
6 "EventCode": "0x13",
7 "Counter": "0,1,2,3",
8 "UMask": "0x2",
9 "PEBScounters": "0,1,2,3",
10 "EventName": "MISALIGN_MEM_REF.LOAD_PAGE_SPLIT",
11 "SampleAfterValue": "200003",
12 "BriefDescription": "Load uops that split a page (Precise event capable)"
13 },
14 {
15 "PEBS": "2",
16 "CollectPEBSRecord": "2",
17 "PublicDescription": "Counts when a memory store of a uop spans a page boundary (a split) is retired.",
18 "EventCode": "0x13",
19 "Counter": "0,1,2,3",
20 "UMask": "0x4",
21 "PEBScounters": "0,1,2,3",
22 "EventName": "MISALIGN_MEM_REF.STORE_PAGE_SPLIT",
23 "SampleAfterValue": "200003",
24 "BriefDescription": "Store uops that split a page (Precise event capable)"
25 },
26 {
27 "CollectPEBSRecord": "1",
28 "PublicDescription": "Counts machine clears due to memory ordering issues. This occurs when a snoop request happens and the machine is uncertain if memory ordering will be preserved - as another core is in the process of modifying the data.",
29 "EventCode": "0xC3",
30 "Counter": "0,1,2,3",
31 "UMask": "0x2",
32 "PEBScounters": "0,1,2,3",
33 "EventName": "MACHINE_CLEARS.MEMORY_ORDERING",
34 "PDIR_COUNTER": "na",
35 "SampleAfterValue": "20003",
36 "BriefDescription": "Machine clears due to memory ordering issue"
37 }
38] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/goldmontplus/other.json b/tools/perf/pmu-events/arch/x86/goldmontplus/other.json
new file mode 100644
index 000000000000..b860374418ab
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/goldmontplus/other.json
@@ -0,0 +1,98 @@
1[
2 {
3 "CollectPEBSRecord": "1",
4 "PublicDescription": "Counts cycles that fetch is stalled due to any reason. That is, the decoder queue is able to accept bytes, but the fetch unit is unable to provide bytes. This will include cycles due to an ITLB miss, ICache miss and other events.",
5 "EventCode": "0x86",
6 "Counter": "0,1,2,3",
7 "UMask": "0x0",
8 "PEBScounters": "0,1,2,3",
9 "EventName": "FETCH_STALL.ALL",
10 "PDIR_COUNTER": "na",
11 "SampleAfterValue": "200003",
12 "BriefDescription": "Cycles code-fetch stalled due to any reason."
13 },
14 {
15 "CollectPEBSRecord": "1",
16 "PublicDescription": "Counts cycles that fetch is stalled due to an outstanding ITLB miss. That is, the decoder queue is able to accept bytes, but the fetch unit is unable to provide bytes due to an ITLB miss. Note: this event is not the same as page walk cycles to retrieve an instruction translation.",
17 "EventCode": "0x86",
18 "Counter": "0,1,2,3",
19 "UMask": "0x1",
20 "PEBScounters": "0,1,2,3",
21 "EventName": "FETCH_STALL.ITLB_FILL_PENDING_CYCLES",
22 "PDIR_COUNTER": "na",
23 "SampleAfterValue": "200003",
24 "BriefDescription": "Cycles the code-fetch stalls and an ITLB miss is outstanding."
25 },
26 {
27 "CollectPEBSRecord": "1",
28 "PublicDescription": "Counts the number of issue slots per core cycle that were not consumed by the backend due to either a full resource in the backend (RESOURCE_FULL) or due to the processor recovering from some event (RECOVERY).",
29 "EventCode": "0xCA",
30 "Counter": "0,1,2,3",
31 "UMask": "0x0",
32 "PEBScounters": "0,1,2,3",
33 "EventName": "ISSUE_SLOTS_NOT_CONSUMED.ANY",
34 "PDIR_COUNTER": "na",
35 "SampleAfterValue": "200003",
36 "BriefDescription": "Unfilled issue slots per cycle"
37 },
38 {
39 "CollectPEBSRecord": "1",
40 "PublicDescription": "Counts the number of issue slots per core cycle that were not consumed because of a full resource in the backend. Including but not limited to resources such as the Re-order Buffer (ROB), reservation stations (RS), load/store buffers, physical registers, or any other needed machine resource that is currently unavailable. Note that uops must be available for consumption in order for this event to fire. If a uop is not available (Instruction Queue is empty), this event will not count.",
41 "EventCode": "0xCA",
42 "Counter": "0,1,2,3",
43 "UMask": "0x1",
44 "PEBScounters": "0,1,2,3",
45 "EventName": "ISSUE_SLOTS_NOT_CONSUMED.RESOURCE_FULL",
46 "PDIR_COUNTER": "na",
47 "SampleAfterValue": "200003",
48 "BriefDescription": "Unfilled issue slots per cycle because of a full resource in the backend"
49 },
50 {
51 "CollectPEBSRecord": "1",
52 "PublicDescription": "Counts the number of issue slots per core cycle that were not consumed by the backend because allocation is stalled waiting for a mispredicted jump to retire or other branch-like conditions (e.g. the event is relevant during certain microcode flows). Counts all issue slots blocked while within this window including slots where uops were not available in the Instruction Queue.",
53 "EventCode": "0xCA",
54 "Counter": "0,1,2,3",
55 "UMask": "0x2",
56 "PEBScounters": "0,1,2,3",
57 "EventName": "ISSUE_SLOTS_NOT_CONSUMED.RECOVERY",
58 "PDIR_COUNTER": "na",
59 "SampleAfterValue": "200003",
60 "BriefDescription": "Unfilled issue slots per cycle to recover"
61 },
62 {
63 "CollectPEBSRecord": "2",
64 "PublicDescription": "Counts hardware interrupts received by the processor.",
65 "EventCode": "0xCB",
66 "Counter": "0,1,2,3",
67 "UMask": "0x1",
68 "PEBScounters": "0,1,2,3",
69 "EventName": "HW_INTERRUPTS.RECEIVED",
70 "PDIR_COUNTER": "na",
71 "SampleAfterValue": "203",
72 "BriefDescription": "Hardware interrupts received"
73 },
74 {
75 "CollectPEBSRecord": "2",
76 "PublicDescription": "Counts the number of core cycles during which interrupts are masked (disabled). Increments by 1 each core cycle that EFLAGS.IF is 0, regardless of whether interrupts are pending or not.",
77 "EventCode": "0xCB",
78 "Counter": "0,1,2,3",
79 "UMask": "0x2",
80 "PEBScounters": "0,1,2,3",
81 "EventName": "HW_INTERRUPTS.MASKED",
82 "PDIR_COUNTER": "na",
83 "SampleAfterValue": "200003",
84 "BriefDescription": "Cycles hardware interrupts are masked"
85 },
86 {
87 "CollectPEBSRecord": "2",
88 "PublicDescription": "Counts core cycles during which there are pending interrupts, but interrupts are masked (EFLAGS.IF = 0).",
89 "EventCode": "0xCB",
90 "Counter": "0,1,2,3",
91 "UMask": "0x4",
92 "PEBScounters": "0,1,2,3",
93 "EventName": "HW_INTERRUPTS.PENDING_AND_MASKED",
94 "PDIR_COUNTER": "na",
95 "SampleAfterValue": "200003",
96 "BriefDescription": "Cycles pending interrupts are masked"
97 }
98] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/goldmontplus/pipeline.json b/tools/perf/pmu-events/arch/x86/goldmontplus/pipeline.json
new file mode 100644
index 000000000000..ccf1aed69197
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/goldmontplus/pipeline.json
@@ -0,0 +1,544 @@
1[
2 {
3 "PEBS": "2",
4 "CollectPEBSRecord": "1",
5 "PublicDescription": "Counts the number of instructions that retire execution. For instructions that consist of multiple uops, this event counts the retirement of the last uop of the instruction. The counter continues counting during hardware interrupts, traps, and inside interrupt handlers. This event uses fixed counter 0. You cannot collect a PEBs record for this event.",
6 "EventCode": "0x00",
7 "Counter": "Fixed counter 0",
8 "UMask": "0x1",
9 "PEBScounters": "32",
10 "EventName": "INST_RETIRED.ANY",
11 "PDIR_COUNTER": "na",
12 "SampleAfterValue": "2000003",
13 "BriefDescription": "Instructions retired (Fixed event)"
14 },
15 {
16 "CollectPEBSRecord": "1",
17 "PublicDescription": "Counts the number of core cycles while the core is not in a halt state. The core enters the halt state when it is running the HLT instruction. In mobile systems the core frequency may change from time to time. For this reason this event may have a changing ratio with regards to time. This event uses fixed counter 1. You cannot collect a PEBs record for this event.",
18 "EventCode": "0x00",
19 "Counter": "Fixed counter 1",
20 "UMask": "0x2",
21 "PEBScounters": "33",
22 "EventName": "CPU_CLK_UNHALTED.CORE",
23 "PDIR_COUNTER": "na",
24 "SampleAfterValue": "2000003",
25 "BriefDescription": "Core cycles when core is not halted (Fixed event)"
26 },
27 {
28 "CollectPEBSRecord": "1",
29 "PublicDescription": "Counts the number of reference cycles that the core is not in a halt state. The core enters the halt state when it is running the HLT instruction. In mobile systems the core frequency may change from time. This event is not affected by core frequency changes but counts as if the core is running at the maximum frequency all the time. This event uses fixed counter 2. You cannot collect a PEBs record for this event.",
30 "EventCode": "0x00",
31 "Counter": "Fixed counter 2",
32 "UMask": "0x3",
33 "PEBScounters": "34",
34 "EventName": "CPU_CLK_UNHALTED.REF_TSC",
35 "PDIR_COUNTER": "na",
36 "SampleAfterValue": "2000003",
37 "BriefDescription": "Reference cycles when core is not halted (Fixed event)"
38 },
39 {
40 "PEBS": "2",
41 "CollectPEBSRecord": "2",
42 "PublicDescription": "Counts a load blocked from using a store forward, but did not occur because the store data was not available at the right time. The forward might occur subsequently when the data is available.",
43 "EventCode": "0x03",
44 "Counter": "0,1,2,3",
45 "UMask": "0x1",
46 "PEBScounters": "0,1,2,3",
47 "EventName": "LD_BLOCKS.DATA_UNKNOWN",
48 "SampleAfterValue": "200003",
49 "BriefDescription": "Loads blocked due to store data not ready (Precise event capable)"
50 },
51 {
52 "PEBS": "2",
53 "CollectPEBSRecord": "2",
54 "PublicDescription": "Counts a load blocked from using a store forward because of an address/size mismatch, only one of the loads blocked from each store will be counted.",
55 "EventCode": "0x03",
56 "Counter": "0,1,2,3",
57 "UMask": "0x2",
58 "PEBScounters": "0,1,2,3",
59 "EventName": "LD_BLOCKS.STORE_FORWARD",
60 "SampleAfterValue": "200003",
61 "BriefDescription": "Loads blocked due to store forward restriction (Precise event capable)"
62 },
63 {
64 "PEBS": "2",
65 "CollectPEBSRecord": "2",
66 "PublicDescription": "Counts loads that block because their address modulo 4K matches a pending store.",
67 "EventCode": "0x03",
68 "Counter": "0,1,2,3",
69 "UMask": "0x4",
70 "PEBScounters": "0,1,2,3",
71 "EventName": "LD_BLOCKS.4K_ALIAS",
72 "SampleAfterValue": "200003",
73 "BriefDescription": "Loads blocked because address has 4k partial address false dependence (Precise event capable)"
74 },
75 {
76 "PEBS": "2",
77 "CollectPEBSRecord": "2",
78 "PublicDescription": "Counts loads blocked because they are unable to find their physical address in the micro TLB (UTLB).",
79 "EventCode": "0x03",
80 "Counter": "0,1,2,3",
81 "UMask": "0x8",
82 "PEBScounters": "0,1,2,3",
83 "EventName": "LD_BLOCKS.UTLB_MISS",
84 "SampleAfterValue": "200003",
85 "BriefDescription": "Loads blocked because address in not in the UTLB (Precise event capable)"
86 },
87 {
88 "PEBS": "2",
89 "CollectPEBSRecord": "2",
90 "PublicDescription": "Counts anytime a load that retires is blocked for any reason.",
91 "EventCode": "0x03",
92 "Counter": "0,1,2,3",
93 "UMask": "0x10",
94 "PEBScounters": "0,1,2,3",
95 "EventName": "LD_BLOCKS.ALL_BLOCK",
96 "SampleAfterValue": "200003",
97 "BriefDescription": "Loads blocked (Precise event capable)"
98 },
99 {
100 "CollectPEBSRecord": "1",
101 "PublicDescription": "Counts uops issued by the front end and allocated into the back end of the machine. This event counts uops that retire as well as uops that were speculatively executed but didn't retire. The sort of speculative uops that might be counted includes, but is not limited to those uops issued in the shadow of a miss-predicted branch, those uops that are inserted during an assist (such as for a denormal floating point result), and (previously allocated) uops that might be canceled during a machine clear.",
102 "EventCode": "0x0E",
103 "Counter": "0,1,2,3",
104 "UMask": "0x0",
105 "PEBScounters": "0,1,2,3",
106 "EventName": "UOPS_ISSUED.ANY",
107 "PDIR_COUNTER": "na",
108 "SampleAfterValue": "200003",
109 "BriefDescription": "Uops issued to the back end per cycle"
110 },
111 {
112 "CollectPEBSRecord": "1",
113 "PublicDescription": "Core cycles when core is not halted. This event uses a (_P)rogrammable general purpose performance counter.",
114 "EventCode": "0x3C",
115 "Counter": "0,1,2,3",
116 "UMask": "0x0",
117 "PEBScounters": "0,1,2,3",
118 "EventName": "CPU_CLK_UNHALTED.CORE_P",
119 "PDIR_COUNTER": "na",
120 "SampleAfterValue": "2000003",
121 "BriefDescription": "Core cycles when core is not halted"
122 },
123 {
124 "CollectPEBSRecord": "1",
125 "PublicDescription": "Reference cycles when core is not halted. This event uses a (_P)rogrammable general purpose performance counter.",
126 "EventCode": "0x3C",
127 "Counter": "0,1,2,3",
128 "UMask": "0x1",
129 "PEBScounters": "0,1,2,3",
130 "EventName": "CPU_CLK_UNHALTED.REF",
131 "PDIR_COUNTER": "na",
132 "SampleAfterValue": "2000003",
133 "BriefDescription": "Reference cycles when core is not halted"
134 },
135 {
136 "CollectPEBSRecord": "1",
137 "PublicDescription": "This event used to measure front-end inefficiencies. I.e. when front-end of the machine is not delivering uops to the back-end and the back-end has is not stalled. This event can be used to identify if the machine is truly front-end bound. When this event occurs, it is an indication that the front-end of the machine is operating at less than its theoretical peak performance. Background: We can think of the processor pipeline as being divided into 2 broader parts: Front-end and Back-end. Front-end is responsible for fetching the instruction, decoding into uops in machine understandable format and putting them into a uop queue to be consumed by back end. The back-end then takes these uops, allocates the required resources. When all resources are ready, uops are executed. If the back-end is not ready to accept uops from the front-end, then we do not want to count these as front-end bottlenecks. However, whenever we have bottlenecks in the back-end, we will have allocation unit stalls and eventually forcing the front-end to wait until the back-end is ready to receive more uops. This event counts only when back-end is requesting more uops and front-end is not able to provide them. When 3 uops are requested and no uops are delivered, the event counts 3. When 3 are requested, and only 1 is delivered, the event counts 2. When only 2 are delivered, the event counts 1. Alternatively stated, the event will not count if 3 uops are delivered, or if the back end is stalled and not requesting any uops at all. Counts indicate missed opportunities for the front-end to deliver a uop to the back end. Some examples of conditions that cause front-end efficiencies are: ICache misses, ITLB misses, and decoder restrictions that limit the front-end bandwidth. Known Issues: Some uops require multiple allocation slots. These uops will not be charged as a front end 'not delivered' opportunity, and will be regarded as a back end problem. For example, the INC instruction has one uop that requires 2 issue slots. A stream of INC instructions will not count as UOPS_NOT_DELIVERED, even though only one instruction can be issued per clock. The low uop issue rate for a stream of INC instructions is considered to be a back end issue.",
138 "EventCode": "0x9C",
139 "Counter": "0,1,2,3",
140 "UMask": "0x0",
141 "PEBScounters": "0,1,2,3",
142 "EventName": "UOPS_NOT_DELIVERED.ANY",
143 "PDIR_COUNTER": "na",
144 "SampleAfterValue": "200003",
145 "BriefDescription": "Uops requested but not-delivered to the back-end per cycle"
146 },
147 {
148 "PEBS": "2",
149 "CollectPEBSRecord": "1",
150 "PublicDescription": "Counts the number of instructions that retire execution. For instructions that consist of multiple uops, this event counts the retirement of the last uop of the instruction. The event continues counting during hardware interrupts, traps, and inside interrupt handlers. This is an architectural performance event. This event uses a (_P)rogrammable general purpose performance counter. *This event is Precise Event capable: The EventingRIP field in the PEBS record is precise to the address of the instruction which caused the event. Note: Because PEBS records can be collected only on IA32_PMC0, only one event can use the PEBS facility at a time.",
151 "EventCode": "0xC0",
152 "Counter": "0,1,2,3",
153 "UMask": "0x0",
154 "PEBScounters": "0,1,2,3",
155 "EventName": "INST_RETIRED.ANY_P",
156 "SampleAfterValue": "2000003",
157 "BriefDescription": "Instructions retired (Precise event capable)"
158 },
159 {
160 "PEBS": "2",
161 "CollectPEBSRecord": "2",
162 "PublicDescription": "Counts INST_RETIRED.ANY using the Reduced Skid PEBS feature that reduces the shadow in which events aren't counted allowing for a more unbiased distribution of samples across instructions retired.",
163 "EventCode": "0xC0",
164 "Counter": "0,1,2,3",
165 "UMask": "0x0",
166 "EventName": "INST_RETIRED.PREC_DIST",
167 "SampleAfterValue": "2000003",
168 "BriefDescription": "Instructions retired - using Reduced Skid PEBS feature"
169 },
170 {
171 "PEBS": "2",
172 "CollectPEBSRecord": "2",
173 "PublicDescription": "Counts uops which retired.",
174 "EventCode": "0xC2",
175 "Counter": "0,1,2,3",
176 "UMask": "0x0",
177 "PEBScounters": "0,1,2,3",
178 "EventName": "UOPS_RETIRED.ANY",
179 "PDIR_COUNTER": "na",
180 "SampleAfterValue": "2000003",
181 "BriefDescription": "Uops retired (Precise event capable)"
182 },
183 {
184 "PEBS": "2",
185 "CollectPEBSRecord": "2",
186 "PublicDescription": "Counts uops retired that are from the complex flows issued by the micro-sequencer (MS). Counts both the uops from a micro-coded instruction, and the uops that might be generated from a micro-coded assist.",
187 "EventCode": "0xC2",
188 "Counter": "0,1,2,3",
189 "UMask": "0x1",
190 "PEBScounters": "0,1,2,3",
191 "EventName": "UOPS_RETIRED.MS",
192 "PDIR_COUNTER": "na",
193 "SampleAfterValue": "2000003",
194 "BriefDescription": "MS uops retired (Precise event capable)"
195 },
196 {
197 "PEBS": "2",
198 "CollectPEBSRecord": "1",
199 "PublicDescription": "Counts the number of floating point divide uops retired.",
200 "EventCode": "0xC2",
201 "Counter": "0,1,2,3",
202 "UMask": "0x8",
203 "PEBScounters": "0,1,2,3",
204 "EventName": "UOPS_RETIRED.FPDIV",
205 "SampleAfterValue": "2000003",
206 "BriefDescription": "Floating point divide uops retired (Precise Event Capable)"
207 },
208 {
209 "PEBS": "2",
210 "CollectPEBSRecord": "1",
211 "PublicDescription": "Counts the number of integer divide uops retired.",
212 "EventCode": "0xC2",
213 "Counter": "0,1,2,3",
214 "UMask": "0x10",
215 "PEBScounters": "0,1,2,3",
216 "EventName": "UOPS_RETIRED.IDIV",
217 "SampleAfterValue": "2000003",
218 "BriefDescription": "Integer divide uops retired (Precise Event Capable)"
219 },
220 {
221 "CollectPEBSRecord": "1",
222 "PublicDescription": "Counts machine clears for any reason.",
223 "EventCode": "0xC3",
224 "Counter": "0,1,2,3",
225 "UMask": "0x0",
226 "PEBScounters": "0,1,2,3",
227 "EventName": "MACHINE_CLEARS.ALL",
228 "PDIR_COUNTER": "na",
229 "SampleAfterValue": "20003",
230 "BriefDescription": "All machine clears"
231 },
232 {
233 "CollectPEBSRecord": "1",
234 "PublicDescription": "Counts the number of times that the processor detects that a program is writing to a code section and has to perform a machine clear because of that modification. Self-modifying code (SMC) causes a severe penalty in all Intel architecture processors.",
235 "EventCode": "0xC3",
236 "Counter": "0,1,2,3",
237 "UMask": "0x1",
238 "PEBScounters": "0,1,2,3",
239 "EventName": "MACHINE_CLEARS.SMC",
240 "PDIR_COUNTER": "na",
241 "SampleAfterValue": "20003",
242 "BriefDescription": "Self-Modifying Code detected"
243 },
244 {
245 "CollectPEBSRecord": "1",
246 "PublicDescription": "Counts machine clears due to floating point (FP) operations needing assists. For instance, if the result was a floating point denormal, the hardware clears the pipeline and reissues uops to produce the correct IEEE compliant denormal result.",
247 "EventCode": "0xC3",
248 "Counter": "0,1,2,3",
249 "UMask": "0x4",
250 "PEBScounters": "0,1,2,3",
251 "EventName": "MACHINE_CLEARS.FP_ASSIST",
252 "PDIR_COUNTER": "na",
253 "SampleAfterValue": "20003",
254 "BriefDescription": "Machine clears due to FP assists"
255 },
256 {
257 "CollectPEBSRecord": "1",
258 "PublicDescription": "Counts machine clears due to memory disambiguation. Memory disambiguation happens when a load which has been issued conflicts with a previous unretired store in the pipeline whose address was not known at issue time, but is later resolved to be the same as the load address.",
259 "EventCode": "0xC3",
260 "Counter": "0,1,2,3",
261 "UMask": "0x8",
262 "PEBScounters": "0,1,2,3",
263 "EventName": "MACHINE_CLEARS.DISAMBIGUATION",
264 "PDIR_COUNTER": "na",
265 "SampleAfterValue": "20003",
266 "BriefDescription": "Machine clears due to memory disambiguation"
267 },
268 {
269 "CollectPEBSRecord": "1",
270 "PublicDescription": "Counts the number of times that the machines clears due to a page fault. Covers both I-side and D-side(Loads/Stores) page faults. A page fault occurs when either page is not present, or an access violation",
271 "EventCode": "0xC3",
272 "Counter": "0,1,2,3",
273 "UMask": "0x20",
274 "PEBScounters": "0,1,2,3",
275 "EventName": "MACHINE_CLEARS.PAGE_FAULT",
276 "PDIR_COUNTER": "na",
277 "SampleAfterValue": "20003",
278 "BriefDescription": "Machines clear due to a page fault"
279 },
280 {
281 "PEBS": "2",
282 "CollectPEBSRecord": "2",
283 "PublicDescription": "Counts branch instructions retired for all branch types. This is an architectural performance event.",
284 "EventCode": "0xC4",
285 "Counter": "0,1,2,3",
286 "UMask": "0x0",
287 "PEBScounters": "0,1,2,3",
288 "EventName": "BR_INST_RETIRED.ALL_BRANCHES",
289 "SampleAfterValue": "200003",
290 "BriefDescription": "Retired branch instructions (Precise event capable)"
291 },
292 {
293 "PEBS": "2",
294 "CollectPEBSRecord": "2",
295 "PublicDescription": "Counts retired Jcc (Jump on Conditional Code/Jump if Condition is Met) branch instructions retired, including both when the branch was taken and when it was not taken.",
296 "EventCode": "0xC4",
297 "Counter": "0,1,2,3",
298 "UMask": "0x7e",
299 "PEBScounters": "0,1,2,3",
300 "EventName": "BR_INST_RETIRED.JCC",
301 "SampleAfterValue": "200003",
302 "BriefDescription": "Retired conditional branch instructions (Precise event capable)"
303 },
304 {
305 "PEBS": "2",
306 "CollectPEBSRecord": "2",
307 "PublicDescription": "Counts the number of taken branch instructions retired.",
308 "EventCode": "0xC4",
309 "Counter": "0,1,2,3",
310 "UMask": "0x80",
311 "PEBScounters": "0,1,2,3",
312 "EventName": "BR_INST_RETIRED.ALL_TAKEN_BRANCHES",
313 "SampleAfterValue": "200003",
314 "BriefDescription": "Retired taken branch instructions (Precise event capable)"
315 },
316 {
317 "PEBS": "2",
318 "CollectPEBSRecord": "2",
319 "PublicDescription": "Counts far branch instructions retired. This includes far jump, far call and return, and Interrupt call and return.",
320 "EventCode": "0xC4",
321 "Counter": "0,1,2,3",
322 "UMask": "0xbf",
323 "PEBScounters": "0,1,2,3",
324 "EventName": "BR_INST_RETIRED.FAR_BRANCH",
325 "SampleAfterValue": "200003",
326 "BriefDescription": "Retired far branch instructions (Precise event capable)"
327 },
328 {
329 "PEBS": "2",
330 "CollectPEBSRecord": "2",
331 "PublicDescription": "Counts near indirect call or near indirect jmp branch instructions retired.",
332 "EventCode": "0xC4",
333 "Counter": "0,1,2,3",
334 "UMask": "0xeb",
335 "PEBScounters": "0,1,2,3",
336 "EventName": "BR_INST_RETIRED.NON_RETURN_IND",
337 "SampleAfterValue": "200003",
338 "BriefDescription": "Retired instructions of near indirect Jmp or call (Precise event capable)"
339 },
340 {
341 "PEBS": "2",
342 "CollectPEBSRecord": "2",
343 "PublicDescription": "Counts near return branch instructions retired.",
344 "EventCode": "0xC4",
345 "Counter": "0,1,2,3",
346 "UMask": "0xf7",
347 "PEBScounters": "0,1,2,3",
348 "EventName": "BR_INST_RETIRED.RETURN",
349 "SampleAfterValue": "200003",
350 "BriefDescription": "Retired near return instructions (Precise event capable)"
351 },
352 {
353 "PEBS": "2",
354 "CollectPEBSRecord": "2",
355 "PublicDescription": "Counts near CALL branch instructions retired.",
356 "EventCode": "0xC4",
357 "Counter": "0,1,2,3",
358 "UMask": "0xf9",
359 "PEBScounters": "0,1,2,3",
360 "EventName": "BR_INST_RETIRED.CALL",
361 "SampleAfterValue": "200003",
362 "BriefDescription": "Retired near call instructions (Precise event capable)"
363 },
364 {
365 "PEBS": "2",
366 "CollectPEBSRecord": "2",
367 "PublicDescription": "Counts near indirect CALL branch instructions retired.",
368 "EventCode": "0xC4",
369 "Counter": "0,1,2,3",
370 "UMask": "0xfb",
371 "PEBScounters": "0,1,2,3",
372 "EventName": "BR_INST_RETIRED.IND_CALL",
373 "SampleAfterValue": "200003",
374 "BriefDescription": "Retired near indirect call instructions (Precise event capable)"
375 },
376 {
377 "PEBS": "2",
378 "CollectPEBSRecord": "2",
379 "PublicDescription": "Counts near relative CALL branch instructions retired.",
380 "EventCode": "0xC4",
381 "Counter": "0,1,2,3",
382 "UMask": "0xfd",
383 "PEBScounters": "0,1,2,3",
384 "EventName": "BR_INST_RETIRED.REL_CALL",
385 "SampleAfterValue": "200003",
386 "BriefDescription": "Retired near relative call instructions (Precise event capable)"
387 },
388 {
389 "PEBS": "2",
390 "CollectPEBSRecord": "2",
391 "PublicDescription": "Counts Jcc (Jump on Conditional Code/Jump if Condition is Met) branch instructions retired that were taken and does not count when the Jcc branch instruction were not taken.",
392 "EventCode": "0xC4",
393 "Counter": "0,1,2,3",
394 "UMask": "0xfe",
395 "PEBScounters": "0,1,2,3",
396 "EventName": "BR_INST_RETIRED.TAKEN_JCC",
397 "SampleAfterValue": "200003",
398 "BriefDescription": "Retired conditional branch instructions that were taken (Precise event capable)"
399 },
400 {
401 "PEBS": "2",
402 "CollectPEBSRecord": "2",
403 "PublicDescription": "Counts mispredicted branch instructions retired including all branch types.",
404 "EventCode": "0xC5",
405 "Counter": "0,1,2,3",
406 "UMask": "0x0",
407 "PEBScounters": "0,1,2,3",
408 "EventName": "BR_MISP_RETIRED.ALL_BRANCHES",
409 "SampleAfterValue": "200003",
410 "BriefDescription": "Retired mispredicted branch instructions (Precise event capable)"
411 },
412 {
413 "PEBS": "2",
414 "CollectPEBSRecord": "2",
415 "PublicDescription": "Counts mispredicted retired Jcc (Jump on Conditional Code/Jump if Condition is Met) branch instructions retired, including both when the branch was supposed to be taken and when it was not supposed to be taken (but the processor predicted the opposite condition).",
416 "EventCode": "0xC5",
417 "Counter": "0,1,2,3",
418 "UMask": "0x7e",
419 "PEBScounters": "0,1,2,3",
420 "EventName": "BR_MISP_RETIRED.JCC",
421 "SampleAfterValue": "200003",
422 "BriefDescription": "Retired mispredicted conditional branch instructions (Precise event capable)"
423 },
424 {
425 "PEBS": "2",
426 "CollectPEBSRecord": "2",
427 "PublicDescription": "Counts mispredicted branch instructions retired that were near indirect call or near indirect jmp, where the target address taken was not what the processor predicted.",
428 "EventCode": "0xC5",
429 "Counter": "0,1,2,3",
430 "UMask": "0xeb",
431 "PEBScounters": "0,1,2,3",
432 "EventName": "BR_MISP_RETIRED.NON_RETURN_IND",
433 "SampleAfterValue": "200003",
434 "BriefDescription": "Retired mispredicted instructions of near indirect Jmp or near indirect call (Precise event capable)"
435 },
436 {
437 "PEBS": "2",
438 "CollectPEBSRecord": "2",
439 "PublicDescription": "Counts mispredicted near RET branch instructions retired, where the return address taken was not what the processor predicted.",
440 "EventCode": "0xC5",
441 "Counter": "0,1,2,3",
442 "UMask": "0xf7",
443 "PEBScounters": "0,1,2,3",
444 "EventName": "BR_MISP_RETIRED.RETURN",
445 "SampleAfterValue": "200003",
446 "BriefDescription": "Retired mispredicted near return instructions (Precise event capable)"
447 },
448 {
449 "PEBS": "2",
450 "CollectPEBSRecord": "2",
451 "PublicDescription": "Counts mispredicted near indirect CALL branch instructions retired, where the target address taken was not what the processor predicted.",
452 "EventCode": "0xC5",
453 "Counter": "0,1,2,3",
454 "UMask": "0xfb",
455 "PEBScounters": "0,1,2,3",
456 "EventName": "BR_MISP_RETIRED.IND_CALL",
457 "SampleAfterValue": "200003",
458 "BriefDescription": "Retired mispredicted near indirect call instructions (Precise event capable)"
459 },
460 {
461 "PEBS": "2",
462 "CollectPEBSRecord": "2",
463 "PublicDescription": "Counts mispredicted retired Jcc (Jump on Conditional Code/Jump if Condition is Met) branch instructions retired that were supposed to be taken but the processor predicted that it would not be taken.",
464 "EventCode": "0xC5",
465 "Counter": "0,1,2,3",
466 "UMask": "0xfe",
467 "PEBScounters": "0,1,2,3",
468 "EventName": "BR_MISP_RETIRED.TAKEN_JCC",
469 "SampleAfterValue": "200003",
470 "BriefDescription": "Retired mispredicted conditional branch instructions that were taken (Precise event capable)"
471 },
472 {
473 "CollectPEBSRecord": "1",
474 "PublicDescription": "Counts core cycles if either divide unit is busy.",
475 "EventCode": "0xCD",
476 "Counter": "0,1,2,3",
477 "UMask": "0x0",
478 "PEBScounters": "0,1,2,3",
479 "EventName": "CYCLES_DIV_BUSY.ALL",
480 "PDIR_COUNTER": "na",
481 "SampleAfterValue": "2000003",
482 "BriefDescription": "Cycles a divider is busy"
483 },
484 {
485 "CollectPEBSRecord": "1",
486 "PublicDescription": "Counts core cycles the integer divide unit is busy.",
487 "EventCode": "0xCD",
488 "Counter": "0,1,2,3",
489 "UMask": "0x1",
490 "PEBScounters": "0,1,2,3",
491 "EventName": "CYCLES_DIV_BUSY.IDIV",
492 "PDIR_COUNTER": "na",
493 "SampleAfterValue": "200003",
494 "BriefDescription": "Cycles the integer divide unit is busy"
495 },
496 {
497 "CollectPEBSRecord": "1",
498 "PublicDescription": "Counts core cycles the floating point divide unit is busy.",
499 "EventCode": "0xCD",
500 "Counter": "0,1,2,3",
501 "UMask": "0x2",
502 "PEBScounters": "0,1,2,3",
503 "EventName": "CYCLES_DIV_BUSY.FPDIV",
504 "PDIR_COUNTER": "na",
505 "SampleAfterValue": "200003",
506 "BriefDescription": "Cycles the FP divide unit is busy"
507 },
508 {
509 "CollectPEBSRecord": "1",
510 "PublicDescription": "Counts the number of times a BACLEAR is signaled for any reason, including, but not limited to indirect branch/call, Jcc (Jump on Conditional Code/Jump if Condition is Met) branch, unconditional branch/call, and returns.",
511 "EventCode": "0xE6",
512 "Counter": "0,1,2,3",
513 "UMask": "0x1",
514 "PEBScounters": "0,1,2,3",
515 "EventName": "BACLEARS.ALL",
516 "PDIR_COUNTER": "na",
517 "SampleAfterValue": "200003",
518 "BriefDescription": "BACLEARs asserted for any branch type"
519 },
520 {
521 "CollectPEBSRecord": "1",
522 "PublicDescription": "Counts BACLEARS on return instructions.",
523 "EventCode": "0xE6",
524 "Counter": "0,1,2,3",
525 "UMask": "0x8",
526 "PEBScounters": "0,1,2,3",
527 "EventName": "BACLEARS.RETURN",
528 "PDIR_COUNTER": "na",
529 "SampleAfterValue": "200003",
530 "BriefDescription": "BACLEARs asserted for return branch"
531 },
532 {
533 "CollectPEBSRecord": "1",
534 "PublicDescription": "Counts BACLEARS on Jcc (Jump on Conditional Code/Jump if Condition is Met) branches.",
535 "EventCode": "0xE6",
536 "Counter": "0,1,2,3",
537 "UMask": "0x10",
538 "PEBScounters": "0,1,2,3",
539 "EventName": "BACLEARS.COND",
540 "PDIR_COUNTER": "na",
541 "SampleAfterValue": "200003",
542 "BriefDescription": "BACLEARs asserted for conditional branch"
543 }
544] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/goldmontplus/virtual-memory.json b/tools/perf/pmu-events/arch/x86/goldmontplus/virtual-memory.json
new file mode 100644
index 000000000000..0b53a3b0dfb8
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/goldmontplus/virtual-memory.json
@@ -0,0 +1,218 @@
1[
2 {
3 "CollectPEBSRecord": "1",
4 "PublicDescription": "Counts page walks completed due to demand data loads (including SW prefetches) whose address translations missed in all TLB levels and were mapped to 4K pages. The page walks can end with or without a page fault.",
5 "EventCode": "0x08",
6 "Counter": "0,1,2,3",
7 "UMask": "0x2",
8 "PEBScounters": "0,1,2,3",
9 "EventName": "DTLB_LOAD_MISSES.WALK_COMPLETED_4K",
10 "PDIR_COUNTER": "na",
11 "SampleAfterValue": "200003",
12 "BriefDescription": "Page walk completed due to a demand load to a 4K page"
13 },
14 {
15 "CollectPEBSRecord": "1",
16 "PublicDescription": "Counts page walks completed due to demand data loads (including SW prefetches) whose address translations missed in all TLB levels and were mapped to 2M or 4M pages. The page walks can end with or without a page fault.",
17 "EventCode": "0x08",
18 "Counter": "0,1,2,3",
19 "UMask": "0x4",
20 "PEBScounters": "0,1,2,3",
21 "EventName": "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M",
22 "PDIR_COUNTER": "na",
23 "SampleAfterValue": "200003",
24 "BriefDescription": "Page walk completed due to a demand load to a 2M or 4M page"
25 },
26 {
27 "CollectPEBSRecord": "1",
28 "PublicDescription": "Counts page walks completed due to demand data loads (including SW prefetches) whose address translations missed in all TLB levels and were mapped to 1GB pages. The page walks can end with or without a page fault.",
29 "EventCode": "0x08",
30 "Counter": "0,1,2,3",
31 "UMask": "0x8",
32 "PEBScounters": "0,1,2,3",
33 "EventName": "DTLB_LOAD_MISSES.WALK_COMPLETED_1GB",
34 "PDIR_COUNTER": "na",
35 "SampleAfterValue": "200003",
36 "BriefDescription": "Page walk completed due to a demand load to a 1GB page"
37 },
38 {
39 "CollectPEBSRecord": "1",
40 "PublicDescription": "Counts once per cycle for each page walk occurring due to a load (demand data loads or SW prefetches). Includes cycles spent traversing the Extended Page Table (EPT). Average cycles per walk can be calculated by dividing by the number of walks.",
41 "EventCode": "0x08",
42 "Counter": "0,1,2,3",
43 "UMask": "0x10",
44 "PEBScounters": "0,1,2,3",
45 "EventName": "DTLB_LOAD_MISSES.WALK_PENDING",
46 "PDIR_COUNTER": "na",
47 "SampleAfterValue": "200003",
48 "BriefDescription": "Page walks outstanding due to a demand load every cycle."
49 },
50 {
51 "CollectPEBSRecord": "1",
52 "PublicDescription": "Counts page walks completed due to demand data stores whose address translations missed in the TLB and were mapped to 4K pages. The page walks can end with or without a page fault.",
53 "EventCode": "0x49",
54 "Counter": "0,1,2,3",
55 "UMask": "0x2",
56 "PEBScounters": "0,1,2,3",
57 "EventName": "DTLB_STORE_MISSES.WALK_COMPLETED_4K",
58 "PDIR_COUNTER": "na",
59 "SampleAfterValue": "2000003",
60 "BriefDescription": "Page walk completed due to a demand data store to a 4K page"
61 },
62 {
63 "CollectPEBSRecord": "1",
64 "PublicDescription": "Counts page walks completed due to demand data stores whose address translations missed in the TLB and were mapped to 2M or 4M pages. The page walks can end with or without a page fault.",
65 "EventCode": "0x49",
66 "Counter": "0,1,2,3",
67 "UMask": "0x4",
68 "PEBScounters": "0,1,2,3",
69 "EventName": "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M",
70 "PDIR_COUNTER": "na",
71 "SampleAfterValue": "2000003",
72 "BriefDescription": "Page walk completed due to a demand data store to a 2M or 4M page"
73 },
74 {
75 "CollectPEBSRecord": "1",
76 "PublicDescription": "Counts page walks completed due to demand data stores whose address translations missed in the TLB and were mapped to 1GB pages. The page walks can end with or without a page fault.",
77 "EventCode": "0x49",
78 "Counter": "0,1,2,3",
79 "UMask": "0x8",
80 "PEBScounters": "0,1,2,3",
81 "EventName": "DTLB_STORE_MISSES.WALK_COMPLETED_1GB",
82 "PDIR_COUNTER": "na",
83 "SampleAfterValue": "2000003",
84 "BriefDescription": "Page walk completed due to a demand data store to a 1GB page"
85 },
86 {
87 "CollectPEBSRecord": "1",
88 "PublicDescription": "Counts once per cycle for each page walk occurring due to a demand data store. Includes cycles spent traversing the Extended Page Table (EPT). Average cycles per walk can be calculated by dividing by the number of walks.",
89 "EventCode": "0x49",
90 "Counter": "0,1,2,3",
91 "UMask": "0x10",
92 "PEBScounters": "0,1,2,3",
93 "EventName": "DTLB_STORE_MISSES.WALK_PENDING",
94 "PDIR_COUNTER": "na",
95 "SampleAfterValue": "200003",
96 "BriefDescription": "Page walks outstanding due to a demand data store every cycle."
97 },
98 {
99 "CollectPEBSRecord": "1",
100 "PublicDescription": "Counts once per cycle for each page walk only while traversing the Extended Page Table (EPT), and does not count during the rest of the translation. The EPT is used for translating Guest-Physical Addresses to Physical Addresses for Virtual Machine Monitors (VMMs). Average cycles per walk can be calculated by dividing the count by number of walks.",
101 "EventCode": "0x4F",
102 "Counter": "0,1,2,3",
103 "UMask": "0x10",
104 "PEBScounters": "0,1,2,3",
105 "EventName": "EPT.WALK_PENDING",
106 "PDIR_COUNTER": "na",
107 "SampleAfterValue": "200003",
108 "BriefDescription": "Page walks outstanding due to walking the EPT every cycle"
109 },
110 {
111 "CollectPEBSRecord": "1",
112 "PublicDescription": "Counts the number of times the machine was unable to find a translation in the Instruction Translation Lookaside Buffer (ITLB) for a linear address of an instruction fetch. It counts when new translation are filled into the ITLB. The event is speculative in nature, but will not count translations (page walks) that are begun and not finished, or translations that are finished but not filled into the ITLB.",
113 "EventCode": "0x81",
114 "Counter": "0,1,2,3",
115 "UMask": "0x4",
116 "PEBScounters": "0,1,2,3",
117 "EventName": "ITLB.MISS",
118 "PDIR_COUNTER": "na",
119 "SampleAfterValue": "200003",
120 "BriefDescription": "ITLB misses"
121 },
122 {
123 "CollectPEBSRecord": "1",
124 "PublicDescription": "Counts page walks completed due to instruction fetches whose address translations missed in the TLB and were mapped to 4K pages. The page walks can end with or without a page fault.",
125 "EventCode": "0x85",
126 "Counter": "0,1,2,3",
127 "UMask": "0x2",
128 "PEBScounters": "0,1,2,3",
129 "EventName": "ITLB_MISSES.WALK_COMPLETED_4K",
130 "PDIR_COUNTER": "na",
131 "SampleAfterValue": "2000003",
132 "BriefDescription": "Page walk completed due to an instruction fetch in a 4K page"
133 },
134 {
135 "CollectPEBSRecord": "1",
136 "PublicDescription": "Counts page walks completed due to instruction fetches whose address translations missed in the TLB and were mapped to 2M or 4M pages. The page walks can end with or without a page fault.",
137 "EventCode": "0x85",
138 "Counter": "0,1,2,3",
139 "UMask": "0x4",
140 "PEBScounters": "0,1,2,3",
141 "EventName": "ITLB_MISSES.WALK_COMPLETED_2M_4M",
142 "PDIR_COUNTER": "na",
143 "SampleAfterValue": "2000003",
144 "BriefDescription": "Page walk completed due to an instruction fetch in a 2M or 4M page"
145 },
146 {
147 "CollectPEBSRecord": "1",
148 "PublicDescription": "Counts page walks completed due to instruction fetches whose address translations missed in the TLB and were mapped to 1GB pages. The page walks can end with or without a page fault.",
149 "EventCode": "0x85",
150 "Counter": "0,1,2,3",
151 "UMask": "0x8",
152 "PEBScounters": "0,1,2,3",
153 "EventName": "ITLB_MISSES.WALK_COMPLETED_1GB",
154 "PDIR_COUNTER": "na",
155 "SampleAfterValue": "2000003",
156 "BriefDescription": "Page walk completed due to an instruction fetch in a 1GB page"
157 },
158 {
159 "CollectPEBSRecord": "1",
160 "PublicDescription": "Counts once per cycle for each page walk occurring due to an instruction fetch. Includes cycles spent traversing the Extended Page Table (EPT). Average cycles per walk can be calculated by dividing by the number of walks.",
161 "EventCode": "0x85",
162 "Counter": "0,1,2,3",
163 "UMask": "0x10",
164 "PEBScounters": "0,1,2,3",
165 "EventName": "ITLB_MISSES.WALK_PENDING",
166 "PDIR_COUNTER": "na",
167 "SampleAfterValue": "200003",
168 "BriefDescription": "Page walks outstanding due to an instruction fetch every cycle."
169 },
170 {
171 "CollectPEBSRecord": "1",
172 "PublicDescription": "Counts STLB flushes. The TLBs are flushed on instructions like INVLPG and MOV to CR3.",
173 "EventCode": "0xBD",
174 "Counter": "0,1,2,3",
175 "UMask": "0x20",
176 "PEBScounters": "0,1,2,3",
177 "EventName": "TLB_FLUSHES.STLB_ANY",
178 "PDIR_COUNTER": "na",
179 "SampleAfterValue": "20003",
180 "BriefDescription": "STLB flushes"
181 },
182 {
183 "PEBS": "2",
184 "CollectPEBSRecord": "2",
185 "PublicDescription": "Counts load uops retired that caused a DTLB miss.",
186 "EventCode": "0xD0",
187 "Counter": "0,1,2,3",
188 "UMask": "0x11",
189 "PEBScounters": "0,1,2,3",
190 "EventName": "MEM_UOPS_RETIRED.DTLB_MISS_LOADS",
191 "SampleAfterValue": "200003",
192 "BriefDescription": "Load uops retired that missed the DTLB (Precise event capable)"
193 },
194 {
195 "PEBS": "2",
196 "CollectPEBSRecord": "2",
197 "PublicDescription": "Counts store uops retired that caused a DTLB miss.",
198 "EventCode": "0xD0",
199 "Counter": "0,1,2,3",
200 "UMask": "0x12",
201 "PEBScounters": "0,1,2,3",
202 "EventName": "MEM_UOPS_RETIRED.DTLB_MISS_STORES",
203 "SampleAfterValue": "200003",
204 "BriefDescription": "Store uops retired that missed the DTLB (Precise event capable)"
205 },
206 {
207 "PEBS": "2",
208 "CollectPEBSRecord": "2",
209 "PublicDescription": "Counts uops retired that had a DTLB miss on load, store or either. Note that when two distinct memory operations to the same page miss the DTLB, only one of them will be recorded as a DTLB miss.",
210 "EventCode": "0xD0",
211 "Counter": "0,1,2,3",
212 "UMask": "0x13",
213 "PEBScounters": "0,1,2,3",
214 "EventName": "MEM_UOPS_RETIRED.DTLB_MISS",
215 "SampleAfterValue": "200003",
216 "BriefDescription": "Memory uops retired that missed the DTLB (Precise event capable)"
217 }
218] \ No newline at end of file
diff --git a/tools/perf/pmu-events/arch/x86/haswell/hsw-metrics.json b/tools/perf/pmu-events/arch/x86/haswell/hsw-metrics.json
new file mode 100644
index 000000000000..5ab5c78fe580
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/haswell/hsw-metrics.json
@@ -0,0 +1,158 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , IDQ.MITE_UOPS / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 16 * ( ICACHE.HIT + ICACHE.MISSES ) / 4.0 ) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "( UOPS_EXECUTED.CORE / 2 / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@) ) if #SMT_on else UOPS_EXECUTED.CORE / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE.IFDATA_STALL - (( 14 * ITLB_MISSES.STLB_HIT + ITLB_MISSES.WALK_DURATION )) ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_UOPS_RETIRED.L1_MISS + mem_load_uops_retired.hit_lfb )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( cpu@l1d_pend_miss.pending_cycles\\,any\\=1@ / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( ITLB_MISSES.WALK_DURATION + DTLB_LOAD_MISSES.WALK_DURATION + DTLB_STORE_MISSES.WALK_DURATION ) / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
100 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
101 "MetricGroup": "Power",
102 "MetricName": "Turbo_Utilization"
103 },
104 {
105 "BriefDescription": "Fraction of cycles where both hardware threads were active",
106 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
107 "MetricGroup": "SMT;Summary",
108 "MetricName": "SMT_2T_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles spent in Kernel mode",
112 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
113 "MetricGroup": "Summary",
114 "MetricName": "Kernel_Utilization"
115 },
116 {
117 "BriefDescription": "C3 residency percent per core",
118 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
119 "MetricGroup": "Power",
120 "MetricName": "C3_Core_Residency"
121 },
122 {
123 "BriefDescription": "C6 residency percent per core",
124 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C6_Core_Residency"
127 },
128 {
129 "BriefDescription": "C7 residency percent per core",
130 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C7_Core_Residency"
133 },
134 {
135 "BriefDescription": "C2 residency percent per package",
136 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C2_Pkg_Residency"
139 },
140 {
141 "BriefDescription": "C3 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C3_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C6 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C6_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C7 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C7_Pkg_Residency"
157 }
158]
diff --git a/tools/perf/pmu-events/arch/x86/haswellx/hsx-metrics.json b/tools/perf/pmu-events/arch/x86/haswellx/hsx-metrics.json
new file mode 100644
index 000000000000..5ab5c78fe580
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/haswellx/hsx-metrics.json
@@ -0,0 +1,158 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , IDQ.MITE_UOPS / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 16 * ( ICACHE.HIT + ICACHE.MISSES ) / 4.0 ) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "( UOPS_EXECUTED.CORE / 2 / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@) ) if #SMT_on else UOPS_EXECUTED.CORE / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE.IFDATA_STALL - (( 14 * ITLB_MISSES.STLB_HIT + ITLB_MISSES.WALK_DURATION )) ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_UOPS_RETIRED.L1_MISS + mem_load_uops_retired.hit_lfb )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( cpu@l1d_pend_miss.pending_cycles\\,any\\=1@ / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( ITLB_MISSES.WALK_DURATION + DTLB_LOAD_MISSES.WALK_DURATION + DTLB_STORE_MISSES.WALK_DURATION ) / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
100 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
101 "MetricGroup": "Power",
102 "MetricName": "Turbo_Utilization"
103 },
104 {
105 "BriefDescription": "Fraction of cycles where both hardware threads were active",
106 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
107 "MetricGroup": "SMT;Summary",
108 "MetricName": "SMT_2T_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles spent in Kernel mode",
112 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
113 "MetricGroup": "Summary",
114 "MetricName": "Kernel_Utilization"
115 },
116 {
117 "BriefDescription": "C3 residency percent per core",
118 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
119 "MetricGroup": "Power",
120 "MetricName": "C3_Core_Residency"
121 },
122 {
123 "BriefDescription": "C6 residency percent per core",
124 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C6_Core_Residency"
127 },
128 {
129 "BriefDescription": "C7 residency percent per core",
130 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C7_Core_Residency"
133 },
134 {
135 "BriefDescription": "C2 residency percent per package",
136 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C2_Pkg_Residency"
139 },
140 {
141 "BriefDescription": "C3 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C3_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C6 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C6_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C7 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C7_Pkg_Residency"
157 }
158]
diff --git a/tools/perf/pmu-events/arch/x86/ivybridge/ivb-metrics.json b/tools/perf/pmu-events/arch/x86/ivybridge/ivb-metrics.json
new file mode 100644
index 000000000000..7c2679514efb
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/ivybridge/ivb-metrics.json
@@ -0,0 +1,164 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , UOPS_ISSUED.ANY / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 32 * ( ICACHE.HIT + ICACHE.MISSES ) / 4) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_EXECUTED.THREAD / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else UOPS_EXECUTED.CYCLES_GE_1_UOP_EXEC)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE.IFETCH_STALL ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_UOPS_RETIRED.L1_MISS + mem_load_uops_retired.hit_lfb )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( cpu@l1d_pend_miss.pending_cycles\\,any\\=1@ / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( ITLB_MISSES.WALK_DURATION + DTLB_LOAD_MISSES.WALK_DURATION + DTLB_STORE_MISSES.WALK_DURATION ) / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Giga Floating Point Operations Per Second",
100 "MetricExpr": "(( 1*( FP_COMP_OPS_EXE.SSE_SCALAR_SINGLE + FP_COMP_OPS_EXE.SSE_SCALAR_DOUBLE ) + 2* FP_COMP_OPS_EXE.SSE_PACKED_DOUBLE + 4*( FP_COMP_OPS_EXE.SSE_PACKED_SINGLE + SIMD_FP_256.PACKED_DOUBLE ) + 8* SIMD_FP_256.PACKED_SINGLE )) / 1000000000 / duration_time",
101 "MetricGroup": "FLOPS;Summary",
102 "MetricName": "GFLOPs"
103 },
104 {
105 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
106 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
107 "MetricGroup": "Power",
108 "MetricName": "Turbo_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles where both hardware threads were active",
112 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
113 "MetricGroup": "SMT;Summary",
114 "MetricName": "SMT_2T_Utilization"
115 },
116 {
117 "BriefDescription": "Fraction of cycles spent in Kernel mode",
118 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
119 "MetricGroup": "Summary",
120 "MetricName": "Kernel_Utilization"
121 },
122 {
123 "BriefDescription": "C3 residency percent per core",
124 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Core_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per core",
130 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Core_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per core",
136 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Core_Residency"
139 },
140 {
141 "BriefDescription": "C2 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C2_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C3 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C3_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C6 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C6_Pkg_Residency"
157 },
158 {
159 "BriefDescription": "C7 residency percent per package",
160 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
161 "MetricGroup": "Power",
162 "MetricName": "C7_Pkg_Residency"
163 }
164]
diff --git a/tools/perf/pmu-events/arch/x86/ivytown/ivt-metrics.json b/tools/perf/pmu-events/arch/x86/ivytown/ivt-metrics.json
new file mode 100644
index 000000000000..7c2679514efb
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/ivytown/ivt-metrics.json
@@ -0,0 +1,164 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , UOPS_ISSUED.ANY / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 32 * ( ICACHE.HIT + ICACHE.MISSES ) / 4) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_EXECUTED.THREAD / (( cpu@UOPS_EXECUTED.CORE\\,cmask\\=1@ / 2) if #SMT_on else UOPS_EXECUTED.CYCLES_GE_1_UOP_EXEC)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE.IFETCH_STALL ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_UOPS_RETIRED.L1_MISS + mem_load_uops_retired.hit_lfb )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( cpu@l1d_pend_miss.pending_cycles\\,any\\=1@ / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( ITLB_MISSES.WALK_DURATION + DTLB_LOAD_MISSES.WALK_DURATION + DTLB_STORE_MISSES.WALK_DURATION ) / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Giga Floating Point Operations Per Second",
100 "MetricExpr": "(( 1*( FP_COMP_OPS_EXE.SSE_SCALAR_SINGLE + FP_COMP_OPS_EXE.SSE_SCALAR_DOUBLE ) + 2* FP_COMP_OPS_EXE.SSE_PACKED_DOUBLE + 4*( FP_COMP_OPS_EXE.SSE_PACKED_SINGLE + SIMD_FP_256.PACKED_DOUBLE ) + 8* SIMD_FP_256.PACKED_SINGLE )) / 1000000000 / duration_time",
101 "MetricGroup": "FLOPS;Summary",
102 "MetricName": "GFLOPs"
103 },
104 {
105 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
106 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
107 "MetricGroup": "Power",
108 "MetricName": "Turbo_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles where both hardware threads were active",
112 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
113 "MetricGroup": "SMT;Summary",
114 "MetricName": "SMT_2T_Utilization"
115 },
116 {
117 "BriefDescription": "Fraction of cycles spent in Kernel mode",
118 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
119 "MetricGroup": "Summary",
120 "MetricName": "Kernel_Utilization"
121 },
122 {
123 "BriefDescription": "C3 residency percent per core",
124 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Core_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per core",
130 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Core_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per core",
136 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Core_Residency"
139 },
140 {
141 "BriefDescription": "C2 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C2_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C3 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C3_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C6 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C6_Pkg_Residency"
157 },
158 {
159 "BriefDescription": "C7 residency percent per package",
160 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
161 "MetricGroup": "Power",
162 "MetricName": "C7_Pkg_Residency"
163 }
164]
diff --git a/tools/perf/pmu-events/arch/x86/jaketown/jkt-metrics.json b/tools/perf/pmu-events/arch/x86/jaketown/jkt-metrics.json
new file mode 100644
index 000000000000..fd7d7c438226
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/jaketown/jkt-metrics.json
@@ -0,0 +1,140 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , UOPS_ISSUED.ANY / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 32 * ( ICACHE.HIT + ICACHE.MISSES ) / 4) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_DISPATCHED.THREAD / (( cpu@UOPS_DISPATCHED.CORE\\,cmask\\=1@ / 2) if #SMT_on else cpu@UOPS_DISPATCHED.CORE\\,cmask\\=1@)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
64 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
65 "MetricGroup": "SMT",
66 "MetricName": "CORE_CLKS"
67 },
68 {
69 "BriefDescription": "Average CPU Utilization",
70 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
71 "MetricGroup": "Summary",
72 "MetricName": "CPU_Utilization"
73 },
74 {
75 "BriefDescription": "Giga Floating Point Operations Per Second",
76 "MetricExpr": "(( 1*( FP_COMP_OPS_EXE.SSE_SCALAR_SINGLE + FP_COMP_OPS_EXE.SSE_SCALAR_DOUBLE ) + 2* FP_COMP_OPS_EXE.SSE_PACKED_DOUBLE + 4*( FP_COMP_OPS_EXE.SSE_PACKED_SINGLE + SIMD_FP_256.PACKED_DOUBLE ) + 8* SIMD_FP_256.PACKED_SINGLE )) / 1000000000 / duration_time",
77 "MetricGroup": "FLOPS;Summary",
78 "MetricName": "GFLOPs"
79 },
80 {
81 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
82 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
83 "MetricGroup": "Power",
84 "MetricName": "Turbo_Utilization"
85 },
86 {
87 "BriefDescription": "Fraction of cycles where both hardware threads were active",
88 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
89 "MetricGroup": "SMT;Summary",
90 "MetricName": "SMT_2T_Utilization"
91 },
92 {
93 "BriefDescription": "Fraction of cycles spent in Kernel mode",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
95 "MetricGroup": "Summary",
96 "MetricName": "Kernel_Utilization"
97 },
98 {
99 "BriefDescription": "C3 residency percent per core",
100 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
101 "MetricGroup": "Power",
102 "MetricName": "C3_Core_Residency"
103 },
104 {
105 "BriefDescription": "C6 residency percent per core",
106 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
107 "MetricGroup": "Power",
108 "MetricName": "C6_Core_Residency"
109 },
110 {
111 "BriefDescription": "C7 residency percent per core",
112 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
113 "MetricGroup": "Power",
114 "MetricName": "C7_Core_Residency"
115 },
116 {
117 "BriefDescription": "C2 residency percent per package",
118 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
119 "MetricGroup": "Power",
120 "MetricName": "C2_Pkg_Residency"
121 },
122 {
123 "BriefDescription": "C3 residency percent per package",
124 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Pkg_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per package",
130 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Pkg_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per package",
136 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Pkg_Residency"
139 }
140]
diff --git a/tools/perf/pmu-events/arch/x86/mapfile.csv b/tools/perf/pmu-events/arch/x86/mapfile.csv
index 4ea068366c3e..fe1a2c47cabf 100644
--- a/tools/perf/pmu-events/arch/x86/mapfile.csv
+++ b/tools/perf/pmu-events/arch/x86/mapfile.csv
@@ -9,6 +9,7 @@ GenuineIntel-6-27,v4,bonnell,core
9GenuineIntel-6-36,v4,bonnell,core 9GenuineIntel-6-36,v4,bonnell,core
10GenuineIntel-6-35,v4,bonnell,core 10GenuineIntel-6-35,v4,bonnell,core
11GenuineIntel-6-5C,v8,goldmont,core 11GenuineIntel-6-5C,v8,goldmont,core
12GenuineIntel-6-7A,v1,goldmontplus,core
12GenuineIntel-6-3C,v24,haswell,core 13GenuineIntel-6-3C,v24,haswell,core
13GenuineIntel-6-45,v24,haswell,core 14GenuineIntel-6-45,v24,haswell,core
14GenuineIntel-6-46,v24,haswell,core 15GenuineIntel-6-46,v24,haswell,core
diff --git a/tools/perf/pmu-events/arch/x86/sandybridge/snb-metrics.json b/tools/perf/pmu-events/arch/x86/sandybridge/snb-metrics.json
new file mode 100644
index 000000000000..fd7d7c438226
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/sandybridge/snb-metrics.json
@@ -0,0 +1,140 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , UOPS_ISSUED.ANY / ( (UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 32 * ( ICACHE.HIT + ICACHE.MISSES ) / 4) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_DISPATCHED.THREAD / (( cpu@UOPS_DISPATCHED.CORE\\,cmask\\=1@ / 2) if #SMT_on else cpu@UOPS_DISPATCHED.CORE\\,cmask\\=1@)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
64 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
65 "MetricGroup": "SMT",
66 "MetricName": "CORE_CLKS"
67 },
68 {
69 "BriefDescription": "Average CPU Utilization",
70 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
71 "MetricGroup": "Summary",
72 "MetricName": "CPU_Utilization"
73 },
74 {
75 "BriefDescription": "Giga Floating Point Operations Per Second",
76 "MetricExpr": "(( 1*( FP_COMP_OPS_EXE.SSE_SCALAR_SINGLE + FP_COMP_OPS_EXE.SSE_SCALAR_DOUBLE ) + 2* FP_COMP_OPS_EXE.SSE_PACKED_DOUBLE + 4*( FP_COMP_OPS_EXE.SSE_PACKED_SINGLE + SIMD_FP_256.PACKED_DOUBLE ) + 8* SIMD_FP_256.PACKED_SINGLE )) / 1000000000 / duration_time",
77 "MetricGroup": "FLOPS;Summary",
78 "MetricName": "GFLOPs"
79 },
80 {
81 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
82 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
83 "MetricGroup": "Power",
84 "MetricName": "Turbo_Utilization"
85 },
86 {
87 "BriefDescription": "Fraction of cycles where both hardware threads were active",
88 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
89 "MetricGroup": "SMT;Summary",
90 "MetricName": "SMT_2T_Utilization"
91 },
92 {
93 "BriefDescription": "Fraction of cycles spent in Kernel mode",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
95 "MetricGroup": "Summary",
96 "MetricName": "Kernel_Utilization"
97 },
98 {
99 "BriefDescription": "C3 residency percent per core",
100 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
101 "MetricGroup": "Power",
102 "MetricName": "C3_Core_Residency"
103 },
104 {
105 "BriefDescription": "C6 residency percent per core",
106 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
107 "MetricGroup": "Power",
108 "MetricName": "C6_Core_Residency"
109 },
110 {
111 "BriefDescription": "C7 residency percent per core",
112 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
113 "MetricGroup": "Power",
114 "MetricName": "C7_Core_Residency"
115 },
116 {
117 "BriefDescription": "C2 residency percent per package",
118 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
119 "MetricGroup": "Power",
120 "MetricName": "C2_Pkg_Residency"
121 },
122 {
123 "BriefDescription": "C3 residency percent per package",
124 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Pkg_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per package",
130 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Pkg_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per package",
136 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Pkg_Residency"
139 }
140]
diff --git a/tools/perf/pmu-events/arch/x86/skylake/skl-metrics.json b/tools/perf/pmu-events/arch/x86/skylake/skl-metrics.json
new file mode 100644
index 000000000000..36c903faed0b
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/skylake/skl-metrics.json
@@ -0,0 +1,164 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , UOPS_ISSUED.ANY / ((UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 64 * ( ICACHE_64B.IFTAG_HIT + ICACHE_64B.IFTAG_MISS ) / 4.1) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_EXECUTED.THREAD / (( UOPS_EXECUTED.CORE_CYCLES_GE_1 / 2) if #SMT_on else UOPS_EXECUTED.CORE_CYCLES_GE_1)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE_16B.IFDATA_STALL - ICACHE_64B.IFTAG_STALL ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_RETIRED.L1_MISS_PS + MEM_LOAD_RETIRED.FB_HIT_PS )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( L1D_PEND_MISS.PENDING_CYCLES_ANY / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( ITLB_MISSES.WALK_PENDING + DTLB_LOAD_MISSES.WALK_PENDING + DTLB_STORE_MISSES.WALK_PENDING + EPT.WALK_PENDING ) / ( 2 * (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles) )",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Giga Floating Point Operations Per Second",
100 "MetricExpr": "(( 1*( FP_ARITH_INST_RETIRED.SCALAR_SINGLE + FP_ARITH_INST_RETIRED.SCALAR_DOUBLE ) + 2* FP_ARITH_INST_RETIRED.128B_PACKED_DOUBLE + 4*( FP_ARITH_INST_RETIRED.128B_PACKED_SINGLE + FP_ARITH_INST_RETIRED.256B_PACKED_DOUBLE ) + 8* FP_ARITH_INST_RETIRED.256B_PACKED_SINGLE )) / 1000000000 / duration_time",
101 "MetricGroup": "FLOPS;Summary",
102 "MetricName": "GFLOPs"
103 },
104 {
105 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
106 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
107 "MetricGroup": "Power",
108 "MetricName": "Turbo_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles where both hardware threads were active",
112 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
113 "MetricGroup": "SMT;Summary",
114 "MetricName": "SMT_2T_Utilization"
115 },
116 {
117 "BriefDescription": "Fraction of cycles spent in Kernel mode",
118 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
119 "MetricGroup": "Summary",
120 "MetricName": "Kernel_Utilization"
121 },
122 {
123 "BriefDescription": "C3 residency percent per core",
124 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Core_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per core",
130 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Core_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per core",
136 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Core_Residency"
139 },
140 {
141 "BriefDescription": "C2 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C2_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C3 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C3_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C6 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C6_Pkg_Residency"
157 },
158 {
159 "BriefDescription": "C7 residency percent per package",
160 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
161 "MetricGroup": "Power",
162 "MetricName": "C7_Pkg_Residency"
163 }
164]
diff --git a/tools/perf/pmu-events/arch/x86/skylakex/skx-metrics.json b/tools/perf/pmu-events/arch/x86/skylakex/skx-metrics.json
new file mode 100644
index 000000000000..36c903faed0b
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/skylakex/skx-metrics.json
@@ -0,0 +1,164 @@
1[
2 {
3 "BriefDescription": "Instructions Per Cycle (per logical thread)",
4 "MetricExpr": "INST_RETIRED.ANY / CPU_CLK_UNHALTED.THREAD",
5 "MetricGroup": "TopDownL1",
6 "MetricName": "IPC"
7 },
8 {
9 "BriefDescription": "Uops Per Instruction",
10 "MetricExpr": "UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY",
11 "MetricGroup": "Pipeline",
12 "MetricName": "UPI"
13 },
14 {
15 "BriefDescription": "Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions",
16 "MetricExpr": "min( 1 , UOPS_ISSUED.ANY / ((UOPS_RETIRED.RETIRE_SLOTS / INST_RETIRED.ANY) * 64 * ( ICACHE_64B.IFTAG_HIT + ICACHE_64B.IFTAG_MISS ) / 4.1) )",
17 "MetricGroup": "Frontend",
18 "MetricName": "IFetch_Line_Utilization"
19 },
20 {
21 "BriefDescription": "Fraction of Uops delivered by the DSB (aka Decoded Icache; or Uop Cache)",
22 "MetricExpr": "IDQ.DSB_UOPS / ( IDQ.DSB_UOPS + LSD.UOPS + IDQ.MITE_UOPS + IDQ.MS_UOPS )",
23 "MetricGroup": "DSB; Frontend_Bandwidth",
24 "MetricName": "DSB_Coverage"
25 },
26 {
27 "BriefDescription": "Cycles Per Instruction (threaded)",
28 "MetricExpr": "1 / (INST_RETIRED.ANY / cycles)",
29 "MetricGroup": "Pipeline;Summary",
30 "MetricName": "CPI"
31 },
32 {
33 "BriefDescription": "Per-thread actual clocks when the logical processor is active. This is called 'Clockticks' in VTune.",
34 "MetricExpr": "CPU_CLK_UNHALTED.THREAD",
35 "MetricGroup": "Summary",
36 "MetricName": "CLKS"
37 },
38 {
39 "BriefDescription": "Total issue-pipeline slots",
40 "MetricExpr": "4*(( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
41 "MetricGroup": "TopDownL1",
42 "MetricName": "SLOTS"
43 },
44 {
45 "BriefDescription": "Total number of retired Instructions",
46 "MetricExpr": "INST_RETIRED.ANY",
47 "MetricGroup": "Summary",
48 "MetricName": "Instructions"
49 },
50 {
51 "BriefDescription": "Instructions Per Cycle (per physical core)",
52 "MetricExpr": "INST_RETIRED.ANY / (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles)",
53 "MetricGroup": "SMT",
54 "MetricName": "CoreIPC"
55 },
56 {
57 "BriefDescription": "Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)",
58 "MetricExpr": "UOPS_EXECUTED.THREAD / (( UOPS_EXECUTED.CORE_CYCLES_GE_1 / 2) if #SMT_on else UOPS_EXECUTED.CORE_CYCLES_GE_1)",
59 "MetricGroup": "Pipeline;Ports_Utilization",
60 "MetricName": "ILP"
61 },
62 {
63 "BriefDescription": "Average Branch Address Clear Cost (fraction of cycles)",
64 "MetricExpr": "2* (( RS_EVENTS.EMPTY_CYCLES - ICACHE_16B.IFDATA_STALL - ICACHE_64B.IFTAG_STALL ) / RS_EVENTS.EMPTY_END)",
65 "MetricGroup": "Unknown_Branches",
66 "MetricName": "BAClear_Cost"
67 },
68 {
69 "BriefDescription": "Core actual clocks when any thread is active on the physical core",
70 "MetricExpr": "( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else CPU_CLK_UNHALTED.THREAD",
71 "MetricGroup": "SMT",
72 "MetricName": "CORE_CLKS"
73 },
74 {
75 "BriefDescription": "Actual Average Latency for L1 data-cache miss demand loads",
76 "MetricExpr": "L1D_PEND_MISS.PENDING / ( MEM_LOAD_RETIRED.L1_MISS_PS + MEM_LOAD_RETIRED.FB_HIT_PS )",
77 "MetricGroup": "Memory_Bound;Memory_Lat",
78 "MetricName": "Load_Miss_Real_Latency"
79 },
80 {
81 "BriefDescription": "Memory-Level-Parallelism (average number of L1 miss demand load when there is at least 1 such miss)",
82 "MetricExpr": "L1D_PEND_MISS.PENDING / (( L1D_PEND_MISS.PENDING_CYCLES_ANY / 2) if #SMT_on else L1D_PEND_MISS.PENDING_CYCLES)",
83 "MetricGroup": "Memory_Bound;Memory_BW",
84 "MetricName": "MLP"
85 },
86 {
87 "BriefDescription": "Utilization of the core's Page Walker(s) serving STLB misses triggered by instruction/Load/Store accesses",
88 "MetricExpr": "( ITLB_MISSES.WALK_PENDING + DTLB_LOAD_MISSES.WALK_PENDING + DTLB_STORE_MISSES.WALK_PENDING + EPT.WALK_PENDING ) / ( 2 * (( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles) )",
89 "MetricGroup": "TLB",
90 "MetricName": "Page_Walks_Utilization"
91 },
92 {
93 "BriefDescription": "Average CPU Utilization",
94 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC / msr@tsc@",
95 "MetricGroup": "Summary",
96 "MetricName": "CPU_Utilization"
97 },
98 {
99 "BriefDescription": "Giga Floating Point Operations Per Second",
100 "MetricExpr": "(( 1*( FP_ARITH_INST_RETIRED.SCALAR_SINGLE + FP_ARITH_INST_RETIRED.SCALAR_DOUBLE ) + 2* FP_ARITH_INST_RETIRED.128B_PACKED_DOUBLE + 4*( FP_ARITH_INST_RETIRED.128B_PACKED_SINGLE + FP_ARITH_INST_RETIRED.256B_PACKED_DOUBLE ) + 8* FP_ARITH_INST_RETIRED.256B_PACKED_SINGLE )) / 1000000000 / duration_time",
101 "MetricGroup": "FLOPS;Summary",
102 "MetricName": "GFLOPs"
103 },
104 {
105 "BriefDescription": "Average Frequency Utilization relative nominal frequency",
106 "MetricExpr": "CPU_CLK_UNHALTED.THREAD / CPU_CLK_UNHALTED.REF_TSC",
107 "MetricGroup": "Power",
108 "MetricName": "Turbo_Utilization"
109 },
110 {
111 "BriefDescription": "Fraction of cycles where both hardware threads were active",
112 "MetricExpr": "1 - CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE / ( CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY / 2 ) if #SMT_on else 0",
113 "MetricGroup": "SMT;Summary",
114 "MetricName": "SMT_2T_Utilization"
115 },
116 {
117 "BriefDescription": "Fraction of cycles spent in Kernel mode",
118 "MetricExpr": "CPU_CLK_UNHALTED.REF_TSC:u / CPU_CLK_UNHALTED.REF_TSC",
119 "MetricGroup": "Summary",
120 "MetricName": "Kernel_Utilization"
121 },
122 {
123 "BriefDescription": "C3 residency percent per core",
124 "MetricExpr": "(cstate_core@c3\\-residency@ / msr@tsc@) * 100",
125 "MetricGroup": "Power",
126 "MetricName": "C3_Core_Residency"
127 },
128 {
129 "BriefDescription": "C6 residency percent per core",
130 "MetricExpr": "(cstate_core@c6\\-residency@ / msr@tsc@) * 100",
131 "MetricGroup": "Power",
132 "MetricName": "C6_Core_Residency"
133 },
134 {
135 "BriefDescription": "C7 residency percent per core",
136 "MetricExpr": "(cstate_core@c7\\-residency@ / msr@tsc@) * 100",
137 "MetricGroup": "Power",
138 "MetricName": "C7_Core_Residency"
139 },
140 {
141 "BriefDescription": "C2 residency percent per package",
142 "MetricExpr": "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100",
143 "MetricGroup": "Power",
144 "MetricName": "C2_Pkg_Residency"
145 },
146 {
147 "BriefDescription": "C3 residency percent per package",
148 "MetricExpr": "(cstate_pkg@c3\\-residency@ / msr@tsc@) * 100",
149 "MetricGroup": "Power",
150 "MetricName": "C3_Pkg_Residency"
151 },
152 {
153 "BriefDescription": "C6 residency percent per package",
154 "MetricExpr": "(cstate_pkg@c6\\-residency@ / msr@tsc@) * 100",
155 "MetricGroup": "Power",
156 "MetricName": "C6_Pkg_Residency"
157 },
158 {
159 "BriefDescription": "C7 residency percent per package",
160 "MetricExpr": "(cstate_pkg@c7\\-residency@ / msr@tsc@) * 100",
161 "MetricGroup": "Power",
162 "MetricName": "C7_Pkg_Residency"
163 }
164]
diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
index d51dc9ca8861..9eb7047bafe4 100644
--- a/tools/perf/pmu-events/jevents.c
+++ b/tools/perf/pmu-events/jevents.c
@@ -292,7 +292,7 @@ static int print_events_table_entry(void *data, char *name, char *event,
292 char *desc, char *long_desc, 292 char *desc, char *long_desc,
293 char *pmu, char *unit, char *perpkg, 293 char *pmu, char *unit, char *perpkg,
294 char *metric_expr, 294 char *metric_expr,
295 char *metric_name) 295 char *metric_name, char *metric_group)
296{ 296{
297 struct perf_entry_data *pd = data; 297 struct perf_entry_data *pd = data;
298 FILE *outfp = pd->outfp; 298 FILE *outfp = pd->outfp;
@@ -304,8 +304,10 @@ static int print_events_table_entry(void *data, char *name, char *event,
304 */ 304 */
305 fprintf(outfp, "{\n"); 305 fprintf(outfp, "{\n");
306 306
307 fprintf(outfp, "\t.name = \"%s\",\n", name); 307 if (name)
308 fprintf(outfp, "\t.event = \"%s\",\n", event); 308 fprintf(outfp, "\t.name = \"%s\",\n", name);
309 if (event)
310 fprintf(outfp, "\t.event = \"%s\",\n", event);
309 fprintf(outfp, "\t.desc = \"%s\",\n", desc); 311 fprintf(outfp, "\t.desc = \"%s\",\n", desc);
310 fprintf(outfp, "\t.topic = \"%s\",\n", topic); 312 fprintf(outfp, "\t.topic = \"%s\",\n", topic);
311 if (long_desc && long_desc[0]) 313 if (long_desc && long_desc[0])
@@ -320,6 +322,8 @@ static int print_events_table_entry(void *data, char *name, char *event,
320 fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr); 322 fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr);
321 if (metric_name) 323 if (metric_name)
322 fprintf(outfp, "\t.metric_name = \"%s\",\n", metric_name); 324 fprintf(outfp, "\t.metric_name = \"%s\",\n", metric_name);
325 if (metric_group)
326 fprintf(outfp, "\t.metric_group = \"%s\",\n", metric_group);
323 fprintf(outfp, "},\n"); 327 fprintf(outfp, "},\n");
324 328
325 return 0; 329 return 0;
@@ -357,6 +361,9 @@ static char *real_event(const char *name, char *event)
357{ 361{
358 int i; 362 int i;
359 363
364 if (!name)
365 return NULL;
366
360 for (i = 0; fixed[i].name; i++) 367 for (i = 0; fixed[i].name; i++)
361 if (!strcasecmp(name, fixed[i].name)) 368 if (!strcasecmp(name, fixed[i].name))
362 return (char *)fixed[i].event; 369 return (char *)fixed[i].event;
@@ -369,7 +376,7 @@ int json_events(const char *fn,
369 char *long_desc, 376 char *long_desc,
370 char *pmu, char *unit, char *perpkg, 377 char *pmu, char *unit, char *perpkg,
371 char *metric_expr, 378 char *metric_expr,
372 char *metric_name), 379 char *metric_name, char *metric_group),
373 void *data) 380 void *data)
374{ 381{
375 int err = -EIO; 382 int err = -EIO;
@@ -397,6 +404,7 @@ int json_events(const char *fn,
397 char *unit = NULL; 404 char *unit = NULL;
398 char *metric_expr = NULL; 405 char *metric_expr = NULL;
399 char *metric_name = NULL; 406 char *metric_name = NULL;
407 char *metric_group = NULL;
400 unsigned long long eventcode = 0; 408 unsigned long long eventcode = 0;
401 struct msrmap *msr = NULL; 409 struct msrmap *msr = NULL;
402 jsmntok_t *msrval = NULL; 410 jsmntok_t *msrval = NULL;
@@ -476,6 +484,8 @@ int json_events(const char *fn,
476 addfield(map, &perpkg, "", "", val); 484 addfield(map, &perpkg, "", "", val);
477 } else if (json_streq(map, field, "MetricName")) { 485 } else if (json_streq(map, field, "MetricName")) {
478 addfield(map, &metric_name, "", "", val); 486 addfield(map, &metric_name, "", "", val);
487 } else if (json_streq(map, field, "MetricGroup")) {
488 addfield(map, &metric_group, "", "", val);
479 } else if (json_streq(map, field, "MetricExpr")) { 489 } else if (json_streq(map, field, "MetricExpr")) {
480 addfield(map, &metric_expr, "", "", val); 490 addfield(map, &metric_expr, "", "", val);
481 for (s = metric_expr; *s; s++) 491 for (s = metric_expr; *s; s++)
@@ -501,10 +511,11 @@ int json_events(const char *fn,
501 addfield(map, &event, ",", filter, NULL); 511 addfield(map, &event, ",", filter, NULL);
502 if (msr != NULL) 512 if (msr != NULL)
503 addfield(map, &event, ",", msr->pname, msrval); 513 addfield(map, &event, ",", msr->pname, msrval);
504 fixname(name); 514 if (name)
515 fixname(name);
505 516
506 err = func(data, name, real_event(name, event), desc, long_desc, 517 err = func(data, name, real_event(name, event), desc, long_desc,
507 pmu, unit, perpkg, metric_expr, metric_name); 518 pmu, unit, perpkg, metric_expr, metric_name, metric_group);
508 free(event); 519 free(event);
509 free(desc); 520 free(desc);
510 free(name); 521 free(name);
@@ -516,6 +527,7 @@ int json_events(const char *fn,
516 free(unit); 527 free(unit);
517 free(metric_expr); 528 free(metric_expr);
518 free(metric_name); 529 free(metric_name);
530 free(metric_group);
519 if (err) 531 if (err)
520 break; 532 break;
521 tok += j; 533 tok += j;
diff --git a/tools/perf/pmu-events/jevents.h b/tools/perf/pmu-events/jevents.h
index 611fac01913d..4684c673c445 100644
--- a/tools/perf/pmu-events/jevents.h
+++ b/tools/perf/pmu-events/jevents.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef JEVENTS_H 2#ifndef JEVENTS_H
2#define JEVENTS_H 1 3#define JEVENTS_H 1
3 4
@@ -6,7 +7,7 @@ int json_events(const char *fn,
6 char *long_desc, 7 char *long_desc,
7 char *pmu, 8 char *pmu,
8 char *unit, char *perpkg, char *metric_expr, 9 char *unit, char *perpkg, char *metric_expr,
9 char *metric_name), 10 char *metric_name, char *metric_group),
10 void *data); 11 void *data);
11char *get_cpu_str(void); 12char *get_cpu_str(void);
12 13
diff --git a/tools/perf/pmu-events/jsmn.h b/tools/perf/pmu-events/jsmn.h
index d666b10cf25b..c7b0f6ea2a31 100644
--- a/tools/perf/pmu-events/jsmn.h
+++ b/tools/perf/pmu-events/jsmn.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __JSMN_H_ 2#ifndef __JSMN_H_
2#define __JSMN_H_ 3#define __JSMN_H_
3 4
diff --git a/tools/perf/pmu-events/json.h b/tools/perf/pmu-events/json.h
index 278ebd32cfb6..fbcd5a0590ad 100644
--- a/tools/perf/pmu-events/json.h
+++ b/tools/perf/pmu-events/json.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef JSON_H 2#ifndef JSON_H
2#define JSON_H 1 3#define JSON_H 1
3 4
diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h
index 569eab3688dd..92a4d15ee0b9 100644
--- a/tools/perf/pmu-events/pmu-events.h
+++ b/tools/perf/pmu-events/pmu-events.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PMU_EVENTS_H 2#ifndef PMU_EVENTS_H
2#define PMU_EVENTS_H 3#define PMU_EVENTS_H
3 4
@@ -15,6 +16,7 @@ struct pmu_event {
15 const char *perpkg; 16 const char *perpkg;
16 const char *metric_expr; 17 const char *metric_expr;
17 const char *metric_name; 18 const char *metric_name;
19 const char *metric_group;
18}; 20};
19 21
20/* 22/*
diff --git a/tools/perf/python/tracepoint.py b/tools/perf/python/tracepoint.py
index eb4dbed57de7..eb76f6516247 100755
--- a/tools/perf/python/tracepoint.py
+++ b/tools/perf/python/tracepoint.py
@@ -1,4 +1,5 @@
1#! /usr/bin/python 1#! /usr/bin/python
2# SPDX-License-Identifier: GPL-2.0
2# -*- python -*- 3# -*- python -*-
3# -*- coding: utf-8 -*- 4# -*- coding: utf-8 -*-
4 5
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL b/tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL
index decdeb0f6789..e8994332d7dc 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1use 5.010000; 2use 5.010000;
2use ExtUtils::MakeMaker; 3use ExtUtils::MakeMaker;
3# See lib/ExtUtils/MakeMaker.pm for details of how to influence 4# See lib/ExtUtils/MakeMaker.pm for details of how to influence
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
index 9e0985794e20..81a56cd2b3c1 100755
--- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
@@ -1,4 +1,5 @@
1# EventClass.py 1# EventClass.py
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# This is a library defining some events types classes, which could 4# This is a library defining some events types classes, which could
4# be used by other scripts to analyzing the perf samples. 5# be used by other scripts to analyzing the perf samples.
diff --git a/tools/perf/scripts/python/event_analyzing_sample.py b/tools/perf/scripts/python/event_analyzing_sample.py
index 163c39fa12d9..4e843b9864ec 100644
--- a/tools/perf/scripts/python/event_analyzing_sample.py
+++ b/tools/perf/scripts/python/event_analyzing_sample.py
@@ -1,4 +1,5 @@
1# event_analyzing_sample.py: general event handler in python 1# event_analyzing_sample.py: general event handler in python
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# Current perf report is already very powerful with the annotation integrated, 4# Current perf report is already very powerful with the annotation integrated,
4# and this script is not trying to be as powerful as perf report, but 5# and this script is not trying to be as powerful as perf report, but
diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py
index 0b6ce8c253e8..a150164b44a3 100755
--- a/tools/perf/scripts/python/net_dropmonitor.py
+++ b/tools/perf/scripts/python/net_dropmonitor.py
@@ -1,4 +1,5 @@
1# Monitor the system for dropped packets and proudce a report of drop locations and counts 1# Monitor the system for dropped packets and proudce a report of drop locations and counts
2# SPDX-License-Identifier: GPL-2.0
2 3
3import os 4import os
4import sys 5import sys
diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py
index 4c6f09ac7d12..9b2050f778f1 100644
--- a/tools/perf/scripts/python/netdev-times.py
+++ b/tools/perf/scripts/python/netdev-times.py
@@ -1,4 +1,5 @@
1# Display a process of packets and processed time. 1# Display a process of packets and processed time.
2# SPDX-License-Identifier: GPL-2.0
2# It helps us to investigate networking or network device. 3# It helps us to investigate networking or network device.
3# 4#
4# options 5# options
diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
index 5a605f70ef32..1697b5e18c96 100755
--- a/tools/perf/scripts/python/stackcollapse.py
+++ b/tools/perf/scripts/python/stackcollapse.py
@@ -1,4 +1,5 @@
1# stackcollapse.py - format perf samples with one line per distinct call stack 1# stackcollapse.py - format perf samples with one line per distinct call stack
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# This script's output has two space-separated fields. The first is a semicolon 4# This script's output has two space-separated fields. The first is a semicolon
4# separated stack including the program name (from the "comm" field) and the 5# separated stack including the program name (from the "comm" field) and the
diff --git a/tools/perf/scripts/python/stat-cpi.py b/tools/perf/scripts/python/stat-cpi.py
index 8b60f343dd07..8410672efb8b 100644
--- a/tools/perf/scripts/python/stat-cpi.py
+++ b/tools/perf/scripts/python/stat-cpi.py
@@ -1,4 +1,5 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# SPDX-License-Identifier: GPL-2.0
2 3
3data = {} 4data = {}
4times = [] 5times = []
diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c
index c9aafed7da15..0e1367f90af5 100644
--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * The struct perf_event_attr test support. 3 * The struct perf_event_attr test support.
3 * 4 *
@@ -166,7 +167,7 @@ static int run_dir(const char *d, const char *perf)
166 snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s", 167 snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
167 d, d, perf, vcnt, v); 168 d, d, perf, vcnt, v);
168 169
169 return system(cmd); 170 return system(cmd) ? TEST_FAIL : TEST_OK;
170} 171}
171 172
172int test__attr(struct test *test __maybe_unused, int subtest __maybe_unused) 173int test__attr(struct test *test __maybe_unused, int subtest __maybe_unused)
diff --git a/tools/perf/tests/attr.py b/tools/perf/tests/attr.py
index 6bb50e82a3e3..ff9b60b99f52 100644
--- a/tools/perf/tests/attr.py
+++ b/tools/perf/tests/attr.py
@@ -1,4 +1,5 @@
1#! /usr/bin/python 1#! /usr/bin/python
2# SPDX-License-Identifier: GPL-2.0
2 3
3import os 4import os
4import sys 5import sys
@@ -237,6 +238,7 @@ class Test(object):
237 # events in result. Fail if there's not any. 238 # events in result. Fail if there's not any.
238 for exp_name, exp_event in expect.items(): 239 for exp_name, exp_event in expect.items():
239 exp_list = [] 240 exp_list = []
241 res_event = {}
240 log.debug(" matching [%s]" % exp_name) 242 log.debug(" matching [%s]" % exp_name)
241 for res_name, res_event in result.items(): 243 for res_name, res_event in result.items():
242 log.debug(" to [%s]" % res_name) 244 log.debug(" to [%s]" % res_name)
@@ -253,7 +255,10 @@ class Test(object):
253 if exp_event.optional(): 255 if exp_event.optional():
254 log.debug(" %s does not match, but is optional" % exp_name) 256 log.debug(" %s does not match, but is optional" % exp_name)
255 else: 257 else:
256 exp_event.diff(res_event) 258 if not res_event:
259 log.debug(" res_event is empty");
260 else:
261 exp_event.diff(res_event)
257 raise Fail(self, 'match failure'); 262 raise Fail(self, 'match failure');
258 263
259 match[exp_name] = exp_list 264 match[exp_name] = exp_list
diff --git a/tools/perf/tests/attr/base-record b/tools/perf/tests/attr/base-record
index 31e0b1da830b..37940665f736 100644
--- a/tools/perf/tests/attr/base-record
+++ b/tools/perf/tests/attr/base-record
@@ -23,7 +23,7 @@ comm=1
23freq=1 23freq=1
24inherit_stat=0 24inherit_stat=0
25enable_on_exec=1 25enable_on_exec=1
26task=0 26task=1
27watermark=0 27watermark=0
28precise_ip=0|1|2|3 28precise_ip=0|1|2|3
29mmap_data=0 29mmap_data=0
diff --git a/tools/perf/tests/attr/test-record-group b/tools/perf/tests/attr/test-record-group
index 6e7961f6f7a5..618ba1c17474 100644
--- a/tools/perf/tests/attr/test-record-group
+++ b/tools/perf/tests/attr/test-record-group
@@ -17,5 +17,6 @@ sample_type=327
17read_format=4 17read_format=4
18mmap=0 18mmap=0
19comm=0 19comm=0
20task=0
20enable_on_exec=0 21enable_on_exec=0
21disabled=0 22disabled=0
diff --git a/tools/perf/tests/attr/test-record-group-sampling b/tools/perf/tests/attr/test-record-group-sampling
index ef59afd6d635..f906b793196f 100644
--- a/tools/perf/tests/attr/test-record-group-sampling
+++ b/tools/perf/tests/attr/test-record-group-sampling
@@ -23,7 +23,7 @@ sample_type=343
23 23
24# PERF_FORMAT_ID | PERF_FORMAT_GROUP 24# PERF_FORMAT_ID | PERF_FORMAT_GROUP
25read_format=12 25read_format=12
26 26task=0
27mmap=0 27mmap=0
28comm=0 28comm=0
29enable_on_exec=0 29enable_on_exec=0
diff --git a/tools/perf/tests/attr/test-record-group1 b/tools/perf/tests/attr/test-record-group1
index 87a222d014d8..48e8bd12fe46 100644
--- a/tools/perf/tests/attr/test-record-group1
+++ b/tools/perf/tests/attr/test-record-group1
@@ -18,5 +18,6 @@ sample_type=327
18read_format=4 18read_format=4
19mmap=0 19mmap=0
20comm=0 20comm=0
21task=0
21enable_on_exec=0 22enable_on_exec=0
22disabled=0 23disabled=0
diff --git a/tools/perf/tests/attr/test-stat-C0 b/tools/perf/tests/attr/test-stat-C0
index 67717fe6a65d..a2c76d10b2bb 100644
--- a/tools/perf/tests/attr/test-stat-C0
+++ b/tools/perf/tests/attr/test-stat-C0
@@ -7,3 +7,4 @@ ret = 1
7# events are disabled by default when attached to cpu 7# events are disabled by default when attached to cpu
8disabled=1 8disabled=1
9enable_on_exec=0 9enable_on_exec=0
10optional=1
diff --git a/tools/perf/tests/attr/test-stat-basic b/tools/perf/tests/attr/test-stat-basic
index 74e17881f2ba..69867d049fda 100644
--- a/tools/perf/tests/attr/test-stat-basic
+++ b/tools/perf/tests/attr/test-stat-basic
@@ -4,3 +4,4 @@ args = -e cycles kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-stat] 6[event:base-stat]
7optional=1
diff --git a/tools/perf/tests/attr/test-stat-default b/tools/perf/tests/attr/test-stat-default
index e911dbd4eb47..d9e99b3f77e6 100644
--- a/tools/perf/tests/attr/test-stat-default
+++ b/tools/perf/tests/attr/test-stat-default
@@ -32,6 +32,7 @@ config=2
32fd=5 32fd=5
33type=0 33type=0
34config=0 34config=0
35optional=1
35 36
36# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND 37# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
37[event6:base-stat] 38[event6:base-stat]
@@ -52,15 +53,18 @@ optional=1
52fd=8 53fd=8
53type=0 54type=0
54config=1 55config=1
56optional=1
55 57
56# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS 58# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS
57[event9:base-stat] 59[event9:base-stat]
58fd=9 60fd=9
59type=0 61type=0
60config=4 62config=4
63optional=1
61 64
62# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES 65# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES
63[event10:base-stat] 66[event10:base-stat]
64fd=10 67fd=10
65type=0 68type=0
66config=5 69config=5
70optional=1
diff --git a/tools/perf/tests/attr/test-stat-detailed-1 b/tools/perf/tests/attr/test-stat-detailed-1
index b39270a08e74..8b04a055d154 100644
--- a/tools/perf/tests/attr/test-stat-detailed-1
+++ b/tools/perf/tests/attr/test-stat-detailed-1
@@ -33,6 +33,7 @@ config=2
33fd=5 33fd=5
34type=0 34type=0
35config=0 35config=0
36optional=1
36 37
37# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND 38# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
38[event6:base-stat] 39[event6:base-stat]
@@ -53,18 +54,21 @@ optional=1
53fd=8 54fd=8
54type=0 55type=0
55config=1 56config=1
57optional=1
56 58
57# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS 59# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS
58[event9:base-stat] 60[event9:base-stat]
59fd=9 61fd=9
60type=0 62type=0
61config=4 63config=4
64optional=1
62 65
63# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES 66# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES
64[event10:base-stat] 67[event10:base-stat]
65fd=10 68fd=10
66type=0 69type=0
67config=5 70config=5
71optional=1
68 72
69# PERF_TYPE_HW_CACHE / 73# PERF_TYPE_HW_CACHE /
70# PERF_COUNT_HW_CACHE_L1D << 0 | 74# PERF_COUNT_HW_CACHE_L1D << 0 |
@@ -74,6 +78,7 @@ config=5
74fd=11 78fd=11
75type=3 79type=3
76config=0 80config=0
81optional=1
77 82
78# PERF_TYPE_HW_CACHE / 83# PERF_TYPE_HW_CACHE /
79# PERF_COUNT_HW_CACHE_L1D << 0 | 84# PERF_COUNT_HW_CACHE_L1D << 0 |
@@ -83,6 +88,7 @@ config=0
83fd=12 88fd=12
84type=3 89type=3
85config=65536 90config=65536
91optional=1
86 92
87# PERF_TYPE_HW_CACHE / 93# PERF_TYPE_HW_CACHE /
88# PERF_COUNT_HW_CACHE_LL << 0 | 94# PERF_COUNT_HW_CACHE_LL << 0 |
@@ -92,6 +98,7 @@ config=65536
92fd=13 98fd=13
93type=3 99type=3
94config=2 100config=2
101optional=1
95 102
96# PERF_TYPE_HW_CACHE, 103# PERF_TYPE_HW_CACHE,
97# PERF_COUNT_HW_CACHE_LL << 0 | 104# PERF_COUNT_HW_CACHE_LL << 0 |
@@ -101,3 +108,4 @@ config=2
101fd=14 108fd=14
102type=3 109type=3
103config=65538 110config=65538
111optional=1
diff --git a/tools/perf/tests/attr/test-stat-detailed-2 b/tools/perf/tests/attr/test-stat-detailed-2
index 45f8e6ea34f8..4fca9f1bfbf8 100644
--- a/tools/perf/tests/attr/test-stat-detailed-2
+++ b/tools/perf/tests/attr/test-stat-detailed-2
@@ -33,6 +33,7 @@ config=2
33fd=5 33fd=5
34type=0 34type=0
35config=0 35config=0
36optional=1
36 37
37# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND 38# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
38[event6:base-stat] 39[event6:base-stat]
@@ -53,18 +54,21 @@ optional=1
53fd=8 54fd=8
54type=0 55type=0
55config=1 56config=1
57optional=1
56 58
57# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS 59# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS
58[event9:base-stat] 60[event9:base-stat]
59fd=9 61fd=9
60type=0 62type=0
61config=4 63config=4
64optional=1
62 65
63# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES 66# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES
64[event10:base-stat] 67[event10:base-stat]
65fd=10 68fd=10
66type=0 69type=0
67config=5 70config=5
71optional=1
68 72
69# PERF_TYPE_HW_CACHE / 73# PERF_TYPE_HW_CACHE /
70# PERF_COUNT_HW_CACHE_L1D << 0 | 74# PERF_COUNT_HW_CACHE_L1D << 0 |
@@ -74,6 +78,7 @@ config=5
74fd=11 78fd=11
75type=3 79type=3
76config=0 80config=0
81optional=1
77 82
78# PERF_TYPE_HW_CACHE / 83# PERF_TYPE_HW_CACHE /
79# PERF_COUNT_HW_CACHE_L1D << 0 | 84# PERF_COUNT_HW_CACHE_L1D << 0 |
@@ -83,6 +88,7 @@ config=0
83fd=12 88fd=12
84type=3 89type=3
85config=65536 90config=65536
91optional=1
86 92
87# PERF_TYPE_HW_CACHE / 93# PERF_TYPE_HW_CACHE /
88# PERF_COUNT_HW_CACHE_LL << 0 | 94# PERF_COUNT_HW_CACHE_LL << 0 |
@@ -92,6 +98,7 @@ config=65536
92fd=13 98fd=13
93type=3 99type=3
94config=2 100config=2
101optional=1
95 102
96# PERF_TYPE_HW_CACHE, 103# PERF_TYPE_HW_CACHE,
97# PERF_COUNT_HW_CACHE_LL << 0 | 104# PERF_COUNT_HW_CACHE_LL << 0 |
@@ -101,6 +108,7 @@ config=2
101fd=14 108fd=14
102type=3 109type=3
103config=65538 110config=65538
111optional=1
104 112
105# PERF_TYPE_HW_CACHE, 113# PERF_TYPE_HW_CACHE,
106# PERF_COUNT_HW_CACHE_L1I << 0 | 114# PERF_COUNT_HW_CACHE_L1I << 0 |
@@ -120,6 +128,7 @@ optional=1
120fd=16 128fd=16
121type=3 129type=3
122config=65537 130config=65537
131optional=1
123 132
124# PERF_TYPE_HW_CACHE, 133# PERF_TYPE_HW_CACHE,
125# PERF_COUNT_HW_CACHE_DTLB << 0 | 134# PERF_COUNT_HW_CACHE_DTLB << 0 |
@@ -129,6 +138,7 @@ config=65537
129fd=17 138fd=17
130type=3 139type=3
131config=3 140config=3
141optional=1
132 142
133# PERF_TYPE_HW_CACHE, 143# PERF_TYPE_HW_CACHE,
134# PERF_COUNT_HW_CACHE_DTLB << 0 | 144# PERF_COUNT_HW_CACHE_DTLB << 0 |
@@ -138,6 +148,7 @@ config=3
138fd=18 148fd=18
139type=3 149type=3
140config=65539 150config=65539
151optional=1
141 152
142# PERF_TYPE_HW_CACHE, 153# PERF_TYPE_HW_CACHE,
143# PERF_COUNT_HW_CACHE_ITLB << 0 | 154# PERF_COUNT_HW_CACHE_ITLB << 0 |
@@ -147,6 +158,7 @@ config=65539
147fd=19 158fd=19
148type=3 159type=3
149config=4 160config=4
161optional=1
150 162
151# PERF_TYPE_HW_CACHE, 163# PERF_TYPE_HW_CACHE,
152# PERF_COUNT_HW_CACHE_ITLB << 0 | 164# PERF_COUNT_HW_CACHE_ITLB << 0 |
@@ -156,3 +168,4 @@ config=4
156fd=20 168fd=20
157type=3 169type=3
158config=65540 170config=65540
171optional=1
diff --git a/tools/perf/tests/attr/test-stat-detailed-3 b/tools/perf/tests/attr/test-stat-detailed-3
index 30ae0fb7a3fd..4bb58e1c82a6 100644
--- a/tools/perf/tests/attr/test-stat-detailed-3
+++ b/tools/perf/tests/attr/test-stat-detailed-3
@@ -33,6 +33,7 @@ config=2
33fd=5 33fd=5
34type=0 34type=0
35config=0 35config=0
36optional=1
36 37
37# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND 38# PERF_TYPE_HARDWARE / PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
38[event6:base-stat] 39[event6:base-stat]
@@ -53,18 +54,21 @@ optional=1
53fd=8 54fd=8
54type=0 55type=0
55config=1 56config=1
57optional=1
56 58
57# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS 59# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_INSTRUCTIONS
58[event9:base-stat] 60[event9:base-stat]
59fd=9 61fd=9
60type=0 62type=0
61config=4 63config=4
64optional=1
62 65
63# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES 66# PERF_TYPE_HARDWARE / PERF_COUNT_HW_BRANCH_MISSES
64[event10:base-stat] 67[event10:base-stat]
65fd=10 68fd=10
66type=0 69type=0
67config=5 70config=5
71optional=1
68 72
69# PERF_TYPE_HW_CACHE / 73# PERF_TYPE_HW_CACHE /
70# PERF_COUNT_HW_CACHE_L1D << 0 | 74# PERF_COUNT_HW_CACHE_L1D << 0 |
@@ -74,6 +78,7 @@ config=5
74fd=11 78fd=11
75type=3 79type=3
76config=0 80config=0
81optional=1
77 82
78# PERF_TYPE_HW_CACHE / 83# PERF_TYPE_HW_CACHE /
79# PERF_COUNT_HW_CACHE_L1D << 0 | 84# PERF_COUNT_HW_CACHE_L1D << 0 |
@@ -83,6 +88,7 @@ config=0
83fd=12 88fd=12
84type=3 89type=3
85config=65536 90config=65536
91optional=1
86 92
87# PERF_TYPE_HW_CACHE / 93# PERF_TYPE_HW_CACHE /
88# PERF_COUNT_HW_CACHE_LL << 0 | 94# PERF_COUNT_HW_CACHE_LL << 0 |
@@ -92,6 +98,7 @@ config=65536
92fd=13 98fd=13
93type=3 99type=3
94config=2 100config=2
101optional=1
95 102
96# PERF_TYPE_HW_CACHE, 103# PERF_TYPE_HW_CACHE,
97# PERF_COUNT_HW_CACHE_LL << 0 | 104# PERF_COUNT_HW_CACHE_LL << 0 |
@@ -101,6 +108,7 @@ config=2
101fd=14 108fd=14
102type=3 109type=3
103config=65538 110config=65538
111optional=1
104 112
105# PERF_TYPE_HW_CACHE, 113# PERF_TYPE_HW_CACHE,
106# PERF_COUNT_HW_CACHE_L1I << 0 | 114# PERF_COUNT_HW_CACHE_L1I << 0 |
@@ -120,6 +128,7 @@ optional=1
120fd=16 128fd=16
121type=3 129type=3
122config=65537 130config=65537
131optional=1
123 132
124# PERF_TYPE_HW_CACHE, 133# PERF_TYPE_HW_CACHE,
125# PERF_COUNT_HW_CACHE_DTLB << 0 | 134# PERF_COUNT_HW_CACHE_DTLB << 0 |
@@ -129,6 +138,7 @@ config=65537
129fd=17 138fd=17
130type=3 139type=3
131config=3 140config=3
141optional=1
132 142
133# PERF_TYPE_HW_CACHE, 143# PERF_TYPE_HW_CACHE,
134# PERF_COUNT_HW_CACHE_DTLB << 0 | 144# PERF_COUNT_HW_CACHE_DTLB << 0 |
@@ -138,6 +148,7 @@ config=3
138fd=18 148fd=18
139type=3 149type=3
140config=65539 150config=65539
151optional=1
141 152
142# PERF_TYPE_HW_CACHE, 153# PERF_TYPE_HW_CACHE,
143# PERF_COUNT_HW_CACHE_ITLB << 0 | 154# PERF_COUNT_HW_CACHE_ITLB << 0 |
@@ -147,6 +158,7 @@ config=65539
147fd=19 158fd=19
148type=3 159type=3
149config=4 160config=4
161optional=1
150 162
151# PERF_TYPE_HW_CACHE, 163# PERF_TYPE_HW_CACHE,
152# PERF_COUNT_HW_CACHE_ITLB << 0 | 164# PERF_COUNT_HW_CACHE_ITLB << 0 |
@@ -156,6 +168,7 @@ config=4
156fd=20 168fd=20
157type=3 169type=3
158config=65540 170config=65540
171optional=1
159 172
160# PERF_TYPE_HW_CACHE, 173# PERF_TYPE_HW_CACHE,
161# PERF_COUNT_HW_CACHE_L1D << 0 | 174# PERF_COUNT_HW_CACHE_L1D << 0 |
diff --git a/tools/perf/tests/attr/test-stat-group b/tools/perf/tests/attr/test-stat-group
index fdc1596a8862..e15d6946e9b3 100644
--- a/tools/perf/tests/attr/test-stat-group
+++ b/tools/perf/tests/attr/test-stat-group
@@ -6,6 +6,7 @@ ret = 1
6[event-1:base-stat] 6[event-1:base-stat]
7fd=1 7fd=1
8group_fd=-1 8group_fd=-1
9read_format=3|15
9 10
10[event-2:base-stat] 11[event-2:base-stat]
11fd=2 12fd=2
@@ -13,3 +14,4 @@ group_fd=1
13config=1 14config=1
14disabled=0 15disabled=0
15enable_on_exec=0 16enable_on_exec=0
17read_format=3|15
diff --git a/tools/perf/tests/attr/test-stat-group1 b/tools/perf/tests/attr/test-stat-group1
index 2a1f86e4a904..1746751123dc 100644
--- a/tools/perf/tests/attr/test-stat-group1
+++ b/tools/perf/tests/attr/test-stat-group1
@@ -6,6 +6,7 @@ ret = 1
6[event-1:base-stat] 6[event-1:base-stat]
7fd=1 7fd=1
8group_fd=-1 8group_fd=-1
9read_format=3|15
9 10
10[event-2:base-stat] 11[event-2:base-stat]
11fd=2 12fd=2
@@ -13,3 +14,4 @@ group_fd=1
13config=1 14config=1
14disabled=0 15disabled=0
15enable_on_exec=0 16enable_on_exec=0
17read_format=3|15
diff --git a/tools/perf/tests/attr/test-stat-no-inherit b/tools/perf/tests/attr/test-stat-no-inherit
index d54b2a1e3e28..924fbb9300d1 100644
--- a/tools/perf/tests/attr/test-stat-no-inherit
+++ b/tools/perf/tests/attr/test-stat-no-inherit
@@ -5,3 +5,4 @@ ret = 1
5 5
6[event:base-stat] 6[event:base-stat]
7inherit=0 7inherit=0
8optional=1
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index d233ad336463..71b9a0b613d2 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Test backward bit in event attribute, read ring buffer from end to 3 * Test backward bit in event attribute, read ring buffer from end to
3 * beginning 4 * beginning
diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c
index 0d7c06584905..47bedf25ba69 100644
--- a/tools/perf/tests/bitmap.c
+++ b/tools/perf/tests/bitmap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/bitmap.h> 3#include <linux/bitmap.h>
3#include "tests.h" 4#include "tests.h"
diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c
index 97937e1bc53a..335b695f4970 100644
--- a/tools/perf/tests/bp_signal.c
+++ b/tools/perf/tests/bp_signal.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Inspired by breakpoint overflow test done by 3 * Inspired by breakpoint overflow test done by
3 * Vince Weaver <vincent.weaver@maine.edu> for perf_event_tests 4 * Vince Weaver <vincent.weaver@maine.edu> for perf_event_tests
diff --git a/tools/perf/tests/bp_signal_overflow.c b/tools/perf/tests/bp_signal_overflow.c
index 61ecd8021f49..ca962559e845 100644
--- a/tools/perf/tests/bp_signal_overflow.c
+++ b/tools/perf/tests/bp_signal_overflow.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Originally done by Vince Weaver <vincent.weaver@maine.edu> for 3 * Originally done by Vince Weaver <vincent.weaver@maine.edu> for
3 * perf_event_tests (git://github.com/deater/perf_event_tests) 4 * perf_event_tests (git://github.com/deater/perf_event_tests)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 377bea009163..766573e236e4 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -1,8 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * builtin-test.c 3 * builtin-test.c
3 * 4 *
4 * Builtin regression testing command: ever growing number of sanity tests 5 * Builtin regression testing command: ever growing number of sanity tests
5 */ 6 */
7#include <fcntl.h>
6#include <errno.h> 8#include <errno.h>
7#include <unistd.h> 9#include <unistd.h>
8#include <string.h> 10#include <string.h>
diff --git a/tools/perf/tests/clang.c b/tools/perf/tests/clang.c
index c60ec916f0f2..f45fe11dcf50 100644
--- a/tools/perf/tests/clang.c
+++ b/tools/perf/tests/clang.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "tests.h" 2#include "tests.h"
2#include "debug.h" 3#include "debug.h"
3#include "util.h" 4#include "util.h"
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 466a462b26d1..fcc8984bc329 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include <linux/types.h> 4#include <linux/types.h>
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
index 199702252270..e78b897677bd 100644
--- a/tools/perf/tests/cpumap.c
+++ b/tools/perf/tests/cpumap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "tests.h" 2#include "tests.h"
2#include <stdio.h> 3#include <stdio.h>
3#include "cpumap.h" 4#include "cpumap.h"
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index 30aead42d136..7f6c52021e41 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <dirent.h> 2#include <dirent.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 9ba1d216a89f..ac40e05bcab4 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/types.h> 3#include <linux/types.h>
3#include <inttypes.h> 4#include <inttypes.h>
diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index b82b981c3259..1a2686f1fcf0 100644
--- a/tools/perf/tests/event-times.c
+++ b/tools/perf/tests/event-times.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <errno.h> 3#include <errno.h>
3#include <inttypes.h> 4#include <inttypes.h>
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c
index 9484da2ec6b4..f14dcd613438 100644
--- a/tools/perf/tests/event_update.c
+++ b/tools/perf/tests/event_update.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include "evlist.h" 3#include "evlist.h"
3#include "evsel.h" 4#include "evsel.h"
diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c
index d32759b6e38a..a104728ebf25 100644
--- a/tools/perf/tests/evsel-roundtrip-name.c
+++ b/tools/perf/tests/evsel-roundtrip-name.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "evlist.h" 2#include "evlist.h"
2#include "evsel.h" 3#include "evsel.h"
3#include "parse-events.h" 4#include "parse-events.h"
diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c
index 5fc906d26c5c..699561fa512c 100644
--- a/tools/perf/tests/evsel-tp-sched.c
+++ b/tools/perf/tests/evsel-tp-sched.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/err.h> 2#include <linux/err.h>
2#include <traceevent/event-parse.h> 3#include <traceevent/event-parse.h>
3#include "evsel.h" 4#include "evsel.h"
diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c
index cb251bf523e7..01f0706995a9 100644
--- a/tools/perf/tests/expr.c
+++ b/tools/perf/tests/expr.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "util/debug.h" 2#include "util/debug.h"
2#include "util/expr.h" 3#include "util/expr.h"
3#include "tests.h" 4#include "tests.h"
diff --git a/tools/perf/tests/fdarray.c b/tools/perf/tests/fdarray.c
index 7d3a9e2ff897..c7c81c4a5b2b 100644
--- a/tools/perf/tests/fdarray.c
+++ b/tools/perf/tests/fdarray.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <api/fd/array.h> 2#include <api/fd/array.h>
2#include <poll.h> 3#include <poll.h>
3#include "util/debug.h" 4#include "util/debug.h"
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index 00b8dc50f3db..f7c5b613d667 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include "perf.h" 3#include "perf.h"
3#include "util/debug.h" 4#include "util/debug.h"
diff --git a/tools/perf/tests/hists_common.h b/tools/perf/tests/hists_common.h
index 888254e8665c..a2de0ff0ce3a 100644
--- a/tools/perf/tests/hists_common.h
+++ b/tools/perf/tests/hists_common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_TESTS__HISTS_COMMON_H__ 2#ifndef __PERF_TESTS__HISTS_COMMON_H__
2#define __PERF_TESTS__HISTS_COMMON_H__ 3#define __PERF_TESTS__HISTS_COMMON_H__
3 4
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index 8d19c0200cb7..65fe02bebbee 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "perf.h" 2#include "perf.h"
2#include "util/debug.h" 3#include "util/debug.h"
3#include "util/event.h" 4#include "util/event.h"
diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c
index 755ca551b810..1c5bedab3c2c 100644
--- a/tools/perf/tests/hists_filter.c
+++ b/tools/perf/tests/hists_filter.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "perf.h" 2#include "perf.h"
2#include "util/debug.h" 3#include "util/debug.h"
3#include "util/symbol.h" 4#include "util/symbol.h"
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 073c9c2856bc..9a9d06cb0222 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "perf.h" 2#include "perf.h"
2#include "tests.h" 3#include "tests.h"
3#include "debug.h" 4#include "debug.h"
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c
index 282d62eaebe2..faacb4f41460 100644
--- a/tools/perf/tests/hists_output.c
+++ b/tools/perf/tests/hists_output.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "perf.h" 2#include "perf.h"
2#include "util/debug.h" 3#include "util/debug.h"
3#include "util/event.h" 4#include "util/event.h"
diff --git a/tools/perf/tests/is_printable_array.c b/tools/perf/tests/is_printable_array.c
index 38f765767587..9c7b3baca4fe 100644
--- a/tools/perf/tests/is_printable_array.c
+++ b/tools/perf/tests/is_printable_array.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include "tests.h" 4#include "tests.h"
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 739428603b71..842d33637a18 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/types.h> 2#include <linux/types.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <sys/prctl.h> 4#include <sys/prctl.h>
diff --git a/tools/perf/tests/kmod-path.c b/tools/perf/tests/kmod-path.c
index 8b9d4ba06c0e..8e57d46109de 100644
--- a/tools/perf/tests/kmod-path.c
+++ b/tools/perf/tests/kmod-path.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdbool.h> 2#include <stdbool.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include "tests.h" 4#include "tests.h"
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 5187b50dbafe..a039f93199e5 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <bpf/libbpf.h> 3#include <bpf/libbpf.h>
3#include <util/llvm-utils.h> 4#include <util/llvm-utils.h>
diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h
index b83571758d83..f68b0d9b8ae2 100644
--- a/tools/perf/tests/llvm.h
+++ b/tools/perf/tests/llvm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_TEST_LLVM_H 2#ifndef PERF_TEST_LLVM_H
2#define PERF_TEST_LLVM_H 3#define PERF_TEST_LLVM_H
3 4
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index bc8a70ee46d8..5a8bf318f8a7 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3/* For the CLR_() macros */ 4/* For the CLR_() macros */
diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c
index f94a4196e7c9..868d82b501f4 100644
--- a/tools/perf/tests/mmap-thread-lookup.c
+++ b/tools/perf/tests/mmap-thread-lookup.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <sys/syscall.h> 4#include <sys/syscall.h>
@@ -131,7 +132,7 @@ static int synth_all(struct machine *machine)
131{ 132{
132 return perf_event__synthesize_threads(NULL, 133 return perf_event__synthesize_threads(NULL,
133 perf_event__process, 134 perf_event__process,
134 machine, 0, 500); 135 machine, 0, 500, 1);
135} 136}
136 137
137static int synth_process(struct machine *machine) 138static int synth_process(struct machine *machine)
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c
index 9cf1c35f2ad0..c531e6deb104 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3/* For the CPU_* macros */ 4/* For the CPU_* macros */
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index b6ee1c41f45d..d9619d265314 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/err.h> 2#include <linux/err.h>
2#include "perf.h" 3#include "perf.h"
3#include "evlist.h" 4#include "evlist.h"
diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c
index 9dc5c5d37553..00cd63f90b92 100644
--- a/tools/perf/tests/openat-syscall.c
+++ b/tools/perf/tests/openat-syscall.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <api/fs/tracing_path.h> 4#include <api/fs/tracing_path.h>
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 0f0b025faa4b..f0679613bd18 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "parse-events.h" 2#include "parse-events.h"
2#include "evsel.h" 3#include "evsel.h"
3#include "evlist.h" 4#include "evlist.h"
diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c
index 91867dcc39f0..2196d1497c0c 100644
--- a/tools/perf/tests/parse-no-sample-id-all.c
+++ b/tools/perf/tests/parse-no-sample-id-all.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/kernel.h> 2#include <linux/kernel.h>
2#include <linux/types.h> 3#include <linux/types.h>
3#include <stddef.h> 4#include <stddef.h>
diff --git a/tools/perf/tests/perf-hooks.c b/tools/perf/tests/perf-hooks.c
index bf2517d6de70..a693bcf017ea 100644
--- a/tools/perf/tests/perf-hooks.c
+++ b/tools/perf/tests/perf-hooks.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <signal.h> 2#include <signal.h>
2#include <stdlib.h> 3#include <stdlib.h>
3 4
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 19b650064b70..c34904d37705 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3/* For the CLR_() macros */ 4/* For the CLR_() macros */
diff --git a/tools/perf/tests/perf-targz-src-pkg b/tools/perf/tests/perf-targz-src-pkg
index f2d9c5fe58e0..fae26b1cf08f 100755
--- a/tools/perf/tests/perf-targz-src-pkg
+++ b/tools/perf/tests/perf-targz-src-pkg
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Test one of the main kernel Makefile targets to generate a perf sources tarball 3# Test one of the main kernel Makefile targets to generate a perf sources tarball
3# suitable for build outside the full kernel sources. 4# suitable for build outside the full kernel sources.
4# 5#
diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
index 9f7f589f9c54..9abca267afa9 100644
--- a/tools/perf/tests/pmu.c
+++ b/tools/perf/tests/pmu.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "parse-events.h" 2#include "parse-events.h"
2#include "pmu.h" 3#include "pmu.h"
3#include "util.h" 4#include "util.h"
diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c
index 598a7e058ad4..5d2df65ada6a 100644
--- a/tools/perf/tests/python-use.c
+++ b/tools/perf/tests/python-use.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Just test if we can load the python binding. 3 * Just test if we can load the python binding.
3 */ 4 */
diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c
index c3858487159d..3ec6302b6498 100644
--- a/tools/perf/tests/sample-parsing.c
+++ b/tools/perf/tests/sample-parsing.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdbool.h> 2#include <stdbool.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/tools/perf/tests/sdt.c b/tools/perf/tests/sdt.c
index a9903d9b8bc2..5059452d27dd 100644
--- a/tools/perf/tests/sdt.c
+++ b/tools/perf/tests/sdt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <sys/epoll.h> 4#include <sys/epoll.h>
diff --git a/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh b/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh
index 462fc755092e..7a84d73324e3 100755
--- a/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh
+++ b/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh
@@ -10,6 +10,9 @@
10 10
11. $(dirname $0)/lib/probe.sh 11. $(dirname $0)/lib/probe.sh
12 12
13ld=$(realpath /lib64/ld*.so.* | uniq)
14libc=$(echo $ld | sed 's/ld/libc/g')
15
13trace_libc_inet_pton_backtrace() { 16trace_libc_inet_pton_backtrace() {
14 idx=0 17 idx=0
15 expected[0]="PING.*bytes" 18 expected[0]="PING.*bytes"
@@ -18,8 +21,8 @@ trace_libc_inet_pton_backtrace() {
18 expected[3]=".*packets transmitted.*" 21 expected[3]=".*packets transmitted.*"
19 expected[4]="rtt min.*" 22 expected[4]="rtt min.*"
20 expected[5]="[0-9]+\.[0-9]+[[:space:]]+probe_libc:inet_pton:\([[:xdigit:]]+\)" 23 expected[5]="[0-9]+\.[0-9]+[[:space:]]+probe_libc:inet_pton:\([[:xdigit:]]+\)"
21 expected[6]=".*inet_pton[[:space:]]\(/usr/lib.*/libc-[0-9]+\.[0-9]+\.so\)$" 24 expected[6]=".*inet_pton[[:space:]]\($libc\)$"
22 expected[7]="getaddrinfo[[:space:]]\(/usr/lib.*/libc-[0-9]+\.[0-9]+\.so\)$" 25 expected[7]="getaddrinfo[[:space:]]\($libc\)$"
23 expected[8]=".*\(.*/bin/ping.*\)$" 26 expected[8]=".*\(.*/bin/ping.*\)$"
24 27
25 perf trace --no-syscalls -e probe_libc:inet_pton/max-stack=3/ ping -6 -c 1 ::1 2>&1 | grep -v ^$ | while read line ; do 28 perf trace --no-syscalls -e probe_libc:inet_pton/max-stack=3/ ping -6 -c 1 ::1 2>&1 | grep -v ^$ | while read line ; do
@@ -35,7 +38,7 @@ trace_libc_inet_pton_backtrace() {
35} 38}
36 39
37skip_if_no_perf_probe && \ 40skip_if_no_perf_probe && \
38perf probe -q /lib64/libc-*.so inet_pton && \ 41perf probe -q $libc inet_pton && \
39trace_libc_inet_pton_backtrace 42trace_libc_inet_pton_backtrace
40err=$? 43err=$?
41rm -f ${file} 44rm -f ${file}
diff --git a/tools/perf/tests/stat.c b/tools/perf/tests/stat.c
index 7f988a939036..94250024684a 100644
--- a/tools/perf/tests/stat.c
+++ b/tools/perf/tests/stat.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include "event.h" 3#include "event.h"
3#include "tests.h" 4#include "tests.h"
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index d88511f6072c..725a196991a8 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 2acd78555192..7d3f4bf9534f 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/time.h> 2#include <sys/time.h>
2#include <sys/prctl.h> 3#include <sys/prctl.h>
3#include <errno.h> 4#include <errno.h>
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index f0881d0dd9c9..bc4a7344e274 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "evlist.h" 2#include "evlist.h"
2#include "evsel.h" 3#include "evsel.h"
3#include "thread_map.h" 4#include "thread_map.h"
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 921412a6a880..2862b80bc288 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef TESTS_H 2#ifndef TESTS_H
2#define TESTS_H 3#define TESTS_H
3 4
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
index b3423c744f46..dbcb6a19b375 100644
--- a/tools/perf/tests/thread-map.c
+++ b/tools/perf/tests/thread-map.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <sys/types.h> 3#include <sys/types.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/perf/tests/thread-mg-share.c b/tools/perf/tests/thread-mg-share.c
index b9c7f58db6c4..b1d1bbafe7ae 100644
--- a/tools/perf/tests/thread-mg-share.c
+++ b/tools/perf/tests/thread-mg-share.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "tests.h" 2#include "tests.h"
2#include "machine.h" 3#include "machine.h"
3#include "thread.h" 4#include "thread.h"
diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c
index 19b0561fd6f6..17cb1bb3448c 100644
--- a/tools/perf/tests/topology.c
+++ b/tools/perf/tests/topology.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <stdio.h> 4#include <stdio.h>
@@ -29,12 +30,14 @@ static int get_temp(char *path)
29static int session_write_header(char *path) 30static int session_write_header(char *path)
30{ 31{
31 struct perf_session *session; 32 struct perf_session *session;
32 struct perf_data_file file = { 33 struct perf_data data = {
33 .path = path, 34 .file = {
34 .mode = PERF_DATA_MODE_WRITE, 35 .path = path,
36 },
37 .mode = PERF_DATA_MODE_WRITE,
35 }; 38 };
36 39
37 session = perf_session__new(&file, false, NULL); 40 session = perf_session__new(&data, false, NULL);
38 TEST_ASSERT_VAL("can't get session", session); 41 TEST_ASSERT_VAL("can't get session", session);
39 42
40 session->evlist = perf_evlist__new_default(); 43 session->evlist = perf_evlist__new_default();
@@ -46,7 +49,7 @@ static int session_write_header(char *path)
46 session->header.data_size += DATA_SIZE; 49 session->header.data_size += DATA_SIZE;
47 50
48 TEST_ASSERT_VAL("failed to write header", 51 TEST_ASSERT_VAL("failed to write header",
49 !perf_session__write_header(session, session->evlist, file.fd, true)); 52 !perf_session__write_header(session, session->evlist, data.file.fd, true));
50 53
51 perf_session__delete(session); 54 perf_session__delete(session);
52 55
@@ -56,13 +59,15 @@ static int session_write_header(char *path)
56static int check_cpu_topology(char *path, struct cpu_map *map) 59static int check_cpu_topology(char *path, struct cpu_map *map)
57{ 60{
58 struct perf_session *session; 61 struct perf_session *session;
59 struct perf_data_file file = { 62 struct perf_data data = {
60 .path = path, 63 .file = {
61 .mode = PERF_DATA_MODE_READ, 64 .path = path,
65 },
66 .mode = PERF_DATA_MODE_READ,
62 }; 67 };
63 int i; 68 int i;
64 69
65 session = perf_session__new(&file, false, NULL); 70 session = perf_session__new(&data, false, NULL);
66 TEST_ASSERT_VAL("can't get session", session); 71 TEST_ASSERT_VAL("can't get session", session);
67 72
68 for (i = 0; i < session->header.env.nr_cpus_avail; i++) { 73 for (i = 0; i < session->header.env.nr_cpus_avail; i++) {
diff --git a/tools/perf/tests/unit_number__scnprintf.c b/tools/perf/tests/unit_number__scnprintf.c
index 15cd1cf8c129..2bb8cb0039c1 100644
--- a/tools/perf/tests/unit_number__scnprintf.c
+++ b/tools/perf/tests/unit_number__scnprintf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include <linux/compiler.h> 3#include <linux/compiler.h>
3#include <linux/types.h> 4#include <linux/types.h>
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index 86cb8868f67f..f6789fb029d6 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/rbtree.h> 3#include <linux/rbtree.h>
3#include <inttypes.h> 4#include <inttypes.h>
diff --git a/tools/perf/trace/beauty/Build b/tools/perf/trace/beauty/Build
index 175d633c6b49..066bbf0f4a74 100644
--- a/tools/perf/trace/beauty/Build
+++ b/tools/perf/trace/beauty/Build
@@ -3,5 +3,7 @@ libperf-y += fcntl.o
3ifeq ($(SRCARCH),$(filter $(SRCARCH),x86)) 3ifeq ($(SRCARCH),$(filter $(SRCARCH),x86))
4libperf-y += ioctl.o 4libperf-y += ioctl.o
5endif 5endif
6libperf-y += kcmp.o
6libperf-y += pkey_alloc.o 7libperf-y += pkey_alloc.o
8libperf-y += prctl.o
7libperf-y += statx.o 9libperf-y += statx.o
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 4b58581a6053..a6dfd04beaee 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -1,8 +1,10 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_TRACE_BEAUTY_H 2#ifndef _PERF_TRACE_BEAUTY_H
2#define _PERF_TRACE_BEAUTY_H 3#define _PERF_TRACE_BEAUTY_H
3 4
4#include <linux/kernel.h> 5#include <linux/kernel.h>
5#include <linux/types.h> 6#include <linux/types.h>
7#include <sys/types.h>
6 8
7struct strarray { 9struct strarray {
8 int offset; 10 int offset;
@@ -26,6 +28,8 @@ size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const cha
26struct trace; 28struct trace;
27struct thread; 29struct thread;
28 30
31size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size);
32
29/** 33/**
30 * @val: value of syscall argument being formatted 34 * @val: value of syscall argument being formatted
31 * @args: All the args, use syscall_args__val(arg, nth) to access one 35 * @args: All the args, use syscall_args__val(arg, nth) to access one
@@ -78,12 +82,27 @@ size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_ar
78size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg); 82size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg);
79#define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd 83#define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd
80 84
85size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg);
86#define SCA_KCMP_TYPE syscall_arg__scnprintf_kcmp_type
87
88size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg);
89#define SCA_KCMP_IDX syscall_arg__scnprintf_kcmp_idx
90
81size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg); 91size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg);
82#define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights 92#define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights
83 93
84size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg); 94size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg);
85#define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags 95#define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags
86 96
97size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg);
98#define SCA_PRCTL_OPTION syscall_arg__scnprintf_prctl_option
99
100size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg);
101#define SCA_PRCTL_ARG2 syscall_arg__scnprintf_prctl_arg2
102
103size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg);
104#define SCA_PRCTL_ARG3 syscall_arg__scnprintf_prctl_arg3
105
87size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg); 106size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg);
88#define SCA_STATX_FLAGS syscall_arg__scnprintf_statx_flags 107#define SCA_STATX_FLAGS syscall_arg__scnprintf_statx_flags
89 108
diff --git a/tools/perf/trace/beauty/eventfd.c b/tools/perf/trace/beauty/eventfd.c
index b08f21eb6f4d..5d6a477a6400 100644
--- a/tools/perf/trace/beauty/eventfd.c
+++ b/tools/perf/trace/beauty/eventfd.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#ifndef EFD_SEMAPHORE 2#ifndef EFD_SEMAPHORE
2#define EFD_SEMAPHORE 1 3#define EFD_SEMAPHORE 1
3#endif 4#endif
diff --git a/tools/perf/trace/beauty/flock.c b/tools/perf/trace/beauty/flock.c
index 74613703a14e..f9707f57566c 100644
--- a/tools/perf/trace/beauty/flock.c
+++ b/tools/perf/trace/beauty/flock.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <fcntl.h> 2#include <fcntl.h>
2 3
3#ifndef LOCK_MAND 4#ifndef LOCK_MAND
diff --git a/tools/perf/trace/beauty/futex_op.c b/tools/perf/trace/beauty/futex_op.c
index bfd3359b09b6..61850fbc85ff 100644
--- a/tools/perf/trace/beauty/futex_op.c
+++ b/tools/perf/trace/beauty/futex_op.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/futex.h> 2#include <linux/futex.h>
2 3
3#ifndef FUTEX_WAIT_BITSET 4#ifndef FUTEX_WAIT_BITSET
diff --git a/tools/perf/trace/beauty/kcmp.c b/tools/perf/trace/beauty/kcmp.c
new file mode 100644
index 000000000000..f62040eb9d5c
--- /dev/null
+++ b/tools/perf/trace/beauty/kcmp.c
@@ -0,0 +1,44 @@
1/*
2 * trace/beauty/kcmp.c
3 *
4 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
5 *
6 * Released under the GPL v2. (and only v2, not any later version)
7 */
8
9#include "trace/beauty/beauty.h"
10#include <linux/kernel.h>
11#include <sys/types.h>
12#include <machine.h>
13#include <uapi/linux/kcmp.h>
14
15#include "trace/beauty/generated/kcmp_type_array.c"
16
17size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg)
18{
19 unsigned long fd = arg->val;
20 int type = syscall_arg__val(arg, 2);
21 pid_t pid;
22
23 if (type != KCMP_FILE)
24 return syscall_arg__scnprintf_long(bf, size, arg);
25
26 pid = syscall_arg__val(arg, arg->idx == 3 ? 0 : 1); /* idx1 -> pid1, idx2 -> pid2 */
27 return pid__scnprintf_fd(arg->trace, pid, fd, bf, size);
28}
29
30static size_t kcmp__scnprintf_type(int type, char *bf, size_t size)
31{
32 static DEFINE_STRARRAY(kcmp_types);
33 return strarray__scnprintf(&strarray__kcmp_types, bf, size, "%d", type);
34}
35
36size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg)
37{
38 unsigned long type = arg->val;
39
40 if (type != KCMP_FILE)
41 arg->mask |= (1 << 3) | (1 << 4); /* Ignore idx1 and idx2 */
42
43 return kcmp__scnprintf_type(type, bf, size);
44}
diff --git a/tools/perf/trace/beauty/kcmp_type.sh b/tools/perf/trace/beauty/kcmp_type.sh
new file mode 100755
index 000000000000..40d063b8c082
--- /dev/null
+++ b/tools/perf/trace/beauty/kcmp_type.sh
@@ -0,0 +1,10 @@
1#!/bin/sh
2
3header_dir=$1
4
5printf "static const char *kcmp_types[] = {\n"
6regex='^[[:space:]]+(KCMP_(\w+)),'
7egrep $regex ${header_dir}/kcmp.h | grep -v KCMP_TYPES, | \
8 sed -r "s/$regex/\1 \2/g" | \
9 xargs printf "\t[%s]\t= \"%s\",\n"
10printf "};\n"
diff --git a/tools/perf/trace/beauty/madvise_behavior.sh b/tools/perf/trace/beauty/madvise_behavior.sh
new file mode 100755
index 000000000000..60ef8640ee70
--- /dev/null
+++ b/tools/perf/trace/beauty/madvise_behavior.sh
@@ -0,0 +1,10 @@
1#!/bin/sh
2
3header_dir=$1
4
5printf "static const char *madvise_advices[] = {\n"
6regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MADV_([[:alnum:]_]+)[[:space:]]+([[:digit:]]+)[[:space:]]*.*'
7egrep $regex ${header_dir}/mman-common.h | \
8 sed -r "s/$regex/\2 \1/g" | \
9 sort -n | xargs printf "\t[%s] = \"%s\",\n"
10printf "};\n"
diff --git a/tools/perf/trace/beauty/mmap.c b/tools/perf/trace/beauty/mmap.c
index 754558f9009d..9e1668b2c5d7 100644
--- a/tools/perf/trace/beauty/mmap.c
+++ b/tools/perf/trace/beauty/mmap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <uapi/linux/mman.h> 2#include <uapi/linux/mman.h>
2 3
3static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, 4static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
@@ -94,35 +95,21 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
94 95
95#define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags 96#define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags
96 97
98static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size)
99{
100#include "trace/beauty/generated/madvise_behavior_array.c"
101 static DEFINE_STRARRAY(madvise_advices);
102
103 if (behavior < strarray__madvise_advices.nr_entries && strarray__madvise_advices.entries[behavior] != NULL)
104 return scnprintf(bf, size, "MADV_%s", strarray__madvise_advices.entries[behavior]);
105
106 return scnprintf(bf, size, "%#", behavior);
107}
108
97static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, 109static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
98 struct syscall_arg *arg) 110 struct syscall_arg *arg)
99{ 111{
100 int behavior = arg->val; 112 return madvise__scnprintf_behavior(arg->val, bf, size);
101
102 switch (behavior) {
103#define P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n)
104 P_MADV_BHV(NORMAL);
105 P_MADV_BHV(RANDOM);
106 P_MADV_BHV(SEQUENTIAL);
107 P_MADV_BHV(WILLNEED);
108 P_MADV_BHV(DONTNEED);
109 P_MADV_BHV(FREE);
110 P_MADV_BHV(REMOVE);
111 P_MADV_BHV(DONTFORK);
112 P_MADV_BHV(DOFORK);
113 P_MADV_BHV(HWPOISON);
114 P_MADV_BHV(SOFT_OFFLINE);
115 P_MADV_BHV(MERGEABLE);
116 P_MADV_BHV(UNMERGEABLE);
117 P_MADV_BHV(HUGEPAGE);
118 P_MADV_BHV(NOHUGEPAGE);
119 P_MADV_BHV(DONTDUMP);
120 P_MADV_BHV(DODUMP);
121#undef P_MADV_BHV
122 default: break;
123 }
124
125 return scnprintf(bf, size, "%#x", behavior);
126} 113}
127 114
128#define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior 115#define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior
diff --git a/tools/perf/trace/beauty/mode_t.c b/tools/perf/trace/beauty/mode_t.c
index 930d8fef2400..d929ad7dd97b 100644
--- a/tools/perf/trace/beauty/mode_t.c
+++ b/tools/perf/trace/beauty/mode_t.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <sys/stat.h> 3#include <sys/stat.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/perf/trace/beauty/msg_flags.c b/tools/perf/trace/beauty/msg_flags.c
index 1106c8960cc4..c064d6aae659 100644
--- a/tools/perf/trace/beauty/msg_flags.c
+++ b/tools/perf/trace/beauty/msg_flags.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <sys/socket.h> 3#include <sys/socket.h>
3 4
diff --git a/tools/perf/trace/beauty/open_flags.c b/tools/perf/trace/beauty/open_flags.c
index e359e041dc0e..6aec6178a99d 100644
--- a/tools/perf/trace/beauty/open_flags.c
+++ b/tools/perf/trace/beauty/open_flags.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <sys/stat.h> 3#include <sys/stat.h>
3#include <fcntl.h> 4#include <fcntl.h>
diff --git a/tools/perf/trace/beauty/perf_event_open.c b/tools/perf/trace/beauty/perf_event_open.c
index 311f09dd718d..2bafd7c995ff 100644
--- a/tools/perf/trace/beauty/perf_event_open.c
+++ b/tools/perf/trace/beauty/perf_event_open.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#ifndef PERF_FLAG_FD_NO_GROUP 2#ifndef PERF_FLAG_FD_NO_GROUP
2# define PERF_FLAG_FD_NO_GROUP (1UL << 0) 3# define PERF_FLAG_FD_NO_GROUP (1UL << 0)
3#endif 4#endif
diff --git a/tools/perf/trace/beauty/pid.c b/tools/perf/trace/beauty/pid.c
index b6d419e16dcf..0313df342830 100644
--- a/tools/perf/trace/beauty/pid.c
+++ b/tools/perf/trace/beauty/pid.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_arg *arg) 2size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_arg *arg)
2{ 3{
3 int pid = arg->val; 4 int pid = arg->val;
diff --git a/tools/perf/trace/beauty/prctl.c b/tools/perf/trace/beauty/prctl.c
new file mode 100644
index 000000000000..246130dad6c4
--- /dev/null
+++ b/tools/perf/trace/beauty/prctl.c
@@ -0,0 +1,82 @@
1/*
2 * trace/beauty/prctl.c
3 *
4 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
5 *
6 * Released under the GPL v2. (and only v2, not any later version)
7 */
8
9#include "trace/beauty/beauty.h"
10#include <linux/kernel.h>
11#include <uapi/linux/prctl.h>
12
13#include "trace/beauty/generated/prctl_option_array.c"
14
15static size_t prctl__scnprintf_option(int option, char *bf, size_t size)
16{
17 static DEFINE_STRARRAY(prctl_options);
18 return strarray__scnprintf(&strarray__prctl_options, bf, size, "%d", option);
19}
20
21static size_t prctl__scnprintf_set_mm(int option, char *bf, size_t size)
22{
23 static DEFINE_STRARRAY(prctl_set_mm_options);
24 return strarray__scnprintf(&strarray__prctl_set_mm_options, bf, size, "%d", option);
25}
26
27size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg)
28{
29 int option = syscall_arg__val(arg, 0);
30
31 if (option == PR_SET_MM)
32 return prctl__scnprintf_set_mm(arg->val, bf, size);
33 /*
34 * We still don't grab the contents of pointers on entry or exit,
35 * so just print them as hex numbers
36 */
37 if (option == PR_SET_NAME)
38 return syscall_arg__scnprintf_hex(bf, size, arg);
39
40 return syscall_arg__scnprintf_long(bf, size, arg);
41}
42
43size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg)
44{
45 int option = syscall_arg__val(arg, 0);
46
47 if (option == PR_SET_MM)
48 return syscall_arg__scnprintf_hex(bf, size, arg);
49
50 return syscall_arg__scnprintf_long(bf, size, arg);
51}
52
53size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg)
54{
55 unsigned long option = arg->val;
56 enum {
57 SPO_ARG2 = (1 << 1),
58 SPO_ARG3 = (1 << 2),
59 SPO_ARG4 = (1 << 3),
60 SPO_ARG5 = (1 << 4),
61 SPO_ARG6 = (1 << 5),
62 };
63 const u8 all_but2 = SPO_ARG3 | SPO_ARG4 | SPO_ARG5 | SPO_ARG6;
64 const u8 all = SPO_ARG2 | all_but2;
65 const u8 masks[] = {
66 [PR_GET_DUMPABLE] = all,
67 [PR_SET_DUMPABLE] = all_but2,
68 [PR_SET_NAME] = all_but2,
69 [PR_GET_CHILD_SUBREAPER] = all_but2,
70 [PR_SET_CHILD_SUBREAPER] = all_but2,
71 [PR_GET_SECUREBITS] = all,
72 [PR_SET_SECUREBITS] = all_but2,
73 [PR_SET_MM] = SPO_ARG4 | SPO_ARG5 | SPO_ARG6,
74 [PR_GET_PDEATHSIG] = all,
75 [PR_SET_PDEATHSIG] = all_but2,
76 };
77
78 if (option < ARRAY_SIZE(masks))
79 arg->mask |= masks[option];
80
81 return prctl__scnprintf_option(option, bf, size);
82}
diff --git a/tools/perf/trace/beauty/prctl_option.sh b/tools/perf/trace/beauty/prctl_option.sh
new file mode 100755
index 000000000000..0be4138fbe71
--- /dev/null
+++ b/tools/perf/trace/beauty/prctl_option.sh
@@ -0,0 +1,17 @@
1#!/bin/sh
2
3header_dir=$1
4
5printf "static const char *prctl_options[] = {\n"
6regex='^#define[[:space:]]+PR_([GS]ET\w+)[[:space:]]*([[:xdigit:]]+).*'
7egrep $regex ${header_dir}/prctl.h | grep -v PR_SET_PTRACER | \
8 sed -r "s/$regex/\2 \1/g" | \
9 sort -n | xargs printf "\t[%s] = \"%s\",\n"
10printf "};\n"
11
12printf "static const char *prctl_set_mm_options[] = {\n"
13regex='^#[[:space:]]+define[[:space:]]+PR_SET_MM_(\w+)[[:space:]]*([[:digit:]]+).*'
14egrep $regex ${header_dir}/prctl.h | \
15 sed -r "s/$regex/\2 \1/g" | \
16 sort -n | xargs printf "\t[%s] = \"%s\",\n"
17printf "};\n"
diff --git a/tools/perf/trace/beauty/sched_policy.c b/tools/perf/trace/beauty/sched_policy.c
index 34775295b9b3..ba5096ae76b6 100644
--- a/tools/perf/trace/beauty/sched_policy.c
+++ b/tools/perf/trace/beauty/sched_policy.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sched.h> 2#include <sched.h>
2 3
3/* 4/*
diff --git a/tools/perf/trace/beauty/seccomp.c b/tools/perf/trace/beauty/seccomp.c
index 356441bce27d..b7097fd5fed9 100644
--- a/tools/perf/trace/beauty/seccomp.c
+++ b/tools/perf/trace/beauty/seccomp.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#ifndef SECCOMP_SET_MODE_STRICT 2#ifndef SECCOMP_SET_MODE_STRICT
2#define SECCOMP_SET_MODE_STRICT 0 3#define SECCOMP_SET_MODE_STRICT 0
3#endif 4#endif
diff --git a/tools/perf/trace/beauty/signum.c b/tools/perf/trace/beauty/signum.c
index fde8f2fc6558..bde18a53f090 100644
--- a/tools/perf/trace/beauty/signum.c
+++ b/tools/perf/trace/beauty/signum.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <signal.h> 2#include <signal.h>
2 3
3static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg) 4static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg)
diff --git a/tools/perf/trace/beauty/socket_type.c b/tools/perf/trace/beauty/socket_type.c
index 0a5ce818131c..bca26aef4a77 100644
--- a/tools/perf/trace/beauty/socket_type.c
+++ b/tools/perf/trace/beauty/socket_type.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <sys/socket.h> 3#include <sys/socket.h>
3 4
diff --git a/tools/perf/trace/beauty/waitid_options.c b/tools/perf/trace/beauty/waitid_options.c
index 7942724adec8..8465281a093d 100644
--- a/tools/perf/trace/beauty/waitid_options.c
+++ b/tools/perf/trace/beauty/waitid_options.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <sys/wait.h> 3#include <sys/wait.h>
3 4
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index d0c2007c307b..63399af3049f 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../util.h" 2#include "../util.h"
2#include "../string2.h" 3#include "../string2.h"
3#include "../config.h" 4#include "../config.h"
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index a12eff75638b..03e1734412b9 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_BROWSER_H_ 2#ifndef _PERF_UI_BROWSER_H_
2#define _PERF_UI_BROWSER_H_ 1 3#define _PERF_UI_BROWSER_H_ 1
3 4
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 786fecaf578e..8f7f59d1a2b5 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../../util/util.h" 2#include "../../util/util.h"
2#include "../browser.h" 3#include "../browser.h"
3#include "../helpline.h" 4#include "../helpline.h"
diff --git a/tools/perf/ui/browsers/header.c b/tools/perf/ui/browsers/header.c
index e2c9390ff4c5..d75492189acb 100644
--- a/tools/perf/ui/browsers/header.c
+++ b/tools/perf/ui/browsers/header.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "util/cache.h" 2#include "util/cache.h"
2#include "util/debug.h" 3#include "util/debug.h"
3#include "ui/browser.h" 4#include "ui/browser.h"
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 13dfb0a0bdeb..68146f4620a5 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <dirent.h> 2#include <dirent.h>
2#include <errno.h> 3#include <errno.h>
3#include <inttypes.h> 4#include <inttypes.h>
@@ -154,57 +155,9 @@ static void callchain_list__set_folding(struct callchain_list *cl, bool unfold)
154 cl->unfolded = unfold ? cl->has_children : false; 155 cl->unfolded = unfold ? cl->has_children : false;
155} 156}
156 157
157static struct inline_node *inline_node__create(struct map *map, u64 ip)
158{
159 struct dso *dso;
160 struct inline_node *node;
161
162 if (map == NULL)
163 return NULL;
164
165 dso = map->dso;
166 if (dso == NULL)
167 return NULL;
168
169 node = dso__parse_addr_inlines(dso,
170 map__rip_2objdump(map, ip));
171
172 return node;
173}
174
175static int inline__count_rows(struct inline_node *node)
176{
177 struct inline_list *ilist;
178 int i = 0;
179
180 if (node == NULL)
181 return 0;
182
183 list_for_each_entry(ilist, &node->val, list) {
184 if ((ilist->filename != NULL) || (ilist->funcname != NULL))
185 i++;
186 }
187
188 return i;
189}
190
191static int callchain_list__inline_rows(struct callchain_list *chain)
192{
193 struct inline_node *node;
194 int rows;
195
196 node = inline_node__create(chain->ms.map, chain->ip);
197 if (node == NULL)
198 return 0;
199
200 rows = inline__count_rows(node);
201 inline_node__delete(node);
202 return rows;
203}
204
205static int callchain_node__count_rows_rb_tree(struct callchain_node *node) 158static int callchain_node__count_rows_rb_tree(struct callchain_node *node)
206{ 159{
207 int n = 0, inline_rows; 160 int n = 0;
208 struct rb_node *nd; 161 struct rb_node *nd;
209 162
210 for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) { 163 for (nd = rb_first(&node->rb_root); nd; nd = rb_next(nd)) {
@@ -215,12 +168,6 @@ static int callchain_node__count_rows_rb_tree(struct callchain_node *node)
215 list_for_each_entry(chain, &child->val, list) { 168 list_for_each_entry(chain, &child->val, list) {
216 ++n; 169 ++n;
217 170
218 if (symbol_conf.inline_name) {
219 inline_rows =
220 callchain_list__inline_rows(chain);
221 n += inline_rows;
222 }
223
224 /* We need this because we may not have children */ 171 /* We need this because we may not have children */
225 folded_sign = callchain_list__folded(chain); 172 folded_sign = callchain_list__folded(chain);
226 if (folded_sign == '+') 173 if (folded_sign == '+')
@@ -272,7 +219,7 @@ static int callchain_node__count_rows(struct callchain_node *node)
272{ 219{
273 struct callchain_list *chain; 220 struct callchain_list *chain;
274 bool unfolded = false; 221 bool unfolded = false;
275 int n = 0, inline_rows; 222 int n = 0;
276 223
277 if (callchain_param.mode == CHAIN_FLAT) 224 if (callchain_param.mode == CHAIN_FLAT)
278 return callchain_node__count_flat_rows(node); 225 return callchain_node__count_flat_rows(node);
@@ -281,10 +228,6 @@ static int callchain_node__count_rows(struct callchain_node *node)
281 228
282 list_for_each_entry(chain, &node->val, list) { 229 list_for_each_entry(chain, &node->val, list) {
283 ++n; 230 ++n;
284 if (symbol_conf.inline_name) {
285 inline_rows = callchain_list__inline_rows(chain);
286 n += inline_rows;
287 }
288 231
289 unfolded = chain->unfolded; 232 unfolded = chain->unfolded;
290 } 233 }
@@ -432,19 +375,6 @@ static void hist_entry__init_have_children(struct hist_entry *he)
432 he->init_have_children = true; 375 he->init_have_children = true;
433} 376}
434 377
435static void hist_entry_init_inline_node(struct hist_entry *he)
436{
437 if (he->inline_node)
438 return;
439
440 he->inline_node = inline_node__create(he->ms.map, he->ip);
441
442 if (he->inline_node == NULL)
443 return;
444
445 he->has_children = true;
446}
447
448static bool hist_browser__toggle_fold(struct hist_browser *browser) 378static bool hist_browser__toggle_fold(struct hist_browser *browser)
449{ 379{
450 struct hist_entry *he = browser->he_selection; 380 struct hist_entry *he = browser->he_selection;
@@ -476,12 +406,8 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser)
476 406
477 if (he->unfolded) { 407 if (he->unfolded) {
478 if (he->leaf) 408 if (he->leaf)
479 if (he->inline_node) 409 he->nr_rows = callchain__count_rows(
480 he->nr_rows = inline__count_rows( 410 &he->sorted_chain);
481 he->inline_node);
482 else
483 he->nr_rows = callchain__count_rows(
484 &he->sorted_chain);
485 else 411 else
486 he->nr_rows = hierarchy_count_rows(browser, he, false); 412 he->nr_rows = hierarchy_count_rows(browser, he, false);
487 413
@@ -841,71 +767,6 @@ static bool hist_browser__check_dump_full(struct hist_browser *browser __maybe_u
841 767
842#define LEVEL_OFFSET_STEP 3 768#define LEVEL_OFFSET_STEP 3
843 769
844static int hist_browser__show_inline(struct hist_browser *browser,
845 struct inline_node *node,
846 unsigned short row,
847 int offset)
848{
849 struct inline_list *ilist;
850 char buf[1024];
851 int color, width, first_row;
852
853 first_row = row;
854 width = browser->b.width - (LEVEL_OFFSET_STEP + 2);
855 list_for_each_entry(ilist, &node->val, list) {
856 if ((ilist->filename != NULL) || (ilist->funcname != NULL)) {
857 color = HE_COLORSET_NORMAL;
858 if (ui_browser__is_current_entry(&browser->b, row))
859 color = HE_COLORSET_SELECTED;
860
861 if (callchain_param.key == CCKEY_ADDRESS ||
862 callchain_param.key == CCKEY_SRCLINE) {
863 if (ilist->filename != NULL)
864 scnprintf(buf, sizeof(buf),
865 "%s:%d (inline)",
866 ilist->filename,
867 ilist->line_nr);
868 else
869 scnprintf(buf, sizeof(buf), "??");
870 } else if (ilist->funcname != NULL)
871 scnprintf(buf, sizeof(buf), "%s (inline)",
872 ilist->funcname);
873 else if (ilist->filename != NULL)
874 scnprintf(buf, sizeof(buf),
875 "%s:%d (inline)",
876 ilist->filename,
877 ilist->line_nr);
878 else
879 scnprintf(buf, sizeof(buf), "??");
880
881 ui_browser__set_color(&browser->b, color);
882 hist_browser__gotorc(browser, row, 0);
883 ui_browser__write_nstring(&browser->b, " ",
884 LEVEL_OFFSET_STEP + offset);
885 ui_browser__write_nstring(&browser->b, buf, width);
886 row++;
887 }
888 }
889
890 return row - first_row;
891}
892
893static size_t show_inline_list(struct hist_browser *browser, struct map *map,
894 u64 ip, int row, int offset)
895{
896 struct inline_node *node;
897 int ret;
898
899 node = inline_node__create(map, ip);
900 if (node == NULL)
901 return 0;
902
903 ret = hist_browser__show_inline(browser, node, row, offset);
904
905 inline_node__delete(node);
906 return ret;
907}
908
909static int hist_browser__show_callchain_list(struct hist_browser *browser, 770static int hist_browser__show_callchain_list(struct hist_browser *browser,
910 struct callchain_node *node, 771 struct callchain_node *node,
911 struct callchain_list *chain, 772 struct callchain_list *chain,
@@ -917,7 +778,7 @@ static int hist_browser__show_callchain_list(struct hist_browser *browser,
917 char bf[1024], *alloc_str; 778 char bf[1024], *alloc_str;
918 char buf[64], *alloc_str2; 779 char buf[64], *alloc_str2;
919 const char *str; 780 const char *str;
920 int inline_rows = 0, ret = 1; 781 int ret = 1;
921 782
922 if (arg->row_offset != 0) { 783 if (arg->row_offset != 0) {
923 arg->row_offset--; 784 arg->row_offset--;
@@ -954,12 +815,7 @@ static int hist_browser__show_callchain_list(struct hist_browser *browser,
954 free(alloc_str); 815 free(alloc_str);
955 free(alloc_str2); 816 free(alloc_str2);
956 817
957 if (symbol_conf.inline_name) { 818 return ret;
958 inline_rows = show_inline_list(browser, chain->ms.map,
959 chain->ip, row + 1, offset);
960 }
961
962 return ret + inline_rows;
963} 819}
964 820
965static bool check_percent_display(struct rb_node *node, u64 parent_total) 821static bool check_percent_display(struct rb_node *node, u64 parent_total)
@@ -1383,12 +1239,6 @@ static int hist_browser__show_entry(struct hist_browser *browser,
1383 folded_sign = hist_entry__folded(entry); 1239 folded_sign = hist_entry__folded(entry);
1384 } 1240 }
1385 1241
1386 if (symbol_conf.inline_name &&
1387 (!entry->has_children)) {
1388 hist_entry_init_inline_node(entry);
1389 folded_sign = hist_entry__folded(entry);
1390 }
1391
1392 if (row_offset == 0) { 1242 if (row_offset == 0) {
1393 struct hpp_arg arg = { 1243 struct hpp_arg arg = {
1394 .b = &browser->b, 1244 .b = &browser->b,
@@ -1420,8 +1270,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
1420 } 1270 }
1421 1271
1422 if (first) { 1272 if (first) {
1423 if (symbol_conf.use_callchain || 1273 if (symbol_conf.use_callchain) {
1424 symbol_conf.inline_name) {
1425 ui_browser__printf(&browser->b, "%c ", folded_sign); 1274 ui_browser__printf(&browser->b, "%c ", folded_sign);
1426 width -= 2; 1275 width -= 2;
1427 } 1276 }
@@ -1463,15 +1312,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,
1463 .is_current_entry = current_entry, 1312 .is_current_entry = current_entry,
1464 }; 1313 };
1465 1314
1466 if (entry->inline_node) 1315 printed += hist_browser__show_callchain(browser,
1467 printed += hist_browser__show_inline(browser, 1316 entry, 1, row,
1468 entry->inline_node, row, 0); 1317 hist_browser__show_callchain_entry,
1469 else 1318 &arg,
1470 printed += hist_browser__show_callchain(browser, 1319 hist_browser__check_output_full);
1471 entry, 1, row,
1472 hist_browser__show_callchain_entry,
1473 &arg,
1474 hist_browser__check_output_full);
1475 } 1320 }
1476 1321
1477 return printed; 1322 return printed;
diff --git a/tools/perf/ui/browsers/hists.h b/tools/perf/ui/browsers/hists.h
index 23d6acb84800..ba431777f559 100644
--- a/tools/perf/ui/browsers/hists.h
+++ b/tools/perf/ui/browsers/hists.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_BROWSER_HISTS_H_ 2#ifndef _PERF_UI_BROWSER_HISTS_H_
2#define _PERF_UI_BROWSER_HISTS_H_ 1 3#define _PERF_UI_BROWSER_HISTS_H_ 1
3 4
diff --git a/tools/perf/ui/browsers/map.c b/tools/perf/ui/browsers/map.c
index ffa5addf631d..e03fa75f108a 100644
--- a/tools/perf/ui/browsers/map.c
+++ b/tools/perf/ui/browsers/map.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <elf.h> 2#include <elf.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <sys/ttydefaults.h> 4#include <sys/ttydefaults.h>
diff --git a/tools/perf/ui/browsers/map.h b/tools/perf/ui/browsers/map.h
index 2d58e4b3eb6f..0ed7dbb3a373 100644
--- a/tools/perf/ui/browsers/map.h
+++ b/tools/perf/ui/browsers/map.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_MAP_BROWSER_H_ 2#ifndef _PERF_UI_MAP_BROWSER_H_
2#define _PERF_UI_MAP_BROWSER_H_ 1 3#define _PERF_UI_MAP_BROWSER_H_ 1
3struct map; 4struct map;
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index ad6b6ee3770e..90a32ac69e76 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <elf.h> 2#include <elf.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <sys/ttydefaults.h> 4#include <sys/ttydefaults.h>
diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
index 02176193f427..fc7a2e105bfd 100644
--- a/tools/perf/ui/gtk/annotate.c
+++ b/tools/perf/ui/gtk/annotate.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "gtk.h" 2#include "gtk.h"
2#include "util/debug.h" 3#include "util/debug.h"
3#include "util/annotate.h" 4#include "util/annotate.h"
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index c24d91221290..4820e25ac68d 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../evlist.h" 2#include "../evlist.h"
2#include "../cache.h" 3#include "../cache.h"
3#include "../evsel.h" 4#include "../evsel.h"
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index 0a9173ff9a61..9846ea5c831b 100644
--- a/tools/perf/ui/gtk/gtk.h
+++ b/tools/perf/ui/gtk/gtk.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_GTK_H_ 2#ifndef _PERF_GTK_H_
2#define _PERF_GTK_H_ 1 3#define _PERF_GTK_H_ 1
3 4
diff --git a/tools/perf/ui/gtk/helpline.c b/tools/perf/ui/gtk/helpline.c
index 3388cbd12186..fbf1ea9ce9a2 100644
--- a/tools/perf/ui/gtk/helpline.c
+++ b/tools/perf/ui/gtk/helpline.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <string.h> 3#include <string.h>
3 4
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index e24f83957705..24e1ec201ffd 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../evlist.h" 2#include "../evlist.h"
2#include "../cache.h" 3#include "../cache.h"
3#include "../evsel.h" 4#include "../evsel.h"
diff --git a/tools/perf/ui/gtk/progress.c b/tools/perf/ui/gtk/progress.c
index b656655fbc39..b6ad8857da78 100644
--- a/tools/perf/ui/gtk/progress.c
+++ b/tools/perf/ui/gtk/progress.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2 3
3#include "gtk.h" 4#include "gtk.h"
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c
index 1d57676f8212..506e73b3834c 100644
--- a/tools/perf/ui/gtk/setup.c
+++ b/tools/perf/ui/gtk/setup.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "gtk.h" 2#include "gtk.h"
2#include "../../util/cache.h" 3#include "../../util/cache.h"
3#include "../../util/debug.h" 4#include "../../util/debug.h"
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c
index 00b91921edb1..7250d8101c8f 100644
--- a/tools/perf/ui/gtk/util.c
+++ b/tools/perf/ui/gtk/util.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../util.h" 2#include "../util.h"
2#include "../../util/util.h" 3#include "../../util/util.h"
3#include "../../util/debug.h" 4#include "../../util/debug.h"
diff --git a/tools/perf/ui/helpline.c b/tools/perf/ui/helpline.c
index 379039ab00d8..b3c421429ed4 100644
--- a/tools/perf/ui/helpline.c
+++ b/tools/perf/ui/helpline.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h
index d52d0a1a881b..8f775a053ca3 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_HELPLINE_H_ 2#ifndef _PERF_UI_HELPLINE_H_
2#define _PERF_UI_HELPLINE_H_ 1 3#define _PERF_UI_HELPLINE_H_ 1
3 4
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index ddb2c6fbdf91..706f6f1e9c7d 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include <math.h> 3#include <math.h>
3#include <linux/compiler.h> 4#include <linux/compiler.h>
@@ -532,7 +533,7 @@ void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,
532 533
533void perf_hpp__column_unregister(struct perf_hpp_fmt *format) 534void perf_hpp__column_unregister(struct perf_hpp_fmt *format)
534{ 535{
535 list_del(&format->list); 536 list_del_init(&format->list);
536} 537}
537 538
538void perf_hpp__cancel_cumulate(void) 539void perf_hpp__cancel_cumulate(void)
@@ -606,6 +607,13 @@ next:
606 607
607static void fmt_free(struct perf_hpp_fmt *fmt) 608static void fmt_free(struct perf_hpp_fmt *fmt)
608{ 609{
610 /*
611 * At this point fmt should be completely
612 * unhooked, if not it's a bug.
613 */
614 BUG_ON(!list_empty(&fmt->list));
615 BUG_ON(!list_empty(&fmt->sort_list));
616
609 if (fmt->free) 617 if (fmt->free)
610 fmt->free(fmt); 618 fmt->free(fmt);
611} 619}
diff --git a/tools/perf/ui/keysyms.h b/tools/perf/ui/keysyms.h
index 65092d576b4e..fbfac29077f2 100644
--- a/tools/perf/ui/keysyms.h
+++ b/tools/perf/ui/keysyms.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_KEYSYMS_H_ 2#ifndef _PERF_KEYSYMS_H_
2#define _PERF_KEYSYMS_H_ 1 3#define _PERF_KEYSYMS_H_ 1
3 4
diff --git a/tools/perf/ui/libslang.h b/tools/perf/ui/libslang.h
index db816695ad97..c0686cda39a5 100644
--- a/tools/perf/ui/libslang.h
+++ b/tools/perf/ui/libslang.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_SLANG_H_ 2#ifndef _PERF_UI_SLANG_H_
2#define _PERF_UI_SLANG_H_ 1 3#define _PERF_UI_SLANG_H_ 1
3/* 4/*
diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index ae91c8148edf..bbfbc91a0fa4 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/kernel.h> 2#include <linux/kernel.h>
2#include "../cache.h" 3#include "../cache.h"
3#include "progress.h" 4#include "progress.h"
@@ -27,13 +28,17 @@ void ui_progress__update(struct ui_progress *p, u64 adv)
27 } 28 }
28} 29}
29 30
30void ui_progress__init(struct ui_progress *p, u64 total, const char *title) 31void __ui_progress__init(struct ui_progress *p, u64 total,
32 const char *title, bool size)
31{ 33{
32 p->curr = 0; 34 p->curr = 0;
33 p->next = p->step = total / 16 ?: 1; 35 p->next = p->step = total / 16 ?: 1;
34 p->total = total; 36 p->total = total;
35 p->title = title; 37 p->title = title;
38 p->size = size;
36 39
40 if (ui_progress__ops->init)
41 ui_progress__ops->init(p);
37} 42}
38 43
39void ui_progress__finish(void) 44void ui_progress__finish(void)
diff --git a/tools/perf/ui/progress.h b/tools/perf/ui/progress.h
index 717d39d3052b..4f52c37b2f09 100644
--- a/tools/perf/ui/progress.h
+++ b/tools/perf/ui/progress.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_PROGRESS_H_ 2#ifndef _PERF_UI_PROGRESS_H_
2#define _PERF_UI_PROGRESS_H_ 1 3#define _PERF_UI_PROGRESS_H_ 1
3 4
@@ -8,12 +9,22 @@ void ui_progress__finish(void);
8struct ui_progress { 9struct ui_progress {
9 const char *title; 10 const char *title;
10 u64 curr, next, step, total; 11 u64 curr, next, step, total;
12 bool size;
11}; 13};
12 14
13void ui_progress__init(struct ui_progress *p, u64 total, const char *title); 15void __ui_progress__init(struct ui_progress *p, u64 total,
16 const char *title, bool size);
17
18#define ui_progress__init(p, total, title) \
19 __ui_progress__init(p, total, title, false)
20
21#define ui_progress__init_size(p, total, title) \
22 __ui_progress__init(p, total, title, true)
23
14void ui_progress__update(struct ui_progress *p, u64 adv); 24void ui_progress__update(struct ui_progress *p, u64 adv);
15 25
16struct ui_progress_ops { 26struct ui_progress_ops {
27 void (*init)(struct ui_progress *p);
17 void (*update)(struct ui_progress *p); 28 void (*update)(struct ui_progress *p);
18 void (*finish)(void); 29 void (*finish)(void);
19}; 30};
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index caf1ce6f5152..44fe824e96cd 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <pthread.h> 2#include <pthread.h>
2#include <dlfcn.h> 3#include <dlfcn.h>
3 4
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 8bdb7a500181..25dd1e0ecc58 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <linux/string.h> 3#include <linux/string.h>
3 4
@@ -21,64 +22,6 @@ static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
21 return ret; 22 return ret;
22} 23}
23 24
24static size_t inline__fprintf(struct map *map, u64 ip, int left_margin,
25 int depth, int depth_mask, FILE *fp)
26{
27 struct dso *dso;
28 struct inline_node *node;
29 struct inline_list *ilist;
30 int ret = 0, i;
31
32 if (map == NULL)
33 return 0;
34
35 dso = map->dso;
36 if (dso == NULL)
37 return 0;
38
39 node = dso__parse_addr_inlines(dso,
40 map__rip_2objdump(map, ip));
41 if (node == NULL)
42 return 0;
43
44 list_for_each_entry(ilist, &node->val, list) {
45 if ((ilist->filename != NULL) || (ilist->funcname != NULL)) {
46 ret += callchain__fprintf_left_margin(fp, left_margin);
47
48 for (i = 0; i < depth; i++) {
49 if (depth_mask & (1 << i))
50 ret += fprintf(fp, "|");
51 else
52 ret += fprintf(fp, " ");
53 ret += fprintf(fp, " ");
54 }
55
56 if (callchain_param.key == CCKEY_ADDRESS ||
57 callchain_param.key == CCKEY_SRCLINE) {
58 if (ilist->filename != NULL)
59 ret += fprintf(fp, "%s:%d (inline)",
60 ilist->filename,
61 ilist->line_nr);
62 else
63 ret += fprintf(fp, "??");
64 } else if (ilist->funcname != NULL)
65 ret += fprintf(fp, "%s (inline)",
66 ilist->funcname);
67 else if (ilist->filename != NULL)
68 ret += fprintf(fp, "%s:%d (inline)",
69 ilist->filename,
70 ilist->line_nr);
71 else
72 ret += fprintf(fp, "??");
73
74 ret += fprintf(fp, "\n");
75 }
76 }
77
78 inline_node__delete(node);
79 return ret;
80}
81
82static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, 25static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
83 int left_margin) 26 int left_margin)
84{ 27{
@@ -137,9 +80,6 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
137 fputc('\n', fp); 80 fputc('\n', fp);
138 free(alloc_str); 81 free(alloc_str);
139 82
140 if (symbol_conf.inline_name)
141 ret += inline__fprintf(chain->ms.map, chain->ip,
142 left_margin, depth, depth_mask, fp);
143 return ret; 83 return ret;
144} 84}
145 85
@@ -314,13 +254,6 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
314 254
315 if (++entries_printed == callchain_param.print_limit) 255 if (++entries_printed == callchain_param.print_limit)
316 break; 256 break;
317
318 if (symbol_conf.inline_name)
319 ret += inline__fprintf(chain->ms.map,
320 chain->ip,
321 left_margin,
322 0, 0,
323 fp);
324 } 257 }
325 root = &cnode->rb_root; 258 root = &cnode->rb_root;
326 } 259 }
@@ -600,7 +533,6 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
600{ 533{
601 int ret; 534 int ret;
602 int callchain_ret = 0; 535 int callchain_ret = 0;
603 int inline_ret = 0;
604 struct perf_hpp hpp = { 536 struct perf_hpp hpp = {
605 .buf = bf, 537 .buf = bf,
606 .size = size, 538 .size = size,
@@ -622,13 +554,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
622 callchain_ret = hist_entry_callchain__fprintf(he, total_period, 554 callchain_ret = hist_entry_callchain__fprintf(he, total_period,
623 0, fp); 555 0, fp);
624 556
625 if (callchain_ret == 0 && symbol_conf.inline_name) { 557 ret += callchain_ret;
626 inline_ret = inline__fprintf(he->ms.map, he->ip, 0, 0, 0, fp);
627 ret += inline_ret;
628 if (inline_ret > 0)
629 ret += fprintf(fp, "\n");
630 } else
631 ret += callchain_ret;
632 558
633 return ret; 559 return ret;
634} 560}
diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
index 88f5143a5981..4ca799aadb4e 100644
--- a/tools/perf/ui/tui/helpline.c
+++ b/tools/perf/ui/tui/helpline.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/perf/ui/tui/progress.c b/tools/perf/ui/tui/progress.c
index c4b99008e2c9..bc134b82829d 100644
--- a/tools/perf/ui/tui/progress.c
+++ b/tools/perf/ui/tui/progress.c
@@ -1,12 +1,34 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/kernel.h>
1#include "../cache.h" 3#include "../cache.h"
2#include "../progress.h" 4#include "../progress.h"
3#include "../libslang.h" 5#include "../libslang.h"
4#include "../ui.h" 6#include "../ui.h"
5#include "tui.h" 7#include "tui.h"
8#include "units.h"
6#include "../browser.h" 9#include "../browser.h"
7 10
11static void __tui_progress__init(struct ui_progress *p)
12{
13 p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
14}
15
16static int get_title(struct ui_progress *p, char *buf, size_t size)
17{
18 char buf_cur[20];
19 char buf_tot[20];
20 int ret;
21
22 ret = unit_number__scnprintf(buf_cur, sizeof(buf_cur), p->curr);
23 ret += unit_number__scnprintf(buf_tot, sizeof(buf_tot), p->total);
24
25 return ret + scnprintf(buf, size, "%s [%s/%s]",
26 p->title, buf_cur, buf_tot);
27}
28
8static void tui_progress__update(struct ui_progress *p) 29static void tui_progress__update(struct ui_progress *p)
9{ 30{
31 char buf[100], *title = (char *) p->title;
10 int bar, y; 32 int bar, y;
11 /* 33 /*
12 * FIXME: We should have a per UI backend way of showing progress, 34 * FIXME: We should have a per UI backend way of showing progress,
@@ -18,13 +40,18 @@ static void tui_progress__update(struct ui_progress *p)
18 if (p->total == 0) 40 if (p->total == 0)
19 return; 41 return;
20 42
43 if (p->size) {
44 get_title(p, buf, sizeof(buf));
45 title = buf;
46 }
47
21 ui__refresh_dimensions(false); 48 ui__refresh_dimensions(false);
22 pthread_mutex_lock(&ui__lock); 49 pthread_mutex_lock(&ui__lock);
23 y = SLtt_Screen_Rows / 2 - 2; 50 y = SLtt_Screen_Rows / 2 - 2;
24 SLsmg_set_color(0); 51 SLsmg_set_color(0);
25 SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols); 52 SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
26 SLsmg_gotorc(y++, 1); 53 SLsmg_gotorc(y++, 1);
27 SLsmg_write_string((char *)p->title); 54 SLsmg_write_string(title);
28 SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' '); 55 SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' ');
29 SLsmg_set_color(HE_COLORSET_SELECTED); 56 SLsmg_set_color(HE_COLORSET_SELECTED);
30 bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total; 57 bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
@@ -49,8 +76,8 @@ static void tui_progress__finish(void)
49 pthread_mutex_unlock(&ui__lock); 76 pthread_mutex_unlock(&ui__lock);
50} 77}
51 78
52static struct ui_progress_ops tui_progress__ops = 79static struct ui_progress_ops tui_progress__ops = {
53{ 80 .init = __tui_progress__init,
54 .update = tui_progress__update, 81 .update = tui_progress__update,
55 .finish = tui_progress__finish, 82 .finish = tui_progress__finish,
56}; 83};
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index d9350a1da48b..d4ac41679721 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <signal.h> 3#include <signal.h>
3#include <stdbool.h> 4#include <stdbool.h>
diff --git a/tools/perf/ui/tui/tui.h b/tools/perf/ui/tui/tui.h
index 18961c7b6ec5..8de06f634c56 100644
--- a/tools/perf/ui/tui/tui.h
+++ b/tools/perf/ui/tui/tui.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_TUI_H_ 2#ifndef _PERF_TUI_H_
2#define _PERF_TUI_H_ 1 3#define _PERF_TUI_H_ 1
3 4
diff --git a/tools/perf/ui/tui/util.c b/tools/perf/ui/tui/util.c
index d96ad7c8325d..b9794d6185af 100644
--- a/tools/perf/ui/tui/util.c
+++ b/tools/perf/ui/tui/util.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../../util/util.h" 2#include "../../util/util.h"
2#include <signal.h> 3#include <signal.h>
3#include <stdbool.h> 4#include <stdbool.h>
diff --git a/tools/perf/ui/ui.h b/tools/perf/ui/ui.h
index 4b6fb6c7a542..9b6fdf06e1d2 100644
--- a/tools/perf/ui/ui.h
+++ b/tools/perf/ui/ui.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_H_ 2#ifndef _PERF_UI_H_
2#define _PERF_UI_H_ 1 3#define _PERF_UI_H_ 1
3 4
diff --git a/tools/perf/ui/util.c b/tools/perf/ui/util.c
index e3e0a963d03a..63bf06e80ab9 100644
--- a/tools/perf/ui/util.c
+++ b/tools/perf/ui/util.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "util.h" 2#include "util.h"
2#include "../debug.h" 3#include "../debug.h"
3 4
diff --git a/tools/perf/ui/util.h b/tools/perf/ui/util.h
index 361f08c52d37..5e44223b56fa 100644
--- a/tools/perf/ui/util.h
+++ b/tools/perf/ui/util.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UI_UTIL_H_ 2#ifndef _PERF_UI_UTIL_H_
2#define _PERF_UI_UTIL_H_ 1 3#define _PERF_UI_UTIL_H_ 1
3 4
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 94518c1bf8b6..a3de7916fe63 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -13,6 +13,7 @@ libperf-y += find_bit.o
13libperf-y += kallsyms.o 13libperf-y += kallsyms.o
14libperf-y += levenshtein.o 14libperf-y += levenshtein.o
15libperf-y += llvm-utils.o 15libperf-y += llvm-utils.o
16libperf-y += mmap.o
16libperf-y += memswap.o 17libperf-y += memswap.o
17libperf-y += parse-events.o 18libperf-y += parse-events.o
18libperf-y += perf_regs.o 19libperf-y += perf_regs.o
@@ -34,6 +35,7 @@ libperf-y += dso.o
34libperf-y += symbol.o 35libperf-y += symbol.o
35libperf-y += symbol_fprintf.o 36libperf-y += symbol_fprintf.o
36libperf-y += color.o 37libperf-y += color.o
38libperf-y += metricgroup.o
37libperf-y += header.o 39libperf-y += header.o
38libperf-y += callchain.o 40libperf-y += callchain.o
39libperf-y += values.o 41libperf-y += values.o
@@ -78,6 +80,7 @@ libperf-y += data.o
78libperf-y += tsc.o 80libperf-y += tsc.o
79libperf-y += cloexec.o 81libperf-y += cloexec.o
80libperf-y += call-path.o 82libperf-y += call-path.o
83libperf-y += rwsem.o
81libperf-y += thread-stack.o 84libperf-y += thread-stack.o
82libperf-$(CONFIG_AUXTRACE) += auxtrace.o 85libperf-$(CONFIG_AUXTRACE) += auxtrace.o
83libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/ 86libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/
diff --git a/tools/perf/util/PERF-VERSION-GEN b/tools/perf/util/PERF-VERSION-GEN
index 39f17507578d..3802cee5e188 100755
--- a/tools/perf/util/PERF-VERSION-GEN
+++ b/tools/perf/util/PERF-VERSION-GEN
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3if [ $# -eq 1 ] ; then 4if [ $# -eq 1 ] ; then
4 OUTPUT=$1 5 OUTPUT=$1
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 4397a8b6e6cd..da1c4c4a0dd8 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -49,10 +49,9 @@ struct arch {
49 void *priv; 49 void *priv;
50 unsigned int model; 50 unsigned int model;
51 unsigned int family; 51 unsigned int family;
52 int (*init)(struct arch *arch); 52 int (*init)(struct arch *arch, char *cpuid);
53 bool (*ins_is_fused)(struct arch *arch, const char *ins1, 53 bool (*ins_is_fused)(struct arch *arch, const char *ins1,
54 const char *ins2); 54 const char *ins2);
55 int (*cpuid_parse)(struct arch *arch, char *cpuid);
56 struct { 55 struct {
57 char comment_char; 56 char comment_char;
58 char skip_functions_char; 57 char skip_functions_char;
@@ -132,10 +131,10 @@ static struct arch architectures[] = {
132 }, 131 },
133 { 132 {
134 .name = "x86", 133 .name = "x86",
134 .init = x86__annotate_init,
135 .instructions = x86__instructions, 135 .instructions = x86__instructions,
136 .nr_instructions = ARRAY_SIZE(x86__instructions), 136 .nr_instructions = ARRAY_SIZE(x86__instructions),
137 .ins_is_fused = x86__ins_is_fused, 137 .ins_is_fused = x86__ins_is_fused,
138 .cpuid_parse = x86__cpuid_parse,
139 .objdump = { 138 .objdump = {
140 .comment_char = '#', 139 .comment_char = '#',
141 }, 140 },
@@ -606,9 +605,19 @@ static struct arch *arch__find(const char *name)
606int symbol__alloc_hist(struct symbol *sym) 605int symbol__alloc_hist(struct symbol *sym)
607{ 606{
608 struct annotation *notes = symbol__annotation(sym); 607 struct annotation *notes = symbol__annotation(sym);
609 const size_t size = symbol__size(sym); 608 size_t size = symbol__size(sym);
610 size_t sizeof_sym_hist; 609 size_t sizeof_sym_hist;
611 610
611 /*
612 * Add buffer of one element for zero length symbol.
613 * When sample is taken from first instruction of
614 * zero length symbol, perf still resolves it and
615 * shows symbol name in perf report and allows to
616 * annotate it.
617 */
618 if (size == 0)
619 size = 1;
620
612 /* Check for overflow when calculating sizeof_sym_hist */ 621 /* Check for overflow when calculating sizeof_sym_hist */
613 if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(struct sym_hist_entry)) 622 if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(struct sym_hist_entry))
614 return -1; 623 return -1;
@@ -1447,16 +1456,13 @@ int symbol__disassemble(struct symbol *sym, struct map *map,
1447 *parch = arch; 1456 *parch = arch;
1448 1457
1449 if (arch->init) { 1458 if (arch->init) {
1450 err = arch->init(arch); 1459 err = arch->init(arch, cpuid);
1451 if (err) { 1460 if (err) {
1452 pr_err("%s: failed to initialize %s arch priv area\n", __func__, arch->name); 1461 pr_err("%s: failed to initialize %s arch priv area\n", __func__, arch->name);
1453 return err; 1462 return err;
1454 } 1463 }
1455 } 1464 }
1456 1465
1457 if (arch->cpuid_parse && cpuid)
1458 arch->cpuid_parse(arch, cpuid);
1459
1460 pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__, 1466 pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
1461 symfs_filename, sym->name, map->unmap_ip(map, sym->start), 1467 symfs_filename, sym->name, map->unmap_ip(map, sym->start),
1462 map->unmap_ip(map, sym->end)); 1468 map->unmap_ip(map, sym->end));
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 9ce575c25fd9..f6ba3560de5e 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_ANNOTATE_H 2#ifndef __PERF_ANNOTATE_H
2#define __PERF_ANNOTATE_H 3#define __PERF_ANNOTATE_H
3 4
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 5547457566a7..a33491416400 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -208,7 +208,7 @@ static int auxtrace_queues__grow(struct auxtrace_queues *queues,
208 208
209static void *auxtrace_copy_data(u64 size, struct perf_session *session) 209static void *auxtrace_copy_data(u64 size, struct perf_session *session)
210{ 210{
211 int fd = perf_data_file__fd(session->file); 211 int fd = perf_data__fd(session->data);
212 void *p; 212 void *p;
213 ssize_t ret; 213 ssize_t ret;
214 214
@@ -305,7 +305,7 @@ static int auxtrace_queues__add_event_buffer(struct auxtrace_queues *queues,
305 if (session->one_mmap) { 305 if (session->one_mmap) {
306 buffer->data = buffer->data_offset - session->one_mmap_offset + 306 buffer->data = buffer->data_offset - session->one_mmap_offset +
307 session->one_mmap_addr; 307 session->one_mmap_addr;
308 } else if (perf_data_file__is_pipe(session->file)) { 308 } else if (perf_data__is_pipe(session->data)) {
309 buffer->data = auxtrace_copy_data(buffer->size, session); 309 buffer->data = auxtrace_copy_data(buffer->size, session);
310 if (!buffer->data) 310 if (!buffer->data)
311 return -ENOMEM; 311 return -ENOMEM;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 33b5e6cdf38c..d19e11b68de7 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -378,7 +378,7 @@ struct addr_filters {
378static inline u64 auxtrace_mmap__read_snapshot_head(struct auxtrace_mmap *mm) 378static inline u64 auxtrace_mmap__read_snapshot_head(struct auxtrace_mmap *mm)
379{ 379{
380 struct perf_event_mmap_page *pc = mm->userpg; 380 struct perf_event_mmap_page *pc = mm->userpg;
381 u64 head = ACCESS_ONCE(pc->aux_head); 381 u64 head = READ_ONCE(pc->aux_head);
382 382
383 /* Ensure all reads are done after we read the head */ 383 /* Ensure all reads are done after we read the head */
384 rmb(); 384 rmb();
@@ -389,7 +389,7 @@ static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm)
389{ 389{
390 struct perf_event_mmap_page *pc = mm->userpg; 390 struct perf_event_mmap_page *pc = mm->userpg;
391#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) 391#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT)
392 u64 head = ACCESS_ONCE(pc->aux_head); 392 u64 head = READ_ONCE(pc->aux_head);
393#else 393#else
394 u64 head = __sync_val_compare_and_swap(&pc->aux_head, 0, 0); 394 u64 head = __sync_val_compare_and_swap(&pc->aux_head, 0, 0);
395#endif 395#endif
diff --git a/tools/perf/util/block-range.c b/tools/perf/util/block-range.c
index 7b3e1d75d803..f1451c987eec 100644
--- a/tools/perf/util/block-range.c
+++ b/tools/perf/util/block-range.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "block-range.h" 2#include "block-range.h"
2#include "annotate.h" 3#include "annotate.h"
3 4
diff --git a/tools/perf/util/block-range.h b/tools/perf/util/block-range.h
index a8c841381131..a5ba719d69fb 100644
--- a/tools/perf/util/block-range.h
+++ b/tools/perf/util/block-range.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_BLOCK_RANGE_H 2#ifndef __PERF_BLOCK_RANGE_H
2#define __PERF_BLOCK_RANGE_H 3#define __PERF_BLOCK_RANGE_H
3 4
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 4a1264c66101..72c107fcbc5a 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * bpf-loader.c 3 * bpf-loader.c
3 * 4 *
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 48863867878b..5d3aefd6fae7 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> 3 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
3 * Copyright (C) 2015, Huawei Inc. 4 * Copyright (C) 2015, Huawei Inc.
diff --git a/tools/perf/util/bpf-prologue.c b/tools/perf/util/bpf-prologue.c
index 827f9140f3b8..29347756b0af 100644
--- a/tools/perf/util/bpf-prologue.c
+++ b/tools/perf/util/bpf-prologue.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * bpf-prologue.c 3 * bpf-prologue.c
3 * 4 *
diff --git a/tools/perf/util/bpf-prologue.h b/tools/perf/util/bpf-prologue.h
index ba564838375f..c50c7358009f 100644
--- a/tools/perf/util/bpf-prologue.h
+++ b/tools/perf/util/bpf-prologue.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2015, He Kuang <hekuang@huawei.com> 3 * Copyright (C) 2015, He Kuang <hekuang@huawei.com>
3 * Copyright (C) 2015, Huawei Inc. 4 * Copyright (C) 2015, Huawei Inc.
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index c1a06fcd7e70..7f8553630c4d 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * build-id.c 3 * build-id.c
3 * 4 *
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index c94b0dcbfd74..f0c565164a97 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_BUILD_ID_H_ 2#ifndef PERF_BUILD_ID_H_
2#define PERF_BUILD_ID_H_ 1 3#define PERF_BUILD_ID_H_ 1
3 4
diff --git a/tools/perf/util/c++/clang-c.h b/tools/perf/util/c++/clang-c.h
index ccafcf72b37a..e513366f2ee0 100644
--- a/tools/perf/util/c++/clang-c.h
+++ b/tools/perf/util/c++/clang-c.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_UTIL_CLANG_C_H 2#ifndef PERF_UTIL_CLANG_C_H
2#define PERF_UTIL_CLANG_C_H 3#define PERF_UTIL_CLANG_C_H
3 4
diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp
index 9b11e8c82798..a4014d786676 100644
--- a/tools/perf/util/c++/clang-test.cpp
+++ b/tools/perf/util/c++/clang-test.cpp
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "clang.h" 2#include "clang.h"
2#include "clang-c.h" 3#include "clang-c.h"
3#include "llvm/IR/Function.h" 4#include "llvm/IR/Function.h"
diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
index 1e974152cac2..1bfc946e37dc 100644
--- a/tools/perf/util/c++/clang.cpp
+++ b/tools/perf/util/c++/clang.cpp
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * llvm C frontend for perf. Support dynamically compile C file 3 * llvm C frontend for perf. Support dynamically compile C file
3 * 4 *
diff --git a/tools/perf/util/c++/clang.h b/tools/perf/util/c++/clang.h
index dd8b0427550d..6ce33e22f23c 100644
--- a/tools/perf/util/c++/clang.h
+++ b/tools/perf/util/c++/clang.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_UTIL_CLANG_H 2#ifndef PERF_UTIL_CLANG_H
2#define PERF_UTIL_CLANG_H 3#define PERF_UTIL_CLANG_H
3 4
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 0175765c05b9..9f2e36ef5072 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_CACHE_H 2#ifndef __PERF_CACHE_H
2#define __PERF_CACHE_H 3#define __PERF_CACHE_H
3 4
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 510b513e0f01..082505d08d72 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2009-2011, Frederic Weisbecker <fweisbec@gmail.com> 3 * Copyright (C) 2009-2011, Frederic Weisbecker <fweisbec@gmail.com>
3 * 4 *
@@ -65,8 +66,6 @@ static int parse_callchain_mode(const char *value)
65 callchain_param.mode = CHAIN_FOLDED; 66 callchain_param.mode = CHAIN_FOLDED;
66 return 0; 67 return 0;
67 } 68 }
68
69 pr_err("Invalid callchain mode: %s\n", value);
70 return -1; 69 return -1;
71} 70}
72 71
@@ -82,8 +81,6 @@ static int parse_callchain_order(const char *value)
82 callchain_param.order_set = true; 81 callchain_param.order_set = true;
83 return 0; 82 return 0;
84 } 83 }
85
86 pr_err("Invalid callchain order: %s\n", value);
87 return -1; 84 return -1;
88} 85}
89 86
@@ -105,8 +102,6 @@ static int parse_callchain_sort_key(const char *value)
105 callchain_param.branch_callstack = 1; 102 callchain_param.branch_callstack = 1;
106 return 0; 103 return 0;
107 } 104 }
108
109 pr_err("Invalid callchain sort key: %s\n", value);
110 return -1; 105 return -1;
111} 106}
112 107
@@ -124,8 +119,6 @@ static int parse_callchain_value(const char *value)
124 callchain_param.value = CCVAL_COUNT; 119 callchain_param.value = CCVAL_COUNT;
125 return 0; 120 return 0;
126 } 121 }
127
128 pr_err("Invalid callchain config key: %s\n", value);
129 return -1; 122 return -1;
130} 123}
131 124
@@ -319,12 +312,27 @@ int perf_callchain_config(const char *var, const char *value)
319 312
320 return ret; 313 return ret;
321 } 314 }
322 if (!strcmp(var, "print-type")) 315 if (!strcmp(var, "print-type")){
323 return parse_callchain_mode(value); 316 int ret;
324 if (!strcmp(var, "order")) 317 ret = parse_callchain_mode(value);
325 return parse_callchain_order(value); 318 if (ret == -1)
326 if (!strcmp(var, "sort-key")) 319 pr_err("Invalid callchain mode: %s\n", value);
327 return parse_callchain_sort_key(value); 320 return ret;
321 }
322 if (!strcmp(var, "order")){
323 int ret;
324 ret = parse_callchain_order(value);
325 if (ret == -1)
326 pr_err("Invalid callchain order: %s\n", value);
327 return ret;
328 }
329 if (!strcmp(var, "sort-key")){
330 int ret;
331 ret = parse_callchain_sort_key(value);
332 if (ret == -1)
333 pr_err("Invalid callchain sort key: %s\n", value);
334 return ret;
335 }
328 if (!strcmp(var, "threshold")) { 336 if (!strcmp(var, "threshold")) {
329 callchain_param.min_percent = strtod(value, &endptr); 337 callchain_param.min_percent = strtod(value, &endptr);
330 if (value == endptr) { 338 if (value == endptr) {
@@ -559,6 +567,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
559 call->ip = cursor_node->ip; 567 call->ip = cursor_node->ip;
560 call->ms.sym = cursor_node->sym; 568 call->ms.sym = cursor_node->sym;
561 call->ms.map = map__get(cursor_node->map); 569 call->ms.map = map__get(cursor_node->map);
570 call->srcline = cursor_node->srcline;
562 571
563 if (cursor_node->branch) { 572 if (cursor_node->branch) {
564 call->branch_count = 1; 573 call->branch_count = 1;
@@ -637,99 +646,120 @@ enum match_result {
637 MATCH_GT, 646 MATCH_GT,
638}; 647};
639 648
640static enum match_result match_chain_srcline(struct callchain_cursor_node *node, 649static enum match_result match_chain_strings(const char *left,
641 struct callchain_list *cnode) 650 const char *right)
642{ 651{
643 char *left = NULL;
644 char *right = NULL;
645 enum match_result ret = MATCH_EQ; 652 enum match_result ret = MATCH_EQ;
646 int cmp; 653 int cmp;
647 654
648 if (cnode->ms.map)
649 left = get_srcline(cnode->ms.map->dso,
650 map__rip_2objdump(cnode->ms.map, cnode->ip),
651 cnode->ms.sym, true, false);
652 if (node->map)
653 right = get_srcline(node->map->dso,
654 map__rip_2objdump(node->map, node->ip),
655 node->sym, true, false);
656
657 if (left && right) 655 if (left && right)
658 cmp = strcmp(left, right); 656 cmp = strcmp(left, right);
659 else if (!left && right) 657 else if (!left && right)
660 cmp = 1; 658 cmp = 1;
661 else if (left && !right) 659 else if (left && !right)
662 cmp = -1; 660 cmp = -1;
663 else if (cnode->ip == node->ip)
664 cmp = 0;
665 else 661 else
666 cmp = (cnode->ip < node->ip) ? -1 : 1; 662 return MATCH_ERROR;
667 663
668 if (cmp != 0) 664 if (cmp != 0)
669 ret = cmp < 0 ? MATCH_LT : MATCH_GT; 665 ret = cmp < 0 ? MATCH_LT : MATCH_GT;
670 666
671 free_srcline(left);
672 free_srcline(right);
673 return ret; 667 return ret;
674} 668}
675 669
670/*
671 * We need to always use relative addresses because we're aggregating
672 * callchains from multiple threads, i.e. different address spaces, so
673 * comparing absolute addresses make no sense as a symbol in a DSO may end up
674 * in a different address when used in a different binary or even the same
675 * binary but with some sort of address randomization technique, thus we need
676 * to compare just relative addresses. -acme
677 */
678static enum match_result match_chain_dso_addresses(struct map *left_map, u64 left_ip,
679 struct map *right_map, u64 right_ip)
680{
681 struct dso *left_dso = left_map ? left_map->dso : NULL;
682 struct dso *right_dso = right_map ? right_map->dso : NULL;
683
684 if (left_dso != right_dso)
685 return left_dso < right_dso ? MATCH_LT : MATCH_GT;
686
687 if (left_ip != right_ip)
688 return left_ip < right_ip ? MATCH_LT : MATCH_GT;
689
690 return MATCH_EQ;
691}
692
676static enum match_result match_chain(struct callchain_cursor_node *node, 693static enum match_result match_chain(struct callchain_cursor_node *node,
677 struct callchain_list *cnode) 694 struct callchain_list *cnode)
678{ 695{
679 struct symbol *sym = node->sym; 696 enum match_result match = MATCH_ERROR;
680 u64 left, right;
681
682 if (callchain_param.key == CCKEY_SRCLINE) {
683 enum match_result match = match_chain_srcline(node, cnode);
684 697
698 switch (callchain_param.key) {
699 case CCKEY_SRCLINE:
700 match = match_chain_strings(cnode->srcline, node->srcline);
685 if (match != MATCH_ERROR) 701 if (match != MATCH_ERROR)
686 return match; 702 break;
703 /* otherwise fall-back to symbol-based comparison below */
704 __fallthrough;
705 case CCKEY_FUNCTION:
706 if (node->sym && cnode->ms.sym) {
707 /*
708 * Compare inlined frames based on their symbol name
709 * because different inlined frames will have the same
710 * symbol start. Otherwise do a faster comparison based
711 * on the symbol start address.
712 */
713 if (cnode->ms.sym->inlined || node->sym->inlined) {
714 match = match_chain_strings(cnode->ms.sym->name,
715 node->sym->name);
716 if (match != MATCH_ERROR)
717 break;
718 } else {
719 match = match_chain_dso_addresses(cnode->ms.map, cnode->ms.sym->start,
720 node->map, node->sym->start);
721 break;
722 }
723 }
724 /* otherwise fall-back to IP-based comparison below */
725 __fallthrough;
726 case CCKEY_ADDRESS:
727 default:
728 match = match_chain_dso_addresses(cnode->ms.map, cnode->ip, node->map, node->ip);
729 break;
687 } 730 }
688 731
689 if (cnode->ms.sym && sym && callchain_param.key == CCKEY_FUNCTION) { 732 if (match == MATCH_EQ && node->branch) {
690 left = cnode->ms.sym->start; 733 cnode->branch_count++;
691 right = sym->start;
692 } else {
693 left = cnode->ip;
694 right = node->ip;
695 }
696 734
697 if (left == right) { 735 if (node->branch_from) {
698 if (node->branch) { 736 /*
699 cnode->branch_count++; 737 * It's "to" of a branch
738 */
739 cnode->brtype_stat.branch_to = true;
700 740
701 if (node->branch_from) { 741 if (node->branch_flags.predicted)
702 /* 742 cnode->predicted_count++;
703 * It's "to" of a branch
704 */
705 cnode->brtype_stat.branch_to = true;
706 743
707 if (node->branch_flags.predicted) 744 if (node->branch_flags.abort)
708 cnode->predicted_count++; 745 cnode->abort_count++;
709 746
710 if (node->branch_flags.abort) 747 branch_type_count(&cnode->brtype_stat,
711 cnode->abort_count++; 748 &node->branch_flags,
712 749 node->branch_from,
713 branch_type_count(&cnode->brtype_stat, 750 node->ip);
714 &node->branch_flags, 751 } else {
715 node->branch_from, 752 /*
716 node->ip); 753 * It's "from" of a branch
717 } else { 754 */
718 /* 755 cnode->brtype_stat.branch_to = false;
719 * It's "from" of a branch 756 cnode->cycles_count += node->branch_flags.cycles;
720 */ 757 cnode->iter_count += node->nr_loop_iter;
721 cnode->brtype_stat.branch_to = false; 758 cnode->iter_cycles += node->iter_cycles;
722 cnode->cycles_count +=
723 node->branch_flags.cycles;
724 cnode->iter_count += node->nr_loop_iter;
725 cnode->iter_cycles += node->iter_cycles;
726 }
727 } 759 }
728
729 return MATCH_EQ;
730 } 760 }
731 761
732 return left > right ? MATCH_GT : MATCH_LT; 762 return match;
733} 763}
734 764
735/* 765/*
@@ -958,7 +988,7 @@ merge_chain_branch(struct callchain_cursor *cursor,
958 list_for_each_entry_safe(list, next_list, &src->val, list) { 988 list_for_each_entry_safe(list, next_list, &src->val, list) {
959 callchain_cursor_append(cursor, list->ip, 989 callchain_cursor_append(cursor, list->ip,
960 list->ms.map, list->ms.sym, 990 list->ms.map, list->ms.sym,
961 false, NULL, 0, 0, 0); 991 false, NULL, 0, 0, 0, list->srcline);
962 list_del(&list->list); 992 list_del(&list->list);
963 map__zput(list->ms.map); 993 map__zput(list->ms.map);
964 free(list); 994 free(list);
@@ -998,7 +1028,8 @@ int callchain_merge(struct callchain_cursor *cursor,
998int callchain_cursor_append(struct callchain_cursor *cursor, 1028int callchain_cursor_append(struct callchain_cursor *cursor,
999 u64 ip, struct map *map, struct symbol *sym, 1029 u64 ip, struct map *map, struct symbol *sym,
1000 bool branch, struct branch_flags *flags, 1030 bool branch, struct branch_flags *flags,
1001 int nr_loop_iter, u64 iter_cycles, u64 branch_from) 1031 int nr_loop_iter, u64 iter_cycles, u64 branch_from,
1032 const char *srcline)
1002{ 1033{
1003 struct callchain_cursor_node *node = *cursor->last; 1034 struct callchain_cursor_node *node = *cursor->last;
1004 1035
@@ -1017,6 +1048,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
1017 node->branch = branch; 1048 node->branch = branch;
1018 node->nr_loop_iter = nr_loop_iter; 1049 node->nr_loop_iter = nr_loop_iter;
1019 node->iter_cycles = iter_cycles; 1050 node->iter_cycles = iter_cycles;
1051 node->srcline = srcline;
1020 1052
1021 if (flags) 1053 if (flags)
1022 memcpy(&node->branch_flags, flags, 1054 memcpy(&node->branch_flags, flags,
@@ -1059,10 +1091,8 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
1059{ 1091{
1060 al->map = node->map; 1092 al->map = node->map;
1061 al->sym = node->sym; 1093 al->sym = node->sym;
1062 if (node->map) 1094 al->srcline = node->srcline;
1063 al->addr = node->map->map_ip(node->map, node->ip); 1095 al->addr = node->ip;
1064 else
1065 al->addr = node->ip;
1066 1096
1067 if (al->sym == NULL) { 1097 if (al->sym == NULL) {
1068 if (hide_unresolved) 1098 if (hide_unresolved)
@@ -1104,16 +1134,15 @@ char *callchain_list__sym_name(struct callchain_list *cl,
1104 int printed; 1134 int printed;
1105 1135
1106 if (cl->ms.sym) { 1136 if (cl->ms.sym) {
1107 if (show_srcline && cl->ms.map && !cl->srcline) 1137 const char *inlined = cl->ms.sym->inlined ? " (inlined)" : "";
1108 cl->srcline = get_srcline(cl->ms.map->dso, 1138
1109 map__rip_2objdump(cl->ms.map, 1139 if (show_srcline && cl->srcline)
1110 cl->ip), 1140 printed = scnprintf(bf, bfsize, "%s %s%s",
1111 cl->ms.sym, false, show_addr); 1141 cl->ms.sym->name, cl->srcline,
1112 if (cl->srcline) 1142 inlined);
1113 printed = scnprintf(bf, bfsize, "%s %s",
1114 cl->ms.sym->name, cl->srcline);
1115 else 1143 else
1116 printed = scnprintf(bf, bfsize, "%s", cl->ms.sym->name); 1144 printed = scnprintf(bf, bfsize, "%s%s",
1145 cl->ms.sym->name, inlined);
1117 } else 1146 } else
1118 printed = scnprintf(bf, bfsize, "%#" PRIx64, cl->ip); 1147 printed = scnprintf(bf, bfsize, "%#" PRIx64, cl->ip);
1119 1148
@@ -1521,7 +1550,7 @@ int callchain_cursor__copy(struct callchain_cursor *dst,
1521 node->branch, &node->branch_flags, 1550 node->branch, &node->branch_flags,
1522 node->nr_loop_iter, 1551 node->nr_loop_iter,
1523 node->iter_cycles, 1552 node->iter_cycles,
1524 node->branch_from); 1553 node->branch_from, node->srcline);
1525 if (rc) 1554 if (rc)
1526 break; 1555 break;
1527 1556
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 1ed6fc61d0a5..b79ef2478a57 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_CALLCHAIN_H 2#ifndef __PERF_CALLCHAIN_H
2#define __PERF_CALLCHAIN_H 3#define __PERF_CALLCHAIN_H
3 4
@@ -121,7 +122,7 @@ struct callchain_list {
121 u64 iter_count; 122 u64 iter_count;
122 u64 iter_cycles; 123 u64 iter_cycles;
123 struct branch_type_stat brtype_stat; 124 struct branch_type_stat brtype_stat;
124 char *srcline; 125 const char *srcline;
125 struct list_head list; 126 struct list_head list;
126}; 127};
127 128
@@ -135,6 +136,7 @@ struct callchain_cursor_node {
135 u64 ip; 136 u64 ip;
136 struct map *map; 137 struct map *map;
137 struct symbol *sym; 138 struct symbol *sym;
139 const char *srcline;
138 bool branch; 140 bool branch;
139 struct branch_flags branch_flags; 141 struct branch_flags branch_flags;
140 u64 branch_from; 142 u64 branch_from;
@@ -201,7 +203,8 @@ static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
201int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, 203int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
202 struct map *map, struct symbol *sym, 204 struct map *map, struct symbol *sym,
203 bool branch, struct branch_flags *flags, 205 bool branch, struct branch_flags *flags,
204 int nr_loop_iter, u64 iter_cycles, u64 branch_from); 206 int nr_loop_iter, u64 iter_cycles, u64 branch_from,
207 const char *srcline);
205 208
206/* Close a cursor writing session. Initialize for the reader */ 209/* Close a cursor writing session. Initialize for the reader */
207static inline void callchain_cursor_commit(struct callchain_cursor *cursor) 210static inline void callchain_cursor_commit(struct callchain_cursor *cursor)
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 0e77bc9e5f3c..d9ffc1e6eb39 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "util.h" 2#include "util.h"
2#include "../perf.h" 3#include "../perf.h"
3#include <subcmd/parse-options.h> 4#include <subcmd/parse-options.h>
diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h
index d91966b97cbd..afafc87e9201 100644
--- a/tools/perf/util/cgroup.h
+++ b/tools/perf/util/cgroup.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __CGROUP_H__ 2#ifndef __CGROUP_H__
2#define __CGROUP_H__ 3#define __CGROUP_H__
3 4
diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 4b4f00df58a8..ca0fff6272be 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <sched.h> 3#include <sched.h>
3#include "util.h" 4#include "util.h"
diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
index 94a5a7d829d5..78216b1015c4 100644
--- a/tools/perf/util/cloexec.h
+++ b/tools/perf/util/cloexec.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_CLOEXEC_H 2#ifndef __PERF_CLOEXEC_H
2#define __PERF_CLOEXEC_H 3#define __PERF_CLOEXEC_H
3 4
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index dbbf89b050a5..39e628b8938e 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/kernel.h> 2#include <linux/kernel.h>
2#include "cache.h" 3#include "cache.h"
3#include "config.h" 4#include "config.h"
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h
index 52122bcc3170..22777b1812ee 100644
--- a/tools/perf/util/color.h
+++ b/tools/perf/util/color.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_COLOR_H 2#ifndef __PERF_COLOR_H
2#define __PERF_COLOR_H 3#define __PERF_COLOR_H
3 4
diff --git a/tools/perf/util/comm.c b/tools/perf/util/comm.c
index 7bc981b6bf29..7798a2cc8a86 100644
--- a/tools/perf/util/comm.c
+++ b/tools/perf/util/comm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "comm.h" 2#include "comm.h"
2#include "util.h" 3#include "util.h"
3#include <errno.h> 4#include <errno.h>
@@ -5,6 +6,7 @@
5#include <stdio.h> 6#include <stdio.h>
6#include <string.h> 7#include <string.h>
7#include <linux/refcount.h> 8#include <linux/refcount.h>
9#include "rwsem.h"
8 10
9struct comm_str { 11struct comm_str {
10 char *str; 12 char *str;
@@ -14,6 +16,7 @@ struct comm_str {
14 16
15/* Should perhaps be moved to struct machine */ 17/* Should perhaps be moved to struct machine */
16static struct rb_root comm_str_root; 18static struct rb_root comm_str_root;
19static struct rw_semaphore comm_str_lock = {.lock = PTHREAD_RWLOCK_INITIALIZER,};
17 20
18static struct comm_str *comm_str__get(struct comm_str *cs) 21static struct comm_str *comm_str__get(struct comm_str *cs)
19{ 22{
@@ -25,7 +28,9 @@ static struct comm_str *comm_str__get(struct comm_str *cs)
25static void comm_str__put(struct comm_str *cs) 28static void comm_str__put(struct comm_str *cs)
26{ 29{
27 if (cs && refcount_dec_and_test(&cs->refcnt)) { 30 if (cs && refcount_dec_and_test(&cs->refcnt)) {
31 down_write(&comm_str_lock);
28 rb_erase(&cs->rb_node, &comm_str_root); 32 rb_erase(&cs->rb_node, &comm_str_root);
33 up_write(&comm_str_lock);
29 zfree(&cs->str); 34 zfree(&cs->str);
30 free(cs); 35 free(cs);
31 } 36 }
@@ -50,7 +55,8 @@ static struct comm_str *comm_str__alloc(const char *str)
50 return cs; 55 return cs;
51} 56}
52 57
53static struct comm_str *comm_str__findnew(const char *str, struct rb_root *root) 58static
59struct comm_str *__comm_str__findnew(const char *str, struct rb_root *root)
54{ 60{
55 struct rb_node **p = &root->rb_node; 61 struct rb_node **p = &root->rb_node;
56 struct rb_node *parent = NULL; 62 struct rb_node *parent = NULL;
@@ -81,6 +87,17 @@ static struct comm_str *comm_str__findnew(const char *str, struct rb_root *root)
81 return new; 87 return new;
82} 88}
83 89
90static struct comm_str *comm_str__findnew(const char *str, struct rb_root *root)
91{
92 struct comm_str *cs;
93
94 down_write(&comm_str_lock);
95 cs = __comm_str__findnew(str, root);
96 up_write(&comm_str_lock);
97
98 return cs;
99}
100
84struct comm *comm__new(const char *str, u64 timestamp, bool exec) 101struct comm *comm__new(const char *str, u64 timestamp, bool exec)
85{ 102{
86 struct comm *comm = zalloc(sizeof(*comm)); 103 struct comm *comm = zalloc(sizeof(*comm));
diff --git a/tools/perf/util/comm.h b/tools/perf/util/comm.h
index 71c9c39340d4..3e5c438fe85e 100644
--- a/tools/perf/util/comm.h
+++ b/tools/perf/util/comm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_COMM_H 2#ifndef __PERF_COMM_H
2#define __PERF_COMM_H 3#define __PERF_COMM_H
3 4
diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h
index 67fd1bb7c2b7..ecca688a25fb 100644
--- a/tools/perf/util/compress.h
+++ b/tools/perf/util/compress.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_COMPRESS_H 2#ifndef PERF_COMPRESS_H
2#define PERF_COMPRESS_H 3#define PERF_COMPRESS_H
3 4
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index bc75596f9e79..84eb9393c7db 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * config.c 3 * config.c
3 * 4 *
@@ -700,10 +701,7 @@ struct perf_config_set *perf_config_set__new(void)
700 701
701 if (set) { 702 if (set) {
702 INIT_LIST_HEAD(&set->sections); 703 INIT_LIST_HEAD(&set->sections);
703 if (perf_config_set__init(set) < 0) { 704 perf_config_set__init(set);
704 perf_config_set__delete(set);
705 set = NULL;
706 }
707 } 705 }
708 706
709 return set; 707 return set;
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
index b6bb11f3f165..baf82bf227ac 100644
--- a/tools/perf/util/config.h
+++ b/tools/perf/util/config.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_CONFIG_H 2#ifndef __PERF_CONFIG_H
2#define __PERF_CONFIG_H 3#define __PERF_CONFIG_H
3 4
diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c
index c4af82ab7808..03032b410c29 100644
--- a/tools/perf/util/counts.c
+++ b/tools/perf/util/counts.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include "evsel.h" 4#include "evsel.h"
diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h
index cb45a6aecf9d..0d1050ccc586 100644
--- a/tools/perf/util/counts.h
+++ b/tools/perf/util/counts.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_COUNTS_H 2#ifndef __PERF_COUNTS_H
2#define __PERF_COUNTS_H 3#define __PERF_COUNTS_H
3 4
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 37b3bb79ee08..1ccbd3342069 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "util.h" 2#include "util.h"
2#include <api/fs/fs.h> 3#include <api/fs/fs.h>
3#include "../perf.h" 4#include "../perf.h"
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 6b8bff87481d..ed8999d1a640 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_CPUMAP_H 2#ifndef __PERF_CPUMAP_H
2#define __PERF_CPUMAP_H 3#define __PERF_CPUMAP_H
3 4
diff --git a/tools/perf/util/ctype.c b/tools/perf/util/ctype.c
index 4b261c2ec0f1..ee4c1e8ed54b 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/perf/util/ctype.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Sane locale-independent, ASCII ctype. 3 * Sane locale-independent, ASCII ctype.
3 * 4 *
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 2346cecb8ea2..5744c12641a5 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -1577,10 +1577,10 @@ int bt_convert__perf2ctf(const char *input, const char *path,
1577 struct perf_data_convert_opts *opts) 1577 struct perf_data_convert_opts *opts)
1578{ 1578{
1579 struct perf_session *session; 1579 struct perf_session *session;
1580 struct perf_data_file file = { 1580 struct perf_data data = {
1581 .path = input, 1581 .file.path = input,
1582 .mode = PERF_DATA_MODE_READ, 1582 .mode = PERF_DATA_MODE_READ,
1583 .force = opts->force, 1583 .force = opts->force,
1584 }; 1584 };
1585 struct convert c = { 1585 struct convert c = {
1586 .tool = { 1586 .tool = {
@@ -1619,7 +1619,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
1619 1619
1620 err = -1; 1620 err = -1;
1621 /* perf.data session */ 1621 /* perf.data session */
1622 session = perf_session__new(&file, 0, &c.tool); 1622 session = perf_session__new(&data, 0, &c.tool);
1623 if (!session) 1623 if (!session)
1624 goto free_writer; 1624 goto free_writer;
1625 1625
@@ -1650,7 +1650,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
1650 1650
1651 fprintf(stderr, 1651 fprintf(stderr,
1652 "[ perf data convert: Converted '%s' into CTF data '%s' ]\n", 1652 "[ perf data convert: Converted '%s' into CTF data '%s' ]\n",
1653 file.path, path); 1653 data.file.path, path);
1654 1654
1655 fprintf(stderr, 1655 fprintf(stderr,
1656 "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples", 1656 "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
diff --git a/tools/perf/util/data-convert-bt.h b/tools/perf/util/data-convert-bt.h
index 9a3b587f76c1..821674d63c4e 100644
--- a/tools/perf/util/data-convert-bt.h
+++ b/tools/perf/util/data-convert-bt.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __DATA_CONVERT_BT_H 2#ifndef __DATA_CONVERT_BT_H
2#define __DATA_CONVERT_BT_H 3#define __DATA_CONVERT_BT_H
3#include "data-convert.h" 4#include "data-convert.h"
diff --git a/tools/perf/util/data-convert.h b/tools/perf/util/data-convert.h
index 5314962fe95b..af90b6076c06 100644
--- a/tools/perf/util/data-convert.h
+++ b/tools/perf/util/data-convert.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __DATA_CONVERT_H 2#ifndef __DATA_CONVERT_H
2#define __DATA_CONVERT_H 3#define __DATA_CONVERT_H
3 4
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 263f5a906ba5..48094fde0a68 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -1,8 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include <sys/types.h> 4#include <sys/types.h>
4#include <sys/stat.h> 5#include <sys/stat.h>
5#include <errno.h> 6#include <errno.h>
7#include <fcntl.h>
6#include <unistd.h> 8#include <unistd.h>
7#include <string.h> 9#include <string.h>
8 10
@@ -20,56 +22,56 @@
20#endif 22#endif
21#endif 23#endif
22 24
23static bool check_pipe(struct perf_data_file *file) 25static bool check_pipe(struct perf_data *data)
24{ 26{
25 struct stat st; 27 struct stat st;
26 bool is_pipe = false; 28 bool is_pipe = false;
27 int fd = perf_data_file__is_read(file) ? 29 int fd = perf_data__is_read(data) ?
28 STDIN_FILENO : STDOUT_FILENO; 30 STDIN_FILENO : STDOUT_FILENO;
29 31
30 if (!file->path) { 32 if (!data->file.path) {
31 if (!fstat(fd, &st) && S_ISFIFO(st.st_mode)) 33 if (!fstat(fd, &st) && S_ISFIFO(st.st_mode))
32 is_pipe = true; 34 is_pipe = true;
33 } else { 35 } else {
34 if (!strcmp(file->path, "-")) 36 if (!strcmp(data->file.path, "-"))
35 is_pipe = true; 37 is_pipe = true;
36 } 38 }
37 39
38 if (is_pipe) 40 if (is_pipe)
39 file->fd = fd; 41 data->file.fd = fd;
40 42
41 return file->is_pipe = is_pipe; 43 return data->is_pipe = is_pipe;
42} 44}
43 45
44static int check_backup(struct perf_data_file *file) 46static int check_backup(struct perf_data *data)
45{ 47{
46 struct stat st; 48 struct stat st;
47 49
48 if (!stat(file->path, &st) && st.st_size) { 50 if (!stat(data->file.path, &st) && st.st_size) {
49 /* TODO check errors properly */ 51 /* TODO check errors properly */
50 char oldname[PATH_MAX]; 52 char oldname[PATH_MAX];
51 snprintf(oldname, sizeof(oldname), "%s.old", 53 snprintf(oldname, sizeof(oldname), "%s.old",
52 file->path); 54 data->file.path);
53 unlink(oldname); 55 unlink(oldname);
54 rename(file->path, oldname); 56 rename(data->file.path, oldname);
55 } 57 }
56 58
57 return 0; 59 return 0;
58} 60}
59 61
60static int open_file_read(struct perf_data_file *file) 62static int open_file_read(struct perf_data *data)
61{ 63{
62 struct stat st; 64 struct stat st;
63 int fd; 65 int fd;
64 char sbuf[STRERR_BUFSIZE]; 66 char sbuf[STRERR_BUFSIZE];
65 67
66 fd = open(file->path, O_RDONLY); 68 fd = open(data->file.path, O_RDONLY);
67 if (fd < 0) { 69 if (fd < 0) {
68 int err = errno; 70 int err = errno;
69 71
70 pr_err("failed to open %s: %s", file->path, 72 pr_err("failed to open %s: %s", data->file.path,
71 str_error_r(err, sbuf, sizeof(sbuf))); 73 str_error_r(err, sbuf, sizeof(sbuf)));
72 if (err == ENOENT && !strcmp(file->path, "perf.data")) 74 if (err == ENOENT && !strcmp(data->file.path, "perf.data"))
73 pr_err(" (try 'perf record' first)"); 75 pr_err(" (try 'perf record' first)");
74 pr_err("\n"); 76 pr_err("\n");
75 return -err; 77 return -err;
@@ -78,19 +80,19 @@ static int open_file_read(struct perf_data_file *file)
78 if (fstat(fd, &st) < 0) 80 if (fstat(fd, &st) < 0)
79 goto out_close; 81 goto out_close;
80 82
81 if (!file->force && st.st_uid && (st.st_uid != geteuid())) { 83 if (!data->force && st.st_uid && (st.st_uid != geteuid())) {
82 pr_err("File %s not owned by current user or root (use -f to override)\n", 84 pr_err("File %s not owned by current user or root (use -f to override)\n",
83 file->path); 85 data->file.path);
84 goto out_close; 86 goto out_close;
85 } 87 }
86 88
87 if (!st.st_size) { 89 if (!st.st_size) {
88 pr_info("zero-sized file (%s), nothing to do!\n", 90 pr_info("zero-sized data (%s), nothing to do!\n",
89 file->path); 91 data->file.path);
90 goto out_close; 92 goto out_close;
91 } 93 }
92 94
93 file->size = st.st_size; 95 data->size = st.st_size;
94 return fd; 96 return fd;
95 97
96 out_close: 98 out_close:
@@ -98,49 +100,49 @@ static int open_file_read(struct perf_data_file *file)
98 return -1; 100 return -1;
99} 101}
100 102
101static int open_file_write(struct perf_data_file *file) 103static int open_file_write(struct perf_data *data)
102{ 104{
103 int fd; 105 int fd;
104 char sbuf[STRERR_BUFSIZE]; 106 char sbuf[STRERR_BUFSIZE];
105 107
106 if (check_backup(file)) 108 if (check_backup(data))
107 return -1; 109 return -1;
108 110
109 fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, 111 fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
110 S_IRUSR|S_IWUSR); 112 S_IRUSR|S_IWUSR);
111 113
112 if (fd < 0) 114 if (fd < 0)
113 pr_err("failed to open %s : %s\n", file->path, 115 pr_err("failed to open %s : %s\n", data->file.path,
114 str_error_r(errno, sbuf, sizeof(sbuf))); 116 str_error_r(errno, sbuf, sizeof(sbuf)));
115 117
116 return fd; 118 return fd;
117} 119}
118 120
119static int open_file(struct perf_data_file *file) 121static int open_file(struct perf_data *data)
120{ 122{
121 int fd; 123 int fd;
122 124
123 fd = perf_data_file__is_read(file) ? 125 fd = perf_data__is_read(data) ?
124 open_file_read(file) : open_file_write(file); 126 open_file_read(data) : open_file_write(data);
125 127
126 file->fd = fd; 128 data->file.fd = fd;
127 return fd < 0 ? -1 : 0; 129 return fd < 0 ? -1 : 0;
128} 130}
129 131
130int perf_data_file__open(struct perf_data_file *file) 132int perf_data__open(struct perf_data *data)
131{ 133{
132 if (check_pipe(file)) 134 if (check_pipe(data))
133 return 0; 135 return 0;
134 136
135 if (!file->path) 137 if (!data->file.path)
136 file->path = "perf.data"; 138 data->file.path = "perf.data";
137 139
138 return open_file(file); 140 return open_file(data);
139} 141}
140 142
141void perf_data_file__close(struct perf_data_file *file) 143void perf_data__close(struct perf_data *data)
142{ 144{
143 close(file->fd); 145 close(data->file.fd);
144} 146}
145 147
146ssize_t perf_data_file__write(struct perf_data_file *file, 148ssize_t perf_data_file__write(struct perf_data_file *file,
@@ -149,42 +151,48 @@ ssize_t perf_data_file__write(struct perf_data_file *file,
149 return writen(file->fd, buf, size); 151 return writen(file->fd, buf, size);
150} 152}
151 153
152int perf_data_file__switch(struct perf_data_file *file, 154ssize_t perf_data__write(struct perf_data *data,
155 void *buf, size_t size)
156{
157 return perf_data_file__write(&data->file, buf, size);
158}
159
160int perf_data__switch(struct perf_data *data,
153 const char *postfix, 161 const char *postfix,
154 size_t pos, bool at_exit) 162 size_t pos, bool at_exit)
155{ 163{
156 char *new_filepath; 164 char *new_filepath;
157 int ret; 165 int ret;
158 166
159 if (check_pipe(file)) 167 if (check_pipe(data))
160 return -EINVAL; 168 return -EINVAL;
161 if (perf_data_file__is_read(file)) 169 if (perf_data__is_read(data))
162 return -EINVAL; 170 return -EINVAL;
163 171
164 if (asprintf(&new_filepath, "%s.%s", file->path, postfix) < 0) 172 if (asprintf(&new_filepath, "%s.%s", data->file.path, postfix) < 0)
165 return -ENOMEM; 173 return -ENOMEM;
166 174
167 /* 175 /*
168 * Only fire a warning, don't return error, continue fill 176 * Only fire a warning, don't return error, continue fill
169 * original file. 177 * original file.
170 */ 178 */
171 if (rename(file->path, new_filepath)) 179 if (rename(data->file.path, new_filepath))
172 pr_warning("Failed to rename %s to %s\n", file->path, new_filepath); 180 pr_warning("Failed to rename %s to %s\n", data->file.path, new_filepath);
173 181
174 if (!at_exit) { 182 if (!at_exit) {
175 close(file->fd); 183 close(data->file.fd);
176 ret = perf_data_file__open(file); 184 ret = perf_data__open(data);
177 if (ret < 0) 185 if (ret < 0)
178 goto out; 186 goto out;
179 187
180 if (lseek(file->fd, pos, SEEK_SET) == (off_t)-1) { 188 if (lseek(data->file.fd, pos, SEEK_SET) == (off_t)-1) {
181 ret = -errno; 189 ret = -errno;
182 pr_debug("Failed to lseek to %zu: %s", 190 pr_debug("Failed to lseek to %zu: %s",
183 pos, strerror(errno)); 191 pos, strerror(errno));
184 goto out; 192 goto out;
185 } 193 }
186 } 194 }
187 ret = file->fd; 195 ret = data->file.fd;
188out: 196out:
189 free(new_filepath); 197 free(new_filepath);
190 return ret; 198 return ret;
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index ae510ce16cb1..4828f7feea89 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_DATA_H 2#ifndef __PERF_DATA_H
2#define __PERF_DATA_H 3#define __PERF_DATA_H
3 4
@@ -9,51 +10,57 @@ enum perf_data_mode {
9}; 10};
10 11
11struct perf_data_file { 12struct perf_data_file {
12 const char *path; 13 const char *path;
13 int fd; 14 int fd;
15};
16
17struct perf_data {
18 struct perf_data_file file;
14 bool is_pipe; 19 bool is_pipe;
15 bool force; 20 bool force;
16 unsigned long size; 21 unsigned long size;
17 enum perf_data_mode mode; 22 enum perf_data_mode mode;
18}; 23};
19 24
20static inline bool perf_data_file__is_read(struct perf_data_file *file) 25static inline bool perf_data__is_read(struct perf_data *data)
21{ 26{
22 return file->mode == PERF_DATA_MODE_READ; 27 return data->mode == PERF_DATA_MODE_READ;
23} 28}
24 29
25static inline bool perf_data_file__is_write(struct perf_data_file *file) 30static inline bool perf_data__is_write(struct perf_data *data)
26{ 31{
27 return file->mode == PERF_DATA_MODE_WRITE; 32 return data->mode == PERF_DATA_MODE_WRITE;
28} 33}
29 34
30static inline int perf_data_file__is_pipe(struct perf_data_file *file) 35static inline int perf_data__is_pipe(struct perf_data *data)
31{ 36{
32 return file->is_pipe; 37 return data->is_pipe;
33} 38}
34 39
35static inline int perf_data_file__fd(struct perf_data_file *file) 40static inline int perf_data__fd(struct perf_data *data)
36{ 41{
37 return file->fd; 42 return data->file.fd;
38} 43}
39 44
40static inline unsigned long perf_data_file__size(struct perf_data_file *file) 45static inline unsigned long perf_data__size(struct perf_data *data)
41{ 46{
42 return file->size; 47 return data->size;
43} 48}
44 49
45int perf_data_file__open(struct perf_data_file *file); 50int perf_data__open(struct perf_data *data);
46void perf_data_file__close(struct perf_data_file *file); 51void perf_data__close(struct perf_data *data);
52ssize_t perf_data__write(struct perf_data *data,
53 void *buf, size_t size);
47ssize_t perf_data_file__write(struct perf_data_file *file, 54ssize_t perf_data_file__write(struct perf_data_file *file,
48 void *buf, size_t size); 55 void *buf, size_t size);
49/* 56/*
50 * If at_exit is set, only rename current perf.data to 57 * If at_exit is set, only rename current perf.data to
51 * perf.data.<postfix>, continue write on original file. 58 * perf.data.<postfix>, continue write on original data.
52 * Set at_exit when flushing the last output. 59 * Set at_exit when flushing the last output.
53 * 60 *
54 * Return value is fd of new output. 61 * Return value is fd of new output.
55 */ 62 */
56int perf_data_file__switch(struct perf_data_file *file, 63int perf_data__switch(struct perf_data *data,
57 const char *postfix, 64 const char *postfix,
58 size_t pos, bool at_exit); 65 size_t pos, bool at_exit);
59#endif /* __PERF_DATA_H */ 66#endif /* __PERF_DATA_H */
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index a5b3777ffee6..f3a71db83947 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* For general debugging purposes */ 2/* For general debugging purposes */
2 3
3#include "../perf.h" 4#include "../perf.h"
@@ -111,50 +112,53 @@ int dump_printf(const char *fmt, ...)
111 return ret; 112 return ret;
112} 113}
113 114
114static void trace_event_printer(enum binary_printer_ops op, 115static int trace_event_printer(enum binary_printer_ops op,
115 unsigned int val, void *extra) 116 unsigned int val, void *extra, FILE *fp)
116{ 117{
117 const char *color = PERF_COLOR_BLUE; 118 const char *color = PERF_COLOR_BLUE;
118 union perf_event *event = (union perf_event *)extra; 119 union perf_event *event = (union perf_event *)extra;
119 unsigned char ch = (unsigned char)val; 120 unsigned char ch = (unsigned char)val;
121 int printed = 0;
120 122
121 switch (op) { 123 switch (op) {
122 case BINARY_PRINT_DATA_BEGIN: 124 case BINARY_PRINT_DATA_BEGIN:
123 printf("."); 125 printed += fprintf(fp, ".");
124 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n", 126 printed += color_fprintf(fp, color, "\n. ... raw event: size %d bytes\n",
125 event->header.size); 127 event->header.size);
126 break; 128 break;
127 case BINARY_PRINT_LINE_BEGIN: 129 case BINARY_PRINT_LINE_BEGIN:
128 printf("."); 130 printed += fprintf(fp, ".");
129 break; 131 break;
130 case BINARY_PRINT_ADDR: 132 case BINARY_PRINT_ADDR:
131 color_fprintf(stdout, color, " %04x: ", val); 133 printed += color_fprintf(fp, color, " %04x: ", val);
132 break; 134 break;
133 case BINARY_PRINT_NUM_DATA: 135 case BINARY_PRINT_NUM_DATA:
134 color_fprintf(stdout, color, " %02x", val); 136 printed += color_fprintf(fp, color, " %02x", val);
135 break; 137 break;
136 case BINARY_PRINT_NUM_PAD: 138 case BINARY_PRINT_NUM_PAD:
137 color_fprintf(stdout, color, " "); 139 printed += color_fprintf(fp, color, " ");
138 break; 140 break;
139 case BINARY_PRINT_SEP: 141 case BINARY_PRINT_SEP:
140 color_fprintf(stdout, color, " "); 142 printed += color_fprintf(fp, color, " ");
141 break; 143 break;
142 case BINARY_PRINT_CHAR_DATA: 144 case BINARY_PRINT_CHAR_DATA:
143 color_fprintf(stdout, color, "%c", 145 printed += color_fprintf(fp, color, "%c",
144 isprint(ch) ? ch : '.'); 146 isprint(ch) ? ch : '.');
145 break; 147 break;
146 case BINARY_PRINT_CHAR_PAD: 148 case BINARY_PRINT_CHAR_PAD:
147 color_fprintf(stdout, color, " "); 149 printed += color_fprintf(fp, color, " ");
148 break; 150 break;
149 case BINARY_PRINT_LINE_END: 151 case BINARY_PRINT_LINE_END:
150 color_fprintf(stdout, color, "\n"); 152 printed += color_fprintf(fp, color, "\n");
151 break; 153 break;
152 case BINARY_PRINT_DATA_END: 154 case BINARY_PRINT_DATA_END:
153 printf("\n"); 155 printed += fprintf(fp, "\n");
154 break; 156 break;
155 default: 157 default:
156 break; 158 break;
157 } 159 }
160
161 return printed;
158} 162}
159 163
160void trace_event(union perf_event *event) 164void trace_event(union perf_event *event)
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index c818bdb1c1ab..77445dfc5c7d 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* For debugging general purposes */ 2/* For debugging general purposes */
2#ifndef __PERF_DEBUG_H 3#ifndef __PERF_DEBUG_H
3#define __PERF_DEBUG_H 4#define __PERF_DEBUG_H
diff --git a/tools/perf/util/demangle-java.c b/tools/perf/util/demangle-java.c
index cb66d334f532..e4c486756053 100644
--- a/tools/perf/util/demangle-java.c
+++ b/tools/perf/util/demangle-java.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/perf/util/demangle-java.h b/tools/perf/util/demangle-java.h
index a981c1f968fe..f936c8eabe5d 100644
--- a/tools/perf/util/demangle-java.h
+++ b/tools/perf/util/demangle-java.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_DEMANGLE_JAVA 2#ifndef __PERF_DEMANGLE_JAVA
2#define __PERF_DEMANGLE_JAVA 1 3#define __PERF_DEMANGLE_JAVA 1
3/* 4/*
diff --git a/tools/perf/util/demangle-rust.c b/tools/perf/util/demangle-rust.c
index f9dafa888c06..423afbbd386b 100644
--- a/tools/perf/util/demangle-rust.c
+++ b/tools/perf/util/demangle-rust.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <string.h> 2#include <string.h>
2#include "util.h" 3#include "util.h"
3#include "debug.h" 4#include "debug.h"
diff --git a/tools/perf/util/demangle-rust.h b/tools/perf/util/demangle-rust.h
index 7b41ead7e0dd..2fca618b1aa5 100644
--- a/tools/perf/util/demangle-rust.h
+++ b/tools/perf/util/demangle-rust.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_DEMANGLE_RUST 2#ifndef __PERF_DEMANGLE_RUST
2#define __PERF_DEMANGLE_RUST 1 3#define __PERF_DEMANGLE_RUST 1
3 4
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index b9e087fb8247..d5b6f7f5baff 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <asm/bug.h> 2#include <asm/bug.h>
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include <sys/time.h> 4#include <sys/time.h>
@@ -6,9 +7,11 @@
6#include <sys/stat.h> 7#include <sys/stat.h>
7#include <unistd.h> 8#include <unistd.h>
8#include <errno.h> 9#include <errno.h>
10#include <fcntl.h>
9#include "compress.h" 11#include "compress.h"
10#include "path.h" 12#include "path.h"
11#include "symbol.h" 13#include "symbol.h"
14#include "srcline.h"
12#include "dso.h" 15#include "dso.h"
13#include "machine.h" 16#include "machine.h"
14#include "auxtrace.h" 17#include "auxtrace.h"
@@ -1200,6 +1203,8 @@ struct dso *dso__new(const char *name)
1200 for (i = 0; i < MAP__NR_TYPES; ++i) 1203 for (i = 0; i < MAP__NR_TYPES; ++i)
1201 dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; 1204 dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
1202 dso->data.cache = RB_ROOT; 1205 dso->data.cache = RB_ROOT;
1206 dso->inlined_nodes = RB_ROOT;
1207 dso->srclines = RB_ROOT;
1203 dso->data.fd = -1; 1208 dso->data.fd = -1;
1204 dso->data.status = DSO_DATA_STATUS_UNKNOWN; 1209 dso->data.status = DSO_DATA_STATUS_UNKNOWN;
1205 dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND; 1210 dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
@@ -1231,6 +1236,10 @@ void dso__delete(struct dso *dso)
1231 if (!RB_EMPTY_NODE(&dso->rb_node)) 1236 if (!RB_EMPTY_NODE(&dso->rb_node))
1232 pr_err("DSO %s is still in rbtree when being deleted!\n", 1237 pr_err("DSO %s is still in rbtree when being deleted!\n",
1233 dso->long_name); 1238 dso->long_name);
1239
1240 /* free inlines first, as they reference symbols */
1241 inlines__tree_delete(&dso->inlined_nodes);
1242 srcline__tree_delete(&dso->srclines);
1234 for (i = 0; i < MAP__NR_TYPES; ++i) 1243 for (i = 0; i < MAP__NR_TYPES; ++i)
1235 symbols__delete(&dso->symbols[i]); 1244 symbols__delete(&dso->symbols[i]);
1236 1245
@@ -1365,9 +1374,9 @@ void __dsos__add(struct dsos *dsos, struct dso *dso)
1365 1374
1366void dsos__add(struct dsos *dsos, struct dso *dso) 1375void dsos__add(struct dsos *dsos, struct dso *dso)
1367{ 1376{
1368 pthread_rwlock_wrlock(&dsos->lock); 1377 down_write(&dsos->lock);
1369 __dsos__add(dsos, dso); 1378 __dsos__add(dsos, dso);
1370 pthread_rwlock_unlock(&dsos->lock); 1379 up_write(&dsos->lock);
1371} 1380}
1372 1381
1373struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short) 1382struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
@@ -1386,9 +1395,9 @@ struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
1386struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short) 1395struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
1387{ 1396{
1388 struct dso *dso; 1397 struct dso *dso;
1389 pthread_rwlock_rdlock(&dsos->lock); 1398 down_read(&dsos->lock);
1390 dso = __dsos__find(dsos, name, cmp_short); 1399 dso = __dsos__find(dsos, name, cmp_short);
1391 pthread_rwlock_unlock(&dsos->lock); 1400 up_read(&dsos->lock);
1392 return dso; 1401 return dso;
1393} 1402}
1394 1403
@@ -1415,9 +1424,9 @@ struct dso *__dsos__findnew(struct dsos *dsos, const char *name)
1415struct dso *dsos__findnew(struct dsos *dsos, const char *name) 1424struct dso *dsos__findnew(struct dsos *dsos, const char *name)
1416{ 1425{
1417 struct dso *dso; 1426 struct dso *dso;
1418 pthread_rwlock_wrlock(&dsos->lock); 1427 down_write(&dsos->lock);
1419 dso = dso__get(__dsos__findnew(dsos, name)); 1428 dso = dso__get(__dsos__findnew(dsos, name));
1420 pthread_rwlock_unlock(&dsos->lock); 1429 up_write(&dsos->lock);
1421 return dso; 1430 return dso;
1422} 1431}
1423 1432
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index f886141678eb..c229dbe0277a 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_DSO 2#ifndef __PERF_DSO
2#define __PERF_DSO 3#define __PERF_DSO
3 4
@@ -6,7 +7,7 @@
6#include <linux/rbtree.h> 7#include <linux/rbtree.h>
7#include <sys/types.h> 8#include <sys/types.h>
8#include <stdbool.h> 9#include <stdbool.h>
9#include <pthread.h> 10#include "rwsem.h"
10#include <linux/types.h> 11#include <linux/types.h>
11#include <linux/bitops.h> 12#include <linux/bitops.h>
12#include "map.h" 13#include "map.h"
@@ -129,7 +130,7 @@ struct dso_cache {
129struct dsos { 130struct dsos {
130 struct list_head head; 131 struct list_head head;
131 struct rb_root root; /* rbtree root sorted by long name */ 132 struct rb_root root; /* rbtree root sorted by long name */
132 pthread_rwlock_t lock; 133 struct rw_semaphore lock;
133}; 134};
134 135
135struct auxtrace_cache; 136struct auxtrace_cache;
@@ -141,6 +142,8 @@ struct dso {
141 struct rb_root *root; /* root of rbtree that rb_node is in */ 142 struct rb_root *root; /* root of rbtree that rb_node is in */
142 struct rb_root symbols[MAP__NR_TYPES]; 143 struct rb_root symbols[MAP__NR_TYPES];
143 struct rb_root symbol_names[MAP__NR_TYPES]; 144 struct rb_root symbol_names[MAP__NR_TYPES];
145 struct rb_root inlined_nodes;
146 struct rb_root srclines;
144 struct { 147 struct {
145 u64 addr; 148 u64 addr;
146 struct symbol *symbol; 149 struct symbol *symbol;
diff --git a/tools/perf/util/dump-insn.c b/tools/perf/util/dump-insn.c
index ffbdb19f05d0..10988d3de7ce 100644
--- a/tools/perf/util/dump-insn.c
+++ b/tools/perf/util/dump-insn.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include "dump-insn.h" 3#include "dump-insn.h"
3 4
diff --git a/tools/perf/util/dump-insn.h b/tools/perf/util/dump-insn.h
index 90fb115981cf..0e06280a8860 100644
--- a/tools/perf/util/dump-insn.h
+++ b/tools/perf/util/dump-insn.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_DUMP_INSN_H 2#ifndef __PERF_DUMP_INSN_H
2#define __PERF_DUMP_INSN_H 1 3#define __PERF_DUMP_INSN_H 1
3 4
diff --git a/tools/perf/util/dwarf-regs.c b/tools/perf/util/dwarf-regs.c
index c708395b3cb6..db55eddce8cd 100644
--- a/tools/perf/util/dwarf-regs.c
+++ b/tools/perf/util/dwarf-regs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * dwarf-regs.c : Mapping of DWARF debug register numbers into register names. 3 * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
3 * 4 *
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 9e21538c42ae..6276b340f893 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "cpumap.h" 2#include "cpumap.h"
2#include "env.h" 3#include "env.h"
3#include "util.h" 4#include "util.h"
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index b164dfd2dcbf..1eb35b190b34 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_ENV_H 2#ifndef __PERF_ENV_H
2#define __PERF_ENV_H 3#define __PERF_ENV_H
3 4
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 1c905ba3641b..97a8ef9980db 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1,5 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <dirent.h> 2#include <dirent.h>
2#include <errno.h> 3#include <errno.h>
4#include <fcntl.h>
3#include <inttypes.h> 5#include <inttypes.h>
4#include <linux/kernel.h> 6#include <linux/kernel.h>
5#include <linux/types.h> 7#include <linux/types.h>
@@ -677,21 +679,21 @@ out:
677 return err; 679 return err;
678} 680}
679 681
680int perf_event__synthesize_threads(struct perf_tool *tool, 682static int __perf_event__synthesize_threads(struct perf_tool *tool,
681 perf_event__handler_t process, 683 perf_event__handler_t process,
682 struct machine *machine, 684 struct machine *machine,
683 bool mmap_data, 685 bool mmap_data,
684 unsigned int proc_map_timeout) 686 unsigned int proc_map_timeout,
687 struct dirent **dirent,
688 int start,
689 int num)
685{ 690{
686 DIR *proc;
687 char proc_path[PATH_MAX];
688 struct dirent *dirent;
689 union perf_event *comm_event, *mmap_event, *fork_event; 691 union perf_event *comm_event, *mmap_event, *fork_event;
690 union perf_event *namespaces_event; 692 union perf_event *namespaces_event;
691 int err = -1; 693 int err = -1;
692 694 char *end;
693 if (machine__is_default_guest(machine)) 695 pid_t pid;
694 return 0; 696 int i;
695 697
696 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size); 698 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
697 if (comm_event == NULL) 699 if (comm_event == NULL)
@@ -711,31 +713,25 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
711 if (namespaces_event == NULL) 713 if (namespaces_event == NULL)
712 goto out_free_fork; 714 goto out_free_fork;
713 715
714 snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir); 716 for (i = start; i < start + num; i++) {
715 proc = opendir(proc_path); 717 if (!isdigit(dirent[i]->d_name[0]))
716 718 continue;
717 if (proc == NULL)
718 goto out_free_namespaces;
719
720 while ((dirent = readdir(proc)) != NULL) {
721 char *end;
722 pid_t pid = strtol(dirent->d_name, &end, 10);
723 719
724 if (*end) /* only interested in proper numerical dirents */ 720 pid = (pid_t)strtol(dirent[i]->d_name, &end, 10);
721 /* only interested in proper numerical dirents */
722 if (*end)
725 continue; 723 continue;
726 /* 724 /*
727 * We may race with exiting thread, so don't stop just because 725 * We may race with exiting thread, so don't stop just because
728 * one thread couldn't be synthesized. 726 * one thread couldn't be synthesized.
729 */ 727 */
730 __event__synthesize_thread(comm_event, mmap_event, fork_event, 728 __event__synthesize_thread(comm_event, mmap_event, fork_event,
731 namespaces_event, pid, 1, process, 729 namespaces_event, pid, 1, process,
732 tool, machine, mmap_data, 730 tool, machine, mmap_data,
733 proc_map_timeout); 731 proc_map_timeout);
734 } 732 }
735
736 err = 0; 733 err = 0;
737 closedir(proc); 734
738out_free_namespaces:
739 free(namespaces_event); 735 free(namespaces_event);
740out_free_fork: 736out_free_fork:
741 free(fork_event); 737 free(fork_event);
@@ -747,6 +743,118 @@ out:
747 return err; 743 return err;
748} 744}
749 745
746struct synthesize_threads_arg {
747 struct perf_tool *tool;
748 perf_event__handler_t process;
749 struct machine *machine;
750 bool mmap_data;
751 unsigned int proc_map_timeout;
752 struct dirent **dirent;
753 int num;
754 int start;
755};
756
757static void *synthesize_threads_worker(void *arg)
758{
759 struct synthesize_threads_arg *args = arg;
760
761 __perf_event__synthesize_threads(args->tool, args->process,
762 args->machine, args->mmap_data,
763 args->proc_map_timeout, args->dirent,
764 args->start, args->num);
765 return NULL;
766}
767
768int perf_event__synthesize_threads(struct perf_tool *tool,
769 perf_event__handler_t process,
770 struct machine *machine,
771 bool mmap_data,
772 unsigned int proc_map_timeout,
773 unsigned int nr_threads_synthesize)
774{
775 struct synthesize_threads_arg *args = NULL;
776 pthread_t *synthesize_threads = NULL;
777 char proc_path[PATH_MAX];
778 struct dirent **dirent;
779 int num_per_thread;
780 int m, n, i, j;
781 int thread_nr;
782 int base = 0;
783 int err = -1;
784
785
786 if (machine__is_default_guest(machine))
787 return 0;
788
789 snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
790 n = scandir(proc_path, &dirent, 0, alphasort);
791 if (n < 0)
792 return err;
793
794 if (nr_threads_synthesize == UINT_MAX)
795 thread_nr = sysconf(_SC_NPROCESSORS_ONLN);
796 else
797 thread_nr = nr_threads_synthesize;
798
799 if (thread_nr <= 1) {
800 err = __perf_event__synthesize_threads(tool, process,
801 machine, mmap_data,
802 proc_map_timeout,
803 dirent, base, n);
804 goto free_dirent;
805 }
806 if (thread_nr > n)
807 thread_nr = n;
808
809 synthesize_threads = calloc(sizeof(pthread_t), thread_nr);
810 if (synthesize_threads == NULL)
811 goto free_dirent;
812
813 args = calloc(sizeof(*args), thread_nr);
814 if (args == NULL)
815 goto free_threads;
816
817 num_per_thread = n / thread_nr;
818 m = n % thread_nr;
819 for (i = 0; i < thread_nr; i++) {
820 args[i].tool = tool;
821 args[i].process = process;
822 args[i].machine = machine;
823 args[i].mmap_data = mmap_data;
824 args[i].proc_map_timeout = proc_map_timeout;
825 args[i].dirent = dirent;
826 }
827 for (i = 0; i < m; i++) {
828 args[i].num = num_per_thread + 1;
829 args[i].start = i * args[i].num;
830 }
831 if (i != 0)
832 base = args[i-1].start + args[i-1].num;
833 for (j = i; j < thread_nr; j++) {
834 args[j].num = num_per_thread;
835 args[j].start = base + (j - i) * args[i].num;
836 }
837
838 for (i = 0; i < thread_nr; i++) {
839 if (pthread_create(&synthesize_threads[i], NULL,
840 synthesize_threads_worker, &args[i]))
841 goto out_join;
842 }
843 err = 0;
844out_join:
845 for (i = 0; i < thread_nr; i++)
846 pthread_join(synthesize_threads[i], NULL);
847 free(args);
848free_threads:
849 free(synthesize_threads);
850free_dirent:
851 for (i = 0; i < n; i++)
852 free(dirent[i]);
853 free(dirent);
854
855 return err;
856}
857
750struct process_symbol_args { 858struct process_symbol_args {
751 const char *name; 859 const char *name;
752 u64 start; 860 u64 start;
@@ -1497,6 +1605,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
1497 al->sym = NULL; 1605 al->sym = NULL;
1498 al->cpu = sample->cpu; 1606 al->cpu = sample->cpu;
1499 al->socket = -1; 1607 al->socket = -1;
1608 al->srcline = NULL;
1500 1609
1501 if (al->cpu >= 0) { 1610 if (al->cpu >= 0) {
1502 struct perf_env *env = machine->env; 1611 struct perf_env *env = machine->env;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index ee7bcc898d35..1ae95efbfb95 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_RECORD_H 2#ifndef __PERF_RECORD_H
2#define __PERF_RECORD_H 3#define __PERF_RECORD_H
3 4
@@ -680,7 +681,8 @@ int perf_event__synthesize_cpu_map(struct perf_tool *tool,
680int perf_event__synthesize_threads(struct perf_tool *tool, 681int perf_event__synthesize_threads(struct perf_tool *tool,
681 perf_event__handler_t process, 682 perf_event__handler_t process,
682 struct machine *machine, bool mmap_data, 683 struct machine *machine, bool mmap_data,
683 unsigned int proc_map_timeout); 684 unsigned int proc_map_timeout,
685 unsigned int nr_threads_synthesize);
684int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, 686int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
685 perf_event__handler_t process, 687 perf_event__handler_t process,
686 struct machine *machine); 688 struct machine *machine);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 6a0d7ffbeba0..c6c891e154a6 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -33,9 +33,6 @@
33#include <linux/log2.h> 33#include <linux/log2.h>
34#include <linux/err.h> 34#include <linux/err.h>
35 35
36static void perf_mmap__munmap(struct perf_mmap *map);
37static void perf_mmap__put(struct perf_mmap *map);
38
39#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) 36#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
40#define SID(e, x, y) xyarray__entry(e->sample_id, x, y) 37#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
41 38
@@ -704,129 +701,6 @@ static int perf_evlist__resume(struct perf_evlist *evlist)
704 return perf_evlist__set_paused(evlist, false); 701 return perf_evlist__set_paused(evlist, false);
705} 702}
706 703
707/* When check_messup is true, 'end' must points to a good entry */
708static union perf_event *
709perf_mmap__read(struct perf_mmap *md, bool check_messup, u64 start,
710 u64 end, u64 *prev)
711{
712 unsigned char *data = md->base + page_size;
713 union perf_event *event = NULL;
714 int diff = end - start;
715
716 if (check_messup) {
717 /*
718 * If we're further behind than half the buffer, there's a chance
719 * the writer will bite our tail and mess up the samples under us.
720 *
721 * If we somehow ended up ahead of the 'end', we got messed up.
722 *
723 * In either case, truncate and restart at 'end'.
724 */
725 if (diff > md->mask / 2 || diff < 0) {
726 fprintf(stderr, "WARNING: failed to keep up with mmap data.\n");
727
728 /*
729 * 'end' points to a known good entry, start there.
730 */
731 start = end;
732 diff = 0;
733 }
734 }
735
736 if (diff >= (int)sizeof(event->header)) {
737 size_t size;
738
739 event = (union perf_event *)&data[start & md->mask];
740 size = event->header.size;
741
742 if (size < sizeof(event->header) || diff < (int)size) {
743 event = NULL;
744 goto broken_event;
745 }
746
747 /*
748 * Event straddles the mmap boundary -- header should always
749 * be inside due to u64 alignment of output.
750 */
751 if ((start & md->mask) + size != ((start + size) & md->mask)) {
752 unsigned int offset = start;
753 unsigned int len = min(sizeof(*event), size), cpy;
754 void *dst = md->event_copy;
755
756 do {
757 cpy = min(md->mask + 1 - (offset & md->mask), len);
758 memcpy(dst, &data[offset & md->mask], cpy);
759 offset += cpy;
760 dst += cpy;
761 len -= cpy;
762 } while (len);
763
764 event = (union perf_event *) md->event_copy;
765 }
766
767 start += size;
768 }
769
770broken_event:
771 if (prev)
772 *prev = start;
773
774 return event;
775}
776
777union perf_event *perf_mmap__read_forward(struct perf_mmap *md, bool check_messup)
778{
779 u64 head;
780 u64 old = md->prev;
781
782 /*
783 * Check if event was unmapped due to a POLLHUP/POLLERR.
784 */
785 if (!refcount_read(&md->refcnt))
786 return NULL;
787
788 head = perf_mmap__read_head(md);
789
790 return perf_mmap__read(md, check_messup, old, head, &md->prev);
791}
792
793union perf_event *
794perf_mmap__read_backward(struct perf_mmap *md)
795{
796 u64 head, end;
797 u64 start = md->prev;
798
799 /*
800 * Check if event was unmapped due to a POLLHUP/POLLERR.
801 */
802 if (!refcount_read(&md->refcnt))
803 return NULL;
804
805 head = perf_mmap__read_head(md);
806 if (!head)
807 return NULL;
808
809 /*
810 * 'head' pointer starts from 0. Kernel minus sizeof(record) form
811 * it each time when kernel writes to it, so in fact 'head' is
812 * negative. 'end' pointer is made manually by adding the size of
813 * the ring buffer to 'head' pointer, means the validate data can
814 * read is the whole ring buffer. If 'end' is positive, the ring
815 * buffer has not fully filled, so we must adjust 'end' to 0.
816 *
817 * However, since both 'head' and 'end' is unsigned, we can't
818 * simply compare 'end' against 0. Here we compare '-head' and
819 * the size of the ring buffer, where -head is the number of bytes
820 * kernel write to the ring buffer.
821 */
822 if (-head < (u64)(md->mask + 1))
823 end = 0;
824 else
825 end = head + md->mask + 1;
826
827 return perf_mmap__read(md, false, start, end, &md->prev);
828}
829
830union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist, int idx) 704union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist, int idx)
831{ 705{
832 struct perf_mmap *md = &evlist->mmap[idx]; 706 struct perf_mmap *md = &evlist->mmap[idx];
@@ -857,96 +731,16 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
857 return perf_evlist__mmap_read_forward(evlist, idx); 731 return perf_evlist__mmap_read_forward(evlist, idx);
858} 732}
859 733
860void perf_mmap__read_catchup(struct perf_mmap *md)
861{
862 u64 head;
863
864 if (!refcount_read(&md->refcnt))
865 return;
866
867 head = perf_mmap__read_head(md);
868 md->prev = head;
869}
870
871void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx) 734void perf_evlist__mmap_read_catchup(struct perf_evlist *evlist, int idx)
872{ 735{
873 perf_mmap__read_catchup(&evlist->mmap[idx]); 736 perf_mmap__read_catchup(&evlist->mmap[idx]);
874} 737}
875 738
876static bool perf_mmap__empty(struct perf_mmap *md)
877{
878 return perf_mmap__read_head(md) == md->prev && !md->auxtrace_mmap.base;
879}
880
881static void perf_mmap__get(struct perf_mmap *map)
882{
883 refcount_inc(&map->refcnt);
884}
885
886static void perf_mmap__put(struct perf_mmap *md)
887{
888 BUG_ON(md->base && refcount_read(&md->refcnt) == 0);
889
890 if (refcount_dec_and_test(&md->refcnt))
891 perf_mmap__munmap(md);
892}
893
894void perf_mmap__consume(struct perf_mmap *md, bool overwrite)
895{
896 if (!overwrite) {
897 u64 old = md->prev;
898
899 perf_mmap__write_tail(md, old);
900 }
901
902 if (refcount_read(&md->refcnt) == 1 && perf_mmap__empty(md))
903 perf_mmap__put(md);
904}
905
906void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx) 739void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
907{ 740{
908 perf_mmap__consume(&evlist->mmap[idx], evlist->overwrite); 741 perf_mmap__consume(&evlist->mmap[idx], evlist->overwrite);
909} 742}
910 743
911int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
912 struct auxtrace_mmap_params *mp __maybe_unused,
913 void *userpg __maybe_unused,
914 int fd __maybe_unused)
915{
916 return 0;
917}
918
919void __weak auxtrace_mmap__munmap(struct auxtrace_mmap *mm __maybe_unused)
920{
921}
922
923void __weak auxtrace_mmap_params__init(
924 struct auxtrace_mmap_params *mp __maybe_unused,
925 off_t auxtrace_offset __maybe_unused,
926 unsigned int auxtrace_pages __maybe_unused,
927 bool auxtrace_overwrite __maybe_unused)
928{
929}
930
931void __weak auxtrace_mmap_params__set_idx(
932 struct auxtrace_mmap_params *mp __maybe_unused,
933 struct perf_evlist *evlist __maybe_unused,
934 int idx __maybe_unused,
935 bool per_cpu __maybe_unused)
936{
937}
938
939static void perf_mmap__munmap(struct perf_mmap *map)
940{
941 if (map->base != NULL) {
942 munmap(map->base, perf_mmap__mmap_len(map));
943 map->base = NULL;
944 map->fd = -1;
945 refcount_set(&map->refcnt, 0);
946 }
947 auxtrace_mmap__munmap(&map->auxtrace_mmap);
948}
949
950static void perf_evlist__munmap_nofree(struct perf_evlist *evlist) 744static void perf_evlist__munmap_nofree(struct perf_evlist *evlist)
951{ 745{
952 int i; 746 int i;
@@ -995,48 +789,6 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct perf_evlist *evlist)
995 return map; 789 return map;
996} 790}
997 791
998struct mmap_params {
999 int prot;
1000 int mask;
1001 struct auxtrace_mmap_params auxtrace_mp;
1002};
1003
1004static int perf_mmap__mmap(struct perf_mmap *map,
1005 struct mmap_params *mp, int fd)
1006{
1007 /*
1008 * The last one will be done at perf_evlist__mmap_consume(), so that we
1009 * make sure we don't prevent tools from consuming every last event in
1010 * the ring buffer.
1011 *
1012 * I.e. we can get the POLLHUP meaning that the fd doesn't exist
1013 * anymore, but the last events for it are still in the ring buffer,
1014 * waiting to be consumed.
1015 *
1016 * Tools can chose to ignore this at their own discretion, but the
1017 * evlist layer can't just drop it when filtering events in
1018 * perf_evlist__filter_pollfd().
1019 */
1020 refcount_set(&map->refcnt, 2);
1021 map->prev = 0;
1022 map->mask = mp->mask;
1023 map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
1024 MAP_SHARED, fd, 0);
1025 if (map->base == MAP_FAILED) {
1026 pr_debug2("failed to mmap perf event ring buffer, error %d\n",
1027 errno);
1028 map->base = NULL;
1029 return -1;
1030 }
1031 map->fd = fd;
1032
1033 if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
1034 &mp->auxtrace_mp, map->base, fd))
1035 return -1;
1036
1037 return 0;
1038}
1039
1040static bool 792static bool
1041perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused, 793perf_evlist__should_poll(struct perf_evlist *evlist __maybe_unused,
1042 struct perf_evsel *evsel) 794 struct perf_evsel *evsel)
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index bf2c4936e35f..e72ae64c11ac 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_EVLIST_H 2#ifndef __PERF_EVLIST_H
2#define __PERF_EVLIST_H 1 3#define __PERF_EVLIST_H 1
3 4
@@ -6,12 +7,13 @@
6#include <linux/refcount.h> 7#include <linux/refcount.h>
7#include <linux/list.h> 8#include <linux/list.h>
8#include <api/fd/array.h> 9#include <api/fd/array.h>
10#include <fcntl.h>
9#include <stdio.h> 11#include <stdio.h>
10#include "../perf.h" 12#include "../perf.h"
11#include "event.h" 13#include "event.h"
12#include "evsel.h" 14#include "evsel.h"
15#include "mmap.h"
13#include "util.h" 16#include "util.h"
14#include "auxtrace.h"
15#include <signal.h> 17#include <signal.h>
16#include <unistd.h> 18#include <unistd.h>
17 19
@@ -23,55 +25,6 @@ struct record_opts;
23#define PERF_EVLIST__HLIST_BITS 8 25#define PERF_EVLIST__HLIST_BITS 8
24#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS) 26#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
25 27
26/**
27 * struct perf_mmap - perf's ring buffer mmap details
28 *
29 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
30 */
31struct perf_mmap {
32 void *base;
33 int mask;
34 int fd;
35 refcount_t refcnt;
36 u64 prev;
37 struct auxtrace_mmap auxtrace_mmap;
38 char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
39};
40
41static inline size_t
42perf_mmap__mmap_len(struct perf_mmap *map)
43{
44 return map->mask + 1 + page_size;
45}
46
47/*
48 * State machine of bkw_mmap_state:
49 *
50 * .________________(forbid)_____________.
51 * | V
52 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
53 * ^ ^ | ^ |
54 * | |__(forbid)____/ |___(forbid)___/|
55 * | |
56 * \_________________(3)_______________/
57 *
58 * NOTREADY : Backward ring buffers are not ready
59 * RUNNING : Backward ring buffers are recording
60 * DATA_PENDING : We are required to collect data from backward ring buffers
61 * EMPTY : We have collected data from backward ring buffers.
62 *
63 * (0): Setup backward ring buffer
64 * (1): Pause ring buffers for reading
65 * (2): Read from ring buffers
66 * (3): Resume ring buffers for recording
67 */
68enum bkw_mmap_state {
69 BKW_MMAP_NOTREADY,
70 BKW_MMAP_RUNNING,
71 BKW_MMAP_DATA_PENDING,
72 BKW_MMAP_EMPTY,
73};
74
75struct perf_evlist { 28struct perf_evlist {
76 struct list_head entries; 29 struct list_head entries;
77 struct hlist_head heads[PERF_EVLIST__HLIST_SIZE]; 30 struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
@@ -176,12 +129,6 @@ struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
176 129
177void perf_evlist__toggle_bkw_mmap(struct perf_evlist *evlist, enum bkw_mmap_state state); 130void perf_evlist__toggle_bkw_mmap(struct perf_evlist *evlist, enum bkw_mmap_state state);
178 131
179union perf_event *perf_mmap__read_forward(struct perf_mmap *map, bool check_messup);
180union perf_event *perf_mmap__read_backward(struct perf_mmap *map);
181
182void perf_mmap__read_catchup(struct perf_mmap *md);
183void perf_mmap__consume(struct perf_mmap *md, bool overwrite);
184
185union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx); 132union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
186 133
187union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist, 134union perf_event *perf_evlist__mmap_read_forward(struct perf_evlist *evlist,
@@ -285,25 +232,6 @@ size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp);
285int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size); 232int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size);
286int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size); 233int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size);
287 234
288static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
289{
290 struct perf_event_mmap_page *pc = mm->base;
291 u64 head = ACCESS_ONCE(pc->data_head);
292 rmb();
293 return head;
294}
295
296static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
297{
298 struct perf_event_mmap_page *pc = md->base;
299
300 /*
301 * ensure all reads are done before we write the tail out.
302 */
303 mb();
304 pc->data_tail = tail;
305}
306
307bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str); 235bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str);
308void perf_evlist__to_front(struct perf_evlist *evlist, 236void perf_evlist__to_front(struct perf_evlist *evlist,
309 struct perf_evsel *move_evsel); 237 struct perf_evsel *move_evsel);
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 4bb89373eb52..f894893c203d 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -271,12 +271,17 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
271 return evsel; 271 return evsel;
272} 272}
273 273
274static bool perf_event_can_profile_kernel(void)
275{
276 return geteuid() == 0 || perf_event_paranoid() == -1;
277}
278
274struct perf_evsel *perf_evsel__new_cycles(bool precise) 279struct perf_evsel *perf_evsel__new_cycles(bool precise)
275{ 280{
276 struct perf_event_attr attr = { 281 struct perf_event_attr attr = {
277 .type = PERF_TYPE_HARDWARE, 282 .type = PERF_TYPE_HARDWARE,
278 .config = PERF_COUNT_HW_CPU_CYCLES, 283 .config = PERF_COUNT_HW_CPU_CYCLES,
279 .exclude_kernel = geteuid() != 0, 284 .exclude_kernel = !perf_event_can_profile_kernel(),
280 }; 285 };
281 struct perf_evsel *evsel; 286 struct perf_evsel *evsel;
282 287
@@ -678,7 +683,7 @@ void perf_evsel__config_callchain(struct perf_evsel *evsel,
678 if (!function) { 683 if (!function) {
679 perf_evsel__set_sample_bit(evsel, REGS_USER); 684 perf_evsel__set_sample_bit(evsel, REGS_USER);
680 perf_evsel__set_sample_bit(evsel, STACK_USER); 685 perf_evsel__set_sample_bit(evsel, STACK_USER);
681 attr->sample_regs_user = PERF_REGS_MASK; 686 attr->sample_regs_user |= PERF_REGS_MASK;
682 attr->sample_stack_user = param->dump_size; 687 attr->sample_stack_user = param->dump_size;
683 attr->exclude_callchain_user = 1; 688 attr->exclude_callchain_user = 1;
684 } else { 689 } else {
@@ -931,6 +936,11 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
931 perf_evsel__set_sample_bit(evsel, REGS_INTR); 936 perf_evsel__set_sample_bit(evsel, REGS_INTR);
932 } 937 }
933 938
939 if (opts->sample_user_regs) {
940 attr->sample_regs_user |= opts->sample_user_regs;
941 perf_evsel__set_sample_bit(evsel, REGS_USER);
942 }
943
934 if (target__has_cpu(&opts->target) || opts->sample_cpu) 944 if (target__has_cpu(&opts->target) || opts->sample_cpu)
935 perf_evsel__set_sample_bit(evsel, CPU); 945 perf_evsel__set_sample_bit(evsel, CPU);
936 946
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index dd2c4b5112a5..9277df96ffda 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_EVSEL_H 2#ifndef __PERF_EVSEL_H
2#define __PERF_EVSEL_H 1 3#define __PERF_EVSEL_H 1
3 4
@@ -68,6 +69,8 @@ struct perf_evsel_config_term {
68 } val; 69 } val;
69}; 70};
70 71
72struct perf_stat_evsel;
73
71/** struct perf_evsel - event selector 74/** struct perf_evsel - event selector
72 * 75 *
73 * @evlist - evlist this evsel is in, if it is in one. 76 * @evlist - evlist this evsel is in, if it is in one.
@@ -101,6 +104,7 @@ struct perf_evsel {
101 const char *unit; 104 const char *unit;
102 struct event_format *tp_format; 105 struct event_format *tp_format;
103 off_t id_offset; 106 off_t id_offset;
107 struct perf_stat_evsel *stats;
104 void *priv; 108 void *priv;
105 u64 db_id; 109 u64 db_id;
106 struct cgroup_sel *cgrp; 110 struct cgroup_sel *cgrp;
@@ -137,6 +141,7 @@ struct perf_evsel {
137 const char * metric_name; 141 const char * metric_name;
138 struct perf_evsel **metric_events; 142 struct perf_evsel **metric_events;
139 bool collect_stat; 143 bool collect_stat;
144 bool weak_group;
140}; 145};
141 146
142union u64_swap { 147union u64_swap {
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index 583f3a602506..06dfb027879d 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdbool.h> 4#include <stdbool.h>
@@ -157,7 +158,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
157 } 158 }
158 } 159 }
159 160
160 if (print_dso) { 161 if (print_dso && (!node->sym || !node->sym->inlined)) {
161 printed += fprintf(fp, " ("); 162 printed += fprintf(fp, " (");
162 printed += map__fprintf_dsoname(node->map, fp); 163 printed += map__fprintf_dsoname(node->map, fp);
163 printed += fprintf(fp, ")"); 164 printed += fprintf(fp, ")");
@@ -166,41 +167,12 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
166 if (print_srcline) 167 if (print_srcline)
167 printed += map__fprintf_srcline(node->map, addr, "\n ", fp); 168 printed += map__fprintf_srcline(node->map, addr, "\n ", fp);
168 169
170 if (node->sym && node->sym->inlined)
171 printed += fprintf(fp, " (inlined)");
172
169 if (!print_oneline) 173 if (!print_oneline)
170 printed += fprintf(fp, "\n"); 174 printed += fprintf(fp, "\n");
171 175
172 if (symbol_conf.inline_name && node->map) {
173 struct inline_node *inode;
174
175 addr = map__rip_2objdump(node->map, node->ip),
176 inode = dso__parse_addr_inlines(node->map->dso, addr);
177
178 if (inode) {
179 struct inline_list *ilist;
180
181 list_for_each_entry(ilist, &inode->val, list) {
182 if (print_arrow)
183 printed += fprintf(fp, " <-");
184
185 /* IP is same, just skip it */
186 if (print_ip)
187 printed += fprintf(fp, "%c%16s",
188 s, "");
189 if (print_sym)
190 printed += fprintf(fp, " %s",
191 ilist->funcname);
192 if (print_srcline)
193 printed += fprintf(fp, "\n %s:%d",
194 ilist->filename,
195 ilist->line_nr);
196 if (!print_oneline)
197 printed += fprintf(fp, "\n");
198 }
199
200 inline_node__delete(inode);
201 }
202 }
203
204 if (symbol_conf.bt_stop_list && 176 if (symbol_conf.bt_stop_list &&
205 node->sym && 177 node->sym &&
206 strlist__has_entry(symbol_conf.bt_stop_list, 178 strlist__has_entry(symbol_conf.bt_stop_list,
diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h
index 400ef9eab00a..046160831f90 100644
--- a/tools/perf/util/expr.h
+++ b/tools/perf/util/expr.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PARSE_CTX_H 2#ifndef PARSE_CTX_H
2#define PARSE_CTX_H 1 3#define PARSE_CTX_H 1
3 4
diff --git a/tools/perf/util/find-vdso-map.c b/tools/perf/util/find-vdso-map.c
index 95ef1cffc056..d7823e3508fc 100644
--- a/tools/perf/util/find-vdso-map.c
+++ b/tools/perf/util/find-vdso-map.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1static int find_vdso_map(void **start, void **end) 2static int find_vdso_map(void **start, void **end)
2{ 3{
3 FILE *maps; 4 FILE *maps;
diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
index 2424bd9862a3..de322d51c7fe 100644
--- a/tools/perf/util/genelf.h
+++ b/tools/perf/util/genelf.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __GENELF_H__ 2#ifndef __GENELF_H__
2#define __GENELF_H__ 3#define __GENELF_H__
3 4
diff --git a/tools/perf/util/generate-cmdlist.sh b/tools/perf/util/generate-cmdlist.sh
index 0ac2037c970c..9bbcec4e3365 100755
--- a/tools/perf/util/generate-cmdlist.sh
+++ b/tools/perf/util/generate-cmdlist.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3echo "/* Automatically generated by $0 */ 4echo "/* Automatically generated by $0 */
4struct cmdname_help 5struct cmdname_help
diff --git a/tools/perf/util/group.h b/tools/perf/util/group.h
index 116debe7a995..f36c7e31780a 100644
--- a/tools/perf/util/group.h
+++ b/tools/perf/util/group.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef GROUP_H 2#ifndef GROUP_H
2#define GROUP_H 1 3#define GROUP_H 1
3 4
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 605bbd5404fb..7c0e9d587bfa 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include "util.h" 4#include "util.h"
@@ -1762,7 +1763,7 @@ process_event_desc(struct feat_fd *ff, void *data __maybe_unused)
1762 1763
1763 session = container_of(ff->ph, struct perf_session, header); 1764 session = container_of(ff->ph, struct perf_session, header);
1764 1765
1765 if (session->file->is_pipe) { 1766 if (session->data->is_pipe) {
1766 /* Save events for reading later by print_event_desc, 1767 /* Save events for reading later by print_event_desc,
1767 * since they can't be read again in pipe mode. */ 1768 * since they can't be read again in pipe mode. */
1768 ff->events = events; 1769 ff->events = events;
@@ -1771,7 +1772,7 @@ process_event_desc(struct feat_fd *ff, void *data __maybe_unused)
1771 for (evsel = events; evsel->attr.size; evsel++) 1772 for (evsel = events; evsel->attr.size; evsel++)
1772 perf_evlist__set_event_name(session->evlist, evsel); 1773 perf_evlist__set_event_name(session->evlist, evsel);
1773 1774
1774 if (!session->file->is_pipe) 1775 if (!session->data->is_pipe)
1775 free_event_desc(events); 1776 free_event_desc(events);
1776 1777
1777 return 0; 1778 return 0;
@@ -2248,7 +2249,7 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
2248{ 2249{
2249 struct header_print_data hd; 2250 struct header_print_data hd;
2250 struct perf_header *header = &session->header; 2251 struct perf_header *header = &session->header;
2251 int fd = perf_data_file__fd(session->file); 2252 int fd = perf_data__fd(session->data);
2252 struct stat st; 2253 struct stat st;
2253 int ret, bit; 2254 int ret, bit;
2254 2255
@@ -2264,7 +2265,7 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
2264 perf_header__process_sections(header, fd, &hd, 2265 perf_header__process_sections(header, fd, &hd,
2265 perf_file_section__fprintf_info); 2266 perf_file_section__fprintf_info);
2266 2267
2267 if (session->file->is_pipe) 2268 if (session->data->is_pipe)
2268 return 0; 2269 return 0;
2269 2270
2270 fprintf(fp, "# missing features: "); 2271 fprintf(fp, "# missing features: ");
@@ -2757,7 +2758,7 @@ static int perf_header__read_pipe(struct perf_session *session)
2757 struct perf_pipe_file_header f_header; 2758 struct perf_pipe_file_header f_header;
2758 2759
2759 if (perf_file_header__read_pipe(&f_header, header, 2760 if (perf_file_header__read_pipe(&f_header, header,
2760 perf_data_file__fd(session->file), 2761 perf_data__fd(session->data),
2761 session->repipe) < 0) { 2762 session->repipe) < 0) {
2762 pr_debug("incompatible file format\n"); 2763 pr_debug("incompatible file format\n");
2763 return -EINVAL; 2764 return -EINVAL;
@@ -2860,13 +2861,13 @@ static int perf_evlist__prepare_tracepoint_events(struct perf_evlist *evlist,
2860 2861
2861int perf_session__read_header(struct perf_session *session) 2862int perf_session__read_header(struct perf_session *session)
2862{ 2863{
2863 struct perf_data_file *file = session->file; 2864 struct perf_data *data = session->data;
2864 struct perf_header *header = &session->header; 2865 struct perf_header *header = &session->header;
2865 struct perf_file_header f_header; 2866 struct perf_file_header f_header;
2866 struct perf_file_attr f_attr; 2867 struct perf_file_attr f_attr;
2867 u64 f_id; 2868 u64 f_id;
2868 int nr_attrs, nr_ids, i, j; 2869 int nr_attrs, nr_ids, i, j;
2869 int fd = perf_data_file__fd(file); 2870 int fd = perf_data__fd(data);
2870 2871
2871 session->evlist = perf_evlist__new(); 2872 session->evlist = perf_evlist__new();
2872 if (session->evlist == NULL) 2873 if (session->evlist == NULL)
@@ -2874,7 +2875,7 @@ int perf_session__read_header(struct perf_session *session)
2874 2875
2875 session->evlist->env = &header->env; 2876 session->evlist->env = &header->env;
2876 session->machines.host.env = &header->env; 2877 session->machines.host.env = &header->env;
2877 if (perf_data_file__is_pipe(file)) 2878 if (perf_data__is_pipe(data))
2878 return perf_header__read_pipe(session); 2879 return perf_header__read_pipe(session);
2879 2880
2880 if (perf_file_header__read(&f_header, header, fd) < 0) 2881 if (perf_file_header__read(&f_header, header, fd) < 0)
@@ -2889,7 +2890,7 @@ int perf_session__read_header(struct perf_session *session)
2889 if (f_header.data.size == 0) { 2890 if (f_header.data.size == 0) {
2890 pr_warning("WARNING: The %s file's data size field is 0 which is unexpected.\n" 2891 pr_warning("WARNING: The %s file's data size field is 0 which is unexpected.\n"
2891 "Was the 'perf record' command properly terminated?\n", 2892 "Was the 'perf record' command properly terminated?\n",
2892 file->path); 2893 data->file.path);
2893 } 2894 }
2894 2895
2895 nr_attrs = f_header.attrs.size / f_header.attr_size; 2896 nr_attrs = f_header.attrs.size / f_header.attr_size;
@@ -3397,7 +3398,7 @@ int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused,
3397 struct perf_session *session) 3398 struct perf_session *session)
3398{ 3399{
3399 ssize_t size_read, padding, size = event->tracing_data.size; 3400 ssize_t size_read, padding, size = event->tracing_data.size;
3400 int fd = perf_data_file__fd(session->file); 3401 int fd = perf_data__fd(session->data);
3401 off_t offset = lseek(fd, 0, SEEK_CUR); 3402 off_t offset = lseek(fd, 0, SEEK_CUR);
3402 char buf[BUFSIZ]; 3403 char buf[BUFSIZ];
3403 3404
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index f7a16ee527b8..29ccbfdf8724 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_HEADER_H 2#ifndef __PERF_HEADER_H
2#define __PERF_HEADER_H 3#define __PERF_HEADER_H
3 4
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
index 15b95300d7f3..4f07a5ba5030 100644
--- a/tools/perf/util/help-unknown-cmd.c
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "cache.h" 2#include "cache.h"
2#include "config.h" 3#include "config.h"
3#include <poll.h> 4#include <poll.h>
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index e60d8d8ea4c2..b6140950301e 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "util.h" 2#include "util.h"
2#include "build-id.h" 3#include "build-id.h"
3#include "hist.h" 4#include "hist.h"
@@ -596,6 +597,7 @@ __hists__add_entry(struct hists *hists,
596 .map = al->map, 597 .map = al->map,
597 .sym = al->sym, 598 .sym = al->sym,
598 }, 599 },
600 .srcline = al->srcline ? strdup(al->srcline) : NULL,
599 .socket = al->socket, 601 .socket = al->socket,
600 .cpu = al->cpu, 602 .cpu = al->cpu,
601 .cpumode = al->cpumode, 603 .cpumode = al->cpumode,
@@ -950,6 +952,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
950 .map = al->map, 952 .map = al->map,
951 .sym = al->sym, 953 .sym = al->sym,
952 }, 954 },
955 .srcline = al->srcline ? strdup(al->srcline) : NULL,
953 .parent = iter->parent, 956 .parent = iter->parent,
954 .raw_data = sample->raw_data, 957 .raw_data = sample->raw_data,
955 .raw_size = sample->raw_size, 958 .raw_size = sample->raw_size,
@@ -1141,11 +1144,6 @@ void hist_entry__delete(struct hist_entry *he)
1141 zfree(&he->mem_info); 1144 zfree(&he->mem_info);
1142 } 1145 }
1143 1146
1144 if (he->inline_node) {
1145 inline_node__delete(he->inline_node);
1146 he->inline_node = NULL;
1147 }
1148
1149 zfree(&he->stat_acc); 1147 zfree(&he->stat_acc);
1150 free_srcline(he->srcline); 1148 free_srcline(he->srcline);
1151 if (he->srcfile && he->srcfile[0]) 1149 if (he->srcfile && he->srcfile[0])
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index e60dda26a920..f6630cb95eff 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_HIST_H 2#ifndef __PERF_HIST_H
2#define __PERF_HIST_H 3#define __PERF_HIST_H
3 4
diff --git a/tools/perf/util/include/asm/asm-offsets.h b/tools/perf/util/include/asm/asm-offsets.h
index ed538942523d..3aff4cf44944 100644
--- a/tools/perf/util/include/asm/asm-offsets.h
+++ b/tools/perf/util/include/asm/asm-offsets.h
@@ -1 +1,2 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* stub */ 2/* stub */
diff --git a/tools/perf/util/include/asm/cpufeature.h b/tools/perf/util/include/asm/cpufeature.h
index acffd5e4d1d4..2270481c7e0a 100644
--- a/tools/perf/util/include/asm/cpufeature.h
+++ b/tools/perf/util/include/asm/cpufeature.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2#ifndef PERF_CPUFEATURE_H 3#ifndef PERF_CPUFEATURE_H
3#define PERF_CPUFEATURE_H 4#define PERF_CPUFEATURE_H
diff --git a/tools/perf/util/include/asm/dwarf2.h b/tools/perf/util/include/asm/dwarf2.h
index afe38199e922..e9876be63dbf 100644
--- a/tools/perf/util/include/asm/dwarf2.h
+++ b/tools/perf/util/include/asm/dwarf2.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2#ifndef PERF_DWARF2_H 3#ifndef PERF_DWARF2_H
3#define PERF_DWARF2_H 4#define PERF_DWARF2_H
diff --git a/tools/perf/util/include/asm/uaccess.h b/tools/perf/util/include/asm/uaccess.h
index d0f72b8fcc35..6a6f4b990547 100644
--- a/tools/perf/util/include/asm/uaccess.h
+++ b/tools/perf/util/include/asm/uaccess.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_ASM_UACCESS_H_ 2#ifndef _PERF_ASM_UACCESS_H_
2#define _PERF_ASM_UACCESS_H_ 3#define _PERF_ASM_UACCESS_H_
3 4
diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h
index 43bfd8da7919..7d99a084e82d 100644
--- a/tools/perf/util/include/dwarf-regs.h
+++ b/tools/perf/util/include/dwarf-regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_DWARF_REGS_H_ 2#ifndef _PERF_DWARF_REGS_H_
2#define _PERF_DWARF_REGS_H_ 3#define _PERF_DWARF_REGS_H_
3 4
diff --git a/tools/perf/util/include/linux/linkage.h b/tools/perf/util/include/linux/linkage.h
index 06387cffe125..f01d48a8d707 100644
--- a/tools/perf/util/include/linux/linkage.h
+++ b/tools/perf/util/include/linux/linkage.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2#ifndef PERF_LINUX_LINKAGE_H_ 3#ifndef PERF_LINUX_LINKAGE_H_
3#define PERF_LINUX_LINKAGE_H_ 4#define PERF_LINUX_LINKAGE_H_
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index 218ee2bac9a5..5325e65f9711 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -500,7 +500,7 @@ static int intel_bts_process_queue(struct intel_bts_queue *btsq, u64 *timestamp)
500 } 500 }
501 501
502 if (!buffer->data) { 502 if (!buffer->data) {
503 int fd = perf_data_file__fd(btsq->bts->session->file); 503 int fd = perf_data__fd(btsq->bts->session->data);
504 504
505 buffer->data = auxtrace_buffer__get_data(buffer, fd); 505 buffer->data = auxtrace_buffer__get_data(buffer, fd);
506 if (!buffer->data) { 506 if (!buffer->data) {
@@ -664,10 +664,10 @@ static int intel_bts_process_auxtrace_event(struct perf_session *session,
664 if (!bts->data_queued) { 664 if (!bts->data_queued) {
665 struct auxtrace_buffer *buffer; 665 struct auxtrace_buffer *buffer;
666 off_t data_offset; 666 off_t data_offset;
667 int fd = perf_data_file__fd(session->file); 667 int fd = perf_data__fd(session->data);
668 int err; 668 int err;
669 669
670 if (perf_data_file__is_pipe(session->file)) { 670 if (perf_data__is_pipe(session->data)) {
671 data_offset = 0; 671 data_offset = 0;
672 } else { 672 } else {
673 data_offset = lseek(fd, 0, SEEK_CUR); 673 data_offset = lseek(fd, 0, SEEK_CUR);
diff --git a/tools/perf/util/intel-pt-decoder/gen-insn-attr-x86.awk b/tools/perf/util/intel-pt-decoder/gen-insn-attr-x86.awk
index 54e961659514..ddd5c4c21129 100644
--- a/tools/perf/util/intel-pt-decoder/gen-insn-attr-x86.awk
+++ b/tools/perf/util/intel-pt-decoder/gen-insn-attr-x86.awk
@@ -1,4 +1,5 @@
1#!/bin/awk -f 1#!/bin/awk -f
2# SPDX-License-Identifier: GPL-2.0
2# gen-insn-attr-x86.awk: Instruction attribute table generator 3# gen-insn-attr-x86.awk: Instruction attribute table generator
3# Written by Masami Hiramatsu <mhiramat@redhat.com> 4# Written by Masami Hiramatsu <mhiramat@redhat.com>
4# 5#
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index b58f9fd1e2ee..23f9ba676df0 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -271,7 +271,7 @@ next:
271 ptq->buffer = buffer; 271 ptq->buffer = buffer;
272 272
273 if (!buffer->data) { 273 if (!buffer->data) {
274 int fd = perf_data_file__fd(ptq->pt->session->file); 274 int fd = perf_data__fd(ptq->pt->session->data);
275 275
276 buffer->data = auxtrace_buffer__get_data(buffer, fd); 276 buffer->data = auxtrace_buffer__get_data(buffer, fd);
277 if (!buffer->data) 277 if (!buffer->data)
@@ -2084,10 +2084,10 @@ static int intel_pt_process_auxtrace_event(struct perf_session *session,
2084 if (!pt->data_queued) { 2084 if (!pt->data_queued) {
2085 struct auxtrace_buffer *buffer; 2085 struct auxtrace_buffer *buffer;
2086 off_t data_offset; 2086 off_t data_offset;
2087 int fd = perf_data_file__fd(session->file); 2087 int fd = perf_data__fd(session->data);
2088 int err; 2088 int err;
2089 2089
2090 if (perf_data_file__is_pipe(session->file)) { 2090 if (perf_data__is_pipe(session->data)) {
2091 data_offset = 0; 2091 data_offset = 0;
2092 } else { 2092 } else {
2093 data_offset = lseek(fd, 0, SEEK_CUR); 2093 data_offset = lseek(fd, 0, SEEK_CUR);
diff --git a/tools/perf/util/intlist.h b/tools/perf/util/intlist.h
index 020b9ca1b47e..85bab8735fa9 100644
--- a/tools/perf/util/intlist.h
+++ b/tools/perf/util/intlist.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_INTLIST_H 2#ifndef __PERF_INTLIST_H
2#define __PERF_INTLIST_H 3#define __PERF_INTLIST_H
3 4
diff --git a/tools/perf/util/jit.h b/tools/perf/util/jit.h
index 3f42ee4d2a0b..6817ffc2a059 100644
--- a/tools/perf/util/jit.h
+++ b/tools/perf/util/jit.h
@@ -1,9 +1,10 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __JIT_H__ 2#ifndef __JIT_H__
2#define __JIT_H__ 3#define __JIT_H__
3 4
4#include <data.h> 5#include <data.h>
5 6
6int jit_process(struct perf_session *session, struct perf_data_file *output, 7int jit_process(struct perf_session *session, struct perf_data *output,
7 struct machine *machine, char *filename, pid_t pid, u64 *nbytes); 8 struct machine *machine, char *filename, pid_t pid, u64 *nbytes);
8 9
9int jit_inject_record(const char *filename); 10int jit_inject_record(const char *filename);
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 9084930e1757..a1863000e972 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/sysmacros.h> 2#include <sys/sysmacros.h>
2#include <sys/types.h> 3#include <sys/types.h>
3#include <errno.h> 4#include <errno.h>
@@ -29,7 +30,7 @@
29#include "sane_ctype.h" 30#include "sane_ctype.h"
30 31
31struct jit_buf_desc { 32struct jit_buf_desc {
32 struct perf_data_file *output; 33 struct perf_data *output;
33 struct perf_session *session; 34 struct perf_session *session;
34 struct machine *machine; 35 struct machine *machine;
35 union jr_entry *entry; 36 union jr_entry *entry;
@@ -60,8 +61,8 @@ struct debug_line_info {
60 61
61struct jit_tool { 62struct jit_tool {
62 struct perf_tool tool; 63 struct perf_tool tool;
63 struct perf_data_file output; 64 struct perf_data output;
64 struct perf_data_file input; 65 struct perf_data input;
65 u64 bytes_written; 66 u64 bytes_written;
66}; 67};
67 68
@@ -356,7 +357,7 @@ jit_inject_event(struct jit_buf_desc *jd, union perf_event *event)
356{ 357{
357 ssize_t size; 358 ssize_t size;
358 359
359 size = perf_data_file__write(jd->output, event, event->header.size); 360 size = perf_data__write(jd->output, event, event->header.size);
360 if (size < 0) 361 if (size < 0)
361 return -1; 362 return -1;
362 363
@@ -751,7 +752,7 @@ jit_detect(char *mmap_name, pid_t pid)
751 752
752int 753int
753jit_process(struct perf_session *session, 754jit_process(struct perf_session *session,
754 struct perf_data_file *output, 755 struct perf_data *output,
755 struct machine *machine, 756 struct machine *machine,
756 char *filename, 757 char *filename,
757 pid_t pid, 758 pid_t pid,
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index d01e73592f6e..7b1f06567521 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_KVM_STAT_H 2#ifndef __PERF_KVM_STAT_H
2#define __PERF_KVM_STAT_H 3#define __PERF_KVM_STAT_H
3 4
diff --git a/tools/perf/util/levenshtein.c b/tools/perf/util/levenshtein.c
index f616e4f65b67..a217ecf0359d 100644
--- a/tools/perf/util/levenshtein.c
+++ b/tools/perf/util/levenshtein.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "levenshtein.h" 2#include "levenshtein.h"
2#include <errno.h> 3#include <errno.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/perf/util/levenshtein.h b/tools/perf/util/levenshtein.h
index b0fcb6d8a881..34ca173c557d 100644
--- a/tools/perf/util/levenshtein.h
+++ b/tools/perf/util/levenshtein.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_LEVENSHTEIN_H 2#ifndef __PERF_LEVENSHTEIN_H
2#define __PERF_LEVENSHTEIN_H 3#define __PERF_LEVENSHTEIN_H
3 4
diff --git a/tools/perf/util/libunwind/arm64.c b/tools/perf/util/libunwind/arm64.c
index 6559bc586643..66756e6be111 100644
--- a/tools/perf/util/libunwind/arm64.c
+++ b/tools/perf/util/libunwind/arm64.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file setups defines to compile arch specific binary from the 3 * This file setups defines to compile arch specific binary from the
3 * generic one. 4 * generic one.
diff --git a/tools/perf/util/libunwind/x86_32.c b/tools/perf/util/libunwind/x86_32.c
index 957ffff72428..c5e568188e19 100644
--- a/tools/perf/util/libunwind/x86_32.c
+++ b/tools/perf/util/libunwind/x86_32.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * This file setups defines to compile arch specific binary from the 3 * This file setups defines to compile arch specific binary from the
3 * generic one. 4 * generic one.
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 209b0c82eff4..4952b429caa7 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> 3 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
3 * Copyright (C) 2015, Huawei Inc. 4 * Copyright (C) 2015, Huawei Inc.
diff --git a/tools/perf/util/llvm-utils.h b/tools/perf/util/llvm-utils.h
index c87a2a92a88f..d3ad8deb5db4 100644
--- a/tools/perf/util/llvm-utils.h
+++ b/tools/perf/util/llvm-utils.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> 3 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
3 * Copyright (C) 2015, Huawei Inc. 4 * Copyright (C) 2015, Huawei Inc.
diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
index 4ca7c5c6cdcd..07498eaddc08 100644
--- a/tools/perf/util/lzma.c
+++ b/tools/perf/util/lzma.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <lzma.h> 3#include <lzma.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index df709363ef69..6a8d03c3d9b7 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <dirent.h> 2#include <dirent.h>
2#include <errno.h> 3#include <errno.h>
3#include <inttypes.h> 4#include <inttypes.h>
@@ -30,7 +31,21 @@ static void dsos__init(struct dsos *dsos)
30{ 31{
31 INIT_LIST_HEAD(&dsos->head); 32 INIT_LIST_HEAD(&dsos->head);
32 dsos->root = RB_ROOT; 33 dsos->root = RB_ROOT;
33 pthread_rwlock_init(&dsos->lock, NULL); 34 init_rwsem(&dsos->lock);
35}
36
37static void machine__threads_init(struct machine *machine)
38{
39 int i;
40
41 for (i = 0; i < THREADS__TABLE_SIZE; i++) {
42 struct threads *threads = &machine->threads[i];
43 threads->entries = RB_ROOT;
44 init_rwsem(&threads->lock);
45 threads->nr = 0;
46 INIT_LIST_HEAD(&threads->dead);
47 threads->last_match = NULL;
48 }
34} 49}
35 50
36int machine__init(struct machine *machine, const char *root_dir, pid_t pid) 51int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
@@ -40,11 +55,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
40 RB_CLEAR_NODE(&machine->rb_node); 55 RB_CLEAR_NODE(&machine->rb_node);
41 dsos__init(&machine->dsos); 56 dsos__init(&machine->dsos);
42 57
43 machine->threads = RB_ROOT; 58 machine__threads_init(machine);
44 pthread_rwlock_init(&machine->threads_lock, NULL);
45 machine->nr_threads = 0;
46 INIT_LIST_HEAD(&machine->dead_threads);
47 machine->last_match = NULL;
48 59
49 machine->vdso_info = NULL; 60 machine->vdso_info = NULL;
50 machine->env = NULL; 61 machine->env = NULL;
@@ -120,7 +131,7 @@ static void dsos__purge(struct dsos *dsos)
120{ 131{
121 struct dso *pos, *n; 132 struct dso *pos, *n;
122 133
123 pthread_rwlock_wrlock(&dsos->lock); 134 down_write(&dsos->lock);
124 135
125 list_for_each_entry_safe(pos, n, &dsos->head, node) { 136 list_for_each_entry_safe(pos, n, &dsos->head, node) {
126 RB_CLEAR_NODE(&pos->rb_node); 137 RB_CLEAR_NODE(&pos->rb_node);
@@ -129,39 +140,49 @@ static void dsos__purge(struct dsos *dsos)
129 dso__put(pos); 140 dso__put(pos);
130 } 141 }
131 142
132 pthread_rwlock_unlock(&dsos->lock); 143 up_write(&dsos->lock);
133} 144}
134 145
135static void dsos__exit(struct dsos *dsos) 146static void dsos__exit(struct dsos *dsos)
136{ 147{
137 dsos__purge(dsos); 148 dsos__purge(dsos);
138 pthread_rwlock_destroy(&dsos->lock); 149 exit_rwsem(&dsos->lock);
139} 150}
140 151
141void machine__delete_threads(struct machine *machine) 152void machine__delete_threads(struct machine *machine)
142{ 153{
143 struct rb_node *nd; 154 struct rb_node *nd;
155 int i;
144 156
145 pthread_rwlock_wrlock(&machine->threads_lock); 157 for (i = 0; i < THREADS__TABLE_SIZE; i++) {
146 nd = rb_first(&machine->threads); 158 struct threads *threads = &machine->threads[i];
147 while (nd) { 159 down_write(&threads->lock);
148 struct thread *t = rb_entry(nd, struct thread, rb_node); 160 nd = rb_first(&threads->entries);
161 while (nd) {
162 struct thread *t = rb_entry(nd, struct thread, rb_node);
149 163
150 nd = rb_next(nd); 164 nd = rb_next(nd);
151 __machine__remove_thread(machine, t, false); 165 __machine__remove_thread(machine, t, false);
166 }
167 up_write(&threads->lock);
152 } 168 }
153 pthread_rwlock_unlock(&machine->threads_lock);
154} 169}
155 170
156void machine__exit(struct machine *machine) 171void machine__exit(struct machine *machine)
157{ 172{
173 int i;
174
158 machine__destroy_kernel_maps(machine); 175 machine__destroy_kernel_maps(machine);
159 map_groups__exit(&machine->kmaps); 176 map_groups__exit(&machine->kmaps);
160 dsos__exit(&machine->dsos); 177 dsos__exit(&machine->dsos);
161 machine__exit_vdso(machine); 178 machine__exit_vdso(machine);
162 zfree(&machine->root_dir); 179 zfree(&machine->root_dir);
163 zfree(&machine->current_tid); 180 zfree(&machine->current_tid);
164 pthread_rwlock_destroy(&machine->threads_lock); 181
182 for (i = 0; i < THREADS__TABLE_SIZE; i++) {
183 struct threads *threads = &machine->threads[i];
184 exit_rwsem(&threads->lock);
185 }
165} 186}
166 187
167void machine__delete(struct machine *machine) 188void machine__delete(struct machine *machine)
@@ -379,10 +400,11 @@ out_err:
379 * lookup/new thread inserted. 400 * lookup/new thread inserted.
380 */ 401 */
381static struct thread *____machine__findnew_thread(struct machine *machine, 402static struct thread *____machine__findnew_thread(struct machine *machine,
403 struct threads *threads,
382 pid_t pid, pid_t tid, 404 pid_t pid, pid_t tid,
383 bool create) 405 bool create)
384{ 406{
385 struct rb_node **p = &machine->threads.rb_node; 407 struct rb_node **p = &threads->entries.rb_node;
386 struct rb_node *parent = NULL; 408 struct rb_node *parent = NULL;
387 struct thread *th; 409 struct thread *th;
388 410
@@ -391,14 +413,14 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
391 * so most of the time we dont have to look up 413 * so most of the time we dont have to look up
392 * the full rbtree: 414 * the full rbtree:
393 */ 415 */
394 th = machine->last_match; 416 th = threads->last_match;
395 if (th != NULL) { 417 if (th != NULL) {
396 if (th->tid == tid) { 418 if (th->tid == tid) {
397 machine__update_thread_pid(machine, th, pid); 419 machine__update_thread_pid(machine, th, pid);
398 return thread__get(th); 420 return thread__get(th);
399 } 421 }
400 422
401 machine->last_match = NULL; 423 threads->last_match = NULL;
402 } 424 }
403 425
404 while (*p != NULL) { 426 while (*p != NULL) {
@@ -406,7 +428,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
406 th = rb_entry(parent, struct thread, rb_node); 428 th = rb_entry(parent, struct thread, rb_node);
407 429
408 if (th->tid == tid) { 430 if (th->tid == tid) {
409 machine->last_match = th; 431 threads->last_match = th;
410 machine__update_thread_pid(machine, th, pid); 432 machine__update_thread_pid(machine, th, pid);
411 return thread__get(th); 433 return thread__get(th);
412 } 434 }
@@ -423,7 +445,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
423 th = thread__new(pid, tid); 445 th = thread__new(pid, tid);
424 if (th != NULL) { 446 if (th != NULL) {
425 rb_link_node(&th->rb_node, parent, p); 447 rb_link_node(&th->rb_node, parent, p);
426 rb_insert_color(&th->rb_node, &machine->threads); 448 rb_insert_color(&th->rb_node, &threads->entries);
427 449
428 /* 450 /*
429 * We have to initialize map_groups separately 451 * We have to initialize map_groups separately
@@ -434,7 +456,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
434 * leader and that would screwed the rb tree. 456 * leader and that would screwed the rb tree.
435 */ 457 */
436 if (thread__init_map_groups(th, machine)) { 458 if (thread__init_map_groups(th, machine)) {
437 rb_erase_init(&th->rb_node, &machine->threads); 459 rb_erase_init(&th->rb_node, &threads->entries);
438 RB_CLEAR_NODE(&th->rb_node); 460 RB_CLEAR_NODE(&th->rb_node);
439 thread__put(th); 461 thread__put(th);
440 return NULL; 462 return NULL;
@@ -443,8 +465,8 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
443 * It is now in the rbtree, get a ref 465 * It is now in the rbtree, get a ref
444 */ 466 */
445 thread__get(th); 467 thread__get(th);
446 machine->last_match = th; 468 threads->last_match = th;
447 ++machine->nr_threads; 469 ++threads->nr;
448 } 470 }
449 471
450 return th; 472 return th;
@@ -452,27 +474,30 @@ static struct thread *____machine__findnew_thread(struct machine *machine,
452 474
453struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid) 475struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid)
454{ 476{
455 return ____machine__findnew_thread(machine, pid, tid, true); 477 return ____machine__findnew_thread(machine, machine__threads(machine, tid), pid, tid, true);
456} 478}
457 479
458struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, 480struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
459 pid_t tid) 481 pid_t tid)
460{ 482{
483 struct threads *threads = machine__threads(machine, tid);
461 struct thread *th; 484 struct thread *th;
462 485
463 pthread_rwlock_wrlock(&machine->threads_lock); 486 down_write(&threads->lock);
464 th = __machine__findnew_thread(machine, pid, tid); 487 th = __machine__findnew_thread(machine, pid, tid);
465 pthread_rwlock_unlock(&machine->threads_lock); 488 up_write(&threads->lock);
466 return th; 489 return th;
467} 490}
468 491
469struct thread *machine__find_thread(struct machine *machine, pid_t pid, 492struct thread *machine__find_thread(struct machine *machine, pid_t pid,
470 pid_t tid) 493 pid_t tid)
471{ 494{
495 struct threads *threads = machine__threads(machine, tid);
472 struct thread *th; 496 struct thread *th;
473 pthread_rwlock_rdlock(&machine->threads_lock); 497
474 th = ____machine__findnew_thread(machine, pid, tid, false); 498 down_read(&threads->lock);
475 pthread_rwlock_unlock(&machine->threads_lock); 499 th = ____machine__findnew_thread(machine, threads, pid, tid, false);
500 up_read(&threads->lock);
476 return th; 501 return th;
477} 502}
478 503
@@ -564,7 +589,7 @@ static struct dso *machine__findnew_module_dso(struct machine *machine,
564{ 589{
565 struct dso *dso; 590 struct dso *dso;
566 591
567 pthread_rwlock_wrlock(&machine->dsos.lock); 592 down_write(&machine->dsos.lock);
568 593
569 dso = __dsos__find(&machine->dsos, m->name, true); 594 dso = __dsos__find(&machine->dsos, m->name, true);
570 if (!dso) { 595 if (!dso) {
@@ -578,7 +603,7 @@ static struct dso *machine__findnew_module_dso(struct machine *machine,
578 603
579 dso__get(dso); 604 dso__get(dso);
580out_unlock: 605out_unlock:
581 pthread_rwlock_unlock(&machine->dsos.lock); 606 up_write(&machine->dsos.lock);
582 return dso; 607 return dso;
583} 608}
584 609
@@ -719,21 +744,25 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
719 744
720size_t machine__fprintf(struct machine *machine, FILE *fp) 745size_t machine__fprintf(struct machine *machine, FILE *fp)
721{ 746{
722 size_t ret;
723 struct rb_node *nd; 747 struct rb_node *nd;
748 size_t ret;
749 int i;
724 750
725 pthread_rwlock_rdlock(&machine->threads_lock); 751 for (i = 0; i < THREADS__TABLE_SIZE; i++) {
752 struct threads *threads = &machine->threads[i];
726 753
727 ret = fprintf(fp, "Threads: %u\n", machine->nr_threads); 754 down_read(&threads->lock);
728 755
729 for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) { 756 ret = fprintf(fp, "Threads: %u\n", threads->nr);
730 struct thread *pos = rb_entry(nd, struct thread, rb_node);
731 757
732 ret += thread__fprintf(pos, fp); 758 for (nd = rb_first(&threads->entries); nd; nd = rb_next(nd)) {
733 } 759 struct thread *pos = rb_entry(nd, struct thread, rb_node);
734 760
735 pthread_rwlock_unlock(&machine->threads_lock); 761 ret += thread__fprintf(pos, fp);
762 }
736 763
764 up_read(&threads->lock);
765 }
737 return ret; 766 return ret;
738} 767}
739 768
@@ -1292,7 +1321,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
1292 struct dso *kernel = NULL; 1321 struct dso *kernel = NULL;
1293 struct dso *dso; 1322 struct dso *dso;
1294 1323
1295 pthread_rwlock_rdlock(&machine->dsos.lock); 1324 down_read(&machine->dsos.lock);
1296 1325
1297 list_for_each_entry(dso, &machine->dsos.head, node) { 1326 list_for_each_entry(dso, &machine->dsos.head, node) {
1298 1327
@@ -1322,7 +1351,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
1322 break; 1351 break;
1323 } 1352 }
1324 1353
1325 pthread_rwlock_unlock(&machine->dsos.lock); 1354 up_read(&machine->dsos.lock);
1326 1355
1327 if (kernel == NULL) 1356 if (kernel == NULL)
1328 kernel = machine__findnew_dso(machine, kmmap_prefix); 1357 kernel = machine__findnew_dso(machine, kmmap_prefix);
@@ -1479,23 +1508,25 @@ out_problem:
1479 1508
1480static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock) 1509static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock)
1481{ 1510{
1482 if (machine->last_match == th) 1511 struct threads *threads = machine__threads(machine, th->tid);
1483 machine->last_match = NULL; 1512
1513 if (threads->last_match == th)
1514 threads->last_match = NULL;
1484 1515
1485 BUG_ON(refcount_read(&th->refcnt) == 0); 1516 BUG_ON(refcount_read(&th->refcnt) == 0);
1486 if (lock) 1517 if (lock)
1487 pthread_rwlock_wrlock(&machine->threads_lock); 1518 down_write(&threads->lock);
1488 rb_erase_init(&th->rb_node, &machine->threads); 1519 rb_erase_init(&th->rb_node, &threads->entries);
1489 RB_CLEAR_NODE(&th->rb_node); 1520 RB_CLEAR_NODE(&th->rb_node);
1490 --machine->nr_threads; 1521 --threads->nr;
1491 /* 1522 /*
1492 * Move it first to the dead_threads list, then drop the reference, 1523 * Move it first to the dead_threads list, then drop the reference,
1493 * if this is the last reference, then the thread__delete destructor 1524 * if this is the last reference, then the thread__delete destructor
1494 * will be called and we will remove it from the dead_threads list. 1525 * will be called and we will remove it from the dead_threads list.
1495 */ 1526 */
1496 list_add_tail(&th->node, &machine->dead_threads); 1527 list_add_tail(&th->node, &threads->dead);
1497 if (lock) 1528 if (lock)
1498 pthread_rwlock_unlock(&machine->threads_lock); 1529 up_write(&threads->lock);
1499 thread__put(th); 1530 thread__put(th);
1500} 1531}
1501 1532
@@ -1679,6 +1710,26 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
1679 return mi; 1710 return mi;
1680} 1711}
1681 1712
1713static char *callchain_srcline(struct map *map, struct symbol *sym, u64 ip)
1714{
1715 char *srcline = NULL;
1716
1717 if (!map || callchain_param.key == CCKEY_FUNCTION)
1718 return srcline;
1719
1720 srcline = srcline__tree_find(&map->dso->srclines, ip);
1721 if (!srcline) {
1722 bool show_sym = false;
1723 bool show_addr = callchain_param.key == CCKEY_ADDRESS;
1724
1725 srcline = get_srcline(map->dso, map__rip_2objdump(map, ip),
1726 sym, show_sym, show_addr);
1727 srcline__tree_insert(&map->dso->srclines, ip, srcline);
1728 }
1729
1730 return srcline;
1731}
1732
1682struct iterations { 1733struct iterations {
1683 int nr_loop_iter; 1734 int nr_loop_iter;
1684 u64 cycles; 1735 u64 cycles;
@@ -1698,6 +1749,7 @@ static int add_callchain_ip(struct thread *thread,
1698 struct addr_location al; 1749 struct addr_location al;
1699 int nr_loop_iter = 0; 1750 int nr_loop_iter = 0;
1700 u64 iter_cycles = 0; 1751 u64 iter_cycles = 0;
1752 const char *srcline = NULL;
1701 1753
1702 al.filtered = 0; 1754 al.filtered = 0;
1703 al.sym = NULL; 1755 al.sym = NULL;
@@ -1753,9 +1805,10 @@ static int add_callchain_ip(struct thread *thread,
1753 iter_cycles = iter->cycles; 1805 iter_cycles = iter->cycles;
1754 } 1806 }
1755 1807
1808 srcline = callchain_srcline(al.map, al.sym, al.addr);
1756 return callchain_cursor_append(cursor, al.addr, al.map, al.sym, 1809 return callchain_cursor_append(cursor, al.addr, al.map, al.sym,
1757 branch, flags, nr_loop_iter, 1810 branch, flags, nr_loop_iter,
1758 iter_cycles, branch_from); 1811 iter_cycles, branch_from, srcline);
1759} 1812}
1760 1813
1761struct branch_info *sample__resolve_bstack(struct perf_sample *sample, 1814struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
@@ -2068,15 +2121,54 @@ check_calls:
2068 return 0; 2121 return 0;
2069} 2122}
2070 2123
2124static int append_inlines(struct callchain_cursor *cursor,
2125 struct map *map, struct symbol *sym, u64 ip)
2126{
2127 struct inline_node *inline_node;
2128 struct inline_list *ilist;
2129 u64 addr;
2130 int ret = 1;
2131
2132 if (!symbol_conf.inline_name || !map || !sym)
2133 return ret;
2134
2135 addr = map__rip_2objdump(map, ip);
2136
2137 inline_node = inlines__tree_find(&map->dso->inlined_nodes, addr);
2138 if (!inline_node) {
2139 inline_node = dso__parse_addr_inlines(map->dso, addr, sym);
2140 if (!inline_node)
2141 return ret;
2142 inlines__tree_insert(&map->dso->inlined_nodes, inline_node);
2143 }
2144
2145 list_for_each_entry(ilist, &inline_node->val, list) {
2146 ret = callchain_cursor_append(cursor, ip, map,
2147 ilist->symbol, false,
2148 NULL, 0, 0, 0, ilist->srcline);
2149
2150 if (ret != 0)
2151 return ret;
2152 }
2153
2154 return ret;
2155}
2156
2071static int unwind_entry(struct unwind_entry *entry, void *arg) 2157static int unwind_entry(struct unwind_entry *entry, void *arg)
2072{ 2158{
2073 struct callchain_cursor *cursor = arg; 2159 struct callchain_cursor *cursor = arg;
2160 const char *srcline = NULL;
2074 2161
2075 if (symbol_conf.hide_unresolved && entry->sym == NULL) 2162 if (symbol_conf.hide_unresolved && entry->sym == NULL)
2076 return 0; 2163 return 0;
2164
2165 if (append_inlines(cursor, entry->map, entry->sym, entry->ip) == 0)
2166 return 0;
2167
2168 srcline = callchain_srcline(entry->map, entry->sym, entry->ip);
2077 return callchain_cursor_append(cursor, entry->ip, 2169 return callchain_cursor_append(cursor, entry->ip,
2078 entry->map, entry->sym, 2170 entry->map, entry->sym,
2079 false, NULL, 0, 0, 0); 2171 false, NULL, 0, 0, 0, srcline);
2080} 2172}
2081 2173
2082static int thread__resolve_callchain_unwind(struct thread *thread, 2174static int thread__resolve_callchain_unwind(struct thread *thread,
@@ -2140,21 +2232,26 @@ int machine__for_each_thread(struct machine *machine,
2140 int (*fn)(struct thread *thread, void *p), 2232 int (*fn)(struct thread *thread, void *p),
2141 void *priv) 2233 void *priv)
2142{ 2234{
2235 struct threads *threads;
2143 struct rb_node *nd; 2236 struct rb_node *nd;
2144 struct thread *thread; 2237 struct thread *thread;
2145 int rc = 0; 2238 int rc = 0;
2239 int i;
2146 2240
2147 for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) { 2241 for (i = 0; i < THREADS__TABLE_SIZE; i++) {
2148 thread = rb_entry(nd, struct thread, rb_node); 2242 threads = &machine->threads[i];
2149 rc = fn(thread, priv); 2243 for (nd = rb_first(&threads->entries); nd; nd = rb_next(nd)) {
2150 if (rc != 0) 2244 thread = rb_entry(nd, struct thread, rb_node);
2151 return rc; 2245 rc = fn(thread, priv);
2152 } 2246 if (rc != 0)
2247 return rc;
2248 }
2153 2249
2154 list_for_each_entry(thread, &machine->dead_threads, node) { 2250 list_for_each_entry(thread, &threads->dead, node) {
2155 rc = fn(thread, priv); 2251 rc = fn(thread, priv);
2156 if (rc != 0) 2252 if (rc != 0)
2157 return rc; 2253 return rc;
2254 }
2158 } 2255 }
2159 return rc; 2256 return rc;
2160} 2257}
@@ -2183,12 +2280,16 @@ int machines__for_each_thread(struct machines *machines,
2183int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, 2280int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
2184 struct target *target, struct thread_map *threads, 2281 struct target *target, struct thread_map *threads,
2185 perf_event__handler_t process, bool data_mmap, 2282 perf_event__handler_t process, bool data_mmap,
2186 unsigned int proc_map_timeout) 2283 unsigned int proc_map_timeout,
2284 unsigned int nr_threads_synthesize)
2187{ 2285{
2188 if (target__has_task(target)) 2286 if (target__has_task(target))
2189 return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap, proc_map_timeout); 2287 return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap, proc_map_timeout);
2190 else if (target__has_cpu(target)) 2288 else if (target__has_cpu(target))
2191 return perf_event__synthesize_threads(tool, process, machine, data_mmap, proc_map_timeout); 2289 return perf_event__synthesize_threads(tool, process,
2290 machine, data_mmap,
2291 proc_map_timeout,
2292 nr_threads_synthesize);
2192 /* command specified */ 2293 /* command specified */
2193 return 0; 2294 return 0;
2194} 2295}
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 3cdb1340f917..5ce860b64c74 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_MACHINE_H 2#ifndef __PERF_MACHINE_H
2#define __PERF_MACHINE_H 3#define __PERF_MACHINE_H
3 4
@@ -6,6 +7,7 @@
6#include "map.h" 7#include "map.h"
7#include "dso.h" 8#include "dso.h"
8#include "event.h" 9#include "event.h"
10#include "rwsem.h"
9 11
10struct addr_location; 12struct addr_location;
11struct branch_stack; 13struct branch_stack;
@@ -23,6 +25,17 @@ extern const char *ref_reloc_sym_names[];
23 25
24struct vdso_info; 26struct vdso_info;
25 27
28#define THREADS__TABLE_BITS 8
29#define THREADS__TABLE_SIZE (1 << THREADS__TABLE_BITS)
30
31struct threads {
32 struct rb_root entries;
33 struct rw_semaphore lock;
34 unsigned int nr;
35 struct list_head dead;
36 struct thread *last_match;
37};
38
26struct machine { 39struct machine {
27 struct rb_node rb_node; 40 struct rb_node rb_node;
28 pid_t pid; 41 pid_t pid;
@@ -30,11 +43,7 @@ struct machine {
30 bool comm_exec; 43 bool comm_exec;
31 bool kptr_restrict_warned; 44 bool kptr_restrict_warned;
32 char *root_dir; 45 char *root_dir;
33 struct rb_root threads; 46 struct threads threads[THREADS__TABLE_SIZE];
34 pthread_rwlock_t threads_lock;
35 unsigned int nr_threads;
36 struct list_head dead_threads;
37 struct thread *last_match;
38 struct vdso_info *vdso_info; 47 struct vdso_info *vdso_info;
39 struct perf_env *env; 48 struct perf_env *env;
40 struct dsos dsos; 49 struct dsos dsos;
@@ -48,6 +57,12 @@ struct machine {
48 }; 57 };
49}; 58};
50 59
60static inline struct threads *machine__threads(struct machine *machine, pid_t tid)
61{
62 /* Cast it to handle tid == -1 */
63 return &machine->threads[(unsigned int)tid % THREADS__TABLE_SIZE];
64}
65
51static inline 66static inline
52struct map *__machine__kernel_map(struct machine *machine, enum map_type type) 67struct map *__machine__kernel_map(struct machine *machine, enum map_type type)
53{ 68{
@@ -243,15 +258,18 @@ int machines__for_each_thread(struct machines *machines,
243int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, 258int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
244 struct target *target, struct thread_map *threads, 259 struct target *target, struct thread_map *threads,
245 perf_event__handler_t process, bool data_mmap, 260 perf_event__handler_t process, bool data_mmap,
246 unsigned int proc_map_timeout); 261 unsigned int proc_map_timeout,
262 unsigned int nr_threads_synthesize);
247static inline 263static inline
248int machine__synthesize_threads(struct machine *machine, struct target *target, 264int machine__synthesize_threads(struct machine *machine, struct target *target,
249 struct thread_map *threads, bool data_mmap, 265 struct thread_map *threads, bool data_mmap,
250 unsigned int proc_map_timeout) 266 unsigned int proc_map_timeout,
267 unsigned int nr_threads_synthesize)
251{ 268{
252 return __machine__synthesize_threads(machine, NULL, target, threads, 269 return __machine__synthesize_threads(machine, NULL, target, threads,
253 perf_event__process, data_mmap, 270 perf_event__process, data_mmap,
254 proc_map_timeout); 271 proc_map_timeout,
272 nr_threads_synthesize);
255} 273}
256 274
257pid_t machine__get_current_tid(struct machine *machine, int cpu); 275pid_t machine__get_current_tid(struct machine *machine, int cpu);
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index bdaa0a4edc17..6d40efd74402 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "symbol.h" 2#include "symbol.h"
2#include <errno.h> 3#include <errno.h>
3#include <inttypes.h> 4#include <inttypes.h>
@@ -488,7 +489,7 @@ u64 map__objdump_2mem(struct map *map, u64 ip)
488static void maps__init(struct maps *maps) 489static void maps__init(struct maps *maps)
489{ 490{
490 maps->entries = RB_ROOT; 491 maps->entries = RB_ROOT;
491 pthread_rwlock_init(&maps->lock, NULL); 492 init_rwsem(&maps->lock);
492} 493}
493 494
494void map_groups__init(struct map_groups *mg, struct machine *machine) 495void map_groups__init(struct map_groups *mg, struct machine *machine)
@@ -517,9 +518,9 @@ static void __maps__purge(struct maps *maps)
517 518
518static void maps__exit(struct maps *maps) 519static void maps__exit(struct maps *maps)
519{ 520{
520 pthread_rwlock_wrlock(&maps->lock); 521 down_write(&maps->lock);
521 __maps__purge(maps); 522 __maps__purge(maps);
522 pthread_rwlock_unlock(&maps->lock); 523 up_write(&maps->lock);
523} 524}
524 525
525void map_groups__exit(struct map_groups *mg) 526void map_groups__exit(struct map_groups *mg)
@@ -586,7 +587,7 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
586 struct symbol *sym; 587 struct symbol *sym;
587 struct rb_node *nd; 588 struct rb_node *nd;
588 589
589 pthread_rwlock_rdlock(&maps->lock); 590 down_read(&maps->lock);
590 591
591 for (nd = rb_first(&maps->entries); nd; nd = rb_next(nd)) { 592 for (nd = rb_first(&maps->entries); nd; nd = rb_next(nd)) {
592 struct map *pos = rb_entry(nd, struct map, rb_node); 593 struct map *pos = rb_entry(nd, struct map, rb_node);
@@ -602,7 +603,7 @@ struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
602 603
603 sym = NULL; 604 sym = NULL;
604out: 605out:
605 pthread_rwlock_unlock(&maps->lock); 606 up_read(&maps->lock);
606 return sym; 607 return sym;
607} 608}
608 609
@@ -638,7 +639,7 @@ static size_t maps__fprintf(struct maps *maps, FILE *fp)
638 size_t printed = 0; 639 size_t printed = 0;
639 struct rb_node *nd; 640 struct rb_node *nd;
640 641
641 pthread_rwlock_rdlock(&maps->lock); 642 down_read(&maps->lock);
642 643
643 for (nd = rb_first(&maps->entries); nd; nd = rb_next(nd)) { 644 for (nd = rb_first(&maps->entries); nd; nd = rb_next(nd)) {
644 struct map *pos = rb_entry(nd, struct map, rb_node); 645 struct map *pos = rb_entry(nd, struct map, rb_node);
@@ -650,7 +651,7 @@ static size_t maps__fprintf(struct maps *maps, FILE *fp)
650 } 651 }
651 } 652 }
652 653
653 pthread_rwlock_unlock(&maps->lock); 654 up_read(&maps->lock);
654 655
655 return printed; 656 return printed;
656} 657}
@@ -682,7 +683,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
682 struct rb_node *next; 683 struct rb_node *next;
683 int err = 0; 684 int err = 0;
684 685
685 pthread_rwlock_wrlock(&maps->lock); 686 down_write(&maps->lock);
686 687
687 root = &maps->entries; 688 root = &maps->entries;
688 next = rb_first(root); 689 next = rb_first(root);
@@ -750,7 +751,7 @@ put_map:
750 751
751 err = 0; 752 err = 0;
752out: 753out:
753 pthread_rwlock_unlock(&maps->lock); 754 up_write(&maps->lock);
754 return err; 755 return err;
755} 756}
756 757
@@ -771,7 +772,7 @@ int map_groups__clone(struct thread *thread,
771 struct map *map; 772 struct map *map;
772 struct maps *maps = &parent->maps[type]; 773 struct maps *maps = &parent->maps[type];
773 774
774 pthread_rwlock_rdlock(&maps->lock); 775 down_read(&maps->lock);
775 776
776 for (map = maps__first(maps); map; map = map__next(map)) { 777 for (map = maps__first(maps); map; map = map__next(map)) {
777 struct map *new = map__clone(map); 778 struct map *new = map__clone(map);
@@ -788,7 +789,7 @@ int map_groups__clone(struct thread *thread,
788 789
789 err = 0; 790 err = 0;
790out_unlock: 791out_unlock:
791 pthread_rwlock_unlock(&maps->lock); 792 up_read(&maps->lock);
792 return err; 793 return err;
793} 794}
794 795
@@ -815,9 +816,9 @@ static void __maps__insert(struct maps *maps, struct map *map)
815 816
816void maps__insert(struct maps *maps, struct map *map) 817void maps__insert(struct maps *maps, struct map *map)
817{ 818{
818 pthread_rwlock_wrlock(&maps->lock); 819 down_write(&maps->lock);
819 __maps__insert(maps, map); 820 __maps__insert(maps, map);
820 pthread_rwlock_unlock(&maps->lock); 821 up_write(&maps->lock);
821} 822}
822 823
823static void __maps__remove(struct maps *maps, struct map *map) 824static void __maps__remove(struct maps *maps, struct map *map)
@@ -828,9 +829,9 @@ static void __maps__remove(struct maps *maps, struct map *map)
828 829
829void maps__remove(struct maps *maps, struct map *map) 830void maps__remove(struct maps *maps, struct map *map)
830{ 831{
831 pthread_rwlock_wrlock(&maps->lock); 832 down_write(&maps->lock);
832 __maps__remove(maps, map); 833 __maps__remove(maps, map);
833 pthread_rwlock_unlock(&maps->lock); 834 up_write(&maps->lock);
834} 835}
835 836
836struct map *maps__find(struct maps *maps, u64 ip) 837struct map *maps__find(struct maps *maps, u64 ip)
@@ -838,7 +839,7 @@ struct map *maps__find(struct maps *maps, u64 ip)
838 struct rb_node **p, *parent = NULL; 839 struct rb_node **p, *parent = NULL;
839 struct map *m; 840 struct map *m;
840 841
841 pthread_rwlock_rdlock(&maps->lock); 842 down_read(&maps->lock);
842 843
843 p = &maps->entries.rb_node; 844 p = &maps->entries.rb_node;
844 while (*p != NULL) { 845 while (*p != NULL) {
@@ -854,7 +855,7 @@ struct map *maps__find(struct maps *maps, u64 ip)
854 855
855 m = NULL; 856 m = NULL;
856out: 857out:
857 pthread_rwlock_unlock(&maps->lock); 858 up_read(&maps->lock);
858 return m; 859 return m;
859} 860}
860 861
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 73aacf7a7dc4..edeb7291c8e1 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_MAP_H 2#ifndef __PERF_MAP_H
2#define __PERF_MAP_H 3#define __PERF_MAP_H
3 4
@@ -9,6 +10,7 @@
9#include <stdio.h> 10#include <stdio.h>
10#include <stdbool.h> 11#include <stdbool.h>
11#include <linux/types.h> 12#include <linux/types.h>
13#include "rwsem.h"
12 14
13enum map_type { 15enum map_type {
14 MAP__FUNCTION = 0, 16 MAP__FUNCTION = 0,
@@ -61,7 +63,7 @@ struct kmap {
61 63
62struct maps { 64struct maps {
63 struct rb_root entries; 65 struct rb_root entries;
64 pthread_rwlock_t lock; 66 struct rw_semaphore lock;
65}; 67};
66 68
67struct map_groups { 69struct map_groups {
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 28afe5fa84d6..93f74d8d3cdd 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stddef.h> 2#include <stddef.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/perf/util/mem-events.h b/tools/perf/util/mem-events.h
index 40f72ee4f42a..a889ec2fa9f5 100644
--- a/tools/perf/util/mem-events.h
+++ b/tools/perf/util/mem-events.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_MEM_EVENTS_H 2#ifndef __PERF_MEM_EVENTS_H
2#define __PERF_MEM_EVENTS_H 3#define __PERF_MEM_EVENTS_H
3 4
diff --git a/tools/perf/util/memswap.c b/tools/perf/util/memswap.c
index 55f7faa8d9ec..c1317e4983bc 100644
--- a/tools/perf/util/memswap.c
+++ b/tools/perf/util/memswap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <byteswap.h> 2#include <byteswap.h>
2#include "memswap.h" 3#include "memswap.h"
3#include <linux/types.h> 4#include <linux/types.h>
diff --git a/tools/perf/util/memswap.h b/tools/perf/util/memswap.h
index 7d1b1c34bb57..1e29ff903ca9 100644
--- a/tools/perf/util/memswap.h
+++ b/tools/perf/util/memswap.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_MEMSWAP_H_ 2#ifndef PERF_MEMSWAP_H_
2#define PERF_MEMSWAP_H_ 3#define PERF_MEMSWAP_H_
3 4
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
new file mode 100644
index 000000000000..0ddd9c199227
--- /dev/null
+++ b/tools/perf/util/metricgroup.c
@@ -0,0 +1,490 @@
1/*
2 * Copyright (c) 2017, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 */
14
15/* Manage metrics and groups of metrics from JSON files */
16
17#include "metricgroup.h"
18#include "evlist.h"
19#include "strbuf.h"
20#include "pmu.h"
21#include "expr.h"
22#include "rblist.h"
23#include "pmu.h"
24#include <string.h>
25#include <stdbool.h>
26#include <errno.h>
27#include "pmu-events/pmu-events.h"
28#include "strbuf.h"
29#include "strlist.h"
30#include <assert.h>
31#include <ctype.h>
32
33struct metric_event *metricgroup__lookup(struct rblist *metric_events,
34 struct perf_evsel *evsel,
35 bool create)
36{
37 struct rb_node *nd;
38 struct metric_event me = {
39 .evsel = evsel
40 };
41 nd = rblist__find(metric_events, &me);
42 if (nd)
43 return container_of(nd, struct metric_event, nd);
44 if (create) {
45 rblist__add_node(metric_events, &me);
46 nd = rblist__find(metric_events, &me);
47 if (nd)
48 return container_of(nd, struct metric_event, nd);
49 }
50 return NULL;
51}
52
53static int metric_event_cmp(struct rb_node *rb_node, const void *entry)
54{
55 struct metric_event *a = container_of(rb_node,
56 struct metric_event,
57 nd);
58 const struct metric_event *b = entry;
59
60 if (a->evsel == b->evsel)
61 return 0;
62 if ((char *)a->evsel < (char *)b->evsel)
63 return -1;
64 return +1;
65}
66
67static struct rb_node *metric_event_new(struct rblist *rblist __maybe_unused,
68 const void *entry)
69{
70 struct metric_event *me = malloc(sizeof(struct metric_event));
71
72 if (!me)
73 return NULL;
74 memcpy(me, entry, sizeof(struct metric_event));
75 me->evsel = ((struct metric_event *)entry)->evsel;
76 INIT_LIST_HEAD(&me->head);
77 return &me->nd;
78}
79
80static void metricgroup__rblist_init(struct rblist *metric_events)
81{
82 rblist__init(metric_events);
83 metric_events->node_cmp = metric_event_cmp;
84 metric_events->node_new = metric_event_new;
85}
86
87struct egroup {
88 struct list_head nd;
89 int idnum;
90 const char **ids;
91 const char *metric_name;
92 const char *metric_expr;
93};
94
95static struct perf_evsel *find_evsel(struct perf_evlist *perf_evlist,
96 const char **ids,
97 int idnum,
98 struct perf_evsel **metric_events)
99{
100 struct perf_evsel *ev, *start = NULL;
101 int ind = 0;
102
103 evlist__for_each_entry (perf_evlist, ev) {
104 if (!strcmp(ev->name, ids[ind])) {
105 metric_events[ind] = ev;
106 if (ind == 0)
107 start = ev;
108 if (++ind == idnum) {
109 metric_events[ind] = NULL;
110 return start;
111 }
112 } else {
113 ind = 0;
114 start = NULL;
115 }
116 }
117 /*
118 * This can happen when an alias expands to multiple
119 * events, like for uncore events.
120 * We don't support this case for now.
121 */
122 return NULL;
123}
124
125static int metricgroup__setup_events(struct list_head *groups,
126 struct perf_evlist *perf_evlist,
127 struct rblist *metric_events_list)
128{
129 struct metric_event *me;
130 struct metric_expr *expr;
131 int i = 0;
132 int ret = 0;
133 struct egroup *eg;
134 struct perf_evsel *evsel;
135
136 list_for_each_entry (eg, groups, nd) {
137 struct perf_evsel **metric_events;
138
139 metric_events = calloc(sizeof(void *), eg->idnum + 1);
140 if (!metric_events) {
141 ret = -ENOMEM;
142 break;
143 }
144 evsel = find_evsel(perf_evlist, eg->ids, eg->idnum,
145 metric_events);
146 if (!evsel) {
147 pr_debug("Cannot resolve %s: %s\n",
148 eg->metric_name, eg->metric_expr);
149 continue;
150 }
151 for (i = 0; i < eg->idnum; i++)
152 metric_events[i]->collect_stat = true;
153 me = metricgroup__lookup(metric_events_list, evsel, true);
154 if (!me) {
155 ret = -ENOMEM;
156 break;
157 }
158 expr = malloc(sizeof(struct metric_expr));
159 if (!expr) {
160 ret = -ENOMEM;
161 break;
162 }
163 expr->metric_expr = eg->metric_expr;
164 expr->metric_name = eg->metric_name;
165 expr->metric_events = metric_events;
166 list_add(&expr->nd, &me->head);
167 }
168 return ret;
169}
170
171static bool match_metric(const char *n, const char *list)
172{
173 int len;
174 char *m;
175
176 if (!list)
177 return false;
178 if (!strcmp(list, "all"))
179 return true;
180 if (!n)
181 return !strcasecmp(list, "No_group");
182 len = strlen(list);
183 m = strcasestr(n, list);
184 if (!m)
185 return false;
186 if ((m == n || m[-1] == ';' || m[-1] == ' ') &&
187 (m[len] == 0 || m[len] == ';'))
188 return true;
189 return false;
190}
191
192struct mep {
193 struct rb_node nd;
194 const char *name;
195 struct strlist *metrics;
196};
197
198static int mep_cmp(struct rb_node *rb_node, const void *entry)
199{
200 struct mep *a = container_of(rb_node, struct mep, nd);
201 struct mep *b = (struct mep *)entry;
202
203 return strcmp(a->name, b->name);
204}
205
206static struct rb_node *mep_new(struct rblist *rl __maybe_unused,
207 const void *entry)
208{
209 struct mep *me = malloc(sizeof(struct mep));
210
211 if (!me)
212 return NULL;
213 memcpy(me, entry, sizeof(struct mep));
214 me->name = strdup(me->name);
215 if (!me->name)
216 goto out_me;
217 me->metrics = strlist__new(NULL, NULL);
218 if (!me->metrics)
219 goto out_name;
220 return &me->nd;
221out_name:
222 free((char *)me->name);
223out_me:
224 free(me);
225 return NULL;
226}
227
228static struct mep *mep_lookup(struct rblist *groups, const char *name)
229{
230 struct rb_node *nd;
231 struct mep me = {
232 .name = name
233 };
234 nd = rblist__find(groups, &me);
235 if (nd)
236 return container_of(nd, struct mep, nd);
237 rblist__add_node(groups, &me);
238 nd = rblist__find(groups, &me);
239 if (nd)
240 return container_of(nd, struct mep, nd);
241 return NULL;
242}
243
244static void mep_delete(struct rblist *rl __maybe_unused,
245 struct rb_node *nd)
246{
247 struct mep *me = container_of(nd, struct mep, nd);
248
249 strlist__delete(me->metrics);
250 free((void *)me->name);
251 free(me);
252}
253
254static void metricgroup__print_strlist(struct strlist *metrics, bool raw)
255{
256 struct str_node *sn;
257 int n = 0;
258
259 strlist__for_each_entry (sn, metrics) {
260 if (raw)
261 printf("%s%s", n > 0 ? " " : "", sn->s);
262 else
263 printf(" %s\n", sn->s);
264 n++;
265 }
266 if (raw)
267 putchar('\n');
268}
269
270void metricgroup__print(bool metrics, bool metricgroups, char *filter,
271 bool raw)
272{
273 struct pmu_events_map *map = perf_pmu__find_map();
274 struct pmu_event *pe;
275 int i;
276 struct rblist groups;
277 struct rb_node *node, *next;
278 struct strlist *metriclist = NULL;
279
280 if (!map)
281 return;
282
283 if (!metricgroups) {
284 metriclist = strlist__new(NULL, NULL);
285 if (!metriclist)
286 return;
287 }
288
289 rblist__init(&groups);
290 groups.node_new = mep_new;
291 groups.node_cmp = mep_cmp;
292 groups.node_delete = mep_delete;
293 for (i = 0; ; i++) {
294 const char *g;
295 pe = &map->table[i];
296
297 if (!pe->name && !pe->metric_group && !pe->metric_name)
298 break;
299 if (!pe->metric_expr)
300 continue;
301 g = pe->metric_group;
302 if (!g && pe->metric_name) {
303 if (pe->name)
304 continue;
305 g = "No_group";
306 }
307 if (g) {
308 char *omg;
309 char *mg = strdup(g);
310
311 if (!mg)
312 return;
313 omg = mg;
314 while ((g = strsep(&mg, ";")) != NULL) {
315 struct mep *me;
316 char *s;
317
318 if (*g == 0)
319 g = "No_group";
320 while (isspace(*g))
321 g++;
322 if (filter && !strstr(g, filter))
323 continue;
324 if (raw)
325 s = (char *)pe->metric_name;
326 else {
327 if (asprintf(&s, "%s\n\t[%s]",
328 pe->metric_name, pe->desc) < 0)
329 return;
330 }
331
332 if (!s)
333 continue;
334
335 if (!metricgroups) {
336 strlist__add(metriclist, s);
337 } else {
338 me = mep_lookup(&groups, g);
339 if (!me)
340 continue;
341 strlist__add(me->metrics, s);
342 }
343 }
344 free(omg);
345 }
346 }
347
348 if (metricgroups && !raw)
349 printf("\nMetric Groups:\n\n");
350 else if (metrics && !raw)
351 printf("\nMetrics:\n\n");
352
353 for (node = rb_first(&groups.entries); node; node = next) {
354 struct mep *me = container_of(node, struct mep, nd);
355
356 if (metricgroups)
357 printf("%s%s%s", me->name, metrics ? ":" : "", raw ? " " : "\n");
358 if (metrics)
359 metricgroup__print_strlist(me->metrics, raw);
360 next = rb_next(node);
361 rblist__remove_node(&groups, node);
362 }
363 if (!metricgroups)
364 metricgroup__print_strlist(metriclist, raw);
365 strlist__delete(metriclist);
366}
367
368static int metricgroup__add_metric(const char *metric, struct strbuf *events,
369 struct list_head *group_list)
370{
371 struct pmu_events_map *map = perf_pmu__find_map();
372 struct pmu_event *pe;
373 int ret = -EINVAL;
374 int i, j;
375
376 if (!map)
377 return 0;
378
379 for (i = 0; ; i++) {
380 pe = &map->table[i];
381
382 if (!pe->name && !pe->metric_group && !pe->metric_name)
383 break;
384 if (!pe->metric_expr)
385 continue;
386 if (match_metric(pe->metric_group, metric) ||
387 match_metric(pe->metric_name, metric)) {
388 const char **ids;
389 int idnum;
390 struct egroup *eg;
391
392 pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
393
394 if (expr__find_other(pe->metric_expr,
395 NULL, &ids, &idnum) < 0)
396 continue;
397 if (events->len > 0)
398 strbuf_addf(events, ",");
399 for (j = 0; j < idnum; j++) {
400 pr_debug("found event %s\n", ids[j]);
401 strbuf_addf(events, "%s%s",
402 j == 0 ? "{" : ",",
403 ids[j]);
404 }
405 strbuf_addf(events, "}:W");
406
407 eg = malloc(sizeof(struct egroup));
408 if (!eg) {
409 ret = -ENOMEM;
410 break;
411 }
412 eg->ids = ids;
413 eg->idnum = idnum;
414 eg->metric_name = pe->metric_name;
415 eg->metric_expr = pe->metric_expr;
416 list_add_tail(&eg->nd, group_list);
417 ret = 0;
418 }
419 }
420 return ret;
421}
422
423static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
424 struct list_head *group_list)
425{
426 char *llist, *nlist, *p;
427 int ret = -EINVAL;
428
429 nlist = strdup(list);
430 if (!nlist)
431 return -ENOMEM;
432 llist = nlist;
433
434 strbuf_init(events, 100);
435 strbuf_addf(events, "%s", "");
436
437 while ((p = strsep(&llist, ",")) != NULL) {
438 ret = metricgroup__add_metric(p, events, group_list);
439 if (ret == -EINVAL) {
440 fprintf(stderr, "Cannot find metric or group `%s'\n",
441 p);
442 break;
443 }
444 }
445 free(nlist);
446 return ret;
447}
448
449static void metricgroup__free_egroups(struct list_head *group_list)
450{
451 struct egroup *eg, *egtmp;
452 int i;
453
454 list_for_each_entry_safe (eg, egtmp, group_list, nd) {
455 for (i = 0; i < eg->idnum; i++)
456 free((char *)eg->ids[i]);
457 free(eg->ids);
458 free(eg);
459 }
460}
461
462int metricgroup__parse_groups(const struct option *opt,
463 const char *str,
464 struct rblist *metric_events)
465{
466 struct parse_events_error parse_error;
467 struct perf_evlist *perf_evlist = *(struct perf_evlist **)opt->value;
468 struct strbuf extra_events;
469 LIST_HEAD(group_list);
470 int ret;
471
472 if (metric_events->nr_entries == 0)
473 metricgroup__rblist_init(metric_events);
474 ret = metricgroup__add_metric_list(str, &extra_events, &group_list);
475 if (ret)
476 return ret;
477 pr_debug("adding %s\n", extra_events.buf);
478 memset(&parse_error, 0, sizeof(struct parse_events_error));
479 ret = parse_events(perf_evlist, extra_events.buf, &parse_error);
480 if (ret) {
481 parse_events_print_error(&parse_error, extra_events.buf);
482 goto out;
483 }
484 strbuf_release(&extra_events);
485 ret = metricgroup__setup_events(&group_list, perf_evlist,
486 metric_events);
487out:
488 metricgroup__free_egroups(&group_list);
489 return ret;
490}
diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h
new file mode 100644
index 000000000000..06854e125ee7
--- /dev/null
+++ b/tools/perf/util/metricgroup.h
@@ -0,0 +1,31 @@
1#ifndef METRICGROUP_H
2#define METRICGROUP_H 1
3
4#include "linux/list.h"
5#include "rblist.h"
6#include <subcmd/parse-options.h>
7#include "evlist.h"
8#include "strbuf.h"
9
10struct metric_event {
11 struct rb_node nd;
12 struct perf_evsel *evsel;
13 struct list_head head; /* list of metric_expr */
14};
15
16struct metric_expr {
17 struct list_head nd;
18 const char *metric_expr;
19 const char *metric_name;
20 struct perf_evsel **metric_events;
21};
22
23struct metric_event *metricgroup__lookup(struct rblist *metric_events,
24 struct perf_evsel *evsel,
25 bool create);
26int metricgroup__parse_groups(const struct option *opt,
27 const char *str,
28 struct rblist *metric_events);
29
30void metricgroup__print(bool metrics, bool groups, char *filter, bool raw);
31#endif
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
new file mode 100644
index 000000000000..9fe5f9c7d577
--- /dev/null
+++ b/tools/perf/util/mmap.c
@@ -0,0 +1,352 @@
1/*
2 * Copyright (C) 2011-2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Parts came from evlist.c builtin-{top,stat,record}.c, see those files for further
5 * copyright notes.
6 *
7 * Released under the GPL v2. (and only v2, not any later version)
8 */
9
10#include <sys/mman.h>
11#include <inttypes.h>
12#include <asm/bug.h>
13#include "debug.h"
14#include "event.h"
15#include "mmap.h"
16#include "util.h" /* page_size */
17
18size_t perf_mmap__mmap_len(struct perf_mmap *map)
19{
20 return map->mask + 1 + page_size;
21}
22
23/* When check_messup is true, 'end' must points to a good entry */
24static union perf_event *perf_mmap__read(struct perf_mmap *map, bool check_messup,
25 u64 start, u64 end, u64 *prev)
26{
27 unsigned char *data = map->base + page_size;
28 union perf_event *event = NULL;
29 int diff = end - start;
30
31 if (check_messup) {
32 /*
33 * If we're further behind than half the buffer, there's a chance
34 * the writer will bite our tail and mess up the samples under us.
35 *
36 * If we somehow ended up ahead of the 'end', we got messed up.
37 *
38 * In either case, truncate and restart at 'end'.
39 */
40 if (diff > map->mask / 2 || diff < 0) {
41 fprintf(stderr, "WARNING: failed to keep up with mmap data.\n");
42
43 /*
44 * 'end' points to a known good entry, start there.
45 */
46 start = end;
47 diff = 0;
48 }
49 }
50
51 if (diff >= (int)sizeof(event->header)) {
52 size_t size;
53
54 event = (union perf_event *)&data[start & map->mask];
55 size = event->header.size;
56
57 if (size < sizeof(event->header) || diff < (int)size) {
58 event = NULL;
59 goto broken_event;
60 }
61
62 /*
63 * Event straddles the mmap boundary -- header should always
64 * be inside due to u64 alignment of output.
65 */
66 if ((start & map->mask) + size != ((start + size) & map->mask)) {
67 unsigned int offset = start;
68 unsigned int len = min(sizeof(*event), size), cpy;
69 void *dst = map->event_copy;
70
71 do {
72 cpy = min(map->mask + 1 - (offset & map->mask), len);
73 memcpy(dst, &data[offset & map->mask], cpy);
74 offset += cpy;
75 dst += cpy;
76 len -= cpy;
77 } while (len);
78
79 event = (union perf_event *)map->event_copy;
80 }
81
82 start += size;
83 }
84
85broken_event:
86 if (prev)
87 *prev = start;
88
89 return event;
90}
91
92union perf_event *perf_mmap__read_forward(struct perf_mmap *map, bool check_messup)
93{
94 u64 head;
95 u64 old = map->prev;
96
97 /*
98 * Check if event was unmapped due to a POLLHUP/POLLERR.
99 */
100 if (!refcount_read(&map->refcnt))
101 return NULL;
102
103 head = perf_mmap__read_head(map);
104
105 return perf_mmap__read(map, check_messup, old, head, &map->prev);
106}
107
108union perf_event *perf_mmap__read_backward(struct perf_mmap *map)
109{
110 u64 head, end;
111 u64 start = map->prev;
112
113 /*
114 * Check if event was unmapped due to a POLLHUP/POLLERR.
115 */
116 if (!refcount_read(&map->refcnt))
117 return NULL;
118
119 head = perf_mmap__read_head(map);
120 if (!head)
121 return NULL;
122
123 /*
124 * 'head' pointer starts from 0. Kernel minus sizeof(record) form
125 * it each time when kernel writes to it, so in fact 'head' is
126 * negative. 'end' pointer is made manually by adding the size of
127 * the ring buffer to 'head' pointer, means the validate data can
128 * read is the whole ring buffer. If 'end' is positive, the ring
129 * buffer has not fully filled, so we must adjust 'end' to 0.
130 *
131 * However, since both 'head' and 'end' is unsigned, we can't
132 * simply compare 'end' against 0. Here we compare '-head' and
133 * the size of the ring buffer, where -head is the number of bytes
134 * kernel write to the ring buffer.
135 */
136 if (-head < (u64)(map->mask + 1))
137 end = 0;
138 else
139 end = head + map->mask + 1;
140
141 return perf_mmap__read(map, false, start, end, &map->prev);
142}
143
144void perf_mmap__read_catchup(struct perf_mmap *map)
145{
146 u64 head;
147
148 if (!refcount_read(&map->refcnt))
149 return;
150
151 head = perf_mmap__read_head(map);
152 map->prev = head;
153}
154
155static bool perf_mmap__empty(struct perf_mmap *map)
156{
157 return perf_mmap__read_head(map) == map->prev && !map->auxtrace_mmap.base;
158}
159
160void perf_mmap__get(struct perf_mmap *map)
161{
162 refcount_inc(&map->refcnt);
163}
164
165void perf_mmap__put(struct perf_mmap *map)
166{
167 BUG_ON(map->base && refcount_read(&map->refcnt) == 0);
168
169 if (refcount_dec_and_test(&map->refcnt))
170 perf_mmap__munmap(map);
171}
172
173void perf_mmap__consume(struct perf_mmap *map, bool overwrite)
174{
175 if (!overwrite) {
176 u64 old = map->prev;
177
178 perf_mmap__write_tail(map, old);
179 }
180
181 if (refcount_read(&map->refcnt) == 1 && perf_mmap__empty(map))
182 perf_mmap__put(map);
183}
184
185int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
186 struct auxtrace_mmap_params *mp __maybe_unused,
187 void *userpg __maybe_unused,
188 int fd __maybe_unused)
189{
190 return 0;
191}
192
193void __weak auxtrace_mmap__munmap(struct auxtrace_mmap *mm __maybe_unused)
194{
195}
196
197void __weak auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp __maybe_unused,
198 off_t auxtrace_offset __maybe_unused,
199 unsigned int auxtrace_pages __maybe_unused,
200 bool auxtrace_overwrite __maybe_unused)
201{
202}
203
204void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __maybe_unused,
205 struct perf_evlist *evlist __maybe_unused,
206 int idx __maybe_unused,
207 bool per_cpu __maybe_unused)
208{
209}
210
211void perf_mmap__munmap(struct perf_mmap *map)
212{
213 if (map->base != NULL) {
214 munmap(map->base, perf_mmap__mmap_len(map));
215 map->base = NULL;
216 map->fd = -1;
217 refcount_set(&map->refcnt, 0);
218 }
219 auxtrace_mmap__munmap(&map->auxtrace_mmap);
220}
221
222int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
223{
224 /*
225 * The last one will be done at perf_evlist__mmap_consume(), so that we
226 * make sure we don't prevent tools from consuming every last event in
227 * the ring buffer.
228 *
229 * I.e. we can get the POLLHUP meaning that the fd doesn't exist
230 * anymore, but the last events for it are still in the ring buffer,
231 * waiting to be consumed.
232 *
233 * Tools can chose to ignore this at their own discretion, but the
234 * evlist layer can't just drop it when filtering events in
235 * perf_evlist__filter_pollfd().
236 */
237 refcount_set(&map->refcnt, 2);
238 map->prev = 0;
239 map->mask = mp->mask;
240 map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
241 MAP_SHARED, fd, 0);
242 if (map->base == MAP_FAILED) {
243 pr_debug2("failed to mmap perf event ring buffer, error %d\n",
244 errno);
245 map->base = NULL;
246 return -1;
247 }
248 map->fd = fd;
249
250 if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
251 &mp->auxtrace_mp, map->base, fd))
252 return -1;
253
254 return 0;
255}
256
257static int backward_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
258{
259 struct perf_event_header *pheader;
260 u64 evt_head = head;
261 int size = mask + 1;
262
263 pr_debug2("backward_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
264 pheader = (struct perf_event_header *)(buf + (head & mask));
265 *start = head;
266 while (true) {
267 if (evt_head - head >= (unsigned int)size) {
268 pr_debug("Finished reading backward ring buffer: rewind\n");
269 if (evt_head - head > (unsigned int)size)
270 evt_head -= pheader->size;
271 *end = evt_head;
272 return 0;
273 }
274
275 pheader = (struct perf_event_header *)(buf + (evt_head & mask));
276
277 if (pheader->size == 0) {
278 pr_debug("Finished reading backward ring buffer: get start\n");
279 *end = evt_head;
280 return 0;
281 }
282
283 evt_head += pheader->size;
284 pr_debug3("move evt_head: %"PRIx64"\n", evt_head);
285 }
286 WARN_ONCE(1, "Shouldn't get here\n");
287 return -1;
288}
289
290static int rb_find_range(void *data, int mask, u64 head, u64 old,
291 u64 *start, u64 *end, bool backward)
292{
293 if (!backward) {
294 *start = old;
295 *end = head;
296 return 0;
297 }
298
299 return backward_rb_find_range(data, mask, head, start, end);
300}
301
302int perf_mmap__push(struct perf_mmap *md, bool overwrite, bool backward,
303 void *to, int push(void *to, void *buf, size_t size))
304{
305 u64 head = perf_mmap__read_head(md);
306 u64 old = md->prev;
307 u64 end = head, start = old;
308 unsigned char *data = md->base + page_size;
309 unsigned long size;
310 void *buf;
311 int rc = 0;
312
313 if (rb_find_range(data, md->mask, head, old, &start, &end, backward))
314 return -1;
315
316 if (start == end)
317 return 0;
318
319 size = end - start;
320 if (size > (unsigned long)(md->mask) + 1) {
321 WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
322
323 md->prev = head;
324 perf_mmap__consume(md, overwrite || backward);
325 return 0;
326 }
327
328 if ((start & md->mask) + size != (end & md->mask)) {
329 buf = &data[start & md->mask];
330 size = md->mask + 1 - (start & md->mask);
331 start += size;
332
333 if (push(to, buf, size) < 0) {
334 rc = -1;
335 goto out;
336 }
337 }
338
339 buf = &data[start & md->mask];
340 size = end - start;
341 start += size;
342
343 if (push(to, buf, size) < 0) {
344 rc = -1;
345 goto out;
346 }
347
348 md->prev = head;
349 perf_mmap__consume(md, overwrite || backward);
350out:
351 return rc;
352}
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
new file mode 100644
index 000000000000..efd78b827b05
--- /dev/null
+++ b/tools/perf/util/mmap.h
@@ -0,0 +1,97 @@
1#ifndef __PERF_MMAP_H
2#define __PERF_MMAP_H 1
3
4#include <linux/compiler.h>
5#include <linux/refcount.h>
6#include <linux/types.h>
7#include <asm/barrier.h>
8#include <stdbool.h>
9#include "auxtrace.h"
10#include "event.h"
11
12/**
13 * struct perf_mmap - perf's ring buffer mmap details
14 *
15 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
16 */
17struct perf_mmap {
18 void *base;
19 int mask;
20 int fd;
21 refcount_t refcnt;
22 u64 prev;
23 struct auxtrace_mmap auxtrace_mmap;
24 char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
25};
26
27/*
28 * State machine of bkw_mmap_state:
29 *
30 * .________________(forbid)_____________.
31 * | V
32 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
33 * ^ ^ | ^ |
34 * | |__(forbid)____/ |___(forbid)___/|
35 * | |
36 * \_________________(3)_______________/
37 *
38 * NOTREADY : Backward ring buffers are not ready
39 * RUNNING : Backward ring buffers are recording
40 * DATA_PENDING : We are required to collect data from backward ring buffers
41 * EMPTY : We have collected data from backward ring buffers.
42 *
43 * (0): Setup backward ring buffer
44 * (1): Pause ring buffers for reading
45 * (2): Read from ring buffers
46 * (3): Resume ring buffers for recording
47 */
48enum bkw_mmap_state {
49 BKW_MMAP_NOTREADY,
50 BKW_MMAP_RUNNING,
51 BKW_MMAP_DATA_PENDING,
52 BKW_MMAP_EMPTY,
53};
54
55struct mmap_params {
56 int prot, mask;
57 struct auxtrace_mmap_params auxtrace_mp;
58};
59
60int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd);
61void perf_mmap__munmap(struct perf_mmap *map);
62
63void perf_mmap__get(struct perf_mmap *map);
64void perf_mmap__put(struct perf_mmap *map);
65
66void perf_mmap__consume(struct perf_mmap *map, bool overwrite);
67
68void perf_mmap__read_catchup(struct perf_mmap *md);
69
70static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
71{
72 struct perf_event_mmap_page *pc = mm->base;
73 u64 head = ACCESS_ONCE(pc->data_head);
74 rmb();
75 return head;
76}
77
78static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
79{
80 struct perf_event_mmap_page *pc = md->base;
81
82 /*
83 * ensure all reads are done before we write the tail out.
84 */
85 mb();
86 pc->data_tail = tail;
87}
88
89union perf_event *perf_mmap__read_forward(struct perf_mmap *map, bool check_messup);
90union perf_event *perf_mmap__read_backward(struct perf_mmap *map);
91
92int perf_mmap__push(struct perf_mmap *md, bool overwrite, bool backward,
93 void *to, int push(void *to, void *buf, size_t size));
94
95size_t perf_mmap__mmap_len(struct perf_mmap *map);
96
97#endif /*__PERF_MMAP_H */
diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
index a58e91197729..5be021701f34 100644
--- a/tools/perf/util/namespaces.c
+++ b/tools/perf/util/namespaces.c
@@ -11,6 +11,7 @@
11#include "event.h" 11#include "event.h"
12#include <sys/types.h> 12#include <sys/types.h>
13#include <sys/stat.h> 13#include <sys/stat.h>
14#include <fcntl.h>
14#include <limits.h> 15#include <limits.h>
15#include <sched.h> 16#include <sched.h>
16#include <stdlib.h> 17#include <stdlib.h>
diff --git a/tools/perf/util/namespaces.h b/tools/perf/util/namespaces.h
index 05d82601c9a6..760558dcfd18 100644
--- a/tools/perf/util/namespaces.h
+++ b/tools/perf/util/namespaces.h
@@ -9,9 +9,10 @@
9#ifndef __PERF_NAMESPACES_H 9#ifndef __PERF_NAMESPACES_H
10#define __PERF_NAMESPACES_H 10#define __PERF_NAMESPACES_H
11 11
12#include "../perf.h" 12#include <sys/types.h>
13#include <linux/list.h> 13#include <linux/perf_event.h>
14#include <linux/refcount.h> 14#include <linux/refcount.h>
15#include <linux/types.h>
15 16
16struct namespaces_event; 17struct namespaces_event;
17 18
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index 4de398cfb577..8e09fd2d842f 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <linux/list.h> 4#include <linux/list.h>
diff --git a/tools/perf/util/ordered-events.h b/tools/perf/util/ordered-events.h
index e11468a9a6e4..96e5292d88e2 100644
--- a/tools/perf/util/ordered-events.h
+++ b/tools/perf/util/ordered-events.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __ORDERED_EVENTS_H 2#ifndef __ORDERED_EVENTS_H
2#define __ORDERED_EVENTS_H 3#define __ORDERED_EVENTS_H
3 4
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c
index e71fb5f31e84..bd779d9f4d1e 100644
--- a/tools/perf/util/parse-branch-options.c
+++ b/tools/perf/util/parse-branch-options.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "perf.h" 2#include "perf.h"
2#include "util/util.h" 3#include "util/util.h"
3#include "util/debug.h" 4#include "util/debug.h"
diff --git a/tools/perf/util/parse-branch-options.h b/tools/perf/util/parse-branch-options.h
index 6086fd90eb23..11d1722733f2 100644
--- a/tools/perf/util/parse-branch-options.h
+++ b/tools/perf/util/parse-branch-options.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_PARSE_BRANCH_OPTIONS_H 2#ifndef _PERF_PARSE_BRANCH_OPTIONS_H
2#define _PERF_PARSE_BRANCH_OPTIONS_H 1 3#define _PERF_PARSE_BRANCH_OPTIONS_H 1
3#include <stdint.h> 4#include <stdint.h>
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index f6257fb4f08c..a7fcd95961ef 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/hw_breakpoint.h> 2#include <linux/hw_breakpoint.h>
2#include <linux/err.h> 3#include <linux/err.h>
3#include <dirent.h> 4#include <dirent.h>
@@ -28,6 +29,7 @@
28#include "probe-file.h" 29#include "probe-file.h"
29#include "asm/bug.h" 30#include "asm/bug.h"
30#include "util/parse-branch-options.h" 31#include "util/parse-branch-options.h"
32#include "metricgroup.h"
31 33
32#define MAX_NAME_LEN 100 34#define MAX_NAME_LEN 100
33 35
@@ -309,10 +311,11 @@ static char *get_config_name(struct list_head *head_terms)
309static struct perf_evsel * 311static struct perf_evsel *
310__add_event(struct list_head *list, int *idx, 312__add_event(struct list_head *list, int *idx,
311 struct perf_event_attr *attr, 313 struct perf_event_attr *attr,
312 char *name, struct cpu_map *cpus, 314 char *name, struct perf_pmu *pmu,
313 struct list_head *config_terms, bool auto_merge_stats) 315 struct list_head *config_terms, bool auto_merge_stats)
314{ 316{
315 struct perf_evsel *evsel; 317 struct perf_evsel *evsel;
318 struct cpu_map *cpus = pmu ? pmu->cpus : NULL;
316 319
317 event_attr_init(attr); 320 event_attr_init(attr);
318 321
@@ -323,7 +326,7 @@ __add_event(struct list_head *list, int *idx,
323 (*idx)++; 326 (*idx)++;
324 evsel->cpus = cpu_map__get(cpus); 327 evsel->cpus = cpu_map__get(cpus);
325 evsel->own_cpus = cpu_map__get(cpus); 328 evsel->own_cpus = cpu_map__get(cpus);
326 evsel->system_wide = !!cpus; 329 evsel->system_wide = pmu ? pmu->is_uncore : false;
327 evsel->auto_merge_stats = auto_merge_stats; 330 evsel->auto_merge_stats = auto_merge_stats;
328 331
329 if (name) 332 if (name)
@@ -1218,11 +1221,17 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state,
1218 struct perf_pmu_info info; 1221 struct perf_pmu_info info;
1219 struct perf_pmu *pmu; 1222 struct perf_pmu *pmu;
1220 struct perf_evsel *evsel; 1223 struct perf_evsel *evsel;
1224 struct parse_events_error *err = parse_state->error;
1221 LIST_HEAD(config_terms); 1225 LIST_HEAD(config_terms);
1222 1226
1223 pmu = perf_pmu__find(name); 1227 pmu = perf_pmu__find(name);
1224 if (!pmu) 1228 if (!pmu) {
1229 if (asprintf(&err->str,
1230 "Cannot find PMU `%s'. Missing kernel support?",
1231 name) < 0)
1232 err->str = NULL;
1225 return -EINVAL; 1233 return -EINVAL;
1234 }
1226 1235
1227 if (pmu->default_config) { 1236 if (pmu->default_config) {
1228 memcpy(&attr, pmu->default_config, 1237 memcpy(&attr, pmu->default_config,
@@ -1233,7 +1242,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state,
1233 1242
1234 if (!head_config) { 1243 if (!head_config) {
1235 attr.type = pmu->type; 1244 attr.type = pmu->type;
1236 evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu->cpus, NULL, auto_merge_stats); 1245 evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats);
1237 return evsel ? 0 : -ENOMEM; 1246 return evsel ? 0 : -ENOMEM;
1238 } 1247 }
1239 1248
@@ -1254,7 +1263,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state,
1254 return -EINVAL; 1263 return -EINVAL;
1255 1264
1256 evsel = __add_event(list, &parse_state->idx, &attr, 1265 evsel = __add_event(list, &parse_state->idx, &attr,
1257 get_config_name(head_config), pmu->cpus, 1266 get_config_name(head_config), pmu,
1258 &config_terms, auto_merge_stats); 1267 &config_terms, auto_merge_stats);
1259 if (evsel) { 1268 if (evsel) {
1260 evsel->unit = info.unit; 1269 evsel->unit = info.unit;
@@ -1366,6 +1375,7 @@ struct event_modifier {
1366 int exclude_GH; 1375 int exclude_GH;
1367 int sample_read; 1376 int sample_read;
1368 int pinned; 1377 int pinned;
1378 int weak;
1369}; 1379};
1370 1380
1371static int get_event_modifier(struct event_modifier *mod, char *str, 1381static int get_event_modifier(struct event_modifier *mod, char *str,
@@ -1384,6 +1394,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
1384 1394
1385 int exclude = eu | ek | eh; 1395 int exclude = eu | ek | eh;
1386 int exclude_GH = evsel ? evsel->exclude_GH : 0; 1396 int exclude_GH = evsel ? evsel->exclude_GH : 0;
1397 int weak = 0;
1387 1398
1388 memset(mod, 0, sizeof(*mod)); 1399 memset(mod, 0, sizeof(*mod));
1389 1400
@@ -1421,6 +1432,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
1421 sample_read = 1; 1432 sample_read = 1;
1422 } else if (*str == 'D') { 1433 } else if (*str == 'D') {
1423 pinned = 1; 1434 pinned = 1;
1435 } else if (*str == 'W') {
1436 weak = 1;
1424 } else 1437 } else
1425 break; 1438 break;
1426 1439
@@ -1451,6 +1464,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
1451 mod->exclude_GH = exclude_GH; 1464 mod->exclude_GH = exclude_GH;
1452 mod->sample_read = sample_read; 1465 mod->sample_read = sample_read;
1453 mod->pinned = pinned; 1466 mod->pinned = pinned;
1467 mod->weak = weak;
1454 1468
1455 return 0; 1469 return 0;
1456} 1470}
@@ -1464,7 +1478,7 @@ static int check_modifier(char *str)
1464 char *p = str; 1478 char *p = str;
1465 1479
1466 /* The sizeof includes 0 byte as well. */ 1480 /* The sizeof includes 0 byte as well. */
1467 if (strlen(str) > (sizeof("ukhGHpppPSDI") - 1)) 1481 if (strlen(str) > (sizeof("ukhGHpppPSDIW") - 1))
1468 return -1; 1482 return -1;
1469 1483
1470 while (*p) { 1484 while (*p) {
@@ -1504,6 +1518,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
1504 evsel->exclude_GH = mod.exclude_GH; 1518 evsel->exclude_GH = mod.exclude_GH;
1505 evsel->sample_read = mod.sample_read; 1519 evsel->sample_read = mod.sample_read;
1506 evsel->precise_max = mod.precise_max; 1520 evsel->precise_max = mod.precise_max;
1521 evsel->weak_group = mod.weak;
1507 1522
1508 if (perf_evsel__is_group_leader(evsel)) 1523 if (perf_evsel__is_group_leader(evsel))
1509 evsel->attr.pinned = mod.pinned; 1524 evsel->attr.pinned = mod.pinned;
@@ -1726,8 +1741,8 @@ static int get_term_width(void)
1726 return ws.ws_col > MAX_WIDTH ? MAX_WIDTH : ws.ws_col; 1741 return ws.ws_col > MAX_WIDTH ? MAX_WIDTH : ws.ws_col;
1727} 1742}
1728 1743
1729static void parse_events_print_error(struct parse_events_error *err, 1744void parse_events_print_error(struct parse_events_error *err,
1730 const char *event) 1745 const char *event)
1731{ 1746{
1732 const char *str = "invalid or unsupported event: "; 1747 const char *str = "invalid or unsupported event: ";
1733 char _buf[MAX_WIDTH]; 1748 char _buf[MAX_WIDTH];
@@ -1782,8 +1797,6 @@ static void parse_events_print_error(struct parse_events_error *err,
1782 zfree(&err->str); 1797 zfree(&err->str);
1783 zfree(&err->help); 1798 zfree(&err->help);
1784 } 1799 }
1785
1786 fprintf(stderr, "Run 'perf list' for a list of valid events\n");
1787} 1800}
1788 1801
1789#undef MAX_WIDTH 1802#undef MAX_WIDTH
@@ -1795,8 +1808,10 @@ int parse_events_option(const struct option *opt, const char *str,
1795 struct parse_events_error err = { .idx = 0, }; 1808 struct parse_events_error err = { .idx = 0, };
1796 int ret = parse_events(evlist, str, &err); 1809 int ret = parse_events(evlist, str, &err);
1797 1810
1798 if (ret) 1811 if (ret) {
1799 parse_events_print_error(&err, str); 1812 parse_events_print_error(&err, str);
1813 fprintf(stderr, "Run 'perf list' for a list of valid events\n");
1814 }
1800 1815
1801 return ret; 1816 return ret;
1802} 1817}
@@ -2374,6 +2389,8 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag,
2374 print_tracepoint_events(NULL, NULL, name_only); 2389 print_tracepoint_events(NULL, NULL, name_only);
2375 2390
2376 print_sdt_events(NULL, NULL, name_only); 2391 print_sdt_events(NULL, NULL, name_only);
2392
2393 metricgroup__print(true, true, NULL, name_only);
2377} 2394}
2378 2395
2379int parse_events__is_hardcoded_term(struct parse_events_term *term) 2396int parse_events__is_hardcoded_term(struct parse_events_term *term)
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 635135125111..be337c266697 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_PARSE_EVENTS_H 2#ifndef __PERF_PARSE_EVENTS_H
2#define __PERF_PARSE_EVENTS_H 3#define __PERF_PARSE_EVENTS_H
3/* 4/*
@@ -202,6 +203,9 @@ int is_valid_tracepoint(const char *event_string);
202int valid_event_mount(const char *eventfs); 203int valid_event_mount(const char *eventfs);
203char *parse_events_formats_error_string(char *additional_terms); 204char *parse_events_formats_error_string(char *additional_terms);
204 205
206void parse_events_print_error(struct parse_events_error *err,
207 const char *event);
208
205#ifdef HAVE_LIBELF_SUPPORT 209#ifdef HAVE_LIBELF_SUPPORT
206/* 210/*
207 * If the probe point starts with '%', 211 * If the probe point starts with '%',
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index c42edeac451f..655ecff636a8 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -5,9 +5,13 @@
5%option stack 5%option stack
6%option bison-locations 6%option bison-locations
7%option yylineno 7%option yylineno
8%option reject
8 9
9%{ 10%{
10#include <errno.h> 11#include <errno.h>
12#include <sys/types.h>
13#include <sys/stat.h>
14#include <unistd.h>
11#include "../perf.h" 15#include "../perf.h"
12#include "parse-events.h" 16#include "parse-events.h"
13#include "parse-events-bison.h" 17#include "parse-events-bison.h"
@@ -53,9 +57,8 @@ static int str(yyscan_t scanner, int token)
53 return token; 57 return token;
54} 58}
55 59
56static bool isbpf(yyscan_t scanner) 60static bool isbpf_suffix(char *text)
57{ 61{
58 char *text = parse_events_get_text(scanner);
59 int len = strlen(text); 62 int len = strlen(text);
60 63
61 if (len < 2) 64 if (len < 2)
@@ -68,6 +71,17 @@ static bool isbpf(yyscan_t scanner)
68 return false; 71 return false;
69} 72}
70 73
74static bool isbpf(yyscan_t scanner)
75{
76 char *text = parse_events_get_text(scanner);
77 struct stat st;
78
79 if (!isbpf_suffix(text))
80 return false;
81
82 return stat(text, &st) == 0;
83}
84
71/* 85/*
72 * This function is called when the parser gets two kind of input: 86 * This function is called when the parser gets two kind of input:
73 * 87 *
@@ -141,6 +155,10 @@ do { \
141 yycolumn += yyleng; \ 155 yycolumn += yyleng; \
142} while (0); 156} while (0);
143 157
158#define USER_REJECT \
159 yycolumn -= yyleng; \
160 REJECT
161
144%} 162%}
145 163
146%x mem 164%x mem
@@ -161,7 +179,7 @@ name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
161name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]* 179name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]*
162drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)? 180drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
163/* If you add a modifier you need to update check_modifier() */ 181/* If you add a modifier you need to update check_modifier() */
164modifier_event [ukhpPGHSDI]+ 182modifier_event [ukhpPGHSDIW]+
165modifier_bp [rwx]{1,3} 183modifier_bp [rwx]{1,3}
166 184
167%% 185%%
@@ -288,6 +306,7 @@ cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COU
288alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } 306alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
289emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } 307emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
290dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } 308dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
309duration_time { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
291bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); } 310bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); }
292 311
293 /* 312 /*
@@ -322,8 +341,8 @@ r{num_raw_hex} { return raw(yyscanner); }
322{num_hex} { return value(yyscanner, 16); } 341{num_hex} { return value(yyscanner, 16); }
323 342
324{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } 343{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
325{bpf_object} { if (!isbpf(yyscanner)) REJECT; return str(yyscanner, PE_BPF_OBJECT); } 344{bpf_object} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_OBJECT); }
326{bpf_source} { if (!isbpf(yyscanner)) REJECT; return str(yyscanner, PE_BPF_SOURCE); } 345{bpf_source} { if (!isbpf(yyscanner)) { USER_REJECT }; return str(yyscanner, PE_BPF_SOURCE); }
327{name} { return pmu_str_check(yyscanner); } 346{name} { return pmu_str_check(yyscanner); }
328"/" { BEGIN(config); return '/'; } 347"/" { BEGIN(config); return '/'; }
329- { return '-'; } 348- { return '-'; }
diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
index 646ecf736aad..e6599e290f46 100644
--- a/tools/perf/util/parse-regs-options.c
+++ b/tools/perf/util/parse-regs-options.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "perf.h" 2#include "perf.h"
2#include "util/util.h" 3#include "util/util.h"
3#include "util/debug.h" 4#include "util/debug.h"
diff --git a/tools/perf/util/parse-regs-options.h b/tools/perf/util/parse-regs-options.h
index 7d762b188007..cdefb1acf6be 100644
--- a/tools/perf/util/parse-regs-options.h
+++ b/tools/perf/util/parse-regs-options.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_PARSE_REGS_OPTIONS_H 2#ifndef _PERF_PARSE_REGS_OPTIONS_H
2#define _PERF_PARSE_REGS_OPTIONS_H 1 3#define _PERF_PARSE_REGS_OPTIONS_H 1
3struct option; 4struct option;
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 50ec3bc87a60..933f5c6bffb4 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * I'm tired of doing "vsnprintf()" etc just to open a 3 * I'm tired of doing "vsnprintf()" etc just to open a
3 * file, so here's a "return static buffer with printf" 4 * file, so here's a "return static buffer with printf"
diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h
index 9a276a58e3c2..14a254ada7eb 100644
--- a/tools/perf/util/path.h
+++ b/tools/perf/util/path.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_PATH_H 2#ifndef _PERF_PATH_H
2#define _PERF_PATH_H 3#define _PERF_PATH_H
3 4
diff --git a/tools/perf/util/perf-hooks.c b/tools/perf/util/perf-hooks.c
index d55092964da2..4f3aa8d99ef4 100644
--- a/tools/perf/util/perf-hooks.c
+++ b/tools/perf/util/perf-hooks.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * perf_hooks.c 3 * perf_hooks.c
3 * 4 *
diff --git a/tools/perf/util/perf-hooks.h b/tools/perf/util/perf-hooks.h
index 838d5797bc1e..27fbec62d4fe 100644
--- a/tools/perf/util/perf-hooks.h
+++ b/tools/perf/util/perf-hooks.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_UTIL_PERF_HOOKS_H 2#ifndef PERF_UTIL_PERF_HOOKS_H
2#define PERF_UTIL_PERF_HOOKS_H 3#define PERF_UTIL_PERF_HOOKS_H
3 4
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index b2ae039eff85..2acfcc527cac 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include "perf_regs.h" 3#include "perf_regs.h"
3#include "event.h" 4#include "event.h"
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index 32b37d19dcc3..c9319f8d17a6 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_REGS_H 2#ifndef __PERF_REGS_H
2#define __PERF_REGS_H 3#define __PERF_REGS_H
3 4
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index ac16a9db1fb5..07cb2ac041d7 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1,7 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/list.h> 2#include <linux/list.h>
2#include <linux/compiler.h> 3#include <linux/compiler.h>
3#include <sys/types.h> 4#include <sys/types.h>
4#include <errno.h> 5#include <errno.h>
6#include <fcntl.h>
5#include <sys/stat.h> 7#include <sys/stat.h>
6#include <unistd.h> 8#include <unistd.h>
7#include <stdio.h> 9#include <stdio.h>
@@ -470,17 +472,36 @@ static void pmu_read_sysfs(void)
470 closedir(dir); 472 closedir(dir);
471} 473}
472 474
475static struct cpu_map *__pmu_cpumask(const char *path)
476{
477 FILE *file;
478 struct cpu_map *cpus;
479
480 file = fopen(path, "r");
481 if (!file)
482 return NULL;
483
484 cpus = cpu_map__read(file);
485 fclose(file);
486 return cpus;
487}
488
489/*
490 * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64)
491 * may have a "cpus" file.
492 */
493#define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask"
494#define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus"
495
473static struct cpu_map *pmu_cpumask(const char *name) 496static struct cpu_map *pmu_cpumask(const char *name)
474{ 497{
475 struct stat st;
476 char path[PATH_MAX]; 498 char path[PATH_MAX];
477 FILE *file;
478 struct cpu_map *cpus; 499 struct cpu_map *cpus;
479 const char *sysfs = sysfs__mountpoint(); 500 const char *sysfs = sysfs__mountpoint();
480 const char *templates[] = { 501 const char *templates[] = {
481 "%s/bus/event_source/devices/%s/cpumask", 502 CPUS_TEMPLATE_UNCORE,
482 "%s/bus/event_source/devices/%s/cpus", 503 CPUS_TEMPLATE_CPU,
483 NULL 504 NULL
484 }; 505 };
485 const char **template; 506 const char **template;
486 507
@@ -489,20 +510,25 @@ static struct cpu_map *pmu_cpumask(const char *name)
489 510
490 for (template = templates; *template; template++) { 511 for (template = templates; *template; template++) {
491 snprintf(path, PATH_MAX, *template, sysfs, name); 512 snprintf(path, PATH_MAX, *template, sysfs, name);
492 if (stat(path, &st) == 0) 513 cpus = __pmu_cpumask(path);
493 break; 514 if (cpus)
515 return cpus;
494 } 516 }
495 517
496 if (!*template) 518 return NULL;
497 return NULL; 519}
498 520
499 file = fopen(path, "r"); 521static bool pmu_is_uncore(const char *name)
500 if (!file) 522{
501 return NULL; 523 char path[PATH_MAX];
524 struct cpu_map *cpus;
525 const char *sysfs = sysfs__mountpoint();
502 526
503 cpus = cpu_map__read(file); 527 snprintf(path, PATH_MAX, CPUS_TEMPLATE_UNCORE, sysfs, name);
504 fclose(file); 528 cpus = __pmu_cpumask(path);
505 return cpus; 529 cpu_map__put(cpus);
530
531 return !!cpus;
506} 532}
507 533
508/* 534/*
@@ -516,16 +542,8 @@ char * __weak get_cpuid_str(void)
516 return NULL; 542 return NULL;
517} 543}
518 544
519/* 545static char *perf_pmu__getcpuid(void)
520 * From the pmu_events_map, find the table of PMU events that corresponds
521 * to the current running CPU. Then, add all PMU events from that table
522 * as aliases.
523 */
524static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
525{ 546{
526 int i;
527 struct pmu_events_map *map;
528 struct pmu_event *pe;
529 char *cpuid; 547 char *cpuid;
530 static bool printed; 548 static bool printed;
531 549
@@ -535,22 +553,50 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
535 if (!cpuid) 553 if (!cpuid)
536 cpuid = get_cpuid_str(); 554 cpuid = get_cpuid_str();
537 if (!cpuid) 555 if (!cpuid)
538 return; 556 return NULL;
539 557
540 if (!printed) { 558 if (!printed) {
541 pr_debug("Using CPUID %s\n", cpuid); 559 pr_debug("Using CPUID %s\n", cpuid);
542 printed = true; 560 printed = true;
543 } 561 }
562 return cpuid;
563}
564
565struct pmu_events_map *perf_pmu__find_map(void)
566{
567 struct pmu_events_map *map;
568 char *cpuid = perf_pmu__getcpuid();
569 int i;
544 570
545 i = 0; 571 i = 0;
546 while (1) { 572 for (;;) {
547 map = &pmu_events_map[i++]; 573 map = &pmu_events_map[i++];
548 if (!map->table) 574 if (!map->table) {
549 goto out; 575 map = NULL;
576 break;
577 }
550 578
551 if (!strcmp(map->cpuid, cpuid)) 579 if (!strcmp(map->cpuid, cpuid))
552 break; 580 break;
553 } 581 }
582 free(cpuid);
583 return map;
584}
585
586/*
587 * From the pmu_events_map, find the table of PMU events that corresponds
588 * to the current running CPU. Then, add all PMU events from that table
589 * as aliases.
590 */
591static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
592{
593 int i;
594 struct pmu_events_map *map;
595 struct pmu_event *pe;
596
597 map = perf_pmu__find_map();
598 if (!map)
599 return;
554 600
555 /* 601 /*
556 * Found a matching PMU events table. Create aliases 602 * Found a matching PMU events table. Create aliases
@@ -560,8 +606,11 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
560 const char *pname; 606 const char *pname;
561 607
562 pe = &map->table[i++]; 608 pe = &map->table[i++];
563 if (!pe->name) 609 if (!pe->name) {
610 if (pe->metric_group || pe->metric_name)
611 continue;
564 break; 612 break;
613 }
565 614
566 pname = pe->pmu ? pe->pmu : "cpu"; 615 pname = pe->pmu ? pe->pmu : "cpu";
567 if (strncmp(pname, name, strlen(pname))) 616 if (strncmp(pname, name, strlen(pname)))
@@ -575,9 +624,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
575 (char *)pe->metric_expr, 624 (char *)pe->metric_expr,
576 (char *)pe->metric_name); 625 (char *)pe->metric_name);
577 } 626 }
578
579out:
580 free(cpuid);
581} 627}
582 628
583struct perf_event_attr * __weak 629struct perf_event_attr * __weak
@@ -617,6 +663,8 @@ static struct perf_pmu *pmu_lookup(const char *name)
617 663
618 pmu->cpus = pmu_cpumask(name); 664 pmu->cpus = pmu_cpumask(name);
619 665
666 pmu->is_uncore = pmu_is_uncore(name);
667
620 INIT_LIST_HEAD(&pmu->format); 668 INIT_LIST_HEAD(&pmu->format);
621 INIT_LIST_HEAD(&pmu->aliases); 669 INIT_LIST_HEAD(&pmu->aliases);
622 list_splice(&format, &pmu->format); 670 list_splice(&format, &pmu->format);
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 389e9729331f..27c75e635866 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PMU_H 2#ifndef __PMU_H
2#define __PMU_H 3#define __PMU_H
3 4
@@ -22,6 +23,7 @@ struct perf_pmu {
22 char *name; 23 char *name;
23 __u32 type; 24 __u32 type;
24 bool selectable; 25 bool selectable;
26 bool is_uncore;
25 struct perf_event_attr *default_config; 27 struct perf_event_attr *default_config;
26 struct cpu_map *cpus; 28 struct cpu_map *cpus;
27 struct list_head format; /* HEAD struct perf_pmu_format -> list */ 29 struct list_head format; /* HEAD struct perf_pmu_format -> list */
@@ -90,4 +92,6 @@ int perf_pmu__test(void);
90 92
91struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); 93struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
92 94
95struct pmu_events_map *perf_pmu__find_map(void);
96
93#endif /* __PMU_H */ 97#endif /* __PMU_H */
diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c
index e908177b9976..23e367063446 100644
--- a/tools/perf/util/print_binary.c
+++ b/tools/perf/util/print_binary.c
@@ -1,41 +1,44 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "print_binary.h" 2#include "print_binary.h"
2#include <linux/log2.h> 3#include <linux/log2.h>
3#include "sane_ctype.h" 4#include "sane_ctype.h"
4 5
5void print_binary(unsigned char *data, size_t len, 6int binary__fprintf(unsigned char *data, size_t len,
6 size_t bytes_per_line, print_binary_t printer, 7 size_t bytes_per_line, binary__fprintf_t printer,
7 void *extra) 8 void *extra, FILE *fp)
8{ 9{
9 size_t i, j, mask; 10 size_t i, j, mask;
11 int printed = 0;
10 12
11 if (!printer) 13 if (!printer)
12 return; 14 return 0;
13 15
14 bytes_per_line = roundup_pow_of_two(bytes_per_line); 16 bytes_per_line = roundup_pow_of_two(bytes_per_line);
15 mask = bytes_per_line - 1; 17 mask = bytes_per_line - 1;
16 18
17 printer(BINARY_PRINT_DATA_BEGIN, 0, extra); 19 printed += printer(BINARY_PRINT_DATA_BEGIN, 0, extra, fp);
18 for (i = 0; i < len; i++) { 20 for (i = 0; i < len; i++) {
19 if ((i & mask) == 0) { 21 if ((i & mask) == 0) {
20 printer(BINARY_PRINT_LINE_BEGIN, -1, extra); 22 printed += printer(BINARY_PRINT_LINE_BEGIN, -1, extra, fp);
21 printer(BINARY_PRINT_ADDR, i, extra); 23 printed += printer(BINARY_PRINT_ADDR, i, extra, fp);
22 } 24 }
23 25
24 printer(BINARY_PRINT_NUM_DATA, data[i], extra); 26 printed += printer(BINARY_PRINT_NUM_DATA, data[i], extra, fp);
25 27
26 if (((i & mask) == mask) || i == len - 1) { 28 if (((i & mask) == mask) || i == len - 1) {
27 for (j = 0; j < mask-(i & mask); j++) 29 for (j = 0; j < mask-(i & mask); j++)
28 printer(BINARY_PRINT_NUM_PAD, -1, extra); 30 printed += printer(BINARY_PRINT_NUM_PAD, -1, extra, fp);
29 31
30 printer(BINARY_PRINT_SEP, i, extra); 32 printer(BINARY_PRINT_SEP, i, extra, fp);
31 for (j = i & ~mask; j <= i; j++) 33 for (j = i & ~mask; j <= i; j++)
32 printer(BINARY_PRINT_CHAR_DATA, data[j], extra); 34 printed += printer(BINARY_PRINT_CHAR_DATA, data[j], extra, fp);
33 for (j = 0; j < mask-(i & mask); j++) 35 for (j = 0; j < mask-(i & mask); j++)
34 printer(BINARY_PRINT_CHAR_PAD, i, extra); 36 printed += printer(BINARY_PRINT_CHAR_PAD, i, extra, fp);
35 printer(BINARY_PRINT_LINE_END, -1, extra); 37 printed += printer(BINARY_PRINT_LINE_END, -1, extra, fp);
36 } 38 }
37 } 39 }
38 printer(BINARY_PRINT_DATA_END, -1, extra); 40 printed += printer(BINARY_PRINT_DATA_END, -1, extra, fp);
41 return printed;
39} 42}
40 43
41int is_printable_array(char *p, unsigned int len) 44int is_printable_array(char *p, unsigned int len)
diff --git a/tools/perf/util/print_binary.h b/tools/perf/util/print_binary.h
index da0427263d2d..2a1554afc957 100644
--- a/tools/perf/util/print_binary.h
+++ b/tools/perf/util/print_binary.h
@@ -1,7 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_PRINT_BINARY_H 2#ifndef PERF_PRINT_BINARY_H
2#define PERF_PRINT_BINARY_H 3#define PERF_PRINT_BINARY_H
3 4
4#include <stddef.h> 5#include <stddef.h>
6#include <stdio.h>
5 7
6enum binary_printer_ops { 8enum binary_printer_ops {
7 BINARY_PRINT_DATA_BEGIN, 9 BINARY_PRINT_DATA_BEGIN,
@@ -16,12 +18,19 @@ enum binary_printer_ops {
16 BINARY_PRINT_DATA_END, 18 BINARY_PRINT_DATA_END,
17}; 19};
18 20
19typedef void (*print_binary_t)(enum binary_printer_ops op, 21typedef int (*binary__fprintf_t)(enum binary_printer_ops op,
20 unsigned int val, void *extra); 22 unsigned int val, void *extra, FILE *fp);
21 23
22void print_binary(unsigned char *data, size_t len, 24int binary__fprintf(unsigned char *data, size_t len,
23 size_t bytes_per_line, print_binary_t printer, 25 size_t bytes_per_line, binary__fprintf_t printer,
24 void *extra); 26 void *extra, FILE *fp);
27
28static inline void print_binary(unsigned char *data, size_t len,
29 size_t bytes_per_line, binary__fprintf_t printer,
30 void *extra)
31{
32 binary__fprintf(data, len, bytes_per_line, printer, extra, stdout);
33}
25 34
26int is_printable_array(char *p, unsigned int len); 35int is_printable_array(char *p, unsigned int len);
27 36
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 078681d12168..45b14f020558 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PROBE_EVENT_H 2#ifndef _PROBE_EVENT_H
2#define _PROBE_EVENT_H 3#define _PROBE_EVENT_H
3 4
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index cdf8d83a484c..4ae1123c6794 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -15,6 +15,7 @@
15 * 15 *
16 */ 16 */
17#include <errno.h> 17#include <errno.h>
18#include <fcntl.h>
18#include <sys/stat.h> 19#include <sys/stat.h>
19#include <sys/types.h> 20#include <sys/types.h>
20#include <sys/uio.h> 21#include <sys/uio.h>
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index 2ca4163abafe..63f29b1d22c1 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PROBE_FILE_H 2#ifndef __PROBE_FILE_H
2#define __PROBE_FILE_H 3#define __PROBE_FILE_H
3 4
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 27f061551012..16252980ff00 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PROBE_FINDER_H 2#ifndef _PROBE_FINDER_H
2#define _PROBE_FINDER_H 3#define _PROBE_FINDER_H
3 4
diff --git a/tools/perf/util/pstack.c b/tools/perf/util/pstack.c
index b234a6e3d0d4..797fe1ae2d2e 100644
--- a/tools/perf/util/pstack.c
+++ b/tools/perf/util/pstack.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Simple pointer stack 3 * Simple pointer stack
3 * 4 *
diff --git a/tools/perf/util/pstack.h b/tools/perf/util/pstack.h
index ded7f2e36624..8729b8be061d 100644
--- a/tools/perf/util/pstack.h
+++ b/tools/perf/util/pstack.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_PSTACK_ 2#ifndef _PERF_PSTACK_
2#define _PERF_PSTACK_ 3#define _PERF_PSTACK_
3 4
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index e66dc495809a..b4f2f06722a7 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -10,6 +10,7 @@ util/ctype.c
10util/evlist.c 10util/evlist.c
11util/evsel.c 11util/evsel.c
12util/cpumap.c 12util/cpumap.c
13util/mmap.c
13util/namespaces.c 14util/namespaces.c
14../lib/bitmap.c 15../lib/bitmap.c
15../lib/find_bit.c 16../lib/find_bit.c
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index c129e99114ae..8e49d9cafcfc 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <Python.h> 2#include <Python.h>
2#include <structmember.h> 3#include <structmember.h>
3#include <inttypes.h> 4#include <inttypes.h>
diff --git a/tools/perf/util/quote.c b/tools/perf/util/quote.c
index 1ba8920151d8..22eaa201aa27 100644
--- a/tools/perf/util/quote.c
+++ b/tools/perf/util/quote.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include "strbuf.h" 4#include "strbuf.h"
diff --git a/tools/perf/util/quote.h b/tools/perf/util/quote.h
index 055ca45bed99..274bf26d3511 100644
--- a/tools/perf/util/quote.h
+++ b/tools/perf/util/quote.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_QUOTE_H 2#ifndef __PERF_QUOTE_H
2#define __PERF_QUOTE_H 3#define __PERF_QUOTE_H
3 4
diff --git a/tools/perf/util/rb_resort.h b/tools/perf/util/rb_resort.h
index 808cc45611fe..a920f702a74d 100644
--- a/tools/perf/util/rb_resort.h
+++ b/tools/perf/util/rb_resort.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_RESORT_RB_H_ 2#ifndef _PERF_RESORT_RB_H_
2#define _PERF_RESORT_RB_H_ 3#define _PERF_RESORT_RB_H_
3/* 4/*
@@ -143,7 +144,8 @@ struct __name##_sorted *__name = __name##_sorted__new
143 __ilist->rblist.nr_entries) 144 __ilist->rblist.nr_entries)
144 145
145/* For 'struct machine->threads' */ 146/* For 'struct machine->threads' */
146#define DECLARE_RESORT_RB_MACHINE_THREADS(__name, __machine) \ 147#define DECLARE_RESORT_RB_MACHINE_THREADS(__name, __machine, hash_bucket) \
147 DECLARE_RESORT_RB(__name)(&__machine->threads, __machine->nr_threads) 148 DECLARE_RESORT_RB(__name)(&__machine->threads[hash_bucket].entries, \
149 __machine->threads[hash_bucket].nr)
148 150
149#endif /* _PERF_RESORT_RB_H_ */ 151#endif /* _PERF_RESORT_RB_H_ */
diff --git a/tools/perf/util/rblist.h b/tools/perf/util/rblist.h
index ff9913b994c2..4c8638a22571 100644
--- a/tools/perf/util/rblist.h
+++ b/tools/perf/util/rblist.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_RBLIST_H 2#ifndef __PERF_RBLIST_H
2#define __PERF_RBLIST_H 3#define __PERF_RBLIST_H
3 4
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index d91bdf5a1aa4..1e97937b03a9 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "evlist.h" 2#include "evlist.h"
2#include "evsel.h" 3#include "evsel.h"
3#include "cpumap.h" 4#include "cpumap.h"
diff --git a/tools/perf/util/rwsem.c b/tools/perf/util/rwsem.c
new file mode 100644
index 000000000000..5e52e7baa7b6
--- /dev/null
+++ b/tools/perf/util/rwsem.c
@@ -0,0 +1,32 @@
1#include "util.h"
2#include "rwsem.h"
3
4int init_rwsem(struct rw_semaphore *sem)
5{
6 return pthread_rwlock_init(&sem->lock, NULL);
7}
8
9int exit_rwsem(struct rw_semaphore *sem)
10{
11 return pthread_rwlock_destroy(&sem->lock);
12}
13
14int down_read(struct rw_semaphore *sem)
15{
16 return perf_singlethreaded ? 0 : pthread_rwlock_rdlock(&sem->lock);
17}
18
19int up_read(struct rw_semaphore *sem)
20{
21 return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
22}
23
24int down_write(struct rw_semaphore *sem)
25{
26 return perf_singlethreaded ? 0 : pthread_rwlock_wrlock(&sem->lock);
27}
28
29int up_write(struct rw_semaphore *sem)
30{
31 return perf_singlethreaded ? 0 : pthread_rwlock_unlock(&sem->lock);
32}
diff --git a/tools/perf/util/rwsem.h b/tools/perf/util/rwsem.h
new file mode 100644
index 000000000000..94565ad4d494
--- /dev/null
+++ b/tools/perf/util/rwsem.h
@@ -0,0 +1,19 @@
1#ifndef _PERF_RWSEM_H
2#define _PERF_RWSEM_H
3
4#include <pthread.h>
5
6struct rw_semaphore {
7 pthread_rwlock_t lock;
8};
9
10int init_rwsem(struct rw_semaphore *sem);
11int exit_rwsem(struct rw_semaphore *sem);
12
13int down_read(struct rw_semaphore *sem);
14int up_read(struct rw_semaphore *sem);
15
16int down_write(struct rw_semaphore *sem);
17int up_write(struct rw_semaphore *sem);
18
19#endif /* _PERF_RWSEM_H */
diff --git a/tools/perf/util/sane_ctype.h b/tools/perf/util/sane_ctype.h
index 4308c22c22ad..c2b42ff9ff32 100644
--- a/tools/perf/util/sane_ctype.h
+++ b/tools/perf/util/sane_ctype.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_SANE_CTYPE_H 2#ifndef _PERF_SANE_CTYPE_H
2#define _PERF_SANE_CTYPE_H 3#define _PERF_SANE_CTYPE_H
3 4
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index a7ebd9fe8e40..5c412310f266 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
@@ -32,14 +33,14 @@ static int perf_session__deliver_event(struct perf_session *session,
32 33
33static int perf_session__open(struct perf_session *session) 34static int perf_session__open(struct perf_session *session)
34{ 35{
35 struct perf_data_file *file = session->file; 36 struct perf_data *data = session->data;
36 37
37 if (perf_session__read_header(session) < 0) { 38 if (perf_session__read_header(session) < 0) {
38 pr_err("incompatible file format (rerun with -v to learn more)\n"); 39 pr_err("incompatible file format (rerun with -v to learn more)\n");
39 return -1; 40 return -1;
40 } 41 }
41 42
42 if (perf_data_file__is_pipe(file)) 43 if (perf_data__is_pipe(data))
43 return 0; 44 return 0;
44 45
45 if (perf_header__has_feat(&session->header, HEADER_STAT)) 46 if (perf_header__has_feat(&session->header, HEADER_STAT))
@@ -120,7 +121,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe,
120 session->tool, event->file_offset); 121 session->tool, event->file_offset);
121} 122}
122 123
123struct perf_session *perf_session__new(struct perf_data_file *file, 124struct perf_session *perf_session__new(struct perf_data *data,
124 bool repipe, struct perf_tool *tool) 125 bool repipe, struct perf_tool *tool)
125{ 126{
126 struct perf_session *session = zalloc(sizeof(*session)); 127 struct perf_session *session = zalloc(sizeof(*session));
@@ -134,13 +135,13 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
134 machines__init(&session->machines); 135 machines__init(&session->machines);
135 ordered_events__init(&session->ordered_events, ordered_events__deliver_event); 136 ordered_events__init(&session->ordered_events, ordered_events__deliver_event);
136 137
137 if (file) { 138 if (data) {
138 if (perf_data_file__open(file)) 139 if (perf_data__open(data))
139 goto out_delete; 140 goto out_delete;
140 141
141 session->file = file; 142 session->data = data;
142 143
143 if (perf_data_file__is_read(file)) { 144 if (perf_data__is_read(data)) {
144 if (perf_session__open(session) < 0) 145 if (perf_session__open(session) < 0)
145 goto out_close; 146 goto out_close;
146 147
@@ -148,7 +149,7 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
148 * set session attributes that are present in perf.data 149 * set session attributes that are present in perf.data
149 * but not in pipe-mode. 150 * but not in pipe-mode.
150 */ 151 */
151 if (!file->is_pipe) { 152 if (!data->is_pipe) {
152 perf_session__set_id_hdr_size(session); 153 perf_session__set_id_hdr_size(session);
153 perf_session__set_comm_exec(session); 154 perf_session__set_comm_exec(session);
154 } 155 }
@@ -157,7 +158,7 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
157 session->machines.host.env = &perf_env; 158 session->machines.host.env = &perf_env;
158 } 159 }
159 160
160 if (!file || perf_data_file__is_write(file)) { 161 if (!data || perf_data__is_write(data)) {
161 /* 162 /*
162 * In O_RDONLY mode this will be performed when reading the 163 * In O_RDONLY mode this will be performed when reading the
163 * kernel MMAP event, in perf_event__process_mmap(). 164 * kernel MMAP event, in perf_event__process_mmap().
@@ -170,7 +171,7 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
170 * In pipe-mode, evlist is empty until PERF_RECORD_HEADER_ATTR is 171 * In pipe-mode, evlist is empty until PERF_RECORD_HEADER_ATTR is
171 * processed, so perf_evlist__sample_id_all is not meaningful here. 172 * processed, so perf_evlist__sample_id_all is not meaningful here.
172 */ 173 */
173 if ((!file || !file->is_pipe) && tool && tool->ordering_requires_timestamps && 174 if ((!data || !data->is_pipe) && tool && tool->ordering_requires_timestamps &&
174 tool->ordered_events && !perf_evlist__sample_id_all(session->evlist)) { 175 tool->ordered_events && !perf_evlist__sample_id_all(session->evlist)) {
175 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); 176 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
176 tool->ordered_events = false; 177 tool->ordered_events = false;
@@ -179,7 +180,7 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
179 return session; 180 return session;
180 181
181 out_close: 182 out_close:
182 perf_data_file__close(file); 183 perf_data__close(data);
183 out_delete: 184 out_delete:
184 perf_session__delete(session); 185 perf_session__delete(session);
185 out: 186 out:
@@ -201,8 +202,8 @@ void perf_session__delete(struct perf_session *session)
201 perf_session__delete_threads(session); 202 perf_session__delete_threads(session);
202 perf_env__exit(&session->header.env); 203 perf_env__exit(&session->header.env);
203 machines__exit(&session->machines); 204 machines__exit(&session->machines);
204 if (session->file) 205 if (session->data)
205 perf_data_file__close(session->file); 206 perf_data__close(session->data);
206 free(session); 207 free(session);
207} 208}
208 209
@@ -290,8 +291,8 @@ static s64 process_event_auxtrace_stub(struct perf_tool *tool __maybe_unused,
290 __maybe_unused) 291 __maybe_unused)
291{ 292{
292 dump_printf(": unhandled!\n"); 293 dump_printf(": unhandled!\n");
293 if (perf_data_file__is_pipe(session->file)) 294 if (perf_data__is_pipe(session->data))
294 skipn(perf_data_file__fd(session->file), event->auxtrace.size); 295 skipn(perf_data__fd(session->data), event->auxtrace.size);
295 return event->auxtrace.size; 296 return event->auxtrace.size;
296} 297}
297 298
@@ -374,6 +375,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
374 tool->mmap2 = process_event_stub; 375 tool->mmap2 = process_event_stub;
375 if (tool->comm == NULL) 376 if (tool->comm == NULL)
376 tool->comm = process_event_stub; 377 tool->comm = process_event_stub;
378 if (tool->namespaces == NULL)
379 tool->namespaces = process_event_stub;
377 if (tool->fork == NULL) 380 if (tool->fork == NULL)
378 tool->fork = process_event_stub; 381 tool->fork = process_event_stub;
379 if (tool->exit == NULL) 382 if (tool->exit == NULL)
@@ -1347,7 +1350,7 @@ static s64 perf_session__process_user_event(struct perf_session *session,
1347{ 1350{
1348 struct ordered_events *oe = &session->ordered_events; 1351 struct ordered_events *oe = &session->ordered_events;
1349 struct perf_tool *tool = session->tool; 1352 struct perf_tool *tool = session->tool;
1350 int fd = perf_data_file__fd(session->file); 1353 int fd = perf_data__fd(session->data);
1351 int err; 1354 int err;
1352 1355
1353 dump_event(session->evlist, event, file_offset, NULL); 1356 dump_event(session->evlist, event, file_offset, NULL);
@@ -1447,10 +1450,10 @@ int perf_session__peek_event(struct perf_session *session, off_t file_offset,
1447 goto out_parse_sample; 1450 goto out_parse_sample;
1448 } 1451 }
1449 1452
1450 if (perf_data_file__is_pipe(session->file)) 1453 if (perf_data__is_pipe(session->data))
1451 return -1; 1454 return -1;
1452 1455
1453 fd = perf_data_file__fd(session->file); 1456 fd = perf_data__fd(session->data);
1454 hdr_sz = sizeof(struct perf_event_header); 1457 hdr_sz = sizeof(struct perf_event_header);
1455 1458
1456 if (buf_sz < hdr_sz) 1459 if (buf_sz < hdr_sz)
@@ -1685,7 +1688,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
1685{ 1688{
1686 struct ordered_events *oe = &session->ordered_events; 1689 struct ordered_events *oe = &session->ordered_events;
1687 struct perf_tool *tool = session->tool; 1690 struct perf_tool *tool = session->tool;
1688 int fd = perf_data_file__fd(session->file); 1691 int fd = perf_data__fd(session->data);
1689 union perf_event *event; 1692 union perf_event *event;
1690 uint32_t size, cur_size = 0; 1693 uint32_t size, cur_size = 0;
1691 void *buf = NULL; 1694 void *buf = NULL;
@@ -1826,7 +1829,7 @@ static int __perf_session__process_events(struct perf_session *session,
1826{ 1829{
1827 struct ordered_events *oe = &session->ordered_events; 1830 struct ordered_events *oe = &session->ordered_events;
1828 struct perf_tool *tool = session->tool; 1831 struct perf_tool *tool = session->tool;
1829 int fd = perf_data_file__fd(session->file); 1832 int fd = perf_data__fd(session->data);
1830 u64 head, page_offset, file_offset, file_pos, size; 1833 u64 head, page_offset, file_offset, file_pos, size;
1831 int err, mmap_prot, mmap_flags, map_idx = 0; 1834 int err, mmap_prot, mmap_flags, map_idx = 0;
1832 size_t mmap_size; 1835 size_t mmap_size;
@@ -1847,7 +1850,7 @@ static int __perf_session__process_events(struct perf_session *session,
1847 if (data_offset + data_size < file_size) 1850 if (data_offset + data_size < file_size)
1848 file_size = data_offset + data_size; 1851 file_size = data_offset + data_size;
1849 1852
1850 ui_progress__init(&prog, file_size, "Processing events..."); 1853 ui_progress__init_size(&prog, file_size, "Processing events...");
1851 1854
1852 mmap_size = MMAP_SIZE; 1855 mmap_size = MMAP_SIZE;
1853 if (mmap_size > file_size) { 1856 if (mmap_size > file_size) {
@@ -1943,13 +1946,13 @@ out_err:
1943 1946
1944int perf_session__process_events(struct perf_session *session) 1947int perf_session__process_events(struct perf_session *session)
1945{ 1948{
1946 u64 size = perf_data_file__size(session->file); 1949 u64 size = perf_data__size(session->data);
1947 int err; 1950 int err;
1948 1951
1949 if (perf_session__register_idle_thread(session) < 0) 1952 if (perf_session__register_idle_thread(session) < 0)
1950 return -ENOMEM; 1953 return -ENOMEM;
1951 1954
1952 if (!perf_data_file__is_pipe(session->file)) 1955 if (!perf_data__is_pipe(session->data))
1953 err = __perf_session__process_events(session, 1956 err = __perf_session__process_events(session,
1954 session->header.data_offset, 1957 session->header.data_offset,
1955 session->header.data_size, size); 1958 session->header.data_size, size);
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 47b5e7dbcb18..da1434a7c120 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_SESSION_H 2#ifndef __PERF_SESSION_H
2#define __PERF_SESSION_H 3#define __PERF_SESSION_H
3 4
@@ -32,13 +33,13 @@ struct perf_session {
32 void *one_mmap_addr; 33 void *one_mmap_addr;
33 u64 one_mmap_offset; 34 u64 one_mmap_offset;
34 struct ordered_events ordered_events; 35 struct ordered_events ordered_events;
35 struct perf_data_file *file; 36 struct perf_data *data;
36 struct perf_tool *tool; 37 struct perf_tool *tool;
37}; 38};
38 39
39struct perf_tool; 40struct perf_tool;
40 41
41struct perf_session *perf_session__new(struct perf_data_file *file, 42struct perf_session *perf_session__new(struct perf_data *data,
42 bool repipe, struct perf_tool *tool); 43 bool repipe, struct perf_tool *tool);
43void perf_session__delete(struct perf_session *session); 44void perf_session__delete(struct perf_session *session);
44 45
@@ -113,7 +114,7 @@ int __perf_session__set_tracepoints_handlers(struct perf_session *session,
113 114
114extern volatile int session_done; 115extern volatile int session_done;
115 116
116#define session_done() ACCESS_ONCE(session_done) 117#define session_done() READ_ONCE(session_done)
117 118
118int perf_session__deliver_synth_event(struct perf_session *session, 119int perf_session__deliver_synth_event(struct perf_session *session,
119 union perf_event *event, 120 union perf_event *event,
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index eb3ab902a1c0..a00eacdf02ed 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <regex.h> 4#include <regex.h>
@@ -225,6 +226,9 @@ static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r)
225 if (sym_l == sym_r) 226 if (sym_l == sym_r)
226 return 0; 227 return 0;
227 228
229 if (sym_l->inlined || sym_r->inlined)
230 return strcmp(sym_l->name, sym_r->name);
231
228 if (sym_l->start != sym_r->start) 232 if (sym_l->start != sym_r->start)
229 return (int64_t)(sym_r->start - sym_l->start); 233 return (int64_t)(sym_r->start - sym_l->start);
230 234
@@ -283,6 +287,9 @@ static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
283 ret += repsep_snprintf(bf + ret, size - ret, "%.*s", 287 ret += repsep_snprintf(bf + ret, size - ret, "%.*s",
284 width - ret, 288 width - ret,
285 sym->name); 289 sym->name);
290 if (sym->inlined)
291 ret += repsep_snprintf(bf + ret, size - ret,
292 " (inlined)");
286 } 293 }
287 } else { 294 } else {
288 size_t len = BITS_PER_LONG / 4; 295 size_t len = BITS_PER_LONG / 4;
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index f36dc4980a6c..f5901c10a563 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_SORT_H 2#ifndef __PERF_SORT_H
2#define __PERF_SORT_H 3#define __PERF_SORT_H
3#include "../builtin.h" 4#include "../builtin.h"
@@ -129,7 +130,6 @@ struct hist_entry {
129 }; 130 };
130 char *srcline; 131 char *srcline;
131 char *srcfile; 132 char *srcfile;
132 struct inline_node *inline_node;
133 struct symbol *parent; 133 struct symbol *parent;
134 struct branch_info *branch_info; 134 struct branch_info *branch_info;
135 struct hists *hists; 135 struct hists *hists;
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index ed8e8d2de942..d19f05c56de6 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdlib.h> 4#include <stdlib.h>
@@ -10,7 +11,7 @@
10#include "util/debug.h" 11#include "util/debug.h"
11#include "util/callchain.h" 12#include "util/callchain.h"
12#include "srcline.h" 13#include "srcline.h"
13 14#include "string2.h"
14#include "symbol.h" 15#include "symbol.h"
15 16
16bool srcline_full_filename; 17bool srcline_full_filename;
@@ -33,28 +34,17 @@ static const char *dso__name(struct dso *dso)
33 return dso_name; 34 return dso_name;
34} 35}
35 36
36static int inline_list__append(char *filename, char *funcname, int line_nr, 37static int inline_list__append(struct symbol *symbol, char *srcline,
37 struct inline_node *node, struct dso *dso) 38 struct inline_node *node)
38{ 39{
39 struct inline_list *ilist; 40 struct inline_list *ilist;
40 char *demangled;
41 41
42 ilist = zalloc(sizeof(*ilist)); 42 ilist = zalloc(sizeof(*ilist));
43 if (ilist == NULL) 43 if (ilist == NULL)
44 return -1; 44 return -1;
45 45
46 ilist->filename = filename; 46 ilist->symbol = symbol;
47 ilist->line_nr = line_nr; 47 ilist->srcline = srcline;
48
49 if (dso != NULL) {
50 demangled = dso__demangle_sym(dso, 0, funcname);
51 if (demangled == NULL) {
52 ilist->funcname = funcname;
53 } else {
54 ilist->funcname = demangled;
55 free(funcname);
56 }
57 }
58 48
59 if (callchain_param.order == ORDER_CALLEE) 49 if (callchain_param.order == ORDER_CALLEE)
60 list_add_tail(&ilist->list, &node->val); 50 list_add_tail(&ilist->list, &node->val);
@@ -64,6 +54,65 @@ static int inline_list__append(char *filename, char *funcname, int line_nr,
64 return 0; 54 return 0;
65} 55}
66 56
57/* basename version that takes a const input string */
58static const char *gnu_basename(const char *path)
59{
60 const char *base = strrchr(path, '/');
61
62 return base ? base + 1 : path;
63}
64
65static char *srcline_from_fileline(const char *file, unsigned int line)
66{
67 char *srcline;
68
69 if (!file)
70 return NULL;
71
72 if (!srcline_full_filename)
73 file = gnu_basename(file);
74
75 if (asprintf(&srcline, "%s:%u", file, line) < 0)
76 return NULL;
77
78 return srcline;
79}
80
81static struct symbol *new_inline_sym(struct dso *dso,
82 struct symbol *base_sym,
83 const char *funcname)
84{
85 struct symbol *inline_sym;
86 char *demangled = NULL;
87
88 if (dso) {
89 demangled = dso__demangle_sym(dso, 0, funcname);
90 if (demangled)
91 funcname = demangled;
92 }
93
94 if (base_sym && strcmp(funcname, base_sym->name) == 0) {
95 /* reuse the real, existing symbol */
96 inline_sym = base_sym;
97 /* ensure that we don't alias an inlined symbol, which could
98 * lead to double frees in inline_node__delete
99 */
100 assert(!base_sym->inlined);
101 } else {
102 /* create a fake symbol for the inline frame */
103 inline_sym = symbol__new(base_sym ? base_sym->start : 0,
104 base_sym ? base_sym->end : 0,
105 base_sym ? base_sym->binding : 0,
106 funcname);
107 if (inline_sym)
108 inline_sym->inlined = 1;
109 }
110
111 free(demangled);
112
113 return inline_sym;
114}
115
67#ifdef HAVE_LIBBFD_SUPPORT 116#ifdef HAVE_LIBBFD_SUPPORT
68 117
69/* 118/*
@@ -207,18 +256,23 @@ static void addr2line_cleanup(struct a2l_data *a2l)
207#define MAX_INLINE_NEST 1024 256#define MAX_INLINE_NEST 1024
208 257
209static int inline_list__append_dso_a2l(struct dso *dso, 258static int inline_list__append_dso_a2l(struct dso *dso,
210 struct inline_node *node) 259 struct inline_node *node,
260 struct symbol *sym)
211{ 261{
212 struct a2l_data *a2l = dso->a2l; 262 struct a2l_data *a2l = dso->a2l;
213 char *funcname = a2l->funcname ? strdup(a2l->funcname) : NULL; 263 struct symbol *inline_sym = new_inline_sym(dso, sym, a2l->funcname);
214 char *filename = a2l->filename ? strdup(a2l->filename) : NULL; 264 char *srcline = NULL;
215 265
216 return inline_list__append(filename, funcname, a2l->line, node, dso); 266 if (a2l->filename)
267 srcline = srcline_from_fileline(a2l->filename, a2l->line);
268
269 return inline_list__append(inline_sym, srcline, node);
217} 270}
218 271
219static int addr2line(const char *dso_name, u64 addr, 272static int addr2line(const char *dso_name, u64 addr,
220 char **file, unsigned int *line, struct dso *dso, 273 char **file, unsigned int *line, struct dso *dso,
221 bool unwind_inlines, struct inline_node *node) 274 bool unwind_inlines, struct inline_node *node,
275 struct symbol *sym)
222{ 276{
223 int ret = 0; 277 int ret = 0;
224 struct a2l_data *a2l = dso->a2l; 278 struct a2l_data *a2l = dso->a2l;
@@ -244,7 +298,7 @@ static int addr2line(const char *dso_name, u64 addr,
244 if (unwind_inlines) { 298 if (unwind_inlines) {
245 int cnt = 0; 299 int cnt = 0;
246 300
247 if (node && inline_list__append_dso_a2l(dso, node)) 301 if (node && inline_list__append_dso_a2l(dso, node, sym))
248 return 0; 302 return 0;
249 303
250 while (bfd_find_inliner_info(a2l->abfd, &a2l->filename, 304 while (bfd_find_inliner_info(a2l->abfd, &a2l->filename,
@@ -255,7 +309,7 @@ static int addr2line(const char *dso_name, u64 addr,
255 a2l->filename = NULL; 309 a2l->filename = NULL;
256 310
257 if (node != NULL) { 311 if (node != NULL) {
258 if (inline_list__append_dso_a2l(dso, node)) 312 if (inline_list__append_dso_a2l(dso, node, sym))
259 return 0; 313 return 0;
260 // found at least one inline frame 314 // found at least one inline frame
261 ret = 1; 315 ret = 1;
@@ -287,7 +341,7 @@ void dso__free_a2l(struct dso *dso)
287} 341}
288 342
289static struct inline_node *addr2inlines(const char *dso_name, u64 addr, 343static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
290 struct dso *dso) 344 struct dso *dso, struct symbol *sym)
291{ 345{
292 struct inline_node *node; 346 struct inline_node *node;
293 347
@@ -300,17 +354,8 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
300 INIT_LIST_HEAD(&node->val); 354 INIT_LIST_HEAD(&node->val);
301 node->addr = addr; 355 node->addr = addr;
302 356
303 if (!addr2line(dso_name, addr, NULL, NULL, dso, TRUE, node)) 357 addr2line(dso_name, addr, NULL, NULL, dso, true, node, sym);
304 goto out_free_inline_node;
305
306 if (list_empty(&node->val))
307 goto out_free_inline_node;
308
309 return node; 358 return node;
310
311out_free_inline_node:
312 inline_node__delete(node);
313 return NULL;
314} 359}
315 360
316#else /* HAVE_LIBBFD_SUPPORT */ 361#else /* HAVE_LIBBFD_SUPPORT */
@@ -340,7 +385,8 @@ static int addr2line(const char *dso_name, u64 addr,
340 char **file, unsigned int *line_nr, 385 char **file, unsigned int *line_nr,
341 struct dso *dso __maybe_unused, 386 struct dso *dso __maybe_unused,
342 bool unwind_inlines __maybe_unused, 387 bool unwind_inlines __maybe_unused,
343 struct inline_node *node __maybe_unused) 388 struct inline_node *node __maybe_unused,
389 struct symbol *sym __maybe_unused)
344{ 390{
345 FILE *fp; 391 FILE *fp;
346 char cmd[PATH_MAX]; 392 char cmd[PATH_MAX];
@@ -380,16 +426,18 @@ void dso__free_a2l(struct dso *dso __maybe_unused)
380} 426}
381 427
382static struct inline_node *addr2inlines(const char *dso_name, u64 addr, 428static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
383 struct dso *dso __maybe_unused) 429 struct dso *dso __maybe_unused,
430 struct symbol *sym)
384{ 431{
385 FILE *fp; 432 FILE *fp;
386 char cmd[PATH_MAX]; 433 char cmd[PATH_MAX];
387 struct inline_node *node; 434 struct inline_node *node;
388 char *filename = NULL; 435 char *filename = NULL;
389 size_t len; 436 char *funcname = NULL;
437 size_t filelen, funclen;
390 unsigned int line_nr = 0; 438 unsigned int line_nr = 0;
391 439
392 scnprintf(cmd, sizeof(cmd), "addr2line -e %s -i %016"PRIx64, 440 scnprintf(cmd, sizeof(cmd), "addr2line -e %s -i -f %016"PRIx64,
393 dso_name, addr); 441 dso_name, addr);
394 442
395 fp = popen(cmd, "r"); 443 fp = popen(cmd, "r");
@@ -407,26 +455,34 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
407 INIT_LIST_HEAD(&node->val); 455 INIT_LIST_HEAD(&node->val);
408 node->addr = addr; 456 node->addr = addr;
409 457
410 while (getline(&filename, &len, fp) != -1) { 458 /* addr2line -f generates two lines for each inlined functions */
411 if (filename_split(filename, &line_nr) != 1) { 459 while (getline(&funcname, &funclen, fp) != -1) {
412 free(filename); 460 char *srcline;
461 struct symbol *inline_sym;
462
463 rtrim(funcname);
464
465 if (getline(&filename, &filelen, fp) == -1)
413 goto out; 466 goto out;
414 }
415 467
416 if (inline_list__append(filename, NULL, line_nr, node, 468 if (filename_split(filename, &line_nr) != 1)
417 NULL) != 0)
418 goto out; 469 goto out;
419 470
420 filename = NULL; 471 srcline = srcline_from_fileline(filename, line_nr);
472 inline_sym = new_inline_sym(dso, sym, funcname);
473
474 if (inline_list__append(inline_sym, srcline, node) != 0) {
475 free(srcline);
476 if (inline_sym && inline_sym->inlined)
477 symbol__delete(inline_sym);
478 goto out;
479 }
421 } 480 }
422 481
423out: 482out:
424 pclose(fp); 483 pclose(fp);
425 484 free(filename);
426 if (list_empty(&node->val)) { 485 free(funcname);
427 inline_node__delete(node);
428 return NULL;
429 }
430 486
431 return node; 487 return node;
432} 488}
@@ -454,19 +510,18 @@ char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
454 if (dso_name == NULL) 510 if (dso_name == NULL)
455 goto out; 511 goto out;
456 512
457 if (!addr2line(dso_name, addr, &file, &line, dso, unwind_inlines, NULL)) 513 if (!addr2line(dso_name, addr, &file, &line, dso,
514 unwind_inlines, NULL, sym))
458 goto out; 515 goto out;
459 516
460 if (asprintf(&srcline, "%s:%u", 517 srcline = srcline_from_fileline(file, line);
461 srcline_full_filename ? file : basename(file), 518 free(file);
462 line) < 0) { 519
463 free(file); 520 if (!srcline)
464 goto out; 521 goto out;
465 }
466 522
467 dso->a2l_fails = 0; 523 dso->a2l_fails = 0;
468 524
469 free(file);
470 return srcline; 525 return srcline;
471 526
472out: 527out:
@@ -500,7 +555,74 @@ char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
500 return __get_srcline(dso, addr, sym, show_sym, show_addr, false); 555 return __get_srcline(dso, addr, sym, show_sym, show_addr, false);
501} 556}
502 557
503struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr) 558struct srcline_node {
559 u64 addr;
560 char *srcline;
561 struct rb_node rb_node;
562};
563
564void srcline__tree_insert(struct rb_root *tree, u64 addr, char *srcline)
565{
566 struct rb_node **p = &tree->rb_node;
567 struct rb_node *parent = NULL;
568 struct srcline_node *i, *node;
569
570 node = zalloc(sizeof(struct srcline_node));
571 if (!node) {
572 perror("not enough memory for the srcline node");
573 return;
574 }
575
576 node->addr = addr;
577 node->srcline = srcline;
578
579 while (*p != NULL) {
580 parent = *p;
581 i = rb_entry(parent, struct srcline_node, rb_node);
582 if (addr < i->addr)
583 p = &(*p)->rb_left;
584 else
585 p = &(*p)->rb_right;
586 }
587 rb_link_node(&node->rb_node, parent, p);
588 rb_insert_color(&node->rb_node, tree);
589}
590
591char *srcline__tree_find(struct rb_root *tree, u64 addr)
592{
593 struct rb_node *n = tree->rb_node;
594
595 while (n) {
596 struct srcline_node *i = rb_entry(n, struct srcline_node,
597 rb_node);
598
599 if (addr < i->addr)
600 n = n->rb_left;
601 else if (addr > i->addr)
602 n = n->rb_right;
603 else
604 return i->srcline;
605 }
606
607 return NULL;
608}
609
610void srcline__tree_delete(struct rb_root *tree)
611{
612 struct srcline_node *pos;
613 struct rb_node *next = rb_first(tree);
614
615 while (next) {
616 pos = rb_entry(next, struct srcline_node, rb_node);
617 next = rb_next(&pos->rb_node);
618 rb_erase(&pos->rb_node, tree);
619 free_srcline(pos->srcline);
620 zfree(&pos);
621 }
622}
623
624struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr,
625 struct symbol *sym)
504{ 626{
505 const char *dso_name; 627 const char *dso_name;
506 628
@@ -508,7 +630,7 @@ struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr)
508 if (dso_name == NULL) 630 if (dso_name == NULL)
509 return NULL; 631 return NULL;
510 632
511 return addr2inlines(dso_name, addr, dso); 633 return addr2inlines(dso_name, addr, dso, sym);
512} 634}
513 635
514void inline_node__delete(struct inline_node *node) 636void inline_node__delete(struct inline_node *node)
@@ -517,10 +639,63 @@ void inline_node__delete(struct inline_node *node)
517 639
518 list_for_each_entry_safe(ilist, tmp, &node->val, list) { 640 list_for_each_entry_safe(ilist, tmp, &node->val, list) {
519 list_del_init(&ilist->list); 641 list_del_init(&ilist->list);
520 zfree(&ilist->filename); 642 free_srcline(ilist->srcline);
521 zfree(&ilist->funcname); 643 /* only the inlined symbols are owned by the list */
644 if (ilist->symbol && ilist->symbol->inlined)
645 symbol__delete(ilist->symbol);
522 free(ilist); 646 free(ilist);
523 } 647 }
524 648
525 free(node); 649 free(node);
526} 650}
651
652void inlines__tree_insert(struct rb_root *tree, struct inline_node *inlines)
653{
654 struct rb_node **p = &tree->rb_node;
655 struct rb_node *parent = NULL;
656 const u64 addr = inlines->addr;
657 struct inline_node *i;
658
659 while (*p != NULL) {
660 parent = *p;
661 i = rb_entry(parent, struct inline_node, rb_node);
662 if (addr < i->addr)
663 p = &(*p)->rb_left;
664 else
665 p = &(*p)->rb_right;
666 }
667 rb_link_node(&inlines->rb_node, parent, p);
668 rb_insert_color(&inlines->rb_node, tree);
669}
670
671struct inline_node *inlines__tree_find(struct rb_root *tree, u64 addr)
672{
673 struct rb_node *n = tree->rb_node;
674
675 while (n) {
676 struct inline_node *i = rb_entry(n, struct inline_node,
677 rb_node);
678
679 if (addr < i->addr)
680 n = n->rb_left;
681 else if (addr > i->addr)
682 n = n->rb_right;
683 else
684 return i;
685 }
686
687 return NULL;
688}
689
690void inlines__tree_delete(struct rb_root *tree)
691{
692 struct inline_node *pos;
693 struct rb_node *next = rb_first(tree);
694
695 while (next) {
696 pos = rb_entry(next, struct inline_node, rb_node);
697 next = rb_next(&pos->rb_node);
698 rb_erase(&pos->rb_node, tree);
699 inline_node__delete(pos);
700 }
701}
diff --git a/tools/perf/util/srcline.h b/tools/perf/util/srcline.h
index 7b52ba88676e..847b7086182c 100644
--- a/tools/perf/util/srcline.h
+++ b/tools/perf/util/srcline.h
@@ -1,7 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_SRCLINE_H 2#ifndef PERF_SRCLINE_H
2#define PERF_SRCLINE_H 3#define PERF_SRCLINE_H
3 4
4#include <linux/list.h> 5#include <linux/list.h>
6#include <linux/rbtree.h>
5#include <linux/types.h> 7#include <linux/types.h>
6 8
7struct dso; 9struct dso;
@@ -14,21 +16,38 @@ char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
14 bool show_sym, bool show_addr, bool unwind_inlines); 16 bool show_sym, bool show_addr, bool unwind_inlines);
15void free_srcline(char *srcline); 17void free_srcline(char *srcline);
16 18
19/* insert the srcline into the DSO, which will take ownership */
20void srcline__tree_insert(struct rb_root *tree, u64 addr, char *srcline);
21/* find previously inserted srcline */
22char *srcline__tree_find(struct rb_root *tree, u64 addr);
23/* delete all srclines within the tree */
24void srcline__tree_delete(struct rb_root *tree);
25
17#define SRCLINE_UNKNOWN ((char *) "??:0") 26#define SRCLINE_UNKNOWN ((char *) "??:0")
18 27
19struct inline_list { 28struct inline_list {
20 char *filename; 29 struct symbol *symbol;
21 char *funcname; 30 char *srcline;
22 unsigned int line_nr;
23 struct list_head list; 31 struct list_head list;
24}; 32};
25 33
26struct inline_node { 34struct inline_node {
27 u64 addr; 35 u64 addr;
28 struct list_head val; 36 struct list_head val;
37 struct rb_node rb_node;
29}; 38};
30 39
31struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr); 40/* parse inlined frames for the given address */
41struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr,
42 struct symbol *sym);
43/* free resources associated to the inline node list */
32void inline_node__delete(struct inline_node *node); 44void inline_node__delete(struct inline_node *node);
33 45
46/* insert the inline node list into the DSO, which will take ownership */
47void inlines__tree_insert(struct rb_root *tree, struct inline_node *inlines);
48/* find previously inserted inline node list */
49struct inline_node *inlines__tree_find(struct rb_root *tree, u64 addr);
50/* delete all nodes within the tree of inline_node s */
51void inlines__tree_delete(struct rb_root *tree);
52
34#endif /* PERF_SRCLINE_H */ 53#endif /* PERF_SRCLINE_H */
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index a04cf56d3517..855e35cbb1dc 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include "evsel.h" 3#include "evsel.h"
3#include "stat.h" 4#include "stat.h"
@@ -6,6 +7,7 @@
6#include "rblist.h" 7#include "rblist.h"
7#include "evlist.h" 8#include "evlist.h"
8#include "expr.h" 9#include "expr.h"
10#include "metricgroup.h"
9 11
10enum { 12enum {
11 CTX_BIT_USER = 1 << 0, 13 CTX_BIT_USER = 1 << 0,
@@ -55,7 +57,6 @@ struct saved_value {
55 struct rb_node rb_node; 57 struct rb_node rb_node;
56 struct perf_evsel *evsel; 58 struct perf_evsel *evsel;
57 int cpu; 59 int cpu;
58 int ctx;
59 struct stats stats; 60 struct stats stats;
60}; 61};
61 62
@@ -66,8 +67,6 @@ static int saved_value_cmp(struct rb_node *rb_node, const void *entry)
66 rb_node); 67 rb_node);
67 const struct saved_value *b = entry; 68 const struct saved_value *b = entry;
68 69
69 if (a->ctx != b->ctx)
70 return a->ctx - b->ctx;
71 if (a->cpu != b->cpu) 70 if (a->cpu != b->cpu)
72 return a->cpu - b->cpu; 71 return a->cpu - b->cpu;
73 if (a->evsel == b->evsel) 72 if (a->evsel == b->evsel)
@@ -89,13 +88,12 @@ static struct rb_node *saved_value_new(struct rblist *rblist __maybe_unused,
89} 88}
90 89
91static struct saved_value *saved_value_lookup(struct perf_evsel *evsel, 90static struct saved_value *saved_value_lookup(struct perf_evsel *evsel,
92 int cpu, int ctx, 91 int cpu,
93 bool create) 92 bool create)
94{ 93{
95 struct rb_node *nd; 94 struct rb_node *nd;
96 struct saved_value dm = { 95 struct saved_value dm = {
97 .cpu = cpu, 96 .cpu = cpu,
98 .ctx = ctx,
99 .evsel = evsel, 97 .evsel = evsel,
100 }; 98 };
101 nd = rblist__find(&runtime_saved_values, &dm); 99 nd = rblist__find(&runtime_saved_values, &dm);
@@ -181,59 +179,60 @@ void perf_stat__reset_shadow_stats(void)
181 * more semantic information such as miss/hit ratios, 179 * more semantic information such as miss/hit ratios,
182 * instruction rates, etc: 180 * instruction rates, etc:
183 */ 181 */
184void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, 182void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
185 int cpu) 183 int cpu)
186{ 184{
187 int ctx = evsel_context(counter); 185 int ctx = evsel_context(counter);
188 186
187 count *= counter->scale;
188
189 if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK) || 189 if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK) ||
190 perf_evsel__match(counter, SOFTWARE, SW_CPU_CLOCK)) 190 perf_evsel__match(counter, SOFTWARE, SW_CPU_CLOCK))
191 update_stats(&runtime_nsecs_stats[cpu], count[0]); 191 update_stats(&runtime_nsecs_stats[cpu], count);
192 else if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES)) 192 else if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES))
193 update_stats(&runtime_cycles_stats[ctx][cpu], count[0]); 193 update_stats(&runtime_cycles_stats[ctx][cpu], count);
194 else if (perf_stat_evsel__is(counter, CYCLES_IN_TX)) 194 else if (perf_stat_evsel__is(counter, CYCLES_IN_TX))
195 update_stats(&runtime_cycles_in_tx_stats[ctx][cpu], count[0]); 195 update_stats(&runtime_cycles_in_tx_stats[ctx][cpu], count);
196 else if (perf_stat_evsel__is(counter, TRANSACTION_START)) 196 else if (perf_stat_evsel__is(counter, TRANSACTION_START))
197 update_stats(&runtime_transaction_stats[ctx][cpu], count[0]); 197 update_stats(&runtime_transaction_stats[ctx][cpu], count);
198 else if (perf_stat_evsel__is(counter, ELISION_START)) 198 else if (perf_stat_evsel__is(counter, ELISION_START))
199 update_stats(&runtime_elision_stats[ctx][cpu], count[0]); 199 update_stats(&runtime_elision_stats[ctx][cpu], count);
200 else if (perf_stat_evsel__is(counter, TOPDOWN_TOTAL_SLOTS)) 200 else if (perf_stat_evsel__is(counter, TOPDOWN_TOTAL_SLOTS))
201 update_stats(&runtime_topdown_total_slots[ctx][cpu], count[0]); 201 update_stats(&runtime_topdown_total_slots[ctx][cpu], count);
202 else if (perf_stat_evsel__is(counter, TOPDOWN_SLOTS_ISSUED)) 202 else if (perf_stat_evsel__is(counter, TOPDOWN_SLOTS_ISSUED))
203 update_stats(&runtime_topdown_slots_issued[ctx][cpu], count[0]); 203 update_stats(&runtime_topdown_slots_issued[ctx][cpu], count);
204 else if (perf_stat_evsel__is(counter, TOPDOWN_SLOTS_RETIRED)) 204 else if (perf_stat_evsel__is(counter, TOPDOWN_SLOTS_RETIRED))
205 update_stats(&runtime_topdown_slots_retired[ctx][cpu], count[0]); 205 update_stats(&runtime_topdown_slots_retired[ctx][cpu], count);
206 else if (perf_stat_evsel__is(counter, TOPDOWN_FETCH_BUBBLES)) 206 else if (perf_stat_evsel__is(counter, TOPDOWN_FETCH_BUBBLES))
207 update_stats(&runtime_topdown_fetch_bubbles[ctx][cpu],count[0]); 207 update_stats(&runtime_topdown_fetch_bubbles[ctx][cpu], count);
208 else if (perf_stat_evsel__is(counter, TOPDOWN_RECOVERY_BUBBLES)) 208 else if (perf_stat_evsel__is(counter, TOPDOWN_RECOVERY_BUBBLES))
209 update_stats(&runtime_topdown_recovery_bubbles[ctx][cpu], count[0]); 209 update_stats(&runtime_topdown_recovery_bubbles[ctx][cpu], count);
210 else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) 210 else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_FRONTEND))
211 update_stats(&runtime_stalled_cycles_front_stats[ctx][cpu], count[0]); 211 update_stats(&runtime_stalled_cycles_front_stats[ctx][cpu], count);
212 else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_BACKEND)) 212 else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_BACKEND))
213 update_stats(&runtime_stalled_cycles_back_stats[ctx][cpu], count[0]); 213 update_stats(&runtime_stalled_cycles_back_stats[ctx][cpu], count);
214 else if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS)) 214 else if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS))
215 update_stats(&runtime_branches_stats[ctx][cpu], count[0]); 215 update_stats(&runtime_branches_stats[ctx][cpu], count);
216 else if (perf_evsel__match(counter, HARDWARE, HW_CACHE_REFERENCES)) 216 else if (perf_evsel__match(counter, HARDWARE, HW_CACHE_REFERENCES))
217 update_stats(&runtime_cacherefs_stats[ctx][cpu], count[0]); 217 update_stats(&runtime_cacherefs_stats[ctx][cpu], count);
218 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_L1D)) 218 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_L1D))
219 update_stats(&runtime_l1_dcache_stats[ctx][cpu], count[0]); 219 update_stats(&runtime_l1_dcache_stats[ctx][cpu], count);
220 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_L1I)) 220 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_L1I))
221 update_stats(&runtime_ll_cache_stats[ctx][cpu], count[0]); 221 update_stats(&runtime_ll_cache_stats[ctx][cpu], count);
222 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_LL)) 222 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_LL))
223 update_stats(&runtime_ll_cache_stats[ctx][cpu], count[0]); 223 update_stats(&runtime_ll_cache_stats[ctx][cpu], count);
224 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_DTLB)) 224 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_DTLB))
225 update_stats(&runtime_dtlb_cache_stats[ctx][cpu], count[0]); 225 update_stats(&runtime_dtlb_cache_stats[ctx][cpu], count);
226 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_ITLB)) 226 else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_ITLB))
227 update_stats(&runtime_itlb_cache_stats[ctx][cpu], count[0]); 227 update_stats(&runtime_itlb_cache_stats[ctx][cpu], count);
228 else if (perf_stat_evsel__is(counter, SMI_NUM)) 228 else if (perf_stat_evsel__is(counter, SMI_NUM))
229 update_stats(&runtime_smi_num_stats[ctx][cpu], count[0]); 229 update_stats(&runtime_smi_num_stats[ctx][cpu], count);
230 else if (perf_stat_evsel__is(counter, APERF)) 230 else if (perf_stat_evsel__is(counter, APERF))
231 update_stats(&runtime_aperf_stats[ctx][cpu], count[0]); 231 update_stats(&runtime_aperf_stats[ctx][cpu], count);
232 232
233 if (counter->collect_stat) { 233 if (counter->collect_stat) {
234 struct saved_value *v = saved_value_lookup(counter, cpu, ctx, 234 struct saved_value *v = saved_value_lookup(counter, cpu, true);
235 true); 235 update_stats(&v->stats, count);
236 update_stats(&v->stats, count[0]);
237 } 236 }
238} 237}
239 238
@@ -627,15 +626,68 @@ static void print_smi_cost(int cpu, struct perf_evsel *evsel,
627 out->print_metric(out->ctx, NULL, "%4.0f", "SMI#", smi_num); 626 out->print_metric(out->ctx, NULL, "%4.0f", "SMI#", smi_num);
628} 627}
629 628
629static void generic_metric(const char *metric_expr,
630 struct perf_evsel **metric_events,
631 char *name,
632 const char *metric_name,
633 double avg,
634 int cpu,
635 struct perf_stat_output_ctx *out)
636{
637 print_metric_t print_metric = out->print_metric;
638 struct parse_ctx pctx;
639 double ratio;
640 int i;
641 void *ctxp = out->ctx;
642
643 expr__ctx_init(&pctx);
644 expr__add_id(&pctx, name, avg);
645 for (i = 0; metric_events[i]; i++) {
646 struct saved_value *v;
647 struct stats *stats;
648 double scale;
649
650 if (!strcmp(metric_events[i]->name, "duration_time")) {
651 stats = &walltime_nsecs_stats;
652 scale = 1e-9;
653 } else {
654 v = saved_value_lookup(metric_events[i], cpu, false);
655 if (!v)
656 break;
657 stats = &v->stats;
658 scale = 1.0;
659 }
660 expr__add_id(&pctx, metric_events[i]->name, avg_stats(stats)*scale);
661 }
662 if (!metric_events[i]) {
663 const char *p = metric_expr;
664
665 if (expr__parse(&ratio, &pctx, &p) == 0)
666 print_metric(ctxp, NULL, "%8.1f",
667 metric_name ?
668 metric_name :
669 out->force_header ? name : "",
670 ratio);
671 else
672 print_metric(ctxp, NULL, NULL,
673 out->force_header ?
674 (metric_name ? metric_name : name) : "", 0);
675 } else
676 print_metric(ctxp, NULL, NULL, "", 0);
677}
678
630void perf_stat__print_shadow_stats(struct perf_evsel *evsel, 679void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
631 double avg, int cpu, 680 double avg, int cpu,
632 struct perf_stat_output_ctx *out) 681 struct perf_stat_output_ctx *out,
682 struct rblist *metric_events)
633{ 683{
634 void *ctxp = out->ctx; 684 void *ctxp = out->ctx;
635 print_metric_t print_metric = out->print_metric; 685 print_metric_t print_metric = out->print_metric;
636 double total, ratio = 0.0, total2; 686 double total, ratio = 0.0, total2;
637 const char *color = NULL; 687 const char *color = NULL;
638 int ctx = evsel_context(evsel); 688 int ctx = evsel_context(evsel);
689 struct metric_event *me;
690 int num = 1;
639 691
640 if (perf_evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) { 692 if (perf_evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) {
641 total = avg_stats(&runtime_cycles_stats[ctx][cpu]); 693 total = avg_stats(&runtime_cycles_stats[ctx][cpu]);
@@ -819,33 +871,8 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
819 else 871 else
820 print_metric(ctxp, NULL, NULL, name, 0); 872 print_metric(ctxp, NULL, NULL, name, 0);
821 } else if (evsel->metric_expr) { 873 } else if (evsel->metric_expr) {
822 struct parse_ctx pctx; 874 generic_metric(evsel->metric_expr, evsel->metric_events, evsel->name,
823 int i; 875 evsel->metric_name, avg, cpu, out);
824
825 expr__ctx_init(&pctx);
826 expr__add_id(&pctx, evsel->name, avg);
827 for (i = 0; evsel->metric_events[i]; i++) {
828 struct saved_value *v;
829
830 v = saved_value_lookup(evsel->metric_events[i], cpu, ctx, false);
831 if (!v)
832 break;
833 expr__add_id(&pctx, evsel->metric_events[i]->name,
834 avg_stats(&v->stats));
835 }
836 if (!evsel->metric_events[i]) {
837 const char *p = evsel->metric_expr;
838
839 if (expr__parse(&ratio, &pctx, &p) == 0)
840 print_metric(ctxp, NULL, "%8.1f",
841 evsel->metric_name ?
842 evsel->metric_name :
843 out->force_header ? evsel->name : "",
844 ratio);
845 else
846 print_metric(ctxp, NULL, NULL, "", 0);
847 } else
848 print_metric(ctxp, NULL, NULL, "", 0);
849 } else if (runtime_nsecs_stats[cpu].n != 0) { 876 } else if (runtime_nsecs_stats[cpu].n != 0) {
850 char unit = 'M'; 877 char unit = 'M';
851 char unit_buf[10]; 878 char unit_buf[10];
@@ -863,6 +890,20 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
863 } else if (perf_stat_evsel__is(evsel, SMI_NUM)) { 890 } else if (perf_stat_evsel__is(evsel, SMI_NUM)) {
864 print_smi_cost(cpu, evsel, out); 891 print_smi_cost(cpu, evsel, out);
865 } else { 892 } else {
866 print_metric(ctxp, NULL, NULL, NULL, 0); 893 num = 0;
867 } 894 }
895
896 if ((me = metricgroup__lookup(metric_events, evsel, false)) != NULL) {
897 struct metric_expr *mexp;
898
899 list_for_each_entry (mexp, &me->head, nd) {
900 if (num++ > 0)
901 out->new_line(ctxp);
902 generic_metric(mexp->metric_expr, mexp->metric_events,
903 evsel->name, mexp->metric_name,
904 avg, cpu, out);
905 }
906 }
907 if (num == 0)
908 print_metric(ctxp, NULL, NULL, NULL, 0);
868} 909}
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 35e9848734d6..151e9efd7286 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <math.h> 4#include <math.h>
@@ -69,7 +70,7 @@ double rel_stddev_stats(double stddev, double avg)
69bool __perf_evsel_stat__is(struct perf_evsel *evsel, 70bool __perf_evsel_stat__is(struct perf_evsel *evsel,
70 enum perf_stat_evsel_id id) 71 enum perf_stat_evsel_id id)
71{ 72{
72 struct perf_stat_evsel *ps = evsel->priv; 73 struct perf_stat_evsel *ps = evsel->stats;
73 74
74 return ps->id == id; 75 return ps->id == id;
75} 76}
@@ -93,7 +94,7 @@ static const char *id_str[PERF_STAT_EVSEL_ID__MAX] = {
93 94
94void perf_stat_evsel_id_init(struct perf_evsel *evsel) 95void perf_stat_evsel_id_init(struct perf_evsel *evsel)
95{ 96{
96 struct perf_stat_evsel *ps = evsel->priv; 97 struct perf_stat_evsel *ps = evsel->stats;
97 int i; 98 int i;
98 99
99 /* ps->id is 0 hence PERF_STAT_EVSEL_ID__NONE by default */ 100 /* ps->id is 0 hence PERF_STAT_EVSEL_ID__NONE by default */
@@ -109,7 +110,7 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel)
109static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel) 110static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
110{ 111{
111 int i; 112 int i;
112 struct perf_stat_evsel *ps = evsel->priv; 113 struct perf_stat_evsel *ps = evsel->stats;
113 114
114 for (i = 0; i < 3; i++) 115 for (i = 0; i < 3; i++)
115 init_stats(&ps->res_stats[i]); 116 init_stats(&ps->res_stats[i]);
@@ -119,8 +120,8 @@ static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
119 120
120static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel) 121static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
121{ 122{
122 evsel->priv = zalloc(sizeof(struct perf_stat_evsel)); 123 evsel->stats = zalloc(sizeof(struct perf_stat_evsel));
123 if (evsel->priv == NULL) 124 if (evsel->stats == NULL)
124 return -ENOMEM; 125 return -ENOMEM;
125 perf_evsel__reset_stat_priv(evsel); 126 perf_evsel__reset_stat_priv(evsel);
126 return 0; 127 return 0;
@@ -128,11 +129,11 @@ static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
128 129
129static void perf_evsel__free_stat_priv(struct perf_evsel *evsel) 130static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
130{ 131{
131 struct perf_stat_evsel *ps = evsel->priv; 132 struct perf_stat_evsel *ps = evsel->stats;
132 133
133 if (ps) 134 if (ps)
134 free(ps->group_data); 135 free(ps->group_data);
135 zfree(&evsel->priv); 136 zfree(&evsel->stats);
136} 137}
137 138
138static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel, 139static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
@@ -277,7 +278,9 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel
277 perf_evsel__compute_deltas(evsel, cpu, thread, count); 278 perf_evsel__compute_deltas(evsel, cpu, thread, count);
278 perf_counts_values__scale(count, config->scale, NULL); 279 perf_counts_values__scale(count, config->scale, NULL);
279 if (config->aggr_mode == AGGR_NONE) 280 if (config->aggr_mode == AGGR_NONE)
280 perf_stat__update_shadow_stats(evsel, count->values, cpu); 281 perf_stat__update_shadow_stats(evsel, count->val, cpu);
282 if (config->aggr_mode == AGGR_THREAD)
283 perf_stat__update_shadow_stats(evsel, count->val, 0);
281 break; 284 break;
282 case AGGR_GLOBAL: 285 case AGGR_GLOBAL:
283 aggr->val += count->val; 286 aggr->val += count->val;
@@ -318,9 +321,8 @@ int perf_stat_process_counter(struct perf_stat_config *config,
318 struct perf_evsel *counter) 321 struct perf_evsel *counter)
319{ 322{
320 struct perf_counts_values *aggr = &counter->counts->aggr; 323 struct perf_counts_values *aggr = &counter->counts->aggr;
321 struct perf_stat_evsel *ps = counter->priv; 324 struct perf_stat_evsel *ps = counter->stats;
322 u64 *count = counter->counts->aggr.values; 325 u64 *count = counter->counts->aggr.values;
323 u64 val;
324 int i, ret; 326 int i, ret;
325 327
326 aggr->val = aggr->ena = aggr->run = 0; 328 aggr->val = aggr->ena = aggr->run = 0;
@@ -360,8 +362,7 @@ int perf_stat_process_counter(struct perf_stat_config *config,
360 /* 362 /*
361 * Save the full runtime - to allow normalization during printout: 363 * Save the full runtime - to allow normalization during printout:
362 */ 364 */
363 val = counter->scale * *count; 365 perf_stat__update_shadow_stats(counter, *count, 0);
364 perf_stat__update_shadow_stats(counter, &val, 0);
365 366
366 return 0; 367 return 0;
367} 368}
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index eacaf958e19d..eefca5c981fd 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_STATS_H 2#ifndef __PERF_STATS_H
2#define __PERF_STATS_H 3#define __PERF_STATS_H
3 4
@@ -82,7 +83,7 @@ typedef void (*new_line_t )(void *ctx);
82 83
83void perf_stat__init_shadow_stats(void); 84void perf_stat__init_shadow_stats(void);
84void perf_stat__reset_shadow_stats(void); 85void perf_stat__reset_shadow_stats(void);
85void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, 86void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
86 int cpu); 87 int cpu);
87struct perf_stat_output_ctx { 88struct perf_stat_output_ctx {
88 void *ctx; 89 void *ctx;
@@ -91,9 +92,11 @@ struct perf_stat_output_ctx {
91 bool force_header; 92 bool force_header;
92}; 93};
93 94
95struct rblist;
94void perf_stat__print_shadow_stats(struct perf_evsel *evsel, 96void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
95 double avg, int cpu, 97 double avg, int cpu,
96 struct perf_stat_output_ctx *out); 98 struct perf_stat_output_ctx *out,
99 struct rblist *metric_events);
97void perf_stat__collect_metric_expr(struct perf_evlist *); 100void perf_stat__collect_metric_expr(struct perf_evlist *);
98 101
99int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); 102int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index aafe908b82b5..3d1cf5bf7f18 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "debug.h" 2#include "debug.h"
2#include "util.h" 3#include "util.h"
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h
index 802d743378af..ea94d8628980 100644
--- a/tools/perf/util/strbuf.h
+++ b/tools/perf/util/strbuf.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_STRBUF_H 2#ifndef __PERF_STRBUF_H
2#define __PERF_STRBUF_H 3#define __PERF_STRBUF_H
3 4
diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index 4dc0af669a30..7f3253d44afd 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "util.h" 2#include "util.h"
2#include "string2.h" 3#include "string2.h"
3#include "strfilter.h" 4#include "strfilter.h"
diff --git a/tools/perf/util/strfilter.h b/tools/perf/util/strfilter.h
index cff5eda88728..e0c25a40f796 100644
--- a/tools/perf/util/strfilter.h
+++ b/tools/perf/util/strfilter.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_STRFILTER_H 2#ifndef __PERF_STRFILTER_H
2#define __PERF_STRFILTER_H 3#define __PERF_STRFILTER_H
3/* General purpose glob matching filter */ 4/* General purpose glob matching filter */
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index cca53b693a48..aaa08ee8c717 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "string2.h" 2#include "string2.h"
2#include <linux/kernel.h> 3#include <linux/kernel.h>
3#include <linux/string.h> 4#include <linux/string.h>
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
index 2f619681bd6a..ee14ca5451ab 100644
--- a/tools/perf/util/string2.h
+++ b/tools/perf/util/string2.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_STRING_H 2#ifndef PERF_STRING_H
2#define PERF_STRING_H 3#define PERF_STRING_H
3 4
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
index 19207e50fce5..d58f1e08b170 100644
--- a/tools/perf/util/strlist.h
+++ b/tools/perf/util/strlist.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_STRLIST_H 2#ifndef __PERF_STRLIST_H
2#define __PERF_STRLIST_H 3#define __PERF_STRLIST_H
3 4
diff --git a/tools/perf/util/svghelper.h b/tools/perf/util/svghelper.h
index 946fdf2db97c..e55338d5c3bd 100644
--- a/tools/perf/util/svghelper.h
+++ b/tools/perf/util/svghelper.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_SVGHELPER_H 2#ifndef __PERF_SVGHELPER_H
2#define __PERF_SVGHELPER_H 3#define __PERF_SVGHELPER_H
3 4
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 5c39f420111e..2de770511e70 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <fcntl.h> 2#include <fcntl.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <errno.h> 4#include <errno.h>
@@ -810,12 +811,6 @@ static u64 ref_reloc(struct kmap *kmap)
810void __weak arch__sym_update(struct symbol *s __maybe_unused, 811void __weak arch__sym_update(struct symbol *s __maybe_unused,
811 GElf_Sym *sym __maybe_unused) { } 812 GElf_Sym *sym __maybe_unused) { }
812 813
813void __weak arch__adjust_sym_map_offset(GElf_Sym *sym, GElf_Shdr *shdr,
814 struct map *map __maybe_unused)
815{
816 sym->st_value -= shdr->sh_addr - shdr->sh_offset;
817}
818
819int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, 814int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
820 struct symsrc *runtime_ss, int kmodule) 815 struct symsrc *runtime_ss, int kmodule)
821{ 816{
@@ -996,7 +991,7 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
996 991
997 /* Adjust symbol to map to file offset */ 992 /* Adjust symbol to map to file offset */
998 if (adjust_kernel_syms) 993 if (adjust_kernel_syms)
999 arch__adjust_sym_map_offset(&sym, &shdr, map); 994 sym.st_value -= shdr.sh_addr - shdr.sh_offset;
1000 995
1001 if (strcmp(section_name, 996 if (strcmp(section_name,
1002 (curr_dso->short_name + 997 (curr_dso->short_name +
diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-minimal.c
index 1a5aa35b0100..ff48d0d49584 100644
--- a/tools/perf/util/symbol-minimal.c
+++ b/tools/perf/util/symbol-minimal.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "symbol.h" 2#include "symbol.h"
2#include "util.h" 3#include "util.h"
3 4
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 5909ee4c7ade..1b67a8639dfe 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <dirent.h> 2#include <dirent.h>
2#include <errno.h> 3#include <errno.h>
3#include <stdlib.h> 4#include <stdlib.h>
@@ -45,6 +46,7 @@ struct symbol_conf symbol_conf = {
45 .show_hist_headers = true, 46 .show_hist_headers = true,
46 .symfs = "", 47 .symfs = "",
47 .event_group = true, 48 .event_group = true,
49 .inline_name = true,
48}; 50};
49 51
50static enum dso_binary_type binary_type_symtab[] = { 52static enum dso_binary_type binary_type_symtab[] = {
@@ -226,7 +228,7 @@ void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
226 struct maps *maps = &mg->maps[type]; 228 struct maps *maps = &mg->maps[type];
227 struct map *next, *curr; 229 struct map *next, *curr;
228 230
229 pthread_rwlock_wrlock(&maps->lock); 231 down_write(&maps->lock);
230 232
231 curr = maps__first(maps); 233 curr = maps__first(maps);
232 if (curr == NULL) 234 if (curr == NULL)
@@ -246,7 +248,7 @@ void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
246 curr->end = ~0ULL; 248 curr->end = ~0ULL;
247 249
248out_unlock: 250out_unlock:
249 pthread_rwlock_unlock(&maps->lock); 251 up_write(&maps->lock);
250} 252}
251 253
252struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name) 254struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
@@ -1671,7 +1673,7 @@ struct map *map_groups__find_by_name(struct map_groups *mg,
1671 struct maps *maps = &mg->maps[type]; 1673 struct maps *maps = &mg->maps[type];
1672 struct map *map; 1674 struct map *map;
1673 1675
1674 pthread_rwlock_rdlock(&maps->lock); 1676 down_read(&maps->lock);
1675 1677
1676 for (map = maps__first(maps); map; map = map__next(map)) { 1678 for (map = maps__first(maps); map; map = map__next(map)) {
1677 if (map->dso && strcmp(map->dso->short_name, name) == 0) 1679 if (map->dso && strcmp(map->dso->short_name, name) == 0)
@@ -1681,7 +1683,7 @@ struct map *map_groups__find_by_name(struct map_groups *mg,
1681 map = NULL; 1683 map = NULL;
1682 1684
1683out_unlock: 1685out_unlock:
1684 pthread_rwlock_unlock(&maps->lock); 1686 up_read(&maps->lock);
1685 return map; 1687 return map;
1686} 1688}
1687 1689
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 2bd6a1f01a1c..a4f0075b4e5c 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_SYMBOL 2#ifndef __PERF_SYMBOL
2#define __PERF_SYMBOL 1 3#define __PERF_SYMBOL 1
3 4
@@ -59,6 +60,7 @@ struct symbol {
59 u8 binding; 60 u8 binding;
60 u8 idle:1; 61 u8 idle:1;
61 u8 ignore:1; 62 u8 ignore:1;
63 u8 inlined:1;
62 u8 arch_sym; 64 u8 arch_sym;
63 char name[0]; 65 char name[0];
64}; 66};
@@ -208,6 +210,7 @@ struct addr_location {
208 struct thread *thread; 210 struct thread *thread;
209 struct map *map; 211 struct map *map;
210 struct symbol *sym; 212 struct symbol *sym;
213 const char *srcline;
211 u64 addr; 214 u64 addr;
212 char level; 215 char level;
213 u8 filtered; 216 u8 filtered;
@@ -344,9 +347,6 @@ int setup_intlist(struct intlist **list, const char *list_str,
344#ifdef HAVE_LIBELF_SUPPORT 347#ifdef HAVE_LIBELF_SUPPORT
345bool elf__needs_adjust_symbols(GElf_Ehdr ehdr); 348bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
346void arch__sym_update(struct symbol *s, GElf_Sym *sym); 349void arch__sym_update(struct symbol *s, GElf_Sym *sym);
347void arch__adjust_sym_map_offset(GElf_Sym *sym,
348 GElf_Shdr *shdr __maybe_unused,
349 struct map *map __maybe_unused);
350#endif 350#endif
351 351
352#define SYMBOL_A 0 352#define SYMBOL_A 0
diff --git a/tools/perf/util/symbol_fprintf.c b/tools/perf/util/symbol_fprintf.c
index 63694e174e5c..6dd2cb88ccbe 100644
--- a/tools/perf/util/symbol_fprintf.c
+++ b/tools/perf/util/symbol_fprintf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <elf.h> 2#include <elf.h>
2#include <inttypes.h> 3#include <inttypes.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c
index 19e5db90394c..6eea7cff3d4e 100644
--- a/tools/perf/util/syscalltbl.c
+++ b/tools/perf/util/syscalltbl.c
@@ -15,9 +15,9 @@
15 15
16#include "syscalltbl.h" 16#include "syscalltbl.h"
17#include <stdlib.h> 17#include <stdlib.h>
18#include <linux/compiler.h>
18 19
19#ifdef HAVE_SYSCALL_TABLE 20#ifdef HAVE_SYSCALL_TABLE
20#include <linux/compiler.h>
21#include <string.h> 21#include <string.h>
22#include "string2.h" 22#include "string2.h"
23#include "util.h" 23#include "util.h"
diff --git a/tools/perf/util/syscalltbl.h b/tools/perf/util/syscalltbl.h
index e9fb8786da7c..c8e7e9ce0f01 100644
--- a/tools/perf/util/syscalltbl.h
+++ b/tools/perf/util/syscalltbl.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_SYSCALLTBL_H 2#ifndef __PERF_SYSCALLTBL_H
2#define __PERF_SYSCALLTBL_H 3#define __PERF_SYSCALLTBL_H
3 4
diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h
index 7381b1ca4041..446aa7a56f25 100644
--- a/tools/perf/util/target.h
+++ b/tools/perf/util/target.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_TARGET_H 2#ifndef _PERF_TARGET_H
2#define _PERF_TARGET_H 3#define _PERF_TARGET_H
3 4
diff --git a/tools/perf/util/term.c b/tools/perf/util/term.c
index 8f254a74d97d..e7aa82c06c76 100644
--- a/tools/perf/util/term.c
+++ b/tools/perf/util/term.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "term.h" 2#include "term.h"
2#include <stdlib.h> 3#include <stdlib.h>
3#include <termios.h> 4#include <termios.h>
diff --git a/tools/perf/util/term.h b/tools/perf/util/term.h
index 2c06a61846a1..607b170a9017 100644
--- a/tools/perf/util/term.h
+++ b/tools/perf/util/term.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_TERM_H 2#ifndef __PERF_TERM_H
2#define __PERF_TERM_H 3#define __PERF_TERM_H
3 4
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index aee9a42102ba..68b65b10579b 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../perf.h" 2#include "../perf.h"
2#include <errno.h> 3#include <errno.h>
3#include <stdlib.h> 4#include <stdlib.h>
@@ -45,6 +46,8 @@ struct thread *thread__new(pid_t pid, pid_t tid)
45 thread->cpu = -1; 46 thread->cpu = -1;
46 INIT_LIST_HEAD(&thread->namespaces_list); 47 INIT_LIST_HEAD(&thread->namespaces_list);
47 INIT_LIST_HEAD(&thread->comm_list); 48 INIT_LIST_HEAD(&thread->comm_list);
49 init_rwsem(&thread->namespaces_lock);
50 init_rwsem(&thread->comm_lock);
48 51
49 comm_str = malloc(32); 52 comm_str = malloc(32);
50 if (!comm_str) 53 if (!comm_str)
@@ -83,18 +86,26 @@ void thread__delete(struct thread *thread)
83 map_groups__put(thread->mg); 86 map_groups__put(thread->mg);
84 thread->mg = NULL; 87 thread->mg = NULL;
85 } 88 }
89 down_write(&thread->namespaces_lock);
86 list_for_each_entry_safe(namespaces, tmp_namespaces, 90 list_for_each_entry_safe(namespaces, tmp_namespaces,
87 &thread->namespaces_list, list) { 91 &thread->namespaces_list, list) {
88 list_del(&namespaces->list); 92 list_del(&namespaces->list);
89 namespaces__free(namespaces); 93 namespaces__free(namespaces);
90 } 94 }
95 up_write(&thread->namespaces_lock);
96
97 down_write(&thread->comm_lock);
91 list_for_each_entry_safe(comm, tmp_comm, &thread->comm_list, list) { 98 list_for_each_entry_safe(comm, tmp_comm, &thread->comm_list, list) {
92 list_del(&comm->list); 99 list_del(&comm->list);
93 comm__free(comm); 100 comm__free(comm);
94 } 101 }
102 up_write(&thread->comm_lock);
103
95 unwind__finish_access(thread); 104 unwind__finish_access(thread);
96 nsinfo__zput(thread->nsinfo); 105 nsinfo__zput(thread->nsinfo);
97 106
107 exit_rwsem(&thread->namespaces_lock);
108 exit_rwsem(&thread->comm_lock);
98 free(thread); 109 free(thread);
99} 110}
100 111
@@ -125,8 +136,8 @@ struct namespaces *thread__namespaces(const struct thread *thread)
125 return list_first_entry(&thread->namespaces_list, struct namespaces, list); 136 return list_first_entry(&thread->namespaces_list, struct namespaces, list);
126} 137}
127 138
128int thread__set_namespaces(struct thread *thread, u64 timestamp, 139static int __thread__set_namespaces(struct thread *thread, u64 timestamp,
129 struct namespaces_event *event) 140 struct namespaces_event *event)
130{ 141{
131 struct namespaces *new, *curr = thread__namespaces(thread); 142 struct namespaces *new, *curr = thread__namespaces(thread);
132 143
@@ -149,6 +160,17 @@ int thread__set_namespaces(struct thread *thread, u64 timestamp,
149 return 0; 160 return 0;
150} 161}
151 162
163int thread__set_namespaces(struct thread *thread, u64 timestamp,
164 struct namespaces_event *event)
165{
166 int ret;
167
168 down_write(&thread->namespaces_lock);
169 ret = __thread__set_namespaces(thread, timestamp, event);
170 up_write(&thread->namespaces_lock);
171 return ret;
172}
173
152struct comm *thread__comm(const struct thread *thread) 174struct comm *thread__comm(const struct thread *thread)
153{ 175{
154 if (list_empty(&thread->comm_list)) 176 if (list_empty(&thread->comm_list))
@@ -170,8 +192,8 @@ struct comm *thread__exec_comm(const struct thread *thread)
170 return last; 192 return last;
171} 193}
172 194
173int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, 195static int ____thread__set_comm(struct thread *thread, const char *str,
174 bool exec) 196 u64 timestamp, bool exec)
175{ 197{
176 struct comm *new, *curr = thread__comm(thread); 198 struct comm *new, *curr = thread__comm(thread);
177 199
@@ -195,6 +217,17 @@ int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp,
195 return 0; 217 return 0;
196} 218}
197 219
220int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp,
221 bool exec)
222{
223 int ret;
224
225 down_write(&thread->comm_lock);
226 ret = ____thread__set_comm(thread, str, timestamp, exec);
227 up_write(&thread->comm_lock);
228 return ret;
229}
230
198int thread__set_comm_from_proc(struct thread *thread) 231int thread__set_comm_from_proc(struct thread *thread)
199{ 232{
200 char path[64]; 233 char path[64];
@@ -212,7 +245,7 @@ int thread__set_comm_from_proc(struct thread *thread)
212 return err; 245 return err;
213} 246}
214 247
215const char *thread__comm_str(const struct thread *thread) 248static const char *__thread__comm_str(const struct thread *thread)
216{ 249{
217 const struct comm *comm = thread__comm(thread); 250 const struct comm *comm = thread__comm(thread);
218 251
@@ -222,6 +255,17 @@ const char *thread__comm_str(const struct thread *thread)
222 return comm__str(comm); 255 return comm__str(comm);
223} 256}
224 257
258const char *thread__comm_str(const struct thread *thread)
259{
260 const char *str;
261
262 down_read((struct rw_semaphore *)&thread->comm_lock);
263 str = __thread__comm_str(thread);
264 up_read((struct rw_semaphore *)&thread->comm_lock);
265
266 return str;
267}
268
225/* CHECKME: it should probably better return the max comm len from its comm list */ 269/* CHECKME: it should probably better return the max comm len from its comm list */
226int thread__comm_len(struct thread *thread) 270int thread__comm_len(struct thread *thread)
227{ 271{
@@ -264,7 +308,7 @@ static int __thread__prepare_access(struct thread *thread)
264 struct maps *maps = &thread->mg->maps[i]; 308 struct maps *maps = &thread->mg->maps[i];
265 struct map *map; 309 struct map *map;
266 310
267 pthread_rwlock_rdlock(&maps->lock); 311 down_read(&maps->lock);
268 312
269 for (map = maps__first(maps); map; map = map__next(map)) { 313 for (map = maps__first(maps); map; map = map__next(map)) {
270 err = unwind__prepare_access(thread, map, &initialized); 314 err = unwind__prepare_access(thread, map, &initialized);
@@ -272,7 +316,7 @@ static int __thread__prepare_access(struct thread *thread)
272 break; 316 break;
273 } 317 }
274 318
275 pthread_rwlock_unlock(&maps->lock); 319 up_read(&maps->lock);
276 } 320 }
277 321
278 return err; 322 return err;
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index cb1a5dd5c2b9..40cfa36c022a 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_THREAD_H 2#ifndef __PERF_THREAD_H
2#define __PERF_THREAD_H 3#define __PERF_THREAD_H
3 4
@@ -9,6 +10,7 @@
9#include "symbol.h" 10#include "symbol.h"
10#include <strlist.h> 11#include <strlist.h>
11#include <intlist.h> 12#include <intlist.h>
13#include "rwsem.h"
12 14
13struct thread_stack; 15struct thread_stack;
14struct unwind_libunwind_ops; 16struct unwind_libunwind_ops;
@@ -29,7 +31,9 @@ struct thread {
29 int comm_len; 31 int comm_len;
30 bool dead; /* if set thread has exited */ 32 bool dead; /* if set thread has exited */
31 struct list_head namespaces_list; 33 struct list_head namespaces_list;
34 struct rw_semaphore namespaces_lock;
32 struct list_head comm_list; 35 struct list_head comm_list;
36 struct rw_semaphore comm_lock;
33 u64 db_id; 37 u64 db_id;
34 38
35 void *priv; 39 void *priv;
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 63ead7b06324..be0d5a736dea 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <dirent.h> 2#include <dirent.h>
2#include <errno.h> 3#include <errno.h>
3#include <limits.h> 4#include <limits.h>
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index bd34d7a0b9fa..f15803985435 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_THREAD_MAP_H 2#ifndef __PERF_THREAD_MAP_H
2#define __PERF_THREAD_MAP_H 3#define __PERF_THREAD_MAP_H
3 4
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 5b5d0214debd..81927d027417 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <string.h> 3#include <string.h>
3#include <sys/time.h> 4#include <sys/time.h>
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index 8656be08513b..15b475c50ccf 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TIME_UTILS_H_ 2#ifndef _TIME_UTILS_H_
2#define _TIME_UTILS_H_ 3#define _TIME_UTILS_H_
3 4
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index d549e50db397..2532b558099b 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_TOOL_H 2#ifndef __PERF_TOOL_H
2#define __PERF_TOOL_H 3#define __PERF_TOOL_H
3 4
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index 9bdfb78a9a35..9892323cdd7c 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_TOP_H 2#ifndef __PERF_TOP_H
2#define __PERF_TOP_H 1 3#define __PERF_TOP_H 1
3 4
@@ -37,6 +38,7 @@ struct perf_top {
37 int sym_pcnt_filter; 38 int sym_pcnt_filter;
38 const char *sym_filter; 39 const char *sym_filter;
39 float min_percent; 40 float min_percent;
41 unsigned int nr_threads_synthesize;
40}; 42};
41 43
42#define CONSOLE_CLEAR "" 44#define CONSOLE_CLEAR ""
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index e7d60d05596d..d7f2113462fb 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -28,7 +28,6 @@
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <sys/wait.h> 30#include <sys/wait.h>
31#include <pthread.h>
32#include <fcntl.h> 31#include <fcntl.h>
33#include <unistd.h> 32#include <unistd.h>
34#include <errno.h> 33#include <errno.h>
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 8a9a677f7576..40b425949aa3 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -27,7 +27,6 @@
27#include <sys/stat.h> 27#include <sys/stat.h>
28#include <sys/wait.h> 28#include <sys/wait.h>
29#include <sys/mman.h> 29#include <sys/mman.h>
30#include <pthread.h>
31#include <fcntl.h> 30#include <fcntl.h>
32#include <unistd.h> 31#include <unistd.h>
33#include <errno.h> 32#include <errno.h>
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
index c330780674fc..16a776371d03 100644
--- a/tools/perf/util/trace-event.c
+++ b/tools/perf/util/trace-event.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1 2
2#include <stdio.h> 3#include <stdio.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 1fbc044f9eb0..dcbdb53dc702 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_UTIL_TRACE_EVENT_H 2#ifndef _PERF_UTIL_TRACE_EVENT_H
2#define _PERF_UTIL_TRACE_EVENT_H 3#define _PERF_UTIL_TRACE_EVENT_H
3 4
diff --git a/tools/perf/util/trigger.h b/tools/perf/util/trigger.h
index e97d7016d771..370138e7e35c 100644
--- a/tools/perf/util/trigger.h
+++ b/tools/perf/util/trigger.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TRIGGER_H_ 2#ifndef __TRIGGER_H_
2#define __TRIGGER_H_ 1 3#define __TRIGGER_H_ 1
3 4
diff --git a/tools/perf/util/tsc.c b/tools/perf/util/tsc.c
index 1b741646eed0..bfa782421cbd 100644
--- a/tools/perf/util/tsc.c
+++ b/tools/perf/util/tsc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <linux/types.h> 3#include <linux/types.h>
3 4
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index d5b11e2b85e0..e0c3af34ac8d 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_TSC_H 2#ifndef __PERF_TSC_H
2#define __PERF_TSC_H 3#define __PERF_TSC_H
3 4
diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c
index 4767ec2c5ef6..a46762aec4c9 100644
--- a/tools/perf/util/units.c
+++ b/tools/perf/util/units.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "units.h" 2#include "units.h"
2#include <inttypes.h> 3#include <inttypes.h>
3#include <limits.h> 4#include <limits.h>
diff --git a/tools/perf/util/units.h b/tools/perf/util/units.h
index f02c87317150..99263b6a23f7 100644
--- a/tools/perf/util/units.h
+++ b/tools/perf/util/units.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERF_UNIT_H 2#ifndef PERF_UNIT_H
2#define PERF_UNIT_H 3#define PERF_UNIT_H
3 4
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index 7755a5e0fe5e..1e9c974faf67 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/compiler.h> 2#include <linux/compiler.h>
2#include <elfutils/libdw.h> 3#include <elfutils/libdw.h>
3#include <elfutils/libdwfl.h> 4#include <elfutils/libdwfl.h>
diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h
index 4a2b269a7b3b..0cbd2650e280 100644
--- a/tools/perf/util/unwind-libdw.h
+++ b/tools/perf/util/unwind-libdw.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_UNWIND_LIBDW_H 2#ifndef __PERF_UNWIND_LIBDW_H
2#define __PERF_UNWIND_LIBDW_H 3#define __PERF_UNWIND_LIBDW_H
3 4
diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 672c2ada9357..7a42f703e858 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Post mortem Dwarf CFI based unwinding on top of regs and stack dumps. 3 * Post mortem Dwarf CFI based unwinding on top of regs and stack dumps.
3 * 4 *
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 8aef572d0889..647a1e6b4c7b 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "unwind.h" 2#include "unwind.h"
2#include "thread.h" 3#include "thread.h"
3#include "session.h" 4#include "session.h"
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index bfbdcc6198c9..8a44a1569a21 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __UNWIND_H 2#ifndef __UNWIND_H
2#define __UNWIND_H 3#define __UNWIND_H
3 4
diff --git a/tools/perf/util/usage.c b/tools/perf/util/usage.c
index 6cc9d9888ce0..070d25ceea6a 100644
--- a/tools/perf/util/usage.c
+++ b/tools/perf/util/usage.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * usage.c 3 * usage.c
3 * 4 *
diff --git a/tools/perf/util/util-cxx.h b/tools/perf/util/util-cxx.h
index 0e0e019c9f34..80a99e458d4e 100644
--- a/tools/perf/util/util-cxx.h
+++ b/tools/perf/util/util-cxx.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Support C++ source use utilities defined in util.h 3 * Support C++ source use utilities defined in util.h
3 */ 4 */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 4c360daa4e24..a789f952b3e9 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "../perf.h" 2#include "../perf.h"
2#include "util.h" 3#include "util.h"
3#include "debug.h" 4#include "debug.h"
@@ -6,6 +7,7 @@
6#include <sys/stat.h> 7#include <sys/stat.h>
7#include <sys/utsname.h> 8#include <sys/utsname.h>
8#include <dirent.h> 9#include <dirent.h>
10#include <fcntl.h>
9#include <inttypes.h> 11#include <inttypes.h>
10#include <signal.h> 12#include <signal.h>
11#include <stdio.h> 13#include <stdio.h>
@@ -22,6 +24,19 @@
22/* 24/*
23 * XXX We need to find a better place for these things... 25 * XXX We need to find a better place for these things...
24 */ 26 */
27
28bool perf_singlethreaded = true;
29
30void perf_set_singlethreaded(void)
31{
32 perf_singlethreaded = true;
33}
34
35void perf_set_multithreaded(void)
36{
37 perf_singlethreaded = false;
38}
39
25unsigned int page_size; 40unsigned int page_size;
26int cacheline_size; 41int cacheline_size;
27 42
@@ -174,7 +189,7 @@ out:
174 return err; 189 return err;
175} 190}
176 191
177int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size) 192static int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size)
178{ 193{
179 void *ptr; 194 void *ptr;
180 loff_t pgoff; 195 loff_t pgoff;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index b136c271125f..01434509c2e9 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef GIT_COMPAT_UTIL_H 2#ifndef GIT_COMPAT_UTIL_H
2#define GIT_COMPAT_UTIL_H 3#define GIT_COMPAT_UTIL_H
3 4
@@ -5,7 +6,6 @@
5/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ 6/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
6#define _DEFAULT_SOURCE 1 7#define _DEFAULT_SOURCE 1
7 8
8#include <fcntl.h>
9#include <stdbool.h> 9#include <stdbool.h>
10#include <stddef.h> 10#include <stddef.h>
11#include <stdlib.h> 11#include <stdlib.h>
@@ -35,7 +35,6 @@ bool lsdir_no_dot_filter(const char *name, struct dirent *d);
35int copyfile(const char *from, const char *to); 35int copyfile(const char *from, const char *to);
36int copyfile_mode(const char *from, const char *to, mode_t mode); 36int copyfile_mode(const char *from, const char *to, mode_t mode);
37int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi); 37int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi);
38int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
39 38
40ssize_t readn(int fd, void *buf, size_t n); 39ssize_t readn(int fd, void *buf, size_t n);
41ssize_t writen(int fd, const void *buf, size_t n); 40ssize_t writen(int fd, const void *buf, size_t n);
@@ -64,4 +63,9 @@ int sched_getcpu(void);
64int setns(int fd, int nstype); 63int setns(int fd, int nstype);
65#endif 64#endif
66 65
66extern bool perf_singlethreaded;
67
68void perf_set_singlethreaded(void);
69void perf_set_multithreaded(void);
70
67#endif /* GIT_COMPAT_UTIL_H */ 71#endif /* GIT_COMPAT_UTIL_H */
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index 8a32bb0095e5..4b7a303e4ba8 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <inttypes.h> 2#include <inttypes.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/perf/util/values.h b/tools/perf/util/values.h
index 808ff9c73bf5..8c41f22f42cf 100644
--- a/tools/perf/util/values.h
+++ b/tools/perf/util/values.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_VALUES_H 2#ifndef __PERF_VALUES_H
2#define __PERF_VALUES_H 3#define __PERF_VALUES_H
3 4
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c
index d3c39eec89a8..0acb1ec0e2f0 100644
--- a/tools/perf/util/vdso.c
+++ b/tools/perf/util/vdso.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <stdio.h> 4#include <stdio.h>
@@ -319,7 +320,7 @@ struct dso *machine__findnew_vdso(struct machine *machine,
319 struct vdso_info *vdso_info; 320 struct vdso_info *vdso_info;
320 struct dso *dso = NULL; 321 struct dso *dso = NULL;
321 322
322 pthread_rwlock_wrlock(&machine->dsos.lock); 323 down_write(&machine->dsos.lock);
323 if (!machine->vdso_info) 324 if (!machine->vdso_info)
324 machine->vdso_info = vdso_info__new(); 325 machine->vdso_info = vdso_info__new();
325 326
@@ -347,7 +348,7 @@ struct dso *machine__findnew_vdso(struct machine *machine,
347 348
348out_unlock: 349out_unlock:
349 dso__get(dso); 350 dso__get(dso);
350 pthread_rwlock_unlock(&machine->dsos.lock); 351 up_write(&machine->dsos.lock);
351 return dso; 352 return dso;
352} 353}
353 354
diff --git a/tools/perf/util/vdso.h b/tools/perf/util/vdso.h
index cdc4fabfc212..bc74ace603ae 100644
--- a/tools/perf/util/vdso.h
+++ b/tools/perf/util/vdso.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __PERF_VDSO__ 2#ifndef __PERF_VDSO__
2#define __PERF_VDSO__ 3#define __PERF_VDSO__
3 4
diff --git a/tools/perf/util/xyarray.c b/tools/perf/util/xyarray.c
index c8f415d9877b..dc95154f5646 100644
--- a/tools/perf/util/xyarray.c
+++ b/tools/perf/util/xyarray.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include "xyarray.h" 2#include "xyarray.h"
2#include "util.h" 3#include "util.h"
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/perf/util/xyarray.h b/tools/perf/util/xyarray.h
index 4ba726c90870..7ffe562e7ae7 100644
--- a/tools/perf/util/xyarray.h
+++ b/tools/perf/util/xyarray.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PERF_XYARRAY_H_ 2#ifndef _PERF_XYARRAY_H_
2#define _PERF_XYARRAY_H_ 1 3#define _PERF_XYARRAY_H_ 1
3 4
@@ -23,12 +24,12 @@ static inline void *xyarray__entry(struct xyarray *xy, int x, int y)
23 24
24static inline int xyarray__max_y(struct xyarray *xy) 25static inline int xyarray__max_y(struct xyarray *xy)
25{ 26{
26 return xy->max_x; 27 return xy->max_y;
27} 28}
28 29
29static inline int xyarray__max_x(struct xyarray *xy) 30static inline int xyarray__max_x(struct xyarray *xy)
30{ 31{
31 return xy->max_y; 32 return xy->max_x;
32} 33}
33 34
34#endif /* _PERF_XYARRAY_H_ */ 35#endif /* _PERF_XYARRAY_H_ */
diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c
index 1329d843eb7b..a725b958cf31 100644
--- a/tools/perf/util/zlib.c
+++ b/tools/perf/util/zlib.c
@@ -1,3 +1,5 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <fcntl.h>
1#include <stdio.h> 3#include <stdio.h>
2#include <unistd.h> 4#include <unistd.h>
3#include <sys/stat.h> 5#include <sys/stat.h>
diff --git a/tools/power/acpi/tools/acpidump/Makefile b/tools/power/acpi/tools/acpidump/Makefile
index f7c7af1f9258..b436f8675f6a 100644
--- a/tools/power/acpi/tools/acpidump/Makefile
+++ b/tools/power/acpi/tools/acpidump/Makefile
@@ -39,6 +39,7 @@ TOOL_OBJS = \
39 utnonansi.o\ 39 utnonansi.o\
40 utprint.o\ 40 utprint.o\
41 utstring.o\ 41 utstring.o\
42 utstrsuppt.o\
42 utstrtoul64.o\ 43 utstrtoul64.o\
43 utxferror.o\ 44 utxferror.o\
44 oslinuxtbl.o\ 45 oslinuxtbl.o\
diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c
index 60df1fbd4a77..0634449156d8 100644
--- a/tools/power/acpi/tools/acpidump/apdump.c
+++ b/tools/power/acpi/tools/acpidump/apdump.c
@@ -287,8 +287,7 @@ int ap_dump_table_by_address(char *ascii_address)
287 287
288 /* Convert argument to an integer physical address */ 288 /* Convert argument to an integer physical address */
289 289
290 status = acpi_ut_strtoul64(ascii_address, ACPI_STRTOUL_64BIT, 290 status = acpi_ut_strtoul64(ascii_address, &long_address);
291 &long_address);
292 if (ACPI_FAILURE(status)) { 291 if (ACPI_FAILURE(status)) {
293 fprintf(stderr, "%s: Could not convert to a physical address\n", 292 fprintf(stderr, "%s: Could not convert to a physical address\n",
294 ascii_address); 293 ascii_address);
diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
index 943b6b614683..22c3b4ee1617 100644
--- a/tools/power/acpi/tools/acpidump/apmain.c
+++ b/tools/power/acpi/tools/acpidump/apmain.c
@@ -208,9 +208,7 @@ static int ap_do_options(int argc, char **argv)
208 case 'r': /* Dump tables from specified RSDP */ 208 case 'r': /* Dump tables from specified RSDP */
209 209
210 status = 210 status =
211 acpi_ut_strtoul64(acpi_gbl_optarg, 211 acpi_ut_strtoul64(acpi_gbl_optarg, &gbl_rsdp_base);
212 ACPI_STRTOUL_64BIT,
213 &gbl_rsdp_base);
214 if (ACPI_FAILURE(status)) { 212 if (ACPI_FAILURE(status)) {
215 fprintf(stderr, 213 fprintf(stderr,
216 "%s: Could not convert to a physical address\n", 214 "%s: Could not convert to a physical address\n",
diff --git a/tools/power/cpupower/.gitignore b/tools/power/cpupower/.gitignore
index d42073f12609..1f9977cc609c 100644
--- a/tools/power/cpupower/.gitignore
+++ b/tools/power/cpupower/.gitignore
@@ -1,7 +1,6 @@
1.libs 1.libs
2libcpupower.so 2libcpupower.so
3libcpupower.so.0 3libcpupower.so.*
4libcpupower.so.0.0.0
5build/ccdv 4build/ccdv
6cpufreq-info 5cpufreq-info
7cpufreq-set 6cpufreq-set
diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile
index 4c5a481a850c..1dd5f4fcffd5 100644
--- a/tools/power/cpupower/Makefile
+++ b/tools/power/cpupower/Makefile
@@ -26,10 +26,12 @@ endif
26 26
27ifneq ($(OUTPUT),) 27ifneq ($(OUTPUT),)
28# check that the output directory actually exists 28# check that the output directory actually exists
29OUTDIR := $(realpath $(OUTPUT)) 29OUTDIR := $(shell cd $(OUTPUT) && pwd)
30$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) 30$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
31endif 31endif
32 32
33include ../../scripts/Makefile.arch
34
33# --- CONFIGURATION BEGIN --- 35# --- CONFIGURATION BEGIN ---
34 36
35# Set the following to `true' to make a unstripped, unoptimized 37# Set the following to `true' to make a unstripped, unoptimized
@@ -79,7 +81,11 @@ bindir ?= /usr/bin
79sbindir ?= /usr/sbin 81sbindir ?= /usr/sbin
80mandir ?= /usr/man 82mandir ?= /usr/man
81includedir ?= /usr/include 83includedir ?= /usr/include
84ifeq ($(IS_64_BIT), 1)
85libdir ?= /usr/lib64
86else
82libdir ?= /usr/lib 87libdir ?= /usr/lib
88endif
83localedir ?= /usr/share/locale 89localedir ?= /usr/share/locale
84docdir ?= /usr/share/doc/packages/cpupower 90docdir ?= /usr/share/doc/packages/cpupower
85confdir ?= /etc/ 91confdir ?= /etc/
diff --git a/tools/power/cpupower/bench/Makefile b/tools/power/cpupower/bench/Makefile
index 3e59f1aa3947..d79ab161cc75 100644
--- a/tools/power/cpupower/bench/Makefile
+++ b/tools/power/cpupower/bench/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1OUTPUT := ./ 2OUTPUT := ./
2ifeq ("$(origin O)", "command line") 3ifeq ("$(origin O)", "command line")
3ifneq ($(O),) 4ifneq ($(O),)
diff --git a/tools/power/cpupower/debug/i386/Makefile b/tools/power/cpupower/debug/i386/Makefile
index c05cc0ac80c7..b3f771039b17 100644
--- a/tools/power/cpupower/debug/i386/Makefile
+++ b/tools/power/cpupower/debug/i386/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1OUTPUT=./ 2OUTPUT=./
2ifeq ("$(origin O)", "command line") 3ifeq ("$(origin O)", "command line")
3 OUTPUT := $(O)/ 4 OUTPUT := $(O)/
diff --git a/tools/power/cpupower/debug/kernel/Makefile b/tools/power/cpupower/debug/kernel/Makefile
index a8a6f8eec5c2..c23e5a6ceb7e 100644
--- a/tools/power/cpupower/debug/kernel/Makefile
+++ b/tools/power/cpupower/debug/kernel/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1obj-m := 2obj-m :=
2 3
3KDIR := /lib/modules/$(shell uname -r)/build 4KDIR := /lib/modules/$(shell uname -r)/build
diff --git a/tools/power/cpupower/debug/x86_64/Makefile b/tools/power/cpupower/debug/x86_64/Makefile
index 1c5214526716..59af84b8ef45 100644
--- a/tools/power/cpupower/debug/x86_64/Makefile
+++ b/tools/power/cpupower/debug/x86_64/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1OUTPUT=./ 2OUTPUT=./
2ifeq ("$(origin O)", "command line") 3ifeq ("$(origin O)", "command line")
3 OUTPUT := $(O)/ 4 OUTPUT := $(O)/
diff --git a/tools/power/cpupower/lib/cpuidle.h b/tools/power/cpupower/lib/cpuidle.h
index 04eb3cfa6e42..2e10fead2e1e 100644
--- a/tools/power/cpupower/lib/cpuidle.h
+++ b/tools/power/cpupower/lib/cpuidle.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __CPUPOWER_CPUIDLE_H__ 2#ifndef __CPUPOWER_CPUIDLE_H__
2#define __CPUPOWER_CPUIDLE_H__ 3#define __CPUPOWER_CPUIDLE_H__
3 4
diff --git a/tools/power/cpupower/lib/cpupower.h b/tools/power/cpupower/lib/cpupower.h
index fa031fcc7710..e4e4292eacec 100644
--- a/tools/power/cpupower/lib/cpupower.h
+++ b/tools/power/cpupower/lib/cpupower.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __CPUPOWER_CPUPOWER_H__ 2#ifndef __CPUPOWER_CPUPOWER_H__
2#define __CPUPOWER_CPUPOWER_H__ 3#define __CPUPOWER_CPUPOWER_H__
3 4
diff --git a/tools/power/cpupower/lib/cpupower_intern.h b/tools/power/cpupower/lib/cpupower_intern.h
index f8ec4009621c..92affdfbe417 100644
--- a/tools/power/cpupower/lib/cpupower_intern.h
+++ b/tools/power/cpupower/lib/cpupower_intern.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#define PATH_TO_CPU "/sys/devices/system/cpu/" 2#define PATH_TO_CPU "/sys/devices/system/cpu/"
2#define MAX_LINE_LEN 4096 3#define MAX_LINE_LEN 4096
3#define SYSFS_PATH_MAX 255 4#define SYSFS_PATH_MAX 255
diff --git a/tools/power/cpupower/utils/builtin.h b/tools/power/cpupower/utils/builtin.h
index 2284c8ea4e2a..f7065ae60a14 100644
--- a/tools/power/cpupower/utils/builtin.h
+++ b/tools/power/cpupower/utils/builtin.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef BUILTIN_H 2#ifndef BUILTIN_H
2#define BUILTIN_H 3#define BUILTIN_H
3 4
diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c
index 3e701f0e9c14..df43cd45d810 100644
--- a/tools/power/cpupower/utils/cpufreq-info.c
+++ b/tools/power/cpupower/utils/cpufreq-info.c
@@ -93,8 +93,6 @@ static void print_speed(unsigned long speed)
93 if (speed > 1000000) 93 if (speed > 1000000)
94 printf("%u.%06u GHz", ((unsigned int) speed/1000000), 94 printf("%u.%06u GHz", ((unsigned int) speed/1000000),
95 ((unsigned int) speed%1000000)); 95 ((unsigned int) speed%1000000));
96 else if (speed > 100000)
97 printf("%u MHz", (unsigned int) speed);
98 else if (speed > 1000) 96 else if (speed > 1000)
99 printf("%u.%03u MHz", ((unsigned int) speed/1000), 97 printf("%u.%03u MHz", ((unsigned int) speed/1000),
100 (unsigned int) (speed%1000)); 98 (unsigned int) (speed%1000));
diff --git a/tools/power/cpupower/utils/cpuidle-set.c b/tools/power/cpupower/utils/cpuidle-set.c
index 691c24d50ef4..569f268f4c7f 100644
--- a/tools/power/cpupower/utils/cpuidle-set.c
+++ b/tools/power/cpupower/utils/cpuidle-set.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <unistd.h> 2#include <unistd.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <errno.h> 4#include <errno.h>
diff --git a/tools/power/cpupower/utils/helpers/amd.c b/tools/power/cpupower/utils/helpers/amd.c
index 5fd5c5b8c7b8..bb41cdd0df6b 100644
--- a/tools/power/cpupower/utils/helpers/amd.c
+++ b/tools/power/cpupower/utils/helpers/amd.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#if defined(__i386__) || defined(__x86_64__) 2#if defined(__i386__) || defined(__x86_64__)
2#include <unistd.h> 3#include <unistd.h>
3#include <errno.h> 4#include <errno.h>
diff --git a/tools/power/cpupower/utils/helpers/bitmask.c b/tools/power/cpupower/utils/helpers/bitmask.c
index 5c074c60f904..6c7932f5bd66 100644
--- a/tools/power/cpupower/utils/helpers/bitmask.c
+++ b/tools/power/cpupower/utils/helpers/bitmask.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/power/cpupower/utils/helpers/bitmask.h b/tools/power/cpupower/utils/helpers/bitmask.h
index eb289df41053..b98d93a44e1b 100644
--- a/tools/power/cpupower/utils/helpers/bitmask.h
+++ b/tools/power/cpupower/utils/helpers/bitmask.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __CPUPOWER_BITMASK__ 2#ifndef __CPUPOWER_BITMASK__
2#define __CPUPOWER_BITMASK__ 3#define __CPUPOWER_BITMASK__
3 4
diff --git a/tools/power/cpupower/utils/helpers/cpuid.c b/tools/power/cpupower/utils/helpers/cpuid.c
index 32d37c9be791..732b0b41ba26 100644
--- a/tools/power/cpupower/utils/helpers/cpuid.c
+++ b/tools/power/cpupower/utils/helpers/cpuid.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <errno.h> 3#include <errno.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
index a5e7ddf19dbd..80fdf55f414d 100644
--- a/tools/power/cpupower/utils/helpers/misc.c
+++ b/tools/power/cpupower/utils/helpers/misc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#if defined(__i386__) || defined(__x86_64__) 2#if defined(__i386__) || defined(__x86_64__)
2 3
3#include "helpers/helpers.h" 4#include "helpers/helpers.h"
diff --git a/tools/power/cpupower/utils/helpers/msr.c b/tools/power/cpupower/utils/helpers/msr.c
index 31a4b24a8bc6..ab9950748838 100644
--- a/tools/power/cpupower/utils/helpers/msr.c
+++ b/tools/power/cpupower/utils/helpers/msr.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#if defined(__i386__) || defined(__x86_64__) 2#if defined(__i386__) || defined(__x86_64__)
2 3
3#include <fcntl.h> 4#include <fcntl.h>
diff --git a/tools/power/cpupower/utils/helpers/pci.c b/tools/power/cpupower/utils/helpers/pci.c
index 8b278983cfc5..113f3da2a203 100644
--- a/tools/power/cpupower/utils/helpers/pci.c
+++ b/tools/power/cpupower/utils/helpers/pci.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#if defined(__i386__) || defined(__x86_64__) 2#if defined(__i386__) || defined(__x86_64__)
2 3
3#include <helpers/helpers.h> 4#include <helpers/helpers.h>
diff --git a/tools/power/cpupower/utils/helpers/sysfs.h b/tools/power/cpupower/utils/helpers/sysfs.h
index d28f11fedbda..0f0b9ad97e4a 100644
--- a/tools/power/cpupower/utils/helpers/sysfs.h
+++ b/tools/power/cpupower/utils/helpers/sysfs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __CPUPOWER_HELPERS_SYSFS_H__ 2#ifndef __CPUPOWER_HELPERS_SYSFS_H__
2#define __CPUPOWER_HELPERS_SYSFS_H__ 3#define __CPUPOWER_HELPERS_SYSFS_H__
3 4
diff --git a/tools/power/cpupower/utils/version-gen.sh b/tools/power/cpupower/utils/version-gen.sh
index 5ec41c556992..c70de2eabffb 100755
--- a/tools/power/cpupower/utils/version-gen.sh
+++ b/tools/power/cpupower/utils/version-gen.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# Script which prints out the version to use for building cpupowerutils. 4# Script which prints out the version to use for building cpupowerutils.
4# Must be called from tools/power/cpupower/ 5# Must be called from tools/power/cpupower/
diff --git a/tools/power/pm-graph/Makefile b/tools/power/pm-graph/Makefile
index 32f40eacdafe..4e1e999e7b05 100644
--- a/tools/power/pm-graph/Makefile
+++ b/tools/power/pm-graph/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1PREFIX ?= /usr 2PREFIX ?= /usr
2DESTDIR ?= 3DESTDIR ?=
3 4
diff --git a/tools/power/x86/turbostat/Makefile b/tools/power/x86/turbostat/Makefile
index 8792ad8dbf83..a9bc914a8fe8 100644
--- a/tools/power/x86/turbostat/Makefile
+++ b/tools/power/x86/turbostat/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CC = $(CROSS_COMPILE)gcc 2CC = $(CROSS_COMPILE)gcc
2BUILD_OUTPUT := $(CURDIR) 3BUILD_OUTPUT := $(CURDIR)
3PREFIX ?= /usr 4PREFIX ?= /usr
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 0dafba2c1e7d..bd9c6b31a504 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -92,7 +92,6 @@ unsigned int do_ring_perf_limit_reasons;
92unsigned int crystal_hz; 92unsigned int crystal_hz;
93unsigned long long tsc_hz; 93unsigned long long tsc_hz;
94int base_cpu; 94int base_cpu;
95int do_migrate;
96double discover_bclk(unsigned int family, unsigned int model); 95double discover_bclk(unsigned int family, unsigned int model);
97unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ 96unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */
98 /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ 97 /* IA32_HWP_REQUEST, IA32_HWP_STATUS */
@@ -303,9 +302,6 @@ int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg
303 302
304int cpu_migrate(int cpu) 303int cpu_migrate(int cpu)
305{ 304{
306 if (!do_migrate)
307 return 0;
308
309 CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); 305 CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set);
310 CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); 306 CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set);
311 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) 307 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1)
@@ -5007,7 +5003,6 @@ void cmdline(int argc, char **argv)
5007 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help 5003 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help
5008 {"Joules", no_argument, 0, 'J'}, 5004 {"Joules", no_argument, 0, 'J'},
5009 {"list", no_argument, 0, 'l'}, 5005 {"list", no_argument, 0, 'l'},
5010 {"migrate", no_argument, 0, 'm'},
5011 {"out", required_argument, 0, 'o'}, 5006 {"out", required_argument, 0, 'o'},
5012 {"quiet", no_argument, 0, 'q'}, 5007 {"quiet", no_argument, 0, 'q'},
5013 {"show", required_argument, 0, 's'}, 5008 {"show", required_argument, 0, 's'},
@@ -5019,7 +5014,7 @@ void cmdline(int argc, char **argv)
5019 5014
5020 progname = argv[0]; 5015 progname = argv[0];
5021 5016
5022 while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:Jmo:qST:v", 5017 while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v",
5023 long_options, &option_index)) != -1) { 5018 long_options, &option_index)) != -1) {
5024 switch (opt) { 5019 switch (opt) {
5025 case 'a': 5020 case 'a':
@@ -5062,9 +5057,6 @@ void cmdline(int argc, char **argv)
5062 list_header_only++; 5057 list_header_only++;
5063 quiet++; 5058 quiet++;
5064 break; 5059 break;
5065 case 'm':
5066 do_migrate = 1;
5067 break;
5068 case 'o': 5060 case 'o':
5069 outf = fopen_or_die(optarg, "w"); 5061 outf = fopen_or_die(optarg, "w");
5070 break; 5062 break;
diff --git a/tools/power/x86/x86_energy_perf_policy/Makefile b/tools/power/x86/x86_energy_perf_policy/Makefile
index a711eec0c895..2447b1bbaacf 100644
--- a/tools/power/x86/x86_energy_perf_policy/Makefile
+++ b/tools/power/x86/x86_energy_perf_policy/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CC = $(CROSS_COMPILE)gcc 2CC = $(CROSS_COMPILE)gcc
2BUILD_OUTPUT := $(CURDIR) 3BUILD_OUTPUT := $(CURDIR)
3PREFIX := /usr 4PREFIX := /usr
diff --git a/tools/scripts/Makefile.arch b/tools/scripts/Makefile.arch
index ad85b921a607..78d90a249e88 100644
--- a/tools/scripts/Makefile.arch
+++ b/tools/scripts/Makefile.arch
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1HOSTARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ 2HOSTARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
2 -e s/sun4u/sparc/ -e s/sparc64/sparc/ \ 3 -e s/sun4u/sparc/ -e s/sparc64/sparc/ \
3 -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \ 4 -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \
diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
index 9dc8f078a83c..3fab179b1aba 100644
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -1,7 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0
1ifneq ($(O),) 2ifneq ($(O),)
2ifeq ($(origin O), command line) 3ifeq ($(origin O), command line)
3 ABSOLUTE_O := $(realpath $(O)) 4 dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
4 dummy := $(if $(ABSOLUTE_O),,$(error O=$(O) does not exist)) 5 ABSOLUTE_O := $(shell cd $(O) ; pwd)
5 OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/) 6 OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
6 COMMAND_O := O=$(ABSOLUTE_O) 7 COMMAND_O := O=$(ABSOLUTE_O)
7ifeq ($(objtree),) 8ifeq ($(objtree),)
@@ -12,7 +13,7 @@ endif
12 13
13# check that the output directory actually exists 14# check that the output directory actually exists
14ifneq ($(OUTPUT),) 15ifneq ($(OUTPUT),)
15OUTDIR := $(realpath $(OUTPUT)) 16OUTDIR := $(shell cd $(OUTPUT) && pwd)
16$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) 17$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
17endif 18endif
18 19
diff --git a/tools/spi/spidev_fdx.c b/tools/spi/spidev_fdx.c
index 0ea3e51292fc..7d2a867cd4ae 100644
--- a/tools/spi/spidev_fdx.c
+++ b/tools/spi/spidev_fdx.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/testing/fault-injection/failcmd.sh b/tools/testing/fault-injection/failcmd.sh
index 78a9ed7fecdb..29a6c63c5a15 100644
--- a/tools/testing/fault-injection/failcmd.sh
+++ b/tools/testing/fault-injection/failcmd.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# NAME 4# NAME
4# failcmd.sh - run a command with injecting slab/page allocation failures 5# failcmd.sh - run a command with injecting slab/page allocation failures
diff --git a/tools/testing/ktest/compare-ktest-sample.pl b/tools/testing/ktest/compare-ktest-sample.pl
index a373a5bfff68..4118eb4a842d 100755
--- a/tools/testing/ktest/compare-ktest-sample.pl
+++ b/tools/testing/ktest/compare-ktest-sample.pl
@@ -1,4 +1,5 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2# SPDX-License-Identifier: GPL-2.0
2 3
3open (IN,"ktest.pl"); 4open (IN,"ktest.pl");
4while (<IN>) { 5while (<IN>) {
diff --git a/tools/testing/nvdimm/Kbuild b/tools/testing/nvdimm/Kbuild
index d870520da68b..db33b28c5ef3 100644
--- a/tools/testing/nvdimm/Kbuild
+++ b/tools/testing/nvdimm/Kbuild
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ldflags-y += --wrap=ioremap_wc 2ldflags-y += --wrap=ioremap_wc
2ldflags-y += --wrap=memremap 3ldflags-y += --wrap=memremap
3ldflags-y += --wrap=devm_ioremap_nocache 4ldflags-y += --wrap=devm_ioremap_nocache
@@ -69,6 +70,7 @@ libnvdimm-y += $(NVDIMM_SRC)/region_devs.o
69libnvdimm-y += $(NVDIMM_SRC)/region.o 70libnvdimm-y += $(NVDIMM_SRC)/region.o
70libnvdimm-y += $(NVDIMM_SRC)/namespace_devs.o 71libnvdimm-y += $(NVDIMM_SRC)/namespace_devs.o
71libnvdimm-y += $(NVDIMM_SRC)/label.o 72libnvdimm-y += $(NVDIMM_SRC)/label.o
73libnvdimm-y += $(NVDIMM_SRC)/badrange.o
72libnvdimm-$(CONFIG_ND_CLAIM) += $(NVDIMM_SRC)/claim.o 74libnvdimm-$(CONFIG_ND_CLAIM) += $(NVDIMM_SRC)/claim.o
73libnvdimm-$(CONFIG_BTT) += $(NVDIMM_SRC)/btt_devs.o 75libnvdimm-$(CONFIG_BTT) += $(NVDIMM_SRC)/btt_devs.o
74libnvdimm-$(CONFIG_NVDIMM_PFN) += $(NVDIMM_SRC)/pfn_devs.o 76libnvdimm-$(CONFIG_NVDIMM_PFN) += $(NVDIMM_SRC)/pfn_devs.o
diff --git a/tools/testing/nvdimm/Makefile b/tools/testing/nvdimm/Makefile
index 3dfe024b4e7e..c37a6a0bde28 100644
--- a/tools/testing/nvdimm/Makefile
+++ b/tools/testing/nvdimm/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1KDIR ?= ../../../ 2KDIR ?= ../../../
2 3
3default: 4default:
diff --git a/tools/testing/nvdimm/config_check.c b/tools/testing/nvdimm/config_check.c
index 7dc5a0af9b54..cac891028cd1 100644
--- a/tools/testing/nvdimm/config_check.c
+++ b/tools/testing/nvdimm/config_check.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <linux/bug.h> 2#include <linux/bug.h>
2 3
3void check(void) 4void check(void)
diff --git a/tools/testing/nvdimm/test/Kbuild b/tools/testing/nvdimm/test/Kbuild
index d32f25bba42a..fb3c3d7cdb9b 100644
--- a/tools/testing/nvdimm/test/Kbuild
+++ b/tools/testing/nvdimm/test/Kbuild
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ccflags-y := -I$(src)/../../../../drivers/nvdimm/ 2ccflags-y := -I$(src)/../../../../drivers/nvdimm/
2ccflags-y += -I$(src)/../../../../drivers/acpi/nfit/ 3ccflags-y += -I$(src)/../../../../drivers/acpi/nfit/
3 4
diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c
index d20791c3f499..7217b2b953b5 100644
--- a/tools/testing/nvdimm/test/nfit.c
+++ b/tools/testing/nvdimm/test/nfit.c
@@ -168,8 +168,12 @@ struct nfit_test {
168 spinlock_t lock; 168 spinlock_t lock;
169 } ars_state; 169 } ars_state;
170 struct device *dimm_dev[NUM_DCR]; 170 struct device *dimm_dev[NUM_DCR];
171 struct badrange badrange;
172 struct work_struct work;
171}; 173};
172 174
175static struct workqueue_struct *nfit_wq;
176
173static struct nfit_test *to_nfit_test(struct device *dev) 177static struct nfit_test *to_nfit_test(struct device *dev)
174{ 178{
175 struct platform_device *pdev = to_platform_device(dev); 179 struct platform_device *pdev = to_platform_device(dev);
@@ -234,48 +238,68 @@ static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd,
234 return rc; 238 return rc;
235} 239}
236 240
237#define NFIT_TEST_ARS_RECORDS 4
238#define NFIT_TEST_CLEAR_ERR_UNIT 256 241#define NFIT_TEST_CLEAR_ERR_UNIT 256
239 242
240static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 243static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd,
241 unsigned int buf_len) 244 unsigned int buf_len)
242{ 245{
246 int ars_recs;
247
243 if (buf_len < sizeof(*nd_cmd)) 248 if (buf_len < sizeof(*nd_cmd))
244 return -EINVAL; 249 return -EINVAL;
245 250
251 /* for testing, only store up to n records that fit within 4k */
252 ars_recs = SZ_4K / sizeof(struct nd_ars_record);
253
246 nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 254 nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status)
247 + NFIT_TEST_ARS_RECORDS * sizeof(struct nd_ars_record); 255 + ars_recs * sizeof(struct nd_ars_record);
248 nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 256 nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16;
249 nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 257 nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT;
250 258
251 return 0; 259 return 0;
252} 260}
253 261
254/* 262static void post_ars_status(struct ars_state *ars_state,
255 * Initialize the ars_state to return an ars_result 1 second in the future with 263 struct badrange *badrange, u64 addr, u64 len)
256 * a 4K error range in the middle of the requested address range.
257 */
258static void post_ars_status(struct ars_state *ars_state, u64 addr, u64 len)
259{ 264{
260 struct nd_cmd_ars_status *ars_status; 265 struct nd_cmd_ars_status *ars_status;
261 struct nd_ars_record *ars_record; 266 struct nd_ars_record *ars_record;
267 struct badrange_entry *be;
268 u64 end = addr + len - 1;
269 int i = 0;
262 270
263 ars_state->deadline = jiffies + 1*HZ; 271 ars_state->deadline = jiffies + 1*HZ;
264 ars_status = ars_state->ars_status; 272 ars_status = ars_state->ars_status;
265 ars_status->status = 0; 273 ars_status->status = 0;
266 ars_status->out_length = sizeof(struct nd_cmd_ars_status)
267 + sizeof(struct nd_ars_record);
268 ars_status->address = addr; 274 ars_status->address = addr;
269 ars_status->length = len; 275 ars_status->length = len;
270 ars_status->type = ND_ARS_PERSISTENT; 276 ars_status->type = ND_ARS_PERSISTENT;
271 ars_status->num_records = 1; 277
272 ars_record = &ars_status->records[0]; 278 spin_lock(&badrange->lock);
273 ars_record->handle = 0; 279 list_for_each_entry(be, &badrange->list, list) {
274 ars_record->err_address = addr + len / 2; 280 u64 be_end = be->start + be->length - 1;
275 ars_record->length = SZ_4K; 281 u64 rstart, rend;
282
283 /* skip entries outside the range */
284 if (be_end < addr || be->start > end)
285 continue;
286
287 rstart = (be->start < addr) ? addr : be->start;
288 rend = (be_end < end) ? be_end : end;
289 ars_record = &ars_status->records[i];
290 ars_record->handle = 0;
291 ars_record->err_address = rstart;
292 ars_record->length = rend - rstart + 1;
293 i++;
294 }
295 spin_unlock(&badrange->lock);
296 ars_status->num_records = i;
297 ars_status->out_length = sizeof(struct nd_cmd_ars_status)
298 + i * sizeof(struct nd_ars_record);
276} 299}
277 300
278static int nfit_test_cmd_ars_start(struct ars_state *ars_state, 301static int nfit_test_cmd_ars_start(struct nfit_test *t,
302 struct ars_state *ars_state,
279 struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 303 struct nd_cmd_ars_start *ars_start, unsigned int buf_len,
280 int *cmd_rc) 304 int *cmd_rc)
281{ 305{
@@ -289,7 +313,7 @@ static int nfit_test_cmd_ars_start(struct ars_state *ars_state,
289 } else { 313 } else {
290 ars_start->status = 0; 314 ars_start->status = 0;
291 ars_start->scrub_time = 1; 315 ars_start->scrub_time = 1;
292 post_ars_status(ars_state, ars_start->address, 316 post_ars_status(ars_state, &t->badrange, ars_start->address,
293 ars_start->length); 317 ars_start->length);
294 *cmd_rc = 0; 318 *cmd_rc = 0;
295 } 319 }
@@ -320,7 +344,8 @@ static int nfit_test_cmd_ars_status(struct ars_state *ars_state,
320 return 0; 344 return 0;
321} 345}
322 346
323static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err, 347static int nfit_test_cmd_clear_error(struct nfit_test *t,
348 struct nd_cmd_clear_error *clear_err,
324 unsigned int buf_len, int *cmd_rc) 349 unsigned int buf_len, int *cmd_rc)
325{ 350{
326 const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 351 const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1;
@@ -330,18 +355,91 @@ static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err,
330 if ((clear_err->address & mask) || (clear_err->length & mask)) 355 if ((clear_err->address & mask) || (clear_err->length & mask))
331 return -EINVAL; 356 return -EINVAL;
332 357
333 /* 358 badrange_forget(&t->badrange, clear_err->address, clear_err->length);
334 * Report 'all clear' success for all commands even though a new
335 * scrub will find errors again. This is enough to have the
336 * error removed from the 'badblocks' tracking in the pmem
337 * driver.
338 */
339 clear_err->status = 0; 359 clear_err->status = 0;
340 clear_err->cleared = clear_err->length; 360 clear_err->cleared = clear_err->length;
341 *cmd_rc = 0; 361 *cmd_rc = 0;
342 return 0; 362 return 0;
343} 363}
344 364
365struct region_search_spa {
366 u64 addr;
367 struct nd_region *region;
368};
369
370static int is_region_device(struct device *dev)
371{
372 return !strncmp(dev->kobj.name, "region", 6);
373}
374
375static int nfit_test_search_region_spa(struct device *dev, void *data)
376{
377 struct region_search_spa *ctx = data;
378 struct nd_region *nd_region;
379 resource_size_t ndr_end;
380
381 if (!is_region_device(dev))
382 return 0;
383
384 nd_region = to_nd_region(dev);
385 ndr_end = nd_region->ndr_start + nd_region->ndr_size;
386
387 if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) {
388 ctx->region = nd_region;
389 return 1;
390 }
391
392 return 0;
393}
394
395static int nfit_test_search_spa(struct nvdimm_bus *bus,
396 struct nd_cmd_translate_spa *spa)
397{
398 int ret;
399 struct nd_region *nd_region = NULL;
400 struct nvdimm *nvdimm = NULL;
401 struct nd_mapping *nd_mapping = NULL;
402 struct region_search_spa ctx = {
403 .addr = spa->spa,
404 .region = NULL,
405 };
406 u64 dpa;
407
408 ret = device_for_each_child(&bus->dev, &ctx,
409 nfit_test_search_region_spa);
410
411 if (!ret)
412 return -ENODEV;
413
414 nd_region = ctx.region;
415
416 dpa = ctx.addr - nd_region->ndr_start;
417
418 /*
419 * last dimm is selected for test
420 */
421 nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1];
422 nvdimm = nd_mapping->nvdimm;
423
424 spa->devices[0].nfit_device_handle = handle[nvdimm->id];
425 spa->num_nvdimms = 1;
426 spa->devices[0].dpa = dpa;
427
428 return 0;
429}
430
431static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus,
432 struct nd_cmd_translate_spa *spa, unsigned int buf_len)
433{
434 if (buf_len < spa->translate_length)
435 return -EINVAL;
436
437 if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms)
438 spa->status = 2;
439
440 return 0;
441}
442
345static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len) 443static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len)
346{ 444{
347 static const struct nd_smart_payload smart_data = { 445 static const struct nd_smart_payload smart_data = {
@@ -378,6 +476,93 @@ static int nfit_test_cmd_smart_threshold(struct nd_cmd_smart_threshold *smart_t,
378 return 0; 476 return 0;
379} 477}
380 478
479static void uc_error_notify(struct work_struct *work)
480{
481 struct nfit_test *t = container_of(work, typeof(*t), work);
482
483 __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR);
484}
485
486static int nfit_test_cmd_ars_error_inject(struct nfit_test *t,
487 struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len)
488{
489 int rc;
490
491 if (buf_len != sizeof(*err_inj)) {
492 rc = -EINVAL;
493 goto err;
494 }
495
496 if (err_inj->err_inj_spa_range_length <= 0) {
497 rc = -EINVAL;
498 goto err;
499 }
500
501 rc = badrange_add(&t->badrange, err_inj->err_inj_spa_range_base,
502 err_inj->err_inj_spa_range_length);
503 if (rc < 0)
504 goto err;
505
506 if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY))
507 queue_work(nfit_wq, &t->work);
508
509 err_inj->status = 0;
510 return 0;
511
512err:
513 err_inj->status = NFIT_ARS_INJECT_INVALID;
514 return rc;
515}
516
517static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t,
518 struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len)
519{
520 int rc;
521
522 if (buf_len != sizeof(*err_clr)) {
523 rc = -EINVAL;
524 goto err;
525 }
526
527 if (err_clr->err_inj_clr_spa_range_length <= 0) {
528 rc = -EINVAL;
529 goto err;
530 }
531
532 badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base,
533 err_clr->err_inj_clr_spa_range_length);
534
535 err_clr->status = 0;
536 return 0;
537
538err:
539 err_clr->status = NFIT_ARS_INJECT_INVALID;
540 return rc;
541}
542
543static int nfit_test_cmd_ars_inject_status(struct nfit_test *t,
544 struct nd_cmd_ars_err_inj_stat *err_stat,
545 unsigned int buf_len)
546{
547 struct badrange_entry *be;
548 int max = SZ_4K / sizeof(struct nd_error_stat_query_record);
549 int i = 0;
550
551 err_stat->status = 0;
552 spin_lock(&t->badrange.lock);
553 list_for_each_entry(be, &t->badrange.list, list) {
554 err_stat->record[i].err_inj_stat_spa_range_base = be->start;
555 err_stat->record[i].err_inj_stat_spa_range_length = be->length;
556 i++;
557 if (i > max)
558 break;
559 }
560 spin_unlock(&t->badrange.lock);
561 err_stat->inj_err_rec_count = i;
562
563 return 0;
564}
565
381static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 566static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
382 struct nvdimm *nvdimm, unsigned int cmd, void *buf, 567 struct nvdimm *nvdimm, unsigned int cmd, void *buf,
383 unsigned int buf_len, int *cmd_rc) 568 unsigned int buf_len, int *cmd_rc)
@@ -449,6 +634,38 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
449 } 634 }
450 } else { 635 } else {
451 struct ars_state *ars_state = &t->ars_state; 636 struct ars_state *ars_state = &t->ars_state;
637 struct nd_cmd_pkg *call_pkg = buf;
638
639 if (!nd_desc)
640 return -ENOTTY;
641
642 if (cmd == ND_CMD_CALL) {
643 func = call_pkg->nd_command;
644
645 buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out;
646 buf = (void *) call_pkg->nd_payload;
647
648 switch (func) {
649 case NFIT_CMD_TRANSLATE_SPA:
650 rc = nfit_test_cmd_translate_spa(
651 acpi_desc->nvdimm_bus, buf, buf_len);
652 return rc;
653 case NFIT_CMD_ARS_INJECT_SET:
654 rc = nfit_test_cmd_ars_error_inject(t, buf,
655 buf_len);
656 return rc;
657 case NFIT_CMD_ARS_INJECT_CLEAR:
658 rc = nfit_test_cmd_ars_inject_clear(t, buf,
659 buf_len);
660 return rc;
661 case NFIT_CMD_ARS_INJECT_GET:
662 rc = nfit_test_cmd_ars_inject_status(t, buf,
663 buf_len);
664 return rc;
665 default:
666 return -ENOTTY;
667 }
668 }
452 669
453 if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 670 if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask))
454 return -ENOTTY; 671 return -ENOTTY;
@@ -458,15 +675,15 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
458 rc = nfit_test_cmd_ars_cap(buf, buf_len); 675 rc = nfit_test_cmd_ars_cap(buf, buf_len);
459 break; 676 break;
460 case ND_CMD_ARS_START: 677 case ND_CMD_ARS_START:
461 rc = nfit_test_cmd_ars_start(ars_state, buf, buf_len, 678 rc = nfit_test_cmd_ars_start(t, ars_state, buf,
462 cmd_rc); 679 buf_len, cmd_rc);
463 break; 680 break;
464 case ND_CMD_ARS_STATUS: 681 case ND_CMD_ARS_STATUS:
465 rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 682 rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len,
466 cmd_rc); 683 cmd_rc);
467 break; 684 break;
468 case ND_CMD_CLEAR_ERROR: 685 case ND_CMD_CLEAR_ERROR:
469 rc = nfit_test_cmd_clear_error(buf, buf_len, cmd_rc); 686 rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc);
470 break; 687 break;
471 default: 688 default:
472 return -ENOTTY; 689 return -ENOTTY;
@@ -566,10 +783,9 @@ static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr)
566 783
567static int ars_state_init(struct device *dev, struct ars_state *ars_state) 784static int ars_state_init(struct device *dev, struct ars_state *ars_state)
568{ 785{
786 /* for testing, only store up to n records that fit within 4k */
569 ars_state->ars_status = devm_kzalloc(dev, 787 ars_state->ars_status = devm_kzalloc(dev,
570 sizeof(struct nd_cmd_ars_status) 788 sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL);
571 + sizeof(struct nd_ars_record) * NFIT_TEST_ARS_RECORDS,
572 GFP_KERNEL);
573 if (!ars_state->ars_status) 789 if (!ars_state->ars_status)
574 return -ENOMEM; 790 return -ENOMEM;
575 spin_lock_init(&ars_state->lock); 791 spin_lock_init(&ars_state->lock);
@@ -1419,7 +1635,8 @@ static void nfit_test0_setup(struct nfit_test *t)
1419 + i * sizeof(u64); 1635 + i * sizeof(u64);
1420 } 1636 }
1421 1637
1422 post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA0_SIZE); 1638 post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0],
1639 SPA0_SIZE);
1423 1640
1424 acpi_desc = &t->acpi_desc; 1641 acpi_desc = &t->acpi_desc;
1425 set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1642 set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en);
@@ -1430,7 +1647,12 @@ static void nfit_test0_setup(struct nfit_test *t)
1430 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1647 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
1431 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1648 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
1432 set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 1649 set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
1650 set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en);
1433 set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 1651 set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en);
1652 set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en);
1653 set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_nfit_cmd_force_en);
1654 set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_nfit_cmd_force_en);
1655 set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_nfit_cmd_force_en);
1434} 1656}
1435 1657
1436static void nfit_test1_setup(struct nfit_test *t) 1658static void nfit_test1_setup(struct nfit_test *t)
@@ -1520,16 +1742,14 @@ static void nfit_test1_setup(struct nfit_test *t)
1520 dcr->code = NFIT_FIC_BYTE; 1742 dcr->code = NFIT_FIC_BYTE;
1521 dcr->windows = 0; 1743 dcr->windows = 0;
1522 1744
1523 post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA2_SIZE); 1745 post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0],
1746 SPA2_SIZE);
1524 1747
1525 acpi_desc = &t->acpi_desc; 1748 acpi_desc = &t->acpi_desc;
1526 set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1749 set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en);
1527 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1750 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
1528 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1751 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
1529 set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 1752 set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
1530 set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en);
1531 set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
1532 set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
1533} 1753}
1534 1754
1535static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 1755static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa,
@@ -1592,6 +1812,7 @@ static int nfit_ctl_test(struct device *dev)
1592 unsigned long mask, cmd_size, offset; 1812 unsigned long mask, cmd_size, offset;
1593 union { 1813 union {
1594 struct nd_cmd_get_config_size cfg_size; 1814 struct nd_cmd_get_config_size cfg_size;
1815 struct nd_cmd_clear_error clear_err;
1595 struct nd_cmd_ars_status ars_stat; 1816 struct nd_cmd_ars_status ars_stat;
1596 struct nd_cmd_ars_cap ars_cap; 1817 struct nd_cmd_ars_cap ars_cap;
1597 char buf[sizeof(struct nd_cmd_ars_status) 1818 char buf[sizeof(struct nd_cmd_ars_status)
@@ -1616,10 +1837,15 @@ static int nfit_ctl_test(struct device *dev)
1616 .cmd_mask = 1UL << ND_CMD_ARS_CAP 1837 .cmd_mask = 1UL << ND_CMD_ARS_CAP
1617 | 1UL << ND_CMD_ARS_START 1838 | 1UL << ND_CMD_ARS_START
1618 | 1UL << ND_CMD_ARS_STATUS 1839 | 1UL << ND_CMD_ARS_STATUS
1619 | 1UL << ND_CMD_CLEAR_ERROR, 1840 | 1UL << ND_CMD_CLEAR_ERROR
1841 | 1UL << ND_CMD_CALL,
1620 .module = THIS_MODULE, 1842 .module = THIS_MODULE,
1621 .provider_name = "ACPI.NFIT", 1843 .provider_name = "ACPI.NFIT",
1622 .ndctl = acpi_nfit_ctl, 1844 .ndctl = acpi_nfit_ctl,
1845 .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA
1846 | 1UL << NFIT_CMD_ARS_INJECT_SET
1847 | 1UL << NFIT_CMD_ARS_INJECT_CLEAR
1848 | 1UL << NFIT_CMD_ARS_INJECT_GET,
1623 }, 1849 },
1624 .dev = &adev->dev, 1850 .dev = &adev->dev,
1625 }; 1851 };
@@ -1770,6 +1996,23 @@ static int nfit_ctl_test(struct device *dev)
1770 return -EIO; 1996 return -EIO;
1771 } 1997 }
1772 1998
1999 /* test clear error */
2000 cmd_size = sizeof(cmds.clear_err);
2001 cmds.clear_err = (struct nd_cmd_clear_error) {
2002 .length = 512,
2003 .cleared = 512,
2004 };
2005 rc = setup_result(cmds.buf, cmd_size);
2006 if (rc)
2007 return rc;
2008 rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR,
2009 cmds.buf, cmd_size, &cmd_rc);
2010 if (rc < 0 || cmd_rc) {
2011 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
2012 __func__, __LINE__, rc, cmd_rc);
2013 return -EIO;
2014 }
2015
1773 return 0; 2016 return 0;
1774} 2017}
1775 2018
@@ -1918,6 +2161,10 @@ static __init int nfit_test_init(void)
1918 2161
1919 nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 2162 nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm);
1920 2163
2164 nfit_wq = create_singlethread_workqueue("nfit");
2165 if (!nfit_wq)
2166 return -ENOMEM;
2167
1921 nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2168 nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm");
1922 if (IS_ERR(nfit_test_dimm)) { 2169 if (IS_ERR(nfit_test_dimm)) {
1923 rc = PTR_ERR(nfit_test_dimm); 2170 rc = PTR_ERR(nfit_test_dimm);
@@ -1934,6 +2181,7 @@ static __init int nfit_test_init(void)
1934 goto err_register; 2181 goto err_register;
1935 } 2182 }
1936 INIT_LIST_HEAD(&nfit_test->resources); 2183 INIT_LIST_HEAD(&nfit_test->resources);
2184 badrange_init(&nfit_test->badrange);
1937 switch (i) { 2185 switch (i) {
1938 case 0: 2186 case 0:
1939 nfit_test->num_pm = NUM_PM; 2187 nfit_test->num_pm = NUM_PM;
@@ -1969,6 +2217,7 @@ static __init int nfit_test_init(void)
1969 goto err_register; 2217 goto err_register;
1970 2218
1971 instances[i] = nfit_test; 2219 instances[i] = nfit_test;
2220 INIT_WORK(&nfit_test->work, uc_error_notify);
1972 } 2221 }
1973 2222
1974 rc = platform_driver_register(&nfit_test_driver); 2223 rc = platform_driver_register(&nfit_test_driver);
@@ -1977,6 +2226,7 @@ static __init int nfit_test_init(void)
1977 return 0; 2226 return 0;
1978 2227
1979 err_register: 2228 err_register:
2229 destroy_workqueue(nfit_wq);
1980 for (i = 0; i < NUM_NFITS; i++) 2230 for (i = 0; i < NUM_NFITS; i++)
1981 if (instances[i]) 2231 if (instances[i])
1982 platform_device_unregister(&instances[i]->pdev); 2232 platform_device_unregister(&instances[i]->pdev);
@@ -1992,6 +2242,8 @@ static __exit void nfit_test_exit(void)
1992{ 2242{
1993 int i; 2243 int i;
1994 2244
2245 flush_workqueue(nfit_wq);
2246 destroy_workqueue(nfit_wq);
1995 for (i = 0; i < NUM_NFITS; i++) 2247 for (i = 0; i < NUM_NFITS; i++)
1996 platform_device_unregister(&instances[i]->pdev); 2248 platform_device_unregister(&instances[i]->pdev);
1997 platform_driver_unregister(&nfit_test_driver); 2249 platform_driver_unregister(&nfit_test_driver);
diff --git a/tools/testing/nvdimm/test/nfit_test.h b/tools/testing/nvdimm/test/nfit_test.h
index d3d63dd5ed38..113b44675a71 100644
--- a/tools/testing/nvdimm/test/nfit_test.h
+++ b/tools/testing/nvdimm/test/nfit_test.h
@@ -32,6 +32,58 @@ struct nfit_test_resource {
32 void *buf; 32 void *buf;
33}; 33};
34 34
35#define ND_TRANSLATE_SPA_STATUS_INVALID_SPA 2
36#define NFIT_ARS_INJECT_INVALID 2
37
38enum err_inj_options {
39 ND_ARS_ERR_INJ_OPT_NOTIFY = 0,
40};
41
42/* nfit commands */
43enum nfit_cmd_num {
44 NFIT_CMD_TRANSLATE_SPA = 5,
45 NFIT_CMD_ARS_INJECT_SET = 7,
46 NFIT_CMD_ARS_INJECT_CLEAR = 8,
47 NFIT_CMD_ARS_INJECT_GET = 9,
48};
49
50struct nd_cmd_translate_spa {
51 __u64 spa;
52 __u32 status;
53 __u8 flags;
54 __u8 _reserved[3];
55 __u64 translate_length;
56 __u32 num_nvdimms;
57 struct nd_nvdimm_device {
58 __u32 nfit_device_handle;
59 __u32 _reserved;
60 __u64 dpa;
61 } __packed devices[0];
62
63} __packed;
64
65struct nd_cmd_ars_err_inj {
66 __u64 err_inj_spa_range_base;
67 __u64 err_inj_spa_range_length;
68 __u8 err_inj_options;
69 __u32 status;
70} __packed;
71
72struct nd_cmd_ars_err_inj_clr {
73 __u64 err_inj_clr_spa_range_base;
74 __u64 err_inj_clr_spa_range_length;
75 __u32 status;
76} __packed;
77
78struct nd_cmd_ars_err_inj_stat {
79 __u32 status;
80 __u32 inj_err_rec_count;
81 struct nd_error_stat_query_record {
82 __u64 err_inj_stat_spa_range_base;
83 __u64 err_inj_stat_spa_range_length;
84 } __packed record[0];
85} __packed;
86
35union acpi_object; 87union acpi_object;
36typedef void *acpi_handle; 88typedef void *acpi_handle;
37 89
diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree/Makefile
index 6a9480c03cbd..fa7ee369b3c9 100644
--- a/tools/testing/radix-tree/Makefile
+++ b/tools/testing/radix-tree/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1 2
2CFLAGS += -I. -I../../include -g -O2 -Wall -D_LGPL_SOURCE -fsanitize=address 3CFLAGS += -I. -I../../include -g -O2 -Wall -D_LGPL_SOURCE -fsanitize=address
3LDFLAGS += -fsanitize=address 4LDFLAGS += -fsanitize=address
diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c
index cf48c8473f48..6903ccf35595 100644
--- a/tools/testing/radix-tree/linux.c
+++ b/tools/testing/radix-tree/linux.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <string.h> 3#include <string.h>
3#include <malloc.h> 4#include <malloc.h>
diff --git a/tools/testing/radix-tree/linux/gfp.h b/tools/testing/radix-tree/linux/gfp.h
index 39a0dcb9475a..e9fff59dfd8a 100644
--- a/tools/testing/radix-tree/linux/gfp.h
+++ b/tools/testing/radix-tree/linux/gfp.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _GFP_H 2#ifndef _GFP_H
2#define _GFP_H 3#define _GFP_H
3 4
diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h
index b21a77fddcf7..c3bc3f364f68 100644
--- a/tools/testing/radix-tree/linux/kernel.h
+++ b/tools/testing/radix-tree/linux/kernel.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _KERNEL_H 2#ifndef _KERNEL_H
2#define _KERNEL_H 3#define _KERNEL_H
3 4
diff --git a/tools/testing/radix-tree/linux/percpu.h b/tools/testing/radix-tree/linux/percpu.h
index 3ea01a1a88c2..b2403aa743b2 100644
--- a/tools/testing/radix-tree/linux/percpu.h
+++ b/tools/testing/radix-tree/linux/percpu.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#define DECLARE_PER_CPU(type, val) extern type val 2#define DECLARE_PER_CPU(type, val) extern type val
2#define DEFINE_PER_CPU(type, val) type val 3#define DEFINE_PER_CPU(type, val) type val
3 4
diff --git a/tools/testing/radix-tree/linux/preempt.h b/tools/testing/radix-tree/linux/preempt.h
index 35c5ac81529f..edb10302b903 100644
--- a/tools/testing/radix-tree/linux/preempt.h
+++ b/tools/testing/radix-tree/linux/preempt.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __LINUX_PREEMPT_H 2#ifndef __LINUX_PREEMPT_H
2#define __LINUX_PREEMPT_H 3#define __LINUX_PREEMPT_H
3 4
diff --git a/tools/testing/radix-tree/linux/radix-tree.h b/tools/testing/radix-tree/linux/radix-tree.h
index bf1bb231f9b5..24f13d27a8da 100644
--- a/tools/testing/radix-tree/linux/radix-tree.h
+++ b/tools/testing/radix-tree/linux/radix-tree.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _TEST_RADIX_TREE_H 2#ifndef _TEST_RADIX_TREE_H
2#define _TEST_RADIX_TREE_H 3#define _TEST_RADIX_TREE_H
3 4
diff --git a/tools/testing/radix-tree/linux/rcupdate.h b/tools/testing/radix-tree/linux/rcupdate.h
index f7129ea2a899..73ed33658203 100644
--- a/tools/testing/radix-tree/linux/rcupdate.h
+++ b/tools/testing/radix-tree/linux/rcupdate.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _RCUPDATE_H 2#ifndef _RCUPDATE_H
2#define _RCUPDATE_H 3#define _RCUPDATE_H
3 4
diff --git a/tools/testing/radix-tree/linux/slab.h b/tools/testing/radix-tree/linux/slab.h
index e40337f41a38..979baeec7e70 100644
--- a/tools/testing/radix-tree/linux/slab.h
+++ b/tools/testing/radix-tree/linux/slab.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef SLAB_H 2#ifndef SLAB_H
2#define SLAB_H 3#define SLAB_H
3 4
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c
index bc9a78449572..257f3f8aacaa 100644
--- a/tools/testing/radix-tree/main.c
+++ b/tools/testing/radix-tree/main.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c
index 06c71178d07d..59245b3d587c 100644
--- a/tools/testing/radix-tree/multiorder.c
+++ b/tools/testing/radix-tree/multiorder.c
@@ -618,7 +618,7 @@ static void multiorder_account(void)
618 __radix_tree_insert(&tree, 1 << 5, 5, (void *)0x12); 618 __radix_tree_insert(&tree, 1 << 5, 5, (void *)0x12);
619 __radix_tree_lookup(&tree, 1 << 5, &node, &slot); 619 __radix_tree_lookup(&tree, 1 << 5, &node, &slot);
620 assert(node->count == node->exceptional * 2); 620 assert(node->count == node->exceptional * 2);
621 __radix_tree_replace(&tree, node, slot, NULL, NULL, NULL); 621 __radix_tree_replace(&tree, node, slot, NULL, NULL);
622 assert(node->exceptional == 0); 622 assert(node->exceptional == 0);
623 623
624 item_kill_tree(&tree); 624 item_kill_tree(&tree);
diff --git a/tools/testing/radix-tree/regression.h b/tools/testing/radix-tree/regression.h
index e018c4816688..3c8a1584e9ee 100644
--- a/tools/testing/radix-tree/regression.h
+++ b/tools/testing/radix-tree/regression.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __REGRESSION_H__ 2#ifndef __REGRESSION_H__
2#define __REGRESSION_H__ 3#define __REGRESSION_H__
3 4
diff --git a/tools/testing/radix-tree/regression1.c b/tools/testing/radix-tree/regression1.c
index bf97742fc18c..0aece092f40e 100644
--- a/tools/testing/radix-tree/regression1.c
+++ b/tools/testing/radix-tree/regression1.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Regression1 3 * Regression1
3 * Description: 4 * Description:
diff --git a/tools/testing/radix-tree/regression2.c b/tools/testing/radix-tree/regression2.c
index 42dd2a33ed24..424b91c77831 100644
--- a/tools/testing/radix-tree/regression2.c
+++ b/tools/testing/radix-tree/regression2.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Regression2 3 * Regression2
3 * Description: 4 * Description:
diff --git a/tools/testing/radix-tree/regression3.c b/tools/testing/radix-tree/regression3.c
index 670c3d2ae7b1..ace2543c3eda 100644
--- a/tools/testing/radix-tree/regression3.c
+++ b/tools/testing/radix-tree/regression3.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Regression3 3 * Regression3
3 * Description: 4 * Description:
diff --git a/tools/testing/radix-tree/tag_check.c b/tools/testing/radix-tree/tag_check.c
index 36dcf7d6945d..543181e4847b 100644
--- a/tools/testing/radix-tree/tag_check.c
+++ b/tools/testing/radix-tree/tag_check.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <assert.h> 3#include <assert.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/testing/radix-tree/test.c b/tools/testing/radix-tree/test.c
index 1a257d738a1e..5978ab1f403d 100644
--- a/tools/testing/radix-tree/test.c
+++ b/tools/testing/radix-tree/test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <assert.h> 3#include <assert.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h
index 0f8220cc6166..d9c031dbeb1a 100644
--- a/tools/testing/radix-tree/test.h
+++ b/tools/testing/radix-tree/test.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <linux/gfp.h> 2#include <linux/gfp.h>
2#include <linux/types.h> 3#include <linux/types.h>
3#include <linux/radix-tree.h> 4#include <linux/radix-tree.h>
diff --git a/tools/testing/scatterlist/Makefile b/tools/testing/scatterlist/Makefile
new file mode 100644
index 000000000000..933c3a6e4d77
--- /dev/null
+++ b/tools/testing/scatterlist/Makefile
@@ -0,0 +1,30 @@
1CFLAGS += -I. -I../../include -g -O2 -Wall -fsanitize=address
2LDFLAGS += -fsanitize=address -fsanitize=undefined
3TARGETS = main
4OFILES = main.o scatterlist.o
5
6ifeq ($(BUILD), 32)
7 CFLAGS += -m32
8 LDFLAGS += -m32
9endif
10
11targets: include $(TARGETS)
12
13main: $(OFILES)
14
15clean:
16 $(RM) $(TARGETS) $(OFILES) scatterlist.c linux/scatterlist.h linux/highmem.h linux/kmemleak.h asm/io.h
17 @rmdir asm
18
19scatterlist.c: ../../../lib/scatterlist.c
20 @sed -e 's/^static //' -e 's/__always_inline //' -e 's/inline //' < $< > $@
21
22.PHONY: include
23
24include: ../../../include/linux/scatterlist.h
25 @mkdir -p linux
26 @mkdir -p asm
27 @touch asm/io.h
28 @touch linux/highmem.h
29 @touch linux/kmemleak.h
30 @cp $< linux/scatterlist.h
diff --git a/tools/testing/scatterlist/linux/mm.h b/tools/testing/scatterlist/linux/mm.h
new file mode 100644
index 000000000000..6f9ac14aa800
--- /dev/null
+++ b/tools/testing/scatterlist/linux/mm.h
@@ -0,0 +1,125 @@
1#ifndef _LINUX_MM_H
2#define _LINUX_MM_H
3
4#include <assert.h>
5#include <string.h>
6#include <stdlib.h>
7#include <errno.h>
8#include <limits.h>
9#include <stdio.h>
10
11typedef unsigned long dma_addr_t;
12
13#define unlikely
14
15#define BUG_ON(x) assert(!(x))
16
17#define WARN_ON(condition) ({ \
18 int __ret_warn_on = !!(condition); \
19 unlikely(__ret_warn_on); \
20})
21
22#define WARN_ON_ONCE(condition) ({ \
23 int __ret_warn_on = !!(condition); \
24 if (unlikely(__ret_warn_on)) \
25 assert(0); \
26 unlikely(__ret_warn_on); \
27})
28
29#define PAGE_SIZE (4096)
30#define PAGE_SHIFT (12)
31#define PAGE_MASK (~(PAGE_SIZE-1))
32
33#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
34#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
35#define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
36
37#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
38
39#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
40
41#define virt_to_page(x) ((void *)x)
42#define page_address(x) ((void *)x)
43
44static inline unsigned long page_to_phys(struct page *page)
45{
46 assert(0);
47
48 return 0;
49}
50
51#define page_to_pfn(page) ((unsigned long)(page) / PAGE_SIZE)
52#define pfn_to_page(pfn) (void *)((pfn) * PAGE_SIZE)
53#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
54
55#define __min(t1, t2, min1, min2, x, y) ({ \
56 t1 min1 = (x); \
57 t2 min2 = (y); \
58 (void) (&min1 == &min2); \
59 min1 < min2 ? min1 : min2; })
60
61#define ___PASTE(a,b) a##b
62#define __PASTE(a,b) ___PASTE(a,b)
63
64#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
65
66#define min(x, y) \
67 __min(typeof(x), typeof(y), \
68 __UNIQUE_ID(min1_), __UNIQUE_ID(min2_), \
69 x, y)
70
71#define min_t(type, x, y) \
72 __min(type, type, \
73 __UNIQUE_ID(min1_), __UNIQUE_ID(min2_), \
74 x, y)
75
76#define preemptible() (1)
77
78static inline void *kmap(struct page *page)
79{
80 assert(0);
81
82 return NULL;
83}
84
85static inline void *kmap_atomic(struct page *page)
86{
87 assert(0);
88
89 return NULL;
90}
91
92static inline void kunmap(void *addr)
93{
94 assert(0);
95}
96
97static inline void kunmap_atomic(void *addr)
98{
99 assert(0);
100}
101
102static inline unsigned long __get_free_page(unsigned int flags)
103{
104 return (unsigned long)malloc(PAGE_SIZE);
105}
106
107static inline void free_page(unsigned long page)
108{
109 free((void *)page);
110}
111
112static inline void *kmalloc(unsigned int size, unsigned int flags)
113{
114 return malloc(size);
115}
116
117#define kfree(x) free(x)
118
119#define kmemleak_alloc(a, b, c, d)
120#define kmemleak_free(a)
121
122#define PageSlab(p) (0)
123#define flush_kernel_dcache_page(p)
124
125#endif
diff --git a/tools/testing/scatterlist/main.c b/tools/testing/scatterlist/main.c
new file mode 100644
index 000000000000..0a1464181226
--- /dev/null
+++ b/tools/testing/scatterlist/main.c
@@ -0,0 +1,79 @@
1#include <stdio.h>
2#include <assert.h>
3
4#include <linux/scatterlist.h>
5
6#define MAX_PAGES (64)
7
8static void set_pages(struct page **pages, const unsigned *array, unsigned num)
9{
10 unsigned int i;
11
12 assert(num < MAX_PAGES);
13 for (i = 0; i < num; i++)
14 pages[i] = (struct page *)(unsigned long)
15 ((1 + array[i]) * PAGE_SIZE);
16}
17
18#define pfn(...) (unsigned []){ __VA_ARGS__ }
19
20int main(void)
21{
22 const unsigned int sgmax = SCATTERLIST_MAX_SEGMENT;
23 struct test {
24 int alloc_ret;
25 unsigned num_pages;
26 unsigned *pfn;
27 unsigned size;
28 unsigned int max_seg;
29 unsigned int expected_segments;
30 } *test, tests[] = {
31 { -EINVAL, 1, pfn(0), PAGE_SIZE, PAGE_SIZE + 1, 1 },
32 { -EINVAL, 1, pfn(0), PAGE_SIZE, 0, 1 },
33 { -EINVAL, 1, pfn(0), PAGE_SIZE, sgmax + 1, 1 },
34 { 0, 1, pfn(0), PAGE_SIZE, sgmax, 1 },
35 { 0, 1, pfn(0), 1, sgmax, 1 },
36 { 0, 2, pfn(0, 1), 2 * PAGE_SIZE, sgmax, 1 },
37 { 0, 2, pfn(1, 0), 2 * PAGE_SIZE, sgmax, 2 },
38 { 0, 3, pfn(0, 1, 2), 3 * PAGE_SIZE, sgmax, 1 },
39 { 0, 3, pfn(0, 2, 1), 3 * PAGE_SIZE, sgmax, 3 },
40 { 0, 3, pfn(0, 1, 3), 3 * PAGE_SIZE, sgmax, 2 },
41 { 0, 3, pfn(1, 2, 4), 3 * PAGE_SIZE, sgmax, 2 },
42 { 0, 3, pfn(1, 3, 4), 3 * PAGE_SIZE, sgmax, 2 },
43 { 0, 4, pfn(0, 1, 3, 4), 4 * PAGE_SIZE, sgmax, 2 },
44 { 0, 5, pfn(0, 1, 3, 4, 5), 5 * PAGE_SIZE, sgmax, 2 },
45 { 0, 5, pfn(0, 1, 3, 4, 6), 5 * PAGE_SIZE, sgmax, 3 },
46 { 0, 5, pfn(0, 1, 2, 3, 4), 5 * PAGE_SIZE, sgmax, 1 },
47 { 0, 5, pfn(0, 1, 2, 3, 4), 5 * PAGE_SIZE, 2 * PAGE_SIZE, 3 },
48 { 0, 6, pfn(0, 1, 2, 3, 4, 5), 6 * PAGE_SIZE, 2 * PAGE_SIZE, 3 },
49 { 0, 6, pfn(0, 2, 3, 4, 5, 6), 6 * PAGE_SIZE, 2 * PAGE_SIZE, 4 },
50 { 0, 6, pfn(0, 1, 3, 4, 5, 6), 6 * PAGE_SIZE, 2 * PAGE_SIZE, 3 },
51 { 0, 0, NULL, 0, 0, 0 },
52 };
53 unsigned int i;
54
55 for (i = 0, test = tests; test->expected_segments; test++, i++) {
56 struct page *pages[MAX_PAGES];
57 struct sg_table st;
58 int ret;
59
60 set_pages(pages, test->pfn, test->num_pages);
61
62 ret = __sg_alloc_table_from_pages(&st, pages, test->num_pages,
63 0, test->size, test->max_seg,
64 GFP_KERNEL);
65 assert(ret == test->alloc_ret);
66
67 if (test->alloc_ret)
68 continue;
69
70 assert(st.nents == test->expected_segments);
71 assert(st.orig_nents == test->expected_segments);
72
73 sg_free_table(&st);
74 }
75
76 assert(i == (sizeof(tests) / sizeof(tests[0])) - 1);
77
78 return 0;
79}
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 26ce4f7168be..eaf599dc2137 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -1,4 +1,6 @@
1TARGETS = bpf 1# SPDX-License-Identifier: GPL-2.0
2TARGETS = android
3TARGETS += bpf
2TARGETS += breakpoints 4TARGETS += breakpoints
3TARGETS += capabilities 5TARGETS += capabilities
4TARGETS += cpufreq 6TARGETS += cpufreq
@@ -52,6 +54,10 @@ override LDFLAGS =
52override MAKEFLAGS = 54override MAKEFLAGS =
53endif 55endif
54 56
57ifneq ($(KBUILD_SRC),)
58override LDFLAGS =
59endif
60
55BUILD := $(O) 61BUILD := $(O)
56ifndef BUILD 62ifndef BUILD
57 BUILD := $(KBUILD_OUTPUT) 63 BUILD := $(KBUILD_OUTPUT)
@@ -62,32 +68,32 @@ endif
62 68
63export BUILD 69export BUILD
64all: 70all:
65 for TARGET in $(TARGETS); do \ 71 @for TARGET in $(TARGETS); do \
66 BUILD_TARGET=$$BUILD/$$TARGET; \ 72 BUILD_TARGET=$$BUILD/$$TARGET; \
67 mkdir $$BUILD_TARGET -p; \ 73 mkdir $$BUILD_TARGET -p; \
68 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 74 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
69 done; 75 done;
70 76
71run_tests: all 77run_tests: all
72 for TARGET in $(TARGETS); do \ 78 @for TARGET in $(TARGETS); do \
73 BUILD_TARGET=$$BUILD/$$TARGET; \ 79 BUILD_TARGET=$$BUILD/$$TARGET; \
74 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ 80 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
75 done; 81 done;
76 82
77hotplug: 83hotplug:
78 for TARGET in $(TARGETS_HOTPLUG); do \ 84 @for TARGET in $(TARGETS_HOTPLUG); do \
79 BUILD_TARGET=$$BUILD/$$TARGET; \ 85 BUILD_TARGET=$$BUILD/$$TARGET; \
80 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 86 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
81 done; 87 done;
82 88
83run_hotplug: hotplug 89run_hotplug: hotplug
84 for TARGET in $(TARGETS_HOTPLUG); do \ 90 @for TARGET in $(TARGETS_HOTPLUG); do \
85 BUILD_TARGET=$$BUILD/$$TARGET; \ 91 BUILD_TARGET=$$BUILD/$$TARGET; \
86 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 92 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
87 done; 93 done;
88 94
89clean_hotplug: 95clean_hotplug:
90 for TARGET in $(TARGETS_HOTPLUG); do \ 96 @for TARGET in $(TARGETS_HOTPLUG); do \
91 BUILD_TARGET=$$BUILD/$$TARGET; \ 97 BUILD_TARGET=$$BUILD/$$TARGET; \
92 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 98 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
93 done; 99 done;
@@ -103,7 +109,7 @@ install:
103ifdef INSTALL_PATH 109ifdef INSTALL_PATH
104 @# Ask all targets to install their files 110 @# Ask all targets to install their files
105 mkdir -p $(INSTALL_PATH) 111 mkdir -p $(INSTALL_PATH)
106 for TARGET in $(TARGETS); do \ 112 @for TARGET in $(TARGETS); do \
107 BUILD_TARGET=$$BUILD/$$TARGET; \ 113 BUILD_TARGET=$$BUILD/$$TARGET; \
108 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ 114 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
109 done; 115 done;
@@ -128,7 +134,7 @@ else
128endif 134endif
129 135
130clean: 136clean:
131 for TARGET in $(TARGETS); do \ 137 @for TARGET in $(TARGETS); do \
132 BUILD_TARGET=$$BUILD/$$TARGET; \ 138 BUILD_TARGET=$$BUILD/$$TARGET; \
133 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 139 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
134 done; 140 done;
diff --git a/tools/testing/selftests/android/Makefile b/tools/testing/selftests/android/Makefile
new file mode 100644
index 000000000000..1a7492268993
--- /dev/null
+++ b/tools/testing/selftests/android/Makefile
@@ -0,0 +1,46 @@
1SUBDIRS := ion
2
3TEST_PROGS := run.sh
4
5.PHONY: all clean
6
7include ../lib.mk
8
9all:
10 @for DIR in $(SUBDIRS); do \
11 BUILD_TARGET=$(OUTPUT)/$$DIR; \
12 mkdir $$BUILD_TARGET -p; \
13 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
14 #SUBDIR test prog name should be in the form: SUBDIR_test.sh
15 TEST=$$DIR"_test.sh"; \
16 if [ -e $$DIR/$$TEST ]; then
17 rsync -a $$DIR/$$TEST $$BUILD_TARGET/;
18 fi
19 done
20
21override define RUN_TESTS
22 @cd $(OUTPUT); ./run.sh
23endef
24
25override define INSTALL_RULE
26 mkdir -p $(INSTALL_PATH)
27 install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)
28
29 @for SUBDIR in $(SUBDIRS); do \
30 BUILD_TARGET=$(OUTPUT)/$$SUBDIR; \
31 mkdir $$BUILD_TARGET -p; \
32 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
33 done;
34endef
35
36override define EMIT_TESTS
37 echo "./run.sh"
38endef
39
40override define CLEAN
41 @for DIR in $(SUBDIRS); do \
42 BUILD_TARGET=$(OUTPUT)/$$DIR; \
43 mkdir $$BUILD_TARGET -p; \
44 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
45 done
46endef
diff --git a/tools/testing/selftests/android/ion/.gitignore b/tools/testing/selftests/android/ion/.gitignore
new file mode 100644
index 000000000000..67e6f391b2a9
--- /dev/null
+++ b/tools/testing/selftests/android/ion/.gitignore
@@ -0,0 +1,2 @@
1ionapp_export
2ionapp_import
diff --git a/tools/testing/selftests/android/ion/Makefile b/tools/testing/selftests/android/ion/Makefile
new file mode 100644
index 000000000000..96e0c448b39d
--- /dev/null
+++ b/tools/testing/selftests/android/ion/Makefile
@@ -0,0 +1,16 @@
1
2INCLUDEDIR := -I. -I../../../../../drivers/staging/android/uapi/
3CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g
4
5TEST_GEN_FILES := ionapp_export ionapp_import
6
7all: $(TEST_GEN_FILES)
8
9$(TEST_GEN_FILES): ipcsocket.c ionutils.c
10
11TEST_PROGS := ion_test.sh
12
13include ../../lib.mk
14
15$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
16$(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c
diff --git a/tools/testing/selftests/android/ion/README b/tools/testing/selftests/android/ion/README
new file mode 100644
index 000000000000..21783e9c451e
--- /dev/null
+++ b/tools/testing/selftests/android/ion/README
@@ -0,0 +1,101 @@
1ION BUFFER SHARING UTILITY
2==========================
3File: ion_test.sh : Utility to test ION driver buffer sharing mechanism.
4Author: Pintu Kumar <pintu.ping@gmail.com>
5
6Introduction:
7-------------
8This is a test utility to verify ION buffer sharing in user space
9between 2 independent processes.
10It uses unix domain socket (with SCM_RIGHTS) as IPC to transfer an FD to
11another process to share the same buffer.
12This utility demonstrates how ION buffer sharing can be implemented between
13two user space processes, using various heap types.
14The following heap types are supported by ION driver.
15ION_HEAP_TYPE_SYSTEM (0)
16ION_HEAP_TYPE_SYSTEM_CONTIG (1)
17ION_HEAP_TYPE_CARVEOUT (2)
18ION_HEAP_TYPE_CHUNK (3)
19ION_HEAP_TYPE_DMA (4)
20
21By default only the SYSTEM and SYSTEM_CONTIG heaps are supported.
22Each heap is associated with the respective heap id.
23This utility is designed in the form of client/server program.
24The server part (ionapp_export) is the exporter of the buffer.
25It is responsible for creating an ION client, allocating the buffer based on
26the heap id, writing some data to this buffer and then exporting the FD
27(associated with this buffer) to another process using socket IPC.
28This FD is called as buffer FD (which is different than the ION client FD).
29
30The client part (ionapp_import) is the importer of the buffer.
31It retrives the FD from the socket data and installs into its address space.
32This new FD internally points to the same kernel buffer.
33So first it reads the data that is stored in this buffer and prints it.
34Then it writes the different size of data (it could be different data) to the
35same buffer.
36Finally the buffer FD must be closed by both the exporter and importer.
37Thus the same kernel buffer is shared among two user space processes using
38ION driver and only one time allocation.
39
40Prerequisite:
41-------------
42This utility works only if /dev/ion interface is present.
43The following configs needs to be enabled in kernel to include ion driver.
44CONFIG_ANDROID=y
45CONFIG_STAGING=y
46CONFIG_ION=y
47CONFIG_ION_SYSTEM_HEAP=y
48
49This utility requires to be run as root user.
50
51
52Compile and test:
53-----------------
54This utility is made to be run as part of kselftest framework in kernel.
55To compile and run using kselftest you can simply do the following from the
56kernel top directory.
57linux$ make TARGETS=android kselftest
58Or you can also use:
59linux$ make -C tools/testing/selftests TARGETS=android run_tests
60Using the selftest it can directly execute the ion_test.sh script to test the
61buffer sharing using ion system heap.
62Currently the heap size is hard coded as just 10 bytes inside this script.
63You need to be a root user to run under selftest.
64
65You can also compile and test manually using the following steps:
66ion$ make
67These will generate 2 executable: ionapp_export, ionapp_import
68Now you can run the export and import manually by specifying the heap type
69and the heap size.
70You can also directly execute the shell script to run the test automatically.
71Simply use the following command to run the test.
72ion$ sudo ./ion_test.sh
73
74Test Results:
75-------------
76The utility is verified on Ubuntu-32 bit system with Linux Kernel 4.14.
77Here is the snapshot of the test result using kselftest.
78
79linux# make TARGETS=android kselftest
80heap_type: 0, heap_size: 10
81--------------------------------------
82heap type: 0
83 heap id: 1
84heap name: ion_system_heap
85--------------------------------------
86Fill buffer content:
870xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
88Sharing fd: 6, Client fd: 5
89<ion_close_buffer_fd>: buffer release successfully....
90Received buffer fd: 4
91Read buffer content:
920xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0x0 0x0 0x0 0x0 0x0 0x0
930x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
94Fill buffer content:
950xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
960xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
970xfd 0xfd
98<ion_close_buffer_fd>: buffer release successfully....
99ion_test.sh: heap_type: 0 - [PASS]
100
101ion_test.sh: done
diff --git a/tools/testing/selftests/android/ion/config b/tools/testing/selftests/android/ion/config
new file mode 100644
index 000000000000..19db6ca9aa2b
--- /dev/null
+++ b/tools/testing/selftests/android/ion/config
@@ -0,0 +1,4 @@
1CONFIG_ANDROID=y
2CONFIG_STAGING=y
3CONFIG_ION=y
4CONFIG_ION_SYSTEM_HEAP=y
diff --git a/tools/testing/selftests/android/ion/ion.h b/tools/testing/selftests/android/ion/ion.h
new file mode 100644
index 000000000000..f7021ac51335
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ion.h
@@ -0,0 +1,143 @@
1/*
2 * ion.h
3 *
4 * Copyright (C) 2011 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17/* This file is copied from drivers/staging/android/uapi/ion.h
18 * This local copy is required for the selftest to pass, when build
19 * outside the kernel source tree.
20 * Please keep this file in sync with its original file until the
21 * ion driver is moved outside the staging tree.
22 */
23
24#ifndef _UAPI_LINUX_ION_H
25#define _UAPI_LINUX_ION_H
26
27#include <linux/ioctl.h>
28#include <linux/types.h>
29
30/**
31 * enum ion_heap_types - list of all possible types of heaps
32 * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
33 * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
34 * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
35 * carveout heap, allocations are physically
36 * contiguous
37 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
38 * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
39 * is used to identify the heaps, so only 32
40 * total heap types are supported
41 */
42enum ion_heap_type {
43 ION_HEAP_TYPE_SYSTEM,
44 ION_HEAP_TYPE_SYSTEM_CONTIG,
45 ION_HEAP_TYPE_CARVEOUT,
46 ION_HEAP_TYPE_CHUNK,
47 ION_HEAP_TYPE_DMA,
48 ION_HEAP_TYPE_CUSTOM, /*
49 * must be last so device specific heaps always
50 * are at the end of this enum
51 */
52};
53
54#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
55
56/**
57 * allocation flags - the lower 16 bits are used by core ion, the upper 16
58 * bits are reserved for use by the heaps themselves.
59 */
60
61/*
62 * mappings of this buffer should be cached, ion will do cache maintenance
63 * when the buffer is mapped for dma
64 */
65#define ION_FLAG_CACHED 1
66
67/**
68 * DOC: Ion Userspace API
69 *
70 * create a client by opening /dev/ion
71 * most operations handled via following ioctls
72 *
73 */
74
75/**
76 * struct ion_allocation_data - metadata passed from userspace for allocations
77 * @len: size of the allocation
78 * @heap_id_mask: mask of heap ids to allocate from
79 * @flags: flags passed to heap
80 * @handle: pointer that will be populated with a cookie to use to
81 * refer to this allocation
82 *
83 * Provided by userspace as an argument to the ioctl
84 */
85struct ion_allocation_data {
86 __u64 len;
87 __u32 heap_id_mask;
88 __u32 flags;
89 __u32 fd;
90 __u32 unused;
91};
92
93#define MAX_HEAP_NAME 32
94
95/**
96 * struct ion_heap_data - data about a heap
97 * @name - first 32 characters of the heap name
98 * @type - heap type
99 * @heap_id - heap id for the heap
100 */
101struct ion_heap_data {
102 char name[MAX_HEAP_NAME];
103 __u32 type;
104 __u32 heap_id;
105 __u32 reserved0;
106 __u32 reserved1;
107 __u32 reserved2;
108};
109
110/**
111 * struct ion_heap_query - collection of data about all heaps
112 * @cnt - total number of heaps to be copied
113 * @heaps - buffer to copy heap data
114 */
115struct ion_heap_query {
116 __u32 cnt; /* Total number of heaps to be copied */
117 __u32 reserved0; /* align to 64bits */
118 __u64 heaps; /* buffer to be populated */
119 __u32 reserved1;
120 __u32 reserved2;
121};
122
123#define ION_IOC_MAGIC 'I'
124
125/**
126 * DOC: ION_IOC_ALLOC - allocate memory
127 *
128 * Takes an ion_allocation_data struct and returns it with the handle field
129 * populated with the opaque handle for the allocation.
130 */
131#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
132 struct ion_allocation_data)
133
134/**
135 * DOC: ION_IOC_HEAP_QUERY - information about available heaps
136 *
137 * Takes an ion_heap_query structure and populates information about
138 * available Ion heaps.
139 */
140#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
141 struct ion_heap_query)
142
143#endif /* _UAPI_LINUX_ION_H */
diff --git a/tools/testing/selftests/android/ion/ion_test.sh b/tools/testing/selftests/android/ion/ion_test.sh
new file mode 100755
index 000000000000..a1aff506f5e6
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ion_test.sh
@@ -0,0 +1,55 @@
1#!/bin/bash
2
3heapsize=4096
4TCID="ion_test.sh"
5errcode=0
6
7run_test()
8{
9 heaptype=$1
10 ./ionapp_export -i $heaptype -s $heapsize &
11 sleep 1
12 ./ionapp_import
13 if [ $? -ne 0 ]; then
14 echo "$TCID: heap_type: $heaptype - [FAIL]"
15 errcode=1
16 else
17 echo "$TCID: heap_type: $heaptype - [PASS]"
18 fi
19 sleep 1
20 echo ""
21}
22
23check_root()
24{
25 uid=$(id -u)
26 if [ $uid -ne 0 ]; then
27 echo $TCID: must be run as root >&2
28 exit 0
29 fi
30}
31
32check_device()
33{
34 DEVICE=/dev/ion
35 if [ ! -e $DEVICE ]; then
36 echo $TCID: No $DEVICE device found >&2
37 echo $TCID: May be CONFIG_ION is not set >&2
38 exit 0
39 fi
40}
41
42main_function()
43{
44 check_device
45 check_root
46
47 # ION_SYSTEM_HEAP TEST
48 run_test 0
49 # ION_SYSTEM_CONTIG_HEAP TEST
50 run_test 1
51}
52
53main_function
54echo "$TCID: done"
55exit $errcode
diff --git a/tools/testing/selftests/android/ion/ionapp_export.c b/tools/testing/selftests/android/ion/ionapp_export.c
new file mode 100644
index 000000000000..a944e72621a9
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ionapp_export.c
@@ -0,0 +1,135 @@
1/*
2 * ionapp_export.c
3 *
4 * It is a user space utility to create and export android
5 * ion memory buffer fd to another process using unix domain socket as IPC.
6 * This acts like a server for ionapp_import(client).
7 * So, this server has to be started first before the client.
8 *
9 * Copyright (C) 2017 Pintu Kumar <pintu.ping@gmail.com>
10 *
11 * This software is licensed under the terms of the GNU General Public
12 * License version 2, as published by the Free Software Foundation, and
13 * may be copied, distributed, and modified under those terms.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <unistd.h>
26#include <errno.h>
27#include <sys/time.h>
28#include "ionutils.h"
29#include "ipcsocket.h"
30
31
32void print_usage(int argc, char *argv[])
33{
34 printf("Usage: %s [-h <help>] [-i <heap id>] [-s <size in bytes>]\n",
35 argv[0]);
36}
37
38int main(int argc, char *argv[])
39{
40 int opt, ret, status, heapid;
41 int sockfd, client_fd, shared_fd;
42 unsigned char *map_buf;
43 unsigned long map_len, heap_type, heap_size, flags;
44 struct ion_buffer_info info;
45 struct socket_info skinfo;
46
47 if (argc < 2) {
48 print_usage(argc, argv);
49 return -1;
50 }
51
52 heap_size = 0;
53 flags = 0;
54
55 while ((opt = getopt(argc, argv, "hi:s:")) != -1) {
56 switch (opt) {
57 case 'h':
58 print_usage(argc, argv);
59 exit(0);
60 break;
61 case 'i':
62 heapid = atoi(optarg);
63 switch (heapid) {
64 case 0:
65 heap_type = ION_HEAP_TYPE_SYSTEM;
66 break;
67 case 1:
68 heap_type = ION_HEAP_TYPE_SYSTEM_CONTIG;
69 break;
70 default:
71 printf("ERROR: heap type not supported\n");
72 exit(1);
73 }
74 break;
75 case 's':
76 heap_size = atoi(optarg);
77 break;
78 default:
79 print_usage(argc, argv);
80 exit(1);
81 break;
82 }
83 }
84
85 if (heap_size <= 0) {
86 printf("heap_size cannot be 0\n");
87 print_usage(argc, argv);
88 exit(1);
89 }
90
91 printf("heap_type: %ld, heap_size: %ld\n", heap_type, heap_size);
92 info.heap_type = heap_type;
93 info.heap_size = heap_size;
94 info.flag_type = flags;
95
96 /* This is server: open the socket connection first */
97 /* Here; 1 indicates server or exporter */
98 status = opensocket(&sockfd, SOCKET_NAME, 1);
99 if (status < 0) {
100 fprintf(stderr, "<%s>: Failed opensocket.\n", __func__);
101 goto err_socket;
102 }
103 skinfo.sockfd = sockfd;
104
105 ret = ion_export_buffer_fd(&info);
106 if (ret < 0) {
107 fprintf(stderr, "FAILED: ion_get_buffer_fd\n");
108 goto err_export;
109 }
110 client_fd = info.ionfd;
111 shared_fd = info.buffd;
112 map_buf = info.buffer;
113 map_len = info.buflen;
114 write_buffer(map_buf, map_len);
115
116 /* share ion buf fd with other user process */
117 printf("Sharing fd: %d, Client fd: %d\n", shared_fd, client_fd);
118 skinfo.datafd = shared_fd;
119 skinfo.buflen = map_len;
120
121 ret = socket_send_fd(&skinfo);
122 if (ret < 0) {
123 fprintf(stderr, "FAILED: socket_send_fd\n");
124 goto err_send;
125 }
126
127err_send:
128err_export:
129 ion_close_buffer_fd(&info);
130
131err_socket:
132 closesocket(sockfd, SOCKET_NAME);
133
134 return 0;
135}
diff --git a/tools/testing/selftests/android/ion/ionapp_import.c b/tools/testing/selftests/android/ion/ionapp_import.c
new file mode 100644
index 000000000000..ae2d704cfa46
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ionapp_import.c
@@ -0,0 +1,88 @@
1/*
2 * ionapp_import.c
3 *
4 * It is a user space utility to receive android ion memory buffer fd
5 * over unix domain socket IPC that can be exported by ionapp_export.
6 * This acts like a client for ionapp_export.
7 *
8 * Copyright (C) 2017 Pintu Kumar <pintu.ping@gmail.com>
9 *
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <unistd.h>
24#include <string.h>
25#include "ionutils.h"
26#include "ipcsocket.h"
27
28
29int main(void)
30{
31 int ret, status;
32 int sockfd, shared_fd;
33 unsigned char *map_buf;
34 unsigned long map_len;
35 struct ion_buffer_info info;
36 struct socket_info skinfo;
37
38 /* This is the client part. Here 0 means client or importer */
39 status = opensocket(&sockfd, SOCKET_NAME, 0);
40 if (status < 0) {
41 fprintf(stderr, "No exporter exists...\n");
42 ret = status;
43 goto err_socket;
44 }
45
46 skinfo.sockfd = sockfd;
47
48 ret = socket_receive_fd(&skinfo);
49 if (ret < 0) {
50 fprintf(stderr, "Failed: socket_receive_fd\n");
51 goto err_recv;
52 }
53
54 shared_fd = skinfo.datafd;
55 printf("Received buffer fd: %d\n", shared_fd);
56 if (shared_fd <= 0) {
57 fprintf(stderr, "ERROR: improper buf fd\n");
58 ret = -1;
59 goto err_fd;
60 }
61
62 memset(&info, 0, sizeof(info));
63 info.buffd = shared_fd;
64 info.buflen = ION_BUFFER_LEN;
65
66 ret = ion_import_buffer_fd(&info);
67 if (ret < 0) {
68 fprintf(stderr, "Failed: ion_use_buffer_fd\n");
69 goto err_import;
70 }
71
72 map_buf = info.buffer;
73 map_len = info.buflen;
74 read_buffer(map_buf, map_len);
75
76 /* Write probably new data to the same buffer again */
77 map_len = ION_BUFFER_LEN;
78 write_buffer(map_buf, map_len);
79
80err_import:
81 ion_close_buffer_fd(&info);
82err_fd:
83err_recv:
84err_socket:
85 closesocket(sockfd, SOCKET_NAME);
86
87 return ret;
88}
diff --git a/tools/testing/selftests/android/ion/ionutils.c b/tools/testing/selftests/android/ion/ionutils.c
new file mode 100644
index 000000000000..ce69c14f51fa
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ionutils.c
@@ -0,0 +1,259 @@
1#include <stdio.h>
2#include <string.h>
3#include <unistd.h>
4#include <fcntl.h>
5#include <errno.h>
6//#include <stdint.h>
7#include <sys/ioctl.h>
8#include <sys/mman.h>
9#include "ionutils.h"
10#include "ipcsocket.h"
11
12
13void write_buffer(void *buffer, unsigned long len)
14{
15 int i;
16 unsigned char *ptr = (unsigned char *)buffer;
17
18 if (!ptr) {
19 fprintf(stderr, "<%s>: Invalid buffer...\n", __func__);
20 return;
21 }
22
23 printf("Fill buffer content:\n");
24 memset(ptr, 0xfd, len);
25 for (i = 0; i < len; i++)
26 printf("0x%x ", ptr[i]);
27 printf("\n");
28}
29
30void read_buffer(void *buffer, unsigned long len)
31{
32 int i;
33 unsigned char *ptr = (unsigned char *)buffer;
34
35 if (!ptr) {
36 fprintf(stderr, "<%s>: Invalid buffer...\n", __func__);
37 return;
38 }
39
40 printf("Read buffer content:\n");
41 for (i = 0; i < len; i++)
42 printf("0x%x ", ptr[i]);
43 printf("\n");
44}
45
46int ion_export_buffer_fd(struct ion_buffer_info *ion_info)
47{
48 int i, ret, ionfd, buffer_fd;
49 unsigned int heap_id;
50 unsigned long maplen;
51 unsigned char *map_buffer;
52 struct ion_allocation_data alloc_data;
53 struct ion_heap_query query;
54 struct ion_heap_data heap_data[MAX_HEAP_COUNT];
55
56 if (!ion_info) {
57 fprintf(stderr, "<%s>: Invalid ion info\n", __func__);
58 return -1;
59 }
60
61 /* Create an ION client */
62 ionfd = open(ION_DEVICE, O_RDWR);
63 if (ionfd < 0) {
64 fprintf(stderr, "<%s>: Failed to open ion client: %s\n",
65 __func__, strerror(errno));
66 return -1;
67 }
68
69 memset(&query, 0, sizeof(query));
70 query.cnt = MAX_HEAP_COUNT;
71 query.heaps = (unsigned long int)&heap_data[0];
72 /* Query ION heap_id_mask from ION heap */
73 ret = ioctl(ionfd, ION_IOC_HEAP_QUERY, &query);
74 if (ret < 0) {
75 fprintf(stderr, "<%s>: Failed: ION_IOC_HEAP_QUERY: %s\n",
76 __func__, strerror(errno));
77 goto err_query;
78 }
79
80 heap_id = MAX_HEAP_COUNT + 1;
81 for (i = 0; i < query.cnt; i++) {
82 if (heap_data[i].type == ion_info->heap_type) {
83 printf("--------------------------------------\n");
84 printf("heap type: %d\n", heap_data[i].type);
85 printf(" heap id: %d\n", heap_data[i].heap_id);
86 printf("heap name: %s\n", heap_data[i].name);
87 printf("--------------------------------------\n");
88 heap_id = heap_data[i].heap_id;
89 break;
90 }
91 }
92
93 if (heap_id > MAX_HEAP_COUNT) {
94 fprintf(stderr, "<%s>: ERROR: heap type does not exists\n",
95 __func__);
96 goto err_heap;
97 }
98
99 alloc_data.len = ion_info->heap_size;
100 alloc_data.heap_id_mask = 1 << heap_id;
101 alloc_data.flags = ion_info->flag_type;
102
103 /* Allocate memory for this ION client as per heap_type */
104 ret = ioctl(ionfd, ION_IOC_ALLOC, &alloc_data);
105 if (ret < 0) {
106 fprintf(stderr, "<%s>: Failed: ION_IOC_ALLOC: %s\n",
107 __func__, strerror(errno));
108 goto err_alloc;
109 }
110
111 /* This will return a valid buffer fd */
112 buffer_fd = alloc_data.fd;
113 maplen = alloc_data.len;
114
115 if (buffer_fd < 0 || maplen <= 0) {
116 fprintf(stderr, "<%s>: Invalid map data, fd: %d, len: %ld\n",
117 __func__, buffer_fd, maplen);
118 goto err_fd_data;
119 }
120
121 /* Create memory mapped buffer for the buffer fd */
122 map_buffer = (unsigned char *)mmap(NULL, maplen, PROT_READ|PROT_WRITE,
123 MAP_SHARED, buffer_fd, 0);
124 if (map_buffer == MAP_FAILED) {
125 fprintf(stderr, "<%s>: Failed: mmap: %s\n",
126 __func__, strerror(errno));
127 goto err_mmap;
128 }
129
130 ion_info->ionfd = ionfd;
131 ion_info->buffd = buffer_fd;
132 ion_info->buffer = map_buffer;
133 ion_info->buflen = maplen;
134
135 return 0;
136
137 munmap(map_buffer, maplen);
138
139err_fd_data:
140err_mmap:
141 /* in case of error: close the buffer fd */
142 if (buffer_fd)
143 close(buffer_fd);
144
145err_query:
146err_heap:
147err_alloc:
148 /* In case of error: close the ion client fd */
149 if (ionfd)
150 close(ionfd);
151
152 return -1;
153}
154
155int ion_import_buffer_fd(struct ion_buffer_info *ion_info)
156{
157 int buffd;
158 unsigned char *map_buf;
159 unsigned long map_len;
160
161 if (!ion_info) {
162 fprintf(stderr, "<%s>: Invalid ion info\n", __func__);
163 return -1;
164 }
165
166 map_len = ion_info->buflen;
167 buffd = ion_info->buffd;
168
169 if (buffd < 0 || map_len <= 0) {
170 fprintf(stderr, "<%s>: Invalid map data, fd: %d, len: %ld\n",
171 __func__, buffd, map_len);
172 goto err_buffd;
173 }
174
175 map_buf = (unsigned char *)mmap(NULL, map_len, PROT_READ|PROT_WRITE,
176 MAP_SHARED, buffd, 0);
177 if (map_buf == MAP_FAILED) {
178 printf("<%s>: Failed - mmap: %s\n",
179 __func__, strerror(errno));
180 goto err_mmap;
181 }
182
183 ion_info->buffer = map_buf;
184 ion_info->buflen = map_len;
185
186 return 0;
187
188err_mmap:
189 if (buffd)
190 close(buffd);
191
192err_buffd:
193 return -1;
194}
195
196void ion_close_buffer_fd(struct ion_buffer_info *ion_info)
197{
198 if (ion_info) {
199 /* unmap the buffer properly in the end */
200 munmap(ion_info->buffer, ion_info->buflen);
201 /* close the buffer fd */
202 if (ion_info->buffd > 0)
203 close(ion_info->buffd);
204 /* Finally, close the client fd */
205 if (ion_info->ionfd > 0)
206 close(ion_info->ionfd);
207 printf("<%s>: buffer release successfully....\n", __func__);
208 }
209}
210
211int socket_send_fd(struct socket_info *info)
212{
213 int status;
214 int fd, sockfd;
215 struct socketdata skdata;
216
217 if (!info) {
218 fprintf(stderr, "<%s>: Invalid socket info\n", __func__);
219 return -1;
220 }
221
222 sockfd = info->sockfd;
223 fd = info->datafd;
224 memset(&skdata, 0, sizeof(skdata));
225 skdata.data = fd;
226 skdata.len = sizeof(skdata.data);
227 status = sendtosocket(sockfd, &skdata);
228 if (status < 0) {
229 fprintf(stderr, "<%s>: Failed: sendtosocket\n", __func__);
230 return -1;
231 }
232
233 return 0;
234}
235
236int socket_receive_fd(struct socket_info *info)
237{
238 int status;
239 int fd, sockfd;
240 struct socketdata skdata;
241
242 if (!info) {
243 fprintf(stderr, "<%s>: Invalid socket info\n", __func__);
244 return -1;
245 }
246
247 sockfd = info->sockfd;
248 memset(&skdata, 0, sizeof(skdata));
249 status = receivefromsocket(sockfd, &skdata);
250 if (status < 0) {
251 fprintf(stderr, "<%s>: Failed: receivefromsocket\n", __func__);
252 return -1;
253 }
254
255 fd = (int)skdata.data;
256 info->datafd = fd;
257
258 return status;
259}
diff --git a/tools/testing/selftests/android/ion/ionutils.h b/tools/testing/selftests/android/ion/ionutils.h
new file mode 100644
index 000000000000..9941eb858576
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ionutils.h
@@ -0,0 +1,55 @@
1#ifndef __ION_UTILS_H
2#define __ION_UTILS_H
3
4#include "ion.h"
5
6#define SOCKET_NAME "ion_socket"
7#define ION_DEVICE "/dev/ion"
8
9#define ION_BUFFER_LEN 4096
10#define MAX_HEAP_COUNT ION_HEAP_TYPE_CUSTOM
11
12struct socket_info {
13 int sockfd;
14 int datafd;
15 unsigned long buflen;
16};
17
18struct ion_buffer_info {
19 int ionfd;
20 int buffd;
21 unsigned int heap_type;
22 unsigned int flag_type;
23 unsigned long heap_size;
24 unsigned long buflen;
25 unsigned char *buffer;
26};
27
28
29/* This is used to fill the data into the mapped buffer */
30void write_buffer(void *buffer, unsigned long len);
31
32/* This is used to read the data from the exported buffer */
33void read_buffer(void *buffer, unsigned long len);
34
35/* This is used to create an ION buffer FD for the kernel buffer
36 * So you can export this same buffer to others in the form of FD
37 */
38int ion_export_buffer_fd(struct ion_buffer_info *ion_info);
39
40/* This is used to import or map an exported FD.
41 * So we point to same buffer without making a copy. Hence zero-copy.
42 */
43int ion_import_buffer_fd(struct ion_buffer_info *ion_info);
44
45/* This is used to close all references for the ION client */
46void ion_close_buffer_fd(struct ion_buffer_info *ion_info);
47
48/* This is used to send FD to another process using socket IPC */
49int socket_send_fd(struct socket_info *skinfo);
50
51/* This is used to receive FD from another process using socket IPC */
52int socket_receive_fd(struct socket_info *skinfo);
53
54
55#endif
diff --git a/tools/testing/selftests/android/ion/ipcsocket.c b/tools/testing/selftests/android/ion/ipcsocket.c
new file mode 100644
index 000000000000..7dc521002095
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ipcsocket.c
@@ -0,0 +1,227 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <sys/socket.h>
7#include <sys/time.h>
8#include <sys/un.h>
9#include <errno.h>
10
11#include "ipcsocket.h"
12
13
14int opensocket(int *sockfd, const char *name, int connecttype)
15{
16 int ret, temp = 1;
17
18 if (!name || strlen(name) > MAX_SOCK_NAME_LEN) {
19 fprintf(stderr, "<%s>: Invalid socket name.\n", __func__);
20 return -1;
21 }
22
23 ret = socket(PF_LOCAL, SOCK_STREAM, 0);
24 if (ret < 0) {
25 fprintf(stderr, "<%s>: Failed socket: <%s>\n",
26 __func__, strerror(errno));
27 return ret;
28 }
29
30 *sockfd = ret;
31 if (setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR,
32 (char *)&temp, sizeof(int)) < 0) {
33 fprintf(stderr, "<%s>: Failed setsockopt: <%s>\n",
34 __func__, strerror(errno));
35 goto err;
36 }
37
38 sprintf(sock_name, "/tmp/%s", name);
39
40 if (connecttype == 1) {
41 /* This is for Server connection */
42 struct sockaddr_un skaddr;
43 int clientfd;
44 socklen_t sklen;
45
46 unlink(sock_name);
47 memset(&skaddr, 0, sizeof(skaddr));
48 skaddr.sun_family = AF_LOCAL;
49 strcpy(skaddr.sun_path, sock_name);
50
51 ret = bind(*sockfd, (struct sockaddr *)&skaddr,
52 SUN_LEN(&skaddr));
53 if (ret < 0) {
54 fprintf(stderr, "<%s>: Failed bind: <%s>\n",
55 __func__, strerror(errno));
56 goto err;
57 }
58
59 ret = listen(*sockfd, 5);
60 if (ret < 0) {
61 fprintf(stderr, "<%s>: Failed listen: <%s>\n",
62 __func__, strerror(errno));
63 goto err;
64 }
65
66 memset(&skaddr, 0, sizeof(skaddr));
67 sklen = sizeof(skaddr);
68
69 ret = accept(*sockfd, (struct sockaddr *)&skaddr,
70 (socklen_t *)&sklen);
71 if (ret < 0) {
72 fprintf(stderr, "<%s>: Failed accept: <%s>\n",
73 __func__, strerror(errno));
74 goto err;
75 }
76
77 clientfd = ret;
78 *sockfd = clientfd;
79 } else {
80 /* This is for client connection */
81 struct sockaddr_un skaddr;
82
83 memset(&skaddr, 0, sizeof(skaddr));
84 skaddr.sun_family = AF_LOCAL;
85 strcpy(skaddr.sun_path, sock_name);
86
87 ret = connect(*sockfd, (struct sockaddr *)&skaddr,
88 SUN_LEN(&skaddr));
89 if (ret < 0) {
90 fprintf(stderr, "<%s>: Failed connect: <%s>\n",
91 __func__, strerror(errno));
92 goto err;
93 }
94 }
95
96 return 0;
97
98err:
99 if (*sockfd)
100 close(*sockfd);
101
102 return ret;
103}
104
105int sendtosocket(int sockfd, struct socketdata *skdata)
106{
107 int ret, buffd;
108 unsigned int len;
109 char cmsg_b[CMSG_SPACE(sizeof(int))];
110 struct cmsghdr *cmsg;
111 struct msghdr msgh;
112 struct iovec iov;
113 struct timeval timeout;
114 fd_set selFDs;
115
116 if (!skdata) {
117 fprintf(stderr, "<%s>: socketdata is NULL\n", __func__);
118 return -1;
119 }
120
121 FD_ZERO(&selFDs);
122 FD_SET(0, &selFDs);
123 FD_SET(sockfd, &selFDs);
124 timeout.tv_sec = 20;
125 timeout.tv_usec = 0;
126
127 ret = select(sockfd+1, NULL, &selFDs, NULL, &timeout);
128 if (ret < 0) {
129 fprintf(stderr, "<%s>: Failed select: <%s>\n",
130 __func__, strerror(errno));
131 return -1;
132 }
133
134 if (FD_ISSET(sockfd, &selFDs)) {
135 buffd = skdata->data;
136 len = skdata->len;
137 memset(&msgh, 0, sizeof(msgh));
138 msgh.msg_control = &cmsg_b;
139 msgh.msg_controllen = CMSG_LEN(len);
140 iov.iov_base = "OK";
141 iov.iov_len = 2;
142 msgh.msg_iov = &iov;
143 msgh.msg_iovlen = 1;
144 cmsg = CMSG_FIRSTHDR(&msgh);
145 cmsg->cmsg_level = SOL_SOCKET;
146 cmsg->cmsg_type = SCM_RIGHTS;
147 cmsg->cmsg_len = CMSG_LEN(len);
148 memcpy(CMSG_DATA(cmsg), &buffd, len);
149
150 ret = sendmsg(sockfd, &msgh, MSG_DONTWAIT);
151 if (ret < 0) {
152 fprintf(stderr, "<%s>: Failed sendmsg: <%s>\n",
153 __func__, strerror(errno));
154 return -1;
155 }
156 }
157
158 return 0;
159}
160
161int receivefromsocket(int sockfd, struct socketdata *skdata)
162{
163 int ret, buffd;
164 unsigned int len = 0;
165 char cmsg_b[CMSG_SPACE(sizeof(int))];
166 struct cmsghdr *cmsg;
167 struct msghdr msgh;
168 struct iovec iov;
169 fd_set recvFDs;
170 char data[32];
171
172 if (!skdata) {
173 fprintf(stderr, "<%s>: socketdata is NULL\n", __func__);
174 return -1;
175 }
176
177 FD_ZERO(&recvFDs);
178 FD_SET(0, &recvFDs);
179 FD_SET(sockfd, &recvFDs);
180
181 ret = select(sockfd+1, &recvFDs, NULL, NULL, NULL);
182 if (ret < 0) {
183 fprintf(stderr, "<%s>: Failed select: <%s>\n",
184 __func__, strerror(errno));
185 return -1;
186 }
187
188 if (FD_ISSET(sockfd, &recvFDs)) {
189 len = sizeof(buffd);
190 memset(&msgh, 0, sizeof(msgh));
191 msgh.msg_control = &cmsg_b;
192 msgh.msg_controllen = CMSG_LEN(len);
193 iov.iov_base = data;
194 iov.iov_len = sizeof(data)-1;
195 msgh.msg_iov = &iov;
196 msgh.msg_iovlen = 1;
197 cmsg = CMSG_FIRSTHDR(&msgh);
198 cmsg->cmsg_level = SOL_SOCKET;
199 cmsg->cmsg_type = SCM_RIGHTS;
200 cmsg->cmsg_len = CMSG_LEN(len);
201
202 ret = recvmsg(sockfd, &msgh, MSG_DONTWAIT);
203 if (ret < 0) {
204 fprintf(stderr, "<%s>: Failed recvmsg: <%s>\n",
205 __func__, strerror(errno));
206 return -1;
207 }
208
209 memcpy(&buffd, CMSG_DATA(cmsg), len);
210 skdata->data = buffd;
211 skdata->len = len;
212 }
213 return 0;
214}
215
216int closesocket(int sockfd, char *name)
217{
218 char sockname[MAX_SOCK_NAME_LEN];
219
220 if (sockfd)
221 close(sockfd);
222 sprintf(sockname, "/tmp/%s", name);
223 unlink(sockname);
224 shutdown(sockfd, 2);
225
226 return 0;
227}
diff --git a/tools/testing/selftests/android/ion/ipcsocket.h b/tools/testing/selftests/android/ion/ipcsocket.h
new file mode 100644
index 000000000000..b3e84498a8a1
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ipcsocket.h
@@ -0,0 +1,35 @@
1
2#ifndef _IPCSOCKET_H
3#define _IPCSOCKET_H
4
5
6#define MAX_SOCK_NAME_LEN 64
7
8char sock_name[MAX_SOCK_NAME_LEN];
9
10/* This structure is responsible for holding the IPC data
11 * data: hold the buffer fd
12 * len: just the length of 32-bit integer fd
13 */
14struct socketdata {
15 int data;
16 unsigned int len;
17};
18
19/* This API is used to open the IPC socket connection
20 * name: implies a unique socket name in the system
21 * connecttype: implies server(0) or client(1)
22 */
23int opensocket(int *sockfd, const char *name, int connecttype);
24
25/* This is the API to send socket data over IPC socket */
26int sendtosocket(int sockfd, struct socketdata *data);
27
28/* This is the API to receive socket data over IPC socket */
29int receivefromsocket(int sockfd, struct socketdata *data);
30
31/* This is the API to close the socket connection */
32int closesocket(int sockfd, char *name);
33
34
35#endif
diff --git a/tools/testing/selftests/android/run.sh b/tools/testing/selftests/android/run.sh
new file mode 100755
index 000000000000..dd8edf291454
--- /dev/null
+++ b/tools/testing/selftests/android/run.sh
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3(cd ion; ./ion_test.sh)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index f4b23d697448..333a48655ee0 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1LIBDIR := ../../../lib 2LIBDIR := ../../../lib
2BPFDIR := $(LIBDIR)/bpf 3BPFDIR := $(LIBDIR)/bpf
3APIDIR := ../../../include/uapi 4APIDIR := ../../../include/uapi
@@ -12,16 +13,17 @@ CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../i
12LDLIBS += -lcap -lelf 13LDLIBS += -lcap -lelf
13 14
14TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 15TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
15 test_align 16 test_align test_verifier_log test_dev_cgroup
16 17
17TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \ 18TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
18 test_pkt_md_access.o test_xdp_redirect.o sockmap_parse_prog.o sockmap_verdict_prog.o 19 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
20 sockmap_verdict_prog.o dev_cgroup.o
19 21
20TEST_PROGS := test_kmod.sh test_xdp_redirect.sh 22TEST_PROGS := test_kmod.sh test_xdp_redirect.sh test_xdp_meta.sh
21 23
22include ../lib.mk 24include ../lib.mk
23 25
24BPFOBJ := $(OUTPUT)/libbpf.a 26BPFOBJ := $(OUTPUT)/libbpf.a $(OUTPUT)/cgroup_helpers.c
25 27
26$(TEST_GEN_PROGS): $(BPFOBJ) 28$(TEST_GEN_PROGS): $(BPFOBJ)
27 29
@@ -34,8 +36,20 @@ $(BPFOBJ): force
34 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ 36 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
35 37
36CLANG ?= clang 38CLANG ?= clang
39LLC ?= llc
40
41PROBE := $(shell llc -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)
42
43# Let newer LLVM versions transparently probe the kernel for availability
44# of full BPF instruction set.
45ifeq ($(PROBE),)
46 CPU ?= probe
47else
48 CPU ?= generic
49endif
37 50
38%.o: %.c 51%.o: %.c
39 $(CLANG) -I. -I./include/uapi -I../../../include/uapi \ 52 $(CLANG) -I. -I./include/uapi -I../../../include/uapi \
40 -Wno-compare-distinct-pointer-types \ 53 -Wno-compare-distinct-pointer-types \
41 -O2 -target bpf -c $< -o $@ 54 -O2 -target bpf -emit-llvm -c $< -o - | \
55 $(LLC) -march=bpf -mcpu=$(CPU) -filetype=obj -o $@
diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
index 74af266aa512..b25595ea4a78 100644
--- a/tools/testing/selftests/bpf/bpf_endian.h
+++ b/tools/testing/selftests/bpf/bpf_endian.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __BPF_ENDIAN__ 2#ifndef __BPF_ENDIAN__
2#define __BPF_ENDIAN__ 3#define __BPF_ENDIAN__
3 4
diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index 36fb9161b34a..fd9a17fa8a8b 100644
--- a/tools/testing/selftests/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __BPF_HELPERS_H 2#ifndef __BPF_HELPERS_H
2#define __BPF_HELPERS_H 3#define __BPF_HELPERS_H
3 4
@@ -62,14 +63,25 @@ static unsigned long long (*bpf_get_prandom_u32)(void) =
62 (void *) BPF_FUNC_get_prandom_u32; 63 (void *) BPF_FUNC_get_prandom_u32;
63static int (*bpf_xdp_adjust_head)(void *ctx, int offset) = 64static int (*bpf_xdp_adjust_head)(void *ctx, int offset) =
64 (void *) BPF_FUNC_xdp_adjust_head; 65 (void *) BPF_FUNC_xdp_adjust_head;
66static int (*bpf_xdp_adjust_meta)(void *ctx, int offset) =
67 (void *) BPF_FUNC_xdp_adjust_meta;
65static int (*bpf_setsockopt)(void *ctx, int level, int optname, void *optval, 68static int (*bpf_setsockopt)(void *ctx, int level, int optname, void *optval,
66 int optlen) = 69 int optlen) =
67 (void *) BPF_FUNC_setsockopt; 70 (void *) BPF_FUNC_setsockopt;
68static int (*bpf_sk_redirect_map)(void *map, int key, int flags) = 71static int (*bpf_getsockopt)(void *ctx, int level, int optname, void *optval,
72 int optlen) =
73 (void *) BPF_FUNC_getsockopt;
74static int (*bpf_sk_redirect_map)(void *ctx, void *map, int key, int flags) =
69 (void *) BPF_FUNC_sk_redirect_map; 75 (void *) BPF_FUNC_sk_redirect_map;
70static int (*bpf_sock_map_update)(void *map, void *key, void *value, 76static int (*bpf_sock_map_update)(void *map, void *key, void *value,
71 unsigned long long flags) = 77 unsigned long long flags) =
72 (void *) BPF_FUNC_sock_map_update; 78 (void *) BPF_FUNC_sock_map_update;
79static int (*bpf_perf_event_read_value)(void *map, unsigned long long flags,
80 void *buf, unsigned int buf_size) =
81 (void *) BPF_FUNC_perf_event_read_value;
82static int (*bpf_perf_prog_read_value)(void *ctx, void *buf,
83 unsigned int buf_size) =
84 (void *) BPF_FUNC_perf_prog_read_value;
73 85
74 86
75/* llvm builtin functions that eBPF C program may use to 87/* llvm builtin functions that eBPF C program may use to
@@ -109,7 +121,47 @@ static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) =
109static int (*bpf_skb_change_head)(void *, int len, int flags) = 121static int (*bpf_skb_change_head)(void *, int len, int flags) =
110 (void *) BPF_FUNC_skb_change_head; 122 (void *) BPF_FUNC_skb_change_head;
111 123
124/* Scan the ARCH passed in from ARCH env variable (see Makefile) */
125#if defined(__TARGET_ARCH_x86)
126 #define bpf_target_x86
127 #define bpf_target_defined
128#elif defined(__TARGET_ARCH_s930x)
129 #define bpf_target_s930x
130 #define bpf_target_defined
131#elif defined(__TARGET_ARCH_arm64)
132 #define bpf_target_arm64
133 #define bpf_target_defined
134#elif defined(__TARGET_ARCH_mips)
135 #define bpf_target_mips
136 #define bpf_target_defined
137#elif defined(__TARGET_ARCH_powerpc)
138 #define bpf_target_powerpc
139 #define bpf_target_defined
140#elif defined(__TARGET_ARCH_sparc)
141 #define bpf_target_sparc
142 #define bpf_target_defined
143#else
144 #undef bpf_target_defined
145#endif
146
147/* Fall back to what the compiler says */
148#ifndef bpf_target_defined
112#if defined(__x86_64__) 149#if defined(__x86_64__)
150 #define bpf_target_x86
151#elif defined(__s390x__)
152 #define bpf_target_s930x
153#elif defined(__aarch64__)
154 #define bpf_target_arm64
155#elif defined(__mips__)
156 #define bpf_target_mips
157#elif defined(__powerpc__)
158 #define bpf_target_powerpc
159#elif defined(__sparc__)
160 #define bpf_target_sparc
161#endif
162#endif
163
164#if defined(bpf_target_x86)
113 165
114#define PT_REGS_PARM1(x) ((x)->di) 166#define PT_REGS_PARM1(x) ((x)->di)
115#define PT_REGS_PARM2(x) ((x)->si) 167#define PT_REGS_PARM2(x) ((x)->si)
@@ -122,7 +174,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
122#define PT_REGS_SP(x) ((x)->sp) 174#define PT_REGS_SP(x) ((x)->sp)
123#define PT_REGS_IP(x) ((x)->ip) 175#define PT_REGS_IP(x) ((x)->ip)
124 176
125#elif defined(__s390x__) 177#elif defined(bpf_target_s390x)
126 178
127#define PT_REGS_PARM1(x) ((x)->gprs[2]) 179#define PT_REGS_PARM1(x) ((x)->gprs[2])
128#define PT_REGS_PARM2(x) ((x)->gprs[3]) 180#define PT_REGS_PARM2(x) ((x)->gprs[3])
@@ -135,7 +187,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
135#define PT_REGS_SP(x) ((x)->gprs[15]) 187#define PT_REGS_SP(x) ((x)->gprs[15])
136#define PT_REGS_IP(x) ((x)->psw.addr) 188#define PT_REGS_IP(x) ((x)->psw.addr)
137 189
138#elif defined(__aarch64__) 190#elif defined(bpf_target_arm64)
139 191
140#define PT_REGS_PARM1(x) ((x)->regs[0]) 192#define PT_REGS_PARM1(x) ((x)->regs[0])
141#define PT_REGS_PARM2(x) ((x)->regs[1]) 193#define PT_REGS_PARM2(x) ((x)->regs[1])
@@ -148,7 +200,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
148#define PT_REGS_SP(x) ((x)->sp) 200#define PT_REGS_SP(x) ((x)->sp)
149#define PT_REGS_IP(x) ((x)->pc) 201#define PT_REGS_IP(x) ((x)->pc)
150 202
151#elif defined(__mips__) 203#elif defined(bpf_target_mips)
152 204
153#define PT_REGS_PARM1(x) ((x)->regs[4]) 205#define PT_REGS_PARM1(x) ((x)->regs[4])
154#define PT_REGS_PARM2(x) ((x)->regs[5]) 206#define PT_REGS_PARM2(x) ((x)->regs[5])
@@ -161,7 +213,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
161#define PT_REGS_SP(x) ((x)->regs[29]) 213#define PT_REGS_SP(x) ((x)->regs[29])
162#define PT_REGS_IP(x) ((x)->cp0_epc) 214#define PT_REGS_IP(x) ((x)->cp0_epc)
163 215
164#elif defined(__powerpc__) 216#elif defined(bpf_target_powerpc)
165 217
166#define PT_REGS_PARM1(x) ((x)->gpr[3]) 218#define PT_REGS_PARM1(x) ((x)->gpr[3])
167#define PT_REGS_PARM2(x) ((x)->gpr[4]) 219#define PT_REGS_PARM2(x) ((x)->gpr[4])
@@ -172,7 +224,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
172#define PT_REGS_SP(x) ((x)->sp) 224#define PT_REGS_SP(x) ((x)->sp)
173#define PT_REGS_IP(x) ((x)->nip) 225#define PT_REGS_IP(x) ((x)->nip)
174 226
175#elif defined(__sparc__) 227#elif defined(bpf_target_sparc)
176 228
177#define PT_REGS_PARM1(x) ((x)->u_regs[UREG_I0]) 229#define PT_REGS_PARM1(x) ((x)->u_regs[UREG_I0])
178#define PT_REGS_PARM2(x) ((x)->u_regs[UREG_I1]) 230#define PT_REGS_PARM2(x) ((x)->u_regs[UREG_I1])
@@ -182,6 +234,8 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
182#define PT_REGS_RET(x) ((x)->u_regs[UREG_I7]) 234#define PT_REGS_RET(x) ((x)->u_regs[UREG_I7])
183#define PT_REGS_RC(x) ((x)->u_regs[UREG_I0]) 235#define PT_REGS_RC(x) ((x)->u_regs[UREG_I0])
184#define PT_REGS_SP(x) ((x)->u_regs[UREG_FP]) 236#define PT_REGS_SP(x) ((x)->u_regs[UREG_FP])
237
238/* Should this also be a bpf_target check for the sparc case? */
185#if defined(__arch64__) 239#if defined(__arch64__)
186#define PT_REGS_IP(x) ((x)->tpc) 240#define PT_REGS_IP(x) ((x)->tpc)
187#else 241#else
@@ -190,10 +244,10 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
190 244
191#endif 245#endif
192 246
193#ifdef __powerpc__ 247#ifdef bpf_target_powerpc
194#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = (ctx)->link; }) 248#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = (ctx)->link; })
195#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP 249#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
196#elif defined(__sparc__) 250#elif bpf_target_sparc
197#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = PT_REGS_RET(ctx); }) 251#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = PT_REGS_RET(ctx); })
198#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP 252#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
199#else 253#else
diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h
index 20ecbaa0d85d..d0811b3d6a6f 100644
--- a/tools/testing/selftests/bpf/bpf_util.h
+++ b/tools/testing/selftests/bpf/bpf_util.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __BPF_UTIL__ 2#ifndef __BPF_UTIL__
2#define __BPF_UTIL__ 3#define __BPF_UTIL__
3 4
@@ -12,6 +13,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
12 unsigned int start, end, possible_cpus = 0; 13 unsigned int start, end, possible_cpus = 0;
13 char buff[128]; 14 char buff[128];
14 FILE *fp; 15 FILE *fp;
16 int n;
15 17
16 fp = fopen(fcpu, "r"); 18 fp = fopen(fcpu, "r");
17 if (!fp) { 19 if (!fp) {
@@ -20,17 +22,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
20 } 22 }
21 23
22 while (fgets(buff, sizeof(buff), fp)) { 24 while (fgets(buff, sizeof(buff), fp)) {
23 if (sscanf(buff, "%u-%u", &start, &end) == 2) { 25 n = sscanf(buff, "%u-%u", &start, &end);
24 possible_cpus = start == 0 ? end + 1 : 0; 26 if (n == 0) {
25 break; 27 printf("Failed to retrieve # possible CPUs!\n");
28 exit(1);
29 } else if (n == 1) {
30 end = start;
26 } 31 }
32 possible_cpus = start == 0 ? end + 1 : 0;
33 break;
27 } 34 }
28
29 fclose(fp); 35 fclose(fp);
30 if (!possible_cpus) {
31 printf("Failed to retrieve # possible CPUs!\n");
32 exit(1);
33 }
34 36
35 return possible_cpus; 37 return possible_cpus;
36} 38}
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
new file mode 100644
index 000000000000..f3bca3ade0f3
--- /dev/null
+++ b/tools/testing/selftests/bpf/cgroup_helpers.c
@@ -0,0 +1,178 @@
1// SPDX-License-Identifier: GPL-2.0
2#define _GNU_SOURCE
3#include <sched.h>
4#include <sys/mount.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7#include <linux/limits.h>
8#include <stdio.h>
9#include <linux/sched.h>
10#include <fcntl.h>
11#include <unistd.h>
12#include <ftw.h>
13
14
15#include "cgroup_helpers.h"
16
17/*
18 * To avoid relying on the system setup, when setup_cgroup_env is called
19 * we create a new mount namespace, and cgroup namespace. The cgroup2
20 * root is mounted at CGROUP_MOUNT_PATH
21 *
22 * Unfortunately, most people don't have cgroupv2 enabled at this point in time.
23 * It's easier to create our own mount namespace and manage it ourselves.
24 *
25 * We assume /mnt exists.
26 */
27
28#define WALK_FD_LIMIT 16
29#define CGROUP_MOUNT_PATH "/mnt"
30#define CGROUP_WORK_DIR "/cgroup-test-work-dir"
31#define format_cgroup_path(buf, path) \
32 snprintf(buf, sizeof(buf), "%s%s%s", CGROUP_MOUNT_PATH, \
33 CGROUP_WORK_DIR, path)
34
35/**
36 * setup_cgroup_environment() - Setup the cgroup environment
37 *
38 * After calling this function, cleanup_cgroup_environment should be called
39 * once testing is complete.
40 *
41 * This function will print an error to stderr and return 1 if it is unable
42 * to setup the cgroup environment. If setup is successful, 0 is returned.
43 */
44int setup_cgroup_environment(void)
45{
46 char cgroup_workdir[PATH_MAX + 1];
47
48 format_cgroup_path(cgroup_workdir, "");
49
50 if (unshare(CLONE_NEWNS)) {
51 log_err("unshare");
52 return 1;
53 }
54
55 if (mount("none", "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
56 log_err("mount fakeroot");
57 return 1;
58 }
59
60 if (mount("none", CGROUP_MOUNT_PATH, "cgroup2", 0, NULL) && errno != EBUSY) {
61 log_err("mount cgroup2");
62 return 1;
63 }
64
65 /* Cleanup existing failed runs, now that the environment is setup */
66 cleanup_cgroup_environment();
67
68 if (mkdir(cgroup_workdir, 0777) && errno != EEXIST) {
69 log_err("mkdir cgroup work dir");
70 return 1;
71 }
72
73 return 0;
74}
75
76static int nftwfunc(const char *filename, const struct stat *statptr,
77 int fileflags, struct FTW *pfwt)
78{
79 if ((fileflags & FTW_D) && rmdir(filename))
80 log_err("Removing cgroup: %s", filename);
81 return 0;
82}
83
84
85static int join_cgroup_from_top(char *cgroup_path)
86{
87 char cgroup_procs_path[PATH_MAX + 1];
88 pid_t pid = getpid();
89 int fd, rc = 0;
90
91 snprintf(cgroup_procs_path, sizeof(cgroup_procs_path),
92 "%s/cgroup.procs", cgroup_path);
93
94 fd = open(cgroup_procs_path, O_WRONLY);
95 if (fd < 0) {
96 log_err("Opening Cgroup Procs: %s", cgroup_procs_path);
97 return 1;
98 }
99
100 if (dprintf(fd, "%d\n", pid) < 0) {
101 log_err("Joining Cgroup");
102 rc = 1;
103 }
104
105 close(fd);
106 return rc;
107}
108
109/**
110 * join_cgroup() - Join a cgroup
111 * @path: The cgroup path, relative to the workdir, to join
112 *
113 * This function expects a cgroup to already be created, relative to the cgroup
114 * work dir, and it joins it. For example, passing "/my-cgroup" as the path
115 * would actually put the calling process into the cgroup
116 * "/cgroup-test-work-dir/my-cgroup"
117 *
118 * On success, it returns 0, otherwise on failure it returns 1.
119 */
120int join_cgroup(char *path)
121{
122 char cgroup_path[PATH_MAX + 1];
123
124 format_cgroup_path(cgroup_path, path);
125 return join_cgroup_from_top(cgroup_path);
126}
127
128/**
129 * cleanup_cgroup_environment() - Cleanup Cgroup Testing Environment
130 *
131 * This is an idempotent function to delete all temporary cgroups that
132 * have been created during the test, including the cgroup testing work
133 * directory.
134 *
135 * At call time, it moves the calling process to the root cgroup, and then
136 * runs the deletion process. It is idempotent, and should not fail, unless
137 * a process is lingering.
138 *
139 * On failure, it will print an error to stderr, and try to continue.
140 */
141void cleanup_cgroup_environment(void)
142{
143 char cgroup_workdir[PATH_MAX + 1];
144
145 format_cgroup_path(cgroup_workdir, "");
146 join_cgroup_from_top(CGROUP_MOUNT_PATH);
147 nftw(cgroup_workdir, nftwfunc, WALK_FD_LIMIT, FTW_DEPTH | FTW_MOUNT);
148}
149
150/**
151 * create_and_get_cgroup() - Create a cgroup, relative to workdir, and get the FD
152 * @path: The cgroup path, relative to the workdir, to join
153 *
154 * This function creates a cgroup under the top level workdir and returns the
155 * file descriptor. It is idempotent.
156 *
157 * On success, it returns the file descriptor. On failure it returns 0.
158 * If there is a failure, it prints the error to stderr.
159 */
160int create_and_get_cgroup(char *path)
161{
162 char cgroup_path[PATH_MAX + 1];
163 int fd;
164
165 format_cgroup_path(cgroup_path, path);
166 if (mkdir(cgroup_path, 0777) && errno != EEXIST) {
167 log_err("mkdiring cgroup %s .. %s", path, cgroup_path);
168 return 0;
169 }
170
171 fd = open(cgroup_path, O_RDONLY);
172 if (fd < 0) {
173 log_err("Opening Cgroup");
174 return 0;
175 }
176
177 return fd;
178}
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.h b/tools/testing/selftests/bpf/cgroup_helpers.h
new file mode 100644
index 000000000000..06485e0002b3
--- /dev/null
+++ b/tools/testing/selftests/bpf/cgroup_helpers.h
@@ -0,0 +1,17 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __CGROUP_HELPERS_H
3#define __CGROUP_HELPERS_H
4#include <errno.h>
5#include <string.h>
6
7#define clean_errno() (errno == 0 ? "None" : strerror(errno))
8#define log_err(MSG, ...) fprintf(stderr, "(%s:%d: errno: %s) " MSG "\n", \
9 __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
10
11
12int create_and_get_cgroup(char *path);
13int join_cgroup(char *path);
14int setup_cgroup_environment(void);
15void cleanup_cgroup_environment(void);
16
17#endif
diff --git a/tools/testing/selftests/bpf/dev_cgroup.c b/tools/testing/selftests/bpf/dev_cgroup.c
new file mode 100644
index 000000000000..ce41a3475f27
--- /dev/null
+++ b/tools/testing/selftests/bpf/dev_cgroup.c
@@ -0,0 +1,60 @@
1/* Copyright (c) 2017 Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7
8#include <linux/bpf.h>
9#include <linux/version.h>
10#include "bpf_helpers.h"
11
12SEC("cgroup/dev")
13int bpf_prog1(struct bpf_cgroup_dev_ctx *ctx)
14{
15 short type = ctx->access_type & 0xFFFF;
16#ifdef DEBUG
17 short access = ctx->access_type >> 16;
18 char fmt[] = " %d:%d \n";
19
20 switch (type) {
21 case BPF_DEVCG_DEV_BLOCK:
22 fmt[0] = 'b';
23 break;
24 case BPF_DEVCG_DEV_CHAR:
25 fmt[0] = 'c';
26 break;
27 default:
28 fmt[0] = '?';
29 break;
30 }
31
32 if (access & BPF_DEVCG_ACC_READ)
33 fmt[8] = 'r';
34
35 if (access & BPF_DEVCG_ACC_WRITE)
36 fmt[9] = 'w';
37
38 if (access & BPF_DEVCG_ACC_MKNOD)
39 fmt[10] = 'm';
40
41 bpf_trace_printk(fmt, sizeof(fmt), ctx->major, ctx->minor);
42#endif
43
44 /* Allow access to /dev/zero and /dev/random.
45 * Forbid everything else.
46 */
47 if (ctx->major != 1 || type != BPF_DEVCG_DEV_CHAR)
48 return 0;
49
50 switch (ctx->minor) {
51 case 5: /* 1:5 /dev/zero */
52 case 9: /* 1:9 /dev/urandom */
53 return 1;
54 }
55
56 return 0;
57}
58
59char _license[] SEC("license") = "GPL";
60__u32 _version SEC("version") = LINUX_VERSION_CODE;
diff --git a/tools/testing/selftests/bpf/include/uapi/linux/types.h b/tools/testing/selftests/bpf/include/uapi/linux/types.h
index 51841848fbfe..91fa51a9c31d 100644
--- a/tools/testing/selftests/bpf/include/uapi/linux/types.h
+++ b/tools/testing/selftests/bpf/include/uapi/linux/types.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _UAPI_LINUX_TYPES_H 2#ifndef _UAPI_LINUX_TYPES_H
2#define _UAPI_LINUX_TYPES_H 3#define _UAPI_LINUX_TYPES_H
3 4
diff --git a/tools/testing/selftests/bpf/sockmap_parse_prog.c b/tools/testing/selftests/bpf/sockmap_parse_prog.c
index fae3b96c3aa4..a1dec2b6d9c5 100644
--- a/tools/testing/selftests/bpf/sockmap_parse_prog.c
+++ b/tools/testing/selftests/bpf/sockmap_parse_prog.c
@@ -29,9 +29,6 @@ int bpf_prog1(struct __sk_buff *skb)
29 * fields. 29 * fields.
30 */ 30 */
31 d[7] = 1; 31 d[7] = 1;
32
33 bpf_printk("parse: data[0] = (%u): local_port %i remote %i\n",
34 d[0], lport, bpf_ntohl(rport));
35 return skb->len; 32 return skb->len;
36} 33}
37 34
diff --git a/tools/testing/selftests/bpf/sockmap_verdict_prog.c b/tools/testing/selftests/bpf/sockmap_verdict_prog.c
index 9b99bd10807d..d7bea972cb21 100644
--- a/tools/testing/selftests/bpf/sockmap_verdict_prog.c
+++ b/tools/testing/selftests/bpf/sockmap_verdict_prog.c
@@ -58,11 +58,9 @@ int bpf_prog2(struct __sk_buff *skb)
58 d[6] = 0xe; 58 d[6] = 0xe;
59 d[7] = 0xf; 59 d[7] = 0xf;
60 60
61 bpf_printk("verdict: data[0] = redir(%u:%u)\n", map, sk);
62
63 if (!map) 61 if (!map)
64 return bpf_sk_redirect_map(&sock_map_rx, sk, 0); 62 return bpf_sk_redirect_map(skb, &sock_map_rx, sk, 0);
65 return bpf_sk_redirect_map(&sock_map_tx, sk, 0); 63 return bpf_sk_redirect_map(skb, &sock_map_tx, sk, 0);
66} 64}
67 65
68char _license[] SEC("license") = "GPL"; 66char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/test_dev_cgroup.c b/tools/testing/selftests/bpf/test_dev_cgroup.c
new file mode 100644
index 000000000000..02c85d6c89b0
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_dev_cgroup.c
@@ -0,0 +1,93 @@
1/* Copyright (c) 2017 Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <errno.h>
12#include <assert.h>
13
14#include <linux/bpf.h>
15#include <bpf/bpf.h>
16#include <bpf/libbpf.h>
17
18#include "cgroup_helpers.h"
19
20#define DEV_CGROUP_PROG "./dev_cgroup.o"
21
22#define TEST_CGROUP "test-bpf-based-device-cgroup/"
23
24int main(int argc, char **argv)
25{
26 struct bpf_object *obj;
27 int error = EXIT_FAILURE;
28 int prog_fd, cgroup_fd;
29 __u32 prog_cnt;
30
31 if (bpf_prog_load(DEV_CGROUP_PROG, BPF_PROG_TYPE_CGROUP_DEVICE,
32 &obj, &prog_fd)) {
33 printf("Failed to load DEV_CGROUP program\n");
34 goto err;
35 }
36
37 if (setup_cgroup_environment()) {
38 printf("Failed to load DEV_CGROUP program\n");
39 goto err;
40 }
41
42 /* Create a cgroup, get fd, and join it */
43 cgroup_fd = create_and_get_cgroup(TEST_CGROUP);
44 if (!cgroup_fd) {
45 printf("Failed to create test cgroup\n");
46 goto err;
47 }
48
49 if (join_cgroup(TEST_CGROUP)) {
50 printf("Failed to join cgroup\n");
51 goto err;
52 }
53
54 /* Attach bpf program */
55 if (bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_DEVICE, 0)) {
56 printf("Failed to attach DEV_CGROUP program");
57 goto err;
58 }
59
60 if (bpf_prog_query(cgroup_fd, BPF_CGROUP_DEVICE, 0, NULL, NULL,
61 &prog_cnt)) {
62 printf("Failed to query attached programs");
63 goto err;
64 }
65
66 /* All operations with /dev/zero and and /dev/urandom are allowed,
67 * everything else is forbidden.
68 */
69 assert(system("rm -f /tmp/test_dev_cgroup_null") == 0);
70 assert(system("mknod /tmp/test_dev_cgroup_null c 1 3"));
71 assert(system("rm -f /tmp/test_dev_cgroup_null") == 0);
72
73 /* /dev/zero is whitelisted */
74 assert(system("rm -f /tmp/test_dev_cgroup_zero") == 0);
75 assert(system("mknod /tmp/test_dev_cgroup_zero c 1 5") == 0);
76 assert(system("rm -f /tmp/test_dev_cgroup_zero") == 0);
77
78 assert(system("dd if=/dev/urandom of=/dev/zero count=64") == 0);
79
80 /* src is allowed, target is forbidden */
81 assert(system("dd if=/dev/urandom of=/dev/full count=64"));
82
83 /* src is forbidden, target is allowed */
84 assert(system("dd if=/dev/random of=/dev/zero count=64"));
85
86 error = 0;
87 printf("test_dev_cgroup:PASS\n");
88
89err:
90 cleanup_cgroup_environment();
91
92 return error;
93}
diff --git a/tools/testing/selftests/bpf/test_kmod.sh b/tools/testing/selftests/bpf/test_kmod.sh
index 6d58cca8e235..ed4774d8d6ed 100755
--- a/tools/testing/selftests/bpf/test_kmod.sh
+++ b/tools/testing/selftests/bpf/test_kmod.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3SRC_TREE=../../../../ 4SRC_TREE=../../../../
4 5
diff --git a/tools/testing/selftests/bpf/test_lpm_map.c b/tools/testing/selftests/bpf/test_lpm_map.c
index e97565243d59..f61480641b6e 100644
--- a/tools/testing/selftests/bpf/test_lpm_map.c
+++ b/tools/testing/selftests/bpf/test_lpm_map.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Randomized tests for eBPF longest-prefix-match maps 3 * Randomized tests for eBPF longest-prefix-match maps
3 * 4 *
@@ -31,6 +32,10 @@ struct tlpm_node {
31 uint8_t key[]; 32 uint8_t key[];
32}; 33};
33 34
35static struct tlpm_node *tlpm_match(struct tlpm_node *list,
36 const uint8_t *key,
37 size_t n_bits);
38
34static struct tlpm_node *tlpm_add(struct tlpm_node *list, 39static struct tlpm_node *tlpm_add(struct tlpm_node *list,
35 const uint8_t *key, 40 const uint8_t *key,
36 size_t n_bits) 41 size_t n_bits)
@@ -38,9 +43,17 @@ static struct tlpm_node *tlpm_add(struct tlpm_node *list,
38 struct tlpm_node *node; 43 struct tlpm_node *node;
39 size_t n; 44 size_t n;
40 45
46 n = (n_bits + 7) / 8;
47
48 /* 'overwrite' an equivalent entry if one already exists */
49 node = tlpm_match(list, key, n_bits);
50 if (node && node->n_bits == n_bits) {
51 memcpy(node->key, key, n);
52 return list;
53 }
54
41 /* add new entry with @key/@n_bits to @list and return new head */ 55 /* add new entry with @key/@n_bits to @list and return new head */
42 56
43 n = (n_bits + 7) / 8;
44 node = malloc(sizeof(*node) + n); 57 node = malloc(sizeof(*node) + n);
45 assert(node); 58 assert(node);
46 59
@@ -92,6 +105,34 @@ static struct tlpm_node *tlpm_match(struct tlpm_node *list,
92 return best; 105 return best;
93} 106}
94 107
108static struct tlpm_node *tlpm_delete(struct tlpm_node *list,
109 const uint8_t *key,
110 size_t n_bits)
111{
112 struct tlpm_node *best = tlpm_match(list, key, n_bits);
113 struct tlpm_node *node;
114
115 if (!best || best->n_bits != n_bits)
116 return list;
117
118 if (best == list) {
119 node = best->next;
120 free(best);
121 return node;
122 }
123
124 for (node = list; node; node = node->next) {
125 if (node->next == best) {
126 node->next = best->next;
127 free(best);
128 return list;
129 }
130 }
131 /* should never get here */
132 assert(0);
133 return list;
134}
135
95static void test_lpm_basic(void) 136static void test_lpm_basic(void)
96{ 137{
97 struct tlpm_node *list = NULL, *t1, *t2; 138 struct tlpm_node *list = NULL, *t1, *t2;
@@ -114,6 +155,13 @@ static void test_lpm_basic(void)
114 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff, 0xff }, 15)); 155 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff, 0xff }, 15));
115 assert(!tlpm_match(list, (uint8_t[]){ 0x7f, 0xff }, 16)); 156 assert(!tlpm_match(list, (uint8_t[]){ 0x7f, 0xff }, 16));
116 157
158 list = tlpm_delete(list, (uint8_t[]){ 0xff, 0xff }, 16);
159 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff }, 8));
160 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff, 0xff }, 16));
161
162 list = tlpm_delete(list, (uint8_t[]){ 0xff }, 8);
163 assert(!tlpm_match(list, (uint8_t[]){ 0xff }, 8));
164
117 tlpm_clear(list); 165 tlpm_clear(list);
118} 166}
119 167
@@ -158,7 +206,7 @@ static void test_lpm_order(void)
158 206
159static void test_lpm_map(int keysize) 207static void test_lpm_map(int keysize)
160{ 208{
161 size_t i, j, n_matches, n_nodes, n_lookups; 209 size_t i, j, n_matches, n_matches_after_delete, n_nodes, n_lookups;
162 struct tlpm_node *t, *list = NULL; 210 struct tlpm_node *t, *list = NULL;
163 struct bpf_lpm_trie_key *key; 211 struct bpf_lpm_trie_key *key;
164 uint8_t *data, *value; 212 uint8_t *data, *value;
@@ -170,6 +218,7 @@ static void test_lpm_map(int keysize)
170 */ 218 */
171 219
172 n_matches = 0; 220 n_matches = 0;
221 n_matches_after_delete = 0;
173 n_nodes = 1 << 8; 222 n_nodes = 1 << 8;
174 n_lookups = 1 << 16; 223 n_lookups = 1 << 16;
175 224
@@ -223,15 +272,54 @@ static void test_lpm_map(int keysize)
223 } 272 }
224 } 273 }
225 274
275 /* Remove the first half of the elements in the tlpm and the
276 * corresponding nodes from the bpf-lpm. Then run the same
277 * large number of random lookups in both and make sure they match.
278 * Note: we need to count the number of nodes actually inserted
279 * since there may have been duplicates.
280 */
281 for (i = 0, t = list; t; i++, t = t->next)
282 ;
283 for (j = 0; j < i / 2; ++j) {
284 key->prefixlen = list->n_bits;
285 memcpy(key->data, list->key, keysize);
286 r = bpf_map_delete_elem(map, key);
287 assert(!r);
288 list = tlpm_delete(list, list->key, list->n_bits);
289 assert(list);
290 }
291 for (i = 0; i < n_lookups; ++i) {
292 for (j = 0; j < keysize; ++j)
293 data[j] = rand() & 0xff;
294
295 t = tlpm_match(list, data, 8 * keysize);
296
297 key->prefixlen = 8 * keysize;
298 memcpy(key->data, data, keysize);
299 r = bpf_map_lookup_elem(map, key, value);
300 assert(!r || errno == ENOENT);
301 assert(!t == !!r);
302
303 if (t) {
304 ++n_matches_after_delete;
305 assert(t->n_bits == value[keysize]);
306 for (j = 0; j < t->n_bits; ++j)
307 assert((t->key[j / 8] & (1 << (7 - j % 8))) ==
308 (value[j / 8] & (1 << (7 - j % 8))));
309 }
310 }
311
226 close(map); 312 close(map);
227 tlpm_clear(list); 313 tlpm_clear(list);
228 314
229 /* With 255 random nodes in the map, we are pretty likely to match 315 /* With 255 random nodes in the map, we are pretty likely to match
230 * something on every lookup. For statistics, use this: 316 * something on every lookup. For statistics, use this:
231 * 317 *
232 * printf(" nodes: %zu\n" 318 * printf(" nodes: %zu\n"
233 * "lookups: %zu\n" 319 * " lookups: %zu\n"
234 * "matches: %zu\n", n_nodes, n_lookups, n_matches); 320 * " matches: %zu\n"
321 * "matches(delete): %zu\n",
322 * n_nodes, n_lookups, n_matches, n_matches_after_delete);
235 */ 323 */
236} 324}
237 325
@@ -331,6 +419,108 @@ static void test_lpm_ipaddr(void)
331 close(map_fd_ipv6); 419 close(map_fd_ipv6);
332} 420}
333 421
422static void test_lpm_delete(void)
423{
424 struct bpf_lpm_trie_key *key;
425 size_t key_size;
426 int map_fd;
427 __u64 value;
428
429 key_size = sizeof(*key) + sizeof(__u32);
430 key = alloca(key_size);
431
432 map_fd = bpf_create_map(BPF_MAP_TYPE_LPM_TRIE,
433 key_size, sizeof(value),
434 100, BPF_F_NO_PREALLOC);
435 assert(map_fd >= 0);
436
437 /* Add nodes:
438 * 192.168.0.0/16 (1)
439 * 192.168.0.0/24 (2)
440 * 192.168.128.0/24 (3)
441 * 192.168.1.0/24 (4)
442 *
443 * (1)
444 * / \
445 * (IM) (3)
446 * / \
447 * (2) (4)
448 */
449 value = 1;
450 key->prefixlen = 16;
451 inet_pton(AF_INET, "192.168.0.0", key->data);
452 assert(bpf_map_update_elem(map_fd, key, &value, 0) == 0);
453
454 value = 2;
455 key->prefixlen = 24;
456 inet_pton(AF_INET, "192.168.0.0", key->data);
457 assert(bpf_map_update_elem(map_fd, key, &value, 0) == 0);
458
459 value = 3;
460 key->prefixlen = 24;
461 inet_pton(AF_INET, "192.168.128.0", key->data);
462 assert(bpf_map_update_elem(map_fd, key, &value, 0) == 0);
463
464 value = 4;
465 key->prefixlen = 24;
466 inet_pton(AF_INET, "192.168.1.0", key->data);
467 assert(bpf_map_update_elem(map_fd, key, &value, 0) == 0);
468
469 /* remove non-existent node */
470 key->prefixlen = 32;
471 inet_pton(AF_INET, "10.0.0.1", key->data);
472 assert(bpf_map_lookup_elem(map_fd, key, &value) == -1 &&
473 errno == ENOENT);
474
475 /* assert initial lookup */
476 key->prefixlen = 32;
477 inet_pton(AF_INET, "192.168.0.1", key->data);
478 assert(bpf_map_lookup_elem(map_fd, key, &value) == 0);
479 assert(value == 2);
480
481 /* remove leaf node */
482 key->prefixlen = 24;
483 inet_pton(AF_INET, "192.168.0.0", key->data);
484 assert(bpf_map_delete_elem(map_fd, key) == 0);
485
486 key->prefixlen = 32;
487 inet_pton(AF_INET, "192.168.0.1", key->data);
488 assert(bpf_map_lookup_elem(map_fd, key, &value) == 0);
489 assert(value == 1);
490
491 /* remove leaf (and intermediary) node */
492 key->prefixlen = 24;
493 inet_pton(AF_INET, "192.168.1.0", key->data);
494 assert(bpf_map_delete_elem(map_fd, key) == 0);
495
496 key->prefixlen = 32;
497 inet_pton(AF_INET, "192.168.1.1", key->data);
498 assert(bpf_map_lookup_elem(map_fd, key, &value) == 0);
499 assert(value == 1);
500
501 /* remove root node */
502 key->prefixlen = 16;
503 inet_pton(AF_INET, "192.168.0.0", key->data);
504 assert(bpf_map_delete_elem(map_fd, key) == 0);
505
506 key->prefixlen = 32;
507 inet_pton(AF_INET, "192.168.128.1", key->data);
508 assert(bpf_map_lookup_elem(map_fd, key, &value) == 0);
509 assert(value == 3);
510
511 /* remove last node */
512 key->prefixlen = 24;
513 inet_pton(AF_INET, "192.168.128.0", key->data);
514 assert(bpf_map_delete_elem(map_fd, key) == 0);
515
516 key->prefixlen = 32;
517 inet_pton(AF_INET, "192.168.128.1", key->data);
518 assert(bpf_map_lookup_elem(map_fd, key, &value) == -1 &&
519 errno == ENOENT);
520
521 close(map_fd);
522}
523
334int main(void) 524int main(void)
335{ 525{
336 struct rlimit limit = { RLIM_INFINITY, RLIM_INFINITY }; 526 struct rlimit limit = { RLIM_INFINITY, RLIM_INFINITY };
@@ -353,6 +543,8 @@ int main(void)
353 543
354 test_lpm_ipaddr(); 544 test_lpm_ipaddr();
355 545
546 test_lpm_delete();
547
356 printf("test_lpm: OK\n"); 548 printf("test_lpm: OK\n");
357 return 0; 549 return 0;
358} 550}
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index fe3a443a1102..040356ecc862 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -466,7 +466,7 @@ static void test_sockmap(int tasks, void *data)
466 int one = 1, map_fd_rx, map_fd_tx, map_fd_break, s, sc, rc; 466 int one = 1, map_fd_rx, map_fd_tx, map_fd_break, s, sc, rc;
467 struct bpf_map *bpf_map_rx, *bpf_map_tx, *bpf_map_break; 467 struct bpf_map *bpf_map_rx, *bpf_map_tx, *bpf_map_break;
468 int ports[] = {50200, 50201, 50202, 50204}; 468 int ports[] = {50200, 50201, 50202, 50204};
469 int err, i, fd, sfd[6] = {0xdeadbeef}; 469 int err, i, fd, udp, sfd[6] = {0xdeadbeef};
470 u8 buf[20] = {0x0, 0x5, 0x3, 0x2, 0x1, 0x0}; 470 u8 buf[20] = {0x0, 0x5, 0x3, 0x2, 0x1, 0x0};
471 int parse_prog, verdict_prog; 471 int parse_prog, verdict_prog;
472 struct sockaddr_in addr; 472 struct sockaddr_in addr;
@@ -548,6 +548,16 @@ static void test_sockmap(int tasks, void *data)
548 goto out_sockmap; 548 goto out_sockmap;
549 } 549 }
550 550
551 /* Test update with unsupported UDP socket */
552 udp = socket(AF_INET, SOCK_DGRAM, 0);
553 i = 0;
554 err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY);
555 if (!err) {
556 printf("Failed socket SOCK_DGRAM allowed '%i:%i'\n",
557 i, udp);
558 goto out_sockmap;
559 }
560
551 /* Test update without programs */ 561 /* Test update without programs */
552 for (i = 0; i < 6; i++) { 562 for (i = 0; i < 6; i++) {
553 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); 563 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY);
@@ -1033,6 +1043,51 @@ static void test_map_parallel(void)
1033 assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT); 1043 assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT);
1034} 1044}
1035 1045
1046static void test_map_rdonly(void)
1047{
1048 int fd, key = 0, value = 0;
1049
1050 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value),
1051 MAP_SIZE, map_flags | BPF_F_RDONLY);
1052 if (fd < 0) {
1053 printf("Failed to create map for read only test '%s'!\n",
1054 strerror(errno));
1055 exit(1);
1056 }
1057
1058 key = 1;
1059 value = 1234;
1060 /* Insert key=1 element. */
1061 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == -1 &&
1062 errno == EPERM);
1063
1064 /* Check that key=2 is not found. */
1065 assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT);
1066 assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == ENOENT);
1067}
1068
1069static void test_map_wronly(void)
1070{
1071 int fd, key = 0, value = 0;
1072
1073 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value),
1074 MAP_SIZE, map_flags | BPF_F_WRONLY);
1075 if (fd < 0) {
1076 printf("Failed to create map for read only test '%s'!\n",
1077 strerror(errno));
1078 exit(1);
1079 }
1080
1081 key = 1;
1082 value = 1234;
1083 /* Insert key=1 element. */
1084 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0);
1085
1086 /* Check that key=2 is not found. */
1087 assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == EPERM);
1088 assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == EPERM);
1089}
1090
1036static void run_all_tests(void) 1091static void run_all_tests(void)
1037{ 1092{
1038 test_hashmap(0, NULL); 1093 test_hashmap(0, NULL);
@@ -1050,6 +1105,9 @@ static void run_all_tests(void)
1050 test_map_large(); 1105 test_map_large();
1051 test_map_parallel(); 1106 test_map_parallel();
1052 test_map_stress(); 1107 test_map_stress();
1108
1109 test_map_rdonly();
1110 test_map_wronly();
1053} 1111}
1054 1112
1055int main(void) 1113int main(void)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 11ee25cea227..69427531408d 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -10,6 +10,7 @@
10#include <string.h> 10#include <string.h>
11#include <assert.h> 11#include <assert.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <time.h>
13 14
14#include <linux/types.h> 15#include <linux/types.h>
15typedef __u16 __sum16; 16typedef __u16 __sum16;
@@ -19,6 +20,8 @@ typedef __u16 __sum16;
19#include <linux/ip.h> 20#include <linux/ip.h>
20#include <linux/ipv6.h> 21#include <linux/ipv6.h>
21#include <linux/tcp.h> 22#include <linux/tcp.h>
23#include <linux/filter.h>
24#include <linux/unistd.h>
22 25
23#include <sys/wait.h> 26#include <sys/wait.h>
24#include <sys/resource.h> 27#include <sys/resource.h>
@@ -273,16 +276,26 @@ static void test_bpf_obj_id(void)
273 const int nr_iters = 2; 276 const int nr_iters = 2;
274 const char *file = "./test_obj_id.o"; 277 const char *file = "./test_obj_id.o";
275 const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable"; 278 const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
279 const char *expected_prog_name = "test_obj_id";
280 const char *expected_map_name = "test_map_id";
281 const __u64 nsec_per_sec = 1000000000;
276 282
277 struct bpf_object *objs[nr_iters]; 283 struct bpf_object *objs[nr_iters];
278 int prog_fds[nr_iters], map_fds[nr_iters]; 284 int prog_fds[nr_iters], map_fds[nr_iters];
279 /* +1 to test for the info_len returned by kernel */ 285 /* +1 to test for the info_len returned by kernel */
280 struct bpf_prog_info prog_infos[nr_iters + 1]; 286 struct bpf_prog_info prog_infos[nr_iters + 1];
281 struct bpf_map_info map_infos[nr_iters + 1]; 287 struct bpf_map_info map_infos[nr_iters + 1];
288 /* Each prog only uses one map. +1 to test nr_map_ids
289 * returned by kernel.
290 */
291 __u32 map_ids[nr_iters + 1];
282 char jited_insns[128], xlated_insns[128], zeros[128]; 292 char jited_insns[128], xlated_insns[128], zeros[128];
283 __u32 i, next_id, info_len, nr_id_found, duration = 0; 293 __u32 i, next_id, info_len, nr_id_found, duration = 0;
294 struct timespec real_time_ts, boot_time_ts;
284 int sysctl_fd, jit_enabled = 0, err = 0; 295 int sysctl_fd, jit_enabled = 0, err = 0;
285 __u64 array_value; 296 __u64 array_value;
297 uid_t my_uid = getuid();
298 time_t now, load_time;
286 299
287 sysctl_fd = open(jit_sysctl, 0, O_RDONLY); 300 sysctl_fd = open(jit_sysctl, 0, O_RDONLY);
288 if (sysctl_fd != -1) { 301 if (sysctl_fd != -1) {
@@ -307,6 +320,7 @@ static void test_bpf_obj_id(void)
307 /* Check bpf_obj_get_info_by_fd() */ 320 /* Check bpf_obj_get_info_by_fd() */
308 bzero(zeros, sizeof(zeros)); 321 bzero(zeros, sizeof(zeros));
309 for (i = 0; i < nr_iters; i++) { 322 for (i = 0; i < nr_iters; i++) {
323 now = time(NULL);
310 err = bpf_prog_load(file, BPF_PROG_TYPE_SOCKET_FILTER, 324 err = bpf_prog_load(file, BPF_PROG_TYPE_SOCKET_FILTER,
311 &objs[i], &prog_fds[i]); 325 &objs[i], &prog_fds[i]);
312 /* test_obj_id.o is a dumb prog. It should never fail 326 /* test_obj_id.o is a dumb prog. It should never fail
@@ -316,6 +330,38 @@ static void test_bpf_obj_id(void)
316 error_cnt++; 330 error_cnt++;
317 assert(!err); 331 assert(!err);
318 332
333 /* Insert a magic value to the map */
334 map_fds[i] = bpf_find_map(__func__, objs[i], "test_map_id");
335 assert(map_fds[i] >= 0);
336 err = bpf_map_update_elem(map_fds[i], &array_key,
337 &array_magic_value, 0);
338 assert(!err);
339
340 /* Check getting map info */
341 info_len = sizeof(struct bpf_map_info) * 2;
342 bzero(&map_infos[i], info_len);
343 err = bpf_obj_get_info_by_fd(map_fds[i], &map_infos[i],
344 &info_len);
345 if (CHECK(err ||
346 map_infos[i].type != BPF_MAP_TYPE_ARRAY ||
347 map_infos[i].key_size != sizeof(__u32) ||
348 map_infos[i].value_size != sizeof(__u64) ||
349 map_infos[i].max_entries != 1 ||
350 map_infos[i].map_flags != 0 ||
351 info_len != sizeof(struct bpf_map_info) ||
352 strcmp((char *)map_infos[i].name, expected_map_name),
353 "get-map-info(fd)",
354 "err %d errno %d type %d(%d) info_len %u(%lu) key_size %u value_size %u max_entries %u map_flags %X name %s(%s)\n",
355 err, errno,
356 map_infos[i].type, BPF_MAP_TYPE_ARRAY,
357 info_len, sizeof(struct bpf_map_info),
358 map_infos[i].key_size,
359 map_infos[i].value_size,
360 map_infos[i].max_entries,
361 map_infos[i].map_flags,
362 map_infos[i].name, expected_map_name))
363 goto done;
364
319 /* Check getting prog info */ 365 /* Check getting prog info */
320 info_len = sizeof(struct bpf_prog_info) * 2; 366 info_len = sizeof(struct bpf_prog_info) * 2;
321 bzero(&prog_infos[i], info_len); 367 bzero(&prog_infos[i], info_len);
@@ -325,8 +371,16 @@ static void test_bpf_obj_id(void)
325 prog_infos[i].jited_prog_len = sizeof(jited_insns); 371 prog_infos[i].jited_prog_len = sizeof(jited_insns);
326 prog_infos[i].xlated_prog_insns = ptr_to_u64(xlated_insns); 372 prog_infos[i].xlated_prog_insns = ptr_to_u64(xlated_insns);
327 prog_infos[i].xlated_prog_len = sizeof(xlated_insns); 373 prog_infos[i].xlated_prog_len = sizeof(xlated_insns);
374 prog_infos[i].map_ids = ptr_to_u64(map_ids + i);
375 prog_infos[i].nr_map_ids = 2;
376 err = clock_gettime(CLOCK_REALTIME, &real_time_ts);
377 assert(!err);
378 err = clock_gettime(CLOCK_BOOTTIME, &boot_time_ts);
379 assert(!err);
328 err = bpf_obj_get_info_by_fd(prog_fds[i], &prog_infos[i], 380 err = bpf_obj_get_info_by_fd(prog_fds[i], &prog_infos[i],
329 &info_len); 381 &info_len);
382 load_time = (real_time_ts.tv_sec - boot_time_ts.tv_sec)
383 + (prog_infos[i].load_time / nsec_per_sec);
330 if (CHECK(err || 384 if (CHECK(err ||
331 prog_infos[i].type != BPF_PROG_TYPE_SOCKET_FILTER || 385 prog_infos[i].type != BPF_PROG_TYPE_SOCKET_FILTER ||
332 info_len != sizeof(struct bpf_prog_info) || 386 info_len != sizeof(struct bpf_prog_info) ||
@@ -334,9 +388,14 @@ static void test_bpf_obj_id(void)
334 (jit_enabled && 388 (jit_enabled &&
335 !memcmp(jited_insns, zeros, sizeof(zeros))) || 389 !memcmp(jited_insns, zeros, sizeof(zeros))) ||
336 !prog_infos[i].xlated_prog_len || 390 !prog_infos[i].xlated_prog_len ||
337 !memcmp(xlated_insns, zeros, sizeof(zeros)), 391 !memcmp(xlated_insns, zeros, sizeof(zeros)) ||
392 load_time < now - 60 || load_time > now + 60 ||
393 prog_infos[i].created_by_uid != my_uid ||
394 prog_infos[i].nr_map_ids != 1 ||
395 *(int *)prog_infos[i].map_ids != map_infos[i].id ||
396 strcmp((char *)prog_infos[i].name, expected_prog_name),
338 "get-prog-info(fd)", 397 "get-prog-info(fd)",
339 "err %d errno %d i %d type %d(%d) info_len %u(%lu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d\n", 398 "err %d errno %d i %d type %d(%d) info_len %u(%lu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d load_time %lu(%lu) uid %u(%u) nr_map_ids %u(%u) map_id %u(%u) name %s(%s)\n",
340 err, errno, i, 399 err, errno, i,
341 prog_infos[i].type, BPF_PROG_TYPE_SOCKET_FILTER, 400 prog_infos[i].type, BPF_PROG_TYPE_SOCKET_FILTER,
342 info_len, sizeof(struct bpf_prog_info), 401 info_len, sizeof(struct bpf_prog_info),
@@ -344,36 +403,12 @@ static void test_bpf_obj_id(void)
344 prog_infos[i].jited_prog_len, 403 prog_infos[i].jited_prog_len,
345 prog_infos[i].xlated_prog_len, 404 prog_infos[i].xlated_prog_len,
346 !!memcmp(jited_insns, zeros, sizeof(zeros)), 405 !!memcmp(jited_insns, zeros, sizeof(zeros)),
347 !!memcmp(xlated_insns, zeros, sizeof(zeros)))) 406 !!memcmp(xlated_insns, zeros, sizeof(zeros)),
348 goto done; 407 load_time, now,
349 408 prog_infos[i].created_by_uid, my_uid,
350 map_fds[i] = bpf_find_map(__func__, objs[i], "test_map_id"); 409 prog_infos[i].nr_map_ids, 1,
351 assert(map_fds[i] >= 0); 410 *(int *)prog_infos[i].map_ids, map_infos[i].id,
352 err = bpf_map_update_elem(map_fds[i], &array_key, 411 prog_infos[i].name, expected_prog_name))
353 &array_magic_value, 0);
354 assert(!err);
355
356 /* Check getting map info */
357 info_len = sizeof(struct bpf_map_info) * 2;
358 bzero(&map_infos[i], info_len);
359 err = bpf_obj_get_info_by_fd(map_fds[i], &map_infos[i],
360 &info_len);
361 if (CHECK(err ||
362 map_infos[i].type != BPF_MAP_TYPE_ARRAY ||
363 map_infos[i].key_size != sizeof(__u32) ||
364 map_infos[i].value_size != sizeof(__u64) ||
365 map_infos[i].max_entries != 1 ||
366 map_infos[i].map_flags != 0 ||
367 info_len != sizeof(struct bpf_map_info),
368 "get-map-info(fd)",
369 "err %d errno %d type %d(%d) info_len %u(%lu) key_size %u value_size %u max_entries %u map_flags %X\n",
370 err, errno,
371 map_infos[i].type, BPF_MAP_TYPE_ARRAY,
372 info_len, sizeof(struct bpf_map_info),
373 map_infos[i].key_size,
374 map_infos[i].value_size,
375 map_infos[i].max_entries,
376 map_infos[i].map_flags))
377 goto done; 412 goto done;
378 } 413 }
379 414
@@ -382,6 +417,7 @@ static void test_bpf_obj_id(void)
382 next_id = 0; 417 next_id = 0;
383 while (!bpf_prog_get_next_id(next_id, &next_id)) { 418 while (!bpf_prog_get_next_id(next_id, &next_id)) {
384 struct bpf_prog_info prog_info = {}; 419 struct bpf_prog_info prog_info = {};
420 __u32 saved_map_id;
385 int prog_fd; 421 int prog_fd;
386 422
387 info_len = sizeof(prog_info); 423 info_len = sizeof(prog_info);
@@ -404,16 +440,33 @@ static void test_bpf_obj_id(void)
404 440
405 nr_id_found++; 441 nr_id_found++;
406 442
443 /* Negative test:
444 * prog_info.nr_map_ids = 1
445 * prog_info.map_ids = NULL
446 */
447 prog_info.nr_map_ids = 1;
448 err = bpf_obj_get_info_by_fd(prog_fd, &prog_info, &info_len);
449 if (CHECK(!err || errno != EFAULT,
450 "get-prog-fd-bad-nr-map-ids", "err %d errno %d(%d)",
451 err, errno, EFAULT))
452 break;
453 bzero(&prog_info, sizeof(prog_info));
454 info_len = sizeof(prog_info);
455
456 saved_map_id = *(int *)(prog_infos[i].map_ids);
457 prog_info.map_ids = prog_infos[i].map_ids;
458 prog_info.nr_map_ids = 2;
407 err = bpf_obj_get_info_by_fd(prog_fd, &prog_info, &info_len); 459 err = bpf_obj_get_info_by_fd(prog_fd, &prog_info, &info_len);
408 prog_infos[i].jited_prog_insns = 0; 460 prog_infos[i].jited_prog_insns = 0;
409 prog_infos[i].xlated_prog_insns = 0; 461 prog_infos[i].xlated_prog_insns = 0;
410 CHECK(err || info_len != sizeof(struct bpf_prog_info) || 462 CHECK(err || info_len != sizeof(struct bpf_prog_info) ||
411 memcmp(&prog_info, &prog_infos[i], info_len), 463 memcmp(&prog_info, &prog_infos[i], info_len) ||
464 *(int *)prog_info.map_ids != saved_map_id,
412 "get-prog-info(next_id->fd)", 465 "get-prog-info(next_id->fd)",
413 "err %d errno %d info_len %u(%lu) memcmp %d\n", 466 "err %d errno %d info_len %u(%lu) memcmp %d map_id %u(%u)\n",
414 err, errno, info_len, sizeof(struct bpf_prog_info), 467 err, errno, info_len, sizeof(struct bpf_prog_info),
415 memcmp(&prog_info, &prog_infos[i], info_len)); 468 memcmp(&prog_info, &prog_infos[i], info_len),
416 469 *(int *)prog_info.map_ids, saved_map_id);
417 close(prog_fd); 470 close(prog_fd);
418 } 471 }
419 CHECK(nr_id_found != nr_iters, 472 CHECK(nr_id_found != nr_iters,
@@ -495,6 +548,75 @@ static void test_pkt_md_access(void)
495 bpf_object__close(obj); 548 bpf_object__close(obj);
496} 549}
497 550
551static void test_obj_name(void)
552{
553 struct {
554 const char *name;
555 int success;
556 int expected_errno;
557 } tests[] = {
558 { "", 1, 0 },
559 { "_123456789ABCDE", 1, 0 },
560 { "_123456789ABCDEF", 0, EINVAL },
561 { "_123456789ABCD\n", 0, EINVAL },
562 };
563 struct bpf_insn prog[] = {
564 BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0),
565 BPF_EXIT_INSN(),
566 };
567 __u32 duration = 0;
568 int i;
569
570 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
571 size_t name_len = strlen(tests[i].name) + 1;
572 union bpf_attr attr;
573 size_t ncopy;
574 int fd;
575
576 /* test different attr.prog_name during BPF_PROG_LOAD */
577 ncopy = name_len < sizeof(attr.prog_name) ?
578 name_len : sizeof(attr.prog_name);
579 bzero(&attr, sizeof(attr));
580 attr.prog_type = BPF_PROG_TYPE_SCHED_CLS;
581 attr.insn_cnt = 2;
582 attr.insns = ptr_to_u64(prog);
583 attr.license = ptr_to_u64("");
584 memcpy(attr.prog_name, tests[i].name, ncopy);
585
586 fd = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
587 CHECK((tests[i].success && fd < 0) ||
588 (!tests[i].success && fd != -1) ||
589 (!tests[i].success && errno != tests[i].expected_errno),
590 "check-bpf-prog-name",
591 "fd %d(%d) errno %d(%d)\n",
592 fd, tests[i].success, errno, tests[i].expected_errno);
593
594 if (fd != -1)
595 close(fd);
596
597 /* test different attr.map_name during BPF_MAP_CREATE */
598 ncopy = name_len < sizeof(attr.map_name) ?
599 name_len : sizeof(attr.map_name);
600 bzero(&attr, sizeof(attr));
601 attr.map_type = BPF_MAP_TYPE_ARRAY;
602 attr.key_size = 4;
603 attr.value_size = 4;
604 attr.max_entries = 1;
605 attr.map_flags = 0;
606 memcpy(attr.map_name, tests[i].name, ncopy);
607 fd = syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));
608 CHECK((tests[i].success && fd < 0) ||
609 (!tests[i].success && fd != -1) ||
610 (!tests[i].success && errno != tests[i].expected_errno),
611 "check-bpf-map-name",
612 "fd %d(%d) errno %d(%d)\n",
613 fd, tests[i].success, errno, tests[i].expected_errno);
614
615 if (fd != -1)
616 close(fd);
617 }
618}
619
498int main(void) 620int main(void)
499{ 621{
500 struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY }; 622 struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };
@@ -507,6 +629,7 @@ int main(void)
507 test_tcp_estats(); 629 test_tcp_estats();
508 test_bpf_obj_id(); 630 test_bpf_obj_id();
509 test_pkt_md_access(); 631 test_pkt_md_access();
632 test_obj_name();
510 633
511 printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt); 634 printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt);
512 return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS; 635 return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
diff --git a/tools/testing/selftests/bpf/test_tag.c b/tools/testing/selftests/bpf/test_tag.c
index de409fc50c35..8b201895c569 100644
--- a/tools/testing/selftests/bpf/test_tag.c
+++ b/tools/testing/selftests/bpf/test_tag.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdint.h> 2#include <stdint.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 26f3250bdcd2..3c64f30cf63c 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -1130,15 +1130,27 @@ static struct bpf_test tests[] = {
1130 .errstr = "invalid bpf_context access", 1130 .errstr = "invalid bpf_context access",
1131 }, 1131 },
1132 { 1132 {
1133 "check skb->mark is writeable by SK_SKB", 1133 "invalid access of skb->mark for SK_SKB",
1134 .insns = {
1135 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
1136 offsetof(struct __sk_buff, mark)),
1137 BPF_EXIT_INSN(),
1138 },
1139 .result = REJECT,
1140 .prog_type = BPF_PROG_TYPE_SK_SKB,
1141 .errstr = "invalid bpf_context access",
1142 },
1143 {
1144 "check skb->mark is not writeable by SK_SKB",
1134 .insns = { 1145 .insns = {
1135 BPF_MOV64_IMM(BPF_REG_0, 0), 1146 BPF_MOV64_IMM(BPF_REG_0, 0),
1136 BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 1147 BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
1137 offsetof(struct __sk_buff, mark)), 1148 offsetof(struct __sk_buff, mark)),
1138 BPF_EXIT_INSN(), 1149 BPF_EXIT_INSN(),
1139 }, 1150 },
1140 .result = ACCEPT, 1151 .result = REJECT,
1141 .prog_type = BPF_PROG_TYPE_SK_SKB, 1152 .prog_type = BPF_PROG_TYPE_SK_SKB,
1153 .errstr = "invalid bpf_context access",
1142 }, 1154 },
1143 { 1155 {
1144 "check skb->tc_index is writeable by SK_SKB", 1156 "check skb->tc_index is writeable by SK_SKB",
@@ -3567,7 +3579,7 @@ static struct bpf_test tests[] = {
3567 .prog_type = BPF_PROG_TYPE_SCHED_CLS, 3579 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
3568 }, 3580 },
3569 { 3581 {
3570 "helper access to packet: test19, cls helper fail range zero", 3582 "helper access to packet: test19, cls helper range zero",
3571 .insns = { 3583 .insns = {
3572 BPF_LDX_MEM(BPF_W, BPF_REG_6, BPF_REG_1, 3584 BPF_LDX_MEM(BPF_W, BPF_REG_6, BPF_REG_1,
3573 offsetof(struct __sk_buff, data)), 3585 offsetof(struct __sk_buff, data)),
@@ -3587,8 +3599,7 @@ static struct bpf_test tests[] = {
3587 BPF_MOV64_IMM(BPF_REG_0, 0), 3599 BPF_MOV64_IMM(BPF_REG_0, 0),
3588 BPF_EXIT_INSN(), 3600 BPF_EXIT_INSN(),
3589 }, 3601 },
3590 .result = REJECT, 3602 .result = ACCEPT,
3591 .errstr = "invalid access to packet",
3592 .prog_type = BPF_PROG_TYPE_SCHED_CLS, 3603 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
3593 }, 3604 },
3594 { 3605 {
@@ -4366,11 +4377,10 @@ static struct bpf_test tests[] = {
4366 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4377 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
4367 BPF_LD_MAP_FD(BPF_REG_1, 0), 4378 BPF_LD_MAP_FD(BPF_REG_1, 0),
4368 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4379 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
4369 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4), 4380 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 3),
4370 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4381 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
4371 BPF_MOV64_IMM(BPF_REG_2, 0), 4382 BPF_MOV64_IMM(BPF_REG_2, 0),
4372 BPF_MOV64_IMM(BPF_REG_3, 0), 4383 BPF_EMIT_CALL(BPF_FUNC_trace_printk),
4373 BPF_EMIT_CALL(BPF_FUNC_probe_read),
4374 BPF_EXIT_INSN(), 4384 BPF_EXIT_INSN(),
4375 }, 4385 },
4376 .fixup_map2 = { 3 }, 4386 .fixup_map2 = { 3 },
@@ -4470,13 +4480,12 @@ static struct bpf_test tests[] = {
4470 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4480 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
4471 BPF_LD_MAP_FD(BPF_REG_1, 0), 4481 BPF_LD_MAP_FD(BPF_REG_1, 0),
4472 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4482 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
4473 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5), 4483 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
4474 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4484 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
4475 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 4485 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
4476 offsetof(struct test_val, foo)), 4486 offsetof(struct test_val, foo)),
4477 BPF_MOV64_IMM(BPF_REG_2, 0), 4487 BPF_MOV64_IMM(BPF_REG_2, 0),
4478 BPF_MOV64_IMM(BPF_REG_3, 0), 4488 BPF_EMIT_CALL(BPF_FUNC_trace_printk),
4479 BPF_EMIT_CALL(BPF_FUNC_probe_read),
4480 BPF_EXIT_INSN(), 4489 BPF_EXIT_INSN(),
4481 }, 4490 },
4482 .fixup_map2 = { 3 }, 4491 .fixup_map2 = { 3 },
@@ -4606,13 +4615,12 @@ static struct bpf_test tests[] = {
4606 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4615 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
4607 BPF_LD_MAP_FD(BPF_REG_1, 0), 4616 BPF_LD_MAP_FD(BPF_REG_1, 0),
4608 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4617 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
4609 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6), 4618 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
4610 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4619 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
4611 BPF_MOV64_IMM(BPF_REG_3, 0), 4620 BPF_MOV64_IMM(BPF_REG_3, 0),
4612 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3), 4621 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
4613 BPF_MOV64_IMM(BPF_REG_2, 0), 4622 BPF_MOV64_IMM(BPF_REG_2, 0),
4614 BPF_MOV64_IMM(BPF_REG_3, 0), 4623 BPF_EMIT_CALL(BPF_FUNC_trace_printk),
4615 BPF_EMIT_CALL(BPF_FUNC_probe_read),
4616 BPF_EXIT_INSN(), 4624 BPF_EXIT_INSN(),
4617 }, 4625 },
4618 .fixup_map2 = { 3 }, 4626 .fixup_map2 = { 3 },
@@ -4747,15 +4755,14 @@ static struct bpf_test tests[] = {
4747 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4755 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
4748 BPF_LD_MAP_FD(BPF_REG_1, 0), 4756 BPF_LD_MAP_FD(BPF_REG_1, 0),
4749 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4757 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
4750 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7), 4758 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
4751 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4759 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
4752 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0), 4760 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
4753 BPF_JMP_IMM(BPF_JGT, BPF_REG_3, 4761 BPF_JMP_IMM(BPF_JGT, BPF_REG_3,
4754 offsetof(struct test_val, foo), 4), 4762 offsetof(struct test_val, foo), 3),
4755 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3), 4763 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
4756 BPF_MOV64_IMM(BPF_REG_2, 0), 4764 BPF_MOV64_IMM(BPF_REG_2, 0),
4757 BPF_MOV64_IMM(BPF_REG_3, 0), 4765 BPF_EMIT_CALL(BPF_FUNC_trace_printk),
4758 BPF_EMIT_CALL(BPF_FUNC_probe_read),
4759 BPF_EXIT_INSN(), 4766 BPF_EXIT_INSN(),
4760 }, 4767 },
4761 .fixup_map2 = { 3 }, 4768 .fixup_map2 = { 3 },
@@ -5338,7 +5345,7 @@ static struct bpf_test tests[] = {
5338 BPF_EMIT_CALL(BPF_FUNC_probe_read), 5345 BPF_EMIT_CALL(BPF_FUNC_probe_read),
5339 BPF_EXIT_INSN(), 5346 BPF_EXIT_INSN(),
5340 }, 5347 },
5341 .errstr = "invalid stack type R1 off=-64 access_size=0", 5348 .errstr = "invalid indirect read from stack off -64+0 size 64",
5342 .result = REJECT, 5349 .result = REJECT,
5343 .prog_type = BPF_PROG_TYPE_TRACEPOINT, 5350 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5344 }, 5351 },
@@ -5493,7 +5500,7 @@ static struct bpf_test tests[] = {
5493 BPF_MOV64_IMM(BPF_REG_0, 0), 5500 BPF_MOV64_IMM(BPF_REG_0, 0),
5494 BPF_EXIT_INSN(), 5501 BPF_EXIT_INSN(),
5495 }, 5502 },
5496 .errstr = "invalid stack type R1 off=-64 access_size=0", 5503 .errstr = "invalid indirect read from stack off -64+0 size 64",
5497 .result = REJECT, 5504 .result = REJECT,
5498 .prog_type = BPF_PROG_TYPE_TRACEPOINT, 5505 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5499 }, 5506 },
@@ -5624,7 +5631,7 @@ static struct bpf_test tests[] = {
5624 .prog_type = BPF_PROG_TYPE_TRACEPOINT, 5631 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5625 }, 5632 },
5626 { 5633 {
5627 "helper access to variable memory: size = 0 allowed on NULL", 5634 "helper access to variable memory: size = 0 allowed on NULL (ARG_PTR_TO_MEM_OR_NULL)",
5628 .insns = { 5635 .insns = {
5629 BPF_MOV64_IMM(BPF_REG_1, 0), 5636 BPF_MOV64_IMM(BPF_REG_1, 0),
5630 BPF_MOV64_IMM(BPF_REG_2, 0), 5637 BPF_MOV64_IMM(BPF_REG_2, 0),
@@ -5638,7 +5645,7 @@ static struct bpf_test tests[] = {
5638 .prog_type = BPF_PROG_TYPE_SCHED_CLS, 5645 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
5639 }, 5646 },
5640 { 5647 {
5641 "helper access to variable memory: size > 0 not allowed on NULL", 5648 "helper access to variable memory: size > 0 not allowed on NULL (ARG_PTR_TO_MEM_OR_NULL)",
5642 .insns = { 5649 .insns = {
5643 BPF_MOV64_IMM(BPF_REG_1, 0), 5650 BPF_MOV64_IMM(BPF_REG_1, 0),
5644 BPF_MOV64_IMM(BPF_REG_2, 0), 5651 BPF_MOV64_IMM(BPF_REG_2, 0),
@@ -5656,7 +5663,7 @@ static struct bpf_test tests[] = {
5656 .prog_type = BPF_PROG_TYPE_SCHED_CLS, 5663 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
5657 }, 5664 },
5658 { 5665 {
5659 "helper access to variable memory: size = 0 not allowed on != NULL", 5666 "helper access to variable memory: size = 0 allowed on != NULL stack pointer (ARG_PTR_TO_MEM_OR_NULL)",
5660 .insns = { 5667 .insns = {
5661 BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), 5668 BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
5662 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8), 5669 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
@@ -5669,11 +5676,201 @@ static struct bpf_test tests[] = {
5669 BPF_EMIT_CALL(BPF_FUNC_csum_diff), 5676 BPF_EMIT_CALL(BPF_FUNC_csum_diff),
5670 BPF_EXIT_INSN(), 5677 BPF_EXIT_INSN(),
5671 }, 5678 },
5672 .errstr = "invalid stack type R1 off=-8 access_size=0", 5679 .result = ACCEPT,
5673 .result = REJECT, 5680 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
5681 },
5682 {
5683 "helper access to variable memory: size = 0 allowed on != NULL map pointer (ARG_PTR_TO_MEM_OR_NULL)",
5684 .insns = {
5685 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
5686 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5687 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
5688 BPF_LD_MAP_FD(BPF_REG_1, 0),
5689 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
5690 BPF_FUNC_map_lookup_elem),
5691 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
5692 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
5693 BPF_MOV64_IMM(BPF_REG_2, 0),
5694 BPF_MOV64_IMM(BPF_REG_3, 0),
5695 BPF_MOV64_IMM(BPF_REG_4, 0),
5696 BPF_MOV64_IMM(BPF_REG_5, 0),
5697 BPF_EMIT_CALL(BPF_FUNC_csum_diff),
5698 BPF_EXIT_INSN(),
5699 },
5700 .fixup_map1 = { 3 },
5701 .result = ACCEPT,
5702 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
5703 },
5704 {
5705 "helper access to variable memory: size possible = 0 allowed on != NULL stack pointer (ARG_PTR_TO_MEM_OR_NULL)",
5706 .insns = {
5707 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
5708 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5709 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
5710 BPF_LD_MAP_FD(BPF_REG_1, 0),
5711 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
5712 BPF_FUNC_map_lookup_elem),
5713 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 9),
5714 BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_0, 0),
5715 BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 8, 7),
5716 BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
5717 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
5718 BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, 0),
5719 BPF_MOV64_IMM(BPF_REG_3, 0),
5720 BPF_MOV64_IMM(BPF_REG_4, 0),
5721 BPF_MOV64_IMM(BPF_REG_5, 0),
5722 BPF_EMIT_CALL(BPF_FUNC_csum_diff),
5723 BPF_EXIT_INSN(),
5724 },
5725 .fixup_map1 = { 3 },
5726 .result = ACCEPT,
5727 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
5728 },
5729 {
5730 "helper access to variable memory: size possible = 0 allowed on != NULL map pointer (ARG_PTR_TO_MEM_OR_NULL)",
5731 .insns = {
5732 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
5733 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5734 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
5735 BPF_LD_MAP_FD(BPF_REG_1, 0),
5736 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
5737 BPF_FUNC_map_lookup_elem),
5738 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
5739 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
5740 BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_0, 0),
5741 BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 8, 4),
5742 BPF_MOV64_IMM(BPF_REG_3, 0),
5743 BPF_MOV64_IMM(BPF_REG_4, 0),
5744 BPF_MOV64_IMM(BPF_REG_5, 0),
5745 BPF_EMIT_CALL(BPF_FUNC_csum_diff),
5746 BPF_EXIT_INSN(),
5747 },
5748 .fixup_map1 = { 3 },
5749 .result = ACCEPT,
5750 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
5751 },
5752 {
5753 "helper access to variable memory: size possible = 0 allowed on != NULL packet pointer (ARG_PTR_TO_MEM_OR_NULL)",
5754 .insns = {
5755 BPF_LDX_MEM(BPF_W, BPF_REG_6, BPF_REG_1,
5756 offsetof(struct __sk_buff, data)),
5757 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
5758 offsetof(struct __sk_buff, data_end)),
5759 BPF_MOV64_REG(BPF_REG_0, BPF_REG_6),
5760 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
5761 BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 7),
5762 BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
5763 BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_6, 0),
5764 BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 8, 4),
5765 BPF_MOV64_IMM(BPF_REG_3, 0),
5766 BPF_MOV64_IMM(BPF_REG_4, 0),
5767 BPF_MOV64_IMM(BPF_REG_5, 0),
5768 BPF_EMIT_CALL(BPF_FUNC_csum_diff),
5769 BPF_EXIT_INSN(),
5770 },
5771 .result = ACCEPT,
5674 .prog_type = BPF_PROG_TYPE_SCHED_CLS, 5772 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
5675 }, 5773 },
5676 { 5774 {
5775 "helper access to variable memory: size = 0 not allowed on NULL (!ARG_PTR_TO_MEM_OR_NULL)",
5776 .insns = {
5777 BPF_MOV64_IMM(BPF_REG_1, 0),
5778 BPF_MOV64_IMM(BPF_REG_2, 0),
5779 BPF_MOV64_IMM(BPF_REG_3, 0),
5780 BPF_EMIT_CALL(BPF_FUNC_probe_read),
5781 BPF_EXIT_INSN(),
5782 },
5783 .errstr = "R1 type=inv expected=fp",
5784 .result = REJECT,
5785 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5786 },
5787 {
5788 "helper access to variable memory: size > 0 not allowed on NULL (!ARG_PTR_TO_MEM_OR_NULL)",
5789 .insns = {
5790 BPF_MOV64_IMM(BPF_REG_1, 0),
5791 BPF_MOV64_IMM(BPF_REG_2, 1),
5792 BPF_MOV64_IMM(BPF_REG_3, 0),
5793 BPF_EMIT_CALL(BPF_FUNC_probe_read),
5794 BPF_EXIT_INSN(),
5795 },
5796 .errstr = "R1 type=inv expected=fp",
5797 .result = REJECT,
5798 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5799 },
5800 {
5801 "helper access to variable memory: size = 0 allowed on != NULL stack pointer (!ARG_PTR_TO_MEM_OR_NULL)",
5802 .insns = {
5803 BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
5804 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
5805 BPF_MOV64_IMM(BPF_REG_2, 0),
5806 BPF_MOV64_IMM(BPF_REG_3, 0),
5807 BPF_EMIT_CALL(BPF_FUNC_probe_read),
5808 BPF_EXIT_INSN(),
5809 },
5810 .result = ACCEPT,
5811 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5812 },
5813 {
5814 "helper access to variable memory: size = 0 allowed on != NULL map pointer (!ARG_PTR_TO_MEM_OR_NULL)",
5815 .insns = {
5816 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
5817 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5818 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
5819 BPF_LD_MAP_FD(BPF_REG_1, 0),
5820 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
5821 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
5822 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
5823 BPF_MOV64_IMM(BPF_REG_2, 0),
5824 BPF_MOV64_IMM(BPF_REG_3, 0),
5825 BPF_EMIT_CALL(BPF_FUNC_probe_read),
5826 BPF_EXIT_INSN(),
5827 },
5828 .fixup_map1 = { 3 },
5829 .result = ACCEPT,
5830 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5831 },
5832 {
5833 "helper access to variable memory: size possible = 0 allowed on != NULL stack pointer (!ARG_PTR_TO_MEM_OR_NULL)",
5834 .insns = {
5835 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
5836 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5837 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
5838 BPF_LD_MAP_FD(BPF_REG_1, 0),
5839 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
5840 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
5841 BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_0, 0),
5842 BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 8, 4),
5843 BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
5844 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
5845 BPF_MOV64_IMM(BPF_REG_3, 0),
5846 BPF_EMIT_CALL(BPF_FUNC_probe_read),
5847 BPF_EXIT_INSN(),
5848 },
5849 .fixup_map1 = { 3 },
5850 .result = ACCEPT,
5851 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5852 },
5853 {
5854 "helper access to variable memory: size possible = 0 allowed on != NULL map pointer (!ARG_PTR_TO_MEM_OR_NULL)",
5855 .insns = {
5856 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
5857 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
5858 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
5859 BPF_LD_MAP_FD(BPF_REG_1, 0),
5860 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
5861 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
5862 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
5863 BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_0, 0),
5864 BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 8, 2),
5865 BPF_MOV64_IMM(BPF_REG_3, 0),
5866 BPF_EMIT_CALL(BPF_FUNC_probe_read),
5867 BPF_EXIT_INSN(),
5868 },
5869 .fixup_map1 = { 3 },
5870 .result = ACCEPT,
5871 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5872 },
5873 {
5677 "helper access to variable memory: 8 bytes leak", 5874 "helper access to variable memory: 8 bytes leak",
5678 .insns = { 5875 .insns = {
5679 BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), 5876 BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
@@ -6645,6 +6842,1261 @@ static struct bpf_test tests[] = {
6645 .errstr = "BPF_END uses reserved fields", 6842 .errstr = "BPF_END uses reserved fields",
6646 .result = REJECT, 6843 .result = REJECT,
6647 }, 6844 },
6845 {
6846 "meta access, test1",
6847 .insns = {
6848 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
6849 offsetof(struct xdp_md, data_meta)),
6850 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6851 offsetof(struct xdp_md, data)),
6852 BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
6853 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
6854 BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
6855 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
6856 BPF_MOV64_IMM(BPF_REG_0, 0),
6857 BPF_EXIT_INSN(),
6858 },
6859 .result = ACCEPT,
6860 .prog_type = BPF_PROG_TYPE_XDP,
6861 },
6862 {
6863 "meta access, test2",
6864 .insns = {
6865 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
6866 offsetof(struct xdp_md, data_meta)),
6867 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6868 offsetof(struct xdp_md, data)),
6869 BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
6870 BPF_ALU64_IMM(BPF_SUB, BPF_REG_0, 8),
6871 BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
6872 BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 8),
6873 BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
6874 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_0, 0),
6875 BPF_MOV64_IMM(BPF_REG_0, 0),
6876 BPF_EXIT_INSN(),
6877 },
6878 .result = REJECT,
6879 .errstr = "invalid access to packet, off=-8",
6880 .prog_type = BPF_PROG_TYPE_XDP,
6881 },
6882 {
6883 "meta access, test3",
6884 .insns = {
6885 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
6886 offsetof(struct xdp_md, data_meta)),
6887 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6888 offsetof(struct xdp_md, data_end)),
6889 BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
6890 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
6891 BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
6892 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
6893 BPF_MOV64_IMM(BPF_REG_0, 0),
6894 BPF_EXIT_INSN(),
6895 },
6896 .result = REJECT,
6897 .errstr = "invalid access to packet",
6898 .prog_type = BPF_PROG_TYPE_XDP,
6899 },
6900 {
6901 "meta access, test4",
6902 .insns = {
6903 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
6904 offsetof(struct xdp_md, data_meta)),
6905 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6906 offsetof(struct xdp_md, data_end)),
6907 BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1,
6908 offsetof(struct xdp_md, data)),
6909 BPF_MOV64_REG(BPF_REG_0, BPF_REG_4),
6910 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
6911 BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_3, 1),
6912 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
6913 BPF_MOV64_IMM(BPF_REG_0, 0),
6914 BPF_EXIT_INSN(),
6915 },
6916 .result = REJECT,
6917 .errstr = "invalid access to packet",
6918 .prog_type = BPF_PROG_TYPE_XDP,
6919 },
6920 {
6921 "meta access, test5",
6922 .insns = {
6923 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6924 offsetof(struct xdp_md, data_meta)),
6925 BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1,
6926 offsetof(struct xdp_md, data)),
6927 BPF_MOV64_REG(BPF_REG_0, BPF_REG_3),
6928 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
6929 BPF_JMP_REG(BPF_JGT, BPF_REG_0, BPF_REG_4, 3),
6930 BPF_MOV64_IMM(BPF_REG_2, -8),
6931 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
6932 BPF_FUNC_xdp_adjust_meta),
6933 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_3, 0),
6934 BPF_MOV64_IMM(BPF_REG_0, 0),
6935 BPF_EXIT_INSN(),
6936 },
6937 .result = REJECT,
6938 .errstr = "R3 !read_ok",
6939 .prog_type = BPF_PROG_TYPE_XDP,
6940 },
6941 {
6942 "meta access, test6",
6943 .insns = {
6944 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
6945 offsetof(struct xdp_md, data_meta)),
6946 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6947 offsetof(struct xdp_md, data)),
6948 BPF_MOV64_REG(BPF_REG_0, BPF_REG_3),
6949 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
6950 BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
6951 BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 8),
6952 BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_0, 1),
6953 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
6954 BPF_MOV64_IMM(BPF_REG_0, 0),
6955 BPF_EXIT_INSN(),
6956 },
6957 .result = REJECT,
6958 .errstr = "invalid access to packet",
6959 .prog_type = BPF_PROG_TYPE_XDP,
6960 },
6961 {
6962 "meta access, test7",
6963 .insns = {
6964 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
6965 offsetof(struct xdp_md, data_meta)),
6966 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6967 offsetof(struct xdp_md, data)),
6968 BPF_MOV64_REG(BPF_REG_0, BPF_REG_3),
6969 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 8),
6970 BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
6971 BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 8),
6972 BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
6973 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
6974 BPF_MOV64_IMM(BPF_REG_0, 0),
6975 BPF_EXIT_INSN(),
6976 },
6977 .result = ACCEPT,
6978 .prog_type = BPF_PROG_TYPE_XDP,
6979 },
6980 {
6981 "meta access, test8",
6982 .insns = {
6983 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
6984 offsetof(struct xdp_md, data_meta)),
6985 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
6986 offsetof(struct xdp_md, data)),
6987 BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
6988 BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 0xFFFF),
6989 BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
6990 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
6991 BPF_MOV64_IMM(BPF_REG_0, 0),
6992 BPF_EXIT_INSN(),
6993 },
6994 .result = ACCEPT,
6995 .prog_type = BPF_PROG_TYPE_XDP,
6996 },
6997 {
6998 "meta access, test9",
6999 .insns = {
7000 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7001 offsetof(struct xdp_md, data_meta)),
7002 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7003 offsetof(struct xdp_md, data)),
7004 BPF_MOV64_REG(BPF_REG_4, BPF_REG_2),
7005 BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 0xFFFF),
7006 BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 1),
7007 BPF_JMP_REG(BPF_JGT, BPF_REG_4, BPF_REG_3, 1),
7008 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
7009 BPF_MOV64_IMM(BPF_REG_0, 0),
7010 BPF_EXIT_INSN(),
7011 },
7012 .result = REJECT,
7013 .errstr = "invalid access to packet",
7014 .prog_type = BPF_PROG_TYPE_XDP,
7015 },
7016 {
7017 "meta access, test10",
7018 .insns = {
7019 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7020 offsetof(struct xdp_md, data_meta)),
7021 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7022 offsetof(struct xdp_md, data)),
7023 BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1,
7024 offsetof(struct xdp_md, data_end)),
7025 BPF_MOV64_IMM(BPF_REG_5, 42),
7026 BPF_MOV64_IMM(BPF_REG_6, 24),
7027 BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_5, -8),
7028 BPF_STX_XADD(BPF_DW, BPF_REG_10, BPF_REG_6, -8),
7029 BPF_LDX_MEM(BPF_DW, BPF_REG_5, BPF_REG_10, -8),
7030 BPF_JMP_IMM(BPF_JGT, BPF_REG_5, 100, 6),
7031 BPF_ALU64_REG(BPF_ADD, BPF_REG_3, BPF_REG_5),
7032 BPF_MOV64_REG(BPF_REG_5, BPF_REG_3),
7033 BPF_MOV64_REG(BPF_REG_6, BPF_REG_2),
7034 BPF_ALU64_IMM(BPF_ADD, BPF_REG_6, 8),
7035 BPF_JMP_REG(BPF_JGT, BPF_REG_6, BPF_REG_5, 1),
7036 BPF_LDX_MEM(BPF_B, BPF_REG_2, BPF_REG_2, 0),
7037 BPF_MOV64_IMM(BPF_REG_0, 0),
7038 BPF_EXIT_INSN(),
7039 },
7040 .result = REJECT,
7041 .errstr = "invalid access to packet",
7042 .prog_type = BPF_PROG_TYPE_XDP,
7043 },
7044 {
7045 "meta access, test11",
7046 .insns = {
7047 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7048 offsetof(struct xdp_md, data_meta)),
7049 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7050 offsetof(struct xdp_md, data)),
7051 BPF_MOV64_IMM(BPF_REG_5, 42),
7052 BPF_MOV64_IMM(BPF_REG_6, 24),
7053 BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_5, -8),
7054 BPF_STX_XADD(BPF_DW, BPF_REG_10, BPF_REG_6, -8),
7055 BPF_LDX_MEM(BPF_DW, BPF_REG_5, BPF_REG_10, -8),
7056 BPF_JMP_IMM(BPF_JGT, BPF_REG_5, 100, 6),
7057 BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_5),
7058 BPF_MOV64_REG(BPF_REG_5, BPF_REG_2),
7059 BPF_MOV64_REG(BPF_REG_6, BPF_REG_2),
7060 BPF_ALU64_IMM(BPF_ADD, BPF_REG_6, 8),
7061 BPF_JMP_REG(BPF_JGT, BPF_REG_6, BPF_REG_3, 1),
7062 BPF_LDX_MEM(BPF_B, BPF_REG_5, BPF_REG_5, 0),
7063 BPF_MOV64_IMM(BPF_REG_0, 0),
7064 BPF_EXIT_INSN(),
7065 },
7066 .result = ACCEPT,
7067 .prog_type = BPF_PROG_TYPE_XDP,
7068 },
7069 {
7070 "meta access, test12",
7071 .insns = {
7072 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7073 offsetof(struct xdp_md, data_meta)),
7074 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7075 offsetof(struct xdp_md, data)),
7076 BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1,
7077 offsetof(struct xdp_md, data_end)),
7078 BPF_MOV64_REG(BPF_REG_5, BPF_REG_3),
7079 BPF_ALU64_IMM(BPF_ADD, BPF_REG_5, 16),
7080 BPF_JMP_REG(BPF_JGT, BPF_REG_5, BPF_REG_4, 5),
7081 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_3, 0),
7082 BPF_MOV64_REG(BPF_REG_5, BPF_REG_2),
7083 BPF_ALU64_IMM(BPF_ADD, BPF_REG_5, 16),
7084 BPF_JMP_REG(BPF_JGT, BPF_REG_5, BPF_REG_3, 1),
7085 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_2, 0),
7086 BPF_MOV64_IMM(BPF_REG_0, 0),
7087 BPF_EXIT_INSN(),
7088 },
7089 .result = ACCEPT,
7090 .prog_type = BPF_PROG_TYPE_XDP,
7091 },
7092 {
7093 "arithmetic ops make PTR_TO_CTX unusable",
7094 .insns = {
7095 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
7096 offsetof(struct __sk_buff, data) -
7097 offsetof(struct __sk_buff, mark)),
7098 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
7099 offsetof(struct __sk_buff, mark)),
7100 BPF_EXIT_INSN(),
7101 },
7102 .errstr = "dereference of modified ctx ptr R1 off=68+8, ctx+const is allowed, ctx+const+const is not",
7103 .result = REJECT,
7104 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
7105 },
7106 {
7107 "XDP pkt read, pkt_end mangling, bad access 1",
7108 .insns = {
7109 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7110 offsetof(struct xdp_md, data)),
7111 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7112 offsetof(struct xdp_md, data_end)),
7113 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7114 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7115 BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, 8),
7116 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 1),
7117 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7118 BPF_MOV64_IMM(BPF_REG_0, 0),
7119 BPF_EXIT_INSN(),
7120 },
7121 .errstr = "R1 offset is outside of the packet",
7122 .result = REJECT,
7123 .prog_type = BPF_PROG_TYPE_XDP,
7124 },
7125 {
7126 "XDP pkt read, pkt_end mangling, bad access 2",
7127 .insns = {
7128 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7129 offsetof(struct xdp_md, data)),
7130 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7131 offsetof(struct xdp_md, data_end)),
7132 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7133 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7134 BPF_ALU64_IMM(BPF_SUB, BPF_REG_3, 8),
7135 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 1),
7136 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7137 BPF_MOV64_IMM(BPF_REG_0, 0),
7138 BPF_EXIT_INSN(),
7139 },
7140 .errstr = "R1 offset is outside of the packet",
7141 .result = REJECT,
7142 .prog_type = BPF_PROG_TYPE_XDP,
7143 },
7144 {
7145 "XDP pkt read, pkt_data' > pkt_end, good access",
7146 .insns = {
7147 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7148 offsetof(struct xdp_md, data)),
7149 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7150 offsetof(struct xdp_md, data_end)),
7151 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7152 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7153 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 1),
7154 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7155 BPF_MOV64_IMM(BPF_REG_0, 0),
7156 BPF_EXIT_INSN(),
7157 },
7158 .result = ACCEPT,
7159 .prog_type = BPF_PROG_TYPE_XDP,
7160 },
7161 {
7162 "XDP pkt read, pkt_data' > pkt_end, bad access 1",
7163 .insns = {
7164 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7165 offsetof(struct xdp_md, data)),
7166 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7167 offsetof(struct xdp_md, data_end)),
7168 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7169 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7170 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 1),
7171 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7172 BPF_MOV64_IMM(BPF_REG_0, 0),
7173 BPF_EXIT_INSN(),
7174 },
7175 .errstr = "R1 offset is outside of the packet",
7176 .result = REJECT,
7177 .prog_type = BPF_PROG_TYPE_XDP,
7178 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7179 },
7180 {
7181 "XDP pkt read, pkt_data' > pkt_end, bad access 2",
7182 .insns = {
7183 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7184 offsetof(struct xdp_md, data)),
7185 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7186 offsetof(struct xdp_md, data_end)),
7187 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7188 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7189 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 0),
7190 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7191 BPF_MOV64_IMM(BPF_REG_0, 0),
7192 BPF_EXIT_INSN(),
7193 },
7194 .errstr = "R1 offset is outside of the packet",
7195 .result = REJECT,
7196 .prog_type = BPF_PROG_TYPE_XDP,
7197 },
7198 {
7199 "XDP pkt read, pkt_end > pkt_data', good access",
7200 .insns = {
7201 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7202 offsetof(struct xdp_md, data)),
7203 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7204 offsetof(struct xdp_md, data_end)),
7205 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7206 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7207 BPF_JMP_REG(BPF_JGT, BPF_REG_3, BPF_REG_1, 1),
7208 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7209 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7210 BPF_MOV64_IMM(BPF_REG_0, 0),
7211 BPF_EXIT_INSN(),
7212 },
7213 .result = ACCEPT,
7214 .prog_type = BPF_PROG_TYPE_XDP,
7215 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7216 },
7217 {
7218 "XDP pkt read, pkt_end > pkt_data', bad access 1",
7219 .insns = {
7220 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7221 offsetof(struct xdp_md, data)),
7222 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7223 offsetof(struct xdp_md, data_end)),
7224 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7225 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7226 BPF_JMP_REG(BPF_JGT, BPF_REG_3, BPF_REG_1, 1),
7227 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7228 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7229 BPF_MOV64_IMM(BPF_REG_0, 0),
7230 BPF_EXIT_INSN(),
7231 },
7232 .errstr = "R1 offset is outside of the packet",
7233 .result = REJECT,
7234 .prog_type = BPF_PROG_TYPE_XDP,
7235 },
7236 {
7237 "XDP pkt read, pkt_end > pkt_data', bad access 2",
7238 .insns = {
7239 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7240 offsetof(struct xdp_md, data)),
7241 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7242 offsetof(struct xdp_md, data_end)),
7243 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7244 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7245 BPF_JMP_REG(BPF_JGT, BPF_REG_3, BPF_REG_1, 1),
7246 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7247 BPF_MOV64_IMM(BPF_REG_0, 0),
7248 BPF_EXIT_INSN(),
7249 },
7250 .errstr = "R1 offset is outside of the packet",
7251 .result = REJECT,
7252 .prog_type = BPF_PROG_TYPE_XDP,
7253 },
7254 {
7255 "XDP pkt read, pkt_data' < pkt_end, good access",
7256 .insns = {
7257 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7258 offsetof(struct xdp_md, data)),
7259 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7260 offsetof(struct xdp_md, data_end)),
7261 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7262 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7263 BPF_JMP_REG(BPF_JLT, BPF_REG_1, BPF_REG_3, 1),
7264 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7265 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7266 BPF_MOV64_IMM(BPF_REG_0, 0),
7267 BPF_EXIT_INSN(),
7268 },
7269 .result = ACCEPT,
7270 .prog_type = BPF_PROG_TYPE_XDP,
7271 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7272 },
7273 {
7274 "XDP pkt read, pkt_data' < pkt_end, bad access 1",
7275 .insns = {
7276 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7277 offsetof(struct xdp_md, data)),
7278 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7279 offsetof(struct xdp_md, data_end)),
7280 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7281 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7282 BPF_JMP_REG(BPF_JLT, BPF_REG_1, BPF_REG_3, 1),
7283 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7284 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7285 BPF_MOV64_IMM(BPF_REG_0, 0),
7286 BPF_EXIT_INSN(),
7287 },
7288 .errstr = "R1 offset is outside of the packet",
7289 .result = REJECT,
7290 .prog_type = BPF_PROG_TYPE_XDP,
7291 },
7292 {
7293 "XDP pkt read, pkt_data' < pkt_end, bad access 2",
7294 .insns = {
7295 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7296 offsetof(struct xdp_md, data)),
7297 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7298 offsetof(struct xdp_md, data_end)),
7299 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7300 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7301 BPF_JMP_REG(BPF_JLT, BPF_REG_1, BPF_REG_3, 1),
7302 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7303 BPF_MOV64_IMM(BPF_REG_0, 0),
7304 BPF_EXIT_INSN(),
7305 },
7306 .errstr = "R1 offset is outside of the packet",
7307 .result = REJECT,
7308 .prog_type = BPF_PROG_TYPE_XDP,
7309 },
7310 {
7311 "XDP pkt read, pkt_end < pkt_data', good access",
7312 .insns = {
7313 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7314 offsetof(struct xdp_md, data)),
7315 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7316 offsetof(struct xdp_md, data_end)),
7317 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7318 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7319 BPF_JMP_REG(BPF_JLT, BPF_REG_3, BPF_REG_1, 1),
7320 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7321 BPF_MOV64_IMM(BPF_REG_0, 0),
7322 BPF_EXIT_INSN(),
7323 },
7324 .result = ACCEPT,
7325 .prog_type = BPF_PROG_TYPE_XDP,
7326 },
7327 {
7328 "XDP pkt read, pkt_end < pkt_data', bad access 1",
7329 .insns = {
7330 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7331 offsetof(struct xdp_md, data)),
7332 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7333 offsetof(struct xdp_md, data_end)),
7334 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7335 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7336 BPF_JMP_REG(BPF_JLT, BPF_REG_3, BPF_REG_1, 1),
7337 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7338 BPF_MOV64_IMM(BPF_REG_0, 0),
7339 BPF_EXIT_INSN(),
7340 },
7341 .errstr = "R1 offset is outside of the packet",
7342 .result = REJECT,
7343 .prog_type = BPF_PROG_TYPE_XDP,
7344 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7345 },
7346 {
7347 "XDP pkt read, pkt_end < pkt_data', bad access 2",
7348 .insns = {
7349 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7350 offsetof(struct xdp_md, data)),
7351 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7352 offsetof(struct xdp_md, data_end)),
7353 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7354 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7355 BPF_JMP_REG(BPF_JLT, BPF_REG_3, BPF_REG_1, 0),
7356 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7357 BPF_MOV64_IMM(BPF_REG_0, 0),
7358 BPF_EXIT_INSN(),
7359 },
7360 .errstr = "R1 offset is outside of the packet",
7361 .result = REJECT,
7362 .prog_type = BPF_PROG_TYPE_XDP,
7363 },
7364 {
7365 "XDP pkt read, pkt_data' >= pkt_end, good access",
7366 .insns = {
7367 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7368 offsetof(struct xdp_md, data)),
7369 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7370 offsetof(struct xdp_md, data_end)),
7371 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7372 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7373 BPF_JMP_REG(BPF_JGE, BPF_REG_1, BPF_REG_3, 1),
7374 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7375 BPF_MOV64_IMM(BPF_REG_0, 0),
7376 BPF_EXIT_INSN(),
7377 },
7378 .result = ACCEPT,
7379 .prog_type = BPF_PROG_TYPE_XDP,
7380 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7381 },
7382 {
7383 "XDP pkt read, pkt_data' >= pkt_end, bad access 1",
7384 .insns = {
7385 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7386 offsetof(struct xdp_md, data)),
7387 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7388 offsetof(struct xdp_md, data_end)),
7389 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7390 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7391 BPF_JMP_REG(BPF_JGE, BPF_REG_1, BPF_REG_3, 1),
7392 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7393 BPF_MOV64_IMM(BPF_REG_0, 0),
7394 BPF_EXIT_INSN(),
7395 },
7396 .errstr = "R1 offset is outside of the packet",
7397 .result = REJECT,
7398 .prog_type = BPF_PROG_TYPE_XDP,
7399 },
7400 {
7401 "XDP pkt read, pkt_data' >= pkt_end, bad access 2",
7402 .insns = {
7403 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7404 offsetof(struct xdp_md, data)),
7405 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7406 offsetof(struct xdp_md, data_end)),
7407 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7408 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7409 BPF_JMP_REG(BPF_JGE, BPF_REG_1, BPF_REG_3, 0),
7410 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7411 BPF_MOV64_IMM(BPF_REG_0, 0),
7412 BPF_EXIT_INSN(),
7413 },
7414 .errstr = "R1 offset is outside of the packet",
7415 .result = REJECT,
7416 .prog_type = BPF_PROG_TYPE_XDP,
7417 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7418 },
7419 {
7420 "XDP pkt read, pkt_end >= pkt_data', good access",
7421 .insns = {
7422 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7423 offsetof(struct xdp_md, data)),
7424 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7425 offsetof(struct xdp_md, data_end)),
7426 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7427 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7428 BPF_JMP_REG(BPF_JGE, BPF_REG_3, BPF_REG_1, 1),
7429 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7430 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7431 BPF_MOV64_IMM(BPF_REG_0, 0),
7432 BPF_EXIT_INSN(),
7433 },
7434 .result = ACCEPT,
7435 .prog_type = BPF_PROG_TYPE_XDP,
7436 },
7437 {
7438 "XDP pkt read, pkt_end >= pkt_data', bad access 1",
7439 .insns = {
7440 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7441 offsetof(struct xdp_md, data)),
7442 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7443 offsetof(struct xdp_md, data_end)),
7444 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7445 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7446 BPF_JMP_REG(BPF_JGE, BPF_REG_3, BPF_REG_1, 1),
7447 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7448 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7449 BPF_MOV64_IMM(BPF_REG_0, 0),
7450 BPF_EXIT_INSN(),
7451 },
7452 .errstr = "R1 offset is outside of the packet",
7453 .result = REJECT,
7454 .prog_type = BPF_PROG_TYPE_XDP,
7455 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7456 },
7457 {
7458 "XDP pkt read, pkt_end >= pkt_data', bad access 2",
7459 .insns = {
7460 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7461 offsetof(struct xdp_md, data)),
7462 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7463 offsetof(struct xdp_md, data_end)),
7464 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7465 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7466 BPF_JMP_REG(BPF_JGE, BPF_REG_3, BPF_REG_1, 1),
7467 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7468 BPF_MOV64_IMM(BPF_REG_0, 0),
7469 BPF_EXIT_INSN(),
7470 },
7471 .errstr = "R1 offset is outside of the packet",
7472 .result = REJECT,
7473 .prog_type = BPF_PROG_TYPE_XDP,
7474 },
7475 {
7476 "XDP pkt read, pkt_data' <= pkt_end, good access",
7477 .insns = {
7478 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7479 offsetof(struct xdp_md, data)),
7480 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7481 offsetof(struct xdp_md, data_end)),
7482 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7483 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7484 BPF_JMP_REG(BPF_JLE, BPF_REG_1, BPF_REG_3, 1),
7485 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7486 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7487 BPF_MOV64_IMM(BPF_REG_0, 0),
7488 BPF_EXIT_INSN(),
7489 },
7490 .result = ACCEPT,
7491 .prog_type = BPF_PROG_TYPE_XDP,
7492 },
7493 {
7494 "XDP pkt read, pkt_data' <= pkt_end, bad access 1",
7495 .insns = {
7496 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7497 offsetof(struct xdp_md, data)),
7498 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7499 offsetof(struct xdp_md, data_end)),
7500 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7501 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7502 BPF_JMP_REG(BPF_JLE, BPF_REG_1, BPF_REG_3, 1),
7503 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7504 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7505 BPF_MOV64_IMM(BPF_REG_0, 0),
7506 BPF_EXIT_INSN(),
7507 },
7508 .errstr = "R1 offset is outside of the packet",
7509 .result = REJECT,
7510 .prog_type = BPF_PROG_TYPE_XDP,
7511 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7512 },
7513 {
7514 "XDP pkt read, pkt_data' <= pkt_end, bad access 2",
7515 .insns = {
7516 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7517 offsetof(struct xdp_md, data)),
7518 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7519 offsetof(struct xdp_md, data_end)),
7520 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7521 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7522 BPF_JMP_REG(BPF_JLE, BPF_REG_1, BPF_REG_3, 1),
7523 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7524 BPF_MOV64_IMM(BPF_REG_0, 0),
7525 BPF_EXIT_INSN(),
7526 },
7527 .errstr = "R1 offset is outside of the packet",
7528 .result = REJECT,
7529 .prog_type = BPF_PROG_TYPE_XDP,
7530 },
7531 {
7532 "XDP pkt read, pkt_end <= pkt_data', good access",
7533 .insns = {
7534 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7535 offsetof(struct xdp_md, data)),
7536 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7537 offsetof(struct xdp_md, data_end)),
7538 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7539 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7540 BPF_JMP_REG(BPF_JLE, BPF_REG_3, BPF_REG_1, 1),
7541 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7542 BPF_MOV64_IMM(BPF_REG_0, 0),
7543 BPF_EXIT_INSN(),
7544 },
7545 .result = ACCEPT,
7546 .prog_type = BPF_PROG_TYPE_XDP,
7547 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7548 },
7549 {
7550 "XDP pkt read, pkt_end <= pkt_data', bad access 1",
7551 .insns = {
7552 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7553 offsetof(struct xdp_md, data)),
7554 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7555 offsetof(struct xdp_md, data_end)),
7556 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7557 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7558 BPF_JMP_REG(BPF_JLE, BPF_REG_3, BPF_REG_1, 1),
7559 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7560 BPF_MOV64_IMM(BPF_REG_0, 0),
7561 BPF_EXIT_INSN(),
7562 },
7563 .errstr = "R1 offset is outside of the packet",
7564 .result = REJECT,
7565 .prog_type = BPF_PROG_TYPE_XDP,
7566 },
7567 {
7568 "XDP pkt read, pkt_end <= pkt_data', bad access 2",
7569 .insns = {
7570 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7571 offsetof(struct xdp_md, data)),
7572 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7573 offsetof(struct xdp_md, data_end)),
7574 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7575 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7576 BPF_JMP_REG(BPF_JLE, BPF_REG_3, BPF_REG_1, 0),
7577 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7578 BPF_MOV64_IMM(BPF_REG_0, 0),
7579 BPF_EXIT_INSN(),
7580 },
7581 .errstr = "R1 offset is outside of the packet",
7582 .result = REJECT,
7583 .prog_type = BPF_PROG_TYPE_XDP,
7584 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7585 },
7586 {
7587 "XDP pkt read, pkt_meta' > pkt_data, good access",
7588 .insns = {
7589 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7590 offsetof(struct xdp_md, data_meta)),
7591 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7592 offsetof(struct xdp_md, data)),
7593 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7594 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7595 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 1),
7596 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7597 BPF_MOV64_IMM(BPF_REG_0, 0),
7598 BPF_EXIT_INSN(),
7599 },
7600 .result = ACCEPT,
7601 .prog_type = BPF_PROG_TYPE_XDP,
7602 },
7603 {
7604 "XDP pkt read, pkt_meta' > pkt_data, bad access 1",
7605 .insns = {
7606 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7607 offsetof(struct xdp_md, data_meta)),
7608 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7609 offsetof(struct xdp_md, data)),
7610 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7611 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7612 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 1),
7613 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7614 BPF_MOV64_IMM(BPF_REG_0, 0),
7615 BPF_EXIT_INSN(),
7616 },
7617 .errstr = "R1 offset is outside of the packet",
7618 .result = REJECT,
7619 .prog_type = BPF_PROG_TYPE_XDP,
7620 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7621 },
7622 {
7623 "XDP pkt read, pkt_meta' > pkt_data, bad access 2",
7624 .insns = {
7625 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7626 offsetof(struct xdp_md, data_meta)),
7627 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7628 offsetof(struct xdp_md, data)),
7629 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7630 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7631 BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 0),
7632 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7633 BPF_MOV64_IMM(BPF_REG_0, 0),
7634 BPF_EXIT_INSN(),
7635 },
7636 .errstr = "R1 offset is outside of the packet",
7637 .result = REJECT,
7638 .prog_type = BPF_PROG_TYPE_XDP,
7639 },
7640 {
7641 "XDP pkt read, pkt_data > pkt_meta', good access",
7642 .insns = {
7643 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7644 offsetof(struct xdp_md, data_meta)),
7645 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7646 offsetof(struct xdp_md, data)),
7647 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7648 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7649 BPF_JMP_REG(BPF_JGT, BPF_REG_3, BPF_REG_1, 1),
7650 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7651 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7652 BPF_MOV64_IMM(BPF_REG_0, 0),
7653 BPF_EXIT_INSN(),
7654 },
7655 .result = ACCEPT,
7656 .prog_type = BPF_PROG_TYPE_XDP,
7657 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7658 },
7659 {
7660 "XDP pkt read, pkt_data > pkt_meta', bad access 1",
7661 .insns = {
7662 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7663 offsetof(struct xdp_md, data_meta)),
7664 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7665 offsetof(struct xdp_md, data)),
7666 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7667 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7668 BPF_JMP_REG(BPF_JGT, BPF_REG_3, BPF_REG_1, 1),
7669 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7670 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7671 BPF_MOV64_IMM(BPF_REG_0, 0),
7672 BPF_EXIT_INSN(),
7673 },
7674 .errstr = "R1 offset is outside of the packet",
7675 .result = REJECT,
7676 .prog_type = BPF_PROG_TYPE_XDP,
7677 },
7678 {
7679 "XDP pkt read, pkt_data > pkt_meta', bad access 2",
7680 .insns = {
7681 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7682 offsetof(struct xdp_md, data_meta)),
7683 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7684 offsetof(struct xdp_md, data)),
7685 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7686 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7687 BPF_JMP_REG(BPF_JGT, BPF_REG_3, BPF_REG_1, 1),
7688 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7689 BPF_MOV64_IMM(BPF_REG_0, 0),
7690 BPF_EXIT_INSN(),
7691 },
7692 .errstr = "R1 offset is outside of the packet",
7693 .result = REJECT,
7694 .prog_type = BPF_PROG_TYPE_XDP,
7695 },
7696 {
7697 "XDP pkt read, pkt_meta' < pkt_data, good access",
7698 .insns = {
7699 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7700 offsetof(struct xdp_md, data_meta)),
7701 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7702 offsetof(struct xdp_md, data)),
7703 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7704 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7705 BPF_JMP_REG(BPF_JLT, BPF_REG_1, BPF_REG_3, 1),
7706 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7707 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7708 BPF_MOV64_IMM(BPF_REG_0, 0),
7709 BPF_EXIT_INSN(),
7710 },
7711 .result = ACCEPT,
7712 .prog_type = BPF_PROG_TYPE_XDP,
7713 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7714 },
7715 {
7716 "XDP pkt read, pkt_meta' < pkt_data, bad access 1",
7717 .insns = {
7718 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7719 offsetof(struct xdp_md, data_meta)),
7720 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7721 offsetof(struct xdp_md, data)),
7722 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7723 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7724 BPF_JMP_REG(BPF_JLT, BPF_REG_1, BPF_REG_3, 1),
7725 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7726 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7727 BPF_MOV64_IMM(BPF_REG_0, 0),
7728 BPF_EXIT_INSN(),
7729 },
7730 .errstr = "R1 offset is outside of the packet",
7731 .result = REJECT,
7732 .prog_type = BPF_PROG_TYPE_XDP,
7733 },
7734 {
7735 "XDP pkt read, pkt_meta' < pkt_data, bad access 2",
7736 .insns = {
7737 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7738 offsetof(struct xdp_md, data_meta)),
7739 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7740 offsetof(struct xdp_md, data)),
7741 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7742 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7743 BPF_JMP_REG(BPF_JLT, BPF_REG_1, BPF_REG_3, 1),
7744 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7745 BPF_MOV64_IMM(BPF_REG_0, 0),
7746 BPF_EXIT_INSN(),
7747 },
7748 .errstr = "R1 offset is outside of the packet",
7749 .result = REJECT,
7750 .prog_type = BPF_PROG_TYPE_XDP,
7751 },
7752 {
7753 "XDP pkt read, pkt_data < pkt_meta', good access",
7754 .insns = {
7755 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7756 offsetof(struct xdp_md, data_meta)),
7757 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7758 offsetof(struct xdp_md, data)),
7759 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7760 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7761 BPF_JMP_REG(BPF_JLT, BPF_REG_3, BPF_REG_1, 1),
7762 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7763 BPF_MOV64_IMM(BPF_REG_0, 0),
7764 BPF_EXIT_INSN(),
7765 },
7766 .result = ACCEPT,
7767 .prog_type = BPF_PROG_TYPE_XDP,
7768 },
7769 {
7770 "XDP pkt read, pkt_data < pkt_meta', bad access 1",
7771 .insns = {
7772 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7773 offsetof(struct xdp_md, data_meta)),
7774 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7775 offsetof(struct xdp_md, data)),
7776 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7777 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7778 BPF_JMP_REG(BPF_JLT, BPF_REG_3, BPF_REG_1, 1),
7779 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7780 BPF_MOV64_IMM(BPF_REG_0, 0),
7781 BPF_EXIT_INSN(),
7782 },
7783 .errstr = "R1 offset is outside of the packet",
7784 .result = REJECT,
7785 .prog_type = BPF_PROG_TYPE_XDP,
7786 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7787 },
7788 {
7789 "XDP pkt read, pkt_data < pkt_meta', bad access 2",
7790 .insns = {
7791 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7792 offsetof(struct xdp_md, data_meta)),
7793 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7794 offsetof(struct xdp_md, data)),
7795 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7796 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7797 BPF_JMP_REG(BPF_JLT, BPF_REG_3, BPF_REG_1, 0),
7798 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7799 BPF_MOV64_IMM(BPF_REG_0, 0),
7800 BPF_EXIT_INSN(),
7801 },
7802 .errstr = "R1 offset is outside of the packet",
7803 .result = REJECT,
7804 .prog_type = BPF_PROG_TYPE_XDP,
7805 },
7806 {
7807 "XDP pkt read, pkt_meta' >= pkt_data, good access",
7808 .insns = {
7809 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7810 offsetof(struct xdp_md, data_meta)),
7811 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7812 offsetof(struct xdp_md, data)),
7813 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7814 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7815 BPF_JMP_REG(BPF_JGE, BPF_REG_1, BPF_REG_3, 1),
7816 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7817 BPF_MOV64_IMM(BPF_REG_0, 0),
7818 BPF_EXIT_INSN(),
7819 },
7820 .result = ACCEPT,
7821 .prog_type = BPF_PROG_TYPE_XDP,
7822 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7823 },
7824 {
7825 "XDP pkt read, pkt_meta' >= pkt_data, bad access 1",
7826 .insns = {
7827 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7828 offsetof(struct xdp_md, data_meta)),
7829 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7830 offsetof(struct xdp_md, data)),
7831 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7832 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7833 BPF_JMP_REG(BPF_JGE, BPF_REG_1, BPF_REG_3, 1),
7834 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7835 BPF_MOV64_IMM(BPF_REG_0, 0),
7836 BPF_EXIT_INSN(),
7837 },
7838 .errstr = "R1 offset is outside of the packet",
7839 .result = REJECT,
7840 .prog_type = BPF_PROG_TYPE_XDP,
7841 },
7842 {
7843 "XDP pkt read, pkt_meta' >= pkt_data, bad access 2",
7844 .insns = {
7845 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7846 offsetof(struct xdp_md, data_meta)),
7847 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7848 offsetof(struct xdp_md, data)),
7849 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7850 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7851 BPF_JMP_REG(BPF_JGE, BPF_REG_1, BPF_REG_3, 0),
7852 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7853 BPF_MOV64_IMM(BPF_REG_0, 0),
7854 BPF_EXIT_INSN(),
7855 },
7856 .errstr = "R1 offset is outside of the packet",
7857 .result = REJECT,
7858 .prog_type = BPF_PROG_TYPE_XDP,
7859 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7860 },
7861 {
7862 "XDP pkt read, pkt_data >= pkt_meta', good access",
7863 .insns = {
7864 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7865 offsetof(struct xdp_md, data_meta)),
7866 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7867 offsetof(struct xdp_md, data)),
7868 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7869 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7870 BPF_JMP_REG(BPF_JGE, BPF_REG_3, BPF_REG_1, 1),
7871 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7872 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7873 BPF_MOV64_IMM(BPF_REG_0, 0),
7874 BPF_EXIT_INSN(),
7875 },
7876 .result = ACCEPT,
7877 .prog_type = BPF_PROG_TYPE_XDP,
7878 },
7879 {
7880 "XDP pkt read, pkt_data >= pkt_meta', bad access 1",
7881 .insns = {
7882 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7883 offsetof(struct xdp_md, data_meta)),
7884 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7885 offsetof(struct xdp_md, data)),
7886 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7887 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7888 BPF_JMP_REG(BPF_JGE, BPF_REG_3, BPF_REG_1, 1),
7889 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7890 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7891 BPF_MOV64_IMM(BPF_REG_0, 0),
7892 BPF_EXIT_INSN(),
7893 },
7894 .errstr = "R1 offset is outside of the packet",
7895 .result = REJECT,
7896 .prog_type = BPF_PROG_TYPE_XDP,
7897 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7898 },
7899 {
7900 "XDP pkt read, pkt_data >= pkt_meta', bad access 2",
7901 .insns = {
7902 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7903 offsetof(struct xdp_md, data_meta)),
7904 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7905 offsetof(struct xdp_md, data)),
7906 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7907 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7908 BPF_JMP_REG(BPF_JGE, BPF_REG_3, BPF_REG_1, 1),
7909 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7910 BPF_MOV64_IMM(BPF_REG_0, 0),
7911 BPF_EXIT_INSN(),
7912 },
7913 .errstr = "R1 offset is outside of the packet",
7914 .result = REJECT,
7915 .prog_type = BPF_PROG_TYPE_XDP,
7916 },
7917 {
7918 "XDP pkt read, pkt_meta' <= pkt_data, good access",
7919 .insns = {
7920 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7921 offsetof(struct xdp_md, data_meta)),
7922 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7923 offsetof(struct xdp_md, data)),
7924 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7925 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7926 BPF_JMP_REG(BPF_JLE, BPF_REG_1, BPF_REG_3, 1),
7927 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7928 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7929 BPF_MOV64_IMM(BPF_REG_0, 0),
7930 BPF_EXIT_INSN(),
7931 },
7932 .result = ACCEPT,
7933 .prog_type = BPF_PROG_TYPE_XDP,
7934 },
7935 {
7936 "XDP pkt read, pkt_meta' <= pkt_data, bad access 1",
7937 .insns = {
7938 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7939 offsetof(struct xdp_md, data_meta)),
7940 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7941 offsetof(struct xdp_md, data)),
7942 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7943 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7944 BPF_JMP_REG(BPF_JLE, BPF_REG_1, BPF_REG_3, 1),
7945 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
7946 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -4),
7947 BPF_MOV64_IMM(BPF_REG_0, 0),
7948 BPF_EXIT_INSN(),
7949 },
7950 .errstr = "R1 offset is outside of the packet",
7951 .result = REJECT,
7952 .prog_type = BPF_PROG_TYPE_XDP,
7953 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7954 },
7955 {
7956 "XDP pkt read, pkt_meta' <= pkt_data, bad access 2",
7957 .insns = {
7958 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7959 offsetof(struct xdp_md, data_meta)),
7960 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7961 offsetof(struct xdp_md, data)),
7962 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7963 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7964 BPF_JMP_REG(BPF_JLE, BPF_REG_1, BPF_REG_3, 1),
7965 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
7966 BPF_MOV64_IMM(BPF_REG_0, 0),
7967 BPF_EXIT_INSN(),
7968 },
7969 .errstr = "R1 offset is outside of the packet",
7970 .result = REJECT,
7971 .prog_type = BPF_PROG_TYPE_XDP,
7972 },
7973 {
7974 "XDP pkt read, pkt_data <= pkt_meta', good access",
7975 .insns = {
7976 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7977 offsetof(struct xdp_md, data_meta)),
7978 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7979 offsetof(struct xdp_md, data)),
7980 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7981 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
7982 BPF_JMP_REG(BPF_JLE, BPF_REG_3, BPF_REG_1, 1),
7983 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
7984 BPF_MOV64_IMM(BPF_REG_0, 0),
7985 BPF_EXIT_INSN(),
7986 },
7987 .result = ACCEPT,
7988 .prog_type = BPF_PROG_TYPE_XDP,
7989 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
7990 },
7991 {
7992 "XDP pkt read, pkt_data <= pkt_meta', bad access 1",
7993 .insns = {
7994 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
7995 offsetof(struct xdp_md, data_meta)),
7996 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
7997 offsetof(struct xdp_md, data)),
7998 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
7999 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
8000 BPF_JMP_REG(BPF_JLE, BPF_REG_3, BPF_REG_1, 1),
8001 BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8),
8002 BPF_MOV64_IMM(BPF_REG_0, 0),
8003 BPF_EXIT_INSN(),
8004 },
8005 .errstr = "R1 offset is outside of the packet",
8006 .result = REJECT,
8007 .prog_type = BPF_PROG_TYPE_XDP,
8008 },
8009 {
8010 "XDP pkt read, pkt_data <= pkt_meta', bad access 2",
8011 .insns = {
8012 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
8013 offsetof(struct xdp_md, data_meta)),
8014 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1,
8015 offsetof(struct xdp_md, data)),
8016 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
8017 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 8),
8018 BPF_JMP_REG(BPF_JLE, BPF_REG_3, BPF_REG_1, 0),
8019 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, -5),
8020 BPF_MOV64_IMM(BPF_REG_0, 0),
8021 BPF_EXIT_INSN(),
8022 },
8023 .errstr = "R1 offset is outside of the packet",
8024 .result = REJECT,
8025 .prog_type = BPF_PROG_TYPE_XDP,
8026 .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
8027 },
8028 {
8029 "bpf_exit with invalid return code. test1",
8030 .insns = {
8031 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
8032 BPF_EXIT_INSN(),
8033 },
8034 .errstr = "R0 has value (0x0; 0xffffffff)",
8035 .result = REJECT,
8036 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
8037 },
8038 {
8039 "bpf_exit with invalid return code. test2",
8040 .insns = {
8041 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
8042 BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1),
8043 BPF_EXIT_INSN(),
8044 },
8045 .result = ACCEPT,
8046 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
8047 },
8048 {
8049 "bpf_exit with invalid return code. test3",
8050 .insns = {
8051 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
8052 BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 3),
8053 BPF_EXIT_INSN(),
8054 },
8055 .errstr = "R0 has value (0x0; 0x3)",
8056 .result = REJECT,
8057 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
8058 },
8059 {
8060 "bpf_exit with invalid return code. test4",
8061 .insns = {
8062 BPF_MOV64_IMM(BPF_REG_0, 1),
8063 BPF_EXIT_INSN(),
8064 },
8065 .result = ACCEPT,
8066 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
8067 },
8068 {
8069 "bpf_exit with invalid return code. test5",
8070 .insns = {
8071 BPF_MOV64_IMM(BPF_REG_0, 2),
8072 BPF_EXIT_INSN(),
8073 },
8074 .errstr = "R0 has value (0x2; 0x0)",
8075 .result = REJECT,
8076 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
8077 },
8078 {
8079 "bpf_exit with invalid return code. test6",
8080 .insns = {
8081 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
8082 BPF_EXIT_INSN(),
8083 },
8084 .errstr = "R0 is not a known value (ctx)",
8085 .result = REJECT,
8086 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
8087 },
8088 {
8089 "bpf_exit with invalid return code. test7",
8090 .insns = {
8091 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
8092 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 4),
8093 BPF_ALU64_REG(BPF_MUL, BPF_REG_0, BPF_REG_2),
8094 BPF_EXIT_INSN(),
8095 },
8096 .errstr = "R0 has unknown scalar value",
8097 .result = REJECT,
8098 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
8099 },
6648}; 8100};
6649 8101
6650static int probe_filter_length(const struct bpf_insn *fp) 8102static int probe_filter_length(const struct bpf_insn *fp)
@@ -6692,7 +8144,7 @@ static int create_map_in_map(void)
6692 return inner_map_fd; 8144 return inner_map_fd;
6693 } 8145 }
6694 8146
6695 outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, 8147 outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL,
6696 sizeof(int), inner_map_fd, 1, 0); 8148 sizeof(int), inner_map_fd, 1, 0);
6697 if (outer_map_fd < 0) 8149 if (outer_map_fd < 0)
6698 printf("Failed to create array of maps '%s'!\n", 8150 printf("Failed to create array of maps '%s'!\n",
diff --git a/tools/testing/selftests/bpf/test_verifier_log.c b/tools/testing/selftests/bpf/test_verifier_log.c
new file mode 100644
index 000000000000..3cc0b561489e
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_verifier_log.c
@@ -0,0 +1,171 @@
1#include <errno.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5#include <unistd.h>
6
7#include <linux/bpf.h>
8#include <linux/filter.h>
9#include <linux/unistd.h>
10
11#include <bpf/bpf.h>
12
13#define LOG_SIZE (1 << 20)
14
15#define err(str...) printf("ERROR: " str)
16
17static const struct bpf_insn code_sample[] = {
18 /* We need a few instructions to pass the min log length */
19 BPF_MOV64_IMM(BPF_REG_0, 0),
20 BPF_MOV64_IMM(BPF_REG_0, 0),
21 BPF_MOV64_IMM(BPF_REG_0, 0),
22 BPF_MOV64_IMM(BPF_REG_0, 0),
23 BPF_MOV64_IMM(BPF_REG_0, 0),
24 BPF_MOV64_IMM(BPF_REG_0, 0),
25 BPF_MOV64_IMM(BPF_REG_0, 0),
26 BPF_MOV64_IMM(BPF_REG_0, 0),
27 BPF_MOV64_IMM(BPF_REG_0, 0),
28 BPF_MOV64_IMM(BPF_REG_0, 0),
29 BPF_MOV64_IMM(BPF_REG_0, 0),
30 BPF_MOV64_IMM(BPF_REG_0, 0),
31 BPF_MOV64_IMM(BPF_REG_0, 0),
32 BPF_MOV64_IMM(BPF_REG_0, 0),
33 BPF_MOV64_IMM(BPF_REG_0, 0),
34 BPF_MOV64_IMM(BPF_REG_0, 0),
35 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
36 BPF_FUNC_map_lookup_elem),
37 BPF_EXIT_INSN(),
38};
39
40static inline __u64 ptr_to_u64(const void *ptr)
41{
42 return (__u64) (unsigned long) ptr;
43}
44
45static int load(char *log, size_t log_len, int log_level)
46{
47 union bpf_attr attr;
48
49 bzero(&attr, sizeof(attr));
50 attr.prog_type = BPF_PROG_TYPE_SOCKET_FILTER;
51 attr.insn_cnt = (__u32)(sizeof(code_sample) / sizeof(struct bpf_insn));
52 attr.insns = ptr_to_u64(code_sample);
53 attr.license = ptr_to_u64("GPL");
54 attr.log_buf = ptr_to_u64(log);
55 attr.log_size = log_len;
56 attr.log_level = log_level;
57
58 return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
59}
60
61static void check_ret(int ret, int exp_errno)
62{
63 if (ret > 0) {
64 close(ret);
65 err("broken sample loaded successfully!?\n");
66 exit(1);
67 }
68
69 if (!ret || errno != exp_errno) {
70 err("Program load returned: ret:%d/errno:%d, expected ret:%d/errno:%d\n",
71 ret, errno, -1, exp_errno);
72 exit(1);
73 }
74}
75
76static void check_ones(const char *buf, size_t len, const char *msg)
77{
78 while (len--)
79 if (buf[len] != 1) {
80 err("%s", msg);
81 exit(1);
82 }
83}
84
85static void test_log_good(char *log, size_t buf_len, size_t log_len,
86 size_t exp_len, int exp_errno, const char *full_log)
87{
88 size_t len;
89 int ret;
90
91 memset(log, 1, buf_len);
92
93 ret = load(log, log_len, 1);
94 check_ret(ret, exp_errno);
95
96 len = strnlen(log, buf_len);
97 if (len == buf_len) {
98 err("verifier did not NULL terminate the log\n");
99 exit(1);
100 }
101 if (exp_len && len != exp_len) {
102 err("incorrect log length expected:%zd have:%zd\n",
103 exp_len, len);
104 exit(1);
105 }
106
107 if (strchr(log, 1)) {
108 err("verifier leaked a byte through\n");
109 exit(1);
110 }
111
112 check_ones(log + len + 1, buf_len - len - 1,
113 "verifier wrote bytes past NULL termination\n");
114
115 if (memcmp(full_log, log, LOG_SIZE)) {
116 err("log did not match expected output\n");
117 exit(1);
118 }
119}
120
121static void test_log_bad(char *log, size_t log_len, int log_level)
122{
123 int ret;
124
125 ret = load(log, log_len, log_level);
126 check_ret(ret, EINVAL);
127 if (log)
128 check_ones(log, LOG_SIZE,
129 "verifier touched log with bad parameters\n");
130}
131
132int main(int argc, char **argv)
133{
134 char full_log[LOG_SIZE];
135 char log[LOG_SIZE];
136 size_t want_len;
137 int i;
138
139 memset(log, 1, LOG_SIZE);
140
141 /* Test incorrect attr */
142 printf("Test log_level 0...\n");
143 test_log_bad(log, LOG_SIZE, 0);
144
145 printf("Test log_size < 128...\n");
146 test_log_bad(log, 15, 1);
147
148 printf("Test log_buff = NULL...\n");
149 test_log_bad(NULL, LOG_SIZE, 1);
150
151 /* Test with log big enough */
152 printf("Test oversized buffer...\n");
153 test_log_good(full_log, LOG_SIZE, LOG_SIZE, 0, EACCES, full_log);
154
155 want_len = strlen(full_log);
156
157 printf("Test exact buffer...\n");
158 test_log_good(log, LOG_SIZE, want_len + 2, want_len, EACCES, full_log);
159
160 printf("Test undersized buffers...\n");
161 for (i = 0; i < 64; i++) {
162 full_log[want_len - i + 1] = 1;
163 full_log[want_len - i] = 0;
164
165 test_log_good(log, LOG_SIZE, want_len + 1 - i, want_len - i,
166 ENOSPC, full_log);
167 }
168
169 printf("test_verifier_log: OK\n");
170 return 0;
171}
diff --git a/tools/testing/selftests/bpf/test_xdp_meta.c b/tools/testing/selftests/bpf/test_xdp_meta.c
new file mode 100644
index 000000000000..8d0182650653
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_xdp_meta.c
@@ -0,0 +1,53 @@
1#include <linux/bpf.h>
2#include <linux/if_ether.h>
3#include <linux/pkt_cls.h>
4
5#include "bpf_helpers.h"
6
7#define __round_mask(x, y) ((__typeof__(x))((y) - 1))
8#define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1)
9#define ctx_ptr(ctx, mem) (void *)(unsigned long)ctx->mem
10
11SEC("t")
12int ing_cls(struct __sk_buff *ctx)
13{
14 __u8 *data, *data_meta, *data_end;
15 __u32 diff = 0;
16
17 data_meta = ctx_ptr(ctx, data_meta);
18 data_end = ctx_ptr(ctx, data_end);
19 data = ctx_ptr(ctx, data);
20
21 if (data + ETH_ALEN > data_end ||
22 data_meta + round_up(ETH_ALEN, 4) > data)
23 return TC_ACT_SHOT;
24
25 diff |= ((__u32 *)data_meta)[0] ^ ((__u32 *)data)[0];
26 diff |= ((__u16 *)data_meta)[2] ^ ((__u16 *)data)[2];
27
28 return diff ? TC_ACT_SHOT : TC_ACT_OK;
29}
30
31SEC("x")
32int ing_xdp(struct xdp_md *ctx)
33{
34 __u8 *data, *data_meta, *data_end;
35 int ret;
36
37 ret = bpf_xdp_adjust_meta(ctx, -round_up(ETH_ALEN, 4));
38 if (ret < 0)
39 return XDP_DROP;
40
41 data_meta = ctx_ptr(ctx, data_meta);
42 data_end = ctx_ptr(ctx, data_end);
43 data = ctx_ptr(ctx, data);
44
45 if (data + ETH_ALEN > data_end ||
46 data_meta + round_up(ETH_ALEN, 4) > data)
47 return XDP_DROP;
48
49 __builtin_memcpy(data_meta, data, ETH_ALEN);
50 return XDP_PASS;
51}
52
53char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/test_xdp_meta.sh b/tools/testing/selftests/bpf/test_xdp_meta.sh
new file mode 100755
index 000000000000..307aa856cee3
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_xdp_meta.sh
@@ -0,0 +1,51 @@
1#!/bin/sh
2
3cleanup()
4{
5 if [ "$?" = "0" ]; then
6 echo "selftests: test_xdp_meta [PASS]";
7 else
8 echo "selftests: test_xdp_meta [FAILED]";
9 fi
10
11 set +e
12 ip netns del ns1 2> /dev/null
13 ip netns del ns2 2> /dev/null
14}
15
16ip link set dev lo xdp off 2>/dev/null > /dev/null
17if [ $? -ne 0 ];then
18 echo "selftests: [SKIP] Could not run test without the ip xdp support"
19 exit 0
20fi
21set -e
22
23ip netns add ns1
24ip netns add ns2
25
26trap cleanup 0 2 3 6 9
27
28ip link add veth1 type veth peer name veth2
29
30ip link set veth1 netns ns1
31ip link set veth2 netns ns2
32
33ip netns exec ns1 ip addr add 10.1.1.11/24 dev veth1
34ip netns exec ns2 ip addr add 10.1.1.22/24 dev veth2
35
36ip netns exec ns1 tc qdisc add dev veth1 clsact
37ip netns exec ns2 tc qdisc add dev veth2 clsact
38
39ip netns exec ns1 tc filter add dev veth1 ingress bpf da obj test_xdp_meta.o sec t
40ip netns exec ns2 tc filter add dev veth2 ingress bpf da obj test_xdp_meta.o sec t
41
42ip netns exec ns1 ip link set dev veth1 xdp obj test_xdp_meta.o sec x
43ip netns exec ns2 ip link set dev veth2 xdp obj test_xdp_meta.o sec x
44
45ip netns exec ns1 ip link set dev veth1 up
46ip netns exec ns2 ip link set dev veth2 up
47
48ip netns exec ns1 ping -c 1 10.1.1.22
49ip netns exec ns2 ping -c 1 10.1.1.11
50
51exit 0
diff --git a/tools/testing/selftests/breakpoints/Makefile b/tools/testing/selftests/breakpoints/Makefile
index 6b214b7b10fb..9ec2c78de8ca 100644
--- a/tools/testing/selftests/breakpoints/Makefile
+++ b/tools/testing/selftests/breakpoints/Makefile
@@ -1,15 +1,16 @@
1# SPDX-License-Identifier: GPL-2.0
1# Taken from perf makefile 2# Taken from perf makefile
2uname_M := $(shell uname -m 2>/dev/null || echo not) 3uname_M := $(shell uname -m 2>/dev/null || echo not)
3ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) 4ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
4 5
6TEST_GEN_PROGS := step_after_suspend_test
7
5ifeq ($(ARCH),x86) 8ifeq ($(ARCH),x86)
6TEST_GEN_PROGS := breakpoint_test 9TEST_GEN_PROGS += breakpoint_test
7endif 10endif
8ifneq (,$(filter $(ARCH),aarch64 arm64)) 11ifneq (,$(filter $(ARCH),aarch64 arm64))
9TEST_GEN_PROGS := breakpoint_test_arm64 12TEST_GEN_PROGS += breakpoint_test_arm64
10endif 13endif
11 14
12TEST_GEN_PROGS += step_after_suspend_test
13
14include ../lib.mk 15include ../lib.mk
15 16
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c b/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
index 960d02100c26..2d95e5adde72 100644
--- a/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
+++ b/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
@@ -19,6 +19,7 @@
19 19
20#define _GNU_SOURCE 20#define _GNU_SOURCE
21 21
22#include <asm/ptrace.h>
22#include <sys/types.h> 23#include <sys/types.h>
23#include <sys/wait.h> 24#include <sys/wait.h>
24#include <sys/ptrace.h> 25#include <sys/ptrace.h>
diff --git a/tools/testing/selftests/capabilities/Makefile b/tools/testing/selftests/capabilities/Makefile
index 29b8adfdac71..6e9d98d457d5 100644
--- a/tools/testing/selftests/capabilities/Makefile
+++ b/tools/testing/selftests/capabilities/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_GEN_FILES := validate_cap 2TEST_GEN_FILES := validate_cap
2TEST_GEN_PROGS := test_execve 3TEST_GEN_PROGS := test_execve
3 4
diff --git a/tools/testing/selftests/capabilities/test_execve.c b/tools/testing/selftests/capabilities/test_execve.c
index cf6778441381..3ab39a61b95b 100644
--- a/tools/testing/selftests/capabilities/test_execve.c
+++ b/tools/testing/selftests/capabilities/test_execve.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2 3
3#include <cap-ng.h> 4#include <cap-ng.h>
diff --git a/tools/testing/selftests/capabilities/validate_cap.c b/tools/testing/selftests/capabilities/validate_cap.c
index 694cd73d4493..cdfc94268fe6 100644
--- a/tools/testing/selftests/capabilities/validate_cap.c
+++ b/tools/testing/selftests/capabilities/validate_cap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <cap-ng.h> 2#include <cap-ng.h>
2#include <linux/capability.h> 3#include <linux/capability.h>
3#include <stdbool.h> 4#include <stdbool.h>
diff --git a/tools/testing/selftests/cpu-hotplug/Makefile b/tools/testing/selftests/cpu-hotplug/Makefile
index fe1f99101c5d..d8be047ee5b6 100644
--- a/tools/testing/selftests/cpu-hotplug/Makefile
+++ b/tools/testing/selftests/cpu-hotplug/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: 2all:
2 3
3TEST_PROGS := cpu-on-off-test.sh 4TEST_PROGS := cpu-on-off-test.sh
diff --git a/tools/testing/selftests/cpu-hotplug/config b/tools/testing/selftests/cpu-hotplug/config
index e6ab090cfbf3..d4aca2ad5069 100644
--- a/tools/testing/selftests/cpu-hotplug/config
+++ b/tools/testing/selftests/cpu-hotplug/config
@@ -1,2 +1 @@
1CONFIG_NOTIFIER_ERROR_INJECTION=y CONFIG_NOTIFIER_ERROR_INJECTION=y
2CONFIG_CPU_NOTIFIER_ERROR_INJECT=m
diff --git a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
index b18b253d7bfb..f3a8933c1275 100755
--- a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
+++ b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3SYSFS= 4SYSFS=
4 5
diff --git a/tools/testing/selftests/cpufreq/Makefile b/tools/testing/selftests/cpufreq/Makefile
index 3955cd96f3a2..c86ca8342222 100644
--- a/tools/testing/selftests/cpufreq/Makefile
+++ b/tools/testing/selftests/cpufreq/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: 2all:
2 3
3TEST_PROGS := main.sh 4TEST_PROGS := main.sh
diff --git a/tools/testing/selftests/cpufreq/cpu.sh b/tools/testing/selftests/cpufreq/cpu.sh
index 8e08a83d65f2..39fdcdfb8e97 100755
--- a/tools/testing/selftests/cpufreq/cpu.sh
+++ b/tools/testing/selftests/cpufreq/cpu.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# CPU helpers 4# CPU helpers
4 5
diff --git a/tools/testing/selftests/cpufreq/cpufreq.sh b/tools/testing/selftests/cpufreq/cpufreq.sh
index 1ed3832030b4..b583a2fb4504 100755
--- a/tools/testing/selftests/cpufreq/cpufreq.sh
+++ b/tools/testing/selftests/cpufreq/cpufreq.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3# protect against multiple inclusion 4# protect against multiple inclusion
4if [ $FILE_CPUFREQ ]; then 5if [ $FILE_CPUFREQ ]; then
diff --git a/tools/testing/selftests/cpufreq/governor.sh b/tools/testing/selftests/cpufreq/governor.sh
index def645103555..fe37df79c087 100755
--- a/tools/testing/selftests/cpufreq/governor.sh
+++ b/tools/testing/selftests/cpufreq/governor.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# Test governors 4# Test governors
4 5
diff --git a/tools/testing/selftests/cpufreq/main.sh b/tools/testing/selftests/cpufreq/main.sh
index 01bac76ac0ec..d83922de9d89 100755
--- a/tools/testing/selftests/cpufreq/main.sh
+++ b/tools/testing/selftests/cpufreq/main.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3source cpu.sh 4source cpu.sh
4source cpufreq.sh 5source cpufreq.sh
diff --git a/tools/testing/selftests/cpufreq/module.sh b/tools/testing/selftests/cpufreq/module.sh
index 8ff2244a33a1..22563cd122e7 100755
--- a/tools/testing/selftests/cpufreq/module.sh
+++ b/tools/testing/selftests/cpufreq/module.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# Modules specific tests cases 4# Modules specific tests cases
4 5
diff --git a/tools/testing/selftests/cpufreq/special-tests.sh b/tools/testing/selftests/cpufreq/special-tests.sh
index 58b730f23ef7..8d40505dc468 100755
--- a/tools/testing/selftests/cpufreq/special-tests.sh
+++ b/tools/testing/selftests/cpufreq/special-tests.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# Special test cases reported by people 4# Special test cases reported by people
4 5
diff --git a/tools/testing/selftests/drivers/gpu/drm_mm.sh b/tools/testing/selftests/drivers/gpu/drm_mm.sh
index 96dd55c92799..b789dc8257e6 100755
--- a/tools/testing/selftests/drivers/gpu/drm_mm.sh
+++ b/tools/testing/selftests/drivers/gpu/drm_mm.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs API tests for struct drm_mm (DRM range manager) 3# Runs API tests for struct drm_mm (DRM range manager)
3 4
4if ! /sbin/modprobe -n -q test-drm_mm; then 5if ! /sbin/modprobe -n -q test-drm_mm; then
diff --git a/tools/testing/selftests/drivers/gpu/i915.sh b/tools/testing/selftests/drivers/gpu/i915.sh
index c06d6e8a8dcc..d3895bc714b7 100755
--- a/tools/testing/selftests/drivers/gpu/i915.sh
+++ b/tools/testing/selftests/drivers/gpu/i915.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs hardware independent tests for i915 (drivers/gpu/drm/i915) 3# Runs hardware independent tests for i915 (drivers/gpu/drm/i915)
3 4
4if ! /sbin/modprobe -q -r i915; then 5if ! /sbin/modprobe -q -r i915; then
diff --git a/tools/testing/selftests/efivarfs/create-read.c b/tools/testing/selftests/efivarfs/create-read.c
index 7feef1880968..9674a19396a3 100644
--- a/tools/testing/selftests/efivarfs/create-read.c
+++ b/tools/testing/selftests/efivarfs/create-read.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <stdint.h> 3#include <stdint.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh b/tools/testing/selftests/efivarfs/efivarfs.sh
index 057278448515..c6d5790575ae 100755
--- a/tools/testing/selftests/efivarfs/efivarfs.sh
+++ b/tools/testing/selftests/efivarfs/efivarfs.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3efivarfs_mount=/sys/firmware/efi/efivars 4efivarfs_mount=/sys/firmware/efi/efivars
4test_guid=210be57c-9849-4fc7-a635-e6382d1aec27 5test_guid=210be57c-9849-4fc7-a635-e6382d1aec27
diff --git a/tools/testing/selftests/efivarfs/open-unlink.c b/tools/testing/selftests/efivarfs/open-unlink.c
index 4af74f733036..562742d44ac9 100644
--- a/tools/testing/selftests/efivarfs/open-unlink.c
+++ b/tools/testing/selftests/efivarfs/open-unlink.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <errno.h> 2#include <errno.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdint.h> 4#include <stdint.h>
diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile
index 2e13035dff7f..427c41ba5151 100644
--- a/tools/testing/selftests/exec/Makefile
+++ b/tools/testing/selftests/exec/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS = -Wall 2CFLAGS = -Wall
2 3
3TEST_GEN_PROGS := execveat 4TEST_GEN_PROGS := execveat
diff --git a/tools/testing/selftests/exec/execveat.c b/tools/testing/selftests/exec/execveat.c
index 8d5d1d2ee7c1..67cd4597db2b 100644
--- a/tools/testing/selftests/exec/execveat.c
+++ b/tools/testing/selftests/exec/execveat.c
@@ -147,7 +147,7 @@ static void exe_cp(const char *src, const char *dest)
147} 147}
148 148
149#define XX_DIR_LEN 200 149#define XX_DIR_LEN 200
150static int check_execveat_pathmax(int dot_dfd, const char *src, int is_script) 150static int check_execveat_pathmax(int root_dfd, const char *src, int is_script)
151{ 151{
152 int fail = 0; 152 int fail = 0;
153 int ii, count, len; 153 int ii, count, len;
@@ -156,20 +156,30 @@ static int check_execveat_pathmax(int dot_dfd, const char *src, int is_script)
156 156
157 if (*longpath == '\0') { 157 if (*longpath == '\0') {
158 /* Create a filename close to PATH_MAX in length */ 158 /* Create a filename close to PATH_MAX in length */
159 char *cwd = getcwd(NULL, 0);
160
161 if (!cwd) {
162 printf("Failed to getcwd(), errno=%d (%s)\n",
163 errno, strerror(errno));
164 return 2;
165 }
166 strcpy(longpath, cwd);
167 strcat(longpath, "/");
159 memset(longname, 'x', XX_DIR_LEN - 1); 168 memset(longname, 'x', XX_DIR_LEN - 1);
160 longname[XX_DIR_LEN - 1] = '/'; 169 longname[XX_DIR_LEN - 1] = '/';
161 longname[XX_DIR_LEN] = '\0'; 170 longname[XX_DIR_LEN] = '\0';
162 count = (PATH_MAX - 3) / XX_DIR_LEN; 171 count = (PATH_MAX - 3 - strlen(cwd)) / XX_DIR_LEN;
163 for (ii = 0; ii < count; ii++) { 172 for (ii = 0; ii < count; ii++) {
164 strcat(longpath, longname); 173 strcat(longpath, longname);
165 mkdir(longpath, 0755); 174 mkdir(longpath, 0755);
166 } 175 }
167 len = (PATH_MAX - 3) - (count * XX_DIR_LEN); 176 len = (PATH_MAX - 3 - strlen(cwd)) - (count * XX_DIR_LEN);
168 if (len <= 0) 177 if (len <= 0)
169 len = 1; 178 len = 1;
170 memset(longname, 'y', len); 179 memset(longname, 'y', len);
171 longname[len] = '\0'; 180 longname[len] = '\0';
172 strcat(longpath, longname); 181 strcat(longpath, longname);
182 free(cwd);
173 } 183 }
174 exe_cp(src, longpath); 184 exe_cp(src, longpath);
175 185
@@ -190,7 +200,7 @@ static int check_execveat_pathmax(int dot_dfd, const char *src, int is_script)
190 } 200 }
191 201
192 /* 202 /*
193 * Execute as a long pathname relative to ".". If this is a script, 203 * Execute as a long pathname relative to "/". If this is a script,
194 * the interpreter will launch but fail to open the script because its 204 * the interpreter will launch but fail to open the script because its
195 * name ("/dev/fd/5/xxx....") is bigger than PATH_MAX. 205 * name ("/dev/fd/5/xxx....") is bigger than PATH_MAX.
196 * 206 *
@@ -200,10 +210,10 @@ static int check_execveat_pathmax(int dot_dfd, const char *src, int is_script)
200 * the exit status shall be 126."), so allow either. 210 * the exit status shall be 126."), so allow either.
201 */ 211 */
202 if (is_script) 212 if (is_script)
203 fail += check_execveat_invoked_rc(dot_dfd, longpath, 0, 213 fail += check_execveat_invoked_rc(root_dfd, longpath + 1, 0,
204 127, 126); 214 127, 126);
205 else 215 else
206 fail += check_execveat(dot_dfd, longpath, 0); 216 fail += check_execveat(root_dfd, longpath + 1, 0);
207 217
208 return fail; 218 return fail;
209} 219}
@@ -218,6 +228,7 @@ static int run_tests(void)
218 int subdir_dfd_ephemeral = open_or_die("subdir.ephemeral", 228 int subdir_dfd_ephemeral = open_or_die("subdir.ephemeral",
219 O_DIRECTORY|O_RDONLY); 229 O_DIRECTORY|O_RDONLY);
220 int dot_dfd = open_or_die(".", O_DIRECTORY|O_RDONLY); 230 int dot_dfd = open_or_die(".", O_DIRECTORY|O_RDONLY);
231 int root_dfd = open_or_die("/", O_DIRECTORY|O_RDONLY);
221 int dot_dfd_path = open_or_die(".", O_DIRECTORY|O_RDONLY|O_PATH); 232 int dot_dfd_path = open_or_die(".", O_DIRECTORY|O_RDONLY|O_PATH);
222 int dot_dfd_cloexec = open_or_die(".", O_DIRECTORY|O_RDONLY|O_CLOEXEC); 233 int dot_dfd_cloexec = open_or_die(".", O_DIRECTORY|O_RDONLY|O_CLOEXEC);
223 int fd = open_or_die("execveat", O_RDONLY); 234 int fd = open_or_die("execveat", O_RDONLY);
@@ -353,8 +364,8 @@ static int run_tests(void)
353 /* Attempt to execute relative to non-directory => ENOTDIR */ 364 /* Attempt to execute relative to non-directory => ENOTDIR */
354 fail += check_execveat_fail(fd, "execveat", 0, ENOTDIR); 365 fail += check_execveat_fail(fd, "execveat", 0, ENOTDIR);
355 366
356 fail += check_execveat_pathmax(dot_dfd, "execveat", 0); 367 fail += check_execveat_pathmax(root_dfd, "execveat", 0);
357 fail += check_execveat_pathmax(dot_dfd, "script", 1); 368 fail += check_execveat_pathmax(root_dfd, "script", 1);
358 return fail; 369 return fail;
359} 370}
360 371
diff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile
index 0ab11307b414..13a73bf725b5 100644
--- a/tools/testing/selftests/filesystems/Makefile
+++ b/tools/testing/selftests/filesystems/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_PROGS := dnotify_test 2TEST_PROGS := dnotify_test
2all: $(TEST_PROGS) 3all: $(TEST_PROGS)
3 4
diff --git a/tools/testing/selftests/filesystems/dnotify_test.c b/tools/testing/selftests/filesystems/dnotify_test.c
index 8b37b4a1e18d..c0a9b2d3302d 100644
--- a/tools/testing/selftests/filesystems/dnotify_test.c
+++ b/tools/testing/selftests/filesystems/dnotify_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE /* needed to get the defines */ 2#define _GNU_SOURCE /* needed to get the defines */
2#include <fcntl.h> /* in glibc 2.2 this has the needed 3#include <fcntl.h> /* in glibc 2.2 this has the needed
3 values defined */ 4 values defined */
diff --git a/tools/testing/selftests/firmware/fw_fallback.sh b/tools/testing/selftests/firmware/fw_fallback.sh
index 8f511035f783..34a42c68ebfb 100755
--- a/tools/testing/selftests/firmware/fw_fallback.sh
+++ b/tools/testing/selftests/firmware/fw_fallback.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# This validates that the kernel will fall back to using the fallback mechanism 3# This validates that the kernel will fall back to using the fallback mechanism
3# to load firmware it can't find on disk itself. We must request a firmware 4# to load firmware it can't find on disk itself. We must request a firmware
4# that the kernel won't find, and any installed helper (e.g. udev) also 5# that the kernel won't find, and any installed helper (e.g. udev) also
@@ -85,6 +86,11 @@ load_fw_cancel()
85 86
86load_fw_custom() 87load_fw_custom()
87{ 88{
89 if [ ! -e "$DIR"/trigger_custom_fallback ]; then
90 echo "$0: custom fallback trigger not present, ignoring test" >&2
91 return 1
92 fi
93
88 local name="$1" 94 local name="$1"
89 local file="$2" 95 local file="$2"
90 96
@@ -107,11 +113,17 @@ load_fw_custom()
107 113
108 # Wait for request to finish. 114 # Wait for request to finish.
109 wait 115 wait
116 return 0
110} 117}
111 118
112 119
113load_fw_custom_cancel() 120load_fw_custom_cancel()
114{ 121{
122 if [ ! -e "$DIR"/trigger_custom_fallback ]; then
123 echo "$0: canceling custom fallback trigger not present, ignoring test" >&2
124 return 1
125 fi
126
115 local name="$1" 127 local name="$1"
116 local file="$2" 128 local file="$2"
117 129
@@ -132,6 +144,7 @@ load_fw_custom_cancel()
132 144
133 # Wait for request to finish. 145 # Wait for request to finish.
134 wait 146 wait
147 return 0
135} 148}
136 149
137load_fw_fallback_with_child() 150load_fw_fallback_with_child()
@@ -226,20 +239,22 @@ else
226 echo "$0: cancelling fallback mechanism works" 239 echo "$0: cancelling fallback mechanism works"
227fi 240fi
228 241
229load_fw_custom "$NAME" "$FW" 242if load_fw_custom "$NAME" "$FW" ; then
230if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then 243 if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then
231 echo "$0: firmware was not loaded" >&2 244 echo "$0: firmware was not loaded" >&2
232 exit 1 245 exit 1
233else 246 else
234 echo "$0: custom fallback loading mechanism works" 247 echo "$0: custom fallback loading mechanism works"
248 fi
235fi 249fi
236 250
237load_fw_custom_cancel "nope-$NAME" "$FW" 251if load_fw_custom_cancel "nope-$NAME" "$FW" ; then
238if diff -q "$FW" /dev/test_firmware >/dev/null ; then 252 if diff -q "$FW" /dev/test_firmware >/dev/null ; then
239 echo "$0: firmware was expected to be cancelled" >&2 253 echo "$0: firmware was expected to be cancelled" >&2
240 exit 1 254 exit 1
241else 255 else
242 echo "$0: cancelling custom fallback mechanism works" 256 echo "$0: cancelling custom fallback mechanism works"
257 fi
243fi 258fi
244 259
245set +e 260set +e
diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh
index 7d8fd2e3695a..b1f20fef36c7 100755
--- a/tools/testing/selftests/firmware/fw_filesystem.sh
+++ b/tools/testing/selftests/firmware/fw_filesystem.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# This validates that the kernel will load firmware out of its list of 3# This validates that the kernel will load firmware out of its list of
3# firmware locations on disk. Since the user helper does similar work, 4# firmware locations on disk. Since the user helper does similar work,
4# we reset the custom load directory to a location the user helper doesn't 5# we reset the custom load directory to a location the user helper doesn't
@@ -69,9 +70,13 @@ if printf '\000' >"$DIR"/trigger_request 2> /dev/null; then
69 exit 1 70 exit 1
70fi 71fi
71 72
72if printf '\000' >"$DIR"/trigger_async_request 2> /dev/null; then 73if [ ! -e "$DIR"/trigger_async_request ]; then
73 echo "$0: empty filename should not succeed (async)" >&2 74 echo "$0: empty filename: async trigger not present, ignoring test" >&2
74 exit 1 75else
76 if printf '\000' >"$DIR"/trigger_async_request 2> /dev/null; then
77 echo "$0: empty filename should not succeed (async)" >&2
78 exit 1
79 fi
75fi 80fi
76 81
77# Request a firmware that doesn't exist, it should fail. 82# Request a firmware that doesn't exist, it should fail.
@@ -104,17 +109,21 @@ else
104fi 109fi
105 110
106# Try the asynchronous version too 111# Try the asynchronous version too
107if ! echo -n "$NAME" >"$DIR"/trigger_async_request ; then 112if [ ! -e "$DIR"/trigger_async_request ]; then
108 echo "$0: could not trigger async request" >&2 113 echo "$0: firmware loading: async trigger not present, ignoring test" >&2
109 exit 1
110fi
111
112# Verify the contents are what we expect.
113if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then
114 echo "$0: firmware was not loaded (async)" >&2
115 exit 1
116else 114else
117 echo "$0: async filesystem loading works" 115 if ! echo -n "$NAME" >"$DIR"/trigger_async_request ; then
116 echo "$0: could not trigger async request" >&2
117 exit 1
118 fi
119
120 # Verify the contents are what we expect.
121 if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then
122 echo "$0: firmware was not loaded (async)" >&2
123 exit 1
124 else
125 echo "$0: async filesystem loading works"
126 fi
118fi 127fi
119 128
120### Batched requests tests 129### Batched requests tests
diff --git a/tools/testing/selftests/ftrace/Makefile b/tools/testing/selftests/ftrace/Makefile
index a8a5e21850e7..cd1f5b3a7774 100644
--- a/tools/testing/selftests/ftrace/Makefile
+++ b/tools/testing/selftests/ftrace/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: 2all:
2 3
3TEST_PROGS := ftracetest 4TEST_PROGS := ftracetest
diff --git a/tools/testing/selftests/ftrace/config b/tools/testing/selftests/ftrace/config
index 8a1c9f949fe0..b01924c71c09 100644
--- a/tools/testing/selftests/ftrace/config
+++ b/tools/testing/selftests/ftrace/config
@@ -1,2 +1,6 @@
1CONFIG_KPROBES=y 1CONFIG_KPROBES=y
2CONFIG_FTRACE=y 2CONFIG_FTRACE=y
3CONFIG_FUNCTION_PROFILER=y
4CONFIG_TRACER_SNAPSHOT=y
5CONFIG_STACK_TRACER=y
6CONFIG_HIST_TRIGGERS=y
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest
index abc706cf7702..f9a9d424c980 100755
--- a/tools/testing/selftests/ftrace/ftracetest
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -222,7 +222,14 @@ SIG_RESULT=
222SIG_BASE=36 # Use realtime signals 222SIG_BASE=36 # Use realtime signals
223SIG_PID=$$ 223SIG_PID=$$
224 224
225exit_pass () {
226 exit 0
227}
228
225SIG_FAIL=$((SIG_BASE + FAIL)) 229SIG_FAIL=$((SIG_BASE + FAIL))
230exit_fail () {
231 exit 1
232}
226trap 'SIG_RESULT=$FAIL' $SIG_FAIL 233trap 'SIG_RESULT=$FAIL' $SIG_FAIL
227 234
228SIG_UNRESOLVED=$((SIG_BASE + UNRESOLVED)) 235SIG_UNRESOLVED=$((SIG_BASE + UNRESOLVED))
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/basic2.tc b/tools/testing/selftests/ftrace/test.d/00basic/basic2.tc
index ebfce83f35b4..531e472362df 100644
--- a/tools/testing/selftests/ftrace/test.d/00basic/basic2.tc
+++ b/tools/testing/selftests/ftrace/test.d/00basic/basic2.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Basic test for tracers 3# description: Basic test for tracers
3# flags: instance 4# flags: instance
4test -f available_tracers 5test -f available_tracers
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/basic3.tc b/tools/testing/selftests/ftrace/test.d/00basic/basic3.tc
index 9e33f841812f..58a2506f788e 100644
--- a/tools/testing/selftests/ftrace/test.d/00basic/basic3.tc
+++ b/tools/testing/selftests/ftrace/test.d/00basic/basic3.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Basic trace clock test 3# description: Basic trace clock test
3# flags: instance 4# flags: instance
4test -f trace_clock 5test -f trace_clock
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/basic4.tc b/tools/testing/selftests/ftrace/test.d/00basic/basic4.tc
index aa51f6c17359..0696098d6408 100644
--- a/tools/testing/selftests/ftrace/test.d/00basic/basic4.tc
+++ b/tools/testing/selftests/ftrace/test.d/00basic/basic4.tc
@@ -2,4 +2,4 @@
2# description: Basic event tracing check 2# description: Basic event tracing check
3test -f available_events -a -f set_event -a -d events 3test -f available_events -a -f set_event -a -d events
4# check scheduler events are available 4# check scheduler events are available
5grep -q sched available_events && exit 0 || exit $FAIL 5grep -q sched available_events && exit_pass || exit_fail
diff --git a/tools/testing/selftests/ftrace/test.d/event/event-enable.tc b/tools/testing/selftests/ftrace/test.d/event/event-enable.tc
index 283b45ecb199..9daf034186f5 100644
--- a/tools/testing/selftests/ftrace/test.d/event/event-enable.tc
+++ b/tools/testing/selftests/ftrace/test.d/event/event-enable.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event tracing - enable/disable with event level files 3# description: event tracing - enable/disable with event level files
3# flags: instance 4# flags: instance
4 5
@@ -10,7 +11,7 @@ do_reset() {
10fail() { #msg 11fail() { #msg
11 do_reset 12 do_reset
12 echo $1 13 echo $1
13 exit $FAIL 14 exit_fail
14} 15}
15 16
16yield() { 17yield() {
diff --git a/tools/testing/selftests/ftrace/test.d/event/event-pid.tc b/tools/testing/selftests/ftrace/test.d/event/event-pid.tc
index 96c1a95be4f7..132478b305c2 100644
--- a/tools/testing/selftests/ftrace/test.d/event/event-pid.tc
+++ b/tools/testing/selftests/ftrace/test.d/event/event-pid.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event tracing - restricts events based on pid 3# description: event tracing - restricts events based on pid
3# flags: instance 4# flags: instance
4 5
@@ -12,7 +13,7 @@ do_reset() {
12fail() { #msg 13fail() { #msg
13 do_reset 14 do_reset
14 echo $1 15 echo $1
15 exit $FAIL 16 exit_fail
16} 17}
17 18
18yield() { 19yield() {
diff --git a/tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc b/tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc
index b8fe2e5b9e67..6a37a8642ee6 100644
--- a/tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc
+++ b/tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event tracing - enable/disable with subsystem level files 3# description: event tracing - enable/disable with subsystem level files
3# flags: instance 4# flags: instance
4 5
@@ -10,7 +11,7 @@ do_reset() {
10fail() { #msg 11fail() { #msg
11 do_reset 12 do_reset
12 echo $1 13 echo $1
13 exit $FAIL 14 exit_fail
14} 15}
15 16
16yield() { 17yield() {
diff --git a/tools/testing/selftests/ftrace/test.d/event/toplevel-enable.tc b/tools/testing/selftests/ftrace/test.d/event/toplevel-enable.tc
index 15e2d3fe1731..4e9b6e2c0219 100644
--- a/tools/testing/selftests/ftrace/test.d/event/toplevel-enable.tc
+++ b/tools/testing/selftests/ftrace/test.d/event/toplevel-enable.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event tracing - enable/disable with top level files 3# description: event tracing - enable/disable with top level files
3 4
4do_reset() { 5do_reset() {
@@ -9,7 +10,7 @@ do_reset() {
9fail() { #msg 10fail() { #msg
10 do_reset 11 do_reset
11 echo $1 12 echo $1
12 exit $FAIL 13 exit_fail
13} 14}
14 15
15yield() { 16yield() {
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc
index 15c2dba06ea2..1aec99d108eb 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - function graph filters with stack tracer 3# description: ftrace - function graph filters with stack tracer
3 4
4# Make sure that function graph filtering works, and is not 5# Make sure that function graph filtering works, and is not
@@ -27,7 +28,7 @@ do_reset() {
27fail() { # msg 28fail() { # msg
28 do_reset 29 do_reset
29 echo $1 30 echo $1
30 exit $FAIL 31 exit_fail
31} 32}
32 33
33disable_tracing 34disable_tracing
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc
index 0ab2189613ef..9f8d27ca39cf 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - function graph filters 3# description: ftrace - function graph filters
3 4
4# Make sure that function graph filtering works 5# Make sure that function graph filtering works
@@ -17,7 +18,7 @@ do_reset() {
17fail() { # msg 18fail() { # msg
18 do_reset 19 do_reset
19 echo $1 20 echo $1
20 exit $FAIL 21 exit_fail
21} 22}
22 23
23disable_tracing 24disable_tracing
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc
index 8095e122daa9..589d52b211b7 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - function glob filters 3# description: ftrace - function glob filters
3 4
4# Make sure that function glob matching filter works. 5# Make sure that function glob matching filter works.
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
index bab5ff7c607e..524ce24b3c22 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - function pid filters 3# description: ftrace - function pid filters
3 4
4# Make sure that function pid matching filter works. 5# Make sure that function pid matching filter works.
@@ -50,7 +51,7 @@ do_reset() {
50fail() { # msg 51fail() { # msg
51 do_reset 52 do_reset
52 echo $1 53 echo $1
53 exit $FAIL 54 exit_fail
54} 55}
55 56
56yield() { 57yield() {
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc
index 77dfb6b48186..6fed4cf2db81 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - test for function event triggers 3# description: ftrace - test for function event triggers
3# flags: instance 4# flags: instance
4# 5#
@@ -26,7 +27,7 @@ do_reset() {
26fail() { # mesg 27fail() { # mesg
27 do_reset 28 do_reset
28 echo $1 29 echo $1
29 exit $FAIL 30 exit_fail
30} 31}
31 32
32SLEEP_TIME=".1" 33SLEEP_TIME=".1"
@@ -47,8 +48,7 @@ test_event_enabled() {
47 48
48 e=`cat $EVENT_ENABLE` 49 e=`cat $EVENT_ENABLE`
49 if [ "$e" != $val ]; then 50 if [ "$e" != $val ]; then
50 echo "Expected $val but found $e" 51 fail "Expected $val but found $e"
51 exit 1
52 fi 52 fi
53} 53}
54 54
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc
index 7808336d6f50..b2d5a8febfe8 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - function profiler with function tracing 3# description: ftrace - function profiler with function tracing
3 4
4# There was a bug after a rewrite of the ftrace infrastructure that 5# There was a bug after a rewrite of the ftrace infrastructure that
@@ -31,7 +32,7 @@ fail() { # mesg
31 reset_tracer 32 reset_tracer
32 echo > set_ftrace_filter 33 echo > set_ftrace_filter
33 echo $1 34 echo $1
34 exit $FAIL 35 exit_fail
35} 36}
36 37
37echo "Testing function tracer with profiler:" 38echo "Testing function tracer with profiler:"
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
index 113b4d9bc733..0f3f92622e33 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - test reading of set_ftrace_filter 3# description: ftrace - test reading of set_ftrace_filter
3# 4#
4# The set_ftrace_filter file of ftrace is used to list functions as well as 5# The set_ftrace_filter file of ftrace is used to list functions as well as
@@ -25,14 +26,14 @@ do_reset() {
25fail() { # mesg 26fail() { # mesg
26 do_reset 27 do_reset
27 echo $1 28 echo $1
28 exit $FAIL 29 exit_fail
29} 30}
30 31
31do_reset 32do_reset
32 33
33FILTER=set_ftrace_filter 34FILTER=set_ftrace_filter
34FUNC1="schedule" 35FUNC1="schedule"
35FUNC2="do_IRQ" 36FUNC2="do_softirq"
36 37
37ALL_FUNCS="#### all functions enabled ####" 38ALL_FUNCS="#### all functions enabled ####"
38 39
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func_traceonoff_triggers.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func_traceonoff_triggers.tc
index 7a9ab4ff83b6..f6d9ac73268a 100644
--- a/tools/testing/selftests/ftrace/test.d/ftrace/func_traceonoff_triggers.tc
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_traceonoff_triggers.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: ftrace - test for function traceon/off triggers 3# description: ftrace - test for function traceon/off triggers
3# flags: instance 4# flags: instance
4# 5#
@@ -26,7 +27,7 @@ do_reset() {
26fail() { # mesg 27fail() { # mesg
27 do_reset 28 do_reset
28 echo $1 29 echo $1
29 exit $FAIL 30 exit_fail
30} 31}
31 32
32SLEEP_TIME=".1" 33SLEEP_TIME=".1"
diff --git a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
index 8a353314dc9b..4fa0f79144f4 100644
--- a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
+++ b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Test creation and deletion of trace instances while setting an event 3# description: Test creation and deletion of trace instances while setting an event
3 4
4if [ ! -d instances ] ; then 5if [ ! -d instances ] ; then
@@ -10,7 +11,7 @@ fail() { # mesg
10 rmdir foo 2>/dev/null 11 rmdir foo 2>/dev/null
11 echo $1 12 echo $1
12 set -e 13 set -e
13 exit $FAIL 14 exit_fail
14} 15}
15 16
16cd instances 17cd instances
diff --git a/tools/testing/selftests/ftrace/test.d/instances/instance.tc b/tools/testing/selftests/ftrace/test.d/instances/instance.tc
index 1e1abe0ad354..b84651283bf3 100644
--- a/tools/testing/selftests/ftrace/test.d/instances/instance.tc
+++ b/tools/testing/selftests/ftrace/test.d/instances/instance.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Test creation and deletion of trace instances 3# description: Test creation and deletion of trace instances
3 4
4if [ ! -d instances ] ; then 5if [ ! -d instances ] ; then
@@ -10,7 +11,7 @@ fail() { # mesg
10 rmdir x y z 2>/dev/null 11 rmdir x y z 2>/dev/null
11 echo $1 12 echo $1
12 set -e 13 set -e
13 exit $FAIL 14 exit_fail
14} 15}
15 16
16cd instances 17cd instances
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc b/tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
index c3843ed49bf6..4604d2103c89 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kprobe dynamic event - adding and removing 3# description: Kprobe dynamic event - adding and removing
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc b/tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
index 74507db8bbc8..bbc443a9190c 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kprobe dynamic event - busy event check 3# description: Kprobe dynamic event - busy event check
3 4
4[ -f kprobe_events ] || exit_unsupported 5[ -f kprobe_events ] || exit_unsupported
@@ -8,7 +9,7 @@ echo > kprobe_events
8echo p:myevent _do_fork > kprobe_events 9echo p:myevent _do_fork > kprobe_events
9test -d events/kprobes/myevent 10test -d events/kprobes/myevent
10echo 1 > events/kprobes/myevent/enable 11echo 1 > events/kprobes/myevent/enable
11echo > kprobe_events && exit 1 # this must fail 12echo > kprobe_events && exit_fail # this must fail
12echo 0 > events/kprobes/myevent/enable 13echo 0 > events/kprobes/myevent/enable
13echo > kprobe_events # this must succeed 14echo > kprobe_events # this must succeed
14clear_trace 15clear_trace
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
index 64949d4eda69..8b43c6804fc3 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kprobe dynamic event with arguments 3# description: Kprobe dynamic event with arguments
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
@@ -13,5 +14,5 @@ echo 1 > events/kprobes/testprobe/enable
13echo 0 > events/kprobes/testprobe/enable 14echo 0 > events/kprobes/testprobe/enable
14echo "-:testprobe" >> kprobe_events 15echo "-:testprobe" >> kprobe_events
15clear_trace 16clear_trace
16test -d events/kprobes/testprobe && exit 1 || exit 0 17test -d events/kprobes/testprobe && exit_fail || exit_pass
17 18
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc
index c75faefb4fff..2a1755bfc290 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kprobes event arguments with types 3# description: Kprobes event arguments with types
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
@@ -34,4 +35,4 @@ check_types $ARGS
34 35
35echo "-:testprobe" >> kprobe_events 36echo "-:testprobe" >> kprobe_events
36clear_trace 37clear_trace
37test -d events/kprobes/testprobe && exit 1 || exit 0 38test -d events/kprobes/testprobe && exit_fail || exit_pass
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc
index b9302cc82c12..2724a1068cb1 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kprobe event auto/manual naming 3# description: Kprobe event auto/manual naming
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc
index d6f2f4965697..cc4cac0e60f2 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kprobe dynamic event with function tracer 3# description: Kprobe dynamic event with function tracer
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
index 6d634e4b7680..1e9f75f7a30f 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kprobe dynamic event - probing module 3# description: Kprobe dynamic event - probing module
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
index 0d09546258fd..321954683aaa 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kretprobe dynamic event with arguments 3# description: Kretprobe dynamic event with arguments
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
@@ -13,4 +14,4 @@ echo 1 > events/kprobes/testprobe2/enable
13echo 0 > events/kprobes/testprobe2/enable 14echo 0 > events/kprobes/testprobe2/enable
14echo '-:testprobe2' >> kprobe_events 15echo '-:testprobe2' >> kprobe_events
15clear_trace 16clear_trace
16test -d events/kprobes/testprobe2 && exit 1 || exit 0 17test -d events/kprobes/testprobe2 && exit_fail || exit_pass
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_maxactive.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_maxactive.tc
index 7ec6f2639ad6..7c0290684c43 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_maxactive.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_maxactive.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Kretprobe dynamic event with maxactive 3# description: Kretprobe dynamic event with maxactive
3 4
4[ -f kprobe_events ] || exit_unsupported # this is configurable 5[ -f kprobe_events ] || exit_unsupported # this is configurable
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc b/tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc
index 2a1cb9908746..bb16cf91f1b5 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc
@@ -1,6 +1,9 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: Register/unregister many kprobe events 3# description: Register/unregister many kprobe events
3 4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
4# ftrace fentry skip size depends on the machine architecture. 7# ftrace fentry skip size depends on the machine architecture.
5# Currently HAVE_KPROBES_ON_FTRACE defined on x86 and powerpc64le 8# Currently HAVE_KPROBES_ON_FTRACE defined on x86 and powerpc64le
6case `uname -m` in 9case `uname -m` in
diff --git a/tools/testing/selftests/ftrace/test.d/template b/tools/testing/selftests/ftrace/test.d/template
index 5448f7abad5f..5c39ceb18a0d 100644
--- a/tools/testing/selftests/ftrace/test.d/template
+++ b/tools/testing/selftests/ftrace/test.d/template
@@ -4,6 +4,7 @@
4# Note that all tests are run with "errexit" option. 4# Note that all tests are run with "errexit" option.
5 5
6exit 0 # Return 0 if the test is passed, otherwise return !0 6exit 0 # Return 0 if the test is passed, otherwise return !0
7# Or you can call exit_pass for passed test, and exit_fail for failed test.
7# If the test could not run because of lack of feature, call exit_unsupported 8# If the test could not run because of lack of feature, call exit_unsupported
8# If the test returned unclear results, call exit_unresolved 9# If the test returned unclear results, call exit_unresolved
9# If the test is a dummy, or a placeholder, call exit_untested 10# If the test is a dummy, or a placeholder, call exit_untested
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-eventonoff.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-eventonoff.tc
index c5435adfdd93..28cc355a3a7b 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-eventonoff.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-eventonoff.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test event enable/disable trigger 3# description: event trigger - test event enable/disable trigger
3# flags: instance 4# flags: instance
4 5
@@ -11,7 +12,7 @@ do_reset() {
11fail() { #msg 12fail() { #msg
12 do_reset 13 do_reset
13 echo $1 14 echo $1
14 exit $FAIL 15 exit_fail
15} 16}
16 17
17if [ ! -f set_event -o ! -d events/sched ]; then 18if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-filter.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-filter.tc
index 48849a8d577f..a48e23eb8a8b 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-filter.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-filter.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test trigger filter 3# description: event trigger - test trigger filter
3# flags: instance 4# flags: instance
4 5
@@ -11,7 +12,7 @@ do_reset() {
11fail() { #msg 12fail() { #msg
12 do_reset 13 do_reset
13 echo $1 14 echo $1
14 exit $FAIL 15 exit_fail
15} 16}
16 17
17if [ ! -f set_event -o ! -d events/sched ]; then 18if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc
index b7f86d10b549..8da80efc44d8 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test histogram modifiers 3# description: event trigger - test histogram modifiers
3# flags: instance 4# flags: instance
4 5
@@ -11,7 +12,7 @@ do_reset() {
11fail() { #msg 12fail() { #msg
12 do_reset 13 do_reset
13 echo $1 14 echo $1
14 exit $FAIL 15 exit_fail
15} 16}
16 17
17if [ ! -f set_event -o ! -d events/sched ]; then 18if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist.tc
index fb66f7d9339d..449fe9ff91a2 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test histogram trigger 3# description: event trigger - test histogram trigger
3# flags: instance 4# flags: instance
4 5
@@ -11,7 +12,7 @@ do_reset() {
11fail() { #msg 12fail() { #msg
12 do_reset 13 do_reset
13 echo $1 14 echo $1
14 exit $FAIL 15 exit_fail
15} 16}
16 17
17if [ ! -f set_event -o ! -d events/sched ]; then 18if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-multihist.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-multihist.tc
index f9153087dd7c..c5ef8b9d02b3 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-multihist.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-multihist.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test multiple histogram triggers 3# description: event trigger - test multiple histogram triggers
3# flags: instance 4# flags: instance
4 5
@@ -11,7 +12,7 @@ do_reset() {
11fail() { #msg 12fail() { #msg
12 do_reset 13 do_reset
13 echo $1 14 echo $1
14 exit $FAIL 15 exit_fail
15} 16}
16 17
17if [ ! -f set_event -o ! -d events/sched ]; then 18if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc
index ed94f0c4e0e4..ed38f0050d77 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test snapshot-trigger 3# description: event trigger - test snapshot-trigger
3 4
4do_reset() { 5do_reset() {
@@ -10,7 +11,7 @@ do_reset() {
10fail() { #msg 11fail() { #msg
11 do_reset 12 do_reset
12 echo $1 13 echo $1
13 exit $FAIL 14 exit_fail
14} 15}
15 16
16if [ ! -f set_event -o ! -d events/sched ]; then 17if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-stacktrace.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-stacktrace.tc
index 9fa23b085def..3121d795a868 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-stacktrace.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-stacktrace.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test stacktrace-trigger 3# description: event trigger - test stacktrace-trigger
3 4
4do_reset() { 5do_reset() {
@@ -10,7 +11,7 @@ do_reset() {
10fail() { #msg 11fail() { #msg
11 do_reset 12 do_reset
12 echo $1 13 echo $1
13 exit $FAIL 14 exit_fail
14} 15}
15 16
16if [ ! -f set_event -o ! -d events/sched ]; then 17if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-traceonoff.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-traceonoff.tc
index 87648e5f987c..c59d9eb546da 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-traceonoff.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-traceonoff.tc
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# description: event trigger - test traceon/off trigger 3# description: event trigger - test traceon/off trigger
3 4
4do_reset() { 5do_reset() {
@@ -10,7 +11,7 @@ do_reset() {
10fail() { #msg 11fail() { #msg
11 do_reset 12 do_reset
12 echo $1 13 echo $1
13 exit $FAIL 14 exit_fail
14} 15}
15 16
16if [ ! -f set_event -o ! -d events/sched ]; then 17if [ ! -f set_event -o ! -d events/sched ]; then
diff --git a/tools/testing/selftests/futex/Makefile b/tools/testing/selftests/futex/Makefile
index 7c647f619d63..cea4adcd42b8 100644
--- a/tools/testing/selftests/futex/Makefile
+++ b/tools/testing/selftests/futex/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1SUBDIRS := functional 2SUBDIRS := functional
2 3
3TEST_PROGS := run.sh 4TEST_PROGS := run.sh
@@ -7,14 +8,17 @@ TEST_PROGS := run.sh
7include ../lib.mk 8include ../lib.mk
8 9
9all: 10all:
10 for DIR in $(SUBDIRS); do \ 11 @for DIR in $(SUBDIRS); do \
11 BUILD_TARGET=$(OUTPUT)/$$DIR; \ 12 BUILD_TARGET=$(OUTPUT)/$$DIR; \
12 mkdir $$BUILD_TARGET -p; \ 13 mkdir $$BUILD_TARGET -p; \
13 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ 14 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
15 if [ -e $$DIR/$(TEST_PROGS) ]; then
16 rsync -a $$DIR/$(TEST_PROGS) $$BUILD_TARGET/;
17 fi
14 done 18 done
15 19
16override define RUN_TESTS 20override define RUN_TESTS
17 $(OUTPUT)/run.sh 21 @cd $(OUTPUT); ./run.sh
18endef 22endef
19 23
20override define INSTALL_RULE 24override define INSTALL_RULE
@@ -33,7 +37,7 @@ override define EMIT_TESTS
33endef 37endef
34 38
35override define CLEAN 39override define CLEAN
36 for DIR in $(SUBDIRS); do \ 40 @for DIR in $(SUBDIRS); do \
37 BUILD_TARGET=$(OUTPUT)/$$DIR; \ 41 BUILD_TARGET=$(OUTPUT)/$$DIR; \
38 mkdir $$BUILD_TARGET -p; \ 42 mkdir $$BUILD_TARGET -p; \
39 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ 43 make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile
index a648e7a6cbc3..ff8feca49746 100644
--- a/tools/testing/selftests/futex/functional/Makefile
+++ b/tools/testing/selftests/futex/functional/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1INCLUDES := -I../include -I../../ 2INCLUDES := -I../include -I../../
2CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES) 3CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES)
3LDFLAGS := $(LDFLAGS) -pthread -lrt 4LDFLAGS := $(LDFLAGS) -pthread -lrt
diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
index 298929df97e6..1bbb47565c55 100644
--- a/tools/testing/selftests/gpio/Makefile
+++ b/tools/testing/selftests/gpio/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1 2
2TEST_PROGS := gpio-mockup.sh 3TEST_PROGS := gpio-mockup.sh
3TEST_FILES := gpio-mockup-sysfs.sh $(BINARIES) 4TEST_FILES := gpio-mockup-sysfs.sh $(BINARIES)
diff --git a/tools/testing/selftests/gpio/gpio-mockup-sysfs.sh b/tools/testing/selftests/gpio/gpio-mockup-sysfs.sh
index 085d7a39899c..dd269d877562 100755
--- a/tools/testing/selftests/gpio/gpio-mockup-sysfs.sh
+++ b/tools/testing/selftests/gpio/gpio-mockup-sysfs.sh
@@ -1,4 +1,5 @@
1 1
2# SPDX-License-Identifier: GPL-2.0
2is_consistent() 3is_consistent()
3{ 4{
4 val= 5 val=
diff --git a/tools/testing/selftests/gpio/gpio-mockup.sh b/tools/testing/selftests/gpio/gpio-mockup.sh
index b183439e058e..183fb932edbd 100755
--- a/tools/testing/selftests/gpio/gpio-mockup.sh
+++ b/tools/testing/selftests/gpio/gpio-mockup.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3#exit status 4#exit status
4#1: run as non-root user 5#1: run as non-root user
diff --git a/tools/testing/selftests/ia64/Makefile b/tools/testing/selftests/ia64/Makefile
index 2b3de2d3e945..4bce1a84b3a1 100644
--- a/tools/testing/selftests/ia64/Makefile
+++ b/tools/testing/selftests/ia64/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_PROGS := aliasing-test 2TEST_PROGS := aliasing-test
2 3
3all: $(TEST_PROGS) 4all: $(TEST_PROGS)
diff --git a/tools/testing/selftests/intel_pstate/Makefile b/tools/testing/selftests/intel_pstate/Makefile
index 849a90ffe8dd..5a3f7d37e912 100644
--- a/tools/testing/selftests/intel_pstate/Makefile
+++ b/tools/testing/selftests/intel_pstate/Makefile
@@ -1,7 +1,10 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE 2CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE
2LDLIBS := $(LDLIBS) -lm 3LDLIBS := $(LDLIBS) -lm
3 4
5ifeq (,$(filter $(ARCH),x86))
4TEST_GEN_FILES := msr aperf 6TEST_GEN_FILES := msr aperf
7endif
5 8
6TEST_PROGS := run.sh 9TEST_PROGS := run.sh
7 10
diff --git a/tools/testing/selftests/intel_pstate/aperf.c b/tools/testing/selftests/intel_pstate/aperf.c
index cd72f3dc83e9..d21edea9c560 100644
--- a/tools/testing/selftests/intel_pstate/aperf.c
+++ b/tools/testing/selftests/intel_pstate/aperf.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <math.h> 2#include <math.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/testing/selftests/intel_pstate/msr.c b/tools/testing/selftests/intel_pstate/msr.c
index abbbfc84d359..88fdd2a4b0a0 100644
--- a/tools/testing/selftests/intel_pstate/msr.c
+++ b/tools/testing/selftests/intel_pstate/msr.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <math.h> 2#include <math.h>
2#include <unistd.h> 3#include <unistd.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/testing/selftests/intel_pstate/run.sh b/tools/testing/selftests/intel_pstate/run.sh
index 7868c106b8b1..c670359becc6 100755
--- a/tools/testing/selftests/intel_pstate/run.sh
+++ b/tools/testing/selftests/intel_pstate/run.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# This test runs on Intel x86 based hardware which support the intel_pstate 4# This test runs on Intel x86 based hardware which support the intel_pstate
4# driver. The test checks the frequency settings from the maximum turbo 5# driver. The test checks the frequency settings from the maximum turbo
@@ -29,13 +30,12 @@
29 30
30EVALUATE_ONLY=0 31EVALUATE_ONLY=0
31 32
32max_cpus=$(($(nproc)-1)) 33if ! uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ | grep -q x86; then
34 echo "$0 # Skipped: Test can only run on x86 architectures."
35 exit 0
36fi
33 37
34# compile programs 38max_cpus=$(($(nproc)-1))
35gcc aperf.c -Wall -D_GNU_SOURCE -o aperf -lm
36[ $? -ne 0 ] && echo "Problem compiling aperf.c." && exit 1
37gcc -o msr msr.c -lm
38[ $? -ne 0 ] && echo "Problem compiling msr.c." && exit 1
39 39
40function run_test () { 40function run_test () {
41 41
diff --git a/tools/testing/selftests/ipc/Makefile b/tools/testing/selftests/ipc/Makefile
index 30ef4c7f53ea..1c4448a843a4 100644
--- a/tools/testing/selftests/ipc/Makefile
+++ b/tools/testing/selftests/ipc/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1uname_M := $(shell uname -m 2>/dev/null || echo not) 2uname_M := $(shell uname -m 2>/dev/null || echo not)
2ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) 3ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
3ifeq ($(ARCH),i386) 4ifeq ($(ARCH),i386)
diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
index 1b2ce334bb3f..ee9382bdfadc 100644
--- a/tools/testing/selftests/ipc/msgque.c
+++ b/tools/testing/selftests/ipc/msgque.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdlib.h> 2#include <stdlib.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/testing/selftests/kcmp/kcmp_test.c b/tools/testing/selftests/kcmp/kcmp_test.c
index 73684c4a1ed6..6ea7b9f37a41 100644
--- a/tools/testing/selftests/kcmp/kcmp_test.c
+++ b/tools/testing/selftests/kcmp/kcmp_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2 3
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 693616651da5..5bef05d6ba39 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -6,7 +6,14 @@ ifeq (0,$(MAKELEVEL))
6OUTPUT := $(shell pwd) 6OUTPUT := $(shell pwd)
7endif 7endif
8 8
9# The following are built by lib.mk common compile rules.
10# TEST_CUSTOM_PROGS should be used by tests that require
11# custom build rule and prevent common build rule use.
12# TEST_PROGS are for test shell scripts.
13# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
14# and install targets. Common clean doesn't touch them.
9TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) 15TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
16TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
10TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 17TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
11 18
12all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 19all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
@@ -20,17 +27,32 @@ define RUN_TESTS
20 test_num=`echo $$test_num+1 | bc`; \ 27 test_num=`echo $$test_num+1 | bc`; \
21 echo "selftests: $$BASENAME_TEST"; \ 28 echo "selftests: $$BASENAME_TEST"; \
22 echo "========================================"; \ 29 echo "========================================"; \
23 if [ ! -x $$BASENAME_TEST ]; then \ 30 if [ ! -x $$TEST ]; then \
24 echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\ 31 echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
25 echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \ 32 echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
26 else \ 33 else \
27 cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\ 34 if [ "X$(summary)" != "X" ]; then \
35 cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\
36 else \
37 cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\
38 fi; \
28 fi; \ 39 fi; \
29 done; 40 done;
30endef 41endef
31 42
32run_tests: all 43run_tests: all
33 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_PROGS)) 44ifneq ($(KBUILD_SRC),)
45 @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
46 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
47 fi
48 @if [ "X$(TEST_PROGS)" != "X" ]; then
49 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
50 else
51 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
52 fi
53else
54 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
55endif
34 56
35define INSTALL_RULE 57define INSTALL_RULE
36 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ 58 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
@@ -38,10 +60,10 @@ define INSTALL_RULE
38 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \ 60 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
39 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \ 61 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
40 fi 62 fi
41 @if [ "X$(TEST_GEN_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \ 63 @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
42 mkdir -p ${INSTALL_PATH}; \ 64 mkdir -p ${INSTALL_PATH}; \
43 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \ 65 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
44 rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \ 66 rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
45 fi 67 fi
46endef 68endef
47 69
@@ -53,15 +75,20 @@ else
53endif 75endif
54 76
55define EMIT_TESTS 77define EMIT_TESTS
56 @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \ 78 @for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
57 BASENAME_TEST=`basename $$TEST`; \ 79 BASENAME_TEST=`basename $$TEST`; \
58 echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \ 80 echo "(./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
59 done; 81 done;
60endef 82endef
61 83
62emit_tests: 84emit_tests:
63 $(EMIT_TESTS) 85 $(EMIT_TESTS)
64 86
87# define if isn't already. It is undefined in make O= case.
88ifeq ($(RM),)
89RM := rm -f
90endif
91
65define CLEAN 92define CLEAN
66 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) 93 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
67endef 94endef
@@ -69,6 +96,15 @@ endef
69clean: 96clean:
70 $(CLEAN) 97 $(CLEAN)
71 98
99# When make O= with kselftest target from main level
100# the following aren't defined.
101#
102ifneq ($(KBUILD_SRC),)
103LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
104COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
105LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
106endif
107
72$(OUTPUT)/%:%.c 108$(OUTPUT)/%:%.c
73 $(LINK.c) $^ $(LDLIBS) -o $@ 109 $(LINK.c) $^ $(LDLIBS) -o $@
74 110
diff --git a/tools/testing/selftests/lib/bitmap.sh b/tools/testing/selftests/lib/bitmap.sh
index b073c22a3435..4dee4d2a8bbe 100755
--- a/tools/testing/selftests/lib/bitmap.sh
+++ b/tools/testing/selftests/lib/bitmap.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs bitmap infrastructure tests using test_bitmap kernel module 3# Runs bitmap infrastructure tests using test_bitmap kernel module
3if ! /sbin/modprobe -q -n test_bitmap; then 4if ! /sbin/modprobe -q -n test_bitmap; then
4 echo "bitmap: [SKIP]" 5 echo "bitmap: [SKIP]"
diff --git a/tools/testing/selftests/lib/prime_numbers.sh b/tools/testing/selftests/lib/prime_numbers.sh
index da4cbcd766f5..b363994e5e11 100755
--- a/tools/testing/selftests/lib/prime_numbers.sh
+++ b/tools/testing/selftests/lib/prime_numbers.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Checks fast/slow prime_number generation for inconsistencies 3# Checks fast/slow prime_number generation for inconsistencies
3 4
4if ! /sbin/modprobe -q -r prime_numbers; then 5if ! /sbin/modprobe -q -r prime_numbers; then
diff --git a/tools/testing/selftests/lib/printf.sh b/tools/testing/selftests/lib/printf.sh
index cbf3b124bd94..0c37377fd7d4 100755
--- a/tools/testing/selftests/lib/printf.sh
+++ b/tools/testing/selftests/lib/printf.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs printf infrastructure using test_printf kernel module 3# Runs printf infrastructure using test_printf kernel module
3if ! /sbin/modprobe -q -n test_printf; then 4if ! /sbin/modprobe -q -n test_printf; then
4 echo "printf: [SKIP]" 5 echo "printf: [SKIP]"
diff --git a/tools/testing/selftests/locking/ww_mutex.sh b/tools/testing/selftests/locking/ww_mutex.sh
index 6905da965f3b..2c3d6b1878c2 100644
--- a/tools/testing/selftests/locking/ww_mutex.sh
+++ b/tools/testing/selftests/locking/ww_mutex.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs API tests for struct ww_mutex (Wait/Wound mutexes) 3# Runs API tests for struct ww_mutex (Wait/Wound mutexes)
3 4
4if /sbin/modprobe -q test-ww_mutex; then 5if /sbin/modprobe -q test-ww_mutex; then
diff --git a/tools/testing/selftests/media_tests/Makefile b/tools/testing/selftests/media_tests/Makefile
index 6b34a0199468..be5bd4ffb895 100644
--- a/tools/testing/selftests/media_tests/Makefile
+++ b/tools/testing/selftests/media_tests/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_PROGS := media_device_test media_device_open video_device_test 2TEST_PROGS := media_device_test media_device_open video_device_test
2all: $(TEST_PROGS) 3all: $(TEST_PROGS)
3 4
diff --git a/tools/testing/selftests/media_tests/bind_unbind_sample.sh b/tools/testing/selftests/media_tests/bind_unbind_sample.sh
index 9f362f10631a..0101c1ec4ff7 100755
--- a/tools/testing/selftests/media_tests/bind_unbind_sample.sh
+++ b/tools/testing/selftests/media_tests/bind_unbind_sample.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2# Find device number in /sys/bus/usb/drivers/drivername 3# Find device number in /sys/bus/usb/drivers/drivername
3# Edit this file to update the driver numer and name 4# Edit this file to update the driver numer and name
4# Example test for uvcvideo driver 5# Example test for uvcvideo driver
diff --git a/tools/testing/selftests/media_tests/open_loop_test.sh b/tools/testing/selftests/media_tests/open_loop_test.sh
index dcd3c17efc17..d4c0179bbe2c 100755
--- a/tools/testing/selftests/media_tests/open_loop_test.sh
+++ b/tools/testing/selftests/media_tests/open_loop_test.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 i=0 3 i=0
3file=/dev/media$1 4file=/dev/media$1
4 while :; do 5 while :; do
diff --git a/tools/testing/selftests/membarrier/membarrier_test.c b/tools/testing/selftests/membarrier/membarrier_test.c
index 21399fcf1a59..9e674d9514d1 100644
--- a/tools/testing/selftests/membarrier/membarrier_test.c
+++ b/tools/testing/selftests/membarrier/membarrier_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <linux/membarrier.h> 3#include <linux/membarrier.h>
3#include <syscall.h> 4#include <syscall.h>
diff --git a/tools/testing/selftests/memfd/Makefile b/tools/testing/selftests/memfd/Makefile
index bc9d02d615da..3926a0409dda 100644
--- a/tools/testing/selftests/memfd/Makefile
+++ b/tools/testing/selftests/memfd/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS += -D_FILE_OFFSET_BITS=64 2CFLAGS += -D_FILE_OFFSET_BITS=64
2CFLAGS += -I../../../../include/uapi/ 3CFLAGS += -I../../../../include/uapi/
3CFLAGS += -I../../../../include/ 4CFLAGS += -I../../../../include/
diff --git a/tools/testing/selftests/memfd/fuse_mnt.c b/tools/testing/selftests/memfd/fuse_mnt.c
index feacf1280fcd..6936f2a001f3 100644
--- a/tools/testing/selftests/memfd/fuse_mnt.c
+++ b/tools/testing/selftests/memfd/fuse_mnt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * memfd test file-system 3 * memfd test file-system
3 * This file uses FUSE to create a dummy file-system with only one file /memfd. 4 * This file uses FUSE to create a dummy file-system with only one file /memfd.
diff --git a/tools/testing/selftests/memfd/fuse_test.c b/tools/testing/selftests/memfd/fuse_test.c
index 7f3617274bf5..1ccb7a3eb14b 100644
--- a/tools/testing/selftests/memfd/fuse_test.c
+++ b/tools/testing/selftests/memfd/fuse_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * memfd GUP test-case 3 * memfd GUP test-case
3 * This tests memfd interactions with get_user_pages(). We require the 4 * This tests memfd interactions with get_user_pages(). We require the
diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
index f94c6d1fb46f..132a54f74e88 100644
--- a/tools/testing/selftests/memfd/memfd_test.c
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#define __EXPORTED_HEADERS__ 3#define __EXPORTED_HEADERS__
3 4
@@ -514,7 +515,7 @@ static void mfd_assert_grow_write(int fd)
514 515
515 buf = malloc(mfd_def_size * 8); 516 buf = malloc(mfd_def_size * 8);
516 if (!buf) { 517 if (!buf) {
517 printf("malloc(%d) failed: %m\n", mfd_def_size * 8); 518 printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
518 abort(); 519 abort();
519 } 520 }
520 521
@@ -534,7 +535,7 @@ static void mfd_fail_grow_write(int fd)
534 535
535 buf = malloc(mfd_def_size * 8); 536 buf = malloc(mfd_def_size * 8);
536 if (!buf) { 537 if (!buf) {
537 printf("malloc(%d) failed: %m\n", mfd_def_size * 8); 538 printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
538 abort(); 539 abort();
539 } 540 }
540 541
diff --git a/tools/testing/selftests/memfd/run_fuse_test.sh b/tools/testing/selftests/memfd/run_fuse_test.sh
index 69b930e1e041..407df68dfe27 100755
--- a/tools/testing/selftests/memfd/run_fuse_test.sh
+++ b/tools/testing/selftests/memfd/run_fuse_test.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3if test -d "./mnt" ; then 4if test -d "./mnt" ; then
4 fusermount -u ./mnt 5 fusermount -u ./mnt
diff --git a/tools/testing/selftests/memfd/run_tests.sh b/tools/testing/selftests/memfd/run_tests.sh
index daabb350697c..daabb350697c 100644..100755
--- a/tools/testing/selftests/memfd/run_tests.sh
+++ b/tools/testing/selftests/memfd/run_tests.sh
diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile
index afb2624c7048..86636d207adf 100644
--- a/tools/testing/selftests/memory-hotplug/Makefile
+++ b/tools/testing/selftests/memory-hotplug/Makefile
@@ -1,12 +1,13 @@
1# SPDX-License-Identifier: GPL-2.0
1all: 2all:
2 3
3include ../lib.mk 4include ../lib.mk
4 5
5TEST_PROGS := mem-on-off-test.sh 6TEST_PROGS := mem-on-off-test.sh
6override RUN_TESTS := ./mem-on-off-test.sh -r 2 || echo "selftests: memory-hotplug [FAIL]" 7override RUN_TESTS := ./mem-on-off-test.sh -r 2 && echo "selftests: memory-hotplug [PASS]" || echo "selftests: memory-hotplug [FAIL]"
7override EMIT_TESTS := echo "$(RUN_TESTS)" 8override EMIT_TESTS := echo "$(RUN_TESTS)"
8 9
9run_full_test: 10run_full_test:
10 @/bin/bash ./mem-on-off-test.sh || echo "memory-hotplug selftests: [FAIL]" 11 @/bin/bash ./mem-on-off-test.sh && echo "memory-hotplug selftests: [PASS]" || echo "memory-hotplug selftests: [FAIL]"
11 12
12clean: 13clean:
diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 35025ce9ca66..ae2c790d0880 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2 3
3SYSFS= 4SYSFS=
4 5
diff --git a/tools/testing/selftests/mount/Makefile b/tools/testing/selftests/mount/Makefile
index 9093d7ffe87f..e094f71c6dbc 100644
--- a/tools/testing/selftests/mount/Makefile
+++ b/tools/testing/selftests/mount/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for mount selftests. 2# Makefile for mount selftests.
2CFLAGS = -Wall \ 3CFLAGS = -Wall \
3 -O2 4 -O2
diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
index 517785052f1c..584dc6bc3b06 100644
--- a/tools/testing/selftests/mount/unprivileged-remount-test.c
+++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <sched.h> 3#include <sched.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/testing/selftests/mqueue/Makefile b/tools/testing/selftests/mqueue/Makefile
index 79a664aeb8d7..743d3f9e5918 100644
--- a/tools/testing/selftests/mqueue/Makefile
+++ b/tools/testing/selftests/mqueue/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS += -O2 2CFLAGS += -O2
2LDLIBS = -lrt -lpthread -lpopt 3LDLIBS = -lrt -lpthread -lpopt
3TEST_GEN_PROGS := mq_open_tests mq_perf_tests 4TEST_GEN_PROGS := mq_open_tests mq_perf_tests
@@ -5,8 +6,8 @@ TEST_GEN_PROGS := mq_open_tests mq_perf_tests
5include ../lib.mk 6include ../lib.mk
6 7
7override define RUN_TESTS 8override define RUN_TESTS
8 @./mq_open_tests /test1 || echo "selftests: mq_open_tests [FAIL]" 9 @$(OUTPUT)/mq_open_tests /test1 || echo "selftests: mq_open_tests [FAIL]"
9 @./mq_perf_tests || echo "selftests: mq_perf_tests [FAIL]" 10 @$(OUTPUT)/mq_perf_tests || echo "selftests: mq_perf_tests [FAIL]"
10endef 11endef
11 12
12override define EMIT_TESTS 13override define EMIT_TESTS
diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore
index 9801253e4802..c612d6e38c62 100644
--- a/tools/testing/selftests/net/.gitignore
+++ b/tools/testing/selftests/net/.gitignore
@@ -6,3 +6,4 @@ reuseport_bpf
6reuseport_bpf_cpu 6reuseport_bpf_cpu
7reuseport_bpf_numa 7reuseport_bpf_numa
8reuseport_dualstack 8reuseport_dualstack
9reuseaddr_conflict
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index de1f5772b878..500c74db746c 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for net selftests 2# Makefile for net selftests
2 3
3CFLAGS = -Wall -Wl,--no-as-needed -O2 -g 4CFLAGS = -Wall -Wl,--no-as-needed -O2 -g
@@ -5,9 +6,9 @@ CFLAGS += -I../../../../usr/include/
5 6
6TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh 7TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh
7TEST_GEN_FILES = socket 8TEST_GEN_FILES = socket
8TEST_GEN_FILES += psock_fanout psock_tpacket 9TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy
9TEST_GEN_FILES += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa 10TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
10TEST_GEN_FILES += reuseport_dualstack msg_zerocopy 11TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict
11 12
12include ../lib.mk 13include ../lib.mk
13 14
diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/selftests/net/msg_zerocopy.c
index 40232af5b023..3ab6ec403905 100644
--- a/tools/testing/selftests/net/msg_zerocopy.c
+++ b/tools/testing/selftests/net/msg_zerocopy.c
@@ -55,7 +55,7 @@
55#include <unistd.h> 55#include <unistd.h>
56 56
57#ifndef SO_EE_ORIGIN_ZEROCOPY 57#ifndef SO_EE_ORIGIN_ZEROCOPY
58#define SO_EE_ORIGIN_ZEROCOPY SO_EE_ORIGIN_UPAGE 58#define SO_EE_ORIGIN_ZEROCOPY 5
59#endif 59#endif
60 60
61#ifndef SO_ZEROCOPY 61#ifndef SO_ZEROCOPY
diff --git a/tools/testing/selftests/net/netdevice.sh b/tools/testing/selftests/net/netdevice.sh
index 4e00568d70c2..903679e0ff31 100755
--- a/tools/testing/selftests/net/netdevice.sh
+++ b/tools/testing/selftests/net/netdevice.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# This test is for checking network interface 4# This test is for checking network interface
4# For the moment it tests only ethernet interface (but wifi could be easily added) 5# For the moment it tests only ethernet interface (but wifi could be easily added)
@@ -178,7 +179,7 @@ if [ "$(id -u)" -ne 0 ];then
178 exit 0 179 exit 0
179fi 180fi
180 181
181ip -Version 2>/dev/null >/dev/null 182ip link show 2>/dev/null >/dev/null
182if [ $? -ne 0 ];then 183if [ $? -ne 0 ];then
183 echo "SKIP: Could not run test without the ip tool" 184 echo "SKIP: Could not run test without the ip tool"
184 exit 0 185 exit 0
diff --git a/tools/testing/selftests/net/reuseaddr_conflict.c b/tools/testing/selftests/net/reuseaddr_conflict.c
new file mode 100644
index 000000000000..7c5b12664b03
--- /dev/null
+++ b/tools/testing/selftests/net/reuseaddr_conflict.c
@@ -0,0 +1,114 @@
1/*
2 * Test for the regression introduced by
3 *
4 * b9470c27607b ("inet: kill smallest_size and smallest_port")
5 *
6 * If we open an ipv4 socket on a port with reuseaddr we shouldn't reset the tb
7 * when we open the ipv6 conterpart, which is what was happening previously.
8 */
9#include <errno.h>
10#include <error.h>
11#include <arpa/inet.h>
12#include <netinet/in.h>
13#include <stdbool.h>
14#include <stdio.h>
15#include <sys/socket.h>
16#include <sys/types.h>
17#include <unistd.h>
18
19#define PORT 9999
20
21int open_port(int ipv6, int any)
22{
23 int fd = -1;
24 int reuseaddr = 1;
25 int v6only = 1;
26 int addrlen;
27 int ret = -1;
28 struct sockaddr *addr;
29 int family = ipv6 ? AF_INET6 : AF_INET;
30
31 struct sockaddr_in6 addr6 = {
32 .sin6_family = AF_INET6,
33 .sin6_port = htons(PORT),
34 .sin6_addr = in6addr_any
35 };
36 struct sockaddr_in addr4 = {
37 .sin_family = AF_INET,
38 .sin_port = htons(PORT),
39 .sin_addr.s_addr = any ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"),
40 };
41
42
43 if (ipv6) {
44 addr = (struct sockaddr*)&addr6;
45 addrlen = sizeof(addr6);
46 } else {
47 addr = (struct sockaddr*)&addr4;
48 addrlen = sizeof(addr4);
49 }
50
51 if ((fd = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
52 perror("socket");
53 goto out;
54 }
55
56 if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only,
57 sizeof(v6only)) < 0) {
58 perror("setsockopt IPV6_V6ONLY");
59 goto out;
60 }
61
62 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
63 sizeof(reuseaddr)) < 0) {
64 perror("setsockopt SO_REUSEADDR");
65 goto out;
66 }
67
68 if (bind(fd, addr, addrlen) < 0) {
69 perror("bind");
70 goto out;
71 }
72
73 if (any)
74 return fd;
75
76 if (listen(fd, 1) < 0) {
77 perror("listen");
78 goto out;
79 }
80 return fd;
81out:
82 close(fd);
83 return ret;
84}
85
86int main(void)
87{
88 int listenfd;
89 int fd1, fd2;
90
91 fprintf(stderr, "Opening 127.0.0.1:%d\n", PORT);
92 listenfd = open_port(0, 0);
93 if (listenfd < 0)
94 error(1, errno, "Couldn't open listen socket");
95 fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
96 fd1 = open_port(0, 1);
97 if (fd1 >= 0)
98 error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
99 fprintf(stderr, "Opening in6addr_any:%d\n", PORT);
100 fd1 = open_port(1, 1);
101 if (fd1 < 0)
102 error(1, errno, "Couldn't open ipv6 reuseport");
103 fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
104 fd2 = open_port(0, 1);
105 if (fd2 >= 0)
106 error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
107 close(fd1);
108 fprintf(stderr, "Opening INADDR_ANY:%d after closing ipv6 socket\n", PORT);
109 fd1 = open_port(0, 1);
110 if (fd1 >= 0)
111 error(1, 0, "Was allowed to create an ipv4 reuseport on an already bound non-reuseport socket with no ipv6");
112 fprintf(stderr, "Success");
113 return 0;
114}
diff --git a/tools/testing/selftests/net/reuseport_bpf_cpu.c b/tools/testing/selftests/net/reuseport_bpf_cpu.c
index b23d6f54de7b..2d646174729f 100644
--- a/tools/testing/selftests/net/reuseport_bpf_cpu.c
+++ b/tools/testing/selftests/net/reuseport_bpf_cpu.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Test functionality of BPF filters with SO_REUSEPORT. This program creates 3 * Test functionality of BPF filters with SO_REUSEPORT. This program creates
3 * an SO_REUSEPORT receiver group containing one socket per CPU core. It then 4 * an SO_REUSEPORT receiver group containing one socket per CPU core. It then
diff --git a/tools/testing/selftests/net/reuseport_bpf_numa.c b/tools/testing/selftests/net/reuseport_bpf_numa.c
index 6f20bc9ff627..365c32e84189 100644
--- a/tools/testing/selftests/net/reuseport_bpf_numa.c
+++ b/tools/testing/selftests/net/reuseport_bpf_numa.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Test functionality of BPF filters with SO_REUSEPORT. Same test as 3 * Test functionality of BPF filters with SO_REUSEPORT. Same test as
3 * in reuseport_bpf_cpu, only as one socket per NUMA node. 4 * in reuseport_bpf_cpu, only as one socket per NUMA node.
diff --git a/tools/testing/selftests/net/reuseport_dualstack.c b/tools/testing/selftests/net/reuseport_dualstack.c
index 90958aaaafb9..fe3230c55986 100644
--- a/tools/testing/selftests/net/reuseport_dualstack.c
+++ b/tools/testing/selftests/net/reuseport_dualstack.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * It is possible to use SO_REUSEPORT to open multiple sockets bound to 3 * It is possible to use SO_REUSEPORT to open multiple sockets bound to
3 * equivalent local addresses using AF_INET and AF_INET6 at the same time. If 4 * equivalent local addresses using AF_INET and AF_INET6 at the same time. If
diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh
index 57b5ff576240..5215493166c9 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -15,6 +15,14 @@ check_err()
15 fi 15 fi
16} 16}
17 17
18# same but inverted -- used when command must fail for test to pass
19check_fail()
20{
21 if [ $1 -eq 0 ]; then
22 ret=1
23 fi
24}
25
18kci_add_dummy() 26kci_add_dummy()
19{ 27{
20 ip link add name "$devdummy" type dummy 28 ip link add name "$devdummy" type dummy
@@ -29,6 +37,26 @@ kci_del_dummy()
29 check_err $? 37 check_err $?
30} 38}
31 39
40kci_test_netconf()
41{
42 dev="$1"
43 r=$ret
44
45 ip netconf show dev "$dev" > /dev/null
46 check_err $?
47
48 for f in 4 6; do
49 ip -$f netconf show dev "$dev" > /dev/null
50 check_err $?
51 done
52
53 if [ $ret -ne 0 ] ;then
54 echo "FAIL: ip netconf show $dev"
55 test $r -eq 0 && ret=0
56 return 1
57 fi
58}
59
32# add a bridge with vlans on top 60# add a bridge with vlans on top
33kci_test_bridge() 61kci_test_bridge()
34{ 62{
@@ -55,6 +83,11 @@ kci_test_bridge()
55 check_err $? 83 check_err $?
56 ip r s t all > /dev/null 84 ip r s t all > /dev/null
57 check_err $? 85 check_err $?
86
87 for name in "$devbr" "$vlandev" "$devdummy" ; do
88 kci_test_netconf "$name"
89 done
90
58 ip -6 addr del dev "$vlandev" dead:42::1234/64 91 ip -6 addr del dev "$vlandev" dead:42::1234/64
59 check_err $? 92 check_err $?
60 93
@@ -92,6 +125,9 @@ kci_test_gre()
92 check_err $? 125 check_err $?
93 ip addr > /dev/null 126 ip addr > /dev/null
94 check_err $? 127 check_err $?
128
129 kci_test_netconf "$gredev"
130
95 ip addr del dev "$devdummy" 10.23.7.11/24 131 ip addr del dev "$devdummy" 10.23.7.11/24
96 check_err $? 132 check_err $?
97 133
@@ -235,6 +271,237 @@ kci_test_addrlabel()
235 echo "PASS: ipv6 addrlabel" 271 echo "PASS: ipv6 addrlabel"
236} 272}
237 273
274kci_test_ifalias()
275{
276 ret=0
277 namewant=$(uuidgen)
278 syspathname="/sys/class/net/$devdummy/ifalias"
279
280 ip link set dev "$devdummy" alias "$namewant"
281 check_err $?
282
283 if [ $ret -ne 0 ]; then
284 echo "FAIL: cannot set interface alias of $devdummy to $namewant"
285 return 1
286 fi
287
288 ip link show "$devdummy" | grep -q "alias $namewant"
289 check_err $?
290
291 if [ -r "$syspathname" ] ; then
292 read namehave < "$syspathname"
293 if [ "$namewant" != "$namehave" ]; then
294 echo "FAIL: did set ifalias $namewant but got $namehave"
295 return 1
296 fi
297
298 namewant=$(uuidgen)
299 echo "$namewant" > "$syspathname"
300 ip link show "$devdummy" | grep -q "alias $namewant"
301 check_err $?
302
303 # sysfs interface allows to delete alias again
304 echo "" > "$syspathname"
305
306 ip link show "$devdummy" | grep -q "alias $namewant"
307 check_fail $?
308
309 for i in $(seq 1 100); do
310 uuidgen > "$syspathname" &
311 done
312
313 wait
314
315 # re-add the alias -- kernel should free mem when dummy dev is removed
316 ip link set dev "$devdummy" alias "$namewant"
317 check_err $?
318 fi
319
320 if [ $ret -ne 0 ]; then
321 echo "FAIL: set interface alias $devdummy to $namewant"
322 return 1
323 fi
324
325 echo "PASS: set ifalias $namewant for $devdummy"
326}
327
328kci_test_vrf()
329{
330 vrfname="test-vrf"
331 ret=0
332
333 ip link show type vrf 2>/dev/null
334 if [ $? -ne 0 ]; then
335 echo "SKIP: vrf: iproute2 too old"
336 return 0
337 fi
338
339 ip link add "$vrfname" type vrf table 10
340 check_err $?
341 if [ $ret -ne 0 ];then
342 echo "FAIL: can't add vrf interface, skipping test"
343 return 0
344 fi
345
346 ip -br link show type vrf | grep -q "$vrfname"
347 check_err $?
348 if [ $ret -ne 0 ];then
349 echo "FAIL: created vrf device not found"
350 return 1
351 fi
352
353 ip link set dev "$vrfname" up
354 check_err $?
355
356 ip link set dev "$devdummy" master "$vrfname"
357 check_err $?
358 ip link del dev "$vrfname"
359 check_err $?
360
361 if [ $ret -ne 0 ];then
362 echo "FAIL: vrf"
363 return 1
364 fi
365
366 echo "PASS: vrf"
367}
368
369kci_test_encap_vxlan()
370{
371 ret=0
372 vxlan="test-vxlan0"
373 vlan="test-vlan0"
374 testns="$1"
375
376 ip netns exec "$testns" ip link add "$vxlan" type vxlan id 42 group 239.1.1.1 \
377 dev "$devdummy" dstport 4789 2>/dev/null
378 if [ $? -ne 0 ]; then
379 echo "FAIL: can't add vxlan interface, skipping test"
380 return 0
381 fi
382 check_err $?
383
384 ip netns exec "$testns" ip addr add 10.2.11.49/24 dev "$vxlan"
385 check_err $?
386
387 ip netns exec "$testns" ip link set up dev "$vxlan"
388 check_err $?
389
390 ip netns exec "$testns" ip link add link "$vxlan" name "$vlan" type vlan id 1
391 check_err $?
392
393 ip netns exec "$testns" ip link del "$vxlan"
394 check_err $?
395
396 if [ $ret -ne 0 ]; then
397 echo "FAIL: vxlan"
398 return 1
399 fi
400 echo "PASS: vxlan"
401}
402
403kci_test_encap_fou()
404{
405 ret=0
406 name="test-fou"
407 testns="$1"
408
409 ip fou help 2>&1 |grep -q 'Usage: ip fou'
410 if [ $? -ne 0 ];then
411 echo "SKIP: fou: iproute2 too old"
412 return 1
413 fi
414
415 ip netns exec "$testns" ip fou add port 7777 ipproto 47 2>/dev/null
416 if [ $? -ne 0 ];then
417 echo "FAIL: can't add fou port 7777, skipping test"
418 return 1
419 fi
420
421 ip netns exec "$testns" ip fou add port 8888 ipproto 4
422 check_err $?
423
424 ip netns exec "$testns" ip fou del port 9999 2>/dev/null
425 check_fail $?
426
427 ip netns exec "$testns" ip fou del port 7777
428 check_err $?
429
430 if [ $ret -ne 0 ]; then
431 echo "FAIL: fou"
432 return 1
433 fi
434
435 echo "PASS: fou"
436}
437
438# test various encap methods, use netns to avoid unwanted interference
439kci_test_encap()
440{
441 testns="testns"
442 ret=0
443
444 ip netns add "$testns"
445 if [ $? -ne 0 ]; then
446 echo "SKIP encap tests: cannot add net namespace $testns"
447 return 1
448 fi
449
450 ip netns exec "$testns" ip link set lo up
451 check_err $?
452
453 ip netns exec "$testns" ip link add name "$devdummy" type dummy
454 check_err $?
455 ip netns exec "$testns" ip link set "$devdummy" up
456 check_err $?
457
458 kci_test_encap_vxlan "$testns"
459 kci_test_encap_fou "$testns"
460
461 ip netns del "$testns"
462}
463
464kci_test_macsec()
465{
466 msname="test_macsec0"
467 ret=0
468
469 ip macsec help 2>&1 | grep -q "^Usage: ip macsec"
470 if [ $? -ne 0 ]; then
471 echo "SKIP: macsec: iproute2 too old"
472 return 0
473 fi
474
475 ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on
476 check_err $?
477 if [ $ret -ne 0 ];then
478 echo "FAIL: can't add macsec interface, skipping test"
479 return 1
480 fi
481
482 ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
483 check_err $?
484
485 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
486 check_err $?
487
488 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on key 00 0123456789abcdef0123456789abcdef
489 check_err $?
490
491 ip macsec show > /dev/null
492 check_err $?
493
494 ip link del dev "$msname"
495 check_err $?
496
497 if [ $ret -ne 0 ];then
498 echo "FAIL: macsec"
499 return 1
500 fi
501
502 echo "PASS: macsec"
503}
504
238kci_test_rtnl() 505kci_test_rtnl()
239{ 506{
240 kci_add_dummy 507 kci_add_dummy
@@ -249,6 +516,10 @@ kci_test_rtnl()
249 kci_test_gre 516 kci_test_gre
250 kci_test_bridge 517 kci_test_bridge
251 kci_test_addrlabel 518 kci_test_addrlabel
519 kci_test_ifalias
520 kci_test_vrf
521 kci_test_encap
522 kci_test_macsec
252 523
253 kci_del_dummy 524 kci_del_dummy
254} 525}
diff --git a/tools/testing/selftests/net/run_afpackettests b/tools/testing/selftests/net/run_afpackettests
index 5246e782d6e8..21fe149e3de1 100755
--- a/tools/testing/selftests/net/run_afpackettests
+++ b/tools/testing/selftests/net/run_afpackettests
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3if [ $(id -u) != 0 ]; then 4if [ $(id -u) != 0 ]; then
4 echo $msg must be run as root >&2 5 echo $msg must be run as root >&2
diff --git a/tools/testing/selftests/net/run_netsocktests b/tools/testing/selftests/net/run_netsocktests
index 16058bbea7a8..b093f39c298c 100755
--- a/tools/testing/selftests/net/run_netsocktests
+++ b/tools/testing/selftests/net/run_netsocktests
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3echo "--------------------" 4echo "--------------------"
4echo "running socket test" 5echo "running socket test"
diff --git a/tools/testing/selftests/net/socket.c b/tools/testing/selftests/net/socket.c
index 0f227f2f9be9..afca1ead677f 100644
--- a/tools/testing/selftests/net/socket.c
+++ b/tools/testing/selftests/net/socket.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <errno.h> 3#include <errno.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/testing/selftests/net/test_bpf.sh b/tools/testing/selftests/net/test_bpf.sh
index 8b29796d46aa..65677909c574 100755
--- a/tools/testing/selftests/net/test_bpf.sh
+++ b/tools/testing/selftests/net/test_bpf.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs bpf test using test_bpf kernel module 3# Runs bpf test using test_bpf kernel module
3 4
4if /sbin/modprobe -q test_bpf ; then 5if /sbin/modprobe -q test_bpf ; then
diff --git a/tools/testing/selftests/networking/timestamping/Makefile b/tools/testing/selftests/networking/timestamping/Makefile
index 92fb8ee917c5..a728040edbe1 100644
--- a/tools/testing/selftests/networking/timestamping/Makefile
+++ b/tools/testing/selftests/networking/timestamping/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS += -I../../../../../usr/include 2CFLAGS += -I../../../../../usr/include
2 3
3TEST_PROGS := hwtstamp_config rxtimestamp timestamping txtimestamp 4TEST_PROGS := hwtstamp_config rxtimestamp timestamping txtimestamp
diff --git a/tools/testing/selftests/networking/timestamping/hwtstamp_config.c b/tools/testing/selftests/networking/timestamping/hwtstamp_config.c
index e8b685a7f15f..e1fdee841021 100644
--- a/tools/testing/selftests/networking/timestamping/hwtstamp_config.c
+++ b/tools/testing/selftests/networking/timestamping/hwtstamp_config.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Test program for SIOC{G,S}HWTSTAMP 2/* Test program for SIOC{G,S}HWTSTAMP
2 * Copyright 2013 Solarflare Communications 3 * Copyright 2013 Solarflare Communications
3 * Author: Ben Hutchings 4 * Author: Ben Hutchings
diff --git a/tools/testing/selftests/networking/timestamping/rxtimestamp.c b/tools/testing/selftests/networking/timestamping/rxtimestamp.c
index 00f286661dcd..dd4162fc0419 100644
--- a/tools/testing/selftests/networking/timestamping/rxtimestamp.c
+++ b/tools/testing/selftests/networking/timestamping/rxtimestamp.c
@@ -341,7 +341,7 @@ int main(int argc, char **argv)
341 return 0; 341 return 0;
342 case 'n': 342 case 'n':
343 t = atoi(optarg); 343 t = atoi(optarg);
344 if (t > ARRAY_SIZE(test_cases)) 344 if (t >= ARRAY_SIZE(test_cases))
345 error(1, 0, "Invalid test case: %d", t); 345 error(1, 0, "Invalid test case: %d", t);
346 all_tests = false; 346 all_tests = false;
347 test_cases[t].enabled = true; 347 test_cases[t].enabled = true;
diff --git a/tools/testing/selftests/nsfs/owner.c b/tools/testing/selftests/nsfs/owner.c
index 437205f8b714..96a976c74550 100644
--- a/tools/testing/selftests/nsfs/owner.c
+++ b/tools/testing/selftests/nsfs/owner.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <sched.h> 3#include <sched.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/testing/selftests/nsfs/pidns.c b/tools/testing/selftests/nsfs/pidns.c
index ae3a0d68e966..1182d4e437a2 100644
--- a/tools/testing/selftests/nsfs/pidns.c
+++ b/tools/testing/selftests/nsfs/pidns.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <sched.h> 3#include <sched.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
index 72c3ac2323e1..f6b1338730db 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for powerpc selftests 2# Makefile for powerpc selftests
2 3
3# ARCH can be overridden by the user for cross compiling 4# ARCH can be overridden by the user for cross compiling
diff --git a/tools/testing/selftests/powerpc/benchmarks/Makefile b/tools/testing/selftests/powerpc/benchmarks/Makefile
index fb96a89bd953..a35058e3766c 100644
--- a/tools/testing/selftests/powerpc/benchmarks/Makefile
+++ b/tools/testing/selftests/powerpc/benchmarks/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_GEN_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall 2TEST_GEN_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall
2 3
3CFLAGS += -O2 4CFLAGS += -O2
diff --git a/tools/testing/selftests/powerpc/benchmarks/context_switch.c b/tools/testing/selftests/powerpc/benchmarks/context_switch.c
index f4241339edd2..87f1f0252299 100644
--- a/tools/testing/selftests/powerpc/benchmarks/context_switch.c
+++ b/tools/testing/selftests/powerpc/benchmarks/context_switch.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#define _GNU_SOURCE 12#define _GNU_SOURCE
13#include <errno.h>
13#include <sched.h> 14#include <sched.h>
14#include <string.h> 15#include <string.h>
15#include <stdio.h> 16#include <stdio.h>
@@ -75,6 +76,7 @@ static void touch(void)
75 76
76static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu) 77static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu)
77{ 78{
79 int rc;
78 pthread_t tid; 80 pthread_t tid;
79 cpu_set_t cpuset; 81 cpu_set_t cpuset;
80 pthread_attr_t attr; 82 pthread_attr_t attr;
@@ -82,14 +84,23 @@ static void start_thread_on(void *(*fn)(void *), void *arg, unsigned long cpu)
82 CPU_ZERO(&cpuset); 84 CPU_ZERO(&cpuset);
83 CPU_SET(cpu, &cpuset); 85 CPU_SET(cpu, &cpuset);
84 86
85 pthread_attr_init(&attr); 87 rc = pthread_attr_init(&attr);
88 if (rc) {
89 errno = rc;
90 perror("pthread_attr_init");
91 exit(1);
92 }
86 93
87 if (pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset)) { 94 rc = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
95 if (rc) {
96 errno = rc;
88 perror("pthread_attr_setaffinity_np"); 97 perror("pthread_attr_setaffinity_np");
89 exit(1); 98 exit(1);
90 } 99 }
91 100
92 if (pthread_create(&tid, &attr, fn, arg)) { 101 rc = pthread_create(&tid, &attr, fn, arg);
102 if (rc) {
103 errno = rc;
93 perror("pthread_create"); 104 perror("pthread_create");
94 exit(1); 105 exit(1);
95 } 106 }
diff --git a/tools/testing/selftests/powerpc/cache_shape/Makefile b/tools/testing/selftests/powerpc/cache_shape/Makefile
index b24485ab30e2..1be547434a49 100644
--- a/tools/testing/selftests/powerpc/cache_shape/Makefile
+++ b/tools/testing/selftests/powerpc/cache_shape/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_PROGS := cache_shape 2TEST_PROGS := cache_shape
2 3
3all: $(TEST_PROGS) 4all: $(TEST_PROGS)
diff --git a/tools/testing/selftests/powerpc/copyloops/Makefile b/tools/testing/selftests/powerpc/copyloops/Makefile
index 681ab19d0a84..ac4a52e19e59 100644
--- a/tools/testing/selftests/powerpc/copyloops/Makefile
+++ b/tools/testing/selftests/powerpc/copyloops/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# The loops are all 64-bit code 2# The loops are all 64-bit code
2CFLAGS += -m64 3CFLAGS += -m64
3CFLAGS += -I$(CURDIR) 4CFLAGS += -I$(CURDIR)
diff --git a/tools/testing/selftests/powerpc/copyloops/asm/export.h b/tools/testing/selftests/powerpc/copyloops/asm/export.h
index 2d14a9b4248c..0bab35f6777a 100644
--- a/tools/testing/selftests/powerpc/copyloops/asm/export.h
+++ b/tools/testing/selftests/powerpc/copyloops/asm/export.h
@@ -1 +1,2 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#define EXPORT_SYMBOL(x) 2#define EXPORT_SYMBOL(x)
diff --git a/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h b/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
index 80d34a9ffff4..5ffe04d802c9 100644
--- a/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
+++ b/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <ppc-asm.h> 2#include <ppc-asm.h>
2 3
3#define CONFIG_ALTIVEC 4#define CONFIG_ALTIVEC
diff --git a/tools/testing/selftests/powerpc/copyloops/validate.c b/tools/testing/selftests/powerpc/copyloops/validate.c
index 7fb436f82d16..0f6873618552 100644
--- a/tools/testing/selftests/powerpc/copyloops/validate.c
+++ b/tools/testing/selftests/powerpc/copyloops/validate.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <malloc.h> 2#include <malloc.h>
2#include <string.h> 3#include <string.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/testing/selftests/powerpc/dscr/Makefile b/tools/testing/selftests/powerpc/dscr/Makefile
index c5639deb8887..55d7db7a616b 100644
--- a/tools/testing/selftests/powerpc/dscr/Makefile
+++ b/tools/testing/selftests/powerpc/dscr/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_GEN_PROGS := dscr_default_test dscr_explicit_test dscr_user_test \ 2TEST_GEN_PROGS := dscr_default_test dscr_explicit_test dscr_user_test \
2 dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test \ 3 dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test \
3 dscr_sysfs_thread_test 4 dscr_sysfs_thread_test
diff --git a/tools/testing/selftests/powerpc/dscr/dscr.h b/tools/testing/selftests/powerpc/dscr/dscr.h
index 18ea223bd398..cdb840bc54f2 100644
--- a/tools/testing/selftests/powerpc/dscr/dscr.h
+++ b/tools/testing/selftests/powerpc/dscr/dscr.h
@@ -39,7 +39,7 @@
39#define rmb() asm volatile("lwsync":::"memory") 39#define rmb() asm volatile("lwsync":::"memory")
40#define wmb() asm volatile("lwsync":::"memory") 40#define wmb() asm volatile("lwsync":::"memory")
41 41
42#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) 42#define READ_ONCE(x) (*(volatile typeof(x) *)&(x))
43 43
44/* Prilvilege state DSCR access */ 44/* Prilvilege state DSCR access */
45inline unsigned long get_dscr(void) 45inline unsigned long get_dscr(void)
diff --git a/tools/testing/selftests/powerpc/dscr/dscr_default_test.c b/tools/testing/selftests/powerpc/dscr/dscr_default_test.c
index df17c3bab0a7..9e1a37e93b63 100644
--- a/tools/testing/selftests/powerpc/dscr/dscr_default_test.c
+++ b/tools/testing/selftests/powerpc/dscr/dscr_default_test.c
@@ -27,7 +27,7 @@ static void *do_test(void *in)
27 unsigned long d, cur_dscr, cur_dscr_usr; 27 unsigned long d, cur_dscr, cur_dscr_usr;
28 unsigned long s1, s2; 28 unsigned long s1, s2;
29 29
30 s1 = ACCESS_ONCE(sequence); 30 s1 = READ_ONCE(sequence);
31 if (s1 & 1) 31 if (s1 & 1)
32 continue; 32 continue;
33 rmb(); 33 rmb();
diff --git a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
index 17fb1b43c320..1899bd85121f 100644
--- a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
+++ b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
@@ -53,6 +53,8 @@ static int check_all_cpu_dscr_defaults(unsigned long val)
53 } 53 }
54 54
55 while ((dp = readdir(sysfs))) { 55 while ((dp = readdir(sysfs))) {
56 int len;
57
56 if (!(dp->d_type & DT_DIR)) 58 if (!(dp->d_type & DT_DIR))
57 continue; 59 continue;
58 if (!strcmp(dp->d_name, "cpuidle")) 60 if (!strcmp(dp->d_name, "cpuidle"))
@@ -60,7 +62,9 @@ static int check_all_cpu_dscr_defaults(unsigned long val)
60 if (!strstr(dp->d_name, "cpu")) 62 if (!strstr(dp->d_name, "cpu"))
61 continue; 63 continue;
62 64
63 sprintf(file, "%s%s/dscr", CPU_PATH, dp->d_name); 65 len = snprintf(file, LEN_MAX, "%s%s/dscr", CPU_PATH, dp->d_name);
66 if (len >= LEN_MAX)
67 continue;
64 if (access(file, F_OK)) 68 if (access(file, F_OK))
65 continue; 69 continue;
66 70
diff --git a/tools/testing/selftests/powerpc/include/basic_asm.h b/tools/testing/selftests/powerpc/include/basic_asm.h
index 12eaddf72e66..886dc026fe7a 100644
--- a/tools/testing/selftests/powerpc/include/basic_asm.h
+++ b/tools/testing/selftests/powerpc/include/basic_asm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _SELFTESTS_POWERPC_BASIC_ASM_H 2#ifndef _SELFTESTS_POWERPC_BASIC_ASM_H
2#define _SELFTESTS_POWERPC_BASIC_ASM_H 3#define _SELFTESTS_POWERPC_BASIC_ASM_H
3 4
diff --git a/tools/testing/selftests/powerpc/include/instructions.h b/tools/testing/selftests/powerpc/include/instructions.h
index 0fb0bd3b28c9..f36061eb6f0f 100644
--- a/tools/testing/selftests/powerpc/include/instructions.h
+++ b/tools/testing/selftests/powerpc/include/instructions.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _SELFTESTS_POWERPC_INSTRUCTIONS_H 2#ifndef _SELFTESTS_POWERPC_INSTRUCTIONS_H
2#define _SELFTESTS_POWERPC_INSTRUCTIONS_H 3#define _SELFTESTS_POWERPC_INSTRUCTIONS_H
3 4
diff --git a/tools/testing/selftests/powerpc/math/Makefile b/tools/testing/selftests/powerpc/math/Makefile
index fa8bae920c91..0dd3a01fdab9 100644
--- a/tools/testing/selftests/powerpc/math/Makefile
+++ b/tools/testing/selftests/powerpc/math/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal vsx_preempt 2TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal vsx_preempt
2 3
3include ../../lib.mk 4include ../../lib.mk
diff --git a/tools/testing/selftests/powerpc/mm/Makefile b/tools/testing/selftests/powerpc/mm/Makefile
index 1cffe54dccfb..bf315bcbe663 100644
--- a/tools/testing/selftests/powerpc/mm/Makefile
+++ b/tools/testing/selftests/powerpc/mm/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1noarg: 2noarg:
2 $(MAKE) -C ../ 3 $(MAKE) -C ../
3 4
diff --git a/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
index 49003674de4f..9932359ce38f 100644
--- a/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
+++ b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <sys/mman.h> 3#include <sys/mman.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/testing/selftests/powerpc/pmu/Makefile b/tools/testing/selftests/powerpc/pmu/Makefile
index e4e55d1d3e0f..6e1629bf5b09 100644
--- a/tools/testing/selftests/powerpc/pmu/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1noarg: 2noarg:
2 $(MAKE) -C ../ 3 $(MAKE) -C ../
3 4
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/Makefile b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
index 6001fb0a377a..c4e64bc2e265 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1noarg: 2noarg:
2 $(MAKE) -C ../../ 3 $(MAKE) -C ../../
3 4
diff --git a/tools/testing/selftests/powerpc/ptrace/Makefile b/tools/testing/selftests/powerpc/ptrace/Makefile
index 8932263e5a74..480305266504 100644
--- a/tools/testing/selftests/powerpc/ptrace/Makefile
+++ b/tools/testing/selftests/powerpc/ptrace/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_PROGS := ptrace-gpr ptrace-tm-gpr ptrace-tm-spd-gpr \ 2TEST_PROGS := ptrace-gpr ptrace-tm-gpr ptrace-tm-spd-gpr \
2 ptrace-tar ptrace-tm-tar ptrace-tm-spd-tar ptrace-vsx ptrace-tm-vsx \ 3 ptrace-tar ptrace-tm-tar ptrace-tm-spd-tar ptrace-vsx ptrace-tm-vsx \
3 ptrace-tm-spd-vsx ptrace-tm-spr 4 ptrace-tm-spd-vsx ptrace-tm-spr
diff --git a/tools/testing/selftests/powerpc/signal/Makefile b/tools/testing/selftests/powerpc/signal/Makefile
index f0eef27458e2..a7cbd5082e27 100644
--- a/tools/testing/selftests/powerpc/signal/Makefile
+++ b/tools/testing/selftests/powerpc/signal/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_PROGS := signal signal_tm 2TEST_PROGS := signal signal_tm
2 3
3all: $(TEST_PROGS) 4all: $(TEST_PROGS)
diff --git a/tools/testing/selftests/powerpc/stringloops/Makefile b/tools/testing/selftests/powerpc/stringloops/Makefile
index 557b9379f3bb..1125e489055e 100644
--- a/tools/testing/selftests/powerpc/stringloops/Makefile
+++ b/tools/testing/selftests/powerpc/stringloops/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# The loops are all 64-bit code 2# The loops are all 64-bit code
2CFLAGS += -m64 3CFLAGS += -m64
3CFLAGS += -I$(CURDIR) 4CFLAGS += -I$(CURDIR)
diff --git a/tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h b/tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h
index 11bece87e880..136242ec4b0e 100644
--- a/tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h
+++ b/tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <ppc-asm.h> 2#include <ppc-asm.h>
2 3
3#ifndef r1 4#ifndef r1
diff --git a/tools/testing/selftests/powerpc/stringloops/memcmp.c b/tools/testing/selftests/powerpc/stringloops/memcmp.c
index 30b1222380ca..8250db25b379 100644
--- a/tools/testing/selftests/powerpc/stringloops/memcmp.c
+++ b/tools/testing/selftests/powerpc/stringloops/memcmp.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <malloc.h> 2#include <malloc.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/testing/selftests/powerpc/switch_endian/Makefile b/tools/testing/selftests/powerpc/switch_endian/Makefile
index b92c2a132c4f..30b8ff8fb82e 100644
--- a/tools/testing/selftests/powerpc/switch_endian/Makefile
+++ b/tools/testing/selftests/powerpc/switch_endian/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_GEN_PROGS := switch_endian_test 2TEST_GEN_PROGS := switch_endian_test
2 3
3ASFLAGS += -O2 -Wall -g -nostdlib -m64 4ASFLAGS += -O2 -Wall -g -nostdlib -m64
diff --git a/tools/testing/selftests/powerpc/switch_endian/check.S b/tools/testing/selftests/powerpc/switch_endian/check.S
index e2484d2c24f4..927a5c675e83 100644
--- a/tools/testing/selftests/powerpc/switch_endian/check.S
+++ b/tools/testing/selftests/powerpc/switch_endian/check.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include "common.h" 2#include "common.h"
2 3
3/* 4/*
diff --git a/tools/testing/selftests/powerpc/switch_endian/common.h b/tools/testing/selftests/powerpc/switch_endian/common.h
index 69e399698c64..1434cbc2a6ad 100644
--- a/tools/testing/selftests/powerpc/switch_endian/common.h
+++ b/tools/testing/selftests/powerpc/switch_endian/common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <ppc-asm.h> 2#include <ppc-asm.h>
2#include <asm/unistd.h> 3#include <asm/unistd.h>
3 4
diff --git a/tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S b/tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S
index bceb53f57573..cc4930467235 100644
--- a/tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S
+++ b/tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include "common.h" 2#include "common.h"
2 3
3 .data 4 .data
diff --git a/tools/testing/selftests/powerpc/syscalls/ipc.h b/tools/testing/selftests/powerpc/syscalls/ipc.h
index fbebc022edf6..26a20682c9a4 100644
--- a/tools/testing/selftests/powerpc/syscalls/ipc.h
+++ b/tools/testing/selftests/powerpc/syscalls/ipc.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifdef __NR_semop 2#ifdef __NR_semop
2DO_TEST(semop, __NR_semop) 3DO_TEST(semop, __NR_semop)
3#endif 4#endif
diff --git a/tools/testing/selftests/powerpc/tm/.gitignore b/tools/testing/selftests/powerpc/tm/.gitignore
index 2f1f7b013293..241a4a4ee0e4 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -12,3 +12,4 @@ tm-signal-context-chk-gpr
12tm-signal-context-chk-vmx 12tm-signal-context-chk-vmx
13tm-signal-context-chk-vsx 13tm-signal-context-chk-vsx
14tm-vmx-unavail 14tm-vmx-unavail
15tm-unavailable
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 7bfcd454fb2a..8ed6f8c57230 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,8 +1,9 @@
1# SPDX-License-Identifier: GPL-2.0
1SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu \ 2SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu \
2 tm-signal-context-chk-vmx tm-signal-context-chk-vsx 3 tm-signal-context-chk-vmx tm-signal-context-chk-vsx
3 4
4TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \ 5TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
5 tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail \ 6 tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail tm-unavailable \
6 $(SIGNAL_CONTEXT_CHK_TESTS) 7 $(SIGNAL_CONTEXT_CHK_TESTS)
7 8
8include ../../lib.mk 9include ../../lib.mk
@@ -16,6 +17,7 @@ $(OUTPUT)/tm-syscall: CFLAGS += -I../../../../../usr/include
16$(OUTPUT)/tm-tmspr: CFLAGS += -pthread 17$(OUTPUT)/tm-tmspr: CFLAGS += -pthread
17$(OUTPUT)/tm-vmx-unavail: CFLAGS += -pthread -m64 18$(OUTPUT)/tm-vmx-unavail: CFLAGS += -pthread -m64
18$(OUTPUT)/tm-resched-dscr: ../pmu/lib.o 19$(OUTPUT)/tm-resched-dscr: ../pmu/lib.o
20$(OUTPUT)/tm-unavailable: CFLAGS += -O0 -pthread -m64 -Wno-error=uninitialized -mvsx
19 21
20SIGNAL_CONTEXT_CHK_TESTS := $(patsubst %,$(OUTPUT)/%,$(SIGNAL_CONTEXT_CHK_TESTS)) 22SIGNAL_CONTEXT_CHK_TESTS := $(patsubst %,$(OUTPUT)/%,$(SIGNAL_CONTEXT_CHK_TESTS))
21$(SIGNAL_CONTEXT_CHK_TESTS): tm-signal.S 23$(SIGNAL_CONTEXT_CHK_TESTS): tm-signal.S
diff --git a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
index a7ac2e4c60d9..4cdb83964bb3 100644
--- a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
+++ b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Test context switching to see if the DSCR SPR is correctly preserved 2/* Test context switching to see if the DSCR SPR is correctly preserved
2 * when within a transaction. 3 * when within a transaction.
3 * 4 *
diff --git a/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S b/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
index 431f61ae2368..bd1ca25febe4 100644
--- a/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
+++ b/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <ppc-asm.h> 2#include <ppc-asm.h>
2#include <asm/unistd.h> 3#include <asm/unistd.h>
3 4
diff --git a/tools/testing/selftests/powerpc/tm/tm-unavailable.c b/tools/testing/selftests/powerpc/tm/tm-unavailable.c
new file mode 100644
index 000000000000..96c37f84ce54
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-unavailable.c
@@ -0,0 +1,371 @@
1/*
2 * Copyright 2017, Gustavo Romero, Breno Leitao, Cyril Bur, IBM Corp.
3 * Licensed under GPLv2.
4 *
5 * Force FP, VEC and VSX unavailable exception during transaction in all
6 * possible scenarios regarding the MSR.FP and MSR.VEC state, e.g. when FP
7 * is enable and VEC is disable, when FP is disable and VEC is enable, and
8 * so on. Then we check if the restored state is correctly set for the
9 * FP and VEC registers to the previous state we set just before we entered
10 * in TM, i.e. we check if it corrupts somehow the recheckpointed FP and
11 * VEC/Altivec registers on abortion due to an unavailable exception in TM.
12 * N.B. In this test we do not test all the FP/Altivec/VSX registers for
13 * corruption, but only for registers vs0 and vs32, which are respectively
14 * representatives of FP and VEC/Altivec reg sets.
15 */
16
17#define _GNU_SOURCE
18#include <stdio.h>
19#include <stdlib.h>
20#include <unistd.h>
21#include <inttypes.h>
22#include <stdbool.h>
23#include <pthread.h>
24#include <sched.h>
25
26#include "tm.h"
27
28#define DEBUG 0
29
30/* Unavailable exceptions to test in HTM */
31#define FP_UNA_EXCEPTION 0
32#define VEC_UNA_EXCEPTION 1
33#define VSX_UNA_EXCEPTION 2
34
35#define NUM_EXCEPTIONS 3
36
37struct Flags {
38 int touch_fp;
39 int touch_vec;
40 int result;
41 int exception;
42} flags;
43
44bool expecting_failure(void)
45{
46 if (flags.touch_fp && flags.exception == FP_UNA_EXCEPTION)
47 return false;
48
49 if (flags.touch_vec && flags.exception == VEC_UNA_EXCEPTION)
50 return false;
51
52 /*
53 * If both FP and VEC are touched it does not mean that touching VSX
54 * won't raise an exception. However since FP and VEC state are already
55 * correctly loaded, the transaction is not aborted (i.e.
56 * treclaimed/trecheckpointed) and MSR.VSX is just set as 1, so a TM
57 * failure is not expected also in this case.
58 */
59 if ((flags.touch_fp && flags.touch_vec) &&
60 flags.exception == VSX_UNA_EXCEPTION)
61 return false;
62
63 return true;
64}
65
66/* Check if failure occurred whilst in transaction. */
67bool is_failure(uint64_t condition_reg)
68{
69 /*
70 * When failure handling occurs, CR0 is set to 0b1010 (0xa). Otherwise
71 * transaction completes without failure and hence reaches out 'tend.'
72 * that sets CR0 to 0b0100 (0x4).
73 */
74 return ((condition_reg >> 28) & 0xa) == 0xa;
75}
76
77void *ping(void *input)
78{
79
80 /*
81 * Expected values for vs0 and vs32 after a TM failure. They must never
82 * change, otherwise they got corrupted.
83 */
84 uint64_t high_vs0 = 0x5555555555555555;
85 uint64_t low_vs0 = 0xffffffffffffffff;
86 uint64_t high_vs32 = 0x5555555555555555;
87 uint64_t low_vs32 = 0xffffffffffffffff;
88
89 /* Counter for busy wait */
90 uint64_t counter = 0x1ff000000;
91
92 /*
93 * Variable to keep a copy of CR register content taken just after we
94 * leave the transactional state.
95 */
96 uint64_t cr_ = 0;
97
98 /*
99 * Wait a bit so thread can get its name "ping". This is not important
100 * to reproduce the issue but it's nice to have for systemtap debugging.
101 */
102 if (DEBUG)
103 sleep(1);
104
105 printf("If MSR.FP=%d MSR.VEC=%d: ", flags.touch_fp, flags.touch_vec);
106
107 if (flags.exception != FP_UNA_EXCEPTION &&
108 flags.exception != VEC_UNA_EXCEPTION &&
109 flags.exception != VSX_UNA_EXCEPTION) {
110 printf("No valid exception specified to test.\n");
111 return NULL;
112 }
113
114 asm (
115 /* Prepare to merge low and high. */
116 " mtvsrd 33, %[high_vs0] ;"
117 " mtvsrd 34, %[low_vs0] ;"
118
119 /*
120 * Adjust VS0 expected value after an TM failure,
121 * i.e. vs0 = 0x5555555555555555555FFFFFFFFFFFFFFFF
122 */
123 " xxmrghd 0, 33, 34 ;"
124
125 /*
126 * Adjust VS32 expected value after an TM failure,
127 * i.e. vs32 = 0x5555555555555555555FFFFFFFFFFFFFFFF
128 */
129 " xxmrghd 32, 33, 34 ;"
130
131 /*
132 * Wait an amount of context switches so load_fp and load_vec
133 * overflow and MSR.FP, MSR.VEC, and MSR.VSX become zero (off).
134 */
135 " mtctr %[counter] ;"
136
137 /* Decrement CTR branch if CTR non zero. */
138 "1: bdnz 1b ;"
139
140 /*
141 * Check if we want to touch FP prior to the test in order
142 * to set MSR.FP = 1 before provoking an unavailable
143 * exception in TM.
144 */
145 " cmpldi %[touch_fp], 0 ;"
146 " beq no_fp ;"
147 " fadd 10, 10, 10 ;"
148 "no_fp: ;"
149
150 /*
151 * Check if we want to touch VEC prior to the test in order
152 * to set MSR.VEC = 1 before provoking an unavailable
153 * exception in TM.
154 */
155 " cmpldi %[touch_vec], 0 ;"
156 " beq no_vec ;"
157 " vaddcuw 10, 10, 10 ;"
158 "no_vec: ;"
159
160 /*
161 * Perhaps it would be a better idea to do the
162 * compares outside transactional context and simply
163 * duplicate code.
164 */
165 " tbegin. ;"
166 " beq trans_fail ;"
167
168 /* Do we do FP Unavailable? */
169 " cmpldi %[exception], %[ex_fp] ;"
170 " bne 1f ;"
171 " fadd 10, 10, 10 ;"
172 " b done ;"
173
174 /* Do we do VEC Unavailable? */
175 "1: cmpldi %[exception], %[ex_vec] ;"
176 " bne 2f ;"
177 " vaddcuw 10, 10, 10 ;"
178 " b done ;"
179
180 /*
181 * Not FP or VEC, therefore VSX. Ensure this
182 * instruction always generates a VSX Unavailable.
183 * ISA 3.0 is tricky here.
184 * (xxmrghd will on ISA 2.07 and ISA 3.0)
185 */
186 "2: xxmrghd 10, 10, 10 ;"
187
188 "done: tend. ;"
189
190 "trans_fail: ;"
191
192 /* Give values back to C. */
193 " mfvsrd %[high_vs0], 0 ;"
194 " xxsldwi 3, 0, 0, 2 ;"
195 " mfvsrd %[low_vs0], 3 ;"
196 " mfvsrd %[high_vs32], 32 ;"
197 " xxsldwi 3, 32, 32, 2 ;"
198 " mfvsrd %[low_vs32], 3 ;"
199
200 /* Give CR back to C so that it can check what happened. */
201 " mfcr %[cr_] ;"
202
203 : [high_vs0] "+r" (high_vs0),
204 [low_vs0] "+r" (low_vs0),
205 [high_vs32] "=r" (high_vs32),
206 [low_vs32] "=r" (low_vs32),
207 [cr_] "+r" (cr_)
208 : [touch_fp] "r" (flags.touch_fp),
209 [touch_vec] "r" (flags.touch_vec),
210 [exception] "r" (flags.exception),
211 [ex_fp] "i" (FP_UNA_EXCEPTION),
212 [ex_vec] "i" (VEC_UNA_EXCEPTION),
213 [ex_vsx] "i" (VSX_UNA_EXCEPTION),
214 [counter] "r" (counter)
215
216 : "cr0", "ctr", "v10", "vs0", "vs10", "vs3", "vs32", "vs33",
217 "vs34", "fr10"
218
219 );
220
221 /*
222 * Check if we were expecting a failure and it did not occur by checking
223 * CR0 state just after we leave the transaction. Either way we check if
224 * vs0 or vs32 got corrupted.
225 */
226 if (expecting_failure() && !is_failure(cr_)) {
227 printf("\n\tExpecting the transaction to fail, %s",
228 "but it didn't\n\t");
229 flags.result++;
230 }
231
232 /* Check if we were not expecting a failure and a it occurred. */
233 if (!expecting_failure() && is_failure(cr_)) {
234 printf("\n\tUnexpected transaction failure 0x%02lx\n\t",
235 failure_code());
236 return (void *) -1;
237 }
238
239 /*
240 * Check if TM failed due to the cause we were expecting. 0xda is a
241 * TM_CAUSE_FAC_UNAV cause, otherwise it's an unexpected cause.
242 */
243 if (is_failure(cr_) && !failure_is_unavailable()) {
244 printf("\n\tUnexpected failure cause 0x%02lx\n\t",
245 failure_code());
246 return (void *) -1;
247 }
248
249 /* 0x4 is a success and 0xa is a fail. See comment in is_failure(). */
250 if (DEBUG)
251 printf("CR0: 0x%1lx ", cr_ >> 28);
252
253 /* Check FP (vs0) for the expected value. */
254 if (high_vs0 != 0x5555555555555555 || low_vs0 != 0xFFFFFFFFFFFFFFFF) {
255 printf("FP corrupted!");
256 printf(" high = %#16" PRIx64 " low = %#16" PRIx64 " ",
257 high_vs0, low_vs0);
258 flags.result++;
259 } else
260 printf("FP ok ");
261
262 /* Check VEC (vs32) for the expected value. */
263 if (high_vs32 != 0x5555555555555555 || low_vs32 != 0xFFFFFFFFFFFFFFFF) {
264 printf("VEC corrupted!");
265 printf(" high = %#16" PRIx64 " low = %#16" PRIx64,
266 high_vs32, low_vs32);
267 flags.result++;
268 } else
269 printf("VEC ok");
270
271 putchar('\n');
272
273 return NULL;
274}
275
276/* Thread to force context switch */
277void *pong(void *not_used)
278{
279 /* Wait thread get its name "pong". */
280 if (DEBUG)
281 sleep(1);
282
283 /* Classed as an interactive-like thread. */
284 while (1)
285 sched_yield();
286}
287
288/* Function that creates a thread and launches the "ping" task. */
289void test_fp_vec(int fp, int vec, pthread_attr_t *attr)
290{
291 int retries = 2;
292 void *ret_value;
293 pthread_t t0;
294
295 flags.touch_fp = fp;
296 flags.touch_vec = vec;
297
298 /*
299 * Without luck it's possible that the transaction is aborted not due to
300 * the unavailable exception caught in the middle as we expect but also,
301 * for instance, due to a context switch or due to a KVM reschedule (if
302 * it's running on a VM). Thus we try a few times before giving up,
303 * checking if the failure cause is the one we expect.
304 */
305 do {
306 /* Bind 'ping' to CPU 0, as specified in 'attr'. */
307 pthread_create(&t0, attr, ping, (void *) &flags);
308 pthread_setname_np(t0, "ping");
309 pthread_join(t0, &ret_value);
310 retries--;
311 } while (ret_value != NULL && retries);
312
313 if (!retries) {
314 flags.result = 1;
315 if (DEBUG)
316 printf("All transactions failed unexpectedly\n");
317
318 }
319}
320
321int main(int argc, char **argv)
322{
323 int exception; /* FP = 0, VEC = 1, VSX = 2 */
324 pthread_t t1;
325 pthread_attr_t attr;
326 cpu_set_t cpuset;
327
328 /* Set only CPU 0 in the mask. Both threads will be bound to CPU 0. */
329 CPU_ZERO(&cpuset);
330 CPU_SET(0, &cpuset);
331
332 /* Init pthread attribute. */
333 pthread_attr_init(&attr);
334
335 /* Set CPU 0 mask into the pthread attribute. */
336 pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
337
338 pthread_create(&t1, &attr /* Bind 'pong' to CPU 0 */, pong, NULL);
339 pthread_setname_np(t1, "pong"); /* Name it for systemtap convenience */
340
341 flags.result = 0;
342
343 for (exception = 0; exception < NUM_EXCEPTIONS; exception++) {
344 printf("Checking if FP/VEC registers are sane after");
345
346 if (exception == FP_UNA_EXCEPTION)
347 printf(" a FP unavailable exception...\n");
348
349 else if (exception == VEC_UNA_EXCEPTION)
350 printf(" a VEC unavailable exception...\n");
351
352 else
353 printf(" a VSX unavailable exception...\n");
354
355 flags.exception = exception;
356
357 test_fp_vec(0, 0, &attr);
358 test_fp_vec(1, 0, &attr);
359 test_fp_vec(0, 1, &attr);
360 test_fp_vec(1, 1, &attr);
361
362 }
363
364 if (flags.result > 0) {
365 printf("result: failed!\n");
366 exit(1);
367 } else {
368 printf("result: success\n");
369 exit(0);
370 }
371}
diff --git a/tools/testing/selftests/powerpc/tm/tm.h b/tools/testing/selftests/powerpc/tm/tm.h
index 0ffff04433c5..df4204247d45 100644
--- a/tools/testing/selftests/powerpc/tm/tm.h
+++ b/tools/testing/selftests/powerpc/tm/tm.h
@@ -47,6 +47,11 @@ static inline bool failure_is_syscall(void)
47 return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL; 47 return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
48} 48}
49 49
50static inline bool failure_is_unavailable(void)
51{
52 return (failure_code() & TM_CAUSE_FAC_UNAV) == TM_CAUSE_FAC_UNAV;
53}
54
50static inline bool failure_is_nesting(void) 55static inline bool failure_is_nesting(void)
51{ 56{
52 return (__builtin_get_texasru() & 0x400000); 57 return (__builtin_get_texasru() & 0x400000);
diff --git a/tools/testing/selftests/powerpc/vphn/test-vphn.c b/tools/testing/selftests/powerpc/vphn/test-vphn.c
index 5742f6876b25..81d3069ffb84 100644
--- a/tools/testing/selftests/powerpc/vphn/test-vphn.c
+++ b/tools/testing/selftests/powerpc/vphn/test-vphn.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <stdio.h> 2#include <stdio.h>
2#include <byteswap.h> 3#include <byteswap.h>
3#include "utils.h" 4#include "utils.h"
diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile
index 35aa1c8f2df2..c7923b205222 100644
--- a/tools/testing/selftests/prctl/Makefile
+++ b/tools/testing/selftests/prctl/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ifndef CROSS_COMPILE 2ifndef CROSS_COMPILE
2uname_M := $(shell uname -m 2>/dev/null || echo not) 3uname_M := $(shell uname -m 2>/dev/null || echo not)
3ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) 4ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
diff --git a/tools/testing/selftests/prctl/disable-tsc-ctxt-sw-stress-test.c b/tools/testing/selftests/prctl/disable-tsc-ctxt-sw-stress-test.c
index f7499d1c0415..62a93cc61b7c 100644
--- a/tools/testing/selftests/prctl/disable-tsc-ctxt-sw-stress-test.c
+++ b/tools/testing/selftests/prctl/disable-tsc-ctxt-sw-stress-test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...) 3 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)
3 * 4 *
diff --git a/tools/testing/selftests/prctl/disable-tsc-on-off-stress-test.c b/tools/testing/selftests/prctl/disable-tsc-on-off-stress-test.c
index a06f027e9d16..79950f9a26fd 100644
--- a/tools/testing/selftests/prctl/disable-tsc-on-off-stress-test.c
+++ b/tools/testing/selftests/prctl/disable-tsc-on-off-stress-test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...) 3 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)
3 * 4 *
diff --git a/tools/testing/selftests/prctl/disable-tsc-test.c b/tools/testing/selftests/prctl/disable-tsc-test.c
index 8d494f7bebdb..f84d4ee111d3 100644
--- a/tools/testing/selftests/prctl/disable-tsc-test.c
+++ b/tools/testing/selftests/prctl/disable-tsc-test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...) 3 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)
3 * 4 *
diff --git a/tools/testing/selftests/pstore/Makefile b/tools/testing/selftests/pstore/Makefile
index c5f2440ba1f7..5ef57855a2be 100644
--- a/tools/testing/selftests/pstore/Makefile
+++ b/tools/testing/selftests/pstore/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for pstore selftests. 2# Makefile for pstore selftests.
2# Expects pstore backend is registered. 3# Expects pstore backend is registered.
3 4
diff --git a/tools/testing/selftests/ptp/Makefile b/tools/testing/selftests/ptp/Makefile
index d4064c742c26..ef06de0898b7 100644
--- a/tools/testing/selftests/ptp/Makefile
+++ b/tools/testing/selftests/ptp/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS += -I../../../../usr/include/ 2CFLAGS += -I../../../../usr/include/
2TEST_PROGS := testptp 3TEST_PROGS := testptp
3LDLIBS += -lrt 4LDLIBS += -lrt
diff --git a/tools/testing/selftests/ptrace/peeksiginfo.c b/tools/testing/selftests/ptrace/peeksiginfo.c
index c34cd8ac8aaa..54900657eb44 100644
--- a/tools/testing/selftests/ptrace/peeksiginfo.c
+++ b/tools/testing/selftests/ptrace/peeksiginfo.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <stdio.h> 3#include <stdio.h>
3#include <signal.h> 4#include <signal.h>
diff --git a/tools/testing/selftests/rcutorture/bin/config_override.sh b/tools/testing/selftests/rcutorture/bin/config_override.sh
index 49fa51726ce3..ef7fcbac3d42 100755
--- a/tools/testing/selftests/rcutorture/bin/config_override.sh
+++ b/tools/testing/selftests/rcutorture/bin/config_override.sh
@@ -42,7 +42,7 @@ else
42 exit 1 42 exit 1
43fi 43fi
44 44
45T=/tmp/config_override.sh.$$ 45T=${TMPDIR-/tmp}/config_override.sh.$$
46trap 'rm -rf $T' 0 46trap 'rm -rf $T' 0
47mkdir $T 47mkdir $T
48 48
diff --git a/tools/testing/selftests/rcutorture/bin/configcheck.sh b/tools/testing/selftests/rcutorture/bin/configcheck.sh
index 70fca318a82b..197deece7c7c 100755
--- a/tools/testing/selftests/rcutorture/bin/configcheck.sh
+++ b/tools/testing/selftests/rcutorture/bin/configcheck.sh
@@ -19,7 +19,7 @@
19# 19#
20# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 20# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
21 21
22T=/tmp/abat-chk-config.sh.$$ 22T=${TMPDIR-/tmp}/abat-chk-config.sh.$$
23trap 'rm -rf $T' 0 23trap 'rm -rf $T' 0
24mkdir $T 24mkdir $T
25 25
diff --git a/tools/testing/selftests/rcutorture/bin/configinit.sh b/tools/testing/selftests/rcutorture/bin/configinit.sh
index 3f81a1095206..51f66a7ce876 100755
--- a/tools/testing/selftests/rcutorture/bin/configinit.sh
+++ b/tools/testing/selftests/rcutorture/bin/configinit.sh
@@ -32,7 +32,7 @@
32# 32#
33# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 33# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
34 34
35T=/tmp/configinit.sh.$$ 35T=${TMPDIR-/tmp}/configinit.sh.$$
36trap 'rm -rf $T' 0 36trap 'rm -rf $T' 0
37mkdir $T 37mkdir $T
38 38
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-build.sh b/tools/testing/selftests/rcutorture/bin/kvm-build.sh
index 46752c164676..fb66d0173638 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-build.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-build.sh
@@ -35,7 +35,7 @@ then
35 exit 1 35 exit 1
36fi 36fi
37 37
38T=/tmp/test-linux.sh.$$ 38T=${TMPDIR-/tmp}/test-linux.sh.$$
39trap 'rm -rf $T' 0 39trap 'rm -rf $T' 0
40mkdir $T 40mkdir $T
41 41
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 0af36a721b9c..ab14b97c942c 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -38,7 +38,7 @@
38# 38#
39# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 39# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
40 40
41T=/tmp/kvm-test-1-run.sh.$$ 41T=${TMPDIR-/tmp}/kvm-test-1-run.sh.$$
42trap 'rm -rf $T' 0 42trap 'rm -rf $T' 0
43mkdir $T 43mkdir $T
44 44
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh b/tools/testing/selftests/rcutorture/bin/kvm.sh
index b55895fb10ed..ccd49e958fd2 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -30,7 +30,7 @@
30scriptname=$0 30scriptname=$0
31args="$*" 31args="$*"
32 32
33T=/tmp/kvm.sh.$$ 33T=${TMPDIR-/tmp}/kvm.sh.$$
34trap 'rm -rf $T' 0 34trap 'rm -rf $T' 0
35mkdir $T 35mkdir $T
36 36
@@ -222,7 +222,7 @@ do
222 exit 1 222 exit 1
223 fi 223 fi
224done 224done
225sort -k2nr $T/cfgcpu > $T/cfgcpu.sort 225sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
226 226
227# Use a greedy bin-packing algorithm, sorting the list accordingly. 227# Use a greedy bin-packing algorithm, sorting the list accordingly.
228awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus ' 228awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
diff --git a/tools/testing/selftests/rcutorture/bin/parse-build.sh b/tools/testing/selftests/rcutorture/bin/parse-build.sh
index a6b57622c2e5..24fe5f822b28 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-build.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-build.sh
@@ -28,7 +28,7 @@
28 28
29F=$1 29F=$1
30title=$2 30title=$2
31T=/tmp/parse-build.sh.$$ 31T=${TMPDIR-/tmp}/parse-build.sh.$$
32trap 'rm -rf $T' 0 32trap 'rm -rf $T' 0
33mkdir $T 33mkdir $T
34 34
diff --git a/tools/testing/selftests/rcutorture/bin/parse-torture.sh b/tools/testing/selftests/rcutorture/bin/parse-torture.sh
index e3c5f0705696..f12c38909b00 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-torture.sh
@@ -27,7 +27,7 @@
27# 27#
28# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 28# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
29 29
30T=/tmp/parse-torture.sh.$$ 30T=${TMPDIR-/tmp}/parse-torture.sh.$$
31file="$1" 31file="$1"
32title="$2" 32title="$2"
33 33
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/Makefile b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/Makefile
index 16b01559fa55..4bed0b678f8b 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/Makefile
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: srcu.c store_buffering 2all: srcu.c store_buffering
2 3
3LINUX_SOURCE = ../../../../../.. 4LINUX_SOURCE = ../../../../../..
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/include/linux/types.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/include/linux/types.h
index 4a3d538fef12..891ad13e95b2 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/include/linux/types.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/include/linux/types.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This header has been modifies to remove definitions of types that 3 * This header has been modifies to remove definitions of types that
3 * are defined in standard userspace headers or are problematic for some 4 * are defined in standard userspace headers or are problematic for some
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/modify_srcu.awk b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/modify_srcu.awk
index c9e8bc5082a7..e05182d3e47d 100755
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/modify_srcu.awk
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/modify_srcu.awk
@@ -1,4 +1,5 @@
1#!/usr/bin/awk -f 1#!/usr/bin/awk -f
2# SPDX-License-Identifier: GPL-2.0
2 3
3# Modify SRCU for formal verification. The first argument should be srcu.h and 4# Modify SRCU for formal verification. The first argument should be srcu.h and
4# the second should be srcu.c. Outputs modified srcu.h and srcu.c into the 5# the second should be srcu.c. Outputs modified srcu.h and srcu.c into the
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/assume.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/assume.h
index a64955447995..570a49d9da7e 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/assume.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/assume.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ASSUME_H 2#ifndef ASSUME_H
2#define ASSUME_H 3#define ASSUME_H
3 4
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h
index 6687acc08e6d..3f95a768a03b 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef BARRIERS_H 2#ifndef BARRIERS_H
2#define BARRIERS_H 3#define BARRIERS_H
3 4
@@ -34,8 +35,7 @@
34#define rs_smp_mb() do {} while (0) 35#define rs_smp_mb() do {} while (0)
35#endif 36#endif
36 37
37#define ACCESS_ONCE(x) (*(volatile typeof(x) *) &(x)) 38#define READ_ONCE(x) (*(volatile typeof(x) *) &(x))
38#define READ_ONCE(x) ACCESS_ONCE(x) 39#define WRITE_ONCE(x) ((*(volatile typeof(x) *) &(x)) = (val))
39#define WRITE_ONCE(x, val) (ACCESS_ONCE(x) = (val))
40 40
41#endif 41#endif
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/bug_on.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/bug_on.h
index 2a80e91f78e7..5e7912c6a521 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/bug_on.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/bug_on.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef BUG_ON_H 2#ifndef BUG_ON_H
2#define BUG_ON_H 3#define BUG_ON_H
3 4
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/combined_source.c b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/combined_source.c
index 29eb5d2697ed..e67ee5b3dd7c 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/combined_source.c
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/combined_source.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <config.h> 2#include <config.h>
2 3
3/* Include all source files. */ 4/* Include all source files. */
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/config.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/config.h
index a60038aeea7a..283d7103334f 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/config.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/config.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* "Cheater" definitions based on restricted Kconfig choices. */ 2/* "Cheater" definitions based on restricted Kconfig choices. */
2 3
3#undef CONFIG_TINY_RCU 4#undef CONFIG_TINY_RCU
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/include_srcu.c b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/include_srcu.c
index 5ec582a53018..e5202d4cff30 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/include_srcu.c
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/include_srcu.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <config.h> 2#include <config.h>
2 3
3#include <assert.h> 4#include <assert.h>
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/int_typedefs.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/int_typedefs.h
index 3aad63917858..0dd27aa517a7 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/int_typedefs.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/int_typedefs.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef INT_TYPEDEFS_H 2#ifndef INT_TYPEDEFS_H
2#define INT_TYPEDEFS_H 3#define INT_TYPEDEFS_H
3 4
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/locks.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/locks.h
index 356004665576..cf6938d679d7 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/locks.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/locks.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef LOCKS_H 2#ifndef LOCKS_H
2#define LOCKS_H 3#define LOCKS_H
3 4
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/misc.c b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/misc.c
index ca892e3b2351..9440cc39e3c6 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/misc.c
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/misc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <config.h> 2#include <config.h>
2 3
3#include "misc.h" 4#include "misc.h"
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/percpu.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/percpu.h
index 3de5a49de49b..27e67a3f291f 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/percpu.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/percpu.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PERCPU_H 2#ifndef PERCPU_H
2#define PERCPU_H 3#define PERCPU_H
3 4
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.c b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.c
index 4f1b068e9b7a..b4083ae348fb 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.c
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <config.h> 2#include <config.h>
2 3
3#include "preempt.h" 4#include "preempt.h"
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.h
index 2f95ee0e4dd5..f8b762cd214c 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef PREEMPT_H 2#ifndef PREEMPT_H
2#define PREEMPT_H 3#define PREEMPT_H
3 4
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/simple_sync_srcu.c b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/simple_sync_srcu.c
index ac9cbc62b411..97f592048e0b 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/simple_sync_srcu.c
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/simple_sync_srcu.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <config.h> 2#include <config.h>
2 3
3#include <assert.h> 4#include <assert.h>
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/workqueues.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/workqueues.h
index e58c8dfd3e90..28b960300971 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/workqueues.h
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/workqueues.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef WORKQUEUES_H 2#ifndef WORKQUEUES_H
2#define WORKQUEUES_H 3#define WORKQUEUES_H
3 4
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/Makefile b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/Makefile
index 3a3aee149225..ad21b925fbb4 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/Makefile
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CBMC_FLAGS = -I../.. -I../../src -I../../include -I../../empty_includes -32 -pointer-check -mm pso 2CBMC_FLAGS = -I../.. -I../../src -I../../include -I../../empty_includes -32 -pointer-check -mm pso
2 3
3all: 4all:
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/test.c b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/test.c
index 470b1105a112..2ce2016f7871 100644
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/test.c
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/store_buffering/test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <src/combined_source.c> 2#include <src/combined_source.c>
2 3
3int x; 4int x;
diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/test_script.sh b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/test_script.sh
index d1545972a0fa..2fe1f0339b4f 100755
--- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/test_script.sh
+++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/tests/test_script.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3# This script expects a mode (either --should-pass or --should-fail) followed by 4# This script expects a mode (either --should-pass or --should-fail) followed by
4# an input file. The script uses the following environment variables. The test C 5# an input file. The script uses the following environment variables. The test C
diff --git a/tools/testing/selftests/seccomp/.gitignore b/tools/testing/selftests/seccomp/.gitignore
index 346d83ca8069..5af29d3a1b0a 100644
--- a/tools/testing/selftests/seccomp/.gitignore
+++ b/tools/testing/selftests/seccomp/.gitignore
@@ -1 +1,2 @@
1seccomp_bpf 1seccomp_bpf
2seccomp_benchmark
diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
index aeb0c805f3ca..fce7f4ce0692 100644
--- a/tools/testing/selftests/seccomp/Makefile
+++ b/tools/testing/selftests/seccomp/Makefile
@@ -1,8 +1,17 @@
1TEST_GEN_PROGS := seccomp_bpf 1# SPDX-License-Identifier: GPL-2.0
2CFLAGS += -Wl,-no-as-needed -Wall 2all:
3LDFLAGS += -lpthread
4 3
5include ../lib.mk 4include ../lib.mk
6 5
7$(TEST_GEN_PROGS): seccomp_bpf.c ../kselftest_harness.h 6.PHONY: all clean
8 $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 7
8BINARIES := seccomp_bpf seccomp_benchmark
9CFLAGS += -Wl,-no-as-needed -Wall
10
11seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
12 $(CC) $(CFLAGS) $(LDFLAGS) -lpthread $< -o $@
13
14TEST_PROGS += $(BINARIES)
15EXTRA_CLEAN := $(BINARIES)
16
17all: $(BINARIES)
diff --git a/tools/testing/selftests/seccomp/seccomp_benchmark.c b/tools/testing/selftests/seccomp/seccomp_benchmark.c
new file mode 100644
index 000000000000..5838c8697ec3
--- /dev/null
+++ b/tools/testing/selftests/seccomp/seccomp_benchmark.c
@@ -0,0 +1,99 @@
1/*
2 * Strictly speaking, this is not a test. But it can report during test
3 * runs so relative performace can be measured.
4 */
5#define _GNU_SOURCE
6#include <assert.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <time.h>
10#include <unistd.h>
11#include <linux/filter.h>
12#include <linux/seccomp.h>
13#include <sys/prctl.h>
14#include <sys/syscall.h>
15#include <sys/types.h>
16
17#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
18
19unsigned long long timing(clockid_t clk_id, unsigned long long samples)
20{
21 pid_t pid, ret;
22 unsigned long long i;
23 struct timespec start, finish;
24
25 pid = getpid();
26 assert(clock_gettime(clk_id, &start) == 0);
27 for (i = 0; i < samples; i++) {
28 ret = syscall(__NR_getpid);
29 assert(pid == ret);
30 }
31 assert(clock_gettime(clk_id, &finish) == 0);
32
33 i = finish.tv_sec - start.tv_sec;
34 i *= 1000000000;
35 i += finish.tv_nsec - start.tv_nsec;
36
37 printf("%lu.%09lu - %lu.%09lu = %llu\n",
38 finish.tv_sec, finish.tv_nsec,
39 start.tv_sec, start.tv_nsec,
40 i);
41
42 return i;
43}
44
45unsigned long long calibrate(void)
46{
47 unsigned long long i;
48
49 printf("Calibrating reasonable sample size...\n");
50
51 for (i = 5; ; i++) {
52 unsigned long long samples = 1 << i;
53
54 /* Find something that takes more than 5 seconds to run. */
55 if (timing(CLOCK_REALTIME, samples) / 1000000000ULL > 5)
56 return samples;
57 }
58}
59
60int main(int argc, char *argv[])
61{
62 struct sock_filter filter[] = {
63 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
64 };
65 struct sock_fprog prog = {
66 .len = (unsigned short)ARRAY_SIZE(filter),
67 .filter = filter,
68 };
69 long ret;
70 unsigned long long samples;
71 unsigned long long native, filtered;
72
73 if (argc > 1)
74 samples = strtoull(argv[1], NULL, 0);
75 else
76 samples = calibrate();
77
78 printf("Benchmarking %llu samples...\n", samples);
79
80 native = timing(CLOCK_PROCESS_CPUTIME_ID, samples) / samples;
81 printf("getpid native: %llu ns\n", native);
82
83 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
84 assert(ret == 0);
85
86 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog);
87 assert(ret == 0);
88
89 filtered = timing(CLOCK_PROCESS_CPUTIME_ID, samples) / samples;
90 printf("getpid RET_ALLOW: %llu ns\n", filtered);
91
92 printf("Estimated seccomp overhead per syscall: %llu ns\n",
93 filtered - native);
94
95 if (filtered == native)
96 printf("Trying running again with more samples.\n");
97
98 return 0;
99}
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 4d6f92a9df6b..24dbf634e2dd 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -6,10 +6,18 @@
6 */ 6 */
7 7
8#include <sys/types.h> 8#include <sys/types.h>
9#include <asm/siginfo.h> 9
10#define __have_siginfo_t 1 10/*
11#define __have_sigval_t 1 11 * glibc 2.26 and later have SIGSYS in siginfo_t. Before that,
12#define __have_sigevent_t 1 12 * we need to use the kernel's siginfo.h file and trick glibc
13 * into accepting it.
14 */
15#if !__GLIBC_PREREQ(2, 26)
16# include <asm/siginfo.h>
17# define __have_siginfo_t 1
18# define __have_sigval_t 1
19# define __have_sigevent_t 1
20#endif
13 21
14#include <errno.h> 22#include <errno.h>
15#include <linux/filter.h> 23#include <linux/filter.h>
@@ -68,17 +76,7 @@
68#define SECCOMP_MODE_FILTER 2 76#define SECCOMP_MODE_FILTER 2
69#endif 77#endif
70 78
71#ifndef SECCOMP_RET_KILL 79#ifndef SECCOMP_RET_ALLOW
72#define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
73#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
74#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
75#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
76#define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
77
78/* Masks for the return value sections. */
79#define SECCOMP_RET_ACTION 0x7fff0000U
80#define SECCOMP_RET_DATA 0x0000ffffU
81
82struct seccomp_data { 80struct seccomp_data {
83 int nr; 81 int nr;
84 __u32 arch; 82 __u32 arch;
@@ -87,6 +85,70 @@ struct seccomp_data {
87}; 85};
88#endif 86#endif
89 87
88#ifndef SECCOMP_RET_KILL_PROCESS
89#define SECCOMP_RET_KILL_PROCESS 0x80000000U /* kill the process */
90#define SECCOMP_RET_KILL_THREAD 0x00000000U /* kill the thread */
91#endif
92#ifndef SECCOMP_RET_KILL
93#define SECCOMP_RET_KILL SECCOMP_RET_KILL_THREAD
94#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
95#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
96#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
97#define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
98#endif
99#ifndef SECCOMP_RET_LOG
100#define SECCOMP_RET_LOG 0x7ffc0000U /* allow after logging */
101#endif
102
103#ifndef __NR_seccomp
104# if defined(__i386__)
105# define __NR_seccomp 354
106# elif defined(__x86_64__)
107# define __NR_seccomp 317
108# elif defined(__arm__)
109# define __NR_seccomp 383
110# elif defined(__aarch64__)
111# define __NR_seccomp 277
112# elif defined(__hppa__)
113# define __NR_seccomp 338
114# elif defined(__powerpc__)
115# define __NR_seccomp 358
116# elif defined(__s390__)
117# define __NR_seccomp 348
118# else
119# warning "seccomp syscall number unknown for this architecture"
120# define __NR_seccomp 0xffff
121# endif
122#endif
123
124#ifndef SECCOMP_SET_MODE_STRICT
125#define SECCOMP_SET_MODE_STRICT 0
126#endif
127
128#ifndef SECCOMP_SET_MODE_FILTER
129#define SECCOMP_SET_MODE_FILTER 1
130#endif
131
132#ifndef SECCOMP_GET_ACTION_AVAIL
133#define SECCOMP_GET_ACTION_AVAIL 2
134#endif
135
136#ifndef SECCOMP_FILTER_FLAG_TSYNC
137#define SECCOMP_FILTER_FLAG_TSYNC 1
138#endif
139
140#ifndef SECCOMP_FILTER_FLAG_LOG
141#define SECCOMP_FILTER_FLAG_LOG 2
142#endif
143
144#ifndef seccomp
145int seccomp(unsigned int op, unsigned int flags, void *args)
146{
147 errno = 0;
148 return syscall(__NR_seccomp, op, flags, args);
149}
150#endif
151
90#if __BYTE_ORDER == __LITTLE_ENDIAN 152#if __BYTE_ORDER == __LITTLE_ENDIAN
91#define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n])) 153#define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]))
92#elif __BYTE_ORDER == __BIG_ENDIAN 154#elif __BYTE_ORDER == __BIG_ENDIAN
@@ -136,7 +198,7 @@ TEST(no_new_privs_support)
136 } 198 }
137} 199}
138 200
139/* Tests kernel support by checking for a copy_from_user() fault on * NULL. */ 201/* Tests kernel support by checking for a copy_from_user() fault on NULL. */
140TEST(mode_filter_support) 202TEST(mode_filter_support)
141{ 203{
142 long ret; 204 long ret;
@@ -342,6 +404,28 @@ TEST(empty_prog)
342 EXPECT_EQ(EINVAL, errno); 404 EXPECT_EQ(EINVAL, errno);
343} 405}
344 406
407TEST(log_all)
408{
409 struct sock_filter filter[] = {
410 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_LOG),
411 };
412 struct sock_fprog prog = {
413 .len = (unsigned short)ARRAY_SIZE(filter),
414 .filter = filter,
415 };
416 long ret;
417 pid_t parent = getppid();
418
419 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
420 ASSERT_EQ(0, ret);
421
422 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog);
423 ASSERT_EQ(0, ret);
424
425 /* getppid() should succeed and be logged (no check for logging) */
426 EXPECT_EQ(parent, syscall(__NR_getppid));
427}
428
345TEST_SIGNAL(unknown_ret_is_kill_inside, SIGSYS) 429TEST_SIGNAL(unknown_ret_is_kill_inside, SIGSYS)
346{ 430{
347 struct sock_filter filter[] = { 431 struct sock_filter filter[] = {
@@ -520,6 +604,117 @@ TEST_SIGNAL(KILL_one_arg_six, SIGSYS)
520 close(fd); 604 close(fd);
521} 605}
522 606
607/* This is a thread task to die via seccomp filter violation. */
608void *kill_thread(void *data)
609{
610 bool die = (bool)data;
611
612 if (die) {
613 prctl(PR_GET_SECCOMP, 0, 0, 0, 0);
614 return (void *)SIBLING_EXIT_FAILURE;
615 }
616
617 return (void *)SIBLING_EXIT_UNKILLED;
618}
619
620/* Prepare a thread that will kill itself or both of us. */
621void kill_thread_or_group(struct __test_metadata *_metadata, bool kill_process)
622{
623 pthread_t thread;
624 void *status;
625 /* Kill only when calling __NR_prctl. */
626 struct sock_filter filter_thread[] = {
627 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
628 offsetof(struct seccomp_data, nr)),
629 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_prctl, 0, 1),
630 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL_THREAD),
631 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
632 };
633 struct sock_fprog prog_thread = {
634 .len = (unsigned short)ARRAY_SIZE(filter_thread),
635 .filter = filter_thread,
636 };
637 struct sock_filter filter_process[] = {
638 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
639 offsetof(struct seccomp_data, nr)),
640 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_prctl, 0, 1),
641 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL_PROCESS),
642 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
643 };
644 struct sock_fprog prog_process = {
645 .len = (unsigned short)ARRAY_SIZE(filter_process),
646 .filter = filter_process,
647 };
648
649 ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
650 TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
651 }
652
653 ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0,
654 kill_process ? &prog_process : &prog_thread));
655
656 /*
657 * Add the KILL_THREAD rule again to make sure that the KILL_PROCESS
658 * flag cannot be downgraded by a new filter.
659 */
660 ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog_thread));
661
662 /* Start a thread that will exit immediately. */
663 ASSERT_EQ(0, pthread_create(&thread, NULL, kill_thread, (void *)false));
664 ASSERT_EQ(0, pthread_join(thread, &status));
665 ASSERT_EQ(SIBLING_EXIT_UNKILLED, (unsigned long)status);
666
667 /* Start a thread that will die immediately. */
668 ASSERT_EQ(0, pthread_create(&thread, NULL, kill_thread, (void *)true));
669 ASSERT_EQ(0, pthread_join(thread, &status));
670 ASSERT_NE(SIBLING_EXIT_FAILURE, (unsigned long)status);
671
672 /*
673 * If we get here, only the spawned thread died. Let the parent know
674 * the whole process didn't die (i.e. this thread, the spawner,
675 * stayed running).
676 */
677 exit(42);
678}
679
680TEST(KILL_thread)
681{
682 int status;
683 pid_t child_pid;
684
685 child_pid = fork();
686 ASSERT_LE(0, child_pid);
687 if (child_pid == 0) {
688 kill_thread_or_group(_metadata, false);
689 _exit(38);
690 }
691
692 ASSERT_EQ(child_pid, waitpid(child_pid, &status, 0));
693
694 /* If only the thread was killed, we'll see exit 42. */
695 ASSERT_TRUE(WIFEXITED(status));
696 ASSERT_EQ(42, WEXITSTATUS(status));
697}
698
699TEST(KILL_process)
700{
701 int status;
702 pid_t child_pid;
703
704 child_pid = fork();
705 ASSERT_LE(0, child_pid);
706 if (child_pid == 0) {
707 kill_thread_or_group(_metadata, true);
708 _exit(38);
709 }
710
711 ASSERT_EQ(child_pid, waitpid(child_pid, &status, 0));
712
713 /* If the entire process was killed, we'll see SIGSYS. */
714 ASSERT_TRUE(WIFSIGNALED(status));
715 ASSERT_EQ(SIGSYS, WTERMSIG(status));
716}
717
523/* TODO(wad) add 64-bit versus 32-bit arg tests. */ 718/* TODO(wad) add 64-bit versus 32-bit arg tests. */
524TEST(arg_out_of_range) 719TEST(arg_out_of_range)
525{ 720{
@@ -541,26 +736,30 @@ TEST(arg_out_of_range)
541 EXPECT_EQ(EINVAL, errno); 736 EXPECT_EQ(EINVAL, errno);
542} 737}
543 738
739#define ERRNO_FILTER(name, errno) \
740 struct sock_filter _read_filter_##name[] = { \
741 BPF_STMT(BPF_LD|BPF_W|BPF_ABS, \
742 offsetof(struct seccomp_data, nr)), \
743 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_read, 0, 1), \
744 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ERRNO | errno), \
745 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), \
746 }; \
747 struct sock_fprog prog_##name = { \
748 .len = (unsigned short)ARRAY_SIZE(_read_filter_##name), \
749 .filter = _read_filter_##name, \
750 }
751
752/* Make sure basic errno values are correctly passed through a filter. */
544TEST(ERRNO_valid) 753TEST(ERRNO_valid)
545{ 754{
546 struct sock_filter filter[] = { 755 ERRNO_FILTER(valid, E2BIG);
547 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
548 offsetof(struct seccomp_data, nr)),
549 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_read, 0, 1),
550 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ERRNO | E2BIG),
551 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
552 };
553 struct sock_fprog prog = {
554 .len = (unsigned short)ARRAY_SIZE(filter),
555 .filter = filter,
556 };
557 long ret; 756 long ret;
558 pid_t parent = getppid(); 757 pid_t parent = getppid();
559 758
560 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 759 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
561 ASSERT_EQ(0, ret); 760 ASSERT_EQ(0, ret);
562 761
563 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog); 762 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog_valid);
564 ASSERT_EQ(0, ret); 763 ASSERT_EQ(0, ret);
565 764
566 EXPECT_EQ(parent, syscall(__NR_getppid)); 765 EXPECT_EQ(parent, syscall(__NR_getppid));
@@ -568,26 +767,17 @@ TEST(ERRNO_valid)
568 EXPECT_EQ(E2BIG, errno); 767 EXPECT_EQ(E2BIG, errno);
569} 768}
570 769
770/* Make sure an errno of zero is correctly handled by the arch code. */
571TEST(ERRNO_zero) 771TEST(ERRNO_zero)
572{ 772{
573 struct sock_filter filter[] = { 773 ERRNO_FILTER(zero, 0);
574 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
575 offsetof(struct seccomp_data, nr)),
576 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_read, 0, 1),
577 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ERRNO | 0),
578 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
579 };
580 struct sock_fprog prog = {
581 .len = (unsigned short)ARRAY_SIZE(filter),
582 .filter = filter,
583 };
584 long ret; 774 long ret;
585 pid_t parent = getppid(); 775 pid_t parent = getppid();
586 776
587 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 777 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
588 ASSERT_EQ(0, ret); 778 ASSERT_EQ(0, ret);
589 779
590 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog); 780 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog_zero);
591 ASSERT_EQ(0, ret); 781 ASSERT_EQ(0, ret);
592 782
593 EXPECT_EQ(parent, syscall(__NR_getppid)); 783 EXPECT_EQ(parent, syscall(__NR_getppid));
@@ -595,26 +785,21 @@ TEST(ERRNO_zero)
595 EXPECT_EQ(0, read(0, NULL, 0)); 785 EXPECT_EQ(0, read(0, NULL, 0));
596} 786}
597 787
788/*
789 * The SECCOMP_RET_DATA mask is 16 bits wide, but errno is smaller.
790 * This tests that the errno value gets capped correctly, fixed by
791 * 580c57f10768 ("seccomp: cap SECCOMP_RET_ERRNO data to MAX_ERRNO").
792 */
598TEST(ERRNO_capped) 793TEST(ERRNO_capped)
599{ 794{
600 struct sock_filter filter[] = { 795 ERRNO_FILTER(capped, 4096);
601 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
602 offsetof(struct seccomp_data, nr)),
603 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_read, 0, 1),
604 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ERRNO | 4096),
605 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
606 };
607 struct sock_fprog prog = {
608 .len = (unsigned short)ARRAY_SIZE(filter),
609 .filter = filter,
610 };
611 long ret; 796 long ret;
612 pid_t parent = getppid(); 797 pid_t parent = getppid();
613 798
614 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 799 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
615 ASSERT_EQ(0, ret); 800 ASSERT_EQ(0, ret);
616 801
617 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog); 802 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog_capped);
618 ASSERT_EQ(0, ret); 803 ASSERT_EQ(0, ret);
619 804
620 EXPECT_EQ(parent, syscall(__NR_getppid)); 805 EXPECT_EQ(parent, syscall(__NR_getppid));
@@ -622,6 +807,37 @@ TEST(ERRNO_capped)
622 EXPECT_EQ(4095, errno); 807 EXPECT_EQ(4095, errno);
623} 808}
624 809
810/*
811 * Filters are processed in reverse order: last applied is executed first.
812 * Since only the SECCOMP_RET_ACTION mask is tested for return values, the
813 * SECCOMP_RET_DATA mask results will follow the most recently applied
814 * matching filter return (and not the lowest or highest value).
815 */
816TEST(ERRNO_order)
817{
818 ERRNO_FILTER(first, 11);
819 ERRNO_FILTER(second, 13);
820 ERRNO_FILTER(third, 12);
821 long ret;
822 pid_t parent = getppid();
823
824 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
825 ASSERT_EQ(0, ret);
826
827 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog_first);
828 ASSERT_EQ(0, ret);
829
830 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog_second);
831 ASSERT_EQ(0, ret);
832
833 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog_third);
834 ASSERT_EQ(0, ret);
835
836 EXPECT_EQ(parent, syscall(__NR_getppid));
837 EXPECT_EQ(-1, read(0, NULL, 0));
838 EXPECT_EQ(12, errno);
839}
840
625FIXTURE_DATA(TRAP) { 841FIXTURE_DATA(TRAP) {
626 struct sock_fprog prog; 842 struct sock_fprog prog;
627}; 843};
@@ -676,7 +892,7 @@ TEST_F_SIGNAL(TRAP, ign, SIGSYS)
676 syscall(__NR_getpid); 892 syscall(__NR_getpid);
677} 893}
678 894
679static struct siginfo TRAP_info; 895static siginfo_t TRAP_info;
680static volatile int TRAP_nr; 896static volatile int TRAP_nr;
681static void TRAP_action(int nr, siginfo_t *info, void *void_context) 897static void TRAP_action(int nr, siginfo_t *info, void *void_context)
682{ 898{
@@ -735,6 +951,7 @@ TEST_F(TRAP, handler)
735 951
736FIXTURE_DATA(precedence) { 952FIXTURE_DATA(precedence) {
737 struct sock_fprog allow; 953 struct sock_fprog allow;
954 struct sock_fprog log;
738 struct sock_fprog trace; 955 struct sock_fprog trace;
739 struct sock_fprog error; 956 struct sock_fprog error;
740 struct sock_fprog trap; 957 struct sock_fprog trap;
@@ -746,6 +963,13 @@ FIXTURE_SETUP(precedence)
746 struct sock_filter allow_insns[] = { 963 struct sock_filter allow_insns[] = {
747 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), 964 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
748 }; 965 };
966 struct sock_filter log_insns[] = {
967 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
968 offsetof(struct seccomp_data, nr)),
969 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getpid, 1, 0),
970 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
971 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_LOG),
972 };
749 struct sock_filter trace_insns[] = { 973 struct sock_filter trace_insns[] = {
750 BPF_STMT(BPF_LD|BPF_W|BPF_ABS, 974 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
751 offsetof(struct seccomp_data, nr)), 975 offsetof(struct seccomp_data, nr)),
@@ -782,6 +1006,7 @@ FIXTURE_SETUP(precedence)
782 memcpy(self->_x.filter, &_x##_insns, sizeof(_x##_insns)); \ 1006 memcpy(self->_x.filter, &_x##_insns, sizeof(_x##_insns)); \
783 self->_x.len = (unsigned short)ARRAY_SIZE(_x##_insns) 1007 self->_x.len = (unsigned short)ARRAY_SIZE(_x##_insns)
784 FILTER_ALLOC(allow); 1008 FILTER_ALLOC(allow);
1009 FILTER_ALLOC(log);
785 FILTER_ALLOC(trace); 1010 FILTER_ALLOC(trace);
786 FILTER_ALLOC(error); 1011 FILTER_ALLOC(error);
787 FILTER_ALLOC(trap); 1012 FILTER_ALLOC(trap);
@@ -792,6 +1017,7 @@ FIXTURE_TEARDOWN(precedence)
792{ 1017{
793#define FILTER_FREE(_x) if (self->_x.filter) free(self->_x.filter) 1018#define FILTER_FREE(_x) if (self->_x.filter) free(self->_x.filter)
794 FILTER_FREE(allow); 1019 FILTER_FREE(allow);
1020 FILTER_FREE(log);
795 FILTER_FREE(trace); 1021 FILTER_FREE(trace);
796 FILTER_FREE(error); 1022 FILTER_FREE(error);
797 FILTER_FREE(trap); 1023 FILTER_FREE(trap);
@@ -809,6 +1035,8 @@ TEST_F(precedence, allow_ok)
809 1035
810 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow); 1036 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
811 ASSERT_EQ(0, ret); 1037 ASSERT_EQ(0, ret);
1038 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1039 ASSERT_EQ(0, ret);
812 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1040 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
813 ASSERT_EQ(0, ret); 1041 ASSERT_EQ(0, ret);
814 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error); 1042 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error);
@@ -833,6 +1061,8 @@ TEST_F_SIGNAL(precedence, kill_is_highest, SIGSYS)
833 1061
834 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow); 1062 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
835 ASSERT_EQ(0, ret); 1063 ASSERT_EQ(0, ret);
1064 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1065 ASSERT_EQ(0, ret);
836 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1066 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
837 ASSERT_EQ(0, ret); 1067 ASSERT_EQ(0, ret);
838 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error); 1068 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error);
@@ -864,6 +1094,8 @@ TEST_F_SIGNAL(precedence, kill_is_highest_in_any_order, SIGSYS)
864 ASSERT_EQ(0, ret); 1094 ASSERT_EQ(0, ret);
865 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error); 1095 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error);
866 ASSERT_EQ(0, ret); 1096 ASSERT_EQ(0, ret);
1097 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1098 ASSERT_EQ(0, ret);
867 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1099 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
868 ASSERT_EQ(0, ret); 1100 ASSERT_EQ(0, ret);
869 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trap); 1101 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trap);
@@ -885,6 +1117,8 @@ TEST_F_SIGNAL(precedence, trap_is_second, SIGSYS)
885 1117
886 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow); 1118 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
887 ASSERT_EQ(0, ret); 1119 ASSERT_EQ(0, ret);
1120 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1121 ASSERT_EQ(0, ret);
888 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1122 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
889 ASSERT_EQ(0, ret); 1123 ASSERT_EQ(0, ret);
890 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error); 1124 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error);
@@ -910,6 +1144,8 @@ TEST_F_SIGNAL(precedence, trap_is_second_in_any_order, SIGSYS)
910 ASSERT_EQ(0, ret); 1144 ASSERT_EQ(0, ret);
911 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trap); 1145 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trap);
912 ASSERT_EQ(0, ret); 1146 ASSERT_EQ(0, ret);
1147 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1148 ASSERT_EQ(0, ret);
913 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1149 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
914 ASSERT_EQ(0, ret); 1150 ASSERT_EQ(0, ret);
915 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error); 1151 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error);
@@ -931,6 +1167,8 @@ TEST_F(precedence, errno_is_third)
931 1167
932 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow); 1168 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
933 ASSERT_EQ(0, ret); 1169 ASSERT_EQ(0, ret);
1170 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1171 ASSERT_EQ(0, ret);
934 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1172 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
935 ASSERT_EQ(0, ret); 1173 ASSERT_EQ(0, ret);
936 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error); 1174 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error);
@@ -949,6 +1187,8 @@ TEST_F(precedence, errno_is_third_in_any_order)
949 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 1187 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
950 ASSERT_EQ(0, ret); 1188 ASSERT_EQ(0, ret);
951 1189
1190 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1191 ASSERT_EQ(0, ret);
952 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error); 1192 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->error);
953 ASSERT_EQ(0, ret); 1193 ASSERT_EQ(0, ret);
954 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1194 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
@@ -971,6 +1211,8 @@ TEST_F(precedence, trace_is_fourth)
971 1211
972 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow); 1212 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
973 ASSERT_EQ(0, ret); 1213 ASSERT_EQ(0, ret);
1214 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1215 ASSERT_EQ(0, ret);
974 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace); 1216 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->trace);
975 ASSERT_EQ(0, ret); 1217 ASSERT_EQ(0, ret);
976 /* Should work just fine. */ 1218 /* Should work just fine. */
@@ -992,12 +1234,54 @@ TEST_F(precedence, trace_is_fourth_in_any_order)
992 ASSERT_EQ(0, ret); 1234 ASSERT_EQ(0, ret);
993 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow); 1235 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
994 ASSERT_EQ(0, ret); 1236 ASSERT_EQ(0, ret);
1237 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1238 ASSERT_EQ(0, ret);
995 /* Should work just fine. */ 1239 /* Should work just fine. */
996 EXPECT_EQ(parent, syscall(__NR_getppid)); 1240 EXPECT_EQ(parent, syscall(__NR_getppid));
997 /* No ptracer */ 1241 /* No ptracer */
998 EXPECT_EQ(-1, syscall(__NR_getpid)); 1242 EXPECT_EQ(-1, syscall(__NR_getpid));
999} 1243}
1000 1244
1245TEST_F(precedence, log_is_fifth)
1246{
1247 pid_t mypid, parent;
1248 long ret;
1249
1250 mypid = getpid();
1251 parent = getppid();
1252 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
1253 ASSERT_EQ(0, ret);
1254
1255 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
1256 ASSERT_EQ(0, ret);
1257 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1258 ASSERT_EQ(0, ret);
1259 /* Should work just fine. */
1260 EXPECT_EQ(parent, syscall(__NR_getppid));
1261 /* Should also work just fine */
1262 EXPECT_EQ(mypid, syscall(__NR_getpid));
1263}
1264
1265TEST_F(precedence, log_is_fifth_in_any_order)
1266{
1267 pid_t mypid, parent;
1268 long ret;
1269
1270 mypid = getpid();
1271 parent = getppid();
1272 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
1273 ASSERT_EQ(0, ret);
1274
1275 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->log);
1276 ASSERT_EQ(0, ret);
1277 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->allow);
1278 ASSERT_EQ(0, ret);
1279 /* Should work just fine. */
1280 EXPECT_EQ(parent, syscall(__NR_getppid));
1281 /* Should also work just fine */
1282 EXPECT_EQ(mypid, syscall(__NR_getpid));
1283}
1284
1001#ifndef PTRACE_O_TRACESECCOMP 1285#ifndef PTRACE_O_TRACESECCOMP
1002#define PTRACE_O_TRACESECCOMP 0x00000080 1286#define PTRACE_O_TRACESECCOMP 0x00000080
1003#endif 1287#endif
@@ -1262,6 +1546,13 @@ TEST_F(TRACE_poke, getpid_runs_normally)
1262# error "Do not know how to find your architecture's registers and syscalls" 1546# error "Do not know how to find your architecture's registers and syscalls"
1263#endif 1547#endif
1264 1548
1549/* When the syscall return can't be changed, stub out the tests for it. */
1550#ifdef SYSCALL_NUM_RET_SHARE_REG
1551# define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(-1, action)
1552#else
1553# define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(val, action)
1554#endif
1555
1265/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for 1556/* Use PTRACE_GETREGS and PTRACE_SETREGS when available. This is useful for
1266 * architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux). 1557 * architectures without HAVE_ARCH_TRACEHOOK (e.g. User-mode Linux).
1267 */ 1558 */
@@ -1357,7 +1648,7 @@ void change_syscall(struct __test_metadata *_metadata,
1357#ifdef SYSCALL_NUM_RET_SHARE_REG 1648#ifdef SYSCALL_NUM_RET_SHARE_REG
1358 TH_LOG("Can't modify syscall return on this architecture"); 1649 TH_LOG("Can't modify syscall return on this architecture");
1359#else 1650#else
1360 regs.SYSCALL_RET = 1; 1651 regs.SYSCALL_RET = EPERM;
1361#endif 1652#endif
1362 1653
1363#ifdef HAVE_GETREGS 1654#ifdef HAVE_GETREGS
@@ -1426,6 +1717,8 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
1426 1717
1427 if (nr == __NR_getpid) 1718 if (nr == __NR_getpid)
1428 change_syscall(_metadata, tracee, __NR_getppid); 1719 change_syscall(_metadata, tracee, __NR_getppid);
1720 if (nr == __NR_open)
1721 change_syscall(_metadata, tracee, -1);
1429} 1722}
1430 1723
1431FIXTURE_DATA(TRACE_syscall) { 1724FIXTURE_DATA(TRACE_syscall) {
@@ -1480,6 +1773,28 @@ FIXTURE_TEARDOWN(TRACE_syscall)
1480 free(self->prog.filter); 1773 free(self->prog.filter);
1481} 1774}
1482 1775
1776TEST_F(TRACE_syscall, ptrace_syscall_redirected)
1777{
1778 /* Swap SECCOMP_RET_TRACE tracer for PTRACE_SYSCALL tracer. */
1779 teardown_trace_fixture(_metadata, self->tracer);
1780 self->tracer = setup_trace_fixture(_metadata, tracer_ptrace, NULL,
1781 true);
1782
1783 /* Tracer will redirect getpid to getppid. */
1784 EXPECT_NE(self->mypid, syscall(__NR_getpid));
1785}
1786
1787TEST_F(TRACE_syscall, ptrace_syscall_dropped)
1788{
1789 /* Swap SECCOMP_RET_TRACE tracer for PTRACE_SYSCALL tracer. */
1790 teardown_trace_fixture(_metadata, self->tracer);
1791 self->tracer = setup_trace_fixture(_metadata, tracer_ptrace, NULL,
1792 true);
1793
1794 /* Tracer should skip the open syscall, resulting in EPERM. */
1795 EXPECT_SYSCALL_RETURN(EPERM, syscall(__NR_open));
1796}
1797
1483TEST_F(TRACE_syscall, syscall_allowed) 1798TEST_F(TRACE_syscall, syscall_allowed)
1484{ 1799{
1485 long ret; 1800 long ret;
@@ -1520,13 +1835,8 @@ TEST_F(TRACE_syscall, syscall_dropped)
1520 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->prog, 0, 0); 1835 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &self->prog, 0, 0);
1521 ASSERT_EQ(0, ret); 1836 ASSERT_EQ(0, ret);
1522 1837
1523#ifdef SYSCALL_NUM_RET_SHARE_REG
1524 /* gettid has been skipped */
1525 EXPECT_EQ(-1, syscall(__NR_gettid));
1526#else
1527 /* gettid has been skipped and an altered return value stored. */ 1838 /* gettid has been skipped and an altered return value stored. */
1528 EXPECT_EQ(1, syscall(__NR_gettid)); 1839 EXPECT_SYSCALL_RETURN(EPERM, syscall(__NR_gettid));
1529#endif
1530 EXPECT_NE(self->mytid, syscall(__NR_gettid)); 1840 EXPECT_NE(self->mytid, syscall(__NR_gettid));
1531} 1841}
1532 1842
@@ -1557,6 +1867,7 @@ TEST_F(TRACE_syscall, skip_after_RET_TRACE)
1557 ASSERT_EQ(0, ret); 1867 ASSERT_EQ(0, ret);
1558 1868
1559 /* Tracer will redirect getpid to getppid, and we should see EPERM. */ 1869 /* Tracer will redirect getpid to getppid, and we should see EPERM. */
1870 errno = 0;
1560 EXPECT_EQ(-1, syscall(__NR_getpid)); 1871 EXPECT_EQ(-1, syscall(__NR_getpid));
1561 EXPECT_EQ(EPERM, errno); 1872 EXPECT_EQ(EPERM, errno);
1562} 1873}
@@ -1654,47 +1965,6 @@ TEST_F_SIGNAL(TRACE_syscall, kill_after_ptrace, SIGSYS)
1654 EXPECT_NE(self->mypid, syscall(__NR_getpid)); 1965 EXPECT_NE(self->mypid, syscall(__NR_getpid));
1655} 1966}
1656 1967
1657#ifndef __NR_seccomp
1658# if defined(__i386__)
1659# define __NR_seccomp 354
1660# elif defined(__x86_64__)
1661# define __NR_seccomp 317
1662# elif defined(__arm__)
1663# define __NR_seccomp 383
1664# elif defined(__aarch64__)
1665# define __NR_seccomp 277
1666# elif defined(__hppa__)
1667# define __NR_seccomp 338
1668# elif defined(__powerpc__)
1669# define __NR_seccomp 358
1670# elif defined(__s390__)
1671# define __NR_seccomp 348
1672# else
1673# warning "seccomp syscall number unknown for this architecture"
1674# define __NR_seccomp 0xffff
1675# endif
1676#endif
1677
1678#ifndef SECCOMP_SET_MODE_STRICT
1679#define SECCOMP_SET_MODE_STRICT 0
1680#endif
1681
1682#ifndef SECCOMP_SET_MODE_FILTER
1683#define SECCOMP_SET_MODE_FILTER 1
1684#endif
1685
1686#ifndef SECCOMP_FILTER_FLAG_TSYNC
1687#define SECCOMP_FILTER_FLAG_TSYNC 1
1688#endif
1689
1690#ifndef seccomp
1691int seccomp(unsigned int op, unsigned int flags, void *args)
1692{
1693 errno = 0;
1694 return syscall(__NR_seccomp, op, flags, args);
1695}
1696#endif
1697
1698TEST(seccomp_syscall) 1968TEST(seccomp_syscall)
1699{ 1969{
1700 struct sock_filter filter[] = { 1970 struct sock_filter filter[] = {
@@ -1783,6 +2053,67 @@ TEST(seccomp_syscall_mode_lock)
1783 } 2053 }
1784} 2054}
1785 2055
2056/*
2057 * Test detection of known and unknown filter flags. Userspace needs to be able
2058 * to check if a filter flag is supported by the current kernel and a good way
2059 * of doing that is by attempting to enter filter mode, with the flag bit in
2060 * question set, and a NULL pointer for the _args_ parameter. EFAULT indicates
2061 * that the flag is valid and EINVAL indicates that the flag is invalid.
2062 */
2063TEST(detect_seccomp_filter_flags)
2064{
2065 unsigned int flags[] = { SECCOMP_FILTER_FLAG_TSYNC,
2066 SECCOMP_FILTER_FLAG_LOG };
2067 unsigned int flag, all_flags;
2068 int i;
2069 long ret;
2070
2071 /* Test detection of known-good filter flags */
2072 for (i = 0, all_flags = 0; i < ARRAY_SIZE(flags); i++) {
2073 flag = flags[i];
2074 ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL);
2075 ASSERT_NE(ENOSYS, errno) {
2076 TH_LOG("Kernel does not support seccomp syscall!");
2077 }
2078 EXPECT_EQ(-1, ret);
2079 EXPECT_EQ(EFAULT, errno) {
2080 TH_LOG("Failed to detect that a known-good filter flag (0x%X) is supported!",
2081 flag);
2082 }
2083
2084 all_flags |= flag;
2085 }
2086
2087 /* Test detection of all known-good filter flags */
2088 ret = seccomp(SECCOMP_SET_MODE_FILTER, all_flags, NULL);
2089 EXPECT_EQ(-1, ret);
2090 EXPECT_EQ(EFAULT, errno) {
2091 TH_LOG("Failed to detect that all known-good filter flags (0x%X) are supported!",
2092 all_flags);
2093 }
2094
2095 /* Test detection of an unknown filter flag */
2096 flag = -1;
2097 ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL);
2098 EXPECT_EQ(-1, ret);
2099 EXPECT_EQ(EINVAL, errno) {
2100 TH_LOG("Failed to detect that an unknown filter flag (0x%X) is unsupported!",
2101 flag);
2102 }
2103
2104 /*
2105 * Test detection of an unknown filter flag that may simply need to be
2106 * added to this test
2107 */
2108 flag = flags[ARRAY_SIZE(flags) - 1] << 1;
2109 ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL);
2110 EXPECT_EQ(-1, ret);
2111 EXPECT_EQ(EINVAL, errno) {
2112 TH_LOG("Failed to detect that an unknown filter flag (0x%X) is unsupported! Does a new flag need to be added to this test?",
2113 flag);
2114 }
2115}
2116
1786TEST(TSYNC_first) 2117TEST(TSYNC_first)
1787{ 2118{
1788 struct sock_filter filter[] = { 2119 struct sock_filter filter[] = {
@@ -2421,6 +2752,99 @@ TEST(syscall_restart)
2421 _metadata->passed = 0; 2752 _metadata->passed = 0;
2422} 2753}
2423 2754
2755TEST_SIGNAL(filter_flag_log, SIGSYS)
2756{
2757 struct sock_filter allow_filter[] = {
2758 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
2759 };
2760 struct sock_filter kill_filter[] = {
2761 BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
2762 offsetof(struct seccomp_data, nr)),
2763 BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_getpid, 0, 1),
2764 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL),
2765 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
2766 };
2767 struct sock_fprog allow_prog = {
2768 .len = (unsigned short)ARRAY_SIZE(allow_filter),
2769 .filter = allow_filter,
2770 };
2771 struct sock_fprog kill_prog = {
2772 .len = (unsigned short)ARRAY_SIZE(kill_filter),
2773 .filter = kill_filter,
2774 };
2775 long ret;
2776 pid_t parent = getppid();
2777
2778 ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
2779 ASSERT_EQ(0, ret);
2780
2781 /* Verify that the FILTER_FLAG_LOG flag isn't accepted in strict mode */
2782 ret = seccomp(SECCOMP_SET_MODE_STRICT, SECCOMP_FILTER_FLAG_LOG,
2783 &allow_prog);
2784 ASSERT_NE(ENOSYS, errno) {
2785 TH_LOG("Kernel does not support seccomp syscall!");
2786 }
2787 EXPECT_NE(0, ret) {
2788 TH_LOG("Kernel accepted FILTER_FLAG_LOG flag in strict mode!");
2789 }
2790 EXPECT_EQ(EINVAL, errno) {
2791 TH_LOG("Kernel returned unexpected errno for FILTER_FLAG_LOG flag in strict mode!");
2792 }
2793
2794 /* Verify that a simple, permissive filter can be added with no flags */
2795 ret = seccomp(SECCOMP_SET_MODE_FILTER, 0, &allow_prog);
2796 EXPECT_EQ(0, ret);
2797
2798 /* See if the same filter can be added with the FILTER_FLAG_LOG flag */
2799 ret = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_LOG,
2800 &allow_prog);
2801 ASSERT_NE(EINVAL, errno) {
2802 TH_LOG("Kernel does not support the FILTER_FLAG_LOG flag!");
2803 }
2804 EXPECT_EQ(0, ret);
2805
2806 /* Ensure that the kill filter works with the FILTER_FLAG_LOG flag */
2807 ret = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_LOG,
2808 &kill_prog);
2809 EXPECT_EQ(0, ret);
2810
2811 EXPECT_EQ(parent, syscall(__NR_getppid));
2812 /* getpid() should never return. */
2813 EXPECT_EQ(0, syscall(__NR_getpid));
2814}
2815
2816TEST(get_action_avail)
2817{
2818 __u32 actions[] = { SECCOMP_RET_KILL_THREAD, SECCOMP_RET_TRAP,
2819 SECCOMP_RET_ERRNO, SECCOMP_RET_TRACE,
2820 SECCOMP_RET_LOG, SECCOMP_RET_ALLOW };
2821 __u32 unknown_action = 0x10000000U;
2822 int i;
2823 long ret;
2824
2825 ret = seccomp(SECCOMP_GET_ACTION_AVAIL, 0, &actions[0]);
2826 ASSERT_NE(ENOSYS, errno) {
2827 TH_LOG("Kernel does not support seccomp syscall!");
2828 }
2829 ASSERT_NE(EINVAL, errno) {
2830 TH_LOG("Kernel does not support SECCOMP_GET_ACTION_AVAIL operation!");
2831 }
2832 EXPECT_EQ(ret, 0);
2833
2834 for (i = 0; i < ARRAY_SIZE(actions); i++) {
2835 ret = seccomp(SECCOMP_GET_ACTION_AVAIL, 0, &actions[i]);
2836 EXPECT_EQ(ret, 0) {
2837 TH_LOG("Expected action (0x%X) not available!",
2838 actions[i]);
2839 }
2840 }
2841
2842 /* Check that an unknown action is handled properly (EOPNOTSUPP) */
2843 ret = seccomp(SECCOMP_GET_ACTION_AVAIL, 0, &unknown_action);
2844 EXPECT_EQ(ret, -1);
2845 EXPECT_EQ(errno, EOPNOTSUPP);
2846}
2847
2424/* 2848/*
2425 * TODO: 2849 * TODO:
2426 * - add microbenchmarks 2850 * - add microbenchmarks
@@ -2429,6 +2853,8 @@ TEST(syscall_restart)
2429 * - endianness checking when appropriate 2853 * - endianness checking when appropriate
2430 * - 64-bit arg prodding 2854 * - 64-bit arg prodding
2431 * - arch value testing (x86 modes especially) 2855 * - arch value testing (x86 modes especially)
2856 * - verify that FILTER_FLAG_LOG filters generate log messages
2857 * - verify that RET_LOG generates log messages
2432 * - ... 2858 * - ...
2433 */ 2859 */
2434 2860
diff --git a/tools/testing/selftests/sigaltstack/sas.c b/tools/testing/selftests/sigaltstack/sas.c
index 7d406c3973ba..228c2ae47687 100644
--- a/tools/testing/selftests/sigaltstack/sas.c
+++ b/tools/testing/selftests/sigaltstack/sas.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Stas Sergeev <stsp@users.sourceforge.net> 3 * Stas Sergeev <stsp@users.sourceforge.net>
3 * 4 *
@@ -39,7 +40,11 @@ void my_usr1(int sig, siginfo_t *si, void *u)
39 stack_t stk; 40 stack_t stk;
40 struct stk_data *p; 41 struct stk_data *p;
41 42
43#if __s390x__
44 register unsigned long sp asm("%15");
45#else
42 register unsigned long sp asm("sp"); 46 register unsigned long sp asm("sp");
47#endif
43 48
44 if (sp < (unsigned long)sstack || 49 if (sp < (unsigned long)sstack ||
45 sp >= (unsigned long)sstack + SIGSTKSZ) { 50 sp >= (unsigned long)sstack + SIGSTKSZ) {
diff --git a/tools/testing/selftests/splice/Makefile b/tools/testing/selftests/splice/Makefile
index 7e1187e007fa..e519b159b60d 100644
--- a/tools/testing/selftests/splice/Makefile
+++ b/tools/testing/selftests/splice/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1TEST_PROGS := default_file_splice_read.sh 2TEST_PROGS := default_file_splice_read.sh
2TEST_GEN_PROGS_EXTENDED := default_file_splice_read 3TEST_GEN_PROGS_EXTENDED := default_file_splice_read
3 4
diff --git a/tools/testing/selftests/splice/default_file_splice_read.c b/tools/testing/selftests/splice/default_file_splice_read.c
index 01dd6091554c..a3c6e5672e09 100644
--- a/tools/testing/selftests/splice/default_file_splice_read.c
+++ b/tools/testing/selftests/splice/default_file_splice_read.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <fcntl.h> 3#include <fcntl.h>
3 4
diff --git a/tools/testing/selftests/splice/default_file_splice_read.sh b/tools/testing/selftests/splice/default_file_splice_read.sh
index 1ea2adeabc94..490db5a2e435 100755
--- a/tools/testing/selftests/splice/default_file_splice_read.sh
+++ b/tools/testing/selftests/splice/default_file_splice_read.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2n=`./default_file_splice_read </dev/null | wc -c` 3n=`./default_file_splice_read </dev/null | wc -c`
3 4
4test "$n" = 0 && exit 0 5test "$n" = 0 && exit 0
diff --git a/tools/testing/selftests/static_keys/test_static_keys.sh b/tools/testing/selftests/static_keys/test_static_keys.sh
index 1261e3fa1e3a..24cff498b31a 100755
--- a/tools/testing/selftests/static_keys/test_static_keys.sh
+++ b/tools/testing/selftests/static_keys/test_static_keys.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs static keys kernel module tests 3# Runs static keys kernel module tests
3 4
4if /sbin/modprobe -q test_static_key_base; then 5if /sbin/modprobe -q test_static_key_base; then
diff --git a/tools/testing/selftests/sync/Makefile b/tools/testing/selftests/sync/Makefile
index 4981c6b6d050..b3c8ba3cb668 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -1,13 +1,18 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS += -O2 -g -std=gnu89 -pthread -Wall -Wextra 2CFLAGS += -O2 -g -std=gnu89 -pthread -Wall -Wextra
2CFLAGS += -I../../../../usr/include/ 3CFLAGS += -I../../../../usr/include/
3LDFLAGS += -pthread 4LDFLAGS += -pthread
4 5
5TEST_PROGS = sync_test 6.PHONY: all clean
6
7all: $(TEST_PROGS)
8 7
9include ../lib.mk 8include ../lib.mk
10 9
10# lib.mk TEST_CUSTOM_PROGS var is for custom tests that need special
11# build rules. lib.mk will run and install them.
12
13TEST_CUSTOM_PROGS := $(OUTPUT)/sync_test
14all: $(TEST_CUSTOM_PROGS)
15
11OBJS = sync_test.o sync.o 16OBJS = sync_test.o sync.o
12 17
13TESTS += sync_alloc.o 18TESTS += sync_alloc.o
@@ -18,6 +23,16 @@ TESTS += sync_stress_parallelism.o
18TESTS += sync_stress_consumer.o 23TESTS += sync_stress_consumer.o
19TESTS += sync_stress_merge.o 24TESTS += sync_stress_merge.o
20 25
21sync_test: $(OBJS) $(TESTS) 26OBJS := $(patsubst %,$(OUTPUT)/%,$(OBJS))
27TESTS := $(patsubst %,$(OUTPUT)/%,$(TESTS))
28
29$(TEST_CUSTOM_PROGS): $(TESTS) $(OBJS)
30 $(CC) -o $(TEST_CUSTOM_PROGS) $(OBJS) $(TESTS) $(CFLAGS) $(LDFLAGS)
31
32$(OBJS): $(OUTPUT)/%.o: %.c
33 $(CC) -c $^ -o $@
34
35$(TESTS): $(OUTPUT)/%.o: %.c
36 $(CC) -c $^ -o $@
22 37
23EXTRA_CLEAN := sync_test $(OBJS) $(TESTS) 38EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(OBJS) $(TESTS)
diff --git a/tools/testing/selftests/tc-testing/.gitignore b/tools/testing/selftests/tc-testing/.gitignore
index c18dd8d83cee..7a60b85e148f 100644
--- a/tools/testing/selftests/tc-testing/.gitignore
+++ b/tools/testing/selftests/tc-testing/.gitignore
@@ -1 +1,2 @@
1__pycache__/ 1__pycache__/
2*.pyc
diff --git a/tools/testing/selftests/tc-testing/creating-testcases/AddingTestCases.txt b/tools/testing/selftests/tc-testing/creating-testcases/AddingTestCases.txt
index 4e09257bc443..00438331ba47 100644
--- a/tools/testing/selftests/tc-testing/creating-testcases/AddingTestCases.txt
+++ b/tools/testing/selftests/tc-testing/creating-testcases/AddingTestCases.txt
@@ -34,6 +34,12 @@ category: A list of single-word descriptions covering what the command
34setup: The list of commands required to ensure the command under test 34setup: The list of commands required to ensure the command under test
35 succeeds. For example: if testing a filter, the command to create 35 succeeds. For example: if testing a filter, the command to create
36 the qdisc would appear here. 36 the qdisc would appear here.
37 This list can be empty.
38 Each command can be a string to be executed, or a list consisting
39 of a string which is a command to be executed, followed by 1 or
40 more acceptable exit codes for this command.
41 If only a string is given for the command, then an exit code of 0
42 will be expected.
37cmdUnderTest: The tc command being tested itself. 43cmdUnderTest: The tc command being tested itself.
38expExitCode: The code returned by the command under test upon its termination. 44expExitCode: The code returned by the command under test upon its termination.
39 tdc will compare this value against the actual returned value. 45 tdc will compare this value against the actual returned value.
@@ -49,6 +55,12 @@ matchCount: How many times the regex in matchPattern should match. A value
49teardown: The list of commands to clean up after the test is completed. 55teardown: The list of commands to clean up after the test is completed.
50 The environment should be returned to the same state as when 56 The environment should be returned to the same state as when
51 this test was started: qdiscs deleted, actions flushed, etc. 57 this test was started: qdiscs deleted, actions flushed, etc.
58 This list can be empty.
59 Each command can be a string to be executed, or a list consisting
60 of a string which is a command to be executed, followed by 1 or
61 more acceptable exit codes for this command.
62 If only a string is given for the command, then an exit code of 0
63 will be expected.
52 64
53 65
54SETUP/TEARDOWN ERRORS 66SETUP/TEARDOWN ERRORS
diff --git a/tools/testing/selftests/tc-testing/creating-testcases/example.json b/tools/testing/selftests/tc-testing/creating-testcases/example.json
new file mode 100644
index 000000000000..5ec501200970
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/creating-testcases/example.json
@@ -0,0 +1,55 @@
1[
2 {
3 "id": "1f",
4 "name": "simple test to test framework",
5 "category": [
6 "example"
7 ],
8 "setup": [
9 "mkdir mytest"
10 ],
11 "cmdUnderTest": "touch mytest/blorfl",
12 "expExitCode": "0",
13 "verifyCmd": "ls mytest/* | grep '[b]lorfl'",
14 "matchPattern": "orfl",
15 "matchCount": "1",
16 "teardown": [
17 "rm -rf mytest"
18 ]
19 },
20 {
21 "id": "2f",
22 "name": "simple test, no need for verify",
23 "category": [
24 "example"
25 ],
26 "setup": [
27 "mkdir mytest",
28 "touch mytest/blorfl"
29 ],
30 "cmdUnderTest": "ls mytest/blorfl",
31 "expExitCode": "0",
32 "verifyCmd": "/bin/true",
33 "matchPattern": " ",
34 "matchCount": "0",
35 "teardown": [
36 "rm -rf mytest"
37 ]
38 },
39 {
40 "id": "3f",
41 "name": "simple test, no need for setup or teardown (or verify)",
42 "category": [
43 "example"
44 ],
45 "setup": [
46 ],
47 "cmdUnderTest": "ip l l lo",
48 "expExitCode": "0",
49 "verifyCmd": "/bin/true",
50 "matchPattern": " ",
51 "matchCount": "0",
52 "teardown": [
53 ]
54 }
55]
diff --git a/tools/testing/selftests/tc-testing/creating-testcases/template.json b/tools/testing/selftests/tc-testing/creating-testcases/template.json
index 87971744bdd4..8b99b86d65bd 100644
--- a/tools/testing/selftests/tc-testing/creating-testcases/template.json
+++ b/tools/testing/selftests/tc-testing/creating-testcases/template.json
@@ -26,7 +26,13 @@
26 "" 26 ""
27 ], 27 ],
28 "setup": [ 28 "setup": [
29 "" 29 "",
30 [
31 "",
32 0,
33 1,
34 255
35 ]
30 ], 36 ],
31 "cmdUnderTest": "", 37 "cmdUnderTest": "",
32 "expExitCode": "", 38 "expExitCode": "",
@@ -34,7 +40,12 @@
34 "matchPattern": "", 40 "matchPattern": "",
35 "matchCount": "", 41 "matchCount": "",
36 "teardown": [ 42 "teardown": [
37 "" 43 "",
44 [
45 "",
46 0,
47 255
48 ]
38 ] 49 ]
39 } 50 }
40] 51]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/gact.json b/tools/testing/selftests/tc-testing/tc-tests/actions/gact.json
new file mode 100644
index 000000000000..e2187b6e0b7a
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/gact.json
@@ -0,0 +1,469 @@
1[
2 {
3 "id": "e89a",
4 "name": "Add valid pass action",
5 "category": [
6 "actions",
7 "gact"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action gact",
12 0,
13 1,
14 255
15 ]
16 ],
17 "cmdUnderTest": "$TC actions add action pass index 8",
18 "expExitCode": "0",
19 "verifyCmd": "$TC actions list action gact",
20 "matchPattern": "action order [0-9]*: gact action pass.*index 8 ref",
21 "matchCount": "1",
22 "teardown": [
23 "$TC actions flush action gact"
24 ]
25 },
26 {
27 "id": "a02c",
28 "name": "Add valid pipe action",
29 "category": [
30 "actions",
31 "gact"
32 ],
33 "setup": [
34 [
35 "$TC actions flush action gact",
36 0,
37 1,
38 255
39 ]
40 ],
41 "cmdUnderTest": "$TC actions add action pipe index 6",
42 "expExitCode": "0",
43 "verifyCmd": "$TC actions list action gact",
44 "matchPattern": "action order [0-9]*: gact action pipe.*index 6 ref",
45 "matchCount": "1",
46 "teardown": [
47 "$TC actions flush action gact"
48 ]
49 },
50 {
51 "id": "feef",
52 "name": "Add valid reclassify action",
53 "category": [
54 "actions",
55 "gact"
56 ],
57 "setup": [
58 [
59 "$TC actions flush action gact",
60 0,
61 1,
62 255
63 ]
64 ],
65 "cmdUnderTest": "$TC actions add action reclassify index 5",
66 "expExitCode": "0",
67 "verifyCmd": "$TC actions list action gact",
68 "matchPattern": "action order [0-9]*: gact action reclassify.*index 5 ref",
69 "matchCount": "1",
70 "teardown": [
71 "$TC actions flush action gact"
72 ]
73 },
74 {
75 "id": "8a7a",
76 "name": "Add valid drop action",
77 "category": [
78 "actions",
79 "gact"
80 ],
81 "setup": [
82 [
83 "$TC actions flush action gact",
84 0,
85 1,
86 255
87 ]
88 ],
89 "cmdUnderTest": "$TC actions add action drop index 30",
90 "expExitCode": "0",
91 "verifyCmd": "$TC actions list action gact",
92 "matchPattern": "action order [0-9]*: gact action drop.*index 30 ref",
93 "matchCount": "1",
94 "teardown": [
95 "$TC actions flush action gact"
96 ]
97 },
98 {
99 "id": "9a52",
100 "name": "Add valid continue action",
101 "category": [
102 "actions",
103 "gact"
104 ],
105 "setup": [
106 [
107 "$TC actions flush action gact",
108 0,
109 1,
110 255
111 ]
112 ],
113 "cmdUnderTest": "$TC actions add action continue index 432",
114 "expExitCode": "0",
115 "verifyCmd": "$TC actions list action gact",
116 "matchPattern": "action order [0-9]*: gact action continue.*index 432 ref",
117 "matchCount": "1",
118 "teardown": [
119 "$TC actions flush action gact"
120 ]
121 },
122 {
123 "id": "d700",
124 "name": "Add invalid action",
125 "category": [
126 "actions",
127 "gact"
128 ],
129 "setup": [
130 [
131 "$TC actions flush action gact",
132 0,
133 1,
134 255
135 ]
136 ],
137 "cmdUnderTest": "$TC actions add action pump index 386",
138 "expExitCode": "255",
139 "verifyCmd": "$TC actions list action gact",
140 "matchPattern": "action order [0-9]*: gact action.*index 386 ref",
141 "matchCount": "0",
142 "teardown": [
143 "$TC actions flush action gact"
144 ]
145 },
146 {
147 "id": "9215",
148 "name": "Add action with duplicate index",
149 "category": [
150 "actions",
151 "gact"
152 ],
153 "setup": [
154 [
155 "$TC actions flush action gact",
156 0,
157 1,
158 255
159 ],
160 "$TC actions add action pipe index 15"
161 ],
162 "cmdUnderTest": "$TC actions add action drop index 15",
163 "expExitCode": "255",
164 "verifyCmd": "$TC actions list action gact",
165 "matchPattern": "action order [0-9]*: gact action drop.*index 15 ref",
166 "matchCount": "0",
167 "teardown": [
168 "$TC actions flush action gact"
169 ]
170 },
171 {
172 "id": "798e",
173 "name": "Add action with index exceeding 32-bit maximum",
174 "category": [
175 "actions",
176 "gact"
177 ],
178 "setup": [
179 [
180 "$TC actions flush action gact",
181 0,
182 1,
183 255
184 ]
185 ],
186 "cmdUnderTest": "$TC actions add action drop index 4294967296",
187 "expExitCode": "255",
188 "verifyCmd": "actions list action gact",
189 "matchPattern": "action order [0-9]*: gact action drop.*index 4294967296 ref",
190 "matchCount": "0",
191 "teardown": [
192 "$TC actions flush action gact"
193 ]
194 },
195 {
196 "id": "22be",
197 "name": "Add action with index at 32-bit maximum",
198 "category": [
199 "actions",
200 "gact"
201 ],
202 "setup": [
203 [
204 "$TC actions flush action gact",
205 0,
206 1,
207 255
208 ]
209 ],
210 "cmdUnderTest": "$TC actions add action drop index 4294967295",
211 "expExitCode": "0",
212 "verifyCmd": "$TC actions list action gact",
213 "matchPattern": "action order [0-9]*: gact action drop.*index 4294967295 ref",
214 "matchCount": "1",
215 "teardown": [
216 "$TC actions flush action gact"
217 ]
218 },
219 {
220 "id": "ac2a",
221 "name": "List actions",
222 "category": [
223 "actions",
224 "gact"
225 ],
226 "setup": [
227 [
228 "$TC actions flush action gact",
229 0,
230 1,
231 255
232 ],
233 "$TC actions add action reclassify index 101",
234 "$TC actions add action reclassify index 102",
235 "$TC actions add action reclassify index 103",
236 "$TC actions add action reclassify index 104",
237 "$TC actions add action reclassify index 105"
238 ],
239 "cmdUnderTest": "$TC actions list action gact",
240 "expExitCode": "0",
241 "verifyCmd": "$TC actions list action gact",
242 "matchPattern": "action order [0-9]*: gact action reclassify",
243 "matchCount": "5",
244 "teardown": [
245 "$TC actions flush action gact"
246 ]
247 },
248 {
249 "id": "3edf",
250 "name": "Flush gact actions",
251 "category": [
252 "actions",
253 "gact"
254 ],
255 "setup": [
256 "$TC actions add action reclassify index 101",
257 "$TC actions add action reclassify index 102",
258 "$TC actions add action reclassify index 103",
259 "$TC actions add action reclassify index 104",
260 "$TC actions add action reclassify index 105"
261 ],
262 "cmdUnderTest": "$TC actions flush action gact",
263 "expExitCode": "0",
264 "verifyCmd": "$TC actions list action gact",
265 "matchPattern": "action order [0-9]*: gact action reclassify",
266 "matchCount": "0",
267 "teardown": []
268 },
269 {
270 "id": "63ec",
271 "name": "Delete pass action",
272 "category": [
273 "actions",
274 "gact"
275 ],
276 "setup": [
277 [
278 "$TC actions flush action gact",
279 0,
280 1,
281 255
282 ],
283 "$TC actions add action pass index 1"
284 ],
285 "cmdUnderTest": "$TC actions del action gact index 1",
286 "expExitCode": "0",
287 "verifyCmd": "$TC actions list action gact",
288 "matchPattern": "action order [0-9]*: gact action pass.*index 1 ref",
289 "matchCount": "0",
290 "teardown": [
291 "$TC actions flush action gact"
292 ]
293 },
294 {
295 "id": "46be",
296 "name": "Delete pipe action",
297 "category": [
298 "actions",
299 "gact"
300 ],
301 "setup": [
302 [
303 "$TC actions flush action gact",
304 0,
305 1,
306 255
307 ],
308 "$TC actions add action pipe index 9"
309 ],
310 "cmdUnderTest": "$TC actions del action gact index 9",
311 "expExitCode": "0",
312 "verifyCmd": "$TC actions list action gact",
313 "matchPattern": "action order [0-9]*: gact action pipe.*index 9 ref",
314 "matchCount": "0",
315 "teardown": [
316 "$TC actions flush action gact"
317 ]
318 },
319 {
320 "id": "2e08",
321 "name": "Delete reclassify action",
322 "category": [
323 "actions",
324 "gact"
325 ],
326 "setup": [
327 [
328 "$TC actions flush action gact",
329 0,
330 1,
331 255
332 ],
333 "$TC actions add action reclassify index 65536"
334 ],
335 "cmdUnderTest": "$TC actions del action gact index 65536",
336 "expExitCode": "0",
337 "verifyCmd": "$TC actions list action gact",
338 "matchPattern": "action order [0-9]*: gact action reclassify.*index 65536 ref",
339 "matchCount": "0",
340 "teardown": [
341 "$TC actions flush action gact"
342 ]
343 },
344 {
345 "id": "99c4",
346 "name": "Delete drop action",
347 "category": [
348 "actions",
349 "gact"
350 ],
351 "setup": [
352 [
353 "$TC actions flush action gact",
354 0,
355 1,
356 255
357 ],
358 "$TC actions add action drop index 16"
359 ],
360 "cmdUnderTest": "$TC actions del action gact index 16",
361 "expExitCode": "0",
362 "verifyCmd": "$TC actions list action gact",
363 "matchPattern": "action order [0-9]*: gact action drop.*index 16 ref",
364 "matchCount": "0",
365 "teardown": [
366 "$TC actions flush action gact"
367 ]
368 },
369 {
370 "id": "fb6b",
371 "name": "Delete continue action",
372 "category": [
373 "actions",
374 "gact"
375 ],
376 "setup": [
377 [
378 "$TC actions flush action gact",
379 0,
380 1,
381 255
382 ],
383 "$TC actions add action continue index 32"
384 ],
385 "cmdUnderTest": "$TC actions del action gact index 32",
386 "expExitCode": "0",
387 "verifyCmd": "actions list action gact",
388 "matchPattern": "action order [0-9]*: gact action continue.*index 32 ref",
389 "matchCount": "0",
390 "teardown": [
391 "$TC actions flush action gact"
392 ]
393 },
394 {
395 "id": "0eb3",
396 "name": "Delete non-existent action",
397 "category": [
398 "actions",
399 "gact"
400 ],
401 "setup": [
402 [
403 "$TC actions flush action gact",
404 0,
405 1,
406 255
407 ]
408 ],
409 "cmdUnderTest": "$TC actions del action gact index 2",
410 "expExitCode": "255",
411 "verifyCmd": "$TC actions list action gact",
412 "matchPattern": "action order [0-9]*: gact action",
413 "matchCount": "0",
414 "teardown": [
415 "$TC actions flush action gact"
416 ]
417 },
418 {
419 "id": "f02c",
420 "name": "Replace gact action",
421 "category": [
422 "actions",
423 "gact"
424 ],
425 "setup": [
426 [
427 "$TC actions flush action gact",
428 0,
429 1,
430 255
431 ],
432 "$TC actions add action drop index 10",
433 "$TC actions add action drop index 12"
434 ],
435 "cmdUnderTest": "$TC actions replace action ok index 12",
436 "expExitCode": "0",
437 "verifyCmd": "$TC actions ls action gact",
438 "matchPattern": "action order [0-9]*: gact action pass",
439 "matchCount": "1",
440 "teardown": [
441 "$TC actions flush action gact"
442 ]
443 },
444 {
445 "id": "525f",
446 "name": "Get gact action by index",
447 "category": [
448 "actions",
449 "gact"
450 ],
451 "setup": [
452 [
453 "$TC actions flush action gact",
454 0,
455 1,
456 255
457 ],
458 "$TC actions add action drop index 3900800700"
459 ],
460 "cmdUnderTest": "$TC actions get action gact index 3900800700",
461 "expExitCode": "0",
462 "verifyCmd": "$TC actions get action gact index 3900800700",
463 "matchPattern": "index 3900800700",
464 "matchCount": "1",
465 "teardown": [
466 "$TC actions flush action gact"
467 ]
468 }
469]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json b/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json
new file mode 100644
index 000000000000..9f34f0753969
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/ife.json
@@ -0,0 +1,52 @@
1[
2 {
3 "id": "a568",
4 "name": "Add action with ife type",
5 "category": [
6 "actions",
7 "ife"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action ife",
12 0,
13 1,
14 255
15 ],
16 "$TC actions add action ife encode type 0xDEAD index 1"
17 ],
18 "cmdUnderTest": "$TC actions get action ife index 1",
19 "expExitCode": "0",
20 "verifyCmd": "$TC actions get action ife index 1",
21 "matchPattern": "type 0xDEAD",
22 "matchCount": "1",
23 "teardown": [
24 "$TC actions flush action ife"
25 ]
26 },
27 {
28 "id": "b983",
29 "name": "Add action without ife type",
30 "category": [
31 "actions",
32 "ife"
33 ],
34 "setup": [
35 [
36 "$TC actions flush action ife",
37 0,
38 1,
39 255
40 ],
41 "$TC actions add action ife encode index 1"
42 ],
43 "cmdUnderTest": "$TC actions get action ife index 1",
44 "expExitCode": "0",
45 "verifyCmd": "$TC actions get action ife index 1",
46 "matchPattern": "type 0xED3E",
47 "matchCount": "1",
48 "teardown": [
49 "$TC actions flush action ife"
50 ]
51 }
52]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/mirred.json b/tools/testing/selftests/tc-testing/tc-tests/actions/mirred.json
new file mode 100644
index 000000000000..0fcccf18399b
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/mirred.json
@@ -0,0 +1,223 @@
1[
2 {
3 "id": "5124",
4 "name": "Add mirred mirror to egress action",
5 "category": [
6 "actions",
7 "mirred"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action mirred",
12 0,
13 1,
14 255
15 ]
16 ],
17 "cmdUnderTest": "$TC actions add action mirred egress mirror index 1 dev lo",
18 "expExitCode": "0",
19 "verifyCmd": "$TC actions list action mirred",
20 "matchPattern": "action order [0-9]*: mirred \\(Egress Mirror to device lo\\).*index 1 ref",
21 "matchCount": "1",
22 "teardown": [
23 "$TC actions flush action mirred"
24 ]
25 },
26 {
27 "id": "6fb4",
28 "name": "Add mirred redirect to egress action",
29 "category": [
30 "actions",
31 "mirred"
32 ],
33 "setup": [
34 [
35 "$TC actions flush action mirred",
36 0,
37 1,
38 255
39 ]
40 ],
41 "cmdUnderTest": "$TC actions add action mirred egress redirect index 2 dev lo action pipe",
42 "expExitCode": "0",
43 "verifyCmd": "$TC actions list action mirred",
44 "matchPattern": "action order [0-9]*: mirred \\(Egress Redirect to device lo\\).*index 2 ref",
45 "matchCount": "1",
46 "teardown": [
47 "$TC actions flush action mirred"
48 ]
49 },
50 {
51 "id": "ba38",
52 "name": "Get mirred actions",
53 "category": [
54 "actions",
55 "mirred"
56 ],
57 "setup": [
58 [
59 "$TC actions flush action mirred",
60 0,
61 1,
62 255
63 ],
64 "$TC actions add action mirred egress mirror index 1 dev lo",
65 "$TC actions add action mirred egress redirect index 2 dev lo"
66 ],
67 "cmdUnderTest": "$TC actions show action mirred",
68 "expExitCode": "0",
69 "verifyCmd": "$TC actions list action mirred",
70 "matchPattern": "[Mirror|Redirect] to device lo",
71 "matchCount": "2",
72 "teardown": [
73 "$TC actions flush action mirred"
74 ]
75 },
76 {
77 "id": "d7c0",
78 "name": "Add invalid mirred direction",
79 "category": [
80 "actions",
81 "mirred"
82 ],
83 "setup": [
84 [
85 "$TC actions flush action mirred",
86 0,
87 1,
88 255
89 ]
90 ],
91 "cmdUnderTest": "$TC actions add action mirred inbound mirror index 20 dev lo",
92 "expExitCode": "255",
93 "verifyCmd": "$TC actions list action mirred",
94 "matchPattern": "action order [0-9]*: mirred \\(.*to device lo\\).*index 20 ref",
95 "matchCount": "0",
96 "teardown": [
97 "$TC actions flush action mirred"
98 ]
99 },
100 {
101 "id": "e213",
102 "name": "Add invalid mirred action",
103 "category": [
104 "actions",
105 "mirred"
106 ],
107 "setup": [
108 [
109 "$TC actions flush action mirred",
110 0,
111 1,
112 255
113 ]
114 ],
115 "cmdUnderTest": "$TC actions add action mirred egress remirror index 20 dev lo",
116 "expExitCode": "255",
117 "verifyCmd": "$TC actions list action mirred",
118 "matchPattern": "action order [0-9]*: mirred \\(Egress.*to device lo\\).*index 20 ref",
119 "matchCount": "0",
120 "teardown": [
121 "$TC actions flush action mirred"
122 ]
123 },
124 {
125 "id": "2d89",
126 "name": "Add mirred action with invalid device",
127 "category": [
128 "actions",
129 "mirred"
130 ],
131 "setup": [
132 [
133 "$TC actions flush action mirred",
134 0,
135 1,
136 255
137 ]
138 ],
139 "cmdUnderTest": "$TC actions add action mirred egress mirror index 20 dev eltoh",
140 "expExitCode": "255",
141 "verifyCmd": "$TC actions list action mirred",
142 "matchPattern": "action order [0-9]*: mirred \\(.*to device eltoh\\).*index 20 ref",
143 "matchCount": "0",
144 "teardown": [
145 "$TC actions flush action mirred"
146 ]
147 },
148 {
149 "id": "300b",
150 "name": "Add mirred action with duplicate index",
151 "category": [
152 "actions",
153 "mirred"
154 ],
155 "setup": [
156 [
157 "$TC actions flush action mirred",
158 0,
159 1,
160 255
161 ],
162 "$TC actions add action mirred egress redirect index 15 dev lo"
163 ],
164 "cmdUnderTest": "$TC actions add action mirred egress mirror index 15 dev lo",
165 "expExitCode": "255",
166 "verifyCmd": "$TC actions list action mirred",
167 "matchPattern": "action order [0-9]*: mirred \\(.*to device lo\\).*index 15 ref",
168 "matchCount": "1",
169 "teardown": [
170 "$TC actions flush action mirred"
171 ]
172 },
173 {
174 "id": "a70e",
175 "name": "Delete mirred mirror action",
176 "category": [
177 "actions",
178 "mirred"
179 ],
180 "setup": [
181 [
182 "$TC actions flush action mirred",
183 0,
184 1,
185 255
186 ],
187 "$TC actions add action mirred egress mirror index 5 dev lo"
188 ],
189 "cmdUnderTest": "$TC actions del action mirred index 5",
190 "expExitCode": "0",
191 "verifyCmd": "$TC actions list action mirred",
192 "matchPattern": "action order [0-9]*: mirred \\(Egress Mirror to device lo\\).*index 5 ref",
193 "matchCount": "0",
194 "teardown": [
195 "$TC actions flush action mirred"
196 ]
197 },
198 {
199 "id": "3fb3",
200 "name": "Delete mirred redirect action",
201 "category": [
202 "actions",
203 "mirred"
204 ],
205 "setup": [
206 [
207 "$TC actions flush action mirred",
208 0,
209 1,
210 255
211 ],
212 "$TC actions add action mirred egress redirect index 5 dev lo"
213 ],
214 "cmdUnderTest": "$TC actions del action mirred index 5",
215 "expExitCode": "0",
216 "verifyCmd": "$TC actions list action mirred",
217 "matchPattern": "action order [0-9]*: mirred \\(Egress Redirect to device lo\\).*index 5 ref",
218 "matchCount": "0",
219 "teardown": [
220 "$TC actions flush action mirred"
221 ]
222 }
223]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/police.json b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
new file mode 100644
index 000000000000..0e602a3f9393
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
@@ -0,0 +1,527 @@
1[
2 {
3 "id": "49aa",
4 "name": "Add valid basic police action",
5 "category": [
6 "actions",
7 "police"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action police",
12 0,
13 1,
14 255
15 ]
16 ],
17 "cmdUnderTest": "$TC actions add action police rate 1kbit burst 10k index 1",
18 "expExitCode": "0",
19 "verifyCmd": "$TC actions ls action police",
20 "matchPattern": "action order [0-9]*: police 0x1 rate 1Kbit burst 10Kb",
21 "matchCount": "1",
22 "teardown": [
23 "$TC actions flush action police"
24 ]
25 },
26 {
27 "id": "3abe",
28 "name": "Add police action with duplicate index",
29 "category": [
30 "actions",
31 "police"
32 ],
33 "setup": [
34 [
35 "$TC actions flush action police",
36 0,
37 1,
38 255
39 ],
40 "$TC actions add action police rate 4Mbit burst 120k index 9"
41 ],
42 "cmdUnderTest": "$TC actions add action police rate 8kbit burst 24k index 9",
43 "expExitCode": "255",
44 "verifyCmd": "$TC actions ls action police",
45 "matchPattern": "action order [0-9]*: police 0x9",
46 "matchCount": "1",
47 "teardown": [
48 "$TC actions flush action police"
49 ]
50 },
51 {
52 "id": "49fa",
53 "name": "Add valid police action with mtu",
54 "category": [
55 "actions",
56 "police"
57 ],
58 "setup": [
59 [
60 "$TC actions flush action police",
61 0,
62 1,
63 255
64 ]
65 ],
66 "cmdUnderTest": "$TC actions add action police rate 90kbit burst 10k mtu 1k index 98",
67 "expExitCode": "0",
68 "verifyCmd": "$TC actions get action police index 98",
69 "matchPattern": "action order [0-9]*: police 0x62 rate 90Kbit burst 10Kb mtu 1Kb",
70 "matchCount": "1",
71 "teardown": [
72 "$TC actions flush action police"
73 ]
74 },
75 {
76 "id": "7943",
77 "name": "Add valid police action with peakrate",
78 "category": [
79 "actions",
80 "police"
81 ],
82 "setup": [
83 [
84 "$TC actions flush action police",
85 0,
86 1,
87 255
88 ]
89 ],
90 "cmdUnderTest": "$TC actions add action police rate 90kbit burst 10k mtu 2kb peakrate 100kbit index 3",
91 "expExitCode": "0",
92 "verifyCmd": "$TC actions ls action police",
93 "matchPattern": "action order [0-9]*: police 0x3 rate 90Kbit burst 10Kb mtu 2Kb peakrate 100Kbit",
94 "matchCount": "1",
95 "teardown": [
96 "$TC actions flush action police"
97 ]
98 },
99 {
100 "id": "055e",
101 "name": "Add police action with peakrate and no mtu",
102 "category": [
103 "actions",
104 "police"
105 ],
106 "setup": [
107 [
108 "$TC actions flush action police",
109 0,
110 1,
111 255
112 ]
113 ],
114 "cmdUnderTest": "$TC actions add action police rate 5kbit burst 6kb peakrate 10kbit index 9",
115 "expExitCode": "255",
116 "verifyCmd": "$TC actions ls action police",
117 "matchPattern": "action order [0-9]*: police 0x9 rate 5Kb burst 10Kb",
118 "matchCount": "0",
119 "teardown": [
120 "$TC actions flush action police"
121 ]
122 },
123 {
124 "id": "f057",
125 "name": "Add police action with valid overhead",
126 "category": [
127 "actions",
128 "police"
129 ],
130 "setup": [
131 [
132 "$TC actions flush action police",
133 0,
134 1,
135 255
136 ]
137 ],
138 "cmdUnderTest": "$TC actions add action police rate 1mbit burst 100k overhead 64 index 64",
139 "expExitCode": "0",
140 "verifyCmd": "$TC actions get action police index 64",
141 "matchPattern": "action order [0-9]*: police 0x40 rate 1Mbit burst 100Kb mtu 2Kb action reclassify overhead 64b",
142 "matchCount": "1",
143 "teardown": [
144 "$TC actions flush action police"
145 ]
146 },
147 {
148 "id": "7ffb",
149 "name": "Add police action with ethernet linklayer type",
150 "category": [
151 "actions",
152 "police"
153 ],
154 "setup": [
155 [
156 "$TC actions flush action police",
157 0,
158 1,
159 255
160 ]
161 ],
162 "cmdUnderTest": "$TC actions add action police rate 2mbit burst 200k linklayer ethernet index 8",
163 "expExitCode": "0",
164 "verifyCmd": "$TC actions show action police",
165 "matchPattern": "action order [0-9]*: police 0x8 rate 2Mbit burst 200Kb mtu 2Kb action reclassify overhead 0b",
166 "matchCount": "1",
167 "teardown": [
168 "$TC actions flush action police"
169 ]
170 },
171 {
172 "id": "3dda",
173 "name": "Add police action with atm linklayer type",
174 "category": [
175 "actions",
176 "police"
177 ],
178 "setup": [
179 [
180 "$TC actions flush action police",
181 0,
182 1,
183 255
184 ]
185 ],
186 "cmdUnderTest": "$TC actions add action police rate 2mbit burst 200k linklayer atm index 8",
187 "expExitCode": "0",
188 "verifyCmd": "$TC actions show action police",
189 "matchPattern": "action order [0-9]*: police 0x8 rate 2Mbit burst 200Kb mtu 2Kb action reclassify overhead 0b linklayer atm",
190 "matchCount": "1",
191 "teardown": [
192 "$TC actions flush action police"
193 ]
194 },
195 {
196 "id": "551b",
197 "name": "Add police actions with conform-exceed control continue/drop",
198 "category": [
199 "actions",
200 "police"
201 ],
202 "setup": [
203 [
204 "$TC actions flush action police",
205 0,
206 1,
207 255
208 ]
209 ],
210 "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed continue/drop index 1",
211 "expExitCode": "0",
212 "verifyCmd": "$TC actions get action police index 1",
213 "matchPattern": "action order [0-9]*: police 0x1 rate 3Mbit burst 250Kb mtu 2Kb action continue/drop",
214 "matchCount": "1",
215 "teardown": [
216 "$TC actions flush action police"
217 ]
218 },
219 {
220 "id": "0c70",
221 "name": "Add police actions with conform-exceed control pass/reclassify",
222 "category": [
223 "actions",
224 "police"
225 ],
226 "setup": [
227 [
228 "$TC actions flush action police",
229 0,
230 1,
231 255
232 ]
233 ],
234 "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed pass/reclassify index 4",
235 "expExitCode": "0",
236 "verifyCmd": "$TC actions ls action police",
237 "matchPattern": "action order [0-9]*: police 0x4 rate 3Mbit burst 250Kb mtu 2Kb action pass/reclassify",
238 "matchCount": "1",
239 "teardown": [
240 "$TC actions flush action police"
241 ]
242 },
243 {
244 "id": "d946",
245 "name": "Add police actions with conform-exceed control pass/pipe",
246 "category": [
247 "actions",
248 "police"
249 ],
250 "setup": [
251 [
252 "$TC actions flush action police",
253 0,
254 1,
255 255
256 ]
257 ],
258 "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed pass/pipe index 5",
259 "expExitCode": "0",
260 "verifyCmd": "$TC actions ls action police",
261 "matchPattern": "action order [0-9]*: police 0x5 rate 3Mbit burst 250Kb mtu 2Kb action pass/pipe",
262 "matchCount": "1",
263 "teardown": [
264 "$TC actions flush action police"
265 ]
266 },
267 {
268 "id": "336e",
269 "name": "Delete police action",
270 "category": [
271 "actions",
272 "police"
273 ],
274 "setup": [
275 [
276 "$TC actions flush action police",
277 0,
278 1,
279 255
280 ],
281 "$TC actions add action police rate 5mbit burst 2m index 12"
282 ],
283 "cmdUnderTest": "$TC actions delete action police index 12",
284 "expExitCode": "0",
285 "verifyCmd": "$TC actions ls action police",
286 "matchPattern": "action order [0-9]*: police 0xc rate 5Mb burst 2Mb",
287 "matchCount": "0",
288 "teardown": [
289 "$TC actions flush action police"
290 ]
291 },
292 {
293 "id": "77fa",
294 "name": "Get single police action from many actions",
295 "category": [
296 "actions",
297 "police"
298 ],
299 "setup": [
300 [
301 "$TC actions flush action police",
302 0,
303 1,
304 255
305 ],
306 "$TC actions add action police rate 1mbit burst 100k index 1",
307 "$TC actions add action police rate 2mbit burst 200k index 2",
308 "$TC actions add action police rate 3mbit burst 300k index 3",
309 "$TC actions add action police rate 4mbit burst 400k index 4",
310 "$TC actions add action police rate 5mbit burst 500k index 5",
311 "$TC actions add action police rate 6mbit burst 600k index 6",
312 "$TC actions add action police rate 7mbit burst 700k index 7",
313 "$TC actions add action police rate 8mbit burst 800k index 8"
314 ],
315 "cmdUnderTest": "$TC actions get action police index 4",
316 "expExitCode": "0",
317 "verifyCmd": "$TC actions get action police index 4",
318 "matchPattern": "action order [0-9]*: police 0x4 rate 4Mbit burst 400Kb",
319 "matchCount": "1",
320 "teardown": [
321 "$TC actions flush action police"
322 ]
323 },
324 {
325 "id": "aa43",
326 "name": "Get single police action without specifying index",
327 "category": [
328 "actions",
329 "police"
330 ],
331 "setup": [
332 [
333 "$TC actions flush action police",
334 0,
335 1,
336 255
337 ],
338 "$TC actions add action police rate 1mbit burst 100k index 1"
339 ],
340 "cmdUnderTest": "$TC actions get action police",
341 "expExitCode": "255",
342 "verifyCmd": "$TC actions get action police",
343 "matchPattern": "action order [0-9]*: police",
344 "matchCount": "0",
345 "teardown": [
346 "$TC actions flush action police"
347 ]
348 },
349 {
350 "id": "858b",
351 "name": "List police actions",
352 "category": [
353 "actions",
354 "police"
355 ],
356 "setup": [
357 [
358 "$TC actions flush action police",
359 0,
360 1,
361 255
362 ],
363 "$TC actions add action police rate 1mbit burst 100k index 1",
364 "$TC actions add action police rate 2mbit burst 200k index 2",
365 "$TC actions add action police rate 3mbit burst 300k index 3",
366 "$TC actions add action police rate 4mbit burst 400k index 4",
367 "$TC actions add action police rate 5mbit burst 500k index 5",
368 "$TC actions add action police rate 6mbit burst 600k index 6",
369 "$TC actions add action police rate 7mbit burst 700k index 7",
370 "$TC actions add action police rate 8mbit burst 800k index 8"
371 ],
372 "cmdUnderTest": "$TC actions list action police",
373 "expExitCode": "0",
374 "verifyCmd": "$TC actions ls action police",
375 "matchPattern": "action order [0-9]*: police 0x[1-8] rate [1-8]Mbit burst [1-8]00Kb",
376 "matchCount": "8",
377 "teardown": [
378 "$TC actions flush action police"
379 ]
380 },
381 {
382 "id": "1c3a",
383 "name": "Flush police actions",
384 "category": [
385 "actions",
386 "police"
387 ],
388 "setup": [
389 "$TC actions add action police rate 1mbit burst 100k index 1",
390 "$TC actions add action police rate 2mbit burst 200k index 2",
391 "$TC actions add action police rate 3mbit burst 300k index 3",
392 "$TC actions add action police rate 4mbit burst 400k index 4",
393 "$TC actions add action police rate 5mbit burst 500k index 5",
394 "$TC actions add action police rate 6mbit burst 600k index 6",
395 "$TC actions add action police rate 7mbit burst 700k index 7",
396 "$TC actions add action police rate 8mbit burst 800k index 8"
397 ],
398 "cmdUnderTest": "$TC actions flush action police",
399 "expExitCode": "0",
400 "verifyCmd": "$TC actions ls action police",
401 "matchPattern": "action order [0-9]*: police",
402 "matchCount": "0",
403 "teardown": [
404 ""
405 ]
406 },
407 {
408 "id": "7326",
409 "name": "Add police action with control continue",
410 "category": [
411 "actions",
412 "police"
413 ],
414 "setup": [
415 [
416 "$TC actions flush action police",
417 0,
418 1,
419 255
420 ]
421 ],
422 "cmdUnderTest": "$TC actions add action police rate 7mbit burst 1m continue index 1",
423 "expExitCode": "0",
424 "verifyCmd": "$TC actions get action police index 1",
425 "matchPattern": "action order [0-9]*: police 0x1 rate 7Mbit burst 1024Kb mtu 2Kb action continue",
426 "matchCount": "1",
427 "teardown": [
428 "$TC actions flush action police"
429 ]
430 },
431 {
432 "id": "34fa",
433 "name": "Add police action with control drop",
434 "category": [
435 "actions",
436 "police"
437 ],
438 "setup": [
439 [
440 "$TC actions flush action police",
441 0,
442 1,
443 255
444 ]
445 ],
446 "cmdUnderTest": "$TC actions add action police rate 7mbit burst 1m drop index 1",
447 "expExitCode": "0",
448 "verifyCmd": "$TC actions ls action police",
449 "matchPattern": "action order [0-9]*: police 0x1 rate 7Mbit burst 1024Kb mtu 2Kb action drop",
450 "matchCount": "1",
451 "teardown": [
452 "$TC actions flush action police"
453 ]
454 },
455 {
456 "id": "8dd5",
457 "name": "Add police action with control ok",
458 "category": [
459 "actions",
460 "police"
461 ],
462 "setup": [
463 [
464 "$TC actions flush action police",
465 0,
466 1,
467 255
468 ]
469 ],
470 "cmdUnderTest": "$TC actions add action police rate 7mbit burst 1m ok index 1",
471 "expExitCode": "0",
472 "verifyCmd": "$TC actions ls action police",
473 "matchPattern": "action order [0-9]*: police 0x1 rate 7Mbit burst 1024Kb mtu 2Kb action pass",
474 "matchCount": "1",
475 "teardown": [
476 "$TC actions flush action police"
477 ]
478 },
479 {
480 "id": "b9d1",
481 "name": "Add police action with control reclassify",
482 "category": [
483 "actions",
484 "police"
485 ],
486 "setup": [
487 [
488 "$TC actions flush action police",
489 0,
490 1,
491 255
492 ]
493 ],
494 "cmdUnderTest": "$TC actions add action police rate 7mbit burst 1m reclassify index 1",
495 "expExitCode": "0",
496 "verifyCmd": "$TC actions get action police index 1",
497 "matchPattern": "action order [0-9]*: police 0x1 rate 7Mbit burst 1024Kb mtu 2Kb action reclassify",
498 "matchCount": "1",
499 "teardown": [
500 "$TC actions flush action police"
501 ]
502 },
503 {
504 "id": "c534",
505 "name": "Add police action with control pipe",
506 "category": [
507 "actions",
508 "police"
509 ],
510 "setup": [
511 [
512 "$TC actions flush action police",
513 0,
514 1,
515 255
516 ]
517 ],
518 "cmdUnderTest": "$TC actions add action police rate 7mbit burst 1m pipe index 1",
519 "expExitCode": "0",
520 "verifyCmd": "$TC actions ls action police",
521 "matchPattern": "action order [0-9]*: police 0x1 rate 7Mbit burst 1024Kb mtu 2Kb action pipe",
522 "matchCount": "1",
523 "teardown": [
524 "$TC actions flush action police"
525 ]
526 }
527]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/simple.json b/tools/testing/selftests/tc-testing/tc-tests/actions/simple.json
new file mode 100644
index 000000000000..e89a7aa4012d
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/simple.json
@@ -0,0 +1,130 @@
1[
2 {
3 "id": "b078",
4 "name": "Add simple action",
5 "category": [
6 "actions",
7 "simple"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action simple",
12 0,
13 1,
14 255
15 ]
16 ],
17 "cmdUnderTest": "$TC actions add action simple sdata \"A triumph\" index 60",
18 "expExitCode": "0",
19 "verifyCmd": "$TC actions list action simple",
20 "matchPattern": "action order [0-9]*: Simple <A triumph>.*index 60 ref",
21 "matchCount": "1",
22 "teardown": [
23 "$TC actions flush action simple"
24 ]
25 },
26 {
27 "id": "6d4c",
28 "name": "Add simple action with duplicate index",
29 "category": [
30 "actions",
31 "simple"
32 ],
33 "setup": [
34 [
35 "$TC actions flush action simple",
36 0,
37 1,
38 255
39 ],
40 "$TC actions add action simple sdata \"Aruba\" index 4"
41 ],
42 "cmdUnderTest": "$TC actions add action simple sdata \"Jamaica\" index 4",
43 "expExitCode": "255",
44 "verifyCmd": "$TC actions list action simple",
45 "matchPattern": "action order [0-9]*: Simple <Jamaica>.*ref",
46 "matchCount": "0",
47 "teardown": [
48 "$TC actions flush action simple"
49 ]
50 },
51 {
52 "id": "2542",
53 "name": "List simple actions",
54 "category": [
55 "actions",
56 "simple"
57 ],
58 "setup": [
59 [
60 "$TC actions flush action simple",
61 0,
62 1,
63 255
64 ],
65 "$TC actions add action simple sdata \"Rock\"",
66 "$TC actions add action simple sdata \"Paper\"",
67 "$TC actions add action simple sdata \"Scissors\" index 98"
68 ],
69 "cmdUnderTest": "$TC actions list action simple",
70 "expExitCode": "0",
71 "verifyCmd": "$TC actions list action simple",
72 "matchPattern": "action order [0-9]*: Simple <[A-Z][a-z]*>",
73 "matchCount": "3",
74 "teardown": [
75 "$TC actions flush action simple"
76 ]
77 },
78 {
79 "id": "ea67",
80 "name": "Delete simple action",
81 "category": [
82 "actions",
83 "simple"
84 ],
85 "setup": [
86 [
87 "$TC actions flush action simple",
88 0,
89 1,
90 255
91 ],
92 "$TC actions add action simple sdata \"Blinkenlights\" index 1"
93 ],
94 "cmdUnderTest": "$TC actions delete action simple index 1",
95 "expExitCode": "0",
96 "verifyCmd": "$TC actions list action simple",
97 "matchPattern": "action order [0-9]*: Simple <Blinkenlights>.*index 1 ref",
98 "matchCount": "0",
99 "teardown": [
100 "$TC actions flush action simple"
101 ]
102 },
103 {
104 "id": "8ff1",
105 "name": "Flush simple actions",
106 "category": [
107 "actions",
108 "simple"
109 ],
110 "setup": [
111 [
112 "$TC actions flush action simple",
113 0,
114 1,
115 255
116 ],
117 "$TC actions add action simple sdata \"Kirk\"",
118 "$TC actions add action simple sdata \"Spock\" index 50",
119 "$TC actions add action simple sdata \"McCoy\" index 9"
120 ],
121 "cmdUnderTest": "$TC actions flush action simple",
122 "expExitCode": "0",
123 "verifyCmd": "$TC actions list action simple",
124 "matchPattern": "action order [0-9]*: Simple <[A-Z][a-z]*>",
125 "matchCount": "0",
126 "teardown": [
127 ""
128 ]
129 }
130]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/skbedit.json b/tools/testing/selftests/tc-testing/tc-tests/actions/skbedit.json
new file mode 100644
index 000000000000..99635ea4722e
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/skbedit.json
@@ -0,0 +1,320 @@
1[
2 {
3 "id": "6236",
4 "name": "Add skbedit action with valid mark",
5 "category": [
6 "actions",
7 "skbedit"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action skbedit",
12 0,
13 1,
14 255
15 ]
16 ],
17 "cmdUnderTest": "$TC actions add action skbedit mark 1",
18 "expExitCode": "0",
19 "verifyCmd": "$TC actions list action skbedit",
20 "matchPattern": "action order [0-9]*: skbedit mark 1",
21 "matchCount": "1",
22 "teardown": [
23 "$TC actions flush action skbedit"
24 ]
25 },
26 {
27 "id": "407b",
28 "name": "Add skbedit action with invalid mark",
29 "category": [
30 "actions",
31 "skbedit"
32 ],
33 "setup": [
34 [
35 "$TC actions flush action skbedit",
36 0,
37 1,
38 255
39 ]
40 ],
41 "cmdUnderTest": "$TC actions add action skbedit mark 666777888999",
42 "expExitCode": "255",
43 "verifyCmd": "$TC actions list action skbedit",
44 "matchPattern": "action order [0-9]*: skbedit mark",
45 "matchCount": "0",
46 "teardown": [
47 "$TC actions flush action skbedit"
48 ]
49 },
50 {
51 "id": "081d",
52 "name": "Add skbedit action with priority",
53 "category": [
54 "actions",
55 "skbedit"
56 ],
57 "setup": [
58 [
59 "$TC actions flush action skbedit",
60 0,
61 1,
62 255
63 ]
64 ],
65 "cmdUnderTest": "$TC actions add action skbedit prio 99",
66 "expExitCode": "0",
67 "verifyCmd": "$TC actions list action skbedit",
68 "matchPattern": "action order [0-9]*: skbedit priority :99",
69 "matchCount": "1",
70 "teardown": [
71 "$TC actions flush action skbedit"
72 ]
73 },
74 {
75 "id": "cc37",
76 "name": "Add skbedit action with invalid priority",
77 "category": [
78 "actions",
79 "skbedit"
80 ],
81 "setup": [
82 [
83 "$TC actions flush action skbedit",
84 0,
85 1,
86 255
87 ]
88 ],
89 "cmdUnderTest": "$TC actions add action skbedit prio foo",
90 "expExitCode": "255",
91 "verifyCmd": "$TC actions list action skbedit",
92 "matchPattern": "action order [0-9]*: skbedit priority",
93 "matchCount": "0",
94 "teardown": [
95 "$TC actions flush action skbedit"
96 ]
97 },
98 {
99 "id": "3c95",
100 "name": "Add skbedit action with queue_mapping",
101 "category": [
102 "actions",
103 "skbedit"
104 ],
105 "setup": [
106 [
107 "$TC actions flush action skbedit",
108 0,
109 1,
110 255
111 ]
112 ],
113 "cmdUnderTest": "$TC actions add action skbedit queue_mapping 909",
114 "expExitCode": "0",
115 "verifyCmd": "$TC actions list action skbedit",
116 "matchPattern": "action order [0-9]*: skbedit queue_mapping 909",
117 "matchCount": "1",
118 "teardown": [
119 "$TC actions flush action skbedit"
120 ]
121 },
122 {
123 "id": "985c",
124 "name": "Add skbedit action with invalid queue_mapping",
125 "category": [
126 "actions",
127 "skbedit"
128 ],
129 "setup": [
130 [
131 "$TC actions flush action skbedit",
132 0,
133 1,
134 255
135 ]
136 ],
137 "cmdUnderTest": "$TC actions add action skbedit queue_mapping 67000",
138 "expExitCode": "255",
139 "verifyCmd": "$TC actions list action skbedit",
140 "matchPattern": "action order [0-9]*: skbedit queue_mapping",
141 "matchCount": "0",
142 "teardown": [
143 "$TC actions flush action skbedit"
144 ]
145 },
146 {
147 "id": "224f",
148 "name": "Add skbedit action with ptype host",
149 "category": [
150 "actions",
151 "skbedit"
152 ],
153 "setup": [
154 [
155 "$TC actions flush action skbedit",
156 0,
157 1,
158 255
159 ]
160 ],
161 "cmdUnderTest": "$TC actions add action skbedit ptype host",
162 "expExitCode": "0",
163 "verifyCmd": "$TC actions list action skbedit",
164 "matchPattern": "action order [0-9]*: skbedit ptype host",
165 "matchCount": "1",
166 "teardown": [
167 "$TC actions flush action skbedit"
168 ]
169 },
170 {
171 "id": "d1a3",
172 "name": "Add skbedit action with ptype otherhost",
173 "category": [
174 "actions",
175 "skbedit"
176 ],
177 "setup": [
178 [
179 "$TC actions flush action skbedit",
180 0,
181 1,
182 255
183 ]
184 ],
185 "cmdUnderTest": "$TC actions add action skbedit ptype otherhost",
186 "expExitCode": "0",
187 "verifyCmd": "$TC actions list action skbedit",
188 "matchPattern": "action order [0-9]*: skbedit ptype otherhost",
189 "matchCount": "1",
190 "teardown": [
191 "$TC actions flush action skbedit"
192 ]
193 },
194 {
195 "id": "b9c6",
196 "name": "Add skbedit action with invalid ptype",
197 "category": [
198 "actions",
199 "skbedit"
200 ],
201 "setup": [
202 [
203 "$TC actions flush action skbedit",
204 0,
205 1,
206 255
207 ]
208 ],
209 "cmdUnderTest": "$TC actions add action skbedit ptype openair",
210 "expExitCode": "255",
211 "verifyCmd": "$TC actions list action skbedit",
212 "matchPattern": "action order [0-9]*: skbedit ptype openair",
213 "matchCount": "0",
214 "teardown": [
215 "$TC actions flush action skbedit"
216 ]
217 },
218 {
219 "id": "5172",
220 "name": "List skbedit actions",
221 "category": [
222 "actions",
223 "skbedit"
224 ],
225 "setup": [
226 [
227 "$TC actions flush action skbedit",
228 0,
229 1,
230 255
231 ],
232 "$TC actions add action skbedit ptype otherhost",
233 "$TC actions add action skbedit ptype broadcast",
234 "$TC actions add action skbedit mark 59",
235 "$TC actions add action skbedit mark 409"
236 ],
237 "cmdUnderTest": "$TC actions list action skbedit",
238 "expExitCode": "0",
239 "verifyCmd": "$TC actions list action skbedit",
240 "matchPattern": "action order [0-9]*: skbedit",
241 "matchCount": "4",
242 "teardown": [
243 "$TC actions flush action skbedit"
244 ]
245 },
246 {
247 "id": "a6d6",
248 "name": "Add skbedit action with index",
249 "category": [
250 "actions",
251 "skbedit"
252 ],
253 "setup": [
254 [
255 "$TC actions flush action skbedit",
256 0,
257 1,
258 255
259 ]
260 ],
261 "cmdUnderTest": "$TC actions add action skbedit mark 808 index 4040404040",
262 "expExitCode": "0",
263 "verifyCmd": "$TC actions list action skbedit",
264 "matchPattern": "index 4040404040",
265 "matchCount": "1",
266 "teardown": [
267 "$TC actions flush action skbedit"
268 ]
269 },
270 {
271 "id": "38f3",
272 "name": "Delete skbedit action",
273 "category": [
274 "actions",
275 "skbedit"
276 ],
277 "setup": [
278 [
279 "$TC actions flush action skbedit",
280 0,
281 1,
282 255
283 ],
284 "$TC actions add action skbedit mark 42 index 9009"
285 ],
286 "cmdUnderTest": "$TC actions del action skbedit index 9009",
287 "expExitCode": "0",
288 "verifyCmd": "$TC actions list action skbedit",
289 "matchPattern": "action order [0-9]*: skbedit mark 42",
290 "matchCount": "0",
291 "teardown": [
292 "$TC actions flush action skbedit"
293 ]
294 },
295 {
296 "id": "ce97",
297 "name": "Flush skbedit actions",
298 "category": [
299 "actions",
300 "skbedit"
301 ],
302 "setup": [
303 "$TC actions add action skbedit mark 500",
304 "$TC actions add action skbedit mark 501",
305 "$TC actions add action skbedit mark 502",
306 "$TC actions add action skbedit mark 503",
307 "$TC actions add action skbedit mark 504",
308 "$TC actions add action skbedit mark 505",
309 "$TC actions add action skbedit mark 506"
310 ],
311 "cmdUnderTest": "$TC actions flush action skbedit",
312 "expExitCode": "0",
313 "verifyCmd": "$TC actions list action skbedit",
314 "matchPattern": "action order [0-9]*: skbedit",
315 "matchCount": "0",
316 "teardown": [
317 "$TC actions flush action skbedit"
318 ]
319 }
320]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json b/tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json
new file mode 100644
index 000000000000..e34075059c26
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/skbmod.json
@@ -0,0 +1,372 @@
1[
2 {
3 "id": "7d50",
4 "name": "Add skbmod action to set destination mac",
5 "category": [
6 "actions",
7 "skbmod"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action skbmod",
12 0,
13 1,
14 255
15 ]
16 ],
17 "cmdUnderTest": "$TC actions add action skbmod set dmac 11:22:33:44:55:66 index 5",
18 "expExitCode": "0",
19 "verifyCmd": "$TC actions ls action skbmod",
20 "matchPattern": "action order [0-9]*: skbmod pipe set dmac 11:22:33:44:55:66\\s+index 5",
21 "matchCount": "1",
22 "teardown": [
23 "$TC actions flush action skbmod"
24 ]
25 },
26 {
27 "id": "9b29",
28 "name": "Add skbmod action to set source mac",
29 "category": [
30 "actions",
31 "skbmod"
32 ],
33 "setup": [
34 [
35 "$TC actions flush action skbmod",
36 0,
37 1,
38 255
39 ]
40 ],
41 "cmdUnderTest": "$TC actions add action skbmod set smac 77:88:99:AA:BB:CC index 7",
42 "expExitCode": "0",
43 "verifyCmd": "$TC actions get action skbmod index 7",
44 "matchPattern": "action order [0-9]*: skbmod pipe set smac 77:88:99:aa:bb:cc\\s+index 7",
45 "matchCount": "1",
46 "teardown": [
47 "$TC actions flush action skbmod"
48 ]
49 },
50 {
51 "id": "1724",
52 "name": "Add skbmod action with invalid mac",
53 "category": [
54 "actions",
55 "skbmod"
56 ],
57 "setup": [
58 [
59 "$TC actions flush action skbmod",
60 0,
61 1,
62 255
63 ]
64 ],
65 "cmdUnderTest": "$TC actions add action skbmod set smac 00:44:55:44:55",
66 "expExitCode": "255",
67 "verifyCmd": "$TC actions ls action skbmod",
68 "matchPattern": "action order [0-9]*: skbmod pipe set smac 00:44:55:44:55",
69 "matchCount": "0",
70 "teardown": [
71 "$TC actions flush action skbmod"
72 ]
73 },
74 {
75 "id": "3cf1",
76 "name": "Add skbmod action with valid etype",
77 "category": [
78 "actions",
79 "skbmod"
80 ],
81 "setup": [
82 [
83 "$TC actions flush action skbmod",
84 0,
85 1,
86 255
87 ]
88 ],
89 "cmdUnderTest": "$TC actions add action skbmod set etype 0xfefe",
90 "expExitCode": "0",
91 "verifyCmd": "$TC actions ls action skbmod",
92 "matchPattern": "action order [0-9]*: skbmod pipe set etype 0xFEFE",
93 "matchCount": "1",
94 "teardown": [
95 "$TC actions flush action skbmod"
96 ]
97 },
98 {
99 "id": "a749",
100 "name": "Add skbmod action with invalid etype",
101 "category": [
102 "actions",
103 "skbmod"
104 ],
105 "setup": [
106 [
107 "$TC actions flush action skbmod",
108 0,
109 1,
110 255
111 ]
112 ],
113 "cmdUnderTest": "$TC actions add action skbmod set etype 0xfefef",
114 "expExitCode": "255",
115 "verifyCmd": "$TC actions ls action skbmod",
116 "matchPattern": "action order [0-9]*: skbmod pipe set etype 0xFEFEF",
117 "matchCount": "0",
118 "teardown": [
119 "$TC actions flush action skbmod"
120 ]
121 },
122 {
123 "id": "bfe6",
124 "name": "Add skbmod action to swap mac",
125 "category": [
126 "actions",
127 "skbmod"
128 ],
129 "setup": [
130 [
131 "$TC actions flush action skbmod",
132 0,
133 1,
134 255
135 ]
136 ],
137 "cmdUnderTest": "$TC actions add action skbmod swap mac",
138 "expExitCode": "0",
139 "verifyCmd": "$TC actions get action skbmod index 1",
140 "matchPattern": "action order [0-9]*: skbmod pipe swap mac",
141 "matchCount": "1",
142 "teardown": [
143 "$TC actions flush action skbmod"
144 ]
145 },
146 {
147 "id": "839b",
148 "name": "Add skbmod action with control pipe",
149 "category": [
150 "actions",
151 "skbmod"
152 ],
153 "setup": [
154 [
155 "$TC actions flush action skbmod",
156 0,
157 1,
158 255
159 ]
160 ],
161 "cmdUnderTest": "$TC actions add action skbmod swap mac pipe",
162 "expExitCode": "0",
163 "verifyCmd": "$TC actions ls action skbmod",
164 "matchPattern": "action order [0-9]*: skbmod pipe swap mac",
165 "matchCount": "1",
166 "teardown": [
167 "$TC actions flush action skbmod"
168 ]
169 },
170 {
171 "id": "c167",
172 "name": "Add skbmod action with control reclassify",
173 "category": [
174 "actions",
175 "skbmod"
176 ],
177 "setup": [
178 [
179 "$TC actions flush action skbmod",
180 0,
181 1,
182 255
183 ]
184 ],
185 "cmdUnderTest": "$TC actions add action skbmod set etype 0xbeef reclassify",
186 "expExitCode": "0",
187 "verifyCmd": "$TC actions ls action skbmod",
188 "matchPattern": "action order [0-9]*: skbmod reclassify set etype 0xBEEF",
189 "matchCount": "1",
190 "teardown": [
191 "$TC actions flush action skbmod"
192 ]
193 },
194 {
195 "id": "0c2f",
196 "name": "Add skbmod action with control drop",
197 "category": [
198 "actions",
199 "skbmod"
200 ],
201 "setup": [
202 [
203 "$TC actions flush action skbmod",
204 0,
205 1,
206 255
207 ]
208 ],
209 "cmdUnderTest": "$TC actions add action skbmod set etype 0x0001 drop",
210 "expExitCode": "0",
211 "verifyCmd": "$TC actions get action skbmod index 1",
212 "matchPattern": "action order [0-9]*: skbmod drop set etype 0x1",
213 "matchCount": "1",
214 "teardown": [
215 "$TC actions flush action skbmod"
216 ]
217 },
218 {
219 "id": "d113",
220 "name": "Add skbmod action with control continue",
221 "category": [
222 "actions",
223 "skbmod"
224 ],
225 "setup": [
226 [
227 "$TC actions flush action skbmod",
228 0,
229 1,
230 255
231 ]
232 ],
233 "cmdUnderTest": "$TC actions add action skbmod set etype 0x1 continue",
234 "expExitCode": "0",
235 "verifyCmd": "$TC actions ls action skbmod",
236 "matchPattern": "action order [0-9]*: skbmod continue set etype 0x1",
237 "matchCount": "1",
238 "teardown": [
239 "$TC actions flush action skbmod"
240 ]
241 },
242 {
243 "id": "7242",
244 "name": "Add skbmod action with control pass",
245 "category": [
246 "actions",
247 "skbmod"
248 ],
249 "setup": [
250 [
251 "$TC actions flush action skbmod",
252 0,
253 1,
254 255
255 ]
256 ],
257 "cmdUnderTest": "$TC actions add action skbmod set smac 00:00:00:00:00:01 pass",
258 "expExitCode": "0",
259 "verifyCmd": "$TC actions ls action skbmod",
260 "matchPattern": "action order [0-9]*: skbmod pass set smac 00:00:00:00:00:01",
261 "matchCount": "1",
262 "teardown": [
263 "$TC actions flush action skbmod"
264 ]
265 },
266 {
267 "id": "58cb",
268 "name": "List skbmod actions",
269 "category": [
270 "actions",
271 "skbmod"
272 ],
273 "setup": [
274 [
275 "$TC actions flush action skbmod",
276 0,
277 1,
278 255
279 ],
280 "$TC actions add action skbmod set etype 0x0001",
281 "$TC actions add action skbmod set etype 0x0011",
282 "$TC actions add action skbmod set etype 0x0021",
283 "$TC actions add action skbmod set etype 0x0031",
284 "$TC actions add action skbmod set etype 0x0041"
285 ],
286 "cmdUnderTest": "$TC actions ls action skbmod",
287 "expExitCode": "0",
288 "verifyCmd": "$TC actions ls action skbmod",
289 "matchPattern": "action order [0-9]*: skbmod",
290 "matchCount": "5",
291 "teardown": [
292 "$TC actions flush action skbmod"
293 ]
294 },
295 {
296 "id": "9aa8",
297 "name": "Get a single skbmod action from a list",
298 "category": [
299 "actions",
300 "skbmod"
301 ],
302 "setup": [
303 [
304 "$TC actions flush action skbmod",
305 0,
306 1,
307 255
308 ],
309 "$TC actions add action skbmod set etype 0x0001",
310 "$TC actions add action skbmod set etype 0x0011",
311 "$TC actions add action skbmod set etype 0x0021",
312 "$TC actions add action skbmod set etype 0x0031",
313 "$TC actions add action skbmod set etype 0x0041"
314 ],
315 "cmdUnderTest": "$TC actions ls action skbmod",
316 "expExitCode": "0",
317 "verifyCmd": "$TC actions get action skbmod index 4",
318 "matchPattern": "action order [0-9]*: skbmod pipe set etype 0x0031",
319 "matchCount": "1",
320 "teardown": [
321 "$TC actions flush action skbmod"
322 ]
323 },
324 {
325 "id": "e93a",
326 "name": "Delete an skbmod action",
327 "category": [
328 "actions",
329 "skbmod"
330 ],
331 "setup": [
332 [
333 "$TC actions flush action skbmod",
334 0,
335 1,
336 255
337 ],
338 "$TC actions add action skbmod set etype 0x1111 index 909"
339 ],
340 "cmdUnderTest": "$TC actions del action skbmod index 909",
341 "expExitCode": "0",
342 "verifyCmd": "$TC actions ls action skbmod",
343 "matchPattern": "action order [0-9]*: skbmod pipe set etype 0x1111\\s+index 909",
344 "matchCount": "0",
345 "teardown": [
346 "$TC actions flush action skbmod"
347 ]
348 },
349 {
350 "id": "40c2",
351 "name": "Flush skbmod actions",
352 "category": [
353 "actions",
354 "skbmod"
355 ],
356 "setup": [
357 "$TC actions add action skbmod set etype 0x0001",
358 "$TC actions add action skbmod set etype 0x0011",
359 "$TC actions add action skbmod set etype 0x0021",
360 "$TC actions add action skbmod set etype 0x0031",
361 "$TC actions add action skbmod set etype 0x0041"
362 ],
363 "cmdUnderTest": "$TC actions flush action skbmod",
364 "expExitCode": "0",
365 "verifyCmd": "$TC actions ls action skbmod",
366 "matchPattern": "action order [0-9]*: skbmod",
367 "matchCount": "0",
368 "teardown": [
369 "$TC actions flush action skbmod"
370 ]
371 }
372]
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/tests.json b/tools/testing/selftests/tc-testing/tc-tests/actions/tests.json
deleted file mode 100644
index 6973bdc5b5bf..000000000000
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/tests.json
+++ /dev/null
@@ -1,1165 +0,0 @@
1[
2 {
3 "id": "e89a",
4 "name": "Add valid pass action",
5 "category": [
6 "actions",
7 "gact"
8 ],
9 "setup": [
10 [
11 "$TC actions flush action gact",
12 0,
13 1,
14 255
15 ]
16 ],
17 "cmdUnderTest": "$TC actions add action pass index 8",
18 "expExitCode": "0",
19 "verifyCmd": "$TC actions list action gact",
20 "matchPattern": "action order [0-9]*: gact action pass.*index 8 ref",
21 "matchCount": "1",
22 "teardown": [
23 "$TC actions flush action gact"
24 ]
25 },
26 {
27 "id": "a02c",
28 "name": "Add valid pipe action",
29 "category": [
30 "actions",
31 "gact"
32 ],
33 "setup": [
34 [
35 "$TC actions flush action gact",
36 0,
37 1,
38 255
39 ]
40 ],
41 "cmdUnderTest": "$TC actions add action pipe index 6",
42 "expExitCode": "0",
43 "verifyCmd": "$TC actions list action gact",
44 "matchPattern": "action order [0-9]*: gact action pipe.*index 6 ref",
45 "matchCount": "1",
46 "teardown": [
47 "$TC actions flush action gact"
48 ]
49 },
50 {
51 "id": "feef",
52 "name": "Add valid reclassify action",
53 "category": [
54 "actions",
55 "gact"
56 ],
57 "setup": [
58 [
59 "$TC actions flush action gact",
60 0,
61 1,
62 255
63 ]
64 ],
65 "cmdUnderTest": "$TC actions add action reclassify index 5",
66 "expExitCode": "0",
67 "verifyCmd": "$TC actions list action gact",
68 "matchPattern": "action order [0-9]*: gact action reclassify.*index 5 ref",
69 "matchCount": "1",
70 "teardown": [
71 "$TC actions flush action gact"
72 ]
73 },
74 {
75 "id": "8a7a",
76 "name": "Add valid drop action",
77 "category": [
78 "actions",
79 "gact"
80 ],
81 "setup": [
82 [
83 "$TC actions flush action gact",
84 0,
85 1,
86 255
87 ]
88 ],
89 "cmdUnderTest": "$TC actions add action drop index 30",
90 "expExitCode": "0",
91 "verifyCmd": "$TC actions list action gact",
92 "matchPattern": "action order [0-9]*: gact action drop.*index 30 ref",
93 "matchCount": "1",
94 "teardown": [
95 "$TC actions flush action gact"
96 ]
97 },
98 {
99 "id": "9a52",
100 "name": "Add valid continue action",
101 "category": [
102 "actions",
103 "gact"
104 ],
105 "setup": [
106 [
107 "$TC actions flush action gact",
108 0,
109 1,
110 255
111 ]
112 ],
113 "cmdUnderTest": "$TC actions add action continue index 432",
114 "expExitCode": "0",
115 "verifyCmd": "$TC actions list action gact",
116 "matchPattern": "action order [0-9]*: gact action continue.*index 432 ref",
117 "matchCount": "1",
118 "teardown": [
119 "$TC actions flush action gact"
120 ]
121 },
122 {
123 "id": "d700",
124 "name": "Add invalid action",
125 "category": [
126 "actions",
127 "gact"
128 ],
129 "setup": [
130 [
131 "$TC actions flush action gact",
132 0,
133 1,
134 255
135 ]
136 ],
137 "cmdUnderTest": "$TC actions add action pump index 386",
138 "expExitCode": "255",
139 "verifyCmd": "$TC actions list action gact",
140 "matchPattern": "action order [0-9]*: gact action.*index 386 ref",
141 "matchCount": "0",
142 "teardown": [
143 "$TC actions flush action gact"
144 ]
145 },
146 {
147 "id": "9215",
148 "name": "Add action with duplicate index",
149 "category": [
150 "actions",
151 "gact"
152 ],
153 "setup": [
154 [
155 "$TC actions flush action gact",
156 0,
157 1,
158 255
159 ],
160 "$TC actions add action pipe index 15"
161 ],
162 "cmdUnderTest": "$TC actions add action drop index 15",
163 "expExitCode": "255",
164 "verifyCmd": "$TC actions list action gact",
165 "matchPattern": "action order [0-9]*: gact action drop.*index 15 ref",
166 "matchCount": "0",
167 "teardown": [
168 "$TC actions flush action gact"
169 ]
170 },
171 {
172 "id": "798e",
173 "name": "Add action with index exceeding 32-bit maximum",
174 "category": [
175 "actions",
176 "gact"
177 ],
178 "setup": [
179 [
180 "$TC actions flush action gact",
181 0,
182 1,
183 255
184 ]
185 ],
186 "cmdUnderTest": "$TC actions add action drop index 4294967296",
187 "expExitCode": "255",
188 "verifyCmd": "actions list action gact",
189 "matchPattern": "action order [0-9]*: gact action drop.*index 4294967296 ref",
190 "matchCount": "0",
191 "teardown": [
192 "$TC actions flush action gact"
193 ]
194 },
195 {
196 "id": "22be",
197 "name": "Add action with index at 32-bit maximum",
198 "category": [
199 "actions",
200 "gact"
201 ],
202 "setup": [
203 [
204 "$TC actions flush action gact",
205 0,
206 1,
207 255
208 ]
209 ],
210 "cmdUnderTest": "$TC actions add action drop index 4294967295",
211 "expExitCode": "0",
212 "verifyCmd": "$TC actions list action gact",
213 "matchPattern": "action order [0-9]*: gact action drop.*index 4294967295 ref",
214 "matchCount": "1",
215 "teardown": [
216 "$TC actions flush action gact"
217 ]
218 },
219 {
220 "id": "ac2a",
221 "name": "List actions",
222 "category": [
223 "actions",
224 "gact"
225 ],
226 "setup": [
227 [
228 "$TC actions flush action gact",
229 0,
230 1,
231 255
232 ],
233 "$TC actions add action reclassify index 101",
234 "$TC actions add action reclassify index 102",
235 "$TC actions add action reclassify index 103",
236 "$TC actions add action reclassify index 104",
237 "$TC actions add action reclassify index 105"
238 ],
239 "cmdUnderTest": "$TC actions list action gact",
240 "expExitCode": "0",
241 "verifyCmd": "$TC actions list action gact",
242 "matchPattern": "action order [0-9]*: gact action reclassify",
243 "matchCount": "5",
244 "teardown": [
245 "$TC actions flush action gact"
246 ]
247 },
248 {
249 "id": "63ec",
250 "name": "Delete pass action",
251 "category": [
252 "actions",
253 "gact"
254 ],
255 "setup": [
256 [
257 "$TC actions flush action gact",
258 0,
259 1,
260 255
261 ],
262 "$TC actions add action pass index 1"
263 ],
264 "cmdUnderTest": "$TC actions del action gact index 1",
265 "expExitCode": "0",
266 "verifyCmd": "$TC actions list action gact",
267 "matchPattern": "action order [0-9]*: gact action pass.*index 1 ref",
268 "matchCount": "0",
269 "teardown": [
270 "$TC actions flush action gact"
271 ]
272 },
273 {
274 "id": "46be",
275 "name": "Delete pipe action",
276 "category": [
277 "actions",
278 "gact"
279 ],
280 "setup": [
281 [
282 "$TC actions flush action gact",
283 0,
284 1,
285 255
286 ],
287 "$TC actions add action pipe index 9"
288 ],
289 "cmdUnderTest": "$TC actions del action gact index 9",
290 "expExitCode": "0",
291 "verifyCmd": "$TC actions list action gact",
292 "matchPattern": "action order [0-9]*: gact action pipe.*index 9 ref",
293 "matchCount": "0",
294 "teardown": [
295 "$TC actions flush action gact"
296 ]
297 },
298 {
299 "id": "2e08",
300 "name": "Delete reclassify action",
301 "category": [
302 "actions",
303 "gact"
304 ],
305 "setup": [
306 [
307 "$TC actions flush action gact",
308 0,
309 1,
310 255
311 ],
312 "$TC actions add action reclassify index 65536"
313 ],
314 "cmdUnderTest": "$TC actions del action gact index 65536",
315 "expExitCode": "0",
316 "verifyCmd": "$TC actions list action gact",
317 "matchPattern": "action order [0-9]*: gact action reclassify.*index 65536 ref",
318 "matchCount": "0",
319 "teardown": [
320 "$TC actions flush action gact"
321 ]
322 },
323 {
324 "id": "99c4",
325 "name": "Delete drop action",
326 "category": [
327 "actions",
328 "gact"
329 ],
330 "setup": [
331 [
332 "$TC actions flush action gact",
333 0,
334 1,
335 255
336 ],
337 "$TC actions add action drop index 16"
338 ],
339 "cmdUnderTest": "$TC actions del action gact index 16",
340 "expExitCode": "0",
341 "verifyCmd": "$TC actions list action gact",
342 "matchPattern": "action order [0-9]*: gact action drop.*index 16 ref",
343 "matchCount": "0",
344 "teardown": [
345 "$TC actions flush action gact"
346 ]
347 },
348 {
349 "id": "fb6b",
350 "name": "Delete continue action",
351 "category": [
352 "actions",
353 "gact"
354 ],
355 "setup": [
356 [
357 "$TC actions flush action gact",
358 0,
359 1,
360 255
361 ],
362 "$TC actions add action continue index 32"
363 ],
364 "cmdUnderTest": "$TC actions del action gact index 32",
365 "expExitCode": "0",
366 "verifyCmd": "actions list action gact",
367 "matchPattern": "action order [0-9]*: gact action continue.*index 32 ref",
368 "matchCount": "0",
369 "teardown": [
370 "$TC actions flush action gact"
371 ]
372 },
373 {
374 "id": "0eb3",
375 "name": "Delete non-existent action",
376 "category": [
377 "actions",
378 "gact"
379 ],
380 "setup": [
381 [
382 "$TC actions flush action gact",
383 0,
384 1,
385 255
386 ]
387 ],
388 "cmdUnderTest": "$TC actions del action gact index 2",
389 "expExitCode": "255",
390 "verifyCmd": "$TC actions list action gact",
391 "matchPattern": "action order [0-9]*: gact action",
392 "matchCount": "0",
393 "teardown": [
394 "$TC actions flush action gact"
395 ]
396 },
397 {
398 "id": "5124",
399 "name": "Add mirred mirror to egress action",
400 "category": [
401 "actions",
402 "mirred"
403 ],
404 "setup": [
405 [
406 "$TC actions flush action mirred",
407 0,
408 1,
409 255
410 ]
411 ],
412 "cmdUnderTest": "$TC actions add action mirred egress mirror index 1 dev lo",
413 "expExitCode": "0",
414 "verifyCmd": "$TC actions list action mirred",
415 "matchPattern": "action order [0-9]*: mirred \\(Egress Mirror to device lo\\).*index 1 ref",
416 "matchCount": "1",
417 "teardown": [
418 "$TC actions flush action mirred"
419 ]
420 },
421 {
422 "id": "6fb4",
423 "name": "Add mirred redirect to egress action",
424 "category": [
425 "actions",
426 "mirred"
427 ],
428 "setup": [
429 [
430 "$TC actions flush action mirred",
431 0,
432 1,
433 255
434 ]
435 ],
436 "cmdUnderTest": "$TC actions add action mirred egress redirect index 2 dev lo action pipe",
437 "expExitCode": "0",
438 "verifyCmd": "$TC actions list action mirred",
439 "matchPattern": "action order [0-9]*: mirred \\(Egress Redirect to device lo\\).*index 2 ref",
440 "matchCount": "1",
441 "teardown": [
442 "$TC actions flush action mirred"
443 ]
444 },
445 {
446 "id": "ba38",
447 "name": "Get mirred actions",
448 "category": [
449 "actions",
450 "mirred"
451 ],
452 "setup": [
453 [
454 "$TC actions flush action mirred",
455 0,
456 1,
457 255
458 ],
459 "$TC actions add action mirred egress mirror index 1 dev lo",
460 "$TC actions add action mirred egress redirect index 2 dev lo"
461 ],
462 "cmdUnderTest": "$TC actions show action mirred",
463 "expExitCode": "0",
464 "verifyCmd": "$TC actions list action mirred",
465 "matchPattern": "[Mirror|Redirect] to device lo",
466 "matchCount": "2",
467 "teardown": [
468 "$TC actions flush action mirred"
469 ]
470 },
471 {
472 "id": "d7c0",
473 "name": "Add invalid mirred direction",
474 "category": [
475 "actions",
476 "mirred"
477 ],
478 "setup": [
479 [
480 "$TC actions flush action mirred",
481 0,
482 1,
483 255
484 ]
485 ],
486 "cmdUnderTest": "$TC actions add action mirred inbound mirror index 20 dev lo",
487 "expExitCode": "255",
488 "verifyCmd": "$TC actions list action mirred",
489 "matchPattern": "action order [0-9]*: mirred \\(.*to device lo\\).*index 20 ref",
490 "matchCount": "0",
491 "teardown": [
492 "$TC actions flush action mirred"
493 ]
494 },
495 {
496 "id": "e213",
497 "name": "Add invalid mirred action",
498 "category": [
499 "actions",
500 "mirred"
501 ],
502 "setup": [
503 [
504 "$TC actions flush action mirred",
505 0,
506 1,
507 255
508 ]
509 ],
510 "cmdUnderTest": "$TC actions add action mirred egress remirror index 20 dev lo",
511 "expExitCode": "255",
512 "verifyCmd": "$TC actions list action mirred",
513 "matchPattern": "action order [0-9]*: mirred \\(Egress.*to device lo\\).*index 20 ref",
514 "matchCount": "0",
515 "teardown": [
516 "$TC actions flush action mirred"
517 ]
518 },
519 {
520 "id": "2d89",
521 "name": "Add mirred action with invalid device",
522 "category": [
523 "actions",
524 "mirred"
525 ],
526 "setup": [
527 [
528 "$TC actions flush action mirred",
529 0,
530 1,
531 255
532 ]
533 ],
534 "cmdUnderTest": "$TC actions add action mirred egress mirror index 20 dev eltoh",
535 "expExitCode": "255",
536 "verifyCmd": "$TC actions list action mirred",
537 "matchPattern": "action order [0-9]*: mirred \\(.*to device eltoh\\).*index 20 ref",
538 "matchCount": "0",
539 "teardown": [
540 "$TC actions flush action mirred"
541 ]
542 },
543 {
544 "id": "300b",
545 "name": "Add mirred action with duplicate index",
546 "category": [
547 "actions",
548 "mirred"
549 ],
550 "setup": [
551 [
552 "$TC actions flush action mirred",
553 0,
554 1,
555 255
556 ],
557 "$TC actions add action mirred egress redirect index 15 dev lo"
558 ],
559 "cmdUnderTest": "$TC actions add action mirred egress mirror index 15 dev lo",
560 "expExitCode": "255",
561 "verifyCmd": "$TC actions list action mirred",
562 "matchPattern": "action order [0-9]*: mirred \\(.*to device lo\\).*index 15 ref",
563 "matchCount": "1",
564 "teardown": [
565 "$TC actions flush action mirred"
566 ]
567 },
568 {
569 "id": "a70e",
570 "name": "Delete mirred mirror action",
571 "category": [
572 "actions",
573 "mirred"
574 ],
575 "setup": [
576 [
577 "$TC actions flush action mirred",
578 0,
579 1,
580 255
581 ],
582 "$TC actions add action mirred egress mirror index 5 dev lo"
583 ],
584 "cmdUnderTest": "$TC actions del action mirred index 5",
585 "expExitCode": "0",
586 "verifyCmd": "$TC actions list action mirred",
587 "matchPattern": "action order [0-9]*: mirred \\(Egress Mirror to device lo\\).*index 5 ref",
588 "matchCount": "0",
589 "teardown": [
590 "$TC actions flush action mirred"
591 ]
592 },
593 {
594 "id": "3fb3",
595 "name": "Delete mirred redirect action",
596 "category": [
597 "actions",
598 "mirred"
599 ],
600 "setup": [
601 [
602 "$TC actions flush action mirred",
603 0,
604 1,
605 255
606 ],
607 "$TC actions add action mirred egress redirect index 5 dev lo"
608 ],
609 "cmdUnderTest": "$TC actions del action mirred index 5",
610 "expExitCode": "0",
611 "verifyCmd": "$TC actions list action mirred",
612 "matchPattern": "action order [0-9]*: mirred \\(Egress Redirect to device lo\\).*index 5 ref",
613 "matchCount": "0",
614 "teardown": [
615 "$TC actions flush action mirred"
616 ]
617 },
618 {
619 "id": "b078",
620 "name": "Add simple action",
621 "category": [
622 "actions",
623 "simple"
624 ],
625 "setup": [
626 [
627 "$TC actions flush action simple",
628 0,
629 1,
630 255
631 ]
632 ],
633 "cmdUnderTest": "$TC actions add action simple sdata \"A triumph\" index 60",
634 "expExitCode": "0",
635 "verifyCmd": "$TC actions list action simple",
636 "matchPattern": "action order [0-9]*: Simple <A triumph>.*index 60 ref",
637 "matchCount": "1",
638 "teardown": [
639 "$TC actions flush action simple"
640 ]
641 },
642 {
643 "id": "6d4c",
644 "name": "Add simple action with duplicate index",
645 "category": [
646 "actions",
647 "simple"
648 ],
649 "setup": [
650 [
651 "$TC actions flush action simple",
652 0,
653 1,
654 255
655 ],
656 "$TC actions add action simple sdata \"Aruba\" index 4"
657 ],
658 "cmdUnderTest": "$TC actions add action simple sdata \"Jamaica\" index 4",
659 "expExitCode": "255",
660 "verifyCmd": "$TC actions list action simple",
661 "matchPattern": "action order [0-9]*: Simple <Jamaica>.*ref",
662 "matchCount": "0",
663 "teardown": [
664 "$TC actions flush action simple"
665 ]
666 },
667 {
668 "id": "2542",
669 "name": "List simple actions",
670 "category": [
671 "actions",
672 "simple"
673 ],
674 "setup": [
675 [
676 "$TC actions flush action simple",
677 0,
678 1,
679 255
680 ],
681 "$TC actions add action simple sdata \"Rock\"",
682 "$TC actions add action simple sdata \"Paper\"",
683 "$TC actions add action simple sdata \"Scissors\" index 98"
684 ],
685 "cmdUnderTest": "$TC actions list action simple",
686 "expExitCode": "0",
687 "verifyCmd": "$TC actions list action simple",
688 "matchPattern": "action order [0-9]*: Simple <[A-Z][a-z]*>",
689 "matchCount": "3",
690 "teardown": [
691 "$TC actions flush action simple"
692 ]
693 },
694 {
695 "id": "ea67",
696 "name": "Delete simple action",
697 "category": [
698 "actions",
699 "simple"
700 ],
701 "setup": [
702 [
703 "$TC actions flush action simple",
704 0,
705 1,
706 255
707 ],
708 "$TC actions add action simple sdata \"Blinkenlights\" index 1"
709 ],
710 "cmdUnderTest": "$TC actions delete action simple index 1",
711 "expExitCode": "0",
712 "verifyCmd": "$TC actions list action simple",
713 "matchPattern": "action order [0-9]*: Simple <Blinkenlights>.*index 1 ref",
714 "matchCount": "0",
715 "teardown": [
716 "$TC actions flush action simple"
717 ]
718 },
719 {
720 "id": "8ff1",
721 "name": "Flush simple actions",
722 "category": [
723 "actions",
724 "simple"
725 ],
726 "setup": [
727 [
728 "$TC actions flush action simple",
729 0,
730 1,
731 255
732 ],
733 "$TC actions add action simple sdata \"Kirk\"",
734 "$TC actions add action simple sdata \"Spock\" index 50",
735 "$TC actions add action simple sdata \"McCoy\" index 9"
736 ],
737 "cmdUnderTest": "$TC actions flush action simple",
738 "expExitCode": "0",
739 "verifyCmd": "$TC actions list action simple",
740 "matchPattern": "action order [0-9]*: Simple <[A-Z][a-z]*>",
741 "matchCount": "0",
742 "teardown": [
743 ""
744 ]
745 },
746 {
747 "id": "6236",
748 "name": "Add skbedit action with valid mark",
749 "category": [
750 "actions",
751 "skbedit"
752 ],
753 "setup": [
754 [
755 "$TC actions flush action skbedit",
756 0,
757 1,
758 255
759 ]
760 ],
761 "cmdUnderTest": "$TC actions add action skbedit mark 1",
762 "expExitCode": "0",
763 "verifyCmd": "$TC actions list action skbedit",
764 "matchPattern": "action order [0-9]*: skbedit mark 1",
765 "matchCount": "1",
766 "teardown": [
767 "$TC actions flush action skbedit"
768 ]
769 },
770 {
771 "id": "407b",
772 "name": "Add skbedit action with invalid mark",
773 "category": [
774 "actions",
775 "skbedit"
776 ],
777 "setup": [
778 [
779 "$TC actions flush action skbedit",
780 0,
781 1,
782 255
783 ]
784 ],
785 "cmdUnderTest": "$TC actions add action skbedit mark 666777888999",
786 "expExitCode": "255",
787 "verifyCmd": "$TC actions list action skbedit",
788 "matchPattern": "action order [0-9]*: skbedit mark",
789 "matchCount": "0",
790 "teardown": [
791 "$TC actions flush action skbedit"
792 ]
793 },
794 {
795 "id": "081d",
796 "name": "Add skbedit action with priority",
797 "category": [
798 "actions",
799 "skbedit"
800 ],
801 "setup": [
802 [
803 "$TC actions flush action skbedit",
804 0,
805 1,
806 255
807 ]
808 ],
809 "cmdUnderTest": "$TC actions add action skbedit prio 99",
810 "expExitCode": "0",
811 "verifyCmd": "$TC actions list action skbedit",
812 "matchPattern": "action order [0-9]*: skbedit priority :99",
813 "matchCount": "1",
814 "teardown": [
815 "$TC actions flush action skbedit"
816 ]
817 },
818 {
819 "id": "cc37",
820 "name": "Add skbedit action with invalid priority",
821 "category": [
822 "actions",
823 "skbedit"
824 ],
825 "setup": [
826 [
827 "$TC actions flush action skbedit",
828 0,
829 1,
830 255
831 ]
832 ],
833 "cmdUnderTest": "$TC actions add action skbedit prio foo",
834 "expExitCode": "255",
835 "verifyCmd": "$TC actions list action skbedit",
836 "matchPattern": "action order [0-9]*: skbedit priority",
837 "matchCount": "0",
838 "teardown": [
839 "$TC actions flush action skbedit"
840 ]
841 },
842 {
843 "id": "3c95",
844 "name": "Add skbedit action with queue_mapping",
845 "category": [
846 "actions",
847 "skbedit"
848 ],
849 "setup": [
850 [
851 "$TC actions flush action skbedit",
852 0,
853 1,
854 255
855 ]
856 ],
857 "cmdUnderTest": "$TC actions add action skbedit queue_mapping 909",
858 "expExitCode": "0",
859 "verifyCmd": "$TC actions list action skbedit",
860 "matchPattern": "action order [0-9]*: skbedit queue_mapping 909",
861 "matchCount": "1",
862 "teardown": [
863 "$TC actions flush action skbedit"
864 ]
865 },
866 {
867 "id": "985c",
868 "name": "Add skbedit action with invalid queue_mapping",
869 "category": [
870 "actions",
871 "skbedit"
872 ],
873 "setup": [
874 [
875 "$TC actions flush action skbedit",
876 0,
877 1,
878 255
879 ]
880 ],
881 "cmdUnderTest": "$TC actions add action skbedit queue_mapping 67000",
882 "expExitCode": "255",
883 "verifyCmd": "$TC actions list action skbedit",
884 "matchPattern": "action order [0-9]*: skbedit queue_mapping",
885 "matchCount": "0",
886 "teardown": [
887 "$TC actions flush action skbedit"
888 ]
889 },
890 {
891 "id": "224f",
892 "name": "Add skbedit action with ptype host",
893 "category": [
894 "actions",
895 "skbedit"
896 ],
897 "setup": [
898 [
899 "$TC actions flush action skbedit",
900 0,
901 1,
902 255
903 ]
904 ],
905 "cmdUnderTest": "$TC actions add action skbedit ptype host",
906 "expExitCode": "0",
907 "verifyCmd": "$TC actions list action skbedit",
908 "matchPattern": "action order [0-9]*: skbedit ptype host",
909 "matchCount": "1",
910 "teardown": [
911 "$TC actions flush action skbedit"
912 ]
913 },
914 {
915 "id": "d1a3",
916 "name": "Add skbedit action with ptype otherhost",
917 "category": [
918 "actions",
919 "skbedit"
920 ],
921 "setup": [
922 [
923 "$TC actions flush action skbedit",
924 0,
925 1,
926 255
927 ]
928 ],
929 "cmdUnderTest": "$TC actions add action skbedit ptype otherhost",
930 "expExitCode": "0",
931 "verifyCmd": "$TC actions list action skbedit",
932 "matchPattern": "action order [0-9]*: skbedit ptype otherhost",
933 "matchCount": "1",
934 "teardown": [
935 "$TC actions flush action skbedit"
936 ]
937 },
938 {
939 "id": "b9c6",
940 "name": "Add skbedit action with invalid ptype",
941 "category": [
942 "actions",
943 "skbedit"
944 ],
945 "setup": [
946 [
947 "$TC actions flush action skbedit",
948 0,
949 1,
950 255
951 ]
952 ],
953 "cmdUnderTest": "$TC actions add action skbedit ptype openair",
954 "expExitCode": "255",
955 "verifyCmd": "$TC actions list action skbedit",
956 "matchPattern": "action order [0-9]*: skbedit ptype openair",
957 "matchCount": "0",
958 "teardown": [
959 "$TC actions flush action skbedit"
960 ]
961 },
962 {
963 "id": "5172",
964 "name": "List skbedit actions",
965 "category": [
966 "actions",
967 "skbedit"
968 ],
969 "setup": [
970 [
971 "$TC actions flush action skbedit",
972 0,
973 1,
974 255
975 ],
976 "$TC actions add action skbedit ptype otherhost",
977 "$TC actions add action skbedit ptype broadcast",
978 "$TC actions add action skbedit mark 59",
979 "$TC actions add action skbedit mark 409"
980 ],
981 "cmdUnderTest": "$TC actions list action skbedit",
982 "expExitCode": "0",
983 "verifyCmd": "$TC actions list action skbedit",
984 "matchPattern": "action order [0-9]*: skbedit",
985 "matchCount": "4",
986 "teardown": [
987 "$TC actions flush action skbedit"
988 ]
989 },
990 {
991 "id": "a6d6",
992 "name": "Add skbedit action with index",
993 "category": [
994 "actions",
995 "skbedit"
996 ],
997 "setup": [
998 [
999 "$TC actions flush action skbedit",
1000 0,
1001 1,
1002 255
1003 ]
1004 ],
1005 "cmdUnderTest": "$TC actions add action skbedit mark 808 index 4040404040",
1006 "expExitCode": "0",
1007 "verifyCmd": "$TC actions list action skbedit",
1008 "matchPattern": "index 4040404040",
1009 "matchCount": "1",
1010 "teardown": [
1011 "$TC actions flush action skbedit"
1012 ]
1013 },
1014 {
1015 "id": "38f3",
1016 "name": "Delete skbedit action",
1017 "category": [
1018 "actions",
1019 "skbedit"
1020 ],
1021 "setup": [
1022 [
1023 "$TC actions flush action skbedit",
1024 0,
1025 1,
1026 255
1027 ],
1028 "$TC actions add action skbedit mark 42 index 9009"
1029 ],
1030 "cmdUnderTest": "$TC actions del action skbedit index 9009",
1031 "expExitCode": "0",
1032 "verifyCmd": "$TC actions list action skbedit",
1033 "matchPattern": "action order [0-9]*: skbedit mark 42",
1034 "matchCount": "0",
1035 "teardown": [
1036 "$TC actions flush action skbedit"
1037 ]
1038 },
1039 {
1040 "id": "ce97",
1041 "name": "Flush skbedit actions",
1042 "category": [
1043 "actions",
1044 "skbedit"
1045 ],
1046 "setup": [
1047 "$TC actions add action skbedit mark 500",
1048 "$TC actions add action skbedit mark 501",
1049 "$TC actions add action skbedit mark 502",
1050 "$TC actions add action skbedit mark 503",
1051 "$TC actions add action skbedit mark 504",
1052 "$TC actions add action skbedit mark 505",
1053 "$TC actions add action skbedit mark 506"
1054 ],
1055 "cmdUnderTest": "$TC actions flush action skbedit",
1056 "expExitCode": "0",
1057 "verifyCmd": "$TC actions list action skbedit",
1058 "matchPattern": "action order [0-9]*: skbedit",
1059 "matchCount": "0",
1060 "teardown": [
1061 "$TC actions flush action skbedit"
1062 ]
1063 },
1064 {
1065 "id": "f02c",
1066 "name": "Replace gact action",
1067 "category": [
1068 "actions",
1069 "gact"
1070 ],
1071 "setup": [
1072 [
1073 "$TC actions flush action gact",
1074 0,
1075 1,
1076 255
1077 ],
1078 "$TC actions add action drop index 10",
1079 "$TC actions add action drop index 12"
1080 ],
1081 "cmdUnderTest": "$TC actions replace action ok index 12",
1082 "expExitCode": "0",
1083 "verifyCmd": "$TC actions ls action gact",
1084 "matchPattern": "action order [0-9]*: gact action pass",
1085 "matchCount": "1",
1086 "teardown": [
1087 "$TC actions flush action gact"
1088 ]
1089 },
1090 {
1091 "id": "525f",
1092 "name": "Get gact action by index",
1093 "category": [
1094 "actions",
1095 "gact"
1096 ],
1097 "setup": [
1098 [
1099 "$TC actions flush action gact",
1100 0,
1101 1,
1102 255
1103 ],
1104 "$TC actions add action drop index 3900800700"
1105 ],
1106 "cmdUnderTest": "$TC actions get action gact index 3900800700",
1107 "expExitCode": "0",
1108 "verifyCmd": "$TC actions get action gact index 3900800700",
1109 "matchPattern": "index 3900800700",
1110 "matchCount": "1",
1111 "teardown": [
1112 "$TC actions flush action gact"
1113 ]
1114 },
1115 {
1116 "id": "a568",
1117 "name": "Add action with ife type",
1118 "category": [
1119 "actions",
1120 "ife"
1121 ],
1122 "setup": [
1123 [
1124 "$TC actions flush action ife",
1125 0,
1126 1,
1127 255
1128 ],
1129 "$TC actions add action ife encode type 0xDEAD index 1"
1130 ],
1131 "cmdUnderTest": "$TC actions get action ife index 1",
1132 "expExitCode": "0",
1133 "verifyCmd": "$TC actions get action ife index 1",
1134 "matchPattern": "type 0xDEAD",
1135 "matchCount": "1",
1136 "teardown": [
1137 "$TC actions flush action ife"
1138 ]
1139 },
1140 {
1141 "id": "b983",
1142 "name": "Add action without ife type",
1143 "category": [
1144 "actions",
1145 "ife"
1146 ],
1147 "setup": [
1148 [
1149 "$TC actions flush action ife",
1150 0,
1151 1,
1152 255
1153 ],
1154 "$TC actions add action ife encode index 1"
1155 ],
1156 "cmdUnderTest": "$TC actions get action ife index 1",
1157 "expExitCode": "0",
1158 "verifyCmd": "$TC actions get action ife index 1",
1159 "matchPattern": "type 0xED3E",
1160 "matchCount": "1",
1161 "teardown": [
1162 "$TC actions flush action ife"
1163 ]
1164 }
1165] \ No newline at end of file
diff --git a/tools/testing/selftests/tc-testing/tc-tests/filters/tests.json b/tools/testing/selftests/tc-testing/tc-tests/filters/tests.json
index c727b96a59b0..5fa02d86b35f 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/filters/tests.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/filters/tests.json
@@ -17,5 +17,26 @@
17 "teardown": [ 17 "teardown": [
18 "$TC qdisc del dev $DEV1 ingress" 18 "$TC qdisc del dev $DEV1 ingress"
19 ] 19 ]
20 },
21 {
22 "id": "d052",
23 "name": "Add 1M filters with the same action",
24 "category": [
25 "filter",
26 "flower"
27 ],
28 "setup": [
29 "$TC qdisc add dev $DEV2 ingress",
30 "./tdc_batch.py $DEV2 $BATCH_FILE --share_action -n 1000000"
31 ],
32 "cmdUnderTest": "$TC -b $BATCH_FILE",
33 "expExitCode": "0",
34 "verifyCmd": "$TC actions list action gact",
35 "matchPattern": "action order 0: gact action drop.*index 1 ref 1000000 bind 1000000",
36 "matchCount": "1",
37 "teardown": [
38 "$TC qdisc del dev $DEV2 ingress",
39 "/bin/rm $BATCH_FILE"
40 ]
20 } 41 }
21] \ No newline at end of file 42]
diff --git a/tools/testing/selftests/tc-testing/tdc.py b/tools/testing/selftests/tc-testing/tdc.py
index cd61b7844c0d..fc373fdf2bdc 100755
--- a/tools/testing/selftests/tc-testing/tdc.py
+++ b/tools/testing/selftests/tc-testing/tdc.py
@@ -1,4 +1,5 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0
2 3
3""" 4"""
4tdc.py - Linux tc (Traffic Control) unit test driver 5tdc.py - Linux tc (Traffic Control) unit test driver
@@ -49,7 +50,7 @@ def exec_cmd(command, nsonly=True):
49 stderr=subprocess.PIPE) 50 stderr=subprocess.PIPE)
50 (rawout, serr) = proc.communicate() 51 (rawout, serr) = proc.communicate()
51 52
52 if proc.returncode != 0: 53 if proc.returncode != 0 and len(serr) > 0:
53 foutput = serr.decode("utf-8") 54 foutput = serr.decode("utf-8")
54 else: 55 else:
55 foutput = rawout.decode("utf-8") 56 foutput = rawout.decode("utf-8")
@@ -88,7 +89,7 @@ def prepare_env(cmdlist):
88 exit(1) 89 exit(1)
89 90
90 91
91def test_runner(filtered_tests): 92def test_runner(filtered_tests, args):
92 """ 93 """
93 Driver function for the unit tests. 94 Driver function for the unit tests.
94 95
@@ -105,6 +106,8 @@ def test_runner(filtered_tests):
105 for tidx in testlist: 106 for tidx in testlist:
106 result = True 107 result = True
107 tresult = "" 108 tresult = ""
109 if "flower" in tidx["category"] and args.device == None:
110 continue
108 print("Test " + tidx["id"] + ": " + tidx["name"]) 111 print("Test " + tidx["id"] + ": " + tidx["name"])
109 prepare_env(tidx["setup"]) 112 prepare_env(tidx["setup"])
110 (p, procout) = exec_cmd(tidx["cmdUnderTest"]) 113 (p, procout) = exec_cmd(tidx["cmdUnderTest"])
@@ -150,7 +153,11 @@ def ns_create():
150 exec_cmd(cmd, False) 153 exec_cmd(cmd, False)
151 cmd = 'ip link set $DEV0 up' 154 cmd = 'ip link set $DEV0 up'
152 exec_cmd(cmd, False) 155 exec_cmd(cmd, False)
153 cmd = 'ip -s $NS link set $DEV1 up' 156 cmd = 'ip -n $NS link set $DEV1 up'
157 exec_cmd(cmd, False)
158 cmd = 'ip link set $DEV2 netns $NS'
159 exec_cmd(cmd, False)
160 cmd = 'ip -n $NS link set $DEV2 up'
154 exec_cmd(cmd, False) 161 exec_cmd(cmd, False)
155 162
156 163
@@ -173,15 +180,20 @@ def has_blank_ids(idlist):
173 180
174def load_from_file(filename): 181def load_from_file(filename):
175 """ 182 """
176 Open the JSON file containing the test cases and return them as an 183 Open the JSON file containing the test cases and return them
177 ordered dictionary object. 184 as list of ordered dictionary objects.
178 """ 185 """
179 with open(filename) as test_data: 186 try:
180 testlist = json.load(test_data, object_pairs_hook=OrderedDict) 187 with open(filename) as test_data:
181 idlist = get_id_list(testlist) 188 testlist = json.load(test_data, object_pairs_hook=OrderedDict)
182 if (has_blank_ids(idlist)): 189 except json.JSONDecodeError as jde:
183 for k in testlist: 190 print('IGNORING test case file {}\n\tBECAUSE: {}'.format(filename, jde))
184 k['filename'] = filename 191 testlist = list()
192 else:
193 idlist = get_id_list(testlist)
194 if (has_blank_ids(idlist)):
195 for k in testlist:
196 k['filename'] = filename
185 return testlist 197 return testlist
186 198
187 199
@@ -203,7 +215,7 @@ def set_args(parser):
203 help='Run tests only from the specified category, or if no category is specified, list known categories.') 215 help='Run tests only from the specified category, or if no category is specified, list known categories.')
204 parser.add_argument('-f', '--file', type=str, 216 parser.add_argument('-f', '--file', type=str,
205 help='Run tests from the specified file') 217 help='Run tests from the specified file')
206 parser.add_argument('-l', '--list', type=str, nargs='?', const="", metavar='CATEGORY', 218 parser.add_argument('-l', '--list', type=str, nargs='?', const="++", metavar='CATEGORY',
207 help='List all test cases, or those only within the specified category') 219 help='List all test cases, or those only within the specified category')
208 parser.add_argument('-s', '--show', type=str, nargs=1, metavar='ID', dest='showID', 220 parser.add_argument('-s', '--show', type=str, nargs=1, metavar='ID', dest='showID',
209 help='Display the test case with specified id') 221 help='Display the test case with specified id')
@@ -211,7 +223,8 @@ def set_args(parser):
211 help='Execute the single test case with specified ID') 223 help='Execute the single test case with specified ID')
212 parser.add_argument('-i', '--id', action='store_true', dest='gen_id', 224 parser.add_argument('-i', '--id', action='store_true', dest='gen_id',
213 help='Generate ID numbers for new test cases') 225 help='Generate ID numbers for new test cases')
214 return parser 226 parser.add_argument('-d', '--device',
227 help='Execute the test case in flower category')
215 return parser 228 return parser
216 229
217 230
@@ -225,6 +238,8 @@ def check_default_settings(args):
225 238
226 if args.path != None: 239 if args.path != None:
227 NAMES['TC'] = args.path 240 NAMES['TC'] = args.path
241 if args.device != None:
242 NAMES['DEV2'] = args.device
228 if not os.path.isfile(NAMES['TC']): 243 if not os.path.isfile(NAMES['TC']):
229 print("The specified tc path " + NAMES['TC'] + " does not exist.") 244 print("The specified tc path " + NAMES['TC'] + " does not exist.")
230 exit(1) 245 exit(1)
@@ -357,10 +372,10 @@ def set_operation_mode(args):
357 testcases = get_categorized_testlist(alltests, ucat) 372 testcases = get_categorized_testlist(alltests, ucat)
358 373
359 if args.list: 374 if args.list:
360 if (len(args.list) == 0): 375 if (args.list == "++"):
361 list_test_cases(alltests) 376 list_test_cases(alltests)
362 exit(0) 377 exit(0)
363 elif(len(args.list > 0)): 378 elif(len(args.list) > 0):
364 if (args.list not in ucat): 379 if (args.list not in ucat):
365 print("Unknown category " + args.list) 380 print("Unknown category " + args.list)
366 print("Available categories:") 381 print("Available categories:")
@@ -381,14 +396,17 @@ def set_operation_mode(args):
381 if (len(alltests) == 0): 396 if (len(alltests) == 0):
382 print("Cannot find a test case with ID matching " + target_id) 397 print("Cannot find a test case with ID matching " + target_id)
383 exit(1) 398 exit(1)
384 catresults = test_runner(alltests) 399 catresults = test_runner(alltests, args)
385 print("All test results: " + "\n\n" + catresults) 400 print("All test results: " + "\n\n" + catresults)
386 elif (len(target_category) > 0): 401 elif (len(target_category) > 0):
402 if (target_category == "flower") and args.device == None:
403 print("Please specify a NIC device (-d) to run category flower")
404 exit(1)
387 if (target_category not in ucat): 405 if (target_category not in ucat):
388 print("Specified category is not present in this file.") 406 print("Specified category is not present in this file.")
389 exit(1) 407 exit(1)
390 else: 408 else:
391 catresults = test_runner(testcases[target_category]) 409 catresults = test_runner(testcases[target_category], args)
392 print("Category " + target_category + "\n\n" + catresults) 410 print("Category " + target_category + "\n\n" + catresults)
393 411
394 ns_destroy() 412 ns_destroy()
diff --git a/tools/testing/selftests/tc-testing/tdc_batch.py b/tools/testing/selftests/tc-testing/tdc_batch.py
new file mode 100755
index 000000000000..707c6bfef689
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tdc_batch.py
@@ -0,0 +1,62 @@
1#!/usr/bin/python3
2
3"""
4tdc_batch.py - a script to generate TC batch file
5
6Copyright (C) 2017 Chris Mi <chrism@mellanox.com>
7"""
8
9import argparse
10
11parser = argparse.ArgumentParser(description='TC batch file generator')
12parser.add_argument("device", help="device name")
13parser.add_argument("file", help="batch file name")
14parser.add_argument("-n", "--number", type=int,
15 help="how many lines in batch file")
16parser.add_argument("-o", "--skip_sw",
17 help="skip_sw (offload), by default skip_hw",
18 action="store_true")
19parser.add_argument("-s", "--share_action",
20 help="all filters share the same action",
21 action="store_true")
22parser.add_argument("-p", "--prio",
23 help="all filters have different prio",
24 action="store_true")
25args = parser.parse_args()
26
27device = args.device
28file = open(args.file, 'w')
29
30number = 1
31if args.number:
32 number = args.number
33
34skip = "skip_hw"
35if args.skip_sw:
36 skip = "skip_sw"
37
38share_action = ""
39if args.share_action:
40 share_action = "index 1"
41
42prio = "prio 1"
43if args.prio:
44 prio = ""
45 if number > 0x4000:
46 number = 0x4000
47
48index = 0
49for i in range(0x100):
50 for j in range(0x100):
51 for k in range(0x100):
52 mac = ("%02x:%02x:%02x" % (i, j, k))
53 src_mac = "e4:11:00:" + mac
54 dst_mac = "e4:12:00:" + mac
55 cmd = ("filter add dev %s %s protocol ip parent ffff: flower %s "
56 "src_mac %s dst_mac %s action drop %s" %
57 (device, prio, skip, src_mac, dst_mac, share_action))
58 file.write("%s\n" % cmd)
59 index += 1
60 if index >= number:
61 file.close()
62 exit(0)
diff --git a/tools/testing/selftests/tc-testing/tdc_config.py b/tools/testing/selftests/tc-testing/tdc_config.py
index 01087375a7c3..a023d0d62b25 100644
--- a/tools/testing/selftests/tc-testing/tdc_config.py
+++ b/tools/testing/selftests/tc-testing/tdc_config.py
@@ -1,4 +1,5 @@
1""" 1"""
2# SPDX-License-Identifier: GPL-2.0
2tdc_config.py - tdc user-specified values 3tdc_config.py - tdc user-specified values
3 4
4Copyright (C) 2017 Lucas Bates <lucasb@mojatatu.com> 5Copyright (C) 2017 Lucas Bates <lucasb@mojatatu.com>
@@ -12,6 +13,22 @@ NAMES = {
12 # Name of veth devices to be created for the namespace 13 # Name of veth devices to be created for the namespace
13 'DEV0': 'v0p0', 14 'DEV0': 'v0p0',
14 'DEV1': 'v0p1', 15 'DEV1': 'v0p1',
16 'DEV2': '',
17 'BATCH_FILE': './batch.txt',
15 # Name of the namespace to use 18 # Name of the namespace to use
16 'NS': 'tcut' 19 'NS': 'tcut'
17 } 20 }
21
22
23ENVIR = { }
24
25# put customizations in tdc_config_local.py
26try:
27 from tdc_config_local import *
28except ImportError as ie:
29 pass
30
31try:
32 NAMES.update(EXTRA_NAMES)
33except NameError as ne:
34 pass
diff --git a/tools/testing/selftests/tc-testing/tdc_config_local_template.py b/tools/testing/selftests/tc-testing/tdc_config_local_template.py
new file mode 100644
index 000000000000..d48fc732a399
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/tdc_config_local_template.py
@@ -0,0 +1,23 @@
1"""
2tdc_config_local.py - tdc plugin-writer-specified values
3
4Copyright (C) 2017 bjb@mojatatu.com
5"""
6
7import os
8
9ENVIR = os.environ.copy()
10
11ENV_LD_LIBRARY_PATH = os.getenv('LD_LIBRARY_PATH', '')
12ENV_OTHER_LIB = os.getenv('OTHER_LIB', '')
13
14
15# example adding value to NAMES, without editing tdc_config.py
16EXTRA_NAMES = dict()
17EXTRA_NAMES['SOME_BIN'] = os.path.join(os.getenv('OTHER_BIN', ''), 'some_bin')
18
19
20# example adding values to ENVIR, without editing tdc_config.py
21ENVIR['VALGRIND_LIB'] = '/usr/lib/valgrind'
22ENVIR['VALGRIND_BIN'] = '/usr/bin/valgrind'
23ENVIR['VGDB_BIN'] = '/usr/bin/vgdb'
diff --git a/tools/testing/selftests/tc-testing/tdc_helper.py b/tools/testing/selftests/tc-testing/tdc_helper.py
index c3254f861fb2..db381120a566 100644
--- a/tools/testing/selftests/tc-testing/tdc_helper.py
+++ b/tools/testing/selftests/tc-testing/tdc_helper.py
@@ -1,4 +1,5 @@
1""" 1"""
2# SPDX-License-Identifier: GPL-2.0
2tdc_helper.py - tdc helper functions 3tdc_helper.py - tdc helper functions
3 4
4Copyright (C) 2017 Lucas Bates <lucasb@mojatatu.com> 5Copyright (C) 2017 Lucas Bates <lucasb@mojatatu.com>
@@ -15,7 +16,7 @@ def get_categorized_testlist(alltests, ucat):
15 16
16 17
17def get_unique_item(lst): 18def get_unique_item(lst):
18 """ For a list, return a set of the unique items in the list. """ 19 """ For a list, return a list of the unique items in the list. """
19 return list(set(lst)) 20 return list(set(lst))
20 21
21 22
@@ -57,7 +58,7 @@ def print_sll(items):
57def print_test_case(tcase): 58def print_test_case(tcase):
58 """ Pretty-printing of a given test case. """ 59 """ Pretty-printing of a given test case. """
59 for k in tcase.keys(): 60 for k in tcase.keys():
60 if (type(tcase[k]) == list): 61 if (isinstance(tcase[k], list)):
61 print(k + ":") 62 print(k + ":")
62 print_list(tcase[k]) 63 print_list(tcase[k])
63 else: 64 else:
diff --git a/tools/testing/selftests/timers/.gitignore b/tools/testing/selftests/timers/.gitignore
index cc986621f512..2c8ac8416299 100644
--- a/tools/testing/selftests/timers/.gitignore
+++ b/tools/testing/selftests/timers/.gitignore
@@ -18,3 +18,5 @@ threadtest
18valid-adjtimex 18valid-adjtimex
19adjtick 19adjtick
20set-tz 20set-tz
21freq-step
22rtctest_setdate
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index ae4593115408..3496680981f2 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CFLAGS += -O3 -Wl,-no-as-needed -Wall 2CFLAGS += -O3 -Wl,-no-as-needed -Wall
2LDFLAGS += -lrt -lpthread -lm 3LDFLAGS += -lrt -lpthread -lm
3 4
diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testing/selftests/timers/set-timer-lat.c
index 9c92b7bd5641..50da45437daa 100644
--- a/tools/testing/selftests/timers/set-timer-lat.c
+++ b/tools/testing/selftests/timers/set-timer-lat.c
@@ -143,7 +143,8 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
143 printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n", 143 printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n",
144 clockstring(clock_id), 144 clockstring(clock_id),
145 flags ? "ABSTIME":"RELTIME"); 145 flags ? "ABSTIME":"RELTIME");
146 return 0; 146 /* Indicate timer isn't set, so caller doesn't wait */
147 return 1;
147 } 148 }
148 printf("%s - timer_create() failed\n", clockstring(clock_id)); 149 printf("%s - timer_create() failed\n", clockstring(clock_id));
149 return -1; 150 return -1;
@@ -213,8 +214,9 @@ int do_timer(int clock_id, int flags)
213 int err; 214 int err;
214 215
215 err = setup_timer(clock_id, flags, interval, &tm1); 216 err = setup_timer(clock_id, flags, interval, &tm1);
217 /* Unsupported case - return 0 to not fail the test */
216 if (err) 218 if (err)
217 return err; 219 return err == 1 ? 0 : err;
218 220
219 while (alarmcount < 5) 221 while (alarmcount < 5)
220 sleep(1); 222 sleep(1);
@@ -228,18 +230,17 @@ int do_timer_oneshot(int clock_id, int flags)
228 timer_t tm1; 230 timer_t tm1;
229 const int interval = 0; 231 const int interval = 0;
230 struct timeval timeout; 232 struct timeval timeout;
231 fd_set fds;
232 int err; 233 int err;
233 234
234 err = setup_timer(clock_id, flags, interval, &tm1); 235 err = setup_timer(clock_id, flags, interval, &tm1);
236 /* Unsupported case - return 0 to not fail the test */
235 if (err) 237 if (err)
236 return err; 238 return err == 1 ? 0 : err;
237 239
238 memset(&timeout, 0, sizeof(timeout)); 240 memset(&timeout, 0, sizeof(timeout));
239 timeout.tv_sec = 5; 241 timeout.tv_sec = 5;
240 FD_ZERO(&fds);
241 do { 242 do {
242 err = select(FD_SETSIZE, &fds, NULL, NULL, &timeout); 243 err = select(0, NULL, NULL, NULL, &timeout);
243 } while (err == -1 && errno == EINTR); 244 } while (err == -1 && errno == EINTR);
244 245
245 timer_delete(tm1); 246 timer_delete(tm1);
diff --git a/tools/testing/selftests/user/test_user_copy.sh b/tools/testing/selftests/user/test_user_copy.sh
index 350107f40c1d..d60506fc77f8 100755
--- a/tools/testing/selftests/user/test_user_copy.sh
+++ b/tools/testing/selftests/user/test_user_copy.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# Runs copy_to/from_user infrastructure using test_user_copy kernel module 3# Runs copy_to/from_user infrastructure using test_user_copy kernel module
3 4
4if /sbin/modprobe -q test_user_copy; then 5if /sbin/modprobe -q test_user_copy; then
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index 706b68b1c372..3d5a62ff7d31 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1ifndef CROSS_COMPILE 2ifndef CROSS_COMPILE
2CFLAGS := -std=gnu99 3CFLAGS := -std=gnu99
3CFLAGS_vdso_standalone_test_x86 := -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector 4CFLAGS_vdso_standalone_test_x86 := -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector
diff --git a/tools/testing/selftests/vDSO/vdso_test.c b/tools/testing/selftests/vDSO/vdso_test.c
index 8daeb7d7032c..2df26bd0099c 100644
--- a/tools/testing/selftests/vDSO/vdso_test.c
+++ b/tools/testing/selftests/vDSO/vdso_test.c
@@ -19,6 +19,19 @@ extern void *vdso_sym(const char *version, const char *name);
19extern void vdso_init_from_sysinfo_ehdr(uintptr_t base); 19extern void vdso_init_from_sysinfo_ehdr(uintptr_t base);
20extern void vdso_init_from_auxv(void *auxv); 20extern void vdso_init_from_auxv(void *auxv);
21 21
22/*
23 * ARM64's vDSO exports its gettimeofday() implementation with a different
24 * name and version from other architectures, so we need to handle it as
25 * a special case.
26 */
27#if defined(__aarch64__)
28const char *version = "LINUX_2.6.39";
29const char *name = "__kernel_gettimeofday";
30#else
31const char *version = "LINUX_2.6";
32const char *name = "__vdso_gettimeofday";
33#endif
34
22int main(int argc, char **argv) 35int main(int argc, char **argv)
23{ 36{
24 unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR); 37 unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
@@ -31,10 +44,10 @@ int main(int argc, char **argv)
31 44
32 /* Find gettimeofday. */ 45 /* Find gettimeofday. */
33 typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz); 46 typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz);
34 gtod_t gtod = (gtod_t)vdso_sym("LINUX_2.6", "__vdso_gettimeofday"); 47 gtod_t gtod = (gtod_t)vdso_sym(version, name);
35 48
36 if (!gtod) { 49 if (!gtod) {
37 printf("Could not find __vdso_gettimeofday\n"); 50 printf("Could not find %s\n", name);
38 return 1; 51 return 1;
39 } 52 }
40 53
@@ -45,7 +58,7 @@ int main(int argc, char **argv)
45 printf("The time is %lld.%06lld\n", 58 printf("The time is %lld.%06lld\n",
46 (long long)tv.tv_sec, (long long)tv.tv_usec); 59 (long long)tv.tv_sec, (long long)tv.tv_usec);
47 } else { 60 } else {
48 printf("__vdso_gettimeofday failed\n"); 61 printf("%s failed\n", name);
49 } 62 }
50 63
51 return 0; 64 return 0;
diff --git a/tools/testing/selftests/vm/.gitignore b/tools/testing/selftests/vm/.gitignore
index 142c565bb351..1ca2ee4d15b9 100644
--- a/tools/testing/selftests/vm/.gitignore
+++ b/tools/testing/selftests/vm/.gitignore
@@ -8,3 +8,5 @@ on-fault-limit
8transhuge-stress 8transhuge-stress
9userfaultfd 9userfaultfd
10mlock-intersect-test 10mlock-intersect-test
11mlock-random-test
12virtual_address_range
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index cbb29e41ef2b..7f45806bd863 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for vm selftests 2# Makefile for vm selftests
2 3
3ifndef OUTPUT 4ifndef OUTPUT
@@ -17,6 +18,7 @@ TEST_GEN_FILES += transhuge-stress
17TEST_GEN_FILES += userfaultfd 18TEST_GEN_FILES += userfaultfd
18TEST_GEN_FILES += mlock-random-test 19TEST_GEN_FILES += mlock-random-test
19TEST_GEN_FILES += virtual_address_range 20TEST_GEN_FILES += virtual_address_range
21TEST_GEN_FILES += gup_benchmark
20 22
21TEST_PROGS := run_vmtests 23TEST_PROGS := run_vmtests
22 24
diff --git a/tools/testing/selftests/vm/compaction_test.c b/tools/testing/selftests/vm/compaction_test.c
index 6d1437f895b8..a65b016d4c13 100644
--- a/tools/testing/selftests/vm/compaction_test.c
+++ b/tools/testing/selftests/vm/compaction_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * 3 *
3 * A test for the patch "Allow compaction of unevictable pages". 4 * A test for the patch "Allow compaction of unevictable pages".
diff --git a/tools/testing/selftests/vm/gup_benchmark.c b/tools/testing/selftests/vm/gup_benchmark.c
new file mode 100644
index 000000000000..36df55132036
--- /dev/null
+++ b/tools/testing/selftests/vm/gup_benchmark.c
@@ -0,0 +1,91 @@
1#include <fcntl.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5
6#include <sys/ioctl.h>
7#include <sys/mman.h>
8#include <sys/prctl.h>
9#include <sys/stat.h>
10#include <sys/types.h>
11
12#include <linux/types.h>
13
14#define MB (1UL << 20)
15#define PAGE_SIZE sysconf(_SC_PAGESIZE)
16
17#define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark)
18
19struct gup_benchmark {
20 __u64 delta_usec;
21 __u64 addr;
22 __u64 size;
23 __u32 nr_pages_per_call;
24 __u32 flags;
25};
26
27int main(int argc, char **argv)
28{
29 struct gup_benchmark gup;
30 unsigned long size = 128 * MB;
31 int i, fd, opt, nr_pages = 1, thp = -1, repeats = 1, write = 0;
32 char *p;
33
34 while ((opt = getopt(argc, argv, "m:r:n:tT")) != -1) {
35 switch (opt) {
36 case 'm':
37 size = atoi(optarg) * MB;
38 break;
39 case 'r':
40 repeats = atoi(optarg);
41 break;
42 case 'n':
43 nr_pages = atoi(optarg);
44 break;
45 case 't':
46 thp = 1;
47 break;
48 case 'T':
49 thp = 0;
50 break;
51 case 'w':
52 write = 1;
53 default:
54 return -1;
55 }
56 }
57
58 gup.nr_pages_per_call = nr_pages;
59 gup.flags = write;
60
61 fd = open("/sys/kernel/debug/gup_benchmark", O_RDWR);
62 if (fd == -1)
63 perror("open"), exit(1);
64
65 p = mmap(NULL, size, PROT_READ | PROT_WRITE,
66 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
67 if (p == MAP_FAILED)
68 perror("mmap"), exit(1);
69 gup.addr = (unsigned long)p;
70
71 if (thp == 1)
72 madvise(p, size, MADV_HUGEPAGE);
73 else if (thp == 0)
74 madvise(p, size, MADV_NOHUGEPAGE);
75
76 for (; (unsigned long)p < gup.addr + size; p += PAGE_SIZE)
77 p[0] = 0;
78
79 for (i = 0; i < repeats; i++) {
80 gup.size = size;
81 if (ioctl(fd, GUP_FAST_BENCHMARK, &gup))
82 perror("ioctl"), exit(1);
83
84 printf("Time: %lld us", gup.delta_usec);
85 if (gup.size != size)
86 printf(", truncated (size: %lld)", gup.size);
87 printf("\n");
88 }
89
90 return 0;
91}
diff --git a/tools/testing/selftests/vm/hugepage-mmap.c b/tools/testing/selftests/vm/hugepage-mmap.c
index a10f310d2362..93f9e7b81331 100644
--- a/tools/testing/selftests/vm/hugepage-mmap.c
+++ b/tools/testing/selftests/vm/hugepage-mmap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * hugepage-mmap: 3 * hugepage-mmap:
3 * 4 *
diff --git a/tools/testing/selftests/vm/hugepage-shm.c b/tools/testing/selftests/vm/hugepage-shm.c
index 0d0ef4fc0c04..e2527f32005b 100644
--- a/tools/testing/selftests/vm/hugepage-shm.c
+++ b/tools/testing/selftests/vm/hugepage-shm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * hugepage-shm: 3 * hugepage-shm:
3 * 4 *
diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c
index 77687ab59f77..9b777fa95f09 100644
--- a/tools/testing/selftests/vm/map_hugetlb.c
+++ b/tools/testing/selftests/vm/map_hugetlb.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Example of using hugepage memory in a user application using the mmap 3 * Example of using hugepage memory in a user application using the mmap
3 * system call with MAP_HUGETLB flag. Before running this program make 4 * system call with MAP_HUGETLB flag. Before running this program make
diff --git a/tools/testing/selftests/vm/mlock-random-test.c b/tools/testing/selftests/vm/mlock-random-test.c
index 83de4f58d262..ff4d72eb74b9 100644
--- a/tools/testing/selftests/vm/mlock-random-test.c
+++ b/tools/testing/selftests/vm/mlock-random-test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * It tests the mlock/mlock2() when they are invoked 3 * It tests the mlock/mlock2() when they are invoked
3 * on randomly memory region. 4 * on randomly memory region.
diff --git a/tools/testing/selftests/vm/mlock2-tests.c b/tools/testing/selftests/vm/mlock2-tests.c
index e5dbc87b4297..4997b9222cfa 100644
--- a/tools/testing/selftests/vm/mlock2-tests.c
+++ b/tools/testing/selftests/vm/mlock2-tests.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <sys/mman.h> 3#include <sys/mman.h>
3#include <stdint.h> 4#include <stdint.h>
diff --git a/tools/testing/selftests/vm/mlock2.h b/tools/testing/selftests/vm/mlock2.h
index 7ee062929d3e..2a6e76c226bc 100644
--- a/tools/testing/selftests/vm/mlock2.h
+++ b/tools/testing/selftests/vm/mlock2.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <syscall.h> 2#include <syscall.h>
2#include <errno.h> 3#include <errno.h>
3#include <stdio.h> 4#include <stdio.h>
diff --git a/tools/testing/selftests/vm/on-fault-limit.c b/tools/testing/selftests/vm/on-fault-limit.c
index 7f96a5c2e292..634d87dfb2a4 100644
--- a/tools/testing/selftests/vm/on-fault-limit.c
+++ b/tools/testing/selftests/vm/on-fault-limit.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/mman.h> 2#include <sys/mman.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <unistd.h> 4#include <unistd.h>
diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests
index 07548a1fa901..cc826326de87 100755
--- a/tools/testing/selftests/vm/run_vmtests
+++ b/tools/testing/selftests/vm/run_vmtests
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2#please run as root 3#please run as root
3 4
4#we need 256M, below is the size in kB 5#we need 256M, below is the size in kB
diff --git a/tools/testing/selftests/vm/thuge-gen.c b/tools/testing/selftests/vm/thuge-gen.c
index 88a2ab535e01..361ef7192cc6 100644
--- a/tools/testing/selftests/vm/thuge-gen.c
+++ b/tools/testing/selftests/vm/thuge-gen.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Test selecting other page sizes for mmap/shmget. 2/* Test selecting other page sizes for mmap/shmget.
2 3
3 Before running this huge pages for each huge page size must have been 4 Before running this huge pages for each huge page size must have been
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index a2c53a3d223d..de2f9ec8a87f 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -397,7 +397,7 @@ static void retry_copy_page(int ufd, struct uffdio_copy *uffdio_copy,
397 } 397 }
398} 398}
399 399
400static int copy_page(int ufd, unsigned long offset) 400static int __copy_page(int ufd, unsigned long offset, bool retry)
401{ 401{
402 struct uffdio_copy uffdio_copy; 402 struct uffdio_copy uffdio_copy;
403 403
@@ -418,7 +418,7 @@ static int copy_page(int ufd, unsigned long offset)
418 fprintf(stderr, "UFFDIO_COPY unexpected copy %Ld\n", 418 fprintf(stderr, "UFFDIO_COPY unexpected copy %Ld\n",
419 uffdio_copy.copy), exit(1); 419 uffdio_copy.copy), exit(1);
420 } else { 420 } else {
421 if (test_uffdio_copy_eexist) { 421 if (test_uffdio_copy_eexist && retry) {
422 test_uffdio_copy_eexist = false; 422 test_uffdio_copy_eexist = false;
423 retry_copy_page(ufd, &uffdio_copy, offset); 423 retry_copy_page(ufd, &uffdio_copy, offset);
424 } 424 }
@@ -427,6 +427,16 @@ static int copy_page(int ufd, unsigned long offset)
427 return 0; 427 return 0;
428} 428}
429 429
430static int copy_page_retry(int ufd, unsigned long offset)
431{
432 return __copy_page(ufd, offset, true);
433}
434
435static int copy_page(int ufd, unsigned long offset)
436{
437 return __copy_page(ufd, offset, false);
438}
439
430static void *uffd_poll_thread(void *arg) 440static void *uffd_poll_thread(void *arg)
431{ 441{
432 unsigned long cpu = (unsigned long) arg; 442 unsigned long cpu = (unsigned long) arg;
@@ -544,7 +554,7 @@ static void *background_thread(void *arg)
544 for (page_nr = cpu * nr_pages_per_cpu; 554 for (page_nr = cpu * nr_pages_per_cpu;
545 page_nr < (cpu+1) * nr_pages_per_cpu; 555 page_nr < (cpu+1) * nr_pages_per_cpu;
546 page_nr++) 556 page_nr++)
547 copy_page(uffd, page_nr * page_size); 557 copy_page_retry(uffd, page_nr * page_size);
548 558
549 return NULL; 559 return NULL;
550} 560}
@@ -779,7 +789,7 @@ static void retry_uffdio_zeropage(int ufd,
779 } 789 }
780} 790}
781 791
782static int uffdio_zeropage(int ufd, unsigned long offset) 792static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry)
783{ 793{
784 struct uffdio_zeropage uffdio_zeropage; 794 struct uffdio_zeropage uffdio_zeropage;
785 int ret; 795 int ret;
@@ -814,7 +824,7 @@ static int uffdio_zeropage(int ufd, unsigned long offset)
814 fprintf(stderr, "UFFDIO_ZEROPAGE unexpected %Ld\n", 824 fprintf(stderr, "UFFDIO_ZEROPAGE unexpected %Ld\n",
815 uffdio_zeropage.zeropage), exit(1); 825 uffdio_zeropage.zeropage), exit(1);
816 } else { 826 } else {
817 if (test_uffdio_zeropage_eexist) { 827 if (test_uffdio_zeropage_eexist && retry) {
818 test_uffdio_zeropage_eexist = false; 828 test_uffdio_zeropage_eexist = false;
819 retry_uffdio_zeropage(ufd, &uffdio_zeropage, 829 retry_uffdio_zeropage(ufd, &uffdio_zeropage,
820 offset); 830 offset);
@@ -830,6 +840,11 @@ static int uffdio_zeropage(int ufd, unsigned long offset)
830 return 0; 840 return 0;
831} 841}
832 842
843static int uffdio_zeropage(int ufd, unsigned long offset)
844{
845 return __uffdio_zeropage(ufd, offset, false);
846}
847
833/* exercise UFFDIO_ZEROPAGE */ 848/* exercise UFFDIO_ZEROPAGE */
834static int userfaultfd_zeropage_test(void) 849static int userfaultfd_zeropage_test(void)
835{ 850{
diff --git a/tools/testing/selftests/watchdog/Makefile b/tools/testing/selftests/watchdog/Makefile
index f863c664e3d1..6b5598b55252 100644
--- a/tools/testing/selftests/watchdog/Makefile
+++ b/tools/testing/selftests/watchdog/Makefile
@@ -1,8 +1,4 @@
1TEST_PROGS := watchdog-test 1# SPDX-License-Identifier: GPL-2.0
2 2TEST_GEN_PROGS := watchdog-test
3all: $(TEST_PROGS)
4 3
5include ../lib.mk 4include ../lib.mk
6
7clean:
8 rm -fr $(TEST_PROGS)
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index a1391be2dc1e..6e290874b70e 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Watchdog Driver Test Program 3 * Watchdog Driver Test Program
3 */ 4 */
diff --git a/tools/testing/selftests/x86/5lvl.c b/tools/testing/selftests/x86/5lvl.c
new file mode 100644
index 000000000000..2eafdcd4c2b3
--- /dev/null
+++ b/tools/testing/selftests/x86/5lvl.c
@@ -0,0 +1,177 @@
1#include <stdio.h>
2#include <sys/mman.h>
3
4#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
5
6#define PAGE_SIZE 4096
7#define LOW_ADDR ((void *) (1UL << 30))
8#define HIGH_ADDR ((void *) (1UL << 50))
9
10struct testcase {
11 void *addr;
12 unsigned long size;
13 unsigned long flags;
14 const char *msg;
15 unsigned int low_addr_required:1;
16 unsigned int keep_mapped:1;
17};
18
19static struct testcase testcases[] = {
20 {
21 .addr = NULL,
22 .size = 2 * PAGE_SIZE,
23 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
24 .msg = "mmap(NULL)",
25 .low_addr_required = 1,
26 },
27 {
28 .addr = LOW_ADDR,
29 .size = 2 * PAGE_SIZE,
30 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
31 .msg = "mmap(LOW_ADDR)",
32 .low_addr_required = 1,
33 },
34 {
35 .addr = HIGH_ADDR,
36 .size = 2 * PAGE_SIZE,
37 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
38 .msg = "mmap(HIGH_ADDR)",
39 .keep_mapped = 1,
40 },
41 {
42 .addr = HIGH_ADDR,
43 .size = 2 * PAGE_SIZE,
44 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
45 .msg = "mmap(HIGH_ADDR) again",
46 .keep_mapped = 1,
47 },
48 {
49 .addr = HIGH_ADDR,
50 .size = 2 * PAGE_SIZE,
51 .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
52 .msg = "mmap(HIGH_ADDR, MAP_FIXED)",
53 },
54 {
55 .addr = (void*) -1,
56 .size = 2 * PAGE_SIZE,
57 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
58 .msg = "mmap(-1)",
59 .keep_mapped = 1,
60 },
61 {
62 .addr = (void*) -1,
63 .size = 2 * PAGE_SIZE,
64 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
65 .msg = "mmap(-1) again",
66 },
67 {
68 .addr = (void *)((1UL << 47) - PAGE_SIZE),
69 .size = 2 * PAGE_SIZE,
70 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
71 .msg = "mmap((1UL << 47), 2 * PAGE_SIZE)",
72 .low_addr_required = 1,
73 .keep_mapped = 1,
74 },
75 {
76 .addr = (void *)((1UL << 47) - PAGE_SIZE / 2),
77 .size = 2 * PAGE_SIZE,
78 .flags = MAP_PRIVATE | MAP_ANONYMOUS,
79 .msg = "mmap((1UL << 47), 2 * PAGE_SIZE / 2)",
80 .low_addr_required = 1,
81 .keep_mapped = 1,
82 },
83 {
84 .addr = (void *)((1UL << 47) - PAGE_SIZE),
85 .size = 2 * PAGE_SIZE,
86 .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
87 .msg = "mmap((1UL << 47) - PAGE_SIZE, 2 * PAGE_SIZE, MAP_FIXED)",
88 },
89 {
90 .addr = NULL,
91 .size = 2UL << 20,
92 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS,
93 .msg = "mmap(NULL, MAP_HUGETLB)",
94 .low_addr_required = 1,
95 },
96 {
97 .addr = LOW_ADDR,
98 .size = 2UL << 20,
99 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS,
100 .msg = "mmap(LOW_ADDR, MAP_HUGETLB)",
101 .low_addr_required = 1,
102 },
103 {
104 .addr = HIGH_ADDR,
105 .size = 2UL << 20,
106 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS,
107 .msg = "mmap(HIGH_ADDR, MAP_HUGETLB)",
108 .keep_mapped = 1,
109 },
110 {
111 .addr = HIGH_ADDR,
112 .size = 2UL << 20,
113 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS,
114 .msg = "mmap(HIGH_ADDR, MAP_HUGETLB) again",
115 .keep_mapped = 1,
116 },
117 {
118 .addr = HIGH_ADDR,
119 .size = 2UL << 20,
120 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
121 .msg = "mmap(HIGH_ADDR, MAP_FIXED | MAP_HUGETLB)",
122 },
123 {
124 .addr = (void*) -1,
125 .size = 2UL << 20,
126 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS,
127 .msg = "mmap(-1, MAP_HUGETLB)",
128 .keep_mapped = 1,
129 },
130 {
131 .addr = (void*) -1,
132 .size = 2UL << 20,
133 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS,
134 .msg = "mmap(-1, MAP_HUGETLB) again",
135 },
136 {
137 .addr = (void *)((1UL << 47) - PAGE_SIZE),
138 .size = 4UL << 20,
139 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS,
140 .msg = "mmap((1UL << 47), 4UL << 20, MAP_HUGETLB)",
141 .low_addr_required = 1,
142 .keep_mapped = 1,
143 },
144 {
145 .addr = (void *)((1UL << 47) - (2UL << 20)),
146 .size = 4UL << 20,
147 .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
148 .msg = "mmap((1UL << 47) - (2UL << 20), 4UL << 20, MAP_FIXED | MAP_HUGETLB)",
149 },
150};
151
152int main(int argc, char **argv)
153{
154 int i;
155 void *p;
156
157 for (i = 0; i < ARRAY_SIZE(testcases); i++) {
158 struct testcase *t = testcases + i;
159
160 p = mmap(t->addr, t->size, PROT_NONE, t->flags, -1, 0);
161
162 printf("%s: %p - ", t->msg, p);
163
164 if (p == MAP_FAILED) {
165 printf("FAILED\n");
166 continue;
167 }
168
169 if (t->low_addr_required && p >= (void *)(1UL << 47))
170 printf("FAILED\n");
171 else
172 printf("OK\n");
173 if (!t->keep_mapped)
174 munmap(p, t->size);
175 }
176 return 0;
177}
diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile
index 97f187e2663f..939a337128db 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: 2all:
2 3
3include ../lib.mk 4include ../lib.mk
@@ -10,7 +11,7 @@ TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_sysc
10TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \ 11TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
11 test_FCMOV test_FCOMI test_FISTTP \ 12 test_FCMOV test_FCOMI test_FISTTP \
12 vdso_restorer 13 vdso_restorer
13TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip 14TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip 5lvl
14 15
15TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) 16TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
16TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY) 17TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
@@ -20,7 +21,7 @@ BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
20BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) 21BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
21BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) 22BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
22 23
23CFLAGS := -O2 -g -std=gnu99 -pthread -Wall 24CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
24 25
25UNAME_M := $(shell uname -m) 26UNAME_M := $(shell uname -m)
26CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32) 27CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c
index d075ea0e5ca1..361466a2eaef 100644
--- a/tools/testing/selftests/x86/entry_from_vm86.c
+++ b/tools/testing/selftests/x86/entry_from_vm86.c
@@ -95,6 +95,27 @@ asm (
95 "int3\n\t" 95 "int3\n\t"
96 "vmcode_int80:\n\t" 96 "vmcode_int80:\n\t"
97 "int $0x80\n\t" 97 "int $0x80\n\t"
98 "vmcode_umip:\n\t"
99 /* addressing via displacements */
100 "smsw (2052)\n\t"
101 "sidt (2054)\n\t"
102 "sgdt (2060)\n\t"
103 /* addressing via registers */
104 "mov $2066, %bx\n\t"
105 "smsw (%bx)\n\t"
106 "mov $2068, %bx\n\t"
107 "sidt (%bx)\n\t"
108 "mov $2074, %bx\n\t"
109 "sgdt (%bx)\n\t"
110 /* register operands, only for smsw */
111 "smsw %ax\n\t"
112 "mov %ax, (2080)\n\t"
113 "int3\n\t"
114 "vmcode_umip_str:\n\t"
115 "str %eax\n\t"
116 "vmcode_umip_sldt:\n\t"
117 "sldt %eax\n\t"
118 "int3\n\t"
98 ".size vmcode, . - vmcode\n\t" 119 ".size vmcode, . - vmcode\n\t"
99 "end_vmcode:\n\t" 120 "end_vmcode:\n\t"
100 ".code32\n\t" 121 ".code32\n\t"
@@ -103,7 +124,8 @@ asm (
103 124
104extern unsigned char vmcode[], end_vmcode[]; 125extern unsigned char vmcode[], end_vmcode[];
105extern unsigned char vmcode_bound[], vmcode_sysenter[], vmcode_syscall[], 126extern unsigned char vmcode_bound[], vmcode_sysenter[], vmcode_syscall[],
106 vmcode_sti[], vmcode_int3[], vmcode_int80[]; 127 vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_umip[],
128 vmcode_umip_str[], vmcode_umip_sldt[];
107 129
108/* Returns false if the test was skipped. */ 130/* Returns false if the test was skipped. */
109static bool do_test(struct vm86plus_struct *v86, unsigned long eip, 131static bool do_test(struct vm86plus_struct *v86, unsigned long eip,
@@ -160,6 +182,68 @@ static bool do_test(struct vm86plus_struct *v86, unsigned long eip,
160 return true; 182 return true;
161} 183}
162 184
185void do_umip_tests(struct vm86plus_struct *vm86, unsigned char *test_mem)
186{
187 struct table_desc {
188 unsigned short limit;
189 unsigned long base;
190 } __attribute__((packed));
191
192 /* Initialize variables with arbitrary values */
193 struct table_desc gdt1 = { .base = 0x3c3c3c3c, .limit = 0x9999 };
194 struct table_desc gdt2 = { .base = 0x1a1a1a1a, .limit = 0xaeae };
195 struct table_desc idt1 = { .base = 0x7b7b7b7b, .limit = 0xf1f1 };
196 struct table_desc idt2 = { .base = 0x89898989, .limit = 0x1313 };
197 unsigned short msw1 = 0x1414, msw2 = 0x2525, msw3 = 3737;
198
199 /* UMIP -- exit with INT3 unless kernel emulation did not trap #GP */
200 do_test(vm86, vmcode_umip - vmcode, VM86_TRAP, 3, "UMIP tests");
201
202 /* Results from displacement-only addressing */
203 msw1 = *(unsigned short *)(test_mem + 2052);
204 memcpy(&idt1, test_mem + 2054, sizeof(idt1));
205 memcpy(&gdt1, test_mem + 2060, sizeof(gdt1));
206
207 /* Results from register-indirect addressing */
208 msw2 = *(unsigned short *)(test_mem + 2066);
209 memcpy(&idt2, test_mem + 2068, sizeof(idt2));
210 memcpy(&gdt2, test_mem + 2074, sizeof(gdt2));
211
212 /* Results when using register operands */
213 msw3 = *(unsigned short *)(test_mem + 2080);
214
215 printf("[INFO]\tResult from SMSW:[0x%04x]\n", msw1);
216 printf("[INFO]\tResult from SIDT: limit[0x%04x]base[0x%08lx]\n",
217 idt1.limit, idt1.base);
218 printf("[INFO]\tResult from SGDT: limit[0x%04x]base[0x%08lx]\n",
219 gdt1.limit, gdt1.base);
220
221 if (msw1 != msw2 || msw1 != msw3)
222 printf("[FAIL]\tAll the results of SMSW should be the same.\n");
223 else
224 printf("[PASS]\tAll the results from SMSW are identical.\n");
225
226 if (memcmp(&gdt1, &gdt2, sizeof(gdt1)))
227 printf("[FAIL]\tAll the results of SGDT should be the same.\n");
228 else
229 printf("[PASS]\tAll the results from SGDT are identical.\n");
230
231 if (memcmp(&idt1, &idt2, sizeof(idt1)))
232 printf("[FAIL]\tAll the results of SIDT should be the same.\n");
233 else
234 printf("[PASS]\tAll the results from SIDT are identical.\n");
235
236 sethandler(SIGILL, sighandler, 0);
237 do_test(vm86, vmcode_umip_str - vmcode, VM86_SIGNAL, 0,
238 "STR instruction");
239 clearhandler(SIGILL);
240
241 sethandler(SIGILL, sighandler, 0);
242 do_test(vm86, vmcode_umip_sldt - vmcode, VM86_SIGNAL, 0,
243 "SLDT instruction");
244 clearhandler(SIGILL);
245}
246
163int main(void) 247int main(void)
164{ 248{
165 struct vm86plus_struct v86; 249 struct vm86plus_struct v86;
@@ -218,6 +302,9 @@ int main(void)
218 v86.regs.eax = (unsigned int)-1; 302 v86.regs.eax = (unsigned int)-1;
219 do_test(&v86, vmcode_int80 - vmcode, VM86_INTx, 0x80, "int80"); 303 do_test(&v86, vmcode_int80 - vmcode, VM86_INTx, 0x80, "int80");
220 304
305 /* UMIP -- should exit with INTx 0x80 unless UMIP was not disabled */
306 do_umip_tests(&v86, addr);
307
221 /* Execute a null pointer */ 308 /* Execute a null pointer */
222 v86.regs.cs = 0; 309 v86.regs.cs = 0;
223 v86.regs.ss = 0; 310 v86.regs.ss = 0;
diff --git a/tools/testing/selftests/x86/ioperm.c b/tools/testing/selftests/x86/ioperm.c
index b77313ba2ab1..01de41c1b725 100644
--- a/tools/testing/selftests/x86/ioperm.c
+++ b/tools/testing/selftests/x86/ioperm.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * ioperm.c - Test case for ioperm(2) 3 * ioperm.c - Test case for ioperm(2)
3 * Copyright (c) 2015 Andrew Lutomirski 4 * Copyright (c) 2015 Andrew Lutomirski
diff --git a/tools/testing/selftests/x86/iopl.c b/tools/testing/selftests/x86/iopl.c
index c496ca97bc18..6aa27f34644c 100644
--- a/tools/testing/selftests/x86/iopl.c
+++ b/tools/testing/selftests/x86/iopl.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * iopl.c - Test case for a Linux on Xen 64-bit bug 3 * iopl.c - Test case for a Linux on Xen 64-bit bug
3 * Copyright (c) 2015 Andrew Lutomirski 4 * Copyright (c) 2015 Andrew Lutomirski
diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
index b9a22f18566a..66e5ce5b91f0 100644
--- a/tools/testing/selftests/x86/ldt_gdt.c
+++ b/tools/testing/selftests/x86/ldt_gdt.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * ldt_gdt.c - Test cases for LDT and GDT access 3 * ldt_gdt.c - Test cases for LDT and GDT access
3 * Copyright (c) 2015 Andrew Lutomirski 4 * Copyright (c) 2015 Andrew Lutomirski
@@ -114,7 +115,15 @@ static void check_valid_segment(uint16_t index, int ldt,
114 return; 115 return;
115 } 116 }
116 117
117 if (ar != expected_ar) { 118 /* The SDM says "bits 19:16 are undefined". Thanks. */
119 ar &= ~0xF0000;
120
121 /*
122 * NB: Different Linux versions do different things with the
123 * accessed bit in set_thread_area().
124 */
125 if (ar != expected_ar &&
126 (ldt || ar != (expected_ar | AR_ACCESSED))) {
118 printf("[FAIL]\t%s entry %hu has AR 0x%08X but expected 0x%08X\n", 127 printf("[FAIL]\t%s entry %hu has AR 0x%08X but expected 0x%08X\n",
119 (ldt ? "LDT" : "GDT"), index, ar, expected_ar); 128 (ldt ? "LDT" : "GDT"), index, ar, expected_ar);
120 nerrs++; 129 nerrs++;
@@ -128,30 +137,51 @@ static void check_valid_segment(uint16_t index, int ldt,
128 } 137 }
129} 138}
130 139
131static bool install_valid_mode(const struct user_desc *desc, uint32_t ar, 140static bool install_valid_mode(const struct user_desc *d, uint32_t ar,
132 bool oldmode) 141 bool oldmode, bool ldt)
133{ 142{
134 int ret = syscall(SYS_modify_ldt, oldmode ? 1 : 0x11, 143 struct user_desc desc = *d;
135 desc, sizeof(*desc)); 144 int ret;
136 if (ret < -1) 145
137 errno = -ret; 146 if (!ldt) {
147#ifndef __i386__
148 /* No point testing set_thread_area in a 64-bit build */
149 return false;
150#endif
151 if (!gdt_entry_num)
152 return false;
153 desc.entry_number = gdt_entry_num;
154
155 ret = syscall(SYS_set_thread_area, &desc);
156 } else {
157 ret = syscall(SYS_modify_ldt, oldmode ? 1 : 0x11,
158 &desc, sizeof(desc));
159
160 if (ret < -1)
161 errno = -ret;
162
163 if (ret != 0 && errno == ENOSYS) {
164 printf("[OK]\tmodify_ldt returned -ENOSYS\n");
165 return false;
166 }
167 }
168
138 if (ret == 0) { 169 if (ret == 0) {
139 uint32_t limit = desc->limit; 170 uint32_t limit = desc.limit;
140 if (desc->limit_in_pages) 171 if (desc.limit_in_pages)
141 limit = (limit << 12) + 4095; 172 limit = (limit << 12) + 4095;
142 check_valid_segment(desc->entry_number, 1, ar, limit, true); 173 check_valid_segment(desc.entry_number, ldt, ar, limit, true);
143 return true; 174 return true;
144 } else if (errno == ENOSYS) {
145 printf("[OK]\tmodify_ldt returned -ENOSYS\n");
146 return false;
147 } else { 175 } else {
148 if (desc->seg_32bit) { 176 if (desc.seg_32bit) {
149 printf("[FAIL]\tUnexpected modify_ldt failure %d\n", 177 printf("[FAIL]\tUnexpected %s failure %d\n",
178 ldt ? "modify_ldt" : "set_thread_area",
150 errno); 179 errno);
151 nerrs++; 180 nerrs++;
152 return false; 181 return false;
153 } else { 182 } else {
154 printf("[OK]\tmodify_ldt rejected 16 bit segment\n"); 183 printf("[OK]\t%s rejected 16 bit segment\n",
184 ldt ? "modify_ldt" : "set_thread_area");
155 return false; 185 return false;
156 } 186 }
157 } 187 }
@@ -159,7 +189,15 @@ static bool install_valid_mode(const struct user_desc *desc, uint32_t ar,
159 189
160static bool install_valid(const struct user_desc *desc, uint32_t ar) 190static bool install_valid(const struct user_desc *desc, uint32_t ar)
161{ 191{
162 return install_valid_mode(desc, ar, false); 192 bool ret = install_valid_mode(desc, ar, false, true);
193
194 if (desc->contents <= 1 && desc->seg_32bit &&
195 !desc->seg_not_present) {
196 /* Should work in the GDT, too. */
197 install_valid_mode(desc, ar, false, false);
198 }
199
200 return ret;
163} 201}
164 202
165static void install_invalid(const struct user_desc *desc, bool oldmode) 203static void install_invalid(const struct user_desc *desc, bool oldmode)
@@ -366,9 +404,24 @@ static void do_simple_tests(void)
366 install_invalid(&desc, false); 404 install_invalid(&desc, false);
367 405
368 desc.seg_not_present = 0; 406 desc.seg_not_present = 0;
369 desc.read_exec_only = 0;
370 desc.seg_32bit = 1; 407 desc.seg_32bit = 1;
408 desc.read_exec_only = 0;
409 desc.limit = 0xfffff;
410
371 install_valid(&desc, AR_DPL3 | AR_TYPE_RWDATA | AR_S | AR_P | AR_DB); 411 install_valid(&desc, AR_DPL3 | AR_TYPE_RWDATA | AR_S | AR_P | AR_DB);
412
413 desc.limit_in_pages = 1;
414
415 install_valid(&desc, AR_DPL3 | AR_TYPE_RWDATA | AR_S | AR_P | AR_DB | AR_G);
416 desc.read_exec_only = 1;
417 install_valid(&desc, AR_DPL3 | AR_TYPE_RODATA | AR_S | AR_P | AR_DB | AR_G);
418 desc.contents = 1;
419 desc.read_exec_only = 0;
420 install_valid(&desc, AR_DPL3 | AR_TYPE_RWDATA_EXPDOWN | AR_S | AR_P | AR_DB | AR_G);
421 desc.read_exec_only = 1;
422 install_valid(&desc, AR_DPL3 | AR_TYPE_RODATA_EXPDOWN | AR_S | AR_P | AR_DB | AR_G);
423
424 desc.limit = 0;
372 install_invalid(&desc, true); 425 install_invalid(&desc, true);
373} 426}
374 427
diff --git a/tools/testing/selftests/x86/mpx-debug.h b/tools/testing/selftests/x86/mpx-debug.h
index 9230981f2e12..7546eba7f17a 100644
--- a/tools/testing/selftests/x86/mpx-debug.h
+++ b/tools/testing/selftests/x86/mpx-debug.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _MPX_DEBUG_H 2#ifndef _MPX_DEBUG_H
2#define _MPX_DEBUG_H 3#define _MPX_DEBUG_H
3 4
diff --git a/tools/testing/selftests/x86/mpx-dig.c b/tools/testing/selftests/x86/mpx-dig.c
index ce85356d7e2e..c13607ef5c11 100644
--- a/tools/testing/selftests/x86/mpx-dig.c
+++ b/tools/testing/selftests/x86/mpx-dig.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Written by Dave Hansen <dave.hansen@intel.com> 3 * Written by Dave Hansen <dave.hansen@intel.com>
3 */ 4 */
diff --git a/tools/testing/selftests/x86/mpx-hw.h b/tools/testing/selftests/x86/mpx-hw.h
index 093c190178a9..d1b61ab870f8 100644
--- a/tools/testing/selftests/x86/mpx-hw.h
+++ b/tools/testing/selftests/x86/mpx-hw.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _MPX_HW_H 2#ifndef _MPX_HW_H
2#define _MPX_HW_H 3#define _MPX_HW_H
3 4
@@ -51,14 +52,14 @@
51struct mpx_bd_entry { 52struct mpx_bd_entry {
52 union { 53 union {
53 char x[MPX_BOUNDS_DIR_ENTRY_SIZE_BYTES]; 54 char x[MPX_BOUNDS_DIR_ENTRY_SIZE_BYTES];
54 void *contents[1]; 55 void *contents[0];
55 }; 56 };
56} __attribute__((packed)); 57} __attribute__((packed));
57 58
58struct mpx_bt_entry { 59struct mpx_bt_entry {
59 union { 60 union {
60 char x[MPX_BOUNDS_TABLE_ENTRY_SIZE_BYTES]; 61 char x[MPX_BOUNDS_TABLE_ENTRY_SIZE_BYTES];
61 unsigned long contents[1]; 62 unsigned long contents[0];
62 }; 63 };
63} __attribute__((packed)); 64} __attribute__((packed));
64 65
diff --git a/tools/testing/selftests/x86/mpx-mm.h b/tools/testing/selftests/x86/mpx-mm.h
index af706a5398f7..6dbdd66b8242 100644
--- a/tools/testing/selftests/x86/mpx-mm.h
+++ b/tools/testing/selftests/x86/mpx-mm.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _MPX_MM_H 2#ifndef _MPX_MM_H
2#define _MPX_MM_H 3#define _MPX_MM_H
3 4
diff --git a/tools/testing/selftests/x86/pkey-helpers.h b/tools/testing/selftests/x86/pkey-helpers.h
index b20293956eec..b3cb7670e026 100644
--- a/tools/testing/selftests/x86/pkey-helpers.h
+++ b/tools/testing/selftests/x86/pkey-helpers.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _PKEYS_HELPER_H 2#ifndef _PKEYS_HELPER_H
2#define _PKEYS_HELPER_H 3#define _PKEYS_HELPER_H
3#define _GNU_SOURCE 4#define _GNU_SOURCE
@@ -29,6 +30,7 @@ static inline void sigsafe_printf(const char *format, ...)
29 if (!dprint_in_signal) { 30 if (!dprint_in_signal) {
30 vprintf(format, ap); 31 vprintf(format, ap);
31 } else { 32 } else {
33 int ret;
32 int len = vsnprintf(dprint_in_signal_buffer, 34 int len = vsnprintf(dprint_in_signal_buffer,
33 DPRINT_IN_SIGNAL_BUF_SIZE, 35 DPRINT_IN_SIGNAL_BUF_SIZE,
34 format, ap); 36 format, ap);
@@ -38,7 +40,9 @@ static inline void sigsafe_printf(const char *format, ...)
38 */ 40 */
39 if (len > DPRINT_IN_SIGNAL_BUF_SIZE) 41 if (len > DPRINT_IN_SIGNAL_BUF_SIZE)
40 len = DPRINT_IN_SIGNAL_BUF_SIZE; 42 len = DPRINT_IN_SIGNAL_BUF_SIZE;
41 write(1, dprint_in_signal_buffer, len); 43 ret = write(1, dprint_in_signal_buffer, len);
44 if (ret < 0)
45 abort();
42 } 46 }
43 va_end(ap); 47 va_end(ap);
44} 48}
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c
index 23927845518d..bc1b0735bb50 100644
--- a/tools/testing/selftests/x86/protection_keys.c
+++ b/tools/testing/selftests/x86/protection_keys.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Tests x86 Memory Protection Keys (see Documentation/x86/protection-keys.txt) 3 * Tests x86 Memory Protection Keys (see Documentation/x86/protection-keys.txt)
3 * 4 *
@@ -188,17 +189,29 @@ void lots_o_noops_around_write(int *write_to_me)
188#define u64 uint64_t 189#define u64 uint64_t
189 190
190#ifdef __i386__ 191#ifdef __i386__
191#define SYS_mprotect_key 380 192
192#define SYS_pkey_alloc 381 193#ifndef SYS_mprotect_key
193#define SYS_pkey_free 382 194# define SYS_mprotect_key 380
195#endif
196#ifndef SYS_pkey_alloc
197# define SYS_pkey_alloc 381
198# define SYS_pkey_free 382
199#endif
194#define REG_IP_IDX REG_EIP 200#define REG_IP_IDX REG_EIP
195#define si_pkey_offset 0x14 201#define si_pkey_offset 0x14
202
196#else 203#else
197#define SYS_mprotect_key 329 204
198#define SYS_pkey_alloc 330 205#ifndef SYS_mprotect_key
199#define SYS_pkey_free 331 206# define SYS_mprotect_key 329
207#endif
208#ifndef SYS_pkey_alloc
209# define SYS_pkey_alloc 330
210# define SYS_pkey_free 331
211#endif
200#define REG_IP_IDX REG_RIP 212#define REG_IP_IDX REG_RIP
201#define si_pkey_offset 0x20 213#define si_pkey_offset 0x20
214
202#endif 215#endif
203 216
204void dump_mem(void *dumpme, int len_bytes) 217void dump_mem(void *dumpme, int len_bytes)
@@ -237,7 +250,7 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext)
237 unsigned long ip; 250 unsigned long ip;
238 char *fpregs; 251 char *fpregs;
239 u32 *pkru_ptr; 252 u32 *pkru_ptr;
240 u64 si_pkey; 253 u64 siginfo_pkey;
241 u32 *si_pkey_ptr; 254 u32 *si_pkey_ptr;
242 int pkru_offset; 255 int pkru_offset;
243 fpregset_t fpregset; 256 fpregset_t fpregset;
@@ -279,9 +292,9 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext)
279 si_pkey_ptr = (u32 *)(((u8 *)si) + si_pkey_offset); 292 si_pkey_ptr = (u32 *)(((u8 *)si) + si_pkey_offset);
280 dprintf1("si_pkey_ptr: %p\n", si_pkey_ptr); 293 dprintf1("si_pkey_ptr: %p\n", si_pkey_ptr);
281 dump_mem(si_pkey_ptr - 8, 24); 294 dump_mem(si_pkey_ptr - 8, 24);
282 si_pkey = *si_pkey_ptr; 295 siginfo_pkey = *si_pkey_ptr;
283 pkey_assert(si_pkey < NR_PKEYS); 296 pkey_assert(siginfo_pkey < NR_PKEYS);
284 last_si_pkey = si_pkey; 297 last_si_pkey = siginfo_pkey;
285 298
286 if ((si->si_code == SEGV_MAPERR) || 299 if ((si->si_code == SEGV_MAPERR) ||
287 (si->si_code == SEGV_ACCERR) || 300 (si->si_code == SEGV_ACCERR) ||
@@ -293,7 +306,7 @@ void signal_handler(int signum, siginfo_t *si, void *vucontext)
293 dprintf1("signal pkru from xsave: %08x\n", *pkru_ptr); 306 dprintf1("signal pkru from xsave: %08x\n", *pkru_ptr);
294 /* need __rdpkru() version so we do not do shadow_pkru checking */ 307 /* need __rdpkru() version so we do not do shadow_pkru checking */
295 dprintf1("signal pkru from pkru: %08x\n", __rdpkru()); 308 dprintf1("signal pkru from pkru: %08x\n", __rdpkru());
296 dprintf1("si_pkey from siginfo: %jx\n", si_pkey); 309 dprintf1("pkey from siginfo: %jx\n", siginfo_pkey);
297 *(u64 *)pkru_ptr = 0x00000000; 310 *(u64 *)pkru_ptr = 0x00000000;
298 dprintf1("WARNING: set PRKU=0 to allow faulting instruction to continue\n"); 311 dprintf1("WARNING: set PRKU=0 to allow faulting instruction to continue\n");
299 pkru_faults++; 312 pkru_faults++;
diff --git a/tools/testing/selftests/x86/ptrace_syscall.c b/tools/testing/selftests/x86/ptrace_syscall.c
index eaea92439708..1ae1c5a7392e 100644
--- a/tools/testing/selftests/x86/ptrace_syscall.c
+++ b/tools/testing/selftests/x86/ptrace_syscall.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2 3
3#include <sys/ptrace.h> 4#include <sys/ptrace.h>
diff --git a/tools/testing/selftests/x86/raw_syscall_helper_32.S b/tools/testing/selftests/x86/raw_syscall_helper_32.S
index 534e71e35c6a..94410fa2b5ed 100644
--- a/tools/testing/selftests/x86/raw_syscall_helper_32.S
+++ b/tools/testing/selftests/x86/raw_syscall_helper_32.S
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1.global sys32_helper 2.global sys32_helper
2sys32_helper: 3sys32_helper:
3 /* Args: syscall_args_32*, function pointer */ 4 /* Args: syscall_args_32*, function pointer */
diff --git a/tools/testing/selftests/x86/test_FCMOV.c b/tools/testing/selftests/x86/test_FCMOV.c
index 4adcca0c80c4..6b5036fbb735 100644
--- a/tools/testing/selftests/x86/test_FCMOV.c
+++ b/tools/testing/selftests/x86/test_FCMOV.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#undef _GNU_SOURCE 2#undef _GNU_SOURCE
2#define _GNU_SOURCE 1 3#define _GNU_SOURCE 1
3#undef __USE_GNU 4#undef __USE_GNU
diff --git a/tools/testing/selftests/x86/test_FCOMI.c b/tools/testing/selftests/x86/test_FCOMI.c
index db4933e31af9..aec6692c6dcf 100644
--- a/tools/testing/selftests/x86/test_FCOMI.c
+++ b/tools/testing/selftests/x86/test_FCOMI.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#undef _GNU_SOURCE 2#undef _GNU_SOURCE
2#define _GNU_SOURCE 1 3#define _GNU_SOURCE 1
3#undef __USE_GNU 4#undef __USE_GNU
diff --git a/tools/testing/selftests/x86/test_FISTTP.c b/tools/testing/selftests/x86/test_FISTTP.c
index b8e61a047f6b..09789c0ce3e9 100644
--- a/tools/testing/selftests/x86/test_FISTTP.c
+++ b/tools/testing/selftests/x86/test_FISTTP.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#undef _GNU_SOURCE 2#undef _GNU_SOURCE
2#define _GNU_SOURCE 1 3#define _GNU_SOURCE 1
3#undef __USE_GNU 4#undef __USE_GNU
diff --git a/tools/testing/selftests/x86/test_vdso.c b/tools/testing/selftests/x86/test_vdso.c
index 65d7a2bf7e14..29973cde06d3 100644
--- a/tools/testing/selftests/x86/test_vdso.c
+++ b/tools/testing/selftests/x86/test_vdso.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * ldt_gdt.c - Test cases for LDT and GDT access 3 * ldt_gdt.c - Test cases for LDT and GDT access
3 * Copyright (c) 2011-2015 Andrew Lutomirski 4 * Copyright (c) 2011-2015 Andrew Lutomirski
diff --git a/tools/testing/selftests/zram/Makefile b/tools/testing/selftests/zram/Makefile
index c3a87e5f9d36..7f78eb1b59cb 100644
--- a/tools/testing/selftests/zram/Makefile
+++ b/tools/testing/selftests/zram/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: 2all:
2 3
3TEST_PROGS := zram.sh 4TEST_PROGS := zram.sh
diff --git a/tools/testing/selftests/zram/zram.sh b/tools/testing/selftests/zram/zram.sh
index 683a292e3290..754de7da426a 100755
--- a/tools/testing/selftests/zram/zram.sh
+++ b/tools/testing/selftests/zram/zram.sh
@@ -1,4 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
2TCID="zram.sh" 3TCID="zram.sh"
3 4
4. ./zram_lib.sh 5. ./zram_lib.sh
diff --git a/tools/testing/vsock/.gitignore b/tools/testing/vsock/.gitignore
new file mode 100644
index 000000000000..dc5f11faf530
--- /dev/null
+++ b/tools/testing/vsock/.gitignore
@@ -0,0 +1,2 @@
1*.d
2vsock_diag_test
diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile
new file mode 100644
index 000000000000..66ba0924194d
--- /dev/null
+++ b/tools/testing/vsock/Makefile
@@ -0,0 +1,9 @@
1all: test
2test: vsock_diag_test
3vsock_diag_test: vsock_diag_test.o timeout.o control.o
4
5CFLAGS += -g -O2 -Werror -Wall -I. -I../../include/uapi -I../../include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE
6.PHONY: all test clean
7clean:
8 ${RM} *.o *.d vsock_diag_test
9-include *.d
diff --git a/tools/testing/vsock/README b/tools/testing/vsock/README
new file mode 100644
index 000000000000..2cc6d7302db6
--- /dev/null
+++ b/tools/testing/vsock/README
@@ -0,0 +1,36 @@
1AF_VSOCK test suite
2-------------------
3These tests exercise net/vmw_vsock/ host<->guest sockets for VMware, KVM, and
4Hyper-V.
5
6The following tests are available:
7
8 * vsock_diag_test - vsock_diag.ko module for listing open sockets
9
10The following prerequisite steps are not automated and must be performed prior
11to running tests:
12
131. Build the kernel and these tests.
142. Install the kernel and tests on the host.
153. Install the kernel and tests inside the guest.
164. Boot the guest and ensure that the AF_VSOCK transport is enabled.
17
18Invoke test binaries in both directions as follows:
19
20 # host=server, guest=client
21 (host)# $TEST_BINARY --mode=server \
22 --control-port=1234 \
23 --peer-cid=3
24 (guest)# $TEST_BINARY --mode=client \
25 --control-host=$HOST_IP \
26 --control-port=1234 \
27 --peer-cid=2
28
29 # host=client, guest=server
30 (guest)# $TEST_BINARY --mode=server \
31 --control-port=1234 \
32 --peer-cid=2
33 (host)# $TEST_BINARY --mode=client \
34 --control-port=$GUEST_IP \
35 --control-port=1234 \
36 --peer-cid=3
diff --git a/tools/testing/vsock/control.c b/tools/testing/vsock/control.c
new file mode 100644
index 000000000000..90fd47f0e422
--- /dev/null
+++ b/tools/testing/vsock/control.c
@@ -0,0 +1,219 @@
1/* Control socket for client/server test execution
2 *
3 * Copyright (C) 2017 Red Hat, Inc.
4 *
5 * Author: Stefan Hajnoczi <stefanha@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; version 2
10 * of the License.
11 */
12
13/* The client and server may need to coordinate to avoid race conditions like
14 * the client attempting to connect to a socket that the server is not
15 * listening on yet. The control socket offers a communications channel for
16 * such coordination tasks.
17 *
18 * If the client calls control_expectln("LISTENING"), then it will block until
19 * the server calls control_writeln("LISTENING"). This provides a simple
20 * mechanism for coordinating between the client and the server.
21 */
22
23#include <errno.h>
24#include <netdb.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include <sys/types.h>
30#include <sys/socket.h>
31
32#include "timeout.h"
33#include "control.h"
34
35static int control_fd = -1;
36
37/* Open the control socket, either in server or client mode */
38void control_init(const char *control_host,
39 const char *control_port,
40 bool server)
41{
42 struct addrinfo hints = {
43 .ai_socktype = SOCK_STREAM,
44 };
45 struct addrinfo *result = NULL;
46 struct addrinfo *ai;
47 int ret;
48
49 ret = getaddrinfo(control_host, control_port, &hints, &result);
50 if (ret != 0) {
51 fprintf(stderr, "%s\n", gai_strerror(ret));
52 exit(EXIT_FAILURE);
53 }
54
55 for (ai = result; ai; ai = ai->ai_next) {
56 int fd;
57 int val = 1;
58
59 fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
60 if (fd < 0)
61 continue;
62
63 if (!server) {
64 if (connect(fd, ai->ai_addr, ai->ai_addrlen) < 0)
65 goto next;
66 control_fd = fd;
67 printf("Control socket connected to %s:%s.\n",
68 control_host, control_port);
69 break;
70 }
71
72 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
73 &val, sizeof(val)) < 0) {
74 perror("setsockopt");
75 exit(EXIT_FAILURE);
76 }
77
78 if (bind(fd, ai->ai_addr, ai->ai_addrlen) < 0)
79 goto next;
80 if (listen(fd, 1) < 0)
81 goto next;
82
83 printf("Control socket listening on %s:%s\n",
84 control_host, control_port);
85 fflush(stdout);
86
87 control_fd = accept(fd, NULL, 0);
88 close(fd);
89
90 if (control_fd < 0) {
91 perror("accept");
92 exit(EXIT_FAILURE);
93 }
94 printf("Control socket connection accepted...\n");
95 break;
96
97next:
98 close(fd);
99 }
100
101 if (control_fd < 0) {
102 fprintf(stderr, "Control socket initialization failed. Invalid address %s:%s?\n",
103 control_host, control_port);
104 exit(EXIT_FAILURE);
105 }
106
107 freeaddrinfo(result);
108}
109
110/* Free resources */
111void control_cleanup(void)
112{
113 close(control_fd);
114 control_fd = -1;
115}
116
117/* Write a line to the control socket */
118void control_writeln(const char *str)
119{
120 ssize_t len = strlen(str);
121 ssize_t ret;
122
123 timeout_begin(TIMEOUT);
124
125 do {
126 ret = send(control_fd, str, len, MSG_MORE);
127 timeout_check("send");
128 } while (ret < 0 && errno == EINTR);
129
130 if (ret != len) {
131 perror("send");
132 exit(EXIT_FAILURE);
133 }
134
135 do {
136 ret = send(control_fd, "\n", 1, 0);
137 timeout_check("send");
138 } while (ret < 0 && errno == EINTR);
139
140 if (ret != 1) {
141 perror("send");
142 exit(EXIT_FAILURE);
143 }
144
145 timeout_end();
146}
147
148/* Return the next line from the control socket (without the trailing newline).
149 *
150 * The program terminates if a timeout occurs.
151 *
152 * The caller must free() the returned string.
153 */
154char *control_readln(void)
155{
156 char *buf = NULL;
157 size_t idx = 0;
158 size_t buflen = 0;
159
160 timeout_begin(TIMEOUT);
161
162 for (;;) {
163 ssize_t ret;
164
165 if (idx >= buflen) {
166 char *new_buf;
167
168 new_buf = realloc(buf, buflen + 80);
169 if (!new_buf) {
170 perror("realloc");
171 exit(EXIT_FAILURE);
172 }
173
174 buf = new_buf;
175 buflen += 80;
176 }
177
178 do {
179 ret = recv(control_fd, &buf[idx], 1, 0);
180 timeout_check("recv");
181 } while (ret < 0 && errno == EINTR);
182
183 if (ret == 0) {
184 fprintf(stderr, "unexpected EOF on control socket\n");
185 exit(EXIT_FAILURE);
186 }
187
188 if (ret != 1) {
189 perror("recv");
190 exit(EXIT_FAILURE);
191 }
192
193 if (buf[idx] == '\n') {
194 buf[idx] = '\0';
195 break;
196 }
197
198 idx++;
199 }
200
201 timeout_end();
202
203 return buf;
204}
205
206/* Wait until a given line is received or a timeout occurs */
207void control_expectln(const char *str)
208{
209 char *line;
210
211 line = control_readln();
212 if (strcmp(str, line) != 0) {
213 fprintf(stderr, "expected \"%s\" on control socket, got \"%s\"\n",
214 str, line);
215 exit(EXIT_FAILURE);
216 }
217
218 free(line);
219}
diff --git a/tools/testing/vsock/control.h b/tools/testing/vsock/control.h
new file mode 100644
index 000000000000..54a07efd267c
--- /dev/null
+++ b/tools/testing/vsock/control.h
@@ -0,0 +1,13 @@
1#ifndef CONTROL_H
2#define CONTROL_H
3
4#include <stdbool.h>
5
6void control_init(const char *control_host, const char *control_port,
7 bool server);
8void control_cleanup(void);
9void control_writeln(const char *str);
10char *control_readln(void);
11void control_expectln(const char *str);
12
13#endif /* CONTROL_H */
diff --git a/tools/testing/vsock/timeout.c b/tools/testing/vsock/timeout.c
new file mode 100644
index 000000000000..c49b3003b2db
--- /dev/null
+++ b/tools/testing/vsock/timeout.c
@@ -0,0 +1,64 @@
1/* Timeout API for single-threaded programs that use blocking
2 * syscalls (read/write/send/recv/connect/accept).
3 *
4 * Copyright (C) 2017 Red Hat, Inc.
5 *
6 * Author: Stefan Hajnoczi <stefanha@redhat.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; version 2
11 * of the License.
12 */
13
14/* Use the following pattern:
15 *
16 * timeout_begin(TIMEOUT);
17 * do {
18 * ret = accept(...);
19 * timeout_check("accept");
20 * } while (ret < 0 && ret == EINTR);
21 * timeout_end();
22 */
23
24#include <stdlib.h>
25#include <stdbool.h>
26#include <unistd.h>
27#include <stdio.h>
28#include "timeout.h"
29
30static volatile bool timeout;
31
32/* SIGALRM handler function. Do not use sleep(2), alarm(2), or
33 * setitimer(2) while using this API - they may interfere with each
34 * other.
35 */
36void sigalrm(int signo)
37{
38 timeout = true;
39}
40
41/* Start a timeout. Call timeout_check() to verify that the timeout hasn't
42 * expired. timeout_end() must be called to stop the timeout. Timeouts cannot
43 * be nested.
44 */
45void timeout_begin(unsigned int seconds)
46{
47 alarm(seconds);
48}
49
50/* Exit with an error message if the timeout has expired */
51void timeout_check(const char *operation)
52{
53 if (timeout) {
54 fprintf(stderr, "%s timed out\n", operation);
55 exit(EXIT_FAILURE);
56 }
57}
58
59/* Stop a timeout */
60void timeout_end(void)
61{
62 alarm(0);
63 timeout = false;
64}
diff --git a/tools/testing/vsock/timeout.h b/tools/testing/vsock/timeout.h
new file mode 100644
index 000000000000..77db9ce9860a
--- /dev/null
+++ b/tools/testing/vsock/timeout.h
@@ -0,0 +1,14 @@
1#ifndef TIMEOUT_H
2#define TIMEOUT_H
3
4enum {
5 /* Default timeout */
6 TIMEOUT = 10 /* seconds */
7};
8
9void sigalrm(int signo);
10void timeout_begin(unsigned int seconds);
11void timeout_check(const char *operation);
12void timeout_end(void);
13
14#endif /* TIMEOUT_H */
diff --git a/tools/testing/vsock/vsock_diag_test.c b/tools/testing/vsock/vsock_diag_test.c
new file mode 100644
index 000000000000..e896a4af52f4
--- /dev/null
+++ b/tools/testing/vsock/vsock_diag_test.c
@@ -0,0 +1,681 @@
1/*
2 * vsock_diag_test - vsock_diag.ko test suite
3 *
4 * Copyright (C) 2017 Red Hat, Inc.
5 *
6 * Author: Stefan Hajnoczi <stefanha@redhat.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; version 2
11 * of the License.
12 */
13
14#include <getopt.h>
15#include <stdio.h>
16#include <stdbool.h>
17#include <stdlib.h>
18#include <string.h>
19#include <errno.h>
20#include <unistd.h>
21#include <signal.h>
22#include <sys/socket.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <linux/list.h>
26#include <linux/net.h>
27#include <linux/netlink.h>
28#include <linux/sock_diag.h>
29#include <netinet/tcp.h>
30
31#include "../../../include/uapi/linux/vm_sockets.h"
32#include "../../../include/uapi/linux/vm_sockets_diag.h"
33
34#include "timeout.h"
35#include "control.h"
36
37enum test_mode {
38 TEST_MODE_UNSET,
39 TEST_MODE_CLIENT,
40 TEST_MODE_SERVER
41};
42
43/* Per-socket status */
44struct vsock_stat {
45 struct list_head list;
46 struct vsock_diag_msg msg;
47};
48
49static const char *sock_type_str(int type)
50{
51 switch (type) {
52 case SOCK_DGRAM:
53 return "DGRAM";
54 case SOCK_STREAM:
55 return "STREAM";
56 default:
57 return "INVALID TYPE";
58 }
59}
60
61static const char *sock_state_str(int state)
62{
63 switch (state) {
64 case TCP_CLOSE:
65 return "UNCONNECTED";
66 case TCP_SYN_SENT:
67 return "CONNECTING";
68 case TCP_ESTABLISHED:
69 return "CONNECTED";
70 case TCP_CLOSING:
71 return "DISCONNECTING";
72 case TCP_LISTEN:
73 return "LISTEN";
74 default:
75 return "INVALID STATE";
76 }
77}
78
79static const char *sock_shutdown_str(int shutdown)
80{
81 switch (shutdown) {
82 case 1:
83 return "RCV_SHUTDOWN";
84 case 2:
85 return "SEND_SHUTDOWN";
86 case 3:
87 return "RCV_SHUTDOWN | SEND_SHUTDOWN";
88 default:
89 return "0";
90 }
91}
92
93static void print_vsock_addr(FILE *fp, unsigned int cid, unsigned int port)
94{
95 if (cid == VMADDR_CID_ANY)
96 fprintf(fp, "*:");
97 else
98 fprintf(fp, "%u:", cid);
99
100 if (port == VMADDR_PORT_ANY)
101 fprintf(fp, "*");
102 else
103 fprintf(fp, "%u", port);
104}
105
106static void print_vsock_stat(FILE *fp, struct vsock_stat *st)
107{
108 print_vsock_addr(fp, st->msg.vdiag_src_cid, st->msg.vdiag_src_port);
109 fprintf(fp, " ");
110 print_vsock_addr(fp, st->msg.vdiag_dst_cid, st->msg.vdiag_dst_port);
111 fprintf(fp, " %s %s %s %u\n",
112 sock_type_str(st->msg.vdiag_type),
113 sock_state_str(st->msg.vdiag_state),
114 sock_shutdown_str(st->msg.vdiag_shutdown),
115 st->msg.vdiag_ino);
116}
117
118static void print_vsock_stats(FILE *fp, struct list_head *head)
119{
120 struct vsock_stat *st;
121
122 list_for_each_entry(st, head, list)
123 print_vsock_stat(fp, st);
124}
125
126static struct vsock_stat *find_vsock_stat(struct list_head *head, int fd)
127{
128 struct vsock_stat *st;
129 struct stat stat;
130
131 if (fstat(fd, &stat) < 0) {
132 perror("fstat");
133 exit(EXIT_FAILURE);
134 }
135
136 list_for_each_entry(st, head, list)
137 if (st->msg.vdiag_ino == stat.st_ino)
138 return st;
139
140 fprintf(stderr, "cannot find fd %d\n", fd);
141 exit(EXIT_FAILURE);
142}
143
144static void check_no_sockets(struct list_head *head)
145{
146 if (!list_empty(head)) {
147 fprintf(stderr, "expected no sockets\n");
148 print_vsock_stats(stderr, head);
149 exit(1);
150 }
151}
152
153static void check_num_sockets(struct list_head *head, int expected)
154{
155 struct list_head *node;
156 int n = 0;
157
158 list_for_each(node, head)
159 n++;
160
161 if (n != expected) {
162 fprintf(stderr, "expected %d sockets, found %d\n",
163 expected, n);
164 print_vsock_stats(stderr, head);
165 exit(EXIT_FAILURE);
166 }
167}
168
169static void check_socket_state(struct vsock_stat *st, __u8 state)
170{
171 if (st->msg.vdiag_state != state) {
172 fprintf(stderr, "expected socket state %#x, got %#x\n",
173 state, st->msg.vdiag_state);
174 exit(EXIT_FAILURE);
175 }
176}
177
178static void send_req(int fd)
179{
180 struct sockaddr_nl nladdr = {
181 .nl_family = AF_NETLINK,
182 };
183 struct {
184 struct nlmsghdr nlh;
185 struct vsock_diag_req vreq;
186 } req = {
187 .nlh = {
188 .nlmsg_len = sizeof(req),
189 .nlmsg_type = SOCK_DIAG_BY_FAMILY,
190 .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP,
191 },
192 .vreq = {
193 .sdiag_family = AF_VSOCK,
194 .vdiag_states = ~(__u32)0,
195 },
196 };
197 struct iovec iov = {
198 .iov_base = &req,
199 .iov_len = sizeof(req),
200 };
201 struct msghdr msg = {
202 .msg_name = &nladdr,
203 .msg_namelen = sizeof(nladdr),
204 .msg_iov = &iov,
205 .msg_iovlen = 1,
206 };
207
208 for (;;) {
209 if (sendmsg(fd, &msg, 0) < 0) {
210 if (errno == EINTR)
211 continue;
212
213 perror("sendmsg");
214 exit(EXIT_FAILURE);
215 }
216
217 return;
218 }
219}
220
221static ssize_t recv_resp(int fd, void *buf, size_t len)
222{
223 struct sockaddr_nl nladdr = {
224 .nl_family = AF_NETLINK,
225 };
226 struct iovec iov = {
227 .iov_base = buf,
228 .iov_len = len,
229 };
230 struct msghdr msg = {
231 .msg_name = &nladdr,
232 .msg_namelen = sizeof(nladdr),
233 .msg_iov = &iov,
234 .msg_iovlen = 1,
235 };
236 ssize_t ret;
237
238 do {
239 ret = recvmsg(fd, &msg, 0);
240 } while (ret < 0 && errno == EINTR);
241
242 if (ret < 0) {
243 perror("recvmsg");
244 exit(EXIT_FAILURE);
245 }
246
247 return ret;
248}
249
250static void add_vsock_stat(struct list_head *sockets,
251 const struct vsock_diag_msg *resp)
252{
253 struct vsock_stat *st;
254
255 st = malloc(sizeof(*st));
256 if (!st) {
257 perror("malloc");
258 exit(EXIT_FAILURE);
259 }
260
261 st->msg = *resp;
262 list_add_tail(&st->list, sockets);
263}
264
265/*
266 * Read vsock stats into a list.
267 */
268static void read_vsock_stat(struct list_head *sockets)
269{
270 long buf[8192 / sizeof(long)];
271 int fd;
272
273 fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
274 if (fd < 0) {
275 perror("socket");
276 exit(EXIT_FAILURE);
277 }
278
279 send_req(fd);
280
281 for (;;) {
282 const struct nlmsghdr *h;
283 ssize_t ret;
284
285 ret = recv_resp(fd, buf, sizeof(buf));
286 if (ret == 0)
287 goto done;
288 if (ret < sizeof(*h)) {
289 fprintf(stderr, "short read of %zd bytes\n", ret);
290 exit(EXIT_FAILURE);
291 }
292
293 h = (struct nlmsghdr *)buf;
294
295 while (NLMSG_OK(h, ret)) {
296 if (h->nlmsg_type == NLMSG_DONE)
297 goto done;
298
299 if (h->nlmsg_type == NLMSG_ERROR) {
300 const struct nlmsgerr *err = NLMSG_DATA(h);
301
302 if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
303 fprintf(stderr, "NLMSG_ERROR\n");
304 else {
305 errno = -err->error;
306 perror("NLMSG_ERROR");
307 }
308
309 exit(EXIT_FAILURE);
310 }
311
312 if (h->nlmsg_type != SOCK_DIAG_BY_FAMILY) {
313 fprintf(stderr, "unexpected nlmsg_type %#x\n",
314 h->nlmsg_type);
315 exit(EXIT_FAILURE);
316 }
317 if (h->nlmsg_len <
318 NLMSG_LENGTH(sizeof(struct vsock_diag_msg))) {
319 fprintf(stderr, "short vsock_diag_msg\n");
320 exit(EXIT_FAILURE);
321 }
322
323 add_vsock_stat(sockets, NLMSG_DATA(h));
324
325 h = NLMSG_NEXT(h, ret);
326 }
327 }
328
329done:
330 close(fd);
331}
332
333static void free_sock_stat(struct list_head *sockets)
334{
335 struct vsock_stat *st;
336 struct vsock_stat *next;
337
338 list_for_each_entry_safe(st, next, sockets, list)
339 free(st);
340}
341
342static void test_no_sockets(unsigned int peer_cid)
343{
344 LIST_HEAD(sockets);
345
346 read_vsock_stat(&sockets);
347
348 check_no_sockets(&sockets);
349
350 free_sock_stat(&sockets);
351}
352
353static void test_listen_socket_server(unsigned int peer_cid)
354{
355 union {
356 struct sockaddr sa;
357 struct sockaddr_vm svm;
358 } addr = {
359 .svm = {
360 .svm_family = AF_VSOCK,
361 .svm_port = 1234,
362 .svm_cid = VMADDR_CID_ANY,
363 },
364 };
365 LIST_HEAD(sockets);
366 struct vsock_stat *st;
367 int fd;
368
369 fd = socket(AF_VSOCK, SOCK_STREAM, 0);
370
371 if (bind(fd, &addr.sa, sizeof(addr.svm)) < 0) {
372 perror("bind");
373 exit(EXIT_FAILURE);
374 }
375
376 if (listen(fd, 1) < 0) {
377 perror("listen");
378 exit(EXIT_FAILURE);
379 }
380
381 read_vsock_stat(&sockets);
382
383 check_num_sockets(&sockets, 1);
384 st = find_vsock_stat(&sockets, fd);
385 check_socket_state(st, TCP_LISTEN);
386
387 close(fd);
388 free_sock_stat(&sockets);
389}
390
391static void test_connect_client(unsigned int peer_cid)
392{
393 union {
394 struct sockaddr sa;
395 struct sockaddr_vm svm;
396 } addr = {
397 .svm = {
398 .svm_family = AF_VSOCK,
399 .svm_port = 1234,
400 .svm_cid = peer_cid,
401 },
402 };
403 int fd;
404 int ret;
405 LIST_HEAD(sockets);
406 struct vsock_stat *st;
407
408 control_expectln("LISTENING");
409
410 fd = socket(AF_VSOCK, SOCK_STREAM, 0);
411
412 timeout_begin(TIMEOUT);
413 do {
414 ret = connect(fd, &addr.sa, sizeof(addr.svm));
415 timeout_check("connect");
416 } while (ret < 0 && errno == EINTR);
417 timeout_end();
418
419 if (ret < 0) {
420 perror("connect");
421 exit(EXIT_FAILURE);
422 }
423
424 read_vsock_stat(&sockets);
425
426 check_num_sockets(&sockets, 1);
427 st = find_vsock_stat(&sockets, fd);
428 check_socket_state(st, TCP_ESTABLISHED);
429
430 control_expectln("DONE");
431 control_writeln("DONE");
432
433 close(fd);
434 free_sock_stat(&sockets);
435}
436
437static void test_connect_server(unsigned int peer_cid)
438{
439 union {
440 struct sockaddr sa;
441 struct sockaddr_vm svm;
442 } addr = {
443 .svm = {
444 .svm_family = AF_VSOCK,
445 .svm_port = 1234,
446 .svm_cid = VMADDR_CID_ANY,
447 },
448 };
449 union {
450 struct sockaddr sa;
451 struct sockaddr_vm svm;
452 } clientaddr;
453 socklen_t clientaddr_len = sizeof(clientaddr.svm);
454 LIST_HEAD(sockets);
455 struct vsock_stat *st;
456 int fd;
457 int client_fd;
458
459 fd = socket(AF_VSOCK, SOCK_STREAM, 0);
460
461 if (bind(fd, &addr.sa, sizeof(addr.svm)) < 0) {
462 perror("bind");
463 exit(EXIT_FAILURE);
464 }
465
466 if (listen(fd, 1) < 0) {
467 perror("listen");
468 exit(EXIT_FAILURE);
469 }
470
471 control_writeln("LISTENING");
472
473 timeout_begin(TIMEOUT);
474 do {
475 client_fd = accept(fd, &clientaddr.sa, &clientaddr_len);
476 timeout_check("accept");
477 } while (client_fd < 0 && errno == EINTR);
478 timeout_end();
479
480 if (client_fd < 0) {
481 perror("accept");
482 exit(EXIT_FAILURE);
483 }
484 if (clientaddr.sa.sa_family != AF_VSOCK) {
485 fprintf(stderr, "expected AF_VSOCK from accept(2), got %d\n",
486 clientaddr.sa.sa_family);
487 exit(EXIT_FAILURE);
488 }
489 if (clientaddr.svm.svm_cid != peer_cid) {
490 fprintf(stderr, "expected peer CID %u from accept(2), got %u\n",
491 peer_cid, clientaddr.svm.svm_cid);
492 exit(EXIT_FAILURE);
493 }
494
495 read_vsock_stat(&sockets);
496
497 check_num_sockets(&sockets, 2);
498 find_vsock_stat(&sockets, fd);
499 st = find_vsock_stat(&sockets, client_fd);
500 check_socket_state(st, TCP_ESTABLISHED);
501
502 control_writeln("DONE");
503 control_expectln("DONE");
504
505 close(client_fd);
506 close(fd);
507 free_sock_stat(&sockets);
508}
509
510static struct {
511 const char *name;
512 void (*run_client)(unsigned int peer_cid);
513 void (*run_server)(unsigned int peer_cid);
514} test_cases[] = {
515 {
516 .name = "No sockets",
517 .run_server = test_no_sockets,
518 },
519 {
520 .name = "Listen socket",
521 .run_server = test_listen_socket_server,
522 },
523 {
524 .name = "Connect",
525 .run_client = test_connect_client,
526 .run_server = test_connect_server,
527 },
528 {},
529};
530
531static void init_signals(void)
532{
533 struct sigaction act = {
534 .sa_handler = sigalrm,
535 };
536
537 sigaction(SIGALRM, &act, NULL);
538 signal(SIGPIPE, SIG_IGN);
539}
540
541static unsigned int parse_cid(const char *str)
542{
543 char *endptr = NULL;
544 unsigned long int n;
545
546 errno = 0;
547 n = strtoul(str, &endptr, 10);
548 if (errno || *endptr != '\0') {
549 fprintf(stderr, "malformed CID \"%s\"\n", str);
550 exit(EXIT_FAILURE);
551 }
552 return n;
553}
554
555static const char optstring[] = "";
556static const struct option longopts[] = {
557 {
558 .name = "control-host",
559 .has_arg = required_argument,
560 .val = 'H',
561 },
562 {
563 .name = "control-port",
564 .has_arg = required_argument,
565 .val = 'P',
566 },
567 {
568 .name = "mode",
569 .has_arg = required_argument,
570 .val = 'm',
571 },
572 {
573 .name = "peer-cid",
574 .has_arg = required_argument,
575 .val = 'p',
576 },
577 {
578 .name = "help",
579 .has_arg = no_argument,
580 .val = '?',
581 },
582 {},
583};
584
585static void usage(void)
586{
587 fprintf(stderr, "Usage: vsock_diag_test [--help] [--control-host=<host>] --control-port=<port> --mode=client|server --peer-cid=<cid>\n"
588 "\n"
589 " Server: vsock_diag_test --control-port=1234 --mode=server --peer-cid=3\n"
590 " Client: vsock_diag_test --control-host=192.168.0.1 --control-port=1234 --mode=client --peer-cid=2\n"
591 "\n"
592 "Run vsock_diag.ko tests. Must be launched in both\n"
593 "guest and host. One side must use --mode=client and\n"
594 "the other side must use --mode=server.\n"
595 "\n"
596 "A TCP control socket connection is used to coordinate tests\n"
597 "between the client and the server. The server requires a\n"
598 "listen address and the client requires an address to\n"
599 "connect to.\n"
600 "\n"
601 "The CID of the other side must be given with --peer-cid=<cid>.\n");
602 exit(EXIT_FAILURE);
603}
604
605int main(int argc, char **argv)
606{
607 const char *control_host = NULL;
608 const char *control_port = NULL;
609 int mode = TEST_MODE_UNSET;
610 unsigned int peer_cid = VMADDR_CID_ANY;
611 int i;
612
613 init_signals();
614
615 for (;;) {
616 int opt = getopt_long(argc, argv, optstring, longopts, NULL);
617
618 if (opt == -1)
619 break;
620
621 switch (opt) {
622 case 'H':
623 control_host = optarg;
624 break;
625 case 'm':
626 if (strcmp(optarg, "client") == 0)
627 mode = TEST_MODE_CLIENT;
628 else if (strcmp(optarg, "server") == 0)
629 mode = TEST_MODE_SERVER;
630 else {
631 fprintf(stderr, "--mode must be \"client\" or \"server\"\n");
632 return EXIT_FAILURE;
633 }
634 break;
635 case 'p':
636 peer_cid = parse_cid(optarg);
637 break;
638 case 'P':
639 control_port = optarg;
640 break;
641 case '?':
642 default:
643 usage();
644 }
645 }
646
647 if (!control_port)
648 usage();
649 if (mode == TEST_MODE_UNSET)
650 usage();
651 if (peer_cid == VMADDR_CID_ANY)
652 usage();
653
654 if (!control_host) {
655 if (mode != TEST_MODE_SERVER)
656 usage();
657 control_host = "0.0.0.0";
658 }
659
660 control_init(control_host, control_port, mode == TEST_MODE_SERVER);
661
662 for (i = 0; test_cases[i].name; i++) {
663 void (*run)(unsigned int peer_cid);
664
665 printf("%s...", test_cases[i].name);
666 fflush(stdout);
667
668 if (mode == TEST_MODE_CLIENT)
669 run = test_cases[i].run_client;
670 else
671 run = test_cases[i].run_server;
672
673 if (run)
674 run(peer_cid);
675
676 printf("ok\n");
677 }
678
679 control_cleanup();
680 return EXIT_SUCCESS;
681}
diff --git a/tools/thermal/tmon/Makefile b/tools/thermal/tmon/Makefile
index 3a961e998281..735a510230c3 100644
--- a/tools/thermal/tmon/Makefile
+++ b/tools/thermal/tmon/Makefile
@@ -1,9 +1,16 @@
1# SPDX-License-Identifier: GPL-2.0
2# We need this for the "cc-option" macro.
3include ../../../scripts/Kbuild.include
4
1VERSION = 1.0 5VERSION = 1.0
2 6
3BINDIR=usr/bin 7BINDIR=usr/bin
4WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int 8WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int
5CFLAGS+= -O1 ${WARNFLAGS} -fstack-protector 9CFLAGS+= -O1 ${WARNFLAGS}
6CC=$(CROSS_COMPILE)gcc 10# Add "-fstack-protector" only if toolchain supports it.
11CFLAGS+= $(call cc-option,-fstack-protector)
12CC?= $(CROSS_COMPILE)gcc
13PKG_CONFIG?= pkg-config
7 14
8CFLAGS+=-D VERSION=\"$(VERSION)\" 15CFLAGS+=-D VERSION=\"$(VERSION)\"
9LDFLAGS+= 16LDFLAGS+=
@@ -18,12 +25,12 @@ STATIC := --static
18endif 25endif
19 26
20TMON_LIBS=-lm -lpthread 27TMON_LIBS=-lm -lpthread
21TMON_LIBS += $(shell pkg-config --libs $(STATIC) panelw ncursesw 2> /dev/null || \ 28TMON_LIBS += $(shell $(PKG_CONFIG) --libs $(STATIC) panelw ncursesw 2> /dev/null || \
22 pkg-config --libs $(STATIC) panel ncurses 2> /dev/null || \ 29 $(PKG_CONFIG) --libs $(STATIC) panel ncurses 2> /dev/null || \
23 echo -lpanel -lncurses) 30 echo -lpanel -lncurses)
24 31
25CFLAGS += $(shell pkg-config --cflags $(STATIC) panelw ncursesw 2> /dev/null || \ 32CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \
26 pkg-config --cflags $(STATIC) panel ncurses 2> /dev/null) 33 $(PKG_CONFIG) --cflags $(STATIC) panel ncurses 2> /dev/null)
27 34
28OBJS = tmon.o tui.o sysfs.o pid.o 35OBJS = tmon.o tui.o sysfs.o pid.o
29OBJS += 36OBJS +=
diff --git a/tools/thermal/tmon/tmon.8 b/tools/thermal/tmon/tmon.8
index 02d5179803aa..2f122de5841b 100644
--- a/tools/thermal/tmon/tmon.8
+++ b/tools/thermal/tmon/tmon.8
@@ -1,4 +1,5 @@
1.TH TMON 8 1.TH TMON 8
2# SPDX-License-Identifier: GPL-2.0
2.SH NAME 3.SH NAME
3\fBtmon\fP - A monitoring and testing tool for Linux kernel thermal subsystem 4\fBtmon\fP - A monitoring and testing tool for Linux kernel thermal subsystem
4 5
diff --git a/tools/usb/Makefile b/tools/usb/Makefile
index acf2165c04e6..4e6506078494 100644
--- a/tools/usb/Makefile
+++ b/tools/usb/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for USB tools 2# Makefile for USB tools
2 3
3CC = $(CROSS_COMPILE)gcc 4CC = $(CROSS_COMPILE)gcc
diff --git a/tools/usb/ffs-aio-example/multibuff/host_app/Makefile b/tools/usb/ffs-aio-example/multibuff/host_app/Makefile
index 8c4a6f0aa82d..df36e4c28f61 100644
--- a/tools/usb/ffs-aio-example/multibuff/host_app/Makefile
+++ b/tools/usb/ffs-aio-example/multibuff/host_app/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CC = gcc 2CC = gcc
2LIBUSB_CFLAGS = $(shell pkg-config --cflags libusb-1.0) 3LIBUSB_CFLAGS = $(shell pkg-config --cflags libusb-1.0)
3LIBUSB_LIBS = $(shell pkg-config --libs libusb-1.0) 4LIBUSB_LIBS = $(shell pkg-config --libs libusb-1.0)
diff --git a/tools/usb/hcd-tests.sh b/tools/usb/hcd-tests.sh
index b30b3dc4c788..e8cad6a4f9c9 100644
--- a/tools/usb/hcd-tests.sh
+++ b/tools/usb/hcd-tests.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# test types can be passed on the command line: 4# test types can be passed on the command line:
4# 5#
diff --git a/tools/usb/usbip/Makefile.am b/tools/usb/usbip/Makefile.am
index 66f8bf038c9f..5961e9c18812 100644
--- a/tools/usb/usbip/Makefile.am
+++ b/tools/usb/usbip/Makefile.am
@@ -1,6 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0
1SUBDIRS := libsrc src 2SUBDIRS := libsrc src
2includedir = @includedir@/usbip 3includedir = @includedir@/usbip
3include_HEADERS := $(addprefix libsrc/, \ 4include_HEADERS := $(addprefix libsrc/, \
4 usbip_common.h vhci_driver.h usbip_host_driver.h) 5 usbip_common.h vhci_driver.h usbip_host_driver.h \
6 list.h sysfs_utils.h usbip_host_common.h)
5 7
6dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8) 8dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8)
diff --git a/tools/usb/usbip/cleanup.sh b/tools/usb/usbip/cleanup.sh
index 955c3ccb729a..8028c3a5c22b 100755
--- a/tools/usb/usbip/cleanup.sh
+++ b/tools/usb/usbip/cleanup.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3if [ -r Makefile ]; then 4if [ -r Makefile ]; then
4 make distclean 5 make distclean
diff --git a/tools/usb/usbip/libsrc/Makefile.am b/tools/usb/usbip/libsrc/Makefile.am
index 90daf95c0804..dabd2c91d311 100644
--- a/tools/usb/usbip/libsrc/Makefile.am
+++ b/tools/usb/usbip/libsrc/Makefile.am
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1libusbip_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' 2libusbip_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
2libusbip_la_CFLAGS = @EXTRA_CFLAGS@ 3libusbip_la_CFLAGS = @EXTRA_CFLAGS@
3libusbip_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@ 4libusbip_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@
diff --git a/tools/usb/usbip/libsrc/list.h b/tools/usb/usbip/libsrc/list.h
index 5eaaa78e2c6a..a941671e4900 100644
--- a/tools/usb/usbip/libsrc/list.h
+++ b/tools/usb/usbip/libsrc/list.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LIST_H 2#ifndef _LIST_H
2#define _LIST_H 3#define _LIST_H
3 4
diff --git a/tools/usb/usbip/libsrc/sysfs_utils.c b/tools/usb/usbip/libsrc/sysfs_utils.c
index 36ac88ece0b8..14d5e67d398a 100644
--- a/tools/usb/usbip/libsrc/sysfs_utils.c
+++ b/tools/usb/usbip/libsrc/sysfs_utils.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#include <sys/types.h> 2#include <sys/types.h>
2#include <sys/stat.h> 3#include <sys/stat.h>
3#include <fcntl.h> 4#include <fcntl.h>
diff --git a/tools/usb/usbip/libsrc/sysfs_utils.h b/tools/usb/usbip/libsrc/sysfs_utils.h
index 32ac1d105d18..0cd5f17e7eb2 100644
--- a/tools/usb/usbip/libsrc/sysfs_utils.h
+++ b/tools/usb/usbip/libsrc/sysfs_utils.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1 2
2#ifndef __SYSFS_UTILS_H 3#ifndef __SYSFS_UTILS_H
3#define __SYSFS_UTILS_H 4#define __SYSFS_UTILS_H
diff --git a/tools/usb/usbip/libsrc/usbip_common.c b/tools/usb/usbip/libsrc/usbip_common.c
index 1517a232ab18..001bb8e8f668 100644
--- a/tools/usb/usbip/libsrc/usbip_common.c
+++ b/tools/usb/usbip/libsrc/usbip_common.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi 3 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */ 4 */
diff --git a/tools/usb/usbip/libsrc/usbip_common.h b/tools/usb/usbip/libsrc/usbip_common.h
index 51ef5fe485dd..e45ec9d2fdbc 100644
--- a/tools/usb/usbip/libsrc/usbip_common.h
+++ b/tools/usb/usbip/libsrc/usbip_common.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi 3 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */ 4 */
diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c
index 9bd2cd71645d..5727dfb15a83 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi 3 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */ 4 */
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h b/tools/usb/usbip/libsrc/vhci_driver.h
index 4898d3bafb10..418b404d5121 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi 3 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */ 4 */
diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index e81a4ebadeff..e26f39e0579d 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' 2AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
2AM_CFLAGS = @EXTRA_CFLAGS@ 3AM_CFLAGS = @EXTRA_CFLAGS@
3LDADD = $(top_builddir)/libsrc/libusbip.la 4LDADD = $(top_builddir)/libsrc/libusbip.la
diff --git a/tools/usb/usbip/src/usbip_network.h b/tools/usb/usbip/src/usbip_network.h
index c1e875cf1078..7032687621d3 100644
--- a/tools/usb/usbip/src/usbip_network.h
+++ b/tools/usb/usbip/src/usbip_network.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi 3 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */ 4 */
diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile
index 39c89a5ea990..8e2a908115c2 100644
--- a/tools/virtio/Makefile
+++ b/tools/virtio/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: test mod 2all: test mod
2test: virtio_test vringh_test 3test: virtio_test vringh_test
3virtio_test: virtio_ring.o virtio_test.o 4virtio_test: virtio_ring.o virtio_test.o
diff --git a/tools/virtio/asm/barrier.h b/tools/virtio/asm/barrier.h
index ba34f9e96efd..0ac3caf90877 100644
--- a/tools/virtio/asm/barrier.h
+++ b/tools/virtio/asm/barrier.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#if defined(__i386__) || defined(__x86_64__) 2#if defined(__i386__) || defined(__x86_64__)
2#define barrier() asm volatile("" ::: "memory") 3#define barrier() asm volatile("" ::: "memory")
3#define virt_mb() __sync_synchronize() 4#define virt_mb() __sync_synchronize()
diff --git a/tools/virtio/linux/bug.h b/tools/virtio/linux/bug.h
index fb94f0787c47..b14c2c3b6b85 100644
--- a/tools/virtio/linux/bug.h
+++ b/tools/virtio/linux/bug.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef BUG_H 2#ifndef BUG_H
2#define BUG_H 3#define BUG_H
3 4
diff --git a/tools/virtio/linux/compiler.h b/tools/virtio/linux/compiler.h
index c9ccfd42ec13..903dc9c4bd11 100644
--- a/tools/virtio/linux/compiler.h
+++ b/tools/virtio/linux/compiler.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef LINUX_COMPILER_H 2#ifndef LINUX_COMPILER_H
2#define LINUX_COMPILER_H 3#define LINUX_COMPILER_H
3 4
diff --git a/tools/virtio/linux/dma-mapping.h b/tools/virtio/linux/dma-mapping.h
index 18601f6689b9..1571e24e9494 100644
--- a/tools/virtio/linux/dma-mapping.h
+++ b/tools/virtio/linux/dma-mapping.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LINUX_DMA_MAPPING_H 2#ifndef _LINUX_DMA_MAPPING_H
2#define _LINUX_DMA_MAPPING_H 3#define _LINUX_DMA_MAPPING_H
3 4
diff --git a/tools/virtio/linux/err.h b/tools/virtio/linux/err.h
index e32eff8b2a14..0943c644a701 100644
--- a/tools/virtio/linux/err.h
+++ b/tools/virtio/linux/err.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef ERR_H 2#ifndef ERR_H
2#define ERR_H 3#define ERR_H
3#define MAX_ERRNO 4095 4#define MAX_ERRNO 4095
diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h
index d9554fc3f340..395521a7a8d8 100644
--- a/tools/virtio/linux/kernel.h
+++ b/tools/virtio/linux/kernel.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef KERNEL_H 2#ifndef KERNEL_H
2#define KERNEL_H 3#define KERNEL_H
3#include <stdbool.h> 4#include <stdbool.h>
diff --git a/tools/virtio/linux/module.h b/tools/virtio/linux/module.h
index 28ce95a05997..9dfa96fea2b2 100644
--- a/tools/virtio/linux/module.h
+++ b/tools/virtio/linux/module.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <linux/export.h> 2#include <linux/export.h>
2 3
3#define MODULE_LICENSE(__MODULE_LICENSE_value) \ 4#define MODULE_LICENSE(__MODULE_LICENSE_value) \
diff --git a/tools/virtio/linux/scatterlist.h b/tools/virtio/linux/scatterlist.h
index 68c9e2adc996..9a45f90e2d08 100644
--- a/tools/virtio/linux/scatterlist.h
+++ b/tools/virtio/linux/scatterlist.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef SCATTERLIST_H 2#ifndef SCATTERLIST_H
2#define SCATTERLIST_H 3#define SCATTERLIST_H
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/tools/virtio/linux/slab.h b/tools/virtio/linux/slab.h
index 7e1c1197d439..319dcaa07755 100644
--- a/tools/virtio/linux/slab.h
+++ b/tools/virtio/linux/slab.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef LINUX_SLAB_H 2#ifndef LINUX_SLAB_H
2#define GFP_KERNEL 0 3#define GFP_KERNEL 0
3#define GFP_ATOMIC 0 4#define GFP_ATOMIC 0
diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
index fa05d01b2c90..991dfb263998 100644
--- a/tools/virtio/linux/uaccess.h
+++ b/tools/virtio/linux/uaccess.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef UACCESS_H 2#ifndef UACCESS_H
2#define UACCESS_H 3#define UACCESS_H
3 4
diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h
index d8f534025b7f..b751350d4ce8 100644
--- a/tools/virtio/linux/virtio.h
+++ b/tools/virtio/linux/virtio.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef LINUX_VIRTIO_H 2#ifndef LINUX_VIRTIO_H
2#define LINUX_VIRTIO_H 3#define LINUX_VIRTIO_H
3#include <linux/scatterlist.h> 4#include <linux/scatterlist.h>
diff --git a/tools/virtio/linux/virtio_byteorder.h b/tools/virtio/linux/virtio_byteorder.h
index 9de9e6ac1d10..5b50f7eebd9c 100644
--- a/tools/virtio/linux/virtio_byteorder.h
+++ b/tools/virtio/linux/virtio_byteorder.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef _LINUX_VIRTIO_BYTEORDER_STUB_H 2#ifndef _LINUX_VIRTIO_BYTEORDER_STUB_H
2#define _LINUX_VIRTIO_BYTEORDER_STUB_H 3#define _LINUX_VIRTIO_BYTEORDER_STUB_H
3 4
diff --git a/tools/virtio/linux/virtio_config.h b/tools/virtio/linux/virtio_config.h
index 9ba11815e0a1..dbf14c1e2188 100644
--- a/tools/virtio/linux/virtio_config.h
+++ b/tools/virtio/linux/virtio_config.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#include <linux/virtio_byteorder.h> 2#include <linux/virtio_byteorder.h>
2#include <linux/virtio.h> 3#include <linux/virtio.h>
3#include <uapi/linux/virtio_config.h> 4#include <uapi/linux/virtio_config.h>
diff --git a/tools/virtio/ringtest/Makefile b/tools/virtio/ringtest/Makefile
index c012edbdb13b..85c98c2810fb 100644
--- a/tools/virtio/ringtest/Makefile
+++ b/tools/virtio/ringtest/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1all: 2all:
2 3
3all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder ptr_ring noring 4all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder ptr_ring noring
diff --git a/tools/virtio/ringtest/main.h b/tools/virtio/ringtest/main.h
index 90b0133004e1..5706e075adf2 100644
--- a/tools/virtio/ringtest/main.h
+++ b/tools/virtio/ringtest/main.h
@@ -110,11 +110,15 @@ static inline void busy_wait(void)
110 barrier(); 110 barrier();
111} 111}
112 112
113#if defined(__x86_64__) || defined(__i386__)
114#define smp_mb() asm volatile("lock; addl $0,-128(%%rsp)" ::: "memory", "cc")
115#else
113/* 116/*
114 * Not using __ATOMIC_SEQ_CST since gcc docs say they are only synchronized 117 * Not using __ATOMIC_SEQ_CST since gcc docs say they are only synchronized
115 * with other __ATOMIC_SEQ_CST calls. 118 * with other __ATOMIC_SEQ_CST calls.
116 */ 119 */
117#define smp_mb() __sync_synchronize() 120#define smp_mb() __sync_synchronize()
121#endif
118 122
119/* 123/*
120 * This abuses the atomic builtins for thread fences, and 124 * This abuses the atomic builtins for thread fences, and
diff --git a/tools/virtio/ringtest/noring.c b/tools/virtio/ringtest/noring.c
index b8d1c1daac7c..ce2440d5ca93 100644
--- a/tools/virtio/ringtest/noring.c
+++ b/tools/virtio/ringtest/noring.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include "main.h" 3#include "main.h"
3#include <assert.h> 4#include <assert.h>
diff --git a/tools/virtio/ringtest/ptr_ring.c b/tools/virtio/ringtest/ptr_ring.c
index 7b22f1b20652..38bb171aceba 100644
--- a/tools/virtio/ringtest/ptr_ring.c
+++ b/tools/virtio/ringtest/ptr_ring.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include "main.h" 3#include "main.h"
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/virtio/ringtest/run-on-all.sh b/tools/virtio/ringtest/run-on-all.sh
index 29b0d3920bfc..dcc3ea758f48 100755
--- a/tools/virtio/ringtest/run-on-all.sh
+++ b/tools/virtio/ringtest/run-on-all.sh
@@ -1,4 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
2 3
3CPUS_ONLINE=$(lscpu --online -p=cpu|grep -v -e '#') 4CPUS_ONLINE=$(lscpu --online -p=cpu|grep -v -e '#')
4#use last CPU for host. Why not the first? 5#use last CPU for host. Why not the first?
diff --git a/tools/virtio/uapi/linux/virtio_ring.h b/tools/virtio/uapi/linux/virtio_ring.h
index 4d99c78234d3..cf50b2e5ff02 100644
--- a/tools/virtio/uapi/linux/virtio_ring.h
+++ b/tools/virtio/uapi/linux/virtio_ring.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef VIRTIO_RING_H 2#ifndef VIRTIO_RING_H
2#define VIRTIO_RING_H 3#define VIRTIO_RING_H
3#include "../../../../include/uapi/linux/virtio_ring.h" 4#include "../../../../include/uapi/linux/virtio_ring.h"
diff --git a/tools/virtio/virtio-trace/Makefile b/tools/virtio/virtio-trace/Makefile
index 0d2381633475..7843ebcda71d 100644
--- a/tools/virtio/virtio-trace/Makefile
+++ b/tools/virtio/virtio-trace/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1CC = gcc 2CC = gcc
2CFLAGS = -O2 -Wall -pthread 3CFLAGS = -O2 -Wall -pthread
3 4
diff --git a/tools/virtio/virtio-trace/trace-agent.h b/tools/virtio/virtio-trace/trace-agent.h
index 8de79bfeaa73..e67885969f0e 100644
--- a/tools/virtio/virtio-trace/trace-agent.h
+++ b/tools/virtio/virtio-trace/trace-agent.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1#ifndef __TRACE_AGENT_H__ 2#ifndef __TRACE_AGENT_H__
2#define __TRACE_AGENT_H__ 3#define __TRACE_AGENT_H__
3#include <pthread.h> 4#include <pthread.h>
diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
index 0fecaec90d0d..b427def67e7e 100644
--- a/tools/virtio/virtio_test.c
+++ b/tools/virtio/virtio_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1#define _GNU_SOURCE 2#define _GNU_SOURCE
2#include <getopt.h> 3#include <getopt.h>
3#include <string.h> 4#include <string.h>
diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c
index 9476c616d064..293653463303 100644
--- a/tools/virtio/vringh_test.c
+++ b/tools/virtio/vringh_test.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Simple test of virtio code, entirely in userpsace. */ 2/* Simple test of virtio code, entirely in userpsace. */
2#define _GNU_SOURCE 3#define _GNU_SOURCE
3#include <sched.h> 4#include <sched.h>
diff --git a/tools/vm/Makefile b/tools/vm/Makefile
index 006029456988..be320b905ea7 100644
--- a/tools/vm/Makefile
+++ b/tools/vm/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# Makefile for vm tools 2# Makefile for vm tools
2# 3#
3TARGETS=page-types slabinfo page_owner_sort 4TARGETS=page-types slabinfo page_owner_sort
diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c
index f1c055f3c243..18fc112b65cd 100644
--- a/tools/vm/page_owner_sort.c
+++ b/tools/vm/page_owner_sort.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * User-space helper to sort the output of /sys/kernel/debug/page_owner 3 * User-space helper to sort the output of /sys/kernel/debug/page_owner
3 * 4 *
diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c
index b9d34b37c017..f82c2eaa859d 100644
--- a/tools/vm/slabinfo.c
+++ b/tools/vm/slabinfo.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Slabinfo: Tool to get reports about slabs 3 * Slabinfo: Tool to get reports about slabs
3 * 4 *
@@ -83,6 +84,7 @@ int output_lines = -1;
83int sort_loss; 84int sort_loss;
84int extended_totals; 85int extended_totals;
85int show_bytes; 86int show_bytes;
87int unreclaim_only;
86 88
87/* Debug options */ 89/* Debug options */
88int sanity; 90int sanity;
@@ -132,6 +134,7 @@ static void usage(void)
132 "-L|--Loss Sort by loss\n" 134 "-L|--Loss Sort by loss\n"
133 "-X|--Xtotals Show extended summary information\n" 135 "-X|--Xtotals Show extended summary information\n"
134 "-B|--Bytes Show size in bytes\n" 136 "-B|--Bytes Show size in bytes\n"
137 "-U|--Unreclaim Show unreclaimable slabs only\n"
135 "\nValid debug options (FZPUT may be combined)\n" 138 "\nValid debug options (FZPUT may be combined)\n"
136 "a / A Switch on all debug options (=FZUP)\n" 139 "a / A Switch on all debug options (=FZUP)\n"
137 "- Switch off all debug options\n" 140 "- Switch off all debug options\n"
@@ -568,6 +571,9 @@ static void slabcache(struct slabinfo *s)
568 if (strcmp(s->name, "*") == 0) 571 if (strcmp(s->name, "*") == 0)
569 return; 572 return;
570 573
574 if (unreclaim_only && s->reclaim_account)
575 return;
576
571 if (actual_slabs == 1) { 577 if (actual_slabs == 1) {
572 report(s); 578 report(s);
573 return; 579 return;
@@ -1346,6 +1352,7 @@ struct option opts[] = {
1346 { "Loss", no_argument, NULL, 'L'}, 1352 { "Loss", no_argument, NULL, 'L'},
1347 { "Xtotals", no_argument, NULL, 'X'}, 1353 { "Xtotals", no_argument, NULL, 'X'},
1348 { "Bytes", no_argument, NULL, 'B'}, 1354 { "Bytes", no_argument, NULL, 'B'},
1355 { "Unreclaim", no_argument, NULL, 'U'},
1349 { NULL, 0, NULL, 0 } 1356 { NULL, 0, NULL, 0 }
1350}; 1357};
1351 1358
@@ -1357,7 +1364,7 @@ int main(int argc, char *argv[])
1357 1364
1358 page_size = getpagesize(); 1365 page_size = getpagesize();
1359 1366
1360 while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTSN:LXB", 1367 while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTSN:LXBU",
1361 opts, NULL)) != -1) 1368 opts, NULL)) != -1)
1362 switch (c) { 1369 switch (c) {
1363 case '1': 1370 case '1':
@@ -1438,6 +1445,9 @@ int main(int argc, char *argv[])
1438 case 'B': 1445 case 'B':
1439 show_bytes = 1; 1446 show_bytes = 1;
1440 break; 1447 break;
1448 case 'U':
1449 unreclaim_only = 1;
1450 break;
1441 default: 1451 default:
1442 fatal("%s: Invalid option '%c'\n", argv[0], optopt); 1452 fatal("%s: Invalid option '%c'\n", argv[0], optopt);
1443 1453
diff --git a/tools/wmi/Makefile b/tools/wmi/Makefile
new file mode 100644
index 000000000000..e664f1167388
--- /dev/null
+++ b/tools/wmi/Makefile
@@ -0,0 +1,18 @@
1PREFIX ?= /usr
2SBINDIR ?= sbin
3INSTALL ?= install
4CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
5CC = $(CROSS_COMPILE)gcc
6
7TARGET = dell-smbios-example
8
9all: $(TARGET)
10
11%: %.c
12 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
13
14clean:
15 $(RM) $(TARGET)
16
17install: dell-smbios-example
18 $(INSTALL) -D -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/$(SBINDIR)/$(TARGET)
diff --git a/tools/wmi/dell-smbios-example.c b/tools/wmi/dell-smbios-example.c
new file mode 100644
index 000000000000..9d3bde081249
--- /dev/null
+++ b/tools/wmi/dell-smbios-example.c
@@ -0,0 +1,210 @@
1/*
2 * Sample application for SMBIOS communication over WMI interface
3 * Performs the following:
4 * - Simple cmd_class/cmd_select lookup for TPM information
5 * - Simple query of known tokens and their values
6 * - Simple activation of a token
7 *
8 * Copyright (C) 2017 Dell, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <errno.h>
16#include <fcntl.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <sys/ioctl.h>
20#include <unistd.h>
21
22/* if uapi header isn't installed, this might not yet exist */
23#ifndef __packed
24#define __packed __attribute__((packed))
25#endif
26#include <linux/wmi.h>
27
28/* It would be better to discover these using udev, but for a simple
29 * application they're hardcoded
30 */
31static const char *ioctl_devfs = "/dev/wmi/dell-smbios";
32static const char *token_sysfs =
33 "/sys/bus/platform/devices/dell-smbios.0/tokens";
34
35static void show_buffer(struct dell_wmi_smbios_buffer *buffer)
36{
37 printf("Call: %x/%x [%x,%x,%x,%x]\nResults: [%8x,%8x,%8x,%8x]\n",
38 buffer->std.cmd_class, buffer->std.cmd_select,
39 buffer->std.input[0], buffer->std.input[1],
40 buffer->std.input[2], buffer->std.input[3],
41 buffer->std.output[0], buffer->std.output[1],
42 buffer->std.output[2], buffer->std.output[3]);
43}
44
45static int run_wmi_smbios_cmd(struct dell_wmi_smbios_buffer *buffer)
46{
47 int fd;
48 int ret;
49
50 fd = open(ioctl_devfs, O_NONBLOCK);
51 ret = ioctl(fd, DELL_WMI_SMBIOS_CMD, buffer);
52 close(fd);
53 return ret;
54}
55
56static int find_token(__u16 token, __u16 *location, __u16 *value)
57{
58 char location_sysfs[60];
59 char value_sysfs[57];
60 char buf[4096];
61 FILE *f;
62 int ret;
63
64 ret = sprintf(value_sysfs, "%s/%04x_value", token_sysfs, token);
65 if (ret < 0) {
66 printf("sprintf value failed\n");
67 return 2;
68 }
69 f = fopen(value_sysfs, "rb");
70 if (!f) {
71 printf("failed to open %s\n", value_sysfs);
72 return 2;
73 }
74 fread(buf, 1, 4096, f);
75 fclose(f);
76 *value = (__u16) strtol(buf, NULL, 16);
77
78 ret = sprintf(location_sysfs, "%s/%04x_location", token_sysfs, token);
79 if (ret < 0) {
80 printf("sprintf location failed\n");
81 return 1;
82 }
83 f = fopen(location_sysfs, "rb");
84 if (!f) {
85 printf("failed to open %s\n", location_sysfs);
86 return 2;
87 }
88 fread(buf, 1, 4096, f);
89 fclose(f);
90 *location = (__u16) strtol(buf, NULL, 16);
91
92 if (*location)
93 return 0;
94 return 2;
95}
96
97static int token_is_active(__u16 *location, __u16 *cmpvalue,
98 struct dell_wmi_smbios_buffer *buffer)
99{
100 int ret;
101
102 buffer->std.cmd_class = CLASS_TOKEN_READ;
103 buffer->std.cmd_select = SELECT_TOKEN_STD;
104 buffer->std.input[0] = *location;
105 ret = run_wmi_smbios_cmd(buffer);
106 if (ret != 0 || buffer->std.output[0] != 0)
107 return ret;
108 ret = (buffer->std.output[1] == *cmpvalue);
109 return ret;
110}
111
112static int query_token(__u16 token, struct dell_wmi_smbios_buffer *buffer)
113{
114 __u16 location;
115 __u16 value;
116 int ret;
117
118 ret = find_token(token, &location, &value);
119 if (ret != 0) {
120 printf("unable to find token %04x\n", token);
121 return 1;
122 }
123 return token_is_active(&location, &value, buffer);
124}
125
126static int activate_token(struct dell_wmi_smbios_buffer *buffer,
127 __u16 token)
128{
129 __u16 location;
130 __u16 value;
131 int ret;
132
133 ret = find_token(token, &location, &value);
134 if (ret != 0) {
135 printf("unable to find token %04x\n", token);
136 return 1;
137 }
138 buffer->std.cmd_class = CLASS_TOKEN_WRITE;
139 buffer->std.cmd_select = SELECT_TOKEN_STD;
140 buffer->std.input[0] = location;
141 buffer->std.input[1] = 1;
142 ret = run_wmi_smbios_cmd(buffer);
143 return ret;
144}
145
146static int query_buffer_size(__u64 *buffer_size)
147{
148 FILE *f;
149
150 f = fopen(ioctl_devfs, "rb");
151 if (!f)
152 return -EINVAL;
153 fread(buffer_size, sizeof(__u64), 1, f);
154 fclose(f);
155 return EXIT_SUCCESS;
156}
157
158int main(void)
159{
160 struct dell_wmi_smbios_buffer *buffer;
161 int ret;
162 __u64 value = 0;
163
164 ret = query_buffer_size(&value);
165 if (ret == EXIT_FAILURE || !value) {
166 printf("Unable to read buffer size\n");
167 goto out;
168 }
169 printf("Detected required buffer size %lld\n", value);
170
171 buffer = malloc(value);
172 if (buffer == NULL) {
173 printf("failed to alloc memory for ioctl\n");
174 ret = -ENOMEM;
175 goto out;
176 }
177 buffer->length = value;
178
179 /* simple SMBIOS call for looking up TPM info */
180 buffer->std.cmd_class = CLASS_FLASH_INTERFACE;
181 buffer->std.cmd_select = SELECT_FLASH_INTERFACE;
182 buffer->std.input[0] = 2;
183 ret = run_wmi_smbios_cmd(buffer);
184 if (ret) {
185 printf("smbios ioctl failed: %d\n", ret);
186 ret = EXIT_FAILURE;
187 goto out;
188 }
189 show_buffer(buffer);
190
191 /* query some tokens */
192 ret = query_token(CAPSULE_EN_TOKEN, buffer);
193 printf("UEFI Capsule enabled token is: %d\n", ret);
194 ret = query_token(CAPSULE_DIS_TOKEN, buffer);
195 printf("UEFI Capsule disabled token is: %d\n", ret);
196
197 /* activate UEFI capsule token if disabled */
198 if (ret) {
199 printf("Enabling UEFI capsule token");
200 if (activate_token(buffer, CAPSULE_EN_TOKEN)) {
201 printf("activate failed\n");
202 ret = -1;
203 goto out;
204 }
205 }
206 ret = EXIT_SUCCESS;
207out:
208 free(buffer);
209 return ret;
210}