aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-03-26 04:17:40 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-03-26 04:17:40 -0400
commit80045e14423aaf1d3d51bca0524336f8a624003e (patch)
tree915319f6d353a2e8c1f69a16502e61d6020f3bc4
parent5cec2d2e5839f9c0fec319c523a911e0a7fd299f (diff)
parent7c22278edd0a931c565a8511dfc1bc57ffbb9166 (diff)
Merge tag 'misc-habanalabs-fixes-2019-03-26' of git://people.freedesktop.org/~gabbayo/linux into char-misc-next:
Oded writes: The following bug fixes are included in this tag: - Fix host crash upon resume after suspend - Fix MMU related bugs which result in user's jobs getting stuck - Fix race between user context cleanup and hard-reset which results in host crash - Fix sparse warning * tag 'misc-habanalabs-fixes-2019-03-26' of git://people.freedesktop.org/~gabbayo/linux: (265 commits) habanalabs: cast to expected type habanalabs: prevent host crash during suspend/resume habanalabs: perform accounting for active CS habanalabs: fix mapping with page size bigger than 4KB habanalabs: complete user context cleanup before hard reset habanalabs: fix bug when mapping very large memory area habanalabs: fix MMU number of pages calculation Linux 5.1-rc2 clocksource/drivers/clps711x: Remove board support ext4: prohibit fstrim in norecovery mode ext4: cleanup bh release code in ext4_ind_remove_space() ext4: brelse all indirect buffer in ext4_ind_remove_space() genirq: Mark expected switch case fall-through clocksource/drivers/riscv: Fix clocksource mask x86/gart: Exclude GART aperture from kcore cifs: update internal module version number SMB3: Fix SMB3.1.1 guest mounts to Samba cifs: Fix slab-out-of-bounds when tracing SMB tcon cifs: allow guest mounts to work for smb3.11 fix incorrect error code mapping for OBJECTID_NOT_FOUND ...
-rw-r--r--Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt1
-rw-r--r--MAINTAINERS10
-rw-r--r--Makefile2
-rw-r--r--arch/arc/Kconfig21
-rw-r--r--arch/arc/Makefile6
-rw-r--r--arch/arc/boot/dts/abilis_tb100.dtsi58
-rw-r--r--arch/arc/boot/dts/abilis_tb100_dvk.dts14
-rw-r--r--arch/arc/boot/dts/abilis_tb101.dtsi58
-rw-r--r--arch/arc/boot/dts/abilis_tb101_dvk.dts14
-rw-r--r--arch/arc/boot/dts/abilis_tb10x.dtsi60
-rw-r--r--arch/arc/boot/dts/axc001.dtsi6
-rw-r--r--arch/arc/boot/dts/axc003.dtsi16
-rw-r--r--arch/arc/boot/dts/axc003_idu.dtsi16
-rw-r--r--arch/arc/boot/dts/axs10x_mb.dtsi22
-rw-r--r--arch/arc/boot/dts/hsdk.dts33
-rw-r--r--arch/arc/boot/dts/vdk_axc003.dtsi4
-rw-r--r--arch/arc/boot/dts/vdk_axc003_idu.dtsi4
-rw-r--r--arch/arc/boot/dts/vdk_axs10x_mb.dtsi18
-rw-r--r--arch/arc/configs/hsdk_defconfig1
-rw-r--r--arch/arc/include/asm/arcregs.h12
-rw-r--r--arch/arc/include/asm/irqflags-arcv2.h8
-rw-r--r--arch/arc/include/asm/perf_event.h2
-rw-r--r--arch/arc/include/asm/spinlock.h49
-rw-r--r--arch/arc/kernel/head.S6
-rw-r--r--arch/arc/kernel/intc-arcv2.c2
-rw-r--r--arch/arc/kernel/setup.c211
-rw-r--r--arch/arc/kernel/troubleshoot.c5
-rw-r--r--arch/arc/lib/Makefile8
-rw-r--r--arch/arc/lib/memcpy-archs-unaligned.S47
-rw-r--r--arch/arc/plat-eznps/Kconfig12
-rw-r--r--arch/arm/mach-cns3xxx/core.c2
-rw-r--r--arch/arm64/Kconfig1
-rw-r--r--arch/arm64/include/asm/cputype.h6
-rw-r--r--arch/arm64/kernel/cpufeature.c1
-rw-r--r--arch/arm64/kernel/probes/kprobes.c56
-rw-r--r--arch/arm64/kernel/stacktrace.c1
-rw-r--r--arch/mips/bcm47xx/workarounds.c1
-rw-r--r--arch/mips/include/asm/jump_label.h8
-rw-r--r--arch/mips/include/uapi/asm/posix_types.h7
-rw-r--r--arch/mips/kernel/vmlinux.lds.S12
-rw-r--r--arch/mips/loongson64/lemote-2f/irq.c2
-rw-r--r--arch/powerpc/include/asm/mmu.h2
-rw-r--r--arch/powerpc/include/asm/vdso_datapage.h8
-rw-r--r--arch/powerpc/kernel/cpu_setup_6xx.S3
-rw-r--r--arch/powerpc/kernel/head_32.S6
-rw-r--r--arch/powerpc/kernel/security.c23
-rw-r--r--arch/powerpc/kernel/vdso64/gettimeofday.S4
-rw-r--r--arch/powerpc/mm/hash_low_32.S8
-rw-r--r--arch/x86/boot/string.c3
-rw-r--r--arch/x86/hyperv/hv_init.c6
-rw-r--r--arch/x86/include/asm/cpu_device_id.h31
-rw-r--r--arch/x86/include/asm/processor-cyrix.h21
-rw-r--r--arch/x86/kernel/aperture_64.c20
-rw-r--r--arch/x86/kernel/cpu/cyrix.c14
-rw-r--r--arch/x86/kernel/cpu/microcode/core.c2
-rw-r--r--arch/x86/kernel/hpet.c2
-rw-r--r--arch/x86/kernel/hw_breakpoint.c1
-rw-r--r--arch/x86/kernel/mpparse.c4
-rw-r--r--arch/x86/lib/csum-partial_64.c2
-rw-r--r--arch/x86/mm/pti.c4
-rw-r--r--block/bio.c43
-rw-r--r--block/blk-cgroup.c9
-rw-r--r--block/blk-iolatency.c1
-rw-r--r--block/blk-mq.c8
-rw-r--r--block/blk-mq.h2
-rw-r--r--block/blk-sysfs.c12
-rw-r--r--drivers/acpi/utils.c1
-rw-r--r--drivers/auxdisplay/Kconfig38
-rw-r--r--drivers/auxdisplay/Makefile2
-rw-r--r--drivers/auxdisplay/charlcd.c55
-rw-r--r--drivers/auxdisplay/hd44780.c4
-rw-r--r--drivers/auxdisplay/panel.c4
-rw-r--r--drivers/base/power/domain.c13
-rw-r--r--drivers/base/swnode.c4
-rw-r--r--drivers/block/loop.c2
-rw-r--r--drivers/block/paride/pcd.c6
-rw-r--r--drivers/block/paride/pf.c16
-rw-r--r--drivers/block/rbd.c28
-rw-r--r--drivers/clocksource/clps711x-timer.c44
-rw-r--r--drivers/clocksource/mips-gic-timer.c2
-rw-r--r--drivers/clocksource/tcb_clksrc.c4
-rw-r--r--drivers/clocksource/timer-riscv.c5
-rw-r--r--drivers/clocksource/timer-ti-dm.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_mixer.c110
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c15
-rw-r--r--drivers/gpu/drm/i915/i915_gpu_error.c2
-rw-r--r--drivers/gpu/drm/i915/intel_bios.c1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_debugfs.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_dmem.c12
-rw-r--r--drivers/gpu/drm/udl/udl_gem.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fb.c12
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c2
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_utils.c12
-rw-r--r--drivers/infiniband/hw/mlx4/alias_GUID.c2
-rw-r--r--drivers/infiniband/hw/mlx5/devx.c34
-rw-r--r--drivers/infiniband/hw/mlx5/main.c7
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c4
-rw-r--r--drivers/iommu/amd_iommu.c7
-rw-r--r--drivers/iommu/intel-iommu.c5
-rw-r--r--drivers/iommu/iova.c5
-rw-r--r--drivers/irqchip/irq-brcmstb-l2.c4
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c2
-rw-r--r--drivers/irqchip/irq-gic.c45
-rw-r--r--drivers/irqchip/irq-imx-irqsteer.c8
-rw-r--r--drivers/irqchip/irq-mbigen.c3
-rw-r--r--drivers/irqchip/irq-mmp.c2
-rw-r--r--drivers/irqchip/irq-mvebu-sei.c2
-rw-r--r--drivers/irqchip/irq-stm32-exti.c10
-rw-r--r--drivers/misc/habanalabs/command_submission.c6
-rw-r--r--drivers/misc/habanalabs/debugfs.c7
-rw-r--r--drivers/misc/habanalabs/device.c71
-rw-r--r--drivers/misc/habanalabs/goya/goya.c65
-rw-r--r--drivers/misc/habanalabs/habanalabs.h21
-rw-r--r--drivers/misc/habanalabs/hw_queue.c5
-rw-r--r--drivers/misc/habanalabs/memory.c38
-rw-r--r--drivers/misc/habanalabs/mmu.c6
-rw-r--r--drivers/mmc/host/alcor.c25
-rw-r--r--drivers/mmc/host/davinci_mmc.c2
-rw-r--r--drivers/mmc/host/mxcmmc.c16
-rw-r--r--drivers/mmc/host/pxamci.c2
-rw-r--r--drivers/mmc/host/renesas_sdhi_core.c8
-rw-r--r--drivers/mmc/host/sdhci-omap.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/qp.c72
-rw-r--r--drivers/platform/chrome/cros_ec_debugfs.c10
-rw-r--r--drivers/platform/chrome/wilco_ec/mailbox.c2
-rw-r--r--drivers/scsi/hisi_sas/hisi_sas_main.c6
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c23
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c7
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c2
-rw-r--r--drivers/scsi/scsi_lib.c15
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c2
-rw-r--r--drivers/thermal/broadcom/bcm2835_thermal.c9
-rw-r--r--drivers/thermal/cpu_cooling.c3
-rw-r--r--drivers/thermal/intel/int340x_thermal/int3400_thermal.c21
-rw-r--r--drivers/thermal/intel/intel_powerclamp.c4
-rw-r--r--drivers/thermal/mtk_thermal.c7
-rw-r--r--drivers/thermal/samsung/exynos_tmu.c2
-rw-r--r--fs/block_dev.c12
-rw-r--r--fs/cifs/cifsfs.c2
-rw-r--r--fs/cifs/cifsfs.h2
-rw-r--r--fs/cifs/file.c148
-rw-r--r--fs/cifs/smb2maperror.c3
-rw-r--r--fs/cifs/smb2pdu.c11
-rw-r--r--fs/cifs/trace.h6
-rw-r--r--fs/ext4/ext4_jbd2.h2
-rw-r--r--fs/ext4/file.c2
-rw-r--r--fs/ext4/indirect.c43
-rw-r--r--fs/ext4/inode.c30
-rw-r--r--fs/ext4/ioctl.c7
-rw-r--r--fs/ext4/resize.c17
-rw-r--r--fs/ext4/super.c16
-rw-r--r--fs/io_uring.c439
-rw-r--r--fs/iomap.c12
-rw-r--r--fs/notify/fanotify/fanotify_user.c12
-rw-r--r--fs/notify/inotify/inotify_user.c7
-rw-r--r--fs/proc/kcore.c27
-rw-r--r--fs/udf/inode.c4
-rw-r--r--fs/udf/truncate.c8
-rw-r--r--fs/udf/udfdecl.h2
-rw-r--r--include/linux/blk-mq.h3
-rw-r--r--include/linux/blk_types.h1
-rw-r--r--include/linux/blkdev.h3
-rw-r--r--include/linux/ceph/libceph.h2
-rw-r--r--include/linux/irq.h2
-rw-r--r--include/linux/irqchip/arm-gic.h3
-rw-r--r--include/linux/kcore.h2
-rw-r--r--include/linux/mlx5/qp.h3
-rw-r--r--include/linux/sbitmap.h2
-rw-r--r--include/linux/uio.h24
-rw-r--r--include/misc/charlcd.h1
-rw-r--r--kernel/events/core.c2
-rw-r--r--kernel/futex.c4
-rw-r--r--kernel/irq/devres.c2
-rw-r--r--kernel/irq/manage.c1
-rw-r--r--kernel/sched/core.c2
-rw-r--r--kernel/sched/cpufreq_schedutil.c59
-rw-r--r--kernel/sched/fair.c84
-rw-r--r--kernel/time/jiffies.c2
-rw-r--r--kernel/watchdog.c4
-rw-r--r--kernel/workqueue.c5
-rw-r--r--net/ceph/ceph_common.c18
-rw-r--r--net/ceph/mon_client.c9
-rw-r--r--security/selinux/ss/policydb.c13
-rw-r--r--sound/drivers/opl3/opl3_voice.h2
-rw-r--r--sound/firewire/motu/motu.c20
-rw-r--r--sound/isa/sb/sb8.c4
-rw-r--r--sound/pci/echoaudio/echoaudio.c5
-rw-r--r--sound/pci/hda/hda_codec.c20
-rw-r--r--sound/pci/hda/hda_intel.c14
-rw-r--r--sound/pci/hda/patch_realtek.c17
-rw-r--r--tools/arch/arm64/include/uapi/asm/unistd.h2
-rw-r--r--tools/bpf/bpftool/prog.c266
-rw-r--r--tools/build/Makefile.feature6
-rw-r--r--tools/build/feature/test-all.c5
-rw-r--r--tools/include/uapi/asm-generic/unistd.h149
-rw-r--r--tools/include/uapi/linux/in.h9
-rw-r--r--tools/lib/bpf/libbpf.c253
-rw-r--r--tools/lib/bpf/libbpf.h64
-rw-r--r--tools/lib/bpf/libbpf.map3
-rw-r--r--tools/objtool/check.c3
-rw-r--r--tools/perf/Documentation/Build.txt24
-rw-r--r--tools/perf/Documentation/perf-config.txt16
-rw-r--r--tools/perf/Documentation/perf-record.txt4
-rw-r--r--tools/perf/Documentation/perf-report.txt13
-rw-r--r--tools/perf/Documentation/perf-script.txt3
-rw-r--r--tools/perf/Documentation/perf-stat.txt5
-rw-r--r--tools/perf/Documentation/tips.txt7
-rw-r--r--tools/perf/Makefile.config15
-rw-r--r--tools/perf/arch/x86/entry/syscalls/syscall_64.tbl6
-rw-r--r--tools/perf/arch/x86/util/Build1
-rw-r--r--tools/perf/arch/x86/util/archinsn.c26
-rw-r--r--tools/perf/bench/epoll-ctl.c2
-rw-r--r--tools/perf/bench/epoll-wait.c2
-rw-r--r--tools/perf/builtin-list.c2
-rw-r--r--tools/perf/builtin-record.c54
-rw-r--r--tools/perf/builtin-report.c50
-rw-r--r--tools/perf/builtin-script.c129
-rw-r--r--tools/perf/builtin-stat.c3
-rw-r--r--tools/perf/builtin-top.c62
-rw-r--r--tools/perf/builtin.h3
-rw-r--r--tools/perf/perf.c1
-rw-r--r--tools/perf/perf.h2
-rw-r--r--tools/perf/pmu-events/arch/powerpc/power8/other.json594
-rw-r--r--tools/perf/pmu-events/arch/x86/amdfam17h/branch.json12
-rw-r--r--tools/perf/pmu-events/arch/x86/amdfam17h/cache.json287
-rw-r--r--tools/perf/pmu-events/arch/x86/amdfam17h/core.json134
-rw-r--r--tools/perf/pmu-events/arch/x86/amdfam17h/floating-point.json168
-rw-r--r--tools/perf/pmu-events/arch/x86/amdfam17h/memory.json162
-rw-r--r--tools/perf/pmu-events/arch/x86/amdfam17h/other.json65
-rw-r--r--tools/perf/pmu-events/arch/x86/mapfile.csv1
-rw-r--r--tools/perf/scripts/python/export-to-postgresql.py61
-rw-r--r--tools/perf/scripts/python/export-to-sqlite.py26
-rwxr-xr-xtools/perf/scripts/python/exported-sql-viewer.py42
-rw-r--r--tools/perf/tests/attr/test-record-C02
-rw-r--r--tools/perf/tests/attr/test-record-basic2
-rw-r--r--tools/perf/tests/attr/test-record-branch-any2
-rw-r--r--tools/perf/tests/attr/test-record-branch-filter-any2
-rw-r--r--tools/perf/tests/attr/test-record-branch-filter-any_call2
-rw-r--r--tools/perf/tests/attr/test-record-branch-filter-any_ret2
-rw-r--r--tools/perf/tests/attr/test-record-branch-filter-hv2
-rw-r--r--tools/perf/tests/attr/test-record-branch-filter-ind_call2
-rw-r--r--tools/perf/tests/attr/test-record-branch-filter-k2
-rw-r--r--tools/perf/tests/attr/test-record-branch-filter-u2
-rw-r--r--tools/perf/tests/attr/test-record-count2
-rw-r--r--tools/perf/tests/attr/test-record-data2
-rw-r--r--tools/perf/tests/attr/test-record-freq2
-rw-r--r--tools/perf/tests/attr/test-record-graph-default2
-rw-r--r--tools/perf/tests/attr/test-record-graph-dwarf2
-rw-r--r--tools/perf/tests/attr/test-record-graph-fp2
-rw-r--r--tools/perf/tests/attr/test-record-group2
-rw-r--r--tools/perf/tests/attr/test-record-group-sampling2
-rw-r--r--tools/perf/tests/attr/test-record-group12
-rw-r--r--tools/perf/tests/attr/test-record-no-buffering2
-rw-r--r--tools/perf/tests/attr/test-record-no-inherit2
-rw-r--r--tools/perf/tests/attr/test-record-no-samples2
-rw-r--r--tools/perf/tests/attr/test-record-period2
-rw-r--r--tools/perf/tests/attr/test-record-raw2
-rw-r--r--tools/perf/tests/backward-ring-buffer.c2
-rw-r--r--tools/perf/tests/evsel-tp-sched.c1
-rw-r--r--tools/perf/tests/expr.c5
-rw-r--r--tools/perf/tests/openat-syscall-all-cpus.c4
-rw-r--r--tools/perf/ui/browser.c10
-rw-r--r--tools/perf/ui/browsers/Build1
-rw-r--r--tools/perf/ui/browsers/annotate.c2
-rw-r--r--tools/perf/ui/browsers/hists.c141
-rw-r--r--tools/perf/ui/browsers/res_sample.c91
-rw-r--r--tools/perf/ui/browsers/scripts.c274
-rw-r--r--tools/perf/util/annotate.c163
-rw-r--r--tools/perf/util/annotate.h1
-rw-r--r--tools/perf/util/archinsn.h12
-rw-r--r--tools/perf/util/bpf-event.c425
-rw-r--r--tools/perf/util/bpf-event.h42
-rw-r--r--tools/perf/util/build-id.c1
-rw-r--r--tools/perf/util/config.c3
-rw-r--r--tools/perf/util/data.c107
-rw-r--r--tools/perf/util/data.h14
-rw-r--r--tools/perf/util/dso.c43
-rw-r--r--tools/perf/util/dso.h8
-rw-r--r--tools/perf/util/env.c155
-rw-r--r--tools/perf/util/env.h24
-rw-r--r--tools/perf/util/evlist.c119
-rw-r--r--tools/perf/util/evlist.h12
-rw-r--r--tools/perf/util/evsel.c8
-rw-r--r--tools/perf/util/evsel.h6
-rw-r--r--tools/perf/util/header.c295
-rw-r--r--tools/perf/util/header.h7
-rw-r--r--tools/perf/util/hist.c54
-rw-r--r--tools/perf/util/hist.h31
-rw-r--r--tools/perf/util/map.c18
-rw-r--r--tools/perf/util/ordered-events.c2
-rw-r--r--tools/perf/util/parse-events.c2
-rw-r--r--tools/perf/util/probe-event.c6
-rw-r--r--tools/perf/util/session.c28
-rw-r--r--tools/perf/util/sort.c91
-rw-r--r--tools/perf/util/sort.h12
-rw-r--r--tools/perf/util/stat.c12
-rw-r--r--tools/perf/util/symbol.c5
-rw-r--r--tools/perf/util/symbol_conf.h3
-rw-r--r--tools/perf/util/time-utils.c8
-rw-r--r--tools/perf/util/time-utils.h1
-rw-r--r--tools/power/x86/turbostat/turbostat.c3
303 files changed, 5561 insertions, 2694 deletions
diff --git a/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt b/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
index 8de96a4fb2d5..f977ea7617f6 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
@@ -16,6 +16,7 @@ Required properties:
16 - "renesas,irqc-r8a7793" (R-Car M2-N) 16 - "renesas,irqc-r8a7793" (R-Car M2-N)
17 - "renesas,irqc-r8a7794" (R-Car E2) 17 - "renesas,irqc-r8a7794" (R-Car E2)
18 - "renesas,intc-ex-r8a774a1" (RZ/G2M) 18 - "renesas,intc-ex-r8a774a1" (RZ/G2M)
19 - "renesas,intc-ex-r8a774c0" (RZ/G2E)
19 - "renesas,intc-ex-r8a7795" (R-Car H3) 20 - "renesas,intc-ex-r8a7795" (R-Car H3)
20 - "renesas,intc-ex-r8a7796" (R-Car M3-W) 21 - "renesas,intc-ex-r8a7796" (R-Car M3-W)
21 - "renesas,intc-ex-r8a77965" (R-Car M3-N) 22 - "renesas,intc-ex-r8a77965" (R-Car M3-N)
diff --git a/MAINTAINERS b/MAINTAINERS
index e17ebf70b548..3e5a5d263f29 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8096,6 +8096,16 @@ F: include/linux/iommu.h
8096F: include/linux/of_iommu.h 8096F: include/linux/of_iommu.h
8097F: include/linux/iova.h 8097F: include/linux/iova.h
8098 8098
8099IO_URING
8100M: Jens Axboe <axboe@kernel.dk>
8101L: linux-block@vger.kernel.org
8102L: linux-fsdevel@vger.kernel.org
8103T: git git://git.kernel.dk/linux-block
8104T: git git://git.kernel.dk/liburing
8105S: Maintained
8106F: fs/io_uring.c
8107F: include/uapi/linux/io_uring.h
8108
8099IP MASQUERADING 8109IP MASQUERADING
8100M: Juanjo Ciarlante <jjciarla@raiz.uncu.edu.ar> 8110M: Juanjo Ciarlante <jjciarla@raiz.uncu.edu.ar>
8101S: Maintained 8111S: Maintained
diff --git a/Makefile b/Makefile
index 99c0530489ef..c0a34064c574 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
2VERSION = 5 2VERSION = 5
3PATCHLEVEL = 1 3PATCHLEVEL = 1
4SUBLEVEL = 0 4SUBLEVEL = 0
5EXTRAVERSION = -rc1 5EXTRAVERSION = -rc2
6NAME = Shy Crocodile 6NAME = Shy Crocodile
7 7
8# *DOCUMENTATION* 8# *DOCUMENTATION*
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index df55672c59e6..c781e45d1d99 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -144,11 +144,11 @@ config ARC_CPU_770
144 Support for ARC770 core introduced with Rel 4.10 (Summer 2011) 144 Support for ARC770 core introduced with Rel 4.10 (Summer 2011)
145 This core has a bunch of cool new features: 145 This core has a bunch of cool new features:
146 -MMU-v3: Variable Page Sz (4k, 8k, 16k), bigger J-TLB (128x4) 146 -MMU-v3: Variable Page Sz (4k, 8k, 16k), bigger J-TLB (128x4)
147 Shared Address Spaces (for sharing TLB entries in MMU) 147 Shared Address Spaces (for sharing TLB entries in MMU)
148 -Caches: New Prog Model, Region Flush 148 -Caches: New Prog Model, Region Flush
149 -Insns: endian swap, load-locked/store-conditional, time-stamp-ctr 149 -Insns: endian swap, load-locked/store-conditional, time-stamp-ctr
150 150
151endif #ISA_ARCOMPACT 151endif #ISA_ARCOMPACT
152 152
153config ARC_CPU_HS 153config ARC_CPU_HS
154 bool "ARC-HS" 154 bool "ARC-HS"
@@ -198,7 +198,7 @@ config ARC_SMP_HALT_ON_RESET
198 at designated entry point. For other case, all jump to common 198 at designated entry point. For other case, all jump to common
199 entry point and spin wait for Master's signal. 199 entry point and spin wait for Master's signal.
200 200
201endif #SMP 201endif #SMP
202 202
203config ARC_MCIP 203config ARC_MCIP
204 bool "ARConnect Multicore IP (MCIP) Support " 204 bool "ARConnect Multicore IP (MCIP) Support "
@@ -249,7 +249,7 @@ config ARC_CACHE_VIPT_ALIASING
249 bool "Support VIPT Aliasing D$" 249 bool "Support VIPT Aliasing D$"
250 depends on ARC_HAS_DCACHE && ISA_ARCOMPACT 250 depends on ARC_HAS_DCACHE && ISA_ARCOMPACT
251 251
252endif #ARC_CACHE 252endif #ARC_CACHE
253 253
254config ARC_HAS_ICCM 254config ARC_HAS_ICCM
255 bool "Use ICCM" 255 bool "Use ICCM"
@@ -370,7 +370,7 @@ config ARC_FPU_SAVE_RESTORE
370 based on actual usage of FPU by a task. Thus our implemn does 370 based on actual usage of FPU by a task. Thus our implemn does
371 this for all tasks in system. 371 this for all tasks in system.
372 372
373endif #ISA_ARCOMPACT 373endif #ISA_ARCOMPACT
374 374
375config ARC_CANT_LLSC 375config ARC_CANT_LLSC
376 def_bool n 376 def_bool n
@@ -386,6 +386,15 @@ config ARC_HAS_SWAPE
386 386
387if ISA_ARCV2 387if ISA_ARCV2
388 388
389config ARC_USE_UNALIGNED_MEM_ACCESS
390 bool "Enable unaligned access in HW"
391 default y
392 select HAVE_EFFICIENT_UNALIGNED_ACCESS
393 help
394 The ARC HS architecture supports unaligned memory access
395 which is disabled by default. Enable unaligned access in
396 hardware and use software to use it
397
389config ARC_HAS_LL64 398config ARC_HAS_LL64
390 bool "Insn: 64bit LDD/STD" 399 bool "Insn: 64bit LDD/STD"
391 help 400 help
@@ -414,7 +423,7 @@ config ARC_IRQ_NO_AUTOSAVE
414 This is programmable and can be optionally disabled in which case 423 This is programmable and can be optionally disabled in which case
415 software INTERRUPT_PROLOGUE/EPILGUE do the needed work 424 software INTERRUPT_PROLOGUE/EPILGUE do the needed work
416 425
417endif # ISA_ARCV2 426endif # ISA_ARCV2
418 427
419endmenu # "ARC CPU Configuration" 428endmenu # "ARC CPU Configuration"
420 429
diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index df00578c279d..e2b991f75bc5 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -28,6 +28,12 @@ cflags-$(CONFIG_ARC_HAS_SWAPE) += -mswape
28 28
29ifdef CONFIG_ISA_ARCV2 29ifdef CONFIG_ISA_ARCV2
30 30
31ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
32cflags-y += -munaligned-access
33else
34cflags-y += -mno-unaligned-access
35endif
36
31ifndef CONFIG_ARC_HAS_LL64 37ifndef CONFIG_ARC_HAS_LL64
32cflags-y += -mno-ll64 38cflags-y += -mno-ll64
33endif 39endif
diff --git a/arch/arc/boot/dts/abilis_tb100.dtsi b/arch/arc/boot/dts/abilis_tb100.dtsi
index 02410b211433..c0bcd97522bb 100644
--- a/arch/arc/boot/dts/abilis_tb100.dtsi
+++ b/arch/arc/boot/dts/abilis_tb100.dtsi
@@ -38,7 +38,7 @@
38 clock-div = <6>; 38 clock-div = <6>;
39 }; 39 };
40 40
41 iomux: iomux@FF10601c { 41 iomux: iomux@ff10601c {
42 /* Port 1 */ 42 /* Port 1 */
43 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */ 43 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */
44 abilis,function = "mis0"; 44 abilis,function = "mis0";
@@ -162,182 +162,182 @@
162 }; 162 };
163 }; 163 };
164 164
165 gpioa: gpio@FF140000 { 165 gpioa: gpio@ff140000 {
166 compatible = "abilis,tb10x-gpio"; 166 compatible = "abilis,tb10x-gpio";
167 interrupt-controller; 167 interrupt-controller;
168 #interrupt-cells = <1>; 168 #interrupt-cells = <1>;
169 interrupt-parent = <&tb10x_ictl>; 169 interrupt-parent = <&tb10x_ictl>;
170 interrupts = <27 2>; 170 interrupts = <27 2>;
171 reg = <0xFF140000 0x1000>; 171 reg = <0xff140000 0x1000>;
172 gpio-controller; 172 gpio-controller;
173 #gpio-cells = <2>; 173 #gpio-cells = <2>;
174 abilis,ngpio = <3>; 174 abilis,ngpio = <3>;
175 gpio-ranges = <&iomux 0 0 0>; 175 gpio-ranges = <&iomux 0 0 0>;
176 gpio-ranges-group-names = "gpioa"; 176 gpio-ranges-group-names = "gpioa";
177 }; 177 };
178 gpiob: gpio@FF141000 { 178 gpiob: gpio@ff141000 {
179 compatible = "abilis,tb10x-gpio"; 179 compatible = "abilis,tb10x-gpio";
180 interrupt-controller; 180 interrupt-controller;
181 #interrupt-cells = <1>; 181 #interrupt-cells = <1>;
182 interrupt-parent = <&tb10x_ictl>; 182 interrupt-parent = <&tb10x_ictl>;
183 interrupts = <27 2>; 183 interrupts = <27 2>;
184 reg = <0xFF141000 0x1000>; 184 reg = <0xff141000 0x1000>;
185 gpio-controller; 185 gpio-controller;
186 #gpio-cells = <2>; 186 #gpio-cells = <2>;
187 abilis,ngpio = <2>; 187 abilis,ngpio = <2>;
188 gpio-ranges = <&iomux 0 0 0>; 188 gpio-ranges = <&iomux 0 0 0>;
189 gpio-ranges-group-names = "gpiob"; 189 gpio-ranges-group-names = "gpiob";
190 }; 190 };
191 gpioc: gpio@FF142000 { 191 gpioc: gpio@ff142000 {
192 compatible = "abilis,tb10x-gpio"; 192 compatible = "abilis,tb10x-gpio";
193 interrupt-controller; 193 interrupt-controller;
194 #interrupt-cells = <1>; 194 #interrupt-cells = <1>;
195 interrupt-parent = <&tb10x_ictl>; 195 interrupt-parent = <&tb10x_ictl>;
196 interrupts = <27 2>; 196 interrupts = <27 2>;
197 reg = <0xFF142000 0x1000>; 197 reg = <0xff142000 0x1000>;
198 gpio-controller; 198 gpio-controller;
199 #gpio-cells = <2>; 199 #gpio-cells = <2>;
200 abilis,ngpio = <3>; 200 abilis,ngpio = <3>;
201 gpio-ranges = <&iomux 0 0 0>; 201 gpio-ranges = <&iomux 0 0 0>;
202 gpio-ranges-group-names = "gpioc"; 202 gpio-ranges-group-names = "gpioc";
203 }; 203 };
204 gpiod: gpio@FF143000 { 204 gpiod: gpio@ff143000 {
205 compatible = "abilis,tb10x-gpio"; 205 compatible = "abilis,tb10x-gpio";
206 interrupt-controller; 206 interrupt-controller;
207 #interrupt-cells = <1>; 207 #interrupt-cells = <1>;
208 interrupt-parent = <&tb10x_ictl>; 208 interrupt-parent = <&tb10x_ictl>;
209 interrupts = <27 2>; 209 interrupts = <27 2>;
210 reg = <0xFF143000 0x1000>; 210 reg = <0xff143000 0x1000>;
211 gpio-controller; 211 gpio-controller;
212 #gpio-cells = <2>; 212 #gpio-cells = <2>;
213 abilis,ngpio = <2>; 213 abilis,ngpio = <2>;
214 gpio-ranges = <&iomux 0 0 0>; 214 gpio-ranges = <&iomux 0 0 0>;
215 gpio-ranges-group-names = "gpiod"; 215 gpio-ranges-group-names = "gpiod";
216 }; 216 };
217 gpioe: gpio@FF144000 { 217 gpioe: gpio@ff144000 {
218 compatible = "abilis,tb10x-gpio"; 218 compatible = "abilis,tb10x-gpio";
219 interrupt-controller; 219 interrupt-controller;
220 #interrupt-cells = <1>; 220 #interrupt-cells = <1>;
221 interrupt-parent = <&tb10x_ictl>; 221 interrupt-parent = <&tb10x_ictl>;
222 interrupts = <27 2>; 222 interrupts = <27 2>;
223 reg = <0xFF144000 0x1000>; 223 reg = <0xff144000 0x1000>;
224 gpio-controller; 224 gpio-controller;
225 #gpio-cells = <2>; 225 #gpio-cells = <2>;
226 abilis,ngpio = <3>; 226 abilis,ngpio = <3>;
227 gpio-ranges = <&iomux 0 0 0>; 227 gpio-ranges = <&iomux 0 0 0>;
228 gpio-ranges-group-names = "gpioe"; 228 gpio-ranges-group-names = "gpioe";
229 }; 229 };
230 gpiof: gpio@FF145000 { 230 gpiof: gpio@ff145000 {
231 compatible = "abilis,tb10x-gpio"; 231 compatible = "abilis,tb10x-gpio";
232 interrupt-controller; 232 interrupt-controller;
233 #interrupt-cells = <1>; 233 #interrupt-cells = <1>;
234 interrupt-parent = <&tb10x_ictl>; 234 interrupt-parent = <&tb10x_ictl>;
235 interrupts = <27 2>; 235 interrupts = <27 2>;
236 reg = <0xFF145000 0x1000>; 236 reg = <0xff145000 0x1000>;
237 gpio-controller; 237 gpio-controller;
238 #gpio-cells = <2>; 238 #gpio-cells = <2>;
239 abilis,ngpio = <2>; 239 abilis,ngpio = <2>;
240 gpio-ranges = <&iomux 0 0 0>; 240 gpio-ranges = <&iomux 0 0 0>;
241 gpio-ranges-group-names = "gpiof"; 241 gpio-ranges-group-names = "gpiof";
242 }; 242 };
243 gpiog: gpio@FF146000 { 243 gpiog: gpio@ff146000 {
244 compatible = "abilis,tb10x-gpio"; 244 compatible = "abilis,tb10x-gpio";
245 interrupt-controller; 245 interrupt-controller;
246 #interrupt-cells = <1>; 246 #interrupt-cells = <1>;
247 interrupt-parent = <&tb10x_ictl>; 247 interrupt-parent = <&tb10x_ictl>;
248 interrupts = <27 2>; 248 interrupts = <27 2>;
249 reg = <0xFF146000 0x1000>; 249 reg = <0xff146000 0x1000>;
250 gpio-controller; 250 gpio-controller;
251 #gpio-cells = <2>; 251 #gpio-cells = <2>;
252 abilis,ngpio = <3>; 252 abilis,ngpio = <3>;
253 gpio-ranges = <&iomux 0 0 0>; 253 gpio-ranges = <&iomux 0 0 0>;
254 gpio-ranges-group-names = "gpiog"; 254 gpio-ranges-group-names = "gpiog";
255 }; 255 };
256 gpioh: gpio@FF147000 { 256 gpioh: gpio@ff147000 {
257 compatible = "abilis,tb10x-gpio"; 257 compatible = "abilis,tb10x-gpio";
258 interrupt-controller; 258 interrupt-controller;
259 #interrupt-cells = <1>; 259 #interrupt-cells = <1>;
260 interrupt-parent = <&tb10x_ictl>; 260 interrupt-parent = <&tb10x_ictl>;
261 interrupts = <27 2>; 261 interrupts = <27 2>;
262 reg = <0xFF147000 0x1000>; 262 reg = <0xff147000 0x1000>;
263 gpio-controller; 263 gpio-controller;
264 #gpio-cells = <2>; 264 #gpio-cells = <2>;
265 abilis,ngpio = <2>; 265 abilis,ngpio = <2>;
266 gpio-ranges = <&iomux 0 0 0>; 266 gpio-ranges = <&iomux 0 0 0>;
267 gpio-ranges-group-names = "gpioh"; 267 gpio-ranges-group-names = "gpioh";
268 }; 268 };
269 gpioi: gpio@FF148000 { 269 gpioi: gpio@ff148000 {
270 compatible = "abilis,tb10x-gpio"; 270 compatible = "abilis,tb10x-gpio";
271 interrupt-controller; 271 interrupt-controller;
272 #interrupt-cells = <1>; 272 #interrupt-cells = <1>;
273 interrupt-parent = <&tb10x_ictl>; 273 interrupt-parent = <&tb10x_ictl>;
274 interrupts = <27 2>; 274 interrupts = <27 2>;
275 reg = <0xFF148000 0x1000>; 275 reg = <0xff148000 0x1000>;
276 gpio-controller; 276 gpio-controller;
277 #gpio-cells = <2>; 277 #gpio-cells = <2>;
278 abilis,ngpio = <12>; 278 abilis,ngpio = <12>;
279 gpio-ranges = <&iomux 0 0 0>; 279 gpio-ranges = <&iomux 0 0 0>;
280 gpio-ranges-group-names = "gpioi"; 280 gpio-ranges-group-names = "gpioi";
281 }; 281 };
282 gpioj: gpio@FF149000 { 282 gpioj: gpio@ff149000 {
283 compatible = "abilis,tb10x-gpio"; 283 compatible = "abilis,tb10x-gpio";
284 interrupt-controller; 284 interrupt-controller;
285 #interrupt-cells = <1>; 285 #interrupt-cells = <1>;
286 interrupt-parent = <&tb10x_ictl>; 286 interrupt-parent = <&tb10x_ictl>;
287 interrupts = <27 2>; 287 interrupts = <27 2>;
288 reg = <0xFF149000 0x1000>; 288 reg = <0xff149000 0x1000>;
289 gpio-controller; 289 gpio-controller;
290 #gpio-cells = <2>; 290 #gpio-cells = <2>;
291 abilis,ngpio = <32>; 291 abilis,ngpio = <32>;
292 gpio-ranges = <&iomux 0 0 0>; 292 gpio-ranges = <&iomux 0 0 0>;
293 gpio-ranges-group-names = "gpioj"; 293 gpio-ranges-group-names = "gpioj";
294 }; 294 };
295 gpiok: gpio@FF14a000 { 295 gpiok: gpio@ff14a000 {
296 compatible = "abilis,tb10x-gpio"; 296 compatible = "abilis,tb10x-gpio";
297 interrupt-controller; 297 interrupt-controller;
298 #interrupt-cells = <1>; 298 #interrupt-cells = <1>;
299 interrupt-parent = <&tb10x_ictl>; 299 interrupt-parent = <&tb10x_ictl>;
300 interrupts = <27 2>; 300 interrupts = <27 2>;
301 reg = <0xFF14A000 0x1000>; 301 reg = <0xff14a000 0x1000>;
302 gpio-controller; 302 gpio-controller;
303 #gpio-cells = <2>; 303 #gpio-cells = <2>;
304 abilis,ngpio = <22>; 304 abilis,ngpio = <22>;
305 gpio-ranges = <&iomux 0 0 0>; 305 gpio-ranges = <&iomux 0 0 0>;
306 gpio-ranges-group-names = "gpiok"; 306 gpio-ranges-group-names = "gpiok";
307 }; 307 };
308 gpiol: gpio@FF14b000 { 308 gpiol: gpio@ff14b000 {
309 compatible = "abilis,tb10x-gpio"; 309 compatible = "abilis,tb10x-gpio";
310 interrupt-controller; 310 interrupt-controller;
311 #interrupt-cells = <1>; 311 #interrupt-cells = <1>;
312 interrupt-parent = <&tb10x_ictl>; 312 interrupt-parent = <&tb10x_ictl>;
313 interrupts = <27 2>; 313 interrupts = <27 2>;
314 reg = <0xFF14B000 0x1000>; 314 reg = <0xff14b000 0x1000>;
315 gpio-controller; 315 gpio-controller;
316 #gpio-cells = <2>; 316 #gpio-cells = <2>;
317 abilis,ngpio = <4>; 317 abilis,ngpio = <4>;
318 gpio-ranges = <&iomux 0 0 0>; 318 gpio-ranges = <&iomux 0 0 0>;
319 gpio-ranges-group-names = "gpiol"; 319 gpio-ranges-group-names = "gpiol";
320 }; 320 };
321 gpiom: gpio@FF14c000 { 321 gpiom: gpio@ff14c000 {
322 compatible = "abilis,tb10x-gpio"; 322 compatible = "abilis,tb10x-gpio";
323 interrupt-controller; 323 interrupt-controller;
324 #interrupt-cells = <1>; 324 #interrupt-cells = <1>;
325 interrupt-parent = <&tb10x_ictl>; 325 interrupt-parent = <&tb10x_ictl>;
326 interrupts = <27 2>; 326 interrupts = <27 2>;
327 reg = <0xFF14C000 0x1000>; 327 reg = <0xff14c000 0x1000>;
328 gpio-controller; 328 gpio-controller;
329 #gpio-cells = <2>; 329 #gpio-cells = <2>;
330 abilis,ngpio = <4>; 330 abilis,ngpio = <4>;
331 gpio-ranges = <&iomux 0 0 0>; 331 gpio-ranges = <&iomux 0 0 0>;
332 gpio-ranges-group-names = "gpiom"; 332 gpio-ranges-group-names = "gpiom";
333 }; 333 };
334 gpion: gpio@FF14d000 { 334 gpion: gpio@ff14d000 {
335 compatible = "abilis,tb10x-gpio"; 335 compatible = "abilis,tb10x-gpio";
336 interrupt-controller; 336 interrupt-controller;
337 #interrupt-cells = <1>; 337 #interrupt-cells = <1>;
338 interrupt-parent = <&tb10x_ictl>; 338 interrupt-parent = <&tb10x_ictl>;
339 interrupts = <27 2>; 339 interrupts = <27 2>;
340 reg = <0xFF14D000 0x1000>; 340 reg = <0xff14d000 0x1000>;
341 gpio-controller; 341 gpio-controller;
342 #gpio-cells = <2>; 342 #gpio-cells = <2>;
343 abilis,ngpio = <5>; 343 abilis,ngpio = <5>;
diff --git a/arch/arc/boot/dts/abilis_tb100_dvk.dts b/arch/arc/boot/dts/abilis_tb100_dvk.dts
index 3acf04db8030..c968e677db46 100644
--- a/arch/arc/boot/dts/abilis_tb100_dvk.dts
+++ b/arch/arc/boot/dts/abilis_tb100_dvk.dts
@@ -37,27 +37,27 @@
37 }; 37 };
38 38
39 soc100 { 39 soc100 {
40 uart@FF100000 { 40 uart@ff100000 {
41 pinctrl-names = "default"; 41 pinctrl-names = "default";
42 pinctrl-0 = <&pctl_uart0>; 42 pinctrl-0 = <&pctl_uart0>;
43 }; 43 };
44 ethernet@FE100000 { 44 ethernet@fe100000 {
45 phy-mode = "rgmii"; 45 phy-mode = "rgmii";
46 }; 46 };
47 47
48 i2c0: i2c@FF120000 { 48 i2c0: i2c@ff120000 {
49 i2c-sda-hold-time-ns = <432>; 49 i2c-sda-hold-time-ns = <432>;
50 }; 50 };
51 i2c1: i2c@FF121000 { 51 i2c1: i2c@ff121000 {
52 i2c-sda-hold-time-ns = <432>; 52 i2c-sda-hold-time-ns = <432>;
53 }; 53 };
54 i2c2: i2c@FF122000 { 54 i2c2: i2c@ff122000 {
55 i2c-sda-hold-time-ns = <432>; 55 i2c-sda-hold-time-ns = <432>;
56 }; 56 };
57 i2c3: i2c@FF123000 { 57 i2c3: i2c@ff123000 {
58 i2c-sda-hold-time-ns = <432>; 58 i2c-sda-hold-time-ns = <432>;
59 }; 59 };
60 i2c4: i2c@FF124000 { 60 i2c4: i2c@ff124000 {
61 i2c-sda-hold-time-ns = <432>; 61 i2c-sda-hold-time-ns = <432>;
62 }; 62 };
63 63
diff --git a/arch/arc/boot/dts/abilis_tb101.dtsi b/arch/arc/boot/dts/abilis_tb101.dtsi
index f9e7686044eb..6a1615f58f05 100644
--- a/arch/arc/boot/dts/abilis_tb101.dtsi
+++ b/arch/arc/boot/dts/abilis_tb101.dtsi
@@ -38,7 +38,7 @@
38 clock-div = <6>; 38 clock-div = <6>;
39 }; 39 };
40 40
41 iomux: iomux@FF10601c { 41 iomux: iomux@ff10601c {
42 /* Port 1 */ 42 /* Port 1 */
43 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */ 43 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */
44 abilis,function = "mis0"; 44 abilis,function = "mis0";
@@ -171,182 +171,182 @@
171 }; 171 };
172 }; 172 };
173 173
174 gpioa: gpio@FF140000 { 174 gpioa: gpio@ff140000 {
175 compatible = "abilis,tb10x-gpio"; 175 compatible = "abilis,tb10x-gpio";
176 interrupt-controller; 176 interrupt-controller;
177 #interrupt-cells = <1>; 177 #interrupt-cells = <1>;
178 interrupt-parent = <&tb10x_ictl>; 178 interrupt-parent = <&tb10x_ictl>;
179 interrupts = <27 2>; 179 interrupts = <27 2>;
180 reg = <0xFF140000 0x1000>; 180 reg = <0xff140000 0x1000>;
181 gpio-controller; 181 gpio-controller;
182 #gpio-cells = <2>; 182 #gpio-cells = <2>;
183 abilis,ngpio = <3>; 183 abilis,ngpio = <3>;
184 gpio-ranges = <&iomux 0 0 0>; 184 gpio-ranges = <&iomux 0 0 0>;
185 gpio-ranges-group-names = "gpioa"; 185 gpio-ranges-group-names = "gpioa";
186 }; 186 };
187 gpiob: gpio@FF141000 { 187 gpiob: gpio@ff141000 {
188 compatible = "abilis,tb10x-gpio"; 188 compatible = "abilis,tb10x-gpio";
189 interrupt-controller; 189 interrupt-controller;
190 #interrupt-cells = <1>; 190 #interrupt-cells = <1>;
191 interrupt-parent = <&tb10x_ictl>; 191 interrupt-parent = <&tb10x_ictl>;
192 interrupts = <27 2>; 192 interrupts = <27 2>;
193 reg = <0xFF141000 0x1000>; 193 reg = <0xff141000 0x1000>;
194 gpio-controller; 194 gpio-controller;
195 #gpio-cells = <2>; 195 #gpio-cells = <2>;
196 abilis,ngpio = <2>; 196 abilis,ngpio = <2>;
197 gpio-ranges = <&iomux 0 0 0>; 197 gpio-ranges = <&iomux 0 0 0>;
198 gpio-ranges-group-names = "gpiob"; 198 gpio-ranges-group-names = "gpiob";
199 }; 199 };
200 gpioc: gpio@FF142000 { 200 gpioc: gpio@ff142000 {
201 compatible = "abilis,tb10x-gpio"; 201 compatible = "abilis,tb10x-gpio";
202 interrupt-controller; 202 interrupt-controller;
203 #interrupt-cells = <1>; 203 #interrupt-cells = <1>;
204 interrupt-parent = <&tb10x_ictl>; 204 interrupt-parent = <&tb10x_ictl>;
205 interrupts = <27 2>; 205 interrupts = <27 2>;
206 reg = <0xFF142000 0x1000>; 206 reg = <0xff142000 0x1000>;
207 gpio-controller; 207 gpio-controller;
208 #gpio-cells = <2>; 208 #gpio-cells = <2>;
209 abilis,ngpio = <3>; 209 abilis,ngpio = <3>;
210 gpio-ranges = <&iomux 0 0 0>; 210 gpio-ranges = <&iomux 0 0 0>;
211 gpio-ranges-group-names = "gpioc"; 211 gpio-ranges-group-names = "gpioc";
212 }; 212 };
213 gpiod: gpio@FF143000 { 213 gpiod: gpio@ff143000 {
214 compatible = "abilis,tb10x-gpio"; 214 compatible = "abilis,tb10x-gpio";
215 interrupt-controller; 215 interrupt-controller;
216 #interrupt-cells = <1>; 216 #interrupt-cells = <1>;
217 interrupt-parent = <&tb10x_ictl>; 217 interrupt-parent = <&tb10x_ictl>;
218 interrupts = <27 2>; 218 interrupts = <27 2>;
219 reg = <0xFF143000 0x1000>; 219 reg = <0xff143000 0x1000>;
220 gpio-controller; 220 gpio-controller;
221 #gpio-cells = <2>; 221 #gpio-cells = <2>;
222 abilis,ngpio = <2>; 222 abilis,ngpio = <2>;
223 gpio-ranges = <&iomux 0 0 0>; 223 gpio-ranges = <&iomux 0 0 0>;
224 gpio-ranges-group-names = "gpiod"; 224 gpio-ranges-group-names = "gpiod";
225 }; 225 };
226 gpioe: gpio@FF144000 { 226 gpioe: gpio@ff144000 {
227 compatible = "abilis,tb10x-gpio"; 227 compatible = "abilis,tb10x-gpio";
228 interrupt-controller; 228 interrupt-controller;
229 #interrupt-cells = <1>; 229 #interrupt-cells = <1>;
230 interrupt-parent = <&tb10x_ictl>; 230 interrupt-parent = <&tb10x_ictl>;
231 interrupts = <27 2>; 231 interrupts = <27 2>;
232 reg = <0xFF144000 0x1000>; 232 reg = <0xff144000 0x1000>;
233 gpio-controller; 233 gpio-controller;
234 #gpio-cells = <2>; 234 #gpio-cells = <2>;
235 abilis,ngpio = <3>; 235 abilis,ngpio = <3>;
236 gpio-ranges = <&iomux 0 0 0>; 236 gpio-ranges = <&iomux 0 0 0>;
237 gpio-ranges-group-names = "gpioe"; 237 gpio-ranges-group-names = "gpioe";
238 }; 238 };
239 gpiof: gpio@FF145000 { 239 gpiof: gpio@ff145000 {
240 compatible = "abilis,tb10x-gpio"; 240 compatible = "abilis,tb10x-gpio";
241 interrupt-controller; 241 interrupt-controller;
242 #interrupt-cells = <1>; 242 #interrupt-cells = <1>;
243 interrupt-parent = <&tb10x_ictl>; 243 interrupt-parent = <&tb10x_ictl>;
244 interrupts = <27 2>; 244 interrupts = <27 2>;
245 reg = <0xFF145000 0x1000>; 245 reg = <0xff145000 0x1000>;
246 gpio-controller; 246 gpio-controller;
247 #gpio-cells = <2>; 247 #gpio-cells = <2>;
248 abilis,ngpio = <2>; 248 abilis,ngpio = <2>;
249 gpio-ranges = <&iomux 0 0 0>; 249 gpio-ranges = <&iomux 0 0 0>;
250 gpio-ranges-group-names = "gpiof"; 250 gpio-ranges-group-names = "gpiof";
251 }; 251 };
252 gpiog: gpio@FF146000 { 252 gpiog: gpio@ff146000 {
253 compatible = "abilis,tb10x-gpio"; 253 compatible = "abilis,tb10x-gpio";
254 interrupt-controller; 254 interrupt-controller;
255 #interrupt-cells = <1>; 255 #interrupt-cells = <1>;
256 interrupt-parent = <&tb10x_ictl>; 256 interrupt-parent = <&tb10x_ictl>;
257 interrupts = <27 2>; 257 interrupts = <27 2>;
258 reg = <0xFF146000 0x1000>; 258 reg = <0xff146000 0x1000>;
259 gpio-controller; 259 gpio-controller;
260 #gpio-cells = <2>; 260 #gpio-cells = <2>;
261 abilis,ngpio = <3>; 261 abilis,ngpio = <3>;
262 gpio-ranges = <&iomux 0 0 0>; 262 gpio-ranges = <&iomux 0 0 0>;
263 gpio-ranges-group-names = "gpiog"; 263 gpio-ranges-group-names = "gpiog";
264 }; 264 };
265 gpioh: gpio@FF147000 { 265 gpioh: gpio@ff147000 {
266 compatible = "abilis,tb10x-gpio"; 266 compatible = "abilis,tb10x-gpio";
267 interrupt-controller; 267 interrupt-controller;
268 #interrupt-cells = <1>; 268 #interrupt-cells = <1>;
269 interrupt-parent = <&tb10x_ictl>; 269 interrupt-parent = <&tb10x_ictl>;
270 interrupts = <27 2>; 270 interrupts = <27 2>;
271 reg = <0xFF147000 0x1000>; 271 reg = <0xff147000 0x1000>;
272 gpio-controller; 272 gpio-controller;
273 #gpio-cells = <2>; 273 #gpio-cells = <2>;
274 abilis,ngpio = <2>; 274 abilis,ngpio = <2>;
275 gpio-ranges = <&iomux 0 0 0>; 275 gpio-ranges = <&iomux 0 0 0>;
276 gpio-ranges-group-names = "gpioh"; 276 gpio-ranges-group-names = "gpioh";
277 }; 277 };
278 gpioi: gpio@FF148000 { 278 gpioi: gpio@ff148000 {
279 compatible = "abilis,tb10x-gpio"; 279 compatible = "abilis,tb10x-gpio";
280 interrupt-controller; 280 interrupt-controller;
281 #interrupt-cells = <1>; 281 #interrupt-cells = <1>;
282 interrupt-parent = <&tb10x_ictl>; 282 interrupt-parent = <&tb10x_ictl>;
283 interrupts = <27 2>; 283 interrupts = <27 2>;
284 reg = <0xFF148000 0x1000>; 284 reg = <0xff148000 0x1000>;
285 gpio-controller; 285 gpio-controller;
286 #gpio-cells = <2>; 286 #gpio-cells = <2>;
287 abilis,ngpio = <12>; 287 abilis,ngpio = <12>;
288 gpio-ranges = <&iomux 0 0 0>; 288 gpio-ranges = <&iomux 0 0 0>;
289 gpio-ranges-group-names = "gpioi"; 289 gpio-ranges-group-names = "gpioi";
290 }; 290 };
291 gpioj: gpio@FF149000 { 291 gpioj: gpio@ff149000 {
292 compatible = "abilis,tb10x-gpio"; 292 compatible = "abilis,tb10x-gpio";
293 interrupt-controller; 293 interrupt-controller;
294 #interrupt-cells = <1>; 294 #interrupt-cells = <1>;
295 interrupt-parent = <&tb10x_ictl>; 295 interrupt-parent = <&tb10x_ictl>;
296 interrupts = <27 2>; 296 interrupts = <27 2>;
297 reg = <0xFF149000 0x1000>; 297 reg = <0xff149000 0x1000>;
298 gpio-controller; 298 gpio-controller;
299 #gpio-cells = <2>; 299 #gpio-cells = <2>;
300 abilis,ngpio = <32>; 300 abilis,ngpio = <32>;
301 gpio-ranges = <&iomux 0 0 0>; 301 gpio-ranges = <&iomux 0 0 0>;
302 gpio-ranges-group-names = "gpioj"; 302 gpio-ranges-group-names = "gpioj";
303 }; 303 };
304 gpiok: gpio@FF14a000 { 304 gpiok: gpio@ff14a000 {
305 compatible = "abilis,tb10x-gpio"; 305 compatible = "abilis,tb10x-gpio";
306 interrupt-controller; 306 interrupt-controller;
307 #interrupt-cells = <1>; 307 #interrupt-cells = <1>;
308 interrupt-parent = <&tb10x_ictl>; 308 interrupt-parent = <&tb10x_ictl>;
309 interrupts = <27 2>; 309 interrupts = <27 2>;
310 reg = <0xFF14A000 0x1000>; 310 reg = <0xff14a000 0x1000>;
311 gpio-controller; 311 gpio-controller;
312 #gpio-cells = <2>; 312 #gpio-cells = <2>;
313 abilis,ngpio = <22>; 313 abilis,ngpio = <22>;
314 gpio-ranges = <&iomux 0 0 0>; 314 gpio-ranges = <&iomux 0 0 0>;
315 gpio-ranges-group-names = "gpiok"; 315 gpio-ranges-group-names = "gpiok";
316 }; 316 };
317 gpiol: gpio@FF14b000 { 317 gpiol: gpio@ff14b000 {
318 compatible = "abilis,tb10x-gpio"; 318 compatible = "abilis,tb10x-gpio";
319 interrupt-controller; 319 interrupt-controller;
320 #interrupt-cells = <1>; 320 #interrupt-cells = <1>;
321 interrupt-parent = <&tb10x_ictl>; 321 interrupt-parent = <&tb10x_ictl>;
322 interrupts = <27 2>; 322 interrupts = <27 2>;
323 reg = <0xFF14B000 0x1000>; 323 reg = <0xff14b000 0x1000>;
324 gpio-controller; 324 gpio-controller;
325 #gpio-cells = <2>; 325 #gpio-cells = <2>;
326 abilis,ngpio = <4>; 326 abilis,ngpio = <4>;
327 gpio-ranges = <&iomux 0 0 0>; 327 gpio-ranges = <&iomux 0 0 0>;
328 gpio-ranges-group-names = "gpiol"; 328 gpio-ranges-group-names = "gpiol";
329 }; 329 };
330 gpiom: gpio@FF14c000 { 330 gpiom: gpio@ff14c000 {
331 compatible = "abilis,tb10x-gpio"; 331 compatible = "abilis,tb10x-gpio";
332 interrupt-controller; 332 interrupt-controller;
333 #interrupt-cells = <1>; 333 #interrupt-cells = <1>;
334 interrupt-parent = <&tb10x_ictl>; 334 interrupt-parent = <&tb10x_ictl>;
335 interrupts = <27 2>; 335 interrupts = <27 2>;
336 reg = <0xFF14C000 0x1000>; 336 reg = <0xff14c000 0x1000>;
337 gpio-controller; 337 gpio-controller;
338 #gpio-cells = <2>; 338 #gpio-cells = <2>;
339 abilis,ngpio = <4>; 339 abilis,ngpio = <4>;
340 gpio-ranges = <&iomux 0 0 0>; 340 gpio-ranges = <&iomux 0 0 0>;
341 gpio-ranges-group-names = "gpiom"; 341 gpio-ranges-group-names = "gpiom";
342 }; 342 };
343 gpion: gpio@FF14d000 { 343 gpion: gpio@ff14d000 {
344 compatible = "abilis,tb10x-gpio"; 344 compatible = "abilis,tb10x-gpio";
345 interrupt-controller; 345 interrupt-controller;
346 #interrupt-cells = <1>; 346 #interrupt-cells = <1>;
347 interrupt-parent = <&tb10x_ictl>; 347 interrupt-parent = <&tb10x_ictl>;
348 interrupts = <27 2>; 348 interrupts = <27 2>;
349 reg = <0xFF14D000 0x1000>; 349 reg = <0xff14d000 0x1000>;
350 gpio-controller; 350 gpio-controller;
351 #gpio-cells = <2>; 351 #gpio-cells = <2>;
352 abilis,ngpio = <5>; 352 abilis,ngpio = <5>;
diff --git a/arch/arc/boot/dts/abilis_tb101_dvk.dts b/arch/arc/boot/dts/abilis_tb101_dvk.dts
index 37d88c5dd181..05143ce9c120 100644
--- a/arch/arc/boot/dts/abilis_tb101_dvk.dts
+++ b/arch/arc/boot/dts/abilis_tb101_dvk.dts
@@ -37,27 +37,27 @@
37 }; 37 };
38 38
39 soc100 { 39 soc100 {
40 uart@FF100000 { 40 uart@ff100000 {
41 pinctrl-names = "default"; 41 pinctrl-names = "default";
42 pinctrl-0 = <&pctl_uart0>; 42 pinctrl-0 = <&pctl_uart0>;
43 }; 43 };
44 ethernet@FE100000 { 44 ethernet@fe100000 {
45 phy-mode = "rgmii"; 45 phy-mode = "rgmii";
46 }; 46 };
47 47
48 i2c0: i2c@FF120000 { 48 i2c0: i2c@ff120000 {
49 i2c-sda-hold-time-ns = <432>; 49 i2c-sda-hold-time-ns = <432>;
50 }; 50 };
51 i2c1: i2c@FF121000 { 51 i2c1: i2c@ff121000 {
52 i2c-sda-hold-time-ns = <432>; 52 i2c-sda-hold-time-ns = <432>;
53 }; 53 };
54 i2c2: i2c@FF122000 { 54 i2c2: i2c@ff122000 {
55 i2c-sda-hold-time-ns = <432>; 55 i2c-sda-hold-time-ns = <432>;
56 }; 56 };
57 i2c3: i2c@FF123000 { 57 i2c3: i2c@ff123000 {
58 i2c-sda-hold-time-ns = <432>; 58 i2c-sda-hold-time-ns = <432>;
59 }; 59 };
60 i2c4: i2c@FF124000 { 60 i2c4: i2c@ff124000 {
61 i2c-sda-hold-time-ns = <432>; 61 i2c-sda-hold-time-ns = <432>;
62 }; 62 };
63 63
diff --git a/arch/arc/boot/dts/abilis_tb10x.dtsi b/arch/arc/boot/dts/abilis_tb10x.dtsi
index 3121536b25a3..2fbf1bdfe6de 100644
--- a/arch/arc/boot/dts/abilis_tb10x.dtsi
+++ b/arch/arc/boot/dts/abilis_tb10x.dtsi
@@ -54,7 +54,7 @@
54 #size-cells = <1>; 54 #size-cells = <1>;
55 device_type = "soc"; 55 device_type = "soc";
56 ranges = <0xfe000000 0xfe000000 0x02000000 56 ranges = <0xfe000000 0xfe000000 0x02000000
57 0x000F0000 0x000F0000 0x00010000>; 57 0x000f0000 0x000f0000 0x00010000>;
58 compatible = "abilis,tb10x", "simple-bus"; 58 compatible = "abilis,tb10x", "simple-bus";
59 59
60 pll0: oscillator { 60 pll0: oscillator {
@@ -75,10 +75,10 @@
75 clock-output-names = "ahb_clk"; 75 clock-output-names = "ahb_clk";
76 }; 76 };
77 77
78 iomux: iomux@FF10601c { 78 iomux: iomux@ff10601c {
79 compatible = "abilis,tb10x-iomux"; 79 compatible = "abilis,tb10x-iomux";
80 #gpio-range-cells = <3>; 80 #gpio-range-cells = <3>;
81 reg = <0xFF10601c 0x4>; 81 reg = <0xff10601c 0x4>;
82 }; 82 };
83 83
84 intc: interrupt-controller { 84 intc: interrupt-controller {
@@ -88,7 +88,7 @@
88 }; 88 };
89 tb10x_ictl: pic@fe002000 { 89 tb10x_ictl: pic@fe002000 {
90 compatible = "abilis,tb10x-ictl"; 90 compatible = "abilis,tb10x-ictl";
91 reg = <0xFE002000 0x20>; 91 reg = <0xfe002000 0x20>;
92 interrupt-controller; 92 interrupt-controller;
93 #interrupt-cells = <2>; 93 #interrupt-cells = <2>;
94 interrupt-parent = <&intc>; 94 interrupt-parent = <&intc>;
@@ -96,27 +96,27 @@
96 20 21 22 23 24 25 26 27 28 29 30 31>; 96 20 21 22 23 24 25 26 27 28 29 30 31>;
97 }; 97 };
98 98
99 uart@FF100000 { 99 uart@ff100000 {
100 compatible = "snps,dw-apb-uart"; 100 compatible = "snps,dw-apb-uart";
101 reg = <0xFF100000 0x100>; 101 reg = <0xff100000 0x100>;
102 clock-frequency = <166666666>; 102 clock-frequency = <166666666>;
103 interrupts = <25 8>; 103 interrupts = <25 8>;
104 reg-shift = <2>; 104 reg-shift = <2>;
105 reg-io-width = <4>; 105 reg-io-width = <4>;
106 interrupt-parent = <&tb10x_ictl>; 106 interrupt-parent = <&tb10x_ictl>;
107 }; 107 };
108 ethernet@FE100000 { 108 ethernet@fe100000 {
109 compatible = "snps,dwmac-3.70a","snps,dwmac"; 109 compatible = "snps,dwmac-3.70a","snps,dwmac";
110 reg = <0xFE100000 0x1058>; 110 reg = <0xfe100000 0x1058>;
111 interrupt-parent = <&tb10x_ictl>; 111 interrupt-parent = <&tb10x_ictl>;
112 interrupts = <6 8>; 112 interrupts = <6 8>;
113 interrupt-names = "macirq"; 113 interrupt-names = "macirq";
114 clocks = <&ahb_clk>; 114 clocks = <&ahb_clk>;
115 clock-names = "stmmaceth"; 115 clock-names = "stmmaceth";
116 }; 116 };
117 dma@FE000000 { 117 dma@fe000000 {
118 compatible = "snps,dma-spear1340"; 118 compatible = "snps,dma-spear1340";
119 reg = <0xFE000000 0x400>; 119 reg = <0xfe000000 0x400>;
120 interrupt-parent = <&tb10x_ictl>; 120 interrupt-parent = <&tb10x_ictl>;
121 interrupts = <14 8>; 121 interrupts = <14 8>;
122 dma-channels = <6>; 122 dma-channels = <6>;
@@ -132,70 +132,70 @@
132 multi-block = <1 1 1 1 1 1>; 132 multi-block = <1 1 1 1 1 1>;
133 }; 133 };
134 134
135 i2c0: i2c@FF120000 { 135 i2c0: i2c@ff120000 {
136 #address-cells = <1>; 136 #address-cells = <1>;
137 #size-cells = <0>; 137 #size-cells = <0>;
138 compatible = "snps,designware-i2c"; 138 compatible = "snps,designware-i2c";
139 reg = <0xFF120000 0x1000>; 139 reg = <0xff120000 0x1000>;
140 interrupt-parent = <&tb10x_ictl>; 140 interrupt-parent = <&tb10x_ictl>;
141 interrupts = <12 8>; 141 interrupts = <12 8>;
142 clocks = <&ahb_clk>; 142 clocks = <&ahb_clk>;
143 }; 143 };
144 i2c1: i2c@FF121000 { 144 i2c1: i2c@ff121000 {
145 #address-cells = <1>; 145 #address-cells = <1>;
146 #size-cells = <0>; 146 #size-cells = <0>;
147 compatible = "snps,designware-i2c"; 147 compatible = "snps,designware-i2c";
148 reg = <0xFF121000 0x1000>; 148 reg = <0xff121000 0x1000>;
149 interrupt-parent = <&tb10x_ictl>; 149 interrupt-parent = <&tb10x_ictl>;
150 interrupts = <12 8>; 150 interrupts = <12 8>;
151 clocks = <&ahb_clk>; 151 clocks = <&ahb_clk>;
152 }; 152 };
153 i2c2: i2c@FF122000 { 153 i2c2: i2c@ff122000 {
154 #address-cells = <1>; 154 #address-cells = <1>;
155 #size-cells = <0>; 155 #size-cells = <0>;
156 compatible = "snps,designware-i2c"; 156 compatible = "snps,designware-i2c";
157 reg = <0xFF122000 0x1000>; 157 reg = <0xff122000 0x1000>;
158 interrupt-parent = <&tb10x_ictl>; 158 interrupt-parent = <&tb10x_ictl>;
159 interrupts = <12 8>; 159 interrupts = <12 8>;
160 clocks = <&ahb_clk>; 160 clocks = <&ahb_clk>;
161 }; 161 };
162 i2c3: i2c@FF123000 { 162 i2c3: i2c@ff123000 {
163 #address-cells = <1>; 163 #address-cells = <1>;
164 #size-cells = <0>; 164 #size-cells = <0>;
165 compatible = "snps,designware-i2c"; 165 compatible = "snps,designware-i2c";
166 reg = <0xFF123000 0x1000>; 166 reg = <0xff123000 0x1000>;
167 interrupt-parent = <&tb10x_ictl>; 167 interrupt-parent = <&tb10x_ictl>;
168 interrupts = <12 8>; 168 interrupts = <12 8>;
169 clocks = <&ahb_clk>; 169 clocks = <&ahb_clk>;
170 }; 170 };
171 i2c4: i2c@FF124000 { 171 i2c4: i2c@ff124000 {
172 #address-cells = <1>; 172 #address-cells = <1>;
173 #size-cells = <0>; 173 #size-cells = <0>;
174 compatible = "snps,designware-i2c"; 174 compatible = "snps,designware-i2c";
175 reg = <0xFF124000 0x1000>; 175 reg = <0xff124000 0x1000>;
176 interrupt-parent = <&tb10x_ictl>; 176 interrupt-parent = <&tb10x_ictl>;
177 interrupts = <12 8>; 177 interrupts = <12 8>;
178 clocks = <&ahb_clk>; 178 clocks = <&ahb_clk>;
179 }; 179 };
180 180
181 spi0: spi@0xFE010000 { 181 spi0: spi@fe010000 {
182 #address-cells = <1>; 182 #address-cells = <1>;
183 #size-cells = <0>; 183 #size-cells = <0>;
184 cell-index = <0>; 184 cell-index = <0>;
185 compatible = "abilis,tb100-spi"; 185 compatible = "abilis,tb100-spi";
186 num-cs = <1>; 186 num-cs = <1>;
187 reg = <0xFE010000 0x20>; 187 reg = <0xfe010000 0x20>;
188 interrupt-parent = <&tb10x_ictl>; 188 interrupt-parent = <&tb10x_ictl>;
189 interrupts = <26 8>; 189 interrupts = <26 8>;
190 clocks = <&ahb_clk>; 190 clocks = <&ahb_clk>;
191 }; 191 };
192 spi1: spi@0xFE011000 { 192 spi1: spi@fe011000 {
193 #address-cells = <1>; 193 #address-cells = <1>;
194 #size-cells = <0>; 194 #size-cells = <0>;
195 cell-index = <1>; 195 cell-index = <1>;
196 compatible = "abilis,tb100-spi"; 196 compatible = "abilis,tb100-spi";
197 num-cs = <2>; 197 num-cs = <2>;
198 reg = <0xFE011000 0x20>; 198 reg = <0xfe011000 0x20>;
199 interrupt-parent = <&tb10x_ictl>; 199 interrupt-parent = <&tb10x_ictl>;
200 interrupts = <10 8>; 200 interrupts = <10 8>;
201 clocks = <&ahb_clk>; 201 clocks = <&ahb_clk>;
@@ -226,23 +226,23 @@
226 interrupts = <20 2>, <19 2>; 226 interrupts = <20 2>, <19 2>;
227 interrupt-names = "cmd_irq", "event_irq"; 227 interrupt-names = "cmd_irq", "event_irq";
228 }; 228 };
229 tb10x_mdsc0: tb10x-mdscr@FF300000 { 229 tb10x_mdsc0: tb10x-mdscr@ff300000 {
230 compatible = "abilis,tb100-mdscr"; 230 compatible = "abilis,tb100-mdscr";
231 reg = <0xFF300000 0x7000>; 231 reg = <0xff300000 0x7000>;
232 tb100-mdscr-manage-tsin; 232 tb100-mdscr-manage-tsin;
233 }; 233 };
234 tb10x_mscr0: tb10x-mdscr@FF307000 { 234 tb10x_mscr0: tb10x-mdscr@ff307000 {
235 compatible = "abilis,tb100-mdscr"; 235 compatible = "abilis,tb100-mdscr";
236 reg = <0xFF307000 0x7000>; 236 reg = <0xff307000 0x7000>;
237 }; 237 };
238 tb10x_scr0: tb10x-mdscr@ff30e000 { 238 tb10x_scr0: tb10x-mdscr@ff30e000 {
239 compatible = "abilis,tb100-mdscr"; 239 compatible = "abilis,tb100-mdscr";
240 reg = <0xFF30e000 0x4000>; 240 reg = <0xff30e000 0x4000>;
241 tb100-mdscr-manage-tsin; 241 tb100-mdscr-manage-tsin;
242 }; 242 };
243 tb10x_scr1: tb10x-mdscr@ff312000 { 243 tb10x_scr1: tb10x-mdscr@ff312000 {
244 compatible = "abilis,tb100-mdscr"; 244 compatible = "abilis,tb100-mdscr";
245 reg = <0xFF312000 0x4000>; 245 reg = <0xff312000 0x4000>;
246 tb100-mdscr-manage-tsin; 246 tb100-mdscr-manage-tsin;
247 }; 247 };
248 tb10x_wfb: tb10x-wfb@ff319000 { 248 tb10x_wfb: tb10x-wfb@ff319000 {
diff --git a/arch/arc/boot/dts/axc001.dtsi b/arch/arc/boot/dts/axc001.dtsi
index fdc266504ada..37be3bf03ad6 100644
--- a/arch/arc/boot/dts/axc001.dtsi
+++ b/arch/arc/boot/dts/axc001.dtsi
@@ -41,7 +41,7 @@
41 * this GPIO block ORs all interrupts on CPU card (creg,..) 41 * this GPIO block ORs all interrupts on CPU card (creg,..)
42 * to uplink only 1 IRQ to ARC core intc 42 * to uplink only 1 IRQ to ARC core intc
43 */ 43 */
44 dw-apb-gpio@0x2000 { 44 dw-apb-gpio@2000 {
45 compatible = "snps,dw-apb-gpio"; 45 compatible = "snps,dw-apb-gpio";
46 reg = < 0x2000 0x80 >; 46 reg = < 0x2000 0x80 >;
47 #address-cells = <1>; 47 #address-cells = <1>;
@@ -60,7 +60,7 @@
60 }; 60 };
61 }; 61 };
62 62
63 debug_uart: dw-apb-uart@0x5000 { 63 debug_uart: dw-apb-uart@5000 {
64 compatible = "snps,dw-apb-uart"; 64 compatible = "snps,dw-apb-uart";
65 reg = <0x5000 0x100>; 65 reg = <0x5000 0x100>;
66 clock-frequency = <33333000>; 66 clock-frequency = <33333000>;
@@ -88,7 +88,7 @@
88 * avoid duplicating the MB dtsi file given that IRQ from 88 * avoid duplicating the MB dtsi file given that IRQ from
89 * this intc to cpu intc are different for axs101 and axs103 89 * this intc to cpu intc are different for axs101 and axs103
90 */ 90 */
91 mb_intc: dw-apb-ictl@0xe0012000 { 91 mb_intc: dw-apb-ictl@e0012000 {
92 #interrupt-cells = <1>; 92 #interrupt-cells = <1>;
93 compatible = "snps,dw-apb-ictl"; 93 compatible = "snps,dw-apb-ictl";
94 reg = < 0x0 0xe0012000 0x0 0x200 >; 94 reg = < 0x0 0xe0012000 0x0 0x200 >;
diff --git a/arch/arc/boot/dts/axc003.dtsi b/arch/arc/boot/dts/axc003.dtsi
index d75d65ddf8e3..effa37536d7a 100644
--- a/arch/arc/boot/dts/axc003.dtsi
+++ b/arch/arc/boot/dts/axc003.dtsi
@@ -55,7 +55,7 @@
55 * this GPIO block ORs all interrupts on CPU card (creg,..) 55 * this GPIO block ORs all interrupts on CPU card (creg,..)
56 * to uplink only 1 IRQ to ARC core intc 56 * to uplink only 1 IRQ to ARC core intc
57 */ 57 */
58 dw-apb-gpio@0x2000 { 58 dw-apb-gpio@2000 {
59 compatible = "snps,dw-apb-gpio"; 59 compatible = "snps,dw-apb-gpio";
60 reg = < 0x2000 0x80 >; 60 reg = < 0x2000 0x80 >;
61 #address-cells = <1>; 61 #address-cells = <1>;
@@ -74,7 +74,7 @@
74 }; 74 };
75 }; 75 };
76 76
77 debug_uart: dw-apb-uart@0x5000 { 77 debug_uart: dw-apb-uart@5000 {
78 compatible = "snps,dw-apb-uart"; 78 compatible = "snps,dw-apb-uart";
79 reg = <0x5000 0x100>; 79 reg = <0x5000 0x100>;
80 clock-frequency = <33333000>; 80 clock-frequency = <33333000>;
@@ -102,19 +102,19 @@
102 * external DMA buffer located outside of IOC aperture. 102 * external DMA buffer located outside of IOC aperture.
103 */ 103 */
104 axs10x_mb { 104 axs10x_mb {
105 ethernet@0x18000 { 105 ethernet@18000 {
106 dma-coherent; 106 dma-coherent;
107 }; 107 };
108 108
109 ehci@0x40000 { 109 ehci@40000 {
110 dma-coherent; 110 dma-coherent;
111 }; 111 };
112 112
113 ohci@0x60000 { 113 ohci@60000 {
114 dma-coherent; 114 dma-coherent;
115 }; 115 };
116 116
117 mmc@0x15000 { 117 mmc@15000 {
118 dma-coherent; 118 dma-coherent;
119 }; 119 };
120 }; 120 };
@@ -132,7 +132,7 @@
132 * avoid duplicating the MB dtsi file given that IRQ from 132 * avoid duplicating the MB dtsi file given that IRQ from
133 * this intc to cpu intc are different for axs101 and axs103 133 * this intc to cpu intc are different for axs101 and axs103
134 */ 134 */
135 mb_intc: dw-apb-ictl@0xe0012000 { 135 mb_intc: dw-apb-ictl@e0012000 {
136 #interrupt-cells = <1>; 136 #interrupt-cells = <1>;
137 compatible = "snps,dw-apb-ictl"; 137 compatible = "snps,dw-apb-ictl";
138 reg = < 0x0 0xe0012000 0x0 0x200 >; 138 reg = < 0x0 0xe0012000 0x0 0x200 >;
@@ -153,7 +153,7 @@
153 #size-cells = <2>; 153 #size-cells = <2>;
154 ranges; 154 ranges;
155 /* 155 /*
156 * Move frame buffer out of IOC aperture (0x8z-0xAz). 156 * Move frame buffer out of IOC aperture (0x8z-0xaz).
157 */ 157 */
158 frame_buffer: frame_buffer@be000000 { 158 frame_buffer: frame_buffer@be000000 {
159 compatible = "shared-dma-pool"; 159 compatible = "shared-dma-pool";
diff --git a/arch/arc/boot/dts/axc003_idu.dtsi b/arch/arc/boot/dts/axc003_idu.dtsi
index a05bb737ea63..e401e59f6180 100644
--- a/arch/arc/boot/dts/axc003_idu.dtsi
+++ b/arch/arc/boot/dts/axc003_idu.dtsi
@@ -62,7 +62,7 @@
62 * this GPIO block ORs all interrupts on CPU card (creg,..) 62 * this GPIO block ORs all interrupts on CPU card (creg,..)
63 * to uplink only 1 IRQ to ARC core intc 63 * to uplink only 1 IRQ to ARC core intc
64 */ 64 */
65 dw-apb-gpio@0x2000 { 65 dw-apb-gpio@2000 {
66 compatible = "snps,dw-apb-gpio"; 66 compatible = "snps,dw-apb-gpio";
67 reg = < 0x2000 0x80 >; 67 reg = < 0x2000 0x80 >;
68 #address-cells = <1>; 68 #address-cells = <1>;
@@ -81,7 +81,7 @@
81 }; 81 };
82 }; 82 };
83 83
84 debug_uart: dw-apb-uart@0x5000 { 84 debug_uart: dw-apb-uart@5000 {
85 compatible = "snps,dw-apb-uart"; 85 compatible = "snps,dw-apb-uart";
86 reg = <0x5000 0x100>; 86 reg = <0x5000 0x100>;
87 clock-frequency = <33333000>; 87 clock-frequency = <33333000>;
@@ -109,19 +109,19 @@
109 * external DMA buffer located outside of IOC aperture. 109 * external DMA buffer located outside of IOC aperture.
110 */ 110 */
111 axs10x_mb { 111 axs10x_mb {
112 ethernet@0x18000 { 112 ethernet@18000 {
113 dma-coherent; 113 dma-coherent;
114 }; 114 };
115 115
116 ehci@0x40000 { 116 ehci@40000 {
117 dma-coherent; 117 dma-coherent;
118 }; 118 };
119 119
120 ohci@0x60000 { 120 ohci@60000 {
121 dma-coherent; 121 dma-coherent;
122 }; 122 };
123 123
124 mmc@0x15000 { 124 mmc@15000 {
125 dma-coherent; 125 dma-coherent;
126 }; 126 };
127 }; 127 };
@@ -138,7 +138,7 @@
138 * avoid duplicating the MB dtsi file given that IRQ from 138 * avoid duplicating the MB dtsi file given that IRQ from
139 * this intc to cpu intc are different for axs101 and axs103 139 * this intc to cpu intc are different for axs101 and axs103
140 */ 140 */
141 mb_intc: dw-apb-ictl@0xe0012000 { 141 mb_intc: dw-apb-ictl@e0012000 {
142 #interrupt-cells = <1>; 142 #interrupt-cells = <1>;
143 compatible = "snps,dw-apb-ictl"; 143 compatible = "snps,dw-apb-ictl";
144 reg = < 0x0 0xe0012000 0x0 0x200 >; 144 reg = < 0x0 0xe0012000 0x0 0x200 >;
@@ -159,7 +159,7 @@
159 #size-cells = <2>; 159 #size-cells = <2>;
160 ranges; 160 ranges;
161 /* 161 /*
162 * Move frame buffer out of IOC aperture (0x8z-0xAz). 162 * Move frame buffer out of IOC aperture (0x8z-0xaz).
163 */ 163 */
164 frame_buffer: frame_buffer@be000000 { 164 frame_buffer: frame_buffer@be000000 {
165 compatible = "shared-dma-pool"; 165 compatible = "shared-dma-pool";
diff --git a/arch/arc/boot/dts/axs10x_mb.dtsi b/arch/arc/boot/dts/axs10x_mb.dtsi
index 37bafd44e36d..4ead6dc9af2f 100644
--- a/arch/arc/boot/dts/axs10x_mb.dtsi
+++ b/arch/arc/boot/dts/axs10x_mb.dtsi
@@ -72,7 +72,7 @@
72 }; 72 };
73 }; 73 };
74 74
75 gmac: ethernet@0x18000 { 75 gmac: ethernet@18000 {
76 #interrupt-cells = <1>; 76 #interrupt-cells = <1>;
77 compatible = "snps,dwmac"; 77 compatible = "snps,dwmac";
78 reg = < 0x18000 0x2000 >; 78 reg = < 0x18000 0x2000 >;
@@ -88,13 +88,13 @@
88 mac-address = [00 00 00 00 00 00]; /* Filled in by U-Boot */ 88 mac-address = [00 00 00 00 00 00]; /* Filled in by U-Boot */
89 }; 89 };
90 90
91 ehci@0x40000 { 91 ehci@40000 {
92 compatible = "generic-ehci"; 92 compatible = "generic-ehci";
93 reg = < 0x40000 0x100 >; 93 reg = < 0x40000 0x100 >;
94 interrupts = < 8 >; 94 interrupts = < 8 >;
95 }; 95 };
96 96
97 ohci@0x60000 { 97 ohci@60000 {
98 compatible = "generic-ohci"; 98 compatible = "generic-ohci";
99 reg = < 0x60000 0x100 >; 99 reg = < 0x60000 0x100 >;
100 interrupts = < 8 >; 100 interrupts = < 8 >;
@@ -118,7 +118,7 @@
118 * dw_mci_pltfm_prepare_command() is used in generic platform 118 * dw_mci_pltfm_prepare_command() is used in generic platform
119 * code. 119 * code.
120 */ 120 */
121 mmc@0x15000 { 121 mmc@15000 {
122 compatible = "altr,socfpga-dw-mshc"; 122 compatible = "altr,socfpga-dw-mshc";
123 reg = < 0x15000 0x400 >; 123 reg = < 0x15000 0x400 >;
124 fifo-depth = < 16 >; 124 fifo-depth = < 16 >;
@@ -129,7 +129,7 @@
129 bus-width = < 4 >; 129 bus-width = < 4 >;
130 }; 130 };
131 131
132 uart@0x20000 { 132 uart@20000 {
133 compatible = "snps,dw-apb-uart"; 133 compatible = "snps,dw-apb-uart";
134 reg = <0x20000 0x100>; 134 reg = <0x20000 0x100>;
135 clock-frequency = <33333333>; 135 clock-frequency = <33333333>;
@@ -139,7 +139,7 @@
139 reg-io-width = <4>; 139 reg-io-width = <4>;
140 }; 140 };
141 141
142 uart@0x21000 { 142 uart@21000 {
143 compatible = "snps,dw-apb-uart"; 143 compatible = "snps,dw-apb-uart";
144 reg = <0x21000 0x100>; 144 reg = <0x21000 0x100>;
145 clock-frequency = <33333333>; 145 clock-frequency = <33333333>;
@@ -150,7 +150,7 @@
150 }; 150 };
151 151
152 /* UART muxed with USB data port (ttyS3) */ 152 /* UART muxed with USB data port (ttyS3) */
153 uart@0x22000 { 153 uart@22000 {
154 compatible = "snps,dw-apb-uart"; 154 compatible = "snps,dw-apb-uart";
155 reg = <0x22000 0x100>; 155 reg = <0x22000 0x100>;
156 clock-frequency = <33333333>; 156 clock-frequency = <33333333>;
@@ -160,7 +160,7 @@
160 reg-io-width = <4>; 160 reg-io-width = <4>;
161 }; 161 };
162 162
163 i2c@0x1d000 { 163 i2c@1d000 {
164 compatible = "snps,designware-i2c"; 164 compatible = "snps,designware-i2c";
165 reg = <0x1d000 0x100>; 165 reg = <0x1d000 0x100>;
166 clock-frequency = <400000>; 166 clock-frequency = <400000>;
@@ -177,7 +177,7 @@
177 #sound-dai-cells = <0>; 177 #sound-dai-cells = <0>;
178 }; 178 };
179 179
180 i2c@0x1f000 { 180 i2c@1f000 {
181 compatible = "snps,designware-i2c"; 181 compatible = "snps,designware-i2c";
182 #address-cells = <1>; 182 #address-cells = <1>;
183 #size-cells = <0>; 183 #size-cells = <0>;
@@ -218,13 +218,13 @@
218 }; 218 };
219 }; 219 };
220 220
221 eeprom@0x54{ 221 eeprom@54{
222 compatible = "atmel,24c01"; 222 compatible = "atmel,24c01";
223 reg = <0x54>; 223 reg = <0x54>;
224 pagesize = <0x8>; 224 pagesize = <0x8>;
225 }; 225 };
226 226
227 eeprom@0x57{ 227 eeprom@57{
228 compatible = "atmel,24c04"; 228 compatible = "atmel,24c04";
229 reg = <0x57>; 229 reg = <0x57>;
230 pagesize = <0x8>; 230 pagesize = <0x8>;
diff --git a/arch/arc/boot/dts/hsdk.dts b/arch/arc/boot/dts/hsdk.dts
index 43f17b51ee89..69bc1c9e8e50 100644
--- a/arch/arc/boot/dts/hsdk.dts
+++ b/arch/arc/boot/dts/hsdk.dts
@@ -110,12 +110,12 @@
110 cgu_rst: reset-controller@8a0 { 110 cgu_rst: reset-controller@8a0 {
111 compatible = "snps,hsdk-reset"; 111 compatible = "snps,hsdk-reset";
112 #reset-cells = <1>; 112 #reset-cells = <1>;
113 reg = <0x8A0 0x4>, <0xFF0 0x4>; 113 reg = <0x8a0 0x4>, <0xff0 0x4>;
114 }; 114 };
115 115
116 core_clk: core-clk@0 { 116 core_clk: core-clk@0 {
117 compatible = "snps,hsdk-core-pll-clock"; 117 compatible = "snps,hsdk-core-pll-clock";
118 reg = <0x00 0x10>, <0x14B8 0x4>; 118 reg = <0x00 0x10>, <0x14b8 0x4>;
119 #clock-cells = <0>; 119 #clock-cells = <0>;
120 clocks = <&input_clk>; 120 clocks = <&input_clk>;
121 121
@@ -167,6 +167,18 @@
167 #clock-cells = <0>; 167 #clock-cells = <0>;
168 }; 168 };
169 169
170 dmac_core_clk: dmac-core-clk {
171 compatible = "fixed-clock";
172 clock-frequency = <400000000>;
173 #clock-cells = <0>;
174 };
175
176 dmac_cfg_clk: dmac-gpu-cfg-clk {
177 compatible = "fixed-clock";
178 clock-frequency = <200000000>;
179 #clock-cells = <0>;
180 };
181
170 gmac: ethernet@8000 { 182 gmac: ethernet@8000 {
171 #interrupt-cells = <1>; 183 #interrupt-cells = <1>;
172 compatible = "snps,dwmac"; 184 compatible = "snps,dwmac";
@@ -200,6 +212,7 @@
200 compatible = "snps,hsdk-v1.0-ohci", "generic-ohci"; 212 compatible = "snps,hsdk-v1.0-ohci", "generic-ohci";
201 reg = <0x60000 0x100>; 213 reg = <0x60000 0x100>;
202 interrupts = <15>; 214 interrupts = <15>;
215 resets = <&cgu_rst HSDK_USB_RESET>;
203 dma-coherent; 216 dma-coherent;
204 }; 217 };
205 218
@@ -207,6 +220,7 @@
207 compatible = "snps,hsdk-v1.0-ehci", "generic-ehci"; 220 compatible = "snps,hsdk-v1.0-ehci", "generic-ehci";
208 reg = <0x40000 0x100>; 221 reg = <0x40000 0x100>;
209 interrupts = <15>; 222 interrupts = <15>;
223 resets = <&cgu_rst HSDK_USB_RESET>;
210 dma-coherent; 224 dma-coherent;
211 }; 225 };
212 226
@@ -237,6 +251,21 @@
237 reg = <0>; 251 reg = <0>;
238 }; 252 };
239 }; 253 };
254
255 dmac: dmac@80000 {
256 compatible = "snps,axi-dma-1.01a";
257 reg = <0x80000 0x400>;
258 interrupts = <27>;
259 clocks = <&dmac_core_clk>, <&dmac_cfg_clk>;
260 clock-names = "core-clk", "cfgr-clk";
261
262 dma-channels = <4>;
263 snps,dma-masters = <2>;
264 snps,data-width = <3>;
265 snps,block-size = <4096 4096 4096 4096>;
266 snps,priority = <0 1 2 3>;
267 snps,axi-max-burst-len = <16>;
268 };
240 }; 269 };
241 270
242 memory@80000000 { 271 memory@80000000 {
diff --git a/arch/arc/boot/dts/vdk_axc003.dtsi b/arch/arc/boot/dts/vdk_axc003.dtsi
index 0fd6ba985b16..84e8766c8ca2 100644
--- a/arch/arc/boot/dts/vdk_axc003.dtsi
+++ b/arch/arc/boot/dts/vdk_axc003.dtsi
@@ -36,7 +36,7 @@
36 #interrupt-cells = <1>; 36 #interrupt-cells = <1>;
37 }; 37 };
38 38
39 debug_uart: dw-apb-uart@0x5000 { 39 debug_uart: dw-apb-uart@5000 {
40 compatible = "snps,dw-apb-uart"; 40 compatible = "snps,dw-apb-uart";
41 reg = <0x5000 0x100>; 41 reg = <0x5000 0x100>;
42 clock-frequency = <2403200>; 42 clock-frequency = <2403200>;
@@ -49,7 +49,7 @@
49 49
50 }; 50 };
51 51
52 mb_intc: dw-apb-ictl@0xe0012000 { 52 mb_intc: dw-apb-ictl@e0012000 {
53 #interrupt-cells = <1>; 53 #interrupt-cells = <1>;
54 compatible = "snps,dw-apb-ictl"; 54 compatible = "snps,dw-apb-ictl";
55 reg = < 0xe0012000 0x200 >; 55 reg = < 0xe0012000 0x200 >;
diff --git a/arch/arc/boot/dts/vdk_axc003_idu.dtsi b/arch/arc/boot/dts/vdk_axc003_idu.dtsi
index 28956f9a9f3d..eb7e705e8a27 100644
--- a/arch/arc/boot/dts/vdk_axc003_idu.dtsi
+++ b/arch/arc/boot/dts/vdk_axc003_idu.dtsi
@@ -44,7 +44,7 @@
44 #interrupt-cells = <1>; 44 #interrupt-cells = <1>;
45 }; 45 };
46 46
47 debug_uart: dw-apb-uart@0x5000 { 47 debug_uart: dw-apb-uart@5000 {
48 compatible = "snps,dw-apb-uart"; 48 compatible = "snps,dw-apb-uart";
49 reg = <0x5000 0x100>; 49 reg = <0x5000 0x100>;
50 clock-frequency = <2403200>; 50 clock-frequency = <2403200>;
@@ -57,7 +57,7 @@
57 57
58 }; 58 };
59 59
60 mb_intc: dw-apb-ictl@0xe0012000 { 60 mb_intc: dw-apb-ictl@e0012000 {
61 #interrupt-cells = <1>; 61 #interrupt-cells = <1>;
62 compatible = "snps,dw-apb-ictl"; 62 compatible = "snps,dw-apb-ictl";
63 reg = < 0xe0012000 0x200 >; 63 reg = < 0xe0012000 0x200 >;
diff --git a/arch/arc/boot/dts/vdk_axs10x_mb.dtsi b/arch/arc/boot/dts/vdk_axs10x_mb.dtsi
index 48bb4b4cd234..925d5cc95dbb 100644
--- a/arch/arc/boot/dts/vdk_axs10x_mb.dtsi
+++ b/arch/arc/boot/dts/vdk_axs10x_mb.dtsi
@@ -36,7 +36,7 @@
36 }; 36 };
37 }; 37 };
38 38
39 ethernet@0x18000 { 39 ethernet@18000 {
40 #interrupt-cells = <1>; 40 #interrupt-cells = <1>;
41 compatible = "snps,dwmac"; 41 compatible = "snps,dwmac";
42 reg = < 0x18000 0x2000 >; 42 reg = < 0x18000 0x2000 >;
@@ -49,13 +49,13 @@
49 clock-names = "stmmaceth"; 49 clock-names = "stmmaceth";
50 }; 50 };
51 51
52 ehci@0x40000 { 52 ehci@40000 {
53 compatible = "generic-ehci"; 53 compatible = "generic-ehci";
54 reg = < 0x40000 0x100 >; 54 reg = < 0x40000 0x100 >;
55 interrupts = < 8 >; 55 interrupts = < 8 >;
56 }; 56 };
57 57
58 uart@0x20000 { 58 uart@20000 {
59 compatible = "snps,dw-apb-uart"; 59 compatible = "snps,dw-apb-uart";
60 reg = <0x20000 0x100>; 60 reg = <0x20000 0x100>;
61 clock-frequency = <2403200>; 61 clock-frequency = <2403200>;
@@ -65,7 +65,7 @@
65 reg-io-width = <4>; 65 reg-io-width = <4>;
66 }; 66 };
67 67
68 uart@0x21000 { 68 uart@21000 {
69 compatible = "snps,dw-apb-uart"; 69 compatible = "snps,dw-apb-uart";
70 reg = <0x21000 0x100>; 70 reg = <0x21000 0x100>;
71 clock-frequency = <2403200>; 71 clock-frequency = <2403200>;
@@ -75,7 +75,7 @@
75 reg-io-width = <4>; 75 reg-io-width = <4>;
76 }; 76 };
77 77
78 uart@0x22000 { 78 uart@22000 {
79 compatible = "snps,dw-apb-uart"; 79 compatible = "snps,dw-apb-uart";
80 reg = <0x22000 0x100>; 80 reg = <0x22000 0x100>;
81 clock-frequency = <2403200>; 81 clock-frequency = <2403200>;
@@ -101,7 +101,7 @@
101 interrupt-names = "arc_ps2_irq"; 101 interrupt-names = "arc_ps2_irq";
102 }; 102 };
103 103
104 mmc@0x15000 { 104 mmc@15000 {
105 compatible = "snps,dw-mshc"; 105 compatible = "snps,dw-mshc";
106 reg = <0x15000 0x400>; 106 reg = <0x15000 0x400>;
107 fifo-depth = <1024>; 107 fifo-depth = <1024>;
@@ -117,11 +117,11 @@
117 * Embedded Vision subsystem UIO mappings; only relevant for EV VDK 117 * Embedded Vision subsystem UIO mappings; only relevant for EV VDK
118 * 118 *
119 * This node is intentionally put outside of MB above becase 119 * This node is intentionally put outside of MB above becase
120 * it maps areas outside of MB's 0xEz-0xFz. 120 * it maps areas outside of MB's 0xez-0xfz.
121 */ 121 */
122 uio_ev: uio@0xD0000000 { 122 uio_ev: uio@d0000000 {
123 compatible = "generic-uio"; 123 compatible = "generic-uio";
124 reg = <0xD0000000 0x2000 0xD1000000 0x2000 0x90000000 0x10000000 0xC0000000 0x10000000>; 124 reg = <0xd0000000 0x2000 0xd1000000 0x2000 0x90000000 0x10000000 0xc0000000 0x10000000>;
125 reg-names = "ev_gsa", "ev_ctrl", "ev_shared_mem", "ev_code_mem"; 125 reg-names = "ev_gsa", "ev_ctrl", "ev_shared_mem", "ev_code_mem";
126 interrupt-parent = <&mb_intc>; 126 interrupt-parent = <&mb_intc>;
127 interrupts = <23>; 127 interrupts = <23>;
diff --git a/arch/arc/configs/hsdk_defconfig b/arch/arc/configs/hsdk_defconfig
index 6fd3d29546af..0e5fd29ed238 100644
--- a/arch/arc/configs/hsdk_defconfig
+++ b/arch/arc/configs/hsdk_defconfig
@@ -8,6 +8,7 @@ CONFIG_NAMESPACES=y
8# CONFIG_UTS_NS is not set 8# CONFIG_UTS_NS is not set
9# CONFIG_PID_NS is not set 9# CONFIG_PID_NS is not set
10CONFIG_BLK_DEV_INITRD=y 10CONFIG_BLK_DEV_INITRD=y
11CONFIG_BLK_DEV_RAM=y
11CONFIG_EMBEDDED=y 12CONFIG_EMBEDDED=y
12CONFIG_PERF_EVENTS=y 13CONFIG_PERF_EVENTS=y
13# CONFIG_VM_EVENT_COUNTERS is not set 14# CONFIG_VM_EVENT_COUNTERS is not set
diff --git a/arch/arc/include/asm/arcregs.h b/arch/arc/include/asm/arcregs.h
index a27eafdc8260..a7d4be87b2f0 100644
--- a/arch/arc/include/asm/arcregs.h
+++ b/arch/arc/include/asm/arcregs.h
@@ -82,6 +82,7 @@
82#define ECR_V_DTLB_MISS 0x05 82#define ECR_V_DTLB_MISS 0x05
83#define ECR_V_PROTV 0x06 83#define ECR_V_PROTV 0x06
84#define ECR_V_TRAP 0x09 84#define ECR_V_TRAP 0x09
85#define ECR_V_MISALIGN 0x0d
85#endif 86#endif
86 87
87/* DTLB Miss and Protection Violation Cause Codes */ 88/* DTLB Miss and Protection Violation Cause Codes */
@@ -167,14 +168,6 @@ struct bcr_mpy {
167#endif 168#endif
168}; 169};
169 170
170struct bcr_extn_xymem {
171#ifdef CONFIG_CPU_BIG_ENDIAN
172 unsigned int ram_org:2, num_banks:4, bank_sz:4, ver:8;
173#else
174 unsigned int ver:8, bank_sz:4, num_banks:4, ram_org:2;
175#endif
176};
177
178struct bcr_iccm_arcompact { 171struct bcr_iccm_arcompact {
179#ifdef CONFIG_CPU_BIG_ENDIAN 172#ifdef CONFIG_CPU_BIG_ENDIAN
180 unsigned int base:16, pad:5, sz:3, ver:8; 173 unsigned int base:16, pad:5, sz:3, ver:8;
@@ -312,7 +305,7 @@ struct cpuinfo_arc {
312 struct cpuinfo_arc_bpu bpu; 305 struct cpuinfo_arc_bpu bpu;
313 struct bcr_identity core; 306 struct bcr_identity core;
314 struct bcr_isa_arcv2 isa; 307 struct bcr_isa_arcv2 isa;
315 const char *details, *name; 308 const char *release, *name;
316 unsigned int vec_base; 309 unsigned int vec_base;
317 struct cpuinfo_arc_ccm iccm, dccm; 310 struct cpuinfo_arc_ccm iccm, dccm;
318 struct { 311 struct {
@@ -322,7 +315,6 @@ struct cpuinfo_arc {
322 timer0:1, timer1:1, rtc:1, gfrc:1, pad4:4; 315 timer0:1, timer1:1, rtc:1, gfrc:1, pad4:4;
323 } extn; 316 } extn;
324 struct bcr_mpy extn_mpy; 317 struct bcr_mpy extn_mpy;
325 struct bcr_extn_xymem extn_xymem;
326}; 318};
327 319
328extern struct cpuinfo_arc cpuinfo_arc700[]; 320extern struct cpuinfo_arc cpuinfo_arc700[];
diff --git a/arch/arc/include/asm/irqflags-arcv2.h b/arch/arc/include/asm/irqflags-arcv2.h
index 8a4f77ea3238..e66d0339e1d8 100644
--- a/arch/arc/include/asm/irqflags-arcv2.h
+++ b/arch/arc/include/asm/irqflags-arcv2.h
@@ -44,7 +44,13 @@
44#define ARCV2_IRQ_DEF_PRIO 1 44#define ARCV2_IRQ_DEF_PRIO 1
45 45
46/* seed value for status register */ 46/* seed value for status register */
47#define ISA_INIT_STATUS_BITS (STATUS_IE_MASK | STATUS_AD_MASK | \ 47#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
48#define __AD_ENB STATUS_AD_MASK
49#else
50#define __AD_ENB 0
51#endif
52
53#define ISA_INIT_STATUS_BITS (STATUS_IE_MASK | __AD_ENB | \
48 (ARCV2_IRQ_DEF_PRIO << 1)) 54 (ARCV2_IRQ_DEF_PRIO << 1))
49 55
50#ifndef __ASSEMBLY__ 56#ifndef __ASSEMBLY__
diff --git a/arch/arc/include/asm/perf_event.h b/arch/arc/include/asm/perf_event.h
index 6958545390f0..9cd7ee4fad39 100644
--- a/arch/arc/include/asm/perf_event.h
+++ b/arch/arc/include/asm/perf_event.h
@@ -105,10 +105,10 @@ static const char * const arc_pmu_ev_hw_map[] = {
105 [PERF_COUNT_HW_INSTRUCTIONS] = "iall", 105 [PERF_COUNT_HW_INSTRUCTIONS] = "iall",
106 /* All jump instructions that are taken */ 106 /* All jump instructions that are taken */
107 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmptak", 107 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmptak",
108 [PERF_COUNT_ARC_BPOK] = "bpok", /* NP-NT, PT-T, PNT-NT */
109#ifdef CONFIG_ISA_ARCV2 108#ifdef CONFIG_ISA_ARCV2
110 [PERF_COUNT_HW_BRANCH_MISSES] = "bpmp", 109 [PERF_COUNT_HW_BRANCH_MISSES] = "bpmp",
111#else 110#else
111 [PERF_COUNT_ARC_BPOK] = "bpok", /* NP-NT, PT-T, PNT-NT */
112 [PERF_COUNT_HW_BRANCH_MISSES] = "bpfail", /* NP-T, PT-NT, PNT-T */ 112 [PERF_COUNT_HW_BRANCH_MISSES] = "bpfail", /* NP-T, PT-NT, PNT-T */
113#endif 113#endif
114 [PERF_COUNT_ARC_LDC] = "imemrdc", /* Instr: mem read cached */ 114 [PERF_COUNT_ARC_LDC] = "imemrdc", /* Instr: mem read cached */
diff --git a/arch/arc/include/asm/spinlock.h b/arch/arc/include/asm/spinlock.h
index 2ba04a7db621..daa914da7968 100644
--- a/arch/arc/include/asm/spinlock.h
+++ b/arch/arc/include/asm/spinlock.h
@@ -21,8 +21,6 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
21{ 21{
22 unsigned int val; 22 unsigned int val;
23 23
24 smp_mb();
25
26 __asm__ __volatile__( 24 __asm__ __volatile__(
27 "1: llock %[val], [%[slock]] \n" 25 "1: llock %[val], [%[slock]] \n"
28 " breq %[val], %[LOCKED], 1b \n" /* spin while LOCKED */ 26 " breq %[val], %[LOCKED], 1b \n" /* spin while LOCKED */
@@ -34,6 +32,14 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
34 [LOCKED] "r" (__ARCH_SPIN_LOCK_LOCKED__) 32 [LOCKED] "r" (__ARCH_SPIN_LOCK_LOCKED__)
35 : "memory", "cc"); 33 : "memory", "cc");
36 34
35 /*
36 * ACQUIRE barrier to ensure load/store after taking the lock
37 * don't "bleed-up" out of the critical section (leak-in is allowed)
38 * http://www.spinics.net/lists/kernel/msg2010409.html
39 *
40 * ARCv2 only has load-load, store-store and all-all barrier
41 * thus need the full all-all barrier
42 */
37 smp_mb(); 43 smp_mb();
38} 44}
39 45
@@ -42,8 +48,6 @@ static inline int arch_spin_trylock(arch_spinlock_t *lock)
42{ 48{
43 unsigned int val, got_it = 0; 49 unsigned int val, got_it = 0;
44 50
45 smp_mb();
46
47 __asm__ __volatile__( 51 __asm__ __volatile__(
48 "1: llock %[val], [%[slock]] \n" 52 "1: llock %[val], [%[slock]] \n"
49 " breq %[val], %[LOCKED], 4f \n" /* already LOCKED, just bail */ 53 " breq %[val], %[LOCKED], 4f \n" /* already LOCKED, just bail */
@@ -67,9 +71,7 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
67{ 71{
68 smp_mb(); 72 smp_mb();
69 73
70 lock->slock = __ARCH_SPIN_LOCK_UNLOCKED__; 74 WRITE_ONCE(lock->slock, __ARCH_SPIN_LOCK_UNLOCKED__);
71
72 smp_mb();
73} 75}
74 76
75/* 77/*
@@ -81,8 +83,6 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
81{ 83{
82 unsigned int val; 84 unsigned int val;
83 85
84 smp_mb();
85
86 /* 86 /*
87 * zero means writer holds the lock exclusively, deny Reader. 87 * zero means writer holds the lock exclusively, deny Reader.
88 * Otherwise grant lock to first/subseq reader 88 * Otherwise grant lock to first/subseq reader
@@ -113,8 +113,6 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
113{ 113{
114 unsigned int val, got_it = 0; 114 unsigned int val, got_it = 0;
115 115
116 smp_mb();
117
118 __asm__ __volatile__( 116 __asm__ __volatile__(
119 "1: llock %[val], [%[rwlock]] \n" 117 "1: llock %[val], [%[rwlock]] \n"
120 " brls %[val], %[WR_LOCKED], 4f\n" /* <= 0: already write locked, bail */ 118 " brls %[val], %[WR_LOCKED], 4f\n" /* <= 0: already write locked, bail */
@@ -140,8 +138,6 @@ static inline void arch_write_lock(arch_rwlock_t *rw)
140{ 138{
141 unsigned int val; 139 unsigned int val;
142 140
143 smp_mb();
144
145 /* 141 /*
146 * If reader(s) hold lock (lock < __ARCH_RW_LOCK_UNLOCKED__), 142 * If reader(s) hold lock (lock < __ARCH_RW_LOCK_UNLOCKED__),
147 * deny writer. Otherwise if unlocked grant to writer 143 * deny writer. Otherwise if unlocked grant to writer
@@ -175,8 +171,6 @@ static inline int arch_write_trylock(arch_rwlock_t *rw)
175{ 171{
176 unsigned int val, got_it = 0; 172 unsigned int val, got_it = 0;
177 173
178 smp_mb();
179
180 __asm__ __volatile__( 174 __asm__ __volatile__(
181 "1: llock %[val], [%[rwlock]] \n" 175 "1: llock %[val], [%[rwlock]] \n"
182 " brne %[val], %[UNLOCKED], 4f \n" /* !UNLOCKED, bail */ 176 " brne %[val], %[UNLOCKED], 4f \n" /* !UNLOCKED, bail */
@@ -217,17 +211,13 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
217 : [val] "=&r" (val) 211 : [val] "=&r" (val)
218 : [rwlock] "r" (&(rw->counter)) 212 : [rwlock] "r" (&(rw->counter))
219 : "memory", "cc"); 213 : "memory", "cc");
220
221 smp_mb();
222} 214}
223 215
224static inline void arch_write_unlock(arch_rwlock_t *rw) 216static inline void arch_write_unlock(arch_rwlock_t *rw)
225{ 217{
226 smp_mb(); 218 smp_mb();
227 219
228 rw->counter = __ARCH_RW_LOCK_UNLOCKED__; 220 WRITE_ONCE(rw->counter, __ARCH_RW_LOCK_UNLOCKED__);
229
230 smp_mb();
231} 221}
232 222
233#else /* !CONFIG_ARC_HAS_LLSC */ 223#else /* !CONFIG_ARC_HAS_LLSC */
@@ -237,10 +227,9 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
237 unsigned int val = __ARCH_SPIN_LOCK_LOCKED__; 227 unsigned int val = __ARCH_SPIN_LOCK_LOCKED__;
238 228
239 /* 229 /*
240 * This smp_mb() is technically superfluous, we only need the one 230 * Per lkmm, smp_mb() is only required after _lock (and before_unlock)
241 * after the lock for providing the ACQUIRE semantics. 231 * for ACQ and REL semantics respectively. However EX based spinlocks
242 * However doing the "right" thing was regressing hackbench 232 * need the extra smp_mb to workaround a hardware quirk.
243 * so keeping this, pending further investigation
244 */ 233 */
245 smp_mb(); 234 smp_mb();
246 235
@@ -257,14 +246,6 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
257#endif 246#endif
258 : "memory"); 247 : "memory");
259 248
260 /*
261 * ACQUIRE barrier to ensure load/store after taking the lock
262 * don't "bleed-up" out of the critical section (leak-in is allowed)
263 * http://www.spinics.net/lists/kernel/msg2010409.html
264 *
265 * ARCv2 only has load-load, store-store and all-all barrier
266 * thus need the full all-all barrier
267 */
268 smp_mb(); 249 smp_mb();
269} 250}
270 251
@@ -309,8 +290,7 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
309 : "memory"); 290 : "memory");
310 291
311 /* 292 /*
312 * superfluous, but keeping for now - see pairing version in 293 * see pairing version/comment in arch_spin_lock above
313 * arch_spin_lock above
314 */ 294 */
315 smp_mb(); 295 smp_mb();
316} 296}
@@ -344,7 +324,6 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
344 arch_spin_unlock(&(rw->lock_mutex)); 324 arch_spin_unlock(&(rw->lock_mutex));
345 local_irq_restore(flags); 325 local_irq_restore(flags);
346 326
347 smp_mb();
348 return ret; 327 return ret;
349} 328}
350 329
diff --git a/arch/arc/kernel/head.S b/arch/arc/kernel/head.S
index 30e090625916..8f6e0447dd17 100644
--- a/arch/arc/kernel/head.S
+++ b/arch/arc/kernel/head.S
@@ -54,7 +54,12 @@
54 ; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access 54 ; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access
55 ; by default 55 ; by default
56 lr r5, [status32] 56 lr r5, [status32]
57#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
57 bset r5, r5, STATUS_AD_BIT 58 bset r5, r5, STATUS_AD_BIT
59#else
60 ; Although disabled at reset, bootloader might have enabled it
61 bclr r5, r5, STATUS_AD_BIT
62#endif
58 kflag r5 63 kflag r5
59#endif 64#endif
60.endm 65.endm
@@ -106,6 +111,7 @@ ENTRY(stext)
106 ; r2 = pointer to uboot provided cmdline or external DTB in mem 111 ; r2 = pointer to uboot provided cmdline or external DTB in mem
107 ; These are handled later in handle_uboot_args() 112 ; These are handled later in handle_uboot_args()
108 st r0, [@uboot_tag] 113 st r0, [@uboot_tag]
114 st r1, [@uboot_magic]
109 st r2, [@uboot_arg] 115 st r2, [@uboot_arg]
110 116
111 ; setup "current" tsk and optionally cache it in dedicated r25 117 ; setup "current" tsk and optionally cache it in dedicated r25
diff --git a/arch/arc/kernel/intc-arcv2.c b/arch/arc/kernel/intc-arcv2.c
index cf18b3e5a934..c0d0124de089 100644
--- a/arch/arc/kernel/intc-arcv2.c
+++ b/arch/arc/kernel/intc-arcv2.c
@@ -95,7 +95,7 @@ void arc_init_IRQ(void)
95 95
96 /* setup status32, don't enable intr yet as kernel doesn't want */ 96 /* setup status32, don't enable intr yet as kernel doesn't want */
97 tmp = read_aux_reg(ARC_REG_STATUS32); 97 tmp = read_aux_reg(ARC_REG_STATUS32);
98 tmp |= STATUS_AD_MASK | (ARCV2_IRQ_DEF_PRIO << 1); 98 tmp |= ARCV2_IRQ_DEF_PRIO << 1;
99 tmp &= ~STATUS_IE_MASK; 99 tmp &= ~STATUS_IE_MASK;
100 asm volatile("kflag %0 \n"::"r"(tmp)); 100 asm volatile("kflag %0 \n"::"r"(tmp));
101} 101}
diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c
index 7b2340996cf8..a9c88b7e9182 100644
--- a/arch/arc/kernel/setup.c
+++ b/arch/arc/kernel/setup.c
@@ -36,6 +36,7 @@ unsigned int intr_to_DE_cnt;
36 36
37/* Part of U-boot ABI: see head.S */ 37/* Part of U-boot ABI: see head.S */
38int __initdata uboot_tag; 38int __initdata uboot_tag;
39int __initdata uboot_magic;
39char __initdata *uboot_arg; 40char __initdata *uboot_arg;
40 41
41const struct machine_desc *machine_desc; 42const struct machine_desc *machine_desc;
@@ -44,29 +45,24 @@ struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
44 45
45struct cpuinfo_arc cpuinfo_arc700[NR_CPUS]; 46struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
46 47
47static const struct id_to_str arc_cpu_rel[] = { 48static const struct id_to_str arc_legacy_rel[] = {
49 /* ID.ARCVER, Release */
48#ifdef CONFIG_ISA_ARCOMPACT 50#ifdef CONFIG_ISA_ARCOMPACT
49 { 0x34, "R4.10"}, 51 { 0x34, "R4.10"},
50 { 0x35, "R4.11"}, 52 { 0x35, "R4.11"},
51#else 53#else
52 { 0x51, "R2.0" }, 54 { 0x51, "R2.0" },
53 { 0x52, "R2.1" }, 55 { 0x52, "R2.1" },
54 { 0x53, "R3.0" }, 56 { 0x53, "R3.0" },
55 { 0x54, "R3.10a" },
56#endif 57#endif
57 { 0x00, NULL } 58 { 0x00, NULL }
58}; 59};
59 60
60static const struct id_to_str arc_cpu_nm[] = { 61static const struct id_to_str arc_cpu_rel[] = {
61#ifdef CONFIG_ISA_ARCOMPACT 62 /* UARCH.MAJOR, Release */
62 { 0x20, "ARC 600" }, 63 { 0, "R3.10a"},
63 { 0x30, "ARC 770" }, /* 750 identified seperately */ 64 { 1, "R3.50a"},
64#else 65 { 0xFF, NULL }
65 { 0x40, "ARC EM" },
66 { 0x50, "ARC HS38" },
67 { 0x54, "ARC HS48" },
68#endif
69 { 0x00, "Unknown" }
70}; 66};
71 67
72static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu) 68static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
@@ -116,31 +112,72 @@ static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
116 } 112 }
117} 113}
118 114
115static void decode_arc_core(struct cpuinfo_arc *cpu)
116{
117 struct bcr_uarch_build_arcv2 uarch;
118 const struct id_to_str *tbl;
119
120 /*
121 * Up until (including) the first core4 release (0x54) things were
122 * simple: AUX IDENTITY.ARCVER was sufficient to identify arc family
123 * and release: 0x50 to 0x53 was HS38, 0x54 was HS48 (dual issue)
124 */
125
126 if (cpu->core.family < 0x54) { /* includes arc700 */
127
128 for (tbl = &arc_legacy_rel[0]; tbl->id != 0; tbl++) {
129 if (cpu->core.family == tbl->id) {
130 cpu->release = tbl->str;
131 break;
132 }
133 }
134
135 if (is_isa_arcompact())
136 cpu->name = "ARC700";
137 else if (tbl->str)
138 cpu->name = "HS38";
139 else
140 cpu->name = cpu->release = "Unknown";
141
142 return;
143 }
144
145 /*
146 * However the subsequent HS release (same 0x54) allow HS38 or HS48
147 * configurations and encode this info in a different BCR.
148 * The BCR was introduced in 0x54 so can't be read unconditionally.
149 */
150
151 READ_BCR(ARC_REG_MICRO_ARCH_BCR, uarch);
152
153 if (uarch.prod == 4) {
154 cpu->name = "HS48";
155 cpu->extn.dual = 1;
156
157 } else {
158 cpu->name = "HS38";
159 }
160
161 for (tbl = &arc_cpu_rel[0]; tbl->id != 0xFF; tbl++) {
162 if (uarch.maj == tbl->id) {
163 cpu->release = tbl->str;
164 break;
165 }
166 }
167}
168
119static void read_arc_build_cfg_regs(void) 169static void read_arc_build_cfg_regs(void)
120{ 170{
121 struct bcr_timer timer; 171 struct bcr_timer timer;
122 struct bcr_generic bcr; 172 struct bcr_generic bcr;
123 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()]; 173 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
124 const struct id_to_str *tbl;
125 struct bcr_isa_arcv2 isa; 174 struct bcr_isa_arcv2 isa;
126 struct bcr_actionpoint ap; 175 struct bcr_actionpoint ap;
127 176
128 FIX_PTR(cpu); 177 FIX_PTR(cpu);
129 178
130 READ_BCR(AUX_IDENTITY, cpu->core); 179 READ_BCR(AUX_IDENTITY, cpu->core);
131 180 decode_arc_core(cpu);
132 for (tbl = &arc_cpu_rel[0]; tbl->id != 0; tbl++) {
133 if (cpu->core.family == tbl->id) {
134 cpu->details = tbl->str;
135 break;
136 }
137 }
138
139 for (tbl = &arc_cpu_nm[0]; tbl->id != 0; tbl++) {
140 if ((cpu->core.family & 0xF4) == tbl->id)
141 break;
142 }
143 cpu->name = tbl->str;
144 181
145 READ_BCR(ARC_REG_TIMERS_BCR, timer); 182 READ_BCR(ARC_REG_TIMERS_BCR, timer);
146 cpu->extn.timer0 = timer.t0; 183 cpu->extn.timer0 = timer.t0;
@@ -151,16 +188,6 @@ static void read_arc_build_cfg_regs(void)
151 188
152 READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy); 189 READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy);
153 190
154 cpu->extn.norm = read_aux_reg(ARC_REG_NORM_BCR) > 1 ? 1 : 0; /* 2,3 */
155 cpu->extn.barrel = read_aux_reg(ARC_REG_BARREL_BCR) > 1 ? 1 : 0; /* 2,3 */
156 cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR) ? 1 : 0; /* 1,3 */
157 cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR) ? 1 : 0;
158 cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR) > 1 ? 1 : 0; /* 2 */
159 cpu->extn.swape = (cpu->core.family >= 0x34) ? 1 :
160 IS_ENABLED(CONFIG_ARC_HAS_SWAPE);
161
162 READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem);
163
164 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */ 191 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
165 read_decode_ccm_bcr(cpu); 192 read_decode_ccm_bcr(cpu);
166 193
@@ -198,30 +225,12 @@ static void read_arc_build_cfg_regs(void)
198 cpu->bpu.num_pred = 2048 << bpu.pte; 225 cpu->bpu.num_pred = 2048 << bpu.pte;
199 cpu->bpu.ret_stk = 4 << bpu.rse; 226 cpu->bpu.ret_stk = 4 << bpu.rse;
200 227
201 if (cpu->core.family >= 0x54) { 228 /* if dual issue hardware, is it enabled ? */
202 229 if (cpu->extn.dual) {
203 struct bcr_uarch_build_arcv2 uarch; 230 unsigned int exec_ctrl;
204
205 /*
206 * The first 0x54 core (uarch maj:min 0:1 or 0:2) was
207 * dual issue only (HS4x). But next uarch rev (1:0)
208 * allows it be configured for single issue (HS3x)
209 * Ensure we fiddle with dual issue only on HS4x
210 */
211 READ_BCR(ARC_REG_MICRO_ARCH_BCR, uarch);
212
213 if (uarch.prod == 4) {
214 unsigned int exec_ctrl;
215
216 /* dual issue hardware always present */
217 cpu->extn.dual = 1;
218
219 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
220 231
221 /* dual issue hardware enabled ? */ 232 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
222 cpu->extn.dual_enb = !(exec_ctrl & 1); 233 cpu->extn.dual_enb = !(exec_ctrl & 1);
223
224 }
225 } 234 }
226 } 235 }
227 236
@@ -263,7 +272,8 @@ static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
263{ 272{
264 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id]; 273 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
265 struct bcr_identity *core = &cpu->core; 274 struct bcr_identity *core = &cpu->core;
266 int i, n = 0, ua = 0; 275 char mpy_opt[16];
276 int n = 0;
267 277
268 FIX_PTR(cpu); 278 FIX_PTR(cpu);
269 279
@@ -272,7 +282,7 @@ static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
272 core->family, core->cpu_id, core->chip_id); 282 core->family, core->cpu_id, core->chip_id);
273 283
274 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n", 284 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
275 cpu_id, cpu->name, cpu->details, 285 cpu_id, cpu->name, cpu->release,
276 is_isa_arcompact() ? "ARCompact" : "ARCv2", 286 is_isa_arcompact() ? "ARCompact" : "ARCv2",
277 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"), 287 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
278 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue ")); 288 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
@@ -283,61 +293,50 @@ static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
283 IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT), 293 IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
284 IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT)); 294 IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
285 295
286#ifdef __ARC_UNALIGNED__
287 ua = 1;
288#endif
289 n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s%s",
290 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
291 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
292 IS_AVAIL1(cpu->isa.unalign, "unalign "), IS_USED_RUN(ua));
293
294 if (i)
295 n += scnprintf(buf + n, len - n, "\n\t\t: ");
296
297 if (cpu->extn_mpy.ver) { 296 if (cpu->extn_mpy.ver) {
298 if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */ 297 if (is_isa_arcompact()) {
299 n += scnprintf(buf + n, len - n, "mpy "); 298 scnprintf(mpy_opt, 16, "mpy");
300 } else { 299 } else {
300
301 int opt = 2; /* stock MPY/MPYH */ 301 int opt = 2; /* stock MPY/MPYH */
302 302
303 if (cpu->extn_mpy.dsp) /* OPT 7-9 */ 303 if (cpu->extn_mpy.dsp) /* OPT 7-9 */
304 opt = cpu->extn_mpy.dsp + 6; 304 opt = cpu->extn_mpy.dsp + 6;
305 305
306 n += scnprintf(buf + n, len - n, "mpy[opt %d] ", opt); 306 scnprintf(mpy_opt, 16, "mpy[opt %d] ", opt);
307 } 307 }
308 } 308 }
309 309
310 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n", 310 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
311 IS_AVAIL1(cpu->isa.div_rem, "div_rem "), 311 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
312 IS_AVAIL1(cpu->extn.norm, "norm "), 312 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
313 IS_AVAIL1(cpu->extn.barrel, "barrel-shift "), 313 IS_AVAIL2(cpu->isa.unalign, "unalign ", CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS),
314 IS_AVAIL1(cpu->extn.swap, "swap "), 314 IS_AVAIL1(cpu->extn_mpy.ver, mpy_opt),
315 IS_AVAIL1(cpu->extn.minmax, "minmax "), 315 IS_AVAIL1(cpu->isa.div_rem, "div_rem "));
316 IS_AVAIL1(cpu->extn.crc, "crc "), 316
317 IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE)); 317 if (cpu->bpu.ver) {
318
319 if (cpu->bpu.ver)
320 n += scnprintf(buf + n, len - n, 318 n += scnprintf(buf + n, len - n,
321 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d Return stk: %d", 319 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d Return stk: %d",
322 IS_AVAIL1(cpu->bpu.full, "full"), 320 IS_AVAIL1(cpu->bpu.full, "full"),
323 IS_AVAIL1(!cpu->bpu.full, "partial"), 321 IS_AVAIL1(!cpu->bpu.full, "partial"),
324 cpu->bpu.num_cache, cpu->bpu.num_pred, cpu->bpu.ret_stk); 322 cpu->bpu.num_cache, cpu->bpu.num_pred, cpu->bpu.ret_stk);
325 323
326 if (is_isa_arcv2()) { 324 if (is_isa_arcv2()) {
327 struct bcr_lpb lpb; 325 struct bcr_lpb lpb;
328 326
329 READ_BCR(ARC_REG_LPB_BUILD, lpb); 327 READ_BCR(ARC_REG_LPB_BUILD, lpb);
330 if (lpb.ver) { 328 if (lpb.ver) {
331 unsigned int ctl; 329 unsigned int ctl;
332 ctl = read_aux_reg(ARC_REG_LPB_CTRL); 330 ctl = read_aux_reg(ARC_REG_LPB_CTRL);
333 331
334 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s", 332 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
335 lpb.entries, 333 lpb.entries,
336 IS_DISABLED_RUN(!ctl)); 334 IS_DISABLED_RUN(!ctl));
335 }
337 } 336 }
337 n += scnprintf(buf + n, len - n, "\n");
338 } 338 }
339 339
340 n += scnprintf(buf + n, len - n, "\n");
341 return buf; 340 return buf;
342} 341}
343 342
@@ -390,11 +389,6 @@ static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
390 } 389 }
391 } 390 }
392 391
393 n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
394 EF_ARC_OSABI_CURRENT >> 8,
395 EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
396 "no-legacy-syscalls" : "64-bit data any register aligned");
397
398 return buf; 392 return buf;
399} 393}
400 394
@@ -497,6 +491,8 @@ static inline bool uboot_arg_invalid(unsigned long addr)
497#define UBOOT_TAG_NONE 0 491#define UBOOT_TAG_NONE 0
498#define UBOOT_TAG_CMDLINE 1 492#define UBOOT_TAG_CMDLINE 1
499#define UBOOT_TAG_DTB 2 493#define UBOOT_TAG_DTB 2
494/* We always pass 0 as magic from U-boot */
495#define UBOOT_MAGIC_VALUE 0
500 496
501void __init handle_uboot_args(void) 497void __init handle_uboot_args(void)
502{ 498{
@@ -511,6 +507,11 @@ void __init handle_uboot_args(void)
511 goto ignore_uboot_args; 507 goto ignore_uboot_args;
512 } 508 }
513 509
510 if (uboot_magic != UBOOT_MAGIC_VALUE) {
511 pr_warn(IGNORE_ARGS "non zero uboot magic\n");
512 goto ignore_uboot_args;
513 }
514
514 if (uboot_tag != UBOOT_TAG_NONE && 515 if (uboot_tag != UBOOT_TAG_NONE &&
515 uboot_arg_invalid((unsigned long)uboot_arg)) { 516 uboot_arg_invalid((unsigned long)uboot_arg)) {
516 pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg); 517 pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg);
diff --git a/arch/arc/kernel/troubleshoot.c b/arch/arc/kernel/troubleshoot.c
index 215f515442e0..b0aa8c028331 100644
--- a/arch/arc/kernel/troubleshoot.c
+++ b/arch/arc/kernel/troubleshoot.c
@@ -145,7 +145,8 @@ static void show_ecr_verbose(struct pt_regs *regs)
145 } else if (vec == ECR_V_PROTV) { 145 } else if (vec == ECR_V_PROTV) {
146 if (cause_code == ECR_C_PROTV_INST_FETCH) 146 if (cause_code == ECR_C_PROTV_INST_FETCH)
147 pr_cont("Execute from Non-exec Page\n"); 147 pr_cont("Execute from Non-exec Page\n");
148 else if (cause_code == ECR_C_PROTV_MISALIG_DATA) 148 else if (cause_code == ECR_C_PROTV_MISALIG_DATA &&
149 IS_ENABLED(CONFIG_ISA_ARCOMPACT))
149 pr_cont("Misaligned r/w from 0x%08lx\n", address); 150 pr_cont("Misaligned r/w from 0x%08lx\n", address);
150 else 151 else
151 pr_cont("%s access not allowed on page\n", 152 pr_cont("%s access not allowed on page\n",
@@ -161,6 +162,8 @@ static void show_ecr_verbose(struct pt_regs *regs)
161 pr_cont("Bus Error from Data Mem\n"); 162 pr_cont("Bus Error from Data Mem\n");
162 else 163 else
163 pr_cont("Bus Error, check PRM\n"); 164 pr_cont("Bus Error, check PRM\n");
165 } else if (vec == ECR_V_MISALIGN) {
166 pr_cont("Misaligned r/w from 0x%08lx\n", address);
164#endif 167#endif
165 } else if (vec == ECR_V_TRAP) { 168 } else if (vec == ECR_V_TRAP) {
166 if (regs->ecr_param == 5) 169 if (regs->ecr_param == 5)
diff --git a/arch/arc/lib/Makefile b/arch/arc/lib/Makefile
index b1656d156097..f7537b466b23 100644
--- a/arch/arc/lib/Makefile
+++ b/arch/arc/lib/Makefile
@@ -8,4 +8,10 @@
8lib-y := strchr-700.o strcpy-700.o strlen.o memcmp.o 8lib-y := strchr-700.o strcpy-700.o strlen.o memcmp.o
9 9
10lib-$(CONFIG_ISA_ARCOMPACT) += memcpy-700.o memset.o strcmp.o 10lib-$(CONFIG_ISA_ARCOMPACT) += memcpy-700.o memset.o strcmp.o
11lib-$(CONFIG_ISA_ARCV2) += memcpy-archs.o memset-archs.o strcmp-archs.o 11lib-$(CONFIG_ISA_ARCV2) += memset-archs.o strcmp-archs.o
12
13ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
14lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs-unaligned.o
15else
16lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs.o
17endif
diff --git a/arch/arc/lib/memcpy-archs-unaligned.S b/arch/arc/lib/memcpy-archs-unaligned.S
new file mode 100644
index 000000000000..28993a73fdde
--- /dev/null
+++ b/arch/arc/lib/memcpy-archs-unaligned.S
@@ -0,0 +1,47 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * ARCv2 memcpy implementation optimized for unaligned memory access using.
4 *
5 * Copyright (C) 2019 Synopsys
6 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
7 */
8
9#include <linux/linkage.h>
10
11#ifdef CONFIG_ARC_HAS_LL64
12# define LOADX(DST,RX) ldd.ab DST, [RX, 8]
13# define STOREX(SRC,RX) std.ab SRC, [RX, 8]
14# define ZOLSHFT 5
15# define ZOLAND 0x1F
16#else
17# define LOADX(DST,RX) ld.ab DST, [RX, 4]
18# define STOREX(SRC,RX) st.ab SRC, [RX, 4]
19# define ZOLSHFT 4
20# define ZOLAND 0xF
21#endif
22
23ENTRY_CFI(memcpy)
24 mov r3, r0 ; don;t clobber ret val
25
26 lsr.f lp_count, r2, ZOLSHFT
27 lpnz @.Lcopy32_64bytes
28 ;; LOOP START
29 LOADX (r6, r1)
30 LOADX (r8, r1)
31 LOADX (r10, r1)
32 LOADX (r4, r1)
33 STOREX (r6, r3)
34 STOREX (r8, r3)
35 STOREX (r10, r3)
36 STOREX (r4, r3)
37.Lcopy32_64bytes:
38
39 and.f lp_count, r2, ZOLAND ;Last remaining 31 bytes
40 lpnz @.Lcopyremainingbytes
41 ;; LOOP START
42 ldb.ab r5, [r1, 1]
43 stb.ab r5, [r3, 1]
44.Lcopyremainingbytes:
45
46 j [blink]
47END_CFI(memcpy)
diff --git a/arch/arc/plat-eznps/Kconfig b/arch/arc/plat-eznps/Kconfig
index 8eff057efcae..2eaecfb063a7 100644
--- a/arch/arc/plat-eznps/Kconfig
+++ b/arch/arc/plat-eznps/Kconfig
@@ -26,8 +26,8 @@ config EZNPS_MTM_EXT
26 help 26 help
27 Here we add new hierarchy for CPUs topology. 27 Here we add new hierarchy for CPUs topology.
28 We got: 28 We got:
29 Core 29 Core
30 Thread 30 Thread
31 At the new thread level each CPU represent one HW thread. 31 At the new thread level each CPU represent one HW thread.
32 At highest hierarchy each core contain 16 threads, 32 At highest hierarchy each core contain 16 threads,
33 any of them seem like CPU from Linux point of view. 33 any of them seem like CPU from Linux point of view.
@@ -35,10 +35,10 @@ config EZNPS_MTM_EXT
35 core and HW scheduler round robin between them. 35 core and HW scheduler round robin between them.
36 36
37config EZNPS_MEM_ERROR_ALIGN 37config EZNPS_MEM_ERROR_ALIGN
38 bool "ARC-EZchip Memory error as an exception" 38 bool "ARC-EZchip Memory error as an exception"
39 depends on EZNPS_MTM_EXT 39 depends on EZNPS_MTM_EXT
40 default n 40 default n
41 help 41 help
42 On the real chip of the NPS, user memory errors are handled 42 On the real chip of the NPS, user memory errors are handled
43 as a machine check exception, which is fatal, whereas on 43 as a machine check exception, which is fatal, whereas on
44 simulator platform for NPS, is handled as a Level 2 interrupt 44 simulator platform for NPS, is handled as a Level 2 interrupt
diff --git a/arch/arm/mach-cns3xxx/core.c b/arch/arm/mach-cns3xxx/core.c
index 7d5a44a06648..f676592d8402 100644
--- a/arch/arm/mach-cns3xxx/core.c
+++ b/arch/arm/mach-cns3xxx/core.c
@@ -90,7 +90,7 @@ void __init cns3xxx_map_io(void)
90/* used by entry-macro.S */ 90/* used by entry-macro.S */
91void __init cns3xxx_init_irq(void) 91void __init cns3xxx_init_irq(void)
92{ 92{
93 gic_init(0, 29, IOMEM(CNS3XXX_TC11MP_GIC_DIST_BASE_VIRT), 93 gic_init(IOMEM(CNS3XXX_TC11MP_GIC_DIST_BASE_VIRT),
94 IOMEM(CNS3XXX_TC11MP_GIC_CPU_BASE_VIRT)); 94 IOMEM(CNS3XXX_TC11MP_GIC_CPU_BASE_VIRT));
95} 95}
96 96
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 117b2541ef3d..7e34b9eba5de 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -159,7 +159,6 @@ config ARM64
159 select IRQ_DOMAIN 159 select IRQ_DOMAIN
160 select IRQ_FORCED_THREADING 160 select IRQ_FORCED_THREADING
161 select MODULES_USE_ELF_RELA 161 select MODULES_USE_ELF_RELA
162 select MULTI_IRQ_HANDLER
163 select NEED_DMA_MAP_STATE 162 select NEED_DMA_MAP_STATE
164 select NEED_SG_DMA_LENGTH 163 select NEED_SG_DMA_LENGTH
165 select OF 164 select OF
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h
index 2afb1338b48a..5f1437099b99 100644
--- a/arch/arm64/include/asm/cputype.h
+++ b/arch/arm64/include/asm/cputype.h
@@ -77,6 +77,7 @@
77#define ARM_CPU_IMP_QCOM 0x51 77#define ARM_CPU_IMP_QCOM 0x51
78#define ARM_CPU_IMP_NVIDIA 0x4E 78#define ARM_CPU_IMP_NVIDIA 0x4E
79#define ARM_CPU_IMP_FUJITSU 0x46 79#define ARM_CPU_IMP_FUJITSU 0x46
80#define ARM_CPU_IMP_HISI 0x48
80 81
81#define ARM_CPU_PART_AEM_V8 0xD0F 82#define ARM_CPU_PART_AEM_V8 0xD0F
82#define ARM_CPU_PART_FOUNDATION 0xD00 83#define ARM_CPU_PART_FOUNDATION 0xD00
@@ -107,6 +108,8 @@
107 108
108#define FUJITSU_CPU_PART_A64FX 0x001 109#define FUJITSU_CPU_PART_A64FX 0x001
109 110
111#define HISI_CPU_PART_TSV110 0xD01
112
110#define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53) 113#define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)
111#define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57) 114#define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
112#define MIDR_CORTEX_A72 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72) 115#define MIDR_CORTEX_A72 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72)
@@ -126,10 +129,11 @@
126#define MIDR_NVIDIA_DENVER MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_DENVER) 129#define MIDR_NVIDIA_DENVER MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_DENVER)
127#define MIDR_NVIDIA_CARMEL MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_CARMEL) 130#define MIDR_NVIDIA_CARMEL MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_CARMEL)
128#define MIDR_FUJITSU_A64FX MIDR_CPU_MODEL(ARM_CPU_IMP_FUJITSU, FUJITSU_CPU_PART_A64FX) 131#define MIDR_FUJITSU_A64FX MIDR_CPU_MODEL(ARM_CPU_IMP_FUJITSU, FUJITSU_CPU_PART_A64FX)
132#define MIDR_HISI_TSV110 MIDR_CPU_MODEL(ARM_CPU_IMP_HISI, HISI_CPU_PART_TSV110)
129 133
130/* Fujitsu Erratum 010001 affects A64FX 1.0 and 1.1, (v0r0 and v1r0) */ 134/* Fujitsu Erratum 010001 affects A64FX 1.0 and 1.1, (v0r0 and v1r0) */
131#define MIDR_FUJITSU_ERRATUM_010001 MIDR_FUJITSU_A64FX 135#define MIDR_FUJITSU_ERRATUM_010001 MIDR_FUJITSU_A64FX
132#define MIDR_FUJITSU_ERRATUM_010001_MASK (~MIDR_VARIANT(1)) 136#define MIDR_FUJITSU_ERRATUM_010001_MASK (~MIDR_CPU_VAR_REV(1, 0))
133#define TCR_CLEAR_FUJITSU_ERRATUM_010001 (TCR_NFD1 | TCR_NFD0) 137#define TCR_CLEAR_FUJITSU_ERRATUM_010001 (TCR_NFD1 | TCR_NFD0)
134 138
135#ifndef __ASSEMBLY__ 139#ifndef __ASSEMBLY__
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index e24e94d28767..4061de10cea6 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -963,6 +963,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,
963 MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), 963 MIDR_ALL_VERSIONS(MIDR_CORTEX_A57),
964 MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), 964 MIDR_ALL_VERSIONS(MIDR_CORTEX_A72),
965 MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), 965 MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
966 MIDR_ALL_VERSIONS(MIDR_HISI_TSV110),
966 { /* sentinel */ } 967 { /* sentinel */ }
967 }; 968 };
968 char const *str = "command line option"; 969 char const *str = "command line option";
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 7fb6f3aa5ceb..7a679caf4585 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -91,8 +91,6 @@ static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
91int __kprobes arch_prepare_kprobe(struct kprobe *p) 91int __kprobes arch_prepare_kprobe(struct kprobe *p)
92{ 92{
93 unsigned long probe_addr = (unsigned long)p->addr; 93 unsigned long probe_addr = (unsigned long)p->addr;
94 extern char __start_rodata[];
95 extern char __end_rodata[];
96 94
97 if (probe_addr & 0x3) 95 if (probe_addr & 0x3)
98 return -EINVAL; 96 return -EINVAL;
@@ -100,10 +98,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
100 /* copy instruction */ 98 /* copy instruction */
101 p->opcode = le32_to_cpu(*p->addr); 99 p->opcode = le32_to_cpu(*p->addr);
102 100
103 if (in_exception_text(probe_addr)) 101 if (search_exception_tables(probe_addr))
104 return -EINVAL;
105 if (probe_addr >= (unsigned long) __start_rodata &&
106 probe_addr <= (unsigned long) __end_rodata)
107 return -EINVAL; 102 return -EINVAL;
108 103
109 /* decode instruction */ 104 /* decode instruction */
@@ -476,26 +471,37 @@ kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr)
476 return DBG_HOOK_HANDLED; 471 return DBG_HOOK_HANDLED;
477} 472}
478 473
479bool arch_within_kprobe_blacklist(unsigned long addr) 474/*
475 * Provide a blacklist of symbols identifying ranges which cannot be kprobed.
476 * This blacklist is exposed to userspace via debugfs (kprobes/blacklist).
477 */
478int __init arch_populate_kprobe_blacklist(void)
480{ 479{
481 if ((addr >= (unsigned long)__kprobes_text_start && 480 int ret;
482 addr < (unsigned long)__kprobes_text_end) || 481
483 (addr >= (unsigned long)__entry_text_start && 482 ret = kprobe_add_area_blacklist((unsigned long)__entry_text_start,
484 addr < (unsigned long)__entry_text_end) || 483 (unsigned long)__entry_text_end);
485 (addr >= (unsigned long)__idmap_text_start && 484 if (ret)
486 addr < (unsigned long)__idmap_text_end) || 485 return ret;
487 (addr >= (unsigned long)__hyp_text_start && 486 ret = kprobe_add_area_blacklist((unsigned long)__irqentry_text_start,
488 addr < (unsigned long)__hyp_text_end) || 487 (unsigned long)__irqentry_text_end);
489 !!search_exception_tables(addr)) 488 if (ret)
490 return true; 489 return ret;
491 490 ret = kprobe_add_area_blacklist((unsigned long)__exception_text_start,
492 if (!is_kernel_in_hyp_mode()) { 491 (unsigned long)__exception_text_end);
493 if ((addr >= (unsigned long)__hyp_idmap_text_start && 492 if (ret)
494 addr < (unsigned long)__hyp_idmap_text_end)) 493 return ret;
495 return true; 494 ret = kprobe_add_area_blacklist((unsigned long)__idmap_text_start,
496 } 495 (unsigned long)__idmap_text_end);
497 496 if (ret)
498 return false; 497 return ret;
498 ret = kprobe_add_area_blacklist((unsigned long)__hyp_text_start,
499 (unsigned long)__hyp_text_end);
500 if (ret || is_kernel_in_hyp_mode())
501 return ret;
502 ret = kprobe_add_area_blacklist((unsigned long)__hyp_idmap_text_start,
503 (unsigned long)__hyp_idmap_text_end);
504 return ret;
499} 505}
500 506
501void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs) 507void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs)
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 1a29f2695ff2..d908b5e9e949 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -143,6 +143,7 @@ void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
143 if (trace->nr_entries < trace->max_entries) 143 if (trace->nr_entries < trace->max_entries)
144 trace->entries[trace->nr_entries++] = ULONG_MAX; 144 trace->entries[trace->nr_entries++] = ULONG_MAX;
145} 145}
146EXPORT_SYMBOL_GPL(save_stack_trace_regs);
146 147
147static noinline void __save_stack_trace(struct task_struct *tsk, 148static noinline void __save_stack_trace(struct task_struct *tsk,
148 struct stack_trace *trace, unsigned int nosched) 149 struct stack_trace *trace, unsigned int nosched)
diff --git a/arch/mips/bcm47xx/workarounds.c b/arch/mips/bcm47xx/workarounds.c
index 46eddbec8d9f..0ab95dd431b3 100644
--- a/arch/mips/bcm47xx/workarounds.c
+++ b/arch/mips/bcm47xx/workarounds.c
@@ -24,6 +24,7 @@ void __init bcm47xx_workarounds(void)
24 case BCM47XX_BOARD_NETGEAR_WNR3500L: 24 case BCM47XX_BOARD_NETGEAR_WNR3500L:
25 bcm47xx_workarounds_enable_usb_power(12); 25 bcm47xx_workarounds_enable_usb_power(12);
26 break; 26 break;
27 case BCM47XX_BOARD_NETGEAR_WNDR3400V2:
27 case BCM47XX_BOARD_NETGEAR_WNDR3400_V3: 28 case BCM47XX_BOARD_NETGEAR_WNDR3400_V3:
28 bcm47xx_workarounds_enable_usb_power(21); 29 bcm47xx_workarounds_enable_usb_power(21);
29 break; 30 break;
diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
index e77672539e8e..e4456e450f94 100644
--- a/arch/mips/include/asm/jump_label.h
+++ b/arch/mips/include/asm/jump_label.h
@@ -21,15 +21,15 @@
21#endif 21#endif
22 22
23#ifdef CONFIG_CPU_MICROMIPS 23#ifdef CONFIG_CPU_MICROMIPS
24#define NOP_INSN "nop32" 24#define B_INSN "b32"
25#else 25#else
26#define NOP_INSN "nop" 26#define B_INSN "b"
27#endif 27#endif
28 28
29static __always_inline bool arch_static_branch(struct static_key *key, bool branch) 29static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
30{ 30{
31 asm_volatile_goto("1:\t" NOP_INSN "\n\t" 31 asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
32 "nop\n\t" 32 "2:\tnop\n\t"
33 ".pushsection __jump_table, \"aw\"\n\t" 33 ".pushsection __jump_table, \"aw\"\n\t"
34 WORD_INSN " 1b, %l[l_yes], %0\n\t" 34 WORD_INSN " 1b, %l[l_yes], %0\n\t"
35 ".popsection\n\t" 35 ".popsection\n\t"
diff --git a/arch/mips/include/uapi/asm/posix_types.h b/arch/mips/include/uapi/asm/posix_types.h
index 6aa49c10f88f..f0ccb5b90ce9 100644
--- a/arch/mips/include/uapi/asm/posix_types.h
+++ b/arch/mips/include/uapi/asm/posix_types.h
@@ -21,13 +21,6 @@
21typedef long __kernel_daddr_t; 21typedef long __kernel_daddr_t;
22#define __kernel_daddr_t __kernel_daddr_t 22#define __kernel_daddr_t __kernel_daddr_t
23 23
24#if (_MIPS_SZLONG == 32)
25typedef struct {
26 long val[2];
27} __kernel_fsid_t;
28#define __kernel_fsid_t __kernel_fsid_t
29#endif
30
31#include <asm-generic/posix_types.h> 24#include <asm-generic/posix_types.h>
32 25
33#endif /* _ASM_POSIX_TYPES_H */ 26#endif /* _ASM_POSIX_TYPES_H */
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index cb7e9ed7a453..33ee0d18fb0a 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -140,6 +140,13 @@ SECTIONS
140 PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT) 140 PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
141#endif 141#endif
142 142
143#ifdef CONFIG_MIPS_ELF_APPENDED_DTB
144 .appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
145 *(.appended_dtb)
146 KEEP(*(.appended_dtb))
147 }
148#endif
149
143#ifdef CONFIG_RELOCATABLE 150#ifdef CONFIG_RELOCATABLE
144 . = ALIGN(4); 151 . = ALIGN(4);
145 152
@@ -164,11 +171,6 @@ SECTIONS
164 __appended_dtb = .; 171 __appended_dtb = .;
165 /* leave space for appended DTB */ 172 /* leave space for appended DTB */
166 . += 0x100000; 173 . += 0x100000;
167#elif defined(CONFIG_MIPS_ELF_APPENDED_DTB)
168 .appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
169 *(.appended_dtb)
170 KEEP(*(.appended_dtb))
171 }
172#endif 174#endif
173 /* 175 /*
174 * Align to 64K in attempt to eliminate holes before the 176 * Align to 64K in attempt to eliminate holes before the
diff --git a/arch/mips/loongson64/lemote-2f/irq.c b/arch/mips/loongson64/lemote-2f/irq.c
index 9e33e45aa17c..b213cecb8e3a 100644
--- a/arch/mips/loongson64/lemote-2f/irq.c
+++ b/arch/mips/loongson64/lemote-2f/irq.c
@@ -103,7 +103,7 @@ static struct irqaction ip6_irqaction = {
103static struct irqaction cascade_irqaction = { 103static struct irqaction cascade_irqaction = {
104 .handler = no_action, 104 .handler = no_action,
105 .name = "cascade", 105 .name = "cascade",
106 .flags = IRQF_NO_THREAD, 106 .flags = IRQF_NO_THREAD | IRQF_NO_SUSPEND,
107}; 107};
108 108
109void __init mach_init_irq(void) 109void __init mach_init_irq(void)
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index d34ad1657d7b..598cdcdd1355 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -352,7 +352,7 @@ static inline bool strict_kernel_rwx_enabled(void)
352#if defined(CONFIG_SPARSEMEM_VMEMMAP) && defined(CONFIG_SPARSEMEM_EXTREME) && \ 352#if defined(CONFIG_SPARSEMEM_VMEMMAP) && defined(CONFIG_SPARSEMEM_EXTREME) && \
353 defined (CONFIG_PPC_64K_PAGES) 353 defined (CONFIG_PPC_64K_PAGES)
354#define MAX_PHYSMEM_BITS 51 354#define MAX_PHYSMEM_BITS 51
355#else 355#elif defined(CONFIG_SPARSEMEM)
356#define MAX_PHYSMEM_BITS 46 356#define MAX_PHYSMEM_BITS 46
357#endif 357#endif
358 358
diff --git a/arch/powerpc/include/asm/vdso_datapage.h b/arch/powerpc/include/asm/vdso_datapage.h
index 1afe90ade595..bbc06bd72b1f 100644
--- a/arch/powerpc/include/asm/vdso_datapage.h
+++ b/arch/powerpc/include/asm/vdso_datapage.h
@@ -82,10 +82,10 @@ struct vdso_data {
82 __u32 icache_block_size; /* L1 i-cache block size */ 82 __u32 icache_block_size; /* L1 i-cache block size */
83 __u32 dcache_log_block_size; /* L1 d-cache log block size */ 83 __u32 dcache_log_block_size; /* L1 d-cache log block size */
84 __u32 icache_log_block_size; /* L1 i-cache log block size */ 84 __u32 icache_log_block_size; /* L1 i-cache log block size */
85 __s32 wtom_clock_sec; /* Wall to monotonic clock */ 85 __u32 stamp_sec_fraction; /* fractional seconds of stamp_xtime */
86 __s32 wtom_clock_nsec; 86 __s32 wtom_clock_nsec; /* Wall to monotonic clock nsec */
87 struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */ 87 __s64 wtom_clock_sec; /* Wall to monotonic clock sec */
88 __u32 stamp_sec_fraction; /* fractional seconds of stamp_xtime */ 88 struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */
89 __u32 syscall_map_64[SYSCALL_MAP_SIZE]; /* map of syscalls */ 89 __u32 syscall_map_64[SYSCALL_MAP_SIZE]; /* map of syscalls */
90 __u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */ 90 __u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */
91}; 91};
diff --git a/arch/powerpc/kernel/cpu_setup_6xx.S b/arch/powerpc/kernel/cpu_setup_6xx.S
index 6f1c11e0691f..7534ecff5e92 100644
--- a/arch/powerpc/kernel/cpu_setup_6xx.S
+++ b/arch/powerpc/kernel/cpu_setup_6xx.S
@@ -24,9 +24,6 @@ BEGIN_MMU_FTR_SECTION
24 li r10,0 24 li r10,0
25 mtspr SPRN_SPRG_603_LRU,r10 /* init SW LRU tracking */ 25 mtspr SPRN_SPRG_603_LRU,r10 /* init SW LRU tracking */
26END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU) 26END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
27 lis r10, (swapper_pg_dir - PAGE_OFFSET)@h
28 ori r10, r10, (swapper_pg_dir - PAGE_OFFSET)@l
29 mtspr SPRN_SPRG_PGDIR, r10
30 27
31BEGIN_FTR_SECTION 28BEGIN_FTR_SECTION
32 bl __init_fpu_registers 29 bl __init_fpu_registers
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index ce6a972f2584..48051c8977c5 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -855,6 +855,9 @@ __secondary_start:
855 li r3,0 855 li r3,0
856 stw r3, RTAS_SP(r4) /* 0 => not in RTAS */ 856 stw r3, RTAS_SP(r4) /* 0 => not in RTAS */
857#endif 857#endif
858 lis r4, (swapper_pg_dir - PAGE_OFFSET)@h
859 ori r4, r4, (swapper_pg_dir - PAGE_OFFSET)@l
860 mtspr SPRN_SPRG_PGDIR, r4
858 861
859 /* enable MMU and jump to start_secondary */ 862 /* enable MMU and jump to start_secondary */
860 li r4,MSR_KERNEL 863 li r4,MSR_KERNEL
@@ -942,6 +945,9 @@ start_here:
942 li r3,0 945 li r3,0
943 stw r3, RTAS_SP(r4) /* 0 => not in RTAS */ 946 stw r3, RTAS_SP(r4) /* 0 => not in RTAS */
944#endif 947#endif
948 lis r4, (swapper_pg_dir - PAGE_OFFSET)@h
949 ori r4, r4, (swapper_pg_dir - PAGE_OFFSET)@l
950 mtspr SPRN_SPRG_PGDIR, r4
945 951
946 /* stack */ 952 /* stack */
947 lis r1,init_thread_union@ha 953 lis r1,init_thread_union@ha
diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c
index 9b8631533e02..b33bafb8fcea 100644
--- a/arch/powerpc/kernel/security.c
+++ b/arch/powerpc/kernel/security.c
@@ -190,29 +190,22 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, c
190 bcs = security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED); 190 bcs = security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED);
191 ccd = security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED); 191 ccd = security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED);
192 192
193 if (bcs || ccd || count_cache_flush_type != COUNT_CACHE_FLUSH_NONE) { 193 if (bcs || ccd) {
194 bool comma = false;
195 seq_buf_printf(&s, "Mitigation: "); 194 seq_buf_printf(&s, "Mitigation: ");
196 195
197 if (bcs) { 196 if (bcs)
198 seq_buf_printf(&s, "Indirect branch serialisation (kernel only)"); 197 seq_buf_printf(&s, "Indirect branch serialisation (kernel only)");
199 comma = true;
200 }
201 198
202 if (ccd) { 199 if (bcs && ccd)
203 if (comma)
204 seq_buf_printf(&s, ", ");
205 seq_buf_printf(&s, "Indirect branch cache disabled");
206 comma = true;
207 }
208
209 if (comma)
210 seq_buf_printf(&s, ", "); 200 seq_buf_printf(&s, ", ");
211 201
212 seq_buf_printf(&s, "Software count cache flush"); 202 if (ccd)
203 seq_buf_printf(&s, "Indirect branch cache disabled");
204 } else if (count_cache_flush_type != COUNT_CACHE_FLUSH_NONE) {
205 seq_buf_printf(&s, "Mitigation: Software count cache flush");
213 206
214 if (count_cache_flush_type == COUNT_CACHE_FLUSH_HW) 207 if (count_cache_flush_type == COUNT_CACHE_FLUSH_HW)
215 seq_buf_printf(&s, "(hardware accelerated)"); 208 seq_buf_printf(&s, " (hardware accelerated)");
216 } else if (btb_flush_enabled) { 209 } else if (btb_flush_enabled) {
217 seq_buf_printf(&s, "Mitigation: Branch predictor state flush"); 210 seq_buf_printf(&s, "Mitigation: Branch predictor state flush");
218 } else { 211 } else {
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S
index a4ed9edfd5f0..1f324c28705b 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -92,7 +92,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
92 * At this point, r4,r5 contain our sec/nsec values. 92 * At this point, r4,r5 contain our sec/nsec values.
93 */ 93 */
94 94
95 lwa r6,WTOM_CLOCK_SEC(r3) 95 ld r6,WTOM_CLOCK_SEC(r3)
96 lwa r9,WTOM_CLOCK_NSEC(r3) 96 lwa r9,WTOM_CLOCK_NSEC(r3)
97 97
98 /* We now have our result in r6,r9. We create a fake dependency 98 /* We now have our result in r6,r9. We create a fake dependency
@@ -125,7 +125,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
125 bne cr6,75f 125 bne cr6,75f
126 126
127 /* CLOCK_MONOTONIC_COARSE */ 127 /* CLOCK_MONOTONIC_COARSE */
128 lwa r6,WTOM_CLOCK_SEC(r3) 128 ld r6,WTOM_CLOCK_SEC(r3)
129 lwa r9,WTOM_CLOCK_NSEC(r3) 129 lwa r9,WTOM_CLOCK_NSEC(r3)
130 130
131 /* check if counter has updated */ 131 /* check if counter has updated */
diff --git a/arch/powerpc/mm/hash_low_32.S b/arch/powerpc/mm/hash_low_32.S
index 1f13494efb2b..a6c491f18a04 100644
--- a/arch/powerpc/mm/hash_low_32.S
+++ b/arch/powerpc/mm/hash_low_32.S
@@ -70,12 +70,12 @@ _GLOBAL(hash_page)
70 lis r0,KERNELBASE@h /* check if kernel address */ 70 lis r0,KERNELBASE@h /* check if kernel address */
71 cmplw 0,r4,r0 71 cmplw 0,r4,r0
72 ori r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */ 72 ori r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */
73 mfspr r5, SPRN_SPRG_PGDIR /* virt page-table root */ 73 mfspr r5, SPRN_SPRG_PGDIR /* phys page-table root */
74 blt+ 112f /* assume user more likely */ 74 blt+ 112f /* assume user more likely */
75 lis r5,swapper_pg_dir@ha /* if kernel address, use */ 75 lis r5, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */
76 addi r5,r5,swapper_pg_dir@l /* kernel page table */ 76 addi r5 ,r5 ,(swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */
77 rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */ 77 rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */
78112: tophys(r5, r5) 78112:
79#ifndef CONFIG_PTE_64BIT 79#ifndef CONFIG_PTE_64BIT
80 rlwimi r5,r4,12,20,29 /* insert top 10 bits of address */ 80 rlwimi r5,r4,12,20,29 /* insert top 10 bits of address */
81 lwz r8,0(r5) /* get pmd entry */ 81 lwz r8,0(r5) /* get pmd entry */
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 315a67b8896b..90154df8f125 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -13,8 +13,9 @@
13 */ 13 */
14 14
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/kernel.h> 16#include <linux/compiler.h>
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/limits.h>
18#include <asm/asm.h> 19#include <asm/asm.h>
19#include "ctype.h" 20#include "ctype.h"
20#include "string.h" 21#include "string.h"
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 6461a16b4559..e4ba467a9fc6 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -103,9 +103,13 @@ static int hv_cpu_init(unsigned int cpu)
103 u64 msr_vp_index; 103 u64 msr_vp_index;
104 struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()]; 104 struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()];
105 void **input_arg; 105 void **input_arg;
106 struct page *pg;
106 107
107 input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); 108 input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
108 *input_arg = page_address(alloc_page(GFP_KERNEL)); 109 pg = alloc_page(GFP_KERNEL);
110 if (unlikely(!pg))
111 return -ENOMEM;
112 *input_arg = page_address(pg);
109 113
110 hv_get_vp_index(msr_vp_index); 114 hv_get_vp_index(msr_vp_index);
111 115
diff --git a/arch/x86/include/asm/cpu_device_id.h b/arch/x86/include/asm/cpu_device_id.h
index 3417110574c1..31c379c1da41 100644
--- a/arch/x86/include/asm/cpu_device_id.h
+++ b/arch/x86/include/asm/cpu_device_id.h
@@ -1,6 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _CPU_DEVICE_ID 2#ifndef _ASM_X86_CPU_DEVICE_ID
3#define _CPU_DEVICE_ID 1 3#define _ASM_X86_CPU_DEVICE_ID
4 4
5/* 5/*
6 * Declare drivers belonging to specific x86 CPUs 6 * Declare drivers belonging to specific x86 CPUs
@@ -9,8 +9,6 @@
9 9
10#include <linux/mod_devicetable.h> 10#include <linux/mod_devicetable.h>
11 11
12extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
13
14/* 12/*
15 * Match specific microcode revisions. 13 * Match specific microcode revisions.
16 * 14 *
@@ -22,21 +20,22 @@ extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
22 */ 20 */
23 21
24struct x86_cpu_desc { 22struct x86_cpu_desc {
25 __u8 x86_family; 23 u8 x86_family;
26 __u8 x86_vendor; 24 u8 x86_vendor;
27 __u8 x86_model; 25 u8 x86_model;
28 __u8 x86_stepping; 26 u8 x86_stepping;
29 __u32 x86_microcode_rev; 27 u32 x86_microcode_rev;
30}; 28};
31 29
32#define INTEL_CPU_DESC(mod, step, rev) { \ 30#define INTEL_CPU_DESC(model, stepping, revision) { \
33 .x86_family = 6, \ 31 .x86_family = 6, \
34 .x86_vendor = X86_VENDOR_INTEL, \ 32 .x86_vendor = X86_VENDOR_INTEL, \
35 .x86_model = mod, \ 33 .x86_model = (model), \
36 .x86_stepping = step, \ 34 .x86_stepping = (stepping), \
37 .x86_microcode_rev = rev, \ 35 .x86_microcode_rev = (revision), \
38} 36}
39 37
38extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
40extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table); 39extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table);
41 40
42#endif 41#endif /* _ASM_X86_CPU_DEVICE_ID */
diff --git a/arch/x86/include/asm/processor-cyrix.h b/arch/x86/include/asm/processor-cyrix.h
index aaedd73ea2c6..df700a6cc869 100644
--- a/arch/x86/include/asm/processor-cyrix.h
+++ b/arch/x86/include/asm/processor-cyrix.h
@@ -3,19 +3,6 @@
3 * NSC/Cyrix CPU indexed register access. Must be inlined instead of 3 * NSC/Cyrix CPU indexed register access. Must be inlined instead of
4 * macros to ensure correct access ordering 4 * macros to ensure correct access ordering
5 * Access order is always 0x22 (=offset), 0x23 (=value) 5 * Access order is always 0x22 (=offset), 0x23 (=value)
6 *
7 * When using the old macros a line like
8 * setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
9 * gets expanded to:
10 * do {
11 * outb((CX86_CCR2), 0x22);
12 * outb((({
13 * outb((CX86_CCR2), 0x22);
14 * inb(0x23);
15 * }) | 0x88), 0x23);
16 * } while (0);
17 *
18 * which in fact violates the access order (= 0x22, 0x22, 0x23, 0x23).
19 */ 6 */
20 7
21static inline u8 getCx86(u8 reg) 8static inline u8 getCx86(u8 reg)
@@ -29,11 +16,3 @@ static inline void setCx86(u8 reg, u8 data)
29 outb(reg, 0x22); 16 outb(reg, 0x22);
30 outb(data, 0x23); 17 outb(data, 0x23);
31} 18}
32
33#define getCx86_old(reg) ({ outb((reg), 0x22); inb(0x23); })
34
35#define setCx86_old(reg, data) do { \
36 outb((reg), 0x22); \
37 outb((data), 0x23); \
38} while (0)
39
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index 58176b56354e..294ed4392a0e 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -14,6 +14,7 @@
14#define pr_fmt(fmt) "AGP: " fmt 14#define pr_fmt(fmt) "AGP: " fmt
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/kcore.h>
17#include <linux/types.h> 18#include <linux/types.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/memblock.h> 20#include <linux/memblock.h>
@@ -57,7 +58,7 @@ int fallback_aper_force __initdata;
57 58
58int fix_aperture __initdata = 1; 59int fix_aperture __initdata = 1;
59 60
60#ifdef CONFIG_PROC_VMCORE 61#if defined(CONFIG_PROC_VMCORE) || defined(CONFIG_PROC_KCORE)
61/* 62/*
62 * If the first kernel maps the aperture over e820 RAM, the kdump kernel will 63 * If the first kernel maps the aperture over e820 RAM, the kdump kernel will
63 * use the same range because it will remain configured in the northbridge. 64 * use the same range because it will remain configured in the northbridge.
@@ -66,20 +67,25 @@ int fix_aperture __initdata = 1;
66 */ 67 */
67static unsigned long aperture_pfn_start, aperture_page_count; 68static unsigned long aperture_pfn_start, aperture_page_count;
68 69
69static int gart_oldmem_pfn_is_ram(unsigned long pfn) 70static int gart_mem_pfn_is_ram(unsigned long pfn)
70{ 71{
71 return likely((pfn < aperture_pfn_start) || 72 return likely((pfn < aperture_pfn_start) ||
72 (pfn >= aperture_pfn_start + aperture_page_count)); 73 (pfn >= aperture_pfn_start + aperture_page_count));
73} 74}
74 75
75static void exclude_from_vmcore(u64 aper_base, u32 aper_order) 76static void __init exclude_from_core(u64 aper_base, u32 aper_order)
76{ 77{
77 aperture_pfn_start = aper_base >> PAGE_SHIFT; 78 aperture_pfn_start = aper_base >> PAGE_SHIFT;
78 aperture_page_count = (32 * 1024 * 1024) << aper_order >> PAGE_SHIFT; 79 aperture_page_count = (32 * 1024 * 1024) << aper_order >> PAGE_SHIFT;
79 WARN_ON(register_oldmem_pfn_is_ram(&gart_oldmem_pfn_is_ram)); 80#ifdef CONFIG_PROC_VMCORE
81 WARN_ON(register_oldmem_pfn_is_ram(&gart_mem_pfn_is_ram));
82#endif
83#ifdef CONFIG_PROC_KCORE
84 WARN_ON(register_mem_pfn_is_ram(&gart_mem_pfn_is_ram));
85#endif
80} 86}
81#else 87#else
82static void exclude_from_vmcore(u64 aper_base, u32 aper_order) 88static void exclude_from_core(u64 aper_base, u32 aper_order)
83{ 89{
84} 90}
85#endif 91#endif
@@ -474,7 +480,7 @@ out:
474 * may have allocated the range over its e820 RAM 480 * may have allocated the range over its e820 RAM
475 * and fixed up the northbridge 481 * and fixed up the northbridge
476 */ 482 */
477 exclude_from_vmcore(last_aper_base, last_aper_order); 483 exclude_from_core(last_aper_base, last_aper_order);
478 484
479 return 1; 485 return 1;
480 } 486 }
@@ -520,7 +526,7 @@ out:
520 * overlap with the first kernel's memory. We can't access the 526 * overlap with the first kernel's memory. We can't access the
521 * range through vmcore even though it should be part of the dump. 527 * range through vmcore even though it should be part of the dump.
522 */ 528 */
523 exclude_from_vmcore(aper_alloc, aper_order); 529 exclude_from_core(aper_alloc, aper_order);
524 530
525 /* Fix up the north bridges */ 531 /* Fix up the north bridges */
526 for (i = 0; i < amd_nb_bus_dev_ranges[i].dev_limit; i++) { 532 for (i = 0; i < amd_nb_bus_dev_ranges[i].dev_limit; i++) {
diff --git a/arch/x86/kernel/cpu/cyrix.c b/arch/x86/kernel/cpu/cyrix.c
index d12226f60168..1d9b8aaea06c 100644
--- a/arch/x86/kernel/cpu/cyrix.c
+++ b/arch/x86/kernel/cpu/cyrix.c
@@ -124,7 +124,7 @@ static void set_cx86_reorder(void)
124 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */ 124 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
125 125
126 /* Load/Store Serialize to mem access disable (=reorder it) */ 126 /* Load/Store Serialize to mem access disable (=reorder it) */
127 setCx86_old(CX86_PCR0, getCx86_old(CX86_PCR0) & ~0x80); 127 setCx86(CX86_PCR0, getCx86(CX86_PCR0) & ~0x80);
128 /* set load/store serialize from 1GB to 4GB */ 128 /* set load/store serialize from 1GB to 4GB */
129 ccr3 |= 0xe0; 129 ccr3 |= 0xe0;
130 setCx86(CX86_CCR3, ccr3); 130 setCx86(CX86_CCR3, ccr3);
@@ -135,11 +135,11 @@ static void set_cx86_memwb(void)
135 pr_info("Enable Memory-Write-back mode on Cyrix/NSC processor.\n"); 135 pr_info("Enable Memory-Write-back mode on Cyrix/NSC processor.\n");
136 136
137 /* CCR2 bit 2: unlock NW bit */ 137 /* CCR2 bit 2: unlock NW bit */
138 setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) & ~0x04); 138 setCx86(CX86_CCR2, getCx86(CX86_CCR2) & ~0x04);
139 /* set 'Not Write-through' */ 139 /* set 'Not Write-through' */
140 write_cr0(read_cr0() | X86_CR0_NW); 140 write_cr0(read_cr0() | X86_CR0_NW);
141 /* CCR2 bit 2: lock NW bit and set WT1 */ 141 /* CCR2 bit 2: lock NW bit and set WT1 */
142 setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x14); 142 setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x14);
143} 143}
144 144
145/* 145/*
@@ -153,14 +153,14 @@ static void geode_configure(void)
153 local_irq_save(flags); 153 local_irq_save(flags);
154 154
155 /* Suspend on halt power saving and enable #SUSP pin */ 155 /* Suspend on halt power saving and enable #SUSP pin */
156 setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x88); 156 setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
157 157
158 ccr3 = getCx86(CX86_CCR3); 158 ccr3 = getCx86(CX86_CCR3);
159 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */ 159 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
160 160
161 161
162 /* FPU fast, DTE cache, Mem bypass */ 162 /* FPU fast, DTE cache, Mem bypass */
163 setCx86_old(CX86_CCR4, getCx86_old(CX86_CCR4) | 0x38); 163 setCx86(CX86_CCR4, getCx86(CX86_CCR4) | 0x38);
164 setCx86(CX86_CCR3, ccr3); /* disable MAPEN */ 164 setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
165 165
166 set_cx86_memwb(); 166 set_cx86_memwb();
@@ -296,7 +296,7 @@ static void init_cyrix(struct cpuinfo_x86 *c)
296 /* GXm supports extended cpuid levels 'ala' AMD */ 296 /* GXm supports extended cpuid levels 'ala' AMD */
297 if (c->cpuid_level == 2) { 297 if (c->cpuid_level == 2) {
298 /* Enable cxMMX extensions (GX1 Datasheet 54) */ 298 /* Enable cxMMX extensions (GX1 Datasheet 54) */
299 setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7) | 1); 299 setCx86(CX86_CCR7, getCx86(CX86_CCR7) | 1);
300 300
301 /* 301 /*
302 * GXm : 0x30 ... 0x5f GXm datasheet 51 302 * GXm : 0x30 ... 0x5f GXm datasheet 51
@@ -319,7 +319,7 @@ static void init_cyrix(struct cpuinfo_x86 *c)
319 if (dir1 > 7) { 319 if (dir1 > 7) {
320 dir0_msn++; /* M II */ 320 dir0_msn++; /* M II */
321 /* Enable MMX extensions (App note 108) */ 321 /* Enable MMX extensions (App note 108) */
322 setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7)|1); 322 setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
323 } else { 323 } else {
324 /* A 6x86MX - it has the bug. */ 324 /* A 6x86MX - it has the bug. */
325 set_cpu_bug(c, X86_BUG_COMA); 325 set_cpu_bug(c, X86_BUG_COMA);
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index 97f9ada9ceda..5260185cbf7b 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -608,6 +608,8 @@ static int microcode_reload_late(void)
608 if (ret > 0) 608 if (ret > 0)
609 microcode_check(); 609 microcode_check();
610 610
611 pr_info("Reload completed, microcode revision: 0x%x\n", boot_cpu_data.microcode);
612
611 return ret; 613 return ret;
612} 614}
613 615
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index dfd3aca82c61..fb32925a2e62 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -905,6 +905,8 @@ int __init hpet_enable(void)
905 return 0; 905 return 0;
906 906
907 hpet_set_mapping(); 907 hpet_set_mapping();
908 if (!hpet_virt_address)
909 return 0;
908 910
909 /* 911 /*
910 * Read the period and check for a sane value: 912 * Read the period and check for a sane value:
diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index ff9bfd40429e..d73083021002 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
354#endif 354#endif
355 default: 355 default:
356 WARN_ON_ONCE(1); 356 WARN_ON_ONCE(1);
357 return -EINVAL;
357 } 358 }
358 359
359 /* 360 /*
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c
index 3482460d984d..1bfe5c6e6cfe 100644
--- a/arch/x86/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse.c
@@ -598,8 +598,8 @@ static int __init smp_scan_config(unsigned long base, unsigned long length)
598 mpf_base = base; 598 mpf_base = base;
599 mpf_found = true; 599 mpf_found = true;
600 600
601 pr_info("found SMP MP-table at [mem %#010lx-%#010lx] mapped at [%p]\n", 601 pr_info("found SMP MP-table at [mem %#010lx-%#010lx]\n",
602 base, base + sizeof(*mpf) - 1, mpf); 602 base, base + sizeof(*mpf) - 1);
603 603
604 memblock_reserve(base, sizeof(*mpf)); 604 memblock_reserve(base, sizeof(*mpf));
605 if (mpf->physptr) 605 if (mpf->physptr)
diff --git a/arch/x86/lib/csum-partial_64.c b/arch/x86/lib/csum-partial_64.c
index 9baca3e054be..e7925d668b68 100644
--- a/arch/x86/lib/csum-partial_64.c
+++ b/arch/x86/lib/csum-partial_64.c
@@ -94,7 +94,7 @@ static unsigned do_csum(const unsigned char *buff, unsigned len)
94 : "m" (*(unsigned long *)buff), 94 : "m" (*(unsigned long *)buff),
95 "r" (zero), "0" (result)); 95 "r" (zero), "0" (result));
96 --count; 96 --count;
97 buff += 8; 97 buff += 8;
98 } 98 }
99 result = add32_with_carry(result>>32, 99 result = add32_with_carry(result>>32,
100 result&0xffffffff); 100 result&0xffffffff);
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 4fee5c3003ed..139b28a01ce4 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -77,7 +77,7 @@ static void __init pti_print_if_secure(const char *reason)
77 pr_info("%s\n", reason); 77 pr_info("%s\n", reason);
78} 78}
79 79
80enum pti_mode { 80static enum pti_mode {
81 PTI_AUTO = 0, 81 PTI_AUTO = 0,
82 PTI_FORCE_OFF, 82 PTI_FORCE_OFF,
83 PTI_FORCE_ON 83 PTI_FORCE_ON
@@ -602,7 +602,7 @@ static void pti_clone_kernel_text(void)
602 set_memory_global(start, (end_global - start) >> PAGE_SHIFT); 602 set_memory_global(start, (end_global - start) >> PAGE_SHIFT);
603} 603}
604 604
605void pti_set_kernel_image_nonglobal(void) 605static void pti_set_kernel_image_nonglobal(void)
606{ 606{
607 /* 607 /*
608 * The identity map is created with PMDs, regardless of the 608 * The identity map is created with PMDs, regardless of the
diff --git a/block/bio.c b/block/bio.c
index 71a78d9fb8b7..b64cedc7f87c 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -849,20 +849,14 @@ static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter)
849 size = bio_add_page(bio, bv->bv_page, len, 849 size = bio_add_page(bio, bv->bv_page, len,
850 bv->bv_offset + iter->iov_offset); 850 bv->bv_offset + iter->iov_offset);
851 if (size == len) { 851 if (size == len) {
852 struct page *page; 852 if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
853 int i; 853 struct page *page;
854 int i;
855
856 mp_bvec_for_each_page(page, bv, i)
857 get_page(page);
858 }
854 859
855 /*
856 * For the normal O_DIRECT case, we could skip grabbing this
857 * reference and then not have to put them again when IO
858 * completes. But this breaks some in-kernel users, like
859 * splicing to/from a loop device, where we release the pipe
860 * pages unconditionally. If we can fix that case, we can
861 * get rid of the get here and the need to call
862 * bio_release_pages() at IO completion time.
863 */
864 mp_bvec_for_each_page(page, bv, i)
865 get_page(page);
866 iov_iter_advance(iter, size); 860 iov_iter_advance(iter, size);
867 return 0; 861 return 0;
868 } 862 }
@@ -925,10 +919,12 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
925 * This takes either an iterator pointing to user memory, or one pointing to 919 * This takes either an iterator pointing to user memory, or one pointing to
926 * kernel pages (BVEC iterator). If we're adding user pages, we pin them and 920 * kernel pages (BVEC iterator). If we're adding user pages, we pin them and
927 * map them into the kernel. On IO completion, the caller should put those 921 * map them into the kernel. On IO completion, the caller should put those
928 * pages. For now, when adding kernel pages, we still grab a reference to the 922 * pages. If we're adding kernel pages, and the caller told us it's safe to
929 * page. This isn't strictly needed for the common case, but some call paths 923 * do so, we just have to add the pages to the bio directly. We don't grab an
930 * end up releasing pages from eg a pipe and we can't easily control these. 924 * extra reference to those pages (the user should already have that), and we
931 * See comment in __bio_iov_bvec_add_pages(). 925 * don't put the page on IO completion. The caller needs to check if the bio is
926 * flagged BIO_NO_PAGE_REF on IO completion. If it isn't, then pages should be
927 * released.
932 * 928 *
933 * The function tries, but does not guarantee, to pin as many pages as 929 * The function tries, but does not guarantee, to pin as many pages as
934 * fit into the bio, or are requested in *iter, whatever is smaller. If 930 * fit into the bio, or are requested in *iter, whatever is smaller. If
@@ -940,6 +936,13 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
940 const bool is_bvec = iov_iter_is_bvec(iter); 936 const bool is_bvec = iov_iter_is_bvec(iter);
941 unsigned short orig_vcnt = bio->bi_vcnt; 937 unsigned short orig_vcnt = bio->bi_vcnt;
942 938
939 /*
940 * If this is a BVEC iter, then the pages are kernel pages. Don't
941 * release them on IO completion, if the caller asked us to.
942 */
943 if (is_bvec && iov_iter_bvec_no_ref(iter))
944 bio_set_flag(bio, BIO_NO_PAGE_REF);
945
943 do { 946 do {
944 int ret; 947 int ret;
945 948
@@ -1696,7 +1699,8 @@ static void bio_dirty_fn(struct work_struct *work)
1696 next = bio->bi_private; 1699 next = bio->bi_private;
1697 1700
1698 bio_set_pages_dirty(bio); 1701 bio_set_pages_dirty(bio);
1699 bio_release_pages(bio); 1702 if (!bio_flagged(bio, BIO_NO_PAGE_REF))
1703 bio_release_pages(bio);
1700 bio_put(bio); 1704 bio_put(bio);
1701 } 1705 }
1702} 1706}
@@ -1713,7 +1717,8 @@ void bio_check_pages_dirty(struct bio *bio)
1713 goto defer; 1717 goto defer;
1714 } 1718 }
1715 1719
1716 bio_release_pages(bio); 1720 if (!bio_flagged(bio, BIO_NO_PAGE_REF))
1721 bio_release_pages(bio);
1717 bio_put(bio); 1722 bio_put(bio);
1718 return; 1723 return;
1719defer: 1724defer:
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 77f37ef8ef06..617a2b3f7582 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1736,8 +1736,8 @@ out:
1736 1736
1737/** 1737/**
1738 * blkcg_schedule_throttle - this task needs to check for throttling 1738 * blkcg_schedule_throttle - this task needs to check for throttling
1739 * @q - the request queue IO was submitted on 1739 * @q: the request queue IO was submitted on
1740 * @use_memdelay - do we charge this to memory delay for PSI 1740 * @use_memdelay: do we charge this to memory delay for PSI
1741 * 1741 *
1742 * This is called by the IO controller when we know there's delay accumulated 1742 * This is called by the IO controller when we know there's delay accumulated
1743 * for the blkg for this task. We do not pass the blkg because there are places 1743 * for the blkg for this task. We do not pass the blkg because there are places
@@ -1769,8 +1769,9 @@ void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay)
1769 1769
1770/** 1770/**
1771 * blkcg_add_delay - add delay to this blkg 1771 * blkcg_add_delay - add delay to this blkg
1772 * @now - the current time in nanoseconds 1772 * @blkg: blkg of interest
1773 * @delta - how many nanoseconds of delay to add 1773 * @now: the current time in nanoseconds
1774 * @delta: how many nanoseconds of delay to add
1774 * 1775 *
1775 * Charge @delta to the blkg's current delay accumulation. This is used to 1776 * Charge @delta to the blkg's current delay accumulation. This is used to
1776 * throttle tasks if an IO controller thinks we need more throttling. 1777 * throttle tasks if an IO controller thinks we need more throttling.
diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c
index 2620baa1f699..507212d75ee2 100644
--- a/block/blk-iolatency.c
+++ b/block/blk-iolatency.c
@@ -75,6 +75,7 @@
75#include <linux/blk-mq.h> 75#include <linux/blk-mq.h>
76#include "blk-rq-qos.h" 76#include "blk-rq-qos.h"
77#include "blk-stat.h" 77#include "blk-stat.h"
78#include "blk.h"
78 79
79#define DEFAULT_SCALE_COOKIE 1000000U 80#define DEFAULT_SCALE_COOKIE 1000000U
80 81
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a9c181603cbd..70b210a308c4 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -782,7 +782,6 @@ void blk_mq_add_to_requeue_list(struct request *rq, bool at_head,
782 if (kick_requeue_list) 782 if (kick_requeue_list)
783 blk_mq_kick_requeue_list(q); 783 blk_mq_kick_requeue_list(q);
784} 784}
785EXPORT_SYMBOL(blk_mq_add_to_requeue_list);
786 785
787void blk_mq_kick_requeue_list(struct request_queue *q) 786void blk_mq_kick_requeue_list(struct request_queue *q)
788{ 787{
@@ -1093,8 +1092,7 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
1093 bool ret; 1092 bool ret;
1094 1093
1095 if (!(hctx->flags & BLK_MQ_F_TAG_SHARED)) { 1094 if (!(hctx->flags & BLK_MQ_F_TAG_SHARED)) {
1096 if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state)) 1095 blk_mq_sched_mark_restart_hctx(hctx);
1097 set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
1098 1096
1099 /* 1097 /*
1100 * It's possible that a tag was freed in the window between the 1098 * It's possible that a tag was freed in the window between the
@@ -2857,7 +2855,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
2857 /* 2855 /*
2858 * Default to classic polling 2856 * Default to classic polling
2859 */ 2857 */
2860 q->poll_nsec = -1; 2858 q->poll_nsec = BLK_MQ_POLL_CLASSIC;
2861 2859
2862 blk_mq_init_cpu_queues(q, set->nr_hw_queues); 2860 blk_mq_init_cpu_queues(q, set->nr_hw_queues);
2863 blk_mq_add_queue_tag_set(set, q); 2861 blk_mq_add_queue_tag_set(set, q);
@@ -3392,7 +3390,7 @@ static bool blk_mq_poll_hybrid(struct request_queue *q,
3392{ 3390{
3393 struct request *rq; 3391 struct request *rq;
3394 3392
3395 if (q->poll_nsec == -1) 3393 if (q->poll_nsec == BLK_MQ_POLL_CLASSIC)
3396 return false; 3394 return false;
3397 3395
3398 if (!blk_qc_t_is_internal(cookie)) 3396 if (!blk_qc_t_is_internal(cookie))
diff --git a/block/blk-mq.h b/block/blk-mq.h
index c11353a3749d..0ed8e5a8729f 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -41,6 +41,8 @@ void blk_mq_free_queue(struct request_queue *q);
41int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr); 41int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr);
42void blk_mq_wake_waiters(struct request_queue *q); 42void blk_mq_wake_waiters(struct request_queue *q);
43bool blk_mq_dispatch_rq_list(struct request_queue *, struct list_head *, bool); 43bool blk_mq_dispatch_rq_list(struct request_queue *, struct list_head *, bool);
44void blk_mq_add_to_requeue_list(struct request *rq, bool at_head,
45 bool kick_requeue_list);
44void blk_mq_flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list); 46void blk_mq_flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list);
45bool blk_mq_get_driver_tag(struct request *rq); 47bool blk_mq_get_driver_tag(struct request *rq);
46struct request *blk_mq_dequeue_from_ctx(struct blk_mq_hw_ctx *hctx, 48struct request *blk_mq_dequeue_from_ctx(struct blk_mq_hw_ctx *hctx,
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 59685918167e..422327089e0f 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -360,8 +360,8 @@ static ssize_t queue_poll_delay_show(struct request_queue *q, char *page)
360{ 360{
361 int val; 361 int val;
362 362
363 if (q->poll_nsec == -1) 363 if (q->poll_nsec == BLK_MQ_POLL_CLASSIC)
364 val = -1; 364 val = BLK_MQ_POLL_CLASSIC;
365 else 365 else
366 val = q->poll_nsec / 1000; 366 val = q->poll_nsec / 1000;
367 367
@@ -380,10 +380,12 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page,
380 if (err < 0) 380 if (err < 0)
381 return err; 381 return err;
382 382
383 if (val == -1) 383 if (val == BLK_MQ_POLL_CLASSIC)
384 q->poll_nsec = -1; 384 q->poll_nsec = BLK_MQ_POLL_CLASSIC;
385 else 385 else if (val >= 0)
386 q->poll_nsec = val * 1000; 386 q->poll_nsec = val * 1000;
387 else
388 return -EINVAL;
387 389
388 return count; 390 return count;
389} 391}
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 78db97687f26..c4b06cc075f9 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -800,6 +800,7 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
800 match.hrv = hrv; 800 match.hrv = hrv;
801 801
802 dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb); 802 dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
803 put_device(dev);
803 return !!dev; 804 return !!dev;
804} 805}
805EXPORT_SYMBOL(acpi_dev_present); 806EXPORT_SYMBOL(acpi_dev_present);
diff --git a/drivers/auxdisplay/Kconfig b/drivers/auxdisplay/Kconfig
index 57410f9c5d44..c52c738e554a 100644
--- a/drivers/auxdisplay/Kconfig
+++ b/drivers/auxdisplay/Kconfig
@@ -164,9 +164,7 @@ config ARM_CHARLCD
164 line and the Linux version on the second line, but that's 164 line and the Linux version on the second line, but that's
165 still useful. 165 still useful.
166 166
167endif # AUXDISPLAY 167menuconfig PARPORT_PANEL
168
169menuconfig PANEL
170 tristate "Parallel port LCD/Keypad Panel support" 168 tristate "Parallel port LCD/Keypad Panel support"
171 depends on PARPORT 169 depends on PARPORT
172 select CHARLCD 170 select CHARLCD
@@ -178,7 +176,7 @@ menuconfig PANEL
178 compiled as a module, or linked into the kernel and started at boot. 176 compiled as a module, or linked into the kernel and started at boot.
179 If you don't understand what all this is about, say N. 177 If you don't understand what all this is about, say N.
180 178
181if PANEL 179if PARPORT_PANEL
182 180
183config PANEL_PARPORT 181config PANEL_PARPORT
184 int "Default parallel port number (0=LPT1)" 182 int "Default parallel port number (0=LPT1)"
@@ -419,8 +417,11 @@ config PANEL_LCD_PIN_BL
419 417
420 Default for the 'BL' pin in custom profile is '0' (uncontrolled). 418 Default for the 'BL' pin in custom profile is '0' (uncontrolled).
421 419
420endif # PARPORT_PANEL
421
422config PANEL_CHANGE_MESSAGE 422config PANEL_CHANGE_MESSAGE
423 bool "Change LCD initialization message ?" 423 bool "Change LCD initialization message ?"
424 depends on CHARLCD
424 default "n" 425 default "n"
425 ---help--- 426 ---help---
426 This allows you to replace the boot message indicating the kernel version 427 This allows you to replace the boot message indicating the kernel version
@@ -444,7 +445,34 @@ config PANEL_BOOT_MESSAGE
444 An empty message will only clear the display at driver init time. Any other 445 An empty message will only clear the display at driver init time. Any other
445 printf()-formatted message is valid with newline and escape codes. 446 printf()-formatted message is valid with newline and escape codes.
446 447
447endif # PANEL 448choice
449 prompt "Backlight initial state"
450 default CHARLCD_BL_FLASH
451
452 config CHARLCD_BL_OFF
453 bool "Off"
454 help
455 Backlight is initially turned off
456
457 config CHARLCD_BL_ON
458 bool "On"
459 help
460 Backlight is initially turned on
461
462 config CHARLCD_BL_FLASH
463 bool "Flash"
464 help
465 Backlight is flashed briefly on init
466
467endchoice
468
469endif # AUXDISPLAY
470
471config PANEL
472 tristate "Parallel port LCD/Keypad Panel support (OLD OPTION)"
473 depends on PARPORT
474 select AUXDISPLAY
475 select PARPORT_PANEL
448 476
449config CHARLCD 477config CHARLCD
450 tristate "Character LCD core support" if COMPILE_TEST 478 tristate "Character LCD core support" if COMPILE_TEST
diff --git a/drivers/auxdisplay/Makefile b/drivers/auxdisplay/Makefile
index 7ac6776ca3f6..cf54b5efb07e 100644
--- a/drivers/auxdisplay/Makefile
+++ b/drivers/auxdisplay/Makefile
@@ -10,4 +10,4 @@ obj-$(CONFIG_CFAG12864B) += cfag12864b.o cfag12864bfb.o
10obj-$(CONFIG_IMG_ASCII_LCD) += img-ascii-lcd.o 10obj-$(CONFIG_IMG_ASCII_LCD) += img-ascii-lcd.o
11obj-$(CONFIG_HD44780) += hd44780.o 11obj-$(CONFIG_HD44780) += hd44780.o
12obj-$(CONFIG_HT16K33) += ht16k33.o 12obj-$(CONFIG_HT16K33) += ht16k33.o
13obj-$(CONFIG_PANEL) += panel.o 13obj-$(CONFIG_PARPORT_PANEL) += panel.o
diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c
index 60e0b772673f..92745efefb54 100644
--- a/drivers/auxdisplay/charlcd.c
+++ b/drivers/auxdisplay/charlcd.c
@@ -91,7 +91,7 @@ struct charlcd_priv {
91 unsigned long long drvdata[0]; 91 unsigned long long drvdata[0];
92}; 92};
93 93
94#define to_priv(p) container_of(p, struct charlcd_priv, lcd) 94#define charlcd_to_priv(p) container_of(p, struct charlcd_priv, lcd)
95 95
96/* Device single-open policy control */ 96/* Device single-open policy control */
97static atomic_t charlcd_available = ATOMIC_INIT(1); 97static atomic_t charlcd_available = ATOMIC_INIT(1);
@@ -105,7 +105,7 @@ static void long_sleep(int ms)
105/* turn the backlight on or off */ 105/* turn the backlight on or off */
106static void charlcd_backlight(struct charlcd *lcd, int on) 106static void charlcd_backlight(struct charlcd *lcd, int on)
107{ 107{
108 struct charlcd_priv *priv = to_priv(lcd); 108 struct charlcd_priv *priv = charlcd_to_priv(lcd);
109 109
110 if (!lcd->ops->backlight) 110 if (!lcd->ops->backlight)
111 return; 111 return;
@@ -134,7 +134,7 @@ static void charlcd_bl_off(struct work_struct *work)
134/* turn the backlight on for a little while */ 134/* turn the backlight on for a little while */
135void charlcd_poke(struct charlcd *lcd) 135void charlcd_poke(struct charlcd *lcd)
136{ 136{
137 struct charlcd_priv *priv = to_priv(lcd); 137 struct charlcd_priv *priv = charlcd_to_priv(lcd);
138 138
139 if (!lcd->ops->backlight) 139 if (!lcd->ops->backlight)
140 return; 140 return;
@@ -152,7 +152,7 @@ EXPORT_SYMBOL_GPL(charlcd_poke);
152 152
153static void charlcd_gotoxy(struct charlcd *lcd) 153static void charlcd_gotoxy(struct charlcd *lcd)
154{ 154{
155 struct charlcd_priv *priv = to_priv(lcd); 155 struct charlcd_priv *priv = charlcd_to_priv(lcd);
156 unsigned int addr; 156 unsigned int addr;
157 157
158 /* 158 /*
@@ -170,7 +170,7 @@ static void charlcd_gotoxy(struct charlcd *lcd)
170 170
171static void charlcd_home(struct charlcd *lcd) 171static void charlcd_home(struct charlcd *lcd)
172{ 172{
173 struct charlcd_priv *priv = to_priv(lcd); 173 struct charlcd_priv *priv = charlcd_to_priv(lcd);
174 174
175 priv->addr.x = 0; 175 priv->addr.x = 0;
176 priv->addr.y = 0; 176 priv->addr.y = 0;
@@ -179,7 +179,7 @@ static void charlcd_home(struct charlcd *lcd)
179 179
180static void charlcd_print(struct charlcd *lcd, char c) 180static void charlcd_print(struct charlcd *lcd, char c)
181{ 181{
182 struct charlcd_priv *priv = to_priv(lcd); 182 struct charlcd_priv *priv = charlcd_to_priv(lcd);
183 183
184 if (priv->addr.x < lcd->bwidth) { 184 if (priv->addr.x < lcd->bwidth) {
185 if (lcd->char_conv) 185 if (lcd->char_conv)
@@ -211,7 +211,7 @@ static void charlcd_clear_fast(struct charlcd *lcd)
211/* clears the display and resets X/Y */ 211/* clears the display and resets X/Y */
212static void charlcd_clear_display(struct charlcd *lcd) 212static void charlcd_clear_display(struct charlcd *lcd)
213{ 213{
214 struct charlcd_priv *priv = to_priv(lcd); 214 struct charlcd_priv *priv = charlcd_to_priv(lcd);
215 215
216 lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CLEAR); 216 lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CLEAR);
217 priv->addr.x = 0; 217 priv->addr.x = 0;
@@ -223,7 +223,7 @@ static void charlcd_clear_display(struct charlcd *lcd)
223static int charlcd_init_display(struct charlcd *lcd) 223static int charlcd_init_display(struct charlcd *lcd)
224{ 224{
225 void (*write_cmd_raw)(struct charlcd *lcd, int cmd); 225 void (*write_cmd_raw)(struct charlcd *lcd, int cmd);
226 struct charlcd_priv *priv = to_priv(lcd); 226 struct charlcd_priv *priv = charlcd_to_priv(lcd);
227 u8 init; 227 u8 init;
228 228
229 if (lcd->ifwidth != 4 && lcd->ifwidth != 8) 229 if (lcd->ifwidth != 4 && lcd->ifwidth != 8)
@@ -369,7 +369,7 @@ static bool parse_xy(const char *s, unsigned long *x, unsigned long *y)
369 369
370static inline int handle_lcd_special_code(struct charlcd *lcd) 370static inline int handle_lcd_special_code(struct charlcd *lcd)
371{ 371{
372 struct charlcd_priv *priv = to_priv(lcd); 372 struct charlcd_priv *priv = charlcd_to_priv(lcd);
373 373
374 /* LCD special codes */ 374 /* LCD special codes */
375 375
@@ -580,7 +580,7 @@ static inline int handle_lcd_special_code(struct charlcd *lcd)
580 580
581static void charlcd_write_char(struct charlcd *lcd, char c) 581static void charlcd_write_char(struct charlcd *lcd, char c)
582{ 582{
583 struct charlcd_priv *priv = to_priv(lcd); 583 struct charlcd_priv *priv = charlcd_to_priv(lcd);
584 584
585 /* first, we'll test if we're in escape mode */ 585 /* first, we'll test if we're in escape mode */
586 if ((c != '\n') && priv->esc_seq.len >= 0) { 586 if ((c != '\n') && priv->esc_seq.len >= 0) {
@@ -705,7 +705,7 @@ static ssize_t charlcd_write(struct file *file, const char __user *buf,
705 705
706static int charlcd_open(struct inode *inode, struct file *file) 706static int charlcd_open(struct inode *inode, struct file *file)
707{ 707{
708 struct charlcd_priv *priv = to_priv(the_charlcd); 708 struct charlcd_priv *priv = charlcd_to_priv(the_charlcd);
709 int ret; 709 int ret;
710 710
711 ret = -EBUSY; 711 ret = -EBUSY;
@@ -763,10 +763,24 @@ static void charlcd_puts(struct charlcd *lcd, const char *s)
763 } 763 }
764} 764}
765 765
766#ifdef CONFIG_PANEL_BOOT_MESSAGE
767#define LCD_INIT_TEXT CONFIG_PANEL_BOOT_MESSAGE
768#else
769#define LCD_INIT_TEXT "Linux-" UTS_RELEASE "\n"
770#endif
771
772#ifdef CONFIG_CHARLCD_BL_ON
773#define LCD_INIT_BL "\x1b[L+"
774#elif defined(CONFIG_CHARLCD_BL_FLASH)
775#define LCD_INIT_BL "\x1b[L*"
776#else
777#define LCD_INIT_BL "\x1b[L-"
778#endif
779
766/* initialize the LCD driver */ 780/* initialize the LCD driver */
767static int charlcd_init(struct charlcd *lcd) 781static int charlcd_init(struct charlcd *lcd)
768{ 782{
769 struct charlcd_priv *priv = to_priv(lcd); 783 struct charlcd_priv *priv = charlcd_to_priv(lcd);
770 int ret; 784 int ret;
771 785
772 if (lcd->ops->backlight) { 786 if (lcd->ops->backlight) {
@@ -784,13 +798,8 @@ static int charlcd_init(struct charlcd *lcd)
784 return ret; 798 return ret;
785 799
786 /* display a short message */ 800 /* display a short message */
787#ifdef CONFIG_PANEL_CHANGE_MESSAGE 801 charlcd_puts(lcd, "\x1b[Lc\x1b[Lb" LCD_INIT_BL LCD_INIT_TEXT);
788#ifdef CONFIG_PANEL_BOOT_MESSAGE 802
789 charlcd_puts(lcd, "\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
790#endif
791#else
792 charlcd_puts(lcd, "\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\n");
793#endif
794 /* clear the display on the next device opening */ 803 /* clear the display on the next device opening */
795 priv->must_clear = true; 804 priv->must_clear = true;
796 charlcd_home(lcd); 805 charlcd_home(lcd);
@@ -818,6 +827,12 @@ struct charlcd *charlcd_alloc(unsigned int drvdata_size)
818} 827}
819EXPORT_SYMBOL_GPL(charlcd_alloc); 828EXPORT_SYMBOL_GPL(charlcd_alloc);
820 829
830void charlcd_free(struct charlcd *lcd)
831{
832 kfree(charlcd_to_priv(lcd));
833}
834EXPORT_SYMBOL_GPL(charlcd_free);
835
821static int panel_notify_sys(struct notifier_block *this, unsigned long code, 836static int panel_notify_sys(struct notifier_block *this, unsigned long code,
822 void *unused) 837 void *unused)
823{ 838{
@@ -866,7 +881,7 @@ EXPORT_SYMBOL_GPL(charlcd_register);
866 881
867int charlcd_unregister(struct charlcd *lcd) 882int charlcd_unregister(struct charlcd *lcd)
868{ 883{
869 struct charlcd_priv *priv = to_priv(lcd); 884 struct charlcd_priv *priv = charlcd_to_priv(lcd);
870 885
871 unregister_reboot_notifier(&panel_notifier); 886 unregister_reboot_notifier(&panel_notifier);
872 charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-"); 887 charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-");
diff --git a/drivers/auxdisplay/hd44780.c b/drivers/auxdisplay/hd44780.c
index 9ad93ea42fdc..ab15b64707ad 100644
--- a/drivers/auxdisplay/hd44780.c
+++ b/drivers/auxdisplay/hd44780.c
@@ -271,7 +271,7 @@ static int hd44780_probe(struct platform_device *pdev)
271 return 0; 271 return 0;
272 272
273fail: 273fail:
274 kfree(lcd); 274 charlcd_free(lcd);
275 return ret; 275 return ret;
276} 276}
277 277
@@ -280,6 +280,8 @@ static int hd44780_remove(struct platform_device *pdev)
280 struct charlcd *lcd = platform_get_drvdata(pdev); 280 struct charlcd *lcd = platform_get_drvdata(pdev);
281 281
282 charlcd_unregister(lcd); 282 charlcd_unregister(lcd);
283
284 charlcd_free(lcd);
283 return 0; 285 return 0;
284} 286}
285 287
diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c
index 21b9b2f2470a..e06de63497cf 100644
--- a/drivers/auxdisplay/panel.c
+++ b/drivers/auxdisplay/panel.c
@@ -1620,7 +1620,7 @@ err_lcd_unreg:
1620 if (lcd.enabled) 1620 if (lcd.enabled)
1621 charlcd_unregister(lcd.charlcd); 1621 charlcd_unregister(lcd.charlcd);
1622err_unreg_device: 1622err_unreg_device:
1623 kfree(lcd.charlcd); 1623 charlcd_free(lcd.charlcd);
1624 lcd.charlcd = NULL; 1624 lcd.charlcd = NULL;
1625 parport_unregister_device(pprt); 1625 parport_unregister_device(pprt);
1626 pprt = NULL; 1626 pprt = NULL;
@@ -1647,7 +1647,7 @@ static void panel_detach(struct parport *port)
1647 if (lcd.enabled) { 1647 if (lcd.enabled) {
1648 charlcd_unregister(lcd.charlcd); 1648 charlcd_unregister(lcd.charlcd);
1649 lcd.initialized = false; 1649 lcd.initialized = false;
1650 kfree(lcd.charlcd); 1650 charlcd_free(lcd.charlcd);
1651 lcd.charlcd = NULL; 1651 lcd.charlcd = NULL;
1652 } 1652 }
1653 1653
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 76c9969b7124..96a6dc9d305c 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -1469,12 +1469,12 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1469 if (IS_ERR(gpd_data)) 1469 if (IS_ERR(gpd_data))
1470 return PTR_ERR(gpd_data); 1470 return PTR_ERR(gpd_data);
1471 1471
1472 genpd_lock(genpd);
1473
1474 ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; 1472 ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
1475 if (ret) 1473 if (ret)
1476 goto out; 1474 goto out;
1477 1475
1476 genpd_lock(genpd);
1477
1478 dev_pm_domain_set(dev, &genpd->domain); 1478 dev_pm_domain_set(dev, &genpd->domain);
1479 1479
1480 genpd->device_count++; 1480 genpd->device_count++;
@@ -1482,9 +1482,8 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1482 1482
1483 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); 1483 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
1484 1484
1485 out:
1486 genpd_unlock(genpd); 1485 genpd_unlock(genpd);
1487 1486 out:
1488 if (ret) 1487 if (ret)
1489 genpd_free_dev_data(dev, gpd_data); 1488 genpd_free_dev_data(dev, gpd_data);
1490 else 1489 else
@@ -1533,15 +1532,15 @@ static int genpd_remove_device(struct generic_pm_domain *genpd,
1533 genpd->device_count--; 1532 genpd->device_count--;
1534 genpd->max_off_time_changed = true; 1533 genpd->max_off_time_changed = true;
1535 1534
1536 if (genpd->detach_dev)
1537 genpd->detach_dev(genpd, dev);
1538
1539 dev_pm_domain_set(dev, NULL); 1535 dev_pm_domain_set(dev, NULL);
1540 1536
1541 list_del_init(&pdd->list_node); 1537 list_del_init(&pdd->list_node);
1542 1538
1543 genpd_unlock(genpd); 1539 genpd_unlock(genpd);
1544 1540
1541 if (genpd->detach_dev)
1542 genpd->detach_dev(genpd, dev);
1543
1545 genpd_free_dev_data(dev, gpd_data); 1544 genpd_free_dev_data(dev, gpd_data);
1546 1545
1547 return 0; 1546 return 0;
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 1fad9291f6aa..7fc5a18e02ad 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -472,7 +472,7 @@ static int software_node_read_string_array(const struct fwnode_handle *fwnode,
472 val, nval); 472 val, nval);
473} 473}
474 474
475struct fwnode_handle * 475static struct fwnode_handle *
476software_node_get_parent(const struct fwnode_handle *fwnode) 476software_node_get_parent(const struct fwnode_handle *fwnode)
477{ 477{
478 struct software_node *swnode = to_software_node(fwnode); 478 struct software_node *swnode = to_software_node(fwnode);
@@ -481,7 +481,7 @@ software_node_get_parent(const struct fwnode_handle *fwnode)
481 NULL; 481 NULL;
482} 482}
483 483
484struct fwnode_handle * 484static struct fwnode_handle *
485software_node_get_next_child(const struct fwnode_handle *fwnode, 485software_node_get_next_child(const struct fwnode_handle *fwnode,
486 struct fwnode_handle *child) 486 struct fwnode_handle *child)
487{ 487{
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 1e6edd568214..bf1c61cab8eb 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -656,7 +656,7 @@ static int loop_validate_file(struct file *file, struct block_device *bdev)
656 return -EBADF; 656 return -EBADF;
657 657
658 l = f->f_mapping->host->i_bdev->bd_disk->private_data; 658 l = f->f_mapping->host->i_bdev->bd_disk->private_data;
659 if (l->lo_state == Lo_unbound) { 659 if (l->lo_state != Lo_bound) {
660 return -EINVAL; 660 return -EINVAL;
661 } 661 }
662 f = l->lo_backing_file; 662 f = l->lo_backing_file;
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index 96670eefaeb2..377a694dc228 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -749,8 +749,12 @@ static int pcd_detect(void)
749 return 0; 749 return 0;
750 750
751 printk("%s: No CD-ROM drive found\n", name); 751 printk("%s: No CD-ROM drive found\n", name);
752 for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) 752 for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
753 blk_cleanup_queue(cd->disk->queue);
754 cd->disk->queue = NULL;
755 blk_mq_free_tag_set(&cd->tag_set);
753 put_disk(cd->disk); 756 put_disk(cd->disk);
757 }
754 pi_unregister_driver(par_drv); 758 pi_unregister_driver(par_drv);
755 return -1; 759 return -1;
756} 760}
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index e92e7a8eeeb2..103b617cdc31 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -761,8 +761,12 @@ static int pf_detect(void)
761 return 0; 761 return 0;
762 762
763 printk("%s: No ATAPI disk detected\n", name); 763 printk("%s: No ATAPI disk detected\n", name);
764 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) 764 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
765 blk_cleanup_queue(pf->disk->queue);
766 pf->disk->queue = NULL;
767 blk_mq_free_tag_set(&pf->tag_set);
765 put_disk(pf->disk); 768 put_disk(pf->disk);
769 }
766 pi_unregister_driver(par_drv); 770 pi_unregister_driver(par_drv);
767 return -1; 771 return -1;
768} 772}
@@ -1047,13 +1051,15 @@ static void __exit pf_exit(void)
1047 int unit; 1051 int unit;
1048 unregister_blkdev(major, name); 1052 unregister_blkdev(major, name);
1049 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { 1053 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
1050 if (!pf->present) 1054 if (pf->present)
1051 continue; 1055 del_gendisk(pf->disk);
1052 del_gendisk(pf->disk); 1056
1053 blk_cleanup_queue(pf->disk->queue); 1057 blk_cleanup_queue(pf->disk->queue);
1054 blk_mq_free_tag_set(&pf->tag_set); 1058 blk_mq_free_tag_set(&pf->tag_set);
1055 put_disk(pf->disk); 1059 put_disk(pf->disk);
1056 pi_release(pf->pi); 1060
1061 if (pf->present)
1062 pi_release(pf->pi);
1057 } 1063 }
1058} 1064}
1059 1065
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 4ba967d65cf9..2210c1b9491b 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -833,7 +833,7 @@ static int parse_rbd_opts_token(char *c, void *private)
833 pctx->opts->queue_depth = intval; 833 pctx->opts->queue_depth = intval;
834 break; 834 break;
835 case Opt_alloc_size: 835 case Opt_alloc_size:
836 if (intval < 1) { 836 if (intval < SECTOR_SIZE) {
837 pr_err("alloc_size out of range\n"); 837 pr_err("alloc_size out of range\n");
838 return -EINVAL; 838 return -EINVAL;
839 } 839 }
@@ -924,23 +924,6 @@ static void rbd_put_client(struct rbd_client *rbdc)
924 kref_put(&rbdc->kref, rbd_client_release); 924 kref_put(&rbdc->kref, rbd_client_release);
925} 925}
926 926
927static int wait_for_latest_osdmap(struct ceph_client *client)
928{
929 u64 newest_epoch;
930 int ret;
931
932 ret = ceph_monc_get_version(&client->monc, "osdmap", &newest_epoch);
933 if (ret)
934 return ret;
935
936 if (client->osdc.osdmap->epoch >= newest_epoch)
937 return 0;
938
939 ceph_osdc_maybe_request_map(&client->osdc);
940 return ceph_monc_wait_osdmap(&client->monc, newest_epoch,
941 client->options->mount_timeout);
942}
943
944/* 927/*
945 * Get a ceph client with specific addr and configuration, if one does 928 * Get a ceph client with specific addr and configuration, if one does
946 * not exist create it. Either way, ceph_opts is consumed by this 929 * not exist create it. Either way, ceph_opts is consumed by this
@@ -960,7 +943,8 @@ static struct rbd_client *rbd_get_client(struct ceph_options *ceph_opts)
960 * Using an existing client. Make sure ->pg_pools is up to 943 * Using an existing client. Make sure ->pg_pools is up to
961 * date before we look up the pool id in do_rbd_add(). 944 * date before we look up the pool id in do_rbd_add().
962 */ 945 */
963 ret = wait_for_latest_osdmap(rbdc->client); 946 ret = ceph_wait_for_latest_osdmap(rbdc->client,
947 rbdc->client->options->mount_timeout);
964 if (ret) { 948 if (ret) {
965 rbd_warn(NULL, "failed to get latest osdmap: %d", ret); 949 rbd_warn(NULL, "failed to get latest osdmap: %d", ret);
966 rbd_put_client(rbdc); 950 rbd_put_client(rbdc);
@@ -4203,12 +4187,12 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
4203 q->limits.max_sectors = queue_max_hw_sectors(q); 4187 q->limits.max_sectors = queue_max_hw_sectors(q);
4204 blk_queue_max_segments(q, USHRT_MAX); 4188 blk_queue_max_segments(q, USHRT_MAX);
4205 blk_queue_max_segment_size(q, UINT_MAX); 4189 blk_queue_max_segment_size(q, UINT_MAX);
4206 blk_queue_io_min(q, objset_bytes); 4190 blk_queue_io_min(q, rbd_dev->opts->alloc_size);
4207 blk_queue_io_opt(q, objset_bytes); 4191 blk_queue_io_opt(q, rbd_dev->opts->alloc_size);
4208 4192
4209 if (rbd_dev->opts->trim) { 4193 if (rbd_dev->opts->trim) {
4210 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q); 4194 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
4211 q->limits.discard_granularity = objset_bytes; 4195 q->limits.discard_granularity = rbd_dev->opts->alloc_size;
4212 blk_queue_max_discard_sectors(q, objset_bytes >> SECTOR_SHIFT); 4196 blk_queue_max_discard_sectors(q, objset_bytes >> SECTOR_SHIFT);
4213 blk_queue_max_write_zeroes_sectors(q, objset_bytes >> SECTOR_SHIFT); 4197 blk_queue_max_write_zeroes_sectors(q, objset_bytes >> SECTOR_SHIFT);
4214 } 4198 }
diff --git a/drivers/clocksource/clps711x-timer.c b/drivers/clocksource/clps711x-timer.c
index a8dd80576c95..857f8c086274 100644
--- a/drivers/clocksource/clps711x-timer.c
+++ b/drivers/clocksource/clps711x-timer.c
@@ -31,16 +31,9 @@ static u64 notrace clps711x_sched_clock_read(void)
31 return ~readw(tcd); 31 return ~readw(tcd);
32} 32}
33 33
34static int __init _clps711x_clksrc_init(struct clk *clock, void __iomem *base) 34static void __init clps711x_clksrc_init(struct clk *clock, void __iomem *base)
35{ 35{
36 unsigned long rate; 36 unsigned long rate = clk_get_rate(clock);
37
38 if (!base)
39 return -ENOMEM;
40 if (IS_ERR(clock))
41 return PTR_ERR(clock);
42
43 rate = clk_get_rate(clock);
44 37
45 tcd = base; 38 tcd = base;
46 39
@@ -48,8 +41,6 @@ static int __init _clps711x_clksrc_init(struct clk *clock, void __iomem *base)
48 clocksource_mmio_readw_down); 41 clocksource_mmio_readw_down);
49 42
50 sched_clock_register(clps711x_sched_clock_read, 16, rate); 43 sched_clock_register(clps711x_sched_clock_read, 16, rate);
51
52 return 0;
53} 44}
54 45
55static irqreturn_t clps711x_timer_interrupt(int irq, void *dev_id) 46static irqreturn_t clps711x_timer_interrupt(int irq, void *dev_id)
@@ -67,13 +58,6 @@ static int __init _clps711x_clkevt_init(struct clk *clock, void __iomem *base,
67 struct clock_event_device *clkevt; 58 struct clock_event_device *clkevt;
68 unsigned long rate; 59 unsigned long rate;
69 60
70 if (!irq)
71 return -EINVAL;
72 if (!base)
73 return -ENOMEM;
74 if (IS_ERR(clock))
75 return PTR_ERR(clock);
76
77 clkevt = kzalloc(sizeof(*clkevt), GFP_KERNEL); 61 clkevt = kzalloc(sizeof(*clkevt), GFP_KERNEL);
78 if (!clkevt) 62 if (!clkevt)
79 return -ENOMEM; 63 return -ENOMEM;
@@ -93,31 +77,29 @@ static int __init _clps711x_clkevt_init(struct clk *clock, void __iomem *base,
93 "clps711x-timer", clkevt); 77 "clps711x-timer", clkevt);
94} 78}
95 79
96void __init clps711x_clksrc_init(void __iomem *tc1_base, void __iomem *tc2_base,
97 unsigned int irq)
98{
99 struct clk *tc1 = clk_get_sys("clps711x-timer.0", NULL);
100 struct clk *tc2 = clk_get_sys("clps711x-timer.1", NULL);
101
102 BUG_ON(_clps711x_clksrc_init(tc1, tc1_base));
103 BUG_ON(_clps711x_clkevt_init(tc2, tc2_base, irq));
104}
105
106#ifdef CONFIG_TIMER_OF
107static int __init clps711x_timer_init(struct device_node *np) 80static int __init clps711x_timer_init(struct device_node *np)
108{ 81{
109 unsigned int irq = irq_of_parse_and_map(np, 0); 82 unsigned int irq = irq_of_parse_and_map(np, 0);
110 struct clk *clock = of_clk_get(np, 0); 83 struct clk *clock = of_clk_get(np, 0);
111 void __iomem *base = of_iomap(np, 0); 84 void __iomem *base = of_iomap(np, 0);
112 85
86 if (!base)
87 return -ENOMEM;
88 if (!irq)
89 return -EINVAL;
90 if (IS_ERR(clock))
91 return PTR_ERR(clock);
92
113 switch (of_alias_get_id(np, "timer")) { 93 switch (of_alias_get_id(np, "timer")) {
114 case CLPS711X_CLKSRC_CLOCKSOURCE: 94 case CLPS711X_CLKSRC_CLOCKSOURCE:
115 return _clps711x_clksrc_init(clock, base); 95 clps711x_clksrc_init(clock, base);
96 break;
116 case CLPS711X_CLKSRC_CLOCKEVENT: 97 case CLPS711X_CLKSRC_CLOCKEVENT:
117 return _clps711x_clkevt_init(clock, base, irq); 98 return _clps711x_clkevt_init(clock, base, irq);
118 default: 99 default:
119 return -EINVAL; 100 return -EINVAL;
120 } 101 }
102
103 return 0;
121} 104}
122TIMER_OF_DECLARE(clps711x, "cirrus,ep7209-timer", clps711x_timer_init); 105TIMER_OF_DECLARE(clps711x, "cirrus,ep7209-timer", clps711x_timer_init);
123#endif
diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c
index 54f8a331b53a..37671a5d4ed9 100644
--- a/drivers/clocksource/mips-gic-timer.c
+++ b/drivers/clocksource/mips-gic-timer.c
@@ -67,7 +67,7 @@ static irqreturn_t gic_compare_interrupt(int irq, void *dev_id)
67 return IRQ_HANDLED; 67 return IRQ_HANDLED;
68} 68}
69 69
70struct irqaction gic_compare_irqaction = { 70static struct irqaction gic_compare_irqaction = {
71 .handler = gic_compare_interrupt, 71 .handler = gic_compare_interrupt,
72 .percpu_dev_id = &gic_clockevent_device, 72 .percpu_dev_id = &gic_clockevent_device,
73 .flags = IRQF_PERCPU | IRQF_TIMER, 73 .flags = IRQF_PERCPU | IRQF_TIMER,
diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c
index 43f4d5c4d6fa..f987027ca566 100644
--- a/drivers/clocksource/tcb_clksrc.c
+++ b/drivers/clocksource/tcb_clksrc.c
@@ -71,7 +71,7 @@ static u64 tc_get_cycles32(struct clocksource *cs)
71 return readl_relaxed(tcaddr + ATMEL_TC_REG(0, CV)); 71 return readl_relaxed(tcaddr + ATMEL_TC_REG(0, CV));
72} 72}
73 73
74void tc_clksrc_suspend(struct clocksource *cs) 74static void tc_clksrc_suspend(struct clocksource *cs)
75{ 75{
76 int i; 76 int i;
77 77
@@ -86,7 +86,7 @@ void tc_clksrc_suspend(struct clocksource *cs)
86 bmr_cache = readl(tcaddr + ATMEL_TC_BMR); 86 bmr_cache = readl(tcaddr + ATMEL_TC_BMR);
87} 87}
88 88
89void tc_clksrc_resume(struct clocksource *cs) 89static void tc_clksrc_resume(struct clocksource *cs)
90{ 90{
91 int i; 91 int i;
92 92
diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
index e8163693e936..5e6038fbf115 100644
--- a/drivers/clocksource/timer-riscv.c
+++ b/drivers/clocksource/timer-riscv.c
@@ -58,7 +58,7 @@ static u64 riscv_sched_clock(void)
58static DEFINE_PER_CPU(struct clocksource, riscv_clocksource) = { 58static DEFINE_PER_CPU(struct clocksource, riscv_clocksource) = {
59 .name = "riscv_clocksource", 59 .name = "riscv_clocksource",
60 .rating = 300, 60 .rating = 300,
61 .mask = CLOCKSOURCE_MASK(BITS_PER_LONG), 61 .mask = CLOCKSOURCE_MASK(64),
62 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 62 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
63 .read = riscv_clocksource_rdtime, 63 .read = riscv_clocksource_rdtime,
64}; 64};
@@ -120,8 +120,7 @@ static int __init riscv_timer_init_dt(struct device_node *n)
120 return error; 120 return error;
121 } 121 }
122 122
123 sched_clock_register(riscv_sched_clock, 123 sched_clock_register(riscv_sched_clock, 64, riscv_timebase);
124 BITS_PER_LONG, riscv_timebase);
125 124
126 error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING, 125 error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING,
127 "clockevents/riscv/timer:starting", 126 "clockevents/riscv/timer:starting",
diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c
index c364027638e1..3352da6ed61f 100644
--- a/drivers/clocksource/timer-ti-dm.c
+++ b/drivers/clocksource/timer-ti-dm.c
@@ -586,8 +586,8 @@ static int omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload,
586} 586}
587 587
588/* Optimized set_load which removes costly spin wait in timer_start */ 588/* Optimized set_load which removes costly spin wait in timer_start */
589int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, 589static int omap_dm_timer_set_load_start(struct omap_dm_timer *timer,
590 unsigned int load) 590 int autoreload, unsigned int load)
591{ 591{
592 u32 l; 592 u32 l;
593 593
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index bfa9062ce6b9..16fcb56c232b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -700,6 +700,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
700 struct amdgpu_vm_bo_base *bo_base, *tmp; 700 struct amdgpu_vm_bo_base *bo_base, *tmp;
701 int r = 0; 701 int r = 0;
702 702
703 vm->bulk_moveable &= list_empty(&vm->evicted);
704
703 list_for_each_entry_safe(bo_base, tmp, &vm->evicted, vm_status) { 705 list_for_each_entry_safe(bo_base, tmp, &vm->evicted, vm_status) {
704 struct amdgpu_bo *bo = bo_base->bo; 706 struct amdgpu_bo *bo = bo_base->bo;
705 707
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 600259b4e291..2fe8397241ea 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -742,7 +742,7 @@ static int gmc_v9_0_allocate_vm_inv_eng(struct amdgpu_device *adev)
742 } 742 }
743 743
744 ring->vm_inv_eng = inv_eng - 1; 744 ring->vm_inv_eng = inv_eng - 1;
745 change_bit(inv_eng - 1, (unsigned long *)(&vm_inv_engs[vmhub])); 745 vm_inv_engs[vmhub] &= ~(1 << ring->vm_inv_eng);
746 746
747 dev_info(adev->dev, "ring %s uses VM inv eng %u on hub %u\n", 747 dev_info(adev->dev, "ring %s uses VM inv eng %u on hub %u\n",
748 ring->name, ring->vm_inv_eng, ring->funcs->vmhub); 748 ring->name, ring->vm_inv_eng, ring->funcs->vmhub);
diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c
index 0573eab0e190..f35e4ab55b27 100644
--- a/drivers/gpu/drm/exynos/exynos_mixer.c
+++ b/drivers/gpu/drm/exynos/exynos_mixer.c
@@ -20,6 +20,7 @@
20#include "regs-vp.h" 20#include "regs-vp.h"
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/ktime.h>
23#include <linux/spinlock.h> 24#include <linux/spinlock.h>
24#include <linux/wait.h> 25#include <linux/wait.h>
25#include <linux/i2c.h> 26#include <linux/i2c.h>
@@ -352,15 +353,62 @@ static void mixer_cfg_vp_blend(struct mixer_context *ctx, unsigned int alpha)
352 mixer_reg_write(ctx, MXR_VIDEO_CFG, val); 353 mixer_reg_write(ctx, MXR_VIDEO_CFG, val);
353} 354}
354 355
355static void mixer_vsync_set_update(struct mixer_context *ctx, bool enable) 356static bool mixer_is_synced(struct mixer_context *ctx)
356{ 357{
357 /* block update on vsync */ 358 u32 base, shadow;
358 mixer_reg_writemask(ctx, MXR_STATUS, enable ?
359 MXR_STATUS_SYNC_ENABLE : 0, MXR_STATUS_SYNC_ENABLE);
360 359
360 if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
361 ctx->mxr_ver == MXR_VER_128_0_0_184)
362 return !(mixer_reg_read(ctx, MXR_CFG) &
363 MXR_CFG_LAYER_UPDATE_COUNT_MASK);
364
365 if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags) &&
366 vp_reg_read(ctx, VP_SHADOW_UPDATE))
367 return false;
368
369 base = mixer_reg_read(ctx, MXR_CFG);
370 shadow = mixer_reg_read(ctx, MXR_CFG_S);
371 if (base != shadow)
372 return false;
373
374 base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(0));
375 shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(0));
376 if (base != shadow)
377 return false;
378
379 base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(1));
380 shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(1));
381 if (base != shadow)
382 return false;
383
384 return true;
385}
386
387static int mixer_wait_for_sync(struct mixer_context *ctx)
388{
389 ktime_t timeout = ktime_add_us(ktime_get(), 100000);
390
391 while (!mixer_is_synced(ctx)) {
392 usleep_range(1000, 2000);
393 if (ktime_compare(ktime_get(), timeout) > 0)
394 return -ETIMEDOUT;
395 }
396 return 0;
397}
398
399static void mixer_disable_sync(struct mixer_context *ctx)
400{
401 mixer_reg_writemask(ctx, MXR_STATUS, 0, MXR_STATUS_SYNC_ENABLE);
402}
403
404static void mixer_enable_sync(struct mixer_context *ctx)
405{
406 if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
407 ctx->mxr_ver == MXR_VER_128_0_0_184)
408 mixer_reg_writemask(ctx, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
409 mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SYNC_ENABLE);
361 if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags)) 410 if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags))
362 vp_reg_write(ctx, VP_SHADOW_UPDATE, enable ? 411 vp_reg_write(ctx, VP_SHADOW_UPDATE, VP_SHADOW_UPDATE_ENABLE);
363 VP_SHADOW_UPDATE_ENABLE : 0);
364} 412}
365 413
366static void mixer_cfg_scan(struct mixer_context *ctx, int width, int height) 414static void mixer_cfg_scan(struct mixer_context *ctx, int width, int height)
@@ -498,7 +546,6 @@ static void vp_video_buffer(struct mixer_context *ctx,
498 546
499 spin_lock_irqsave(&ctx->reg_slock, flags); 547 spin_lock_irqsave(&ctx->reg_slock, flags);
500 548
501 vp_reg_write(ctx, VP_SHADOW_UPDATE, 1);
502 /* interlace or progressive scan mode */ 549 /* interlace or progressive scan mode */
503 val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0); 550 val = (test_bit(MXR_BIT_INTERLACE, &ctx->flags) ? ~0 : 0);
504 vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_LINE_SKIP); 551 vp_reg_writemask(ctx, VP_MODE, val, VP_MODE_LINE_SKIP);
@@ -553,11 +600,6 @@ static void vp_video_buffer(struct mixer_context *ctx,
553 vp_regs_dump(ctx); 600 vp_regs_dump(ctx);
554} 601}
555 602
556static void mixer_layer_update(struct mixer_context *ctx)
557{
558 mixer_reg_writemask(ctx, MXR_CFG, ~0, MXR_CFG_LAYER_UPDATE);
559}
560
561static void mixer_graph_buffer(struct mixer_context *ctx, 603static void mixer_graph_buffer(struct mixer_context *ctx,
562 struct exynos_drm_plane *plane) 604 struct exynos_drm_plane *plane)
563{ 605{
@@ -640,11 +682,6 @@ static void mixer_graph_buffer(struct mixer_context *ctx,
640 mixer_cfg_layer(ctx, win, priority, true); 682 mixer_cfg_layer(ctx, win, priority, true);
641 mixer_cfg_gfx_blend(ctx, win, pixel_alpha, state->base.alpha); 683 mixer_cfg_gfx_blend(ctx, win, pixel_alpha, state->base.alpha);
642 684
643 /* layer update mandatory for mixer 16.0.33.0 */
644 if (ctx->mxr_ver == MXR_VER_16_0_33_0 ||
645 ctx->mxr_ver == MXR_VER_128_0_0_184)
646 mixer_layer_update(ctx);
647
648 spin_unlock_irqrestore(&ctx->reg_slock, flags); 685 spin_unlock_irqrestore(&ctx->reg_slock, flags);
649 686
650 mixer_regs_dump(ctx); 687 mixer_regs_dump(ctx);
@@ -709,7 +746,7 @@ static void mixer_win_reset(struct mixer_context *ctx)
709static irqreturn_t mixer_irq_handler(int irq, void *arg) 746static irqreturn_t mixer_irq_handler(int irq, void *arg)
710{ 747{
711 struct mixer_context *ctx = arg; 748 struct mixer_context *ctx = arg;
712 u32 val, base, shadow; 749 u32 val;
713 750
714 spin_lock(&ctx->reg_slock); 751 spin_lock(&ctx->reg_slock);
715 752
@@ -723,26 +760,9 @@ static irqreturn_t mixer_irq_handler(int irq, void *arg)
723 val &= ~MXR_INT_STATUS_VSYNC; 760 val &= ~MXR_INT_STATUS_VSYNC;
724 761
725 /* interlace scan need to check shadow register */ 762 /* interlace scan need to check shadow register */
726 if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)) { 763 if (test_bit(MXR_BIT_INTERLACE, &ctx->flags)
727 if (test_bit(MXR_BIT_VP_ENABLED, &ctx->flags) && 764 && !mixer_is_synced(ctx))
728 vp_reg_read(ctx, VP_SHADOW_UPDATE)) 765 goto out;
729 goto out;
730
731 base = mixer_reg_read(ctx, MXR_CFG);
732 shadow = mixer_reg_read(ctx, MXR_CFG_S);
733 if (base != shadow)
734 goto out;
735
736 base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(0));
737 shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(0));
738 if (base != shadow)
739 goto out;
740
741 base = mixer_reg_read(ctx, MXR_GRAPHIC_BASE(1));
742 shadow = mixer_reg_read(ctx, MXR_GRAPHIC_BASE_S(1));
743 if (base != shadow)
744 goto out;
745 }
746 766
747 drm_crtc_handle_vblank(&ctx->crtc->base); 767 drm_crtc_handle_vblank(&ctx->crtc->base);
748 } 768 }
@@ -917,12 +937,14 @@ static void mixer_disable_vblank(struct exynos_drm_crtc *crtc)
917 937
918static void mixer_atomic_begin(struct exynos_drm_crtc *crtc) 938static void mixer_atomic_begin(struct exynos_drm_crtc *crtc)
919{ 939{
920 struct mixer_context *mixer_ctx = crtc->ctx; 940 struct mixer_context *ctx = crtc->ctx;
921 941
922 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 942 if (!test_bit(MXR_BIT_POWERED, &ctx->flags))
923 return; 943 return;
924 944
925 mixer_vsync_set_update(mixer_ctx, false); 945 if (mixer_wait_for_sync(ctx))
946 dev_err(ctx->dev, "timeout waiting for VSYNC\n");
947 mixer_disable_sync(ctx);
926} 948}
927 949
928static void mixer_update_plane(struct exynos_drm_crtc *crtc, 950static void mixer_update_plane(struct exynos_drm_crtc *crtc,
@@ -964,7 +986,7 @@ static void mixer_atomic_flush(struct exynos_drm_crtc *crtc)
964 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags)) 986 if (!test_bit(MXR_BIT_POWERED, &mixer_ctx->flags))
965 return; 987 return;
966 988
967 mixer_vsync_set_update(mixer_ctx, true); 989 mixer_enable_sync(mixer_ctx);
968 exynos_crtc_handle_event(crtc); 990 exynos_crtc_handle_event(crtc);
969} 991}
970 992
@@ -979,7 +1001,7 @@ static void mixer_enable(struct exynos_drm_crtc *crtc)
979 1001
980 exynos_drm_pipe_clk_enable(crtc, true); 1002 exynos_drm_pipe_clk_enable(crtc, true);
981 1003
982 mixer_vsync_set_update(ctx, false); 1004 mixer_disable_sync(ctx);
983 1005
984 mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET); 1006 mixer_reg_writemask(ctx, MXR_STATUS, ~0, MXR_STATUS_SOFT_RESET);
985 1007
@@ -992,7 +1014,7 @@ static void mixer_enable(struct exynos_drm_crtc *crtc)
992 1014
993 mixer_commit(ctx); 1015 mixer_commit(ctx);
994 1016
995 mixer_vsync_set_update(ctx, true); 1017 mixer_enable_sync(ctx);
996 1018
997 set_bit(MXR_BIT_POWERED, &ctx->flags); 1019 set_bit(MXR_BIT_POWERED, &ctx->flags);
998} 1020}
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 30d516e975c6..8558e81fdc2a 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1734,8 +1734,13 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1734 * pages from. 1734 * pages from.
1735 */ 1735 */
1736 if (!obj->base.filp) { 1736 if (!obj->base.filp) {
1737 i915_gem_object_put(obj); 1737 addr = -ENXIO;
1738 return -ENXIO; 1738 goto err;
1739 }
1740
1741 if (range_overflows(args->offset, args->size, (u64)obj->base.size)) {
1742 addr = -EINVAL;
1743 goto err;
1739 } 1744 }
1740 1745
1741 addr = vm_mmap(obj->base.filp, 0, args->size, 1746 addr = vm_mmap(obj->base.filp, 0, args->size,
@@ -1749,8 +1754,8 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1749 struct vm_area_struct *vma; 1754 struct vm_area_struct *vma;
1750 1755
1751 if (down_write_killable(&mm->mmap_sem)) { 1756 if (down_write_killable(&mm->mmap_sem)) {
1752 i915_gem_object_put(obj); 1757 addr = -EINTR;
1753 return -EINTR; 1758 goto err;
1754 } 1759 }
1755 vma = find_vma(mm, addr); 1760 vma = find_vma(mm, addr);
1756 if (vma && __vma_matches(vma, obj->base.filp, addr, args->size)) 1761 if (vma && __vma_matches(vma, obj->base.filp, addr, args->size))
@@ -1768,12 +1773,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1768 i915_gem_object_put(obj); 1773 i915_gem_object_put(obj);
1769 1774
1770 args->addr_ptr = (u64)addr; 1775 args->addr_ptr = (u64)addr;
1771
1772 return 0; 1776 return 0;
1773 1777
1774err: 1778err:
1775 i915_gem_object_put(obj); 1779 i915_gem_object_put(obj);
1776
1777 return addr; 1780 return addr;
1778} 1781}
1779 1782
diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index 9a65341fec09..aa6791255252 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -1721,7 +1721,7 @@ error_msg(struct i915_gpu_state *error, unsigned long engines, const char *msg)
1721 i915_error_generate_code(error, engines)); 1721 i915_error_generate_code(error, engines));
1722 if (engines) { 1722 if (engines) {
1723 /* Just show the first executing process, more is confusing */ 1723 /* Just show the first executing process, more is confusing */
1724 i = ffs(engines); 1724 i = __ffs(engines);
1725 len += scnprintf(error->error_msg + len, 1725 len += scnprintf(error->error_msg + len,
1726 sizeof(error->error_msg) - len, 1726 sizeof(error->error_msg) - len,
1727 ", in %s [%d]", 1727 ", in %s [%d]",
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index b508d8a735e0..4364f42cac6b 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -1673,6 +1673,7 @@ init_vbt_missing_defaults(struct drm_i915_private *dev_priv)
1673 info->supports_dvi = (port != PORT_A && port != PORT_E); 1673 info->supports_dvi = (port != PORT_A && port != PORT_E);
1674 info->supports_hdmi = info->supports_dvi; 1674 info->supports_hdmi = info->supports_dvi;
1675 info->supports_dp = (port != PORT_E); 1675 info->supports_dp = (port != PORT_E);
1676 info->supports_edp = (port == PORT_A);
1676 } 1677 }
1677} 1678}
1678 1679
diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
index 88a52f6b39fe..7dfbbbc1beea 100644
--- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c
+++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
@@ -181,7 +181,7 @@ nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
181 } 181 }
182 182
183 ret = pm_runtime_get_sync(drm->dev); 183 ret = pm_runtime_get_sync(drm->dev);
184 if (IS_ERR_VALUE(ret) && ret != -EACCES) 184 if (ret < 0 && ret != -EACCES)
185 return ret; 185 return ret;
186 ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_USER, &args, sizeof(args)); 186 ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_USER, &args, sizeof(args));
187 pm_runtime_put_autosuspend(drm->dev); 187 pm_runtime_put_autosuspend(drm->dev);
diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c
index aa9fec80492d..40c47d6a7d78 100644
--- a/drivers/gpu/drm/nouveau/nouveau_dmem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c
@@ -100,12 +100,10 @@ static void
100nouveau_dmem_free(struct hmm_devmem *devmem, struct page *page) 100nouveau_dmem_free(struct hmm_devmem *devmem, struct page *page)
101{ 101{
102 struct nouveau_dmem_chunk *chunk; 102 struct nouveau_dmem_chunk *chunk;
103 struct nouveau_drm *drm;
104 unsigned long idx; 103 unsigned long idx;
105 104
106 chunk = (void *)hmm_devmem_page_get_drvdata(page); 105 chunk = (void *)hmm_devmem_page_get_drvdata(page);
107 idx = page_to_pfn(page) - chunk->pfn_first; 106 idx = page_to_pfn(page) - chunk->pfn_first;
108 drm = chunk->drm;
109 107
110 /* 108 /*
111 * FIXME: 109 * FIXME:
@@ -456,11 +454,6 @@ nouveau_dmem_resume(struct nouveau_drm *drm)
456 /* FIXME handle pin failure */ 454 /* FIXME handle pin failure */
457 WARN_ON(ret); 455 WARN_ON(ret);
458 } 456 }
459 list_for_each_entry (chunk, &drm->dmem->chunk_empty, list) {
460 ret = nouveau_bo_pin(chunk->bo, TTM_PL_FLAG_VRAM, false);
461 /* FIXME handle pin failure */
462 WARN_ON(ret);
463 }
464 mutex_unlock(&drm->dmem->mutex); 457 mutex_unlock(&drm->dmem->mutex);
465} 458}
466 459
@@ -479,9 +472,6 @@ nouveau_dmem_suspend(struct nouveau_drm *drm)
479 list_for_each_entry (chunk, &drm->dmem->chunk_full, list) { 472 list_for_each_entry (chunk, &drm->dmem->chunk_full, list) {
480 nouveau_bo_unpin(chunk->bo); 473 nouveau_bo_unpin(chunk->bo);
481 } 474 }
482 list_for_each_entry (chunk, &drm->dmem->chunk_empty, list) {
483 nouveau_bo_unpin(chunk->bo);
484 }
485 mutex_unlock(&drm->dmem->mutex); 475 mutex_unlock(&drm->dmem->mutex);
486} 476}
487 477
@@ -623,7 +613,7 @@ nouveau_dmem_init(struct nouveau_drm *drm)
623 */ 613 */
624 drm->dmem->devmem = hmm_devmem_add(&nouveau_dmem_devmem_ops, 614 drm->dmem->devmem = hmm_devmem_add(&nouveau_dmem_devmem_ops,
625 device, size); 615 device, size);
626 if (drm->dmem->devmem == NULL) { 616 if (IS_ERR(drm->dmem->devmem)) {
627 kfree(drm->dmem); 617 kfree(drm->dmem);
628 drm->dmem = NULL; 618 drm->dmem = NULL;
629 return; 619 return;
diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c
index d5a23295dd80..bb7b58407039 100644
--- a/drivers/gpu/drm/udl/udl_gem.c
+++ b/drivers/gpu/drm/udl/udl_gem.c
@@ -224,7 +224,7 @@ int udl_gem_mmap(struct drm_file *file, struct drm_device *dev,
224 *offset = drm_vma_node_offset_addr(&gobj->base.vma_node); 224 *offset = drm_vma_node_offset_addr(&gobj->base.vma_node);
225 225
226out: 226out:
227 drm_gem_object_put(&gobj->base); 227 drm_gem_object_put_unlocked(&gobj->base);
228unlock: 228unlock:
229 mutex_unlock(&udl->gem_lock); 229 mutex_unlock(&udl->gem_lock);
230 return ret; 230 return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
index b913a56f3426..2a9112515f46 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
@@ -564,11 +564,9 @@ static int vmw_fb_set_par(struct fb_info *info)
564 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 564 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
565 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) 565 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC)
566 }; 566 };
567 struct drm_display_mode *old_mode;
568 struct drm_display_mode *mode; 567 struct drm_display_mode *mode;
569 int ret; 568 int ret;
570 569
571 old_mode = par->set_mode;
572 mode = drm_mode_duplicate(vmw_priv->dev, &new_mode); 570 mode = drm_mode_duplicate(vmw_priv->dev, &new_mode);
573 if (!mode) { 571 if (!mode) {
574 DRM_ERROR("Could not create new fb mode.\n"); 572 DRM_ERROR("Could not create new fb mode.\n");
@@ -579,11 +577,7 @@ static int vmw_fb_set_par(struct fb_info *info)
579 mode->vdisplay = var->yres; 577 mode->vdisplay = var->yres;
580 vmw_guess_mode_timing(mode); 578 vmw_guess_mode_timing(mode);
581 579
582 if (old_mode && drm_mode_equal(old_mode, mode)) { 580 if (!vmw_kms_validate_mode_vram(vmw_priv,
583 drm_mode_destroy(vmw_priv->dev, mode);
584 mode = old_mode;
585 old_mode = NULL;
586 } else if (!vmw_kms_validate_mode_vram(vmw_priv,
587 mode->hdisplay * 581 mode->hdisplay *
588 DIV_ROUND_UP(var->bits_per_pixel, 8), 582 DIV_ROUND_UP(var->bits_per_pixel, 8),
589 mode->vdisplay)) { 583 mode->vdisplay)) {
@@ -620,8 +614,8 @@ static int vmw_fb_set_par(struct fb_info *info)
620 schedule_delayed_work(&par->local_work, 0); 614 schedule_delayed_work(&par->local_work, 0);
621 615
622out_unlock: 616out_unlock:
623 if (old_mode) 617 if (par->set_mode)
624 drm_mode_destroy(vmw_priv->dev, old_mode); 618 drm_mode_destroy(vmw_priv->dev, par->set_mode);
625 par->set_mode = mode; 619 par->set_mode = mode;
626 620
627 mutex_unlock(&par->bo_mutex); 621 mutex_unlock(&par->bo_mutex);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index b93c558dd86e..7da752ca1c34 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -57,7 +57,7 @@ static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man,
57 57
58 id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL); 58 id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
59 if (id < 0) 59 if (id < 0)
60 return id; 60 return (id != -ENOMEM ? 0 : id);
61 61
62 spin_lock(&gman->lock); 62 spin_lock(&gman->lock);
63 63
diff --git a/drivers/infiniband/hw/i40iw/i40iw_utils.c b/drivers/infiniband/hw/i40iw/i40iw_utils.c
index c5a881172524..337410f40860 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_utils.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_utils.c
@@ -173,7 +173,12 @@ int i40iw_inetaddr_event(struct notifier_block *notifier,
173 173
174 rcu_read_lock(); 174 rcu_read_lock();
175 in = __in_dev_get_rcu(upper_dev); 175 in = __in_dev_get_rcu(upper_dev);
176 local_ipaddr = ntohl(in->ifa_list->ifa_address); 176
177 if (!in->ifa_list)
178 local_ipaddr = 0;
179 else
180 local_ipaddr = ntohl(in->ifa_list->ifa_address);
181
177 rcu_read_unlock(); 182 rcu_read_unlock();
178 } else { 183 } else {
179 local_ipaddr = ntohl(ifa->ifa_address); 184 local_ipaddr = ntohl(ifa->ifa_address);
@@ -185,6 +190,11 @@ int i40iw_inetaddr_event(struct notifier_block *notifier,
185 case NETDEV_UP: 190 case NETDEV_UP:
186 /* Fall through */ 191 /* Fall through */
187 case NETDEV_CHANGEADDR: 192 case NETDEV_CHANGEADDR:
193
194 /* Just skip if no need to handle ARP cache */
195 if (!local_ipaddr)
196 break;
197
188 i40iw_manage_arp_cache(iwdev, 198 i40iw_manage_arp_cache(iwdev,
189 netdev->dev_addr, 199 netdev->dev_addr,
190 &local_ipaddr, 200 &local_ipaddr,
diff --git a/drivers/infiniband/hw/mlx4/alias_GUID.c b/drivers/infiniband/hw/mlx4/alias_GUID.c
index 782499abcd98..2a0b59a4b6eb 100644
--- a/drivers/infiniband/hw/mlx4/alias_GUID.c
+++ b/drivers/infiniband/hw/mlx4/alias_GUID.c
@@ -804,8 +804,8 @@ void mlx4_ib_destroy_alias_guid_service(struct mlx4_ib_dev *dev)
804 unsigned long flags; 804 unsigned long flags;
805 805
806 for (i = 0 ; i < dev->num_ports; i++) { 806 for (i = 0 ; i < dev->num_ports; i++) {
807 cancel_delayed_work(&dev->sriov.alias_guid.ports_guid[i].alias_guid_work);
808 det = &sriov->alias_guid.ports_guid[i]; 807 det = &sriov->alias_guid.ports_guid[i];
808 cancel_delayed_work_sync(&det->alias_guid_work);
809 spin_lock_irqsave(&sriov->alias_guid.ag_work_lock, flags); 809 spin_lock_irqsave(&sriov->alias_guid.ag_work_lock, flags);
810 while (!list_empty(&det->cb_list)) { 810 while (!list_empty(&det->cb_list)) {
811 cb_ctx = list_entry(det->cb_list.next, 811 cb_ctx = list_entry(det->cb_list.next,
diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index eaa055007f28..9e08df7914aa 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -20,6 +20,7 @@
20 20
21enum devx_obj_flags { 21enum devx_obj_flags {
22 DEVX_OBJ_FLAGS_INDIRECT_MKEY = 1 << 0, 22 DEVX_OBJ_FLAGS_INDIRECT_MKEY = 1 << 0,
23 DEVX_OBJ_FLAGS_DCT = 1 << 1,
23}; 24};
24 25
25struct devx_async_data { 26struct devx_async_data {
@@ -39,7 +40,10 @@ struct devx_obj {
39 u32 dinlen; /* destroy inbox length */ 40 u32 dinlen; /* destroy inbox length */
40 u32 dinbox[MLX5_MAX_DESTROY_INBOX_SIZE_DW]; 41 u32 dinbox[MLX5_MAX_DESTROY_INBOX_SIZE_DW];
41 u32 flags; 42 u32 flags;
42 struct mlx5_ib_devx_mr devx_mr; 43 union {
44 struct mlx5_ib_devx_mr devx_mr;
45 struct mlx5_core_dct core_dct;
46 };
43}; 47};
44 48
45struct devx_umem { 49struct devx_umem {
@@ -347,7 +351,6 @@ static u64 devx_get_obj_id(const void *in)
347 obj_id = get_enc_obj_id(MLX5_CMD_OP_CREATE_RQ, 351 obj_id = get_enc_obj_id(MLX5_CMD_OP_CREATE_RQ,
348 MLX5_GET(arm_rq_in, in, srq_number)); 352 MLX5_GET(arm_rq_in, in, srq_number));
349 break; 353 break;
350 case MLX5_CMD_OP_DRAIN_DCT:
351 case MLX5_CMD_OP_ARM_DCT_FOR_KEY_VIOLATION: 354 case MLX5_CMD_OP_ARM_DCT_FOR_KEY_VIOLATION:
352 obj_id = get_enc_obj_id(MLX5_CMD_OP_CREATE_DCT, 355 obj_id = get_enc_obj_id(MLX5_CMD_OP_CREATE_DCT,
353 MLX5_GET(drain_dct_in, in, dctn)); 356 MLX5_GET(drain_dct_in, in, dctn));
@@ -618,7 +621,6 @@ static bool devx_is_obj_modify_cmd(const void *in)
618 case MLX5_CMD_OP_2RST_QP: 621 case MLX5_CMD_OP_2RST_QP:
619 case MLX5_CMD_OP_ARM_XRC_SRQ: 622 case MLX5_CMD_OP_ARM_XRC_SRQ:
620 case MLX5_CMD_OP_ARM_RQ: 623 case MLX5_CMD_OP_ARM_RQ:
621 case MLX5_CMD_OP_DRAIN_DCT:
622 case MLX5_CMD_OP_ARM_DCT_FOR_KEY_VIOLATION: 624 case MLX5_CMD_OP_ARM_DCT_FOR_KEY_VIOLATION:
623 case MLX5_CMD_OP_ARM_XRQ: 625 case MLX5_CMD_OP_ARM_XRQ:
624 case MLX5_CMD_OP_SET_XRQ_DC_PARAMS_ENTRY: 626 case MLX5_CMD_OP_SET_XRQ_DC_PARAMS_ENTRY:
@@ -1124,7 +1126,11 @@ static int devx_obj_cleanup(struct ib_uobject *uobject,
1124 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY) 1126 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY)
1125 devx_cleanup_mkey(obj); 1127 devx_cleanup_mkey(obj);
1126 1128
1127 ret = mlx5_cmd_exec(obj->mdev, obj->dinbox, obj->dinlen, out, sizeof(out)); 1129 if (obj->flags & DEVX_OBJ_FLAGS_DCT)
1130 ret = mlx5_core_destroy_dct(obj->mdev, &obj->core_dct);
1131 else
1132 ret = mlx5_cmd_exec(obj->mdev, obj->dinbox, obj->dinlen, out,
1133 sizeof(out));
1128 if (ib_is_destroy_retryable(ret, why, uobject)) 1134 if (ib_is_destroy_retryable(ret, why, uobject))
1129 return ret; 1135 return ret;
1130 1136
@@ -1185,9 +1191,17 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(
1185 devx_set_umem_valid(cmd_in); 1191 devx_set_umem_valid(cmd_in);
1186 } 1192 }
1187 1193
1188 err = mlx5_cmd_exec(dev->mdev, cmd_in, 1194 if (opcode == MLX5_CMD_OP_CREATE_DCT) {
1189 cmd_in_len, 1195 obj->flags |= DEVX_OBJ_FLAGS_DCT;
1190 cmd_out, cmd_out_len); 1196 err = mlx5_core_create_dct(dev->mdev, &obj->core_dct,
1197 cmd_in, cmd_in_len,
1198 cmd_out, cmd_out_len);
1199 } else {
1200 err = mlx5_cmd_exec(dev->mdev, cmd_in,
1201 cmd_in_len,
1202 cmd_out, cmd_out_len);
1203 }
1204
1191 if (err) 1205 if (err)
1192 goto obj_free; 1206 goto obj_free;
1193 1207
@@ -1214,7 +1228,11 @@ err_copy:
1214 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY) 1228 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY)
1215 devx_cleanup_mkey(obj); 1229 devx_cleanup_mkey(obj);
1216obj_destroy: 1230obj_destroy:
1217 mlx5_cmd_exec(obj->mdev, obj->dinbox, obj->dinlen, out, sizeof(out)); 1231 if (obj->flags & DEVX_OBJ_FLAGS_DCT)
1232 mlx5_core_destroy_dct(obj->mdev, &obj->core_dct);
1233 else
1234 mlx5_cmd_exec(obj->mdev, obj->dinbox, obj->dinlen, out,
1235 sizeof(out));
1218obj_free: 1236obj_free:
1219 kfree(obj); 1237 kfree(obj);
1220 return err; 1238 return err;
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 994c19d01211..531ff20b32ad 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -415,10 +415,17 @@ static int translate_eth_ext_proto_oper(u32 eth_proto_oper, u8 *active_speed,
415 *active_speed = IB_SPEED_EDR; 415 *active_speed = IB_SPEED_EDR;
416 break; 416 break;
417 case MLX5E_PROT_MASK(MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2): 417 case MLX5E_PROT_MASK(MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2):
418 *active_width = IB_WIDTH_2X;
419 *active_speed = IB_SPEED_EDR;
420 break;
418 case MLX5E_PROT_MASK(MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR): 421 case MLX5E_PROT_MASK(MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR):
419 *active_width = IB_WIDTH_1X; 422 *active_width = IB_WIDTH_1X;
420 *active_speed = IB_SPEED_HDR; 423 *active_speed = IB_SPEED_HDR;
421 break; 424 break;
425 case MLX5E_PROT_MASK(MLX5E_CAUI_4_100GBASE_CR4_KR4):
426 *active_width = IB_WIDTH_4X;
427 *active_speed = IB_SPEED_EDR;
428 break;
422 case MLX5E_PROT_MASK(MLX5E_100GAUI_2_100GBASE_CR2_KR2): 429 case MLX5E_PROT_MASK(MLX5E_100GAUI_2_100GBASE_CR2_KR2):
423 *active_width = IB_WIDTH_2X; 430 *active_width = IB_WIDTH_2X;
424 *active_speed = IB_SPEED_HDR; 431 *active_speed = IB_SPEED_HDR;
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 6b1f0e76900b..7cd006da1dae 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -3729,6 +3729,7 @@ static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr,
3729 3729
3730 } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { 3730 } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) {
3731 struct mlx5_ib_modify_qp_resp resp = {}; 3731 struct mlx5_ib_modify_qp_resp resp = {};
3732 u32 out[MLX5_ST_SZ_DW(create_dct_out)] = {0};
3732 u32 min_resp_len = offsetof(typeof(resp), dctn) + 3733 u32 min_resp_len = offsetof(typeof(resp), dctn) +
3733 sizeof(resp.dctn); 3734 sizeof(resp.dctn);
3734 3735
@@ -3747,7 +3748,8 @@ static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr,
3747 MLX5_SET(dctc, dctc, hop_limit, attr->ah_attr.grh.hop_limit); 3748 MLX5_SET(dctc, dctc, hop_limit, attr->ah_attr.grh.hop_limit);
3748 3749
3749 err = mlx5_core_create_dct(dev->mdev, &qp->dct.mdct, qp->dct.in, 3750 err = mlx5_core_create_dct(dev->mdev, &qp->dct.mdct, qp->dct.in,
3750 MLX5_ST_SZ_BYTES(create_dct_in)); 3751 MLX5_ST_SZ_BYTES(create_dct_in), out,
3752 sizeof(out));
3751 if (err) 3753 if (err)
3752 return err; 3754 return err;
3753 resp.dctn = qp->dct.mdct.mqp.qpn; 3755 resp.dctn = qp->dct.mdct.mqp.qpn;
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b319e51c379b..21cb088d6687 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2608,7 +2608,12 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
2608 2608
2609 /* Everything is mapped - write the right values into s->dma_address */ 2609 /* Everything is mapped - write the right values into s->dma_address */
2610 for_each_sg(sglist, s, nelems, i) { 2610 for_each_sg(sglist, s, nelems, i) {
2611 s->dma_address += address + s->offset; 2611 /*
2612 * Add in the remaining piece of the scatter-gather offset that
2613 * was masked out when we were determining the physical address
2614 * via (sg_phys(s) & PAGE_MASK) earlier.
2615 */
2616 s->dma_address += address + (s->offset & ~PAGE_MASK);
2612 s->dma_length = s->length; 2617 s->dma_length = s->length;
2613 } 2618 }
2614 2619
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 87274b54febd..28cb713d728c 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -1538,6 +1538,9 @@ static void iommu_disable_protect_mem_regions(struct intel_iommu *iommu)
1538 u32 pmen; 1538 u32 pmen;
1539 unsigned long flags; 1539 unsigned long flags;
1540 1540
1541 if (!cap_plmr(iommu->cap) && !cap_phmr(iommu->cap))
1542 return;
1543
1541 raw_spin_lock_irqsave(&iommu->register_lock, flags); 1544 raw_spin_lock_irqsave(&iommu->register_lock, flags);
1542 pmen = readl(iommu->reg + DMAR_PMEN_REG); 1545 pmen = readl(iommu->reg + DMAR_PMEN_REG);
1543 pmen &= ~DMA_PMEN_EPM; 1546 pmen &= ~DMA_PMEN_EPM;
@@ -5332,7 +5335,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct intel_svm_dev *sd
5332 5335
5333 ctx_lo = context[0].lo; 5336 ctx_lo = context[0].lo;
5334 5337
5335 sdev->did = domain->iommu_did[iommu->seq_id]; 5338 sdev->did = FLPT_DEFAULT_DID;
5336 sdev->sid = PCI_DEVID(info->bus, info->devfn); 5339 sdev->sid = PCI_DEVID(info->bus, info->devfn);
5337 5340
5338 if (!(ctx_lo & CONTEXT_PASIDE)) { 5341 if (!(ctx_lo & CONTEXT_PASIDE)) {
diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index f8d3ba247523..2de8122e218f 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -207,8 +207,10 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad,
207 curr_iova = rb_entry(curr, struct iova, node); 207 curr_iova = rb_entry(curr, struct iova, node);
208 } while (curr && new_pfn <= curr_iova->pfn_hi); 208 } while (curr && new_pfn <= curr_iova->pfn_hi);
209 209
210 if (limit_pfn < size || new_pfn < iovad->start_pfn) 210 if (limit_pfn < size || new_pfn < iovad->start_pfn) {
211 iovad->max32_alloc_size = size;
211 goto iova32_full; 212 goto iova32_full;
213 }
212 214
213 /* pfn_lo will point to size aligned address if size_aligned is set */ 215 /* pfn_lo will point to size aligned address if size_aligned is set */
214 new->pfn_lo = new_pfn; 216 new->pfn_lo = new_pfn;
@@ -222,7 +224,6 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad,
222 return 0; 224 return 0;
223 225
224iova32_full: 226iova32_full:
225 iovad->max32_alloc_size = size;
226 spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); 227 spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
227 return -ENOMEM; 228 return -ENOMEM;
228} 229}
diff --git a/drivers/irqchip/irq-brcmstb-l2.c b/drivers/irqchip/irq-brcmstb-l2.c
index 83364fedbf0a..5e4ca139e4ea 100644
--- a/drivers/irqchip/irq-brcmstb-l2.c
+++ b/drivers/irqchip/irq-brcmstb-l2.c
@@ -275,14 +275,14 @@ out_free:
275 return ret; 275 return ret;
276} 276}
277 277
278int __init brcmstb_l2_edge_intc_of_init(struct device_node *np, 278static int __init brcmstb_l2_edge_intc_of_init(struct device_node *np,
279 struct device_node *parent) 279 struct device_node *parent)
280{ 280{
281 return brcmstb_l2_intc_of_init(np, parent, &l2_edge_intc_init); 281 return brcmstb_l2_intc_of_init(np, parent, &l2_edge_intc_init);
282} 282}
283IRQCHIP_DECLARE(brcmstb_l2_intc, "brcm,l2-intc", brcmstb_l2_edge_intc_of_init); 283IRQCHIP_DECLARE(brcmstb_l2_intc, "brcm,l2-intc", brcmstb_l2_edge_intc_of_init);
284 284
285int __init brcmstb_l2_lvl_intc_of_init(struct device_node *np, 285static int __init brcmstb_l2_lvl_intc_of_init(struct device_node *np,
286 struct device_node *parent) 286 struct device_node *parent)
287{ 287{
288 return brcmstb_l2_intc_of_init(np, parent, &l2_lvl_intc_init); 288 return brcmstb_l2_intc_of_init(np, parent, &l2_lvl_intc_init);
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 2dd1ff0cf558..7577755bdcf4 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1482,7 +1482,7 @@ static int lpi_range_cmp(void *priv, struct list_head *a, struct list_head *b)
1482 ra = container_of(a, struct lpi_range, entry); 1482 ra = container_of(a, struct lpi_range, entry);
1483 rb = container_of(b, struct lpi_range, entry); 1483 rb = container_of(b, struct lpi_range, entry);
1484 1484
1485 return rb->base_id - ra->base_id; 1485 return ra->base_id - rb->base_id;
1486} 1486}
1487 1487
1488static void merge_lpi_ranges(void) 1488static void merge_lpi_ranges(void)
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index ba2a37a27a54..fd3110c171ba 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -1089,11 +1089,10 @@ static void gic_init_chip(struct gic_chip_data *gic, struct device *dev,
1089#endif 1089#endif
1090} 1090}
1091 1091
1092static int gic_init_bases(struct gic_chip_data *gic, int irq_start, 1092static int gic_init_bases(struct gic_chip_data *gic,
1093 struct fwnode_handle *handle) 1093 struct fwnode_handle *handle)
1094{ 1094{
1095 irq_hw_number_t hwirq_base; 1095 int gic_irqs, ret;
1096 int gic_irqs, irq_base, ret;
1097 1096
1098 if (IS_ENABLED(CONFIG_GIC_NON_BANKED) && gic->percpu_offset) { 1097 if (IS_ENABLED(CONFIG_GIC_NON_BANKED) && gic->percpu_offset) {
1099 /* Frankein-GIC without banked registers... */ 1098 /* Frankein-GIC without banked registers... */
@@ -1145,28 +1144,21 @@ static int gic_init_bases(struct gic_chip_data *gic, int irq_start,
1145 } else { /* Legacy support */ 1144 } else { /* Legacy support */
1146 /* 1145 /*
1147 * For primary GICs, skip over SGIs. 1146 * For primary GICs, skip over SGIs.
1148 * For secondary GICs, skip over PPIs, too. 1147 * No secondary GIC support whatsoever.
1149 */ 1148 */
1150 if (gic == &gic_data[0] && (irq_start & 31) > 0) { 1149 int irq_base;
1151 hwirq_base = 16;
1152 if (irq_start != -1)
1153 irq_start = (irq_start & ~31) + 16;
1154 } else {
1155 hwirq_base = 32;
1156 }
1157 1150
1158 gic_irqs -= hwirq_base; /* calculate # of irqs to allocate */ 1151 gic_irqs -= 16; /* calculate # of irqs to allocate */
1159 1152
1160 irq_base = irq_alloc_descs(irq_start, 16, gic_irqs, 1153 irq_base = irq_alloc_descs(16, 16, gic_irqs,
1161 numa_node_id()); 1154 numa_node_id());
1162 if (irq_base < 0) { 1155 if (irq_base < 0) {
1163 WARN(1, "Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n", 1156 WARN(1, "Cannot allocate irq_descs @ IRQ16, assuming pre-allocated\n");
1164 irq_start); 1157 irq_base = 16;
1165 irq_base = irq_start;
1166 } 1158 }
1167 1159
1168 gic->domain = irq_domain_add_legacy(NULL, gic_irqs, irq_base, 1160 gic->domain = irq_domain_add_legacy(NULL, gic_irqs, irq_base,
1169 hwirq_base, &gic_irq_domain_ops, gic); 1161 16, &gic_irq_domain_ops, gic);
1170 } 1162 }
1171 1163
1172 if (WARN_ON(!gic->domain)) { 1164 if (WARN_ON(!gic->domain)) {
@@ -1195,7 +1187,6 @@ error:
1195} 1187}
1196 1188
1197static int __init __gic_init_bases(struct gic_chip_data *gic, 1189static int __init __gic_init_bases(struct gic_chip_data *gic,
1198 int irq_start,
1199 struct fwnode_handle *handle) 1190 struct fwnode_handle *handle)
1200{ 1191{
1201 char *name; 1192 char *name;
@@ -1231,32 +1222,28 @@ static int __init __gic_init_bases(struct gic_chip_data *gic,
1231 gic_init_chip(gic, NULL, name, false); 1222 gic_init_chip(gic, NULL, name, false);
1232 } 1223 }
1233 1224
1234 ret = gic_init_bases(gic, irq_start, handle); 1225 ret = gic_init_bases(gic, handle);
1235 if (ret) 1226 if (ret)
1236 kfree(name); 1227 kfree(name);
1237 1228
1238 return ret; 1229 return ret;
1239} 1230}
1240 1231
1241void __init gic_init(unsigned int gic_nr, int irq_start, 1232void __init gic_init(void __iomem *dist_base, void __iomem *cpu_base)
1242 void __iomem *dist_base, void __iomem *cpu_base)
1243{ 1233{
1244 struct gic_chip_data *gic; 1234 struct gic_chip_data *gic;
1245 1235
1246 if (WARN_ON(gic_nr >= CONFIG_ARM_GIC_MAX_NR))
1247 return;
1248
1249 /* 1236 /*
1250 * Non-DT/ACPI systems won't run a hypervisor, so let's not 1237 * Non-DT/ACPI systems won't run a hypervisor, so let's not
1251 * bother with these... 1238 * bother with these...
1252 */ 1239 */
1253 static_branch_disable(&supports_deactivate_key); 1240 static_branch_disable(&supports_deactivate_key);
1254 1241
1255 gic = &gic_data[gic_nr]; 1242 gic = &gic_data[0];
1256 gic->raw_dist_base = dist_base; 1243 gic->raw_dist_base = dist_base;
1257 gic->raw_cpu_base = cpu_base; 1244 gic->raw_cpu_base = cpu_base;
1258 1245
1259 __gic_init_bases(gic, irq_start, NULL); 1246 __gic_init_bases(gic, NULL);
1260} 1247}
1261 1248
1262static void gic_teardown(struct gic_chip_data *gic) 1249static void gic_teardown(struct gic_chip_data *gic)
@@ -1399,7 +1386,7 @@ int gic_of_init_child(struct device *dev, struct gic_chip_data **gic, int irq)
1399 if (ret) 1386 if (ret)
1400 return ret; 1387 return ret;
1401 1388
1402 ret = gic_init_bases(*gic, -1, &dev->of_node->fwnode); 1389 ret = gic_init_bases(*gic, &dev->of_node->fwnode);
1403 if (ret) { 1390 if (ret) {
1404 gic_teardown(*gic); 1391 gic_teardown(*gic);
1405 return ret; 1392 return ret;
@@ -1459,7 +1446,7 @@ gic_of_init(struct device_node *node, struct device_node *parent)
1459 if (gic_cnt == 0 && !gic_check_eoimode(node, &gic->raw_cpu_base)) 1446 if (gic_cnt == 0 && !gic_check_eoimode(node, &gic->raw_cpu_base))
1460 static_branch_disable(&supports_deactivate_key); 1447 static_branch_disable(&supports_deactivate_key);
1461 1448
1462 ret = __gic_init_bases(gic, -1, &node->fwnode); 1449 ret = __gic_init_bases(gic, &node->fwnode);
1463 if (ret) { 1450 if (ret) {
1464 gic_teardown(gic); 1451 gic_teardown(gic);
1465 return ret; 1452 return ret;
@@ -1650,7 +1637,7 @@ static int __init gic_v2_acpi_init(struct acpi_subtable_header *header,
1650 return -ENOMEM; 1637 return -ENOMEM;
1651 } 1638 }
1652 1639
1653 ret = __gic_init_bases(gic, -1, domain_handle); 1640 ret = __gic_init_bases(gic, domain_handle);
1654 if (ret) { 1641 if (ret) {
1655 pr_err("Failed to initialise GIC\n"); 1642 pr_err("Failed to initialise GIC\n");
1656 irq_domain_free_fwnode(domain_handle); 1643 irq_domain_free_fwnode(domain_handle);
diff --git a/drivers/irqchip/irq-imx-irqsteer.c b/drivers/irqchip/irq-imx-irqsteer.c
index d1098f4da6a4..88df3d00052c 100644
--- a/drivers/irqchip/irq-imx-irqsteer.c
+++ b/drivers/irqchip/irq-imx-irqsteer.c
@@ -169,8 +169,12 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
169 169
170 raw_spin_lock_init(&data->lock); 170 raw_spin_lock_init(&data->lock);
171 171
172 of_property_read_u32(np, "fsl,num-irqs", &irqs_num); 172 ret = of_property_read_u32(np, "fsl,num-irqs", &irqs_num);
173 of_property_read_u32(np, "fsl,channel", &data->channel); 173 if (ret)
174 return ret;
175 ret = of_property_read_u32(np, "fsl,channel", &data->channel);
176 if (ret)
177 return ret;
174 178
175 /* 179 /*
176 * There is one output irq for each group of 64 inputs. 180 * There is one output irq for each group of 64 inputs.
diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c
index 567b29c47608..98b6e1d4b1a6 100644
--- a/drivers/irqchip/irq-mbigen.c
+++ b/drivers/irqchip/irq-mbigen.c
@@ -161,6 +161,9 @@ static void mbigen_write_msg(struct msi_desc *desc, struct msi_msg *msg)
161 void __iomem *base = d->chip_data; 161 void __iomem *base = d->chip_data;
162 u32 val; 162 u32 val;
163 163
164 if (!msg->address_lo && !msg->address_hi)
165 return;
166
164 base += get_mbigen_vec_reg(d->hwirq); 167 base += get_mbigen_vec_reg(d->hwirq);
165 val = readl_relaxed(base); 168 val = readl_relaxed(base);
166 169
diff --git a/drivers/irqchip/irq-mmp.c b/drivers/irqchip/irq-mmp.c
index 3496b61a312a..8eed478f3b7e 100644
--- a/drivers/irqchip/irq-mmp.c
+++ b/drivers/irqchip/irq-mmp.c
@@ -179,7 +179,7 @@ static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node,
179 return 0; 179 return 0;
180} 180}
181 181
182const struct irq_domain_ops mmp_irq_domain_ops = { 182static const struct irq_domain_ops mmp_irq_domain_ops = {
183 .map = mmp_irq_domain_map, 183 .map = mmp_irq_domain_map,
184 .xlate = mmp_irq_domain_xlate, 184 .xlate = mmp_irq_domain_xlate,
185}; 185};
diff --git a/drivers/irqchip/irq-mvebu-sei.c b/drivers/irqchip/irq-mvebu-sei.c
index add4c9c934c8..18832ccc8ff8 100644
--- a/drivers/irqchip/irq-mvebu-sei.c
+++ b/drivers/irqchip/irq-mvebu-sei.c
@@ -478,7 +478,7 @@ dispose_irq:
478 return ret; 478 return ret;
479} 479}
480 480
481struct mvebu_sei_caps mvebu_sei_ap806_caps = { 481static struct mvebu_sei_caps mvebu_sei_ap806_caps = {
482 .ap_range = { 482 .ap_range = {
483 .first = 0, 483 .first = 0,
484 .size = 21, 484 .size = 21,
diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-exti.c
index a93296b9b45d..7bd1d4cb2e19 100644
--- a/drivers/irqchip/irq-stm32-exti.c
+++ b/drivers/irqchip/irq-stm32-exti.c
@@ -716,7 +716,6 @@ stm32_exti_chip_data *stm32_exti_chip_init(struct stm32_exti_host_data *h_data,
716 const struct stm32_exti_bank *stm32_bank; 716 const struct stm32_exti_bank *stm32_bank;
717 struct stm32_exti_chip_data *chip_data; 717 struct stm32_exti_chip_data *chip_data;
718 void __iomem *base = h_data->base; 718 void __iomem *base = h_data->base;
719 u32 irqs_mask;
720 719
721 stm32_bank = h_data->drv_data->exti_banks[bank_idx]; 720 stm32_bank = h_data->drv_data->exti_banks[bank_idx];
722 chip_data = &h_data->chips_data[bank_idx]; 721 chip_data = &h_data->chips_data[bank_idx];
@@ -725,21 +724,12 @@ stm32_exti_chip_data *stm32_exti_chip_init(struct stm32_exti_host_data *h_data,
725 724
726 raw_spin_lock_init(&chip_data->rlock); 725 raw_spin_lock_init(&chip_data->rlock);
727 726
728 /* Determine number of irqs supported */
729 writel_relaxed(~0UL, base + stm32_bank->rtsr_ofst);
730 irqs_mask = readl_relaxed(base + stm32_bank->rtsr_ofst);
731
732 /* 727 /*
733 * This IP has no reset, so after hot reboot we should 728 * This IP has no reset, so after hot reboot we should
734 * clear registers to avoid residue 729 * clear registers to avoid residue
735 */ 730 */
736 writel_relaxed(0, base + stm32_bank->imr_ofst); 731 writel_relaxed(0, base + stm32_bank->imr_ofst);
737 writel_relaxed(0, base + stm32_bank->emr_ofst); 732 writel_relaxed(0, base + stm32_bank->emr_ofst);
738 writel_relaxed(0, base + stm32_bank->rtsr_ofst);
739 writel_relaxed(0, base + stm32_bank->ftsr_ofst);
740 writel_relaxed(~0UL, base + stm32_bank->rpr_ofst);
741 if (stm32_bank->fpr_ofst != UNDEF_REG)
742 writel_relaxed(~0UL, base + stm32_bank->fpr_ofst);
743 733
744 pr_info("%pOF: bank%d\n", h_data->node, bank_idx); 734 pr_info("%pOF: bank%d\n", h_data->node, bank_idx);
745 735
diff --git a/drivers/misc/habanalabs/command_submission.c b/drivers/misc/habanalabs/command_submission.c
index 3525236ed8d9..19c84214a7ea 100644
--- a/drivers/misc/habanalabs/command_submission.c
+++ b/drivers/misc/habanalabs/command_submission.c
@@ -179,6 +179,12 @@ static void cs_do_release(struct kref *ref)
179 179
180 /* We also need to update CI for internal queues */ 180 /* We also need to update CI for internal queues */
181 if (cs->submitted) { 181 if (cs->submitted) {
182 int cs_cnt = atomic_dec_return(&hdev->cs_active_cnt);
183
184 WARN_ONCE((cs_cnt < 0),
185 "hl%d: error in CS active cnt %d\n",
186 hdev->id, cs_cnt);
187
182 hl_int_hw_queue_update_ci(cs); 188 hl_int_hw_queue_update_ci(cs);
183 189
184 spin_lock(&hdev->hw_queues_mirror_lock); 190 spin_lock(&hdev->hw_queues_mirror_lock);
diff --git a/drivers/misc/habanalabs/debugfs.c b/drivers/misc/habanalabs/debugfs.c
index a53c12aff6ad..974a87789bd8 100644
--- a/drivers/misc/habanalabs/debugfs.c
+++ b/drivers/misc/habanalabs/debugfs.c
@@ -232,6 +232,7 @@ static int vm_show(struct seq_file *s, void *data)
232 struct hl_vm_phys_pg_pack *phys_pg_pack = NULL; 232 struct hl_vm_phys_pg_pack *phys_pg_pack = NULL;
233 enum vm_type_t *vm_type; 233 enum vm_type_t *vm_type;
234 bool once = true; 234 bool once = true;
235 u64 j;
235 int i; 236 int i;
236 237
237 if (!dev_entry->hdev->mmu_enable) 238 if (!dev_entry->hdev->mmu_enable)
@@ -260,7 +261,7 @@ static int vm_show(struct seq_file *s, void *data)
260 } else { 261 } else {
261 phys_pg_pack = hnode->ptr; 262 phys_pg_pack = hnode->ptr;
262 seq_printf(s, 263 seq_printf(s,
263 " 0x%-14llx %-10u %-4u\n", 264 " 0x%-14llx %-10llu %-4u\n",
264 hnode->vaddr, phys_pg_pack->total_size, 265 hnode->vaddr, phys_pg_pack->total_size,
265 phys_pg_pack->handle); 266 phys_pg_pack->handle);
266 } 267 }
@@ -282,9 +283,9 @@ static int vm_show(struct seq_file *s, void *data)
282 phys_pg_pack->page_size); 283 phys_pg_pack->page_size);
283 seq_puts(s, " physical address\n"); 284 seq_puts(s, " physical address\n");
284 seq_puts(s, "---------------------\n"); 285 seq_puts(s, "---------------------\n");
285 for (i = 0 ; i < phys_pg_pack->npages ; i++) { 286 for (j = 0 ; j < phys_pg_pack->npages ; j++) {
286 seq_printf(s, " 0x%-14llx\n", 287 seq_printf(s, " 0x%-14llx\n",
287 phys_pg_pack->pages[i]); 288 phys_pg_pack->pages[j]);
288 } 289 }
289 } 290 }
290 spin_unlock(&vm->idr_lock); 291 spin_unlock(&vm->idr_lock);
diff --git a/drivers/misc/habanalabs/device.c b/drivers/misc/habanalabs/device.c
index de46aa6ed154..77d51be66c7e 100644
--- a/drivers/misc/habanalabs/device.c
+++ b/drivers/misc/habanalabs/device.c
@@ -11,6 +11,8 @@
11#include <linux/sched/signal.h> 11#include <linux/sched/signal.h>
12#include <linux/hwmon.h> 12#include <linux/hwmon.h>
13 13
14#define HL_PLDM_PENDING_RESET_PER_SEC (HL_PENDING_RESET_PER_SEC * 10)
15
14bool hl_device_disabled_or_in_reset(struct hl_device *hdev) 16bool hl_device_disabled_or_in_reset(struct hl_device *hdev)
15{ 17{
16 if ((hdev->disabled) || (atomic_read(&hdev->in_reset))) 18 if ((hdev->disabled) || (atomic_read(&hdev->in_reset)))
@@ -216,6 +218,7 @@ static int device_early_init(struct hl_device *hdev)
216 spin_lock_init(&hdev->hw_queues_mirror_lock); 218 spin_lock_init(&hdev->hw_queues_mirror_lock);
217 atomic_set(&hdev->in_reset, 0); 219 atomic_set(&hdev->in_reset, 0);
218 atomic_set(&hdev->fd_open_cnt, 0); 220 atomic_set(&hdev->fd_open_cnt, 0);
221 atomic_set(&hdev->cs_active_cnt, 0);
219 222
220 return 0; 223 return 0;
221 224
@@ -413,6 +416,27 @@ int hl_device_suspend(struct hl_device *hdev)
413 416
414 pci_save_state(hdev->pdev); 417 pci_save_state(hdev->pdev);
415 418
419 /* Block future CS/VM/JOB completion operations */
420 rc = atomic_cmpxchg(&hdev->in_reset, 0, 1);
421 if (rc) {
422 dev_err(hdev->dev, "Can't suspend while in reset\n");
423 return -EIO;
424 }
425
426 /* This blocks all other stuff that is not blocked by in_reset */
427 hdev->disabled = true;
428
429 /*
430 * Flush anyone that is inside the critical section of enqueue
431 * jobs to the H/W
432 */
433 hdev->asic_funcs->hw_queues_lock(hdev);
434 hdev->asic_funcs->hw_queues_unlock(hdev);
435
436 /* Flush processes that are sending message to CPU */
437 mutex_lock(&hdev->send_cpu_message_lock);
438 mutex_unlock(&hdev->send_cpu_message_lock);
439
416 rc = hdev->asic_funcs->suspend(hdev); 440 rc = hdev->asic_funcs->suspend(hdev);
417 if (rc) 441 if (rc)
418 dev_err(hdev->dev, 442 dev_err(hdev->dev,
@@ -440,21 +464,38 @@ int hl_device_resume(struct hl_device *hdev)
440 464
441 pci_set_power_state(hdev->pdev, PCI_D0); 465 pci_set_power_state(hdev->pdev, PCI_D0);
442 pci_restore_state(hdev->pdev); 466 pci_restore_state(hdev->pdev);
443 rc = pci_enable_device(hdev->pdev); 467 rc = pci_enable_device_mem(hdev->pdev);
444 if (rc) { 468 if (rc) {
445 dev_err(hdev->dev, 469 dev_err(hdev->dev,
446 "Failed to enable PCI device in resume\n"); 470 "Failed to enable PCI device in resume\n");
447 return rc; 471 return rc;
448 } 472 }
449 473
474 pci_set_master(hdev->pdev);
475
450 rc = hdev->asic_funcs->resume(hdev); 476 rc = hdev->asic_funcs->resume(hdev);
451 if (rc) { 477 if (rc) {
452 dev_err(hdev->dev, 478 dev_err(hdev->dev, "Failed to resume device after suspend\n");
453 "Failed to enable PCI access from device CPU\n"); 479 goto disable_device;
454 return rc; 480 }
481
482
483 hdev->disabled = false;
484 atomic_set(&hdev->in_reset, 0);
485
486 rc = hl_device_reset(hdev, true, false);
487 if (rc) {
488 dev_err(hdev->dev, "Failed to reset device during resume\n");
489 goto disable_device;
455 } 490 }
456 491
457 return 0; 492 return 0;
493
494disable_device:
495 pci_clear_master(hdev->pdev);
496 pci_disable_device(hdev->pdev);
497
498 return rc;
458} 499}
459 500
460static void hl_device_hard_reset_pending(struct work_struct *work) 501static void hl_device_hard_reset_pending(struct work_struct *work)
@@ -462,9 +503,16 @@ static void hl_device_hard_reset_pending(struct work_struct *work)
462 struct hl_device_reset_work *device_reset_work = 503 struct hl_device_reset_work *device_reset_work =
463 container_of(work, struct hl_device_reset_work, reset_work); 504 container_of(work, struct hl_device_reset_work, reset_work);
464 struct hl_device *hdev = device_reset_work->hdev; 505 struct hl_device *hdev = device_reset_work->hdev;
465 u16 pending_cnt = HL_PENDING_RESET_PER_SEC; 506 u16 pending_total, pending_cnt;
466 struct task_struct *task = NULL; 507 struct task_struct *task = NULL;
467 508
509 if (hdev->pldm)
510 pending_total = HL_PLDM_PENDING_RESET_PER_SEC;
511 else
512 pending_total = HL_PENDING_RESET_PER_SEC;
513
514 pending_cnt = pending_total;
515
468 /* Flush all processes that are inside hl_open */ 516 /* Flush all processes that are inside hl_open */
469 mutex_lock(&hdev->fd_open_cnt_lock); 517 mutex_lock(&hdev->fd_open_cnt_lock);
470 518
@@ -489,6 +537,19 @@ static void hl_device_hard_reset_pending(struct work_struct *work)
489 } 537 }
490 } 538 }
491 539
540 pending_cnt = pending_total;
541
542 while ((atomic_read(&hdev->fd_open_cnt)) && (pending_cnt)) {
543
544 pending_cnt--;
545
546 ssleep(1);
547 }
548
549 if (atomic_read(&hdev->fd_open_cnt))
550 dev_crit(hdev->dev,
551 "Going to hard reset with open user contexts\n");
552
492 mutex_unlock(&hdev->fd_open_cnt_lock); 553 mutex_unlock(&hdev->fd_open_cnt_lock);
493 554
494 hl_device_reset(hdev, true, true); 555 hl_device_reset(hdev, true, true);
diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
index 238dd57c541b..ea979ebd62fb 100644
--- a/drivers/misc/habanalabs/goya/goya.c
+++ b/drivers/misc/habanalabs/goya/goya.c
@@ -1201,15 +1201,6 @@ static int goya_stop_external_queues(struct hl_device *hdev)
1201 return retval; 1201 return retval;
1202} 1202}
1203 1203
1204static void goya_resume_external_queues(struct hl_device *hdev)
1205{
1206 WREG32(mmDMA_QM_0_GLBL_CFG1, 0);
1207 WREG32(mmDMA_QM_1_GLBL_CFG1, 0);
1208 WREG32(mmDMA_QM_2_GLBL_CFG1, 0);
1209 WREG32(mmDMA_QM_3_GLBL_CFG1, 0);
1210 WREG32(mmDMA_QM_4_GLBL_CFG1, 0);
1211}
1212
1213/* 1204/*
1214 * goya_init_cpu_queues - Initialize PQ/CQ/EQ of CPU 1205 * goya_init_cpu_queues - Initialize PQ/CQ/EQ of CPU
1215 * 1206 *
@@ -2178,36 +2169,6 @@ static int goya_stop_internal_queues(struct hl_device *hdev)
2178 return retval; 2169 return retval;
2179} 2170}
2180 2171
2181static void goya_resume_internal_queues(struct hl_device *hdev)
2182{
2183 WREG32(mmMME_QM_GLBL_CFG1, 0);
2184 WREG32(mmMME_CMDQ_GLBL_CFG1, 0);
2185
2186 WREG32(mmTPC0_QM_GLBL_CFG1, 0);
2187 WREG32(mmTPC0_CMDQ_GLBL_CFG1, 0);
2188
2189 WREG32(mmTPC1_QM_GLBL_CFG1, 0);
2190 WREG32(mmTPC1_CMDQ_GLBL_CFG1, 0);
2191
2192 WREG32(mmTPC2_QM_GLBL_CFG1, 0);
2193 WREG32(mmTPC2_CMDQ_GLBL_CFG1, 0);
2194
2195 WREG32(mmTPC3_QM_GLBL_CFG1, 0);
2196 WREG32(mmTPC3_CMDQ_GLBL_CFG1, 0);
2197
2198 WREG32(mmTPC4_QM_GLBL_CFG1, 0);
2199 WREG32(mmTPC4_CMDQ_GLBL_CFG1, 0);
2200
2201 WREG32(mmTPC5_QM_GLBL_CFG1, 0);
2202 WREG32(mmTPC5_CMDQ_GLBL_CFG1, 0);
2203
2204 WREG32(mmTPC6_QM_GLBL_CFG1, 0);
2205 WREG32(mmTPC6_CMDQ_GLBL_CFG1, 0);
2206
2207 WREG32(mmTPC7_QM_GLBL_CFG1, 0);
2208 WREG32(mmTPC7_CMDQ_GLBL_CFG1, 0);
2209}
2210
2211static void goya_dma_stall(struct hl_device *hdev) 2172static void goya_dma_stall(struct hl_device *hdev)
2212{ 2173{
2213 WREG32(mmDMA_QM_0_GLBL_CFG1, 1 << DMA_QM_0_GLBL_CFG1_DMA_STOP_SHIFT); 2174 WREG32(mmDMA_QM_0_GLBL_CFG1, 1 << DMA_QM_0_GLBL_CFG1_DMA_STOP_SHIFT);
@@ -2905,20 +2866,6 @@ int goya_suspend(struct hl_device *hdev)
2905{ 2866{
2906 int rc; 2867 int rc;
2907 2868
2908 rc = goya_stop_internal_queues(hdev);
2909
2910 if (rc) {
2911 dev_err(hdev->dev, "failed to stop internal queues\n");
2912 return rc;
2913 }
2914
2915 rc = goya_stop_external_queues(hdev);
2916
2917 if (rc) {
2918 dev_err(hdev->dev, "failed to stop external queues\n");
2919 return rc;
2920 }
2921
2922 rc = goya_send_pci_access_msg(hdev, ARMCP_PACKET_DISABLE_PCI_ACCESS); 2869 rc = goya_send_pci_access_msg(hdev, ARMCP_PACKET_DISABLE_PCI_ACCESS);
2923 if (rc) 2870 if (rc)
2924 dev_err(hdev->dev, "Failed to disable PCI access from CPU\n"); 2871 dev_err(hdev->dev, "Failed to disable PCI access from CPU\n");
@@ -2928,15 +2875,7 @@ int goya_suspend(struct hl_device *hdev)
2928 2875
2929int goya_resume(struct hl_device *hdev) 2876int goya_resume(struct hl_device *hdev)
2930{ 2877{
2931 int rc; 2878 return goya_init_iatu(hdev);
2932
2933 goya_resume_external_queues(hdev);
2934 goya_resume_internal_queues(hdev);
2935
2936 rc = goya_send_pci_access_msg(hdev, ARMCP_PACKET_ENABLE_PCI_ACCESS);
2937 if (rc)
2938 dev_err(hdev->dev, "Failed to enable PCI access from CPU\n");
2939 return rc;
2940} 2879}
2941 2880
2942static int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma, 2881static int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
@@ -3070,7 +3009,7 @@ void *goya_get_int_queue_base(struct hl_device *hdev, u32 queue_id,
3070 3009
3071 *dma_handle = hdev->asic_prop.sram_base_address; 3010 *dma_handle = hdev->asic_prop.sram_base_address;
3072 3011
3073 base = hdev->pcie_bar[SRAM_CFG_BAR_ID]; 3012 base = (void *) hdev->pcie_bar[SRAM_CFG_BAR_ID];
3074 3013
3075 switch (queue_id) { 3014 switch (queue_id) {
3076 case GOYA_QUEUE_ID_MME: 3015 case GOYA_QUEUE_ID_MME:
diff --git a/drivers/misc/habanalabs/habanalabs.h b/drivers/misc/habanalabs/habanalabs.h
index a7c95e9f9b9a..a8ee52c880cd 100644
--- a/drivers/misc/habanalabs/habanalabs.h
+++ b/drivers/misc/habanalabs/habanalabs.h
@@ -793,11 +793,11 @@ struct hl_vm_hash_node {
793 * struct hl_vm_phys_pg_pack - physical page pack. 793 * struct hl_vm_phys_pg_pack - physical page pack.
794 * @vm_type: describes the type of the virtual area descriptor. 794 * @vm_type: describes the type of the virtual area descriptor.
795 * @pages: the physical page array. 795 * @pages: the physical page array.
796 * @npages: num physical pages in the pack.
797 * @total_size: total size of all the pages in this list.
796 * @mapping_cnt: number of shared mappings. 798 * @mapping_cnt: number of shared mappings.
797 * @asid: the context related to this list. 799 * @asid: the context related to this list.
798 * @npages: num physical pages in the pack.
799 * @page_size: size of each page in the pack. 800 * @page_size: size of each page in the pack.
800 * @total_size: total size of all the pages in this list.
801 * @flags: HL_MEM_* flags related to this list. 801 * @flags: HL_MEM_* flags related to this list.
802 * @handle: the provided handle related to this list. 802 * @handle: the provided handle related to this list.
803 * @offset: offset from the first page. 803 * @offset: offset from the first page.
@@ -807,11 +807,11 @@ struct hl_vm_hash_node {
807struct hl_vm_phys_pg_pack { 807struct hl_vm_phys_pg_pack {
808 enum vm_type_t vm_type; /* must be first */ 808 enum vm_type_t vm_type; /* must be first */
809 u64 *pages; 809 u64 *pages;
810 u64 npages;
811 u64 total_size;
810 atomic_t mapping_cnt; 812 atomic_t mapping_cnt;
811 u32 asid; 813 u32 asid;
812 u32 npages;
813 u32 page_size; 814 u32 page_size;
814 u32 total_size;
815 u32 flags; 815 u32 flags;
816 u32 handle; 816 u32 handle;
817 u32 offset; 817 u32 offset;
@@ -1056,13 +1056,15 @@ struct hl_device_reset_work {
1056 * @cb_pool_lock: protects the CB pool. 1056 * @cb_pool_lock: protects the CB pool.
1057 * @user_ctx: current user context executing. 1057 * @user_ctx: current user context executing.
1058 * @dram_used_mem: current DRAM memory consumption. 1058 * @dram_used_mem: current DRAM memory consumption.
1059 * @in_reset: is device in reset flow.
1060 * @curr_pll_profile: current PLL profile.
1061 * @fd_open_cnt: number of open user processes.
1062 * @timeout_jiffies: device CS timeout value. 1059 * @timeout_jiffies: device CS timeout value.
1063 * @max_power: the max power of the device, as configured by the sysadmin. This 1060 * @max_power: the max power of the device, as configured by the sysadmin. This
1064 * value is saved so in case of hard-reset, KMD will restore this 1061 * value is saved so in case of hard-reset, KMD will restore this
1065 * value and update the F/W after the re-initialization 1062 * value and update the F/W after the re-initialization
1063 * @in_reset: is device in reset flow.
1064 * @curr_pll_profile: current PLL profile.
1065 * @fd_open_cnt: number of open user processes.
1066 * @cs_active_cnt: number of active command submissions on this device (active
1067 * means already in H/W queues)
1066 * @major: habanalabs KMD major. 1068 * @major: habanalabs KMD major.
1067 * @high_pll: high PLL profile frequency. 1069 * @high_pll: high PLL profile frequency.
1068 * @soft_reset_cnt: number of soft reset since KMD loading. 1070 * @soft_reset_cnt: number of soft reset since KMD loading.
@@ -1128,11 +1130,12 @@ struct hl_device {
1128 struct hl_ctx *user_ctx; 1130 struct hl_ctx *user_ctx;
1129 1131
1130 atomic64_t dram_used_mem; 1132 atomic64_t dram_used_mem;
1133 u64 timeout_jiffies;
1134 u64 max_power;
1131 atomic_t in_reset; 1135 atomic_t in_reset;
1132 atomic_t curr_pll_profile; 1136 atomic_t curr_pll_profile;
1133 atomic_t fd_open_cnt; 1137 atomic_t fd_open_cnt;
1134 u64 timeout_jiffies; 1138 atomic_t cs_active_cnt;
1135 u64 max_power;
1136 u32 major; 1139 u32 major;
1137 u32 high_pll; 1140 u32 high_pll;
1138 u32 soft_reset_cnt; 1141 u32 soft_reset_cnt;
diff --git a/drivers/misc/habanalabs/hw_queue.c b/drivers/misc/habanalabs/hw_queue.c
index 67bece26417c..ef3bb6951360 100644
--- a/drivers/misc/habanalabs/hw_queue.c
+++ b/drivers/misc/habanalabs/hw_queue.c
@@ -370,12 +370,13 @@ int hl_hw_queue_schedule_cs(struct hl_cs *cs)
370 spin_unlock(&hdev->hw_queues_mirror_lock); 370 spin_unlock(&hdev->hw_queues_mirror_lock);
371 } 371 }
372 372
373 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) { 373 atomic_inc(&hdev->cs_active_cnt);
374
375 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node)
374 if (job->ext_queue) 376 if (job->ext_queue)
375 ext_hw_queue_schedule_job(job); 377 ext_hw_queue_schedule_job(job);
376 else 378 else
377 int_hw_queue_schedule_job(job); 379 int_hw_queue_schedule_job(job);
378 }
379 380
380 cs->submitted = true; 381 cs->submitted = true;
381 382
diff --git a/drivers/misc/habanalabs/memory.c b/drivers/misc/habanalabs/memory.c
index 3a12fd1a5274..ce1fda40a8b8 100644
--- a/drivers/misc/habanalabs/memory.c
+++ b/drivers/misc/habanalabs/memory.c
@@ -56,9 +56,9 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
56 struct hl_device *hdev = ctx->hdev; 56 struct hl_device *hdev = ctx->hdev;
57 struct hl_vm *vm = &hdev->vm; 57 struct hl_vm *vm = &hdev->vm;
58 struct hl_vm_phys_pg_pack *phys_pg_pack; 58 struct hl_vm_phys_pg_pack *phys_pg_pack;
59 u64 paddr = 0; 59 u64 paddr = 0, total_size, num_pgs, i;
60 u32 total_size, num_pgs, num_curr_pgs, page_size, page_shift; 60 u32 num_curr_pgs, page_size, page_shift;
61 int handle, rc, i; 61 int handle, rc;
62 bool contiguous; 62 bool contiguous;
63 63
64 num_curr_pgs = 0; 64 num_curr_pgs = 0;
@@ -73,7 +73,7 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
73 paddr = (u64) gen_pool_alloc(vm->dram_pg_pool, total_size); 73 paddr = (u64) gen_pool_alloc(vm->dram_pg_pool, total_size);
74 if (!paddr) { 74 if (!paddr) {
75 dev_err(hdev->dev, 75 dev_err(hdev->dev,
76 "failed to allocate %u huge contiguous pages\n", 76 "failed to allocate %llu huge contiguous pages\n",
77 num_pgs); 77 num_pgs);
78 return -ENOMEM; 78 return -ENOMEM;
79 } 79 }
@@ -93,7 +93,7 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
93 phys_pg_pack->flags = args->flags; 93 phys_pg_pack->flags = args->flags;
94 phys_pg_pack->contiguous = contiguous; 94 phys_pg_pack->contiguous = contiguous;
95 95
96 phys_pg_pack->pages = kcalloc(num_pgs, sizeof(u64), GFP_KERNEL); 96 phys_pg_pack->pages = kvmalloc_array(num_pgs, sizeof(u64), GFP_KERNEL);
97 if (!phys_pg_pack->pages) { 97 if (!phys_pg_pack->pages) {
98 rc = -ENOMEM; 98 rc = -ENOMEM;
99 goto pages_arr_err; 99 goto pages_arr_err;
@@ -148,7 +148,7 @@ page_err:
148 gen_pool_free(vm->dram_pg_pool, phys_pg_pack->pages[i], 148 gen_pool_free(vm->dram_pg_pool, phys_pg_pack->pages[i],
149 page_size); 149 page_size);
150 150
151 kfree(phys_pg_pack->pages); 151 kvfree(phys_pg_pack->pages);
152pages_arr_err: 152pages_arr_err:
153 kfree(phys_pg_pack); 153 kfree(phys_pg_pack);
154pages_pack_err: 154pages_pack_err:
@@ -267,7 +267,7 @@ static void free_phys_pg_pack(struct hl_device *hdev,
267 struct hl_vm_phys_pg_pack *phys_pg_pack) 267 struct hl_vm_phys_pg_pack *phys_pg_pack)
268{ 268{
269 struct hl_vm *vm = &hdev->vm; 269 struct hl_vm *vm = &hdev->vm;
270 int i; 270 u64 i;
271 271
272 if (!phys_pg_pack->created_from_userptr) { 272 if (!phys_pg_pack->created_from_userptr) {
273 if (phys_pg_pack->contiguous) { 273 if (phys_pg_pack->contiguous) {
@@ -288,7 +288,7 @@ static void free_phys_pg_pack(struct hl_device *hdev,
288 } 288 }
289 } 289 }
290 290
291 kfree(phys_pg_pack->pages); 291 kvfree(phys_pg_pack->pages);
292 kfree(phys_pg_pack); 292 kfree(phys_pg_pack);
293} 293}
294 294
@@ -519,7 +519,7 @@ static inline int add_va_block(struct hl_device *hdev,
519 * - Return the start address of the virtual block 519 * - Return the start address of the virtual block
520 */ 520 */
521static u64 get_va_block(struct hl_device *hdev, 521static u64 get_va_block(struct hl_device *hdev,
522 struct hl_va_range *va_range, u32 size, u64 hint_addr, 522 struct hl_va_range *va_range, u64 size, u64 hint_addr,
523 bool is_userptr) 523 bool is_userptr)
524{ 524{
525 struct hl_vm_va_block *va_block, *new_va_block = NULL; 525 struct hl_vm_va_block *va_block, *new_va_block = NULL;
@@ -577,7 +577,8 @@ static u64 get_va_block(struct hl_device *hdev,
577 } 577 }
578 578
579 if (!new_va_block) { 579 if (!new_va_block) {
580 dev_err(hdev->dev, "no available va block for size %u\n", size); 580 dev_err(hdev->dev, "no available va block for size %llu\n",
581 size);
581 goto out; 582 goto out;
582 } 583 }
583 584
@@ -648,8 +649,8 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx,
648 struct hl_vm_phys_pg_pack *phys_pg_pack; 649 struct hl_vm_phys_pg_pack *phys_pg_pack;
649 struct scatterlist *sg; 650 struct scatterlist *sg;
650 dma_addr_t dma_addr; 651 dma_addr_t dma_addr;
651 u64 page_mask; 652 u64 page_mask, total_npages;
652 u32 npages, total_npages, page_size = PAGE_SIZE; 653 u32 npages, page_size = PAGE_SIZE;
653 bool first = true, is_huge_page_opt = true; 654 bool first = true, is_huge_page_opt = true;
654 int rc, i, j; 655 int rc, i, j;
655 656
@@ -691,7 +692,8 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx,
691 692
692 page_mask = ~(((u64) page_size) - 1); 693 page_mask = ~(((u64) page_size) - 1);
693 694
694 phys_pg_pack->pages = kcalloc(total_npages, sizeof(u64), GFP_KERNEL); 695 phys_pg_pack->pages = kvmalloc_array(total_npages, sizeof(u64),
696 GFP_KERNEL);
695 if (!phys_pg_pack->pages) { 697 if (!phys_pg_pack->pages) {
696 rc = -ENOMEM; 698 rc = -ENOMEM;
697 goto page_pack_arr_mem_err; 699 goto page_pack_arr_mem_err;
@@ -750,9 +752,9 @@ static int map_phys_page_pack(struct hl_ctx *ctx, u64 vaddr,
750 struct hl_vm_phys_pg_pack *phys_pg_pack) 752 struct hl_vm_phys_pg_pack *phys_pg_pack)
751{ 753{
752 struct hl_device *hdev = ctx->hdev; 754 struct hl_device *hdev = ctx->hdev;
753 u64 next_vaddr = vaddr, paddr; 755 u64 next_vaddr = vaddr, paddr, mapped_pg_cnt = 0, i;
754 u32 page_size = phys_pg_pack->page_size; 756 u32 page_size = phys_pg_pack->page_size;
755 int i, rc = 0, mapped_pg_cnt = 0; 757 int rc = 0;
756 758
757 for (i = 0 ; i < phys_pg_pack->npages ; i++) { 759 for (i = 0 ; i < phys_pg_pack->npages ; i++) {
758 paddr = phys_pg_pack->pages[i]; 760 paddr = phys_pg_pack->pages[i];
@@ -764,7 +766,7 @@ static int map_phys_page_pack(struct hl_ctx *ctx, u64 vaddr,
764 rc = hl_mmu_map(ctx, next_vaddr, paddr, page_size); 766 rc = hl_mmu_map(ctx, next_vaddr, paddr, page_size);
765 if (rc) { 767 if (rc) {
766 dev_err(hdev->dev, 768 dev_err(hdev->dev,
767 "map failed for handle %u, npages: %d, mapped: %d", 769 "map failed for handle %u, npages: %llu, mapped: %llu",
768 phys_pg_pack->handle, phys_pg_pack->npages, 770 phys_pg_pack->handle, phys_pg_pack->npages,
769 mapped_pg_cnt); 771 mapped_pg_cnt);
770 goto err; 772 goto err;
@@ -985,10 +987,10 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr)
985 struct hl_vm_hash_node *hnode = NULL; 987 struct hl_vm_hash_node *hnode = NULL;
986 struct hl_userptr *userptr = NULL; 988 struct hl_userptr *userptr = NULL;
987 enum vm_type_t *vm_type; 989 enum vm_type_t *vm_type;
988 u64 next_vaddr; 990 u64 next_vaddr, i;
989 u32 page_size; 991 u32 page_size;
990 bool is_userptr; 992 bool is_userptr;
991 int i, rc; 993 int rc;
992 994
993 /* protect from double entrance */ 995 /* protect from double entrance */
994 mutex_lock(&ctx->mem_hash_lock); 996 mutex_lock(&ctx->mem_hash_lock);
diff --git a/drivers/misc/habanalabs/mmu.c b/drivers/misc/habanalabs/mmu.c
index 2f2e99cb2743..3a5a2cec8305 100644
--- a/drivers/misc/habanalabs/mmu.c
+++ b/drivers/misc/habanalabs/mmu.c
@@ -832,7 +832,7 @@ err:
832int hl_mmu_map(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size) 832int hl_mmu_map(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size)
833{ 833{
834 struct hl_device *hdev = ctx->hdev; 834 struct hl_device *hdev = ctx->hdev;
835 u64 real_virt_addr; 835 u64 real_virt_addr, real_phys_addr;
836 u32 real_page_size, npages; 836 u32 real_page_size, npages;
837 int i, rc, mapped_cnt = 0; 837 int i, rc, mapped_cnt = 0;
838 838
@@ -857,14 +857,16 @@ int hl_mmu_map(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size)
857 857
858 npages = page_size / real_page_size; 858 npages = page_size / real_page_size;
859 real_virt_addr = virt_addr; 859 real_virt_addr = virt_addr;
860 real_phys_addr = phys_addr;
860 861
861 for (i = 0 ; i < npages ; i++) { 862 for (i = 0 ; i < npages ; i++) {
862 rc = _hl_mmu_map(ctx, real_virt_addr, phys_addr, 863 rc = _hl_mmu_map(ctx, real_virt_addr, real_phys_addr,
863 real_page_size); 864 real_page_size);
864 if (rc) 865 if (rc)
865 goto err; 866 goto err;
866 867
867 real_virt_addr += real_page_size; 868 real_virt_addr += real_page_size;
869 real_phys_addr += real_page_size;
868 mapped_cnt++; 870 mapped_cnt++;
869 } 871 }
870 872
diff --git a/drivers/mmc/host/alcor.c b/drivers/mmc/host/alcor.c
index c712b7deb3a9..82a97866e0cf 100644
--- a/drivers/mmc/host/alcor.c
+++ b/drivers/mmc/host/alcor.c
@@ -1044,14 +1044,27 @@ static void alcor_init_mmc(struct alcor_sdmmc_host *host)
1044 mmc->caps2 = MMC_CAP2_NO_SDIO; 1044 mmc->caps2 = MMC_CAP2_NO_SDIO;
1045 mmc->ops = &alcor_sdc_ops; 1045 mmc->ops = &alcor_sdc_ops;
1046 1046
1047 /* Hardware cannot do scatter lists */ 1047 /* The hardware does DMA data transfer of 4096 bytes to/from a single
1048 * buffer address. Scatterlists are not supported, but upon DMA
1049 * completion (signalled via IRQ), the original vendor driver does
1050 * then immediately set up another DMA transfer of the next 4096
1051 * bytes.
1052 *
1053 * This means that we need to handle the I/O in 4096 byte chunks.
1054 * Lacking a way to limit the sglist entries to 4096 bytes, we instead
1055 * impose that only one segment is provided, with maximum size 4096,
1056 * which also happens to be the minimum size. This means that the
1057 * single-entry sglist handled by this driver can be handed directly
1058 * to the hardware, nice and simple.
1059 *
1060 * Unfortunately though, that means we only do 4096 bytes I/O per
1061 * MMC command. A future improvement would be to make the driver
1062 * accept sg lists and entries of any size, and simply iterate
1063 * through them 4096 bytes at a time.
1064 */
1048 mmc->max_segs = AU6601_MAX_DMA_SEGMENTS; 1065 mmc->max_segs = AU6601_MAX_DMA_SEGMENTS;
1049 mmc->max_seg_size = AU6601_MAX_DMA_BLOCK_SIZE; 1066 mmc->max_seg_size = AU6601_MAX_DMA_BLOCK_SIZE;
1050 1067 mmc->max_req_size = mmc->max_seg_size;
1051 mmc->max_blk_size = mmc->max_seg_size;
1052 mmc->max_blk_count = mmc->max_segs;
1053
1054 mmc->max_req_size = mmc->max_seg_size * mmc->max_segs;
1055} 1068}
1056 1069
1057static int alcor_pci_sdmmc_drv_probe(struct platform_device *pdev) 1070static int alcor_pci_sdmmc_drv_probe(struct platform_device *pdev)
diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c
index 49e0daf2ef5e..f37003df1e01 100644
--- a/drivers/mmc/host/davinci_mmc.c
+++ b/drivers/mmc/host/davinci_mmc.c
@@ -1117,7 +1117,7 @@ static inline void mmc_davinci_cpufreq_deregister(struct mmc_davinci_host *host)
1117{ 1117{
1118} 1118}
1119#endif 1119#endif
1120static void __init init_mmcsd_host(struct mmc_davinci_host *host) 1120static void init_mmcsd_host(struct mmc_davinci_host *host)
1121{ 1121{
1122 1122
1123 mmc_davinci_reset_ctrl(host, 1); 1123 mmc_davinci_reset_ctrl(host, 1);
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index d54612257b06..45f7b9b53d48 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -290,11 +290,8 @@ static void mxcmci_swap_buffers(struct mmc_data *data)
290 struct scatterlist *sg; 290 struct scatterlist *sg;
291 int i; 291 int i;
292 292
293 for_each_sg(data->sg, sg, data->sg_len, i) { 293 for_each_sg(data->sg, sg, data->sg_len, i)
294 void *buf = kmap_atomic(sg_page(sg) + sg->offset); 294 buffer_swap32(sg_virt(sg), sg->length);
295 buffer_swap32(buf, sg->length);
296 kunmap_atomic(buf);
297 }
298} 295}
299#else 296#else
300static inline void mxcmci_swap_buffers(struct mmc_data *data) {} 297static inline void mxcmci_swap_buffers(struct mmc_data *data) {}
@@ -611,7 +608,6 @@ static int mxcmci_transfer_data(struct mxcmci_host *host)
611{ 608{
612 struct mmc_data *data = host->req->data; 609 struct mmc_data *data = host->req->data;
613 struct scatterlist *sg; 610 struct scatterlist *sg;
614 void *buf;
615 int stat, i; 611 int stat, i;
616 612
617 host->data = data; 613 host->data = data;
@@ -619,18 +615,14 @@ static int mxcmci_transfer_data(struct mxcmci_host *host)
619 615
620 if (data->flags & MMC_DATA_READ) { 616 if (data->flags & MMC_DATA_READ) {
621 for_each_sg(data->sg, sg, data->sg_len, i) { 617 for_each_sg(data->sg, sg, data->sg_len, i) {
622 buf = kmap_atomic(sg_page(sg) + sg->offset); 618 stat = mxcmci_pull(host, sg_virt(sg), sg->length);
623 stat = mxcmci_pull(host, buf, sg->length);
624 kunmap(buf);
625 if (stat) 619 if (stat)
626 return stat; 620 return stat;
627 host->datasize += sg->length; 621 host->datasize += sg->length;
628 } 622 }
629 } else { 623 } else {
630 for_each_sg(data->sg, sg, data->sg_len, i) { 624 for_each_sg(data->sg, sg, data->sg_len, i) {
631 buf = kmap_atomic(sg_page(sg) + sg->offset); 625 stat = mxcmci_push(host, sg_virt(sg), sg->length);
632 stat = mxcmci_push(host, buf, sg->length);
633 kunmap(buf);
634 if (stat) 626 if (stat)
635 return stat; 627 return stat;
636 host->datasize += sg->length; 628 host->datasize += sg->length;
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index c907bf502a12..c1d3f0e38921 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -162,7 +162,7 @@ static void pxamci_dma_irq(void *param);
162static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data) 162static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
163{ 163{
164 struct dma_async_tx_descriptor *tx; 164 struct dma_async_tx_descriptor *tx;
165 enum dma_data_direction direction; 165 enum dma_transfer_direction direction;
166 struct dma_slave_config config; 166 struct dma_slave_config config;
167 struct dma_chan *chan; 167 struct dma_chan *chan;
168 unsigned int nob = data->blocks; 168 unsigned int nob = data->blocks;
diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c
index 71e13844df6c..8742e27e4e8b 100644
--- a/drivers/mmc/host/renesas_sdhi_core.c
+++ b/drivers/mmc/host/renesas_sdhi_core.c
@@ -641,6 +641,7 @@ int renesas_sdhi_probe(struct platform_device *pdev,
641 struct renesas_sdhi *priv; 641 struct renesas_sdhi *priv;
642 struct resource *res; 642 struct resource *res;
643 int irq, ret, i; 643 int irq, ret, i;
644 u16 ver;
644 645
645 of_data = of_device_get_match_data(&pdev->dev); 646 of_data = of_device_get_match_data(&pdev->dev);
646 647
@@ -773,12 +774,17 @@ int renesas_sdhi_probe(struct platform_device *pdev,
773 if (ret) 774 if (ret)
774 goto efree; 775 goto efree;
775 776
777 ver = sd_ctrl_read16(host, CTL_VERSION);
778 /* GEN2_SDR104 is first known SDHI to use 32bit block count */
779 if (ver < SDHI_VER_GEN2_SDR104 && mmc_data->max_blk_count > U16_MAX)
780 mmc_data->max_blk_count = U16_MAX;
781
776 ret = tmio_mmc_host_probe(host); 782 ret = tmio_mmc_host_probe(host);
777 if (ret < 0) 783 if (ret < 0)
778 goto edisclk; 784 goto edisclk;
779 785
780 /* One Gen2 SDHI incarnation does NOT have a CBSY bit */ 786 /* One Gen2 SDHI incarnation does NOT have a CBSY bit */
781 if (sd_ctrl_read16(host, CTL_VERSION) == SDHI_VER_GEN2_SDR50) 787 if (ver == SDHI_VER_GEN2_SDR50)
782 mmc_data->flags &= ~TMIO_MMC_HAVE_CBSY; 788 mmc_data->flags &= ~TMIO_MMC_HAVE_CBSY;
783 789
784 /* Enable tuning iff we have an SCC and a supported mode */ 790 /* Enable tuning iff we have an SCC and a supported mode */
diff --git a/drivers/mmc/host/sdhci-omap.c b/drivers/mmc/host/sdhci-omap.c
index b1a66ca3821a..5bbed477c9b1 100644
--- a/drivers/mmc/host/sdhci-omap.c
+++ b/drivers/mmc/host/sdhci-omap.c
@@ -1056,6 +1056,9 @@ static int sdhci_omap_probe(struct platform_device *pdev)
1056 mmc->f_max = 48000000; 1056 mmc->f_max = 48000000;
1057 } 1057 }
1058 1058
1059 if (!mmc_can_gpio_ro(mmc))
1060 mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;
1061
1059 pltfm_host->clk = devm_clk_get(dev, "fck"); 1062 pltfm_host->clk = devm_clk_get(dev, "fck");
1060 if (IS_ERR(pltfm_host->clk)) { 1063 if (IS_ERR(pltfm_host->clk)) {
1061 ret = PTR_ERR(pltfm_host->clk); 1064 ret = PTR_ERR(pltfm_host->clk);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/qp.c b/drivers/net/ethernet/mellanox/mlx5/core/qp.c
index 370ca94b6775..b8ba74de9555 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/qp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/qp.c
@@ -40,6 +40,9 @@
40#include "mlx5_core.h" 40#include "mlx5_core.h"
41#include "lib/eq.h" 41#include "lib/eq.h"
42 42
43static int mlx5_core_drain_dct(struct mlx5_core_dev *dev,
44 struct mlx5_core_dct *dct);
45
43static struct mlx5_core_rsc_common * 46static struct mlx5_core_rsc_common *
44mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn) 47mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn)
45{ 48{
@@ -227,20 +230,49 @@ static void destroy_resource_common(struct mlx5_core_dev *dev,
227 wait_for_completion(&qp->common.free); 230 wait_for_completion(&qp->common.free);
228} 231}
229 232
233static int _mlx5_core_destroy_dct(struct mlx5_core_dev *dev,
234 struct mlx5_core_dct *dct, bool need_cleanup)
235{
236 u32 out[MLX5_ST_SZ_DW(destroy_dct_out)] = {0};
237 u32 in[MLX5_ST_SZ_DW(destroy_dct_in)] = {0};
238 struct mlx5_core_qp *qp = &dct->mqp;
239 int err;
240
241 err = mlx5_core_drain_dct(dev, dct);
242 if (err) {
243 if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) {
244 goto destroy;
245 } else {
246 mlx5_core_warn(
247 dev, "failed drain DCT 0x%x with error 0x%x\n",
248 qp->qpn, err);
249 return err;
250 }
251 }
252 wait_for_completion(&dct->drained);
253destroy:
254 if (need_cleanup)
255 destroy_resource_common(dev, &dct->mqp);
256 MLX5_SET(destroy_dct_in, in, opcode, MLX5_CMD_OP_DESTROY_DCT);
257 MLX5_SET(destroy_dct_in, in, dctn, qp->qpn);
258 MLX5_SET(destroy_dct_in, in, uid, qp->uid);
259 err = mlx5_cmd_exec(dev, (void *)&in, sizeof(in),
260 (void *)&out, sizeof(out));
261 return err;
262}
263
230int mlx5_core_create_dct(struct mlx5_core_dev *dev, 264int mlx5_core_create_dct(struct mlx5_core_dev *dev,
231 struct mlx5_core_dct *dct, 265 struct mlx5_core_dct *dct,
232 u32 *in, int inlen) 266 u32 *in, int inlen,
267 u32 *out, int outlen)
233{ 268{
234 u32 out[MLX5_ST_SZ_DW(create_dct_out)] = {0};
235 u32 din[MLX5_ST_SZ_DW(destroy_dct_in)] = {0};
236 u32 dout[MLX5_ST_SZ_DW(destroy_dct_out)] = {0};
237 struct mlx5_core_qp *qp = &dct->mqp; 269 struct mlx5_core_qp *qp = &dct->mqp;
238 int err; 270 int err;
239 271
240 init_completion(&dct->drained); 272 init_completion(&dct->drained);
241 MLX5_SET(create_dct_in, in, opcode, MLX5_CMD_OP_CREATE_DCT); 273 MLX5_SET(create_dct_in, in, opcode, MLX5_CMD_OP_CREATE_DCT);
242 274
243 err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out)); 275 err = mlx5_cmd_exec(dev, in, inlen, out, outlen);
244 if (err) { 276 if (err) {
245 mlx5_core_warn(dev, "create DCT failed, ret %d\n", err); 277 mlx5_core_warn(dev, "create DCT failed, ret %d\n", err);
246 return err; 278 return err;
@@ -254,11 +286,7 @@ int mlx5_core_create_dct(struct mlx5_core_dev *dev,
254 286
255 return 0; 287 return 0;
256err_cmd: 288err_cmd:
257 MLX5_SET(destroy_dct_in, din, opcode, MLX5_CMD_OP_DESTROY_DCT); 289 _mlx5_core_destroy_dct(dev, dct, false);
258 MLX5_SET(destroy_dct_in, din, dctn, qp->qpn);
259 MLX5_SET(destroy_dct_in, din, uid, qp->uid);
260 mlx5_cmd_exec(dev, (void *)&in, sizeof(din),
261 (void *)&out, sizeof(dout));
262 return err; 290 return err;
263} 291}
264EXPORT_SYMBOL_GPL(mlx5_core_create_dct); 292EXPORT_SYMBOL_GPL(mlx5_core_create_dct);
@@ -323,29 +351,7 @@ static int mlx5_core_drain_dct(struct mlx5_core_dev *dev,
323int mlx5_core_destroy_dct(struct mlx5_core_dev *dev, 351int mlx5_core_destroy_dct(struct mlx5_core_dev *dev,
324 struct mlx5_core_dct *dct) 352 struct mlx5_core_dct *dct)
325{ 353{
326 u32 out[MLX5_ST_SZ_DW(destroy_dct_out)] = {0}; 354 return _mlx5_core_destroy_dct(dev, dct, true);
327 u32 in[MLX5_ST_SZ_DW(destroy_dct_in)] = {0};
328 struct mlx5_core_qp *qp = &dct->mqp;
329 int err;
330
331 err = mlx5_core_drain_dct(dev, dct);
332 if (err) {
333 if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) {
334 goto destroy;
335 } else {
336 mlx5_core_warn(dev, "failed drain DCT 0x%x with error 0x%x\n", qp->qpn, err);
337 return err;
338 }
339 }
340 wait_for_completion(&dct->drained);
341destroy:
342 destroy_resource_common(dev, &dct->mqp);
343 MLX5_SET(destroy_dct_in, in, opcode, MLX5_CMD_OP_DESTROY_DCT);
344 MLX5_SET(destroy_dct_in, in, dctn, qp->qpn);
345 MLX5_SET(destroy_dct_in, in, uid, qp->uid);
346 err = mlx5_cmd_exec(dev, (void *)&in, sizeof(in),
347 (void *)&out, sizeof(out));
348 return err;
349} 355}
350EXPORT_SYMBOL_GPL(mlx5_core_destroy_dct); 356EXPORT_SYMBOL_GPL(mlx5_core_destroy_dct);
351 357
diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c
index 900c7073c46f..71308766e891 100644
--- a/drivers/platform/chrome/cros_ec_debugfs.c
+++ b/drivers/platform/chrome/cros_ec_debugfs.c
@@ -440,7 +440,7 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
440 440
441 ret = cros_ec_create_pdinfo(debug_info); 441 ret = cros_ec_create_pdinfo(debug_info);
442 if (ret) 442 if (ret)
443 goto remove_debugfs; 443 goto remove_log;
444 444
445 ec->debug_info = debug_info; 445 ec->debug_info = debug_info;
446 446
@@ -448,6 +448,8 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
448 448
449 return 0; 449 return 0;
450 450
451remove_log:
452 cros_ec_cleanup_console_log(debug_info);
451remove_debugfs: 453remove_debugfs:
452 debugfs_remove_recursive(debug_info->dir); 454 debugfs_remove_recursive(debug_info->dir);
453 return ret; 455 return ret;
@@ -467,7 +469,8 @@ static int __maybe_unused cros_ec_debugfs_suspend(struct device *dev)
467{ 469{
468 struct cros_ec_dev *ec = dev_get_drvdata(dev); 470 struct cros_ec_dev *ec = dev_get_drvdata(dev);
469 471
470 cancel_delayed_work_sync(&ec->debug_info->log_poll_work); 472 if (ec->debug_info->log_buffer.buf)
473 cancel_delayed_work_sync(&ec->debug_info->log_poll_work);
471 474
472 return 0; 475 return 0;
473} 476}
@@ -476,7 +479,8 @@ static int __maybe_unused cros_ec_debugfs_resume(struct device *dev)
476{ 479{
477 struct cros_ec_dev *ec = dev_get_drvdata(dev); 480 struct cros_ec_dev *ec = dev_get_drvdata(dev);
478 481
479 schedule_delayed_work(&ec->debug_info->log_poll_work, 0); 482 if (ec->debug_info->log_buffer.buf)
483 schedule_delayed_work(&ec->debug_info->log_poll_work, 0);
480 484
481 return 0; 485 return 0;
482} 486}
diff --git a/drivers/platform/chrome/wilco_ec/mailbox.c b/drivers/platform/chrome/wilco_ec/mailbox.c
index f6ff29a11f1a..14355668ddfa 100644
--- a/drivers/platform/chrome/wilco_ec/mailbox.c
+++ b/drivers/platform/chrome/wilco_ec/mailbox.c
@@ -223,11 +223,11 @@ int wilco_ec_mailbox(struct wilco_ec_device *ec, struct wilco_ec_message *msg)
223 msg->command, msg->type, msg->flags, msg->response_size, 223 msg->command, msg->type, msg->flags, msg->response_size,
224 msg->request_size); 224 msg->request_size);
225 225
226 mutex_lock(&ec->mailbox_lock);
226 /* Prepare request packet */ 227 /* Prepare request packet */
227 rq = ec->data_buffer; 228 rq = ec->data_buffer;
228 wilco_ec_prepare(msg, rq); 229 wilco_ec_prepare(msg, rq);
229 230
230 mutex_lock(&ec->mailbox_lock);
231 ret = wilco_ec_transfer(ec, msg, rq); 231 ret = wilco_ec_transfer(ec, msg, rq);
232 mutex_unlock(&ec->mailbox_lock); 232 mutex_unlock(&ec->mailbox_lock);
233 233
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 3c3cf89f713f..14bac4966c87 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -1801,6 +1801,12 @@ static int hisi_sas_I_T_nexus_reset(struct domain_device *device)
1801 } 1801 }
1802 hisi_sas_dereg_device(hisi_hba, device); 1802 hisi_sas_dereg_device(hisi_hba, device);
1803 1803
1804 if (dev_is_sata(device)) {
1805 rc = hisi_sas_softreset_ata_disk(device);
1806 if (rc)
1807 return TMF_RESP_FUNC_FAILED;
1808 }
1809
1804 rc = hisi_sas_debug_I_T_nexus_reset(device); 1810 rc = hisi_sas_debug_I_T_nexus_reset(device);
1805 1811
1806 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) 1812 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV))
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 1135e74646e2..8cec5230fe31 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -96,6 +96,7 @@ static int client_reserve = 1;
96static char partition_name[96] = "UNKNOWN"; 96static char partition_name[96] = "UNKNOWN";
97static unsigned int partition_number = -1; 97static unsigned int partition_number = -1;
98static LIST_HEAD(ibmvscsi_head); 98static LIST_HEAD(ibmvscsi_head);
99static DEFINE_SPINLOCK(ibmvscsi_driver_lock);
99 100
100static struct scsi_transport_template *ibmvscsi_transport_template; 101static struct scsi_transport_template *ibmvscsi_transport_template;
101 102
@@ -2270,7 +2271,9 @@ static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
2270 } 2271 }
2271 2272
2272 dev_set_drvdata(&vdev->dev, hostdata); 2273 dev_set_drvdata(&vdev->dev, hostdata);
2274 spin_lock(&ibmvscsi_driver_lock);
2273 list_add_tail(&hostdata->host_list, &ibmvscsi_head); 2275 list_add_tail(&hostdata->host_list, &ibmvscsi_head);
2276 spin_unlock(&ibmvscsi_driver_lock);
2274 return 0; 2277 return 0;
2275 2278
2276 add_srp_port_failed: 2279 add_srp_port_failed:
@@ -2292,15 +2295,27 @@ static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
2292static int ibmvscsi_remove(struct vio_dev *vdev) 2295static int ibmvscsi_remove(struct vio_dev *vdev)
2293{ 2296{
2294 struct ibmvscsi_host_data *hostdata = dev_get_drvdata(&vdev->dev); 2297 struct ibmvscsi_host_data *hostdata = dev_get_drvdata(&vdev->dev);
2295 list_del(&hostdata->host_list); 2298 unsigned long flags;
2296 unmap_persist_bufs(hostdata); 2299
2300 srp_remove_host(hostdata->host);
2301 scsi_remove_host(hostdata->host);
2302
2303 purge_requests(hostdata, DID_ERROR);
2304
2305 spin_lock_irqsave(hostdata->host->host_lock, flags);
2297 release_event_pool(&hostdata->pool, hostdata); 2306 release_event_pool(&hostdata->pool, hostdata);
2307 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
2308
2298 ibmvscsi_release_crq_queue(&hostdata->queue, hostdata, 2309 ibmvscsi_release_crq_queue(&hostdata->queue, hostdata,
2299 max_events); 2310 max_events);
2300 2311
2301 kthread_stop(hostdata->work_thread); 2312 kthread_stop(hostdata->work_thread);
2302 srp_remove_host(hostdata->host); 2313 unmap_persist_bufs(hostdata);
2303 scsi_remove_host(hostdata->host); 2314
2315 spin_lock(&ibmvscsi_driver_lock);
2316 list_del(&hostdata->host_list);
2317 spin_unlock(&ibmvscsi_driver_lock);
2318
2304 scsi_host_put(hostdata->host); 2319 scsi_host_put(hostdata->host);
2305 2320
2306 return 0; 2321 return 0;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 420045155ba0..0c700b140ce7 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -4991,6 +4991,13 @@ qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4991 if ((domain & 0xf0) == 0xf0) 4991 if ((domain & 0xf0) == 0xf0)
4992 continue; 4992 continue;
4993 4993
4994 /* Bypass if not same domain and area of adapter. */
4995 if (area && domain && ((area != vha->d_id.b.area) ||
4996 (domain != vha->d_id.b.domain)) &&
4997 (ha->current_topology == ISP_CFG_NL))
4998 continue;
4999
5000
4994 /* Bypass invalid local loop ID. */ 5001 /* Bypass invalid local loop ID. */
4995 if (loop_id > LAST_LOCAL_LOOP_ID) 5002 if (loop_id > LAST_LOCAL_LOOP_ID)
4996 continue; 5003 continue;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 677f82fdf56f..91f576d743fe 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1517,7 +1517,7 @@ __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
1517 goto eh_reset_failed; 1517 goto eh_reset_failed;
1518 } 1518 }
1519 err = 2; 1519 err = 2;
1520 if (do_reset(fcport, cmd->device->lun, blk_mq_rq_cpu(cmd->request) + 1) 1520 if (do_reset(fcport, cmd->device->lun, 1)
1521 != QLA_SUCCESS) { 1521 != QLA_SUCCESS) {
1522 ql_log(ql_log_warn, vha, 0x800c, 1522 ql_log(ql_log_warn, vha, 0x800c,
1523 "do_reset failed for cmd=%p.\n", cmd); 1523 "do_reset failed for cmd=%p.\n", cmd);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 20189675677a..601b9f1de267 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -585,10 +585,17 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
585 if (!blk_rq_is_scsi(req)) { 585 if (!blk_rq_is_scsi(req)) {
586 WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED)); 586 WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED));
587 cmd->flags &= ~SCMD_INITIALIZED; 587 cmd->flags &= ~SCMD_INITIALIZED;
588 destroy_rcu_head(&cmd->rcu);
589 } 588 }
590 589
591 /* 590 /*
591 * Calling rcu_barrier() is not necessary here because the
592 * SCSI error handler guarantees that the function called by
593 * call_rcu() has been called before scsi_end_request() is
594 * called.
595 */
596 destroy_rcu_head(&cmd->rcu);
597
598 /*
592 * In the MQ case the command gets freed by __blk_mq_end_request, 599 * In the MQ case the command gets freed by __blk_mq_end_request,
593 * so we have to do all cleanup that depends on it earlier. 600 * so we have to do all cleanup that depends on it earlier.
594 * 601 *
@@ -2541,8 +2548,10 @@ void scsi_device_resume(struct scsi_device *sdev)
2541 * device deleted during suspend) 2548 * device deleted during suspend)
2542 */ 2549 */
2543 mutex_lock(&sdev->state_mutex); 2550 mutex_lock(&sdev->state_mutex);
2544 sdev->quiesced_by = NULL; 2551 if (sdev->quiesced_by) {
2545 blk_clear_pm_only(sdev->request_queue); 2552 sdev->quiesced_by = NULL;
2553 blk_clear_pm_only(sdev->request_queue);
2554 }
2546 if (sdev->sdev_state == SDEV_QUIESCE) 2555 if (sdev->sdev_state == SDEV_QUIESCE)
2547 scsi_device_set_state(sdev, SDEV_RUNNING); 2556 scsi_device_set_state(sdev, SDEV_RUNNING);
2548 mutex_unlock(&sdev->state_mutex); 2557 mutex_unlock(&sdev->state_mutex);
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 0508831d6fb9..0a82e93566dc 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -2200,6 +2200,8 @@ void iscsi_remove_session(struct iscsi_cls_session *session)
2200 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE); 2200 scsi_target_unblock(&session->dev, SDEV_TRANSPORT_OFFLINE);
2201 /* flush running scans then delete devices */ 2201 /* flush running scans then delete devices */
2202 flush_work(&session->scan_work); 2202 flush_work(&session->scan_work);
2203 /* flush running unbind operations */
2204 flush_work(&session->unbind_work);
2203 __iscsi_unbind_session(&session->unbind_work); 2205 __iscsi_unbind_session(&session->unbind_work);
2204 2206
2205 /* hw iscsi may not have removed all connections from session */ 2207 /* hw iscsi may not have removed all connections from session */
diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c
index 720760cd493f..ba39647a690c 100644
--- a/drivers/thermal/broadcom/bcm2835_thermal.c
+++ b/drivers/thermal/broadcom/bcm2835_thermal.c
@@ -119,8 +119,7 @@ static const struct debugfs_reg32 bcm2835_thermal_regs[] = {
119 119
120static void bcm2835_thermal_debugfs(struct platform_device *pdev) 120static void bcm2835_thermal_debugfs(struct platform_device *pdev)
121{ 121{
122 struct thermal_zone_device *tz = platform_get_drvdata(pdev); 122 struct bcm2835_thermal_data *data = platform_get_drvdata(pdev);
123 struct bcm2835_thermal_data *data = tz->devdata;
124 struct debugfs_regset32 *regset; 123 struct debugfs_regset32 *regset;
125 124
126 data->debugfsdir = debugfs_create_dir("bcm2835_thermal", NULL); 125 data->debugfsdir = debugfs_create_dir("bcm2835_thermal", NULL);
@@ -266,7 +265,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
266 265
267 data->tz = tz; 266 data->tz = tz;
268 267
269 platform_set_drvdata(pdev, tz); 268 platform_set_drvdata(pdev, data);
270 269
271 /* 270 /*
272 * Thermal_zone doesn't enable hwmon as default, 271 * Thermal_zone doesn't enable hwmon as default,
@@ -290,8 +289,8 @@ err_clk:
290 289
291static int bcm2835_thermal_remove(struct platform_device *pdev) 290static int bcm2835_thermal_remove(struct platform_device *pdev)
292{ 291{
293 struct thermal_zone_device *tz = platform_get_drvdata(pdev); 292 struct bcm2835_thermal_data *data = platform_get_drvdata(pdev);
294 struct bcm2835_thermal_data *data = tz->devdata; 293 struct thermal_zone_device *tz = data->tz;
295 294
296 debugfs_remove_recursive(data->debugfsdir); 295 debugfs_remove_recursive(data->debugfsdir);
297 thermal_zone_of_sensor_unregister(&pdev->dev, tz); 296 thermal_zone_of_sensor_unregister(&pdev->dev, tz);
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 6fff16113628..f7c1f49ec87f 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -536,12 +536,11 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
536 struct thermal_zone_device *tz, u32 power, 536 struct thermal_zone_device *tz, u32 power,
537 unsigned long *state) 537 unsigned long *state)
538{ 538{
539 unsigned int cur_freq, target_freq; 539 unsigned int target_freq;
540 u32 last_load, normalised_power; 540 u32 last_load, normalised_power;
541 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; 541 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
542 struct cpufreq_policy *policy = cpufreq_cdev->policy; 542 struct cpufreq_policy *policy = cpufreq_cdev->policy;
543 543
544 cur_freq = cpufreq_quick_get(policy->cpu);
545 power = power > 0 ? power : 0; 544 power = power > 0 ? power : 0;
546 last_load = cpufreq_cdev->last_load ?: 1; 545 last_load = cpufreq_cdev->last_load ?: 1;
547 normalised_power = (power * 100) / last_load; 546 normalised_power = (power * 100) / last_load;
diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index 61ca7ce3624e..5f3ed24e26ec 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -22,6 +22,13 @@ enum int3400_thermal_uuid {
22 INT3400_THERMAL_PASSIVE_1, 22 INT3400_THERMAL_PASSIVE_1,
23 INT3400_THERMAL_ACTIVE, 23 INT3400_THERMAL_ACTIVE,
24 INT3400_THERMAL_CRITICAL, 24 INT3400_THERMAL_CRITICAL,
25 INT3400_THERMAL_ADAPTIVE_PERFORMANCE,
26 INT3400_THERMAL_EMERGENCY_CALL_MODE,
27 INT3400_THERMAL_PASSIVE_2,
28 INT3400_THERMAL_POWER_BOSS,
29 INT3400_THERMAL_VIRTUAL_SENSOR,
30 INT3400_THERMAL_COOLING_MODE,
31 INT3400_THERMAL_HARDWARE_DUTY_CYCLING,
25 INT3400_THERMAL_MAXIMUM_UUID, 32 INT3400_THERMAL_MAXIMUM_UUID,
26}; 33};
27 34
@@ -29,6 +36,13 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = {
29 "42A441D6-AE6A-462b-A84B-4A8CE79027D3", 36 "42A441D6-AE6A-462b-A84B-4A8CE79027D3",
30 "3A95C389-E4B8-4629-A526-C52C88626BAE", 37 "3A95C389-E4B8-4629-A526-C52C88626BAE",
31 "97C68AE7-15FA-499c-B8C9-5DA81D606E0A", 38 "97C68AE7-15FA-499c-B8C9-5DA81D606E0A",
39 "63BE270F-1C11-48FD-A6F7-3AF253FF3E2D",
40 "5349962F-71E6-431D-9AE8-0A635B710AEE",
41 "9E04115A-AE87-4D1C-9500-0F3E340BFE75",
42 "F5A35014-C209-46A4-993A-EB56DE7530A1",
43 "6ED722A7-9240-48A5-B479-31EEF723D7CF",
44 "16CAF1B7-DD38-40ED-B1C1-1B8A1913D531",
45 "BE84BABF-C4D4-403D-B495-3128FD44dAC1",
32}; 46};
33 47
34struct int3400_thermal_priv { 48struct int3400_thermal_priv {
@@ -299,10 +313,9 @@ static int int3400_thermal_probe(struct platform_device *pdev)
299 313
300 platform_set_drvdata(pdev, priv); 314 platform_set_drvdata(pdev, priv);
301 315
302 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) { 316 int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
303 int3400_thermal_ops.get_mode = int3400_thermal_get_mode; 317 int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
304 int3400_thermal_ops.set_mode = int3400_thermal_set_mode; 318
305 }
306 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0, 319 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
307 priv, &int3400_thermal_ops, 320 priv, &int3400_thermal_ops,
308 &int3400_thermal_params, 0, 0); 321 &int3400_thermal_params, 0, 0);
diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c
index 7571f7c2e7c9..ac7256b5f020 100644
--- a/drivers/thermal/intel/intel_powerclamp.c
+++ b/drivers/thermal/intel/intel_powerclamp.c
@@ -101,7 +101,7 @@ struct powerclamp_worker_data {
101 bool clamping; 101 bool clamping;
102}; 102};
103 103
104static struct powerclamp_worker_data * __percpu worker_data; 104static struct powerclamp_worker_data __percpu *worker_data;
105static struct thermal_cooling_device *cooling_dev; 105static struct thermal_cooling_device *cooling_dev;
106static unsigned long *cpu_clamping_mask; /* bit map for tracking per cpu 106static unsigned long *cpu_clamping_mask; /* bit map for tracking per cpu
107 * clamping kthread worker 107 * clamping kthread worker
@@ -494,7 +494,7 @@ static void start_power_clamp_worker(unsigned long cpu)
494 struct powerclamp_worker_data *w_data = per_cpu_ptr(worker_data, cpu); 494 struct powerclamp_worker_data *w_data = per_cpu_ptr(worker_data, cpu);
495 struct kthread_worker *worker; 495 struct kthread_worker *worker;
496 496
497 worker = kthread_create_worker_on_cpu(cpu, 0, "kidle_inject/%ld", cpu); 497 worker = kthread_create_worker_on_cpu(cpu, 0, "kidle_inj/%ld", cpu);
498 if (IS_ERR(worker)) 498 if (IS_ERR(worker))
499 return; 499 return;
500 500
diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index 5c07a61447d3..e4ea7f6aef20 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -199,6 +199,9 @@ enum {
199#define MT7622_TS1 0 199#define MT7622_TS1 0
200#define MT7622_NUM_CONTROLLER 1 200#define MT7622_NUM_CONTROLLER 1
201 201
202/* The maximum number of banks */
203#define MAX_NUM_ZONES 8
204
202/* The calibration coefficient of sensor */ 205/* The calibration coefficient of sensor */
203#define MT7622_CALIBRATION 165 206#define MT7622_CALIBRATION 165
204 207
@@ -249,7 +252,7 @@ struct mtk_thermal_data {
249 const int num_controller; 252 const int num_controller;
250 const int *controller_offset; 253 const int *controller_offset;
251 bool need_switch_bank; 254 bool need_switch_bank;
252 struct thermal_bank_cfg bank_data[]; 255 struct thermal_bank_cfg bank_data[MAX_NUM_ZONES];
253}; 256};
254 257
255struct mtk_thermal { 258struct mtk_thermal {
@@ -268,7 +271,7 @@ struct mtk_thermal {
268 s32 vts[MAX_NUM_VTS]; 271 s32 vts[MAX_NUM_VTS];
269 272
270 const struct mtk_thermal_data *conf; 273 const struct mtk_thermal_data *conf;
271 struct mtk_thermal_bank banks[]; 274 struct mtk_thermal_bank banks[MAX_NUM_ZONES];
272}; 275};
273 276
274/* MT8183 thermal sensor data */ 277/* MT8183 thermal sensor data */
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 48eef552cba4..fc9399d9c082 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -666,7 +666,7 @@ static int exynos_get_temp(void *p, int *temp)
666 struct exynos_tmu_data *data = p; 666 struct exynos_tmu_data *data = p;
667 int value, ret = 0; 667 int value, ret = 0;
668 668
669 if (!data || !data->tmu_read || !data->enabled) 669 if (!data || !data->tmu_read)
670 return -EINVAL; 670 return -EINVAL;
671 else if (!data->enabled) 671 else if (!data->enabled)
672 /* 672 /*
diff --git a/fs/block_dev.c b/fs/block_dev.c
index e9faa52bb489..78d3257435c0 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -336,12 +336,14 @@ static void blkdev_bio_end_io(struct bio *bio)
336 if (should_dirty) { 336 if (should_dirty) {
337 bio_check_pages_dirty(bio); 337 bio_check_pages_dirty(bio);
338 } else { 338 } else {
339 struct bio_vec *bvec; 339 if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
340 int i; 340 struct bvec_iter_all iter_all;
341 struct bvec_iter_all iter_all; 341 struct bio_vec *bvec;
342 int i;
342 343
343 bio_for_each_segment_all(bvec, bio, i, iter_all) 344 bio_for_each_segment_all(bvec, bio, i, iter_all)
344 put_page(bvec->bv_page); 345 put_page(bvec->bv_page);
346 }
345 bio_put(bio); 347 bio_put(bio);
346 } 348 }
347} 349}
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 217276b8b942..f9b71c12cc9f 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -1008,7 +1008,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
1008 unsigned int xid; 1008 unsigned int xid;
1009 int rc; 1009 int rc;
1010 1010
1011 if (remap_flags & ~REMAP_FILE_ADVISORY) 1011 if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))
1012 return -EINVAL; 1012 return -EINVAL;
1013 1013
1014 cifs_dbg(FYI, "clone range\n"); 1014 cifs_dbg(FYI, "clone range\n");
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 142164ef1f05..5c0298b9998f 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -150,5 +150,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
150extern const struct export_operations cifs_export_ops; 150extern const struct export_operations cifs_export_ops;
151#endif /* CONFIG_CIFS_NFSD_EXPORT */ 151#endif /* CONFIG_CIFS_NFSD_EXPORT */
152 152
153#define CIFS_VERSION "2.18" 153#define CIFS_VERSION "2.19"
154#endif /* _CIFSFS_H */ 154#endif /* _CIFSFS_H */
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 2a6d20c0ce02..89006e044973 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2632,43 +2632,56 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
2632 struct TCP_Server_Info *server = 2632 struct TCP_Server_Info *server =
2633 tlink_tcon(wdata->cfile->tlink)->ses->server; 2633 tlink_tcon(wdata->cfile->tlink)->ses->server;
2634 2634
2635 /*
2636 * Wait for credits to resend this wdata.
2637 * Note: we are attempting to resend the whole wdata not in segments
2638 */
2639 do { 2635 do {
2640 rc = server->ops->wait_mtu_credits(server, wdata->bytes, &wsize, 2636 if (wdata->cfile->invalidHandle) {
2641 &credits); 2637 rc = cifs_reopen_file(wdata->cfile, false);
2638 if (rc == -EAGAIN)
2639 continue;
2640 else if (rc)
2641 break;
2642 }
2642 2643
2643 if (rc)
2644 goto out;
2645 2644
2646 if (wsize < wdata->bytes) { 2645 /*
2647 add_credits_and_wake_if(server, &credits, 0); 2646 * Wait for credits to resend this wdata.
2648 msleep(1000); 2647 * Note: we are attempting to resend the whole wdata not in
2649 } 2648 * segments
2650 } while (wsize < wdata->bytes); 2649 */
2650 do {
2651 rc = server->ops->wait_mtu_credits(server, wdata->bytes,
2652 &wsize, &credits);
2653 if (rc)
2654 goto fail;
2655
2656 if (wsize < wdata->bytes) {
2657 add_credits_and_wake_if(server, &credits, 0);
2658 msleep(1000);
2659 }
2660 } while (wsize < wdata->bytes);
2661 wdata->credits = credits;
2651 2662
2652 wdata->credits = credits; 2663 rc = adjust_credits(server, &wdata->credits, wdata->bytes);
2653 rc = -EAGAIN; 2664
2654 while (rc == -EAGAIN) { 2665 if (!rc) {
2655 rc = 0; 2666 if (wdata->cfile->invalidHandle)
2656 if (wdata->cfile->invalidHandle) 2667 rc = -EAGAIN;
2657 rc = cifs_reopen_file(wdata->cfile, false); 2668 else
2658 if (!rc) 2669 rc = server->ops->async_writev(wdata,
2659 rc = server->ops->async_writev(wdata,
2660 cifs_uncached_writedata_release); 2670 cifs_uncached_writedata_release);
2661 } 2671 }
2662 2672
2663 if (!rc) { 2673 /* If the write was successfully sent, we are done */
2664 list_add_tail(&wdata->list, wdata_list); 2674 if (!rc) {
2665 return 0; 2675 list_add_tail(&wdata->list, wdata_list);
2666 } 2676 return 0;
2677 }
2667 2678
2668 add_credits_and_wake_if(server, &wdata->credits, 0); 2679 /* Roll back credits and retry if needed */
2669out: 2680 add_credits_and_wake_if(server, &wdata->credits, 0);
2670 kref_put(&wdata->refcount, cifs_uncached_writedata_release); 2681 } while (rc == -EAGAIN);
2671 2682
2683fail:
2684 kref_put(&wdata->refcount, cifs_uncached_writedata_release);
2672 return rc; 2685 return rc;
2673} 2686}
2674 2687
@@ -2896,12 +2909,12 @@ restart_loop:
2896 wdata->bytes, &tmp_from, 2909 wdata->bytes, &tmp_from,
2897 ctx->cfile, cifs_sb, &tmp_list, 2910 ctx->cfile, cifs_sb, &tmp_list,
2898 ctx); 2911 ctx);
2912
2913 kref_put(&wdata->refcount,
2914 cifs_uncached_writedata_release);
2899 } 2915 }
2900 2916
2901 list_splice(&tmp_list, &ctx->list); 2917 list_splice(&tmp_list, &ctx->list);
2902
2903 kref_put(&wdata->refcount,
2904 cifs_uncached_writedata_release);
2905 goto restart_loop; 2918 goto restart_loop;
2906 } 2919 }
2907 } 2920 }
@@ -3348,44 +3361,55 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata,
3348 struct TCP_Server_Info *server = 3361 struct TCP_Server_Info *server =
3349 tlink_tcon(rdata->cfile->tlink)->ses->server; 3362 tlink_tcon(rdata->cfile->tlink)->ses->server;
3350 3363
3351 /*
3352 * Wait for credits to resend this rdata.
3353 * Note: we are attempting to resend the whole rdata not in segments
3354 */
3355 do { 3364 do {
3356 rc = server->ops->wait_mtu_credits(server, rdata->bytes, 3365 if (rdata->cfile->invalidHandle) {
3366 rc = cifs_reopen_file(rdata->cfile, true);
3367 if (rc == -EAGAIN)
3368 continue;
3369 else if (rc)
3370 break;
3371 }
3372
3373 /*
3374 * Wait for credits to resend this rdata.
3375 * Note: we are attempting to resend the whole rdata not in
3376 * segments
3377 */
3378 do {
3379 rc = server->ops->wait_mtu_credits(server, rdata->bytes,
3357 &rsize, &credits); 3380 &rsize, &credits);
3358 3381
3359 if (rc) 3382 if (rc)
3360 goto out; 3383 goto fail;
3361 3384
3362 if (rsize < rdata->bytes) { 3385 if (rsize < rdata->bytes) {
3363 add_credits_and_wake_if(server, &credits, 0); 3386 add_credits_and_wake_if(server, &credits, 0);
3364 msleep(1000); 3387 msleep(1000);
3365 } 3388 }
3366 } while (rsize < rdata->bytes); 3389 } while (rsize < rdata->bytes);
3390 rdata->credits = credits;
3367 3391
3368 rdata->credits = credits; 3392 rc = adjust_credits(server, &rdata->credits, rdata->bytes);
3369 rc = -EAGAIN; 3393 if (!rc) {
3370 while (rc == -EAGAIN) { 3394 if (rdata->cfile->invalidHandle)
3371 rc = 0; 3395 rc = -EAGAIN;
3372 if (rdata->cfile->invalidHandle) 3396 else
3373 rc = cifs_reopen_file(rdata->cfile, true); 3397 rc = server->ops->async_readv(rdata);
3374 if (!rc) 3398 }
3375 rc = server->ops->async_readv(rdata);
3376 }
3377 3399
3378 if (!rc) { 3400 /* If the read was successfully sent, we are done */
3379 /* Add to aio pending list */ 3401 if (!rc) {
3380 list_add_tail(&rdata->list, rdata_list); 3402 /* Add to aio pending list */
3381 return 0; 3403 list_add_tail(&rdata->list, rdata_list);
3382 } 3404 return 0;
3405 }
3383 3406
3384 add_credits_and_wake_if(server, &rdata->credits, 0); 3407 /* Roll back credits and retry if needed */
3385out: 3408 add_credits_and_wake_if(server, &rdata->credits, 0);
3386 kref_put(&rdata->refcount, 3409 } while (rc == -EAGAIN);
3387 cifs_uncached_readdata_release);
3388 3410
3411fail:
3412 kref_put(&rdata->refcount, cifs_uncached_readdata_release);
3389 return rc; 3413 return rc;
3390} 3414}
3391 3415
diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c
index 924269cec135..e32c264e3adb 100644
--- a/fs/cifs/smb2maperror.c
+++ b/fs/cifs/smb2maperror.c
@@ -1036,7 +1036,8 @@ static const struct status_to_posix_error smb2_error_map_table[] = {
1036 {STATUS_UNFINISHED_CONTEXT_DELETED, -EIO, 1036 {STATUS_UNFINISHED_CONTEXT_DELETED, -EIO,
1037 "STATUS_UNFINISHED_CONTEXT_DELETED"}, 1037 "STATUS_UNFINISHED_CONTEXT_DELETED"},
1038 {STATUS_NO_TGT_REPLY, -EIO, "STATUS_NO_TGT_REPLY"}, 1038 {STATUS_NO_TGT_REPLY, -EIO, "STATUS_NO_TGT_REPLY"},
1039 {STATUS_OBJECTID_NOT_FOUND, -EIO, "STATUS_OBJECTID_NOT_FOUND"}, 1039 /* Note that ENOATTTR and ENODATA are the same errno */
1040 {STATUS_OBJECTID_NOT_FOUND, -ENODATA, "STATUS_OBJECTID_NOT_FOUND"},
1040 {STATUS_NO_IP_ADDRESSES, -EIO, "STATUS_NO_IP_ADDRESSES"}, 1041 {STATUS_NO_IP_ADDRESSES, -EIO, "STATUS_NO_IP_ADDRESSES"},
1041 {STATUS_WRONG_CREDENTIAL_HANDLE, -EIO, 1042 {STATUS_WRONG_CREDENTIAL_HANDLE, -EIO,
1042 "STATUS_WRONG_CREDENTIAL_HANDLE"}, 1043 "STATUS_WRONG_CREDENTIAL_HANDLE"},
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index c399e09b76e6..21ac19ff19cb 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -1628,9 +1628,16 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
1628 iov[1].iov_base = unc_path; 1628 iov[1].iov_base = unc_path;
1629 iov[1].iov_len = unc_path_len; 1629 iov[1].iov_len = unc_path_len;
1630 1630
1631 /* 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1 */ 1631 /*
1632 * 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1
1633 * unless it is guest or anonymous user. See MS-SMB2 3.2.5.3.1
1634 * (Samba servers don't always set the flag so also check if null user)
1635 */
1632 if ((ses->server->dialect == SMB311_PROT_ID) && 1636 if ((ses->server->dialect == SMB311_PROT_ID) &&
1633 !smb3_encryption_required(tcon)) 1637 !smb3_encryption_required(tcon) &&
1638 !(ses->session_flags &
1639 (SMB2_SESSION_FLAG_IS_GUEST|SMB2_SESSION_FLAG_IS_NULL)) &&
1640 ((ses->user_name != NULL) || (ses->sectype == Kerberos)))
1634 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED; 1641 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
1635 1642
1636 memset(&rqst, 0, sizeof(struct smb_rqst)); 1643 memset(&rqst, 0, sizeof(struct smb_rqst));
diff --git a/fs/cifs/trace.h b/fs/cifs/trace.h
index fa226de48ef3..99c4d799c24b 100644
--- a/fs/cifs/trace.h
+++ b/fs/cifs/trace.h
@@ -549,19 +549,19 @@ DECLARE_EVENT_CLASS(smb3_tcon_class,
549 __field(unsigned int, xid) 549 __field(unsigned int, xid)
550 __field(__u32, tid) 550 __field(__u32, tid)
551 __field(__u64, sesid) 551 __field(__u64, sesid)
552 __field(const char *, unc_name) 552 __string(name, unc_name)
553 __field(int, rc) 553 __field(int, rc)
554 ), 554 ),
555 TP_fast_assign( 555 TP_fast_assign(
556 __entry->xid = xid; 556 __entry->xid = xid;
557 __entry->tid = tid; 557 __entry->tid = tid;
558 __entry->sesid = sesid; 558 __entry->sesid = sesid;
559 __entry->unc_name = unc_name; 559 __assign_str(name, unc_name);
560 __entry->rc = rc; 560 __entry->rc = rc;
561 ), 561 ),
562 TP_printk("xid=%u sid=0x%llx tid=0x%x unc_name=%s rc=%d", 562 TP_printk("xid=%u sid=0x%llx tid=0x%x unc_name=%s rc=%d",
563 __entry->xid, __entry->sesid, __entry->tid, 563 __entry->xid, __entry->sesid, __entry->tid,
564 __entry->unc_name, __entry->rc) 564 __get_str(name), __entry->rc)
565) 565)
566 566
567#define DEFINE_SMB3_TCON_EVENT(name) \ 567#define DEFINE_SMB3_TCON_EVENT(name) \
diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h
index a1ac7e9245ec..75a5309f2231 100644
--- a/fs/ext4/ext4_jbd2.h
+++ b/fs/ext4/ext4_jbd2.h
@@ -384,7 +384,7 @@ static inline void ext4_update_inode_fsync_trans(handle_t *handle,
384{ 384{
385 struct ext4_inode_info *ei = EXT4_I(inode); 385 struct ext4_inode_info *ei = EXT4_I(inode);
386 386
387 if (ext4_handle_valid(handle)) { 387 if (ext4_handle_valid(handle) && !is_handle_aborted(handle)) {
388 ei->i_sync_tid = handle->h_transaction->t_tid; 388 ei->i_sync_tid = handle->h_transaction->t_tid;
389 if (datasync) 389 if (datasync)
390 ei->i_datasync_tid = handle->h_transaction->t_tid; 390 ei->i_datasync_tid = handle->h_transaction->t_tid;
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 69d65d49837b..98ec11f69cd4 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -125,7 +125,7 @@ ext4_unaligned_aio(struct inode *inode, struct iov_iter *from, loff_t pos)
125 struct super_block *sb = inode->i_sb; 125 struct super_block *sb = inode->i_sb;
126 int blockmask = sb->s_blocksize - 1; 126 int blockmask = sb->s_blocksize - 1;
127 127
128 if (pos >= i_size_read(inode)) 128 if (pos >= ALIGN(i_size_read(inode), sb->s_blocksize))
129 return 0; 129 return 0;
130 130
131 if ((pos | iov_iter_alignment(from)) & blockmask) 131 if ((pos | iov_iter_alignment(from)) & blockmask)
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
index c2225f0d31b5..2024d3fa5504 100644
--- a/fs/ext4/indirect.c
+++ b/fs/ext4/indirect.c
@@ -1222,6 +1222,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
1222 ext4_lblk_t offsets[4], offsets2[4]; 1222 ext4_lblk_t offsets[4], offsets2[4];
1223 Indirect chain[4], chain2[4]; 1223 Indirect chain[4], chain2[4];
1224 Indirect *partial, *partial2; 1224 Indirect *partial, *partial2;
1225 Indirect *p = NULL, *p2 = NULL;
1225 ext4_lblk_t max_block; 1226 ext4_lblk_t max_block;
1226 __le32 nr = 0, nr2 = 0; 1227 __le32 nr = 0, nr2 = 0;
1227 int n = 0, n2 = 0; 1228 int n = 0, n2 = 0;
@@ -1263,7 +1264,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
1263 } 1264 }
1264 1265
1265 1266
1266 partial = ext4_find_shared(inode, n, offsets, chain, &nr); 1267 partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
1267 if (nr) { 1268 if (nr) {
1268 if (partial == chain) { 1269 if (partial == chain) {
1269 /* Shared branch grows from the inode */ 1270 /* Shared branch grows from the inode */
@@ -1288,13 +1289,11 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
1288 partial->p + 1, 1289 partial->p + 1,
1289 (__le32 *)partial->bh->b_data+addr_per_block, 1290 (__le32 *)partial->bh->b_data+addr_per_block,
1290 (chain+n-1) - partial); 1291 (chain+n-1) - partial);
1291 BUFFER_TRACE(partial->bh, "call brelse");
1292 brelse(partial->bh);
1293 partial--; 1292 partial--;
1294 } 1293 }
1295 1294
1296end_range: 1295end_range:
1297 partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); 1296 partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
1298 if (nr2) { 1297 if (nr2) {
1299 if (partial2 == chain2) { 1298 if (partial2 == chain2) {
1300 /* 1299 /*
@@ -1324,16 +1323,14 @@ end_range:
1324 (__le32 *)partial2->bh->b_data, 1323 (__le32 *)partial2->bh->b_data,
1325 partial2->p, 1324 partial2->p,
1326 (chain2+n2-1) - partial2); 1325 (chain2+n2-1) - partial2);
1327 BUFFER_TRACE(partial2->bh, "call brelse");
1328 brelse(partial2->bh);
1329 partial2--; 1326 partial2--;
1330 } 1327 }
1331 goto do_indirects; 1328 goto do_indirects;
1332 } 1329 }
1333 1330
1334 /* Punch happened within the same level (n == n2) */ 1331 /* Punch happened within the same level (n == n2) */
1335 partial = ext4_find_shared(inode, n, offsets, chain, &nr); 1332 partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
1336 partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); 1333 partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
1337 1334
1338 /* Free top, but only if partial2 isn't its subtree. */ 1335 /* Free top, but only if partial2 isn't its subtree. */
1339 if (nr) { 1336 if (nr) {
@@ -1390,11 +1387,7 @@ end_range:
1390 partial->p + 1, 1387 partial->p + 1,
1391 partial2->p, 1388 partial2->p,
1392 (chain+n-1) - partial); 1389 (chain+n-1) - partial);
1393 BUFFER_TRACE(partial->bh, "call brelse"); 1390 goto cleanup;
1394 brelse(partial->bh);
1395 BUFFER_TRACE(partial2->bh, "call brelse");
1396 brelse(partial2->bh);
1397 return 0;
1398 } 1391 }
1399 1392
1400 /* 1393 /*
@@ -1409,8 +1402,6 @@ end_range:
1409 partial->p + 1, 1402 partial->p + 1,
1410 (__le32 *)partial->bh->b_data+addr_per_block, 1403 (__le32 *)partial->bh->b_data+addr_per_block,
1411 (chain+n-1) - partial); 1404 (chain+n-1) - partial);
1412 BUFFER_TRACE(partial->bh, "call brelse");
1413 brelse(partial->bh);
1414 partial--; 1405 partial--;
1415 } 1406 }
1416 if (partial2 > chain2 && depth2 <= depth) { 1407 if (partial2 > chain2 && depth2 <= depth) {
@@ -1418,11 +1409,21 @@ end_range:
1418 (__le32 *)partial2->bh->b_data, 1409 (__le32 *)partial2->bh->b_data,
1419 partial2->p, 1410 partial2->p,
1420 (chain2+n2-1) - partial2); 1411 (chain2+n2-1) - partial2);
1421 BUFFER_TRACE(partial2->bh, "call brelse");
1422 brelse(partial2->bh);
1423 partial2--; 1412 partial2--;
1424 } 1413 }
1425 } 1414 }
1415
1416cleanup:
1417 while (p && p > chain) {
1418 BUFFER_TRACE(p->bh, "call brelse");
1419 brelse(p->bh);
1420 p--;
1421 }
1422 while (p2 && p2 > chain2) {
1423 BUFFER_TRACE(p2->bh, "call brelse");
1424 brelse(p2->bh);
1425 p2--;
1426 }
1426 return 0; 1427 return 0;
1427 1428
1428do_indirects: 1429do_indirects:
@@ -1430,7 +1431,7 @@ do_indirects:
1430 switch (offsets[0]) { 1431 switch (offsets[0]) {
1431 default: 1432 default:
1432 if (++n >= n2) 1433 if (++n >= n2)
1433 return 0; 1434 break;
1434 nr = i_data[EXT4_IND_BLOCK]; 1435 nr = i_data[EXT4_IND_BLOCK];
1435 if (nr) { 1436 if (nr) {
1436 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1); 1437 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1);
@@ -1439,7 +1440,7 @@ do_indirects:
1439 /* fall through */ 1440 /* fall through */
1440 case EXT4_IND_BLOCK: 1441 case EXT4_IND_BLOCK:
1441 if (++n >= n2) 1442 if (++n >= n2)
1442 return 0; 1443 break;
1443 nr = i_data[EXT4_DIND_BLOCK]; 1444 nr = i_data[EXT4_DIND_BLOCK];
1444 if (nr) { 1445 if (nr) {
1445 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2); 1446 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2);
@@ -1448,7 +1449,7 @@ do_indirects:
1448 /* fall through */ 1449 /* fall through */
1449 case EXT4_DIND_BLOCK: 1450 case EXT4_DIND_BLOCK:
1450 if (++n >= n2) 1451 if (++n >= n2)
1451 return 0; 1452 break;
1452 nr = i_data[EXT4_TIND_BLOCK]; 1453 nr = i_data[EXT4_TIND_BLOCK];
1453 if (nr) { 1454 if (nr) {
1454 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3); 1455 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3);
@@ -1458,5 +1459,5 @@ do_indirects:
1458 case EXT4_TIND_BLOCK: 1459 case EXT4_TIND_BLOCK:
1459 ; 1460 ;
1460 } 1461 }
1461 return 0; 1462 goto cleanup;
1462} 1463}
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index b54b261ded36..b32a57bc5d5d 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -6080,36 +6080,6 @@ out:
6080 return; 6080 return;
6081} 6081}
6082 6082
6083#if 0
6084/*
6085 * Bind an inode's backing buffer_head into this transaction, to prevent
6086 * it from being flushed to disk early. Unlike
6087 * ext4_reserve_inode_write, this leaves behind no bh reference and
6088 * returns no iloc structure, so the caller needs to repeat the iloc
6089 * lookup to mark the inode dirty later.
6090 */
6091static int ext4_pin_inode(handle_t *handle, struct inode *inode)
6092{
6093 struct ext4_iloc iloc;
6094
6095 int err = 0;
6096 if (handle) {
6097 err = ext4_get_inode_loc(inode, &iloc);
6098 if (!err) {
6099 BUFFER_TRACE(iloc.bh, "get_write_access");
6100 err = jbd2_journal_get_write_access(handle, iloc.bh);
6101 if (!err)
6102 err = ext4_handle_dirty_metadata(handle,
6103 NULL,
6104 iloc.bh);
6105 brelse(iloc.bh);
6106 }
6107 }
6108 ext4_std_error(inode->i_sb, err);
6109 return err;
6110}
6111#endif
6112
6113int ext4_change_inode_journal_flag(struct inode *inode, int val) 6083int ext4_change_inode_journal_flag(struct inode *inode, int val)
6114{ 6084{
6115 journal_t *journal; 6085 journal_t *journal;
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 3c4f8bb59f8a..bab3da4f1e0d 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1000,6 +1000,13 @@ resizefs_out:
1000 if (!blk_queue_discard(q)) 1000 if (!blk_queue_discard(q))
1001 return -EOPNOTSUPP; 1001 return -EOPNOTSUPP;
1002 1002
1003 /*
1004 * We haven't replayed the journal, so we cannot use our
1005 * block-bitmap-guided storage zapping commands.
1006 */
1007 if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb))
1008 return -EROFS;
1009
1003 if (copy_from_user(&range, (struct fstrim_range __user *)arg, 1010 if (copy_from_user(&range, (struct fstrim_range __user *)arg,
1004 sizeof(range))) 1011 sizeof(range)))
1005 return -EFAULT; 1012 return -EFAULT;
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 3d9b18505c0c..e7ae26e36c9c 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -932,11 +932,18 @@ static int add_new_gdb_meta_bg(struct super_block *sb,
932 memcpy(n_group_desc, o_group_desc, 932 memcpy(n_group_desc, o_group_desc,
933 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); 933 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *));
934 n_group_desc[gdb_num] = gdb_bh; 934 n_group_desc[gdb_num] = gdb_bh;
935
936 BUFFER_TRACE(gdb_bh, "get_write_access");
937 err = ext4_journal_get_write_access(handle, gdb_bh);
938 if (err) {
939 kvfree(n_group_desc);
940 brelse(gdb_bh);
941 return err;
942 }
943
935 EXT4_SB(sb)->s_group_desc = n_group_desc; 944 EXT4_SB(sb)->s_group_desc = n_group_desc;
936 EXT4_SB(sb)->s_gdb_count++; 945 EXT4_SB(sb)->s_gdb_count++;
937 kvfree(o_group_desc); 946 kvfree(o_group_desc);
938 BUFFER_TRACE(gdb_bh, "get_write_access");
939 err = ext4_journal_get_write_access(handle, gdb_bh);
940 return err; 947 return err;
941} 948}
942 949
@@ -2073,6 +2080,10 @@ out:
2073 free_flex_gd(flex_gd); 2080 free_flex_gd(flex_gd);
2074 if (resize_inode != NULL) 2081 if (resize_inode != NULL)
2075 iput(resize_inode); 2082 iput(resize_inode);
2076 ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", n_blocks_count); 2083 if (err)
2084 ext4_warning(sb, "error (%d) occurred during "
2085 "file system resize", err);
2086 ext4_msg(sb, KERN_INFO, "resized filesystem to %llu",
2087 ext4_blocks_count(es));
2077 return err; 2088 return err;
2078} 2089}
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index f5b828bf1299..6ed4eb81e674 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -430,6 +430,12 @@ static void ext4_journal_commit_callback(journal_t *journal, transaction_t *txn)
430 spin_unlock(&sbi->s_md_lock); 430 spin_unlock(&sbi->s_md_lock);
431} 431}
432 432
433static bool system_going_down(void)
434{
435 return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF
436 || system_state == SYSTEM_RESTART;
437}
438
433/* Deal with the reporting of failure conditions on a filesystem such as 439/* Deal with the reporting of failure conditions on a filesystem such as
434 * inconsistencies detected or read IO failures. 440 * inconsistencies detected or read IO failures.
435 * 441 *
@@ -460,7 +466,12 @@ static void ext4_handle_error(struct super_block *sb)
460 if (journal) 466 if (journal)
461 jbd2_journal_abort(journal, -EIO); 467 jbd2_journal_abort(journal, -EIO);
462 } 468 }
463 if (test_opt(sb, ERRORS_RO)) { 469 /*
470 * We force ERRORS_RO behavior when system is rebooting. Otherwise we
471 * could panic during 'reboot -f' as the underlying device got already
472 * disabled.
473 */
474 if (test_opt(sb, ERRORS_RO) || system_going_down()) {
464 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); 475 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
465 /* 476 /*
466 * Make sure updated value of ->s_mount_flags will be visible 477 * Make sure updated value of ->s_mount_flags will be visible
@@ -468,8 +479,7 @@ static void ext4_handle_error(struct super_block *sb)
468 */ 479 */
469 smp_wmb(); 480 smp_wmb();
470 sb->s_flags |= SB_RDONLY; 481 sb->s_flags |= SB_RDONLY;
471 } 482 } else if (test_opt(sb, ERRORS_PANIC)) {
472 if (test_opt(sb, ERRORS_PANIC)) {
473 if (EXT4_SB(sb)->s_journal && 483 if (EXT4_SB(sb)->s_journal &&
474 !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR)) 484 !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR))
475 return; 485 return;
diff --git a/fs/io_uring.c b/fs/io_uring.c
index c88088d92613..6aaa30580a2b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -189,17 +189,28 @@ struct sqe_submit {
189 bool needs_fixed_file; 189 bool needs_fixed_file;
190}; 190};
191 191
192/*
193 * First field must be the file pointer in all the
194 * iocb unions! See also 'struct kiocb' in <linux/fs.h>
195 */
192struct io_poll_iocb { 196struct io_poll_iocb {
193 struct file *file; 197 struct file *file;
194 struct wait_queue_head *head; 198 struct wait_queue_head *head;
195 __poll_t events; 199 __poll_t events;
196 bool woken; 200 bool done;
197 bool canceled; 201 bool canceled;
198 struct wait_queue_entry wait; 202 struct wait_queue_entry wait;
199}; 203};
200 204
205/*
206 * NOTE! Each of the iocb union members has the file pointer
207 * as the first entry in their struct definition. So you can
208 * access the file pointer through any of the sub-structs,
209 * or directly as just 'ki_filp' in this struct.
210 */
201struct io_kiocb { 211struct io_kiocb {
202 union { 212 union {
213 struct file *file;
203 struct kiocb rw; 214 struct kiocb rw;
204 struct io_poll_iocb poll; 215 struct io_poll_iocb poll;
205 }; 216 };
@@ -214,6 +225,7 @@ struct io_kiocb {
214#define REQ_F_IOPOLL_COMPLETED 2 /* polled IO has completed */ 225#define REQ_F_IOPOLL_COMPLETED 2 /* polled IO has completed */
215#define REQ_F_FIXED_FILE 4 /* ctx owns file */ 226#define REQ_F_FIXED_FILE 4 /* ctx owns file */
216#define REQ_F_SEQ_PREV 8 /* sequential with previous */ 227#define REQ_F_SEQ_PREV 8 /* sequential with previous */
228#define REQ_F_PREPPED 16 /* prep already done */
217 u64 user_data; 229 u64 user_data;
218 u64 error; 230 u64 error;
219 231
@@ -355,20 +367,25 @@ static void io_cqring_fill_event(struct io_ring_ctx *ctx, u64 ki_user_data,
355 } 367 }
356} 368}
357 369
358static void io_cqring_add_event(struct io_ring_ctx *ctx, u64 ki_user_data, 370static void io_cqring_ev_posted(struct io_ring_ctx *ctx)
371{
372 if (waitqueue_active(&ctx->wait))
373 wake_up(&ctx->wait);
374 if (waitqueue_active(&ctx->sqo_wait))
375 wake_up(&ctx->sqo_wait);
376}
377
378static void io_cqring_add_event(struct io_ring_ctx *ctx, u64 user_data,
359 long res, unsigned ev_flags) 379 long res, unsigned ev_flags)
360{ 380{
361 unsigned long flags; 381 unsigned long flags;
362 382
363 spin_lock_irqsave(&ctx->completion_lock, flags); 383 spin_lock_irqsave(&ctx->completion_lock, flags);
364 io_cqring_fill_event(ctx, ki_user_data, res, ev_flags); 384 io_cqring_fill_event(ctx, user_data, res, ev_flags);
365 io_commit_cqring(ctx); 385 io_commit_cqring(ctx);
366 spin_unlock_irqrestore(&ctx->completion_lock, flags); 386 spin_unlock_irqrestore(&ctx->completion_lock, flags);
367 387
368 if (waitqueue_active(&ctx->wait)) 388 io_cqring_ev_posted(ctx);
369 wake_up(&ctx->wait);
370 if (waitqueue_active(&ctx->sqo_wait))
371 wake_up(&ctx->sqo_wait);
372} 389}
373 390
374static void io_ring_drop_ctx_refs(struct io_ring_ctx *ctx, unsigned refs) 391static void io_ring_drop_ctx_refs(struct io_ring_ctx *ctx, unsigned refs)
@@ -382,13 +399,14 @@ static void io_ring_drop_ctx_refs(struct io_ring_ctx *ctx, unsigned refs)
382static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx, 399static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
383 struct io_submit_state *state) 400 struct io_submit_state *state)
384{ 401{
402 gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
385 struct io_kiocb *req; 403 struct io_kiocb *req;
386 404
387 if (!percpu_ref_tryget(&ctx->refs)) 405 if (!percpu_ref_tryget(&ctx->refs))
388 return NULL; 406 return NULL;
389 407
390 if (!state) { 408 if (!state) {
391 req = kmem_cache_alloc(req_cachep, __GFP_NOWARN); 409 req = kmem_cache_alloc(req_cachep, gfp);
392 if (unlikely(!req)) 410 if (unlikely(!req))
393 goto out; 411 goto out;
394 } else if (!state->free_reqs) { 412 } else if (!state->free_reqs) {
@@ -396,10 +414,18 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
396 int ret; 414 int ret;
397 415
398 sz = min_t(size_t, state->ios_left, ARRAY_SIZE(state->reqs)); 416 sz = min_t(size_t, state->ios_left, ARRAY_SIZE(state->reqs));
399 ret = kmem_cache_alloc_bulk(req_cachep, __GFP_NOWARN, sz, 417 ret = kmem_cache_alloc_bulk(req_cachep, gfp, sz, state->reqs);
400 state->reqs); 418
401 if (unlikely(ret <= 0)) 419 /*
402 goto out; 420 * Bulk alloc is all-or-nothing. If we fail to get a batch,
421 * retry single alloc to be on the safe side.
422 */
423 if (unlikely(ret <= 0)) {
424 state->reqs[0] = kmem_cache_alloc(req_cachep, gfp);
425 if (!state->reqs[0])
426 goto out;
427 ret = 1;
428 }
403 state->free_reqs = ret - 1; 429 state->free_reqs = ret - 1;
404 state->cur_req = 1; 430 state->cur_req = 1;
405 req = state->reqs[0]; 431 req = state->reqs[0];
@@ -411,7 +437,8 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
411 437
412 req->ctx = ctx; 438 req->ctx = ctx;
413 req->flags = 0; 439 req->flags = 0;
414 refcount_set(&req->refs, 0); 440 /* one is dropped after submission, the other at completion */
441 refcount_set(&req->refs, 2);
415 return req; 442 return req;
416out: 443out:
417 io_ring_drop_ctx_refs(ctx, 1); 444 io_ring_drop_ctx_refs(ctx, 1);
@@ -429,10 +456,16 @@ static void io_free_req_many(struct io_ring_ctx *ctx, void **reqs, int *nr)
429 456
430static void io_free_req(struct io_kiocb *req) 457static void io_free_req(struct io_kiocb *req)
431{ 458{
432 if (!refcount_read(&req->refs) || refcount_dec_and_test(&req->refs)) { 459 if (req->file && !(req->flags & REQ_F_FIXED_FILE))
433 io_ring_drop_ctx_refs(req->ctx, 1); 460 fput(req->file);
434 kmem_cache_free(req_cachep, req); 461 io_ring_drop_ctx_refs(req->ctx, 1);
435 } 462 kmem_cache_free(req_cachep, req);
463}
464
465static void io_put_req(struct io_kiocb *req)
466{
467 if (refcount_dec_and_test(&req->refs))
468 io_free_req(req);
436} 469}
437 470
438/* 471/*
@@ -442,44 +475,34 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
442 struct list_head *done) 475 struct list_head *done)
443{ 476{
444 void *reqs[IO_IOPOLL_BATCH]; 477 void *reqs[IO_IOPOLL_BATCH];
445 int file_count, to_free;
446 struct file *file = NULL;
447 struct io_kiocb *req; 478 struct io_kiocb *req;
479 int to_free;
448 480
449 file_count = to_free = 0; 481 to_free = 0;
450 while (!list_empty(done)) { 482 while (!list_empty(done)) {
451 req = list_first_entry(done, struct io_kiocb, list); 483 req = list_first_entry(done, struct io_kiocb, list);
452 list_del(&req->list); 484 list_del(&req->list);
453 485
454 io_cqring_fill_event(ctx, req->user_data, req->error, 0); 486 io_cqring_fill_event(ctx, req->user_data, req->error, 0);
455
456 reqs[to_free++] = req;
457 (*nr_events)++; 487 (*nr_events)++;
458 488
459 /* 489 if (refcount_dec_and_test(&req->refs)) {
460 * Batched puts of the same file, to avoid dirtying the 490 /* If we're not using fixed files, we have to pair the
461 * file usage count multiple times, if avoidable. 491 * completion part with the file put. Use regular
462 */ 492 * completions for those, only batch free for fixed
463 if (!(req->flags & REQ_F_FIXED_FILE)) { 493 * file.
464 if (!file) { 494 */
465 file = req->rw.ki_filp; 495 if (req->flags & REQ_F_FIXED_FILE) {
466 file_count = 1; 496 reqs[to_free++] = req;
467 } else if (file == req->rw.ki_filp) { 497 if (to_free == ARRAY_SIZE(reqs))
468 file_count++; 498 io_free_req_many(ctx, reqs, &to_free);
469 } else { 499 } else {
470 fput_many(file, file_count); 500 io_free_req(req);
471 file = req->rw.ki_filp;
472 file_count = 1;
473 } 501 }
474 } 502 }
475
476 if (to_free == ARRAY_SIZE(reqs))
477 io_free_req_many(ctx, reqs, &to_free);
478 } 503 }
479 io_commit_cqring(ctx);
480 504
481 if (file) 505 io_commit_cqring(ctx);
482 fput_many(file, file_count);
483 io_free_req_many(ctx, reqs, &to_free); 506 io_free_req_many(ctx, reqs, &to_free);
484} 507}
485 508
@@ -602,21 +625,14 @@ static void kiocb_end_write(struct kiocb *kiocb)
602 } 625 }
603} 626}
604 627
605static void io_fput(struct io_kiocb *req)
606{
607 if (!(req->flags & REQ_F_FIXED_FILE))
608 fput(req->rw.ki_filp);
609}
610
611static void io_complete_rw(struct kiocb *kiocb, long res, long res2) 628static void io_complete_rw(struct kiocb *kiocb, long res, long res2)
612{ 629{
613 struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw); 630 struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw);
614 631
615 kiocb_end_write(kiocb); 632 kiocb_end_write(kiocb);
616 633
617 io_fput(req);
618 io_cqring_add_event(req->ctx, req->user_data, res, 0); 634 io_cqring_add_event(req->ctx, req->user_data, res, 0);
619 io_free_req(req); 635 io_put_req(req);
620} 636}
621 637
622static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2) 638static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
@@ -731,31 +747,18 @@ static int io_prep_rw(struct io_kiocb *req, const struct sqe_submit *s,
731 const struct io_uring_sqe *sqe = s->sqe; 747 const struct io_uring_sqe *sqe = s->sqe;
732 struct io_ring_ctx *ctx = req->ctx; 748 struct io_ring_ctx *ctx = req->ctx;
733 struct kiocb *kiocb = &req->rw; 749 struct kiocb *kiocb = &req->rw;
734 unsigned ioprio, flags; 750 unsigned ioprio;
735 int fd, ret; 751 int ret;
736 752
753 if (!req->file)
754 return -EBADF;
737 /* For -EAGAIN retry, everything is already prepped */ 755 /* For -EAGAIN retry, everything is already prepped */
738 if (kiocb->ki_filp) 756 if (req->flags & REQ_F_PREPPED)
739 return 0; 757 return 0;
740 758
741 flags = READ_ONCE(sqe->flags); 759 if (force_nonblock && !io_file_supports_async(req->file))
742 fd = READ_ONCE(sqe->fd); 760 force_nonblock = false;
743 761
744 if (flags & IOSQE_FIXED_FILE) {
745 if (unlikely(!ctx->user_files ||
746 (unsigned) fd >= ctx->nr_user_files))
747 return -EBADF;
748 kiocb->ki_filp = ctx->user_files[fd];
749 req->flags |= REQ_F_FIXED_FILE;
750 } else {
751 if (s->needs_fixed_file)
752 return -EBADF;
753 kiocb->ki_filp = io_file_get(state, fd);
754 if (unlikely(!kiocb->ki_filp))
755 return -EBADF;
756 if (force_nonblock && !io_file_supports_async(kiocb->ki_filp))
757 force_nonblock = false;
758 }
759 kiocb->ki_pos = READ_ONCE(sqe->off); 762 kiocb->ki_pos = READ_ONCE(sqe->off);
760 kiocb->ki_flags = iocb_flags(kiocb->ki_filp); 763 kiocb->ki_flags = iocb_flags(kiocb->ki_filp);
761 kiocb->ki_hint = ki_hint_validate(file_write_hint(kiocb->ki_filp)); 764 kiocb->ki_hint = ki_hint_validate(file_write_hint(kiocb->ki_filp));
@@ -764,7 +767,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct sqe_submit *s,
764 if (ioprio) { 767 if (ioprio) {
765 ret = ioprio_check_cap(ioprio); 768 ret = ioprio_check_cap(ioprio);
766 if (ret) 769 if (ret)
767 goto out_fput; 770 return ret;
768 771
769 kiocb->ki_ioprio = ioprio; 772 kiocb->ki_ioprio = ioprio;
770 } else 773 } else
@@ -772,38 +775,26 @@ static int io_prep_rw(struct io_kiocb *req, const struct sqe_submit *s,
772 775
773 ret = kiocb_set_rw_flags(kiocb, READ_ONCE(sqe->rw_flags)); 776 ret = kiocb_set_rw_flags(kiocb, READ_ONCE(sqe->rw_flags));
774 if (unlikely(ret)) 777 if (unlikely(ret))
775 goto out_fput; 778 return ret;
776 if (force_nonblock) { 779 if (force_nonblock) {
777 kiocb->ki_flags |= IOCB_NOWAIT; 780 kiocb->ki_flags |= IOCB_NOWAIT;
778 req->flags |= REQ_F_FORCE_NONBLOCK; 781 req->flags |= REQ_F_FORCE_NONBLOCK;
779 } 782 }
780 if (ctx->flags & IORING_SETUP_IOPOLL) { 783 if (ctx->flags & IORING_SETUP_IOPOLL) {
781 ret = -EOPNOTSUPP;
782 if (!(kiocb->ki_flags & IOCB_DIRECT) || 784 if (!(kiocb->ki_flags & IOCB_DIRECT) ||
783 !kiocb->ki_filp->f_op->iopoll) 785 !kiocb->ki_filp->f_op->iopoll)
784 goto out_fput; 786 return -EOPNOTSUPP;
785 787
786 req->error = 0; 788 req->error = 0;
787 kiocb->ki_flags |= IOCB_HIPRI; 789 kiocb->ki_flags |= IOCB_HIPRI;
788 kiocb->ki_complete = io_complete_rw_iopoll; 790 kiocb->ki_complete = io_complete_rw_iopoll;
789 } else { 791 } else {
790 if (kiocb->ki_flags & IOCB_HIPRI) { 792 if (kiocb->ki_flags & IOCB_HIPRI)
791 ret = -EINVAL; 793 return -EINVAL;
792 goto out_fput;
793 }
794 kiocb->ki_complete = io_complete_rw; 794 kiocb->ki_complete = io_complete_rw;
795 } 795 }
796 req->flags |= REQ_F_PREPPED;
796 return 0; 797 return 0;
797out_fput:
798 if (!(flags & IOSQE_FIXED_FILE)) {
799 /*
800 * in case of error, we didn't use this file reference. drop it.
801 */
802 if (state)
803 state->used_refs--;
804 io_file_put(state, kiocb->ki_filp);
805 }
806 return ret;
807} 798}
808 799
809static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret) 800static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
@@ -864,6 +855,9 @@ static int io_import_fixed(struct io_ring_ctx *ctx, int rw,
864 iov_iter_bvec(iter, rw, imu->bvec, imu->nr_bvecs, offset + len); 855 iov_iter_bvec(iter, rw, imu->bvec, imu->nr_bvecs, offset + len);
865 if (offset) 856 if (offset)
866 iov_iter_advance(iter, offset); 857 iov_iter_advance(iter, offset);
858
859 /* don't drop a reference to these pages */
860 iter->type |= ITER_BVEC_FLAG_NO_REF;
867 return 0; 861 return 0;
868} 862}
869 863
@@ -887,7 +881,7 @@ static int io_import_iovec(struct io_ring_ctx *ctx, int rw,
887 opcode = READ_ONCE(sqe->opcode); 881 opcode = READ_ONCE(sqe->opcode);
888 if (opcode == IORING_OP_READ_FIXED || 882 if (opcode == IORING_OP_READ_FIXED ||
889 opcode == IORING_OP_WRITE_FIXED) { 883 opcode == IORING_OP_WRITE_FIXED) {
890 ssize_t ret = io_import_fixed(ctx, rw, sqe, iter); 884 int ret = io_import_fixed(ctx, rw, sqe, iter);
891 *iovec = NULL; 885 *iovec = NULL;
892 return ret; 886 return ret;
893 } 887 }
@@ -945,31 +939,29 @@ static void io_async_list_note(int rw, struct io_kiocb *req, size_t len)
945 async_list->io_end = io_end; 939 async_list->io_end = io_end;
946} 940}
947 941
948static ssize_t io_read(struct io_kiocb *req, const struct sqe_submit *s, 942static int io_read(struct io_kiocb *req, const struct sqe_submit *s,
949 bool force_nonblock, struct io_submit_state *state) 943 bool force_nonblock, struct io_submit_state *state)
950{ 944{
951 struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs; 945 struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
952 struct kiocb *kiocb = &req->rw; 946 struct kiocb *kiocb = &req->rw;
953 struct iov_iter iter; 947 struct iov_iter iter;
954 struct file *file; 948 struct file *file;
955 size_t iov_count; 949 size_t iov_count;
956 ssize_t ret; 950 int ret;
957 951
958 ret = io_prep_rw(req, s, force_nonblock, state); 952 ret = io_prep_rw(req, s, force_nonblock, state);
959 if (ret) 953 if (ret)
960 return ret; 954 return ret;
961 file = kiocb->ki_filp; 955 file = kiocb->ki_filp;
962 956
963 ret = -EBADF;
964 if (unlikely(!(file->f_mode & FMODE_READ))) 957 if (unlikely(!(file->f_mode & FMODE_READ)))
965 goto out_fput; 958 return -EBADF;
966 ret = -EINVAL;
967 if (unlikely(!file->f_op->read_iter)) 959 if (unlikely(!file->f_op->read_iter))
968 goto out_fput; 960 return -EINVAL;
969 961
970 ret = io_import_iovec(req->ctx, READ, s, &iovec, &iter); 962 ret = io_import_iovec(req->ctx, READ, s, &iovec, &iter);
971 if (ret) 963 if (ret)
972 goto out_fput; 964 return ret;
973 965
974 iov_count = iov_iter_count(&iter); 966 iov_count = iov_iter_count(&iter);
975 ret = rw_verify_area(READ, file, &kiocb->ki_pos, iov_count); 967 ret = rw_verify_area(READ, file, &kiocb->ki_pos, iov_count);
@@ -991,38 +983,32 @@ static ssize_t io_read(struct io_kiocb *req, const struct sqe_submit *s,
991 } 983 }
992 } 984 }
993 kfree(iovec); 985 kfree(iovec);
994out_fput:
995 /* Hold on to the file for -EAGAIN */
996 if (unlikely(ret && ret != -EAGAIN))
997 io_fput(req);
998 return ret; 986 return ret;
999} 987}
1000 988
1001static ssize_t io_write(struct io_kiocb *req, const struct sqe_submit *s, 989static int io_write(struct io_kiocb *req, const struct sqe_submit *s,
1002 bool force_nonblock, struct io_submit_state *state) 990 bool force_nonblock, struct io_submit_state *state)
1003{ 991{
1004 struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs; 992 struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
1005 struct kiocb *kiocb = &req->rw; 993 struct kiocb *kiocb = &req->rw;
1006 struct iov_iter iter; 994 struct iov_iter iter;
1007 struct file *file; 995 struct file *file;
1008 size_t iov_count; 996 size_t iov_count;
1009 ssize_t ret; 997 int ret;
1010 998
1011 ret = io_prep_rw(req, s, force_nonblock, state); 999 ret = io_prep_rw(req, s, force_nonblock, state);
1012 if (ret) 1000 if (ret)
1013 return ret; 1001 return ret;
1014 1002
1015 ret = -EBADF;
1016 file = kiocb->ki_filp; 1003 file = kiocb->ki_filp;
1017 if (unlikely(!(file->f_mode & FMODE_WRITE))) 1004 if (unlikely(!(file->f_mode & FMODE_WRITE)))
1018 goto out_fput; 1005 return -EBADF;
1019 ret = -EINVAL;
1020 if (unlikely(!file->f_op->write_iter)) 1006 if (unlikely(!file->f_op->write_iter))
1021 goto out_fput; 1007 return -EINVAL;
1022 1008
1023 ret = io_import_iovec(req->ctx, WRITE, s, &iovec, &iter); 1009 ret = io_import_iovec(req->ctx, WRITE, s, &iovec, &iter);
1024 if (ret) 1010 if (ret)
1025 goto out_fput; 1011 return ret;
1026 1012
1027 iov_count = iov_iter_count(&iter); 1013 iov_count = iov_iter_count(&iter);
1028 1014
@@ -1054,10 +1040,6 @@ static ssize_t io_write(struct io_kiocb *req, const struct sqe_submit *s,
1054 } 1040 }
1055out_free: 1041out_free:
1056 kfree(iovec); 1042 kfree(iovec);
1057out_fput:
1058 /* Hold on to the file for -EAGAIN */
1059 if (unlikely(ret && ret != -EAGAIN))
1060 io_fput(req);
1061 return ret; 1043 return ret;
1062} 1044}
1063 1045
@@ -1072,29 +1054,19 @@ static int io_nop(struct io_kiocb *req, u64 user_data)
1072 if (unlikely(ctx->flags & IORING_SETUP_IOPOLL)) 1054 if (unlikely(ctx->flags & IORING_SETUP_IOPOLL))
1073 return -EINVAL; 1055 return -EINVAL;
1074 1056
1075 /*
1076 * Twilight zone - it's possible that someone issued an opcode that
1077 * has a file attached, then got -EAGAIN on submission, and changed
1078 * the sqe before we retried it from async context. Avoid dropping
1079 * a file reference for this malicious case, and flag the error.
1080 */
1081 if (req->rw.ki_filp) {
1082 err = -EBADF;
1083 io_fput(req);
1084 }
1085 io_cqring_add_event(ctx, user_data, err, 0); 1057 io_cqring_add_event(ctx, user_data, err, 0);
1086 io_free_req(req); 1058 io_put_req(req);
1087 return 0; 1059 return 0;
1088} 1060}
1089 1061
1090static int io_prep_fsync(struct io_kiocb *req, const struct io_uring_sqe *sqe) 1062static int io_prep_fsync(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1091{ 1063{
1092 struct io_ring_ctx *ctx = req->ctx; 1064 struct io_ring_ctx *ctx = req->ctx;
1093 unsigned flags;
1094 int fd;
1095 1065
1096 /* Prep already done */ 1066 if (!req->file)
1097 if (req->rw.ki_filp) 1067 return -EBADF;
1068 /* Prep already done (EAGAIN retry) */
1069 if (req->flags & REQ_F_PREPPED)
1098 return 0; 1070 return 0;
1099 1071
1100 if (unlikely(ctx->flags & IORING_SETUP_IOPOLL)) 1072 if (unlikely(ctx->flags & IORING_SETUP_IOPOLL))
@@ -1102,20 +1074,7 @@ static int io_prep_fsync(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1102 if (unlikely(sqe->addr || sqe->ioprio || sqe->buf_index)) 1074 if (unlikely(sqe->addr || sqe->ioprio || sqe->buf_index))
1103 return -EINVAL; 1075 return -EINVAL;
1104 1076
1105 fd = READ_ONCE(sqe->fd); 1077 req->flags |= REQ_F_PREPPED;
1106 flags = READ_ONCE(sqe->flags);
1107
1108 if (flags & IOSQE_FIXED_FILE) {
1109 if (unlikely(!ctx->user_files || fd >= ctx->nr_user_files))
1110 return -EBADF;
1111 req->rw.ki_filp = ctx->user_files[fd];
1112 req->flags |= REQ_F_FIXED_FILE;
1113 } else {
1114 req->rw.ki_filp = fget(fd);
1115 if (unlikely(!req->rw.ki_filp))
1116 return -EBADF;
1117 }
1118
1119 return 0; 1078 return 0;
1120} 1079}
1121 1080
@@ -1144,9 +1103,8 @@ static int io_fsync(struct io_kiocb *req, const struct io_uring_sqe *sqe,
1144 end > 0 ? end : LLONG_MAX, 1103 end > 0 ? end : LLONG_MAX,
1145 fsync_flags & IORING_FSYNC_DATASYNC); 1104 fsync_flags & IORING_FSYNC_DATASYNC);
1146 1105
1147 io_fput(req);
1148 io_cqring_add_event(req->ctx, sqe->user_data, ret, 0); 1106 io_cqring_add_event(req->ctx, sqe->user_data, ret, 0);
1149 io_free_req(req); 1107 io_put_req(req);
1150 return 0; 1108 return 0;
1151} 1109}
1152 1110
@@ -1204,15 +1162,16 @@ static int io_poll_remove(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1204 spin_unlock_irq(&ctx->completion_lock); 1162 spin_unlock_irq(&ctx->completion_lock);
1205 1163
1206 io_cqring_add_event(req->ctx, sqe->user_data, ret, 0); 1164 io_cqring_add_event(req->ctx, sqe->user_data, ret, 0);
1207 io_free_req(req); 1165 io_put_req(req);
1208 return 0; 1166 return 0;
1209} 1167}
1210 1168
1211static void io_poll_complete(struct io_kiocb *req, __poll_t mask) 1169static void io_poll_complete(struct io_ring_ctx *ctx, struct io_kiocb *req,
1170 __poll_t mask)
1212{ 1171{
1213 io_cqring_add_event(req->ctx, req->user_data, mangle_poll(mask), 0); 1172 req->poll.done = true;
1214 io_fput(req); 1173 io_cqring_fill_event(ctx, req->user_data, mangle_poll(mask), 0);
1215 io_free_req(req); 1174 io_commit_cqring(ctx);
1216} 1175}
1217 1176
1218static void io_poll_complete_work(struct work_struct *work) 1177static void io_poll_complete_work(struct work_struct *work)
@@ -1240,9 +1199,11 @@ static void io_poll_complete_work(struct work_struct *work)
1240 return; 1199 return;
1241 } 1200 }
1242 list_del_init(&req->list); 1201 list_del_init(&req->list);
1202 io_poll_complete(ctx, req, mask);
1243 spin_unlock_irq(&ctx->completion_lock); 1203 spin_unlock_irq(&ctx->completion_lock);
1244 1204
1245 io_poll_complete(req, mask); 1205 io_cqring_ev_posted(ctx);
1206 io_put_req(req);
1246} 1207}
1247 1208
1248static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync, 1209static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
@@ -1253,29 +1214,25 @@ static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
1253 struct io_kiocb *req = container_of(poll, struct io_kiocb, poll); 1214 struct io_kiocb *req = container_of(poll, struct io_kiocb, poll);
1254 struct io_ring_ctx *ctx = req->ctx; 1215 struct io_ring_ctx *ctx = req->ctx;
1255 __poll_t mask = key_to_poll(key); 1216 __poll_t mask = key_to_poll(key);
1256 1217 unsigned long flags;
1257 poll->woken = true;
1258 1218
1259 /* for instances that support it check for an event match first: */ 1219 /* for instances that support it check for an event match first: */
1260 if (mask) { 1220 if (mask && !(mask & poll->events))
1261 unsigned long flags; 1221 return 0;
1262 1222
1263 if (!(mask & poll->events)) 1223 list_del_init(&poll->wait.entry);
1264 return 0;
1265 1224
1266 /* try to complete the iocb inline if we can: */ 1225 if (mask && spin_trylock_irqsave(&ctx->completion_lock, flags)) {
1267 if (spin_trylock_irqsave(&ctx->completion_lock, flags)) { 1226 list_del(&req->list);
1268 list_del(&req->list); 1227 io_poll_complete(ctx, req, mask);
1269 spin_unlock_irqrestore(&ctx->completion_lock, flags); 1228 spin_unlock_irqrestore(&ctx->completion_lock, flags);
1270 1229
1271 list_del_init(&poll->wait.entry); 1230 io_cqring_ev_posted(ctx);
1272 io_poll_complete(req, mask); 1231 io_put_req(req);
1273 return 1; 1232 } else {
1274 } 1233 queue_work(ctx->sqo_wq, &req->work);
1275 } 1234 }
1276 1235
1277 list_del_init(&poll->wait.entry);
1278 queue_work(ctx->sqo_wq, &req->work);
1279 return 1; 1236 return 1;
1280} 1237}
1281 1238
@@ -1305,36 +1262,23 @@ static int io_poll_add(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1305 struct io_poll_iocb *poll = &req->poll; 1262 struct io_poll_iocb *poll = &req->poll;
1306 struct io_ring_ctx *ctx = req->ctx; 1263 struct io_ring_ctx *ctx = req->ctx;
1307 struct io_poll_table ipt; 1264 struct io_poll_table ipt;
1308 unsigned flags; 1265 bool cancel = false;
1309 __poll_t mask; 1266 __poll_t mask;
1310 u16 events; 1267 u16 events;
1311 int fd;
1312 1268
1313 if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) 1269 if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
1314 return -EINVAL; 1270 return -EINVAL;
1315 if (sqe->addr || sqe->ioprio || sqe->off || sqe->len || sqe->buf_index) 1271 if (sqe->addr || sqe->ioprio || sqe->off || sqe->len || sqe->buf_index)
1316 return -EINVAL; 1272 return -EINVAL;
1273 if (!poll->file)
1274 return -EBADF;
1317 1275
1318 INIT_WORK(&req->work, io_poll_complete_work); 1276 INIT_WORK(&req->work, io_poll_complete_work);
1319 events = READ_ONCE(sqe->poll_events); 1277 events = READ_ONCE(sqe->poll_events);
1320 poll->events = demangle_poll(events) | EPOLLERR | EPOLLHUP; 1278 poll->events = demangle_poll(events) | EPOLLERR | EPOLLHUP;
1321 1279
1322 flags = READ_ONCE(sqe->flags);
1323 fd = READ_ONCE(sqe->fd);
1324
1325 if (flags & IOSQE_FIXED_FILE) {
1326 if (unlikely(!ctx->user_files || fd >= ctx->nr_user_files))
1327 return -EBADF;
1328 poll->file = ctx->user_files[fd];
1329 req->flags |= REQ_F_FIXED_FILE;
1330 } else {
1331 poll->file = fget(fd);
1332 }
1333 if (unlikely(!poll->file))
1334 return -EBADF;
1335
1336 poll->head = NULL; 1280 poll->head = NULL;
1337 poll->woken = false; 1281 poll->done = false;
1338 poll->canceled = false; 1282 poll->canceled = false;
1339 1283
1340 ipt.pt._qproc = io_poll_queue_proc; 1284 ipt.pt._qproc = io_poll_queue_proc;
@@ -1346,56 +1290,44 @@ static int io_poll_add(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1346 INIT_LIST_HEAD(&poll->wait.entry); 1290 INIT_LIST_HEAD(&poll->wait.entry);
1347 init_waitqueue_func_entry(&poll->wait, io_poll_wake); 1291 init_waitqueue_func_entry(&poll->wait, io_poll_wake);
1348 1292
1349 /* one for removal from waitqueue, one for this function */
1350 refcount_set(&req->refs, 2);
1351
1352 mask = vfs_poll(poll->file, &ipt.pt) & poll->events; 1293 mask = vfs_poll(poll->file, &ipt.pt) & poll->events;
1353 if (unlikely(!poll->head)) {
1354 /* we did not manage to set up a waitqueue, done */
1355 goto out;
1356 }
1357 1294
1358 spin_lock_irq(&ctx->completion_lock); 1295 spin_lock_irq(&ctx->completion_lock);
1359 spin_lock(&poll->head->lock); 1296 if (likely(poll->head)) {
1360 if (poll->woken) { 1297 spin_lock(&poll->head->lock);
1361 /* wake_up context handles the rest */ 1298 if (unlikely(list_empty(&poll->wait.entry))) {
1362 mask = 0; 1299 if (ipt.error)
1300 cancel = true;
1301 ipt.error = 0;
1302 mask = 0;
1303 }
1304 if (mask || ipt.error)
1305 list_del_init(&poll->wait.entry);
1306 else if (cancel)
1307 WRITE_ONCE(poll->canceled, true);
1308 else if (!poll->done) /* actually waiting for an event */
1309 list_add_tail(&req->list, &ctx->cancel_list);
1310 spin_unlock(&poll->head->lock);
1311 }
1312 if (mask) { /* no async, we'd stolen it */
1313 req->error = mangle_poll(mask);
1363 ipt.error = 0; 1314 ipt.error = 0;
1364 } else if (mask || ipt.error) { 1315 io_poll_complete(ctx, req, mask);
1365 /* if we get an error or a mask we are done */
1366 WARN_ON_ONCE(list_empty(&poll->wait.entry));
1367 list_del_init(&poll->wait.entry);
1368 } else {
1369 /* actually waiting for an event */
1370 list_add_tail(&req->list, &ctx->cancel_list);
1371 } 1316 }
1372 spin_unlock(&poll->head->lock);
1373 spin_unlock_irq(&ctx->completion_lock); 1317 spin_unlock_irq(&ctx->completion_lock);
1374 1318
1375out: 1319 if (mask) {
1376 if (unlikely(ipt.error)) { 1320 io_cqring_ev_posted(ctx);
1377 if (!(flags & IOSQE_FIXED_FILE)) 1321 io_put_req(req);
1378 fput(poll->file);
1379 /*
1380 * Drop one of our refs to this req, __io_submit_sqe() will
1381 * drop the other one since we're returning an error.
1382 */
1383 io_free_req(req);
1384 return ipt.error;
1385 } 1322 }
1386 1323 return ipt.error;
1387 if (mask)
1388 io_poll_complete(req, mask);
1389 io_free_req(req);
1390 return 0;
1391} 1324}
1392 1325
1393static int __io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, 1326static int __io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,
1394 const struct sqe_submit *s, bool force_nonblock, 1327 const struct sqe_submit *s, bool force_nonblock,
1395 struct io_submit_state *state) 1328 struct io_submit_state *state)
1396{ 1329{
1397 ssize_t ret; 1330 int ret, opcode;
1398 int opcode;
1399 1331
1400 if (unlikely(s->index >= ctx->sq_entries)) 1332 if (unlikely(s->index >= ctx->sq_entries))
1401 return -EINVAL; 1333 return -EINVAL;
@@ -1524,10 +1456,13 @@ restart:
1524 break; 1456 break;
1525 cond_resched(); 1457 cond_resched();
1526 } while (1); 1458 } while (1);
1459
1460 /* drop submission reference */
1461 io_put_req(req);
1527 } 1462 }
1528 if (ret) { 1463 if (ret) {
1529 io_cqring_add_event(ctx, sqe->user_data, ret, 0); 1464 io_cqring_add_event(ctx, sqe->user_data, ret, 0);
1530 io_free_req(req); 1465 io_put_req(req);
1531 } 1466 }
1532 1467
1533 /* async context always use a copy of the sqe */ 1468 /* async context always use a copy of the sqe */
@@ -1614,11 +1549,55 @@ static bool io_add_to_prev_work(struct async_list *list, struct io_kiocb *req)
1614 return ret; 1549 return ret;
1615} 1550}
1616 1551
1552static bool io_op_needs_file(const struct io_uring_sqe *sqe)
1553{
1554 int op = READ_ONCE(sqe->opcode);
1555
1556 switch (op) {
1557 case IORING_OP_NOP:
1558 case IORING_OP_POLL_REMOVE:
1559 return false;
1560 default:
1561 return true;
1562 }
1563}
1564
1565static int io_req_set_file(struct io_ring_ctx *ctx, const struct sqe_submit *s,
1566 struct io_submit_state *state, struct io_kiocb *req)
1567{
1568 unsigned flags;
1569 int fd;
1570
1571 flags = READ_ONCE(s->sqe->flags);
1572 fd = READ_ONCE(s->sqe->fd);
1573
1574 if (!io_op_needs_file(s->sqe)) {
1575 req->file = NULL;
1576 return 0;
1577 }
1578
1579 if (flags & IOSQE_FIXED_FILE) {
1580 if (unlikely(!ctx->user_files ||
1581 (unsigned) fd >= ctx->nr_user_files))
1582 return -EBADF;
1583 req->file = ctx->user_files[fd];
1584 req->flags |= REQ_F_FIXED_FILE;
1585 } else {
1586 if (s->needs_fixed_file)
1587 return -EBADF;
1588 req->file = io_file_get(state, fd);
1589 if (unlikely(!req->file))
1590 return -EBADF;
1591 }
1592
1593 return 0;
1594}
1595
1617static int io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s, 1596static int io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s,
1618 struct io_submit_state *state) 1597 struct io_submit_state *state)
1619{ 1598{
1620 struct io_kiocb *req; 1599 struct io_kiocb *req;
1621 ssize_t ret; 1600 int ret;
1622 1601
1623 /* enforce forwards compatibility on users */ 1602 /* enforce forwards compatibility on users */
1624 if (unlikely(s->sqe->flags & ~IOSQE_FIXED_FILE)) 1603 if (unlikely(s->sqe->flags & ~IOSQE_FIXED_FILE))
@@ -1628,7 +1607,9 @@ static int io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s,
1628 if (unlikely(!req)) 1607 if (unlikely(!req))
1629 return -EAGAIN; 1608 return -EAGAIN;
1630 1609
1631 req->rw.ki_filp = NULL; 1610 ret = io_req_set_file(ctx, s, state, req);
1611 if (unlikely(ret))
1612 goto out;
1632 1613
1633 ret = __io_submit_sqe(ctx, req, s, true, state); 1614 ret = __io_submit_sqe(ctx, req, s, true, state);
1634 if (ret == -EAGAIN) { 1615 if (ret == -EAGAIN) {
@@ -1649,11 +1630,23 @@ static int io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s,
1649 INIT_WORK(&req->work, io_sq_wq_submit_work); 1630 INIT_WORK(&req->work, io_sq_wq_submit_work);
1650 queue_work(ctx->sqo_wq, &req->work); 1631 queue_work(ctx->sqo_wq, &req->work);
1651 } 1632 }
1652 ret = 0; 1633
1634 /*
1635 * Queued up for async execution, worker will release
1636 * submit reference when the iocb is actually
1637 * submitted.
1638 */
1639 return 0;
1653 } 1640 }
1654 } 1641 }
1642
1643out:
1644 /* drop submission reference */
1645 io_put_req(req);
1646
1647 /* and drop final reference, if we failed */
1655 if (ret) 1648 if (ret)
1656 io_free_req(req); 1649 io_put_req(req);
1657 1650
1658 return ret; 1651 return ret;
1659} 1652}
diff --git a/fs/iomap.c b/fs/iomap.c
index 97cb9d486a7d..abdd18e404f8 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -1589,12 +1589,14 @@ static void iomap_dio_bio_end_io(struct bio *bio)
1589 if (should_dirty) { 1589 if (should_dirty) {
1590 bio_check_pages_dirty(bio); 1590 bio_check_pages_dirty(bio);
1591 } else { 1591 } else {
1592 struct bio_vec *bvec; 1592 if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
1593 int i; 1593 struct bvec_iter_all iter_all;
1594 struct bvec_iter_all iter_all; 1594 struct bio_vec *bvec;
1595 int i;
1595 1596
1596 bio_for_each_segment_all(bvec, bio, i, iter_all) 1597 bio_for_each_segment_all(bvec, bio, i, iter_all)
1597 put_page(bvec->bv_page); 1598 put_page(bvec->bv_page);
1599 }
1598 bio_put(bio); 1600 bio_put(bio);
1599 } 1601 }
1600} 1602}
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 56992b32c6bb..a90bb19dcfa2 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -208,6 +208,7 @@ static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
208{ 208{
209 struct fanotify_event_info_fid info = { }; 209 struct fanotify_event_info_fid info = { };
210 struct file_handle handle = { }; 210 struct file_handle handle = { };
211 unsigned char bounce[FANOTIFY_INLINE_FH_LEN], *fh;
211 size_t fh_len = event->fh_len; 212 size_t fh_len = event->fh_len;
212 size_t len = fanotify_event_info_len(event); 213 size_t len = fanotify_event_info_len(event);
213 214
@@ -233,7 +234,16 @@ static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
233 234
234 buf += sizeof(handle); 235 buf += sizeof(handle);
235 len -= sizeof(handle); 236 len -= sizeof(handle);
236 if (copy_to_user(buf, fanotify_event_fh(event), fh_len)) 237 /*
238 * For an inline fh, copy through stack to exclude the copy from
239 * usercopy hardening protections.
240 */
241 fh = fanotify_event_fh(event);
242 if (fh_len <= FANOTIFY_INLINE_FH_LEN) {
243 memcpy(bounce, fh, fh_len);
244 fh = bounce;
245 }
246 if (copy_to_user(buf, fh, fh_len))
237 return -EFAULT; 247 return -EFAULT;
238 248
239 /* Pad with 0's */ 249 /* Pad with 0's */
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index e2901fbb9f76..7b53598c8804 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -519,8 +519,10 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
519 fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group); 519 fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group);
520 if (!fsn_mark) 520 if (!fsn_mark)
521 return -ENOENT; 521 return -ENOENT;
522 else if (create) 522 else if (create) {
523 return -EEXIST; 523 ret = -EEXIST;
524 goto out;
525 }
524 526
525 i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark); 527 i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
526 528
@@ -548,6 +550,7 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
548 /* return the wd */ 550 /* return the wd */
549 ret = i_mark->wd; 551 ret = i_mark->wd;
550 552
553out:
551 /* match the get from fsnotify_find_mark() */ 554 /* match the get from fsnotify_find_mark() */
552 fsnotify_put_mark(fsn_mark); 555 fsnotify_put_mark(fsn_mark);
553 556
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index bbcc185062bb..d29d869abec1 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -54,6 +54,28 @@ static LIST_HEAD(kclist_head);
54static DECLARE_RWSEM(kclist_lock); 54static DECLARE_RWSEM(kclist_lock);
55static int kcore_need_update = 1; 55static int kcore_need_update = 1;
56 56
57/*
58 * Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error
59 * Same as oldmem_pfn_is_ram in vmcore
60 */
61static int (*mem_pfn_is_ram)(unsigned long pfn);
62
63int __init register_mem_pfn_is_ram(int (*fn)(unsigned long pfn))
64{
65 if (mem_pfn_is_ram)
66 return -EBUSY;
67 mem_pfn_is_ram = fn;
68 return 0;
69}
70
71static int pfn_is_ram(unsigned long pfn)
72{
73 if (mem_pfn_is_ram)
74 return mem_pfn_is_ram(pfn);
75 else
76 return 1;
77}
78
57/* This doesn't grab kclist_lock, so it should only be used at init time. */ 79/* This doesn't grab kclist_lock, so it should only be used at init time. */
58void __init kclist_add(struct kcore_list *new, void *addr, size_t size, 80void __init kclist_add(struct kcore_list *new, void *addr, size_t size,
59 int type) 81 int type)
@@ -465,6 +487,11 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
465 goto out; 487 goto out;
466 } 488 }
467 m = NULL; /* skip the list anchor */ 489 m = NULL; /* skip the list anchor */
490 } else if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) {
491 if (clear_user(buffer, tsz)) {
492 ret = -EFAULT;
493 goto out;
494 }
468 } else if (m->type == KCORE_VMALLOC) { 495 } else if (m->type == KCORE_VMALLOC) {
469 vread(buf, (char *)start, tsz); 496 vread(buf, (char *)start, tsz);
470 /* we have to zero-fill user buffer even if no read */ 497 /* we have to zero-fill user buffer even if no read */
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index ae796e10f68b..e7276932e433 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1242,8 +1242,10 @@ set_size:
1242 truncate_setsize(inode, newsize); 1242 truncate_setsize(inode, newsize);
1243 down_write(&iinfo->i_data_sem); 1243 down_write(&iinfo->i_data_sem);
1244 udf_clear_extent_cache(inode); 1244 udf_clear_extent_cache(inode);
1245 udf_truncate_extents(inode); 1245 err = udf_truncate_extents(inode);
1246 up_write(&iinfo->i_data_sem); 1246 up_write(&iinfo->i_data_sem);
1247 if (err)
1248 return err;
1247 } 1249 }
1248update_time: 1250update_time:
1249 inode->i_mtime = inode->i_ctime = current_time(inode); 1251 inode->i_mtime = inode->i_ctime = current_time(inode);
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c
index b647f0bd150c..63a47f1e1d52 100644
--- a/fs/udf/truncate.c
+++ b/fs/udf/truncate.c
@@ -199,7 +199,7 @@ static void udf_update_alloc_ext_desc(struct inode *inode,
199 * for making file shorter. For making file longer, udf_extend_file() has to 199 * for making file shorter. For making file longer, udf_extend_file() has to
200 * be used. 200 * be used.
201 */ 201 */
202void udf_truncate_extents(struct inode *inode) 202int udf_truncate_extents(struct inode *inode)
203{ 203{
204 struct extent_position epos; 204 struct extent_position epos;
205 struct kernel_lb_addr eloc, neloc = {}; 205 struct kernel_lb_addr eloc, neloc = {};
@@ -224,7 +224,7 @@ void udf_truncate_extents(struct inode *inode)
224 if (etype == -1) { 224 if (etype == -1) {
225 /* We should extend the file? */ 225 /* We should extend the file? */
226 WARN_ON(byte_offset); 226 WARN_ON(byte_offset);
227 return; 227 return 0;
228 } 228 }
229 epos.offset -= adsize; 229 epos.offset -= adsize;
230 extent_trunc(inode, &epos, &eloc, etype, elen, byte_offset); 230 extent_trunc(inode, &epos, &eloc, etype, elen, byte_offset);
@@ -260,6 +260,9 @@ void udf_truncate_extents(struct inode *inode)
260 epos.block = eloc; 260 epos.block = eloc;
261 epos.bh = udf_tread(sb, 261 epos.bh = udf_tread(sb,
262 udf_get_lb_pblock(sb, &eloc, 0)); 262 udf_get_lb_pblock(sb, &eloc, 0));
263 /* Error reading indirect block? */
264 if (!epos.bh)
265 return -EIO;
263 if (elen) 266 if (elen)
264 indirect_ext_len = 267 indirect_ext_len =
265 (elen + sb->s_blocksize - 1) >> 268 (elen + sb->s_blocksize - 1) >>
@@ -283,4 +286,5 @@ void udf_truncate_extents(struct inode *inode)
283 iinfo->i_lenExtents = inode->i_size; 286 iinfo->i_lenExtents = inode->i_size;
284 287
285 brelse(epos.bh); 288 brelse(epos.bh);
289 return 0;
286} 290}
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index ee246769dee4..d89ef71887fc 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -235,7 +235,7 @@ extern struct inode *udf_new_inode(struct inode *, umode_t);
235/* truncate.c */ 235/* truncate.c */
236extern void udf_truncate_tail_extent(struct inode *); 236extern void udf_truncate_tail_extent(struct inode *);
237extern void udf_discard_prealloc(struct inode *); 237extern void udf_discard_prealloc(struct inode *);
238extern void udf_truncate_extents(struct inode *); 238extern int udf_truncate_extents(struct inode *);
239 239
240/* balloc.c */ 240/* balloc.c */
241extern void udf_free_blocks(struct super_block *, struct inode *, 241extern void udf_free_blocks(struct super_block *, struct inode *,
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index b0c814bcc7e3..cb2aa7ecafff 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -57,7 +57,6 @@ struct blk_mq_hw_ctx {
57 unsigned int queue_num; 57 unsigned int queue_num;
58 58
59 atomic_t nr_active; 59 atomic_t nr_active;
60 unsigned int nr_expired;
61 60
62 struct hlist_node cpuhp_dead; 61 struct hlist_node cpuhp_dead;
63 struct kobject kobj; 62 struct kobject kobj;
@@ -300,8 +299,6 @@ void blk_mq_end_request(struct request *rq, blk_status_t error);
300void __blk_mq_end_request(struct request *rq, blk_status_t error); 299void __blk_mq_end_request(struct request *rq, blk_status_t error);
301 300
302void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list); 301void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list);
303void blk_mq_add_to_requeue_list(struct request *rq, bool at_head,
304 bool kick_requeue_list);
305void blk_mq_kick_requeue_list(struct request_queue *q); 302void blk_mq_kick_requeue_list(struct request_queue *q);
306void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs); 303void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs);
307bool blk_mq_complete_request(struct request *rq); 304bool blk_mq_complete_request(struct request *rq);
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index d66bf5f32610..791fee35df88 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -215,6 +215,7 @@ struct bio {
215/* 215/*
216 * bio flags 216 * bio flags
217 */ 217 */
218#define BIO_NO_PAGE_REF 0 /* don't put release vec pages */
218#define BIO_SEG_VALID 1 /* bi_phys_segments valid */ 219#define BIO_SEG_VALID 1 /* bi_phys_segments valid */
219#define BIO_CLONED 2 /* doesn't own data */ 220#define BIO_CLONED 2 /* doesn't own data */
220#define BIO_BOUNCED 3 /* bio is a bounce bio */ 221#define BIO_BOUNCED 3 /* bio is a bounce bio */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 0de92b29f589..5c58a3b2bf00 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -50,6 +50,9 @@ struct blk_stat_callback;
50/* Must be consistent with blk_mq_poll_stats_bkt() */ 50/* Must be consistent with blk_mq_poll_stats_bkt() */
51#define BLK_MQ_POLL_STATS_BKTS 16 51#define BLK_MQ_POLL_STATS_BKTS 16
52 52
53/* Doing classic polling */
54#define BLK_MQ_POLL_CLASSIC -1
55
53/* 56/*
54 * Maximum number of blkcg policies allowed to be registered concurrently. 57 * Maximum number of blkcg policies allowed to be registered concurrently.
55 * Defined here to simplify include dependency. 58 * Defined here to simplify include dependency.
diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h
index a420c07904bc..337d5049ff93 100644
--- a/include/linux/ceph/libceph.h
+++ b/include/linux/ceph/libceph.h
@@ -294,6 +294,8 @@ extern void ceph_destroy_client(struct ceph_client *client);
294extern int __ceph_open_session(struct ceph_client *client, 294extern int __ceph_open_session(struct ceph_client *client,
295 unsigned long started); 295 unsigned long started);
296extern int ceph_open_session(struct ceph_client *client); 296extern int ceph_open_session(struct ceph_client *client);
297int ceph_wait_for_latest_osdmap(struct ceph_client *client,
298 unsigned long timeout);
297 299
298/* pagevec.c */ 300/* pagevec.c */
299extern void ceph_release_page_vector(struct page **pages, int num_pages); 301extern void ceph_release_page_vector(struct page **pages, int num_pages);
diff --git a/include/linux/irq.h b/include/linux/irq.h
index d6160d479b14..7ae8de5ad0f2 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -195,7 +195,7 @@ struct irq_data {
195 * IRQD_LEVEL - Interrupt is level triggered 195 * IRQD_LEVEL - Interrupt is level triggered
196 * IRQD_WAKEUP_STATE - Interrupt is configured for wakeup 196 * IRQD_WAKEUP_STATE - Interrupt is configured for wakeup
197 * from suspend 197 * from suspend
198 * IRDQ_MOVE_PCNTXT - Interrupt can be moved in process 198 * IRQD_MOVE_PCNTXT - Interrupt can be moved in process
199 * context 199 * context
200 * IRQD_IRQ_DISABLED - Disabled state of the interrupt 200 * IRQD_IRQ_DISABLED - Disabled state of the interrupt
201 * IRQD_IRQ_MASKED - Masked state of the interrupt 201 * IRQD_IRQ_MASKED - Masked state of the interrupt
diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
index 626179077bb0..0f049b384ccd 100644
--- a/include/linux/irqchip/arm-gic.h
+++ b/include/linux/irqchip/arm-gic.h
@@ -158,8 +158,7 @@ int gic_of_init_child(struct device *dev, struct gic_chip_data **gic, int irq);
158 * Legacy platforms not converted to DT yet must use this to init 158 * Legacy platforms not converted to DT yet must use this to init
159 * their GIC 159 * their GIC
160 */ 160 */
161void gic_init(unsigned int nr, int start, 161void gic_init(void __iomem *dist , void __iomem *cpu);
162 void __iomem *dist , void __iomem *cpu);
163 162
164int gicv2m_init(struct fwnode_handle *parent_handle, 163int gicv2m_init(struct fwnode_handle *parent_handle,
165 struct irq_domain *parent); 164 struct irq_domain *parent);
diff --git a/include/linux/kcore.h b/include/linux/kcore.h
index 8c3f8c14eeaa..c843f4a9c512 100644
--- a/include/linux/kcore.h
+++ b/include/linux/kcore.h
@@ -44,6 +44,8 @@ void kclist_add_remap(struct kcore_list *m, void *addr, void *vaddr, size_t sz)
44 m->vaddr = (unsigned long)vaddr; 44 m->vaddr = (unsigned long)vaddr;
45 kclist_add(m, addr, sz, KCORE_REMAP); 45 kclist_add(m, addr, sz, KCORE_REMAP);
46} 46}
47
48extern int __init register_mem_pfn_is_ram(int (*fn)(unsigned long pfn));
47#else 49#else
48static inline 50static inline
49void kclist_add(struct kcore_list *new, void *addr, size_t size, int type) 51void kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
diff --git a/include/linux/mlx5/qp.h b/include/linux/mlx5/qp.h
index b26ea9077384..0343c81d4c5f 100644
--- a/include/linux/mlx5/qp.h
+++ b/include/linux/mlx5/qp.h
@@ -557,7 +557,8 @@ static inline struct mlx5_core_mkey *__mlx5_mr_lookup(struct mlx5_core_dev *dev,
557 557
558int mlx5_core_create_dct(struct mlx5_core_dev *dev, 558int mlx5_core_create_dct(struct mlx5_core_dev *dev,
559 struct mlx5_core_dct *qp, 559 struct mlx5_core_dct *qp,
560 u32 *in, int inlen); 560 u32 *in, int inlen,
561 u32 *out, int outlen);
561int mlx5_core_create_qp(struct mlx5_core_dev *dev, 562int mlx5_core_create_qp(struct mlx5_core_dev *dev,
562 struct mlx5_core_qp *qp, 563 struct mlx5_core_qp *qp,
563 u32 *in, 564 u32 *in,
diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
index 14d558146aea..20f3e3f029b9 100644
--- a/include/linux/sbitmap.h
+++ b/include/linux/sbitmap.h
@@ -330,7 +330,7 @@ static inline void sbitmap_clear_bit(struct sbitmap *sb, unsigned int bitnr)
330/* 330/*
331 * This one is special, since it doesn't actually clear the bit, rather it 331 * This one is special, since it doesn't actually clear the bit, rather it
332 * sets the corresponding bit in the ->cleared mask instead. Paired with 332 * sets the corresponding bit in the ->cleared mask instead. Paired with
333 * the caller doing sbitmap_batch_clear() if a given index is full, which 333 * the caller doing sbitmap_deferred_clear() if a given index is full, which
334 * will clear the previously freed entries in the corresponding ->word. 334 * will clear the previously freed entries in the corresponding ->word.
335 */ 335 */
336static inline void sbitmap_deferred_clear_bit(struct sbitmap *sb, unsigned int bitnr) 336static inline void sbitmap_deferred_clear_bit(struct sbitmap *sb, unsigned int bitnr)
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 87477e1640f9..f184af1999a8 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -23,14 +23,23 @@ struct kvec {
23}; 23};
24 24
25enum iter_type { 25enum iter_type {
26 ITER_IOVEC = 0, 26 /* set if ITER_BVEC doesn't hold a bv_page ref */
27 ITER_KVEC = 2, 27 ITER_BVEC_FLAG_NO_REF = 2,
28 ITER_BVEC = 4, 28
29 ITER_PIPE = 8, 29 /* iter types */
30 ITER_DISCARD = 16, 30 ITER_IOVEC = 4,
31 ITER_KVEC = 8,
32 ITER_BVEC = 16,
33 ITER_PIPE = 32,
34 ITER_DISCARD = 64,
31}; 35};
32 36
33struct iov_iter { 37struct iov_iter {
38 /*
39 * Bit 0 is the read/write bit, set if we're writing.
40 * Bit 1 is the BVEC_FLAG_NO_REF bit, set if type is a bvec and
41 * the caller isn't expecting to drop a page reference when done.
42 */
34 unsigned int type; 43 unsigned int type;
35 size_t iov_offset; 44 size_t iov_offset;
36 size_t count; 45 size_t count;
@@ -84,6 +93,11 @@ static inline unsigned char iov_iter_rw(const struct iov_iter *i)
84 return i->type & (READ | WRITE); 93 return i->type & (READ | WRITE);
85} 94}
86 95
96static inline bool iov_iter_bvec_no_ref(const struct iov_iter *i)
97{
98 return (i->type & ITER_BVEC_FLAG_NO_REF) != 0;
99}
100
87/* 101/*
88 * Total number of bytes covered by an iovec. 102 * Total number of bytes covered by an iovec.
89 * 103 *
diff --git a/include/misc/charlcd.h b/include/misc/charlcd.h
index 23f61850f363..1832402324ce 100644
--- a/include/misc/charlcd.h
+++ b/include/misc/charlcd.h
@@ -35,6 +35,7 @@ struct charlcd_ops {
35}; 35};
36 36
37struct charlcd *charlcd_alloc(unsigned int drvdata_size); 37struct charlcd *charlcd_alloc(unsigned int drvdata_size);
38void charlcd_free(struct charlcd *lcd);
38 39
39int charlcd_register(struct charlcd *lcd); 40int charlcd_register(struct charlcd *lcd);
40int charlcd_unregister(struct charlcd *lcd); 41int charlcd_unregister(struct charlcd *lcd);
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1032a16bd186..72d06e302e99 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7189,6 +7189,7 @@ static void perf_event_mmap_output(struct perf_event *event,
7189 struct perf_output_handle handle; 7189 struct perf_output_handle handle;
7190 struct perf_sample_data sample; 7190 struct perf_sample_data sample;
7191 int size = mmap_event->event_id.header.size; 7191 int size = mmap_event->event_id.header.size;
7192 u32 type = mmap_event->event_id.header.type;
7192 int ret; 7193 int ret;
7193 7194
7194 if (!perf_event_mmap_match(event, data)) 7195 if (!perf_event_mmap_match(event, data))
@@ -7232,6 +7233,7 @@ static void perf_event_mmap_output(struct perf_event *event,
7232 perf_output_end(&handle); 7233 perf_output_end(&handle);
7233out: 7234out:
7234 mmap_event->event_id.header.size = size; 7235 mmap_event->event_id.header.size = size;
7236 mmap_event->event_id.header.type = type;
7235} 7237}
7236 7238
7237static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) 7239static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
diff --git a/kernel/futex.c b/kernel/futex.c
index c3b73b0311bc..9e40cf7be606 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3436,6 +3436,10 @@ static int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int p
3436{ 3436{
3437 u32 uval, uninitialized_var(nval), mval; 3437 u32 uval, uninitialized_var(nval), mval;
3438 3438
3439 /* Futex address must be 32bit aligned */
3440 if ((((unsigned long)uaddr) % sizeof(*uaddr)) != 0)
3441 return -1;
3442
3439retry: 3443retry:
3440 if (get_user(uval, uaddr)) 3444 if (get_user(uval, uaddr))
3441 return -1; 3445 return -1;
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
index 5d5378ea0afe..f808c6a97dcc 100644
--- a/kernel/irq/devres.c
+++ b/kernel/irq/devres.c
@@ -84,8 +84,6 @@ EXPORT_SYMBOL(devm_request_threaded_irq);
84 * @dev: device to request interrupt for 84 * @dev: device to request interrupt for
85 * @irq: Interrupt line to allocate 85 * @irq: Interrupt line to allocate
86 * @handler: Function to be called when the IRQ occurs 86 * @handler: Function to be called when the IRQ occurs
87 * @thread_fn: function to be called in a threaded interrupt context. NULL
88 * for devices which handle everything in @handler
89 * @irqflags: Interrupt type flags 87 * @irqflags: Interrupt type flags
90 * @devname: An ascii name for the claiming device, dev_name(dev) if NULL 88 * @devname: An ascii name for the claiming device, dev_name(dev) if NULL
91 * @dev_id: A cookie passed back to the handler function 89 * @dev_id: A cookie passed back to the handler function
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 9ec34a2a6638..1401afa0d58a 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -196,6 +196,7 @@ int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
196 case IRQ_SET_MASK_OK: 196 case IRQ_SET_MASK_OK:
197 case IRQ_SET_MASK_OK_DONE: 197 case IRQ_SET_MASK_OK_DONE:
198 cpumask_copy(desc->irq_common_data.affinity, mask); 198 cpumask_copy(desc->irq_common_data.affinity, mask);
199 /* fall through */
199 case IRQ_SET_MASK_OK_NOCOPY: 200 case IRQ_SET_MASK_OK_NOCOPY:
200 irq_validate_effective_affinity(data); 201 irq_validate_effective_affinity(data);
201 irq_set_thread_affinity(desc); 202 irq_set_thread_affinity(desc);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ead464a0f2e5..4778c48a7fda 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6998,7 +6998,7 @@ static int __maybe_unused cpu_period_quota_parse(char *buf,
6998{ 6998{
6999 char tok[21]; /* U64_MAX */ 6999 char tok[21]; /* U64_MAX */
7000 7000
7001 if (!sscanf(buf, "%s %llu", tok, periodp)) 7001 if (sscanf(buf, "%20s %llu", tok, periodp) < 1)
7002 return -EINVAL; 7002 return -EINVAL;
7003 7003
7004 *periodp *= NSEC_PER_USEC; 7004 *periodp *= NSEC_PER_USEC;
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 2efe629425be..5c41ea367422 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -48,10 +48,10 @@ struct sugov_cpu {
48 48
49 bool iowait_boost_pending; 49 bool iowait_boost_pending;
50 unsigned int iowait_boost; 50 unsigned int iowait_boost;
51 unsigned int iowait_boost_max;
52 u64 last_update; 51 u64 last_update;
53 52
54 unsigned long bw_dl; 53 unsigned long bw_dl;
54 unsigned long min;
55 unsigned long max; 55 unsigned long max;
56 56
57 /* The field below is for single-CPU policies only: */ 57 /* The field below is for single-CPU policies only: */
@@ -303,8 +303,7 @@ static bool sugov_iowait_reset(struct sugov_cpu *sg_cpu, u64 time,
303 if (delta_ns <= TICK_NSEC) 303 if (delta_ns <= TICK_NSEC)
304 return false; 304 return false;
305 305
306 sg_cpu->iowait_boost = set_iowait_boost 306 sg_cpu->iowait_boost = set_iowait_boost ? sg_cpu->min : 0;
307 ? sg_cpu->sg_policy->policy->min : 0;
308 sg_cpu->iowait_boost_pending = set_iowait_boost; 307 sg_cpu->iowait_boost_pending = set_iowait_boost;
309 308
310 return true; 309 return true;
@@ -344,14 +343,13 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
344 343
345 /* Double the boost at each request */ 344 /* Double the boost at each request */
346 if (sg_cpu->iowait_boost) { 345 if (sg_cpu->iowait_boost) {
347 sg_cpu->iowait_boost <<= 1; 346 sg_cpu->iowait_boost =
348 if (sg_cpu->iowait_boost > sg_cpu->iowait_boost_max) 347 min_t(unsigned int, sg_cpu->iowait_boost << 1, SCHED_CAPACITY_SCALE);
349 sg_cpu->iowait_boost = sg_cpu->iowait_boost_max;
350 return; 348 return;
351 } 349 }
352 350
353 /* First wakeup after IO: start with minimum boost */ 351 /* First wakeup after IO: start with minimum boost */
354 sg_cpu->iowait_boost = sg_cpu->sg_policy->policy->min; 352 sg_cpu->iowait_boost = sg_cpu->min;
355} 353}
356 354
357/** 355/**
@@ -373,47 +371,38 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
373 * This mechanism is designed to boost high frequently IO waiting tasks, while 371 * This mechanism is designed to boost high frequently IO waiting tasks, while
374 * being more conservative on tasks which does sporadic IO operations. 372 * being more conservative on tasks which does sporadic IO operations.
375 */ 373 */
376static void sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time, 374static unsigned long sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time,
377 unsigned long *util, unsigned long *max) 375 unsigned long util, unsigned long max)
378{ 376{
379 unsigned int boost_util, boost_max; 377 unsigned long boost;
380 378
381 /* No boost currently required */ 379 /* No boost currently required */
382 if (!sg_cpu->iowait_boost) 380 if (!sg_cpu->iowait_boost)
383 return; 381 return util;
384 382
385 /* Reset boost if the CPU appears to have been idle enough */ 383 /* Reset boost if the CPU appears to have been idle enough */
386 if (sugov_iowait_reset(sg_cpu, time, false)) 384 if (sugov_iowait_reset(sg_cpu, time, false))
387 return; 385 return util;
388 386
389 /* 387 if (!sg_cpu->iowait_boost_pending) {
390 * An IO waiting task has just woken up:
391 * allow to further double the boost value
392 */
393 if (sg_cpu->iowait_boost_pending) {
394 sg_cpu->iowait_boost_pending = false;
395 } else {
396 /* 388 /*
397 * Otherwise: reduce the boost value and disable it when we 389 * No boost pending; reduce the boost value.
398 * reach the minimum.
399 */ 390 */
400 sg_cpu->iowait_boost >>= 1; 391 sg_cpu->iowait_boost >>= 1;
401 if (sg_cpu->iowait_boost < sg_cpu->sg_policy->policy->min) { 392 if (sg_cpu->iowait_boost < sg_cpu->min) {
402 sg_cpu->iowait_boost = 0; 393 sg_cpu->iowait_boost = 0;
403 return; 394 return util;
404 } 395 }
405 } 396 }
406 397
398 sg_cpu->iowait_boost_pending = false;
399
407 /* 400 /*
408 * Apply the current boost value: a CPU is boosted only if its current 401 * @util is already in capacity scale; convert iowait_boost
409 * utilization is smaller then the current IO boost level. 402 * into the same scale so we can compare.
410 */ 403 */
411 boost_util = sg_cpu->iowait_boost; 404 boost = (sg_cpu->iowait_boost * max) >> SCHED_CAPACITY_SHIFT;
412 boost_max = sg_cpu->iowait_boost_max; 405 return max(boost, util);
413 if (*util * boost_max < *max * boost_util) {
414 *util = boost_util;
415 *max = boost_max;
416 }
417} 406}
418 407
419#ifdef CONFIG_NO_HZ_COMMON 408#ifdef CONFIG_NO_HZ_COMMON
@@ -460,7 +449,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
460 449
461 util = sugov_get_util(sg_cpu); 450 util = sugov_get_util(sg_cpu);
462 max = sg_cpu->max; 451 max = sg_cpu->max;
463 sugov_iowait_apply(sg_cpu, time, &util, &max); 452 util = sugov_iowait_apply(sg_cpu, time, util, max);
464 next_f = get_next_freq(sg_policy, util, max); 453 next_f = get_next_freq(sg_policy, util, max);
465 /* 454 /*
466 * Do not reduce the frequency if the CPU has not been idle 455 * Do not reduce the frequency if the CPU has not been idle
@@ -500,7 +489,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time)
500 489
501 j_util = sugov_get_util(j_sg_cpu); 490 j_util = sugov_get_util(j_sg_cpu);
502 j_max = j_sg_cpu->max; 491 j_max = j_sg_cpu->max;
503 sugov_iowait_apply(j_sg_cpu, time, &j_util, &j_max); 492 j_util = sugov_iowait_apply(j_sg_cpu, time, j_util, j_max);
504 493
505 if (j_util * max > j_max * util) { 494 if (j_util * max > j_max * util) {
506 util = j_util; 495 util = j_util;
@@ -837,7 +826,9 @@ static int sugov_start(struct cpufreq_policy *policy)
837 memset(sg_cpu, 0, sizeof(*sg_cpu)); 826 memset(sg_cpu, 0, sizeof(*sg_cpu));
838 sg_cpu->cpu = cpu; 827 sg_cpu->cpu = cpu;
839 sg_cpu->sg_policy = sg_policy; 828 sg_cpu->sg_policy = sg_policy;
840 sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq; 829 sg_cpu->min =
830 (SCHED_CAPACITY_SCALE * policy->cpuinfo.min_freq) /
831 policy->cpuinfo.max_freq;
841 } 832 }
842 833
843 for_each_cpu(cpu, policy->cpus) { 834 for_each_cpu(cpu, policy->cpus) {
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ea74d43924b2..fdab7eb6f351 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8060,6 +8060,18 @@ check_cpu_capacity(struct rq *rq, struct sched_domain *sd)
8060} 8060}
8061 8061
8062/* 8062/*
8063 * Check whether a rq has a misfit task and if it looks like we can actually
8064 * help that task: we can migrate the task to a CPU of higher capacity, or
8065 * the task's current CPU is heavily pressured.
8066 */
8067static inline int check_misfit_status(struct rq *rq, struct sched_domain *sd)
8068{
8069 return rq->misfit_task_load &&
8070 (rq->cpu_capacity_orig < rq->rd->max_cpu_capacity ||
8071 check_cpu_capacity(rq, sd));
8072}
8073
8074/*
8063 * Group imbalance indicates (and tries to solve) the problem where balancing 8075 * Group imbalance indicates (and tries to solve) the problem where balancing
8064 * groups is inadequate due to ->cpus_allowed constraints. 8076 * groups is inadequate due to ->cpus_allowed constraints.
8065 * 8077 *
@@ -9586,35 +9598,21 @@ static void nohz_balancer_kick(struct rq *rq)
9586 if (time_before(now, nohz.next_balance)) 9598 if (time_before(now, nohz.next_balance))
9587 goto out; 9599 goto out;
9588 9600
9589 if (rq->nr_running >= 2 || rq->misfit_task_load) { 9601 if (rq->nr_running >= 2) {
9590 flags = NOHZ_KICK_MASK; 9602 flags = NOHZ_KICK_MASK;
9591 goto out; 9603 goto out;
9592 } 9604 }
9593 9605
9594 rcu_read_lock(); 9606 rcu_read_lock();
9595 sds = rcu_dereference(per_cpu(sd_llc_shared, cpu));
9596 if (sds) {
9597 /*
9598 * If there is an imbalance between LLC domains (IOW we could
9599 * increase the overall cache use), we need some less-loaded LLC
9600 * domain to pull some load. Likewise, we may need to spread
9601 * load within the current LLC domain (e.g. packed SMT cores but
9602 * other CPUs are idle). We can't really know from here how busy
9603 * the others are - so just get a nohz balance going if it looks
9604 * like this LLC domain has tasks we could move.
9605 */
9606 nr_busy = atomic_read(&sds->nr_busy_cpus);
9607 if (nr_busy > 1) {
9608 flags = NOHZ_KICK_MASK;
9609 goto unlock;
9610 }
9611
9612 }
9613 9607
9614 sd = rcu_dereference(rq->sd); 9608 sd = rcu_dereference(rq->sd);
9615 if (sd) { 9609 if (sd) {
9616 if ((rq->cfs.h_nr_running >= 1) && 9610 /*
9617 check_cpu_capacity(rq, sd)) { 9611 * If there's a CFS task and the current CPU has reduced
9612 * capacity; kick the ILB to see if there's a better CPU to run
9613 * on.
9614 */
9615 if (rq->cfs.h_nr_running >= 1 && check_cpu_capacity(rq, sd)) {
9618 flags = NOHZ_KICK_MASK; 9616 flags = NOHZ_KICK_MASK;
9619 goto unlock; 9617 goto unlock;
9620 } 9618 }
@@ -9622,6 +9620,11 @@ static void nohz_balancer_kick(struct rq *rq)
9622 9620
9623 sd = rcu_dereference(per_cpu(sd_asym_packing, cpu)); 9621 sd = rcu_dereference(per_cpu(sd_asym_packing, cpu));
9624 if (sd) { 9622 if (sd) {
9623 /*
9624 * When ASYM_PACKING; see if there's a more preferred CPU
9625 * currently idle; in which case, kick the ILB to move tasks
9626 * around.
9627 */
9625 for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) { 9628 for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) {
9626 if (sched_asym_prefer(i, cpu)) { 9629 if (sched_asym_prefer(i, cpu)) {
9627 flags = NOHZ_KICK_MASK; 9630 flags = NOHZ_KICK_MASK;
@@ -9629,6 +9632,45 @@ static void nohz_balancer_kick(struct rq *rq)
9629 } 9632 }
9630 } 9633 }
9631 } 9634 }
9635
9636 sd = rcu_dereference(per_cpu(sd_asym_cpucapacity, cpu));
9637 if (sd) {
9638 /*
9639 * When ASYM_CPUCAPACITY; see if there's a higher capacity CPU
9640 * to run the misfit task on.
9641 */
9642 if (check_misfit_status(rq, sd)) {
9643 flags = NOHZ_KICK_MASK;
9644 goto unlock;
9645 }
9646
9647 /*
9648 * For asymmetric systems, we do not want to nicely balance
9649 * cache use, instead we want to embrace asymmetry and only
9650 * ensure tasks have enough CPU capacity.
9651 *
9652 * Skip the LLC logic because it's not relevant in that case.
9653 */
9654 goto unlock;
9655 }
9656
9657 sds = rcu_dereference(per_cpu(sd_llc_shared, cpu));
9658 if (sds) {
9659 /*
9660 * If there is an imbalance between LLC domains (IOW we could
9661 * increase the overall cache use), we need some less-loaded LLC
9662 * domain to pull some load. Likewise, we may need to spread
9663 * load within the current LLC domain (e.g. packed SMT cores but
9664 * other CPUs are idle). We can't really know from here how busy
9665 * the others are - so just get a nohz balance going if it looks
9666 * like this LLC domain has tasks we could move.
9667 */
9668 nr_busy = atomic_read(&sds->nr_busy_cpus);
9669 if (nr_busy > 1) {
9670 flags = NOHZ_KICK_MASK;
9671 goto unlock;
9672 }
9673 }
9632unlock: 9674unlock:
9633 rcu_read_unlock(); 9675 rcu_read_unlock();
9634out: 9676out:
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index dc1b6f1929f9..ac9c03dd6c7d 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -89,7 +89,7 @@ struct clocksource * __init __weak clocksource_default_clock(void)
89 return &clocksource_jiffies; 89 return &clocksource_jiffies;
90} 90}
91 91
92struct clocksource refined_jiffies; 92static struct clocksource refined_jiffies;
93 93
94int register_refined_jiffies(long cycles_per_second) 94int register_refined_jiffies(long cycles_per_second)
95{ 95{
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 8fbfda94a67b..403c9bd90413 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -42,9 +42,9 @@ int __read_mostly watchdog_user_enabled = 1;
42int __read_mostly nmi_watchdog_user_enabled = NMI_WATCHDOG_DEFAULT; 42int __read_mostly nmi_watchdog_user_enabled = NMI_WATCHDOG_DEFAULT;
43int __read_mostly soft_watchdog_user_enabled = 1; 43int __read_mostly soft_watchdog_user_enabled = 1;
44int __read_mostly watchdog_thresh = 10; 44int __read_mostly watchdog_thresh = 10;
45int __read_mostly nmi_watchdog_available; 45static int __read_mostly nmi_watchdog_available;
46 46
47struct cpumask watchdog_allowed_mask __read_mostly; 47static struct cpumask watchdog_allowed_mask __read_mostly;
48 48
49struct cpumask watchdog_cpumask __read_mostly; 49struct cpumask watchdog_cpumask __read_mostly;
50unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask); 50unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 4026d1871407..ddee541ea97a 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4266,7 +4266,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
4266 INIT_LIST_HEAD(&wq->list); 4266 INIT_LIST_HEAD(&wq->list);
4267 4267
4268 if (alloc_and_link_pwqs(wq) < 0) 4268 if (alloc_and_link_pwqs(wq) < 0)
4269 goto err_free_wq; 4269 goto err_unreg_lockdep;
4270 4270
4271 if (wq_online && init_rescuer(wq) < 0) 4271 if (wq_online && init_rescuer(wq) < 0)
4272 goto err_destroy; 4272 goto err_destroy;
@@ -4292,9 +4292,10 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
4292 4292
4293 return wq; 4293 return wq;
4294 4294
4295err_free_wq: 4295err_unreg_lockdep:
4296 wq_unregister_lockdep(wq); 4296 wq_unregister_lockdep(wq);
4297 wq_free_lockdep(wq); 4297 wq_free_lockdep(wq);
4298err_free_wq:
4298 free_workqueue_attrs(wq->unbound_attrs); 4299 free_workqueue_attrs(wq->unbound_attrs);
4299 kfree(wq); 4300 kfree(wq);
4300 return NULL; 4301 return NULL;
diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c
index 9cab80207ced..79eac465ec65 100644
--- a/net/ceph/ceph_common.c
+++ b/net/ceph/ceph_common.c
@@ -738,7 +738,6 @@ int __ceph_open_session(struct ceph_client *client, unsigned long started)
738} 738}
739EXPORT_SYMBOL(__ceph_open_session); 739EXPORT_SYMBOL(__ceph_open_session);
740 740
741
742int ceph_open_session(struct ceph_client *client) 741int ceph_open_session(struct ceph_client *client)
743{ 742{
744 int ret; 743 int ret;
@@ -754,6 +753,23 @@ int ceph_open_session(struct ceph_client *client)
754} 753}
755EXPORT_SYMBOL(ceph_open_session); 754EXPORT_SYMBOL(ceph_open_session);
756 755
756int ceph_wait_for_latest_osdmap(struct ceph_client *client,
757 unsigned long timeout)
758{
759 u64 newest_epoch;
760 int ret;
761
762 ret = ceph_monc_get_version(&client->monc, "osdmap", &newest_epoch);
763 if (ret)
764 return ret;
765
766 if (client->osdc.osdmap->epoch >= newest_epoch)
767 return 0;
768
769 ceph_osdc_maybe_request_map(&client->osdc);
770 return ceph_monc_wait_osdmap(&client->monc, newest_epoch, timeout);
771}
772EXPORT_SYMBOL(ceph_wait_for_latest_osdmap);
757 773
758static int __init init_ceph_lib(void) 774static int __init init_ceph_lib(void)
759{ 775{
diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
index 18deb3d889c4..a53e4fbb6319 100644
--- a/net/ceph/mon_client.c
+++ b/net/ceph/mon_client.c
@@ -922,6 +922,15 @@ int ceph_monc_blacklist_add(struct ceph_mon_client *monc,
922 mutex_unlock(&monc->mutex); 922 mutex_unlock(&monc->mutex);
923 923
924 ret = wait_generic_request(req); 924 ret = wait_generic_request(req);
925 if (!ret)
926 /*
927 * Make sure we have the osdmap that includes the blacklist
928 * entry. This is needed to ensure that the OSDs pick up the
929 * new blacklist before processing any future requests from
930 * this client.
931 */
932 ret = ceph_wait_for_latest_osdmap(monc->client, 0);
933
925out: 934out:
926 put_generic_request(req); 935 put_generic_request(req);
927 return ret; 936 return ret;
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 6b576e588725..daecdfb15a9c 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -828,9 +828,11 @@ void policydb_destroy(struct policydb *p)
828 hashtab_map(p->range_tr, range_tr_destroy, NULL); 828 hashtab_map(p->range_tr, range_tr_destroy, NULL);
829 hashtab_destroy(p->range_tr); 829 hashtab_destroy(p->range_tr);
830 830
831 for (i = 0; i < p->p_types.nprim; i++) 831 if (p->type_attr_map_array) {
832 ebitmap_destroy(&p->type_attr_map_array[i]); 832 for (i = 0; i < p->p_types.nprim; i++)
833 kvfree(p->type_attr_map_array); 833 ebitmap_destroy(&p->type_attr_map_array[i]);
834 kvfree(p->type_attr_map_array);
835 }
834 836
835 ebitmap_destroy(&p->filename_trans_ttypes); 837 ebitmap_destroy(&p->filename_trans_ttypes);
836 ebitmap_destroy(&p->policycaps); 838 ebitmap_destroy(&p->policycaps);
@@ -2496,10 +2498,13 @@ int policydb_read(struct policydb *p, void *fp)
2496 if (!p->type_attr_map_array) 2498 if (!p->type_attr_map_array)
2497 goto bad; 2499 goto bad;
2498 2500
2501 /* just in case ebitmap_init() becomes more than just a memset(0): */
2502 for (i = 0; i < p->p_types.nprim; i++)
2503 ebitmap_init(&p->type_attr_map_array[i]);
2504
2499 for (i = 0; i < p->p_types.nprim; i++) { 2505 for (i = 0; i < p->p_types.nprim; i++) {
2500 struct ebitmap *e = &p->type_attr_map_array[i]; 2506 struct ebitmap *e = &p->type_attr_map_array[i];
2501 2507
2502 ebitmap_init(e);
2503 if (p->policyvers >= POLICYDB_VERSION_AVTAB) { 2508 if (p->policyvers >= POLICYDB_VERSION_AVTAB) {
2504 rc = ebitmap_read(e, fp); 2509 rc = ebitmap_read(e, fp);
2505 if (rc) 2510 if (rc)
diff --git a/sound/drivers/opl3/opl3_voice.h b/sound/drivers/opl3/opl3_voice.h
index 5b02bd49fde4..4e4ecc21760b 100644
--- a/sound/drivers/opl3/opl3_voice.h
+++ b/sound/drivers/opl3/opl3_voice.h
@@ -41,7 +41,7 @@ void snd_opl3_timer_func(struct timer_list *t);
41 41
42/* Prototypes for opl3_drums.c */ 42/* Prototypes for opl3_drums.c */
43void snd_opl3_load_drums(struct snd_opl3 *opl3); 43void snd_opl3_load_drums(struct snd_opl3 *opl3);
44void snd_opl3_drum_switch(struct snd_opl3 *opl3, int note, int on_off, int vel, struct snd_midi_channel *chan); 44void snd_opl3_drum_switch(struct snd_opl3 *opl3, int note, int vel, int on_off, struct snd_midi_channel *chan);
45 45
46/* Prototypes for opl3_oss.c */ 46/* Prototypes for opl3_oss.c */
47#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS) 47#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
diff --git a/sound/firewire/motu/motu.c b/sound/firewire/motu/motu.c
index 220e61926ea4..513291ba0ab0 100644
--- a/sound/firewire/motu/motu.c
+++ b/sound/firewire/motu/motu.c
@@ -36,7 +36,7 @@ static void name_card(struct snd_motu *motu)
36 fw_csr_iterator_init(&it, motu->unit->directory); 36 fw_csr_iterator_init(&it, motu->unit->directory);
37 while (fw_csr_iterator_next(&it, &key, &val)) { 37 while (fw_csr_iterator_next(&it, &key, &val)) {
38 switch (key) { 38 switch (key) {
39 case CSR_VERSION: 39 case CSR_MODEL:
40 version = val; 40 version = val;
41 break; 41 break;
42 } 42 }
@@ -46,7 +46,7 @@ static void name_card(struct snd_motu *motu)
46 strcpy(motu->card->shortname, motu->spec->name); 46 strcpy(motu->card->shortname, motu->spec->name);
47 strcpy(motu->card->mixername, motu->spec->name); 47 strcpy(motu->card->mixername, motu->spec->name);
48 snprintf(motu->card->longname, sizeof(motu->card->longname), 48 snprintf(motu->card->longname, sizeof(motu->card->longname),
49 "MOTU %s (version:%d), GUID %08x%08x at %s, S%d", 49 "MOTU %s (version:%06x), GUID %08x%08x at %s, S%d",
50 motu->spec->name, version, 50 motu->spec->name, version,
51 fw_dev->config_rom[3], fw_dev->config_rom[4], 51 fw_dev->config_rom[3], fw_dev->config_rom[4],
52 dev_name(&motu->unit->device), 100 << fw_dev->max_speed); 52 dev_name(&motu->unit->device), 100 << fw_dev->max_speed);
@@ -237,20 +237,20 @@ static const struct snd_motu_spec motu_audio_express = {
237#define SND_MOTU_DEV_ENTRY(model, data) \ 237#define SND_MOTU_DEV_ENTRY(model, data) \
238{ \ 238{ \
239 .match_flags = IEEE1394_MATCH_VENDOR_ID | \ 239 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
240 IEEE1394_MATCH_MODEL_ID | \ 240 IEEE1394_MATCH_SPECIFIER_ID | \
241 IEEE1394_MATCH_SPECIFIER_ID, \ 241 IEEE1394_MATCH_VERSION, \
242 .vendor_id = OUI_MOTU, \ 242 .vendor_id = OUI_MOTU, \
243 .model_id = model, \
244 .specifier_id = OUI_MOTU, \ 243 .specifier_id = OUI_MOTU, \
244 .version = model, \
245 .driver_data = (kernel_ulong_t)data, \ 245 .driver_data = (kernel_ulong_t)data, \
246} 246}
247 247
248static const struct ieee1394_device_id motu_id_table[] = { 248static const struct ieee1394_device_id motu_id_table[] = {
249 SND_MOTU_DEV_ENTRY(0x101800, &motu_828mk2), 249 SND_MOTU_DEV_ENTRY(0x000003, &motu_828mk2),
250 SND_MOTU_DEV_ENTRY(0x107800, &snd_motu_spec_traveler), 250 SND_MOTU_DEV_ENTRY(0x000009, &snd_motu_spec_traveler),
251 SND_MOTU_DEV_ENTRY(0x106800, &motu_828mk3), /* FireWire only. */ 251 SND_MOTU_DEV_ENTRY(0x000015, &motu_828mk3), /* FireWire only. */
252 SND_MOTU_DEV_ENTRY(0x100800, &motu_828mk3), /* Hybrid. */ 252 SND_MOTU_DEV_ENTRY(0x000035, &motu_828mk3), /* Hybrid. */
253 SND_MOTU_DEV_ENTRY(0x104800, &motu_audio_express), 253 SND_MOTU_DEV_ENTRY(0x000033, &motu_audio_express),
254 { } 254 { }
255}; 255};
256MODULE_DEVICE_TABLE(ieee1394, motu_id_table); 256MODULE_DEVICE_TABLE(ieee1394, motu_id_table);
diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c
index aa2a83eb81a9..dc27a480c2d9 100644
--- a/sound/isa/sb/sb8.c
+++ b/sound/isa/sb/sb8.c
@@ -111,6 +111,10 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
111 111
112 /* block the 0x388 port to avoid PnP conflicts */ 112 /* block the 0x388 port to avoid PnP conflicts */
113 acard->fm_res = request_region(0x388, 4, "SoundBlaster FM"); 113 acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
114 if (!acard->fm_res) {
115 err = -EBUSY;
116 goto _err;
117 }
114 118
115 if (port[dev] != SNDRV_AUTO_PORT) { 119 if (port[dev] != SNDRV_AUTO_PORT) {
116 if ((err = snd_sbdsp_create(card, port[dev], irq[dev], 120 if ((err = snd_sbdsp_create(card, port[dev], irq[dev],
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index ea876b0b02b9..dc0084dc8550 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -1952,6 +1952,11 @@ static int snd_echo_create(struct snd_card *card,
1952 } 1952 }
1953 chip->dsp_registers = (volatile u32 __iomem *) 1953 chip->dsp_registers = (volatile u32 __iomem *)
1954 ioremap_nocache(chip->dsp_registers_phys, sz); 1954 ioremap_nocache(chip->dsp_registers_phys, sz);
1955 if (!chip->dsp_registers) {
1956 dev_err(chip->card->dev, "ioremap failed\n");
1957 snd_echo_free(chip);
1958 return -ENOMEM;
1959 }
1955 1960
1956 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, 1961 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
1957 KBUILD_MODNAME, chip)) { 1962 KBUILD_MODNAME, chip)) {
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 5f2005098a60..ec0b8595eb4d 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -2939,6 +2939,20 @@ static int hda_codec_runtime_resume(struct device *dev)
2939#endif /* CONFIG_PM */ 2939#endif /* CONFIG_PM */
2940 2940
2941#ifdef CONFIG_PM_SLEEP 2941#ifdef CONFIG_PM_SLEEP
2942static int hda_codec_force_resume(struct device *dev)
2943{
2944 int ret;
2945
2946 /* The get/put pair below enforces the runtime resume even if the
2947 * device hasn't been used at suspend time. This trick is needed to
2948 * update the jack state change during the sleep.
2949 */
2950 pm_runtime_get_noresume(dev);
2951 ret = pm_runtime_force_resume(dev);
2952 pm_runtime_put(dev);
2953 return ret;
2954}
2955
2942static int hda_codec_pm_suspend(struct device *dev) 2956static int hda_codec_pm_suspend(struct device *dev)
2943{ 2957{
2944 dev->power.power_state = PMSG_SUSPEND; 2958 dev->power.power_state = PMSG_SUSPEND;
@@ -2948,7 +2962,7 @@ static int hda_codec_pm_suspend(struct device *dev)
2948static int hda_codec_pm_resume(struct device *dev) 2962static int hda_codec_pm_resume(struct device *dev)
2949{ 2963{
2950 dev->power.power_state = PMSG_RESUME; 2964 dev->power.power_state = PMSG_RESUME;
2951 return pm_runtime_force_resume(dev); 2965 return hda_codec_force_resume(dev);
2952} 2966}
2953 2967
2954static int hda_codec_pm_freeze(struct device *dev) 2968static int hda_codec_pm_freeze(struct device *dev)
@@ -2960,13 +2974,13 @@ static int hda_codec_pm_freeze(struct device *dev)
2960static int hda_codec_pm_thaw(struct device *dev) 2974static int hda_codec_pm_thaw(struct device *dev)
2961{ 2975{
2962 dev->power.power_state = PMSG_THAW; 2976 dev->power.power_state = PMSG_THAW;
2963 return pm_runtime_force_resume(dev); 2977 return hda_codec_force_resume(dev);
2964} 2978}
2965 2979
2966static int hda_codec_pm_restore(struct device *dev) 2980static int hda_codec_pm_restore(struct device *dev)
2967{ 2981{
2968 dev->power.power_state = PMSG_RESTORE; 2982 dev->power.power_state = PMSG_RESTORE;
2969 return pm_runtime_force_resume(dev); 2983 return hda_codec_force_resume(dev);
2970} 2984}
2971#endif /* CONFIG_PM_SLEEP */ 2985#endif /* CONFIG_PM_SLEEP */
2972 2986
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index e5c49003e75f..ece256a3b48f 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -947,7 +947,7 @@ static void __azx_runtime_suspend(struct azx *chip)
947 display_power(chip, false); 947 display_power(chip, false);
948} 948}
949 949
950static void __azx_runtime_resume(struct azx *chip) 950static void __azx_runtime_resume(struct azx *chip, bool from_rt)
951{ 951{
952 struct hda_intel *hda = container_of(chip, struct hda_intel, chip); 952 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
953 struct hdac_bus *bus = azx_bus(chip); 953 struct hdac_bus *bus = azx_bus(chip);
@@ -964,7 +964,7 @@ static void __azx_runtime_resume(struct azx *chip)
964 azx_init_pci(chip); 964 azx_init_pci(chip);
965 hda_intel_init_chip(chip, true); 965 hda_intel_init_chip(chip, true);
966 966
967 if (status) { 967 if (status && from_rt) {
968 list_for_each_codec(codec, &chip->bus) 968 list_for_each_codec(codec, &chip->bus)
969 if (status & (1 << codec->addr)) 969 if (status & (1 << codec->addr))
970 schedule_delayed_work(&codec->jackpoll_work, 970 schedule_delayed_work(&codec->jackpoll_work,
@@ -1016,7 +1016,7 @@ static int azx_resume(struct device *dev)
1016 chip->msi = 0; 1016 chip->msi = 0;
1017 if (azx_acquire_irq(chip, 1) < 0) 1017 if (azx_acquire_irq(chip, 1) < 0)
1018 return -EIO; 1018 return -EIO;
1019 __azx_runtime_resume(chip); 1019 __azx_runtime_resume(chip, false);
1020 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 1020 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1021 1021
1022 trace_azx_resume(chip); 1022 trace_azx_resume(chip);
@@ -1081,7 +1081,7 @@ static int azx_runtime_resume(struct device *dev)
1081 chip = card->private_data; 1081 chip = card->private_data;
1082 if (!azx_has_pm_runtime(chip)) 1082 if (!azx_has_pm_runtime(chip))
1083 return 0; 1083 return 0;
1084 __azx_runtime_resume(chip); 1084 __azx_runtime_resume(chip, true);
1085 1085
1086 /* disable controller Wake Up event*/ 1086 /* disable controller Wake Up event*/
1087 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & 1087 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
@@ -2144,10 +2144,12 @@ static struct snd_pci_quirk power_save_blacklist[] = {
2144 SND_PCI_QUIRK(0x8086, 0x2057, "Intel NUC5i7RYB", 0), 2144 SND_PCI_QUIRK(0x8086, 0x2057, "Intel NUC5i7RYB", 0),
2145 /* https://bugzilla.redhat.com/show_bug.cgi?id=1520902 */ 2145 /* https://bugzilla.redhat.com/show_bug.cgi?id=1520902 */
2146 SND_PCI_QUIRK(0x8086, 0x2068, "Intel NUC7i3BNB", 0), 2146 SND_PCI_QUIRK(0x8086, 0x2068, "Intel NUC7i3BNB", 0),
2147 /* https://bugzilla.redhat.com/show_bug.cgi?id=1572975 */
2148 SND_PCI_QUIRK(0x17aa, 0x36a7, "Lenovo C50 All in one", 0),
2149 /* https://bugzilla.kernel.org/show_bug.cgi?id=198611 */ 2147 /* https://bugzilla.kernel.org/show_bug.cgi?id=198611 */
2150 SND_PCI_QUIRK(0x17aa, 0x2227, "Lenovo X1 Carbon 3rd Gen", 0), 2148 SND_PCI_QUIRK(0x17aa, 0x2227, "Lenovo X1 Carbon 3rd Gen", 0),
2149 /* https://bugzilla.redhat.com/show_bug.cgi?id=1689623 */
2150 SND_PCI_QUIRK(0x17aa, 0x367b, "Lenovo IdeaCentre B550", 0),
2151 /* https://bugzilla.redhat.com/show_bug.cgi?id=1572975 */
2152 SND_PCI_QUIRK(0x17aa, 0x36a7, "Lenovo C50 All in one", 0),
2151 {} 2153 {}
2152}; 2154};
2153#endif /* CONFIG_PM */ 2155#endif /* CONFIG_PM */
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 384719d5c44e..191830d4fa40 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -5687,6 +5687,7 @@ enum {
5687 ALC225_FIXUP_DELL_WYSE_AIO_MIC_NO_PRESENCE, 5687 ALC225_FIXUP_DELL_WYSE_AIO_MIC_NO_PRESENCE,
5688 ALC225_FIXUP_WYSE_AUTO_MUTE, 5688 ALC225_FIXUP_WYSE_AUTO_MUTE,
5689 ALC225_FIXUP_WYSE_DISABLE_MIC_VREF, 5689 ALC225_FIXUP_WYSE_DISABLE_MIC_VREF,
5690 ALC286_FIXUP_ACER_AIO_HEADSET_MIC,
5690}; 5691};
5691 5692
5692static const struct hda_fixup alc269_fixups[] = { 5693static const struct hda_fixup alc269_fixups[] = {
@@ -6685,6 +6686,16 @@ static const struct hda_fixup alc269_fixups[] = {
6685 .chained = true, 6686 .chained = true,
6686 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC 6687 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
6687 }, 6688 },
6689 [ALC286_FIXUP_ACER_AIO_HEADSET_MIC] = {
6690 .type = HDA_FIXUP_VERBS,
6691 .v.verbs = (const struct hda_verb[]) {
6692 { 0x20, AC_VERB_SET_COEF_INDEX, 0x4f },
6693 { 0x20, AC_VERB_SET_PROC_COEF, 0x5029 },
6694 { }
6695 },
6696 .chained = true,
6697 .chain_id = ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE
6698 },
6688}; 6699};
6689 6700
6690static const struct snd_pci_quirk alc269_fixup_tbl[] = { 6701static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -6701,9 +6712,9 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6701 SND_PCI_QUIRK(0x1025, 0x079b, "Acer Aspire V5-573G", ALC282_FIXUP_ASPIRE_V5_PINS), 6712 SND_PCI_QUIRK(0x1025, 0x079b, "Acer Aspire V5-573G", ALC282_FIXUP_ASPIRE_V5_PINS),
6702 SND_PCI_QUIRK(0x1025, 0x102b, "Acer Aspire C24-860", ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE), 6713 SND_PCI_QUIRK(0x1025, 0x102b, "Acer Aspire C24-860", ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE),
6703 SND_PCI_QUIRK(0x1025, 0x106d, "Acer Cloudbook 14", ALC283_FIXUP_CHROME_BOOK), 6714 SND_PCI_QUIRK(0x1025, 0x106d, "Acer Cloudbook 14", ALC283_FIXUP_CHROME_BOOK),
6704 SND_PCI_QUIRK(0x1025, 0x128f, "Acer Veriton Z6860G", ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE), 6715 SND_PCI_QUIRK(0x1025, 0x128f, "Acer Veriton Z6860G", ALC286_FIXUP_ACER_AIO_HEADSET_MIC),
6705 SND_PCI_QUIRK(0x1025, 0x1290, "Acer Veriton Z4860G", ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE), 6716 SND_PCI_QUIRK(0x1025, 0x1290, "Acer Veriton Z4860G", ALC286_FIXUP_ACER_AIO_HEADSET_MIC),
6706 SND_PCI_QUIRK(0x1025, 0x1291, "Acer Veriton Z4660G", ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE), 6717 SND_PCI_QUIRK(0x1025, 0x1291, "Acer Veriton Z4660G", ALC286_FIXUP_ACER_AIO_HEADSET_MIC),
6707 SND_PCI_QUIRK(0x1025, 0x1330, "Acer TravelMate X514-51T", ALC255_FIXUP_ACER_HEADSET_MIC), 6718 SND_PCI_QUIRK(0x1025, 0x1330, "Acer TravelMate X514-51T", ALC255_FIXUP_ACER_HEADSET_MIC),
6708 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), 6719 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6709 SND_PCI_QUIRK(0x1028, 0x054b, "Dell XPS one 2710", ALC275_FIXUP_DELL_XPS), 6720 SND_PCI_QUIRK(0x1028, 0x054b, "Dell XPS one 2710", ALC275_FIXUP_DELL_XPS),
diff --git a/tools/arch/arm64/include/uapi/asm/unistd.h b/tools/arch/arm64/include/uapi/asm/unistd.h
index dae1584cf017..4703d218663a 100644
--- a/tools/arch/arm64/include/uapi/asm/unistd.h
+++ b/tools/arch/arm64/include/uapi/asm/unistd.h
@@ -17,5 +17,7 @@
17 17
18#define __ARCH_WANT_RENAMEAT 18#define __ARCH_WANT_RENAMEAT
19#define __ARCH_WANT_NEW_STAT 19#define __ARCH_WANT_NEW_STAT
20#define __ARCH_WANT_SET_GET_RLIMIT
21#define __ARCH_WANT_TIME32_SYSCALLS
20 22
21#include <asm-generic/unistd.h> 23#include <asm-generic/unistd.h>
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 8ef80d65a474..d2be5a06c339 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -401,41 +401,31 @@ static int do_show(int argc, char **argv)
401 401
402static int do_dump(int argc, char **argv) 402static int do_dump(int argc, char **argv)
403{ 403{
404 unsigned int finfo_rec_size, linfo_rec_size, jited_linfo_rec_size; 404 struct bpf_prog_info_linear *info_linear;
405 void *func_info = NULL, *linfo = NULL, *jited_linfo = NULL;
406 unsigned int nr_finfo, nr_linfo = 0, nr_jited_linfo = 0;
407 struct bpf_prog_linfo *prog_linfo = NULL; 405 struct bpf_prog_linfo *prog_linfo = NULL;
408 unsigned long *func_ksyms = NULL; 406 enum {DUMP_JITED, DUMP_XLATED} mode;
409 struct bpf_prog_info info = {};
410 unsigned int *func_lens = NULL;
411 const char *disasm_opt = NULL; 407 const char *disasm_opt = NULL;
412 unsigned int nr_func_ksyms; 408 struct bpf_prog_info *info;
413 unsigned int nr_func_lens;
414 struct dump_data dd = {}; 409 struct dump_data dd = {};
415 __u32 len = sizeof(info); 410 void *func_info = NULL;
416 struct btf *btf = NULL; 411 struct btf *btf = NULL;
417 unsigned int buf_size;
418 char *filepath = NULL; 412 char *filepath = NULL;
419 bool opcodes = false; 413 bool opcodes = false;
420 bool visual = false; 414 bool visual = false;
421 char func_sig[1024]; 415 char func_sig[1024];
422 unsigned char *buf; 416 unsigned char *buf;
423 bool linum = false; 417 bool linum = false;
424 __u32 *member_len; 418 __u32 member_len;
425 __u64 *member_ptr; 419 __u64 arrays;
426 ssize_t n; 420 ssize_t n;
427 int err;
428 int fd; 421 int fd;
429 422
430 if (is_prefix(*argv, "jited")) { 423 if (is_prefix(*argv, "jited")) {
431 if (disasm_init()) 424 if (disasm_init())
432 return -1; 425 return -1;
433 426 mode = DUMP_JITED;
434 member_len = &info.jited_prog_len;
435 member_ptr = &info.jited_prog_insns;
436 } else if (is_prefix(*argv, "xlated")) { 427 } else if (is_prefix(*argv, "xlated")) {
437 member_len = &info.xlated_prog_len; 428 mode = DUMP_XLATED;
438 member_ptr = &info.xlated_prog_insns;
439 } else { 429 } else {
440 p_err("expected 'xlated' or 'jited', got: %s", *argv); 430 p_err("expected 'xlated' or 'jited', got: %s", *argv);
441 return -1; 431 return -1;
@@ -474,175 +464,50 @@ static int do_dump(int argc, char **argv)
474 return -1; 464 return -1;
475 } 465 }
476 466
477 err = bpf_obj_get_info_by_fd(fd, &info, &len); 467 if (mode == DUMP_JITED)
478 if (err) { 468 arrays = 1UL << BPF_PROG_INFO_JITED_INSNS;
479 p_err("can't get prog info: %s", strerror(errno)); 469 else
480 return -1; 470 arrays = 1UL << BPF_PROG_INFO_XLATED_INSNS;
481 }
482
483 if (!*member_len) {
484 p_info("no instructions returned");
485 close(fd);
486 return 0;
487 }
488 471
489 buf_size = *member_len; 472 arrays |= 1UL << BPF_PROG_INFO_JITED_KSYMS;
473 arrays |= 1UL << BPF_PROG_INFO_JITED_FUNC_LENS;
474 arrays |= 1UL << BPF_PROG_INFO_FUNC_INFO;
475 arrays |= 1UL << BPF_PROG_INFO_LINE_INFO;
476 arrays |= 1UL << BPF_PROG_INFO_JITED_LINE_INFO;
490 477
491 buf = malloc(buf_size); 478 info_linear = bpf_program__get_prog_info_linear(fd, arrays);
492 if (!buf) { 479 close(fd);
493 p_err("mem alloc failed"); 480 if (IS_ERR_OR_NULL(info_linear)) {
494 close(fd); 481 p_err("can't get prog info: %s", strerror(errno));
495 return -1; 482 return -1;
496 } 483 }
497 484
498 nr_func_ksyms = info.nr_jited_ksyms; 485 info = &info_linear->info;
499 if (nr_func_ksyms) { 486 if (mode == DUMP_JITED) {
500 func_ksyms = malloc(nr_func_ksyms * sizeof(__u64)); 487 if (info->jited_prog_len == 0) {
501 if (!func_ksyms) { 488 p_info("no instructions returned");
502 p_err("mem alloc failed");
503 close(fd);
504 goto err_free;
505 }
506 }
507
508 nr_func_lens = info.nr_jited_func_lens;
509 if (nr_func_lens) {
510 func_lens = malloc(nr_func_lens * sizeof(__u32));
511 if (!func_lens) {
512 p_err("mem alloc failed");
513 close(fd);
514 goto err_free; 489 goto err_free;
515 } 490 }
516 } 491 buf = (unsigned char *)(info->jited_prog_insns);
517 492 member_len = info->jited_prog_len;
518 nr_finfo = info.nr_func_info; 493 } else { /* DUMP_XLATED */
519 finfo_rec_size = info.func_info_rec_size; 494 if (info->xlated_prog_len == 0) {
520 if (nr_finfo && finfo_rec_size) { 495 p_err("error retrieving insn dump: kernel.kptr_restrict set?");
521 func_info = malloc(nr_finfo * finfo_rec_size);
522 if (!func_info) {
523 p_err("mem alloc failed");
524 close(fd);
525 goto err_free; 496 goto err_free;
526 } 497 }
498 buf = (unsigned char *)info->xlated_prog_insns;
499 member_len = info->xlated_prog_len;
527 } 500 }
528 501
529 linfo_rec_size = info.line_info_rec_size; 502 if (info->btf_id && btf__get_from_id(info->btf_id, &btf)) {
530 if (info.nr_line_info && linfo_rec_size && info.btf_id) {
531 nr_linfo = info.nr_line_info;
532 linfo = malloc(nr_linfo * linfo_rec_size);
533 if (!linfo) {
534 p_err("mem alloc failed");
535 close(fd);
536 goto err_free;
537 }
538 }
539
540 jited_linfo_rec_size = info.jited_line_info_rec_size;
541 if (info.nr_jited_line_info &&
542 jited_linfo_rec_size &&
543 info.nr_jited_ksyms &&
544 info.nr_jited_func_lens &&
545 info.btf_id) {
546 nr_jited_linfo = info.nr_jited_line_info;
547 jited_linfo = malloc(nr_jited_linfo * jited_linfo_rec_size);
548 if (!jited_linfo) {
549 p_err("mem alloc failed");
550 close(fd);
551 goto err_free;
552 }
553 }
554
555 memset(&info, 0, sizeof(info));
556
557 *member_ptr = ptr_to_u64(buf);
558 *member_len = buf_size;
559 info.jited_ksyms = ptr_to_u64(func_ksyms);
560 info.nr_jited_ksyms = nr_func_ksyms;
561 info.jited_func_lens = ptr_to_u64(func_lens);
562 info.nr_jited_func_lens = nr_func_lens;
563 info.nr_func_info = nr_finfo;
564 info.func_info_rec_size = finfo_rec_size;
565 info.func_info = ptr_to_u64(func_info);
566 info.nr_line_info = nr_linfo;
567 info.line_info_rec_size = linfo_rec_size;
568 info.line_info = ptr_to_u64(linfo);
569 info.nr_jited_line_info = nr_jited_linfo;
570 info.jited_line_info_rec_size = jited_linfo_rec_size;
571 info.jited_line_info = ptr_to_u64(jited_linfo);
572
573 err = bpf_obj_get_info_by_fd(fd, &info, &len);
574 close(fd);
575 if (err) {
576 p_err("can't get prog info: %s", strerror(errno));
577 goto err_free;
578 }
579
580 if (*member_len > buf_size) {
581 p_err("too many instructions returned");
582 goto err_free;
583 }
584
585 if (info.nr_jited_ksyms > nr_func_ksyms) {
586 p_err("too many addresses returned");
587 goto err_free;
588 }
589
590 if (info.nr_jited_func_lens > nr_func_lens) {
591 p_err("too many values returned");
592 goto err_free;
593 }
594
595 if (info.nr_func_info != nr_finfo) {
596 p_err("incorrect nr_func_info %d vs. expected %d",
597 info.nr_func_info, nr_finfo);
598 goto err_free;
599 }
600
601 if (info.func_info_rec_size != finfo_rec_size) {
602 p_err("incorrect func_info_rec_size %d vs. expected %d",
603 info.func_info_rec_size, finfo_rec_size);
604 goto err_free;
605 }
606
607 if (linfo && info.nr_line_info != nr_linfo) {
608 p_err("incorrect nr_line_info %u vs. expected %u",
609 info.nr_line_info, nr_linfo);
610 goto err_free;
611 }
612
613 if (info.line_info_rec_size != linfo_rec_size) {
614 p_err("incorrect line_info_rec_size %u vs. expected %u",
615 info.line_info_rec_size, linfo_rec_size);
616 goto err_free;
617 }
618
619 if (jited_linfo && info.nr_jited_line_info != nr_jited_linfo) {
620 p_err("incorrect nr_jited_line_info %u vs. expected %u",
621 info.nr_jited_line_info, nr_jited_linfo);
622 goto err_free;
623 }
624
625 if (info.jited_line_info_rec_size != jited_linfo_rec_size) {
626 p_err("incorrect jited_line_info_rec_size %u vs. expected %u",
627 info.jited_line_info_rec_size, jited_linfo_rec_size);
628 goto err_free;
629 }
630
631 if ((member_len == &info.jited_prog_len &&
632 info.jited_prog_insns == 0) ||
633 (member_len == &info.xlated_prog_len &&
634 info.xlated_prog_insns == 0)) {
635 p_err("error retrieving insn dump: kernel.kptr_restrict set?");
636 goto err_free;
637 }
638
639 if (info.btf_id && btf__get_from_id(info.btf_id, &btf)) {
640 p_err("failed to get btf"); 503 p_err("failed to get btf");
641 goto err_free; 504 goto err_free;
642 } 505 }
643 506
644 if (nr_linfo) { 507 func_info = (void *)info->func_info;
645 prog_linfo = bpf_prog_linfo__new(&info); 508
509 if (info->nr_line_info) {
510 prog_linfo = bpf_prog_linfo__new(info);
646 if (!prog_linfo) 511 if (!prog_linfo)
647 p_info("error in processing bpf_line_info. continue without it."); 512 p_info("error in processing bpf_line_info. continue without it.");
648 } 513 }
@@ -655,9 +520,9 @@ static int do_dump(int argc, char **argv)
655 goto err_free; 520 goto err_free;
656 } 521 }
657 522
658 n = write(fd, buf, *member_len); 523 n = write(fd, buf, member_len);
659 close(fd); 524 close(fd);
660 if (n != *member_len) { 525 if (n != member_len) {
661 p_err("error writing output file: %s", 526 p_err("error writing output file: %s",
662 n < 0 ? strerror(errno) : "short write"); 527 n < 0 ? strerror(errno) : "short write");
663 goto err_free; 528 goto err_free;
@@ -665,19 +530,19 @@ static int do_dump(int argc, char **argv)
665 530
666 if (json_output) 531 if (json_output)
667 jsonw_null(json_wtr); 532 jsonw_null(json_wtr);
668 } else if (member_len == &info.jited_prog_len) { 533 } else if (mode == DUMP_JITED) {
669 const char *name = NULL; 534 const char *name = NULL;
670 535
671 if (info.ifindex) { 536 if (info->ifindex) {
672 name = ifindex_to_bfd_params(info.ifindex, 537 name = ifindex_to_bfd_params(info->ifindex,
673 info.netns_dev, 538 info->netns_dev,
674 info.netns_ino, 539 info->netns_ino,
675 &disasm_opt); 540 &disasm_opt);
676 if (!name) 541 if (!name)
677 goto err_free; 542 goto err_free;
678 } 543 }
679 544
680 if (info.nr_jited_func_lens && info.jited_func_lens) { 545 if (info->nr_jited_func_lens && info->jited_func_lens) {
681 struct kernel_sym *sym = NULL; 546 struct kernel_sym *sym = NULL;
682 struct bpf_func_info *record; 547 struct bpf_func_info *record;
683 char sym_name[SYM_MAX_NAME]; 548 char sym_name[SYM_MAX_NAME];
@@ -685,17 +550,16 @@ static int do_dump(int argc, char **argv)
685 __u64 *ksyms = NULL; 550 __u64 *ksyms = NULL;
686 __u32 *lens; 551 __u32 *lens;
687 __u32 i; 552 __u32 i;
688 553 if (info->nr_jited_ksyms) {
689 if (info.nr_jited_ksyms) {
690 kernel_syms_load(&dd); 554 kernel_syms_load(&dd);
691 ksyms = (__u64 *) info.jited_ksyms; 555 ksyms = (__u64 *) info->jited_ksyms;
692 } 556 }
693 557
694 if (json_output) 558 if (json_output)
695 jsonw_start_array(json_wtr); 559 jsonw_start_array(json_wtr);
696 560
697 lens = (__u32 *) info.jited_func_lens; 561 lens = (__u32 *) info->jited_func_lens;
698 for (i = 0; i < info.nr_jited_func_lens; i++) { 562 for (i = 0; i < info->nr_jited_func_lens; i++) {
699 if (ksyms) { 563 if (ksyms) {
700 sym = kernel_syms_search(&dd, ksyms[i]); 564 sym = kernel_syms_search(&dd, ksyms[i]);
701 if (sym) 565 if (sym)
@@ -707,7 +571,7 @@ static int do_dump(int argc, char **argv)
707 } 571 }
708 572
709 if (func_info) { 573 if (func_info) {
710 record = func_info + i * finfo_rec_size; 574 record = func_info + i * info->func_info_rec_size;
711 btf_dumper_type_only(btf, record->type_id, 575 btf_dumper_type_only(btf, record->type_id,
712 func_sig, 576 func_sig,
713 sizeof(func_sig)); 577 sizeof(func_sig));
@@ -744,49 +608,37 @@ static int do_dump(int argc, char **argv)
744 if (json_output) 608 if (json_output)
745 jsonw_end_array(json_wtr); 609 jsonw_end_array(json_wtr);
746 } else { 610 } else {
747 disasm_print_insn(buf, *member_len, opcodes, name, 611 disasm_print_insn(buf, member_len, opcodes, name,
748 disasm_opt, btf, NULL, 0, 0, false); 612 disasm_opt, btf, NULL, 0, 0, false);
749 } 613 }
750 } else if (visual) { 614 } else if (visual) {
751 if (json_output) 615 if (json_output)
752 jsonw_null(json_wtr); 616 jsonw_null(json_wtr);
753 else 617 else
754 dump_xlated_cfg(buf, *member_len); 618 dump_xlated_cfg(buf, member_len);
755 } else { 619 } else {
756 kernel_syms_load(&dd); 620 kernel_syms_load(&dd);
757 dd.nr_jited_ksyms = info.nr_jited_ksyms; 621 dd.nr_jited_ksyms = info->nr_jited_ksyms;
758 dd.jited_ksyms = (__u64 *) info.jited_ksyms; 622 dd.jited_ksyms = (__u64 *) info->jited_ksyms;
759 dd.btf = btf; 623 dd.btf = btf;
760 dd.func_info = func_info; 624 dd.func_info = func_info;
761 dd.finfo_rec_size = finfo_rec_size; 625 dd.finfo_rec_size = info->func_info_rec_size;
762 dd.prog_linfo = prog_linfo; 626 dd.prog_linfo = prog_linfo;
763 627
764 if (json_output) 628 if (json_output)
765 dump_xlated_json(&dd, buf, *member_len, opcodes, 629 dump_xlated_json(&dd, buf, member_len, opcodes,
766 linum); 630 linum);
767 else 631 else
768 dump_xlated_plain(&dd, buf, *member_len, opcodes, 632 dump_xlated_plain(&dd, buf, member_len, opcodes,
769 linum); 633 linum);
770 kernel_syms_destroy(&dd); 634 kernel_syms_destroy(&dd);
771 } 635 }
772 636
773 free(buf); 637 free(info_linear);
774 free(func_ksyms);
775 free(func_lens);
776 free(func_info);
777 free(linfo);
778 free(jited_linfo);
779 bpf_prog_linfo__free(prog_linfo);
780 return 0; 638 return 0;
781 639
782err_free: 640err_free:
783 free(buf); 641 free(info_linear);
784 free(func_ksyms);
785 free(func_lens);
786 free(func_info);
787 free(linfo);
788 free(jited_linfo);
789 bpf_prog_linfo__free(prog_linfo);
790 return -1; 642 return -1;
791} 643}
792 644
diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 61e46d54a67c..8d3864b061f3 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -66,7 +66,8 @@ FEATURE_TESTS_BASIC := \
66 sched_getcpu \ 66 sched_getcpu \
67 sdt \ 67 sdt \
68 setns \ 68 setns \
69 libaio 69 libaio \
70 disassembler-four-args
70 71
71# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list 72# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
72# of all feature tests 73# of all feature tests
@@ -118,7 +119,8 @@ FEATURE_DISPLAY ?= \
118 lzma \ 119 lzma \
119 get_cpuid \ 120 get_cpuid \
120 bpf \ 121 bpf \
121 libaio 122 libaio \
123 disassembler-four-args
122 124
123# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. 125# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
124# If in the future we need per-feature checks/flags for features not 126# If in the future we need per-feature checks/flags for features not
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c
index e903b86b742f..7853e6d91090 100644
--- a/tools/build/feature/test-all.c
+++ b/tools/build/feature/test-all.c
@@ -178,6 +178,10 @@
178# include "test-reallocarray.c" 178# include "test-reallocarray.c"
179#undef main 179#undef main
180 180
181#define main main_test_disassembler_four_args
182# include "test-disassembler-four-args.c"
183#undef main
184
181int main(int argc, char *argv[]) 185int main(int argc, char *argv[])
182{ 186{
183 main_test_libpython(); 187 main_test_libpython();
@@ -219,6 +223,7 @@ int main(int argc, char *argv[])
219 main_test_setns(); 223 main_test_setns();
220 main_test_libaio(); 224 main_test_libaio();
221 main_test_reallocarray(); 225 main_test_reallocarray();
226 main_test_disassembler_four_args();
222 227
223 return 0; 228 return 0;
224} 229}
diff --git a/tools/include/uapi/asm-generic/unistd.h b/tools/include/uapi/asm-generic/unistd.h
index d90127298f12..12cdf611d217 100644
--- a/tools/include/uapi/asm-generic/unistd.h
+++ b/tools/include/uapi/asm-generic/unistd.h
@@ -38,8 +38,10 @@ __SYSCALL(__NR_io_destroy, sys_io_destroy)
38__SC_COMP(__NR_io_submit, sys_io_submit, compat_sys_io_submit) 38__SC_COMP(__NR_io_submit, sys_io_submit, compat_sys_io_submit)
39#define __NR_io_cancel 3 39#define __NR_io_cancel 3
40__SYSCALL(__NR_io_cancel, sys_io_cancel) 40__SYSCALL(__NR_io_cancel, sys_io_cancel)
41#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
41#define __NR_io_getevents 4 42#define __NR_io_getevents 4
42__SC_COMP(__NR_io_getevents, sys_io_getevents, compat_sys_io_getevents) 43__SC_3264(__NR_io_getevents, sys_io_getevents_time32, sys_io_getevents)
44#endif
43 45
44/* fs/xattr.c */ 46/* fs/xattr.c */
45#define __NR_setxattr 5 47#define __NR_setxattr 5
@@ -179,7 +181,7 @@ __SYSCALL(__NR_fchownat, sys_fchownat)
179#define __NR_fchown 55 181#define __NR_fchown 55
180__SYSCALL(__NR_fchown, sys_fchown) 182__SYSCALL(__NR_fchown, sys_fchown)
181#define __NR_openat 56 183#define __NR_openat 56
182__SC_COMP(__NR_openat, sys_openat, compat_sys_openat) 184__SYSCALL(__NR_openat, sys_openat)
183#define __NR_close 57 185#define __NR_close 57
184__SYSCALL(__NR_close, sys_close) 186__SYSCALL(__NR_close, sys_close)
185#define __NR_vhangup 58 187#define __NR_vhangup 58
@@ -222,10 +224,12 @@ __SC_COMP(__NR_pwritev, sys_pwritev, compat_sys_pwritev)
222__SYSCALL(__NR3264_sendfile, sys_sendfile64) 224__SYSCALL(__NR3264_sendfile, sys_sendfile64)
223 225
224/* fs/select.c */ 226/* fs/select.c */
227#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
225#define __NR_pselect6 72 228#define __NR_pselect6 72
226__SC_COMP(__NR_pselect6, sys_pselect6, compat_sys_pselect6) 229__SC_COMP_3264(__NR_pselect6, sys_pselect6_time32, sys_pselect6, compat_sys_pselect6_time32)
227#define __NR_ppoll 73 230#define __NR_ppoll 73
228__SC_COMP(__NR_ppoll, sys_ppoll, compat_sys_ppoll) 231__SC_COMP_3264(__NR_ppoll, sys_ppoll_time32, sys_ppoll, compat_sys_ppoll_time32)
232#endif
229 233
230/* fs/signalfd.c */ 234/* fs/signalfd.c */
231#define __NR_signalfd4 74 235#define __NR_signalfd4 74
@@ -269,16 +273,20 @@ __SC_COMP(__NR_sync_file_range, sys_sync_file_range, \
269/* fs/timerfd.c */ 273/* fs/timerfd.c */
270#define __NR_timerfd_create 85 274#define __NR_timerfd_create 85
271__SYSCALL(__NR_timerfd_create, sys_timerfd_create) 275__SYSCALL(__NR_timerfd_create, sys_timerfd_create)
276#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
272#define __NR_timerfd_settime 86 277#define __NR_timerfd_settime 86
273__SC_COMP(__NR_timerfd_settime, sys_timerfd_settime, \ 278__SC_3264(__NR_timerfd_settime, sys_timerfd_settime32, \
274 compat_sys_timerfd_settime) 279 sys_timerfd_settime)
275#define __NR_timerfd_gettime 87 280#define __NR_timerfd_gettime 87
276__SC_COMP(__NR_timerfd_gettime, sys_timerfd_gettime, \ 281__SC_3264(__NR_timerfd_gettime, sys_timerfd_gettime32, \
277 compat_sys_timerfd_gettime) 282 sys_timerfd_gettime)
283#endif
278 284
279/* fs/utimes.c */ 285/* fs/utimes.c */
286#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
280#define __NR_utimensat 88 287#define __NR_utimensat 88
281__SC_COMP(__NR_utimensat, sys_utimensat, compat_sys_utimensat) 288__SC_3264(__NR_utimensat, sys_utimensat_time32, sys_utimensat)
289#endif
282 290
283/* kernel/acct.c */ 291/* kernel/acct.c */
284#define __NR_acct 89 292#define __NR_acct 89
@@ -309,8 +317,10 @@ __SYSCALL(__NR_set_tid_address, sys_set_tid_address)
309__SYSCALL(__NR_unshare, sys_unshare) 317__SYSCALL(__NR_unshare, sys_unshare)
310 318
311/* kernel/futex.c */ 319/* kernel/futex.c */
320#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
312#define __NR_futex 98 321#define __NR_futex 98
313__SC_COMP(__NR_futex, sys_futex, compat_sys_futex) 322__SC_3264(__NR_futex, sys_futex_time32, sys_futex)
323#endif
314#define __NR_set_robust_list 99 324#define __NR_set_robust_list 99
315__SC_COMP(__NR_set_robust_list, sys_set_robust_list, \ 325__SC_COMP(__NR_set_robust_list, sys_set_robust_list, \
316 compat_sys_set_robust_list) 326 compat_sys_set_robust_list)
@@ -319,8 +329,10 @@ __SC_COMP(__NR_get_robust_list, sys_get_robust_list, \
319 compat_sys_get_robust_list) 329 compat_sys_get_robust_list)
320 330
321/* kernel/hrtimer.c */ 331/* kernel/hrtimer.c */
332#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
322#define __NR_nanosleep 101 333#define __NR_nanosleep 101
323__SC_COMP(__NR_nanosleep, sys_nanosleep, compat_sys_nanosleep) 334__SC_3264(__NR_nanosleep, sys_nanosleep_time32, sys_nanosleep)
335#endif
324 336
325/* kernel/itimer.c */ 337/* kernel/itimer.c */
326#define __NR_getitimer 102 338#define __NR_getitimer 102
@@ -341,23 +353,29 @@ __SYSCALL(__NR_delete_module, sys_delete_module)
341/* kernel/posix-timers.c */ 353/* kernel/posix-timers.c */
342#define __NR_timer_create 107 354#define __NR_timer_create 107
343__SC_COMP(__NR_timer_create, sys_timer_create, compat_sys_timer_create) 355__SC_COMP(__NR_timer_create, sys_timer_create, compat_sys_timer_create)
356#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
344#define __NR_timer_gettime 108 357#define __NR_timer_gettime 108
345__SC_COMP(__NR_timer_gettime, sys_timer_gettime, compat_sys_timer_gettime) 358__SC_3264(__NR_timer_gettime, sys_timer_gettime32, sys_timer_gettime)
359#endif
346#define __NR_timer_getoverrun 109 360#define __NR_timer_getoverrun 109
347__SYSCALL(__NR_timer_getoverrun, sys_timer_getoverrun) 361__SYSCALL(__NR_timer_getoverrun, sys_timer_getoverrun)
362#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
348#define __NR_timer_settime 110 363#define __NR_timer_settime 110
349__SC_COMP(__NR_timer_settime, sys_timer_settime, compat_sys_timer_settime) 364__SC_3264(__NR_timer_settime, sys_timer_settime32, sys_timer_settime)
365#endif
350#define __NR_timer_delete 111 366#define __NR_timer_delete 111
351__SYSCALL(__NR_timer_delete, sys_timer_delete) 367__SYSCALL(__NR_timer_delete, sys_timer_delete)
368#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
352#define __NR_clock_settime 112 369#define __NR_clock_settime 112
353__SC_COMP(__NR_clock_settime, sys_clock_settime, compat_sys_clock_settime) 370__SC_3264(__NR_clock_settime, sys_clock_settime32, sys_clock_settime)
354#define __NR_clock_gettime 113 371#define __NR_clock_gettime 113
355__SC_COMP(__NR_clock_gettime, sys_clock_gettime, compat_sys_clock_gettime) 372__SC_3264(__NR_clock_gettime, sys_clock_gettime32, sys_clock_gettime)
356#define __NR_clock_getres 114 373#define __NR_clock_getres 114
357__SC_COMP(__NR_clock_getres, sys_clock_getres, compat_sys_clock_getres) 374__SC_3264(__NR_clock_getres, sys_clock_getres_time32, sys_clock_getres)
358#define __NR_clock_nanosleep 115 375#define __NR_clock_nanosleep 115
359__SC_COMP(__NR_clock_nanosleep, sys_clock_nanosleep, \ 376__SC_3264(__NR_clock_nanosleep, sys_clock_nanosleep_time32, \
360 compat_sys_clock_nanosleep) 377 sys_clock_nanosleep)
378#endif
361 379
362/* kernel/printk.c */ 380/* kernel/printk.c */
363#define __NR_syslog 116 381#define __NR_syslog 116
@@ -388,9 +406,11 @@ __SYSCALL(__NR_sched_yield, sys_sched_yield)
388__SYSCALL(__NR_sched_get_priority_max, sys_sched_get_priority_max) 406__SYSCALL(__NR_sched_get_priority_max, sys_sched_get_priority_max)
389#define __NR_sched_get_priority_min 126 407#define __NR_sched_get_priority_min 126
390__SYSCALL(__NR_sched_get_priority_min, sys_sched_get_priority_min) 408__SYSCALL(__NR_sched_get_priority_min, sys_sched_get_priority_min)
409#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
391#define __NR_sched_rr_get_interval 127 410#define __NR_sched_rr_get_interval 127
392__SC_COMP(__NR_sched_rr_get_interval, sys_sched_rr_get_interval, \ 411__SC_3264(__NR_sched_rr_get_interval, sys_sched_rr_get_interval_time32, \
393 compat_sys_sched_rr_get_interval) 412 sys_sched_rr_get_interval)
413#endif
394 414
395/* kernel/signal.c */ 415/* kernel/signal.c */
396#define __NR_restart_syscall 128 416#define __NR_restart_syscall 128
@@ -411,9 +431,11 @@ __SC_COMP(__NR_rt_sigaction, sys_rt_sigaction, compat_sys_rt_sigaction)
411__SC_COMP(__NR_rt_sigprocmask, sys_rt_sigprocmask, compat_sys_rt_sigprocmask) 431__SC_COMP(__NR_rt_sigprocmask, sys_rt_sigprocmask, compat_sys_rt_sigprocmask)
412#define __NR_rt_sigpending 136 432#define __NR_rt_sigpending 136
413__SC_COMP(__NR_rt_sigpending, sys_rt_sigpending, compat_sys_rt_sigpending) 433__SC_COMP(__NR_rt_sigpending, sys_rt_sigpending, compat_sys_rt_sigpending)
434#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
414#define __NR_rt_sigtimedwait 137 435#define __NR_rt_sigtimedwait 137
415__SC_COMP(__NR_rt_sigtimedwait, sys_rt_sigtimedwait, \ 436__SC_COMP_3264(__NR_rt_sigtimedwait, sys_rt_sigtimedwait_time32, \
416 compat_sys_rt_sigtimedwait) 437 sys_rt_sigtimedwait, compat_sys_rt_sigtimedwait_time32)
438#endif
417#define __NR_rt_sigqueueinfo 138 439#define __NR_rt_sigqueueinfo 138
418__SC_COMP(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo, \ 440__SC_COMP(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo, \
419 compat_sys_rt_sigqueueinfo) 441 compat_sys_rt_sigqueueinfo)
@@ -467,10 +489,15 @@ __SYSCALL(__NR_uname, sys_newuname)
467__SYSCALL(__NR_sethostname, sys_sethostname) 489__SYSCALL(__NR_sethostname, sys_sethostname)
468#define __NR_setdomainname 162 490#define __NR_setdomainname 162
469__SYSCALL(__NR_setdomainname, sys_setdomainname) 491__SYSCALL(__NR_setdomainname, sys_setdomainname)
492
493#ifdef __ARCH_WANT_SET_GET_RLIMIT
494/* getrlimit and setrlimit are superseded with prlimit64 */
470#define __NR_getrlimit 163 495#define __NR_getrlimit 163
471__SC_COMP(__NR_getrlimit, sys_getrlimit, compat_sys_getrlimit) 496__SC_COMP(__NR_getrlimit, sys_getrlimit, compat_sys_getrlimit)
472#define __NR_setrlimit 164 497#define __NR_setrlimit 164
473__SC_COMP(__NR_setrlimit, sys_setrlimit, compat_sys_setrlimit) 498__SC_COMP(__NR_setrlimit, sys_setrlimit, compat_sys_setrlimit)
499#endif
500
474#define __NR_getrusage 165 501#define __NR_getrusage 165
475__SC_COMP(__NR_getrusage, sys_getrusage, compat_sys_getrusage) 502__SC_COMP(__NR_getrusage, sys_getrusage, compat_sys_getrusage)
476#define __NR_umask 166 503#define __NR_umask 166
@@ -481,12 +508,14 @@ __SYSCALL(__NR_prctl, sys_prctl)
481__SYSCALL(__NR_getcpu, sys_getcpu) 508__SYSCALL(__NR_getcpu, sys_getcpu)
482 509
483/* kernel/time.c */ 510/* kernel/time.c */
511#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
484#define __NR_gettimeofday 169 512#define __NR_gettimeofday 169
485__SC_COMP(__NR_gettimeofday, sys_gettimeofday, compat_sys_gettimeofday) 513__SC_COMP(__NR_gettimeofday, sys_gettimeofday, compat_sys_gettimeofday)
486#define __NR_settimeofday 170 514#define __NR_settimeofday 170
487__SC_COMP(__NR_settimeofday, sys_settimeofday, compat_sys_settimeofday) 515__SC_COMP(__NR_settimeofday, sys_settimeofday, compat_sys_settimeofday)
488#define __NR_adjtimex 171 516#define __NR_adjtimex 171
489__SC_COMP(__NR_adjtimex, sys_adjtimex, compat_sys_adjtimex) 517__SC_3264(__NR_adjtimex, sys_adjtimex_time32, sys_adjtimex)
518#endif
490 519
491/* kernel/timer.c */ 520/* kernel/timer.c */
492#define __NR_getpid 172 521#define __NR_getpid 172
@@ -511,11 +540,13 @@ __SC_COMP(__NR_sysinfo, sys_sysinfo, compat_sys_sysinfo)
511__SC_COMP(__NR_mq_open, sys_mq_open, compat_sys_mq_open) 540__SC_COMP(__NR_mq_open, sys_mq_open, compat_sys_mq_open)
512#define __NR_mq_unlink 181 541#define __NR_mq_unlink 181
513__SYSCALL(__NR_mq_unlink, sys_mq_unlink) 542__SYSCALL(__NR_mq_unlink, sys_mq_unlink)
543#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
514#define __NR_mq_timedsend 182 544#define __NR_mq_timedsend 182
515__SC_COMP(__NR_mq_timedsend, sys_mq_timedsend, compat_sys_mq_timedsend) 545__SC_3264(__NR_mq_timedsend, sys_mq_timedsend_time32, sys_mq_timedsend)
516#define __NR_mq_timedreceive 183 546#define __NR_mq_timedreceive 183
517__SC_COMP(__NR_mq_timedreceive, sys_mq_timedreceive, \ 547__SC_3264(__NR_mq_timedreceive, sys_mq_timedreceive_time32, \
518 compat_sys_mq_timedreceive) 548 sys_mq_timedreceive)
549#endif
519#define __NR_mq_notify 184 550#define __NR_mq_notify 184
520__SC_COMP(__NR_mq_notify, sys_mq_notify, compat_sys_mq_notify) 551__SC_COMP(__NR_mq_notify, sys_mq_notify, compat_sys_mq_notify)
521#define __NR_mq_getsetattr 185 552#define __NR_mq_getsetattr 185
@@ -536,8 +567,10 @@ __SC_COMP(__NR_msgsnd, sys_msgsnd, compat_sys_msgsnd)
536__SYSCALL(__NR_semget, sys_semget) 567__SYSCALL(__NR_semget, sys_semget)
537#define __NR_semctl 191 568#define __NR_semctl 191
538__SC_COMP(__NR_semctl, sys_semctl, compat_sys_semctl) 569__SC_COMP(__NR_semctl, sys_semctl, compat_sys_semctl)
570#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
539#define __NR_semtimedop 192 571#define __NR_semtimedop 192
540__SC_COMP(__NR_semtimedop, sys_semtimedop, compat_sys_semtimedop) 572__SC_COMP(__NR_semtimedop, sys_semtimedop, sys_semtimedop_time32)
573#endif
541#define __NR_semop 193 574#define __NR_semop 193
542__SYSCALL(__NR_semop, sys_semop) 575__SYSCALL(__NR_semop, sys_semop)
543 576
@@ -658,8 +691,10 @@ __SC_COMP(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo, \
658__SYSCALL(__NR_perf_event_open, sys_perf_event_open) 691__SYSCALL(__NR_perf_event_open, sys_perf_event_open)
659#define __NR_accept4 242 692#define __NR_accept4 242
660__SYSCALL(__NR_accept4, sys_accept4) 693__SYSCALL(__NR_accept4, sys_accept4)
694#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
661#define __NR_recvmmsg 243 695#define __NR_recvmmsg 243
662__SC_COMP(__NR_recvmmsg, sys_recvmmsg, compat_sys_recvmmsg) 696__SC_COMP_3264(__NR_recvmmsg, sys_recvmmsg_time32, sys_recvmmsg, compat_sys_recvmmsg_time32)
697#endif
663 698
664/* 699/*
665 * Architectures may provide up to 16 syscalls of their own 700 * Architectures may provide up to 16 syscalls of their own
@@ -667,8 +702,10 @@ __SC_COMP(__NR_recvmmsg, sys_recvmmsg, compat_sys_recvmmsg)
667 */ 702 */
668#define __NR_arch_specific_syscall 244 703#define __NR_arch_specific_syscall 244
669 704
705#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
670#define __NR_wait4 260 706#define __NR_wait4 260
671__SC_COMP(__NR_wait4, sys_wait4, compat_sys_wait4) 707__SC_COMP(__NR_wait4, sys_wait4, compat_sys_wait4)
708#endif
672#define __NR_prlimit64 261 709#define __NR_prlimit64 261
673__SYSCALL(__NR_prlimit64, sys_prlimit64) 710__SYSCALL(__NR_prlimit64, sys_prlimit64)
674#define __NR_fanotify_init 262 711#define __NR_fanotify_init 262
@@ -678,10 +715,11 @@ __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
678#define __NR_name_to_handle_at 264 715#define __NR_name_to_handle_at 264
679__SYSCALL(__NR_name_to_handle_at, sys_name_to_handle_at) 716__SYSCALL(__NR_name_to_handle_at, sys_name_to_handle_at)
680#define __NR_open_by_handle_at 265 717#define __NR_open_by_handle_at 265
681__SC_COMP(__NR_open_by_handle_at, sys_open_by_handle_at, \ 718__SYSCALL(__NR_open_by_handle_at, sys_open_by_handle_at)
682 compat_sys_open_by_handle_at) 719#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
683#define __NR_clock_adjtime 266 720#define __NR_clock_adjtime 266
684__SC_COMP(__NR_clock_adjtime, sys_clock_adjtime, compat_sys_clock_adjtime) 721__SC_3264(__NR_clock_adjtime, sys_clock_adjtime32, sys_clock_adjtime)
722#endif
685#define __NR_syncfs 267 723#define __NR_syncfs 267
686__SYSCALL(__NR_syncfs, sys_syncfs) 724__SYSCALL(__NR_syncfs, sys_syncfs)
687#define __NR_setns 268 725#define __NR_setns 268
@@ -734,15 +772,60 @@ __SYSCALL(__NR_pkey_alloc, sys_pkey_alloc)
734__SYSCALL(__NR_pkey_free, sys_pkey_free) 772__SYSCALL(__NR_pkey_free, sys_pkey_free)
735#define __NR_statx 291 773#define __NR_statx 291
736__SYSCALL(__NR_statx, sys_statx) 774__SYSCALL(__NR_statx, sys_statx)
775#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
737#define __NR_io_pgetevents 292 776#define __NR_io_pgetevents 292
738__SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) 777__SC_COMP_3264(__NR_io_pgetevents, sys_io_pgetevents_time32, sys_io_pgetevents, compat_sys_io_pgetevents)
778#endif
739#define __NR_rseq 293 779#define __NR_rseq 293
740__SYSCALL(__NR_rseq, sys_rseq) 780__SYSCALL(__NR_rseq, sys_rseq)
741#define __NR_kexec_file_load 294 781#define __NR_kexec_file_load 294
742__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) 782__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load)
783/* 295 through 402 are unassigned to sync up with generic numbers, don't use */
784#if __BITS_PER_LONG == 32
785#define __NR_clock_gettime64 403
786__SYSCALL(__NR_clock_gettime64, sys_clock_gettime)
787#define __NR_clock_settime64 404
788__SYSCALL(__NR_clock_settime64, sys_clock_settime)
789#define __NR_clock_adjtime64 405
790__SYSCALL(__NR_clock_adjtime64, sys_clock_adjtime)
791#define __NR_clock_getres_time64 406
792__SYSCALL(__NR_clock_getres_time64, sys_clock_getres)
793#define __NR_clock_nanosleep_time64 407
794__SYSCALL(__NR_clock_nanosleep_time64, sys_clock_nanosleep)
795#define __NR_timer_gettime64 408
796__SYSCALL(__NR_timer_gettime64, sys_timer_gettime)
797#define __NR_timer_settime64 409
798__SYSCALL(__NR_timer_settime64, sys_timer_settime)
799#define __NR_timerfd_gettime64 410
800__SYSCALL(__NR_timerfd_gettime64, sys_timerfd_gettime)
801#define __NR_timerfd_settime64 411
802__SYSCALL(__NR_timerfd_settime64, sys_timerfd_settime)
803#define __NR_utimensat_time64 412
804__SYSCALL(__NR_utimensat_time64, sys_utimensat)
805#define __NR_pselect6_time64 413
806__SC_COMP(__NR_pselect6_time64, sys_pselect6, compat_sys_pselect6_time64)
807#define __NR_ppoll_time64 414
808__SC_COMP(__NR_ppoll_time64, sys_ppoll, compat_sys_ppoll_time64)
809#define __NR_io_pgetevents_time64 416
810__SYSCALL(__NR_io_pgetevents_time64, sys_io_pgetevents)
811#define __NR_recvmmsg_time64 417
812__SC_COMP(__NR_recvmmsg_time64, sys_recvmmsg, compat_sys_recvmmsg_time64)
813#define __NR_mq_timedsend_time64 418
814__SYSCALL(__NR_mq_timedsend_time64, sys_mq_timedsend)
815#define __NR_mq_timedreceive_time64 419
816__SYSCALL(__NR_mq_timedreceive_time64, sys_mq_timedreceive)
817#define __NR_semtimedop_time64 420
818__SYSCALL(__NR_semtimedop_time64, sys_semtimedop)
819#define __NR_rt_sigtimedwait_time64 421
820__SC_COMP(__NR_rt_sigtimedwait_time64, sys_rt_sigtimedwait, compat_sys_rt_sigtimedwait_time64)
821#define __NR_futex_time64 422
822__SYSCALL(__NR_futex_time64, sys_futex)
823#define __NR_sched_rr_get_interval_time64 423
824__SYSCALL(__NR_sched_rr_get_interval_time64, sys_sched_rr_get_interval)
825#endif
743 826
744#undef __NR_syscalls 827#undef __NR_syscalls
745#define __NR_syscalls 295 828#define __NR_syscalls 424
746 829
747/* 830/*
748 * 32 bit systems traditionally used different 831 * 32 bit systems traditionally used different
diff --git a/tools/include/uapi/linux/in.h b/tools/include/uapi/linux/in.h
index a55cb8b10165..e7ad9d350a28 100644
--- a/tools/include/uapi/linux/in.h
+++ b/tools/include/uapi/linux/in.h
@@ -292,10 +292,11 @@ struct sockaddr_in {
292#define IN_LOOPBACK(a) ((((long int) (a)) & 0xff000000) == 0x7f000000) 292#define IN_LOOPBACK(a) ((((long int) (a)) & 0xff000000) == 0x7f000000)
293 293
294/* Defines for Multicast INADDR */ 294/* Defines for Multicast INADDR */
295#define INADDR_UNSPEC_GROUP 0xe0000000U /* 224.0.0.0 */ 295#define INADDR_UNSPEC_GROUP 0xe0000000U /* 224.0.0.0 */
296#define INADDR_ALLHOSTS_GROUP 0xe0000001U /* 224.0.0.1 */ 296#define INADDR_ALLHOSTS_GROUP 0xe0000001U /* 224.0.0.1 */
297#define INADDR_ALLRTRS_GROUP 0xe0000002U /* 224.0.0.2 */ 297#define INADDR_ALLRTRS_GROUP 0xe0000002U /* 224.0.0.2 */
298#define INADDR_MAX_LOCAL_GROUP 0xe00000ffU /* 224.0.0.255 */ 298#define INADDR_ALLSNOOPERS_GROUP 0xe000006aU /* 224.0.0.106 */
299#define INADDR_MAX_LOCAL_GROUP 0xe00000ffU /* 224.0.0.255 */
299#endif 300#endif
300 301
301/* <asm/byteorder.h> contains the htonl type stuff.. */ 302/* <asm/byteorder.h> contains the htonl type stuff.. */
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index d5b830d60601..e6ad87512519 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -112,6 +112,11 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
112# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ 112# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
113#endif 113#endif
114 114
115static inline __u64 ptr_to_u64(const void *ptr)
116{
117 return (__u64) (unsigned long) ptr;
118}
119
115struct bpf_capabilities { 120struct bpf_capabilities {
116 /* v4.14: kernel support for program & map names. */ 121 /* v4.14: kernel support for program & map names. */
117 __u32 name:1; 122 __u32 name:1;
@@ -622,7 +627,7 @@ bpf_object__init_maps(struct bpf_object *obj, int flags)
622 bool strict = !(flags & MAPS_RELAX_COMPAT); 627 bool strict = !(flags & MAPS_RELAX_COMPAT);
623 int i, map_idx, map_def_sz, nr_maps = 0; 628 int i, map_idx, map_def_sz, nr_maps = 0;
624 Elf_Scn *scn; 629 Elf_Scn *scn;
625 Elf_Data *data; 630 Elf_Data *data = NULL;
626 Elf_Data *symbols = obj->efile.symbols; 631 Elf_Data *symbols = obj->efile.symbols;
627 632
628 if (obj->efile.maps_shndx < 0) 633 if (obj->efile.maps_shndx < 0)
@@ -2999,3 +3004,249 @@ bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
2999 ring_buffer_write_tail(header, data_tail); 3004 ring_buffer_write_tail(header, data_tail);
3000 return ret; 3005 return ret;
3001} 3006}
3007
3008struct bpf_prog_info_array_desc {
3009 int array_offset; /* e.g. offset of jited_prog_insns */
3010 int count_offset; /* e.g. offset of jited_prog_len */
3011 int size_offset; /* > 0: offset of rec size,
3012 * < 0: fix size of -size_offset
3013 */
3014};
3015
3016static struct bpf_prog_info_array_desc bpf_prog_info_array_desc[] = {
3017 [BPF_PROG_INFO_JITED_INSNS] = {
3018 offsetof(struct bpf_prog_info, jited_prog_insns),
3019 offsetof(struct bpf_prog_info, jited_prog_len),
3020 -1,
3021 },
3022 [BPF_PROG_INFO_XLATED_INSNS] = {
3023 offsetof(struct bpf_prog_info, xlated_prog_insns),
3024 offsetof(struct bpf_prog_info, xlated_prog_len),
3025 -1,
3026 },
3027 [BPF_PROG_INFO_MAP_IDS] = {
3028 offsetof(struct bpf_prog_info, map_ids),
3029 offsetof(struct bpf_prog_info, nr_map_ids),
3030 -(int)sizeof(__u32),
3031 },
3032 [BPF_PROG_INFO_JITED_KSYMS] = {
3033 offsetof(struct bpf_prog_info, jited_ksyms),
3034 offsetof(struct bpf_prog_info, nr_jited_ksyms),
3035 -(int)sizeof(__u64),
3036 },
3037 [BPF_PROG_INFO_JITED_FUNC_LENS] = {
3038 offsetof(struct bpf_prog_info, jited_func_lens),
3039 offsetof(struct bpf_prog_info, nr_jited_func_lens),
3040 -(int)sizeof(__u32),
3041 },
3042 [BPF_PROG_INFO_FUNC_INFO] = {
3043 offsetof(struct bpf_prog_info, func_info),
3044 offsetof(struct bpf_prog_info, nr_func_info),
3045 offsetof(struct bpf_prog_info, func_info_rec_size),
3046 },
3047 [BPF_PROG_INFO_LINE_INFO] = {
3048 offsetof(struct bpf_prog_info, line_info),
3049 offsetof(struct bpf_prog_info, nr_line_info),
3050 offsetof(struct bpf_prog_info, line_info_rec_size),
3051 },
3052 [BPF_PROG_INFO_JITED_LINE_INFO] = {
3053 offsetof(struct bpf_prog_info, jited_line_info),
3054 offsetof(struct bpf_prog_info, nr_jited_line_info),
3055 offsetof(struct bpf_prog_info, jited_line_info_rec_size),
3056 },
3057 [BPF_PROG_INFO_PROG_TAGS] = {
3058 offsetof(struct bpf_prog_info, prog_tags),
3059 offsetof(struct bpf_prog_info, nr_prog_tags),
3060 -(int)sizeof(__u8) * BPF_TAG_SIZE,
3061 },
3062
3063};
3064
3065static __u32 bpf_prog_info_read_offset_u32(struct bpf_prog_info *info, int offset)
3066{
3067 __u32 *array = (__u32 *)info;
3068
3069 if (offset >= 0)
3070 return array[offset / sizeof(__u32)];
3071 return -(int)offset;
3072}
3073
3074static __u64 bpf_prog_info_read_offset_u64(struct bpf_prog_info *info, int offset)
3075{
3076 __u64 *array = (__u64 *)info;
3077
3078 if (offset >= 0)
3079 return array[offset / sizeof(__u64)];
3080 return -(int)offset;
3081}
3082
3083static void bpf_prog_info_set_offset_u32(struct bpf_prog_info *info, int offset,
3084 __u32 val)
3085{
3086 __u32 *array = (__u32 *)info;
3087
3088 if (offset >= 0)
3089 array[offset / sizeof(__u32)] = val;
3090}
3091
3092static void bpf_prog_info_set_offset_u64(struct bpf_prog_info *info, int offset,
3093 __u64 val)
3094{
3095 __u64 *array = (__u64 *)info;
3096
3097 if (offset >= 0)
3098 array[offset / sizeof(__u64)] = val;
3099}
3100
3101struct bpf_prog_info_linear *
3102bpf_program__get_prog_info_linear(int fd, __u64 arrays)
3103{
3104 struct bpf_prog_info_linear *info_linear;
3105 struct bpf_prog_info info = {};
3106 __u32 info_len = sizeof(info);
3107 __u32 data_len = 0;
3108 int i, err;
3109 void *ptr;
3110
3111 if (arrays >> BPF_PROG_INFO_LAST_ARRAY)
3112 return ERR_PTR(-EINVAL);
3113
3114 /* step 1: get array dimensions */
3115 err = bpf_obj_get_info_by_fd(fd, &info, &info_len);
3116 if (err) {
3117 pr_debug("can't get prog info: %s", strerror(errno));
3118 return ERR_PTR(-EFAULT);
3119 }
3120
3121 /* step 2: calculate total size of all arrays */
3122 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3123 bool include_array = (arrays & (1UL << i)) > 0;
3124 struct bpf_prog_info_array_desc *desc;
3125 __u32 count, size;
3126
3127 desc = bpf_prog_info_array_desc + i;
3128
3129 /* kernel is too old to support this field */
3130 if (info_len < desc->array_offset + sizeof(__u32) ||
3131 info_len < desc->count_offset + sizeof(__u32) ||
3132 (desc->size_offset > 0 && info_len < desc->size_offset))
3133 include_array = false;
3134
3135 if (!include_array) {
3136 arrays &= ~(1UL << i); /* clear the bit */
3137 continue;
3138 }
3139
3140 count = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
3141 size = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
3142
3143 data_len += count * size;
3144 }
3145
3146 /* step 3: allocate continuous memory */
3147 data_len = roundup(data_len, sizeof(__u64));
3148 info_linear = malloc(sizeof(struct bpf_prog_info_linear) + data_len);
3149 if (!info_linear)
3150 return ERR_PTR(-ENOMEM);
3151
3152 /* step 4: fill data to info_linear->info */
3153 info_linear->arrays = arrays;
3154 memset(&info_linear->info, 0, sizeof(info));
3155 ptr = info_linear->data;
3156
3157 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3158 struct bpf_prog_info_array_desc *desc;
3159 __u32 count, size;
3160
3161 if ((arrays & (1UL << i)) == 0)
3162 continue;
3163
3164 desc = bpf_prog_info_array_desc + i;
3165 count = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
3166 size = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
3167 bpf_prog_info_set_offset_u32(&info_linear->info,
3168 desc->count_offset, count);
3169 bpf_prog_info_set_offset_u32(&info_linear->info,
3170 desc->size_offset, size);
3171 bpf_prog_info_set_offset_u64(&info_linear->info,
3172 desc->array_offset,
3173 ptr_to_u64(ptr));
3174 ptr += count * size;
3175 }
3176
3177 /* step 5: call syscall again to get required arrays */
3178 err = bpf_obj_get_info_by_fd(fd, &info_linear->info, &info_len);
3179 if (err) {
3180 pr_debug("can't get prog info: %s", strerror(errno));
3181 free(info_linear);
3182 return ERR_PTR(-EFAULT);
3183 }
3184
3185 /* step 6: verify the data */
3186 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3187 struct bpf_prog_info_array_desc *desc;
3188 __u32 v1, v2;
3189
3190 if ((arrays & (1UL << i)) == 0)
3191 continue;
3192
3193 desc = bpf_prog_info_array_desc + i;
3194 v1 = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
3195 v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
3196 desc->count_offset);
3197 if (v1 != v2)
3198 pr_warning("%s: mismatch in element count\n", __func__);
3199
3200 v1 = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
3201 v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
3202 desc->size_offset);
3203 if (v1 != v2)
3204 pr_warning("%s: mismatch in rec size\n", __func__);
3205 }
3206
3207 /* step 7: update info_len and data_len */
3208 info_linear->info_len = sizeof(struct bpf_prog_info);
3209 info_linear->data_len = data_len;
3210
3211 return info_linear;
3212}
3213
3214void bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear)
3215{
3216 int i;
3217
3218 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3219 struct bpf_prog_info_array_desc *desc;
3220 __u64 addr, offs;
3221
3222 if ((info_linear->arrays & (1UL << i)) == 0)
3223 continue;
3224
3225 desc = bpf_prog_info_array_desc + i;
3226 addr = bpf_prog_info_read_offset_u64(&info_linear->info,
3227 desc->array_offset);
3228 offs = addr - ptr_to_u64(info_linear->data);
3229 bpf_prog_info_set_offset_u64(&info_linear->info,
3230 desc->array_offset, offs);
3231 }
3232}
3233
3234void bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear)
3235{
3236 int i;
3237
3238 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3239 struct bpf_prog_info_array_desc *desc;
3240 __u64 addr, offs;
3241
3242 if ((info_linear->arrays & (1UL << i)) == 0)
3243 continue;
3244
3245 desc = bpf_prog_info_array_desc + i;
3246 offs = bpf_prog_info_read_offset_u64(&info_linear->info,
3247 desc->array_offset);
3248 addr = offs + ptr_to_u64(info_linear->data);
3249 bpf_prog_info_set_offset_u64(&info_linear->info,
3250 desc->array_offset, addr);
3251 }
3252}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index b4652aa1a58a..c70785cc8ef5 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -10,6 +10,7 @@
10#ifndef __LIBBPF_LIBBPF_H 10#ifndef __LIBBPF_LIBBPF_H
11#define __LIBBPF_LIBBPF_H 11#define __LIBBPF_LIBBPF_H
12 12
13#include <stdarg.h>
13#include <stdio.h> 14#include <stdio.h>
14#include <stdint.h> 15#include <stdint.h>
15#include <stdbool.h> 16#include <stdbool.h>
@@ -377,6 +378,69 @@ LIBBPF_API bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex);
377LIBBPF_API bool bpf_probe_helper(enum bpf_func_id id, 378LIBBPF_API bool bpf_probe_helper(enum bpf_func_id id,
378 enum bpf_prog_type prog_type, __u32 ifindex); 379 enum bpf_prog_type prog_type, __u32 ifindex);
379 380
381/*
382 * Get bpf_prog_info in continuous memory
383 *
384 * struct bpf_prog_info has multiple arrays. The user has option to choose
385 * arrays to fetch from kernel. The following APIs provide an uniform way to
386 * fetch these data. All arrays in bpf_prog_info are stored in a single
387 * continuous memory region. This makes it easy to store the info in a
388 * file.
389 *
390 * Before writing bpf_prog_info_linear to files, it is necessary to
391 * translate pointers in bpf_prog_info to offsets. Helper functions
392 * bpf_program__bpil_addr_to_offs() and bpf_program__bpil_offs_to_addr()
393 * are introduced to switch between pointers and offsets.
394 *
395 * Examples:
396 * # To fetch map_ids and prog_tags:
397 * __u64 arrays = (1UL << BPF_PROG_INFO_MAP_IDS) |
398 * (1UL << BPF_PROG_INFO_PROG_TAGS);
399 * struct bpf_prog_info_linear *info_linear =
400 * bpf_program__get_prog_info_linear(fd, arrays);
401 *
402 * # To save data in file
403 * bpf_program__bpil_addr_to_offs(info_linear);
404 * write(f, info_linear, sizeof(*info_linear) + info_linear->data_len);
405 *
406 * # To read data from file
407 * read(f, info_linear, <proper_size>);
408 * bpf_program__bpil_offs_to_addr(info_linear);
409 */
410enum bpf_prog_info_array {
411 BPF_PROG_INFO_FIRST_ARRAY = 0,
412 BPF_PROG_INFO_JITED_INSNS = 0,
413 BPF_PROG_INFO_XLATED_INSNS,
414 BPF_PROG_INFO_MAP_IDS,
415 BPF_PROG_INFO_JITED_KSYMS,
416 BPF_PROG_INFO_JITED_FUNC_LENS,
417 BPF_PROG_INFO_FUNC_INFO,
418 BPF_PROG_INFO_LINE_INFO,
419 BPF_PROG_INFO_JITED_LINE_INFO,
420 BPF_PROG_INFO_PROG_TAGS,
421 BPF_PROG_INFO_LAST_ARRAY,
422};
423
424struct bpf_prog_info_linear {
425 /* size of struct bpf_prog_info, when the tool is compiled */
426 __u32 info_len;
427 /* total bytes allocated for data, round up to 8 bytes */
428 __u32 data_len;
429 /* which arrays are included in data */
430 __u64 arrays;
431 struct bpf_prog_info info;
432 __u8 data[];
433};
434
435LIBBPF_API struct bpf_prog_info_linear *
436bpf_program__get_prog_info_linear(int fd, __u64 arrays);
437
438LIBBPF_API void
439bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear);
440
441LIBBPF_API void
442bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear);
443
380#ifdef __cplusplus 444#ifdef __cplusplus
381} /* extern "C" */ 445} /* extern "C" */
382#endif 446#endif
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 778a26702a70..f3ce50500cf2 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -153,4 +153,7 @@ LIBBPF_0.0.2 {
153 xsk_socket__delete; 153 xsk_socket__delete;
154 xsk_umem__fd; 154 xsk_umem__fd;
155 xsk_socket__fd; 155 xsk_socket__fd;
156 bpf_program__get_prog_info_linear;
157 bpf_program__bpil_addr_to_offs;
158 bpf_program__bpil_offs_to_addr;
156} LIBBPF_0.0.1; 159} LIBBPF_0.0.1;
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 0414a0d52262..5dde107083c6 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2184,9 +2184,10 @@ static void cleanup(struct objtool_file *file)
2184 elf_close(file->elf); 2184 elf_close(file->elf);
2185} 2185}
2186 2186
2187static struct objtool_file file;
2188
2187int check(const char *_objname, bool orc) 2189int check(const char *_objname, bool orc)
2188{ 2190{
2189 struct objtool_file file;
2190 int ret, warnings = 0; 2191 int ret, warnings = 0;
2191 2192
2192 objname = _objname; 2193 objname = _objname;
diff --git a/tools/perf/Documentation/Build.txt b/tools/perf/Documentation/Build.txt
index f6fc6507ba55..3766886c4bca 100644
--- a/tools/perf/Documentation/Build.txt
+++ b/tools/perf/Documentation/Build.txt
@@ -47,3 +47,27 @@ Those objects are then used in final linking:
47 47
48NOTE this description is omitting other libraries involved, only 48NOTE this description is omitting other libraries involved, only
49 focusing on build framework outcomes 49 focusing on build framework outcomes
50
513) Build with ASan or UBSan
52==========================
53 $ cd tools/perf
54 $ make DESTDIR=/usr
55 $ make DESTDIR=/usr install
56
57AddressSanitizer (or ASan) is a GCC feature that detects memory corruption bugs
58such as buffer overflows and memory leaks.
59
60 $ cd tools/perf
61 $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address'
62 $ ASAN_OPTIONS=log_path=asan.log ./perf record -a
63
64ASan outputs all detected issues into a log file named 'asan.log.<pid>'.
65
66UndefinedBehaviorSanitizer (or UBSan) is a fast undefined behavior detector
67supported by GCC. UBSan detects undefined behaviors of programs at runtime.
68
69 $ cd tools/perf
70 $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined'
71 $ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a
72
73If UBSan detects any problem at runtime, it outputs a “runtime error:” message.
diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 86f3dcc15f83..462b3cde0675 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -114,7 +114,7 @@ Given a $HOME/.perfconfig like this:
114 114
115 [report] 115 [report]
116 # Defaults 116 # Defaults
117 sort-order = comm,dso,symbol 117 sort_order = comm,dso,symbol
118 percent-limit = 0 118 percent-limit = 0
119 queue-size = 0 119 queue-size = 0
120 children = true 120 children = true
@@ -584,6 +584,20 @@ llvm.*::
584 llvm.opts:: 584 llvm.opts::
585 Options passed to llc. 585 Options passed to llc.
586 586
587samples.*::
588
589 samples.context::
590 Define how many ns worth of time to show
591 around samples in perf report sample context browser.
592
593scripts.*::
594
595 Any option defines a script that is added to the scripts menu
596 in the interactive perf browser and whose output is displayed.
597 The name of the option is the name, the value is a script command line.
598 The script gets the same options passed as a full perf script,
599 in particular -i perfdata file, --cpu, --tid
600
587SEE ALSO 601SEE ALSO
588-------- 602--------
589linkperf:perf[1] 603linkperf:perf[1]
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 8f0c2be34848..8fe4dffcadd0 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -495,6 +495,10 @@ overhead. You can still switch them on with:
495 495
496 --switch-output --no-no-buildid --no-no-buildid-cache 496 --switch-output --no-no-buildid --no-no-buildid-cache
497 497
498--switch-max-files=N::
499
500When rotating perf.data with --switch-output, only keep N files.
501
498--dry-run:: 502--dry-run::
499Parse options then exit. --dry-run can be used to detect errors in cmdline 503Parse options then exit. --dry-run can be used to detect errors in cmdline
500options. 504options.
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 1a27bfe05039..f441baa794ce 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -105,6 +105,8 @@ OPTIONS
105 guest machine 105 guest machine
106 - sample: Number of sample 106 - sample: Number of sample
107 - period: Raw number of event count of sample 107 - period: Raw number of event count of sample
108 - time: Separate the samples by time stamp with the resolution specified by
109 --time-quantum (default 100ms). Specify with overhead and before it.
108 110
109 By default, comm, dso and symbol keys are used. 111 By default, comm, dso and symbol keys are used.
110 (i.e. --sort comm,dso,symbol) 112 (i.e. --sort comm,dso,symbol)
@@ -459,6 +461,10 @@ include::itrace.txt[]
459--socket-filter:: 461--socket-filter::
460 Only report the samples on the processor socket that match with this filter 462 Only report the samples on the processor socket that match with this filter
461 463
464--samples=N::
465 Save N individual samples for each histogram entry to show context in perf
466 report tui browser.
467
462--raw-trace:: 468--raw-trace::
463 When displaying traceevent output, do not use print fmt or plugins. 469 When displaying traceevent output, do not use print fmt or plugins.
464 470
@@ -477,6 +483,9 @@ include::itrace.txt[]
477 Please note that not all mmaps are stored, options affecting which ones 483 Please note that not all mmaps are stored, options affecting which ones
478 are include 'perf record --data', for instance. 484 are include 'perf record --data', for instance.
479 485
486--ns::
487 Show time stamps in nanoseconds.
488
480--stats:: 489--stats::
481 Display overall events statistics without any further processing. 490 Display overall events statistics without any further processing.
482 (like the one at the end of the perf report -D command) 491 (like the one at the end of the perf report -D command)
@@ -494,6 +503,10 @@ include::itrace.txt[]
494 The period/hits keywords set the base the percentage is computed 503 The period/hits keywords set the base the percentage is computed
495 on - the samples period or the number of samples (hits). 504 on - the samples period or the number of samples (hits).
496 505
506--time-quantum::
507 Configure time quantum for time sort key. Default 100ms.
508 Accepts s, us, ms, ns units.
509
497include::callchain-overhead-calculation.txt[] 510include::callchain-overhead-calculation.txt[]
498 511
499SEE ALSO 512SEE ALSO
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 2e19fd7ffe35..9b0d04dd2a61 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -380,6 +380,9 @@ include::itrace.txt[]
380 Set the maximum number of program blocks to print with brstackasm for 380 Set the maximum number of program blocks to print with brstackasm for
381 each sample. 381 each sample.
382 382
383--reltime::
384 Print time stamps relative to trace start.
385
383--per-event-dump:: 386--per-event-dump::
384 Create per event files with a "perf.data.EVENT.dump" name instead of 387 Create per event files with a "perf.data.EVENT.dump" name instead of
385 printing to stdout, useful, for instance, for generating flamegraphs. 388 printing to stdout, useful, for instance, for generating flamegraphs.
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 4bc2085e5197..39c05f89104e 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -72,9 +72,8 @@ report::
72--all-cpus:: 72--all-cpus::
73 system-wide collection from all CPUs (default if no target is specified) 73 system-wide collection from all CPUs (default if no target is specified)
74 74
75-c:: 75--no-scale::
76--scale:: 76 Don't scale/normalize counter values
77 scale/normalize counter values
78 77
79-d:: 78-d::
80--detailed:: 79--detailed::
diff --git a/tools/perf/Documentation/tips.txt b/tools/perf/Documentation/tips.txt
index 849599f39c5e..869965d629ce 100644
--- a/tools/perf/Documentation/tips.txt
+++ b/tools/perf/Documentation/tips.txt
@@ -15,6 +15,7 @@ To see callchains in a more compact form: perf report -g folded
15Show individual samples with: perf script 15Show individual samples with: perf script
16Limit to show entries above 5% only: perf report --percent-limit 5 16Limit to show entries above 5% only: perf report --percent-limit 5
17Profiling branch (mis)predictions with: perf record -b / perf report 17Profiling branch (mis)predictions with: perf record -b / perf report
18To show assembler sample contexts use perf record -b / perf script -F +brstackinsn --xed
18Treat branches as callchains: perf report --branch-history 19Treat branches as callchains: perf report --branch-history
19To count events in every 1000 msec: perf stat -I 1000 20To count events in every 1000 msec: perf stat -I 1000
20Print event counts in CSV format with: perf stat -x, 21Print event counts in CSV format with: perf stat -x,
@@ -34,3 +35,9 @@ Show current config key-value pairs: perf config --list
34Show user configuration overrides: perf config --user --list 35Show user configuration overrides: perf config --user --list
35To add Node.js USDT(User-Level Statically Defined Tracing): perf buildid-cache --add `which node` 36To add Node.js USDT(User-Level Statically Defined Tracing): perf buildid-cache --add `which node`
36To report cacheline events from previous recording: perf c2c report 37To report cacheline events from previous recording: perf c2c report
38To browse sample contexts use perf report --sample 10 and select in context menu
39To separate samples by time use perf report --sort time,overhead,sym
40To set sample time separation other than 100ms with --sort time use --time-quantum
41Add -I to perf report to sample register values visible in perf report context.
42To show IPC for sampling periods use perf record -e '{cycles,instructions}:S' and then browse context
43To show context switches in perf report sample context add --switch-events to perf record.
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 0f11d5891301..fe3f97e342fa 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -227,6 +227,8 @@ FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
227 227
228FEATURE_CHECK_LDFLAGS-libaio = -lrt 228FEATURE_CHECK_LDFLAGS-libaio = -lrt
229 229
230FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes
231
230CFLAGS += -fno-omit-frame-pointer 232CFLAGS += -fno-omit-frame-pointer
231CFLAGS += -ggdb3 233CFLAGS += -ggdb3
232CFLAGS += -funwind-tables 234CFLAGS += -funwind-tables
@@ -713,7 +715,7 @@ else
713endif 715endif
714 716
715ifeq ($(feature-libbfd), 1) 717ifeq ($(feature-libbfd), 1)
716 EXTLIBS += -lbfd 718 EXTLIBS += -lbfd -lopcodes
717else 719else
718 # we are on a system that requires -liberty and (maybe) -lz 720 # we are on a system that requires -liberty and (maybe) -lz
719 # to link against -lbfd; test each case individually here 721 # to link against -lbfd; test each case individually here
@@ -724,12 +726,15 @@ else
724 $(call feature_check,libbfd-liberty-z) 726 $(call feature_check,libbfd-liberty-z)
725 727
726 ifeq ($(feature-libbfd-liberty), 1) 728 ifeq ($(feature-libbfd-liberty), 1)
727 EXTLIBS += -lbfd -liberty 729 EXTLIBS += -lbfd -lopcodes -liberty
730 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
728 else 731 else
729 ifeq ($(feature-libbfd-liberty-z), 1) 732 ifeq ($(feature-libbfd-liberty-z), 1)
730 EXTLIBS += -lbfd -liberty -lz 733 EXTLIBS += -lbfd -lopcodes -liberty -lz
734 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
731 endif 735 endif
732 endif 736 endif
737 $(call feature_check,disassembler-four-args)
733endif 738endif
734 739
735ifdef NO_DEMANGLE 740ifdef NO_DEMANGLE
@@ -808,6 +813,10 @@ ifdef HAVE_KVM_STAT_SUPPORT
808 CFLAGS += -DHAVE_KVM_STAT_SUPPORT 813 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
809endif 814endif
810 815
816ifeq ($(feature-disassembler-four-args), 1)
817 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
818endif
819
811ifeq (${IS_64_BIT}, 1) 820ifeq (${IS_64_BIT}, 1)
812 ifndef NO_PERF_READ_VDSO32 821 ifndef NO_PERF_READ_VDSO32
813 $(call feature_check,compile-32) 822 $(call feature_check,compile-32)
diff --git a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
index f0b1709a5ffb..2ae92fddb6d5 100644
--- a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
@@ -343,6 +343,8 @@
343332 common statx __x64_sys_statx 343332 common statx __x64_sys_statx
344333 common io_pgetevents __x64_sys_io_pgetevents 344333 common io_pgetevents __x64_sys_io_pgetevents
345334 common rseq __x64_sys_rseq 345334 common rseq __x64_sys_rseq
346# don't use numbers 387 through 423, add new calls after the last
347# 'common' entry
346 348
347# 349#
348# x32-specific system call numbers start at 512 to avoid cache impact 350# x32-specific system call numbers start at 512 to avoid cache impact
@@ -361,7 +363,7 @@
361520 x32 execve __x32_compat_sys_execve/ptregs 363520 x32 execve __x32_compat_sys_execve/ptregs
362521 x32 ptrace __x32_compat_sys_ptrace 364521 x32 ptrace __x32_compat_sys_ptrace
363522 x32 rt_sigpending __x32_compat_sys_rt_sigpending 365522 x32 rt_sigpending __x32_compat_sys_rt_sigpending
364523 x32 rt_sigtimedwait __x32_compat_sys_rt_sigtimedwait 366523 x32 rt_sigtimedwait __x32_compat_sys_rt_sigtimedwait_time64
365524 x32 rt_sigqueueinfo __x32_compat_sys_rt_sigqueueinfo 367524 x32 rt_sigqueueinfo __x32_compat_sys_rt_sigqueueinfo
366525 x32 sigaltstack __x32_compat_sys_sigaltstack 368525 x32 sigaltstack __x32_compat_sys_sigaltstack
367526 x32 timer_create __x32_compat_sys_timer_create 369526 x32 timer_create __x32_compat_sys_timer_create
@@ -375,7 +377,7 @@
375534 x32 preadv __x32_compat_sys_preadv64 377534 x32 preadv __x32_compat_sys_preadv64
376535 x32 pwritev __x32_compat_sys_pwritev64 378535 x32 pwritev __x32_compat_sys_pwritev64
377536 x32 rt_tgsigqueueinfo __x32_compat_sys_rt_tgsigqueueinfo 379536 x32 rt_tgsigqueueinfo __x32_compat_sys_rt_tgsigqueueinfo
378537 x32 recvmmsg __x32_compat_sys_recvmmsg 380537 x32 recvmmsg __x32_compat_sys_recvmmsg_time64
379538 x32 sendmmsg __x32_compat_sys_sendmmsg 381538 x32 sendmmsg __x32_compat_sys_sendmmsg
380539 x32 process_vm_readv __x32_compat_sys_process_vm_readv 382539 x32 process_vm_readv __x32_compat_sys_process_vm_readv
381540 x32 process_vm_writev __x32_compat_sys_process_vm_writev 383540 x32 process_vm_writev __x32_compat_sys_process_vm_writev
diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build
index 7aab0be5fc5f..47f9c56e744f 100644
--- a/tools/perf/arch/x86/util/Build
+++ b/tools/perf/arch/x86/util/Build
@@ -14,5 +14,6 @@ perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
14perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o 14perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
15 15
16perf-$(CONFIG_AUXTRACE) += auxtrace.o 16perf-$(CONFIG_AUXTRACE) += auxtrace.o
17perf-$(CONFIG_AUXTRACE) += archinsn.o
17perf-$(CONFIG_AUXTRACE) += intel-pt.o 18perf-$(CONFIG_AUXTRACE) += intel-pt.o
18perf-$(CONFIG_AUXTRACE) += intel-bts.o 19perf-$(CONFIG_AUXTRACE) += intel-bts.o
diff --git a/tools/perf/arch/x86/util/archinsn.c b/tools/perf/arch/x86/util/archinsn.c
new file mode 100644
index 000000000000..4237bb2e7fa2
--- /dev/null
+++ b/tools/perf/arch/x86/util/archinsn.c
@@ -0,0 +1,26 @@
1// SPDX-License-Identifier: GPL-2.0
2#include "perf.h"
3#include "archinsn.h"
4#include "util/intel-pt-decoder/insn.h"
5#include "machine.h"
6#include "thread.h"
7#include "symbol.h"
8
9void arch_fetch_insn(struct perf_sample *sample,
10 struct thread *thread,
11 struct machine *machine)
12{
13 struct insn insn;
14 int len;
15 bool is64bit = false;
16
17 if (!sample->ip)
18 return;
19 len = thread__memcpy(thread, machine, sample->insn, sample->ip, sizeof(sample->insn), &is64bit);
20 if (len <= 0)
21 return;
22 insn_init(&insn, sample->insn, len, is64bit);
23 insn_get_length(&insn);
24 if (insn_complete(&insn) && insn.length <= len)
25 sample->insn_len = insn.length;
26}
diff --git a/tools/perf/bench/epoll-ctl.c b/tools/perf/bench/epoll-ctl.c
index 0c0a6e824934..2af067859966 100644
--- a/tools/perf/bench/epoll-ctl.c
+++ b/tools/perf/bench/epoll-ctl.c
@@ -224,7 +224,7 @@ static int do_threads(struct worker *worker, struct cpu_map *cpu)
224 pthread_attr_t thread_attr, *attrp = NULL; 224 pthread_attr_t thread_attr, *attrp = NULL;
225 cpu_set_t cpuset; 225 cpu_set_t cpuset;
226 unsigned int i, j; 226 unsigned int i, j;
227 int ret; 227 int ret = 0;
228 228
229 if (!noaffinity) 229 if (!noaffinity)
230 pthread_attr_init(&thread_attr); 230 pthread_attr_init(&thread_attr);
diff --git a/tools/perf/bench/epoll-wait.c b/tools/perf/bench/epoll-wait.c
index 5a11534e96a0..fe85448abd45 100644
--- a/tools/perf/bench/epoll-wait.c
+++ b/tools/perf/bench/epoll-wait.c
@@ -293,7 +293,7 @@ static int do_threads(struct worker *worker, struct cpu_map *cpu)
293 pthread_attr_t thread_attr, *attrp = NULL; 293 pthread_attr_t thread_attr, *attrp = NULL;
294 cpu_set_t cpuset; 294 cpu_set_t cpuset;
295 unsigned int i, j; 295 unsigned int i, j;
296 int ret, events = EPOLLIN; 296 int ret = 0, events = EPOLLIN;
297 297
298 if (oneshot) 298 if (oneshot)
299 events |= EPOLLONESHOT; 299 events |= EPOLLONESHOT;
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index c9f98d00c0e9..a8394b4f1167 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -119,7 +119,7 @@ int cmd_list(int argc, const char **argv)
119 details_flag); 119 details_flag);
120 print_tracepoint_events(NULL, s, raw_dump); 120 print_tracepoint_events(NULL, s, raw_dump);
121 print_sdt_events(NULL, s, raw_dump); 121 print_sdt_events(NULL, s, raw_dump);
122 metricgroup__print(true, true, NULL, raw_dump, details_flag); 122 metricgroup__print(true, true, s, raw_dump, details_flag);
123 free(s); 123 free(s);
124 } 124 }
125 } 125 }
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f3f7f3100336..4e2d953d4bc5 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -62,6 +62,9 @@ struct switch_output {
62 unsigned long time; 62 unsigned long time;
63 const char *str; 63 const char *str;
64 bool set; 64 bool set;
65 char **filenames;
66 int num_files;
67 int cur_file;
65}; 68};
66 69
67struct record { 70struct record {
@@ -392,7 +395,7 @@ static int record__process_auxtrace(struct perf_tool *tool,
392 size_t padding; 395 size_t padding;
393 u8 pad[8] = {0}; 396 u8 pad[8] = {0};
394 397
395 if (!perf_data__is_pipe(data)) { 398 if (!perf_data__is_pipe(data) && !perf_data__is_dir(data)) {
396 off_t file_offset; 399 off_t file_offset;
397 int fd = perf_data__fd(data); 400 int fd = perf_data__fd(data);
398 int err; 401 int err;
@@ -837,6 +840,8 @@ static void record__init_features(struct record *rec)
837 if (!(rec->opts.use_clockid && rec->opts.clockid_res_ns)) 840 if (!(rec->opts.use_clockid && rec->opts.clockid_res_ns))
838 perf_header__clear_feat(&session->header, HEADER_CLOCKID); 841 perf_header__clear_feat(&session->header, HEADER_CLOCKID);
839 842
843 perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT);
844
840 perf_header__clear_feat(&session->header, HEADER_STAT); 845 perf_header__clear_feat(&session->header, HEADER_STAT);
841} 846}
842 847
@@ -890,6 +895,7 @@ record__switch_output(struct record *rec, bool at_exit)
890{ 895{
891 struct perf_data *data = &rec->data; 896 struct perf_data *data = &rec->data;
892 int fd, err; 897 int fd, err;
898 char *new_filename;
893 899
894 /* Same Size: "2015122520103046"*/ 900 /* Same Size: "2015122520103046"*/
895 char timestamp[] = "InvalidTimestamp"; 901 char timestamp[] = "InvalidTimestamp";
@@ -910,7 +916,7 @@ record__switch_output(struct record *rec, bool at_exit)
910 916
911 fd = perf_data__switch(data, timestamp, 917 fd = perf_data__switch(data, timestamp,
912 rec->session->header.data_offset, 918 rec->session->header.data_offset,
913 at_exit); 919 at_exit, &new_filename);
914 if (fd >= 0 && !at_exit) { 920 if (fd >= 0 && !at_exit) {
915 rec->bytes_written = 0; 921 rec->bytes_written = 0;
916 rec->session->header.data_size = 0; 922 rec->session->header.data_size = 0;
@@ -920,6 +926,21 @@ record__switch_output(struct record *rec, bool at_exit)
920 fprintf(stderr, "[ perf record: Dump %s.%s ]\n", 926 fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
921 data->path, timestamp); 927 data->path, timestamp);
922 928
929 if (rec->switch_output.num_files) {
930 int n = rec->switch_output.cur_file + 1;
931
932 if (n >= rec->switch_output.num_files)
933 n = 0;
934 rec->switch_output.cur_file = n;
935 if (rec->switch_output.filenames[n]) {
936 remove(rec->switch_output.filenames[n]);
937 free(rec->switch_output.filenames[n]);
938 }
939 rec->switch_output.filenames[n] = new_filename;
940 } else {
941 free(new_filename);
942 }
943
923 /* Output tracking events */ 944 /* Output tracking events */
924 if (!at_exit) { 945 if (!at_exit) {
925 record__synthesize(rec, false); 946 record__synthesize(rec, false);
@@ -1093,7 +1114,7 @@ static int record__synthesize(struct record *rec, bool tail)
1093 return err; 1114 return err;
1094 } 1115 }
1095 1116
1096 err = perf_event__synthesize_bpf_events(tool, process_synthesized_event, 1117 err = perf_event__synthesize_bpf_events(session, process_synthesized_event,
1097 machine, opts); 1118 machine, opts);
1098 if (err < 0) 1119 if (err < 0)
1099 pr_warning("Couldn't synthesize bpf events.\n"); 1120 pr_warning("Couldn't synthesize bpf events.\n");
@@ -1116,6 +1137,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
1116 struct perf_data *data = &rec->data; 1137 struct perf_data *data = &rec->data;
1117 struct perf_session *session; 1138 struct perf_session *session;
1118 bool disabled = false, draining = false; 1139 bool disabled = false, draining = false;
1140 struct perf_evlist *sb_evlist = NULL;
1119 int fd; 1141 int fd;
1120 1142
1121 atexit(record__sig_exit); 1143 atexit(record__sig_exit);
@@ -1216,6 +1238,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
1216 goto out_child; 1238 goto out_child;
1217 } 1239 }
1218 1240
1241 if (!opts->no_bpf_event)
1242 bpf_event__add_sb_event(&sb_evlist, &session->header.env);
1243
1244 if (perf_evlist__start_sb_thread(sb_evlist, &rec->opts.target)) {
1245 pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
1246 opts->no_bpf_event = true;
1247 }
1248
1219 err = record__synthesize(rec, false); 1249 err = record__synthesize(rec, false);
1220 if (err < 0) 1250 if (err < 0)
1221 goto out_child; 1251 goto out_child;
@@ -1466,6 +1496,9 @@ out_child:
1466 1496
1467out_delete_session: 1497out_delete_session:
1468 perf_session__delete(session); 1498 perf_session__delete(session);
1499
1500 if (!opts->no_bpf_event)
1501 perf_evlist__stop_sb_thread(sb_evlist);
1469 return status; 1502 return status;
1470} 1503}
1471 1504
@@ -1870,7 +1903,7 @@ static struct option __record_options[] = {
1870 OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize, 1903 OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize,
1871 "synthesize non-sample events at the end of output"), 1904 "synthesize non-sample events at the end of output"),
1872 OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"), 1905 OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
1873 OPT_BOOLEAN(0, "bpf-event", &record.opts.bpf_event, "record bpf events"), 1906 OPT_BOOLEAN(0, "no-bpf-event", &record.opts.no_bpf_event, "record bpf events"),
1874 OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq, 1907 OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq,
1875 "Fail if the specified frequency can't be used"), 1908 "Fail if the specified frequency can't be used"),
1876 OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'", 1909 OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'",
@@ -1968,9 +2001,11 @@ static struct option __record_options[] = {
1968 OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary, 2001 OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
1969 "Record timestamp boundary (time of first/last samples)"), 2002 "Record timestamp boundary (time of first/last samples)"),
1970 OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str, 2003 OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
1971 &record.switch_output.set, "signal,size,time", 2004 &record.switch_output.set, "signal or size[BKMG] or time[smhd]",
1972 "Switch output when receive SIGUSR2 or cross size,time threshold", 2005 "Switch output when receiving SIGUSR2 (signal) or cross a size or time threshold",
1973 "signal"), 2006 "signal"),
2007 OPT_INTEGER(0, "switch-max-files", &record.switch_output.num_files,
2008 "Limit number of switch output generated files"),
1974 OPT_BOOLEAN(0, "dry-run", &dry_run, 2009 OPT_BOOLEAN(0, "dry-run", &dry_run,
1975 "Parse options then exit"), 2010 "Parse options then exit"),
1976#ifdef HAVE_AIO_SUPPORT 2011#ifdef HAVE_AIO_SUPPORT
@@ -2057,6 +2092,13 @@ int cmd_record(int argc, const char **argv)
2057 alarm(rec->switch_output.time); 2092 alarm(rec->switch_output.time);
2058 } 2093 }
2059 2094
2095 if (rec->switch_output.num_files) {
2096 rec->switch_output.filenames = calloc(sizeof(char *),
2097 rec->switch_output.num_files);
2098 if (!rec->switch_output.filenames)
2099 return -EINVAL;
2100 }
2101
2060 /* 2102 /*
2061 * Allow aliases to facilitate the lookup of symbols for address 2103 * Allow aliases to facilitate the lookup of symbols for address
2062 * filters. Refer to auxtrace_parse_filters(). 2104 * filters. Refer to auxtrace_parse_filters().
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index ee93c18a6685..4054eb1f98ac 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -47,9 +47,11 @@
47#include <errno.h> 47#include <errno.h>
48#include <inttypes.h> 48#include <inttypes.h>
49#include <regex.h> 49#include <regex.h>
50#include "sane_ctype.h"
50#include <signal.h> 51#include <signal.h>
51#include <linux/bitmap.h> 52#include <linux/bitmap.h>
52#include <linux/stringify.h> 53#include <linux/stringify.h>
54#include <linux/time64.h>
53#include <sys/types.h> 55#include <sys/types.h>
54#include <sys/stat.h> 56#include <sys/stat.h>
55#include <unistd.h> 57#include <unistd.h>
@@ -926,6 +928,43 @@ report_parse_callchain_opt(const struct option *opt, const char *arg, int unset)
926 return parse_callchain_report_opt(arg); 928 return parse_callchain_report_opt(arg);
927} 929}
928 930
931static int
932parse_time_quantum(const struct option *opt, const char *arg,
933 int unset __maybe_unused)
934{
935 unsigned long *time_q = opt->value;
936 char *end;
937
938 *time_q = strtoul(arg, &end, 0);
939 if (end == arg)
940 goto parse_err;
941 if (*time_q == 0) {
942 pr_err("time quantum cannot be 0");
943 return -1;
944 }
945 while (isspace(*end))
946 end++;
947 if (*end == 0)
948 return 0;
949 if (!strcmp(end, "s")) {
950 *time_q *= NSEC_PER_SEC;
951 return 0;
952 }
953 if (!strcmp(end, "ms")) {
954 *time_q *= NSEC_PER_MSEC;
955 return 0;
956 }
957 if (!strcmp(end, "us")) {
958 *time_q *= NSEC_PER_USEC;
959 return 0;
960 }
961 if (!strcmp(end, "ns"))
962 return 0;
963parse_err:
964 pr_err("Cannot parse time quantum `%s'\n", arg);
965 return -1;
966}
967
929int 968int
930report_parse_ignore_callees_opt(const struct option *opt __maybe_unused, 969report_parse_ignore_callees_opt(const struct option *opt __maybe_unused,
931 const char *arg, int unset __maybe_unused) 970 const char *arg, int unset __maybe_unused)
@@ -1044,10 +1083,9 @@ int cmd_report(int argc, const char **argv)
1044 OPT_BOOLEAN(0, "header-only", &report.header_only, 1083 OPT_BOOLEAN(0, "header-only", &report.header_only,
1045 "Show only data header."), 1084 "Show only data header."),
1046 OPT_STRING('s', "sort", &sort_order, "key[,key2...]", 1085 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1047 "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..." 1086 sort_help("sort by key(s):")),
1048 " Please refer the man page for the complete list."),
1049 OPT_STRING('F', "fields", &field_order, "key[,keys...]", 1087 OPT_STRING('F', "fields", &field_order, "key[,keys...]",
1050 "output field(s): overhead, period, sample plus all of sort keys"), 1088 sort_help("output field(s): overhead period sample ")),
1051 OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization, 1089 OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
1052 "Show sample percentage for different cpu modes"), 1090 "Show sample percentage for different cpu modes"),
1053 OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization, 1091 OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
@@ -1120,6 +1158,8 @@ int cmd_report(int argc, const char **argv)
1120 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, 1158 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
1121 "Enable kernel symbol demangling"), 1159 "Enable kernel symbol demangling"),
1122 OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"), 1160 OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
1161 OPT_INTEGER(0, "samples", &symbol_conf.res_sample,
1162 "Number of samples to save per histogram entry for individual browsing"),
1123 OPT_CALLBACK(0, "percent-limit", &report, "percent", 1163 OPT_CALLBACK(0, "percent-limit", &report, "percent",
1124 "Don't show entries under that percent", parse_percent_limit), 1164 "Don't show entries under that percent", parse_percent_limit),
1125 OPT_CALLBACK(0, "percentage", NULL, "relative|absolute", 1165 OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
@@ -1147,6 +1187,10 @@ int cmd_report(int argc, const char **argv)
1147 OPT_CALLBACK(0, "percent-type", &report.annotation_opts, "local-period", 1187 OPT_CALLBACK(0, "percent-type", &report.annotation_opts, "local-period",
1148 "Set percent type local/global-period/hits", 1188 "Set percent type local/global-period/hits",
1149 annotate_parse_percent_type), 1189 annotate_parse_percent_type),
1190 OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs, "Show times in nanosecs"),
1191 OPT_CALLBACK(0, "time-quantum", &symbol_conf.time_quantum, "time (ms|us|ns|s)",
1192 "Set time quantum for time sort key (default 100ms)",
1193 parse_time_quantum),
1150 OPT_END() 1194 OPT_END()
1151 }; 1195 };
1152 struct perf_data data = { 1196 struct perf_data data = {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 53f78cf3113f..61cfd8f70989 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -29,10 +29,12 @@
29#include "util/time-utils.h" 29#include "util/time-utils.h"
30#include "util/path.h" 30#include "util/path.h"
31#include "print_binary.h" 31#include "print_binary.h"
32#include "archinsn.h"
32#include <linux/bitmap.h> 33#include <linux/bitmap.h>
33#include <linux/kernel.h> 34#include <linux/kernel.h>
34#include <linux/stringify.h> 35#include <linux/stringify.h>
35#include <linux/time64.h> 36#include <linux/time64.h>
37#include <sys/utsname.h>
36#include "asm/bug.h" 38#include "asm/bug.h"
37#include "util/mem-events.h" 39#include "util/mem-events.h"
38#include "util/dump-insn.h" 40#include "util/dump-insn.h"
@@ -51,6 +53,8 @@
51 53
52static char const *script_name; 54static char const *script_name;
53static char const *generate_script_lang; 55static char const *generate_script_lang;
56static bool reltime;
57static u64 initial_time;
54static bool debug_mode; 58static bool debug_mode;
55static u64 last_timestamp; 59static u64 last_timestamp;
56static u64 nr_unordered; 60static u64 nr_unordered;
@@ -58,11 +62,11 @@ static bool no_callchain;
58static bool latency_format; 62static bool latency_format;
59static bool system_wide; 63static bool system_wide;
60static bool print_flags; 64static bool print_flags;
61static bool nanosecs;
62static const char *cpu_list; 65static const char *cpu_list;
63static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 66static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
64static struct perf_stat_config stat_config; 67static struct perf_stat_config stat_config;
65static int max_blocks; 68static int max_blocks;
69static bool native_arch;
66 70
67unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH; 71unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH;
68 72
@@ -684,15 +688,21 @@ static int perf_sample__fprintf_start(struct perf_sample *sample,
684 } 688 }
685 689
686 if (PRINT_FIELD(TIME)) { 690 if (PRINT_FIELD(TIME)) {
687 nsecs = sample->time; 691 u64 t = sample->time;
692 if (reltime) {
693 if (!initial_time)
694 initial_time = sample->time;
695 t = sample->time - initial_time;
696 }
697 nsecs = t;
688 secs = nsecs / NSEC_PER_SEC; 698 secs = nsecs / NSEC_PER_SEC;
689 nsecs -= secs * NSEC_PER_SEC; 699 nsecs -= secs * NSEC_PER_SEC;
690 700
691 if (nanosecs) 701 if (symbol_conf.nanosecs)
692 printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs); 702 printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs);
693 else { 703 else {
694 char sample_time[32]; 704 char sample_time[32];
695 timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time)); 705 timestamp__scnprintf_usec(t, sample_time, sizeof(sample_time));
696 printed += fprintf(fp, "%12s: ", sample_time); 706 printed += fprintf(fp, "%12s: ", sample_time);
697 } 707 }
698 } 708 }
@@ -1227,6 +1237,12 @@ static int perf_sample__fprintf_callindent(struct perf_sample *sample,
1227 return len + dlen; 1237 return len + dlen;
1228} 1238}
1229 1239
1240__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused,
1241 struct thread *thread __maybe_unused,
1242 struct machine *machine __maybe_unused)
1243{
1244}
1245
1230static int perf_sample__fprintf_insn(struct perf_sample *sample, 1246static int perf_sample__fprintf_insn(struct perf_sample *sample,
1231 struct perf_event_attr *attr, 1247 struct perf_event_attr *attr,
1232 struct thread *thread, 1248 struct thread *thread,
@@ -1234,9 +1250,12 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample,
1234{ 1250{
1235 int printed = 0; 1251 int printed = 0;
1236 1252
1253 if (sample->insn_len == 0 && native_arch)
1254 arch_fetch_insn(sample, thread, machine);
1255
1237 if (PRINT_FIELD(INSNLEN)) 1256 if (PRINT_FIELD(INSNLEN))
1238 printed += fprintf(fp, " ilen: %d", sample->insn_len); 1257 printed += fprintf(fp, " ilen: %d", sample->insn_len);
1239 if (PRINT_FIELD(INSN)) { 1258 if (PRINT_FIELD(INSN) && sample->insn_len) {
1240 int i; 1259 int i;
1241 1260
1242 printed += fprintf(fp, " insn:"); 1261 printed += fprintf(fp, " insn:");
@@ -1922,6 +1941,13 @@ static int cleanup_scripting(void)
1922 return scripting_ops ? scripting_ops->stop_script() : 0; 1941 return scripting_ops ? scripting_ops->stop_script() : 0;
1923} 1942}
1924 1943
1944static bool filter_cpu(struct perf_sample *sample)
1945{
1946 if (cpu_list)
1947 return !test_bit(sample->cpu, cpu_bitmap);
1948 return false;
1949}
1950
1925static int process_sample_event(struct perf_tool *tool, 1951static int process_sample_event(struct perf_tool *tool,
1926 union perf_event *event, 1952 union perf_event *event,
1927 struct perf_sample *sample, 1953 struct perf_sample *sample,
@@ -1956,7 +1982,7 @@ static int process_sample_event(struct perf_tool *tool,
1956 if (al.filtered) 1982 if (al.filtered)
1957 goto out_put; 1983 goto out_put;
1958 1984
1959 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) 1985 if (filter_cpu(sample))
1960 goto out_put; 1986 goto out_put;
1961 1987
1962 if (scripting_ops) 1988 if (scripting_ops)
@@ -2041,9 +2067,11 @@ static int process_comm_event(struct perf_tool *tool,
2041 sample->tid = event->comm.tid; 2067 sample->tid = event->comm.tid;
2042 sample->pid = event->comm.pid; 2068 sample->pid = event->comm.pid;
2043 } 2069 }
2044 perf_sample__fprintf_start(sample, thread, evsel, 2070 if (!filter_cpu(sample)) {
2071 perf_sample__fprintf_start(sample, thread, evsel,
2045 PERF_RECORD_COMM, stdout); 2072 PERF_RECORD_COMM, stdout);
2046 perf_event__fprintf(event, stdout); 2073 perf_event__fprintf(event, stdout);
2074 }
2047 ret = 0; 2075 ret = 0;
2048out: 2076out:
2049 thread__put(thread); 2077 thread__put(thread);
@@ -2077,9 +2105,11 @@ static int process_namespaces_event(struct perf_tool *tool,
2077 sample->tid = event->namespaces.tid; 2105 sample->tid = event->namespaces.tid;
2078 sample->pid = event->namespaces.pid; 2106 sample->pid = event->namespaces.pid;
2079 } 2107 }
2080 perf_sample__fprintf_start(sample, thread, evsel, 2108 if (!filter_cpu(sample)) {
2081 PERF_RECORD_NAMESPACES, stdout); 2109 perf_sample__fprintf_start(sample, thread, evsel,
2082 perf_event__fprintf(event, stdout); 2110 PERF_RECORD_NAMESPACES, stdout);
2111 perf_event__fprintf(event, stdout);
2112 }
2083 ret = 0; 2113 ret = 0;
2084out: 2114out:
2085 thread__put(thread); 2115 thread__put(thread);
@@ -2111,9 +2141,11 @@ static int process_fork_event(struct perf_tool *tool,
2111 sample->tid = event->fork.tid; 2141 sample->tid = event->fork.tid;
2112 sample->pid = event->fork.pid; 2142 sample->pid = event->fork.pid;
2113 } 2143 }
2114 perf_sample__fprintf_start(sample, thread, evsel, 2144 if (!filter_cpu(sample)) {
2115 PERF_RECORD_FORK, stdout); 2145 perf_sample__fprintf_start(sample, thread, evsel,
2116 perf_event__fprintf(event, stdout); 2146 PERF_RECORD_FORK, stdout);
2147 perf_event__fprintf(event, stdout);
2148 }
2117 thread__put(thread); 2149 thread__put(thread);
2118 2150
2119 return 0; 2151 return 0;
@@ -2141,9 +2173,11 @@ static int process_exit_event(struct perf_tool *tool,
2141 sample->tid = event->fork.tid; 2173 sample->tid = event->fork.tid;
2142 sample->pid = event->fork.pid; 2174 sample->pid = event->fork.pid;
2143 } 2175 }
2144 perf_sample__fprintf_start(sample, thread, evsel, 2176 if (!filter_cpu(sample)) {
2145 PERF_RECORD_EXIT, stdout); 2177 perf_sample__fprintf_start(sample, thread, evsel,
2146 perf_event__fprintf(event, stdout); 2178 PERF_RECORD_EXIT, stdout);
2179 perf_event__fprintf(event, stdout);
2180 }
2147 2181
2148 if (perf_event__process_exit(tool, event, sample, machine) < 0) 2182 if (perf_event__process_exit(tool, event, sample, machine) < 0)
2149 err = -1; 2183 err = -1;
@@ -2177,9 +2211,11 @@ static int process_mmap_event(struct perf_tool *tool,
2177 sample->tid = event->mmap.tid; 2211 sample->tid = event->mmap.tid;
2178 sample->pid = event->mmap.pid; 2212 sample->pid = event->mmap.pid;
2179 } 2213 }
2180 perf_sample__fprintf_start(sample, thread, evsel, 2214 if (!filter_cpu(sample)) {
2181 PERF_RECORD_MMAP, stdout); 2215 perf_sample__fprintf_start(sample, thread, evsel,
2182 perf_event__fprintf(event, stdout); 2216 PERF_RECORD_MMAP, stdout);
2217 perf_event__fprintf(event, stdout);
2218 }
2183 thread__put(thread); 2219 thread__put(thread);
2184 return 0; 2220 return 0;
2185} 2221}
@@ -2209,9 +2245,11 @@ static int process_mmap2_event(struct perf_tool *tool,
2209 sample->tid = event->mmap2.tid; 2245 sample->tid = event->mmap2.tid;
2210 sample->pid = event->mmap2.pid; 2246 sample->pid = event->mmap2.pid;
2211 } 2247 }
2212 perf_sample__fprintf_start(sample, thread, evsel, 2248 if (!filter_cpu(sample)) {
2213 PERF_RECORD_MMAP2, stdout); 2249 perf_sample__fprintf_start(sample, thread, evsel,
2214 perf_event__fprintf(event, stdout); 2250 PERF_RECORD_MMAP2, stdout);
2251 perf_event__fprintf(event, stdout);
2252 }
2215 thread__put(thread); 2253 thread__put(thread);
2216 return 0; 2254 return 0;
2217} 2255}
@@ -2236,9 +2274,11 @@ static int process_switch_event(struct perf_tool *tool,
2236 return -1; 2274 return -1;
2237 } 2275 }
2238 2276
2239 perf_sample__fprintf_start(sample, thread, evsel, 2277 if (!filter_cpu(sample)) {
2240 PERF_RECORD_SWITCH, stdout); 2278 perf_sample__fprintf_start(sample, thread, evsel,
2241 perf_event__fprintf(event, stdout); 2279 PERF_RECORD_SWITCH, stdout);
2280 perf_event__fprintf(event, stdout);
2281 }
2242 thread__put(thread); 2282 thread__put(thread);
2243 return 0; 2283 return 0;
2244} 2284}
@@ -2259,9 +2299,11 @@ process_lost_event(struct perf_tool *tool,
2259 if (thread == NULL) 2299 if (thread == NULL)
2260 return -1; 2300 return -1;
2261 2301
2262 perf_sample__fprintf_start(sample, thread, evsel, 2302 if (!filter_cpu(sample)) {
2263 PERF_RECORD_LOST, stdout); 2303 perf_sample__fprintf_start(sample, thread, evsel,
2264 perf_event__fprintf(event, stdout); 2304 PERF_RECORD_LOST, stdout);
2305 perf_event__fprintf(event, stdout);
2306 }
2265 thread__put(thread); 2307 thread__put(thread);
2266 return 0; 2308 return 0;
2267} 2309}
@@ -2948,7 +2990,8 @@ static int check_ev_match(char *dir_name, char *scriptname,
2948 * will list all statically runnable scripts, select one, execute it and 2990 * will list all statically runnable scripts, select one, execute it and
2949 * show the output in a perf browser. 2991 * show the output in a perf browser.
2950 */ 2992 */
2951int find_scripts(char **scripts_array, char **scripts_path_array) 2993int find_scripts(char **scripts_array, char **scripts_path_array, int num,
2994 int pathlen)
2952{ 2995{
2953 struct dirent *script_dirent, *lang_dirent; 2996 struct dirent *script_dirent, *lang_dirent;
2954 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; 2997 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
@@ -2993,7 +3036,10 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
2993 /* Skip those real time scripts: xxxtop.p[yl] */ 3036 /* Skip those real time scripts: xxxtop.p[yl] */
2994 if (strstr(script_dirent->d_name, "top.")) 3037 if (strstr(script_dirent->d_name, "top."))
2995 continue; 3038 continue;
2996 sprintf(scripts_path_array[i], "%s/%s", lang_path, 3039 if (i >= num)
3040 break;
3041 snprintf(scripts_path_array[i], pathlen, "%s/%s",
3042 lang_path,
2997 script_dirent->d_name); 3043 script_dirent->d_name);
2998 temp = strchr(script_dirent->d_name, '.'); 3044 temp = strchr(script_dirent->d_name, '.');
2999 snprintf(scripts_array[i], 3045 snprintf(scripts_array[i],
@@ -3232,7 +3278,7 @@ static int parse_insn_trace(const struct option *opt __maybe_unused,
3232{ 3278{
3233 parse_output_fields(NULL, "+insn,-event,-period", 0); 3279 parse_output_fields(NULL, "+insn,-event,-period", 0);
3234 itrace_parse_synth_opts(opt, "i0ns", 0); 3280 itrace_parse_synth_opts(opt, "i0ns", 0);
3235 nanosecs = true; 3281 symbol_conf.nanosecs = true;
3236 return 0; 3282 return 0;
3237} 3283}
3238 3284
@@ -3250,7 +3296,7 @@ static int parse_call_trace(const struct option *opt __maybe_unused,
3250{ 3296{
3251 parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0); 3297 parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0);
3252 itrace_parse_synth_opts(opt, "cewp", 0); 3298 itrace_parse_synth_opts(opt, "cewp", 0);
3253 nanosecs = true; 3299 symbol_conf.nanosecs = true;
3254 return 0; 3300 return 0;
3255} 3301}
3256 3302
@@ -3260,7 +3306,7 @@ static int parse_callret_trace(const struct option *opt __maybe_unused,
3260{ 3306{
3261 parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent,+flags", 0); 3307 parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent,+flags", 0);
3262 itrace_parse_synth_opts(opt, "crewp", 0); 3308 itrace_parse_synth_opts(opt, "crewp", 0);
3263 nanosecs = true; 3309 symbol_conf.nanosecs = true;
3264 return 0; 3310 return 0;
3265} 3311}
3266 3312
@@ -3277,6 +3323,7 @@ int cmd_script(int argc, const char **argv)
3277 .set = false, 3323 .set = false,
3278 .default_no_sample = true, 3324 .default_no_sample = true,
3279 }; 3325 };
3326 struct utsname uts;
3280 char *script_path = NULL; 3327 char *script_path = NULL;
3281 const char **__argv; 3328 const char **__argv;
3282 int i, j, err = 0; 3329 int i, j, err = 0;
@@ -3374,6 +3421,7 @@ int cmd_script(int argc, const char **argv)
3374 "Set the maximum stack depth when parsing the callchain, " 3421 "Set the maximum stack depth when parsing the callchain, "
3375 "anything beyond the specified depth will be ignored. " 3422 "anything beyond the specified depth will be ignored. "
3376 "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)), 3423 "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
3424 OPT_BOOLEAN(0, "reltime", &reltime, "Show time stamps relative to start"),
3377 OPT_BOOLEAN('I', "show-info", &show_full_info, 3425 OPT_BOOLEAN('I', "show-info", &show_full_info,
3378 "display extended information from perf.data file"), 3426 "display extended information from perf.data file"),
3379 OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path, 3427 OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
@@ -3395,7 +3443,7 @@ int cmd_script(int argc, const char **argv)
3395 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), 3443 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
3396 OPT_INTEGER(0, "max-blocks", &max_blocks, 3444 OPT_INTEGER(0, "max-blocks", &max_blocks,
3397 "Maximum number of code blocks to dump with brstackinsn"), 3445 "Maximum number of code blocks to dump with brstackinsn"),
3398 OPT_BOOLEAN(0, "ns", &nanosecs, 3446 OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs,
3399 "Use 9 decimal places when displaying time"), 3447 "Use 9 decimal places when displaying time"),
3400 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", 3448 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
3401 "Instruction Tracing options\n" ITRACE_HELP, 3449 "Instruction Tracing options\n" ITRACE_HELP,
@@ -3448,6 +3496,11 @@ int cmd_script(int argc, const char **argv)
3448 } 3496 }
3449 } 3497 }
3450 3498
3499 if (script.time_str && reltime) {
3500 fprintf(stderr, "Don't combine --reltime with --time\n");
3501 return -1;
3502 }
3503
3451 if (itrace_synth_opts.callchain && 3504 if (itrace_synth_opts.callchain &&
3452 itrace_synth_opts.callchain_sz > scripting_max_stack) 3505 itrace_synth_opts.callchain_sz > scripting_max_stack)
3453 scripting_max_stack = itrace_synth_opts.callchain_sz; 3506 scripting_max_stack = itrace_synth_opts.callchain_sz;
@@ -3615,6 +3668,12 @@ int cmd_script(int argc, const char **argv)
3615 if (symbol__init(&session->header.env) < 0) 3668 if (symbol__init(&session->header.env) < 0)
3616 goto out_delete; 3669 goto out_delete;
3617 3670
3671 uname(&uts);
3672 if (!strcmp(uts.machine, session->header.env.arch) ||
3673 (!strcmp(uts.machine, "x86_64") &&
3674 !strcmp(session->header.env.arch, "i386")))
3675 native_arch = true;
3676
3618 script.session = session; 3677 script.session = session;
3619 script__setup_sample_type(&script); 3678 script__setup_sample_type(&script);
3620 3679
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 7b8f09b0b8bf..49ee3c2033ec 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -718,7 +718,8 @@ static struct option stat_options[] = {
718 "system-wide collection from all CPUs"), 718 "system-wide collection from all CPUs"),
719 OPT_BOOLEAN('g', "group", &group, 719 OPT_BOOLEAN('g', "group", &group,
720 "put the counters into a counter group"), 720 "put the counters into a counter group"),
721 OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), 721 OPT_BOOLEAN(0, "scale", &stat_config.scale,
722 "Use --no-scale to disable counter scaling for multiplexing"),
722 OPT_INCR('v', "verbose", &verbose, 723 OPT_INCR('v', "verbose", &verbose,
723 "be more verbose (show counter open errors, etc)"), 724 "be more verbose (show counter open errors, etc)"),
724 OPT_INTEGER('r', "repeat", &stat_config.run_count, 725 OPT_INTEGER('r', "repeat", &stat_config.run_count,
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 231a90daa958..1999d6533d12 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1189,30 +1189,26 @@ static int __cmd_top(struct perf_top *top)
1189 pthread_t thread, thread_process; 1189 pthread_t thread, thread_process;
1190 int ret; 1190 int ret;
1191 1191
1192 top->session = perf_session__new(NULL, false, NULL);
1193 if (top->session == NULL)
1194 return -1;
1195
1196 if (!top->annotation_opts.objdump_path) { 1192 if (!top->annotation_opts.objdump_path) {
1197 ret = perf_env__lookup_objdump(&top->session->header.env, 1193 ret = perf_env__lookup_objdump(&top->session->header.env,
1198 &top->annotation_opts.objdump_path); 1194 &top->annotation_opts.objdump_path);
1199 if (ret) 1195 if (ret)
1200 goto out_delete; 1196 return ret;
1201 } 1197 }
1202 1198
1203 ret = callchain_param__setup_sample_type(&callchain_param); 1199 ret = callchain_param__setup_sample_type(&callchain_param);
1204 if (ret) 1200 if (ret)
1205 goto out_delete; 1201 return ret;
1206 1202
1207 if (perf_session__register_idle_thread(top->session) < 0) 1203 if (perf_session__register_idle_thread(top->session) < 0)
1208 goto out_delete; 1204 return ret;
1209 1205
1210 if (top->nr_threads_synthesize > 1) 1206 if (top->nr_threads_synthesize > 1)
1211 perf_set_multithreaded(); 1207 perf_set_multithreaded();
1212 1208
1213 init_process_thread(top); 1209 init_process_thread(top);
1214 1210
1215 ret = perf_event__synthesize_bpf_events(&top->tool, perf_event__process, 1211 ret = perf_event__synthesize_bpf_events(top->session, perf_event__process,
1216 &top->session->machines.host, 1212 &top->session->machines.host,
1217 &top->record_opts); 1213 &top->record_opts);
1218 if (ret < 0) 1214 if (ret < 0)
@@ -1227,13 +1223,18 @@ static int __cmd_top(struct perf_top *top)
1227 1223
1228 if (perf_hpp_list.socket) { 1224 if (perf_hpp_list.socket) {
1229 ret = perf_env__read_cpu_topology_map(&perf_env); 1225 ret = perf_env__read_cpu_topology_map(&perf_env);
1230 if (ret < 0) 1226 if (ret < 0) {
1231 goto out_err_cpu_topo; 1227 char errbuf[BUFSIZ];
1228 const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
1229
1230 ui__error("Could not read the CPU topology map: %s\n", err);
1231 return ret;
1232 }
1232 } 1233 }
1233 1234
1234 ret = perf_top__start_counters(top); 1235 ret = perf_top__start_counters(top);
1235 if (ret) 1236 if (ret)
1236 goto out_delete; 1237 return ret;
1237 1238
1238 top->session->evlist = top->evlist; 1239 top->session->evlist = top->evlist;
1239 perf_session__set_id_hdr_size(top->session); 1240 perf_session__set_id_hdr_size(top->session);
@@ -1252,7 +1253,7 @@ static int __cmd_top(struct perf_top *top)
1252 ret = -1; 1253 ret = -1;
1253 if (pthread_create(&thread_process, NULL, process_thread, top)) { 1254 if (pthread_create(&thread_process, NULL, process_thread, top)) {
1254 ui__error("Could not create process thread.\n"); 1255 ui__error("Could not create process thread.\n");
1255 goto out_delete; 1256 return ret;
1256 } 1257 }
1257 1258
1258 if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui : 1259 if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui :
@@ -1296,19 +1297,7 @@ out_join:
1296out_join_thread: 1297out_join_thread:
1297 pthread_cond_signal(&top->qe.cond); 1298 pthread_cond_signal(&top->qe.cond);
1298 pthread_join(thread_process, NULL); 1299 pthread_join(thread_process, NULL);
1299out_delete:
1300 perf_session__delete(top->session);
1301 top->session = NULL;
1302
1303 return ret; 1300 return ret;
1304
1305out_err_cpu_topo: {
1306 char errbuf[BUFSIZ];
1307 const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
1308
1309 ui__error("Could not read the CPU topology map: %s\n", err);
1310 goto out_delete;
1311}
1312} 1301}
1313 1302
1314static int 1303static int
@@ -1480,6 +1469,7 @@ int cmd_top(int argc, const char **argv)
1480 "Display raw encoding of assembly instructions (default)"), 1469 "Display raw encoding of assembly instructions (default)"),
1481 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, 1470 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
1482 "Enable kernel symbol demangling"), 1471 "Enable kernel symbol demangling"),
1472 OPT_BOOLEAN(0, "no-bpf-event", &top.record_opts.no_bpf_event, "do not record bpf events"),
1483 OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path", 1473 OPT_STRING(0, "objdump", &top.annotation_opts.objdump_path, "path",
1484 "objdump binary to use for disassembly and annotations"), 1474 "objdump binary to use for disassembly and annotations"),
1485 OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style", 1475 OPT_STRING('M', "disassembler-style", &top.annotation_opts.disassembler_style, "disassembler style",
@@ -1511,6 +1501,7 @@ int cmd_top(int argc, const char **argv)
1511 "number of thread to run event synthesize"), 1501 "number of thread to run event synthesize"),
1512 OPT_END() 1502 OPT_END()
1513 }; 1503 };
1504 struct perf_evlist *sb_evlist = NULL;
1514 const char * const top_usage[] = { 1505 const char * const top_usage[] = {
1515 "perf top [<options>]", 1506 "perf top [<options>]",
1516 NULL 1507 NULL
@@ -1628,8 +1619,9 @@ int cmd_top(int argc, const char **argv)
1628 annotation_config__init(); 1619 annotation_config__init();
1629 1620
1630 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); 1621 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
1631 if (symbol__init(NULL) < 0) 1622 status = symbol__init(NULL);
1632 return -1; 1623 if (status < 0)
1624 goto out_delete_evlist;
1633 1625
1634 sort__setup_elide(stdout); 1626 sort__setup_elide(stdout);
1635 1627
@@ -1639,10 +1631,28 @@ int cmd_top(int argc, const char **argv)
1639 signal(SIGWINCH, winch_sig); 1631 signal(SIGWINCH, winch_sig);
1640 } 1632 }
1641 1633
1634 top.session = perf_session__new(NULL, false, NULL);
1635 if (top.session == NULL) {
1636 status = -1;
1637 goto out_delete_evlist;
1638 }
1639
1640 if (!top.record_opts.no_bpf_event)
1641 bpf_event__add_sb_event(&sb_evlist, &perf_env);
1642
1643 if (perf_evlist__start_sb_thread(sb_evlist, target)) {
1644 pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
1645 opts->no_bpf_event = true;
1646 }
1647
1642 status = __cmd_top(&top); 1648 status = __cmd_top(&top);
1643 1649
1650 if (!opts->no_bpf_event)
1651 perf_evlist__stop_sb_thread(sb_evlist);
1652
1644out_delete_evlist: 1653out_delete_evlist:
1645 perf_evlist__delete(top.evlist); 1654 perf_evlist__delete(top.evlist);
1655 perf_session__delete(top.session);
1646 1656
1647 return status; 1657 return status;
1648} 1658}
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 05745f3ce912..999fe9170122 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -40,5 +40,6 @@ int cmd_mem(int argc, const char **argv);
40int cmd_data(int argc, const char **argv); 40int cmd_data(int argc, const char **argv);
41int cmd_ftrace(int argc, const char **argv); 41int cmd_ftrace(int argc, const char **argv);
42 42
43int find_scripts(char **scripts_array, char **scripts_path_array); 43int find_scripts(char **scripts_array, char **scripts_path_array, int num,
44 int pathlen);
44#endif 45#endif
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index a11cb006f968..72df4b6fa36f 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -298,6 +298,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
298 use_pager = 1; 298 use_pager = 1;
299 commit_pager_choice(); 299 commit_pager_choice();
300 300
301 perf_env__init(&perf_env);
301 perf_env__set_cmdline(&perf_env, argc, argv); 302 perf_env__set_cmdline(&perf_env, argc, argv);
302 status = p->fn(argc, argv); 303 status = p->fn(argc, argv);
303 perf_config__exit(); 304 perf_config__exit();
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index b120e547ddc7..c59743def8d3 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -66,7 +66,7 @@ struct record_opts {
66 bool ignore_missing_thread; 66 bool ignore_missing_thread;
67 bool strict_freq; 67 bool strict_freq;
68 bool sample_id; 68 bool sample_id;
69 bool bpf_event; 69 bool no_bpf_event;
70 unsigned int freq; 70 unsigned int freq;
71 unsigned int mmap_pages; 71 unsigned int mmap_pages;
72 unsigned int auxtrace_mmap_pages; 72 unsigned int auxtrace_mmap_pages;
diff --git a/tools/perf/pmu-events/arch/powerpc/power8/other.json b/tools/perf/pmu-events/arch/powerpc/power8/other.json
index 704302c3e67d..9dc2f6b70354 100644
--- a/tools/perf/pmu-events/arch/powerpc/power8/other.json
+++ b/tools/perf/pmu-events/arch/powerpc/power8/other.json
@@ -348,18 +348,6 @@
348 "PublicDescription": "" 348 "PublicDescription": ""
349 }, 349 },
350 {, 350 {,
351 "EventCode": "0x517082",
352 "EventName": "PM_CO_DISP_FAIL",
353 "BriefDescription": "CO dispatch failed due to all CO machines being busy",
354 "PublicDescription": ""
355 },
356 {,
357 "EventCode": "0x527084",
358 "EventName": "PM_CO_TM_SC_FOOTPRINT",
359 "BriefDescription": "L2 did a cleanifdirty CO to the L3 (ie created an SC line in the L3)",
360 "PublicDescription": ""
361 },
362 {,
363 "EventCode": "0x3608a", 351 "EventCode": "0x3608a",
364 "EventName": "PM_CO_USAGE", 352 "EventName": "PM_CO_USAGE",
365 "BriefDescription": "Continuous 16 cycle(2to1) window where this signals rotates thru sampling each L2 CO machine busy. PMU uses this wave to then do 16 cyc count to sample total number of machs running", 353 "BriefDescription": "Continuous 16 cycle(2to1) window where this signals rotates thru sampling each L2 CO machine busy. PMU uses this wave to then do 16 cyc count to sample total number of machs running",
@@ -1578,36 +1566,12 @@
1578 "PublicDescription": "" 1566 "PublicDescription": ""
1579 }, 1567 },
1580 {, 1568 {,
1581 "EventCode": "0x617082",
1582 "EventName": "PM_ISIDE_DISP",
1583 "BriefDescription": "All i-side dispatch attempts",
1584 "PublicDescription": ""
1585 },
1586 {,
1587 "EventCode": "0x627084",
1588 "EventName": "PM_ISIDE_DISP_FAIL",
1589 "BriefDescription": "All i-side dispatch attempts that failed due to a addr collision with another machine",
1590 "PublicDescription": ""
1591 },
1592 {,
1593 "EventCode": "0x627086",
1594 "EventName": "PM_ISIDE_DISP_FAIL_OTHER",
1595 "BriefDescription": "All i-side dispatch attempts that failed due to a reason other than addrs collision",
1596 "PublicDescription": ""
1597 },
1598 {,
1599 "EventCode": "0x4608e", 1569 "EventCode": "0x4608e",
1600 "EventName": "PM_ISIDE_L2MEMACC", 1570 "EventName": "PM_ISIDE_L2MEMACC",
1601 "BriefDescription": "valid when first beat of data comes in for an i-side fetch where data came from mem(or L4)", 1571 "BriefDescription": "valid when first beat of data comes in for an i-side fetch where data came from mem(or L4)",
1602 "PublicDescription": "" 1572 "PublicDescription": ""
1603 }, 1573 },
1604 {, 1574 {,
1605 "EventCode": "0x44608e",
1606 "EventName": "PM_ISIDE_MRU_TOUCH",
1607 "BriefDescription": "Iside L2 MRU touch",
1608 "PublicDescription": ""
1609 },
1610 {,
1611 "EventCode": "0x30ac", 1575 "EventCode": "0x30ac",
1612 "EventName": "PM_ISU_REF_FX0", 1576 "EventName": "PM_ISU_REF_FX0",
1613 "BriefDescription": "FX0 ISU reject", 1577 "BriefDescription": "FX0 ISU reject",
@@ -1734,222 +1698,36 @@
1734 "PublicDescription": "" 1698 "PublicDescription": ""
1735 }, 1699 },
1736 {, 1700 {,
1737 "EventCode": "0x417080",
1738 "EventName": "PM_L2_CASTOUT_MOD",
1739 "BriefDescription": "L2 Castouts - Modified (M, Mu, Me)",
1740 "PublicDescription": ""
1741 },
1742 {,
1743 "EventCode": "0x417082",
1744 "EventName": "PM_L2_CASTOUT_SHR",
1745 "BriefDescription": "L2 Castouts - Shared (T, Te, Si, S)",
1746 "PublicDescription": ""
1747 },
1748 {,
1749 "EventCode": "0x27084", 1701 "EventCode": "0x27084",
1750 "EventName": "PM_L2_CHIP_PUMP", 1702 "EventName": "PM_L2_CHIP_PUMP",
1751 "BriefDescription": "RC requests that were local on chip pump attempts", 1703 "BriefDescription": "RC requests that were local on chip pump attempts",
1752 "PublicDescription": "" 1704 "PublicDescription": ""
1753 }, 1705 },
1754 {, 1706 {,
1755 "EventCode": "0x427086",
1756 "EventName": "PM_L2_DC_INV",
1757 "BriefDescription": "Dcache invalidates from L2",
1758 "PublicDescription": ""
1759 },
1760 {,
1761 "EventCode": "0x44608c",
1762 "EventName": "PM_L2_DISP_ALL_L2MISS",
1763 "BriefDescription": "All successful Ld/St dispatches for this thread that were an L2miss",
1764 "PublicDescription": ""
1765 },
1766 {,
1767 "EventCode": "0x27086", 1707 "EventCode": "0x27086",
1768 "EventName": "PM_L2_GROUP_PUMP", 1708 "EventName": "PM_L2_GROUP_PUMP",
1769 "BriefDescription": "RC requests that were on Node Pump attempts", 1709 "BriefDescription": "RC requests that were on Node Pump attempts",
1770 "PublicDescription": "" 1710 "PublicDescription": ""
1771 }, 1711 },
1772 {, 1712 {,
1773 "EventCode": "0x626084",
1774 "EventName": "PM_L2_GRP_GUESS_CORRECT",
1775 "BriefDescription": "L2 guess grp and guess was correct (data intra-6chip AND ^on-chip)",
1776 "PublicDescription": ""
1777 },
1778 {,
1779 "EventCode": "0x626086",
1780 "EventName": "PM_L2_GRP_GUESS_WRONG",
1781 "BriefDescription": "L2 guess grp and guess was not correct (ie data on-chip OR beyond-6chip)",
1782 "PublicDescription": ""
1783 },
1784 {,
1785 "EventCode": "0x427084",
1786 "EventName": "PM_L2_IC_INV",
1787 "BriefDescription": "Icache Invalidates from L2",
1788 "PublicDescription": ""
1789 },
1790 {,
1791 "EventCode": "0x436088",
1792 "EventName": "PM_L2_INST",
1793 "BriefDescription": "All successful I-side dispatches for this thread (excludes i_l2mru_tch reqs)",
1794 "PublicDescription": ""
1795 },
1796 {,
1797 "EventCode": "0x43608a",
1798 "EventName": "PM_L2_INST_MISS",
1799 "BriefDescription": "All successful i-side dispatches that were an L2miss for this thread (excludes i_l2mru_tch reqs)",
1800 "PublicDescription": ""
1801 },
1802 {,
1803 "EventCode": "0x416080",
1804 "EventName": "PM_L2_LD",
1805 "BriefDescription": "All successful D-side Load dispatches for this thread",
1806 "PublicDescription": ""
1807 },
1808 {,
1809 "EventCode": "0x437088",
1810 "EventName": "PM_L2_LD_DISP",
1811 "BriefDescription": "All successful load dispatches",
1812 "PublicDescription": ""
1813 },
1814 {,
1815 "EventCode": "0x43708a",
1816 "EventName": "PM_L2_LD_HIT",
1817 "BriefDescription": "All successful load dispatches that were L2 hits",
1818 "PublicDescription": ""
1819 },
1820 {,
1821 "EventCode": "0x426084",
1822 "EventName": "PM_L2_LD_MISS",
1823 "BriefDescription": "All successful D-Side Load dispatches that were an L2miss for this thread",
1824 "PublicDescription": ""
1825 },
1826 {,
1827 "EventCode": "0x616080",
1828 "EventName": "PM_L2_LOC_GUESS_CORRECT",
1829 "BriefDescription": "L2 guess loc and guess was correct (ie data local)",
1830 "PublicDescription": ""
1831 },
1832 {,
1833 "EventCode": "0x616082",
1834 "EventName": "PM_L2_LOC_GUESS_WRONG",
1835 "BriefDescription": "L2 guess loc and guess was not correct (ie data not on chip)",
1836 "PublicDescription": ""
1837 },
1838 {,
1839 "EventCode": "0x516080",
1840 "EventName": "PM_L2_RCLD_DISP",
1841 "BriefDescription": "L2 RC load dispatch attempt",
1842 "PublicDescription": ""
1843 },
1844 {,
1845 "EventCode": "0x516082",
1846 "EventName": "PM_L2_RCLD_DISP_FAIL_ADDR",
1847 "BriefDescription": "L2 RC load dispatch attempt failed due to address collision with RC/CO/SN/SQ",
1848 "PublicDescription": ""
1849 },
1850 {,
1851 "EventCode": "0x526084",
1852 "EventName": "PM_L2_RCLD_DISP_FAIL_OTHER",
1853 "BriefDescription": "L2 RC load dispatch attempt failed due to other reasons",
1854 "PublicDescription": ""
1855 },
1856 {,
1857 "EventCode": "0x536088",
1858 "EventName": "PM_L2_RCST_DISP",
1859 "BriefDescription": "L2 RC store dispatch attempt",
1860 "PublicDescription": ""
1861 },
1862 {,
1863 "EventCode": "0x53608a",
1864 "EventName": "PM_L2_RCST_DISP_FAIL_ADDR",
1865 "BriefDescription": "L2 RC store dispatch attempt failed due to address collision with RC/CO/SN/SQ",
1866 "PublicDescription": ""
1867 },
1868 {,
1869 "EventCode": "0x54608c",
1870 "EventName": "PM_L2_RCST_DISP_FAIL_OTHER",
1871 "BriefDescription": "L2 RC store dispatch attempt failed due to other reasons",
1872 "PublicDescription": ""
1873 },
1874 {,
1875 "EventCode": "0x537088",
1876 "EventName": "PM_L2_RC_ST_DONE",
1877 "BriefDescription": "RC did st to line that was Tx or Sx",
1878 "PublicDescription": ""
1879 },
1880 {,
1881 "EventCode": "0x63708a",
1882 "EventName": "PM_L2_RTY_LD",
1883 "BriefDescription": "RC retries on PB for any load from core",
1884 "PublicDescription": ""
1885 },
1886 {,
1887 "EventCode": "0x3708a", 1713 "EventCode": "0x3708a",
1888 "EventName": "PM_L2_RTY_ST", 1714 "EventName": "PM_L2_RTY_ST",
1889 "BriefDescription": "RC retries on PB for any store from core", 1715 "BriefDescription": "RC retries on PB for any store from core",
1890 "PublicDescription": "" 1716 "PublicDescription": ""
1891 }, 1717 },
1892 {, 1718 {,
1893 "EventCode": "0x54708c",
1894 "EventName": "PM_L2_SN_M_RD_DONE",
1895 "BriefDescription": "SNP dispatched for a read and was M",
1896 "PublicDescription": ""
1897 },
1898 {,
1899 "EventCode": "0x54708e",
1900 "EventName": "PM_L2_SN_M_WR_DONE",
1901 "BriefDescription": "SNP dispatched for a write and was M",
1902 "PublicDescription": ""
1903 },
1904 {,
1905 "EventCode": "0x53708a",
1906 "EventName": "PM_L2_SN_SX_I_DONE",
1907 "BriefDescription": "SNP dispatched and went from Sx or Tx to Ix",
1908 "PublicDescription": ""
1909 },
1910 {,
1911 "EventCode": "0x17080", 1719 "EventCode": "0x17080",
1912 "EventName": "PM_L2_ST", 1720 "EventName": "PM_L2_ST",
1913 "BriefDescription": "All successful D-side store dispatches for this thread", 1721 "BriefDescription": "All successful D-side store dispatches for this thread",
1914 "PublicDescription": "" 1722 "PublicDescription": ""
1915 }, 1723 },
1916 {, 1724 {,
1917 "EventCode": "0x44708c",
1918 "EventName": "PM_L2_ST_DISP",
1919 "BriefDescription": "All successful store dispatches",
1920 "PublicDescription": ""
1921 },
1922 {,
1923 "EventCode": "0x44708e",
1924 "EventName": "PM_L2_ST_HIT",
1925 "BriefDescription": "All successful store dispatches that were L2Hits",
1926 "PublicDescription": ""
1927 },
1928 {,
1929 "EventCode": "0x17082", 1725 "EventCode": "0x17082",
1930 "EventName": "PM_L2_ST_MISS", 1726 "EventName": "PM_L2_ST_MISS",
1931 "BriefDescription": "All successful D-side store dispatches for this thread that were L2 Miss", 1727 "BriefDescription": "All successful D-side store dispatches for this thread that were L2 Miss",
1932 "PublicDescription": "" 1728 "PublicDescription": ""
1933 }, 1729 },
1934 {, 1730 {,
1935 "EventCode": "0x636088",
1936 "EventName": "PM_L2_SYS_GUESS_CORRECT",
1937 "BriefDescription": "L2 guess sys and guess was correct (ie data beyond-6chip)",
1938 "PublicDescription": ""
1939 },
1940 {,
1941 "EventCode": "0x63608a",
1942 "EventName": "PM_L2_SYS_GUESS_WRONG",
1943 "BriefDescription": "L2 guess sys and guess was not correct (ie data ^beyond-6chip)",
1944 "PublicDescription": ""
1945 },
1946 {,
1947 "EventCode": "0x617080",
1948 "EventName": "PM_L2_SYS_PUMP",
1949 "BriefDescription": "RC requests that were system pump attempts",
1950 "PublicDescription": ""
1951 },
1952 {,
1953 "EventCode": "0x1e05e", 1731 "EventCode": "0x1e05e",
1954 "EventName": "PM_L2_TM_REQ_ABORT", 1732 "EventName": "PM_L2_TM_REQ_ABORT",
1955 "BriefDescription": "TM abort", 1733 "BriefDescription": "TM abort",
@@ -1962,36 +1740,12 @@
1962 "PublicDescription": "" 1740 "PublicDescription": ""
1963 }, 1741 },
1964 {, 1742 {,
1965 "EventCode": "0x23808a",
1966 "EventName": "PM_L3_CINJ",
1967 "BriefDescription": "l3 ci of cache inject",
1968 "PublicDescription": ""
1969 },
1970 {,
1971 "EventCode": "0x128084",
1972 "EventName": "PM_L3_CI_HIT",
1973 "BriefDescription": "L3 Castins Hit (total count",
1974 "PublicDescription": ""
1975 },
1976 {,
1977 "EventCode": "0x128086",
1978 "EventName": "PM_L3_CI_MISS",
1979 "BriefDescription": "L3 castins miss (total count",
1980 "PublicDescription": ""
1981 },
1982 {,
1983 "EventCode": "0x819082", 1743 "EventCode": "0x819082",
1984 "EventName": "PM_L3_CI_USAGE", 1744 "EventName": "PM_L3_CI_USAGE",
1985 "BriefDescription": "rotating sample of 16 CI or CO actives", 1745 "BriefDescription": "rotating sample of 16 CI or CO actives",
1986 "PublicDescription": "" 1746 "PublicDescription": ""
1987 }, 1747 },
1988 {, 1748 {,
1989 "EventCode": "0x438088",
1990 "EventName": "PM_L3_CO",
1991 "BriefDescription": "l3 castout occurring ( does not include casthrough or log writes (cinj/dmaw)",
1992 "PublicDescription": ""
1993 },
1994 {,
1995 "EventCode": "0x83908b", 1749 "EventCode": "0x83908b",
1996 "EventName": "PM_L3_CO0_ALLOC", 1750 "EventName": "PM_L3_CO0_ALLOC",
1997 "BriefDescription": "lifetime, sample of CO machine 0 valid", 1751 "BriefDescription": "lifetime, sample of CO machine 0 valid",
@@ -2010,120 +1764,18 @@
2010 "PublicDescription": "" 1764 "PublicDescription": ""
2011 }, 1765 },
2012 {, 1766 {,
2013 "EventCode": "0x238088",
2014 "EventName": "PM_L3_CO_LCO",
2015 "BriefDescription": "Total L3 castouts occurred on LCO",
2016 "PublicDescription": ""
2017 },
2018 {,
2019 "EventCode": "0x28084", 1767 "EventCode": "0x28084",
2020 "EventName": "PM_L3_CO_MEM", 1768 "EventName": "PM_L3_CO_MEM",
2021 "BriefDescription": "L3 CO to memory OR of port 0 and 1 ( lossy)", 1769 "BriefDescription": "L3 CO to memory OR of port 0 and 1 ( lossy)",
2022 "PublicDescription": "" 1770 "PublicDescription": ""
2023 }, 1771 },
2024 {, 1772 {,
2025 "EventCode": "0xb19082",
2026 "EventName": "PM_L3_GRP_GUESS_CORRECT",
2027 "BriefDescription": "Initial scope=group and data from same group (near) (pred successful)",
2028 "PublicDescription": ""
2029 },
2030 {,
2031 "EventCode": "0xb3908a",
2032 "EventName": "PM_L3_GRP_GUESS_WRONG_HIGH",
2033 "BriefDescription": "Initial scope=group but data from local node. Predition too high",
2034 "PublicDescription": ""
2035 },
2036 {,
2037 "EventCode": "0xb39088",
2038 "EventName": "PM_L3_GRP_GUESS_WRONG_LOW",
2039 "BriefDescription": "Initial scope=group but data from outside group (far or rem). Prediction too Low",
2040 "PublicDescription": ""
2041 },
2042 {,
2043 "EventCode": "0x218080",
2044 "EventName": "PM_L3_HIT",
2045 "BriefDescription": "L3 Hits",
2046 "PublicDescription": ""
2047 },
2048 {,
2049 "EventCode": "0x138088",
2050 "EventName": "PM_L3_L2_CO_HIT",
2051 "BriefDescription": "L2 castout hits",
2052 "PublicDescription": ""
2053 },
2054 {,
2055 "EventCode": "0x13808a",
2056 "EventName": "PM_L3_L2_CO_MISS",
2057 "BriefDescription": "L2 castout miss",
2058 "PublicDescription": ""
2059 },
2060 {,
2061 "EventCode": "0x14808c",
2062 "EventName": "PM_L3_LAT_CI_HIT",
2063 "BriefDescription": "L3 Lateral Castins Hit",
2064 "PublicDescription": ""
2065 },
2066 {,
2067 "EventCode": "0x14808e",
2068 "EventName": "PM_L3_LAT_CI_MISS",
2069 "BriefDescription": "L3 Lateral Castins Miss",
2070 "PublicDescription": ""
2071 },
2072 {,
2073 "EventCode": "0x228084",
2074 "EventName": "PM_L3_LD_HIT",
2075 "BriefDescription": "L3 demand LD Hits",
2076 "PublicDescription": ""
2077 },
2078 {,
2079 "EventCode": "0x228086",
2080 "EventName": "PM_L3_LD_MISS",
2081 "BriefDescription": "L3 demand LD Miss",
2082 "PublicDescription": ""
2083 },
2084 {,
2085 "EventCode": "0x1e052", 1773 "EventCode": "0x1e052",
2086 "EventName": "PM_L3_LD_PREF", 1774 "EventName": "PM_L3_LD_PREF",
2087 "BriefDescription": "L3 Load Prefetches", 1775 "BriefDescription": "L3 Load Prefetches",
2088 "PublicDescription": "" 1776 "PublicDescription": ""
2089 }, 1777 },
2090 {, 1778 {,
2091 "EventCode": "0xb19080",
2092 "EventName": "PM_L3_LOC_GUESS_CORRECT",
2093 "BriefDescription": "initial scope=node/chip and data from local node (local) (pred successful)",
2094 "PublicDescription": ""
2095 },
2096 {,
2097 "EventCode": "0xb29086",
2098 "EventName": "PM_L3_LOC_GUESS_WRONG",
2099 "BriefDescription": "Initial scope=node but data from out side local node (near or far or rem). Prediction too Low",
2100 "PublicDescription": ""
2101 },
2102 {,
2103 "EventCode": "0x218082",
2104 "EventName": "PM_L3_MISS",
2105 "BriefDescription": "L3 Misses",
2106 "PublicDescription": ""
2107 },
2108 {,
2109 "EventCode": "0x54808c",
2110 "EventName": "PM_L3_P0_CO_L31",
2111 "BriefDescription": "l3 CO to L3.1 (lco) port 0",
2112 "PublicDescription": ""
2113 },
2114 {,
2115 "EventCode": "0x538088",
2116 "EventName": "PM_L3_P0_CO_MEM",
2117 "BriefDescription": "l3 CO to memory port 0",
2118 "PublicDescription": ""
2119 },
2120 {,
2121 "EventCode": "0x929084",
2122 "EventName": "PM_L3_P0_CO_RTY",
2123 "BriefDescription": "L3 CO received retry port 0",
2124 "PublicDescription": ""
2125 },
2126 {,
2127 "EventCode": "0xa29084", 1779 "EventCode": "0xa29084",
2128 "EventName": "PM_L3_P0_GRP_PUMP", 1780 "EventName": "PM_L3_P0_GRP_PUMP",
2129 "BriefDescription": "L3 pf sent with grp scope port 0", 1781 "BriefDescription": "L3 pf sent with grp scope port 0",
@@ -2148,120 +1800,6 @@
2148 "PublicDescription": "" 1800 "PublicDescription": ""
2149 }, 1801 },
2150 {, 1802 {,
2151 "EventCode": "0xa19080",
2152 "EventName": "PM_L3_P0_NODE_PUMP",
2153 "BriefDescription": "L3 pf sent with nodal scope port 0",
2154 "PublicDescription": ""
2155 },
2156 {,
2157 "EventCode": "0x919080",
2158 "EventName": "PM_L3_P0_PF_RTY",
2159 "BriefDescription": "L3 PF received retry port 0",
2160 "PublicDescription": ""
2161 },
2162 {,
2163 "EventCode": "0x939088",
2164 "EventName": "PM_L3_P0_SN_HIT",
2165 "BriefDescription": "L3 snoop hit port 0",
2166 "PublicDescription": ""
2167 },
2168 {,
2169 "EventCode": "0x118080",
2170 "EventName": "PM_L3_P0_SN_INV",
2171 "BriefDescription": "Port0 snooper detects someone doing a store to a line thats Sx",
2172 "PublicDescription": ""
2173 },
2174 {,
2175 "EventCode": "0x94908c",
2176 "EventName": "PM_L3_P0_SN_MISS",
2177 "BriefDescription": "L3 snoop miss port 0",
2178 "PublicDescription": ""
2179 },
2180 {,
2181 "EventCode": "0xa39088",
2182 "EventName": "PM_L3_P0_SYS_PUMP",
2183 "BriefDescription": "L3 pf sent with sys scope port 0",
2184 "PublicDescription": ""
2185 },
2186 {,
2187 "EventCode": "0x54808e",
2188 "EventName": "PM_L3_P1_CO_L31",
2189 "BriefDescription": "l3 CO to L3.1 (lco) port 1",
2190 "PublicDescription": ""
2191 },
2192 {,
2193 "EventCode": "0x53808a",
2194 "EventName": "PM_L3_P1_CO_MEM",
2195 "BriefDescription": "l3 CO to memory port 1",
2196 "PublicDescription": ""
2197 },
2198 {,
2199 "EventCode": "0x929086",
2200 "EventName": "PM_L3_P1_CO_RTY",
2201 "BriefDescription": "L3 CO received retry port 1",
2202 "PublicDescription": ""
2203 },
2204 {,
2205 "EventCode": "0xa29086",
2206 "EventName": "PM_L3_P1_GRP_PUMP",
2207 "BriefDescription": "L3 pf sent with grp scope port 1",
2208 "PublicDescription": ""
2209 },
2210 {,
2211 "EventCode": "0x528086",
2212 "EventName": "PM_L3_P1_LCO_DATA",
2213 "BriefDescription": "lco sent with data port 1",
2214 "PublicDescription": ""
2215 },
2216 {,
2217 "EventCode": "0x518082",
2218 "EventName": "PM_L3_P1_LCO_NO_DATA",
2219 "BriefDescription": "dataless l3 lco sent port 1",
2220 "PublicDescription": ""
2221 },
2222 {,
2223 "EventCode": "0xa4908e",
2224 "EventName": "PM_L3_P1_LCO_RTY",
2225 "BriefDescription": "L3 LCO received retry port 1",
2226 "PublicDescription": ""
2227 },
2228 {,
2229 "EventCode": "0xa19082",
2230 "EventName": "PM_L3_P1_NODE_PUMP",
2231 "BriefDescription": "L3 pf sent with nodal scope port 1",
2232 "PublicDescription": ""
2233 },
2234 {,
2235 "EventCode": "0x919082",
2236 "EventName": "PM_L3_P1_PF_RTY",
2237 "BriefDescription": "L3 PF received retry port 1",
2238 "PublicDescription": ""
2239 },
2240 {,
2241 "EventCode": "0x93908a",
2242 "EventName": "PM_L3_P1_SN_HIT",
2243 "BriefDescription": "L3 snoop hit port 1",
2244 "PublicDescription": ""
2245 },
2246 {,
2247 "EventCode": "0x118082",
2248 "EventName": "PM_L3_P1_SN_INV",
2249 "BriefDescription": "Port1 snooper detects someone doing a store to a line thats Sx",
2250 "PublicDescription": ""
2251 },
2252 {,
2253 "EventCode": "0x94908e",
2254 "EventName": "PM_L3_P1_SN_MISS",
2255 "BriefDescription": "L3 snoop miss port 1",
2256 "PublicDescription": ""
2257 },
2258 {,
2259 "EventCode": "0xa3908a",
2260 "EventName": "PM_L3_P1_SYS_PUMP",
2261 "BriefDescription": "L3 pf sent with sys scope port 1",
2262 "PublicDescription": ""
2263 },
2264 {,
2265 "EventCode": "0x84908d", 1803 "EventCode": "0x84908d",
2266 "EventName": "PM_L3_PF0_ALLOC", 1804 "EventName": "PM_L3_PF0_ALLOC",
2267 "BriefDescription": "lifetime, sample of PF machine 0 valid", 1805 "BriefDescription": "lifetime, sample of PF machine 0 valid",
@@ -2274,12 +1812,6 @@
2274 "PublicDescription": "" 1812 "PublicDescription": ""
2275 }, 1813 },
2276 {, 1814 {,
2277 "EventCode": "0x428084",
2278 "EventName": "PM_L3_PF_HIT_L3",
2279 "BriefDescription": "l3 pf hit in l3",
2280 "PublicDescription": ""
2281 },
2282 {,
2283 "EventCode": "0x18080", 1815 "EventCode": "0x18080",
2284 "EventName": "PM_L3_PF_MISS_L3", 1816 "EventName": "PM_L3_PF_MISS_L3",
2285 "BriefDescription": "L3 Prefetch missed in L3", 1817 "BriefDescription": "L3 Prefetch missed in L3",
@@ -2370,42 +1902,12 @@
2370 "PublicDescription": "" 1902 "PublicDescription": ""
2371 }, 1903 },
2372 {, 1904 {,
2373 "EventCode": "0xb29084",
2374 "EventName": "PM_L3_SYS_GUESS_CORRECT",
2375 "BriefDescription": "Initial scope=system and data from outside group (far or rem)(pred successful)",
2376 "PublicDescription": ""
2377 },
2378 {,
2379 "EventCode": "0xb4908c",
2380 "EventName": "PM_L3_SYS_GUESS_WRONG",
2381 "BriefDescription": "Initial scope=system but data from local or near. Predction too high",
2382 "PublicDescription": ""
2383 },
2384 {,
2385 "EventCode": "0x24808e",
2386 "EventName": "PM_L3_TRANS_PF",
2387 "BriefDescription": "L3 Transient prefetch",
2388 "PublicDescription": ""
2389 },
2390 {,
2391 "EventCode": "0x18081", 1905 "EventCode": "0x18081",
2392 "EventName": "PM_L3_WI0_ALLOC", 1906 "EventName": "PM_L3_WI0_ALLOC",
2393 "BriefDescription": "lifetime, sample of Write Inject machine 0 valid", 1907 "BriefDescription": "lifetime, sample of Write Inject machine 0 valid",
2394 "PublicDescription": "0.0" 1908 "PublicDescription": "0.0"
2395 }, 1909 },
2396 {, 1910 {,
2397 "EventCode": "0x418080",
2398 "EventName": "PM_L3_WI0_BUSY",
2399 "BriefDescription": "lifetime, sample of Write Inject machine 0 valid",
2400 "PublicDescription": ""
2401 },
2402 {,
2403 "EventCode": "0x418082",
2404 "EventName": "PM_L3_WI_USAGE",
2405 "BriefDescription": "rotating sample of 8 WI actives",
2406 "PublicDescription": ""
2407 },
2408 {,
2409 "EventCode": "0xc080", 1911 "EventCode": "0xc080",
2410 "EventName": "PM_LD_REF_L1_LSU0", 1912 "EventName": "PM_LD_REF_L1_LSU0",
2411 "BriefDescription": "LS0 L1 D cache load references counted at finish, gated by reject", 1913 "BriefDescription": "LS0 L1 D cache load references counted at finish, gated by reject",
@@ -3312,12 +2814,6 @@
3312 "PublicDescription": "" 2814 "PublicDescription": ""
3313 }, 2815 },
3314 {, 2816 {,
3315 "EventCode": "0x328084",
3316 "EventName": "PM_NON_TM_RST_SC",
3317 "BriefDescription": "non tm snp rst tm sc",
3318 "PublicDescription": ""
3319 },
3320 {,
3321 "EventCode": "0x2001a", 2817 "EventCode": "0x2001a",
3322 "EventName": "PM_NTCG_ALL_FIN", 2818 "EventName": "PM_NTCG_ALL_FIN",
3323 "BriefDescription": "Cycles after all instructions have finished to group completed", 2819 "BriefDescription": "Cycles after all instructions have finished to group completed",
@@ -3420,24 +2916,6 @@
3420 "PublicDescription": "" 2916 "PublicDescription": ""
3421 }, 2917 },
3422 {, 2918 {,
3423 "EventCode": "0x34808e",
3424 "EventName": "PM_RD_CLEARING_SC",
3425 "BriefDescription": "rd clearing sc",
3426 "PublicDescription": ""
3427 },
3428 {,
3429 "EventCode": "0x34808c",
3430 "EventName": "PM_RD_FORMING_SC",
3431 "BriefDescription": "rd forming sc",
3432 "PublicDescription": ""
3433 },
3434 {,
3435 "EventCode": "0x428086",
3436 "EventName": "PM_RD_HIT_PF",
3437 "BriefDescription": "rd machine hit l3 pf machine",
3438 "PublicDescription": ""
3439 },
3440 {,
3441 "EventCode": "0x20004", 2919 "EventCode": "0x20004",
3442 "EventName": "PM_REAL_SRQ_FULL", 2920 "EventName": "PM_REAL_SRQ_FULL",
3443 "BriefDescription": "Out of real srq entries", 2921 "BriefDescription": "Out of real srq entries",
@@ -3504,18 +2982,6 @@
3504 "PublicDescription": "TLBIE snoopSnoop TLBIE" 2982 "PublicDescription": "TLBIE snoopSnoop TLBIE"
3505 }, 2983 },
3506 {, 2984 {,
3507 "EventCode": "0x338088",
3508 "EventName": "PM_SNP_TM_HIT_M",
3509 "BriefDescription": "snp tm st hit m mu",
3510 "PublicDescription": ""
3511 },
3512 {,
3513 "EventCode": "0x33808a",
3514 "EventName": "PM_SNP_TM_HIT_T",
3515 "BriefDescription": "snp tm_st_hit t tn te",
3516 "PublicDescription": ""
3517 },
3518 {,
3519 "EventCode": "0x4608c", 2985 "EventCode": "0x4608c",
3520 "EventName": "PM_SN_USAGE", 2986 "EventName": "PM_SN_USAGE",
3521 "BriefDescription": "Continuous 16 cycle(2to1) window where this signals rotates thru sampling each L2 SN machine busy. PMU uses this wave to then do 16 cyc count to sample total number of machs running", 2987 "BriefDescription": "Continuous 16 cycle(2to1) window where this signals rotates thru sampling each L2 SN machine busy. PMU uses this wave to then do 16 cyc count to sample total number of machs running",
@@ -3534,12 +3000,6 @@
3534 "PublicDescription": "STCX executed reported at sent to nest42" 3000 "PublicDescription": "STCX executed reported at sent to nest42"
3535 }, 3001 },
3536 {, 3002 {,
3537 "EventCode": "0x717080",
3538 "EventName": "PM_ST_CAUSED_FAIL",
3539 "BriefDescription": "Non TM St caused any thread to fail",
3540 "PublicDescription": ""
3541 },
3542 {,
3543 "EventCode": "0x3090", 3003 "EventCode": "0x3090",
3544 "EventName": "PM_SWAP_CANCEL", 3004 "EventName": "PM_SWAP_CANCEL",
3545 "BriefDescription": "SWAP cancel , rtag not available", 3005 "BriefDescription": "SWAP cancel , rtag not available",
@@ -3624,18 +3084,6 @@
3624 "PublicDescription": "" 3084 "PublicDescription": ""
3625 }, 3085 },
3626 {, 3086 {,
3627 "EventCode": "0x318082",
3628 "EventName": "PM_TM_CAM_OVERFLOW",
3629 "BriefDescription": "l3 tm cam overflow during L2 co of SC",
3630 "PublicDescription": ""
3631 },
3632 {,
3633 "EventCode": "0x74708c",
3634 "EventName": "PM_TM_CAP_OVERFLOW",
3635 "BriefDescription": "TM Footprint Capactiy Overflow",
3636 "PublicDescription": ""
3637 },
3638 {,
3639 "EventCode": "0x20ba", 3087 "EventCode": "0x20ba",
3640 "EventName": "PM_TM_END_ALL", 3088 "EventName": "PM_TM_END_ALL",
3641 "BriefDescription": "Tm any tend", 3089 "BriefDescription": "Tm any tend",
@@ -3690,48 +3138,6 @@
3690 "PublicDescription": "Transactional conflict from LSU, whatever gets reported to texas 42" 3138 "PublicDescription": "Transactional conflict from LSU, whatever gets reported to texas 42"
3691 }, 3139 },
3692 {, 3140 {,
3693 "EventCode": "0x727086",
3694 "EventName": "PM_TM_FAV_CAUSED_FAIL",
3695 "BriefDescription": "TM Load (fav) caused another thread to fail",
3696 "PublicDescription": ""
3697 },
3698 {,
3699 "EventCode": "0x717082",
3700 "EventName": "PM_TM_LD_CAUSED_FAIL",
3701 "BriefDescription": "Non TM Ld caused any thread to fail",
3702 "PublicDescription": ""
3703 },
3704 {,
3705 "EventCode": "0x727084",
3706 "EventName": "PM_TM_LD_CONF",
3707 "BriefDescription": "TM Load (fav or non-fav) ran into conflict (failed)",
3708 "PublicDescription": ""
3709 },
3710 {,
3711 "EventCode": "0x328086",
3712 "EventName": "PM_TM_RST_SC",
3713 "BriefDescription": "tm snp rst tm sc",
3714 "PublicDescription": ""
3715 },
3716 {,
3717 "EventCode": "0x318080",
3718 "EventName": "PM_TM_SC_CO",
3719 "BriefDescription": "l3 castout tm Sc line",
3720 "PublicDescription": ""
3721 },
3722 {,
3723 "EventCode": "0x73708a",
3724 "EventName": "PM_TM_ST_CAUSED_FAIL",
3725 "BriefDescription": "TM Store (fav or non-fav) caused another thread to fail",
3726 "PublicDescription": ""
3727 },
3728 {,
3729 "EventCode": "0x737088",
3730 "EventName": "PM_TM_ST_CONF",
3731 "BriefDescription": "TM Store (fav or non-fav) ran into conflict (failed)",
3732 "PublicDescription": ""
3733 },
3734 {,
3735 "EventCode": "0x20bc", 3141 "EventCode": "0x20bc",
3736 "EventName": "PM_TM_TBEGIN", 3142 "EventName": "PM_TM_TBEGIN",
3737 "BriefDescription": "Tm nested tbegin", 3143 "BriefDescription": "Tm nested tbegin",
diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/branch.json b/tools/perf/pmu-events/arch/x86/amdfam17h/branch.json
new file mode 100644
index 000000000000..93ddfd8053ca
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/branch.json
@@ -0,0 +1,12 @@
1[
2 {
3 "EventName": "bp_l1_btb_correct",
4 "EventCode": "0x8a",
5 "BriefDescription": "L1 BTB Correction."
6 },
7 {
8 "EventName": "bp_l2_btb_correct",
9 "EventCode": "0x8b",
10 "BriefDescription": "L2 BTB Correction."
11 }
12]
diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/cache.json b/tools/perf/pmu-events/arch/x86/amdfam17h/cache.json
new file mode 100644
index 000000000000..fad4af9142cb
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/cache.json
@@ -0,0 +1,287 @@
1[
2 {
3 "EventName": "ic_fw32",
4 "EventCode": "0x80",
5 "BriefDescription": "The number of 32B fetch windows transferred from IC pipe to DE instruction decoder (includes non-cacheable and cacheable fill responses)."
6 },
7 {
8 "EventName": "ic_fw32_miss",
9 "EventCode": "0x81",
10 "BriefDescription": "The number of 32B fetch windows tried to read the L1 IC and missed in the full tag."
11 },
12 {
13 "EventName": "ic_cache_fill_l2",
14 "EventCode": "0x82",
15 "BriefDescription": "The number of 64 byte instruction cache line was fulfilled from the L2 cache."
16 },
17 {
18 "EventName": "ic_cache_fill_sys",
19 "EventCode": "0x83",
20 "BriefDescription": "The number of 64 byte instruction cache line fulfilled from system memory or another cache."
21 },
22 {
23 "EventName": "bp_l1_tlb_miss_l2_hit",
24 "EventCode": "0x84",
25 "BriefDescription": "The number of instruction fetches that miss in the L1 ITLB but hit in the L2 ITLB."
26 },
27 {
28 "EventName": "bp_l1_tlb_miss_l2_miss",
29 "EventCode": "0x85",
30 "BriefDescription": "The number of instruction fetches that miss in both the L1 and L2 TLBs."
31 },
32 {
33 "EventName": "bp_snp_re_sync",
34 "EventCode": "0x86",
35 "BriefDescription": "The number of pipeline restarts caused by invalidating probes that hit on the instruction stream currently being executed. This would happen if the active instruction stream was being modified by another processor in an MP system - typically a highly unlikely event."
36 },
37 {
38 "EventName": "ic_fetch_stall.ic_stall_any",
39 "EventCode": "0x87",
40 "BriefDescription": "IC pipe was stalled during this clock cycle for any reason (nothing valid in pipe ICM1).",
41 "PublicDescription": "Instruction Pipe Stall. IC pipe was stalled during this clock cycle for any reason (nothing valid in pipe ICM1).",
42 "UMask": "0x4"
43 },
44 {
45 "EventName": "ic_fetch_stall.ic_stall_dq_empty",
46 "EventCode": "0x87",
47 "BriefDescription": "IC pipe was stalled during this clock cycle (including IC to OC fetches) due to DQ empty.",
48 "PublicDescription": "Instruction Pipe Stall. IC pipe was stalled during this clock cycle (including IC to OC fetches) due to DQ empty.",
49 "UMask": "0x2"
50 },
51 {
52 "EventName": "ic_fetch_stall.ic_stall_back_pressure",
53 "EventCode": "0x87",
54 "BriefDescription": "IC pipe was stalled during this clock cycle (including IC to OC fetches) due to back-pressure.",
55 "PublicDescription": "Instruction Pipe Stall. IC pipe was stalled during this clock cycle (including IC to OC fetches) due to back-pressure.",
56 "UMask": "0x1"
57 },
58 {
59 "EventName": "ic_cache_inval.l2_invalidating_probe",
60 "EventCode": "0x8c",
61 "BriefDescription": "IC line invalidated due to L2 invalidating probe (external or LS).",
62 "PublicDescription": "The number of instruction cache lines invalidated. A non-SMC event is CMC (cross modifying code), either from the other thread of the core or another core. IC line invalidated due to L2 invalidating probe (external or LS).",
63 "UMask": "0x2"
64 },
65 {
66 "EventName": "ic_cache_inval.fill_invalidated",
67 "EventCode": "0x8c",
68 "BriefDescription": "IC line invalidated due to overwriting fill response.",
69 "PublicDescription": "The number of instruction cache lines invalidated. A non-SMC event is CMC (cross modifying code), either from the other thread of the core or another core. IC line invalidated due to overwriting fill response.",
70 "UMask": "0x1"
71 },
72 {
73 "EventName": "bp_tlb_rel",
74 "EventCode": "0x99",
75 "BriefDescription": "The number of ITLB reload requests."
76 },
77 {
78 "EventName": "l2_request_g1.rd_blk_l",
79 "EventCode": "0x60",
80 "BriefDescription": "Requests to L2 Group1.",
81 "PublicDescription": "Requests to L2 Group1.",
82 "UMask": "0x80"
83 },
84 {
85 "EventName": "l2_request_g1.rd_blk_x",
86 "EventCode": "0x60",
87 "BriefDescription": "Requests to L2 Group1.",
88 "PublicDescription": "Requests to L2 Group1.",
89 "UMask": "0x40"
90 },
91 {
92 "EventName": "l2_request_g1.ls_rd_blk_c_s",
93 "EventCode": "0x60",
94 "BriefDescription": "Requests to L2 Group1.",
95 "PublicDescription": "Requests to L2 Group1.",
96 "UMask": "0x20"
97 },
98 {
99 "EventName": "l2_request_g1.cacheable_ic_read",
100 "EventCode": "0x60",
101 "BriefDescription": "Requests to L2 Group1.",
102 "PublicDescription": "Requests to L2 Group1.",
103 "UMask": "0x10"
104 },
105 {
106 "EventName": "l2_request_g1.change_to_x",
107 "EventCode": "0x60",
108 "BriefDescription": "Requests to L2 Group1.",
109 "PublicDescription": "Requests to L2 Group1.",
110 "UMask": "0x8"
111 },
112 {
113 "EventName": "l2_request_g1.prefetch_l2",
114 "EventCode": "0x60",
115 "BriefDescription": "Requests to L2 Group1.",
116 "PublicDescription": "Requests to L2 Group1.",
117 "UMask": "0x4"
118 },
119 {
120 "EventName": "l2_request_g1.l2_hw_pf",
121 "EventCode": "0x60",
122 "BriefDescription": "Requests to L2 Group1.",
123 "PublicDescription": "Requests to L2 Group1.",
124 "UMask": "0x2"
125 },
126 {
127 "EventName": "l2_request_g1.other_requests",
128 "EventCode": "0x60",
129 "BriefDescription": "Events covered by l2_request_g2.",
130 "PublicDescription": "Requests to L2 Group1. Events covered by l2_request_g2.",
131 "UMask": "0x1"
132 },
133 {
134 "EventName": "l2_request_g2.group1",
135 "EventCode": "0x61",
136 "BriefDescription": "All Group 1 commands not in unit0.",
137 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous. All Group 1 commands not in unit0.",
138 "UMask": "0x80"
139 },
140 {
141 "EventName": "l2_request_g2.ls_rd_sized",
142 "EventCode": "0x61",
143 "BriefDescription": "RdSized, RdSized32, RdSized64.",
144 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous. RdSized, RdSized32, RdSized64.",
145 "UMask": "0x40"
146 },
147 {
148 "EventName": "l2_request_g2.ls_rd_sized_nc",
149 "EventCode": "0x61",
150 "BriefDescription": "RdSizedNC, RdSized32NC, RdSized64NC.",
151 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous. RdSizedNC, RdSized32NC, RdSized64NC.",
152 "UMask": "0x20"
153 },
154 {
155 "EventName": "l2_request_g2.ic_rd_sized",
156 "EventCode": "0x61",
157 "BriefDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
158 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
159 "UMask": "0x10"
160 },
161 {
162 "EventName": "l2_request_g2.ic_rd_sized_nc",
163 "EventCode": "0x61",
164 "BriefDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
165 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
166 "UMask": "0x8"
167 },
168 {
169 "EventName": "l2_request_g2.smc_inval",
170 "EventCode": "0x61",
171 "BriefDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
172 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
173 "UMask": "0x4"
174 },
175 {
176 "EventName": "l2_request_g2.bus_locks_originator",
177 "EventCode": "0x61",
178 "BriefDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
179 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
180 "UMask": "0x2"
181 },
182 {
183 "EventName": "l2_request_g2.bus_locks_responses",
184 "EventCode": "0x61",
185 "BriefDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
186 "PublicDescription": "Multi-events in that LS and IF requests can be received simultaneous.",
187 "UMask": "0x1"
188 },
189 {
190 "EventName": "l2_latency.l2_cycles_waiting_on_fills",
191 "EventCode": "0x62",
192 "BriefDescription": "Total cycles spent waiting for L2 fills to complete from L3 or memory, divided by four. Event counts are for both threads. To calculate average latency, the number of fills from both threads must be used.",
193 "PublicDescription": "Total cycles spent waiting for L2 fills to complete from L3 or memory, divided by four. Event counts are for both threads. To calculate average latency, the number of fills from both threads must be used.",
194 "UMask": "0x1"
195 },
196 {
197 "EventName": "l2_wcb_req.wcb_write",
198 "EventCode": "0x63",
199 "PublicDescription": "LS (Load/Store unit) to L2 WCB (Write Combining Buffer) write requests.",
200 "BriefDescription": "LS to L2 WCB write requests.",
201 "UMask": "0x40"
202 },
203 {
204 "EventName": "l2_wcb_req.wcb_close",
205 "EventCode": "0x63",
206 "BriefDescription": "LS to L2 WCB close requests.",
207 "PublicDescription": "LS (Load/Store unit) to L2 WCB (Write Combining Buffer) close requests.",
208 "UMask": "0x20"
209 },
210 {
211 "EventName": "l2_wcb_req.zero_byte_store",
212 "EventCode": "0x63",
213 "BriefDescription": "LS to L2 WCB zero byte store requests.",
214 "PublicDescription": "LS (Load/Store unit) to L2 WCB (Write Combining Buffer) zero byte store requests.",
215 "UMask": "0x4"
216 },
217 {
218 "EventName": "l2_wcb_req.cl_zero",
219 "EventCode": "0x63",
220 "PublicDescription": "LS to L2 WCB cache line zeroing requests.",
221 "BriefDescription": "LS (Load/Store unit) to L2 WCB (Write Combining Buffer) cache line zeroing requests.",
222 "UMask": "0x1"
223 },
224 {
225 "EventName": "l2_cache_req_stat.ls_rd_blk_cs",
226 "EventCode": "0x64",
227 "BriefDescription": "LS ReadBlock C/S Hit.",
228 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. LS ReadBlock C/S Hit.",
229 "UMask": "0x80"
230 },
231 {
232 "EventName": "l2_cache_req_stat.ls_rd_blk_l_hit_x",
233 "EventCode": "0x64",
234 "BriefDescription": "LS Read Block L Hit X.",
235 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. LS Read Block L Hit X.",
236 "UMask": "0x40"
237 },
238 {
239 "EventName": "l2_cache_req_stat.ls_rd_blk_l_hit_s",
240 "EventCode": "0x64",
241 "BriefDescription": "LsRdBlkL Hit Shared.",
242 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. LsRdBlkL Hit Shared.",
243 "UMask": "0x20"
244 },
245 {
246 "EventName": "l2_cache_req_stat.ls_rd_blk_x",
247 "EventCode": "0x64",
248 "BriefDescription": "LsRdBlkX/ChgToX Hit X. Count RdBlkX finding Shared as a Miss.",
249 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. LsRdBlkX/ChgToX Hit X. Count RdBlkX finding Shared as a Miss.",
250 "UMask": "0x10"
251 },
252 {
253 "EventName": "l2_cache_req_stat.ls_rd_blk_c",
254 "EventCode": "0x64",
255 "BriefDescription": "LS Read Block C S L X Change to X Miss.",
256 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. LS Read Block C S L X Change to X Miss.",
257 "UMask": "0x8"
258 },
259 {
260 "EventName": "l2_cache_req_stat.ic_fill_hit_x",
261 "EventCode": "0x64",
262 "BriefDescription": "IC Fill Hit Exclusive Stale.",
263 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. IC Fill Hit Exclusive Stale.",
264 "UMask": "0x4"
265 },
266 {
267 "EventName": "l2_cache_req_stat.ic_fill_hit_s",
268 "EventCode": "0x64",
269 "BriefDescription": "IC Fill Hit Shared.",
270 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. IC Fill Hit Shared.",
271 "UMask": "0x2"
272 },
273 {
274 "EventName": "l2_cache_req_stat.ic_fill_miss",
275 "EventCode": "0x64",
276 "BriefDescription": "IC Fill Miss.",
277 "PublicDescription": "This event does not count accesses to the L2 cache by the L2 prefetcher, but it does count accesses by the L1 prefetcher. IC Fill Miss.",
278 "UMask": "0x1"
279 },
280 {
281 "EventName": "l2_fill_pending.l2_fill_busy",
282 "EventCode": "0x6d",
283 "BriefDescription": "Total cycles spent with one or more fill requests in flight from L2.",
284 "PublicDescription": "Total cycles spent with one or more fill requests in flight from L2.",
285 "UMask": "0x1"
286 }
287]
diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/core.json b/tools/perf/pmu-events/arch/x86/amdfam17h/core.json
new file mode 100644
index 000000000000..7b285b0a7f35
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/core.json
@@ -0,0 +1,134 @@
1[
2 {
3 "EventName": "ex_ret_instr",
4 "EventCode": "0xc0",
5 "BriefDescription": "Retired Instructions."
6 },
7 {
8 "EventName": "ex_ret_cops",
9 "EventCode": "0xc1",
10 "BriefDescription": "Retired Uops.",
11 "PublicDescription": "The number of uOps retired. This includes all processor activity (instructions, exceptions, interrupts, microcode assists, etc.). The number of events logged per cycle can vary from 0 to 4."
12 },
13 {
14 "EventName": "ex_ret_brn",
15 "EventCode": "0xc2",
16 "BriefDescription": "[Retired Branch Instructions.",
17 "PublicDescription": "The number of branch instructions retired. This includes all types of architectural control flow changes, including exceptions and interrupts."
18 },
19 {
20 "EventName": "ex_ret_brn_misp",
21 "EventCode": "0xc3",
22 "BriefDescription": "Retired Branch Instructions Mispredicted.",
23 "PublicDescription": "The number of branch instructions retired, of any type, that were not correctly predicted. This includes those for which prediction is not attempted (far control transfers, exceptions and interrupts)."
24 },
25 {
26 "EventName": "ex_ret_brn_tkn",
27 "EventCode": "0xc4",
28 "BriefDescription": "Retired Taken Branch Instructions.",
29 "PublicDescription": "The number of taken branches that were retired. This includes all types of architectural control flow changes, including exceptions and interrupts."
30 },
31 {
32 "EventName": "ex_ret_brn_tkn_misp",
33 "EventCode": "0xc5",
34 "BriefDescription": "Retired Taken Branch Instructions Mispredicted.",
35 "PublicDescription": "The number of retired taken branch instructions that were mispredicted."
36 },
37 {
38 "EventName": "ex_ret_brn_far",
39 "EventCode": "0xc6",
40 "BriefDescription": "Retired Far Control Transfers.",
41 "PublicDescription": "The number of far control transfers retired including far call/jump/return, IRET, SYSCALL and SYSRET, plus exceptions and interrupts. Far control transfers are not subject to branch prediction."
42 },
43 {
44 "EventName": "ex_ret_brn_resync",
45 "EventCode": "0xc7",
46 "BriefDescription": "Retired Branch Resyncs.",
47 "PublicDescription": "The number of resync branches. These reflect pipeline restarts due to certain microcode assists and events such as writes to the active instruction stream, among other things. Each occurrence reflects a restart penalty similar to a branch mispredict. This is relatively rare."
48 },
49 {
50 "EventName": "ex_ret_near_ret",
51 "EventCode": "0xc8",
52 "BriefDescription": "Retired Near Returns.",
53 "PublicDescription": "The number of near return instructions (RET or RET Iw) retired."
54 },
55 {
56 "EventName": "ex_ret_near_ret_mispred",
57 "EventCode": "0xc9",
58 "BriefDescription": "Retired Near Returns Mispredicted.",
59 "PublicDescription": "The number of near returns retired that were not correctly predicted by the return address predictor. Each such mispredict incurs the same penalty as a mispredicted conditional branch instruction."
60 },
61 {
62 "EventName": "ex_ret_brn_ind_misp",
63 "EventCode": "0xca",
64 "BriefDescription": "Retired Indirect Branch Instructions Mispredicted.",
65 "PublicDescription": "Retired Indirect Branch Instructions Mispredicted."
66 },
67 {
68 "EventName": "ex_ret_mmx_fp_instr.sse_instr",
69 "EventCode": "0xcb",
70 "BriefDescription": "SSE instructions (SSE, SSE2, SSE3, SSSE3, SSE4A, SSE41, SSE42, AVX).",
71 "PublicDescription": "The number of MMX, SSE or x87 instructions retired. The UnitMask allows the selection of the individual classes of instructions as given in the table. Each increment represents one complete instruction. Since this event includes non-numeric instructions it is not suitable for measuring MFLOPS. SSE instructions (SSE, SSE2, SSE3, SSSE3, SSE4A, SSE41, SSE42, AVX).",
72 "UMask": "0x4"
73 },
74 {
75 "EventName": "ex_ret_mmx_fp_instr.mmx_instr",
76 "EventCode": "0xcb",
77 "BriefDescription": "MMX instructions.",
78 "PublicDescription": "The number of MMX, SSE or x87 instructions retired. The UnitMask allows the selection of the individual classes of instructions as given in the table. Each increment represents one complete instruction. Since this event includes non-numeric instructions it is not suitable for measuring MFLOPS. MMX instructions.",
79 "UMask": "0x2"
80 },
81 {
82 "EventName": "ex_ret_mmx_fp_instr.x87_instr",
83 "EventCode": "0xcb",
84 "BriefDescription": "x87 instructions.",
85 "PublicDescription": "The number of MMX, SSE or x87 instructions retired. The UnitMask allows the selection of the individual classes of instructions as given in the table. Each increment represents one complete instruction. Since this event includes non-numeric instructions it is not suitable for measuring MFLOPS. x87 instructions.",
86 "UMask": "0x1"
87 },
88 {
89 "EventName": "ex_ret_cond",
90 "EventCode": "0xd1",
91 "BriefDescription": "Retired Conditional Branch Instructions."
92 },
93 {
94 "EventName": "ex_ret_cond_misp",
95 "EventCode": "0xd2",
96 "BriefDescription": "Retired Conditional Branch Instructions Mispredicted."
97 },
98 {
99 "EventName": "ex_div_busy",
100 "EventCode": "0xd3",
101 "BriefDescription": "Div Cycles Busy count."
102 },
103 {
104 "EventName": "ex_div_count",
105 "EventCode": "0xd4",
106 "BriefDescription": "Div Op Count."
107 },
108 {
109 "EventName": "ex_tagged_ibs_ops.ibs_count_rollover",
110 "EventCode": "0x1cf",
111 "BriefDescription": "Number of times an op could not be tagged by IBS because of a previous tagged op that has not retired.",
112 "PublicDescription": "Tagged IBS Ops. Number of times an op could not be tagged by IBS because of a previous tagged op that has not retired.",
113 "UMask": "0x4"
114 },
115 {
116 "EventName": "ex_tagged_ibs_ops.ibs_tagged_ops_ret",
117 "EventCode": "0x1cf",
118 "BriefDescription": "Number of Ops tagged by IBS that retired.",
119 "PublicDescription": "Tagged IBS Ops. Number of Ops tagged by IBS that retired.",
120 "UMask": "0x2"
121 },
122 {
123 "EventName": "ex_tagged_ibs_ops.ibs_tagged_ops",
124 "EventCode": "0x1cf",
125 "BriefDescription": "Number of Ops tagged by IBS.",
126 "PublicDescription": "Tagged IBS Ops. Number of Ops tagged by IBS.",
127 "UMask": "0x1"
128 },
129 {
130 "EventName": "ex_ret_fus_brnch_inst",
131 "EventCode": "0x1d0",
132 "BriefDescription": "The number of fused retired branch instructions retired per cycle. The number of events logged per cycle can vary from 0 to 3."
133 }
134]
diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/floating-point.json b/tools/perf/pmu-events/arch/x86/amdfam17h/floating-point.json
new file mode 100644
index 000000000000..ea4711983d1d
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/floating-point.json
@@ -0,0 +1,168 @@
1[
2 {
3 "EventName": "fpu_pipe_assignment.dual",
4 "EventCode": "0x00",
5 "BriefDescription": "Total number multi-pipe uOps.",
6 "PublicDescription": "The number of operations (uOps) and dual-pipe uOps dispatched to each of the 4 FPU execution pipelines. This event reflects how busy the FPU pipelines are and may be used for workload characterization. This includes all operations performed by x87, MMX, and SSE instructions, including moves. Each increment represents a one- cycle dispatch event. This event is a speculative event. Since this event includes non-numeric operations it is not suitable for measuring MFLOPS. Total number multi-pipe uOps assigned to Pipe 3.",
7 "UMask": "0xf0"
8 },
9 {
10 "EventName": "fpu_pipe_assignment.total",
11 "EventCode": "0x00",
12 "BriefDescription": "Total number uOps.",
13 "PublicDescription": "The number of operations (uOps) and dual-pipe uOps dispatched to each of the 4 FPU execution pipelines. This event reflects how busy the FPU pipelines are and may be used for workload characterization. This includes all operations performed by x87, MMX, and SSE instructions, including moves. Each increment represents a one- cycle dispatch event. This event is a speculative event. Since this event includes non-numeric operations it is not suitable for measuring MFLOPS. Total number uOps assigned to Pipe 3.",
14 "UMask": "0xf"
15 },
16 {
17 "EventName": "fp_sched_empty",
18 "EventCode": "0x01",
19 "BriefDescription": "This is a speculative event. The number of cycles in which the FPU scheduler is empty. Note that some Ops like FP loads bypass the scheduler."
20 },
21 {
22 "EventName": "fp_retx87_fp_ops.all",
23 "EventCode": "0x02",
24 "BriefDescription": "All Ops.",
25 "PublicDescription": "The number of x87 floating-point Ops that have retired. The number of events logged per cycle can vary from 0 to 8.",
26 "UMask": "0x7"
27 },
28 {
29 "EventName": "fp_retx87_fp_ops.div_sqr_r_ops",
30 "EventCode": "0x02",
31 "BriefDescription": "Divide and square root Ops.",
32 "PublicDescription": "The number of x87 floating-point Ops that have retired. The number of events logged per cycle can vary from 0 to 8. Divide and square root Ops.",
33 "UMask": "0x4"
34 },
35 {
36 "EventName": "fp_retx87_fp_ops.mul_ops",
37 "EventCode": "0x02",
38 "BriefDescription": "Multiply Ops.",
39 "PublicDescription": "The number of x87 floating-point Ops that have retired. The number of events logged per cycle can vary from 0 to 8. Multiply Ops.",
40 "UMask": "0x2"
41 },
42 {
43 "EventName": "fp_retx87_fp_ops.add_sub_ops",
44 "EventCode": "0x02",
45 "BriefDescription": "Add/subtract Ops.",
46 "PublicDescription": "The number of x87 floating-point Ops that have retired. The number of events logged per cycle can vary from 0 to 8. Add/subtract Ops.",
47 "UMask": "0x1"
48 },
49 {
50 "EventName": "fp_ret_sse_avx_ops.all",
51 "EventCode": "0x03",
52 "BriefDescription": "All FLOPS.",
53 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15.",
54 "UMask": "0xff"
55 },
56 {
57 "EventName": "fp_ret_sse_avx_ops.dp_mult_add_flops",
58 "EventCode": "0x03",
59 "BriefDescription": "Double precision multiply-add FLOPS. Multiply-add counts as 2 FLOPS.",
60 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Double precision multiply-add FLOPS. Multiply-add counts as 2 FLOPS.",
61 "UMask": "0x80"
62 },
63 {
64 "EventName": "fp_ret_sse_avx_ops.dp_div_flops",
65 "EventCode": "0x03",
66 "BriefDescription": "Double precision divide/square root FLOPS.",
67 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Double precision divide/square root FLOPS.",
68 "UMask": "0x40"
69 },
70 {
71 "EventName": "fp_ret_sse_avx_ops.dp_mult_flops",
72 "EventCode": "0x03",
73 "BriefDescription": "Double precision multiply FLOPS.",
74 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Double precision multiply FLOPS.",
75 "UMask": "0x20"
76 },
77 {
78 "EventName": "fp_ret_sse_avx_ops.dp_add_sub_flops",
79 "EventCode": "0x03",
80 "BriefDescription": "Double precision add/subtract FLOPS.",
81 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Double precision add/subtract FLOPS.",
82 "UMask": "0x10"
83 },
84 {
85 "EventName": "fp_ret_sse_avx_ops.sp_mult_add_flops",
86 "EventCode": "0x03",
87 "BriefDescription": "Single precision multiply-add FLOPS. Multiply-add counts as 2 FLOPS.",
88 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Single precision multiply-add FLOPS. Multiply-add counts as 2 FLOPS.",
89 "UMask": "0x8"
90 },
91 {
92 "EventName": "fp_ret_sse_avx_ops.sp_div_flops",
93 "EventCode": "0x03",
94 "BriefDescription": "Single-precision divide/square root FLOPS.",
95 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Single-precision divide/square root FLOPS.",
96 "UMask": "0x4"
97 },
98 {
99 "EventName": "fp_ret_sse_avx_ops.sp_mult_flops",
100 "EventCode": "0x03",
101 "BriefDescription": "Single-precision multiply FLOPS.",
102 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Single-precision multiply FLOPS.",
103 "UMask": "0x2"
104 },
105 {
106 "EventName": "fp_ret_sse_avx_ops.sp_add_sub_flops",
107 "EventCode": "0x03",
108 "BriefDescription": "Single-precision add/subtract FLOPS.",
109 "PublicDescription": "This is a retire-based event. The number of retired SSE/AVX FLOPS. The number of events logged per cycle can vary from 0 to 64. This event can count above 15. Single-precision add/subtract FLOPS.",
110 "UMask": "0x1"
111 },
112 {
113 "EventName": "fp_num_mov_elim_scal_op.optimized",
114 "EventCode": "0x04",
115 "BriefDescription": "Number of Scalar Ops optimized.",
116 "PublicDescription": "This is a dispatch based speculative event, and is useful for measuring the effectiveness of the Move elimination and Scalar code optimization schemes. Number of Scalar Ops optimized.",
117 "UMask": "0x8"
118 },
119 {
120 "EventName": "fp_num_mov_elim_scal_op.opt_potential",
121 "EventCode": "0x04",
122 "BriefDescription": "Number of Ops that are candidates for optimization (have Z-bit either set or pass).",
123 "PublicDescription": "This is a dispatch based speculative event, and is useful for measuring the effectiveness of the Move elimination and Scalar code optimization schemes. Number of Ops that are candidates for optimization (have Z-bit either set or pass).",
124 "UMask": "0x4"
125 },
126 {
127 "EventName": "fp_num_mov_elim_scal_op.sse_mov_ops_elim",
128 "EventCode": "0x04",
129 "BriefDescription": "Number of SSE Move Ops eliminated.",
130 "PublicDescription": "This is a dispatch based speculative event, and is useful for measuring the effectiveness of the Move elimination and Scalar code optimization schemes. Number of SSE Move Ops eliminated.",
131 "UMask": "0x2"
132 },
133 {
134 "EventName": "fp_num_mov_elim_scal_op.sse_mov_ops",
135 "EventCode": "0x04",
136 "BriefDescription": "Number of SSE Move Ops.",
137 "PublicDescription": "This is a dispatch based speculative event, and is useful for measuring the effectiveness of the Move elimination and Scalar code optimization schemes. Number of SSE Move Ops.",
138 "UMask": "0x1"
139 },
140 {
141 "EventName": "fp_retired_ser_ops.x87_ctrl_ret",
142 "EventCode": "0x05",
143 "BriefDescription": "x87 control word mispredict traps due to mispredictions in RC or PC, or changes in mask bits.",
144 "PublicDescription": "The number of serializing Ops retired. x87 control word mispredict traps due to mispredictions in RC or PC, or changes in mask bits.",
145 "UMask": "0x8"
146 },
147 {
148 "EventName": "fp_retired_ser_ops.x87_bot_ret",
149 "EventCode": "0x05",
150 "BriefDescription": "x87 bottom-executing uOps retired.",
151 "PublicDescription": "The number of serializing Ops retired. x87 bottom-executing uOps retired.",
152 "UMask": "0x4"
153 },
154 {
155 "EventName": "fp_retired_ser_ops.sse_ctrl_ret",
156 "EventCode": "0x05",
157 "BriefDescription": "SSE control word mispredict traps due to mispredictions in RC, FTZ or DAZ, or changes in mask bits.",
158 "PublicDescription": "The number of serializing Ops retired. SSE control word mispredict traps due to mispredictions in RC, FTZ or DAZ, or changes in mask bits.",
159 "UMask": "0x2"
160 },
161 {
162 "EventName": "fp_retired_ser_ops.sse_bot_ret",
163 "EventCode": "0x05",
164 "BriefDescription": "SSE bottom-executing uOps retired.",
165 "PublicDescription": "The number of serializing Ops retired. SSE bottom-executing uOps retired.",
166 "UMask": "0x1"
167 }
168]
diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/memory.json b/tools/perf/pmu-events/arch/x86/amdfam17h/memory.json
new file mode 100644
index 000000000000..fa2d60d4def0
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/memory.json
@@ -0,0 +1,162 @@
1[
2 {
3 "EventName": "ls_locks.bus_lock",
4 "EventCode": "0x25",
5 "BriefDescription": "Bus lock when a locked operations crosses a cache boundary or is done on an uncacheable memory type.",
6 "PublicDescription": "Bus lock when a locked operations crosses a cache boundary or is done on an uncacheable memory type.",
7 "UMask": "0x1"
8 },
9 {
10 "EventName": "ls_dispatch.ld_st_dispatch",
11 "EventCode": "0x29",
12 "BriefDescription": "Load-op-Stores.",
13 "PublicDescription": "Counts the number of operations dispatched to the LS unit. Unit Masks ADDed. Load-op-Stores.",
14 "UMask": "0x4"
15 },
16 {
17 "EventName": "ls_dispatch.store_dispatch",
18 "EventCode": "0x29",
19 "BriefDescription": "Counts the number of operations dispatched to the LS unit. Unit Masks ADDed.",
20 "PublicDescription": "Counts the number of operations dispatched to the LS unit. Unit Masks ADDed.",
21 "UMask": "0x2"
22 },
23 {
24 "EventName": "ls_dispatch.ld_dispatch",
25 "EventCode": "0x29",
26 "BriefDescription": "Counts the number of operations dispatched to the LS unit. Unit Masks ADDed.",
27 "PublicDescription": "Counts the number of operations dispatched to the LS unit. Unit Masks ADDed.",
28 "UMask": "0x1"
29 },
30 {
31 "EventName": "ls_stlf",
32 "EventCode": "0x35",
33 "BriefDescription": "Number of STLF hits."
34 },
35 {
36 "EventName": "ls_dc_accesses",
37 "EventCode": "0x40",
38 "BriefDescription": "The number of accesses to the data cache for load and store references. This may include certain microcode scratchpad accesses, although these are generally rare. Each increment represents an eight-byte access, although the instruction may only be accessing a portion of that. This event is a speculative event."
39 },
40 {
41 "EventName": "ls_l1_d_tlb_miss.all",
42 "EventCode": "0x45",
43 "BriefDescription": "L1 DTLB Miss or Reload off all sizes.",
44 "PublicDescription": "L1 DTLB Miss or Reload off all sizes.",
45 "UMask": "0xff"
46 },
47 {
48 "EventName": "ls_l1_d_tlb_miss.tlb_reload_1g_l2_miss",
49 "EventCode": "0x45",
50 "BriefDescription": "L1 DTLB Miss of a page of 1G size.",
51 "PublicDescription": "L1 DTLB Miss of a page of 1G size.",
52 "UMask": "0x80"
53 },
54 {
55 "EventName": "ls_l1_d_tlb_miss.tlb_reload_2m_l2_miss",
56 "EventCode": "0x45",
57 "BriefDescription": "L1 DTLB Miss of a page of 2M size.",
58 "PublicDescription": "L1 DTLB Miss of a page of 2M size.",
59 "UMask": "0x40"
60 },
61 {
62 "EventName": "ls_l1_d_tlb_miss.tlb_reload_32k_l2_miss",
63 "EventCode": "0x45",
64 "BriefDescription": "L1 DTLB Miss of a page of 32K size.",
65 "PublicDescription": "L1 DTLB Miss of a page of 32K size.",
66 "UMask": "0x20"
67 },
68 {
69 "EventName": "ls_l1_d_tlb_miss.tlb_reload_4k_l2_miss",
70 "EventCode": "0x45",
71 "BriefDescription": "L1 DTLB Miss of a page of 4K size.",
72 "PublicDescription": "L1 DTLB Miss of a page of 4K size.",
73 "UMask": "0x10"
74 },
75 {
76 "EventName": "ls_l1_d_tlb_miss.tlb_reload_1g_l2_hit",
77 "EventCode": "0x45",
78 "BriefDescription": "L1 DTLB Reload of a page of 1G size.",
79 "PublicDescription": "L1 DTLB Reload of a page of 1G size.",
80 "UMask": "0x8"
81 },
82 {
83 "EventName": "ls_l1_d_tlb_miss.tlb_reload_2m_l2_hit",
84 "EventCode": "0x45",
85 "BriefDescription": "L1 DTLB Reload of a page of 2M size.",
86 "PublicDescription": "L1 DTLB Reload of a page of 2M size.",
87 "UMask": "0x4"
88 },
89 {
90 "EventName": "ls_l1_d_tlb_miss.tlb_reload_32k_l2_hit",
91 "EventCode": "0x45",
92 "BriefDescription": "L1 DTLB Reload of a page of 32K size.",
93 "PublicDescription": "L1 DTLB Reload of a page of 32K size.",
94 "UMask": "0x2"
95 },
96 {
97 "EventName": "ls_l1_d_tlb_miss.tlb_reload_4k_l2_hit",
98 "EventCode": "0x45",
99 "BriefDescription": "L1 DTLB Reload of a page of 4K size.",
100 "PublicDescription": "L1 DTLB Reload of a page of 4K size.",
101 "UMask": "0x1"
102 },
103 {
104 "EventName": "ls_tablewalker.perf_mon_tablewalk_alloc_iside",
105 "EventCode": "0x46",
106 "BriefDescription": "Tablewalker allocation.",
107 "PublicDescription": "Tablewalker allocation.",
108 "UMask": "0xc"
109 },
110 {
111 "EventName": "ls_tablewalker.perf_mon_tablewalk_alloc_dside",
112 "EventCode": "0x46",
113 "BriefDescription": "Tablewalker allocation.",
114 "PublicDescription": "Tablewalker allocation.",
115 "UMask": "0x3"
116 },
117 {
118 "EventName": "ls_misal_accesses",
119 "EventCode": "0x47",
120 "BriefDescription": "Misaligned loads."
121 },
122 {
123 "EventName": "ls_pref_instr_disp.prefetch_nta",
124 "EventCode": "0x4b",
125 "BriefDescription": "Software Prefetch Instructions (PREFETCHNTA instruction) Dispatched.",
126 "PublicDescription": "Software Prefetch Instructions (PREFETCHNTA instruction) Dispatched.",
127 "UMask": "0x4"
128 },
129 {
130 "EventName": "ls_pref_instr_disp.store_prefetch_w",
131 "EventCode": "0x4b",
132 "BriefDescription": "Software Prefetch Instructions (3DNow PREFETCHW instruction) Dispatched.",
133 "PublicDescription": "Software Prefetch Instructions (3DNow PREFETCHW instruction) Dispatched.",
134 "UMask": "0x2"
135 },
136 {
137 "EventName": "ls_pref_instr_disp.load_prefetch_w",
138 "EventCode": "0x4b",
139 "BriefDescription": "Prefetch, Prefetch_T0_T1_T2.",
140 "PublicDescription": "Software Prefetch Instructions Dispatched. Prefetch, Prefetch_T0_T1_T2.",
141 "UMask": "0x1"
142 },
143 {
144 "EventName": "ls_inef_sw_pref.mab_mch_cnt",
145 "EventCode": "0x52",
146 "BriefDescription": "The number of software prefetches that did not fetch data outside of the processor core.",
147 "PublicDescription": "The number of software prefetches that did not fetch data outside of the processor core.",
148 "UMask": "0x2"
149 },
150 {
151 "EventName": "ls_inef_sw_pref.data_pipe_sw_pf_dc_hit",
152 "EventCode": "0x52",
153 "BriefDescription": "The number of software prefetches that did not fetch data outside of the processor core.",
154 "PublicDescription": "The number of software prefetches that did not fetch data outside of the processor core.",
155 "UMask": "0x1"
156 },
157 {
158 "EventName": "ls_not_halted_cyc",
159 "EventCode": "0x76",
160 "BriefDescription": "Cycles not in Halt."
161 }
162]
diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/other.json b/tools/perf/pmu-events/arch/x86/amdfam17h/other.json
new file mode 100644
index 000000000000..b26a00d05a2e
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/other.json
@@ -0,0 +1,65 @@
1[
2 {
3 "EventName": "ic_oc_mode_switch.oc_ic_mode_switch",
4 "EventCode": "0x28a",
5 "BriefDescription": "OC to IC mode switch.",
6 "PublicDescription": "OC Mode Switch. OC to IC mode switch.",
7 "UMask": "0x2"
8 },
9 {
10 "EventName": "ic_oc_mode_switch.ic_oc_mode_switch",
11 "EventCode": "0x28a",
12 "BriefDescription": "IC to OC mode switch.",
13 "PublicDescription": "OC Mode Switch. IC to OC mode switch.",
14 "UMask": "0x1"
15 },
16 {
17 "EventName": "de_dis_dispatch_token_stalls0.retire_token_stall",
18 "EventCode": "0xaf",
19 "BriefDescription": "RETIRE Tokens unavailable.",
20 "PublicDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall. RETIRE Tokens unavailable.",
21 "UMask": "0x40"
22 },
23 {
24 "EventName": "de_dis_dispatch_token_stalls0.agsq_token_stall",
25 "EventCode": "0xaf",
26 "BriefDescription": "AGSQ Tokens unavailable.",
27 "PublicDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall. AGSQ Tokens unavailable.",
28 "UMask": "0x20"
29 },
30 {
31 "EventName": "de_dis_dispatch_token_stalls0.alu_token_stall",
32 "EventCode": "0xaf",
33 "BriefDescription": "ALU tokens total unavailable.",
34 "PublicDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall. ALU tokens total unavailable.",
35 "UMask": "0x10"
36 },
37 {
38 "EventName": "de_dis_dispatch_token_stalls0.alsq3_0_token_stall",
39 "EventCode": "0xaf",
40 "BriefDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall.",
41 "PublicDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall.",
42 "UMask": "0x8"
43 },
44 {
45 "EventName": "de_dis_dispatch_token_stalls0.alsq3_token_stall",
46 "EventCode": "0xaf",
47 "BriefDescription": "ALSQ 3 Tokens unavailable.",
48 "PublicDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall. ALSQ 3 Tokens unavailable.",
49 "UMask": "0x4"
50 },
51 {
52 "EventName": "de_dis_dispatch_token_stalls0.alsq2_token_stall",
53 "EventCode": "0xaf",
54 "BriefDescription": "ALSQ 2 Tokens unavailable.",
55 "PublicDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall. ALSQ 2 Tokens unavailable.",
56 "UMask": "0x2"
57 },
58 {
59 "EventName": "de_dis_dispatch_token_stalls0.alsq1_token_stall",
60 "EventCode": "0xaf",
61 "BriefDescription": "ALSQ 1 Tokens unavailable.",
62 "PublicDescription": "Cycles where a dispatch group is valid but does not get dispatched due to a token stall. ALSQ 1 Tokens unavailable.",
63 "UMask": "0x1"
64 }
65]
diff --git a/tools/perf/pmu-events/arch/x86/mapfile.csv b/tools/perf/pmu-events/arch/x86/mapfile.csv
index e05c2c8458fc..d6984a3017e0 100644
--- a/tools/perf/pmu-events/arch/x86/mapfile.csv
+++ b/tools/perf/pmu-events/arch/x86/mapfile.csv
@@ -33,3 +33,4 @@ GenuineIntel-6-25,v2,westmereep-sp,core
33GenuineIntel-6-2F,v2,westmereex,core 33GenuineIntel-6-2F,v2,westmereex,core
34GenuineIntel-6-55-[01234],v1,skylakex,core 34GenuineIntel-6-55-[01234],v1,skylakex,core
35GenuineIntel-6-55-[56789ABCDEF],v1,cascadelakex,core 35GenuineIntel-6-55-[56789ABCDEF],v1,cascadelakex,core
36AuthenticAMD-23-[[:xdigit:]]+,v1,amdfam17h,core
diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
index 390a351d15ea..c3eae1d77d36 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -10,6 +10,8 @@
10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11# more details. 11# more details.
12 12
13from __future__ import print_function
14
13import os 15import os
14import sys 16import sys
15import struct 17import struct
@@ -199,6 +201,18 @@ import datetime
199 201
200from PySide.QtSql import * 202from PySide.QtSql import *
201 203
204if sys.version_info < (3, 0):
205 def toserverstr(str):
206 return str
207 def toclientstr(str):
208 return str
209else:
210 # Assume UTF-8 server_encoding and client_encoding
211 def toserverstr(str):
212 return bytes(str, "UTF_8")
213 def toclientstr(str):
214 return bytes(str, "UTF_8")
215
202# Need to access PostgreSQL C library directly to use COPY FROM STDIN 216# Need to access PostgreSQL C library directly to use COPY FROM STDIN
203from ctypes import * 217from ctypes import *
204libpq = CDLL("libpq.so.5") 218libpq = CDLL("libpq.so.5")
@@ -234,12 +248,17 @@ perf_db_export_mode = True
234perf_db_export_calls = False 248perf_db_export_calls = False
235perf_db_export_callchains = False 249perf_db_export_callchains = False
236 250
251def printerr(*args, **kw_args):
252 print(*args, file=sys.stderr, **kw_args)
253
254def printdate(*args, **kw_args):
255 print(datetime.datetime.today(), *args, sep=' ', **kw_args)
237 256
238def usage(): 257def usage():
239 print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]" 258 printerr("Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]")
240 print >> sys.stderr, "where: columns 'all' or 'branches'" 259 printerr("where: columns 'all' or 'branches'")
241 print >> sys.stderr, " calls 'calls' => create calls and call_paths table" 260 printerr(" calls 'calls' => create calls and call_paths table")
242 print >> sys.stderr, " callchains 'callchains' => create call_paths table" 261 printerr(" callchains 'callchains' => create call_paths table")
243 raise Exception("Too few arguments") 262 raise Exception("Too few arguments")
244 263
245if (len(sys.argv) < 2): 264if (len(sys.argv) < 2):
@@ -273,7 +292,7 @@ def do_query(q, s):
273 return 292 return
274 raise Exception("Query failed: " + q.lastError().text()) 293 raise Exception("Query failed: " + q.lastError().text())
275 294
276print datetime.datetime.today(), "Creating database..." 295printdate("Creating database...")
277 296
278db = QSqlDatabase.addDatabase('QPSQL') 297db = QSqlDatabase.addDatabase('QPSQL')
279query = QSqlQuery(db) 298query = QSqlQuery(db)
@@ -506,12 +525,12 @@ do_query(query, 'CREATE VIEW samples_view AS '
506 ' FROM samples') 525 ' FROM samples')
507 526
508 527
509file_header = struct.pack("!11sii", "PGCOPY\n\377\r\n\0", 0, 0) 528file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0)
510file_trailer = "\377\377" 529file_trailer = b"\377\377"
511 530
512def open_output_file(file_name): 531def open_output_file(file_name):
513 path_name = output_dir_name + "/" + file_name 532 path_name = output_dir_name + "/" + file_name
514 file = open(path_name, "w+") 533 file = open(path_name, "wb+")
515 file.write(file_header) 534 file.write(file_header)
516 return file 535 return file
517 536
@@ -526,13 +545,13 @@ def copy_output_file_direct(file, table_name):
526 545
527# Use COPY FROM STDIN because security may prevent postgres from accessing the files directly 546# Use COPY FROM STDIN because security may prevent postgres from accessing the files directly
528def copy_output_file(file, table_name): 547def copy_output_file(file, table_name):
529 conn = PQconnectdb("dbname = " + dbname) 548 conn = PQconnectdb(toclientstr("dbname = " + dbname))
530 if (PQstatus(conn)): 549 if (PQstatus(conn)):
531 raise Exception("COPY FROM STDIN PQconnectdb failed") 550 raise Exception("COPY FROM STDIN PQconnectdb failed")
532 file.write(file_trailer) 551 file.write(file_trailer)
533 file.seek(0) 552 file.seek(0)
534 sql = "COPY " + table_name + " FROM STDIN (FORMAT 'binary')" 553 sql = "COPY " + table_name + " FROM STDIN (FORMAT 'binary')"
535 res = PQexec(conn, sql) 554 res = PQexec(conn, toclientstr(sql))
536 if (PQresultStatus(res) != 4): 555 if (PQresultStatus(res) != 4):
537 raise Exception("COPY FROM STDIN PQexec failed") 556 raise Exception("COPY FROM STDIN PQexec failed")
538 data = file.read(65536) 557 data = file.read(65536)
@@ -566,7 +585,7 @@ if perf_db_export_calls:
566 call_file = open_output_file("call_table.bin") 585 call_file = open_output_file("call_table.bin")
567 586
568def trace_begin(): 587def trace_begin():
569 print datetime.datetime.today(), "Writing to intermediate files..." 588 printdate("Writing to intermediate files...")
570 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs 589 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
571 evsel_table(0, "unknown") 590 evsel_table(0, "unknown")
572 machine_table(0, 0, "unknown") 591 machine_table(0, 0, "unknown")
@@ -582,7 +601,7 @@ def trace_begin():
582unhandled_count = 0 601unhandled_count = 0
583 602
584def trace_end(): 603def trace_end():
585 print datetime.datetime.today(), "Copying to database..." 604 printdate("Copying to database...")
586 copy_output_file(evsel_file, "selected_events") 605 copy_output_file(evsel_file, "selected_events")
587 copy_output_file(machine_file, "machines") 606 copy_output_file(machine_file, "machines")
588 copy_output_file(thread_file, "threads") 607 copy_output_file(thread_file, "threads")
@@ -597,7 +616,7 @@ def trace_end():
597 if perf_db_export_calls: 616 if perf_db_export_calls:
598 copy_output_file(call_file, "calls") 617 copy_output_file(call_file, "calls")
599 618
600 print datetime.datetime.today(), "Removing intermediate files..." 619 printdate("Removing intermediate files...")
601 remove_output_file(evsel_file) 620 remove_output_file(evsel_file)
602 remove_output_file(machine_file) 621 remove_output_file(machine_file)
603 remove_output_file(thread_file) 622 remove_output_file(thread_file)
@@ -612,7 +631,7 @@ def trace_end():
612 if perf_db_export_calls: 631 if perf_db_export_calls:
613 remove_output_file(call_file) 632 remove_output_file(call_file)
614 os.rmdir(output_dir_name) 633 os.rmdir(output_dir_name)
615 print datetime.datetime.today(), "Adding primary keys" 634 printdate("Adding primary keys")
616 do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') 635 do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
617 do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)') 636 do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)')
618 do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)') 637 do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)')
@@ -627,7 +646,7 @@ def trace_end():
627 if perf_db_export_calls: 646 if perf_db_export_calls:
628 do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') 647 do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)')
629 648
630 print datetime.datetime.today(), "Adding foreign keys" 649 printdate("Adding foreign keys")
631 do_query(query, 'ALTER TABLE threads ' 650 do_query(query, 'ALTER TABLE threads '
632 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' 651 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),'
633 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)') 652 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)')
@@ -663,8 +682,8 @@ def trace_end():
663 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') 682 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
664 683
665 if (unhandled_count): 684 if (unhandled_count):
666 print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" 685 printdate("Warning: ", unhandled_count, " unhandled events")
667 print datetime.datetime.today(), "Done" 686 printdate("Done")
668 687
669def trace_unhandled(event_name, context, event_fields_dict): 688def trace_unhandled(event_name, context, event_fields_dict):
670 global unhandled_count 689 global unhandled_count
@@ -674,12 +693,14 @@ def sched__sched_switch(*x):
674 pass 693 pass
675 694
676def evsel_table(evsel_id, evsel_name, *x): 695def evsel_table(evsel_id, evsel_name, *x):
696 evsel_name = toserverstr(evsel_name)
677 n = len(evsel_name) 697 n = len(evsel_name)
678 fmt = "!hiqi" + str(n) + "s" 698 fmt = "!hiqi" + str(n) + "s"
679 value = struct.pack(fmt, 2, 8, evsel_id, n, evsel_name) 699 value = struct.pack(fmt, 2, 8, evsel_id, n, evsel_name)
680 evsel_file.write(value) 700 evsel_file.write(value)
681 701
682def machine_table(machine_id, pid, root_dir, *x): 702def machine_table(machine_id, pid, root_dir, *x):
703 root_dir = toserverstr(root_dir)
683 n = len(root_dir) 704 n = len(root_dir)
684 fmt = "!hiqiii" + str(n) + "s" 705 fmt = "!hiqiii" + str(n) + "s"
685 value = struct.pack(fmt, 3, 8, machine_id, 4, pid, n, root_dir) 706 value = struct.pack(fmt, 3, 8, machine_id, 4, pid, n, root_dir)
@@ -690,6 +711,7 @@ def thread_table(thread_id, machine_id, process_id, pid, tid, *x):
690 thread_file.write(value) 711 thread_file.write(value)
691 712
692def comm_table(comm_id, comm_str, *x): 713def comm_table(comm_id, comm_str, *x):
714 comm_str = toserverstr(comm_str)
693 n = len(comm_str) 715 n = len(comm_str)
694 fmt = "!hiqi" + str(n) + "s" 716 fmt = "!hiqi" + str(n) + "s"
695 value = struct.pack(fmt, 2, 8, comm_id, n, comm_str) 717 value = struct.pack(fmt, 2, 8, comm_id, n, comm_str)
@@ -701,6 +723,9 @@ def comm_thread_table(comm_thread_id, comm_id, thread_id, *x):
701 comm_thread_file.write(value) 723 comm_thread_file.write(value)
702 724
703def dso_table(dso_id, machine_id, short_name, long_name, build_id, *x): 725def dso_table(dso_id, machine_id, short_name, long_name, build_id, *x):
726 short_name = toserverstr(short_name)
727 long_name = toserverstr(long_name)
728 build_id = toserverstr(build_id)
704 n1 = len(short_name) 729 n1 = len(short_name)
705 n2 = len(long_name) 730 n2 = len(long_name)
706 n3 = len(build_id) 731 n3 = len(build_id)
@@ -709,12 +734,14 @@ def dso_table(dso_id, machine_id, short_name, long_name, build_id, *x):
709 dso_file.write(value) 734 dso_file.write(value)
710 735
711def symbol_table(symbol_id, dso_id, sym_start, sym_end, binding, symbol_name, *x): 736def symbol_table(symbol_id, dso_id, sym_start, sym_end, binding, symbol_name, *x):
737 symbol_name = toserverstr(symbol_name)
712 n = len(symbol_name) 738 n = len(symbol_name)
713 fmt = "!hiqiqiqiqiii" + str(n) + "s" 739 fmt = "!hiqiqiqiqiii" + str(n) + "s"
714 value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8, sym_start, 8, sym_end, 4, binding, n, symbol_name) 740 value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8, sym_start, 8, sym_end, 4, binding, n, symbol_name)
715 symbol_file.write(value) 741 symbol_file.write(value)
716 742
717def branch_type_table(branch_type, name, *x): 743def branch_type_table(branch_type, name, *x):
744 name = toserverstr(name)
718 n = len(name) 745 n = len(name)
719 fmt = "!hiii" + str(n) + "s" 746 fmt = "!hiii" + str(n) + "s"
720 value = struct.pack(fmt, 2, 4, branch_type, n, name) 747 value = struct.pack(fmt, 2, 4, branch_type, n, name)
diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py
index eb63e6c7107f..3b71902a5a21 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -10,6 +10,8 @@
10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11# more details. 11# more details.
12 12
13from __future__ import print_function
14
13import os 15import os
14import sys 16import sys
15import struct 17import struct
@@ -60,11 +62,17 @@ perf_db_export_mode = True
60perf_db_export_calls = False 62perf_db_export_calls = False
61perf_db_export_callchains = False 63perf_db_export_callchains = False
62 64
65def printerr(*args, **keyword_args):
66 print(*args, file=sys.stderr, **keyword_args)
67
68def printdate(*args, **kw_args):
69 print(datetime.datetime.today(), *args, sep=' ', **kw_args)
70
63def usage(): 71def usage():
64 print >> sys.stderr, "Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]" 72 printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]");
65 print >> sys.stderr, "where: columns 'all' or 'branches'" 73 printerr("where: columns 'all' or 'branches'");
66 print >> sys.stderr, " calls 'calls' => create calls and call_paths table" 74 printerr(" calls 'calls' => create calls and call_paths table");
67 print >> sys.stderr, " callchains 'callchains' => create call_paths table" 75 printerr(" callchains 'callchains' => create call_paths table");
68 raise Exception("Too few arguments") 76 raise Exception("Too few arguments")
69 77
70if (len(sys.argv) < 2): 78if (len(sys.argv) < 2):
@@ -100,7 +108,7 @@ def do_query_(q):
100 return 108 return
101 raise Exception("Query failed: " + q.lastError().text()) 109 raise Exception("Query failed: " + q.lastError().text())
102 110
103print datetime.datetime.today(), "Creating database..." 111printdate("Creating database ...")
104 112
105db_exists = False 113db_exists = False
106try: 114try:
@@ -378,7 +386,7 @@ if perf_db_export_calls:
378 call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") 386 call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
379 387
380def trace_begin(): 388def trace_begin():
381 print datetime.datetime.today(), "Writing records..." 389 printdate("Writing records...")
382 do_query(query, 'BEGIN TRANSACTION') 390 do_query(query, 'BEGIN TRANSACTION')
383 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs 391 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
384 evsel_table(0, "unknown") 392 evsel_table(0, "unknown")
@@ -397,14 +405,14 @@ unhandled_count = 0
397def trace_end(): 405def trace_end():
398 do_query(query, 'END TRANSACTION') 406 do_query(query, 'END TRANSACTION')
399 407
400 print datetime.datetime.today(), "Adding indexes" 408 printdate("Adding indexes")
401 if perf_db_export_calls: 409 if perf_db_export_calls:
402 do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') 410 do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
403 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') 411 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
404 412
405 if (unhandled_count): 413 if (unhandled_count):
406 print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" 414 printdate("Warning: ", unhandled_count, " unhandled events")
407 print datetime.datetime.today(), "Done" 415 printdate("Done")
408 416
409def trace_unhandled(event_name, context, event_fields_dict): 417def trace_unhandled(event_name, context, event_fields_dict):
410 global unhandled_count 418 global unhandled_count
diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py
index afec9479ca7f..e38518cdcbc3 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -88,11 +88,20 @@
88# 7fab593ea956 48 89 15 3b 13 22 00 movq %rdx, 0x22133b(%rip) 88# 7fab593ea956 48 89 15 3b 13 22 00 movq %rdx, 0x22133b(%rip)
89# 8107675243232 2 ls 22011 22011 hardware interrupt No 7fab593ea956 _dl_start+0x26 (ld-2.19.so) -> ffffffff86a012e0 page_fault ([kernel]) 89# 8107675243232 2 ls 22011 22011 hardware interrupt No 7fab593ea956 _dl_start+0x26 (ld-2.19.so) -> ffffffff86a012e0 page_fault ([kernel])
90 90
91from __future__ import print_function
92
91import sys 93import sys
92import weakref 94import weakref
93import threading 95import threading
94import string 96import string
95import cPickle 97try:
98 # Python2
99 import cPickle as pickle
100 # size of pickled integer big enough for record size
101 glb_nsz = 8
102except ImportError:
103 import pickle
104 glb_nsz = 16
96import re 105import re
97import os 106import os
98from PySide.QtCore import * 107from PySide.QtCore import *
@@ -102,6 +111,15 @@ from decimal import *
102from ctypes import * 111from ctypes import *
103from multiprocessing import Process, Array, Value, Event 112from multiprocessing import Process, Array, Value, Event
104 113
114# xrange is range in Python3
115try:
116 xrange
117except NameError:
118 xrange = range
119
120def printerr(*args, **keyword_args):
121 print(*args, file=sys.stderr, **keyword_args)
122
105# Data formatting helpers 123# Data formatting helpers
106 124
107def tohex(ip): 125def tohex(ip):
@@ -1004,10 +1022,6 @@ class ChildDataItemFinder():
1004 1022
1005glb_chunk_sz = 10000 1023glb_chunk_sz = 10000
1006 1024
1007# size of pickled integer big enough for record size
1008
1009glb_nsz = 8
1010
1011# Background process for SQL data fetcher 1025# Background process for SQL data fetcher
1012 1026
1013class SQLFetcherProcess(): 1027class SQLFetcherProcess():
@@ -1066,7 +1080,7 @@ class SQLFetcherProcess():
1066 return True 1080 return True
1067 if space >= glb_nsz: 1081 if space >= glb_nsz:
1068 # Use 0 (or space < glb_nsz) to mean there is no more at the top of the buffer 1082 # Use 0 (or space < glb_nsz) to mean there is no more at the top of the buffer
1069 nd = cPickle.dumps(0, cPickle.HIGHEST_PROTOCOL) 1083 nd = pickle.dumps(0, pickle.HIGHEST_PROTOCOL)
1070 self.buffer[self.local_head : self.local_head + len(nd)] = nd 1084 self.buffer[self.local_head : self.local_head + len(nd)] = nd
1071 self.local_head = 0 1085 self.local_head = 0
1072 if self.local_tail - self.local_head > sz: 1086 if self.local_tail - self.local_head > sz:
@@ -1084,9 +1098,9 @@ class SQLFetcherProcess():
1084 self.wait_event.wait() 1098 self.wait_event.wait()
1085 1099
1086 def AddToBuffer(self, obj): 1100 def AddToBuffer(self, obj):
1087 d = cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL) 1101 d = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
1088 n = len(d) 1102 n = len(d)
1089 nd = cPickle.dumps(n, cPickle.HIGHEST_PROTOCOL) 1103 nd = pickle.dumps(n, pickle.HIGHEST_PROTOCOL)
1090 sz = n + glb_nsz 1104 sz = n + glb_nsz
1091 self.WaitForSpace(sz) 1105 self.WaitForSpace(sz)
1092 pos = self.local_head 1106 pos = self.local_head
@@ -1198,12 +1212,12 @@ class SQLFetcher(QObject):
1198 pos = self.local_tail 1212 pos = self.local_tail
1199 if len(self.buffer) - pos < glb_nsz: 1213 if len(self.buffer) - pos < glb_nsz:
1200 pos = 0 1214 pos = 0
1201 n = cPickle.loads(self.buffer[pos : pos + glb_nsz]) 1215 n = pickle.loads(self.buffer[pos : pos + glb_nsz])
1202 if n == 0: 1216 if n == 0:
1203 pos = 0 1217 pos = 0
1204 n = cPickle.loads(self.buffer[0 : glb_nsz]) 1218 n = pickle.loads(self.buffer[0 : glb_nsz])
1205 pos += glb_nsz 1219 pos += glb_nsz
1206 obj = cPickle.loads(self.buffer[pos : pos + n]) 1220 obj = pickle.loads(self.buffer[pos : pos + n])
1207 self.local_tail = pos + n 1221 self.local_tail = pos + n
1208 return obj 1222 return obj
1209 1223
@@ -2973,7 +2987,7 @@ class DBRef():
2973 2987
2974def Main(): 2988def Main():
2975 if (len(sys.argv) < 2): 2989 if (len(sys.argv) < 2):
2976 print >> sys.stderr, "Usage is: exported-sql-viewer.py {<database name> | --help-only}" 2990 printerr("Usage is: exported-sql-viewer.py {<database name> | --help-only}");
2977 raise Exception("Too few arguments") 2991 raise Exception("Too few arguments")
2978 2992
2979 dbname = sys.argv[1] 2993 dbname = sys.argv[1]
@@ -2986,8 +3000,8 @@ def Main():
2986 3000
2987 is_sqlite3 = False 3001 is_sqlite3 = False
2988 try: 3002 try:
2989 f = open(dbname) 3003 f = open(dbname, "rb")
2990 if f.read(15) == "SQLite format 3": 3004 if f.read(15) == b'SQLite format 3':
2991 is_sqlite3 = True 3005 is_sqlite3 = True
2992 f.close() 3006 f.close()
2993 except: 3007 except:
diff --git a/tools/perf/tests/attr/test-record-C0 b/tools/perf/tests/attr/test-record-C0
index cb0a3138fa54..93818054ae20 100644
--- a/tools/perf/tests/attr/test-record-C0
+++ b/tools/perf/tests/attr/test-record-C0
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -C 0 kill >/dev/null 2>&1 3args = --no-bpf-event -C 0 kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-basic b/tools/perf/tests/attr/test-record-basic
index 85a23cf35ba1..b0ca42a5ecc9 100644
--- a/tools/perf/tests/attr/test-record-basic
+++ b/tools/perf/tests/attr/test-record-basic
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = kill >/dev/null 2>&1 3args = --no-bpf-event kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-any b/tools/perf/tests/attr/test-record-branch-any
index 81f839e2fad0..1a99b3ce6b89 100644
--- a/tools/perf/tests/attr/test-record-branch-any
+++ b/tools/perf/tests/attr/test-record-branch-any
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -b kill >/dev/null 2>&1 3args = --no-bpf-event -b kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-filter-any b/tools/perf/tests/attr/test-record-branch-filter-any
index 357421f4dfce..709768b508c6 100644
--- a/tools/perf/tests/attr/test-record-branch-filter-any
+++ b/tools/perf/tests/attr/test-record-branch-filter-any
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -j any kill >/dev/null 2>&1 3args = --no-bpf-event -j any kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-filter-any_call b/tools/perf/tests/attr/test-record-branch-filter-any_call
index dbc55f2ab845..f943221f7825 100644
--- a/tools/perf/tests/attr/test-record-branch-filter-any_call
+++ b/tools/perf/tests/attr/test-record-branch-filter-any_call
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -j any_call kill >/dev/null 2>&1 3args = --no-bpf-event -j any_call kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-filter-any_ret b/tools/perf/tests/attr/test-record-branch-filter-any_ret
index a0824ff8e131..fd4f5b4154a9 100644
--- a/tools/perf/tests/attr/test-record-branch-filter-any_ret
+++ b/tools/perf/tests/attr/test-record-branch-filter-any_ret
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -j any_ret kill >/dev/null 2>&1 3args = --no-bpf-event -j any_ret kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-filter-hv b/tools/perf/tests/attr/test-record-branch-filter-hv
index f34d6f120181..4e52d685ebe1 100644
--- a/tools/perf/tests/attr/test-record-branch-filter-hv
+++ b/tools/perf/tests/attr/test-record-branch-filter-hv
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -j hv kill >/dev/null 2>&1 3args = --no-bpf-event -j hv kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-filter-ind_call b/tools/perf/tests/attr/test-record-branch-filter-ind_call
index b86a35232248..e08c6ab3796e 100644
--- a/tools/perf/tests/attr/test-record-branch-filter-ind_call
+++ b/tools/perf/tests/attr/test-record-branch-filter-ind_call
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -j ind_call kill >/dev/null 2>&1 3args = --no-bpf-event -j ind_call kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-filter-k b/tools/perf/tests/attr/test-record-branch-filter-k
index d3fbc5e1858a..b4b98f84fc2f 100644
--- a/tools/perf/tests/attr/test-record-branch-filter-k
+++ b/tools/perf/tests/attr/test-record-branch-filter-k
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -j k kill >/dev/null 2>&1 3args = --no-bpf-event -j k kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-branch-filter-u b/tools/perf/tests/attr/test-record-branch-filter-u
index a318f0dda173..fb9610edbb0d 100644
--- a/tools/perf/tests/attr/test-record-branch-filter-u
+++ b/tools/perf/tests/attr/test-record-branch-filter-u
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -j u kill >/dev/null 2>&1 3args = --no-bpf-event -j u kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-count b/tools/perf/tests/attr/test-record-count
index 34f6cc577263..5e9b9019d786 100644
--- a/tools/perf/tests/attr/test-record-count
+++ b/tools/perf/tests/attr/test-record-count
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -c 123 kill >/dev/null 2>&1 3args = --no-bpf-event -c 123 kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-data b/tools/perf/tests/attr/test-record-data
index a9cf2233b0ce..a99bb13149c2 100644
--- a/tools/perf/tests/attr/test-record-data
+++ b/tools/perf/tests/attr/test-record-data
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -d kill >/dev/null 2>&1 3args = --no-bpf-event -d kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-freq b/tools/perf/tests/attr/test-record-freq
index bf4cb459f0d5..89e29f6b2ae0 100644
--- a/tools/perf/tests/attr/test-record-freq
+++ b/tools/perf/tests/attr/test-record-freq
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -F 100 kill >/dev/null 2>&1 3args = --no-bpf-event -F 100 kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-graph-default b/tools/perf/tests/attr/test-record-graph-default
index 0b216e69760c..5d8234d50845 100644
--- a/tools/perf/tests/attr/test-record-graph-default
+++ b/tools/perf/tests/attr/test-record-graph-default
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -g kill >/dev/null 2>&1 3args = --no-bpf-event -g kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-graph-dwarf b/tools/perf/tests/attr/test-record-graph-dwarf
index da2fa73bd0a2..ae92061d611d 100644
--- a/tools/perf/tests/attr/test-record-graph-dwarf
+++ b/tools/perf/tests/attr/test-record-graph-dwarf
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = --call-graph dwarf -- kill >/dev/null 2>&1 3args = --no-bpf-event --call-graph dwarf -- kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-graph-fp b/tools/perf/tests/attr/test-record-graph-fp
index 625d190bb798..5630521c0b0f 100644
--- a/tools/perf/tests/attr/test-record-graph-fp
+++ b/tools/perf/tests/attr/test-record-graph-fp
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = --call-graph fp kill >/dev/null 2>&1 3args = --no-bpf-event --call-graph fp kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-group b/tools/perf/tests/attr/test-record-group
index 618ba1c17474..14ee60fd3f41 100644
--- a/tools/perf/tests/attr/test-record-group
+++ b/tools/perf/tests/attr/test-record-group
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = --group -e cycles,instructions kill >/dev/null 2>&1 3args = --no-bpf-event --group -e cycles,instructions kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event-1:base-record] 6[event-1:base-record]
diff --git a/tools/perf/tests/attr/test-record-group-sampling b/tools/perf/tests/attr/test-record-group-sampling
index f0729c454f16..300b9f7e6d69 100644
--- a/tools/perf/tests/attr/test-record-group-sampling
+++ b/tools/perf/tests/attr/test-record-group-sampling
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 3args = --no-bpf-event -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event-1:base-record] 6[event-1:base-record]
diff --git a/tools/perf/tests/attr/test-record-group1 b/tools/perf/tests/attr/test-record-group1
index 48e8bd12fe46..3ffe246e0228 100644
--- a/tools/perf/tests/attr/test-record-group1
+++ b/tools/perf/tests/attr/test-record-group1
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -e '{cycles,instructions}' kill >/dev/null 2>&1 3args = --no-bpf-event -e '{cycles,instructions}' kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event-1:base-record] 6[event-1:base-record]
diff --git a/tools/perf/tests/attr/test-record-no-buffering b/tools/perf/tests/attr/test-record-no-buffering
index aa3956d8fe20..583dcbb078ba 100644
--- a/tools/perf/tests/attr/test-record-no-buffering
+++ b/tools/perf/tests/attr/test-record-no-buffering
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = --no-buffering kill >/dev/null 2>&1 3args = --no-bpf-event --no-buffering kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-no-inherit b/tools/perf/tests/attr/test-record-no-inherit
index 560943decb87..15d1dc162e1c 100644
--- a/tools/perf/tests/attr/test-record-no-inherit
+++ b/tools/perf/tests/attr/test-record-no-inherit
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -i kill >/dev/null 2>&1 3args = --no-bpf-event -i kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-no-samples b/tools/perf/tests/attr/test-record-no-samples
index 8eb73ab639e0..596fbd6d5a2c 100644
--- a/tools/perf/tests/attr/test-record-no-samples
+++ b/tools/perf/tests/attr/test-record-no-samples
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -n kill >/dev/null 2>&1 3args = --no-bpf-event -n kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-period b/tools/perf/tests/attr/test-record-period
index 69bc748f0f27..119101154c5e 100644
--- a/tools/perf/tests/attr/test-record-period
+++ b/tools/perf/tests/attr/test-record-period
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -c 100 -P kill >/dev/null 2>&1 3args = --no-bpf-event -c 100 -P kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/attr/test-record-raw b/tools/perf/tests/attr/test-record-raw
index a188a614a44c..13a5f7860c78 100644
--- a/tools/perf/tests/attr/test-record-raw
+++ b/tools/perf/tests/attr/test-record-raw
@@ -1,6 +1,6 @@
1[config] 1[config]
2command = record 2command = record
3args = -R kill >/dev/null 2>&1 3args = --no-bpf-event -R kill >/dev/null 2>&1
4ret = 1 4ret = 1
5 5
6[event:base-record] 6[event:base-record]
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 6d598cc071ae..1a9c3becf5ff 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -18,7 +18,7 @@ static void testcase(void)
18 int i; 18 int i;
19 19
20 for (i = 0; i < NR_ITERS; i++) { 20 for (i = 0; i < NR_ITERS; i++) {
21 char proc_name[10]; 21 char proc_name[15];
22 22
23 snprintf(proc_name, sizeof(proc_name), "p:%d\n", i); 23 snprintf(proc_name, sizeof(proc_name), "p:%d\n", i);
24 prctl(PR_SET_NAME, proc_name); 24 prctl(PR_SET_NAME, proc_name);
diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c
index ea7acf403727..71f60c0f9faa 100644
--- a/tools/perf/tests/evsel-tp-sched.c
+++ b/tools/perf/tests/evsel-tp-sched.c
@@ -85,5 +85,6 @@ int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtes
85 if (perf_evsel__test_field(evsel, "target_cpu", 4, true)) 85 if (perf_evsel__test_field(evsel, "target_cpu", 4, true))
86 ret = -1; 86 ret = -1;
87 87
88 perf_evsel__delete(evsel);
88 return ret; 89 return ret;
89} 90}
diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c
index 01f0706995a9..9acc1e80b936 100644
--- a/tools/perf/tests/expr.c
+++ b/tools/perf/tests/expr.c
@@ -19,7 +19,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
19 const char *p; 19 const char *p;
20 const char **other; 20 const char **other;
21 double val; 21 double val;
22 int ret; 22 int i, ret;
23 struct parse_ctx ctx; 23 struct parse_ctx ctx;
24 int num_other; 24 int num_other;
25 25
@@ -56,6 +56,9 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
56 TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ")); 56 TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ"));
57 TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO")); 57 TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO"));
58 TEST_ASSERT_VAL("find other", other[3] == NULL); 58 TEST_ASSERT_VAL("find other", other[3] == NULL);
59
60 for (i = 0; i < num_other; i++)
61 free((void *)other[i]);
59 free((void *)other); 62 free((void *)other);
60 63
61 return 0; 64 return 0;
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c
index c531e6deb104..493ecb611540 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -45,7 +45,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int
45 if (IS_ERR(evsel)) { 45 if (IS_ERR(evsel)) {
46 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); 46 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
47 pr_debug("%s\n", errbuf); 47 pr_debug("%s\n", errbuf);
48 goto out_thread_map_delete; 48 goto out_cpu_map_delete;
49 } 49 }
50 50
51 if (perf_evsel__open(evsel, cpus, threads) < 0) { 51 if (perf_evsel__open(evsel, cpus, threads) < 0) {
@@ -119,6 +119,8 @@ out_close_fd:
119 perf_evsel__close_fd(evsel); 119 perf_evsel__close_fd(evsel);
120out_evsel_delete: 120out_evsel_delete:
121 perf_evsel__delete(evsel); 121 perf_evsel__delete(evsel);
122out_cpu_map_delete:
123 cpu_map__put(cpus);
122out_thread_map_delete: 124out_thread_map_delete:
123 thread_map__put(threads); 125 thread_map__put(threads);
124 return err; 126 return err;
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 4f75561424ed..4ad37d8c7d6a 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -611,14 +611,16 @@ void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence)
611 browser->top = browser->entries; 611 browser->top = browser->entries;
612 break; 612 break;
613 case SEEK_CUR: 613 case SEEK_CUR:
614 browser->top = browser->top + browser->top_idx + offset; 614 browser->top = (char **)browser->top + offset;
615 break; 615 break;
616 case SEEK_END: 616 case SEEK_END:
617 browser->top = browser->top + browser->nr_entries - 1 + offset; 617 browser->top = (char **)browser->entries + browser->nr_entries - 1 + offset;
618 break; 618 break;
619 default: 619 default:
620 return; 620 return;
621 } 621 }
622 assert((char **)browser->top < (char **)browser->entries + browser->nr_entries);
623 assert((char **)browser->top >= (char **)browser->entries);
622} 624}
623 625
624unsigned int ui_browser__argv_refresh(struct ui_browser *browser) 626unsigned int ui_browser__argv_refresh(struct ui_browser *browser)
@@ -630,7 +632,9 @@ unsigned int ui_browser__argv_refresh(struct ui_browser *browser)
630 browser->top = browser->entries; 632 browser->top = browser->entries;
631 633
632 pos = (char **)browser->top; 634 pos = (char **)browser->top;
633 while (idx < browser->nr_entries) { 635 while (idx < browser->nr_entries &&
636 row < (unsigned)SLtt_Screen_Rows - 1) {
637 assert(pos < (char **)browser->entries + browser->nr_entries);
634 if (!browser->filter || !browser->filter(browser, *pos)) { 638 if (!browser->filter || !browser->filter(browser, *pos)) {
635 ui_browser__gotorc(browser, row, 0); 639 ui_browser__gotorc(browser, row, 0);
636 browser->write(browser, pos, row); 640 browser->write(browser, pos, row);
diff --git a/tools/perf/ui/browsers/Build b/tools/perf/ui/browsers/Build
index 8fee56b46502..fdf86f7981ca 100644
--- a/tools/perf/ui/browsers/Build
+++ b/tools/perf/ui/browsers/Build
@@ -3,6 +3,7 @@ perf-y += hists.o
3perf-y += map.o 3perf-y += map.o
4perf-y += scripts.o 4perf-y += scripts.o
5perf-y += header.o 5perf-y += header.o
6perf-y += res_sample.o
6 7
7CFLAGS_annotate.o += -DENABLE_SLFUTURE_CONST 8CFLAGS_annotate.o += -DENABLE_SLFUTURE_CONST
8CFLAGS_hists.o += -DENABLE_SLFUTURE_CONST 9CFLAGS_hists.o += -DENABLE_SLFUTURE_CONST
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 35bdfd8b1e71..98d934a36d86 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -750,7 +750,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
750 continue; 750 continue;
751 case 'r': 751 case 'r':
752 { 752 {
753 script_browse(NULL); 753 script_browse(NULL, NULL);
754 continue; 754 continue;
755 } 755 }
756 case 'k': 756 case 'k':
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index aef800d97ea1..3421ecbdd3f0 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -7,6 +7,7 @@
7#include <string.h> 7#include <string.h>
8#include <linux/rbtree.h> 8#include <linux/rbtree.h>
9#include <sys/ttydefaults.h> 9#include <sys/ttydefaults.h>
10#include <linux/time64.h>
10 11
11#include "../../util/callchain.h" 12#include "../../util/callchain.h"
12#include "../../util/evsel.h" 13#include "../../util/evsel.h"
@@ -30,6 +31,7 @@
30#include "srcline.h" 31#include "srcline.h"
31#include "string2.h" 32#include "string2.h"
32#include "units.h" 33#include "units.h"
34#include "time-utils.h"
33 35
34#include "sane_ctype.h" 36#include "sane_ctype.h"
35 37
@@ -1224,6 +1226,8 @@ void hist_browser__init_hpp(void)
1224 hist_browser__hpp_color_overhead_guest_us; 1226 hist_browser__hpp_color_overhead_guest_us;
1225 perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color = 1227 perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color =
1226 hist_browser__hpp_color_overhead_acc; 1228 hist_browser__hpp_color_overhead_acc;
1229
1230 res_sample_init();
1227} 1231}
1228 1232
1229static int hist_browser__show_entry(struct hist_browser *browser, 1233static int hist_browser__show_entry(struct hist_browser *browser,
@@ -2338,9 +2342,12 @@ close_file_and_continue:
2338} 2342}
2339 2343
2340struct popup_action { 2344struct popup_action {
2345 unsigned long time;
2341 struct thread *thread; 2346 struct thread *thread;
2342 struct map_symbol ms; 2347 struct map_symbol ms;
2343 int socket; 2348 int socket;
2349 struct perf_evsel *evsel;
2350 enum rstype rstype;
2344 2351
2345 int (*fn)(struct hist_browser *browser, struct popup_action *act); 2352 int (*fn)(struct hist_browser *browser, struct popup_action *act);
2346}; 2353};
@@ -2527,46 +2534,137 @@ static int
2527do_run_script(struct hist_browser *browser __maybe_unused, 2534do_run_script(struct hist_browser *browser __maybe_unused,
2528 struct popup_action *act) 2535 struct popup_action *act)
2529{ 2536{
2530 char script_opt[64]; 2537 char *script_opt;
2531 memset(script_opt, 0, sizeof(script_opt)); 2538 int len;
2539 int n = 0;
2532 2540
2541 len = 100;
2542 if (act->thread)
2543 len += strlen(thread__comm_str(act->thread));
2544 else if (act->ms.sym)
2545 len += strlen(act->ms.sym->name);
2546 script_opt = malloc(len);
2547 if (!script_opt)
2548 return -1;
2549
2550 script_opt[0] = 0;
2533 if (act->thread) { 2551 if (act->thread) {
2534 scnprintf(script_opt, sizeof(script_opt), " -c %s ", 2552 n = scnprintf(script_opt, len, " -c %s ",
2535 thread__comm_str(act->thread)); 2553 thread__comm_str(act->thread));
2536 } else if (act->ms.sym) { 2554 } else if (act->ms.sym) {
2537 scnprintf(script_opt, sizeof(script_opt), " -S %s ", 2555 n = scnprintf(script_opt, len, " -S %s ",
2538 act->ms.sym->name); 2556 act->ms.sym->name);
2539 } 2557 }
2540 2558
2541 script_browse(script_opt); 2559 if (act->time) {
2560 char start[32], end[32];
2561 unsigned long starttime = act->time;
2562 unsigned long endtime = act->time + symbol_conf.time_quantum;
2563
2564 if (starttime == endtime) { /* Display 1ms as fallback */
2565 starttime -= 1*NSEC_PER_MSEC;
2566 endtime += 1*NSEC_PER_MSEC;
2567 }
2568 timestamp__scnprintf_usec(starttime, start, sizeof start);
2569 timestamp__scnprintf_usec(endtime, end, sizeof end);
2570 n += snprintf(script_opt + n, len - n, " --time %s,%s", start, end);
2571 }
2572
2573 script_browse(script_opt, act->evsel);
2574 free(script_opt);
2542 return 0; 2575 return 0;
2543} 2576}
2544 2577
2545static int 2578static int
2546add_script_opt(struct hist_browser *browser __maybe_unused, 2579do_res_sample_script(struct hist_browser *browser __maybe_unused,
2580 struct popup_action *act)
2581{
2582 struct hist_entry *he;
2583
2584 he = hist_browser__selected_entry(browser);
2585 res_sample_browse(he->res_samples, he->num_res, act->evsel, act->rstype);
2586 return 0;
2587}
2588
2589static int
2590add_script_opt_2(struct hist_browser *browser __maybe_unused,
2547 struct popup_action *act, char **optstr, 2591 struct popup_action *act, char **optstr,
2548 struct thread *thread, struct symbol *sym) 2592 struct thread *thread, struct symbol *sym,
2593 struct perf_evsel *evsel, const char *tstr)
2549{ 2594{
2595
2550 if (thread) { 2596 if (thread) {
2551 if (asprintf(optstr, "Run scripts for samples of thread [%s]", 2597 if (asprintf(optstr, "Run scripts for samples of thread [%s]%s",
2552 thread__comm_str(thread)) < 0) 2598 thread__comm_str(thread), tstr) < 0)
2553 return 0; 2599 return 0;
2554 } else if (sym) { 2600 } else if (sym) {
2555 if (asprintf(optstr, "Run scripts for samples of symbol [%s]", 2601 if (asprintf(optstr, "Run scripts for samples of symbol [%s]%s",
2556 sym->name) < 0) 2602 sym->name, tstr) < 0)
2557 return 0; 2603 return 0;
2558 } else { 2604 } else {
2559 if (asprintf(optstr, "Run scripts for all samples") < 0) 2605 if (asprintf(optstr, "Run scripts for all samples%s", tstr) < 0)
2560 return 0; 2606 return 0;
2561 } 2607 }
2562 2608
2563 act->thread = thread; 2609 act->thread = thread;
2564 act->ms.sym = sym; 2610 act->ms.sym = sym;
2611 act->evsel = evsel;
2565 act->fn = do_run_script; 2612 act->fn = do_run_script;
2566 return 1; 2613 return 1;
2567} 2614}
2568 2615
2569static int 2616static int
2617add_script_opt(struct hist_browser *browser,
2618 struct popup_action *act, char **optstr,
2619 struct thread *thread, struct symbol *sym,
2620 struct perf_evsel *evsel)
2621{
2622 int n, j;
2623 struct hist_entry *he;
2624
2625 n = add_script_opt_2(browser, act, optstr, thread, sym, evsel, "");
2626
2627 he = hist_browser__selected_entry(browser);
2628 if (sort_order && strstr(sort_order, "time")) {
2629 char tstr[128];
2630
2631 optstr++;
2632 act++;
2633 j = sprintf(tstr, " in ");
2634 j += timestamp__scnprintf_usec(he->time, tstr + j,
2635 sizeof tstr - j);
2636 j += sprintf(tstr + j, "-");
2637 timestamp__scnprintf_usec(he->time + symbol_conf.time_quantum,
2638 tstr + j, sizeof tstr - j);
2639 n += add_script_opt_2(browser, act, optstr, thread, sym,
2640 evsel, tstr);
2641 act->time = he->time;
2642 }
2643 return n;
2644}
2645
2646static int
2647add_res_sample_opt(struct hist_browser *browser __maybe_unused,
2648 struct popup_action *act, char **optstr,
2649 struct res_sample *res_sample,
2650 struct perf_evsel *evsel,
2651 enum rstype type)
2652{
2653 if (!res_sample)
2654 return 0;
2655
2656 if (asprintf(optstr, "Show context for individual samples %s",
2657 type == A_ASM ? "with assembler" :
2658 type == A_SOURCE ? "with source" : "") < 0)
2659 return 0;
2660
2661 act->fn = do_res_sample_script;
2662 act->evsel = evsel;
2663 act->rstype = type;
2664 return 1;
2665}
2666
2667static int
2570do_switch_data(struct hist_browser *browser __maybe_unused, 2668do_switch_data(struct hist_browser *browser __maybe_unused,
2571 struct popup_action *act __maybe_unused) 2669 struct popup_action *act __maybe_unused)
2572{ 2670{
@@ -3031,7 +3129,7 @@ skip_annotation:
3031 nr_options += add_script_opt(browser, 3129 nr_options += add_script_opt(browser,
3032 &actions[nr_options], 3130 &actions[nr_options],
3033 &options[nr_options], 3131 &options[nr_options],
3034 thread, NULL); 3132 thread, NULL, evsel);
3035 } 3133 }
3036 /* 3134 /*
3037 * Note that browser->selection != NULL 3135 * Note that browser->selection != NULL
@@ -3046,11 +3144,24 @@ skip_annotation:
3046 nr_options += add_script_opt(browser, 3144 nr_options += add_script_opt(browser,
3047 &actions[nr_options], 3145 &actions[nr_options],
3048 &options[nr_options], 3146 &options[nr_options],
3049 NULL, browser->selection->sym); 3147 NULL, browser->selection->sym,
3148 evsel);
3050 } 3149 }
3051 } 3150 }
3052 nr_options += add_script_opt(browser, &actions[nr_options], 3151 nr_options += add_script_opt(browser, &actions[nr_options],
3053 &options[nr_options], NULL, NULL); 3152 &options[nr_options], NULL, NULL, evsel);
3153 nr_options += add_res_sample_opt(browser, &actions[nr_options],
3154 &options[nr_options],
3155 hist_browser__selected_entry(browser)->res_samples,
3156 evsel, A_NORMAL);
3157 nr_options += add_res_sample_opt(browser, &actions[nr_options],
3158 &options[nr_options],
3159 hist_browser__selected_entry(browser)->res_samples,
3160 evsel, A_ASM);
3161 nr_options += add_res_sample_opt(browser, &actions[nr_options],
3162 &options[nr_options],
3163 hist_browser__selected_entry(browser)->res_samples,
3164 evsel, A_SOURCE);
3054 nr_options += add_switch_opt(browser, &actions[nr_options], 3165 nr_options += add_switch_opt(browser, &actions[nr_options],
3055 &options[nr_options]); 3166 &options[nr_options]);
3056skip_scripting: 3167skip_scripting:
diff --git a/tools/perf/ui/browsers/res_sample.c b/tools/perf/ui/browsers/res_sample.c
new file mode 100644
index 000000000000..c0dd73176d42
--- /dev/null
+++ b/tools/perf/ui/browsers/res_sample.c
@@ -0,0 +1,91 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Display a menu with individual samples to browse with perf script */
3#include "util.h"
4#include "hist.h"
5#include "evsel.h"
6#include "hists.h"
7#include "sort.h"
8#include "config.h"
9#include "time-utils.h"
10#include <linux/time64.h>
11
12static u64 context_len = 10 * NSEC_PER_MSEC;
13
14static int res_sample_config(const char *var, const char *value, void *data __maybe_unused)
15{
16 if (!strcmp(var, "samples.context"))
17 return perf_config_u64(&context_len, var, value);
18 return 0;
19}
20
21void res_sample_init(void)
22{
23 perf_config(res_sample_config, NULL);
24}
25
26int res_sample_browse(struct res_sample *res_samples, int num_res,
27 struct perf_evsel *evsel, enum rstype rstype)
28{
29 char **names;
30 int i, n;
31 int choice;
32 char *cmd;
33 char pbuf[256], tidbuf[32], cpubuf[32];
34 const char *perf = perf_exe(pbuf, sizeof pbuf);
35 char trange[128], tsample[64];
36 struct res_sample *r;
37 char extra_format[256];
38
39 names = calloc(num_res, sizeof(char *));
40 if (!names)
41 return -1;
42 for (i = 0; i < num_res; i++) {
43 char tbuf[64];
44
45 timestamp__scnprintf_nsec(res_samples[i].time, tbuf, sizeof tbuf);
46 if (asprintf(&names[i], "%s: CPU %d tid %d", tbuf,
47 res_samples[i].cpu, res_samples[i].tid) < 0) {
48 while (--i >= 0)
49 free(names[i]);
50 free(names);
51 return -1;
52 }
53 }
54 choice = ui__popup_menu(num_res, names);
55 for (i = 0; i < num_res; i++)
56 free(names[i]);
57 free(names);
58
59 if (choice < 0 || choice >= num_res)
60 return -1;
61 r = &res_samples[choice];
62
63 n = timestamp__scnprintf_nsec(r->time - context_len, trange, sizeof trange);
64 trange[n++] = ',';
65 timestamp__scnprintf_nsec(r->time + context_len, trange + n, sizeof trange - n);
66
67 timestamp__scnprintf_nsec(r->time, tsample, sizeof tsample);
68
69 attr_to_script(extra_format, &evsel->attr);
70
71 if (asprintf(&cmd, "%s script %s%s --time %s %s%s %s%s --ns %s %s %s %s %s | less +/%s",
72 perf,
73 input_name ? "-i " : "",
74 input_name ? input_name : "",
75 trange,
76 r->cpu >= 0 ? "--cpu " : "",
77 r->cpu >= 0 ? (sprintf(cpubuf, "%d", r->cpu), cpubuf) : "",
78 r->tid ? "--tid " : "",
79 r->tid ? (sprintf(tidbuf, "%d", r->tid), tidbuf) : "",
80 extra_format,
81 rstype == A_ASM ? "-F +insn --xed" :
82 rstype == A_SOURCE ? "-F +srcline,+srccode" : "",
83 symbol_conf.inline_name ? "--inline" : "",
84 "--show-lost-events ",
85 r->tid ? "--show-switch-events --show-task-events " : "",
86 tsample) < 0)
87 return -1;
88 run_script(cmd);
89 free(cmd);
90 return 0;
91}
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index 90a32ac69e76..27cf3ab88d13 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -1,34 +1,12 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include <elf.h>
3#include <inttypes.h>
4#include <sys/ttydefaults.h>
5#include <string.h>
6#include "../../util/sort.h" 2#include "../../util/sort.h"
7#include "../../util/util.h" 3#include "../../util/util.h"
8#include "../../util/hist.h" 4#include "../../util/hist.h"
9#include "../../util/debug.h" 5#include "../../util/debug.h"
10#include "../../util/symbol.h" 6#include "../../util/symbol.h"
11#include "../browser.h" 7#include "../browser.h"
12#include "../helpline.h"
13#include "../libslang.h" 8#include "../libslang.h"
14 9#include "config.h"
15/* 2048 lines should be enough for a script output */
16#define MAX_LINES 2048
17
18/* 160 bytes for one output line */
19#define AVERAGE_LINE_LEN 160
20
21struct script_line {
22 struct list_head node;
23 char line[AVERAGE_LINE_LEN];
24};
25
26struct perf_script_browser {
27 struct ui_browser b;
28 struct list_head entries;
29 const char *script_name;
30 int nr_lines;
31};
32 10
33#define SCRIPT_NAMELEN 128 11#define SCRIPT_NAMELEN 128
34#define SCRIPT_MAX_NO 64 12#define SCRIPT_MAX_NO 64
@@ -40,149 +18,169 @@ struct perf_script_browser {
40 */ 18 */
41#define SCRIPT_FULLPATH_LEN 256 19#define SCRIPT_FULLPATH_LEN 256
42 20
21struct script_config {
22 const char **names;
23 char **paths;
24 int index;
25 const char *perf;
26 char extra_format[256];
27};
28
29void attr_to_script(char *extra_format, struct perf_event_attr *attr)
30{
31 extra_format[0] = 0;
32 if (attr->read_format & PERF_FORMAT_GROUP)
33 strcat(extra_format, " -F +metric");
34 if (attr->sample_type & PERF_SAMPLE_BRANCH_STACK)
35 strcat(extra_format, " -F +brstackinsn --xed");
36 if (attr->sample_type & PERF_SAMPLE_REGS_INTR)
37 strcat(extra_format, " -F +iregs");
38 if (attr->sample_type & PERF_SAMPLE_REGS_USER)
39 strcat(extra_format, " -F +uregs");
40 if (attr->sample_type & PERF_SAMPLE_PHYS_ADDR)
41 strcat(extra_format, " -F +phys_addr");
42}
43
44static int add_script_option(const char *name, const char *opt,
45 struct script_config *c)
46{
47 c->names[c->index] = name;
48 if (asprintf(&c->paths[c->index],
49 "%s script %s -F +metric %s %s",
50 c->perf, opt, symbol_conf.inline_name ? " --inline" : "",
51 c->extra_format) < 0)
52 return -1;
53 c->index++;
54 return 0;
55}
56
57static int scripts_config(const char *var, const char *value, void *data)
58{
59 struct script_config *c = data;
60
61 if (!strstarts(var, "scripts."))
62 return -1;
63 if (c->index >= SCRIPT_MAX_NO)
64 return -1;
65 c->names[c->index] = strdup(var + 7);
66 if (!c->names[c->index])
67 return -1;
68 if (asprintf(&c->paths[c->index], "%s %s", value,
69 c->extra_format) < 0)
70 return -1;
71 c->index++;
72 return 0;
73}
74
43/* 75/*
44 * When success, will copy the full path of the selected script 76 * When success, will copy the full path of the selected script
45 * into the buffer pointed by script_name, and return 0. 77 * into the buffer pointed by script_name, and return 0.
46 * Return -1 on failure. 78 * Return -1 on failure.
47 */ 79 */
48static int list_scripts(char *script_name) 80static int list_scripts(char *script_name, bool *custom,
81 struct perf_evsel *evsel)
49{ 82{
50 char *buf, *names[SCRIPT_MAX_NO], *paths[SCRIPT_MAX_NO]; 83 char *buf, *paths[SCRIPT_MAX_NO], *names[SCRIPT_MAX_NO];
51 int i, num, choice, ret = -1; 84 int i, num, choice;
85 int ret = 0;
86 int max_std, custom_perf;
87 char pbuf[256];
88 const char *perf = perf_exe(pbuf, sizeof pbuf);
89 struct script_config scriptc = {
90 .names = (const char **)names,
91 .paths = paths,
92 .perf = perf
93 };
94
95 script_name[0] = 0;
52 96
53 /* Preset the script name to SCRIPT_NAMELEN */ 97 /* Preset the script name to SCRIPT_NAMELEN */
54 buf = malloc(SCRIPT_MAX_NO * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN)); 98 buf = malloc(SCRIPT_MAX_NO * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN));
55 if (!buf) 99 if (!buf)
56 return ret; 100 return -1;
57 101
58 for (i = 0; i < SCRIPT_MAX_NO; i++) { 102 if (evsel)
59 names[i] = buf + i * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN); 103 attr_to_script(scriptc.extra_format, &evsel->attr);
104 add_script_option("Show individual samples", "", &scriptc);
105 add_script_option("Show individual samples with assembler", "-F +insn --xed",
106 &scriptc);
107 add_script_option("Show individual samples with source", "-F +srcline,+srccode",
108 &scriptc);
109 perf_config(scripts_config, &scriptc);
110 custom_perf = scriptc.index;
111 add_script_option("Show samples with custom perf script arguments", "", &scriptc);
112 i = scriptc.index;
113 max_std = i;
114
115 for (; i < SCRIPT_MAX_NO; i++) {
116 names[i] = buf + (i - max_std) * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN);
60 paths[i] = names[i] + SCRIPT_NAMELEN; 117 paths[i] = names[i] + SCRIPT_NAMELEN;
61 } 118 }
62 119
63 num = find_scripts(names, paths); 120 num = find_scripts(names + max_std, paths + max_std, SCRIPT_MAX_NO - max_std,
64 if (num > 0) { 121 SCRIPT_FULLPATH_LEN);
65 choice = ui__popup_menu(num, names); 122 if (num < 0)
66 if (choice < num && choice >= 0) { 123 num = 0;
67 strcpy(script_name, paths[choice]); 124 choice = ui__popup_menu(num + max_std, (char * const *)names);
68 ret = 0; 125 if (choice < 0) {
69 } 126 ret = -1;
127 goto out;
70 } 128 }
129 if (choice == custom_perf) {
130 char script_args[50];
131 int key = ui_browser__input_window("perf script command",
132 "Enter perf script command line (without perf script prefix)",
133 script_args, "", 0);
134 if (key != K_ENTER)
135 return -1;
136 sprintf(script_name, "%s script %s", perf, script_args);
137 } else if (choice < num + max_std) {
138 strcpy(script_name, paths[choice]);
139 }
140 *custom = choice >= max_std;
71 141
142out:
72 free(buf); 143 free(buf);
144 for (i = 0; i < max_std; i++)
145 free(paths[i]);
73 return ret; 146 return ret;
74} 147}
75 148
76static void script_browser__write(struct ui_browser *browser, 149void run_script(char *cmd)
77 void *entry, int row)
78{ 150{
79 struct script_line *sline = list_entry(entry, struct script_line, node); 151 pr_debug("Running %s\n", cmd);
80 bool current_entry = ui_browser__is_current_entry(browser, row); 152 SLang_reset_tty();
81 153 if (system(cmd) < 0)
82 ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED : 154 pr_warning("Cannot run %s\n", cmd);
83 HE_COLORSET_NORMAL); 155 /*
84 156 * SLang doesn't seem to reset the whole terminal, so be more
85 ui_browser__write_nstring(browser, sline->line, browser->width); 157 * forceful to get back to the original state.
158 */
159 printf("\033[c\033[H\033[J");
160 fflush(stdout);
161 SLang_init_tty(0, 0, 0);
162 SLsmg_refresh();
86} 163}
87 164
88static int script_browser__run(struct perf_script_browser *browser) 165int script_browse(const char *script_opt, struct perf_evsel *evsel)
89{ 166{
90 int key; 167 char *cmd, script_name[SCRIPT_FULLPATH_LEN];
168 bool custom = false;
91 169
92 if (ui_browser__show(&browser->b, browser->script_name, 170 memset(script_name, 0, SCRIPT_FULLPATH_LEN);
93 "Press ESC to exit") < 0) 171 if (list_scripts(script_name, &custom, evsel))
94 return -1; 172 return -1;
95 173
96 while (1) { 174 if (asprintf(&cmd, "%s%s %s %s%s 2>&1 | less",
97 key = ui_browser__run(&browser->b, 0); 175 custom ? "perf script -s " : "",
98 176 script_name,
99 /* We can add some special key handling here if needed */ 177 script_opt ? script_opt : "",
100 break; 178 input_name ? "-i " : "",
101 } 179 input_name ? input_name : "") < 0)
102
103 ui_browser__hide(&browser->b);
104 return key;
105}
106
107
108int script_browse(const char *script_opt)
109{
110 char cmd[SCRIPT_FULLPATH_LEN*2], script_name[SCRIPT_FULLPATH_LEN];
111 char *line = NULL;
112 size_t len = 0;
113 ssize_t retlen;
114 int ret = -1, nr_entries = 0;
115 FILE *fp;
116 void *buf;
117 struct script_line *sline;
118
119 struct perf_script_browser script = {
120 .b = {
121 .refresh = ui_browser__list_head_refresh,
122 .seek = ui_browser__list_head_seek,
123 .write = script_browser__write,
124 },
125 .script_name = script_name,
126 };
127
128 INIT_LIST_HEAD(&script.entries);
129
130 /* Save each line of the output in one struct script_line object. */
131 buf = zalloc((sizeof(*sline)) * MAX_LINES);
132 if (!buf)
133 return -1; 180 return -1;
134 sline = buf;
135
136 memset(script_name, 0, SCRIPT_FULLPATH_LEN);
137 if (list_scripts(script_name))
138 goto exit;
139
140 sprintf(cmd, "perf script -s %s ", script_name);
141 181
142 if (script_opt) 182 run_script(cmd);
143 strcat(cmd, script_opt); 183 free(cmd);
144 184
145 if (input_name) { 185 return 0;
146 strcat(cmd, " -i ");
147 strcat(cmd, input_name);
148 }
149
150 strcat(cmd, " 2>&1");
151
152 fp = popen(cmd, "r");
153 if (!fp)
154 goto exit;
155
156 while ((retlen = getline(&line, &len, fp)) != -1) {
157 strncpy(sline->line, line, AVERAGE_LINE_LEN);
158
159 /* If one output line is very large, just cut it short */
160 if (retlen >= AVERAGE_LINE_LEN) {
161 sline->line[AVERAGE_LINE_LEN - 1] = '\0';
162 sline->line[AVERAGE_LINE_LEN - 2] = '\n';
163 }
164 list_add_tail(&sline->node, &script.entries);
165
166 if (script.b.width < retlen)
167 script.b.width = retlen;
168
169 if (nr_entries++ >= MAX_LINES - 1)
170 break;
171 sline++;
172 }
173
174 if (script.b.width > AVERAGE_LINE_LEN)
175 script.b.width = AVERAGE_LINE_LEN;
176
177 free(line);
178 pclose(fp);
179
180 script.nr_lines = nr_entries;
181 script.b.nr_entries = nr_entries;
182 script.b.entries = &script.entries;
183
184 ret = script_browser__run(&script);
185exit:
186 free(buf);
187 return ret;
188} 186}
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 5f6dbbf5d749..c8b01176c9e1 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -10,6 +10,10 @@
10#include <errno.h> 10#include <errno.h>
11#include <inttypes.h> 11#include <inttypes.h>
12#include <libgen.h> 12#include <libgen.h>
13#include <bpf/bpf.h>
14#include <bpf/btf.h>
15#include <bpf/libbpf.h>
16#include <linux/btf.h>
13#include "util.h" 17#include "util.h"
14#include "ui/ui.h" 18#include "ui/ui.h"
15#include "sort.h" 19#include "sort.h"
@@ -24,6 +28,7 @@
24#include "annotate.h" 28#include "annotate.h"
25#include "evsel.h" 29#include "evsel.h"
26#include "evlist.h" 30#include "evlist.h"
31#include "bpf-event.h"
27#include "block-range.h" 32#include "block-range.h"
28#include "string2.h" 33#include "string2.h"
29#include "arch/common.h" 34#include "arch/common.h"
@@ -31,6 +36,7 @@
31#include <pthread.h> 36#include <pthread.h>
32#include <linux/bitops.h> 37#include <linux/bitops.h>
33#include <linux/kernel.h> 38#include <linux/kernel.h>
39#include <bpf/libbpf.h>
34 40
35/* FIXME: For the HE_COLORSET */ 41/* FIXME: For the HE_COLORSET */
36#include "ui/browser.h" 42#include "ui/browser.h"
@@ -1615,6 +1621,9 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *
1615 " --vmlinux vmlinux\n", build_id_msg ?: ""); 1621 " --vmlinux vmlinux\n", build_id_msg ?: "");
1616 } 1622 }
1617 break; 1623 break;
1624 case SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF:
1625 scnprintf(buf, buflen, "Please link with binutils's libopcode to enable BPF annotation");
1626 break;
1618 default: 1627 default:
1619 scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum); 1628 scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum);
1620 break; 1629 break;
@@ -1674,6 +1683,156 @@ fallback:
1674 return 0; 1683 return 0;
1675} 1684}
1676 1685
1686#if defined(HAVE_LIBBFD_SUPPORT) && defined(HAVE_LIBBPF_SUPPORT)
1687#define PACKAGE "perf"
1688#include <bfd.h>
1689#include <dis-asm.h>
1690
1691static int symbol__disassemble_bpf(struct symbol *sym,
1692 struct annotate_args *args)
1693{
1694 struct annotation *notes = symbol__annotation(sym);
1695 struct annotation_options *opts = args->options;
1696 struct bpf_prog_info_linear *info_linear;
1697 struct bpf_prog_linfo *prog_linfo = NULL;
1698 struct bpf_prog_info_node *info_node;
1699 int len = sym->end - sym->start;
1700 disassembler_ftype disassemble;
1701 struct map *map = args->ms.map;
1702 struct disassemble_info info;
1703 struct dso *dso = map->dso;
1704 int pc = 0, count, sub_id;
1705 struct btf *btf = NULL;
1706 char tpath[PATH_MAX];
1707 size_t buf_size;
1708 int nr_skip = 0;
1709 int ret = -1;
1710 char *buf;
1711 bfd *bfdf;
1712 FILE *s;
1713
1714 if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO)
1715 return -1;
1716
1717 pr_debug("%s: handling sym %s addr %lx len %lx\n", __func__,
1718 sym->name, sym->start, sym->end - sym->start);
1719
1720 memset(tpath, 0, sizeof(tpath));
1721 perf_exe(tpath, sizeof(tpath));
1722
1723 bfdf = bfd_openr(tpath, NULL);
1724 assert(bfdf);
1725 assert(bfd_check_format(bfdf, bfd_object));
1726
1727 s = open_memstream(&buf, &buf_size);
1728 if (!s)
1729 goto out;
1730 init_disassemble_info(&info, s,
1731 (fprintf_ftype) fprintf);
1732
1733 info.arch = bfd_get_arch(bfdf);
1734 info.mach = bfd_get_mach(bfdf);
1735
1736 info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env,
1737 dso->bpf_prog.id);
1738 if (!info_node)
1739 goto out;
1740 info_linear = info_node->info_linear;
1741 sub_id = dso->bpf_prog.sub_id;
1742
1743 info.buffer = (void *)(info_linear->info.jited_prog_insns);
1744 info.buffer_length = info_linear->info.jited_prog_len;
1745
1746 if (info_linear->info.nr_line_info)
1747 prog_linfo = bpf_prog_linfo__new(&info_linear->info);
1748
1749 if (info_linear->info.btf_id) {
1750 struct btf_node *node;
1751
1752 node = perf_env__find_btf(dso->bpf_prog.env,
1753 info_linear->info.btf_id);
1754 if (node)
1755 btf = btf__new((__u8 *)(node->data),
1756 node->data_size);
1757 }
1758
1759 disassemble_init_for_target(&info);
1760
1761#ifdef DISASM_FOUR_ARGS_SIGNATURE
1762 disassemble = disassembler(info.arch,
1763 bfd_big_endian(bfdf),
1764 info.mach,
1765 bfdf);
1766#else
1767 disassemble = disassembler(bfdf);
1768#endif
1769 assert(disassemble);
1770
1771 fflush(s);
1772 do {
1773 const struct bpf_line_info *linfo = NULL;
1774 struct disasm_line *dl;
1775 size_t prev_buf_size;
1776 const char *srcline;
1777 u64 addr;
1778
1779 addr = pc + ((u64 *)(info_linear->info.jited_ksyms))[sub_id];
1780 count = disassemble(pc, &info);
1781
1782 if (prog_linfo)
1783 linfo = bpf_prog_linfo__lfind_addr_func(prog_linfo,
1784 addr, sub_id,
1785 nr_skip);
1786
1787 if (linfo && btf) {
1788 srcline = btf__name_by_offset(btf, linfo->line_off);
1789 nr_skip++;
1790 } else
1791 srcline = NULL;
1792
1793 fprintf(s, "\n");
1794 prev_buf_size = buf_size;
1795 fflush(s);
1796
1797 if (!opts->hide_src_code && srcline) {
1798 args->offset = -1;
1799 args->line = strdup(srcline);
1800 args->line_nr = 0;
1801 args->ms.sym = sym;
1802 dl = disasm_line__new(args);
1803 if (dl) {
1804 annotation_line__add(&dl->al,
1805 &notes->src->source);
1806 }
1807 }
1808
1809 args->offset = pc;
1810 args->line = buf + prev_buf_size;
1811 args->line_nr = 0;
1812 args->ms.sym = sym;
1813 dl = disasm_line__new(args);
1814 if (dl)
1815 annotation_line__add(&dl->al, &notes->src->source);
1816
1817 pc += count;
1818 } while (count > 0 && pc < len);
1819
1820 ret = 0;
1821out:
1822 free(prog_linfo);
1823 free(btf);
1824 fclose(s);
1825 bfd_close(bfdf);
1826 return ret;
1827}
1828#else // defined(HAVE_LIBBFD_SUPPORT) && defined(HAVE_LIBBPF_SUPPORT)
1829static int symbol__disassemble_bpf(struct symbol *sym __maybe_unused,
1830 struct annotate_args *args __maybe_unused)
1831{
1832 return SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF;
1833}
1834#endif // defined(HAVE_LIBBFD_SUPPORT) && defined(HAVE_LIBBPF_SUPPORT)
1835
1677static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) 1836static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
1678{ 1837{
1679 struct annotation_options *opts = args->options; 1838 struct annotation_options *opts = args->options;
@@ -1701,7 +1860,9 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
1701 pr_debug("annotating [%p] %30s : [%p] %30s\n", 1860 pr_debug("annotating [%p] %30s : [%p] %30s\n",
1702 dso, dso->long_name, sym, sym->name); 1861 dso, dso->long_name, sym, sym->name);
1703 1862
1704 if (dso__is_kcore(dso)) { 1863 if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) {
1864 return symbol__disassemble_bpf(sym, args);
1865 } else if (dso__is_kcore(dso)) {
1705 kce.kcore_filename = symfs_filename; 1866 kce.kcore_filename = symfs_filename;
1706 kce.addr = map__rip_2objdump(map, sym->start); 1867 kce.addr = map__rip_2objdump(map, sym->start);
1707 kce.offs = sym->start; 1868 kce.offs = sym->start;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index df34fe483164..5bc0cf655d37 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -369,6 +369,7 @@ enum symbol_disassemble_errno {
369 __SYMBOL_ANNOTATE_ERRNO__START = -10000, 369 __SYMBOL_ANNOTATE_ERRNO__START = -10000,
370 370
371 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START, 371 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START,
372 SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
372 373
373 __SYMBOL_ANNOTATE_ERRNO__END, 374 __SYMBOL_ANNOTATE_ERRNO__END,
374}; 375};
diff --git a/tools/perf/util/archinsn.h b/tools/perf/util/archinsn.h
new file mode 100644
index 000000000000..448cbb6b8d7e
--- /dev/null
+++ b/tools/perf/util/archinsn.h
@@ -0,0 +1,12 @@
1#ifndef INSN_H
2#define INSN_H 1
3
4struct perf_sample;
5struct machine;
6struct thread;
7
8void arch_fetch_insn(struct perf_sample *sample,
9 struct thread *thread,
10 struct machine *machine);
11
12#endif
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index 028c8ec1f62a..2a4a0da35632 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -3,11 +3,17 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <bpf/bpf.h> 4#include <bpf/bpf.h>
5#include <bpf/btf.h> 5#include <bpf/btf.h>
6#include <bpf/libbpf.h>
6#include <linux/btf.h> 7#include <linux/btf.h>
8#include <linux/err.h>
7#include "bpf-event.h" 9#include "bpf-event.h"
8#include "debug.h" 10#include "debug.h"
9#include "symbol.h" 11#include "symbol.h"
10#include "machine.h" 12#include "machine.h"
13#include "env.h"
14#include "session.h"
15#include "map.h"
16#include "evlist.h"
11 17
12#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr)) 18#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr))
13 19
@@ -21,15 +27,122 @@ static int snprintf_hex(char *buf, size_t size, unsigned char *data, size_t len)
21 return ret; 27 return ret;
22} 28}
23 29
30static int machine__process_bpf_event_load(struct machine *machine,
31 union perf_event *event,
32 struct perf_sample *sample __maybe_unused)
33{
34 struct bpf_prog_info_linear *info_linear;
35 struct bpf_prog_info_node *info_node;
36 struct perf_env *env = machine->env;
37 int id = event->bpf_event.id;
38 unsigned int i;
39
40 /* perf-record, no need to handle bpf-event */
41 if (env == NULL)
42 return 0;
43
44 info_node = perf_env__find_bpf_prog_info(env, id);
45 if (!info_node)
46 return 0;
47 info_linear = info_node->info_linear;
48
49 for (i = 0; i < info_linear->info.nr_jited_ksyms; i++) {
50 u64 *addrs = (u64 *)(uintptr_t)(info_linear->info.jited_ksyms);
51 u64 addr = addrs[i];
52 struct map *map;
53
54 map = map_groups__find(&machine->kmaps, addr);
55
56 if (map) {
57 map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
58 map->dso->bpf_prog.id = id;
59 map->dso->bpf_prog.sub_id = i;
60 map->dso->bpf_prog.env = env;
61 }
62 }
63 return 0;
64}
65
24int machine__process_bpf_event(struct machine *machine __maybe_unused, 66int machine__process_bpf_event(struct machine *machine __maybe_unused,
25 union perf_event *event, 67 union perf_event *event,
26 struct perf_sample *sample __maybe_unused) 68 struct perf_sample *sample __maybe_unused)
27{ 69{
28 if (dump_trace) 70 if (dump_trace)
29 perf_event__fprintf_bpf_event(event, stdout); 71 perf_event__fprintf_bpf_event(event, stdout);
72
73 switch (event->bpf_event.type) {
74 case PERF_BPF_EVENT_PROG_LOAD:
75 return machine__process_bpf_event_load(machine, event, sample);
76
77 case PERF_BPF_EVENT_PROG_UNLOAD:
78 /*
79 * Do not free bpf_prog_info and btf of the program here,
80 * as annotation still need them. They will be freed at
81 * the end of the session.
82 */
83 break;
84 default:
85 pr_debug("unexpected bpf_event type of %d\n",
86 event->bpf_event.type);
87 break;
88 }
30 return 0; 89 return 0;
31} 90}
32 91
92static int perf_env__fetch_btf(struct perf_env *env,
93 u32 btf_id,
94 struct btf *btf)
95{
96 struct btf_node *node;
97 u32 data_size;
98 const void *data;
99
100 data = btf__get_raw_data(btf, &data_size);
101
102 node = malloc(data_size + sizeof(struct btf_node));
103 if (!node)
104 return -1;
105
106 node->id = btf_id;
107 node->data_size = data_size;
108 memcpy(node->data, data, data_size);
109
110 perf_env__insert_btf(env, node);
111 return 0;
112}
113
114static int synthesize_bpf_prog_name(char *buf, int size,
115 struct bpf_prog_info *info,
116 struct btf *btf,
117 u32 sub_id)
118{
119 u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(uintptr_t)(info->prog_tags);
120 void *func_infos = (void *)(uintptr_t)(info->func_info);
121 u32 sub_prog_cnt = info->nr_jited_ksyms;
122 const struct bpf_func_info *finfo;
123 const char *short_name = NULL;
124 const struct btf_type *t;
125 int name_len;
126
127 name_len = snprintf(buf, size, "bpf_prog_");
128 name_len += snprintf_hex(buf + name_len, size - name_len,
129 prog_tags[sub_id], BPF_TAG_SIZE);
130 if (btf) {
131 finfo = func_infos + sub_id * info->func_info_rec_size;
132 t = btf__type_by_id(btf, finfo->type_id);
133 short_name = btf__name_by_offset(btf, t->name_off);
134 } else if (sub_id == 0 && sub_prog_cnt == 1) {
135 /* no subprog */
136 if (info->name[0])
137 short_name = info->name;
138 } else
139 short_name = "F";
140 if (short_name)
141 name_len += snprintf(buf + name_len, size - name_len,
142 "_%s", short_name);
143 return name_len;
144}
145
33/* 146/*
34 * Synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for one bpf 147 * Synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for one bpf
35 * program. One PERF_RECORD_BPF_EVENT is generated for the program. And 148 * program. One PERF_RECORD_BPF_EVENT is generated for the program. And
@@ -40,7 +153,7 @@ int machine__process_bpf_event(struct machine *machine __maybe_unused,
40 * -1 for failures; 153 * -1 for failures;
41 * -2 for lack of kernel support. 154 * -2 for lack of kernel support.
42 */ 155 */
43static int perf_event__synthesize_one_bpf_prog(struct perf_tool *tool, 156static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
44 perf_event__handler_t process, 157 perf_event__handler_t process,
45 struct machine *machine, 158 struct machine *machine,
46 int fd, 159 int fd,
@@ -49,102 +162,71 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_tool *tool,
49{ 162{
50 struct ksymbol_event *ksymbol_event = &event->ksymbol_event; 163 struct ksymbol_event *ksymbol_event = &event->ksymbol_event;
51 struct bpf_event *bpf_event = &event->bpf_event; 164 struct bpf_event *bpf_event = &event->bpf_event;
52 u32 sub_prog_cnt, i, func_info_rec_size = 0; 165 struct bpf_prog_info_linear *info_linear;
53 u8 (*prog_tags)[BPF_TAG_SIZE] = NULL; 166 struct perf_tool *tool = session->tool;
54 struct bpf_prog_info info = { .type = 0, }; 167 struct bpf_prog_info_node *info_node;
55 u32 info_len = sizeof(info); 168 struct bpf_prog_info *info;
56 void *func_infos = NULL;
57 u64 *prog_addrs = NULL;
58 struct btf *btf = NULL; 169 struct btf *btf = NULL;
59 u32 *prog_lens = NULL; 170 struct perf_env *env;
60 bool has_btf = false; 171 u32 sub_prog_cnt, i;
61 char errbuf[512];
62 int err = 0; 172 int err = 0;
173 u64 arrays;
174
175 /*
176 * for perf-record and perf-report use header.env;
177 * otherwise, use global perf_env.
178 */
179 env = session->data ? &session->header.env : &perf_env;
63 180
64 /* Call bpf_obj_get_info_by_fd() to get sizes of arrays */ 181 arrays = 1UL << BPF_PROG_INFO_JITED_KSYMS;
65 err = bpf_obj_get_info_by_fd(fd, &info, &info_len); 182 arrays |= 1UL << BPF_PROG_INFO_JITED_FUNC_LENS;
183 arrays |= 1UL << BPF_PROG_INFO_FUNC_INFO;
184 arrays |= 1UL << BPF_PROG_INFO_PROG_TAGS;
185 arrays |= 1UL << BPF_PROG_INFO_JITED_INSNS;
186 arrays |= 1UL << BPF_PROG_INFO_LINE_INFO;
187 arrays |= 1UL << BPF_PROG_INFO_JITED_LINE_INFO;
66 188
67 if (err) { 189 info_linear = bpf_program__get_prog_info_linear(fd, arrays);
68 pr_debug("%s: failed to get BPF program info: %s, aborting\n", 190 if (IS_ERR_OR_NULL(info_linear)) {
69 __func__, str_error_r(errno, errbuf, sizeof(errbuf))); 191 info_linear = NULL;
192 pr_debug("%s: failed to get BPF program info. aborting\n", __func__);
70 return -1; 193 return -1;
71 } 194 }
72 if (info_len < offsetof(struct bpf_prog_info, prog_tags)) { 195
196 if (info_linear->info_len < offsetof(struct bpf_prog_info, prog_tags)) {
73 pr_debug("%s: the kernel is too old, aborting\n", __func__); 197 pr_debug("%s: the kernel is too old, aborting\n", __func__);
74 return -2; 198 return -2;
75 } 199 }
76 200
201 info = &info_linear->info;
202
77 /* number of ksyms, func_lengths, and tags should match */ 203 /* number of ksyms, func_lengths, and tags should match */
78 sub_prog_cnt = info.nr_jited_ksyms; 204 sub_prog_cnt = info->nr_jited_ksyms;
79 if (sub_prog_cnt != info.nr_prog_tags || 205 if (sub_prog_cnt != info->nr_prog_tags ||
80 sub_prog_cnt != info.nr_jited_func_lens) 206 sub_prog_cnt != info->nr_jited_func_lens)
81 return -1; 207 return -1;
82 208
83 /* check BTF func info support */ 209 /* check BTF func info support */
84 if (info.btf_id && info.nr_func_info && info.func_info_rec_size) { 210 if (info->btf_id && info->nr_func_info && info->func_info_rec_size) {
85 /* btf func info number should be same as sub_prog_cnt */ 211 /* btf func info number should be same as sub_prog_cnt */
86 if (sub_prog_cnt != info.nr_func_info) { 212 if (sub_prog_cnt != info->nr_func_info) {
87 pr_debug("%s: mismatch in BPF sub program count and BTF function info count, aborting\n", __func__); 213 pr_debug("%s: mismatch in BPF sub program count and BTF function info count, aborting\n", __func__);
88 return -1; 214 err = -1;
89 } 215 goto out;
90 if (btf__get_from_id(info.btf_id, &btf)) {
91 pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info.btf_id);
92 return -1;
93 } 216 }
94 func_info_rec_size = info.func_info_rec_size; 217 if (btf__get_from_id(info->btf_id, &btf)) {
95 func_infos = calloc(sub_prog_cnt, func_info_rec_size); 218 pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info->btf_id);
96 if (!func_infos) { 219 err = -1;
97 pr_debug("%s: failed to allocate memory for func_infos, aborting\n", __func__); 220 btf = NULL;
98 return -1; 221 goto out;
99 } 222 }
100 has_btf = true; 223 perf_env__fetch_btf(env, info->btf_id, btf);
101 }
102
103 /*
104 * We need address, length, and tag for each sub program.
105 * Allocate memory and call bpf_obj_get_info_by_fd() again
106 */
107 prog_addrs = calloc(sub_prog_cnt, sizeof(u64));
108 if (!prog_addrs) {
109 pr_debug("%s: failed to allocate memory for prog_addrs, aborting\n", __func__);
110 goto out;
111 }
112 prog_lens = calloc(sub_prog_cnt, sizeof(u32));
113 if (!prog_lens) {
114 pr_debug("%s: failed to allocate memory for prog_lens, aborting\n", __func__);
115 goto out;
116 }
117 prog_tags = calloc(sub_prog_cnt, BPF_TAG_SIZE);
118 if (!prog_tags) {
119 pr_debug("%s: failed to allocate memory for prog_tags, aborting\n", __func__);
120 goto out;
121 }
122
123 memset(&info, 0, sizeof(info));
124 info.nr_jited_ksyms = sub_prog_cnt;
125 info.nr_jited_func_lens = sub_prog_cnt;
126 info.nr_prog_tags = sub_prog_cnt;
127 info.jited_ksyms = ptr_to_u64(prog_addrs);
128 info.jited_func_lens = ptr_to_u64(prog_lens);
129 info.prog_tags = ptr_to_u64(prog_tags);
130 info_len = sizeof(info);
131 if (has_btf) {
132 info.nr_func_info = sub_prog_cnt;
133 info.func_info_rec_size = func_info_rec_size;
134 info.func_info = ptr_to_u64(func_infos);
135 }
136
137 err = bpf_obj_get_info_by_fd(fd, &info, &info_len);
138 if (err) {
139 pr_debug("%s: failed to get BPF program info, aborting\n", __func__);
140 goto out;
141 } 224 }
142 225
143 /* Synthesize PERF_RECORD_KSYMBOL */ 226 /* Synthesize PERF_RECORD_KSYMBOL */
144 for (i = 0; i < sub_prog_cnt; i++) { 227 for (i = 0; i < sub_prog_cnt; i++) {
145 const struct bpf_func_info *finfo; 228 __u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
146 const char *short_name = NULL; 229 __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms);
147 const struct btf_type *t;
148 int name_len; 230 int name_len;
149 231
150 *ksymbol_event = (struct ksymbol_event){ 232 *ksymbol_event = (struct ksymbol_event){
@@ -157,26 +239,9 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_tool *tool,
157 .ksym_type = PERF_RECORD_KSYMBOL_TYPE_BPF, 239 .ksym_type = PERF_RECORD_KSYMBOL_TYPE_BPF,
158 .flags = 0, 240 .flags = 0,
159 }; 241 };
160 name_len = snprintf(ksymbol_event->name, KSYM_NAME_LEN,
161 "bpf_prog_");
162 name_len += snprintf_hex(ksymbol_event->name + name_len,
163 KSYM_NAME_LEN - name_len,
164 prog_tags[i], BPF_TAG_SIZE);
165 if (has_btf) {
166 finfo = func_infos + i * info.func_info_rec_size;
167 t = btf__type_by_id(btf, finfo->type_id);
168 short_name = btf__name_by_offset(btf, t->name_off);
169 } else if (i == 0 && sub_prog_cnt == 1) {
170 /* no subprog */
171 if (info.name[0])
172 short_name = info.name;
173 } else
174 short_name = "F";
175 if (short_name)
176 name_len += snprintf(ksymbol_event->name + name_len,
177 KSYM_NAME_LEN - name_len,
178 "_%s", short_name);
179 242
243 name_len = synthesize_bpf_prog_name(ksymbol_event->name,
244 KSYM_NAME_LEN, info, btf, i);
180 ksymbol_event->header.size += PERF_ALIGN(name_len + 1, 245 ksymbol_event->header.size += PERF_ALIGN(name_len + 1,
181 sizeof(u64)); 246 sizeof(u64));
182 247
@@ -186,8 +251,8 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_tool *tool,
186 machine, process); 251 machine, process);
187 } 252 }
188 253
189 /* Synthesize PERF_RECORD_BPF_EVENT */ 254 if (!opts->no_bpf_event) {
190 if (opts->bpf_event) { 255 /* Synthesize PERF_RECORD_BPF_EVENT */
191 *bpf_event = (struct bpf_event){ 256 *bpf_event = (struct bpf_event){
192 .header = { 257 .header = {
193 .type = PERF_RECORD_BPF_EVENT, 258 .type = PERF_RECORD_BPF_EVENT,
@@ -195,25 +260,38 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_tool *tool,
195 }, 260 },
196 .type = PERF_BPF_EVENT_PROG_LOAD, 261 .type = PERF_BPF_EVENT_PROG_LOAD,
197 .flags = 0, 262 .flags = 0,
198 .id = info.id, 263 .id = info->id,
199 }; 264 };
200 memcpy(bpf_event->tag, prog_tags[i], BPF_TAG_SIZE); 265 memcpy(bpf_event->tag, info->tag, BPF_TAG_SIZE);
201 memset((void *)event + event->header.size, 0, machine->id_hdr_size); 266 memset((void *)event + event->header.size, 0, machine->id_hdr_size);
202 event->header.size += machine->id_hdr_size; 267 event->header.size += machine->id_hdr_size;
268
269 /* save bpf_prog_info to env */
270 info_node = malloc(sizeof(struct bpf_prog_info_node));
271 if (!info_node) {
272 err = -1;
273 goto out;
274 }
275
276 info_node->info_linear = info_linear;
277 perf_env__insert_bpf_prog_info(env, info_node);
278 info_linear = NULL;
279
280 /*
281 * process after saving bpf_prog_info to env, so that
282 * required information is ready for look up
283 */
203 err = perf_tool__process_synth_event(tool, event, 284 err = perf_tool__process_synth_event(tool, event,
204 machine, process); 285 machine, process);
205 } 286 }
206 287
207out: 288out:
208 free(prog_tags); 289 free(info_linear);
209 free(prog_lens);
210 free(prog_addrs);
211 free(func_infos);
212 free(btf); 290 free(btf);
213 return err ? -1 : 0; 291 return err ? -1 : 0;
214} 292}
215 293
216int perf_event__synthesize_bpf_events(struct perf_tool *tool, 294int perf_event__synthesize_bpf_events(struct perf_session *session,
217 perf_event__handler_t process, 295 perf_event__handler_t process,
218 struct machine *machine, 296 struct machine *machine,
219 struct record_opts *opts) 297 struct record_opts *opts)
@@ -247,7 +325,7 @@ int perf_event__synthesize_bpf_events(struct perf_tool *tool,
247 continue; 325 continue;
248 } 326 }
249 327
250 err = perf_event__synthesize_one_bpf_prog(tool, process, 328 err = perf_event__synthesize_one_bpf_prog(session, process,
251 machine, fd, 329 machine, fd,
252 event, opts); 330 event, opts);
253 close(fd); 331 close(fd);
@@ -261,3 +339,142 @@ int perf_event__synthesize_bpf_events(struct perf_tool *tool,
261 free(event); 339 free(event);
262 return err; 340 return err;
263} 341}
342
343static void perf_env__add_bpf_info(struct perf_env *env, u32 id)
344{
345 struct bpf_prog_info_linear *info_linear;
346 struct bpf_prog_info_node *info_node;
347 struct btf *btf = NULL;
348 u64 arrays;
349 u32 btf_id;
350 int fd;
351
352 fd = bpf_prog_get_fd_by_id(id);
353 if (fd < 0)
354 return;
355
356 arrays = 1UL << BPF_PROG_INFO_JITED_KSYMS;
357 arrays |= 1UL << BPF_PROG_INFO_JITED_FUNC_LENS;
358 arrays |= 1UL << BPF_PROG_INFO_FUNC_INFO;
359 arrays |= 1UL << BPF_PROG_INFO_PROG_TAGS;
360 arrays |= 1UL << BPF_PROG_INFO_JITED_INSNS;
361 arrays |= 1UL << BPF_PROG_INFO_LINE_INFO;
362 arrays |= 1UL << BPF_PROG_INFO_JITED_LINE_INFO;
363
364 info_linear = bpf_program__get_prog_info_linear(fd, arrays);
365 if (IS_ERR_OR_NULL(info_linear)) {
366 pr_debug("%s: failed to get BPF program info. aborting\n", __func__);
367 goto out;
368 }
369
370 btf_id = info_linear->info.btf_id;
371
372 info_node = malloc(sizeof(struct bpf_prog_info_node));
373 if (info_node) {
374 info_node->info_linear = info_linear;
375 perf_env__insert_bpf_prog_info(env, info_node);
376 } else
377 free(info_linear);
378
379 if (btf_id == 0)
380 goto out;
381
382 if (btf__get_from_id(btf_id, &btf)) {
383 pr_debug("%s: failed to get BTF of id %u, aborting\n",
384 __func__, btf_id);
385 goto out;
386 }
387 perf_env__fetch_btf(env, btf_id, btf);
388
389out:
390 free(btf);
391 close(fd);
392}
393
394static int bpf_event__sb_cb(union perf_event *event, void *data)
395{
396 struct perf_env *env = data;
397
398 if (event->header.type != PERF_RECORD_BPF_EVENT)
399 return -1;
400
401 switch (event->bpf_event.type) {
402 case PERF_BPF_EVENT_PROG_LOAD:
403 perf_env__add_bpf_info(env, event->bpf_event.id);
404
405 case PERF_BPF_EVENT_PROG_UNLOAD:
406 /*
407 * Do not free bpf_prog_info and btf of the program here,
408 * as annotation still need them. They will be freed at
409 * the end of the session.
410 */
411 break;
412 default:
413 pr_debug("unexpected bpf_event type of %d\n",
414 event->bpf_event.type);
415 break;
416 }
417
418 return 0;
419}
420
421int bpf_event__add_sb_event(struct perf_evlist **evlist,
422 struct perf_env *env)
423{
424 struct perf_event_attr attr = {
425 .type = PERF_TYPE_SOFTWARE,
426 .config = PERF_COUNT_SW_DUMMY,
427 .sample_id_all = 1,
428 .watermark = 1,
429 .bpf_event = 1,
430 .size = sizeof(attr), /* to capture ABI version */
431 };
432
433 /*
434 * Older gcc versions don't support designated initializers, like above,
435 * for unnamed union members, such as the following:
436 */
437 attr.wakeup_watermark = 1;
438
439 return perf_evlist__add_sb_event(evlist, &attr, bpf_event__sb_cb, env);
440}
441
442void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
443 struct perf_env *env,
444 FILE *fp)
445{
446 __u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
447 __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms);
448 char name[KSYM_NAME_LEN];
449 struct btf *btf = NULL;
450 u32 sub_prog_cnt, i;
451
452 sub_prog_cnt = info->nr_jited_ksyms;
453 if (sub_prog_cnt != info->nr_prog_tags ||
454 sub_prog_cnt != info->nr_jited_func_lens)
455 return;
456
457 if (info->btf_id) {
458 struct btf_node *node;
459
460 node = perf_env__find_btf(env, info->btf_id);
461 if (node)
462 btf = btf__new((__u8 *)(node->data),
463 node->data_size);
464 }
465
466 if (sub_prog_cnt == 1) {
467 synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, 0);
468 fprintf(fp, "# bpf_prog_info %u: %s addr 0x%llx size %u\n",
469 info->id, name, prog_addrs[0], prog_lens[0]);
470 return;
471 }
472
473 fprintf(fp, "# bpf_prog_info %u:\n", info->id);
474 for (i = 0; i < sub_prog_cnt; i++) {
475 synthesize_bpf_prog_name(name, KSYM_NAME_LEN, info, btf, i);
476
477 fprintf(fp, "# \tsub_prog %u: %s addr 0x%llx size %u\n",
478 i, name, prog_addrs[i], prog_lens[i]);
479 }
480}
diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h
index 7890067e1a37..04c33b3bfe28 100644
--- a/tools/perf/util/bpf-event.h
+++ b/tools/perf/util/bpf-event.h
@@ -3,22 +3,45 @@
3#define __PERF_BPF_EVENT_H 3#define __PERF_BPF_EVENT_H
4 4
5#include <linux/compiler.h> 5#include <linux/compiler.h>
6#include <linux/rbtree.h>
7#include <pthread.h>
8#include <api/fd/array.h>
6#include "event.h" 9#include "event.h"
10#include <stdio.h>
7 11
8struct machine; 12struct machine;
9union perf_event; 13union perf_event;
14struct perf_env;
10struct perf_sample; 15struct perf_sample;
11struct perf_tool;
12struct record_opts; 16struct record_opts;
17struct evlist;
18struct target;
19
20struct bpf_prog_info_node {
21 struct bpf_prog_info_linear *info_linear;
22 struct rb_node rb_node;
23};
24
25struct btf_node {
26 struct rb_node rb_node;
27 u32 id;
28 u32 data_size;
29 char data[];
30};
13 31
14#ifdef HAVE_LIBBPF_SUPPORT 32#ifdef HAVE_LIBBPF_SUPPORT
15int machine__process_bpf_event(struct machine *machine, union perf_event *event, 33int machine__process_bpf_event(struct machine *machine, union perf_event *event,
16 struct perf_sample *sample); 34 struct perf_sample *sample);
17 35
18int perf_event__synthesize_bpf_events(struct perf_tool *tool, 36int perf_event__synthesize_bpf_events(struct perf_session *session,
19 perf_event__handler_t process, 37 perf_event__handler_t process,
20 struct machine *machine, 38 struct machine *machine,
21 struct record_opts *opts); 39 struct record_opts *opts);
40int bpf_event__add_sb_event(struct perf_evlist **evlist,
41 struct perf_env *env);
42void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
43 struct perf_env *env,
44 FILE *fp);
22#else 45#else
23static inline int machine__process_bpf_event(struct machine *machine __maybe_unused, 46static inline int machine__process_bpf_event(struct machine *machine __maybe_unused,
24 union perf_event *event __maybe_unused, 47 union perf_event *event __maybe_unused,
@@ -27,12 +50,25 @@ static inline int machine__process_bpf_event(struct machine *machine __maybe_unu
27 return 0; 50 return 0;
28} 51}
29 52
30static inline int perf_event__synthesize_bpf_events(struct perf_tool *tool __maybe_unused, 53static inline int perf_event__synthesize_bpf_events(struct perf_session *session __maybe_unused,
31 perf_event__handler_t process __maybe_unused, 54 perf_event__handler_t process __maybe_unused,
32 struct machine *machine __maybe_unused, 55 struct machine *machine __maybe_unused,
33 struct record_opts *opts __maybe_unused) 56 struct record_opts *opts __maybe_unused)
34{ 57{
35 return 0; 58 return 0;
36} 59}
60
61static inline int bpf_event__add_sb_event(struct perf_evlist **evlist __maybe_unused,
62 struct perf_env *env __maybe_unused)
63{
64 return 0;
65}
66
67static inline void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info __maybe_unused,
68 struct perf_env *env __maybe_unused,
69 FILE *fp __maybe_unused)
70{
71
72}
37#endif // HAVE_LIBBPF_SUPPORT 73#endif // HAVE_LIBBPF_SUPPORT
38#endif 74#endif
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index bff0d17920ed..0c5517a8d0b7 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -185,6 +185,7 @@ char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size)
185 return bf; 185 return bf;
186} 186}
187 187
188/* The caller is responsible to free the returned buffer. */
188char *build_id_cache__origname(const char *sbuild_id) 189char *build_id_cache__origname(const char *sbuild_id)
189{ 190{
190 char *linkname; 191 char *linkname;
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index fa092511c52b..7e3c1b60120c 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -633,11 +633,10 @@ static int collect_config(const char *var, const char *value,
633 } 633 }
634 634
635 ret = set_value(item, value); 635 ret = set_value(item, value);
636 return ret;
637 636
638out_free: 637out_free:
639 free(key); 638 free(key);
640 return -1; 639 return ret;
641} 640}
642 641
643int perf_config_set__collect(struct perf_config_set *set, const char *file_name, 642int perf_config_set__collect(struct perf_config_set *set, const char *file_name,
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index e098e189f93e..6a64f713710d 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -14,6 +14,7 @@
14#include "data.h" 14#include "data.h"
15#include "util.h" 15#include "util.h"
16#include "debug.h" 16#include "debug.h"
17#include "header.h"
17 18
18static void close_dir(struct perf_data_file *files, int nr) 19static void close_dir(struct perf_data_file *files, int nr)
19{ 20{
@@ -34,12 +35,16 @@ int perf_data__create_dir(struct perf_data *data, int nr)
34 struct perf_data_file *files = NULL; 35 struct perf_data_file *files = NULL;
35 int i, ret = -1; 36 int i, ret = -1;
36 37
38 if (WARN_ON(!data->is_dir))
39 return -EINVAL;
40
37 files = zalloc(nr * sizeof(*files)); 41 files = zalloc(nr * sizeof(*files));
38 if (!files) 42 if (!files)
39 return -ENOMEM; 43 return -ENOMEM;
40 44
41 data->dir.files = files; 45 data->dir.version = PERF_DIR_VERSION;
42 data->dir.nr = nr; 46 data->dir.files = files;
47 data->dir.nr = nr;
43 48
44 for (i = 0; i < nr; i++) { 49 for (i = 0; i < nr; i++) {
45 struct perf_data_file *file = &files[i]; 50 struct perf_data_file *file = &files[i];
@@ -69,6 +74,13 @@ int perf_data__open_dir(struct perf_data *data)
69 DIR *dir; 74 DIR *dir;
70 int nr = 0; 75 int nr = 0;
71 76
77 if (WARN_ON(!data->is_dir))
78 return -EINVAL;
79
80 /* The version is provided by DIR_FORMAT feature. */
81 if (WARN_ON(data->dir.version != PERF_DIR_VERSION))
82 return -1;
83
72 dir = opendir(data->path); 84 dir = opendir(data->path);
73 if (!dir) 85 if (!dir)
74 return -EINVAL; 86 return -EINVAL;
@@ -118,6 +130,26 @@ out_err:
118 return ret; 130 return ret;
119} 131}
120 132
133int perf_data__update_dir(struct perf_data *data)
134{
135 int i;
136
137 if (WARN_ON(!data->is_dir))
138 return -EINVAL;
139
140 for (i = 0; i < data->dir.nr; i++) {
141 struct perf_data_file *file = &data->dir.files[i];
142 struct stat st;
143
144 if (fstat(file->fd, &st))
145 return -1;
146
147 file->size = st.st_size;
148 }
149
150 return 0;
151}
152
121static bool check_pipe(struct perf_data *data) 153static bool check_pipe(struct perf_data *data)
122{ 154{
123 struct stat st; 155 struct stat st;
@@ -173,6 +205,16 @@ static int check_backup(struct perf_data *data)
173 return 0; 205 return 0;
174} 206}
175 207
208static bool is_dir(struct perf_data *data)
209{
210 struct stat st;
211
212 if (stat(data->path, &st))
213 return false;
214
215 return (st.st_mode & S_IFMT) == S_IFDIR;
216}
217
176static int open_file_read(struct perf_data *data) 218static int open_file_read(struct perf_data *data)
177{ 219{
178 struct stat st; 220 struct stat st;
@@ -254,6 +296,30 @@ static int open_file_dup(struct perf_data *data)
254 return open_file(data); 296 return open_file(data);
255} 297}
256 298
299static int open_dir(struct perf_data *data)
300{
301 int ret;
302
303 /*
304 * So far we open only the header, so we can read the data version and
305 * layout.
306 */
307 if (asprintf(&data->file.path, "%s/header", data->path) < 0)
308 return -1;
309
310 if (perf_data__is_write(data) &&
311 mkdir(data->path, S_IRWXU) < 0)
312 return -1;
313
314 ret = open_file(data);
315
316 /* Cleanup whatever we managed to create so far. */
317 if (ret && perf_data__is_write(data))
318 rm_rf_perf_data(data->path);
319
320 return ret;
321}
322
257int perf_data__open(struct perf_data *data) 323int perf_data__open(struct perf_data *data)
258{ 324{
259 if (check_pipe(data)) 325 if (check_pipe(data))
@@ -265,11 +331,18 @@ int perf_data__open(struct perf_data *data)
265 if (check_backup(data)) 331 if (check_backup(data))
266 return -1; 332 return -1;
267 333
268 return open_file_dup(data); 334 if (perf_data__is_read(data))
335 data->is_dir = is_dir(data);
336
337 return perf_data__is_dir(data) ?
338 open_dir(data) : open_file_dup(data);
269} 339}
270 340
271void perf_data__close(struct perf_data *data) 341void perf_data__close(struct perf_data *data)
272{ 342{
343 if (perf_data__is_dir(data))
344 perf_data__close_dir(data);
345
273 zfree(&data->file.path); 346 zfree(&data->file.path);
274 close(data->file.fd); 347 close(data->file.fd);
275} 348}
@@ -288,9 +361,9 @@ ssize_t perf_data__write(struct perf_data *data,
288 361
289int perf_data__switch(struct perf_data *data, 362int perf_data__switch(struct perf_data *data,
290 const char *postfix, 363 const char *postfix,
291 size_t pos, bool at_exit) 364 size_t pos, bool at_exit,
365 char **new_filepath)
292{ 366{
293 char *new_filepath;
294 int ret; 367 int ret;
295 368
296 if (check_pipe(data)) 369 if (check_pipe(data))
@@ -298,15 +371,15 @@ int perf_data__switch(struct perf_data *data,
298 if (perf_data__is_read(data)) 371 if (perf_data__is_read(data))
299 return -EINVAL; 372 return -EINVAL;
300 373
301 if (asprintf(&new_filepath, "%s.%s", data->path, postfix) < 0) 374 if (asprintf(new_filepath, "%s.%s", data->path, postfix) < 0)
302 return -ENOMEM; 375 return -ENOMEM;
303 376
304 /* 377 /*
305 * Only fire a warning, don't return error, continue fill 378 * Only fire a warning, don't return error, continue fill
306 * original file. 379 * original file.
307 */ 380 */
308 if (rename(data->path, new_filepath)) 381 if (rename(data->path, *new_filepath))
309 pr_warning("Failed to rename %s to %s\n", data->path, new_filepath); 382 pr_warning("Failed to rename %s to %s\n", data->path, *new_filepath);
310 383
311 if (!at_exit) { 384 if (!at_exit) {
312 close(data->file.fd); 385 close(data->file.fd);
@@ -323,6 +396,22 @@ int perf_data__switch(struct perf_data *data,
323 } 396 }
324 ret = data->file.fd; 397 ret = data->file.fd;
325out: 398out:
326 free(new_filepath);
327 return ret; 399 return ret;
328} 400}
401
402unsigned long perf_data__size(struct perf_data *data)
403{
404 u64 size = data->file.size;
405 int i;
406
407 if (!data->is_dir)
408 return size;
409
410 for (i = 0; i < data->dir.nr; i++) {
411 struct perf_data_file *file = &data->dir.files[i];
412
413 size += file->size;
414 }
415
416 return size;
417}
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 14b47be2bd69..259868a39019 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -19,10 +19,12 @@ struct perf_data {
19 const char *path; 19 const char *path;
20 struct perf_data_file file; 20 struct perf_data_file file;
21 bool is_pipe; 21 bool is_pipe;
22 bool is_dir;
22 bool force; 23 bool force;
23 enum perf_data_mode mode; 24 enum perf_data_mode mode;
24 25
25 struct { 26 struct {
27 u64 version;
26 struct perf_data_file *files; 28 struct perf_data_file *files;
27 int nr; 29 int nr;
28 } dir; 30 } dir;
@@ -43,14 +45,14 @@ static inline int perf_data__is_pipe(struct perf_data *data)
43 return data->is_pipe; 45 return data->is_pipe;
44} 46}
45 47
46static inline int perf_data__fd(struct perf_data *data) 48static inline bool perf_data__is_dir(struct perf_data *data)
47{ 49{
48 return data->file.fd; 50 return data->is_dir;
49} 51}
50 52
51static inline unsigned long perf_data__size(struct perf_data *data) 53static inline int perf_data__fd(struct perf_data *data)
52{ 54{
53 return data->file.size; 55 return data->file.fd;
54} 56}
55 57
56int perf_data__open(struct perf_data *data); 58int perf_data__open(struct perf_data *data);
@@ -68,9 +70,11 @@ ssize_t perf_data_file__write(struct perf_data_file *file,
68 */ 70 */
69int perf_data__switch(struct perf_data *data, 71int perf_data__switch(struct perf_data *data,
70 const char *postfix, 72 const char *postfix,
71 size_t pos, bool at_exit); 73 size_t pos, bool at_exit, char **new_filepath);
72 74
73int perf_data__create_dir(struct perf_data *data, int nr); 75int perf_data__create_dir(struct perf_data *data, int nr);
74int perf_data__open_dir(struct perf_data *data); 76int perf_data__open_dir(struct perf_data *data);
75void perf_data__close_dir(struct perf_data *data); 77void perf_data__close_dir(struct perf_data *data);
78int perf_data__update_dir(struct perf_data *data);
79unsigned long perf_data__size(struct perf_data *data);
76#endif /* __PERF_DATA_H */ 80#endif /* __PERF_DATA_H */
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index ba58ba603b69..e059976d9d93 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -184,6 +184,7 @@ int dso__read_binary_type_filename(const struct dso *dso,
184 case DSO_BINARY_TYPE__KALLSYMS: 184 case DSO_BINARY_TYPE__KALLSYMS:
185 case DSO_BINARY_TYPE__GUEST_KALLSYMS: 185 case DSO_BINARY_TYPE__GUEST_KALLSYMS:
186 case DSO_BINARY_TYPE__JAVA_JIT: 186 case DSO_BINARY_TYPE__JAVA_JIT:
187 case DSO_BINARY_TYPE__BPF_PROG_INFO:
187 case DSO_BINARY_TYPE__NOT_FOUND: 188 case DSO_BINARY_TYPE__NOT_FOUND:
188 ret = -1; 189 ret = -1;
189 break; 190 break;
@@ -1141,28 +1142,34 @@ void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
1141 1142
1142static void dso__set_basename(struct dso *dso) 1143static void dso__set_basename(struct dso *dso)
1143{ 1144{
1144 /* 1145 char *base, *lname;
1145 * basename() may modify path buffer, so we must pass 1146 int tid;
1146 * a copy.
1147 */
1148 char *base, *lname = strdup(dso->long_name);
1149 1147
1150 if (!lname) 1148 if (sscanf(dso->long_name, "/tmp/perf-%d.map", &tid) == 1) {
1151 return; 1149 if (asprintf(&base, "[JIT] tid %d", tid) < 0)
1152 1150 return;
1153 /* 1151 } else {
1154 * basename() may return a pointer to internal 1152 /*
1155 * storage which is reused in subsequent calls 1153 * basename() may modify path buffer, so we must pass
1156 * so copy the result. 1154 * a copy.
1157 */ 1155 */
1158 base = strdup(basename(lname)); 1156 lname = strdup(dso->long_name);
1157 if (!lname)
1158 return;
1159 1159
1160 free(lname); 1160 /*
1161 * basename() may return a pointer to internal
1162 * storage which is reused in subsequent calls
1163 * so copy the result.
1164 */
1165 base = strdup(basename(lname));
1161 1166
1162 if (!base) 1167 free(lname);
1163 return;
1164 1168
1165 dso__set_short_name(dso, base, true); 1169 if (!base)
1170 return;
1171 }
1172 dso__set_short_name(dso, base, true);
1166} 1173}
1167 1174
1168int dso__name_len(const struct dso *dso) 1175int dso__name_len(const struct dso *dso)
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index bb417c54c25a..6e3f63781e51 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -14,6 +14,7 @@
14 14
15struct machine; 15struct machine;
16struct map; 16struct map;
17struct perf_env;
17 18
18enum dso_binary_type { 19enum dso_binary_type {
19 DSO_BINARY_TYPE__KALLSYMS = 0, 20 DSO_BINARY_TYPE__KALLSYMS = 0,
@@ -35,6 +36,7 @@ enum dso_binary_type {
35 DSO_BINARY_TYPE__KCORE, 36 DSO_BINARY_TYPE__KCORE,
36 DSO_BINARY_TYPE__GUEST_KCORE, 37 DSO_BINARY_TYPE__GUEST_KCORE,
37 DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO, 38 DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
39 DSO_BINARY_TYPE__BPF_PROG_INFO,
38 DSO_BINARY_TYPE__NOT_FOUND, 40 DSO_BINARY_TYPE__NOT_FOUND,
39}; 41};
40 42
@@ -189,6 +191,12 @@ struct dso {
189 u64 debug_frame_offset; 191 u64 debug_frame_offset;
190 u64 eh_frame_hdr_offset; 192 u64 eh_frame_hdr_offset;
191 } data; 193 } data;
194 /* bpf prog information */
195 struct {
196 u32 id;
197 u32 sub_id;
198 struct perf_env *env;
199 } bpf_prog;
192 200
193 union { /* Tool specific area */ 201 union { /* Tool specific area */
194 void *priv; 202 void *priv;
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 4c23779e271a..c6351b557bb0 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -3,15 +3,163 @@
3#include "env.h" 3#include "env.h"
4#include "sane_ctype.h" 4#include "sane_ctype.h"
5#include "util.h" 5#include "util.h"
6#include "bpf-event.h"
6#include <errno.h> 7#include <errno.h>
7#include <sys/utsname.h> 8#include <sys/utsname.h>
9#include <bpf/libbpf.h>
8 10
9struct perf_env perf_env; 11struct perf_env perf_env;
10 12
13void perf_env__insert_bpf_prog_info(struct perf_env *env,
14 struct bpf_prog_info_node *info_node)
15{
16 __u32 prog_id = info_node->info_linear->info.id;
17 struct bpf_prog_info_node *node;
18 struct rb_node *parent = NULL;
19 struct rb_node **p;
20
21 down_write(&env->bpf_progs.lock);
22 p = &env->bpf_progs.infos.rb_node;
23
24 while (*p != NULL) {
25 parent = *p;
26 node = rb_entry(parent, struct bpf_prog_info_node, rb_node);
27 if (prog_id < node->info_linear->info.id) {
28 p = &(*p)->rb_left;
29 } else if (prog_id > node->info_linear->info.id) {
30 p = &(*p)->rb_right;
31 } else {
32 pr_debug("duplicated bpf prog info %u\n", prog_id);
33 goto out;
34 }
35 }
36
37 rb_link_node(&info_node->rb_node, parent, p);
38 rb_insert_color(&info_node->rb_node, &env->bpf_progs.infos);
39 env->bpf_progs.infos_cnt++;
40out:
41 up_write(&env->bpf_progs.lock);
42}
43
44struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
45 __u32 prog_id)
46{
47 struct bpf_prog_info_node *node = NULL;
48 struct rb_node *n;
49
50 down_read(&env->bpf_progs.lock);
51 n = env->bpf_progs.infos.rb_node;
52
53 while (n) {
54 node = rb_entry(n, struct bpf_prog_info_node, rb_node);
55 if (prog_id < node->info_linear->info.id)
56 n = n->rb_left;
57 else if (prog_id > node->info_linear->info.id)
58 n = n->rb_right;
59 else
60 break;
61 }
62
63 up_read(&env->bpf_progs.lock);
64 return node;
65}
66
67void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node)
68{
69 struct rb_node *parent = NULL;
70 __u32 btf_id = btf_node->id;
71 struct btf_node *node;
72 struct rb_node **p;
73
74 down_write(&env->bpf_progs.lock);
75 p = &env->bpf_progs.btfs.rb_node;
76
77 while (*p != NULL) {
78 parent = *p;
79 node = rb_entry(parent, struct btf_node, rb_node);
80 if (btf_id < node->id) {
81 p = &(*p)->rb_left;
82 } else if (btf_id > node->id) {
83 p = &(*p)->rb_right;
84 } else {
85 pr_debug("duplicated btf %u\n", btf_id);
86 goto out;
87 }
88 }
89
90 rb_link_node(&btf_node->rb_node, parent, p);
91 rb_insert_color(&btf_node->rb_node, &env->bpf_progs.btfs);
92 env->bpf_progs.btfs_cnt++;
93out:
94 up_write(&env->bpf_progs.lock);
95}
96
97struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id)
98{
99 struct btf_node *node = NULL;
100 struct rb_node *n;
101
102 down_read(&env->bpf_progs.lock);
103 n = env->bpf_progs.btfs.rb_node;
104
105 while (n) {
106 node = rb_entry(n, struct btf_node, rb_node);
107 if (btf_id < node->id)
108 n = n->rb_left;
109 else if (btf_id > node->id)
110 n = n->rb_right;
111 else
112 break;
113 }
114
115 up_read(&env->bpf_progs.lock);
116 return node;
117}
118
119/* purge data in bpf_progs.infos tree */
120static void perf_env__purge_bpf(struct perf_env *env)
121{
122 struct rb_root *root;
123 struct rb_node *next;
124
125 down_write(&env->bpf_progs.lock);
126
127 root = &env->bpf_progs.infos;
128 next = rb_first(root);
129
130 while (next) {
131 struct bpf_prog_info_node *node;
132
133 node = rb_entry(next, struct bpf_prog_info_node, rb_node);
134 next = rb_next(&node->rb_node);
135 rb_erase(&node->rb_node, root);
136 free(node);
137 }
138
139 env->bpf_progs.infos_cnt = 0;
140
141 root = &env->bpf_progs.btfs;
142 next = rb_first(root);
143
144 while (next) {
145 struct btf_node *node;
146
147 node = rb_entry(next, struct btf_node, rb_node);
148 next = rb_next(&node->rb_node);
149 rb_erase(&node->rb_node, root);
150 free(node);
151 }
152
153 env->bpf_progs.btfs_cnt = 0;
154
155 up_write(&env->bpf_progs.lock);
156}
157
11void perf_env__exit(struct perf_env *env) 158void perf_env__exit(struct perf_env *env)
12{ 159{
13 int i; 160 int i;
14 161
162 perf_env__purge_bpf(env);
15 zfree(&env->hostname); 163 zfree(&env->hostname);
16 zfree(&env->os_release); 164 zfree(&env->os_release);
17 zfree(&env->version); 165 zfree(&env->version);
@@ -38,6 +186,13 @@ void perf_env__exit(struct perf_env *env)
38 zfree(&env->memory_nodes); 186 zfree(&env->memory_nodes);
39} 187}
40 188
189void perf_env__init(struct perf_env *env)
190{
191 env->bpf_progs.infos = RB_ROOT;
192 env->bpf_progs.btfs = RB_ROOT;
193 init_rwsem(&env->bpf_progs.lock);
194}
195
41int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) 196int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
42{ 197{
43 int i; 198 int i;
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index d01b8355f4ca..4f8e2b485c01 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -3,7 +3,9 @@
3#define __PERF_ENV_H 3#define __PERF_ENV_H
4 4
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/rbtree.h>
6#include "cpumap.h" 7#include "cpumap.h"
8#include "rwsem.h"
7 9
8struct cpu_topology_map { 10struct cpu_topology_map {
9 int socket_id; 11 int socket_id;
@@ -64,8 +66,23 @@ struct perf_env {
64 struct memory_node *memory_nodes; 66 struct memory_node *memory_nodes;
65 unsigned long long memory_bsize; 67 unsigned long long memory_bsize;
66 u64 clockid_res_ns; 68 u64 clockid_res_ns;
69
70 /*
71 * bpf_info_lock protects bpf rbtrees. This is needed because the
72 * trees are accessed by different threads in perf-top
73 */
74 struct {
75 struct rw_semaphore lock;
76 struct rb_root infos;
77 u32 infos_cnt;
78 struct rb_root btfs;
79 u32 btfs_cnt;
80 } bpf_progs;
67}; 81};
68 82
83struct bpf_prog_info_node;
84struct btf_node;
85
69extern struct perf_env perf_env; 86extern struct perf_env perf_env;
70 87
71void perf_env__exit(struct perf_env *env); 88void perf_env__exit(struct perf_env *env);
@@ -80,4 +97,11 @@ const char *perf_env__arch(struct perf_env *env);
80const char *perf_env__raw_arch(struct perf_env *env); 97const char *perf_env__raw_arch(struct perf_env *env);
81int perf_env__nr_cpus_avail(struct perf_env *env); 98int perf_env__nr_cpus_avail(struct perf_env *env);
82 99
100void perf_env__init(struct perf_env *env);
101void perf_env__insert_bpf_prog_info(struct perf_env *env,
102 struct bpf_prog_info_node *info_node);
103struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env,
104 __u32 prog_id);
105void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node);
106struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id);
83#endif /* __PERF_ENV_H */ 107#endif /* __PERF_ENV_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ed20f4379956..ec78e93085de 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -19,6 +19,7 @@
19#include "debug.h" 19#include "debug.h"
20#include "units.h" 20#include "units.h"
21#include "asm/bug.h" 21#include "asm/bug.h"
22#include "bpf-event.h"
22#include <signal.h> 23#include <signal.h>
23#include <unistd.h> 24#include <unistd.h>
24 25
@@ -1856,3 +1857,121 @@ struct perf_evsel *perf_evlist__reset_weak_group(struct perf_evlist *evsel_list,
1856 } 1857 }
1857 return leader; 1858 return leader;
1858} 1859}
1860
1861int perf_evlist__add_sb_event(struct perf_evlist **evlist,
1862 struct perf_event_attr *attr,
1863 perf_evsel__sb_cb_t cb,
1864 void *data)
1865{
1866 struct perf_evsel *evsel;
1867 bool new_evlist = (*evlist) == NULL;
1868
1869 if (*evlist == NULL)
1870 *evlist = perf_evlist__new();
1871 if (*evlist == NULL)
1872 return -1;
1873
1874 if (!attr->sample_id_all) {
1875 pr_warning("enabling sample_id_all for all side band events\n");
1876 attr->sample_id_all = 1;
1877 }
1878
1879 evsel = perf_evsel__new_idx(attr, (*evlist)->nr_entries);
1880 if (!evsel)
1881 goto out_err;
1882
1883 evsel->side_band.cb = cb;
1884 evsel->side_band.data = data;
1885 perf_evlist__add(*evlist, evsel);
1886 return 0;
1887
1888out_err:
1889 if (new_evlist) {
1890 perf_evlist__delete(*evlist);
1891 *evlist = NULL;
1892 }
1893 return -1;
1894}
1895
1896static void *perf_evlist__poll_thread(void *arg)
1897{
1898 struct perf_evlist *evlist = arg;
1899 bool draining = false;
1900 int i;
1901
1902 while (draining || !(evlist->thread.done)) {
1903 if (draining)
1904 draining = false;
1905 else if (evlist->thread.done)
1906 draining = true;
1907
1908 if (!draining)
1909 perf_evlist__poll(evlist, 1000);
1910
1911 for (i = 0; i < evlist->nr_mmaps; i++) {
1912 struct perf_mmap *map = &evlist->mmap[i];
1913 union perf_event *event;
1914
1915 if (perf_mmap__read_init(map))
1916 continue;
1917 while ((event = perf_mmap__read_event(map)) != NULL) {
1918 struct perf_evsel *evsel = perf_evlist__event2evsel(evlist, event);
1919
1920 if (evsel && evsel->side_band.cb)
1921 evsel->side_band.cb(event, evsel->side_band.data);
1922 else
1923 pr_warning("cannot locate proper evsel for the side band event\n");
1924
1925 perf_mmap__consume(map);
1926 }
1927 perf_mmap__read_done(map);
1928 }
1929 }
1930 return NULL;
1931}
1932
1933int perf_evlist__start_sb_thread(struct perf_evlist *evlist,
1934 struct target *target)
1935{
1936 struct perf_evsel *counter;
1937
1938 if (!evlist)
1939 return 0;
1940
1941 if (perf_evlist__create_maps(evlist, target))
1942 goto out_delete_evlist;
1943
1944 evlist__for_each_entry(evlist, counter) {
1945 if (perf_evsel__open(counter, evlist->cpus,
1946 evlist->threads) < 0)
1947 goto out_delete_evlist;
1948 }
1949
1950 if (perf_evlist__mmap(evlist, UINT_MAX))
1951 goto out_delete_evlist;
1952
1953 evlist__for_each_entry(evlist, counter) {
1954 if (perf_evsel__enable(counter))
1955 goto out_delete_evlist;
1956 }
1957
1958 evlist->thread.done = 0;
1959 if (pthread_create(&evlist->thread.th, NULL, perf_evlist__poll_thread, evlist))
1960 goto out_delete_evlist;
1961
1962 return 0;
1963
1964out_delete_evlist:
1965 perf_evlist__delete(evlist);
1966 evlist = NULL;
1967 return -1;
1968}
1969
1970void perf_evlist__stop_sb_thread(struct perf_evlist *evlist)
1971{
1972 if (!evlist)
1973 return;
1974 evlist->thread.done = 1;
1975 pthread_join(evlist->thread.th, NULL);
1976 perf_evlist__delete(evlist);
1977}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 744906dd4887..dcb68f34d2cd 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -54,6 +54,10 @@ struct perf_evlist {
54 struct perf_sample *sample); 54 struct perf_sample *sample);
55 u64 first_sample_time; 55 u64 first_sample_time;
56 u64 last_sample_time; 56 u64 last_sample_time;
57 struct {
58 pthread_t th;
59 volatile int done;
60 } thread;
57}; 61};
58 62
59struct perf_evsel_str_handler { 63struct perf_evsel_str_handler {
@@ -87,6 +91,14 @@ int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
87 91
88int perf_evlist__add_dummy(struct perf_evlist *evlist); 92int perf_evlist__add_dummy(struct perf_evlist *evlist);
89 93
94int perf_evlist__add_sb_event(struct perf_evlist **evlist,
95 struct perf_event_attr *attr,
96 perf_evsel__sb_cb_t cb,
97 void *data);
98int perf_evlist__start_sb_thread(struct perf_evlist *evlist,
99 struct target *target);
100void perf_evlist__stop_sb_thread(struct perf_evlist *evlist);
101
90int perf_evlist__add_newtp(struct perf_evlist *evlist, 102int perf_evlist__add_newtp(struct perf_evlist *evlist,
91 const char *sys, const char *name, void *handler); 103 const char *sys, const char *name, void *handler);
92 104
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 3bbf73e979c0..7835e05f0c0a 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1036,7 +1036,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
1036 attr->mmap2 = track && !perf_missing_features.mmap2; 1036 attr->mmap2 = track && !perf_missing_features.mmap2;
1037 attr->comm = track; 1037 attr->comm = track;
1038 attr->ksymbol = track && !perf_missing_features.ksymbol; 1038 attr->ksymbol = track && !perf_missing_features.ksymbol;
1039 attr->bpf_event = track && opts->bpf_event && 1039 attr->bpf_event = track && !opts->no_bpf_event &&
1040 !perf_missing_features.bpf_event; 1040 !perf_missing_features.bpf_event;
1041 1041
1042 if (opts->record_namespaces) 1042 if (opts->record_namespaces)
@@ -1292,6 +1292,7 @@ void perf_evsel__exit(struct perf_evsel *evsel)
1292{ 1292{
1293 assert(list_empty(&evsel->node)); 1293 assert(list_empty(&evsel->node));
1294 assert(evsel->evlist == NULL); 1294 assert(evsel->evlist == NULL);
1295 perf_evsel__free_counts(evsel);
1295 perf_evsel__free_fd(evsel); 1296 perf_evsel__free_fd(evsel);
1296 perf_evsel__free_id(evsel); 1297 perf_evsel__free_id(evsel);
1297 perf_evsel__free_config_terms(evsel); 1298 perf_evsel__free_config_terms(evsel);
@@ -1342,10 +1343,9 @@ void perf_counts_values__scale(struct perf_counts_values *count,
1342 count->val = 0; 1343 count->val = 0;
1343 } else if (count->run < count->ena) { 1344 } else if (count->run < count->ena) {
1344 scaled = 1; 1345 scaled = 1;
1345 count->val = (u64)((double) count->val * count->ena / count->run + 0.5); 1346 count->val = (u64)((double) count->val * count->ena / count->run);
1346 } 1347 }
1347 } else 1348 }
1348 count->ena = count->run = 0;
1349 1349
1350 if (pscaled) 1350 if (pscaled)
1351 *pscaled = scaled; 1351 *pscaled = scaled;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index cc578e02e08f..0f2c6c93d721 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -73,6 +73,8 @@ struct perf_evsel_config_term {
73 73
74struct perf_stat_evsel; 74struct perf_stat_evsel;
75 75
76typedef int (perf_evsel__sb_cb_t)(union perf_event *event, void *data);
77
76/** struct perf_evsel - event selector 78/** struct perf_evsel - event selector
77 * 79 *
78 * @evlist - evlist this evsel is in, if it is in one. 80 * @evlist - evlist this evsel is in, if it is in one.
@@ -151,6 +153,10 @@ struct perf_evsel {
151 bool collect_stat; 153 bool collect_stat;
152 bool weak_group; 154 bool weak_group;
153 const char *pmu_name; 155 const char *pmu_name;
156 struct {
157 perf_evsel__sb_cb_t *cb;
158 void *data;
159 } side_band;
154}; 160};
155 161
156union u64_swap { 162union u64_swap {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 01b324c275b9..b9e693825873 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -18,6 +18,7 @@
18#include <sys/utsname.h> 18#include <sys/utsname.h>
19#include <linux/time64.h> 19#include <linux/time64.h>
20#include <dirent.h> 20#include <dirent.h>
21#include <bpf/libbpf.h>
21 22
22#include "evlist.h" 23#include "evlist.h"
23#include "evsel.h" 24#include "evsel.h"
@@ -40,6 +41,7 @@
40#include "time-utils.h" 41#include "time-utils.h"
41#include "units.h" 42#include "units.h"
42#include "cputopo.h" 43#include "cputopo.h"
44#include "bpf-event.h"
43 45
44#include "sane_ctype.h" 46#include "sane_ctype.h"
45 47
@@ -861,6 +863,104 @@ static int write_clockid(struct feat_fd *ff,
861 sizeof(ff->ph->env.clockid_res_ns)); 863 sizeof(ff->ph->env.clockid_res_ns));
862} 864}
863 865
866static int write_dir_format(struct feat_fd *ff,
867 struct perf_evlist *evlist __maybe_unused)
868{
869 struct perf_session *session;
870 struct perf_data *data;
871
872 session = container_of(ff->ph, struct perf_session, header);
873 data = session->data;
874
875 if (WARN_ON(!perf_data__is_dir(data)))
876 return -1;
877
878 return do_write(ff, &data->dir.version, sizeof(data->dir.version));
879}
880
881#ifdef HAVE_LIBBPF_SUPPORT
882static int write_bpf_prog_info(struct feat_fd *ff,
883 struct perf_evlist *evlist __maybe_unused)
884{
885 struct perf_env *env = &ff->ph->env;
886 struct rb_root *root;
887 struct rb_node *next;
888 int ret;
889
890 down_read(&env->bpf_progs.lock);
891
892 ret = do_write(ff, &env->bpf_progs.infos_cnt,
893 sizeof(env->bpf_progs.infos_cnt));
894 if (ret < 0)
895 goto out;
896
897 root = &env->bpf_progs.infos;
898 next = rb_first(root);
899 while (next) {
900 struct bpf_prog_info_node *node;
901 size_t len;
902
903 node = rb_entry(next, struct bpf_prog_info_node, rb_node);
904 next = rb_next(&node->rb_node);
905 len = sizeof(struct bpf_prog_info_linear) +
906 node->info_linear->data_len;
907
908 /* before writing to file, translate address to offset */
909 bpf_program__bpil_addr_to_offs(node->info_linear);
910 ret = do_write(ff, node->info_linear, len);
911 /*
912 * translate back to address even when do_write() fails,
913 * so that this function never changes the data.
914 */
915 bpf_program__bpil_offs_to_addr(node->info_linear);
916 if (ret < 0)
917 goto out;
918 }
919out:
920 up_read(&env->bpf_progs.lock);
921 return ret;
922}
923#else // HAVE_LIBBPF_SUPPORT
924static int write_bpf_prog_info(struct feat_fd *ff __maybe_unused,
925 struct perf_evlist *evlist __maybe_unused)
926{
927 return 0;
928}
929#endif // HAVE_LIBBPF_SUPPORT
930
931static int write_bpf_btf(struct feat_fd *ff,
932 struct perf_evlist *evlist __maybe_unused)
933{
934 struct perf_env *env = &ff->ph->env;
935 struct rb_root *root;
936 struct rb_node *next;
937 int ret;
938
939 down_read(&env->bpf_progs.lock);
940
941 ret = do_write(ff, &env->bpf_progs.btfs_cnt,
942 sizeof(env->bpf_progs.btfs_cnt));
943
944 if (ret < 0)
945 goto out;
946
947 root = &env->bpf_progs.btfs;
948 next = rb_first(root);
949 while (next) {
950 struct btf_node *node;
951
952 node = rb_entry(next, struct btf_node, rb_node);
953 next = rb_next(&node->rb_node);
954 ret = do_write(ff, &node->id,
955 sizeof(u32) * 2 + node->data_size);
956 if (ret < 0)
957 goto out;
958 }
959out:
960 up_read(&env->bpf_progs.lock);
961 return ret;
962}
963
864static int cpu_cache_level__sort(const void *a, const void *b) 964static int cpu_cache_level__sort(const void *a, const void *b)
865{ 965{
866 struct cpu_cache_level *cache_a = (struct cpu_cache_level *)a; 966 struct cpu_cache_level *cache_a = (struct cpu_cache_level *)a;
@@ -1341,6 +1441,63 @@ static void print_clockid(struct feat_fd *ff, FILE *fp)
1341 ff->ph->env.clockid_res_ns * 1000); 1441 ff->ph->env.clockid_res_ns * 1000);
1342} 1442}
1343 1443
1444static void print_dir_format(struct feat_fd *ff, FILE *fp)
1445{
1446 struct perf_session *session;
1447 struct perf_data *data;
1448
1449 session = container_of(ff->ph, struct perf_session, header);
1450 data = session->data;
1451
1452 fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version);
1453}
1454
1455static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp)
1456{
1457 struct perf_env *env = &ff->ph->env;
1458 struct rb_root *root;
1459 struct rb_node *next;
1460
1461 down_read(&env->bpf_progs.lock);
1462
1463 root = &env->bpf_progs.infos;
1464 next = rb_first(root);
1465
1466 while (next) {
1467 struct bpf_prog_info_node *node;
1468
1469 node = rb_entry(next, struct bpf_prog_info_node, rb_node);
1470 next = rb_next(&node->rb_node);
1471
1472 bpf_event__print_bpf_prog_info(&node->info_linear->info,
1473 env, fp);
1474 }
1475
1476 up_read(&env->bpf_progs.lock);
1477}
1478
1479static void print_bpf_btf(struct feat_fd *ff, FILE *fp)
1480{
1481 struct perf_env *env = &ff->ph->env;
1482 struct rb_root *root;
1483 struct rb_node *next;
1484
1485 down_read(&env->bpf_progs.lock);
1486
1487 root = &env->bpf_progs.btfs;
1488 next = rb_first(root);
1489
1490 while (next) {
1491 struct btf_node *node;
1492
1493 node = rb_entry(next, struct btf_node, rb_node);
1494 next = rb_next(&node->rb_node);
1495 fprintf(fp, "# btf info of id %u\n", node->id);
1496 }
1497
1498 up_read(&env->bpf_progs.lock);
1499}
1500
1344static void free_event_desc(struct perf_evsel *events) 1501static void free_event_desc(struct perf_evsel *events)
1345{ 1502{
1346 struct perf_evsel *evsel; 1503 struct perf_evsel *evsel;
@@ -2373,6 +2530,139 @@ static int process_clockid(struct feat_fd *ff,
2373 return 0; 2530 return 0;
2374} 2531}
2375 2532
2533static int process_dir_format(struct feat_fd *ff,
2534 void *_data __maybe_unused)
2535{
2536 struct perf_session *session;
2537 struct perf_data *data;
2538
2539 session = container_of(ff->ph, struct perf_session, header);
2540 data = session->data;
2541
2542 if (WARN_ON(!perf_data__is_dir(data)))
2543 return -1;
2544
2545 return do_read_u64(ff, &data->dir.version);
2546}
2547
2548#ifdef HAVE_LIBBPF_SUPPORT
2549static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused)
2550{
2551 struct bpf_prog_info_linear *info_linear;
2552 struct bpf_prog_info_node *info_node;
2553 struct perf_env *env = &ff->ph->env;
2554 u32 count, i;
2555 int err = -1;
2556
2557 if (ff->ph->needs_swap) {
2558 pr_warning("interpreting bpf_prog_info from systems with endianity is not yet supported\n");
2559 return 0;
2560 }
2561
2562 if (do_read_u32(ff, &count))
2563 return -1;
2564
2565 down_write(&env->bpf_progs.lock);
2566
2567 for (i = 0; i < count; ++i) {
2568 u32 info_len, data_len;
2569
2570 info_linear = NULL;
2571 info_node = NULL;
2572 if (do_read_u32(ff, &info_len))
2573 goto out;
2574 if (do_read_u32(ff, &data_len))
2575 goto out;
2576
2577 if (info_len > sizeof(struct bpf_prog_info)) {
2578 pr_warning("detected invalid bpf_prog_info\n");
2579 goto out;
2580 }
2581
2582 info_linear = malloc(sizeof(struct bpf_prog_info_linear) +
2583 data_len);
2584 if (!info_linear)
2585 goto out;
2586 info_linear->info_len = sizeof(struct bpf_prog_info);
2587 info_linear->data_len = data_len;
2588 if (do_read_u64(ff, (u64 *)(&info_linear->arrays)))
2589 goto out;
2590 if (__do_read(ff, &info_linear->info, info_len))
2591 goto out;
2592 if (info_len < sizeof(struct bpf_prog_info))
2593 memset(((void *)(&info_linear->info)) + info_len, 0,
2594 sizeof(struct bpf_prog_info) - info_len);
2595
2596 if (__do_read(ff, info_linear->data, data_len))
2597 goto out;
2598
2599 info_node = malloc(sizeof(struct bpf_prog_info_node));
2600 if (!info_node)
2601 goto out;
2602
2603 /* after reading from file, translate offset to address */
2604 bpf_program__bpil_offs_to_addr(info_linear);
2605 info_node->info_linear = info_linear;
2606 perf_env__insert_bpf_prog_info(env, info_node);
2607 }
2608
2609 return 0;
2610out:
2611 free(info_linear);
2612 free(info_node);
2613 up_write(&env->bpf_progs.lock);
2614 return err;
2615}
2616#else // HAVE_LIBBPF_SUPPORT
2617static int process_bpf_prog_info(struct feat_fd *ff __maybe_unused, void *data __maybe_unused)
2618{
2619 return 0;
2620}
2621#endif // HAVE_LIBBPF_SUPPORT
2622
2623static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
2624{
2625 struct perf_env *env = &ff->ph->env;
2626 u32 count, i;
2627
2628 if (ff->ph->needs_swap) {
2629 pr_warning("interpreting btf from systems with endianity is not yet supported\n");
2630 return 0;
2631 }
2632
2633 if (do_read_u32(ff, &count))
2634 return -1;
2635
2636 down_write(&env->bpf_progs.lock);
2637
2638 for (i = 0; i < count; ++i) {
2639 struct btf_node *node;
2640 u32 id, data_size;
2641
2642 if (do_read_u32(ff, &id))
2643 return -1;
2644 if (do_read_u32(ff, &data_size))
2645 return -1;
2646
2647 node = malloc(sizeof(struct btf_node) + data_size);
2648 if (!node)
2649 return -1;
2650
2651 node->id = id;
2652 node->data_size = data_size;
2653
2654 if (__do_read(ff, node->data, data_size)) {
2655 free(node);
2656 return -1;
2657 }
2658
2659 perf_env__insert_btf(env, node);
2660 }
2661
2662 up_write(&env->bpf_progs.lock);
2663 return 0;
2664}
2665
2376struct feature_ops { 2666struct feature_ops {
2377 int (*write)(struct feat_fd *ff, struct perf_evlist *evlist); 2667 int (*write)(struct feat_fd *ff, struct perf_evlist *evlist);
2378 void (*print)(struct feat_fd *ff, FILE *fp); 2668 void (*print)(struct feat_fd *ff, FILE *fp);
@@ -2432,7 +2722,10 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
2432 FEAT_OPN(CACHE, cache, true), 2722 FEAT_OPN(CACHE, cache, true),
2433 FEAT_OPR(SAMPLE_TIME, sample_time, false), 2723 FEAT_OPR(SAMPLE_TIME, sample_time, false),
2434 FEAT_OPR(MEM_TOPOLOGY, mem_topology, true), 2724 FEAT_OPR(MEM_TOPOLOGY, mem_topology, true),
2435 FEAT_OPR(CLOCKID, clockid, false) 2725 FEAT_OPR(CLOCKID, clockid, false),
2726 FEAT_OPN(DIR_FORMAT, dir_format, false),
2727 FEAT_OPR(BPF_PROG_INFO, bpf_prog_info, false),
2728 FEAT_OPR(BPF_BTF, bpf_btf, false),
2436}; 2729};
2437 2730
2438struct header_print_data { 2731struct header_print_data {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 0d553ddca0a3..386da49e1bfa 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -39,6 +39,9 @@ enum {
39 HEADER_SAMPLE_TIME, 39 HEADER_SAMPLE_TIME,
40 HEADER_MEM_TOPOLOGY, 40 HEADER_MEM_TOPOLOGY,
41 HEADER_CLOCKID, 41 HEADER_CLOCKID,
42 HEADER_DIR_FORMAT,
43 HEADER_BPF_PROG_INFO,
44 HEADER_BPF_BTF,
42 HEADER_LAST_FEATURE, 45 HEADER_LAST_FEATURE,
43 HEADER_FEAT_BITS = 256, 46 HEADER_FEAT_BITS = 256,
44}; 47};
@@ -48,6 +51,10 @@ enum perf_header_version {
48 PERF_HEADER_VERSION_2, 51 PERF_HEADER_VERSION_2,
49}; 52};
50 53
54enum perf_dir_version {
55 PERF_DIR_VERSION = 1,
56};
57
51struct perf_file_section { 58struct perf_file_section {
52 u64 offset; 59 u64 offset;
53 u64 size; 60 u64 size;
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index f9eb95bf3938..7ace7a10054d 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -19,6 +19,7 @@
19#include <math.h> 19#include <math.h>
20#include <inttypes.h> 20#include <inttypes.h>
21#include <sys/param.h> 21#include <sys/param.h>
22#include <linux/time64.h>
22 23
23static bool hists__filter_entry_by_dso(struct hists *hists, 24static bool hists__filter_entry_by_dso(struct hists *hists,
24 struct hist_entry *he); 25 struct hist_entry *he);
@@ -192,6 +193,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
192 hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3); 193 hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3);
193 hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12); 194 hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12);
194 hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12); 195 hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12);
196 hists__new_col_len(hists, HISTC_TIME, 12);
195 197
196 if (h->srcline) { 198 if (h->srcline) {
197 len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header)); 199 len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header));
@@ -246,6 +248,14 @@ static void he_stat__add_cpumode_period(struct he_stat *he_stat,
246 } 248 }
247} 249}
248 250
251static long hist_time(unsigned long htime)
252{
253 unsigned long time_quantum = symbol_conf.time_quantum;
254 if (time_quantum)
255 return (htime / time_quantum) * time_quantum;
256 return htime;
257}
258
249static void he_stat__add_period(struct he_stat *he_stat, u64 period, 259static void he_stat__add_period(struct he_stat *he_stat, u64 period,
250 u64 weight) 260 u64 weight)
251{ 261{
@@ -426,6 +436,13 @@ static int hist_entry__init(struct hist_entry *he,
426 goto err_rawdata; 436 goto err_rawdata;
427 } 437 }
428 438
439 if (symbol_conf.res_sample) {
440 he->res_samples = calloc(sizeof(struct res_sample),
441 symbol_conf.res_sample);
442 if (!he->res_samples)
443 goto err_srcline;
444 }
445
429 INIT_LIST_HEAD(&he->pairs.node); 446 INIT_LIST_HEAD(&he->pairs.node);
430 thread__get(he->thread); 447 thread__get(he->thread);
431 he->hroot_in = RB_ROOT_CACHED; 448 he->hroot_in = RB_ROOT_CACHED;
@@ -436,6 +453,9 @@ static int hist_entry__init(struct hist_entry *he,
436 453
437 return 0; 454 return 0;
438 455
456err_srcline:
457 free(he->srcline);
458
439err_rawdata: 459err_rawdata:
440 free(he->raw_data); 460 free(he->raw_data);
441 461
@@ -593,6 +613,32 @@ out:
593 return he; 613 return he;
594} 614}
595 615
616static unsigned random_max(unsigned high)
617{
618 unsigned thresh = -high % high;
619 for (;;) {
620 unsigned r = random();
621 if (r >= thresh)
622 return r % high;
623 }
624}
625
626static void hists__res_sample(struct hist_entry *he, struct perf_sample *sample)
627{
628 struct res_sample *r;
629 int j;
630
631 if (he->num_res < symbol_conf.res_sample) {
632 j = he->num_res++;
633 } else {
634 j = random_max(symbol_conf.res_sample);
635 }
636 r = &he->res_samples[j];
637 r->time = sample->time;
638 r->cpu = sample->cpu;
639 r->tid = sample->tid;
640}
641
596static struct hist_entry* 642static struct hist_entry*
597__hists__add_entry(struct hists *hists, 643__hists__add_entry(struct hists *hists,
598 struct addr_location *al, 644 struct addr_location *al,
@@ -635,10 +681,13 @@ __hists__add_entry(struct hists *hists,
635 .raw_data = sample->raw_data, 681 .raw_data = sample->raw_data,
636 .raw_size = sample->raw_size, 682 .raw_size = sample->raw_size,
637 .ops = ops, 683 .ops = ops,
684 .time = hist_time(sample->time),
638 }, *he = hists__findnew_entry(hists, &entry, al, sample_self); 685 }, *he = hists__findnew_entry(hists, &entry, al, sample_self);
639 686
640 if (!hists->has_callchains && he && he->callchain_size != 0) 687 if (!hists->has_callchains && he && he->callchain_size != 0)
641 hists->has_callchains = true; 688 hists->has_callchains = true;
689 if (he && symbol_conf.res_sample)
690 hists__res_sample(he, sample);
642 return he; 691 return he;
643} 692}
644 693
@@ -1062,8 +1111,10 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
1062 1111
1063 err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent, 1112 err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent,
1064 iter->evsel, al, max_stack_depth); 1113 iter->evsel, al, max_stack_depth);
1065 if (err) 1114 if (err) {
1115 map__put(alm);
1066 return err; 1116 return err;
1117 }
1067 1118
1068 err = iter->ops->prepare_entry(iter, al); 1119 err = iter->ops->prepare_entry(iter, al);
1069 if (err) 1120 if (err)
@@ -1162,6 +1213,7 @@ void hist_entry__delete(struct hist_entry *he)
1162 mem_info__zput(he->mem_info); 1213 mem_info__zput(he->mem_info);
1163 } 1214 }
1164 1215
1216 zfree(&he->res_samples);
1165 zfree(&he->stat_acc); 1217 zfree(&he->stat_acc);
1166 free_srcline(he->srcline); 1218 free_srcline(he->srcline);
1167 if (he->srcfile && he->srcfile[0]) 1219 if (he->srcfile && he->srcfile[0])
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 4af27fbab24f..76ff6c6d03b8 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -31,6 +31,7 @@ enum hist_filter {
31 31
32enum hist_column { 32enum hist_column {
33 HISTC_SYMBOL, 33 HISTC_SYMBOL,
34 HISTC_TIME,
34 HISTC_DSO, 35 HISTC_DSO,
35 HISTC_THREAD, 36 HISTC_THREAD,
36 HISTC_COMM, 37 HISTC_COMM,
@@ -432,9 +433,18 @@ struct hist_browser_timer {
432}; 433};
433 434
434struct annotation_options; 435struct annotation_options;
436struct res_sample;
437
438enum rstype {
439 A_NORMAL,
440 A_ASM,
441 A_SOURCE
442};
435 443
436#ifdef HAVE_SLANG_SUPPORT 444#ifdef HAVE_SLANG_SUPPORT
437#include "../ui/keysyms.h" 445#include "../ui/keysyms.h"
446void attr_to_script(char *buf, struct perf_event_attr *attr);
447
438int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel, 448int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel,
439 struct hist_browser_timer *hbt, 449 struct hist_browser_timer *hbt,
440 struct annotation_options *annotation_opts); 450 struct annotation_options *annotation_opts);
@@ -449,7 +459,13 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
449 struct perf_env *env, 459 struct perf_env *env,
450 bool warn_lost_event, 460 bool warn_lost_event,
451 struct annotation_options *annotation_options); 461 struct annotation_options *annotation_options);
452int script_browse(const char *script_opt); 462
463int script_browse(const char *script_opt, struct perf_evsel *evsel);
464
465void run_script(char *cmd);
466int res_sample_browse(struct res_sample *res_samples, int num_res,
467 struct perf_evsel *evsel, enum rstype rstype);
468void res_sample_init(void);
453#else 469#else
454static inline 470static inline
455int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, 471int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
@@ -478,11 +494,22 @@ static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
478 return 0; 494 return 0;
479} 495}
480 496
481static inline int script_browse(const char *script_opt __maybe_unused) 497static inline int script_browse(const char *script_opt __maybe_unused,
498 struct perf_evsel *evsel __maybe_unused)
482{ 499{
483 return 0; 500 return 0;
484} 501}
485 502
503static inline int res_sample_browse(struct res_sample *res_samples __maybe_unused,
504 int num_res __maybe_unused,
505 struct perf_evsel *evsel __maybe_unused,
506 enum rstype rstype __maybe_unused)
507{
508 return 0;
509}
510
511static inline void res_sample_init(void) {}
512
486#define K_LEFT -1000 513#define K_LEFT -1000
487#define K_RIGHT -2000 514#define K_RIGHT -2000
488#define K_SWITCH_INPUT_DATA -3000 515#define K_SWITCH_INPUT_DATA -3000
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index fbeb0c6efaa6..e32628cd20a7 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -577,10 +577,25 @@ static void __maps__purge(struct maps *maps)
577 } 577 }
578} 578}
579 579
580static void __maps__purge_names(struct maps *maps)
581{
582 struct rb_root *root = &maps->names;
583 struct rb_node *next = rb_first(root);
584
585 while (next) {
586 struct map *pos = rb_entry(next, struct map, rb_node_name);
587
588 next = rb_next(&pos->rb_node_name);
589 rb_erase_init(&pos->rb_node_name, root);
590 map__put(pos);
591 }
592}
593
580static void maps__exit(struct maps *maps) 594static void maps__exit(struct maps *maps)
581{ 595{
582 down_write(&maps->lock); 596 down_write(&maps->lock);
583 __maps__purge(maps); 597 __maps__purge(maps);
598 __maps__purge_names(maps);
584 up_write(&maps->lock); 599 up_write(&maps->lock);
585} 600}
586 601
@@ -917,6 +932,9 @@ static void __maps__remove(struct maps *maps, struct map *map)
917{ 932{
918 rb_erase_init(&map->rb_node, &maps->entries); 933 rb_erase_init(&map->rb_node, &maps->entries);
919 map__put(map); 934 map__put(map);
935
936 rb_erase_init(&map->rb_node_name, &maps->names);
937 map__put(map);
920} 938}
921 939
922void maps__remove(struct maps *maps, struct map *map) 940void maps__remove(struct maps *maps, struct map *map)
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index ea523d3b248f..989fed6f43b5 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -270,6 +270,8 @@ static int __ordered_events__flush(struct ordered_events *oe, enum oe_flush how,
270 "FINAL", 270 "FINAL",
271 "ROUND", 271 "ROUND",
272 "HALF ", 272 "HALF ",
273 "TOP ",
274 "TIME ",
273 }; 275 };
274 int err; 276 int err;
275 bool show_progress = false; 277 bool show_progress = false;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 4dcc01b2532c..5ef4939408f2 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2271,6 +2271,7 @@ static bool is_event_supported(u8 type, unsigned config)
2271 perf_evsel__delete(evsel); 2271 perf_evsel__delete(evsel);
2272 } 2272 }
2273 2273
2274 thread_map__put(tmap);
2274 return ret; 2275 return ret;
2275} 2276}
2276 2277
@@ -2341,6 +2342,7 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob,
2341 printf(" %-50s [%s]\n", buf, "SDT event"); 2342 printf(" %-50s [%s]\n", buf, "SDT event");
2342 free(buf); 2343 free(buf);
2343 } 2344 }
2345 free(path);
2344 } else 2346 } else
2345 printf(" %-50s [%s]\n", nd->s, "SDT event"); 2347 printf(" %-50s [%s]\n", nd->s, "SDT event");
2346 if (nd2) { 2348 if (nd2) {
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a1b8d9649ca7..198e09ff611e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -160,8 +160,10 @@ static struct map *kernel_get_module_map(const char *module)
160 if (module && strchr(module, '/')) 160 if (module && strchr(module, '/'))
161 return dso__new_map(module); 161 return dso__new_map(module);
162 162
163 if (!module) 163 if (!module) {
164 module = "kernel"; 164 pos = machine__kernel_map(host_machine);
165 return map__get(pos);
166 }
165 167
166 for (pos = maps__first(maps); pos; pos = map__next(pos)) { 168 for (pos = maps__first(maps); pos; pos = map__next(pos)) {
167 /* short_name is "[module]" */ 169 /* short_name is "[module]" */
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index db643f3c2b95..b17f1c9bc965 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -132,6 +132,7 @@ struct perf_session *perf_session__new(struct perf_data *data,
132 ordered_events__init(&session->ordered_events, 132 ordered_events__init(&session->ordered_events,
133 ordered_events__deliver_event, NULL); 133 ordered_events__deliver_event, NULL);
134 134
135 perf_env__init(&session->header.env);
135 if (data) { 136 if (data) {
136 if (perf_data__open(data)) 137 if (perf_data__open(data))
137 goto out_delete; 138 goto out_delete;
@@ -152,6 +153,10 @@ struct perf_session *perf_session__new(struct perf_data *data,
152 } 153 }
153 154
154 perf_evlist__init_trace_event_sample_raw(session->evlist); 155 perf_evlist__init_trace_event_sample_raw(session->evlist);
156
157 /* Open the directory data. */
158 if (data->is_dir && perf_data__open_dir(data))
159 goto out_delete;
155 } 160 }
156 } else { 161 } else {
157 session->machines.host.env = &perf_env; 162 session->machines.host.env = &perf_env;
@@ -1843,10 +1848,17 @@ fetch_mmaped_event(struct perf_session *session,
1843#define NUM_MMAPS 128 1848#define NUM_MMAPS 128
1844#endif 1849#endif
1845 1850
1851struct reader;
1852
1853typedef s64 (*reader_cb_t)(struct perf_session *session,
1854 union perf_event *event,
1855 u64 file_offset);
1856
1846struct reader { 1857struct reader {
1847 int fd; 1858 int fd;
1848 u64 data_size; 1859 u64 data_size;
1849 u64 data_offset; 1860 u64 data_offset;
1861 reader_cb_t process;
1850}; 1862};
1851 1863
1852static int 1864static int
@@ -1917,7 +1929,7 @@ more:
1917 size = event->header.size; 1929 size = event->header.size;
1918 1930
1919 if (size < sizeof(struct perf_event_header) || 1931 if (size < sizeof(struct perf_event_header) ||
1920 (skip = perf_session__process_event(session, event, file_pos)) < 0) { 1932 (skip = rd->process(session, event, file_pos)) < 0) {
1921 pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n", 1933 pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
1922 file_offset + head, event->header.size, 1934 file_offset + head, event->header.size,
1923 event->header.type); 1935 event->header.type);
@@ -1943,12 +1955,20 @@ out:
1943 return err; 1955 return err;
1944} 1956}
1945 1957
1958static s64 process_simple(struct perf_session *session,
1959 union perf_event *event,
1960 u64 file_offset)
1961{
1962 return perf_session__process_event(session, event, file_offset);
1963}
1964
1946static int __perf_session__process_events(struct perf_session *session) 1965static int __perf_session__process_events(struct perf_session *session)
1947{ 1966{
1948 struct reader rd = { 1967 struct reader rd = {
1949 .fd = perf_data__fd(session->data), 1968 .fd = perf_data__fd(session->data),
1950 .data_size = session->header.data_size, 1969 .data_size = session->header.data_size,
1951 .data_offset = session->header.data_offset, 1970 .data_offset = session->header.data_offset,
1971 .process = process_simple,
1952 }; 1972 };
1953 struct ordered_events *oe = &session->ordered_events; 1973 struct ordered_events *oe = &session->ordered_events;
1954 struct perf_tool *tool = session->tool; 1974 struct perf_tool *tool = session->tool;
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index d2299e912e59..5d2518e89fc4 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -3,6 +3,7 @@
3#include <inttypes.h> 3#include <inttypes.h>
4#include <regex.h> 4#include <regex.h>
5#include <linux/mman.h> 5#include <linux/mman.h>
6#include <linux/time64.h>
6#include "sort.h" 7#include "sort.h"
7#include "hist.h" 8#include "hist.h"
8#include "comm.h" 9#include "comm.h"
@@ -12,9 +13,11 @@
12#include "evsel.h" 13#include "evsel.h"
13#include "evlist.h" 14#include "evlist.h"
14#include "strlist.h" 15#include "strlist.h"
16#include "strbuf.h"
15#include <traceevent/event-parse.h> 17#include <traceevent/event-parse.h>
16#include "mem-events.h" 18#include "mem-events.h"
17#include "annotate.h" 19#include "annotate.h"
20#include "time-utils.h"
18#include <linux/kernel.h> 21#include <linux/kernel.h>
19 22
20regex_t parent_regex; 23regex_t parent_regex;
@@ -654,6 +657,42 @@ struct sort_entry sort_socket = {
654 .se_width_idx = HISTC_SOCKET, 657 .se_width_idx = HISTC_SOCKET,
655}; 658};
656 659
660/* --sort time */
661
662static int64_t
663sort__time_cmp(struct hist_entry *left, struct hist_entry *right)
664{
665 return right->time - left->time;
666}
667
668static int hist_entry__time_snprintf(struct hist_entry *he, char *bf,
669 size_t size, unsigned int width)
670{
671 unsigned long secs;
672 unsigned long long nsecs;
673 char he_time[32];
674
675 nsecs = he->time;
676 secs = nsecs / NSEC_PER_SEC;
677 nsecs -= secs * NSEC_PER_SEC;
678
679 if (symbol_conf.nanosecs)
680 snprintf(he_time, sizeof he_time, "%5lu.%09llu: ",
681 secs, nsecs);
682 else
683 timestamp__scnprintf_usec(he->time, he_time,
684 sizeof(he_time));
685
686 return repsep_snprintf(bf, size, "%-.*s", width, he_time);
687}
688
689struct sort_entry sort_time = {
690 .se_header = "Time",
691 .se_cmp = sort__time_cmp,
692 .se_snprintf = hist_entry__time_snprintf,
693 .se_width_idx = HISTC_TIME,
694};
695
657/* --sort trace */ 696/* --sort trace */
658 697
659static char *get_trace_output(struct hist_entry *he) 698static char *get_trace_output(struct hist_entry *he)
@@ -1634,6 +1673,7 @@ static struct sort_dimension common_sort_dimensions[] = {
1634 DIM(SORT_DSO_SIZE, "dso_size", sort_dso_size), 1673 DIM(SORT_DSO_SIZE, "dso_size", sort_dso_size),
1635 DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id), 1674 DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id),
1636 DIM(SORT_SYM_IPC_NULL, "ipc_null", sort_sym_ipc_null), 1675 DIM(SORT_SYM_IPC_NULL, "ipc_null", sort_sym_ipc_null),
1676 DIM(SORT_TIME, "time", sort_time),
1637}; 1677};
1638 1678
1639#undef DIM 1679#undef DIM
@@ -3068,3 +3108,54 @@ void reset_output_field(void)
3068 reset_dimensions(); 3108 reset_dimensions();
3069 perf_hpp__reset_output_field(&perf_hpp_list); 3109 perf_hpp__reset_output_field(&perf_hpp_list);
3070} 3110}
3111
3112#define INDENT (3*8 + 1)
3113
3114static void add_key(struct strbuf *sb, const char *str, int *llen)
3115{
3116 if (*llen >= 75) {
3117 strbuf_addstr(sb, "\n\t\t\t ");
3118 *llen = INDENT;
3119 }
3120 strbuf_addf(sb, " %s", str);
3121 *llen += strlen(str) + 1;
3122}
3123
3124static void add_sort_string(struct strbuf *sb, struct sort_dimension *s, int n,
3125 int *llen)
3126{
3127 int i;
3128
3129 for (i = 0; i < n; i++)
3130 add_key(sb, s[i].name, llen);
3131}
3132
3133static void add_hpp_sort_string(struct strbuf *sb, struct hpp_dimension *s, int n,
3134 int *llen)
3135{
3136 int i;
3137
3138 for (i = 0; i < n; i++)
3139 add_key(sb, s[i].name, llen);
3140}
3141
3142const char *sort_help(const char *prefix)
3143{
3144 struct strbuf sb;
3145 char *s;
3146 int len = strlen(prefix) + INDENT;
3147
3148 strbuf_init(&sb, 300);
3149 strbuf_addstr(&sb, prefix);
3150 add_hpp_sort_string(&sb, hpp_sort_dimensions,
3151 ARRAY_SIZE(hpp_sort_dimensions), &len);
3152 add_sort_string(&sb, common_sort_dimensions,
3153 ARRAY_SIZE(common_sort_dimensions), &len);
3154 add_sort_string(&sb, bstack_sort_dimensions,
3155 ARRAY_SIZE(bstack_sort_dimensions), &len);
3156 add_sort_string(&sb, memory_sort_dimensions,
3157 ARRAY_SIZE(memory_sort_dimensions), &len);
3158 s = strbuf_detach(&sb, NULL);
3159 strbuf_release(&sb);
3160 return s;
3161}
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 2fbee0b1011c..ce376a73f964 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -47,6 +47,12 @@ extern struct sort_entry sort_srcline;
47extern enum sort_type sort__first_dimension; 47extern enum sort_type sort__first_dimension;
48extern const char default_mem_sort_order[]; 48extern const char default_mem_sort_order[];
49 49
50struct res_sample {
51 u64 time;
52 int cpu;
53 int tid;
54};
55
50struct he_stat { 56struct he_stat {
51 u64 period; 57 u64 period;
52 u64 period_sys; 58 u64 period_sys;
@@ -135,10 +141,13 @@ struct hist_entry {
135 char *srcfile; 141 char *srcfile;
136 struct symbol *parent; 142 struct symbol *parent;
137 struct branch_info *branch_info; 143 struct branch_info *branch_info;
144 long time;
138 struct hists *hists; 145 struct hists *hists;
139 struct mem_info *mem_info; 146 struct mem_info *mem_info;
140 void *raw_data; 147 void *raw_data;
141 u32 raw_size; 148 u32 raw_size;
149 int num_res;
150 struct res_sample *res_samples;
142 void *trace_output; 151 void *trace_output;
143 struct perf_hpp_list *hpp_list; 152 struct perf_hpp_list *hpp_list;
144 struct hist_entry *parent_he; 153 struct hist_entry *parent_he;
@@ -231,6 +240,7 @@ enum sort_type {
231 SORT_DSO_SIZE, 240 SORT_DSO_SIZE,
232 SORT_CGROUP_ID, 241 SORT_CGROUP_ID,
233 SORT_SYM_IPC_NULL, 242 SORT_SYM_IPC_NULL,
243 SORT_TIME,
234 244
235 /* branch stack specific sort keys */ 245 /* branch stack specific sort keys */
236 __SORT_BRANCH_STACK, 246 __SORT_BRANCH_STACK,
@@ -286,6 +296,8 @@ void reset_output_field(void);
286void sort__setup_elide(FILE *fp); 296void sort__setup_elide(FILE *fp);
287void perf_hpp__set_elide(int idx, bool elide); 297void perf_hpp__set_elide(int idx, bool elide);
288 298
299const char *sort_help(const char *prefix);
300
289int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); 301int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
290 302
291bool is_strict_order(const char *order); 303bool is_strict_order(const char *order);
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 4d40515307b8..2856cc9d5a31 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -291,10 +291,8 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel
291 break; 291 break;
292 case AGGR_GLOBAL: 292 case AGGR_GLOBAL:
293 aggr->val += count->val; 293 aggr->val += count->val;
294 if (config->scale) { 294 aggr->ena += count->ena;
295 aggr->ena += count->ena; 295 aggr->run += count->run;
296 aggr->run += count->run;
297 }
298 case AGGR_UNSET: 296 case AGGR_UNSET:
299 default: 297 default:
300 break; 298 break;
@@ -442,10 +440,8 @@ int create_perf_stat_counter(struct perf_evsel *evsel,
442 struct perf_event_attr *attr = &evsel->attr; 440 struct perf_event_attr *attr = &evsel->attr;
443 struct perf_evsel *leader = evsel->leader; 441 struct perf_evsel *leader = evsel->leader;
444 442
445 if (config->scale) { 443 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
446 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | 444 PERF_FORMAT_TOTAL_TIME_RUNNING;
447 PERF_FORMAT_TOTAL_TIME_RUNNING;
448 }
449 445
450 /* 446 /*
451 * The event is part of non trivial group, let's enable 447 * The event is part of non trivial group, let's enable
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 758bf5f74e6e..5cbad55cd99d 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -6,6 +6,7 @@
6#include <string.h> 6#include <string.h>
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/mman.h> 8#include <linux/mman.h>
9#include <linux/time64.h>
9#include <sys/types.h> 10#include <sys/types.h>
10#include <sys/stat.h> 11#include <sys/stat.h>
11#include <sys/param.h> 12#include <sys/param.h>
@@ -39,15 +40,18 @@ int vmlinux_path__nr_entries;
39char **vmlinux_path; 40char **vmlinux_path;
40 41
41struct symbol_conf symbol_conf = { 42struct symbol_conf symbol_conf = {
43 .nanosecs = false,
42 .use_modules = true, 44 .use_modules = true,
43 .try_vmlinux_path = true, 45 .try_vmlinux_path = true,
44 .demangle = true, 46 .demangle = true,
45 .demangle_kernel = false, 47 .demangle_kernel = false,
46 .cumulate_callchain = true, 48 .cumulate_callchain = true,
49 .time_quantum = 100 * NSEC_PER_MSEC, /* 100ms */
47 .show_hist_headers = true, 50 .show_hist_headers = true,
48 .symfs = "", 51 .symfs = "",
49 .event_group = true, 52 .event_group = true,
50 .inline_name = true, 53 .inline_name = true,
54 .res_sample = 0,
51}; 55};
52 56
53static enum dso_binary_type binary_type_symtab[] = { 57static enum dso_binary_type binary_type_symtab[] = {
@@ -1451,6 +1455,7 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
1451 case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: 1455 case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO:
1452 return true; 1456 return true;
1453 1457
1458 case DSO_BINARY_TYPE__BPF_PROG_INFO:
1454 case DSO_BINARY_TYPE__NOT_FOUND: 1459 case DSO_BINARY_TYPE__NOT_FOUND:
1455 default: 1460 default:
1456 return false; 1461 return false;
diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
index fffea68c1203..6c55fa6fccec 100644
--- a/tools/perf/util/symbol_conf.h
+++ b/tools/perf/util/symbol_conf.h
@@ -8,6 +8,7 @@ struct strlist;
8struct intlist; 8struct intlist;
9 9
10struct symbol_conf { 10struct symbol_conf {
11 bool nanosecs;
11 unsigned short priv_size; 12 unsigned short priv_size;
12 bool try_vmlinux_path, 13 bool try_vmlinux_path,
13 init_annotation, 14 init_annotation,
@@ -55,6 +56,7 @@ struct symbol_conf {
55 *sym_list_str, 56 *sym_list_str,
56 *col_width_list_str, 57 *col_width_list_str,
57 *bt_stop_list_str; 58 *bt_stop_list_str;
59 unsigned long time_quantum;
58 struct strlist *dso_list, 60 struct strlist *dso_list,
59 *comm_list, 61 *comm_list,
60 *sym_list, 62 *sym_list,
@@ -66,6 +68,7 @@ struct symbol_conf {
66 struct intlist *pid_list, 68 struct intlist *pid_list,
67 *tid_list; 69 *tid_list;
68 const char *symfs; 70 const char *symfs;
71 int res_sample;
69}; 72};
70 73
71extern struct symbol_conf symbol_conf; 74extern struct symbol_conf symbol_conf;
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 0f53baec660e..20663a460df3 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -453,6 +453,14 @@ int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
453 return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); 453 return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec);
454} 454}
455 455
456int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz)
457{
458 u64 sec = timestamp / NSEC_PER_SEC,
459 nsec = timestamp % NSEC_PER_SEC;
460
461 return scnprintf(buf, sz, "%" PRIu64 ".%09" PRIu64, sec, nsec);
462}
463
456int fetch_current_timestamp(char *buf, size_t sz) 464int fetch_current_timestamp(char *buf, size_t sz)
457{ 465{
458 struct timeval tv; 466 struct timeval tv;
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index b923de44e36f..72a42ea1d513 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -30,6 +30,7 @@ int perf_time__parse_for_ranges(const char *str, struct perf_session *session,
30 int *range_size, int *range_num); 30 int *range_size, int *range_num);
31 31
32int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); 32int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
33int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz);
33 34
34int fetch_current_timestamp(char *buf, size_t sz); 35int fetch_current_timestamp(char *buf, size_t sz);
35 36
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 9327c0ddc3a5..c3fad065c89c 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -5077,6 +5077,9 @@ int fork_it(char **argv)
5077 signal(SIGQUIT, SIG_IGN); 5077 signal(SIGQUIT, SIG_IGN);
5078 if (waitpid(child_pid, &status, 0) == -1) 5078 if (waitpid(child_pid, &status, 0) == -1)
5079 err(status, "waitpid"); 5079 err(status, "waitpid");
5080
5081 if (WIFEXITED(status))
5082 status = WEXITSTATUS(status);
5080 } 5083 }
5081 /* 5084 /*
5082 * n.b. fork_it() does not check for errors from for_all_cpus() 5085 * n.b. fork_it() does not check for errors from for_all_cpus()