aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/obsolete/sysfs-class-dax22
-rw-r--r--Documentation/ABI/testing/sysfs-fs-f2fs7
-rw-r--r--Documentation/admin-guide/md.rst3
-rw-r--r--Documentation/arm/kernel_mode_neon.txt4
-rw-r--r--Documentation/devicetree/bindings/display/ssd1307fb.txt2
-rw-r--r--Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt1
-rw-r--r--Documentation/filesystems/cifs/TODO3
-rw-r--r--Documentation/filesystems/cifs/cifs.txt34
-rw-r--r--Documentation/filesystems/f2fs.txt2
-rw-r--r--Documentation/kbuild/makefiles.txt2
-rw-r--r--Documentation/virtual/kvm/api.txt17
-rw-r--r--Documentation/virtual/kvm/halt-polling.txt37
-rw-r--r--Documentation/virtual/kvm/mmu.txt41
-rw-r--r--MAINTAINERS31
-rw-r--r--Makefile22
-rw-r--r--arch/alpha/include/uapi/asm/Kbuild2
-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/include/uapi/asm/Kbuild2
-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/Kconfig3
-rw-r--r--arch/arm/Kconfig-nommu2
-rw-r--r--arch/arm/Makefile2
-rw-r--r--arch/arm/boot/bootp/Makefile2
-rw-r--r--arch/arm/boot/bootp/init.S2
-rw-r--r--arch/arm/boot/compressed/Makefile2
-rw-r--r--arch/arm/boot/compressed/ll_char_wr.S4
-rw-r--r--arch/arm/boot/dts/imx28-cfa10036.dts3
-rw-r--r--arch/arm/common/mcpm_entry.c2
-rw-r--r--arch/arm/include/asm/Kbuild1
-rw-r--r--arch/arm/include/asm/arch_gicv3.h4
-rw-r--r--arch/arm/include/asm/assembler.h12
-rw-r--r--arch/arm/include/asm/barrier.h2
-rw-r--r--arch/arm/include/asm/hardware/entry-macro-iomd.S10
-rw-r--r--arch/arm/include/asm/kvm_emulate.h8
-rw-r--r--arch/arm/include/asm/kvm_host.h53
-rw-r--r--arch/arm/include/asm/kvm_hyp.h4
-rw-r--r--arch/arm/include/asm/kvm_mmu.h9
-rw-r--r--arch/arm/include/asm/pgtable.h3
-rw-r--r--arch/arm/include/asm/processor.h6
-rw-r--r--arch/arm/include/asm/smp.h1
-rw-r--r--arch/arm/include/asm/smp_twd.h16
-rw-r--r--arch/arm/include/asm/spinlock.h3
-rw-r--r--arch/arm/include/asm/suspend.h1
-rw-r--r--arch/arm/include/asm/uaccess.h3
-rw-r--r--arch/arm/include/asm/v7m.h2
-rw-r--r--arch/arm/include/asm/vfpmacros.h8
-rw-r--r--arch/arm/include/debug/tegra.S2
-rw-r--r--arch/arm/include/uapi/asm/Kbuild1
-rw-r--r--arch/arm/kernel/debug.S2
-rw-r--r--arch/arm/kernel/entry-armv.S12
-rw-r--r--arch/arm/kernel/entry-common.S2
-rw-r--r--arch/arm/kernel/entry-header.S11
-rw-r--r--arch/arm/kernel/entry-v7m.S4
-rw-r--r--arch/arm/kernel/head-nommu.S4
-rw-r--r--arch/arm/kernel/hyp-stub.S4
-rw-r--r--arch/arm/kernel/machine_kexec.c5
-rw-r--r--arch/arm/kernel/patch.c6
-rw-r--r--arch/arm/kernel/sleep.S12
-rw-r--r--arch/arm/kernel/smp.c10
-rw-r--r--arch/arm/kernel/smp_twd.c66
-rw-r--r--arch/arm/kernel/unwind.c14
-rw-r--r--arch/arm/kvm/Makefile5
-rw-r--r--arch/arm/kvm/coproc.c23
-rw-r--r--arch/arm/kvm/hyp/cp15-sr.c1
-rw-r--r--arch/arm/kvm/hyp/hyp-entry.S2
-rw-r--r--arch/arm/kvm/hyp/switch.c2
-rw-r--r--arch/arm/kvm/hyp/tlb.c4
-rw-r--r--arch/arm/kvm/interrupts.S4
-rw-r--r--arch/arm/lib/Makefile2
-rw-r--r--arch/arm/lib/bitops.h8
-rw-r--r--arch/arm/lib/clear_user.S2
-rw-r--r--arch/arm/lib/copy_from_user.S2
-rw-r--r--arch/arm/lib/copy_page.S4
-rw-r--r--arch/arm/lib/copy_template.S6
-rw-r--r--arch/arm/lib/copy_to_user.S2
-rw-r--r--arch/arm/lib/csumpartial.S20
-rw-r--r--arch/arm/lib/csumpartialcopygeneric.S4
-rw-r--r--arch/arm/lib/csumpartialcopyuser.S2
-rw-r--r--arch/arm/lib/div64.S4
-rw-r--r--arch/arm/lib/floppydma.S10
-rw-r--r--arch/arm/lib/io-readsb.S20
-rw-r--r--arch/arm/lib/io-readsl.S2
-rw-r--r--arch/arm/lib/io-readsw-armv3.S6
-rw-r--r--arch/arm/lib/io-readsw-armv4.S12
-rw-r--r--arch/arm/lib/io-writesb.S20
-rw-r--r--arch/arm/lib/io-writesl.S2
-rw-r--r--arch/arm/lib/io-writesw-armv3.S2
-rw-r--r--arch/arm/lib/io-writesw-armv4.S6
-rw-r--r--arch/arm/lib/lib1funcs.S4
-rw-r--r--arch/arm/lib/memcpy.S4
-rw-r--r--arch/arm/lib/memmove.S24
-rw-r--r--arch/arm/lib/memset.S42
-rw-r--r--arch/arm/lib/xor-neon.c2
-rw-r--r--arch/arm/mach-actions/platsmp.c15
-rw-r--r--arch/arm/mach-cns3xxx/core.c2
-rw-r--r--arch/arm/mach-exynos/headsmp.S2
-rw-r--r--arch/arm/mach-exynos/platsmp.c31
-rw-r--r--arch/arm/mach-ks8695/include/mach/entry-macro.S2
-rw-r--r--arch/arm/mach-omap2/prm_common.c4
-rw-r--r--arch/arm/mach-oxnas/Makefile1
-rw-r--r--arch/arm/mach-oxnas/hotplug.c109
-rw-r--r--arch/arm/mach-oxnas/platsmp.c4
-rw-r--r--arch/arm/mach-prima2/common.h2
-rw-r--r--arch/arm/mach-prima2/headsmp.S2
-rw-r--r--arch/arm/mach-prima2/hotplug.c3
-rw-r--r--arch/arm/mach-prima2/platsmp.c17
-rw-r--r--arch/arm/mach-qcom/platsmp.c26
-rw-r--r--arch/arm/mach-spear/generic.h2
-rw-r--r--arch/arm/mach-spear/headsmp.S2
-rw-r--r--arch/arm/mach-spear/hotplug.c4
-rw-r--r--arch/arm/mach-spear/platsmp.c27
-rw-r--r--arch/arm/mach-tegra/reset-handler.S2
-rw-r--r--arch/arm/mm/cache-v6.S8
-rw-r--r--arch/arm/mm/copypage-v4mc.c3
-rw-r--r--arch/arm/mm/copypage-v4wb.c3
-rw-r--r--arch/arm/mm/copypage-v4wt.c3
-rw-r--r--arch/arm/mm/dma-mapping.c2
-rw-r--r--arch/arm/mm/idmap.c4
-rw-r--r--arch/arm/mm/init.c69
-rw-r--r--arch/arm/mm/pmsa-v8.c4
-rw-r--r--arch/arm/mm/proc-v7m.S7
-rw-r--r--arch/arm64/Kconfig1
-rw-r--r--arch/arm64/include/asm/cputype.h6
-rw-r--r--arch/arm64/include/asm/kvm_emulate.h12
-rw-r--r--arch/arm64/include/asm/kvm_host.h48
-rw-r--r--arch/arm64/include/asm/kvm_hyp.h3
-rw-r--r--arch/arm64/include/asm/kvm_mmu.h13
-rw-r--r--arch/arm64/include/asm/sysreg.h7
-rw-r--r--arch/arm64/include/uapi/asm/Kbuild1
-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/arm64/kvm/Makefile4
-rw-r--r--arch/arm64/kvm/debug.c2
-rw-r--r--arch/arm64/kvm/hyp.S3
-rw-r--r--arch/arm64/kvm/hyp/hyp-entry.S12
-rw-r--r--arch/arm64/kvm/hyp/sysreg-sr.c1
-rw-r--r--arch/arm64/kvm/sys_regs.c168
-rw-r--r--arch/c6x/include/uapi/asm/Kbuild2
-rw-r--r--arch/csky/include/uapi/asm/Kbuild2
-rw-r--r--arch/h8300/Makefile2
-rw-r--r--arch/h8300/include/asm/Kbuild1
-rw-r--r--arch/h8300/include/uapi/asm/Kbuild2
-rw-r--r--arch/hexagon/include/uapi/asm/Kbuild2
-rw-r--r--arch/ia64/hp/sim/simscsi.c7
-rw-r--r--arch/ia64/include/uapi/asm/Kbuild3
-rw-r--r--arch/ia64/sn/kernel/Makefile2
-rw-r--r--arch/ia64/sn/kernel/sn2/Makefile2
-rw-r--r--arch/ia64/sn/pci/Makefile2
-rw-r--r--arch/ia64/sn/pci/pcibr/Makefile2
-rw-r--r--arch/m68k/include/uapi/asm/Kbuild2
-rw-r--r--arch/microblaze/include/uapi/asm/Kbuild2
-rw-r--r--arch/mips/bcm47xx/workarounds.c1
-rw-r--r--arch/mips/include/asm/jump_label.h8
-rw-r--r--arch/mips/include/asm/kvm_host.h2
-rw-r--r--arch/mips/include/uapi/asm/Kbuild2
-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/nds32/include/uapi/asm/Kbuild2
-rw-r--r--arch/nios2/include/uapi/asm/Kbuild2
-rw-r--r--arch/openrisc/include/asm/Kbuild2
-rw-r--r--arch/openrisc/include/uapi/asm/Kbuild2
-rw-r--r--arch/parisc/include/asm/Kbuild2
-rw-r--r--arch/parisc/include/uapi/asm/Kbuild2
-rw-r--r--arch/powerpc/configs/skiroot_defconfig12
-rw-r--r--arch/powerpc/include/asm/Kbuild1
-rw-r--r--arch/powerpc/include/asm/book3s/64/hugetlb.h8
-rw-r--r--arch/powerpc/include/asm/kvm_host.h5
-rw-r--r--arch/powerpc/include/asm/kvm_ppc.h14
-rw-r--r--arch/powerpc/include/asm/mmu.h2
-rw-r--r--arch/powerpc/include/asm/vdso_datapage.h8
-rw-r--r--arch/powerpc/include/uapi/asm/Kbuild2
-rw-r--r--arch/powerpc/include/uapi/asm/kvm.h2
-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/head_fsl_booke.S7
-rw-r--r--arch/powerpc/kernel/security.c23
-rw-r--r--arch/powerpc/kernel/traps.c1
-rw-r--r--arch/powerpc/kernel/vdso64/gettimeofday.S4
-rw-r--r--arch/powerpc/kvm/book3s.c13
-rw-r--r--arch/powerpc/kvm/book3s_32_mmu.c1
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu.c14
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_hv.c18
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_radix.c15
-rw-r--r--arch/powerpc/kvm/book3s_64_vio.c8
-rw-r--r--arch/powerpc/kvm/book3s_emulate.c18
-rw-r--r--arch/powerpc/kvm/book3s_hv.c33
-rw-r--r--arch/powerpc/kvm/book3s_hv_builtin.c14
-rw-r--r--arch/powerpc/kvm/book3s_hv_rm_xics.c7
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S10
-rw-r--r--arch/powerpc/kvm/book3s_rtas.c8
-rw-r--r--arch/powerpc/kvm/powerpc.c22
-rw-r--r--arch/powerpc/mm/Makefile3
-rw-r--r--arch/powerpc/mm/hash_low_32.S8
-rw-r--r--arch/powerpc/platforms/powernv/opal-call.c1
-rw-r--r--arch/powerpc/platforms/pseries/papr_scm.c1
-rw-r--r--arch/riscv/include/uapi/asm/Kbuild1
-rw-r--r--arch/s390/boot/Makefile3
-rw-r--r--arch/s390/include/asm/Kbuild1
-rw-r--r--arch/s390/include/asm/cio.h1
-rw-r--r--arch/s390/include/asm/irq.h1
-rw-r--r--arch/s390/include/asm/isc.h1
-rw-r--r--arch/s390/include/asm/kvm_host.h39
-rw-r--r--arch/s390/include/uapi/asm/Kbuild2
-rw-r--r--arch/s390/kernel/irq.c1
-rw-r--r--arch/s390/kvm/interrupt.c431
-rw-r--r--arch/s390/kvm/kvm-s390.c190
-rw-r--r--arch/s390/kvm/kvm-s390.h4
-rw-r--r--arch/sh/include/uapi/asm/Kbuild1
-rw-r--r--arch/sparc/include/uapi/asm/Kbuild2
-rw-r--r--arch/um/drivers/ubd_kern.c6
-rw-r--r--arch/um/drivers/vector_user.c3
-rw-r--r--arch/unicore32/boot/compressed/Makefile5
-rw-r--r--arch/unicore32/boot/compressed/vmlinux.lds.S (renamed from arch/unicore32/boot/compressed/vmlinux.lds.in)0
-rw-r--r--arch/unicore32/include/uapi/asm/Kbuild2
-rw-r--r--arch/x86/boot/string.c3
-rw-r--r--arch/x86/entry/syscalls/syscall_32.tbl1
-rw-r--r--arch/x86/entry/syscalls/syscall_64.tbl1
-rw-r--r--arch/x86/events/intel/core.c4
-rw-r--r--arch/x86/events/perf_event.h4
-rw-r--r--arch/x86/hyperv/hv_init.c6
-rw-r--r--arch/x86/include/asm/bitops.h6
-rw-r--r--arch/x86/include/asm/cpu_device_id.h31
-rw-r--r--arch/x86/include/asm/kvm_host.h42
-rw-r--r--arch/x86/include/asm/kvm_vcpu_regs.h25
-rw-r--r--arch/x86/include/asm/processor-cyrix.h21
-rw-r--r--arch/x86/include/asm/string_32.h104
-rw-r--r--arch/x86/include/asm/string_64.h15
-rw-r--r--arch/x86/include/uapi/asm/Kbuild3
-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/kvmclock.c20
-rw-r--r--arch/x86/kernel/mpparse.c4
-rw-r--r--arch/x86/kvm/cpuid.c2
-rw-r--r--arch/x86/kvm/hyperv.c2
-rw-r--r--arch/x86/kvm/i8254.c2
-rw-r--r--arch/x86/kvm/i8259.c2
-rw-r--r--arch/x86/kvm/ioapic.c2
-rw-r--r--arch/x86/kvm/lapic.c7
-rw-r--r--arch/x86/kvm/mmu.c466
-rw-r--r--arch/x86/kvm/mmu.h1
-rw-r--r--arch/x86/kvm/mmutrace.h42
-rw-r--r--arch/x86/kvm/page_track.c2
-rw-r--r--arch/x86/kvm/svm.c120
-rw-r--r--arch/x86/kvm/vmx/nested.c129
-rw-r--r--arch/x86/kvm/vmx/vmcs.h1
-rw-r--r--arch/x86/kvm/vmx/vmenter.S167
-rw-r--r--arch/x86/kvm/vmx/vmx.c188
-rw-r--r--arch/x86/kvm/vmx/vmx.h20
-rw-r--r--arch/x86/kvm/x86.c32
-rw-r--r--arch/x86/kvm/x86.h7
-rw-r--r--arch/x86/lib/csum-partial_64.c2
-rw-r--r--arch/x86/mm/pti.c4
-rw-r--r--arch/xtensa/include/asm/Kbuild1
-rw-r--r--arch/xtensa/include/uapi/asm/Kbuild3
-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-merge.c15
-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/nfit/core.c8
-rw-r--r--drivers/acpi/numa.c1
-rw-r--r--drivers/acpi/utils.c1
-rw-r--r--drivers/amba/bus.c45
-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/memory.c1
-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/block/xen-blkback/xenbus.c99
-rw-r--r--drivers/clocksource/arm_arch_timer.c11
-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/dax/Kconfig28
-rw-r--r--drivers/dax/Makefile6
-rw-r--r--drivers/dax/bus.c503
-rw-r--r--drivers/dax/bus.h61
-rw-r--r--drivers/dax/dax-private.h34
-rw-r--r--drivers/dax/dax.h18
-rw-r--r--drivers/dax/device-dax.h25
-rw-r--r--drivers/dax/device.c363
-rw-r--r--drivers/dax/kmem.c108
-rw-r--r--drivers/dax/pmem.c153
-rw-r--r--drivers/dax/pmem/Makefile7
-rw-r--r--drivers/dax/pmem/compat.c73
-rw-r--r--drivers/dax/pmem/core.c71
-rw-r--r--drivers/dax/pmem/pmem.c40
-rw-r--r--drivers/dax/super.c41
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c13
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/psp_v3_1.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/soc15.c1
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c52
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c43
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/calcs/dcn_calcs.c8
-rw-r--r--drivers/gpu/drm/amd/display/dc/core/dc_link.c16
-rw-r--r--drivers/gpu/drm/amd/display/modules/freesync/freesync.c7
-rw-r--r--drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h2
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c3
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c30
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h4
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c6
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c8
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c4
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c222
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h7
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c17
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c2
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/smu9_smumgr.c6
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c6
-rw-r--r--drivers/gpu/drm/drm_atomic_helper.c59
-rw-r--r--drivers/gpu/drm/drm_ioc32.c6
-rw-r--r--drivers/gpu/drm/etnaviv/Kconfig1
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h2
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_dump.c2
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_gem.h1
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c2
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c2
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c4
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_perfmon.c6
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_sched.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_mixer.c110
-rw-r--r--drivers/gpu/drm/i915/i915_active.c36
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c35
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c18
-rw-r--r--drivers/gpu/drm/i915/i915_gpu_error.c2
-rw-r--r--drivers/gpu/drm/i915/i915_scheduler.c27
-rw-r--r--drivers/gpu/drm/i915/intel_bios.c1
-rw-r--r--drivers/gpu/drm/i915/intel_breadcrumbs.c18
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c14
-rw-r--r--drivers/gpu/drm/i915/selftests/i915_gem_context.c69
-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/qxl/qxl_drv.c5
-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/gpu/vga/vgaarb.c49
-rw-r--r--drivers/hwtracing/coresight/coresight-etm3x.c44
-rw-r--r--drivers/hwtracing/coresight/coresight-etm4x.c21
-rw-r--r--drivers/hwtracing/coresight/coresight-priv.h40
-rw-r--r--drivers/hwtracing/coresight/coresight-stm.c14
-rw-r--r--drivers/hwtracing/coresight/coresight-tmc.c30
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c7
-rw-r--r--drivers/i2c/busses/i2c-mt65xx.c8
-rw-r--r--drivers/i2c/busses/i2c-rcar.c15
-rw-r--r--drivers/i2c/busses/i2c-sis630.c4
-rw-r--r--drivers/i2c/busses/i2c-stm32f7.c2
-rw-r--r--drivers/i2c/i2c-core-base.c9
-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.c15
-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/lightnvm/pblk-rl.c7
-rw-r--r--drivers/md/raid10.c3
-rw-r--r--drivers/md/raid5-log.h1
-rw-r--r--drivers/md/raid5-ppl.c63
-rw-r--r--drivers/md/raid5.c3
-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/ntb/hw/intel/ntb_hw_gen1.c25
-rw-r--r--drivers/ntb/hw/intel/ntb_hw_gen1.h5
-rw-r--r--drivers/ntb/hw/intel/ntb_hw_gen3.c33
-rw-r--r--drivers/ntb/hw/mscc/ntb_hw_switchtec.c20
-rw-r--r--drivers/ntb/ntb_transport.c31
-rw-r--r--drivers/nvdimm/e820.c1
-rw-r--r--drivers/nvdimm/nd.h2
-rw-r--r--drivers/nvdimm/of_pmem.c1
-rw-r--r--drivers/nvdimm/region_devs.c1
-rw-r--r--drivers/nvme/host/core.c28
-rw-r--r--drivers/nvme/host/fc.c36
-rw-r--r--drivers/nvme/host/nvme.h5
-rw-r--r--drivers/nvme/host/pci.c3
-rw-r--r--drivers/nvme/host/tcp.c32
-rw-r--r--drivers/nvme/host/trace.c14
-rw-r--r--drivers/nvme/host/trace.h2
-rw-r--r--drivers/nvme/target/core.c20
-rw-r--r--drivers/nvme/target/fc.c42
-rw-r--r--drivers/nvme/target/io-cmd-bdev.c8
-rw-r--r--drivers/nvme/target/io-cmd-file.c2
-rw-r--r--drivers/parport/daisy.c32
-rw-r--r--drivers/parport/probe.c2
-rw-r--r--drivers/parport/share.c10
-rw-r--r--drivers/platform/chrome/cros_ec_debugfs.c10
-rw-r--r--drivers/platform/chrome/wilco_ec/mailbox.c2
-rw-r--r--drivers/s390/cio/chsc.c37
-rw-r--r--drivers/s390/cio/chsc.h1
-rw-r--r--drivers/scsi/aacraid/linit.c13
-rw-r--r--drivers/scsi/hisi_sas/hisi_sas.h8
-rw-r--r--drivers/scsi/hisi_sas/hisi_sas_main.c63
-rw-r--r--drivers/scsi/hisi_sas/hisi_sas_v2_hw.c1
-rw-r--r--drivers/scsi/hisi_sas/hisi_sas_v3_hw.c89
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c23
-rw-r--r--drivers/scsi/libiscsi.c22
-rw-r--r--drivers/scsi/libiscsi_tcp.c11
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c21
-rw-r--r--drivers/scsi/lpfc/lpfc_nvme.c3
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c4
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_dfs.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c7
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c4
-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/scsi/smartpqi/smartpqi_init.c6
-rw-r--r--drivers/scsi/ufs/ufs-hisi.c11
-rw-r--r--drivers/scsi/ufs/ufshcd-pltfrm.c2
-rw-r--r--drivers/scsi/ufs/ufshcd-pltfrm.h2
-rw-r--r--drivers/scsi/ufs/ufshcd.h2
-rw-r--r--drivers/scsi/virtio_scsi.c2
-rw-r--r--drivers/target/target_core_user.c19
-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--drivers/video/fbdev/aty/radeon_pm.c6
-rw-r--r--drivers/video/fbdev/cg14.c4
-rw-r--r--drivers/video/fbdev/cg3.c2
-rw-r--r--drivers/video/fbdev/chipsfb.c3
-rw-r--r--drivers/video/fbdev/core/fb_cmdline.c23
-rw-r--r--drivers/video/fbdev/core/fbcon.c14
-rw-r--r--drivers/video/fbdev/core/fbmem.c3
-rw-r--r--drivers/video/fbdev/core/fbmon.c2
-rw-r--r--drivers/video/fbdev/ffb.c2
-rw-r--r--drivers/video/fbdev/geode/gxfb_core.c13
-rw-r--r--drivers/video/fbdev/geode/lxfb_core.c13
-rw-r--r--drivers/video/fbdev/imsttfb.c4
-rw-r--r--drivers/video/fbdev/mbx/mbxdebugfs.c40
-rw-r--r--drivers/video/fbdev/mbx/mbxfb.c2
-rw-r--r--drivers/video/fbdev/offb.c4
-rw-r--r--drivers/video/fbdev/omap2/omapfb/dss/core.c34
-rw-r--r--drivers/video/fbdev/omap2/omapfb/dss/dss-of.c4
-rw-r--r--drivers/video/fbdev/omap2/omapfb/dss/dss.h2
-rw-r--r--drivers/video/fbdev/omap2/omapfb/dss/hdmi4_core.c2
-rw-r--r--drivers/video/fbdev/ssd1307fb.c4
-rw-r--r--drivers/video/fbdev/via/viafbdev.c2
-rw-r--r--drivers/xen/balloon.c5
-rw-r--r--fs/9p/v9fs_vfs.h23
-rw-r--r--fs/9p/vfs_file.c6
-rw-r--r--fs/9p/vfs_inode.c23
-rw-r--r--fs/9p/vfs_inode_dotl.c27
-rw-r--r--fs/9p/vfs_super.c4
-rw-r--r--fs/block_dev.c12
-rw-r--r--fs/btrfs/extent-tree.c2
-rw-r--r--fs/btrfs/qgroup.c4
-rw-r--r--fs/btrfs/raid56.c3
-rw-r--r--fs/btrfs/transaction.c49
-rw-r--r--fs/btrfs/tree-log.c33
-rw-r--r--fs/btrfs/volumes.c2
-rw-r--r--fs/cifs/cifs_debug.c11
-rw-r--r--fs/cifs/cifs_ioctl.h3
-rw-r--r--fs/cifs/cifsfs.c2
-rw-r--r--fs/cifs/cifsfs.h2
-rw-r--r--fs/cifs/cifsglob.h16
-rw-r--r--fs/cifs/connect.c4
-rw-r--r--fs/cifs/dir.c107
-rw-r--r--fs/cifs/file.c162
-rw-r--r--fs/cifs/smb1ops.c126
-rw-r--r--fs/cifs/smb2inode.c87
-rw-r--r--fs/cifs/smb2maperror.c3
-rw-r--r--fs/cifs/smb2ops.c423
-rw-r--r--fs/cifs/smb2pdu.c156
-rw-r--r--fs/cifs/smb2pdu.h7
-rw-r--r--fs/cifs/smb2proto.h7
-rw-r--r--fs/cifs/smb2status.h6
-rw-r--r--fs/cifs/trace.h130
-rw-r--r--fs/cifs/transport.c226
-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/f2fs/checkpoint.c20
-rw-r--r--fs/f2fs/data.c59
-rw-r--r--fs/f2fs/debug.c19
-rw-r--r--fs/f2fs/dir.c15
-rw-r--r--fs/f2fs/extent_cache.c2
-rw-r--r--fs/f2fs/f2fs.h77
-rw-r--r--fs/f2fs/file.c46
-rw-r--r--fs/f2fs/inline.c12
-rw-r--r--fs/f2fs/inode.c15
-rw-r--r--fs/f2fs/namei.c3
-rw-r--r--fs/f2fs/node.c6
-rw-r--r--fs/f2fs/segment.c80
-rw-r--r--fs/f2fs/segment.h2
-rw-r--r--fs/f2fs/super.c109
-rw-r--r--fs/f2fs/sysfs.c17
-rw-r--r--fs/f2fs/trace.c20
-rw-r--r--fs/f2fs/xattr.c25
-rw-r--r--fs/f2fs/xattr.h6
-rw-r--r--fs/io_uring.c439
-rw-r--r--fs/iomap.c12
-rw-r--r--fs/lockd/host.c3
-rw-r--r--fs/locks.c5
-rw-r--r--fs/nfs/client.c2
-rw-r--r--fs/nfs/flexfilelayout/flexfilelayout.c5
-rw-r--r--fs/nfs/nfs4proc.c5
-rw-r--r--fs/nfs/pnfs.c2
-rw-r--r--fs/notify/fanotify/fanotify_user.c12
-rw-r--r--fs/notify/inotify/inotify_user.c7
-rw-r--r--fs/proc/base.c9
-rw-r--r--fs/proc/kcore.c27
-rw-r--r--fs/sysfs/mount.c8
-rw-r--r--fs/udf/inode.c4
-rw-r--r--fs/udf/truncate.c8
-rw-r--r--fs/udf/udfdecl.h2
-rw-r--r--fs/xfs/libxfs/xfs_dir2_leaf.c37
-rw-r--r--fs/xfs/libxfs/xfs_dir2_node.c18
-rw-r--r--include/asm-generic/Kbuild5
-rw-r--r--include/clocksource/arm_arch_timer.h1
-rw-r--r--include/drm/drm_fb_helper.h14
-rw-r--r--include/kvm/arm_arch_timer.h68
-rw-r--r--include/linux/acpi.h5
-rw-r--r--include/linux/amba/bus.h39
-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/f2fs_fs.h20
-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/kvm_host.h24
-rw-r--r--include/linux/libnvdimm.h1
-rw-r--r--include/linux/mlx5/qp.h3
-rw-r--r--include/linux/ntb.h10
-rw-r--r--include/linux/pagemap.h1
-rw-r--r--include/linux/parport.h13
-rw-r--r--include/linux/proc_fs.h6
-rw-r--r--include/linux/ring_buffer.h2
-rw-r--r--include/linux/sbitmap.h2
-rw-r--r--include/linux/switchtec.h10
-rw-r--r--include/linux/syscalls.h3
-rw-r--r--include/linux/uio.h24
-rw-r--r--include/linux/vgaarb.h2
-rw-r--r--include/misc/charlcd.h1
-rw-r--r--include/sound/pcm.h2
-rw-r--r--include/trace/events/f2fs.h47
-rw-r--r--include/trace/events/sunrpc.h6
-rw-r--r--include/uapi/asm-generic/Kbuild (renamed from include/uapi/asm-generic/Kbuild.asm)4
-rw-r--r--include/uapi/asm-generic/unistd.h2
-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/printk/printk.c1
-rw-r--r--kernel/resource.c18
-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/signal.c133
-rw-r--r--kernel/sys_ni.c1
-rw-r--r--kernel/time/jiffies.c2
-rw-r--r--kernel/trace/blktrace.c1
-rw-r--r--kernel/trace/ftrace.c12
-rw-r--r--kernel/trace/ring_buffer.c5
-rw-r--r--kernel/trace/trace.c6
-rw-r--r--kernel/trace/trace_dynevent.c2
-rw-r--r--kernel/trace/trace_events_hist.c1
-rw-r--r--kernel/trace/trace_kdb.c6
-rw-r--r--kernel/trace/trace_kprobe.c23
-rw-r--r--kernel/trace/trace_probe.c20
-rw-r--r--kernel/trace/trace_probe.h1
-rw-r--r--kernel/trace/trace_uprobe.c8
-rw-r--r--kernel/watchdog.c4
-rw-r--r--kernel/workqueue.c5
-rw-r--r--lib/Makefile2
-rw-r--r--lib/raid6/Makefile2
-rw-r--r--mm/filemap.c202
-rw-r--r--mm/memory_hotplug.c32
-rw-r--r--net/9p/client.c2
-rw-r--r--net/9p/trans_xen.c2
-rw-r--r--net/ceph/ceph_common.c18
-rw-r--r--net/ceph/mon_client.c9
-rw-r--r--net/sunrpc/clnt.c44
-rw-r--r--net/sunrpc/xprt.c2
-rw-r--r--net/sunrpc/xprtsock.c6
-rw-r--r--scripts/Makefile.asm-generic11
-rw-r--r--scripts/Makefile.build6
-rw-r--r--scripts/Makefile.lib6
-rw-r--r--scripts/Makefile.modinst2
-rw-r--r--scripts/Makefile.modpost1
-rwxr-xr-xscripts/adjust_autoksyms.sh9
-rw-r--r--scripts/coccinelle/free/put_device.cocci56
-rw-r--r--scripts/kconfig/lxdialog/.gitignore4
-rwxr-xr-xscripts/link-vmlinux.sh9
-rw-r--r--scripts/mod/modpost.c27
-rwxr-xr-xscripts/package/builddeb32
-rwxr-xr-xscripts/package/buildtar2
-rwxr-xr-xscripts/package/mkdebian39
-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/hda/hdac_stream.c5
-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/hda_tegra.c12
-rw-r--r--sound/pci/hda/patch_conexant.c3
-rw-r--r--sound/pci/hda/patch_hdmi.c67
-rw-r--r--sound/pci/hda/patch_realtek.c82
-rw-r--r--sound/usb/usx2y/usb_stream.c5
-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
-rw-r--r--tools/testing/nvdimm/Kbuild7
-rw-r--r--tools/testing/nvdimm/dax-dev.c16
-rw-r--r--tools/testing/selftests/Makefile1
-rw-r--r--tools/testing/selftests/kvm/.gitignore1
-rw-r--r--tools/testing/selftests/kvm/Makefile1
-rw-r--r--tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c95
-rw-r--r--tools/testing/selftests/pidfd/Makefile6
-rw-r--r--tools/testing/selftests/pidfd/pidfd_test.c381
-rw-r--r--virt/kvm/arm/arch_timer.c608
-rw-r--r--virt/kvm/arm/arm.c64
-rw-r--r--virt/kvm/arm/hyp/vgic-v3-sr.c2
-rw-r--r--virt/kvm/arm/mmu.c20
-rw-r--r--virt/kvm/arm/trace.h107
-rw-r--r--virt/kvm/arm/vgic/vgic-v3.c4
-rw-r--r--virt/kvm/coalesced_mmio.c3
-rw-r--r--virt/kvm/eventfd.c7
-rw-r--r--virt/kvm/irqchip.c4
-rw-r--r--virt/kvm/kvm_main.c103
-rw-r--r--virt/kvm/vfio.c4
799 files changed, 13402 insertions, 6842 deletions
diff --git a/Documentation/ABI/obsolete/sysfs-class-dax b/Documentation/ABI/obsolete/sysfs-class-dax
new file mode 100644
index 000000000000..2cb9fc5e8bd1
--- /dev/null
+++ b/Documentation/ABI/obsolete/sysfs-class-dax
@@ -0,0 +1,22 @@
1What: /sys/class/dax/
2Date: May, 2016
3KernelVersion: v4.7
4Contact: linux-nvdimm@lists.01.org
5Description: Device DAX is the device-centric analogue of Filesystem
6 DAX (CONFIG_FS_DAX). It allows memory ranges to be
7 allocated and mapped without need of an intervening file
8 system. Device DAX is strict, precise and predictable.
9 Specifically this interface:
10
11 1/ Guarantees fault granularity with respect to a given
12 page size (pte, pmd, or pud) set at configuration time.
13
14 2/ Enforces deterministic behavior by being strict about
15 what fault scenarios are supported.
16
17 The /sys/class/dax/ interface enumerates all the
18 device-dax instances in the system. The ABI is
19 deprecated and will be removed after 2020. It is
20 replaced with the DAX bus interface /sys/bus/dax/ where
21 device-dax instances can be found under
22 /sys/bus/dax/devices/
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index a7ce33199457..91822ce25831 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -86,6 +86,13 @@ Description:
86 The unit size is one block, now only support configuring in range 86 The unit size is one block, now only support configuring in range
87 of [1, 512]. 87 of [1, 512].
88 88
89What: /sys/fs/f2fs/<disk>/umount_discard_timeout
90Date: January 2019
91Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
92Description:
93 Set timeout to issue discard commands during umount.
94 Default: 5 secs
95
89What: /sys/fs/f2fs/<disk>/max_victim_search 96What: /sys/fs/f2fs/<disk>/max_victim_search
90Date: January 2014 97Date: January 2014
91Contact: "Jaegeuk Kim" <jaegeuk.kim@samsung.com> 98Contact: "Jaegeuk Kim" <jaegeuk.kim@samsung.com>
diff --git a/Documentation/admin-guide/md.rst b/Documentation/admin-guide/md.rst
index 84de718f24a4..3c51084ffd37 100644
--- a/Documentation/admin-guide/md.rst
+++ b/Documentation/admin-guide/md.rst
@@ -756,3 +756,6 @@ These currently include:
756 The cache mode for raid5. raid5 could include an extra disk for 756 The cache mode for raid5. raid5 could include an extra disk for
757 caching. The mode can be "write-throuth" and "write-back". The 757 caching. The mode can be "write-throuth" and "write-back". The
758 default is "write-through". 758 default is "write-through".
759
760 ppl_write_hint
761 NVMe stream ID to be set for each PPL write request.
diff --git a/Documentation/arm/kernel_mode_neon.txt b/Documentation/arm/kernel_mode_neon.txt
index 525452726d31..b9e060c5b61e 100644
--- a/Documentation/arm/kernel_mode_neon.txt
+++ b/Documentation/arm/kernel_mode_neon.txt
@@ -6,7 +6,7 @@ TL;DR summary
6* Use only NEON instructions, or VFP instructions that don't rely on support 6* Use only NEON instructions, or VFP instructions that don't rely on support
7 code 7 code
8* Isolate your NEON code in a separate compilation unit, and compile it with 8* Isolate your NEON code in a separate compilation unit, and compile it with
9 '-mfpu=neon -mfloat-abi=softfp' 9 '-march=armv7-a -mfpu=neon -mfloat-abi=softfp'
10* Put kernel_neon_begin() and kernel_neon_end() calls around the calls into your 10* Put kernel_neon_begin() and kernel_neon_end() calls around the calls into your
11 NEON code 11 NEON code
12* Don't sleep in your NEON code, and be aware that it will be executed with 12* Don't sleep in your NEON code, and be aware that it will be executed with
@@ -87,7 +87,7 @@ instructions appearing in unexpected places if no special care is taken.
87Therefore, the recommended and only supported way of using NEON/VFP in the 87Therefore, the recommended and only supported way of using NEON/VFP in the
88kernel is by adhering to the following rules: 88kernel is by adhering to the following rules:
89* isolate the NEON code in a separate compilation unit and compile it with 89* isolate the NEON code in a separate compilation unit and compile it with
90 '-mfpu=neon -mfloat-abi=softfp'; 90 '-march=armv7-a -mfpu=neon -mfloat-abi=softfp';
91* issue the calls to kernel_neon_begin(), kernel_neon_end() as well as the calls 91* issue the calls to kernel_neon_begin(), kernel_neon_end() as well as the calls
92 into the unit containing the NEON code from a compilation unit which is *not* 92 into the unit containing the NEON code from a compilation unit which is *not*
93 built with the GCC flag '-mfpu=neon' set. 93 built with the GCC flag '-mfpu=neon' set.
diff --git a/Documentation/devicetree/bindings/display/ssd1307fb.txt b/Documentation/devicetree/bindings/display/ssd1307fb.txt
index 209d931ef16c..b67f8caa212c 100644
--- a/Documentation/devicetree/bindings/display/ssd1307fb.txt
+++ b/Documentation/devicetree/bindings/display/ssd1307fb.txt
@@ -36,7 +36,6 @@ ssd1307: oled@3c {
36 reg = <0x3c>; 36 reg = <0x3c>;
37 pwms = <&pwm 4 3000>; 37 pwms = <&pwm 4 3000>;
38 reset-gpios = <&gpio2 7>; 38 reset-gpios = <&gpio2 7>;
39 reset-active-low;
40}; 39};
41 40
42ssd1306: oled@3c { 41ssd1306: oled@3c {
@@ -44,7 +43,6 @@ ssd1306: oled@3c {
44 reg = <0x3c>; 43 reg = <0x3c>;
45 pwms = <&pwm 4 3000>; 44 pwms = <&pwm 4 3000>;
46 reset-gpios = <&gpio2 7>; 45 reset-gpios = <&gpio2 7>;
47 reset-active-low;
48 solomon,com-lrremap; 46 solomon,com-lrremap;
49 solomon,com-invdir; 47 solomon,com-invdir;
50 solomon,com-offset = <32>; 48 solomon,com-offset = <32>;
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/Documentation/filesystems/cifs/TODO b/Documentation/filesystems/cifs/TODO
index 66b3f54aa6dc..9267f3fb131f 100644
--- a/Documentation/filesystems/cifs/TODO
+++ b/Documentation/filesystems/cifs/TODO
@@ -111,7 +111,8 @@ negotiated size) and send larger write sizes to modern servers.
111 111
1125) Continue to extend the smb3 "buildbot" which does automated xfstesting 1125) Continue to extend the smb3 "buildbot" which does automated xfstesting
113against Windows, Samba and Azure currently - to add additional tests and 113against Windows, Samba and Azure currently - to add additional tests and
114to allow the buildbot to execute the tests faster. 114to allow the buildbot to execute the tests faster. The URL for the
115buildbot is: http://smb3-test-rhel-75.southcentralus.cloudapp.azure.com
115 116
1166) Address various coverity warnings (most are not bugs per-se, but 1176) Address various coverity warnings (most are not bugs per-se, but
117the more warnings are addressed, the easier it is to spot real 118the more warnings are addressed, the easier it is to spot real
diff --git a/Documentation/filesystems/cifs/cifs.txt b/Documentation/filesystems/cifs/cifs.txt
index 67756607246e..1be3d21c286e 100644
--- a/Documentation/filesystems/cifs/cifs.txt
+++ b/Documentation/filesystems/cifs/cifs.txt
@@ -1,16 +1,21 @@
1 This is the client VFS module for the SMB3 NAS protocol as well 1 This is the client VFS module for the SMB3 NAS protocol as well
2 older dialects such as the Common Internet File System (CIFS) 2 as for older dialects such as the Common Internet File System (CIFS)
3 protocol which was the successor to the Server Message Block 3 protocol which was the successor to the Server Message Block
4 (SMB) protocol, the native file sharing mechanism for most early 4 (SMB) protocol, the native file sharing mechanism for most early
5 PC operating systems. New and improved versions of CIFS are now 5 PC operating systems. New and improved versions of CIFS are now
6 called SMB2 and SMB3. These dialects are also supported by the 6 called SMB2 and SMB3. Use of SMB3 (and later, including SMB3.1.1)
7 CIFS VFS module. CIFS is fully supported by network 7 is strongly preferred over using older dialects like CIFS due to
8 file servers such as Windows 2000, 2003, 2008, 2012 and 2016 8 security reaasons. All modern dialects, including the most recent,
9 as well by Samba (which provides excellent CIFS 9 SMB3.1.1 are supported by the CIFS VFS module. The SMB3 protocol
10 server support for Linux and many other operating systems), Apple 10 is implemented and supported by all major file servers
11 systems, as well as most Network Attached Storage vendors, so 11 such as all modern versions of Windows (including Windows 2016
12 this network filesystem client can mount to a wide variety of 12 Server), as well as by Samba (which provides excellent
13 servers. 13 CIFS/SMB2/SMB3 server support and tools for Linux and many other
14 operating systems). Apple systems also support SMB3 well, as
15 do most Network Attached Storage vendors, so this network
16 filesystem client can mount to a wide variety of systems.
17 It also supports mounting to the cloud (for example
18 Microsoft Azure), including the necessary security features.
14 19
15 The intent of this module is to provide the most advanced network 20 The intent of this module is to provide the most advanced network
16 file system function for SMB3 compliant servers, including advanced 21 file system function for SMB3 compliant servers, including advanced
@@ -24,12 +29,17 @@
24 cluster file systems for fileserving in some Linux to Linux environments, 29 cluster file systems for fileserving in some Linux to Linux environments,
25 not just in Linux to Windows (or Linux to Mac) environments. 30 not just in Linux to Windows (or Linux to Mac) environments.
26 31
27 This filesystem has an mount utility (mount.cifs) that can be obtained from 32 This filesystem has a mount utility (mount.cifs) and various user space
33 tools (including smbinfo and setcifsacl) that can be obtained from
28 34
29 https://ftp.samba.org/pub/linux-cifs/cifs-utils/ 35 https://git.samba.org/?p=cifs-utils.git
36 or
37 git://git.samba.org/cifs-utils.git
30 38
31 It must be installed in the directory with the other mount helpers. 39 mount.cifs should be installed in the directory with the other mount helpers.
32 40
33 For more information on the module see the project wiki page at 41 For more information on the module see the project wiki page at
34 42
43 https://wiki.samba.org/index.php/LinuxCIFS
44 and
35 https://wiki.samba.org/index.php/LinuxCIFS_utils 45 https://wiki.samba.org/index.php/LinuxCIFS_utils
diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
index e46c2147ddf8..f7b5e4ff0de3 100644
--- a/Documentation/filesystems/f2fs.txt
+++ b/Documentation/filesystems/f2fs.txt
@@ -126,6 +126,8 @@ disable_ext_identify Disable the extension list configured by mkfs, so f2fs
126 does not aware of cold files such as media files. 126 does not aware of cold files such as media files.
127inline_xattr Enable the inline xattrs feature. 127inline_xattr Enable the inline xattrs feature.
128noinline_xattr Disable the inline xattrs feature. 128noinline_xattr Disable the inline xattrs feature.
129inline_xattr_size=%u Support configuring inline xattr size, it depends on
130 flexible inline xattr feature.
129inline_data Enable the inline data feature: New created small(<~3.4k) 131inline_data Enable the inline data feature: New created small(<~3.4k)
130 files can be written into inode block. 132 files can be written into inode block.
131inline_dentry Enable the inline dir feature: data in new created 133inline_dentry Enable the inline dir feature: data in new created
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index f124be6e4c3a..03c065855eaf 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1274,7 +1274,7 @@ See subsequent chapter for the syntax of the Kbuild file.
1274 1274
1275--- 7.4 mandatory-y 1275--- 7.4 mandatory-y
1276 1276
1277 mandatory-y is essentially used by include/(uapi/)asm-generic/Kbuild.asm 1277 mandatory-y is essentially used by include/(uapi/)asm-generic/Kbuild
1278 to define the minimum set of ASM headers that all architectures must have. 1278 to define the minimum set of ASM headers that all architectures must have.
1279 1279
1280 This works like optional generic-y. If a mandatory header is missing 1280 This works like optional generic-y. If a mandatory header is missing
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 356156f5c52d..7de9eee73fcd 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -45,6 +45,23 @@ the API. The only supported use is one virtual machine per process,
45and one vcpu per thread. 45and one vcpu per thread.
46 46
47 47
48It is important to note that althought VM ioctls may only be issued from
49the process that created the VM, a VM's lifecycle is associated with its
50file descriptor, not its creator (process). In other words, the VM and
51its resources, *including the associated address space*, are not freed
52until the last reference to the VM's file descriptor has been released.
53For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
54not be freed until both the parent (original) process and its child have
55put their references to the VM's file descriptor.
56
57Because a VM's resources are not freed until the last reference to its
58file descriptor is released, creating additional references to a VM via
59via fork(), dup(), etc... without careful consideration is strongly
60discouraged and may have unwanted side effects, e.g. memory allocated
61by and on behalf of the VM's process may not be freed/unaccounted when
62the VM is shut down.
63
64
483. Extensions 653. Extensions
49------------- 66-------------
50 67
diff --git a/Documentation/virtual/kvm/halt-polling.txt b/Documentation/virtual/kvm/halt-polling.txt
index 4a8418318769..4f791b128dd2 100644
--- a/Documentation/virtual/kvm/halt-polling.txt
+++ b/Documentation/virtual/kvm/halt-polling.txt
@@ -53,7 +53,8 @@ the global max polling interval then the polling interval can be increased in
53the hope that next time during the longer polling interval the wake up source 53the hope that next time during the longer polling interval the wake up source
54will be received while the host is polling and the latency benefits will be 54will be received while the host is polling and the latency benefits will be
55received. The polling interval is grown in the function grow_halt_poll_ns() and 55received. The polling interval is grown in the function grow_halt_poll_ns() and
56is multiplied by the module parameter halt_poll_ns_grow. 56is multiplied by the module parameters halt_poll_ns_grow and
57halt_poll_ns_grow_start.
57 58
58In the event that the total block time was greater than the global max polling 59In the event that the total block time was greater than the global max polling
59interval then the host will never poll for long enough (limited by the global 60interval then the host will never poll for long enough (limited by the global
@@ -80,22 +81,30 @@ shrunk. These variables are defined in include/linux/kvm_host.h and as module
80parameters in virt/kvm/kvm_main.c, or arch/powerpc/kvm/book3s_hv.c in the 81parameters in virt/kvm/kvm_main.c, or arch/powerpc/kvm/book3s_hv.c in the
81powerpc kvm-hv case. 82powerpc kvm-hv case.
82 83
83Module Parameter | Description | Default Value 84Module Parameter | Description | Default Value
84-------------------------------------------------------------------------------- 85--------------------------------------------------------------------------------
85halt_poll_ns | The global max polling interval | KVM_HALT_POLL_NS_DEFAULT 86halt_poll_ns | The global max polling | KVM_HALT_POLL_NS_DEFAULT
86 | which defines the ceiling value | 87 | interval which defines |
87 | of the polling interval for | (per arch value) 88 | the ceiling value of the |
88 | each vcpu. | 89 | polling interval for | (per arch value)
90 | each vcpu. |
89-------------------------------------------------------------------------------- 91--------------------------------------------------------------------------------
90halt_poll_ns_grow | The value by which the halt | 2 92halt_poll_ns_grow | The value by which the | 2
91 | polling interval is multiplied | 93 | halt polling interval is |
92 | in the grow_halt_poll_ns() | 94 | multiplied in the |
93 | function. | 95 | grow_halt_poll_ns() |
96 | function. |
94-------------------------------------------------------------------------------- 97--------------------------------------------------------------------------------
95halt_poll_ns_shrink | The value by which the halt | 0 98halt_poll_ns_grow_start | The initial value to grow | 10000
96 | polling interval is divided in | 99 | to from zero in the |
97 | the shrink_halt_poll_ns() | 100 | grow_halt_poll_ns() |
98 | function. | 101 | function. |
102--------------------------------------------------------------------------------
103halt_poll_ns_shrink | The value by which the | 0
104 | halt polling interval is |
105 | divided in the |
106 | shrink_halt_poll_ns() |
107 | function. |
99-------------------------------------------------------------------------------- 108--------------------------------------------------------------------------------
100 109
101These module parameters can be set from the debugfs files in: 110These module parameters can be set from the debugfs files in:
diff --git a/Documentation/virtual/kvm/mmu.txt b/Documentation/virtual/kvm/mmu.txt
index e507a9e0421e..f365102c80f5 100644
--- a/Documentation/virtual/kvm/mmu.txt
+++ b/Documentation/virtual/kvm/mmu.txt
@@ -224,10 +224,6 @@ Shadow pages contain the following information:
224 A bitmap indicating which sptes in spt point (directly or indirectly) at 224 A bitmap indicating which sptes in spt point (directly or indirectly) at
225 pages that may be unsynchronized. Used to quickly locate all unsychronized 225 pages that may be unsynchronized. Used to quickly locate all unsychronized
226 pages reachable from a given page. 226 pages reachable from a given page.
227 mmu_valid_gen:
228 Generation number of the page. It is compared with kvm->arch.mmu_valid_gen
229 during hash table lookup, and used to skip invalidated shadow pages (see
230 "Zapping all pages" below.)
231 clear_spte_count: 227 clear_spte_count:
232 Only present on 32-bit hosts, where a 64-bit spte cannot be written 228 Only present on 32-bit hosts, where a 64-bit spte cannot be written
233 atomically. The reader uses this while running out of the MMU lock 229 atomically. The reader uses this while running out of the MMU lock
@@ -402,27 +398,6 @@ causes its disallow_lpage to be incremented, thus preventing instantiation of
402a large spte. The frames at the end of an unaligned memory slot have 398a large spte. The frames at the end of an unaligned memory slot have
403artificially inflated ->disallow_lpages so they can never be instantiated. 399artificially inflated ->disallow_lpages so they can never be instantiated.
404 400
405Zapping all pages (page generation count)
406=========================================
407
408For the large memory guests, walking and zapping all pages is really slow
409(because there are a lot of pages), and also blocks memory accesses of
410all VCPUs because it needs to hold the MMU lock.
411
412To make it be more scalable, kvm maintains a global generation number
413which is stored in kvm->arch.mmu_valid_gen. Every shadow page stores
414the current global generation-number into sp->mmu_valid_gen when it
415is created. Pages with a mismatching generation number are "obsolete".
416
417When KVM need zap all shadow pages sptes, it just simply increases the global
418generation-number then reload root shadow pages on all vcpus. As the VCPUs
419create new shadow page tables, the old pages are not used because of the
420mismatching generation number.
421
422KVM then walks through all pages and zaps obsolete pages. While the zap
423operation needs to take the MMU lock, the lock can be released periodically
424so that the VCPUs can make progress.
425
426Fast invalidation of MMIO sptes 401Fast invalidation of MMIO sptes
427=============================== 402===============================
428 403
@@ -435,8 +410,7 @@ shadow pages, and is made more scalable with a similar technique.
435MMIO sptes have a few spare bits, which are used to store a 410MMIO sptes have a few spare bits, which are used to store a
436generation number. The global generation number is stored in 411generation number. The global generation number is stored in
437kvm_memslots(kvm)->generation, and increased whenever guest memory info 412kvm_memslots(kvm)->generation, and increased whenever guest memory info
438changes. This generation number is distinct from the one described in 413changes.
439the previous section.
440 414
441When KVM finds an MMIO spte, it checks the generation number of the spte. 415When KVM finds an MMIO spte, it checks the generation number of the spte.
442If the generation number of the spte does not equal the global generation 416If the generation number of the spte does not equal the global generation
@@ -452,13 +426,16 @@ stored into the MMIO spte. Thus, the MMIO spte might be created based on
452out-of-date information, but with an up-to-date generation number. 426out-of-date information, but with an up-to-date generation number.
453 427
454To avoid this, the generation number is incremented again after synchronize_srcu 428To avoid this, the generation number is incremented again after synchronize_srcu
455returns; thus, the low bit of kvm_memslots(kvm)->generation is only 1 during a 429returns; thus, bit 63 of kvm_memslots(kvm)->generation set to 1 only during a
456memslot update, while some SRCU readers might be using the old copy. We do not 430memslot update, while some SRCU readers might be using the old copy. We do not
457want to use an MMIO sptes created with an odd generation number, and we can do 431want to use an MMIO sptes created with an odd generation number, and we can do
458this without losing a bit in the MMIO spte. The low bit of the generation 432this without losing a bit in the MMIO spte. The "update in-progress" bit of the
459is not stored in MMIO spte, and presumed zero when it is extracted out of the 433generation is not stored in MMIO spte, and is so is implicitly zero when the
460spte. If KVM is unlucky and creates an MMIO spte while the low bit is 1, 434generation is extracted out of the spte. If KVM is unlucky and creates an MMIO
461the next access to the spte will always be a cache miss. 435spte while an update is in-progress, the next access to the spte will always be
436a cache miss. For example, a subsequent access during the update window will
437miss due to the in-progress flag diverging, while an access after the update
438window closes will have a higher generation number (as compared to the spte).
462 439
463 440
464Further reading 441Further reading
diff --git a/MAINTAINERS b/MAINTAINERS
index f8ff9ae52c21..3e5a5d263f29 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5278,7 +5278,7 @@ DRM DRIVERS FOR VIVANTE GPU IP
5278M: Lucas Stach <l.stach@pengutronix.de> 5278M: Lucas Stach <l.stach@pengutronix.de>
5279R: Russell King <linux+etnaviv@armlinux.org.uk> 5279R: Russell King <linux+etnaviv@armlinux.org.uk>
5280R: Christian Gmeiner <christian.gmeiner@gmail.com> 5280R: Christian Gmeiner <christian.gmeiner@gmail.com>
5281L: etnaviv@lists.freedesktop.org 5281L: etnaviv@lists.freedesktop.org (moderated for non-subscribers)
5282L: dri-devel@lists.freedesktop.org 5282L: dri-devel@lists.freedesktop.org
5283S: Maintained 5283S: Maintained
5284F: drivers/gpu/drm/etnaviv/ 5284F: drivers/gpu/drm/etnaviv/
@@ -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
@@ -8461,6 +8471,7 @@ F: include/linux/kvm*
8461F: include/kvm/iodev.h 8471F: include/kvm/iodev.h
8462F: virt/kvm/* 8472F: virt/kvm/*
8463F: tools/kvm/ 8473F: tools/kvm/
8474F: tools/testing/selftests/kvm/
8464 8475
8465KERNEL VIRTUAL MACHINE FOR AMD-V (KVM/amd) 8476KERNEL VIRTUAL MACHINE FOR AMD-V (KVM/amd)
8466M: Joerg Roedel <joro@8bytes.org> 8477M: Joerg Roedel <joro@8bytes.org>
@@ -8470,29 +8481,25 @@ S: Maintained
8470F: arch/x86/include/asm/svm.h 8481F: arch/x86/include/asm/svm.h
8471F: arch/x86/kvm/svm.c 8482F: arch/x86/kvm/svm.c
8472 8483
8473KERNEL VIRTUAL MACHINE FOR ARM (KVM/arm) 8484KERNEL VIRTUAL MACHINE FOR ARM/ARM64 (KVM/arm, KVM/arm64)
8474M: Christoffer Dall <christoffer.dall@arm.com> 8485M: Christoffer Dall <christoffer.dall@arm.com>
8475M: Marc Zyngier <marc.zyngier@arm.com> 8486M: Marc Zyngier <marc.zyngier@arm.com>
8487R: James Morse <james.morse@arm.com>
8488R: Julien Thierry <julien.thierry@arm.com>
8489R: Suzuki K Pouloze <suzuki.poulose@arm.com>
8476L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 8490L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
8477L: kvmarm@lists.cs.columbia.edu 8491L: kvmarm@lists.cs.columbia.edu
8478W: http://systems.cs.columbia.edu/projects/kvm-arm 8492W: http://systems.cs.columbia.edu/projects/kvm-arm
8479T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git 8493T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git
8480S: Supported 8494S: Maintained
8481F: arch/arm/include/uapi/asm/kvm* 8495F: arch/arm/include/uapi/asm/kvm*
8482F: arch/arm/include/asm/kvm* 8496F: arch/arm/include/asm/kvm*
8483F: arch/arm/kvm/ 8497F: arch/arm/kvm/
8484F: virt/kvm/arm/
8485F: include/kvm/arm_*
8486
8487KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)
8488M: Christoffer Dall <christoffer.dall@arm.com>
8489M: Marc Zyngier <marc.zyngier@arm.com>
8490L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
8491L: kvmarm@lists.cs.columbia.edu
8492S: Maintained
8493F: arch/arm64/include/uapi/asm/kvm* 8498F: arch/arm64/include/uapi/asm/kvm*
8494F: arch/arm64/include/asm/kvm* 8499F: arch/arm64/include/asm/kvm*
8495F: arch/arm64/kvm/ 8500F: arch/arm64/kvm/
8501F: virt/kvm/arm/
8502F: include/kvm/arm_*
8496 8503
8497KERNEL VIRTUAL MACHINE FOR MIPS (KVM/mips) 8504KERNEL VIRTUAL MACHINE FOR MIPS (KVM/mips)
8498M: James Hogan <jhogan@kernel.org> 8505M: James Hogan <jhogan@kernel.org>
diff --git a/Makefile b/Makefile
index 9ef547fc7ffe..c0a34064c574 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2VERSION = 5 2VERSION = 5
3PATCHLEVEL = 0 3PATCHLEVEL = 1
4SUBLEVEL = 0 4SUBLEVEL = 0
5EXTRAVERSION = 5EXTRAVERSION = -rc2
6NAME = Shy Crocodile 6NAME = Shy Crocodile
7 7
8# *DOCUMENTATION* 8# *DOCUMENTATION*
@@ -31,6 +31,16 @@ _all:
31# descending is started. They are now explicitly listed as the 31# descending is started. They are now explicitly listed as the
32# prepare rule. 32# prepare rule.
33 33
34# Ugly workaround for Debian make-kpkg:
35# make-kpkg directly includes the top Makefile of Linux kernel. In such a case,
36# skip sub-make to support debian_* targets in ruleset/kernel_version.mk, but
37# displays warning to discourage such abusage.
38ifneq ($(word 2, $(MAKEFILE_LIST)),)
39$(warning Do not include top Makefile of Linux Kernel)
40sub-make-done := 1
41MAKEFLAGS += -rR
42endif
43
34ifneq ($(sub-make-done),1) 44ifneq ($(sub-make-done),1)
35 45
36# Do not use make's built-in rules and variables 46# Do not use make's built-in rules and variables
@@ -402,7 +412,7 @@ CHECK = sparse
402 412
403CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 413CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
404 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) 414 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
405NOSTDINC_FLAGS = 415NOSTDINC_FLAGS :=
406CFLAGS_MODULE = 416CFLAGS_MODULE =
407AFLAGS_MODULE = 417AFLAGS_MODULE =
408LDFLAGS_MODULE = 418LDFLAGS_MODULE =
@@ -1088,9 +1098,11 @@ asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
1088 1098
1089PHONY += asm-generic uapi-asm-generic 1099PHONY += asm-generic uapi-asm-generic
1090asm-generic: uapi-asm-generic 1100asm-generic: uapi-asm-generic
1091 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm 1101 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1102 generic=include/asm-generic
1092uapi-asm-generic: 1103uapi-asm-generic:
1093 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm 1104 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1105 generic=include/uapi/asm-generic
1094 1106
1095PHONY += prepare-objtool 1107PHONY += prepare-objtool
1096prepare-objtool: $(objtool_target) 1108prepare-objtool: $(objtool_target)
diff --git a/arch/alpha/include/uapi/asm/Kbuild b/arch/alpha/include/uapi/asm/Kbuild
index 439f5157aa35..7417847dc438 100644
--- a/arch/alpha/include/uapi/asm/Kbuild
+++ b/arch/alpha/include/uapi/asm/Kbuild
@@ -1,3 +1 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h generated-y += unistd_32.h
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/include/uapi/asm/Kbuild b/arch/arc/include/uapi/asm/Kbuild
index 0febf1a07c30..755bb11323d8 100644
--- a/arch/arc/include/uapi/asm/Kbuild
+++ b/arch/arc/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += kvm_para.h 1generic-y += kvm_para.h
4generic-y += ucontext.h 2generic-y += ucontext.h
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/Kconfig b/arch/arm/Kconfig
index 5085a1eab9fc..054ead960f98 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1310,7 +1310,7 @@ config SCHED_SMT
1310config HAVE_ARM_SCU 1310config HAVE_ARM_SCU
1311 bool 1311 bool
1312 help 1312 help
1313 This option enables support for the ARM system coherency unit 1313 This option enables support for the ARM snoop control unit
1314 1314
1315config HAVE_ARM_ARCH_TIMER 1315config HAVE_ARM_ARCH_TIMER
1316 bool "Architected timer support" 1316 bool "Architected timer support"
@@ -1322,7 +1322,6 @@ config HAVE_ARM_ARCH_TIMER
1322 1322
1323config HAVE_ARM_TWD 1323config HAVE_ARM_TWD
1324 bool 1324 bool
1325 select TIMER_OF if OF
1326 help 1325 help
1327 This options enables support for the ARM timer and watchdog unit 1326 This options enables support for the ARM timer and watchdog unit
1328 1327
diff --git a/arch/arm/Kconfig-nommu b/arch/arm/Kconfig-nommu
index 1168a03c8525..36c80d3dd93f 100644
--- a/arch/arm/Kconfig-nommu
+++ b/arch/arm/Kconfig-nommu
@@ -20,10 +20,12 @@ config DRAM_SIZE
20 20
21config FLASH_MEM_BASE 21config FLASH_MEM_BASE
22 hex 'FLASH Base Address' if SET_MEM_PARAM 22 hex 'FLASH Base Address' if SET_MEM_PARAM
23 depends on CPU_ARM740T || CPU_ARM946E || CPU_ARM940T
23 default 0x00400000 24 default 0x00400000
24 25
25config FLASH_SIZE 26config FLASH_SIZE
26 hex 'FLASH Size' if SET_MEM_PARAM 27 hex 'FLASH Size' if SET_MEM_PARAM
28 depends on CPU_ARM740T || CPU_ARM946E || CPU_ARM940T
27 default 0x00400000 29 default 0x00400000
28 30
29config PROCESSOR_ID 31config PROCESSOR_ID
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 00000e91ad65..807a7d06c2a0 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -10,7 +10,7 @@
10# 10#
11# Copyright (C) 1995-2001 by Russell King 11# Copyright (C) 1995-2001 by Russell King
12 12
13LDFLAGS_vmlinux :=-p --no-undefined -X --pic-veneer 13LDFLAGS_vmlinux := --no-undefined -X --pic-veneer
14ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) 14ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
15LDFLAGS_vmlinux += --be8 15LDFLAGS_vmlinux += --be8
16KBUILD_LDFLAGS_MODULE += --be8 16KBUILD_LDFLAGS_MODULE += --be8
diff --git a/arch/arm/boot/bootp/Makefile b/arch/arm/boot/bootp/Makefile
index 83e1a076a5d6..981a8d03f064 100644
--- a/arch/arm/boot/bootp/Makefile
+++ b/arch/arm/boot/bootp/Makefile
@@ -8,7 +8,7 @@
8 8
9GCOV_PROFILE := n 9GCOV_PROFILE := n
10 10
11LDFLAGS_bootp :=-p --no-undefined -X \ 11LDFLAGS_bootp := --no-undefined -X \
12 --defsym initrd_phys=$(INITRD_PHYS) \ 12 --defsym initrd_phys=$(INITRD_PHYS) \
13 --defsym params_phys=$(PARAMS_PHYS) -T 13 --defsym params_phys=$(PARAMS_PHYS) -T
14AFLAGS_initrd.o :=-DINITRD=\"$(INITRD)\" 14AFLAGS_initrd.o :=-DINITRD=\"$(INITRD)\"
diff --git a/arch/arm/boot/bootp/init.S b/arch/arm/boot/bootp/init.S
index 78b508075161..142927e5f485 100644
--- a/arch/arm/boot/bootp/init.S
+++ b/arch/arm/boot/bootp/init.S
@@ -44,7 +44,7 @@ _start: add lr, pc, #-0x8 @ lr = current load addr
44 */ 44 */
45 movne r10, #0 @ terminator 45 movne r10, #0 @ terminator
46 movne r4, #2 @ Size of this entry (2 words) 46 movne r4, #2 @ Size of this entry (2 words)
47 stmneia r9, {r4, r5, r10} @ Size, ATAG_CORE, terminator 47 stmiane r9, {r4, r5, r10} @ Size, ATAG_CORE, terminator
48 48
49/* 49/*
50 * find the end of the tag list, and then add an INITRD tag on the end. 50 * find the end of the tag list, and then add an INITRD tag on the end.
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 6114ae6ea466..9219389bbe61 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -132,8 +132,6 @@ endif
132ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) 132ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
133LDFLAGS_vmlinux += --be8 133LDFLAGS_vmlinux += --be8
134endif 134endif
135# ?
136LDFLAGS_vmlinux += -p
137# Report unresolved symbol references 135# Report unresolved symbol references
138LDFLAGS_vmlinux += --no-undefined 136LDFLAGS_vmlinux += --no-undefined
139# Delete all temporary local symbols 137# Delete all temporary local symbols
diff --git a/arch/arm/boot/compressed/ll_char_wr.S b/arch/arm/boot/compressed/ll_char_wr.S
index 8517c8606b4a..b1dcdb9f4030 100644
--- a/arch/arm/boot/compressed/ll_char_wr.S
+++ b/arch/arm/boot/compressed/ll_char_wr.S
@@ -75,7 +75,7 @@ Lrow4bpplp:
75 tst r1, #7 @ avoid using r7 directly after 75 tst r1, #7 @ avoid using r7 directly after
76 str r7, [r0, -r5]! 76 str r7, [r0, -r5]!
77 subne r1, r1, #1 77 subne r1, r1, #1
78 ldrneb r7, [r6, r1] 78 ldrbne r7, [r6, r1]
79 bne Lrow4bpplp 79 bne Lrow4bpplp
80 ldmfd sp!, {r4 - r7, pc} 80 ldmfd sp!, {r4 - r7, pc}
81 81
@@ -103,7 +103,7 @@ Lrow8bpplp:
103 sub r0, r0, r5 @ avoid ip 103 sub r0, r0, r5 @ avoid ip
104 stmia r0, {r4, ip} 104 stmia r0, {r4, ip}
105 subne r1, r1, #1 105 subne r1, r1, #1
106 ldrneb r7, [r6, r1] 106 ldrbne r7, [r6, r1]
107 bne Lrow8bpplp 107 bne Lrow8bpplp
108 ldmfd sp!, {r4 - r7, pc} 108 ldmfd sp!, {r4 - r7, pc}
109 109
diff --git a/arch/arm/boot/dts/imx28-cfa10036.dts b/arch/arm/boot/dts/imx28-cfa10036.dts
index d3e3622979c5..de48b5808ef6 100644
--- a/arch/arm/boot/dts/imx28-cfa10036.dts
+++ b/arch/arm/boot/dts/imx28-cfa10036.dts
@@ -11,6 +11,7 @@
11 11
12/dts-v1/; 12/dts-v1/;
13#include "imx28.dtsi" 13#include "imx28.dtsi"
14#include <dt-bindings/gpio/gpio.h>
14 15
15/ { 16/ {
16 model = "Crystalfontz CFA-10036 Board"; 17 model = "Crystalfontz CFA-10036 Board";
@@ -96,7 +97,7 @@
96 pinctrl-names = "default"; 97 pinctrl-names = "default";
97 pinctrl-0 = <&ssd1306_cfa10036>; 98 pinctrl-0 = <&ssd1306_cfa10036>;
98 reg = <0x3c>; 99 reg = <0x3c>;
99 reset-gpios = <&gpio2 7 0>; 100 reset-gpios = <&gpio2 7 GPIO_ACTIVE_LOW>;
100 solomon,height = <32>; 101 solomon,height = <32>;
101 solomon,width = <128>; 102 solomon,width = <128>;
102 solomon,page-offset = <0>; 103 solomon,page-offset = <0>;
diff --git a/arch/arm/common/mcpm_entry.c b/arch/arm/common/mcpm_entry.c
index ad574d20415c..1b1b82b37ce0 100644
--- a/arch/arm/common/mcpm_entry.c
+++ b/arch/arm/common/mcpm_entry.c
@@ -381,7 +381,7 @@ static int __init nocache_trampoline(unsigned long _arg)
381 unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); 381 unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
382 phys_reset_t phys_reset; 382 phys_reset_t phys_reset;
383 383
384 mcpm_set_entry_vector(cpu, cluster, cpu_resume); 384 mcpm_set_entry_vector(cpu, cluster, cpu_resume_no_hyp);
385 setup_mm_for_reboot(); 385 setup_mm_for_reboot();
386 386
387 __mcpm_cpu_going_down(cpu, cluster); 387 __mcpm_cpu_going_down(cpu, cluster);
diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild
index 1d66db9c9db5..a8a4eb7f6dae 100644
--- a/arch/arm/include/asm/Kbuild
+++ b/arch/arm/include/asm/Kbuild
@@ -18,7 +18,6 @@ generic-y += segment.h
18generic-y += serial.h 18generic-y += serial.h
19generic-y += simd.h 19generic-y += simd.h
20generic-y += sizes.h 20generic-y += sizes.h
21generic-y += timex.h
22generic-y += trace_clock.h 21generic-y += trace_clock.h
23 22
24generated-y += mach-types.h 23generated-y += mach-types.h
diff --git a/arch/arm/include/asm/arch_gicv3.h b/arch/arm/include/asm/arch_gicv3.h
index f6f485f4744e..d15b8c99f1b3 100644
--- a/arch/arm/include/asm/arch_gicv3.h
+++ b/arch/arm/include/asm/arch_gicv3.h
@@ -55,7 +55,7 @@
55#define ICH_VTR __ACCESS_CP15(c12, 4, c11, 1) 55#define ICH_VTR __ACCESS_CP15(c12, 4, c11, 1)
56#define ICH_MISR __ACCESS_CP15(c12, 4, c11, 2) 56#define ICH_MISR __ACCESS_CP15(c12, 4, c11, 2)
57#define ICH_EISR __ACCESS_CP15(c12, 4, c11, 3) 57#define ICH_EISR __ACCESS_CP15(c12, 4, c11, 3)
58#define ICH_ELSR __ACCESS_CP15(c12, 4, c11, 5) 58#define ICH_ELRSR __ACCESS_CP15(c12, 4, c11, 5)
59#define ICH_VMCR __ACCESS_CP15(c12, 4, c11, 7) 59#define ICH_VMCR __ACCESS_CP15(c12, 4, c11, 7)
60 60
61#define __LR0(x) __ACCESS_CP15(c12, 4, c12, x) 61#define __LR0(x) __ACCESS_CP15(c12, 4, c12, x)
@@ -152,7 +152,7 @@ CPUIF_MAP(ICH_HCR, ICH_HCR_EL2)
152CPUIF_MAP(ICH_VTR, ICH_VTR_EL2) 152CPUIF_MAP(ICH_VTR, ICH_VTR_EL2)
153CPUIF_MAP(ICH_MISR, ICH_MISR_EL2) 153CPUIF_MAP(ICH_MISR, ICH_MISR_EL2)
154CPUIF_MAP(ICH_EISR, ICH_EISR_EL2) 154CPUIF_MAP(ICH_EISR, ICH_EISR_EL2)
155CPUIF_MAP(ICH_ELSR, ICH_ELSR_EL2) 155CPUIF_MAP(ICH_ELRSR, ICH_ELRSR_EL2)
156CPUIF_MAP(ICH_VMCR, ICH_VMCR_EL2) 156CPUIF_MAP(ICH_VMCR, ICH_VMCR_EL2)
157CPUIF_MAP(ICH_AP0R3, ICH_AP0R3_EL2) 157CPUIF_MAP(ICH_AP0R3, ICH_AP0R3_EL2)
158CPUIF_MAP(ICH_AP0R2, ICH_AP0R2_EL2) 158CPUIF_MAP(ICH_AP0R2, ICH_AP0R2_EL2)
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 28a48e0d4cca..b59921a560da 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -376,9 +376,9 @@ THUMB( orr \reg , \reg , #PSR_T_BIT )
376 .macro usraccoff, instr, reg, ptr, inc, off, cond, abort, t=TUSER() 376 .macro usraccoff, instr, reg, ptr, inc, off, cond, abort, t=TUSER()
3779999: 3779999:
378 .if \inc == 1 378 .if \inc == 1
379 \instr\cond\()b\()\t\().w \reg, [\ptr, #\off] 379 \instr\()b\t\cond\().w \reg, [\ptr, #\off]
380 .elseif \inc == 4 380 .elseif \inc == 4
381 \instr\cond\()\t\().w \reg, [\ptr, #\off] 381 \instr\t\cond\().w \reg, [\ptr, #\off]
382 .else 382 .else
383 .error "Unsupported inc macro argument" 383 .error "Unsupported inc macro argument"
384 .endif 384 .endif
@@ -417,9 +417,9 @@ THUMB( orr \reg , \reg , #PSR_T_BIT )
417 .rept \rept 417 .rept \rept
4189999: 4189999:
419 .if \inc == 1 419 .if \inc == 1
420 \instr\cond\()b\()\t \reg, [\ptr], #\inc 420 \instr\()b\t\cond \reg, [\ptr], #\inc
421 .elseif \inc == 4 421 .elseif \inc == 4
422 \instr\cond\()\t \reg, [\ptr], #\inc 422 \instr\t\cond \reg, [\ptr], #\inc
423 .else 423 .else
424 .error "Unsupported inc macro argument" 424 .error "Unsupported inc macro argument"
425 .endif 425 .endif
@@ -460,7 +460,7 @@ THUMB( orr \reg , \reg , #PSR_T_BIT )
460 .macro check_uaccess, addr:req, size:req, limit:req, tmp:req, bad:req 460 .macro check_uaccess, addr:req, size:req, limit:req, tmp:req, bad:req
461#ifndef CONFIG_CPU_USE_DOMAINS 461#ifndef CONFIG_CPU_USE_DOMAINS
462 adds \tmp, \addr, #\size - 1 462 adds \tmp, \addr, #\size - 1
463 sbcccs \tmp, \tmp, \limit 463 sbcscc \tmp, \tmp, \limit
464 bcs \bad 464 bcs \bad
465#ifdef CONFIG_CPU_SPECTRE 465#ifdef CONFIG_CPU_SPECTRE
466 movcs \addr, #0 466 movcs \addr, #0
@@ -474,7 +474,7 @@ THUMB( orr \reg , \reg , #PSR_T_BIT )
474 sub \tmp, \limit, #1 474 sub \tmp, \limit, #1
475 subs \tmp, \tmp, \addr @ tmp = limit - 1 - addr 475 subs \tmp, \tmp, \addr @ tmp = limit - 1 - addr
476 addhs \tmp, \tmp, #1 @ if (tmp >= 0) { 476 addhs \tmp, \tmp, #1 @ if (tmp >= 0) {
477 subhss \tmp, \tmp, \size @ tmp = limit - (addr + size) } 477 subshs \tmp, \tmp, \size @ tmp = limit - (addr + size) }
478 movlo \addr, #0 @ if (tmp < 0) addr = NULL 478 movlo \addr, #0 @ if (tmp < 0) addr = NULL
479 csdb 479 csdb
480#endif 480#endif
diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
index 69772e742a0a..83ae97c049d9 100644
--- a/arch/arm/include/asm/barrier.h
+++ b/arch/arm/include/asm/barrier.h
@@ -11,6 +11,8 @@
11#define sev() __asm__ __volatile__ ("sev" : : : "memory") 11#define sev() __asm__ __volatile__ ("sev" : : : "memory")
12#define wfe() __asm__ __volatile__ ("wfe" : : : "memory") 12#define wfe() __asm__ __volatile__ ("wfe" : : : "memory")
13#define wfi() __asm__ __volatile__ ("wfi" : : : "memory") 13#define wfi() __asm__ __volatile__ ("wfi" : : : "memory")
14#else
15#define wfe() do { } while (0)
14#endif 16#endif
15 17
16#if __LINUX_ARM_ARCH__ >= 7 18#if __LINUX_ARM_ARCH__ >= 7
diff --git a/arch/arm/include/asm/hardware/entry-macro-iomd.S b/arch/arm/include/asm/hardware/entry-macro-iomd.S
index 8c215acd9b57..f7692731e514 100644
--- a/arch/arm/include/asm/hardware/entry-macro-iomd.S
+++ b/arch/arm/include/asm/hardware/entry-macro-iomd.S
@@ -16,25 +16,25 @@
16 ldr \tmp, =irq_prio_h 16 ldr \tmp, =irq_prio_h
17 teq \irqstat, #0 17 teq \irqstat, #0
18#ifdef IOMD_BASE 18#ifdef IOMD_BASE
19 ldreqb \irqstat, [\base, #IOMD_DMAREQ] @ get dma 19 ldrbeq \irqstat, [\base, #IOMD_DMAREQ] @ get dma
20 addeq \tmp, \tmp, #256 @ irq_prio_h table size 20 addeq \tmp, \tmp, #256 @ irq_prio_h table size
21 teqeq \irqstat, #0 21 teqeq \irqstat, #0
22 bne 2406f 22 bne 2406f
23#endif 23#endif
24 ldreqb \irqstat, [\base, #IOMD_IRQREQA] @ get low priority 24 ldrbeq \irqstat, [\base, #IOMD_IRQREQA] @ get low priority
25 addeq \tmp, \tmp, #256 @ irq_prio_d table size 25 addeq \tmp, \tmp, #256 @ irq_prio_d table size
26 teqeq \irqstat, #0 26 teqeq \irqstat, #0
27#ifdef IOMD_IRQREQC 27#ifdef IOMD_IRQREQC
28 ldreqb \irqstat, [\base, #IOMD_IRQREQC] 28 ldrbeq \irqstat, [\base, #IOMD_IRQREQC]
29 addeq \tmp, \tmp, #256 @ irq_prio_l table size 29 addeq \tmp, \tmp, #256 @ irq_prio_l table size
30 teqeq \irqstat, #0 30 teqeq \irqstat, #0
31#endif 31#endif
32#ifdef IOMD_IRQREQD 32#ifdef IOMD_IRQREQD
33 ldreqb \irqstat, [\base, #IOMD_IRQREQD] 33 ldrbeq \irqstat, [\base, #IOMD_IRQREQD]
34 addeq \tmp, \tmp, #256 @ irq_prio_lc table size 34 addeq \tmp, \tmp, #256 @ irq_prio_lc table size
35 teqeq \irqstat, #0 35 teqeq \irqstat, #0
36#endif 36#endif
372406: ldrneb \irqnr, [\tmp, \irqstat] @ get IRQ number 372406: ldrbne \irqnr, [\tmp, \irqstat] @ get IRQ number
38 .endm 38 .endm
39 39
40/* 40/*
diff --git a/arch/arm/include/asm/kvm_emulate.h b/arch/arm/include/asm/kvm_emulate.h
index 77121b713bef..8927cae7c966 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -265,6 +265,14 @@ static inline bool kvm_vcpu_dabt_isextabt(struct kvm_vcpu *vcpu)
265 } 265 }
266} 266}
267 267
268static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
269{
270 if (kvm_vcpu_trap_is_iabt(vcpu))
271 return false;
272
273 return kvm_vcpu_dabt_iswrite(vcpu);
274}
275
268static inline u32 kvm_vcpu_hvc_get_imm(struct kvm_vcpu *vcpu) 276static inline u32 kvm_vcpu_hvc_get_imm(struct kvm_vcpu *vcpu)
269{ 277{
270 return kvm_vcpu_get_hsr(vcpu) & HSR_HVC_IMM_MASK; 278 return kvm_vcpu_get_hsr(vcpu) & HSR_HVC_IMM_MASK;
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 50e89869178a..770d73257ad9 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -26,6 +26,7 @@
26#include <asm/kvm_asm.h> 26#include <asm/kvm_asm.h>
27#include <asm/kvm_mmio.h> 27#include <asm/kvm_mmio.h>
28#include <asm/fpstate.h> 28#include <asm/fpstate.h>
29#include <asm/smp_plat.h>
29#include <kvm/arm_arch_timer.h> 30#include <kvm/arm_arch_timer.h>
30 31
31#define __KVM_HAVE_ARCH_INTC_INITIALIZED 32#define __KVM_HAVE_ARCH_INTC_INITIALIZED
@@ -57,10 +58,13 @@ int __attribute_const__ kvm_target_cpu(void);
57int kvm_reset_vcpu(struct kvm_vcpu *vcpu); 58int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
58void kvm_reset_coprocs(struct kvm_vcpu *vcpu); 59void kvm_reset_coprocs(struct kvm_vcpu *vcpu);
59 60
60struct kvm_arch { 61struct kvm_vmid {
61 /* VTTBR value associated with below pgd and vmid */ 62 /* The VMID generation used for the virt. memory system */
62 u64 vttbr; 63 u64 vmid_gen;
64 u32 vmid;
65};
63 66
67struct kvm_arch {
64 /* The last vcpu id that ran on each physical CPU */ 68 /* The last vcpu id that ran on each physical CPU */
65 int __percpu *last_vcpu_ran; 69 int __percpu *last_vcpu_ran;
66 70
@@ -70,11 +74,11 @@ struct kvm_arch {
70 */ 74 */
71 75
72 /* The VMID generation used for the virt. memory system */ 76 /* The VMID generation used for the virt. memory system */
73 u64 vmid_gen; 77 struct kvm_vmid vmid;
74 u32 vmid;
75 78
76 /* Stage-2 page table */ 79 /* Stage-2 page table */
77 pgd_t *pgd; 80 pgd_t *pgd;
81 phys_addr_t pgd_phys;
78 82
79 /* Interrupt controller */ 83 /* Interrupt controller */
80 struct vgic_dist vgic; 84 struct vgic_dist vgic;
@@ -148,6 +152,13 @@ struct kvm_cpu_context {
148 152
149typedef struct kvm_cpu_context kvm_cpu_context_t; 153typedef struct kvm_cpu_context kvm_cpu_context_t;
150 154
155static inline void kvm_init_host_cpu_context(kvm_cpu_context_t *cpu_ctxt,
156 int cpu)
157{
158 /* The host's MPIDR is immutable, so let's set it up at boot time */
159 cpu_ctxt->cp15[c0_MPIDR] = cpu_logical_map(cpu);
160}
161
151struct vcpu_reset_state { 162struct vcpu_reset_state {
152 unsigned long pc; 163 unsigned long pc;
153 unsigned long r0; 164 unsigned long r0;
@@ -224,7 +235,35 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
224int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); 235int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
225int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); 236int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
226int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); 237int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
227unsigned long kvm_call_hyp(void *hypfn, ...); 238
239unsigned long __kvm_call_hyp(void *hypfn, ...);
240
241/*
242 * The has_vhe() part doesn't get emitted, but is used for type-checking.
243 */
244#define kvm_call_hyp(f, ...) \
245 do { \
246 if (has_vhe()) { \
247 f(__VA_ARGS__); \
248 } else { \
249 __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__); \
250 } \
251 } while(0)
252
253#define kvm_call_hyp_ret(f, ...) \
254 ({ \
255 typeof(f(__VA_ARGS__)) ret; \
256 \
257 if (has_vhe()) { \
258 ret = f(__VA_ARGS__); \
259 } else { \
260 ret = __kvm_call_hyp(kvm_ksym_ref(f), \
261 ##__VA_ARGS__); \
262 } \
263 \
264 ret; \
265 })
266
228void force_vm_exit(const cpumask_t *mask); 267void force_vm_exit(const cpumask_t *mask);
229int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu, 268int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
230 struct kvm_vcpu_events *events); 269 struct kvm_vcpu_events *events);
@@ -275,7 +314,7 @@ static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,
275 * compliant with the PCS!). 314 * compliant with the PCS!).
276 */ 315 */
277 316
278 kvm_call_hyp((void*)hyp_stack_ptr, vector_ptr, pgd_ptr); 317 __kvm_call_hyp((void*)hyp_stack_ptr, vector_ptr, pgd_ptr);
279} 318}
280 319
281static inline void __cpu_init_stage2(void) 320static inline void __cpu_init_stage2(void)
diff --git a/arch/arm/include/asm/kvm_hyp.h b/arch/arm/include/asm/kvm_hyp.h
index e93a0cac9add..87bcd18df8d5 100644
--- a/arch/arm/include/asm/kvm_hyp.h
+++ b/arch/arm/include/asm/kvm_hyp.h
@@ -40,6 +40,7 @@
40#define TTBR1 __ACCESS_CP15_64(1, c2) 40#define TTBR1 __ACCESS_CP15_64(1, c2)
41#define VTTBR __ACCESS_CP15_64(6, c2) 41#define VTTBR __ACCESS_CP15_64(6, c2)
42#define PAR __ACCESS_CP15_64(0, c7) 42#define PAR __ACCESS_CP15_64(0, c7)
43#define CNTP_CVAL __ACCESS_CP15_64(2, c14)
43#define CNTV_CVAL __ACCESS_CP15_64(3, c14) 44#define CNTV_CVAL __ACCESS_CP15_64(3, c14)
44#define CNTVOFF __ACCESS_CP15_64(4, c14) 45#define CNTVOFF __ACCESS_CP15_64(4, c14)
45 46
@@ -85,6 +86,7 @@
85#define TID_PRIV __ACCESS_CP15(c13, 0, c0, 4) 86#define TID_PRIV __ACCESS_CP15(c13, 0, c0, 4)
86#define HTPIDR __ACCESS_CP15(c13, 4, c0, 2) 87#define HTPIDR __ACCESS_CP15(c13, 4, c0, 2)
87#define CNTKCTL __ACCESS_CP15(c14, 0, c1, 0) 88#define CNTKCTL __ACCESS_CP15(c14, 0, c1, 0)
89#define CNTP_CTL __ACCESS_CP15(c14, 0, c2, 1)
88#define CNTV_CTL __ACCESS_CP15(c14, 0, c3, 1) 90#define CNTV_CTL __ACCESS_CP15(c14, 0, c3, 1)
89#define CNTHCTL __ACCESS_CP15(c14, 4, c1, 0) 91#define CNTHCTL __ACCESS_CP15(c14, 4, c1, 0)
90 92
@@ -94,6 +96,8 @@
94#define read_sysreg_el0(r) read_sysreg(r##_el0) 96#define read_sysreg_el0(r) read_sysreg(r##_el0)
95#define write_sysreg_el0(v, r) write_sysreg(v, r##_el0) 97#define write_sysreg_el0(v, r) write_sysreg(v, r##_el0)
96 98
99#define cntp_ctl_el0 CNTP_CTL
100#define cntp_cval_el0 CNTP_CVAL
97#define cntv_ctl_el0 CNTV_CTL 101#define cntv_ctl_el0 CNTV_CTL
98#define cntv_cval_el0 CNTV_CVAL 102#define cntv_cval_el0 CNTV_CVAL
99#define cntvoff_el2 CNTVOFF 103#define cntvoff_el2 CNTVOFF
diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
index 3a875fc1b63c..2de96a180166 100644
--- a/arch/arm/include/asm/kvm_mmu.h
+++ b/arch/arm/include/asm/kvm_mmu.h
@@ -421,9 +421,14 @@ static inline int hyp_map_aux_data(void)
421 421
422static inline void kvm_set_ipa_limit(void) {} 422static inline void kvm_set_ipa_limit(void) {}
423 423
424static inline bool kvm_cpu_has_cnp(void) 424static __always_inline u64 kvm_get_vttbr(struct kvm *kvm)
425{ 425{
426 return false; 426 struct kvm_vmid *vmid = &kvm->arch.vmid;
427 u64 vmid_field, baddr;
428
429 baddr = kvm->arch.pgd_phys;
430 vmid_field = (u64)vmid->vmid << VTTBR_VMID_SHIFT;
431 return kvm_phys_to_vttbr(baddr) | vmid_field;
427} 432}
428 433
429#endif /* !__ASSEMBLY__ */ 434#endif /* !__ASSEMBLY__ */
diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index a757401129f9..48ce1b19069b 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -125,6 +125,9 @@ extern pgprot_t pgprot_s2_device;
125#define pgprot_stronglyordered(prot) \ 125#define pgprot_stronglyordered(prot) \
126 __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED) 126 __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED)
127 127
128#define pgprot_device(prot) \
129 __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_DEV_SHARED | L_PTE_SHARED | L_PTE_DIRTY | L_PTE_XN)
130
128#ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE 131#ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
129#define pgprot_dmacoherent(prot) \ 132#define pgprot_dmacoherent(prot) \
130 __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE | L_PTE_XN) 133 __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE | L_PTE_XN)
diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
index 120f4c9bbfde..57fe73ea0f72 100644
--- a/arch/arm/include/asm/processor.h
+++ b/arch/arm/include/asm/processor.h
@@ -89,7 +89,11 @@ extern void release_thread(struct task_struct *);
89unsigned long get_wchan(struct task_struct *p); 89unsigned long get_wchan(struct task_struct *p);
90 90
91#if __LINUX_ARM_ARCH__ == 6 || defined(CONFIG_ARM_ERRATA_754327) 91#if __LINUX_ARM_ARCH__ == 6 || defined(CONFIG_ARM_ERRATA_754327)
92#define cpu_relax() smp_mb() 92#define cpu_relax() \
93 do { \
94 smp_mb(); \
95 __asm__ __volatile__("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"); \
96 } while (0)
93#else 97#else
94#define cpu_relax() barrier() 98#define cpu_relax() barrier()
95#endif 99#endif
diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
index 709a55989cb0..451ae684aaf4 100644
--- a/arch/arm/include/asm/smp.h
+++ b/arch/arm/include/asm/smp.h
@@ -67,7 +67,6 @@ struct secondary_data {
67 void *stack; 67 void *stack;
68}; 68};
69extern struct secondary_data secondary_data; 69extern struct secondary_data secondary_data;
70extern volatile int pen_release;
71extern void secondary_startup(void); 70extern void secondary_startup(void);
72extern void secondary_startup_arm(void); 71extern void secondary_startup_arm(void);
73 72
diff --git a/arch/arm/include/asm/smp_twd.h b/arch/arm/include/asm/smp_twd.h
index 312784ee9936..c729d2113a24 100644
--- a/arch/arm/include/asm/smp_twd.h
+++ b/arch/arm/include/asm/smp_twd.h
@@ -19,20 +19,4 @@
19#define TWD_TIMER_CONTROL_PERIODIC (1 << 1) 19#define TWD_TIMER_CONTROL_PERIODIC (1 << 1)
20#define TWD_TIMER_CONTROL_IT_ENABLE (1 << 2) 20#define TWD_TIMER_CONTROL_IT_ENABLE (1 << 2)
21 21
22#include <linux/ioport.h>
23
24struct twd_local_timer {
25 struct resource res[2];
26};
27
28#define DEFINE_TWD_LOCAL_TIMER(name,base,irq) \
29struct twd_local_timer name __initdata = { \
30 .res = { \
31 DEFINE_RES_MEM(base, 0x10), \
32 DEFINE_RES_IRQ(irq), \
33 }, \
34};
35
36int twd_local_timer_register(struct twd_local_timer *);
37
38#endif 22#endif
diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
index 099c78fcf62d..8f009e788ad4 100644
--- a/arch/arm/include/asm/spinlock.h
+++ b/arch/arm/include/asm/spinlock.h
@@ -210,11 +210,12 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
210 210
211 prefetchw(&rw->lock); 211 prefetchw(&rw->lock);
212 __asm__ __volatile__( 212 __asm__ __volatile__(
213" .syntax unified\n"
213"1: ldrex %0, [%2]\n" 214"1: ldrex %0, [%2]\n"
214" adds %0, %0, #1\n" 215" adds %0, %0, #1\n"
215" strexpl %1, %0, [%2]\n" 216" strexpl %1, %0, [%2]\n"
216 WFE("mi") 217 WFE("mi")
217" rsbpls %0, %1, #0\n" 218" rsbspl %0, %1, #0\n"
218" bmi 1b" 219" bmi 1b"
219 : "=&r" (tmp), "=&r" (tmp2) 220 : "=&r" (tmp), "=&r" (tmp2)
220 : "r" (&rw->lock) 221 : "r" (&rw->lock)
diff --git a/arch/arm/include/asm/suspend.h b/arch/arm/include/asm/suspend.h
index 452bbdcbcc83..506314265c6f 100644
--- a/arch/arm/include/asm/suspend.h
+++ b/arch/arm/include/asm/suspend.h
@@ -10,6 +10,7 @@ struct sleep_save_sp {
10}; 10};
11 11
12extern void cpu_resume(void); 12extern void cpu_resume(void);
13extern void cpu_resume_no_hyp(void);
13extern void cpu_resume_arm(void); 14extern void cpu_resume_arm(void);
14extern int cpu_suspend(unsigned long, int (*)(unsigned long)); 15extern int cpu_suspend(unsigned long, int (*)(unsigned long));
15 16
diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
index ae5a0df5316e..dff49845eb87 100644
--- a/arch/arm/include/asm/uaccess.h
+++ b/arch/arm/include/asm/uaccess.h
@@ -85,7 +85,8 @@ static inline void set_fs(mm_segment_t fs)
85#define __range_ok(addr, size) ({ \ 85#define __range_ok(addr, size) ({ \
86 unsigned long flag, roksum; \ 86 unsigned long flag, roksum; \
87 __chk_user_ptr(addr); \ 87 __chk_user_ptr(addr); \
88 __asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \ 88 __asm__(".syntax unified\n" \
89 "adds %1, %2, %3; sbcscc %1, %1, %0; movcc %0, #0" \
89 : "=&r" (flag), "=&r" (roksum) \ 90 : "=&r" (flag), "=&r" (roksum) \
90 : "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \ 91 : "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \
91 : "cc"); \ 92 : "cc"); \
diff --git a/arch/arm/include/asm/v7m.h b/arch/arm/include/asm/v7m.h
index 187ccf6496ad..2cb00d15831b 100644
--- a/arch/arm/include/asm/v7m.h
+++ b/arch/arm/include/asm/v7m.h
@@ -49,7 +49,7 @@
49 * (0 -> msp; 1 -> psp). Bits [1:0] are fixed to 0b01. 49 * (0 -> msp; 1 -> psp). Bits [1:0] are fixed to 0b01.
50 */ 50 */
51#define EXC_RET_STACK_MASK 0x00000004 51#define EXC_RET_STACK_MASK 0x00000004
52#define EXC_RET_THREADMODE_PROCESSSTACK 0xfffffffd 52#define EXC_RET_THREADMODE_PROCESSSTACK (3 << 2)
53 53
54/* Cache related definitions */ 54/* Cache related definitions */
55 55
diff --git a/arch/arm/include/asm/vfpmacros.h b/arch/arm/include/asm/vfpmacros.h
index ef5dfedacd8d..628c336e8e3b 100644
--- a/arch/arm/include/asm/vfpmacros.h
+++ b/arch/arm/include/asm/vfpmacros.h
@@ -29,13 +29,13 @@
29 ldr \tmp, =elf_hwcap @ may not have MVFR regs 29 ldr \tmp, =elf_hwcap @ may not have MVFR regs
30 ldr \tmp, [\tmp, #0] 30 ldr \tmp, [\tmp, #0]
31 tst \tmp, #HWCAP_VFPD32 31 tst \tmp, #HWCAP_VFPD32
32 ldcnel p11, cr0, [\base],#32*4 @ FLDMIAD \base!, {d16-d31} 32 ldclne p11, cr0, [\base],#32*4 @ FLDMIAD \base!, {d16-d31}
33 addeq \base, \base, #32*4 @ step over unused register space 33 addeq \base, \base, #32*4 @ step over unused register space
34#else 34#else
35 VFPFMRX \tmp, MVFR0 @ Media and VFP Feature Register 0 35 VFPFMRX \tmp, MVFR0 @ Media and VFP Feature Register 0
36 and \tmp, \tmp, #MVFR0_A_SIMD_MASK @ A_SIMD field 36 and \tmp, \tmp, #MVFR0_A_SIMD_MASK @ A_SIMD field
37 cmp \tmp, #2 @ 32 x 64bit registers? 37 cmp \tmp, #2 @ 32 x 64bit registers?
38 ldceql p11, cr0, [\base],#32*4 @ FLDMIAD \base!, {d16-d31} 38 ldcleq p11, cr0, [\base],#32*4 @ FLDMIAD \base!, {d16-d31}
39 addne \base, \base, #32*4 @ step over unused register space 39 addne \base, \base, #32*4 @ step over unused register space
40#endif 40#endif
41#endif 41#endif
@@ -53,13 +53,13 @@
53 ldr \tmp, =elf_hwcap @ may not have MVFR regs 53 ldr \tmp, =elf_hwcap @ may not have MVFR regs
54 ldr \tmp, [\tmp, #0] 54 ldr \tmp, [\tmp, #0]
55 tst \tmp, #HWCAP_VFPD32 55 tst \tmp, #HWCAP_VFPD32
56 stcnel p11, cr0, [\base],#32*4 @ FSTMIAD \base!, {d16-d31} 56 stclne p11, cr0, [\base],#32*4 @ FSTMIAD \base!, {d16-d31}
57 addeq \base, \base, #32*4 @ step over unused register space 57 addeq \base, \base, #32*4 @ step over unused register space
58#else 58#else
59 VFPFMRX \tmp, MVFR0 @ Media and VFP Feature Register 0 59 VFPFMRX \tmp, MVFR0 @ Media and VFP Feature Register 0
60 and \tmp, \tmp, #MVFR0_A_SIMD_MASK @ A_SIMD field 60 and \tmp, \tmp, #MVFR0_A_SIMD_MASK @ A_SIMD field
61 cmp \tmp, #2 @ 32 x 64bit registers? 61 cmp \tmp, #2 @ 32 x 64bit registers?
62 stceql p11, cr0, [\base],#32*4 @ FSTMIAD \base!, {d16-d31} 62 stcleq p11, cr0, [\base],#32*4 @ FSTMIAD \base!, {d16-d31}
63 addne \base, \base, #32*4 @ step over unused register space 63 addne \base, \base, #32*4 @ step over unused register space
64#endif 64#endif
65#endif 65#endif
diff --git a/arch/arm/include/debug/tegra.S b/arch/arm/include/debug/tegra.S
index 3bc80599c022..4a5a645c76e2 100644
--- a/arch/arm/include/debug/tegra.S
+++ b/arch/arm/include/debug/tegra.S
@@ -173,7 +173,7 @@
173 173
174 .macro senduart, rd, rx 174 .macro senduart, rd, rx
175 cmp \rx, #0 175 cmp \rx, #0
176 strneb \rd, [\rx, #UART_TX << UART_SHIFT] 176 strbne \rd, [\rx, #UART_TX << UART_SHIFT]
1771001: 1771001:
178 .endm 178 .endm
179 179
diff --git a/arch/arm/include/uapi/asm/Kbuild b/arch/arm/include/uapi/asm/Kbuild
index eee8f7d23899..23b4464c0995 100644
--- a/arch/arm/include/uapi/asm/Kbuild
+++ b/arch/arm/include/uapi/asm/Kbuild
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2include include/uapi/asm-generic/Kbuild.asm
3 2
4generated-y += unistd-common.h 3generated-y += unistd-common.h
5generated-y += unistd-oabi.h 4generated-y += unistd-oabi.h
diff --git a/arch/arm/kernel/debug.S b/arch/arm/kernel/debug.S
index b795dc2408c0..b9f94e03d916 100644
--- a/arch/arm/kernel/debug.S
+++ b/arch/arm/kernel/debug.S
@@ -86,7 +86,7 @@ hexbuf_rel: .long hexbuf_addr - .
86ENTRY(printascii) 86ENTRY(printascii)
87 addruart_current r3, r1, r2 87 addruart_current r3, r1, r2
881: teq r0, #0 881: teq r0, #0
89 ldrneb r1, [r0], #1 89 ldrbne r1, [r0], #1
90 teqne r1, #0 90 teqne r1, #0
91 reteq lr 91 reteq lr
922: teq r1, #'\n' 922: teq r1, #'\n'
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index e85a3af9ddeb..ce4aea57130a 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -636,7 +636,7 @@ call_fpe:
636 @ Test if we need to give access to iWMMXt coprocessors 636 @ Test if we need to give access to iWMMXt coprocessors
637 ldr r5, [r10, #TI_FLAGS] 637 ldr r5, [r10, #TI_FLAGS]
638 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 638 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
639 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1) 639 movscs r7, r5, lsr #(TIF_USING_IWMMXT + 1)
640 bcs iwmmxt_task_enable 640 bcs iwmmxt_task_enable
641#endif 641#endif
642 ARM( add pc, pc, r8, lsr #6 ) 642 ARM( add pc, pc, r8, lsr #6 )
@@ -872,7 +872,7 @@ __kuser_cmpxchg64: @ 0xffff0f60
872 smp_dmb arm 872 smp_dmb arm
8731: ldrexd r0, r1, [r2] @ load current val 8731: ldrexd r0, r1, [r2] @ load current val
874 eors r3, r0, r4 @ compare with oldval (1) 874 eors r3, r0, r4 @ compare with oldval (1)
875 eoreqs r3, r1, r5 @ compare with oldval (2) 875 eorseq r3, r1, r5 @ compare with oldval (2)
876 strexdeq r3, r6, r7, [r2] @ store newval if eq 876 strexdeq r3, r6, r7, [r2] @ store newval if eq
877 teqeq r3, #1 @ success? 877 teqeq r3, #1 @ success?
878 beq 1b @ if no then retry 878 beq 1b @ if no then retry
@@ -896,8 +896,8 @@ __kuser_cmpxchg64: @ 0xffff0f60
896 ldmia r1, {r6, lr} @ load new val 896 ldmia r1, {r6, lr} @ load new val
8971: ldmia r2, {r0, r1} @ load current val 8971: ldmia r2, {r0, r1} @ load current val
898 eors r3, r0, r4 @ compare with oldval (1) 898 eors r3, r0, r4 @ compare with oldval (1)
899 eoreqs r3, r1, r5 @ compare with oldval (2) 899 eorseq r3, r1, r5 @ compare with oldval (2)
9002: stmeqia r2, {r6, lr} @ store newval if eq 9002: stmiaeq r2, {r6, lr} @ store newval if eq
901 rsbs r0, r3, #0 @ set return val and C flag 901 rsbs r0, r3, #0 @ set return val and C flag
902 ldmfd sp!, {r4, r5, r6, pc} 902 ldmfd sp!, {r4, r5, r6, pc}
903 903
@@ -911,7 +911,7 @@ kuser_cmpxchg64_fixup:
911 mov r7, #0xffff0fff 911 mov r7, #0xffff0fff
912 sub r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64))) 912 sub r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64)))
913 subs r8, r4, r7 913 subs r8, r4, r7
914 rsbcss r8, r8, #(2b - 1b) 914 rsbscs r8, r8, #(2b - 1b)
915 strcs r7, [sp, #S_PC] 915 strcs r7, [sp, #S_PC]
916#if __LINUX_ARM_ARCH__ < 6 916#if __LINUX_ARM_ARCH__ < 6
917 bcc kuser_cmpxchg32_fixup 917 bcc kuser_cmpxchg32_fixup
@@ -969,7 +969,7 @@ kuser_cmpxchg32_fixup:
969 mov r7, #0xffff0fff 969 mov r7, #0xffff0fff
970 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg))) 970 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
971 subs r8, r4, r7 971 subs r8, r4, r7
972 rsbcss r8, r8, #(2b - 1b) 972 rsbscs r8, r8, #(2b - 1b)
973 strcs r7, [sp, #S_PC] 973 strcs r7, [sp, #S_PC]
974 ret lr 974 ret lr
975 .previous 975 .previous
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 0465d65d23de..f7649adef505 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -373,7 +373,7 @@ sys_syscall:
373 movhs scno, #0 373 movhs scno, #0
374 csdb 374 csdb
375#endif 375#endif
376 stmloia sp, {r5, r6} @ shuffle args 376 stmialo sp, {r5, r6} @ shuffle args
377 movlo r0, r1 377 movlo r0, r1
378 movlo r1, r2 378 movlo r1, r2
379 movlo r2, r3 379 movlo r2, r3
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index 773424843d6e..32051ec5b33f 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -127,7 +127,8 @@
127 */ 127 */
128 .macro v7m_exception_slow_exit ret_r0 128 .macro v7m_exception_slow_exit ret_r0
129 cpsid i 129 cpsid i
130 ldr lr, =EXC_RET_THREADMODE_PROCESSSTACK 130 ldr lr, =exc_ret
131 ldr lr, [lr]
131 132
132 @ read original r12, sp, lr, pc and xPSR 133 @ read original r12, sp, lr, pc and xPSR
133 add r12, sp, #S_IP 134 add r12, sp, #S_IP
@@ -387,8 +388,8 @@
387 badr lr, \ret @ return address 388 badr lr, \ret @ return address
388 .if \reload 389 .if \reload
389 add r1, sp, #S_R0 + S_OFF @ pointer to regs 390 add r1, sp, #S_R0 + S_OFF @ pointer to regs
390 ldmccia r1, {r0 - r6} @ reload r0-r6 391 ldmiacc r1, {r0 - r6} @ reload r0-r6
391 stmccia sp, {r4, r5} @ update stack arguments 392 stmiacc sp, {r4, r5} @ update stack arguments
392 .endif 393 .endif
393 ldrcc pc, [\table, \tmp, lsl #2] @ call sys_* routine 394 ldrcc pc, [\table, \tmp, lsl #2] @ call sys_* routine
394#else 395#else
@@ -396,8 +397,8 @@
396 badr lr, \ret @ return address 397 badr lr, \ret @ return address
397 .if \reload 398 .if \reload
398 add r1, sp, #S_R0 + S_OFF @ pointer to regs 399 add r1, sp, #S_R0 + S_OFF @ pointer to regs
399 ldmccia r1, {r0 - r6} @ reload r0-r6 400 ldmiacc r1, {r0 - r6} @ reload r0-r6
400 stmccia sp, {r4, r5} @ update stack arguments 401 stmiacc sp, {r4, r5} @ update stack arguments
401 .endif 402 .endif
402 ldrcc pc, [\table, \nr, lsl #2] @ call sys_* routine 403 ldrcc pc, [\table, \nr, lsl #2] @ call sys_* routine
403#endif 404#endif
diff --git a/arch/arm/kernel/entry-v7m.S b/arch/arm/kernel/entry-v7m.S
index abcf47848525..19d2dcd6530d 100644
--- a/arch/arm/kernel/entry-v7m.S
+++ b/arch/arm/kernel/entry-v7m.S
@@ -146,3 +146,7 @@ ENTRY(vector_table)
146 .rept CONFIG_CPU_V7M_NUM_IRQ 146 .rept CONFIG_CPU_V7M_NUM_IRQ
147 .long __irq_entry @ External Interrupts 147 .long __irq_entry @ External Interrupts
148 .endr 148 .endr
149 .align 2
150 .globl exc_ret
151exc_ret:
152 .space 4
diff --git a/arch/arm/kernel/head-nommu.S b/arch/arm/kernel/head-nommu.S
index ec29de250076..c08d2d890f7b 100644
--- a/arch/arm/kernel/head-nommu.S
+++ b/arch/arm/kernel/head-nommu.S
@@ -439,8 +439,8 @@ M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(3)])
439 str r5, [r12, #PMSAv8_RBAR_A(0)] 439 str r5, [r12, #PMSAv8_RBAR_A(0)]
440 str r6, [r12, #PMSAv8_RLAR_A(0)] 440 str r6, [r12, #PMSAv8_RLAR_A(0)]
441#else 441#else
442 mcr p15, 0, r5, c6, c10, 1 @ PRBAR4 442 mcr p15, 0, r5, c6, c10, 0 @ PRBAR4
443 mcr p15, 0, r6, c6, c10, 2 @ PRLAR4 443 mcr p15, 0, r6, c6, c10, 1 @ PRLAR4
444#endif 444#endif
445#endif 445#endif
446 ret lr 446 ret lr
diff --git a/arch/arm/kernel/hyp-stub.S b/arch/arm/kernel/hyp-stub.S
index 60146e32619a..82a942894fc0 100644
--- a/arch/arm/kernel/hyp-stub.S
+++ b/arch/arm/kernel/hyp-stub.S
@@ -180,8 +180,8 @@ ARM_BE8(orr r7, r7, #(1 << 25)) @ HSCTLR.EE
180 @ Check whether GICv3 system registers are available 180 @ Check whether GICv3 system registers are available
181 mrc p15, 0, r7, c0, c1, 1 @ ID_PFR1 181 mrc p15, 0, r7, c0, c1, 1 @ ID_PFR1
182 ubfx r7, r7, #28, #4 182 ubfx r7, r7, #28, #4
183 cmp r7, #1 183 teq r7, #0
184 bne 2f 184 beq 2f
185 185
186 @ Enable system register accesses 186 @ Enable system register accesses
187 mrc p15, 4, r7, c12, c9, 5 @ ICC_HSRE 187 mrc p15, 4, r7, c12, c9, 5 @ ICC_HSRE
diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c
index dd2eb5f76b9f..76300f3813e8 100644
--- a/arch/arm/kernel/machine_kexec.c
+++ b/arch/arm/kernel/machine_kexec.c
@@ -91,8 +91,11 @@ void machine_crash_nonpanic_core(void *unused)
91 91
92 set_cpu_online(smp_processor_id(), false); 92 set_cpu_online(smp_processor_id(), false);
93 atomic_dec(&waiting_for_crash_ipi); 93 atomic_dec(&waiting_for_crash_ipi);
94 while (1) 94
95 while (1) {
95 cpu_relax(); 96 cpu_relax();
97 wfe();
98 }
96} 99}
97 100
98void crash_smp_send_stop(void) 101void crash_smp_send_stop(void)
diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
index a50dc00d79a2..d0a05a3bdb96 100644
--- a/arch/arm/kernel/patch.c
+++ b/arch/arm/kernel/patch.c
@@ -16,7 +16,7 @@ struct patch {
16 unsigned int insn; 16 unsigned int insn;
17}; 17};
18 18
19static DEFINE_SPINLOCK(patch_lock); 19static DEFINE_RAW_SPINLOCK(patch_lock);
20 20
21static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags) 21static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)
22 __acquires(&patch_lock) 22 __acquires(&patch_lock)
@@ -33,7 +33,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)
33 return addr; 33 return addr;
34 34
35 if (flags) 35 if (flags)
36 spin_lock_irqsave(&patch_lock, *flags); 36 raw_spin_lock_irqsave(&patch_lock, *flags);
37 else 37 else
38 __acquire(&patch_lock); 38 __acquire(&patch_lock);
39 39
@@ -48,7 +48,7 @@ static void __kprobes patch_unmap(int fixmap, unsigned long *flags)
48 clear_fixmap(fixmap); 48 clear_fixmap(fixmap);
49 49
50 if (flags) 50 if (flags)
51 spin_unlock_irqrestore(&patch_lock, *flags); 51 raw_spin_unlock_irqrestore(&patch_lock, *flags);
52 else 52 else
53 __release(&patch_lock); 53 __release(&patch_lock);
54} 54}
diff --git a/arch/arm/kernel/sleep.S b/arch/arm/kernel/sleep.S
index a8257fc9cf2a..5dc8b80bb693 100644
--- a/arch/arm/kernel/sleep.S
+++ b/arch/arm/kernel/sleep.S
@@ -120,6 +120,14 @@ ENDPROC(cpu_resume_after_mmu)
120 .text 120 .text
121 .align 121 .align
122 122
123#ifdef CONFIG_MCPM
124 .arm
125THUMB( .thumb )
126ENTRY(cpu_resume_no_hyp)
127ARM_BE8(setend be) @ ensure we are in BE mode
128 b no_hyp
129#endif
130
123#ifdef CONFIG_MMU 131#ifdef CONFIG_MMU
124 .arm 132 .arm
125ENTRY(cpu_resume_arm) 133ENTRY(cpu_resume_arm)
@@ -135,6 +143,7 @@ ARM_BE8(setend be) @ ensure we are in BE mode
135 bl __hyp_stub_install_secondary 143 bl __hyp_stub_install_secondary
136#endif 144#endif
137 safe_svcmode_maskall r1 145 safe_svcmode_maskall r1
146no_hyp:
138 mov r1, #0 147 mov r1, #0
139 ALT_SMP(mrc p15, 0, r0, c0, c0, 5) 148 ALT_SMP(mrc p15, 0, r0, c0, c0, 5)
140 ALT_UP_B(1f) 149 ALT_UP_B(1f)
@@ -164,6 +173,9 @@ ENDPROC(cpu_resume)
164#ifdef CONFIG_MMU 173#ifdef CONFIG_MMU
165ENDPROC(cpu_resume_arm) 174ENDPROC(cpu_resume_arm)
166#endif 175#endif
176#ifdef CONFIG_MCPM
177ENDPROC(cpu_resume_no_hyp)
178#endif
167 179
168 .align 2 180 .align 2
169_sleep_save_sp: 181_sleep_save_sp:
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 1d6f5ea522f4..facd4240ca02 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -62,12 +62,6 @@
62 */ 62 */
63struct secondary_data secondary_data; 63struct secondary_data secondary_data;
64 64
65/*
66 * control for which core is the next to come out of the secondary
67 * boot "holding pen"
68 */
69volatile int pen_release = -1;
70
71enum ipi_msg_type { 65enum ipi_msg_type {
72 IPI_WAKEUP, 66 IPI_WAKEUP,
73 IPI_TIMER, 67 IPI_TIMER,
@@ -604,8 +598,10 @@ static void ipi_cpu_stop(unsigned int cpu)
604 local_fiq_disable(); 598 local_fiq_disable();
605 local_irq_disable(); 599 local_irq_disable();
606 600
607 while (1) 601 while (1) {
608 cpu_relax(); 602 cpu_relax();
603 wfe();
604 }
609} 605}
610 606
611static DEFINE_PER_CPU(struct completion *, cpu_completion); 607static DEFINE_PER_CPU(struct completion *, cpu_completion);
diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index b30eafeef096..3cdc399b9fc3 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -100,8 +100,6 @@ static void twd_timer_stop(void)
100 disable_percpu_irq(clk->irq); 100 disable_percpu_irq(clk->irq);
101} 101}
102 102
103#ifdef CONFIG_COMMON_CLK
104
105/* 103/*
106 * Updates clockevent frequency when the cpu frequency changes. 104 * Updates clockevent frequency when the cpu frequency changes.
107 * Called on the cpu that is changing frequency with interrupts disabled. 105 * Called on the cpu that is changing frequency with interrupts disabled.
@@ -143,54 +141,6 @@ static int twd_clk_init(void)
143} 141}
144core_initcall(twd_clk_init); 142core_initcall(twd_clk_init);
145 143
146#elif defined (CONFIG_CPU_FREQ)
147
148#include <linux/cpufreq.h>
149
150/*
151 * Updates clockevent frequency when the cpu frequency changes.
152 * Called on the cpu that is changing frequency with interrupts disabled.
153 */
154static void twd_update_frequency(void *data)
155{
156 twd_timer_rate = clk_get_rate(twd_clk);
157
158 clockevents_update_freq(raw_cpu_ptr(twd_evt), twd_timer_rate);
159}
160
161static int twd_cpufreq_transition(struct notifier_block *nb,
162 unsigned long state, void *data)
163{
164 struct cpufreq_freqs *freqs = data;
165
166 /*
167 * The twd clock events must be reprogrammed to account for the new
168 * frequency. The timer is local to a cpu, so cross-call to the
169 * changing cpu.
170 */
171 if (state == CPUFREQ_POSTCHANGE)
172 smp_call_function_single(freqs->cpu, twd_update_frequency,
173 NULL, 1);
174
175 return NOTIFY_OK;
176}
177
178static struct notifier_block twd_cpufreq_nb = {
179 .notifier_call = twd_cpufreq_transition,
180};
181
182static int twd_cpufreq_init(void)
183{
184 if (twd_evt && raw_cpu_ptr(twd_evt) && !IS_ERR(twd_clk))
185 return cpufreq_register_notifier(&twd_cpufreq_nb,
186 CPUFREQ_TRANSITION_NOTIFIER);
187
188 return 0;
189}
190core_initcall(twd_cpufreq_init);
191
192#endif
193
194static void twd_calibrate_rate(void) 144static void twd_calibrate_rate(void)
195{ 145{
196 unsigned long count; 146 unsigned long count;
@@ -366,21 +316,6 @@ out_free:
366 return err; 316 return err;
367} 317}
368 318
369int __init twd_local_timer_register(struct twd_local_timer *tlt)
370{
371 if (twd_base || twd_evt)
372 return -EBUSY;
373
374 twd_ppi = tlt->res[1].start;
375
376 twd_base = ioremap(tlt->res[0].start, resource_size(&tlt->res[0]));
377 if (!twd_base)
378 return -ENOMEM;
379
380 return twd_local_timer_common_register(NULL);
381}
382
383#ifdef CONFIG_OF
384static int __init twd_local_timer_of_register(struct device_node *np) 319static int __init twd_local_timer_of_register(struct device_node *np)
385{ 320{
386 int err; 321 int err;
@@ -406,4 +341,3 @@ out:
406TIMER_OF_DECLARE(arm_twd_a9, "arm,cortex-a9-twd-timer", twd_local_timer_of_register); 341TIMER_OF_DECLARE(arm_twd_a9, "arm,cortex-a9-twd-timer", twd_local_timer_of_register);
407TIMER_OF_DECLARE(arm_twd_a5, "arm,cortex-a5-twd-timer", twd_local_timer_of_register); 342TIMER_OF_DECLARE(arm_twd_a5, "arm,cortex-a5-twd-timer", twd_local_timer_of_register);
408TIMER_OF_DECLARE(arm_twd_11mp, "arm,arm11mp-twd-timer", twd_local_timer_of_register); 343TIMER_OF_DECLARE(arm_twd_11mp, "arm,arm11mp-twd-timer", twd_local_timer_of_register);
409#endif
diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c
index 0bee233fef9a..314cfb232a63 100644
--- a/arch/arm/kernel/unwind.c
+++ b/arch/arm/kernel/unwind.c
@@ -93,7 +93,7 @@ extern const struct unwind_idx __start_unwind_idx[];
93static const struct unwind_idx *__origin_unwind_idx; 93static const struct unwind_idx *__origin_unwind_idx;
94extern const struct unwind_idx __stop_unwind_idx[]; 94extern const struct unwind_idx __stop_unwind_idx[];
95 95
96static DEFINE_SPINLOCK(unwind_lock); 96static DEFINE_RAW_SPINLOCK(unwind_lock);
97static LIST_HEAD(unwind_tables); 97static LIST_HEAD(unwind_tables);
98 98
99/* Convert a prel31 symbol to an absolute address */ 99/* Convert a prel31 symbol to an absolute address */
@@ -201,7 +201,7 @@ static const struct unwind_idx *unwind_find_idx(unsigned long addr)
201 /* module unwind tables */ 201 /* module unwind tables */
202 struct unwind_table *table; 202 struct unwind_table *table;
203 203
204 spin_lock_irqsave(&unwind_lock, flags); 204 raw_spin_lock_irqsave(&unwind_lock, flags);
205 list_for_each_entry(table, &unwind_tables, list) { 205 list_for_each_entry(table, &unwind_tables, list) {
206 if (addr >= table->begin_addr && 206 if (addr >= table->begin_addr &&
207 addr < table->end_addr) { 207 addr < table->end_addr) {
@@ -213,7 +213,7 @@ static const struct unwind_idx *unwind_find_idx(unsigned long addr)
213 break; 213 break;
214 } 214 }
215 } 215 }
216 spin_unlock_irqrestore(&unwind_lock, flags); 216 raw_spin_unlock_irqrestore(&unwind_lock, flags);
217 } 217 }
218 218
219 pr_debug("%s: idx = %p\n", __func__, idx); 219 pr_debug("%s: idx = %p\n", __func__, idx);
@@ -529,9 +529,9 @@ struct unwind_table *unwind_table_add(unsigned long start, unsigned long size,
529 tab->begin_addr = text_addr; 529 tab->begin_addr = text_addr;
530 tab->end_addr = text_addr + text_size; 530 tab->end_addr = text_addr + text_size;
531 531
532 spin_lock_irqsave(&unwind_lock, flags); 532 raw_spin_lock_irqsave(&unwind_lock, flags);
533 list_add_tail(&tab->list, &unwind_tables); 533 list_add_tail(&tab->list, &unwind_tables);
534 spin_unlock_irqrestore(&unwind_lock, flags); 534 raw_spin_unlock_irqrestore(&unwind_lock, flags);
535 535
536 return tab; 536 return tab;
537} 537}
@@ -543,9 +543,9 @@ void unwind_table_del(struct unwind_table *tab)
543 if (!tab) 543 if (!tab)
544 return; 544 return;
545 545
546 spin_lock_irqsave(&unwind_lock, flags); 546 raw_spin_lock_irqsave(&unwind_lock, flags);
547 list_del(&tab->list); 547 list_del(&tab->list);
548 spin_unlock_irqrestore(&unwind_lock, flags); 548 raw_spin_unlock_irqrestore(&unwind_lock, flags);
549 549
550 kfree(tab); 550 kfree(tab);
551} 551}
diff --git a/arch/arm/kvm/Makefile b/arch/arm/kvm/Makefile
index 48de846f2246..531e59f5be9c 100644
--- a/arch/arm/kvm/Makefile
+++ b/arch/arm/kvm/Makefile
@@ -8,9 +8,8 @@ ifeq ($(plus_virt),+virt)
8 plus_virt_def := -DREQUIRES_VIRT=1 8 plus_virt_def := -DREQUIRES_VIRT=1
9endif 9endif
10 10
11ccflags-y += -Iarch/arm/kvm -Ivirt/kvm/arm/vgic 11ccflags-y += -I $(srctree)/$(src) -I $(srctree)/virt/kvm/arm/vgic
12CFLAGS_arm.o := -I. $(plus_virt_def) 12CFLAGS_arm.o := $(plus_virt_def)
13CFLAGS_mmu.o := -I.
14 13
15AFLAGS_init.o := -Wa,-march=armv7-a$(plus_virt) 14AFLAGS_init.o := -Wa,-march=armv7-a$(plus_virt)
16AFLAGS_interrupts.o := -Wa,-march=armv7-a$(plus_virt) 15AFLAGS_interrupts.o := -Wa,-march=armv7-a$(plus_virt)
diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
index e8bd288fd5be..14915c78bd99 100644
--- a/arch/arm/kvm/coproc.c
+++ b/arch/arm/kvm/coproc.c
@@ -293,15 +293,16 @@ static bool access_cntp_tval(struct kvm_vcpu *vcpu,
293 const struct coproc_params *p, 293 const struct coproc_params *p,
294 const struct coproc_reg *r) 294 const struct coproc_reg *r)
295{ 295{
296 u64 now = kvm_phys_timer_read(); 296 u32 val;
297 u64 val;
298 297
299 if (p->is_write) { 298 if (p->is_write) {
300 val = *vcpu_reg(vcpu, p->Rt1); 299 val = *vcpu_reg(vcpu, p->Rt1);
301 kvm_arm_timer_set_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL, val + now); 300 kvm_arm_timer_write_sysreg(vcpu,
301 TIMER_PTIMER, TIMER_REG_TVAL, val);
302 } else { 302 } else {
303 val = kvm_arm_timer_get_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL); 303 val = kvm_arm_timer_read_sysreg(vcpu,
304 *vcpu_reg(vcpu, p->Rt1) = val - now; 304 TIMER_PTIMER, TIMER_REG_TVAL);
305 *vcpu_reg(vcpu, p->Rt1) = val;
305 } 306 }
306 307
307 return true; 308 return true;
@@ -315,9 +316,11 @@ static bool access_cntp_ctl(struct kvm_vcpu *vcpu,
315 316
316 if (p->is_write) { 317 if (p->is_write) {
317 val = *vcpu_reg(vcpu, p->Rt1); 318 val = *vcpu_reg(vcpu, p->Rt1);
318 kvm_arm_timer_set_reg(vcpu, KVM_REG_ARM_PTIMER_CTL, val); 319 kvm_arm_timer_write_sysreg(vcpu,
320 TIMER_PTIMER, TIMER_REG_CTL, val);
319 } else { 321 } else {
320 val = kvm_arm_timer_get_reg(vcpu, KVM_REG_ARM_PTIMER_CTL); 322 val = kvm_arm_timer_read_sysreg(vcpu,
323 TIMER_PTIMER, TIMER_REG_CTL);
321 *vcpu_reg(vcpu, p->Rt1) = val; 324 *vcpu_reg(vcpu, p->Rt1) = val;
322 } 325 }
323 326
@@ -333,9 +336,11 @@ static bool access_cntp_cval(struct kvm_vcpu *vcpu,
333 if (p->is_write) { 336 if (p->is_write) {
334 val = (u64)*vcpu_reg(vcpu, p->Rt2) << 32; 337 val = (u64)*vcpu_reg(vcpu, p->Rt2) << 32;
335 val |= *vcpu_reg(vcpu, p->Rt1); 338 val |= *vcpu_reg(vcpu, p->Rt1);
336 kvm_arm_timer_set_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL, val); 339 kvm_arm_timer_write_sysreg(vcpu,
340 TIMER_PTIMER, TIMER_REG_CVAL, val);
337 } else { 341 } else {
338 val = kvm_arm_timer_get_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL); 342 val = kvm_arm_timer_read_sysreg(vcpu,
343 TIMER_PTIMER, TIMER_REG_CVAL);
339 *vcpu_reg(vcpu, p->Rt1) = val; 344 *vcpu_reg(vcpu, p->Rt1) = val;
340 *vcpu_reg(vcpu, p->Rt2) = val >> 32; 345 *vcpu_reg(vcpu, p->Rt2) = val >> 32;
341 } 346 }
diff --git a/arch/arm/kvm/hyp/cp15-sr.c b/arch/arm/kvm/hyp/cp15-sr.c
index c4782812714c..8bf895ec6e04 100644
--- a/arch/arm/kvm/hyp/cp15-sr.c
+++ b/arch/arm/kvm/hyp/cp15-sr.c
@@ -27,7 +27,6 @@ static u64 *cp15_64(struct kvm_cpu_context *ctxt, int idx)
27 27
28void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt) 28void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
29{ 29{
30 ctxt->cp15[c0_MPIDR] = read_sysreg(VMPIDR);
31 ctxt->cp15[c0_CSSELR] = read_sysreg(CSSELR); 30 ctxt->cp15[c0_CSSELR] = read_sysreg(CSSELR);
32 ctxt->cp15[c1_SCTLR] = read_sysreg(SCTLR); 31 ctxt->cp15[c1_SCTLR] = read_sysreg(SCTLR);
33 ctxt->cp15[c1_CPACR] = read_sysreg(CPACR); 32 ctxt->cp15[c1_CPACR] = read_sysreg(CPACR);
diff --git a/arch/arm/kvm/hyp/hyp-entry.S b/arch/arm/kvm/hyp/hyp-entry.S
index aa3f9a9837ac..6ed3cf23fe89 100644
--- a/arch/arm/kvm/hyp/hyp-entry.S
+++ b/arch/arm/kvm/hyp/hyp-entry.S
@@ -176,7 +176,7 @@ THUMB( orr lr, lr, #PSR_T_BIT )
176 msr spsr_cxsf, lr 176 msr spsr_cxsf, lr
177 ldr lr, =panic 177 ldr lr, =panic
178 msr ELR_hyp, lr 178 msr ELR_hyp, lr
179 ldr lr, =kvm_call_hyp 179 ldr lr, =__kvm_call_hyp
180 clrex 180 clrex
181 eret 181 eret
182ENDPROC(__hyp_do_panic) 182ENDPROC(__hyp_do_panic)
diff --git a/arch/arm/kvm/hyp/switch.c b/arch/arm/kvm/hyp/switch.c
index acf1c37fa49c..3b058a5d7c5f 100644
--- a/arch/arm/kvm/hyp/switch.c
+++ b/arch/arm/kvm/hyp/switch.c
@@ -77,7 +77,7 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu)
77static void __hyp_text __activate_vm(struct kvm_vcpu *vcpu) 77static void __hyp_text __activate_vm(struct kvm_vcpu *vcpu)
78{ 78{
79 struct kvm *kvm = kern_hyp_va(vcpu->kvm); 79 struct kvm *kvm = kern_hyp_va(vcpu->kvm);
80 write_sysreg(kvm->arch.vttbr, VTTBR); 80 write_sysreg(kvm_get_vttbr(kvm), VTTBR);
81 write_sysreg(vcpu->arch.midr, VPIDR); 81 write_sysreg(vcpu->arch.midr, VPIDR);
82} 82}
83 83
diff --git a/arch/arm/kvm/hyp/tlb.c b/arch/arm/kvm/hyp/tlb.c
index c0edd450e104..8e4afba73635 100644
--- a/arch/arm/kvm/hyp/tlb.c
+++ b/arch/arm/kvm/hyp/tlb.c
@@ -41,7 +41,7 @@ void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
41 41
42 /* Switch to requested VMID */ 42 /* Switch to requested VMID */
43 kvm = kern_hyp_va(kvm); 43 kvm = kern_hyp_va(kvm);
44 write_sysreg(kvm->arch.vttbr, VTTBR); 44 write_sysreg(kvm_get_vttbr(kvm), VTTBR);
45 isb(); 45 isb();
46 46
47 write_sysreg(0, TLBIALLIS); 47 write_sysreg(0, TLBIALLIS);
@@ -61,7 +61,7 @@ void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
61 struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm); 61 struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm);
62 62
63 /* Switch to requested VMID */ 63 /* Switch to requested VMID */
64 write_sysreg(kvm->arch.vttbr, VTTBR); 64 write_sysreg(kvm_get_vttbr(kvm), VTTBR);
65 isb(); 65 isb();
66 66
67 write_sysreg(0, TLBIALL); 67 write_sysreg(0, TLBIALL);
diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S
index 80a1d6cd261c..a08e6419ebe9 100644
--- a/arch/arm/kvm/interrupts.S
+++ b/arch/arm/kvm/interrupts.S
@@ -42,7 +42,7 @@
42 * r12: caller save 42 * r12: caller save
43 * rest: callee save 43 * rest: callee save
44 */ 44 */
45ENTRY(kvm_call_hyp) 45ENTRY(__kvm_call_hyp)
46 hvc #0 46 hvc #0
47 bx lr 47 bx lr
48ENDPROC(kvm_call_hyp) 48ENDPROC(__kvm_call_hyp)
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index ad25fd1872c7..0bff0176db2c 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -39,7 +39,7 @@ $(obj)/csumpartialcopy.o: $(obj)/csumpartialcopygeneric.S
39$(obj)/csumpartialcopyuser.o: $(obj)/csumpartialcopygeneric.S 39$(obj)/csumpartialcopyuser.o: $(obj)/csumpartialcopygeneric.S
40 40
41ifeq ($(CONFIG_KERNEL_MODE_NEON),y) 41ifeq ($(CONFIG_KERNEL_MODE_NEON),y)
42 NEON_FLAGS := -mfloat-abi=softfp -mfpu=neon 42 NEON_FLAGS := -march=armv7-a -mfloat-abi=softfp -mfpu=neon
43 CFLAGS_xor-neon.o += $(NEON_FLAGS) 43 CFLAGS_xor-neon.o += $(NEON_FLAGS)
44 obj-$(CONFIG_XOR_BLOCKS) += xor-neon.o 44 obj-$(CONFIG_XOR_BLOCKS) += xor-neon.o
45endif 45endif
diff --git a/arch/arm/lib/bitops.h b/arch/arm/lib/bitops.h
index 93cddab73072..95bd35991288 100644
--- a/arch/arm/lib/bitops.h
+++ b/arch/arm/lib/bitops.h
@@ -7,7 +7,7 @@
7ENTRY( \name ) 7ENTRY( \name )
8UNWIND( .fnstart ) 8UNWIND( .fnstart )
9 ands ip, r1, #3 9 ands ip, r1, #3
10 strneb r1, [ip] @ assert word-aligned 10 strbne r1, [ip] @ assert word-aligned
11 mov r2, #1 11 mov r2, #1
12 and r3, r0, #31 @ Get bit offset 12 and r3, r0, #31 @ Get bit offset
13 mov r0, r0, lsr #5 13 mov r0, r0, lsr #5
@@ -32,7 +32,7 @@ ENDPROC(\name )
32ENTRY( \name ) 32ENTRY( \name )
33UNWIND( .fnstart ) 33UNWIND( .fnstart )
34 ands ip, r1, #3 34 ands ip, r1, #3
35 strneb r1, [ip] @ assert word-aligned 35 strbne r1, [ip] @ assert word-aligned
36 mov r2, #1 36 mov r2, #1
37 and r3, r0, #31 @ Get bit offset 37 and r3, r0, #31 @ Get bit offset
38 mov r0, r0, lsr #5 38 mov r0, r0, lsr #5
@@ -62,7 +62,7 @@ ENDPROC(\name )
62ENTRY( \name ) 62ENTRY( \name )
63UNWIND( .fnstart ) 63UNWIND( .fnstart )
64 ands ip, r1, #3 64 ands ip, r1, #3
65 strneb r1, [ip] @ assert word-aligned 65 strbne r1, [ip] @ assert word-aligned
66 and r2, r0, #31 66 and r2, r0, #31
67 mov r0, r0, lsr #5 67 mov r0, r0, lsr #5
68 mov r3, #1 68 mov r3, #1
@@ -89,7 +89,7 @@ ENDPROC(\name )
89ENTRY( \name ) 89ENTRY( \name )
90UNWIND( .fnstart ) 90UNWIND( .fnstart )
91 ands ip, r1, #3 91 ands ip, r1, #3
92 strneb r1, [ip] @ assert word-aligned 92 strbne r1, [ip] @ assert word-aligned
93 and r3, r0, #31 93 and r3, r0, #31
94 mov r0, r0, lsr #5 94 mov r0, r0, lsr #5
95 save_and_disable_irqs ip 95 save_and_disable_irqs ip
diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
index e936352ccb00..55946e3fa2ba 100644
--- a/arch/arm/lib/clear_user.S
+++ b/arch/arm/lib/clear_user.S
@@ -44,7 +44,7 @@ UNWIND(.save {r1, lr})
44 strusr r2, r0, 1, ne, rept=2 44 strusr r2, r0, 1, ne, rept=2
45 tst r1, #1 @ x1 x0 x1 x0 x1 x0 x1 45 tst r1, #1 @ x1 x0 x1 x0 x1 x0 x1
46 it ne @ explicit IT needed for the label 46 it ne @ explicit IT needed for the label
47USER( strnebt r2, [r0]) 47USER( strbtne r2, [r0])
48 mov r0, #0 48 mov r0, #0
49 ldmfd sp!, {r1, pc} 49 ldmfd sp!, {r1, pc}
50UNWIND(.fnend) 50UNWIND(.fnend)
diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
index 0d4c189c7f4f..6a3419e2c6d8 100644
--- a/arch/arm/lib/copy_from_user.S
+++ b/arch/arm/lib/copy_from_user.S
@@ -91,7 +91,7 @@
91 .endm 91 .endm
92 92
93 .macro str1b ptr reg cond=al abort 93 .macro str1b ptr reg cond=al abort
94 str\cond\()b \reg, [\ptr], #1 94 strb\cond \reg, [\ptr], #1
95 .endm 95 .endm
96 96
97 .macro enter reg1 reg2 97 .macro enter reg1 reg2
diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
index 6ee2f6706f86..b84ce1792043 100644
--- a/arch/arm/lib/copy_page.S
+++ b/arch/arm/lib/copy_page.S
@@ -39,9 +39,9 @@ ENTRY(copy_page)
39 .endr 39 .endr
40 subs r2, r2, #1 @ 1 40 subs r2, r2, #1 @ 1
41 stmia r0!, {r3, r4, ip, lr} @ 4 41 stmia r0!, {r3, r4, ip, lr} @ 4
42 ldmgtia r1!, {r3, r4, ip, lr} @ 4 42 ldmiagt r1!, {r3, r4, ip, lr} @ 4
43 bgt 1b @ 1 43 bgt 1b @ 1
44 PLD( ldmeqia r1!, {r3, r4, ip, lr} ) 44 PLD( ldmiaeq r1!, {r3, r4, ip, lr} )
45 PLD( beq 2b ) 45 PLD( beq 2b )
46 ldmfd sp!, {r4, pc} @ 3 46 ldmfd sp!, {r4, pc} @ 3
47ENDPROC(copy_page) 47ENDPROC(copy_page)
diff --git a/arch/arm/lib/copy_template.S b/arch/arm/lib/copy_template.S
index 652e4d98cd47..a11f2c25e03a 100644
--- a/arch/arm/lib/copy_template.S
+++ b/arch/arm/lib/copy_template.S
@@ -99,7 +99,7 @@
99 99
100 CALGN( ands ip, r0, #31 ) 100 CALGN( ands ip, r0, #31 )
101 CALGN( rsb r3, ip, #32 ) 101 CALGN( rsb r3, ip, #32 )
102 CALGN( sbcnes r4, r3, r2 ) @ C is always set here 102 CALGN( sbcsne r4, r3, r2 ) @ C is always set here
103 CALGN( bcs 2f ) 103 CALGN( bcs 2f )
104 CALGN( adr r4, 6f ) 104 CALGN( adr r4, 6f )
105 CALGN( subs r2, r2, r3 ) @ C gets set 105 CALGN( subs r2, r2, r3 ) @ C gets set
@@ -204,7 +204,7 @@
204 204
205 CALGN( ands ip, r0, #31 ) 205 CALGN( ands ip, r0, #31 )
206 CALGN( rsb ip, ip, #32 ) 206 CALGN( rsb ip, ip, #32 )
207 CALGN( sbcnes r4, ip, r2 ) @ C is always set here 207 CALGN( sbcsne r4, ip, r2 ) @ C is always set here
208 CALGN( subcc r2, r2, ip ) 208 CALGN( subcc r2, r2, ip )
209 CALGN( bcc 15f ) 209 CALGN( bcc 15f )
210 210
@@ -241,7 +241,7 @@
241 orr r9, r9, ip, lspush #\push 241 orr r9, r9, ip, lspush #\push
242 mov ip, ip, lspull #\pull 242 mov ip, ip, lspull #\pull
243 orr ip, ip, lr, lspush #\push 243 orr ip, ip, lr, lspush #\push
244 str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f 244 str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, abort=19f
245 bge 12b 245 bge 12b
246 PLD( cmn r2, #96 ) 246 PLD( cmn r2, #96 )
247 PLD( bge 13b ) 247 PLD( bge 13b )
diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
index 97a6ff4b7e3c..c7d08096e354 100644
--- a/arch/arm/lib/copy_to_user.S
+++ b/arch/arm/lib/copy_to_user.S
@@ -49,7 +49,7 @@
49 .endm 49 .endm
50 50
51 .macro ldr1b ptr reg cond=al abort 51 .macro ldr1b ptr reg cond=al abort
52 ldr\cond\()b \reg, [\ptr], #1 52 ldrb\cond \reg, [\ptr], #1
53 .endm 53 .endm
54 54
55#ifdef CONFIG_CPU_USE_DOMAINS 55#ifdef CONFIG_CPU_USE_DOMAINS
diff --git a/arch/arm/lib/csumpartial.S b/arch/arm/lib/csumpartial.S
index 984e0f29d548..bd84e2db353b 100644
--- a/arch/arm/lib/csumpartial.S
+++ b/arch/arm/lib/csumpartial.S
@@ -40,9 +40,9 @@ td3 .req lr
40 /* we must have at least one byte. */ 40 /* we must have at least one byte. */
41 tst buf, #1 @ odd address? 41 tst buf, #1 @ odd address?
42 movne sum, sum, ror #8 42 movne sum, sum, ror #8
43 ldrneb td0, [buf], #1 43 ldrbne td0, [buf], #1
44 subne len, len, #1 44 subne len, len, #1
45 adcnes sum, sum, td0, put_byte_1 45 adcsne sum, sum, td0, put_byte_1
46 46
47.Lless4: tst len, #6 47.Lless4: tst len, #6
48 beq .Lless8_byte 48 beq .Lless8_byte
@@ -68,8 +68,8 @@ td3 .req lr
68 bne .Lless8_wordlp 68 bne .Lless8_wordlp
69 69
70.Lless8_byte: tst len, #1 @ odd number of bytes 70.Lless8_byte: tst len, #1 @ odd number of bytes
71 ldrneb td0, [buf], #1 @ include last byte 71 ldrbne td0, [buf], #1 @ include last byte
72 adcnes sum, sum, td0, put_byte_0 @ update checksum 72 adcsne sum, sum, td0, put_byte_0 @ update checksum
73 73
74.Ldone: adc r0, sum, #0 @ collect up the last carry 74.Ldone: adc r0, sum, #0 @ collect up the last carry
75 ldr td0, [sp], #4 75 ldr td0, [sp], #4
@@ -78,17 +78,17 @@ td3 .req lr
78 ldr pc, [sp], #4 @ return 78 ldr pc, [sp], #4 @ return
79 79
80.Lnot_aligned: tst buf, #1 @ odd address 80.Lnot_aligned: tst buf, #1 @ odd address
81 ldrneb td0, [buf], #1 @ make even 81 ldrbne td0, [buf], #1 @ make even
82 subne len, len, #1 82 subne len, len, #1
83 adcnes sum, sum, td0, put_byte_1 @ update checksum 83 adcsne sum, sum, td0, put_byte_1 @ update checksum
84 84
85 tst buf, #2 @ 32-bit aligned? 85 tst buf, #2 @ 32-bit aligned?
86#if __LINUX_ARM_ARCH__ >= 4 86#if __LINUX_ARM_ARCH__ >= 4
87 ldrneh td0, [buf], #2 @ make 32-bit aligned 87 ldrhne td0, [buf], #2 @ make 32-bit aligned
88 subne len, len, #2 88 subne len, len, #2
89#else 89#else
90 ldrneb td0, [buf], #1 90 ldrbne td0, [buf], #1
91 ldrneb ip, [buf], #1 91 ldrbne ip, [buf], #1
92 subne len, len, #2 92 subne len, len, #2
93#ifndef __ARMEB__ 93#ifndef __ARMEB__
94 orrne td0, td0, ip, lsl #8 94 orrne td0, td0, ip, lsl #8
@@ -96,7 +96,7 @@ td3 .req lr
96 orrne td0, ip, td0, lsl #8 96 orrne td0, ip, td0, lsl #8
97#endif 97#endif
98#endif 98#endif
99 adcnes sum, sum, td0 @ update checksum 99 adcsne sum, sum, td0 @ update checksum
100 ret lr 100 ret lr
101 101
102ENTRY(csum_partial) 102ENTRY(csum_partial)
diff --git a/arch/arm/lib/csumpartialcopygeneric.S b/arch/arm/lib/csumpartialcopygeneric.S
index 10b45909610c..08e17758cbea 100644
--- a/arch/arm/lib/csumpartialcopygeneric.S
+++ b/arch/arm/lib/csumpartialcopygeneric.S
@@ -148,9 +148,9 @@ FN_ENTRY
148 strb r5, [dst], #1 148 strb r5, [dst], #1
149 mov r5, r4, get_byte_2 149 mov r5, r4, get_byte_2
150.Lexit: tst len, #1 150.Lexit: tst len, #1
151 strneb r5, [dst], #1 151 strbne r5, [dst], #1
152 andne r5, r5, #255 152 andne r5, r5, #255
153 adcnes sum, sum, r5, put_byte_0 153 adcsne sum, sum, r5, put_byte_0
154 154
155 /* 155 /*
156 * If the dst pointer was not 16-bit aligned, we 156 * If the dst pointer was not 16-bit aligned, we
diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
index b83fdc06286a..f4716d98e0b4 100644
--- a/arch/arm/lib/csumpartialcopyuser.S
+++ b/arch/arm/lib/csumpartialcopyuser.S
@@ -95,7 +95,7 @@
95 add r2, r2, r1 95 add r2, r2, r1
96 mov r0, #0 @ zero the buffer 96 mov r0, #0 @ zero the buffer
979002: teq r2, r1 979002: teq r2, r1
98 strneb r0, [r1], #1 98 strbne r0, [r1], #1
99 bne 9002b 99 bne 9002b
100 load_regs 100 load_regs
101 .popsection 101 .popsection
diff --git a/arch/arm/lib/div64.S b/arch/arm/lib/div64.S
index a9eafe4981eb..4d80f690c48b 100644
--- a/arch/arm/lib/div64.S
+++ b/arch/arm/lib/div64.S
@@ -88,8 +88,8 @@ UNWIND(.fnstart)
88 @ Break out early if dividend reaches 0. 88 @ Break out early if dividend reaches 0.
892: cmp xh, yl 892: cmp xh, yl
90 orrcs yh, yh, ip 90 orrcs yh, yh, ip
91 subcss xh, xh, yl 91 subscs xh, xh, yl
92 movnes ip, ip, lsr #1 92 movsne ip, ip, lsr #1
93 mov yl, yl, lsr #1 93 mov yl, yl, lsr #1
94 bne 2b 94 bne 2b
95 95
diff --git a/arch/arm/lib/floppydma.S b/arch/arm/lib/floppydma.S
index 617150b1baef..de68d3b343e3 100644
--- a/arch/arm/lib/floppydma.S
+++ b/arch/arm/lib/floppydma.S
@@ -14,8 +14,8 @@
14 .global floppy_fiqin_end 14 .global floppy_fiqin_end
15ENTRY(floppy_fiqin_start) 15ENTRY(floppy_fiqin_start)
16 subs r9, r9, #1 16 subs r9, r9, #1
17 ldrgtb r12, [r11, #-4] 17 ldrbgt r12, [r11, #-4]
18 ldrleb r12, [r11], #0 18 ldrble r12, [r11], #0
19 strb r12, [r10], #1 19 strb r12, [r10], #1
20 subs pc, lr, #4 20 subs pc, lr, #4
21floppy_fiqin_end: 21floppy_fiqin_end:
@@ -23,10 +23,10 @@ floppy_fiqin_end:
23 .global floppy_fiqout_end 23 .global floppy_fiqout_end
24ENTRY(floppy_fiqout_start) 24ENTRY(floppy_fiqout_start)
25 subs r9, r9, #1 25 subs r9, r9, #1
26 ldrgeb r12, [r10], #1 26 ldrbge r12, [r10], #1
27 movlt r12, #0 27 movlt r12, #0
28 strleb r12, [r11], #0 28 strble r12, [r11], #0
29 subles pc, lr, #4 29 subsle pc, lr, #4
30 strb r12, [r11, #-4] 30 strb r12, [r11, #-4]
31 subs pc, lr, #4 31 subs pc, lr, #4
32floppy_fiqout_end: 32floppy_fiqout_end:
diff --git a/arch/arm/lib/io-readsb.S b/arch/arm/lib/io-readsb.S
index c31b2f3153f1..91038a0a77b5 100644
--- a/arch/arm/lib/io-readsb.S
+++ b/arch/arm/lib/io-readsb.S
@@ -16,10 +16,10 @@
16 cmp ip, #2 16 cmp ip, #2
17 ldrb r3, [r0] 17 ldrb r3, [r0]
18 strb r3, [r1], #1 18 strb r3, [r1], #1
19 ldrgeb r3, [r0] 19 ldrbge r3, [r0]
20 strgeb r3, [r1], #1 20 strbge r3, [r1], #1
21 ldrgtb r3, [r0] 21 ldrbgt r3, [r0]
22 strgtb r3, [r1], #1 22 strbgt r3, [r1], #1
23 subs r2, r2, ip 23 subs r2, r2, ip
24 bne .Linsb_aligned 24 bne .Linsb_aligned
25 25
@@ -72,7 +72,7 @@ ENTRY(__raw_readsb)
72 bpl .Linsb_16_lp 72 bpl .Linsb_16_lp
73 73
74 tst r2, #15 74 tst r2, #15
75 ldmeqfd sp!, {r4 - r6, pc} 75 ldmfdeq sp!, {r4 - r6, pc}
76 76
77.Linsb_no_16: tst r2, #8 77.Linsb_no_16: tst r2, #8
78 beq .Linsb_no_8 78 beq .Linsb_no_8
@@ -109,15 +109,15 @@ ENTRY(__raw_readsb)
109 str r3, [r1], #4 109 str r3, [r1], #4
110 110
111.Linsb_no_4: ands r2, r2, #3 111.Linsb_no_4: ands r2, r2, #3
112 ldmeqfd sp!, {r4 - r6, pc} 112 ldmfdeq sp!, {r4 - r6, pc}
113 113
114 cmp r2, #2 114 cmp r2, #2
115 ldrb r3, [r0] 115 ldrb r3, [r0]
116 strb r3, [r1], #1 116 strb r3, [r1], #1
117 ldrgeb r3, [r0] 117 ldrbge r3, [r0]
118 strgeb r3, [r1], #1 118 strbge r3, [r1], #1
119 ldrgtb r3, [r0] 119 ldrbgt r3, [r0]
120 strgtb r3, [r1] 120 strbgt r3, [r1]
121 121
122 ldmfd sp!, {r4 - r6, pc} 122 ldmfd sp!, {r4 - r6, pc}
123ENDPROC(__raw_readsb) 123ENDPROC(__raw_readsb)
diff --git a/arch/arm/lib/io-readsl.S b/arch/arm/lib/io-readsl.S
index 2ed86fa5465f..f2e2064318d2 100644
--- a/arch/arm/lib/io-readsl.S
+++ b/arch/arm/lib/io-readsl.S
@@ -30,7 +30,7 @@ ENTRY(__raw_readsl)
302: movs r2, r2, lsl #31 302: movs r2, r2, lsl #31
31 ldrcs r3, [r0, #0] 31 ldrcs r3, [r0, #0]
32 ldrcs ip, [r0, #0] 32 ldrcs ip, [r0, #0]
33 stmcsia r1!, {r3, ip} 33 stmiacs r1!, {r3, ip}
34 ldrne r3, [r0, #0] 34 ldrne r3, [r0, #0]
35 strne r3, [r1, #0] 35 strne r3, [r1, #0]
36 ret lr 36 ret lr
diff --git a/arch/arm/lib/io-readsw-armv3.S b/arch/arm/lib/io-readsw-armv3.S
index 413da9914529..8b25b69c516e 100644
--- a/arch/arm/lib/io-readsw-armv3.S
+++ b/arch/arm/lib/io-readsw-armv3.S
@@ -68,7 +68,7 @@ ENTRY(__raw_readsw)
68 bpl .Linsw_8_lp 68 bpl .Linsw_8_lp
69 69
70 tst r2, #7 70 tst r2, #7
71 ldmeqfd sp!, {r4, r5, r6, pc} 71 ldmfdeq sp!, {r4, r5, r6, pc}
72 72
73.Lno_insw_8: tst r2, #4 73.Lno_insw_8: tst r2, #4
74 beq .Lno_insw_4 74 beq .Lno_insw_4
@@ -97,9 +97,9 @@ ENTRY(__raw_readsw)
97 97
98.Lno_insw_2: tst r2, #1 98.Lno_insw_2: tst r2, #1
99 ldrne r3, [r0] 99 ldrne r3, [r0]
100 strneb r3, [r1], #1 100 strbne r3, [r1], #1
101 movne r3, r3, lsr #8 101 movne r3, r3, lsr #8
102 strneb r3, [r1] 102 strbne r3, [r1]
103 103
104 ldmfd sp!, {r4, r5, r6, pc} 104 ldmfd sp!, {r4, r5, r6, pc}
105 105
diff --git a/arch/arm/lib/io-readsw-armv4.S b/arch/arm/lib/io-readsw-armv4.S
index d9a45e9692ae..5efdd66f5dcd 100644
--- a/arch/arm/lib/io-readsw-armv4.S
+++ b/arch/arm/lib/io-readsw-armv4.S
@@ -76,8 +76,8 @@ ENTRY(__raw_readsw)
76 pack r3, r3, ip 76 pack r3, r3, ip
77 str r3, [r1], #4 77 str r3, [r1], #4
78 78
79.Lno_insw_2: ldrneh r3, [r0] 79.Lno_insw_2: ldrhne r3, [r0]
80 strneh r3, [r1] 80 strhne r3, [r1]
81 81
82 ldmfd sp!, {r4, r5, pc} 82 ldmfd sp!, {r4, r5, pc}
83 83
@@ -94,7 +94,7 @@ ENTRY(__raw_readsw)
94#endif 94#endif
95 95
96.Linsw_noalign: stmfd sp!, {r4, lr} 96.Linsw_noalign: stmfd sp!, {r4, lr}
97 ldrccb ip, [r1, #-1]! 97 ldrbcc ip, [r1, #-1]!
98 bcc 1f 98 bcc 1f
99 99
100 ldrh ip, [r0] 100 ldrh ip, [r0]
@@ -121,11 +121,11 @@ ENTRY(__raw_readsw)
121 121
1223: tst r2, #1 1223: tst r2, #1
123 strb ip, [r1], #1 123 strb ip, [r1], #1
124 ldrneh ip, [r0] 124 ldrhne ip, [r0]
125 _BE_ONLY_( movne ip, ip, ror #8 ) 125 _BE_ONLY_( movne ip, ip, ror #8 )
126 strneb ip, [r1], #1 126 strbne ip, [r1], #1
127 _LE_ONLY_( movne ip, ip, lsr #8 ) 127 _LE_ONLY_( movne ip, ip, lsr #8 )
128 _BE_ONLY_( movne ip, ip, lsr #24 ) 128 _BE_ONLY_( movne ip, ip, lsr #24 )
129 strneb ip, [r1] 129 strbne ip, [r1]
130 ldmfd sp!, {r4, pc} 130 ldmfd sp!, {r4, pc}
131ENDPROC(__raw_readsw) 131ENDPROC(__raw_readsw)
diff --git a/arch/arm/lib/io-writesb.S b/arch/arm/lib/io-writesb.S
index a46bbc9b168b..7d2881a2381e 100644
--- a/arch/arm/lib/io-writesb.S
+++ b/arch/arm/lib/io-writesb.S
@@ -36,10 +36,10 @@
36 cmp ip, #2 36 cmp ip, #2
37 ldrb r3, [r1], #1 37 ldrb r3, [r1], #1
38 strb r3, [r0] 38 strb r3, [r0]
39 ldrgeb r3, [r1], #1 39 ldrbge r3, [r1], #1
40 strgeb r3, [r0] 40 strbge r3, [r0]
41 ldrgtb r3, [r1], #1 41 ldrbgt r3, [r1], #1
42 strgtb r3, [r0] 42 strbgt r3, [r0]
43 subs r2, r2, ip 43 subs r2, r2, ip
44 bne .Loutsb_aligned 44 bne .Loutsb_aligned
45 45
@@ -64,7 +64,7 @@ ENTRY(__raw_writesb)
64 bpl .Loutsb_16_lp 64 bpl .Loutsb_16_lp
65 65
66 tst r2, #15 66 tst r2, #15
67 ldmeqfd sp!, {r4, r5, pc} 67 ldmfdeq sp!, {r4, r5, pc}
68 68
69.Loutsb_no_16: tst r2, #8 69.Loutsb_no_16: tst r2, #8
70 beq .Loutsb_no_8 70 beq .Loutsb_no_8
@@ -80,15 +80,15 @@ ENTRY(__raw_writesb)
80 outword r3 80 outword r3
81 81
82.Loutsb_no_4: ands r2, r2, #3 82.Loutsb_no_4: ands r2, r2, #3
83 ldmeqfd sp!, {r4, r5, pc} 83 ldmfdeq sp!, {r4, r5, pc}
84 84
85 cmp r2, #2 85 cmp r2, #2
86 ldrb r3, [r1], #1 86 ldrb r3, [r1], #1
87 strb r3, [r0] 87 strb r3, [r0]
88 ldrgeb r3, [r1], #1 88 ldrbge r3, [r1], #1
89 strgeb r3, [r0] 89 strbge r3, [r0]
90 ldrgtb r3, [r1] 90 ldrbgt r3, [r1]
91 strgtb r3, [r0] 91 strbgt r3, [r0]
92 92
93 ldmfd sp!, {r4, r5, pc} 93 ldmfd sp!, {r4, r5, pc}
94ENDPROC(__raw_writesb) 94ENDPROC(__raw_writesb)
diff --git a/arch/arm/lib/io-writesl.S b/arch/arm/lib/io-writesl.S
index 4ea2435988c1..7596ac0c90b0 100644
--- a/arch/arm/lib/io-writesl.S
+++ b/arch/arm/lib/io-writesl.S
@@ -28,7 +28,7 @@ ENTRY(__raw_writesl)
28 bpl 1b 28 bpl 1b
29 ldmfd sp!, {r4, lr} 29 ldmfd sp!, {r4, lr}
302: movs r2, r2, lsl #31 302: movs r2, r2, lsl #31
31 ldmcsia r1!, {r3, ip} 31 ldmiacs r1!, {r3, ip}
32 strcs r3, [r0, #0] 32 strcs r3, [r0, #0]
33 ldrne r3, [r1, #0] 33 ldrne r3, [r1, #0]
34 strcs ip, [r0, #0] 34 strcs ip, [r0, #0]
diff --git a/arch/arm/lib/io-writesw-armv3.S b/arch/arm/lib/io-writesw-armv3.S
index 121789eb6802..cb94b9b49405 100644
--- a/arch/arm/lib/io-writesw-armv3.S
+++ b/arch/arm/lib/io-writesw-armv3.S
@@ -79,7 +79,7 @@ ENTRY(__raw_writesw)
79 bpl .Loutsw_8_lp 79 bpl .Loutsw_8_lp
80 80
81 tst r2, #7 81 tst r2, #7
82 ldmeqfd sp!, {r4, r5, r6, pc} 82 ldmfdeq sp!, {r4, r5, r6, pc}
83 83
84.Lno_outsw_8: tst r2, #4 84.Lno_outsw_8: tst r2, #4
85 beq .Lno_outsw_4 85 beq .Lno_outsw_4
diff --git a/arch/arm/lib/io-writesw-armv4.S b/arch/arm/lib/io-writesw-armv4.S
index 269f90c51ad2..e6645b2f249e 100644
--- a/arch/arm/lib/io-writesw-armv4.S
+++ b/arch/arm/lib/io-writesw-armv4.S
@@ -61,8 +61,8 @@ ENTRY(__raw_writesw)
61 ldr r3, [r1], #4 61 ldr r3, [r1], #4
62 outword r3 62 outword r3
63 63
64.Lno_outsw_2: ldrneh r3, [r1] 64.Lno_outsw_2: ldrhne r3, [r1]
65 strneh r3, [r0] 65 strhne r3, [r0]
66 66
67 ldmfd sp!, {r4, r5, pc} 67 ldmfd sp!, {r4, r5, pc}
68 68
@@ -95,6 +95,6 @@ ENTRY(__raw_writesw)
95 95
96 tst r2, #1 96 tst r2, #1
973: movne ip, r3, lsr #8 973: movne ip, r3, lsr #8
98 strneh ip, [r0] 98 strhne ip, [r0]
99 ret lr 99 ret lr
100ENDPROC(__raw_writesw) 100ENDPROC(__raw_writesw)
diff --git a/arch/arm/lib/lib1funcs.S b/arch/arm/lib/lib1funcs.S
index 9397b2e532af..c23f9d9e2970 100644
--- a/arch/arm/lib/lib1funcs.S
+++ b/arch/arm/lib/lib1funcs.S
@@ -96,7 +96,7 @@ Boston, MA 02111-1307, USA. */
96 subhs \dividend, \dividend, \divisor, lsr #3 96 subhs \dividend, \dividend, \divisor, lsr #3
97 orrhs \result, \result, \curbit, lsr #3 97 orrhs \result, \result, \curbit, lsr #3
98 cmp \dividend, #0 @ Early termination? 98 cmp \dividend, #0 @ Early termination?
99 movnes \curbit, \curbit, lsr #4 @ No, any more bits to do? 99 movsne \curbit, \curbit, lsr #4 @ No, any more bits to do?
100 movne \divisor, \divisor, lsr #4 100 movne \divisor, \divisor, lsr #4
101 bne 1b 101 bne 1b
102 102
@@ -182,7 +182,7 @@ Boston, MA 02111-1307, USA. */
182 subhs \dividend, \dividend, \divisor, lsr #3 182 subhs \dividend, \dividend, \divisor, lsr #3
183 cmp \dividend, #1 183 cmp \dividend, #1
184 mov \divisor, \divisor, lsr #4 184 mov \divisor, \divisor, lsr #4
185 subges \order, \order, #4 185 subsge \order, \order, #4
186 bge 1b 186 bge 1b
187 187
188 tst \order, #3 188 tst \order, #3
diff --git a/arch/arm/lib/memcpy.S b/arch/arm/lib/memcpy.S
index 64111bd4440b..4a6997bb4404 100644
--- a/arch/arm/lib/memcpy.S
+++ b/arch/arm/lib/memcpy.S
@@ -30,7 +30,7 @@
30 .endm 30 .endm
31 31
32 .macro ldr1b ptr reg cond=al abort 32 .macro ldr1b ptr reg cond=al abort
33 ldr\cond\()b \reg, [\ptr], #1 33 ldrb\cond \reg, [\ptr], #1
34 .endm 34 .endm
35 35
36 .macro str1w ptr reg abort 36 .macro str1w ptr reg abort
@@ -42,7 +42,7 @@
42 .endm 42 .endm
43 43
44 .macro str1b ptr reg cond=al abort 44 .macro str1b ptr reg cond=al abort
45 str\cond\()b \reg, [\ptr], #1 45 strb\cond \reg, [\ptr], #1
46 .endm 46 .endm
47 47
48 .macro enter reg1 reg2 48 .macro enter reg1 reg2
diff --git a/arch/arm/lib/memmove.S b/arch/arm/lib/memmove.S
index 69a9d47fc5ab..d70304cb2cd0 100644
--- a/arch/arm/lib/memmove.S
+++ b/arch/arm/lib/memmove.S
@@ -59,7 +59,7 @@ ENTRY(memmove)
59 blt 5f 59 blt 5f
60 60
61 CALGN( ands ip, r0, #31 ) 61 CALGN( ands ip, r0, #31 )
62 CALGN( sbcnes r4, ip, r2 ) @ C is always set here 62 CALGN( sbcsne r4, ip, r2 ) @ C is always set here
63 CALGN( bcs 2f ) 63 CALGN( bcs 2f )
64 CALGN( adr r4, 6f ) 64 CALGN( adr r4, 6f )
65 CALGN( subs r2, r2, ip ) @ C is set here 65 CALGN( subs r2, r2, ip ) @ C is set here
@@ -114,20 +114,20 @@ ENTRY(memmove)
114 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block 114 UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
115 115
1168: movs r2, r2, lsl #31 1168: movs r2, r2, lsl #31
117 ldrneb r3, [r1, #-1]! 117 ldrbne r3, [r1, #-1]!
118 ldrcsb r4, [r1, #-1]! 118 ldrbcs r4, [r1, #-1]!
119 ldrcsb ip, [r1, #-1] 119 ldrbcs ip, [r1, #-1]
120 strneb r3, [r0, #-1]! 120 strbne r3, [r0, #-1]!
121 strcsb r4, [r0, #-1]! 121 strbcs r4, [r0, #-1]!
122 strcsb ip, [r0, #-1] 122 strbcs ip, [r0, #-1]
123 ldmfd sp!, {r0, r4, pc} 123 ldmfd sp!, {r0, r4, pc}
124 124
1259: cmp ip, #2 1259: cmp ip, #2
126 ldrgtb r3, [r1, #-1]! 126 ldrbgt r3, [r1, #-1]!
127 ldrgeb r4, [r1, #-1]! 127 ldrbge r4, [r1, #-1]!
128 ldrb lr, [r1, #-1]! 128 ldrb lr, [r1, #-1]!
129 strgtb r3, [r0, #-1]! 129 strbgt r3, [r0, #-1]!
130 strgeb r4, [r0, #-1]! 130 strbge r4, [r0, #-1]!
131 subs r2, r2, ip 131 subs r2, r2, ip
132 strb lr, [r0, #-1]! 132 strb lr, [r0, #-1]!
133 blt 8b 133 blt 8b
@@ -150,7 +150,7 @@ ENTRY(memmove)
150 blt 14f 150 blt 14f
151 151
152 CALGN( ands ip, r0, #31 ) 152 CALGN( ands ip, r0, #31 )
153 CALGN( sbcnes r4, ip, r2 ) @ C is always set here 153 CALGN( sbcsne r4, ip, r2 ) @ C is always set here
154 CALGN( subcc r2, r2, ip ) 154 CALGN( subcc r2, r2, ip )
155 CALGN( bcc 15f ) 155 CALGN( bcc 15f )
156 156
diff --git a/arch/arm/lib/memset.S b/arch/arm/lib/memset.S
index ed6d35d9cdb5..5593a45e0a8c 100644
--- a/arch/arm/lib/memset.S
+++ b/arch/arm/lib/memset.S
@@ -44,20 +44,20 @@ UNWIND( .save {r8, lr} )
44 mov lr, r3 44 mov lr, r3
45 45
462: subs r2, r2, #64 462: subs r2, r2, #64
47 stmgeia ip!, {r1, r3, r8, lr} @ 64 bytes at a time. 47 stmiage ip!, {r1, r3, r8, lr} @ 64 bytes at a time.
48 stmgeia ip!, {r1, r3, r8, lr} 48 stmiage ip!, {r1, r3, r8, lr}
49 stmgeia ip!, {r1, r3, r8, lr} 49 stmiage ip!, {r1, r3, r8, lr}
50 stmgeia ip!, {r1, r3, r8, lr} 50 stmiage ip!, {r1, r3, r8, lr}
51 bgt 2b 51 bgt 2b
52 ldmeqfd sp!, {r8, pc} @ Now <64 bytes to go. 52 ldmfdeq sp!, {r8, pc} @ Now <64 bytes to go.
53/* 53/*
54 * No need to correct the count; we're only testing bits from now on 54 * No need to correct the count; we're only testing bits from now on
55 */ 55 */
56 tst r2, #32 56 tst r2, #32
57 stmneia ip!, {r1, r3, r8, lr} 57 stmiane ip!, {r1, r3, r8, lr}
58 stmneia ip!, {r1, r3, r8, lr} 58 stmiane ip!, {r1, r3, r8, lr}
59 tst r2, #16 59 tst r2, #16
60 stmneia ip!, {r1, r3, r8, lr} 60 stmiane ip!, {r1, r3, r8, lr}
61 ldmfd sp!, {r8, lr} 61 ldmfd sp!, {r8, lr}
62UNWIND( .fnend ) 62UNWIND( .fnend )
63 63
@@ -87,22 +87,22 @@ UNWIND( .save {r4-r8, lr} )
87 rsb r8, r8, #32 87 rsb r8, r8, #32
88 sub r2, r2, r8 88 sub r2, r2, r8
89 movs r8, r8, lsl #(32 - 4) 89 movs r8, r8, lsl #(32 - 4)
90 stmcsia ip!, {r4, r5, r6, r7} 90 stmiacs ip!, {r4, r5, r6, r7}
91 stmmiia ip!, {r4, r5} 91 stmiami ip!, {r4, r5}
92 tst r8, #(1 << 30) 92 tst r8, #(1 << 30)
93 mov r8, r1 93 mov r8, r1
94 strne r1, [ip], #4 94 strne r1, [ip], #4
95 95
963: subs r2, r2, #64 963: subs r2, r2, #64
97 stmgeia ip!, {r1, r3-r8, lr} 97 stmiage ip!, {r1, r3-r8, lr}
98 stmgeia ip!, {r1, r3-r8, lr} 98 stmiage ip!, {r1, r3-r8, lr}
99 bgt 3b 99 bgt 3b
100 ldmeqfd sp!, {r4-r8, pc} 100 ldmfdeq sp!, {r4-r8, pc}
101 101
102 tst r2, #32 102 tst r2, #32
103 stmneia ip!, {r1, r3-r8, lr} 103 stmiane ip!, {r1, r3-r8, lr}
104 tst r2, #16 104 tst r2, #16
105 stmneia ip!, {r4-r7} 105 stmiane ip!, {r4-r7}
106 ldmfd sp!, {r4-r8, lr} 106 ldmfd sp!, {r4-r8, lr}
107UNWIND( .fnend ) 107UNWIND( .fnend )
108 108
@@ -110,7 +110,7 @@ UNWIND( .fnend )
110 110
111UNWIND( .fnstart ) 111UNWIND( .fnstart )
1124: tst r2, #8 1124: tst r2, #8
113 stmneia ip!, {r1, r3} 113 stmiane ip!, {r1, r3}
114 tst r2, #4 114 tst r2, #4
115 strne r1, [ip], #4 115 strne r1, [ip], #4
116/* 116/*
@@ -118,17 +118,17 @@ UNWIND( .fnstart )
118 * may have an unaligned pointer as well. 118 * may have an unaligned pointer as well.
119 */ 119 */
1205: tst r2, #2 1205: tst r2, #2
121 strneb r1, [ip], #1 121 strbne r1, [ip], #1
122 strneb r1, [ip], #1 122 strbne r1, [ip], #1
123 tst r2, #1 123 tst r2, #1
124 strneb r1, [ip], #1 124 strbne r1, [ip], #1
125 ret lr 125 ret lr
126 126
1276: subs r2, r2, #4 @ 1 do we have enough 1276: subs r2, r2, #4 @ 1 do we have enough
128 blt 5b @ 1 bytes to align with? 128 blt 5b @ 1 bytes to align with?
129 cmp r3, #2 @ 1 129 cmp r3, #2 @ 1
130 strltb r1, [ip], #1 @ 1 130 strblt r1, [ip], #1 @ 1
131 strleb r1, [ip], #1 @ 1 131 strble r1, [ip], #1 @ 1
132 strb r1, [ip], #1 @ 1 132 strb r1, [ip], #1 @ 1
133 add r2, r2, r3 @ 1 (r2 = r2 - (4 - r3)) 133 add r2, r2, r3 @ 1 (r2 = r2 - (4 - r3))
134 b 1b 134 b 1b
diff --git a/arch/arm/lib/xor-neon.c b/arch/arm/lib/xor-neon.c
index 2c40aeab3eaa..c691b901092f 100644
--- a/arch/arm/lib/xor-neon.c
+++ b/arch/arm/lib/xor-neon.c
@@ -14,7 +14,7 @@
14MODULE_LICENSE("GPL"); 14MODULE_LICENSE("GPL");
15 15
16#ifndef __ARM_NEON__ 16#ifndef __ARM_NEON__
17#error You should compile this file with '-mfloat-abi=softfp -mfpu=neon' 17#error You should compile this file with '-march=armv7-a -mfloat-abi=softfp -mfpu=neon'
18#endif 18#endif
19 19
20/* 20/*
diff --git a/arch/arm/mach-actions/platsmp.c b/arch/arm/mach-actions/platsmp.c
index 3efaa10efc43..4fd479c948e6 100644
--- a/arch/arm/mach-actions/platsmp.c
+++ b/arch/arm/mach-actions/platsmp.c
@@ -39,10 +39,6 @@ static void __iomem *sps_base_addr;
39static void __iomem *timer_base_addr; 39static void __iomem *timer_base_addr;
40static int ncores; 40static int ncores;
41 41
42static DEFINE_SPINLOCK(boot_lock);
43
44void owl_secondary_startup(void);
45
46static int s500_wakeup_secondary(unsigned int cpu) 42static int s500_wakeup_secondary(unsigned int cpu)
47{ 43{
48 int ret; 44 int ret;
@@ -84,7 +80,6 @@ static int s500_wakeup_secondary(unsigned int cpu)
84 80
85static int s500_smp_boot_secondary(unsigned int cpu, struct task_struct *idle) 81static int s500_smp_boot_secondary(unsigned int cpu, struct task_struct *idle)
86{ 82{
87 unsigned long timeout;
88 int ret; 83 int ret;
89 84
90 ret = s500_wakeup_secondary(cpu); 85 ret = s500_wakeup_secondary(cpu);
@@ -93,21 +88,11 @@ static int s500_smp_boot_secondary(unsigned int cpu, struct task_struct *idle)
93 88
94 udelay(10); 89 udelay(10);
95 90
96 spin_lock(&boot_lock);
97
98 smp_send_reschedule(cpu); 91 smp_send_reschedule(cpu);
99 92
100 timeout = jiffies + (1 * HZ);
101 while (time_before(jiffies, timeout)) {
102 if (pen_release == -1)
103 break;
104 }
105
106 writel(0, timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4); 93 writel(0, timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4);
107 writel(0, timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4); 94 writel(0, timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4);
108 95
109 spin_unlock(&boot_lock);
110
111 return 0; 96 return 0;
112} 97}
113 98
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/arm/mach-exynos/headsmp.S b/arch/arm/mach-exynos/headsmp.S
index 005695c9bf40..0ac2cb9a7355 100644
--- a/arch/arm/mach-exynos/headsmp.S
+++ b/arch/arm/mach-exynos/headsmp.S
@@ -36,4 +36,4 @@ ENDPROC(exynos4_secondary_startup)
36 36
37 .align 2 37 .align 2
381: .long . 381: .long .
39 .long pen_release 39 .long exynos_pen_release
diff --git a/arch/arm/mach-exynos/platsmp.c b/arch/arm/mach-exynos/platsmp.c
index b6da7edbbd2f..abcac6164233 100644
--- a/arch/arm/mach-exynos/platsmp.c
+++ b/arch/arm/mach-exynos/platsmp.c
@@ -28,6 +28,9 @@
28 28
29extern void exynos4_secondary_startup(void); 29extern void exynos4_secondary_startup(void);
30 30
31/* XXX exynos_pen_release is cargo culted code - DO NOT COPY XXX */
32volatile int exynos_pen_release = -1;
33
31#ifdef CONFIG_HOTPLUG_CPU 34#ifdef CONFIG_HOTPLUG_CPU
32static inline void cpu_leave_lowpower(u32 core_id) 35static inline void cpu_leave_lowpower(u32 core_id)
33{ 36{
@@ -57,7 +60,7 @@ static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
57 60
58 wfi(); 61 wfi();
59 62
60 if (pen_release == core_id) { 63 if (exynos_pen_release == core_id) {
61 /* 64 /*
62 * OK, proper wakeup, we're done 65 * OK, proper wakeup, we're done
63 */ 66 */
@@ -228,15 +231,17 @@ void exynos_core_restart(u32 core_id)
228} 231}
229 232
230/* 233/*
231 * Write pen_release in a way that is guaranteed to be visible to all 234 * XXX CARGO CULTED CODE - DO NOT COPY XXX
232 * observers, irrespective of whether they're taking part in coherency 235 *
236 * Write exynos_pen_release in a way that is guaranteed to be visible to
237 * all observers, irrespective of whether they're taking part in coherency
233 * or not. This is necessary for the hotplug code to work reliably. 238 * or not. This is necessary for the hotplug code to work reliably.
234 */ 239 */
235static void write_pen_release(int val) 240static void exynos_write_pen_release(int val)
236{ 241{
237 pen_release = val; 242 exynos_pen_release = val;
238 smp_wmb(); 243 smp_wmb();
239 sync_cache_w(&pen_release); 244 sync_cache_w(&exynos_pen_release);
240} 245}
241 246
242static DEFINE_SPINLOCK(boot_lock); 247static DEFINE_SPINLOCK(boot_lock);
@@ -247,7 +252,7 @@ static void exynos_secondary_init(unsigned int cpu)
247 * let the primary processor know we're out of the 252 * let the primary processor know we're out of the
248 * pen, then head off into the C entry point 253 * pen, then head off into the C entry point
249 */ 254 */
250 write_pen_release(-1); 255 exynos_write_pen_release(-1);
251 256
252 /* 257 /*
253 * Synchronise with the boot thread. 258 * Synchronise with the boot thread.
@@ -322,12 +327,12 @@ static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
322 /* 327 /*
323 * The secondary processor is waiting to be released from 328 * The secondary processor is waiting to be released from
324 * the holding pen - release it, then wait for it to flag 329 * the holding pen - release it, then wait for it to flag
325 * that it has been released by resetting pen_release. 330 * that it has been released by resetting exynos_pen_release.
326 * 331 *
327 * Note that "pen_release" is the hardware CPU core ID, whereas 332 * Note that "exynos_pen_release" is the hardware CPU core ID, whereas
328 * "cpu" is Linux's internal ID. 333 * "cpu" is Linux's internal ID.
329 */ 334 */
330 write_pen_release(core_id); 335 exynos_write_pen_release(core_id);
331 336
332 if (!exynos_cpu_power_state(core_id)) { 337 if (!exynos_cpu_power_state(core_id)) {
333 exynos_cpu_power_up(core_id); 338 exynos_cpu_power_up(core_id);
@@ -376,13 +381,13 @@ static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
376 else 381 else
377 arch_send_wakeup_ipi_mask(cpumask_of(cpu)); 382 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
378 383
379 if (pen_release == -1) 384 if (exynos_pen_release == -1)
380 break; 385 break;
381 386
382 udelay(10); 387 udelay(10);
383 } 388 }
384 389
385 if (pen_release != -1) 390 if (exynos_pen_release != -1)
386 ret = -ETIMEDOUT; 391 ret = -ETIMEDOUT;
387 392
388 /* 393 /*
@@ -392,7 +397,7 @@ static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
392fail: 397fail:
393 spin_unlock(&boot_lock); 398 spin_unlock(&boot_lock);
394 399
395 return pen_release != -1 ? ret : 0; 400 return exynos_pen_release != -1 ? ret : 0;
396} 401}
397 402
398static void __init exynos_smp_prepare_cpus(unsigned int max_cpus) 403static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
diff --git a/arch/arm/mach-ks8695/include/mach/entry-macro.S b/arch/arm/mach-ks8695/include/mach/entry-macro.S
index 8315b34f32ff..7ff812cb010b 100644
--- a/arch/arm/mach-ks8695/include/mach/entry-macro.S
+++ b/arch/arm/mach-ks8695/include/mach/entry-macro.S
@@ -42,6 +42,6 @@
42 moveq \irqstat, \irqstat, lsr #2 42 moveq \irqstat, \irqstat, lsr #2
43 addeq \irqnr, \irqnr, #2 43 addeq \irqnr, \irqnr, #2
44 tst \irqstat, #0x01 44 tst \irqstat, #0x01
45 addeqs \irqnr, \irqnr, #1 45 addseq \irqnr, \irqnr, #1
461001: 461001:
47 .endm 47 .endm
diff --git a/arch/arm/mach-omap2/prm_common.c b/arch/arm/mach-omap2/prm_common.c
index 058a37e6d11c..fd6e0671f957 100644
--- a/arch/arm/mach-omap2/prm_common.c
+++ b/arch/arm/mach-omap2/prm_common.c
@@ -523,8 +523,10 @@ void omap_prm_reset_system(void)
523 523
524 prm_ll_data->reset_system(); 524 prm_ll_data->reset_system();
525 525
526 while (1) 526 while (1) {
527 cpu_relax(); 527 cpu_relax();
528 wfe();
529 }
528} 530}
529 531
530/** 532/**
diff --git a/arch/arm/mach-oxnas/Makefile b/arch/arm/mach-oxnas/Makefile
index b625906a9970..61a34e1c0f22 100644
--- a/arch/arm/mach-oxnas/Makefile
+++ b/arch/arm/mach-oxnas/Makefile
@@ -1,2 +1 @@
1obj-$(CONFIG_SMP) += platsmp.o headsmp.o obj-$(CONFIG_SMP) += platsmp.o headsmp.o
2obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
diff --git a/arch/arm/mach-oxnas/hotplug.c b/arch/arm/mach-oxnas/hotplug.c
deleted file mode 100644
index 854f29b8cba6..000000000000
--- a/arch/arm/mach-oxnas/hotplug.c
+++ /dev/null
@@ -1,109 +0,0 @@
1/*
2 * Copyright (C) 2002 ARM Ltd.
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <linux/kernel.h>
10#include <linux/errno.h>
11#include <linux/smp.h>
12
13#include <asm/cp15.h>
14#include <asm/smp_plat.h>
15
16static inline void cpu_enter_lowpower(void)
17{
18 unsigned int v;
19
20 asm volatile(
21 " mcr p15, 0, %1, c7, c5, 0\n"
22 " mcr p15, 0, %1, c7, c10, 4\n"
23 /*
24 * Turn off coherency
25 */
26 " mrc p15, 0, %0, c1, c0, 1\n"
27 " bic %0, %0, #0x20\n"
28 " mcr p15, 0, %0, c1, c0, 1\n"
29 " mrc p15, 0, %0, c1, c0, 0\n"
30 " bic %0, %0, %2\n"
31 " mcr p15, 0, %0, c1, c0, 0\n"
32 : "=&r" (v)
33 : "r" (0), "Ir" (CR_C)
34 : "cc");
35}
36
37static inline void cpu_leave_lowpower(void)
38{
39 unsigned int v;
40
41 asm volatile( "mrc p15, 0, %0, c1, c0, 0\n"
42 " orr %0, %0, %1\n"
43 " mcr p15, 0, %0, c1, c0, 0\n"
44 " mrc p15, 0, %0, c1, c0, 1\n"
45 " orr %0, %0, #0x20\n"
46 " mcr p15, 0, %0, c1, c0, 1\n"
47 : "=&r" (v)
48 : "Ir" (CR_C)
49 : "cc");
50}
51
52static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
53{
54 /*
55 * there is no power-control hardware on this platform, so all
56 * we can do is put the core into WFI; this is safe as the calling
57 * code will have already disabled interrupts
58 */
59 for (;;) {
60 /*
61 * here's the WFI
62 */
63 asm(".word 0xe320f003\n"
64 :
65 :
66 : "memory", "cc");
67
68 if (pen_release == cpu_logical_map(cpu)) {
69 /*
70 * OK, proper wakeup, we're done
71 */
72 break;
73 }
74
75 /*
76 * Getting here, means that we have come out of WFI without
77 * having been woken up - this shouldn't happen
78 *
79 * Just note it happening - when we're woken, we can report
80 * its occurrence.
81 */
82 (*spurious)++;
83 }
84}
85
86/*
87 * platform-specific code to shutdown a CPU
88 *
89 * Called with IRQs disabled
90 */
91void ox820_cpu_die(unsigned int cpu)
92{
93 int spurious = 0;
94
95 /*
96 * we're ready for shutdown now, so do it
97 */
98 cpu_enter_lowpower();
99 platform_do_lowpower(cpu, &spurious);
100
101 /*
102 * bring this CPU back into the world of cache
103 * coherency, and then restore interrupts
104 */
105 cpu_leave_lowpower();
106
107 if (spurious)
108 pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
109}
diff --git a/arch/arm/mach-oxnas/platsmp.c b/arch/arm/mach-oxnas/platsmp.c
index 442cc8a2f7dc..735141c0e3a3 100644
--- a/arch/arm/mach-oxnas/platsmp.c
+++ b/arch/arm/mach-oxnas/platsmp.c
@@ -19,7 +19,6 @@
19#include <asm/smp_scu.h> 19#include <asm/smp_scu.h>
20 20
21extern void ox820_secondary_startup(void); 21extern void ox820_secondary_startup(void);
22extern void ox820_cpu_die(unsigned int cpu);
23 22
24static void __iomem *cpu_ctrl; 23static void __iomem *cpu_ctrl;
25static void __iomem *gic_cpu_ctrl; 24static void __iomem *gic_cpu_ctrl;
@@ -94,9 +93,6 @@ unmap_scu:
94static const struct smp_operations ox820_smp_ops __initconst = { 93static const struct smp_operations ox820_smp_ops __initconst = {
95 .smp_prepare_cpus = ox820_smp_prepare_cpus, 94 .smp_prepare_cpus = ox820_smp_prepare_cpus,
96 .smp_boot_secondary = ox820_boot_secondary, 95 .smp_boot_secondary = ox820_boot_secondary,
97#ifdef CONFIG_HOTPLUG_CPU
98 .cpu_die = ox820_cpu_die,
99#endif
100}; 96};
101 97
102CPU_METHOD_OF_DECLARE(ox820_smp, "oxsemi,ox820-smp", &ox820_smp_ops); 98CPU_METHOD_OF_DECLARE(ox820_smp, "oxsemi,ox820-smp", &ox820_smp_ops);
diff --git a/arch/arm/mach-prima2/common.h b/arch/arm/mach-prima2/common.h
index 6d77b622d168..457eb7b18160 100644
--- a/arch/arm/mach-prima2/common.h
+++ b/arch/arm/mach-prima2/common.h
@@ -15,6 +15,8 @@
15#include <asm/mach/time.h> 15#include <asm/mach/time.h>
16#include <asm/exception.h> 16#include <asm/exception.h>
17 17
18extern volatile int prima2_pen_release;
19
18extern const struct smp_operations sirfsoc_smp_ops; 20extern const struct smp_operations sirfsoc_smp_ops;
19extern void sirfsoc_secondary_startup(void); 21extern void sirfsoc_secondary_startup(void);
20extern void sirfsoc_cpu_die(unsigned int cpu); 22extern void sirfsoc_cpu_die(unsigned int cpu);
diff --git a/arch/arm/mach-prima2/headsmp.S b/arch/arm/mach-prima2/headsmp.S
index 209d9fc5c16c..6cf4fc60347b 100644
--- a/arch/arm/mach-prima2/headsmp.S
+++ b/arch/arm/mach-prima2/headsmp.S
@@ -34,4 +34,4 @@ ENDPROC(sirfsoc_secondary_startup)
34 34
35 .align 35 .align
361: .long . 361: .long .
37 .long pen_release 37 .long prima2_pen_release
diff --git a/arch/arm/mach-prima2/hotplug.c b/arch/arm/mach-prima2/hotplug.c
index a728c78b996f..b6cf1527e330 100644
--- a/arch/arm/mach-prima2/hotplug.c
+++ b/arch/arm/mach-prima2/hotplug.c
@@ -11,6 +11,7 @@
11#include <linux/smp.h> 11#include <linux/smp.h>
12 12
13#include <asm/smp_plat.h> 13#include <asm/smp_plat.h>
14#include "common.h"
14 15
15static inline void platform_do_lowpower(unsigned int cpu) 16static inline void platform_do_lowpower(unsigned int cpu)
16{ 17{
@@ -18,7 +19,7 @@ static inline void platform_do_lowpower(unsigned int cpu)
18 for (;;) { 19 for (;;) {
19 __asm__ __volatile__("dsb\n\t" "wfi\n\t" 20 __asm__ __volatile__("dsb\n\t" "wfi\n\t"
20 : : : "memory"); 21 : : : "memory");
21 if (pen_release == cpu_logical_map(cpu)) { 22 if (prima2_pen_release == cpu_logical_map(cpu)) {
22 /* 23 /*
23 * OK, proper wakeup, we're done 24 * OK, proper wakeup, we're done
24 */ 25 */
diff --git a/arch/arm/mach-prima2/platsmp.c b/arch/arm/mach-prima2/platsmp.c
index 75ef5d4be554..d1f8b5168083 100644
--- a/arch/arm/mach-prima2/platsmp.c
+++ b/arch/arm/mach-prima2/platsmp.c
@@ -24,13 +24,16 @@ static void __iomem *clk_base;
24 24
25static DEFINE_SPINLOCK(boot_lock); 25static DEFINE_SPINLOCK(boot_lock);
26 26
27/* XXX prima2_pen_release is cargo culted code - DO NOT COPY XXX */
28volatile int prima2_pen_release = -1;
29
27static void sirfsoc_secondary_init(unsigned int cpu) 30static void sirfsoc_secondary_init(unsigned int cpu)
28{ 31{
29 /* 32 /*
30 * let the primary processor know we're out of the 33 * let the primary processor know we're out of the
31 * pen, then head off into the C entry point 34 * pen, then head off into the C entry point
32 */ 35 */
33 pen_release = -1; 36 prima2_pen_release = -1;
34 smp_wmb(); 37 smp_wmb();
35 38
36 /* 39 /*
@@ -80,13 +83,13 @@ static int sirfsoc_boot_secondary(unsigned int cpu, struct task_struct *idle)
80 /* 83 /*
81 * The secondary processor is waiting to be released from 84 * The secondary processor is waiting to be released from
82 * the holding pen - release it, then wait for it to flag 85 * the holding pen - release it, then wait for it to flag
83 * that it has been released by resetting pen_release. 86 * that it has been released by resetting prima2_pen_release.
84 * 87 *
85 * Note that "pen_release" is the hardware CPU ID, whereas 88 * Note that "prima2_pen_release" is the hardware CPU ID, whereas
86 * "cpu" is Linux's internal ID. 89 * "cpu" is Linux's internal ID.
87 */ 90 */
88 pen_release = cpu_logical_map(cpu); 91 prima2_pen_release = cpu_logical_map(cpu);
89 sync_cache_w(&pen_release); 92 sync_cache_w(&prima2_pen_release);
90 93
91 /* 94 /*
92 * Send the secondary CPU SEV, thereby causing the boot monitor to read 95 * Send the secondary CPU SEV, thereby causing the boot monitor to read
@@ -97,7 +100,7 @@ static int sirfsoc_boot_secondary(unsigned int cpu, struct task_struct *idle)
97 timeout = jiffies + (1 * HZ); 100 timeout = jiffies + (1 * HZ);
98 while (time_before(jiffies, timeout)) { 101 while (time_before(jiffies, timeout)) {
99 smp_rmb(); 102 smp_rmb();
100 if (pen_release == -1) 103 if (prima2_pen_release == -1)
101 break; 104 break;
102 105
103 udelay(10); 106 udelay(10);
@@ -109,7 +112,7 @@ static int sirfsoc_boot_secondary(unsigned int cpu, struct task_struct *idle)
109 */ 112 */
110 spin_unlock(&boot_lock); 113 spin_unlock(&boot_lock);
111 114
112 return pen_release != -1 ? -ENOSYS : 0; 115 return prima2_pen_release != -1 ? -ENOSYS : 0;
113} 116}
114 117
115const struct smp_operations sirfsoc_smp_ops __initconst = { 118const struct smp_operations sirfsoc_smp_ops __initconst = {
diff --git a/arch/arm/mach-qcom/platsmp.c b/arch/arm/mach-qcom/platsmp.c
index 5494c9e0c909..99a6a5e809e0 100644
--- a/arch/arm/mach-qcom/platsmp.c
+++ b/arch/arm/mach-qcom/platsmp.c
@@ -46,8 +46,6 @@
46 46
47extern void secondary_startup_arm(void); 47extern void secondary_startup_arm(void);
48 48
49static DEFINE_SPINLOCK(boot_lock);
50
51#ifdef CONFIG_HOTPLUG_CPU 49#ifdef CONFIG_HOTPLUG_CPU
52static void qcom_cpu_die(unsigned int cpu) 50static void qcom_cpu_die(unsigned int cpu)
53{ 51{
@@ -55,15 +53,6 @@ static void qcom_cpu_die(unsigned int cpu)
55} 53}
56#endif 54#endif
57 55
58static void qcom_secondary_init(unsigned int cpu)
59{
60 /*
61 * Synchronise with the boot thread.
62 */
63 spin_lock(&boot_lock);
64 spin_unlock(&boot_lock);
65}
66
67static int scss_release_secondary(unsigned int cpu) 56static int scss_release_secondary(unsigned int cpu)
68{ 57{
69 struct device_node *node; 58 struct device_node *node;
@@ -281,24 +270,12 @@ static int qcom_boot_secondary(unsigned int cpu, int (*func)(unsigned int))
281 } 270 }
282 271
283 /* 272 /*
284 * set synchronisation state between this boot processor
285 * and the secondary one
286 */
287 spin_lock(&boot_lock);
288
289 /*
290 * Send the secondary CPU a soft interrupt, thereby causing 273 * Send the secondary CPU a soft interrupt, thereby causing
291 * the boot monitor to read the system wide flags register, 274 * the boot monitor to read the system wide flags register,
292 * and branch to the address found there. 275 * and branch to the address found there.
293 */ 276 */
294 arch_send_wakeup_ipi_mask(cpumask_of(cpu)); 277 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
295 278
296 /*
297 * now the secondary core is starting up let it run its
298 * calibrations, then wait for it to finish
299 */
300 spin_unlock(&boot_lock);
301
302 return ret; 279 return ret;
303} 280}
304 281
@@ -334,7 +311,6 @@ static void __init qcom_smp_prepare_cpus(unsigned int max_cpus)
334 311
335static const struct smp_operations smp_msm8660_ops __initconst = { 312static const struct smp_operations smp_msm8660_ops __initconst = {
336 .smp_prepare_cpus = qcom_smp_prepare_cpus, 313 .smp_prepare_cpus = qcom_smp_prepare_cpus,
337 .smp_secondary_init = qcom_secondary_init,
338 .smp_boot_secondary = msm8660_boot_secondary, 314 .smp_boot_secondary = msm8660_boot_secondary,
339#ifdef CONFIG_HOTPLUG_CPU 315#ifdef CONFIG_HOTPLUG_CPU
340 .cpu_die = qcom_cpu_die, 316 .cpu_die = qcom_cpu_die,
@@ -344,7 +320,6 @@ CPU_METHOD_OF_DECLARE(qcom_smp, "qcom,gcc-msm8660", &smp_msm8660_ops);
344 320
345static const struct smp_operations qcom_smp_kpssv1_ops __initconst = { 321static const struct smp_operations qcom_smp_kpssv1_ops __initconst = {
346 .smp_prepare_cpus = qcom_smp_prepare_cpus, 322 .smp_prepare_cpus = qcom_smp_prepare_cpus,
347 .smp_secondary_init = qcom_secondary_init,
348 .smp_boot_secondary = kpssv1_boot_secondary, 323 .smp_boot_secondary = kpssv1_boot_secondary,
349#ifdef CONFIG_HOTPLUG_CPU 324#ifdef CONFIG_HOTPLUG_CPU
350 .cpu_die = qcom_cpu_die, 325 .cpu_die = qcom_cpu_die,
@@ -354,7 +329,6 @@ CPU_METHOD_OF_DECLARE(qcom_smp_kpssv1, "qcom,kpss-acc-v1", &qcom_smp_kpssv1_ops)
354 329
355static const struct smp_operations qcom_smp_kpssv2_ops __initconst = { 330static const struct smp_operations qcom_smp_kpssv2_ops __initconst = {
356 .smp_prepare_cpus = qcom_smp_prepare_cpus, 331 .smp_prepare_cpus = qcom_smp_prepare_cpus,
357 .smp_secondary_init = qcom_secondary_init,
358 .smp_boot_secondary = kpssv2_boot_secondary, 332 .smp_boot_secondary = kpssv2_boot_secondary,
359#ifdef CONFIG_HOTPLUG_CPU 333#ifdef CONFIG_HOTPLUG_CPU
360 .cpu_die = qcom_cpu_die, 334 .cpu_die = qcom_cpu_die,
diff --git a/arch/arm/mach-spear/generic.h b/arch/arm/mach-spear/generic.h
index 909b97c0b237..25b4c5e66e39 100644
--- a/arch/arm/mach-spear/generic.h
+++ b/arch/arm/mach-spear/generic.h
@@ -20,6 +20,8 @@
20 20
21#include <asm/mach/time.h> 21#include <asm/mach/time.h>
22 22
23extern volatile int spear_pen_release;
24
23extern void spear13xx_timer_init(void); 25extern void spear13xx_timer_init(void);
24extern void spear3xx_timer_init(void); 26extern void spear3xx_timer_init(void);
25extern struct pl022_ssp_controller pl022_plat_data; 27extern struct pl022_ssp_controller pl022_plat_data;
diff --git a/arch/arm/mach-spear/headsmp.S b/arch/arm/mach-spear/headsmp.S
index c52192dc3d9f..6e250b6c0aa2 100644
--- a/arch/arm/mach-spear/headsmp.S
+++ b/arch/arm/mach-spear/headsmp.S
@@ -43,5 +43,5 @@ pen: ldr r7, [r6]
43 43
44 .align 44 .align
451: .long . 451: .long .
46 .long pen_release 46 .long spear_pen_release
47ENDPROC(spear13xx_secondary_startup) 47ENDPROC(spear13xx_secondary_startup)
diff --git a/arch/arm/mach-spear/hotplug.c b/arch/arm/mach-spear/hotplug.c
index 12edd1cf8a12..0dd84f609627 100644
--- a/arch/arm/mach-spear/hotplug.c
+++ b/arch/arm/mach-spear/hotplug.c
@@ -16,6 +16,8 @@
16#include <asm/cp15.h> 16#include <asm/cp15.h>
17#include <asm/smp_plat.h> 17#include <asm/smp_plat.h>
18 18
19#include "generic.h"
20
19static inline void cpu_enter_lowpower(void) 21static inline void cpu_enter_lowpower(void)
20{ 22{
21 unsigned int v; 23 unsigned int v;
@@ -57,7 +59,7 @@ static inline void spear13xx_do_lowpower(unsigned int cpu, int *spurious)
57 for (;;) { 59 for (;;) {
58 wfi(); 60 wfi();
59 61
60 if (pen_release == cpu) { 62 if (spear_pen_release == cpu) {
61 /* 63 /*
62 * OK, proper wakeup, we're done 64 * OK, proper wakeup, we're done
63 */ 65 */
diff --git a/arch/arm/mach-spear/platsmp.c b/arch/arm/mach-spear/platsmp.c
index 39038a03836a..b1ff4bb86f6d 100644
--- a/arch/arm/mach-spear/platsmp.c
+++ b/arch/arm/mach-spear/platsmp.c
@@ -20,16 +20,21 @@
20#include <mach/spear.h> 20#include <mach/spear.h>
21#include "generic.h" 21#include "generic.h"
22 22
23/* XXX spear_pen_release is cargo culted code - DO NOT COPY XXX */
24volatile int spear_pen_release = -1;
25
23/* 26/*
24 * Write pen_release in a way that is guaranteed to be visible to all 27 * XXX CARGO CULTED CODE - DO NOT COPY XXX
25 * observers, irrespective of whether they're taking part in coherency 28 *
29 * Write spear_pen_release in a way that is guaranteed to be visible to
30 * all observers, irrespective of whether they're taking part in coherency
26 * or not. This is necessary for the hotplug code to work reliably. 31 * or not. This is necessary for the hotplug code to work reliably.
27 */ 32 */
28static void write_pen_release(int val) 33static void spear_write_pen_release(int val)
29{ 34{
30 pen_release = val; 35 spear_pen_release = val;
31 smp_wmb(); 36 smp_wmb();
32 sync_cache_w(&pen_release); 37 sync_cache_w(&spear_pen_release);
33} 38}
34 39
35static DEFINE_SPINLOCK(boot_lock); 40static DEFINE_SPINLOCK(boot_lock);
@@ -42,7 +47,7 @@ static void spear13xx_secondary_init(unsigned int cpu)
42 * let the primary processor know we're out of the 47 * let the primary processor know we're out of the
43 * pen, then head off into the C entry point 48 * pen, then head off into the C entry point
44 */ 49 */
45 write_pen_release(-1); 50 spear_write_pen_release(-1);
46 51
47 /* 52 /*
48 * Synchronise with the boot thread. 53 * Synchronise with the boot thread.
@@ -64,17 +69,17 @@ static int spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
64 /* 69 /*
65 * The secondary processor is waiting to be released from 70 * The secondary processor is waiting to be released from
66 * the holding pen - release it, then wait for it to flag 71 * the holding pen - release it, then wait for it to flag
67 * that it has been released by resetting pen_release. 72 * that it has been released by resetting spear_pen_release.
68 * 73 *
69 * Note that "pen_release" is the hardware CPU ID, whereas 74 * Note that "spear_pen_release" is the hardware CPU ID, whereas
70 * "cpu" is Linux's internal ID. 75 * "cpu" is Linux's internal ID.
71 */ 76 */
72 write_pen_release(cpu); 77 spear_write_pen_release(cpu);
73 78
74 timeout = jiffies + (1 * HZ); 79 timeout = jiffies + (1 * HZ);
75 while (time_before(jiffies, timeout)) { 80 while (time_before(jiffies, timeout)) {
76 smp_rmb(); 81 smp_rmb();
77 if (pen_release == -1) 82 if (spear_pen_release == -1)
78 break; 83 break;
79 84
80 udelay(10); 85 udelay(10);
@@ -86,7 +91,7 @@ static int spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
86 */ 91 */
87 spin_unlock(&boot_lock); 92 spin_unlock(&boot_lock);
88 93
89 return pen_release != -1 ? -ENOSYS : 0; 94 return spear_pen_release != -1 ? -ENOSYS : 0;
90} 95}
91 96
92/* 97/*
diff --git a/arch/arm/mach-tegra/reset-handler.S b/arch/arm/mach-tegra/reset-handler.S
index 805f306fa6f7..e22ccf87eded 100644
--- a/arch/arm/mach-tegra/reset-handler.S
+++ b/arch/arm/mach-tegra/reset-handler.S
@@ -172,7 +172,7 @@ after_errata:
172 mov32 r5, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET 172 mov32 r5, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET
173 mov r0, #CPU_NOT_RESETTABLE 173 mov r0, #CPU_NOT_RESETTABLE
174 cmp r10, #0 174 cmp r10, #0
175 strneb r0, [r5, #__tegra20_cpu1_resettable_status_offset] 175 strbne r0, [r5, #__tegra20_cpu1_resettable_status_offset]
1761: 1761:
177#endif 177#endif
178 178
diff --git a/arch/arm/mm/cache-v6.S b/arch/arm/mm/cache-v6.S
index 24659952c278..be68d62566c7 100644
--- a/arch/arm/mm/cache-v6.S
+++ b/arch/arm/mm/cache-v6.S
@@ -215,8 +215,8 @@ v6_dma_inv_range:
215#endif 215#endif
216 tst r1, #D_CACHE_LINE_SIZE - 1 216 tst r1, #D_CACHE_LINE_SIZE - 1
217#ifdef CONFIG_DMA_CACHE_RWFO 217#ifdef CONFIG_DMA_CACHE_RWFO
218 ldrneb r2, [r1, #-1] @ read for ownership 218 ldrbne r2, [r1, #-1] @ read for ownership
219 strneb r2, [r1, #-1] @ write for ownership 219 strbne r2, [r1, #-1] @ write for ownership
220#endif 220#endif
221 bic r1, r1, #D_CACHE_LINE_SIZE - 1 221 bic r1, r1, #D_CACHE_LINE_SIZE - 1
222#ifdef HARVARD_CACHE 222#ifdef HARVARD_CACHE
@@ -284,8 +284,8 @@ ENTRY(v6_dma_flush_range)
284 add r0, r0, #D_CACHE_LINE_SIZE 284 add r0, r0, #D_CACHE_LINE_SIZE
285 cmp r0, r1 285 cmp r0, r1
286#ifdef CONFIG_DMA_CACHE_RWFO 286#ifdef CONFIG_DMA_CACHE_RWFO
287 ldrlob r2, [r0] @ read for ownership 287 ldrblo r2, [r0] @ read for ownership
288 strlob r2, [r0] @ write for ownership 288 strblo r2, [r0] @ write for ownership
289#endif 289#endif
290 blo 1b 290 blo 1b
291 mov r0, #0 291 mov r0, #0
diff --git a/arch/arm/mm/copypage-v4mc.c b/arch/arm/mm/copypage-v4mc.c
index b03202cddddb..f74cdce6d4da 100644
--- a/arch/arm/mm/copypage-v4mc.c
+++ b/arch/arm/mm/copypage-v4mc.c
@@ -45,6 +45,7 @@ static void mc_copy_user_page(void *from, void *to)
45 int tmp; 45 int tmp;
46 46
47 asm volatile ("\ 47 asm volatile ("\
48 .syntax unified\n\
48 ldmia %0!, {r2, r3, ip, lr} @ 4\n\ 49 ldmia %0!, {r2, r3, ip, lr} @ 4\n\
491: mcr p15, 0, %1, c7, c6, 1 @ 1 invalidate D line\n\ 501: mcr p15, 0, %1, c7, c6, 1 @ 1 invalidate D line\n\
50 stmia %1!, {r2, r3, ip, lr} @ 4\n\ 51 stmia %1!, {r2, r3, ip, lr} @ 4\n\
@@ -56,7 +57,7 @@ static void mc_copy_user_page(void *from, void *to)
56 ldmia %0!, {r2, r3, ip, lr} @ 4\n\ 57 ldmia %0!, {r2, r3, ip, lr} @ 4\n\
57 subs %2, %2, #1 @ 1\n\ 58 subs %2, %2, #1 @ 1\n\
58 stmia %1!, {r2, r3, ip, lr} @ 4\n\ 59 stmia %1!, {r2, r3, ip, lr} @ 4\n\
59 ldmneia %0!, {r2, r3, ip, lr} @ 4\n\ 60 ldmiane %0!, {r2, r3, ip, lr} @ 4\n\
60 bne 1b @ " 61 bne 1b @ "
61 : "+&r" (from), "+&r" (to), "=&r" (tmp) 62 : "+&r" (from), "+&r" (to), "=&r" (tmp)
62 : "2" (PAGE_SIZE / 64) 63 : "2" (PAGE_SIZE / 64)
diff --git a/arch/arm/mm/copypage-v4wb.c b/arch/arm/mm/copypage-v4wb.c
index cd3e165afeed..6d336740aae4 100644
--- a/arch/arm/mm/copypage-v4wb.c
+++ b/arch/arm/mm/copypage-v4wb.c
@@ -27,6 +27,7 @@ static void v4wb_copy_user_page(void *kto, const void *kfrom)
27 int tmp; 27 int tmp;
28 28
29 asm volatile ("\ 29 asm volatile ("\
30 .syntax unified\n\
30 ldmia %1!, {r3, r4, ip, lr} @ 4\n\ 31 ldmia %1!, {r3, r4, ip, lr} @ 4\n\
311: mcr p15, 0, %0, c7, c6, 1 @ 1 invalidate D line\n\ 321: mcr p15, 0, %0, c7, c6, 1 @ 1 invalidate D line\n\
32 stmia %0!, {r3, r4, ip, lr} @ 4\n\ 33 stmia %0!, {r3, r4, ip, lr} @ 4\n\
@@ -38,7 +39,7 @@ static void v4wb_copy_user_page(void *kto, const void *kfrom)
38 ldmia %1!, {r3, r4, ip, lr} @ 4\n\ 39 ldmia %1!, {r3, r4, ip, lr} @ 4\n\
39 subs %2, %2, #1 @ 1\n\ 40 subs %2, %2, #1 @ 1\n\
40 stmia %0!, {r3, r4, ip, lr} @ 4\n\ 41 stmia %0!, {r3, r4, ip, lr} @ 4\n\
41 ldmneia %1!, {r3, r4, ip, lr} @ 4\n\ 42 ldmiane %1!, {r3, r4, ip, lr} @ 4\n\
42 bne 1b @ 1\n\ 43 bne 1b @ 1\n\
43 mcr p15, 0, %1, c7, c10, 4 @ 1 drain WB" 44 mcr p15, 0, %1, c7, c10, 4 @ 1 drain WB"
44 : "+&r" (kto), "+&r" (kfrom), "=&r" (tmp) 45 : "+&r" (kto), "+&r" (kfrom), "=&r" (tmp)
diff --git a/arch/arm/mm/copypage-v4wt.c b/arch/arm/mm/copypage-v4wt.c
index 8614572e1296..3851bb396442 100644
--- a/arch/arm/mm/copypage-v4wt.c
+++ b/arch/arm/mm/copypage-v4wt.c
@@ -25,6 +25,7 @@ static void v4wt_copy_user_page(void *kto, const void *kfrom)
25 int tmp; 25 int tmp;
26 26
27 asm volatile ("\ 27 asm volatile ("\
28 .syntax unified\n\
28 ldmia %1!, {r3, r4, ip, lr} @ 4\n\ 29 ldmia %1!, {r3, r4, ip, lr} @ 4\n\
291: stmia %0!, {r3, r4, ip, lr} @ 4\n\ 301: stmia %0!, {r3, r4, ip, lr} @ 4\n\
30 ldmia %1!, {r3, r4, ip, lr} @ 4+1\n\ 31 ldmia %1!, {r3, r4, ip, lr} @ 4+1\n\
@@ -34,7 +35,7 @@ static void v4wt_copy_user_page(void *kto, const void *kfrom)
34 ldmia %1!, {r3, r4, ip, lr} @ 4\n\ 35 ldmia %1!, {r3, r4, ip, lr} @ 4\n\
35 subs %2, %2, #1 @ 1\n\ 36 subs %2, %2, #1 @ 1\n\
36 stmia %0!, {r3, r4, ip, lr} @ 4\n\ 37 stmia %0!, {r3, r4, ip, lr} @ 4\n\
37 ldmneia %1!, {r3, r4, ip, lr} @ 4\n\ 38 ldmiane %1!, {r3, r4, ip, lr} @ 4\n\
38 bne 1b @ 1\n\ 39 bne 1b @ 1\n\
39 mcr p15, 0, %2, c7, c7, 0 @ flush ID cache" 40 mcr p15, 0, %2, c7, c7, 0 @ flush ID cache"
40 : "+&r" (kto), "+&r" (kfrom), "=&r" (tmp) 41 : "+&r" (kto), "+&r" (kfrom), "=&r" (tmp)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c6aab9c36ff1..43f46aa7ef33 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -2279,7 +2279,7 @@ EXPORT_SYMBOL_GPL(arm_iommu_attach_device);
2279 * @dev: valid struct device pointer 2279 * @dev: valid struct device pointer
2280 * 2280 *
2281 * Detaches the provided device from a previously attached map. 2281 * Detaches the provided device from a previously attached map.
2282 * This voids the dma operations (dma_map_ops pointer) 2282 * This overwrites the dma_ops pointer with appropriate non-IOMMU ops.
2283 */ 2283 */
2284void arm_iommu_detach_device(struct device *dev) 2284void arm_iommu_detach_device(struct device *dev)
2285{ 2285{
diff --git a/arch/arm/mm/idmap.c b/arch/arm/mm/idmap.c
index 1d1edd064199..a033f6134a64 100644
--- a/arch/arm/mm/idmap.c
+++ b/arch/arm/mm/idmap.c
@@ -6,6 +6,7 @@
6 6
7#include <asm/cputype.h> 7#include <asm/cputype.h>
8#include <asm/idmap.h> 8#include <asm/idmap.h>
9#include <asm/hwcap.h>
9#include <asm/pgalloc.h> 10#include <asm/pgalloc.h>
10#include <asm/pgtable.h> 11#include <asm/pgtable.h>
11#include <asm/sections.h> 12#include <asm/sections.h>
@@ -110,7 +111,8 @@ static int __init init_static_idmap(void)
110 __idmap_text_end, 0); 111 __idmap_text_end, 0);
111 112
112 /* Flush L1 for the hardware to see this page table content */ 113 /* Flush L1 for the hardware to see this page table content */
113 flush_cache_louis(); 114 if (!(elf_hwcap & HWCAP_LPAE))
115 flush_cache_louis();
114 116
115 return 0; 117 return 0;
116} 118}
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 15dddfe43319..c2daabbe0af0 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -282,15 +282,12 @@ void __init arm_memblock_init(const struct machine_desc *mdesc)
282 282
283void __init bootmem_init(void) 283void __init bootmem_init(void)
284{ 284{
285 unsigned long min, max_low, max_high;
286
287 memblock_allow_resize(); 285 memblock_allow_resize();
288 max_low = max_high = 0;
289 286
290 find_limits(&min, &max_low, &max_high); 287 find_limits(&min_low_pfn, &max_low_pfn, &max_pfn);
291 288
292 early_memtest((phys_addr_t)min << PAGE_SHIFT, 289 early_memtest((phys_addr_t)min_low_pfn << PAGE_SHIFT,
293 (phys_addr_t)max_low << PAGE_SHIFT); 290 (phys_addr_t)max_low_pfn << PAGE_SHIFT);
294 291
295 /* 292 /*
296 * Sparsemem tries to allocate bootmem in memory_present(), 293 * Sparsemem tries to allocate bootmem in memory_present(),
@@ -308,16 +305,7 @@ void __init bootmem_init(void)
308 * the sparse mem_map arrays initialized by sparse_init() 305 * the sparse mem_map arrays initialized by sparse_init()
309 * for memmap_init_zone(), otherwise all PFNs are invalid. 306 * for memmap_init_zone(), otherwise all PFNs are invalid.
310 */ 307 */
311 zone_sizes_init(min, max_low, max_high); 308 zone_sizes_init(min_low_pfn, max_low_pfn, max_pfn);
312
313 /*
314 * This doesn't seem to be used by the Linux memory manager any
315 * more, but is used by ll_rw_block. If we can get rid of it, we
316 * also get rid of some of the stuff above as well.
317 */
318 min_low_pfn = min;
319 max_low_pfn = max_low;
320 max_pfn = max_high;
321} 309}
322 310
323/* 311/*
@@ -498,55 +486,6 @@ void __init mem_init(void)
498 486
499 mem_init_print_info(NULL); 487 mem_init_print_info(NULL);
500 488
501#define MLK(b, t) b, t, ((t) - (b)) >> 10
502#define MLM(b, t) b, t, ((t) - (b)) >> 20
503#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
504
505 pr_notice("Virtual kernel memory layout:\n"
506 " vector : 0x%08lx - 0x%08lx (%4ld kB)\n"
507#ifdef CONFIG_HAVE_TCM
508 " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
509 " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
510#endif
511 " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
512 " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
513 " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
514#ifdef CONFIG_HIGHMEM
515 " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
516#endif
517#ifdef CONFIG_MODULES
518 " modules : 0x%08lx - 0x%08lx (%4ld MB)\n"
519#endif
520 " .text : 0x%p" " - 0x%p" " (%4td kB)\n"
521 " .init : 0x%p" " - 0x%p" " (%4td kB)\n"
522 " .data : 0x%p" " - 0x%p" " (%4td kB)\n"
523 " .bss : 0x%p" " - 0x%p" " (%4td kB)\n",
524
525 MLK(VECTORS_BASE, VECTORS_BASE + PAGE_SIZE),
526#ifdef CONFIG_HAVE_TCM
527 MLK(DTCM_OFFSET, (unsigned long) dtcm_end),
528 MLK(ITCM_OFFSET, (unsigned long) itcm_end),
529#endif
530 MLK(FIXADDR_START, FIXADDR_END),
531 MLM(VMALLOC_START, VMALLOC_END),
532 MLM(PAGE_OFFSET, (unsigned long)high_memory),
533#ifdef CONFIG_HIGHMEM
534 MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) *
535 (PAGE_SIZE)),
536#endif
537#ifdef CONFIG_MODULES
538 MLM(MODULES_VADDR, MODULES_END),
539#endif
540
541 MLK_ROUNDUP(_text, _etext),
542 MLK_ROUNDUP(__init_begin, __init_end),
543 MLK_ROUNDUP(_sdata, _edata),
544 MLK_ROUNDUP(__bss_start, __bss_stop));
545
546#undef MLK
547#undef MLM
548#undef MLK_ROUNDUP
549
550 /* 489 /*
551 * Check boundaries twice: Some fundamental inconsistencies can 490 * Check boundaries twice: Some fundamental inconsistencies can
552 * be detected at build time already. 491 * be detected at build time already.
diff --git a/arch/arm/mm/pmsa-v8.c b/arch/arm/mm/pmsa-v8.c
index 617a83def88a..0d7d5fb59247 100644
--- a/arch/arm/mm/pmsa-v8.c
+++ b/arch/arm/mm/pmsa-v8.c
@@ -165,7 +165,7 @@ static int __init pmsav8_setup_ram(unsigned int number, phys_addr_t start,phys_a
165 return -EINVAL; 165 return -EINVAL;
166 166
167 bar = start; 167 bar = start;
168 lar = (end - 1) & ~(PMSAv8_MINALIGN - 1);; 168 lar = (end - 1) & ~(PMSAv8_MINALIGN - 1);
169 169
170 bar |= PMSAv8_AP_PL1RW_PL0RW | PMSAv8_RGN_SHARED; 170 bar |= PMSAv8_AP_PL1RW_PL0RW | PMSAv8_RGN_SHARED;
171 lar |= PMSAv8_LAR_IDX(PMSAv8_RGN_NORMAL) | PMSAv8_LAR_EN; 171 lar |= PMSAv8_LAR_IDX(PMSAv8_RGN_NORMAL) | PMSAv8_LAR_EN;
@@ -181,7 +181,7 @@ static int __init pmsav8_setup_io(unsigned int number, phys_addr_t start,phys_ad
181 return -EINVAL; 181 return -EINVAL;
182 182
183 bar = start; 183 bar = start;
184 lar = (end - 1) & ~(PMSAv8_MINALIGN - 1);; 184 lar = (end - 1) & ~(PMSAv8_MINALIGN - 1);
185 185
186 bar |= PMSAv8_AP_PL1RW_PL0RW | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN; 186 bar |= PMSAv8_AP_PL1RW_PL0RW | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN;
187 lar |= PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN; 187 lar |= PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN;
diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S
index 47a5acc64433..acd5a66dfc23 100644
--- a/arch/arm/mm/proc-v7m.S
+++ b/arch/arm/mm/proc-v7m.S
@@ -139,6 +139,9 @@ __v7m_setup_cont:
139 cpsie i 139 cpsie i
140 svc #0 140 svc #0
1411: cpsid i 1411: cpsid i
142 ldr r0, =exc_ret
143 orr lr, lr, #EXC_RET_THREADMODE_PROCESSSTACK
144 str lr, [r0]
142 ldmia sp, {r0-r3, r12} 145 ldmia sp, {r0-r3, r12}
143 str r5, [r12, #11 * 4] @ restore the original SVC vector entry 146 str r5, [r12, #11 * 4] @ restore the original SVC vector entry
144 mov lr, r6 @ restore LR 147 mov lr, r6 @ restore LR
@@ -149,10 +152,10 @@ __v7m_setup_cont:
149 152
150 @ Configure caches (if implemented) 153 @ Configure caches (if implemented)
151 teq r8, #0 154 teq r8, #0
152 stmneia sp, {r0-r6, lr} @ v7m_invalidate_l1 touches r0-r6 155 stmiane sp, {r0-r6, lr} @ v7m_invalidate_l1 touches r0-r6
153 blne v7m_invalidate_l1 156 blne v7m_invalidate_l1
154 teq r8, #0 @ re-evalutae condition 157 teq r8, #0 @ re-evalutae condition
155 ldmneia sp, {r0-r6, lr} 158 ldmiane sp, {r0-r6, lr}
156 159
157 @ Configure the System Control Register to ensure 8-byte stack alignment 160 @ Configure the System Control Register to ensure 8-byte stack alignment
158 @ Note the STKALIGN bit is either RW or RAO. 161 @ Note the STKALIGN bit is either RW or RAO.
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/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 506386a3edde..d3842791e1c4 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -77,6 +77,10 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
77 */ 77 */
78 if (!vcpu_el1_is_32bit(vcpu)) 78 if (!vcpu_el1_is_32bit(vcpu))
79 vcpu->arch.hcr_el2 |= HCR_TID3; 79 vcpu->arch.hcr_el2 |= HCR_TID3;
80
81 if (cpus_have_const_cap(ARM64_MISMATCHED_CACHE_TYPE) ||
82 vcpu_el1_is_32bit(vcpu))
83 vcpu->arch.hcr_el2 |= HCR_TID2;
80} 84}
81 85
82static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu) 86static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu)
@@ -331,6 +335,14 @@ static inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
331 return ESR_ELx_SYS64_ISS_RT(esr); 335 return ESR_ELx_SYS64_ISS_RT(esr);
332} 336}
333 337
338static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
339{
340 if (kvm_vcpu_trap_is_iabt(vcpu))
341 return false;
342
343 return kvm_vcpu_dabt_iswrite(vcpu);
344}
345
334static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu) 346static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
335{ 347{
336 return vcpu_read_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK; 348 return vcpu_read_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 222af1d2c3e4..a01fe087e022 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -31,6 +31,7 @@
31#include <asm/kvm.h> 31#include <asm/kvm.h>
32#include <asm/kvm_asm.h> 32#include <asm/kvm_asm.h>
33#include <asm/kvm_mmio.h> 33#include <asm/kvm_mmio.h>
34#include <asm/smp_plat.h>
34#include <asm/thread_info.h> 35#include <asm/thread_info.h>
35 36
36#define __KVM_HAVE_ARCH_INTC_INITIALIZED 37#define __KVM_HAVE_ARCH_INTC_INITIALIZED
@@ -58,16 +59,19 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
58int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext); 59int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext);
59void __extended_idmap_trampoline(phys_addr_t boot_pgd, phys_addr_t idmap_start); 60void __extended_idmap_trampoline(phys_addr_t boot_pgd, phys_addr_t idmap_start);
60 61
61struct kvm_arch { 62struct kvm_vmid {
62 /* The VMID generation used for the virt. memory system */ 63 /* The VMID generation used for the virt. memory system */
63 u64 vmid_gen; 64 u64 vmid_gen;
64 u32 vmid; 65 u32 vmid;
66};
67
68struct kvm_arch {
69 struct kvm_vmid vmid;
65 70
66 /* stage2 entry level table */ 71 /* stage2 entry level table */
67 pgd_t *pgd; 72 pgd_t *pgd;
73 phys_addr_t pgd_phys;
68 74
69 /* VTTBR value associated with above pgd and vmid */
70 u64 vttbr;
71 /* VTCR_EL2 value for this VM */ 75 /* VTCR_EL2 value for this VM */
72 u64 vtcr; 76 u64 vtcr;
73 77
@@ -382,7 +386,36 @@ void kvm_arm_halt_guest(struct kvm *kvm);
382void kvm_arm_resume_guest(struct kvm *kvm); 386void kvm_arm_resume_guest(struct kvm *kvm);
383 387
384u64 __kvm_call_hyp(void *hypfn, ...); 388u64 __kvm_call_hyp(void *hypfn, ...);
385#define kvm_call_hyp(f, ...) __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__) 389
390/*
391 * The couple of isb() below are there to guarantee the same behaviour
392 * on VHE as on !VHE, where the eret to EL1 acts as a context
393 * synchronization event.
394 */
395#define kvm_call_hyp(f, ...) \
396 do { \
397 if (has_vhe()) { \
398 f(__VA_ARGS__); \
399 isb(); \
400 } else { \
401 __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__); \
402 } \
403 } while(0)
404
405#define kvm_call_hyp_ret(f, ...) \
406 ({ \
407 typeof(f(__VA_ARGS__)) ret; \
408 \
409 if (has_vhe()) { \
410 ret = f(__VA_ARGS__); \
411 isb(); \
412 } else { \
413 ret = __kvm_call_hyp(kvm_ksym_ref(f), \
414 ##__VA_ARGS__); \
415 } \
416 \
417 ret; \
418 })
386 419
387void force_vm_exit(const cpumask_t *mask); 420void force_vm_exit(const cpumask_t *mask);
388void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot); 421void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
@@ -401,6 +434,13 @@ struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
401 434
402DECLARE_PER_CPU(kvm_cpu_context_t, kvm_host_cpu_state); 435DECLARE_PER_CPU(kvm_cpu_context_t, kvm_host_cpu_state);
403 436
437static inline void kvm_init_host_cpu_context(kvm_cpu_context_t *cpu_ctxt,
438 int cpu)
439{
440 /* The host's MPIDR is immutable, so let's set it up at boot time */
441 cpu_ctxt->sys_regs[MPIDR_EL1] = cpu_logical_map(cpu);
442}
443
404void __kvm_enable_ssbs(void); 444void __kvm_enable_ssbs(void);
405 445
406static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr, 446static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,
diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
index a80a7ef57325..4da765f2cca5 100644
--- a/arch/arm64/include/asm/kvm_hyp.h
+++ b/arch/arm64/include/asm/kvm_hyp.h
@@ -21,6 +21,7 @@
21#include <linux/compiler.h> 21#include <linux/compiler.h>
22#include <linux/kvm_host.h> 22#include <linux/kvm_host.h>
23#include <asm/alternative.h> 23#include <asm/alternative.h>
24#include <asm/kvm_mmu.h>
24#include <asm/sysreg.h> 25#include <asm/sysreg.h>
25 26
26#define __hyp_text __section(.hyp.text) notrace 27#define __hyp_text __section(.hyp.text) notrace
@@ -163,7 +164,7 @@ void __noreturn __hyp_do_panic(unsigned long, ...);
163static __always_inline void __hyp_text __load_guest_stage2(struct kvm *kvm) 164static __always_inline void __hyp_text __load_guest_stage2(struct kvm *kvm)
164{ 165{
165 write_sysreg(kvm->arch.vtcr, vtcr_el2); 166 write_sysreg(kvm->arch.vtcr, vtcr_el2);
166 write_sysreg(kvm->arch.vttbr, vttbr_el2); 167 write_sysreg(kvm_get_vttbr(kvm), vttbr_el2);
167 168
168 /* 169 /*
169 * ARM erratum 1165522 requires the actual execution of the above 170 * ARM erratum 1165522 requires the actual execution of the above
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 8af4b1befa42..b0742a16c6c9 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -138,7 +138,8 @@ static inline unsigned long __kern_hyp_va(unsigned long v)
138 }) 138 })
139 139
140/* 140/*
141 * We currently only support a 40bit IPA. 141 * We currently support using a VM-specified IPA size. For backward
142 * compatibility, the default IPA size is fixed to 40bits.
142 */ 143 */
143#define KVM_PHYS_SHIFT (40) 144#define KVM_PHYS_SHIFT (40)
144 145
@@ -591,9 +592,15 @@ static inline u64 kvm_vttbr_baddr_mask(struct kvm *kvm)
591 return vttbr_baddr_mask(kvm_phys_shift(kvm), kvm_stage2_levels(kvm)); 592 return vttbr_baddr_mask(kvm_phys_shift(kvm), kvm_stage2_levels(kvm));
592} 593}
593 594
594static inline bool kvm_cpu_has_cnp(void) 595static __always_inline u64 kvm_get_vttbr(struct kvm *kvm)
595{ 596{
596 return system_supports_cnp(); 597 struct kvm_vmid *vmid = &kvm->arch.vmid;
598 u64 vmid_field, baddr;
599 u64 cnp = system_supports_cnp() ? VTTBR_CNP_BIT : 0;
600
601 baddr = kvm->arch.pgd_phys;
602 vmid_field = (u64)vmid->vmid << VTTBR_VMID_SHIFT;
603 return kvm_phys_to_vttbr(baddr) | vmid_field | cnp;
597} 604}
598 605
599#endif /* __ASSEMBLY__ */ 606#endif /* __ASSEMBLY__ */
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 72dc4c011014..5b267dec6194 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -361,6 +361,7 @@
361 361
362#define SYS_CNTKCTL_EL1 sys_reg(3, 0, 14, 1, 0) 362#define SYS_CNTKCTL_EL1 sys_reg(3, 0, 14, 1, 0)
363 363
364#define SYS_CCSIDR_EL1 sys_reg(3, 1, 0, 0, 0)
364#define SYS_CLIDR_EL1 sys_reg(3, 1, 0, 0, 1) 365#define SYS_CLIDR_EL1 sys_reg(3, 1, 0, 0, 1)
365#define SYS_AIDR_EL1 sys_reg(3, 1, 0, 0, 7) 366#define SYS_AIDR_EL1 sys_reg(3, 1, 0, 0, 7)
366 367
@@ -392,6 +393,10 @@
392#define SYS_CNTP_CTL_EL0 sys_reg(3, 3, 14, 2, 1) 393#define SYS_CNTP_CTL_EL0 sys_reg(3, 3, 14, 2, 1)
393#define SYS_CNTP_CVAL_EL0 sys_reg(3, 3, 14, 2, 2) 394#define SYS_CNTP_CVAL_EL0 sys_reg(3, 3, 14, 2, 2)
394 395
396#define SYS_AARCH32_CNTP_TVAL sys_reg(0, 0, 14, 2, 0)
397#define SYS_AARCH32_CNTP_CTL sys_reg(0, 0, 14, 2, 1)
398#define SYS_AARCH32_CNTP_CVAL sys_reg(0, 2, 0, 14, 0)
399
395#define __PMEV_op2(n) ((n) & 0x7) 400#define __PMEV_op2(n) ((n) & 0x7)
396#define __CNTR_CRm(n) (0x8 | (((n) >> 3) & 0x3)) 401#define __CNTR_CRm(n) (0x8 | (((n) >> 3) & 0x3))
397#define SYS_PMEVCNTRn_EL0(n) sys_reg(3, 3, 14, __CNTR_CRm(n), __PMEV_op2(n)) 402#define SYS_PMEVCNTRn_EL0(n) sys_reg(3, 3, 14, __CNTR_CRm(n), __PMEV_op2(n))
@@ -426,7 +431,7 @@
426#define SYS_ICH_VTR_EL2 sys_reg(3, 4, 12, 11, 1) 431#define SYS_ICH_VTR_EL2 sys_reg(3, 4, 12, 11, 1)
427#define SYS_ICH_MISR_EL2 sys_reg(3, 4, 12, 11, 2) 432#define SYS_ICH_MISR_EL2 sys_reg(3, 4, 12, 11, 2)
428#define SYS_ICH_EISR_EL2 sys_reg(3, 4, 12, 11, 3) 433#define SYS_ICH_EISR_EL2 sys_reg(3, 4, 12, 11, 3)
429#define SYS_ICH_ELSR_EL2 sys_reg(3, 4, 12, 11, 5) 434#define SYS_ICH_ELRSR_EL2 sys_reg(3, 4, 12, 11, 5)
430#define SYS_ICH_VMCR_EL2 sys_reg(3, 4, 12, 11, 7) 435#define SYS_ICH_VMCR_EL2 sys_reg(3, 4, 12, 11, 7)
431 436
432#define __SYS__LR0_EL2(x) sys_reg(3, 4, 12, 12, x) 437#define __SYS__LR0_EL2(x) sys_reg(3, 4, 12, 12, x)
diff --git a/arch/arm64/include/uapi/asm/Kbuild b/arch/arm64/include/uapi/asm/Kbuild
index 87eea29b24ab..602d137932dc 100644
--- a/arch/arm64/include/uapi/asm/Kbuild
+++ b/arch/arm64/include/uapi/asm/Kbuild
@@ -1,4 +1,3 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2include include/uapi/asm-generic/Kbuild.asm
3 2
4generic-y += kvm_para.h 3generic-y += kvm_para.h
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/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
index 0f2a135ba15b..690e033a91c0 100644
--- a/arch/arm64/kvm/Makefile
+++ b/arch/arm64/kvm/Makefile
@@ -3,9 +3,7 @@
3# Makefile for Kernel-based Virtual Machine module 3# Makefile for Kernel-based Virtual Machine module
4# 4#
5 5
6ccflags-y += -Iarch/arm64/kvm -Ivirt/kvm/arm/vgic 6ccflags-y += -I $(srctree)/$(src) -I $(srctree)/virt/kvm/arm/vgic
7CFLAGS_arm.o := -I.
8CFLAGS_mmu.o := -I.
9 7
10KVM=../../../virt/kvm 8KVM=../../../virt/kvm
11 9
diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
index f39801e4136c..fd917d6d12af 100644
--- a/arch/arm64/kvm/debug.c
+++ b/arch/arm64/kvm/debug.c
@@ -76,7 +76,7 @@ static void restore_guest_debug_regs(struct kvm_vcpu *vcpu)
76 76
77void kvm_arm_init_debug(void) 77void kvm_arm_init_debug(void)
78{ 78{
79 __this_cpu_write(mdcr_el2, kvm_call_hyp(__kvm_get_mdcr_el2)); 79 __this_cpu_write(mdcr_el2, kvm_call_hyp_ret(__kvm_get_mdcr_el2));
80} 80}
81 81
82/** 82/**
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 952f6cb9cf72..2845aa680841 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -40,9 +40,6 @@
40 * arch/arm64/kernel/hyp_stub.S. 40 * arch/arm64/kernel/hyp_stub.S.
41 */ 41 */
42ENTRY(__kvm_call_hyp) 42ENTRY(__kvm_call_hyp)
43alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
44 hvc #0 43 hvc #0
45 ret 44 ret
46alternative_else_nop_endif
47 b __vhe_hyp_call
48ENDPROC(__kvm_call_hyp) 45ENDPROC(__kvm_call_hyp)
diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S
index 73c1b483ec39..2b1e686772bf 100644
--- a/arch/arm64/kvm/hyp/hyp-entry.S
+++ b/arch/arm64/kvm/hyp/hyp-entry.S
@@ -43,18 +43,6 @@
43 ldr lr, [sp], #16 43 ldr lr, [sp], #16
44.endm 44.endm
45 45
46ENTRY(__vhe_hyp_call)
47 do_el2_call
48 /*
49 * We used to rely on having an exception return to get
50 * an implicit isb. In the E2H case, we don't have it anymore.
51 * rather than changing all the leaf functions, just do it here
52 * before returning to the rest of the kernel.
53 */
54 isb
55 ret
56ENDPROC(__vhe_hyp_call)
57
58el1_sync: // Guest trapped into EL2 46el1_sync: // Guest trapped into EL2
59 47
60 mrs x0, esr_el2 48 mrs x0, esr_el2
diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c
index b426e2cf973c..c52a8451637c 100644
--- a/arch/arm64/kvm/hyp/sysreg-sr.c
+++ b/arch/arm64/kvm/hyp/sysreg-sr.c
@@ -53,7 +53,6 @@ static void __hyp_text __sysreg_save_user_state(struct kvm_cpu_context *ctxt)
53 53
54static void __hyp_text __sysreg_save_el1_state(struct kvm_cpu_context *ctxt) 54static void __hyp_text __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
55{ 55{
56 ctxt->sys_regs[MPIDR_EL1] = read_sysreg(vmpidr_el2);
57 ctxt->sys_regs[CSSELR_EL1] = read_sysreg(csselr_el1); 56 ctxt->sys_regs[CSSELR_EL1] = read_sysreg(csselr_el1);
58 ctxt->sys_regs[SCTLR_EL1] = read_sysreg_el1(sctlr); 57 ctxt->sys_regs[SCTLR_EL1] = read_sysreg_el1(sctlr);
59 ctxt->sys_regs[ACTLR_EL1] = read_sysreg(actlr_el1); 58 ctxt->sys_regs[ACTLR_EL1] = read_sysreg(actlr_el1);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index c936aa40c3f4..539feecda5b8 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -982,6 +982,10 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
982 return true; 982 return true;
983} 983}
984 984
985#define reg_to_encoding(x) \
986 sys_reg((u32)(x)->Op0, (u32)(x)->Op1, \
987 (u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2);
988
985/* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */ 989/* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */
986#define DBG_BCR_BVR_WCR_WVR_EL1(n) \ 990#define DBG_BCR_BVR_WCR_WVR_EL1(n) \
987 { SYS_DESC(SYS_DBGBVRn_EL1(n)), \ 991 { SYS_DESC(SYS_DBGBVRn_EL1(n)), \
@@ -1003,44 +1007,38 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
1003 { SYS_DESC(SYS_PMEVTYPERn_EL0(n)), \ 1007 { SYS_DESC(SYS_PMEVTYPERn_EL0(n)), \
1004 access_pmu_evtyper, reset_unknown, (PMEVTYPER0_EL0 + n), } 1008 access_pmu_evtyper, reset_unknown, (PMEVTYPER0_EL0 + n), }
1005 1009
1006static bool access_cntp_tval(struct kvm_vcpu *vcpu, 1010static bool access_arch_timer(struct kvm_vcpu *vcpu,
1007 struct sys_reg_params *p, 1011 struct sys_reg_params *p,
1008 const struct sys_reg_desc *r) 1012 const struct sys_reg_desc *r)
1009{ 1013{
1010 u64 now = kvm_phys_timer_read(); 1014 enum kvm_arch_timers tmr;
1011 u64 cval; 1015 enum kvm_arch_timer_regs treg;
1016 u64 reg = reg_to_encoding(r);
1012 1017
1013 if (p->is_write) { 1018 switch (reg) {
1014 kvm_arm_timer_set_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL, 1019 case SYS_CNTP_TVAL_EL0:
1015 p->regval + now); 1020 case SYS_AARCH32_CNTP_TVAL:
1016 } else { 1021 tmr = TIMER_PTIMER;
1017 cval = kvm_arm_timer_get_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL); 1022 treg = TIMER_REG_TVAL;
1018 p->regval = cval - now; 1023 break;
1024 case SYS_CNTP_CTL_EL0:
1025 case SYS_AARCH32_CNTP_CTL:
1026 tmr = TIMER_PTIMER;
1027 treg = TIMER_REG_CTL;
1028 break;
1029 case SYS_CNTP_CVAL_EL0:
1030 case SYS_AARCH32_CNTP_CVAL:
1031 tmr = TIMER_PTIMER;
1032 treg = TIMER_REG_CVAL;
1033 break;
1034 default:
1035 BUG();
1019 } 1036 }
1020 1037
1021 return true;
1022}
1023
1024static bool access_cntp_ctl(struct kvm_vcpu *vcpu,
1025 struct sys_reg_params *p,
1026 const struct sys_reg_desc *r)
1027{
1028 if (p->is_write)
1029 kvm_arm_timer_set_reg(vcpu, KVM_REG_ARM_PTIMER_CTL, p->regval);
1030 else
1031 p->regval = kvm_arm_timer_get_reg(vcpu, KVM_REG_ARM_PTIMER_CTL);
1032
1033 return true;
1034}
1035
1036static bool access_cntp_cval(struct kvm_vcpu *vcpu,
1037 struct sys_reg_params *p,
1038 const struct sys_reg_desc *r)
1039{
1040 if (p->is_write) 1038 if (p->is_write)
1041 kvm_arm_timer_set_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL, p->regval); 1039 kvm_arm_timer_write_sysreg(vcpu, tmr, treg, p->regval);
1042 else 1040 else
1043 p->regval = kvm_arm_timer_get_reg(vcpu, KVM_REG_ARM_PTIMER_CVAL); 1041 p->regval = kvm_arm_timer_read_sysreg(vcpu, tmr, treg);
1044 1042
1045 return true; 1043 return true;
1046} 1044}
@@ -1160,6 +1158,64 @@ static int set_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
1160 return __set_id_reg(rd, uaddr, true); 1158 return __set_id_reg(rd, uaddr, true);
1161} 1159}
1162 1160
1161static bool access_ctr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
1162 const struct sys_reg_desc *r)
1163{
1164 if (p->is_write)
1165 return write_to_read_only(vcpu, p, r);
1166
1167 p->regval = read_sanitised_ftr_reg(SYS_CTR_EL0);
1168 return true;
1169}
1170
1171static bool access_clidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
1172 const struct sys_reg_desc *r)
1173{
1174 if (p->is_write)
1175 return write_to_read_only(vcpu, p, r);
1176
1177 p->regval = read_sysreg(clidr_el1);
1178 return true;
1179}
1180
1181static bool access_csselr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
1182 const struct sys_reg_desc *r)
1183{
1184 if (p->is_write)
1185 vcpu_write_sys_reg(vcpu, p->regval, r->reg);
1186 else
1187 p->regval = vcpu_read_sys_reg(vcpu, r->reg);
1188 return true;
1189}
1190
1191static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
1192 const struct sys_reg_desc *r)
1193{
1194 u32 csselr;
1195
1196 if (p->is_write)
1197 return write_to_read_only(vcpu, p, r);
1198
1199 csselr = vcpu_read_sys_reg(vcpu, CSSELR_EL1);
1200 p->regval = get_ccsidr(csselr);
1201
1202 /*
1203 * Guests should not be doing cache operations by set/way at all, and
1204 * for this reason, we trap them and attempt to infer the intent, so
1205 * that we can flush the entire guest's address space at the appropriate
1206 * time.
1207 * To prevent this trapping from causing performance problems, let's
1208 * expose the geometry of all data and unified caches (which are
1209 * guaranteed to be PIPT and thus non-aliasing) as 1 set and 1 way.
1210 * [If guests should attempt to infer aliasing properties from the
1211 * geometry (which is not permitted by the architecture), they would
1212 * only do so for virtually indexed caches.]
1213 */
1214 if (!(csselr & 1)) // data or unified cache
1215 p->regval &= ~GENMASK(27, 3);
1216 return true;
1217}
1218
1163/* sys_reg_desc initialiser for known cpufeature ID registers */ 1219/* sys_reg_desc initialiser for known cpufeature ID registers */
1164#define ID_SANITISED(name) { \ 1220#define ID_SANITISED(name) { \
1165 SYS_DESC(SYS_##name), \ 1221 SYS_DESC(SYS_##name), \
@@ -1377,7 +1433,10 @@ static const struct sys_reg_desc sys_reg_descs[] = {
1377 1433
1378 { SYS_DESC(SYS_CNTKCTL_EL1), NULL, reset_val, CNTKCTL_EL1, 0}, 1434 { SYS_DESC(SYS_CNTKCTL_EL1), NULL, reset_val, CNTKCTL_EL1, 0},
1379 1435
1380 { SYS_DESC(SYS_CSSELR_EL1), NULL, reset_unknown, CSSELR_EL1 }, 1436 { SYS_DESC(SYS_CCSIDR_EL1), access_ccsidr },
1437 { SYS_DESC(SYS_CLIDR_EL1), access_clidr },
1438 { SYS_DESC(SYS_CSSELR_EL1), access_csselr, reset_unknown, CSSELR_EL1 },
1439 { SYS_DESC(SYS_CTR_EL0), access_ctr },
1381 1440
1382 { SYS_DESC(SYS_PMCR_EL0), access_pmcr, reset_pmcr, }, 1441 { SYS_DESC(SYS_PMCR_EL0), access_pmcr, reset_pmcr, },
1383 { SYS_DESC(SYS_PMCNTENSET_EL0), access_pmcnten, reset_unknown, PMCNTENSET_EL0 }, 1442 { SYS_DESC(SYS_PMCNTENSET_EL0), access_pmcnten, reset_unknown, PMCNTENSET_EL0 },
@@ -1400,9 +1459,9 @@ static const struct sys_reg_desc sys_reg_descs[] = {
1400 { SYS_DESC(SYS_TPIDR_EL0), NULL, reset_unknown, TPIDR_EL0 }, 1459 { SYS_DESC(SYS_TPIDR_EL0), NULL, reset_unknown, TPIDR_EL0 },
1401 { SYS_DESC(SYS_TPIDRRO_EL0), NULL, reset_unknown, TPIDRRO_EL0 }, 1460 { SYS_DESC(SYS_TPIDRRO_EL0), NULL, reset_unknown, TPIDRRO_EL0 },
1402 1461
1403 { SYS_DESC(SYS_CNTP_TVAL_EL0), access_cntp_tval }, 1462 { SYS_DESC(SYS_CNTP_TVAL_EL0), access_arch_timer },
1404 { SYS_DESC(SYS_CNTP_CTL_EL0), access_cntp_ctl }, 1463 { SYS_DESC(SYS_CNTP_CTL_EL0), access_arch_timer },
1405 { SYS_DESC(SYS_CNTP_CVAL_EL0), access_cntp_cval }, 1464 { SYS_DESC(SYS_CNTP_CVAL_EL0), access_arch_timer },
1406 1465
1407 /* PMEVCNTRn_EL0 */ 1466 /* PMEVCNTRn_EL0 */
1408 PMU_PMEVCNTR_EL0(0), 1467 PMU_PMEVCNTR_EL0(0),
@@ -1476,7 +1535,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
1476 1535
1477 { SYS_DESC(SYS_DACR32_EL2), NULL, reset_unknown, DACR32_EL2 }, 1536 { SYS_DESC(SYS_DACR32_EL2), NULL, reset_unknown, DACR32_EL2 },
1478 { SYS_DESC(SYS_IFSR32_EL2), NULL, reset_unknown, IFSR32_EL2 }, 1537 { SYS_DESC(SYS_IFSR32_EL2), NULL, reset_unknown, IFSR32_EL2 },
1479 { SYS_DESC(SYS_FPEXC32_EL2), NULL, reset_val, FPEXC32_EL2, 0x70 }, 1538 { SYS_DESC(SYS_FPEXC32_EL2), NULL, reset_val, FPEXC32_EL2, 0x700 },
1480}; 1539};
1481 1540
1482static bool trap_dbgidr(struct kvm_vcpu *vcpu, 1541static bool trap_dbgidr(struct kvm_vcpu *vcpu,
@@ -1677,6 +1736,7 @@ static const struct sys_reg_desc cp14_64_regs[] = {
1677 * register). 1736 * register).
1678 */ 1737 */
1679static const struct sys_reg_desc cp15_regs[] = { 1738static const struct sys_reg_desc cp15_regs[] = {
1739 { Op1( 0), CRn( 0), CRm( 0), Op2( 1), access_ctr },
1680 { Op1( 0), CRn( 1), CRm( 0), Op2( 0), access_vm_reg, NULL, c1_SCTLR }, 1740 { Op1( 0), CRn( 1), CRm( 0), Op2( 0), access_vm_reg, NULL, c1_SCTLR },
1681 { Op1( 0), CRn( 2), CRm( 0), Op2( 0), access_vm_reg, NULL, c2_TTBR0 }, 1741 { Op1( 0), CRn( 2), CRm( 0), Op2( 0), access_vm_reg, NULL, c2_TTBR0 },
1682 { Op1( 0), CRn( 2), CRm( 0), Op2( 1), access_vm_reg, NULL, c2_TTBR1 }, 1742 { Op1( 0), CRn( 2), CRm( 0), Op2( 1), access_vm_reg, NULL, c2_TTBR1 },
@@ -1723,10 +1783,9 @@ static const struct sys_reg_desc cp15_regs[] = {
1723 1783
1724 { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID }, 1784 { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID },
1725 1785
1726 /* CNTP_TVAL */ 1786 /* Arch Tmers */
1727 { Op1( 0), CRn(14), CRm( 2), Op2( 0), access_cntp_tval }, 1787 { SYS_DESC(SYS_AARCH32_CNTP_TVAL), access_arch_timer },
1728 /* CNTP_CTL */ 1788 { SYS_DESC(SYS_AARCH32_CNTP_CTL), access_arch_timer },
1729 { Op1( 0), CRn(14), CRm( 2), Op2( 1), access_cntp_ctl },
1730 1789
1731 /* PMEVCNTRn */ 1790 /* PMEVCNTRn */
1732 PMU_PMEVCNTR(0), 1791 PMU_PMEVCNTR(0),
@@ -1794,6 +1853,10 @@ static const struct sys_reg_desc cp15_regs[] = {
1794 PMU_PMEVTYPER(30), 1853 PMU_PMEVTYPER(30),
1795 /* PMCCFILTR */ 1854 /* PMCCFILTR */
1796 { Op1(0), CRn(14), CRm(15), Op2(7), access_pmu_evtyper }, 1855 { Op1(0), CRn(14), CRm(15), Op2(7), access_pmu_evtyper },
1856
1857 { Op1(1), CRn( 0), CRm( 0), Op2(0), access_ccsidr },
1858 { Op1(1), CRn( 0), CRm( 0), Op2(1), access_clidr },
1859 { Op1(2), CRn( 0), CRm( 0), Op2(0), access_csselr, NULL, c0_CSSELR },
1797}; 1860};
1798 1861
1799static const struct sys_reg_desc cp15_64_regs[] = { 1862static const struct sys_reg_desc cp15_64_regs[] = {
@@ -1803,7 +1866,7 @@ static const struct sys_reg_desc cp15_64_regs[] = {
1803 { Op1( 1), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, c2_TTBR1 }, 1866 { Op1( 1), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, c2_TTBR1 },
1804 { Op1( 1), CRn( 0), CRm(12), Op2( 0), access_gic_sgi }, /* ICC_ASGI1R */ 1867 { Op1( 1), CRn( 0), CRm(12), Op2( 0), access_gic_sgi }, /* ICC_ASGI1R */
1805 { Op1( 2), CRn( 0), CRm(12), Op2( 0), access_gic_sgi }, /* ICC_SGI0R */ 1868 { Op1( 2), CRn( 0), CRm(12), Op2( 0), access_gic_sgi }, /* ICC_SGI0R */
1806 { Op1( 2), CRn( 0), CRm(14), Op2( 0), access_cntp_cval }, 1869 { SYS_DESC(SYS_AARCH32_CNTP_CVAL), access_arch_timer },
1807}; 1870};
1808 1871
1809/* Target specific emulation tables */ 1872/* Target specific emulation tables */
@@ -1832,30 +1895,19 @@ static const struct sys_reg_desc *get_target_table(unsigned target,
1832 } 1895 }
1833} 1896}
1834 1897
1835#define reg_to_match_value(x) \
1836 ({ \
1837 unsigned long val; \
1838 val = (x)->Op0 << 14; \
1839 val |= (x)->Op1 << 11; \
1840 val |= (x)->CRn << 7; \
1841 val |= (x)->CRm << 3; \
1842 val |= (x)->Op2; \
1843 val; \
1844 })
1845
1846static int match_sys_reg(const void *key, const void *elt) 1898static int match_sys_reg(const void *key, const void *elt)
1847{ 1899{
1848 const unsigned long pval = (unsigned long)key; 1900 const unsigned long pval = (unsigned long)key;
1849 const struct sys_reg_desc *r = elt; 1901 const struct sys_reg_desc *r = elt;
1850 1902
1851 return pval - reg_to_match_value(r); 1903 return pval - reg_to_encoding(r);
1852} 1904}
1853 1905
1854static const struct sys_reg_desc *find_reg(const struct sys_reg_params *params, 1906static const struct sys_reg_desc *find_reg(const struct sys_reg_params *params,
1855 const struct sys_reg_desc table[], 1907 const struct sys_reg_desc table[],
1856 unsigned int num) 1908 unsigned int num)
1857{ 1909{
1858 unsigned long pval = reg_to_match_value(params); 1910 unsigned long pval = reg_to_encoding(params);
1859 1911
1860 return bsearch((void *)pval, table, num, sizeof(table[0]), match_sys_reg); 1912 return bsearch((void *)pval, table, num, sizeof(table[0]), match_sys_reg);
1861} 1913}
@@ -2218,11 +2270,15 @@ static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,
2218 } 2270 }
2219 2271
2220FUNCTION_INVARIANT(midr_el1) 2272FUNCTION_INVARIANT(midr_el1)
2221FUNCTION_INVARIANT(ctr_el0)
2222FUNCTION_INVARIANT(revidr_el1) 2273FUNCTION_INVARIANT(revidr_el1)
2223FUNCTION_INVARIANT(clidr_el1) 2274FUNCTION_INVARIANT(clidr_el1)
2224FUNCTION_INVARIANT(aidr_el1) 2275FUNCTION_INVARIANT(aidr_el1)
2225 2276
2277static void get_ctr_el0(struct kvm_vcpu *v, const struct sys_reg_desc *r)
2278{
2279 ((struct sys_reg_desc *)r)->val = read_sanitised_ftr_reg(SYS_CTR_EL0);
2280}
2281
2226/* ->val is filled in by kvm_sys_reg_table_init() */ 2282/* ->val is filled in by kvm_sys_reg_table_init() */
2227static struct sys_reg_desc invariant_sys_regs[] = { 2283static struct sys_reg_desc invariant_sys_regs[] = {
2228 { SYS_DESC(SYS_MIDR_EL1), NULL, get_midr_el1 }, 2284 { SYS_DESC(SYS_MIDR_EL1), NULL, get_midr_el1 },
diff --git a/arch/c6x/include/uapi/asm/Kbuild b/arch/c6x/include/uapi/asm/Kbuild
index 0febf1a07c30..755bb11323d8 100644
--- a/arch/c6x/include/uapi/asm/Kbuild
+++ b/arch/c6x/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += kvm_para.h 1generic-y += kvm_para.h
4generic-y += ucontext.h 2generic-y += ucontext.h
diff --git a/arch/csky/include/uapi/asm/Kbuild b/arch/csky/include/uapi/asm/Kbuild
index c1b06dcf6cf8..1c72f04ff75d 100644
--- a/arch/csky/include/uapi/asm/Kbuild
+++ b/arch/csky/include/uapi/asm/Kbuild
@@ -1,3 +1 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += ucontext.h generic-y += ucontext.h
diff --git a/arch/h8300/Makefile b/arch/h8300/Makefile
index f801f3708a89..ba0f26cfad61 100644
--- a/arch/h8300/Makefile
+++ b/arch/h8300/Makefile
@@ -27,7 +27,7 @@ KBUILD_LDFLAGS += $(ldflags-y)
27CHECKFLAGS += -msize-long 27CHECKFLAGS += -msize-long
28 28
29ifeq ($(CROSS_COMPILE),) 29ifeq ($(CROSS_COMPILE),)
30CROSS_COMPILE := h8300-unknown-linux- 30CROSS_COMPILE := $(call cc-cross-prefix, h8300-unknown-linux- h8300-linux-)
31endif 31endif
32 32
33core-y += arch/$(ARCH)/kernel/ arch/$(ARCH)/mm/ 33core-y += arch/$(ARCH)/kernel/ arch/$(ARCH)/mm/
diff --git a/arch/h8300/include/asm/Kbuild b/arch/h8300/include/asm/Kbuild
index 961c1dc064e1..3e7c8ecf151e 100644
--- a/arch/h8300/include/asm/Kbuild
+++ b/arch/h8300/include/asm/Kbuild
@@ -17,7 +17,6 @@ generic-y += fb.h
17generic-y += ftrace.h 17generic-y += ftrace.h
18generic-y += futex.h 18generic-y += futex.h
19generic-y += hardirq.h 19generic-y += hardirq.h
20generic-y += hash.h
21generic-y += hw_irq.h 20generic-y += hw_irq.h
22generic-y += irq_regs.h 21generic-y += irq_regs.h
23generic-y += irq_work.h 22generic-y += irq_work.h
diff --git a/arch/h8300/include/uapi/asm/Kbuild b/arch/h8300/include/uapi/asm/Kbuild
index 0febf1a07c30..755bb11323d8 100644
--- a/arch/h8300/include/uapi/asm/Kbuild
+++ b/arch/h8300/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += kvm_para.h 1generic-y += kvm_para.h
4generic-y += ucontext.h 2generic-y += ucontext.h
diff --git a/arch/hexagon/include/uapi/asm/Kbuild b/arch/hexagon/include/uapi/asm/Kbuild
index c1b06dcf6cf8..1c72f04ff75d 100644
--- a/arch/hexagon/include/uapi/asm/Kbuild
+++ b/arch/hexagon/include/uapi/asm/Kbuild
@@ -1,3 +1 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += ucontext.h generic-y += ucontext.h
diff --git a/arch/ia64/hp/sim/simscsi.c b/arch/ia64/hp/sim/simscsi.c
index f86844fc0725..0a8a74271173 100644
--- a/arch/ia64/hp/sim/simscsi.c
+++ b/arch/ia64/hp/sim/simscsi.c
@@ -105,7 +105,8 @@ simscsi_interrupt (unsigned long val)
105 atomic_dec(&num_reqs); 105 atomic_dec(&num_reqs);
106 queue[rd].sc = NULL; 106 queue[rd].sc = NULL;
107 if (DBG) 107 if (DBG)
108 printk("simscsi_interrupt: done with %ld\n", sc->serial_number); 108 printk("simscsi_interrupt: done with %u\n",
109 sc->request->tag);
109 (*sc->scsi_done)(sc); 110 (*sc->scsi_done)(sc);
110 rd = (rd + 1) % SIMSCSI_REQ_QUEUE_LEN; 111 rd = (rd + 1) % SIMSCSI_REQ_QUEUE_LEN;
111 } 112 }
@@ -214,8 +215,8 @@ simscsi_queuecommand_lck (struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)
214 register long sp asm ("sp"); 215 register long sp asm ("sp");
215 216
216 if (DBG) 217 if (DBG)
217 printk("simscsi_queuecommand: target=%d,cmnd=%u,sc=%lu,sp=%lx,done=%p\n", 218 printk("simscsi_queuecommand: target=%d,cmnd=%u,sc=%u,sp=%lx,done=%p\n",
218 target_id, sc->cmnd[0], sc->serial_number, sp, done); 219 target_id, sc->cmnd[0], sc->request->tag, sp, done);
219#endif 220#endif
220 221
221 sc->result = DID_BAD_TARGET << 16; 222 sc->result = DID_BAD_TARGET << 16;
diff --git a/arch/ia64/include/uapi/asm/Kbuild b/arch/ia64/include/uapi/asm/Kbuild
index b71c5f787783..20018cb883a9 100644
--- a/arch/ia64/include/uapi/asm/Kbuild
+++ b/arch/ia64/include/uapi/asm/Kbuild
@@ -1,5 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_64.h 1generated-y += unistd_64.h
4generic-y += kvm_para.h 2generic-y += kvm_para.h
5generic-y += socket.h
diff --git a/arch/ia64/sn/kernel/Makefile b/arch/ia64/sn/kernel/Makefile
index d27df1d45da7..9c349dd23265 100644
--- a/arch/ia64/sn/kernel/Makefile
+++ b/arch/ia64/sn/kernel/Makefile
@@ -7,7 +7,7 @@
7# Copyright (C) 1999,2001-2006,2008 Silicon Graphics, Inc. All Rights Reserved. 7# Copyright (C) 1999,2001-2006,2008 Silicon Graphics, Inc. All Rights Reserved.
8# 8#
9 9
10ccflags-y := -Iarch/ia64/sn/include 10ccflags-y := -I $(srctree)/arch/ia64/sn/include
11 11
12obj-y += setup.o bte.o bte_error.o irq.o mca.o idle.o \ 12obj-y += setup.o bte.o bte_error.o irq.o mca.o idle.o \
13 huberror.o io_acpi_init.o io_common.o \ 13 huberror.o io_acpi_init.o io_common.o \
diff --git a/arch/ia64/sn/kernel/sn2/Makefile b/arch/ia64/sn/kernel/sn2/Makefile
index 3d09108d4277..170bde4549da 100644
--- a/arch/ia64/sn/kernel/sn2/Makefile
+++ b/arch/ia64/sn/kernel/sn2/Makefile
@@ -9,7 +9,5 @@
9# sn2 specific kernel files 9# sn2 specific kernel files
10# 10#
11 11
12ccflags-y := -Iarch/ia64/sn/include
13
14obj-y += cache.o io.o ptc_deadlock.o sn2_smp.o sn_proc_fs.o \ 12obj-y += cache.o io.o ptc_deadlock.o sn2_smp.o sn_proc_fs.o \
15 prominfo_proc.o timer.o timer_interrupt.o sn_hwperf.o 13 prominfo_proc.o timer.o timer_interrupt.o sn_hwperf.o
diff --git a/arch/ia64/sn/pci/Makefile b/arch/ia64/sn/pci/Makefile
index df2a90145426..321576b1b425 100644
--- a/arch/ia64/sn/pci/Makefile
+++ b/arch/ia64/sn/pci/Makefile
@@ -7,6 +7,4 @@
7# 7#
8# Makefile for the sn pci general routines. 8# Makefile for the sn pci general routines.
9 9
10ccflags-y := -Iarch/ia64/sn/include
11
12obj-y := pci_dma.o tioca_provider.o tioce_provider.o pcibr/ 10obj-y := pci_dma.o tioca_provider.o tioce_provider.o pcibr/
diff --git a/arch/ia64/sn/pci/pcibr/Makefile b/arch/ia64/sn/pci/pcibr/Makefile
index 396bcae36309..712f6af7c6e0 100644
--- a/arch/ia64/sn/pci/pcibr/Makefile
+++ b/arch/ia64/sn/pci/pcibr/Makefile
@@ -7,7 +7,7 @@
7# 7#
8# Makefile for the sn2 io routines. 8# Makefile for the sn2 io routines.
9 9
10ccflags-y := -Iarch/ia64/sn/include 10ccflags-y := -I $(srctree)/arch/ia64/sn/include
11 11
12obj-y += pcibr_dma.o pcibr_reg.o \ 12obj-y += pcibr_dma.o pcibr_reg.o \
13 pcibr_ate.o pcibr_provider.o 13 pcibr_ate.o pcibr_provider.o
diff --git a/arch/m68k/include/uapi/asm/Kbuild b/arch/m68k/include/uapi/asm/Kbuild
index 960bf1e4be53..8a7ad40be463 100644
--- a/arch/m68k/include/uapi/asm/Kbuild
+++ b/arch/m68k/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h 1generated-y += unistd_32.h
4generic-y += kvm_para.h 2generic-y += kvm_para.h
diff --git a/arch/microblaze/include/uapi/asm/Kbuild b/arch/microblaze/include/uapi/asm/Kbuild
index 97823ec46e97..3ce84fbb2678 100644
--- a/arch/microblaze/include/uapi/asm/Kbuild
+++ b/arch/microblaze/include/uapi/asm/Kbuild
@@ -1,5 +1,3 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h 1generated-y += unistd_32.h
4generic-y += kvm_para.h 2generic-y += kvm_para.h
5generic-y += ucontext.h 3generic-y += ucontext.h
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/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index d2abd98471e8..41204a49cf95 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -1134,7 +1134,7 @@ static inline void kvm_arch_hardware_unsetup(void) {}
1134static inline void kvm_arch_sync_events(struct kvm *kvm) {} 1134static inline void kvm_arch_sync_events(struct kvm *kvm) {}
1135static inline void kvm_arch_free_memslot(struct kvm *kvm, 1135static inline void kvm_arch_free_memslot(struct kvm *kvm,
1136 struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {} 1136 struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
1137static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {} 1137static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
1138static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} 1138static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
1139static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {} 1139static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
1140static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {} 1140static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
diff --git a/arch/mips/include/uapi/asm/Kbuild b/arch/mips/include/uapi/asm/Kbuild
index 0851c103a8ce..c3798bfe0486 100644
--- a/arch/mips/include/uapi/asm/Kbuild
+++ b/arch/mips/include/uapi/asm/Kbuild
@@ -1,5 +1,3 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_n32.h 1generated-y += unistd_n32.h
4generated-y += unistd_n64.h 2generated-y += unistd_n64.h
5generated-y += unistd_o32.h 3generated-y += unistd_o32.h
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/nds32/include/uapi/asm/Kbuild b/arch/nds32/include/uapi/asm/Kbuild
index c1b06dcf6cf8..1c72f04ff75d 100644
--- a/arch/nds32/include/uapi/asm/Kbuild
+++ b/arch/nds32/include/uapi/asm/Kbuild
@@ -1,3 +1 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += ucontext.h generic-y += ucontext.h
diff --git a/arch/nios2/include/uapi/asm/Kbuild b/arch/nios2/include/uapi/asm/Kbuild
index 0febf1a07c30..755bb11323d8 100644
--- a/arch/nios2/include/uapi/asm/Kbuild
+++ b/arch/nios2/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += kvm_para.h 1generic-y += kvm_para.h
4generic-y += ucontext.h 2generic-y += ucontext.h
diff --git a/arch/openrisc/include/asm/Kbuild b/arch/openrisc/include/asm/Kbuild
index 1f04844b6b82..5a73e2956ac4 100644
--- a/arch/openrisc/include/asm/Kbuild
+++ b/arch/openrisc/include/asm/Kbuild
@@ -15,7 +15,6 @@ generic-y += fb.h
15generic-y += ftrace.h 15generic-y += ftrace.h
16generic-y += hardirq.h 16generic-y += hardirq.h
17generic-y += hw_irq.h 17generic-y += hw_irq.h
18generic-y += irq.h
19generic-y += irq_regs.h 18generic-y += irq_regs.h
20generic-y += irq_work.h 19generic-y += irq_work.h
21generic-y += kdebug.h 20generic-y += kdebug.h
@@ -35,7 +34,6 @@ generic-y += qrwlock.h
35generic-y += sections.h 34generic-y += sections.h
36generic-y += segment.h 35generic-y += segment.h
37generic-y += shmparam.h 36generic-y += shmparam.h
38generic-y += string.h
39generic-y += switch_to.h 37generic-y += switch_to.h
40generic-y += topology.h 38generic-y += topology.h
41generic-y += trace_clock.h 39generic-y += trace_clock.h
diff --git a/arch/openrisc/include/uapi/asm/Kbuild b/arch/openrisc/include/uapi/asm/Kbuild
index 0febf1a07c30..755bb11323d8 100644
--- a/arch/openrisc/include/uapi/asm/Kbuild
+++ b/arch/openrisc/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += kvm_para.h 1generic-y += kvm_para.h
4generic-y += ucontext.h 2generic-y += ucontext.h
diff --git a/arch/parisc/include/asm/Kbuild b/arch/parisc/include/asm/Kbuild
index 0b1e354c8c24..6f49e77d82a2 100644
--- a/arch/parisc/include/asm/Kbuild
+++ b/arch/parisc/include/asm/Kbuild
@@ -1,7 +1,6 @@
1generated-y += syscall_table_32.h 1generated-y += syscall_table_32.h
2generated-y += syscall_table_64.h 2generated-y += syscall_table_64.h
3generated-y += syscall_table_c32.h 3generated-y += syscall_table_c32.h
4generic-y += barrier.h
5generic-y += current.h 4generic-y += current.h
6generic-y += device.h 5generic-y += device.h
7generic-y += div64.h 6generic-y += div64.h
@@ -20,7 +19,6 @@ generic-y += percpu.h
20generic-y += preempt.h 19generic-y += preempt.h
21generic-y += seccomp.h 20generic-y += seccomp.h
22generic-y += segment.h 21generic-y += segment.h
23generic-y += topology.h
24generic-y += trace_clock.h 22generic-y += trace_clock.h
25generic-y += user.h 23generic-y += user.h
26generic-y += vga.h 24generic-y += vga.h
diff --git a/arch/parisc/include/uapi/asm/Kbuild b/arch/parisc/include/uapi/asm/Kbuild
index c54353d390ff..22fdbd08cdc8 100644
--- a/arch/parisc/include/uapi/asm/Kbuild
+++ b/arch/parisc/include/uapi/asm/Kbuild
@@ -1,5 +1,3 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h 1generated-y += unistd_32.h
4generated-y += unistd_64.h 2generated-y += unistd_64.h
5generic-y += kvm_para.h 3generic-y += kvm_para.h
diff --git a/arch/powerpc/configs/skiroot_defconfig b/arch/powerpc/configs/skiroot_defconfig
index cfdd08897a06..5ba131c30f6b 100644
--- a/arch/powerpc/configs/skiroot_defconfig
+++ b/arch/powerpc/configs/skiroot_defconfig
@@ -37,7 +37,8 @@ CONFIG_MODULE_SIG=y
37CONFIG_MODULE_SIG_FORCE=y 37CONFIG_MODULE_SIG_FORCE=y
38CONFIG_MODULE_SIG_SHA512=y 38CONFIG_MODULE_SIG_SHA512=y
39CONFIG_PARTITION_ADVANCED=y 39CONFIG_PARTITION_ADVANCED=y
40# CONFIG_IOSCHED_DEADLINE is not set 40# CONFIG_MQ_IOSCHED_DEADLINE is not set
41# CONFIG_MQ_IOSCHED_KYBER is not set
41# CONFIG_PPC_VAS is not set 42# CONFIG_PPC_VAS is not set
42# CONFIG_PPC_PSERIES is not set 43# CONFIG_PPC_PSERIES is not set
43# CONFIG_PPC_OF_BOOT_TRAMPOLINE is not set 44# CONFIG_PPC_OF_BOOT_TRAMPOLINE is not set
@@ -49,7 +50,6 @@ CONFIG_IRQ_ALL_CPUS=y
49CONFIG_NUMA=y 50CONFIG_NUMA=y
50# CONFIG_COMPACTION is not set 51# CONFIG_COMPACTION is not set
51# CONFIG_MIGRATION is not set 52# CONFIG_MIGRATION is not set
52# CONFIG_BOUNCE is not set
53CONFIG_PPC_64K_PAGES=y 53CONFIG_PPC_64K_PAGES=y
54CONFIG_SCHED_SMT=y 54CONFIG_SCHED_SMT=y
55CONFIG_CMDLINE_BOOL=y 55CONFIG_CMDLINE_BOOL=y
@@ -136,9 +136,11 @@ CONFIG_ACENIC_OMIT_TIGON_I=y
136# CONFIG_NET_VENDOR_AQUANTIA is not set 136# CONFIG_NET_VENDOR_AQUANTIA is not set
137# CONFIG_NET_VENDOR_ARC is not set 137# CONFIG_NET_VENDOR_ARC is not set
138# CONFIG_NET_VENDOR_ATHEROS is not set 138# CONFIG_NET_VENDOR_ATHEROS is not set
139# CONFIG_NET_VENDOR_AURORA is not set
139CONFIG_TIGON3=m 140CONFIG_TIGON3=m
140CONFIG_BNX2X=m 141CONFIG_BNX2X=m
141# CONFIG_NET_VENDOR_BROCADE is not set 142# CONFIG_NET_VENDOR_BROCADE is not set
143# CONFIG_NET_VENDOR_CADENCE is not set
142# CONFIG_NET_CADENCE is not set 144# CONFIG_NET_CADENCE is not set
143# CONFIG_NET_VENDOR_CAVIUM is not set 145# CONFIG_NET_VENDOR_CAVIUM is not set
144CONFIG_CHELSIO_T1=m 146CONFIG_CHELSIO_T1=m
@@ -151,6 +153,7 @@ CONFIG_BE2NET=m
151# CONFIG_NET_VENDOR_HP is not set 153# CONFIG_NET_VENDOR_HP is not set
152# CONFIG_NET_VENDOR_HUAWEI is not set 154# CONFIG_NET_VENDOR_HUAWEI is not set
153CONFIG_E1000=m 155CONFIG_E1000=m
156CONFIG_E1000E=m
154CONFIG_IGB=m 157CONFIG_IGB=m
155CONFIG_IXGB=m 158CONFIG_IXGB=m
156CONFIG_IXGBE=m 159CONFIG_IXGBE=m
@@ -161,15 +164,18 @@ CONFIG_MLX4_EN=m
161# CONFIG_MLX4_CORE_GEN2 is not set 164# CONFIG_MLX4_CORE_GEN2 is not set
162CONFIG_MLX5_CORE=m 165CONFIG_MLX5_CORE=m
163# CONFIG_NET_VENDOR_MICREL is not set 166# CONFIG_NET_VENDOR_MICREL is not set
167# CONFIG_NET_VENDOR_MICROSEMI is not set
164CONFIG_MYRI10GE=m 168CONFIG_MYRI10GE=m
165# CONFIG_NET_VENDOR_NATSEMI is not set 169# CONFIG_NET_VENDOR_NATSEMI is not set
166# CONFIG_NET_VENDOR_NETRONOME is not set 170# CONFIG_NET_VENDOR_NETRONOME is not set
167# CONFIG_NET_VENDOR_NI is not set 171# CONFIG_NET_VENDOR_NI is not set
168# CONFIG_NET_VENDOR_NVIDIA is not set 172# CONFIG_NET_VENDOR_NVIDIA is not set
169# CONFIG_NET_VENDOR_OKI is not set 173# CONFIG_NET_VENDOR_OKI is not set
170# CONFIG_NET_PACKET_ENGINE is not set 174# CONFIG_NET_VENDOR_PACKET_ENGINES is not set
171CONFIG_QLGE=m 175CONFIG_QLGE=m
172CONFIG_NETXEN_NIC=m 176CONFIG_NETXEN_NIC=m
177CONFIG_QED=m
178CONFIG_QEDE=m
173# CONFIG_NET_VENDOR_QUALCOMM is not set 179# CONFIG_NET_VENDOR_QUALCOMM is not set
174# CONFIG_NET_VENDOR_RDC is not set 180# CONFIG_NET_VENDOR_RDC is not set
175# CONFIG_NET_VENDOR_REALTEK is not set 181# CONFIG_NET_VENDOR_REALTEK is not set
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 77ff7fb24823..a0c132bedfae 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -5,7 +5,6 @@ generated-y += syscall_table_spu.h
5generic-y += div64.h 5generic-y += div64.h
6generic-y += export.h 6generic-y += export.h
7generic-y += irq_regs.h 7generic-y += irq_regs.h
8generic-y += irq_work.h
9generic-y += local64.h 8generic-y += local64.h
10generic-y += mcs_spinlock.h 9generic-y += mcs_spinlock.h
11generic-y += preempt.h 10generic-y += preempt.h
diff --git a/arch/powerpc/include/asm/book3s/64/hugetlb.h b/arch/powerpc/include/asm/book3s/64/hugetlb.h
index 66c1e4f88d65..ec2a55a553c7 100644
--- a/arch/powerpc/include/asm/book3s/64/hugetlb.h
+++ b/arch/powerpc/include/asm/book3s/64/hugetlb.h
@@ -39,6 +39,14 @@ static inline int hstate_get_psize(struct hstate *hstate)
39#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE 39#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
40static inline bool gigantic_page_supported(void) 40static inline bool gigantic_page_supported(void)
41{ 41{
42 /*
43 * We used gigantic page reservation with hypervisor assist in some case.
44 * We cannot use runtime allocation of gigantic pages in those platforms
45 * This is hash translation mode LPARs.
46 */
47 if (firmware_has_feature(FW_FEATURE_LPAR) && !radix_enabled())
48 return false;
49
42 return true; 50 return true;
43} 51}
44#endif 52#endif
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 0f98f00da2ea..e6b5bb012ccb 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -99,6 +99,8 @@ struct kvm_nested_guest;
99 99
100struct kvm_vm_stat { 100struct kvm_vm_stat {
101 ulong remote_tlb_flush; 101 ulong remote_tlb_flush;
102 ulong num_2M_pages;
103 ulong num_1G_pages;
102}; 104};
103 105
104struct kvm_vcpu_stat { 106struct kvm_vcpu_stat {
@@ -377,6 +379,7 @@ struct kvmppc_mmu {
377 void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs); 379 void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs);
378 u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr); 380 u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr);
379 u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr); 381 u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr);
382 int (*slbfee)(struct kvm_vcpu *vcpu, gva_t eaddr, ulong *ret_slb);
380 void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr); 383 void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr);
381 void (*slbia)(struct kvm_vcpu *vcpu); 384 void (*slbia)(struct kvm_vcpu *vcpu);
382 /* book3s */ 385 /* book3s */
@@ -837,7 +840,7 @@ struct kvm_vcpu_arch {
837static inline void kvm_arch_hardware_disable(void) {} 840static inline void kvm_arch_hardware_disable(void) {}
838static inline void kvm_arch_hardware_unsetup(void) {} 841static inline void kvm_arch_hardware_unsetup(void) {}
839static inline void kvm_arch_sync_events(struct kvm *kvm) {} 842static inline void kvm_arch_sync_events(struct kvm *kvm) {}
840static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {} 843static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
841static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {} 844static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
842static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} 845static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
843static inline void kvm_arch_exit(void) {} 846static inline void kvm_arch_exit(void) {}
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index a6c8548ed9fa..ac22b28ae78d 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -36,6 +36,8 @@
36#endif 36#endif
37#ifdef CONFIG_KVM_BOOK3S_64_HANDLER 37#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
38#include <asm/paca.h> 38#include <asm/paca.h>
39#include <asm/xive.h>
40#include <asm/cpu_has_feature.h>
39#endif 41#endif
40 42
41/* 43/*
@@ -617,6 +619,18 @@ static inline int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 ir
617static inline void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu) { } 619static inline void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu) { }
618#endif /* CONFIG_KVM_XIVE */ 620#endif /* CONFIG_KVM_XIVE */
619 621
622#if defined(CONFIG_PPC_POWERNV) && defined(CONFIG_KVM_BOOK3S_64_HANDLER)
623static inline bool xics_on_xive(void)
624{
625 return xive_enabled() && cpu_has_feature(CPU_FTR_HVMODE);
626}
627#else
628static inline bool xics_on_xive(void)
629{
630 return false;
631}
632#endif
633
620/* 634/*
621 * Prototypes for functions called only from assembler code. 635 * Prototypes for functions called only from assembler code.
622 * Having prototypes reduces sparse errors. 636 * Having prototypes reduces sparse errors.
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/include/uapi/asm/Kbuild b/arch/powerpc/include/uapi/asm/Kbuild
index 214a39acdf25..2bd5b392277c 100644
--- a/arch/powerpc/include/uapi/asm/Kbuild
+++ b/arch/powerpc/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h 1generated-y += unistd_32.h
4generated-y += unistd_64.h 2generated-y += unistd_64.h
diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h
index 8c876c166ef2..26ca425f4c2c 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -463,10 +463,12 @@ struct kvm_ppc_cpu_char {
463#define KVM_PPC_CPU_CHAR_BR_HINT_HONOURED (1ULL << 58) 463#define KVM_PPC_CPU_CHAR_BR_HINT_HONOURED (1ULL << 58)
464#define KVM_PPC_CPU_CHAR_MTTRIG_THR_RECONF (1ULL << 57) 464#define KVM_PPC_CPU_CHAR_MTTRIG_THR_RECONF (1ULL << 57)
465#define KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS (1ULL << 56) 465#define KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS (1ULL << 56)
466#define KVM_PPC_CPU_CHAR_BCCTR_FLUSH_ASSIST (1ull << 54)
466 467
467#define KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY (1ULL << 63) 468#define KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY (1ULL << 63)
468#define KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR (1ULL << 62) 469#define KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR (1ULL << 62)
469#define KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR (1ULL << 61) 470#define KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR (1ULL << 61)
471#define KVM_PPC_CPU_BEHAV_FLUSH_COUNT_CACHE (1ull << 58)
470 472
471/* Per-vcpu XICS interrupt controller state */ 473/* Per-vcpu XICS interrupt controller state */
472#define KVM_REG_PPC_ICP_STATE (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8c) 474#define KVM_REG_PPC_ICP_STATE (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8c)
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/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S
index 1881127682e9..32332e24e421 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -194,13 +194,6 @@ set_ivor:
194#endif 194#endif
195 mtspr SPRN_MAS4, r2 195 mtspr SPRN_MAS4, r2
196 196
197#if 0
198 /* Enable DOZE */
199 mfspr r2,SPRN_HID0
200 oris r2,r2,HID0_DOZE@h
201 mtspr SPRN_HID0, r2
202#endif
203
204#if !defined(CONFIG_BDI_SWITCH) 197#if !defined(CONFIG_BDI_SWITCH)
205 /* 198 /*
206 * The Abatron BDI JTAG debugger does not tolerate others 199 * The Abatron BDI JTAG debugger does not tolerate others
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/traps.c b/arch/powerpc/kernel/traps.c
index a21200c6aaea..1fd45a8650e1 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -71,6 +71,7 @@
71#include <sysdev/fsl_pci.h> 71#include <sysdev/fsl_pci.h>
72#include <asm/kprobes.h> 72#include <asm/kprobes.h>
73#include <asm/stacktrace.h> 73#include <asm/stacktrace.h>
74#include <asm/nmi.h>
74 75
75#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE) 76#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE)
76int (*__debugger)(struct pt_regs *regs) __read_mostly; 77int (*__debugger)(struct pt_regs *regs) __read_mostly;
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/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 9a7dadbe1f17..10c5579d20ce 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -39,6 +39,7 @@
39#include "book3s.h" 39#include "book3s.h"
40#include "trace.h" 40#include "trace.h"
41 41
42#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
42#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU 43#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
43 44
44/* #define EXIT_DEBUG */ 45/* #define EXIT_DEBUG */
@@ -71,6 +72,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
71 { "pthru_all", VCPU_STAT(pthru_all) }, 72 { "pthru_all", VCPU_STAT(pthru_all) },
72 { "pthru_host", VCPU_STAT(pthru_host) }, 73 { "pthru_host", VCPU_STAT(pthru_host) },
73 { "pthru_bad_aff", VCPU_STAT(pthru_bad_aff) }, 74 { "pthru_bad_aff", VCPU_STAT(pthru_bad_aff) },
75 { "largepages_2M", VM_STAT(num_2M_pages) },
76 { "largepages_1G", VM_STAT(num_1G_pages) },
74 { NULL } 77 { NULL }
75}; 78};
76 79
@@ -642,7 +645,7 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
642 r = -ENXIO; 645 r = -ENXIO;
643 break; 646 break;
644 } 647 }
645 if (xive_enabled()) 648 if (xics_on_xive())
646 *val = get_reg_val(id, kvmppc_xive_get_icp(vcpu)); 649 *val = get_reg_val(id, kvmppc_xive_get_icp(vcpu));
647 else 650 else
648 *val = get_reg_val(id, kvmppc_xics_get_icp(vcpu)); 651 *val = get_reg_val(id, kvmppc_xics_get_icp(vcpu));
@@ -715,7 +718,7 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
715 r = -ENXIO; 718 r = -ENXIO;
716 break; 719 break;
717 } 720 }
718 if (xive_enabled()) 721 if (xics_on_xive())
719 r = kvmppc_xive_set_icp(vcpu, set_reg_val(id, *val)); 722 r = kvmppc_xive_set_icp(vcpu, set_reg_val(id, *val));
720 else 723 else
721 r = kvmppc_xics_set_icp(vcpu, set_reg_val(id, *val)); 724 r = kvmppc_xics_set_icp(vcpu, set_reg_val(id, *val));
@@ -991,7 +994,7 @@ int kvmppc_book3s_hcall_implemented(struct kvm *kvm, unsigned long hcall)
991int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, 994int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
992 bool line_status) 995 bool line_status)
993{ 996{
994 if (xive_enabled()) 997 if (xics_on_xive())
995 return kvmppc_xive_set_irq(kvm, irq_source_id, irq, level, 998 return kvmppc_xive_set_irq(kvm, irq_source_id, irq, level,
996 line_status); 999 line_status);
997 else 1000 else
@@ -1044,7 +1047,7 @@ static int kvmppc_book3s_init(void)
1044 1047
1045#ifdef CONFIG_KVM_XICS 1048#ifdef CONFIG_KVM_XICS
1046#ifdef CONFIG_KVM_XIVE 1049#ifdef CONFIG_KVM_XIVE
1047 if (xive_enabled()) { 1050 if (xics_on_xive()) {
1048 kvmppc_xive_init_module(); 1051 kvmppc_xive_init_module();
1049 kvm_register_device_ops(&kvm_xive_ops, KVM_DEV_TYPE_XICS); 1052 kvm_register_device_ops(&kvm_xive_ops, KVM_DEV_TYPE_XICS);
1050 } else 1053 } else
@@ -1057,7 +1060,7 @@ static int kvmppc_book3s_init(void)
1057static void kvmppc_book3s_exit(void) 1060static void kvmppc_book3s_exit(void)
1058{ 1061{
1059#ifdef CONFIG_KVM_XICS 1062#ifdef CONFIG_KVM_XICS
1060 if (xive_enabled()) 1063 if (xics_on_xive())
1061 kvmppc_xive_exit_module(); 1064 kvmppc_xive_exit_module();
1062#endif 1065#endif
1063#ifdef CONFIG_KVM_BOOK3S_32_HANDLER 1066#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
diff --git a/arch/powerpc/kvm/book3s_32_mmu.c b/arch/powerpc/kvm/book3s_32_mmu.c
index 612169988a3d..6f789f674048 100644
--- a/arch/powerpc/kvm/book3s_32_mmu.c
+++ b/arch/powerpc/kvm/book3s_32_mmu.c
@@ -425,6 +425,7 @@ void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu)
425 mmu->slbmte = NULL; 425 mmu->slbmte = NULL;
426 mmu->slbmfee = NULL; 426 mmu->slbmfee = NULL;
427 mmu->slbmfev = NULL; 427 mmu->slbmfev = NULL;
428 mmu->slbfee = NULL;
428 mmu->slbie = NULL; 429 mmu->slbie = NULL;
429 mmu->slbia = NULL; 430 mmu->slbia = NULL;
430} 431}
diff --git a/arch/powerpc/kvm/book3s_64_mmu.c b/arch/powerpc/kvm/book3s_64_mmu.c
index c92dd25bed23..d4b967f0e8d4 100644
--- a/arch/powerpc/kvm/book3s_64_mmu.c
+++ b/arch/powerpc/kvm/book3s_64_mmu.c
@@ -435,6 +435,19 @@ static void kvmppc_mmu_book3s_64_slbmte(struct kvm_vcpu *vcpu, u64 rs, u64 rb)
435 kvmppc_mmu_map_segment(vcpu, esid << SID_SHIFT); 435 kvmppc_mmu_map_segment(vcpu, esid << SID_SHIFT);
436} 436}
437 437
438static int kvmppc_mmu_book3s_64_slbfee(struct kvm_vcpu *vcpu, gva_t eaddr,
439 ulong *ret_slb)
440{
441 struct kvmppc_slb *slbe = kvmppc_mmu_book3s_64_find_slbe(vcpu, eaddr);
442
443 if (slbe) {
444 *ret_slb = slbe->origv;
445 return 0;
446 }
447 *ret_slb = 0;
448 return -ENOENT;
449}
450
438static u64 kvmppc_mmu_book3s_64_slbmfee(struct kvm_vcpu *vcpu, u64 slb_nr) 451static u64 kvmppc_mmu_book3s_64_slbmfee(struct kvm_vcpu *vcpu, u64 slb_nr)
439{ 452{
440 struct kvmppc_slb *slbe; 453 struct kvmppc_slb *slbe;
@@ -670,6 +683,7 @@ void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu)
670 mmu->slbmte = kvmppc_mmu_book3s_64_slbmte; 683 mmu->slbmte = kvmppc_mmu_book3s_64_slbmte;
671 mmu->slbmfee = kvmppc_mmu_book3s_64_slbmfee; 684 mmu->slbmfee = kvmppc_mmu_book3s_64_slbmfee;
672 mmu->slbmfev = kvmppc_mmu_book3s_64_slbmfev; 685 mmu->slbmfev = kvmppc_mmu_book3s_64_slbmfev;
686 mmu->slbfee = kvmppc_mmu_book3s_64_slbfee;
673 mmu->slbie = kvmppc_mmu_book3s_64_slbie; 687 mmu->slbie = kvmppc_mmu_book3s_64_slbie;
674 mmu->slbia = kvmppc_mmu_book3s_64_slbia; 688 mmu->slbia = kvmppc_mmu_book3s_64_slbia;
675 mmu->xlate = kvmppc_mmu_book3s_64_xlate; 689 mmu->xlate = kvmppc_mmu_book3s_64_xlate;
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index bd2dcfbf00cd..be7bc070eae5 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -442,6 +442,24 @@ int kvmppc_hv_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu,
442 u32 last_inst; 442 u32 last_inst;
443 443
444 /* 444 /*
445 * Fast path - check if the guest physical address corresponds to a
446 * device on the FAST_MMIO_BUS, if so we can avoid loading the
447 * instruction all together, then we can just handle it and return.
448 */
449 if (is_store) {
450 int idx, ret;
451
452 idx = srcu_read_lock(&vcpu->kvm->srcu);
453 ret = kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, (gpa_t) gpa, 0,
454 NULL);
455 srcu_read_unlock(&vcpu->kvm->srcu, idx);
456 if (!ret) {
457 kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4);
458 return RESUME_GUEST;
459 }
460 }
461
462 /*
445 * If we fail, we just return to the guest and try executing it again. 463 * If we fail, we just return to the guest and try executing it again.
446 */ 464 */
447 if (kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) != 465 if (kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) !=
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index 1b821c6efdef..f55ef071883f 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -403,8 +403,13 @@ void kvmppc_unmap_pte(struct kvm *kvm, pte_t *pte, unsigned long gpa,
403 if (!memslot) 403 if (!memslot)
404 return; 404 return;
405 } 405 }
406 if (shift) 406 if (shift) { /* 1GB or 2MB page */
407 page_size = 1ul << shift; 407 page_size = 1ul << shift;
408 if (shift == PMD_SHIFT)
409 kvm->stat.num_2M_pages--;
410 else if (shift == PUD_SHIFT)
411 kvm->stat.num_1G_pages--;
412 }
408 413
409 gpa &= ~(page_size - 1); 414 gpa &= ~(page_size - 1);
410 hpa = old & PTE_RPN_MASK; 415 hpa = old & PTE_RPN_MASK;
@@ -878,6 +883,14 @@ int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu,
878 put_page(page); 883 put_page(page);
879 } 884 }
880 885
886 /* Increment number of large pages if we (successfully) inserted one */
887 if (!ret) {
888 if (level == 1)
889 kvm->stat.num_2M_pages++;
890 else if (level == 2)
891 kvm->stat.num_1G_pages++;
892 }
893
881 return ret; 894 return ret;
882} 895}
883 896
diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index 532ab79734c7..f02b04973710 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -133,7 +133,6 @@ extern void kvm_spapr_tce_release_iommu_group(struct kvm *kvm,
133 continue; 133 continue;
134 134
135 kref_put(&stit->kref, kvm_spapr_tce_liobn_put); 135 kref_put(&stit->kref, kvm_spapr_tce_liobn_put);
136 return;
137 } 136 }
138 } 137 }
139 } 138 }
@@ -338,14 +337,15 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
338 } 337 }
339 } 338 }
340 339
340 kvm_get_kvm(kvm);
341 if (!ret) 341 if (!ret)
342 ret = anon_inode_getfd("kvm-spapr-tce", &kvm_spapr_tce_fops, 342 ret = anon_inode_getfd("kvm-spapr-tce", &kvm_spapr_tce_fops,
343 stt, O_RDWR | O_CLOEXEC); 343 stt, O_RDWR | O_CLOEXEC);
344 344
345 if (ret >= 0) { 345 if (ret >= 0)
346 list_add_rcu(&stt->list, &kvm->arch.spapr_tce_tables); 346 list_add_rcu(&stt->list, &kvm->arch.spapr_tce_tables);
347 kvm_get_kvm(kvm); 347 else
348 } 348 kvm_put_kvm(kvm);
349 349
350 mutex_unlock(&kvm->lock); 350 mutex_unlock(&kvm->lock);
351 351
diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
index 8c7e933e942e..6ef7c5f00a49 100644
--- a/arch/powerpc/kvm/book3s_emulate.c
+++ b/arch/powerpc/kvm/book3s_emulate.c
@@ -47,6 +47,7 @@
47#define OP_31_XOP_SLBMFEV 851 47#define OP_31_XOP_SLBMFEV 851
48#define OP_31_XOP_EIOIO 854 48#define OP_31_XOP_EIOIO 854
49#define OP_31_XOP_SLBMFEE 915 49#define OP_31_XOP_SLBMFEE 915
50#define OP_31_XOP_SLBFEE 979
50 51
51#define OP_31_XOP_TBEGIN 654 52#define OP_31_XOP_TBEGIN 654
52#define OP_31_XOP_TABORT 910 53#define OP_31_XOP_TABORT 910
@@ -416,6 +417,23 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
416 417
417 vcpu->arch.mmu.slbia(vcpu); 418 vcpu->arch.mmu.slbia(vcpu);
418 break; 419 break;
420 case OP_31_XOP_SLBFEE:
421 if (!(inst & 1) || !vcpu->arch.mmu.slbfee) {
422 return EMULATE_FAIL;
423 } else {
424 ulong b, t;
425 ulong cr = kvmppc_get_cr(vcpu) & ~CR0_MASK;
426
427 b = kvmppc_get_gpr(vcpu, rb);
428 if (!vcpu->arch.mmu.slbfee(vcpu, b, &t))
429 cr |= 2 << CR0_SHIFT;
430 kvmppc_set_gpr(vcpu, rt, t);
431 /* copy XER[SO] bit to CR0[SO] */
432 cr |= (vcpu->arch.regs.xer & 0x80000000) >>
433 (31 - CR0_SHIFT);
434 kvmppc_set_cr(vcpu, cr);
435 }
436 break;
419 case OP_31_XOP_SLBMFEE: 437 case OP_31_XOP_SLBMFEE:
420 if (!vcpu->arch.mmu.slbmfee) { 438 if (!vcpu->arch.mmu.slbmfee) {
421 emulated = EMULATE_FAIL; 439 emulated = EMULATE_FAIL;
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index a3d5318f5d1e..06964350b97a 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -922,7 +922,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
922 case H_IPOLL: 922 case H_IPOLL:
923 case H_XIRR_X: 923 case H_XIRR_X:
924 if (kvmppc_xics_enabled(vcpu)) { 924 if (kvmppc_xics_enabled(vcpu)) {
925 if (xive_enabled()) { 925 if (xics_on_xive()) {
926 ret = H_NOT_AVAILABLE; 926 ret = H_NOT_AVAILABLE;
927 return RESUME_GUEST; 927 return RESUME_GUEST;
928 } 928 }
@@ -937,6 +937,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
937 ret = kvmppc_h_set_xdabr(vcpu, kvmppc_get_gpr(vcpu, 4), 937 ret = kvmppc_h_set_xdabr(vcpu, kvmppc_get_gpr(vcpu, 4),
938 kvmppc_get_gpr(vcpu, 5)); 938 kvmppc_get_gpr(vcpu, 5));
939 break; 939 break;
940#ifdef CONFIG_SPAPR_TCE_IOMMU
940 case H_GET_TCE: 941 case H_GET_TCE:
941 ret = kvmppc_h_get_tce(vcpu, kvmppc_get_gpr(vcpu, 4), 942 ret = kvmppc_h_get_tce(vcpu, kvmppc_get_gpr(vcpu, 4),
942 kvmppc_get_gpr(vcpu, 5)); 943 kvmppc_get_gpr(vcpu, 5));
@@ -966,6 +967,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
966 if (ret == H_TOO_HARD) 967 if (ret == H_TOO_HARD)
967 return RESUME_HOST; 968 return RESUME_HOST;
968 break; 969 break;
970#endif
969 case H_RANDOM: 971 case H_RANDOM:
970 if (!powernv_get_random_long(&vcpu->arch.regs.gpr[4])) 972 if (!powernv_get_random_long(&vcpu->arch.regs.gpr[4]))
971 ret = H_HARDWARE; 973 ret = H_HARDWARE;
@@ -1445,7 +1447,7 @@ static int kvmppc_handle_nested_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
1445 case BOOK3S_INTERRUPT_HV_RM_HARD: 1447 case BOOK3S_INTERRUPT_HV_RM_HARD:
1446 vcpu->arch.trap = 0; 1448 vcpu->arch.trap = 0;
1447 r = RESUME_GUEST; 1449 r = RESUME_GUEST;
1448 if (!xive_enabled()) 1450 if (!xics_on_xive())
1449 kvmppc_xics_rm_complete(vcpu, 0); 1451 kvmppc_xics_rm_complete(vcpu, 0);
1450 break; 1452 break;
1451 default: 1453 default:
@@ -3648,11 +3650,12 @@ static void kvmppc_wait_for_exec(struct kvmppc_vcore *vc,
3648 3650
3649static void grow_halt_poll_ns(struct kvmppc_vcore *vc) 3651static void grow_halt_poll_ns(struct kvmppc_vcore *vc)
3650{ 3652{
3651 /* 10us base */ 3653 if (!halt_poll_ns_grow)
3652 if (vc->halt_poll_ns == 0 && halt_poll_ns_grow) 3654 return;
3653 vc->halt_poll_ns = 10000; 3655
3654 else 3656 vc->halt_poll_ns *= halt_poll_ns_grow;
3655 vc->halt_poll_ns *= halt_poll_ns_grow; 3657 if (vc->halt_poll_ns < halt_poll_ns_grow_start)
3658 vc->halt_poll_ns = halt_poll_ns_grow_start;
3656} 3659}
3657 3660
3658static void shrink_halt_poll_ns(struct kvmppc_vcore *vc) 3661static void shrink_halt_poll_ns(struct kvmppc_vcore *vc)
@@ -3666,7 +3669,7 @@ static void shrink_halt_poll_ns(struct kvmppc_vcore *vc)
3666#ifdef CONFIG_KVM_XICS 3669#ifdef CONFIG_KVM_XICS
3667static inline bool xive_interrupt_pending(struct kvm_vcpu *vcpu) 3670static inline bool xive_interrupt_pending(struct kvm_vcpu *vcpu)
3668{ 3671{
3669 if (!xive_enabled()) 3672 if (!xics_on_xive())
3670 return false; 3673 return false;
3671 return vcpu->arch.irq_pending || vcpu->arch.xive_saved_state.pipr < 3674 return vcpu->arch.irq_pending || vcpu->arch.xive_saved_state.pipr <
3672 vcpu->arch.xive_saved_state.cppr; 3675 vcpu->arch.xive_saved_state.cppr;
@@ -4226,7 +4229,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
4226 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); 4229 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr);
4227 srcu_read_unlock(&kvm->srcu, srcu_idx); 4230 srcu_read_unlock(&kvm->srcu, srcu_idx);
4228 } else if (r == RESUME_PASSTHROUGH) { 4231 } else if (r == RESUME_PASSTHROUGH) {
4229 if (WARN_ON(xive_enabled())) 4232 if (WARN_ON(xics_on_xive()))
4230 r = H_SUCCESS; 4233 r = H_SUCCESS;
4231 else 4234 else
4232 r = kvmppc_xics_rm_complete(vcpu, 0); 4235 r = kvmppc_xics_rm_complete(vcpu, 0);
@@ -4750,7 +4753,7 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
4750 * If xive is enabled, we route 0x500 interrupts directly 4753 * If xive is enabled, we route 0x500 interrupts directly
4751 * to the guest. 4754 * to the guest.
4752 */ 4755 */
4753 if (xive_enabled()) 4756 if (xics_on_xive())
4754 lpcr |= LPCR_LPES; 4757 lpcr |= LPCR_LPES;
4755 } 4758 }
4756 4759
@@ -4986,7 +4989,7 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
4986 if (i == pimap->n_mapped) 4989 if (i == pimap->n_mapped)
4987 pimap->n_mapped++; 4990 pimap->n_mapped++;
4988 4991
4989 if (xive_enabled()) 4992 if (xics_on_xive())
4990 rc = kvmppc_xive_set_mapped(kvm, guest_gsi, desc); 4993 rc = kvmppc_xive_set_mapped(kvm, guest_gsi, desc);
4991 else 4994 else
4992 kvmppc_xics_set_mapped(kvm, guest_gsi, desc->irq_data.hwirq); 4995 kvmppc_xics_set_mapped(kvm, guest_gsi, desc->irq_data.hwirq);
@@ -5027,7 +5030,7 @@ static int kvmppc_clr_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
5027 return -ENODEV; 5030 return -ENODEV;
5028 } 5031 }
5029 5032
5030 if (xive_enabled()) 5033 if (xics_on_xive())
5031 rc = kvmppc_xive_clr_mapped(kvm, guest_gsi, pimap->mapped[i].desc); 5034 rc = kvmppc_xive_clr_mapped(kvm, guest_gsi, pimap->mapped[i].desc);
5032 else 5035 else
5033 kvmppc_xics_clr_mapped(kvm, guest_gsi, pimap->mapped[i].r_hwirq); 5036 kvmppc_xics_clr_mapped(kvm, guest_gsi, pimap->mapped[i].r_hwirq);
@@ -5359,13 +5362,11 @@ static int kvm_init_subcore_bitmap(void)
5359 continue; 5362 continue;
5360 5363
5361 sibling_subcore_state = 5364 sibling_subcore_state =
5362 kmalloc_node(sizeof(struct sibling_subcore_state), 5365 kzalloc_node(sizeof(struct sibling_subcore_state),
5363 GFP_KERNEL, node); 5366 GFP_KERNEL, node);
5364 if (!sibling_subcore_state) 5367 if (!sibling_subcore_state)
5365 return -ENOMEM; 5368 return -ENOMEM;
5366 5369
5367 memset(sibling_subcore_state, 0,
5368 sizeof(struct sibling_subcore_state));
5369 5370
5370 for (j = 0; j < threads_per_core; j++) { 5371 for (j = 0; j < threads_per_core; j++) {
5371 int cpu = first_cpu + j; 5372 int cpu = first_cpu + j;
@@ -5406,7 +5407,7 @@ static int kvmppc_book3s_init_hv(void)
5406 * indirectly, via OPAL. 5407 * indirectly, via OPAL.
5407 */ 5408 */
5408#ifdef CONFIG_SMP 5409#ifdef CONFIG_SMP
5409 if (!xive_enabled() && !kvmhv_on_pseries() && 5410 if (!xics_on_xive() && !kvmhv_on_pseries() &&
5410 !local_paca->kvm_hstate.xics_phys) { 5411 !local_paca->kvm_hstate.xics_phys) {
5411 struct device_node *np; 5412 struct device_node *np;
5412 5413
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
index a71e2fc00a4e..b0cf22477e87 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -257,7 +257,7 @@ void kvmhv_rm_send_ipi(int cpu)
257 } 257 }
258 258
259 /* We should never reach this */ 259 /* We should never reach this */
260 if (WARN_ON_ONCE(xive_enabled())) 260 if (WARN_ON_ONCE(xics_on_xive()))
261 return; 261 return;
262 262
263 /* Else poke the target with an IPI */ 263 /* Else poke the target with an IPI */
@@ -577,7 +577,7 @@ unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu)
577{ 577{
578 if (!kvmppc_xics_enabled(vcpu)) 578 if (!kvmppc_xics_enabled(vcpu))
579 return H_TOO_HARD; 579 return H_TOO_HARD;
580 if (xive_enabled()) { 580 if (xics_on_xive()) {
581 if (is_rm()) 581 if (is_rm())
582 return xive_rm_h_xirr(vcpu); 582 return xive_rm_h_xirr(vcpu);
583 if (unlikely(!__xive_vm_h_xirr)) 583 if (unlikely(!__xive_vm_h_xirr))
@@ -592,7 +592,7 @@ unsigned long kvmppc_rm_h_xirr_x(struct kvm_vcpu *vcpu)
592 if (!kvmppc_xics_enabled(vcpu)) 592 if (!kvmppc_xics_enabled(vcpu))
593 return H_TOO_HARD; 593 return H_TOO_HARD;
594 vcpu->arch.regs.gpr[5] = get_tb(); 594 vcpu->arch.regs.gpr[5] = get_tb();
595 if (xive_enabled()) { 595 if (xics_on_xive()) {
596 if (is_rm()) 596 if (is_rm())
597 return xive_rm_h_xirr(vcpu); 597 return xive_rm_h_xirr(vcpu);
598 if (unlikely(!__xive_vm_h_xirr)) 598 if (unlikely(!__xive_vm_h_xirr))
@@ -606,7 +606,7 @@ unsigned long kvmppc_rm_h_ipoll(struct kvm_vcpu *vcpu, unsigned long server)
606{ 606{
607 if (!kvmppc_xics_enabled(vcpu)) 607 if (!kvmppc_xics_enabled(vcpu))
608 return H_TOO_HARD; 608 return H_TOO_HARD;
609 if (xive_enabled()) { 609 if (xics_on_xive()) {
610 if (is_rm()) 610 if (is_rm())
611 return xive_rm_h_ipoll(vcpu, server); 611 return xive_rm_h_ipoll(vcpu, server);
612 if (unlikely(!__xive_vm_h_ipoll)) 612 if (unlikely(!__xive_vm_h_ipoll))
@@ -621,7 +621,7 @@ int kvmppc_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
621{ 621{
622 if (!kvmppc_xics_enabled(vcpu)) 622 if (!kvmppc_xics_enabled(vcpu))
623 return H_TOO_HARD; 623 return H_TOO_HARD;
624 if (xive_enabled()) { 624 if (xics_on_xive()) {
625 if (is_rm()) 625 if (is_rm())
626 return xive_rm_h_ipi(vcpu, server, mfrr); 626 return xive_rm_h_ipi(vcpu, server, mfrr);
627 if (unlikely(!__xive_vm_h_ipi)) 627 if (unlikely(!__xive_vm_h_ipi))
@@ -635,7 +635,7 @@ int kvmppc_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr)
635{ 635{
636 if (!kvmppc_xics_enabled(vcpu)) 636 if (!kvmppc_xics_enabled(vcpu))
637 return H_TOO_HARD; 637 return H_TOO_HARD;
638 if (xive_enabled()) { 638 if (xics_on_xive()) {
639 if (is_rm()) 639 if (is_rm())
640 return xive_rm_h_cppr(vcpu, cppr); 640 return xive_rm_h_cppr(vcpu, cppr);
641 if (unlikely(!__xive_vm_h_cppr)) 641 if (unlikely(!__xive_vm_h_cppr))
@@ -649,7 +649,7 @@ int kvmppc_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr)
649{ 649{
650 if (!kvmppc_xics_enabled(vcpu)) 650 if (!kvmppc_xics_enabled(vcpu))
651 return H_TOO_HARD; 651 return H_TOO_HARD;
652 if (xive_enabled()) { 652 if (xics_on_xive()) {
653 if (is_rm()) 653 if (is_rm())
654 return xive_rm_h_eoi(vcpu, xirr); 654 return xive_rm_h_eoi(vcpu, xirr);
655 if (unlikely(!__xive_vm_h_eoi)) 655 if (unlikely(!__xive_vm_h_eoi))
diff --git a/arch/powerpc/kvm/book3s_hv_rm_xics.c b/arch/powerpc/kvm/book3s_hv_rm_xics.c
index b3f5786b20dc..3b9662a4207e 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_xics.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_xics.c
@@ -144,6 +144,13 @@ static void icp_rm_set_vcpu_irq(struct kvm_vcpu *vcpu,
144 return; 144 return;
145 } 145 }
146 146
147 if (xive_enabled() && kvmhv_on_pseries()) {
148 /* No XICS access or hypercalls available, too hard */
149 this_icp->rm_action |= XICS_RM_KICK_VCPU;
150 this_icp->rm_kick_target = vcpu;
151 return;
152 }
153
147 /* 154 /*
148 * Check if the core is loaded, 155 * Check if the core is loaded,
149 * if not, find an available host core to post to wake the VCPU, 156 * if not, find an available host core to post to wake the VCPU,
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 25043b50cb30..3a5e719ef032 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -2272,8 +2272,13 @@ hcall_real_table:
2272 .long DOTSYM(kvmppc_h_clear_mod) - hcall_real_table 2272 .long DOTSYM(kvmppc_h_clear_mod) - hcall_real_table
2273 .long DOTSYM(kvmppc_h_clear_ref) - hcall_real_table 2273 .long DOTSYM(kvmppc_h_clear_ref) - hcall_real_table
2274 .long DOTSYM(kvmppc_h_protect) - hcall_real_table 2274 .long DOTSYM(kvmppc_h_protect) - hcall_real_table
2275#ifdef CONFIG_SPAPR_TCE_IOMMU
2275 .long DOTSYM(kvmppc_h_get_tce) - hcall_real_table 2276 .long DOTSYM(kvmppc_h_get_tce) - hcall_real_table
2276 .long DOTSYM(kvmppc_rm_h_put_tce) - hcall_real_table 2277 .long DOTSYM(kvmppc_rm_h_put_tce) - hcall_real_table
2278#else
2279 .long 0 /* 0x1c */
2280 .long 0 /* 0x20 */
2281#endif
2277 .long 0 /* 0x24 - H_SET_SPRG0 */ 2282 .long 0 /* 0x24 - H_SET_SPRG0 */
2278 .long DOTSYM(kvmppc_h_set_dabr) - hcall_real_table 2283 .long DOTSYM(kvmppc_h_set_dabr) - hcall_real_table
2279 .long 0 /* 0x2c */ 2284 .long 0 /* 0x2c */
@@ -2351,8 +2356,13 @@ hcall_real_table:
2351 .long 0 /* 0x12c */ 2356 .long 0 /* 0x12c */
2352 .long 0 /* 0x130 */ 2357 .long 0 /* 0x130 */
2353 .long DOTSYM(kvmppc_h_set_xdabr) - hcall_real_table 2358 .long DOTSYM(kvmppc_h_set_xdabr) - hcall_real_table
2359#ifdef CONFIG_SPAPR_TCE_IOMMU
2354 .long DOTSYM(kvmppc_rm_h_stuff_tce) - hcall_real_table 2360 .long DOTSYM(kvmppc_rm_h_stuff_tce) - hcall_real_table
2355 .long DOTSYM(kvmppc_rm_h_put_tce_indirect) - hcall_real_table 2361 .long DOTSYM(kvmppc_rm_h_put_tce_indirect) - hcall_real_table
2362#else
2363 .long 0 /* 0x138 */
2364 .long 0 /* 0x13c */
2365#endif
2356 .long 0 /* 0x140 */ 2366 .long 0 /* 0x140 */
2357 .long 0 /* 0x144 */ 2367 .long 0 /* 0x144 */
2358 .long 0 /* 0x148 */ 2368 .long 0 /* 0x148 */
diff --git a/arch/powerpc/kvm/book3s_rtas.c b/arch/powerpc/kvm/book3s_rtas.c
index 2d3b2b1cc272..4e178c4c1ea5 100644
--- a/arch/powerpc/kvm/book3s_rtas.c
+++ b/arch/powerpc/kvm/book3s_rtas.c
@@ -33,7 +33,7 @@ static void kvm_rtas_set_xive(struct kvm_vcpu *vcpu, struct rtas_args *args)
33 server = be32_to_cpu(args->args[1]); 33 server = be32_to_cpu(args->args[1]);
34 priority = be32_to_cpu(args->args[2]); 34 priority = be32_to_cpu(args->args[2]);
35 35
36 if (xive_enabled()) 36 if (xics_on_xive())
37 rc = kvmppc_xive_set_xive(vcpu->kvm, irq, server, priority); 37 rc = kvmppc_xive_set_xive(vcpu->kvm, irq, server, priority);
38 else 38 else
39 rc = kvmppc_xics_set_xive(vcpu->kvm, irq, server, priority); 39 rc = kvmppc_xics_set_xive(vcpu->kvm, irq, server, priority);
@@ -56,7 +56,7 @@ static void kvm_rtas_get_xive(struct kvm_vcpu *vcpu, struct rtas_args *args)
56 irq = be32_to_cpu(args->args[0]); 56 irq = be32_to_cpu(args->args[0]);
57 57
58 server = priority = 0; 58 server = priority = 0;
59 if (xive_enabled()) 59 if (xics_on_xive())
60 rc = kvmppc_xive_get_xive(vcpu->kvm, irq, &server, &priority); 60 rc = kvmppc_xive_get_xive(vcpu->kvm, irq, &server, &priority);
61 else 61 else
62 rc = kvmppc_xics_get_xive(vcpu->kvm, irq, &server, &priority); 62 rc = kvmppc_xics_get_xive(vcpu->kvm, irq, &server, &priority);
@@ -83,7 +83,7 @@ static void kvm_rtas_int_off(struct kvm_vcpu *vcpu, struct rtas_args *args)
83 83
84 irq = be32_to_cpu(args->args[0]); 84 irq = be32_to_cpu(args->args[0]);
85 85
86 if (xive_enabled()) 86 if (xics_on_xive())
87 rc = kvmppc_xive_int_off(vcpu->kvm, irq); 87 rc = kvmppc_xive_int_off(vcpu->kvm, irq);
88 else 88 else
89 rc = kvmppc_xics_int_off(vcpu->kvm, irq); 89 rc = kvmppc_xics_int_off(vcpu->kvm, irq);
@@ -105,7 +105,7 @@ static void kvm_rtas_int_on(struct kvm_vcpu *vcpu, struct rtas_args *args)
105 105
106 irq = be32_to_cpu(args->args[0]); 106 irq = be32_to_cpu(args->args[0]);
107 107
108 if (xive_enabled()) 108 if (xics_on_xive())
109 rc = kvmppc_xive_int_on(vcpu->kvm, irq); 109 rc = kvmppc_xive_int_on(vcpu->kvm, irq);
110 else 110 else
111 rc = kvmppc_xics_int_on(vcpu->kvm, irq); 111 rc = kvmppc_xics_int_on(vcpu->kvm, irq);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index b90a7d154180..8885377ec3e0 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -748,7 +748,7 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
748 kvmppc_mpic_disconnect_vcpu(vcpu->arch.mpic, vcpu); 748 kvmppc_mpic_disconnect_vcpu(vcpu->arch.mpic, vcpu);
749 break; 749 break;
750 case KVMPPC_IRQ_XICS: 750 case KVMPPC_IRQ_XICS:
751 if (xive_enabled()) 751 if (xics_on_xive())
752 kvmppc_xive_cleanup_vcpu(vcpu); 752 kvmppc_xive_cleanup_vcpu(vcpu);
753 else 753 else
754 kvmppc_xics_free_icp(vcpu); 754 kvmppc_xics_free_icp(vcpu);
@@ -1931,7 +1931,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
1931 r = -EPERM; 1931 r = -EPERM;
1932 dev = kvm_device_from_filp(f.file); 1932 dev = kvm_device_from_filp(f.file);
1933 if (dev) { 1933 if (dev) {
1934 if (xive_enabled()) 1934 if (xics_on_xive())
1935 r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]); 1935 r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]);
1936 else 1936 else
1937 r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]); 1937 r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]);
@@ -2189,10 +2189,12 @@ static int pseries_get_cpu_char(struct kvm_ppc_cpu_char *cp)
2189 KVM_PPC_CPU_CHAR_L1D_THREAD_PRIV | 2189 KVM_PPC_CPU_CHAR_L1D_THREAD_PRIV |
2190 KVM_PPC_CPU_CHAR_BR_HINT_HONOURED | 2190 KVM_PPC_CPU_CHAR_BR_HINT_HONOURED |
2191 KVM_PPC_CPU_CHAR_MTTRIG_THR_RECONF | 2191 KVM_PPC_CPU_CHAR_MTTRIG_THR_RECONF |
2192 KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS; 2192 KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS |
2193 KVM_PPC_CPU_CHAR_BCCTR_FLUSH_ASSIST;
2193 cp->behaviour_mask = KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY | 2194 cp->behaviour_mask = KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY |
2194 KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR | 2195 KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR |
2195 KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR; 2196 KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR |
2197 KVM_PPC_CPU_BEHAV_FLUSH_COUNT_CACHE;
2196 } 2198 }
2197 return 0; 2199 return 0;
2198} 2200}
@@ -2251,12 +2253,16 @@ static int kvmppc_get_cpu_char(struct kvm_ppc_cpu_char *cp)
2251 if (have_fw_feat(fw_features, "enabled", 2253 if (have_fw_feat(fw_features, "enabled",
2252 "fw-count-cache-disabled")) 2254 "fw-count-cache-disabled"))
2253 cp->character |= KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS; 2255 cp->character |= KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS;
2256 if (have_fw_feat(fw_features, "enabled",
2257 "fw-count-cache-flush-bcctr2,0,0"))
2258 cp->character |= KVM_PPC_CPU_CHAR_BCCTR_FLUSH_ASSIST;
2254 cp->character_mask = KVM_PPC_CPU_CHAR_SPEC_BAR_ORI31 | 2259 cp->character_mask = KVM_PPC_CPU_CHAR_SPEC_BAR_ORI31 |
2255 KVM_PPC_CPU_CHAR_BCCTRL_SERIALISED | 2260 KVM_PPC_CPU_CHAR_BCCTRL_SERIALISED |
2256 KVM_PPC_CPU_CHAR_L1D_FLUSH_ORI30 | 2261 KVM_PPC_CPU_CHAR_L1D_FLUSH_ORI30 |
2257 KVM_PPC_CPU_CHAR_L1D_FLUSH_TRIG2 | 2262 KVM_PPC_CPU_CHAR_L1D_FLUSH_TRIG2 |
2258 KVM_PPC_CPU_CHAR_L1D_THREAD_PRIV | 2263 KVM_PPC_CPU_CHAR_L1D_THREAD_PRIV |
2259 KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS; 2264 KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS |
2265 KVM_PPC_CPU_CHAR_BCCTR_FLUSH_ASSIST;
2260 2266
2261 if (have_fw_feat(fw_features, "enabled", 2267 if (have_fw_feat(fw_features, "enabled",
2262 "speculation-policy-favor-security")) 2268 "speculation-policy-favor-security"))
@@ -2267,9 +2273,13 @@ static int kvmppc_get_cpu_char(struct kvm_ppc_cpu_char *cp)
2267 if (!have_fw_feat(fw_features, "disabled", 2273 if (!have_fw_feat(fw_features, "disabled",
2268 "needs-spec-barrier-for-bound-checks")) 2274 "needs-spec-barrier-for-bound-checks"))
2269 cp->behaviour |= KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR; 2275 cp->behaviour |= KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR;
2276 if (have_fw_feat(fw_features, "enabled",
2277 "needs-count-cache-flush-on-context-switch"))
2278 cp->behaviour |= KVM_PPC_CPU_BEHAV_FLUSH_COUNT_CACHE;
2270 cp->behaviour_mask = KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY | 2279 cp->behaviour_mask = KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY |
2271 KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR | 2280 KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR |
2272 KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR; 2281 KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR |
2282 KVM_PPC_CPU_BEHAV_FLUSH_COUNT_CACHE;
2273 2283
2274 of_node_put(fw_features); 2284 of_node_put(fw_features);
2275 } 2285 }
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index d52ec118e09d..3c1bd9fa23cd 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -52,3 +52,6 @@ obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o
52# This is necessary for booting with kcov enabled on book3e machines 52# This is necessary for booting with kcov enabled on book3e machines
53KCOV_INSTRUMENT_tlb_nohash.o := n 53KCOV_INSTRUMENT_tlb_nohash.o := n
54KCOV_INSTRUMENT_fsl_booke_mmu.o := n 54KCOV_INSTRUMENT_fsl_booke_mmu.o := n
55
56# Instrumenting the SLB fault path can lead to duplicate SLB entries
57KCOV_INSTRUMENT_slb.o := n
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/powerpc/platforms/powernv/opal-call.c b/arch/powerpc/platforms/powernv/opal-call.c
index 578757d403ab..daad8c45c8e7 100644
--- a/arch/powerpc/platforms/powernv/opal-call.c
+++ b/arch/powerpc/platforms/powernv/opal-call.c
@@ -86,6 +86,7 @@ static s64 __opal_call_trace(s64 a0, s64 a1, s64 a2, s64 a3,
86 s64 a4, s64 a5, s64 a6, s64 a7, 86 s64 a4, s64 a5, s64 a6, s64 a7,
87 unsigned long opcode, unsigned long msr) 87 unsigned long opcode, unsigned long msr)
88{ 88{
89 return 0;
89} 90}
90 91
91#define DO_TRACE false 92#define DO_TRACE false
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index bba281b1fe1b..96c53b23e58f 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -239,6 +239,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
239 memset(&ndr_desc, 0, sizeof(ndr_desc)); 239 memset(&ndr_desc, 0, sizeof(ndr_desc));
240 ndr_desc.attr_groups = region_attr_groups; 240 ndr_desc.attr_groups = region_attr_groups;
241 ndr_desc.numa_node = dev_to_node(&p->pdev->dev); 241 ndr_desc.numa_node = dev_to_node(&p->pdev->dev);
242 ndr_desc.target_node = ndr_desc.numa_node;
242 ndr_desc.res = &p->res; 243 ndr_desc.res = &p->res;
243 ndr_desc.of_node = p->dn; 244 ndr_desc.of_node = p->dn;
244 ndr_desc.provider_data = p; 245 ndr_desc.provider_data = p;
diff --git a/arch/riscv/include/uapi/asm/Kbuild b/arch/riscv/include/uapi/asm/Kbuild
index d2ee86b4c091..e69de29bb2d1 100644
--- a/arch/riscv/include/uapi/asm/Kbuild
+++ b/arch/riscv/include/uapi/asm/Kbuild
@@ -1 +0,0 @@
1include include/uapi/asm-generic/Kbuild.asm
diff --git a/arch/s390/boot/Makefile b/arch/s390/boot/Makefile
index 11ca8795b74a..c844eaf24ed7 100644
--- a/arch/s390/boot/Makefile
+++ b/arch/s390/boot/Makefile
@@ -57,9 +57,6 @@ $(obj)/section_cmp%: vmlinux $(obj)/compressed/vmlinux FORCE
57$(obj)/compressed/vmlinux: $(obj)/startup.a FORCE 57$(obj)/compressed/vmlinux: $(obj)/startup.a FORCE
58 $(Q)$(MAKE) $(build)=$(obj)/compressed $@ 58 $(Q)$(MAKE) $(build)=$(obj)/compressed $@
59 59
60quiet_cmd_ar = AR $@
61 cmd_ar = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
62
63$(obj)/startup.a: $(OBJECTS) FORCE 60$(obj)/startup.a: $(OBJECTS) FORCE
64 $(call if_changed,ar) 61 $(call if_changed,ar)
65 62
diff --git a/arch/s390/include/asm/Kbuild b/arch/s390/include/asm/Kbuild
index e3239772887a..12d77cb11fe5 100644
--- a/arch/s390/include/asm/Kbuild
+++ b/arch/s390/include/asm/Kbuild
@@ -20,7 +20,6 @@ generic-y += local.h
20generic-y += local64.h 20generic-y += local64.h
21generic-y += mcs_spinlock.h 21generic-y += mcs_spinlock.h
22generic-y += mm-arch-hooks.h 22generic-y += mm-arch-hooks.h
23generic-y += preempt.h
24generic-y += rwsem.h 23generic-y += rwsem.h
25generic-y += trace_clock.h 24generic-y += trace_clock.h
26generic-y += unaligned.h 25generic-y += unaligned.h
diff --git a/arch/s390/include/asm/cio.h b/arch/s390/include/asm/cio.h
index 225667652069..1727180e8ca1 100644
--- a/arch/s390/include/asm/cio.h
+++ b/arch/s390/include/asm/cio.h
@@ -331,5 +331,6 @@ extern void css_schedule_reprobe(void);
331/* Function from drivers/s390/cio/chsc.c */ 331/* Function from drivers/s390/cio/chsc.c */
332int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta); 332int chsc_sstpc(void *page, unsigned int op, u16 ctrl, u64 *clock_delta);
333int chsc_sstpi(void *page, void *result, size_t size); 333int chsc_sstpi(void *page, void *result, size_t size);
334int chsc_sgib(u32 origin);
334 335
335#endif 336#endif
diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h
index 2f7f27e5493f..afaf5e3c57fd 100644
--- a/arch/s390/include/asm/irq.h
+++ b/arch/s390/include/asm/irq.h
@@ -62,6 +62,7 @@ enum interruption_class {
62 IRQIO_MSI, 62 IRQIO_MSI,
63 IRQIO_VIR, 63 IRQIO_VIR,
64 IRQIO_VAI, 64 IRQIO_VAI,
65 IRQIO_GAL,
65 NMI_NMI, 66 NMI_NMI,
66 CPU_RST, 67 CPU_RST,
67 NR_ARCH_IRQS 68 NR_ARCH_IRQS
diff --git a/arch/s390/include/asm/isc.h b/arch/s390/include/asm/isc.h
index 6cb9e2ed05b6..b2cc1ec78d06 100644
--- a/arch/s390/include/asm/isc.h
+++ b/arch/s390/include/asm/isc.h
@@ -21,6 +21,7 @@
21/* Adapter interrupts. */ 21/* Adapter interrupts. */
22#define QDIO_AIRQ_ISC IO_SCH_ISC /* I/O subchannel in qdio mode */ 22#define QDIO_AIRQ_ISC IO_SCH_ISC /* I/O subchannel in qdio mode */
23#define PCI_ISC 2 /* PCI I/O subchannels */ 23#define PCI_ISC 2 /* PCI I/O subchannels */
24#define GAL_ISC 5 /* GIB alert */
24#define AP_ISC 6 /* adjunct processor (crypto) devices */ 25#define AP_ISC 6 /* adjunct processor (crypto) devices */
25 26
26/* Functions for registration of I/O interruption subclasses */ 27/* Functions for registration of I/O interruption subclasses */
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index d5d24889c3bc..c47e22bba87f 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -591,7 +591,6 @@ struct kvm_s390_float_interrupt {
591 struct kvm_s390_mchk_info mchk; 591 struct kvm_s390_mchk_info mchk;
592 struct kvm_s390_ext_info srv_signal; 592 struct kvm_s390_ext_info srv_signal;
593 int next_rr_cpu; 593 int next_rr_cpu;
594 unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)];
595 struct mutex ais_lock; 594 struct mutex ais_lock;
596 u8 simm; 595 u8 simm;
597 u8 nimm; 596 u8 nimm;
@@ -712,6 +711,7 @@ struct s390_io_adapter {
712struct kvm_s390_cpu_model { 711struct kvm_s390_cpu_model {
713 /* facility mask supported by kvm & hosting machine */ 712 /* facility mask supported by kvm & hosting machine */
714 __u64 fac_mask[S390_ARCH_FAC_LIST_SIZE_U64]; 713 __u64 fac_mask[S390_ARCH_FAC_LIST_SIZE_U64];
714 struct kvm_s390_vm_cpu_subfunc subfuncs;
715 /* facility list requested by guest (in dma page) */ 715 /* facility list requested by guest (in dma page) */
716 __u64 *fac_list; 716 __u64 *fac_list;
717 u64 cpuid; 717 u64 cpuid;
@@ -782,9 +782,21 @@ struct kvm_s390_gisa {
782 u8 reserved03[11]; 782 u8 reserved03[11];
783 u32 airq_count; 783 u32 airq_count;
784 } g1; 784 } g1;
785 struct {
786 u64 word[4];
787 } u64;
785 }; 788 };
786}; 789};
787 790
791struct kvm_s390_gib {
792 u32 alert_list_origin;
793 u32 reserved01;
794 u8:5;
795 u8 nisc:3;
796 u8 reserved03[3];
797 u32 reserved04[5];
798};
799
788/* 800/*
789 * sie_page2 has to be allocated as DMA because fac_list, crycb and 801 * sie_page2 has to be allocated as DMA because fac_list, crycb and
790 * gisa need 31bit addresses in the sie control block. 802 * gisa need 31bit addresses in the sie control block.
@@ -793,7 +805,8 @@ struct sie_page2 {
793 __u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64]; /* 0x0000 */ 805 __u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64]; /* 0x0000 */
794 struct kvm_s390_crypto_cb crycb; /* 0x0800 */ 806 struct kvm_s390_crypto_cb crycb; /* 0x0800 */
795 struct kvm_s390_gisa gisa; /* 0x0900 */ 807 struct kvm_s390_gisa gisa; /* 0x0900 */
796 u8 reserved920[0x1000 - 0x920]; /* 0x0920 */ 808 struct kvm *kvm; /* 0x0920 */
809 u8 reserved928[0x1000 - 0x928]; /* 0x0928 */
797}; 810};
798 811
799struct kvm_s390_vsie { 812struct kvm_s390_vsie {
@@ -804,6 +817,20 @@ struct kvm_s390_vsie {
804 struct page *pages[KVM_MAX_VCPUS]; 817 struct page *pages[KVM_MAX_VCPUS];
805}; 818};
806 819
820struct kvm_s390_gisa_iam {
821 u8 mask;
822 spinlock_t ref_lock;
823 u32 ref_count[MAX_ISC + 1];
824};
825
826struct kvm_s390_gisa_interrupt {
827 struct kvm_s390_gisa *origin;
828 struct kvm_s390_gisa_iam alert;
829 struct hrtimer timer;
830 u64 expires;
831 DECLARE_BITMAP(kicked_mask, KVM_MAX_VCPUS);
832};
833
807struct kvm_arch{ 834struct kvm_arch{
808 void *sca; 835 void *sca;
809 int use_esca; 836 int use_esca;
@@ -837,7 +864,8 @@ struct kvm_arch{
837 atomic64_t cmma_dirty_pages; 864 atomic64_t cmma_dirty_pages;
838 /* subset of available cpu features enabled by user space */ 865 /* subset of available cpu features enabled by user space */
839 DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS); 866 DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
840 struct kvm_s390_gisa *gisa; 867 DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS);
868 struct kvm_s390_gisa_interrupt gisa_int;
841}; 869};
842 870
843#define KVM_HVA_ERR_BAD (-1UL) 871#define KVM_HVA_ERR_BAD (-1UL)
@@ -871,6 +899,9 @@ void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
871extern int sie64a(struct kvm_s390_sie_block *, u64 *); 899extern int sie64a(struct kvm_s390_sie_block *, u64 *);
872extern char sie_exit; 900extern char sie_exit;
873 901
902extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
903extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
904
874static inline void kvm_arch_hardware_disable(void) {} 905static inline void kvm_arch_hardware_disable(void) {}
875static inline void kvm_arch_check_processor_compat(void *rtn) {} 906static inline void kvm_arch_check_processor_compat(void *rtn) {}
876static inline void kvm_arch_sync_events(struct kvm *kvm) {} 907static inline void kvm_arch_sync_events(struct kvm *kvm) {}
@@ -878,7 +909,7 @@ static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
878static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} 909static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
879static inline void kvm_arch_free_memslot(struct kvm *kvm, 910static inline void kvm_arch_free_memslot(struct kvm *kvm,
880 struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {} 911 struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
881static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {} 912static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
882static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {} 913static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
883static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm, 914static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
884 struct kvm_memory_slot *slot) {} 915 struct kvm_memory_slot *slot) {}
diff --git a/arch/s390/include/uapi/asm/Kbuild b/arch/s390/include/uapi/asm/Kbuild
index 6b0f30b14642..46c1ff0b842a 100644
--- a/arch/s390/include/uapi/asm/Kbuild
+++ b/arch/s390/include/uapi/asm/Kbuild
@@ -1,6 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2include include/uapi/asm-generic/Kbuild.asm
3 2
4generated-y += unistd_32.h 3generated-y += unistd_32.h
5generated-y += unistd_64.h 4generated-y += unistd_64.h
6generic-y += socket.h
diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index 0e8d68bac82c..0cd5a5f96729 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -88,6 +88,7 @@ static const struct irq_class irqclass_sub_desc[] = {
88 {.irq = IRQIO_MSI, .name = "MSI", .desc = "[I/O] MSI Interrupt" }, 88 {.irq = IRQIO_MSI, .name = "MSI", .desc = "[I/O] MSI Interrupt" },
89 {.irq = IRQIO_VIR, .name = "VIR", .desc = "[I/O] Virtual I/O Devices"}, 89 {.irq = IRQIO_VIR, .name = "VIR", .desc = "[I/O] Virtual I/O Devices"},
90 {.irq = IRQIO_VAI, .name = "VAI", .desc = "[I/O] Virtual I/O Devices AI"}, 90 {.irq = IRQIO_VAI, .name = "VAI", .desc = "[I/O] Virtual I/O Devices AI"},
91 {.irq = IRQIO_GAL, .name = "GAL", .desc = "[I/O] GIB Alert"},
91 {.irq = NMI_NMI, .name = "NMI", .desc = "[NMI] Machine Check"}, 92 {.irq = NMI_NMI, .name = "NMI", .desc = "[NMI] Machine Check"},
92 {.irq = CPU_RST, .name = "RST", .desc = "[CPU] CPU Restart"}, 93 {.irq = CPU_RST, .name = "RST", .desc = "[CPU] CPU Restart"},
93}; 94};
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index fcb55b02990e..82162867f378 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -7,6 +7,9 @@
7 * Author(s): Carsten Otte <cotte@de.ibm.com> 7 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 */ 8 */
9 9
10#define KMSG_COMPONENT "kvm-s390"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
10#include <linux/interrupt.h> 13#include <linux/interrupt.h>
11#include <linux/kvm_host.h> 14#include <linux/kvm_host.h>
12#include <linux/hrtimer.h> 15#include <linux/hrtimer.h>
@@ -23,6 +26,7 @@
23#include <asm/gmap.h> 26#include <asm/gmap.h>
24#include <asm/switch_to.h> 27#include <asm/switch_to.h>
25#include <asm/nmi.h> 28#include <asm/nmi.h>
29#include <asm/airq.h>
26#include "kvm-s390.h" 30#include "kvm-s390.h"
27#include "gaccess.h" 31#include "gaccess.h"
28#include "trace-s390.h" 32#include "trace-s390.h"
@@ -31,6 +35,8 @@
31#define PFAULT_DONE 0x0680 35#define PFAULT_DONE 0x0680
32#define VIRTIO_PARAM 0x0d00 36#define VIRTIO_PARAM 0x0d00
33 37
38static struct kvm_s390_gib *gib;
39
34/* handle external calls via sigp interpretation facility */ 40/* handle external calls via sigp interpretation facility */
35static int sca_ext_call_pending(struct kvm_vcpu *vcpu, int *src_id) 41static int sca_ext_call_pending(struct kvm_vcpu *vcpu, int *src_id)
36{ 42{
@@ -217,22 +223,100 @@ static inline u8 int_word_to_isc(u32 int_word)
217 */ 223 */
218#define IPM_BIT_OFFSET (offsetof(struct kvm_s390_gisa, ipm) * BITS_PER_BYTE) 224#define IPM_BIT_OFFSET (offsetof(struct kvm_s390_gisa, ipm) * BITS_PER_BYTE)
219 225
220static inline void kvm_s390_gisa_set_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc) 226/**
227 * gisa_set_iam - change the GISA interruption alert mask
228 *
229 * @gisa: gisa to operate on
230 * @iam: new IAM value to use
231 *
232 * Change the IAM atomically with the next alert address and the IPM
233 * of the GISA if the GISA is not part of the GIB alert list. All three
234 * fields are located in the first long word of the GISA.
235 *
236 * Returns: 0 on success
237 * -EBUSY in case the gisa is part of the alert list
238 */
239static inline int gisa_set_iam(struct kvm_s390_gisa *gisa, u8 iam)
240{
241 u64 word, _word;
242
243 do {
244 word = READ_ONCE(gisa->u64.word[0]);
245 if ((u64)gisa != word >> 32)
246 return -EBUSY;
247 _word = (word & ~0xffUL) | iam;
248 } while (cmpxchg(&gisa->u64.word[0], word, _word) != word);
249
250 return 0;
251}
252
253/**
254 * gisa_clear_ipm - clear the GISA interruption pending mask
255 *
256 * @gisa: gisa to operate on
257 *
258 * Clear the IPM atomically with the next alert address and the IAM
259 * of the GISA unconditionally. All three fields are located in the
260 * first long word of the GISA.
261 */
262static inline void gisa_clear_ipm(struct kvm_s390_gisa *gisa)
263{
264 u64 word, _word;
265
266 do {
267 word = READ_ONCE(gisa->u64.word[0]);
268 _word = word & ~(0xffUL << 24);
269 } while (cmpxchg(&gisa->u64.word[0], word, _word) != word);
270}
271
272/**
273 * gisa_get_ipm_or_restore_iam - return IPM or restore GISA IAM
274 *
275 * @gi: gisa interrupt struct to work on
276 *
277 * Atomically restores the interruption alert mask if none of the
278 * relevant ISCs are pending and return the IPM.
279 *
280 * Returns: the relevant pending ISCs
281 */
282static inline u8 gisa_get_ipm_or_restore_iam(struct kvm_s390_gisa_interrupt *gi)
283{
284 u8 pending_mask, alert_mask;
285 u64 word, _word;
286
287 do {
288 word = READ_ONCE(gi->origin->u64.word[0]);
289 alert_mask = READ_ONCE(gi->alert.mask);
290 pending_mask = (u8)(word >> 24) & alert_mask;
291 if (pending_mask)
292 return pending_mask;
293 _word = (word & ~0xffUL) | alert_mask;
294 } while (cmpxchg(&gi->origin->u64.word[0], word, _word) != word);
295
296 return 0;
297}
298
299static inline int gisa_in_alert_list(struct kvm_s390_gisa *gisa)
300{
301 return READ_ONCE(gisa->next_alert) != (u32)(u64)gisa;
302}
303
304static inline void gisa_set_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
221{ 305{
222 set_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa); 306 set_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
223} 307}
224 308
225static inline u8 kvm_s390_gisa_get_ipm(struct kvm_s390_gisa *gisa) 309static inline u8 gisa_get_ipm(struct kvm_s390_gisa *gisa)
226{ 310{
227 return READ_ONCE(gisa->ipm); 311 return READ_ONCE(gisa->ipm);
228} 312}
229 313
230static inline void kvm_s390_gisa_clear_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc) 314static inline void gisa_clear_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
231{ 315{
232 clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa); 316 clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
233} 317}
234 318
235static inline int kvm_s390_gisa_tac_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc) 319static inline int gisa_tac_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
236{ 320{
237 return test_and_clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa); 321 return test_and_clear_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
238} 322}
@@ -245,8 +329,13 @@ static inline unsigned long pending_irqs_no_gisa(struct kvm_vcpu *vcpu)
245 329
246static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu) 330static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu)
247{ 331{
248 return pending_irqs_no_gisa(vcpu) | 332 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int;
249 kvm_s390_gisa_get_ipm(vcpu->kvm->arch.gisa) << IRQ_PEND_IO_ISC_7; 333 unsigned long pending_mask;
334
335 pending_mask = pending_irqs_no_gisa(vcpu);
336 if (gi->origin)
337 pending_mask |= gisa_get_ipm(gi->origin) << IRQ_PEND_IO_ISC_7;
338 return pending_mask;
250} 339}
251 340
252static inline int isc_to_irq_type(unsigned long isc) 341static inline int isc_to_irq_type(unsigned long isc)
@@ -318,13 +407,13 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)
318static void __set_cpu_idle(struct kvm_vcpu *vcpu) 407static void __set_cpu_idle(struct kvm_vcpu *vcpu)
319{ 408{
320 kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT); 409 kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT);
321 set_bit(vcpu->vcpu_id, vcpu->kvm->arch.float_int.idle_mask); 410 set_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask);
322} 411}
323 412
324static void __unset_cpu_idle(struct kvm_vcpu *vcpu) 413static void __unset_cpu_idle(struct kvm_vcpu *vcpu)
325{ 414{
326 kvm_s390_clear_cpuflags(vcpu, CPUSTAT_WAIT); 415 kvm_s390_clear_cpuflags(vcpu, CPUSTAT_WAIT);
327 clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.float_int.idle_mask); 416 clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask);
328} 417}
329 418
330static void __reset_intercept_indicators(struct kvm_vcpu *vcpu) 419static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
@@ -345,7 +434,7 @@ static void set_intercept_indicators_io(struct kvm_vcpu *vcpu)
345{ 434{
346 if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_IO_MASK)) 435 if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_IO_MASK))
347 return; 436 return;
348 else if (psw_ioint_disabled(vcpu)) 437 if (psw_ioint_disabled(vcpu))
349 kvm_s390_set_cpuflags(vcpu, CPUSTAT_IO_INT); 438 kvm_s390_set_cpuflags(vcpu, CPUSTAT_IO_INT);
350 else 439 else
351 vcpu->arch.sie_block->lctl |= LCTL_CR6; 440 vcpu->arch.sie_block->lctl |= LCTL_CR6;
@@ -353,7 +442,7 @@ static void set_intercept_indicators_io(struct kvm_vcpu *vcpu)
353 442
354static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu) 443static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu)
355{ 444{
356 if (!(pending_irqs(vcpu) & IRQ_PEND_EXT_MASK)) 445 if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_EXT_MASK))
357 return; 446 return;
358 if (psw_extint_disabled(vcpu)) 447 if (psw_extint_disabled(vcpu))
359 kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT); 448 kvm_s390_set_cpuflags(vcpu, CPUSTAT_EXT_INT);
@@ -363,7 +452,7 @@ static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu)
363 452
364static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu) 453static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu)
365{ 454{
366 if (!(pending_irqs(vcpu) & IRQ_PEND_MCHK_MASK)) 455 if (!(pending_irqs_no_gisa(vcpu) & IRQ_PEND_MCHK_MASK))
367 return; 456 return;
368 if (psw_mchk_disabled(vcpu)) 457 if (psw_mchk_disabled(vcpu))
369 vcpu->arch.sie_block->ictl |= ICTL_LPSW; 458 vcpu->arch.sie_block->ictl |= ICTL_LPSW;
@@ -956,6 +1045,7 @@ static int __must_check __deliver_io(struct kvm_vcpu *vcpu,
956{ 1045{
957 struct list_head *isc_list; 1046 struct list_head *isc_list;
958 struct kvm_s390_float_interrupt *fi; 1047 struct kvm_s390_float_interrupt *fi;
1048 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int;
959 struct kvm_s390_interrupt_info *inti = NULL; 1049 struct kvm_s390_interrupt_info *inti = NULL;
960 struct kvm_s390_io_info io; 1050 struct kvm_s390_io_info io;
961 u32 isc; 1051 u32 isc;
@@ -998,8 +1088,7 @@ static int __must_check __deliver_io(struct kvm_vcpu *vcpu,
998 goto out; 1088 goto out;
999 } 1089 }
1000 1090
1001 if (vcpu->kvm->arch.gisa && 1091 if (gi->origin && gisa_tac_ipm_gisc(gi->origin, isc)) {
1002 kvm_s390_gisa_tac_ipm_gisc(vcpu->kvm->arch.gisa, isc)) {
1003 /* 1092 /*
1004 * in case an adapter interrupt was not delivered 1093 * in case an adapter interrupt was not delivered
1005 * in SIE context KVM will handle the delivery 1094 * in SIE context KVM will handle the delivery
@@ -1089,6 +1178,7 @@ static u64 __calculate_sltime(struct kvm_vcpu *vcpu)
1089 1178
1090int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) 1179int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
1091{ 1180{
1181 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int;
1092 u64 sltime; 1182 u64 sltime;
1093 1183
1094 vcpu->stat.exit_wait_state++; 1184 vcpu->stat.exit_wait_state++;
@@ -1102,6 +1192,11 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
1102 return -EOPNOTSUPP; /* disabled wait */ 1192 return -EOPNOTSUPP; /* disabled wait */
1103 } 1193 }
1104 1194
1195 if (gi->origin &&
1196 (gisa_get_ipm_or_restore_iam(gi) &
1197 vcpu->arch.sie_block->gcr[6] >> 24))
1198 return 0;
1199
1105 if (!ckc_interrupts_enabled(vcpu) && 1200 if (!ckc_interrupts_enabled(vcpu) &&
1106 !cpu_timer_interrupts_enabled(vcpu)) { 1201 !cpu_timer_interrupts_enabled(vcpu)) {
1107 VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer"); 1202 VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer");
@@ -1533,18 +1628,19 @@ static struct kvm_s390_interrupt_info *get_top_io_int(struct kvm *kvm,
1533 1628
1534static int get_top_gisa_isc(struct kvm *kvm, u64 isc_mask, u32 schid) 1629static int get_top_gisa_isc(struct kvm *kvm, u64 isc_mask, u32 schid)
1535{ 1630{
1631 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
1536 unsigned long active_mask; 1632 unsigned long active_mask;
1537 int isc; 1633 int isc;
1538 1634
1539 if (schid) 1635 if (schid)
1540 goto out; 1636 goto out;
1541 if (!kvm->arch.gisa) 1637 if (!gi->origin)
1542 goto out; 1638 goto out;
1543 1639
1544 active_mask = (isc_mask & kvm_s390_gisa_get_ipm(kvm->arch.gisa) << 24) << 32; 1640 active_mask = (isc_mask & gisa_get_ipm(gi->origin) << 24) << 32;
1545 while (active_mask) { 1641 while (active_mask) {
1546 isc = __fls(active_mask) ^ (BITS_PER_LONG - 1); 1642 isc = __fls(active_mask) ^ (BITS_PER_LONG - 1);
1547 if (kvm_s390_gisa_tac_ipm_gisc(kvm->arch.gisa, isc)) 1643 if (gisa_tac_ipm_gisc(gi->origin, isc))
1548 return isc; 1644 return isc;
1549 clear_bit_inv(isc, &active_mask); 1645 clear_bit_inv(isc, &active_mask);
1550 } 1646 }
@@ -1567,6 +1663,7 @@ out:
1567struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, 1663struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
1568 u64 isc_mask, u32 schid) 1664 u64 isc_mask, u32 schid)
1569{ 1665{
1666 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
1570 struct kvm_s390_interrupt_info *inti, *tmp_inti; 1667 struct kvm_s390_interrupt_info *inti, *tmp_inti;
1571 int isc; 1668 int isc;
1572 1669
@@ -1584,7 +1681,7 @@ struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
1584 /* both types of interrupts present */ 1681 /* both types of interrupts present */
1585 if (int_word_to_isc(inti->io.io_int_word) <= isc) { 1682 if (int_word_to_isc(inti->io.io_int_word) <= isc) {
1586 /* classical IO int with higher priority */ 1683 /* classical IO int with higher priority */
1587 kvm_s390_gisa_set_ipm_gisc(kvm->arch.gisa, isc); 1684 gisa_set_ipm_gisc(gi->origin, isc);
1588 goto out; 1685 goto out;
1589 } 1686 }
1590gisa_out: 1687gisa_out:
@@ -1596,7 +1693,7 @@ gisa_out:
1596 kvm_s390_reinject_io_int(kvm, inti); 1693 kvm_s390_reinject_io_int(kvm, inti);
1597 inti = tmp_inti; 1694 inti = tmp_inti;
1598 } else 1695 } else
1599 kvm_s390_gisa_set_ipm_gisc(kvm->arch.gisa, isc); 1696 gisa_set_ipm_gisc(gi->origin, isc);
1600out: 1697out:
1601 return inti; 1698 return inti;
1602} 1699}
@@ -1685,6 +1782,7 @@ static int __inject_float_mchk(struct kvm *kvm,
1685 1782
1686static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) 1783static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
1687{ 1784{
1785 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
1688 struct kvm_s390_float_interrupt *fi; 1786 struct kvm_s390_float_interrupt *fi;
1689 struct list_head *list; 1787 struct list_head *list;
1690 int isc; 1788 int isc;
@@ -1692,9 +1790,9 @@ static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
1692 kvm->stat.inject_io++; 1790 kvm->stat.inject_io++;
1693 isc = int_word_to_isc(inti->io.io_int_word); 1791 isc = int_word_to_isc(inti->io.io_int_word);
1694 1792
1695 if (kvm->arch.gisa && inti->type & KVM_S390_INT_IO_AI_MASK) { 1793 if (gi->origin && inti->type & KVM_S390_INT_IO_AI_MASK) {
1696 VM_EVENT(kvm, 4, "%s isc %1u", "inject: I/O (AI/gisa)", isc); 1794 VM_EVENT(kvm, 4, "%s isc %1u", "inject: I/O (AI/gisa)", isc);
1697 kvm_s390_gisa_set_ipm_gisc(kvm->arch.gisa, isc); 1795 gisa_set_ipm_gisc(gi->origin, isc);
1698 kfree(inti); 1796 kfree(inti);
1699 return 0; 1797 return 0;
1700 } 1798 }
@@ -1726,7 +1824,6 @@ static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti)
1726 */ 1824 */
1727static void __floating_irq_kick(struct kvm *kvm, u64 type) 1825static void __floating_irq_kick(struct kvm *kvm, u64 type)
1728{ 1826{
1729 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;
1730 struct kvm_vcpu *dst_vcpu; 1827 struct kvm_vcpu *dst_vcpu;
1731 int sigcpu, online_vcpus, nr_tries = 0; 1828 int sigcpu, online_vcpus, nr_tries = 0;
1732 1829
@@ -1735,11 +1832,11 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type)
1735 return; 1832 return;
1736 1833
1737 /* find idle VCPUs first, then round robin */ 1834 /* find idle VCPUs first, then round robin */
1738 sigcpu = find_first_bit(fi->idle_mask, online_vcpus); 1835 sigcpu = find_first_bit(kvm->arch.idle_mask, online_vcpus);
1739 if (sigcpu == online_vcpus) { 1836 if (sigcpu == online_vcpus) {
1740 do { 1837 do {
1741 sigcpu = fi->next_rr_cpu; 1838 sigcpu = kvm->arch.float_int.next_rr_cpu++;
1742 fi->next_rr_cpu = (fi->next_rr_cpu + 1) % online_vcpus; 1839 kvm->arch.float_int.next_rr_cpu %= online_vcpus;
1743 /* avoid endless loops if all vcpus are stopped */ 1840 /* avoid endless loops if all vcpus are stopped */
1744 if (nr_tries++ >= online_vcpus) 1841 if (nr_tries++ >= online_vcpus)
1745 return; 1842 return;
@@ -1753,7 +1850,8 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type)
1753 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_STOP_INT); 1850 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_STOP_INT);
1754 break; 1851 break;
1755 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: 1852 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
1756 if (!(type & KVM_S390_INT_IO_AI_MASK && kvm->arch.gisa)) 1853 if (!(type & KVM_S390_INT_IO_AI_MASK &&
1854 kvm->arch.gisa_int.origin))
1757 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_IO_INT); 1855 kvm_s390_set_cpuflags(dst_vcpu, CPUSTAT_IO_INT);
1758 break; 1856 break;
1759 default: 1857 default:
@@ -2003,6 +2101,7 @@ void kvm_s390_clear_float_irqs(struct kvm *kvm)
2003 2101
2004static int get_all_floating_irqs(struct kvm *kvm, u8 __user *usrbuf, u64 len) 2102static int get_all_floating_irqs(struct kvm *kvm, u8 __user *usrbuf, u64 len)
2005{ 2103{
2104 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
2006 struct kvm_s390_interrupt_info *inti; 2105 struct kvm_s390_interrupt_info *inti;
2007 struct kvm_s390_float_interrupt *fi; 2106 struct kvm_s390_float_interrupt *fi;
2008 struct kvm_s390_irq *buf; 2107 struct kvm_s390_irq *buf;
@@ -2026,15 +2125,14 @@ static int get_all_floating_irqs(struct kvm *kvm, u8 __user *usrbuf, u64 len)
2026 2125
2027 max_irqs = len / sizeof(struct kvm_s390_irq); 2126 max_irqs = len / sizeof(struct kvm_s390_irq);
2028 2127
2029 if (kvm->arch.gisa && 2128 if (gi->origin && gisa_get_ipm(gi->origin)) {
2030 kvm_s390_gisa_get_ipm(kvm->arch.gisa)) {
2031 for (i = 0; i <= MAX_ISC; i++) { 2129 for (i = 0; i <= MAX_ISC; i++) {
2032 if (n == max_irqs) { 2130 if (n == max_irqs) {
2033 /* signal userspace to try again */ 2131 /* signal userspace to try again */
2034 ret = -ENOMEM; 2132 ret = -ENOMEM;
2035 goto out_nolock; 2133 goto out_nolock;
2036 } 2134 }
2037 if (kvm_s390_gisa_tac_ipm_gisc(kvm->arch.gisa, i)) { 2135 if (gisa_tac_ipm_gisc(gi->origin, i)) {
2038 irq = (struct kvm_s390_irq *) &buf[n]; 2136 irq = (struct kvm_s390_irq *) &buf[n];
2039 irq->type = KVM_S390_INT_IO(1, 0, 0, 0); 2137 irq->type = KVM_S390_INT_IO(1, 0, 0, 0);
2040 irq->u.io.io_int_word = isc_to_int_word(i); 2138 irq->u.io.io_int_word = isc_to_int_word(i);
@@ -2831,7 +2929,7 @@ static void store_local_irq(struct kvm_s390_local_interrupt *li,
2831int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len) 2929int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len)
2832{ 2930{
2833 int scn; 2931 int scn;
2834 unsigned long sigp_emerg_pending[BITS_TO_LONGS(KVM_MAX_VCPUS)]; 2932 DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
2835 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; 2933 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
2836 unsigned long pending_irqs; 2934 unsigned long pending_irqs;
2837 struct kvm_s390_irq irq; 2935 struct kvm_s390_irq irq;
@@ -2884,27 +2982,278 @@ int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len)
2884 return n; 2982 return n;
2885} 2983}
2886 2984
2887void kvm_s390_gisa_clear(struct kvm *kvm) 2985static void __airqs_kick_single_vcpu(struct kvm *kvm, u8 deliverable_mask)
2888{ 2986{
2889 if (kvm->arch.gisa) { 2987 int vcpu_id, online_vcpus = atomic_read(&kvm->online_vcpus);
2890 memset(kvm->arch.gisa, 0, sizeof(struct kvm_s390_gisa)); 2988 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
2891 kvm->arch.gisa->next_alert = (u32)(u64)kvm->arch.gisa; 2989 struct kvm_vcpu *vcpu;
2892 VM_EVENT(kvm, 3, "gisa 0x%pK cleared", kvm->arch.gisa); 2990
2991 for_each_set_bit(vcpu_id, kvm->arch.idle_mask, online_vcpus) {
2992 vcpu = kvm_get_vcpu(kvm, vcpu_id);
2993 if (psw_ioint_disabled(vcpu))
2994 continue;
2995 deliverable_mask &= (u8)(vcpu->arch.sie_block->gcr[6] >> 24);
2996 if (deliverable_mask) {
2997 /* lately kicked but not yet running */
2998 if (test_and_set_bit(vcpu_id, gi->kicked_mask))
2999 return;
3000 kvm_s390_vcpu_wakeup(vcpu);
3001 return;
3002 }
2893 } 3003 }
2894} 3004}
2895 3005
3006static enum hrtimer_restart gisa_vcpu_kicker(struct hrtimer *timer)
3007{
3008 struct kvm_s390_gisa_interrupt *gi =
3009 container_of(timer, struct kvm_s390_gisa_interrupt, timer);
3010 struct kvm *kvm =
3011 container_of(gi->origin, struct sie_page2, gisa)->kvm;
3012 u8 pending_mask;
3013
3014 pending_mask = gisa_get_ipm_or_restore_iam(gi);
3015 if (pending_mask) {
3016 __airqs_kick_single_vcpu(kvm, pending_mask);
3017 hrtimer_forward_now(timer, ns_to_ktime(gi->expires));
3018 return HRTIMER_RESTART;
3019 };
3020
3021 return HRTIMER_NORESTART;
3022}
3023
3024#define NULL_GISA_ADDR 0x00000000UL
3025#define NONE_GISA_ADDR 0x00000001UL
3026#define GISA_ADDR_MASK 0xfffff000UL
3027
3028static void process_gib_alert_list(void)
3029{
3030 struct kvm_s390_gisa_interrupt *gi;
3031 struct kvm_s390_gisa *gisa;
3032 struct kvm *kvm;
3033 u32 final, origin = 0UL;
3034
3035 do {
3036 /*
3037 * If the NONE_GISA_ADDR is still stored in the alert list
3038 * origin, we will leave the outer loop. No further GISA has
3039 * been added to the alert list by millicode while processing
3040 * the current alert list.
3041 */
3042 final = (origin & NONE_GISA_ADDR);
3043 /*
3044 * Cut off the alert list and store the NONE_GISA_ADDR in the
3045 * alert list origin to avoid further GAL interruptions.
3046 * A new alert list can be build up by millicode in parallel
3047 * for guests not in the yet cut-off alert list. When in the
3048 * final loop, store the NULL_GISA_ADDR instead. This will re-
3049 * enable GAL interruptions on the host again.
3050 */
3051 origin = xchg(&gib->alert_list_origin,
3052 (!final) ? NONE_GISA_ADDR : NULL_GISA_ADDR);
3053 /*
3054 * Loop through the just cut-off alert list and start the
3055 * gisa timers to kick idle vcpus to consume the pending
3056 * interruptions asap.
3057 */
3058 while (origin & GISA_ADDR_MASK) {
3059 gisa = (struct kvm_s390_gisa *)(u64)origin;
3060 origin = gisa->next_alert;
3061 gisa->next_alert = (u32)(u64)gisa;
3062 kvm = container_of(gisa, struct sie_page2, gisa)->kvm;
3063 gi = &kvm->arch.gisa_int;
3064 if (hrtimer_active(&gi->timer))
3065 hrtimer_cancel(&gi->timer);
3066 hrtimer_start(&gi->timer, 0, HRTIMER_MODE_REL);
3067 }
3068 } while (!final);
3069
3070}
3071
3072void kvm_s390_gisa_clear(struct kvm *kvm)
3073{
3074 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
3075
3076 if (!gi->origin)
3077 return;
3078 gisa_clear_ipm(gi->origin);
3079 VM_EVENT(kvm, 3, "gisa 0x%pK cleared", gi->origin);
3080}
3081
2896void kvm_s390_gisa_init(struct kvm *kvm) 3082void kvm_s390_gisa_init(struct kvm *kvm)
2897{ 3083{
2898 if (css_general_characteristics.aiv) { 3084 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
2899 kvm->arch.gisa = &kvm->arch.sie_page2->gisa; 3085
2900 VM_EVENT(kvm, 3, "gisa 0x%pK initialized", kvm->arch.gisa); 3086 if (!css_general_characteristics.aiv)
2901 kvm_s390_gisa_clear(kvm); 3087 return;
2902 } 3088 gi->origin = &kvm->arch.sie_page2->gisa;
3089 gi->alert.mask = 0;
3090 spin_lock_init(&gi->alert.ref_lock);
3091 gi->expires = 50 * 1000; /* 50 usec */
3092 hrtimer_init(&gi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3093 gi->timer.function = gisa_vcpu_kicker;
3094 memset(gi->origin, 0, sizeof(struct kvm_s390_gisa));
3095 gi->origin->next_alert = (u32)(u64)gi->origin;
3096 VM_EVENT(kvm, 3, "gisa 0x%pK initialized", gi->origin);
2903} 3097}
2904 3098
2905void kvm_s390_gisa_destroy(struct kvm *kvm) 3099void kvm_s390_gisa_destroy(struct kvm *kvm)
2906{ 3100{
2907 if (!kvm->arch.gisa) 3101 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
3102
3103 if (!gi->origin)
3104 return;
3105 if (gi->alert.mask)
3106 KVM_EVENT(3, "vm 0x%pK has unexpected iam 0x%02x",
3107 kvm, gi->alert.mask);
3108 while (gisa_in_alert_list(gi->origin))
3109 cpu_relax();
3110 hrtimer_cancel(&gi->timer);
3111 gi->origin = NULL;
3112}
3113
3114/**
3115 * kvm_s390_gisc_register - register a guest ISC
3116 *
3117 * @kvm: the kernel vm to work with
3118 * @gisc: the guest interruption sub class to register
3119 *
3120 * The function extends the vm specific alert mask to use.
3121 * The effective IAM mask in the GISA is updated as well
3122 * in case the GISA is not part of the GIB alert list.
3123 * It will be updated latest when the IAM gets restored
3124 * by gisa_get_ipm_or_restore_iam().
3125 *
3126 * Returns: the nonspecific ISC (NISC) the gib alert mechanism
3127 * has registered with the channel subsystem.
3128 * -ENODEV in case the vm uses no GISA
3129 * -ERANGE in case the guest ISC is invalid
3130 */
3131int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc)
3132{
3133 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
3134
3135 if (!gi->origin)
3136 return -ENODEV;
3137 if (gisc > MAX_ISC)
3138 return -ERANGE;
3139
3140 spin_lock(&gi->alert.ref_lock);
3141 gi->alert.ref_count[gisc]++;
3142 if (gi->alert.ref_count[gisc] == 1) {
3143 gi->alert.mask |= 0x80 >> gisc;
3144 gisa_set_iam(gi->origin, gi->alert.mask);
3145 }
3146 spin_unlock(&gi->alert.ref_lock);
3147
3148 return gib->nisc;
3149}
3150EXPORT_SYMBOL_GPL(kvm_s390_gisc_register);
3151
3152/**
3153 * kvm_s390_gisc_unregister - unregister a guest ISC
3154 *
3155 * @kvm: the kernel vm to work with
3156 * @gisc: the guest interruption sub class to register
3157 *
3158 * The function reduces the vm specific alert mask to use.
3159 * The effective IAM mask in the GISA is updated as well
3160 * in case the GISA is not part of the GIB alert list.
3161 * It will be updated latest when the IAM gets restored
3162 * by gisa_get_ipm_or_restore_iam().
3163 *
3164 * Returns: the nonspecific ISC (NISC) the gib alert mechanism
3165 * has registered with the channel subsystem.
3166 * -ENODEV in case the vm uses no GISA
3167 * -ERANGE in case the guest ISC is invalid
3168 * -EINVAL in case the guest ISC is not registered
3169 */
3170int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc)
3171{
3172 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
3173 int rc = 0;
3174
3175 if (!gi->origin)
3176 return -ENODEV;
3177 if (gisc > MAX_ISC)
3178 return -ERANGE;
3179
3180 spin_lock(&gi->alert.ref_lock);
3181 if (gi->alert.ref_count[gisc] == 0) {
3182 rc = -EINVAL;
3183 goto out;
3184 }
3185 gi->alert.ref_count[gisc]--;
3186 if (gi->alert.ref_count[gisc] == 0) {
3187 gi->alert.mask &= ~(0x80 >> gisc);
3188 gisa_set_iam(gi->origin, gi->alert.mask);
3189 }
3190out:
3191 spin_unlock(&gi->alert.ref_lock);
3192
3193 return rc;
3194}
3195EXPORT_SYMBOL_GPL(kvm_s390_gisc_unregister);
3196
3197static void gib_alert_irq_handler(struct airq_struct *airq)
3198{
3199 inc_irq_stat(IRQIO_GAL);
3200 process_gib_alert_list();
3201}
3202
3203static struct airq_struct gib_alert_irq = {
3204 .handler = gib_alert_irq_handler,
3205 .lsi_ptr = &gib_alert_irq.lsi_mask,
3206};
3207
3208void kvm_s390_gib_destroy(void)
3209{
3210 if (!gib)
2908 return; 3211 return;
2909 kvm->arch.gisa = NULL; 3212 chsc_sgib(0);
3213 unregister_adapter_interrupt(&gib_alert_irq);
3214 free_page((unsigned long)gib);
3215 gib = NULL;
3216}
3217
3218int kvm_s390_gib_init(u8 nisc)
3219{
3220 int rc = 0;
3221
3222 if (!css_general_characteristics.aiv) {
3223 KVM_EVENT(3, "%s", "gib not initialized, no AIV facility");
3224 goto out;
3225 }
3226
3227 gib = (struct kvm_s390_gib *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
3228 if (!gib) {
3229 rc = -ENOMEM;
3230 goto out;
3231 }
3232
3233 gib_alert_irq.isc = nisc;
3234 if (register_adapter_interrupt(&gib_alert_irq)) {
3235 pr_err("Registering the GIB alert interruption handler failed\n");
3236 rc = -EIO;
3237 goto out_free_gib;
3238 }
3239
3240 gib->nisc = nisc;
3241 if (chsc_sgib((u32)(u64)gib)) {
3242 pr_err("Associating the GIB with the AIV facility failed\n");
3243 free_page((unsigned long)gib);
3244 gib = NULL;
3245 rc = -EIO;
3246 goto out_unreg_gal;
3247 }
3248
3249 KVM_EVENT(3, "gib 0x%pK (nisc=%d) initialized", gib, gib->nisc);
3250 goto out;
3251
3252out_unreg_gal:
3253 unregister_adapter_interrupt(&gib_alert_irq);
3254out_free_gib:
3255 free_page((unsigned long)gib);
3256 gib = NULL;
3257out:
3258 return rc;
2910} 3259}
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 7f4bc58a53b9..4638303ba6a8 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -432,11 +432,18 @@ int kvm_arch_init(void *opaque)
432 /* Register floating interrupt controller interface. */ 432 /* Register floating interrupt controller interface. */
433 rc = kvm_register_device_ops(&kvm_flic_ops, KVM_DEV_TYPE_FLIC); 433 rc = kvm_register_device_ops(&kvm_flic_ops, KVM_DEV_TYPE_FLIC);
434 if (rc) { 434 if (rc) {
435 pr_err("Failed to register FLIC rc=%d\n", rc); 435 pr_err("A FLIC registration call failed with rc=%d\n", rc);
436 goto out_debug_unreg; 436 goto out_debug_unreg;
437 } 437 }
438
439 rc = kvm_s390_gib_init(GAL_ISC);
440 if (rc)
441 goto out_gib_destroy;
442
438 return 0; 443 return 0;
439 444
445out_gib_destroy:
446 kvm_s390_gib_destroy();
440out_debug_unreg: 447out_debug_unreg:
441 debug_unregister(kvm_s390_dbf); 448 debug_unregister(kvm_s390_dbf);
442 return rc; 449 return rc;
@@ -444,6 +451,7 @@ out_debug_unreg:
444 451
445void kvm_arch_exit(void) 452void kvm_arch_exit(void)
446{ 453{
454 kvm_s390_gib_destroy();
447 debug_unregister(kvm_s390_dbf); 455 debug_unregister(kvm_s390_dbf);
448} 456}
449 457
@@ -1258,11 +1266,65 @@ static int kvm_s390_set_processor_feat(struct kvm *kvm,
1258static int kvm_s390_set_processor_subfunc(struct kvm *kvm, 1266static int kvm_s390_set_processor_subfunc(struct kvm *kvm,
1259 struct kvm_device_attr *attr) 1267 struct kvm_device_attr *attr)
1260{ 1268{
1261 /* 1269 mutex_lock(&kvm->lock);
1262 * Once supported by kernel + hw, we have to store the subfunctions 1270 if (kvm->created_vcpus) {
1263 * in kvm->arch and remember that user space configured them. 1271 mutex_unlock(&kvm->lock);
1264 */ 1272 return -EBUSY;
1265 return -ENXIO; 1273 }
1274
1275 if (copy_from_user(&kvm->arch.model.subfuncs, (void __user *)attr->addr,
1276 sizeof(struct kvm_s390_vm_cpu_subfunc))) {
1277 mutex_unlock(&kvm->lock);
1278 return -EFAULT;
1279 }
1280 mutex_unlock(&kvm->lock);
1281
1282 VM_EVENT(kvm, 3, "SET: guest PLO subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx",
1283 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[0],
1284 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[1],
1285 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[2],
1286 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[3]);
1287 VM_EVENT(kvm, 3, "SET: guest PTFF subfunc 0x%16.16lx.%16.16lx",
1288 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[0],
1289 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[1]);
1290 VM_EVENT(kvm, 3, "SET: guest KMAC subfunc 0x%16.16lx.%16.16lx",
1291 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[0],
1292 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[1]);
1293 VM_EVENT(kvm, 3, "SET: guest KMC subfunc 0x%16.16lx.%16.16lx",
1294 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[0],
1295 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[1]);
1296 VM_EVENT(kvm, 3, "SET: guest KM subfunc 0x%16.16lx.%16.16lx",
1297 ((unsigned long *) &kvm->arch.model.subfuncs.km)[0],
1298 ((unsigned long *) &kvm->arch.model.subfuncs.km)[1]);
1299 VM_EVENT(kvm, 3, "SET: guest KIMD subfunc 0x%16.16lx.%16.16lx",
1300 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[0],
1301 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[1]);
1302 VM_EVENT(kvm, 3, "SET: guest KLMD subfunc 0x%16.16lx.%16.16lx",
1303 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[0],
1304 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[1]);
1305 VM_EVENT(kvm, 3, "SET: guest PCKMO subfunc 0x%16.16lx.%16.16lx",
1306 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[0],
1307 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[1]);
1308 VM_EVENT(kvm, 3, "SET: guest KMCTR subfunc 0x%16.16lx.%16.16lx",
1309 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[0],
1310 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[1]);
1311 VM_EVENT(kvm, 3, "SET: guest KMF subfunc 0x%16.16lx.%16.16lx",
1312 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[0],
1313 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[1]);
1314 VM_EVENT(kvm, 3, "SET: guest KMO subfunc 0x%16.16lx.%16.16lx",
1315 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[0],
1316 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[1]);
1317 VM_EVENT(kvm, 3, "SET: guest PCC subfunc 0x%16.16lx.%16.16lx",
1318 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[0],
1319 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[1]);
1320 VM_EVENT(kvm, 3, "SET: guest PPNO subfunc 0x%16.16lx.%16.16lx",
1321 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[0],
1322 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[1]);
1323 VM_EVENT(kvm, 3, "SET: guest KMA subfunc 0x%16.16lx.%16.16lx",
1324 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[0],
1325 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[1]);
1326
1327 return 0;
1266} 1328}
1267 1329
1268static int kvm_s390_set_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) 1330static int kvm_s390_set_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr)
@@ -1381,12 +1443,56 @@ static int kvm_s390_get_machine_feat(struct kvm *kvm,
1381static int kvm_s390_get_processor_subfunc(struct kvm *kvm, 1443static int kvm_s390_get_processor_subfunc(struct kvm *kvm,
1382 struct kvm_device_attr *attr) 1444 struct kvm_device_attr *attr)
1383{ 1445{
1384 /* 1446 if (copy_to_user((void __user *)attr->addr, &kvm->arch.model.subfuncs,
1385 * Once we can actually configure subfunctions (kernel + hw support), 1447 sizeof(struct kvm_s390_vm_cpu_subfunc)))
1386 * we have to check if they were already set by user space, if so copy 1448 return -EFAULT;
1387 * them from kvm->arch. 1449
1388 */ 1450 VM_EVENT(kvm, 3, "GET: guest PLO subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx",
1389 return -ENXIO; 1451 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[0],
1452 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[1],
1453 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[2],
1454 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[3]);
1455 VM_EVENT(kvm, 3, "GET: guest PTFF subfunc 0x%16.16lx.%16.16lx",
1456 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[0],
1457 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[1]);
1458 VM_EVENT(kvm, 3, "GET: guest KMAC subfunc 0x%16.16lx.%16.16lx",
1459 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[0],
1460 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[1]);
1461 VM_EVENT(kvm, 3, "GET: guest KMC subfunc 0x%16.16lx.%16.16lx",
1462 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[0],
1463 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[1]);
1464 VM_EVENT(kvm, 3, "GET: guest KM subfunc 0x%16.16lx.%16.16lx",
1465 ((unsigned long *) &kvm->arch.model.subfuncs.km)[0],
1466 ((unsigned long *) &kvm->arch.model.subfuncs.km)[1]);
1467 VM_EVENT(kvm, 3, "GET: guest KIMD subfunc 0x%16.16lx.%16.16lx",
1468 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[0],
1469 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[1]);
1470 VM_EVENT(kvm, 3, "GET: guest KLMD subfunc 0x%16.16lx.%16.16lx",
1471 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[0],
1472 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[1]);
1473 VM_EVENT(kvm, 3, "GET: guest PCKMO subfunc 0x%16.16lx.%16.16lx",
1474 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[0],
1475 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[1]);
1476 VM_EVENT(kvm, 3, "GET: guest KMCTR subfunc 0x%16.16lx.%16.16lx",
1477 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[0],
1478 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[1]);
1479 VM_EVENT(kvm, 3, "GET: guest KMF subfunc 0x%16.16lx.%16.16lx",
1480 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[0],
1481 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[1]);
1482 VM_EVENT(kvm, 3, "GET: guest KMO subfunc 0x%16.16lx.%16.16lx",
1483 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[0],
1484 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[1]);
1485 VM_EVENT(kvm, 3, "GET: guest PCC subfunc 0x%16.16lx.%16.16lx",
1486 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[0],
1487 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[1]);
1488 VM_EVENT(kvm, 3, "GET: guest PPNO subfunc 0x%16.16lx.%16.16lx",
1489 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[0],
1490 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[1]);
1491 VM_EVENT(kvm, 3, "GET: guest KMA subfunc 0x%16.16lx.%16.16lx",
1492 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[0],
1493 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[1]);
1494
1495 return 0;
1390} 1496}
1391 1497
1392static int kvm_s390_get_machine_subfunc(struct kvm *kvm, 1498static int kvm_s390_get_machine_subfunc(struct kvm *kvm,
@@ -1395,8 +1501,55 @@ static int kvm_s390_get_machine_subfunc(struct kvm *kvm,
1395 if (copy_to_user((void __user *)attr->addr, &kvm_s390_available_subfunc, 1501 if (copy_to_user((void __user *)attr->addr, &kvm_s390_available_subfunc,
1396 sizeof(struct kvm_s390_vm_cpu_subfunc))) 1502 sizeof(struct kvm_s390_vm_cpu_subfunc)))
1397 return -EFAULT; 1503 return -EFAULT;
1504
1505 VM_EVENT(kvm, 3, "GET: host PLO subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx",
1506 ((unsigned long *) &kvm_s390_available_subfunc.plo)[0],
1507 ((unsigned long *) &kvm_s390_available_subfunc.plo)[1],
1508 ((unsigned long *) &kvm_s390_available_subfunc.plo)[2],
1509 ((unsigned long *) &kvm_s390_available_subfunc.plo)[3]);
1510 VM_EVENT(kvm, 3, "GET: host PTFF subfunc 0x%16.16lx.%16.16lx",
1511 ((unsigned long *) &kvm_s390_available_subfunc.ptff)[0],
1512 ((unsigned long *) &kvm_s390_available_subfunc.ptff)[1]);
1513 VM_EVENT(kvm, 3, "GET: host KMAC subfunc 0x%16.16lx.%16.16lx",
1514 ((unsigned long *) &kvm_s390_available_subfunc.kmac)[0],
1515 ((unsigned long *) &kvm_s390_available_subfunc.kmac)[1]);
1516 VM_EVENT(kvm, 3, "GET: host KMC subfunc 0x%16.16lx.%16.16lx",
1517 ((unsigned long *) &kvm_s390_available_subfunc.kmc)[0],
1518 ((unsigned long *) &kvm_s390_available_subfunc.kmc)[1]);
1519 VM_EVENT(kvm, 3, "GET: host KM subfunc 0x%16.16lx.%16.16lx",
1520 ((unsigned long *) &kvm_s390_available_subfunc.km)[0],
1521 ((unsigned long *) &kvm_s390_available_subfunc.km)[1]);
1522 VM_EVENT(kvm, 3, "GET: host KIMD subfunc 0x%16.16lx.%16.16lx",
1523 ((unsigned long *) &kvm_s390_available_subfunc.kimd)[0],
1524 ((unsigned long *) &kvm_s390_available_subfunc.kimd)[1]);
1525 VM_EVENT(kvm, 3, "GET: host KLMD subfunc 0x%16.16lx.%16.16lx",
1526 ((unsigned long *) &kvm_s390_available_subfunc.klmd)[0],
1527 ((unsigned long *) &kvm_s390_available_subfunc.klmd)[1]);
1528 VM_EVENT(kvm, 3, "GET: host PCKMO subfunc 0x%16.16lx.%16.16lx",
1529 ((unsigned long *) &kvm_s390_available_subfunc.pckmo)[0],
1530 ((unsigned long *) &kvm_s390_available_subfunc.pckmo)[1]);
1531 VM_EVENT(kvm, 3, "GET: host KMCTR subfunc 0x%16.16lx.%16.16lx",
1532 ((unsigned long *) &kvm_s390_available_subfunc.kmctr)[0],
1533 ((unsigned long *) &kvm_s390_available_subfunc.kmctr)[1]);
1534 VM_EVENT(kvm, 3, "GET: host KMF subfunc 0x%16.16lx.%16.16lx",
1535 ((unsigned long *) &kvm_s390_available_subfunc.kmf)[0],
1536 ((unsigned long *) &kvm_s390_available_subfunc.kmf)[1]);
1537 VM_EVENT(kvm, 3, "GET: host KMO subfunc 0x%16.16lx.%16.16lx",
1538 ((unsigned long *) &kvm_s390_available_subfunc.kmo)[0],
1539 ((unsigned long *) &kvm_s390_available_subfunc.kmo)[1]);
1540 VM_EVENT(kvm, 3, "GET: host PCC subfunc 0x%16.16lx.%16.16lx",
1541 ((unsigned long *) &kvm_s390_available_subfunc.pcc)[0],
1542 ((unsigned long *) &kvm_s390_available_subfunc.pcc)[1]);
1543 VM_EVENT(kvm, 3, "GET: host PPNO subfunc 0x%16.16lx.%16.16lx",
1544 ((unsigned long *) &kvm_s390_available_subfunc.ppno)[0],
1545 ((unsigned long *) &kvm_s390_available_subfunc.ppno)[1]);
1546 VM_EVENT(kvm, 3, "GET: host KMA subfunc 0x%16.16lx.%16.16lx",
1547 ((unsigned long *) &kvm_s390_available_subfunc.kma)[0],
1548 ((unsigned long *) &kvm_s390_available_subfunc.kma)[1]);
1549
1398 return 0; 1550 return 0;
1399} 1551}
1552
1400static int kvm_s390_get_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) 1553static int kvm_s390_get_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr)
1401{ 1554{
1402 int ret = -ENXIO; 1555 int ret = -ENXIO;
@@ -1514,10 +1667,9 @@ static int kvm_s390_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr)
1514 case KVM_S390_VM_CPU_PROCESSOR_FEAT: 1667 case KVM_S390_VM_CPU_PROCESSOR_FEAT:
1515 case KVM_S390_VM_CPU_MACHINE_FEAT: 1668 case KVM_S390_VM_CPU_MACHINE_FEAT:
1516 case KVM_S390_VM_CPU_MACHINE_SUBFUNC: 1669 case KVM_S390_VM_CPU_MACHINE_SUBFUNC:
1670 case KVM_S390_VM_CPU_PROCESSOR_SUBFUNC:
1517 ret = 0; 1671 ret = 0;
1518 break; 1672 break;
1519 /* configuring subfunctions is not supported yet */
1520 case KVM_S390_VM_CPU_PROCESSOR_SUBFUNC:
1521 default: 1673 default:
1522 ret = -ENXIO; 1674 ret = -ENXIO;
1523 break; 1675 break;
@@ -2209,6 +2361,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
2209 if (!kvm->arch.sie_page2) 2361 if (!kvm->arch.sie_page2)
2210 goto out_err; 2362 goto out_err;
2211 2363
2364 kvm->arch.sie_page2->kvm = kvm;
2212 kvm->arch.model.fac_list = kvm->arch.sie_page2->fac_list; 2365 kvm->arch.model.fac_list = kvm->arch.sie_page2->fac_list;
2213 2366
2214 for (i = 0; i < kvm_s390_fac_size(); i++) { 2367 for (i = 0; i < kvm_s390_fac_size(); i++) {
@@ -2218,6 +2371,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
2218 kvm->arch.model.fac_list[i] = S390_lowcore.stfle_fac_list[i] & 2371 kvm->arch.model.fac_list[i] = S390_lowcore.stfle_fac_list[i] &
2219 kvm_s390_fac_base[i]; 2372 kvm_s390_fac_base[i];
2220 } 2373 }
2374 kvm->arch.model.subfuncs = kvm_s390_available_subfunc;
2221 2375
2222 /* we are always in czam mode - even on pre z14 machines */ 2376 /* we are always in czam mode - even on pre z14 machines */
2223 set_kvm_facility(kvm->arch.model.fac_mask, 138); 2377 set_kvm_facility(kvm->arch.model.fac_mask, 138);
@@ -2812,7 +2966,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
2812 2966
2813 vcpu->arch.sie_block->icpua = id; 2967 vcpu->arch.sie_block->icpua = id;
2814 spin_lock_init(&vcpu->arch.local_int.lock); 2968 spin_lock_init(&vcpu->arch.local_int.lock);
2815 vcpu->arch.sie_block->gd = (u32)(u64)kvm->arch.gisa; 2969 vcpu->arch.sie_block->gd = (u32)(u64)kvm->arch.gisa_int.origin;
2816 if (vcpu->arch.sie_block->gd && sclp.has_gisaf) 2970 if (vcpu->arch.sie_block->gd && sclp.has_gisaf)
2817 vcpu->arch.sie_block->gd |= GISA_FORMAT1; 2971 vcpu->arch.sie_block->gd |= GISA_FORMAT1;
2818 seqcount_init(&vcpu->arch.cputm_seqcount); 2972 seqcount_init(&vcpu->arch.cputm_seqcount);
@@ -3458,6 +3612,8 @@ static int vcpu_pre_run(struct kvm_vcpu *vcpu)
3458 kvm_s390_patch_guest_per_regs(vcpu); 3612 kvm_s390_patch_guest_per_regs(vcpu);
3459 } 3613 }
3460 3614
3615 clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.gisa_int.kicked_mask);
3616
3461 vcpu->arch.sie_block->icptcode = 0; 3617 vcpu->arch.sie_block->icptcode = 0;
3462 cpuflags = atomic_read(&vcpu->arch.sie_block->cpuflags); 3618 cpuflags = atomic_read(&vcpu->arch.sie_block->cpuflags);
3463 VCPU_EVENT(vcpu, 6, "entering sie flags %x", cpuflags); 3619 VCPU_EVENT(vcpu, 6, "entering sie flags %x", cpuflags);
@@ -4293,12 +4449,12 @@ static int __init kvm_s390_init(void)
4293 int i; 4449 int i;
4294 4450
4295 if (!sclp.has_sief2) { 4451 if (!sclp.has_sief2) {
4296 pr_info("SIE not available\n"); 4452 pr_info("SIE is not available\n");
4297 return -ENODEV; 4453 return -ENODEV;
4298 } 4454 }
4299 4455
4300 if (nested && hpage) { 4456 if (nested && hpage) {
4301 pr_info("nested (vSIE) and hpage (huge page backing) can currently not be activated concurrently"); 4457 pr_info("A KVM host that supports nesting cannot back its KVM guests with huge pages\n");
4302 return -EINVAL; 4458 return -EINVAL;
4303 } 4459 }
4304 4460
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 1f6e36cdce0d..6d9448dbd052 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -67,7 +67,7 @@ static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
67 67
68static inline int is_vcpu_idle(struct kvm_vcpu *vcpu) 68static inline int is_vcpu_idle(struct kvm_vcpu *vcpu)
69{ 69{
70 return test_bit(vcpu->vcpu_id, vcpu->kvm->arch.float_int.idle_mask); 70 return test_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask);
71} 71}
72 72
73static inline int kvm_is_ucontrol(struct kvm *kvm) 73static inline int kvm_is_ucontrol(struct kvm *kvm)
@@ -381,6 +381,8 @@ int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu,
381void kvm_s390_gisa_init(struct kvm *kvm); 381void kvm_s390_gisa_init(struct kvm *kvm);
382void kvm_s390_gisa_clear(struct kvm *kvm); 382void kvm_s390_gisa_clear(struct kvm *kvm);
383void kvm_s390_gisa_destroy(struct kvm *kvm); 383void kvm_s390_gisa_destroy(struct kvm *kvm);
384int kvm_s390_gib_init(u8 nisc);
385void kvm_s390_gib_destroy(void);
384 386
385/* implemented in guestdbg.c */ 387/* implemented in guestdbg.c */
386void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu); 388void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu);
diff --git a/arch/sh/include/uapi/asm/Kbuild b/arch/sh/include/uapi/asm/Kbuild
index eaa30bcd93bf..ecfbd40924dd 100644
--- a/arch/sh/include/uapi/asm/Kbuild
+++ b/arch/sh/include/uapi/asm/Kbuild
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2include include/uapi/asm-generic/Kbuild.asm
3 2
4generated-y += unistd_32.h 3generated-y += unistd_32.h
5generic-y += kvm_para.h 4generic-y += kvm_para.h
diff --git a/arch/sparc/include/uapi/asm/Kbuild b/arch/sparc/include/uapi/asm/Kbuild
index 214a39acdf25..2bd5b392277c 100644
--- a/arch/sparc/include/uapi/asm/Kbuild
+++ b/arch/sparc/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h 1generated-y += unistd_32.h
4generated-y += unistd_64.h 2generated-y += unistd_64.h
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index a4a41421c5e2..aca09be2373e 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -938,7 +938,7 @@ static int ubd_add(int n, char **error_out)
938 ubd_dev->queue = blk_mq_init_queue(&ubd_dev->tag_set); 938 ubd_dev->queue = blk_mq_init_queue(&ubd_dev->tag_set);
939 if (IS_ERR(ubd_dev->queue)) { 939 if (IS_ERR(ubd_dev->queue)) {
940 err = PTR_ERR(ubd_dev->queue); 940 err = PTR_ERR(ubd_dev->queue);
941 goto out_cleanup; 941 goto out_cleanup_tags;
942 } 942 }
943 943
944 ubd_dev->queue->queuedata = ubd_dev; 944 ubd_dev->queue->queuedata = ubd_dev;
@@ -968,8 +968,8 @@ out:
968 968
969out_cleanup_tags: 969out_cleanup_tags:
970 blk_mq_free_tag_set(&ubd_dev->tag_set); 970 blk_mq_free_tag_set(&ubd_dev->tag_set);
971out_cleanup: 971 if (!(IS_ERR(ubd_dev->queue)))
972 blk_cleanup_queue(ubd_dev->queue); 972 blk_cleanup_queue(ubd_dev->queue);
973 goto out; 973 goto out;
974} 974}
975 975
diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
index d2c17dd74620..b3f7b3ca896d 100644
--- a/arch/um/drivers/vector_user.c
+++ b/arch/um/drivers/vector_user.c
@@ -16,14 +16,12 @@
16#include <sys/types.h> 16#include <sys/types.h>
17#include <sys/stat.h> 17#include <sys/stat.h>
18#include <fcntl.h> 18#include <fcntl.h>
19#include <sys/types.h>
20#include <sys/socket.h> 19#include <sys/socket.h>
21#include <net/ethernet.h> 20#include <net/ethernet.h>
22#include <netinet/ip.h> 21#include <netinet/ip.h>
23#include <netinet/ether.h> 22#include <netinet/ether.h>
24#include <linux/if_ether.h> 23#include <linux/if_ether.h>
25#include <linux/if_packet.h> 24#include <linux/if_packet.h>
26#include <sys/socket.h>
27#include <sys/wait.h> 25#include <sys/wait.h>
28#include <sys/uio.h> 26#include <sys/uio.h>
29#include <linux/virtio_net.h> 27#include <linux/virtio_net.h>
@@ -31,7 +29,6 @@
31#include <stdlib.h> 29#include <stdlib.h>
32#include <os.h> 30#include <os.h>
33#include <um_malloc.h> 31#include <um_malloc.h>
34#include <sys/uio.h>
35#include "vector_user.h" 32#include "vector_user.h"
36 33
37#define ID_GRE 0 34#define ID_GRE 0
diff --git a/arch/unicore32/boot/compressed/Makefile b/arch/unicore32/boot/compressed/Makefile
index 9aecdd3ddc48..150fafc32fb0 100644
--- a/arch/unicore32/boot/compressed/Makefile
+++ b/arch/unicore32/boot/compressed/Makefile
@@ -61,7 +61,4 @@ $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head.o $(obj)/piggy.o \
61ZTEXTADDR := 0x03000000 61ZTEXTADDR := 0x03000000
62ZBSSADDR := ALIGN(4) 62ZBSSADDR := ALIGN(4)
63 63
64SEDFLAGS_lds = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/ 64CPPFLAGS_vmlinux.lds = -DTEXT_START="$(ZTEXTADDR)" -DBSS_START="$(ZBSSADDR)"
65$(obj)/vmlinux.lds: $(obj)/vmlinux.lds.in arch/unicore32/boot/Makefile $(KCONFIG_CONFIG)
66 @sed "$(SEDFLAGS_lds)" < $< > $@
67
diff --git a/arch/unicore32/boot/compressed/vmlinux.lds.in b/arch/unicore32/boot/compressed/vmlinux.lds.S
index d5a3ce296239..d5a3ce296239 100644
--- a/arch/unicore32/boot/compressed/vmlinux.lds.in
+++ b/arch/unicore32/boot/compressed/vmlinux.lds.S
diff --git a/arch/unicore32/include/uapi/asm/Kbuild b/arch/unicore32/include/uapi/asm/Kbuild
index 0febf1a07c30..755bb11323d8 100644
--- a/arch/unicore32/include/uapi/asm/Kbuild
+++ b/arch/unicore32/include/uapi/asm/Kbuild
@@ -1,4 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generic-y += kvm_para.h 1generic-y += kvm_para.h
4generic-y += ucontext.h 2generic-y += ucontext.h
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/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
index 8da78595d69d..1f9607ed087c 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -429,6 +429,7 @@
429421 i386 rt_sigtimedwait_time64 sys_rt_sigtimedwait __ia32_compat_sys_rt_sigtimedwait_time64 429421 i386 rt_sigtimedwait_time64 sys_rt_sigtimedwait __ia32_compat_sys_rt_sigtimedwait_time64
430422 i386 futex_time64 sys_futex __ia32_sys_futex 430422 i386 futex_time64 sys_futex __ia32_sys_futex
431423 i386 sched_rr_get_interval_time64 sys_sched_rr_get_interval __ia32_sys_sched_rr_get_interval 431423 i386 sched_rr_get_interval_time64 sys_sched_rr_get_interval __ia32_sys_sched_rr_get_interval
432424 i386 pidfd_send_signal sys_pidfd_send_signal __ia32_sys_pidfd_send_signal
432425 i386 io_uring_setup sys_io_uring_setup __ia32_sys_io_uring_setup 433425 i386 io_uring_setup sys_io_uring_setup __ia32_sys_io_uring_setup
433426 i386 io_uring_enter sys_io_uring_enter __ia32_sys_io_uring_enter 434426 i386 io_uring_enter sys_io_uring_enter __ia32_sys_io_uring_enter
434427 i386 io_uring_register sys_io_uring_register __ia32_sys_io_uring_register 435427 i386 io_uring_register sys_io_uring_register __ia32_sys_io_uring_register
diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
index c768447f97ec..92ee0b4378d4 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -345,6 +345,7 @@
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 346# don't use numbers 387 through 423, add new calls after the last
347# 'common' entry 347# 'common' entry
348424 common pidfd_send_signal __x64_sys_pidfd_send_signal
348425 common io_uring_setup __x64_sys_io_uring_setup 349425 common io_uring_setup __x64_sys_io_uring_setup
349426 common io_uring_enter __x64_sys_io_uring_enter 350426 common io_uring_enter __x64_sys_io_uring_enter
350427 common io_uring_register __x64_sys_io_uring_register 351427 common io_uring_register __x64_sys_io_uring_register
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 35102ecdfc8d..8baa441d8000 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3410,7 +3410,7 @@ tfa_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
3410 /* 3410 /*
3411 * Without TFA we must not use PMC3. 3411 * Without TFA we must not use PMC3.
3412 */ 3412 */
3413 if (!allow_tsx_force_abort && test_bit(3, c->idxmsk)) { 3413 if (!allow_tsx_force_abort && test_bit(3, c->idxmsk) && idx >= 0) {
3414 c = dyn_constraint(cpuc, c, idx); 3414 c = dyn_constraint(cpuc, c, idx);
3415 c->idxmsk64 &= ~(1ULL << 3); 3415 c->idxmsk64 &= ~(1ULL << 3);
3416 c->weight--; 3416 c->weight--;
@@ -4179,7 +4179,7 @@ static struct attribute *intel_pmu_caps_attrs[] = {
4179 NULL 4179 NULL
4180}; 4180};
4181 4181
4182DEVICE_BOOL_ATTR(allow_tsx_force_abort, 0644, allow_tsx_force_abort); 4182static DEVICE_BOOL_ATTR(allow_tsx_force_abort, 0644, allow_tsx_force_abort);
4183 4183
4184static struct attribute *intel_pmu_attrs[] = { 4184static struct attribute *intel_pmu_attrs[] = {
4185 &dev_attr_freeze_on_smi.attr, 4185 &dev_attr_freeze_on_smi.attr,
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index b04ae6c8775e..a75955741c50 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -1033,12 +1033,12 @@ static inline int intel_pmu_init(void)
1033 return 0; 1033 return 0;
1034} 1034}
1035 1035
1036static inline int intel_cpuc_prepare(struct cpu_hw_event *cpuc, int cpu) 1036static inline int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu)
1037{ 1037{
1038 return 0; 1038 return 0;
1039} 1039}
1040 1040
1041static inline void intel_cpuc_finish(struct cpu_hw_event *cpuc) 1041static inline void intel_cpuc_finish(struct cpu_hw_events *cpuc)
1042{ 1042{
1043} 1043}
1044 1044
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/bitops.h b/arch/x86/include/asm/bitops.h
index ad7b210aa3f6..d153d570bb04 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -36,13 +36,7 @@
36 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). 36 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
37 */ 37 */
38 38
39#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)
40/* Technically wrong, but this avoids compilation errors on some gcc
41 versions. */
42#define BITOP_ADDR(x) "=m" (*(volatile long *) (x))
43#else
44#define BITOP_ADDR(x) "+m" (*(volatile long *) (x)) 39#define BITOP_ADDR(x) "+m" (*(volatile long *) (x))
45#endif
46 40
47#define ADDR BITOP_ADDR(addr) 41#define ADDR BITOP_ADDR(addr)
48 42
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/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 180373360e34..a5db4475e72d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -35,6 +35,7 @@
35#include <asm/msr-index.h> 35#include <asm/msr-index.h>
36#include <asm/asm.h> 36#include <asm/asm.h>
37#include <asm/kvm_page_track.h> 37#include <asm/kvm_page_track.h>
38#include <asm/kvm_vcpu_regs.h>
38#include <asm/hyperv-tlfs.h> 39#include <asm/hyperv-tlfs.h>
39 40
40#define KVM_MAX_VCPUS 288 41#define KVM_MAX_VCPUS 288
@@ -137,23 +138,23 @@ static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
137#define ASYNC_PF_PER_VCPU 64 138#define ASYNC_PF_PER_VCPU 64
138 139
139enum kvm_reg { 140enum kvm_reg {
140 VCPU_REGS_RAX = 0, 141 VCPU_REGS_RAX = __VCPU_REGS_RAX,
141 VCPU_REGS_RCX = 1, 142 VCPU_REGS_RCX = __VCPU_REGS_RCX,
142 VCPU_REGS_RDX = 2, 143 VCPU_REGS_RDX = __VCPU_REGS_RDX,
143 VCPU_REGS_RBX = 3, 144 VCPU_REGS_RBX = __VCPU_REGS_RBX,
144 VCPU_REGS_RSP = 4, 145 VCPU_REGS_RSP = __VCPU_REGS_RSP,
145 VCPU_REGS_RBP = 5, 146 VCPU_REGS_RBP = __VCPU_REGS_RBP,
146 VCPU_REGS_RSI = 6, 147 VCPU_REGS_RSI = __VCPU_REGS_RSI,
147 VCPU_REGS_RDI = 7, 148 VCPU_REGS_RDI = __VCPU_REGS_RDI,
148#ifdef CONFIG_X86_64 149#ifdef CONFIG_X86_64
149 VCPU_REGS_R8 = 8, 150 VCPU_REGS_R8 = __VCPU_REGS_R8,
150 VCPU_REGS_R9 = 9, 151 VCPU_REGS_R9 = __VCPU_REGS_R9,
151 VCPU_REGS_R10 = 10, 152 VCPU_REGS_R10 = __VCPU_REGS_R10,
152 VCPU_REGS_R11 = 11, 153 VCPU_REGS_R11 = __VCPU_REGS_R11,
153 VCPU_REGS_R12 = 12, 154 VCPU_REGS_R12 = __VCPU_REGS_R12,
154 VCPU_REGS_R13 = 13, 155 VCPU_REGS_R13 = __VCPU_REGS_R13,
155 VCPU_REGS_R14 = 14, 156 VCPU_REGS_R14 = __VCPU_REGS_R14,
156 VCPU_REGS_R15 = 15, 157 VCPU_REGS_R15 = __VCPU_REGS_R15,
157#endif 158#endif
158 VCPU_REGS_RIP, 159 VCPU_REGS_RIP,
159 NR_VCPU_REGS 160 NR_VCPU_REGS
@@ -319,6 +320,7 @@ struct kvm_mmu_page {
319 struct list_head link; 320 struct list_head link;
320 struct hlist_node hash_link; 321 struct hlist_node hash_link;
321 bool unsync; 322 bool unsync;
323 bool mmio_cached;
322 324
323 /* 325 /*
324 * The following two entries are used to key the shadow page in the 326 * The following two entries are used to key the shadow page in the
@@ -333,10 +335,6 @@ struct kvm_mmu_page {
333 int root_count; /* Currently serving as active root */ 335 int root_count; /* Currently serving as active root */
334 unsigned int unsync_children; 336 unsigned int unsync_children;
335 struct kvm_rmap_head parent_ptes; /* rmap pointers to parent sptes */ 337 struct kvm_rmap_head parent_ptes; /* rmap pointers to parent sptes */
336
337 /* The page is obsolete if mmu_valid_gen != kvm->arch.mmu_valid_gen. */
338 unsigned long mmu_valid_gen;
339
340 DECLARE_BITMAP(unsync_child_bitmap, 512); 338 DECLARE_BITMAP(unsync_child_bitmap, 512);
341 339
342#ifdef CONFIG_X86_32 340#ifdef CONFIG_X86_32
@@ -848,13 +846,11 @@ struct kvm_arch {
848 unsigned int n_requested_mmu_pages; 846 unsigned int n_requested_mmu_pages;
849 unsigned int n_max_mmu_pages; 847 unsigned int n_max_mmu_pages;
850 unsigned int indirect_shadow_pages; 848 unsigned int indirect_shadow_pages;
851 unsigned long mmu_valid_gen;
852 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES]; 849 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
853 /* 850 /*
854 * Hash table of struct kvm_mmu_page. 851 * Hash table of struct kvm_mmu_page.
855 */ 852 */
856 struct list_head active_mmu_pages; 853 struct list_head active_mmu_pages;
857 struct list_head zapped_obsolete_pages;
858 struct kvm_page_track_notifier_node mmu_sp_tracker; 854 struct kvm_page_track_notifier_node mmu_sp_tracker;
859 struct kvm_page_track_notifier_head track_notifier_head; 855 struct kvm_page_track_notifier_head track_notifier_head;
860 856
@@ -1255,7 +1251,7 @@ void kvm_mmu_clear_dirty_pt_masked(struct kvm *kvm,
1255 struct kvm_memory_slot *slot, 1251 struct kvm_memory_slot *slot,
1256 gfn_t gfn_offset, unsigned long mask); 1252 gfn_t gfn_offset, unsigned long mask);
1257void kvm_mmu_zap_all(struct kvm *kvm); 1253void kvm_mmu_zap_all(struct kvm *kvm);
1258void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, struct kvm_memslots *slots); 1254void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen);
1259unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm); 1255unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm);
1260void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages); 1256void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
1261 1257
diff --git a/arch/x86/include/asm/kvm_vcpu_regs.h b/arch/x86/include/asm/kvm_vcpu_regs.h
new file mode 100644
index 000000000000..1af2cb59233b
--- /dev/null
+++ b/arch/x86/include/asm/kvm_vcpu_regs.h
@@ -0,0 +1,25 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_X86_KVM_VCPU_REGS_H
3#define _ASM_X86_KVM_VCPU_REGS_H
4
5#define __VCPU_REGS_RAX 0
6#define __VCPU_REGS_RCX 1
7#define __VCPU_REGS_RDX 2
8#define __VCPU_REGS_RBX 3
9#define __VCPU_REGS_RSP 4
10#define __VCPU_REGS_RBP 5
11#define __VCPU_REGS_RSI 6
12#define __VCPU_REGS_RDI 7
13
14#ifdef CONFIG_X86_64
15#define __VCPU_REGS_R8 8
16#define __VCPU_REGS_R9 9
17#define __VCPU_REGS_R10 10
18#define __VCPU_REGS_R11 11
19#define __VCPU_REGS_R12 12
20#define __VCPU_REGS_R13 13
21#define __VCPU_REGS_R14 14
22#define __VCPU_REGS_R15 15
23#endif
24
25#endif /* _ASM_X86_KVM_VCPU_REGS_H */
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/include/asm/string_32.h b/arch/x86/include/asm/string_32.h
index 55d392c6bd29..f74362b05619 100644
--- a/arch/x86/include/asm/string_32.h
+++ b/arch/x86/include/asm/string_32.h
@@ -179,14 +179,7 @@ static inline void *__memcpy3d(void *to, const void *from, size_t len)
179 * No 3D Now! 179 * No 3D Now!
180 */ 180 */
181 181
182#if (__GNUC__ >= 4)
183#define memcpy(t, f, n) __builtin_memcpy(t, f, n) 182#define memcpy(t, f, n) __builtin_memcpy(t, f, n)
184#else
185#define memcpy(t, f, n) \
186 (__builtin_constant_p((n)) \
187 ? __constant_memcpy((t), (f), (n)) \
188 : __memcpy((t), (f), (n)))
189#endif
190 183
191#endif 184#endif
192#endif /* !CONFIG_FORTIFY_SOURCE */ 185#endif /* !CONFIG_FORTIFY_SOURCE */
@@ -216,29 +209,6 @@ static inline void *__memset_generic(void *s, char c, size_t count)
216/* we might want to write optimized versions of these later */ 209/* we might want to write optimized versions of these later */
217#define __constant_count_memset(s, c, count) __memset_generic((s), (c), (count)) 210#define __constant_count_memset(s, c, count) __memset_generic((s), (c), (count))
218 211
219/*
220 * memset(x, 0, y) is a reasonably common thing to do, so we want to fill
221 * things 32 bits at a time even when we don't know the size of the
222 * area at compile-time..
223 */
224static __always_inline
225void *__constant_c_memset(void *s, unsigned long c, size_t count)
226{
227 int d0, d1;
228 asm volatile("rep ; stosl\n\t"
229 "testb $2,%b3\n\t"
230 "je 1f\n\t"
231 "stosw\n"
232 "1:\ttestb $1,%b3\n\t"
233 "je 2f\n\t"
234 "stosb\n"
235 "2:"
236 : "=&c" (d0), "=&D" (d1)
237 : "a" (c), "q" (count), "0" (count/4), "1" ((long)s)
238 : "memory");
239 return s;
240}
241
242/* Added by Gertjan van Wingerde to make minix and sysv module work */ 212/* Added by Gertjan van Wingerde to make minix and sysv module work */
243#define __HAVE_ARCH_STRNLEN 213#define __HAVE_ARCH_STRNLEN
244extern size_t strnlen(const char *s, size_t count); 214extern size_t strnlen(const char *s, size_t count);
@@ -247,72 +217,6 @@ extern size_t strnlen(const char *s, size_t count);
247#define __HAVE_ARCH_STRSTR 217#define __HAVE_ARCH_STRSTR
248extern char *strstr(const char *cs, const char *ct); 218extern char *strstr(const char *cs, const char *ct);
249 219
250/*
251 * This looks horribly ugly, but the compiler can optimize it totally,
252 * as we by now know that both pattern and count is constant..
253 */
254static __always_inline
255void *__constant_c_and_count_memset(void *s, unsigned long pattern,
256 size_t count)
257{
258 switch (count) {
259 case 0:
260 return s;
261 case 1:
262 *(unsigned char *)s = pattern & 0xff;
263 return s;
264 case 2:
265 *(unsigned short *)s = pattern & 0xffff;
266 return s;
267 case 3:
268 *(unsigned short *)s = pattern & 0xffff;
269 *((unsigned char *)s + 2) = pattern & 0xff;
270 return s;
271 case 4:
272 *(unsigned long *)s = pattern;
273 return s;
274 }
275
276#define COMMON(x) \
277 asm volatile("rep ; stosl" \
278 x \
279 : "=&c" (d0), "=&D" (d1) \
280 : "a" (eax), "0" (count/4), "1" ((long)s) \
281 : "memory")
282
283 {
284 int d0, d1;
285#if __GNUC__ == 4 && __GNUC_MINOR__ == 0
286 /* Workaround for broken gcc 4.0 */
287 register unsigned long eax asm("%eax") = pattern;
288#else
289 unsigned long eax = pattern;
290#endif
291
292 switch (count % 4) {
293 case 0:
294 COMMON("");
295 return s;
296 case 1:
297 COMMON("\n\tstosb");
298 return s;
299 case 2:
300 COMMON("\n\tstosw");
301 return s;
302 default:
303 COMMON("\n\tstosw\n\tstosb");
304 return s;
305 }
306 }
307
308#undef COMMON
309}
310
311#define __constant_c_x_memset(s, c, count) \
312 (__builtin_constant_p(count) \
313 ? __constant_c_and_count_memset((s), (c), (count)) \
314 : __constant_c_memset((s), (c), (count)))
315
316#define __memset(s, c, count) \ 220#define __memset(s, c, count) \
317 (__builtin_constant_p(count) \ 221 (__builtin_constant_p(count) \
318 ? __constant_count_memset((s), (c), (count)) \ 222 ? __constant_count_memset((s), (c), (count)) \
@@ -321,15 +225,7 @@ void *__constant_c_and_count_memset(void *s, unsigned long pattern,
321#define __HAVE_ARCH_MEMSET 225#define __HAVE_ARCH_MEMSET
322extern void *memset(void *, int, size_t); 226extern void *memset(void *, int, size_t);
323#ifndef CONFIG_FORTIFY_SOURCE 227#ifndef CONFIG_FORTIFY_SOURCE
324#if (__GNUC__ >= 4)
325#define memset(s, c, count) __builtin_memset(s, c, count) 228#define memset(s, c, count) __builtin_memset(s, c, count)
326#else
327#define memset(s, c, count) \
328 (__builtin_constant_p(c) \
329 ? __constant_c_x_memset((s), (0x01010101UL * (unsigned char)(c)), \
330 (count)) \
331 : __memset((s), (c), (count)))
332#endif
333#endif /* !CONFIG_FORTIFY_SOURCE */ 229#endif /* !CONFIG_FORTIFY_SOURCE */
334 230
335#define __HAVE_ARCH_MEMSET16 231#define __HAVE_ARCH_MEMSET16
diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h
index 4e4194e21a09..75314c3dbe47 100644
--- a/arch/x86/include/asm/string_64.h
+++ b/arch/x86/include/asm/string_64.h
@@ -14,21 +14,6 @@
14extern void *memcpy(void *to, const void *from, size_t len); 14extern void *memcpy(void *to, const void *from, size_t len);
15extern void *__memcpy(void *to, const void *from, size_t len); 15extern void *__memcpy(void *to, const void *from, size_t len);
16 16
17#ifndef CONFIG_FORTIFY_SOURCE
18#if (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || __GNUC__ < 4
19#define memcpy(dst, src, len) \
20({ \
21 size_t __len = (len); \
22 void *__ret; \
23 if (__builtin_constant_p(len) && __len >= 64) \
24 __ret = __memcpy((dst), (src), __len); \
25 else \
26 __ret = __builtin_memcpy((dst), (src), __len); \
27 __ret; \
28})
29#endif
30#endif /* !CONFIG_FORTIFY_SOURCE */
31
32#define __HAVE_ARCH_MEMSET 17#define __HAVE_ARCH_MEMSET
33void *memset(void *s, int c, size_t n); 18void *memset(void *s, int c, size_t n);
34void *__memset(void *s, int c, size_t n); 19void *__memset(void *s, int c, size_t n);
diff --git a/arch/x86/include/uapi/asm/Kbuild b/arch/x86/include/uapi/asm/Kbuild
index efe701b7c6ce..59b5ad310f78 100644
--- a/arch/x86/include/uapi/asm/Kbuild
+++ b/arch/x86/include/uapi/asm/Kbuild
@@ -1,6 +1,3 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h 1generated-y += unistd_32.h
4generated-y += unistd_64.h 2generated-y += unistd_64.h
5generated-y += unistd_x32.h 3generated-y += unistd_x32.h
6generic-y += socket.h
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/kvmclock.c b/arch/x86/kernel/kvmclock.c
index e811d4d1c824..904494b924c1 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -104,12 +104,8 @@ static u64 kvm_sched_clock_read(void)
104 104
105static inline void kvm_sched_clock_init(bool stable) 105static inline void kvm_sched_clock_init(bool stable)
106{ 106{
107 if (!stable) { 107 if (!stable)
108 pv_ops.time.sched_clock = kvm_clock_read;
109 clear_sched_clock_stable(); 108 clear_sched_clock_stable();
110 return;
111 }
112
113 kvm_sched_clock_offset = kvm_clock_read(); 109 kvm_sched_clock_offset = kvm_clock_read();
114 pv_ops.time.sched_clock = kvm_sched_clock_read; 110 pv_ops.time.sched_clock = kvm_sched_clock_read;
115 111
@@ -355,6 +351,20 @@ void __init kvmclock_init(void)
355 machine_ops.crash_shutdown = kvm_crash_shutdown; 351 machine_ops.crash_shutdown = kvm_crash_shutdown;
356#endif 352#endif
357 kvm_get_preset_lpj(); 353 kvm_get_preset_lpj();
354
355 /*
356 * X86_FEATURE_NONSTOP_TSC is TSC runs at constant rate
357 * with P/T states and does not stop in deep C-states.
358 *
359 * Invariant TSC exposed by host means kvmclock is not necessary:
360 * can use TSC as clocksource.
361 *
362 */
363 if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC) &&
364 boot_cpu_has(X86_FEATURE_NONSTOP_TSC) &&
365 !check_tsc_unstable())
366 kvm_clock.rating = 299;
367
358 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC); 368 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
359 pv_info.name = "KVM"; 369 pv_info.name = "KVM";
360} 370}
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/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index c07958b59f50..fd3951638ae4 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -405,7 +405,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
405 F(AVX512VBMI) | F(LA57) | F(PKU) | 0 /*OSPKE*/ | 405 F(AVX512VBMI) | F(LA57) | F(PKU) | 0 /*OSPKE*/ |
406 F(AVX512_VPOPCNTDQ) | F(UMIP) | F(AVX512_VBMI2) | F(GFNI) | 406 F(AVX512_VPOPCNTDQ) | F(UMIP) | F(AVX512_VBMI2) | F(GFNI) |
407 F(VAES) | F(VPCLMULQDQ) | F(AVX512_VNNI) | F(AVX512_BITALG) | 407 F(VAES) | F(VPCLMULQDQ) | F(AVX512_VNNI) | F(AVX512_BITALG) |
408 F(CLDEMOTE); 408 F(CLDEMOTE) | F(MOVDIRI) | F(MOVDIR64B);
409 409
410 /* cpuid 7.0.edx*/ 410 /* cpuid 7.0.edx*/
411 const u32 kvm_cpuid_7_0_edx_x86_features = 411 const u32 kvm_cpuid_7_0_edx_x86_features =
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 89d20ed1d2e8..27c43525a05f 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1729,7 +1729,7 @@ static int kvm_hv_eventfd_assign(struct kvm *kvm, u32 conn_id, int fd)
1729 1729
1730 mutex_lock(&hv->hv_lock); 1730 mutex_lock(&hv->hv_lock);
1731 ret = idr_alloc(&hv->conn_to_evt, eventfd, conn_id, conn_id + 1, 1731 ret = idr_alloc(&hv->conn_to_evt, eventfd, conn_id, conn_id + 1,
1732 GFP_KERNEL); 1732 GFP_KERNEL_ACCOUNT);
1733 mutex_unlock(&hv->hv_lock); 1733 mutex_unlock(&hv->hv_lock);
1734 1734
1735 if (ret >= 0) 1735 if (ret >= 0)
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index af192895b1fc..4a6dc54cc12b 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -653,7 +653,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
653 pid_t pid_nr; 653 pid_t pid_nr;
654 int ret; 654 int ret;
655 655
656 pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL); 656 pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL_ACCOUNT);
657 if (!pit) 657 if (!pit)
658 return NULL; 658 return NULL;
659 659
diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index bdcd4139eca9..8b38bb4868a6 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -583,7 +583,7 @@ int kvm_pic_init(struct kvm *kvm)
583 struct kvm_pic *s; 583 struct kvm_pic *s;
584 int ret; 584 int ret;
585 585
586 s = kzalloc(sizeof(struct kvm_pic), GFP_KERNEL); 586 s = kzalloc(sizeof(struct kvm_pic), GFP_KERNEL_ACCOUNT);
587 if (!s) 587 if (!s)
588 return -ENOMEM; 588 return -ENOMEM;
589 spin_lock_init(&s->lock); 589 spin_lock_init(&s->lock);
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 4e822ad363f3..1add1bc881e2 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -622,7 +622,7 @@ int kvm_ioapic_init(struct kvm *kvm)
622 struct kvm_ioapic *ioapic; 622 struct kvm_ioapic *ioapic;
623 int ret; 623 int ret;
624 624
625 ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL); 625 ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL_ACCOUNT);
626 if (!ioapic) 626 if (!ioapic)
627 return -ENOMEM; 627 return -ENOMEM;
628 spin_lock_init(&ioapic->lock); 628 spin_lock_init(&ioapic->lock);
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 4b6c2da7265c..991fdf7fc17f 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -181,7 +181,8 @@ static void recalculate_apic_map(struct kvm *kvm)
181 max_id = max(max_id, kvm_x2apic_id(vcpu->arch.apic)); 181 max_id = max(max_id, kvm_x2apic_id(vcpu->arch.apic));
182 182
183 new = kvzalloc(sizeof(struct kvm_apic_map) + 183 new = kvzalloc(sizeof(struct kvm_apic_map) +
184 sizeof(struct kvm_lapic *) * ((u64)max_id + 1), GFP_KERNEL); 184 sizeof(struct kvm_lapic *) * ((u64)max_id + 1),
185 GFP_KERNEL_ACCOUNT);
185 186
186 if (!new) 187 if (!new)
187 goto out; 188 goto out;
@@ -2259,13 +2260,13 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
2259 ASSERT(vcpu != NULL); 2260 ASSERT(vcpu != NULL);
2260 apic_debug("apic_init %d\n", vcpu->vcpu_id); 2261 apic_debug("apic_init %d\n", vcpu->vcpu_id);
2261 2262
2262 apic = kzalloc(sizeof(*apic), GFP_KERNEL); 2263 apic = kzalloc(sizeof(*apic), GFP_KERNEL_ACCOUNT);
2263 if (!apic) 2264 if (!apic)
2264 goto nomem; 2265 goto nomem;
2265 2266
2266 vcpu->arch.apic = apic; 2267 vcpu->arch.apic = apic;
2267 2268
2268 apic->regs = (void *)get_zeroed_page(GFP_KERNEL); 2269 apic->regs = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
2269 if (!apic->regs) { 2270 if (!apic->regs) {
2270 printk(KERN_ERR "malloc apic regs error for vcpu %x\n", 2271 printk(KERN_ERR "malloc apic regs error for vcpu %x\n",
2271 vcpu->vcpu_id); 2272 vcpu->vcpu_id);
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index f2d1d230d5b8..7837ab001d80 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -109,9 +109,11 @@ module_param(dbg, bool, 0644);
109 (((address) >> PT32_LEVEL_SHIFT(level)) & ((1 << PT32_LEVEL_BITS) - 1)) 109 (((address) >> PT32_LEVEL_SHIFT(level)) & ((1 << PT32_LEVEL_BITS) - 1))
110 110
111 111
112#define PT64_BASE_ADDR_MASK __sme_clr((((1ULL << 52) - 1) & ~(u64)(PAGE_SIZE-1))) 112#ifdef CONFIG_DYNAMIC_PHYSICAL_MASK
113#define PT64_DIR_BASE_ADDR_MASK \ 113#define PT64_BASE_ADDR_MASK (physical_mask & ~(u64)(PAGE_SIZE-1))
114 (PT64_BASE_ADDR_MASK & ~((1ULL << (PAGE_SHIFT + PT64_LEVEL_BITS)) - 1)) 114#else
115#define PT64_BASE_ADDR_MASK (((1ULL << 52) - 1) & ~(u64)(PAGE_SIZE-1))
116#endif
115#define PT64_LVL_ADDR_MASK(level) \ 117#define PT64_LVL_ADDR_MASK(level) \
116 (PT64_BASE_ADDR_MASK & ~((1ULL << (PAGE_SHIFT + (((level) - 1) \ 118 (PT64_BASE_ADDR_MASK & ~((1ULL << (PAGE_SHIFT + (((level) - 1) \
117 * PT64_LEVEL_BITS))) - 1)) 119 * PT64_LEVEL_BITS))) - 1))
@@ -330,53 +332,56 @@ static inline bool is_access_track_spte(u64 spte)
330} 332}
331 333
332/* 334/*
333 * the low bit of the generation number is always presumed to be zero. 335 * Due to limited space in PTEs, the MMIO generation is a 19 bit subset of
334 * This disables mmio caching during memslot updates. The concept is 336 * the memslots generation and is derived as follows:
335 * similar to a seqcount but instead of retrying the access we just punt
336 * and ignore the cache.
337 * 337 *
338 * spte bits 3-11 are used as bits 1-9 of the generation number, 338 * Bits 0-8 of the MMIO generation are propagated to spte bits 3-11
339 * the bits 52-61 are used as bits 10-19 of the generation number. 339 * Bits 9-18 of the MMIO generation are propagated to spte bits 52-61
340 *
341 * The KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS flag is intentionally not included in
342 * the MMIO generation number, as doing so would require stealing a bit from
343 * the "real" generation number and thus effectively halve the maximum number
344 * of MMIO generations that can be handled before encountering a wrap (which
345 * requires a full MMU zap). The flag is instead explicitly queried when
346 * checking for MMIO spte cache hits.
340 */ 347 */
341#define MMIO_SPTE_GEN_LOW_SHIFT 2 348#define MMIO_SPTE_GEN_MASK GENMASK_ULL(18, 0)
342#define MMIO_SPTE_GEN_HIGH_SHIFT 52
343 349
344#define MMIO_GEN_SHIFT 20 350#define MMIO_SPTE_GEN_LOW_START 3
345#define MMIO_GEN_LOW_SHIFT 10 351#define MMIO_SPTE_GEN_LOW_END 11
346#define MMIO_GEN_LOW_MASK ((1 << MMIO_GEN_LOW_SHIFT) - 2) 352#define MMIO_SPTE_GEN_LOW_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_END, \
347#define MMIO_GEN_MASK ((1 << MMIO_GEN_SHIFT) - 1) 353 MMIO_SPTE_GEN_LOW_START)
348 354
349static u64 generation_mmio_spte_mask(unsigned int gen) 355#define MMIO_SPTE_GEN_HIGH_START 52
356#define MMIO_SPTE_GEN_HIGH_END 61
357#define MMIO_SPTE_GEN_HIGH_MASK GENMASK_ULL(MMIO_SPTE_GEN_HIGH_END, \
358 MMIO_SPTE_GEN_HIGH_START)
359static u64 generation_mmio_spte_mask(u64 gen)
350{ 360{
351 u64 mask; 361 u64 mask;
352 362
353 WARN_ON(gen & ~MMIO_GEN_MASK); 363 WARN_ON(gen & ~MMIO_SPTE_GEN_MASK);
354 364
355 mask = (gen & MMIO_GEN_LOW_MASK) << MMIO_SPTE_GEN_LOW_SHIFT; 365 mask = (gen << MMIO_SPTE_GEN_LOW_START) & MMIO_SPTE_GEN_LOW_MASK;
356 mask |= ((u64)gen >> MMIO_GEN_LOW_SHIFT) << MMIO_SPTE_GEN_HIGH_SHIFT; 366 mask |= (gen << MMIO_SPTE_GEN_HIGH_START) & MMIO_SPTE_GEN_HIGH_MASK;
357 return mask; 367 return mask;
358} 368}
359 369
360static unsigned int get_mmio_spte_generation(u64 spte) 370static u64 get_mmio_spte_generation(u64 spte)
361{ 371{
362 unsigned int gen; 372 u64 gen;
363 373
364 spte &= ~shadow_mmio_mask; 374 spte &= ~shadow_mmio_mask;
365 375
366 gen = (spte >> MMIO_SPTE_GEN_LOW_SHIFT) & MMIO_GEN_LOW_MASK; 376 gen = (spte & MMIO_SPTE_GEN_LOW_MASK) >> MMIO_SPTE_GEN_LOW_START;
367 gen |= (spte >> MMIO_SPTE_GEN_HIGH_SHIFT) << MMIO_GEN_LOW_SHIFT; 377 gen |= (spte & MMIO_SPTE_GEN_HIGH_MASK) >> MMIO_SPTE_GEN_HIGH_START;
368 return gen; 378 return gen;
369} 379}
370 380
371static unsigned int kvm_current_mmio_generation(struct kvm_vcpu *vcpu)
372{
373 return kvm_vcpu_memslots(vcpu)->generation & MMIO_GEN_MASK;
374}
375
376static void mark_mmio_spte(struct kvm_vcpu *vcpu, u64 *sptep, u64 gfn, 381static void mark_mmio_spte(struct kvm_vcpu *vcpu, u64 *sptep, u64 gfn,
377 unsigned access) 382 unsigned access)
378{ 383{
379 unsigned int gen = kvm_current_mmio_generation(vcpu); 384 u64 gen = kvm_vcpu_memslots(vcpu)->generation & MMIO_SPTE_GEN_MASK;
380 u64 mask = generation_mmio_spte_mask(gen); 385 u64 mask = generation_mmio_spte_mask(gen);
381 u64 gpa = gfn << PAGE_SHIFT; 386 u64 gpa = gfn << PAGE_SHIFT;
382 387
@@ -386,6 +391,8 @@ static void mark_mmio_spte(struct kvm_vcpu *vcpu, u64 *sptep, u64 gfn,
386 mask |= (gpa & shadow_nonpresent_or_rsvd_mask) 391 mask |= (gpa & shadow_nonpresent_or_rsvd_mask)
387 << shadow_nonpresent_or_rsvd_mask_len; 392 << shadow_nonpresent_or_rsvd_mask_len;
388 393
394 page_header(__pa(sptep))->mmio_cached = true;
395
389 trace_mark_mmio_spte(sptep, gfn, access, gen); 396 trace_mark_mmio_spte(sptep, gfn, access, gen);
390 mmu_spte_set(sptep, mask); 397 mmu_spte_set(sptep, mask);
391} 398}
@@ -407,7 +414,7 @@ static gfn_t get_mmio_spte_gfn(u64 spte)
407 414
408static unsigned get_mmio_spte_access(u64 spte) 415static unsigned get_mmio_spte_access(u64 spte)
409{ 416{
410 u64 mask = generation_mmio_spte_mask(MMIO_GEN_MASK) | shadow_mmio_mask; 417 u64 mask = generation_mmio_spte_mask(MMIO_SPTE_GEN_MASK) | shadow_mmio_mask;
411 return (spte & ~mask) & ~PAGE_MASK; 418 return (spte & ~mask) & ~PAGE_MASK;
412} 419}
413 420
@@ -424,9 +431,13 @@ static bool set_mmio_spte(struct kvm_vcpu *vcpu, u64 *sptep, gfn_t gfn,
424 431
425static bool check_mmio_spte(struct kvm_vcpu *vcpu, u64 spte) 432static bool check_mmio_spte(struct kvm_vcpu *vcpu, u64 spte)
426{ 433{
427 unsigned int kvm_gen, spte_gen; 434 u64 kvm_gen, spte_gen, gen;
428 435
429 kvm_gen = kvm_current_mmio_generation(vcpu); 436 gen = kvm_vcpu_memslots(vcpu)->generation;
437 if (unlikely(gen & KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS))
438 return false;
439
440 kvm_gen = gen & MMIO_SPTE_GEN_MASK;
430 spte_gen = get_mmio_spte_generation(spte); 441 spte_gen = get_mmio_spte_generation(spte);
431 442
432 trace_check_mmio_spte(spte, kvm_gen, spte_gen); 443 trace_check_mmio_spte(spte, kvm_gen, spte_gen);
@@ -959,7 +970,7 @@ static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
959 if (cache->nobjs >= min) 970 if (cache->nobjs >= min)
960 return 0; 971 return 0;
961 while (cache->nobjs < ARRAY_SIZE(cache->objects)) { 972 while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
962 obj = kmem_cache_zalloc(base_cache, GFP_KERNEL); 973 obj = kmem_cache_zalloc(base_cache, GFP_KERNEL_ACCOUNT);
963 if (!obj) 974 if (!obj)
964 return cache->nobjs >= min ? 0 : -ENOMEM; 975 return cache->nobjs >= min ? 0 : -ENOMEM;
965 cache->objects[cache->nobjs++] = obj; 976 cache->objects[cache->nobjs++] = obj;
@@ -2049,12 +2060,6 @@ static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, int direct
2049 if (!direct) 2060 if (!direct)
2050 sp->gfns = mmu_memory_cache_alloc(&vcpu->arch.mmu_page_cache); 2061 sp->gfns = mmu_memory_cache_alloc(&vcpu->arch.mmu_page_cache);
2051 set_page_private(virt_to_page(sp->spt), (unsigned long)sp); 2062 set_page_private(virt_to_page(sp->spt), (unsigned long)sp);
2052
2053 /*
2054 * The active_mmu_pages list is the FIFO list, do not move the
2055 * page until it is zapped. kvm_zap_obsolete_pages depends on
2056 * this feature. See the comments in kvm_zap_obsolete_pages().
2057 */
2058 list_add(&sp->link, &vcpu->kvm->arch.active_mmu_pages); 2063 list_add(&sp->link, &vcpu->kvm->arch.active_mmu_pages);
2059 kvm_mod_used_mmu_pages(vcpu->kvm, +1); 2064 kvm_mod_used_mmu_pages(vcpu->kvm, +1);
2060 return sp; 2065 return sp;
@@ -2195,23 +2200,15 @@ static void kvm_unlink_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp)
2195 --kvm->stat.mmu_unsync; 2200 --kvm->stat.mmu_unsync;
2196} 2201}
2197 2202
2198static int kvm_mmu_prepare_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp, 2203static bool kvm_mmu_prepare_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp,
2199 struct list_head *invalid_list); 2204 struct list_head *invalid_list);
2200static void kvm_mmu_commit_zap_page(struct kvm *kvm, 2205static void kvm_mmu_commit_zap_page(struct kvm *kvm,
2201 struct list_head *invalid_list); 2206 struct list_head *invalid_list);
2202 2207
2203/*
2204 * NOTE: we should pay more attention on the zapped-obsolete page
2205 * (is_obsolete_sp(sp) && sp->role.invalid) when you do hash list walk
2206 * since it has been deleted from active_mmu_pages but still can be found
2207 * at hast list.
2208 *
2209 * for_each_valid_sp() has skipped that kind of pages.
2210 */
2211#define for_each_valid_sp(_kvm, _sp, _gfn) \ 2208#define for_each_valid_sp(_kvm, _sp, _gfn) \
2212 hlist_for_each_entry(_sp, \ 2209 hlist_for_each_entry(_sp, \
2213 &(_kvm)->arch.mmu_page_hash[kvm_page_table_hashfn(_gfn)], hash_link) \ 2210 &(_kvm)->arch.mmu_page_hash[kvm_page_table_hashfn(_gfn)], hash_link) \
2214 if (is_obsolete_sp((_kvm), (_sp)) || (_sp)->role.invalid) { \ 2211 if ((_sp)->role.invalid) { \
2215 } else 2212 } else
2216 2213
2217#define for_each_gfn_indirect_valid_sp(_kvm, _sp, _gfn) \ 2214#define for_each_gfn_indirect_valid_sp(_kvm, _sp, _gfn) \
@@ -2231,18 +2228,28 @@ static bool __kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
2231 return true; 2228 return true;
2232} 2229}
2233 2230
2231static bool kvm_mmu_remote_flush_or_zap(struct kvm *kvm,
2232 struct list_head *invalid_list,
2233 bool remote_flush)
2234{
2235 if (!remote_flush && !list_empty(invalid_list))
2236 return false;
2237
2238 if (!list_empty(invalid_list))
2239 kvm_mmu_commit_zap_page(kvm, invalid_list);
2240 else
2241 kvm_flush_remote_tlbs(kvm);
2242 return true;
2243}
2244
2234static void kvm_mmu_flush_or_zap(struct kvm_vcpu *vcpu, 2245static void kvm_mmu_flush_or_zap(struct kvm_vcpu *vcpu,
2235 struct list_head *invalid_list, 2246 struct list_head *invalid_list,
2236 bool remote_flush, bool local_flush) 2247 bool remote_flush, bool local_flush)
2237{ 2248{
2238 if (!list_empty(invalid_list)) { 2249 if (kvm_mmu_remote_flush_or_zap(vcpu->kvm, invalid_list, remote_flush))
2239 kvm_mmu_commit_zap_page(vcpu->kvm, invalid_list);
2240 return; 2250 return;
2241 }
2242 2251
2243 if (remote_flush) 2252 if (local_flush)
2244 kvm_flush_remote_tlbs(vcpu->kvm);
2245 else if (local_flush)
2246 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); 2253 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
2247} 2254}
2248 2255
@@ -2253,11 +2260,6 @@ static void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point) { }
2253static void mmu_audit_disable(void) { } 2260static void mmu_audit_disable(void) { }
2254#endif 2261#endif
2255 2262
2256static bool is_obsolete_sp(struct kvm *kvm, struct kvm_mmu_page *sp)
2257{
2258 return unlikely(sp->mmu_valid_gen != kvm->arch.mmu_valid_gen);
2259}
2260
2261static bool kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, 2263static bool kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
2262 struct list_head *invalid_list) 2264 struct list_head *invalid_list)
2263{ 2265{
@@ -2482,7 +2484,6 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
2482 if (level > PT_PAGE_TABLE_LEVEL && need_sync) 2484 if (level > PT_PAGE_TABLE_LEVEL && need_sync)
2483 flush |= kvm_sync_pages(vcpu, gfn, &invalid_list); 2485 flush |= kvm_sync_pages(vcpu, gfn, &invalid_list);
2484 } 2486 }
2485 sp->mmu_valid_gen = vcpu->kvm->arch.mmu_valid_gen;
2486 clear_page(sp->spt); 2487 clear_page(sp->spt);
2487 trace_kvm_mmu_get_page(sp, true); 2488 trace_kvm_mmu_get_page(sp, true);
2488 2489
@@ -2668,17 +2669,22 @@ static int mmu_zap_unsync_children(struct kvm *kvm,
2668 return zapped; 2669 return zapped;
2669} 2670}
2670 2671
2671static int kvm_mmu_prepare_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp, 2672static bool __kvm_mmu_prepare_zap_page(struct kvm *kvm,
2672 struct list_head *invalid_list) 2673 struct kvm_mmu_page *sp,
2674 struct list_head *invalid_list,
2675 int *nr_zapped)
2673{ 2676{
2674 int ret; 2677 bool list_unstable;
2675 2678
2676 trace_kvm_mmu_prepare_zap_page(sp); 2679 trace_kvm_mmu_prepare_zap_page(sp);
2677 ++kvm->stat.mmu_shadow_zapped; 2680 ++kvm->stat.mmu_shadow_zapped;
2678 ret = mmu_zap_unsync_children(kvm, sp, invalid_list); 2681 *nr_zapped = mmu_zap_unsync_children(kvm, sp, invalid_list);
2679 kvm_mmu_page_unlink_children(kvm, sp); 2682 kvm_mmu_page_unlink_children(kvm, sp);
2680 kvm_mmu_unlink_parents(kvm, sp); 2683 kvm_mmu_unlink_parents(kvm, sp);
2681 2684
2685 /* Zapping children means active_mmu_pages has become unstable. */
2686 list_unstable = *nr_zapped;
2687
2682 if (!sp->role.invalid && !sp->role.direct) 2688 if (!sp->role.invalid && !sp->role.direct)
2683 unaccount_shadowed(kvm, sp); 2689 unaccount_shadowed(kvm, sp);
2684 2690
@@ -2686,22 +2692,27 @@ static int kvm_mmu_prepare_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp,
2686 kvm_unlink_unsync_page(kvm, sp); 2692 kvm_unlink_unsync_page(kvm, sp);
2687 if (!sp->root_count) { 2693 if (!sp->root_count) {
2688 /* Count self */ 2694 /* Count self */
2689 ret++; 2695 (*nr_zapped)++;
2690 list_move(&sp->link, invalid_list); 2696 list_move(&sp->link, invalid_list);
2691 kvm_mod_used_mmu_pages(kvm, -1); 2697 kvm_mod_used_mmu_pages(kvm, -1);
2692 } else { 2698 } else {
2693 list_move(&sp->link, &kvm->arch.active_mmu_pages); 2699 list_move(&sp->link, &kvm->arch.active_mmu_pages);
2694 2700
2695 /* 2701 if (!sp->role.invalid)
2696 * The obsolete pages can not be used on any vcpus.
2697 * See the comments in kvm_mmu_invalidate_zap_all_pages().
2698 */
2699 if (!sp->role.invalid && !is_obsolete_sp(kvm, sp))
2700 kvm_reload_remote_mmus(kvm); 2702 kvm_reload_remote_mmus(kvm);
2701 } 2703 }
2702 2704
2703 sp->role.invalid = 1; 2705 sp->role.invalid = 1;
2704 return ret; 2706 return list_unstable;
2707}
2708
2709static bool kvm_mmu_prepare_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp,
2710 struct list_head *invalid_list)
2711{
2712 int nr_zapped;
2713
2714 __kvm_mmu_prepare_zap_page(kvm, sp, invalid_list, &nr_zapped);
2715 return nr_zapped;
2705} 2716}
2706 2717
2707static void kvm_mmu_commit_zap_page(struct kvm *kvm, 2718static void kvm_mmu_commit_zap_page(struct kvm *kvm,
@@ -3703,7 +3714,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
3703 3714
3704 u64 *lm_root; 3715 u64 *lm_root;
3705 3716
3706 lm_root = (void*)get_zeroed_page(GFP_KERNEL); 3717 lm_root = (void*)get_zeroed_page(GFP_KERNEL_ACCOUNT);
3707 if (lm_root == NULL) 3718 if (lm_root == NULL)
3708 return 1; 3719 return 1;
3709 3720
@@ -4204,14 +4215,6 @@ static bool fast_cr3_switch(struct kvm_vcpu *vcpu, gpa_t new_cr3,
4204 return false; 4215 return false;
4205 4216
4206 if (cached_root_available(vcpu, new_cr3, new_role)) { 4217 if (cached_root_available(vcpu, new_cr3, new_role)) {
4207 /*
4208 * It is possible that the cached previous root page is
4209 * obsolete because of a change in the MMU
4210 * generation number. However, that is accompanied by
4211 * KVM_REQ_MMU_RELOAD, which will free the root that we
4212 * have set here and allocate a new one.
4213 */
4214
4215 kvm_make_request(KVM_REQ_LOAD_CR3, vcpu); 4218 kvm_make_request(KVM_REQ_LOAD_CR3, vcpu);
4216 if (!skip_tlb_flush) { 4219 if (!skip_tlb_flush) {
4217 kvm_make_request(KVM_REQ_MMU_SYNC, vcpu); 4220 kvm_make_request(KVM_REQ_MMU_SYNC, vcpu);
@@ -5486,6 +5489,76 @@ void kvm_disable_tdp(void)
5486} 5489}
5487EXPORT_SYMBOL_GPL(kvm_disable_tdp); 5490EXPORT_SYMBOL_GPL(kvm_disable_tdp);
5488 5491
5492
5493/* The return value indicates if tlb flush on all vcpus is needed. */
5494typedef bool (*slot_level_handler) (struct kvm *kvm, struct kvm_rmap_head *rmap_head);
5495
5496/* The caller should hold mmu-lock before calling this function. */
5497static __always_inline bool
5498slot_handle_level_range(struct kvm *kvm, struct kvm_memory_slot *memslot,
5499 slot_level_handler fn, int start_level, int end_level,
5500 gfn_t start_gfn, gfn_t end_gfn, bool lock_flush_tlb)
5501{
5502 struct slot_rmap_walk_iterator iterator;
5503 bool flush = false;
5504
5505 for_each_slot_rmap_range(memslot, start_level, end_level, start_gfn,
5506 end_gfn, &iterator) {
5507 if (iterator.rmap)
5508 flush |= fn(kvm, iterator.rmap);
5509
5510 if (need_resched() || spin_needbreak(&kvm->mmu_lock)) {
5511 if (flush && lock_flush_tlb) {
5512 kvm_flush_remote_tlbs(kvm);
5513 flush = false;
5514 }
5515 cond_resched_lock(&kvm->mmu_lock);
5516 }
5517 }
5518
5519 if (flush && lock_flush_tlb) {
5520 kvm_flush_remote_tlbs(kvm);
5521 flush = false;
5522 }
5523
5524 return flush;
5525}
5526
5527static __always_inline bool
5528slot_handle_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5529 slot_level_handler fn, int start_level, int end_level,
5530 bool lock_flush_tlb)
5531{
5532 return slot_handle_level_range(kvm, memslot, fn, start_level,
5533 end_level, memslot->base_gfn,
5534 memslot->base_gfn + memslot->npages - 1,
5535 lock_flush_tlb);
5536}
5537
5538static __always_inline bool
5539slot_handle_all_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5540 slot_level_handler fn, bool lock_flush_tlb)
5541{
5542 return slot_handle_level(kvm, memslot, fn, PT_PAGE_TABLE_LEVEL,
5543 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb);
5544}
5545
5546static __always_inline bool
5547slot_handle_large_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5548 slot_level_handler fn, bool lock_flush_tlb)
5549{
5550 return slot_handle_level(kvm, memslot, fn, PT_PAGE_TABLE_LEVEL + 1,
5551 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb);
5552}
5553
5554static __always_inline bool
5555slot_handle_leaf(struct kvm *kvm, struct kvm_memory_slot *memslot,
5556 slot_level_handler fn, bool lock_flush_tlb)
5557{
5558 return slot_handle_level(kvm, memslot, fn, PT_PAGE_TABLE_LEVEL,
5559 PT_PAGE_TABLE_LEVEL, lock_flush_tlb);
5560}
5561
5489static void free_mmu_pages(struct kvm_vcpu *vcpu) 5562static void free_mmu_pages(struct kvm_vcpu *vcpu)
5490{ 5563{
5491 free_page((unsigned long)vcpu->arch.mmu->pae_root); 5564 free_page((unsigned long)vcpu->arch.mmu->pae_root);
@@ -5505,7 +5578,7 @@ static int alloc_mmu_pages(struct kvm_vcpu *vcpu)
5505 * Therefore we need to allocate shadow page tables in the first 5578 * Therefore we need to allocate shadow page tables in the first
5506 * 4GB of memory, which happens to fit the DMA32 zone. 5579 * 4GB of memory, which happens to fit the DMA32 zone.
5507 */ 5580 */
5508 page = alloc_page(GFP_KERNEL | __GFP_DMA32); 5581 page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_DMA32);
5509 if (!page) 5582 if (!page)
5510 return -ENOMEM; 5583 return -ENOMEM;
5511 5584
@@ -5543,105 +5616,62 @@ static void kvm_mmu_invalidate_zap_pages_in_memslot(struct kvm *kvm,
5543 struct kvm_memory_slot *slot, 5616 struct kvm_memory_slot *slot,
5544 struct kvm_page_track_notifier_node *node) 5617 struct kvm_page_track_notifier_node *node)
5545{ 5618{
5546 kvm_mmu_invalidate_zap_all_pages(kvm); 5619 struct kvm_mmu_page *sp;
5547} 5620 LIST_HEAD(invalid_list);
5548 5621 unsigned long i;
5549void kvm_mmu_init_vm(struct kvm *kvm) 5622 bool flush;
5550{ 5623 gfn_t gfn;
5551 struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
5552
5553 node->track_write = kvm_mmu_pte_write;
5554 node->track_flush_slot = kvm_mmu_invalidate_zap_pages_in_memslot;
5555 kvm_page_track_register_notifier(kvm, node);
5556}
5557 5624
5558void kvm_mmu_uninit_vm(struct kvm *kvm) 5625 spin_lock(&kvm->mmu_lock);
5559{
5560 struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
5561 5626
5562 kvm_page_track_unregister_notifier(kvm, node); 5627 if (list_empty(&kvm->arch.active_mmu_pages))
5563} 5628 goto out_unlock;
5564 5629
5565/* The return value indicates if tlb flush on all vcpus is needed. */ 5630 flush = slot_handle_all_level(kvm, slot, kvm_zap_rmapp, false);
5566typedef bool (*slot_level_handler) (struct kvm *kvm, struct kvm_rmap_head *rmap_head);
5567 5631
5568/* The caller should hold mmu-lock before calling this function. */ 5632 for (i = 0; i < slot->npages; i++) {
5569static __always_inline bool 5633 gfn = slot->base_gfn + i;
5570slot_handle_level_range(struct kvm *kvm, struct kvm_memory_slot *memslot,
5571 slot_level_handler fn, int start_level, int end_level,
5572 gfn_t start_gfn, gfn_t end_gfn, bool lock_flush_tlb)
5573{
5574 struct slot_rmap_walk_iterator iterator;
5575 bool flush = false;
5576 5634
5577 for_each_slot_rmap_range(memslot, start_level, end_level, start_gfn, 5635 for_each_valid_sp(kvm, sp, gfn) {
5578 end_gfn, &iterator) { 5636 if (sp->gfn != gfn)
5579 if (iterator.rmap) 5637 continue;
5580 flush |= fn(kvm, iterator.rmap);
5581 5638
5639 kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list);
5640 }
5582 if (need_resched() || spin_needbreak(&kvm->mmu_lock)) { 5641 if (need_resched() || spin_needbreak(&kvm->mmu_lock)) {
5583 if (flush && lock_flush_tlb) { 5642 kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush);
5584 kvm_flush_remote_tlbs(kvm); 5643 flush = false;
5585 flush = false;
5586 }
5587 cond_resched_lock(&kvm->mmu_lock); 5644 cond_resched_lock(&kvm->mmu_lock);
5588 } 5645 }
5589 } 5646 }
5647 kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush);
5590 5648
5591 if (flush && lock_flush_tlb) { 5649out_unlock:
5592 kvm_flush_remote_tlbs(kvm); 5650 spin_unlock(&kvm->mmu_lock);
5593 flush = false;
5594 }
5595
5596 return flush;
5597} 5651}
5598 5652
5599static __always_inline bool 5653void kvm_mmu_init_vm(struct kvm *kvm)
5600slot_handle_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5601 slot_level_handler fn, int start_level, int end_level,
5602 bool lock_flush_tlb)
5603{ 5654{
5604 return slot_handle_level_range(kvm, memslot, fn, start_level, 5655 struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
5605 end_level, memslot->base_gfn,
5606 memslot->base_gfn + memslot->npages - 1,
5607 lock_flush_tlb);
5608}
5609 5656
5610static __always_inline bool 5657 node->track_write = kvm_mmu_pte_write;
5611slot_handle_all_level(struct kvm *kvm, struct kvm_memory_slot *memslot, 5658 node->track_flush_slot = kvm_mmu_invalidate_zap_pages_in_memslot;
5612 slot_level_handler fn, bool lock_flush_tlb) 5659 kvm_page_track_register_notifier(kvm, node);
5613{
5614 return slot_handle_level(kvm, memslot, fn, PT_PAGE_TABLE_LEVEL,
5615 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb);
5616} 5660}
5617 5661
5618static __always_inline bool 5662void kvm_mmu_uninit_vm(struct kvm *kvm)
5619slot_handle_large_level(struct kvm *kvm, struct kvm_memory_slot *memslot,
5620 slot_level_handler fn, bool lock_flush_tlb)
5621{ 5663{
5622 return slot_handle_level(kvm, memslot, fn, PT_PAGE_TABLE_LEVEL + 1, 5664 struct kvm_page_track_notifier_node *node = &kvm->arch.mmu_sp_tracker;
5623 PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb);
5624}
5625 5665
5626static __always_inline bool 5666 kvm_page_track_unregister_notifier(kvm, node);
5627slot_handle_leaf(struct kvm *kvm, struct kvm_memory_slot *memslot,
5628 slot_level_handler fn, bool lock_flush_tlb)
5629{
5630 return slot_handle_level(kvm, memslot, fn, PT_PAGE_TABLE_LEVEL,
5631 PT_PAGE_TABLE_LEVEL, lock_flush_tlb);
5632} 5667}
5633 5668
5634void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end) 5669void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
5635{ 5670{
5636 struct kvm_memslots *slots; 5671 struct kvm_memslots *slots;
5637 struct kvm_memory_slot *memslot; 5672 struct kvm_memory_slot *memslot;
5638 bool flush_tlb = true;
5639 bool flush = false;
5640 int i; 5673 int i;
5641 5674
5642 if (kvm_available_flush_tlb_with_range())
5643 flush_tlb = false;
5644
5645 spin_lock(&kvm->mmu_lock); 5675 spin_lock(&kvm->mmu_lock);
5646 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { 5676 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
5647 slots = __kvm_memslots(kvm, i); 5677 slots = __kvm_memslots(kvm, i);
@@ -5653,17 +5683,12 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
5653 if (start >= end) 5683 if (start >= end)
5654 continue; 5684 continue;
5655 5685
5656 flush |= slot_handle_level_range(kvm, memslot, 5686 slot_handle_level_range(kvm, memslot, kvm_zap_rmapp,
5657 kvm_zap_rmapp, PT_PAGE_TABLE_LEVEL, 5687 PT_PAGE_TABLE_LEVEL, PT_MAX_HUGEPAGE_LEVEL,
5658 PT_MAX_HUGEPAGE_LEVEL, start, 5688 start, end - 1, true);
5659 end - 1, flush_tlb);
5660 } 5689 }
5661 } 5690 }
5662 5691
5663 if (flush)
5664 kvm_flush_remote_tlbs_with_address(kvm, gfn_start,
5665 gfn_end - gfn_start + 1);
5666
5667 spin_unlock(&kvm->mmu_lock); 5692 spin_unlock(&kvm->mmu_lock);
5668} 5693}
5669 5694
@@ -5815,101 +5840,58 @@ void kvm_mmu_slot_set_dirty(struct kvm *kvm,
5815} 5840}
5816EXPORT_SYMBOL_GPL(kvm_mmu_slot_set_dirty); 5841EXPORT_SYMBOL_GPL(kvm_mmu_slot_set_dirty);
5817 5842
5818#define BATCH_ZAP_PAGES 10 5843static void __kvm_mmu_zap_all(struct kvm *kvm, bool mmio_only)
5819static void kvm_zap_obsolete_pages(struct kvm *kvm)
5820{ 5844{
5821 struct kvm_mmu_page *sp, *node; 5845 struct kvm_mmu_page *sp, *node;
5822 int batch = 0; 5846 LIST_HEAD(invalid_list);
5847 int ign;
5823 5848
5849 spin_lock(&kvm->mmu_lock);
5824restart: 5850restart:
5825 list_for_each_entry_safe_reverse(sp, node, 5851 list_for_each_entry_safe(sp, node, &kvm->arch.active_mmu_pages, link) {
5826 &kvm->arch.active_mmu_pages, link) { 5852 if (mmio_only && !sp->mmio_cached)
5827 int ret;
5828
5829 /*
5830 * No obsolete page exists before new created page since
5831 * active_mmu_pages is the FIFO list.
5832 */
5833 if (!is_obsolete_sp(kvm, sp))
5834 break;
5835
5836 /*
5837 * Since we are reversely walking the list and the invalid
5838 * list will be moved to the head, skip the invalid page
5839 * can help us to avoid the infinity list walking.
5840 */
5841 if (sp->role.invalid)
5842 continue; 5853 continue;
5843 5854 if (sp->role.invalid && sp->root_count)
5844 /* 5855 continue;
5845 * Need not flush tlb since we only zap the sp with invalid 5856 if (__kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list, &ign)) {
5846 * generation number. 5857 WARN_ON_ONCE(mmio_only);
5847 */
5848 if (batch >= BATCH_ZAP_PAGES &&
5849 cond_resched_lock(&kvm->mmu_lock)) {
5850 batch = 0;
5851 goto restart; 5858 goto restart;
5852 } 5859 }
5853 5860 if (cond_resched_lock(&kvm->mmu_lock))
5854 ret = kvm_mmu_prepare_zap_page(kvm, sp,
5855 &kvm->arch.zapped_obsolete_pages);
5856 batch += ret;
5857
5858 if (ret)
5859 goto restart; 5861 goto restart;
5860 } 5862 }
5861 5863
5862 /* 5864 kvm_mmu_commit_zap_page(kvm, &invalid_list);
5863 * Should flush tlb before free page tables since lockless-walking
5864 * may use the pages.
5865 */
5866 kvm_mmu_commit_zap_page(kvm, &kvm->arch.zapped_obsolete_pages);
5867}
5868
5869/*
5870 * Fast invalidate all shadow pages and use lock-break technique
5871 * to zap obsolete pages.
5872 *
5873 * It's required when memslot is being deleted or VM is being
5874 * destroyed, in these cases, we should ensure that KVM MMU does
5875 * not use any resource of the being-deleted slot or all slots
5876 * after calling the function.
5877 */
5878void kvm_mmu_invalidate_zap_all_pages(struct kvm *kvm)
5879{
5880 spin_lock(&kvm->mmu_lock);
5881 trace_kvm_mmu_invalidate_zap_all_pages(kvm);
5882 kvm->arch.mmu_valid_gen++;
5883
5884 /*
5885 * Notify all vcpus to reload its shadow page table
5886 * and flush TLB. Then all vcpus will switch to new
5887 * shadow page table with the new mmu_valid_gen.
5888 *
5889 * Note: we should do this under the protection of
5890 * mmu-lock, otherwise, vcpu would purge shadow page
5891 * but miss tlb flush.
5892 */
5893 kvm_reload_remote_mmus(kvm);
5894
5895 kvm_zap_obsolete_pages(kvm);
5896 spin_unlock(&kvm->mmu_lock); 5865 spin_unlock(&kvm->mmu_lock);
5897} 5866}
5898 5867
5899static bool kvm_has_zapped_obsolete_pages(struct kvm *kvm) 5868void kvm_mmu_zap_all(struct kvm *kvm)
5900{ 5869{
5901 return unlikely(!list_empty_careful(&kvm->arch.zapped_obsolete_pages)); 5870 return __kvm_mmu_zap_all(kvm, false);
5902} 5871}
5903 5872
5904void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, struct kvm_memslots *slots) 5873void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)
5905{ 5874{
5875 WARN_ON(gen & KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS);
5876
5877 gen &= MMIO_SPTE_GEN_MASK;
5878
5906 /* 5879 /*
5907 * The very rare case: if the generation-number is round, 5880 * Generation numbers are incremented in multiples of the number of
5881 * address spaces in order to provide unique generations across all
5882 * address spaces. Strip what is effectively the address space
5883 * modifier prior to checking for a wrap of the MMIO generation so
5884 * that a wrap in any address space is detected.
5885 */
5886 gen &= ~((u64)KVM_ADDRESS_SPACE_NUM - 1);
5887
5888 /*
5889 * The very rare case: if the MMIO generation number has wrapped,
5908 * zap all shadow pages. 5890 * zap all shadow pages.
5909 */ 5891 */
5910 if (unlikely((slots->generation & MMIO_GEN_MASK) == 0)) { 5892 if (unlikely(gen == 0)) {
5911 kvm_debug_ratelimited("kvm: zapping shadow pages for mmio generation wraparound\n"); 5893 kvm_debug_ratelimited("kvm: zapping shadow pages for mmio generation wraparound\n");
5912 kvm_mmu_invalidate_zap_all_pages(kvm); 5894 __kvm_mmu_zap_all(kvm, true);
5913 } 5895 }
5914} 5896}
5915 5897
@@ -5940,24 +5922,16 @@ mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
5940 * want to shrink a VM that only started to populate its MMU 5922 * want to shrink a VM that only started to populate its MMU
5941 * anyway. 5923 * anyway.
5942 */ 5924 */
5943 if (!kvm->arch.n_used_mmu_pages && 5925 if (!kvm->arch.n_used_mmu_pages)
5944 !kvm_has_zapped_obsolete_pages(kvm))
5945 continue; 5926 continue;
5946 5927
5947 idx = srcu_read_lock(&kvm->srcu); 5928 idx = srcu_read_lock(&kvm->srcu);
5948 spin_lock(&kvm->mmu_lock); 5929 spin_lock(&kvm->mmu_lock);
5949 5930
5950 if (kvm_has_zapped_obsolete_pages(kvm)) {
5951 kvm_mmu_commit_zap_page(kvm,
5952 &kvm->arch.zapped_obsolete_pages);
5953 goto unlock;
5954 }
5955
5956 if (prepare_zap_oldest_mmu_page(kvm, &invalid_list)) 5931 if (prepare_zap_oldest_mmu_page(kvm, &invalid_list))
5957 freed++; 5932 freed++;
5958 kvm_mmu_commit_zap_page(kvm, &invalid_list); 5933 kvm_mmu_commit_zap_page(kvm, &invalid_list);
5959 5934
5960unlock:
5961 spin_unlock(&kvm->mmu_lock); 5935 spin_unlock(&kvm->mmu_lock);
5962 srcu_read_unlock(&kvm->srcu, idx); 5936 srcu_read_unlock(&kvm->srcu, idx);
5963 5937
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index c7b333147c4a..bbdc60f2fae8 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -203,7 +203,6 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
203 return -(u32)fault & errcode; 203 return -(u32)fault & errcode;
204} 204}
205 205
206void kvm_mmu_invalidate_zap_all_pages(struct kvm *kvm);
207void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end); 206void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end);
208 207
209void kvm_mmu_gfn_disallow_lpage(struct kvm_memory_slot *slot, gfn_t gfn); 208void kvm_mmu_gfn_disallow_lpage(struct kvm_memory_slot *slot, gfn_t gfn);
diff --git a/arch/x86/kvm/mmutrace.h b/arch/x86/kvm/mmutrace.h
index c73bf4e4988c..9f6c855a0043 100644
--- a/arch/x86/kvm/mmutrace.h
+++ b/arch/x86/kvm/mmutrace.h
@@ -8,18 +8,16 @@
8#undef TRACE_SYSTEM 8#undef TRACE_SYSTEM
9#define TRACE_SYSTEM kvmmmu 9#define TRACE_SYSTEM kvmmmu
10 10
11#define KVM_MMU_PAGE_FIELDS \ 11#define KVM_MMU_PAGE_FIELDS \
12 __field(unsigned long, mmu_valid_gen) \ 12 __field(__u64, gfn) \
13 __field(__u64, gfn) \ 13 __field(__u32, role) \
14 __field(__u32, role) \ 14 __field(__u32, root_count) \
15 __field(__u32, root_count) \
16 __field(bool, unsync) 15 __field(bool, unsync)
17 16
18#define KVM_MMU_PAGE_ASSIGN(sp) \ 17#define KVM_MMU_PAGE_ASSIGN(sp) \
19 __entry->mmu_valid_gen = sp->mmu_valid_gen; \ 18 __entry->gfn = sp->gfn; \
20 __entry->gfn = sp->gfn; \ 19 __entry->role = sp->role.word; \
21 __entry->role = sp->role.word; \ 20 __entry->root_count = sp->root_count; \
22 __entry->root_count = sp->root_count; \
23 __entry->unsync = sp->unsync; 21 __entry->unsync = sp->unsync;
24 22
25#define KVM_MMU_PAGE_PRINTK() ({ \ 23#define KVM_MMU_PAGE_PRINTK() ({ \
@@ -31,9 +29,8 @@
31 \ 29 \
32 role.word = __entry->role; \ 30 role.word = __entry->role; \
33 \ 31 \
34 trace_seq_printf(p, "sp gen %lx gfn %llx l%u%s q%u%s %s%s" \ 32 trace_seq_printf(p, "sp gfn %llx l%u%s q%u%s %s%s" \
35 " %snxe %sad root %u %s%c", \ 33 " %snxe %sad root %u %s%c", \
36 __entry->mmu_valid_gen, \
37 __entry->gfn, role.level, \ 34 __entry->gfn, role.level, \
38 role.cr4_pae ? " pae" : "", \ 35 role.cr4_pae ? " pae" : "", \
39 role.quadrant, \ 36 role.quadrant, \
@@ -283,27 +280,6 @@ TRACE_EVENT(
283); 280);
284 281
285TRACE_EVENT( 282TRACE_EVENT(
286 kvm_mmu_invalidate_zap_all_pages,
287 TP_PROTO(struct kvm *kvm),
288 TP_ARGS(kvm),
289
290 TP_STRUCT__entry(
291 __field(unsigned long, mmu_valid_gen)
292 __field(unsigned int, mmu_used_pages)
293 ),
294
295 TP_fast_assign(
296 __entry->mmu_valid_gen = kvm->arch.mmu_valid_gen;
297 __entry->mmu_used_pages = kvm->arch.n_used_mmu_pages;
298 ),
299
300 TP_printk("kvm-mmu-valid-gen %lx used_pages %x",
301 __entry->mmu_valid_gen, __entry->mmu_used_pages
302 )
303);
304
305
306TRACE_EVENT(
307 check_mmio_spte, 283 check_mmio_spte,
308 TP_PROTO(u64 spte, unsigned int kvm_gen, unsigned int spte_gen), 284 TP_PROTO(u64 spte, unsigned int kvm_gen, unsigned int spte_gen),
309 TP_ARGS(spte, kvm_gen, spte_gen), 285 TP_ARGS(spte, kvm_gen, spte_gen),
diff --git a/arch/x86/kvm/page_track.c b/arch/x86/kvm/page_track.c
index 3052a59a3065..fd04d462fdae 100644
--- a/arch/x86/kvm/page_track.c
+++ b/arch/x86/kvm/page_track.c
@@ -42,7 +42,7 @@ int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
42 for (i = 0; i < KVM_PAGE_TRACK_MAX; i++) { 42 for (i = 0; i < KVM_PAGE_TRACK_MAX; i++) {
43 slot->arch.gfn_track[i] = 43 slot->arch.gfn_track[i] =
44 kvcalloc(npages, sizeof(*slot->arch.gfn_track[i]), 44 kvcalloc(npages, sizeof(*slot->arch.gfn_track[i]),
45 GFP_KERNEL); 45 GFP_KERNEL_ACCOUNT);
46 if (!slot->arch.gfn_track[i]) 46 if (!slot->arch.gfn_track[i])
47 goto track_free; 47 goto track_free;
48 } 48 }
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index f13a3a24d360..b5b128a0a051 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -145,7 +145,6 @@ struct kvm_svm {
145 145
146 /* Struct members for AVIC */ 146 /* Struct members for AVIC */
147 u32 avic_vm_id; 147 u32 avic_vm_id;
148 u32 ldr_mode;
149 struct page *avic_logical_id_table_page; 148 struct page *avic_logical_id_table_page;
150 struct page *avic_physical_id_table_page; 149 struct page *avic_physical_id_table_page;
151 struct hlist_node hnode; 150 struct hlist_node hnode;
@@ -236,6 +235,7 @@ struct vcpu_svm {
236 bool nrips_enabled : 1; 235 bool nrips_enabled : 1;
237 236
238 u32 ldr_reg; 237 u32 ldr_reg;
238 u32 dfr_reg;
239 struct page *avic_backing_page; 239 struct page *avic_backing_page;
240 u64 *avic_physical_id_cache; 240 u64 *avic_physical_id_cache;
241 bool avic_is_running; 241 bool avic_is_running;
@@ -1795,9 +1795,10 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
1795 /* Avoid using vmalloc for smaller buffers. */ 1795 /* Avoid using vmalloc for smaller buffers. */
1796 size = npages * sizeof(struct page *); 1796 size = npages * sizeof(struct page *);
1797 if (size > PAGE_SIZE) 1797 if (size > PAGE_SIZE)
1798 pages = vmalloc(size); 1798 pages = __vmalloc(size, GFP_KERNEL_ACCOUNT | __GFP_ZERO,
1799 PAGE_KERNEL);
1799 else 1800 else
1800 pages = kmalloc(size, GFP_KERNEL); 1801 pages = kmalloc(size, GFP_KERNEL_ACCOUNT);
1801 1802
1802 if (!pages) 1803 if (!pages)
1803 return NULL; 1804 return NULL;
@@ -1865,7 +1866,9 @@ static void __unregister_enc_region_locked(struct kvm *kvm,
1865 1866
1866static struct kvm *svm_vm_alloc(void) 1867static struct kvm *svm_vm_alloc(void)
1867{ 1868{
1868 struct kvm_svm *kvm_svm = vzalloc(sizeof(struct kvm_svm)); 1869 struct kvm_svm *kvm_svm = __vmalloc(sizeof(struct kvm_svm),
1870 GFP_KERNEL_ACCOUNT | __GFP_ZERO,
1871 PAGE_KERNEL);
1869 return &kvm_svm->kvm; 1872 return &kvm_svm->kvm;
1870} 1873}
1871 1874
@@ -1940,7 +1943,7 @@ static int avic_vm_init(struct kvm *kvm)
1940 return 0; 1943 return 0;
1941 1944
1942 /* Allocating physical APIC ID table (4KB) */ 1945 /* Allocating physical APIC ID table (4KB) */
1943 p_page = alloc_page(GFP_KERNEL); 1946 p_page = alloc_page(GFP_KERNEL_ACCOUNT);
1944 if (!p_page) 1947 if (!p_page)
1945 goto free_avic; 1948 goto free_avic;
1946 1949
@@ -1948,7 +1951,7 @@ static int avic_vm_init(struct kvm *kvm)
1948 clear_page(page_address(p_page)); 1951 clear_page(page_address(p_page));
1949 1952
1950 /* Allocating logical APIC ID table (4KB) */ 1953 /* Allocating logical APIC ID table (4KB) */
1951 l_page = alloc_page(GFP_KERNEL); 1954 l_page = alloc_page(GFP_KERNEL_ACCOUNT);
1952 if (!l_page) 1955 if (!l_page)
1953 goto free_avic; 1956 goto free_avic;
1954 1957
@@ -2106,6 +2109,7 @@ static int avic_init_vcpu(struct vcpu_svm *svm)
2106 2109
2107 INIT_LIST_HEAD(&svm->ir_list); 2110 INIT_LIST_HEAD(&svm->ir_list);
2108 spin_lock_init(&svm->ir_list_lock); 2111 spin_lock_init(&svm->ir_list_lock);
2112 svm->dfr_reg = APIC_DFR_FLAT;
2109 2113
2110 return ret; 2114 return ret;
2111} 2115}
@@ -2119,13 +2123,14 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
2119 struct page *nested_msrpm_pages; 2123 struct page *nested_msrpm_pages;
2120 int err; 2124 int err;
2121 2125
2122 svm = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); 2126 svm = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL_ACCOUNT);
2123 if (!svm) { 2127 if (!svm) {
2124 err = -ENOMEM; 2128 err = -ENOMEM;
2125 goto out; 2129 goto out;
2126 } 2130 }
2127 2131
2128 svm->vcpu.arch.guest_fpu = kmem_cache_zalloc(x86_fpu_cache, GFP_KERNEL); 2132 svm->vcpu.arch.guest_fpu = kmem_cache_zalloc(x86_fpu_cache,
2133 GFP_KERNEL_ACCOUNT);
2129 if (!svm->vcpu.arch.guest_fpu) { 2134 if (!svm->vcpu.arch.guest_fpu) {
2130 printk(KERN_ERR "kvm: failed to allocate vcpu's fpu\n"); 2135 printk(KERN_ERR "kvm: failed to allocate vcpu's fpu\n");
2131 err = -ENOMEM; 2136 err = -ENOMEM;
@@ -2137,19 +2142,19 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
2137 goto free_svm; 2142 goto free_svm;
2138 2143
2139 err = -ENOMEM; 2144 err = -ENOMEM;
2140 page = alloc_page(GFP_KERNEL); 2145 page = alloc_page(GFP_KERNEL_ACCOUNT);
2141 if (!page) 2146 if (!page)
2142 goto uninit; 2147 goto uninit;
2143 2148
2144 msrpm_pages = alloc_pages(GFP_KERNEL, MSRPM_ALLOC_ORDER); 2149 msrpm_pages = alloc_pages(GFP_KERNEL_ACCOUNT, MSRPM_ALLOC_ORDER);
2145 if (!msrpm_pages) 2150 if (!msrpm_pages)
2146 goto free_page1; 2151 goto free_page1;
2147 2152
2148 nested_msrpm_pages = alloc_pages(GFP_KERNEL, MSRPM_ALLOC_ORDER); 2153 nested_msrpm_pages = alloc_pages(GFP_KERNEL_ACCOUNT, MSRPM_ALLOC_ORDER);
2149 if (!nested_msrpm_pages) 2154 if (!nested_msrpm_pages)
2150 goto free_page2; 2155 goto free_page2;
2151 2156
2152 hsave_page = alloc_page(GFP_KERNEL); 2157 hsave_page = alloc_page(GFP_KERNEL_ACCOUNT);
2153 if (!hsave_page) 2158 if (!hsave_page)
2154 goto free_page3; 2159 goto free_page3;
2155 2160
@@ -4565,8 +4570,7 @@ static u32 *avic_get_logical_id_entry(struct kvm_vcpu *vcpu, u32 ldr, bool flat)
4565 return &logical_apic_id_table[index]; 4570 return &logical_apic_id_table[index];
4566} 4571}
4567 4572
4568static int avic_ldr_write(struct kvm_vcpu *vcpu, u8 g_physical_id, u32 ldr, 4573static int avic_ldr_write(struct kvm_vcpu *vcpu, u8 g_physical_id, u32 ldr)
4569 bool valid)
4570{ 4574{
4571 bool flat; 4575 bool flat;
4572 u32 *entry, new_entry; 4576 u32 *entry, new_entry;
@@ -4579,31 +4583,39 @@ static int avic_ldr_write(struct kvm_vcpu *vcpu, u8 g_physical_id, u32 ldr,
4579 new_entry = READ_ONCE(*entry); 4583 new_entry = READ_ONCE(*entry);
4580 new_entry &= ~AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK; 4584 new_entry &= ~AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK;
4581 new_entry |= (g_physical_id & AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK); 4585 new_entry |= (g_physical_id & AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK);
4582 if (valid) 4586 new_entry |= AVIC_LOGICAL_ID_ENTRY_VALID_MASK;
4583 new_entry |= AVIC_LOGICAL_ID_ENTRY_VALID_MASK;
4584 else
4585 new_entry &= ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK;
4586 WRITE_ONCE(*entry, new_entry); 4587 WRITE_ONCE(*entry, new_entry);
4587 4588
4588 return 0; 4589 return 0;
4589} 4590}
4590 4591
4592static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
4593{
4594 struct vcpu_svm *svm = to_svm(vcpu);
4595 bool flat = svm->dfr_reg == APIC_DFR_FLAT;
4596 u32 *entry = avic_get_logical_id_entry(vcpu, svm->ldr_reg, flat);
4597
4598 if (entry)
4599 WRITE_ONCE(*entry, (u32) ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK);
4600}
4601
4591static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) 4602static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
4592{ 4603{
4593 int ret; 4604 int ret = 0;
4594 struct vcpu_svm *svm = to_svm(vcpu); 4605 struct vcpu_svm *svm = to_svm(vcpu);
4595 u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR); 4606 u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR);
4596 4607
4597 if (!ldr) 4608 if (ldr == svm->ldr_reg)
4598 return 1; 4609 return 0;
4599 4610
4600 ret = avic_ldr_write(vcpu, vcpu->vcpu_id, ldr, true); 4611 avic_invalidate_logical_id_entry(vcpu);
4601 if (ret && svm->ldr_reg) { 4612
4602 avic_ldr_write(vcpu, 0, svm->ldr_reg, false); 4613 if (ldr)
4603 svm->ldr_reg = 0; 4614 ret = avic_ldr_write(vcpu, vcpu->vcpu_id, ldr);
4604 } else { 4615
4616 if (!ret)
4605 svm->ldr_reg = ldr; 4617 svm->ldr_reg = ldr;
4606 } 4618
4607 return ret; 4619 return ret;
4608} 4620}
4609 4621
@@ -4637,27 +4649,16 @@ static int avic_handle_apic_id_update(struct kvm_vcpu *vcpu)
4637 return 0; 4649 return 0;
4638} 4650}
4639 4651
4640static int avic_handle_dfr_update(struct kvm_vcpu *vcpu) 4652static void avic_handle_dfr_update(struct kvm_vcpu *vcpu)
4641{ 4653{
4642 struct vcpu_svm *svm = to_svm(vcpu); 4654 struct vcpu_svm *svm = to_svm(vcpu);
4643 struct kvm_svm *kvm_svm = to_kvm_svm(vcpu->kvm);
4644 u32 dfr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_DFR); 4655 u32 dfr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_DFR);
4645 u32 mod = (dfr >> 28) & 0xf;
4646 4656
4647 /* 4657 if (svm->dfr_reg == dfr)
4648 * We assume that all local APICs are using the same type. 4658 return;
4649 * If this changes, we need to flush the AVIC logical
4650 * APID id table.
4651 */
4652 if (kvm_svm->ldr_mode == mod)
4653 return 0;
4654
4655 clear_page(page_address(kvm_svm->avic_logical_id_table_page));
4656 kvm_svm->ldr_mode = mod;
4657 4659
4658 if (svm->ldr_reg) 4660 avic_invalidate_logical_id_entry(vcpu);
4659 avic_handle_ldr_update(vcpu); 4661 svm->dfr_reg = dfr;
4660 return 0;
4661} 4662}
4662 4663
4663static int avic_unaccel_trap_write(struct vcpu_svm *svm) 4664static int avic_unaccel_trap_write(struct vcpu_svm *svm)
@@ -5125,11 +5126,11 @@ static void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu)
5125 struct vcpu_svm *svm = to_svm(vcpu); 5126 struct vcpu_svm *svm = to_svm(vcpu);
5126 struct vmcb *vmcb = svm->vmcb; 5127 struct vmcb *vmcb = svm->vmcb;
5127 5128
5128 if (!kvm_vcpu_apicv_active(&svm->vcpu)) 5129 if (kvm_vcpu_apicv_active(vcpu))
5129 return; 5130 vmcb->control.int_ctl |= AVIC_ENABLE_MASK;
5130 5131 else
5131 vmcb->control.int_ctl &= ~AVIC_ENABLE_MASK; 5132 vmcb->control.int_ctl &= ~AVIC_ENABLE_MASK;
5132 mark_dirty(vmcb, VMCB_INTR); 5133 mark_dirty(vmcb, VMCB_AVIC);
5133} 5134}
5134 5135
5135static void svm_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap) 5136static void svm_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
@@ -5195,7 +5196,7 @@ static int svm_ir_list_add(struct vcpu_svm *svm, struct amd_iommu_pi_data *pi)
5195 * Allocating new amd_iommu_pi_data, which will get 5196 * Allocating new amd_iommu_pi_data, which will get
5196 * add to the per-vcpu ir_list. 5197 * add to the per-vcpu ir_list.
5197 */ 5198 */
5198 ir = kzalloc(sizeof(struct amd_svm_iommu_ir), GFP_KERNEL); 5199 ir = kzalloc(sizeof(struct amd_svm_iommu_ir), GFP_KERNEL_ACCOUNT);
5199 if (!ir) { 5200 if (!ir) {
5200 ret = -ENOMEM; 5201 ret = -ENOMEM;
5201 goto out; 5202 goto out;
@@ -6163,8 +6164,7 @@ static inline void avic_post_state_restore(struct kvm_vcpu *vcpu)
6163{ 6164{
6164 if (avic_handle_apic_id_update(vcpu) != 0) 6165 if (avic_handle_apic_id_update(vcpu) != 0)
6165 return; 6166 return;
6166 if (avic_handle_dfr_update(vcpu) != 0) 6167 avic_handle_dfr_update(vcpu);
6167 return;
6168 avic_handle_ldr_update(vcpu); 6168 avic_handle_ldr_update(vcpu);
6169} 6169}
6170 6170
@@ -6311,7 +6311,7 @@ static int sev_bind_asid(struct kvm *kvm, unsigned int handle, int *error)
6311 if (ret) 6311 if (ret)
6312 return ret; 6312 return ret;
6313 6313
6314 data = kzalloc(sizeof(*data), GFP_KERNEL); 6314 data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT);
6315 if (!data) 6315 if (!data)
6316 return -ENOMEM; 6316 return -ENOMEM;
6317 6317
@@ -6361,7 +6361,7 @@ static int sev_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp)
6361 if (copy_from_user(&params, (void __user *)(uintptr_t)argp->data, sizeof(params))) 6361 if (copy_from_user(&params, (void __user *)(uintptr_t)argp->data, sizeof(params)))
6362 return -EFAULT; 6362 return -EFAULT;
6363 6363
6364 start = kzalloc(sizeof(*start), GFP_KERNEL); 6364 start = kzalloc(sizeof(*start), GFP_KERNEL_ACCOUNT);
6365 if (!start) 6365 if (!start)
6366 return -ENOMEM; 6366 return -ENOMEM;
6367 6367
@@ -6458,7 +6458,7 @@ static int sev_launch_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)
6458 if (copy_from_user(&params, (void __user *)(uintptr_t)argp->data, sizeof(params))) 6458 if (copy_from_user(&params, (void __user *)(uintptr_t)argp->data, sizeof(params)))
6459 return -EFAULT; 6459 return -EFAULT;
6460 6460
6461 data = kzalloc(sizeof(*data), GFP_KERNEL); 6461 data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT);
6462 if (!data) 6462 if (!data)
6463 return -ENOMEM; 6463 return -ENOMEM;
6464 6464
@@ -6535,7 +6535,7 @@ static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp)
6535 if (copy_from_user(&params, measure, sizeof(params))) 6535 if (copy_from_user(&params, measure, sizeof(params)))
6536 return -EFAULT; 6536 return -EFAULT;
6537 6537
6538 data = kzalloc(sizeof(*data), GFP_KERNEL); 6538 data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT);
6539 if (!data) 6539 if (!data)
6540 return -ENOMEM; 6540 return -ENOMEM;
6541 6541
@@ -6597,7 +6597,7 @@ static int sev_launch_finish(struct kvm *kvm, struct kvm_sev_cmd *argp)
6597 if (!sev_guest(kvm)) 6597 if (!sev_guest(kvm))
6598 return -ENOTTY; 6598 return -ENOTTY;
6599 6599
6600 data = kzalloc(sizeof(*data), GFP_KERNEL); 6600 data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT);
6601 if (!data) 6601 if (!data)
6602 return -ENOMEM; 6602 return -ENOMEM;
6603 6603
@@ -6618,7 +6618,7 @@ static int sev_guest_status(struct kvm *kvm, struct kvm_sev_cmd *argp)
6618 if (!sev_guest(kvm)) 6618 if (!sev_guest(kvm))
6619 return -ENOTTY; 6619 return -ENOTTY;
6620 6620
6621 data = kzalloc(sizeof(*data), GFP_KERNEL); 6621 data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT);
6622 if (!data) 6622 if (!data)
6623 return -ENOMEM; 6623 return -ENOMEM;
6624 6624
@@ -6646,7 +6646,7 @@ static int __sev_issue_dbg_cmd(struct kvm *kvm, unsigned long src,
6646 struct sev_data_dbg *data; 6646 struct sev_data_dbg *data;
6647 int ret; 6647 int ret;
6648 6648
6649 data = kzalloc(sizeof(*data), GFP_KERNEL); 6649 data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT);
6650 if (!data) 6650 if (!data)
6651 return -ENOMEM; 6651 return -ENOMEM;
6652 6652
@@ -6901,7 +6901,7 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp)
6901 } 6901 }
6902 6902
6903 ret = -ENOMEM; 6903 ret = -ENOMEM;
6904 data = kzalloc(sizeof(*data), GFP_KERNEL); 6904 data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT);
6905 if (!data) 6905 if (!data)
6906 goto e_unpin_memory; 6906 goto e_unpin_memory;
6907 6907
@@ -7007,7 +7007,7 @@ static int svm_register_enc_region(struct kvm *kvm,
7007 if (range->addr > ULONG_MAX || range->size > ULONG_MAX) 7007 if (range->addr > ULONG_MAX || range->size > ULONG_MAX)
7008 return -EINVAL; 7008 return -EINVAL;
7009 7009
7010 region = kzalloc(sizeof(*region), GFP_KERNEL); 7010 region = kzalloc(sizeof(*region), GFP_KERNEL_ACCOUNT);
7011 if (!region) 7011 if (!region)
7012 return -ENOMEM; 7012 return -ENOMEM;
7013 7013
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index d737a51a53ca..f24a2c225070 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -211,7 +211,6 @@ static void free_nested(struct kvm_vcpu *vcpu)
211 if (!vmx->nested.vmxon && !vmx->nested.smm.vmxon) 211 if (!vmx->nested.vmxon && !vmx->nested.smm.vmxon)
212 return; 212 return;
213 213
214 hrtimer_cancel(&vmx->nested.preemption_timer);
215 vmx->nested.vmxon = false; 214 vmx->nested.vmxon = false;
216 vmx->nested.smm.vmxon = false; 215 vmx->nested.smm.vmxon = false;
217 free_vpid(vmx->nested.vpid02); 216 free_vpid(vmx->nested.vpid02);
@@ -274,6 +273,7 @@ static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
274void nested_vmx_free_vcpu(struct kvm_vcpu *vcpu) 273void nested_vmx_free_vcpu(struct kvm_vcpu *vcpu)
275{ 274{
276 vcpu_load(vcpu); 275 vcpu_load(vcpu);
276 vmx_leave_nested(vcpu);
277 vmx_switch_vmcs(vcpu, &to_vmx(vcpu)->vmcs01); 277 vmx_switch_vmcs(vcpu, &to_vmx(vcpu)->vmcs01);
278 free_nested(vcpu); 278 free_nested(vcpu);
279 vcpu_put(vcpu); 279 vcpu_put(vcpu);
@@ -1980,17 +1980,6 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
1980 prepare_vmcs02_early_full(vmx, vmcs12); 1980 prepare_vmcs02_early_full(vmx, vmcs12);
1981 1981
1982 /* 1982 /*
1983 * HOST_RSP is normally set correctly in vmx_vcpu_run() just before
1984 * entry, but only if the current (host) sp changed from the value
1985 * we wrote last (vmx->host_rsp). This cache is no longer relevant
1986 * if we switch vmcs, and rather than hold a separate cache per vmcs,
1987 * here we just force the write to happen on entry. host_rsp will
1988 * also be written unconditionally by nested_vmx_check_vmentry_hw()
1989 * if we are doing early consistency checks via hardware.
1990 */
1991 vmx->host_rsp = 0;
1992
1993 /*
1994 * PIN CONTROLS 1983 * PIN CONTROLS
1995 */ 1984 */
1996 exec_control = vmcs12->pin_based_vm_exec_control; 1985 exec_control = vmcs12->pin_based_vm_exec_control;
@@ -2289,10 +2278,6 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
2289 } 2278 }
2290 vmx_set_rflags(vcpu, vmcs12->guest_rflags); 2279 vmx_set_rflags(vcpu, vmcs12->guest_rflags);
2291 2280
2292 vmx->nested.preemption_timer_expired = false;
2293 if (nested_cpu_has_preemption_timer(vmcs12))
2294 vmx_start_preemption_timer(vcpu);
2295
2296 /* EXCEPTION_BITMAP and CR0_GUEST_HOST_MASK should basically be the 2281 /* EXCEPTION_BITMAP and CR0_GUEST_HOST_MASK should basically be the
2297 * bitwise-or of what L1 wants to trap for L2, and what we want to 2282 * bitwise-or of what L1 wants to trap for L2, and what we want to
2298 * trap. Note that CR0.TS also needs updating - we do this later. 2283 * trap. Note that CR0.TS also needs updating - we do this later.
@@ -2722,6 +2707,7 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
2722{ 2707{
2723 struct vcpu_vmx *vmx = to_vmx(vcpu); 2708 struct vcpu_vmx *vmx = to_vmx(vcpu);
2724 unsigned long cr3, cr4; 2709 unsigned long cr3, cr4;
2710 bool vm_fail;
2725 2711
2726 if (!nested_early_check) 2712 if (!nested_early_check)
2727 return 0; 2713 return 0;
@@ -2755,29 +2741,34 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
2755 vmx->loaded_vmcs->host_state.cr4 = cr4; 2741 vmx->loaded_vmcs->host_state.cr4 = cr4;
2756 } 2742 }
2757 2743
2758 vmx->__launched = vmx->loaded_vmcs->launched;
2759
2760 asm( 2744 asm(
2761 /* Set HOST_RSP */
2762 "sub $%c[wordsize], %%" _ASM_SP "\n\t" /* temporarily adjust RSP for CALL */ 2745 "sub $%c[wordsize], %%" _ASM_SP "\n\t" /* temporarily adjust RSP for CALL */
2763 __ex("vmwrite %%" _ASM_SP ", %%" _ASM_DX) "\n\t" 2746 "cmp %%" _ASM_SP ", %c[host_state_rsp](%[loaded_vmcs]) \n\t"
2764 "mov %%" _ASM_SP ", %c[host_rsp](%1)\n\t" 2747 "je 1f \n\t"
2748 __ex("vmwrite %%" _ASM_SP ", %[HOST_RSP]") "\n\t"
2749 "mov %%" _ASM_SP ", %c[host_state_rsp](%[loaded_vmcs]) \n\t"
2750 "1: \n\t"
2765 "add $%c[wordsize], %%" _ASM_SP "\n\t" /* un-adjust RSP */ 2751 "add $%c[wordsize], %%" _ASM_SP "\n\t" /* un-adjust RSP */
2766 2752
2767 /* Check if vmlaunch or vmresume is needed */ 2753 /* Check if vmlaunch or vmresume is needed */
2768 "cmpl $0, %c[launched](%% " _ASM_CX")\n\t" 2754 "cmpb $0, %c[launched](%[loaded_vmcs])\n\t"
2769 2755
2756 /*
2757 * VMLAUNCH and VMRESUME clear RFLAGS.{CF,ZF} on VM-Exit, set
2758 * RFLAGS.CF on VM-Fail Invalid and set RFLAGS.ZF on VM-Fail
2759 * Valid. vmx_vmenter() directly "returns" RFLAGS, and so the
2760 * results of VM-Enter is captured via CC_{SET,OUT} to vm_fail.
2761 */
2770 "call vmx_vmenter\n\t" 2762 "call vmx_vmenter\n\t"
2771 2763
2772 /* Set vmx->fail accordingly */ 2764 CC_SET(be)
2773 "setbe %c[fail](%% " _ASM_CX")\n\t" 2765 : ASM_CALL_CONSTRAINT, CC_OUT(be) (vm_fail)
2774 : ASM_CALL_CONSTRAINT 2766 : [HOST_RSP]"r"((unsigned long)HOST_RSP),
2775 : "c"(vmx), "d"((unsigned long)HOST_RSP), 2767 [loaded_vmcs]"r"(vmx->loaded_vmcs),
2776 [launched]"i"(offsetof(struct vcpu_vmx, __launched)), 2768 [launched]"i"(offsetof(struct loaded_vmcs, launched)),
2777 [fail]"i"(offsetof(struct vcpu_vmx, fail)), 2769 [host_state_rsp]"i"(offsetof(struct loaded_vmcs, host_state.rsp)),
2778 [host_rsp]"i"(offsetof(struct vcpu_vmx, host_rsp)),
2779 [wordsize]"i"(sizeof(ulong)) 2770 [wordsize]"i"(sizeof(ulong))
2780 : "rax", "cc", "memory" 2771 : "cc", "memory"
2781 ); 2772 );
2782 2773
2783 preempt_enable(); 2774 preempt_enable();
@@ -2787,10 +2778,9 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
2787 if (vmx->msr_autoload.guest.nr) 2778 if (vmx->msr_autoload.guest.nr)
2788 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.guest.nr); 2779 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.guest.nr);
2789 2780
2790 if (vmx->fail) { 2781 if (vm_fail) {
2791 WARN_ON_ONCE(vmcs_read32(VM_INSTRUCTION_ERROR) != 2782 WARN_ON_ONCE(vmcs_read32(VM_INSTRUCTION_ERROR) !=
2792 VMXERR_ENTRY_INVALID_CONTROL_FIELD); 2783 VMXERR_ENTRY_INVALID_CONTROL_FIELD);
2793 vmx->fail = 0;
2794 return 1; 2784 return 1;
2795 } 2785 }
2796 2786
@@ -2813,8 +2803,6 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
2813 2803
2814 return 0; 2804 return 0;
2815} 2805}
2816STACK_FRAME_NON_STANDARD(nested_vmx_check_vmentry_hw);
2817
2818 2806
2819static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu, 2807static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
2820 struct vmcs12 *vmcs12); 2808 struct vmcs12 *vmcs12);
@@ -3031,6 +3019,15 @@ int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
3031 kvm_make_request(KVM_REQ_EVENT, vcpu); 3019 kvm_make_request(KVM_REQ_EVENT, vcpu);
3032 3020
3033 /* 3021 /*
3022 * Do not start the preemption timer hrtimer until after we know
3023 * we are successful, so that only nested_vmx_vmexit needs to cancel
3024 * the timer.
3025 */
3026 vmx->nested.preemption_timer_expired = false;
3027 if (nested_cpu_has_preemption_timer(vmcs12))
3028 vmx_start_preemption_timer(vcpu);
3029
3030 /*
3034 * Note no nested_vmx_succeed or nested_vmx_fail here. At this point 3031 * Note no nested_vmx_succeed or nested_vmx_fail here. At this point
3035 * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet 3032 * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet
3036 * returned as far as L1 is concerned. It will only return (and set 3033 * returned as far as L1 is concerned. It will only return (and set
@@ -3450,13 +3447,10 @@ static void sync_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
3450 else 3447 else
3451 vmcs12->guest_activity_state = GUEST_ACTIVITY_ACTIVE; 3448 vmcs12->guest_activity_state = GUEST_ACTIVITY_ACTIVE;
3452 3449
3453 if (nested_cpu_has_preemption_timer(vmcs12)) { 3450 if (nested_cpu_has_preemption_timer(vmcs12) &&
3454 if (vmcs12->vm_exit_controls & 3451 vmcs12->vm_exit_controls & VM_EXIT_SAVE_VMX_PREEMPTION_TIMER)
3455 VM_EXIT_SAVE_VMX_PREEMPTION_TIMER)
3456 vmcs12->vmx_preemption_timer_value = 3452 vmcs12->vmx_preemption_timer_value =
3457 vmx_get_preemption_timer_value(vcpu); 3453 vmx_get_preemption_timer_value(vcpu);
3458 hrtimer_cancel(&to_vmx(vcpu)->nested.preemption_timer);
3459 }
3460 3454
3461 /* 3455 /*
3462 * In some cases (usually, nested EPT), L2 is allowed to change its 3456 * In some cases (usually, nested EPT), L2 is allowed to change its
@@ -3864,6 +3858,9 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
3864 3858
3865 leave_guest_mode(vcpu); 3859 leave_guest_mode(vcpu);
3866 3860
3861 if (nested_cpu_has_preemption_timer(vmcs12))
3862 hrtimer_cancel(&to_vmx(vcpu)->nested.preemption_timer);
3863
3867 if (vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_TSC_OFFSETING) 3864 if (vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_TSC_OFFSETING)
3868 vcpu->arch.tsc_offset -= vmcs12->tsc_offset; 3865 vcpu->arch.tsc_offset -= vmcs12->tsc_offset;
3869 3866
@@ -3915,9 +3912,6 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
3915 vmx_flush_tlb(vcpu, true); 3912 vmx_flush_tlb(vcpu, true);
3916 } 3913 }
3917 3914
3918 /* This is needed for same reason as it was needed in prepare_vmcs02 */
3919 vmx->host_rsp = 0;
3920
3921 /* Unpin physical memory we referred to in vmcs02 */ 3915 /* Unpin physical memory we referred to in vmcs02 */
3922 if (vmx->nested.apic_access_page) { 3916 if (vmx->nested.apic_access_page) {
3923 kvm_release_page_dirty(vmx->nested.apic_access_page); 3917 kvm_release_page_dirty(vmx->nested.apic_access_page);
@@ -4035,25 +4029,50 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
4035 /* Addr = segment_base + offset */ 4029 /* Addr = segment_base + offset */
4036 /* offset = base + [index * scale] + displacement */ 4030 /* offset = base + [index * scale] + displacement */
4037 off = exit_qualification; /* holds the displacement */ 4031 off = exit_qualification; /* holds the displacement */
4032 if (addr_size == 1)
4033 off = (gva_t)sign_extend64(off, 31);
4034 else if (addr_size == 0)
4035 off = (gva_t)sign_extend64(off, 15);
4038 if (base_is_valid) 4036 if (base_is_valid)
4039 off += kvm_register_read(vcpu, base_reg); 4037 off += kvm_register_read(vcpu, base_reg);
4040 if (index_is_valid) 4038 if (index_is_valid)
4041 off += kvm_register_read(vcpu, index_reg)<<scaling; 4039 off += kvm_register_read(vcpu, index_reg)<<scaling;
4042 vmx_get_segment(vcpu, &s, seg_reg); 4040 vmx_get_segment(vcpu, &s, seg_reg);
4043 *ret = s.base + off;
4044 4041
4042 /*
4043 * The effective address, i.e. @off, of a memory operand is truncated
4044 * based on the address size of the instruction. Note that this is
4045 * the *effective address*, i.e. the address prior to accounting for
4046 * the segment's base.
4047 */
4045 if (addr_size == 1) /* 32 bit */ 4048 if (addr_size == 1) /* 32 bit */
4046 *ret &= 0xffffffff; 4049 off &= 0xffffffff;
4050 else if (addr_size == 0) /* 16 bit */
4051 off &= 0xffff;
4047 4052
4048 /* Checks for #GP/#SS exceptions. */ 4053 /* Checks for #GP/#SS exceptions. */
4049 exn = false; 4054 exn = false;
4050 if (is_long_mode(vcpu)) { 4055 if (is_long_mode(vcpu)) {
4056 /*
4057 * The virtual/linear address is never truncated in 64-bit
4058 * mode, e.g. a 32-bit address size can yield a 64-bit virtual
4059 * address when using FS/GS with a non-zero base.
4060 */
4061 *ret = s.base + off;
4062
4051 /* Long mode: #GP(0)/#SS(0) if the memory address is in a 4063 /* Long mode: #GP(0)/#SS(0) if the memory address is in a
4052 * non-canonical form. This is the only check on the memory 4064 * non-canonical form. This is the only check on the memory
4053 * destination for long mode! 4065 * destination for long mode!
4054 */ 4066 */
4055 exn = is_noncanonical_address(*ret, vcpu); 4067 exn = is_noncanonical_address(*ret, vcpu);
4056 } else if (is_protmode(vcpu)) { 4068 } else {
4069 /*
4070 * When not in long mode, the virtual/linear address is
4071 * unconditionally truncated to 32 bits regardless of the
4072 * address size.
4073 */
4074 *ret = (s.base + off) & 0xffffffff;
4075
4057 /* Protected mode: apply checks for segment validity in the 4076 /* Protected mode: apply checks for segment validity in the
4058 * following order: 4077 * following order:
4059 * - segment type check (#GP(0) may be thrown) 4078 * - segment type check (#GP(0) may be thrown)
@@ -4077,10 +4096,16 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
4077 /* Protected mode: #GP(0)/#SS(0) if the segment is unusable. 4096 /* Protected mode: #GP(0)/#SS(0) if the segment is unusable.
4078 */ 4097 */
4079 exn = (s.unusable != 0); 4098 exn = (s.unusable != 0);
4080 /* Protected mode: #GP(0)/#SS(0) if the memory 4099
4081 * operand is outside the segment limit. 4100 /*
4101 * Protected mode: #GP(0)/#SS(0) if the memory operand is
4102 * outside the segment limit. All CPUs that support VMX ignore
4103 * limit checks for flat segments, i.e. segments with base==0,
4104 * limit==0xffffffff and of type expand-up data or code.
4082 */ 4105 */
4083 exn = exn || (off + sizeof(u64) > s.limit); 4106 if (!(s.base == 0 && s.limit == 0xffffffff &&
4107 ((s.type & 8) || !(s.type & 4))))
4108 exn = exn || (off + sizeof(u64) > s.limit);
4084 } 4109 }
4085 if (exn) { 4110 if (exn) {
4086 kvm_queue_exception_e(vcpu, 4111 kvm_queue_exception_e(vcpu,
@@ -4145,11 +4170,11 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu)
4145 if (r < 0) 4170 if (r < 0)
4146 goto out_vmcs02; 4171 goto out_vmcs02;
4147 4172
4148 vmx->nested.cached_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL); 4173 vmx->nested.cached_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL_ACCOUNT);
4149 if (!vmx->nested.cached_vmcs12) 4174 if (!vmx->nested.cached_vmcs12)
4150 goto out_cached_vmcs12; 4175 goto out_cached_vmcs12;
4151 4176
4152 vmx->nested.cached_shadow_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL); 4177 vmx->nested.cached_shadow_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL_ACCOUNT);
4153 if (!vmx->nested.cached_shadow_vmcs12) 4178 if (!vmx->nested.cached_shadow_vmcs12)
4154 goto out_cached_shadow_vmcs12; 4179 goto out_cached_shadow_vmcs12;
4155 4180
@@ -5696,6 +5721,10 @@ __init int nested_vmx_hardware_setup(int (*exit_handlers[])(struct kvm_vcpu *))
5696 enable_shadow_vmcs = 0; 5721 enable_shadow_vmcs = 0;
5697 if (enable_shadow_vmcs) { 5722 if (enable_shadow_vmcs) {
5698 for (i = 0; i < VMX_BITMAP_NR; i++) { 5723 for (i = 0; i < VMX_BITMAP_NR; i++) {
5724 /*
5725 * The vmx_bitmap is not tied to a VM and so should
5726 * not be charged to a memcg.
5727 */
5699 vmx_bitmap[i] = (unsigned long *) 5728 vmx_bitmap[i] = (unsigned long *)
5700 __get_free_page(GFP_KERNEL); 5729 __get_free_page(GFP_KERNEL);
5701 if (!vmx_bitmap[i]) { 5730 if (!vmx_bitmap[i]) {
diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
index 6def3ba88e3b..cb6079f8a227 100644
--- a/arch/x86/kvm/vmx/vmcs.h
+++ b/arch/x86/kvm/vmx/vmcs.h
@@ -34,6 +34,7 @@ struct vmcs_host_state {
34 unsigned long cr4; /* May not match real cr4 */ 34 unsigned long cr4; /* May not match real cr4 */
35 unsigned long gs_base; 35 unsigned long gs_base;
36 unsigned long fs_base; 36 unsigned long fs_base;
37 unsigned long rsp;
37 38
38 u16 fs_sel, gs_sel, ldt_sel; 39 u16 fs_sel, gs_sel, ldt_sel;
39#ifdef CONFIG_X86_64 40#ifdef CONFIG_X86_64
diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S
index bcef2c7e9bc4..7b272738c576 100644
--- a/arch/x86/kvm/vmx/vmenter.S
+++ b/arch/x86/kvm/vmx/vmenter.S
@@ -1,6 +1,30 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/linkage.h> 2#include <linux/linkage.h>
3#include <asm/asm.h> 3#include <asm/asm.h>
4#include <asm/bitsperlong.h>
5#include <asm/kvm_vcpu_regs.h>
6
7#define WORD_SIZE (BITS_PER_LONG / 8)
8
9#define VCPU_RAX __VCPU_REGS_RAX * WORD_SIZE
10#define VCPU_RCX __VCPU_REGS_RCX * WORD_SIZE
11#define VCPU_RDX __VCPU_REGS_RDX * WORD_SIZE
12#define VCPU_RBX __VCPU_REGS_RBX * WORD_SIZE
13/* Intentionally omit RSP as it's context switched by hardware */
14#define VCPU_RBP __VCPU_REGS_RBP * WORD_SIZE
15#define VCPU_RSI __VCPU_REGS_RSI * WORD_SIZE
16#define VCPU_RDI __VCPU_REGS_RDI * WORD_SIZE
17
18#ifdef CONFIG_X86_64
19#define VCPU_R8 __VCPU_REGS_R8 * WORD_SIZE
20#define VCPU_R9 __VCPU_REGS_R9 * WORD_SIZE
21#define VCPU_R10 __VCPU_REGS_R10 * WORD_SIZE
22#define VCPU_R11 __VCPU_REGS_R11 * WORD_SIZE
23#define VCPU_R12 __VCPU_REGS_R12 * WORD_SIZE
24#define VCPU_R13 __VCPU_REGS_R13 * WORD_SIZE
25#define VCPU_R14 __VCPU_REGS_R14 * WORD_SIZE
26#define VCPU_R15 __VCPU_REGS_R15 * WORD_SIZE
27#endif
4 28
5 .text 29 .text
6 30
@@ -55,3 +79,146 @@ ENDPROC(vmx_vmenter)
55ENTRY(vmx_vmexit) 79ENTRY(vmx_vmexit)
56 ret 80 ret
57ENDPROC(vmx_vmexit) 81ENDPROC(vmx_vmexit)
82
83/**
84 * __vmx_vcpu_run - Run a vCPU via a transition to VMX guest mode
85 * @vmx: struct vcpu_vmx *
86 * @regs: unsigned long * (to guest registers)
87 * @launched: %true if the VMCS has been launched
88 *
89 * Returns:
90 * 0 on VM-Exit, 1 on VM-Fail
91 */
92ENTRY(__vmx_vcpu_run)
93 push %_ASM_BP
94 mov %_ASM_SP, %_ASM_BP
95#ifdef CONFIG_X86_64
96 push %r15
97 push %r14
98 push %r13
99 push %r12
100#else
101 push %edi
102 push %esi
103#endif
104 push %_ASM_BX
105
106 /*
107 * Save @regs, _ASM_ARG2 may be modified by vmx_update_host_rsp() and
108 * @regs is needed after VM-Exit to save the guest's register values.
109 */
110 push %_ASM_ARG2
111
112 /* Copy @launched to BL, _ASM_ARG3 is volatile. */
113 mov %_ASM_ARG3B, %bl
114
115 /* Adjust RSP to account for the CALL to vmx_vmenter(). */
116 lea -WORD_SIZE(%_ASM_SP), %_ASM_ARG2
117 call vmx_update_host_rsp
118
119 /* Load @regs to RAX. */
120 mov (%_ASM_SP), %_ASM_AX
121
122 /* Check if vmlaunch or vmresume is needed */
123 cmpb $0, %bl
124
125 /* Load guest registers. Don't clobber flags. */
126 mov VCPU_RBX(%_ASM_AX), %_ASM_BX
127 mov VCPU_RCX(%_ASM_AX), %_ASM_CX
128 mov VCPU_RDX(%_ASM_AX), %_ASM_DX
129 mov VCPU_RSI(%_ASM_AX), %_ASM_SI
130 mov VCPU_RDI(%_ASM_AX), %_ASM_DI
131 mov VCPU_RBP(%_ASM_AX), %_ASM_BP
132#ifdef CONFIG_X86_64
133 mov VCPU_R8 (%_ASM_AX), %r8
134 mov VCPU_R9 (%_ASM_AX), %r9
135 mov VCPU_R10(%_ASM_AX), %r10
136 mov VCPU_R11(%_ASM_AX), %r11
137 mov VCPU_R12(%_ASM_AX), %r12
138 mov VCPU_R13(%_ASM_AX), %r13
139 mov VCPU_R14(%_ASM_AX), %r14
140 mov VCPU_R15(%_ASM_AX), %r15
141#endif
142 /* Load guest RAX. This kills the vmx_vcpu pointer! */
143 mov VCPU_RAX(%_ASM_AX), %_ASM_AX
144
145 /* Enter guest mode */
146 call vmx_vmenter
147
148 /* Jump on VM-Fail. */
149 jbe 2f
150
151 /* Temporarily save guest's RAX. */
152 push %_ASM_AX
153
154 /* Reload @regs to RAX. */
155 mov WORD_SIZE(%_ASM_SP), %_ASM_AX
156
157 /* Save all guest registers, including RAX from the stack */
158 __ASM_SIZE(pop) VCPU_RAX(%_ASM_AX)
159 mov %_ASM_BX, VCPU_RBX(%_ASM_AX)
160 mov %_ASM_CX, VCPU_RCX(%_ASM_AX)
161 mov %_ASM_DX, VCPU_RDX(%_ASM_AX)
162 mov %_ASM_SI, VCPU_RSI(%_ASM_AX)
163 mov %_ASM_DI, VCPU_RDI(%_ASM_AX)
164 mov %_ASM_BP, VCPU_RBP(%_ASM_AX)
165#ifdef CONFIG_X86_64
166 mov %r8, VCPU_R8 (%_ASM_AX)
167 mov %r9, VCPU_R9 (%_ASM_AX)
168 mov %r10, VCPU_R10(%_ASM_AX)
169 mov %r11, VCPU_R11(%_ASM_AX)
170 mov %r12, VCPU_R12(%_ASM_AX)
171 mov %r13, VCPU_R13(%_ASM_AX)
172 mov %r14, VCPU_R14(%_ASM_AX)
173 mov %r15, VCPU_R15(%_ASM_AX)
174#endif
175
176 /* Clear RAX to indicate VM-Exit (as opposed to VM-Fail). */
177 xor %eax, %eax
178
179 /*
180 * Clear all general purpose registers except RSP and RAX to prevent
181 * speculative use of the guest's values, even those that are reloaded
182 * via the stack. In theory, an L1 cache miss when restoring registers
183 * could lead to speculative execution with the guest's values.
184 * Zeroing XORs are dirt cheap, i.e. the extra paranoia is essentially
185 * free. RSP and RAX are exempt as RSP is restored by hardware during
186 * VM-Exit and RAX is explicitly loaded with 0 or 1 to return VM-Fail.
187 */
1881: xor %ebx, %ebx
189 xor %ecx, %ecx
190 xor %edx, %edx
191 xor %esi, %esi
192 xor %edi, %edi
193 xor %ebp, %ebp
194#ifdef CONFIG_X86_64
195 xor %r8d, %r8d
196 xor %r9d, %r9d
197 xor %r10d, %r10d
198 xor %r11d, %r11d
199 xor %r12d, %r12d
200 xor %r13d, %r13d
201 xor %r14d, %r14d
202 xor %r15d, %r15d
203#endif
204
205 /* "POP" @regs. */
206 add $WORD_SIZE, %_ASM_SP
207 pop %_ASM_BX
208
209#ifdef CONFIG_X86_64
210 pop %r12
211 pop %r13
212 pop %r14
213 pop %r15
214#else
215 pop %esi
216 pop %edi
217#endif
218 pop %_ASM_BP
219 ret
220
221 /* VM-Fail. Out-of-line to avoid a taken Jcc after VM-Exit. */
2222: mov $1, %eax
223 jmp 1b
224ENDPROC(__vmx_vcpu_run)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 30a6bcd735ec..c73375e01ab8 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -246,6 +246,10 @@ static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf)
246 246
247 if (l1tf != VMENTER_L1D_FLUSH_NEVER && !vmx_l1d_flush_pages && 247 if (l1tf != VMENTER_L1D_FLUSH_NEVER && !vmx_l1d_flush_pages &&
248 !boot_cpu_has(X86_FEATURE_FLUSH_L1D)) { 248 !boot_cpu_has(X86_FEATURE_FLUSH_L1D)) {
249 /*
250 * This allocation for vmx_l1d_flush_pages is not tied to a VM
251 * lifetime and so should not be charged to a memcg.
252 */
249 page = alloc_pages(GFP_KERNEL, L1D_CACHE_ORDER); 253 page = alloc_pages(GFP_KERNEL, L1D_CACHE_ORDER);
250 if (!page) 254 if (!page)
251 return -ENOMEM; 255 return -ENOMEM;
@@ -2387,13 +2391,13 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,
2387 return 0; 2391 return 0;
2388} 2392}
2389 2393
2390struct vmcs *alloc_vmcs_cpu(bool shadow, int cpu) 2394struct vmcs *alloc_vmcs_cpu(bool shadow, int cpu, gfp_t flags)
2391{ 2395{
2392 int node = cpu_to_node(cpu); 2396 int node = cpu_to_node(cpu);
2393 struct page *pages; 2397 struct page *pages;
2394 struct vmcs *vmcs; 2398 struct vmcs *vmcs;
2395 2399
2396 pages = __alloc_pages_node(node, GFP_KERNEL, vmcs_config.order); 2400 pages = __alloc_pages_node(node, flags, vmcs_config.order);
2397 if (!pages) 2401 if (!pages)
2398 return NULL; 2402 return NULL;
2399 vmcs = page_address(pages); 2403 vmcs = page_address(pages);
@@ -2440,7 +2444,8 @@ int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs)
2440 loaded_vmcs_init(loaded_vmcs); 2444 loaded_vmcs_init(loaded_vmcs);
2441 2445
2442 if (cpu_has_vmx_msr_bitmap()) { 2446 if (cpu_has_vmx_msr_bitmap()) {
2443 loaded_vmcs->msr_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL); 2447 loaded_vmcs->msr_bitmap = (unsigned long *)
2448 __get_free_page(GFP_KERNEL_ACCOUNT);
2444 if (!loaded_vmcs->msr_bitmap) 2449 if (!loaded_vmcs->msr_bitmap)
2445 goto out_vmcs; 2450 goto out_vmcs;
2446 memset(loaded_vmcs->msr_bitmap, 0xff, PAGE_SIZE); 2451 memset(loaded_vmcs->msr_bitmap, 0xff, PAGE_SIZE);
@@ -2481,7 +2486,7 @@ static __init int alloc_kvm_area(void)
2481 for_each_possible_cpu(cpu) { 2486 for_each_possible_cpu(cpu) {
2482 struct vmcs *vmcs; 2487 struct vmcs *vmcs;
2483 2488
2484 vmcs = alloc_vmcs_cpu(false, cpu); 2489 vmcs = alloc_vmcs_cpu(false, cpu, GFP_KERNEL);
2485 if (!vmcs) { 2490 if (!vmcs) {
2486 free_kvm_area(); 2491 free_kvm_area();
2487 return -ENOMEM; 2492 return -ENOMEM;
@@ -6360,150 +6365,15 @@ static void vmx_update_hv_timer(struct kvm_vcpu *vcpu)
6360 vmx->loaded_vmcs->hv_timer_armed = false; 6365 vmx->loaded_vmcs->hv_timer_armed = false;
6361} 6366}
6362 6367
6363static void __vmx_vcpu_run(struct kvm_vcpu *vcpu, struct vcpu_vmx *vmx) 6368void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp)
6364{ 6369{
6365 unsigned long evmcs_rsp; 6370 if (unlikely(host_rsp != vmx->loaded_vmcs->host_state.rsp)) {
6366 6371 vmx->loaded_vmcs->host_state.rsp = host_rsp;
6367 vmx->__launched = vmx->loaded_vmcs->launched; 6372 vmcs_writel(HOST_RSP, host_rsp);
6368 6373 }
6369 evmcs_rsp = static_branch_unlikely(&enable_evmcs) ?
6370 (unsigned long)&current_evmcs->host_rsp : 0;
6371
6372 if (static_branch_unlikely(&vmx_l1d_should_flush))
6373 vmx_l1d_flush(vcpu);
6374
6375 asm(
6376 /* Store host registers */
6377 "push %%" _ASM_DX "; push %%" _ASM_BP ";"
6378 "push %%" _ASM_CX " \n\t" /* placeholder for guest rcx */
6379 "push %%" _ASM_CX " \n\t"
6380 "sub $%c[wordsize], %%" _ASM_SP "\n\t" /* temporarily adjust RSP for CALL */
6381 "cmp %%" _ASM_SP ", %c[host_rsp](%%" _ASM_CX ") \n\t"
6382 "je 1f \n\t"
6383 "mov %%" _ASM_SP ", %c[host_rsp](%%" _ASM_CX ") \n\t"
6384 /* Avoid VMWRITE when Enlightened VMCS is in use */
6385 "test %%" _ASM_SI ", %%" _ASM_SI " \n\t"
6386 "jz 2f \n\t"
6387 "mov %%" _ASM_SP ", (%%" _ASM_SI ") \n\t"
6388 "jmp 1f \n\t"
6389 "2: \n\t"
6390 __ex("vmwrite %%" _ASM_SP ", %%" _ASM_DX) "\n\t"
6391 "1: \n\t"
6392 "add $%c[wordsize], %%" _ASM_SP "\n\t" /* un-adjust RSP */
6393
6394 /* Reload cr2 if changed */
6395 "mov %c[cr2](%%" _ASM_CX "), %%" _ASM_AX " \n\t"
6396 "mov %%cr2, %%" _ASM_DX " \n\t"
6397 "cmp %%" _ASM_AX ", %%" _ASM_DX " \n\t"
6398 "je 3f \n\t"
6399 "mov %%" _ASM_AX", %%cr2 \n\t"
6400 "3: \n\t"
6401 /* Check if vmlaunch or vmresume is needed */
6402 "cmpl $0, %c[launched](%%" _ASM_CX ") \n\t"
6403 /* Load guest registers. Don't clobber flags. */
6404 "mov %c[rax](%%" _ASM_CX "), %%" _ASM_AX " \n\t"
6405 "mov %c[rbx](%%" _ASM_CX "), %%" _ASM_BX " \n\t"
6406 "mov %c[rdx](%%" _ASM_CX "), %%" _ASM_DX " \n\t"
6407 "mov %c[rsi](%%" _ASM_CX "), %%" _ASM_SI " \n\t"
6408 "mov %c[rdi](%%" _ASM_CX "), %%" _ASM_DI " \n\t"
6409 "mov %c[rbp](%%" _ASM_CX "), %%" _ASM_BP " \n\t"
6410#ifdef CONFIG_X86_64
6411 "mov %c[r8](%%" _ASM_CX "), %%r8 \n\t"
6412 "mov %c[r9](%%" _ASM_CX "), %%r9 \n\t"
6413 "mov %c[r10](%%" _ASM_CX "), %%r10 \n\t"
6414 "mov %c[r11](%%" _ASM_CX "), %%r11 \n\t"
6415 "mov %c[r12](%%" _ASM_CX "), %%r12 \n\t"
6416 "mov %c[r13](%%" _ASM_CX "), %%r13 \n\t"
6417 "mov %c[r14](%%" _ASM_CX "), %%r14 \n\t"
6418 "mov %c[r15](%%" _ASM_CX "), %%r15 \n\t"
6419#endif
6420 /* Load guest RCX. This kills the vmx_vcpu pointer! */
6421 "mov %c[rcx](%%" _ASM_CX "), %%" _ASM_CX " \n\t"
6422
6423 /* Enter guest mode */
6424 "call vmx_vmenter\n\t"
6425
6426 /* Save guest's RCX to the stack placeholder (see above) */
6427 "mov %%" _ASM_CX ", %c[wordsize](%%" _ASM_SP ") \n\t"
6428
6429 /* Load host's RCX, i.e. the vmx_vcpu pointer */
6430 "pop %%" _ASM_CX " \n\t"
6431
6432 /* Set vmx->fail based on EFLAGS.{CF,ZF} */
6433 "setbe %c[fail](%%" _ASM_CX ")\n\t"
6434
6435 /* Save all guest registers, including RCX from the stack */
6436 "mov %%" _ASM_AX ", %c[rax](%%" _ASM_CX ") \n\t"
6437 "mov %%" _ASM_BX ", %c[rbx](%%" _ASM_CX ") \n\t"
6438 __ASM_SIZE(pop) " %c[rcx](%%" _ASM_CX ") \n\t"
6439 "mov %%" _ASM_DX ", %c[rdx](%%" _ASM_CX ") \n\t"
6440 "mov %%" _ASM_SI ", %c[rsi](%%" _ASM_CX ") \n\t"
6441 "mov %%" _ASM_DI ", %c[rdi](%%" _ASM_CX ") \n\t"
6442 "mov %%" _ASM_BP ", %c[rbp](%%" _ASM_CX ") \n\t"
6443#ifdef CONFIG_X86_64
6444 "mov %%r8, %c[r8](%%" _ASM_CX ") \n\t"
6445 "mov %%r9, %c[r9](%%" _ASM_CX ") \n\t"
6446 "mov %%r10, %c[r10](%%" _ASM_CX ") \n\t"
6447 "mov %%r11, %c[r11](%%" _ASM_CX ") \n\t"
6448 "mov %%r12, %c[r12](%%" _ASM_CX ") \n\t"
6449 "mov %%r13, %c[r13](%%" _ASM_CX ") \n\t"
6450 "mov %%r14, %c[r14](%%" _ASM_CX ") \n\t"
6451 "mov %%r15, %c[r15](%%" _ASM_CX ") \n\t"
6452 /*
6453 * Clear host registers marked as clobbered to prevent
6454 * speculative use.
6455 */
6456 "xor %%r8d, %%r8d \n\t"
6457 "xor %%r9d, %%r9d \n\t"
6458 "xor %%r10d, %%r10d \n\t"
6459 "xor %%r11d, %%r11d \n\t"
6460 "xor %%r12d, %%r12d \n\t"
6461 "xor %%r13d, %%r13d \n\t"
6462 "xor %%r14d, %%r14d \n\t"
6463 "xor %%r15d, %%r15d \n\t"
6464#endif
6465 "mov %%cr2, %%" _ASM_AX " \n\t"
6466 "mov %%" _ASM_AX ", %c[cr2](%%" _ASM_CX ") \n\t"
6467
6468 "xor %%eax, %%eax \n\t"
6469 "xor %%ebx, %%ebx \n\t"
6470 "xor %%esi, %%esi \n\t"
6471 "xor %%edi, %%edi \n\t"
6472 "pop %%" _ASM_BP "; pop %%" _ASM_DX " \n\t"
6473 : ASM_CALL_CONSTRAINT
6474 : "c"(vmx), "d"((unsigned long)HOST_RSP), "S"(evmcs_rsp),
6475 [launched]"i"(offsetof(struct vcpu_vmx, __launched)),
6476 [fail]"i"(offsetof(struct vcpu_vmx, fail)),
6477 [host_rsp]"i"(offsetof(struct vcpu_vmx, host_rsp)),
6478 [rax]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RAX])),
6479 [rbx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RBX])),
6480 [rcx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RCX])),
6481 [rdx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RDX])),
6482 [rsi]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RSI])),
6483 [rdi]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RDI])),
6484 [rbp]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RBP])),
6485#ifdef CONFIG_X86_64
6486 [r8]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R8])),
6487 [r9]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R9])),
6488 [r10]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R10])),
6489 [r11]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R11])),
6490 [r12]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R12])),
6491 [r13]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R13])),
6492 [r14]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R14])),
6493 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
6494#endif
6495 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
6496 [wordsize]"i"(sizeof(ulong))
6497 : "cc", "memory"
6498#ifdef CONFIG_X86_64
6499 , "rax", "rbx", "rdi"
6500 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
6501#else
6502 , "eax", "ebx", "edi"
6503#endif
6504 );
6505} 6374}
6506STACK_FRAME_NON_STANDARD(__vmx_vcpu_run); 6375
6376bool __vmx_vcpu_run(struct vcpu_vmx *vmx, unsigned long *regs, bool launched);
6507 6377
6508static void vmx_vcpu_run(struct kvm_vcpu *vcpu) 6378static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
6509{ 6379{
@@ -6572,7 +6442,16 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
6572 */ 6442 */
6573 x86_spec_ctrl_set_guest(vmx->spec_ctrl, 0); 6443 x86_spec_ctrl_set_guest(vmx->spec_ctrl, 0);
6574 6444
6575 __vmx_vcpu_run(vcpu, vmx); 6445 if (static_branch_unlikely(&vmx_l1d_should_flush))
6446 vmx_l1d_flush(vcpu);
6447
6448 if (vcpu->arch.cr2 != read_cr2())
6449 write_cr2(vcpu->arch.cr2);
6450
6451 vmx->fail = __vmx_vcpu_run(vmx, (unsigned long *)&vcpu->arch.regs,
6452 vmx->loaded_vmcs->launched);
6453
6454 vcpu->arch.cr2 = read_cr2();
6576 6455
6577 /* 6456 /*
6578 * We do not use IBRS in the kernel. If this vCPU has used the 6457 * We do not use IBRS in the kernel. If this vCPU has used the
@@ -6657,7 +6536,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
6657 6536
6658static struct kvm *vmx_vm_alloc(void) 6537static struct kvm *vmx_vm_alloc(void)
6659{ 6538{
6660 struct kvm_vmx *kvm_vmx = vzalloc(sizeof(struct kvm_vmx)); 6539 struct kvm_vmx *kvm_vmx = __vmalloc(sizeof(struct kvm_vmx),
6540 GFP_KERNEL_ACCOUNT | __GFP_ZERO,
6541 PAGE_KERNEL);
6661 return &kvm_vmx->kvm; 6542 return &kvm_vmx->kvm;
6662} 6543}
6663 6544
@@ -6673,7 +6554,6 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
6673 if (enable_pml) 6554 if (enable_pml)
6674 vmx_destroy_pml_buffer(vmx); 6555 vmx_destroy_pml_buffer(vmx);
6675 free_vpid(vmx->vpid); 6556 free_vpid(vmx->vpid);
6676 leave_guest_mode(vcpu);
6677 nested_vmx_free_vcpu(vcpu); 6557 nested_vmx_free_vcpu(vcpu);
6678 free_loaded_vmcs(vmx->loaded_vmcs); 6558 free_loaded_vmcs(vmx->loaded_vmcs);
6679 kfree(vmx->guest_msrs); 6559 kfree(vmx->guest_msrs);
@@ -6685,14 +6565,16 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
6685static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) 6565static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
6686{ 6566{
6687 int err; 6567 int err;
6688 struct vcpu_vmx *vmx = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); 6568 struct vcpu_vmx *vmx;
6689 unsigned long *msr_bitmap; 6569 unsigned long *msr_bitmap;
6690 int cpu; 6570 int cpu;
6691 6571
6572 vmx = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL_ACCOUNT);
6692 if (!vmx) 6573 if (!vmx)
6693 return ERR_PTR(-ENOMEM); 6574 return ERR_PTR(-ENOMEM);
6694 6575
6695 vmx->vcpu.arch.guest_fpu = kmem_cache_zalloc(x86_fpu_cache, GFP_KERNEL); 6576 vmx->vcpu.arch.guest_fpu = kmem_cache_zalloc(x86_fpu_cache,
6577 GFP_KERNEL_ACCOUNT);
6696 if (!vmx->vcpu.arch.guest_fpu) { 6578 if (!vmx->vcpu.arch.guest_fpu) {
6697 printk(KERN_ERR "kvm: failed to allocate vcpu's fpu\n"); 6579 printk(KERN_ERR "kvm: failed to allocate vcpu's fpu\n");
6698 err = -ENOMEM; 6580 err = -ENOMEM;
@@ -6714,12 +6596,12 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
6714 * for the guest, etc. 6596 * for the guest, etc.
6715 */ 6597 */
6716 if (enable_pml) { 6598 if (enable_pml) {
6717 vmx->pml_pg = alloc_page(GFP_KERNEL | __GFP_ZERO); 6599 vmx->pml_pg = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
6718 if (!vmx->pml_pg) 6600 if (!vmx->pml_pg)
6719 goto uninit_vcpu; 6601 goto uninit_vcpu;
6720 } 6602 }
6721 6603
6722 vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL); 6604 vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT);
6723 BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx->guest_msrs[0]) 6605 BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx->guest_msrs[0])
6724 > PAGE_SIZE); 6606 > PAGE_SIZE);
6725 6607
diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
index 0ac0a64c7790..1554cb45b393 100644
--- a/arch/x86/kvm/vmx/vmx.h
+++ b/arch/x86/kvm/vmx/vmx.h
@@ -175,7 +175,6 @@ struct nested_vmx {
175 175
176struct vcpu_vmx { 176struct vcpu_vmx {
177 struct kvm_vcpu vcpu; 177 struct kvm_vcpu vcpu;
178 unsigned long host_rsp;
179 u8 fail; 178 u8 fail;
180 u8 msr_bitmap_mode; 179 u8 msr_bitmap_mode;
181 u32 exit_intr_info; 180 u32 exit_intr_info;
@@ -209,7 +208,7 @@ struct vcpu_vmx {
209 struct loaded_vmcs vmcs01; 208 struct loaded_vmcs vmcs01;
210 struct loaded_vmcs *loaded_vmcs; 209 struct loaded_vmcs *loaded_vmcs;
211 struct loaded_vmcs *loaded_cpu_state; 210 struct loaded_vmcs *loaded_cpu_state;
212 bool __launched; /* temporary, used in vmx_vcpu_run */ 211
213 struct msr_autoload { 212 struct msr_autoload {
214 struct vmx_msrs guest; 213 struct vmx_msrs guest;
215 struct vmx_msrs host; 214 struct vmx_msrs host;
@@ -339,8 +338,8 @@ static inline int pi_test_and_set_pir(int vector, struct pi_desc *pi_desc)
339 338
340static inline void pi_set_sn(struct pi_desc *pi_desc) 339static inline void pi_set_sn(struct pi_desc *pi_desc)
341{ 340{
342 return set_bit(POSTED_INTR_SN, 341 set_bit(POSTED_INTR_SN,
343 (unsigned long *)&pi_desc->control); 342 (unsigned long *)&pi_desc->control);
344} 343}
345 344
346static inline void pi_set_on(struct pi_desc *pi_desc) 345static inline void pi_set_on(struct pi_desc *pi_desc)
@@ -445,7 +444,8 @@ static inline u32 vmx_vmentry_ctrl(void)
445{ 444{
446 u32 vmentry_ctrl = vmcs_config.vmentry_ctrl; 445 u32 vmentry_ctrl = vmcs_config.vmentry_ctrl;
447 if (pt_mode == PT_MODE_SYSTEM) 446 if (pt_mode == PT_MODE_SYSTEM)
448 vmentry_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP | VM_EXIT_CLEAR_IA32_RTIT_CTL); 447 vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |
448 VM_ENTRY_LOAD_IA32_RTIT_CTL);
449 /* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */ 449 /* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */
450 return vmentry_ctrl & 450 return vmentry_ctrl &
451 ~(VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | VM_ENTRY_LOAD_IA32_EFER); 451 ~(VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | VM_ENTRY_LOAD_IA32_EFER);
@@ -455,9 +455,10 @@ static inline u32 vmx_vmexit_ctrl(void)
455{ 455{
456 u32 vmexit_ctrl = vmcs_config.vmexit_ctrl; 456 u32 vmexit_ctrl = vmcs_config.vmexit_ctrl;
457 if (pt_mode == PT_MODE_SYSTEM) 457 if (pt_mode == PT_MODE_SYSTEM)
458 vmexit_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP | VM_ENTRY_LOAD_IA32_RTIT_CTL); 458 vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |
459 VM_EXIT_CLEAR_IA32_RTIT_CTL);
459 /* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */ 460 /* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */
460 return vmcs_config.vmexit_ctrl & 461 return vmexit_ctrl &
461 ~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | VM_EXIT_LOAD_IA32_EFER); 462 ~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | VM_EXIT_LOAD_IA32_EFER);
462} 463}
463 464
@@ -478,7 +479,7 @@ static inline struct pi_desc *vcpu_to_pi_desc(struct kvm_vcpu *vcpu)
478 return &(to_vmx(vcpu)->pi_desc); 479 return &(to_vmx(vcpu)->pi_desc);
479} 480}
480 481
481struct vmcs *alloc_vmcs_cpu(bool shadow, int cpu); 482struct vmcs *alloc_vmcs_cpu(bool shadow, int cpu, gfp_t flags);
482void free_vmcs(struct vmcs *vmcs); 483void free_vmcs(struct vmcs *vmcs);
483int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs); 484int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs);
484void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs); 485void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs);
@@ -487,7 +488,8 @@ void loaded_vmcs_clear(struct loaded_vmcs *loaded_vmcs);
487 488
488static inline struct vmcs *alloc_vmcs(bool shadow) 489static inline struct vmcs *alloc_vmcs(bool shadow)
489{ 490{
490 return alloc_vmcs_cpu(shadow, raw_smp_processor_id()); 491 return alloc_vmcs_cpu(shadow, raw_smp_processor_id(),
492 GFP_KERNEL_ACCOUNT);
491} 493}
492 494
493u64 construct_eptp(struct kvm_vcpu *vcpu, unsigned long root_hpa); 495u64 construct_eptp(struct kvm_vcpu *vcpu, unsigned long root_hpa);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 941f932373d0..65e4559eef2f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3879,7 +3879,8 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
3879 r = -EINVAL; 3879 r = -EINVAL;
3880 if (!lapic_in_kernel(vcpu)) 3880 if (!lapic_in_kernel(vcpu))
3881 goto out; 3881 goto out;
3882 u.lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); 3882 u.lapic = kzalloc(sizeof(struct kvm_lapic_state),
3883 GFP_KERNEL_ACCOUNT);
3883 3884
3884 r = -ENOMEM; 3885 r = -ENOMEM;
3885 if (!u.lapic) 3886 if (!u.lapic)
@@ -4066,7 +4067,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
4066 break; 4067 break;
4067 } 4068 }
4068 case KVM_GET_XSAVE: { 4069 case KVM_GET_XSAVE: {
4069 u.xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL); 4070 u.xsave = kzalloc(sizeof(struct kvm_xsave), GFP_KERNEL_ACCOUNT);
4070 r = -ENOMEM; 4071 r = -ENOMEM;
4071 if (!u.xsave) 4072 if (!u.xsave)
4072 break; 4073 break;
@@ -4090,7 +4091,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
4090 break; 4091 break;
4091 } 4092 }
4092 case KVM_GET_XCRS: { 4093 case KVM_GET_XCRS: {
4093 u.xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL); 4094 u.xcrs = kzalloc(sizeof(struct kvm_xcrs), GFP_KERNEL_ACCOUNT);
4094 r = -ENOMEM; 4095 r = -ENOMEM;
4095 if (!u.xcrs) 4096 if (!u.xcrs)
4096 break; 4097 break;
@@ -7055,6 +7056,13 @@ static void kvm_pv_kick_cpu_op(struct kvm *kvm, unsigned long flags, int apicid)
7055 7056
7056void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu) 7057void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu)
7057{ 7058{
7059 if (!lapic_in_kernel(vcpu)) {
7060 WARN_ON_ONCE(vcpu->arch.apicv_active);
7061 return;
7062 }
7063 if (!vcpu->arch.apicv_active)
7064 return;
7065
7058 vcpu->arch.apicv_active = false; 7066 vcpu->arch.apicv_active = false;
7059 kvm_x86_ops->refresh_apicv_exec_ctrl(vcpu); 7067 kvm_x86_ops->refresh_apicv_exec_ctrl(vcpu);
7060} 7068}
@@ -9005,7 +9013,6 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
9005 struct page *page; 9013 struct page *page;
9006 int r; 9014 int r;
9007 9015
9008 vcpu->arch.apicv_active = kvm_x86_ops->get_enable_apicv(vcpu);
9009 vcpu->arch.emulate_ctxt.ops = &emulate_ops; 9016 vcpu->arch.emulate_ctxt.ops = &emulate_ops;
9010 if (!irqchip_in_kernel(vcpu->kvm) || kvm_vcpu_is_reset_bsp(vcpu)) 9017 if (!irqchip_in_kernel(vcpu->kvm) || kvm_vcpu_is_reset_bsp(vcpu))
9011 vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; 9018 vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
@@ -9026,6 +9033,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
9026 goto fail_free_pio_data; 9033 goto fail_free_pio_data;
9027 9034
9028 if (irqchip_in_kernel(vcpu->kvm)) { 9035 if (irqchip_in_kernel(vcpu->kvm)) {
9036 vcpu->arch.apicv_active = kvm_x86_ops->get_enable_apicv(vcpu);
9029 r = kvm_create_lapic(vcpu); 9037 r = kvm_create_lapic(vcpu);
9030 if (r < 0) 9038 if (r < 0)
9031 goto fail_mmu_destroy; 9039 goto fail_mmu_destroy;
@@ -9033,14 +9041,15 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
9033 static_key_slow_inc(&kvm_no_apic_vcpu); 9041 static_key_slow_inc(&kvm_no_apic_vcpu);
9034 9042
9035 vcpu->arch.mce_banks = kzalloc(KVM_MAX_MCE_BANKS * sizeof(u64) * 4, 9043 vcpu->arch.mce_banks = kzalloc(KVM_MAX_MCE_BANKS * sizeof(u64) * 4,
9036 GFP_KERNEL); 9044 GFP_KERNEL_ACCOUNT);
9037 if (!vcpu->arch.mce_banks) { 9045 if (!vcpu->arch.mce_banks) {
9038 r = -ENOMEM; 9046 r = -ENOMEM;
9039 goto fail_free_lapic; 9047 goto fail_free_lapic;
9040 } 9048 }
9041 vcpu->arch.mcg_cap = KVM_MAX_MCE_BANKS; 9049 vcpu->arch.mcg_cap = KVM_MAX_MCE_BANKS;
9042 9050
9043 if (!zalloc_cpumask_var(&vcpu->arch.wbinvd_dirty_mask, GFP_KERNEL)) { 9051 if (!zalloc_cpumask_var(&vcpu->arch.wbinvd_dirty_mask,
9052 GFP_KERNEL_ACCOUNT)) {
9044 r = -ENOMEM; 9053 r = -ENOMEM;
9045 goto fail_free_mce_banks; 9054 goto fail_free_mce_banks;
9046 } 9055 }
@@ -9104,7 +9113,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
9104 9113
9105 INIT_HLIST_HEAD(&kvm->arch.mask_notifier_list); 9114 INIT_HLIST_HEAD(&kvm->arch.mask_notifier_list);
9106 INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); 9115 INIT_LIST_HEAD(&kvm->arch.active_mmu_pages);
9107 INIT_LIST_HEAD(&kvm->arch.zapped_obsolete_pages);
9108 INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); 9116 INIT_LIST_HEAD(&kvm->arch.assigned_dev_head);
9109 atomic_set(&kvm->arch.noncoherent_dma_count, 0); 9117 atomic_set(&kvm->arch.noncoherent_dma_count, 0);
9110 9118
@@ -9299,13 +9307,13 @@ int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot,
9299 9307
9300 slot->arch.rmap[i] = 9308 slot->arch.rmap[i] =
9301 kvcalloc(lpages, sizeof(*slot->arch.rmap[i]), 9309 kvcalloc(lpages, sizeof(*slot->arch.rmap[i]),
9302 GFP_KERNEL); 9310 GFP_KERNEL_ACCOUNT);
9303 if (!slot->arch.rmap[i]) 9311 if (!slot->arch.rmap[i])
9304 goto out_free; 9312 goto out_free;
9305 if (i == 0) 9313 if (i == 0)
9306 continue; 9314 continue;
9307 9315
9308 linfo = kvcalloc(lpages, sizeof(*linfo), GFP_KERNEL); 9316 linfo = kvcalloc(lpages, sizeof(*linfo), GFP_KERNEL_ACCOUNT);
9309 if (!linfo) 9317 if (!linfo)
9310 goto out_free; 9318 goto out_free;
9311 9319
@@ -9348,13 +9356,13 @@ out_free:
9348 return -ENOMEM; 9356 return -ENOMEM;
9349} 9357}
9350 9358
9351void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) 9359void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen)
9352{ 9360{
9353 /* 9361 /*
9354 * memslots->generation has been incremented. 9362 * memslots->generation has been incremented.
9355 * mmio generation may have reached its maximum value. 9363 * mmio generation may have reached its maximum value.
9356 */ 9364 */
9357 kvm_mmu_invalidate_mmio_sptes(kvm, slots); 9365 kvm_mmu_invalidate_mmio_sptes(kvm, gen);
9358} 9366}
9359 9367
9360int kvm_arch_prepare_memory_region(struct kvm *kvm, 9368int kvm_arch_prepare_memory_region(struct kvm *kvm,
@@ -9462,7 +9470,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
9462 9470
9463void kvm_arch_flush_shadow_all(struct kvm *kvm) 9471void kvm_arch_flush_shadow_all(struct kvm *kvm)
9464{ 9472{
9465 kvm_mmu_invalidate_zap_all_pages(kvm); 9473 kvm_mmu_zap_all(kvm);
9466} 9474}
9467 9475
9468void kvm_arch_flush_shadow_memslot(struct kvm *kvm, 9476void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 224cd0a47568..28406aa1136d 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -181,6 +181,11 @@ static inline bool emul_is_noncanonical_address(u64 la,
181static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu, 181static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
182 gva_t gva, gfn_t gfn, unsigned access) 182 gva_t gva, gfn_t gfn, unsigned access)
183{ 183{
184 u64 gen = kvm_memslots(vcpu->kvm)->generation;
185
186 if (unlikely(gen & KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS))
187 return;
188
184 /* 189 /*
185 * If this is a shadow nested page table, the "GVA" is 190 * If this is a shadow nested page table, the "GVA" is
186 * actually a nGPA. 191 * actually a nGPA.
@@ -188,7 +193,7 @@ static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
188 vcpu->arch.mmio_gva = mmu_is_nested(vcpu) ? 0 : gva & PAGE_MASK; 193 vcpu->arch.mmio_gva = mmu_is_nested(vcpu) ? 0 : gva & PAGE_MASK;
189 vcpu->arch.access = access; 194 vcpu->arch.access = access;
190 vcpu->arch.mmio_gfn = gfn; 195 vcpu->arch.mmio_gfn = gfn;
191 vcpu->arch.mmio_gen = kvm_memslots(vcpu->kvm)->generation; 196 vcpu->arch.mmio_gen = gen;
192} 197}
193 198
194static inline bool vcpu_match_mmio_gen(struct kvm_vcpu *vcpu) 199static inline bool vcpu_match_mmio_gen(struct kvm_vcpu *vcpu)
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/arch/xtensa/include/asm/Kbuild b/arch/xtensa/include/asm/Kbuild
index d939e13e8d84..42b6cb3d16f7 100644
--- a/arch/xtensa/include/asm/Kbuild
+++ b/arch/xtensa/include/asm/Kbuild
@@ -15,7 +15,6 @@ generic-y += irq_work.h
15generic-y += kdebug.h 15generic-y += kdebug.h
16generic-y += kmap_types.h 16generic-y += kmap_types.h
17generic-y += kprobes.h 17generic-y += kprobes.h
18generic-y += linkage.h
19generic-y += local.h 18generic-y += local.h
20generic-y += local64.h 19generic-y += local64.h
21generic-y += mcs_spinlock.h 20generic-y += mcs_spinlock.h
diff --git a/arch/xtensa/include/uapi/asm/Kbuild b/arch/xtensa/include/uapi/asm/Kbuild
index 6b43e5049ff7..8a7ad40be463 100644
--- a/arch/xtensa/include/uapi/asm/Kbuild
+++ b/arch/xtensa/include/uapi/asm/Kbuild
@@ -1,5 +1,2 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3generated-y += unistd_32.h 1generated-y += unistd_32.h
4generic-y += kvm_para.h 2generic-y += kvm_para.h
5generic-y += socket.h
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-merge.c b/block/blk-merge.c
index 22467f475ab4..1c9d4f0f96ea 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -180,7 +180,7 @@ static unsigned get_max_segment_size(struct request_queue *q,
180 */ 180 */
181static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv, 181static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv,
182 unsigned *nsegs, unsigned *last_seg_size, 182 unsigned *nsegs, unsigned *last_seg_size,
183 unsigned *front_seg_size, unsigned *sectors) 183 unsigned *front_seg_size, unsigned *sectors, unsigned max_segs)
184{ 184{
185 unsigned len = bv->bv_len; 185 unsigned len = bv->bv_len;
186 unsigned total_len = 0; 186 unsigned total_len = 0;
@@ -190,7 +190,7 @@ static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv,
190 * Multi-page bvec may be too big to hold in one segment, so the 190 * Multi-page bvec may be too big to hold in one segment, so the
191 * current bvec has to be splitted as multiple segments. 191 * current bvec has to be splitted as multiple segments.
192 */ 192 */
193 while (len && new_nsegs + *nsegs < queue_max_segments(q)) { 193 while (len && new_nsegs + *nsegs < max_segs) {
194 seg_size = get_max_segment_size(q, bv->bv_offset + total_len); 194 seg_size = get_max_segment_size(q, bv->bv_offset + total_len);
195 seg_size = min(seg_size, len); 195 seg_size = min(seg_size, len);
196 196
@@ -240,6 +240,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
240 bool do_split = true; 240 bool do_split = true;
241 struct bio *new = NULL; 241 struct bio *new = NULL;
242 const unsigned max_sectors = get_max_io_size(q, bio); 242 const unsigned max_sectors = get_max_io_size(q, bio);
243 const unsigned max_segs = queue_max_segments(q);
243 244
244 bio_for_each_bvec(bv, bio, iter) { 245 bio_for_each_bvec(bv, bio, iter) {
245 /* 246 /*
@@ -254,14 +255,14 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
254 * Consider this a new segment if we're splitting in 255 * Consider this a new segment if we're splitting in
255 * the middle of this vector. 256 * the middle of this vector.
256 */ 257 */
257 if (nsegs < queue_max_segments(q) && 258 if (nsegs < max_segs &&
258 sectors < max_sectors) { 259 sectors < max_sectors) {
259 /* split in the middle of bvec */ 260 /* split in the middle of bvec */
260 bv.bv_len = (max_sectors - sectors) << 9; 261 bv.bv_len = (max_sectors - sectors) << 9;
261 bvec_split_segs(q, &bv, &nsegs, 262 bvec_split_segs(q, &bv, &nsegs,
262 &seg_size, 263 &seg_size,
263 &front_seg_size, 264 &front_seg_size,
264 &sectors); 265 &sectors, max_segs);
265 } 266 }
266 goto split; 267 goto split;
267 } 268 }
@@ -283,7 +284,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
283 continue; 284 continue;
284 } 285 }
285new_segment: 286new_segment:
286 if (nsegs == queue_max_segments(q)) 287 if (nsegs == max_segs)
287 goto split; 288 goto split;
288 289
289 bvprv = bv; 290 bvprv = bv;
@@ -296,7 +297,7 @@ new_segment:
296 if (nsegs == 1 && seg_size > front_seg_size) 297 if (nsegs == 1 && seg_size > front_seg_size)
297 front_seg_size = seg_size; 298 front_seg_size = seg_size;
298 } else if (bvec_split_segs(q, &bv, &nsegs, &seg_size, 299 } else if (bvec_split_segs(q, &bv, &nsegs, &seg_size,
299 &front_seg_size, &sectors)) { 300 &front_seg_size, &sectors, max_segs)) {
300 goto split; 301 goto split;
301 } 302 }
302 } 303 }
@@ -415,7 +416,7 @@ new_segment:
415 bvprv = bv; 416 bvprv = bv;
416 prev = 1; 417 prev = 1;
417 bvec_split_segs(q, &bv, &nr_phys_segs, &seg_size, 418 bvec_split_segs(q, &bv, &nr_phys_segs, &seg_size,
418 &front_seg_size, NULL); 419 &front_seg_size, NULL, UINT_MAX);
419 } 420 }
420 bbio = bio; 421 bbio = bio;
421 } 422 }
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/nfit/core.c b/drivers/acpi/nfit/core.c
index df8979008dd4..5a389a4f4f65 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -2956,11 +2956,15 @@ static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc,
2956 ndr_desc->res = &res; 2956 ndr_desc->res = &res;
2957 ndr_desc->provider_data = nfit_spa; 2957 ndr_desc->provider_data = nfit_spa;
2958 ndr_desc->attr_groups = acpi_nfit_region_attribute_groups; 2958 ndr_desc->attr_groups = acpi_nfit_region_attribute_groups;
2959 if (spa->flags & ACPI_NFIT_PROXIMITY_VALID) 2959 if (spa->flags & ACPI_NFIT_PROXIMITY_VALID) {
2960 ndr_desc->numa_node = acpi_map_pxm_to_online_node( 2960 ndr_desc->numa_node = acpi_map_pxm_to_online_node(
2961 spa->proximity_domain); 2961 spa->proximity_domain);
2962 else 2962 ndr_desc->target_node = acpi_map_pxm_to_node(
2963 spa->proximity_domain);
2964 } else {
2963 ndr_desc->numa_node = NUMA_NO_NODE; 2965 ndr_desc->numa_node = NUMA_NO_NODE;
2966 ndr_desc->target_node = NUMA_NO_NODE;
2967 }
2964 2968
2965 /* 2969 /*
2966 * Persistence domain bits are hierarchical, if 2970 * Persistence domain bits are hierarchical, if
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 7bbbf8256a41..867f6e3f2b4f 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -84,6 +84,7 @@ int acpi_map_pxm_to_node(int pxm)
84 84
85 return node; 85 return node;
86} 86}
87EXPORT_SYMBOL(acpi_map_pxm_to_node);
87 88
88/** 89/**
89 * acpi_map_pxm_to_online_node - Map proximity ID to online node 90 * acpi_map_pxm_to_online_node - Map proximity ID to online node
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/amba/bus.c b/drivers/amba/bus.c
index 41b706403ef7..b4dae624b9af 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -26,19 +26,36 @@
26 26
27#define to_amba_driver(d) container_of(d, struct amba_driver, drv) 27#define to_amba_driver(d) container_of(d, struct amba_driver, drv)
28 28
29static const struct amba_id * 29/* called on periphid match and class 0x9 coresight device. */
30amba_lookup(const struct amba_id *table, struct amba_device *dev) 30static int
31amba_cs_uci_id_match(const struct amba_id *table, struct amba_device *dev)
31{ 32{
32 int ret = 0; 33 int ret = 0;
34 struct amba_cs_uci_id *uci;
35
36 uci = table->data;
33 37
38 /* no table data or zero mask - return match on periphid */
39 if (!uci || (uci->devarch_mask == 0))
40 return 1;
41
42 /* test against read devtype and masked devarch value */
43 ret = (dev->uci.devtype == uci->devtype) &&
44 ((dev->uci.devarch & uci->devarch_mask) == uci->devarch);
45 return ret;
46}
47
48static const struct amba_id *
49amba_lookup(const struct amba_id *table, struct amba_device *dev)
50{
34 while (table->mask) { 51 while (table->mask) {
35 ret = (dev->periphid & table->mask) == table->id; 52 if (((dev->periphid & table->mask) == table->id) &&
36 if (ret) 53 ((dev->cid != CORESIGHT_CID) ||
37 break; 54 (amba_cs_uci_id_match(table, dev))))
55 return table;
38 table++; 56 table++;
39 } 57 }
40 58 return NULL;
41 return ret ? table : NULL;
42} 59}
43 60
44static int amba_match(struct device *dev, struct device_driver *drv) 61static int amba_match(struct device *dev, struct device_driver *drv)
@@ -399,10 +416,22 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
399 cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << 416 cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) <<
400 (i * 8); 417 (i * 8);
401 418
419 if (cid == CORESIGHT_CID) {
420 /* set the base to the start of the last 4k block */
421 void __iomem *csbase = tmp + size - 4096;
422
423 dev->uci.devarch =
424 readl(csbase + UCI_REG_DEVARCH_OFFSET);
425 dev->uci.devtype =
426 readl(csbase + UCI_REG_DEVTYPE_OFFSET) & 0xff;
427 }
428
402 amba_put_disable_pclk(dev); 429 amba_put_disable_pclk(dev);
403 430
404 if (cid == AMBA_CID || cid == CORESIGHT_CID) 431 if (cid == AMBA_CID || cid == CORESIGHT_CID) {
405 dev->periphid = pid; 432 dev->periphid = pid;
433 dev->cid = cid;
434 }
406 435
407 if (!dev->periphid) 436 if (!dev->periphid)
408 ret = -ENODEV; 437 ret = -ENODEV;
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/memory.c b/drivers/base/memory.c
index 048cbf7d5233..cb8347500ce2 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -88,6 +88,7 @@ unsigned long __weak memory_block_size_bytes(void)
88{ 88{
89 return MIN_MEMORY_BLOCK_SIZE; 89 return MIN_MEMORY_BLOCK_SIZE;
90} 90}
91EXPORT_SYMBOL_GPL(memory_block_size_bytes);
91 92
92static unsigned long get_memory_block_size(void) 93static unsigned long get_memory_block_size(void)
93{ 94{
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/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index a4bc74e72c39..24896ffb04ed 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -926,7 +926,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
926 int err, i, j; 926 int err, i, j;
927 struct xen_blkif *blkif = ring->blkif; 927 struct xen_blkif *blkif = ring->blkif;
928 struct xenbus_device *dev = blkif->be->dev; 928 struct xenbus_device *dev = blkif->be->dev;
929 unsigned int ring_page_order, nr_grefs, evtchn; 929 unsigned int nr_grefs, evtchn;
930 930
931 err = xenbus_scanf(XBT_NIL, dir, "event-channel", "%u", 931 err = xenbus_scanf(XBT_NIL, dir, "event-channel", "%u",
932 &evtchn); 932 &evtchn);
@@ -936,43 +936,42 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
936 return err; 936 return err;
937 } 937 }
938 938
939 err = xenbus_scanf(XBT_NIL, dev->otherend, "ring-page-order", "%u", 939 nr_grefs = blkif->nr_ring_pages;
940 &ring_page_order); 940
941 if (err != 1) { 941 if (unlikely(!nr_grefs)) {
942 err = xenbus_scanf(XBT_NIL, dir, "ring-ref", "%u", &ring_ref[0]); 942 WARN_ON(true);
943 return -EINVAL;
944 }
945
946 for (i = 0; i < nr_grefs; i++) {
947 char ring_ref_name[RINGREF_NAME_LEN];
948
949 snprintf(ring_ref_name, RINGREF_NAME_LEN, "ring-ref%u", i);
950 err = xenbus_scanf(XBT_NIL, dir, ring_ref_name,
951 "%u", &ring_ref[i]);
952
943 if (err != 1) { 953 if (err != 1) {
954 if (nr_grefs == 1)
955 break;
956
944 err = -EINVAL; 957 err = -EINVAL;
945 xenbus_dev_fatal(dev, err, "reading %s/ring-ref", dir); 958 xenbus_dev_fatal(dev, err, "reading %s/%s",
959 dir, ring_ref_name);
946 return err; 960 return err;
947 } 961 }
948 nr_grefs = 1; 962 }
949 } else {
950 unsigned int i;
951 963
952 if (ring_page_order > xen_blkif_max_ring_order) { 964 if (err != 1) {
965 WARN_ON(nr_grefs != 1);
966
967 err = xenbus_scanf(XBT_NIL, dir, "ring-ref", "%u",
968 &ring_ref[0]);
969 if (err != 1) {
953 err = -EINVAL; 970 err = -EINVAL;
954 xenbus_dev_fatal(dev, err, "%s/request %d ring page order exceed max:%d", 971 xenbus_dev_fatal(dev, err, "reading %s/ring-ref", dir);
955 dir, ring_page_order,
956 xen_blkif_max_ring_order);
957 return err; 972 return err;
958 } 973 }
959
960 nr_grefs = 1 << ring_page_order;
961 for (i = 0; i < nr_grefs; i++) {
962 char ring_ref_name[RINGREF_NAME_LEN];
963
964 snprintf(ring_ref_name, RINGREF_NAME_LEN, "ring-ref%u", i);
965 err = xenbus_scanf(XBT_NIL, dir, ring_ref_name,
966 "%u", &ring_ref[i]);
967 if (err != 1) {
968 err = -EINVAL;
969 xenbus_dev_fatal(dev, err, "reading %s/%s",
970 dir, ring_ref_name);
971 return err;
972 }
973 }
974 } 974 }
975 blkif->nr_ring_pages = nr_grefs;
976 975
977 for (i = 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) { 976 for (i = 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) {
978 req = kzalloc(sizeof(*req), GFP_KERNEL); 977 req = kzalloc(sizeof(*req), GFP_KERNEL);
@@ -1023,6 +1022,7 @@ fail:
1023static int connect_ring(struct backend_info *be) 1022static int connect_ring(struct backend_info *be)
1024{ 1023{
1025 struct xenbus_device *dev = be->dev; 1024 struct xenbus_device *dev = be->dev;
1025 struct xen_blkif *blkif = be->blkif;
1026 unsigned int pers_grants; 1026 unsigned int pers_grants;
1027 char protocol[64] = ""; 1027 char protocol[64] = "";
1028 int err, i; 1028 int err, i;
@@ -1030,28 +1030,29 @@ static int connect_ring(struct backend_info *be)
1030 size_t xspathsize; 1030 size_t xspathsize;
1031 const size_t xenstore_path_ext_size = 11; /* sufficient for "/queue-NNN" */ 1031 const size_t xenstore_path_ext_size = 11; /* sufficient for "/queue-NNN" */
1032 unsigned int requested_num_queues = 0; 1032 unsigned int requested_num_queues = 0;
1033 unsigned int ring_page_order;
1033 1034
1034 pr_debug("%s %s\n", __func__, dev->otherend); 1035 pr_debug("%s %s\n", __func__, dev->otherend);
1035 1036
1036 be->blkif->blk_protocol = BLKIF_PROTOCOL_DEFAULT; 1037 blkif->blk_protocol = BLKIF_PROTOCOL_DEFAULT;
1037 err = xenbus_scanf(XBT_NIL, dev->otherend, "protocol", 1038 err = xenbus_scanf(XBT_NIL, dev->otherend, "protocol",
1038 "%63s", protocol); 1039 "%63s", protocol);
1039 if (err <= 0) 1040 if (err <= 0)
1040 strcpy(protocol, "unspecified, assuming default"); 1041 strcpy(protocol, "unspecified, assuming default");
1041 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE)) 1042 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE))
1042 be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE; 1043 blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
1043 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32)) 1044 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32))
1044 be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_32; 1045 blkif->blk_protocol = BLKIF_PROTOCOL_X86_32;
1045 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_64)) 1046 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_64))
1046 be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_64; 1047 blkif->blk_protocol = BLKIF_PROTOCOL_X86_64;
1047 else { 1048 else {
1048 xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol); 1049 xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
1049 return -ENOSYS; 1050 return -ENOSYS;
1050 } 1051 }
1051 pers_grants = xenbus_read_unsigned(dev->otherend, "feature-persistent", 1052 pers_grants = xenbus_read_unsigned(dev->otherend, "feature-persistent",
1052 0); 1053 0);
1053 be->blkif->vbd.feature_gnt_persistent = pers_grants; 1054 blkif->vbd.feature_gnt_persistent = pers_grants;
1054 be->blkif->vbd.overflow_max_grants = 0; 1055 blkif->vbd.overflow_max_grants = 0;
1055 1056
1056 /* 1057 /*
1057 * Read the number of hardware queues from frontend. 1058 * Read the number of hardware queues from frontend.
@@ -1067,16 +1068,30 @@ static int connect_ring(struct backend_info *be)
1067 requested_num_queues, xenblk_max_queues); 1068 requested_num_queues, xenblk_max_queues);
1068 return -ENOSYS; 1069 return -ENOSYS;
1069 } 1070 }
1070 be->blkif->nr_rings = requested_num_queues; 1071 blkif->nr_rings = requested_num_queues;
1071 if (xen_blkif_alloc_rings(be->blkif)) 1072 if (xen_blkif_alloc_rings(blkif))
1072 return -ENOMEM; 1073 return -ENOMEM;
1073 1074
1074 pr_info("%s: using %d queues, protocol %d (%s) %s\n", dev->nodename, 1075 pr_info("%s: using %d queues, protocol %d (%s) %s\n", dev->nodename,
1075 be->blkif->nr_rings, be->blkif->blk_protocol, protocol, 1076 blkif->nr_rings, blkif->blk_protocol, protocol,
1076 pers_grants ? "persistent grants" : ""); 1077 pers_grants ? "persistent grants" : "");
1077 1078
1078 if (be->blkif->nr_rings == 1) 1079 ring_page_order = xenbus_read_unsigned(dev->otherend,
1079 return read_per_ring_refs(&be->blkif->rings[0], dev->otherend); 1080 "ring-page-order", 0);
1081
1082 if (ring_page_order > xen_blkif_max_ring_order) {
1083 err = -EINVAL;
1084 xenbus_dev_fatal(dev, err,
1085 "requested ring page order %d exceed max:%d",
1086 ring_page_order,
1087 xen_blkif_max_ring_order);
1088 return err;
1089 }
1090
1091 blkif->nr_ring_pages = 1 << ring_page_order;
1092
1093 if (blkif->nr_rings == 1)
1094 return read_per_ring_refs(&blkif->rings[0], dev->otherend);
1080 else { 1095 else {
1081 xspathsize = strlen(dev->otherend) + xenstore_path_ext_size; 1096 xspathsize = strlen(dev->otherend) + xenstore_path_ext_size;
1082 xspath = kmalloc(xspathsize, GFP_KERNEL); 1097 xspath = kmalloc(xspathsize, GFP_KERNEL);
@@ -1085,10 +1100,10 @@ static int connect_ring(struct backend_info *be)
1085 return -ENOMEM; 1100 return -ENOMEM;
1086 } 1101 }
1087 1102
1088 for (i = 0; i < be->blkif->nr_rings; i++) { 1103 for (i = 0; i < blkif->nr_rings; i++) {
1089 memset(xspath, 0, xspathsize); 1104 memset(xspath, 0, xspathsize);
1090 snprintf(xspath, xspathsize, "%s/queue-%u", dev->otherend, i); 1105 snprintf(xspath, xspathsize, "%s/queue-%u", dev->otherend, i);
1091 err = read_per_ring_refs(&be->blkif->rings[i], xspath); 1106 err = read_per_ring_refs(&blkif->rings[i], xspath);
1092 if (err) { 1107 if (err) {
1093 kfree(xspath); 1108 kfree(xspath);
1094 return err; 1109 return err;
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index a8b20b65bd4b..aa4ec53281ce 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1261,6 +1261,13 @@ static enum arch_timer_ppi_nr __init arch_timer_select_ppi(void)
1261 return ARCH_TIMER_PHYS_SECURE_PPI; 1261 return ARCH_TIMER_PHYS_SECURE_PPI;
1262} 1262}
1263 1263
1264static void __init arch_timer_populate_kvm_info(void)
1265{
1266 arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
1267 if (is_kernel_in_hyp_mode())
1268 arch_timer_kvm_info.physical_irq = arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI];
1269}
1270
1264static int __init arch_timer_of_init(struct device_node *np) 1271static int __init arch_timer_of_init(struct device_node *np)
1265{ 1272{
1266 int i, ret; 1273 int i, ret;
@@ -1275,7 +1282,7 @@ static int __init arch_timer_of_init(struct device_node *np)
1275 for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++) 1282 for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
1276 arch_timer_ppi[i] = irq_of_parse_and_map(np, i); 1283 arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
1277 1284
1278 arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI]; 1285 arch_timer_populate_kvm_info();
1279 1286
1280 rate = arch_timer_get_cntfrq(); 1287 rate = arch_timer_get_cntfrq();
1281 arch_timer_of_configure_rate(rate, np); 1288 arch_timer_of_configure_rate(rate, np);
@@ -1605,7 +1612,7 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
1605 arch_timer_ppi[ARCH_TIMER_HYP_PPI] = 1612 arch_timer_ppi[ARCH_TIMER_HYP_PPI] =
1606 acpi_gtdt_map_ppi(ARCH_TIMER_HYP_PPI); 1613 acpi_gtdt_map_ppi(ARCH_TIMER_HYP_PPI);
1607 1614
1608 arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI]; 1615 arch_timer_populate_kvm_info();
1609 1616
1610 /* 1617 /*
1611 * When probing via ACPI, we have no mechanism to override the sysreg 1618 * When probing via ACPI, we have no mechanism to override the sysreg
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/dax/Kconfig b/drivers/dax/Kconfig
index e0700bf4893a..5ef624fe3934 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -23,12 +23,38 @@ config DEV_DAX
23config DEV_DAX_PMEM 23config DEV_DAX_PMEM
24 tristate "PMEM DAX: direct access to persistent memory" 24 tristate "PMEM DAX: direct access to persistent memory"
25 depends on LIBNVDIMM && NVDIMM_DAX && DEV_DAX 25 depends on LIBNVDIMM && NVDIMM_DAX && DEV_DAX
26 depends on m # until we can kill DEV_DAX_PMEM_COMPAT
26 default DEV_DAX 27 default DEV_DAX
27 help 28 help
28 Support raw access to persistent memory. Note that this 29 Support raw access to persistent memory. Note that this
29 driver consumes memory ranges allocated and exported by the 30 driver consumes memory ranges allocated and exported by the
30 libnvdimm sub-system. 31 libnvdimm sub-system.
31 32
32 Say Y if unsure 33 Say M if unsure
34
35config DEV_DAX_KMEM
36 tristate "KMEM DAX: volatile-use of persistent memory"
37 default DEV_DAX
38 depends on DEV_DAX
39 depends on MEMORY_HOTPLUG # for add_memory() and friends
40 help
41 Support access to persistent memory as if it were RAM. This
42 allows easier use of persistent memory by unmodified
43 applications.
44
45 To use this feature, a DAX device must be unbound from the
46 device_dax driver (PMEM DAX) and bound to this kmem driver
47 on each boot.
48
49 Say N if unsure.
50
51config DEV_DAX_PMEM_COMPAT
52 tristate "PMEM DAX: support the deprecated /sys/class/dax interface"
53 depends on DEV_DAX_PMEM
54 default DEV_DAX_PMEM
55 help
56 Older versions of the libdaxctl library expect to find all
57 device-dax instances under /sys/class/dax. If libdaxctl in
58 your distribution is older than v58 say M, otherwise say N.
33 59
34endif 60endif
diff --git a/drivers/dax/Makefile b/drivers/dax/Makefile
index 574286fac87c..81f7d54dadfb 100644
--- a/drivers/dax/Makefile
+++ b/drivers/dax/Makefile
@@ -1,8 +1,10 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2obj-$(CONFIG_DAX) += dax.o 2obj-$(CONFIG_DAX) += dax.o
3obj-$(CONFIG_DEV_DAX) += device_dax.o 3obj-$(CONFIG_DEV_DAX) += device_dax.o
4obj-$(CONFIG_DEV_DAX_PMEM) += dax_pmem.o 4obj-$(CONFIG_DEV_DAX_KMEM) += kmem.o
5 5
6dax-y := super.o 6dax-y := super.o
7dax_pmem-y := pmem.o 7dax-y += bus.o
8device_dax-y := device.o 8device_dax-y := device.o
9
10obj-y += pmem/
diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
new file mode 100644
index 000000000000..2109cfe80219
--- /dev/null
+++ b/drivers/dax/bus.c
@@ -0,0 +1,503 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2017-2018 Intel Corporation. All rights reserved. */
3#include <linux/memremap.h>
4#include <linux/device.h>
5#include <linux/mutex.h>
6#include <linux/list.h>
7#include <linux/slab.h>
8#include <linux/dax.h>
9#include "dax-private.h"
10#include "bus.h"
11
12static struct class *dax_class;
13
14static DEFINE_MUTEX(dax_bus_lock);
15
16#define DAX_NAME_LEN 30
17struct dax_id {
18 struct list_head list;
19 char dev_name[DAX_NAME_LEN];
20};
21
22static int dax_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
23{
24 /*
25 * We only ever expect to handle device-dax instances, i.e. the
26 * @type argument to MODULE_ALIAS_DAX_DEVICE() is always zero
27 */
28 return add_uevent_var(env, "MODALIAS=" DAX_DEVICE_MODALIAS_FMT, 0);
29}
30
31static struct dax_device_driver *to_dax_drv(struct device_driver *drv)
32{
33 return container_of(drv, struct dax_device_driver, drv);
34}
35
36static struct dax_id *__dax_match_id(struct dax_device_driver *dax_drv,
37 const char *dev_name)
38{
39 struct dax_id *dax_id;
40
41 lockdep_assert_held(&dax_bus_lock);
42
43 list_for_each_entry(dax_id, &dax_drv->ids, list)
44 if (sysfs_streq(dax_id->dev_name, dev_name))
45 return dax_id;
46 return NULL;
47}
48
49static int dax_match_id(struct dax_device_driver *dax_drv, struct device *dev)
50{
51 int match;
52
53 mutex_lock(&dax_bus_lock);
54 match = !!__dax_match_id(dax_drv, dev_name(dev));
55 mutex_unlock(&dax_bus_lock);
56
57 return match;
58}
59
60enum id_action {
61 ID_REMOVE,
62 ID_ADD,
63};
64
65static ssize_t do_id_store(struct device_driver *drv, const char *buf,
66 size_t count, enum id_action action)
67{
68 struct dax_device_driver *dax_drv = to_dax_drv(drv);
69 unsigned int region_id, id;
70 char devname[DAX_NAME_LEN];
71 struct dax_id *dax_id;
72 ssize_t rc = count;
73 int fields;
74
75 fields = sscanf(buf, "dax%d.%d", &region_id, &id);
76 if (fields != 2)
77 return -EINVAL;
78 sprintf(devname, "dax%d.%d", region_id, id);
79 if (!sysfs_streq(buf, devname))
80 return -EINVAL;
81
82 mutex_lock(&dax_bus_lock);
83 dax_id = __dax_match_id(dax_drv, buf);
84 if (!dax_id) {
85 if (action == ID_ADD) {
86 dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL);
87 if (dax_id) {
88 strncpy(dax_id->dev_name, buf, DAX_NAME_LEN);
89 list_add(&dax_id->list, &dax_drv->ids);
90 } else
91 rc = -ENOMEM;
92 } else
93 /* nothing to remove */;
94 } else if (action == ID_REMOVE) {
95 list_del(&dax_id->list);
96 kfree(dax_id);
97 } else
98 /* dax_id already added */;
99 mutex_unlock(&dax_bus_lock);
100
101 if (rc < 0)
102 return rc;
103 if (action == ID_ADD)
104 rc = driver_attach(drv);
105 if (rc)
106 return rc;
107 return count;
108}
109
110static ssize_t new_id_store(struct device_driver *drv, const char *buf,
111 size_t count)
112{
113 return do_id_store(drv, buf, count, ID_ADD);
114}
115static DRIVER_ATTR_WO(new_id);
116
117static ssize_t remove_id_store(struct device_driver *drv, const char *buf,
118 size_t count)
119{
120 return do_id_store(drv, buf, count, ID_REMOVE);
121}
122static DRIVER_ATTR_WO(remove_id);
123
124static struct attribute *dax_drv_attrs[] = {
125 &driver_attr_new_id.attr,
126 &driver_attr_remove_id.attr,
127 NULL,
128};
129ATTRIBUTE_GROUPS(dax_drv);
130
131static int dax_bus_match(struct device *dev, struct device_driver *drv);
132
133static struct bus_type dax_bus_type = {
134 .name = "dax",
135 .uevent = dax_bus_uevent,
136 .match = dax_bus_match,
137 .drv_groups = dax_drv_groups,
138};
139
140static int dax_bus_match(struct device *dev, struct device_driver *drv)
141{
142 struct dax_device_driver *dax_drv = to_dax_drv(drv);
143
144 /*
145 * All but the 'device-dax' driver, which has 'match_always'
146 * set, requires an exact id match.
147 */
148 if (dax_drv->match_always)
149 return 1;
150
151 return dax_match_id(dax_drv, dev);
152}
153
154/*
155 * Rely on the fact that drvdata is set before the attributes are
156 * registered, and that the attributes are unregistered before drvdata
157 * is cleared to assume that drvdata is always valid.
158 */
159static ssize_t id_show(struct device *dev,
160 struct device_attribute *attr, char *buf)
161{
162 struct dax_region *dax_region = dev_get_drvdata(dev);
163
164 return sprintf(buf, "%d\n", dax_region->id);
165}
166static DEVICE_ATTR_RO(id);
167
168static ssize_t region_size_show(struct device *dev,
169 struct device_attribute *attr, char *buf)
170{
171 struct dax_region *dax_region = dev_get_drvdata(dev);
172
173 return sprintf(buf, "%llu\n", (unsigned long long)
174 resource_size(&dax_region->res));
175}
176static struct device_attribute dev_attr_region_size = __ATTR(size, 0444,
177 region_size_show, NULL);
178
179static ssize_t align_show(struct device *dev,
180 struct device_attribute *attr, char *buf)
181{
182 struct dax_region *dax_region = dev_get_drvdata(dev);
183
184 return sprintf(buf, "%u\n", dax_region->align);
185}
186static DEVICE_ATTR_RO(align);
187
188static struct attribute *dax_region_attributes[] = {
189 &dev_attr_region_size.attr,
190 &dev_attr_align.attr,
191 &dev_attr_id.attr,
192 NULL,
193};
194
195static const struct attribute_group dax_region_attribute_group = {
196 .name = "dax_region",
197 .attrs = dax_region_attributes,
198};
199
200static const struct attribute_group *dax_region_attribute_groups[] = {
201 &dax_region_attribute_group,
202 NULL,
203};
204
205static void dax_region_free(struct kref *kref)
206{
207 struct dax_region *dax_region;
208
209 dax_region = container_of(kref, struct dax_region, kref);
210 kfree(dax_region);
211}
212
213void dax_region_put(struct dax_region *dax_region)
214{
215 kref_put(&dax_region->kref, dax_region_free);
216}
217EXPORT_SYMBOL_GPL(dax_region_put);
218
219static void dax_region_unregister(void *region)
220{
221 struct dax_region *dax_region = region;
222
223 sysfs_remove_groups(&dax_region->dev->kobj,
224 dax_region_attribute_groups);
225 dax_region_put(dax_region);
226}
227
228struct dax_region *alloc_dax_region(struct device *parent, int region_id,
229 struct resource *res, int target_node, unsigned int align,
230 unsigned long pfn_flags)
231{
232 struct dax_region *dax_region;
233
234 /*
235 * The DAX core assumes that it can store its private data in
236 * parent->driver_data. This WARN is a reminder / safeguard for
237 * developers of device-dax drivers.
238 */
239 if (dev_get_drvdata(parent)) {
240 dev_WARN(parent, "dax core failed to setup private data\n");
241 return NULL;
242 }
243
244 if (!IS_ALIGNED(res->start, align)
245 || !IS_ALIGNED(resource_size(res), align))
246 return NULL;
247
248 dax_region = kzalloc(sizeof(*dax_region), GFP_KERNEL);
249 if (!dax_region)
250 return NULL;
251
252 dev_set_drvdata(parent, dax_region);
253 memcpy(&dax_region->res, res, sizeof(*res));
254 dax_region->pfn_flags = pfn_flags;
255 kref_init(&dax_region->kref);
256 dax_region->id = region_id;
257 dax_region->align = align;
258 dax_region->dev = parent;
259 dax_region->target_node = target_node;
260 if (sysfs_create_groups(&parent->kobj, dax_region_attribute_groups)) {
261 kfree(dax_region);
262 return NULL;
263 }
264
265 kref_get(&dax_region->kref);
266 if (devm_add_action_or_reset(parent, dax_region_unregister, dax_region))
267 return NULL;
268 return dax_region;
269}
270EXPORT_SYMBOL_GPL(alloc_dax_region);
271
272static ssize_t size_show(struct device *dev,
273 struct device_attribute *attr, char *buf)
274{
275 struct dev_dax *dev_dax = to_dev_dax(dev);
276 unsigned long long size = resource_size(&dev_dax->region->res);
277
278 return sprintf(buf, "%llu\n", size);
279}
280static DEVICE_ATTR_RO(size);
281
282static int dev_dax_target_node(struct dev_dax *dev_dax)
283{
284 struct dax_region *dax_region = dev_dax->region;
285
286 return dax_region->target_node;
287}
288
289static ssize_t target_node_show(struct device *dev,
290 struct device_attribute *attr, char *buf)
291{
292 struct dev_dax *dev_dax = to_dev_dax(dev);
293
294 return sprintf(buf, "%d\n", dev_dax_target_node(dev_dax));
295}
296static DEVICE_ATTR_RO(target_node);
297
298static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
299 char *buf)
300{
301 /*
302 * We only ever expect to handle device-dax instances, i.e. the
303 * @type argument to MODULE_ALIAS_DAX_DEVICE() is always zero
304 */
305 return sprintf(buf, DAX_DEVICE_MODALIAS_FMT "\n", 0);
306}
307static DEVICE_ATTR_RO(modalias);
308
309static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n)
310{
311 struct device *dev = container_of(kobj, struct device, kobj);
312 struct dev_dax *dev_dax = to_dev_dax(dev);
313
314 if (a == &dev_attr_target_node.attr && dev_dax_target_node(dev_dax) < 0)
315 return 0;
316 return a->mode;
317}
318
319static struct attribute *dev_dax_attributes[] = {
320 &dev_attr_modalias.attr,
321 &dev_attr_size.attr,
322 &dev_attr_target_node.attr,
323 NULL,
324};
325
326static const struct attribute_group dev_dax_attribute_group = {
327 .attrs = dev_dax_attributes,
328 .is_visible = dev_dax_visible,
329};
330
331static const struct attribute_group *dax_attribute_groups[] = {
332 &dev_dax_attribute_group,
333 NULL,
334};
335
336void kill_dev_dax(struct dev_dax *dev_dax)
337{
338 struct dax_device *dax_dev = dev_dax->dax_dev;
339 struct inode *inode = dax_inode(dax_dev);
340
341 kill_dax(dax_dev);
342 unmap_mapping_range(inode->i_mapping, 0, 0, 1);
343}
344EXPORT_SYMBOL_GPL(kill_dev_dax);
345
346static void dev_dax_release(struct device *dev)
347{
348 struct dev_dax *dev_dax = to_dev_dax(dev);
349 struct dax_region *dax_region = dev_dax->region;
350 struct dax_device *dax_dev = dev_dax->dax_dev;
351
352 dax_region_put(dax_region);
353 put_dax(dax_dev);
354 kfree(dev_dax);
355}
356
357static void unregister_dev_dax(void *dev)
358{
359 struct dev_dax *dev_dax = to_dev_dax(dev);
360
361 dev_dbg(dev, "%s\n", __func__);
362
363 kill_dev_dax(dev_dax);
364 device_del(dev);
365 put_device(dev);
366}
367
368struct dev_dax *__devm_create_dev_dax(struct dax_region *dax_region, int id,
369 struct dev_pagemap *pgmap, enum dev_dax_subsys subsys)
370{
371 struct device *parent = dax_region->dev;
372 struct dax_device *dax_dev;
373 struct dev_dax *dev_dax;
374 struct inode *inode;
375 struct device *dev;
376 int rc = -ENOMEM;
377
378 if (id < 0)
379 return ERR_PTR(-EINVAL);
380
381 dev_dax = kzalloc(sizeof(*dev_dax), GFP_KERNEL);
382 if (!dev_dax)
383 return ERR_PTR(-ENOMEM);
384
385 memcpy(&dev_dax->pgmap, pgmap, sizeof(*pgmap));
386
387 /*
388 * No 'host' or dax_operations since there is no access to this
389 * device outside of mmap of the resulting character device.
390 */
391 dax_dev = alloc_dax(dev_dax, NULL, NULL);
392 if (!dax_dev)
393 goto err;
394
395 /* a device_dax instance is dead while the driver is not attached */
396 kill_dax(dax_dev);
397
398 /* from here on we're committed to teardown via dax_dev_release() */
399 dev = &dev_dax->dev;
400 device_initialize(dev);
401
402 dev_dax->dax_dev = dax_dev;
403 dev_dax->region = dax_region;
404 dev_dax->target_node = dax_region->target_node;
405 kref_get(&dax_region->kref);
406
407 inode = dax_inode(dax_dev);
408 dev->devt = inode->i_rdev;
409 if (subsys == DEV_DAX_BUS)
410 dev->bus = &dax_bus_type;
411 else
412 dev->class = dax_class;
413 dev->parent = parent;
414 dev->groups = dax_attribute_groups;
415 dev->release = dev_dax_release;
416 dev_set_name(dev, "dax%d.%d", dax_region->id, id);
417
418 rc = device_add(dev);
419 if (rc) {
420 kill_dev_dax(dev_dax);
421 put_device(dev);
422 return ERR_PTR(rc);
423 }
424
425 rc = devm_add_action_or_reset(dax_region->dev, unregister_dev_dax, dev);
426 if (rc)
427 return ERR_PTR(rc);
428
429 return dev_dax;
430
431 err:
432 kfree(dev_dax);
433
434 return ERR_PTR(rc);
435}
436EXPORT_SYMBOL_GPL(__devm_create_dev_dax);
437
438static int match_always_count;
439
440int __dax_driver_register(struct dax_device_driver *dax_drv,
441 struct module *module, const char *mod_name)
442{
443 struct device_driver *drv = &dax_drv->drv;
444 int rc = 0;
445
446 INIT_LIST_HEAD(&dax_drv->ids);
447 drv->owner = module;
448 drv->name = mod_name;
449 drv->mod_name = mod_name;
450 drv->bus = &dax_bus_type;
451
452 /* there can only be one default driver */
453 mutex_lock(&dax_bus_lock);
454 match_always_count += dax_drv->match_always;
455 if (match_always_count > 1) {
456 match_always_count--;
457 WARN_ON(1);
458 rc = -EINVAL;
459 }
460 mutex_unlock(&dax_bus_lock);
461 if (rc)
462 return rc;
463 return driver_register(drv);
464}
465EXPORT_SYMBOL_GPL(__dax_driver_register);
466
467void dax_driver_unregister(struct dax_device_driver *dax_drv)
468{
469 struct device_driver *drv = &dax_drv->drv;
470 struct dax_id *dax_id, *_id;
471
472 mutex_lock(&dax_bus_lock);
473 match_always_count -= dax_drv->match_always;
474 list_for_each_entry_safe(dax_id, _id, &dax_drv->ids, list) {
475 list_del(&dax_id->list);
476 kfree(dax_id);
477 }
478 mutex_unlock(&dax_bus_lock);
479 driver_unregister(drv);
480}
481EXPORT_SYMBOL_GPL(dax_driver_unregister);
482
483int __init dax_bus_init(void)
484{
485 int rc;
486
487 if (IS_ENABLED(CONFIG_DEV_DAX_PMEM_COMPAT)) {
488 dax_class = class_create(THIS_MODULE, "dax");
489 if (IS_ERR(dax_class))
490 return PTR_ERR(dax_class);
491 }
492
493 rc = bus_register(&dax_bus_type);
494 if (rc)
495 class_destroy(dax_class);
496 return rc;
497}
498
499void __exit dax_bus_exit(void)
500{
501 bus_unregister(&dax_bus_type);
502 class_destroy(dax_class);
503}
diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h
new file mode 100644
index 000000000000..8619e3299943
--- /dev/null
+++ b/drivers/dax/bus.h
@@ -0,0 +1,61 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
3#ifndef __DAX_BUS_H__
4#define __DAX_BUS_H__
5#include <linux/device.h>
6
7struct dev_dax;
8struct resource;
9struct dax_device;
10struct dax_region;
11void dax_region_put(struct dax_region *dax_region);
12struct dax_region *alloc_dax_region(struct device *parent, int region_id,
13 struct resource *res, int target_node, unsigned int align,
14 unsigned long flags);
15
16enum dev_dax_subsys {
17 DEV_DAX_BUS,
18 DEV_DAX_CLASS,
19};
20
21struct dev_dax *__devm_create_dev_dax(struct dax_region *dax_region, int id,
22 struct dev_pagemap *pgmap, enum dev_dax_subsys subsys);
23
24static inline struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
25 int id, struct dev_pagemap *pgmap)
26{
27 return __devm_create_dev_dax(dax_region, id, pgmap, DEV_DAX_BUS);
28}
29
30/* to be deleted when DEV_DAX_CLASS is removed */
31struct dev_dax *__dax_pmem_probe(struct device *dev, enum dev_dax_subsys subsys);
32
33struct dax_device_driver {
34 struct device_driver drv;
35 struct list_head ids;
36 int match_always;
37};
38
39int __dax_driver_register(struct dax_device_driver *dax_drv,
40 struct module *module, const char *mod_name);
41#define dax_driver_register(driver) \
42 __dax_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
43void dax_driver_unregister(struct dax_device_driver *dax_drv);
44void kill_dev_dax(struct dev_dax *dev_dax);
45
46#if IS_ENABLED(CONFIG_DEV_DAX_PMEM_COMPAT)
47int dev_dax_probe(struct device *dev);
48#endif
49
50/*
51 * While run_dax() is potentially a generic operation that could be
52 * defined in include/linux/dax.h we don't want to grow any users
53 * outside of drivers/dax/
54 */
55void run_dax(struct dax_device *dax_dev);
56
57#define MODULE_ALIAS_DAX_DEVICE(type) \
58 MODULE_ALIAS("dax:t" __stringify(type) "*")
59#define DAX_DEVICE_MODALIAS_FMT "dax:t%d"
60
61#endif /* __DAX_BUS_H__ */
diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h
index b6fc4f04636d..a45612148ca0 100644
--- a/drivers/dax/dax-private.h
+++ b/drivers/dax/dax-private.h
@@ -16,10 +16,17 @@
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/cdev.h> 17#include <linux/cdev.h>
18 18
19/* private routines between core files */
20struct dax_device;
21struct dax_device *inode_dax(struct inode *inode);
22struct inode *dax_inode(struct dax_device *dax_dev);
23int dax_bus_init(void);
24void dax_bus_exit(void);
25
19/** 26/**
20 * struct dax_region - mapping infrastructure for dax devices 27 * struct dax_region - mapping infrastructure for dax devices
21 * @id: kernel-wide unique region for a memory range 28 * @id: kernel-wide unique region for a memory range
22 * @base: linear address corresponding to @res 29 * @target_node: effective numa node if this memory range is onlined
23 * @kref: to pin while other agents have a need to do lookups 30 * @kref: to pin while other agents have a need to do lookups
24 * @dev: parent device backing this region 31 * @dev: parent device backing this region
25 * @align: allocation and mapping alignment for child dax devices 32 * @align: allocation and mapping alignment for child dax devices
@@ -28,8 +35,7 @@
28 */ 35 */
29struct dax_region { 36struct dax_region {
30 int id; 37 int id;
31 struct ida ida; 38 int target_node;
32 void *base;
33 struct kref kref; 39 struct kref kref;
34 struct device *dev; 40 struct device *dev;
35 unsigned int align; 41 unsigned int align;
@@ -38,20 +44,28 @@ struct dax_region {
38}; 44};
39 45
40/** 46/**
41 * struct dev_dax - instance data for a subdivision of a dax region 47 * struct dev_dax - instance data for a subdivision of a dax region, and
48 * data while the device is activated in the driver.
42 * @region - parent region 49 * @region - parent region
43 * @dax_dev - core dax functionality 50 * @dax_dev - core dax functionality
51 * @target_node: effective numa node if dev_dax memory range is onlined
44 * @dev - device core 52 * @dev - device core
45 * @id - child id in the region 53 * @pgmap - pgmap for memmap setup / lifetime (driver owned)
46 * @num_resources - number of physical address extents in this device 54 * @ref: pgmap reference count (driver owned)
47 * @res - array of physical address ranges 55 * @cmp: @ref final put completion (driver owned)
48 */ 56 */
49struct dev_dax { 57struct dev_dax {
50 struct dax_region *region; 58 struct dax_region *region;
51 struct dax_device *dax_dev; 59 struct dax_device *dax_dev;
60 int target_node;
52 struct device dev; 61 struct device dev;
53 int id; 62 struct dev_pagemap pgmap;
54 int num_resources; 63 struct percpu_ref ref;
55 struct resource res[0]; 64 struct completion cmp;
56}; 65};
66
67static inline struct dev_dax *to_dev_dax(struct device *dev)
68{
69 return container_of(dev, struct dev_dax, dev);
70}
57#endif 71#endif
diff --git a/drivers/dax/dax.h b/drivers/dax/dax.h
deleted file mode 100644
index f9e5feea742c..000000000000
--- a/drivers/dax/dax.h
+++ /dev/null
@@ -1,18 +0,0 @@
1/*
2 * Copyright(c) 2016 - 2017 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#ifndef __DAX_H__
14#define __DAX_H__
15struct dax_device;
16struct dax_device *inode_dax(struct inode *inode);
17struct inode *dax_inode(struct dax_device *dax_dev);
18#endif /* __DAX_H__ */
diff --git a/drivers/dax/device-dax.h b/drivers/dax/device-dax.h
deleted file mode 100644
index 688b051750bd..000000000000
--- a/drivers/dax/device-dax.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/*
2 * Copyright(c) 2016 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#ifndef __DEVICE_DAX_H__
14#define __DEVICE_DAX_H__
15struct device;
16struct dev_dax;
17struct resource;
18struct dax_region;
19void dax_region_put(struct dax_region *dax_region);
20struct dax_region *alloc_dax_region(struct device *parent,
21 int region_id, struct resource *res, unsigned int align,
22 void *addr, unsigned long flags);
23struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
24 int id, struct resource *res, int count);
25#endif /* __DEVICE_DAX_H__ */
diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 948806e57cee..e428468ab661 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -1,15 +1,6 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright(c) 2016 - 2017 Intel Corporation. All rights reserved. 2/* Copyright(c) 2016-2018 Intel Corporation. All rights reserved. */
3 * 3#include <linux/memremap.h>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#include <linux/pagemap.h> 4#include <linux/pagemap.h>
14#include <linux/module.h> 5#include <linux/module.h>
15#include <linux/device.h> 6#include <linux/device.h>
@@ -21,161 +12,39 @@
21#include <linux/mm.h> 12#include <linux/mm.h>
22#include <linux/mman.h> 13#include <linux/mman.h>
23#include "dax-private.h" 14#include "dax-private.h"
24#include "dax.h" 15#include "bus.h"
25 16
26static struct class *dax_class; 17static struct dev_dax *ref_to_dev_dax(struct percpu_ref *ref)
27
28/*
29 * Rely on the fact that drvdata is set before the attributes are
30 * registered, and that the attributes are unregistered before drvdata
31 * is cleared to assume that drvdata is always valid.
32 */
33static ssize_t id_show(struct device *dev,
34 struct device_attribute *attr, char *buf)
35{
36 struct dax_region *dax_region = dev_get_drvdata(dev);
37
38 return sprintf(buf, "%d\n", dax_region->id);
39}
40static DEVICE_ATTR_RO(id);
41
42static ssize_t region_size_show(struct device *dev,
43 struct device_attribute *attr, char *buf)
44{
45 struct dax_region *dax_region = dev_get_drvdata(dev);
46
47 return sprintf(buf, "%llu\n", (unsigned long long)
48 resource_size(&dax_region->res));
49}
50static struct device_attribute dev_attr_region_size = __ATTR(size, 0444,
51 region_size_show, NULL);
52
53static ssize_t align_show(struct device *dev,
54 struct device_attribute *attr, char *buf)
55{
56 struct dax_region *dax_region = dev_get_drvdata(dev);
57
58 return sprintf(buf, "%u\n", dax_region->align);
59}
60static DEVICE_ATTR_RO(align);
61
62static struct attribute *dax_region_attributes[] = {
63 &dev_attr_region_size.attr,
64 &dev_attr_align.attr,
65 &dev_attr_id.attr,
66 NULL,
67};
68
69static const struct attribute_group dax_region_attribute_group = {
70 .name = "dax_region",
71 .attrs = dax_region_attributes,
72};
73
74static const struct attribute_group *dax_region_attribute_groups[] = {
75 &dax_region_attribute_group,
76 NULL,
77};
78
79static void dax_region_free(struct kref *kref)
80{
81 struct dax_region *dax_region;
82
83 dax_region = container_of(kref, struct dax_region, kref);
84 kfree(dax_region);
85}
86
87void dax_region_put(struct dax_region *dax_region)
88{ 18{
89 kref_put(&dax_region->kref, dax_region_free); 19 return container_of(ref, struct dev_dax, ref);
90} 20}
91EXPORT_SYMBOL_GPL(dax_region_put);
92 21
93static void dax_region_unregister(void *region) 22static void dev_dax_percpu_release(struct percpu_ref *ref)
94{ 23{
95 struct dax_region *dax_region = region; 24 struct dev_dax *dev_dax = ref_to_dev_dax(ref);
96 25
97 sysfs_remove_groups(&dax_region->dev->kobj, 26 dev_dbg(&dev_dax->dev, "%s\n", __func__);
98 dax_region_attribute_groups); 27 complete(&dev_dax->cmp);
99 dax_region_put(dax_region);
100} 28}
101 29
102struct dax_region *alloc_dax_region(struct device *parent, int region_id, 30static void dev_dax_percpu_exit(void *data)
103 struct resource *res, unsigned int align, void *addr,
104 unsigned long pfn_flags)
105{ 31{
106 struct dax_region *dax_region; 32 struct percpu_ref *ref = data;
107 33 struct dev_dax *dev_dax = ref_to_dev_dax(ref);
108 /*
109 * The DAX core assumes that it can store its private data in
110 * parent->driver_data. This WARN is a reminder / safeguard for
111 * developers of device-dax drivers.
112 */
113 if (dev_get_drvdata(parent)) {
114 dev_WARN(parent, "dax core failed to setup private data\n");
115 return NULL;
116 }
117
118 if (!IS_ALIGNED(res->start, align)
119 || !IS_ALIGNED(resource_size(res), align))
120 return NULL;
121
122 dax_region = kzalloc(sizeof(*dax_region), GFP_KERNEL);
123 if (!dax_region)
124 return NULL;
125
126 dev_set_drvdata(parent, dax_region);
127 memcpy(&dax_region->res, res, sizeof(*res));
128 dax_region->pfn_flags = pfn_flags;
129 kref_init(&dax_region->kref);
130 dax_region->id = region_id;
131 ida_init(&dax_region->ida);
132 dax_region->align = align;
133 dax_region->dev = parent;
134 dax_region->base = addr;
135 if (sysfs_create_groups(&parent->kobj, dax_region_attribute_groups)) {
136 kfree(dax_region);
137 return NULL;
138 }
139 34
140 kref_get(&dax_region->kref); 35 dev_dbg(&dev_dax->dev, "%s\n", __func__);
141 if (devm_add_action_or_reset(parent, dax_region_unregister, dax_region)) 36 wait_for_completion(&dev_dax->cmp);
142 return NULL; 37 percpu_ref_exit(ref);
143 return dax_region;
144} 38}
145EXPORT_SYMBOL_GPL(alloc_dax_region);
146 39
147static struct dev_dax *to_dev_dax(struct device *dev) 40static void dev_dax_percpu_kill(struct percpu_ref *data)
148{ 41{
149 return container_of(dev, struct dev_dax, dev); 42 struct percpu_ref *ref = data;
150} 43 struct dev_dax *dev_dax = ref_to_dev_dax(ref);
151
152static ssize_t size_show(struct device *dev,
153 struct device_attribute *attr, char *buf)
154{
155 struct dev_dax *dev_dax = to_dev_dax(dev);
156 unsigned long long size = 0;
157 int i;
158 44
159 for (i = 0; i < dev_dax->num_resources; i++) 45 dev_dbg(&dev_dax->dev, "%s\n", __func__);
160 size += resource_size(&dev_dax->res[i]); 46 percpu_ref_kill(ref);
161
162 return sprintf(buf, "%llu\n", size);
163} 47}
164static DEVICE_ATTR_RO(size);
165
166static struct attribute *dev_dax_attributes[] = {
167 &dev_attr_size.attr,
168 NULL,
169};
170
171static const struct attribute_group dev_dax_attribute_group = {
172 .attrs = dev_dax_attributes,
173};
174
175static const struct attribute_group *dax_attribute_groups[] = {
176 &dev_dax_attribute_group,
177 NULL,
178};
179 48
180static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma, 49static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
181 const char *func) 50 const char *func)
@@ -226,21 +95,11 @@ static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
226__weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, 95__weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
227 unsigned long size) 96 unsigned long size)
228{ 97{
229 struct resource *res; 98 struct resource *res = &dev_dax->region->res;
230 /* gcc-4.6.3-nolibc for i386 complains that this is uninitialized */ 99 phys_addr_t phys;
231 phys_addr_t uninitialized_var(phys);
232 int i;
233
234 for (i = 0; i < dev_dax->num_resources; i++) {
235 res = &dev_dax->res[i];
236 phys = pgoff * PAGE_SIZE + res->start;
237 if (phys >= res->start && phys <= res->end)
238 break;
239 pgoff -= PHYS_PFN(resource_size(res));
240 }
241 100
242 if (i < dev_dax->num_resources) { 101 phys = pgoff * PAGE_SIZE + res->start;
243 res = &dev_dax->res[i]; 102 if (phys >= res->start && phys <= res->end) {
244 if (phys + size - 1 <= res->end) 103 if (phys + size - 1 <= res->end)
245 return phys; 104 return phys;
246 } 105 }
@@ -576,152 +435,100 @@ static const struct file_operations dax_fops = {
576 .mmap_supported_flags = MAP_SYNC, 435 .mmap_supported_flags = MAP_SYNC,
577}; 436};
578 437
579static void dev_dax_release(struct device *dev) 438static void dev_dax_cdev_del(void *cdev)
580{ 439{
581 struct dev_dax *dev_dax = to_dev_dax(dev); 440 cdev_del(cdev);
582 struct dax_region *dax_region = dev_dax->region;
583 struct dax_device *dax_dev = dev_dax->dax_dev;
584
585 if (dev_dax->id >= 0)
586 ida_simple_remove(&dax_region->ida, dev_dax->id);
587 dax_region_put(dax_region);
588 put_dax(dax_dev);
589 kfree(dev_dax);
590} 441}
591 442
592static void kill_dev_dax(struct dev_dax *dev_dax) 443static void dev_dax_kill(void *dev_dax)
593{ 444{
594 struct dax_device *dax_dev = dev_dax->dax_dev; 445 kill_dev_dax(dev_dax);
595 struct inode *inode = dax_inode(dax_dev);
596
597 kill_dax(dax_dev);
598 unmap_mapping_range(inode->i_mapping, 0, 0, 1);
599} 446}
600 447
601static void unregister_dev_dax(void *dev) 448int dev_dax_probe(struct device *dev)
602{ 449{
603 struct dev_dax *dev_dax = to_dev_dax(dev); 450 struct dev_dax *dev_dax = to_dev_dax(dev);
604 struct dax_device *dax_dev = dev_dax->dax_dev; 451 struct dax_device *dax_dev = dev_dax->dax_dev;
605 struct inode *inode = dax_inode(dax_dev); 452 struct resource *res = &dev_dax->region->res;
606 struct cdev *cdev = inode->i_cdev;
607
608 dev_dbg(dev, "trace\n");
609
610 kill_dev_dax(dev_dax);
611 cdev_device_del(cdev, dev);
612 put_device(dev);
613}
614
615struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region,
616 int id, struct resource *res, int count)
617{
618 struct device *parent = dax_region->dev;
619 struct dax_device *dax_dev;
620 struct dev_dax *dev_dax;
621 struct inode *inode; 453 struct inode *inode;
622 struct device *dev;
623 struct cdev *cdev; 454 struct cdev *cdev;
624 int rc, i; 455 void *addr;
625 456 int rc;
626 if (!count) 457
627 return ERR_PTR(-EINVAL); 458 /* 1:1 map region resource range to device-dax instance range */
628 459 if (!devm_request_mem_region(dev, res->start, resource_size(res),
629 dev_dax = kzalloc(struct_size(dev_dax, res, count), GFP_KERNEL); 460 dev_name(dev))) {
630 if (!dev_dax) 461 dev_warn(dev, "could not reserve region %pR\n", res);
631 return ERR_PTR(-ENOMEM); 462 return -EBUSY;
632
633 for (i = 0; i < count; i++) {
634 if (!IS_ALIGNED(res[i].start, dax_region->align)
635 || !IS_ALIGNED(resource_size(&res[i]),
636 dax_region->align)) {
637 rc = -EINVAL;
638 break;
639 }
640 dev_dax->res[i].start = res[i].start;
641 dev_dax->res[i].end = res[i].end;
642 } 463 }
643 464
644 if (i < count) 465 init_completion(&dev_dax->cmp);
645 goto err_id; 466 rc = percpu_ref_init(&dev_dax->ref, dev_dax_percpu_release, 0,
467 GFP_KERNEL);
468 if (rc)
469 return rc;
646 470
647 if (id < 0) { 471 rc = devm_add_action_or_reset(dev, dev_dax_percpu_exit, &dev_dax->ref);
648 id = ida_simple_get(&dax_region->ida, 0, 0, GFP_KERNEL); 472 if (rc)
649 dev_dax->id = id; 473 return rc;
650 if (id < 0) {
651 rc = id;
652 goto err_id;
653 }
654 } else {
655 /* region provider owns @id lifetime */
656 dev_dax->id = -1;
657 }
658 474
659 /* 475 dev_dax->pgmap.ref = &dev_dax->ref;
660 * No 'host' or dax_operations since there is no access to this 476 dev_dax->pgmap.kill = dev_dax_percpu_kill;
661 * device outside of mmap of the resulting character device. 477 addr = devm_memremap_pages(dev, &dev_dax->pgmap);
662 */ 478 if (IS_ERR(addr)) {
663 dax_dev = alloc_dax(dev_dax, NULL, NULL); 479 devm_remove_action(dev, dev_dax_percpu_exit, &dev_dax->ref);
664 if (!dax_dev) { 480 percpu_ref_exit(&dev_dax->ref);
665 rc = -ENOMEM; 481 return PTR_ERR(addr);
666 goto err_dax;
667 } 482 }
668 483
669 /* from here on we're committed to teardown via dax_dev_release() */
670 dev = &dev_dax->dev;
671 device_initialize(dev);
672
673 inode = dax_inode(dax_dev); 484 inode = dax_inode(dax_dev);
674 cdev = inode->i_cdev; 485 cdev = inode->i_cdev;
675 cdev_init(cdev, &dax_fops); 486 cdev_init(cdev, &dax_fops);
676 cdev->owner = parent->driver->owner; 487 if (dev->class) {
677 488 /* for the CONFIG_DEV_DAX_PMEM_COMPAT case */
678 dev_dax->num_resources = count; 489 cdev->owner = dev->parent->driver->owner;
679 dev_dax->dax_dev = dax_dev; 490 } else
680 dev_dax->region = dax_region; 491 cdev->owner = dev->driver->owner;
681 kref_get(&dax_region->kref); 492 cdev_set_parent(cdev, &dev->kobj);
682 493 rc = cdev_add(cdev, dev->devt, 1);
683 dev->devt = inode->i_rdev;
684 dev->class = dax_class;
685 dev->parent = parent;
686 dev->groups = dax_attribute_groups;
687 dev->release = dev_dax_release;
688 dev_set_name(dev, "dax%d.%d", dax_region->id, id);
689
690 rc = cdev_device_add(cdev, dev);
691 if (rc) {
692 kill_dev_dax(dev_dax);
693 put_device(dev);
694 return ERR_PTR(rc);
695 }
696
697 rc = devm_add_action_or_reset(dax_region->dev, unregister_dev_dax, dev);
698 if (rc) 494 if (rc)
699 return ERR_PTR(rc); 495 return rc;
700 496
701 return dev_dax; 497 rc = devm_add_action_or_reset(dev, dev_dax_cdev_del, cdev);
498 if (rc)
499 return rc;
702 500
703 err_dax: 501 run_dax(dax_dev);
704 if (dev_dax->id >= 0) 502 return devm_add_action_or_reset(dev, dev_dax_kill, dev_dax);
705 ida_simple_remove(&dax_region->ida, dev_dax->id); 503}
706 err_id: 504EXPORT_SYMBOL_GPL(dev_dax_probe);
707 kfree(dev_dax);
708 505
709 return ERR_PTR(rc); 506static int dev_dax_remove(struct device *dev)
507{
508 /* all probe actions are unwound by devm */
509 return 0;
710} 510}
711EXPORT_SYMBOL_GPL(devm_create_dev_dax); 511
512static struct dax_device_driver device_dax_driver = {
513 .drv = {
514 .probe = dev_dax_probe,
515 .remove = dev_dax_remove,
516 },
517 .match_always = 1,
518};
712 519
713static int __init dax_init(void) 520static int __init dax_init(void)
714{ 521{
715 dax_class = class_create(THIS_MODULE, "dax"); 522 return dax_driver_register(&device_dax_driver);
716 return PTR_ERR_OR_ZERO(dax_class);
717} 523}
718 524
719static void __exit dax_exit(void) 525static void __exit dax_exit(void)
720{ 526{
721 class_destroy(dax_class); 527 dax_driver_unregister(&device_dax_driver);
722} 528}
723 529
724MODULE_AUTHOR("Intel Corporation"); 530MODULE_AUTHOR("Intel Corporation");
725MODULE_LICENSE("GPL v2"); 531MODULE_LICENSE("GPL v2");
726subsys_initcall(dax_init); 532module_init(dax_init);
727module_exit(dax_exit); 533module_exit(dax_exit);
534MODULE_ALIAS_DAX_DEVICE(0);
diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c
new file mode 100644
index 000000000000..a02318c6d28a
--- /dev/null
+++ b/drivers/dax/kmem.c
@@ -0,0 +1,108 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2016-2019 Intel Corporation. All rights reserved. */
3#include <linux/memremap.h>
4#include <linux/pagemap.h>
5#include <linux/memory.h>
6#include <linux/module.h>
7#include <linux/device.h>
8#include <linux/pfn_t.h>
9#include <linux/slab.h>
10#include <linux/dax.h>
11#include <linux/fs.h>
12#include <linux/mm.h>
13#include <linux/mman.h>
14#include "dax-private.h"
15#include "bus.h"
16
17int dev_dax_kmem_probe(struct device *dev)
18{
19 struct dev_dax *dev_dax = to_dev_dax(dev);
20 struct resource *res = &dev_dax->region->res;
21 resource_size_t kmem_start;
22 resource_size_t kmem_size;
23 resource_size_t kmem_end;
24 struct resource *new_res;
25 int numa_node;
26 int rc;
27
28 /*
29 * Ensure good NUMA information for the persistent memory.
30 * Without this check, there is a risk that slow memory
31 * could be mixed in a node with faster memory, causing
32 * unavoidable performance issues.
33 */
34 numa_node = dev_dax->target_node;
35 if (numa_node < 0) {
36 dev_warn(dev, "rejecting DAX region %pR with invalid node: %d\n",
37 res, numa_node);
38 return -EINVAL;
39 }
40
41 /* Hotplug starting at the beginning of the next block: */
42 kmem_start = ALIGN(res->start, memory_block_size_bytes());
43
44 kmem_size = resource_size(res);
45 /* Adjust the size down to compensate for moving up kmem_start: */
46 kmem_size -= kmem_start - res->start;
47 /* Align the size down to cover only complete blocks: */
48 kmem_size &= ~(memory_block_size_bytes() - 1);
49 kmem_end = kmem_start + kmem_size;
50
51 /* Region is permanently reserved. Hot-remove not yet implemented. */
52 new_res = request_mem_region(kmem_start, kmem_size, dev_name(dev));
53 if (!new_res) {
54 dev_warn(dev, "could not reserve region [%pa-%pa]\n",
55 &kmem_start, &kmem_end);
56 return -EBUSY;
57 }
58
59 /*
60 * Set flags appropriate for System RAM. Leave ..._BUSY clear
61 * so that add_memory() can add a child resource. Do not
62 * inherit flags from the parent since it may set new flags
63 * unknown to us that will break add_memory() below.
64 */
65 new_res->flags = IORESOURCE_SYSTEM_RAM;
66 new_res->name = dev_name(dev);
67
68 rc = add_memory(numa_node, new_res->start, resource_size(new_res));
69 if (rc)
70 return rc;
71
72 return 0;
73}
74
75static int dev_dax_kmem_remove(struct device *dev)
76{
77 /*
78 * Purposely leak the request_mem_region() for the device-dax
79 * range and return '0' to ->remove() attempts. The removal of
80 * the device from the driver always succeeds, but the region
81 * is permanently pinned as reserved by the unreleased
82 * request_mem_region().
83 */
84 return 0;
85}
86
87static struct dax_device_driver device_dax_kmem_driver = {
88 .drv = {
89 .probe = dev_dax_kmem_probe,
90 .remove = dev_dax_kmem_remove,
91 },
92};
93
94static int __init dax_kmem_init(void)
95{
96 return dax_driver_register(&device_dax_kmem_driver);
97}
98
99static void __exit dax_kmem_exit(void)
100{
101 dax_driver_unregister(&device_dax_kmem_driver);
102}
103
104MODULE_AUTHOR("Intel Corporation");
105MODULE_LICENSE("GPL v2");
106module_init(dax_kmem_init);
107module_exit(dax_kmem_exit);
108MODULE_ALIAS_DAX_DEVICE(0);
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
deleted file mode 100644
index 2c1f459c0c63..000000000000
--- a/drivers/dax/pmem.c
+++ /dev/null
@@ -1,153 +0,0 @@
1/*
2 * Copyright(c) 2016 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#include <linux/percpu-refcount.h>
14#include <linux/memremap.h>
15#include <linux/module.h>
16#include <linux/pfn_t.h>
17#include "../nvdimm/pfn.h"
18#include "../nvdimm/nd.h"
19#include "device-dax.h"
20
21struct dax_pmem {
22 struct device *dev;
23 struct percpu_ref ref;
24 struct dev_pagemap pgmap;
25 struct completion cmp;
26};
27
28static struct dax_pmem *to_dax_pmem(struct percpu_ref *ref)
29{
30 return container_of(ref, struct dax_pmem, ref);
31}
32
33static void dax_pmem_percpu_release(struct percpu_ref *ref)
34{
35 struct dax_pmem *dax_pmem = to_dax_pmem(ref);
36
37 dev_dbg(dax_pmem->dev, "trace\n");
38 complete(&dax_pmem->cmp);
39}
40
41static void dax_pmem_percpu_exit(void *data)
42{
43 struct percpu_ref *ref = data;
44 struct dax_pmem *dax_pmem = to_dax_pmem(ref);
45
46 dev_dbg(dax_pmem->dev, "trace\n");
47 wait_for_completion(&dax_pmem->cmp);
48 percpu_ref_exit(ref);
49}
50
51static void dax_pmem_percpu_kill(struct percpu_ref *ref)
52{
53 struct dax_pmem *dax_pmem = to_dax_pmem(ref);
54
55 dev_dbg(dax_pmem->dev, "trace\n");
56 percpu_ref_kill(ref);
57}
58
59static int dax_pmem_probe(struct device *dev)
60{
61 void *addr;
62 struct resource res;
63 int rc, id, region_id;
64 struct nd_pfn_sb *pfn_sb;
65 struct dev_dax *dev_dax;
66 struct dax_pmem *dax_pmem;
67 struct nd_namespace_io *nsio;
68 struct dax_region *dax_region;
69 struct nd_namespace_common *ndns;
70 struct nd_dax *nd_dax = to_nd_dax(dev);
71 struct nd_pfn *nd_pfn = &nd_dax->nd_pfn;
72
73 ndns = nvdimm_namespace_common_probe(dev);
74 if (IS_ERR(ndns))
75 return PTR_ERR(ndns);
76 nsio = to_nd_namespace_io(&ndns->dev);
77
78 dax_pmem = devm_kzalloc(dev, sizeof(*dax_pmem), GFP_KERNEL);
79 if (!dax_pmem)
80 return -ENOMEM;
81
82 /* parse the 'pfn' info block via ->rw_bytes */
83 rc = devm_nsio_enable(dev, nsio);
84 if (rc)
85 return rc;
86 rc = nvdimm_setup_pfn(nd_pfn, &dax_pmem->pgmap);
87 if (rc)
88 return rc;
89 devm_nsio_disable(dev, nsio);
90
91 pfn_sb = nd_pfn->pfn_sb;
92
93 if (!devm_request_mem_region(dev, nsio->res.start,
94 resource_size(&nsio->res),
95 dev_name(&ndns->dev))) {
96 dev_warn(dev, "could not reserve region %pR\n", &nsio->res);
97 return -EBUSY;
98 }
99
100 dax_pmem->dev = dev;
101 init_completion(&dax_pmem->cmp);
102 rc = percpu_ref_init(&dax_pmem->ref, dax_pmem_percpu_release, 0,
103 GFP_KERNEL);
104 if (rc)
105 return rc;
106
107 rc = devm_add_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
108 if (rc) {
109 percpu_ref_exit(&dax_pmem->ref);
110 return rc;
111 }
112
113 dax_pmem->pgmap.ref = &dax_pmem->ref;
114 dax_pmem->pgmap.kill = dax_pmem_percpu_kill;
115 addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
116 if (IS_ERR(addr))
117 return PTR_ERR(addr);
118
119 /* adjust the dax_region resource to the start of data */
120 memcpy(&res, &dax_pmem->pgmap.res, sizeof(res));
121 res.start += le64_to_cpu(pfn_sb->dataoff);
122
123 rc = sscanf(dev_name(&ndns->dev), "namespace%d.%d", &region_id, &id);
124 if (rc != 2)
125 return -EINVAL;
126
127 dax_region = alloc_dax_region(dev, region_id, &res,
128 le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP);
129 if (!dax_region)
130 return -ENOMEM;
131
132 /* TODO: support for subdividing a dax region... */
133 dev_dax = devm_create_dev_dax(dax_region, id, &res, 1);
134
135 /* child dev_dax instances now own the lifetime of the dax_region */
136 dax_region_put(dax_region);
137
138 return PTR_ERR_OR_ZERO(dev_dax);
139}
140
141static struct nd_device_driver dax_pmem_driver = {
142 .probe = dax_pmem_probe,
143 .drv = {
144 .name = "dax_pmem",
145 },
146 .type = ND_DRIVER_DAX_PMEM,
147};
148
149module_nd_driver(dax_pmem_driver);
150
151MODULE_LICENSE("GPL v2");
152MODULE_AUTHOR("Intel Corporation");
153MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM);
diff --git a/drivers/dax/pmem/Makefile b/drivers/dax/pmem/Makefile
new file mode 100644
index 000000000000..e2e79bd3fdcf
--- /dev/null
+++ b/drivers/dax/pmem/Makefile
@@ -0,0 +1,7 @@
1obj-$(CONFIG_DEV_DAX_PMEM) += dax_pmem.o
2obj-$(CONFIG_DEV_DAX_PMEM) += dax_pmem_core.o
3obj-$(CONFIG_DEV_DAX_PMEM_COMPAT) += dax_pmem_compat.o
4
5dax_pmem-y := pmem.o
6dax_pmem_core-y := core.o
7dax_pmem_compat-y := compat.o
diff --git a/drivers/dax/pmem/compat.c b/drivers/dax/pmem/compat.c
new file mode 100644
index 000000000000..d7b15e6f30c5
--- /dev/null
+++ b/drivers/dax/pmem/compat.c
@@ -0,0 +1,73 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
3#include <linux/percpu-refcount.h>
4#include <linux/memremap.h>
5#include <linux/module.h>
6#include <linux/pfn_t.h>
7#include <linux/nd.h>
8#include "../bus.h"
9
10/* we need the private definitions to implement compat suport */
11#include "../dax-private.h"
12
13static int dax_pmem_compat_probe(struct device *dev)
14{
15 struct dev_dax *dev_dax = __dax_pmem_probe(dev, DEV_DAX_CLASS);
16 int rc;
17
18 if (IS_ERR(dev_dax))
19 return PTR_ERR(dev_dax);
20
21 if (!devres_open_group(&dev_dax->dev, dev_dax, GFP_KERNEL))
22 return -ENOMEM;
23
24 device_lock(&dev_dax->dev);
25 rc = dev_dax_probe(&dev_dax->dev);
26 device_unlock(&dev_dax->dev);
27
28 devres_close_group(&dev_dax->dev, dev_dax);
29 if (rc)
30 devres_release_group(&dev_dax->dev, dev_dax);
31
32 return rc;
33}
34
35static int dax_pmem_compat_release(struct device *dev, void *data)
36{
37 device_lock(dev);
38 devres_release_group(dev, to_dev_dax(dev));
39 device_unlock(dev);
40
41 return 0;
42}
43
44static int dax_pmem_compat_remove(struct device *dev)
45{
46 device_for_each_child(dev, NULL, dax_pmem_compat_release);
47 return 0;
48}
49
50static struct nd_device_driver dax_pmem_compat_driver = {
51 .probe = dax_pmem_compat_probe,
52 .remove = dax_pmem_compat_remove,
53 .drv = {
54 .name = "dax_pmem_compat",
55 },
56 .type = ND_DRIVER_DAX_PMEM,
57};
58
59static int __init dax_pmem_compat_init(void)
60{
61 return nd_driver_register(&dax_pmem_compat_driver);
62}
63module_init(dax_pmem_compat_init);
64
65static void __exit dax_pmem_compat_exit(void)
66{
67 driver_unregister(&dax_pmem_compat_driver.drv);
68}
69module_exit(dax_pmem_compat_exit);
70
71MODULE_LICENSE("GPL v2");
72MODULE_AUTHOR("Intel Corporation");
73MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM);
diff --git a/drivers/dax/pmem/core.c b/drivers/dax/pmem/core.c
new file mode 100644
index 000000000000..f71019ce0647
--- /dev/null
+++ b/drivers/dax/pmem/core.c
@@ -0,0 +1,71 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
3#include <linux/memremap.h>
4#include <linux/module.h>
5#include <linux/pfn_t.h>
6#include "../../nvdimm/pfn.h"
7#include "../../nvdimm/nd.h"
8#include "../bus.h"
9
10struct dev_dax *__dax_pmem_probe(struct device *dev, enum dev_dax_subsys subsys)
11{
12 struct resource res;
13 int rc, id, region_id;
14 resource_size_t offset;
15 struct nd_pfn_sb *pfn_sb;
16 struct dev_dax *dev_dax;
17 struct nd_namespace_io *nsio;
18 struct dax_region *dax_region;
19 struct dev_pagemap pgmap = { 0 };
20 struct nd_namespace_common *ndns;
21 struct nd_dax *nd_dax = to_nd_dax(dev);
22 struct nd_pfn *nd_pfn = &nd_dax->nd_pfn;
23 struct nd_region *nd_region = to_nd_region(dev->parent);
24
25 ndns = nvdimm_namespace_common_probe(dev);
26 if (IS_ERR(ndns))
27 return ERR_CAST(ndns);
28 nsio = to_nd_namespace_io(&ndns->dev);
29
30 /* parse the 'pfn' info block via ->rw_bytes */
31 rc = devm_nsio_enable(dev, nsio);
32 if (rc)
33 return ERR_PTR(rc);
34 rc = nvdimm_setup_pfn(nd_pfn, &pgmap);
35 if (rc)
36 return ERR_PTR(rc);
37 devm_nsio_disable(dev, nsio);
38
39 /* reserve the metadata area, device-dax will reserve the data */
40 pfn_sb = nd_pfn->pfn_sb;
41 offset = le64_to_cpu(pfn_sb->dataoff);
42 if (!devm_request_mem_region(dev, nsio->res.start, offset,
43 dev_name(&ndns->dev))) {
44 dev_warn(dev, "could not reserve metadata\n");
45 return ERR_PTR(-EBUSY);
46 }
47
48 rc = sscanf(dev_name(&ndns->dev), "namespace%d.%d", &region_id, &id);
49 if (rc != 2)
50 return ERR_PTR(-EINVAL);
51
52 /* adjust the dax_region resource to the start of data */
53 memcpy(&res, &pgmap.res, sizeof(res));
54 res.start += offset;
55 dax_region = alloc_dax_region(dev, region_id, &res,
56 nd_region->target_node, le32_to_cpu(pfn_sb->align),
57 PFN_DEV|PFN_MAP);
58 if (!dax_region)
59 return ERR_PTR(-ENOMEM);
60
61 dev_dax = __devm_create_dev_dax(dax_region, id, &pgmap, subsys);
62
63 /* child dev_dax instances now own the lifetime of the dax_region */
64 dax_region_put(dax_region);
65
66 return dev_dax;
67}
68EXPORT_SYMBOL_GPL(__dax_pmem_probe);
69
70MODULE_LICENSE("GPL v2");
71MODULE_AUTHOR("Intel Corporation");
diff --git a/drivers/dax/pmem/pmem.c b/drivers/dax/pmem/pmem.c
new file mode 100644
index 000000000000..0ae4238a0ef8
--- /dev/null
+++ b/drivers/dax/pmem/pmem.c
@@ -0,0 +1,40 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */
3#include <linux/percpu-refcount.h>
4#include <linux/memremap.h>
5#include <linux/module.h>
6#include <linux/pfn_t.h>
7#include <linux/nd.h>
8#include "../bus.h"
9
10static int dax_pmem_probe(struct device *dev)
11{
12 return PTR_ERR_OR_ZERO(__dax_pmem_probe(dev, DEV_DAX_BUS));
13}
14
15static struct nd_device_driver dax_pmem_driver = {
16 .probe = dax_pmem_probe,
17 .drv = {
18 .name = "dax_pmem",
19 },
20 .type = ND_DRIVER_DAX_PMEM,
21};
22
23static int __init dax_pmem_init(void)
24{
25 return nd_driver_register(&dax_pmem_driver);
26}
27module_init(dax_pmem_init);
28
29static void __exit dax_pmem_exit(void)
30{
31 driver_unregister(&dax_pmem_driver.drv);
32}
33module_exit(dax_pmem_exit);
34
35MODULE_LICENSE("GPL v2");
36MODULE_AUTHOR("Intel Corporation");
37#if !IS_ENABLED(CONFIG_DEV_DAX_PMEM_COMPAT)
38/* For compat builds, don't load this module by default */
39MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM);
40#endif
diff --git a/drivers/dax/super.c b/drivers/dax/super.c
index 0cb8c30ea278..0a339b85133e 100644
--- a/drivers/dax/super.c
+++ b/drivers/dax/super.c
@@ -22,6 +22,7 @@
22#include <linux/uio.h> 22#include <linux/uio.h>
23#include <linux/dax.h> 23#include <linux/dax.h>
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include "dax-private.h"
25 26
26static dev_t dax_devt; 27static dev_t dax_devt;
27DEFINE_STATIC_SRCU(dax_srcu); 28DEFINE_STATIC_SRCU(dax_srcu);
@@ -383,11 +384,15 @@ void kill_dax(struct dax_device *dax_dev)
383 spin_lock(&dax_host_lock); 384 spin_lock(&dax_host_lock);
384 hlist_del_init(&dax_dev->list); 385 hlist_del_init(&dax_dev->list);
385 spin_unlock(&dax_host_lock); 386 spin_unlock(&dax_host_lock);
386
387 dax_dev->private = NULL;
388} 387}
389EXPORT_SYMBOL_GPL(kill_dax); 388EXPORT_SYMBOL_GPL(kill_dax);
390 389
390void run_dax(struct dax_device *dax_dev)
391{
392 set_bit(DAXDEV_ALIVE, &dax_dev->flags);
393}
394EXPORT_SYMBOL_GPL(run_dax);
395
391static struct inode *dax_alloc_inode(struct super_block *sb) 396static struct inode *dax_alloc_inode(struct super_block *sb)
392{ 397{
393 struct dax_device *dax_dev; 398 struct dax_device *dax_dev;
@@ -602,6 +607,8 @@ EXPORT_SYMBOL_GPL(dax_inode);
602 607
603void *dax_get_private(struct dax_device *dax_dev) 608void *dax_get_private(struct dax_device *dax_dev)
604{ 609{
610 if (!test_bit(DAXDEV_ALIVE, &dax_dev->flags))
611 return NULL;
605 return dax_dev->private; 612 return dax_dev->private;
606} 613}
607EXPORT_SYMBOL_GPL(dax_get_private); 614EXPORT_SYMBOL_GPL(dax_get_private);
@@ -615,7 +622,7 @@ static void init_once(void *_dax_dev)
615 inode_init_once(inode); 622 inode_init_once(inode);
616} 623}
617 624
618static int __dax_fs_init(void) 625static int dax_fs_init(void)
619{ 626{
620 int rc; 627 int rc;
621 628
@@ -647,35 +654,45 @@ static int __dax_fs_init(void)
647 return rc; 654 return rc;
648} 655}
649 656
650static void __dax_fs_exit(void) 657static void dax_fs_exit(void)
651{ 658{
652 kern_unmount(dax_mnt); 659 kern_unmount(dax_mnt);
653 unregister_filesystem(&dax_fs_type); 660 unregister_filesystem(&dax_fs_type);
654 kmem_cache_destroy(dax_cache); 661 kmem_cache_destroy(dax_cache);
655} 662}
656 663
657static int __init dax_fs_init(void) 664static int __init dax_core_init(void)
658{ 665{
659 int rc; 666 int rc;
660 667
661 rc = __dax_fs_init(); 668 rc = dax_fs_init();
662 if (rc) 669 if (rc)
663 return rc; 670 return rc;
664 671
665 rc = alloc_chrdev_region(&dax_devt, 0, MINORMASK+1, "dax"); 672 rc = alloc_chrdev_region(&dax_devt, 0, MINORMASK+1, "dax");
666 if (rc) 673 if (rc)
667 __dax_fs_exit(); 674 goto err_chrdev;
668 return rc; 675
676 rc = dax_bus_init();
677 if (rc)
678 goto err_bus;
679 return 0;
680
681err_bus:
682 unregister_chrdev_region(dax_devt, MINORMASK+1);
683err_chrdev:
684 dax_fs_exit();
685 return 0;
669} 686}
670 687
671static void __exit dax_fs_exit(void) 688static void __exit dax_core_exit(void)
672{ 689{
673 unregister_chrdev_region(dax_devt, MINORMASK+1); 690 unregister_chrdev_region(dax_devt, MINORMASK+1);
674 ida_destroy(&dax_minor_ida); 691 ida_destroy(&dax_minor_ida);
675 __dax_fs_exit(); 692 dax_fs_exit();
676} 693}
677 694
678MODULE_AUTHOR("Intel Corporation"); 695MODULE_AUTHOR("Intel Corporation");
679MODULE_LICENSE("GPL v2"); 696MODULE_LICENSE("GPL v2");
680subsys_initcall(dax_fs_init); 697subsys_initcall(dax_core_init);
681module_exit(dax_fs_exit); 698module_exit(dax_core_exit);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index ead851413c0a..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
@@ -947,10 +949,6 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
947 if (r) 949 if (r)
948 return r; 950 return r;
949 951
950 r = amdgpu_vm_clear_bo(adev, vm, pt, cursor.level, ats);
951 if (r)
952 goto error_free_pt;
953
954 if (vm->use_cpu_for_update) { 952 if (vm->use_cpu_for_update) {
955 r = amdgpu_bo_kmap(pt, NULL); 953 r = amdgpu_bo_kmap(pt, NULL);
956 if (r) 954 if (r)
@@ -963,6 +961,10 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
963 pt->parent = amdgpu_bo_ref(cursor.parent->base.bo); 961 pt->parent = amdgpu_bo_ref(cursor.parent->base.bo);
964 962
965 amdgpu_vm_bo_base_init(&entry->base, vm, pt); 963 amdgpu_vm_bo_base_init(&entry->base, vm, pt);
964
965 r = amdgpu_vm_clear_bo(adev, vm, pt, cursor.level, ats);
966 if (r)
967 goto error_free_pt;
966 } 968 }
967 969
968 return 0; 970 return 0;
@@ -3033,13 +3035,14 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
3033 if (r) 3035 if (r)
3034 goto error_unreserve; 3036 goto error_unreserve;
3035 3037
3038 amdgpu_vm_bo_base_init(&vm->root.base, vm, root);
3039
3036 r = amdgpu_vm_clear_bo(adev, vm, root, 3040 r = amdgpu_vm_clear_bo(adev, vm, root,
3037 adev->vm_manager.root_level, 3041 adev->vm_manager.root_level,
3038 vm->pte_support_ats); 3042 vm->pte_support_ats);
3039 if (r) 3043 if (r)
3040 goto error_unreserve; 3044 goto error_unreserve;
3041 3045
3042 amdgpu_vm_bo_base_init(&vm->root.base, vm, root);
3043 amdgpu_bo_unreserve(vm->root.base.bo); 3046 amdgpu_bo_unreserve(vm->root.base.bo);
3044 3047
3045 if (pasid) { 3048 if (pasid) {
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 5533f6e4f4a4..d0309e8c9d12 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -220,6 +220,7 @@ static const struct soc15_reg_golden golden_settings_gc_9_1_rv2[] =
220 220
221static const struct soc15_reg_golden golden_settings_gc_9_x_common[] = 221static const struct soc15_reg_golden golden_settings_gc_9_x_common[] =
222{ 222{
223 SOC15_REG_GOLDEN_VALUE(GC, 0, mmCP_SD_CNTL, 0xffffffff, 0x000001ff),
223 SOC15_REG_GOLDEN_VALUE(GC, 0, mmGRBM_CAM_INDEX, 0xffffffff, 0x00000000), 224 SOC15_REG_GOLDEN_VALUE(GC, 0, mmGRBM_CAM_INDEX, 0xffffffff, 0x00000000),
224 SOC15_REG_GOLDEN_VALUE(GC, 0, mmGRBM_CAM_DATA, 0xffffffff, 0x2544c382) 225 SOC15_REG_GOLDEN_VALUE(GC, 0, mmGRBM_CAM_DATA, 0xffffffff, 0x2544c382)
225}; 226};
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/amd/amdgpu/psp_v3_1.c b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c
index c63de945c021..0487e3a4e9e7 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c
@@ -500,9 +500,7 @@ static bool psp_v3_1_smu_reload_quirk(struct psp_context *psp)
500 struct amdgpu_device *adev = psp->adev; 500 struct amdgpu_device *adev = psp->adev;
501 uint32_t reg; 501 uint32_t reg;
502 502
503 reg = smnMP1_FIRMWARE_FLAGS | 0x03b00000; 503 reg = RREG32_PCIE(smnMP1_FIRMWARE_FLAGS | 0x03b00000);
504 WREG32_SOC15(NBIO, 0, mmPCIE_INDEX2, reg);
505 reg = RREG32_SOC15(NBIO, 0, mmPCIE_DATA2);
506 return (reg & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) ? true : false; 504 return (reg & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) ? true : false;
507} 505}
508 506
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 99ebcf29dcb0..ed89a101f73f 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -461,7 +461,6 @@ static int soc15_asic_reset(struct amdgpu_device *adev)
461 461
462 switch (adev->asic_type) { 462 switch (adev->asic_type) {
463 case CHIP_VEGA10: 463 case CHIP_VEGA10:
464 case CHIP_VEGA20:
465 soc15_asic_get_baco_capability(adev, &baco_reset); 464 soc15_asic_get_baco_capability(adev, &baco_reset);
466 break; 465 break;
467 default: 466 default:
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c
index 47243165a082..ae90a99909ef 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c
@@ -323,57 +323,7 @@ static int init_mqd_hiq(struct mqd_manager *mm, void **mqd,
323 struct kfd_mem_obj **mqd_mem_obj, uint64_t *gart_addr, 323 struct kfd_mem_obj **mqd_mem_obj, uint64_t *gart_addr,
324 struct queue_properties *q) 324 struct queue_properties *q)
325{ 325{
326 uint64_t addr; 326 return init_mqd(mm, mqd, mqd_mem_obj, gart_addr, q);
327 struct cik_mqd *m;
328 int retval;
329
330 retval = kfd_gtt_sa_allocate(mm->dev, sizeof(struct cik_mqd),
331 mqd_mem_obj);
332
333 if (retval != 0)
334 return -ENOMEM;
335
336 m = (struct cik_mqd *) (*mqd_mem_obj)->cpu_ptr;
337 addr = (*mqd_mem_obj)->gpu_addr;
338
339 memset(m, 0, ALIGN(sizeof(struct cik_mqd), 256));
340
341 m->header = 0xC0310800;
342 m->compute_pipelinestat_enable = 1;
343 m->compute_static_thread_mgmt_se0 = 0xFFFFFFFF;
344 m->compute_static_thread_mgmt_se1 = 0xFFFFFFFF;
345 m->compute_static_thread_mgmt_se2 = 0xFFFFFFFF;
346 m->compute_static_thread_mgmt_se3 = 0xFFFFFFFF;
347
348 m->cp_hqd_persistent_state = DEFAULT_CP_HQD_PERSISTENT_STATE |
349 PRELOAD_REQ;
350 m->cp_hqd_quantum = QUANTUM_EN | QUANTUM_SCALE_1MS |
351 QUANTUM_DURATION(10);
352
353 m->cp_mqd_control = MQD_CONTROL_PRIV_STATE_EN;
354 m->cp_mqd_base_addr_lo = lower_32_bits(addr);
355 m->cp_mqd_base_addr_hi = upper_32_bits(addr);
356
357 m->cp_hqd_ib_control = DEFAULT_MIN_IB_AVAIL_SIZE;
358
359 /*
360 * Pipe Priority
361 * Identifies the pipe relative priority when this queue is connected
362 * to the pipeline. The pipe priority is against the GFX pipe and HP3D.
363 * In KFD we are using a fixed pipe priority set to CS_MEDIUM.
364 * 0 = CS_LOW (typically below GFX)
365 * 1 = CS_MEDIUM (typically between HP3D and GFX
366 * 2 = CS_HIGH (typically above HP3D)
367 */
368 m->cp_hqd_pipe_priority = 1;
369 m->cp_hqd_queue_priority = 15;
370
371 *mqd = m;
372 if (gart_addr)
373 *gart_addr = addr;
374 retval = mm->update_mqd(mm, m, q);
375
376 return retval;
377} 327}
378 328
379static int update_mqd_hiq(struct mqd_manager *mm, void *mqd, 329static int update_mqd_hiq(struct mqd_manager *mm, void *mqd,
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 2f26581b93ff..fb27783d7a54 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -886,6 +886,7 @@ static void emulated_link_detect(struct dc_link *link)
886 return; 886 return;
887 } 887 }
888 888
889 /* dc_sink_create returns a new reference */
889 link->local_sink = sink; 890 link->local_sink = sink;
890 891
891 edid_status = dm_helpers_read_local_edid( 892 edid_status = dm_helpers_read_local_edid(
@@ -952,6 +953,8 @@ static int dm_resume(void *handle)
952 if (aconnector->fake_enable && aconnector->dc_link->local_sink) 953 if (aconnector->fake_enable && aconnector->dc_link->local_sink)
953 aconnector->fake_enable = false; 954 aconnector->fake_enable = false;
954 955
956 if (aconnector->dc_sink)
957 dc_sink_release(aconnector->dc_sink);
955 aconnector->dc_sink = NULL; 958 aconnector->dc_sink = NULL;
956 amdgpu_dm_update_connector_after_detect(aconnector); 959 amdgpu_dm_update_connector_after_detect(aconnector);
957 mutex_unlock(&aconnector->hpd_lock); 960 mutex_unlock(&aconnector->hpd_lock);
@@ -1061,6 +1064,8 @@ amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector)
1061 1064
1062 1065
1063 sink = aconnector->dc_link->local_sink; 1066 sink = aconnector->dc_link->local_sink;
1067 if (sink)
1068 dc_sink_retain(sink);
1064 1069
1065 /* 1070 /*
1066 * Edid mgmt connector gets first update only in mode_valid hook and then 1071 * Edid mgmt connector gets first update only in mode_valid hook and then
@@ -1085,21 +1090,24 @@ amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector)
1085 * to it anymore after disconnect, so on next crtc to connector 1090 * to it anymore after disconnect, so on next crtc to connector
1086 * reshuffle by UMD we will get into unwanted dc_sink release 1091 * reshuffle by UMD we will get into unwanted dc_sink release
1087 */ 1092 */
1088 if (aconnector->dc_sink != aconnector->dc_em_sink) 1093 dc_sink_release(aconnector->dc_sink);
1089 dc_sink_release(aconnector->dc_sink);
1090 } 1094 }
1091 aconnector->dc_sink = sink; 1095 aconnector->dc_sink = sink;
1096 dc_sink_retain(aconnector->dc_sink);
1092 amdgpu_dm_update_freesync_caps(connector, 1097 amdgpu_dm_update_freesync_caps(connector,
1093 aconnector->edid); 1098 aconnector->edid);
1094 } else { 1099 } else {
1095 amdgpu_dm_update_freesync_caps(connector, NULL); 1100 amdgpu_dm_update_freesync_caps(connector, NULL);
1096 if (!aconnector->dc_sink) 1101 if (!aconnector->dc_sink) {
1097 aconnector->dc_sink = aconnector->dc_em_sink; 1102 aconnector->dc_sink = aconnector->dc_em_sink;
1098 else if (aconnector->dc_sink != aconnector->dc_em_sink)
1099 dc_sink_retain(aconnector->dc_sink); 1103 dc_sink_retain(aconnector->dc_sink);
1104 }
1100 } 1105 }
1101 1106
1102 mutex_unlock(&dev->mode_config.mutex); 1107 mutex_unlock(&dev->mode_config.mutex);
1108
1109 if (sink)
1110 dc_sink_release(sink);
1103 return; 1111 return;
1104 } 1112 }
1105 1113
@@ -1107,8 +1115,10 @@ amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector)
1107 * TODO: temporary guard to look for proper fix 1115 * TODO: temporary guard to look for proper fix
1108 * if this sink is MST sink, we should not do anything 1116 * if this sink is MST sink, we should not do anything
1109 */ 1117 */
1110 if (sink && sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT_MST) 1118 if (sink && sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
1119 dc_sink_release(sink);
1111 return; 1120 return;
1121 }
1112 1122
1113 if (aconnector->dc_sink == sink) { 1123 if (aconnector->dc_sink == sink) {
1114 /* 1124 /*
@@ -1117,6 +1127,8 @@ amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector)
1117 */ 1127 */
1118 DRM_DEBUG_DRIVER("DCHPD: connector_id=%d: dc_sink didn't change.\n", 1128 DRM_DEBUG_DRIVER("DCHPD: connector_id=%d: dc_sink didn't change.\n",
1119 aconnector->connector_id); 1129 aconnector->connector_id);
1130 if (sink)
1131 dc_sink_release(sink);
1120 return; 1132 return;
1121 } 1133 }
1122 1134
@@ -1138,6 +1150,7 @@ amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector)
1138 amdgpu_dm_update_freesync_caps(connector, NULL); 1150 amdgpu_dm_update_freesync_caps(connector, NULL);
1139 1151
1140 aconnector->dc_sink = sink; 1152 aconnector->dc_sink = sink;
1153 dc_sink_retain(aconnector->dc_sink);
1141 if (sink->dc_edid.length == 0) { 1154 if (sink->dc_edid.length == 0) {
1142 aconnector->edid = NULL; 1155 aconnector->edid = NULL;
1143 drm_dp_cec_unset_edid(&aconnector->dm_dp_aux.aux); 1156 drm_dp_cec_unset_edid(&aconnector->dm_dp_aux.aux);
@@ -1158,11 +1171,15 @@ amdgpu_dm_update_connector_after_detect(struct amdgpu_dm_connector *aconnector)
1158 amdgpu_dm_update_freesync_caps(connector, NULL); 1171 amdgpu_dm_update_freesync_caps(connector, NULL);
1159 drm_connector_update_edid_property(connector, NULL); 1172 drm_connector_update_edid_property(connector, NULL);
1160 aconnector->num_modes = 0; 1173 aconnector->num_modes = 0;
1174 dc_sink_release(aconnector->dc_sink);
1161 aconnector->dc_sink = NULL; 1175 aconnector->dc_sink = NULL;
1162 aconnector->edid = NULL; 1176 aconnector->edid = NULL;
1163 } 1177 }
1164 1178
1165 mutex_unlock(&dev->mode_config.mutex); 1179 mutex_unlock(&dev->mode_config.mutex);
1180
1181 if (sink)
1182 dc_sink_release(sink);
1166} 1183}
1167 1184
1168static void handle_hpd_irq(void *param) 1185static void handle_hpd_irq(void *param)
@@ -2977,6 +2994,7 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,
2977 return stream; 2994 return stream;
2978 } else { 2995 } else {
2979 sink = aconnector->dc_sink; 2996 sink = aconnector->dc_sink;
2997 dc_sink_retain(sink);
2980 } 2998 }
2981 2999
2982 stream = dc_create_stream_for_sink(sink); 3000 stream = dc_create_stream_for_sink(sink);
@@ -3042,8 +3060,7 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,
3042 update_stream_signal(stream, sink); 3060 update_stream_signal(stream, sink);
3043 3061
3044finish: 3062finish:
3045 if (sink && sink->sink_signal == SIGNAL_TYPE_VIRTUAL && aconnector->base.force != DRM_FORCE_ON) 3063 dc_sink_release(sink);
3046 dc_sink_release(sink);
3047 3064
3048 return stream; 3065 return stream;
3049} 3066}
@@ -3301,6 +3318,14 @@ static void amdgpu_dm_connector_destroy(struct drm_connector *connector)
3301 dm->backlight_dev = NULL; 3318 dm->backlight_dev = NULL;
3302 } 3319 }
3303#endif 3320#endif
3321
3322 if (aconnector->dc_em_sink)
3323 dc_sink_release(aconnector->dc_em_sink);
3324 aconnector->dc_em_sink = NULL;
3325 if (aconnector->dc_sink)
3326 dc_sink_release(aconnector->dc_sink);
3327 aconnector->dc_sink = NULL;
3328
3304 drm_dp_cec_unregister_connector(&aconnector->dm_dp_aux.aux); 3329 drm_dp_cec_unregister_connector(&aconnector->dm_dp_aux.aux);
3305 drm_connector_unregister(connector); 3330 drm_connector_unregister(connector);
3306 drm_connector_cleanup(connector); 3331 drm_connector_cleanup(connector);
@@ -3398,10 +3423,12 @@ static void create_eml_sink(struct amdgpu_dm_connector *aconnector)
3398 (edid->extensions + 1) * EDID_LENGTH, 3423 (edid->extensions + 1) * EDID_LENGTH,
3399 &init_params); 3424 &init_params);
3400 3425
3401 if (aconnector->base.force == DRM_FORCE_ON) 3426 if (aconnector->base.force == DRM_FORCE_ON) {
3402 aconnector->dc_sink = aconnector->dc_link->local_sink ? 3427 aconnector->dc_sink = aconnector->dc_link->local_sink ?
3403 aconnector->dc_link->local_sink : 3428 aconnector->dc_link->local_sink :
3404 aconnector->dc_em_sink; 3429 aconnector->dc_em_sink;
3430 dc_sink_retain(aconnector->dc_sink);
3431 }
3405} 3432}
3406 3433
3407static void handle_edid_mgmt(struct amdgpu_dm_connector *aconnector) 3434static void handle_edid_mgmt(struct amdgpu_dm_connector *aconnector)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index f51d52eb52e6..c4ea3a91f17a 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -191,6 +191,7 @@ static int dm_dp_mst_get_modes(struct drm_connector *connector)
191 &init_params); 191 &init_params);
192 192
193 dc_sink->priv = aconnector; 193 dc_sink->priv = aconnector;
194 /* dc_link_add_remote_sink returns a new reference */
194 aconnector->dc_sink = dc_sink; 195 aconnector->dc_sink = dc_sink;
195 196
196 if (aconnector->dc_sink) 197 if (aconnector->dc_sink)
diff --git a/drivers/gpu/drm/amd/display/dc/calcs/dcn_calcs.c b/drivers/gpu/drm/amd/display/dc/calcs/dcn_calcs.c
index 12d1842079ae..eb62d10bb65c 100644
--- a/drivers/gpu/drm/amd/display/dc/calcs/dcn_calcs.c
+++ b/drivers/gpu/drm/amd/display/dc/calcs/dcn_calcs.c
@@ -1348,12 +1348,12 @@ void dcn_bw_update_from_pplib(struct dc *dc)
1348 struct dm_pp_clock_levels_with_voltage fclks = {0}, dcfclks = {0}; 1348 struct dm_pp_clock_levels_with_voltage fclks = {0}, dcfclks = {0};
1349 bool res; 1349 bool res;
1350 1350
1351 kernel_fpu_begin();
1352
1353 /* TODO: This is not the proper way to obtain fabric_and_dram_bandwidth, should be min(fclk, memclk) */ 1351 /* TODO: This is not the proper way to obtain fabric_and_dram_bandwidth, should be min(fclk, memclk) */
1354 res = dm_pp_get_clock_levels_by_type_with_voltage( 1352 res = dm_pp_get_clock_levels_by_type_with_voltage(
1355 ctx, DM_PP_CLOCK_TYPE_FCLK, &fclks); 1353 ctx, DM_PP_CLOCK_TYPE_FCLK, &fclks);
1356 1354
1355 kernel_fpu_begin();
1356
1357 if (res) 1357 if (res)
1358 res = verify_clock_values(&fclks); 1358 res = verify_clock_values(&fclks);
1359 1359
@@ -1372,9 +1372,13 @@ void dcn_bw_update_from_pplib(struct dc *dc)
1372 } else 1372 } else
1373 BREAK_TO_DEBUGGER(); 1373 BREAK_TO_DEBUGGER();
1374 1374
1375 kernel_fpu_end();
1376
1375 res = dm_pp_get_clock_levels_by_type_with_voltage( 1377 res = dm_pp_get_clock_levels_by_type_with_voltage(
1376 ctx, DM_PP_CLOCK_TYPE_DCFCLK, &dcfclks); 1378 ctx, DM_PP_CLOCK_TYPE_DCFCLK, &dcfclks);
1377 1379
1380 kernel_fpu_begin();
1381
1378 if (res) 1382 if (res)
1379 res = verify_clock_values(&dcfclks); 1383 res = verify_clock_values(&dcfclks);
1380 1384
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link.c b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
index 7f5a947ad31d..4eba3c4800b6 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
@@ -794,6 +794,7 @@ bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
794 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock; 794 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock;
795 sink->converter_disable_audio = converter_disable_audio; 795 sink->converter_disable_audio = converter_disable_audio;
796 796
797 /* dc_sink_create returns a new reference */
797 link->local_sink = sink; 798 link->local_sink = sink;
798 799
799 edid_status = dm_helpers_read_local_edid( 800 edid_status = dm_helpers_read_local_edid(
@@ -2037,6 +2038,9 @@ static enum dc_status enable_link(
2037 break; 2038 break;
2038 } 2039 }
2039 2040
2041 if (status == DC_OK)
2042 pipe_ctx->stream->link->link_status.link_active = true;
2043
2040 return status; 2044 return status;
2041} 2045}
2042 2046
@@ -2060,6 +2064,14 @@ static void disable_link(struct dc_link *link, enum signal_type signal)
2060 dp_disable_link_phy_mst(link, signal); 2064 dp_disable_link_phy_mst(link, signal);
2061 } else 2065 } else
2062 link->link_enc->funcs->disable_output(link->link_enc, signal); 2066 link->link_enc->funcs->disable_output(link->link_enc, signal);
2067
2068 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2069 /* MST disable link only when no stream use the link */
2070 if (link->mst_stream_alloc_table.stream_count <= 0)
2071 link->link_status.link_active = false;
2072 } else {
2073 link->link_status.link_active = false;
2074 }
2063} 2075}
2064 2076
2065static bool dp_active_dongle_validate_timing( 2077static bool dp_active_dongle_validate_timing(
@@ -2623,8 +2635,6 @@ void core_link_enable_stream(
2623 } 2635 }
2624 } 2636 }
2625 2637
2626 stream->link->link_status.link_active = true;
2627
2628 core_dc->hwss.enable_audio_stream(pipe_ctx); 2638 core_dc->hwss.enable_audio_stream(pipe_ctx);
2629 2639
2630 /* turn off otg test pattern if enable */ 2640 /* turn off otg test pattern if enable */
@@ -2659,8 +2669,6 @@ void core_link_disable_stream(struct pipe_ctx *pipe_ctx, int option)
2659 core_dc->hwss.disable_stream(pipe_ctx, option); 2669 core_dc->hwss.disable_stream(pipe_ctx, option);
2660 2670
2661 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal); 2671 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
2662
2663 pipe_ctx->stream->link->link_status.link_active = false;
2664} 2672}
2665 2673
2666void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable) 2674void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
diff --git a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
index 94a84bc57c7a..bfd27f10879e 100644
--- a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
+++ b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
@@ -724,7 +724,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
724 724
725static void build_vrr_infopacket_v2(enum signal_type signal, 725static void build_vrr_infopacket_v2(enum signal_type signal,
726 const struct mod_vrr_params *vrr, 726 const struct mod_vrr_params *vrr,
727 const enum color_transfer_func *app_tf, 727 enum color_transfer_func app_tf,
728 struct dc_info_packet *infopacket) 728 struct dc_info_packet *infopacket)
729{ 729{
730 unsigned int payload_size = 0; 730 unsigned int payload_size = 0;
@@ -732,8 +732,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
732 build_vrr_infopacket_header_v2(signal, infopacket, &payload_size); 732 build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
733 build_vrr_infopacket_data(vrr, infopacket); 733 build_vrr_infopacket_data(vrr, infopacket);
734 734
735 if (app_tf != NULL) 735 build_vrr_infopacket_fs2_data(app_tf, infopacket);
736 build_vrr_infopacket_fs2_data(*app_tf, infopacket);
737 736
738 build_vrr_infopacket_checksum(&payload_size, infopacket); 737 build_vrr_infopacket_checksum(&payload_size, infopacket);
739 738
@@ -757,7 +756,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
757 const struct dc_stream_state *stream, 756 const struct dc_stream_state *stream,
758 const struct mod_vrr_params *vrr, 757 const struct mod_vrr_params *vrr,
759 enum vrr_packet_type packet_type, 758 enum vrr_packet_type packet_type,
760 const enum color_transfer_func *app_tf, 759 enum color_transfer_func app_tf,
761 struct dc_info_packet *infopacket) 760 struct dc_info_packet *infopacket)
762{ 761{
763 /* SPD info packet for FreeSync 762 /* SPD info packet for FreeSync
diff --git a/drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h b/drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h
index 4222e403b151..dcef85994c45 100644
--- a/drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h
+++ b/drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
145 const struct dc_stream_state *stream, 145 const struct dc_stream_state *stream,
146 const struct mod_vrr_params *vrr, 146 const struct mod_vrr_params *vrr,
147 enum vrr_packet_type packet_type, 147 enum vrr_packet_type packet_type,
148 const enum color_transfer_func *app_tf, 148 enum color_transfer_func app_tf,
149 struct dc_info_packet *infopacket); 149 struct dc_info_packet *infopacket);
150 150
151void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, 151void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
index ce177d7f04cb..6bf48934fdc4 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
@@ -277,8 +277,7 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, bool skip_display_set
277 if (!skip_display_settings) 277 if (!skip_display_settings)
278 phm_notify_smc_display_config_after_ps_adjustment(hwmgr); 278 phm_notify_smc_display_config_after_ps_adjustment(hwmgr);
279 279
280 if ((hwmgr->request_dpm_level != hwmgr->dpm_level) && 280 if (!phm_force_dpm_levels(hwmgr, hwmgr->request_dpm_level))
281 !phm_force_dpm_levels(hwmgr, hwmgr->request_dpm_level))
282 hwmgr->dpm_level = hwmgr->request_dpm_level; 281 hwmgr->dpm_level = hwmgr->request_dpm_level;
283 282
284 if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) { 283 if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
index 4588bddf8b33..615cf2c09e54 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
@@ -489,15 +489,16 @@ int pp_atomfwctrl_get_gpio_information(struct pp_hwmgr *hwmgr,
489} 489}
490 490
491int pp_atomfwctrl_get_clk_information_by_clkid(struct pp_hwmgr *hwmgr, 491int pp_atomfwctrl_get_clk_information_by_clkid(struct pp_hwmgr *hwmgr,
492 uint8_t id, uint32_t *frequency) 492 uint8_t clk_id, uint8_t syspll_id,
493 uint32_t *frequency)
493{ 494{
494 struct amdgpu_device *adev = hwmgr->adev; 495 struct amdgpu_device *adev = hwmgr->adev;
495 struct atom_get_smu_clock_info_parameters_v3_1 parameters; 496 struct atom_get_smu_clock_info_parameters_v3_1 parameters;
496 struct atom_get_smu_clock_info_output_parameters_v3_1 *output; 497 struct atom_get_smu_clock_info_output_parameters_v3_1 *output;
497 uint32_t ix; 498 uint32_t ix;
498 499
499 parameters.clk_id = id; 500 parameters.clk_id = clk_id;
500 parameters.syspll_id = 0; 501 parameters.syspll_id = syspll_id;
501 parameters.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ; 502 parameters.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
502 parameters.dfsdid = 0; 503 parameters.dfsdid = 0;
503 504
@@ -530,20 +531,23 @@ static void pp_atomfwctrl_copy_vbios_bootup_values_3_2(struct pp_hwmgr *hwmgr,
530 boot_values->ulSocClk = 0; 531 boot_values->ulSocClk = 0;
531 boot_values->ulDCEFClk = 0; 532 boot_values->ulDCEFClk = 0;
532 533
533 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_SOCCLK_ID, &frequency)) 534 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_SOCCLK_ID, SMU11_SYSPLL0_ID, &frequency))
534 boot_values->ulSocClk = frequency; 535 boot_values->ulSocClk = frequency;
535 536
536 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_DCEFCLK_ID, &frequency)) 537 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_DCEFCLK_ID, SMU11_SYSPLL0_ID, &frequency))
537 boot_values->ulDCEFClk = frequency; 538 boot_values->ulDCEFClk = frequency;
538 539
539 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_ECLK_ID, &frequency)) 540 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_ECLK_ID, SMU11_SYSPLL0_ID, &frequency))
540 boot_values->ulEClk = frequency; 541 boot_values->ulEClk = frequency;
541 542
542 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_VCLK_ID, &frequency)) 543 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_VCLK_ID, SMU11_SYSPLL0_ID, &frequency))
543 boot_values->ulVClk = frequency; 544 boot_values->ulVClk = frequency;
544 545
545 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_DCLK_ID, &frequency)) 546 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL0_DCLK_ID, SMU11_SYSPLL0_ID, &frequency))
546 boot_values->ulDClk = frequency; 547 boot_values->ulDClk = frequency;
548
549 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU11_SYSPLL1_0_FCLK_ID, SMU11_SYSPLL1_2_ID, &frequency))
550 boot_values->ulFClk = frequency;
547} 551}
548 552
549static void pp_atomfwctrl_copy_vbios_bootup_values_3_1(struct pp_hwmgr *hwmgr, 553static void pp_atomfwctrl_copy_vbios_bootup_values_3_1(struct pp_hwmgr *hwmgr,
@@ -563,19 +567,19 @@ static void pp_atomfwctrl_copy_vbios_bootup_values_3_1(struct pp_hwmgr *hwmgr,
563 boot_values->ulSocClk = 0; 567 boot_values->ulSocClk = 0;
564 boot_values->ulDCEFClk = 0; 568 boot_values->ulDCEFClk = 0;
565 569
566 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_SOCCLK_ID, &frequency)) 570 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_SOCCLK_ID, 0, &frequency))
567 boot_values->ulSocClk = frequency; 571 boot_values->ulSocClk = frequency;
568 572
569 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_DCEFCLK_ID, &frequency)) 573 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_DCEFCLK_ID, 0, &frequency))
570 boot_values->ulDCEFClk = frequency; 574 boot_values->ulDCEFClk = frequency;
571 575
572 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_ECLK_ID, &frequency)) 576 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_ECLK_ID, 0, &frequency))
573 boot_values->ulEClk = frequency; 577 boot_values->ulEClk = frequency;
574 578
575 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_VCLK_ID, &frequency)) 579 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_VCLK_ID, 0, &frequency))
576 boot_values->ulVClk = frequency; 580 boot_values->ulVClk = frequency;
577 581
578 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_DCLK_ID, &frequency)) 582 if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, SMU9_SYSPLL0_DCLK_ID, 0, &frequency))
579 boot_values->ulDClk = frequency; 583 boot_values->ulDClk = frequency;
580} 584}
581 585
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
index fe9e8ceef50e..b7e2651b570b 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
@@ -139,6 +139,7 @@ struct pp_atomfwctrl_bios_boot_up_values {
139 uint32_t ulEClk; 139 uint32_t ulEClk;
140 uint32_t ulVClk; 140 uint32_t ulVClk;
141 uint32_t ulDClk; 141 uint32_t ulDClk;
142 uint32_t ulFClk;
142 uint16_t usVddc; 143 uint16_t usVddc;
143 uint16_t usVddci; 144 uint16_t usVddci;
144 uint16_t usMvddc; 145 uint16_t usMvddc;
@@ -236,7 +237,8 @@ int pp_atomfwctrl_get_vbios_bootup_values(struct pp_hwmgr *hwmgr,
236int pp_atomfwctrl_get_smc_dpm_information(struct pp_hwmgr *hwmgr, 237int pp_atomfwctrl_get_smc_dpm_information(struct pp_hwmgr *hwmgr,
237 struct pp_atomfwctrl_smc_dpm_parameters *param); 238 struct pp_atomfwctrl_smc_dpm_parameters *param);
238int pp_atomfwctrl_get_clk_information_by_clkid(struct pp_hwmgr *hwmgr, 239int pp_atomfwctrl_get_clk_information_by_clkid(struct pp_hwmgr *hwmgr,
239 uint8_t id, uint32_t *frequency); 240 uint8_t clk_id, uint8_t syspll_id,
241 uint32_t *frequency);
240 242
241#endif 243#endif
242 244
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
index 48187acac59e..83d3d935f3ac 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
@@ -3491,14 +3491,14 @@ static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr, u32 *query)
3491 3491
3492 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogStart); 3492 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogStart);
3493 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, 3493 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3494 ixSMU_PM_STATUS_94, 0); 3494 ixSMU_PM_STATUS_95, 0);
3495 3495
3496 for (i = 0; i < 10; i++) { 3496 for (i = 0; i < 10; i++) {
3497 mdelay(1); 3497 mdelay(500);
3498 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogSample); 3498 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogSample);
3499 tmp = cgs_read_ind_register(hwmgr->device, 3499 tmp = cgs_read_ind_register(hwmgr->device,
3500 CGS_IND_REG__SMC, 3500 CGS_IND_REG__SMC,
3501 ixSMU_PM_STATUS_94); 3501 ixSMU_PM_STATUS_95);
3502 if (tmp != 0) 3502 if (tmp != 0)
3503 break; 3503 break;
3504 } 3504 }
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
index 5479125ff4f6..5c4f701939ea 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
@@ -2575,10 +2575,10 @@ static int vega10_init_smc_table(struct pp_hwmgr *hwmgr)
2575 data->vbios_boot_state.gfx_clock = boot_up_values.ulGfxClk; 2575 data->vbios_boot_state.gfx_clock = boot_up_values.ulGfxClk;
2576 data->vbios_boot_state.mem_clock = boot_up_values.ulUClk; 2576 data->vbios_boot_state.mem_clock = boot_up_values.ulUClk;
2577 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 2577 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr,
2578 SMU9_SYSPLL0_SOCCLK_ID, &boot_up_values.ulSocClk); 2578 SMU9_SYSPLL0_SOCCLK_ID, 0, &boot_up_values.ulSocClk);
2579 2579
2580 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 2580 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr,
2581 SMU9_SYSPLL0_DCEFCLK_ID, &boot_up_values.ulDCEFClk); 2581 SMU9_SYSPLL0_DCEFCLK_ID, 0, &boot_up_values.ulDCEFClk);
2582 2582
2583 data->vbios_boot_state.soc_clock = boot_up_values.ulSocClk; 2583 data->vbios_boot_state.soc_clock = boot_up_values.ulSocClk;
2584 data->vbios_boot_state.dcef_clock = boot_up_values.ulDCEFClk; 2584 data->vbios_boot_state.dcef_clock = boot_up_values.ulDCEFClk;
@@ -4407,9 +4407,9 @@ static int vega10_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t new_ppfe
4407 return ret; 4407 return ret;
4408 4408
4409 features_to_disable = 4409 features_to_disable =
4410 (features_enabled ^ new_ppfeature_masks) & features_enabled; 4410 features_enabled & ~new_ppfeature_masks;
4411 features_to_enable = 4411 features_to_enable =
4412 (features_enabled ^ new_ppfeature_masks) ^ features_to_disable; 4412 ~features_enabled & new_ppfeature_masks;
4413 4413
4414 pr_debug("features_to_disable 0x%llx\n", features_to_disable); 4414 pr_debug("features_to_disable 0x%llx\n", features_to_disable);
4415 pr_debug("features_to_enable 0x%llx\n", features_to_enable); 4415 pr_debug("features_to_enable 0x%llx\n", features_to_enable);
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
index 6c8e78611c03..bdb48e94eff6 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
@@ -2009,9 +2009,9 @@ static int vega12_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t new_ppfe
2009 return ret; 2009 return ret;
2010 2010
2011 features_to_disable = 2011 features_to_disable =
2012 (features_enabled ^ new_ppfeature_masks) & features_enabled; 2012 features_enabled & ~new_ppfeature_masks;
2013 features_to_enable = 2013 features_to_enable =
2014 (features_enabled ^ new_ppfeature_masks) ^ features_to_disable; 2014 ~features_enabled & new_ppfeature_masks;
2015 2015
2016 pr_debug("features_to_disable 0x%llx\n", features_to_disable); 2016 pr_debug("features_to_disable 0x%llx\n", features_to_disable);
2017 pr_debug("features_to_enable 0x%llx\n", features_to_enable); 2017 pr_debug("features_to_enable 0x%llx\n", features_to_enable);
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index aad79affb081..9aa7bec1b5fe 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -463,9 +463,9 @@ static int vega20_setup_asic_task(struct pp_hwmgr *hwmgr)
463static void vega20_init_dpm_state(struct vega20_dpm_state *dpm_state) 463static void vega20_init_dpm_state(struct vega20_dpm_state *dpm_state)
464{ 464{
465 dpm_state->soft_min_level = 0x0; 465 dpm_state->soft_min_level = 0x0;
466 dpm_state->soft_max_level = 0xffff; 466 dpm_state->soft_max_level = VG20_CLOCK_MAX_DEFAULT;
467 dpm_state->hard_min_level = 0x0; 467 dpm_state->hard_min_level = 0x0;
468 dpm_state->hard_max_level = 0xffff; 468 dpm_state->hard_max_level = VG20_CLOCK_MAX_DEFAULT;
469} 469}
470 470
471static int vega20_get_number_of_dpm_level(struct pp_hwmgr *hwmgr, 471static int vega20_get_number_of_dpm_level(struct pp_hwmgr *hwmgr,
@@ -711,8 +711,10 @@ static int vega20_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
711 PP_ASSERT_WITH_CODE(!ret, 711 PP_ASSERT_WITH_CODE(!ret,
712 "[SetupDefaultDpmTable] failed to get fclk dpm levels!", 712 "[SetupDefaultDpmTable] failed to get fclk dpm levels!",
713 return ret); 713 return ret);
714 } else 714 } else {
715 dpm_table->count = 0; 715 dpm_table->count = 1;
716 dpm_table->dpm_levels[0].value = data->vbios_boot_state.fclock / 100;
717 }
716 vega20_init_dpm_state(&(dpm_table->dpm_state)); 718 vega20_init_dpm_state(&(dpm_table->dpm_state));
717 719
718 /* save a copy of the default DPM table */ 720 /* save a copy of the default DPM table */
@@ -754,6 +756,7 @@ static int vega20_init_smc_table(struct pp_hwmgr *hwmgr)
754 data->vbios_boot_state.eclock = boot_up_values.ulEClk; 756 data->vbios_boot_state.eclock = boot_up_values.ulEClk;
755 data->vbios_boot_state.vclock = boot_up_values.ulVClk; 757 data->vbios_boot_state.vclock = boot_up_values.ulVClk;
756 data->vbios_boot_state.dclock = boot_up_values.ulDClk; 758 data->vbios_boot_state.dclock = boot_up_values.ulDClk;
759 data->vbios_boot_state.fclock = boot_up_values.ulFClk;
757 data->vbios_boot_state.uc_cooling_id = boot_up_values.ucCoolingID; 760 data->vbios_boot_state.uc_cooling_id = boot_up_values.ucCoolingID;
758 761
759 smum_send_msg_to_smc_with_parameter(hwmgr, 762 smum_send_msg_to_smc_with_parameter(hwmgr,
@@ -780,6 +783,8 @@ static int vega20_init_smc_table(struct pp_hwmgr *hwmgr)
780static int vega20_override_pcie_parameters(struct pp_hwmgr *hwmgr) 783static int vega20_override_pcie_parameters(struct pp_hwmgr *hwmgr)
781{ 784{
782 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev); 785 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
786 struct vega20_hwmgr *data =
787 (struct vega20_hwmgr *)(hwmgr->backend);
783 uint32_t pcie_gen = 0, pcie_width = 0, smu_pcie_arg; 788 uint32_t pcie_gen = 0, pcie_width = 0, smu_pcie_arg;
784 int ret; 789 int ret;
785 790
@@ -816,6 +821,10 @@ static int vega20_override_pcie_parameters(struct pp_hwmgr *hwmgr)
816 "[OverridePcieParameters] Attempt to override pcie params failed!", 821 "[OverridePcieParameters] Attempt to override pcie params failed!",
817 return ret); 822 return ret);
818 823
824 data->pcie_parameters_override = 1;
825 data->pcie_gen_level1 = pcie_gen;
826 data->pcie_width_level1 = pcie_width;
827
819 return 0; 828 return 0;
820} 829}
821 830
@@ -979,6 +988,8 @@ static int vega20_od8_set_feature_capabilities(
979 } 988 }
980 989
981 if (data->smu_features[GNLD_DPM_UCLK].enabled) { 990 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
991 pptable_information->od_settings_min[OD8_SETTING_UCLK_FMAX] =
992 data->dpm_table.mem_table.dpm_levels[data->dpm_table.mem_table.count - 2].value;
982 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_UCLK_MAX] && 993 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_UCLK_MAX] &&
983 pptable_information->od_settings_min[OD8_SETTING_UCLK_FMAX] > 0 && 994 pptable_information->od_settings_min[OD8_SETTING_UCLK_FMAX] > 0 &&
984 pptable_information->od_settings_max[OD8_SETTING_UCLK_FMAX] > 0 && 995 pptable_information->od_settings_max[OD8_SETTING_UCLK_FMAX] > 0 &&
@@ -2314,32 +2325,8 @@ static int vega20_force_dpm_lowest(struct pp_hwmgr *hwmgr)
2314 2325
2315static int vega20_unforce_dpm_levels(struct pp_hwmgr *hwmgr) 2326static int vega20_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
2316{ 2327{
2317 struct vega20_hwmgr *data =
2318 (struct vega20_hwmgr *)(hwmgr->backend);
2319 uint32_t soft_min_level, soft_max_level;
2320 int ret = 0; 2328 int ret = 0;
2321 2329
2322 soft_min_level = vega20_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
2323 soft_max_level = vega20_find_highest_dpm_level(&(data->dpm_table.gfx_table));
2324 data->dpm_table.gfx_table.dpm_state.soft_min_level =
2325 data->dpm_table.gfx_table.dpm_levels[soft_min_level].value;
2326 data->dpm_table.gfx_table.dpm_state.soft_max_level =
2327 data->dpm_table.gfx_table.dpm_levels[soft_max_level].value;
2328
2329 soft_min_level = vega20_find_lowest_dpm_level(&(data->dpm_table.mem_table));
2330 soft_max_level = vega20_find_highest_dpm_level(&(data->dpm_table.mem_table));
2331 data->dpm_table.mem_table.dpm_state.soft_min_level =
2332 data->dpm_table.mem_table.dpm_levels[soft_min_level].value;
2333 data->dpm_table.mem_table.dpm_state.soft_max_level =
2334 data->dpm_table.mem_table.dpm_levels[soft_max_level].value;
2335
2336 soft_min_level = vega20_find_lowest_dpm_level(&(data->dpm_table.soc_table));
2337 soft_max_level = vega20_find_highest_dpm_level(&(data->dpm_table.soc_table));
2338 data->dpm_table.soc_table.dpm_state.soft_min_level =
2339 data->dpm_table.soc_table.dpm_levels[soft_min_level].value;
2340 data->dpm_table.soc_table.dpm_state.soft_max_level =
2341 data->dpm_table.soc_table.dpm_levels[soft_max_level].value;
2342
2343 ret = vega20_upload_dpm_min_level(hwmgr, 0xFFFFFFFF); 2330 ret = vega20_upload_dpm_min_level(hwmgr, 0xFFFFFFFF);
2344 PP_ASSERT_WITH_CODE(!ret, 2331 PP_ASSERT_WITH_CODE(!ret,
2345 "Failed to upload DPM Bootup Levels!", 2332 "Failed to upload DPM Bootup Levels!",
@@ -2641,9 +2628,8 @@ static int vega20_get_sclks(struct pp_hwmgr *hwmgr,
2641 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.gfx_table); 2628 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.gfx_table);
2642 int i, count; 2629 int i, count;
2643 2630
2644 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_GFXCLK].enabled, 2631 if (!data->smu_features[GNLD_DPM_GFXCLK].enabled)
2645 "[GetSclks]: gfxclk dpm not enabled!\n", 2632 return -1;
2646 return -EPERM);
2647 2633
2648 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count; 2634 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2649 clocks->num_levels = count; 2635 clocks->num_levels = count;
@@ -2670,9 +2656,8 @@ static int vega20_get_memclocks(struct pp_hwmgr *hwmgr,
2670 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.mem_table); 2656 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.mem_table);
2671 int i, count; 2657 int i, count;
2672 2658
2673 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_UCLK].enabled, 2659 if (!data->smu_features[GNLD_DPM_UCLK].enabled)
2674 "[GetMclks]: uclk dpm not enabled!\n", 2660 return -1;
2675 return -EPERM);
2676 2661
2677 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count; 2662 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2678 clocks->num_levels = data->mclk_latency_table.count = count; 2663 clocks->num_levels = data->mclk_latency_table.count = count;
@@ -2696,9 +2681,8 @@ static int vega20_get_dcefclocks(struct pp_hwmgr *hwmgr,
2696 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.dcef_table); 2681 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.dcef_table);
2697 int i, count; 2682 int i, count;
2698 2683
2699 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_DCEFCLK].enabled, 2684 if (!data->smu_features[GNLD_DPM_DCEFCLK].enabled)
2700 "[GetDcfclocks]: dcefclk dpm not enabled!\n", 2685 return -1;
2701 return -EPERM);
2702 2686
2703 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count; 2687 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2704 clocks->num_levels = count; 2688 clocks->num_levels = count;
@@ -2719,9 +2703,8 @@ static int vega20_get_socclocks(struct pp_hwmgr *hwmgr,
2719 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.soc_table); 2703 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.soc_table);
2720 int i, count; 2704 int i, count;
2721 2705
2722 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_SOCCLK].enabled, 2706 if (!data->smu_features[GNLD_DPM_SOCCLK].enabled)
2723 "[GetSocclks]: socclk dpm not enabled!\n", 2707 return -1;
2724 return -EPERM);
2725 2708
2726 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count; 2709 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2727 clocks->num_levels = count; 2710 clocks->num_levels = count;
@@ -2799,7 +2782,6 @@ static int vega20_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
2799 data->od8_settings.od8_settings_array; 2782 data->od8_settings.od8_settings_array;
2800 OverDriveTable_t *od_table = 2783 OverDriveTable_t *od_table =
2801 &(data->smc_state_table.overdrive_table); 2784 &(data->smc_state_table.overdrive_table);
2802 struct pp_clock_levels_with_latency clocks;
2803 int32_t input_index, input_clk, input_vol, i; 2785 int32_t input_index, input_clk, input_vol, i;
2804 int od8_id; 2786 int od8_id;
2805 int ret; 2787 int ret;
@@ -2858,11 +2840,6 @@ static int vega20_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
2858 return -EOPNOTSUPP; 2840 return -EOPNOTSUPP;
2859 } 2841 }
2860 2842
2861 ret = vega20_get_memclocks(hwmgr, &clocks);
2862 PP_ASSERT_WITH_CODE(!ret,
2863 "Attempt to get memory clk levels failed!",
2864 return ret);
2865
2866 for (i = 0; i < size; i += 2) { 2843 for (i = 0; i < size; i += 2) {
2867 if (i + 2 > size) { 2844 if (i + 2 > size) {
2868 pr_info("invalid number of input parameters %d\n", 2845 pr_info("invalid number of input parameters %d\n",
@@ -2879,11 +2856,11 @@ static int vega20_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
2879 return -EINVAL; 2856 return -EINVAL;
2880 } 2857 }
2881 2858
2882 if (input_clk < clocks.data[0].clocks_in_khz / 1000 || 2859 if (input_clk < od8_settings[OD8_SETTING_UCLK_FMAX].min_value ||
2883 input_clk > od8_settings[OD8_SETTING_UCLK_FMAX].max_value) { 2860 input_clk > od8_settings[OD8_SETTING_UCLK_FMAX].max_value) {
2884 pr_info("clock freq %d is not within allowed range [%d - %d]\n", 2861 pr_info("clock freq %d is not within allowed range [%d - %d]\n",
2885 input_clk, 2862 input_clk,
2886 clocks.data[0].clocks_in_khz / 1000, 2863 od8_settings[OD8_SETTING_UCLK_FMAX].min_value,
2887 od8_settings[OD8_SETTING_UCLK_FMAX].max_value); 2864 od8_settings[OD8_SETTING_UCLK_FMAX].max_value);
2888 return -EINVAL; 2865 return -EINVAL;
2889 } 2866 }
@@ -3088,9 +3065,9 @@ static int vega20_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t new_ppfe
3088 return ret; 3065 return ret;
3089 3066
3090 features_to_disable = 3067 features_to_disable =
3091 (features_enabled ^ new_ppfeature_masks) & features_enabled; 3068 features_enabled & ~new_ppfeature_masks;
3092 features_to_enable = 3069 features_to_enable =
3093 (features_enabled ^ new_ppfeature_masks) ^ features_to_disable; 3070 ~features_enabled & new_ppfeature_masks;
3094 3071
3095 pr_debug("features_to_disable 0x%llx\n", features_to_disable); 3072 pr_debug("features_to_disable 0x%llx\n", features_to_disable);
3096 pr_debug("features_to_enable 0x%llx\n", features_to_enable); 3073 pr_debug("features_to_enable 0x%llx\n", features_to_enable);
@@ -3128,7 +3105,7 @@ static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3128 &(data->dpm_table.fclk_table); 3105 &(data->dpm_table.fclk_table);
3129 int i, now, size = 0; 3106 int i, now, size = 0;
3130 int ret = 0; 3107 int ret = 0;
3131 uint32_t gen_speed, lane_width; 3108 uint32_t gen_speed, lane_width, current_gen_speed, current_lane_width;
3132 3109
3133 switch (type) { 3110 switch (type) {
3134 case PP_SCLK: 3111 case PP_SCLK:
@@ -3137,10 +3114,11 @@ static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3137 "Attempt to get current gfx clk Failed!", 3114 "Attempt to get current gfx clk Failed!",
3138 return ret); 3115 return ret);
3139 3116
3140 ret = vega20_get_sclks(hwmgr, &clocks); 3117 if (vega20_get_sclks(hwmgr, &clocks)) {
3141 PP_ASSERT_WITH_CODE(!ret, 3118 size += sprintf(buf + size, "0: %uMhz * (DPM disabled)\n",
3142 "Attempt to get gfx clk levels Failed!", 3119 now / 100);
3143 return ret); 3120 break;
3121 }
3144 3122
3145 for (i = 0; i < clocks.num_levels; i++) 3123 for (i = 0; i < clocks.num_levels; i++)
3146 size += sprintf(buf + size, "%d: %uMhz %s\n", 3124 size += sprintf(buf + size, "%d: %uMhz %s\n",
@@ -3154,10 +3132,11 @@ static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3154 "Attempt to get current mclk freq Failed!", 3132 "Attempt to get current mclk freq Failed!",
3155 return ret); 3133 return ret);
3156 3134
3157 ret = vega20_get_memclocks(hwmgr, &clocks); 3135 if (vega20_get_memclocks(hwmgr, &clocks)) {
3158 PP_ASSERT_WITH_CODE(!ret, 3136 size += sprintf(buf + size, "0: %uMhz * (DPM disabled)\n",
3159 "Attempt to get memory clk levels Failed!", 3137 now / 100);
3160 return ret); 3138 break;
3139 }
3161 3140
3162 for (i = 0; i < clocks.num_levels; i++) 3141 for (i = 0; i < clocks.num_levels; i++)
3163 size += sprintf(buf + size, "%d: %uMhz %s\n", 3142 size += sprintf(buf + size, "%d: %uMhz %s\n",
@@ -3171,10 +3150,11 @@ static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3171 "Attempt to get current socclk freq Failed!", 3150 "Attempt to get current socclk freq Failed!",
3172 return ret); 3151 return ret);
3173 3152
3174 ret = vega20_get_socclocks(hwmgr, &clocks); 3153 if (vega20_get_socclocks(hwmgr, &clocks)) {
3175 PP_ASSERT_WITH_CODE(!ret, 3154 size += sprintf(buf + size, "0: %uMhz * (DPM disabled)\n",
3176 "Attempt to get soc clk levels Failed!", 3155 now / 100);
3177 return ret); 3156 break;
3157 }
3178 3158
3179 for (i = 0; i < clocks.num_levels; i++) 3159 for (i = 0; i < clocks.num_levels; i++)
3180 size += sprintf(buf + size, "%d: %uMhz %s\n", 3160 size += sprintf(buf + size, "%d: %uMhz %s\n",
@@ -3200,10 +3180,11 @@ static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3200 "Attempt to get current dcefclk freq Failed!", 3180 "Attempt to get current dcefclk freq Failed!",
3201 return ret); 3181 return ret);
3202 3182
3203 ret = vega20_get_dcefclocks(hwmgr, &clocks); 3183 if (vega20_get_dcefclocks(hwmgr, &clocks)) {
3204 PP_ASSERT_WITH_CODE(!ret, 3184 size += sprintf(buf + size, "0: %uMhz * (DPM disabled)\n",
3205 "Attempt to get dcefclk levels Failed!", 3185 now / 100);
3206 return ret); 3186 break;
3187 }
3207 3188
3208 for (i = 0; i < clocks.num_levels; i++) 3189 for (i = 0; i < clocks.num_levels; i++)
3209 size += sprintf(buf + size, "%d: %uMhz %s\n", 3190 size += sprintf(buf + size, "%d: %uMhz %s\n",
@@ -3212,28 +3193,36 @@ static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3212 break; 3193 break;
3213 3194
3214 case PP_PCIE: 3195 case PP_PCIE:
3215 gen_speed = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) & 3196 current_gen_speed = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
3216 PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK) 3197 PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
3217 >> PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT; 3198 >> PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
3218 lane_width = (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) & 3199 current_lane_width = (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
3219 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK) 3200 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
3220 >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT; 3201 >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
3221 for (i = 0; i < NUM_LINK_LEVELS; i++) 3202 for (i = 0; i < NUM_LINK_LEVELS; i++) {
3203 if (i == 1 && data->pcie_parameters_override) {
3204 gen_speed = data->pcie_gen_level1;
3205 lane_width = data->pcie_width_level1;
3206 } else {
3207 gen_speed = pptable->PcieGenSpeed[i];
3208 lane_width = pptable->PcieLaneCount[i];
3209 }
3222 size += sprintf(buf + size, "%d: %s %s %dMhz %s\n", i, 3210 size += sprintf(buf + size, "%d: %s %s %dMhz %s\n", i,
3223 (pptable->PcieGenSpeed[i] == 0) ? "2.5GT/s," : 3211 (gen_speed == 0) ? "2.5GT/s," :
3224 (pptable->PcieGenSpeed[i] == 1) ? "5.0GT/s," : 3212 (gen_speed == 1) ? "5.0GT/s," :
3225 (pptable->PcieGenSpeed[i] == 2) ? "8.0GT/s," : 3213 (gen_speed == 2) ? "8.0GT/s," :
3226 (pptable->PcieGenSpeed[i] == 3) ? "16.0GT/s," : "", 3214 (gen_speed == 3) ? "16.0GT/s," : "",
3227 (pptable->PcieLaneCount[i] == 1) ? "x1" : 3215 (lane_width == 1) ? "x1" :
3228 (pptable->PcieLaneCount[i] == 2) ? "x2" : 3216 (lane_width == 2) ? "x2" :
3229 (pptable->PcieLaneCount[i] == 3) ? "x4" : 3217 (lane_width == 3) ? "x4" :
3230 (pptable->PcieLaneCount[i] == 4) ? "x8" : 3218 (lane_width == 4) ? "x8" :
3231 (pptable->PcieLaneCount[i] == 5) ? "x12" : 3219 (lane_width == 5) ? "x12" :
3232 (pptable->PcieLaneCount[i] == 6) ? "x16" : "", 3220 (lane_width == 6) ? "x16" : "",
3233 pptable->LclkFreq[i], 3221 pptable->LclkFreq[i],
3234 (gen_speed == pptable->PcieGenSpeed[i]) && 3222 (current_gen_speed == gen_speed) &&
3235 (lane_width == pptable->PcieLaneCount[i]) ? 3223 (current_lane_width == lane_width) ?
3236 "*" : ""); 3224 "*" : "");
3225 }
3237 break; 3226 break;
3238 3227
3239 case OD_SCLK: 3228 case OD_SCLK:
@@ -3288,13 +3277,8 @@ static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3288 } 3277 }
3289 3278
3290 if (od8_settings[OD8_SETTING_UCLK_FMAX].feature_id) { 3279 if (od8_settings[OD8_SETTING_UCLK_FMAX].feature_id) {
3291 ret = vega20_get_memclocks(hwmgr, &clocks);
3292 PP_ASSERT_WITH_CODE(!ret,
3293 "Fail to get memory clk levels!",
3294 return ret);
3295
3296 size += sprintf(buf + size, "MCLK: %7uMhz %10uMhz\n", 3280 size += sprintf(buf + size, "MCLK: %7uMhz %10uMhz\n",
3297 clocks.data[0].clocks_in_khz / 1000, 3281 od8_settings[OD8_SETTING_UCLK_FMAX].min_value,
3298 od8_settings[OD8_SETTING_UCLK_FMAX].max_value); 3282 od8_settings[OD8_SETTING_UCLK_FMAX].max_value);
3299 } 3283 }
3300 3284
@@ -3356,6 +3340,31 @@ static int vega20_set_uclk_to_highest_dpm_level(struct pp_hwmgr *hwmgr,
3356 return ret; 3340 return ret;
3357} 3341}
3358 3342
3343static int vega20_set_fclk_to_highest_dpm_level(struct pp_hwmgr *hwmgr)
3344{
3345 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3346 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.fclk_table);
3347 int ret = 0;
3348
3349 if (data->smu_features[GNLD_DPM_FCLK].enabled) {
3350 PP_ASSERT_WITH_CODE(dpm_table->count > 0,
3351 "[SetFclkToHightestDpmLevel] Dpm table has no entry!",
3352 return -EINVAL);
3353 PP_ASSERT_WITH_CODE(dpm_table->count <= NUM_FCLK_DPM_LEVELS,
3354 "[SetFclkToHightestDpmLevel] Dpm table has too many entries!",
3355 return -EINVAL);
3356
3357 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3358 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(hwmgr,
3359 PPSMC_MSG_SetSoftMinByFreq,
3360 (PPCLK_FCLK << 16 ) | dpm_table->dpm_state.soft_min_level)),
3361 "[SetFclkToHightestDpmLevel] Set soft min fclk failed!",
3362 return ret);
3363 }
3364
3365 return ret;
3366}
3367
3359static int vega20_pre_display_configuration_changed_task(struct pp_hwmgr *hwmgr) 3368static int vega20_pre_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
3360{ 3369{
3361 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend); 3370 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
@@ -3366,8 +3375,10 @@ static int vega20_pre_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
3366 3375
3367 ret = vega20_set_uclk_to_highest_dpm_level(hwmgr, 3376 ret = vega20_set_uclk_to_highest_dpm_level(hwmgr,
3368 &data->dpm_table.mem_table); 3377 &data->dpm_table.mem_table);
3378 if (ret)
3379 return ret;
3369 3380
3370 return ret; 3381 return vega20_set_fclk_to_highest_dpm_level(hwmgr);
3371} 3382}
3372 3383
3373static int vega20_display_configuration_changed_task(struct pp_hwmgr *hwmgr) 3384static int vega20_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
@@ -3461,9 +3472,9 @@ static int vega20_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
3461 /* gfxclk */ 3472 /* gfxclk */
3462 dpm_table = &(data->dpm_table.gfx_table); 3473 dpm_table = &(data->dpm_table.gfx_table);
3463 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value; 3474 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3464 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3475 dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
3465 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value; 3476 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3466 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3477 dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
3467 3478
3468 if (PP_CAP(PHM_PlatformCaps_UMDPState)) { 3479 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3469 if (VEGA20_UMD_PSTATE_GFXCLK_LEVEL < dpm_table->count) { 3480 if (VEGA20_UMD_PSTATE_GFXCLK_LEVEL < dpm_table->count) {
@@ -3485,9 +3496,9 @@ static int vega20_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
3485 /* memclk */ 3496 /* memclk */
3486 dpm_table = &(data->dpm_table.mem_table); 3497 dpm_table = &(data->dpm_table.mem_table);
3487 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value; 3498 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3488 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3499 dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
3489 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value; 3500 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3490 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3501 dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
3491 3502
3492 if (PP_CAP(PHM_PlatformCaps_UMDPState)) { 3503 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3493 if (VEGA20_UMD_PSTATE_MCLK_LEVEL < dpm_table->count) { 3504 if (VEGA20_UMD_PSTATE_MCLK_LEVEL < dpm_table->count) {
@@ -3526,12 +3537,21 @@ static int vega20_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
3526 if (hwmgr->display_config->nb_pstate_switch_disable) 3537 if (hwmgr->display_config->nb_pstate_switch_disable)
3527 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3538 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3528 3539
3540 /* fclk */
3541 dpm_table = &(data->dpm_table.fclk_table);
3542 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3543 dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
3544 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3545 dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
3546 if (hwmgr->display_config->nb_pstate_switch_disable)
3547 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3548
3529 /* vclk */ 3549 /* vclk */
3530 dpm_table = &(data->dpm_table.vclk_table); 3550 dpm_table = &(data->dpm_table.vclk_table);
3531 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value; 3551 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3532 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3552 dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
3533 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value; 3553 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3534 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3554 dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
3535 3555
3536 if (PP_CAP(PHM_PlatformCaps_UMDPState)) { 3556 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3537 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) { 3557 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
@@ -3548,9 +3568,9 @@ static int vega20_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
3548 /* dclk */ 3568 /* dclk */
3549 dpm_table = &(data->dpm_table.dclk_table); 3569 dpm_table = &(data->dpm_table.dclk_table);
3550 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value; 3570 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3551 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3571 dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
3552 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value; 3572 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3553 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3573 dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
3554 3574
3555 if (PP_CAP(PHM_PlatformCaps_UMDPState)) { 3575 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3556 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) { 3576 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
@@ -3567,9 +3587,9 @@ static int vega20_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
3567 /* socclk */ 3587 /* socclk */
3568 dpm_table = &(data->dpm_table.soc_table); 3588 dpm_table = &(data->dpm_table.soc_table);
3569 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value; 3589 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3570 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3590 dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
3571 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value; 3591 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3572 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3592 dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
3573 3593
3574 if (PP_CAP(PHM_PlatformCaps_UMDPState)) { 3594 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3575 if (VEGA20_UMD_PSTATE_SOCCLK_LEVEL < dpm_table->count) { 3595 if (VEGA20_UMD_PSTATE_SOCCLK_LEVEL < dpm_table->count) {
@@ -3586,9 +3606,9 @@ static int vega20_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
3586 /* eclk */ 3606 /* eclk */
3587 dpm_table = &(data->dpm_table.eclk_table); 3607 dpm_table = &(data->dpm_table.eclk_table);
3588 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value; 3608 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3589 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3609 dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
3590 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value; 3610 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3591 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value; 3611 dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
3592 3612
3593 if (PP_CAP(PHM_PlatformCaps_UMDPState)) { 3613 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3594 if (VEGA20_UMD_PSTATE_VCEMCLK_LEVEL < dpm_table->count) { 3614 if (VEGA20_UMD_PSTATE_VCEMCLK_LEVEL < dpm_table->count) {
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
index 37f5f5e657da..a5bc758ae097 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
@@ -42,6 +42,8 @@
42#define AVFS_CURVE 0 42#define AVFS_CURVE 0
43#define OD8_HOTCURVE_TEMPERATURE 85 43#define OD8_HOTCURVE_TEMPERATURE 85
44 44
45#define VG20_CLOCK_MAX_DEFAULT 0xFFFF
46
45typedef uint32_t PP_Clock; 47typedef uint32_t PP_Clock;
46 48
47enum { 49enum {
@@ -219,6 +221,7 @@ struct vega20_vbios_boot_state {
219 uint32_t eclock; 221 uint32_t eclock;
220 uint32_t dclock; 222 uint32_t dclock;
221 uint32_t vclock; 223 uint32_t vclock;
224 uint32_t fclock;
222}; 225};
223 226
224#define DPMTABLE_OD_UPDATE_SCLK 0x00000001 227#define DPMTABLE_OD_UPDATE_SCLK 0x00000001
@@ -523,6 +526,10 @@ struct vega20_hwmgr {
523 526
524 unsigned long metrics_time; 527 unsigned long metrics_time;
525 SmuMetrics_t metrics_table; 528 SmuMetrics_t metrics_table;
529
530 bool pcie_parameters_override;
531 uint32_t pcie_gen_level1;
532 uint32_t pcie_width_level1;
526}; 533};
527 534
528#define VEGA20_DPM2_NEAR_TDP_DEC 10 535#define VEGA20_DPM2_NEAR_TDP_DEC 10
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
index 97f8a1a970c3..7a7f15d0c53a 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
@@ -32,6 +32,8 @@
32#include "cgs_common.h" 32#include "cgs_common.h"
33#include "vega20_pptable.h" 33#include "vega20_pptable.h"
34 34
35#define VEGA20_FAN_TARGET_TEMPERATURE_OVERRIDE 105
36
35static void set_hw_cap(struct pp_hwmgr *hwmgr, bool enable, 37static void set_hw_cap(struct pp_hwmgr *hwmgr, bool enable,
36 enum phm_platform_caps cap) 38 enum phm_platform_caps cap)
37{ 39{
@@ -798,6 +800,17 @@ static int append_vbios_pptable(struct pp_hwmgr *hwmgr, PPTable_t *ppsmc_pptable
798 return 0; 800 return 0;
799} 801}
800 802
803static int override_powerplay_table_fantargettemperature(struct pp_hwmgr *hwmgr)
804{
805 struct phm_ppt_v3_information *pptable_information =
806 (struct phm_ppt_v3_information *)hwmgr->pptable;
807 PPTable_t *ppsmc_pptable = (PPTable_t *)(pptable_information->smc_pptable);
808
809 ppsmc_pptable->FanTargetTemperature = VEGA20_FAN_TARGET_TEMPERATURE_OVERRIDE;
810
811 return 0;
812}
813
801#define VEGA20_ENGINECLOCK_HARDMAX 198000 814#define VEGA20_ENGINECLOCK_HARDMAX 198000
802static int init_powerplay_table_information( 815static int init_powerplay_table_information(
803 struct pp_hwmgr *hwmgr, 816 struct pp_hwmgr *hwmgr,
@@ -887,6 +900,10 @@ static int init_powerplay_table_information(
887 900
888 901
889 result = append_vbios_pptable(hwmgr, (pptable_information->smc_pptable)); 902 result = append_vbios_pptable(hwmgr, (pptable_information->smc_pptable));
903 if (result)
904 return result;
905
906 result = override_powerplay_table_fantargettemperature(hwmgr);
890 907
891 return result; 908 return result;
892} 909}
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c
index 52abca065764..2d4cfe14f72e 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c
@@ -2330,6 +2330,7 @@ static uint32_t polaris10_get_offsetof(uint32_t type, uint32_t member)
2330 case DRAM_LOG_BUFF_SIZE: 2330 case DRAM_LOG_BUFF_SIZE:
2331 return offsetof(SMU74_SoftRegisters, DRAM_LOG_BUFF_SIZE); 2331 return offsetof(SMU74_SoftRegisters, DRAM_LOG_BUFF_SIZE);
2332 } 2332 }
2333 break;
2333 case SMU_Discrete_DpmTable: 2334 case SMU_Discrete_DpmTable:
2334 switch (member) { 2335 switch (member) {
2335 case UvdBootLevel: 2336 case UvdBootLevel:
@@ -2339,6 +2340,7 @@ static uint32_t polaris10_get_offsetof(uint32_t type, uint32_t member)
2339 case LowSclkInterruptThreshold: 2340 case LowSclkInterruptThreshold:
2340 return offsetof(SMU74_Discrete_DpmTable, LowSclkInterruptThreshold); 2341 return offsetof(SMU74_Discrete_DpmTable, LowSclkInterruptThreshold);
2341 } 2342 }
2343 break;
2342 } 2344 }
2343 pr_warn("can't get the offset of type %x member %x\n", type, member); 2345 pr_warn("can't get the offset of type %x member %x\n", type, member);
2344 return 0; 2346 return 0;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu9_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/smu9_smumgr.c
index 079fc8e8f709..742b3dc1f6cb 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu9_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu9_smumgr.c
@@ -40,10 +40,8 @@ bool smu9_is_smc_ram_running(struct pp_hwmgr *hwmgr)
40 struct amdgpu_device *adev = hwmgr->adev; 40 struct amdgpu_device *adev = hwmgr->adev;
41 uint32_t mp1_fw_flags; 41 uint32_t mp1_fw_flags;
42 42
43 WREG32_SOC15(NBIF, 0, mmPCIE_INDEX2, 43 mp1_fw_flags = RREG32_PCIE(MP1_Public |
44 (MP1_Public | (smnMP1_FIRMWARE_FLAGS & 0xffffffff))); 44 (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
45
46 mp1_fw_flags = RREG32_SOC15(NBIF, 0, mmPCIE_DATA2);
47 45
48 if (mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) 46 if (mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK)
49 return true; 47 return true;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
index b7ff7d4d6f44..ba00744c3413 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
@@ -49,10 +49,8 @@ static bool vega20_is_smc_ram_running(struct pp_hwmgr *hwmgr)
49 struct amdgpu_device *adev = hwmgr->adev; 49 struct amdgpu_device *adev = hwmgr->adev;
50 uint32_t mp1_fw_flags; 50 uint32_t mp1_fw_flags;
51 51
52 WREG32_SOC15(NBIF, 0, mmPCIE_INDEX2, 52 mp1_fw_flags = RREG32_PCIE(MP1_Public |
53 (MP1_Public | (smnMP1_FIRMWARE_FLAGS & 0xffffffff))); 53 (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
54
55 mp1_fw_flags = RREG32_SOC15(NBIF, 0, mmPCIE_DATA2);
56 54
57 if ((mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >> 55 if ((mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >>
58 MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT) 56 MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 540a77a2ade9..40ac19848034 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -3039,9 +3039,31 @@ commit:
3039 return 0; 3039 return 0;
3040} 3040}
3041 3041
3042static int __drm_atomic_helper_disable_all(struct drm_device *dev, 3042/**
3043 struct drm_modeset_acquire_ctx *ctx, 3043 * drm_atomic_helper_disable_all - disable all currently active outputs
3044 bool clean_old_fbs) 3044 * @dev: DRM device
3045 * @ctx: lock acquisition context
3046 *
3047 * Loops through all connectors, finding those that aren't turned off and then
3048 * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
3049 * that they are connected to.
3050 *
3051 * This is used for example in suspend/resume to disable all currently active
3052 * functions when suspending. If you just want to shut down everything at e.g.
3053 * driver unload, look at drm_atomic_helper_shutdown().
3054 *
3055 * Note that if callers haven't already acquired all modeset locks this might
3056 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3057 *
3058 * Returns:
3059 * 0 on success or a negative error code on failure.
3060 *
3061 * See also:
3062 * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and
3063 * drm_atomic_helper_shutdown().
3064 */
3065int drm_atomic_helper_disable_all(struct drm_device *dev,
3066 struct drm_modeset_acquire_ctx *ctx)
3045{ 3067{
3046 struct drm_atomic_state *state; 3068 struct drm_atomic_state *state;
3047 struct drm_connector_state *conn_state; 3069 struct drm_connector_state *conn_state;
@@ -3099,35 +3121,6 @@ free:
3099 drm_atomic_state_put(state); 3121 drm_atomic_state_put(state);
3100 return ret; 3122 return ret;
3101} 3123}
3102
3103/**
3104 * drm_atomic_helper_disable_all - disable all currently active outputs
3105 * @dev: DRM device
3106 * @ctx: lock acquisition context
3107 *
3108 * Loops through all connectors, finding those that aren't turned off and then
3109 * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
3110 * that they are connected to.
3111 *
3112 * This is used for example in suspend/resume to disable all currently active
3113 * functions when suspending. If you just want to shut down everything at e.g.
3114 * driver unload, look at drm_atomic_helper_shutdown().
3115 *
3116 * Note that if callers haven't already acquired all modeset locks this might
3117 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3118 *
3119 * Returns:
3120 * 0 on success or a negative error code on failure.
3121 *
3122 * See also:
3123 * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and
3124 * drm_atomic_helper_shutdown().
3125 */
3126int drm_atomic_helper_disable_all(struct drm_device *dev,
3127 struct drm_modeset_acquire_ctx *ctx)
3128{
3129 return __drm_atomic_helper_disable_all(dev, ctx, false);
3130}
3131EXPORT_SYMBOL(drm_atomic_helper_disable_all); 3124EXPORT_SYMBOL(drm_atomic_helper_disable_all);
3132 3125
3133/** 3126/**
@@ -3148,7 +3141,7 @@ void drm_atomic_helper_shutdown(struct drm_device *dev)
3148 3141
3149 DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret); 3142 DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
3150 3143
3151 ret = __drm_atomic_helper_disable_all(dev, &ctx, true); 3144 ret = drm_atomic_helper_disable_all(dev, &ctx);
3152 if (ret) 3145 if (ret)
3153 DRM_ERROR("Disabling all crtc's during unload failed with %i\n", ret); 3146 DRM_ERROR("Disabling all crtc's during unload failed with %i\n", ret);
3154 3147
diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
index 67b1fca39aa6..0e3043e08c69 100644
--- a/drivers/gpu/drm/drm_ioc32.c
+++ b/drivers/gpu/drm/drm_ioc32.c
@@ -185,7 +185,7 @@ static int compat_drm_getmap(struct file *file, unsigned int cmd,
185 m32.size = map.size; 185 m32.size = map.size;
186 m32.type = map.type; 186 m32.type = map.type;
187 m32.flags = map.flags; 187 m32.flags = map.flags;
188 m32.handle = ptr_to_compat(map.handle); 188 m32.handle = ptr_to_compat((void __user *)map.handle);
189 m32.mtrr = map.mtrr; 189 m32.mtrr = map.mtrr;
190 if (copy_to_user(argp, &m32, sizeof(m32))) 190 if (copy_to_user(argp, &m32, sizeof(m32)))
191 return -EFAULT; 191 return -EFAULT;
@@ -216,7 +216,7 @@ static int compat_drm_addmap(struct file *file, unsigned int cmd,
216 216
217 m32.offset = map.offset; 217 m32.offset = map.offset;
218 m32.mtrr = map.mtrr; 218 m32.mtrr = map.mtrr;
219 m32.handle = ptr_to_compat(map.handle); 219 m32.handle = ptr_to_compat((void __user *)map.handle);
220 if (map.handle != compat_ptr(m32.handle)) 220 if (map.handle != compat_ptr(m32.handle))
221 pr_err_ratelimited("compat_drm_addmap truncated handle %p for type %d offset %x\n", 221 pr_err_ratelimited("compat_drm_addmap truncated handle %p for type %d offset %x\n",
222 map.handle, m32.type, m32.offset); 222 map.handle, m32.type, m32.offset);
@@ -526,7 +526,7 @@ static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
526 if (err) 526 if (err)
527 return err; 527 return err;
528 528
529 req32.handle = ptr_to_compat(req.handle); 529 req32.handle = ptr_to_compat((void __user *)req.handle);
530 if (copy_to_user(argp, &req32, sizeof(req32))) 530 if (copy_to_user(argp, &req32, sizeof(req32)))
531 return -EFAULT; 531 return -EFAULT;
532 532
diff --git a/drivers/gpu/drm/etnaviv/Kconfig b/drivers/gpu/drm/etnaviv/Kconfig
index 041a77e400d4..21df44b78df3 100644
--- a/drivers/gpu/drm/etnaviv/Kconfig
+++ b/drivers/gpu/drm/etnaviv/Kconfig
@@ -2,7 +2,6 @@
2config DRM_ETNAVIV 2config DRM_ETNAVIV
3 tristate "ETNAVIV (DRM support for Vivante GPU IP cores)" 3 tristate "ETNAVIV (DRM support for Vivante GPU IP cores)"
4 depends on DRM 4 depends on DRM
5 depends on ARCH_MXC || ARCH_DOVE || (ARM && COMPILE_TEST)
6 depends on MMU 5 depends on MMU
7 select SHMEM 6 select SHMEM
8 select SYNC_FILE 7 select SYNC_FILE
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h
index acb68c698363..4d5d1a77eb2a 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h
+++ b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h
@@ -15,8 +15,6 @@ struct etnaviv_perfmon_request;
15struct etnaviv_cmdbuf { 15struct etnaviv_cmdbuf {
16 /* suballocator this cmdbuf is allocated from */ 16 /* suballocator this cmdbuf is allocated from */
17 struct etnaviv_cmdbuf_suballoc *suballoc; 17 struct etnaviv_cmdbuf_suballoc *suballoc;
18 /* user context key, must be unique between all active users */
19 struct etnaviv_file_private *ctx;
20 /* cmdbuf properties */ 18 /* cmdbuf properties */
21 int suballoc_offset; 19 int suballoc_offset;
22 void *vaddr; 20 void *vaddr;
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_dump.c b/drivers/gpu/drm/etnaviv/etnaviv_dump.c
index 3fbb4855396c..33854c94cb85 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_dump.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_dump.c
@@ -215,7 +215,7 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)
215 mutex_lock(&obj->lock); 215 mutex_lock(&obj->lock);
216 pages = etnaviv_gem_get_pages(obj); 216 pages = etnaviv_gem_get_pages(obj);
217 mutex_unlock(&obj->lock); 217 mutex_unlock(&obj->lock);
218 if (pages) { 218 if (!IS_ERR(pages)) {
219 int j; 219 int j;
220 220
221 iter.hdr->data[0] = bomap - bomap_start; 221 iter.hdr->data[0] = bomap - bomap_start;
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.h b/drivers/gpu/drm/etnaviv/etnaviv_gem.h
index 76079c2291f8..f0abb744ef95 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem.h
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.h
@@ -95,6 +95,7 @@ struct etnaviv_gem_submit_bo {
95struct etnaviv_gem_submit { 95struct etnaviv_gem_submit {
96 struct drm_sched_job sched_job; 96 struct drm_sched_job sched_job;
97 struct kref refcount; 97 struct kref refcount;
98 struct etnaviv_file_private *ctx;
98 struct etnaviv_gpu *gpu; 99 struct etnaviv_gpu *gpu;
99 struct dma_fence *out_fence, *in_fence; 100 struct dma_fence *out_fence, *in_fence;
100 int out_fence_id; 101 int out_fence_id;
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
index 0566171f8df2..f21529e635e3 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
@@ -15,7 +15,7 @@ struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj)
15 int npages = obj->size >> PAGE_SHIFT; 15 int npages = obj->size >> PAGE_SHIFT;
16 16
17 if (WARN_ON(!etnaviv_obj->pages)) /* should have already pinned! */ 17 if (WARN_ON(!etnaviv_obj->pages)) /* should have already pinned! */
18 return NULL; 18 return ERR_PTR(-EINVAL);
19 19
20 return drm_prime_pages_to_sg(etnaviv_obj->pages, npages); 20 return drm_prime_pages_to_sg(etnaviv_obj->pages, npages);
21} 21}
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
index 30875f8f2933..b2fe3446bfbc 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
@@ -506,7 +506,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
506 if (ret) 506 if (ret)
507 goto err_submit_objects; 507 goto err_submit_objects;
508 508
509 submit->cmdbuf.ctx = file->driver_priv; 509 submit->ctx = file->driver_priv;
510 submit->exec_state = args->exec_state; 510 submit->exec_state = args->exec_state;
511 submit->flags = args->flags; 511 submit->flags = args->flags;
512 512
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c b/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c
index f1c88d8ad5ba..f794e04be9e6 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c
@@ -320,8 +320,8 @@ etnaviv_iommuv2_domain_alloc(struct etnaviv_gpu *gpu)
320 domain = &etnaviv_domain->base; 320 domain = &etnaviv_domain->base;
321 321
322 domain->dev = gpu->dev; 322 domain->dev = gpu->dev;
323 domain->base = 0; 323 domain->base = SZ_4K;
324 domain->size = (u64)SZ_1G * 4; 324 domain->size = (u64)SZ_1G * 4 - SZ_4K;
325 domain->ops = &etnaviv_iommuv2_ops; 325 domain->ops = &etnaviv_iommuv2_ops;
326 326
327 ret = etnaviv_iommuv2_init(etnaviv_domain); 327 ret = etnaviv_iommuv2_init(etnaviv_domain);
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
index 9980d81a26e3..4227a4006c34 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
@@ -113,7 +113,7 @@ static const struct etnaviv_pm_domain doms_3d[] = {
113 .name = "PE", 113 .name = "PE",
114 .profile_read = VIVS_MC_PROFILE_PE_READ, 114 .profile_read = VIVS_MC_PROFILE_PE_READ,
115 .profile_config = VIVS_MC_PROFILE_CONFIG0, 115 .profile_config = VIVS_MC_PROFILE_CONFIG0,
116 .nr_signals = 5, 116 .nr_signals = 4,
117 .signal = (const struct etnaviv_pm_signal[]) { 117 .signal = (const struct etnaviv_pm_signal[]) {
118 { 118 {
119 "PIXEL_COUNT_KILLED_BY_COLOR_PIPE", 119 "PIXEL_COUNT_KILLED_BY_COLOR_PIPE",
@@ -435,7 +435,7 @@ int etnaviv_pm_query_sig(struct etnaviv_gpu *gpu,
435 435
436 dom = meta->domains + signal->domain; 436 dom = meta->domains + signal->domain;
437 437
438 if (signal->iter > dom->nr_signals) 438 if (signal->iter >= dom->nr_signals)
439 return -EINVAL; 439 return -EINVAL;
440 440
441 sig = &dom->signal[signal->iter]; 441 sig = &dom->signal[signal->iter];
@@ -461,7 +461,7 @@ int etnaviv_pm_req_validate(const struct drm_etnaviv_gem_submit_pmr *r,
461 461
462 dom = meta->domains + r->domain; 462 dom = meta->domains + r->domain;
463 463
464 if (r->signal > dom->nr_signals) 464 if (r->signal >= dom->nr_signals)
465 return -EINVAL; 465 return -EINVAL;
466 466
467 return 0; 467 return 0;
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_sched.c b/drivers/gpu/drm/etnaviv/etnaviv_sched.c
index 67ae26602024..6d24fea1766b 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_sched.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_sched.c
@@ -153,7 +153,7 @@ int etnaviv_sched_push_job(struct drm_sched_entity *sched_entity,
153 mutex_lock(&submit->gpu->fence_lock); 153 mutex_lock(&submit->gpu->fence_lock);
154 154
155 ret = drm_sched_job_init(&submit->sched_job, sched_entity, 155 ret = drm_sched_job_init(&submit->sched_job, sched_entity,
156 submit->cmdbuf.ctx); 156 submit->ctx);
157 if (ret) 157 if (ret)
158 goto out_unlock; 158 goto out_unlock;
159 159
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_active.c b/drivers/gpu/drm/i915/i915_active.c
index 215b6ff8aa73..db7bb5bd5add 100644
--- a/drivers/gpu/drm/i915/i915_active.c
+++ b/drivers/gpu/drm/i915/i915_active.c
@@ -163,17 +163,25 @@ int i915_active_ref(struct i915_active *ref,
163 struct i915_request *rq) 163 struct i915_request *rq)
164{ 164{
165 struct i915_active_request *active; 165 struct i915_active_request *active;
166 int err = 0;
167
168 /* Prevent reaping in case we malloc/wait while building the tree */
169 i915_active_acquire(ref);
166 170
167 active = active_instance(ref, timeline); 171 active = active_instance(ref, timeline);
168 if (IS_ERR(active)) 172 if (IS_ERR(active)) {
169 return PTR_ERR(active); 173 err = PTR_ERR(active);
174 goto out;
175 }
170 176
171 if (!i915_active_request_isset(active)) 177 if (!i915_active_request_isset(active))
172 ref->count++; 178 ref->count++;
173 __i915_active_request_set(active, rq); 179 __i915_active_request_set(active, rq);
174 180
175 GEM_BUG_ON(!ref->count); 181 GEM_BUG_ON(!ref->count);
176 return 0; 182out:
183 i915_active_release(ref);
184 return err;
177} 185}
178 186
179bool i915_active_acquire(struct i915_active *ref) 187bool i915_active_acquire(struct i915_active *ref)
@@ -223,19 +231,25 @@ int i915_request_await_active_request(struct i915_request *rq,
223int i915_request_await_active(struct i915_request *rq, struct i915_active *ref) 231int i915_request_await_active(struct i915_request *rq, struct i915_active *ref)
224{ 232{
225 struct active_node *it, *n; 233 struct active_node *it, *n;
226 int ret; 234 int err = 0;
227 235
228 ret = i915_request_await_active_request(rq, &ref->last); 236 /* await allocates and so we need to avoid hitting the shrinker */
229 if (ret) 237 if (i915_active_acquire(ref))
230 return ret; 238 goto out; /* was idle */
239
240 err = i915_request_await_active_request(rq, &ref->last);
241 if (err)
242 goto out;
231 243
232 rbtree_postorder_for_each_entry_safe(it, n, &ref->tree, node) { 244 rbtree_postorder_for_each_entry_safe(it, n, &ref->tree, node) {
233 ret = i915_request_await_active_request(rq, &it->base); 245 err = i915_request_await_active_request(rq, &it->base);
234 if (ret) 246 if (err)
235 return ret; 247 goto out;
236 } 248 }
237 249
238 return 0; 250out:
251 i915_active_release(ref);
252 return err;
239} 253}
240 254
241#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM) 255#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 6630212f2faf..9df65d386d11 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -757,39 +757,6 @@ static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
757 return ret; 757 return ret;
758} 758}
759 759
760#if !defined(CONFIG_VGA_CONSOLE)
761static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
762{
763 return 0;
764}
765#elif !defined(CONFIG_DUMMY_CONSOLE)
766static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
767{
768 return -ENODEV;
769}
770#else
771static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
772{
773 int ret = 0;
774
775 DRM_INFO("Replacing VGA console driver\n");
776
777 console_lock();
778 if (con_is_bound(&vga_con))
779 ret = do_take_over_console(&dummy_con, 0, MAX_NR_CONSOLES - 1, 1);
780 if (ret == 0) {
781 ret = do_unregister_con_driver(&vga_con);
782
783 /* Ignore "already unregistered". */
784 if (ret == -ENODEV)
785 ret = 0;
786 }
787 console_unlock();
788
789 return ret;
790}
791#endif
792
793static void intel_init_dpio(struct drm_i915_private *dev_priv) 760static void intel_init_dpio(struct drm_i915_private *dev_priv)
794{ 761{
795 /* 762 /*
@@ -1420,7 +1387,7 @@ static int i915_driver_init_hw(struct drm_i915_private *dev_priv)
1420 goto err_ggtt; 1387 goto err_ggtt;
1421 } 1388 }
1422 1389
1423 ret = i915_kick_out_vgacon(dev_priv); 1390 ret = vga_remove_vgacon(pdev);
1424 if (ret) { 1391 if (ret) {
1425 DRM_ERROR("failed to remove conflicting VGA console\n"); 1392 DRM_ERROR("failed to remove conflicting VGA console\n");
1426 goto err_ggtt; 1393 goto err_ggtt;
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 6728ea5c71d4..8558e81fdc2a 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1688,7 +1688,8 @@ __vma_matches(struct vm_area_struct *vma, struct file *filp,
1688 if (vma->vm_file != filp) 1688 if (vma->vm_file != filp)
1689 return false; 1689 return false;
1690 1690
1691 return vma->vm_start == addr && (vma->vm_end - vma->vm_start) == size; 1691 return vma->vm_start == addr &&
1692 (vma->vm_end - vma->vm_start) == PAGE_ALIGN(size);
1692} 1693}
1693 1694
1694/** 1695/**
@@ -1733,8 +1734,13 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1733 * pages from. 1734 * pages from.
1734 */ 1735 */
1735 if (!obj->base.filp) { 1736 if (!obj->base.filp) {
1736 i915_gem_object_put(obj); 1737 addr = -ENXIO;
1737 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;
1738 } 1744 }
1739 1745
1740 addr = vm_mmap(obj->base.filp, 0, args->size, 1746 addr = vm_mmap(obj->base.filp, 0, args->size,
@@ -1748,8 +1754,8 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1748 struct vm_area_struct *vma; 1754 struct vm_area_struct *vma;
1749 1755
1750 if (down_write_killable(&mm->mmap_sem)) { 1756 if (down_write_killable(&mm->mmap_sem)) {
1751 i915_gem_object_put(obj); 1757 addr = -EINTR;
1752 return -EINTR; 1758 goto err;
1753 } 1759 }
1754 vma = find_vma(mm, addr); 1760 vma = find_vma(mm, addr);
1755 if (vma && __vma_matches(vma, obj->base.filp, addr, args->size)) 1761 if (vma && __vma_matches(vma, obj->base.filp, addr, args->size))
@@ -1767,12 +1773,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1767 i915_gem_object_put(obj); 1773 i915_gem_object_put(obj);
1768 1774
1769 args->addr_ptr = (u64)addr; 1775 args->addr_ptr = (u64)addr;
1770
1771 return 0; 1776 return 0;
1772 1777
1773err: 1778err:
1774 i915_gem_object_put(obj); 1779 i915_gem_object_put(obj);
1775
1776 return addr; 1780 return addr;
1777} 1781}
1778 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/i915_scheduler.c b/drivers/gpu/drm/i915/i915_scheduler.c
index d01683167c77..8bc042551692 100644
--- a/drivers/gpu/drm/i915/i915_scheduler.c
+++ b/drivers/gpu/drm/i915/i915_scheduler.c
@@ -223,8 +223,14 @@ out:
223 return &p->requests[idx]; 223 return &p->requests[idx];
224} 224}
225 225
226struct sched_cache {
227 struct list_head *priolist;
228};
229
226static struct intel_engine_cs * 230static struct intel_engine_cs *
227sched_lock_engine(struct i915_sched_node *node, struct intel_engine_cs *locked) 231sched_lock_engine(const struct i915_sched_node *node,
232 struct intel_engine_cs *locked,
233 struct sched_cache *cache)
228{ 234{
229 struct intel_engine_cs *engine = node_to_request(node)->engine; 235 struct intel_engine_cs *engine = node_to_request(node)->engine;
230 236
@@ -232,6 +238,7 @@ sched_lock_engine(struct i915_sched_node *node, struct intel_engine_cs *locked)
232 238
233 if (engine != locked) { 239 if (engine != locked) {
234 spin_unlock(&locked->timeline.lock); 240 spin_unlock(&locked->timeline.lock);
241 memset(cache, 0, sizeof(*cache));
235 spin_lock(&engine->timeline.lock); 242 spin_lock(&engine->timeline.lock);
236 } 243 }
237 244
@@ -253,11 +260,11 @@ static bool inflight(const struct i915_request *rq,
253static void __i915_schedule(struct i915_request *rq, 260static void __i915_schedule(struct i915_request *rq,
254 const struct i915_sched_attr *attr) 261 const struct i915_sched_attr *attr)
255{ 262{
256 struct list_head *uninitialized_var(pl); 263 struct intel_engine_cs *engine;
257 struct intel_engine_cs *engine, *last;
258 struct i915_dependency *dep, *p; 264 struct i915_dependency *dep, *p;
259 struct i915_dependency stack; 265 struct i915_dependency stack;
260 const int prio = attr->priority; 266 const int prio = attr->priority;
267 struct sched_cache cache;
261 LIST_HEAD(dfs); 268 LIST_HEAD(dfs);
262 269
263 /* Needed in order to use the temporary link inside i915_dependency */ 270 /* Needed in order to use the temporary link inside i915_dependency */
@@ -328,7 +335,7 @@ static void __i915_schedule(struct i915_request *rq,
328 __list_del_entry(&stack.dfs_link); 335 __list_del_entry(&stack.dfs_link);
329 } 336 }
330 337
331 last = NULL; 338 memset(&cache, 0, sizeof(cache));
332 engine = rq->engine; 339 engine = rq->engine;
333 spin_lock_irq(&engine->timeline.lock); 340 spin_lock_irq(&engine->timeline.lock);
334 341
@@ -338,7 +345,7 @@ static void __i915_schedule(struct i915_request *rq,
338 345
339 INIT_LIST_HEAD(&dep->dfs_link); 346 INIT_LIST_HEAD(&dep->dfs_link);
340 347
341 engine = sched_lock_engine(node, engine); 348 engine = sched_lock_engine(node, engine, &cache);
342 lockdep_assert_held(&engine->timeline.lock); 349 lockdep_assert_held(&engine->timeline.lock);
343 350
344 /* Recheck after acquiring the engine->timeline.lock */ 351 /* Recheck after acquiring the engine->timeline.lock */
@@ -347,11 +354,11 @@ static void __i915_schedule(struct i915_request *rq,
347 354
348 node->attr.priority = prio; 355 node->attr.priority = prio;
349 if (!list_empty(&node->link)) { 356 if (!list_empty(&node->link)) {
350 if (last != engine) { 357 if (!cache.priolist)
351 pl = i915_sched_lookup_priolist(engine, prio); 358 cache.priolist =
352 last = engine; 359 i915_sched_lookup_priolist(engine,
353 } 360 prio);
354 list_move_tail(&node->link, pl); 361 list_move_tail(&node->link, cache.priolist);
355 } else { 362 } else {
356 /* 363 /*
357 * If the request is not in the priolist queue because 364 * If the request is not in the priolist queue because
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/i915/intel_breadcrumbs.c b/drivers/gpu/drm/i915/intel_breadcrumbs.c
index cacaa1d04d17..09ed90c0ba00 100644
--- a/drivers/gpu/drm/i915/intel_breadcrumbs.c
+++ b/drivers/gpu/drm/i915/intel_breadcrumbs.c
@@ -106,16 +106,6 @@ bool intel_engine_breadcrumbs_irq(struct intel_engine_cs *engine)
106 106
107 GEM_BUG_ON(!test_bit(I915_FENCE_FLAG_SIGNAL, 107 GEM_BUG_ON(!test_bit(I915_FENCE_FLAG_SIGNAL,
108 &rq->fence.flags)); 108 &rq->fence.flags));
109 clear_bit(I915_FENCE_FLAG_SIGNAL, &rq->fence.flags);
110
111 /*
112 * We may race with direct invocation of
113 * dma_fence_signal(), e.g. i915_request_retire(),
114 * in which case we can skip processing it ourselves.
115 */
116 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
117 &rq->fence.flags))
118 continue;
119 109
120 /* 110 /*
121 * Queue for execution after dropping the signaling 111 * Queue for execution after dropping the signaling
@@ -123,6 +113,14 @@ bool intel_engine_breadcrumbs_irq(struct intel_engine_cs *engine)
123 * more signalers to the same context or engine. 113 * more signalers to the same context or engine.
124 */ 114 */
125 i915_request_get(rq); 115 i915_request_get(rq);
116
117 /*
118 * We may race with direct invocation of
119 * dma_fence_signal(), e.g. i915_request_retire(),
120 * so we need to acquire our reference to the request
121 * before we cancel the breadcrumb.
122 */
123 clear_bit(I915_FENCE_FLAG_SIGNAL, &rq->fence.flags);
126 list_add_tail(&rq->signal_link, &signal); 124 list_add_tail(&rq->signal_link, &signal);
127 } 125 }
128 126
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index ca705546a0ab..14d580cdefd3 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -3568,6 +3568,13 @@ static void intel_ddi_update_pipe(struct intel_encoder *encoder,
3568{ 3568{
3569 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) 3569 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
3570 intel_ddi_update_pipe_dp(encoder, crtc_state, conn_state); 3570 intel_ddi_update_pipe_dp(encoder, crtc_state, conn_state);
3571
3572 if (conn_state->content_protection ==
3573 DRM_MODE_CONTENT_PROTECTION_DESIRED)
3574 intel_hdcp_enable(to_intel_connector(conn_state->connector));
3575 else if (conn_state->content_protection ==
3576 DRM_MODE_CONTENT_PROTECTION_UNDESIRED)
3577 intel_hdcp_disable(to_intel_connector(conn_state->connector));
3571} 3578}
3572 3579
3573static void intel_ddi_set_fia_lane_count(struct intel_encoder *encoder, 3580static void intel_ddi_set_fia_lane_count(struct intel_encoder *encoder,
@@ -3962,12 +3969,7 @@ static int modeset_pipe(struct drm_crtc *crtc,
3962 goto out; 3969 goto out;
3963 3970
3964 ret = drm_atomic_commit(state); 3971 ret = drm_atomic_commit(state);
3965 if (ret) 3972out:
3966 goto out;
3967
3968 return 0;
3969
3970 out:
3971 drm_atomic_state_put(state); 3973 drm_atomic_state_put(state);
3972 3974
3973 return ret; 3975 return ret;
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/selftests/i915_gem_context.c
index d00d0bb07784..7eb58a9d1319 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_context.c
@@ -710,47 +710,45 @@ __sseu_prepare(struct drm_i915_private *i915,
710 unsigned int flags, 710 unsigned int flags,
711 struct i915_gem_context *ctx, 711 struct i915_gem_context *ctx,
712 struct intel_engine_cs *engine, 712 struct intel_engine_cs *engine,
713 struct igt_spinner **spin_out) 713 struct igt_spinner **spin)
714{ 714{
715 int ret = 0; 715 struct i915_request *rq;
716 716 int ret;
717 if (flags & (TEST_BUSY | TEST_RESET)) {
718 struct igt_spinner *spin;
719 struct i915_request *rq;
720 717
721 spin = kzalloc(sizeof(*spin), GFP_KERNEL); 718 *spin = NULL;
722 if (!spin) { 719 if (!(flags & (TEST_BUSY | TEST_RESET)))
723 ret = -ENOMEM; 720 return 0;
724 goto out;
725 }
726 721
727 ret = igt_spinner_init(spin, i915); 722 *spin = kzalloc(sizeof(**spin), GFP_KERNEL);
728 if (ret) 723 if (!*spin)
729 return ret; 724 return -ENOMEM;
730 725
731 rq = igt_spinner_create_request(spin, ctx, engine, MI_NOOP); 726 ret = igt_spinner_init(*spin, i915);
732 if (IS_ERR(rq)) { 727 if (ret)
733 ret = PTR_ERR(rq); 728 goto err_free;
734 igt_spinner_fini(spin);
735 kfree(spin);
736 goto out;
737 }
738 729
739 i915_request_add(rq); 730 rq = igt_spinner_create_request(*spin, ctx, engine, MI_NOOP);
731 if (IS_ERR(rq)) {
732 ret = PTR_ERR(rq);
733 goto err_fini;
734 }
740 735
741 if (!igt_wait_for_spinner(spin, rq)) { 736 i915_request_add(rq);
742 pr_err("%s: Spinner failed to start!\n", name);
743 igt_spinner_end(spin);
744 igt_spinner_fini(spin);
745 kfree(spin);
746 ret = -ETIMEDOUT;
747 goto out;
748 }
749 737
750 *spin_out = spin; 738 if (!igt_wait_for_spinner(*spin, rq)) {
739 pr_err("%s: Spinner failed to start!\n", name);
740 ret = -ETIMEDOUT;
741 goto err_end;
751 } 742 }
752 743
753out: 744 return 0;
745
746err_end:
747 igt_spinner_end(*spin);
748err_fini:
749 igt_spinner_fini(*spin);
750err_free:
751 kfree(fetch_and_zero(spin));
754 return ret; 752 return ret;
755} 753}
756 754
@@ -897,22 +895,23 @@ __sseu_test(struct drm_i915_private *i915,
897 895
898 ret = __sseu_prepare(i915, name, flags, ctx, engine, &spin); 896 ret = __sseu_prepare(i915, name, flags, ctx, engine, &spin);
899 if (ret) 897 if (ret)
900 goto out; 898 goto out_context;
901 899
902 ret = __i915_gem_context_reconfigure_sseu(ctx, engine, sseu); 900 ret = __i915_gem_context_reconfigure_sseu(ctx, engine, sseu);
903 if (ret) 901 if (ret)
904 goto out; 902 goto out_spin;
905 903
906 ret = __sseu_finish(i915, name, flags, ctx, kctx, engine, obj, 904 ret = __sseu_finish(i915, name, flags, ctx, kctx, engine, obj,
907 hweight32(sseu.slice_mask), spin); 905 hweight32(sseu.slice_mask), spin);
908 906
909out: 907out_spin:
910 if (spin) { 908 if (spin) {
911 igt_spinner_end(spin); 909 igt_spinner_end(spin);
912 igt_spinner_fini(spin); 910 igt_spinner_fini(spin);
913 kfree(spin); 911 kfree(spin);
914 } 912 }
915 913
914out_context:
916 kernel_context_close(kctx); 915 kernel_context_close(kctx);
917 916
918 return ret; 917 return ret;
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/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c
index bb81e310eb6d..578d867a81d5 100644
--- a/drivers/gpu/drm/qxl/qxl_drv.c
+++ b/drivers/gpu/drm/qxl/qxl_drv.c
@@ -79,6 +79,10 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
79 if (ret) 79 if (ret)
80 goto free_dev; 80 goto free_dev;
81 81
82 ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "qxl");
83 if (ret)
84 goto disable_pci;
85
82 ret = qxl_device_init(qdev, &qxl_driver, pdev); 86 ret = qxl_device_init(qdev, &qxl_driver, pdev);
83 if (ret) 87 if (ret)
84 goto disable_pci; 88 goto disable_pci;
@@ -94,7 +98,6 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
94 if (ret) 98 if (ret)
95 goto modeset_cleanup; 99 goto modeset_cleanup;
96 100
97 drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "qxl");
98 drm_fbdev_generic_setup(&qdev->ddev, 32); 101 drm_fbdev_generic_setup(&qdev->ddev, 32);
99 return 0; 102 return 0;
100 103
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/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index dc8e039bfab5..f2f3ef8af271 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -48,6 +48,8 @@
48#include <linux/miscdevice.h> 48#include <linux/miscdevice.h>
49#include <linux/slab.h> 49#include <linux/slab.h>
50#include <linux/screen_info.h> 50#include <linux/screen_info.h>
51#include <linux/vt.h>
52#include <linux/console.h>
51 53
52#include <linux/uaccess.h> 54#include <linux/uaccess.h>
53 55
@@ -168,6 +170,53 @@ void vga_set_default_device(struct pci_dev *pdev)
168 vga_default = pci_dev_get(pdev); 170 vga_default = pci_dev_get(pdev);
169} 171}
170 172
173/**
174 * vga_remove_vgacon - deactivete vga console
175 *
176 * Unbind and unregister vgacon in case pdev is the default vga
177 * device. Can be called by gpu drivers on initialization to make
178 * sure vga register access done by vgacon will not disturb the
179 * device.
180 *
181 * @pdev: pci device.
182 */
183#if !defined(CONFIG_VGA_CONSOLE)
184int vga_remove_vgacon(struct pci_dev *pdev)
185{
186 return 0;
187}
188#elif !defined(CONFIG_DUMMY_CONSOLE)
189int vga_remove_vgacon(struct pci_dev *pdev)
190{
191 return -ENODEV;
192}
193#else
194int vga_remove_vgacon(struct pci_dev *pdev)
195{
196 int ret = 0;
197
198 if (pdev != vga_default)
199 return 0;
200 vgaarb_info(&pdev->dev, "deactivate vga console\n");
201
202 console_lock();
203 if (con_is_bound(&vga_con))
204 ret = do_take_over_console(&dummy_con, 0,
205 MAX_NR_CONSOLES - 1, 1);
206 if (ret == 0) {
207 ret = do_unregister_con_driver(&vga_con);
208
209 /* Ignore "already unregistered". */
210 if (ret == -ENODEV)
211 ret = 0;
212 }
213 console_unlock();
214
215 return ret;
216}
217#endif
218EXPORT_SYMBOL(vga_remove_vgacon);
219
171static inline void vga_irq_set_state(struct vga_device *vgadev, bool state) 220static inline void vga_irq_set_state(struct vga_device *vgadev, bool state)
172{ 221{
173 if (vgadev->irq_set_state) 222 if (vgadev->irq_set_state)
diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x.c
index 9a63e87ea5f3..be302ec5f66b 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x.c
@@ -871,7 +871,7 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
871 } 871 }
872 872
873 pm_runtime_put(&adev->dev); 873 pm_runtime_put(&adev->dev);
874 dev_info(dev, "%s initialized\n", (char *)id->data); 874 dev_info(dev, "%s initialized\n", (char *)coresight_get_uci_data(id));
875 if (boot_enable) { 875 if (boot_enable) {
876 coresight_enable(drvdata->csdev); 876 coresight_enable(drvdata->csdev);
877 drvdata->boot_enable = true; 877 drvdata->boot_enable = true;
@@ -915,36 +915,18 @@ static const struct dev_pm_ops etm_dev_pm_ops = {
915}; 915};
916 916
917static const struct amba_id etm_ids[] = { 917static const struct amba_id etm_ids[] = {
918 { /* ETM 3.3 */ 918 /* ETM 3.3 */
919 .id = 0x000bb921, 919 CS_AMBA_ID_DATA(0x000bb921, "ETM 3.3"),
920 .mask = 0x000fffff, 920 /* ETM 3.5 - Cortex-A5 */
921 .data = "ETM 3.3", 921 CS_AMBA_ID_DATA(0x000bb955, "ETM 3.5"),
922 }, 922 /* ETM 3.5 */
923 { /* ETM 3.5 - Cortex-A5 */ 923 CS_AMBA_ID_DATA(0x000bb956, "ETM 3.5"),
924 .id = 0x000bb955, 924 /* PTM 1.0 */
925 .mask = 0x000fffff, 925 CS_AMBA_ID_DATA(0x000bb950, "PTM 1.0"),
926 .data = "ETM 3.5", 926 /* PTM 1.1 */
927 }, 927 CS_AMBA_ID_DATA(0x000bb95f, "PTM 1.1"),
928 { /* ETM 3.5 */ 928 /* PTM 1.1 Qualcomm */
929 .id = 0x000bb956, 929 CS_AMBA_ID_DATA(0x000b006f, "PTM 1.1"),
930 .mask = 0x000fffff,
931 .data = "ETM 3.5",
932 },
933 { /* PTM 1.0 */
934 .id = 0x000bb950,
935 .mask = 0x000fffff,
936 .data = "PTM 1.0",
937 },
938 { /* PTM 1.1 */
939 .id = 0x000bb95f,
940 .mask = 0x000fffff,
941 .data = "PTM 1.1",
942 },
943 { /* PTM 1.1 Qualcomm */
944 .id = 0x000b006f,
945 .mask = 0x000fffff,
946 .data = "PTM 1.1",
947 },
948 { 0, 0}, 930 { 0, 0},
949}; 931};
950 932
diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c
index fe76b176974a..08ce37c9475d 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x.c
@@ -1068,18 +1068,21 @@ err_arch_supported:
1068 return ret; 1068 return ret;
1069} 1069}
1070 1070
1071#define ETM4x_AMBA_ID(pid) \ 1071static struct amba_cs_uci_id uci_id_etm4[] = {
1072 { \ 1072 {
1073 .id = pid, \ 1073 /* ETMv4 UCI data */
1074 .mask = 0x000fffff, \ 1074 .devarch = 0x47704a13,
1075 .devarch_mask = 0xfff0ffff,
1076 .devtype = 0x00000013,
1075 } 1077 }
1078};
1076 1079
1077static const struct amba_id etm4_ids[] = { 1080static const struct amba_id etm4_ids[] = {
1078 ETM4x_AMBA_ID(0x000bb95d), /* Cortex-A53 */ 1081 CS_AMBA_ID(0x000bb95d), /* Cortex-A53 */
1079 ETM4x_AMBA_ID(0x000bb95e), /* Cortex-A57 */ 1082 CS_AMBA_ID(0x000bb95e), /* Cortex-A57 */
1080 ETM4x_AMBA_ID(0x000bb95a), /* Cortex-A72 */ 1083 CS_AMBA_ID(0x000bb95a), /* Cortex-A72 */
1081 ETM4x_AMBA_ID(0x000bb959), /* Cortex-A73 */ 1084 CS_AMBA_ID(0x000bb959), /* Cortex-A73 */
1082 ETM4x_AMBA_ID(0x000bb9da), /* Cortex-A35 */ 1085 CS_AMBA_UCI_ID(0x000bb9da, uci_id_etm4), /* Cortex-A35 */
1083 {}, 1086 {},
1084}; 1087};
1085 1088
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index b936c6d7e13f..e0684d06e9ee 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -6,6 +6,7 @@
6#ifndef _CORESIGHT_PRIV_H 6#ifndef _CORESIGHT_PRIV_H
7#define _CORESIGHT_PRIV_H 7#define _CORESIGHT_PRIV_H
8 8
9#include <linux/amba/bus.h>
9#include <linux/bitops.h> 10#include <linux/bitops.h>
10#include <linux/io.h> 11#include <linux/io.h>
11#include <linux/coresight.h> 12#include <linux/coresight.h>
@@ -160,4 +161,43 @@ static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
160static inline int etm_writel_cp14(u32 off, u32 val) { return 0; } 161static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
161#endif 162#endif
162 163
164/*
165 * Macros and inline functions to handle CoreSight UCI data and driver
166 * private data in AMBA ID table entries, and extract data values.
167 */
168
169/* coresight AMBA ID, no UCI, no driver data: id table entry */
170#define CS_AMBA_ID(pid) \
171 { \
172 .id = pid, \
173 .mask = 0x000fffff, \
174 }
175
176/* coresight AMBA ID, UCI with driver data only: id table entry. */
177#define CS_AMBA_ID_DATA(pid, dval) \
178 { \
179 .id = pid, \
180 .mask = 0x000fffff, \
181 .data = (void *)&(struct amba_cs_uci_id) \
182 { \
183 .data = (void *)dval, \
184 } \
185 }
186
187/* coresight AMBA ID, full UCI structure: id table entry. */
188#define CS_AMBA_UCI_ID(pid, uci_ptr) \
189 { \
190 .id = pid, \
191 .mask = 0x000fffff, \
192 .data = uci_ptr \
193 }
194
195/* extract the data value from a UCI structure given amba_id pointer. */
196static inline void *coresight_get_uci_data(const struct amba_id *id)
197{
198 if (id->data)
199 return ((struct amba_cs_uci_id *)(id->data))->data;
200 return 0;
201}
202
163#endif 203#endif
diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
index f07825df5c7a..9f8a844ed7aa 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -870,7 +870,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
870 870
871 pm_runtime_put(&adev->dev); 871 pm_runtime_put(&adev->dev);
872 872
873 dev_info(dev, "%s initialized\n", (char *)id->data); 873 dev_info(dev, "%s initialized\n", (char *)coresight_get_uci_data(id));
874 return 0; 874 return 0;
875 875
876stm_unregister: 876stm_unregister:
@@ -905,16 +905,8 @@ static const struct dev_pm_ops stm_dev_pm_ops = {
905}; 905};
906 906
907static const struct amba_id stm_ids[] = { 907static const struct amba_id stm_ids[] = {
908 { 908 CS_AMBA_ID_DATA(0x000bb962, "STM32"),
909 .id = 0x000bb962, 909 CS_AMBA_ID_DATA(0x000bb963, "STM500"),
910 .mask = 0x000fffff,
911 .data = "STM32",
912 },
913 {
914 .id = 0x000bb963,
915 .mask = 0x000fffff,
916 .data = "STM500",
917 },
918 { 0, 0}, 910 { 0, 0},
919}; 911};
920 912
diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c
index ea249f0bcd73..2a02da3d630f 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc.c
@@ -443,7 +443,8 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
443 desc.type = CORESIGHT_DEV_TYPE_SINK; 443 desc.type = CORESIGHT_DEV_TYPE_SINK;
444 desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER; 444 desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
445 desc.ops = &tmc_etr_cs_ops; 445 desc.ops = &tmc_etr_cs_ops;
446 ret = tmc_etr_setup_caps(drvdata, devid, id->data); 446 ret = tmc_etr_setup_caps(drvdata, devid,
447 coresight_get_uci_data(id));
447 if (ret) 448 if (ret)
448 goto out; 449 goto out;
449 break; 450 break;
@@ -475,26 +476,13 @@ out:
475} 476}
476 477
477static const struct amba_id tmc_ids[] = { 478static const struct amba_id tmc_ids[] = {
478 { 479 CS_AMBA_ID(0x000bb961),
479 .id = 0x000bb961, 480 /* Coresight SoC 600 TMC-ETR/ETS */
480 .mask = 0x000fffff, 481 CS_AMBA_ID_DATA(0x000bb9e8, (unsigned long)CORESIGHT_SOC_600_ETR_CAPS),
481 }, 482 /* Coresight SoC 600 TMC-ETB */
482 { 483 CS_AMBA_ID(0x000bb9e9),
483 /* Coresight SoC 600 TMC-ETR/ETS */ 484 /* Coresight SoC 600 TMC-ETF */
484 .id = 0x000bb9e8, 485 CS_AMBA_ID(0x000bb9ea),
485 .mask = 0x000fffff,
486 .data = (void *)(unsigned long)CORESIGHT_SOC_600_ETR_CAPS,
487 },
488 {
489 /* Coresight SoC 600 TMC-ETB */
490 .id = 0x000bb9e9,
491 .mask = 0x000fffff,
492 },
493 {
494 /* Coresight SoC 600 TMC-ETF */
495 .id = 0x000bb9ea,
496 .mask = 0x000fffff,
497 },
498 { 0, 0}, 486 { 0, 0},
499}; 487};
500 488
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index ead5e7de3e4d..416f89b8f881 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -86,7 +86,6 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
86 struct i2c_timings *t = &dev->timings; 86 struct i2c_timings *t = &dev->timings;
87 u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0; 87 u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0;
88 88
89 dev->adapter.nr = -1;
90 dev->tx_fifo_depth = 32; 89 dev->tx_fifo_depth = 32;
91 dev->rx_fifo_depth = 32; 90 dev->rx_fifo_depth = 32;
92 91
@@ -219,7 +218,7 @@ static void i2c_dw_configure_slave(struct dw_i2c_dev *dev)
219 dev->mode = DW_IC_SLAVE; 218 dev->mode = DW_IC_SLAVE;
220} 219}
221 220
222static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id) 221static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev)
223{ 222{
224 u32 param, tx_fifo_depth, rx_fifo_depth; 223 u32 param, tx_fifo_depth, rx_fifo_depth;
225 224
@@ -233,7 +232,6 @@ static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id)
233 if (!dev->tx_fifo_depth) { 232 if (!dev->tx_fifo_depth) {
234 dev->tx_fifo_depth = tx_fifo_depth; 233 dev->tx_fifo_depth = tx_fifo_depth;
235 dev->rx_fifo_depth = rx_fifo_depth; 234 dev->rx_fifo_depth = rx_fifo_depth;
236 dev->adapter.nr = id;
237 } else if (tx_fifo_depth >= 2) { 235 } else if (tx_fifo_depth >= 2) {
238 dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth, 236 dev->tx_fifo_depth = min_t(u32, dev->tx_fifo_depth,
239 tx_fifo_depth); 237 tx_fifo_depth);
@@ -358,13 +356,14 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
358 div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000); 356 div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000);
359 } 357 }
360 358
361 dw_i2c_set_fifo_size(dev, pdev->id); 359 dw_i2c_set_fifo_size(dev);
362 360
363 adap = &dev->adapter; 361 adap = &dev->adapter;
364 adap->owner = THIS_MODULE; 362 adap->owner = THIS_MODULE;
365 adap->class = I2C_CLASS_DEPRECATED; 363 adap->class = I2C_CLASS_DEPRECATED;
366 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 364 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
367 adap->dev.of_node = pdev->dev.of_node; 365 adap->dev.of_node = pdev->dev.of_node;
366 adap->nr = -1;
368 367
369 dev_pm_set_driver_flags(&pdev->dev, 368 dev_pm_set_driver_flags(&pdev->dev,
370 DPM_FLAG_SMART_PREPARE | 369 DPM_FLAG_SMART_PREPARE |
diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 660de1ee68ed..684d651612b3 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -503,7 +503,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
503 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); 503 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG);
504 writel(I2C_DMA_CON_RX, i2c->pdmabase + OFFSET_CON); 504 writel(I2C_DMA_CON_RX, i2c->pdmabase + OFFSET_CON);
505 505
506 dma_rd_buf = i2c_get_dma_safe_msg_buf(msgs, 0); 506 dma_rd_buf = i2c_get_dma_safe_msg_buf(msgs, 1);
507 if (!dma_rd_buf) 507 if (!dma_rd_buf)
508 return -ENOMEM; 508 return -ENOMEM;
509 509
@@ -526,7 +526,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
526 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); 526 writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG);
527 writel(I2C_DMA_CON_TX, i2c->pdmabase + OFFSET_CON); 527 writel(I2C_DMA_CON_TX, i2c->pdmabase + OFFSET_CON);
528 528
529 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 0); 529 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1);
530 if (!dma_wr_buf) 530 if (!dma_wr_buf)
531 return -ENOMEM; 531 return -ENOMEM;
532 532
@@ -549,7 +549,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
549 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_INT_FLAG); 549 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_INT_FLAG);
550 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_CON); 550 writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_CON);
551 551
552 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 0); 552 dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1);
553 if (!dma_wr_buf) 553 if (!dma_wr_buf)
554 return -ENOMEM; 554 return -ENOMEM;
555 555
@@ -561,7 +561,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
561 return -ENOMEM; 561 return -ENOMEM;
562 } 562 }
563 563
564 dma_rd_buf = i2c_get_dma_safe_msg_buf((msgs + 1), 0); 564 dma_rd_buf = i2c_get_dma_safe_msg_buf((msgs + 1), 1);
565 if (!dma_rd_buf) { 565 if (!dma_rd_buf) {
566 dma_unmap_single(i2c->dev, wpaddr, 566 dma_unmap_single(i2c->dev, wpaddr,
567 msgs->len, DMA_TO_DEVICE); 567 msgs->len, DMA_TO_DEVICE);
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index dd52a068b140..a7578f6da979 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -363,9 +363,6 @@ static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv)
363 struct dma_chan *chan = priv->dma_direction == DMA_FROM_DEVICE 363 struct dma_chan *chan = priv->dma_direction == DMA_FROM_DEVICE
364 ? priv->dma_rx : priv->dma_tx; 364 ? priv->dma_rx : priv->dma_tx;
365 365
366 /* Disable DMA Master Received/Transmitted */
367 rcar_i2c_write(priv, ICDMAER, 0);
368
369 dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg), 366 dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg),
370 sg_dma_len(&priv->sg), priv->dma_direction); 367 sg_dma_len(&priv->sg), priv->dma_direction);
371 368
@@ -375,6 +372,9 @@ static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv)
375 priv->flags |= ID_P_NO_RXDMA; 372 priv->flags |= ID_P_NO_RXDMA;
376 373
377 priv->dma_direction = DMA_NONE; 374 priv->dma_direction = DMA_NONE;
375
376 /* Disable DMA Master Received/Transmitted, must be last! */
377 rcar_i2c_write(priv, ICDMAER, 0);
378} 378}
379 379
380static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv) 380static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv)
@@ -611,6 +611,15 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)
611 return true; 611 return true;
612} 612}
613 613
614/*
615 * This driver has a lock-free design because there are IP cores (at least
616 * R-Car Gen2) which have an inherent race condition in their hardware design.
617 * There, we need to clear RCAR_BUS_MASK_DATA bits as soon as possible after
618 * the interrupt was generated, otherwise an unwanted repeated message gets
619 * generated. It turned out that taking a spinlock at the beginning of the ISR
620 * was already causing repeated messages. Thus, this driver was converted to
621 * the now lockless behaviour. Please keep this in mind when hacking the driver.
622 */
614static irqreturn_t rcar_i2c_irq(int irq, void *ptr) 623static irqreturn_t rcar_i2c_irq(int irq, void *ptr)
615{ 624{
616 struct rcar_i2c_priv *priv = ptr; 625 struct rcar_i2c_priv *priv = ptr;
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 1e6805b5cef2..a57aa4fe51a4 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -478,7 +478,7 @@ static int sis630_setup(struct pci_dev *sis630_dev)
478 if (!request_region(smbus_base + SMB_STS, SIS630_SMB_IOREGION, 478 if (!request_region(smbus_base + SMB_STS, SIS630_SMB_IOREGION,
479 sis630_driver.name)) { 479 sis630_driver.name)) {
480 dev_err(&sis630_dev->dev, 480 dev_err(&sis630_dev->dev,
481 "I/O Region 0x%04hx-0x%04hx for SMBus already in use.\n", 481 "I/O Region 0x%04x-0x%04x for SMBus already in use.\n",
482 smbus_base + SMB_STS, 482 smbus_base + SMB_STS,
483 smbus_base + SMB_STS + SIS630_SMB_IOREGION - 1); 483 smbus_base + SMB_STS + SIS630_SMB_IOREGION - 1);
484 retval = -EBUSY; 484 retval = -EBUSY;
@@ -528,7 +528,7 @@ static int sis630_probe(struct pci_dev *dev, const struct pci_device_id *id)
528 sis630_adapter.dev.parent = &dev->dev; 528 sis630_adapter.dev.parent = &dev->dev;
529 529
530 snprintf(sis630_adapter.name, sizeof(sis630_adapter.name), 530 snprintf(sis630_adapter.name, sizeof(sis630_adapter.name),
531 "SMBus SIS630 adapter at %04hx", smbus_base + SMB_STS); 531 "SMBus SIS630 adapter at %04x", smbus_base + SMB_STS);
532 532
533 return i2c_add_adapter(&sis630_adapter); 533 return i2c_add_adapter(&sis630_adapter);
534} 534}
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 13e1213561d4..4284fc991cfd 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -432,7 +432,7 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
432 STM32F7_I2C_ANALOG_FILTER_DELAY_MAX : 0); 432 STM32F7_I2C_ANALOG_FILTER_DELAY_MAX : 0);
433 dnf_delay = setup->dnf * i2cclk; 433 dnf_delay = setup->dnf * i2cclk;
434 434
435 sdadel_min = setup->fall_time - i2c_specs[setup->speed].hddat_min - 435 sdadel_min = i2c_specs[setup->speed].hddat_min + setup->fall_time -
436 af_delay_min - (setup->dnf + 3) * i2cclk; 436 af_delay_min - (setup->dnf + 3) * i2cclk;
437 437
438 sdadel_max = i2c_specs[setup->speed].vddat_max - setup->rise_time - 438 sdadel_max = i2c_specs[setup->speed].vddat_max - setup->rise_time -
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index cb6c5cb0df0b..38af18645133 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -2258,7 +2258,8 @@ EXPORT_SYMBOL(i2c_put_adapter);
2258/** 2258/**
2259 * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg 2259 * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg
2260 * @msg: the message to be checked 2260 * @msg: the message to be checked
2261 * @threshold: the minimum number of bytes for which using DMA makes sense 2261 * @threshold: the minimum number of bytes for which using DMA makes sense.
2262 * Should at least be 1.
2262 * 2263 *
2263 * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO. 2264 * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO.
2264 * Or a valid pointer to be used with DMA. After use, release it by 2265 * Or a valid pointer to be used with DMA. After use, release it by
@@ -2268,7 +2269,11 @@ EXPORT_SYMBOL(i2c_put_adapter);
2268 */ 2269 */
2269u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold) 2270u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
2270{ 2271{
2271 if (msg->len < threshold) 2272 /* also skip 0-length msgs for bogus thresholds of 0 */
2273 if (!threshold)
2274 pr_debug("DMA buffer for addr=0x%02x with length 0 is bogus\n",
2275 msg->addr);
2276 if (msg->len < threshold || msg->len == 0)
2272 return NULL; 2277 return NULL;
2273 2278
2274 if (msg->flags & I2C_M_DMA_SAFE) 2279 if (msg->flags & I2C_M_DMA_SAFE)
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 6b0760dafb3e..21cb088d6687 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -140,10 +140,14 @@ static struct lock_class_key reserved_rbtree_key;
140static inline int match_hid_uid(struct device *dev, 140static inline int match_hid_uid(struct device *dev,
141 struct acpihid_map_entry *entry) 141 struct acpihid_map_entry *entry)
142{ 142{
143 struct acpi_device *adev = ACPI_COMPANION(dev);
143 const char *hid, *uid; 144 const char *hid, *uid;
144 145
145 hid = acpi_device_hid(ACPI_COMPANION(dev)); 146 if (!adev)
146 uid = acpi_device_uid(ACPI_COMPANION(dev)); 147 return -ENODEV;
148
149 hid = acpi_device_hid(adev);
150 uid = acpi_device_uid(adev);
147 151
148 if (!hid || !(*hid)) 152 if (!hid || !(*hid))
149 return -ENODEV; 153 return -ENODEV;
@@ -2604,7 +2608,12 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
2604 2608
2605 /* Everything is mapped - write the right values into s->dma_address */ 2609 /* Everything is mapped - write the right values into s->dma_address */
2606 for_each_sg(sglist, s, nelems, i) { 2610 for_each_sg(sglist, s, nelems, i) {
2607 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);
2608 s->dma_length = s->length; 2617 s->dma_length = s->length;
2609 } 2618 }
2610 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/lightnvm/pblk-rl.c b/drivers/lightnvm/pblk-rl.c
index b014957dde0b..a5f8bc2defbc 100644
--- a/drivers/lightnvm/pblk-rl.c
+++ b/drivers/lightnvm/pblk-rl.c
@@ -233,10 +233,15 @@ void pblk_rl_init(struct pblk_rl *rl, int budget, int threshold)
233 /* To start with, all buffer is available to user I/O writers */ 233 /* To start with, all buffer is available to user I/O writers */
234 rl->rb_budget = budget; 234 rl->rb_budget = budget;
235 rl->rb_user_max = budget; 235 rl->rb_user_max = budget;
236 rl->rb_max_io = threshold ? (budget - threshold) : (budget - 1);
237 rl->rb_gc_max = 0; 236 rl->rb_gc_max = 0;
238 rl->rb_state = PBLK_RL_HIGH; 237 rl->rb_state = PBLK_RL_HIGH;
239 238
239 /* Maximize I/O size and ansure that back threshold is respected */
240 if (threshold)
241 rl->rb_max_io = budget - pblk->min_write_pgs_data - threshold;
242 else
243 rl->rb_max_io = budget - pblk->min_write_pgs_data - 1;
244
240 atomic_set(&rl->rb_user_cnt, 0); 245 atomic_set(&rl->rb_user_cnt, 0);
241 atomic_set(&rl->rb_gc_cnt, 0); 246 atomic_set(&rl->rb_gc_cnt, 0);
242 atomic_set(&rl->rb_space, -1); 247 atomic_set(&rl->rb_space, -1);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index abb5d382f64d..3b6880dd648d 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3939,6 +3939,8 @@ static int raid10_run(struct mddev *mddev)
3939 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); 3939 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
3940 mddev->sync_thread = md_register_thread(md_do_sync, mddev, 3940 mddev->sync_thread = md_register_thread(md_do_sync, mddev,
3941 "reshape"); 3941 "reshape");
3942 if (!mddev->sync_thread)
3943 goto out_free_conf;
3942 } 3944 }
3943 3945
3944 return 0; 3946 return 0;
@@ -4670,7 +4672,6 @@ read_more:
4670 atomic_inc(&r10_bio->remaining); 4672 atomic_inc(&r10_bio->remaining);
4671 read_bio->bi_next = NULL; 4673 read_bio->bi_next = NULL;
4672 generic_make_request(read_bio); 4674 generic_make_request(read_bio);
4673 sector_nr += nr_sectors;
4674 sectors_done += nr_sectors; 4675 sectors_done += nr_sectors;
4675 if (sector_nr <= last) 4676 if (sector_nr <= last)
4676 goto read_more; 4677 goto read_more;
diff --git a/drivers/md/raid5-log.h b/drivers/md/raid5-log.h
index bfb811407061..43c714a8798c 100644
--- a/drivers/md/raid5-log.h
+++ b/drivers/md/raid5-log.h
@@ -45,6 +45,7 @@ extern void ppl_stripe_write_finished(struct stripe_head *sh);
45extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add); 45extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add);
46extern void ppl_quiesce(struct r5conf *conf, int quiesce); 46extern void ppl_quiesce(struct r5conf *conf, int quiesce);
47extern int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio); 47extern int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio);
48extern struct md_sysfs_entry ppl_write_hint;
48 49
49static inline bool raid5_has_log(struct r5conf *conf) 50static inline bool raid5_has_log(struct r5conf *conf)
50{ 51{
diff --git a/drivers/md/raid5-ppl.c b/drivers/md/raid5-ppl.c
index 0b096ddc9c1e..17e9e7d51097 100644
--- a/drivers/md/raid5-ppl.c
+++ b/drivers/md/raid5-ppl.c
@@ -20,6 +20,7 @@
20#include <linux/raid/md_p.h> 20#include <linux/raid/md_p.h>
21#include "md.h" 21#include "md.h"
22#include "raid5.h" 22#include "raid5.h"
23#include "raid5-log.h"
23 24
24/* 25/*
25 * PPL consists of a 4KB header (struct ppl_header) and at least 128KB for 26 * PPL consists of a 4KB header (struct ppl_header) and at least 128KB for
@@ -115,6 +116,8 @@ struct ppl_conf {
115 /* stripes to retry if failed to allocate io_unit */ 116 /* stripes to retry if failed to allocate io_unit */
116 struct list_head no_mem_stripes; 117 struct list_head no_mem_stripes;
117 spinlock_t no_mem_stripes_lock; 118 spinlock_t no_mem_stripes_lock;
119
120 unsigned short write_hint;
118}; 121};
119 122
120struct ppl_log { 123struct ppl_log {
@@ -474,6 +477,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io)
474 bio_set_dev(bio, log->rdev->bdev); 477 bio_set_dev(bio, log->rdev->bdev);
475 bio->bi_iter.bi_sector = log->next_io_sector; 478 bio->bi_iter.bi_sector = log->next_io_sector;
476 bio_add_page(bio, io->header_page, PAGE_SIZE, 0); 479 bio_add_page(bio, io->header_page, PAGE_SIZE, 0);
480 bio->bi_write_hint = ppl_conf->write_hint;
477 481
478 pr_debug("%s: log->current_io_sector: %llu\n", __func__, 482 pr_debug("%s: log->current_io_sector: %llu\n", __func__,
479 (unsigned long long)log->next_io_sector); 483 (unsigned long long)log->next_io_sector);
@@ -503,6 +507,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io)
503 bio = bio_alloc_bioset(GFP_NOIO, BIO_MAX_PAGES, 507 bio = bio_alloc_bioset(GFP_NOIO, BIO_MAX_PAGES,
504 &ppl_conf->bs); 508 &ppl_conf->bs);
505 bio->bi_opf = prev->bi_opf; 509 bio->bi_opf = prev->bi_opf;
510 bio->bi_write_hint = prev->bi_write_hint;
506 bio_copy_dev(bio, prev); 511 bio_copy_dev(bio, prev);
507 bio->bi_iter.bi_sector = bio_end_sector(prev); 512 bio->bi_iter.bi_sector = bio_end_sector(prev);
508 bio_add_page(bio, sh->ppl_page, PAGE_SIZE, 0); 513 bio_add_page(bio, sh->ppl_page, PAGE_SIZE, 0);
@@ -1407,6 +1412,7 @@ int ppl_init_log(struct r5conf *conf)
1407 atomic64_set(&ppl_conf->seq, 0); 1412 atomic64_set(&ppl_conf->seq, 0);
1408 INIT_LIST_HEAD(&ppl_conf->no_mem_stripes); 1413 INIT_LIST_HEAD(&ppl_conf->no_mem_stripes);
1409 spin_lock_init(&ppl_conf->no_mem_stripes_lock); 1414 spin_lock_init(&ppl_conf->no_mem_stripes_lock);
1415 ppl_conf->write_hint = RWF_WRITE_LIFE_NOT_SET;
1410 1416
1411 if (!mddev->external) { 1417 if (!mddev->external) {
1412 ppl_conf->signature = ~crc32c_le(~0, mddev->uuid, sizeof(mddev->uuid)); 1418 ppl_conf->signature = ~crc32c_le(~0, mddev->uuid, sizeof(mddev->uuid));
@@ -1501,3 +1507,60 @@ int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add)
1501 1507
1502 return ret; 1508 return ret;
1503} 1509}
1510
1511static ssize_t
1512ppl_write_hint_show(struct mddev *mddev, char *buf)
1513{
1514 size_t ret = 0;
1515 struct r5conf *conf;
1516 struct ppl_conf *ppl_conf = NULL;
1517
1518 spin_lock(&mddev->lock);
1519 conf = mddev->private;
1520 if (conf && raid5_has_ppl(conf))
1521 ppl_conf = conf->log_private;
1522 ret = sprintf(buf, "%d\n", ppl_conf ? ppl_conf->write_hint : 0);
1523 spin_unlock(&mddev->lock);
1524
1525 return ret;
1526}
1527
1528static ssize_t
1529ppl_write_hint_store(struct mddev *mddev, const char *page, size_t len)
1530{
1531 struct r5conf *conf;
1532 struct ppl_conf *ppl_conf;
1533 int err = 0;
1534 unsigned short new;
1535
1536 if (len >= PAGE_SIZE)
1537 return -EINVAL;
1538 if (kstrtou16(page, 10, &new))
1539 return -EINVAL;
1540
1541 err = mddev_lock(mddev);
1542 if (err)
1543 return err;
1544
1545 conf = mddev->private;
1546 if (!conf) {
1547 err = -ENODEV;
1548 } else if (raid5_has_ppl(conf)) {
1549 ppl_conf = conf->log_private;
1550 if (!ppl_conf)
1551 err = -EINVAL;
1552 else
1553 ppl_conf->write_hint = new;
1554 } else {
1555 err = -EINVAL;
1556 }
1557
1558 mddev_unlock(mddev);
1559
1560 return err ?: len;
1561}
1562
1563struct md_sysfs_entry
1564ppl_write_hint = __ATTR(ppl_write_hint, S_IRUGO | S_IWUSR,
1565 ppl_write_hint_show,
1566 ppl_write_hint_store);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 77ffd09be486..c033bfcb209e 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6650,6 +6650,7 @@ static struct attribute *raid5_attrs[] = {
6650 &raid5_skip_copy.attr, 6650 &raid5_skip_copy.attr,
6651 &raid5_rmw_level.attr, 6651 &raid5_rmw_level.attr,
6652 &r5c_journal_mode.attr, 6652 &r5c_journal_mode.attr,
6653 &ppl_write_hint.attr,
6653 NULL, 6654 NULL,
6654}; 6655};
6655static struct attribute_group raid5_attrs_group = { 6656static struct attribute_group raid5_attrs_group = {
@@ -7393,6 +7394,8 @@ static int raid5_run(struct mddev *mddev)
7393 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); 7394 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
7394 mddev->sync_thread = md_register_thread(md_do_sync, mddev, 7395 mddev->sync_thread = md_register_thread(md_do_sync, mddev,
7395 "reshape"); 7396 "reshape");
7397 if (!mddev->sync_thread)
7398 goto abort;
7396 } 7399 }
7397 7400
7398 /* Ok, everything is just fine now */ 7401 /* Ok, everything is just fine now */
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/ntb/hw/intel/ntb_hw_gen1.c b/drivers/ntb/hw/intel/ntb_hw_gen1.c
index 2ad263f708da..bb57ec239029 100644
--- a/drivers/ntb/hw/intel/ntb_hw_gen1.c
+++ b/drivers/ntb/hw/intel/ntb_hw_gen1.c
@@ -180,7 +180,7 @@ int ndev_mw_to_bar(struct intel_ntb_dev *ndev, int idx)
180 return ndev->reg->mw_bar[idx]; 180 return ndev->reg->mw_bar[idx];
181} 181}
182 182
183static inline int ndev_db_addr(struct intel_ntb_dev *ndev, 183void ndev_db_addr(struct intel_ntb_dev *ndev,
184 phys_addr_t *db_addr, resource_size_t *db_size, 184 phys_addr_t *db_addr, resource_size_t *db_size,
185 phys_addr_t reg_addr, unsigned long reg) 185 phys_addr_t reg_addr, unsigned long reg)
186{ 186{
@@ -196,8 +196,6 @@ static inline int ndev_db_addr(struct intel_ntb_dev *ndev,
196 *db_size = ndev->reg->db_size; 196 *db_size = ndev->reg->db_size;
197 dev_dbg(&ndev->ntb.pdev->dev, "Peer db size %llx\n", *db_size); 197 dev_dbg(&ndev->ntb.pdev->dev, "Peer db size %llx\n", *db_size);
198 } 198 }
199
200 return 0;
201} 199}
202 200
203u64 ndev_db_read(struct intel_ntb_dev *ndev, 201u64 ndev_db_read(struct intel_ntb_dev *ndev,
@@ -1111,13 +1109,28 @@ int intel_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
1111 ndev->self_reg->db_mask); 1109 ndev->self_reg->db_mask);
1112} 1110}
1113 1111
1114int intel_ntb_peer_db_addr(struct ntb_dev *ntb, phys_addr_t *db_addr, 1112static int intel_ntb_peer_db_addr(struct ntb_dev *ntb, phys_addr_t *db_addr,
1115 resource_size_t *db_size) 1113 resource_size_t *db_size, u64 *db_data, int db_bit)
1116{ 1114{
1115 u64 db_bits;
1117 struct intel_ntb_dev *ndev = ntb_ndev(ntb); 1116 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
1118 1117
1119 return ndev_db_addr(ndev, db_addr, db_size, ndev->peer_addr, 1118 if (unlikely(db_bit >= BITS_PER_LONG_LONG))
1119 return -EINVAL;
1120
1121 db_bits = BIT_ULL(db_bit);
1122
1123 if (unlikely(db_bits & ~ntb_ndev(ntb)->db_valid_mask))
1124 return -EINVAL;
1125
1126 ndev_db_addr(ndev, db_addr, db_size, ndev->peer_addr,
1120 ndev->peer_reg->db_bell); 1127 ndev->peer_reg->db_bell);
1128
1129 if (db_data)
1130 *db_data = db_bits;
1131
1132
1133 return 0;
1121} 1134}
1122 1135
1123static int intel_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits) 1136static int intel_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
diff --git a/drivers/ntb/hw/intel/ntb_hw_gen1.h b/drivers/ntb/hw/intel/ntb_hw_gen1.h
index ad8ec1444436..544cf5c06f4d 100644
--- a/drivers/ntb/hw/intel/ntb_hw_gen1.h
+++ b/drivers/ntb/hw/intel/ntb_hw_gen1.h
@@ -147,6 +147,9 @@ extern struct intel_b2b_addr xeon_b2b_dsd_addr;
147int ndev_init_isr(struct intel_ntb_dev *ndev, int msix_min, int msix_max, 147int ndev_init_isr(struct intel_ntb_dev *ndev, int msix_min, int msix_max,
148 int msix_shift, int total_shift); 148 int msix_shift, int total_shift);
149enum ntb_topo xeon_ppd_topo(struct intel_ntb_dev *ndev, u8 ppd); 149enum ntb_topo xeon_ppd_topo(struct intel_ntb_dev *ndev, u8 ppd);
150void ndev_db_addr(struct intel_ntb_dev *ndev,
151 phys_addr_t *db_addr, resource_size_t *db_size,
152 phys_addr_t reg_addr, unsigned long reg);
150u64 ndev_db_read(struct intel_ntb_dev *ndev, void __iomem *mmio); 153u64 ndev_db_read(struct intel_ntb_dev *ndev, void __iomem *mmio);
151int ndev_db_write(struct intel_ntb_dev *ndev, u64 db_bits, 154int ndev_db_write(struct intel_ntb_dev *ndev, u64 db_bits,
152 void __iomem *mmio); 155 void __iomem *mmio);
@@ -166,8 +169,6 @@ int intel_ntb_db_vector_count(struct ntb_dev *ntb);
166u64 intel_ntb_db_vector_mask(struct ntb_dev *ntb, int db_vector); 169u64 intel_ntb_db_vector_mask(struct ntb_dev *ntb, int db_vector);
167int intel_ntb_db_set_mask(struct ntb_dev *ntb, u64 db_bits); 170int intel_ntb_db_set_mask(struct ntb_dev *ntb, u64 db_bits);
168int intel_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits); 171int intel_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits);
169int intel_ntb_peer_db_addr(struct ntb_dev *ntb, phys_addr_t *db_addr,
170 resource_size_t *db_size);
171int intel_ntb_spad_is_unsafe(struct ntb_dev *ntb); 172int intel_ntb_spad_is_unsafe(struct ntb_dev *ntb);
172int intel_ntb_spad_count(struct ntb_dev *ntb); 173int intel_ntb_spad_count(struct ntb_dev *ntb);
173u32 intel_ntb_spad_read(struct ntb_dev *ntb, int idx); 174u32 intel_ntb_spad_read(struct ntb_dev *ntb, int idx);
diff --git a/drivers/ntb/hw/intel/ntb_hw_gen3.c b/drivers/ntb/hw/intel/ntb_hw_gen3.c
index b3fa24778f94..f475b56a3f49 100644
--- a/drivers/ntb/hw/intel/ntb_hw_gen3.c
+++ b/drivers/ntb/hw/intel/ntb_hw_gen3.c
@@ -532,6 +532,37 @@ static int intel_ntb3_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
532 return 0; 532 return 0;
533} 533}
534 534
535int intel_ntb3_peer_db_addr(struct ntb_dev *ntb, phys_addr_t *db_addr,
536 resource_size_t *db_size,
537 u64 *db_data, int db_bit)
538{
539 phys_addr_t db_addr_base;
540 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
541
542 if (unlikely(db_bit >= BITS_PER_LONG_LONG))
543 return -EINVAL;
544
545 if (unlikely(BIT_ULL(db_bit) & ~ntb_ndev(ntb)->db_valid_mask))
546 return -EINVAL;
547
548 ndev_db_addr(ndev, &db_addr_base, db_size, ndev->peer_addr,
549 ndev->peer_reg->db_bell);
550
551 if (db_addr) {
552 *db_addr = db_addr_base + (db_bit * 4);
553 dev_dbg(&ndev->ntb.pdev->dev, "Peer db addr %llx db bit %d\n",
554 *db_addr, db_bit);
555 }
556
557 if (db_data) {
558 *db_data = 1;
559 dev_dbg(&ndev->ntb.pdev->dev, "Peer db data %llx db bit %d\n",
560 *db_data, db_bit);
561 }
562
563 return 0;
564}
565
535static int intel_ntb3_peer_db_set(struct ntb_dev *ntb, u64 db_bits) 566static int intel_ntb3_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
536{ 567{
537 struct intel_ntb_dev *ndev = ntb_ndev(ntb); 568 struct intel_ntb_dev *ndev = ntb_ndev(ntb);
@@ -584,7 +615,7 @@ const struct ntb_dev_ops intel_ntb3_ops = {
584 .db_clear = intel_ntb3_db_clear, 615 .db_clear = intel_ntb3_db_clear,
585 .db_set_mask = intel_ntb_db_set_mask, 616 .db_set_mask = intel_ntb_db_set_mask,
586 .db_clear_mask = intel_ntb_db_clear_mask, 617 .db_clear_mask = intel_ntb_db_clear_mask,
587 .peer_db_addr = intel_ntb_peer_db_addr, 618 .peer_db_addr = intel_ntb3_peer_db_addr,
588 .peer_db_set = intel_ntb3_peer_db_set, 619 .peer_db_set = intel_ntb3_peer_db_set,
589 .spad_is_unsafe = intel_ntb_spad_is_unsafe, 620 .spad_is_unsafe = intel_ntb_spad_is_unsafe,
590 .spad_count = intel_ntb_spad_count, 621 .spad_count = intel_ntb_spad_count,
diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
index f2df2d39c65b..d905d368d28c 100644
--- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
+++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
@@ -236,6 +236,7 @@ static void switchtec_ntb_mw_clr_direct(struct switchtec_ntb *sndev, int idx)
236 ctl_val &= ~NTB_CTRL_BAR_DIR_WIN_EN; 236 ctl_val &= ~NTB_CTRL_BAR_DIR_WIN_EN;
237 iowrite32(ctl_val, &ctl->bar_entry[bar].ctl); 237 iowrite32(ctl_val, &ctl->bar_entry[bar].ctl);
238 iowrite32(0, &ctl->bar_entry[bar].win_size); 238 iowrite32(0, &ctl->bar_entry[bar].win_size);
239 iowrite32(0, &ctl->bar_ext_entry[bar].win_size);
239 iowrite64(sndev->self_partition, &ctl->bar_entry[bar].xlate_addr); 240 iowrite64(sndev->self_partition, &ctl->bar_entry[bar].xlate_addr);
240} 241}
241 242
@@ -258,7 +259,9 @@ static void switchtec_ntb_mw_set_direct(struct switchtec_ntb *sndev, int idx,
258 ctl_val |= NTB_CTRL_BAR_DIR_WIN_EN; 259 ctl_val |= NTB_CTRL_BAR_DIR_WIN_EN;
259 260
260 iowrite32(ctl_val, &ctl->bar_entry[bar].ctl); 261 iowrite32(ctl_val, &ctl->bar_entry[bar].ctl);
261 iowrite32(xlate_pos | size, &ctl->bar_entry[bar].win_size); 262 iowrite32(xlate_pos | (lower_32_bits(size) & 0xFFFFF000),
263 &ctl->bar_entry[bar].win_size);
264 iowrite32(upper_32_bits(size), &ctl->bar_ext_entry[bar].win_size);
262 iowrite64(sndev->self_partition | addr, 265 iowrite64(sndev->self_partition | addr,
263 &ctl->bar_entry[bar].xlate_addr); 266 &ctl->bar_entry[bar].xlate_addr);
264} 267}
@@ -679,11 +682,16 @@ static u64 switchtec_ntb_db_read_mask(struct ntb_dev *ntb)
679 682
680static int switchtec_ntb_peer_db_addr(struct ntb_dev *ntb, 683static int switchtec_ntb_peer_db_addr(struct ntb_dev *ntb,
681 phys_addr_t *db_addr, 684 phys_addr_t *db_addr,
682 resource_size_t *db_size) 685 resource_size_t *db_size,
686 u64 *db_data,
687 int db_bit)
683{ 688{
684 struct switchtec_ntb *sndev = ntb_sndev(ntb); 689 struct switchtec_ntb *sndev = ntb_sndev(ntb);
685 unsigned long offset; 690 unsigned long offset;
686 691
692 if (unlikely(db_bit >= BITS_PER_LONG_LONG))
693 return -EINVAL;
694
687 offset = (unsigned long)sndev->mmio_peer_dbmsg->odb - 695 offset = (unsigned long)sndev->mmio_peer_dbmsg->odb -
688 (unsigned long)sndev->stdev->mmio; 696 (unsigned long)sndev->stdev->mmio;
689 697
@@ -693,6 +701,8 @@ static int switchtec_ntb_peer_db_addr(struct ntb_dev *ntb,
693 *db_addr = pci_resource_start(ntb->pdev, 0) + offset; 701 *db_addr = pci_resource_start(ntb->pdev, 0) + offset;
694 if (db_size) 702 if (db_size)
695 *db_size = sizeof(u32); 703 *db_size = sizeof(u32);
704 if (db_data)
705 *db_data = BIT_ULL(db_bit) << sndev->db_peer_shift;
696 706
697 return 0; 707 return 0;
698} 708}
@@ -1025,7 +1035,9 @@ static int crosslink_setup_mws(struct switchtec_ntb *sndev, int ntb_lut_idx,
1025 ctl_val |= NTB_CTRL_BAR_DIR_WIN_EN; 1035 ctl_val |= NTB_CTRL_BAR_DIR_WIN_EN;
1026 1036
1027 iowrite32(ctl_val, &ctl->bar_entry[bar].ctl); 1037 iowrite32(ctl_val, &ctl->bar_entry[bar].ctl);
1028 iowrite32(xlate_pos | size, &ctl->bar_entry[bar].win_size); 1038 iowrite32(xlate_pos | (lower_32_bits(size) & 0xFFFFF000),
1039 &ctl->bar_entry[bar].win_size);
1040 iowrite32(upper_32_bits(size), &ctl->bar_ext_entry[bar].win_size);
1029 iowrite64(sndev->peer_partition | addr, 1041 iowrite64(sndev->peer_partition | addr,
1030 &ctl->bar_entry[bar].xlate_addr); 1042 &ctl->bar_entry[bar].xlate_addr);
1031 } 1043 }
@@ -1092,7 +1104,7 @@ static int crosslink_enum_partition(struct switchtec_ntb *sndev,
1092 1104
1093 dev_dbg(&sndev->stdev->dev, 1105 dev_dbg(&sndev->stdev->dev,
1094 "Crosslink BAR%d addr: %llx\n", 1106 "Crosslink BAR%d addr: %llx\n",
1095 i, bar_addr); 1107 i*2, bar_addr);
1096 1108
1097 if (bar_addr != bar_space * i) 1109 if (bar_addr != bar_space * i)
1098 continue; 1110 continue;
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 3bfdb4562408..d4f39ba1d976 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -144,7 +144,9 @@ struct ntb_transport_qp {
144 struct list_head tx_free_q; 144 struct list_head tx_free_q;
145 spinlock_t ntb_tx_free_q_lock; 145 spinlock_t ntb_tx_free_q_lock;
146 void __iomem *tx_mw; 146 void __iomem *tx_mw;
147 dma_addr_t tx_mw_phys; 147 phys_addr_t tx_mw_phys;
148 size_t tx_mw_size;
149 dma_addr_t tx_mw_dma_addr;
148 unsigned int tx_index; 150 unsigned int tx_index;
149 unsigned int tx_max_entry; 151 unsigned int tx_max_entry;
150 unsigned int tx_max_frame; 152 unsigned int tx_max_frame;
@@ -862,6 +864,9 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)
862 if (!nt->link_is_up) 864 if (!nt->link_is_up)
863 cancel_delayed_work_sync(&nt->link_work); 865 cancel_delayed_work_sync(&nt->link_work);
864 866
867 for (i = 0; i < nt->mw_count; i++)
868 ntb_free_mw(nt, i);
869
865 /* The scratchpad registers keep the values if the remote side 870 /* The scratchpad registers keep the values if the remote side
866 * goes down, blast them now to give them a sane value the next 871 * goes down, blast them now to give them a sane value the next
867 * time they are accessed 872 * time they are accessed
@@ -1049,6 +1054,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt,
1049 tx_size = (unsigned int)mw_size / num_qps_mw; 1054 tx_size = (unsigned int)mw_size / num_qps_mw;
1050 qp_offset = tx_size * (qp_num / mw_count); 1055 qp_offset = tx_size * (qp_num / mw_count);
1051 1056
1057 qp->tx_mw_size = tx_size;
1052 qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset; 1058 qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset;
1053 if (!qp->tx_mw) 1059 if (!qp->tx_mw)
1054 return -EINVAL; 1060 return -EINVAL;
@@ -1644,7 +1650,7 @@ static int ntb_async_tx_submit(struct ntb_transport_qp *qp,
1644 dma_cookie_t cookie; 1650 dma_cookie_t cookie;
1645 1651
1646 device = chan->device; 1652 device = chan->device;
1647 dest = qp->tx_mw_phys + qp->tx_max_frame * entry->tx_index; 1653 dest = qp->tx_mw_dma_addr + qp->tx_max_frame * entry->tx_index;
1648 buff_off = (size_t)buf & ~PAGE_MASK; 1654 buff_off = (size_t)buf & ~PAGE_MASK;
1649 dest_off = (size_t)dest & ~PAGE_MASK; 1655 dest_off = (size_t)dest & ~PAGE_MASK;
1650 1656
@@ -1863,6 +1869,18 @@ ntb_transport_create_queue(void *data, struct device *client_dev,
1863 qp->rx_dma_chan = NULL; 1869 qp->rx_dma_chan = NULL;
1864 } 1870 }
1865 1871
1872 if (qp->tx_dma_chan) {
1873 qp->tx_mw_dma_addr =
1874 dma_map_resource(qp->tx_dma_chan->device->dev,
1875 qp->tx_mw_phys, qp->tx_mw_size,
1876 DMA_FROM_DEVICE, 0);
1877 if (dma_mapping_error(qp->tx_dma_chan->device->dev,
1878 qp->tx_mw_dma_addr)) {
1879 qp->tx_mw_dma_addr = 0;
1880 goto err1;
1881 }
1882 }
1883
1866 dev_dbg(&pdev->dev, "Using %s memcpy for TX\n", 1884 dev_dbg(&pdev->dev, "Using %s memcpy for TX\n",
1867 qp->tx_dma_chan ? "DMA" : "CPU"); 1885 qp->tx_dma_chan ? "DMA" : "CPU");
1868 1886
@@ -1904,6 +1922,10 @@ err1:
1904 qp->rx_alloc_entry = 0; 1922 qp->rx_alloc_entry = 0;
1905 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q))) 1923 while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q)))
1906 kfree(entry); 1924 kfree(entry);
1925 if (qp->tx_mw_dma_addr)
1926 dma_unmap_resource(qp->tx_dma_chan->device->dev,
1927 qp->tx_mw_dma_addr, qp->tx_mw_size,
1928 DMA_FROM_DEVICE, 0);
1907 if (qp->tx_dma_chan) 1929 if (qp->tx_dma_chan)
1908 dma_release_channel(qp->tx_dma_chan); 1930 dma_release_channel(qp->tx_dma_chan);
1909 if (qp->rx_dma_chan) 1931 if (qp->rx_dma_chan)
@@ -1945,6 +1967,11 @@ void ntb_transport_free_queue(struct ntb_transport_qp *qp)
1945 */ 1967 */
1946 dma_sync_wait(chan, qp->last_cookie); 1968 dma_sync_wait(chan, qp->last_cookie);
1947 dmaengine_terminate_all(chan); 1969 dmaengine_terminate_all(chan);
1970
1971 dma_unmap_resource(chan->device->dev,
1972 qp->tx_mw_dma_addr, qp->tx_mw_size,
1973 DMA_FROM_DEVICE, 0);
1974
1948 dma_release_channel(chan); 1975 dma_release_channel(chan);
1949 } 1976 }
1950 1977
diff --git a/drivers/nvdimm/e820.c b/drivers/nvdimm/e820.c
index 521eaf53a52a..36be9b619187 100644
--- a/drivers/nvdimm/e820.c
+++ b/drivers/nvdimm/e820.c
@@ -47,6 +47,7 @@ static int e820_register_one(struct resource *res, void *data)
47 ndr_desc.res = res; 47 ndr_desc.res = res;
48 ndr_desc.attr_groups = e820_pmem_region_attribute_groups; 48 ndr_desc.attr_groups = e820_pmem_region_attribute_groups;
49 ndr_desc.numa_node = e820_range_to_nid(res->start); 49 ndr_desc.numa_node = e820_range_to_nid(res->start);
50 ndr_desc.target_node = ndr_desc.numa_node;
50 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags); 51 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
51 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc)) 52 if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
52 return -ENXIO; 53 return -ENXIO;
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index 379bf4305e61..a5ac3b240293 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -153,7 +153,7 @@ struct nd_region {
153 u16 ndr_mappings; 153 u16 ndr_mappings;
154 u64 ndr_size; 154 u64 ndr_size;
155 u64 ndr_start; 155 u64 ndr_start;
156 int id, num_lanes, ro, numa_node; 156 int id, num_lanes, ro, numa_node, target_node;
157 void *provider_data; 157 void *provider_data;
158 struct kernfs_node *bb_state; 158 struct kernfs_node *bb_state;
159 struct badblocks bb; 159 struct badblocks bb;
diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index 11b9821eba85..a0c8dcfa0bf9 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -68,6 +68,7 @@ static int of_pmem_region_probe(struct platform_device *pdev)
68 memset(&ndr_desc, 0, sizeof(ndr_desc)); 68 memset(&ndr_desc, 0, sizeof(ndr_desc));
69 ndr_desc.attr_groups = region_attr_groups; 69 ndr_desc.attr_groups = region_attr_groups;
70 ndr_desc.numa_node = dev_to_node(&pdev->dev); 70 ndr_desc.numa_node = dev_to_node(&pdev->dev);
71 ndr_desc.target_node = ndr_desc.numa_node;
71 ndr_desc.res = &pdev->resource[i]; 72 ndr_desc.res = &pdev->resource[i];
72 ndr_desc.of_node = np; 73 ndr_desc.of_node = np;
73 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags); 74 set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags);
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index 3b58baa44b5c..b4ef7d9ff22e 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -1072,6 +1072,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
1072 nd_region->flags = ndr_desc->flags; 1072 nd_region->flags = ndr_desc->flags;
1073 nd_region->ro = ro; 1073 nd_region->ro = ro;
1074 nd_region->numa_node = ndr_desc->numa_node; 1074 nd_region->numa_node = ndr_desc->numa_node;
1075 nd_region->target_node = ndr_desc->target_node;
1075 ida_init(&nd_region->ns_ida); 1076 ida_init(&nd_region->ns_ida);
1076 ida_init(&nd_region->btt_ida); 1077 ida_init(&nd_region->btt_ida);
1077 ida_init(&nd_region->pfn_ida); 1078 ida_init(&nd_region->pfn_ida);
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 07bf2bff3a76..470601980794 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -179,8 +179,8 @@ static int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
179 int ret = 0; 179 int ret = 0;
180 180
181 /* 181 /*
182 * Keep a reference until the work is flushed since ->delete_ctrl 182 * Keep a reference until nvme_do_delete_ctrl() complete,
183 * can free the controller. 183 * since ->delete_ctrl can free the controller.
184 */ 184 */
185 nvme_get_ctrl(ctrl); 185 nvme_get_ctrl(ctrl);
186 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) 186 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
@@ -1250,7 +1250,7 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
1250 if (ns) { 1250 if (ns) {
1251 if (ctrl->effects) 1251 if (ctrl->effects)
1252 effects = le32_to_cpu(ctrl->effects->iocs[opcode]); 1252 effects = le32_to_cpu(ctrl->effects->iocs[opcode]);
1253 if (effects & ~NVME_CMD_EFFECTS_CSUPP) 1253 if (effects & ~(NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC))
1254 dev_warn(ctrl->device, 1254 dev_warn(ctrl->device,
1255 "IO command:%02x has unhandled effects:%08x\n", 1255 "IO command:%02x has unhandled effects:%08x\n",
1256 opcode, effects); 1256 opcode, effects);
@@ -1495,10 +1495,10 @@ static void nvme_set_chunk_size(struct nvme_ns *ns)
1495 blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(chunk_size)); 1495 blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(chunk_size));
1496} 1496}
1497 1497
1498static void nvme_config_discard(struct nvme_ns *ns) 1498static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
1499{ 1499{
1500 struct nvme_ctrl *ctrl = ns->ctrl; 1500 struct nvme_ctrl *ctrl = ns->ctrl;
1501 struct request_queue *queue = ns->queue; 1501 struct request_queue *queue = disk->queue;
1502 u32 size = queue_logical_block_size(queue); 1502 u32 size = queue_logical_block_size(queue);
1503 1503
1504 if (!(ctrl->oncs & NVME_CTRL_ONCS_DSM)) { 1504 if (!(ctrl->oncs & NVME_CTRL_ONCS_DSM)) {
@@ -1526,12 +1526,13 @@ static void nvme_config_discard(struct nvme_ns *ns)
1526 blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); 1526 blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
1527} 1527}
1528 1528
1529static inline void nvme_config_write_zeroes(struct nvme_ns *ns) 1529static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns)
1530{ 1530{
1531 u32 max_sectors; 1531 u32 max_sectors;
1532 unsigned short bs = 1 << ns->lba_shift; 1532 unsigned short bs = 1 << ns->lba_shift;
1533 1533
1534 if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES)) 1534 if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) ||
1535 (ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
1535 return; 1536 return;
1536 /* 1537 /*
1537 * Even though NVMe spec explicitly states that MDTS is not 1538 * Even though NVMe spec explicitly states that MDTS is not
@@ -1548,13 +1549,7 @@ static inline void nvme_config_write_zeroes(struct nvme_ns *ns)
1548 else 1549 else
1549 max_sectors = ((u32)(ns->ctrl->max_hw_sectors + 1) * bs) >> 9; 1550 max_sectors = ((u32)(ns->ctrl->max_hw_sectors + 1) * bs) >> 9;
1550 1551
1551 blk_queue_max_write_zeroes_sectors(ns->queue, max_sectors); 1552 blk_queue_max_write_zeroes_sectors(disk->queue, max_sectors);
1552}
1553
1554static inline void nvme_ns_config_oncs(struct nvme_ns *ns)
1555{
1556 nvme_config_discard(ns);
1557 nvme_config_write_zeroes(ns);
1558} 1553}
1559 1554
1560static void nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid, 1555static void nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid,
@@ -1610,7 +1605,9 @@ static void nvme_update_disk_info(struct gendisk *disk,
1610 capacity = 0; 1605 capacity = 0;
1611 1606
1612 set_capacity(disk, capacity); 1607 set_capacity(disk, capacity);
1613 nvme_ns_config_oncs(ns); 1608
1609 nvme_config_discard(disk, ns);
1610 nvme_config_write_zeroes(disk, ns);
1614 1611
1615 if (id->nsattr & (1 << 0)) 1612 if (id->nsattr & (1 << 0))
1616 set_disk_ro(disk, true); 1613 set_disk_ro(disk, true);
@@ -3304,6 +3301,7 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
3304 mutex_lock(&ctrl->subsys->lock); 3301 mutex_lock(&ctrl->subsys->lock);
3305 list_del_rcu(&ns->siblings); 3302 list_del_rcu(&ns->siblings);
3306 mutex_unlock(&ctrl->subsys->lock); 3303 mutex_unlock(&ctrl->subsys->lock);
3304 nvme_put_ns_head(ns->head);
3307 out_free_id: 3305 out_free_id:
3308 kfree(id); 3306 kfree(id);
3309 out_free_queue: 3307 out_free_queue:
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index b29b12498a1a..f3b9d91ba0df 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -2107,7 +2107,7 @@ nvme_fc_map_data(struct nvme_fc_ctrl *ctrl, struct request *rq,
2107 2107
2108 freq->sg_cnt = 0; 2108 freq->sg_cnt = 0;
2109 2109
2110 if (!blk_rq_payload_bytes(rq)) 2110 if (!blk_rq_nr_phys_segments(rq))
2111 return 0; 2111 return 0;
2112 2112
2113 freq->sg_table.sgl = freq->first_sgl; 2113 freq->sg_table.sgl = freq->first_sgl;
@@ -2304,12 +2304,23 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
2304 if (ret) 2304 if (ret)
2305 return ret; 2305 return ret;
2306 2306
2307 data_len = blk_rq_payload_bytes(rq); 2307 /*
2308 if (data_len) 2308 * nvme core doesn't quite treat the rq opaquely. Commands such
2309 * as WRITE ZEROES will return a non-zero rq payload_bytes yet
2310 * there is no actual payload to be transferred.
2311 * To get it right, key data transmission on there being 1 or
2312 * more physical segments in the sg list. If there is no
2313 * physical segments, there is no payload.
2314 */
2315 if (blk_rq_nr_phys_segments(rq)) {
2316 data_len = blk_rq_payload_bytes(rq);
2309 io_dir = ((rq_data_dir(rq) == WRITE) ? 2317 io_dir = ((rq_data_dir(rq) == WRITE) ?
2310 NVMEFC_FCP_WRITE : NVMEFC_FCP_READ); 2318 NVMEFC_FCP_WRITE : NVMEFC_FCP_READ);
2311 else 2319 } else {
2320 data_len = 0;
2312 io_dir = NVMEFC_FCP_NODATA; 2321 io_dir = NVMEFC_FCP_NODATA;
2322 }
2323
2313 2324
2314 return nvme_fc_start_fcp_op(ctrl, queue, op, data_len, io_dir); 2325 return nvme_fc_start_fcp_op(ctrl, queue, op, data_len, io_dir);
2315} 2326}
@@ -2464,6 +2475,7 @@ static int
2464nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl) 2475nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl)
2465{ 2476{
2466 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts; 2477 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts;
2478 u32 prior_ioq_cnt = ctrl->ctrl.queue_count - 1;
2467 unsigned int nr_io_queues; 2479 unsigned int nr_io_queues;
2468 int ret; 2480 int ret;
2469 2481
@@ -2476,6 +2488,13 @@ nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl)
2476 return ret; 2488 return ret;
2477 } 2489 }
2478 2490
2491 if (!nr_io_queues && prior_ioq_cnt) {
2492 dev_info(ctrl->ctrl.device,
2493 "Fail Reconnect: At least 1 io queue "
2494 "required (was %d)\n", prior_ioq_cnt);
2495 return -ENOSPC;
2496 }
2497
2479 ctrl->ctrl.queue_count = nr_io_queues + 1; 2498 ctrl->ctrl.queue_count = nr_io_queues + 1;
2480 /* check for io queues existing */ 2499 /* check for io queues existing */
2481 if (ctrl->ctrl.queue_count == 1) 2500 if (ctrl->ctrl.queue_count == 1)
@@ -2489,6 +2508,10 @@ nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl)
2489 if (ret) 2508 if (ret)
2490 goto out_delete_hw_queues; 2509 goto out_delete_hw_queues;
2491 2510
2511 if (prior_ioq_cnt != nr_io_queues)
2512 dev_info(ctrl->ctrl.device,
2513 "reconnect: revising io queue count from %d to %d\n",
2514 prior_ioq_cnt, nr_io_queues);
2492 blk_mq_update_nr_hw_queues(&ctrl->tag_set, nr_io_queues); 2515 blk_mq_update_nr_hw_queues(&ctrl->tag_set, nr_io_queues);
2493 2516
2494 return 0; 2517 return 0;
@@ -3006,7 +3029,10 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
3006 3029
3007 ctrl->ctrl.opts = opts; 3030 ctrl->ctrl.opts = opts;
3008 ctrl->ctrl.nr_reconnects = 0; 3031 ctrl->ctrl.nr_reconnects = 0;
3009 ctrl->ctrl.numa_node = dev_to_node(lport->dev); 3032 if (lport->dev)
3033 ctrl->ctrl.numa_node = dev_to_node(lport->dev);
3034 else
3035 ctrl->ctrl.numa_node = NUMA_NO_NODE;
3010 INIT_LIST_HEAD(&ctrl->ctrl_list); 3036 INIT_LIST_HEAD(&ctrl->ctrl_list);
3011 ctrl->lport = lport; 3037 ctrl->lport = lport;
3012 ctrl->rport = rport; 3038 ctrl->rport = rport;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index b91f1838bbd5..527d64545023 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -87,6 +87,11 @@ enum nvme_quirks {
87 * Ignore device provided subnqn. 87 * Ignore device provided subnqn.
88 */ 88 */
89 NVME_QUIRK_IGNORE_DEV_SUBNQN = (1 << 8), 89 NVME_QUIRK_IGNORE_DEV_SUBNQN = (1 << 8),
90
91 /*
92 * Broken Write Zeroes.
93 */
94 NVME_QUIRK_DISABLE_WRITE_ZEROES = (1 << 9),
90}; 95};
91 96
92/* 97/*
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 92bad1c810ac..a90cf5d63aac 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2937,7 +2937,8 @@ static const struct pci_device_id nvme_id_table[] = {
2937 { PCI_VDEVICE(INTEL, 0xf1a6), /* Intel 760p/Pro 7600p */ 2937 { PCI_VDEVICE(INTEL, 0xf1a6), /* Intel 760p/Pro 7600p */
2938 .driver_data = NVME_QUIRK_IGNORE_DEV_SUBNQN, }, 2938 .driver_data = NVME_QUIRK_IGNORE_DEV_SUBNQN, },
2939 { PCI_VDEVICE(INTEL, 0x5845), /* Qemu emulated controller */ 2939 { PCI_VDEVICE(INTEL, 0x5845), /* Qemu emulated controller */
2940 .driver_data = NVME_QUIRK_IDENTIFY_CNS, }, 2940 .driver_data = NVME_QUIRK_IDENTIFY_CNS |
2941 NVME_QUIRK_DISABLE_WRITE_ZEROES, },
2941 { PCI_DEVICE(0x1bb1, 0x0100), /* Seagate Nytro Flash Storage */ 2942 { PCI_DEVICE(0x1bb1, 0x0100), /* Seagate Nytro Flash Storage */
2942 .driver_data = NVME_QUIRK_DELAY_BEFORE_CHK_RDY, }, 2943 .driver_data = NVME_QUIRK_DELAY_BEFORE_CHK_RDY, },
2943 { PCI_DEVICE(0x1c58, 0x0003), /* HGST adapter */ 2944 { PCI_DEVICE(0x1c58, 0x0003), /* HGST adapter */
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 208ee518af65..e7e08889865e 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -463,6 +463,15 @@ static int nvme_tcp_handle_c2h_data(struct nvme_tcp_queue *queue,
463 463
464 queue->data_remaining = le32_to_cpu(pdu->data_length); 464 queue->data_remaining = le32_to_cpu(pdu->data_length);
465 465
466 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS &&
467 unlikely(!(pdu->hdr.flags & NVME_TCP_F_DATA_LAST))) {
468 dev_err(queue->ctrl->ctrl.device,
469 "queue %d tag %#x SUCCESS set but not last PDU\n",
470 nvme_tcp_queue_id(queue), rq->tag);
471 nvme_tcp_error_recovery(&queue->ctrl->ctrl);
472 return -EPROTO;
473 }
474
466 return 0; 475 return 0;
467 476
468} 477}
@@ -618,6 +627,14 @@ static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb,
618 return ret; 627 return ret;
619} 628}
620 629
630static inline void nvme_tcp_end_request(struct request *rq, __le16 status)
631{
632 union nvme_result res = {};
633
634 nvme_end_request(rq, cpu_to_le16(status << 1), res);
635}
636
637
621static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, 638static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb,
622 unsigned int *offset, size_t *len) 639 unsigned int *offset, size_t *len)
623{ 640{
@@ -685,6 +702,8 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb,
685 nvme_tcp_ddgst_final(queue->rcv_hash, &queue->exp_ddgst); 702 nvme_tcp_ddgst_final(queue->rcv_hash, &queue->exp_ddgst);
686 queue->ddgst_remaining = NVME_TCP_DIGEST_LENGTH; 703 queue->ddgst_remaining = NVME_TCP_DIGEST_LENGTH;
687 } else { 704 } else {
705 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS)
706 nvme_tcp_end_request(rq, NVME_SC_SUCCESS);
688 nvme_tcp_init_recv_ctx(queue); 707 nvme_tcp_init_recv_ctx(queue);
689 } 708 }
690 } 709 }
@@ -695,6 +714,7 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb,
695static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, 714static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue,
696 struct sk_buff *skb, unsigned int *offset, size_t *len) 715 struct sk_buff *skb, unsigned int *offset, size_t *len)
697{ 716{
717 struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu;
698 char *ddgst = (char *)&queue->recv_ddgst; 718 char *ddgst = (char *)&queue->recv_ddgst;
699 size_t recv_len = min_t(size_t, *len, queue->ddgst_remaining); 719 size_t recv_len = min_t(size_t, *len, queue->ddgst_remaining);
700 off_t off = NVME_TCP_DIGEST_LENGTH - queue->ddgst_remaining; 720 off_t off = NVME_TCP_DIGEST_LENGTH - queue->ddgst_remaining;
@@ -718,6 +738,13 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue,
718 return -EIO; 738 return -EIO;
719 } 739 }
720 740
741 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) {
742 struct request *rq = blk_mq_tag_to_rq(nvme_tcp_tagset(queue),
743 pdu->command_id);
744
745 nvme_tcp_end_request(rq, NVME_SC_SUCCESS);
746 }
747
721 nvme_tcp_init_recv_ctx(queue); 748 nvme_tcp_init_recv_ctx(queue);
722 return 0; 749 return 0;
723} 750}
@@ -815,10 +842,7 @@ static inline void nvme_tcp_done_send_req(struct nvme_tcp_queue *queue)
815 842
816static void nvme_tcp_fail_request(struct nvme_tcp_request *req) 843static void nvme_tcp_fail_request(struct nvme_tcp_request *req)
817{ 844{
818 union nvme_result res = {}; 845 nvme_tcp_end_request(blk_mq_rq_from_pdu(req), NVME_SC_DATA_XFER_ERROR);
819
820 nvme_end_request(blk_mq_rq_from_pdu(req),
821 cpu_to_le16(NVME_SC_DATA_XFER_ERROR), res);
822} 846}
823 847
824static int nvme_tcp_try_send_data(struct nvme_tcp_request *req) 848static int nvme_tcp_try_send_data(struct nvme_tcp_request *req)
diff --git a/drivers/nvme/host/trace.c b/drivers/nvme/host/trace.c
index 58456de78bb2..5f24ea7a28eb 100644
--- a/drivers/nvme/host/trace.c
+++ b/drivers/nvme/host/trace.c
@@ -50,7 +50,19 @@ static const char *nvme_trace_admin_identify(struct trace_seq *p, u8 *cdw10)
50 return ret; 50 return ret;
51} 51}
52 52
53static const char *nvme_trace_admin_get_features(struct trace_seq *p,
54 u8 *cdw10)
55{
56 const char *ret = trace_seq_buffer_ptr(p);
57 u8 fid = cdw10[0];
58 u8 sel = cdw10[1] & 0x7;
59 u32 cdw11 = get_unaligned_le32(cdw10 + 4);
60
61 trace_seq_printf(p, "fid=0x%x sel=0x%x cdw11=0x%x", fid, sel, cdw11);
62 trace_seq_putc(p, 0);
53 63
64 return ret;
65}
54 66
55static const char *nvme_trace_read_write(struct trace_seq *p, u8 *cdw10) 67static const char *nvme_trace_read_write(struct trace_seq *p, u8 *cdw10)
56{ 68{
@@ -101,6 +113,8 @@ const char *nvme_trace_parse_admin_cmd(struct trace_seq *p,
101 return nvme_trace_create_cq(p, cdw10); 113 return nvme_trace_create_cq(p, cdw10);
102 case nvme_admin_identify: 114 case nvme_admin_identify:
103 return nvme_trace_admin_identify(p, cdw10); 115 return nvme_trace_admin_identify(p, cdw10);
116 case nvme_admin_get_features:
117 return nvme_trace_admin_get_features(p, cdw10);
104 default: 118 default:
105 return nvme_trace_common(p, cdw10); 119 return nvme_trace_common(p, cdw10);
106 } 120 }
diff --git a/drivers/nvme/host/trace.h b/drivers/nvme/host/trace.h
index 244d7c177e5a..97d3c77365b8 100644
--- a/drivers/nvme/host/trace.h
+++ b/drivers/nvme/host/trace.h
@@ -108,7 +108,7 @@ TRACE_EVENT(nvme_setup_cmd,
108 __entry->metadata = le64_to_cpu(cmd->common.metadata); 108 __entry->metadata = le64_to_cpu(cmd->common.metadata);
109 __assign_disk_name(__entry->disk, req->rq_disk); 109 __assign_disk_name(__entry->disk, req->rq_disk);
110 memcpy(__entry->cdw10, &cmd->common.cdw10, 110 memcpy(__entry->cdw10, &cmd->common.cdw10,
111 6 * sizeof(__entry->cdw10)); 111 sizeof(__entry->cdw10));
112 ), 112 ),
113 TP_printk("nvme%d: %sqid=%d, cmdid=%u, nsid=%u, flags=0x%x, meta=0x%llx, cmd=(%s %s)", 113 TP_printk("nvme%d: %sqid=%d, cmdid=%u, nsid=%u, flags=0x%x, meta=0x%llx, cmd=(%s %s)",
114 __entry->ctrl_id, __print_disk_name(__entry->disk), 114 __entry->ctrl_id, __print_disk_name(__entry->disk),
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index d44ede147263..2d73b66e3686 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1163,6 +1163,15 @@ static void nvmet_release_p2p_ns_map(struct nvmet_ctrl *ctrl)
1163 put_device(ctrl->p2p_client); 1163 put_device(ctrl->p2p_client);
1164} 1164}
1165 1165
1166static void nvmet_fatal_error_handler(struct work_struct *work)
1167{
1168 struct nvmet_ctrl *ctrl =
1169 container_of(work, struct nvmet_ctrl, fatal_err_work);
1170
1171 pr_err("ctrl %d fatal error occurred!\n", ctrl->cntlid);
1172 ctrl->ops->delete_ctrl(ctrl);
1173}
1174
1166u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, 1175u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
1167 struct nvmet_req *req, u32 kato, struct nvmet_ctrl **ctrlp) 1176 struct nvmet_req *req, u32 kato, struct nvmet_ctrl **ctrlp)
1168{ 1177{
@@ -1205,6 +1214,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
1205 INIT_WORK(&ctrl->async_event_work, nvmet_async_event_work); 1214 INIT_WORK(&ctrl->async_event_work, nvmet_async_event_work);
1206 INIT_LIST_HEAD(&ctrl->async_events); 1215 INIT_LIST_HEAD(&ctrl->async_events);
1207 INIT_RADIX_TREE(&ctrl->p2p_ns_map, GFP_KERNEL); 1216 INIT_RADIX_TREE(&ctrl->p2p_ns_map, GFP_KERNEL);
1217 INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler);
1208 1218
1209 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); 1219 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
1210 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); 1220 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE);
@@ -1308,21 +1318,11 @@ void nvmet_ctrl_put(struct nvmet_ctrl *ctrl)
1308 kref_put(&ctrl->ref, nvmet_ctrl_free); 1318 kref_put(&ctrl->ref, nvmet_ctrl_free);
1309} 1319}
1310 1320
1311static void nvmet_fatal_error_handler(struct work_struct *work)
1312{
1313 struct nvmet_ctrl *ctrl =
1314 container_of(work, struct nvmet_ctrl, fatal_err_work);
1315
1316 pr_err("ctrl %d fatal error occurred!\n", ctrl->cntlid);
1317 ctrl->ops->delete_ctrl(ctrl);
1318}
1319
1320void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl) 1321void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl)
1321{ 1322{
1322 mutex_lock(&ctrl->lock); 1323 mutex_lock(&ctrl->lock);
1323 if (!(ctrl->csts & NVME_CSTS_CFS)) { 1324 if (!(ctrl->csts & NVME_CSTS_CFS)) {
1324 ctrl->csts |= NVME_CSTS_CFS; 1325 ctrl->csts |= NVME_CSTS_CFS;
1325 INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler);
1326 schedule_work(&ctrl->fatal_err_work); 1326 schedule_work(&ctrl->fatal_err_work);
1327 } 1327 }
1328 mutex_unlock(&ctrl->lock); 1328 mutex_unlock(&ctrl->lock);
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 1e9654f04c60..98b7b1f4ee96 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1143,10 +1143,8 @@ __nvmet_fc_free_assocs(struct nvmet_fc_tgtport *tgtport)
1143 &tgtport->assoc_list, a_list) { 1143 &tgtport->assoc_list, a_list) {
1144 if (!nvmet_fc_tgt_a_get(assoc)) 1144 if (!nvmet_fc_tgt_a_get(assoc))
1145 continue; 1145 continue;
1146 spin_unlock_irqrestore(&tgtport->lock, flags); 1146 if (!schedule_work(&assoc->del_work))
1147 nvmet_fc_delete_target_assoc(assoc); 1147 nvmet_fc_tgt_a_put(assoc);
1148 nvmet_fc_tgt_a_put(assoc);
1149 spin_lock_irqsave(&tgtport->lock, flags);
1150 } 1148 }
1151 spin_unlock_irqrestore(&tgtport->lock, flags); 1149 spin_unlock_irqrestore(&tgtport->lock, flags);
1152} 1150}
@@ -1185,7 +1183,8 @@ nvmet_fc_delete_ctrl(struct nvmet_ctrl *ctrl)
1185 nvmet_fc_tgtport_put(tgtport); 1183 nvmet_fc_tgtport_put(tgtport);
1186 1184
1187 if (found_ctrl) { 1185 if (found_ctrl) {
1188 schedule_work(&assoc->del_work); 1186 if (!schedule_work(&assoc->del_work))
1187 nvmet_fc_tgt_a_put(assoc);
1189 return; 1188 return;
1190 } 1189 }
1191 1190
@@ -1503,10 +1502,8 @@ nvmet_fc_ls_disconnect(struct nvmet_fc_tgtport *tgtport,
1503 (struct fcnvme_ls_disconnect_rqst *)iod->rqstbuf; 1502 (struct fcnvme_ls_disconnect_rqst *)iod->rqstbuf;
1504 struct fcnvme_ls_disconnect_acc *acc = 1503 struct fcnvme_ls_disconnect_acc *acc =
1505 (struct fcnvme_ls_disconnect_acc *)iod->rspbuf; 1504 (struct fcnvme_ls_disconnect_acc *)iod->rspbuf;
1506 struct nvmet_fc_tgt_queue *queue = NULL;
1507 struct nvmet_fc_tgt_assoc *assoc; 1505 struct nvmet_fc_tgt_assoc *assoc;
1508 int ret = 0; 1506 int ret = 0;
1509 bool del_assoc = false;
1510 1507
1511 memset(acc, 0, sizeof(*acc)); 1508 memset(acc, 0, sizeof(*acc));
1512 1509
@@ -1537,18 +1534,7 @@ nvmet_fc_ls_disconnect(struct nvmet_fc_tgtport *tgtport,
1537 assoc = nvmet_fc_find_target_assoc(tgtport, 1534 assoc = nvmet_fc_find_target_assoc(tgtport,
1538 be64_to_cpu(rqst->associd.association_id)); 1535 be64_to_cpu(rqst->associd.association_id));
1539 iod->assoc = assoc; 1536 iod->assoc = assoc;
1540 if (assoc) { 1537 if (!assoc)
1541 if (rqst->discon_cmd.scope ==
1542 FCNVME_DISCONN_CONNECTION) {
1543 queue = nvmet_fc_find_target_queue(tgtport,
1544 be64_to_cpu(
1545 rqst->discon_cmd.id));
1546 if (!queue) {
1547 nvmet_fc_tgt_a_put(assoc);
1548 ret = VERR_NO_CONN;
1549 }
1550 }
1551 } else
1552 ret = VERR_NO_ASSOC; 1538 ret = VERR_NO_ASSOC;
1553 } 1539 }
1554 1540
@@ -1576,26 +1562,10 @@ nvmet_fc_ls_disconnect(struct nvmet_fc_tgtport *tgtport,
1576 sizeof(struct fcnvme_ls_disconnect_acc)), 1562 sizeof(struct fcnvme_ls_disconnect_acc)),
1577 FCNVME_LS_DISCONNECT); 1563 FCNVME_LS_DISCONNECT);
1578 1564
1579
1580 /* are we to delete a Connection ID (queue) */
1581 if (queue) {
1582 int qid = queue->qid;
1583
1584 nvmet_fc_delete_target_queue(queue);
1585
1586 /* release the get taken by find_target_queue */
1587 nvmet_fc_tgt_q_put(queue);
1588
1589 /* tear association down if io queue terminated */
1590 if (!qid)
1591 del_assoc = true;
1592 }
1593
1594 /* release get taken in nvmet_fc_find_target_assoc */ 1565 /* release get taken in nvmet_fc_find_target_assoc */
1595 nvmet_fc_tgt_a_put(iod->assoc); 1566 nvmet_fc_tgt_a_put(iod->assoc);
1596 1567
1597 if (del_assoc) 1568 nvmet_fc_delete_target_assoc(iod->assoc);
1598 nvmet_fc_delete_target_assoc(iod->assoc);
1599} 1569}
1600 1570
1601 1571
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 71dfedbadc26..a065dbfc43b1 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -194,11 +194,11 @@ static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
194 le64_to_cpu(range->slba) << (ns->blksize_shift - 9), 194 le64_to_cpu(range->slba) << (ns->blksize_shift - 9),
195 le32_to_cpu(range->nlb) << (ns->blksize_shift - 9), 195 le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
196 GFP_KERNEL, 0, bio); 196 GFP_KERNEL, 0, bio);
197 197 if (ret && ret != -EOPNOTSUPP) {
198 if (ret)
199 req->error_slba = le64_to_cpu(range->slba); 198 req->error_slba = le64_to_cpu(range->slba);
200 199 return blk_to_nvme_status(req, errno_to_blk_status(ret));
201 return blk_to_nvme_status(req, errno_to_blk_status(ret)); 200 }
201 return NVME_SC_SUCCESS;
202} 202}
203 203
204static void nvmet_bdev_execute_discard(struct nvmet_req *req) 204static void nvmet_bdev_execute_discard(struct nvmet_req *req)
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 517522305e5c..3e43212d3c1c 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -297,7 +297,7 @@ static void nvmet_file_execute_discard(struct nvmet_req *req)
297 } 297 }
298 298
299 ret = vfs_fallocate(req->ns->file, mode, offset, len); 299 ret = vfs_fallocate(req->ns->file, mode, offset, len);
300 if (ret) { 300 if (ret && ret != -EOPNOTSUPP) {
301 req->error_slba = le64_to_cpu(range.slba); 301 req->error_slba = le64_to_cpu(range.slba);
302 status = errno_to_nvme_status(req, ret); 302 status = errno_to_nvme_status(req, ret);
303 break; 303 break;
diff --git a/drivers/parport/daisy.c b/drivers/parport/daisy.c
index 56dd83a45e55..5484a46dafda 100644
--- a/drivers/parport/daisy.c
+++ b/drivers/parport/daisy.c
@@ -213,12 +213,10 @@ void parport_daisy_fini(struct parport *port)
213struct pardevice *parport_open(int devnum, const char *name) 213struct pardevice *parport_open(int devnum, const char *name)
214{ 214{
215 struct daisydev *p = topology; 215 struct daisydev *p = topology;
216 struct pardev_cb par_cb;
217 struct parport *port; 216 struct parport *port;
218 struct pardevice *dev; 217 struct pardevice *dev;
219 int daisy; 218 int daisy;
220 219
221 memset(&par_cb, 0, sizeof(par_cb));
222 spin_lock(&topology_lock); 220 spin_lock(&topology_lock);
223 while (p && p->devnum != devnum) 221 while (p && p->devnum != devnum)
224 p = p->next; 222 p = p->next;
@@ -232,7 +230,7 @@ struct pardevice *parport_open(int devnum, const char *name)
232 port = parport_get_port(p->port); 230 port = parport_get_port(p->port);
233 spin_unlock(&topology_lock); 231 spin_unlock(&topology_lock);
234 232
235 dev = parport_register_dev_model(port, name, &par_cb, devnum); 233 dev = parport_register_device(port, name, NULL, NULL, NULL, 0, NULL);
236 parport_put_port(port); 234 parport_put_port(port);
237 if (!dev) 235 if (!dev)
238 return NULL; 236 return NULL;
@@ -482,31 +480,3 @@ static int assign_addrs(struct parport *port)
482 kfree(deviceid); 480 kfree(deviceid);
483 return detected; 481 return detected;
484} 482}
485
486static int daisy_drv_probe(struct pardevice *par_dev)
487{
488 struct device_driver *drv = par_dev->dev.driver;
489
490 if (strcmp(drv->name, "daisy_drv"))
491 return -ENODEV;
492 if (strcmp(par_dev->name, daisy_dev_name))
493 return -ENODEV;
494
495 return 0;
496}
497
498static struct parport_driver daisy_driver = {
499 .name = "daisy_drv",
500 .probe = daisy_drv_probe,
501 .devmodel = true,
502};
503
504int daisy_drv_init(void)
505{
506 return parport_register_driver(&daisy_driver);
507}
508
509void daisy_drv_exit(void)
510{
511 parport_unregister_driver(&daisy_driver);
512}
diff --git a/drivers/parport/probe.c b/drivers/parport/probe.c
index e5e6a463a941..e035174ba205 100644
--- a/drivers/parport/probe.c
+++ b/drivers/parport/probe.c
@@ -257,7 +257,7 @@ static ssize_t parport_read_device_id (struct parport *port, char *buffer,
257ssize_t parport_device_id (int devnum, char *buffer, size_t count) 257ssize_t parport_device_id (int devnum, char *buffer, size_t count)
258{ 258{
259 ssize_t retval = -ENXIO; 259 ssize_t retval = -ENXIO;
260 struct pardevice *dev = parport_open(devnum, daisy_dev_name); 260 struct pardevice *dev = parport_open (devnum, "Device ID probe");
261 if (!dev) 261 if (!dev)
262 return -ENXIO; 262 return -ENXIO;
263 263
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index 0171b8dbcdcd..5dc53d420ca8 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -137,19 +137,11 @@ static struct bus_type parport_bus_type = {
137 137
138int parport_bus_init(void) 138int parport_bus_init(void)
139{ 139{
140 int retval; 140 return bus_register(&parport_bus_type);
141
142 retval = bus_register(&parport_bus_type);
143 if (retval)
144 return retval;
145 daisy_drv_init();
146
147 return 0;
148} 141}
149 142
150void parport_bus_exit(void) 143void parport_bus_exit(void)
151{ 144{
152 daisy_drv_exit();
153 bus_unregister(&parport_bus_type); 145 bus_unregister(&parport_bus_type);
154} 146}
155 147
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/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index a0baee25134c..4159c63a5fd2 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -1382,3 +1382,40 @@ int chsc_pnso_brinfo(struct subchannel_id schid,
1382 return chsc_error_from_response(brinfo_area->response.code); 1382 return chsc_error_from_response(brinfo_area->response.code);
1383} 1383}
1384EXPORT_SYMBOL_GPL(chsc_pnso_brinfo); 1384EXPORT_SYMBOL_GPL(chsc_pnso_brinfo);
1385
1386int chsc_sgib(u32 origin)
1387{
1388 struct {
1389 struct chsc_header request;
1390 u16 op;
1391 u8 reserved01[2];
1392 u8 reserved02:4;
1393 u8 fmt:4;
1394 u8 reserved03[7];
1395 /* operation data area begin */
1396 u8 reserved04[4];
1397 u32 gib_origin;
1398 u8 reserved05[10];
1399 u8 aix;
1400 u8 reserved06[4029];
1401 struct chsc_header response;
1402 u8 reserved07[4];
1403 } *sgib_area;
1404 int ret;
1405
1406 spin_lock_irq(&chsc_page_lock);
1407 memset(chsc_page, 0, PAGE_SIZE);
1408 sgib_area = chsc_page;
1409 sgib_area->request.length = 0x0fe0;
1410 sgib_area->request.code = 0x0021;
1411 sgib_area->op = 0x1;
1412 sgib_area->gib_origin = origin;
1413
1414 ret = chsc(sgib_area);
1415 if (ret == 0)
1416 ret = chsc_error_from_response(sgib_area->response.code);
1417 spin_unlock_irq(&chsc_page_lock);
1418
1419 return ret;
1420}
1421EXPORT_SYMBOL_GPL(chsc_sgib);
diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h
index 78aba8d94eec..e57d68e325a3 100644
--- a/drivers/s390/cio/chsc.h
+++ b/drivers/s390/cio/chsc.h
@@ -164,6 +164,7 @@ int chsc_get_channel_measurement_chars(struct channel_path *chp);
164int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd); 164int chsc_ssqd(struct subchannel_id schid, struct chsc_ssqd_area *ssqd);
165int chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc, 165int chsc_sadc(struct subchannel_id schid, struct chsc_scssc_area *scssc,
166 u64 summary_indicator_addr, u64 subchannel_indicator_addr); 166 u64 summary_indicator_addr, u64 subchannel_indicator_addr);
167int chsc_sgib(u32 origin);
167int chsc_error_from_response(int response); 168int chsc_error_from_response(int response);
168 169
169int chsc_siosl(struct subchannel_id schid); 170int chsc_siosl(struct subchannel_id schid);
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index a45f81ec80ce..8e28a505f7e8 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -413,13 +413,16 @@ static int aac_slave_configure(struct scsi_device *sdev)
413 if (chn < AAC_MAX_BUSES && tid < AAC_MAX_TARGETS && aac->sa_firmware) { 413 if (chn < AAC_MAX_BUSES && tid < AAC_MAX_TARGETS && aac->sa_firmware) {
414 devtype = aac->hba_map[chn][tid].devtype; 414 devtype = aac->hba_map[chn][tid].devtype;
415 415
416 if (devtype == AAC_DEVTYPE_NATIVE_RAW) 416 if (devtype == AAC_DEVTYPE_NATIVE_RAW) {
417 depth = aac->hba_map[chn][tid].qd_limit; 417 depth = aac->hba_map[chn][tid].qd_limit;
418 else if (devtype == AAC_DEVTYPE_ARC_RAW) 418 set_timeout = 1;
419 goto common_config;
420 }
421 if (devtype == AAC_DEVTYPE_ARC_RAW) {
419 set_qd_dev_type = true; 422 set_qd_dev_type = true;
420 423 set_timeout = 1;
421 set_timeout = 1; 424 goto common_config;
422 goto common_config; 425 }
423 } 426 }
424 427
425 if (aac->jbod && (sdev->type == TYPE_DISK)) 428 if (aac->jbod && (sdev->type == TYPE_DISK))
diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h
index 6c87bd34509a..9bfa9f12d81e 100644
--- a/drivers/scsi/hisi_sas/hisi_sas.h
+++ b/drivers/scsi/hisi_sas/hisi_sas.h
@@ -18,6 +18,7 @@
18#include <linux/dmapool.h> 18#include <linux/dmapool.h>
19#include <linux/iopoll.h> 19#include <linux/iopoll.h>
20#include <linux/lcm.h> 20#include <linux/lcm.h>
21#include <linux/libata.h>
21#include <linux/mfd/syscon.h> 22#include <linux/mfd/syscon.h>
22#include <linux/module.h> 23#include <linux/module.h>
23#include <linux/of_address.h> 24#include <linux/of_address.h>
@@ -94,6 +95,11 @@ enum {
94 PORT_TYPE_SATA = (1U << 0), 95 PORT_TYPE_SATA = (1U << 0),
95}; 96};
96 97
98enum dev_status {
99 HISI_SAS_DEV_INIT,
100 HISI_SAS_DEV_NORMAL,
101};
102
97enum { 103enum {
98 HISI_SAS_INT_ABT_CMD = 0, 104 HISI_SAS_INT_ABT_CMD = 0,
99 HISI_SAS_INT_ABT_DEV = 1, 105 HISI_SAS_INT_ABT_DEV = 1,
@@ -161,6 +167,7 @@ struct hisi_sas_phy {
161 u8 in_reset; 167 u8 in_reset;
162 u8 reserved[2]; 168 u8 reserved[2];
163 u32 phy_type; 169 u32 phy_type;
170 u32 code_violation_err_count;
164 enum sas_linkrate minimum_linkrate; 171 enum sas_linkrate minimum_linkrate;
165 enum sas_linkrate maximum_linkrate; 172 enum sas_linkrate maximum_linkrate;
166}; 173};
@@ -194,6 +201,7 @@ struct hisi_sas_device {
194 struct hisi_sas_dq *dq; 201 struct hisi_sas_dq *dq;
195 struct list_head list; 202 struct list_head list;
196 enum sas_device_type dev_type; 203 enum sas_device_type dev_type;
204 enum dev_status dev_status;
197 int device_id; 205 int device_id;
198 int sata_idx; 206 int sata_idx;
199 spinlock_t lock; /* For protecting slots */ 207 spinlock_t lock; /* For protecting slots */
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 13ca5a0bdf6b..14bac4966c87 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include "hisi_sas.h" 12#include "hisi_sas.h"
13#include "../libsas/sas_internal.h"
13#define DRV_NAME "hisi_sas" 14#define DRV_NAME "hisi_sas"
14 15
15#define DEV_IS_GONE(dev) \ 16#define DEV_IS_GONE(dev) \
@@ -707,6 +708,7 @@ static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device)
707 708
708 hisi_hba->devices[i].device_id = i; 709 hisi_hba->devices[i].device_id = i;
709 sas_dev = &hisi_hba->devices[i]; 710 sas_dev = &hisi_hba->devices[i];
711 sas_dev->dev_status = HISI_SAS_DEV_INIT;
710 sas_dev->dev_type = device->dev_type; 712 sas_dev->dev_type = device->dev_type;
711 sas_dev->hisi_hba = hisi_hba; 713 sas_dev->hisi_hba = hisi_hba;
712 sas_dev->sas_device = device; 714 sas_dev->sas_device = device;
@@ -731,6 +733,8 @@ static int hisi_sas_init_device(struct domain_device *device)
731 struct hisi_sas_tmf_task tmf_task; 733 struct hisi_sas_tmf_task tmf_task;
732 int retry = HISI_SAS_SRST_ATA_DISK_CNT; 734 int retry = HISI_SAS_SRST_ATA_DISK_CNT;
733 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); 735 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
736 struct device *dev = hisi_hba->dev;
737 struct sas_phy *local_phy;
734 738
735 switch (device->dev_type) { 739 switch (device->dev_type) {
736 case SAS_END_DEVICE: 740 case SAS_END_DEVICE:
@@ -746,6 +750,31 @@ static int hisi_sas_init_device(struct domain_device *device)
746 case SAS_SATA_PM: 750 case SAS_SATA_PM:
747 case SAS_SATA_PM_PORT: 751 case SAS_SATA_PM_PORT:
748 case SAS_SATA_PENDING: 752 case SAS_SATA_PENDING:
753 /*
754 * send HARD RESET to clear previous affiliation of
755 * STP target port
756 */
757 local_phy = sas_get_local_phy(device);
758 if (!scsi_is_sas_phy_local(local_phy)) {
759 unsigned long deadline = ata_deadline(jiffies, 20000);
760 struct sata_device *sata_dev = &device->sata_dev;
761 struct ata_host *ata_host = sata_dev->ata_host;
762 struct ata_port_operations *ops = ata_host->ops;
763 struct ata_port *ap = sata_dev->ap;
764 struct ata_link *link;
765 unsigned int classes;
766
767 ata_for_each_link(link, ap, EDGE)
768 rc = ops->hardreset(link, &classes,
769 deadline);
770 }
771 sas_put_local_phy(local_phy);
772 if (rc) {
773 dev_warn(dev, "SATA disk hardreset fail: 0x%x\n",
774 rc);
775 return rc;
776 }
777
749 while (retry-- > 0) { 778 while (retry-- > 0) {
750 rc = hisi_sas_softreset_ata_disk(device); 779 rc = hisi_sas_softreset_ata_disk(device);
751 if (!rc) 780 if (!rc)
@@ -808,6 +837,7 @@ static int hisi_sas_dev_found(struct domain_device *device)
808 rc = hisi_sas_init_device(device); 837 rc = hisi_sas_init_device(device);
809 if (rc) 838 if (rc)
810 goto err_out; 839 goto err_out;
840 sas_dev->dev_status = HISI_SAS_DEV_NORMAL;
811 return 0; 841 return 0;
812 842
813err_out: 843err_out:
@@ -980,7 +1010,8 @@ static void hisi_sas_do_release_task(struct hisi_hba *hisi_hba, struct sas_task
980 spin_lock_irqsave(&task->task_state_lock, flags); 1010 spin_lock_irqsave(&task->task_state_lock, flags);
981 task->task_state_flags &= 1011 task->task_state_flags &=
982 ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); 1012 ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
983 task->task_state_flags |= SAS_TASK_STATE_DONE; 1013 if (!slot->is_internal && task->task_proto != SAS_PROTOCOL_SMP)
1014 task->task_state_flags |= SAS_TASK_STATE_DONE;
984 spin_unlock_irqrestore(&task->task_state_lock, flags); 1015 spin_unlock_irqrestore(&task->task_state_lock, flags);
985 } 1016 }
986 1017
@@ -1713,20 +1744,23 @@ static int hisi_sas_clear_aca(struct domain_device *device, u8 *lun)
1713static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device) 1744static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device)
1714{ 1745{
1715 struct sas_phy *local_phy = sas_get_local_phy(device); 1746 struct sas_phy *local_phy = sas_get_local_phy(device);
1716 int rc, reset_type = (device->dev_type == SAS_SATA_DEV || 1747 struct hisi_sas_device *sas_dev = device->lldd_dev;
1717 (device->tproto & SAS_PROTOCOL_STP)) ? 0 : 1;
1718 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); 1748 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1719 struct sas_ha_struct *sas_ha = &hisi_hba->sha; 1749 struct sas_ha_struct *sas_ha = &hisi_hba->sha;
1720 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[local_phy->number]; 1750 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[local_phy->number];
1721 struct hisi_sas_phy *phy = container_of(sas_phy, 1751 struct hisi_sas_phy *phy = container_of(sas_phy,
1722 struct hisi_sas_phy, sas_phy); 1752 struct hisi_sas_phy, sas_phy);
1723 DECLARE_COMPLETION_ONSTACK(phyreset); 1753 DECLARE_COMPLETION_ONSTACK(phyreset);
1754 int rc, reset_type;
1724 1755
1725 if (scsi_is_sas_phy_local(local_phy)) { 1756 if (scsi_is_sas_phy_local(local_phy)) {
1726 phy->in_reset = 1; 1757 phy->in_reset = 1;
1727 phy->reset_completion = &phyreset; 1758 phy->reset_completion = &phyreset;
1728 } 1759 }
1729 1760
1761 reset_type = (sas_dev->dev_status == HISI_SAS_DEV_INIT ||
1762 !dev_is_sata(device)) ? 1 : 0;
1763
1730 rc = sas_phy_reset(local_phy, reset_type); 1764 rc = sas_phy_reset(local_phy, reset_type);
1731 sas_put_local_phy(local_phy); 1765 sas_put_local_phy(local_phy);
1732 1766
@@ -1742,8 +1776,13 @@ static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device)
1742 /* report PHY down if timed out */ 1776 /* report PHY down if timed out */
1743 if (!ret) 1777 if (!ret)
1744 hisi_sas_phy_down(hisi_hba, sas_phy->id, 0); 1778 hisi_sas_phy_down(hisi_hba, sas_phy->id, 0);
1745 } else 1779 } else if (sas_dev->dev_status != HISI_SAS_DEV_INIT) {
1780 /*
1781 * If in init state, we rely on caller to wait for link to be
1782 * ready; otherwise, delay.
1783 */
1746 msleep(2000); 1784 msleep(2000);
1785 }
1747 1786
1748 return rc; 1787 return rc;
1749} 1788}
@@ -1762,6 +1801,12 @@ static int hisi_sas_I_T_nexus_reset(struct domain_device *device)
1762 } 1801 }
1763 hisi_sas_dereg_device(hisi_hba, device); 1802 hisi_sas_dereg_device(hisi_hba, device);
1764 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
1765 rc = hisi_sas_debug_I_T_nexus_reset(device); 1810 rc = hisi_sas_debug_I_T_nexus_reset(device);
1766 1811
1767 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) 1812 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV))
@@ -2125,9 +2170,18 @@ static int hisi_sas_write_gpio(struct sas_ha_struct *sha, u8 reg_type,
2125 2170
2126static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy) 2171static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy)
2127{ 2172{
2173 struct asd_sas_phy *sas_phy = &phy->sas_phy;
2174 struct sas_phy *sphy = sas_phy->phy;
2175 struct sas_phy_data *d = sphy->hostdata;
2176
2128 phy->phy_attached = 0; 2177 phy->phy_attached = 0;
2129 phy->phy_type = 0; 2178 phy->phy_type = 0;
2130 phy->port = NULL; 2179 phy->port = NULL;
2180
2181 if (d->enable)
2182 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
2183 else
2184 sphy->negotiated_linkrate = SAS_PHY_DISABLED;
2131} 2185}
2132 2186
2133void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy) 2187void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy)
@@ -2253,6 +2307,7 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba)
2253 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { 2307 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
2254 hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED; 2308 hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED;
2255 hisi_hba->devices[i].device_id = i; 2309 hisi_hba->devices[i].device_id = i;
2310 hisi_hba->devices[i].dev_status = HISI_SAS_DEV_INIT;
2256 } 2311 }
2257 2312
2258 for (i = 0; i < hisi_hba->queue_count; i++) { 2313 for (i = 0; i < hisi_hba->queue_count; i++) {
diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
index e40cc6b3b67b..89160ab3efb0 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
@@ -868,6 +868,7 @@ hisi_sas_device *alloc_dev_quirk_v2_hw(struct domain_device *device)
868 868
869 hisi_hba->devices[i].device_id = i; 869 hisi_hba->devices[i].device_id = i;
870 sas_dev = &hisi_hba->devices[i]; 870 sas_dev = &hisi_hba->devices[i];
871 sas_dev->dev_status = HISI_SAS_DEV_INIT;
871 sas_dev->dev_type = device->dev_type; 872 sas_dev->dev_type = device->dev_type;
872 sas_dev->hisi_hba = hisi_hba; 873 sas_dev->hisi_hba = hisi_hba;
873 sas_dev->sas_device = device; 874 sas_dev->sas_device = device;
diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index 9ec8848ec541..086695a4099f 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -129,6 +129,7 @@
129#define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF) 129#define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF)
130#define CMD_HDR_PIR_OFF 8 130#define CMD_HDR_PIR_OFF 8
131#define CMD_HDR_PIR_MSK (0x1 << CMD_HDR_PIR_OFF) 131#define CMD_HDR_PIR_MSK (0x1 << CMD_HDR_PIR_OFF)
132#define SERDES_CFG (PORT_BASE + 0x1c)
132#define SL_CFG (PORT_BASE + 0x84) 133#define SL_CFG (PORT_BASE + 0x84)
133#define AIP_LIMIT (PORT_BASE + 0x90) 134#define AIP_LIMIT (PORT_BASE + 0x90)
134#define SL_CONTROL (PORT_BASE + 0x94) 135#define SL_CONTROL (PORT_BASE + 0x94)
@@ -181,6 +182,8 @@
181#define CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF 22 182#define CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF 22
182#define CHL_INT2 (PORT_BASE + 0x1bc) 183#define CHL_INT2 (PORT_BASE + 0x1bc)
183#define CHL_INT2_SL_IDAF_TOUT_CONF_OFF 0 184#define CHL_INT2_SL_IDAF_TOUT_CONF_OFF 0
185#define CHL_INT2_RX_DISP_ERR_OFF 28
186#define CHL_INT2_RX_CODE_ERR_OFF 29
184#define CHL_INT2_RX_INVLD_DW_OFF 30 187#define CHL_INT2_RX_INVLD_DW_OFF 30
185#define CHL_INT2_STP_LINK_TIMEOUT_OFF 31 188#define CHL_INT2_STP_LINK_TIMEOUT_OFF 31
186#define CHL_INT0_MSK (PORT_BASE + 0x1c0) 189#define CHL_INT0_MSK (PORT_BASE + 0x1c0)
@@ -523,6 +526,7 @@ static void init_reg_v3_hw(struct hisi_hba *hisi_hba)
523 } 526 }
524 hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 527 hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE,
525 prog_phy_link_rate); 528 prog_phy_link_rate);
529 hisi_sas_phy_write32(hisi_hba, i, SERDES_CFG, 0xffc00);
526 hisi_sas_phy_write32(hisi_hba, i, SAS_RX_TRAIN_TIMER, 0x13e80); 530 hisi_sas_phy_write32(hisi_hba, i, SAS_RX_TRAIN_TIMER, 0x13e80);
527 hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff); 531 hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff);
528 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff); 532 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff);
@@ -544,6 +548,8 @@ static void init_reg_v3_hw(struct hisi_hba *hisi_hba)
544 hisi_sas_phy_write32(hisi_hba, i, STP_LINK_TIMER, 0x7f7a120); 548 hisi_sas_phy_write32(hisi_hba, i, STP_LINK_TIMER, 0x7f7a120);
545 hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x2a0a01); 549 hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x2a0a01);
546 hisi_sas_phy_write32(hisi_hba, i, SAS_SSP_CON_TIMER_CFG, 0x32); 550 hisi_sas_phy_write32(hisi_hba, i, SAS_SSP_CON_TIMER_CFG, 0x32);
551 hisi_sas_phy_write32(hisi_hba, i, SAS_EC_INT_COAL_TIME,
552 0x30f4240);
547 /* used for 12G negotiate */ 553 /* used for 12G negotiate */
548 hisi_sas_phy_write32(hisi_hba, i, COARSETUNE_TIME, 0x1e); 554 hisi_sas_phy_write32(hisi_hba, i, COARSETUNE_TIME, 0x1e);
549 hisi_sas_phy_write32(hisi_hba, i, AIP_LIMIT, 0x2ffff); 555 hisi_sas_phy_write32(hisi_hba, i, AIP_LIMIT, 0x2ffff);
@@ -1344,7 +1350,8 @@ static void prep_abort_v3_hw(struct hisi_hba *hisi_hba,
1344 1350
1345static irqreturn_t phy_up_v3_hw(int phy_no, struct hisi_hba *hisi_hba) 1351static irqreturn_t phy_up_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
1346{ 1352{
1347 int i, res; 1353 int i;
1354 irqreturn_t res;
1348 u32 context, port_id, link_rate; 1355 u32 context, port_id, link_rate;
1349 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; 1356 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1350 struct asd_sas_phy *sas_phy = &phy->sas_phy; 1357 struct asd_sas_phy *sas_phy = &phy->sas_phy;
@@ -1575,6 +1582,39 @@ static void handle_chl_int1_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1575 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT1, irq_value); 1582 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT1, irq_value);
1576} 1583}
1577 1584
1585static void phy_get_events_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1586{
1587 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1588 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1589 struct sas_phy *sphy = sas_phy->phy;
1590 unsigned long flags;
1591 u32 reg_value;
1592
1593 spin_lock_irqsave(&phy->lock, flags);
1594
1595 /* loss dword sync */
1596 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DWS_LOST);
1597 sphy->loss_of_dword_sync_count += reg_value;
1598
1599 /* phy reset problem */
1600 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_RESET_PROB);
1601 sphy->phy_reset_problem_count += reg_value;
1602
1603 /* invalid dword */
1604 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_INVLD_DW);
1605 sphy->invalid_dword_count += reg_value;
1606
1607 /* disparity err */
1608 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DISP_ERR);
1609 sphy->running_disparity_error_count += reg_value;
1610
1611 /* code violation error */
1612 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_CODE_ERR);
1613 phy->code_violation_err_count += reg_value;
1614
1615 spin_unlock_irqrestore(&phy->lock, flags);
1616}
1617
1578static void handle_chl_int2_v3_hw(struct hisi_hba *hisi_hba, int phy_no) 1618static void handle_chl_int2_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1579{ 1619{
1580 u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2_MSK); 1620 u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2_MSK);
@@ -1582,6 +1622,9 @@ static void handle_chl_int2_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1582 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; 1622 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1583 struct pci_dev *pci_dev = hisi_hba->pci_dev; 1623 struct pci_dev *pci_dev = hisi_hba->pci_dev;
1584 struct device *dev = hisi_hba->dev; 1624 struct device *dev = hisi_hba->dev;
1625 static const u32 msk = BIT(CHL_INT2_RX_DISP_ERR_OFF) |
1626 BIT(CHL_INT2_RX_CODE_ERR_OFF) |
1627 BIT(CHL_INT2_RX_INVLD_DW_OFF);
1585 1628
1586 irq_value &= ~irq_msk; 1629 irq_value &= ~irq_msk;
1587 if (!irq_value) 1630 if (!irq_value)
@@ -1602,6 +1645,25 @@ static void handle_chl_int2_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1602 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET); 1645 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1603 } 1646 }
1604 1647
1648 if (pci_dev->revision > 0x20 && (irq_value & msk)) {
1649 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1650 struct sas_phy *sphy = sas_phy->phy;
1651
1652 phy_get_events_v3_hw(hisi_hba, phy_no);
1653
1654 if (irq_value & BIT(CHL_INT2_RX_INVLD_DW_OFF))
1655 dev_info(dev, "phy%d invalid dword cnt: %u\n", phy_no,
1656 sphy->invalid_dword_count);
1657
1658 if (irq_value & BIT(CHL_INT2_RX_CODE_ERR_OFF))
1659 dev_info(dev, "phy%d code violation cnt: %u\n", phy_no,
1660 phy->code_violation_err_count);
1661
1662 if (irq_value & BIT(CHL_INT2_RX_DISP_ERR_OFF))
1663 dev_info(dev, "phy%d disparity error cnt: %u\n", phy_no,
1664 sphy->running_disparity_error_count);
1665 }
1666
1605 if ((irq_value & BIT(CHL_INT2_RX_INVLD_DW_OFF)) && 1667 if ((irq_value & BIT(CHL_INT2_RX_INVLD_DW_OFF)) &&
1606 (pci_dev->revision == 0x20)) { 1668 (pci_dev->revision == 0x20)) {
1607 u32 reg_value; 1669 u32 reg_value;
@@ -2230,31 +2292,6 @@ static u32 get_phys_state_v3_hw(struct hisi_hba *hisi_hba)
2230 return hisi_sas_read32(hisi_hba, PHY_STATE); 2292 return hisi_sas_read32(hisi_hba, PHY_STATE);
2231} 2293}
2232 2294
2233static void phy_get_events_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
2234{
2235 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
2236 struct asd_sas_phy *sas_phy = &phy->sas_phy;
2237 struct sas_phy *sphy = sas_phy->phy;
2238 u32 reg_value;
2239
2240 /* loss dword sync */
2241 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DWS_LOST);
2242 sphy->loss_of_dword_sync_count += reg_value;
2243
2244 /* phy reset problem */
2245 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_RESET_PROB);
2246 sphy->phy_reset_problem_count += reg_value;
2247
2248 /* invalid dword */
2249 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_INVLD_DW);
2250 sphy->invalid_dword_count += reg_value;
2251
2252 /* disparity err */
2253 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DISP_ERR);
2254 sphy->running_disparity_error_count += reg_value;
2255
2256}
2257
2258static int disable_host_v3_hw(struct hisi_hba *hisi_hba) 2295static int disable_host_v3_hw(struct hisi_hba *hisi_hba)
2259{ 2296{
2260 struct device *dev = hisi_hba->dev; 2297 struct device *dev = hisi_hba->dev;
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/libiscsi.c b/drivers/scsi/libiscsi.c
index 21309d5b456d..e893949a3d11 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -798,7 +798,7 @@ EXPORT_SYMBOL_GPL(iscsi_conn_send_pdu);
798 * @datalen: len of buffer 798 * @datalen: len of buffer
799 * 799 *
800 * iscsi_cmd_rsp sets up the scsi_cmnd fields based on the PDU and 800 * iscsi_cmd_rsp sets up the scsi_cmnd fields based on the PDU and
801 * then completes the command and task. 801 * then completes the command and task. called under back_lock
802 **/ 802 **/
803static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, 803static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
804 struct iscsi_task *task, char *data, 804 struct iscsi_task *task, char *data,
@@ -894,6 +894,9 @@ out:
894 * @conn: iscsi connection 894 * @conn: iscsi connection
895 * @hdr: iscsi pdu 895 * @hdr: iscsi pdu
896 * @task: scsi command task 896 * @task: scsi command task
897 *
898 * iscsi_data_in_rsp sets up the scsi_cmnd fields based on the data received
899 * then completes the command and task. called under back_lock
897 **/ 900 **/
898static void 901static void
899iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, 902iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
@@ -978,6 +981,16 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
978 return 0; 981 return 0;
979} 982}
980 983
984/**
985 * iscsi_nop_out_rsp - SCSI NOP Response processing
986 * @task: scsi command task
987 * @nop: the nop structure
988 * @data: where to put the data
989 * @datalen: length of data
990 *
991 * iscsi_nop_out_rsp handles nop response from use or
992 * from user space. called under back_lock
993 **/
981static int iscsi_nop_out_rsp(struct iscsi_task *task, 994static int iscsi_nop_out_rsp(struct iscsi_task *task,
982 struct iscsi_nopin *nop, char *data, int datalen) 995 struct iscsi_nopin *nop, char *data, int datalen)
983{ 996{
@@ -1750,7 +1763,9 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)
1750 return 0; 1763 return 0;
1751 1764
1752prepd_reject: 1765prepd_reject:
1766 spin_lock_bh(&session->back_lock);
1753 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ); 1767 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
1768 spin_unlock_bh(&session->back_lock);
1754reject: 1769reject:
1755 spin_unlock_bh(&session->frwd_lock); 1770 spin_unlock_bh(&session->frwd_lock);
1756 ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n", 1771 ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n",
@@ -1758,7 +1773,9 @@ reject:
1758 return SCSI_MLQUEUE_TARGET_BUSY; 1773 return SCSI_MLQUEUE_TARGET_BUSY;
1759 1774
1760prepd_fault: 1775prepd_fault:
1776 spin_lock_bh(&session->back_lock);
1761 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ); 1777 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
1778 spin_unlock_bh(&session->back_lock);
1762fault: 1779fault:
1763 spin_unlock_bh(&session->frwd_lock); 1780 spin_unlock_bh(&session->frwd_lock);
1764 ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n", 1781 ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n",
@@ -3075,8 +3092,9 @@ fail_mgmt_tasks(struct iscsi_session *session, struct iscsi_conn *conn)
3075 state = ISCSI_TASK_ABRT_SESS_RECOV; 3092 state = ISCSI_TASK_ABRT_SESS_RECOV;
3076 if (task->state == ISCSI_TASK_PENDING) 3093 if (task->state == ISCSI_TASK_PENDING)
3077 state = ISCSI_TASK_COMPLETED; 3094 state = ISCSI_TASK_COMPLETED;
3095 spin_lock_bh(&session->back_lock);
3078 iscsi_complete_task(task, state); 3096 iscsi_complete_task(task, state);
3079 3097 spin_unlock_bh(&session->back_lock);
3080 } 3098 }
3081} 3099}
3082 3100
diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c
index 9923e9e3b884..c3fe3f3a78f5 100644
--- a/drivers/scsi/libiscsi_tcp.c
+++ b/drivers/scsi/libiscsi_tcp.c
@@ -129,12 +129,17 @@ static void iscsi_tcp_segment_map(struct iscsi_segment *segment, int recv)
129 BUG_ON(sg->length == 0); 129 BUG_ON(sg->length == 0);
130 130
131 /* 131 /*
132 * We always map for the recv path.
133 *
132 * If the page count is greater than one it is ok to send 134 * If the page count is greater than one it is ok to send
133 * to the network layer's zero copy send path. If not we 135 * to the network layer's zero copy send path. If not we
134 * have to go the slow sendmsg path. We always map for the 136 * have to go the slow sendmsg path.
135 * recv path. 137 *
138 * Same goes for slab pages: skb_can_coalesce() allows
139 * coalescing neighboring slab objects into a single frag which
140 * triggers one of hardened usercopy checks.
136 */ 141 */
137 if (page_count(sg_page(sg)) >= 1 && !recv) 142 if (!recv && page_count(sg_page(sg)) >= 1 && !PageSlab(sg_page(sg)))
138 return; 143 return;
139 144
140 if (recv) { 145 if (recv) {
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 3b5873f6751e..7fcdaed3fa94 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -4090,7 +4090,7 @@ lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc)
4090 /* Sanity check to ensure our sizing is right for both SCSI and NVME */ 4090 /* Sanity check to ensure our sizing is right for both SCSI and NVME */
4091 if (sizeof(struct lpfc_io_buf) > LPFC_COMMON_IO_BUF_SZ) { 4091 if (sizeof(struct lpfc_io_buf) > LPFC_COMMON_IO_BUF_SZ) {
4092 lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 4092 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
4093 "6426 Common buffer size %ld exceeds %d\n", 4093 "6426 Common buffer size %zd exceeds %d\n",
4094 sizeof(struct lpfc_io_buf), 4094 sizeof(struct lpfc_io_buf),
4095 LPFC_COMMON_IO_BUF_SZ); 4095 LPFC_COMMON_IO_BUF_SZ);
4096 return 0; 4096 return 0;
@@ -10052,7 +10052,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10052{ 10052{
10053 struct pci_dev *pdev = phba->pcidev; 10053 struct pci_dev *pdev = phba->pcidev;
10054 unsigned long bar0map_len, bar1map_len, bar2map_len; 10054 unsigned long bar0map_len, bar1map_len, bar2map_len;
10055 int error = -ENODEV; 10055 int error;
10056 uint32_t if_type; 10056 uint32_t if_type;
10057 10057
10058 if (!pdev) 10058 if (!pdev)
@@ -10071,7 +10071,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10071 */ 10071 */
10072 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, 10072 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
10073 &phba->sli4_hba.sli_intf.word0)) { 10073 &phba->sli4_hba.sli_intf.word0)) {
10074 return error; 10074 return -ENODEV;
10075 } 10075 }
10076 10076
10077 /* There is no SLI3 failback for SLI4 devices. */ 10077 /* There is no SLI3 failback for SLI4 devices. */
@@ -10081,7 +10081,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10081 "2894 SLI_INTF reg contents invalid " 10081 "2894 SLI_INTF reg contents invalid "
10082 "sli_intf reg 0x%x\n", 10082 "sli_intf reg 0x%x\n",
10083 phba->sli4_hba.sli_intf.word0); 10083 phba->sli4_hba.sli_intf.word0);
10084 return error; 10084 return -ENODEV;
10085 } 10085 }
10086 10086
10087 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); 10087 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
@@ -10105,7 +10105,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10105 dev_printk(KERN_ERR, &pdev->dev, 10105 dev_printk(KERN_ERR, &pdev->dev,
10106 "ioremap failed for SLI4 PCI config " 10106 "ioremap failed for SLI4 PCI config "
10107 "registers.\n"); 10107 "registers.\n");
10108 goto out; 10108 return -ENODEV;
10109 } 10109 }
10110 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; 10110 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
10111 /* Set up BAR0 PCI config space register memory map */ 10111 /* Set up BAR0 PCI config space register memory map */
@@ -10116,7 +10116,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10116 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { 10116 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10117 dev_printk(KERN_ERR, &pdev->dev, 10117 dev_printk(KERN_ERR, &pdev->dev,
10118 "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); 10118 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
10119 goto out; 10119 return -ENODEV;
10120 } 10120 }
10121 phba->sli4_hba.conf_regs_memmap_p = 10121 phba->sli4_hba.conf_regs_memmap_p =
10122 ioremap(phba->pci_bar0_map, bar0map_len); 10122 ioremap(phba->pci_bar0_map, bar0map_len);
@@ -10124,7 +10124,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10124 dev_printk(KERN_ERR, &pdev->dev, 10124 dev_printk(KERN_ERR, &pdev->dev,
10125 "ioremap failed for SLI4 PCI config " 10125 "ioremap failed for SLI4 PCI config "
10126 "registers.\n"); 10126 "registers.\n");
10127 goto out; 10127 return -ENODEV;
10128 } 10128 }
10129 lpfc_sli4_bar0_register_memmap(phba, if_type); 10129 lpfc_sli4_bar0_register_memmap(phba, if_type);
10130 } 10130 }
@@ -10170,6 +10170,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10170 if (!phba->sli4_hba.drbl_regs_memmap_p) { 10170 if (!phba->sli4_hba.drbl_regs_memmap_p) {
10171 dev_err(&pdev->dev, 10171 dev_err(&pdev->dev,
10172 "ioremap failed for SLI4 HBA doorbell registers.\n"); 10172 "ioremap failed for SLI4 HBA doorbell registers.\n");
10173 error = -ENOMEM;
10173 goto out_iounmap_conf; 10174 goto out_iounmap_conf;
10174 } 10175 }
10175 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; 10176 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
@@ -10219,6 +10220,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
10219 if (!phba->sli4_hba.dpp_regs_memmap_p) { 10220 if (!phba->sli4_hba.dpp_regs_memmap_p) {
10220 dev_err(&pdev->dev, 10221 dev_err(&pdev->dev,
10221 "ioremap failed for SLI4 HBA dpp registers.\n"); 10222 "ioremap failed for SLI4 HBA dpp registers.\n");
10223 error = -ENOMEM;
10222 goto out_iounmap_ctrl; 10224 goto out_iounmap_ctrl;
10223 } 10225 }
10224 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; 10226 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
@@ -10249,7 +10251,7 @@ out_iounmap_ctrl:
10249 iounmap(phba->sli4_hba.ctrl_regs_memmap_p); 10251 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
10250out_iounmap_conf: 10252out_iounmap_conf:
10251 iounmap(phba->sli4_hba.conf_regs_memmap_p); 10253 iounmap(phba->sli4_hba.conf_regs_memmap_p);
10252out: 10254
10253 return error; 10255 return error;
10254} 10256}
10255 10257
@@ -11137,7 +11139,8 @@ lpfc_sli4_hba_unset(struct lpfc_hba *phba)
11137 lpfc_sli4_ras_dma_free(phba); 11139 lpfc_sli4_ras_dma_free(phba);
11138 11140
11139 /* Stop the SLI4 device port */ 11141 /* Stop the SLI4 device port */
11140 phba->pport->work_port_events = 0; 11142 if (phba->pport)
11143 phba->pport->work_port_events = 0;
11141} 11144}
11142 11145
11143 /** 11146 /**
diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
index 55ab9d3ee4ba..1aa00d2c3f74 100644
--- a/drivers/scsi/lpfc/lpfc_nvme.c
+++ b/drivers/scsi/lpfc/lpfc_nvme.c
@@ -965,7 +965,7 @@ lpfc_nvme_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
965 struct lpfc_nodelist *ndlp; 965 struct lpfc_nodelist *ndlp;
966 struct lpfc_nvme_fcpreq_priv *freqpriv; 966 struct lpfc_nvme_fcpreq_priv *freqpriv;
967 struct lpfc_nvme_lport *lport; 967 struct lpfc_nvme_lport *lport;
968 uint32_t code, status, idx, cpu; 968 uint32_t code, status, idx;
969 uint16_t cid, sqhd, data; 969 uint16_t cid, sqhd, data;
970 uint32_t *ptr; 970 uint32_t *ptr;
971 971
@@ -1138,6 +1138,7 @@ out_err:
1138 lpfc_nvme_ktime(phba, lpfc_ncmd); 1138 lpfc_nvme_ktime(phba, lpfc_ncmd);
1139 } 1139 }
1140 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) { 1140 if (phba->cpucheck_on & LPFC_CHECK_NVME_IO) {
1141 uint32_t cpu;
1141 idx = lpfc_ncmd->cur_iocbq.hba_wqidx; 1142 idx = lpfc_ncmd->cur_iocbq.hba_wqidx;
1142 cpu = smp_processor_id(); 1143 cpu = smp_processor_id();
1143 if (cpu < LPFC_CHECK_CPU_CNT) { 1144 if (cpu < LPFC_CHECK_CPU_CNT) {
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index d0817facdae3..57b4a463b589 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -9881,7 +9881,7 @@ __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
9881 * The WQE can be either 64 or 128 bytes, 9881 * The WQE can be either 64 or 128 bytes,
9882 */ 9882 */
9883 9883
9884 lockdep_assert_held(&phba->hbalock); 9884 lockdep_assert_held(&pring->ring_lock);
9885 9885
9886 if (piocb->sli4_xritag == NO_XRI) { 9886 if (piocb->sli4_xritag == NO_XRI) {
9887 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || 9887 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index dace907744a5..293f5cf524d7 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -3924,12 +3924,12 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr)
3924 /* 3924 /*
3925 * The cur_state should not last for more than max_wait secs 3925 * The cur_state should not last for more than max_wait secs
3926 */ 3926 */
3927 for (i = 0; i < max_wait; i++) { 3927 for (i = 0; i < max_wait * 50; i++) {
3928 curr_abs_state = instance->instancet-> 3928 curr_abs_state = instance->instancet->
3929 read_fw_status_reg(instance); 3929 read_fw_status_reg(instance);
3930 3930
3931 if (abs_state == curr_abs_state) { 3931 if (abs_state == curr_abs_state) {
3932 msleep(1000); 3932 msleep(20);
3933 } else 3933 } else
3934 break; 3934 break;
3935 } 3935 }
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 2eb1ae721a7d..f928c4d3a1ef 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -1652,6 +1652,8 @@ qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1652 } 1652 }
1653 1653
1654 rval = kstrtol(buf, 10, &type); 1654 rval = kstrtol(buf, 10, &type);
1655 if (rval)
1656 return rval;
1655 speed = type; 1657 speed = type;
1656 if (type == 40 || type == 80 || type == 160 || 1658 if (type == 40 || type == 80 || type == 160 ||
1657 type == 320) { 1659 type == 320) {
diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index ead17288e2a7..5819a45ac5ef 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -193,6 +193,8 @@ qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
193 193
194 for (i = 0; i < vha->hw->max_qpairs; i++) { 194 for (i = 0; i < vha->hw->max_qpairs; i++) {
195 qpair = vha->hw->queue_pair_map[i]; 195 qpair = vha->hw->queue_pair_map[i];
196 if (!qpair)
197 continue;
196 qla_core_sbt_cmd += qpair->tgt_counters.qla_core_sbt_cmd; 198 qla_core_sbt_cmd += qpair->tgt_counters.qla_core_sbt_cmd;
197 core_qla_que_buf += qpair->tgt_counters.core_qla_que_buf; 199 core_qla_que_buf += qpair->tgt_counters.core_qla_que_buf;
198 qla_core_ret_ctio += qpair->tgt_counters.qla_core_ret_ctio; 200 qla_core_ret_ctio += qpair->tgt_counters.qla_core_ret_ctio;
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_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 63f8e3c19841..456a41d2e2c6 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -1132,7 +1132,7 @@ qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp,
1132 /* if initiator doing write or target doing read */ 1132 /* if initiator doing write or target doing read */
1133 if (direction_to_device) { 1133 if (direction_to_device) {
1134 for_each_sg(sgl, sg, tot_dsds, i) { 1134 for_each_sg(sgl, sg, tot_dsds, i) {
1135 dma_addr_t sle_phys = sg_phys(sg); 1135 u64 sle_phys = sg_phys(sg);
1136 1136
1137 /* If SGE addr + len flips bits in upper 32-bits */ 1137 /* If SGE addr + len flips bits in upper 32-bits */
1138 if (MSD(sle_phys + sg->length) ^ MSD(sle_phys)) { 1138 if (MSD(sle_phys + sg->length) ^ MSD(sle_phys)) {
@@ -1178,7 +1178,7 @@ qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp,
1178 1178
1179 ql_dbg(ql_dbg_tgt + ql_dbg_verbose, vha, 0xe023, 1179 ql_dbg(ql_dbg_tgt + ql_dbg_verbose, vha, 0xe023,
1180 "%s: sg[%x] (phys=%llx sglen=%x) ldma_sg_len: %x dif_bundl_len: %x ldma_needed: %x\n", 1180 "%s: sg[%x] (phys=%llx sglen=%x) ldma_sg_len: %x dif_bundl_len: %x ldma_needed: %x\n",
1181 __func__, i, sg_phys(sg), sglen, ldma_sg_len, 1181 __func__, i, (u64)sg_phys(sg), sglen, ldma_sg_len,
1182 difctx->dif_bundl_len, ldma_needed); 1182 difctx->dif_bundl_len, ldma_needed);
1183 1183
1184 while (sglen) { 1184 while (sglen) {
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/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 5d9ccbab7581..75ec43aa8df3 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -2764,6 +2764,12 @@ static void pqi_process_raid_io_error(struct pqi_io_request *io_request)
2764 sshdr.sense_key == HARDWARE_ERROR && 2764 sshdr.sense_key == HARDWARE_ERROR &&
2765 sshdr.asc == 0x3e && 2765 sshdr.asc == 0x3e &&
2766 sshdr.ascq == 0x1) { 2766 sshdr.ascq == 0x1) {
2767 struct pqi_ctrl_info *ctrl_info = shost_to_hba(scmd->device->host);
2768 struct pqi_scsi_dev *device = scmd->device->hostdata;
2769
2770 if (printk_ratelimit())
2771 scmd_printk(KERN_ERR, scmd, "received 'logical unit failure' from controller for scsi %d:%d:%d:%d\n",
2772 ctrl_info->scsi_host->host_no, device->bus, device->target, device->lun);
2767 pqi_take_device_offline(scmd->device, "RAID"); 2773 pqi_take_device_offline(scmd->device, "RAID");
2768 host_byte = DID_NO_CONNECT; 2774 host_byte = DID_NO_CONNECT;
2769 } 2775 }
diff --git a/drivers/scsi/ufs/ufs-hisi.c b/drivers/scsi/ufs/ufs-hisi.c
index f2d3df357a97..0e855b5afe82 100644
--- a/drivers/scsi/ufs/ufs-hisi.c
+++ b/drivers/scsi/ufs/ufs-hisi.c
@@ -640,7 +640,7 @@ static int ufs_hi3670_init(struct ufs_hba *hba)
640 return 0; 640 return 0;
641} 641}
642 642
643static struct ufs_hba_variant_ops ufs_hba_hi3660_vops = { 643static const struct ufs_hba_variant_ops ufs_hba_hi3660_vops = {
644 .name = "hi3660", 644 .name = "hi3660",
645 .init = ufs_hi3660_init, 645 .init = ufs_hi3660_init,
646 .link_startup_notify = ufs_hisi_link_startup_notify, 646 .link_startup_notify = ufs_hisi_link_startup_notify,
@@ -649,7 +649,7 @@ static struct ufs_hba_variant_ops ufs_hba_hi3660_vops = {
649 .resume = ufs_hisi_resume, 649 .resume = ufs_hisi_resume,
650}; 650};
651 651
652static struct ufs_hba_variant_ops ufs_hba_hi3670_vops = { 652static const struct ufs_hba_variant_ops ufs_hba_hi3670_vops = {
653 .name = "hi3670", 653 .name = "hi3670",
654 .init = ufs_hi3670_init, 654 .init = ufs_hi3670_init,
655 .link_startup_notify = ufs_hisi_link_startup_notify, 655 .link_startup_notify = ufs_hisi_link_startup_notify,
@@ -669,13 +669,10 @@ MODULE_DEVICE_TABLE(of, ufs_hisi_of_match);
669static int ufs_hisi_probe(struct platform_device *pdev) 669static int ufs_hisi_probe(struct platform_device *pdev)
670{ 670{
671 const struct of_device_id *of_id; 671 const struct of_device_id *of_id;
672 struct ufs_hba_variant_ops *vops;
673 struct device *dev = &pdev->dev;
674 672
675 of_id = of_match_node(ufs_hisi_of_match, dev->of_node); 673 of_id = of_match_node(ufs_hisi_of_match, pdev->dev.of_node);
676 vops = (struct ufs_hba_variant_ops *)of_id->data;
677 674
678 return ufshcd_pltfrm_init(pdev, vops); 675 return ufshcd_pltfrm_init(pdev, of_id->data);
679} 676}
680 677
681static int ufs_hisi_remove(struct platform_device *pdev) 678static int ufs_hisi_remove(struct platform_device *pdev)
diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
index 895a9b5ac989..27213676329c 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
@@ -297,7 +297,7 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba)
297 * Returns 0 on success, non-zero value on failure 297 * Returns 0 on success, non-zero value on failure
298 */ 298 */
299int ufshcd_pltfrm_init(struct platform_device *pdev, 299int ufshcd_pltfrm_init(struct platform_device *pdev,
300 struct ufs_hba_variant_ops *vops) 300 const struct ufs_hba_variant_ops *vops)
301{ 301{
302 struct ufs_hba *hba; 302 struct ufs_hba *hba;
303 void __iomem *mmio_base; 303 void __iomem *mmio_base;
diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.h b/drivers/scsi/ufs/ufshcd-pltfrm.h
index df64c4180340..1f29e1fd6d52 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.h
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.h
@@ -17,7 +17,7 @@
17#include "ufshcd.h" 17#include "ufshcd.h"
18 18
19int ufshcd_pltfrm_init(struct platform_device *pdev, 19int ufshcd_pltfrm_init(struct platform_device *pdev,
20 struct ufs_hba_variant_ops *vops); 20 const struct ufs_hba_variant_ops *vops);
21void ufshcd_pltfrm_shutdown(struct platform_device *pdev); 21void ufshcd_pltfrm_shutdown(struct platform_device *pdev);
22 22
23#ifdef CONFIG_PM 23#ifdef CONFIG_PM
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 69ba7445d2b3..ecfa898b9ccc 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -546,7 +546,7 @@ struct ufs_hba {
546 int nutrs; 546 int nutrs;
547 int nutmrs; 547 int nutmrs;
548 u32 ufs_version; 548 u32 ufs_version;
549 struct ufs_hba_variant_ops *vops; 549 const struct ufs_hba_variant_ops *vops;
550 void *priv; 550 void *priv;
551 unsigned int irq; 551 unsigned int irq;
552 bool is_irq_enabled; 552 bool is_irq_enabled;
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 1a6f150cd2d8..8af01777d09c 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -586,7 +586,6 @@ static int virtscsi_device_reset(struct scsi_cmnd *sc)
586 return FAILED; 586 return FAILED;
587 587
588 memset(cmd, 0, sizeof(*cmd)); 588 memset(cmd, 0, sizeof(*cmd));
589 cmd->sc = sc;
590 cmd->req.tmf = (struct virtio_scsi_ctrl_tmf_req){ 589 cmd->req.tmf = (struct virtio_scsi_ctrl_tmf_req){
591 .type = VIRTIO_SCSI_T_TMF, 590 .type = VIRTIO_SCSI_T_TMF,
592 .subtype = cpu_to_virtio32(vscsi->vdev, 591 .subtype = cpu_to_virtio32(vscsi->vdev,
@@ -645,7 +644,6 @@ static int virtscsi_abort(struct scsi_cmnd *sc)
645 return FAILED; 644 return FAILED;
646 645
647 memset(cmd, 0, sizeof(*cmd)); 646 memset(cmd, 0, sizeof(*cmd));
648 cmd->sc = sc;
649 cmd->req.tmf = (struct virtio_scsi_ctrl_tmf_req){ 647 cmd->req.tmf = (struct virtio_scsi_ctrl_tmf_req){
650 .type = VIRTIO_SCSI_T_TMF, 648 .type = VIRTIO_SCSI_T_TMF,
651 .subtype = VIRTIO_SCSI_T_TMF_ABORT_TASK, 649 .subtype = VIRTIO_SCSI_T_TMF_ABORT_TASK,
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 5831e0eecea1..9704b135a7bc 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1663,7 +1663,7 @@ static void tcmu_dev_kref_release(struct kref *kref)
1663 WARN_ON(!all_expired); 1663 WARN_ON(!all_expired);
1664 1664
1665 tcmu_blocks_release(&udev->data_blocks, 0, udev->dbi_max + 1); 1665 tcmu_blocks_release(&udev->data_blocks, 0, udev->dbi_max + 1);
1666 kfree(udev->data_bitmap); 1666 bitmap_free(udev->data_bitmap);
1667 mutex_unlock(&udev->cmdr_lock); 1667 mutex_unlock(&udev->cmdr_lock);
1668 1668
1669 call_rcu(&dev->rcu_head, tcmu_dev_call_rcu); 1669 call_rcu(&dev->rcu_head, tcmu_dev_call_rcu);
@@ -1794,11 +1794,12 @@ static int tcmu_netlink_event_send(struct tcmu_dev *udev,
1794 1794
1795 ret = genlmsg_multicast_allns(&tcmu_genl_family, skb, 0, 1795 ret = genlmsg_multicast_allns(&tcmu_genl_family, skb, 0,
1796 TCMU_MCGRP_CONFIG, GFP_KERNEL); 1796 TCMU_MCGRP_CONFIG, GFP_KERNEL);
1797 /* We don't care if no one is listening */ 1797
1798 if (ret == -ESRCH) 1798 /* Wait during an add as the listener may not be up yet */
1799 ret = 0; 1799 if (ret == 0 ||
1800 if (!ret) 1800 (ret == -ESRCH && cmd == TCMU_CMD_ADDED_DEVICE))
1801 ret = tcmu_wait_genl_cmd_reply(udev); 1801 return tcmu_wait_genl_cmd_reply(udev);
1802
1802 return ret; 1803 return ret;
1803} 1804}
1804 1805
@@ -1870,9 +1871,7 @@ static int tcmu_configure_device(struct se_device *dev)
1870 info = &udev->uio_info; 1871 info = &udev->uio_info;
1871 1872
1872 mutex_lock(&udev->cmdr_lock); 1873 mutex_lock(&udev->cmdr_lock);
1873 udev->data_bitmap = kcalloc(BITS_TO_LONGS(udev->max_blocks), 1874 udev->data_bitmap = bitmap_zalloc(udev->max_blocks, GFP_KERNEL);
1874 sizeof(unsigned long),
1875 GFP_KERNEL);
1876 mutex_unlock(&udev->cmdr_lock); 1875 mutex_unlock(&udev->cmdr_lock);
1877 if (!udev->data_bitmap) { 1876 if (!udev->data_bitmap) {
1878 ret = -ENOMEM; 1877 ret = -ENOMEM;
@@ -1959,7 +1958,7 @@ err_register:
1959 vfree(udev->mb_addr); 1958 vfree(udev->mb_addr);
1960 udev->mb_addr = NULL; 1959 udev->mb_addr = NULL;
1961err_vzalloc: 1960err_vzalloc:
1962 kfree(udev->data_bitmap); 1961 bitmap_free(udev->data_bitmap);
1963 udev->data_bitmap = NULL; 1962 udev->data_bitmap = NULL;
1964err_bitmap_alloc: 1963err_bitmap_alloc:
1965 kfree(info->name); 1964 kfree(info->name);
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/drivers/video/fbdev/aty/radeon_pm.c b/drivers/video/fbdev/aty/radeon_pm.c
index e695adb0e573..2dc5703eac51 100644
--- a/drivers/video/fbdev/aty/radeon_pm.c
+++ b/drivers/video/fbdev/aty/radeon_pm.c
@@ -2844,8 +2844,8 @@ void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk, int ignore_devlis
2844 * in some desktop G4s), Via (M9+ chip on iBook G4) and 2844 * in some desktop G4s), Via (M9+ chip on iBook G4) and
2845 * Snowy (M11 chip on iBook G4 manufactured after July 2005) 2845 * Snowy (M11 chip on iBook G4 manufactured after July 2005)
2846 */ 2846 */
2847 if (!strcmp(rinfo->of_node->name, "ATY,JasperParent") || 2847 if (of_node_name_eq(rinfo->of_node, "ATY,JasperParent") ||
2848 !strcmp(rinfo->of_node->name, "ATY,SnowyParent")) { 2848 of_node_name_eq(rinfo->of_node, "ATY,SnowyParent")) {
2849 rinfo->reinit_func = radeon_reinitialize_M10; 2849 rinfo->reinit_func = radeon_reinitialize_M10;
2850 rinfo->pm_mode |= radeon_pm_off; 2850 rinfo->pm_mode |= radeon_pm_off;
2851 } 2851 }
@@ -2855,7 +2855,7 @@ void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk, int ignore_devlis
2855 rinfo->pm_mode |= radeon_pm_off; 2855 rinfo->pm_mode |= radeon_pm_off;
2856 } 2856 }
2857#endif 2857#endif
2858 if (!strcmp(rinfo->of_node->name, "ATY,ViaParent")) { 2858 if (of_node_name_eq(rinfo->of_node, "ATY,ViaParent")) {
2859 rinfo->reinit_func = radeon_reinitialize_M9P; 2859 rinfo->reinit_func = radeon_reinitialize_M9P;
2860 rinfo->pm_mode |= radeon_pm_off; 2860 rinfo->pm_mode |= radeon_pm_off;
2861 } 2861 }
diff --git a/drivers/video/fbdev/cg14.c b/drivers/video/fbdev/cg14.c
index 9af54c2368fd..a6dce1a78490 100644
--- a/drivers/video/fbdev/cg14.c
+++ b/drivers/video/fbdev/cg14.c
@@ -486,8 +486,8 @@ static int cg14_probe(struct platform_device *op)
486 info->var.xres); 486 info->var.xres);
487 info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres); 487 info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
488 488
489 if (!strcmp(dp->parent->name, "sbus") || 489 if (of_node_name_eq(dp->parent, "sbus") ||
490 !strcmp(dp->parent->name, "sbi")) { 490 of_node_name_eq(dp->parent, "sbi")) {
491 info->fix.smem_start = op->resource[0].start; 491 info->fix.smem_start = op->resource[0].start;
492 par->iospace = op->resource[0].flags & IORESOURCE_BITS; 492 par->iospace = op->resource[0].flags & IORESOURCE_BITS;
493 } else { 493 } else {
diff --git a/drivers/video/fbdev/cg3.c b/drivers/video/fbdev/cg3.c
index 1bd95b02f3aa..6d42def8436b 100644
--- a/drivers/video/fbdev/cg3.c
+++ b/drivers/video/fbdev/cg3.c
@@ -369,7 +369,7 @@ static int cg3_probe(struct platform_device *op)
369 info->var.red.length = 8; 369 info->var.red.length = 8;
370 info->var.green.length = 8; 370 info->var.green.length = 8;
371 info->var.blue.length = 8; 371 info->var.blue.length = 8;
372 if (!strcmp(dp->name, "cgRDI")) 372 if (of_node_name_eq(dp, "cgRDI"))
373 par->flags |= CG3_FLAG_RDI; 373 par->flags |= CG3_FLAG_RDI;
374 if (par->flags & CG3_FLAG_RDI) 374 if (par->flags & CG3_FLAG_RDI)
375 cg3_rdi_maybe_fixup_var(&info->var, dp); 375 cg3_rdi_maybe_fixup_var(&info->var, dp);
diff --git a/drivers/video/fbdev/chipsfb.c b/drivers/video/fbdev/chipsfb.c
index 40182ed85648..ca549e1532e6 100644
--- a/drivers/video/fbdev/chipsfb.c
+++ b/drivers/video/fbdev/chipsfb.c
@@ -349,7 +349,7 @@ static void init_chips(struct fb_info *p, unsigned long addr)
349static int chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent) 349static int chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
350{ 350{
351 struct fb_info *p; 351 struct fb_info *p;
352 unsigned long addr, size; 352 unsigned long addr;
353 unsigned short cmd; 353 unsigned short cmd;
354 int rc = -ENODEV; 354 int rc = -ENODEV;
355 355
@@ -361,7 +361,6 @@ static int chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
361 if ((dp->resource[0].flags & IORESOURCE_MEM) == 0) 361 if ((dp->resource[0].flags & IORESOURCE_MEM) == 0)
362 goto err_disable; 362 goto err_disable;
363 addr = pci_resource_start(dp, 0); 363 addr = pci_resource_start(dp, 0);
364 size = pci_resource_len(dp, 0);
365 if (addr == 0) 364 if (addr == 0)
366 goto err_disable; 365 goto err_disable;
367 366
diff --git a/drivers/video/fbdev/core/fb_cmdline.c b/drivers/video/fbdev/core/fb_cmdline.c
index 39509ccd92f1..3b5bd666b952 100644
--- a/drivers/video/fbdev/core/fb_cmdline.c
+++ b/drivers/video/fbdev/core/fb_cmdline.c
@@ -75,36 +75,33 @@ EXPORT_SYMBOL(fb_get_options);
75 * NOTE: This function is a __setup and __init function. 75 * NOTE: This function is a __setup and __init function.
76 * It only stores the options. Drivers have to call 76 * It only stores the options. Drivers have to call
77 * fb_get_options() as necessary. 77 * fb_get_options() as necessary.
78 *
79 * Returns zero.
80 *
81 */ 78 */
82static int __init video_setup(char *options) 79static int __init video_setup(char *options)
83{ 80{
84 int i, global = 0;
85
86 if (!options || !*options) 81 if (!options || !*options)
87 global = 1; 82 goto out;
88 83
89 if (!global && !strncmp(options, "ofonly", 6)) { 84 if (!strncmp(options, "ofonly", 6)) {
90 ofonly = 1; 85 ofonly = 1;
91 global = 1; 86 goto out;
92 } 87 }
93 88
94 if (!global && !strchr(options, ':')) { 89 if (strchr(options, ':')) {
95 fb_mode_option = options; 90 /* named */
96 global = 1; 91 int i;
97 }
98 92
99 if (!global) {
100 for (i = 0; i < FB_MAX; i++) { 93 for (i = 0; i < FB_MAX; i++) {
101 if (video_options[i] == NULL) { 94 if (video_options[i] == NULL) {
102 video_options[i] = options; 95 video_options[i] = options;
103 break; 96 break;
104 } 97 }
105 } 98 }
99 } else {
100 /* global */
101 fb_mode_option = options;
106 } 102 }
107 103
104out:
108 return 1; 105 return 1;
109} 106}
110__setup("video=", video_setup); 107__setup("video=", video_setup);
diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index bfa1360ec750..cd059a801662 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -656,11 +656,14 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
656 kfree(save); 656 kfree(save);
657 } 657 }
658 658
659 if (logo_shown == FBCON_LOGO_DONTSHOW)
660 return;
661
659 if (logo_lines > vc->vc_bottom) { 662 if (logo_lines > vc->vc_bottom) {
660 logo_shown = FBCON_LOGO_CANSHOW; 663 logo_shown = FBCON_LOGO_CANSHOW;
661 printk(KERN_INFO 664 printk(KERN_INFO
662 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n"); 665 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
663 } else if (logo_shown != FBCON_LOGO_DONTSHOW) { 666 } else {
664 logo_shown = FBCON_LOGO_DRAW; 667 logo_shown = FBCON_LOGO_DRAW;
665 vc->vc_top = logo_lines; 668 vc->vc_top = logo_lines;
666 } 669 }
@@ -999,7 +1002,7 @@ static const char *fbcon_startup(void)
999 if (!softback_buf) { 1002 if (!softback_buf) {
1000 softback_buf = 1003 softback_buf =
1001 (unsigned long) 1004 (unsigned long)
1002 kmalloc(fbcon_softback_size, 1005 kvmalloc(fbcon_softback_size,
1003 GFP_KERNEL); 1006 GFP_KERNEL);
1004 if (!softback_buf) { 1007 if (!softback_buf) {
1005 fbcon_softback_size = 0; 1008 fbcon_softback_size = 0;
@@ -1008,7 +1011,7 @@ static const char *fbcon_startup(void)
1008 } 1011 }
1009 } else { 1012 } else {
1010 if (softback_buf) { 1013 if (softback_buf) {
1011 kfree((void *) softback_buf); 1014 kvfree((void *) softback_buf);
1012 softback_buf = 0; 1015 softback_buf = 0;
1013 softback_top = 0; 1016 softback_top = 0;
1014 } 1017 }
@@ -1066,6 +1069,9 @@ static void fbcon_init(struct vc_data *vc, int init)
1066 1069
1067 cap = info->flags; 1070 cap = info->flags;
1068 1071
1072 if (console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1073 logo_shown = FBCON_LOGO_DONTSHOW;
1074
1069 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW || 1075 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1070 (info->fix.type == FB_TYPE_TEXT)) 1076 (info->fix.type == FB_TYPE_TEXT))
1071 logo = 0; 1077 logo = 0;
@@ -3672,7 +3678,7 @@ static void fbcon_exit(void)
3672 } 3678 }
3673#endif 3679#endif
3674 3680
3675 kfree((void *)softback_buf); 3681 kvfree((void *)softback_buf);
3676 softback_buf = 0UL; 3682 softback_buf = 0UL;
3677 3683
3678 for_each_registered_fb(i) { 3684 for_each_registered_fb(i) {
diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index cb43a2258c51..4721491e6c8c 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -431,6 +431,9 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
431{ 431{
432 unsigned int x; 432 unsigned int x;
433 433
434 if (image->width > info->var.xres || image->height > info->var.yres)
435 return;
436
434 if (rotate == FB_ROTATE_UR) { 437 if (rotate == FB_ROTATE_UR) {
435 for (x = 0; 438 for (x = 0;
436 x < num && image->dx + image->width <= info->var.xres; 439 x < num && image->dx + image->width <= info->var.xres;
diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c
index dd3128990776..3558a70a6664 100644
--- a/drivers/video/fbdev/core/fbmon.c
+++ b/drivers/video/fbdev/core/fbmon.c
@@ -978,6 +978,8 @@ void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
978 get_monspecs(edid, specs); 978 get_monspecs(edid, specs);
979 979
980 specs->modedb = fb_create_modedb(edid, &specs->modedb_len, specs); 980 specs->modedb = fb_create_modedb(edid, &specs->modedb_len, specs);
981 if (!specs->modedb)
982 return;
981 983
982 /* 984 /*
983 * Workaround for buggy EDIDs that sets that the first 985 * Workaround for buggy EDIDs that sets that the first
diff --git a/drivers/video/fbdev/ffb.c b/drivers/video/fbdev/ffb.c
index 6b1915872af1..b7aee0c427a8 100644
--- a/drivers/video/fbdev/ffb.c
+++ b/drivers/video/fbdev/ffb.c
@@ -944,7 +944,7 @@ static int ffb_probe(struct platform_device *op)
944 944
945 info->var.accel_flags = FB_ACCELF_TEXT; 945 info->var.accel_flags = FB_ACCELF_TEXT;
946 946
947 if (!strcmp(dp->name, "SUNW,afb")) 947 if (of_node_name_eq(dp, "SUNW,afb"))
948 par->flags |= FFB_FLAG_AFB; 948 par->flags |= FFB_FLAG_AFB;
949 949
950 par->board_type = of_getintprop_default(dp, "board_type", 0); 950 par->board_type = of_getintprop_default(dp, "board_type", 0);
diff --git a/drivers/video/fbdev/geode/gxfb_core.c b/drivers/video/fbdev/geode/gxfb_core.c
index f4f76373b2a8..b1906cf5a8f0 100644
--- a/drivers/video/fbdev/geode/gxfb_core.c
+++ b/drivers/video/fbdev/geode/gxfb_core.c
@@ -33,6 +33,8 @@
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/cs5535.h> 34#include <linux/cs5535.h>
35 35
36#include <asm/olpc.h>
37
36#include "gxfb.h" 38#include "gxfb.h"
37 39
38static char *mode_option; 40static char *mode_option;
@@ -107,9 +109,6 @@ static struct fb_videomode gx_modedb[] = {
107 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, 109 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
108}; 110};
109 111
110#ifdef CONFIG_OLPC
111#include <asm/olpc.h>
112
113static struct fb_videomode gx_dcon_modedb[] = { 112static struct fb_videomode gx_dcon_modedb[] = {
114 /* The only mode the DCON has is 1200x900 */ 113 /* The only mode the DCON has is 1200x900 */
115 { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3, 114 { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3,
@@ -128,14 +127,6 @@ static void get_modedb(struct fb_videomode **modedb, unsigned int *size)
128 } 127 }
129} 128}
130 129
131#else
132static void get_modedb(struct fb_videomode **modedb, unsigned int *size)
133{
134 *modedb = (struct fb_videomode *) gx_modedb;
135 *size = ARRAY_SIZE(gx_modedb);
136}
137#endif
138
139static int gxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 130static int gxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
140{ 131{
141 if (var->xres > 1600 || var->yres > 1200) 132 if (var->xres > 1600 || var->yres > 1200)
diff --git a/drivers/video/fbdev/geode/lxfb_core.c b/drivers/video/fbdev/geode/lxfb_core.c
index 138da6cb6cbc..17ab905811b1 100644
--- a/drivers/video/fbdev/geode/lxfb_core.c
+++ b/drivers/video/fbdev/geode/lxfb_core.c
@@ -23,6 +23,8 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/uaccess.h> 24#include <linux/uaccess.h>
25 25
26#include <asm/olpc.h>
27
26#include "lxfb.h" 28#include "lxfb.h"
27 29
28static char *mode_option; 30static char *mode_option;
@@ -216,9 +218,6 @@ static struct fb_videomode geode_modedb[] = {
216 0, FB_VMODE_NONINTERLACED, 0 }, 218 0, FB_VMODE_NONINTERLACED, 0 },
217}; 219};
218 220
219#ifdef CONFIG_OLPC
220#include <asm/olpc.h>
221
222static struct fb_videomode olpc_dcon_modedb[] = { 221static struct fb_videomode olpc_dcon_modedb[] = {
223 /* The only mode the DCON has is 1200x900 */ 222 /* The only mode the DCON has is 1200x900 */
224 { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3, 223 { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3,
@@ -237,14 +236,6 @@ static void get_modedb(struct fb_videomode **modedb, unsigned int *size)
237 } 236 }
238} 237}
239 238
240#else
241static void get_modedb(struct fb_videomode **modedb, unsigned int *size)
242{
243 *modedb = (struct fb_videomode *) geode_modedb;
244 *size = ARRAY_SIZE(geode_modedb);
245}
246#endif
247
248static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 239static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
249{ 240{
250 if (var->xres > 1920 || var->yres > 1440) 241 if (var->xres > 1920 || var->yres > 1440)
diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
index 5d9670daf60e..4b9615e4ce74 100644
--- a/drivers/video/fbdev/imsttfb.c
+++ b/drivers/video/fbdev/imsttfb.c
@@ -1497,8 +1497,8 @@ static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1497 switch (pdev->device) { 1497 switch (pdev->device) {
1498 case PCI_DEVICE_ID_IMS_TT128: /* IMS,tt128mbA */ 1498 case PCI_DEVICE_ID_IMS_TT128: /* IMS,tt128mbA */
1499 par->ramdac = IBM; 1499 par->ramdac = IBM;
1500 if (dp && ((strcmp(dp->name, "IMS,tt128mb8") == 0) || 1500 if (of_node_name_eq(dp, "IMS,tt128mb8") ||
1501 (strcmp(dp->name, "IMS,tt128mb8A") == 0))) 1501 of_node_name_eq(dp, "IMS,tt128mb8A"))
1502 par->ramdac = TVP; 1502 par->ramdac = TVP;
1503 break; 1503 break;
1504 case PCI_DEVICE_ID_IMS_TT3D: /* IMS,tt3d */ 1504 case PCI_DEVICE_ID_IMS_TT3D: /* IMS,tt3d */
diff --git a/drivers/video/fbdev/mbx/mbxdebugfs.c b/drivers/video/fbdev/mbx/mbxdebugfs.c
index 2bd328883178..09af721638fb 100644
--- a/drivers/video/fbdev/mbx/mbxdebugfs.c
+++ b/drivers/video/fbdev/mbx/mbxdebugfs.c
@@ -211,36 +211,22 @@ static const struct file_operations misc_fops = {
211static void mbxfb_debugfs_init(struct fb_info *fbi) 211static void mbxfb_debugfs_init(struct fb_info *fbi)
212{ 212{
213 struct mbxfb_info *mfbi = fbi->par; 213 struct mbxfb_info *mfbi = fbi->par;
214 struct mbxfb_debugfs_data *dbg; 214 struct dentry *dir;
215 215
216 dbg = kzalloc(sizeof(struct mbxfb_debugfs_data), GFP_KERNEL); 216 dir = debugfs_create_dir("mbxfb", NULL);
217 mfbi->debugfs_data = dbg; 217 mfbi->debugfs_dir = dir;
218 218
219 dbg->dir = debugfs_create_dir("mbxfb", NULL); 219 debugfs_create_file("sysconf", 0444, dir, fbi, &sysconf_fops);
220 dbg->sysconf = debugfs_create_file("sysconf", 0444, dbg->dir, 220 debugfs_create_file("clock", 0444, dir, fbi, &clock_fops);
221 fbi, &sysconf_fops); 221 debugfs_create_file("display", 0444, dir, fbi, &display_fops);
222 dbg->clock = debugfs_create_file("clock", 0444, dbg->dir, 222 debugfs_create_file("gsctl", 0444, dir, fbi, &gsctl_fops);
223 fbi, &clock_fops); 223 debugfs_create_file("sdram", 0444, dir, fbi, &sdram_fops);
224 dbg->display = debugfs_create_file("display", 0444, dbg->dir, 224 debugfs_create_file("misc", 0444, dir, fbi, &misc_fops);
225 fbi, &display_fops);
226 dbg->gsctl = debugfs_create_file("gsctl", 0444, dbg->dir,
227 fbi, &gsctl_fops);
228 dbg->sdram = debugfs_create_file("sdram", 0444, dbg->dir,
229 fbi, &sdram_fops);
230 dbg->misc = debugfs_create_file("misc", 0444, dbg->dir,
231 fbi, &misc_fops);
232} 225}
233 226
234static void mbxfb_debugfs_remove(struct fb_info *fbi) 227static void mbxfb_debugfs_remove(struct fb_info *fbi)
235{ 228{
236 struct mbxfb_info *mfbi = fbi->par; 229 struct mbxfb_info *mfbi = fbi->par;
237 struct mbxfb_debugfs_data *dbg = mfbi->debugfs_data; 230
238 231 debugfs_remove_recursive(mfbi->debugfs_dir);
239 debugfs_remove(dbg->misc);
240 debugfs_remove(dbg->sdram);
241 debugfs_remove(dbg->gsctl);
242 debugfs_remove(dbg->display);
243 debugfs_remove(dbg->clock);
244 debugfs_remove(dbg->sysconf);
245 debugfs_remove(dbg->dir);
246} 232}
diff --git a/drivers/video/fbdev/mbx/mbxfb.c b/drivers/video/fbdev/mbx/mbxfb.c
index 539b85da0897..6ded480a69b4 100644
--- a/drivers/video/fbdev/mbx/mbxfb.c
+++ b/drivers/video/fbdev/mbx/mbxfb.c
@@ -74,7 +74,7 @@ struct mbxfb_info {
74 74
75 u32 pseudo_palette[MAX_PALETTES]; 75 u32 pseudo_palette[MAX_PALETTES];
76#ifdef CONFIG_FB_MBX_DEBUG 76#ifdef CONFIG_FB_MBX_DEBUG
77 void *debugfs_data; 77 struct dentry *debugfs_dir;
78#endif 78#endif
79 79
80}; 80};
diff --git a/drivers/video/fbdev/offb.c b/drivers/video/fbdev/offb.c
index 057d3cdef92e..fbc6eafb63c7 100644
--- a/drivers/video/fbdev/offb.c
+++ b/drivers/video/fbdev/offb.c
@@ -141,6 +141,7 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
141 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */ 141 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
142 out_le32(par->cmap_adr + 0x58, 142 out_le32(par->cmap_adr + 0x58,
143 in_le32(par->cmap_adr + 0x58) & ~0x20); 143 in_le32(par->cmap_adr + 0x58) & ~0x20);
144 /* fall through */
144 case cmap_r128: 145 case cmap_r128:
145 /* Set palette index & data */ 146 /* Set palette index & data */
146 out_8(par->cmap_adr + 0xb0, regno); 147 out_8(par->cmap_adr + 0xb0, regno);
@@ -210,6 +211,7 @@ static int offb_blank(int blank, struct fb_info *info)
210 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */ 211 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
211 out_le32(par->cmap_adr + 0x58, 212 out_le32(par->cmap_adr + 0x58,
212 in_le32(par->cmap_adr + 0x58) & ~0x20); 213 in_le32(par->cmap_adr + 0x58) & ~0x20);
214 /* fall through */
213 case cmap_r128: 215 case cmap_r128:
214 /* Set palette index & data */ 216 /* Set palette index & data */
215 out_8(par->cmap_adr + 0xb0, i); 217 out_8(par->cmap_adr + 0xb0, i);
@@ -646,7 +648,7 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
646 } 648 }
647#endif 649#endif
648 /* kludge for valkyrie */ 650 /* kludge for valkyrie */
649 if (strcmp(dp->name, "valkyrie") == 0) 651 if (of_node_name_eq(dp, "valkyrie"))
650 address += 0x1000; 652 address += 0x1000;
651 offb_init_fb(no_real_node ? "bootx" : NULL, 653 offb_init_fb(no_real_node ? "bootx" : NULL,
652 width, height, depth, pitch, address, 654 width, height, depth, pitch, address,
diff --git a/drivers/video/fbdev/omap2/omapfb/dss/core.c b/drivers/video/fbdev/omap2/omapfb/dss/core.c
index b4bcf3a4a647..b5956a1a30d4 100644
--- a/drivers/video/fbdev/omap2/omapfb/dss/core.c
+++ b/drivers/video/fbdev/omap2/omapfb/dss/core.c
@@ -110,19 +110,12 @@ DEFINE_SHOW_ATTRIBUTE(dss);
110 110
111static struct dentry *dss_debugfs_dir; 111static struct dentry *dss_debugfs_dir;
112 112
113static int dss_initialize_debugfs(void) 113static void dss_initialize_debugfs(void)
114{ 114{
115 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL); 115 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
116 if (IS_ERR(dss_debugfs_dir)) {
117 int err = PTR_ERR(dss_debugfs_dir);
118 dss_debugfs_dir = NULL;
119 return err;
120 }
121 116
122 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir, 117 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
123 &dss_debug_dump_clocks, &dss_fops); 118 &dss_debug_dump_clocks, &dss_fops);
124
125 return 0;
126} 119}
127 120
128static void dss_uninitialize_debugfs(void) 121static void dss_uninitialize_debugfs(void)
@@ -130,26 +123,19 @@ static void dss_uninitialize_debugfs(void)
130 debugfs_remove_recursive(dss_debugfs_dir); 123 debugfs_remove_recursive(dss_debugfs_dir);
131} 124}
132 125
133int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *)) 126void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
134{ 127{
135 struct dentry *d; 128 debugfs_create_file(name, S_IRUGO, dss_debugfs_dir, write, &dss_fops);
136
137 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
138 write, &dss_fops);
139
140 return PTR_ERR_OR_ZERO(d);
141} 129}
142#else /* CONFIG_FB_OMAP2_DSS_DEBUGFS */ 130#else /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
143static inline int dss_initialize_debugfs(void) 131static inline void dss_initialize_debugfs(void)
144{ 132{
145 return 0;
146} 133}
147static inline void dss_uninitialize_debugfs(void) 134static inline void dss_uninitialize_debugfs(void)
148{ 135{
149} 136}
150int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *)) 137void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
151{ 138{
152 return 0;
153} 139}
154#endif /* CONFIG_FB_OMAP2_DSS_DEBUGFS */ 140#endif /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
155 141
@@ -182,15 +168,11 @@ static struct notifier_block omap_dss_pm_notif_block = {
182 168
183static int __init omap_dss_probe(struct platform_device *pdev) 169static int __init omap_dss_probe(struct platform_device *pdev)
184{ 170{
185 int r;
186
187 core.pdev = pdev; 171 core.pdev = pdev;
188 172
189 dss_features_init(omapdss_get_version()); 173 dss_features_init(omapdss_get_version());
190 174
191 r = dss_initialize_debugfs(); 175 dss_initialize_debugfs();
192 if (r)
193 goto err_debugfs;
194 176
195 if (def_disp_name) 177 if (def_disp_name)
196 core.default_display_name = def_disp_name; 178 core.default_display_name = def_disp_name;
@@ -198,10 +180,6 @@ static int __init omap_dss_probe(struct platform_device *pdev)
198 register_pm_notifier(&omap_dss_pm_notif_block); 180 register_pm_notifier(&omap_dss_pm_notif_block);
199 181
200 return 0; 182 return 0;
201
202err_debugfs:
203
204 return r;
205} 183}
206 184
207static int omap_dss_remove(struct platform_device *pdev) 185static int omap_dss_remove(struct platform_device *pdev)
diff --git a/drivers/video/fbdev/omap2/omapfb/dss/dss-of.c b/drivers/video/fbdev/omap2/omapfb/dss/dss-of.c
index f1eb8b0f8a2a..5ce893c1923d 100644
--- a/drivers/video/fbdev/omap2/omapfb/dss/dss-of.c
+++ b/drivers/video/fbdev/omap2/omapfb/dss/dss-of.c
@@ -60,7 +60,7 @@ omapdss_of_get_next_port(const struct device_node *parent,
60 return NULL; 60 return NULL;
61 } 61 }
62 prev = port; 62 prev = port;
63 } while (of_node_cmp(port->name, "port") != 0); 63 } while (!of_node_name_eq(port, "port"));
64 64
65 of_node_put(ports); 65 of_node_put(ports);
66 } 66 }
@@ -83,7 +83,7 @@ omapdss_of_get_next_endpoint(const struct device_node *parent,
83 if (!ep) 83 if (!ep)
84 return NULL; 84 return NULL;
85 prev = ep; 85 prev = ep;
86 } while (of_node_cmp(ep->name, "endpoint") != 0); 86 } while (!of_node_name_eq(ep, "endpoint"));
87 87
88 return ep; 88 return ep;
89} 89}
diff --git a/drivers/video/fbdev/omap2/omapfb/dss/dss.h b/drivers/video/fbdev/omap2/omapfb/dss/dss.h
index a3cc0ca8f9d2..b1a354494144 100644
--- a/drivers/video/fbdev/omap2/omapfb/dss/dss.h
+++ b/drivers/video/fbdev/omap2/omapfb/dss/dss.h
@@ -214,7 +214,7 @@ struct platform_device *dss_get_core_pdev(void);
214int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask); 214int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask);
215void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask); 215void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask);
216int dss_set_min_bus_tput(struct device *dev, unsigned long tput); 216int dss_set_min_bus_tput(struct device *dev, unsigned long tput);
217int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *)); 217void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
218 218
219/* display */ 219/* display */
220int dss_suspend_all_devices(void); 220int dss_suspend_all_devices(void);
diff --git a/drivers/video/fbdev/omap2/omapfb/dss/hdmi4_core.c b/drivers/video/fbdev/omap2/omapfb/dss/hdmi4_core.c
index fa72e735dad2..d146793dd044 100644
--- a/drivers/video/fbdev/omap2/omapfb/dss/hdmi4_core.c
+++ b/drivers/video/fbdev/omap2/omapfb/dss/hdmi4_core.c
@@ -712,7 +712,7 @@ int hdmi4_audio_config(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
712 else 712 else
713 acore.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT; 713 acore.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
714 /* 714 /*
715 * The I2S input word length is twice the lenght given in the IEC-60958 715 * The I2S input word length is twice the length given in the IEC-60958
716 * status word. If the word size is greater than 716 * status word. If the word size is greater than
717 * 20 bits, increment by one. 717 * 20 bits, increment by one.
718 */ 718 */
diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index 4061a20cfe24..3b361bc9feb8 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -667,10 +667,10 @@ static int ssd1307fb_probe(struct i2c_client *client,
667 667
668 if (par->reset) { 668 if (par->reset) {
669 /* Reset the screen */ 669 /* Reset the screen */
670 gpiod_set_value_cansleep(par->reset, 0);
671 udelay(4);
672 gpiod_set_value_cansleep(par->reset, 1); 670 gpiod_set_value_cansleep(par->reset, 1);
673 udelay(4); 671 udelay(4);
672 gpiod_set_value_cansleep(par->reset, 0);
673 udelay(4);
674 } 674 }
675 675
676 if (par->vbat_reg) { 676 if (par->vbat_reg) {
diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
index 7bb7e90b8f00..bdf5a0ea876d 100644
--- a/drivers/video/fbdev/via/viafbdev.c
+++ b/drivers/video/fbdev/via/viafbdev.c
@@ -2110,7 +2110,7 @@ MODULE_PARM_DESC(viafb_lcd_panel_id,
2110 2110
2111module_param(viafb_lcd_dsp_method, int, S_IRUSR); 2111module_param(viafb_lcd_dsp_method, int, S_IRUSR);
2112MODULE_PARM_DESC(viafb_lcd_dsp_method, 2112MODULE_PARM_DESC(viafb_lcd_dsp_method,
2113 "Set Flat Panel display scaling method.(Default=Expandsion)"); 2113 "Set Flat Panel display scaling method.(Default=Expansion)");
2114 2114
2115module_param(viafb_SAMM_ON, int, S_IRUSR); 2115module_param(viafb_SAMM_ON, int, S_IRUSR);
2116MODULE_PARM_DESC(viafb_SAMM_ON, 2116MODULE_PARM_DESC(viafb_SAMM_ON,
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 39b229f9e256..d37dd5bb7a8f 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -604,6 +604,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)
604 while (pgno < nr_pages) { 604 while (pgno < nr_pages) {
605 page = balloon_retrieve(true); 605 page = balloon_retrieve(true);
606 if (page) { 606 if (page) {
607 __ClearPageOffline(page);
607 pages[pgno++] = page; 608 pages[pgno++] = page;
608#ifdef CONFIG_XEN_HAVE_PVMMU 609#ifdef CONFIG_XEN_HAVE_PVMMU
609 /* 610 /*
@@ -645,8 +646,10 @@ void free_xenballooned_pages(int nr_pages, struct page **pages)
645 mutex_lock(&balloon_mutex); 646 mutex_lock(&balloon_mutex);
646 647
647 for (i = 0; i < nr_pages; i++) { 648 for (i = 0; i < nr_pages; i++) {
648 if (pages[i]) 649 if (pages[i]) {
650 __SetPageOffline(pages[i]);
649 balloon_append(pages[i]); 651 balloon_append(pages[i]);
652 }
650 } 653 }
651 654
652 balloon_stats.target_unpopulated -= nr_pages; 655 balloon_stats.target_unpopulated -= nr_pages;
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h
index 5a0db6dec8d1..aaee1e6584e6 100644
--- a/fs/9p/v9fs_vfs.h
+++ b/fs/9p/v9fs_vfs.h
@@ -40,6 +40,9 @@
40 */ 40 */
41#define P9_LOCK_TIMEOUT (30*HZ) 41#define P9_LOCK_TIMEOUT (30*HZ)
42 42
43/* flags for v9fs_stat2inode() & v9fs_stat2inode_dotl() */
44#define V9FS_STAT2INODE_KEEP_ISIZE 1
45
43extern struct file_system_type v9fs_fs_type; 46extern struct file_system_type v9fs_fs_type;
44extern const struct address_space_operations v9fs_addr_operations; 47extern const struct address_space_operations v9fs_addr_operations;
45extern const struct file_operations v9fs_file_operations; 48extern const struct file_operations v9fs_file_operations;
@@ -61,8 +64,10 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
61 struct inode *inode, umode_t mode, dev_t); 64 struct inode *inode, umode_t mode, dev_t);
62void v9fs_evict_inode(struct inode *inode); 65void v9fs_evict_inode(struct inode *inode);
63ino_t v9fs_qid2ino(struct p9_qid *qid); 66ino_t v9fs_qid2ino(struct p9_qid *qid);
64void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *); 67void v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
65void v9fs_stat2inode_dotl(struct p9_stat_dotl *, struct inode *); 68 struct super_block *sb, unsigned int flags);
69void v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
70 unsigned int flags);
66int v9fs_dir_release(struct inode *inode, struct file *filp); 71int v9fs_dir_release(struct inode *inode, struct file *filp);
67int v9fs_file_open(struct inode *inode, struct file *file); 72int v9fs_file_open(struct inode *inode, struct file *file);
68void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat); 73void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat);
@@ -83,4 +88,18 @@ static inline void v9fs_invalidate_inode_attr(struct inode *inode)
83} 88}
84 89
85int v9fs_open_to_dotl_flags(int flags); 90int v9fs_open_to_dotl_flags(int flags);
91
92static inline void v9fs_i_size_write(struct inode *inode, loff_t i_size)
93{
94 /*
95 * 32-bit need the lock, concurrent updates could break the
96 * sequences and make i_size_read() loop forever.
97 * 64-bit updates are atomic and can skip the locking.
98 */
99 if (sizeof(i_size) > sizeof(long))
100 spin_lock(&inode->i_lock);
101 i_size_write(inode, i_size);
102 if (sizeof(i_size) > sizeof(long))
103 spin_unlock(&inode->i_lock);
104}
86#endif 105#endif
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index a25efa782fcc..9a1125305d84 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -446,7 +446,11 @@ v9fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
446 i_size = i_size_read(inode); 446 i_size = i_size_read(inode);
447 if (iocb->ki_pos > i_size) { 447 if (iocb->ki_pos > i_size) {
448 inode_add_bytes(inode, iocb->ki_pos - i_size); 448 inode_add_bytes(inode, iocb->ki_pos - i_size);
449 i_size_write(inode, iocb->ki_pos); 449 /*
450 * Need to serialize against i_size_write() in
451 * v9fs_stat2inode()
452 */
453 v9fs_i_size_write(inode, iocb->ki_pos);
450 } 454 }
451 return retval; 455 return retval;
452 } 456 }
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 85ff859d3af5..72b779bc0942 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -538,7 +538,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
538 if (retval) 538 if (retval)
539 goto error; 539 goto error;
540 540
541 v9fs_stat2inode(st, inode, sb); 541 v9fs_stat2inode(st, inode, sb, 0);
542 v9fs_cache_inode_get_cookie(inode); 542 v9fs_cache_inode_get_cookie(inode);
543 unlock_new_inode(inode); 543 unlock_new_inode(inode);
544 return inode; 544 return inode;
@@ -1092,7 +1092,7 @@ v9fs_vfs_getattr(const struct path *path, struct kstat *stat,
1092 if (IS_ERR(st)) 1092 if (IS_ERR(st))
1093 return PTR_ERR(st); 1093 return PTR_ERR(st);
1094 1094
1095 v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb); 1095 v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb, 0);
1096 generic_fillattr(d_inode(dentry), stat); 1096 generic_fillattr(d_inode(dentry), stat);
1097 1097
1098 p9stat_free(st); 1098 p9stat_free(st);
@@ -1170,12 +1170,13 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1170 * @stat: Plan 9 metadata (mistat) structure 1170 * @stat: Plan 9 metadata (mistat) structure
1171 * @inode: inode to populate 1171 * @inode: inode to populate
1172 * @sb: superblock of filesystem 1172 * @sb: superblock of filesystem
1173 * @flags: control flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
1173 * 1174 *
1174 */ 1175 */
1175 1176
1176void 1177void
1177v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, 1178v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1178 struct super_block *sb) 1179 struct super_block *sb, unsigned int flags)
1179{ 1180{
1180 umode_t mode; 1181 umode_t mode;
1181 char ext[32]; 1182 char ext[32];
@@ -1216,10 +1217,11 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1216 mode = p9mode2perm(v9ses, stat); 1217 mode = p9mode2perm(v9ses, stat);
1217 mode |= inode->i_mode & ~S_IALLUGO; 1218 mode |= inode->i_mode & ~S_IALLUGO;
1218 inode->i_mode = mode; 1219 inode->i_mode = mode;
1219 i_size_write(inode, stat->length);
1220 1220
1221 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
1222 v9fs_i_size_write(inode, stat->length);
1221 /* not real number of blocks, but 512 byte ones ... */ 1223 /* not real number of blocks, but 512 byte ones ... */
1222 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; 1224 inode->i_blocks = (stat->length + 512 - 1) >> 9;
1223 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR; 1225 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
1224} 1226}
1225 1227
@@ -1416,9 +1418,9 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
1416{ 1418{
1417 int umode; 1419 int umode;
1418 dev_t rdev; 1420 dev_t rdev;
1419 loff_t i_size;
1420 struct p9_wstat *st; 1421 struct p9_wstat *st;
1421 struct v9fs_session_info *v9ses; 1422 struct v9fs_session_info *v9ses;
1423 unsigned int flags;
1422 1424
1423 v9ses = v9fs_inode2v9ses(inode); 1425 v9ses = v9fs_inode2v9ses(inode);
1424 st = p9_client_stat(fid); 1426 st = p9_client_stat(fid);
@@ -1431,16 +1433,13 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
1431 if ((inode->i_mode & S_IFMT) != (umode & S_IFMT)) 1433 if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
1432 goto out; 1434 goto out;
1433 1435
1434 spin_lock(&inode->i_lock);
1435 /* 1436 /*
1436 * We don't want to refresh inode->i_size, 1437 * We don't want to refresh inode->i_size,
1437 * because we may have cached data 1438 * because we may have cached data
1438 */ 1439 */
1439 i_size = inode->i_size; 1440 flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
1440 v9fs_stat2inode(st, inode, inode->i_sb); 1441 V9FS_STAT2INODE_KEEP_ISIZE : 0;
1441 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) 1442 v9fs_stat2inode(st, inode, inode->i_sb, flags);
1442 inode->i_size = i_size;
1443 spin_unlock(&inode->i_lock);
1444out: 1443out:
1445 p9stat_free(st); 1444 p9stat_free(st);
1446 kfree(st); 1445 kfree(st);
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index 4823e1c46999..a950a927a626 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -143,7 +143,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
143 if (retval) 143 if (retval)
144 goto error; 144 goto error;
145 145
146 v9fs_stat2inode_dotl(st, inode); 146 v9fs_stat2inode_dotl(st, inode, 0);
147 v9fs_cache_inode_get_cookie(inode); 147 v9fs_cache_inode_get_cookie(inode);
148 retval = v9fs_get_acl(inode, fid); 148 retval = v9fs_get_acl(inode, fid);
149 if (retval) 149 if (retval)
@@ -496,7 +496,7 @@ v9fs_vfs_getattr_dotl(const struct path *path, struct kstat *stat,
496 if (IS_ERR(st)) 496 if (IS_ERR(st))
497 return PTR_ERR(st); 497 return PTR_ERR(st);
498 498
499 v9fs_stat2inode_dotl(st, d_inode(dentry)); 499 v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
500 generic_fillattr(d_inode(dentry), stat); 500 generic_fillattr(d_inode(dentry), stat);
501 /* Change block size to what the server returned */ 501 /* Change block size to what the server returned */
502 stat->blksize = st->st_blksize; 502 stat->blksize = st->st_blksize;
@@ -607,11 +607,13 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
607 * v9fs_stat2inode_dotl - populate an inode structure with stat info 607 * v9fs_stat2inode_dotl - populate an inode structure with stat info
608 * @stat: stat structure 608 * @stat: stat structure
609 * @inode: inode to populate 609 * @inode: inode to populate
610 * @flags: ctrl flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
610 * 611 *
611 */ 612 */
612 613
613void 614void
614v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) 615v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
616 unsigned int flags)
615{ 617{
616 umode_t mode; 618 umode_t mode;
617 struct v9fs_inode *v9inode = V9FS_I(inode); 619 struct v9fs_inode *v9inode = V9FS_I(inode);
@@ -631,7 +633,8 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
631 mode |= inode->i_mode & ~S_IALLUGO; 633 mode |= inode->i_mode & ~S_IALLUGO;
632 inode->i_mode = mode; 634 inode->i_mode = mode;
633 635
634 i_size_write(inode, stat->st_size); 636 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
637 v9fs_i_size_write(inode, stat->st_size);
635 inode->i_blocks = stat->st_blocks; 638 inode->i_blocks = stat->st_blocks;
636 } else { 639 } else {
637 if (stat->st_result_mask & P9_STATS_ATIME) { 640 if (stat->st_result_mask & P9_STATS_ATIME) {
@@ -661,8 +664,9 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
661 } 664 }
662 if (stat->st_result_mask & P9_STATS_RDEV) 665 if (stat->st_result_mask & P9_STATS_RDEV)
663 inode->i_rdev = new_decode_dev(stat->st_rdev); 666 inode->i_rdev = new_decode_dev(stat->st_rdev);
664 if (stat->st_result_mask & P9_STATS_SIZE) 667 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) &&
665 i_size_write(inode, stat->st_size); 668 stat->st_result_mask & P9_STATS_SIZE)
669 v9fs_i_size_write(inode, stat->st_size);
666 if (stat->st_result_mask & P9_STATS_BLOCKS) 670 if (stat->st_result_mask & P9_STATS_BLOCKS)
667 inode->i_blocks = stat->st_blocks; 671 inode->i_blocks = stat->st_blocks;
668 } 672 }
@@ -928,9 +932,9 @@ v9fs_vfs_get_link_dotl(struct dentry *dentry,
928 932
929int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) 933int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
930{ 934{
931 loff_t i_size;
932 struct p9_stat_dotl *st; 935 struct p9_stat_dotl *st;
933 struct v9fs_session_info *v9ses; 936 struct v9fs_session_info *v9ses;
937 unsigned int flags;
934 938
935 v9ses = v9fs_inode2v9ses(inode); 939 v9ses = v9fs_inode2v9ses(inode);
936 st = p9_client_getattr_dotl(fid, P9_STATS_ALL); 940 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
@@ -942,16 +946,13 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
942 if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT)) 946 if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT))
943 goto out; 947 goto out;
944 948
945 spin_lock(&inode->i_lock);
946 /* 949 /*
947 * We don't want to refresh inode->i_size, 950 * We don't want to refresh inode->i_size,
948 * because we may have cached data 951 * because we may have cached data
949 */ 952 */
950 i_size = inode->i_size; 953 flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
951 v9fs_stat2inode_dotl(st, inode); 954 V9FS_STAT2INODE_KEEP_ISIZE : 0;
952 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) 955 v9fs_stat2inode_dotl(st, inode, flags);
953 inode->i_size = i_size;
954 spin_unlock(&inode->i_lock);
955out: 956out:
956 kfree(st); 957 kfree(st);
957 return 0; 958 return 0;
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 10d3bd3f534b..d13d35cf69c0 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -172,7 +172,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
172 goto release_sb; 172 goto release_sb;
173 } 173 }
174 d_inode(root)->i_ino = v9fs_qid2ino(&st->qid); 174 d_inode(root)->i_ino = v9fs_qid2ino(&st->qid);
175 v9fs_stat2inode_dotl(st, d_inode(root)); 175 v9fs_stat2inode_dotl(st, d_inode(root), 0);
176 kfree(st); 176 kfree(st);
177 } else { 177 } else {
178 struct p9_wstat *st = NULL; 178 struct p9_wstat *st = NULL;
@@ -183,7 +183,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
183 } 183 }
184 184
185 d_inode(root)->i_ino = v9fs_qid2ino(&st->qid); 185 d_inode(root)->i_ino = v9fs_qid2ino(&st->qid);
186 v9fs_stat2inode(st, d_inode(root), sb); 186 v9fs_stat2inode(st, d_inode(root), sb, 0);
187 187
188 p9stat_free(st); 188 p9stat_free(st);
189 kfree(st); 189 kfree(st);
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/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 1d49694e6ae3..c5880329ae37 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -6174,7 +6174,7 @@ static void btrfs_calculate_inode_block_rsv_size(struct btrfs_fs_info *fs_info,
6174 * 6174 *
6175 * This is overestimating in most cases. 6175 * This is overestimating in most cases.
6176 */ 6176 */
6177 qgroup_rsv_size = outstanding_extents * fs_info->nodesize; 6177 qgroup_rsv_size = (u64)outstanding_extents * fs_info->nodesize;
6178 6178
6179 spin_lock(&block_rsv->lock); 6179 spin_lock(&block_rsv->lock);
6180 block_rsv->size = reserve_size; 6180 block_rsv->size = reserve_size;
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index eb680b715dd6..e659d9d61107 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1922,8 +1922,8 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,
1922 int i; 1922 int i;
1923 1923
1924 /* Level sanity check */ 1924 /* Level sanity check */
1925 if (cur_level < 0 || cur_level >= BTRFS_MAX_LEVEL || 1925 if (cur_level < 0 || cur_level >= BTRFS_MAX_LEVEL - 1 ||
1926 root_level < 0 || root_level >= BTRFS_MAX_LEVEL || 1926 root_level < 0 || root_level >= BTRFS_MAX_LEVEL - 1 ||
1927 root_level < cur_level) { 1927 root_level < cur_level) {
1928 btrfs_err_rl(fs_info, 1928 btrfs_err_rl(fs_info,
1929 "%s: bad levels, cur_level=%d root_level=%d", 1929 "%s: bad levels, cur_level=%d root_level=%d",
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 1869ba8e5981..67a6f7d47402 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -2430,8 +2430,9 @@ static noinline void finish_parity_scrub(struct btrfs_raid_bio *rbio,
2430 bitmap_clear(rbio->dbitmap, pagenr, 1); 2430 bitmap_clear(rbio->dbitmap, pagenr, 1);
2431 kunmap(p); 2431 kunmap(p);
2432 2432
2433 for (stripe = 0; stripe < rbio->real_stripes; stripe++) 2433 for (stripe = 0; stripe < nr_data; stripe++)
2434 kunmap(page_in_rbio(rbio, stripe, pagenr, 0)); 2434 kunmap(page_in_rbio(rbio, stripe, pagenr, 0));
2435 kunmap(p_page);
2435 } 2436 }
2436 2437
2437 __free_page(p_page); 2438 __free_page(p_page);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index acdad6d658f5..e4e665f422fc 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1886,8 +1886,10 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
1886 } 1886 }
1887} 1887}
1888 1888
1889static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info) 1889static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans)
1890{ 1890{
1891 struct btrfs_fs_info *fs_info = trans->fs_info;
1892
1891 /* 1893 /*
1892 * We use writeback_inodes_sb here because if we used 1894 * We use writeback_inodes_sb here because if we used
1893 * btrfs_start_delalloc_roots we would deadlock with fs freeze. 1895 * btrfs_start_delalloc_roots we would deadlock with fs freeze.
@@ -1897,15 +1899,50 @@ static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
1897 * from already being in a transaction and our join_transaction doesn't 1899 * from already being in a transaction and our join_transaction doesn't
1898 * have to re-take the fs freeze lock. 1900 * have to re-take the fs freeze lock.
1899 */ 1901 */
1900 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) 1902 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
1901 writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC); 1903 writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
1904 } else {
1905 struct btrfs_pending_snapshot *pending;
1906 struct list_head *head = &trans->transaction->pending_snapshots;
1907
1908 /*
1909 * Flush dellaloc for any root that is going to be snapshotted.
1910 * This is done to avoid a corrupted version of files, in the
1911 * snapshots, that had both buffered and direct IO writes (even
1912 * if they were done sequentially) due to an unordered update of
1913 * the inode's size on disk.
1914 */
1915 list_for_each_entry(pending, head, list) {
1916 int ret;
1917
1918 ret = btrfs_start_delalloc_snapshot(pending->root);
1919 if (ret)
1920 return ret;
1921 }
1922 }
1902 return 0; 1923 return 0;
1903} 1924}
1904 1925
1905static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info) 1926static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans)
1906{ 1927{
1907 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) 1928 struct btrfs_fs_info *fs_info = trans->fs_info;
1929
1930 if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
1908 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); 1931 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
1932 } else {
1933 struct btrfs_pending_snapshot *pending;
1934 struct list_head *head = &trans->transaction->pending_snapshots;
1935
1936 /*
1937 * Wait for any dellaloc that we started previously for the roots
1938 * that are going to be snapshotted. This is to avoid a corrupted
1939 * version of files in the snapshots that had both buffered and
1940 * direct IO writes (even if they were done sequentially).
1941 */
1942 list_for_each_entry(pending, head, list)
1943 btrfs_wait_ordered_extents(pending->root,
1944 U64_MAX, 0, U64_MAX);
1945 }
1909} 1946}
1910 1947
1911int btrfs_commit_transaction(struct btrfs_trans_handle *trans) 1948int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
@@ -2023,7 +2060,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
2023 2060
2024 extwriter_counter_dec(cur_trans, trans->type); 2061 extwriter_counter_dec(cur_trans, trans->type);
2025 2062
2026 ret = btrfs_start_delalloc_flush(fs_info); 2063 ret = btrfs_start_delalloc_flush(trans);
2027 if (ret) 2064 if (ret)
2028 goto cleanup_transaction; 2065 goto cleanup_transaction;
2029 2066
@@ -2039,7 +2076,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
2039 if (ret) 2076 if (ret)
2040 goto cleanup_transaction; 2077 goto cleanup_transaction;
2041 2078
2042 btrfs_wait_delalloc_flush(fs_info); 2079 btrfs_wait_delalloc_flush(trans);
2043 2080
2044 btrfs_scrub_pause(fs_info); 2081 btrfs_scrub_pause(fs_info);
2045 /* 2082 /*
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index f06454a55e00..561884f60d35 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -3578,9 +3578,16 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
3578 } 3578 }
3579 btrfs_release_path(path); 3579 btrfs_release_path(path);
3580 3580
3581 /* find the first key from this transaction again */ 3581 /*
3582 * Find the first key from this transaction again. See the note for
3583 * log_new_dir_dentries, if we're logging a directory recursively we
3584 * won't be holding its i_mutex, which means we can modify the directory
3585 * while we're logging it. If we remove an entry between our first
3586 * search and this search we'll not find the key again and can just
3587 * bail.
3588 */
3582 ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0); 3589 ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0);
3583 if (WARN_ON(ret != 0)) 3590 if (ret != 0)
3584 goto done; 3591 goto done;
3585 3592
3586 /* 3593 /*
@@ -4544,6 +4551,19 @@ static int logged_inode_size(struct btrfs_root *log, struct btrfs_inode *inode,
4544 item = btrfs_item_ptr(path->nodes[0], path->slots[0], 4551 item = btrfs_item_ptr(path->nodes[0], path->slots[0],
4545 struct btrfs_inode_item); 4552 struct btrfs_inode_item);
4546 *size_ret = btrfs_inode_size(path->nodes[0], item); 4553 *size_ret = btrfs_inode_size(path->nodes[0], item);
4554 /*
4555 * If the in-memory inode's i_size is smaller then the inode
4556 * size stored in the btree, return the inode's i_size, so
4557 * that we get a correct inode size after replaying the log
4558 * when before a power failure we had a shrinking truncate
4559 * followed by addition of a new name (rename / new hard link).
4560 * Otherwise return the inode size from the btree, to avoid
4561 * data loss when replaying a log due to previously doing a
4562 * write that expands the inode's size and logging a new name
4563 * immediately after.
4564 */
4565 if (*size_ret > inode->vfs_inode.i_size)
4566 *size_ret = inode->vfs_inode.i_size;
4547 } 4567 }
4548 4568
4549 btrfs_release_path(path); 4569 btrfs_release_path(path);
@@ -4705,15 +4725,8 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans,
4705 struct btrfs_file_extent_item); 4725 struct btrfs_file_extent_item);
4706 4726
4707 if (btrfs_file_extent_type(leaf, extent) == 4727 if (btrfs_file_extent_type(leaf, extent) ==
4708 BTRFS_FILE_EXTENT_INLINE) { 4728 BTRFS_FILE_EXTENT_INLINE)
4709 len = btrfs_file_extent_ram_bytes(leaf, extent);
4710 ASSERT(len == i_size ||
4711 (len == fs_info->sectorsize &&
4712 btrfs_file_extent_compression(leaf, extent) !=
4713 BTRFS_COMPRESS_NONE) ||
4714 (len < i_size && i_size < fs_info->sectorsize));
4715 return 0; 4729 return 0;
4716 }
4717 4730
4718 len = btrfs_file_extent_num_bytes(leaf, extent); 4731 len = btrfs_file_extent_num_bytes(leaf, extent);
4719 /* Last extent goes beyond i_size, no need to log a hole. */ 4732 /* Last extent goes beyond i_size, no need to log a hole. */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9024eee889b9..db934ceae9c1 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6407,7 +6407,7 @@ static void btrfs_end_bio(struct bio *bio)
6407 if (bio_op(bio) == REQ_OP_WRITE) 6407 if (bio_op(bio) == REQ_OP_WRITE)
6408 btrfs_dev_stat_inc_and_print(dev, 6408 btrfs_dev_stat_inc_and_print(dev,
6409 BTRFS_DEV_STAT_WRITE_ERRS); 6409 BTRFS_DEV_STAT_WRITE_ERRS);
6410 else 6410 else if (!(bio->bi_opf & REQ_RAHEAD))
6411 btrfs_dev_stat_inc_and_print(dev, 6411 btrfs_dev_stat_inc_and_print(dev,
6412 BTRFS_DEV_STAT_READ_ERRS); 6412 BTRFS_DEV_STAT_READ_ERRS);
6413 if (bio->bi_opf & REQ_PREFLUSH) 6413 if (bio->bi_opf & REQ_PREFLUSH)
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index e92a2fee3c57..13c1288b04a7 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -115,7 +115,12 @@ static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
115 seq_puts(m, " type: CDROM "); 115 seq_puts(m, " type: CDROM ");
116 else 116 else
117 seq_printf(m, " type: %d ", dev_type); 117 seq_printf(m, " type: %d ", dev_type);
118 if (tcon->seal) 118
119 seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
120
121 if ((tcon->seal) ||
122 (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
123 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
119 seq_printf(m, " Encrypted"); 124 seq_printf(m, " Encrypted");
120 if (tcon->nocase) 125 if (tcon->nocase)
121 seq_printf(m, " nocase"); 126 seq_printf(m, " nocase");
@@ -371,6 +376,10 @@ skip_rdma:
371 atomic_read(&server->in_send), 376 atomic_read(&server->in_send),
372 atomic_read(&server->num_waiters)); 377 atomic_read(&server->num_waiters));
373#endif 378#endif
379 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
380 seq_puts(m, " encrypted");
381 if (ses->sign)
382 seq_puts(m, " signed");
374 383
375 seq_puts(m, "\n\tShares:"); 384 seq_puts(m, "\n\tShares:");
376 j = 0; 385 j = 0;
diff --git a/fs/cifs/cifs_ioctl.h b/fs/cifs/cifs_ioctl.h
index d8bce2f862de..086ddc5108af 100644
--- a/fs/cifs/cifs_ioctl.h
+++ b/fs/cifs/cifs_ioctl.h
@@ -43,6 +43,9 @@ struct smb_snapshot_array {
43 /* snapshots[]; */ 43 /* snapshots[]; */
44} __packed; 44} __packed;
45 45
46/* query_info flags */
47#define PASSTHRU_QUERY_INFO 0x00000000
48#define PASSTHRU_FSCTL 0x00000001
46struct smb_query_info { 49struct smb_query_info {
47 __u32 info_type; 50 __u32 info_type;
48 __u32 file_info_class; 51 __u32 file_info_class;
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/cifsglob.h b/fs/cifs/cifsglob.h
index f293e052e351..38feae812b47 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -479,6 +479,14 @@ struct smb_version_operations {
479 struct cifs_tcon *tcon, 479 struct cifs_tcon *tcon,
480 __le16 *path, int is_dir, 480 __le16 *path, int is_dir,
481 unsigned long p); 481 unsigned long p);
482 /* make unix special files (block, char, fifo, socket) */
483 int (*make_node)(unsigned int xid,
484 struct inode *inode,
485 struct dentry *dentry,
486 struct cifs_tcon *tcon,
487 char *full_path,
488 umode_t mode,
489 dev_t device_number);
482}; 490};
483 491
484struct smb_version_values { 492struct smb_version_values {
@@ -735,13 +743,13 @@ in_flight(struct TCP_Server_Info *server)
735} 743}
736 744
737static inline bool 745static inline bool
738has_credits(struct TCP_Server_Info *server, int *credits) 746has_credits(struct TCP_Server_Info *server, int *credits, int num_credits)
739{ 747{
740 int num; 748 int num;
741 spin_lock(&server->req_lock); 749 spin_lock(&server->req_lock);
742 num = *credits; 750 num = *credits;
743 spin_unlock(&server->req_lock); 751 spin_unlock(&server->req_lock);
744 return num > 0; 752 return num >= num_credits;
745} 753}
746 754
747static inline void 755static inline void
@@ -962,11 +970,14 @@ cap_unix(struct cifs_ses *ses)
962 970
963struct cached_fid { 971struct cached_fid {
964 bool is_valid:1; /* Do we have a useable root fid */ 972 bool is_valid:1; /* Do we have a useable root fid */
973 bool file_all_info_is_valid:1;
974
965 struct kref refcount; 975 struct kref refcount;
966 struct cifs_fid *fid; 976 struct cifs_fid *fid;
967 struct mutex fid_mutex; 977 struct mutex fid_mutex;
968 struct cifs_tcon *tcon; 978 struct cifs_tcon *tcon;
969 struct work_struct lease_break; 979 struct work_struct lease_break;
980 struct smb2_file_all_info file_all_info;
970}; 981};
971 982
972/* 983/*
@@ -1735,6 +1746,7 @@ require use of the stronger protocol */
1735 * GlobalMid_Lock protects: 1746 * GlobalMid_Lock protects:
1736 * list operations on pending_mid_q and oplockQ 1747 * list operations on pending_mid_q and oplockQ
1737 * updates to XID counters, multiplex id and SMB sequence numbers 1748 * updates to XID counters, multiplex id and SMB sequence numbers
1749 * list operations on global DnotifyReqList
1738 * tcp_ses_lock protects: 1750 * tcp_ses_lock protects:
1739 * list operations on tcp and SMB session lists 1751 * list operations on tcp and SMB session lists
1740 * tcon->open_file_lock protects the list of open files hanging off the tcon 1752 * tcon->open_file_lock protects the list of open files hanging off the tcon
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index b95db2b593cb..a8e9738db691 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1191,10 +1191,6 @@ next_pdu:
1191 continue; 1191 continue;
1192 } 1192 }
1193 1193
1194 if (server->large_buf)
1195 buf = server->bigbuf;
1196
1197
1198 server->lstrp = jiffies; 1194 server->lstrp = jiffies;
1199 1195
1200 for (i = 0; i < num_mids; i++) { 1196 for (i = 0; i < num_mids; i++) {
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 907e85d65bb4..f26a48dd2e39 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -621,20 +621,10 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
621{ 621{
622 int rc = -EPERM; 622 int rc = -EPERM;
623 unsigned int xid; 623 unsigned int xid;
624 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
625 struct cifs_sb_info *cifs_sb; 624 struct cifs_sb_info *cifs_sb;
626 struct tcon_link *tlink; 625 struct tcon_link *tlink;
627 struct cifs_tcon *tcon; 626 struct cifs_tcon *tcon;
628 struct cifs_io_parms io_parms;
629 char *full_path = NULL; 627 char *full_path = NULL;
630 struct inode *newinode = NULL;
631 __u32 oplock = 0;
632 struct cifs_fid fid;
633 struct cifs_open_parms oparms;
634 FILE_ALL_INFO *buf = NULL;
635 unsigned int bytes_written;
636 struct win_dev *pdev;
637 struct kvec iov[2];
638 628
639 if (!old_valid_dev(device_number)) 629 if (!old_valid_dev(device_number))
640 return -EINVAL; 630 return -EINVAL;
@@ -654,103 +644,12 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
654 goto mknod_out; 644 goto mknod_out;
655 } 645 }
656 646
657 if (tcon->unix_ext) { 647 rc = tcon->ses->server->ops->make_node(xid, inode, direntry, tcon,
658 struct cifs_unix_set_info_args args = { 648 full_path, mode,
659 .mode = mode & ~current_umask(), 649 device_number);
660 .ctime = NO_CHANGE_64,
661 .atime = NO_CHANGE_64,
662 .mtime = NO_CHANGE_64,
663 .device = device_number,
664 };
665 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
666 args.uid = current_fsuid();
667 args.gid = current_fsgid();
668 } else {
669 args.uid = INVALID_UID; /* no change */
670 args.gid = INVALID_GID; /* no change */
671 }
672 rc = CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
673 cifs_sb->local_nls,
674 cifs_remap(cifs_sb));
675 if (rc)
676 goto mknod_out;
677
678 rc = cifs_get_inode_info_unix(&newinode, full_path,
679 inode->i_sb, xid);
680
681 if (rc == 0)
682 d_instantiate(direntry, newinode);
683 goto mknod_out;
684 }
685
686 if (!S_ISCHR(mode) && !S_ISBLK(mode))
687 goto mknod_out;
688
689 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
690 goto mknod_out;
691
692
693 cifs_dbg(FYI, "sfu compat create special file\n");
694
695 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
696 if (buf == NULL) {
697 rc = -ENOMEM;
698 goto mknod_out;
699 }
700
701 if (backup_cred(cifs_sb))
702 create_options |= CREATE_OPEN_BACKUP_INTENT;
703
704 oparms.tcon = tcon;
705 oparms.cifs_sb = cifs_sb;
706 oparms.desired_access = GENERIC_WRITE;
707 oparms.create_options = create_options;
708 oparms.disposition = FILE_CREATE;
709 oparms.path = full_path;
710 oparms.fid = &fid;
711 oparms.reconnect = false;
712
713 if (tcon->ses->server->oplocks)
714 oplock = REQ_OPLOCK;
715 else
716 oplock = 0;
717 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
718 if (rc)
719 goto mknod_out;
720
721 /*
722 * BB Do not bother to decode buf since no local inode yet to put
723 * timestamps in, but we can reuse it safely.
724 */
725
726 pdev = (struct win_dev *)buf;
727 io_parms.pid = current->tgid;
728 io_parms.tcon = tcon;
729 io_parms.offset = 0;
730 io_parms.length = sizeof(struct win_dev);
731 iov[1].iov_base = buf;
732 iov[1].iov_len = sizeof(struct win_dev);
733 if (S_ISCHR(mode)) {
734 memcpy(pdev->type, "IntxCHR", 8);
735 pdev->major = cpu_to_le64(MAJOR(device_number));
736 pdev->minor = cpu_to_le64(MINOR(device_number));
737 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
738 &bytes_written, iov, 1);
739 } else if (S_ISBLK(mode)) {
740 memcpy(pdev->type, "IntxBLK", 8);
741 pdev->major = cpu_to_le64(MAJOR(device_number));
742 pdev->minor = cpu_to_le64(MINOR(device_number));
743 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
744 &bytes_written, iov, 1);
745 }
746 tcon->ses->server->ops->close(xid, tcon, &fid);
747 d_drop(direntry);
748
749 /* FIXME: add code here to set EAs */
750 650
751mknod_out: 651mknod_out:
752 kfree(full_path); 652 kfree(full_path);
753 kfree(buf);
754 free_xid(xid); 653 free_xid(xid);
755 cifs_put_tlink(tlink); 654 cifs_put_tlink(tlink);
756 return rc; 655 return rc;
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 4c144c1f50eb..89006e044973 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -1645,8 +1645,20 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
1645 rc = server->ops->mand_unlock_range(cfile, flock, xid); 1645 rc = server->ops->mand_unlock_range(cfile, flock, xid);
1646 1646
1647out: 1647out:
1648 if (flock->fl_flags & FL_POSIX && !rc) 1648 if (flock->fl_flags & FL_POSIX) {
1649 /*
1650 * If this is a request to remove all locks because we
1651 * are closing the file, it doesn't matter if the
1652 * unlocking failed as both cifs.ko and the SMB server
1653 * remove the lock on file close
1654 */
1655 if (rc) {
1656 cifs_dbg(VFS, "%s failed rc=%d\n", __func__, rc);
1657 if (!(flock->fl_flags & FL_CLOSE))
1658 return rc;
1659 }
1649 rc = locks_lock_file_wait(file, flock); 1660 rc = locks_lock_file_wait(file, flock);
1661 }
1650 return rc; 1662 return rc;
1651} 1663}
1652 1664
@@ -2620,43 +2632,56 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
2620 struct TCP_Server_Info *server = 2632 struct TCP_Server_Info *server =
2621 tlink_tcon(wdata->cfile->tlink)->ses->server; 2633 tlink_tcon(wdata->cfile->tlink)->ses->server;
2622 2634
2623 /*
2624 * Wait for credits to resend this wdata.
2625 * Note: we are attempting to resend the whole wdata not in segments
2626 */
2627 do { 2635 do {
2628 rc = server->ops->wait_mtu_credits(server, wdata->bytes, &wsize, 2636 if (wdata->cfile->invalidHandle) {
2629 &credits); 2637 rc = cifs_reopen_file(wdata->cfile, false);
2638 if (rc == -EAGAIN)
2639 continue;
2640 else if (rc)
2641 break;
2642 }
2630 2643
2631 if (rc)
2632 goto out;
2633 2644
2634 if (wsize < wdata->bytes) { 2645 /*
2635 add_credits_and_wake_if(server, &credits, 0); 2646 * Wait for credits to resend this wdata.
2636 msleep(1000); 2647 * Note: we are attempting to resend the whole wdata not in
2637 } 2648 * segments
2638 } 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;
2639 2662
2640 wdata->credits = credits; 2663 rc = adjust_credits(server, &wdata->credits, wdata->bytes);
2641 rc = -EAGAIN; 2664
2642 while (rc == -EAGAIN) { 2665 if (!rc) {
2643 rc = 0; 2666 if (wdata->cfile->invalidHandle)
2644 if (wdata->cfile->invalidHandle) 2667 rc = -EAGAIN;
2645 rc = cifs_reopen_file(wdata->cfile, false); 2668 else
2646 if (!rc) 2669 rc = server->ops->async_writev(wdata,
2647 rc = server->ops->async_writev(wdata,
2648 cifs_uncached_writedata_release); 2670 cifs_uncached_writedata_release);
2649 } 2671 }
2650 2672
2651 if (!rc) { 2673 /* If the write was successfully sent, we are done */
2652 list_add_tail(&wdata->list, wdata_list); 2674 if (!rc) {
2653 return 0; 2675 list_add_tail(&wdata->list, wdata_list);
2654 } 2676 return 0;
2677 }
2655 2678
2656 add_credits_and_wake_if(server, &wdata->credits, 0); 2679 /* Roll back credits and retry if needed */
2657out: 2680 add_credits_and_wake_if(server, &wdata->credits, 0);
2658 kref_put(&wdata->refcount, cifs_uncached_writedata_release); 2681 } while (rc == -EAGAIN);
2659 2682
2683fail:
2684 kref_put(&wdata->refcount, cifs_uncached_writedata_release);
2660 return rc; 2685 return rc;
2661} 2686}
2662 2687
@@ -2884,12 +2909,12 @@ restart_loop:
2884 wdata->bytes, &tmp_from, 2909 wdata->bytes, &tmp_from,
2885 ctx->cfile, cifs_sb, &tmp_list, 2910 ctx->cfile, cifs_sb, &tmp_list,
2886 ctx); 2911 ctx);
2912
2913 kref_put(&wdata->refcount,
2914 cifs_uncached_writedata_release);
2887 } 2915 }
2888 2916
2889 list_splice(&tmp_list, &ctx->list); 2917 list_splice(&tmp_list, &ctx->list);
2890
2891 kref_put(&wdata->refcount,
2892 cifs_uncached_writedata_release);
2893 goto restart_loop; 2918 goto restart_loop;
2894 } 2919 }
2895 } 2920 }
@@ -3336,44 +3361,55 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata,
3336 struct TCP_Server_Info *server = 3361 struct TCP_Server_Info *server =
3337 tlink_tcon(rdata->cfile->tlink)->ses->server; 3362 tlink_tcon(rdata->cfile->tlink)->ses->server;
3338 3363
3339 /*
3340 * Wait for credits to resend this rdata.
3341 * Note: we are attempting to resend the whole rdata not in segments
3342 */
3343 do { 3364 do {
3344 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,
3345 &rsize, &credits); 3380 &rsize, &credits);
3346 3381
3347 if (rc) 3382 if (rc)
3348 goto out; 3383 goto fail;
3349 3384
3350 if (rsize < rdata->bytes) { 3385 if (rsize < rdata->bytes) {
3351 add_credits_and_wake_if(server, &credits, 0); 3386 add_credits_and_wake_if(server, &credits, 0);
3352 msleep(1000); 3387 msleep(1000);
3353 } 3388 }
3354 } while (rsize < rdata->bytes); 3389 } while (rsize < rdata->bytes);
3390 rdata->credits = credits;
3355 3391
3356 rdata->credits = credits; 3392 rc = adjust_credits(server, &rdata->credits, rdata->bytes);
3357 rc = -EAGAIN; 3393 if (!rc) {
3358 while (rc == -EAGAIN) { 3394 if (rdata->cfile->invalidHandle)
3359 rc = 0; 3395 rc = -EAGAIN;
3360 if (rdata->cfile->invalidHandle) 3396 else
3361 rc = cifs_reopen_file(rdata->cfile, true); 3397 rc = server->ops->async_readv(rdata);
3362 if (!rc) 3398 }
3363 rc = server->ops->async_readv(rdata);
3364 }
3365 3399
3366 if (!rc) { 3400 /* If the read was successfully sent, we are done */
3367 /* Add to aio pending list */ 3401 if (!rc) {
3368 list_add_tail(&rdata->list, rdata_list); 3402 /* Add to aio pending list */
3369 return 0; 3403 list_add_tail(&rdata->list, rdata_list);
3370 } 3404 return 0;
3405 }
3371 3406
3372 add_credits_and_wake_if(server, &rdata->credits, 0); 3407 /* Roll back credits and retry if needed */
3373out: 3408 add_credits_and_wake_if(server, &rdata->credits, 0);
3374 kref_put(&rdata->refcount, 3409 } while (rc == -EAGAIN);
3375 cifs_uncached_readdata_release);
3376 3410
3411fail:
3412 kref_put(&rdata->refcount, cifs_uncached_readdata_release);
3377 return rc; 3413 return rc;
3378} 3414}
3379 3415
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index f0ce27c3c6e4..c711f1f39bf2 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -1027,6 +1027,131 @@ cifs_can_echo(struct TCP_Server_Info *server)
1027 return false; 1027 return false;
1028} 1028}
1029 1029
1030static int
1031cifs_make_node(unsigned int xid, struct inode *inode,
1032 struct dentry *dentry, struct cifs_tcon *tcon,
1033 char *full_path, umode_t mode, dev_t dev)
1034{
1035 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1036 struct inode *newinode = NULL;
1037 int rc = -EPERM;
1038 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
1039 FILE_ALL_INFO *buf = NULL;
1040 struct cifs_io_parms io_parms;
1041 __u32 oplock = 0;
1042 struct cifs_fid fid;
1043 struct cifs_open_parms oparms;
1044 unsigned int bytes_written;
1045 struct win_dev *pdev;
1046 struct kvec iov[2];
1047
1048 if (tcon->unix_ext) {
1049 /*
1050 * SMB1 Unix Extensions: requires server support but
1051 * works with all special files
1052 */
1053 struct cifs_unix_set_info_args args = {
1054 .mode = mode & ~current_umask(),
1055 .ctime = NO_CHANGE_64,
1056 .atime = NO_CHANGE_64,
1057 .mtime = NO_CHANGE_64,
1058 .device = dev,
1059 };
1060 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
1061 args.uid = current_fsuid();
1062 args.gid = current_fsgid();
1063 } else {
1064 args.uid = INVALID_UID; /* no change */
1065 args.gid = INVALID_GID; /* no change */
1066 }
1067 rc = CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
1068 cifs_sb->local_nls,
1069 cifs_remap(cifs_sb));
1070 if (rc)
1071 goto out;
1072
1073 rc = cifs_get_inode_info_unix(&newinode, full_path,
1074 inode->i_sb, xid);
1075
1076 if (rc == 0)
1077 d_instantiate(dentry, newinode);
1078 goto out;
1079 }
1080
1081 /*
1082 * SMB1 SFU emulation: should work with all servers, but only
1083 * support block and char device (no socket & fifo)
1084 */
1085 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
1086 goto out;
1087
1088 if (!S_ISCHR(mode) && !S_ISBLK(mode))
1089 goto out;
1090
1091 cifs_dbg(FYI, "sfu compat create special file\n");
1092
1093 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
1094 if (buf == NULL) {
1095 rc = -ENOMEM;
1096 goto out;
1097 }
1098
1099 if (backup_cred(cifs_sb))
1100 create_options |= CREATE_OPEN_BACKUP_INTENT;
1101
1102 oparms.tcon = tcon;
1103 oparms.cifs_sb = cifs_sb;
1104 oparms.desired_access = GENERIC_WRITE;
1105 oparms.create_options = create_options;
1106 oparms.disposition = FILE_CREATE;
1107 oparms.path = full_path;
1108 oparms.fid = &fid;
1109 oparms.reconnect = false;
1110
1111 if (tcon->ses->server->oplocks)
1112 oplock = REQ_OPLOCK;
1113 else
1114 oplock = 0;
1115 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
1116 if (rc)
1117 goto out;
1118
1119 /*
1120 * BB Do not bother to decode buf since no local inode yet to put
1121 * timestamps in, but we can reuse it safely.
1122 */
1123
1124 pdev = (struct win_dev *)buf;
1125 io_parms.pid = current->tgid;
1126 io_parms.tcon = tcon;
1127 io_parms.offset = 0;
1128 io_parms.length = sizeof(struct win_dev);
1129 iov[1].iov_base = buf;
1130 iov[1].iov_len = sizeof(struct win_dev);
1131 if (S_ISCHR(mode)) {
1132 memcpy(pdev->type, "IntxCHR", 8);
1133 pdev->major = cpu_to_le64(MAJOR(dev));
1134 pdev->minor = cpu_to_le64(MINOR(dev));
1135 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
1136 &bytes_written, iov, 1);
1137 } else if (S_ISBLK(mode)) {
1138 memcpy(pdev->type, "IntxBLK", 8);
1139 pdev->major = cpu_to_le64(MAJOR(dev));
1140 pdev->minor = cpu_to_le64(MINOR(dev));
1141 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
1142 &bytes_written, iov, 1);
1143 }
1144 tcon->ses->server->ops->close(xid, tcon, &fid);
1145 d_drop(dentry);
1146
1147 /* FIXME: add code here to set EAs */
1148out:
1149 kfree(buf);
1150 return rc;
1151}
1152
1153
1154
1030struct smb_version_operations smb1_operations = { 1155struct smb_version_operations smb1_operations = {
1031 .send_cancel = send_nt_cancel, 1156 .send_cancel = send_nt_cancel,
1032 .compare_fids = cifs_compare_fids, 1157 .compare_fids = cifs_compare_fids,
@@ -1110,6 +1235,7 @@ struct smb_version_operations smb1_operations = {
1110 .get_acl_by_fid = get_cifs_acl_by_fid, 1235 .get_acl_by_fid = get_cifs_acl_by_fid,
1111 .set_acl = set_cifs_acl, 1236 .set_acl = set_cifs_acl,
1112#endif /* CIFS_ACL */ 1237#endif /* CIFS_ACL */
1238 .make_node = cifs_make_node,
1113}; 1239};
1114 1240
1115struct smb_version_values smb1_values = { 1241struct smb_version_values smb1_values = {
diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
index 01a76bccdb8d..278405d26c47 100644
--- a/fs/cifs/smb2inode.c
+++ b/fs/cifs/smb2inode.c
@@ -37,6 +37,16 @@
37#include "smb2pdu.h" 37#include "smb2pdu.h"
38#include "smb2proto.h" 38#include "smb2proto.h"
39 39
40static void
41free_set_inf_compound(struct smb_rqst *rqst)
42{
43 if (rqst[1].rq_iov)
44 SMB2_set_info_free(&rqst[1]);
45 if (rqst[2].rq_iov)
46 SMB2_close_free(&rqst[2]);
47}
48
49
40static int 50static int
41smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, 51smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
42 struct cifs_sb_info *cifs_sb, const char *full_path, 52 struct cifs_sb_info *cifs_sb, const char *full_path,
@@ -112,14 +122,18 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
112 PATH_MAX * 2, 0, NULL); 122 PATH_MAX * 2, 0, NULL);
113 smb2_set_next_command(tcon, &rqst[num_rqst]); 123 smb2_set_next_command(tcon, &rqst[num_rqst]);
114 smb2_set_related(&rqst[num_rqst++]); 124 smb2_set_related(&rqst[num_rqst++]);
125 trace_smb3_query_info_compound_enter(xid, ses->Suid, tcon->tid,
126 full_path);
115 break; 127 break;
116 case SMB2_OP_DELETE: 128 case SMB2_OP_DELETE:
129 trace_smb3_delete_enter(xid, ses->Suid, tcon->tid, full_path);
117 break; 130 break;
118 case SMB2_OP_MKDIR: 131 case SMB2_OP_MKDIR:
119 /* 132 /*
120 * Directories are created through parameters in the 133 * Directories are created through parameters in the
121 * SMB2_open() call. 134 * SMB2_open() call.
122 */ 135 */
136 trace_smb3_mkdir_enter(xid, ses->Suid, tcon->tid, full_path);
123 break; 137 break;
124 case SMB2_OP_RMDIR: 138 case SMB2_OP_RMDIR:
125 memset(&si_iov, 0, sizeof(si_iov)); 139 memset(&si_iov, 0, sizeof(si_iov));
@@ -135,6 +149,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
135 SMB2_O_INFO_FILE, 0, data, size); 149 SMB2_O_INFO_FILE, 0, data, size);
136 smb2_set_next_command(tcon, &rqst[num_rqst]); 150 smb2_set_next_command(tcon, &rqst[num_rqst]);
137 smb2_set_related(&rqst[num_rqst++]); 151 smb2_set_related(&rqst[num_rqst++]);
152 trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path);
138 break; 153 break;
139 case SMB2_OP_SET_EOF: 154 case SMB2_OP_SET_EOF:
140 memset(&si_iov, 0, sizeof(si_iov)); 155 memset(&si_iov, 0, sizeof(si_iov));
@@ -150,6 +165,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
150 SMB2_O_INFO_FILE, 0, data, size); 165 SMB2_O_INFO_FILE, 0, data, size);
151 smb2_set_next_command(tcon, &rqst[num_rqst]); 166 smb2_set_next_command(tcon, &rqst[num_rqst]);
152 smb2_set_related(&rqst[num_rqst++]); 167 smb2_set_related(&rqst[num_rqst++]);
168 trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path);
153 break; 169 break;
154 case SMB2_OP_SET_INFO: 170 case SMB2_OP_SET_INFO:
155 memset(&si_iov, 0, sizeof(si_iov)); 171 memset(&si_iov, 0, sizeof(si_iov));
@@ -166,6 +182,8 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
166 SMB2_O_INFO_FILE, 0, data, size); 182 SMB2_O_INFO_FILE, 0, data, size);
167 smb2_set_next_command(tcon, &rqst[num_rqst]); 183 smb2_set_next_command(tcon, &rqst[num_rqst]);
168 smb2_set_related(&rqst[num_rqst++]); 184 smb2_set_related(&rqst[num_rqst++]);
185 trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid,
186 full_path);
169 break; 187 break;
170 case SMB2_OP_RENAME: 188 case SMB2_OP_RENAME:
171 memset(&si_iov, 0, sizeof(si_iov)); 189 memset(&si_iov, 0, sizeof(si_iov));
@@ -190,6 +208,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
190 SMB2_O_INFO_FILE, 0, data, size); 208 SMB2_O_INFO_FILE, 0, data, size);
191 smb2_set_next_command(tcon, &rqst[num_rqst]); 209 smb2_set_next_command(tcon, &rqst[num_rqst]);
192 smb2_set_related(&rqst[num_rqst++]); 210 smb2_set_related(&rqst[num_rqst++]);
211 trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path);
193 break; 212 break;
194 case SMB2_OP_HARDLINK: 213 case SMB2_OP_HARDLINK:
195 memset(&si_iov, 0, sizeof(si_iov)); 214 memset(&si_iov, 0, sizeof(si_iov));
@@ -214,6 +233,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
214 SMB2_O_INFO_FILE, 0, data, size); 233 SMB2_O_INFO_FILE, 0, data, size);
215 smb2_set_next_command(tcon, &rqst[num_rqst]); 234 smb2_set_next_command(tcon, &rqst[num_rqst]);
216 smb2_set_related(&rqst[num_rqst++]); 235 smb2_set_related(&rqst[num_rqst++]);
236 trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path);
217 break; 237 break;
218 default: 238 default:
219 cifs_dbg(VFS, "Invalid command\n"); 239 cifs_dbg(VFS, "Invalid command\n");
@@ -252,21 +272,65 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
252 SMB2_query_info_free(&rqst[1]); 272 SMB2_query_info_free(&rqst[1]);
253 if (rqst[2].rq_iov) 273 if (rqst[2].rq_iov)
254 SMB2_close_free(&rqst[2]); 274 SMB2_close_free(&rqst[2]);
275 if (rc)
276 trace_smb3_query_info_compound_err(xid, ses->Suid,
277 tcon->tid, rc);
278 else
279 trace_smb3_query_info_compound_done(xid, ses->Suid,
280 tcon->tid);
255 break; 281 break;
256 case SMB2_OP_DELETE: 282 case SMB2_OP_DELETE:
283 if (rc)
284 trace_smb3_delete_err(xid, ses->Suid, tcon->tid, rc);
285 else
286 trace_smb3_delete_done(xid, ses->Suid, tcon->tid);
287 if (rqst[1].rq_iov)
288 SMB2_close_free(&rqst[1]);
289 break;
257 case SMB2_OP_MKDIR: 290 case SMB2_OP_MKDIR:
291 if (rc)
292 trace_smb3_mkdir_err(xid, ses->Suid, tcon->tid, rc);
293 else
294 trace_smb3_mkdir_done(xid, ses->Suid, tcon->tid);
258 if (rqst[1].rq_iov) 295 if (rqst[1].rq_iov)
259 SMB2_close_free(&rqst[1]); 296 SMB2_close_free(&rqst[1]);
260 break; 297 break;
261 case SMB2_OP_HARDLINK: 298 case SMB2_OP_HARDLINK:
299 if (rc)
300 trace_smb3_hardlink_err(xid, ses->Suid, tcon->tid, rc);
301 else
302 trace_smb3_hardlink_done(xid, ses->Suid, tcon->tid);
303 free_set_inf_compound(rqst);
304 break;
262 case SMB2_OP_RENAME: 305 case SMB2_OP_RENAME:
306 if (rc)
307 trace_smb3_rename_err(xid, ses->Suid, tcon->tid, rc);
308 else
309 trace_smb3_rename_done(xid, ses->Suid, tcon->tid);
310 free_set_inf_compound(rqst);
311 break;
263 case SMB2_OP_RMDIR: 312 case SMB2_OP_RMDIR:
313 if (rc)
314 trace_smb3_rmdir_err(xid, ses->Suid, tcon->tid, rc);
315 else
316 trace_smb3_rmdir_done(xid, ses->Suid, tcon->tid);
317 free_set_inf_compound(rqst);
318 break;
264 case SMB2_OP_SET_EOF: 319 case SMB2_OP_SET_EOF:
320 if (rc)
321 trace_smb3_set_eof_err(xid, ses->Suid, tcon->tid, rc);
322 else
323 trace_smb3_set_eof_done(xid, ses->Suid, tcon->tid);
324 free_set_inf_compound(rqst);
325 break;
265 case SMB2_OP_SET_INFO: 326 case SMB2_OP_SET_INFO:
266 if (rqst[1].rq_iov) 327 if (rc)
267 SMB2_set_info_free(&rqst[1]); 328 trace_smb3_set_info_compound_err(xid, ses->Suid,
268 if (rqst[2].rq_iov) 329 tcon->tid, rc);
269 SMB2_close_free(&rqst[2]); 330 else
331 trace_smb3_set_info_compound_done(xid, ses->Suid,
332 tcon->tid);
333 free_set_inf_compound(rqst);
270 break; 334 break;
271 } 335 }
272 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); 336 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
@@ -309,12 +373,17 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
309 rc = open_shroot(xid, tcon, &fid); 373 rc = open_shroot(xid, tcon, &fid);
310 if (rc) 374 if (rc)
311 goto out; 375 goto out;
312 rc = SMB2_query_info(xid, tcon, fid.persistent_fid, 376
313 fid.volatile_fid, smb2_data); 377 if (tcon->crfid.file_all_info_is_valid) {
378 move_smb2_info_to_cifs(data,
379 &tcon->crfid.file_all_info);
380 } else {
381 rc = SMB2_query_info(xid, tcon, fid.persistent_fid,
382 fid.volatile_fid, smb2_data);
383 if (!rc)
384 move_smb2_info_to_cifs(data, smb2_data);
385 }
314 close_shroot(&tcon->crfid); 386 close_shroot(&tcon->crfid);
315 if (rc)
316 goto out;
317 move_smb2_info_to_cifs(data, smb2_data);
318 goto out; 387 goto out;
319 } 388 }
320 389
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/smb2ops.c b/fs/cifs/smb2ops.c
index 085e91436da7..1022a3771e14 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -185,7 +185,7 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
185 spin_unlock(&server->req_lock); 185 spin_unlock(&server->req_lock);
186 cifs_num_waiters_inc(server); 186 cifs_num_waiters_inc(server);
187 rc = wait_event_killable(server->request_q, 187 rc = wait_event_killable(server->request_q,
188 has_credits(server, &server->credits)); 188 has_credits(server, &server->credits, 1));
189 cifs_num_waiters_dec(server); 189 cifs_num_waiters_dec(server);
190 if (rc) 190 if (rc)
191 return rc; 191 return rc;
@@ -619,6 +619,7 @@ smb2_close_cached_fid(struct kref *ref)
619 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid, 619 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
620 cfid->fid->volatile_fid); 620 cfid->fid->volatile_fid);
621 cfid->is_valid = false; 621 cfid->is_valid = false;
622 cfid->file_all_info_is_valid = false;
622 } 623 }
623} 624}
624 625
@@ -643,9 +644,18 @@ smb2_cached_lease_break(struct work_struct *work)
643 */ 644 */
644int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid) 645int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
645{ 646{
646 struct cifs_open_parms oparams; 647 struct cifs_ses *ses = tcon->ses;
647 int rc; 648 struct TCP_Server_Info *server = ses->server;
648 __le16 srch_path = 0; /* Null - since an open of top of share */ 649 struct cifs_open_parms oparms;
650 struct smb2_create_rsp *o_rsp = NULL;
651 struct smb2_query_info_rsp *qi_rsp = NULL;
652 int resp_buftype[2];
653 struct smb_rqst rqst[2];
654 struct kvec rsp_iov[2];
655 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
656 struct kvec qi_iov[1];
657 int rc, flags = 0;
658 __le16 utf16_path = 0; /* Null - since an open of top of share */
649 u8 oplock = SMB2_OPLOCK_LEVEL_II; 659 u8 oplock = SMB2_OPLOCK_LEVEL_II;
650 660
651 mutex_lock(&tcon->crfid.fid_mutex); 661 mutex_lock(&tcon->crfid.fid_mutex);
@@ -657,22 +667,89 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
657 return 0; 667 return 0;
658 } 668 }
659 669
660 oparams.tcon = tcon; 670 if (smb3_encryption_required(tcon))
661 oparams.create_options = 0; 671 flags |= CIFS_TRANSFORM_REQ;
662 oparams.desired_access = FILE_READ_ATTRIBUTES; 672
663 oparams.disposition = FILE_OPEN; 673 memset(rqst, 0, sizeof(rqst));
664 oparams.fid = pfid; 674 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
665 oparams.reconnect = false; 675 memset(rsp_iov, 0, sizeof(rsp_iov));
666 676
667 rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL); 677 /* Open */
668 if (rc == 0) { 678 memset(&open_iov, 0, sizeof(open_iov));
669 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid)); 679 rqst[0].rq_iov = open_iov;
670 tcon->crfid.tcon = tcon; 680 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
671 tcon->crfid.is_valid = true; 681
672 kref_init(&tcon->crfid.refcount); 682 oparms.tcon = tcon;
673 kref_get(&tcon->crfid.refcount); 683 oparms.create_options = 0;
674 } 684 oparms.desired_access = FILE_READ_ATTRIBUTES;
685 oparms.disposition = FILE_OPEN;
686 oparms.fid = pfid;
687 oparms.reconnect = false;
688
689 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &utf16_path);
690 if (rc)
691 goto oshr_exit;
692 smb2_set_next_command(tcon, &rqst[0]);
693
694 memset(&qi_iov, 0, sizeof(qi_iov));
695 rqst[1].rq_iov = qi_iov;
696 rqst[1].rq_nvec = 1;
697
698 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
699 COMPOUND_FID, FILE_ALL_INFORMATION,
700 SMB2_O_INFO_FILE, 0,
701 sizeof(struct smb2_file_all_info) +
702 PATH_MAX * 2, 0, NULL);
703 if (rc)
704 goto oshr_exit;
705
706 smb2_set_related(&rqst[1]);
707
708 rc = compound_send_recv(xid, ses, flags, 2, rqst,
709 resp_buftype, rsp_iov);
710 if (rc)
711 goto oshr_exit;
712
713 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
714 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
715 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
716#ifdef CONFIG_CIFS_DEBUG2
717 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
718#endif /* CIFS_DEBUG2 */
719
720 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
721 oplock = smb2_parse_lease_state(server, o_rsp,
722 &oparms.fid->epoch,
723 oparms.fid->lease_key);
724 else
725 goto oshr_exit;
726
727
728 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
729 tcon->crfid.tcon = tcon;
730 tcon->crfid.is_valid = true;
731 kref_init(&tcon->crfid.refcount);
732 kref_get(&tcon->crfid.refcount);
733
734
735 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
736 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
737 goto oshr_exit;
738 rc = smb2_validate_and_copy_iov(
739 le16_to_cpu(qi_rsp->OutputBufferOffset),
740 sizeof(struct smb2_file_all_info),
741 &rsp_iov[1], sizeof(struct smb2_file_all_info),
742 (char *)&tcon->crfid.file_all_info);
743 if (rc)
744 goto oshr_exit;
745 tcon->crfid.file_all_info_is_valid = 1;
746
747 oshr_exit:
675 mutex_unlock(&tcon->crfid.fid_mutex); 748 mutex_unlock(&tcon->crfid.fid_mutex);
749 SMB2_open_free(&rqst[0]);
750 SMB2_query_info_free(&rqst[1]);
751 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
752 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
676 return rc; 753 return rc;
677} 754}
678 755
@@ -1253,7 +1330,8 @@ smb2_ioctl_query_info(const unsigned int xid,
1253 struct smb_query_info __user *pqi; 1330 struct smb_query_info __user *pqi;
1254 int rc = 0; 1331 int rc = 0;
1255 int flags = 0; 1332 int flags = 0;
1256 struct smb2_query_info_rsp *rsp = NULL; 1333 struct smb2_query_info_rsp *qi_rsp = NULL;
1334 struct smb2_ioctl_rsp *io_rsp = NULL;
1257 void *buffer = NULL; 1335 void *buffer = NULL;
1258 struct smb_rqst rqst[3]; 1336 struct smb_rqst rqst[3];
1259 int resp_buftype[3]; 1337 int resp_buftype[3];
@@ -1263,6 +1341,7 @@ smb2_ioctl_query_info(const unsigned int xid,
1263 u8 oplock = SMB2_OPLOCK_LEVEL_NONE; 1341 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1264 struct cifs_fid fid; 1342 struct cifs_fid fid;
1265 struct kvec qi_iov[1]; 1343 struct kvec qi_iov[1];
1344 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1266 struct kvec close_iov[1]; 1345 struct kvec close_iov[1];
1267 1346
1268 memset(rqst, 0, sizeof(rqst)); 1347 memset(rqst, 0, sizeof(rqst));
@@ -1313,15 +1392,35 @@ smb2_ioctl_query_info(const unsigned int xid,
1313 smb2_set_next_command(tcon, &rqst[0]); 1392 smb2_set_next_command(tcon, &rqst[0]);
1314 1393
1315 /* Query */ 1394 /* Query */
1316 memset(&qi_iov, 0, sizeof(qi_iov)); 1395 if (qi.flags & PASSTHRU_FSCTL) {
1317 rqst[1].rq_iov = qi_iov; 1396 /* Can eventually relax perm check since server enforces too */
1318 rqst[1].rq_nvec = 1; 1397 if (!capable(CAP_SYS_ADMIN))
1319 1398 rc = -EPERM;
1320 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID, 1399 else {
1321 qi.file_info_class, qi.info_type, 1400 memset(&io_iov, 0, sizeof(io_iov));
1322 qi.additional_information, 1401 rqst[1].rq_iov = io_iov;
1402 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1403
1404 rc = SMB2_ioctl_init(tcon, &rqst[1],
1405 COMPOUND_FID, COMPOUND_FID,
1406 qi.info_type, true, NULL,
1407 0);
1408 }
1409 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1410 memset(&qi_iov, 0, sizeof(qi_iov));
1411 rqst[1].rq_iov = qi_iov;
1412 rqst[1].rq_nvec = 1;
1413
1414 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
1415 COMPOUND_FID, qi.file_info_class,
1416 qi.info_type, qi.additional_information,
1323 qi.input_buffer_length, 1417 qi.input_buffer_length,
1324 qi.output_buffer_length, buffer); 1418 qi.output_buffer_length, buffer);
1419 } else { /* unknown flags */
1420 cifs_dbg(VFS, "invalid passthru query flags: 0x%x\n", qi.flags);
1421 rc = -EINVAL;
1422 }
1423
1325 if (rc) 1424 if (rc)
1326 goto iqinf_exit; 1425 goto iqinf_exit;
1327 smb2_set_next_command(tcon, &rqst[1]); 1426 smb2_set_next_command(tcon, &rqst[1]);
@@ -1341,24 +1440,44 @@ smb2_ioctl_query_info(const unsigned int xid,
1341 resp_buftype, rsp_iov); 1440 resp_buftype, rsp_iov);
1342 if (rc) 1441 if (rc)
1343 goto iqinf_exit; 1442 goto iqinf_exit;
1344 pqi = (struct smb_query_info __user *)arg; 1443 if (qi.flags & PASSTHRU_FSCTL) {
1345 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; 1444 pqi = (struct smb_query_info __user *)arg;
1346 if (le32_to_cpu(rsp->OutputBufferLength) < qi.input_buffer_length) 1445 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1347 qi.input_buffer_length = le32_to_cpu(rsp->OutputBufferLength); 1446 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1348 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length, 1447 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1349 sizeof(qi.input_buffer_length))) { 1448 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1350 rc = -EFAULT; 1449 sizeof(qi.input_buffer_length))) {
1351 goto iqinf_exit; 1450 rc = -EFAULT;
1352 } 1451 goto iqinf_exit;
1353 if (copy_to_user(pqi + 1, rsp->Buffer, qi.input_buffer_length)) { 1452 }
1354 rc = -EFAULT; 1453 if (copy_to_user(pqi + 1, &io_rsp[1], qi.input_buffer_length)) {
1355 goto iqinf_exit; 1454 rc = -EFAULT;
1455 goto iqinf_exit;
1456 }
1457 } else {
1458 pqi = (struct smb_query_info __user *)arg;
1459 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1460 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1461 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1462 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1463 sizeof(qi.input_buffer_length))) {
1464 rc = -EFAULT;
1465 goto iqinf_exit;
1466 }
1467 if (copy_to_user(pqi + 1, qi_rsp->Buffer, qi.input_buffer_length)) {
1468 rc = -EFAULT;
1469 goto iqinf_exit;
1470 }
1356 } 1471 }
1357 1472
1358 iqinf_exit: 1473 iqinf_exit:
1359 kfree(buffer); 1474 kfree(buffer);
1360 SMB2_open_free(&rqst[0]); 1475 SMB2_open_free(&rqst[0]);
1361 SMB2_query_info_free(&rqst[1]); 1476 if (qi.flags & PASSTHRU_FSCTL)
1477 SMB2_ioctl_free(&rqst[1]);
1478 else
1479 SMB2_query_info_free(&rqst[1]);
1480
1362 SMB2_close_free(&rqst[2]); 1481 SMB2_close_free(&rqst[2]);
1363 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); 1482 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1364 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); 1483 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
@@ -2472,22 +2591,38 @@ get_smb2_acl(struct cifs_sb_info *cifs_sb,
2472static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, 2591static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2473 loff_t offset, loff_t len, bool keep_size) 2592 loff_t offset, loff_t len, bool keep_size)
2474{ 2593{
2594 struct cifs_ses *ses = tcon->ses;
2475 struct inode *inode; 2595 struct inode *inode;
2476 struct cifsInodeInfo *cifsi; 2596 struct cifsInodeInfo *cifsi;
2477 struct cifsFileInfo *cfile = file->private_data; 2597 struct cifsFileInfo *cfile = file->private_data;
2478 struct file_zero_data_information fsctl_buf; 2598 struct file_zero_data_information fsctl_buf;
2599 struct smb_rqst rqst[2];
2600 int resp_buftype[2];
2601 struct kvec rsp_iov[2];
2602 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2603 struct kvec si_iov[1];
2604 unsigned int size[1];
2605 void *data[1];
2479 long rc; 2606 long rc;
2480 unsigned int xid; 2607 unsigned int xid;
2608 int num = 0, flags = 0;
2609 __le64 eof;
2481 2610
2482 xid = get_xid(); 2611 xid = get_xid();
2483 2612
2484 inode = d_inode(cfile->dentry); 2613 inode = d_inode(cfile->dentry);
2485 cifsi = CIFS_I(inode); 2614 cifsi = CIFS_I(inode);
2486 2615
2616 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2617 ses->Suid, offset, len);
2618
2619
2487 /* if file not oplocked can't be sure whether asking to extend size */ 2620 /* if file not oplocked can't be sure whether asking to extend size */
2488 if (!CIFS_CACHE_READ(cifsi)) 2621 if (!CIFS_CACHE_READ(cifsi))
2489 if (keep_size == false) { 2622 if (keep_size == false) {
2490 rc = -EOPNOTSUPP; 2623 rc = -EOPNOTSUPP;
2624 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
2625 tcon->tid, ses->Suid, offset, len, rc);
2491 free_xid(xid); 2626 free_xid(xid);
2492 return rc; 2627 return rc;
2493 } 2628 }
@@ -2498,33 +2633,73 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2498 */ 2633 */
2499 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) { 2634 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
2500 rc = -EOPNOTSUPP; 2635 rc = -EOPNOTSUPP;
2636 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
2637 ses->Suid, offset, len, rc);
2501 free_xid(xid); 2638 free_xid(xid);
2502 return rc; 2639 return rc;
2503 } 2640 }
2504 2641
2505 /*
2506 * need to make sure we are not asked to extend the file since the SMB3
2507 * fsctl does not change the file size. In the future we could change
2508 * this to zero the first part of the range then set the file size
2509 * which for a non sparse file would zero the newly extended range
2510 */
2511 if (keep_size == false)
2512 if (i_size_read(inode) < offset + len) {
2513 rc = -EOPNOTSUPP;
2514 free_xid(xid);
2515 return rc;
2516 }
2517
2518 cifs_dbg(FYI, "offset %lld len %lld", offset, len); 2642 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2519 2643
2520 fsctl_buf.FileOffset = cpu_to_le64(offset); 2644 fsctl_buf.FileOffset = cpu_to_le64(offset);
2521 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); 2645 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2522 2646
2523 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, 2647 if (smb3_encryption_required(tcon))
2524 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, 2648 flags |= CIFS_TRANSFORM_REQ;
2525 true /* is_fctl */, (char *)&fsctl_buf, 2649
2526 sizeof(struct file_zero_data_information), NULL, NULL); 2650 memset(rqst, 0, sizeof(rqst));
2651 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2652 memset(rsp_iov, 0, sizeof(rsp_iov));
2653
2654
2655 memset(&io_iov, 0, sizeof(io_iov));
2656 rqst[num].rq_iov = io_iov;
2657 rqst[num].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2658 rc = SMB2_ioctl_init(tcon, &rqst[num++], cfile->fid.persistent_fid,
2659 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2660 true /* is_fctl */, (char *)&fsctl_buf,
2661 sizeof(struct file_zero_data_information));
2662 if (rc)
2663 goto zero_range_exit;
2664
2665 /*
2666 * do we also need to change the size of the file?
2667 */
2668 if (keep_size == false && i_size_read(inode) < offset + len) {
2669 smb2_set_next_command(tcon, &rqst[0]);
2670
2671 memset(&si_iov, 0, sizeof(si_iov));
2672 rqst[num].rq_iov = si_iov;
2673 rqst[num].rq_nvec = 1;
2674
2675 eof = cpu_to_le64(offset + len);
2676 size[0] = 8; /* sizeof __le64 */
2677 data[0] = &eof;
2678
2679 rc = SMB2_set_info_init(tcon, &rqst[num++],
2680 cfile->fid.persistent_fid,
2681 cfile->fid.persistent_fid,
2682 current->tgid,
2683 FILE_END_OF_FILE_INFORMATION,
2684 SMB2_O_INFO_FILE, 0, data, size);
2685 smb2_set_related(&rqst[1]);
2686 }
2687
2688 rc = compound_send_recv(xid, ses, flags, num, rqst,
2689 resp_buftype, rsp_iov);
2690
2691 zero_range_exit:
2692 SMB2_ioctl_free(&rqst[0]);
2693 SMB2_set_info_free(&rqst[1]);
2694 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2695 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2527 free_xid(xid); 2696 free_xid(xid);
2697 if (rc)
2698 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
2699 ses->Suid, offset, len, rc);
2700 else
2701 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
2702 ses->Suid, offset, len);
2528 return rc; 2703 return rc;
2529} 2704}
2530 2705
@@ -2573,15 +2748,20 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2573 struct cifsFileInfo *cfile = file->private_data; 2748 struct cifsFileInfo *cfile = file->private_data;
2574 long rc = -EOPNOTSUPP; 2749 long rc = -EOPNOTSUPP;
2575 unsigned int xid; 2750 unsigned int xid;
2751 __le64 eof;
2576 2752
2577 xid = get_xid(); 2753 xid = get_xid();
2578 2754
2579 inode = d_inode(cfile->dentry); 2755 inode = d_inode(cfile->dentry);
2580 cifsi = CIFS_I(inode); 2756 cifsi = CIFS_I(inode);
2581 2757
2758 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2759 tcon->ses->Suid, off, len);
2582 /* if file not oplocked can't be sure whether asking to extend size */ 2760 /* if file not oplocked can't be sure whether asking to extend size */
2583 if (!CIFS_CACHE_READ(cifsi)) 2761 if (!CIFS_CACHE_READ(cifsi))
2584 if (keep_size == false) { 2762 if (keep_size == false) {
2763 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
2764 tcon->tid, tcon->ses->Suid, off, len, rc);
2585 free_xid(xid); 2765 free_xid(xid);
2586 return rc; 2766 return rc;
2587 } 2767 }
@@ -2601,6 +2781,12 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2601 /* BB: in future add else clause to extend file */ 2781 /* BB: in future add else clause to extend file */
2602 else 2782 else
2603 rc = -EOPNOTSUPP; 2783 rc = -EOPNOTSUPP;
2784 if (rc)
2785 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
2786 tcon->tid, tcon->ses->Suid, off, len, rc);
2787 else
2788 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid,
2789 tcon->tid, tcon->ses->Suid, off, len);
2604 free_xid(xid); 2790 free_xid(xid);
2605 return rc; 2791 return rc;
2606 } 2792 }
@@ -2616,14 +2802,31 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2616 */ 2802 */
2617 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) { 2803 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
2618 rc = -EOPNOTSUPP; 2804 rc = -EOPNOTSUPP;
2805 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
2806 tcon->tid, tcon->ses->Suid, off, len, rc);
2619 free_xid(xid); 2807 free_xid(xid);
2620 return rc; 2808 return rc;
2621 } 2809 }
2622 2810
2623 rc = smb2_set_sparse(xid, tcon, cfile, inode, false); 2811 smb2_set_sparse(xid, tcon, cfile, inode, false);
2812 rc = 0;
2813 } else {
2814 smb2_set_sparse(xid, tcon, cfile, inode, false);
2815 rc = 0;
2816 if (i_size_read(inode) < off + len) {
2817 eof = cpu_to_le64(off + len);
2818 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
2819 cfile->fid.volatile_fid, cfile->pid,
2820 &eof);
2821 }
2624 } 2822 }
2625 /* BB: else ... in future add code to extend file and set sparse */
2626 2823
2824 if (rc)
2825 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
2826 tcon->ses->Suid, off, len, rc);
2827 else
2828 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
2829 tcon->ses->Suid, off, len);
2627 2830
2628 free_xid(xid); 2831 free_xid(xid);
2629 return rc; 2832 return rc;
@@ -3604,6 +3807,104 @@ smb2_next_header(char *buf)
3604 return le32_to_cpu(hdr->NextCommand); 3807 return le32_to_cpu(hdr->NextCommand);
3605} 3808}
3606 3809
3810static int
3811smb2_make_node(unsigned int xid, struct inode *inode,
3812 struct dentry *dentry, struct cifs_tcon *tcon,
3813 char *full_path, umode_t mode, dev_t dev)
3814{
3815 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3816 int rc = -EPERM;
3817 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
3818 FILE_ALL_INFO *buf = NULL;
3819 struct cifs_io_parms io_parms;
3820 __u32 oplock = 0;
3821 struct cifs_fid fid;
3822 struct cifs_open_parms oparms;
3823 unsigned int bytes_written;
3824 struct win_dev *pdev;
3825 struct kvec iov[2];
3826
3827 /*
3828 * Check if mounted with mount parm 'sfu' mount parm.
3829 * SFU emulation should work with all servers, but only
3830 * supports block and char device (no socket & fifo),
3831 * and was used by default in earlier versions of Windows
3832 */
3833 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
3834 goto out;
3835
3836 /*
3837 * TODO: Add ability to create instead via reparse point. Windows (e.g.
3838 * their current NFS server) uses this approach to expose special files
3839 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
3840 */
3841
3842 if (!S_ISCHR(mode) && !S_ISBLK(mode))
3843 goto out;
3844
3845 cifs_dbg(FYI, "sfu compat create special file\n");
3846
3847 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
3848 if (buf == NULL) {
3849 rc = -ENOMEM;
3850 goto out;
3851 }
3852
3853 if (backup_cred(cifs_sb))
3854 create_options |= CREATE_OPEN_BACKUP_INTENT;
3855
3856 oparms.tcon = tcon;
3857 oparms.cifs_sb = cifs_sb;
3858 oparms.desired_access = GENERIC_WRITE;
3859 oparms.create_options = create_options;
3860 oparms.disposition = FILE_CREATE;
3861 oparms.path = full_path;
3862 oparms.fid = &fid;
3863 oparms.reconnect = false;
3864
3865 if (tcon->ses->server->oplocks)
3866 oplock = REQ_OPLOCK;
3867 else
3868 oplock = 0;
3869 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
3870 if (rc)
3871 goto out;
3872
3873 /*
3874 * BB Do not bother to decode buf since no local inode yet to put
3875 * timestamps in, but we can reuse it safely.
3876 */
3877
3878 pdev = (struct win_dev *)buf;
3879 io_parms.pid = current->tgid;
3880 io_parms.tcon = tcon;
3881 io_parms.offset = 0;
3882 io_parms.length = sizeof(struct win_dev);
3883 iov[1].iov_base = buf;
3884 iov[1].iov_len = sizeof(struct win_dev);
3885 if (S_ISCHR(mode)) {
3886 memcpy(pdev->type, "IntxCHR", 8);
3887 pdev->major = cpu_to_le64(MAJOR(dev));
3888 pdev->minor = cpu_to_le64(MINOR(dev));
3889 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
3890 &bytes_written, iov, 1);
3891 } else if (S_ISBLK(mode)) {
3892 memcpy(pdev->type, "IntxBLK", 8);
3893 pdev->major = cpu_to_le64(MAJOR(dev));
3894 pdev->minor = cpu_to_le64(MINOR(dev));
3895 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
3896 &bytes_written, iov, 1);
3897 }
3898 tcon->ses->server->ops->close(xid, tcon, &fid);
3899 d_drop(dentry);
3900
3901 /* FIXME: add code here to set EAs */
3902out:
3903 kfree(buf);
3904 return rc;
3905}
3906
3907
3607struct smb_version_operations smb20_operations = { 3908struct smb_version_operations smb20_operations = {
3608 .compare_fids = smb2_compare_fids, 3909 .compare_fids = smb2_compare_fids,
3609 .setup_request = smb2_setup_request, 3910 .setup_request = smb2_setup_request,
@@ -3698,6 +3999,7 @@ struct smb_version_operations smb20_operations = {
3698#endif /* CIFS_ACL */ 3999#endif /* CIFS_ACL */
3699 .next_header = smb2_next_header, 4000 .next_header = smb2_next_header,
3700 .ioctl_query_info = smb2_ioctl_query_info, 4001 .ioctl_query_info = smb2_ioctl_query_info,
4002 .make_node = smb2_make_node,
3701}; 4003};
3702 4004
3703struct smb_version_operations smb21_operations = { 4005struct smb_version_operations smb21_operations = {
@@ -3796,6 +4098,7 @@ struct smb_version_operations smb21_operations = {
3796#endif /* CIFS_ACL */ 4098#endif /* CIFS_ACL */
3797 .next_header = smb2_next_header, 4099 .next_header = smb2_next_header,
3798 .ioctl_query_info = smb2_ioctl_query_info, 4100 .ioctl_query_info = smb2_ioctl_query_info,
4101 .make_node = smb2_make_node,
3799}; 4102};
3800 4103
3801struct smb_version_operations smb30_operations = { 4104struct smb_version_operations smb30_operations = {
@@ -3903,6 +4206,7 @@ struct smb_version_operations smb30_operations = {
3903#endif /* CIFS_ACL */ 4206#endif /* CIFS_ACL */
3904 .next_header = smb2_next_header, 4207 .next_header = smb2_next_header,
3905 .ioctl_query_info = smb2_ioctl_query_info, 4208 .ioctl_query_info = smb2_ioctl_query_info,
4209 .make_node = smb2_make_node,
3906}; 4210};
3907 4211
3908struct smb_version_operations smb311_operations = { 4212struct smb_version_operations smb311_operations = {
@@ -4011,6 +4315,7 @@ struct smb_version_operations smb311_operations = {
4011#endif /* CIFS_ACL */ 4315#endif /* CIFS_ACL */
4012 .next_header = smb2_next_header, 4316 .next_header = smb2_next_header,
4013 .ioctl_query_info = smb2_ioctl_query_info, 4317 .ioctl_query_info = smb2_ioctl_query_info,
4318 .make_node = smb2_make_node,
4014}; 4319};
4015 4320
4016struct smb_version_values smb20_values = { 4321struct smb_version_values smb20_values = {
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 60fbe306f604..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));
@@ -1797,9 +1804,10 @@ create_reconnect_durable_buf(struct cifs_fid *fid)
1797 return buf; 1804 return buf;
1798} 1805}
1799 1806
1800static __u8 1807__u8
1801parse_lease_state(struct TCP_Server_Info *server, struct smb2_create_rsp *rsp, 1808smb2_parse_lease_state(struct TCP_Server_Info *server,
1802 unsigned int *epoch, char *lease_key) 1809 struct smb2_create_rsp *rsp,
1810 unsigned int *epoch, char *lease_key)
1803{ 1811{
1804 char *data_offset; 1812 char *data_offset;
1805 struct create_context *cc; 1813 struct create_context *cc;
@@ -2456,8 +2464,9 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
2456 } 2464 }
2457 2465
2458 if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) 2466 if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
2459 *oplock = parse_lease_state(server, rsp, &oparms->fid->epoch, 2467 *oplock = smb2_parse_lease_state(server, rsp,
2460 oparms->fid->lease_key); 2468 &oparms->fid->epoch,
2469 oparms->fid->lease_key);
2461 else 2470 else
2462 *oplock = rsp->OplockLevel; 2471 *oplock = rsp->OplockLevel;
2463creat_exit: 2472creat_exit:
@@ -2466,65 +2475,46 @@ creat_exit:
2466 return rc; 2475 return rc;
2467} 2476}
2468 2477
2469/*
2470 * SMB2 IOCTL is used for both IOCTLs and FSCTLs
2471 */
2472int 2478int
2473SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, 2479SMB2_ioctl_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
2474 u64 volatile_fid, u32 opcode, bool is_fsctl, 2480 u64 persistent_fid, u64 volatile_fid, u32 opcode,
2475 char *in_data, u32 indatalen, 2481 bool is_fsctl, char *in_data, u32 indatalen)
2476 char **out_data, u32 *plen /* returned data len */)
2477{ 2482{
2478 struct smb_rqst rqst;
2479 struct smb2_ioctl_req *req; 2483 struct smb2_ioctl_req *req;
2480 struct smb2_ioctl_rsp *rsp; 2484 struct kvec *iov = rqst->rq_iov;
2481 struct cifs_ses *ses;
2482 struct kvec iov[2];
2483 struct kvec rsp_iov;
2484 int resp_buftype;
2485 int n_iov;
2486 int rc = 0;
2487 int flags = 0;
2488 unsigned int total_len; 2485 unsigned int total_len;
2489 2486 int rc;
2490 cifs_dbg(FYI, "SMB2 IOCTL\n");
2491
2492 if (out_data != NULL)
2493 *out_data = NULL;
2494
2495 /* zero out returned data len, in case of error */
2496 if (plen)
2497 *plen = 0;
2498
2499 if (tcon)
2500 ses = tcon->ses;
2501 else
2502 return -EIO;
2503
2504 if (!ses || !(ses->server))
2505 return -EIO;
2506 2487
2507 rc = smb2_plain_req_init(SMB2_IOCTL, tcon, (void **) &req, &total_len); 2488 rc = smb2_plain_req_init(SMB2_IOCTL, tcon, (void **) &req, &total_len);
2508 if (rc) 2489 if (rc)
2509 return rc; 2490 return rc;
2510 2491
2511 if (smb3_encryption_required(tcon))
2512 flags |= CIFS_TRANSFORM_REQ;
2513
2514 req->CtlCode = cpu_to_le32(opcode); 2492 req->CtlCode = cpu_to_le32(opcode);
2515 req->PersistentFileId = persistent_fid; 2493 req->PersistentFileId = persistent_fid;
2516 req->VolatileFileId = volatile_fid; 2494 req->VolatileFileId = volatile_fid;
2517 2495
2496 iov[0].iov_base = (char *)req;
2497 /*
2498 * If no input data, the size of ioctl struct in
2499 * protocol spec still includes a 1 byte data buffer,
2500 * but if input data passed to ioctl, we do not
2501 * want to double count this, so we do not send
2502 * the dummy one byte of data in iovec[0] if sending
2503 * input data (in iovec[1]).
2504 */
2518 if (indatalen) { 2505 if (indatalen) {
2519 req->InputCount = cpu_to_le32(indatalen); 2506 req->InputCount = cpu_to_le32(indatalen);
2520 /* do not set InputOffset if no input data */ 2507 /* do not set InputOffset if no input data */
2521 req->InputOffset = 2508 req->InputOffset =
2522 cpu_to_le32(offsetof(struct smb2_ioctl_req, Buffer)); 2509 cpu_to_le32(offsetof(struct smb2_ioctl_req, Buffer));
2510 rqst->rq_nvec = 2;
2511 iov[0].iov_len = total_len - 1;
2523 iov[1].iov_base = in_data; 2512 iov[1].iov_base = in_data;
2524 iov[1].iov_len = indatalen; 2513 iov[1].iov_len = indatalen;
2525 n_iov = 2; 2514 } else {
2526 } else 2515 rqst->rq_nvec = 1;
2527 n_iov = 1; 2516 iov[0].iov_len = total_len;
2517 }
2528 2518
2529 req->OutputOffset = 0; 2519 req->OutputOffset = 0;
2530 req->OutputCount = 0; /* MBZ */ 2520 req->OutputCount = 0; /* MBZ */
@@ -2546,33 +2536,70 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
2546 else 2536 else
2547 req->Flags = 0; 2537 req->Flags = 0;
2548 2538
2549 iov[0].iov_base = (char *)req;
2550
2551 /*
2552 * If no input data, the size of ioctl struct in
2553 * protocol spec still includes a 1 byte data buffer,
2554 * but if input data passed to ioctl, we do not
2555 * want to double count this, so we do not send
2556 * the dummy one byte of data in iovec[0] if sending
2557 * input data (in iovec[1]).
2558 */
2559
2560 if (indatalen) {
2561 iov[0].iov_len = total_len - 1;
2562 } else
2563 iov[0].iov_len = total_len;
2564
2565 /* validate negotiate request must be signed - see MS-SMB2 3.2.5.5 */ 2539 /* validate negotiate request must be signed - see MS-SMB2 3.2.5.5 */
2566 if (opcode == FSCTL_VALIDATE_NEGOTIATE_INFO) 2540 if (opcode == FSCTL_VALIDATE_NEGOTIATE_INFO)
2567 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED; 2541 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
2568 2542
2543 return 0;
2544}
2545
2546void
2547SMB2_ioctl_free(struct smb_rqst *rqst)
2548{
2549 if (rqst && rqst->rq_iov)
2550 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */
2551}
2552
2553/*
2554 * SMB2 IOCTL is used for both IOCTLs and FSCTLs
2555 */
2556int
2557SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
2558 u64 volatile_fid, u32 opcode, bool is_fsctl,
2559 char *in_data, u32 indatalen,
2560 char **out_data, u32 *plen /* returned data len */)
2561{
2562 struct smb_rqst rqst;
2563 struct smb2_ioctl_rsp *rsp = NULL;
2564 struct cifs_ses *ses;
2565 struct kvec iov[SMB2_IOCTL_IOV_SIZE];
2566 struct kvec rsp_iov = {NULL, 0};
2567 int resp_buftype = CIFS_NO_BUFFER;
2568 int rc = 0;
2569 int flags = 0;
2570
2571 cifs_dbg(FYI, "SMB2 IOCTL\n");
2572
2573 if (out_data != NULL)
2574 *out_data = NULL;
2575
2576 /* zero out returned data len, in case of error */
2577 if (plen)
2578 *plen = 0;
2579
2580 if (tcon)
2581 ses = tcon->ses;
2582 else
2583 return -EIO;
2584
2585 if (!ses || !(ses->server))
2586 return -EIO;
2587
2588 if (smb3_encryption_required(tcon))
2589 flags |= CIFS_TRANSFORM_REQ;
2590
2569 memset(&rqst, 0, sizeof(struct smb_rqst)); 2591 memset(&rqst, 0, sizeof(struct smb_rqst));
2592 memset(&iov, 0, sizeof(iov));
2570 rqst.rq_iov = iov; 2593 rqst.rq_iov = iov;
2571 rqst.rq_nvec = n_iov; 2594 rqst.rq_nvec = SMB2_IOCTL_IOV_SIZE;
2595
2596 rc = SMB2_ioctl_init(tcon, &rqst, persistent_fid, volatile_fid,
2597 opcode, is_fsctl, in_data, indatalen);
2598 if (rc)
2599 goto ioctl_exit;
2572 2600
2573 rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, 2601 rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags,
2574 &rsp_iov); 2602 &rsp_iov);
2575 cifs_small_buf_release(req);
2576 rsp = (struct smb2_ioctl_rsp *)rsp_iov.iov_base; 2603 rsp = (struct smb2_ioctl_rsp *)rsp_iov.iov_base;
2577 2604
2578 if (rc != 0) 2605 if (rc != 0)
@@ -2622,6 +2649,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
2622 } 2649 }
2623 2650
2624ioctl_exit: 2651ioctl_exit:
2652 SMB2_ioctl_free(&rqst);
2625 free_rsp_buf(resp_buftype, rsp); 2653 free_rsp_buf(resp_buftype, rsp);
2626 return rc; 2654 return rc;
2627} 2655}
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index 0bd4d4802701..ee8977688e21 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -959,6 +959,13 @@ struct duplicate_extents_to_file {
959 __le64 ByteCount; /* Bytes to be copied */ 959 __le64 ByteCount; /* Bytes to be copied */
960} __packed; 960} __packed;
961 961
962/*
963 * Maximum number of iovs we need for an ioctl request.
964 * [0] : struct smb2_ioctl_req
965 * [1] : in_data
966 */
967#define SMB2_IOCTL_IOV_SIZE 2
968
962struct smb2_ioctl_req { 969struct smb2_ioctl_req {
963 struct smb2_sync_hdr sync_hdr; 970 struct smb2_sync_hdr sync_hdr;
964 __le16 StructureSize; /* Must be 57 */ 971 __le16 StructureSize; /* Must be 57 */
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
index 87733b27a65f..3c32d0cfea69 100644
--- a/fs/cifs/smb2proto.h
+++ b/fs/cifs/smb2proto.h
@@ -144,6 +144,10 @@ extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon,
144 u64 persistent_fid, u64 volatile_fid, u32 opcode, 144 u64 persistent_fid, u64 volatile_fid, u32 opcode,
145 bool is_fsctl, char *in_data, u32 indatalen, 145 bool is_fsctl, char *in_data, u32 indatalen,
146 char **out_data, u32 *plen /* returned data len */); 146 char **out_data, u32 *plen /* returned data len */);
147extern int SMB2_ioctl_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
148 u64 persistent_fid, u64 volatile_fid, u32 opcode,
149 bool is_fsctl, char *in_data, u32 indatalen);
150extern void SMB2_ioctl_free(struct smb_rqst *rqst);
147extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, 151extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
148 u64 persistent_file_id, u64 volatile_file_id); 152 u64 persistent_file_id, u64 volatile_file_id);
149extern int SMB2_close_flags(const unsigned int xid, struct cifs_tcon *tcon, 153extern int SMB2_close_flags(const unsigned int xid, struct cifs_tcon *tcon,
@@ -223,6 +227,9 @@ extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);
223 227
224extern enum securityEnum smb2_select_sectype(struct TCP_Server_Info *, 228extern enum securityEnum smb2_select_sectype(struct TCP_Server_Info *,
225 enum securityEnum); 229 enum securityEnum);
230extern __u8 smb2_parse_lease_state(struct TCP_Server_Info *server,
231 struct smb2_create_rsp *rsp,
232 unsigned int *epoch, char *lease_key);
226extern int smb3_encryption_required(const struct cifs_tcon *tcon); 233extern int smb3_encryption_required(const struct cifs_tcon *tcon);
227extern int smb2_validate_iov(unsigned int offset, unsigned int buffer_length, 234extern int smb2_validate_iov(unsigned int offset, unsigned int buffer_length,
228 struct kvec *iov, unsigned int min_buf_size); 235 struct kvec *iov, unsigned int min_buf_size);
diff --git a/fs/cifs/smb2status.h b/fs/cifs/smb2status.h
index 3d5f62150de4..447c0c6e4c64 100644
--- a/fs/cifs/smb2status.h
+++ b/fs/cifs/smb2status.h
@@ -30,9 +30,9 @@
30 */ 30 */
31 31
32#define STATUS_SEVERITY_SUCCESS __constant_cpu_to_le32(0x0000) 32#define STATUS_SEVERITY_SUCCESS __constant_cpu_to_le32(0x0000)
33#define STATUS_SEVERITY_INFORMATIONAL __constanst_cpu_to_le32(0x0001) 33#define STATUS_SEVERITY_INFORMATIONAL cpu_to_le32(0x0001)
34#define STATUS_SEVERITY_WARNING __constanst_cpu_to_le32(0x0002) 34#define STATUS_SEVERITY_WARNING cpu_to_le32(0x0002)
35#define STATUS_SEVERITY_ERROR __constanst_cpu_to_le32(0x0003) 35#define STATUS_SEVERITY_ERROR cpu_to_le32(0x0003)
36 36
37struct ntstatus { 37struct ntstatus {
38 /* Facility is the high 12 bits of the following field */ 38 /* Facility is the high 12 bits of the following field */
diff --git a/fs/cifs/trace.h b/fs/cifs/trace.h
index d8b049afa606..99c4d799c24b 100644
--- a/fs/cifs/trace.h
+++ b/fs/cifs/trace.h
@@ -59,6 +59,8 @@ DEFINE_EVENT(smb3_rw_err_class, smb3_##name, \
59DEFINE_SMB3_RW_ERR_EVENT(write_err); 59DEFINE_SMB3_RW_ERR_EVENT(write_err);
60DEFINE_SMB3_RW_ERR_EVENT(read_err); 60DEFINE_SMB3_RW_ERR_EVENT(read_err);
61DEFINE_SMB3_RW_ERR_EVENT(query_dir_err); 61DEFINE_SMB3_RW_ERR_EVENT(query_dir_err);
62DEFINE_SMB3_RW_ERR_EVENT(zero_err);
63DEFINE_SMB3_RW_ERR_EVENT(falloc_err);
62 64
63 65
64/* For logging successful read or write */ 66/* For logging successful read or write */
@@ -104,9 +106,13 @@ DEFINE_EVENT(smb3_rw_done_class, smb3_##name, \
104DEFINE_SMB3_RW_DONE_EVENT(write_enter); 106DEFINE_SMB3_RW_DONE_EVENT(write_enter);
105DEFINE_SMB3_RW_DONE_EVENT(read_enter); 107DEFINE_SMB3_RW_DONE_EVENT(read_enter);
106DEFINE_SMB3_RW_DONE_EVENT(query_dir_enter); 108DEFINE_SMB3_RW_DONE_EVENT(query_dir_enter);
109DEFINE_SMB3_RW_DONE_EVENT(zero_enter);
110DEFINE_SMB3_RW_DONE_EVENT(falloc_enter);
107DEFINE_SMB3_RW_DONE_EVENT(write_done); 111DEFINE_SMB3_RW_DONE_EVENT(write_done);
108DEFINE_SMB3_RW_DONE_EVENT(read_done); 112DEFINE_SMB3_RW_DONE_EVENT(read_done);
109DEFINE_SMB3_RW_DONE_EVENT(query_dir_done); 113DEFINE_SMB3_RW_DONE_EVENT(query_dir_done);
114DEFINE_SMB3_RW_DONE_EVENT(zero_done);
115DEFINE_SMB3_RW_DONE_EVENT(falloc_done);
110 116
111/* 117/*
112 * For handle based calls other than read and write, and get/set info 118 * For handle based calls other than read and write, and get/set info
@@ -242,6 +248,123 @@ DEFINE_SMB3_INF_ERR_EVENT(query_info_err);
242DEFINE_SMB3_INF_ERR_EVENT(set_info_err); 248DEFINE_SMB3_INF_ERR_EVENT(set_info_err);
243DEFINE_SMB3_INF_ERR_EVENT(fsctl_err); 249DEFINE_SMB3_INF_ERR_EVENT(fsctl_err);
244 250
251DECLARE_EVENT_CLASS(smb3_inf_compound_enter_class,
252 TP_PROTO(unsigned int xid,
253 __u32 tid,
254 __u64 sesid,
255 const char *full_path),
256 TP_ARGS(xid, tid, sesid, full_path),
257 TP_STRUCT__entry(
258 __field(unsigned int, xid)
259 __field(__u32, tid)
260 __field(__u64, sesid)
261 __string(path, full_path)
262 ),
263 TP_fast_assign(
264 __entry->xid = xid;
265 __entry->tid = tid;
266 __entry->sesid = sesid;
267 __assign_str(path, full_path);
268 ),
269 TP_printk("xid=%u sid=0x%llx tid=0x%x path=%s",
270 __entry->xid, __entry->sesid, __entry->tid,
271 __get_str(path))
272)
273
274#define DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(name) \
275DEFINE_EVENT(smb3_inf_compound_enter_class, smb3_##name, \
276 TP_PROTO(unsigned int xid, \
277 __u32 tid, \
278 __u64 sesid, \
279 const char *full_path), \
280 TP_ARGS(xid, tid, sesid, full_path))
281
282DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(query_info_compound_enter);
283DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(hardlink_enter);
284DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(rename_enter);
285DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(rmdir_enter);
286DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(set_eof_enter);
287DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(set_info_compound_enter);
288DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(delete_enter);
289DEFINE_SMB3_INF_COMPOUND_ENTER_EVENT(mkdir_enter);
290
291
292DECLARE_EVENT_CLASS(smb3_inf_compound_done_class,
293 TP_PROTO(unsigned int xid,
294 __u32 tid,
295 __u64 sesid),
296 TP_ARGS(xid, tid, sesid),
297 TP_STRUCT__entry(
298 __field(unsigned int, xid)
299 __field(__u32, tid)
300 __field(__u64, sesid)
301 ),
302 TP_fast_assign(
303 __entry->xid = xid;
304 __entry->tid = tid;
305 __entry->sesid = sesid;
306 ),
307 TP_printk("xid=%u sid=0x%llx tid=0x%x",
308 __entry->xid, __entry->sesid, __entry->tid)
309)
310
311#define DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(name) \
312DEFINE_EVENT(smb3_inf_compound_done_class, smb3_##name, \
313 TP_PROTO(unsigned int xid, \
314 __u32 tid, \
315 __u64 sesid), \
316 TP_ARGS(xid, tid, sesid))
317
318DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(query_info_compound_done);
319DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(hardlink_done);
320DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(rename_done);
321DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(rmdir_done);
322DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(set_eof_done);
323DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(set_info_compound_done);
324DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(delete_done);
325DEFINE_SMB3_INF_COMPOUND_DONE_EVENT(mkdir_done);
326
327
328DECLARE_EVENT_CLASS(smb3_inf_compound_err_class,
329 TP_PROTO(unsigned int xid,
330 __u32 tid,
331 __u64 sesid,
332 int rc),
333 TP_ARGS(xid, tid, sesid, rc),
334 TP_STRUCT__entry(
335 __field(unsigned int, xid)
336 __field(__u32, tid)
337 __field(__u64, sesid)
338 __field(int, rc)
339 ),
340 TP_fast_assign(
341 __entry->xid = xid;
342 __entry->tid = tid;
343 __entry->sesid = sesid;
344 __entry->rc = rc;
345 ),
346 TP_printk("xid=%u sid=0x%llx tid=0x%x rc=%d",
347 __entry->xid, __entry->sesid, __entry->tid,
348 __entry->rc)
349)
350
351#define DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(name) \
352DEFINE_EVENT(smb3_inf_compound_err_class, smb3_##name, \
353 TP_PROTO(unsigned int xid, \
354 __u32 tid, \
355 __u64 sesid, \
356 int rc), \
357 TP_ARGS(xid, tid, sesid, rc))
358
359DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(query_info_compound_err);
360DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(hardlink_err);
361DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(rename_err);
362DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(rmdir_err);
363DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(set_eof_err);
364DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(set_info_compound_err);
365DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(mkdir_err);
366DEFINE_SMB3_INF_COMPOUND_ERR_EVENT(delete_err);
367
245/* 368/*
246 * For logging SMB3 Status code and Command for responses which return errors 369 * For logging SMB3 Status code and Command for responses which return errors
247 */ 370 */
@@ -426,19 +549,19 @@ DECLARE_EVENT_CLASS(smb3_tcon_class,
426 __field(unsigned int, xid) 549 __field(unsigned int, xid)
427 __field(__u32, tid) 550 __field(__u32, tid)
428 __field(__u64, sesid) 551 __field(__u64, sesid)
429 __field(const char *, unc_name) 552 __string(name, unc_name)
430 __field(int, rc) 553 __field(int, rc)
431 ), 554 ),
432 TP_fast_assign( 555 TP_fast_assign(
433 __entry->xid = xid; 556 __entry->xid = xid;
434 __entry->tid = tid; 557 __entry->tid = tid;
435 __entry->sesid = sesid; 558 __entry->sesid = sesid;
436 __entry->unc_name = unc_name; 559 __assign_str(name, unc_name);
437 __entry->rc = rc; 560 __entry->rc = rc;
438 ), 561 ),
439 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",
440 __entry->xid, __entry->sesid, __entry->tid, 563 __entry->xid, __entry->sesid, __entry->tid,
441 __entry->unc_name, __entry->rc) 564 __get_str(name), __entry->rc)
442) 565)
443 566
444#define DEFINE_SMB3_TCON_EVENT(name) \ 567#define DEFINE_SMB3_TCON_EVENT(name) \
@@ -713,6 +836,7 @@ DEFINE_EVENT(smb3_credit_class, smb3_##name, \
713 TP_ARGS(currmid, hostname, credits)) 836 TP_ARGS(currmid, hostname, credits))
714 837
715DEFINE_SMB3_CREDIT_EVENT(reconnect_with_invalid_credits); 838DEFINE_SMB3_CREDIT_EVENT(reconnect_with_invalid_credits);
839DEFINE_SMB3_CREDIT_EVENT(credit_timeout);
716 840
717#endif /* _CIFS_TRACE_H */ 841#endif /* _CIFS_TRACE_H */
718 842
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 7ce8a585abd6..1de8e996e566 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -486,15 +486,31 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
486} 486}
487 487
488static int 488static int
489wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, 489wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
490 int *credits, unsigned int *instance) 490 const int timeout, const int flags,
491 unsigned int *instance)
491{ 492{
492 int rc; 493 int rc;
494 int *credits;
495 int optype;
496 long int t;
497
498 if (timeout < 0)
499 t = MAX_JIFFY_OFFSET;
500 else
501 t = msecs_to_jiffies(timeout);
502
503 optype = flags & CIFS_OP_MASK;
493 504
494 *instance = 0; 505 *instance = 0;
495 506
507 credits = server->ops->get_credits_field(server, optype);
508 /* Since an echo is already inflight, no need to wait to send another */
509 if (*credits <= 0 && optype == CIFS_ECHO_OP)
510 return -EAGAIN;
511
496 spin_lock(&server->req_lock); 512 spin_lock(&server->req_lock);
497 if (timeout == CIFS_ASYNC_OP) { 513 if ((flags & CIFS_TIMEOUT_MASK) == CIFS_ASYNC_OP) {
498 /* oplock breaks must not be held up */ 514 /* oplock breaks must not be held up */
499 server->in_flight++; 515 server->in_flight++;
500 *credits -= 1; 516 *credits -= 1;
@@ -504,14 +520,21 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int timeout,
504 } 520 }
505 521
506 while (1) { 522 while (1) {
507 if (*credits <= 0) { 523 if (*credits < num_credits) {
508 spin_unlock(&server->req_lock); 524 spin_unlock(&server->req_lock);
509 cifs_num_waiters_inc(server); 525 cifs_num_waiters_inc(server);
510 rc = wait_event_killable(server->request_q, 526 rc = wait_event_killable_timeout(server->request_q,
511 has_credits(server, credits)); 527 has_credits(server, credits, num_credits), t);
512 cifs_num_waiters_dec(server); 528 cifs_num_waiters_dec(server);
513 if (rc) 529 if (!rc) {
514 return rc; 530 trace_smb3_credit_timeout(server->CurrentMid,
531 server->hostname, num_credits);
532 cifs_dbg(VFS, "wait timed out after %d ms\n",
533 timeout);
534 return -ENOTSUPP;
535 }
536 if (rc == -ERESTARTSYS)
537 return -ERESTARTSYS;
515 spin_lock(&server->req_lock); 538 spin_lock(&server->req_lock);
516 } else { 539 } else {
517 if (server->tcpStatus == CifsExiting) { 540 if (server->tcpStatus == CifsExiting) {
@@ -520,14 +543,52 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int timeout,
520 } 543 }
521 544
522 /* 545 /*
546 * For normal commands, reserve the last MAX_COMPOUND
547 * credits to compound requests.
548 * Otherwise these compounds could be permanently
549 * starved for credits by single-credit requests.
550 *
551 * To prevent spinning CPU, block this thread until
552 * there are >MAX_COMPOUND credits available.
553 * But only do this is we already have a lot of
554 * credits in flight to avoid triggering this check
555 * for servers that are slow to hand out credits on
556 * new sessions.
557 */
558 if (!optype && num_credits == 1 &&
559 server->in_flight > 2 * MAX_COMPOUND &&
560 *credits <= MAX_COMPOUND) {
561 spin_unlock(&server->req_lock);
562 cifs_num_waiters_inc(server);
563 rc = wait_event_killable_timeout(
564 server->request_q,
565 has_credits(server, credits,
566 MAX_COMPOUND + 1),
567 t);
568 cifs_num_waiters_dec(server);
569 if (!rc) {
570 trace_smb3_credit_timeout(
571 server->CurrentMid,
572 server->hostname, num_credits);
573 cifs_dbg(VFS, "wait timed out after %d ms\n",
574 timeout);
575 return -ENOTSUPP;
576 }
577 if (rc == -ERESTARTSYS)
578 return -ERESTARTSYS;
579 spin_lock(&server->req_lock);
580 continue;
581 }
582
583 /*
523 * Can not count locking commands against total 584 * Can not count locking commands against total
524 * as they are allowed to block on server. 585 * as they are allowed to block on server.
525 */ 586 */
526 587
527 /* update # of requests on the wire to server */ 588 /* update # of requests on the wire to server */
528 if (timeout != CIFS_BLOCKING_OP) { 589 if ((flags & CIFS_TIMEOUT_MASK) != CIFS_BLOCKING_OP) {
529 *credits -= 1; 590 *credits -= num_credits;
530 server->in_flight++; 591 server->in_flight += num_credits;
531 *instance = server->reconnect_instance; 592 *instance = server->reconnect_instance;
532 } 593 }
533 spin_unlock(&server->req_lock); 594 spin_unlock(&server->req_lock);
@@ -538,16 +599,36 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int timeout,
538} 599}
539 600
540static int 601static int
541wait_for_free_request(struct TCP_Server_Info *server, const int timeout, 602wait_for_free_request(struct TCP_Server_Info *server, const int flags,
542 const int optype, unsigned int *instance) 603 unsigned int *instance)
543{ 604{
544 int *val; 605 return wait_for_free_credits(server, 1, -1, flags,
606 instance);
607}
545 608
546 val = server->ops->get_credits_field(server, optype); 609static int
547 /* Since an echo is already inflight, no need to wait to send another */ 610wait_for_compound_request(struct TCP_Server_Info *server, int num,
548 if (*val <= 0 && optype == CIFS_ECHO_OP) 611 const int flags, unsigned int *instance)
549 return -EAGAIN; 612{
550 return wait_for_free_credits(server, timeout, val, instance); 613 int *credits;
614
615 credits = server->ops->get_credits_field(server, flags & CIFS_OP_MASK);
616
617 spin_lock(&server->req_lock);
618 if (*credits < num) {
619 /*
620 * Return immediately if not too many requests in flight since
621 * we will likely be stuck on waiting for credits.
622 */
623 if (server->in_flight < num - *credits) {
624 spin_unlock(&server->req_lock);
625 return -ENOTSUPP;
626 }
627 }
628 spin_unlock(&server->req_lock);
629
630 return wait_for_free_credits(server, num, 60000, flags,
631 instance);
551} 632}
552 633
553int 634int
@@ -646,16 +727,16 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
646 mid_handle_t *handle, void *cbdata, const int flags, 727 mid_handle_t *handle, void *cbdata, const int flags,
647 const struct cifs_credits *exist_credits) 728 const struct cifs_credits *exist_credits)
648{ 729{
649 int rc, timeout, optype; 730 int rc;
650 struct mid_q_entry *mid; 731 struct mid_q_entry *mid;
651 struct cifs_credits credits = { .value = 0, .instance = 0 }; 732 struct cifs_credits credits = { .value = 0, .instance = 0 };
652 unsigned int instance; 733 unsigned int instance;
734 int optype;
653 735
654 timeout = flags & CIFS_TIMEOUT_MASK;
655 optype = flags & CIFS_OP_MASK; 736 optype = flags & CIFS_OP_MASK;
656 737
657 if ((flags & CIFS_HAS_CREDITS) == 0) { 738 if ((flags & CIFS_HAS_CREDITS) == 0) {
658 rc = wait_for_free_request(server, timeout, optype, &instance); 739 rc = wait_for_free_request(server, flags, &instance);
659 if (rc) 740 if (rc)
660 return rc; 741 return rc;
661 credits.value = 1; 742 credits.value = 1;
@@ -871,18 +952,15 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
871 const int flags, const int num_rqst, struct smb_rqst *rqst, 952 const int flags, const int num_rqst, struct smb_rqst *rqst,
872 int *resp_buf_type, struct kvec *resp_iov) 953 int *resp_buf_type, struct kvec *resp_iov)
873{ 954{
874 int i, j, rc = 0; 955 int i, j, optype, rc = 0;
875 int timeout, optype;
876 struct mid_q_entry *midQ[MAX_COMPOUND]; 956 struct mid_q_entry *midQ[MAX_COMPOUND];
877 bool cancelled_mid[MAX_COMPOUND] = {false}; 957 bool cancelled_mid[MAX_COMPOUND] = {false};
878 struct cifs_credits credits[MAX_COMPOUND] = { 958 struct cifs_credits credits[MAX_COMPOUND] = {
879 { .value = 0, .instance = 0 } 959 { .value = 0, .instance = 0 }
880 }; 960 };
881 unsigned int instance; 961 unsigned int instance;
882 unsigned int first_instance = 0;
883 char *buf; 962 char *buf;
884 963
885 timeout = flags & CIFS_TIMEOUT_MASK;
886 optype = flags & CIFS_OP_MASK; 964 optype = flags & CIFS_OP_MASK;
887 965
888 for (i = 0; i < num_rqst; i++) 966 for (i = 0; i < num_rqst; i++)
@@ -896,81 +974,24 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
896 if (ses->server->tcpStatus == CifsExiting) 974 if (ses->server->tcpStatus == CifsExiting)
897 return -ENOENT; 975 return -ENOENT;
898 976
899 spin_lock(&ses->server->req_lock);
900 if (ses->server->credits < num_rqst) {
901 /*
902 * Return immediately if not too many requests in flight since
903 * we will likely be stuck on waiting for credits.
904 */
905 if (ses->server->in_flight < num_rqst - ses->server->credits) {
906 spin_unlock(&ses->server->req_lock);
907 return -ENOTSUPP;
908 }
909 } else {
910 /* enough credits to send the whole compounded request */
911 ses->server->credits -= num_rqst;
912 ses->server->in_flight += num_rqst;
913 first_instance = ses->server->reconnect_instance;
914 }
915 spin_unlock(&ses->server->req_lock);
916
917 if (first_instance) {
918 cifs_dbg(FYI, "Acquired %d credits at once\n", num_rqst);
919 for (i = 0; i < num_rqst; i++) {
920 credits[i].value = 1;
921 credits[i].instance = first_instance;
922 }
923 goto setup_rqsts;
924 }
925
926 /* 977 /*
927 * There are not enough credits to send the whole compound request but 978 * Wait for all the requests to become available.
928 * there are requests in flight that may bring credits from the server.
929 * This approach still leaves the possibility to be stuck waiting for 979 * This approach still leaves the possibility to be stuck waiting for
930 * credits if the server doesn't grant credits to the outstanding 980 * credits if the server doesn't grant credits to the outstanding
931 * requests. This should be fixed by returning immediately and letting 981 * requests and if the client is completely idle, not generating any
932 * a caller fallback to sequential commands instead of compounding. 982 * other requests.
933 * Ensure we obtain 1 credit per request in the compound chain. 983 * This can be handled by the eventual session reconnect.
934 */ 984 */
935 for (i = 0; i < num_rqst; i++) { 985 rc = wait_for_compound_request(ses->server, num_rqst, flags,
936 rc = wait_for_free_request(ses->server, timeout, optype, 986 &instance);
937 &instance); 987 if (rc)
938 988 return rc;
939 if (rc == 0) {
940 credits[i].value = 1;
941 credits[i].instance = instance;
942 /*
943 * All parts of the compound chain must get credits from
944 * the same session, otherwise we may end up using more
945 * credits than the server granted. If there were
946 * reconnects in between, return -EAGAIN and let callers
947 * handle it.
948 */
949 if (i == 0)
950 first_instance = instance;
951 else if (first_instance != instance) {
952 i++;
953 rc = -EAGAIN;
954 }
955 }
956 989
957 if (rc) { 990 for (i = 0; i < num_rqst; i++) {
958 /* 991 credits[i].value = 1;
959 * We haven't sent an SMB packet to the server yet but 992 credits[i].instance = instance;
960 * we already obtained credits for i requests in the
961 * compound chain - need to return those credits back
962 * for future use. Note that we need to call add_credits
963 * multiple times to match the way we obtained credits
964 * in the first place and to account for in flight
965 * requests correctly.
966 */
967 for (j = 0; j < i; j++)
968 add_credits(ses->server, &credits[j], optype);
969 return rc;
970 }
971 } 993 }
972 994
973setup_rqsts:
974 /* 995 /*
975 * Make sure that we sign in the same order that we send on this socket 996 * Make sure that we sign in the same order that we send on this socket
976 * and avoid races inside tcp sendmsg code that could cause corruption 997 * and avoid races inside tcp sendmsg code that could cause corruption
@@ -981,14 +1002,12 @@ setup_rqsts:
981 1002
982 /* 1003 /*
983 * All the parts of the compound chain belong obtained credits from the 1004 * All the parts of the compound chain belong obtained credits from the
984 * same session (see the appropriate checks above). In the same time 1005 * same session. We can not use credits obtained from the previous
985 * there might be reconnects after those checks but before we acquired
986 * the srv_mutex. We can not use credits obtained from the previous
987 * session to send this request. Check if there were reconnects after 1006 * session to send this request. Check if there were reconnects after
988 * we obtained credits and return -EAGAIN in such cases to let callers 1007 * we obtained credits and return -EAGAIN in such cases to let callers
989 * handle it. 1008 * handle it.
990 */ 1009 */
991 if (first_instance != ses->server->reconnect_instance) { 1010 if (instance != ses->server->reconnect_instance) {
992 mutex_unlock(&ses->server->srv_mutex); 1011 mutex_unlock(&ses->server->srv_mutex);
993 for (j = 0; j < num_rqst; j++) 1012 for (j = 0; j < num_rqst; j++)
994 add_credits(ses->server, &credits[j], optype); 1013 add_credits(ses->server, &credits[j], optype);
@@ -1057,7 +1076,7 @@ setup_rqsts:
1057 smb311_update_preauth_hash(ses, rqst[0].rq_iov, 1076 smb311_update_preauth_hash(ses, rqst[0].rq_iov,
1058 rqst[0].rq_nvec); 1077 rqst[0].rq_nvec);
1059 1078
1060 if (timeout == CIFS_ASYNC_OP) 1079 if ((flags & CIFS_TIMEOUT_MASK) == CIFS_ASYNC_OP)
1061 goto out; 1080 goto out;
1062 1081
1063 for (i = 0; i < num_rqst; i++) { 1082 for (i = 0; i < num_rqst; i++) {
@@ -1194,7 +1213,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
1194int 1213int
1195SendReceive(const unsigned int xid, struct cifs_ses *ses, 1214SendReceive(const unsigned int xid, struct cifs_ses *ses,
1196 struct smb_hdr *in_buf, struct smb_hdr *out_buf, 1215 struct smb_hdr *in_buf, struct smb_hdr *out_buf,
1197 int *pbytes_returned, const int timeout) 1216 int *pbytes_returned, const int flags)
1198{ 1217{
1199 int rc = 0; 1218 int rc = 0;
1200 struct mid_q_entry *midQ; 1219 struct mid_q_entry *midQ;
@@ -1225,7 +1244,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
1225 return -EIO; 1244 return -EIO;
1226 } 1245 }
1227 1246
1228 rc = wait_for_free_request(ses->server, timeout, 0, &credits.instance); 1247 rc = wait_for_free_request(ses->server, flags, &credits.instance);
1229 if (rc) 1248 if (rc)
1230 return rc; 1249 return rc;
1231 1250
@@ -1264,7 +1283,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
1264 if (rc < 0) 1283 if (rc < 0)
1265 goto out; 1284 goto out;
1266 1285
1267 if (timeout == CIFS_ASYNC_OP) 1286 if ((flags & CIFS_TIMEOUT_MASK) == CIFS_ASYNC_OP)
1268 goto out; 1287 goto out;
1269 1288
1270 rc = wait_for_response(ses->server, midQ); 1289 rc = wait_for_response(ses->server, midQ);
@@ -1367,8 +1386,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
1367 return -EIO; 1386 return -EIO;
1368 } 1387 }
1369 1388
1370 rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0, 1389 rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, &instance);
1371 &instance);
1372 if (rc) 1390 if (rc)
1373 return rc; 1391 return rc;
1374 1392
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/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index f955cd3e0677..a98e1b02279e 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -306,8 +306,9 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
306 goto skip_write; 306 goto skip_write;
307 307
308 /* collect a number of dirty meta pages and write together */ 308 /* collect a number of dirty meta pages and write together */
309 if (wbc->for_kupdate || 309 if (wbc->sync_mode != WB_SYNC_ALL &&
310 get_pages(sbi, F2FS_DIRTY_META) < nr_pages_to_skip(sbi, META)) 310 get_pages(sbi, F2FS_DIRTY_META) <
311 nr_pages_to_skip(sbi, META))
311 goto skip_write; 312 goto skip_write;
312 313
313 /* if locked failed, cp will flush dirty pages instead */ 314 /* if locked failed, cp will flush dirty pages instead */
@@ -405,7 +406,7 @@ static int f2fs_set_meta_page_dirty(struct page *page)
405 if (!PageDirty(page)) { 406 if (!PageDirty(page)) {
406 __set_page_dirty_nobuffers(page); 407 __set_page_dirty_nobuffers(page);
407 inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META); 408 inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META);
408 SetPagePrivate(page); 409 f2fs_set_page_private(page, 0);
409 f2fs_trace_pid(page); 410 f2fs_trace_pid(page);
410 return 1; 411 return 1;
411 } 412 }
@@ -956,7 +957,7 @@ void f2fs_update_dirty_page(struct inode *inode, struct page *page)
956 inode_inc_dirty_pages(inode); 957 inode_inc_dirty_pages(inode);
957 spin_unlock(&sbi->inode_lock[type]); 958 spin_unlock(&sbi->inode_lock[type]);
958 959
959 SetPagePrivate(page); 960 f2fs_set_page_private(page, 0);
960 f2fs_trace_pid(page); 961 f2fs_trace_pid(page);
961} 962}
962 963
@@ -1259,10 +1260,17 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1259 else 1260 else
1260 __clear_ckpt_flags(ckpt, CP_DISABLED_FLAG); 1261 __clear_ckpt_flags(ckpt, CP_DISABLED_FLAG);
1261 1262
1263 if (is_sbi_flag_set(sbi, SBI_CP_DISABLED_QUICK))
1264 __set_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
1265 else
1266 __clear_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
1267
1262 if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) 1268 if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH))
1263 __set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG); 1269 __set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
1264 else 1270 /*
1265 __clear_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG); 1271 * TODO: we count on fsck.f2fs to clear this flag until we figure out
1272 * missing cases which clear it incorrectly.
1273 */
1266 1274
1267 if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR)) 1275 if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR))
1268 __set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG); 1276 __set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 568e1d09eb48..9727944139f2 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -301,9 +301,10 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi,
301 for (; start < F2FS_IO_SIZE(sbi); start++) { 301 for (; start < F2FS_IO_SIZE(sbi); start++) {
302 struct page *page = 302 struct page *page =
303 mempool_alloc(sbi->write_io_dummy, 303 mempool_alloc(sbi->write_io_dummy,
304 GFP_NOIO | __GFP_ZERO | __GFP_NOFAIL); 304 GFP_NOIO | __GFP_NOFAIL);
305 f2fs_bug_on(sbi, !page); 305 f2fs_bug_on(sbi, !page);
306 306
307 zero_user_segment(page, 0, PAGE_SIZE);
307 SetPagePrivate(page); 308 SetPagePrivate(page);
308 set_page_private(page, (unsigned long)DUMMY_WRITTEN_PAGE); 309 set_page_private(page, (unsigned long)DUMMY_WRITTEN_PAGE);
309 lock_page(page); 310 lock_page(page);
@@ -1553,6 +1554,9 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
1553 if (last_block > last_block_in_file) 1554 if (last_block > last_block_in_file)
1554 last_block = last_block_in_file; 1555 last_block = last_block_in_file;
1555 1556
1557 /* just zeroing out page which is beyond EOF */
1558 if (block_in_file >= last_block)
1559 goto zero_out;
1556 /* 1560 /*
1557 * Map blocks using the previous result first. 1561 * Map blocks using the previous result first.
1558 */ 1562 */
@@ -1565,16 +1569,11 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
1565 * Then do more f2fs_map_blocks() calls until we are 1569 * Then do more f2fs_map_blocks() calls until we are
1566 * done with this page. 1570 * done with this page.
1567 */ 1571 */
1568 map.m_flags = 0; 1572 map.m_lblk = block_in_file;
1569 1573 map.m_len = last_block - block_in_file;
1570 if (block_in_file < last_block) {
1571 map.m_lblk = block_in_file;
1572 map.m_len = last_block - block_in_file;
1573 1574
1574 if (f2fs_map_blocks(inode, &map, 0, 1575 if (f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_DEFAULT))
1575 F2FS_GET_BLOCK_DEFAULT)) 1576 goto set_error_page;
1576 goto set_error_page;
1577 }
1578got_it: 1577got_it:
1579 if ((map.m_flags & F2FS_MAP_MAPPED)) { 1578 if ((map.m_flags & F2FS_MAP_MAPPED)) {
1580 block_nr = map.m_pblk + block_in_file - map.m_lblk; 1579 block_nr = map.m_pblk + block_in_file - map.m_lblk;
@@ -1589,6 +1588,7 @@ got_it:
1589 DATA_GENERIC)) 1588 DATA_GENERIC))
1590 goto set_error_page; 1589 goto set_error_page;
1591 } else { 1590 } else {
1591zero_out:
1592 zero_user_segment(page, 0, PAGE_SIZE); 1592 zero_user_segment(page, 0, PAGE_SIZE);
1593 if (!PageUptodate(page)) 1593 if (!PageUptodate(page))
1594 SetPageUptodate(page); 1594 SetPageUptodate(page);
@@ -1863,8 +1863,13 @@ got_it:
1863 if (fio->need_lock == LOCK_REQ) 1863 if (fio->need_lock == LOCK_REQ)
1864 f2fs_unlock_op(fio->sbi); 1864 f2fs_unlock_op(fio->sbi);
1865 err = f2fs_inplace_write_data(fio); 1865 err = f2fs_inplace_write_data(fio);
1866 if (err && PageWriteback(page)) 1866 if (err) {
1867 end_page_writeback(page); 1867 if (f2fs_encrypted_file(inode))
1868 fscrypt_pullback_bio_page(&fio->encrypted_page,
1869 true);
1870 if (PageWriteback(page))
1871 end_page_writeback(page);
1872 }
1868 trace_f2fs_do_write_data_page(fio->page, IPU); 1873 trace_f2fs_do_write_data_page(fio->page, IPU);
1869 set_inode_flag(inode, FI_UPDATE_WRITE); 1874 set_inode_flag(inode, FI_UPDATE_WRITE);
1870 return err; 1875 return err;
@@ -2315,7 +2320,8 @@ static void f2fs_write_failed(struct address_space *mapping, loff_t to)
2315 down_write(&F2FS_I(inode)->i_mmap_sem); 2320 down_write(&F2FS_I(inode)->i_mmap_sem);
2316 2321
2317 truncate_pagecache(inode, i_size); 2322 truncate_pagecache(inode, i_size);
2318 f2fs_truncate_blocks(inode, i_size, true, true); 2323 if (!IS_NOQUOTA(inode))
2324 f2fs_truncate_blocks(inode, i_size, true);
2319 2325
2320 up_write(&F2FS_I(inode)->i_mmap_sem); 2326 up_write(&F2FS_I(inode)->i_mmap_sem);
2321 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 2327 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
@@ -2585,14 +2591,11 @@ static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode,
2585{ 2591{
2586 struct f2fs_private_dio *dio; 2592 struct f2fs_private_dio *dio;
2587 bool write = (bio_op(bio) == REQ_OP_WRITE); 2593 bool write = (bio_op(bio) == REQ_OP_WRITE);
2588 int err;
2589 2594
2590 dio = f2fs_kzalloc(F2FS_I_SB(inode), 2595 dio = f2fs_kzalloc(F2FS_I_SB(inode),
2591 sizeof(struct f2fs_private_dio), GFP_NOFS); 2596 sizeof(struct f2fs_private_dio), GFP_NOFS);
2592 if (!dio) { 2597 if (!dio)
2593 err = -ENOMEM;
2594 goto out; 2598 goto out;
2595 }
2596 2599
2597 dio->inode = inode; 2600 dio->inode = inode;
2598 dio->orig_end_io = bio->bi_end_io; 2601 dio->orig_end_io = bio->bi_end_io;
@@ -2710,12 +2713,10 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
2710 2713
2711 clear_cold_data(page); 2714 clear_cold_data(page);
2712 2715
2713 /* This is atomic written page, keep Private */
2714 if (IS_ATOMIC_WRITTEN_PAGE(page)) 2716 if (IS_ATOMIC_WRITTEN_PAGE(page))
2715 return f2fs_drop_inmem_page(inode, page); 2717 return f2fs_drop_inmem_page(inode, page);
2716 2718
2717 set_page_private(page, 0); 2719 f2fs_clear_page_private(page);
2718 ClearPagePrivate(page);
2719} 2720}
2720 2721
2721int f2fs_release_page(struct page *page, gfp_t wait) 2722int f2fs_release_page(struct page *page, gfp_t wait)
@@ -2729,8 +2730,7 @@ int f2fs_release_page(struct page *page, gfp_t wait)
2729 return 0; 2730 return 0;
2730 2731
2731 clear_cold_data(page); 2732 clear_cold_data(page);
2732 set_page_private(page, 0); 2733 f2fs_clear_page_private(page);
2733 ClearPagePrivate(page);
2734 return 1; 2734 return 1;
2735} 2735}
2736 2736
@@ -2798,12 +2798,8 @@ int f2fs_migrate_page(struct address_space *mapping,
2798 return -EAGAIN; 2798 return -EAGAIN;
2799 } 2799 }
2800 2800
2801 /* 2801 /* one extra reference was held for atomic_write page */
2802 * A reference is expected if PagePrivate set when move mapping, 2802 extra_count = atomic_written ? 1 : 0;
2803 * however F2FS breaks this for maintaining dirty page counts when
2804 * truncating pages. So here adjusting the 'extra_count' make it work.
2805 */
2806 extra_count = (atomic_written ? 1 : 0) - page_has_private(page);
2807 rc = migrate_page_move_mapping(mapping, newpage, 2803 rc = migrate_page_move_mapping(mapping, newpage,
2808 page, mode, extra_count); 2804 page, mode, extra_count);
2809 if (rc != MIGRATEPAGE_SUCCESS) { 2805 if (rc != MIGRATEPAGE_SUCCESS) {
@@ -2824,9 +2820,10 @@ int f2fs_migrate_page(struct address_space *mapping,
2824 get_page(newpage); 2820 get_page(newpage);
2825 } 2821 }
2826 2822
2827 if (PagePrivate(page)) 2823 if (PagePrivate(page)) {
2828 SetPagePrivate(newpage); 2824 f2fs_set_page_private(newpage, page_private(page));
2829 set_page_private(newpage, page_private(page)); 2825 f2fs_clear_page_private(page);
2826 }
2830 2827
2831 if (mode != MIGRATE_SYNC_NO_COPY) 2828 if (mode != MIGRATE_SYNC_NO_COPY)
2832 migrate_page_copy(newpage, page); 2829 migrate_page_copy(newpage, page);
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index fd7f170e2f2d..99e9a5c37b71 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -96,8 +96,10 @@ static void update_general_status(struct f2fs_sb_info *sbi)
96 si->free_secs = free_sections(sbi); 96 si->free_secs = free_sections(sbi);
97 si->prefree_count = prefree_segments(sbi); 97 si->prefree_count = prefree_segments(sbi);
98 si->dirty_count = dirty_segments(sbi); 98 si->dirty_count = dirty_segments(sbi);
99 si->node_pages = NODE_MAPPING(sbi)->nrpages; 99 if (sbi->node_inode)
100 si->meta_pages = META_MAPPING(sbi)->nrpages; 100 si->node_pages = NODE_MAPPING(sbi)->nrpages;
101 if (sbi->meta_inode)
102 si->meta_pages = META_MAPPING(sbi)->nrpages;
101 si->nats = NM_I(sbi)->nat_cnt; 103 si->nats = NM_I(sbi)->nat_cnt;
102 si->dirty_nats = NM_I(sbi)->dirty_nat_cnt; 104 si->dirty_nats = NM_I(sbi)->dirty_nat_cnt;
103 si->sits = MAIN_SEGS(sbi); 105 si->sits = MAIN_SEGS(sbi);
@@ -175,7 +177,6 @@ static void update_sit_info(struct f2fs_sb_info *sbi)
175static void update_mem_info(struct f2fs_sb_info *sbi) 177static void update_mem_info(struct f2fs_sb_info *sbi)
176{ 178{
177 struct f2fs_stat_info *si = F2FS_STAT(sbi); 179 struct f2fs_stat_info *si = F2FS_STAT(sbi);
178 unsigned npages;
179 int i; 180 int i;
180 181
181 if (si->base_mem) 182 if (si->base_mem)
@@ -258,10 +259,14 @@ get_cache:
258 sizeof(struct extent_node); 259 sizeof(struct extent_node);
259 260
260 si->page_mem = 0; 261 si->page_mem = 0;
261 npages = NODE_MAPPING(sbi)->nrpages; 262 if (sbi->node_inode) {
262 si->page_mem += (unsigned long long)npages << PAGE_SHIFT; 263 unsigned npages = NODE_MAPPING(sbi)->nrpages;
263 npages = META_MAPPING(sbi)->nrpages; 264 si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
264 si->page_mem += (unsigned long long)npages << PAGE_SHIFT; 265 }
266 if (sbi->meta_inode) {
267 unsigned npages = META_MAPPING(sbi)->nrpages;
268 si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
269 }
265} 270}
266 271
267static int stat_show(struct seq_file *s, void *v) 272static int stat_show(struct seq_file *s, void *v)
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 713b36a10a79..59bc46017855 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -728,7 +728,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
728 !f2fs_truncate_hole(dir, page->index, page->index + 1)) { 728 !f2fs_truncate_hole(dir, page->index, page->index + 1)) {
729 f2fs_clear_page_cache_dirty_tag(page); 729 f2fs_clear_page_cache_dirty_tag(page);
730 clear_page_dirty_for_io(page); 730 clear_page_dirty_for_io(page);
731 ClearPagePrivate(page); 731 f2fs_clear_page_private(page);
732 ClearPageUptodate(page); 732 ClearPageUptodate(page);
733 clear_cold_data(page); 733 clear_cold_data(page);
734 inode_dec_dirty_pages(dir); 734 inode_dec_dirty_pages(dir);
@@ -800,6 +800,10 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
800 if (de->name_len == 0) { 800 if (de->name_len == 0) {
801 bit_pos++; 801 bit_pos++;
802 ctx->pos = start_pos + bit_pos; 802 ctx->pos = start_pos + bit_pos;
803 printk_ratelimited(
804 "%s, invalid namelen(0), ino:%u, run fsck to fix.",
805 KERN_WARNING, le32_to_cpu(de->ino));
806 set_sbi_flag(sbi, SBI_NEED_FSCK);
803 continue; 807 continue;
804 } 808 }
805 809
@@ -810,7 +814,8 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
810 814
811 /* check memory boundary before moving forward */ 815 /* check memory boundary before moving forward */
812 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 816 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
813 if (unlikely(bit_pos > d->max)) { 817 if (unlikely(bit_pos > d->max ||
818 le16_to_cpu(de->name_len) > F2FS_NAME_LEN)) {
814 f2fs_msg(sbi->sb, KERN_WARNING, 819 f2fs_msg(sbi->sb, KERN_WARNING,
815 "%s: corrupted namelen=%d, run fsck to fix.", 820 "%s: corrupted namelen=%d, run fsck to fix.",
816 __func__, le16_to_cpu(de->name_len)); 821 __func__, le16_to_cpu(de->name_len));
@@ -891,7 +896,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
891 page_cache_sync_readahead(inode->i_mapping, ra, file, n, 896 page_cache_sync_readahead(inode->i_mapping, ra, file, n,
892 min(npages - n, (pgoff_t)MAX_DIR_RA_PAGES)); 897 min(npages - n, (pgoff_t)MAX_DIR_RA_PAGES));
893 898
894 dentry_page = f2fs_get_lock_data_page(inode, n, false); 899 dentry_page = f2fs_find_data_page(inode, n);
895 if (IS_ERR(dentry_page)) { 900 if (IS_ERR(dentry_page)) {
896 err = PTR_ERR(dentry_page); 901 err = PTR_ERR(dentry_page);
897 if (err == -ENOENT) { 902 if (err == -ENOENT) {
@@ -909,11 +914,11 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
909 err = f2fs_fill_dentries(ctx, &d, 914 err = f2fs_fill_dentries(ctx, &d,
910 n * NR_DENTRY_IN_BLOCK, &fstr); 915 n * NR_DENTRY_IN_BLOCK, &fstr);
911 if (err) { 916 if (err) {
912 f2fs_put_page(dentry_page, 1); 917 f2fs_put_page(dentry_page, 0);
913 break; 918 break;
914 } 919 }
915 920
916 f2fs_put_page(dentry_page, 1); 921 f2fs_put_page(dentry_page, 0);
917 } 922 }
918out_free: 923out_free:
919 fscrypt_fname_free_buffer(&fstr); 924 fscrypt_fname_free_buffer(&fstr);
diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 1cb0fcc67d2d..caf77fe8ac07 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -506,7 +506,7 @@ static void f2fs_update_extent_tree_range(struct inode *inode,
506 unsigned int end = fofs + len; 506 unsigned int end = fofs + len;
507 unsigned int pos = (unsigned int)fofs; 507 unsigned int pos = (unsigned int)fofs;
508 bool updated = false; 508 bool updated = false;
509 bool leftmost; 509 bool leftmost = false;
510 510
511 if (!et) 511 if (!et)
512 return; 512 return;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 7ea5c9cede37..87f75ebd2fd6 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -190,6 +190,8 @@ enum {
190#define DEF_CP_INTERVAL 60 /* 60 secs */ 190#define DEF_CP_INTERVAL 60 /* 60 secs */
191#define DEF_IDLE_INTERVAL 5 /* 5 secs */ 191#define DEF_IDLE_INTERVAL 5 /* 5 secs */
192#define DEF_DISABLE_INTERVAL 5 /* 5 secs */ 192#define DEF_DISABLE_INTERVAL 5 /* 5 secs */
193#define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */
194#define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */
193 195
194struct cp_control { 196struct cp_control {
195 int reason; 197 int reason;
@@ -253,7 +255,7 @@ struct discard_entry {
253/* max discard pend list number */ 255/* max discard pend list number */
254#define MAX_PLIST_NUM 512 256#define MAX_PLIST_NUM 512
255#define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 257#define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \
256 (MAX_PLIST_NUM - 1) : (blk_num - 1)) 258 (MAX_PLIST_NUM - 1) : ((blk_num) - 1))
257 259
258enum { 260enum {
259 D_PREP, /* initial */ 261 D_PREP, /* initial */
@@ -309,6 +311,7 @@ struct discard_policy {
309 bool sync; /* submit discard with REQ_SYNC flag */ 311 bool sync; /* submit discard with REQ_SYNC flag */
310 bool ordered; /* issue discard by lba order */ 312 bool ordered; /* issue discard by lba order */
311 unsigned int granularity; /* discard granularity */ 313 unsigned int granularity; /* discard granularity */
314 int timeout; /* discard timeout for put_super */
312}; 315};
313 316
314struct discard_cmd_control { 317struct discard_cmd_control {
@@ -455,7 +458,6 @@ struct f2fs_flush_device {
455 458
456/* for inline stuff */ 459/* for inline stuff */
457#define DEF_INLINE_RESERVED_SIZE 1 460#define DEF_INLINE_RESERVED_SIZE 1
458#define DEF_MIN_INLINE_SIZE 1
459static inline int get_extra_isize(struct inode *inode); 461static inline int get_extra_isize(struct inode *inode);
460static inline int get_inline_xattr_addrs(struct inode *inode); 462static inline int get_inline_xattr_addrs(struct inode *inode);
461#define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 463#define MAX_INLINE_DATA(inode) (sizeof(__le32) * \
@@ -1098,6 +1100,7 @@ enum {
1098 SBI_IS_SHUTDOWN, /* shutdown by ioctl */ 1100 SBI_IS_SHUTDOWN, /* shutdown by ioctl */
1099 SBI_IS_RECOVERED, /* recovered orphan/data */ 1101 SBI_IS_RECOVERED, /* recovered orphan/data */
1100 SBI_CP_DISABLED, /* CP was disabled last mount */ 1102 SBI_CP_DISABLED, /* CP was disabled last mount */
1103 SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */
1101 SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ 1104 SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */
1102 SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ 1105 SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */
1103 SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ 1106 SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */
@@ -1109,6 +1112,7 @@ enum {
1109 DISCARD_TIME, 1112 DISCARD_TIME,
1110 GC_TIME, 1113 GC_TIME,
1111 DISABLE_TIME, 1114 DISABLE_TIME,
1115 UMOUNT_DISCARD_TIMEOUT,
1112 MAX_TIME, 1116 MAX_TIME,
1113}; 1117};
1114 1118
@@ -1237,8 +1241,6 @@ struct f2fs_sb_info {
1237 1241
1238 unsigned int nquota_files; /* # of quota sysfile */ 1242 unsigned int nquota_files; /* # of quota sysfile */
1239 1243
1240 u32 s_next_generation; /* for NFS support */
1241
1242 /* # of pages, see count_type */ 1244 /* # of pages, see count_type */
1243 atomic_t nr_pages[NR_COUNT_TYPE]; 1245 atomic_t nr_pages[NR_COUNT_TYPE];
1244 /* # of allocated blocks */ 1246 /* # of allocated blocks */
@@ -1798,13 +1800,12 @@ static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
1798{ 1800{
1799 atomic_inc(&sbi->nr_pages[count_type]); 1801 atomic_inc(&sbi->nr_pages[count_type]);
1800 1802
1801 if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 1803 if (count_type == F2FS_DIRTY_DENTS ||
1802 count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA || 1804 count_type == F2FS_DIRTY_NODES ||
1803 count_type == F2FS_RD_DATA || count_type == F2FS_RD_NODE || 1805 count_type == F2FS_DIRTY_META ||
1804 count_type == F2FS_RD_META) 1806 count_type == F2FS_DIRTY_QDATA ||
1805 return; 1807 count_type == F2FS_DIRTY_IMETA)
1806 1808 set_sbi_flag(sbi, SBI_IS_DIRTY);
1807 set_sbi_flag(sbi, SBI_IS_DIRTY);
1808} 1809}
1809 1810
1810static inline void inode_inc_dirty_pages(struct inode *inode) 1811static inline void inode_inc_dirty_pages(struct inode *inode)
@@ -2156,10 +2157,17 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
2156 get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2157 get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) ||
2157 get_pages(sbi, F2FS_WB_CP_DATA) || 2158 get_pages(sbi, F2FS_WB_CP_DATA) ||
2158 get_pages(sbi, F2FS_DIO_READ) || 2159 get_pages(sbi, F2FS_DIO_READ) ||
2159 get_pages(sbi, F2FS_DIO_WRITE) || 2160 get_pages(sbi, F2FS_DIO_WRITE))
2160 atomic_read(&SM_I(sbi)->dcc_info->queued_discard) ||
2161 atomic_read(&SM_I(sbi)->fcc_info->queued_flush))
2162 return false; 2161 return false;
2162
2163 if (SM_I(sbi) && SM_I(sbi)->dcc_info &&
2164 atomic_read(&SM_I(sbi)->dcc_info->queued_discard))
2165 return false;
2166
2167 if (SM_I(sbi) && SM_I(sbi)->fcc_info &&
2168 atomic_read(&SM_I(sbi)->fcc_info->queued_flush))
2169 return false;
2170
2163 return f2fs_time_over(sbi, type); 2171 return f2fs_time_over(sbi, type);
2164} 2172}
2165 2173
@@ -2300,11 +2308,12 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr)
2300#define F2FS_EXTENTS_FL 0x00080000 /* Inode uses extents */ 2308#define F2FS_EXTENTS_FL 0x00080000 /* Inode uses extents */
2301#define F2FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */ 2309#define F2FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2302#define F2FS_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */ 2310#define F2FS_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2311#define F2FS_NOCOW_FL 0x00800000 /* Do not cow file */
2303#define F2FS_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */ 2312#define F2FS_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
2304#define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 2313#define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
2305#define F2FS_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ 2314#define F2FS_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
2306 2315
2307#define F2FS_FL_USER_VISIBLE 0x304BDFFF /* User visible flags */ 2316#define F2FS_FL_USER_VISIBLE 0x30CBDFFF /* User visible flags */
2308#define F2FS_FL_USER_MODIFIABLE 0x204BC0FF /* User modifiable flags */ 2317#define F2FS_FL_USER_MODIFIABLE 0x204BC0FF /* User modifiable flags */
2309 2318
2310/* Flags we can manipulate with through F2FS_IOC_FSSETXATTR */ 2319/* Flags we can manipulate with through F2FS_IOC_FSSETXATTR */
@@ -2761,9 +2770,9 @@ static inline int get_inline_xattr_addrs(struct inode *inode)
2761 2770
2762#define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 2771#define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr))
2763#define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 2772#define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \
2764 ((offsetof(typeof(*f2fs_inode), field) + \ 2773 ((offsetof(typeof(*(f2fs_inode)), field) + \
2765 sizeof((f2fs_inode)->field)) \ 2774 sizeof((f2fs_inode)->field)) \
2766 <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ 2775 <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \
2767 2776
2768static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2777static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
2769{ 2778{
@@ -2792,8 +2801,8 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
2792 2801
2793#define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 2802#define __is_large_section(sbi) ((sbi)->segs_per_sec > 1)
2794 2803
2795#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \ 2804#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META && \
2796 (!is_read_io(fio->op) || fio->is_meta)) 2805 (!is_read_io((fio)->op) || (fio)->is_meta))
2797 2806
2798bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 2807bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
2799 block_t blkaddr, int type); 2808 block_t blkaddr, int type);
@@ -2825,13 +2834,33 @@ static inline bool is_valid_data_blkaddr(struct f2fs_sb_info *sbi,
2825 return true; 2834 return true;
2826} 2835}
2827 2836
2837static inline void f2fs_set_page_private(struct page *page,
2838 unsigned long data)
2839{
2840 if (PagePrivate(page))
2841 return;
2842
2843 get_page(page);
2844 SetPagePrivate(page);
2845 set_page_private(page, data);
2846}
2847
2848static inline void f2fs_clear_page_private(struct page *page)
2849{
2850 if (!PagePrivate(page))
2851 return;
2852
2853 set_page_private(page, 0);
2854 ClearPagePrivate(page);
2855 f2fs_put_page(page, 0);
2856}
2857
2828/* 2858/*
2829 * file.c 2859 * file.c
2830 */ 2860 */
2831int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2861int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
2832void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 2862void f2fs_truncate_data_blocks(struct dnode_of_data *dn);
2833int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock, 2863int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock);
2834 bool buf_write);
2835int f2fs_truncate(struct inode *inode); 2864int f2fs_truncate(struct inode *inode);
2836int f2fs_getattr(const struct path *path, struct kstat *stat, 2865int f2fs_getattr(const struct path *path, struct kstat *stat,
2837 u32 request_mask, unsigned int flags); 2866 u32 request_mask, unsigned int flags);
@@ -3005,7 +3034,7 @@ void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
3005bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 3034bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
3006void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); 3035void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi);
3007void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); 3036void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi);
3008bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 3037bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi);
3009void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, 3038void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
3010 struct cp_control *cpc); 3039 struct cp_control *cpc);
3011void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); 3040void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi);
@@ -3610,8 +3639,6 @@ extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
3610#define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 3639#define f2fs_build_fault_attr(sbi, rate, type) do { } while (0)
3611#endif 3640#endif
3612 3641
3613#endif
3614
3615static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 3642static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
3616{ 3643{
3617#ifdef CONFIG_QUOTA 3644#ifdef CONFIG_QUOTA
@@ -3624,3 +3651,5 @@ static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
3624#endif 3651#endif
3625 return false; 3652 return false;
3626} 3653}
3654
3655#endif
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index ba5954f41e14..5742ab8b57dc 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -589,8 +589,7 @@ truncate_out:
589 return 0; 589 return 0;
590} 590}
591 591
592int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock, 592int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock)
593 bool buf_write)
594{ 593{
595 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 594 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
596 struct dnode_of_data dn; 595 struct dnode_of_data dn;
@@ -598,7 +597,6 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock,
598 int count = 0, err = 0; 597 int count = 0, err = 0;
599 struct page *ipage; 598 struct page *ipage;
600 bool truncate_page = false; 599 bool truncate_page = false;
601 int flag = buf_write ? F2FS_GET_BLOCK_PRE_AIO : F2FS_GET_BLOCK_PRE_DIO;
602 600
603 trace_f2fs_truncate_blocks_enter(inode, from); 601 trace_f2fs_truncate_blocks_enter(inode, from);
604 602
@@ -608,7 +606,7 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock,
608 goto free_partial; 606 goto free_partial;
609 607
610 if (lock) 608 if (lock)
611 __do_map_lock(sbi, flag, true); 609 f2fs_lock_op(sbi);
612 610
613 ipage = f2fs_get_node_page(sbi, inode->i_ino); 611 ipage = f2fs_get_node_page(sbi, inode->i_ino);
614 if (IS_ERR(ipage)) { 612 if (IS_ERR(ipage)) {
@@ -646,7 +644,7 @@ free_next:
646 err = f2fs_truncate_inode_blocks(inode, free_from); 644 err = f2fs_truncate_inode_blocks(inode, free_from);
647out: 645out:
648 if (lock) 646 if (lock)
649 __do_map_lock(sbi, flag, false); 647 f2fs_unlock_op(sbi);
650free_partial: 648free_partial:
651 /* lastly zero out the first data page */ 649 /* lastly zero out the first data page */
652 if (!err) 650 if (!err)
@@ -681,7 +679,7 @@ int f2fs_truncate(struct inode *inode)
681 return err; 679 return err;
682 } 680 }
683 681
684 err = f2fs_truncate_blocks(inode, i_size_read(inode), true, false); 682 err = f2fs_truncate_blocks(inode, i_size_read(inode), true);
685 if (err) 683 if (err)
686 return err; 684 return err;
687 685
@@ -768,7 +766,6 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
768{ 766{
769 struct inode *inode = d_inode(dentry); 767 struct inode *inode = d_inode(dentry);
770 int err; 768 int err;
771 bool size_changed = false;
772 769
773 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) 770 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
774 return -EIO; 771 return -EIO;
@@ -843,8 +840,6 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
843 down_write(&F2FS_I(inode)->i_sem); 840 down_write(&F2FS_I(inode)->i_sem);
844 F2FS_I(inode)->last_disk_size = i_size_read(inode); 841 F2FS_I(inode)->last_disk_size = i_size_read(inode);
845 up_write(&F2FS_I(inode)->i_sem); 842 up_write(&F2FS_I(inode)->i_sem);
846
847 size_changed = true;
848 } 843 }
849 844
850 __setattr_copy(inode, attr); 845 __setattr_copy(inode, attr);
@@ -858,7 +853,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
858 } 853 }
859 854
860 /* file size may changed here */ 855 /* file size may changed here */
861 f2fs_mark_inode_dirty_sync(inode, size_changed); 856 f2fs_mark_inode_dirty_sync(inode, true);
862 857
863 /* inode change will produce dirty node pages flushed by checkpoint */ 858 /* inode change will produce dirty node pages flushed by checkpoint */
864 f2fs_balance_fs(F2FS_I_SB(inode), true); 859 f2fs_balance_fs(F2FS_I_SB(inode), true);
@@ -1262,7 +1257,7 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
1262 new_size = i_size_read(inode) - len; 1257 new_size = i_size_read(inode) - len;
1263 truncate_pagecache(inode, new_size); 1258 truncate_pagecache(inode, new_size);
1264 1259
1265 ret = f2fs_truncate_blocks(inode, new_size, true, false); 1260 ret = f2fs_truncate_blocks(inode, new_size, true);
1266 up_write(&F2FS_I(inode)->i_mmap_sem); 1261 up_write(&F2FS_I(inode)->i_mmap_sem);
1267 if (!ret) 1262 if (!ret)
1268 f2fs_i_size_write(inode, new_size); 1263 f2fs_i_size_write(inode, new_size);
@@ -1447,7 +1442,7 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
1447 f2fs_balance_fs(sbi, true); 1442 f2fs_balance_fs(sbi, true);
1448 1443
1449 down_write(&F2FS_I(inode)->i_mmap_sem); 1444 down_write(&F2FS_I(inode)->i_mmap_sem);
1450 ret = f2fs_truncate_blocks(inode, i_size_read(inode), true, false); 1445 ret = f2fs_truncate_blocks(inode, i_size_read(inode), true);
1451 up_write(&F2FS_I(inode)->i_mmap_sem); 1446 up_write(&F2FS_I(inode)->i_mmap_sem);
1452 if (ret) 1447 if (ret)
1453 return ret; 1448 return ret;
@@ -1651,6 +1646,8 @@ static int f2fs_ioc_getflags(struct file *filp, unsigned long arg)
1651 flags |= F2FS_ENCRYPT_FL; 1646 flags |= F2FS_ENCRYPT_FL;
1652 if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) 1647 if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode))
1653 flags |= F2FS_INLINE_DATA_FL; 1648 flags |= F2FS_INLINE_DATA_FL;
1649 if (is_inode_flag_set(inode, FI_PIN_FILE))
1650 flags |= F2FS_NOCOW_FL;
1654 1651
1655 flags &= F2FS_FL_USER_VISIBLE; 1652 flags &= F2FS_FL_USER_VISIBLE;
1656 1653
@@ -1750,10 +1747,12 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
1750 1747
1751 down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 1748 down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
1752 1749
1753 if (!get_dirty_pages(inode)) 1750 /*
1754 goto skip_flush; 1751 * Should wait end_io to count F2FS_WB_CP_DATA correctly by
1755 1752 * f2fs_is_atomic_file.
1756 f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING, 1753 */
1754 if (get_dirty_pages(inode))
1755 f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING,
1757 "Unexpected flush for atomic writes: ino=%lu, npages=%u", 1756 "Unexpected flush for atomic writes: ino=%lu, npages=%u",
1758 inode->i_ino, get_dirty_pages(inode)); 1757 inode->i_ino, get_dirty_pages(inode));
1759 ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); 1758 ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
@@ -1761,7 +1760,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
1761 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 1760 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
1762 goto out; 1761 goto out;
1763 } 1762 }
1764skip_flush: 1763
1765 set_inode_flag(inode, FI_ATOMIC_FILE); 1764 set_inode_flag(inode, FI_ATOMIC_FILE);
1766 clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST); 1765 clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST);
1767 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 1766 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
@@ -1968,11 +1967,11 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg)
1968 break; 1967 break;
1969 case F2FS_GOING_DOWN_NEED_FSCK: 1968 case F2FS_GOING_DOWN_NEED_FSCK:
1970 set_sbi_flag(sbi, SBI_NEED_FSCK); 1969 set_sbi_flag(sbi, SBI_NEED_FSCK);
1970 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
1971 set_sbi_flag(sbi, SBI_IS_DIRTY);
1971 /* do checkpoint only */ 1972 /* do checkpoint only */
1972 ret = f2fs_sync_fs(sb, 1); 1973 ret = f2fs_sync_fs(sb, 1);
1973 if (ret) 1974 goto out;
1974 goto out;
1975 break;
1976 default: 1975 default:
1977 ret = -EINVAL; 1976 ret = -EINVAL;
1978 goto out; 1977 goto out;
@@ -1988,6 +1987,9 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg)
1988out: 1987out:
1989 if (in != F2FS_GOING_DOWN_FULLSYNC) 1988 if (in != F2FS_GOING_DOWN_FULLSYNC)
1990 mnt_drop_write_file(filp); 1989 mnt_drop_write_file(filp);
1990
1991 trace_f2fs_shutdown(sbi, in, ret);
1992
1991 return ret; 1993 return ret;
1992} 1994}
1993 1995
@@ -2871,8 +2873,8 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
2871 __u32 pin; 2873 __u32 pin;
2872 int ret = 0; 2874 int ret = 0;
2873 2875
2874 if (!inode_owner_or_capable(inode)) 2876 if (!capable(CAP_SYS_ADMIN))
2875 return -EACCES; 2877 return -EPERM;
2876 2878
2877 if (get_user(pin, (__u32 __user *)arg)) 2879 if (get_user(pin, (__u32 __user *)arg))
2878 return -EFAULT; 2880 return -EFAULT;
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index d636cbcf68f2..bb6a152310ef 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -298,7 +298,7 @@ process_inline:
298 clear_inode_flag(inode, FI_INLINE_DATA); 298 clear_inode_flag(inode, FI_INLINE_DATA);
299 f2fs_put_page(ipage, 1); 299 f2fs_put_page(ipage, 1);
300 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) { 300 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
301 if (f2fs_truncate_blocks(inode, 0, false, false)) 301 if (f2fs_truncate_blocks(inode, 0, false))
302 return false; 302 return false;
303 goto process_inline; 303 goto process_inline;
304 } 304 }
@@ -470,7 +470,7 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
470 return 0; 470 return 0;
471punch_dentry_pages: 471punch_dentry_pages:
472 truncate_inode_pages(&dir->i_data, 0); 472 truncate_inode_pages(&dir->i_data, 0);
473 f2fs_truncate_blocks(dir, 0, false, false); 473 f2fs_truncate_blocks(dir, 0, false);
474 f2fs_remove_dirty_inode(dir); 474 f2fs_remove_dirty_inode(dir);
475 return err; 475 return err;
476} 476}
@@ -659,6 +659,12 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
659 if (IS_ERR(ipage)) 659 if (IS_ERR(ipage))
660 return PTR_ERR(ipage); 660 return PTR_ERR(ipage);
661 661
662 /*
663 * f2fs_readdir was protected by inode.i_rwsem, it is safe to access
664 * ipage without page's lock held.
665 */
666 unlock_page(ipage);
667
662 inline_dentry = inline_data_addr(inode, ipage); 668 inline_dentry = inline_data_addr(inode, ipage);
663 669
664 make_dentry_ptr_inline(inode, &d, inline_dentry); 670 make_dentry_ptr_inline(inode, &d, inline_dentry);
@@ -667,7 +673,7 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
667 if (!err) 673 if (!err)
668 ctx->pos = d.max; 674 ctx->pos = d.max;
669 675
670 f2fs_put_page(ipage, 1); 676 f2fs_put_page(ipage, 0);
671 return err < 0 ? err : 0; 677 return err < 0 ? err : 0;
672} 678}
673 679
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index d910a820ae67..e7f2e8759315 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -14,6 +14,7 @@
14#include "f2fs.h" 14#include "f2fs.h"
15#include "node.h" 15#include "node.h"
16#include "segment.h" 16#include "segment.h"
17#include "xattr.h"
17 18
18#include <trace/events/f2fs.h> 19#include <trace/events/f2fs.h>
19 20
@@ -248,6 +249,20 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
248 return false; 249 return false;
249 } 250 }
250 251
252 if (f2fs_has_extra_attr(inode) &&
253 f2fs_sb_has_flexible_inline_xattr(sbi) &&
254 f2fs_has_inline_xattr(inode) &&
255 (!fi->i_inline_xattr_size ||
256 fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE)) {
257 set_sbi_flag(sbi, SBI_NEED_FSCK);
258 f2fs_msg(sbi->sb, KERN_WARNING,
259 "%s: inode (ino=%lx) has corrupted "
260 "i_inline_xattr_size: %d, max: %zu",
261 __func__, inode->i_ino, fi->i_inline_xattr_size,
262 MAX_INLINE_XATTR_SIZE);
263 return false;
264 }
265
251 if (F2FS_I(inode)->extent_tree) { 266 if (F2FS_I(inode)->extent_tree) {
252 struct extent_info *ei = &F2FS_I(inode)->extent_tree->largest; 267 struct extent_info *ei = &F2FS_I(inode)->extent_tree->largest;
253 268
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index e967d27c1a89..f5e34e467003 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -10,6 +10,7 @@
10#include <linux/pagemap.h> 10#include <linux/pagemap.h>
11#include <linux/sched.h> 11#include <linux/sched.h>
12#include <linux/ctype.h> 12#include <linux/ctype.h>
13#include <linux/random.h>
13#include <linux/dcache.h> 14#include <linux/dcache.h>
14#include <linux/namei.h> 15#include <linux/namei.h>
15#include <linux/quotaops.h> 16#include <linux/quotaops.h>
@@ -50,7 +51,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
50 inode->i_blocks = 0; 51 inode->i_blocks = 0;
51 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); 52 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
52 F2FS_I(inode)->i_crtime = inode->i_mtime; 53 F2FS_I(inode)->i_crtime = inode->i_mtime;
53 inode->i_generation = sbi->s_next_generation++; 54 inode->i_generation = prandom_u32();
54 55
55 if (S_ISDIR(inode->i_mode)) 56 if (S_ISDIR(inode->i_mode))
56 F2FS_I(inode)->i_current_depth = 1; 57 F2FS_I(inode)->i_current_depth = 1;
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 4f450e573312..3f99ab288695 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1920,7 +1920,9 @@ static int f2fs_write_node_pages(struct address_space *mapping,
1920 f2fs_balance_fs_bg(sbi); 1920 f2fs_balance_fs_bg(sbi);
1921 1921
1922 /* collect a number of dirty node pages and write together */ 1922 /* collect a number of dirty node pages and write together */
1923 if (get_pages(sbi, F2FS_DIRTY_NODES) < nr_pages_to_skip(sbi, NODE)) 1923 if (wbc->sync_mode != WB_SYNC_ALL &&
1924 get_pages(sbi, F2FS_DIRTY_NODES) <
1925 nr_pages_to_skip(sbi, NODE))
1924 goto skip_write; 1926 goto skip_write;
1925 1927
1926 if (wbc->sync_mode == WB_SYNC_ALL) 1928 if (wbc->sync_mode == WB_SYNC_ALL)
@@ -1959,7 +1961,7 @@ static int f2fs_set_node_page_dirty(struct page *page)
1959 if (!PageDirty(page)) { 1961 if (!PageDirty(page)) {
1960 __set_page_dirty_nobuffers(page); 1962 __set_page_dirty_nobuffers(page);
1961 inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES); 1963 inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES);
1962 SetPagePrivate(page); 1964 f2fs_set_page_private(page, 0);
1963 f2fs_trace_pid(page); 1965 f2fs_trace_pid(page);
1964 return 1; 1966 return 1;
1965 } 1967 }
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 9b79056d705d..aa7fe79b62b2 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -191,8 +191,7 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page)
191 191
192 f2fs_trace_pid(page); 192 f2fs_trace_pid(page);
193 193
194 set_page_private(page, (unsigned long)ATOMIC_WRITTEN_PAGE); 194 f2fs_set_page_private(page, (unsigned long)ATOMIC_WRITTEN_PAGE);
195 SetPagePrivate(page);
196 195
197 new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS); 196 new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS);
198 197
@@ -215,7 +214,8 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page)
215} 214}
216 215
217static int __revoke_inmem_pages(struct inode *inode, 216static int __revoke_inmem_pages(struct inode *inode,
218 struct list_head *head, bool drop, bool recover) 217 struct list_head *head, bool drop, bool recover,
218 bool trylock)
219{ 219{
220 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 220 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
221 struct inmem_pages *cur, *tmp; 221 struct inmem_pages *cur, *tmp;
@@ -227,7 +227,16 @@ static int __revoke_inmem_pages(struct inode *inode,
227 if (drop) 227 if (drop)
228 trace_f2fs_commit_inmem_page(page, INMEM_DROP); 228 trace_f2fs_commit_inmem_page(page, INMEM_DROP);
229 229
230 lock_page(page); 230 if (trylock) {
231 /*
232 * to avoid deadlock in between page lock and
233 * inmem_lock.
234 */
235 if (!trylock_page(page))
236 continue;
237 } else {
238 lock_page(page);
239 }
231 240
232 f2fs_wait_on_page_writeback(page, DATA, true, true); 241 f2fs_wait_on_page_writeback(page, DATA, true, true);
233 242
@@ -270,8 +279,7 @@ next:
270 ClearPageUptodate(page); 279 ClearPageUptodate(page);
271 clear_cold_data(page); 280 clear_cold_data(page);
272 } 281 }
273 set_page_private(page, 0); 282 f2fs_clear_page_private(page);
274 ClearPagePrivate(page);
275 f2fs_put_page(page, 1); 283 f2fs_put_page(page, 1);
276 284
277 list_del(&cur->list); 285 list_del(&cur->list);
@@ -318,13 +326,19 @@ void f2fs_drop_inmem_pages(struct inode *inode)
318 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 326 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
319 struct f2fs_inode_info *fi = F2FS_I(inode); 327 struct f2fs_inode_info *fi = F2FS_I(inode);
320 328
321 mutex_lock(&fi->inmem_lock); 329 while (!list_empty(&fi->inmem_pages)) {
322 __revoke_inmem_pages(inode, &fi->inmem_pages, true, false); 330 mutex_lock(&fi->inmem_lock);
323 spin_lock(&sbi->inode_lock[ATOMIC_FILE]); 331 __revoke_inmem_pages(inode, &fi->inmem_pages,
324 if (!list_empty(&fi->inmem_ilist)) 332 true, false, true);
325 list_del_init(&fi->inmem_ilist); 333
326 spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); 334 if (list_empty(&fi->inmem_pages)) {
327 mutex_unlock(&fi->inmem_lock); 335 spin_lock(&sbi->inode_lock[ATOMIC_FILE]);
336 if (!list_empty(&fi->inmem_ilist))
337 list_del_init(&fi->inmem_ilist);
338 spin_unlock(&sbi->inode_lock[ATOMIC_FILE]);
339 }
340 mutex_unlock(&fi->inmem_lock);
341 }
328 342
329 clear_inode_flag(inode, FI_ATOMIC_FILE); 343 clear_inode_flag(inode, FI_ATOMIC_FILE);
330 fi->i_gc_failures[GC_FAILURE_ATOMIC] = 0; 344 fi->i_gc_failures[GC_FAILURE_ATOMIC] = 0;
@@ -354,8 +368,7 @@ void f2fs_drop_inmem_page(struct inode *inode, struct page *page)
354 kmem_cache_free(inmem_entry_slab, cur); 368 kmem_cache_free(inmem_entry_slab, cur);
355 369
356 ClearPageUptodate(page); 370 ClearPageUptodate(page);
357 set_page_private(page, 0); 371 f2fs_clear_page_private(page);
358 ClearPagePrivate(page);
359 f2fs_put_page(page, 0); 372 f2fs_put_page(page, 0);
360 373
361 trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE); 374 trace_f2fs_commit_inmem_page(page, INMEM_INVALIDATE);
@@ -429,12 +442,15 @@ retry:
429 * recovery or rewrite & commit last transaction. For other 442 * recovery or rewrite & commit last transaction. For other
430 * error number, revoking was done by filesystem itself. 443 * error number, revoking was done by filesystem itself.
431 */ 444 */
432 err = __revoke_inmem_pages(inode, &revoke_list, false, true); 445 err = __revoke_inmem_pages(inode, &revoke_list,
446 false, true, false);
433 447
434 /* drop all uncommitted pages */ 448 /* drop all uncommitted pages */
435 __revoke_inmem_pages(inode, &fi->inmem_pages, true, false); 449 __revoke_inmem_pages(inode, &fi->inmem_pages,
450 true, false, false);
436 } else { 451 } else {
437 __revoke_inmem_pages(inode, &revoke_list, false, false); 452 __revoke_inmem_pages(inode, &revoke_list,
453 false, false, false);
438 } 454 }
439 455
440 return err; 456 return err;
@@ -542,9 +558,13 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
542static int __submit_flush_wait(struct f2fs_sb_info *sbi, 558static int __submit_flush_wait(struct f2fs_sb_info *sbi,
543 struct block_device *bdev) 559 struct block_device *bdev)
544{ 560{
545 struct bio *bio = f2fs_bio_alloc(sbi, 0, true); 561 struct bio *bio;
546 int ret; 562 int ret;
547 563
564 bio = f2fs_bio_alloc(sbi, 0, false);
565 if (!bio)
566 return -ENOMEM;
567
548 bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH; 568 bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH;
549 bio_set_dev(bio, bdev); 569 bio_set_dev(bio, bdev);
550 ret = submit_bio_wait(bio); 570 ret = submit_bio_wait(bio);
@@ -868,6 +888,9 @@ int f2fs_disable_cp_again(struct f2fs_sb_info *sbi)
868 888
869 if (holes[DATA] > ovp || holes[NODE] > ovp) 889 if (holes[DATA] > ovp || holes[NODE] > ovp)
870 return -EAGAIN; 890 return -EAGAIN;
891 if (is_sbi_flag_set(sbi, SBI_CP_DISABLED_QUICK) &&
892 dirty_segments(sbi) > overprovision_segments(sbi))
893 return -EAGAIN;
871 return 0; 894 return 0;
872} 895}
873 896
@@ -1037,6 +1060,7 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,
1037 1060
1038 dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST; 1061 dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST;
1039 dpolicy->io_aware_gran = MAX_PLIST_NUM; 1062 dpolicy->io_aware_gran = MAX_PLIST_NUM;
1063 dpolicy->timeout = 0;
1040 1064
1041 if (discard_type == DPOLICY_BG) { 1065 if (discard_type == DPOLICY_BG) {
1042 dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME; 1066 dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME;
@@ -1059,6 +1083,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,
1059 } else if (discard_type == DPOLICY_UMOUNT) { 1083 } else if (discard_type == DPOLICY_UMOUNT) {
1060 dpolicy->max_requests = UINT_MAX; 1084 dpolicy->max_requests = UINT_MAX;
1061 dpolicy->io_aware = false; 1085 dpolicy->io_aware = false;
1086 /* we need to issue all to keep CP_TRIMMED_FLAG */
1087 dpolicy->granularity = 1;
1062 } 1088 }
1063} 1089}
1064 1090
@@ -1424,7 +1450,14 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,
1424 int i, issued = 0; 1450 int i, issued = 0;
1425 bool io_interrupted = false; 1451 bool io_interrupted = false;
1426 1452
1453 if (dpolicy->timeout != 0)
1454 f2fs_update_time(sbi, dpolicy->timeout);
1455
1427 for (i = MAX_PLIST_NUM - 1; i >= 0; i--) { 1456 for (i = MAX_PLIST_NUM - 1; i >= 0; i--) {
1457 if (dpolicy->timeout != 0 &&
1458 f2fs_time_over(sbi, dpolicy->timeout))
1459 break;
1460
1428 if (i + 1 < dpolicy->granularity) 1461 if (i + 1 < dpolicy->granularity)
1429 break; 1462 break;
1430 1463
@@ -1611,7 +1644,7 @@ void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi)
1611} 1644}
1612 1645
1613/* This comes from f2fs_put_super */ 1646/* This comes from f2fs_put_super */
1614bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi) 1647bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi)
1615{ 1648{
1616 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1649 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
1617 struct discard_policy dpolicy; 1650 struct discard_policy dpolicy;
@@ -1619,6 +1652,7 @@ bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi)
1619 1652
1620 __init_discard_policy(sbi, &dpolicy, DPOLICY_UMOUNT, 1653 __init_discard_policy(sbi, &dpolicy, DPOLICY_UMOUNT,
1621 dcc->discard_granularity); 1654 dcc->discard_granularity);
1655 dpolicy.timeout = UMOUNT_DISCARD_TIMEOUT;
1622 __issue_discard_cmd(sbi, &dpolicy); 1656 __issue_discard_cmd(sbi, &dpolicy);
1623 dropped = __drop_discard_cmd(sbi); 1657 dropped = __drop_discard_cmd(sbi);
1624 1658
@@ -3164,10 +3198,10 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
3164 stat_inc_inplace_blocks(fio->sbi); 3198 stat_inc_inplace_blocks(fio->sbi);
3165 3199
3166 err = f2fs_submit_page_bio(fio); 3200 err = f2fs_submit_page_bio(fio);
3167 if (!err) 3201 if (!err) {
3168 update_device_state(fio); 3202 update_device_state(fio);
3169 3203 f2fs_update_iostat(fio->sbi, fio->io_type, F2FS_BLKSIZE);
3170 f2fs_update_iostat(fio->sbi, fio->io_type, F2FS_BLKSIZE); 3204 }
3171 3205
3172 return err; 3206 return err;
3173} 3207}
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index a77f76f528b6..5c7ed0442d6e 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -865,7 +865,7 @@ static inline void wake_up_discard_thread(struct f2fs_sb_info *sbi, bool force)
865 } 865 }
866 } 866 }
867 mutex_unlock(&dcc->cmd_lock); 867 mutex_unlock(&dcc->cmd_lock);
868 if (!wakeup) 868 if (!wakeup || !is_idle(sbi, DISCARD_TIME))
869 return; 869 return;
870wake_up: 870wake_up:
871 dcc->discard_wake = 1; 871 dcc->discard_wake = 1;
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index d1ccc52afc93..f2aaa2cc6b3e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -269,7 +269,7 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
269 if (!qname) { 269 if (!qname) {
270 f2fs_msg(sb, KERN_ERR, 270 f2fs_msg(sb, KERN_ERR,
271 "Not enough memory for storing quotafile name"); 271 "Not enough memory for storing quotafile name");
272 return -EINVAL; 272 return -ENOMEM;
273 } 273 }
274 if (F2FS_OPTION(sbi).s_qf_names[qtype]) { 274 if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
275 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0) 275 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
@@ -586,7 +586,7 @@ static int parse_options(struct super_block *sb, char *options)
586 case Opt_io_size_bits: 586 case Opt_io_size_bits:
587 if (args->from && match_int(args, &arg)) 587 if (args->from && match_int(args, &arg))
588 return -EINVAL; 588 return -EINVAL;
589 if (arg > __ilog2_u32(BIO_MAX_PAGES)) { 589 if (arg <= 0 || arg > __ilog2_u32(BIO_MAX_PAGES)) {
590 f2fs_msg(sb, KERN_WARNING, 590 f2fs_msg(sb, KERN_WARNING,
591 "Not support %d, larger than %d", 591 "Not support %d, larger than %d",
592 1 << arg, BIO_MAX_PAGES); 592 1 << arg, BIO_MAX_PAGES);
@@ -821,6 +821,8 @@ static int parse_options(struct super_block *sb, char *options)
821 } 821 }
822 822
823 if (test_opt(sbi, INLINE_XATTR_SIZE)) { 823 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
824 int min_size, max_size;
825
824 if (!f2fs_sb_has_extra_attr(sbi) || 826 if (!f2fs_sb_has_extra_attr(sbi) ||
825 !f2fs_sb_has_flexible_inline_xattr(sbi)) { 827 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
826 f2fs_msg(sb, KERN_ERR, 828 f2fs_msg(sb, KERN_ERR,
@@ -834,14 +836,15 @@ static int parse_options(struct super_block *sb, char *options)
834 "set with inline_xattr option"); 836 "set with inline_xattr option");
835 return -EINVAL; 837 return -EINVAL;
836 } 838 }
837 if (!F2FS_OPTION(sbi).inline_xattr_size || 839
838 F2FS_OPTION(sbi).inline_xattr_size >= 840 min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32);
839 DEF_ADDRS_PER_INODE - 841 max_size = MAX_INLINE_XATTR_SIZE;
840 F2FS_TOTAL_EXTRA_ATTR_SIZE - 842
841 DEF_INLINE_RESERVED_SIZE - 843 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
842 DEF_MIN_INLINE_SIZE) { 844 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
843 f2fs_msg(sb, KERN_ERR, 845 f2fs_msg(sb, KERN_ERR,
844 "inline xattr size is out of range"); 846 "inline xattr size is out of range: %d ~ %d",
847 min_size, max_size);
845 return -EINVAL; 848 return -EINVAL;
846 } 849 }
847 } 850 }
@@ -915,6 +918,10 @@ static int f2fs_drop_inode(struct inode *inode)
915 sb_start_intwrite(inode->i_sb); 918 sb_start_intwrite(inode->i_sb);
916 f2fs_i_size_write(inode, 0); 919 f2fs_i_size_write(inode, 0);
917 920
921 f2fs_submit_merged_write_cond(F2FS_I_SB(inode),
922 inode, NULL, 0, DATA);
923 truncate_inode_pages_final(inode->i_mapping);
924
918 if (F2FS_HAS_BLOCKS(inode)) 925 if (F2FS_HAS_BLOCKS(inode))
919 f2fs_truncate(inode); 926 f2fs_truncate(inode);
920 927
@@ -1048,7 +1055,7 @@ static void f2fs_put_super(struct super_block *sb)
1048 } 1055 }
1049 1056
1050 /* be sure to wait for any on-going discard commands */ 1057 /* be sure to wait for any on-going discard commands */
1051 dropped = f2fs_wait_discard_bios(sbi); 1058 dropped = f2fs_issue_discard_timeout(sbi);
1052 1059
1053 if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) && 1060 if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) &&
1054 !sbi->discard_blks && !dropped) { 1061 !sbi->discard_blks && !dropped) {
@@ -1075,7 +1082,10 @@ static void f2fs_put_super(struct super_block *sb)
1075 f2fs_bug_on(sbi, sbi->fsync_node_num); 1082 f2fs_bug_on(sbi, sbi->fsync_node_num);
1076 1083
1077 iput(sbi->node_inode); 1084 iput(sbi->node_inode);
1085 sbi->node_inode = NULL;
1086
1078 iput(sbi->meta_inode); 1087 iput(sbi->meta_inode);
1088 sbi->meta_inode = NULL;
1079 1089
1080 /* 1090 /*
1081 * iput() can update stat information, if f2fs_write_checkpoint() 1091 * iput() can update stat information, if f2fs_write_checkpoint()
@@ -1455,9 +1465,16 @@ static int f2fs_enable_quotas(struct super_block *sb);
1455 1465
1456static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) 1466static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
1457{ 1467{
1468 unsigned int s_flags = sbi->sb->s_flags;
1458 struct cp_control cpc; 1469 struct cp_control cpc;
1459 int err; 1470 int err = 0;
1471 int ret;
1460 1472
1473 if (s_flags & SB_RDONLY) {
1474 f2fs_msg(sbi->sb, KERN_ERR,
1475 "checkpoint=disable on readonly fs");
1476 return -EINVAL;
1477 }
1461 sbi->sb->s_flags |= SB_ACTIVE; 1478 sbi->sb->s_flags |= SB_ACTIVE;
1462 1479
1463 f2fs_update_time(sbi, DISABLE_TIME); 1480 f2fs_update_time(sbi, DISABLE_TIME);
@@ -1465,18 +1482,24 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
1465 while (!f2fs_time_over(sbi, DISABLE_TIME)) { 1482 while (!f2fs_time_over(sbi, DISABLE_TIME)) {
1466 mutex_lock(&sbi->gc_mutex); 1483 mutex_lock(&sbi->gc_mutex);
1467 err = f2fs_gc(sbi, true, false, NULL_SEGNO); 1484 err = f2fs_gc(sbi, true, false, NULL_SEGNO);
1468 if (err == -ENODATA) 1485 if (err == -ENODATA) {
1486 err = 0;
1469 break; 1487 break;
1488 }
1470 if (err && err != -EAGAIN) 1489 if (err && err != -EAGAIN)
1471 return err; 1490 break;
1472 } 1491 }
1473 1492
1474 err = sync_filesystem(sbi->sb); 1493 ret = sync_filesystem(sbi->sb);
1475 if (err) 1494 if (ret || err) {
1476 return err; 1495 err = ret ? ret: err;
1496 goto restore_flag;
1497 }
1477 1498
1478 if (f2fs_disable_cp_again(sbi)) 1499 if (f2fs_disable_cp_again(sbi)) {
1479 return -EAGAIN; 1500 err = -EAGAIN;
1501 goto restore_flag;
1502 }
1480 1503
1481 mutex_lock(&sbi->gc_mutex); 1504 mutex_lock(&sbi->gc_mutex);
1482 cpc.reason = CP_PAUSE; 1505 cpc.reason = CP_PAUSE;
@@ -1485,7 +1508,9 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
1485 1508
1486 sbi->unusable_block_count = 0; 1509 sbi->unusable_block_count = 0;
1487 mutex_unlock(&sbi->gc_mutex); 1510 mutex_unlock(&sbi->gc_mutex);
1488 return 0; 1511restore_flag:
1512 sbi->sb->s_flags = s_flags; /* Restore MS_RDONLY status */
1513 return err;
1489} 1514}
1490 1515
1491static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) 1516static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
@@ -2023,6 +2048,12 @@ void f2fs_quota_off_umount(struct super_block *sb)
2023 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); 2048 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
2024 } 2049 }
2025 } 2050 }
2051 /*
2052 * In case of checkpoint=disable, we must flush quota blocks.
2053 * This can cause NULL exception for node_inode in end_io, since
2054 * put_super already dropped it.
2055 */
2056 sync_filesystem(sb);
2026} 2057}
2027 2058
2028static void f2fs_truncate_quota_inode_pages(struct super_block *sb) 2059static void f2fs_truncate_quota_inode_pages(struct super_block *sb)
@@ -2703,6 +2734,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
2703 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL; 2734 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL;
2704 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL; 2735 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL;
2705 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL; 2736 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL;
2737 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] =
2738 DEF_UMOUNT_DISCARD_TIMEOUT;
2706 clear_sbi_flag(sbi, SBI_NEED_FSCK); 2739 clear_sbi_flag(sbi, SBI_NEED_FSCK);
2707 2740
2708 for (i = 0; i < NR_COUNT_TYPE; i++) 2741 for (i = 0; i < NR_COUNT_TYPE; i++)
@@ -3022,10 +3055,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
3022 struct f2fs_super_block *raw_super; 3055 struct f2fs_super_block *raw_super;
3023 struct inode *root; 3056 struct inode *root;
3024 int err; 3057 int err;
3025 bool retry = true, need_fsck = false; 3058 bool skip_recovery = false, need_fsck = false;
3026 char *options = NULL; 3059 char *options = NULL;
3027 int recovery, i, valid_super_block; 3060 int recovery, i, valid_super_block;
3028 struct curseg_info *seg_i; 3061 struct curseg_info *seg_i;
3062 int retry_cnt = 1;
3029 3063
3030try_onemore: 3064try_onemore:
3031 err = -EINVAL; 3065 err = -EINVAL;
@@ -3097,7 +3131,6 @@ try_onemore:
3097 sb->s_maxbytes = sbi->max_file_blocks << 3131 sb->s_maxbytes = sbi->max_file_blocks <<
3098 le32_to_cpu(raw_super->log_blocksize); 3132 le32_to_cpu(raw_super->log_blocksize);
3099 sb->s_max_links = F2FS_LINK_MAX; 3133 sb->s_max_links = F2FS_LINK_MAX;
3100 get_random_bytes(&sbi->s_next_generation, sizeof(u32));
3101 3134
3102#ifdef CONFIG_QUOTA 3135#ifdef CONFIG_QUOTA
3103 sb->dq_op = &f2fs_quota_operations; 3136 sb->dq_op = &f2fs_quota_operations;
@@ -3200,6 +3233,10 @@ try_onemore:
3200 3233
3201 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG)) 3234 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
3202 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); 3235 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3236 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) {
3237 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
3238 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
3239 }
3203 3240
3204 /* Initialize device list */ 3241 /* Initialize device list */
3205 err = f2fs_scan_devices(sbi); 3242 err = f2fs_scan_devices(sbi);
@@ -3288,7 +3325,7 @@ try_onemore:
3288 sb->s_root = d_make_root(root); /* allocate root dentry */ 3325 sb->s_root = d_make_root(root); /* allocate root dentry */
3289 if (!sb->s_root) { 3326 if (!sb->s_root) {
3290 err = -ENOMEM; 3327 err = -ENOMEM;
3291 goto free_root_inode; 3328 goto free_node_inode;
3292 } 3329 }
3293 3330
3294 err = f2fs_register_sysfs(sbi); 3331 err = f2fs_register_sysfs(sbi);
@@ -3310,7 +3347,7 @@ try_onemore:
3310 goto free_meta; 3347 goto free_meta;
3311 3348
3312 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG))) 3349 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
3313 goto skip_recovery; 3350 goto reset_checkpoint;
3314 3351
3315 /* recover fsynced data */ 3352 /* recover fsynced data */
3316 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 3353 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
@@ -3327,11 +3364,13 @@ try_onemore:
3327 if (need_fsck) 3364 if (need_fsck)
3328 set_sbi_flag(sbi, SBI_NEED_FSCK); 3365 set_sbi_flag(sbi, SBI_NEED_FSCK);
3329 3366
3330 if (!retry) 3367 if (skip_recovery)
3331 goto skip_recovery; 3368 goto reset_checkpoint;
3332 3369
3333 err = f2fs_recover_fsync_data(sbi, false); 3370 err = f2fs_recover_fsync_data(sbi, false);
3334 if (err < 0) { 3371 if (err < 0) {
3372 if (err != -ENOMEM)
3373 skip_recovery = true;
3335 need_fsck = true; 3374 need_fsck = true;
3336 f2fs_msg(sb, KERN_ERR, 3375 f2fs_msg(sb, KERN_ERR,
3337 "Cannot recover all fsync data errno=%d", err); 3376 "Cannot recover all fsync data errno=%d", err);
@@ -3347,14 +3386,14 @@ try_onemore:
3347 goto free_meta; 3386 goto free_meta;
3348 } 3387 }
3349 } 3388 }
3350skip_recovery: 3389reset_checkpoint:
3351 /* f2fs_recover_fsync_data() cleared this already */ 3390 /* f2fs_recover_fsync_data() cleared this already */
3352 clear_sbi_flag(sbi, SBI_POR_DOING); 3391 clear_sbi_flag(sbi, SBI_POR_DOING);
3353 3392
3354 if (test_opt(sbi, DISABLE_CHECKPOINT)) { 3393 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
3355 err = f2fs_disable_checkpoint(sbi); 3394 err = f2fs_disable_checkpoint(sbi);
3356 if (err) 3395 if (err)
3357 goto free_meta; 3396 goto sync_free_meta;
3358 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) { 3397 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
3359 f2fs_enable_checkpoint(sbi); 3398 f2fs_enable_checkpoint(sbi);
3360 } 3399 }
@@ -3367,7 +3406,7 @@ skip_recovery:
3367 /* After POR, we can run background GC thread.*/ 3406 /* After POR, we can run background GC thread.*/
3368 err = f2fs_start_gc_thread(sbi); 3407 err = f2fs_start_gc_thread(sbi);
3369 if (err) 3408 if (err)
3370 goto free_meta; 3409 goto sync_free_meta;
3371 } 3410 }
3372 kvfree(options); 3411 kvfree(options);
3373 3412
@@ -3387,8 +3426,14 @@ skip_recovery:
3387 cur_cp_version(F2FS_CKPT(sbi))); 3426 cur_cp_version(F2FS_CKPT(sbi)));
3388 f2fs_update_time(sbi, CP_TIME); 3427 f2fs_update_time(sbi, CP_TIME);
3389 f2fs_update_time(sbi, REQ_TIME); 3428 f2fs_update_time(sbi, REQ_TIME);
3429 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
3390 return 0; 3430 return 0;
3391 3431
3432sync_free_meta:
3433 /* safe to flush all the data */
3434 sync_filesystem(sbi->sb);
3435 retry_cnt = 0;
3436
3392free_meta: 3437free_meta:
3393#ifdef CONFIG_QUOTA 3438#ifdef CONFIG_QUOTA
3394 f2fs_truncate_quota_inode_pages(sb); 3439 f2fs_truncate_quota_inode_pages(sb);
@@ -3402,6 +3447,8 @@ free_meta:
3402 * falls into an infinite loop in f2fs_sync_meta_pages(). 3447 * falls into an infinite loop in f2fs_sync_meta_pages().
3403 */ 3448 */
3404 truncate_inode_pages_final(META_MAPPING(sbi)); 3449 truncate_inode_pages_final(META_MAPPING(sbi));
3450 /* evict some inodes being cached by GC */
3451 evict_inodes(sb);
3405 f2fs_unregister_sysfs(sbi); 3452 f2fs_unregister_sysfs(sbi);
3406free_root_inode: 3453free_root_inode:
3407 dput(sb->s_root); 3454 dput(sb->s_root);
@@ -3410,6 +3457,7 @@ free_node_inode:
3410 f2fs_release_ino_entry(sbi, true); 3457 f2fs_release_ino_entry(sbi, true);
3411 truncate_inode_pages_final(NODE_MAPPING(sbi)); 3458 truncate_inode_pages_final(NODE_MAPPING(sbi));
3412 iput(sbi->node_inode); 3459 iput(sbi->node_inode);
3460 sbi->node_inode = NULL;
3413free_stats: 3461free_stats:
3414 f2fs_destroy_stats(sbi); 3462 f2fs_destroy_stats(sbi);
3415free_nm: 3463free_nm:
@@ -3422,6 +3470,7 @@ free_devices:
3422free_meta_inode: 3470free_meta_inode:
3423 make_bad_inode(sbi->meta_inode); 3471 make_bad_inode(sbi->meta_inode);
3424 iput(sbi->meta_inode); 3472 iput(sbi->meta_inode);
3473 sbi->meta_inode = NULL;
3425free_io_dummy: 3474free_io_dummy:
3426 mempool_destroy(sbi->write_io_dummy); 3475 mempool_destroy(sbi->write_io_dummy);
3427free_percpu: 3476free_percpu:
@@ -3443,8 +3492,8 @@ free_sbi:
3443 kvfree(sbi); 3492 kvfree(sbi);
3444 3493
3445 /* give only one another chance */ 3494 /* give only one another chance */
3446 if (retry) { 3495 if (retry_cnt > 0 && skip_recovery) {
3447 retry = false; 3496 retry_cnt--;
3448 shrink_dcache_sb(sb); 3497 shrink_dcache_sb(sb);
3449 goto try_onemore; 3498 goto try_onemore;
3450 } 3499 }
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 70da6801c86f..729f46a3c9ee 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -222,6 +222,8 @@ out:
222#ifdef CONFIG_F2FS_FAULT_INJECTION 222#ifdef CONFIG_F2FS_FAULT_INJECTION
223 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX)) 223 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
224 return -EINVAL; 224 return -EINVAL;
225 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
226 return -EINVAL;
225#endif 227#endif
226 if (a->struct_type == RESERVED_BLOCKS) { 228 if (a->struct_type == RESERVED_BLOCKS) {
227 spin_lock(&sbi->stat_lock); 229 spin_lock(&sbi->stat_lock);
@@ -278,10 +280,16 @@ out:
278 return count; 280 return count;
279 } 281 }
280 282
281 *ui = t;
282 283
283 if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0) 284 if (!strcmp(a->attr.name, "iostat_enable")) {
284 f2fs_reset_iostat(sbi); 285 sbi->iostat_enable = !!t;
286 if (!sbi->iostat_enable)
287 f2fs_reset_iostat(sbi);
288 return count;
289 }
290
291 *ui = (unsigned int)t;
292
285 return count; 293 return count;
286} 294}
287 295
@@ -418,6 +426,8 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
418F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval, 426F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
419 interval_time[DISCARD_TIME]); 427 interval_time[DISCARD_TIME]);
420F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]); 428F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
429F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
430 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
421F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable); 431F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
422F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra); 432F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
423F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold); 433F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
@@ -475,6 +485,7 @@ static struct attribute *f2fs_attrs[] = {
475 ATTR_LIST(idle_interval), 485 ATTR_LIST(idle_interval),
476 ATTR_LIST(discard_idle_interval), 486 ATTR_LIST(discard_idle_interval),
477 ATTR_LIST(gc_idle_interval), 487 ATTR_LIST(gc_idle_interval),
488 ATTR_LIST(umount_discard_timeout),
478 ATTR_LIST(iostat_enable), 489 ATTR_LIST(iostat_enable),
479 ATTR_LIST(readdir_ra), 490 ATTR_LIST(readdir_ra),
480 ATTR_LIST(gc_pin_file_thresh), 491 ATTR_LIST(gc_pin_file_thresh),
diff --git a/fs/f2fs/trace.c b/fs/f2fs/trace.c
index ce2a5eb210b6..d0ab533a9ce8 100644
--- a/fs/f2fs/trace.c
+++ b/fs/f2fs/trace.c
@@ -14,7 +14,7 @@
14#include "trace.h" 14#include "trace.h"
15 15
16static RADIX_TREE(pids, GFP_ATOMIC); 16static RADIX_TREE(pids, GFP_ATOMIC);
17static struct mutex pids_lock; 17static spinlock_t pids_lock;
18static struct last_io_info last_io; 18static struct last_io_info last_io;
19 19
20static inline void __print_last_io(void) 20static inline void __print_last_io(void)
@@ -58,23 +58,29 @@ void f2fs_trace_pid(struct page *page)
58 58
59 set_page_private(page, (unsigned long)pid); 59 set_page_private(page, (unsigned long)pid);
60 60
61retry:
61 if (radix_tree_preload(GFP_NOFS)) 62 if (radix_tree_preload(GFP_NOFS))
62 return; 63 return;
63 64
64 mutex_lock(&pids_lock); 65 spin_lock(&pids_lock);
65 p = radix_tree_lookup(&pids, pid); 66 p = radix_tree_lookup(&pids, pid);
66 if (p == current) 67 if (p == current)
67 goto out; 68 goto out;
68 if (p) 69 if (p)
69 radix_tree_delete(&pids, pid); 70 radix_tree_delete(&pids, pid);
70 71
71 f2fs_radix_tree_insert(&pids, pid, current); 72 if (radix_tree_insert(&pids, pid, current)) {
73 spin_unlock(&pids_lock);
74 radix_tree_preload_end();
75 cond_resched();
76 goto retry;
77 }
72 78
73 trace_printk("%3x:%3x %4x %-16s\n", 79 trace_printk("%3x:%3x %4x %-16s\n",
74 MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), 80 MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
75 pid, current->comm); 81 pid, current->comm);
76out: 82out:
77 mutex_unlock(&pids_lock); 83 spin_unlock(&pids_lock);
78 radix_tree_preload_end(); 84 radix_tree_preload_end();
79} 85}
80 86
@@ -119,7 +125,7 @@ void f2fs_trace_ios(struct f2fs_io_info *fio, int flush)
119 125
120void f2fs_build_trace_ios(void) 126void f2fs_build_trace_ios(void)
121{ 127{
122 mutex_init(&pids_lock); 128 spin_lock_init(&pids_lock);
123} 129}
124 130
125#define PIDVEC_SIZE 128 131#define PIDVEC_SIZE 128
@@ -147,7 +153,7 @@ void f2fs_destroy_trace_ios(void)
147 pid_t next_pid = 0; 153 pid_t next_pid = 0;
148 unsigned int found; 154 unsigned int found;
149 155
150 mutex_lock(&pids_lock); 156 spin_lock(&pids_lock);
151 while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) { 157 while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) {
152 unsigned idx; 158 unsigned idx;
153 159
@@ -155,5 +161,5 @@ void f2fs_destroy_trace_ios(void)
155 for (idx = 0; idx < found; idx++) 161 for (idx = 0; idx < found; idx++)
156 radix_tree_delete(&pids, pid[idx]); 162 radix_tree_delete(&pids, pid[idx]);
157 } 163 }
158 mutex_unlock(&pids_lock); 164 spin_unlock(&pids_lock);
159} 165}
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index 18d5ffbc5e8c..848a785abe25 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -224,11 +224,11 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode,
224{ 224{
225 struct f2fs_xattr_entry *entry; 225 struct f2fs_xattr_entry *entry;
226 unsigned int inline_size = inline_xattr_size(inode); 226 unsigned int inline_size = inline_xattr_size(inode);
227 void *max_addr = base_addr + inline_size;
227 228
228 list_for_each_xattr(entry, base_addr) { 229 list_for_each_xattr(entry, base_addr) {
229 if ((void *)entry + sizeof(__u32) > base_addr + inline_size || 230 if ((void *)entry + sizeof(__u32) > max_addr ||
230 (void *)XATTR_NEXT_ENTRY(entry) + sizeof(__u32) > 231 (void *)XATTR_NEXT_ENTRY(entry) > max_addr) {
231 base_addr + inline_size) {
232 *last_addr = entry; 232 *last_addr = entry;
233 return NULL; 233 return NULL;
234 } 234 }
@@ -239,6 +239,13 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode,
239 if (!memcmp(entry->e_name, name, len)) 239 if (!memcmp(entry->e_name, name, len))
240 break; 240 break;
241 } 241 }
242
243 /* inline xattr header or entry across max inline xattr size */
244 if (IS_XATTR_LAST_ENTRY(entry) &&
245 (void *)entry + sizeof(__u32) > max_addr) {
246 *last_addr = entry;
247 return NULL;
248 }
242 return entry; 249 return entry;
243} 250}
244 251
@@ -340,7 +347,7 @@ check:
340 *base_addr = txattr_addr; 347 *base_addr = txattr_addr;
341 return 0; 348 return 0;
342out: 349out:
343 kzfree(txattr_addr); 350 kvfree(txattr_addr);
344 return err; 351 return err;
345} 352}
346 353
@@ -383,7 +390,7 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
383 *base_addr = txattr_addr; 390 *base_addr = txattr_addr;
384 return 0; 391 return 0;
385fail: 392fail:
386 kzfree(txattr_addr); 393 kvfree(txattr_addr);
387 return err; 394 return err;
388} 395}
389 396
@@ -510,7 +517,7 @@ int f2fs_getxattr(struct inode *inode, int index, const char *name,
510 } 517 }
511 error = size; 518 error = size;
512out: 519out:
513 kzfree(base_addr); 520 kvfree(base_addr);
514 return error; 521 return error;
515} 522}
516 523
@@ -538,7 +545,7 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
538 if (!handler || (handler->list && !handler->list(dentry))) 545 if (!handler || (handler->list && !handler->list(dentry)))
539 continue; 546 continue;
540 547
541 prefix = handler->prefix ?: handler->name; 548 prefix = xattr_prefix(handler);
542 prefix_len = strlen(prefix); 549 prefix_len = strlen(prefix);
543 size = prefix_len + entry->e_name_len + 1; 550 size = prefix_len + entry->e_name_len + 1;
544 if (buffer) { 551 if (buffer) {
@@ -556,7 +563,7 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
556 } 563 }
557 error = buffer_size - rest; 564 error = buffer_size - rest;
558cleanup: 565cleanup:
559 kzfree(base_addr); 566 kvfree(base_addr);
560 return error; 567 return error;
561} 568}
562 569
@@ -687,7 +694,7 @@ static int __f2fs_setxattr(struct inode *inode, int index,
687 if (!error && S_ISDIR(inode->i_mode)) 694 if (!error && S_ISDIR(inode->i_mode))
688 set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_CP); 695 set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_CP);
689exit: 696exit:
690 kzfree(base_addr); 697 kvfree(base_addr);
691 return error; 698 return error;
692} 699}
693 700
diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h
index 67db134da0f5..9172ee082ca8 100644
--- a/fs/f2fs/xattr.h
+++ b/fs/f2fs/xattr.h
@@ -78,6 +78,12 @@ struct f2fs_xattr_entry {
78 sizeof(struct f2fs_xattr_header) - \ 78 sizeof(struct f2fs_xattr_header) - \
79 sizeof(struct f2fs_xattr_entry)) 79 sizeof(struct f2fs_xattr_entry))
80 80
81#define MAX_INLINE_XATTR_SIZE \
82 (DEF_ADDRS_PER_INODE - \
83 F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \
84 DEF_INLINE_RESERVED_SIZE - \
85 MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
86
81/* 87/*
82 * On-disk structure of f2fs_xattr 88 * On-disk structure of f2fs_xattr
83 * We use inline xattrs space + 1 block for xattr. 89 * We use inline xattrs space + 1 block for xattr.
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/lockd/host.c b/fs/lockd/host.c
index 93fb7cf0b92b..f0b5c987d6ae 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -290,12 +290,11 @@ void nlmclnt_release_host(struct nlm_host *host)
290 290
291 WARN_ON_ONCE(host->h_server); 291 WARN_ON_ONCE(host->h_server);
292 292
293 if (refcount_dec_and_test(&host->h_count)) { 293 if (refcount_dec_and_mutex_lock(&host->h_count, &nlm_host_mutex)) {
294 WARN_ON_ONCE(!list_empty(&host->h_lockowners)); 294 WARN_ON_ONCE(!list_empty(&host->h_lockowners));
295 WARN_ON_ONCE(!list_empty(&host->h_granted)); 295 WARN_ON_ONCE(!list_empty(&host->h_granted));
296 WARN_ON_ONCE(!list_empty(&host->h_reclaim)); 296 WARN_ON_ONCE(!list_empty(&host->h_reclaim));
297 297
298 mutex_lock(&nlm_host_mutex);
299 nlm_destroy_host_locked(host); 298 nlm_destroy_host_locked(host);
300 mutex_unlock(&nlm_host_mutex); 299 mutex_unlock(&nlm_host_mutex);
301 } 300 }
diff --git a/fs/locks.c b/fs/locks.c
index eaa1cfaf73b0..71d0c6c2aac5 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1160,6 +1160,11 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
1160 */ 1160 */
1161 error = -EDEADLK; 1161 error = -EDEADLK;
1162 spin_lock(&blocked_lock_lock); 1162 spin_lock(&blocked_lock_lock);
1163 /*
1164 * Ensure that we don't find any locks blocked on this
1165 * request during deadlock detection.
1166 */
1167 __locks_wake_up_blocks(request);
1163 if (likely(!posix_locks_deadlock(request, fl))) { 1168 if (likely(!posix_locks_deadlock(request, fl))) {
1164 error = FILE_LOCK_DEFERRED; 1169 error = FILE_LOCK_DEFERRED;
1165 __locks_insert_block(fl, request, 1170 __locks_insert_block(fl, request,
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index fb1cf1a4bda2..90d71fda65ce 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -453,7 +453,7 @@ void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
453 case XPRT_TRANSPORT_RDMA: 453 case XPRT_TRANSPORT_RDMA:
454 if (retrans == NFS_UNSPEC_RETRANS) 454 if (retrans == NFS_UNSPEC_RETRANS)
455 to->to_retries = NFS_DEF_TCP_RETRANS; 455 to->to_retries = NFS_DEF_TCP_RETRANS;
456 if (timeo == NFS_UNSPEC_TIMEO || to->to_retries == 0) 456 if (timeo == NFS_UNSPEC_TIMEO || to->to_initval == 0)
457 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; 457 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
458 if (to->to_initval > NFS_MAX_TCP_TIMEOUT) 458 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
459 to->to_initval = NFS_MAX_TCP_TIMEOUT; 459 to->to_initval = NFS_MAX_TCP_TIMEOUT;
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index f9264e1922a2..6673d4ff5a2a 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -1289,6 +1289,7 @@ static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
1289static int ff_layout_read_done_cb(struct rpc_task *task, 1289static int ff_layout_read_done_cb(struct rpc_task *task,
1290 struct nfs_pgio_header *hdr) 1290 struct nfs_pgio_header *hdr)
1291{ 1291{
1292 int new_idx = hdr->pgio_mirror_idx;
1292 int err; 1293 int err;
1293 1294
1294 trace_nfs4_pnfs_read(hdr, task->tk_status); 1295 trace_nfs4_pnfs_read(hdr, task->tk_status);
@@ -1307,7 +1308,7 @@ static int ff_layout_read_done_cb(struct rpc_task *task,
1307 case -NFS4ERR_RESET_TO_PNFS: 1308 case -NFS4ERR_RESET_TO_PNFS:
1308 if (ff_layout_choose_best_ds_for_read(hdr->lseg, 1309 if (ff_layout_choose_best_ds_for_read(hdr->lseg,
1309 hdr->pgio_mirror_idx + 1, 1310 hdr->pgio_mirror_idx + 1,
1310 &hdr->pgio_mirror_idx)) 1311 &new_idx))
1311 goto out_layouterror; 1312 goto out_layouterror;
1312 set_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags); 1313 set_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
1313 return task->tk_status; 1314 return task->tk_status;
@@ -1320,7 +1321,9 @@ static int ff_layout_read_done_cb(struct rpc_task *task,
1320 1321
1321 return 0; 1322 return 0;
1322out_layouterror: 1323out_layouterror:
1324 ff_layout_read_record_layoutstats_done(task, hdr);
1323 ff_layout_send_layouterror(hdr->lseg); 1325 ff_layout_send_layouterror(hdr->lseg);
1326 hdr->pgio_mirror_idx = new_idx;
1324out_eagain: 1327out_eagain:
1325 rpc_restart_call_prepare(task); 1328 rpc_restart_call_prepare(task);
1326 return -EAGAIN; 1329 return -EAGAIN;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 4dbb0ee23432..741ff8c9c6ed 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2933,7 +2933,8 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
2933 } 2933 }
2934 2934
2935out: 2935out:
2936 nfs4_sequence_free_slot(&opendata->o_res.seq_res); 2936 if (!opendata->cancelled)
2937 nfs4_sequence_free_slot(&opendata->o_res.seq_res);
2937 return ret; 2938 return ret;
2938} 2939}
2939 2940
@@ -6301,7 +6302,6 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
6301 p->arg.seqid = seqid; 6302 p->arg.seqid = seqid;
6302 p->res.seqid = seqid; 6303 p->res.seqid = seqid;
6303 p->lsp = lsp; 6304 p->lsp = lsp;
6304 refcount_inc(&lsp->ls_count);
6305 /* Ensure we don't close file until we're done freeing locks! */ 6305 /* Ensure we don't close file until we're done freeing locks! */
6306 p->ctx = get_nfs_open_context(ctx); 6306 p->ctx = get_nfs_open_context(ctx);
6307 p->l_ctx = nfs_get_lock_context(ctx); 6307 p->l_ctx = nfs_get_lock_context(ctx);
@@ -6526,7 +6526,6 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
6526 p->res.lock_seqid = p->arg.lock_seqid; 6526 p->res.lock_seqid = p->arg.lock_seqid;
6527 p->lsp = lsp; 6527 p->lsp = lsp;
6528 p->server = server; 6528 p->server = server;
6529 refcount_inc(&lsp->ls_count);
6530 p->ctx = get_nfs_open_context(ctx); 6529 p->ctx = get_nfs_open_context(ctx);
6531 locks_init_lock(&p->fl); 6530 locks_init_lock(&p->fl);
6532 locks_copy_lock(&p->fl, fl); 6531 locks_copy_lock(&p->fl, fl);
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 8247bd1634cb..7066cd7c7aff 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -1889,7 +1889,7 @@ lookup_again:
1889 atomic_read(&lo->plh_outstanding) != 0) { 1889 atomic_read(&lo->plh_outstanding) != 0) {
1890 spin_unlock(&ino->i_lock); 1890 spin_unlock(&ino->i_lock);
1891 lseg = ERR_PTR(wait_var_event_killable(&lo->plh_outstanding, 1891 lseg = ERR_PTR(wait_var_event_killable(&lo->plh_outstanding,
1892 atomic_read(&lo->plh_outstanding))); 1892 !atomic_read(&lo->plh_outstanding)));
1893 if (IS_ERR(lseg) || !list_empty(&lo->plh_segs)) 1893 if (IS_ERR(lseg) || !list_empty(&lo->plh_segs))
1894 goto out_put_layout_hdr; 1894 goto out_put_layout_hdr;
1895 pnfs_put_layout_hdr(lo); 1895 pnfs_put_layout_hdr(lo);
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/base.c b/fs/proc/base.c
index f5ebdd87afb2..ddef482f1334 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -3074,6 +3074,15 @@ static const struct file_operations proc_tgid_base_operations = {
3074 .llseek = generic_file_llseek, 3074 .llseek = generic_file_llseek,
3075}; 3075};
3076 3076
3077struct pid *tgid_pidfd_to_pid(const struct file *file)
3078{
3079 if (!d_is_dir(file->f_path.dentry) ||
3080 (file->f_op != &proc_tgid_base_operations))
3081 return ERR_PTR(-EBADF);
3082
3083 return proc_pid(file_inode(file));
3084}
3085
3077static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) 3086static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
3078{ 3087{
3079 return proc_pident_lookup(dir, dentry, 3088 return proc_pident_lookup(dir, dentry,
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/sysfs/mount.c b/fs/sysfs/mount.c
index 4cb21b558a85..1b56686ab178 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -71,9 +71,11 @@ static int sysfs_init_fs_context(struct fs_context *fc)
71 kfc->magic = SYSFS_MAGIC; 71 kfc->magic = SYSFS_MAGIC;
72 fc->fs_private = kfc; 72 fc->fs_private = kfc;
73 fc->ops = &sysfs_fs_context_ops; 73 fc->ops = &sysfs_fs_context_ops;
74 if (fc->user_ns) 74 if (netns) {
75 put_user_ns(fc->user_ns); 75 if (fc->user_ns)
76 fc->user_ns = get_user_ns(netns->user_ns); 76 put_user_ns(fc->user_ns);
77 fc->user_ns = get_user_ns(netns->user_ns);
78 }
77 fc->global = true; 79 fc->global = true;
78 return 0; 80 return 0;
79} 81}
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/fs/xfs/libxfs/xfs_dir2_leaf.c b/fs/xfs/libxfs/xfs_dir2_leaf.c
index 9a3767818c50..9c2a0a13ed61 100644
--- a/fs/xfs/libxfs/xfs_dir2_leaf.c
+++ b/fs/xfs/libxfs/xfs_dir2_leaf.c
@@ -563,43 +563,40 @@ xfs_dir3_leaf_find_entry(
563 */ 563 */
564int /* error */ 564int /* error */
565xfs_dir2_leaf_addname( 565xfs_dir2_leaf_addname(
566 xfs_da_args_t *args) /* operation arguments */ 566 struct xfs_da_args *args) /* operation arguments */
567{ 567{
568 struct xfs_dir3_icleaf_hdr leafhdr;
569 struct xfs_trans *tp = args->trans;
568 __be16 *bestsp; /* freespace table in leaf */ 570 __be16 *bestsp; /* freespace table in leaf */
569 int compact; /* need to compact leaves */ 571 __be16 *tagp; /* end of data entry */
570 xfs_dir2_data_hdr_t *hdr; /* data block header */
571 struct xfs_buf *dbp; /* data block buffer */ 572 struct xfs_buf *dbp; /* data block buffer */
572 xfs_dir2_data_entry_t *dep; /* data block entry */ 573 struct xfs_buf *lbp; /* leaf's buffer */
573 xfs_inode_t *dp; /* incore directory inode */ 574 struct xfs_dir2_leaf *leaf; /* leaf structure */
574 xfs_dir2_data_unused_t *dup; /* data unused entry */ 575 struct xfs_inode *dp = args->dp; /* incore directory inode */
576 struct xfs_dir2_data_hdr *hdr; /* data block header */
577 struct xfs_dir2_data_entry *dep; /* data block entry */
578 struct xfs_dir2_leaf_entry *lep; /* leaf entry table pointer */
579 struct xfs_dir2_leaf_entry *ents;
580 struct xfs_dir2_data_unused *dup; /* data unused entry */
581 struct xfs_dir2_leaf_tail *ltp; /* leaf tail pointer */
582 struct xfs_dir2_data_free *bf; /* bestfree table */
583 int compact; /* need to compact leaves */
575 int error; /* error return value */ 584 int error; /* error return value */
576 int grown; /* allocated new data block */ 585 int grown; /* allocated new data block */
577 int highstale; /* index of next stale leaf */ 586 int highstale = 0; /* index of next stale leaf */
578 int i; /* temporary, index */ 587 int i; /* temporary, index */
579 int index; /* leaf table position */ 588 int index; /* leaf table position */
580 struct xfs_buf *lbp; /* leaf's buffer */
581 xfs_dir2_leaf_t *leaf; /* leaf structure */
582 int length; /* length of new entry */ 589 int length; /* length of new entry */
583 xfs_dir2_leaf_entry_t *lep; /* leaf entry table pointer */
584 int lfloglow; /* low leaf logging index */ 590 int lfloglow; /* low leaf logging index */
585 int lfloghigh; /* high leaf logging index */ 591 int lfloghigh; /* high leaf logging index */
586 int lowstale; /* index of prev stale leaf */ 592 int lowstale = 0; /* index of prev stale leaf */
587 xfs_dir2_leaf_tail_t *ltp; /* leaf tail pointer */
588 int needbytes; /* leaf block bytes needed */ 593 int needbytes; /* leaf block bytes needed */
589 int needlog; /* need to log data header */ 594 int needlog; /* need to log data header */
590 int needscan; /* need to rescan data free */ 595 int needscan; /* need to rescan data free */
591 __be16 *tagp; /* end of data entry */
592 xfs_trans_t *tp; /* transaction pointer */
593 xfs_dir2_db_t use_block; /* data block number */ 596 xfs_dir2_db_t use_block; /* data block number */
594 struct xfs_dir2_data_free *bf; /* bestfree table */
595 struct xfs_dir2_leaf_entry *ents;
596 struct xfs_dir3_icleaf_hdr leafhdr;
597 597
598 trace_xfs_dir2_leaf_addname(args); 598 trace_xfs_dir2_leaf_addname(args);
599 599
600 dp = args->dp;
601 tp = args->trans;
602
603 error = xfs_dir3_leaf_read(tp, dp, args->geo->leafblk, -1, &lbp); 600 error = xfs_dir3_leaf_read(tp, dp, args->geo->leafblk, -1, &lbp);
604 if (error) 601 if (error)
605 return error; 602 return error;
diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
index 3b03703c5c3d..16731d2d684b 100644
--- a/fs/xfs/libxfs/xfs_dir2_node.c
+++ b/fs/xfs/libxfs/xfs_dir2_node.c
@@ -426,24 +426,22 @@ xfs_dir2_leaf_to_node(
426static int /* error */ 426static int /* error */
427xfs_dir2_leafn_add( 427xfs_dir2_leafn_add(
428 struct xfs_buf *bp, /* leaf buffer */ 428 struct xfs_buf *bp, /* leaf buffer */
429 xfs_da_args_t *args, /* operation arguments */ 429 struct xfs_da_args *args, /* operation arguments */
430 int index) /* insertion pt for new entry */ 430 int index) /* insertion pt for new entry */
431{ 431{
432 struct xfs_dir3_icleaf_hdr leafhdr;
433 struct xfs_inode *dp = args->dp;
434 struct xfs_dir2_leaf *leaf = bp->b_addr;
435 struct xfs_dir2_leaf_entry *lep;
436 struct xfs_dir2_leaf_entry *ents;
432 int compact; /* compacting stale leaves */ 437 int compact; /* compacting stale leaves */
433 xfs_inode_t *dp; /* incore directory inode */ 438 int highstale = 0; /* next stale entry */
434 int highstale; /* next stale entry */
435 xfs_dir2_leaf_t *leaf; /* leaf structure */
436 xfs_dir2_leaf_entry_t *lep; /* leaf entry */
437 int lfloghigh; /* high leaf entry logging */ 439 int lfloghigh; /* high leaf entry logging */
438 int lfloglow; /* low leaf entry logging */ 440 int lfloglow; /* low leaf entry logging */
439 int lowstale; /* previous stale entry */ 441 int lowstale = 0; /* previous stale entry */
440 struct xfs_dir3_icleaf_hdr leafhdr;
441 struct xfs_dir2_leaf_entry *ents;
442 442
443 trace_xfs_dir2_leafn_add(args, index); 443 trace_xfs_dir2_leafn_add(args, index);
444 444
445 dp = args->dp;
446 leaf = bp->b_addr;
447 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf); 445 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
448 ents = dp->d_ops->leaf_ents_p(leaf); 446 ents = dp->d_ops->leaf_ents_p(leaf);
449 447
diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild
new file mode 100644
index 000000000000..6f4536d70b8e
--- /dev/null
+++ b/include/asm-generic/Kbuild
@@ -0,0 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2#
3# asm headers that all architectures except um should have
4# (This file is not included when SRCARCH=um since UML borrows several
5# asm headers from the host architecutre.)
diff --git a/include/clocksource/arm_arch_timer.h b/include/clocksource/arm_arch_timer.h
index 349e5957c949..702967d996bb 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -74,6 +74,7 @@ enum arch_timer_spi_nr {
74struct arch_timer_kvm_info { 74struct arch_timer_kvm_info {
75 struct timecounter timecounter; 75 struct timecounter timecounter;
76 int virtual_irq; 76 int virtual_irq;
77 int physical_irq;
77}; 78};
78 79
79struct arch_timer_mem_frame { 80struct arch_timer_mem_frame {
diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h
index bb9acea61369..286d58efed5d 100644
--- a/include/drm/drm_fb_helper.h
+++ b/include/drm/drm_fb_helper.h
@@ -36,6 +36,7 @@ struct drm_fb_helper;
36#include <drm/drm_crtc.h> 36#include <drm/drm_crtc.h>
37#include <drm/drm_device.h> 37#include <drm/drm_device.h>
38#include <linux/kgdb.h> 38#include <linux/kgdb.h>
39#include <linux/vgaarb.h>
39 40
40enum mode_set_atomic { 41enum mode_set_atomic {
41 LEAVE_ATOMIC_MODE_SET, 42 LEAVE_ATOMIC_MODE_SET,
@@ -642,11 +643,18 @@ drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
642 int resource_id, 643 int resource_id,
643 const char *name) 644 const char *name)
644{ 645{
646 int ret = 0;
647
648 /*
649 * WARNING: Apparently we must kick fbdev drivers before vgacon,
650 * otherwise the vga fbdev driver falls over.
651 */
645#if IS_REACHABLE(CONFIG_FB) 652#if IS_REACHABLE(CONFIG_FB)
646 return remove_conflicting_pci_framebuffers(pdev, resource_id, name); 653 ret = remove_conflicting_pci_framebuffers(pdev, resource_id, name);
647#else
648 return 0;
649#endif 654#endif
655 if (ret == 0)
656 ret = vga_remove_vgacon(pdev);
657 return ret;
650} 658}
651 659
652#endif 660#endif
diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h
index 33771352dcd6..05a18dd265b5 100644
--- a/include/kvm/arm_arch_timer.h
+++ b/include/kvm/arm_arch_timer.h
@@ -22,7 +22,22 @@
22#include <linux/clocksource.h> 22#include <linux/clocksource.h>
23#include <linux/hrtimer.h> 23#include <linux/hrtimer.h>
24 24
25enum kvm_arch_timers {
26 TIMER_PTIMER,
27 TIMER_VTIMER,
28 NR_KVM_TIMERS
29};
30
31enum kvm_arch_timer_regs {
32 TIMER_REG_CNT,
33 TIMER_REG_CVAL,
34 TIMER_REG_TVAL,
35 TIMER_REG_CTL,
36};
37
25struct arch_timer_context { 38struct arch_timer_context {
39 struct kvm_vcpu *vcpu;
40
26 /* Registers: control register, timer value */ 41 /* Registers: control register, timer value */
27 u32 cnt_ctl; 42 u32 cnt_ctl;
28 u64 cnt_cval; 43 u64 cnt_cval;
@@ -30,30 +45,36 @@ struct arch_timer_context {
30 /* Timer IRQ */ 45 /* Timer IRQ */
31 struct kvm_irq_level irq; 46 struct kvm_irq_level irq;
32 47
48 /* Virtual offset */
49 u64 cntvoff;
50
51 /* Emulated Timer (may be unused) */
52 struct hrtimer hrtimer;
53
33 /* 54 /*
34 * We have multiple paths which can save/restore the timer state 55 * We have multiple paths which can save/restore the timer state onto
35 * onto the hardware, so we need some way of keeping track of 56 * the hardware, so we need some way of keeping track of where the
36 * where the latest state is. 57 * latest state is.
37 *
38 * loaded == true: State is loaded on the hardware registers.
39 * loaded == false: State is stored in memory.
40 */ 58 */
41 bool loaded; 59 bool loaded;
42 60
43 /* Virtual offset */ 61 /* Duplicated state from arch_timer.c for convenience */
44 u64 cntvoff; 62 u32 host_timer_irq;
63 u32 host_timer_irq_flags;
64};
65
66struct timer_map {
67 struct arch_timer_context *direct_vtimer;
68 struct arch_timer_context *direct_ptimer;
69 struct arch_timer_context *emul_ptimer;
45}; 70};
46 71
47struct arch_timer_cpu { 72struct arch_timer_cpu {
48 struct arch_timer_context vtimer; 73 struct arch_timer_context timers[NR_KVM_TIMERS];
49 struct arch_timer_context ptimer;
50 74
51 /* Background timer used when the guest is not running */ 75 /* Background timer used when the guest is not running */
52 struct hrtimer bg_timer; 76 struct hrtimer bg_timer;
53 77
54 /* Physical timer emulation */
55 struct hrtimer phys_timer;
56
57 /* Is the timer enabled */ 78 /* Is the timer enabled */
58 bool enabled; 79 bool enabled;
59}; 80};
@@ -76,9 +97,6 @@ int kvm_arm_timer_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
76 97
77bool kvm_timer_is_pending(struct kvm_vcpu *vcpu); 98bool kvm_timer_is_pending(struct kvm_vcpu *vcpu);
78 99
79void kvm_timer_schedule(struct kvm_vcpu *vcpu);
80void kvm_timer_unschedule(struct kvm_vcpu *vcpu);
81
82u64 kvm_phys_timer_read(void); 100u64 kvm_phys_timer_read(void);
83 101
84void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu); 102void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu);
@@ -88,7 +106,19 @@ void kvm_timer_init_vhe(void);
88 106
89bool kvm_arch_timer_get_input_level(int vintid); 107bool kvm_arch_timer_get_input_level(int vintid);
90 108
91#define vcpu_vtimer(v) (&(v)->arch.timer_cpu.vtimer) 109#define vcpu_timer(v) (&(v)->arch.timer_cpu)
92#define vcpu_ptimer(v) (&(v)->arch.timer_cpu.ptimer) 110#define vcpu_get_timer(v,t) (&vcpu_timer(v)->timers[(t)])
111#define vcpu_vtimer(v) (&(v)->arch.timer_cpu.timers[TIMER_VTIMER])
112#define vcpu_ptimer(v) (&(v)->arch.timer_cpu.timers[TIMER_PTIMER])
113
114#define arch_timer_ctx_index(ctx) ((ctx) - vcpu_timer((ctx)->vcpu)->timers)
115
116u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,
117 enum kvm_arch_timers tmr,
118 enum kvm_arch_timer_regs treg);
119void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu,
120 enum kvm_arch_timers tmr,
121 enum kvm_arch_timer_regs treg,
122 u64 val);
93 123
94#endif 124#endif
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 6ac47f5ea514..d5dcebd7aad3 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -400,12 +400,17 @@ extern bool acpi_osi_is_win8(void);
400 400
401#ifdef CONFIG_ACPI_NUMA 401#ifdef CONFIG_ACPI_NUMA
402int acpi_map_pxm_to_online_node(int pxm); 402int acpi_map_pxm_to_online_node(int pxm);
403int acpi_map_pxm_to_node(int pxm);
403int acpi_get_node(acpi_handle handle); 404int acpi_get_node(acpi_handle handle);
404#else 405#else
405static inline int acpi_map_pxm_to_online_node(int pxm) 406static inline int acpi_map_pxm_to_online_node(int pxm)
406{ 407{
407 return 0; 408 return 0;
408} 409}
410static inline int acpi_map_pxm_to_node(int pxm)
411{
412 return 0;
413}
409static inline int acpi_get_node(acpi_handle handle) 414static inline int acpi_get_node(acpi_handle handle)
410{ 415{
411 return 0; 416 return 0;
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index d143c13bed26..f99b74a6e4ca 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -25,6 +25,43 @@
25#define AMBA_CID 0xb105f00d 25#define AMBA_CID 0xb105f00d
26#define CORESIGHT_CID 0xb105900d 26#define CORESIGHT_CID 0xb105900d
27 27
28/*
29 * CoreSight Architecture specification updates the ID specification
30 * for components on the AMBA bus. (ARM IHI 0029E)
31 *
32 * Bits 15:12 of the CID are the device class.
33 *
34 * Class 0xF remains for PrimeCell and legacy components. (AMBA_CID above)
35 * Class 0x9 defines the component as CoreSight (CORESIGHT_CID above)
36 * Class 0x0, 0x1, 0xB, 0xE define components that do not have driver support
37 * at present.
38 * Class 0x2-0x8,0xA and 0xD-0xD are presently reserved.
39 *
40 * Remaining CID bits stay as 0xb105-00d
41 */
42
43/**
44 * Class 0x9 components use additional values to form a Unique Component
45 * Identifier (UCI), where peripheral ID values are identical for different
46 * components. Passed to the amba bus code from the component driver via
47 * the amba_id->data pointer.
48 * @devarch : coresight devarch register value
49 * @devarch_mask: mask bits used for matching. 0 indicates UCI not used.
50 * @devtype : coresight device type value
51 * @data : additional driver data. As we have usurped the original
52 * pointer some devices may still need additional data
53 */
54struct amba_cs_uci_id {
55 unsigned int devarch;
56 unsigned int devarch_mask;
57 unsigned int devtype;
58 void *data;
59};
60
61/* define offsets for registers used by UCI */
62#define UCI_REG_DEVTYPE_OFFSET 0xFCC
63#define UCI_REG_DEVARCH_OFFSET 0xFBC
64
28struct clk; 65struct clk;
29 66
30struct amba_device { 67struct amba_device {
@@ -32,6 +69,8 @@ struct amba_device {
32 struct resource res; 69 struct resource res;
33 struct clk *pclk; 70 struct clk *pclk;
34 unsigned int periphid; 71 unsigned int periphid;
72 unsigned int cid;
73 struct amba_cs_uci_id uci;
35 unsigned int irq[AMBA_NR_IRQS]; 74 unsigned int irq[AMBA_NR_IRQS];
36 char *driver_override; 75 char *driver_override;
37}; 76};
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/f2fs_fs.h b/include/linux/f2fs_fs.h
index d7711048ef93..f5740423b002 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -116,6 +116,7 @@ struct f2fs_super_block {
116/* 116/*
117 * For checkpoint 117 * For checkpoint
118 */ 118 */
119#define CP_DISABLED_QUICK_FLAG 0x00002000
119#define CP_DISABLED_FLAG 0x00001000 120#define CP_DISABLED_FLAG 0x00001000
120#define CP_QUOTA_NEED_FSCK_FLAG 0x00000800 121#define CP_QUOTA_NEED_FSCK_FLAG 0x00000800
121#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400 122#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400
@@ -186,7 +187,7 @@ struct f2fs_orphan_block {
186struct f2fs_extent { 187struct f2fs_extent {
187 __le32 fofs; /* start file offset of the extent */ 188 __le32 fofs; /* start file offset of the extent */
188 __le32 blk; /* start block address of the extent */ 189 __le32 blk; /* start block address of the extent */
189 __le32 len; /* lengh of the extent */ 190 __le32 len; /* length of the extent */
190} __packed; 191} __packed;
191 192
192#define F2FS_NAME_LEN 255 193#define F2FS_NAME_LEN 255
@@ -284,7 +285,7 @@ enum {
284 285
285struct node_footer { 286struct node_footer {
286 __le32 nid; /* node id */ 287 __le32 nid; /* node id */
287 __le32 ino; /* inode nunmber */ 288 __le32 ino; /* inode number */
288 __le32 flag; /* include cold/fsync/dentry marks and offset */ 289 __le32 flag; /* include cold/fsync/dentry marks and offset */
289 __le64 cp_ver; /* checkpoint version */ 290 __le64 cp_ver; /* checkpoint version */
290 __le32 next_blkaddr; /* next node page block address */ 291 __le32 next_blkaddr; /* next node page block address */
@@ -489,12 +490,12 @@ typedef __le32 f2fs_hash_t;
489 490
490/* 491/*
491 * space utilization of regular dentry and inline dentry (w/o extra reservation) 492 * space utilization of regular dentry and inline dentry (w/o extra reservation)
492 * regular dentry inline dentry 493 * regular dentry inline dentry (def) inline dentry (min)
493 * bitmap 1 * 27 = 27 1 * 23 = 23 494 * bitmap 1 * 27 = 27 1 * 23 = 23 1 * 1 = 1
494 * reserved 1 * 3 = 3 1 * 7 = 7 495 * reserved 1 * 3 = 3 1 * 7 = 7 1 * 1 = 1
495 * dentry 11 * 214 = 2354 11 * 182 = 2002 496 * dentry 11 * 214 = 2354 11 * 182 = 2002 11 * 2 = 22
496 * filename 8 * 214 = 1712 8 * 182 = 1456 497 * filename 8 * 214 = 1712 8 * 182 = 1456 8 * 2 = 16
497 * total 4096 3488 498 * total 4096 3488 40
498 * 499 *
499 * Note: there are more reserved space in inline dentry than in regular 500 * Note: there are more reserved space in inline dentry than in regular
500 * dentry, when converting inline dentry we should handle this carefully. 501 * dentry, when converting inline dentry we should handle this carefully.
@@ -506,12 +507,13 @@ typedef __le32 f2fs_hash_t;
506#define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \ 507#define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \
507 F2FS_SLOT_LEN) * \ 508 F2FS_SLOT_LEN) * \
508 NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) 509 NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))
510#define MIN_INLINE_DENTRY_SIZE 40 /* just include '.' and '..' entries */
509 511
510/* One directory entry slot representing F2FS_SLOT_LEN-sized file name */ 512/* One directory entry slot representing F2FS_SLOT_LEN-sized file name */
511struct f2fs_dir_entry { 513struct f2fs_dir_entry {
512 __le32 hash_code; /* hash code of file name */ 514 __le32 hash_code; /* hash code of file name */
513 __le32 ino; /* inode number */ 515 __le32 ino; /* inode number */
514 __le16 name_len; /* lengh of file name */ 516 __le16 name_len; /* length of file name */
515 __u8 file_type; /* file type */ 517 __u8 file_type; /* file type */
516} __packed; 518} __packed;
517 519
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/kvm_host.h b/include/linux/kvm_host.h
index c38cc5eb7e73..9d55c63db09b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -48,6 +48,27 @@
48 */ 48 */
49#define KVM_MEMSLOT_INVALID (1UL << 16) 49#define KVM_MEMSLOT_INVALID (1UL << 16)
50 50
51/*
52 * Bit 63 of the memslot generation number is an "update in-progress flag",
53 * e.g. is temporarily set for the duration of install_new_memslots().
54 * This flag effectively creates a unique generation number that is used to
55 * mark cached memslot data, e.g. MMIO accesses, as potentially being stale,
56 * i.e. may (or may not) have come from the previous memslots generation.
57 *
58 * This is necessary because the actual memslots update is not atomic with
59 * respect to the generation number update. Updating the generation number
60 * first would allow a vCPU to cache a spte from the old memslots using the
61 * new generation number, and updating the generation number after switching
62 * to the new memslots would allow cache hits using the old generation number
63 * to reference the defunct memslots.
64 *
65 * This mechanism is used to prevent getting hits in KVM's caches while a
66 * memslot update is in-progress, and to prevent cache hits *after* updating
67 * the actual generation number against accesses that were inserted into the
68 * cache *before* the memslots were updated.
69 */
70#define KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS BIT_ULL(63)
71
51/* Two fragments for cross MMIO pages. */ 72/* Two fragments for cross MMIO pages. */
52#define KVM_MAX_MMIO_FRAGMENTS 2 73#define KVM_MAX_MMIO_FRAGMENTS 2
53 74
@@ -634,7 +655,7 @@ void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
634 struct kvm_memory_slot *dont); 655 struct kvm_memory_slot *dont);
635int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, 656int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot,
636 unsigned long npages); 657 unsigned long npages);
637void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots); 658void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen);
638int kvm_arch_prepare_memory_region(struct kvm *kvm, 659int kvm_arch_prepare_memory_region(struct kvm *kvm,
639 struct kvm_memory_slot *memslot, 660 struct kvm_memory_slot *memslot,
640 const struct kvm_userspace_memory_region *mem, 661 const struct kvm_userspace_memory_region *mem,
@@ -1182,6 +1203,7 @@ extern bool kvm_rebooting;
1182 1203
1183extern unsigned int halt_poll_ns; 1204extern unsigned int halt_poll_ns;
1184extern unsigned int halt_poll_ns_grow; 1205extern unsigned int halt_poll_ns_grow;
1206extern unsigned int halt_poll_ns_grow_start;
1185extern unsigned int halt_poll_ns_shrink; 1207extern unsigned int halt_poll_ns_shrink;
1186 1208
1187struct kvm_device { 1209struct kvm_device {
diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h
index 43348303cb4b..feb342d026f2 100644
--- a/include/linux/libnvdimm.h
+++ b/include/linux/libnvdimm.h
@@ -130,6 +130,7 @@ struct nd_region_desc {
130 void *provider_data; 130 void *provider_data;
131 int num_lanes; 131 int num_lanes;
132 int numa_node; 132 int numa_node;
133 int target_node;
133 unsigned long flags; 134 unsigned long flags;
134 struct device_node *of_node; 135 struct device_node *of_node;
135}; 136};
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/ntb.h b/include/linux/ntb.h
index 181d16601dd9..56a92e3ae3ae 100644
--- a/include/linux/ntb.h
+++ b/include/linux/ntb.h
@@ -296,7 +296,8 @@ struct ntb_dev_ops {
296 int (*db_clear_mask)(struct ntb_dev *ntb, u64 db_bits); 296 int (*db_clear_mask)(struct ntb_dev *ntb, u64 db_bits);
297 297
298 int (*peer_db_addr)(struct ntb_dev *ntb, 298 int (*peer_db_addr)(struct ntb_dev *ntb,
299 phys_addr_t *db_addr, resource_size_t *db_size); 299 phys_addr_t *db_addr, resource_size_t *db_size,
300 u64 *db_data, int db_bit);
300 u64 (*peer_db_read)(struct ntb_dev *ntb); 301 u64 (*peer_db_read)(struct ntb_dev *ntb);
301 int (*peer_db_set)(struct ntb_dev *ntb, u64 db_bits); 302 int (*peer_db_set)(struct ntb_dev *ntb, u64 db_bits);
302 int (*peer_db_clear)(struct ntb_dev *ntb, u64 db_bits); 303 int (*peer_db_clear)(struct ntb_dev *ntb, u64 db_bits);
@@ -1078,6 +1079,8 @@ static inline int ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
1078 * @ntb: NTB device context. 1079 * @ntb: NTB device context.
1079 * @db_addr: OUT - The address of the peer doorbell register. 1080 * @db_addr: OUT - The address of the peer doorbell register.
1080 * @db_size: OUT - The number of bytes to write the peer doorbell register. 1081 * @db_size: OUT - The number of bytes to write the peer doorbell register.
1082 * @db_data: OUT - The data of peer doorbell register
1083 * @db_bit: door bell bit number
1081 * 1084 *
1082 * Return the address of the peer doorbell register. This may be used, for 1085 * Return the address of the peer doorbell register. This may be used, for
1083 * example, by drivers that offload memory copy operations to a dma engine. 1086 * example, by drivers that offload memory copy operations to a dma engine.
@@ -1091,12 +1094,13 @@ static inline int ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
1091 */ 1094 */
1092static inline int ntb_peer_db_addr(struct ntb_dev *ntb, 1095static inline int ntb_peer_db_addr(struct ntb_dev *ntb,
1093 phys_addr_t *db_addr, 1096 phys_addr_t *db_addr,
1094 resource_size_t *db_size) 1097 resource_size_t *db_size,
1098 u64 *db_data, int db_bit)
1095{ 1099{
1096 if (!ntb->ops->peer_db_addr) 1100 if (!ntb->ops->peer_db_addr)
1097 return -EINVAL; 1101 return -EINVAL;
1098 1102
1099 return ntb->ops->peer_db_addr(ntb, db_addr, db_size); 1103 return ntb->ops->peer_db_addr(ntb, db_addr, db_size, db_data, db_bit);
1100} 1104}
1101 1105
1102/** 1106/**
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index b477a70cc2e4..bcf909d0de5f 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -239,6 +239,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
239#define FGP_WRITE 0x00000008 239#define FGP_WRITE 0x00000008
240#define FGP_NOFS 0x00000010 240#define FGP_NOFS 0x00000010
241#define FGP_NOWAIT 0x00000020 241#define FGP_NOWAIT 0x00000020
242#define FGP_FOR_MMAP 0x00000040
242 243
243struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset, 244struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
244 int fgp_flags, gfp_t cache_gfp_mask); 245 int fgp_flags, gfp_t cache_gfp_mask);
diff --git a/include/linux/parport.h b/include/linux/parport.h
index f41f1d041e2c..397607a0c0eb 100644
--- a/include/linux/parport.h
+++ b/include/linux/parport.h
@@ -460,7 +460,6 @@ extern size_t parport_ieee1284_epp_read_addr (struct parport *,
460 void *, size_t, int); 460 void *, size_t, int);
461 461
462/* IEEE1284.3 functions */ 462/* IEEE1284.3 functions */
463#define daisy_dev_name "Device ID probe"
464extern int parport_daisy_init (struct parport *port); 463extern int parport_daisy_init (struct parport *port);
465extern void parport_daisy_fini (struct parport *port); 464extern void parport_daisy_fini (struct parport *port);
466extern struct pardevice *parport_open (int devnum, const char *name); 465extern struct pardevice *parport_open (int devnum, const char *name);
@@ -469,18 +468,6 @@ extern ssize_t parport_device_id (int devnum, char *buffer, size_t len);
469extern void parport_daisy_deselect_all (struct parport *port); 468extern void parport_daisy_deselect_all (struct parport *port);
470extern int parport_daisy_select (struct parport *port, int daisy, int mode); 469extern int parport_daisy_select (struct parport *port, int daisy, int mode);
471 470
472#ifdef CONFIG_PARPORT_1284
473extern int daisy_drv_init(void);
474extern void daisy_drv_exit(void);
475#else
476static inline int daisy_drv_init(void)
477{
478 return 0;
479}
480
481static inline void daisy_drv_exit(void) {}
482#endif
483
484/* Lowlevel drivers _can_ call this support function to handle irqs. */ 471/* Lowlevel drivers _can_ call this support function to handle irqs. */
485static inline void parport_generic_irq(struct parport *port) 472static inline void parport_generic_irq(struct parport *port)
486{ 473{
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index d0e1f1522a78..52a283ba0465 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -73,6 +73,7 @@ struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mo
73 int (*show)(struct seq_file *, void *), 73 int (*show)(struct seq_file *, void *),
74 proc_write_t write, 74 proc_write_t write,
75 void *data); 75 void *data);
76extern struct pid *tgid_pidfd_to_pid(const struct file *file);
76 77
77#else /* CONFIG_PROC_FS */ 78#else /* CONFIG_PROC_FS */
78 79
@@ -114,6 +115,11 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
114#define proc_create_net(name, mode, parent, state_size, ops) ({NULL;}) 115#define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
115#define proc_create_net_single(name, mode, parent, show, data) ({NULL;}) 116#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
116 117
118static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
119{
120 return ERR_PTR(-EBADF);
121}
122
117#endif /* CONFIG_PROC_FS */ 123#endif /* CONFIG_PROC_FS */
118 124
119struct net; 125struct net;
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index f1429675f252..1a40277b512c 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -128,7 +128,7 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts,
128 unsigned long *lost_events); 128 unsigned long *lost_events);
129 129
130struct ring_buffer_iter * 130struct ring_buffer_iter *
131ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu); 131ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu, gfp_t flags);
132void ring_buffer_read_prepare_sync(void); 132void ring_buffer_read_prepare_sync(void);
133void ring_buffer_read_start(struct ring_buffer_iter *iter); 133void ring_buffer_read_start(struct ring_buffer_iter *iter);
134void ring_buffer_read_finish(struct ring_buffer_iter *iter); 134void ring_buffer_read_finish(struct ring_buffer_iter *iter);
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/switchtec.h b/include/linux/switchtec.h
index eee0412bdf4b..52a079b3a9a6 100644
--- a/include/linux/switchtec.h
+++ b/include/linux/switchtec.h
@@ -248,9 +248,13 @@ struct ntb_ctrl_regs {
248 u32 win_size; 248 u32 win_size;
249 u64 xlate_addr; 249 u64 xlate_addr;
250 } bar_entry[6]; 250 } bar_entry[6];
251 u32 reserved2[216]; 251 struct {
252 u32 req_id_table[256]; 252 u32 win_size;
253 u32 reserved3[512]; 253 u32 reserved[3];
254 } bar_ext_entry[6];
255 u32 reserved2[192];
256 u32 req_id_table[512];
257 u32 reserved3[256];
254 u64 lut_entry[512]; 258 u64 lut_entry[512];
255} __packed; 259} __packed;
256 260
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index c2962953bf11..e446806a561f 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -985,6 +985,9 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
985 unsigned mask, struct statx __user *buffer); 985 unsigned mask, struct statx __user *buffer);
986asmlinkage long sys_rseq(struct rseq __user *rseq, uint32_t rseq_len, 986asmlinkage long sys_rseq(struct rseq __user *rseq, uint32_t rseq_len,
987 int flags, uint32_t sig); 987 int flags, uint32_t sig);
988asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,
989 siginfo_t __user *info,
990 unsigned int flags);
988 991
989/* 992/*
990 * Architecture-specific system calls 993 * Architecture-specific system calls
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/linux/vgaarb.h b/include/linux/vgaarb.h
index ee162e3e879b..553b34c8b5f7 100644
--- a/include/linux/vgaarb.h
+++ b/include/linux/vgaarb.h
@@ -125,9 +125,11 @@ extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
125#ifdef CONFIG_VGA_ARB 125#ifdef CONFIG_VGA_ARB
126extern struct pci_dev *vga_default_device(void); 126extern struct pci_dev *vga_default_device(void);
127extern void vga_set_default_device(struct pci_dev *pdev); 127extern void vga_set_default_device(struct pci_dev *pdev);
128extern int vga_remove_vgacon(struct pci_dev *pdev);
128#else 129#else
129static inline struct pci_dev *vga_default_device(void) { return NULL; }; 130static inline struct pci_dev *vga_default_device(void) { return NULL; };
130static inline void vga_set_default_device(struct pci_dev *pdev) { }; 131static inline void vga_set_default_device(struct pci_dev *pdev) { };
132static inline int vga_remove_vgacon(struct pci_dev *pdev) { return 0; };
131#endif 133#endif
132 134
133/* 135/*
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/include/sound/pcm.h b/include/sound/pcm.h
index 465d7d033c4c..18bd8c3ea605 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -750,7 +750,7 @@ static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *r
750} 750}
751 751
752/** 752/**
753 * snd_pcm_playback_avail - Get the available (readable) space for capture 753 * snd_pcm_capture_avail - Get the available (readable) space for capture
754 * @runtime: PCM runtime instance 754 * @runtime: PCM runtime instance
755 * 755 *
756 * Result is between 0 ... (boundary - 1) 756 * Result is between 0 ... (boundary - 1)
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 3ec73f17ee2a..a3916b4dd57e 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -149,6 +149,17 @@ TRACE_DEFINE_ENUM(CP_TRIMMED);
149 { CP_SPEC_LOG_NUM, "log type is 2" }, \ 149 { CP_SPEC_LOG_NUM, "log type is 2" }, \
150 { CP_RECOVER_DIR, "dir needs recovery" }) 150 { CP_RECOVER_DIR, "dir needs recovery" })
151 151
152#define show_shutdown_mode(type) \
153 __print_symbolic(type, \
154 { F2FS_GOING_DOWN_FULLSYNC, "full sync" }, \
155 { F2FS_GOING_DOWN_METASYNC, "meta sync" }, \
156 { F2FS_GOING_DOWN_NOSYNC, "no sync" }, \
157 { F2FS_GOING_DOWN_METAFLUSH, "meta flush" }, \
158 { F2FS_GOING_DOWN_NEED_FSCK, "need fsck" })
159
160struct f2fs_sb_info;
161struct f2fs_io_info;
162struct extent_info;
152struct victim_sel_policy; 163struct victim_sel_policy;
153struct f2fs_map_blocks; 164struct f2fs_map_blocks;
154 165
@@ -533,6 +544,9 @@ TRACE_EVENT(f2fs_map_blocks,
533 __field(block_t, m_lblk) 544 __field(block_t, m_lblk)
534 __field(block_t, m_pblk) 545 __field(block_t, m_pblk)
535 __field(unsigned int, m_len) 546 __field(unsigned int, m_len)
547 __field(unsigned int, m_flags)
548 __field(int, m_seg_type)
549 __field(bool, m_may_create)
536 __field(int, ret) 550 __field(int, ret)
537 ), 551 ),
538 552
@@ -542,15 +556,22 @@ TRACE_EVENT(f2fs_map_blocks,
542 __entry->m_lblk = map->m_lblk; 556 __entry->m_lblk = map->m_lblk;
543 __entry->m_pblk = map->m_pblk; 557 __entry->m_pblk = map->m_pblk;
544 __entry->m_len = map->m_len; 558 __entry->m_len = map->m_len;
559 __entry->m_flags = map->m_flags;
560 __entry->m_seg_type = map->m_seg_type;
561 __entry->m_may_create = map->m_may_create;
545 __entry->ret = ret; 562 __entry->ret = ret;
546 ), 563 ),
547 564
548 TP_printk("dev = (%d,%d), ino = %lu, file offset = %llu, " 565 TP_printk("dev = (%d,%d), ino = %lu, file offset = %llu, "
549 "start blkaddr = 0x%llx, len = 0x%llx, err = %d", 566 "start blkaddr = 0x%llx, len = 0x%llx, flags = %u,"
567 "seg_type = %d, may_create = %d, err = %d",
550 show_dev_ino(__entry), 568 show_dev_ino(__entry),
551 (unsigned long long)__entry->m_lblk, 569 (unsigned long long)__entry->m_lblk,
552 (unsigned long long)__entry->m_pblk, 570 (unsigned long long)__entry->m_pblk,
553 (unsigned long long)__entry->m_len, 571 (unsigned long long)__entry->m_len,
572 __entry->m_flags,
573 __entry->m_seg_type,
574 __entry->m_may_create,
554 __entry->ret) 575 __entry->ret)
555); 576);
556 577
@@ -1616,6 +1637,30 @@ DEFINE_EVENT(f2fs_sync_dirty_inodes, f2fs_sync_dirty_inodes_exit,
1616 TP_ARGS(sb, type, count) 1637 TP_ARGS(sb, type, count)
1617); 1638);
1618 1639
1640TRACE_EVENT(f2fs_shutdown,
1641
1642 TP_PROTO(struct f2fs_sb_info *sbi, unsigned int mode, int ret),
1643
1644 TP_ARGS(sbi, mode, ret),
1645
1646 TP_STRUCT__entry(
1647 __field(dev_t, dev)
1648 __field(unsigned int, mode)
1649 __field(int, ret)
1650 ),
1651
1652 TP_fast_assign(
1653 __entry->dev = sbi->sb->s_dev;
1654 __entry->mode = mode;
1655 __entry->ret = ret;
1656 ),
1657
1658 TP_printk("dev = (%d,%d), mode: %s, ret:%d",
1659 show_dev(__entry->dev),
1660 show_shutdown_mode(__entry->mode),
1661 __entry->ret)
1662);
1663
1619#endif /* _TRACE_F2FS_H */ 1664#endif /* _TRACE_F2FS_H */
1620 1665
1621 /* This part must be outside protection */ 1666 /* This part must be outside protection */
diff --git a/include/trace/events/sunrpc.h b/include/trace/events/sunrpc.h
index 8451f30c6a0f..7e899e635d33 100644
--- a/include/trace/events/sunrpc.h
+++ b/include/trace/events/sunrpc.h
@@ -712,7 +712,8 @@ TRACE_EVENT(xprt_transmit,
712 712
713 TP_fast_assign( 713 TP_fast_assign(
714 __entry->task_id = rqst->rq_task->tk_pid; 714 __entry->task_id = rqst->rq_task->tk_pid;
715 __entry->client_id = rqst->rq_task->tk_client->cl_clid; 715 __entry->client_id = rqst->rq_task->tk_client ?
716 rqst->rq_task->tk_client->cl_clid : -1;
716 __entry->xid = be32_to_cpu(rqst->rq_xid); 717 __entry->xid = be32_to_cpu(rqst->rq_xid);
717 __entry->seqno = rqst->rq_seqno; 718 __entry->seqno = rqst->rq_seqno;
718 __entry->status = status; 719 __entry->status = status;
@@ -742,7 +743,8 @@ TRACE_EVENT(xprt_enq_xmit,
742 743
743 TP_fast_assign( 744 TP_fast_assign(
744 __entry->task_id = task->tk_pid; 745 __entry->task_id = task->tk_pid;
745 __entry->client_id = task->tk_client->cl_clid; 746 __entry->client_id = task->tk_client ?
747 task->tk_client->cl_clid : -1;
746 __entry->xid = be32_to_cpu(task->tk_rqstp->rq_xid); 748 __entry->xid = be32_to_cpu(task->tk_rqstp->rq_xid);
747 __entry->seqno = task->tk_rqstp->rq_seqno; 749 __entry->seqno = task->tk_rqstp->rq_seqno;
748 __entry->stage = stage; 750 __entry->stage = stage;
diff --git a/include/uapi/asm-generic/Kbuild.asm b/include/uapi/asm-generic/Kbuild
index 355c4ac2c0b0..ebb180aac74e 100644
--- a/include/uapi/asm-generic/Kbuild.asm
+++ b/include/uapi/asm-generic/Kbuild
@@ -1,6 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0
1# 2#
2# Headers that are mandatory in usr/include/asm/ 3# Headers that are mandatory in usr/include/asm/
3# 4# (This file is not included when SRCARCH=um since UML does not support UAPI.)
5
4mandatory-y += auxvec.h 6mandatory-y += auxvec.h
5mandatory-y += bitsperlong.h 7mandatory-y += bitsperlong.h
6mandatory-y += bpf_perf_event.h 8mandatory-y += bpf_perf_event.h
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index bf4624efe5e6..dee7292e1df6 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -824,6 +824,8 @@ __SYSCALL(__NR_futex_time64, sys_futex)
824__SYSCALL(__NR_sched_rr_get_interval_time64, sys_sched_rr_get_interval) 824__SYSCALL(__NR_sched_rr_get_interval_time64, sys_sched_rr_get_interval)
825#endif 825#endif
826 826
827#define __NR_pidfd_send_signal 424
828__SYSCALL(__NR_pidfd_send_signal, sys_pidfd_send_signal)
827#define __NR_io_uring_setup 425 829#define __NR_io_uring_setup 425
828__SYSCALL(__NR_io_uring_setup, sys_io_uring_setup) 830__SYSCALL(__NR_io_uring_setup, sys_io_uring_setup)
829#define __NR_io_uring_enter 426 831#define __NR_io_uring_enter 426
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/printk/printk.c b/kernel/printk/printk.c
index 6b7654b8001f..02ca827b8fac 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -65,6 +65,7 @@ int console_printk[4] = {
65 CONSOLE_LOGLEVEL_MIN, /* minimum_console_loglevel */ 65 CONSOLE_LOGLEVEL_MIN, /* minimum_console_loglevel */
66 CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */ 66 CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */
67}; 67};
68EXPORT_SYMBOL_GPL(console_printk);
68 69
69atomic_t ignore_console_lock_warning __read_mostly = ATOMIC_INIT(0); 70atomic_t ignore_console_lock_warning __read_mostly = ATOMIC_INIT(0);
70EXPORT_SYMBOL(ignore_console_lock_warning); 71EXPORT_SYMBOL(ignore_console_lock_warning);
diff --git a/kernel/resource.c b/kernel/resource.c
index e81b17b53fa5..92190f62ebc5 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -382,7 +382,7 @@ static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,
382 int (*func)(struct resource *, void *)) 382 int (*func)(struct resource *, void *))
383{ 383{
384 struct resource res; 384 struct resource res;
385 int ret = -1; 385 int ret = -EINVAL;
386 386
387 while (start < end && 387 while (start < end &&
388 !find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) { 388 !find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) {
@@ -452,6 +452,9 @@ int walk_mem_res(u64 start, u64 end, void *arg,
452 * This function calls the @func callback against all memory ranges of type 452 * This function calls the @func callback against all memory ranges of type
453 * System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY. 453 * System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY.
454 * It is to be used only for System RAM. 454 * It is to be used only for System RAM.
455 *
456 * This will find System RAM ranges that are children of top-level resources
457 * in addition to top-level System RAM resources.
455 */ 458 */
456int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, 459int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
457 void *arg, int (*func)(unsigned long, unsigned long, void *)) 460 void *arg, int (*func)(unsigned long, unsigned long, void *))
@@ -460,14 +463,14 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
460 unsigned long flags; 463 unsigned long flags;
461 struct resource res; 464 struct resource res;
462 unsigned long pfn, end_pfn; 465 unsigned long pfn, end_pfn;
463 int ret = -1; 466 int ret = -EINVAL;
464 467
465 start = (u64) start_pfn << PAGE_SHIFT; 468 start = (u64) start_pfn << PAGE_SHIFT;
466 end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1; 469 end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
467 flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; 470 flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
468 while (start < end && 471 while (start < end &&
469 !find_next_iomem_res(start, end, flags, IORES_DESC_NONE, 472 !find_next_iomem_res(start, end, flags, IORES_DESC_NONE,
470 true, &res)) { 473 false, &res)) {
471 pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT; 474 pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
472 end_pfn = (res.end + 1) >> PAGE_SHIFT; 475 end_pfn = (res.end + 1) >> PAGE_SHIFT;
473 if (end_pfn > pfn) 476 if (end_pfn > pfn)
@@ -1128,6 +1131,15 @@ struct resource * __request_region(struct resource *parent,
1128 conflict = __request_resource(parent, res); 1131 conflict = __request_resource(parent, res);
1129 if (!conflict) 1132 if (!conflict)
1130 break; 1133 break;
1134 /*
1135 * mm/hmm.c reserves physical addresses which then
1136 * become unavailable to other users. Conflicts are
1137 * not expected. Warn to aid debugging if encountered.
1138 */
1139 if (conflict->desc == IORES_DESC_DEVICE_PRIVATE_MEMORY) {
1140 pr_warn("Unaddressable device %s %pR conflicts with %pR",
1141 conflict->name, conflict, res);
1142 }
1131 if (conflict != parent) { 1143 if (conflict != parent) {
1132 if (!(conflict->flags & IORESOURCE_BUSY)) { 1144 if (!(conflict->flags & IORESOURCE_BUSY)) {
1133 parent = conflict; 1145 parent = conflict;
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/signal.c b/kernel/signal.c
index 5d53183e2705..b7953934aa99 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -19,7 +19,9 @@
19#include <linux/sched/task.h> 19#include <linux/sched/task.h>
20#include <linux/sched/task_stack.h> 20#include <linux/sched/task_stack.h>
21#include <linux/sched/cputime.h> 21#include <linux/sched/cputime.h>
22#include <linux/file.h>
22#include <linux/fs.h> 23#include <linux/fs.h>
24#include <linux/proc_fs.h>
23#include <linux/tty.h> 25#include <linux/tty.h>
24#include <linux/binfmts.h> 26#include <linux/binfmts.h>
25#include <linux/coredump.h> 27#include <linux/coredump.h>
@@ -3487,6 +3489,16 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time32, compat_sigset_t __user *, uthese,
3487#endif 3489#endif
3488#endif 3490#endif
3489 3491
3492static inline void prepare_kill_siginfo(int sig, struct kernel_siginfo *info)
3493{
3494 clear_siginfo(info);
3495 info->si_signo = sig;
3496 info->si_errno = 0;
3497 info->si_code = SI_USER;
3498 info->si_pid = task_tgid_vnr(current);
3499 info->si_uid = from_kuid_munged(current_user_ns(), current_uid());
3500}
3501
3490/** 3502/**
3491 * sys_kill - send a signal to a process 3503 * sys_kill - send a signal to a process
3492 * @pid: the PID of the process 3504 * @pid: the PID of the process
@@ -3496,16 +3508,125 @@ SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
3496{ 3508{
3497 struct kernel_siginfo info; 3509 struct kernel_siginfo info;
3498 3510
3499 clear_siginfo(&info); 3511 prepare_kill_siginfo(sig, &info);
3500 info.si_signo = sig;
3501 info.si_errno = 0;
3502 info.si_code = SI_USER;
3503 info.si_pid = task_tgid_vnr(current);
3504 info.si_uid = from_kuid_munged(current_user_ns(), current_uid());
3505 3512
3506 return kill_something_info(sig, &info, pid); 3513 return kill_something_info(sig, &info, pid);
3507} 3514}
3508 3515
3516#ifdef CONFIG_PROC_FS
3517/*
3518 * Verify that the signaler and signalee either are in the same pid namespace
3519 * or that the signaler's pid namespace is an ancestor of the signalee's pid
3520 * namespace.
3521 */
3522static bool access_pidfd_pidns(struct pid *pid)
3523{
3524 struct pid_namespace *active = task_active_pid_ns(current);
3525 struct pid_namespace *p = ns_of_pid(pid);
3526
3527 for (;;) {
3528 if (!p)
3529 return false;
3530 if (p == active)
3531 break;
3532 p = p->parent;
3533 }
3534
3535 return true;
3536}
3537
3538static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info)
3539{
3540#ifdef CONFIG_COMPAT
3541 /*
3542 * Avoid hooking up compat syscalls and instead handle necessary
3543 * conversions here. Note, this is a stop-gap measure and should not be
3544 * considered a generic solution.
3545 */
3546 if (in_compat_syscall())
3547 return copy_siginfo_from_user32(
3548 kinfo, (struct compat_siginfo __user *)info);
3549#endif
3550 return copy_siginfo_from_user(kinfo, info);
3551}
3552
3553/**
3554 * sys_pidfd_send_signal - send a signal to a process through a task file
3555 * descriptor
3556 * @pidfd: the file descriptor of the process
3557 * @sig: signal to be sent
3558 * @info: the signal info
3559 * @flags: future flags to be passed
3560 *
3561 * The syscall currently only signals via PIDTYPE_PID which covers
3562 * kill(<positive-pid>, <signal>. It does not signal threads or process
3563 * groups.
3564 * In order to extend the syscall to threads and process groups the @flags
3565 * argument should be used. In essence, the @flags argument will determine
3566 * what is signaled and not the file descriptor itself. Put in other words,
3567 * grouping is a property of the flags argument not a property of the file
3568 * descriptor.
3569 *
3570 * Return: 0 on success, negative errno on failure
3571 */
3572SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
3573 siginfo_t __user *, info, unsigned int, flags)
3574{
3575 int ret;
3576 struct fd f;
3577 struct pid *pid;
3578 kernel_siginfo_t kinfo;
3579
3580 /* Enforce flags be set to 0 until we add an extension. */
3581 if (flags)
3582 return -EINVAL;
3583
3584 f = fdget_raw(pidfd);
3585 if (!f.file)
3586 return -EBADF;
3587
3588 /* Is this a pidfd? */
3589 pid = tgid_pidfd_to_pid(f.file);
3590 if (IS_ERR(pid)) {
3591 ret = PTR_ERR(pid);
3592 goto err;
3593 }
3594
3595 ret = -EINVAL;
3596 if (!access_pidfd_pidns(pid))
3597 goto err;
3598
3599 if (info) {
3600 ret = copy_siginfo_from_user_any(&kinfo, info);
3601 if (unlikely(ret))
3602 goto err;
3603
3604 ret = -EINVAL;
3605 if (unlikely(sig != kinfo.si_signo))
3606 goto err;
3607
3608 if ((task_pid(current) != pid) &&
3609 (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) {
3610 /* Only allow sending arbitrary signals to yourself. */
3611 ret = -EPERM;
3612 if (kinfo.si_code != SI_USER)
3613 goto err;
3614
3615 /* Turn this into a regular kill signal. */
3616 prepare_kill_siginfo(sig, &kinfo);
3617 }
3618 } else {
3619 prepare_kill_siginfo(sig, &kinfo);
3620 }
3621
3622 ret = kill_pid_info(sig, &kinfo, pid);
3623
3624err:
3625 fdput(f);
3626 return ret;
3627}
3628#endif /* CONFIG_PROC_FS */
3629
3509static int 3630static int
3510do_send_specific(pid_t tgid, pid_t pid, int sig, struct kernel_siginfo *info) 3631do_send_specific(pid_t tgid, pid_t pid, int sig, struct kernel_siginfo *info)
3511{ 3632{
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 51d7c6794bf1..d21f4befaea4 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -168,6 +168,7 @@ COND_SYSCALL(syslog);
168/* kernel/sched/core.c */ 168/* kernel/sched/core.c */
169 169
170/* kernel/signal.c */ 170/* kernel/signal.c */
171COND_SYSCALL(pidfd_send_signal);
171 172
172/* kernel/sys.c */ 173/* kernel/sys.c */
173COND_SYSCALL(setregid); 174COND_SYSCALL(setregid);
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/trace/blktrace.c b/kernel/trace/blktrace.c
index fac0ddf8a8e2..e1c6d79fb4cc 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -723,6 +723,7 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg)
723#endif 723#endif
724 case BLKTRACESTART: 724 case BLKTRACESTART:
725 start = 1; 725 start = 1;
726 /* fall through */
726 case BLKTRACESTOP: 727 case BLKTRACESTOP:
727 ret = __blk_trace_startstop(q, start); 728 ret = __blk_trace_startstop(q, start);
728 break; 729 break;
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index fa79323331b2..26c8ca9bd06b 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1992,7 +1992,7 @@ static void print_bug_type(void)
1992 * modifying the code. @failed should be one of either: 1992 * modifying the code. @failed should be one of either:
1993 * EFAULT - if the problem happens on reading the @ip address 1993 * EFAULT - if the problem happens on reading the @ip address
1994 * EINVAL - if what is read at @ip is not what was expected 1994 * EINVAL - if what is read at @ip is not what was expected
1995 * EPERM - if the problem happens on writting to the @ip address 1995 * EPERM - if the problem happens on writing to the @ip address
1996 */ 1996 */
1997void ftrace_bug(int failed, struct dyn_ftrace *rec) 1997void ftrace_bug(int failed, struct dyn_ftrace *rec)
1998{ 1998{
@@ -2391,7 +2391,7 @@ __ftrace_replace_code(struct dyn_ftrace *rec, int enable)
2391 return ftrace_modify_call(rec, ftrace_old_addr, ftrace_addr); 2391 return ftrace_modify_call(rec, ftrace_old_addr, ftrace_addr);
2392 } 2392 }
2393 2393
2394 return -1; /* unknow ftrace bug */ 2394 return -1; /* unknown ftrace bug */
2395} 2395}
2396 2396
2397void __weak ftrace_replace_code(int mod_flags) 2397void __weak ftrace_replace_code(int mod_flags)
@@ -3004,7 +3004,7 @@ ftrace_allocate_pages(unsigned long num_to_init)
3004 int cnt; 3004 int cnt;
3005 3005
3006 if (!num_to_init) 3006 if (!num_to_init)
3007 return 0; 3007 return NULL;
3008 3008
3009 start_pg = pg = kzalloc(sizeof(*pg), GFP_KERNEL); 3009 start_pg = pg = kzalloc(sizeof(*pg), GFP_KERNEL);
3010 if (!pg) 3010 if (!pg)
@@ -4755,7 +4755,7 @@ static int
4755ftrace_set_addr(struct ftrace_ops *ops, unsigned long ip, int remove, 4755ftrace_set_addr(struct ftrace_ops *ops, unsigned long ip, int remove,
4756 int reset, int enable) 4756 int reset, int enable)
4757{ 4757{
4758 return ftrace_set_hash(ops, 0, 0, ip, remove, reset, enable); 4758 return ftrace_set_hash(ops, NULL, 0, ip, remove, reset, enable);
4759} 4759}
4760 4760
4761/** 4761/**
@@ -5463,7 +5463,7 @@ void ftrace_create_filter_files(struct ftrace_ops *ops,
5463 5463
5464/* 5464/*
5465 * The name "destroy_filter_files" is really a misnomer. Although 5465 * The name "destroy_filter_files" is really a misnomer. Although
5466 * in the future, it may actualy delete the files, but this is 5466 * in the future, it may actually delete the files, but this is
5467 * really intended to make sure the ops passed in are disabled 5467 * really intended to make sure the ops passed in are disabled
5468 * and that when this function returns, the caller is free to 5468 * and that when this function returns, the caller is free to
5469 * free the ops. 5469 * free the ops.
@@ -5786,7 +5786,7 @@ void ftrace_module_enable(struct module *mod)
5786 /* 5786 /*
5787 * If the tracing is enabled, go ahead and enable the record. 5787 * If the tracing is enabled, go ahead and enable the record.
5788 * 5788 *
5789 * The reason not to enable the record immediatelly is the 5789 * The reason not to enable the record immediately is the
5790 * inherent check of ftrace_make_nop/ftrace_make_call for 5790 * inherent check of ftrace_make_nop/ftrace_make_call for
5791 * correct previous instructions. Making first the NOP 5791 * correct previous instructions. Making first the NOP
5792 * conversion puts the module to the correct state, thus 5792 * conversion puts the module to the correct state, thus
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 9a91479bbbfe..41b6f96e5366 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -4191,6 +4191,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_consume);
4191 * ring_buffer_read_prepare - Prepare for a non consuming read of the buffer 4191 * ring_buffer_read_prepare - Prepare for a non consuming read of the buffer
4192 * @buffer: The ring buffer to read from 4192 * @buffer: The ring buffer to read from
4193 * @cpu: The cpu buffer to iterate over 4193 * @cpu: The cpu buffer to iterate over
4194 * @flags: gfp flags to use for memory allocation
4194 * 4195 *
4195 * This performs the initial preparations necessary to iterate 4196 * This performs the initial preparations necessary to iterate
4196 * through the buffer. Memory is allocated, buffer recording 4197 * through the buffer. Memory is allocated, buffer recording
@@ -4208,7 +4209,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_consume);
4208 * This overall must be paired with ring_buffer_read_finish. 4209 * This overall must be paired with ring_buffer_read_finish.
4209 */ 4210 */
4210struct ring_buffer_iter * 4211struct ring_buffer_iter *
4211ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu) 4212ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu, gfp_t flags)
4212{ 4213{
4213 struct ring_buffer_per_cpu *cpu_buffer; 4214 struct ring_buffer_per_cpu *cpu_buffer;
4214 struct ring_buffer_iter *iter; 4215 struct ring_buffer_iter *iter;
@@ -4216,7 +4217,7 @@ ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu)
4216 if (!cpumask_test_cpu(cpu, buffer->cpumask)) 4217 if (!cpumask_test_cpu(cpu, buffer->cpumask))
4217 return NULL; 4218 return NULL;
4218 4219
4219 iter = kmalloc(sizeof(*iter), GFP_KERNEL); 4220 iter = kmalloc(sizeof(*iter), flags);
4220 if (!iter) 4221 if (!iter)
4221 return NULL; 4222 return NULL;
4222 4223
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 94ffc1c559d5..21153e64bf1c 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4079,7 +4079,8 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
4079 if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { 4079 if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
4080 for_each_tracing_cpu(cpu) { 4080 for_each_tracing_cpu(cpu) {
4081 iter->buffer_iter[cpu] = 4081 iter->buffer_iter[cpu] =
4082 ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); 4082 ring_buffer_read_prepare(iter->trace_buffer->buffer,
4083 cpu, GFP_KERNEL);
4083 } 4084 }
4084 ring_buffer_read_prepare_sync(); 4085 ring_buffer_read_prepare_sync();
4085 for_each_tracing_cpu(cpu) { 4086 for_each_tracing_cpu(cpu) {
@@ -4089,7 +4090,8 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
4089 } else { 4090 } else {
4090 cpu = iter->cpu_file; 4091 cpu = iter->cpu_file;
4091 iter->buffer_iter[cpu] = 4092 iter->buffer_iter[cpu] =
4092 ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); 4093 ring_buffer_read_prepare(iter->trace_buffer->buffer,
4094 cpu, GFP_KERNEL);
4093 ring_buffer_read_prepare_sync(); 4095 ring_buffer_read_prepare_sync();
4094 ring_buffer_read_start(iter->buffer_iter[cpu]); 4096 ring_buffer_read_start(iter->buffer_iter[cpu]);
4095 tracing_iter_reset(iter, cpu); 4097 tracing_iter_reset(iter, cpu);
diff --git a/kernel/trace/trace_dynevent.c b/kernel/trace/trace_dynevent.c
index dd1f43588d70..fa100ed3b4de 100644
--- a/kernel/trace/trace_dynevent.c
+++ b/kernel/trace/trace_dynevent.c
@@ -74,7 +74,7 @@ int dyn_event_release(int argc, char **argv, struct dyn_event_operations *type)
74static int create_dyn_event(int argc, char **argv) 74static int create_dyn_event(int argc, char **argv)
75{ 75{
76 struct dyn_event_operations *ops; 76 struct dyn_event_operations *ops;
77 int ret; 77 int ret = -ENODEV;
78 78
79 if (argv[0][0] == '-' || argv[0][0] == '!') 79 if (argv[0][0] == '-' || argv[0][0] == '!')
80 return dyn_event_release(argc, argv, NULL); 80 return dyn_event_release(argc, argv, NULL);
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index ca46339f3009..795aa2038377 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -3713,7 +3713,6 @@ static void track_data_destroy(struct hist_trigger_data *hist_data,
3713 struct trace_event_file *file = hist_data->event_file; 3713 struct trace_event_file *file = hist_data->event_file;
3714 3714
3715 destroy_hist_field(data->track_data.track_var, 0); 3715 destroy_hist_field(data->track_data.track_var, 0);
3716 destroy_hist_field(data->track_data.var_ref, 0);
3717 3716
3718 if (data->action == ACTION_SNAPSHOT) { 3717 if (data->action == ACTION_SNAPSHOT) {
3719 struct track_data *track_data; 3718 struct track_data *track_data;
diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c
index d953c163a079..810d78a8d14c 100644
--- a/kernel/trace/trace_kdb.c
+++ b/kernel/trace/trace_kdb.c
@@ -51,14 +51,16 @@ static void ftrace_dump_buf(int skip_lines, long cpu_file)
51 if (cpu_file == RING_BUFFER_ALL_CPUS) { 51 if (cpu_file == RING_BUFFER_ALL_CPUS) {
52 for_each_tracing_cpu(cpu) { 52 for_each_tracing_cpu(cpu) {
53 iter.buffer_iter[cpu] = 53 iter.buffer_iter[cpu] =
54 ring_buffer_read_prepare(iter.trace_buffer->buffer, cpu); 54 ring_buffer_read_prepare(iter.trace_buffer->buffer,
55 cpu, GFP_ATOMIC);
55 ring_buffer_read_start(iter.buffer_iter[cpu]); 56 ring_buffer_read_start(iter.buffer_iter[cpu]);
56 tracing_iter_reset(&iter, cpu); 57 tracing_iter_reset(&iter, cpu);
57 } 58 }
58 } else { 59 } else {
59 iter.cpu_file = cpu_file; 60 iter.cpu_file = cpu_file;
60 iter.buffer_iter[cpu_file] = 61 iter.buffer_iter[cpu_file] =
61 ring_buffer_read_prepare(iter.trace_buffer->buffer, cpu_file); 62 ring_buffer_read_prepare(iter.trace_buffer->buffer,
63 cpu_file, GFP_ATOMIC);
62 ring_buffer_read_start(iter.buffer_iter[cpu_file]); 64 ring_buffer_read_start(iter.buffer_iter[cpu_file]);
63 tracing_iter_reset(&iter, cpu_file); 65 tracing_iter_reset(&iter, cpu_file);
64 } 66 }
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 99592c27465e..5d5129b05df7 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -35,7 +35,7 @@ static struct dyn_event_operations trace_kprobe_ops = {
35 .match = trace_kprobe_match, 35 .match = trace_kprobe_match,
36}; 36};
37 37
38/** 38/*
39 * Kprobe event core functions 39 * Kprobe event core functions
40 */ 40 */
41struct trace_kprobe { 41struct trace_kprobe {
@@ -221,7 +221,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
221 221
222 tk->rp.maxactive = maxactive; 222 tk->rp.maxactive = maxactive;
223 223
224 if (!event || !is_good_name(event)) { 224 if (!event || !group) {
225 ret = -EINVAL; 225 ret = -EINVAL;
226 goto error; 226 goto error;
227 } 227 }
@@ -231,11 +231,6 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
231 if (!tk->tp.call.name) 231 if (!tk->tp.call.name)
232 goto error; 232 goto error;
233 233
234 if (!group || !is_good_name(group)) {
235 ret = -EINVAL;
236 goto error;
237 }
238
239 tk->tp.class.system = kstrdup(group, GFP_KERNEL); 234 tk->tp.class.system = kstrdup(group, GFP_KERNEL);
240 if (!tk->tp.class.system) 235 if (!tk->tp.class.system)
241 goto error; 236 goto error;
@@ -624,7 +619,11 @@ static int trace_kprobe_create(int argc, const char *argv[])
624 if (event) 619 if (event)
625 event++; 620 event++;
626 621
627 if (is_return && isdigit(argv[0][1])) { 622 if (isdigit(argv[0][1])) {
623 if (!is_return) {
624 pr_info("Maxactive is not for kprobe");
625 return -EINVAL;
626 }
628 if (event) 627 if (event)
629 len = event - &argv[0][1] - 1; 628 len = event - &argv[0][1] - 1;
630 else 629 else
@@ -634,8 +633,8 @@ static int trace_kprobe_create(int argc, const char *argv[])
634 memcpy(buf, &argv[0][1], len); 633 memcpy(buf, &argv[0][1], len);
635 buf[len] = '\0'; 634 buf[len] = '\0';
636 ret = kstrtouint(buf, 0, &maxactive); 635 ret = kstrtouint(buf, 0, &maxactive);
637 if (ret) { 636 if (ret || !maxactive) {
638 pr_info("Failed to parse maxactive.\n"); 637 pr_info("Invalid maxactive number\n");
639 return ret; 638 return ret;
640 } 639 }
641 /* kretprobes instances are iterated over via a list. The 640 /* kretprobes instances are iterated over via a list. The
@@ -694,9 +693,9 @@ static int trace_kprobe_create(int argc, const char *argv[])
694 tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive, 693 tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive,
695 argc, is_return); 694 argc, is_return);
696 if (IS_ERR(tk)) { 695 if (IS_ERR(tk)) {
697 pr_info("Failed to allocate trace_probe.(%d)\n",
698 (int)PTR_ERR(tk));
699 ret = PTR_ERR(tk); 696 ret = PTR_ERR(tk);
697 /* This must return -ENOMEM otherwise there is a bug */
698 WARN_ON_ONCE(ret != -ENOMEM);
700 goto out; 699 goto out;
701 } 700 }
702 701
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 89da34b326e3..8f8411e7835f 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -13,7 +13,7 @@
13 13
14#include "trace_probe.h" 14#include "trace_probe.h"
15 15
16const char *reserved_field_names[] = { 16static const char *reserved_field_names[] = {
17 "common_type", 17 "common_type",
18 "common_flags", 18 "common_flags",
19 "common_preempt_count", 19 "common_preempt_count",
@@ -159,6 +159,7 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
159 char *buf) 159 char *buf)
160{ 160{
161 const char *slash, *event = *pevent; 161 const char *slash, *event = *pevent;
162 int len;
162 163
163 slash = strchr(event, '/'); 164 slash = strchr(event, '/');
164 if (slash) { 165 if (slash) {
@@ -171,12 +172,25 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
171 return -E2BIG; 172 return -E2BIG;
172 } 173 }
173 strlcpy(buf, event, slash - event + 1); 174 strlcpy(buf, event, slash - event + 1);
175 if (!is_good_name(buf)) {
176 pr_info("Group name must follow the same rules as C identifiers\n");
177 return -EINVAL;
178 }
174 *pgroup = buf; 179 *pgroup = buf;
175 *pevent = slash + 1; 180 *pevent = slash + 1;
181 event = *pevent;
176 } 182 }
177 if (strlen(event) == 0) { 183 len = strlen(event);
184 if (len == 0) {
178 pr_info("Event name is not specified\n"); 185 pr_info("Event name is not specified\n");
179 return -EINVAL; 186 return -EINVAL;
187 } else if (len > MAX_EVENT_NAME_LEN) {
188 pr_info("Event name is too long\n");
189 return -E2BIG;
190 }
191 if (!is_good_name(event)) {
192 pr_info("Event name must follow the same rules as C identifiers\n");
193 return -EINVAL;
180 } 194 }
181 return 0; 195 return 0;
182} 196}
@@ -548,6 +562,8 @@ int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, char *arg,
548 562
549 body = strchr(arg, '='); 563 body = strchr(arg, '=');
550 if (body) { 564 if (body) {
565 if (body - arg > MAX_ARG_NAME_LEN || body == arg)
566 return -EINVAL;
551 parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL); 567 parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL);
552 body++; 568 body++;
553 } else { 569 } else {
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index 8a63f8bc01bc..2177c206de15 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -32,6 +32,7 @@
32#define MAX_TRACE_ARGS 128 32#define MAX_TRACE_ARGS 128
33#define MAX_ARGSTR_LEN 63 33#define MAX_ARGSTR_LEN 63
34#define MAX_ARRAY_LEN 64 34#define MAX_ARRAY_LEN 64
35#define MAX_ARG_NAME_LEN 32
35#define MAX_STRING_SIZE PATH_MAX 36#define MAX_STRING_SIZE PATH_MAX
36 37
37/* Reserved field names */ 38/* Reserved field names */
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 9bde07c06362..be78d99ee6bc 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -273,10 +273,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
273{ 273{
274 struct trace_uprobe *tu; 274 struct trace_uprobe *tu;
275 275
276 if (!event || !is_good_name(event)) 276 if (!event || !group)
277 return ERR_PTR(-EINVAL);
278
279 if (!group || !is_good_name(group))
280 return ERR_PTR(-EINVAL); 277 return ERR_PTR(-EINVAL);
281 278
282 tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL); 279 tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL);
@@ -524,8 +521,9 @@ static int trace_uprobe_create(int argc, const char **argv)
524 521
525 tu = alloc_trace_uprobe(group, event, argc, is_return); 522 tu = alloc_trace_uprobe(group, event, argc, is_return);
526 if (IS_ERR(tu)) { 523 if (IS_ERR(tu)) {
527 pr_info("Failed to allocate trace_uprobe.(%d)\n", (int)PTR_ERR(tu));
528 ret = PTR_ERR(tu); 524 ret = PTR_ERR(tu);
525 /* This must return -ENOMEM otherwise there is a bug */
526 WARN_ON_ONCE(ret != -ENOMEM);
529 goto fail_address_parse; 527 goto fail_address_parse;
530 } 528 }
531 tu->offset = offset; 529 tu->offset = offset;
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/lib/Makefile b/lib/Makefile
index 4e066120a0d6..3b08673e8881 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -213,7 +213,7 @@ KCOV_INSTRUMENT_stackdepot.o := n
213libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \ 213libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \
214 fdt_empty_tree.o 214 fdt_empty_tree.o
215$(foreach file, $(libfdt_files), \ 215$(foreach file, $(libfdt_files), \
216 $(eval CFLAGS_$(file) = -I$(src)/../scripts/dtc/libfdt)) 216 $(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
217lib-$(CONFIG_LIBFDT) += $(libfdt_files) 217lib-$(CONFIG_LIBFDT) += $(libfdt_files)
218 218
219obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o 219obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
diff --git a/lib/raid6/Makefile b/lib/raid6/Makefile
index 4e90d443d1b0..e723eacf7868 100644
--- a/lib/raid6/Makefile
+++ b/lib/raid6/Makefile
@@ -39,7 +39,7 @@ endif
39ifeq ($(CONFIG_KERNEL_MODE_NEON),y) 39ifeq ($(CONFIG_KERNEL_MODE_NEON),y)
40NEON_FLAGS := -ffreestanding 40NEON_FLAGS := -ffreestanding
41ifeq ($(ARCH),arm) 41ifeq ($(ARCH),arm)
42NEON_FLAGS += -mfloat-abi=softfp -mfpu=neon 42NEON_FLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=neon
43endif 43endif
44CFLAGS_recov_neon_inner.o += $(NEON_FLAGS) 44CFLAGS_recov_neon_inner.o += $(NEON_FLAGS)
45ifeq ($(ARCH),arm64) 45ifeq ($(ARCH),arm64)
diff --git a/mm/filemap.c b/mm/filemap.c
index ec6566ffbd90..d78f577baef2 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1587,6 +1587,9 @@ EXPORT_SYMBOL(find_lock_entry);
1587 * @gfp_mask and added to the page cache and the VM's LRU 1587 * @gfp_mask and added to the page cache and the VM's LRU
1588 * list. The page is returned locked and with an increased 1588 * list. The page is returned locked and with an increased
1589 * refcount. 1589 * refcount.
1590 * - FGP_FOR_MMAP: Similar to FGP_CREAT, only we want to allow the caller to do
1591 * its own locking dance if the page is already in cache, or unlock the page
1592 * before returning if we had to add the page to pagecache.
1590 * 1593 *
1591 * If FGP_LOCK or FGP_CREAT are specified then the function may sleep even 1594 * If FGP_LOCK or FGP_CREAT are specified then the function may sleep even
1592 * if the GFP flags specified for FGP_CREAT are atomic. 1595 * if the GFP flags specified for FGP_CREAT are atomic.
@@ -1641,7 +1644,7 @@ no_page:
1641 if (!page) 1644 if (!page)
1642 return NULL; 1645 return NULL;
1643 1646
1644 if (WARN_ON_ONCE(!(fgp_flags & FGP_LOCK))) 1647 if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP))))
1645 fgp_flags |= FGP_LOCK; 1648 fgp_flags |= FGP_LOCK;
1646 1649
1647 /* Init accessed so avoid atomic mark_page_accessed later */ 1650 /* Init accessed so avoid atomic mark_page_accessed later */
@@ -1655,6 +1658,13 @@ no_page:
1655 if (err == -EEXIST) 1658 if (err == -EEXIST)
1656 goto repeat; 1659 goto repeat;
1657 } 1660 }
1661
1662 /*
1663 * add_to_page_cache_lru locks the page, and for mmap we expect
1664 * an unlocked page.
1665 */
1666 if (page && (fgp_flags & FGP_FOR_MMAP))
1667 unlock_page(page);
1658 } 1668 }
1659 1669
1660 return page; 1670 return page;
@@ -2379,64 +2389,98 @@ out:
2379EXPORT_SYMBOL(generic_file_read_iter); 2389EXPORT_SYMBOL(generic_file_read_iter);
2380 2390
2381#ifdef CONFIG_MMU 2391#ifdef CONFIG_MMU
2382/** 2392#define MMAP_LOTSAMISS (100)
2383 * page_cache_read - adds requested page to the page cache if not already there 2393static struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
2384 * @file: file to read 2394 struct file *fpin)
2385 * @offset: page index
2386 * @gfp_mask: memory allocation flags
2387 *
2388 * This adds the requested page to the page cache if it isn't already there,
2389 * and schedules an I/O to read in its contents from disk.
2390 *
2391 * Return: %0 on success, negative error code otherwise.
2392 */
2393static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask)
2394{ 2395{
2395 struct address_space *mapping = file->f_mapping; 2396 int flags = vmf->flags;
2396 struct page *page;
2397 int ret;
2398 2397
2399 do { 2398 if (fpin)
2400 page = __page_cache_alloc(gfp_mask); 2399 return fpin;
2401 if (!page)
2402 return -ENOMEM;
2403 2400
2404 ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask); 2401 /*
2405 if (ret == 0) 2402 * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or
2406 ret = mapping->a_ops->readpage(file, page); 2403 * anything, so we only pin the file and drop the mmap_sem if only
2407 else if (ret == -EEXIST) 2404 * FAULT_FLAG_ALLOW_RETRY is set.
2408 ret = 0; /* losing race to add is OK */ 2405 */
2406 if ((flags & (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT)) ==
2407 FAULT_FLAG_ALLOW_RETRY) {
2408 fpin = get_file(vmf->vma->vm_file);
2409 up_read(&vmf->vma->vm_mm->mmap_sem);
2410 }
2411 return fpin;
2412}
2409 2413
2410 put_page(page); 2414/*
2415 * lock_page_maybe_drop_mmap - lock the page, possibly dropping the mmap_sem
2416 * @vmf - the vm_fault for this fault.
2417 * @page - the page to lock.
2418 * @fpin - the pointer to the file we may pin (or is already pinned).
2419 *
2420 * This works similar to lock_page_or_retry in that it can drop the mmap_sem.
2421 * It differs in that it actually returns the page locked if it returns 1 and 0
2422 * if it couldn't lock the page. If we did have to drop the mmap_sem then fpin
2423 * will point to the pinned file and needs to be fput()'ed at a later point.
2424 */
2425static int lock_page_maybe_drop_mmap(struct vm_fault *vmf, struct page *page,
2426 struct file **fpin)
2427{
2428 if (trylock_page(page))
2429 return 1;
2411 2430
2412 } while (ret == AOP_TRUNCATED_PAGE); 2431 /*
2432 * NOTE! This will make us return with VM_FAULT_RETRY, but with
2433 * the mmap_sem still held. That's how FAULT_FLAG_RETRY_NOWAIT
2434 * is supposed to work. We have way too many special cases..
2435 */
2436 if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT)
2437 return 0;
2413 2438
2414 return ret; 2439 *fpin = maybe_unlock_mmap_for_io(vmf, *fpin);
2440 if (vmf->flags & FAULT_FLAG_KILLABLE) {
2441 if (__lock_page_killable(page)) {
2442 /*
2443 * We didn't have the right flags to drop the mmap_sem,
2444 * but all fault_handlers only check for fatal signals
2445 * if we return VM_FAULT_RETRY, so we need to drop the
2446 * mmap_sem here and return 0 if we don't have a fpin.
2447 */
2448 if (*fpin == NULL)
2449 up_read(&vmf->vma->vm_mm->mmap_sem);
2450 return 0;
2451 }
2452 } else
2453 __lock_page(page);
2454 return 1;
2415} 2455}
2416 2456
2417#define MMAP_LOTSAMISS (100)
2418 2457
2419/* 2458/*
2420 * Synchronous readahead happens when we don't even find 2459 * Synchronous readahead happens when we don't even find a page in the page
2421 * a page in the page cache at all. 2460 * cache at all. We don't want to perform IO under the mmap sem, so if we have
2461 * to drop the mmap sem we return the file that was pinned in order for us to do
2462 * that. If we didn't pin a file then we return NULL. The file that is
2463 * returned needs to be fput()'ed when we're done with it.
2422 */ 2464 */
2423static void do_sync_mmap_readahead(struct vm_fault *vmf) 2465static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
2424{ 2466{
2425 struct file *file = vmf->vma->vm_file; 2467 struct file *file = vmf->vma->vm_file;
2426 struct file_ra_state *ra = &file->f_ra; 2468 struct file_ra_state *ra = &file->f_ra;
2427 struct address_space *mapping = file->f_mapping; 2469 struct address_space *mapping = file->f_mapping;
2470 struct file *fpin = NULL;
2428 pgoff_t offset = vmf->pgoff; 2471 pgoff_t offset = vmf->pgoff;
2429 2472
2430 /* If we don't want any read-ahead, don't bother */ 2473 /* If we don't want any read-ahead, don't bother */
2431 if (vmf->vma->vm_flags & VM_RAND_READ) 2474 if (vmf->vma->vm_flags & VM_RAND_READ)
2432 return; 2475 return fpin;
2433 if (!ra->ra_pages) 2476 if (!ra->ra_pages)
2434 return; 2477 return fpin;
2435 2478
2436 if (vmf->vma->vm_flags & VM_SEQ_READ) { 2479 if (vmf->vma->vm_flags & VM_SEQ_READ) {
2480 fpin = maybe_unlock_mmap_for_io(vmf, fpin);
2437 page_cache_sync_readahead(mapping, ra, file, offset, 2481 page_cache_sync_readahead(mapping, ra, file, offset,
2438 ra->ra_pages); 2482 ra->ra_pages);
2439 return; 2483 return fpin;
2440 } 2484 }
2441 2485
2442 /* Avoid banging the cache line if not needed */ 2486 /* Avoid banging the cache line if not needed */
@@ -2448,37 +2492,44 @@ static void do_sync_mmap_readahead(struct vm_fault *vmf)
2448 * stop bothering with read-ahead. It will only hurt. 2492 * stop bothering with read-ahead. It will only hurt.
2449 */ 2493 */
2450 if (ra->mmap_miss > MMAP_LOTSAMISS) 2494 if (ra->mmap_miss > MMAP_LOTSAMISS)
2451 return; 2495 return fpin;
2452 2496
2453 /* 2497 /*
2454 * mmap read-around 2498 * mmap read-around
2455 */ 2499 */
2500 fpin = maybe_unlock_mmap_for_io(vmf, fpin);
2456 ra->start = max_t(long, 0, offset - ra->ra_pages / 2); 2501 ra->start = max_t(long, 0, offset - ra->ra_pages / 2);
2457 ra->size = ra->ra_pages; 2502 ra->size = ra->ra_pages;
2458 ra->async_size = ra->ra_pages / 4; 2503 ra->async_size = ra->ra_pages / 4;
2459 ra_submit(ra, mapping, file); 2504 ra_submit(ra, mapping, file);
2505 return fpin;
2460} 2506}
2461 2507
2462/* 2508/*
2463 * Asynchronous readahead happens when we find the page and PG_readahead, 2509 * Asynchronous readahead happens when we find the page and PG_readahead,
2464 * so we want to possibly extend the readahead further.. 2510 * so we want to possibly extend the readahead further. We return the file that
2511 * was pinned if we have to drop the mmap_sem in order to do IO.
2465 */ 2512 */
2466static void do_async_mmap_readahead(struct vm_fault *vmf, 2513static struct file *do_async_mmap_readahead(struct vm_fault *vmf,
2467 struct page *page) 2514 struct page *page)
2468{ 2515{
2469 struct file *file = vmf->vma->vm_file; 2516 struct file *file = vmf->vma->vm_file;
2470 struct file_ra_state *ra = &file->f_ra; 2517 struct file_ra_state *ra = &file->f_ra;
2471 struct address_space *mapping = file->f_mapping; 2518 struct address_space *mapping = file->f_mapping;
2519 struct file *fpin = NULL;
2472 pgoff_t offset = vmf->pgoff; 2520 pgoff_t offset = vmf->pgoff;
2473 2521
2474 /* If we don't want any read-ahead, don't bother */ 2522 /* If we don't want any read-ahead, don't bother */
2475 if (vmf->vma->vm_flags & VM_RAND_READ) 2523 if (vmf->vma->vm_flags & VM_RAND_READ)
2476 return; 2524 return fpin;
2477 if (ra->mmap_miss > 0) 2525 if (ra->mmap_miss > 0)
2478 ra->mmap_miss--; 2526 ra->mmap_miss--;
2479 if (PageReadahead(page)) 2527 if (PageReadahead(page)) {
2528 fpin = maybe_unlock_mmap_for_io(vmf, fpin);
2480 page_cache_async_readahead(mapping, ra, file, 2529 page_cache_async_readahead(mapping, ra, file,
2481 page, offset, ra->ra_pages); 2530 page, offset, ra->ra_pages);
2531 }
2532 return fpin;
2482} 2533}
2483 2534
2484/** 2535/**
@@ -2510,6 +2561,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
2510{ 2561{
2511 int error; 2562 int error;
2512 struct file *file = vmf->vma->vm_file; 2563 struct file *file = vmf->vma->vm_file;
2564 struct file *fpin = NULL;
2513 struct address_space *mapping = file->f_mapping; 2565 struct address_space *mapping = file->f_mapping;
2514 struct file_ra_state *ra = &file->f_ra; 2566 struct file_ra_state *ra = &file->f_ra;
2515 struct inode *inode = mapping->host; 2567 struct inode *inode = mapping->host;
@@ -2531,23 +2583,26 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
2531 * We found the page, so try async readahead before 2583 * We found the page, so try async readahead before
2532 * waiting for the lock. 2584 * waiting for the lock.
2533 */ 2585 */
2534 do_async_mmap_readahead(vmf, page); 2586 fpin = do_async_mmap_readahead(vmf, page);
2535 } else if (!page) { 2587 } else if (!page) {
2536 /* No page in the page cache at all */ 2588 /* No page in the page cache at all */
2537 do_sync_mmap_readahead(vmf);
2538 count_vm_event(PGMAJFAULT); 2589 count_vm_event(PGMAJFAULT);
2539 count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT); 2590 count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT);
2540 ret = VM_FAULT_MAJOR; 2591 ret = VM_FAULT_MAJOR;
2592 fpin = do_sync_mmap_readahead(vmf);
2541retry_find: 2593retry_find:
2542 page = find_get_page(mapping, offset); 2594 page = pagecache_get_page(mapping, offset,
2543 if (!page) 2595 FGP_CREAT|FGP_FOR_MMAP,
2544 goto no_cached_page; 2596 vmf->gfp_mask);
2597 if (!page) {
2598 if (fpin)
2599 goto out_retry;
2600 return vmf_error(-ENOMEM);
2601 }
2545 } 2602 }
2546 2603
2547 if (!lock_page_or_retry(page, vmf->vma->vm_mm, vmf->flags)) { 2604 if (!lock_page_maybe_drop_mmap(vmf, page, &fpin))
2548 put_page(page); 2605 goto out_retry;
2549 return ret | VM_FAULT_RETRY;
2550 }
2551 2606
2552 /* Did it get truncated? */ 2607 /* Did it get truncated? */
2553 if (unlikely(page->mapping != mapping)) { 2608 if (unlikely(page->mapping != mapping)) {
@@ -2565,6 +2620,16 @@ retry_find:
2565 goto page_not_uptodate; 2620 goto page_not_uptodate;
2566 2621
2567 /* 2622 /*
2623 * We've made it this far and we had to drop our mmap_sem, now is the
2624 * time to return to the upper layer and have it re-find the vma and
2625 * redo the fault.
2626 */
2627 if (fpin) {
2628 unlock_page(page);
2629 goto out_retry;
2630 }
2631
2632 /*
2568 * Found the page and have a reference on it. 2633 * Found the page and have a reference on it.
2569 * We must recheck i_size under page lock. 2634 * We must recheck i_size under page lock.
2570 */ 2635 */
@@ -2578,28 +2643,6 @@ retry_find:
2578 vmf->page = page; 2643 vmf->page = page;
2579 return ret | VM_FAULT_LOCKED; 2644 return ret | VM_FAULT_LOCKED;
2580 2645
2581no_cached_page:
2582 /*
2583 * We're only likely to ever get here if MADV_RANDOM is in
2584 * effect.
2585 */
2586 error = page_cache_read(file, offset, vmf->gfp_mask);
2587
2588 /*
2589 * The page we want has now been added to the page cache.
2590 * In the unlikely event that someone removed it in the
2591 * meantime, we'll just come back here and read it again.
2592 */
2593 if (error >= 0)
2594 goto retry_find;
2595
2596 /*
2597 * An error return from page_cache_read can result if the
2598 * system is low on memory, or a problem occurs while trying
2599 * to schedule I/O.
2600 */
2601 return vmf_error(error);
2602
2603page_not_uptodate: 2646page_not_uptodate:
2604 /* 2647 /*
2605 * Umm, take care of errors if the page isn't up-to-date. 2648 * Umm, take care of errors if the page isn't up-to-date.
@@ -2608,12 +2651,15 @@ page_not_uptodate:
2608 * and we need to check for errors. 2651 * and we need to check for errors.
2609 */ 2652 */
2610 ClearPageError(page); 2653 ClearPageError(page);
2654 fpin = maybe_unlock_mmap_for_io(vmf, fpin);
2611 error = mapping->a_ops->readpage(file, page); 2655 error = mapping->a_ops->readpage(file, page);
2612 if (!error) { 2656 if (!error) {
2613 wait_on_page_locked(page); 2657 wait_on_page_locked(page);
2614 if (!PageUptodate(page)) 2658 if (!PageUptodate(page))
2615 error = -EIO; 2659 error = -EIO;
2616 } 2660 }
2661 if (fpin)
2662 goto out_retry;
2617 put_page(page); 2663 put_page(page);
2618 2664
2619 if (!error || error == AOP_TRUNCATED_PAGE) 2665 if (!error || error == AOP_TRUNCATED_PAGE)
@@ -2622,6 +2668,18 @@ page_not_uptodate:
2622 /* Things didn't work out. Return zero to tell the mm layer so. */ 2668 /* Things didn't work out. Return zero to tell the mm layer so. */
2623 shrink_readahead_size_eio(file, ra); 2669 shrink_readahead_size_eio(file, ra);
2624 return VM_FAULT_SIGBUS; 2670 return VM_FAULT_SIGBUS;
2671
2672out_retry:
2673 /*
2674 * We dropped the mmap_sem, we need to return to the fault handler to
2675 * re-find the vma and come back and find our hopefully still populated
2676 * page.
2677 */
2678 if (page)
2679 put_page(page);
2680 if (fpin)
2681 fput(fpin);
2682 return ret | VM_FAULT_RETRY;
2625} 2683}
2626EXPORT_SYMBOL(filemap_fault); 2684EXPORT_SYMBOL(filemap_fault);
2627 2685
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index cd23c081924d..f767582af4f8 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -101,28 +101,24 @@ u64 max_mem_size = U64_MAX;
101/* add this memory to iomem resource */ 101/* add this memory to iomem resource */
102static struct resource *register_memory_resource(u64 start, u64 size) 102static struct resource *register_memory_resource(u64 start, u64 size)
103{ 103{
104 struct resource *res, *conflict; 104 struct resource *res;
105 unsigned long flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
106 char *resource_name = "System RAM";
105 107
106 if (start + size > max_mem_size) 108 if (start + size > max_mem_size)
107 return ERR_PTR(-E2BIG); 109 return ERR_PTR(-E2BIG);
108 110
109 res = kzalloc(sizeof(struct resource), GFP_KERNEL); 111 /*
110 if (!res) 112 * Request ownership of the new memory range. This might be
111 return ERR_PTR(-ENOMEM); 113 * a child of an existing resource that was present but
112 114 * not marked as busy.
113 res->name = "System RAM"; 115 */
114 res->start = start; 116 res = __request_region(&iomem_resource, start, size,
115 res->end = start + size - 1; 117 resource_name, flags);
116 res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; 118
117 conflict = request_resource_conflict(&iomem_resource, res); 119 if (!res) {
118 if (conflict) { 120 pr_debug("Unable to reserve System RAM region: %016llx->%016llx\n",
119 if (conflict->desc == IORES_DESC_DEVICE_PRIVATE_MEMORY) { 121 start, start + size);
120 pr_debug("Device unaddressable memory block "
121 "memory hotplug at %#010llx !\n",
122 (unsigned long long)start);
123 }
124 pr_debug("System RAM resource %pR cannot be added\n", res);
125 kfree(res);
126 return ERR_PTR(-EEXIST); 122 return ERR_PTR(-EEXIST);
127 } 123 }
128 return res; 124 return res;
diff --git a/net/9p/client.c b/net/9p/client.c
index 357214a51f13..b85d51f4b8eb 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -1061,7 +1061,7 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
1061 p9_debug(P9_DEBUG_ERROR, 1061 p9_debug(P9_DEBUG_ERROR,
1062 "Please specify a msize of at least 4k\n"); 1062 "Please specify a msize of at least 4k\n");
1063 err = -EINVAL; 1063 err = -EINVAL;
1064 goto free_client; 1064 goto close_trans;
1065 } 1065 }
1066 1066
1067 err = p9_client_version(clnt); 1067 err = p9_client_version(clnt);
diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c
index e2fbf3677b9b..29420ebb8f07 100644
--- a/net/9p/trans_xen.c
+++ b/net/9p/trans_xen.c
@@ -513,7 +513,7 @@ static void xen_9pfs_front_changed(struct xenbus_device *dev,
513 case XenbusStateClosed: 513 case XenbusStateClosed:
514 if (dev->state == XenbusStateClosed) 514 if (dev->state == XenbusStateClosed)
515 break; 515 break;
516 /* Missed the backend's CLOSING state -- fallthrough */ 516 /* fall through - Missed the backend's CLOSING state */
517 case XenbusStateClosing: 517 case XenbusStateClosing:
518 xenbus_frontend_closed(dev); 518 xenbus_frontend_closed(dev);
519 break; 519 break;
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/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 4216fe33204a..187d10443a15 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -1730,7 +1730,12 @@ call_allocate(struct rpc_task *task)
1730 req->rq_callsize = RPC_CALLHDRSIZE + (auth->au_cslack << 1) + 1730 req->rq_callsize = RPC_CALLHDRSIZE + (auth->au_cslack << 1) +
1731 proc->p_arglen; 1731 proc->p_arglen;
1732 req->rq_callsize <<= 2; 1732 req->rq_callsize <<= 2;
1733 req->rq_rcvsize = RPC_REPHDRSIZE + auth->au_rslack + proc->p_replen; 1733 /*
1734 * Note: the reply buffer must at minimum allocate enough space
1735 * for the 'struct accepted_reply' from RFC5531.
1736 */
1737 req->rq_rcvsize = RPC_REPHDRSIZE + auth->au_rslack + \
1738 max_t(size_t, proc->p_replen, 2);
1734 req->rq_rcvsize <<= 2; 1739 req->rq_rcvsize <<= 2;
1735 1740
1736 status = xprt->ops->buf_alloc(task); 1741 status = xprt->ops->buf_alloc(task);
@@ -2306,6 +2311,15 @@ out_exit:
2306 rpc_exit(task, status); 2311 rpc_exit(task, status);
2307} 2312}
2308 2313
2314static bool
2315rpc_check_connected(const struct rpc_rqst *req)
2316{
2317 /* No allocated request or transport? return true */
2318 if (!req || !req->rq_xprt)
2319 return true;
2320 return xprt_connected(req->rq_xprt);
2321}
2322
2309static void 2323static void
2310rpc_check_timeout(struct rpc_task *task) 2324rpc_check_timeout(struct rpc_task *task)
2311{ 2325{
@@ -2317,10 +2331,11 @@ rpc_check_timeout(struct rpc_task *task)
2317 dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid); 2331 dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid);
2318 task->tk_timeouts++; 2332 task->tk_timeouts++;
2319 2333
2320 if (RPC_IS_SOFTCONN(task)) { 2334 if (RPC_IS_SOFTCONN(task) && !rpc_check_connected(task->tk_rqstp)) {
2321 rpc_exit(task, -ETIMEDOUT); 2335 rpc_exit(task, -ETIMEDOUT);
2322 return; 2336 return;
2323 } 2337 }
2338
2324 if (RPC_IS_SOFT(task)) { 2339 if (RPC_IS_SOFT(task)) {
2325 if (clnt->cl_chatty) { 2340 if (clnt->cl_chatty) {
2326 printk(KERN_NOTICE "%s: server %s not responding, timed out\n", 2341 printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
@@ -2387,9 +2402,6 @@ call_decode(struct rpc_task *task)
2387 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf, 2402 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
2388 sizeof(req->rq_rcv_buf)) != 0); 2403 sizeof(req->rq_rcv_buf)) != 0);
2389 2404
2390 if (req->rq_rcv_buf.len < 12)
2391 goto out_retry;
2392
2393 xdr_init_decode(&xdr, &req->rq_rcv_buf, 2405 xdr_init_decode(&xdr, &req->rq_rcv_buf,
2394 req->rq_rcv_buf.head[0].iov_base, req); 2406 req->rq_rcv_buf.head[0].iov_base, req);
2395 switch (rpc_decode_header(task, &xdr)) { 2407 switch (rpc_decode_header(task, &xdr)) {
@@ -2400,7 +2412,6 @@ call_decode(struct rpc_task *task)
2400 task->tk_pid, __func__, task->tk_status); 2412 task->tk_pid, __func__, task->tk_status);
2401 return; 2413 return;
2402 case -EAGAIN: 2414 case -EAGAIN:
2403out_retry:
2404 task->tk_status = 0; 2415 task->tk_status = 0;
2405 /* Note: rpc_decode_header() may have freed the RPC slot */ 2416 /* Note: rpc_decode_header() may have freed the RPC slot */
2406 if (task->tk_rqstp == req) { 2417 if (task->tk_rqstp == req) {
@@ -2449,7 +2460,7 @@ static noinline int
2449rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) 2460rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr)
2450{ 2461{
2451 struct rpc_clnt *clnt = task->tk_client; 2462 struct rpc_clnt *clnt = task->tk_client;
2452 int error = -EACCES; 2463 int error;
2453 __be32 *p; 2464 __be32 *p;
2454 2465
2455 /* RFC-1014 says that the representation of XDR data must be a 2466 /* RFC-1014 says that the representation of XDR data must be a
@@ -2458,7 +2469,7 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr)
2458 * undefined results 2469 * undefined results
2459 */ 2470 */
2460 if (task->tk_rqstp->rq_rcv_buf.len & 3) 2471 if (task->tk_rqstp->rq_rcv_buf.len & 3)
2461 goto out_badlen; 2472 goto out_unparsable;
2462 2473
2463 p = xdr_inline_decode(xdr, 3 * sizeof(*p)); 2474 p = xdr_inline_decode(xdr, 3 * sizeof(*p));
2464 if (!p) 2475 if (!p)
@@ -2492,10 +2503,12 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr)
2492 error = -EOPNOTSUPP; 2503 error = -EOPNOTSUPP;
2493 goto out_err; 2504 goto out_err;
2494 case rpc_garbage_args: 2505 case rpc_garbage_args:
2506 case rpc_system_err:
2495 trace_rpc__garbage_args(task); 2507 trace_rpc__garbage_args(task);
2508 error = -EIO;
2496 break; 2509 break;
2497 default: 2510 default:
2498 trace_rpc__unparsable(task); 2511 goto out_unparsable;
2499 } 2512 }
2500 2513
2501out_garbage: 2514out_garbage:
@@ -2509,11 +2522,6 @@ out_err:
2509 rpc_exit(task, error); 2522 rpc_exit(task, error);
2510 return error; 2523 return error;
2511 2524
2512out_badlen:
2513 trace_rpc__unparsable(task);
2514 error = -EIO;
2515 goto out_err;
2516
2517out_unparsable: 2525out_unparsable:
2518 trace_rpc__unparsable(task); 2526 trace_rpc__unparsable(task);
2519 error = -EIO; 2527 error = -EIO;
@@ -2524,6 +2532,7 @@ out_verifier:
2524 goto out_garbage; 2532 goto out_garbage;
2525 2533
2526out_msg_denied: 2534out_msg_denied:
2535 error = -EACCES;
2527 p = xdr_inline_decode(xdr, sizeof(*p)); 2536 p = xdr_inline_decode(xdr, sizeof(*p));
2528 if (!p) 2537 if (!p)
2529 goto out_unparsable; 2538 goto out_unparsable;
@@ -2535,9 +2544,7 @@ out_msg_denied:
2535 error = -EPROTONOSUPPORT; 2544 error = -EPROTONOSUPPORT;
2536 goto out_err; 2545 goto out_err;
2537 default: 2546 default:
2538 trace_rpc__unparsable(task); 2547 goto out_unparsable;
2539 error = -EIO;
2540 goto out_err;
2541 } 2548 }
2542 2549
2543 p = xdr_inline_decode(xdr, sizeof(*p)); 2550 p = xdr_inline_decode(xdr, sizeof(*p));
@@ -2572,8 +2579,7 @@ out_msg_denied:
2572 task->tk_xprt->servername); 2579 task->tk_xprt->servername);
2573 break; 2580 break;
2574 default: 2581 default:
2575 trace_rpc__unparsable(task); 2582 goto out_unparsable;
2576 error = -EIO;
2577 } 2583 }
2578 goto out_err; 2584 goto out_err;
2579} 2585}
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index e096c5a725df..d7117d241460 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -664,7 +664,7 @@ void xprt_disconnect_done(struct rpc_xprt *xprt)
664 spin_lock_bh(&xprt->transport_lock); 664 spin_lock_bh(&xprt->transport_lock);
665 xprt_clear_connected(xprt); 665 xprt_clear_connected(xprt);
666 xprt_clear_write_space_locked(xprt); 666 xprt_clear_write_space_locked(xprt);
667 xprt_wake_pending_tasks(xprt, -EAGAIN); 667 xprt_wake_pending_tasks(xprt, -ENOTCONN);
668 spin_unlock_bh(&xprt->transport_lock); 668 spin_unlock_bh(&xprt->transport_lock);
669} 669}
670EXPORT_SYMBOL_GPL(xprt_disconnect_done); 670EXPORT_SYMBOL_GPL(xprt_disconnect_done);
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 42f45d33dc56..732d4b57411a 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -453,7 +453,7 @@ xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags,
453 goto out; 453 goto out;
454 if (ret != want) 454 if (ret != want)
455 goto out; 455 goto out;
456 } else 456 } else if (offset < seek_init)
457 offset = seek_init; 457 offset = seek_init;
458 ret = -EMSGSIZE; 458 ret = -EMSGSIZE;
459out: 459out:
@@ -495,8 +495,8 @@ xs_read_stream_request(struct sock_xprt *transport, struct msghdr *msg,
495 int flags, struct rpc_rqst *req) 495 int flags, struct rpc_rqst *req)
496{ 496{
497 struct xdr_buf *buf = &req->rq_private_buf; 497 struct xdr_buf *buf = &req->rq_private_buf;
498 size_t want, read; 498 size_t want, uninitialized_var(read);
499 ssize_t ret; 499 ssize_t uninitialized_var(ret);
500 500
501 xs_read_header(transport, buf); 501 xs_read_header(transport, buf);
502 502
diff --git a/scripts/Makefile.asm-generic b/scripts/Makefile.asm-generic
index a62d2823f6cf..82ad63dcd62b 100644
--- a/scripts/Makefile.asm-generic
+++ b/scripts/Makefile.asm-generic
@@ -12,8 +12,19 @@ all:
12src := $(subst /generated,,$(obj)) 12src := $(subst /generated,,$(obj))
13-include $(src)/Kbuild 13-include $(src)/Kbuild
14 14
15# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
16ifneq ($(SRCARCH),um)
17include $(generic)/Kbuild
18endif
19
15include scripts/Kbuild.include 20include scripts/Kbuild.include
16 21
22redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
23redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
24redundant := $(sort $(redundant))
25$(if $(redundant),\
26 $(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
27
17# If arch does not implement mandatory headers, fallback to asm-generic ones. 28# If arch does not implement mandatory headers, fallback to asm-generic ones.
18mandatory-y := $(filter-out $(generated-y), $(mandatory-y)) 29mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
19generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f))) 30generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 850b611f4aba..2554a15ecf2b 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -426,13 +426,9 @@ $(modorder-target): $(subdir-ym) FORCE
426# Rule to compile a set of .o files into one .a file (with symbol table) 426# Rule to compile a set of .o files into one .a file (with symbol table)
427# 427#
428ifdef lib-target 428ifdef lib-target
429quiet_cmd_link_l_target = AR $@
430
431# lib target archives do get a symbol table and index
432cmd_link_l_target = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
433 429
434$(lib-target): $(lib-y) FORCE 430$(lib-target): $(lib-y) FORCE
435 $(call if_changed,link_l_target) 431 $(call if_changed,ar)
436 432
437targets += $(lib-target) 433targets += $(lib-target)
438 434
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index c0abd9a779c3..8a1f64f17740 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -233,6 +233,12 @@ $(obj)/%: $(src)/%_shipped
233quiet_cmd_ld = LD $@ 233quiet_cmd_ld = LD $@
234 cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@ 234 cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
235 235
236# Archive
237# ---------------------------------------------------------------------------
238
239quiet_cmd_ar = AR $@
240 cmd_ar = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
241
236# Objcopy 242# Objcopy
237# --------------------------------------------------------------------------- 243# ---------------------------------------------------------------------------
238 244
diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
index ff5ca9817a85..0dae402661f3 100644
--- a/scripts/Makefile.modinst
+++ b/scripts/Makefile.modinst
@@ -23,7 +23,7 @@ quiet_cmd_modules_install = INSTALL $@
23 mkdir -p $(2) ; \ 23 mkdir -p $(2) ; \
24 cp $@ $(2) ; \ 24 cp $@ $(2) ; \
25 $(mod_strip_cmd) $(2)/$(notdir $@) ; \ 25 $(mod_strip_cmd) $(2)/$(notdir $@) ; \
26 $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) && \ 26 $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \
27 $(mod_compress_cmd) $(2)/$(notdir $@) 27 $(mod_compress_cmd) $(2)/$(notdir $@)
28 28
29# Modules built outside the kernel source tree go into extra by default 29# Modules built outside the kernel source tree go into extra by default
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index c0b7f526f95e..6b7f354f189a 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -77,7 +77,6 @@ modpost = scripts/mod/modpost \
77 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ 77 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
78 $(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \ 78 $(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \
79 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ 79 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
80 $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
81 $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ 80 $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
82 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) 81 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
83 82
diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh
index 6e6d63957da3..84bf6b500815 100755
--- a/scripts/adjust_autoksyms.sh
+++ b/scripts/adjust_autoksyms.sh
@@ -39,14 +39,7 @@ case "$KBUILD_VERBOSE" in
39esac 39esac
40 40
41# We need access to CONFIG_ symbols 41# We need access to CONFIG_ symbols
42case "${KCONFIG_CONFIG}" in 42. include/config/auto.conf
43*/*)
44 . "${KCONFIG_CONFIG}"
45 ;;
46*)
47 # Force using a file from the current directory
48 . "./${KCONFIG_CONFIG}"
49esac
50 43
51# Generate a new ksym list file with symbols needed by the current 44# Generate a new ksym list file with symbols needed by the current
52# set of modules. 45# set of modules.
diff --git a/scripts/coccinelle/free/put_device.cocci b/scripts/coccinelle/free/put_device.cocci
new file mode 100644
index 000000000000..7395697e7f19
--- /dev/null
+++ b/scripts/coccinelle/free/put_device.cocci
@@ -0,0 +1,56 @@
1// SPDX-License-Identifier: GPL-2.0
2/// Find missing put_device for every of_find_device_by_node.
3///
4// Confidence: Moderate
5// Copyright: (C) 2018-2019 Wen Yang, ZTE.
6// Comments:
7// Options: --no-includes --include-headers
8
9virtual report
10virtual org
11
12@search exists@
13local idexpression id;
14expression x,e,e1;
15position p1,p2;
16type T,T1,T2,T3;
17@@
18
19id = of_find_device_by_node@p1(x)
20... when != e = id
21if (id == NULL || ...) { ... return ...; }
22... when != put_device(&id->dev)
23 when != platform_device_put(id)
24 when != of_dev_put(id)
25 when != if (id) { ... put_device(&id->dev) ... }
26 when != e1 = (T)id
27 when != e1 = &id->dev
28 when != e1 = get_device(&id->dev)
29 when != e1 = (T1)platform_get_drvdata(id)
30(
31 return
32( id
33| (T2)dev_get_drvdata(&id->dev)
34| (T3)platform_get_drvdata(id)
35);
36| return@p2 ...;
37)
38
39@script:python depends on report@
40p1 << search.p1;
41p2 << search.p2;
42@@
43
44coccilib.report.print_report(p2[0], "ERROR: missing put_device; "
45 + "call of_find_device_by_node on line "
46 + p1[0].line
47 + ", but without a corresponding object release "
48 + "within this function.")
49
50@script:python depends on org@
51p1 << search.p1;
52p2 << search.p2;
53@@
54
55cocci.print_main("of_find_device_by_node", p1)
56cocci.print_secs("needed put_device", p2)
diff --git a/scripts/kconfig/lxdialog/.gitignore b/scripts/kconfig/lxdialog/.gitignore
deleted file mode 100644
index 90b08ff025a6..000000000000
--- a/scripts/kconfig/lxdialog/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
1#
2# Generated files
3#
4lxdialog
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index bc7f1fc1f55b..dc0e8c5a1402 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -171,14 +171,7 @@ if [ "$1" = "clean" ]; then
171fi 171fi
172 172
173# We need access to CONFIG_ symbols 173# We need access to CONFIG_ symbols
174case "${KCONFIG_CONFIG}" in 174. include/config/auto.conf
175*/*)
176 . "${KCONFIG_CONFIG}"
177 ;;
178*)
179 # Force using a file from the current directory
180 . "./${KCONFIG_CONFIG}"
181esac
182 175
183# Update version 176# Update version
184info GEN .version 177info GEN .version
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 26bf886bd168..0b0d1080b1c5 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -35,7 +35,6 @@ static int vmlinux_section_warnings = 1;
35static int warn_unresolved = 0; 35static int warn_unresolved = 0;
36/* How a symbol is exported */ 36/* How a symbol is exported */
37static int sec_mismatch_count = 0; 37static int sec_mismatch_count = 0;
38static int sec_mismatch_verbose = 1;
39static int sec_mismatch_fatal = 0; 38static int sec_mismatch_fatal = 0;
40/* ignore missing files */ 39/* ignore missing files */
41static int ignore_missing_files; 40static int ignore_missing_files;
@@ -1406,8 +1405,6 @@ static void report_sec_mismatch(const char *modname,
1406 char *prl_to; 1405 char *prl_to;
1407 1406
1408 sec_mismatch_count++; 1407 sec_mismatch_count++;
1409 if (!sec_mismatch_verbose)
1410 return;
1411 1408
1412 get_pretty_name(from_is_func, &from, &from_p); 1409 get_pretty_name(from_is_func, &from, &from_p);
1413 get_pretty_name(to_is_func, &to, &to_p); 1410 get_pretty_name(to_is_func, &to, &to_p);
@@ -1655,9 +1652,7 @@ static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
1655 1652
1656 sec_mismatch_count++; 1653 sec_mismatch_count++;
1657 1654
1658 if (sec_mismatch_verbose) 1655 report_extable_warnings(modname, elf, mismatch, r, sym, fromsec, tosec);
1659 report_extable_warnings(modname, elf, mismatch, r, sym,
1660 fromsec, tosec);
1661 1656
1662 if (match(tosec, mismatch->bad_tosec)) 1657 if (match(tosec, mismatch->bad_tosec))
1663 fatal("The relocation at %s+0x%lx references\n" 1658 fatal("The relocation at %s+0x%lx references\n"
@@ -2433,7 +2428,7 @@ int main(int argc, char **argv)
2433 struct ext_sym_list *extsym_iter; 2428 struct ext_sym_list *extsym_iter;
2434 struct ext_sym_list *extsym_start = NULL; 2429 struct ext_sym_list *extsym_start = NULL;
2435 2430
2436 while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awE")) != -1) { 2431 while ((opt = getopt(argc, argv, "i:I:e:mnsT:o:awE")) != -1) {
2437 switch (opt) { 2432 switch (opt) {
2438 case 'i': 2433 case 'i':
2439 kernel_read = optarg; 2434 kernel_read = optarg;
@@ -2465,9 +2460,6 @@ int main(int argc, char **argv)
2465 case 's': 2460 case 's':
2466 vmlinux_section_warnings = 0; 2461 vmlinux_section_warnings = 0;
2467 break; 2462 break;
2468 case 'S':
2469 sec_mismatch_verbose = 0;
2470 break;
2471 case 'T': 2463 case 'T':
2472 files_source = optarg; 2464 files_source = optarg;
2473 break; 2465 break;
@@ -2525,18 +2517,9 @@ int main(int argc, char **argv)
2525 } 2517 }
2526 if (dump_write) 2518 if (dump_write)
2527 write_dump(dump_write); 2519 write_dump(dump_write);
2528 if (sec_mismatch_count) { 2520 if (sec_mismatch_count && sec_mismatch_fatal)
2529 if (!sec_mismatch_verbose) { 2521 fatal("modpost: Section mismatches detected.\n"
2530 warn("modpost: Found %d section mismatch(es).\n" 2522 "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2531 "To see full details build your kernel with:\n"
2532 "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n",
2533 sec_mismatch_count);
2534 }
2535 if (sec_mismatch_fatal) {
2536 fatal("modpost: Section mismatches detected.\n"
2537 "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2538 }
2539 }
2540 free(buf.p); 2523 free(buf.p);
2541 2524
2542 return err; 2525 return err;
diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 8ac25d10a6ad..b03dd56a4782 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -12,6 +12,18 @@
12 12
13set -e 13set -e
14 14
15is_enabled() {
16 grep -q "^$1=y" include/config/auto.conf
17}
18
19if_enabled_echo() {
20 if is_enabled "$1"; then
21 echo -n "$2"
22 elif [ $# -ge 3 ]; then
23 echo -n "$3"
24 fi
25}
26
15create_package() { 27create_package() {
16 local pname="$1" pdir="$2" 28 local pname="$1" pdir="$2"
17 29
@@ -62,7 +74,7 @@ parisc|mips|powerpc)
62 installed_image_path="boot/vmlinuz-$version" 74 installed_image_path="boot/vmlinuz-$version"
63esac 75esac
64 76
65BUILD_DEBUG="$(grep -s '^CONFIG_DEBUG_INFO=y' $KCONFIG_CONFIG || true)" 77BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes)
66 78
67# Setup the directory structure 79# Setup the directory structure
68rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files 80rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files
@@ -83,14 +95,14 @@ else
83fi 95fi
84cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path" 96cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path"
85 97
86if grep -q "^CONFIG_OF_EARLY_FLATTREE=y" $KCONFIG_CONFIG ; then 98if is_enabled CONFIG_OF_EARLY_FLATTREE; then
87 # Only some architectures with OF support have this target 99 # Only some architectures with OF support have this target
88 if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then 100 if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then
89 $MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install 101 $MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
90 fi 102 fi
91fi 103fi
92 104
93if grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then 105if is_enabled CONFIG_MODULES; then
94 INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install 106 INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install
95 rm -f "$tmpdir/lib/modules/$version/build" 107 rm -f "$tmpdir/lib/modules/$version/build"
96 rm -f "$tmpdir/lib/modules/$version/source" 108 rm -f "$tmpdir/lib/modules/$version/source"
@@ -111,8 +123,7 @@ if grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then
111 done 123 done
112 124
113 # resign stripped modules 125 # resign stripped modules
114 MODULE_SIG_ALL="$(grep -s '^CONFIG_MODULE_SIG_ALL=y' $KCONFIG_CONFIG || true)" 126 if is_enabled CONFIG_MODULE_SIG_ALL; then
115 if [ -n "$MODULE_SIG_ALL" ]; then
116 INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign 127 INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign
117 fi 128 fi
118 fi 129 fi
@@ -129,11 +140,6 @@ fi
129# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and 140# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
130# so do we; recent versions of dracut and initramfs-tools will obey this. 141# so do we; recent versions of dracut and initramfs-tools will obey this.
131debhookdir=${KDEB_HOOKDIR:-/etc/kernel} 142debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
132if grep -q '^CONFIG_BLK_DEV_INITRD=y' $KCONFIG_CONFIG; then
133 want_initrd=Yes
134else
135 want_initrd=No
136fi
137for script in postinst postrm preinst prerm ; do 143for script in postinst postrm preinst prerm ; do
138 mkdir -p "$tmpdir$debhookdir/$script.d" 144 mkdir -p "$tmpdir$debhookdir/$script.d"
139 cat <<EOF > "$tmpdir/DEBIAN/$script" 145 cat <<EOF > "$tmpdir/DEBIAN/$script"
@@ -145,7 +151,7 @@ set -e
145export DEB_MAINT_PARAMS="\$*" 151export DEB_MAINT_PARAMS="\$*"
146 152
147# Tell initramfs builder whether it's wanted 153# Tell initramfs builder whether it's wanted
148export INITRD=$want_initrd 154export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
149 155
150test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d 156test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
151exit 0 157exit 0
@@ -158,11 +164,11 @@ done
158(cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles" 164(cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles"
159(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles" 165(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
160(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles" 166(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
161if grep -q '^CONFIG_STACK_VALIDATION=y' $KCONFIG_CONFIG ; then 167if is_enabled CONFIG_STACK_VALIDATION; then
162 (cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles" 168 (cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles"
163fi 169fi
164(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles" 170(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
165if grep -q '^CONFIG_GCC_PLUGINS=y' $KCONFIG_CONFIG ; then 171if is_enabled CONFIG_GCC_PLUGINS; then
166 (cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles" 172 (cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles"
167fi 173fi
168destdir=$kernel_headers_dir/usr/src/linux-headers-$version 174destdir=$kernel_headers_dir/usr/src/linux-headers-$version
diff --git a/scripts/package/buildtar b/scripts/package/buildtar
index cfd2a4a3fe42..2f66c81e4021 100755
--- a/scripts/package/buildtar
+++ b/scripts/package/buildtar
@@ -56,7 +56,7 @@ dirs=boot
56# 56#
57# Try to install modules 57# Try to install modules
58# 58#
59if grep -q '^CONFIG_MODULES=y' "${KCONFIG_CONFIG}"; then 59if grep -q '^CONFIG_MODULES=y' include/config/auto.conf; then
60 make ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_MOD_PATH="${tmpdir}" modules_install 60 make ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_MOD_PATH="${tmpdir}" modules_install
61 dirs="$dirs lib" 61 dirs="$dirs lib"
62fi 62fi
diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian
index f030961c5165..8351584cb24e 100755
--- a/scripts/package/mkdebian
+++ b/scripts/package/mkdebian
@@ -7,7 +7,7 @@
7set -e 7set -e
8 8
9is_enabled() { 9is_enabled() {
10 grep -q "^CONFIG_$1=y" $KCONFIG_CONFIG 10 grep -q "^$1=y" include/config/auto.conf
11} 11}
12 12
13if_enabled_echo() { 13if_enabled_echo() {
@@ -31,23 +31,23 @@ set_debarch() {
31 x86_64) 31 x86_64)
32 debarch=amd64 ;; 32 debarch=amd64 ;;
33 sparc*) 33 sparc*)
34 debarch=sparc$(if_enabled_echo 64BIT 64) ;; 34 debarch=sparc$(if_enabled_echo CONFIG_64BIT 64) ;;
35 s390*) 35 s390*)
36 debarch=s390x ;; 36 debarch=s390x ;;
37 ppc*) 37 ppc*)
38 if is_enabled 64BIT; then 38 if is_enabled CONFIG_64BIT; then
39 debarch=ppc64$(if_enabled_echo CPU_LITTLE_ENDIAN el) 39 debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el)
40 else 40 else
41 debarch=powerpc$(if_enabled_echo SPE spe) 41 debarch=powerpc$(if_enabled_echo CONFIG_SPE spe)
42 fi 42 fi
43 ;; 43 ;;
44 parisc*) 44 parisc*)
45 debarch=hppa ;; 45 debarch=hppa ;;
46 mips*) 46 mips*)
47 if is_enabled CPU_LITTLE_ENDIAN; then 47 if is_enabled CONFIG_CPU_LITTLE_ENDIAN; then
48 debarch=mips$(if_enabled_echo 64BIT 64)$(if_enabled_echo CPU_MIPSR6 r6)el 48 debarch=mips$(if_enabled_echo CONFIG_64BIT 64)$(if_enabled_echo CONFIG_CPU_MIPSR6 r6)el
49 elif is_enabled CPU_MIPSR6; then 49 elif is_enabled CONFIG_CPU_MIPSR6; then
50 debarch=mips$(if_enabled_echo 64BIT 64)r6 50 debarch=mips$(if_enabled_echo CONFIG_64BIT 64)r6
51 else 51 else
52 debarch=mips 52 debarch=mips
53 fi 53 fi
@@ -55,8 +55,8 @@ set_debarch() {
55 aarch64|arm64) 55 aarch64|arm64)
56 debarch=arm64 ;; 56 debarch=arm64 ;;
57 arm*) 57 arm*)
58 if is_enabled AEABI; then 58 if is_enabled CONFIG_AEABI; then
59 debarch=arm$(if_enabled_echo VFP hf el) 59 debarch=arm$(if_enabled_echo CONFIG_VFP hf el)
60 else 60 else
61 debarch=arm 61 debarch=arm
62 fi 62 fi
@@ -64,10 +64,10 @@ set_debarch() {
64 openrisc) 64 openrisc)
65 debarch=or1k ;; 65 debarch=or1k ;;
66 sh) 66 sh)
67 if is_enabled CPU_SH3; then 67 if is_enabled CONFIG_CPU_SH3; then
68 debarch=sh3$(if_enabled_echo CPU_BIG_ENDIAN eb) 68 debarch=sh3$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
69 elif is_enabled CPU_SH4; then 69 elif is_enabled CONFIG_CPU_SH4; then
70 debarch=sh4$(if_enabled_echo CPU_BIG_ENDIAN eb) 70 debarch=sh4$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
71 fi 71 fi
72 ;; 72 ;;
73 esac 73 esac
@@ -132,8 +132,12 @@ else
132 echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly" 132 echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
133fi 133fi
134 134
135mkdir -p debian/ 135mkdir -p debian/source/
136echo "1.0" > debian/source/format
137
136echo $debarch > debian/arch 138echo $debarch > debian/arch
139extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev)"
140extra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)"
137 141
138# Generate a simple changelog template 142# Generate a simple changelog template
139cat <<EOF > debian/changelog 143cat <<EOF > debian/changelog
@@ -170,7 +174,7 @@ Source: $sourcename
170Section: kernel 174Section: kernel
171Priority: optional 175Priority: optional
172Maintainer: $maintainer 176Maintainer: $maintainer
173Build-Depends: bc, kmod, cpio 177Build-Depends: bc, kmod, cpio, bison, flex | flex:native $extra_build_depends
174Homepage: http://www.kernel.org/ 178Homepage: http://www.kernel.org/
175 179
176Package: $packagename 180Package: $packagename
@@ -221,5 +225,6 @@ clean:
221 225
222binary: binary-arch 226binary: binary-arch
223EOF 227EOF
228chmod +x debian/rules
224 229
225exit 0 230exit 0
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/hda/hdac_stream.c b/sound/hda/hdac_stream.c
index f5dd288d1a7a..76e9b41fcea2 100644
--- a/sound/hda/hdac_stream.c
+++ b/sound/hda/hdac_stream.c
@@ -95,7 +95,10 @@ void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start)
95 1 << azx_dev->index, 95 1 << azx_dev->index,
96 1 << azx_dev->index); 96 1 << azx_dev->index);
97 /* set stripe control */ 97 /* set stripe control */
98 stripe_ctl = snd_hdac_get_stream_stripe_ctl(bus, azx_dev->substream); 98 if (azx_dev->substream)
99 stripe_ctl = snd_hdac_get_stream_stripe_ctl(bus, azx_dev->substream);
100 else
101 stripe_ctl = 0;
99 snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK, 102 snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK,
100 stripe_ctl); 103 stripe_ctl);
101 /* set DMA start and interrupt mask */ 104 /* set DMA start and interrupt mask */
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/hda_tegra.c b/sound/pci/hda/hda_tegra.c
index dbd8da5685cb..3d68f9ef7694 100644
--- a/sound/pci/hda/hda_tegra.c
+++ b/sound/pci/hda/hda_tegra.c
@@ -219,7 +219,6 @@ disable_hda:
219 return rc; 219 return rc;
220} 220}
221 221
222#ifdef CONFIG_PM_SLEEP
223static void hda_tegra_disable_clocks(struct hda_tegra *data) 222static void hda_tegra_disable_clocks(struct hda_tegra *data)
224{ 223{
225 clk_disable_unprepare(data->hda2hdmi_clk); 224 clk_disable_unprepare(data->hda2hdmi_clk);
@@ -230,7 +229,7 @@ static void hda_tegra_disable_clocks(struct hda_tegra *data)
230/* 229/*
231 * power management 230 * power management
232 */ 231 */
233static int hda_tegra_suspend(struct device *dev) 232static int __maybe_unused hda_tegra_suspend(struct device *dev)
234{ 233{
235 struct snd_card *card = dev_get_drvdata(dev); 234 struct snd_card *card = dev_get_drvdata(dev);
236 int rc; 235 int rc;
@@ -243,7 +242,7 @@ static int hda_tegra_suspend(struct device *dev)
243 return 0; 242 return 0;
244} 243}
245 244
246static int hda_tegra_resume(struct device *dev) 245static int __maybe_unused hda_tegra_resume(struct device *dev)
247{ 246{
248 struct snd_card *card = dev_get_drvdata(dev); 247 struct snd_card *card = dev_get_drvdata(dev);
249 int rc; 248 int rc;
@@ -255,10 +254,8 @@ static int hda_tegra_resume(struct device *dev)
255 254
256 return 0; 255 return 0;
257} 256}
258#endif /* CONFIG_PM_SLEEP */
259 257
260#ifdef CONFIG_PM 258static int __maybe_unused hda_tegra_runtime_suspend(struct device *dev)
261static int hda_tegra_runtime_suspend(struct device *dev)
262{ 259{
263 struct snd_card *card = dev_get_drvdata(dev); 260 struct snd_card *card = dev_get_drvdata(dev);
264 struct azx *chip = card->private_data; 261 struct azx *chip = card->private_data;
@@ -275,7 +272,7 @@ static int hda_tegra_runtime_suspend(struct device *dev)
275 return 0; 272 return 0;
276} 273}
277 274
278static int hda_tegra_runtime_resume(struct device *dev) 275static int __maybe_unused hda_tegra_runtime_resume(struct device *dev)
279{ 276{
280 struct snd_card *card = dev_get_drvdata(dev); 277 struct snd_card *card = dev_get_drvdata(dev);
281 struct azx *chip = card->private_data; 278 struct azx *chip = card->private_data;
@@ -292,7 +289,6 @@ static int hda_tegra_runtime_resume(struct device *dev)
292 289
293 return 0; 290 return 0;
294} 291}
295#endif /* CONFIG_PM */
296 292
297static const struct dev_pm_ops hda_tegra_pm = { 293static const struct dev_pm_ops hda_tegra_pm = {
298 SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume) 294 SET_SYSTEM_SLEEP_PM_OPS(hda_tegra_suspend, hda_tegra_resume)
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index a4ee7656d9ee..fb65ad31e86c 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -936,6 +936,9 @@ static const struct snd_pci_quirk cxt5066_fixups[] = {
936 SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE), 936 SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
937 SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE), 937 SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE),
938 SND_PCI_QUIRK(0x103c, 0x8455, "HP Z2 G4", CXT_FIXUP_HP_MIC_NO_PRESENCE), 938 SND_PCI_QUIRK(0x103c, 0x8455, "HP Z2 G4", CXT_FIXUP_HP_MIC_NO_PRESENCE),
939 SND_PCI_QUIRK(0x103c, 0x8456, "HP Z2 G4 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
940 SND_PCI_QUIRK(0x103c, 0x8457, "HP Z2 G4 mini", CXT_FIXUP_HP_MIC_NO_PRESENCE),
941 SND_PCI_QUIRK(0x103c, 0x8458, "HP Z2 G4 mini premium", CXT_FIXUP_HP_MIC_NO_PRESENCE),
939 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN), 942 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
940 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO), 943 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
941 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 944 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 73d7042ff884..8b3ac690efa3 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -57,10 +57,11 @@ MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
57#define is_geminilake(codec) (((codec)->core.vendor_id == 0x8086280d) || \ 57#define is_geminilake(codec) (((codec)->core.vendor_id == 0x8086280d) || \
58 ((codec)->core.vendor_id == 0x80862800)) 58 ((codec)->core.vendor_id == 0x80862800))
59#define is_cannonlake(codec) ((codec)->core.vendor_id == 0x8086280c) 59#define is_cannonlake(codec) ((codec)->core.vendor_id == 0x8086280c)
60#define is_icelake(codec) ((codec)->core.vendor_id == 0x8086280f)
60#define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \ 61#define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \
61 || is_skylake(codec) || is_broxton(codec) \ 62 || is_skylake(codec) || is_broxton(codec) \
62 || is_kabylake(codec)) || is_geminilake(codec) \ 63 || is_kabylake(codec) || is_geminilake(codec) \
63 || is_cannonlake(codec) 64 || is_cannonlake(codec) || is_icelake(codec))
64#define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882) 65#define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882)
65#define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883) 66#define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
66#define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec)) 67#define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
@@ -181,6 +182,8 @@ struct hdmi_spec {
181 182
182 struct hdac_chmap chmap; 183 struct hdac_chmap chmap;
183 hda_nid_t vendor_nid; 184 hda_nid_t vendor_nid;
185 const int *port_map;
186 int port_num;
184}; 187};
185 188
186#ifdef CONFIG_SND_HDA_COMPONENT 189#ifdef CONFIG_SND_HDA_COMPONENT
@@ -2418,12 +2421,11 @@ static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2418 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids); 2421 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
2419} 2422}
2420 2423
2421#define INTEL_VENDOR_NID 0x08 2424#define INTEL_GET_VENDOR_VERB 0xf81
2422#define INTEL_GLK_VENDOR_NID 0x0B 2425#define INTEL_GET_VENDOR_VERB 0xf81
2423#define INTEL_GET_VENDOR_VERB 0xf81 2426#define INTEL_SET_VENDOR_VERB 0x781
2424#define INTEL_SET_VENDOR_VERB 0x781 2427#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
2425#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */ 2428#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2426#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
2427 2429
2428static void intel_haswell_enable_all_pins(struct hda_codec *codec, 2430static void intel_haswell_enable_all_pins(struct hda_codec *codec,
2429 bool update_tree) 2431 bool update_tree)
@@ -2503,11 +2505,29 @@ static int intel_base_nid(struct hda_codec *codec)
2503 2505
2504static int intel_pin2port(void *audio_ptr, int pin_nid) 2506static int intel_pin2port(void *audio_ptr, int pin_nid)
2505{ 2507{
2506 int base_nid = intel_base_nid(audio_ptr); 2508 struct hda_codec *codec = audio_ptr;
2509 struct hdmi_spec *spec = codec->spec;
2510 int base_nid, i;
2507 2511
2508 if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3)) 2512 if (!spec->port_num) {
2509 return -1; 2513 base_nid = intel_base_nid(codec);
2510 return pin_nid - base_nid + 1; /* intel port is 1-based */ 2514 if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
2515 return -1;
2516 return pin_nid - base_nid + 1; /* intel port is 1-based */
2517 }
2518
2519 /*
2520 * looking for the pin number in the mapping table and return
2521 * the index which indicate the port number
2522 */
2523 for (i = 0; i < spec->port_num; i++) {
2524 if (pin_nid == spec->port_map[i])
2525 return i + 1;
2526 }
2527
2528 /* return -1 if pin number exceeds our expectation */
2529 codec_info(codec, "Can't find the HDMI/DP port for pin %d\n", pin_nid);
2530 return -1;
2511} 2531}
2512 2532
2513static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe) 2533static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
@@ -2608,7 +2628,8 @@ static int parse_intel_hdmi(struct hda_codec *codec)
2608} 2628}
2609 2629
2610/* Intel Haswell and onwards; audio component with eld notifier */ 2630/* Intel Haswell and onwards; audio component with eld notifier */
2611static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid) 2631static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
2632 const int *port_map, int port_num)
2612{ 2633{
2613 struct hdmi_spec *spec; 2634 struct hdmi_spec *spec;
2614 int err; 2635 int err;
@@ -2620,6 +2641,8 @@ static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid)
2620 codec->dp_mst = true; 2641 codec->dp_mst = true;
2621 spec->dyn_pcm_assign = true; 2642 spec->dyn_pcm_assign = true;
2622 spec->vendor_nid = vendor_nid; 2643 spec->vendor_nid = vendor_nid;
2644 spec->port_map = port_map;
2645 spec->port_num = port_num;
2623 2646
2624 intel_haswell_enable_all_pins(codec, true); 2647 intel_haswell_enable_all_pins(codec, true);
2625 intel_haswell_fixup_enable_dp12(codec); 2648 intel_haswell_fixup_enable_dp12(codec);
@@ -2638,12 +2661,23 @@ static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid)
2638 2661
2639static int patch_i915_hsw_hdmi(struct hda_codec *codec) 2662static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2640{ 2663{
2641 return intel_hsw_common_init(codec, INTEL_VENDOR_NID); 2664 return intel_hsw_common_init(codec, 0x08, NULL, 0);
2642} 2665}
2643 2666
2644static int patch_i915_glk_hdmi(struct hda_codec *codec) 2667static int patch_i915_glk_hdmi(struct hda_codec *codec)
2645{ 2668{
2646 return intel_hsw_common_init(codec, INTEL_GLK_VENDOR_NID); 2669 return intel_hsw_common_init(codec, 0x0b, NULL, 0);
2670}
2671
2672static int patch_i915_icl_hdmi(struct hda_codec *codec)
2673{
2674 /*
2675 * pin to port mapping table where the value indicate the pin number and
2676 * the index indicate the port number with 1 base.
2677 */
2678 static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb};
2679
2680 return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map));
2647} 2681}
2648 2682
2649/* Intel Baytrail and Braswell; with eld notifier */ 2683/* Intel Baytrail and Braswell; with eld notifier */
@@ -3886,6 +3920,7 @@ HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
3886HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi), 3920HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
3887HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi), 3921HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
3888HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi), 3922HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi),
3923HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi),
3889HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi), 3924HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
3890HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi), 3925HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
3891HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi), 3926HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
@@ -3899,7 +3934,7 @@ HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi),
3899HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi), 3934HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi),
3900HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi), 3935HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi),
3901HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi), 3936HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi),
3902HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi), 3937HDA_CODEC_ENTRY(0x8086280f, "Icelake HDMI", patch_i915_icl_hdmi),
3903HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi), 3938HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
3904HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi), 3939HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi),
3905HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi), 3940HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index c8413d44973c..191830d4fa40 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -5491,7 +5491,7 @@ static void alc_headset_btn_callback(struct hda_codec *codec,
5491 jack->jack->button_state = report; 5491 jack->jack->button_state = report;
5492} 5492}
5493 5493
5494static void alc_fixup_headset_jack(struct hda_codec *codec, 5494static void alc295_fixup_chromebook(struct hda_codec *codec,
5495 const struct hda_fixup *fix, int action) 5495 const struct hda_fixup *fix, int action)
5496{ 5496{
5497 5497
@@ -5501,6 +5501,16 @@ static void alc_fixup_headset_jack(struct hda_codec *codec,
5501 alc_headset_btn_callback); 5501 alc_headset_btn_callback);
5502 snd_hda_jack_add_kctl(codec, 0x55, "Headset Jack", false, 5502 snd_hda_jack_add_kctl(codec, 0x55, "Headset Jack", false,
5503 SND_JACK_HEADSET, alc_headset_btn_keymap); 5503 SND_JACK_HEADSET, alc_headset_btn_keymap);
5504 switch (codec->core.vendor_id) {
5505 case 0x10ec0295:
5506 alc_update_coef_idx(codec, 0x4a, 0x8000, 1 << 15); /* Reset HP JD */
5507 alc_update_coef_idx(codec, 0x4a, 0x8000, 0 << 15);
5508 break;
5509 case 0x10ec0236:
5510 alc_update_coef_idx(codec, 0x1b, 0x8000, 1 << 15); /* Reset HP JD */
5511 alc_update_coef_idx(codec, 0x1b, 0x8000, 0 << 15);
5512 break;
5513 }
5504 break; 5514 break;
5505 case HDA_FIXUP_ACT_INIT: 5515 case HDA_FIXUP_ACT_INIT:
5506 switch (codec->core.vendor_id) { 5516 switch (codec->core.vendor_id) {
@@ -5670,9 +5680,14 @@ enum {
5670 ALC294_FIXUP_ASUS_MIC, 5680 ALC294_FIXUP_ASUS_MIC,
5671 ALC294_FIXUP_ASUS_HEADSET_MIC, 5681 ALC294_FIXUP_ASUS_HEADSET_MIC,
5672 ALC294_FIXUP_ASUS_SPK, 5682 ALC294_FIXUP_ASUS_SPK,
5673 ALC225_FIXUP_HEADSET_JACK,
5674 ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE, 5683 ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE,
5675 ALC285_FIXUP_LENOVO_PC_BEEP_IN_NOISE, 5684 ALC285_FIXUP_LENOVO_PC_BEEP_IN_NOISE,
5685 ALC255_FIXUP_ACER_HEADSET_MIC,
5686 ALC295_FIXUP_CHROME_BOOK,
5687 ALC225_FIXUP_DELL_WYSE_AIO_MIC_NO_PRESENCE,
5688 ALC225_FIXUP_WYSE_AUTO_MUTE,
5689 ALC225_FIXUP_WYSE_DISABLE_MIC_VREF,
5690 ALC286_FIXUP_ACER_AIO_HEADSET_MIC,
5676}; 5691};
5677 5692
5678static const struct hda_fixup alc269_fixups[] = { 5693static const struct hda_fixup alc269_fixups[] = {
@@ -6615,9 +6630,9 @@ static const struct hda_fixup alc269_fixups[] = {
6615 .chained = true, 6630 .chained = true,
6616 .chain_id = ALC294_FIXUP_ASUS_HEADSET_MIC 6631 .chain_id = ALC294_FIXUP_ASUS_HEADSET_MIC
6617 }, 6632 },
6618 [ALC225_FIXUP_HEADSET_JACK] = { 6633 [ALC295_FIXUP_CHROME_BOOK] = {
6619 .type = HDA_FIXUP_FUNC, 6634 .type = HDA_FIXUP_FUNC,
6620 .v.func = alc_fixup_headset_jack, 6635 .v.func = alc295_fixup_chromebook,
6621 }, 6636 },
6622 [ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE] = { 6637 [ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE] = {
6623 .type = HDA_FIXUP_PINS, 6638 .type = HDA_FIXUP_PINS,
@@ -6639,6 +6654,48 @@ static const struct hda_fixup alc269_fixups[] = {
6639 .chained = true, 6654 .chained = true,
6640 .chain_id = ALC285_FIXUP_LENOVO_HEADPHONE_NOISE 6655 .chain_id = ALC285_FIXUP_LENOVO_HEADPHONE_NOISE
6641 }, 6656 },
6657 [ALC255_FIXUP_ACER_HEADSET_MIC] = {
6658 .type = HDA_FIXUP_PINS,
6659 .v.pins = (const struct hda_pintbl[]) {
6660 { 0x19, 0x03a11130 },
6661 { 0x1a, 0x90a60140 }, /* use as internal mic */
6662 { }
6663 },
6664 .chained = true,
6665 .chain_id = ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC
6666 },
6667 [ALC225_FIXUP_DELL_WYSE_AIO_MIC_NO_PRESENCE] = {
6668 .type = HDA_FIXUP_PINS,
6669 .v.pins = (const struct hda_pintbl[]) {
6670 { 0x16, 0x01011020 }, /* Rear Line out */
6671 { 0x19, 0x01a1913c }, /* use as Front headset mic, without its own jack detect */
6672 { }
6673 },
6674 .chained = true,
6675 .chain_id = ALC225_FIXUP_WYSE_AUTO_MUTE
6676 },
6677 [ALC225_FIXUP_WYSE_AUTO_MUTE] = {
6678 .type = HDA_FIXUP_FUNC,
6679 .v.func = alc_fixup_auto_mute_via_amp,
6680 .chained = true,
6681 .chain_id = ALC225_FIXUP_WYSE_DISABLE_MIC_VREF
6682 },
6683 [ALC225_FIXUP_WYSE_DISABLE_MIC_VREF] = {
6684 .type = HDA_FIXUP_FUNC,
6685 .v.func = alc_fixup_disable_mic_vref,
6686 .chained = true,
6687 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
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 },
6642}; 6699};
6643 6700
6644static const struct snd_pci_quirk alc269_fixup_tbl[] = { 6701static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -6655,9 +6712,10 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6655 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),
6656 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),
6657 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),
6658 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),
6659 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),
6660 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),
6718 SND_PCI_QUIRK(0x1025, 0x1330, "Acer TravelMate X514-51T", ALC255_FIXUP_ACER_HEADSET_MIC),
6661 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), 6719 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6662 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),
6663 SND_PCI_QUIRK(0x1028, 0x05bd, "Dell Latitude E6440", ALC292_FIXUP_DELL_E7X), 6721 SND_PCI_QUIRK(0x1028, 0x05bd, "Dell Latitude E6440", ALC292_FIXUP_DELL_E7X),
@@ -6702,6 +6760,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6702 SND_PCI_QUIRK(0x1028, 0x0871, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC), 6760 SND_PCI_QUIRK(0x1028, 0x0871, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
6703 SND_PCI_QUIRK(0x1028, 0x0872, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC), 6761 SND_PCI_QUIRK(0x1028, 0x0872, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
6704 SND_PCI_QUIRK(0x1028, 0x0873, "Dell Precision 3930", ALC255_FIXUP_DUMMY_LINEOUT_VERB), 6762 SND_PCI_QUIRK(0x1028, 0x0873, "Dell Precision 3930", ALC255_FIXUP_DUMMY_LINEOUT_VERB),
6763 SND_PCI_QUIRK(0x1028, 0x08ad, "Dell WYSE AIO", ALC225_FIXUP_DELL_WYSE_AIO_MIC_NO_PRESENCE),
6764 SND_PCI_QUIRK(0x1028, 0x08ae, "Dell WYSE NB", ALC225_FIXUP_DELL1_MIC_NO_PRESENCE),
6705 SND_PCI_QUIRK(0x1028, 0x0935, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB), 6765 SND_PCI_QUIRK(0x1028, 0x0935, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
6706 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 6766 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
6707 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 6767 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
@@ -6764,11 +6824,13 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6764 SND_PCI_QUIRK(0x103c, 0x2336, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 6824 SND_PCI_QUIRK(0x103c, 0x2336, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6765 SND_PCI_QUIRK(0x103c, 0x2337, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 6825 SND_PCI_QUIRK(0x103c, 0x2337, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6766 SND_PCI_QUIRK(0x103c, 0x221c, "HP EliteBook 755 G2", ALC280_FIXUP_HP_HEADSET_MIC), 6826 SND_PCI_QUIRK(0x103c, 0x221c, "HP EliteBook 755 G2", ALC280_FIXUP_HP_HEADSET_MIC),
6827 SND_PCI_QUIRK(0x103c, 0x802e, "HP Z240 SFF", ALC221_FIXUP_HP_MIC_NO_PRESENCE),
6828 SND_PCI_QUIRK(0x103c, 0x802f, "HP Z240", ALC221_FIXUP_HP_MIC_NO_PRESENCE),
6767 SND_PCI_QUIRK(0x103c, 0x820d, "HP Pavilion 15", ALC269_FIXUP_HP_MUTE_LED_MIC3), 6829 SND_PCI_QUIRK(0x103c, 0x820d, "HP Pavilion 15", ALC269_FIXUP_HP_MUTE_LED_MIC3),
6768 SND_PCI_QUIRK(0x103c, 0x8256, "HP", ALC221_FIXUP_HP_FRONT_MIC), 6830 SND_PCI_QUIRK(0x103c, 0x8256, "HP", ALC221_FIXUP_HP_FRONT_MIC),
6769 SND_PCI_QUIRK(0x103c, 0x827e, "HP x360", ALC295_FIXUP_HP_X360), 6831 SND_PCI_QUIRK(0x103c, 0x827e, "HP x360", ALC295_FIXUP_HP_X360),
6770 SND_PCI_QUIRK(0x103c, 0x82bf, "HP", ALC221_FIXUP_HP_MIC_NO_PRESENCE), 6832 SND_PCI_QUIRK(0x103c, 0x82bf, "HP G3 mini", ALC221_FIXUP_HP_MIC_NO_PRESENCE),
6771 SND_PCI_QUIRK(0x103c, 0x82c0, "HP", ALC221_FIXUP_HP_MIC_NO_PRESENCE), 6833 SND_PCI_QUIRK(0x103c, 0x82c0, "HP G3 mini premium", ALC221_FIXUP_HP_MIC_NO_PRESENCE),
6772 SND_PCI_QUIRK(0x103c, 0x83b9, "HP Spectre x360", ALC269_FIXUP_HP_MUTE_LED_MIC3), 6834 SND_PCI_QUIRK(0x103c, 0x83b9, "HP Spectre x360", ALC269_FIXUP_HP_MUTE_LED_MIC3),
6773 SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC), 6835 SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC),
6774 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300), 6836 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
@@ -7048,7 +7110,7 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
7048 {.id = ALC255_FIXUP_DUMMY_LINEOUT_VERB, .name = "alc255-dummy-lineout"}, 7110 {.id = ALC255_FIXUP_DUMMY_LINEOUT_VERB, .name = "alc255-dummy-lineout"},
7049 {.id = ALC255_FIXUP_DELL_HEADSET_MIC, .name = "alc255-dell-headset"}, 7111 {.id = ALC255_FIXUP_DELL_HEADSET_MIC, .name = "alc255-dell-headset"},
7050 {.id = ALC295_FIXUP_HP_X360, .name = "alc295-hp-x360"}, 7112 {.id = ALC295_FIXUP_HP_X360, .name = "alc295-hp-x360"},
7051 {.id = ALC225_FIXUP_HEADSET_JACK, .name = "alc-sense-combo"}, 7113 {.id = ALC295_FIXUP_CHROME_BOOK, .name = "alc-sense-combo"},
7052 {} 7114 {}
7053}; 7115};
7054#define ALC225_STANDARD_PINS \ 7116#define ALC225_STANDARD_PINS \
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index b0f8979ff2d2..221adf68bd0c 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -104,7 +104,12 @@ static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
104 104
105 for (u = 0; u < USB_STREAM_NURBS; ++u) { 105 for (u = 0; u < USB_STREAM_NURBS; ++u) {
106 sk->inurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL); 106 sk->inurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
107 if (!sk->inurb[u])
108 return -ENOMEM;
109
107 sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL); 110 sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
111 if (!sk->outurb[u])
112 return -ENOMEM;
108 } 113 }
109 114
110 if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe) || 115 if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe) ||
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 5e977d2688da..11c25d9ea431 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)
@@ -3006,3 +3011,249 @@ bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
3006 ring_buffer_write_tail(header, data_tail); 3011 ring_buffer_write_tail(header, data_tail);
3007 return ret; 3012 return ret;
3008} 3013}
3014
3015struct bpf_prog_info_array_desc {
3016 int array_offset; /* e.g. offset of jited_prog_insns */
3017 int count_offset; /* e.g. offset of jited_prog_len */
3018 int size_offset; /* > 0: offset of rec size,
3019 * < 0: fix size of -size_offset
3020 */
3021};
3022
3023static struct bpf_prog_info_array_desc bpf_prog_info_array_desc[] = {
3024 [BPF_PROG_INFO_JITED_INSNS] = {
3025 offsetof(struct bpf_prog_info, jited_prog_insns),
3026 offsetof(struct bpf_prog_info, jited_prog_len),
3027 -1,
3028 },
3029 [BPF_PROG_INFO_XLATED_INSNS] = {
3030 offsetof(struct bpf_prog_info, xlated_prog_insns),
3031 offsetof(struct bpf_prog_info, xlated_prog_len),
3032 -1,
3033 },
3034 [BPF_PROG_INFO_MAP_IDS] = {
3035 offsetof(struct bpf_prog_info, map_ids),
3036 offsetof(struct bpf_prog_info, nr_map_ids),
3037 -(int)sizeof(__u32),
3038 },
3039 [BPF_PROG_INFO_JITED_KSYMS] = {
3040 offsetof(struct bpf_prog_info, jited_ksyms),
3041 offsetof(struct bpf_prog_info, nr_jited_ksyms),
3042 -(int)sizeof(__u64),
3043 },
3044 [BPF_PROG_INFO_JITED_FUNC_LENS] = {
3045 offsetof(struct bpf_prog_info, jited_func_lens),
3046 offsetof(struct bpf_prog_info, nr_jited_func_lens),
3047 -(int)sizeof(__u32),
3048 },
3049 [BPF_PROG_INFO_FUNC_INFO] = {
3050 offsetof(struct bpf_prog_info, func_info),
3051 offsetof(struct bpf_prog_info, nr_func_info),
3052 offsetof(struct bpf_prog_info, func_info_rec_size),
3053 },
3054 [BPF_PROG_INFO_LINE_INFO] = {
3055 offsetof(struct bpf_prog_info, line_info),
3056 offsetof(struct bpf_prog_info, nr_line_info),
3057 offsetof(struct bpf_prog_info, line_info_rec_size),
3058 },
3059 [BPF_PROG_INFO_JITED_LINE_INFO] = {
3060 offsetof(struct bpf_prog_info, jited_line_info),
3061 offsetof(struct bpf_prog_info, nr_jited_line_info),
3062 offsetof(struct bpf_prog_info, jited_line_info_rec_size),
3063 },
3064 [BPF_PROG_INFO_PROG_TAGS] = {
3065 offsetof(struct bpf_prog_info, prog_tags),
3066 offsetof(struct bpf_prog_info, nr_prog_tags),
3067 -(int)sizeof(__u8) * BPF_TAG_SIZE,
3068 },
3069
3070};
3071
3072static __u32 bpf_prog_info_read_offset_u32(struct bpf_prog_info *info, int offset)
3073{
3074 __u32 *array = (__u32 *)info;
3075
3076 if (offset >= 0)
3077 return array[offset / sizeof(__u32)];
3078 return -(int)offset;
3079}
3080
3081static __u64 bpf_prog_info_read_offset_u64(struct bpf_prog_info *info, int offset)
3082{
3083 __u64 *array = (__u64 *)info;
3084
3085 if (offset >= 0)
3086 return array[offset / sizeof(__u64)];
3087 return -(int)offset;
3088}
3089
3090static void bpf_prog_info_set_offset_u32(struct bpf_prog_info *info, int offset,
3091 __u32 val)
3092{
3093 __u32 *array = (__u32 *)info;
3094
3095 if (offset >= 0)
3096 array[offset / sizeof(__u32)] = val;
3097}
3098
3099static void bpf_prog_info_set_offset_u64(struct bpf_prog_info *info, int offset,
3100 __u64 val)
3101{
3102 __u64 *array = (__u64 *)info;
3103
3104 if (offset >= 0)
3105 array[offset / sizeof(__u64)] = val;
3106}
3107
3108struct bpf_prog_info_linear *
3109bpf_program__get_prog_info_linear(int fd, __u64 arrays)
3110{
3111 struct bpf_prog_info_linear *info_linear;
3112 struct bpf_prog_info info = {};
3113 __u32 info_len = sizeof(info);
3114 __u32 data_len = 0;
3115 int i, err;
3116 void *ptr;
3117
3118 if (arrays >> BPF_PROG_INFO_LAST_ARRAY)
3119 return ERR_PTR(-EINVAL);
3120
3121 /* step 1: get array dimensions */
3122 err = bpf_obj_get_info_by_fd(fd, &info, &info_len);
3123 if (err) {
3124 pr_debug("can't get prog info: %s", strerror(errno));
3125 return ERR_PTR(-EFAULT);
3126 }
3127
3128 /* step 2: calculate total size of all arrays */
3129 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3130 bool include_array = (arrays & (1UL << i)) > 0;
3131 struct bpf_prog_info_array_desc *desc;
3132 __u32 count, size;
3133
3134 desc = bpf_prog_info_array_desc + i;
3135
3136 /* kernel is too old to support this field */
3137 if (info_len < desc->array_offset + sizeof(__u32) ||
3138 info_len < desc->count_offset + sizeof(__u32) ||
3139 (desc->size_offset > 0 && info_len < desc->size_offset))
3140 include_array = false;
3141
3142 if (!include_array) {
3143 arrays &= ~(1UL << i); /* clear the bit */
3144 continue;
3145 }
3146
3147 count = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
3148 size = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
3149
3150 data_len += count * size;
3151 }
3152
3153 /* step 3: allocate continuous memory */
3154 data_len = roundup(data_len, sizeof(__u64));
3155 info_linear = malloc(sizeof(struct bpf_prog_info_linear) + data_len);
3156 if (!info_linear)
3157 return ERR_PTR(-ENOMEM);
3158
3159 /* step 4: fill data to info_linear->info */
3160 info_linear->arrays = arrays;
3161 memset(&info_linear->info, 0, sizeof(info));
3162 ptr = info_linear->data;
3163
3164 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3165 struct bpf_prog_info_array_desc *desc;
3166 __u32 count, size;
3167
3168 if ((arrays & (1UL << i)) == 0)
3169 continue;
3170
3171 desc = bpf_prog_info_array_desc + i;
3172 count = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
3173 size = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
3174 bpf_prog_info_set_offset_u32(&info_linear->info,
3175 desc->count_offset, count);
3176 bpf_prog_info_set_offset_u32(&info_linear->info,
3177 desc->size_offset, size);
3178 bpf_prog_info_set_offset_u64(&info_linear->info,
3179 desc->array_offset,
3180 ptr_to_u64(ptr));
3181 ptr += count * size;
3182 }
3183
3184 /* step 5: call syscall again to get required arrays */
3185 err = bpf_obj_get_info_by_fd(fd, &info_linear->info, &info_len);
3186 if (err) {
3187 pr_debug("can't get prog info: %s", strerror(errno));
3188 free(info_linear);
3189 return ERR_PTR(-EFAULT);
3190 }
3191
3192 /* step 6: verify the data */
3193 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3194 struct bpf_prog_info_array_desc *desc;
3195 __u32 v1, v2;
3196
3197 if ((arrays & (1UL << i)) == 0)
3198 continue;
3199
3200 desc = bpf_prog_info_array_desc + i;
3201 v1 = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
3202 v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
3203 desc->count_offset);
3204 if (v1 != v2)
3205 pr_warning("%s: mismatch in element count\n", __func__);
3206
3207 v1 = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
3208 v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
3209 desc->size_offset);
3210 if (v1 != v2)
3211 pr_warning("%s: mismatch in rec size\n", __func__);
3212 }
3213
3214 /* step 7: update info_len and data_len */
3215 info_linear->info_len = sizeof(struct bpf_prog_info);
3216 info_linear->data_len = data_len;
3217
3218 return info_linear;
3219}
3220
3221void bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear)
3222{
3223 int i;
3224
3225 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3226 struct bpf_prog_info_array_desc *desc;
3227 __u64 addr, offs;
3228
3229 if ((info_linear->arrays & (1UL << i)) == 0)
3230 continue;
3231
3232 desc = bpf_prog_info_array_desc + i;
3233 addr = bpf_prog_info_read_offset_u64(&info_linear->info,
3234 desc->array_offset);
3235 offs = addr - ptr_to_u64(info_linear->data);
3236 bpf_prog_info_set_offset_u64(&info_linear->info,
3237 desc->array_offset, offs);
3238 }
3239}
3240
3241void bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear)
3242{
3243 int i;
3244
3245 for (i = BPF_PROG_INFO_FIRST_ARRAY; i < BPF_PROG_INFO_LAST_ARRAY; ++i) {
3246 struct bpf_prog_info_array_desc *desc;
3247 __u64 addr, offs;
3248
3249 if ((info_linear->arrays & (1UL << i)) == 0)
3250 continue;
3251
3252 desc = bpf_prog_info_array_desc + i;
3253 offs = bpf_prog_info_read_offset_u64(&info_linear->info,
3254 desc->array_offset);
3255 addr = offs + ptr_to_u64(info_linear->data);
3256 bpf_prog_info_set_offset_u64(&info_linear->info,
3257 desc->array_offset, addr);
3258 }
3259}
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()
diff --git a/tools/testing/nvdimm/Kbuild b/tools/testing/nvdimm/Kbuild
index 10ddf223055b..e1286d2cdfbf 100644
--- a/tools/testing/nvdimm/Kbuild
+++ b/tools/testing/nvdimm/Kbuild
@@ -35,6 +35,8 @@ obj-$(CONFIG_DAX) += dax.o
35endif 35endif
36obj-$(CONFIG_DEV_DAX) += device_dax.o 36obj-$(CONFIG_DEV_DAX) += device_dax.o
37obj-$(CONFIG_DEV_DAX_PMEM) += dax_pmem.o 37obj-$(CONFIG_DEV_DAX_PMEM) += dax_pmem.o
38obj-$(CONFIG_DEV_DAX_PMEM) += dax_pmem_core.o
39obj-$(CONFIG_DEV_DAX_PMEM_COMPAT) += dax_pmem_compat.o
38 40
39nfit-y := $(ACPI_SRC)/core.o 41nfit-y := $(ACPI_SRC)/core.o
40nfit-y += $(ACPI_SRC)/intel.o 42nfit-y += $(ACPI_SRC)/intel.o
@@ -57,6 +59,7 @@ nd_e820-y := $(NVDIMM_SRC)/e820.o
57nd_e820-y += config_check.o 59nd_e820-y += config_check.o
58 60
59dax-y := $(DAX_SRC)/super.o 61dax-y := $(DAX_SRC)/super.o
62dax-y += $(DAX_SRC)/bus.o
60dax-y += config_check.o 63dax-y += config_check.o
61 64
62device_dax-y := $(DAX_SRC)/device.o 65device_dax-y := $(DAX_SRC)/device.o
@@ -64,7 +67,9 @@ device_dax-y += dax-dev.o
64device_dax-y += device_dax_test.o 67device_dax-y += device_dax_test.o
65device_dax-y += config_check.o 68device_dax-y += config_check.o
66 69
67dax_pmem-y := $(DAX_SRC)/pmem.o 70dax_pmem-y := $(DAX_SRC)/pmem/pmem.o
71dax_pmem_core-y := $(DAX_SRC)/pmem/core.o
72dax_pmem_compat-y := $(DAX_SRC)/pmem/compat.o
68dax_pmem-y += config_check.o 73dax_pmem-y += config_check.o
69 74
70libnvdimm-y := $(NVDIMM_SRC)/core.o 75libnvdimm-y := $(NVDIMM_SRC)/core.o
diff --git a/tools/testing/nvdimm/dax-dev.c b/tools/testing/nvdimm/dax-dev.c
index 36ee3d8797c3..f36e708265b8 100644
--- a/tools/testing/nvdimm/dax-dev.c
+++ b/tools/testing/nvdimm/dax-dev.c
@@ -17,20 +17,11 @@
17phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, 17phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
18 unsigned long size) 18 unsigned long size)
19{ 19{
20 struct resource *res; 20 struct resource *res = &dev_dax->region->res;
21 phys_addr_t addr; 21 phys_addr_t addr;
22 int i;
23 22
24 for (i = 0; i < dev_dax->num_resources; i++) { 23 addr = pgoff * PAGE_SIZE + res->start;
25 res = &dev_dax->res[i]; 24 if (addr >= res->start && addr <= res->end) {
26 addr = pgoff * PAGE_SIZE + res->start;
27 if (addr >= res->start && addr <= res->end)
28 break;
29 pgoff -= PHYS_PFN(resource_size(res));
30 }
31
32 if (i < dev_dax->num_resources) {
33 res = &dev_dax->res[i];
34 if (addr + size - 1 <= res->end) { 25 if (addr + size - 1 <= res->end) {
35 if (get_nfit_res(addr)) { 26 if (get_nfit_res(addr)) {
36 struct page *page; 27 struct page *page;
@@ -44,6 +35,5 @@ phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
44 return addr; 35 return addr;
45 } 36 }
46 } 37 }
47
48 return -1; 38 return -1;
49} 39}
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index fb5758ac469e..971fc8428117 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -32,6 +32,7 @@ TARGETS += net
32TARGETS += netfilter 32TARGETS += netfilter
33TARGETS += networking/timestamping 33TARGETS += networking/timestamping
34TARGETS += nsfs 34TARGETS += nsfs
35TARGETS += pidfd
35TARGETS += powerpc 36TARGETS += powerpc
36TARGETS += proc 37TARGETS += proc
37TARGETS += pstore 38TARGETS += pstore
diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore
index 6210ba41c29e..2689d1ea6d7a 100644
--- a/tools/testing/selftests/kvm/.gitignore
+++ b/tools/testing/selftests/kvm/.gitignore
@@ -3,6 +3,7 @@
3/x86_64/platform_info_test 3/x86_64/platform_info_test
4/x86_64/set_sregs_test 4/x86_64/set_sregs_test
5/x86_64/sync_regs_test 5/x86_64/sync_regs_test
6/x86_64/vmx_close_while_nested_test
6/x86_64/vmx_tsc_adjust_test 7/x86_64/vmx_tsc_adjust_test
7/x86_64/state_test 8/x86_64/state_test
8/dirty_log_test 9/dirty_log_test
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index f9a0e9938480..3c1f4bdf9000 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -16,6 +16,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/cr4_cpuid_sync_test
16TEST_GEN_PROGS_x86_64 += x86_64/state_test 16TEST_GEN_PROGS_x86_64 += x86_64/state_test
17TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test 17TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
18TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid 18TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
19TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
19TEST_GEN_PROGS_x86_64 += dirty_log_test 20TEST_GEN_PROGS_x86_64 += dirty_log_test
20TEST_GEN_PROGS_x86_64 += clear_dirty_log_test 21TEST_GEN_PROGS_x86_64 += clear_dirty_log_test
21 22
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c
new file mode 100644
index 000000000000..6edec6fd790b
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c
@@ -0,0 +1,95 @@
1/*
2 * vmx_close_while_nested
3 *
4 * Copyright (C) 2019, Red Hat, Inc.
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2.
7 *
8 * Verify that nothing bad happens if a KVM user exits with open
9 * file descriptors while executing a nested guest.
10 */
11
12#include "test_util.h"
13#include "kvm_util.h"
14#include "processor.h"
15#include "vmx.h"
16
17#include <string.h>
18#include <sys/ioctl.h>
19
20#include "kselftest.h"
21
22#define VCPU_ID 5
23
24enum {
25 PORT_L0_EXIT = 0x2000,
26};
27
28/* The virtual machine object. */
29static struct kvm_vm *vm;
30
31static void l2_guest_code(void)
32{
33 /* Exit to L0 */
34 asm volatile("inb %%dx, %%al"
35 : : [port] "d" (PORT_L0_EXIT) : "rax");
36}
37
38static void l1_guest_code(struct vmx_pages *vmx_pages)
39{
40#define L2_GUEST_STACK_SIZE 64
41 unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
42 uint32_t control;
43 uintptr_t save_cr3;
44
45 GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages));
46 GUEST_ASSERT(load_vmcs(vmx_pages));
47
48 /* Prepare the VMCS for L2 execution. */
49 prepare_vmcs(vmx_pages, l2_guest_code,
50 &l2_guest_stack[L2_GUEST_STACK_SIZE]);
51
52 GUEST_ASSERT(!vmlaunch());
53 GUEST_ASSERT(0);
54}
55
56int main(int argc, char *argv[])
57{
58 struct vmx_pages *vmx_pages;
59 vm_vaddr_t vmx_pages_gva;
60 struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);
61
62 if (!(entry->ecx & CPUID_VMX)) {
63 fprintf(stderr, "nested VMX not enabled, skipping test\n");
64 exit(KSFT_SKIP);
65 }
66
67 vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code);
68 vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
69
70 /* Allocate VMX pages and shared descriptors (vmx_pages). */
71 vmx_pages = vcpu_alloc_vmx(vm, &vmx_pages_gva);
72 vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva);
73
74 for (;;) {
75 volatile struct kvm_run *run = vcpu_state(vm, VCPU_ID);
76 struct ucall uc;
77
78 vcpu_run(vm, VCPU_ID);
79 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
80 "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
81 run->exit_reason,
82 exit_reason_str(run->exit_reason));
83
84 if (run->io.port == PORT_L0_EXIT)
85 break;
86
87 switch (get_ucall(vm, VCPU_ID, &uc)) {
88 case UCALL_ABORT:
89 TEST_ASSERT(false, "%s", (const char *)uc.args[0]);
90 /* NOT REACHED */
91 default:
92 TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd);
93 }
94 }
95}
diff --git a/tools/testing/selftests/pidfd/Makefile b/tools/testing/selftests/pidfd/Makefile
new file mode 100644
index 000000000000..deaf8073bc06
--- /dev/null
+++ b/tools/testing/selftests/pidfd/Makefile
@@ -0,0 +1,6 @@
1CFLAGS += -g -I../../../../usr/include/
2
3TEST_GEN_PROGS := pidfd_test
4
5include ../lib.mk
6
diff --git a/tools/testing/selftests/pidfd/pidfd_test.c b/tools/testing/selftests/pidfd/pidfd_test.c
new file mode 100644
index 000000000000..d59378a93782
--- /dev/null
+++ b/tools/testing/selftests/pidfd/pidfd_test.c
@@ -0,0 +1,381 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#define _GNU_SOURCE
4#include <errno.h>
5#include <fcntl.h>
6#include <linux/types.h>
7#include <sched.h>
8#include <signal.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <syscall.h>
13#include <sys/mount.h>
14#include <sys/wait.h>
15#include <unistd.h>
16
17#include "../kselftest.h"
18
19static inline int sys_pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
20 unsigned int flags)
21{
22 return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
23}
24
25static int signal_received;
26
27static void set_signal_received_on_sigusr1(int sig)
28{
29 if (sig == SIGUSR1)
30 signal_received = 1;
31}
32
33/*
34 * Straightforward test to see whether pidfd_send_signal() works is to send
35 * a signal to ourself.
36 */
37static int test_pidfd_send_signal_simple_success(void)
38{
39 int pidfd, ret;
40 const char *test_name = "pidfd_send_signal send SIGUSR1";
41
42 pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC);
43 if (pidfd < 0)
44 ksft_exit_fail_msg(
45 "%s test: Failed to open process file descriptor\n",
46 test_name);
47
48 signal(SIGUSR1, set_signal_received_on_sigusr1);
49
50 ret = sys_pidfd_send_signal(pidfd, SIGUSR1, NULL, 0);
51 close(pidfd);
52 if (ret < 0)
53 ksft_exit_fail_msg("%s test: Failed to send signal\n",
54 test_name);
55
56 if (signal_received != 1)
57 ksft_exit_fail_msg("%s test: Failed to receive signal\n",
58 test_name);
59
60 signal_received = 0;
61 ksft_test_result_pass("%s test: Sent signal\n", test_name);
62 return 0;
63}
64
65static int wait_for_pid(pid_t pid)
66{
67 int status, ret;
68
69again:
70 ret = waitpid(pid, &status, 0);
71 if (ret == -1) {
72 if (errno == EINTR)
73 goto again;
74
75 return -1;
76 }
77
78 if (ret != pid)
79 goto again;
80
81 if (!WIFEXITED(status))
82 return -1;
83
84 return WEXITSTATUS(status);
85}
86
87static int test_pidfd_send_signal_exited_fail(void)
88{
89 int pidfd, ret, saved_errno;
90 char buf[256];
91 pid_t pid;
92 const char *test_name = "pidfd_send_signal signal exited process";
93
94 pid = fork();
95 if (pid < 0)
96 ksft_exit_fail_msg("%s test: Failed to create new process\n",
97 test_name);
98
99 if (pid == 0)
100 _exit(EXIT_SUCCESS);
101
102 snprintf(buf, sizeof(buf), "/proc/%d", pid);
103
104 pidfd = open(buf, O_DIRECTORY | O_CLOEXEC);
105
106 (void)wait_for_pid(pid);
107
108 if (pidfd < 0)
109 ksft_exit_fail_msg(
110 "%s test: Failed to open process file descriptor\n",
111 test_name);
112
113 ret = sys_pidfd_send_signal(pidfd, 0, NULL, 0);
114 saved_errno = errno;
115 close(pidfd);
116 if (ret == 0)
117 ksft_exit_fail_msg(
118 "%s test: Managed to send signal to process even though it should have failed\n",
119 test_name);
120
121 if (saved_errno != ESRCH)
122 ksft_exit_fail_msg(
123 "%s test: Expected to receive ESRCH as errno value but received %d instead\n",
124 test_name, saved_errno);
125
126 ksft_test_result_pass("%s test: Failed to send signal as expected\n",
127 test_name);
128 return 0;
129}
130
131/*
132 * The kernel reserves 300 pids via RESERVED_PIDS in kernel/pid.c
133 * That means, when it wraps around any pid < 300 will be skipped.
134 * So we need to use a pid > 300 in order to test recycling.
135 */
136#define PID_RECYCLE 1000
137
138/*
139 * Maximum number of cycles we allow. This is equivalent to PID_MAX_DEFAULT.
140 * If users set a higher limit or we have cycled PIDFD_MAX_DEFAULT number of
141 * times then we skip the test to not go into an infinite loop or block for a
142 * long time.
143 */
144#define PIDFD_MAX_DEFAULT 0x8000
145
146/*
147 * Define a few custom error codes for the child process to clearly indicate
148 * what is happening. This way we can tell the difference between a system
149 * error, a test error, etc.
150 */
151#define PIDFD_PASS 0
152#define PIDFD_FAIL 1
153#define PIDFD_ERROR 2
154#define PIDFD_SKIP 3
155#define PIDFD_XFAIL 4
156
157static int test_pidfd_send_signal_recycled_pid_fail(void)
158{
159 int i, ret;
160 pid_t pid1;
161 const char *test_name = "pidfd_send_signal signal recycled pid";
162
163 ret = unshare(CLONE_NEWPID);
164 if (ret < 0)
165 ksft_exit_fail_msg("%s test: Failed to unshare pid namespace\n",
166 test_name);
167
168 ret = unshare(CLONE_NEWNS);
169 if (ret < 0)
170 ksft_exit_fail_msg(
171 "%s test: Failed to unshare mount namespace\n",
172 test_name);
173
174 ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
175 if (ret < 0)
176 ksft_exit_fail_msg("%s test: Failed to remount / private\n",
177 test_name);
178
179 /* pid 1 in new pid namespace */
180 pid1 = fork();
181 if (pid1 < 0)
182 ksft_exit_fail_msg("%s test: Failed to create new process\n",
183 test_name);
184
185 if (pid1 == 0) {
186 char buf[256];
187 pid_t pid2;
188 int pidfd = -1;
189
190 (void)umount2("/proc", MNT_DETACH);
191 ret = mount("proc", "/proc", "proc", 0, NULL);
192 if (ret < 0)
193 _exit(PIDFD_ERROR);
194
195 /* grab pid PID_RECYCLE */
196 for (i = 0; i <= PIDFD_MAX_DEFAULT; i++) {
197 pid2 = fork();
198 if (pid2 < 0)
199 _exit(PIDFD_ERROR);
200
201 if (pid2 == 0)
202 _exit(PIDFD_PASS);
203
204 if (pid2 == PID_RECYCLE) {
205 snprintf(buf, sizeof(buf), "/proc/%d", pid2);
206 ksft_print_msg("pid to recycle is %d\n", pid2);
207 pidfd = open(buf, O_DIRECTORY | O_CLOEXEC);
208 }
209
210 if (wait_for_pid(pid2))
211 _exit(PIDFD_ERROR);
212
213 if (pid2 >= PID_RECYCLE)
214 break;
215 }
216
217 /*
218 * We want to be as predictable as we can so if we haven't been
219 * able to grab pid PID_RECYCLE skip the test.
220 */
221 if (pid2 != PID_RECYCLE) {
222 /* skip test */
223 close(pidfd);
224 _exit(PIDFD_SKIP);
225 }
226
227 if (pidfd < 0)
228 _exit(PIDFD_ERROR);
229
230 for (i = 0; i <= PIDFD_MAX_DEFAULT; i++) {
231 char c;
232 int pipe_fds[2];
233 pid_t recycled_pid;
234 int child_ret = PIDFD_PASS;
235
236 ret = pipe2(pipe_fds, O_CLOEXEC);
237 if (ret < 0)
238 _exit(PIDFD_ERROR);
239
240 recycled_pid = fork();
241 if (recycled_pid < 0)
242 _exit(PIDFD_ERROR);
243
244 if (recycled_pid == 0) {
245 close(pipe_fds[1]);
246 (void)read(pipe_fds[0], &c, 1);
247 close(pipe_fds[0]);
248
249 _exit(PIDFD_PASS);
250 }
251
252 /*
253 * Stop the child so we can inspect whether we have
254 * recycled pid PID_RECYCLE.
255 */
256 close(pipe_fds[0]);
257 ret = kill(recycled_pid, SIGSTOP);
258 close(pipe_fds[1]);
259 if (ret) {
260 (void)wait_for_pid(recycled_pid);
261 _exit(PIDFD_ERROR);
262 }
263
264 /*
265 * We have recycled the pid. Try to signal it. This
266 * needs to fail since this is a different process than
267 * the one the pidfd refers to.
268 */
269 if (recycled_pid == PID_RECYCLE) {
270 ret = sys_pidfd_send_signal(pidfd, SIGCONT,
271 NULL, 0);
272 if (ret && errno == ESRCH)
273 child_ret = PIDFD_XFAIL;
274 else
275 child_ret = PIDFD_FAIL;
276 }
277
278 /* let the process move on */
279 ret = kill(recycled_pid, SIGCONT);
280 if (ret)
281 (void)kill(recycled_pid, SIGKILL);
282
283 if (wait_for_pid(recycled_pid))
284 _exit(PIDFD_ERROR);
285
286 switch (child_ret) {
287 case PIDFD_FAIL:
288 /* fallthrough */
289 case PIDFD_XFAIL:
290 _exit(child_ret);
291 case PIDFD_PASS:
292 break;
293 default:
294 /* not reached */
295 _exit(PIDFD_ERROR);
296 }
297
298 /*
299 * If the user set a custom pid_max limit we could be
300 * in the millions.
301 * Skip the test in this case.
302 */
303 if (recycled_pid > PIDFD_MAX_DEFAULT)
304 _exit(PIDFD_SKIP);
305 }
306
307 /* failed to recycle pid */
308 _exit(PIDFD_SKIP);
309 }
310
311 ret = wait_for_pid(pid1);
312 switch (ret) {
313 case PIDFD_FAIL:
314 ksft_exit_fail_msg(
315 "%s test: Managed to signal recycled pid %d\n",
316 test_name, PID_RECYCLE);
317 case PIDFD_PASS:
318 ksft_exit_fail_msg("%s test: Failed to recycle pid %d\n",
319 test_name, PID_RECYCLE);
320 case PIDFD_SKIP:
321 ksft_print_msg("%s test: Skipping test\n", test_name);
322 ret = 0;
323 break;
324 case PIDFD_XFAIL:
325 ksft_test_result_pass(
326 "%s test: Failed to signal recycled pid as expected\n",
327 test_name);
328 ret = 0;
329 break;
330 default /* PIDFD_ERROR */:
331 ksft_exit_fail_msg("%s test: Error while running tests\n",
332 test_name);
333 }
334
335 return ret;
336}
337
338static int test_pidfd_send_signal_syscall_support(void)
339{
340 int pidfd, ret;
341 const char *test_name = "pidfd_send_signal check for support";
342
343 pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC);
344 if (pidfd < 0)
345 ksft_exit_fail_msg(
346 "%s test: Failed to open process file descriptor\n",
347 test_name);
348
349 ret = sys_pidfd_send_signal(pidfd, 0, NULL, 0);
350 if (ret < 0) {
351 /*
352 * pidfd_send_signal() will currently return ENOSYS when
353 * CONFIG_PROC_FS is not set.
354 */
355 if (errno == ENOSYS)
356 ksft_exit_skip(
357 "%s test: pidfd_send_signal() syscall not supported (Ensure that CONFIG_PROC_FS=y is set)\n",
358 test_name);
359
360 ksft_exit_fail_msg("%s test: Failed to send signal\n",
361 test_name);
362 }
363
364 close(pidfd);
365 ksft_test_result_pass(
366 "%s test: pidfd_send_signal() syscall is supported. Tests can be executed\n",
367 test_name);
368 return 0;
369}
370
371int main(int argc, char **argv)
372{
373 ksft_print_header();
374
375 test_pidfd_send_signal_syscall_support();
376 test_pidfd_send_signal_simple_success();
377 test_pidfd_send_signal_exited_fail();
378 test_pidfd_send_signal_recycled_pid_fail();
379
380 return ksft_exit_pass();
381}
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index b07ac4614e1c..3417f2dbc366 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -25,6 +25,7 @@
25 25
26#include <clocksource/arm_arch_timer.h> 26#include <clocksource/arm_arch_timer.h>
27#include <asm/arch_timer.h> 27#include <asm/arch_timer.h>
28#include <asm/kvm_emulate.h>
28#include <asm/kvm_hyp.h> 29#include <asm/kvm_hyp.h>
29 30
30#include <kvm/arm_vgic.h> 31#include <kvm/arm_vgic.h>
@@ -34,7 +35,9 @@
34 35
35static struct timecounter *timecounter; 36static struct timecounter *timecounter;
36static unsigned int host_vtimer_irq; 37static unsigned int host_vtimer_irq;
38static unsigned int host_ptimer_irq;
37static u32 host_vtimer_irq_flags; 39static u32 host_vtimer_irq_flags;
40static u32 host_ptimer_irq_flags;
38 41
39static DEFINE_STATIC_KEY_FALSE(has_gic_active_state); 42static DEFINE_STATIC_KEY_FALSE(has_gic_active_state);
40 43
@@ -52,12 +55,34 @@ static bool kvm_timer_irq_can_fire(struct arch_timer_context *timer_ctx);
52static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level, 55static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
53 struct arch_timer_context *timer_ctx); 56 struct arch_timer_context *timer_ctx);
54static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx); 57static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx);
58static void kvm_arm_timer_write(struct kvm_vcpu *vcpu,
59 struct arch_timer_context *timer,
60 enum kvm_arch_timer_regs treg,
61 u64 val);
62static u64 kvm_arm_timer_read(struct kvm_vcpu *vcpu,
63 struct arch_timer_context *timer,
64 enum kvm_arch_timer_regs treg);
55 65
56u64 kvm_phys_timer_read(void) 66u64 kvm_phys_timer_read(void)
57{ 67{
58 return timecounter->cc->read(timecounter->cc); 68 return timecounter->cc->read(timecounter->cc);
59} 69}
60 70
71static void get_timer_map(struct kvm_vcpu *vcpu, struct timer_map *map)
72{
73 if (has_vhe()) {
74 map->direct_vtimer = vcpu_vtimer(vcpu);
75 map->direct_ptimer = vcpu_ptimer(vcpu);
76 map->emul_ptimer = NULL;
77 } else {
78 map->direct_vtimer = vcpu_vtimer(vcpu);
79 map->direct_ptimer = NULL;
80 map->emul_ptimer = vcpu_ptimer(vcpu);
81 }
82
83 trace_kvm_get_timer_map(vcpu->vcpu_id, map);
84}
85
61static inline bool userspace_irqchip(struct kvm *kvm) 86static inline bool userspace_irqchip(struct kvm *kvm)
62{ 87{
63 return static_branch_unlikely(&userspace_irqchip_in_use) && 88 return static_branch_unlikely(&userspace_irqchip_in_use) &&
@@ -78,20 +103,27 @@ static void soft_timer_cancel(struct hrtimer *hrt)
78static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) 103static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id)
79{ 104{
80 struct kvm_vcpu *vcpu = *(struct kvm_vcpu **)dev_id; 105 struct kvm_vcpu *vcpu = *(struct kvm_vcpu **)dev_id;
81 struct arch_timer_context *vtimer; 106 struct arch_timer_context *ctx;
107 struct timer_map map;
82 108
83 /* 109 /*
84 * We may see a timer interrupt after vcpu_put() has been called which 110 * We may see a timer interrupt after vcpu_put() has been called which
85 * sets the CPU's vcpu pointer to NULL, because even though the timer 111 * sets the CPU's vcpu pointer to NULL, because even though the timer
86 * has been disabled in vtimer_save_state(), the hardware interrupt 112 * has been disabled in timer_save_state(), the hardware interrupt
87 * signal may not have been retired from the interrupt controller yet. 113 * signal may not have been retired from the interrupt controller yet.
88 */ 114 */
89 if (!vcpu) 115 if (!vcpu)
90 return IRQ_HANDLED; 116 return IRQ_HANDLED;
91 117
92 vtimer = vcpu_vtimer(vcpu); 118 get_timer_map(vcpu, &map);
93 if (kvm_timer_should_fire(vtimer)) 119
94 kvm_timer_update_irq(vcpu, true, vtimer); 120 if (irq == host_vtimer_irq)
121 ctx = map.direct_vtimer;
122 else
123 ctx = map.direct_ptimer;
124
125 if (kvm_timer_should_fire(ctx))
126 kvm_timer_update_irq(vcpu, true, ctx);
95 127
96 if (userspace_irqchip(vcpu->kvm) && 128 if (userspace_irqchip(vcpu->kvm) &&
97 !static_branch_unlikely(&has_gic_active_state)) 129 !static_branch_unlikely(&has_gic_active_state))
@@ -122,7 +154,9 @@ static u64 kvm_timer_compute_delta(struct arch_timer_context *timer_ctx)
122 154
123static bool kvm_timer_irq_can_fire(struct arch_timer_context *timer_ctx) 155static bool kvm_timer_irq_can_fire(struct arch_timer_context *timer_ctx)
124{ 156{
125 return !(timer_ctx->cnt_ctl & ARCH_TIMER_CTRL_IT_MASK) && 157 WARN_ON(timer_ctx && timer_ctx->loaded);
158 return timer_ctx &&
159 !(timer_ctx->cnt_ctl & ARCH_TIMER_CTRL_IT_MASK) &&
126 (timer_ctx->cnt_ctl & ARCH_TIMER_CTRL_ENABLE); 160 (timer_ctx->cnt_ctl & ARCH_TIMER_CTRL_ENABLE);
127} 161}
128 162
@@ -132,21 +166,22 @@ static bool kvm_timer_irq_can_fire(struct arch_timer_context *timer_ctx)
132 */ 166 */
133static u64 kvm_timer_earliest_exp(struct kvm_vcpu *vcpu) 167static u64 kvm_timer_earliest_exp(struct kvm_vcpu *vcpu)
134{ 168{
135 u64 min_virt = ULLONG_MAX, min_phys = ULLONG_MAX; 169 u64 min_delta = ULLONG_MAX;
136 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 170 int i;
137 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
138 171
139 if (kvm_timer_irq_can_fire(vtimer)) 172 for (i = 0; i < NR_KVM_TIMERS; i++) {
140 min_virt = kvm_timer_compute_delta(vtimer); 173 struct arch_timer_context *ctx = &vcpu->arch.timer_cpu.timers[i];
141 174
142 if (kvm_timer_irq_can_fire(ptimer)) 175 WARN(ctx->loaded, "timer %d loaded\n", i);
143 min_phys = kvm_timer_compute_delta(ptimer); 176 if (kvm_timer_irq_can_fire(ctx))
177 min_delta = min(min_delta, kvm_timer_compute_delta(ctx));
178 }
144 179
145 /* If none of timers can fire, then return 0 */ 180 /* If none of timers can fire, then return 0 */
146 if ((min_virt == ULLONG_MAX) && (min_phys == ULLONG_MAX)) 181 if (min_delta == ULLONG_MAX)
147 return 0; 182 return 0;
148 183
149 return min(min_virt, min_phys); 184 return min_delta;
150} 185}
151 186
152static enum hrtimer_restart kvm_bg_timer_expire(struct hrtimer *hrt) 187static enum hrtimer_restart kvm_bg_timer_expire(struct hrtimer *hrt)
@@ -173,41 +208,58 @@ static enum hrtimer_restart kvm_bg_timer_expire(struct hrtimer *hrt)
173 return HRTIMER_NORESTART; 208 return HRTIMER_NORESTART;
174} 209}
175 210
176static enum hrtimer_restart kvm_phys_timer_expire(struct hrtimer *hrt) 211static enum hrtimer_restart kvm_hrtimer_expire(struct hrtimer *hrt)
177{ 212{
178 struct arch_timer_context *ptimer; 213 struct arch_timer_context *ctx;
179 struct arch_timer_cpu *timer;
180 struct kvm_vcpu *vcpu; 214 struct kvm_vcpu *vcpu;
181 u64 ns; 215 u64 ns;
182 216
183 timer = container_of(hrt, struct arch_timer_cpu, phys_timer); 217 ctx = container_of(hrt, struct arch_timer_context, hrtimer);
184 vcpu = container_of(timer, struct kvm_vcpu, arch.timer_cpu); 218 vcpu = ctx->vcpu;
185 ptimer = vcpu_ptimer(vcpu); 219
220 trace_kvm_timer_hrtimer_expire(ctx);
186 221
187 /* 222 /*
188 * Check that the timer has really expired from the guest's 223 * Check that the timer has really expired from the guest's
189 * PoV (NTP on the host may have forced it to expire 224 * PoV (NTP on the host may have forced it to expire
190 * early). If not ready, schedule for a later time. 225 * early). If not ready, schedule for a later time.
191 */ 226 */
192 ns = kvm_timer_compute_delta(ptimer); 227 ns = kvm_timer_compute_delta(ctx);
193 if (unlikely(ns)) { 228 if (unlikely(ns)) {
194 hrtimer_forward_now(hrt, ns_to_ktime(ns)); 229 hrtimer_forward_now(hrt, ns_to_ktime(ns));
195 return HRTIMER_RESTART; 230 return HRTIMER_RESTART;
196 } 231 }
197 232
198 kvm_timer_update_irq(vcpu, true, ptimer); 233 kvm_timer_update_irq(vcpu, true, ctx);
199 return HRTIMER_NORESTART; 234 return HRTIMER_NORESTART;
200} 235}
201 236
202static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx) 237static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx)
203{ 238{
239 enum kvm_arch_timers index;
204 u64 cval, now; 240 u64 cval, now;
205 241
242 if (!timer_ctx)
243 return false;
244
245 index = arch_timer_ctx_index(timer_ctx);
246
206 if (timer_ctx->loaded) { 247 if (timer_ctx->loaded) {
207 u32 cnt_ctl; 248 u32 cnt_ctl = 0;
249
250 switch (index) {
251 case TIMER_VTIMER:
252 cnt_ctl = read_sysreg_el0(cntv_ctl);
253 break;
254 case TIMER_PTIMER:
255 cnt_ctl = read_sysreg_el0(cntp_ctl);
256 break;
257 case NR_KVM_TIMERS:
258 /* GCC is braindead */
259 cnt_ctl = 0;
260 break;
261 }
208 262
209 /* Only the virtual timer can be loaded so far */
210 cnt_ctl = read_sysreg_el0(cntv_ctl);
211 return (cnt_ctl & ARCH_TIMER_CTRL_ENABLE) && 263 return (cnt_ctl & ARCH_TIMER_CTRL_ENABLE) &&
212 (cnt_ctl & ARCH_TIMER_CTRL_IT_STAT) && 264 (cnt_ctl & ARCH_TIMER_CTRL_IT_STAT) &&
213 !(cnt_ctl & ARCH_TIMER_CTRL_IT_MASK); 265 !(cnt_ctl & ARCH_TIMER_CTRL_IT_MASK);
@@ -224,13 +276,13 @@ static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx)
224 276
225bool kvm_timer_is_pending(struct kvm_vcpu *vcpu) 277bool kvm_timer_is_pending(struct kvm_vcpu *vcpu)
226{ 278{
227 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 279 struct timer_map map;
228 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
229 280
230 if (kvm_timer_should_fire(vtimer)) 281 get_timer_map(vcpu, &map);
231 return true;
232 282
233 return kvm_timer_should_fire(ptimer); 283 return kvm_timer_should_fire(map.direct_vtimer) ||
284 kvm_timer_should_fire(map.direct_ptimer) ||
285 kvm_timer_should_fire(map.emul_ptimer);
234} 286}
235 287
236/* 288/*
@@ -269,77 +321,70 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
269 } 321 }
270} 322}
271 323
272/* Schedule the background timer for the emulated timer. */ 324static void timer_emulate(struct arch_timer_context *ctx)
273static void phys_timer_emulate(struct kvm_vcpu *vcpu)
274{ 325{
275 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 326 bool should_fire = kvm_timer_should_fire(ctx);
276 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); 327
328 trace_kvm_timer_emulate(ctx, should_fire);
329
330 if (should_fire) {
331 kvm_timer_update_irq(ctx->vcpu, true, ctx);
332 return;
333 }
277 334
278 /* 335 /*
279 * If the timer can fire now, we don't need to have a soft timer 336 * If the timer can fire now, we don't need to have a soft timer
280 * scheduled for the future. If the timer cannot fire at all, 337 * scheduled for the future. If the timer cannot fire at all,
281 * then we also don't need a soft timer. 338 * then we also don't need a soft timer.
282 */ 339 */
283 if (kvm_timer_should_fire(ptimer) || !kvm_timer_irq_can_fire(ptimer)) { 340 if (!kvm_timer_irq_can_fire(ctx)) {
284 soft_timer_cancel(&timer->phys_timer); 341 soft_timer_cancel(&ctx->hrtimer);
285 return; 342 return;
286 } 343 }
287 344
288 soft_timer_start(&timer->phys_timer, kvm_timer_compute_delta(ptimer)); 345 soft_timer_start(&ctx->hrtimer, kvm_timer_compute_delta(ctx));
289} 346}
290 347
291/* 348static void timer_save_state(struct arch_timer_context *ctx)
292 * Check if there was a change in the timer state, so that we should either
293 * raise or lower the line level to the GIC or schedule a background timer to
294 * emulate the physical timer.
295 */
296static void kvm_timer_update_state(struct kvm_vcpu *vcpu)
297{ 349{
298 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 350 struct arch_timer_cpu *timer = vcpu_timer(ctx->vcpu);
299 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 351 enum kvm_arch_timers index = arch_timer_ctx_index(ctx);
300 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); 352 unsigned long flags;
301 bool level;
302 353
303 if (unlikely(!timer->enabled)) 354 if (!timer->enabled)
304 return; 355 return;
305 356
306 /* 357 local_irq_save(flags);
307 * The vtimer virtual interrupt is a 'mapped' interrupt, meaning part
308 * of its lifecycle is offloaded to the hardware, and we therefore may
309 * not have lowered the irq.level value before having to signal a new
310 * interrupt, but have to signal an interrupt every time the level is
311 * asserted.
312 */
313 level = kvm_timer_should_fire(vtimer);
314 kvm_timer_update_irq(vcpu, level, vtimer);
315 358
316 phys_timer_emulate(vcpu); 359 if (!ctx->loaded)
360 goto out;
317 361
318 if (kvm_timer_should_fire(ptimer) != ptimer->irq.level) 362 switch (index) {
319 kvm_timer_update_irq(vcpu, !ptimer->irq.level, ptimer); 363 case TIMER_VTIMER:
320} 364 ctx->cnt_ctl = read_sysreg_el0(cntv_ctl);
365 ctx->cnt_cval = read_sysreg_el0(cntv_cval);
321 366
322static void vtimer_save_state(struct kvm_vcpu *vcpu) 367 /* Disable the timer */
323{ 368 write_sysreg_el0(0, cntv_ctl);
324 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 369 isb();
325 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
326 unsigned long flags;
327 370
328 local_irq_save(flags); 371 break;
372 case TIMER_PTIMER:
373 ctx->cnt_ctl = read_sysreg_el0(cntp_ctl);
374 ctx->cnt_cval = read_sysreg_el0(cntp_cval);
329 375
330 if (!vtimer->loaded) 376 /* Disable the timer */
331 goto out; 377 write_sysreg_el0(0, cntp_ctl);
378 isb();
332 379
333 if (timer->enabled) { 380 break;
334 vtimer->cnt_ctl = read_sysreg_el0(cntv_ctl); 381 case NR_KVM_TIMERS:
335 vtimer->cnt_cval = read_sysreg_el0(cntv_cval); 382 BUG();
336 } 383 }
337 384
338 /* Disable the virtual timer */ 385 trace_kvm_timer_save_state(ctx);
339 write_sysreg_el0(0, cntv_ctl);
340 isb();
341 386
342 vtimer->loaded = false; 387 ctx->loaded = false;
343out: 388out:
344 local_irq_restore(flags); 389 local_irq_restore(flags);
345} 390}
@@ -349,67 +394,72 @@ out:
349 * thread is removed from its waitqueue and made runnable when there's a timer 394 * thread is removed from its waitqueue and made runnable when there's a timer
350 * interrupt to handle. 395 * interrupt to handle.
351 */ 396 */
352void kvm_timer_schedule(struct kvm_vcpu *vcpu) 397static void kvm_timer_blocking(struct kvm_vcpu *vcpu)
353{ 398{
354 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 399 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
355 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 400 struct timer_map map;
356 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
357
358 vtimer_save_state(vcpu);
359 401
360 /* 402 get_timer_map(vcpu, &map);
361 * No need to schedule a background timer if any guest timer has
362 * already expired, because kvm_vcpu_block will return before putting
363 * the thread to sleep.
364 */
365 if (kvm_timer_should_fire(vtimer) || kvm_timer_should_fire(ptimer))
366 return;
367 403
368 /* 404 /*
369 * If both timers are not capable of raising interrupts (disabled or 405 * If no timers are capable of raising interrupts (disabled or
370 * masked), then there's no more work for us to do. 406 * masked), then there's no more work for us to do.
371 */ 407 */
372 if (!kvm_timer_irq_can_fire(vtimer) && !kvm_timer_irq_can_fire(ptimer)) 408 if (!kvm_timer_irq_can_fire(map.direct_vtimer) &&
409 !kvm_timer_irq_can_fire(map.direct_ptimer) &&
410 !kvm_timer_irq_can_fire(map.emul_ptimer))
373 return; 411 return;
374 412
375 /* 413 /*
376 * The guest timers have not yet expired, schedule a background timer. 414 * At least one guest time will expire. Schedule a background timer.
377 * Set the earliest expiration time among the guest timers. 415 * Set the earliest expiration time among the guest timers.
378 */ 416 */
379 soft_timer_start(&timer->bg_timer, kvm_timer_earliest_exp(vcpu)); 417 soft_timer_start(&timer->bg_timer, kvm_timer_earliest_exp(vcpu));
380} 418}
381 419
382static void vtimer_restore_state(struct kvm_vcpu *vcpu) 420static void kvm_timer_unblocking(struct kvm_vcpu *vcpu)
383{ 421{
384 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 422 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
385 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 423
424 soft_timer_cancel(&timer->bg_timer);
425}
426
427static void timer_restore_state(struct arch_timer_context *ctx)
428{
429 struct arch_timer_cpu *timer = vcpu_timer(ctx->vcpu);
430 enum kvm_arch_timers index = arch_timer_ctx_index(ctx);
386 unsigned long flags; 431 unsigned long flags;
387 432
433 if (!timer->enabled)
434 return;
435
388 local_irq_save(flags); 436 local_irq_save(flags);
389 437
390 if (vtimer->loaded) 438 if (ctx->loaded)
391 goto out; 439 goto out;
392 440
393 if (timer->enabled) { 441 switch (index) {
394 write_sysreg_el0(vtimer->cnt_cval, cntv_cval); 442 case TIMER_VTIMER:
443 write_sysreg_el0(ctx->cnt_cval, cntv_cval);
395 isb(); 444 isb();
396 write_sysreg_el0(vtimer->cnt_ctl, cntv_ctl); 445 write_sysreg_el0(ctx->cnt_ctl, cntv_ctl);
446 break;
447 case TIMER_PTIMER:
448 write_sysreg_el0(ctx->cnt_cval, cntp_cval);
449 isb();
450 write_sysreg_el0(ctx->cnt_ctl, cntp_ctl);
451 break;
452 case NR_KVM_TIMERS:
453 BUG();
397 } 454 }
398 455
399 vtimer->loaded = true; 456 trace_kvm_timer_restore_state(ctx);
457
458 ctx->loaded = true;
400out: 459out:
401 local_irq_restore(flags); 460 local_irq_restore(flags);
402} 461}
403 462
404void kvm_timer_unschedule(struct kvm_vcpu *vcpu)
405{
406 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
407
408 vtimer_restore_state(vcpu);
409
410 soft_timer_cancel(&timer->bg_timer);
411}
412
413static void set_cntvoff(u64 cntvoff) 463static void set_cntvoff(u64 cntvoff)
414{ 464{
415 u32 low = lower_32_bits(cntvoff); 465 u32 low = lower_32_bits(cntvoff);
@@ -425,23 +475,32 @@ static void set_cntvoff(u64 cntvoff)
425 kvm_call_hyp(__kvm_timer_set_cntvoff, low, high); 475 kvm_call_hyp(__kvm_timer_set_cntvoff, low, high);
426} 476}
427 477
428static inline void set_vtimer_irq_phys_active(struct kvm_vcpu *vcpu, bool active) 478static inline void set_timer_irq_phys_active(struct arch_timer_context *ctx, bool active)
429{ 479{
430 int r; 480 int r;
431 r = irq_set_irqchip_state(host_vtimer_irq, IRQCHIP_STATE_ACTIVE, active); 481 r = irq_set_irqchip_state(ctx->host_timer_irq, IRQCHIP_STATE_ACTIVE, active);
432 WARN_ON(r); 482 WARN_ON(r);
433} 483}
434 484
435static void kvm_timer_vcpu_load_gic(struct kvm_vcpu *vcpu) 485static void kvm_timer_vcpu_load_gic(struct arch_timer_context *ctx)
436{ 486{
437 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 487 struct kvm_vcpu *vcpu = ctx->vcpu;
438 bool phys_active; 488 bool phys_active = false;
489
490 /*
491 * Update the timer output so that it is likely to match the
492 * state we're about to restore. If the timer expires between
493 * this point and the register restoration, we'll take the
494 * interrupt anyway.
495 */
496 kvm_timer_update_irq(ctx->vcpu, kvm_timer_should_fire(ctx), ctx);
439 497
440 if (irqchip_in_kernel(vcpu->kvm)) 498 if (irqchip_in_kernel(vcpu->kvm))
441 phys_active = kvm_vgic_map_is_active(vcpu, vtimer->irq.irq); 499 phys_active = kvm_vgic_map_is_active(vcpu, ctx->irq.irq);
442 else 500
443 phys_active = vtimer->irq.level; 501 phys_active |= ctx->irq.level;
444 set_vtimer_irq_phys_active(vcpu, phys_active); 502
503 set_timer_irq_phys_active(ctx, phys_active);
445} 504}
446 505
447static void kvm_timer_vcpu_load_nogic(struct kvm_vcpu *vcpu) 506static void kvm_timer_vcpu_load_nogic(struct kvm_vcpu *vcpu)
@@ -466,28 +525,32 @@ static void kvm_timer_vcpu_load_nogic(struct kvm_vcpu *vcpu)
466 525
467void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu) 526void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu)
468{ 527{
469 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 528 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
470 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 529 struct timer_map map;
471 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
472 530
473 if (unlikely(!timer->enabled)) 531 if (unlikely(!timer->enabled))
474 return; 532 return;
475 533
476 if (static_branch_likely(&has_gic_active_state)) 534 get_timer_map(vcpu, &map);
477 kvm_timer_vcpu_load_gic(vcpu); 535
478 else 536 if (static_branch_likely(&has_gic_active_state)) {
537 kvm_timer_vcpu_load_gic(map.direct_vtimer);
538 if (map.direct_ptimer)
539 kvm_timer_vcpu_load_gic(map.direct_ptimer);
540 } else {
479 kvm_timer_vcpu_load_nogic(vcpu); 541 kvm_timer_vcpu_load_nogic(vcpu);
542 }
480 543
481 set_cntvoff(vtimer->cntvoff); 544 set_cntvoff(map.direct_vtimer->cntvoff);
482 545
483 vtimer_restore_state(vcpu); 546 kvm_timer_unblocking(vcpu);
484 547
485 /* Set the background timer for the physical timer emulation. */ 548 timer_restore_state(map.direct_vtimer);
486 phys_timer_emulate(vcpu); 549 if (map.direct_ptimer)
550 timer_restore_state(map.direct_ptimer);
487 551
488 /* If the timer fired while we weren't running, inject it now */ 552 if (map.emul_ptimer)
489 if (kvm_timer_should_fire(ptimer) != ptimer->irq.level) 553 timer_emulate(map.emul_ptimer);
490 kvm_timer_update_irq(vcpu, !ptimer->irq.level, ptimer);
491} 554}
492 555
493bool kvm_timer_should_notify_user(struct kvm_vcpu *vcpu) 556bool kvm_timer_should_notify_user(struct kvm_vcpu *vcpu)
@@ -509,15 +572,20 @@ bool kvm_timer_should_notify_user(struct kvm_vcpu *vcpu)
509 572
510void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu) 573void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu)
511{ 574{
512 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 575 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
576 struct timer_map map;
513 577
514 if (unlikely(!timer->enabled)) 578 if (unlikely(!timer->enabled))
515 return; 579 return;
516 580
517 vtimer_save_state(vcpu); 581 get_timer_map(vcpu, &map);
582
583 timer_save_state(map.direct_vtimer);
584 if (map.direct_ptimer)
585 timer_save_state(map.direct_ptimer);
518 586
519 /* 587 /*
520 * Cancel the physical timer emulation, because the only case where we 588 * Cancel soft timer emulation, because the only case where we
521 * need it after a vcpu_put is in the context of a sleeping VCPU, and 589 * need it after a vcpu_put is in the context of a sleeping VCPU, and
522 * in that case we already factor in the deadline for the physical 590 * in that case we already factor in the deadline for the physical
523 * timer when scheduling the bg_timer. 591 * timer when scheduling the bg_timer.
@@ -525,7 +593,11 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu)
525 * In any case, we re-schedule the hrtimer for the physical timer when 593 * In any case, we re-schedule the hrtimer for the physical timer when
526 * coming back to the VCPU thread in kvm_timer_vcpu_load(). 594 * coming back to the VCPU thread in kvm_timer_vcpu_load().
527 */ 595 */
528 soft_timer_cancel(&timer->phys_timer); 596 if (map.emul_ptimer)
597 soft_timer_cancel(&map.emul_ptimer->hrtimer);
598
599 if (swait_active(kvm_arch_vcpu_wq(vcpu)))
600 kvm_timer_blocking(vcpu);
529 601
530 /* 602 /*
531 * The kernel may decide to run userspace after calling vcpu_put, so 603 * The kernel may decide to run userspace after calling vcpu_put, so
@@ -534,8 +606,7 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu)
534 * counter of non-VHE case. For VHE, the virtual counter uses a fixed 606 * counter of non-VHE case. For VHE, the virtual counter uses a fixed
535 * virtual offset of zero, so no need to zero CNTVOFF_EL2 register. 607 * virtual offset of zero, so no need to zero CNTVOFF_EL2 register.
536 */ 608 */
537 if (!has_vhe()) 609 set_cntvoff(0);
538 set_cntvoff(0);
539} 610}
540 611
541/* 612/*
@@ -550,7 +621,7 @@ static void unmask_vtimer_irq_user(struct kvm_vcpu *vcpu)
550 if (!kvm_timer_should_fire(vtimer)) { 621 if (!kvm_timer_should_fire(vtimer)) {
551 kvm_timer_update_irq(vcpu, false, vtimer); 622 kvm_timer_update_irq(vcpu, false, vtimer);
552 if (static_branch_likely(&has_gic_active_state)) 623 if (static_branch_likely(&has_gic_active_state))
553 set_vtimer_irq_phys_active(vcpu, false); 624 set_timer_irq_phys_active(vtimer, false);
554 else 625 else
555 enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags); 626 enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags);
556 } 627 }
@@ -558,7 +629,7 @@ static void unmask_vtimer_irq_user(struct kvm_vcpu *vcpu)
558 629
559void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) 630void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu)
560{ 631{
561 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 632 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
562 633
563 if (unlikely(!timer->enabled)) 634 if (unlikely(!timer->enabled))
564 return; 635 return;
@@ -569,9 +640,10 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu)
569 640
570int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu) 641int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu)
571{ 642{
572 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 643 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
573 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 644 struct timer_map map;
574 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); 645
646 get_timer_map(vcpu, &map);
575 647
576 /* 648 /*
577 * The bits in CNTV_CTL are architecturally reset to UNKNOWN for ARMv8 649 * The bits in CNTV_CTL are architecturally reset to UNKNOWN for ARMv8
@@ -579,12 +651,22 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu)
579 * resets the timer to be disabled and unmasked and is compliant with 651 * resets the timer to be disabled and unmasked and is compliant with
580 * the ARMv7 architecture. 652 * the ARMv7 architecture.
581 */ 653 */
582 vtimer->cnt_ctl = 0; 654 vcpu_vtimer(vcpu)->cnt_ctl = 0;
583 ptimer->cnt_ctl = 0; 655 vcpu_ptimer(vcpu)->cnt_ctl = 0;
584 kvm_timer_update_state(vcpu);
585 656
586 if (timer->enabled && irqchip_in_kernel(vcpu->kvm)) 657 if (timer->enabled) {
587 kvm_vgic_reset_mapped_irq(vcpu, vtimer->irq.irq); 658 kvm_timer_update_irq(vcpu, false, vcpu_vtimer(vcpu));
659 kvm_timer_update_irq(vcpu, false, vcpu_ptimer(vcpu));
660
661 if (irqchip_in_kernel(vcpu->kvm)) {
662 kvm_vgic_reset_mapped_irq(vcpu, map.direct_vtimer->irq.irq);
663 if (map.direct_ptimer)
664 kvm_vgic_reset_mapped_irq(vcpu, map.direct_ptimer->irq.irq);
665 }
666 }
667
668 if (map.emul_ptimer)
669 soft_timer_cancel(&map.emul_ptimer->hrtimer);
588 670
589 return 0; 671 return 0;
590} 672}
@@ -610,56 +692,76 @@ static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff)
610 692
611void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) 693void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
612{ 694{
613 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 695 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
614 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 696 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
615 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); 697 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
616 698
617 /* Synchronize cntvoff across all vtimers of a VM. */ 699 /* Synchronize cntvoff across all vtimers of a VM. */
618 update_vtimer_cntvoff(vcpu, kvm_phys_timer_read()); 700 update_vtimer_cntvoff(vcpu, kvm_phys_timer_read());
619 vcpu_ptimer(vcpu)->cntvoff = 0; 701 ptimer->cntvoff = 0;
620 702
621 hrtimer_init(&timer->bg_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 703 hrtimer_init(&timer->bg_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
622 timer->bg_timer.function = kvm_bg_timer_expire; 704 timer->bg_timer.function = kvm_bg_timer_expire;
623 705
624 hrtimer_init(&timer->phys_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 706 hrtimer_init(&vtimer->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
625 timer->phys_timer.function = kvm_phys_timer_expire; 707 hrtimer_init(&ptimer->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
708 vtimer->hrtimer.function = kvm_hrtimer_expire;
709 ptimer->hrtimer.function = kvm_hrtimer_expire;
626 710
627 vtimer->irq.irq = default_vtimer_irq.irq; 711 vtimer->irq.irq = default_vtimer_irq.irq;
628 ptimer->irq.irq = default_ptimer_irq.irq; 712 ptimer->irq.irq = default_ptimer_irq.irq;
713
714 vtimer->host_timer_irq = host_vtimer_irq;
715 ptimer->host_timer_irq = host_ptimer_irq;
716
717 vtimer->host_timer_irq_flags = host_vtimer_irq_flags;
718 ptimer->host_timer_irq_flags = host_ptimer_irq_flags;
719
720 vtimer->vcpu = vcpu;
721 ptimer->vcpu = vcpu;
629} 722}
630 723
631static void kvm_timer_init_interrupt(void *info) 724static void kvm_timer_init_interrupt(void *info)
632{ 725{
633 enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags); 726 enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags);
727 enable_percpu_irq(host_ptimer_irq, host_ptimer_irq_flags);
634} 728}
635 729
636int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) 730int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value)
637{ 731{
638 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 732 struct arch_timer_context *timer;
639 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); 733 bool level;
640 734
641 switch (regid) { 735 switch (regid) {
642 case KVM_REG_ARM_TIMER_CTL: 736 case KVM_REG_ARM_TIMER_CTL:
643 vtimer->cnt_ctl = value & ~ARCH_TIMER_CTRL_IT_STAT; 737 timer = vcpu_vtimer(vcpu);
738 kvm_arm_timer_write(vcpu, timer, TIMER_REG_CTL, value);
644 break; 739 break;
645 case KVM_REG_ARM_TIMER_CNT: 740 case KVM_REG_ARM_TIMER_CNT:
741 timer = vcpu_vtimer(vcpu);
646 update_vtimer_cntvoff(vcpu, kvm_phys_timer_read() - value); 742 update_vtimer_cntvoff(vcpu, kvm_phys_timer_read() - value);
647 break; 743 break;
648 case KVM_REG_ARM_TIMER_CVAL: 744 case KVM_REG_ARM_TIMER_CVAL:
649 vtimer->cnt_cval = value; 745 timer = vcpu_vtimer(vcpu);
746 kvm_arm_timer_write(vcpu, timer, TIMER_REG_CVAL, value);
650 break; 747 break;
651 case KVM_REG_ARM_PTIMER_CTL: 748 case KVM_REG_ARM_PTIMER_CTL:
652 ptimer->cnt_ctl = value & ~ARCH_TIMER_CTRL_IT_STAT; 749 timer = vcpu_ptimer(vcpu);
750 kvm_arm_timer_write(vcpu, timer, TIMER_REG_CTL, value);
653 break; 751 break;
654 case KVM_REG_ARM_PTIMER_CVAL: 752 case KVM_REG_ARM_PTIMER_CVAL:
655 ptimer->cnt_cval = value; 753 timer = vcpu_ptimer(vcpu);
754 kvm_arm_timer_write(vcpu, timer, TIMER_REG_CVAL, value);
656 break; 755 break;
657 756
658 default: 757 default:
659 return -1; 758 return -1;
660 } 759 }
661 760
662 kvm_timer_update_state(vcpu); 761 level = kvm_timer_should_fire(timer);
762 kvm_timer_update_irq(vcpu, level, timer);
763 timer_emulate(timer);
764
663 return 0; 765 return 0;
664} 766}
665 767
@@ -679,26 +781,113 @@ static u64 read_timer_ctl(struct arch_timer_context *timer)
679 781
680u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid) 782u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid)
681{ 783{
682 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
683 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
684
685 switch (regid) { 784 switch (regid) {
686 case KVM_REG_ARM_TIMER_CTL: 785 case KVM_REG_ARM_TIMER_CTL:
687 return read_timer_ctl(vtimer); 786 return kvm_arm_timer_read(vcpu,
787 vcpu_vtimer(vcpu), TIMER_REG_CTL);
688 case KVM_REG_ARM_TIMER_CNT: 788 case KVM_REG_ARM_TIMER_CNT:
689 return kvm_phys_timer_read() - vtimer->cntvoff; 789 return kvm_arm_timer_read(vcpu,
790 vcpu_vtimer(vcpu), TIMER_REG_CNT);
690 case KVM_REG_ARM_TIMER_CVAL: 791 case KVM_REG_ARM_TIMER_CVAL:
691 return vtimer->cnt_cval; 792 return kvm_arm_timer_read(vcpu,
793 vcpu_vtimer(vcpu), TIMER_REG_CVAL);
692 case KVM_REG_ARM_PTIMER_CTL: 794 case KVM_REG_ARM_PTIMER_CTL:
693 return read_timer_ctl(ptimer); 795 return kvm_arm_timer_read(vcpu,
694 case KVM_REG_ARM_PTIMER_CVAL: 796 vcpu_ptimer(vcpu), TIMER_REG_CTL);
695 return ptimer->cnt_cval;
696 case KVM_REG_ARM_PTIMER_CNT: 797 case KVM_REG_ARM_PTIMER_CNT:
697 return kvm_phys_timer_read(); 798 return kvm_arm_timer_read(vcpu,
799 vcpu_vtimer(vcpu), TIMER_REG_CNT);
800 case KVM_REG_ARM_PTIMER_CVAL:
801 return kvm_arm_timer_read(vcpu,
802 vcpu_ptimer(vcpu), TIMER_REG_CVAL);
698 } 803 }
699 return (u64)-1; 804 return (u64)-1;
700} 805}
701 806
807static u64 kvm_arm_timer_read(struct kvm_vcpu *vcpu,
808 struct arch_timer_context *timer,
809 enum kvm_arch_timer_regs treg)
810{
811 u64 val;
812
813 switch (treg) {
814 case TIMER_REG_TVAL:
815 val = kvm_phys_timer_read() - timer->cntvoff - timer->cnt_cval;
816 break;
817
818 case TIMER_REG_CTL:
819 val = read_timer_ctl(timer);
820 break;
821
822 case TIMER_REG_CVAL:
823 val = timer->cnt_cval;
824 break;
825
826 case TIMER_REG_CNT:
827 val = kvm_phys_timer_read() - timer->cntvoff;
828 break;
829
830 default:
831 BUG();
832 }
833
834 return val;
835}
836
837u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,
838 enum kvm_arch_timers tmr,
839 enum kvm_arch_timer_regs treg)
840{
841 u64 val;
842
843 preempt_disable();
844 kvm_timer_vcpu_put(vcpu);
845
846 val = kvm_arm_timer_read(vcpu, vcpu_get_timer(vcpu, tmr), treg);
847
848 kvm_timer_vcpu_load(vcpu);
849 preempt_enable();
850
851 return val;
852}
853
854static void kvm_arm_timer_write(struct kvm_vcpu *vcpu,
855 struct arch_timer_context *timer,
856 enum kvm_arch_timer_regs treg,
857 u64 val)
858{
859 switch (treg) {
860 case TIMER_REG_TVAL:
861 timer->cnt_cval = val - kvm_phys_timer_read() - timer->cntvoff;
862 break;
863
864 case TIMER_REG_CTL:
865 timer->cnt_ctl = val & ~ARCH_TIMER_CTRL_IT_STAT;
866 break;
867
868 case TIMER_REG_CVAL:
869 timer->cnt_cval = val;
870 break;
871
872 default:
873 BUG();
874 }
875}
876
877void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu,
878 enum kvm_arch_timers tmr,
879 enum kvm_arch_timer_regs treg,
880 u64 val)
881{
882 preempt_disable();
883 kvm_timer_vcpu_put(vcpu);
884
885 kvm_arm_timer_write(vcpu, vcpu_get_timer(vcpu, tmr), treg, val);
886
887 kvm_timer_vcpu_load(vcpu);
888 preempt_enable();
889}
890
702static int kvm_timer_starting_cpu(unsigned int cpu) 891static int kvm_timer_starting_cpu(unsigned int cpu)
703{ 892{
704 kvm_timer_init_interrupt(NULL); 893 kvm_timer_init_interrupt(NULL);
@@ -724,6 +913,8 @@ int kvm_timer_hyp_init(bool has_gic)
724 return -ENODEV; 913 return -ENODEV;
725 } 914 }
726 915
916 /* First, do the virtual EL1 timer irq */
917
727 if (info->virtual_irq <= 0) { 918 if (info->virtual_irq <= 0) {
728 kvm_err("kvm_arch_timer: invalid virtual timer IRQ: %d\n", 919 kvm_err("kvm_arch_timer: invalid virtual timer IRQ: %d\n",
729 info->virtual_irq); 920 info->virtual_irq);
@@ -734,15 +925,15 @@ int kvm_timer_hyp_init(bool has_gic)
734 host_vtimer_irq_flags = irq_get_trigger_type(host_vtimer_irq); 925 host_vtimer_irq_flags = irq_get_trigger_type(host_vtimer_irq);
735 if (host_vtimer_irq_flags != IRQF_TRIGGER_HIGH && 926 if (host_vtimer_irq_flags != IRQF_TRIGGER_HIGH &&
736 host_vtimer_irq_flags != IRQF_TRIGGER_LOW) { 927 host_vtimer_irq_flags != IRQF_TRIGGER_LOW) {
737 kvm_err("Invalid trigger for IRQ%d, assuming level low\n", 928 kvm_err("Invalid trigger for vtimer IRQ%d, assuming level low\n",
738 host_vtimer_irq); 929 host_vtimer_irq);
739 host_vtimer_irq_flags = IRQF_TRIGGER_LOW; 930 host_vtimer_irq_flags = IRQF_TRIGGER_LOW;
740 } 931 }
741 932
742 err = request_percpu_irq(host_vtimer_irq, kvm_arch_timer_handler, 933 err = request_percpu_irq(host_vtimer_irq, kvm_arch_timer_handler,
743 "kvm guest timer", kvm_get_running_vcpus()); 934 "kvm guest vtimer", kvm_get_running_vcpus());
744 if (err) { 935 if (err) {
745 kvm_err("kvm_arch_timer: can't request interrupt %d (%d)\n", 936 kvm_err("kvm_arch_timer: can't request vtimer interrupt %d (%d)\n",
746 host_vtimer_irq, err); 937 host_vtimer_irq, err);
747 return err; 938 return err;
748 } 939 }
@@ -760,6 +951,43 @@ int kvm_timer_hyp_init(bool has_gic)
760 951
761 kvm_debug("virtual timer IRQ%d\n", host_vtimer_irq); 952 kvm_debug("virtual timer IRQ%d\n", host_vtimer_irq);
762 953
954 /* Now let's do the physical EL1 timer irq */
955
956 if (info->physical_irq > 0) {
957 host_ptimer_irq = info->physical_irq;
958 host_ptimer_irq_flags = irq_get_trigger_type(host_ptimer_irq);
959 if (host_ptimer_irq_flags != IRQF_TRIGGER_HIGH &&
960 host_ptimer_irq_flags != IRQF_TRIGGER_LOW) {
961 kvm_err("Invalid trigger for ptimer IRQ%d, assuming level low\n",
962 host_ptimer_irq);
963 host_ptimer_irq_flags = IRQF_TRIGGER_LOW;
964 }
965
966 err = request_percpu_irq(host_ptimer_irq, kvm_arch_timer_handler,
967 "kvm guest ptimer", kvm_get_running_vcpus());
968 if (err) {
969 kvm_err("kvm_arch_timer: can't request ptimer interrupt %d (%d)\n",
970 host_ptimer_irq, err);
971 return err;
972 }
973
974 if (has_gic) {
975 err = irq_set_vcpu_affinity(host_ptimer_irq,
976 kvm_get_running_vcpus());
977 if (err) {
978 kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
979 goto out_free_irq;
980 }
981 }
982
983 kvm_debug("physical timer IRQ%d\n", host_ptimer_irq);
984 } else if (has_vhe()) {
985 kvm_err("kvm_arch_timer: invalid physical timer IRQ: %d\n",
986 info->physical_irq);
987 err = -ENODEV;
988 goto out_free_irq;
989 }
990
763 cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING, 991 cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING,
764 "kvm/arm/timer:starting", kvm_timer_starting_cpu, 992 "kvm/arm/timer:starting", kvm_timer_starting_cpu,
765 kvm_timer_dying_cpu); 993 kvm_timer_dying_cpu);
@@ -771,7 +999,7 @@ out_free_irq:
771 999
772void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) 1000void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
773{ 1001{
774 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 1002 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
775 1003
776 soft_timer_cancel(&timer->bg_timer); 1004 soft_timer_cancel(&timer->bg_timer);
777} 1005}
@@ -807,16 +1035,18 @@ bool kvm_arch_timer_get_input_level(int vintid)
807 1035
808 if (vintid == vcpu_vtimer(vcpu)->irq.irq) 1036 if (vintid == vcpu_vtimer(vcpu)->irq.irq)
809 timer = vcpu_vtimer(vcpu); 1037 timer = vcpu_vtimer(vcpu);
1038 else if (vintid == vcpu_ptimer(vcpu)->irq.irq)
1039 timer = vcpu_ptimer(vcpu);
810 else 1040 else
811 BUG(); /* We only map the vtimer so far */ 1041 BUG();
812 1042
813 return kvm_timer_should_fire(timer); 1043 return kvm_timer_should_fire(timer);
814} 1044}
815 1045
816int kvm_timer_enable(struct kvm_vcpu *vcpu) 1046int kvm_timer_enable(struct kvm_vcpu *vcpu)
817{ 1047{
818 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 1048 struct arch_timer_cpu *timer = vcpu_timer(vcpu);
819 struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); 1049 struct timer_map map;
820 int ret; 1050 int ret;
821 1051
822 if (timer->enabled) 1052 if (timer->enabled)
@@ -834,19 +1064,33 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu)
834 return -EINVAL; 1064 return -EINVAL;
835 } 1065 }
836 1066
837 ret = kvm_vgic_map_phys_irq(vcpu, host_vtimer_irq, vtimer->irq.irq, 1067 get_timer_map(vcpu, &map);
1068
1069 ret = kvm_vgic_map_phys_irq(vcpu,
1070 map.direct_vtimer->host_timer_irq,
1071 map.direct_vtimer->irq.irq,
838 kvm_arch_timer_get_input_level); 1072 kvm_arch_timer_get_input_level);
839 if (ret) 1073 if (ret)
840 return ret; 1074 return ret;
841 1075
1076 if (map.direct_ptimer) {
1077 ret = kvm_vgic_map_phys_irq(vcpu,
1078 map.direct_ptimer->host_timer_irq,
1079 map.direct_ptimer->irq.irq,
1080 kvm_arch_timer_get_input_level);
1081 }
1082
1083 if (ret)
1084 return ret;
1085
842no_vgic: 1086no_vgic:
843 timer->enabled = 1; 1087 timer->enabled = 1;
844 return 0; 1088 return 0;
845} 1089}
846 1090
847/* 1091/*
848 * On VHE system, we only need to configure trap on physical timer and counter 1092 * On VHE system, we only need to configure the EL2 timer trap register once,
849 * accesses in EL0 and EL1 once, not for every world switch. 1093 * not for every world switch.
850 * The host kernel runs at EL2 with HCR_EL2.TGE == 1, 1094 * The host kernel runs at EL2 with HCR_EL2.TGE == 1,
851 * and this makes those bits have no effect for the host kernel execution. 1095 * and this makes those bits have no effect for the host kernel execution.
852 */ 1096 */
@@ -857,11 +1101,11 @@ void kvm_timer_init_vhe(void)
857 u64 val; 1101 u64 val;
858 1102
859 /* 1103 /*
860 * Disallow physical timer access for the guest. 1104 * VHE systems allow the guest direct access to the EL1 physical
861 * Physical counter access is allowed. 1105 * timer/counter.
862 */ 1106 */
863 val = read_sysreg(cnthctl_el2); 1107 val = read_sysreg(cnthctl_el2);
864 val &= ~(CNTHCTL_EL1PCEN << cnthctl_shift); 1108 val |= (CNTHCTL_EL1PCEN << cnthctl_shift);
865 val |= (CNTHCTL_EL1PCTEN << cnthctl_shift); 1109 val |= (CNTHCTL_EL1PCTEN << cnthctl_shift);
866 write_sysreg(val, cnthctl_el2); 1110 write_sysreg(val, cnthctl_el2);
867} 1111}
diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
index 9c486fad3f9f..99c37384ba7b 100644
--- a/virt/kvm/arm/arm.c
+++ b/virt/kvm/arm/arm.c
@@ -65,7 +65,6 @@ static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
65/* The VMID used in the VTTBR */ 65/* The VMID used in the VTTBR */
66static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); 66static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
67static u32 kvm_next_vmid; 67static u32 kvm_next_vmid;
68static unsigned int kvm_vmid_bits __read_mostly;
69static DEFINE_SPINLOCK(kvm_vmid_lock); 68static DEFINE_SPINLOCK(kvm_vmid_lock);
70 69
71static bool vgic_present; 70static bool vgic_present;
@@ -142,7 +141,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
142 kvm_vgic_early_init(kvm); 141 kvm_vgic_early_init(kvm);
143 142
144 /* Mark the initial VMID generation invalid */ 143 /* Mark the initial VMID generation invalid */
145 kvm->arch.vmid_gen = 0; 144 kvm->arch.vmid.vmid_gen = 0;
146 145
147 /* The maximum number of VCPUs is limited by the host's GIC model */ 146 /* The maximum number of VCPUs is limited by the host's GIC model */
148 kvm->arch.max_vcpus = vgic_present ? 147 kvm->arch.max_vcpus = vgic_present ?
@@ -336,13 +335,11 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
336 335
337void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) 336void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu)
338{ 337{
339 kvm_timer_schedule(vcpu);
340 kvm_vgic_v4_enable_doorbell(vcpu); 338 kvm_vgic_v4_enable_doorbell(vcpu);
341} 339}
342 340
343void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) 341void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu)
344{ 342{
345 kvm_timer_unschedule(vcpu);
346 kvm_vgic_v4_disable_doorbell(vcpu); 343 kvm_vgic_v4_disable_doorbell(vcpu);
347} 344}
348 345
@@ -472,37 +469,31 @@ void force_vm_exit(const cpumask_t *mask)
472 469
473/** 470/**
474 * need_new_vmid_gen - check that the VMID is still valid 471 * need_new_vmid_gen - check that the VMID is still valid
475 * @kvm: The VM's VMID to check 472 * @vmid: The VMID to check
476 * 473 *
477 * return true if there is a new generation of VMIDs being used 474 * return true if there is a new generation of VMIDs being used
478 * 475 *
479 * The hardware supports only 256 values with the value zero reserved for the 476 * The hardware supports a limited set of values with the value zero reserved
480 * host, so we check if an assigned value belongs to a previous generation, 477 * for the host, so we check if an assigned value belongs to a previous
481 * which which requires us to assign a new value. If we're the first to use a 478 * generation, which which requires us to assign a new value. If we're the
482 * VMID for the new generation, we must flush necessary caches and TLBs on all 479 * first to use a VMID for the new generation, we must flush necessary caches
483 * CPUs. 480 * and TLBs on all CPUs.
484 */ 481 */
485static bool need_new_vmid_gen(struct kvm *kvm) 482static bool need_new_vmid_gen(struct kvm_vmid *vmid)
486{ 483{
487 u64 current_vmid_gen = atomic64_read(&kvm_vmid_gen); 484 u64 current_vmid_gen = atomic64_read(&kvm_vmid_gen);
488 smp_rmb(); /* Orders read of kvm_vmid_gen and kvm->arch.vmid */ 485 smp_rmb(); /* Orders read of kvm_vmid_gen and kvm->arch.vmid */
489 return unlikely(READ_ONCE(kvm->arch.vmid_gen) != current_vmid_gen); 486 return unlikely(READ_ONCE(vmid->vmid_gen) != current_vmid_gen);
490} 487}
491 488
492/** 489/**
493 * update_vttbr - Update the VTTBR with a valid VMID before the guest runs 490 * update_vmid - Update the vmid with a valid VMID for the current generation
494 * @kvm The guest that we are about to run 491 * @kvm: The guest that struct vmid belongs to
495 * 492 * @vmid: The stage-2 VMID information struct
496 * Called from kvm_arch_vcpu_ioctl_run before entering the guest to ensure the
497 * VM has a valid VMID, otherwise assigns a new one and flushes corresponding
498 * caches and TLBs.
499 */ 493 */
500static void update_vttbr(struct kvm *kvm) 494static void update_vmid(struct kvm_vmid *vmid)
501{ 495{
502 phys_addr_t pgd_phys; 496 if (!need_new_vmid_gen(vmid))
503 u64 vmid, cnp = kvm_cpu_has_cnp() ? VTTBR_CNP_BIT : 0;
504
505 if (!need_new_vmid_gen(kvm))
506 return; 497 return;
507 498
508 spin_lock(&kvm_vmid_lock); 499 spin_lock(&kvm_vmid_lock);
@@ -512,7 +503,7 @@ static void update_vttbr(struct kvm *kvm)
512 * already allocated a valid vmid for this vm, then this vcpu should 503 * already allocated a valid vmid for this vm, then this vcpu should
513 * use the same vmid. 504 * use the same vmid.
514 */ 505 */
515 if (!need_new_vmid_gen(kvm)) { 506 if (!need_new_vmid_gen(vmid)) {
516 spin_unlock(&kvm_vmid_lock); 507 spin_unlock(&kvm_vmid_lock);
517 return; 508 return;
518 } 509 }
@@ -536,18 +527,12 @@ static void update_vttbr(struct kvm *kvm)
536 kvm_call_hyp(__kvm_flush_vm_context); 527 kvm_call_hyp(__kvm_flush_vm_context);
537 } 528 }
538 529
539 kvm->arch.vmid = kvm_next_vmid; 530 vmid->vmid = kvm_next_vmid;
540 kvm_next_vmid++; 531 kvm_next_vmid++;
541 kvm_next_vmid &= (1 << kvm_vmid_bits) - 1; 532 kvm_next_vmid &= (1 << kvm_get_vmid_bits()) - 1;
542
543 /* update vttbr to be used with the new vmid */
544 pgd_phys = virt_to_phys(kvm->arch.pgd);
545 BUG_ON(pgd_phys & ~kvm_vttbr_baddr_mask(kvm));
546 vmid = ((u64)(kvm->arch.vmid) << VTTBR_VMID_SHIFT) & VTTBR_VMID_MASK(kvm_vmid_bits);
547 kvm->arch.vttbr = kvm_phys_to_vttbr(pgd_phys) | vmid | cnp;
548 533
549 smp_wmb(); 534 smp_wmb();
550 WRITE_ONCE(kvm->arch.vmid_gen, atomic64_read(&kvm_vmid_gen)); 535 WRITE_ONCE(vmid->vmid_gen, atomic64_read(&kvm_vmid_gen));
551 536
552 spin_unlock(&kvm_vmid_lock); 537 spin_unlock(&kvm_vmid_lock);
553} 538}
@@ -700,7 +685,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
700 */ 685 */
701 cond_resched(); 686 cond_resched();
702 687
703 update_vttbr(vcpu->kvm); 688 update_vmid(&vcpu->kvm->arch.vmid);
704 689
705 check_vcpu_requests(vcpu); 690 check_vcpu_requests(vcpu);
706 691
@@ -749,7 +734,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
749 */ 734 */
750 smp_store_mb(vcpu->mode, IN_GUEST_MODE); 735 smp_store_mb(vcpu->mode, IN_GUEST_MODE);
751 736
752 if (ret <= 0 || need_new_vmid_gen(vcpu->kvm) || 737 if (ret <= 0 || need_new_vmid_gen(&vcpu->kvm->arch.vmid) ||
753 kvm_request_pending(vcpu)) { 738 kvm_request_pending(vcpu)) {
754 vcpu->mode = OUTSIDE_GUEST_MODE; 739 vcpu->mode = OUTSIDE_GUEST_MODE;
755 isb(); /* Ensure work in x_flush_hwstate is committed */ 740 isb(); /* Ensure work in x_flush_hwstate is committed */
@@ -775,7 +760,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
775 ret = kvm_vcpu_run_vhe(vcpu); 760 ret = kvm_vcpu_run_vhe(vcpu);
776 kvm_arm_vhe_guest_exit(); 761 kvm_arm_vhe_guest_exit();
777 } else { 762 } else {
778 ret = kvm_call_hyp(__kvm_vcpu_run_nvhe, vcpu); 763 ret = kvm_call_hyp_ret(__kvm_vcpu_run_nvhe, vcpu);
779 } 764 }
780 765
781 vcpu->mode = OUTSIDE_GUEST_MODE; 766 vcpu->mode = OUTSIDE_GUEST_MODE;
@@ -1427,10 +1412,6 @@ static inline void hyp_cpu_pm_exit(void)
1427 1412
1428static int init_common_resources(void) 1413static int init_common_resources(void)
1429{ 1414{
1430 /* set size of VMID supported by CPU */
1431 kvm_vmid_bits = kvm_get_vmid_bits();
1432 kvm_info("%d-bit VMID\n", kvm_vmid_bits);
1433
1434 kvm_set_ipa_limit(); 1415 kvm_set_ipa_limit();
1435 1416
1436 return 0; 1417 return 0;
@@ -1571,6 +1552,7 @@ static int init_hyp_mode(void)
1571 kvm_cpu_context_t *cpu_ctxt; 1552 kvm_cpu_context_t *cpu_ctxt;
1572 1553
1573 cpu_ctxt = per_cpu_ptr(&kvm_host_cpu_state, cpu); 1554 cpu_ctxt = per_cpu_ptr(&kvm_host_cpu_state, cpu);
1555 kvm_init_host_cpu_context(cpu_ctxt, cpu);
1574 err = create_hyp_mappings(cpu_ctxt, cpu_ctxt + 1, PAGE_HYP); 1556 err = create_hyp_mappings(cpu_ctxt, cpu_ctxt + 1, PAGE_HYP);
1575 1557
1576 if (err) { 1558 if (err) {
@@ -1581,7 +1563,7 @@ static int init_hyp_mode(void)
1581 1563
1582 err = hyp_map_aux_data(); 1564 err = hyp_map_aux_data();
1583 if (err) 1565 if (err)
1584 kvm_err("Cannot map host auxilary data: %d\n", err); 1566 kvm_err("Cannot map host auxiliary data: %d\n", err);
1585 1567
1586 return 0; 1568 return 0;
1587 1569
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c
index 9652c453480f..264d92da3240 100644
--- a/virt/kvm/arm/hyp/vgic-v3-sr.c
+++ b/virt/kvm/arm/hyp/vgic-v3-sr.c
@@ -226,7 +226,7 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
226 int i; 226 int i;
227 u32 elrsr; 227 u32 elrsr;
228 228
229 elrsr = read_gicreg(ICH_ELSR_EL2); 229 elrsr = read_gicreg(ICH_ELRSR_EL2);
230 230
231 write_gicreg(cpu_if->vgic_hcr & ~ICH_HCR_EN, ICH_HCR_EL2); 231 write_gicreg(cpu_if->vgic_hcr & ~ICH_HCR_EN, ICH_HCR_EL2);
232 232
diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
index e9d28a7ca673..ffd7acdceac7 100644
--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -908,6 +908,7 @@ int create_hyp_exec_mappings(phys_addr_t phys_addr, size_t size,
908 */ 908 */
909int kvm_alloc_stage2_pgd(struct kvm *kvm) 909int kvm_alloc_stage2_pgd(struct kvm *kvm)
910{ 910{
911 phys_addr_t pgd_phys;
911 pgd_t *pgd; 912 pgd_t *pgd;
912 913
913 if (kvm->arch.pgd != NULL) { 914 if (kvm->arch.pgd != NULL) {
@@ -920,7 +921,12 @@ int kvm_alloc_stage2_pgd(struct kvm *kvm)
920 if (!pgd) 921 if (!pgd)
921 return -ENOMEM; 922 return -ENOMEM;
922 923
924 pgd_phys = virt_to_phys(pgd);
925 if (WARN_ON(pgd_phys & ~kvm_vttbr_baddr_mask(kvm)))
926 return -EINVAL;
927
923 kvm->arch.pgd = pgd; 928 kvm->arch.pgd = pgd;
929 kvm->arch.pgd_phys = pgd_phys;
924 return 0; 930 return 0;
925} 931}
926 932
@@ -1008,6 +1014,7 @@ void kvm_free_stage2_pgd(struct kvm *kvm)
1008 unmap_stage2_range(kvm, 0, kvm_phys_size(kvm)); 1014 unmap_stage2_range(kvm, 0, kvm_phys_size(kvm));
1009 pgd = READ_ONCE(kvm->arch.pgd); 1015 pgd = READ_ONCE(kvm->arch.pgd);
1010 kvm->arch.pgd = NULL; 1016 kvm->arch.pgd = NULL;
1017 kvm->arch.pgd_phys = 0;
1011 } 1018 }
1012 spin_unlock(&kvm->mmu_lock); 1019 spin_unlock(&kvm->mmu_lock);
1013 1020
@@ -1396,14 +1403,6 @@ static bool transparent_hugepage_adjust(kvm_pfn_t *pfnp, phys_addr_t *ipap)
1396 return false; 1403 return false;
1397} 1404}
1398 1405
1399static bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
1400{
1401 if (kvm_vcpu_trap_is_iabt(vcpu))
1402 return false;
1403
1404 return kvm_vcpu_dabt_iswrite(vcpu);
1405}
1406
1407/** 1406/**
1408 * stage2_wp_ptes - write protect PMD range 1407 * stage2_wp_ptes - write protect PMD range
1409 * @pmd: pointer to pmd entry 1408 * @pmd: pointer to pmd entry
@@ -1598,14 +1597,13 @@ static void kvm_send_hwpoison_signal(unsigned long address,
1598static bool fault_supports_stage2_pmd_mappings(struct kvm_memory_slot *memslot, 1597static bool fault_supports_stage2_pmd_mappings(struct kvm_memory_slot *memslot,
1599 unsigned long hva) 1598 unsigned long hva)
1600{ 1599{
1601 gpa_t gpa_start, gpa_end; 1600 gpa_t gpa_start;
1602 hva_t uaddr_start, uaddr_end; 1601 hva_t uaddr_start, uaddr_end;
1603 size_t size; 1602 size_t size;
1604 1603
1605 size = memslot->npages * PAGE_SIZE; 1604 size = memslot->npages * PAGE_SIZE;
1606 1605
1607 gpa_start = memslot->base_gfn << PAGE_SHIFT; 1606 gpa_start = memslot->base_gfn << PAGE_SHIFT;
1608 gpa_end = gpa_start + size;
1609 1607
1610 uaddr_start = memslot->userspace_addr; 1608 uaddr_start = memslot->userspace_addr;
1611 uaddr_end = uaddr_start + size; 1609 uaddr_end = uaddr_start + size;
@@ -2353,7 +2351,7 @@ int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot,
2353 return 0; 2351 return 0;
2354} 2352}
2355 2353
2356void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) 2354void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen)
2357{ 2355{
2358} 2356}
2359 2357
diff --git a/virt/kvm/arm/trace.h b/virt/kvm/arm/trace.h
index 3828beab93f2..204d210d01c2 100644
--- a/virt/kvm/arm/trace.h
+++ b/virt/kvm/arm/trace.h
@@ -2,6 +2,7 @@
2#if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ) 2#if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
3#define _TRACE_KVM_H 3#define _TRACE_KVM_H
4 4
5#include <kvm/arm_arch_timer.h>
5#include <linux/tracepoint.h> 6#include <linux/tracepoint.h>
6 7
7#undef TRACE_SYSTEM 8#undef TRACE_SYSTEM
@@ -262,10 +263,114 @@ TRACE_EVENT(kvm_timer_update_irq,
262 __entry->vcpu_id, __entry->irq, __entry->level) 263 __entry->vcpu_id, __entry->irq, __entry->level)
263); 264);
264 265
266TRACE_EVENT(kvm_get_timer_map,
267 TP_PROTO(unsigned long vcpu_id, struct timer_map *map),
268 TP_ARGS(vcpu_id, map),
269
270 TP_STRUCT__entry(
271 __field( unsigned long, vcpu_id )
272 __field( int, direct_vtimer )
273 __field( int, direct_ptimer )
274 __field( int, emul_ptimer )
275 ),
276
277 TP_fast_assign(
278 __entry->vcpu_id = vcpu_id;
279 __entry->direct_vtimer = arch_timer_ctx_index(map->direct_vtimer);
280 __entry->direct_ptimer =
281 (map->direct_ptimer) ? arch_timer_ctx_index(map->direct_ptimer) : -1;
282 __entry->emul_ptimer =
283 (map->emul_ptimer) ? arch_timer_ctx_index(map->emul_ptimer) : -1;
284 ),
285
286 TP_printk("VCPU: %ld, dv: %d, dp: %d, ep: %d",
287 __entry->vcpu_id,
288 __entry->direct_vtimer,
289 __entry->direct_ptimer,
290 __entry->emul_ptimer)
291);
292
293TRACE_EVENT(kvm_timer_save_state,
294 TP_PROTO(struct arch_timer_context *ctx),
295 TP_ARGS(ctx),
296
297 TP_STRUCT__entry(
298 __field( unsigned long, ctl )
299 __field( unsigned long long, cval )
300 __field( int, timer_idx )
301 ),
302
303 TP_fast_assign(
304 __entry->ctl = ctx->cnt_ctl;
305 __entry->cval = ctx->cnt_cval;
306 __entry->timer_idx = arch_timer_ctx_index(ctx);
307 ),
308
309 TP_printk(" CTL: %#08lx CVAL: %#16llx arch_timer_ctx_index: %d",
310 __entry->ctl,
311 __entry->cval,
312 __entry->timer_idx)
313);
314
315TRACE_EVENT(kvm_timer_restore_state,
316 TP_PROTO(struct arch_timer_context *ctx),
317 TP_ARGS(ctx),
318
319 TP_STRUCT__entry(
320 __field( unsigned long, ctl )
321 __field( unsigned long long, cval )
322 __field( int, timer_idx )
323 ),
324
325 TP_fast_assign(
326 __entry->ctl = ctx->cnt_ctl;
327 __entry->cval = ctx->cnt_cval;
328 __entry->timer_idx = arch_timer_ctx_index(ctx);
329 ),
330
331 TP_printk("CTL: %#08lx CVAL: %#16llx arch_timer_ctx_index: %d",
332 __entry->ctl,
333 __entry->cval,
334 __entry->timer_idx)
335);
336
337TRACE_EVENT(kvm_timer_hrtimer_expire,
338 TP_PROTO(struct arch_timer_context *ctx),
339 TP_ARGS(ctx),
340
341 TP_STRUCT__entry(
342 __field( int, timer_idx )
343 ),
344
345 TP_fast_assign(
346 __entry->timer_idx = arch_timer_ctx_index(ctx);
347 ),
348
349 TP_printk("arch_timer_ctx_index: %d", __entry->timer_idx)
350);
351
352TRACE_EVENT(kvm_timer_emulate,
353 TP_PROTO(struct arch_timer_context *ctx, bool should_fire),
354 TP_ARGS(ctx, should_fire),
355
356 TP_STRUCT__entry(
357 __field( int, timer_idx )
358 __field( bool, should_fire )
359 ),
360
361 TP_fast_assign(
362 __entry->timer_idx = arch_timer_ctx_index(ctx);
363 __entry->should_fire = should_fire;
364 ),
365
366 TP_printk("arch_timer_ctx_index: %d (should_fire: %d)",
367 __entry->timer_idx, __entry->should_fire)
368);
369
265#endif /* _TRACE_KVM_H */ 370#endif /* _TRACE_KVM_H */
266 371
267#undef TRACE_INCLUDE_PATH 372#undef TRACE_INCLUDE_PATH
268#define TRACE_INCLUDE_PATH ../../../virt/kvm/arm 373#define TRACE_INCLUDE_PATH ../../virt/kvm/arm
269#undef TRACE_INCLUDE_FILE 374#undef TRACE_INCLUDE_FILE
270#define TRACE_INCLUDE_FILE trace 375#define TRACE_INCLUDE_FILE trace
271 376
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index 4ee0aeb9a905..408a78eb6a97 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -589,7 +589,7 @@ early_param("kvm-arm.vgic_v4_enable", early_gicv4_enable);
589 */ 589 */
590int vgic_v3_probe(const struct gic_kvm_info *info) 590int vgic_v3_probe(const struct gic_kvm_info *info)
591{ 591{
592 u32 ich_vtr_el2 = kvm_call_hyp(__vgic_v3_get_ich_vtr_el2); 592 u32 ich_vtr_el2 = kvm_call_hyp_ret(__vgic_v3_get_ich_vtr_el2);
593 int ret; 593 int ret;
594 594
595 /* 595 /*
@@ -679,7 +679,7 @@ void vgic_v3_put(struct kvm_vcpu *vcpu)
679 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3; 679 struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3;
680 680
681 if (likely(cpu_if->vgic_sre)) 681 if (likely(cpu_if->vgic_sre))
682 cpu_if->vgic_vmcr = kvm_call_hyp(__vgic_v3_read_vmcr); 682 cpu_if->vgic_vmcr = kvm_call_hyp_ret(__vgic_v3_read_vmcr);
683 683
684 kvm_call_hyp(__vgic_v3_save_aprs, vcpu); 684 kvm_call_hyp(__vgic_v3_save_aprs, vcpu);
685 685
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index 6855cce3e528..5294abb3f178 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -144,7 +144,8 @@ int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm,
144 if (zone->pio != 1 && zone->pio != 0) 144 if (zone->pio != 1 && zone->pio != 0)
145 return -EINVAL; 145 return -EINVAL;
146 146
147 dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL); 147 dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev),
148 GFP_KERNEL_ACCOUNT);
148 if (!dev) 149 if (!dev)
149 return -ENOMEM; 150 return -ENOMEM;
150 151
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index b20b751286fc..4325250afd72 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -297,7 +297,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
297 if (!kvm_arch_intc_initialized(kvm)) 297 if (!kvm_arch_intc_initialized(kvm))
298 return -EAGAIN; 298 return -EAGAIN;
299 299
300 irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL); 300 irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL_ACCOUNT);
301 if (!irqfd) 301 if (!irqfd)
302 return -ENOMEM; 302 return -ENOMEM;
303 303
@@ -345,7 +345,8 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
345 } 345 }
346 346
347 if (!irqfd->resampler) { 347 if (!irqfd->resampler) {
348 resampler = kzalloc(sizeof(*resampler), GFP_KERNEL); 348 resampler = kzalloc(sizeof(*resampler),
349 GFP_KERNEL_ACCOUNT);
349 if (!resampler) { 350 if (!resampler) {
350 ret = -ENOMEM; 351 ret = -ENOMEM;
351 mutex_unlock(&kvm->irqfds.resampler_lock); 352 mutex_unlock(&kvm->irqfds.resampler_lock);
@@ -797,7 +798,7 @@ static int kvm_assign_ioeventfd_idx(struct kvm *kvm,
797 if (IS_ERR(eventfd)) 798 if (IS_ERR(eventfd))
798 return PTR_ERR(eventfd); 799 return PTR_ERR(eventfd);
799 800
800 p = kzalloc(sizeof(*p), GFP_KERNEL); 801 p = kzalloc(sizeof(*p), GFP_KERNEL_ACCOUNT);
801 if (!p) { 802 if (!p) {
802 ret = -ENOMEM; 803 ret = -ENOMEM;
803 goto fail; 804 goto fail;
diff --git a/virt/kvm/irqchip.c b/virt/kvm/irqchip.c
index b1286c4e0712..3547b0d8c91e 100644
--- a/virt/kvm/irqchip.c
+++ b/virt/kvm/irqchip.c
@@ -196,7 +196,7 @@ int kvm_set_irq_routing(struct kvm *kvm,
196 nr_rt_entries += 1; 196 nr_rt_entries += 1;
197 197
198 new = kzalloc(sizeof(*new) + (nr_rt_entries * sizeof(struct hlist_head)), 198 new = kzalloc(sizeof(*new) + (nr_rt_entries * sizeof(struct hlist_head)),
199 GFP_KERNEL); 199 GFP_KERNEL_ACCOUNT);
200 200
201 if (!new) 201 if (!new)
202 return -ENOMEM; 202 return -ENOMEM;
@@ -208,7 +208,7 @@ int kvm_set_irq_routing(struct kvm *kvm,
208 208
209 for (i = 0; i < nr; ++i) { 209 for (i = 0; i < nr; ++i) {
210 r = -ENOMEM; 210 r = -ENOMEM;
211 e = kzalloc(sizeof(*e), GFP_KERNEL); 211 e = kzalloc(sizeof(*e), GFP_KERNEL_ACCOUNT);
212 if (!e) 212 if (!e)
213 goto out; 213 goto out;
214 214
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index d237d3350a99..f25aa98a94df 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -81,6 +81,11 @@ unsigned int halt_poll_ns_grow = 2;
81module_param(halt_poll_ns_grow, uint, 0644); 81module_param(halt_poll_ns_grow, uint, 0644);
82EXPORT_SYMBOL_GPL(halt_poll_ns_grow); 82EXPORT_SYMBOL_GPL(halt_poll_ns_grow);
83 83
84/* The start value to grow halt_poll_ns from */
85unsigned int halt_poll_ns_grow_start = 10000; /* 10us */
86module_param(halt_poll_ns_grow_start, uint, 0644);
87EXPORT_SYMBOL_GPL(halt_poll_ns_grow_start);
88
84/* Default resets per-vcpu halt_poll_ns . */ 89/* Default resets per-vcpu halt_poll_ns . */
85unsigned int halt_poll_ns_shrink; 90unsigned int halt_poll_ns_shrink;
86module_param(halt_poll_ns_shrink, uint, 0644); 91module_param(halt_poll_ns_shrink, uint, 0644);
@@ -525,7 +530,7 @@ static struct kvm_memslots *kvm_alloc_memslots(void)
525 int i; 530 int i;
526 struct kvm_memslots *slots; 531 struct kvm_memslots *slots;
527 532
528 slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); 533 slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
529 if (!slots) 534 if (!slots)
530 return NULL; 535 return NULL;
531 536
@@ -601,12 +606,12 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
601 606
602 kvm->debugfs_stat_data = kcalloc(kvm_debugfs_num_entries, 607 kvm->debugfs_stat_data = kcalloc(kvm_debugfs_num_entries,
603 sizeof(*kvm->debugfs_stat_data), 608 sizeof(*kvm->debugfs_stat_data),
604 GFP_KERNEL); 609 GFP_KERNEL_ACCOUNT);
605 if (!kvm->debugfs_stat_data) 610 if (!kvm->debugfs_stat_data)
606 return -ENOMEM; 611 return -ENOMEM;
607 612
608 for (p = debugfs_entries; p->name; p++) { 613 for (p = debugfs_entries; p->name; p++) {
609 stat_data = kzalloc(sizeof(*stat_data), GFP_KERNEL); 614 stat_data = kzalloc(sizeof(*stat_data), GFP_KERNEL_ACCOUNT);
610 if (!stat_data) 615 if (!stat_data)
611 return -ENOMEM; 616 return -ENOMEM;
612 617
@@ -656,12 +661,8 @@ static struct kvm *kvm_create_vm(unsigned long type)
656 struct kvm_memslots *slots = kvm_alloc_memslots(); 661 struct kvm_memslots *slots = kvm_alloc_memslots();
657 if (!slots) 662 if (!slots)
658 goto out_err_no_srcu; 663 goto out_err_no_srcu;
659 /* 664 /* Generations must be different for each address space. */
660 * Generations must be different for each address space. 665 slots->generation = i;
661 * Init kvm generation close to the maximum to easily test the
662 * code of handling generation number wrap-around.
663 */
664 slots->generation = i * 2 - 150;
665 rcu_assign_pointer(kvm->memslots[i], slots); 666 rcu_assign_pointer(kvm->memslots[i], slots);
666 } 667 }
667 668
@@ -671,7 +672,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
671 goto out_err_no_irq_srcu; 672 goto out_err_no_irq_srcu;
672 for (i = 0; i < KVM_NR_BUSES; i++) { 673 for (i = 0; i < KVM_NR_BUSES; i++) {
673 rcu_assign_pointer(kvm->buses[i], 674 rcu_assign_pointer(kvm->buses[i],
674 kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL)); 675 kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));
675 if (!kvm->buses[i]) 676 if (!kvm->buses[i])
676 goto out_err; 677 goto out_err;
677 } 678 }
@@ -789,7 +790,7 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
789{ 790{
790 unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot); 791 unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot);
791 792
792 memslot->dirty_bitmap = kvzalloc(dirty_bytes, GFP_KERNEL); 793 memslot->dirty_bitmap = kvzalloc(dirty_bytes, GFP_KERNEL_ACCOUNT);
793 if (!memslot->dirty_bitmap) 794 if (!memslot->dirty_bitmap)
794 return -ENOMEM; 795 return -ENOMEM;
795 796
@@ -874,31 +875,34 @@ static struct kvm_memslots *install_new_memslots(struct kvm *kvm,
874 int as_id, struct kvm_memslots *slots) 875 int as_id, struct kvm_memslots *slots)
875{ 876{
876 struct kvm_memslots *old_memslots = __kvm_memslots(kvm, as_id); 877 struct kvm_memslots *old_memslots = __kvm_memslots(kvm, as_id);
878 u64 gen = old_memslots->generation;
877 879
878 /* 880 WARN_ON(gen & KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS);
879 * Set the low bit in the generation, which disables SPTE caching 881 slots->generation = gen | KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS;
880 * until the end of synchronize_srcu_expedited.
881 */
882 WARN_ON(old_memslots->generation & 1);
883 slots->generation = old_memslots->generation + 1;
884 882
885 rcu_assign_pointer(kvm->memslots[as_id], slots); 883 rcu_assign_pointer(kvm->memslots[as_id], slots);
886 synchronize_srcu_expedited(&kvm->srcu); 884 synchronize_srcu_expedited(&kvm->srcu);
887 885
888 /* 886 /*
889 * Increment the new memslot generation a second time. This prevents 887 * Increment the new memslot generation a second time, dropping the
890 * vm exits that race with memslot updates from caching a memslot 888 * update in-progress flag and incrementing then generation based on
891 * generation that will (potentially) be valid forever. 889 * the number of address spaces. This provides a unique and easily
892 * 890 * identifiable generation number while the memslots are in flux.
891 */
892 gen = slots->generation & ~KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS;
893
894 /*
893 * Generations must be unique even across address spaces. We do not need 895 * Generations must be unique even across address spaces. We do not need
894 * a global counter for that, instead the generation space is evenly split 896 * a global counter for that, instead the generation space is evenly split
895 * across address spaces. For example, with two address spaces, address 897 * across address spaces. For example, with two address spaces, address
896 * space 0 will use generations 0, 4, 8, ... while * address space 1 will 898 * space 0 will use generations 0, 2, 4, ... while address space 1 will
897 * use generations 2, 6, 10, 14, ... 899 * use generations 1, 3, 5, ...
898 */ 900 */
899 slots->generation += KVM_ADDRESS_SPACE_NUM * 2 - 1; 901 gen += KVM_ADDRESS_SPACE_NUM;
902
903 kvm_arch_memslots_updated(kvm, gen);
900 904
901 kvm_arch_memslots_updated(kvm, slots); 905 slots->generation = gen;
902 906
903 return old_memslots; 907 return old_memslots;
904} 908}
@@ -1018,7 +1022,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
1018 goto out_free; 1022 goto out_free;
1019 } 1023 }
1020 1024
1021 slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); 1025 slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
1022 if (!slots) 1026 if (!slots)
1023 goto out_free; 1027 goto out_free;
1024 memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots)); 1028 memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots));
@@ -1201,11 +1205,9 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
1201 mask = xchg(&dirty_bitmap[i], 0); 1205 mask = xchg(&dirty_bitmap[i], 0);
1202 dirty_bitmap_buffer[i] = mask; 1206 dirty_bitmap_buffer[i] = mask;
1203 1207
1204 if (mask) { 1208 offset = i * BITS_PER_LONG;
1205 offset = i * BITS_PER_LONG; 1209 kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot,
1206 kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, 1210 offset, mask);
1207 offset, mask);
1208 }
1209 } 1211 }
1210 spin_unlock(&kvm->mmu_lock); 1212 spin_unlock(&kvm->mmu_lock);
1211 } 1213 }
@@ -2185,20 +2187,23 @@ void kvm_sigset_deactivate(struct kvm_vcpu *vcpu)
2185 2187
2186static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) 2188static void grow_halt_poll_ns(struct kvm_vcpu *vcpu)
2187{ 2189{
2188 unsigned int old, val, grow; 2190 unsigned int old, val, grow, grow_start;
2189 2191
2190 old = val = vcpu->halt_poll_ns; 2192 old = val = vcpu->halt_poll_ns;
2193 grow_start = READ_ONCE(halt_poll_ns_grow_start);
2191 grow = READ_ONCE(halt_poll_ns_grow); 2194 grow = READ_ONCE(halt_poll_ns_grow);
2192 /* 10us base */ 2195 if (!grow)
2193 if (val == 0 && grow) 2196 goto out;
2194 val = 10000; 2197
2195 else 2198 val *= grow;
2196 val *= grow; 2199 if (val < grow_start)
2200 val = grow_start;
2197 2201
2198 if (val > halt_poll_ns) 2202 if (val > halt_poll_ns)
2199 val = halt_poll_ns; 2203 val = halt_poll_ns;
2200 2204
2201 vcpu->halt_poll_ns = val; 2205 vcpu->halt_poll_ns = val;
2206out:
2202 trace_kvm_halt_poll_ns_grow(vcpu->vcpu_id, val, old); 2207 trace_kvm_halt_poll_ns_grow(vcpu->vcpu_id, val, old);
2203} 2208}
2204 2209
@@ -2683,7 +2688,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
2683 struct kvm_regs *kvm_regs; 2688 struct kvm_regs *kvm_regs;
2684 2689
2685 r = -ENOMEM; 2690 r = -ENOMEM;
2686 kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL); 2691 kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL_ACCOUNT);
2687 if (!kvm_regs) 2692 if (!kvm_regs)
2688 goto out; 2693 goto out;
2689 r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs); 2694 r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
@@ -2711,7 +2716,8 @@ out_free1:
2711 break; 2716 break;
2712 } 2717 }
2713 case KVM_GET_SREGS: { 2718 case KVM_GET_SREGS: {
2714 kvm_sregs = kzalloc(sizeof(struct kvm_sregs), GFP_KERNEL); 2719 kvm_sregs = kzalloc(sizeof(struct kvm_sregs),
2720 GFP_KERNEL_ACCOUNT);
2715 r = -ENOMEM; 2721 r = -ENOMEM;
2716 if (!kvm_sregs) 2722 if (!kvm_sregs)
2717 goto out; 2723 goto out;
@@ -2803,7 +2809,7 @@ out_free1:
2803 break; 2809 break;
2804 } 2810 }
2805 case KVM_GET_FPU: { 2811 case KVM_GET_FPU: {
2806 fpu = kzalloc(sizeof(struct kvm_fpu), GFP_KERNEL); 2812 fpu = kzalloc(sizeof(struct kvm_fpu), GFP_KERNEL_ACCOUNT);
2807 r = -ENOMEM; 2813 r = -ENOMEM;
2808 if (!fpu) 2814 if (!fpu)
2809 goto out; 2815 goto out;
@@ -2980,7 +2986,7 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
2980 if (test) 2986 if (test)
2981 return 0; 2987 return 0;
2982 2988
2983 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2989 dev = kzalloc(sizeof(*dev), GFP_KERNEL_ACCOUNT);
2984 if (!dev) 2990 if (!dev)
2985 return -ENOMEM; 2991 return -ENOMEM;
2986 2992
@@ -3625,6 +3631,7 @@ int kvm_io_bus_write(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
3625 r = __kvm_io_bus_write(vcpu, bus, &range, val); 3631 r = __kvm_io_bus_write(vcpu, bus, &range, val);
3626 return r < 0 ? r : 0; 3632 return r < 0 ? r : 0;
3627} 3633}
3634EXPORT_SYMBOL_GPL(kvm_io_bus_write);
3628 3635
3629/* kvm_io_bus_write_cookie - called under kvm->slots_lock */ 3636/* kvm_io_bus_write_cookie - called under kvm->slots_lock */
3630int kvm_io_bus_write_cookie(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, 3637int kvm_io_bus_write_cookie(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx,
@@ -3675,7 +3682,6 @@ static int __kvm_io_bus_read(struct kvm_vcpu *vcpu, struct kvm_io_bus *bus,
3675 3682
3676 return -EOPNOTSUPP; 3683 return -EOPNOTSUPP;
3677} 3684}
3678EXPORT_SYMBOL_GPL(kvm_io_bus_write);
3679 3685
3680/* kvm_io_bus_read - called under kvm->slots_lock */ 3686/* kvm_io_bus_read - called under kvm->slots_lock */
3681int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr, 3687int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
@@ -3697,7 +3703,6 @@ int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
3697 return r < 0 ? r : 0; 3703 return r < 0 ? r : 0;
3698} 3704}
3699 3705
3700
3701/* Caller must hold slots_lock. */ 3706/* Caller must hold slots_lock. */
3702int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 3707int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
3703 int len, struct kvm_io_device *dev) 3708 int len, struct kvm_io_device *dev)
@@ -3714,8 +3719,8 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
3714 if (bus->dev_count - bus->ioeventfd_count > NR_IOBUS_DEVS - 1) 3719 if (bus->dev_count - bus->ioeventfd_count > NR_IOBUS_DEVS - 1)
3715 return -ENOSPC; 3720 return -ENOSPC;
3716 3721
3717 new_bus = kmalloc(sizeof(*bus) + ((bus->dev_count + 1) * 3722 new_bus = kmalloc(struct_size(bus, range, bus->dev_count + 1),
3718 sizeof(struct kvm_io_range)), GFP_KERNEL); 3723 GFP_KERNEL_ACCOUNT);
3719 if (!new_bus) 3724 if (!new_bus)
3720 return -ENOMEM; 3725 return -ENOMEM;
3721 3726
@@ -3760,8 +3765,8 @@ void kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
3760 if (i == bus->dev_count) 3765 if (i == bus->dev_count)
3761 return; 3766 return;
3762 3767
3763 new_bus = kmalloc(sizeof(*bus) + ((bus->dev_count - 1) * 3768 new_bus = kmalloc(struct_size(bus, range, bus->dev_count - 1),
3764 sizeof(struct kvm_io_range)), GFP_KERNEL); 3769 GFP_KERNEL_ACCOUNT);
3765 if (!new_bus) { 3770 if (!new_bus) {
3766 pr_err("kvm: failed to shrink bus, removing it completely\n"); 3771 pr_err("kvm: failed to shrink bus, removing it completely\n");
3767 goto broken; 3772 goto broken;
@@ -4029,7 +4034,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm)
4029 active = kvm_active_vms; 4034 active = kvm_active_vms;
4030 spin_unlock(&kvm_lock); 4035 spin_unlock(&kvm_lock);
4031 4036
4032 env = kzalloc(sizeof(*env), GFP_KERNEL); 4037 env = kzalloc(sizeof(*env), GFP_KERNEL_ACCOUNT);
4033 if (!env) 4038 if (!env)
4034 return; 4039 return;
4035 4040
@@ -4045,7 +4050,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm)
4045 add_uevent_var(env, "PID=%d", kvm->userspace_pid); 4050 add_uevent_var(env, "PID=%d", kvm->userspace_pid);
4046 4051
4047 if (!IS_ERR_OR_NULL(kvm->debugfs_dentry)) { 4052 if (!IS_ERR_OR_NULL(kvm->debugfs_dentry)) {
4048 char *tmp, *p = kmalloc(PATH_MAX, GFP_KERNEL); 4053 char *tmp, *p = kmalloc(PATH_MAX, GFP_KERNEL_ACCOUNT);
4049 4054
4050 if (p) { 4055 if (p) {
4051 tmp = dentry_path_raw(kvm->debugfs_dentry, p, PATH_MAX); 4056 tmp = dentry_path_raw(kvm->debugfs_dentry, p, PATH_MAX);
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index d99850c462a1..524cbd20379f 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -219,7 +219,7 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
219 } 219 }
220 } 220 }
221 221
222 kvg = kzalloc(sizeof(*kvg), GFP_KERNEL); 222 kvg = kzalloc(sizeof(*kvg), GFP_KERNEL_ACCOUNT);
223 if (!kvg) { 223 if (!kvg) {
224 mutex_unlock(&kv->lock); 224 mutex_unlock(&kv->lock);
225 kvm_vfio_group_put_external_user(vfio_group); 225 kvm_vfio_group_put_external_user(vfio_group);
@@ -405,7 +405,7 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 type)
405 if (tmp->ops == &kvm_vfio_ops) 405 if (tmp->ops == &kvm_vfio_ops)
406 return -EBUSY; 406 return -EBUSY;
407 407
408 kv = kzalloc(sizeof(*kv), GFP_KERNEL); 408 kv = kzalloc(sizeof(*kv), GFP_KERNEL_ACCOUNT);
409 if (!kv) 409 if (!kv)
410 return -ENOMEM; 410 return -ENOMEM;
411 411