aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.mailmap1
-rw-r--r--Documentation/ABI/stable/sysfs-bus-xen-backend9
-rw-r--r--Documentation/admin-guide/kernel-parameters.txt6
-rw-r--r--Documentation/arm64/sve.txt4
-rw-r--r--Documentation/device-mapper/dm-raid.txt4
-rw-r--r--Documentation/devicetree/bindings/arm/cpu-capacity.txt2
-rw-r--r--Documentation/devicetree/bindings/arm/idle-states.txt4
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-imx-lpi2c.txt3
-rw-r--r--Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt1
-rw-r--r--Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt14
-rw-r--r--Documentation/devicetree/bindings/net/cpsw.txt6
-rw-r--r--Documentation/devicetree/bindings/net/sh_eth.txt1
-rw-r--r--Documentation/devicetree/bindings/reset/amlogic,meson-axg-audio-arb.txt21
-rw-r--r--Documentation/devicetree/bindings/watchdog/renesas-wdt.txt5
-rw-r--r--Documentation/early-userspace/README6
-rw-r--r--Documentation/filesystems/ramfs-rootfs-initramfs.txt2
-rw-r--r--Documentation/hwmon/ina2xx2
-rw-r--r--Documentation/i2c/DMA-considerations10
-rw-r--r--Documentation/kbuild/kconfig-language.txt3
-rw-r--r--Documentation/kbuild/makefiles.txt2
-rw-r--r--Documentation/process/changes.rst2
-rw-r--r--Documentation/scsi/scsi-parameters.txt5
-rw-r--r--MAINTAINERS42
-rw-r--r--Makefile29
-rw-r--r--arch/arc/Kconfig10
-rw-r--r--arch/arc/Makefile12
-rw-r--r--arch/arc/boot/dts/axc003.dtsi26
-rw-r--r--arch/arc/boot/dts/axc003_idu.dtsi26
-rw-r--r--arch/arc/boot/dts/axs10x_mb.dtsi7
-rw-r--r--arch/arc/boot/dts/hsdk.dts11
-rw-r--r--arch/arc/configs/axs101_defconfig3
-rw-r--r--arch/arc/configs/axs103_defconfig3
-rw-r--r--arch/arc/configs/axs103_smp_defconfig3
-rw-r--r--arch/arc/configs/haps_hs_defconfig2
-rw-r--r--arch/arc/configs/haps_hs_smp_defconfig2
-rw-r--r--arch/arc/configs/hsdk_defconfig1
-rw-r--r--arch/arc/configs/nps_defconfig1
-rw-r--r--arch/arc/configs/nsim_700_defconfig2
-rw-r--r--arch/arc/configs/nsim_hs_defconfig2
-rw-r--r--arch/arc/configs/nsim_hs_smp_defconfig2
-rw-r--r--arch/arc/configs/nsimosci_defconfig2
-rw-r--r--arch/arc/configs/nsimosci_hs_defconfig2
-rw-r--r--arch/arc/configs/nsimosci_hs_smp_defconfig2
-rw-r--r--arch/arc/configs/tb10x_defconfig1
-rw-r--r--arch/arc/configs/vdk_hs38_defconfig2
-rw-r--r--arch/arc/configs/vdk_hs38_smp_defconfig1
-rw-r--r--arch/arc/include/asm/atomic.h2
-rw-r--r--arch/arc/include/asm/dma-mapping.h13
-rw-r--r--arch/arc/kernel/troubleshoot.c13
-rw-r--r--arch/arc/mm/cache.c36
-rw-r--r--arch/arc/mm/dma.c82
-rw-r--r--arch/arm/Makefile4
-rw-r--r--[-rwxr-xr-x]arch/arm/boot/dts/am335x-osd3358-sm-red.dts0
-rw-r--r--arch/arm/boot/dts/am4372.dtsi1
-rw-r--r--arch/arm/boot/dts/imx23-evk.dts90
-rw-r--r--arch/arm/boot/dts/imx28-evk.dts183
-rw-r--r--arch/arm/boot/dts/imx7d.dtsi12
-rw-r--r--arch/arm/boot/dts/omap4-droid4-xt894.dts20
-rw-r--r--arch/arm/configs/imx_v6_v7_defconfig1
-rw-r--r--arch/arm/configs/mxs_defconfig1
-rw-r--r--arch/arm/configs/versatile_defconfig14
-rw-r--r--arch/arm/include/asm/kvm_host.h1
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c39
-rw-r--r--arch/arm/mach-rockchip/Kconfig1
-rw-r--r--arch/arm64/Kconfig1
-rw-r--r--arch/arm64/Kconfig.platforms1
-rw-r--r--arch/arm64/Makefile4
-rw-r--r--arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts2
-rw-r--r--arch/arm64/boot/dts/arm/juno-r1.dts2
-rw-r--r--arch/arm64/boot/dts/arm/juno-r2.dts2
-rw-r--r--arch/arm64/boot/dts/arm/juno.dts2
-rw-r--r--arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi2
-rw-r--r--arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi2
-rw-r--r--arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi2
-rw-r--r--arch/arm64/boot/dts/mediatek/mt2712e.dtsi2
-rw-r--r--arch/arm64/boot/dts/sprd/sc9860.dtsi2
-rw-r--r--arch/arm64/boot/dts/xilinx/zynqmp.dtsi2
-rw-r--r--arch/arm64/configs/defconfig3
-rw-r--r--arch/arm64/crypto/ghash-ce-glue.c29
-rw-r--r--arch/arm64/crypto/sm4-ce-glue.c2
-rw-r--r--arch/arm64/include/asm/kvm_host.h4
-rw-r--r--arch/arm64/kvm/hyp/switch.c9
-rw-r--r--arch/arm64/mm/mmu.c10
-rw-r--r--arch/c6x/Makefile3
-rw-r--r--arch/h8300/Makefile2
-rw-r--r--arch/hexagon/Makefile4
-rw-r--r--arch/hexagon/include/asm/bitops.h4
-rw-r--r--arch/hexagon/kernel/dma.c2
-rw-r--r--arch/m68k/Makefile2
-rw-r--r--arch/m68k/mac/misc.c10
-rw-r--r--arch/m68k/mm/mcfmmu.c2
-rw-r--r--arch/microblaze/Makefile4
-rw-r--r--arch/mips/Makefile2
-rw-r--r--arch/mips/boot/compressed/Makefile2
-rw-r--r--arch/mips/include/asm/kvm_host.h1
-rw-r--r--arch/mips/include/asm/mach-lantiq/xway/xway_dma.h1
-rw-r--r--arch/mips/kernel/vdso.c20
-rw-r--r--arch/mips/kvm/mmu.c10
-rw-r--r--arch/mips/lantiq/xway/dma.c4
-rw-r--r--arch/mips/lasat/image/Makefile2
-rw-r--r--arch/nds32/Kconfig4
-rw-r--r--arch/nds32/Makefile8
-rw-r--r--arch/nds32/include/asm/elf.h4
-rw-r--r--arch/nds32/include/asm/ftrace.h46
-rw-r--r--arch/nds32/include/asm/nds32.h1
-rw-r--r--arch/nds32/include/asm/uaccess.h229
-rw-r--r--arch/nds32/kernel/Makefile6
-rw-r--r--arch/nds32/kernel/atl2c.c3
-rw-r--r--arch/nds32/kernel/ex-entry.S2
-rw-r--r--arch/nds32/kernel/ex-exit.S4
-rw-r--r--arch/nds32/kernel/ftrace.c309
-rw-r--r--arch/nds32/kernel/module.c4
-rw-r--r--arch/nds32/kernel/stacktrace.c6
-rw-r--r--arch/nds32/kernel/traps.c42
-rw-r--r--arch/nds32/kernel/vmlinux.lds.S12
-rw-r--r--arch/nios2/Kconfig.debug9
-rw-r--r--arch/powerpc/Kconfig1
-rw-r--r--arch/powerpc/Makefile6
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_hv.c2
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_radix.c6
-rw-r--r--arch/powerpc/mm/mmu_context_book3s64.c44
-rw-r--r--arch/powerpc/platforms/powernv/vas-window.c26
-rw-r--r--arch/riscv/Makefile4
-rw-r--r--arch/riscv/include/asm/tlb.h4
-rw-r--r--arch/riscv/kernel/setup.c7
-rw-r--r--arch/riscv/kernel/sys_riscv.c15
-rw-r--r--arch/s390/Makefile2
-rw-r--r--arch/s390/crypto/paes_s390.c2
-rw-r--r--arch/s390/include/asm/mmu.h8
-rw-r--r--arch/s390/kvm/kvm-s390.c2
-rw-r--r--arch/s390/kvm/priv.c30
-rw-r--r--arch/s390/kvm/vsie.c3
-rw-r--r--arch/sh/Makefile4
-rw-r--r--arch/sparc/Makefile4
-rw-r--r--arch/sparc/kernel/of_device_32.c4
-rw-r--r--arch/sparc/kernel/of_device_64.c3
-rw-r--r--arch/um/Makefile2
-rw-r--r--arch/x86/Kconfig2
-rw-r--r--arch/x86/Makefile27
-rw-r--r--arch/x86/Makefile.um4
-rw-r--r--arch/x86/boot/compressed/Makefile6
-rw-r--r--arch/x86/crypto/aesni-intel_asm.S66
-rw-r--r--arch/x86/entry/vdso/Makefile6
-rw-r--r--arch/x86/events/core.c2
-rw-r--r--arch/x86/include/asm/atomic.h12
-rw-r--r--arch/x86/include/asm/atomic64_32.h8
-rw-r--r--arch/x86/include/asm/atomic64_64.h12
-rw-r--r--arch/x86/include/asm/irqflags.h3
-rw-r--r--arch/x86/include/asm/kdebug.h12
-rw-r--r--arch/x86/include/asm/kvm_host.h22
-rw-r--r--arch/x86/include/asm/mce.h1
-rw-r--r--arch/x86/include/asm/pgtable-3level.h7
-rw-r--r--arch/x86/include/asm/pgtable.h2
-rw-r--r--arch/x86/include/asm/pgtable_64.h20
-rw-r--r--arch/x86/include/asm/processor.h6
-rw-r--r--arch/x86/include/asm/set_memory.h42
-rw-r--r--arch/x86/include/asm/signal.h7
-rw-r--r--arch/x86/include/asm/stacktrace.h2
-rw-r--r--arch/x86/include/asm/tlbflush.h40
-rw-r--r--arch/x86/include/asm/vgtod.h2
-rw-r--r--arch/x86/kernel/alternative.c9
-rw-r--r--arch/x86/kernel/apic/vector.c2
-rw-r--r--arch/x86/kernel/cpu/bugs.c50
-rw-r--r--arch/x86/kernel/cpu/common.c1
-rw-r--r--arch/x86/kernel/cpu/intel.c3
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce-internal.h15
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c38
-rw-r--r--arch/x86/kernel/cpu/microcode/amd.c24
-rw-r--r--arch/x86/kernel/cpu/microcode/intel.c17
-rw-r--r--arch/x86/kernel/dumpstack.c31
-rw-r--r--arch/x86/kernel/process_32.c4
-rw-r--r--arch/x86/kernel/process_64.c13
-rw-r--r--arch/x86/kernel/tsc.c2
-rw-r--r--arch/x86/kvm/lapic.c27
-rw-r--r--arch/x86/kvm/mmu.c26
-rw-r--r--arch/x86/kvm/svm.c19
-rw-r--r--arch/x86/kvm/vmx.c46
-rw-r--r--arch/x86/kvm/x86.c28
-rw-r--r--arch/x86/kvm/x86.h2
-rw-r--r--arch/x86/lib/usercopy.c5
-rw-r--r--arch/x86/mm/cpu_entry_area.c33
-rw-r--r--arch/x86/mm/fault.c2
-rw-r--r--arch/x86/mm/init.c4
-rw-r--r--arch/x86/mm/mmap.c2
-rw-r--r--arch/x86/mm/pageattr.c25
-rw-r--r--arch/x86/mm/pat.c16
-rw-r--r--arch/x86/mm/pgtable.c8
-rw-r--r--arch/x86/mm/pti.c2
-rw-r--r--arch/x86/mm/tlb.c7
-rw-r--r--arch/x86/platform/efi/efi_32.c8
-rw-r--r--arch/x86/xen/mmu_pv.c9
-rw-r--r--arch/xtensa/Makefile2
-rw-r--r--arch/xtensa/boot/boot-elf/Makefile2
-rw-r--r--certs/system_certificates.S16
-rw-r--r--drivers/acpi/acpi_lpss.c2
-rw-r--r--drivers/acpi/bus.c13
-rw-r--r--drivers/acpi/nfit/core.c24
-rw-r--r--drivers/acpi/nfit/nfit.h1
-rw-r--r--drivers/ata/libata-core.c2
-rw-r--r--drivers/base/memory.c20
-rw-r--r--drivers/base/power/clock_ops.c2
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c29
-rw-r--r--drivers/block/rbd.c235
-rw-r--r--drivers/block/rsxx/core.c21
-rw-r--r--drivers/bluetooth/Kconfig1
-rw-r--r--drivers/bluetooth/btmtkuart.c8
-rw-r--r--drivers/bus/ti-sysc.c37
-rw-r--r--drivers/char/Kconfig4
-rw-r--r--drivers/char/ipmi/ipmi_bt_sm.c92
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c53
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c17
-rw-r--r--drivers/char/ipmi/ipmi_ssif.c32
-rw-r--r--drivers/char/ipmi/kcs_bmc.c7
-rw-r--r--drivers/char/random.c11
-rw-r--r--drivers/clk/clk-npcm7xx.c4
-rw-r--r--drivers/clk/x86/clk-st.c2
-rw-r--r--drivers/cpuidle/governors/menu.c13
-rw-r--r--drivers/crypto/caam/caamalg_qi.c6
-rw-r--r--drivers/crypto/caam/caampkc.c20
-rw-r--r--drivers/crypto/caam/jr.c3
-rw-r--r--drivers/crypto/cavium/nitrox/nitrox_dev.h3
-rw-r--r--drivers/crypto/cavium/nitrox/nitrox_lib.c1
-rw-r--r--drivers/crypto/cavium/nitrox/nitrox_reqmgr.c57
-rw-r--r--drivers/crypto/chelsio/chtls/chtls.h5
-rw-r--r--drivers/crypto/chelsio/chtls/chtls_main.c7
-rw-r--r--drivers/crypto/vmx/aes_cbc.c30
-rw-r--r--drivers/crypto/vmx/aes_xts.c21
-rw-r--r--drivers/dax/device.c76
-rw-r--r--drivers/dax/pmem.c12
-rw-r--r--drivers/dax/super.c3
-rw-r--r--drivers/dma/dmaengine.c23
-rw-r--r--drivers/firmware/arm_scmi/perf.c8
-rw-r--r--drivers/gpio/gpio-adp5588.c24
-rw-r--r--drivers/gpio/gpio-dwapb.c1
-rw-r--r--drivers/gpio/gpiolib-acpi.c86
-rw-r--r--drivers/gpio/gpiolib-of.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c70
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_device.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c35
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c11
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c9
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c16
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c16
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c16
-rw-r--r--drivers/gpu/drm/amd/amdgpu/kv_dpm.c49
-rw-r--r--drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c7
-rw-r--r--drivers/gpu/drm/amd/amdgpu/si_dpm.c3
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c12
-rw-r--r--drivers/gpu/drm/amd/display/dc/core/dc_link.c6
-rw-r--r--drivers/gpu/drm/i915/gvt/dmabuf.c33
-rw-r--r--drivers/gpu/drm/i915/gvt/fb_decoder.c5
-rw-r--r--drivers/gpu/drm/i915/gvt/fb_decoder.h2
-rw-r--r--drivers/gpu/drm/i915/gvt/handlers.c33
-rw-r--r--drivers/gpu/drm/i915/gvt/kvmgt.c10
-rw-r--r--drivers/gpu/drm/i915/gvt/mmio_context.c2
-rw-r--r--drivers/gpu/drm/i915/gvt/opregion.c20
-rw-r--r--drivers/gpu/drm/i915/gvt/sched_policy.c37
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h4
-rw-r--r--drivers/gpu/drm/i915/i915_vma.c4
-rw-r--r--drivers/gpu/drm/i915/intel_audio.c3
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c17
-rw-r--r--drivers/gpu/drm/i915/intel_display.c15
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c33
-rw-r--r--drivers/gpu/drm/i915/intel_dp_mst.c4
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c8
-rw-r--r--drivers/gpu/drm/i915/intel_lspcon.c2
-rw-r--r--drivers/gpu/drm/i915/intel_overlay.c228
-rw-r--r--drivers/gpu/drm/mediatek/mtk_disp_ovl.c11
-rw-r--r--drivers/gpu/drm/mediatek/mtk_disp_rdma.c92
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_crtc.c47
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_crtc.h3
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_ddp.c18
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h9
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_drv.c27
-rw-r--r--drivers/gpu/drm/nouveau/dispnv50/disp.c67
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.c110
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.c44
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.h2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drm.c21
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fbcon.c57
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fbcon.h5
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_vga.c2
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/engine/disp/base.c14
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/engine/disp/dp.c54
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h1
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c6
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c18
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.h5
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm200.c24
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c41
-rw-r--r--drivers/hid/hid-apple.c9
-rw-r--r--drivers/hid/hid-core.c5
-rw-r--r--drivers/hid/hid-ids.h6
-rw-r--r--drivers/hid/hid-input.c5
-rw-r--r--drivers/hid/hid-multitouch.c19
-rw-r--r--drivers/hid/hid-saitek.c2
-rw-r--r--drivers/hid/hid-sensor-hub.c23
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c11
-rw-r--r--drivers/hid/intel-ish-hid/ipc/hw-ish.h1
-rw-r--r--drivers/hid/intel-ish-hid/ipc/pci-ish.c1
-rw-r--r--drivers/hwmon/adt7475.c25
-rw-r--r--drivers/hwmon/ina2xx.c13
-rw-r--r--drivers/hwmon/nct6775.c2
-rw-r--r--drivers/hwmon/raspberrypi-hwmon.c1
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c55
-rw-r--r--drivers/i2c/busses/i2c-designware-master.c1
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c7
-rw-r--r--drivers/i2c/busses/i2c-i801.c16
-rw-r--r--drivers/i2c/busses/i2c-imx-lpi2c.c1
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c15
-rw-r--r--drivers/i2c/busses/i2c-uniphier-f.c7
-rw-r--r--drivers/i2c/busses/i2c-uniphier.c7
-rw-r--r--drivers/i2c/busses/i2c-xiic.c4
-rw-r--r--drivers/i2c/i2c-core-base.c11
-rw-r--r--drivers/infiniband/core/cma.c12
-rw-r--r--drivers/infiniband/core/rdma_core.c2
-rw-r--r--drivers/infiniband/core/ucma.c6
-rw-r--r--drivers/infiniband/core/uverbs_main.c5
-rw-r--r--drivers/infiniband/hw/bnxt_re/ib_verbs.c2
-rw-r--r--drivers/infiniband/hw/bnxt_re/qplib_fp.c2
-rw-r--r--drivers/infiniband/hw/cxgb4/qp.c6
-rw-r--r--drivers/infiniband/hw/hfi1/pcie.c11
-rw-r--r--drivers/infiniband/hw/mlx4/main.c8
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c2
-rw-r--r--drivers/iommu/rockchip-iommu.c45
-rw-r--r--drivers/irqchip/irq-bcm7038-l1.c4
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c4
-rw-r--r--drivers/irqchip/irq-gic-v3.c8
-rw-r--r--drivers/irqchip/irq-s3c24xx.c2
-rw-r--r--drivers/irqchip/irq-stm32-exti.c25
-rw-r--r--drivers/irqchip/irq-tango.c3
-rw-r--r--drivers/md/dm-crypt.c10
-rw-r--r--drivers/md/dm-integrity.c4
-rw-r--r--drivers/md/dm-raid.c154
-rw-r--r--drivers/md/dm-thin-metadata.c36
-rw-r--r--drivers/md/dm-thin.c73
-rw-r--r--drivers/md/dm-verity-target.c24
-rw-r--r--drivers/md/dm-writecache.c3
-rw-r--r--drivers/md/md-cluster.c10
-rw-r--r--drivers/md/raid10.c5
-rw-r--r--drivers/md/raid5-log.h5
-rw-r--r--drivers/md/raid5.c6
-rw-r--r--drivers/media/media-device.c16
-rw-r--r--drivers/memory/ti-aemif.c2
-rw-r--r--drivers/misc/cb710/core.c23
-rw-r--r--drivers/mmc/core/queue.c12
-rw-r--r--drivers/mmc/core/queue.h1
-rw-r--r--drivers/mmc/host/android-goldfish.c4
-rw-r--r--drivers/mmc/host/atmel-mci.c12
-rw-r--r--drivers/mmc/host/meson-mx-sdio.c8
-rw-r--r--drivers/mmc/host/omap_hsmmc.c1
-rw-r--r--drivers/mmc/host/renesas_sdhi_internal_dmac.c10
-rw-r--r--drivers/mtd/nand/raw/denali.c5
-rw-r--r--drivers/mtd/nand/raw/docg4.c4
-rw-r--r--drivers/net/ethernet/amazon/ena/ena_com.c24
-rw-r--r--drivers/net/ethernet/amazon/ena/ena_eth_com.c6
-rw-r--r--drivers/net/ethernet/amazon/ena/ena_eth_com.h8
-rw-r--r--drivers/net/ethernet/amazon/ena/ena_netdev.c82
-rw-r--r--drivers/net/ethernet/amazon/ena/ena_netdev.h11
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.c22
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.h3
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c7
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c6
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c20
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h1
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.h3
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmmii.c10
-rw-r--r--drivers/net/ethernet/cadence/macb_main.c38
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c10
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c5
-rw-r--r--drivers/net/ethernet/emulex/benet/be_cmds.c2
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hnae.h8
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c67
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c36
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c44
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h8
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c29
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h3
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c23
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h1
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c23
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h1
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h1
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_enet.c129
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_ethtool.c2
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3_enet.c3
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3_enet.h6
-rw-r--r--drivers/net/ethernet/ibm/emac/core.c6
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.c12
-rw-r--r--drivers/net/ethernet/intel/e1000/e1000_ethtool.c7
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_ethtool.c2
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_main.c15
-rw-r--r--drivers/net/ethernet/intel/ice/ice.h15
-rw-r--r--drivers/net/ethernet/intel/ice/ice_adminq_cmd.h25
-rw-r--r--drivers/net/ethernet/intel/ice/ice_common.c30
-rw-r--r--drivers/net/ethernet/intel/ice/ice_controlq.c29
-rw-r--r--drivers/net/ethernet/intel/ice/ice_ethtool.c52
-rw-r--r--drivers/net/ethernet/intel/ice/ice_hw_autogen.h8
-rw-r--r--drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h1
-rw-r--r--drivers/net/ethernet/intel/ice/ice_main.c115
-rw-r--r--drivers/net/ethernet/intel/ice/ice_nvm.c5
-rw-r--r--drivers/net/ethernet/intel/ice/ice_sched.c3
-rw-r--r--drivers/net/ethernet/intel/ice/ice_switch.c4
-rw-r--r--drivers/net/ethernet/intel/ice/ice_switch.h6
-rw-r--r--drivers/net/ethernet/intel/ice/ice_txrx.h2
-rw-r--r--drivers/net/ethernet/intel/ice/ice_type.h16
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ethtool.c2
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c7
-rw-r--r--drivers/net/ethernet/intel/ixgb/ixgb_main.c5
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c4
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c36
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c31
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_type.h1
-rw-r--r--drivers/net/ethernet/lantiq_etop.c1
-rw-r--r--drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/dev.c22
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tc.c19
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fs_core.c76
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/health.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c12
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/wq.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/wq.h2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.h2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c16
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c6
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c20
-rw-r--r--drivers/net/ethernet/netronome/nfp/flower/action.c12
-rw-r--r--drivers/net/ethernet/netronome/nfp/flower/main.h1
-rw-r--r--drivers/net/ethernet/netronome/nfp/flower/match.c2
-rw-r--r--drivers/net/ethernet/netronome/nfp/flower/offload.c11
-rw-r--r--drivers/net/ethernet/netronome/nfp/nfp_net_common.c48
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_init_ops.c2
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_mcp.c187
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_mcp.h27
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_reg_addr.h2
-rw-r--r--drivers/net/ethernet/qlogic/qede/qede_filter.c6
-rw-r--r--drivers/net/ethernet/qlogic/qlge/qlge_main.c23
-rw-r--r--drivers/net/ethernet/qualcomm/qca_7k.c76
-rw-r--r--drivers/net/ethernet/qualcomm/qca_spi.c110
-rw-r--r--drivers/net/ethernet/qualcomm/qca_spi.h5
-rw-r--r--drivers/net/ethernet/realtek/r8169.c16
-rw-r--r--drivers/net/ethernet/renesas/Kconfig1
-rw-r--r--drivers/net/ethernet/renesas/Makefile1
-rw-r--r--drivers/net/ethernet/renesas/ravb.h5
-rw-r--r--drivers/net/ethernet/renesas/ravb_main.c5
-rw-r--r--drivers/net/ethernet/renesas/ravb_ptp.c6
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c49
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h13
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/Kconfig12
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac.h1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c5
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c5
-rw-r--r--drivers/net/ethernet/ti/cpsw-phy-sel.c9
-rw-r--r--drivers/net/hyperv/netvsc_drv.c16
-rw-r--r--drivers/net/phy/sfp.c20
-rw-r--r--drivers/net/usb/qmi_wwan.c30
-rw-r--r--drivers/net/usb/r8152.c4
-rw-r--r--drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c50
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c12
-rw-r--r--drivers/net/xen-netfront.c24
-rw-r--r--drivers/nvdimm/bus.c4
-rw-r--r--drivers/nvdimm/dimm.c24
-rw-r--r--drivers/nvdimm/dimm_devs.c31
-rw-r--r--drivers/nvdimm/namespace_devs.c29
-rw-r--r--drivers/nvdimm/nd-core.h8
-rw-r--r--drivers/nvdimm/nd.h1
-rw-r--r--drivers/nvdimm/pmem.c33
-rw-r--r--drivers/nvdimm/pmem.h13
-rw-r--r--drivers/nvdimm/region_devs.c40
-rw-r--r--drivers/of/base.c47
-rw-r--r--drivers/of/platform.c4
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c18
-rw-r--r--drivers/pci/pci.c3
-rw-r--r--drivers/pci/probe.c5
-rw-r--r--drivers/pci/quirks.c6
-rw-r--r--drivers/pci/switch/switchtec.c4
-rw-r--r--drivers/pinctrl/cirrus/pinctrl-madera-core.c2
-rw-r--r--drivers/pinctrl/pinctrl-ingenic.c4
-rw-r--r--drivers/pinctrl/qcom/pinctrl-msm.c24
-rw-r--r--drivers/reset/Kconfig7
-rw-r--r--drivers/reset/Makefile1
-rw-r--r--drivers/reset/reset-imx7.c2
-rw-r--r--drivers/reset/reset-meson-audio-arb.c168
-rw-r--r--drivers/s390/block/dcssblk.c8
-rw-r--r--drivers/s390/crypto/ap_bus.c86
-rw-r--r--drivers/s390/net/qeth_core_main.c11
-rw-r--r--drivers/s390/net/qeth_l2_main.c2
-rw-r--r--drivers/s390/net/qeth_l3_main.c2
-rw-r--r--drivers/scsi/Kconfig10
-rw-r--r--drivers/scsi/aacraid/aacraid.h2
-rw-r--r--drivers/scsi/csiostor/csio_hw.c71
-rw-r--r--drivers/scsi/csiostor/csio_hw.h1
-rw-r--r--drivers/scsi/csiostor/csio_mb.c6
-rw-r--r--drivers/scsi/hosts.c24
-rw-r--r--drivers/scsi/hpsa.c2
-rw-r--r--drivers/scsi/lpfc/lpfc.h2
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c8
-rw-r--r--drivers/scsi/osd/osd_uld.c22
-rw-r--r--drivers/scsi/qedi/qedi.h7
-rw-r--r--drivers/scsi/qedi/qedi_main.c28
-rw-r--r--drivers/scsi/scsi_lib.c21
-rw-r--r--drivers/scsi/sd.c21
-rw-r--r--drivers/target/iscsi/cxgbit/cxgbit_ddp.c8
-rw-r--r--drivers/target/iscsi/iscsi_target.c19
-rw-r--r--drivers/target/iscsi/iscsi_target.h4
-rw-r--r--drivers/target/iscsi/iscsi_target_login.c190
-rw-r--r--drivers/target/iscsi/iscsi_target_login.h2
-rw-r--r--drivers/thermal/of-thermal.c7
-rw-r--r--drivers/thermal/qoriq_thermal.c27
-rw-r--r--drivers/thermal/rcar_gen3_thermal.c11
-rw-r--r--drivers/thermal/rcar_thermal.c16
-rw-r--r--drivers/vhost/vhost.c2
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c9
-rw-r--r--fs/afs/proc.c15
-rw-r--r--fs/btrfs/ctree.h12
-rw-r--r--fs/btrfs/disk-io.c1
-rw-r--r--fs/btrfs/extent-tree.c17
-rw-r--r--fs/btrfs/inode.c117
-rw-r--r--fs/btrfs/ioctl.c35
-rw-r--r--fs/btrfs/qgroup.c5
-rw-r--r--fs/btrfs/tree-log.c48
-rw-r--r--fs/btrfs/tree-log.h10
-rw-r--r--fs/btrfs/volumes.c7
-rw-r--r--fs/buffer.c1
-rw-r--r--fs/ceph/super.c16
-rw-r--r--fs/cifs/cifs_unicode.c3
-rw-r--r--fs/cifs/connect.c2
-rw-r--r--fs/cifs/inode.c2
-rw-r--r--fs/cifs/smb2misc.c14
-rw-r--r--fs/cifs/smb2ops.c35
-rw-r--r--fs/cifs/smb2pdu.c3
-rw-r--r--fs/dax.c138
-rw-r--r--fs/devpts/inode.c47
-rw-r--r--fs/isofs/inode.c7
-rw-r--r--fs/namespace.c50
-rw-r--r--fs/nilfs2/alloc.c11
-rw-r--r--fs/nilfs2/alloc.h11
-rw-r--r--fs/nilfs2/bmap.c11
-rw-r--r--fs/nilfs2/bmap.h11
-rw-r--r--fs/nilfs2/btnode.c11
-rw-r--r--fs/nilfs2/btnode.h11
-rw-r--r--fs/nilfs2/btree.c11
-rw-r--r--fs/nilfs2/btree.h11
-rw-r--r--fs/nilfs2/cpfile.c11
-rw-r--r--fs/nilfs2/cpfile.h11
-rw-r--r--fs/nilfs2/dat.c11
-rw-r--r--fs/nilfs2/dat.h11
-rw-r--r--fs/nilfs2/dir.c11
-rw-r--r--fs/nilfs2/direct.c11
-rw-r--r--fs/nilfs2/direct.h11
-rw-r--r--fs/nilfs2/file.c11
-rw-r--r--fs/nilfs2/gcinode.c11
-rw-r--r--fs/nilfs2/ifile.c11
-rw-r--r--fs/nilfs2/ifile.h11
-rw-r--r--fs/nilfs2/inode.c11
-rw-r--r--fs/nilfs2/ioctl.c11
-rw-r--r--fs/nilfs2/mdt.c11
-rw-r--r--fs/nilfs2/mdt.h11
-rw-r--r--fs/nilfs2/namei.c11
-rw-r--r--fs/nilfs2/nilfs.h11
-rw-r--r--fs/nilfs2/page.c11
-rw-r--r--fs/nilfs2/page.h11
-rw-r--r--fs/nilfs2/recovery.c11
-rw-r--r--fs/nilfs2/segbuf.c11
-rw-r--r--fs/nilfs2/segbuf.h11
-rw-r--r--fs/nilfs2/segment.c11
-rw-r--r--fs/nilfs2/segment.h11
-rw-r--r--fs/nilfs2/sufile.c11
-rw-r--r--fs/nilfs2/sufile.h11
-rw-r--r--fs/nilfs2/super.c11
-rw-r--r--fs/nilfs2/sysfs.c11
-rw-r--r--fs/nilfs2/sysfs.h11
-rw-r--r--fs/nilfs2/the_nilfs.c11
-rw-r--r--fs/nilfs2/the_nilfs.h11
-rw-r--r--fs/notify/fsnotify.c13
-rw-r--r--fs/notify/mark.c6
-rw-r--r--fs/proc/kcore.c7
-rw-r--r--fs/pstore/ram_core.c17
-rw-r--r--fs/quota/quota.c14
-rw-r--r--fs/super.c67
-rw-r--r--fs/udf/super.c93
-rw-r--r--include/asm-generic/vmlinux.lds.h2
-rw-r--r--include/dt-bindings/reset/amlogic,meson-axg-audio-arb.h17
-rw-r--r--include/linux/arm-smccc.h38
-rw-r--r--include/linux/dax.h13
-rw-r--r--include/linux/export.h7
-rw-r--r--include/linux/hid.h1
-rw-r--r--include/linux/huge_mm.h5
-rw-r--r--include/linux/i2c.h2
-rw-r--r--include/linux/idr.h68
-rw-r--r--include/linux/kcore.h13
-rw-r--r--include/linux/mlx5/driver.h8
-rw-r--r--include/linux/mm.h1
-rw-r--r--include/linux/mm_types.h2
-rw-r--r--include/linux/mm_types_task.h2
-rw-r--r--include/linux/of.h33
-rw-r--r--include/linux/pci.h3
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/linux/platform_data/ina2xx.h2
-rw-r--r--include/linux/quota.h8
-rw-r--r--include/linux/set_memory.h14
-rw-r--r--include/linux/time32.h15
-rw-r--r--include/linux/timekeeping.h4
-rw-r--r--include/linux/tracepoint.h8
-rw-r--r--include/linux/vm_event_item.h1
-rw-r--r--include/linux/vmacache.h5
-rw-r--r--include/net/act_api.h7
-rw-r--r--include/net/cfg80211.h4
-rw-r--r--include/net/netfilter/nf_conntrack_timeout.h2
-rw-r--r--include/net/pkt_cls.h25
-rw-r--r--include/net/regulatory.h4
-rw-r--r--include/uapi/linux/keyctl.h2
-rw-r--r--include/uapi/linux/rds.h1
-rw-r--r--include/uapi/linux/vhost.h2
-rw-r--r--init/Kconfig2
-rw-r--r--ipc/shm.c1
-rw-r--r--kernel/bpf/hashtab.c23
-rw-r--r--kernel/bpf/sockmap.c75
-rw-r--r--kernel/cpu.c37
-rw-r--r--kernel/dma/direct.c4
-rw-r--r--kernel/fork.c3
-rw-r--r--kernel/futex.c2
-rw-r--r--kernel/kallsyms.c51
-rw-r--r--kernel/memremap.c1
-rw-r--r--kernel/printk/printk.c1
-rw-r--r--kernel/printk/printk_safe.c4
-rw-r--r--kernel/time/clocksource.c40
-rw-r--r--kernel/watchdog.c4
-rw-r--r--kernel/watchdog_hld.c2
-rw-r--r--kernel/workqueue.c2
-rw-r--r--lib/Kconfig.debug7
-rw-r--r--lib/Makefile1
-rw-r--r--lib/idr.c155
-rw-r--r--lib/percpu_counter.c1
-rw-r--r--lib/radix-tree.c11
-rw-r--r--lib/rhashtable.c1
-rw-r--r--lib/test_ida.c177
-rw-r--r--mm/debug.c4
-rw-r--r--mm/hmm.c2
-rw-r--r--mm/huge_memory.c8
-rw-r--r--mm/kmemleak.c9
-rw-r--r--mm/madvise.c16
-rw-r--r--mm/memcontrol.c2
-rw-r--r--mm/memory-failure.c210
-rw-r--r--mm/memory_hotplug.c3
-rw-r--r--mm/oom_kill.c14
-rw-r--r--mm/page-writeback.c1
-rw-r--r--mm/page_alloc.c5
-rw-r--r--mm/slub.c1
-rw-r--r--mm/util.c11
-rw-r--r--mm/vmacache.c38
-rw-r--r--net/core/dev.c1
-rw-r--r--net/core/filter.c59
-rw-r--r--net/core/net_namespace.c16
-rw-r--r--net/core/rtnetlink.c4
-rw-r--r--net/core/skbuff.c3
-rw-r--r--net/dsa/dsa.c2
-rw-r--r--net/dsa/slave.c4
-rw-r--r--net/ipv4/igmp.c11
-rw-r--r--net/ipv4/ip_fragment.c1
-rw-r--r--net/ipv4/ip_gre.c8
-rw-r--r--net/ipv4/netfilter/Kconfig8
-rw-r--r--net/ipv4/tcp.c2
-rw-r--r--net/ipv4/tcp_bbr.c42
-rw-r--r--net/ipv4/tcp_input.c4
-rw-r--r--net/ipv4/tcp_ipv4.c6
-rw-r--r--net/ipv4/tcp_minisocks.c3
-rw-r--r--net/ipv6/addrconf.c6
-rw-r--r--net/ipv6/af_inet6.c10
-rw-r--r--net/ipv6/ip6_fib.c7
-rw-r--r--net/ipv6/ip6_gre.c1
-rw-r--r--net/ipv6/ip6_tunnel.c10
-rw-r--r--net/ipv6/ip6_vti.c5
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c1
-rw-r--r--net/ipv6/route.c3
-rw-r--r--net/iucv/af_iucv.c38
-rw-r--r--net/iucv/iucv.c2
-rw-r--r--net/mac80211/ibss.c22
-rw-r--r--net/mac80211/main.c28
-rw-r--r--net/mac80211/mesh_hwmp.c4
-rw-r--r--net/mac80211/mlme.c70
-rw-r--r--net/mac80211/rx.c1
-rw-r--r--net/mac80211/tx.c54
-rw-r--r--net/mac80211/util.c11
-rw-r--r--net/ncsi/ncsi-netlink.c4
-rw-r--r--net/netfilter/Kconfig12
-rw-r--r--net/netfilter/nf_conntrack_proto.c26
-rw-r--r--net/netfilter/nf_conntrack_proto_dccp.c19
-rw-r--r--net/netfilter/nf_conntrack_proto_generic.c8
-rw-r--r--net/netfilter/nf_conntrack_proto_gre.c8
-rw-r--r--net/netfilter/nf_conntrack_proto_icmp.c8
-rw-r--r--net/netfilter/nf_conntrack_proto_icmpv6.c8
-rw-r--r--net/netfilter/nf_conntrack_proto_sctp.c21
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c19
-rw-r--r--net/netfilter/nf_conntrack_proto_udp.c21
-rw-r--r--net/netfilter/nf_tables_api.c1
-rw-r--r--net/netfilter/nfnetlink_cttimeout.c6
-rw-r--r--net/netfilter/nfnetlink_queue.c1
-rw-r--r--net/netfilter/nft_ct.c59
-rw-r--r--net/netfilter/xt_CHECKSUM.c22
-rw-r--r--net/netfilter/xt_cluster.c14
-rw-r--r--net/netfilter/xt_hashlimit.c18
-rw-r--r--net/packet/af_packet.c44
-rw-r--r--net/packet/internal.h1
-rw-r--r--net/rds/Kconfig2
-rw-r--r--net/rds/bind.c5
-rw-r--r--net/rds/ib.c9
-rw-r--r--net/rds/tcp.c1
-rw-r--r--net/rfkill/rfkill-gpio.c1
-rw-r--r--net/sched/act_api.c86
-rw-r--r--net/sched/act_bpf.c8
-rw-r--r--net/sched/act_connmark.c8
-rw-r--r--net/sched/act_csum.c8
-rw-r--r--net/sched/act_gact.c8
-rw-r--r--net/sched/act_ife.c108
-rw-r--r--net/sched/act_ipt.c16
-rw-r--r--net/sched/act_mirred.c8
-rw-r--r--net/sched/act_nat.c8
-rw-r--r--net/sched/act_pedit.c26
-rw-r--r--net/sched/act_police.c8
-rw-r--r--net/sched/act_sample.c8
-rw-r--r--net/sched/act_simple.c8
-rw-r--r--net/sched/act_skbedit.c8
-rw-r--r--net/sched/act_skbmod.c8
-rw-r--r--net/sched/act_tunnel_key.c36
-rw-r--r--net/sched/act_vlan.c8
-rw-r--r--net/sched/cls_api.c4
-rw-r--r--net/sched/cls_u32.c10
-rw-r--r--net/sched/sch_cake.c24
-rw-r--r--net/sctp/proc.c8
-rw-r--r--net/sctp/socket.c56
-rw-r--r--net/tipc/bcast.c4
-rw-r--r--net/tipc/diag.c2
-rw-r--r--net/tipc/name_table.c10
-rw-r--r--net/tipc/name_table.h9
-rw-r--r--net/tipc/netlink.c2
-rw-r--r--net/tipc/netlink_compat.c5
-rw-r--r--net/tipc/socket.c84
-rw-r--r--net/tipc/socket.h3
-rw-r--r--net/tipc/topsrv.c4
-rw-r--r--net/tls/tls_main.c9
-rw-r--r--net/tls/tls_sw.c6
-rw-r--r--net/wireless/nl80211.c15
-rw-r--r--net/wireless/reg.c91
-rw-r--r--net/wireless/util.c2
-rw-r--r--net/xdp/xdp_umem.c4
-rw-r--r--scripts/Kbuild.include8
-rw-r--r--scripts/Makefile.build8
-rw-r--r--scripts/Makefile.lib2
-rw-r--r--scripts/Makefile.modpost2
-rwxr-xr-xscripts/checkpatch.pl3
-rwxr-xr-xscripts/clang-version.sh2
-rw-r--r--scripts/coccinelle/api/alloc/zalloc-simple.cocci41
-rwxr-xr-xscripts/depmod.sh5
-rw-r--r--scripts/dtc/Makefile18
-rw-r--r--scripts/gcc-plugins/Kconfig2
-rw-r--r--scripts/kconfig/Makefile17
-rw-r--r--scripts/kconfig/check-pkgconfig.sh8
-rw-r--r--scripts/kconfig/conf.c5
-rwxr-xr-xscripts/kconfig/gconf-cfg.sh7
-rwxr-xr-xscripts/kconfig/mconf-cfg.sh25
-rw-r--r--scripts/kconfig/mconf.c1
-rw-r--r--scripts/kconfig/nconf-cfg.sh25
-rwxr-xr-xscripts/kconfig/qconf-cfg.sh7
-rw-r--r--scripts/kconfig/symbol.c58
-rw-r--r--scripts/kconfig/tests/err_recursive_dep/Kconfig (renamed from scripts/kconfig/tests/warn_recursive_dep/Kconfig)3
-rw-r--r--scripts/kconfig/tests/err_recursive_dep/__init__.py10
-rw-r--r--scripts/kconfig/tests/err_recursive_dep/expected_stderr38
-rw-r--r--scripts/kconfig/tests/warn_recursive_dep/__init__.py9
-rw-r--r--scripts/kconfig/tests/warn_recursive_dep/expected_stderr30
-rwxr-xr-xscripts/link-vmlinux.sh4
-rw-r--r--scripts/mod/modpost.c8
-rwxr-xr-xscripts/recordmcount.pl3
-rwxr-xr-xscripts/setlocalversion2
-rw-r--r--security/apparmor/secid.c1
-rw-r--r--security/keys/dh.c2
-rw-r--r--sound/core/rawmidi.c4
-rw-r--r--sound/hda/ext/hdac_ext_stream.c22
-rw-r--r--sound/pci/hda/hda_codec.c3
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h3
-rw-r--r--tools/arch/x86/lib/memcpy_64.S2
-rw-r--r--tools/bpf/bpftool/map.c1
-rw-r--r--tools/bpf/bpftool/map_perf_ring.c5
-rwxr-xr-xtools/kvm/kvm_stat/kvm_stat59
-rw-r--r--tools/lib/lockdep/Makefile4
-rw-r--r--tools/lib/traceevent/Makefile4
-rw-r--r--tools/lib/traceevent/event-parse.c712
-rw-r--r--tools/lib/traceevent/event-parse.h458
-rw-r--r--tools/lib/traceevent/event-plugin.c86
-rw-r--r--tools/lib/traceevent/event-utils.h16
-rw-r--r--tools/lib/traceevent/kbuffer-parse.c17
-rw-r--r--tools/lib/traceevent/parse-filter.c304
-rw-r--r--tools/lib/traceevent/parse-utils.c16
-rw-r--r--tools/lib/traceevent/plugin_cfg80211.c20
-rw-r--r--tools/lib/traceevent/plugin_function.c34
-rw-r--r--tools/lib/traceevent/plugin_hrtimer.c56
-rw-r--r--tools/lib/traceevent/plugin_jbd2.c36
-rw-r--r--tools/lib/traceevent/plugin_kmem.c66
-rw-r--r--tools/lib/traceevent/plugin_kvm.c154
-rw-r--r--tools/lib/traceevent/plugin_mac80211.c28
-rw-r--r--tools/lib/traceevent/plugin_sched_switch.c60
-rw-r--r--tools/lib/traceevent/plugin_scsi.c24
-rw-r--r--tools/lib/traceevent/plugin_xen.c20
-rw-r--r--tools/lib/traceevent/trace-seq.c16
-rw-r--r--tools/perf/Documentation/perf-annotate.txt9
-rw-r--r--tools/perf/Documentation/perf-report.txt9
-rw-r--r--tools/perf/Makefile4
-rw-r--r--tools/perf/arch/arm64/util/arm-spe.c1
-rw-r--r--tools/perf/arch/powerpc/util/sym-handling.c4
-rw-r--r--tools/perf/arch/s390/util/auxtrace.c1
-rw-r--r--tools/perf/arch/x86/Makefile3
-rw-r--r--tools/perf/builtin-annotate.c4
-rw-r--r--tools/perf/builtin-kmem.c6
-rw-r--r--tools/perf/builtin-report.c9
-rw-r--r--tools/perf/builtin-script.c6
-rw-r--r--tools/perf/builtin-trace.c191
-rwxr-xr-xtools/perf/check-headers.sh17
-rw-r--r--tools/perf/examples/bpf/augmented_syscalls.c55
-rw-r--r--tools/perf/examples/bpf/hello.c9
-rw-r--r--tools/perf/examples/bpf/sys_enter_openat.c33
-rw-r--r--tools/perf/include/bpf/bpf.h20
-rw-r--r--tools/perf/include/bpf/stdio.h19
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json32
-rw-r--r--tools/perf/pmu-events/arch/arm64/mapfile.csv1
-rw-r--r--tools/perf/tests/bitmap.c2
-rw-r--r--tools/perf/tests/code-reading.c4
-rw-r--r--tools/perf/tests/kmod-path.c136
-rw-r--r--tools/perf/tests/mem2node.c2
-rw-r--r--tools/perf/ui/browsers/annotate.c76
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/annotate.c305
-rw-r--r--tools/perf/util/annotate.h54
-rw-r--r--tools/perf/util/auxtrace.c6
-rw-r--r--tools/perf/util/auxtrace.h1
-rw-r--r--tools/perf/util/bpf-loader.c48
-rw-r--r--tools/perf/util/bpf-loader.h23
-rw-r--r--tools/perf/util/compress.h2
-rw-r--r--tools/perf/util/data-convert-bt.c6
-rw-r--r--tools/perf/util/dso.c111
-rw-r--r--tools/perf/util/dso.h13
-rw-r--r--tools/perf/util/event.c13
-rw-r--r--tools/perf/util/evlist.c2
-rw-r--r--tools/perf/util/evsel.c2
-rw-r--r--tools/perf/util/evsel.h7
-rw-r--r--tools/perf/util/header.c9
-rw-r--r--tools/perf/util/llvm-utils.c31
-rw-r--r--tools/perf/util/llvm-utils.h9
-rw-r--r--tools/perf/util/lzma.c20
-rw-r--r--tools/perf/util/machine.c4
-rw-r--r--tools/perf/util/machine.h2
-rw-r--r--tools/perf/util/map.c44
-rw-r--r--tools/perf/util/map.h1
-rw-r--r--tools/perf/util/mmap.c3
-rw-r--r--tools/perf/util/mmap.h3
-rw-r--r--tools/perf/util/namespaces.c3
-rw-r--r--tools/perf/util/parse-events.c20
-rw-r--r--tools/perf/util/python.c30
-rw-r--r--tools/perf/util/s390-cpumsf-kernel.h71
-rw-r--r--tools/perf/util/s390-cpumsf.c945
-rw-r--r--tools/perf/util/s390-cpumsf.h21
-rw-r--r--tools/perf/util/scripting-engines/trace-event-perl.c2
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c6
-rw-r--r--tools/perf/util/setup.py10
-rw-r--r--tools/perf/util/sort.c16
-rw-r--r--tools/perf/util/sort.h2
-rw-r--r--tools/perf/util/trace-event-parse.c34
-rw-r--r--tools/perf/util/trace-event-read.c44
-rw-r--r--tools/perf/util/trace-event-scripting.c4
-rw-r--r--tools/perf/util/trace-event.c28
-rw-r--r--tools/perf/util/trace-event.h20
-rw-r--r--tools/perf/util/zlib.c18
-rw-r--r--tools/testing/nvdimm/pmem-dax.c12
-rw-r--r--tools/testing/nvdimm/test/nfit.c126
-rw-r--r--tools/testing/radix-tree/Makefile6
-rw-r--r--tools/testing/radix-tree/idr-test.c214
-rw-r--r--tools/testing/radix-tree/linux/xarray.h2
-rw-r--r--tools/testing/radix-tree/main.c23
-rw-r--r--tools/testing/radix-tree/test.h3
-rwxr-xr-xtools/testing/selftests/net/pmtu.sh7
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/police.json48
-rw-r--r--tools/vm/page-types.c6
-rw-r--r--tools/vm/slabinfo.c4
-rw-r--r--usr/Makefile2
-rwxr-xr-xusr/gen_initramfs_list.sh (renamed from scripts/gen_initramfs_list.sh)2
-rw-r--r--usr/initramfs_data.S4
-rw-r--r--virt/kvm/arm/mmu.c21
-rw-r--r--virt/kvm/arm/trace.h15
895 files changed, 11520 insertions, 7290 deletions
diff --git a/.mailmap b/.mailmap
index 2a6f685bf706..285e09645b31 100644
--- a/.mailmap
+++ b/.mailmap
@@ -159,6 +159,7 @@ Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
159Randy Dunlap <rdunlap@infradead.org> <rdunlap@xenotime.net> 159Randy Dunlap <rdunlap@infradead.org> <rdunlap@xenotime.net>
160Rémi Denis-Courmont <rdenis@simphalempin.com> 160Rémi Denis-Courmont <rdenis@simphalempin.com>
161Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> 161Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
162Ross Zwisler <zwisler@kernel.org> <ross.zwisler@linux.intel.com>
162Rudolf Marek <R.Marek@sh.cvut.cz> 163Rudolf Marek <R.Marek@sh.cvut.cz>
163Rui Saraiva <rmps@joel.ist.utl.pt> 164Rui Saraiva <rmps@joel.ist.utl.pt>
164Sachin P Sant <ssant@in.ibm.com> 165Sachin P Sant <ssant@in.ibm.com>
diff --git a/Documentation/ABI/stable/sysfs-bus-xen-backend b/Documentation/ABI/stable/sysfs-bus-xen-backend
index 3d5951c8bf5f..e8b60bd766f7 100644
--- a/Documentation/ABI/stable/sysfs-bus-xen-backend
+++ b/Documentation/ABI/stable/sysfs-bus-xen-backend
@@ -73,3 +73,12 @@ KernelVersion: 3.0
73Contact: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 73Contact: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
74Description: 74Description:
75 Number of sectors written by the frontend. 75 Number of sectors written by the frontend.
76
77What: /sys/bus/xen-backend/devices/*/state
78Date: August 2018
79KernelVersion: 4.19
80Contact: Joe Jin <joe.jin@oracle.com>
81Description:
82 The state of the device. One of: 'Unknown',
83 'Initialising', 'Initialised', 'Connected', 'Closing',
84 'Closed', 'Reconfiguring', 'Reconfigured'.
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 9871e649ffef..64a3bf54b974 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -3523,6 +3523,12 @@
3523 ramdisk_size= [RAM] Sizes of RAM disks in kilobytes 3523 ramdisk_size= [RAM] Sizes of RAM disks in kilobytes
3524 See Documentation/blockdev/ramdisk.txt. 3524 See Documentation/blockdev/ramdisk.txt.
3525 3525
3526 random.trust_cpu={on,off}
3527 [KNL] Enable or disable trusting the use of the
3528 CPU's random number generator (if available) to
3529 fully seed the kernel's CRNG. Default is controlled
3530 by CONFIG_RANDOM_TRUST_CPU.
3531
3526 ras=option[,option,...] [KNL] RAS-specific options 3532 ras=option[,option,...] [KNL] RAS-specific options
3527 3533
3528 cec_disable [X86] 3534 cec_disable [X86]
diff --git a/Documentation/arm64/sve.txt b/Documentation/arm64/sve.txt
index f128f736b4a5..7169a0ec41d8 100644
--- a/Documentation/arm64/sve.txt
+++ b/Documentation/arm64/sve.txt
@@ -200,7 +200,7 @@ prctl(PR_SVE_SET_VL, unsigned long arg)
200 thread. 200 thread.
201 201
202 * Changing the vector length causes all of P0..P15, FFR and all bits of 202 * Changing the vector length causes all of P0..P15, FFR and all bits of
203 Z0..V31 except for Z0 bits [127:0] .. Z31 bits [127:0] to become 203 Z0..Z31 except for Z0 bits [127:0] .. Z31 bits [127:0] to become
204 unspecified. Calling PR_SVE_SET_VL with vl equal to the thread's current 204 unspecified. Calling PR_SVE_SET_VL with vl equal to the thread's current
205 vector length, or calling PR_SVE_SET_VL with the PR_SVE_SET_VL_ONEXEC 205 vector length, or calling PR_SVE_SET_VL with the PR_SVE_SET_VL_ONEXEC
206 flag, does not constitute a change to the vector length for this purpose. 206 flag, does not constitute a change to the vector length for this purpose.
@@ -500,7 +500,7 @@ References
500[2] arch/arm64/include/uapi/asm/ptrace.h 500[2] arch/arm64/include/uapi/asm/ptrace.h
501 AArch64 Linux ptrace ABI definitions 501 AArch64 Linux ptrace ABI definitions
502 502
503[3] linux/Documentation/arm64/cpu-feature-registers.txt 503[3] Documentation/arm64/cpu-feature-registers.txt
504 504
505[4] ARM IHI0055C 505[4] ARM IHI0055C
506 http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf 506 http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf
diff --git a/Documentation/device-mapper/dm-raid.txt b/Documentation/device-mapper/dm-raid.txt
index 390c145f01d7..52a719b49afd 100644
--- a/Documentation/device-mapper/dm-raid.txt
+++ b/Documentation/device-mapper/dm-raid.txt
@@ -348,3 +348,7 @@ Version History
3481.13.1 Fix deadlock caused by early md_stop_writes(). Also fix size an 3481.13.1 Fix deadlock caused by early md_stop_writes(). Also fix size an
349 state races. 349 state races.
3501.13.2 Fix raid redundancy validation and avoid keeping raid set frozen 3501.13.2 Fix raid redundancy validation and avoid keeping raid set frozen
3511.14.0 Fix reshape race on small devices. Fix stripe adding reshape
352 deadlock/potential data corruption. Update superblock when
353 specific devices are requested via rebuild. Fix RAID leg
354 rebuild errors.
diff --git a/Documentation/devicetree/bindings/arm/cpu-capacity.txt b/Documentation/devicetree/bindings/arm/cpu-capacity.txt
index 7809fbe0cdb7..9b5685a1d15d 100644
--- a/Documentation/devicetree/bindings/arm/cpu-capacity.txt
+++ b/Documentation/devicetree/bindings/arm/cpu-capacity.txt
@@ -94,7 +94,7 @@ cpus {
94 }; 94 };
95 95
96 idle-states { 96 idle-states {
97 entry-method = "arm,psci"; 97 entry-method = "psci";
98 98
99 CPU_SLEEP_0: cpu-sleep-0 { 99 CPU_SLEEP_0: cpu-sleep-0 {
100 compatible = "arm,idle-state"; 100 compatible = "arm,idle-state";
diff --git a/Documentation/devicetree/bindings/arm/idle-states.txt b/Documentation/devicetree/bindings/arm/idle-states.txt
index 7a591333f2b1..2c73847499ab 100644
--- a/Documentation/devicetree/bindings/arm/idle-states.txt
+++ b/Documentation/devicetree/bindings/arm/idle-states.txt
@@ -237,8 +237,8 @@ processor idle states, defined as device tree nodes, are listed.
237 Value type: <stringlist> 237 Value type: <stringlist>
238 Usage and definition depend on ARM architecture version. 238 Usage and definition depend on ARM architecture version.
239 # On ARM v8 64-bit this property is required and must 239 # On ARM v8 64-bit this property is required and must
240 be one of: 240 be:
241 - "psci" (see bindings in [2]) 241 - "psci"
242 # On ARM 32-bit systems this property is optional 242 # On ARM 32-bit systems this property is optional
243 243
244The nodes describing the idle states (state) can only be defined within the 244The nodes describing the idle states (state) can only be defined within the
diff --git a/Documentation/devicetree/bindings/i2c/i2c-imx-lpi2c.txt b/Documentation/devicetree/bindings/i2c/i2c-imx-lpi2c.txt
index 00e4365d7206..091c8dfd3229 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-imx-lpi2c.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-imx-lpi2c.txt
@@ -3,7 +3,6 @@
3Required properties: 3Required properties:
4- compatible : 4- compatible :
5 - "fsl,imx7ulp-lpi2c" for LPI2C compatible with the one integrated on i.MX7ULP soc 5 - "fsl,imx7ulp-lpi2c" for LPI2C compatible with the one integrated on i.MX7ULP soc
6 - "fsl,imx8dv-lpi2c" for LPI2C compatible with the one integrated on i.MX8DV soc
7- reg : address and length of the lpi2c master registers 6- reg : address and length of the lpi2c master registers
8- interrupts : lpi2c interrupt 7- interrupts : lpi2c interrupt
9- clocks : lpi2c clock specifier 8- clocks : lpi2c clock specifier
@@ -11,7 +10,7 @@ Required properties:
11Examples: 10Examples:
12 11
13lpi2c7: lpi2c7@40a50000 { 12lpi2c7: lpi2c7@40a50000 {
14 compatible = "fsl,imx8dv-lpi2c"; 13 compatible = "fsl,imx7ulp-lpi2c";
15 reg = <0x40A50000 0x10000>; 14 reg = <0x40A50000 0x10000>;
16 interrupt-parent = <&intc>; 15 interrupt-parent = <&intc>;
17 interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; 16 interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
diff --git a/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt b/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
index 697ca2f26d1b..a046ed374d80 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/renesas,irqc.txt
@@ -13,6 +13,7 @@ Required properties:
13 - "renesas,irqc-r8a7792" (R-Car V2H) 13 - "renesas,irqc-r8a7792" (R-Car V2H)
14 - "renesas,irqc-r8a7793" (R-Car M2-N) 14 - "renesas,irqc-r8a7793" (R-Car M2-N)
15 - "renesas,irqc-r8a7794" (R-Car E2) 15 - "renesas,irqc-r8a7794" (R-Car E2)
16 - "renesas,intc-ex-r8a774a1" (RZ/G2M)
16 - "renesas,intc-ex-r8a7795" (R-Car H3) 17 - "renesas,intc-ex-r8a7795" (R-Car H3)
17 - "renesas,intc-ex-r8a7796" (R-Car M3-W) 18 - "renesas,intc-ex-r8a7796" (R-Car M3-W)
18 - "renesas,intc-ex-r8a77965" (R-Car M3-N) 19 - "renesas,intc-ex-r8a77965" (R-Car M3-N)
diff --git a/Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt b/Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
index b0a8af51c388..265b223cd978 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
@@ -11,7 +11,7 @@ The RISC-V supervisor ISA manual specifies three interrupt sources that are
11attached to every HLIC: software interrupts, the timer interrupt, and external 11attached to every HLIC: software interrupts, the timer interrupt, and external
12interrupts. Software interrupts are used to send IPIs between cores. The 12interrupts. Software interrupts are used to send IPIs between cores. The
13timer interrupt comes from an architecturally mandated real-time timer that is 13timer interrupt comes from an architecturally mandated real-time timer that is
14controller via Supervisor Binary Interface (SBI) calls and CSR reads. External 14controlled via Supervisor Binary Interface (SBI) calls and CSR reads. External
15interrupts connect all other device interrupts to the HLIC, which are routed 15interrupts connect all other device interrupts to the HLIC, which are routed
16via the platform-level interrupt controller (PLIC). 16via the platform-level interrupt controller (PLIC).
17 17
@@ -25,7 +25,15 @@ in the system.
25 25
26Required properties: 26Required properties:
27- compatible : "riscv,cpu-intc" 27- compatible : "riscv,cpu-intc"
28- #interrupt-cells : should be <1> 28- #interrupt-cells : should be <1>. The interrupt sources are defined by the
29 RISC-V supervisor ISA manual, with only the following three interrupts being
30 defined for supervisor mode:
31 - Source 1 is the supervisor software interrupt, which can be sent by an SBI
32 call and is reserved for use by software.
33 - Source 5 is the supervisor timer interrupt, which can be configured by
34 SBI calls and implements a one-shot timer.
35 - Source 9 is the supervisor external interrupt, which chains to all other
36 device interrupts.
29- interrupt-controller : Identifies the node as an interrupt controller 37- interrupt-controller : Identifies the node as an interrupt controller
30 38
31Furthermore, this interrupt-controller MUST be embedded inside the cpu 39Furthermore, this interrupt-controller MUST be embedded inside the cpu
@@ -38,7 +46,7 @@ An example device tree entry for a HLIC is show below.
38 ... 46 ...
39 cpu1-intc: interrupt-controller { 47 cpu1-intc: interrupt-controller {
40 #interrupt-cells = <1>; 48 #interrupt-cells = <1>;
41 compatible = "riscv,cpu-intc", "sifive,fu540-c000-cpu-intc"; 49 compatible = "sifive,fu540-c000-cpu-intc", "riscv,cpu-intc";
42 interrupt-controller; 50 interrupt-controller;
43 }; 51 };
44 }; 52 };
diff --git a/Documentation/devicetree/bindings/net/cpsw.txt b/Documentation/devicetree/bindings/net/cpsw.txt
index 41089369f891..b3acebe08eb0 100644
--- a/Documentation/devicetree/bindings/net/cpsw.txt
+++ b/Documentation/devicetree/bindings/net/cpsw.txt
@@ -19,6 +19,10 @@ Required properties:
19- slaves : Specifies number for slaves 19- slaves : Specifies number for slaves
20- active_slave : Specifies the slave to use for time stamping, 20- active_slave : Specifies the slave to use for time stamping,
21 ethtool and SIOCGMIIPHY 21 ethtool and SIOCGMIIPHY
22- cpsw-phy-sel : Specifies the phandle to the CPSW phy mode selection
23 device. See also cpsw-phy-sel.txt for it's binding.
24 Note that in legacy cases cpsw-phy-sel may be
25 a child device instead of a phandle.
22 26
23Optional properties: 27Optional properties:
24- ti,hwmods : Must be "cpgmac0" 28- ti,hwmods : Must be "cpgmac0"
@@ -75,6 +79,7 @@ Examples:
75 cpts_clock_mult = <0x80000000>; 79 cpts_clock_mult = <0x80000000>;
76 cpts_clock_shift = <29>; 80 cpts_clock_shift = <29>;
77 syscon = <&cm>; 81 syscon = <&cm>;
82 cpsw-phy-sel = <&phy_sel>;
78 cpsw_emac0: slave@0 { 83 cpsw_emac0: slave@0 {
79 phy_id = <&davinci_mdio>, <0>; 84 phy_id = <&davinci_mdio>, <0>;
80 phy-mode = "rgmii-txid"; 85 phy-mode = "rgmii-txid";
@@ -103,6 +108,7 @@ Examples:
103 cpts_clock_mult = <0x80000000>; 108 cpts_clock_mult = <0x80000000>;
104 cpts_clock_shift = <29>; 109 cpts_clock_shift = <29>;
105 syscon = <&cm>; 110 syscon = <&cm>;
111 cpsw-phy-sel = <&phy_sel>;
106 cpsw_emac0: slave@0 { 112 cpsw_emac0: slave@0 {
107 phy_id = <&davinci_mdio>, <0>; 113 phy_id = <&davinci_mdio>, <0>;
108 phy-mode = "rgmii-txid"; 114 phy-mode = "rgmii-txid";
diff --git a/Documentation/devicetree/bindings/net/sh_eth.txt b/Documentation/devicetree/bindings/net/sh_eth.txt
index 76db9f13ad96..abc36274227c 100644
--- a/Documentation/devicetree/bindings/net/sh_eth.txt
+++ b/Documentation/devicetree/bindings/net/sh_eth.txt
@@ -16,6 +16,7 @@ Required properties:
16 "renesas,ether-r8a7794" if the device is a part of R8A7794 SoC. 16 "renesas,ether-r8a7794" if the device is a part of R8A7794 SoC.
17 "renesas,gether-r8a77980" if the device is a part of R8A77980 SoC. 17 "renesas,gether-r8a77980" if the device is a part of R8A77980 SoC.
18 "renesas,ether-r7s72100" if the device is a part of R7S72100 SoC. 18 "renesas,ether-r7s72100" if the device is a part of R7S72100 SoC.
19 "renesas,ether-r7s9210" if the device is a part of R7S9210 SoC.
19 "renesas,rcar-gen1-ether" for a generic R-Car Gen1 device. 20 "renesas,rcar-gen1-ether" for a generic R-Car Gen1 device.
20 "renesas,rcar-gen2-ether" for a generic R-Car Gen2 or RZ/G1 21 "renesas,rcar-gen2-ether" for a generic R-Car Gen2 or RZ/G1
21 device. 22 device.
diff --git a/Documentation/devicetree/bindings/reset/amlogic,meson-axg-audio-arb.txt b/Documentation/devicetree/bindings/reset/amlogic,meson-axg-audio-arb.txt
new file mode 100644
index 000000000000..26e542eb96df
--- /dev/null
+++ b/Documentation/devicetree/bindings/reset/amlogic,meson-axg-audio-arb.txt
@@ -0,0 +1,21 @@
1* Amlogic audio memory arbiter controller
2
3The Amlogic Audio ARB is a simple device which enables or
4disables the access of Audio FIFOs to DDR on AXG based SoC.
5
6Required properties:
7- compatible: 'amlogic,meson-axg-audio-arb'
8- reg: physical base address of the controller and length of memory
9 mapped region.
10- clocks: phandle to the fifo peripheral clock provided by the audio
11 clock controller.
12- #reset-cells: must be 1.
13
14Example on the A113 SoC:
15
16arb: reset-controller@280 {
17 compatible = "amlogic,meson-axg-audio-arb";
18 reg = <0x0 0x280 0x0 0x4>;
19 #reset-cells = <1>;
20 clocks = <&clkc_audio AUD_CLKID_DDR_ARB>;
21};
diff --git a/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt b/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt
index 5d47a262474c..9407212a85a8 100644
--- a/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt
+++ b/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt
@@ -7,6 +7,7 @@ Required properties:
7 Examples with soctypes are: 7 Examples with soctypes are:
8 - "renesas,r8a7743-wdt" (RZ/G1M) 8 - "renesas,r8a7743-wdt" (RZ/G1M)
9 - "renesas,r8a7745-wdt" (RZ/G1E) 9 - "renesas,r8a7745-wdt" (RZ/G1E)
10 - "renesas,r8a774a1-wdt" (RZ/G2M)
10 - "renesas,r8a7790-wdt" (R-Car H2) 11 - "renesas,r8a7790-wdt" (R-Car H2)
11 - "renesas,r8a7791-wdt" (R-Car M2-W) 12 - "renesas,r8a7791-wdt" (R-Car M2-W)
12 - "renesas,r8a7792-wdt" (R-Car V2H) 13 - "renesas,r8a7792-wdt" (R-Car V2H)
@@ -21,8 +22,8 @@ Required properties:
21 - "renesas,r7s72100-wdt" (RZ/A1) 22 - "renesas,r7s72100-wdt" (RZ/A1)
22 The generic compatible string must be: 23 The generic compatible string must be:
23 - "renesas,rza-wdt" for RZ/A 24 - "renesas,rza-wdt" for RZ/A
24 - "renesas,rcar-gen2-wdt" for R-Car Gen2 and RZ/G 25 - "renesas,rcar-gen2-wdt" for R-Car Gen2 and RZ/G1
25 - "renesas,rcar-gen3-wdt" for R-Car Gen3 26 - "renesas,rcar-gen3-wdt" for R-Car Gen3 and RZ/G2
26 27
27- reg : Should contain WDT registers location and length 28- reg : Should contain WDT registers location and length
28- clocks : the clock feeding the watchdog timer. 29- clocks : the clock feeding the watchdog timer.
diff --git a/Documentation/early-userspace/README b/Documentation/early-userspace/README
index 2c00b072a4c8..1e1057958dd3 100644
--- a/Documentation/early-userspace/README
+++ b/Documentation/early-userspace/README
@@ -66,17 +66,17 @@ early userspace image can be built by an unprivileged user.
66 66
67As a technical note, when directories and files are specified, the 67As a technical note, when directories and files are specified, the
68entire CONFIG_INITRAMFS_SOURCE is passed to 68entire CONFIG_INITRAMFS_SOURCE is passed to
69scripts/gen_initramfs_list.sh. This means that CONFIG_INITRAMFS_SOURCE 69usr/gen_initramfs_list.sh. This means that CONFIG_INITRAMFS_SOURCE
70can really be interpreted as any legal argument to 70can really be interpreted as any legal argument to
71gen_initramfs_list.sh. If a directory is specified as an argument then 71gen_initramfs_list.sh. If a directory is specified as an argument then
72the contents are scanned, uid/gid translation is performed, and 72the contents are scanned, uid/gid translation is performed, and
73usr/gen_init_cpio file directives are output. If a directory is 73usr/gen_init_cpio file directives are output. If a directory is
74specified as an argument to scripts/gen_initramfs_list.sh then the 74specified as an argument to usr/gen_initramfs_list.sh then the
75contents of the file are simply copied to the output. All of the output 75contents of the file are simply copied to the output. All of the output
76directives from directory scanning and file contents copying are 76directives from directory scanning and file contents copying are
77processed by usr/gen_init_cpio. 77processed by usr/gen_init_cpio.
78 78
79See also 'scripts/gen_initramfs_list.sh -h'. 79See also 'usr/gen_initramfs_list.sh -h'.
80 80
81Where's this all leading? 81Where's this all leading?
82========================= 82=========================
diff --git a/Documentation/filesystems/ramfs-rootfs-initramfs.txt b/Documentation/filesystems/ramfs-rootfs-initramfs.txt
index b176928e6963..79637d227e85 100644
--- a/Documentation/filesystems/ramfs-rootfs-initramfs.txt
+++ b/Documentation/filesystems/ramfs-rootfs-initramfs.txt
@@ -164,7 +164,7 @@ Documentation/early-userspace/README for more details.)
164The kernel does not depend on external cpio tools. If you specify a 164The kernel does not depend on external cpio tools. If you specify a
165directory instead of a configuration file, the kernel's build infrastructure 165directory instead of a configuration file, the kernel's build infrastructure
166creates a configuration file from that directory (usr/Makefile calls 166creates a configuration file from that directory (usr/Makefile calls
167scripts/gen_initramfs_list.sh), and proceeds to package up that directory 167usr/gen_initramfs_list.sh), and proceeds to package up that directory
168using the config file (by feeding it to usr/gen_init_cpio, which is created 168using the config file (by feeding it to usr/gen_init_cpio, which is created
169from usr/gen_init_cpio.c). The kernel's build-time cpio creation code is 169from usr/gen_init_cpio.c). The kernel's build-time cpio creation code is
170entirely self-contained, and the kernel's boot-time extractor is also 170entirely self-contained, and the kernel's boot-time extractor is also
diff --git a/Documentation/hwmon/ina2xx b/Documentation/hwmon/ina2xx
index 72d16f08e431..b8df81f6d6bc 100644
--- a/Documentation/hwmon/ina2xx
+++ b/Documentation/hwmon/ina2xx
@@ -32,7 +32,7 @@ Supported chips:
32 Datasheet: Publicly available at the Texas Instruments website 32 Datasheet: Publicly available at the Texas Instruments website
33 http://www.ti.com/ 33 http://www.ti.com/
34 34
35Author: Lothar Felten <l-felten@ti.com> 35Author: Lothar Felten <lothar.felten@gmail.com>
36 36
37Description 37Description
38----------- 38-----------
diff --git a/Documentation/i2c/DMA-considerations b/Documentation/i2c/DMA-considerations
index 966610aa4620..203002054120 100644
--- a/Documentation/i2c/DMA-considerations
+++ b/Documentation/i2c/DMA-considerations
@@ -50,10 +50,14 @@ bounce buffer. But you don't need to care about that detail, just use the
50returned buffer. If NULL is returned, the threshold was not met or a bounce 50returned buffer. If NULL is returned, the threshold was not met or a bounce
51buffer could not be allocated. Fall back to PIO in that case. 51buffer could not be allocated. Fall back to PIO in that case.
52 52
53In any case, a buffer obtained from above needs to be released. It ensures data 53In any case, a buffer obtained from above needs to be released. Another helper
54is copied back to the message and a potentially used bounce buffer is freed:: 54function ensures a potentially used bounce buffer is freed::
55 55
56 i2c_release_dma_safe_msg_buf(msg, dma_buf); 56 i2c_put_dma_safe_msg_buf(dma_buf, msg, xferred);
57
58The last argument 'xferred' controls if the buffer is synced back to the
59message or not. No syncing is needed in cases setting up DMA had an error and
60there was no data transferred.
57 61
58The bounce buffer handling from the core is generic and simple. It will always 62The bounce buffer handling from the core is generic and simple. It will always
59allocate a new bounce buffer. If you want a more sophisticated handling (e.g. 63allocate a new bounce buffer. If you want a more sophisticated handling (e.g.
diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt
index c54cb7cb9ff4..864e740811da 100644
--- a/Documentation/kbuild/kconfig-language.txt
+++ b/Documentation/kbuild/kconfig-language.txt
@@ -545,7 +545,7 @@ make KBUILD_KCONFIG=Documentation/kbuild/Kconfig.recursion-issue-02 allnoconfig
545Practical solutions to kconfig recursive issue 545Practical solutions to kconfig recursive issue
546~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 546~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
547 547
548Developers who run into the recursive Kconfig issue have three options 548Developers who run into the recursive Kconfig issue have two options
549at their disposal. We document them below and also provide a list of 549at their disposal. We document them below and also provide a list of
550historical issues resolved through these different solutions. 550historical issues resolved through these different solutions.
551 551
@@ -553,7 +553,6 @@ historical issues resolved through these different solutions.
553 b) Match dependency semantics: 553 b) Match dependency semantics:
554 b1) Swap all "select FOO" to "depends on FOO" or, 554 b1) Swap all "select FOO" to "depends on FOO" or,
555 b2) Swap all "depends on FOO" to "select FOO" 555 b2) Swap all "depends on FOO" to "select FOO"
556 c) Consider the use of "imply" instead of "select"
557 556
558The resolution to a) can be tested with the sample Kconfig file 557The resolution to a) can be tested with the sample Kconfig file
559Documentation/kbuild/Kconfig.recursion-issue-01 through the removal 558Documentation/kbuild/Kconfig.recursion-issue-01 through the removal
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 766355b1d221..7b6a2b2bdc98 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -680,7 +680,7 @@ Both possibilities are described in the following.
680 680
681 Example: 681 Example:
682 #scripts/kconfig/Makefile 682 #scripts/kconfig/Makefile
683 HOSTLOADLIBES_qconf := -L$(QTDIR)/lib 683 HOSTLDLIBS_qconf := -L$(QTDIR)/lib
684 684
685 When linking qconf, it will be passed the extra option 685 When linking qconf, it will be passed the extra option
686 "-L$(QTDIR)/lib". 686 "-L$(QTDIR)/lib".
diff --git a/Documentation/process/changes.rst b/Documentation/process/changes.rst
index 61f918b10a0c..d1bf143b446f 100644
--- a/Documentation/process/changes.rst
+++ b/Documentation/process/changes.rst
@@ -86,7 +86,7 @@ pkg-config
86 86
87The build system, as of 4.18, requires pkg-config to check for installed 87The build system, as of 4.18, requires pkg-config to check for installed
88kconfig tools and to determine flags settings for use in 88kconfig tools and to determine flags settings for use in
89'make {menu,n,g,x}config'. Previously pkg-config was being used but not 89'make {g,x}config'. Previously pkg-config was being used but not
90verified or documented. 90verified or documented.
91 91
92Flex 92Flex
diff --git a/Documentation/scsi/scsi-parameters.txt b/Documentation/scsi/scsi-parameters.txt
index 25a4b4cf04a6..92999d4e0cb8 100644
--- a/Documentation/scsi/scsi-parameters.txt
+++ b/Documentation/scsi/scsi-parameters.txt
@@ -97,6 +97,11 @@ parameters may be changed at runtime by the command
97 allowing boot to proceed. none ignores them, expecting 97 allowing boot to proceed. none ignores them, expecting
98 user space to do the scan. 98 user space to do the scan.
99 99
100 scsi_mod.use_blk_mq=
101 [SCSI] use blk-mq I/O path by default
102 See SCSI_MQ_DEFAULT in drivers/scsi/Kconfig.
103 Format: <y/n>
104
100 sim710= [SCSI,HW] 105 sim710= [SCSI,HW]
101 See header of drivers/scsi/sim710.c. 106 See header of drivers/scsi/sim710.c.
102 107
diff --git a/MAINTAINERS b/MAINTAINERS
index e20e7c42347b..bb65f0c1861c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2311,6 +2311,7 @@ F: drivers/clocksource/cadence_ttc_timer.c
2311F: drivers/i2c/busses/i2c-cadence.c 2311F: drivers/i2c/busses/i2c-cadence.c
2312F: drivers/mmc/host/sdhci-of-arasan.c 2312F: drivers/mmc/host/sdhci-of-arasan.c
2313F: drivers/edac/synopsys_edac.c 2313F: drivers/edac/synopsys_edac.c
2314F: drivers/i2c/busses/i2c-xiic.c
2314 2315
2315ARM64 PORT (AARCH64 ARCHITECTURE) 2316ARM64 PORT (AARCH64 ARCHITECTURE)
2316M: Catalin Marinas <catalin.marinas@arm.com> 2317M: Catalin Marinas <catalin.marinas@arm.com>
@@ -4364,7 +4365,8 @@ F: drivers/i2c/busses/i2c-diolan-u2c.c
4364 4365
4365FILESYSTEM DIRECT ACCESS (DAX) 4366FILESYSTEM DIRECT ACCESS (DAX)
4366M: Matthew Wilcox <mawilcox@microsoft.com> 4367M: Matthew Wilcox <mawilcox@microsoft.com>
4367M: Ross Zwisler <ross.zwisler@linux.intel.com> 4368M: Ross Zwisler <zwisler@kernel.org>
4369M: Jan Kara <jack@suse.cz>
4368L: linux-fsdevel@vger.kernel.org 4370L: linux-fsdevel@vger.kernel.org
4369S: Supported 4371S: Supported
4370F: fs/dax.c 4372F: fs/dax.c
@@ -4374,7 +4376,7 @@ F: include/trace/events/fs_dax.h
4374DEVICE DIRECT ACCESS (DAX) 4376DEVICE DIRECT ACCESS (DAX)
4375M: Dan Williams <dan.j.williams@intel.com> 4377M: Dan Williams <dan.j.williams@intel.com>
4376M: Dave Jiang <dave.jiang@intel.com> 4378M: Dave Jiang <dave.jiang@intel.com>
4377M: Ross Zwisler <ross.zwisler@linux.intel.com> 4379M: Ross Zwisler <zwisler@kernel.org>
4378M: Vishal Verma <vishal.l.verma@intel.com> 4380M: Vishal Verma <vishal.l.verma@intel.com>
4379L: linux-nvdimm@lists.01.org 4381L: linux-nvdimm@lists.01.org
4380S: Supported 4382S: Supported
@@ -7014,6 +7016,20 @@ F: drivers/crypto/vmx/aes*
7014F: drivers/crypto/vmx/ghash* 7016F: drivers/crypto/vmx/ghash*
7015F: drivers/crypto/vmx/ppc-xlate.pl 7017F: drivers/crypto/vmx/ppc-xlate.pl
7016 7018
7019IBM Power PCI Hotplug Driver for RPA-compliant PPC64 platform
7020M: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
7021L: linux-pci@vger.kernel.org
7022L: linuxppc-dev@lists.ozlabs.org
7023S: Supported
7024F: drivers/pci/hotplug/rpaphp*
7025
7026IBM Power IO DLPAR Driver for RPA-compliant PPC64 platform
7027M: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
7028L: linux-pci@vger.kernel.org
7029L: linuxppc-dev@lists.ozlabs.org
7030S: Supported
7031F: drivers/pci/hotplug/rpadlpar*
7032
7017IBM ServeRAID RAID DRIVER 7033IBM ServeRAID RAID DRIVER
7018S: Orphan 7034S: Orphan
7019F: drivers/scsi/ips.* 7035F: drivers/scsi/ips.*
@@ -8254,9 +8270,9 @@ F: drivers/ata/pata_arasan_cf.c
8254 8270
8255LIBATA PATA DRIVERS 8271LIBATA PATA DRIVERS
8256M: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> 8272M: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
8257M: Jens Axboe <kernel.dk> 8273M: Jens Axboe <axboe@kernel.dk>
8258L: linux-ide@vger.kernel.org 8274L: linux-ide@vger.kernel.org
8259T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git 8275T: git git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git
8260S: Maintained 8276S: Maintained
8261F: drivers/ata/pata_*.c 8277F: drivers/ata/pata_*.c
8262F: drivers/ata/ata_generic.c 8278F: drivers/ata/ata_generic.c
@@ -8274,7 +8290,7 @@ LIBATA SATA AHCI PLATFORM devices support
8274M: Hans de Goede <hdegoede@redhat.com> 8290M: Hans de Goede <hdegoede@redhat.com>
8275M: Jens Axboe <axboe@kernel.dk> 8291M: Jens Axboe <axboe@kernel.dk>
8276L: linux-ide@vger.kernel.org 8292L: linux-ide@vger.kernel.org
8277T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git 8293T: git git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git
8278S: Maintained 8294S: Maintained
8279F: drivers/ata/ahci_platform.c 8295F: drivers/ata/ahci_platform.c
8280F: drivers/ata/libahci_platform.c 8296F: drivers/ata/libahci_platform.c
@@ -8290,7 +8306,7 @@ F: drivers/ata/sata_promise.*
8290LIBATA SUBSYSTEM (Serial and Parallel ATA drivers) 8306LIBATA SUBSYSTEM (Serial and Parallel ATA drivers)
8291M: Jens Axboe <axboe@kernel.dk> 8307M: Jens Axboe <axboe@kernel.dk>
8292L: linux-ide@vger.kernel.org 8308L: linux-ide@vger.kernel.org
8293T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git 8309T: git git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git
8294S: Maintained 8310S: Maintained
8295F: drivers/ata/ 8311F: drivers/ata/
8296F: include/linux/ata.h 8312F: include/linux/ata.h
@@ -8303,7 +8319,7 @@ S: Maintained
8303F: tools/lib/lockdep/ 8319F: tools/lib/lockdep/
8304 8320
8305LIBNVDIMM BLK: MMIO-APERTURE DRIVER 8321LIBNVDIMM BLK: MMIO-APERTURE DRIVER
8306M: Ross Zwisler <ross.zwisler@linux.intel.com> 8322M: Ross Zwisler <zwisler@kernel.org>
8307M: Dan Williams <dan.j.williams@intel.com> 8323M: Dan Williams <dan.j.williams@intel.com>
8308M: Vishal Verma <vishal.l.verma@intel.com> 8324M: Vishal Verma <vishal.l.verma@intel.com>
8309M: Dave Jiang <dave.jiang@intel.com> 8325M: Dave Jiang <dave.jiang@intel.com>
@@ -8316,7 +8332,7 @@ F: drivers/nvdimm/region_devs.c
8316LIBNVDIMM BTT: BLOCK TRANSLATION TABLE 8332LIBNVDIMM BTT: BLOCK TRANSLATION TABLE
8317M: Vishal Verma <vishal.l.verma@intel.com> 8333M: Vishal Verma <vishal.l.verma@intel.com>
8318M: Dan Williams <dan.j.williams@intel.com> 8334M: Dan Williams <dan.j.williams@intel.com>
8319M: Ross Zwisler <ross.zwisler@linux.intel.com> 8335M: Ross Zwisler <zwisler@kernel.org>
8320M: Dave Jiang <dave.jiang@intel.com> 8336M: Dave Jiang <dave.jiang@intel.com>
8321L: linux-nvdimm@lists.01.org 8337L: linux-nvdimm@lists.01.org
8322Q: https://patchwork.kernel.org/project/linux-nvdimm/list/ 8338Q: https://patchwork.kernel.org/project/linux-nvdimm/list/
@@ -8324,7 +8340,7 @@ S: Supported
8324F: drivers/nvdimm/btt* 8340F: drivers/nvdimm/btt*
8325 8341
8326LIBNVDIMM PMEM: PERSISTENT MEMORY DRIVER 8342LIBNVDIMM PMEM: PERSISTENT MEMORY DRIVER
8327M: Ross Zwisler <ross.zwisler@linux.intel.com> 8343M: Ross Zwisler <zwisler@kernel.org>
8328M: Dan Williams <dan.j.williams@intel.com> 8344M: Dan Williams <dan.j.williams@intel.com>
8329M: Vishal Verma <vishal.l.verma@intel.com> 8345M: Vishal Verma <vishal.l.verma@intel.com>
8330M: Dave Jiang <dave.jiang@intel.com> 8346M: Dave Jiang <dave.jiang@intel.com>
@@ -8343,7 +8359,7 @@ F: Documentation/devicetree/bindings/pmem/pmem-region.txt
8343 8359
8344LIBNVDIMM: NON-VOLATILE MEMORY DEVICE SUBSYSTEM 8360LIBNVDIMM: NON-VOLATILE MEMORY DEVICE SUBSYSTEM
8345M: Dan Williams <dan.j.williams@intel.com> 8361M: Dan Williams <dan.j.williams@intel.com>
8346M: Ross Zwisler <ross.zwisler@linux.intel.com> 8362M: Ross Zwisler <zwisler@kernel.org>
8347M: Vishal Verma <vishal.l.verma@intel.com> 8363M: Vishal Verma <vishal.l.verma@intel.com>
8348M: Dave Jiang <dave.jiang@intel.com> 8364M: Dave Jiang <dave.jiang@intel.com>
8349L: linux-nvdimm@lists.01.org 8365L: linux-nvdimm@lists.01.org
@@ -11152,7 +11168,7 @@ F: drivers/pci/controller/dwc/pci-exynos.c
11152 11168
11153PCI DRIVER FOR SYNOPSYS DESIGNWARE 11169PCI DRIVER FOR SYNOPSYS DESIGNWARE
11154M: Jingoo Han <jingoohan1@gmail.com> 11170M: Jingoo Han <jingoohan1@gmail.com>
11155M: Joao Pinto <Joao.Pinto@synopsys.com> 11171M: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
11156L: linux-pci@vger.kernel.org 11172L: linux-pci@vger.kernel.org
11157S: Maintained 11173S: Maintained
11158F: Documentation/devicetree/bindings/pci/designware-pcie.txt 11174F: Documentation/devicetree/bindings/pci/designware-pcie.txt
@@ -11344,10 +11360,10 @@ S: Maintained
11344F: drivers/platform/x86/peaq-wmi.c 11360F: drivers/platform/x86/peaq-wmi.c
11345 11361
11346PER-CPU MEMORY ALLOCATOR 11362PER-CPU MEMORY ALLOCATOR
11363M: Dennis Zhou <dennis@kernel.org>
11347M: Tejun Heo <tj@kernel.org> 11364M: Tejun Heo <tj@kernel.org>
11348M: Christoph Lameter <cl@linux.com> 11365M: Christoph Lameter <cl@linux.com>
11349M: Dennis Zhou <dennisszhou@gmail.com> 11366T: git git://git.kernel.org/pub/scm/linux/kernel/git/dennis/percpu.git
11350T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu.git
11351S: Maintained 11367S: Maintained
11352F: include/linux/percpu*.h 11368F: include/linux/percpu*.h
11353F: mm/percpu*.c 11369F: mm/percpu*.c
diff --git a/Makefile b/Makefile
index c13f8b85ba60..4d5c883a98e5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2VERSION = 4 2VERSION = 4
3PATCHLEVEL = 18 3PATCHLEVEL = 19
4SUBLEVEL = 0 4SUBLEVEL = 0
5EXTRAVERSION = 5EXTRAVERSION = -rc3
6NAME = Merciless Moray 6NAME = Merciless Moray
7 7
8# *DOCUMENTATION* 8# *DOCUMENTATION*
@@ -440,7 +440,7 @@ KBUILD_CFLAGS_KERNEL :=
440KBUILD_AFLAGS_MODULE := -DMODULE 440KBUILD_AFLAGS_MODULE := -DMODULE
441KBUILD_CFLAGS_MODULE := -DMODULE 441KBUILD_CFLAGS_MODULE := -DMODULE
442KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds 442KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
443LDFLAGS := 443KBUILD_LDFLAGS :=
444GCC_PLUGINS_CFLAGS := 444GCC_PLUGINS_CFLAGS :=
445 445
446export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC 446export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
@@ -448,7 +448,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
448export MAKE LEX YACC AWK GENKSYMS INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE 448export MAKE LEX YACC AWK GENKSYMS INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE
449export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS 449export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
450 450
451export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS 451export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
452export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 452export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
453export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN 453export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
454export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 454export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
@@ -507,9 +507,13 @@ KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
507endif 507endif
508 508
509RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register 509RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
510RETPOLINE_VDSO_CFLAGS_GCC := -mindirect-branch=thunk-inline -mindirect-branch-register
510RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk 511RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
512RETPOLINE_VDSO_CFLAGS_CLANG := -mretpoline
511RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG))) 513RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
514RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_VDSO_CFLAGS_CLANG)))
512export RETPOLINE_CFLAGS 515export RETPOLINE_CFLAGS
516export RETPOLINE_VDSO_CFLAGS
513 517
514KBUILD_CFLAGS += $(call cc-option,-fno-PIE) 518KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
515KBUILD_AFLAGS += $(call cc-option,-fno-PIE) 519KBUILD_AFLAGS += $(call cc-option,-fno-PIE)
@@ -790,8 +794,8 @@ KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
790endif 794endif
791 795
792ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION 796ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
793KBUILD_CFLAGS_KERNEL += $(call cc-option,-ffunction-sections,) 797KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
794KBUILD_CFLAGS_KERNEL += $(call cc-option,-fdata-sections,) 798LDFLAGS_vmlinux += --gc-sections
795endif 799endif
796 800
797# arch Makefile may override CC so keep this after arch Makefile is included 801# arch Makefile may override CC so keep this after arch Makefile is included
@@ -803,6 +807,9 @@ KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
803# disable pointer signed / unsigned warnings in gcc 4.0 807# disable pointer signed / unsigned warnings in gcc 4.0
804KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign) 808KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign)
805 809
810# disable stringop warnings in gcc 8+
811KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
812
806# disable invalid "can't wrap" optimizations for signed / pointers 813# disable invalid "can't wrap" optimizations for signed / pointers
807KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow) 814KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
808 815
@@ -857,10 +864,6 @@ LDFLAGS_BUILD_ID := $(call ld-option, --build-id)
857KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) 864KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
858LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) 865LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
859 866
860ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
861LDFLAGS_vmlinux += $(call ld-option, --gc-sections,)
862endif
863
864ifeq ($(CONFIG_STRIP_ASM_SYMS),y) 867ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
865LDFLAGS_vmlinux += $(call ld-option, -X,) 868LDFLAGS_vmlinux += $(call ld-option, -X,)
866endif 869endif
@@ -1024,7 +1027,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
1024 1027
1025# Final link of vmlinux with optional arch pass after final link 1028# Final link of vmlinux with optional arch pass after final link
1026cmd_link-vmlinux = \ 1029cmd_link-vmlinux = \
1027 $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ; \ 1030 $(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \
1028 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 1031 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
1029 1032
1030vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE 1033vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
@@ -1354,16 +1357,12 @@ distclean: mrproper
1354 1357
1355# Packaging of the kernel to various formats 1358# Packaging of the kernel to various formats
1356# --------------------------------------------------------------------------- 1359# ---------------------------------------------------------------------------
1357# rpm target kept for backward compatibility
1358package-dir := scripts/package 1360package-dir := scripts/package
1359 1361
1360%src-pkg: FORCE 1362%src-pkg: FORCE
1361 $(Q)$(MAKE) $(build)=$(package-dir) $@ 1363 $(Q)$(MAKE) $(build)=$(package-dir) $@
1362%pkg: include/config/kernel.release FORCE 1364%pkg: include/config/kernel.release FORCE
1363 $(Q)$(MAKE) $(build)=$(package-dir) $@ 1365 $(Q)$(MAKE) $(build)=$(package-dir) $@
1364rpm: rpm-pkg
1365 @echo " WARNING: \"rpm\" target will be removed after Linux 4.18"
1366 @echo " Please use \"rpm-pkg\" instead."
1367 1366
1368 1367
1369# Brief documentation of the typical targets used 1368# Brief documentation of the typical targets used
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 6d5eb8267e42..b4441b0764d7 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -9,6 +9,7 @@
9config ARC 9config ARC
10 def_bool y 10 def_bool y
11 select ARC_TIMERS 11 select ARC_TIMERS
12 select ARCH_HAS_PTE_SPECIAL
12 select ARCH_HAS_SYNC_DMA_FOR_CPU 13 select ARCH_HAS_SYNC_DMA_FOR_CPU
13 select ARCH_HAS_SYNC_DMA_FOR_DEVICE 14 select ARCH_HAS_SYNC_DMA_FOR_DEVICE
14 select ARCH_HAS_SG_CHAIN 15 select ARCH_HAS_SG_CHAIN
@@ -28,8 +29,12 @@ config ARC
28 select GENERIC_SMP_IDLE_THREAD 29 select GENERIC_SMP_IDLE_THREAD
29 select HAVE_ARCH_KGDB 30 select HAVE_ARCH_KGDB
30 select HAVE_ARCH_TRACEHOOK 31 select HAVE_ARCH_TRACEHOOK
32 select HAVE_DEBUG_STACKOVERFLOW
31 select HAVE_FUTEX_CMPXCHG if FUTEX 33 select HAVE_FUTEX_CMPXCHG if FUTEX
34 select HAVE_GENERIC_DMA_COHERENT
32 select HAVE_IOREMAP_PROT 35 select HAVE_IOREMAP_PROT
36 select HAVE_KERNEL_GZIP
37 select HAVE_KERNEL_LZMA
33 select HAVE_KPROBES 38 select HAVE_KPROBES
34 select HAVE_KRETPROBES 39 select HAVE_KRETPROBES
35 select HAVE_MEMBLOCK 40 select HAVE_MEMBLOCK
@@ -44,11 +49,6 @@ config ARC
44 select OF_EARLY_FLATTREE 49 select OF_EARLY_FLATTREE
45 select OF_RESERVED_MEM 50 select OF_RESERVED_MEM
46 select PERF_USE_VMALLOC if ARC_CACHE_VIPT_ALIASING 51 select PERF_USE_VMALLOC if ARC_CACHE_VIPT_ALIASING
47 select HAVE_DEBUG_STACKOVERFLOW
48 select HAVE_GENERIC_DMA_COHERENT
49 select HAVE_KERNEL_GZIP
50 select HAVE_KERNEL_LZMA
51 select ARCH_HAS_PTE_SPECIAL
52 52
53config ARCH_HAS_CACHE_LINE_SIZE 53config ARCH_HAS_CACHE_LINE_SIZE
54 def_bool y 54 def_bool y
diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index 6c1b20dd76ad..99cce77ab98f 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -43,10 +43,7 @@ ifdef CONFIG_ARC_CURR_IN_REG
43LINUXINCLUDE += -include ${src}/arch/arc/include/asm/current.h 43LINUXINCLUDE += -include ${src}/arch/arc/include/asm/current.h
44endif 44endif
45 45
46upto_gcc44 := $(call cc-ifversion, -le, 0404, y) 46cflags-y += -fsection-anchors
47atleast_gcc44 := $(call cc-ifversion, -ge, 0404, y)
48
49cflags-$(atleast_gcc44) += -fsection-anchors
50 47
51cflags-$(CONFIG_ARC_HAS_LLSC) += -mlock 48cflags-$(CONFIG_ARC_HAS_LLSC) += -mlock
52cflags-$(CONFIG_ARC_HAS_SWAPE) += -mswape 49cflags-$(CONFIG_ARC_HAS_SWAPE) += -mswape
@@ -82,11 +79,6 @@ cflags-$(disable_small_data) += -mno-sdata -fcall-used-gp
82cflags-$(CONFIG_CPU_BIG_ENDIAN) += -mbig-endian 79cflags-$(CONFIG_CPU_BIG_ENDIAN) += -mbig-endian
83ldflags-$(CONFIG_CPU_BIG_ENDIAN) += -EB 80ldflags-$(CONFIG_CPU_BIG_ENDIAN) += -EB
84 81
85# STAR 9000518362: (fixed with binutils shipping with gcc 4.8)
86# arc-linux-uclibc-ld (buildroot) or arceb-elf32-ld (EZChip) don't accept
87# --build-id w/o "-marclinux". Default arc-elf32-ld is OK
88ldflags-$(upto_gcc44) += -marclinux
89
90LIBGCC := $(shell $(CC) $(cflags-y) --print-libgcc-file-name) 82LIBGCC := $(shell $(CC) $(cflags-y) --print-libgcc-file-name)
91 83
92# Modules with short calls might break for calls into builtin-kernel 84# Modules with short calls might break for calls into builtin-kernel
@@ -95,7 +87,7 @@ KBUILD_CFLAGS_MODULE += -mlong-calls -mno-millicode
95# Finally dump eveything into kernel build system 87# Finally dump eveything into kernel build system
96KBUILD_CFLAGS += $(cflags-y) 88KBUILD_CFLAGS += $(cflags-y)
97KBUILD_AFLAGS += $(KBUILD_CFLAGS) 89KBUILD_AFLAGS += $(KBUILD_CFLAGS)
98LDFLAGS += $(ldflags-y) 90KBUILD_LDFLAGS += $(ldflags-y)
99 91
100head-y := arch/arc/kernel/head.o 92head-y := arch/arc/kernel/head.o
101 93
diff --git a/arch/arc/boot/dts/axc003.dtsi b/arch/arc/boot/dts/axc003.dtsi
index dc91c663bcc0..d75d65ddf8e3 100644
--- a/arch/arc/boot/dts/axc003.dtsi
+++ b/arch/arc/boot/dts/axc003.dtsi
@@ -94,6 +94,32 @@
94 }; 94 };
95 95
96 /* 96 /*
97 * Mark DMA peripherals connected via IOC port as dma-coherent. We do
98 * it via overlay because peripherals defined in axs10x_mb.dtsi are
99 * used for both AXS101 and AXS103 boards and only AXS103 has IOC (so
100 * only AXS103 board has HW-coherent DMA peripherals)
101 * We don't need to mark pgu@17000 as dma-coherent because it uses
102 * external DMA buffer located outside of IOC aperture.
103 */
104 axs10x_mb {
105 ethernet@0x18000 {
106 dma-coherent;
107 };
108
109 ehci@0x40000 {
110 dma-coherent;
111 };
112
113 ohci@0x60000 {
114 dma-coherent;
115 };
116
117 mmc@0x15000 {
118 dma-coherent;
119 };
120 };
121
122 /*
97 * The DW APB ICTL intc on MB is connected to CPU intc via a 123 * The DW APB ICTL intc on MB is connected to CPU intc via a
98 * DT "invisible" DW APB GPIO block, configured to simply pass thru 124 * DT "invisible" DW APB GPIO block, configured to simply pass thru
99 * interrupts - setup accordinly in platform init (plat-axs10x/ax10x.c) 125 * interrupts - setup accordinly in platform init (plat-axs10x/ax10x.c)
diff --git a/arch/arc/boot/dts/axc003_idu.dtsi b/arch/arc/boot/dts/axc003_idu.dtsi
index 69ff4895f2ba..a05bb737ea63 100644
--- a/arch/arc/boot/dts/axc003_idu.dtsi
+++ b/arch/arc/boot/dts/axc003_idu.dtsi
@@ -101,6 +101,32 @@
101 }; 101 };
102 102
103 /* 103 /*
104 * Mark DMA peripherals connected via IOC port as dma-coherent. We do
105 * it via overlay because peripherals defined in axs10x_mb.dtsi are
106 * used for both AXS101 and AXS103 boards and only AXS103 has IOC (so
107 * only AXS103 board has HW-coherent DMA peripherals)
108 * We don't need to mark pgu@17000 as dma-coherent because it uses
109 * external DMA buffer located outside of IOC aperture.
110 */
111 axs10x_mb {
112 ethernet@0x18000 {
113 dma-coherent;
114 };
115
116 ehci@0x40000 {
117 dma-coherent;
118 };
119
120 ohci@0x60000 {
121 dma-coherent;
122 };
123
124 mmc@0x15000 {
125 dma-coherent;
126 };
127 };
128
129 /*
104 * This INTC is actually connected to DW APB GPIO 130 * This INTC is actually connected to DW APB GPIO
105 * which acts as a wire between MB INTC and CPU INTC. 131 * which acts as a wire between MB INTC and CPU INTC.
106 * GPIO INTC is configured in platform init code 132 * GPIO INTC is configured in platform init code
diff --git a/arch/arc/boot/dts/axs10x_mb.dtsi b/arch/arc/boot/dts/axs10x_mb.dtsi
index 47b74fbc403c..37bafd44e36d 100644
--- a/arch/arc/boot/dts/axs10x_mb.dtsi
+++ b/arch/arc/boot/dts/axs10x_mb.dtsi
@@ -9,6 +9,10 @@
9 */ 9 */
10 10
11/ { 11/ {
12 aliases {
13 ethernet = &gmac;
14 };
15
12 axs10x_mb { 16 axs10x_mb {
13 compatible = "simple-bus"; 17 compatible = "simple-bus";
14 #address-cells = <1>; 18 #address-cells = <1>;
@@ -68,7 +72,7 @@
68 }; 72 };
69 }; 73 };
70 74
71 ethernet@0x18000 { 75 gmac: ethernet@0x18000 {
72 #interrupt-cells = <1>; 76 #interrupt-cells = <1>;
73 compatible = "snps,dwmac"; 77 compatible = "snps,dwmac";
74 reg = < 0x18000 0x2000 >; 78 reg = < 0x18000 0x2000 >;
@@ -81,6 +85,7 @@
81 max-speed = <100>; 85 max-speed = <100>;
82 resets = <&creg_rst 5>; 86 resets = <&creg_rst 5>;
83 reset-names = "stmmaceth"; 87 reset-names = "stmmaceth";
88 mac-address = [00 00 00 00 00 00]; /* Filled in by U-Boot */
84 }; 89 };
85 90
86 ehci@0x40000 { 91 ehci@0x40000 {
diff --git a/arch/arc/boot/dts/hsdk.dts b/arch/arc/boot/dts/hsdk.dts
index 006aa3de5348..ef149f59929a 100644
--- a/arch/arc/boot/dts/hsdk.dts
+++ b/arch/arc/boot/dts/hsdk.dts
@@ -25,6 +25,10 @@
25 bootargs = "earlycon=uart8250,mmio32,0xf0005000,115200n8 console=ttyS0,115200n8 debug print-fatal-signals=1"; 25 bootargs = "earlycon=uart8250,mmio32,0xf0005000,115200n8 console=ttyS0,115200n8 debug print-fatal-signals=1";
26 }; 26 };
27 27
28 aliases {
29 ethernet = &gmac;
30 };
31
28 cpus { 32 cpus {
29 #address-cells = <1>; 33 #address-cells = <1>;
30 #size-cells = <0>; 34 #size-cells = <0>;
@@ -163,7 +167,7 @@
163 #clock-cells = <0>; 167 #clock-cells = <0>;
164 }; 168 };
165 169
166 ethernet@8000 { 170 gmac: ethernet@8000 {
167 #interrupt-cells = <1>; 171 #interrupt-cells = <1>;
168 compatible = "snps,dwmac"; 172 compatible = "snps,dwmac";
169 reg = <0x8000 0x2000>; 173 reg = <0x8000 0x2000>;
@@ -176,6 +180,8 @@
176 phy-handle = <&phy0>; 180 phy-handle = <&phy0>;
177 resets = <&cgu_rst HSDK_ETH_RESET>; 181 resets = <&cgu_rst HSDK_ETH_RESET>;
178 reset-names = "stmmaceth"; 182 reset-names = "stmmaceth";
183 mac-address = [00 00 00 00 00 00]; /* Filled in by U-Boot */
184 dma-coherent;
179 185
180 mdio { 186 mdio {
181 #address-cells = <1>; 187 #address-cells = <1>;
@@ -194,12 +200,14 @@
194 compatible = "snps,hsdk-v1.0-ohci", "generic-ohci"; 200 compatible = "snps,hsdk-v1.0-ohci", "generic-ohci";
195 reg = <0x60000 0x100>; 201 reg = <0x60000 0x100>;
196 interrupts = <15>; 202 interrupts = <15>;
203 dma-coherent;
197 }; 204 };
198 205
199 ehci@40000 { 206 ehci@40000 {
200 compatible = "snps,hsdk-v1.0-ehci", "generic-ehci"; 207 compatible = "snps,hsdk-v1.0-ehci", "generic-ehci";
201 reg = <0x40000 0x100>; 208 reg = <0x40000 0x100>;
202 interrupts = <15>; 209 interrupts = <15>;
210 dma-coherent;
203 }; 211 };
204 212
205 mmc@a000 { 213 mmc@a000 {
@@ -212,6 +220,7 @@
212 clock-names = "biu", "ciu"; 220 clock-names = "biu", "ciu";
213 interrupts = <12>; 221 interrupts = <12>;
214 bus-width = <4>; 222 bus-width = <4>;
223 dma-coherent;
215 }; 224 };
216 }; 225 };
217 226
diff --git a/arch/arc/configs/axs101_defconfig b/arch/arc/configs/axs101_defconfig
index a635ea972304..41bc08be6a3b 100644
--- a/arch/arc/configs/axs101_defconfig
+++ b/arch/arc/configs/axs101_defconfig
@@ -1,5 +1,3 @@
1CONFIG_DEFAULT_HOSTNAME="ARCLinux"
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
4CONFIG_POSIX_MQUEUE=y 2CONFIG_POSIX_MQUEUE=y
5# CONFIG_CROSS_MEMORY_ATTACH is not set 3# CONFIG_CROSS_MEMORY_ATTACH is not set
@@ -63,7 +61,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
63CONFIG_MOUSE_SERIAL=y 61CONFIG_MOUSE_SERIAL=y
64CONFIG_MOUSE_SYNAPTICS_USB=y 62CONFIG_MOUSE_SYNAPTICS_USB=y
65# CONFIG_LEGACY_PTYS is not set 63# CONFIG_LEGACY_PTYS is not set
66# CONFIG_DEVKMEM is not set
67CONFIG_SERIAL_8250=y 64CONFIG_SERIAL_8250=y
68CONFIG_SERIAL_8250_CONSOLE=y 65CONFIG_SERIAL_8250_CONSOLE=y
69CONFIG_SERIAL_8250_DW=y 66CONFIG_SERIAL_8250_DW=y
diff --git a/arch/arc/configs/axs103_defconfig b/arch/arc/configs/axs103_defconfig
index aa507e423075..1e1c4a8011b5 100644
--- a/arch/arc/configs/axs103_defconfig
+++ b/arch/arc/configs/axs103_defconfig
@@ -1,5 +1,3 @@
1CONFIG_DEFAULT_HOSTNAME="ARCLinux"
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
4CONFIG_POSIX_MQUEUE=y 2CONFIG_POSIX_MQUEUE=y
5# CONFIG_CROSS_MEMORY_ATTACH is not set 3# CONFIG_CROSS_MEMORY_ATTACH is not set
@@ -64,7 +62,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
64CONFIG_MOUSE_SERIAL=y 62CONFIG_MOUSE_SERIAL=y
65CONFIG_MOUSE_SYNAPTICS_USB=y 63CONFIG_MOUSE_SYNAPTICS_USB=y
66# CONFIG_LEGACY_PTYS is not set 64# CONFIG_LEGACY_PTYS is not set
67# CONFIG_DEVKMEM is not set
68CONFIG_SERIAL_8250=y 65CONFIG_SERIAL_8250=y
69CONFIG_SERIAL_8250_CONSOLE=y 66CONFIG_SERIAL_8250_CONSOLE=y
70CONFIG_SERIAL_8250_DW=y 67CONFIG_SERIAL_8250_DW=y
diff --git a/arch/arc/configs/axs103_smp_defconfig b/arch/arc/configs/axs103_smp_defconfig
index eba07f468654..6b0c0cfd5c30 100644
--- a/arch/arc/configs/axs103_smp_defconfig
+++ b/arch/arc/configs/axs103_smp_defconfig
@@ -1,5 +1,3 @@
1CONFIG_DEFAULT_HOSTNAME="ARCLinux"
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
4CONFIG_POSIX_MQUEUE=y 2CONFIG_POSIX_MQUEUE=y
5# CONFIG_CROSS_MEMORY_ATTACH is not set 3# CONFIG_CROSS_MEMORY_ATTACH is not set
@@ -65,7 +63,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
65CONFIG_MOUSE_SERIAL=y 63CONFIG_MOUSE_SERIAL=y
66CONFIG_MOUSE_SYNAPTICS_USB=y 64CONFIG_MOUSE_SYNAPTICS_USB=y
67# CONFIG_LEGACY_PTYS is not set 65# CONFIG_LEGACY_PTYS is not set
68# CONFIG_DEVKMEM is not set
69CONFIG_SERIAL_8250=y 66CONFIG_SERIAL_8250=y
70CONFIG_SERIAL_8250_CONSOLE=y 67CONFIG_SERIAL_8250_CONSOLE=y
71CONFIG_SERIAL_8250_DW=y 68CONFIG_SERIAL_8250_DW=y
diff --git a/arch/arc/configs/haps_hs_defconfig b/arch/arc/configs/haps_hs_defconfig
index 098b19fbaa51..240dd2cd5148 100644
--- a/arch/arc/configs/haps_hs_defconfig
+++ b/arch/arc/configs/haps_hs_defconfig
@@ -1,4 +1,3 @@
1CONFIG_DEFAULT_HOSTNAME="ARCLinux"
2# CONFIG_SWAP is not set 1# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y 2CONFIG_SYSVIPC=y
4CONFIG_POSIX_MQUEUE=y 3CONFIG_POSIX_MQUEUE=y
@@ -57,7 +56,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
57# CONFIG_SERIO_SERPORT is not set 56# CONFIG_SERIO_SERPORT is not set
58CONFIG_SERIO_ARC_PS2=y 57CONFIG_SERIO_ARC_PS2=y
59# CONFIG_LEGACY_PTYS is not set 58# CONFIG_LEGACY_PTYS is not set
60# CONFIG_DEVKMEM is not set
61CONFIG_SERIAL_8250=y 59CONFIG_SERIAL_8250=y
62CONFIG_SERIAL_8250_CONSOLE=y 60CONFIG_SERIAL_8250_CONSOLE=y
63CONFIG_SERIAL_8250_NR_UARTS=1 61CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arc/configs/haps_hs_smp_defconfig b/arch/arc/configs/haps_hs_smp_defconfig
index 0104c404d897..14ae7e5acc7c 100644
--- a/arch/arc/configs/haps_hs_smp_defconfig
+++ b/arch/arc/configs/haps_hs_smp_defconfig
@@ -1,4 +1,3 @@
1CONFIG_DEFAULT_HOSTNAME="ARCLinux"
2# CONFIG_SWAP is not set 1# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y 2CONFIG_SYSVIPC=y
4CONFIG_POSIX_MQUEUE=y 3CONFIG_POSIX_MQUEUE=y
@@ -60,7 +59,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
60# CONFIG_SERIO_SERPORT is not set 59# CONFIG_SERIO_SERPORT is not set
61CONFIG_SERIO_ARC_PS2=y 60CONFIG_SERIO_ARC_PS2=y
62# CONFIG_LEGACY_PTYS is not set 61# CONFIG_LEGACY_PTYS is not set
63# CONFIG_DEVKMEM is not set
64CONFIG_SERIAL_8250=y 62CONFIG_SERIAL_8250=y
65CONFIG_SERIAL_8250_CONSOLE=y 63CONFIG_SERIAL_8250_CONSOLE=y
66CONFIG_SERIAL_8250_NR_UARTS=1 64CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arc/configs/hsdk_defconfig b/arch/arc/configs/hsdk_defconfig
index 6491be0ddbc9..1dec2b4bc5e6 100644
--- a/arch/arc/configs/hsdk_defconfig
+++ b/arch/arc/configs/hsdk_defconfig
@@ -1,4 +1,3 @@
1CONFIG_DEFAULT_HOSTNAME="ARCLinux"
2CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
3# CONFIG_CROSS_MEMORY_ATTACH is not set 2# CONFIG_CROSS_MEMORY_ATTACH is not set
4CONFIG_NO_HZ_IDLE=y 3CONFIG_NO_HZ_IDLE=y
diff --git a/arch/arc/configs/nps_defconfig b/arch/arc/configs/nps_defconfig
index 7c9c706ae7f6..31ba224bbfb4 100644
--- a/arch/arc/configs/nps_defconfig
+++ b/arch/arc/configs/nps_defconfig
@@ -59,7 +59,6 @@ CONFIG_NETCONSOLE=y
59# CONFIG_INPUT_MOUSE is not set 59# CONFIG_INPUT_MOUSE is not set
60# CONFIG_SERIO is not set 60# CONFIG_SERIO is not set
61# CONFIG_LEGACY_PTYS is not set 61# CONFIG_LEGACY_PTYS is not set
62# CONFIG_DEVKMEM is not set
63CONFIG_SERIAL_8250=y 62CONFIG_SERIAL_8250=y
64CONFIG_SERIAL_8250_CONSOLE=y 63CONFIG_SERIAL_8250_CONSOLE=y
65CONFIG_SERIAL_8250_NR_UARTS=1 64CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arc/configs/nsim_700_defconfig b/arch/arc/configs/nsim_700_defconfig
index 99e05cf63fca..8e0b8b134cd9 100644
--- a/arch/arc/configs/nsim_700_defconfig
+++ b/arch/arc/configs/nsim_700_defconfig
@@ -1,5 +1,4 @@
1# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_DEFAULT_HOSTNAME="ARCLinux"
3# CONFIG_SWAP is not set 2# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y 3CONFIG_SYSVIPC=y
5CONFIG_POSIX_MQUEUE=y 4CONFIG_POSIX_MQUEUE=y
@@ -44,7 +43,6 @@ CONFIG_LXT_PHY=y
44# CONFIG_INPUT_MOUSE is not set 43# CONFIG_INPUT_MOUSE is not set
45# CONFIG_SERIO is not set 44# CONFIG_SERIO is not set
46# CONFIG_LEGACY_PTYS is not set 45# CONFIG_LEGACY_PTYS is not set
47# CONFIG_DEVKMEM is not set
48CONFIG_SERIAL_ARC=y 46CONFIG_SERIAL_ARC=y
49CONFIG_SERIAL_ARC_CONSOLE=y 47CONFIG_SERIAL_ARC_CONSOLE=y
50# CONFIG_HW_RANDOM is not set 48# CONFIG_HW_RANDOM is not set
diff --git a/arch/arc/configs/nsim_hs_defconfig b/arch/arc/configs/nsim_hs_defconfig
index 0dc4f9b737e7..739b90e5e893 100644
--- a/arch/arc/configs/nsim_hs_defconfig
+++ b/arch/arc/configs/nsim_hs_defconfig
@@ -1,5 +1,4 @@
1# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_DEFAULT_HOSTNAME="ARCLinux"
3# CONFIG_SWAP is not set 2# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y 3CONFIG_SYSVIPC=y
5CONFIG_POSIX_MQUEUE=y 4CONFIG_POSIX_MQUEUE=y
@@ -45,7 +44,6 @@ CONFIG_DEVTMPFS=y
45# CONFIG_INPUT_MOUSE is not set 44# CONFIG_INPUT_MOUSE is not set
46# CONFIG_SERIO is not set 45# CONFIG_SERIO is not set
47# CONFIG_LEGACY_PTYS is not set 46# CONFIG_LEGACY_PTYS is not set
48# CONFIG_DEVKMEM is not set
49CONFIG_SERIAL_ARC=y 47CONFIG_SERIAL_ARC=y
50CONFIG_SERIAL_ARC_CONSOLE=y 48CONFIG_SERIAL_ARC_CONSOLE=y
51# CONFIG_HW_RANDOM is not set 49# CONFIG_HW_RANDOM is not set
diff --git a/arch/arc/configs/nsim_hs_smp_defconfig b/arch/arc/configs/nsim_hs_smp_defconfig
index be3c30a15e54..b5895bdf3a93 100644
--- a/arch/arc/configs/nsim_hs_smp_defconfig
+++ b/arch/arc/configs/nsim_hs_smp_defconfig
@@ -1,5 +1,4 @@
1# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_DEFAULT_HOSTNAME="ARCLinux"
3# CONFIG_SWAP is not set 2# CONFIG_SWAP is not set
4# CONFIG_CROSS_MEMORY_ATTACH is not set 3# CONFIG_CROSS_MEMORY_ATTACH is not set
5CONFIG_HIGH_RES_TIMERS=y 4CONFIG_HIGH_RES_TIMERS=y
@@ -44,7 +43,6 @@ CONFIG_DEVTMPFS=y
44# CONFIG_INPUT_MOUSE is not set 43# CONFIG_INPUT_MOUSE is not set
45# CONFIG_SERIO is not set 44# CONFIG_SERIO is not set
46# CONFIG_LEGACY_PTYS is not set 45# CONFIG_LEGACY_PTYS is not set
47# CONFIG_DEVKMEM is not set
48CONFIG_SERIAL_ARC=y 46CONFIG_SERIAL_ARC=y
49CONFIG_SERIAL_ARC_CONSOLE=y 47CONFIG_SERIAL_ARC_CONSOLE=y
50# CONFIG_HW_RANDOM is not set 48# CONFIG_HW_RANDOM is not set
diff --git a/arch/arc/configs/nsimosci_defconfig b/arch/arc/configs/nsimosci_defconfig
index 3a74b9b21772..f14eeff7d308 100644
--- a/arch/arc/configs/nsimosci_defconfig
+++ b/arch/arc/configs/nsimosci_defconfig
@@ -1,5 +1,4 @@
1# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_DEFAULT_HOSTNAME="ARCLinux"
3# CONFIG_SWAP is not set 2# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y 3CONFIG_SYSVIPC=y
5# CONFIG_CROSS_MEMORY_ATTACH is not set 4# CONFIG_CROSS_MEMORY_ATTACH is not set
@@ -48,7 +47,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
48# CONFIG_SERIO_SERPORT is not set 47# CONFIG_SERIO_SERPORT is not set
49CONFIG_SERIO_ARC_PS2=y 48CONFIG_SERIO_ARC_PS2=y
50# CONFIG_LEGACY_PTYS is not set 49# CONFIG_LEGACY_PTYS is not set
51# CONFIG_DEVKMEM is not set
52CONFIG_SERIAL_8250=y 50CONFIG_SERIAL_8250=y
53CONFIG_SERIAL_8250_CONSOLE=y 51CONFIG_SERIAL_8250_CONSOLE=y
54CONFIG_SERIAL_8250_NR_UARTS=1 52CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arc/configs/nsimosci_hs_defconfig b/arch/arc/configs/nsimosci_hs_defconfig
index ea2834b4dc1d..025298a48305 100644
--- a/arch/arc/configs/nsimosci_hs_defconfig
+++ b/arch/arc/configs/nsimosci_hs_defconfig
@@ -1,5 +1,4 @@
1# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_DEFAULT_HOSTNAME="ARCLinux"
3# CONFIG_SWAP is not set 2# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y 3CONFIG_SYSVIPC=y
5# CONFIG_CROSS_MEMORY_ATTACH is not set 4# CONFIG_CROSS_MEMORY_ATTACH is not set
@@ -47,7 +46,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
47# CONFIG_SERIO_SERPORT is not set 46# CONFIG_SERIO_SERPORT is not set
48CONFIG_SERIO_ARC_PS2=y 47CONFIG_SERIO_ARC_PS2=y
49# CONFIG_LEGACY_PTYS is not set 48# CONFIG_LEGACY_PTYS is not set
50# CONFIG_DEVKMEM is not set
51CONFIG_SERIAL_8250=y 49CONFIG_SERIAL_8250=y
52CONFIG_SERIAL_8250_CONSOLE=y 50CONFIG_SERIAL_8250_CONSOLE=y
53CONFIG_SERIAL_8250_NR_UARTS=1 51CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arc/configs/nsimosci_hs_smp_defconfig b/arch/arc/configs/nsimosci_hs_smp_defconfig
index 80a5a1b4924b..df7b77b13b82 100644
--- a/arch/arc/configs/nsimosci_hs_smp_defconfig
+++ b/arch/arc/configs/nsimosci_hs_smp_defconfig
@@ -1,4 +1,3 @@
1CONFIG_DEFAULT_HOSTNAME="ARCLinux"
2# CONFIG_SWAP is not set 1# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y 2CONFIG_SYSVIPC=y
4# CONFIG_CROSS_MEMORY_ATTACH is not set 3# CONFIG_CROSS_MEMORY_ATTACH is not set
@@ -58,7 +57,6 @@ CONFIG_MOUSE_PS2_TOUCHKIT=y
58# CONFIG_SERIO_SERPORT is not set 57# CONFIG_SERIO_SERPORT is not set
59CONFIG_SERIO_ARC_PS2=y 58CONFIG_SERIO_ARC_PS2=y
60# CONFIG_LEGACY_PTYS is not set 59# CONFIG_LEGACY_PTYS is not set
61# CONFIG_DEVKMEM is not set
62CONFIG_SERIAL_8250=y 60CONFIG_SERIAL_8250=y
63CONFIG_SERIAL_8250_CONSOLE=y 61CONFIG_SERIAL_8250_CONSOLE=y
64CONFIG_SERIAL_8250_NR_UARTS=1 62CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arc/configs/tb10x_defconfig b/arch/arc/configs/tb10x_defconfig
index 2cc87f909747..a7f65313f84a 100644
--- a/arch/arc/configs/tb10x_defconfig
+++ b/arch/arc/configs/tb10x_defconfig
@@ -57,7 +57,6 @@ CONFIG_STMMAC_ETH=y
57# CONFIG_SERIO is not set 57# CONFIG_SERIO is not set
58# CONFIG_VT is not set 58# CONFIG_VT is not set
59# CONFIG_LEGACY_PTYS is not set 59# CONFIG_LEGACY_PTYS is not set
60# CONFIG_DEVKMEM is not set
61CONFIG_SERIAL_8250=y 60CONFIG_SERIAL_8250=y
62CONFIG_SERIAL_8250_CONSOLE=y 61CONFIG_SERIAL_8250_CONSOLE=y
63CONFIG_SERIAL_8250_NR_UARTS=1 62CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arc/configs/vdk_hs38_defconfig b/arch/arc/configs/vdk_hs38_defconfig
index f629493929ea..db47c3541f15 100644
--- a/arch/arc/configs/vdk_hs38_defconfig
+++ b/arch/arc/configs/vdk_hs38_defconfig
@@ -1,5 +1,4 @@
1# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_DEFAULT_HOSTNAME="ARCLinux"
3# CONFIG_CROSS_MEMORY_ATTACH is not set 2# CONFIG_CROSS_MEMORY_ATTACH is not set
4CONFIG_HIGH_RES_TIMERS=y 3CONFIG_HIGH_RES_TIMERS=y
5CONFIG_IKCONFIG=y 4CONFIG_IKCONFIG=y
@@ -53,7 +52,6 @@ CONFIG_NATIONAL_PHY=y
53CONFIG_MOUSE_PS2_TOUCHKIT=y 52CONFIG_MOUSE_PS2_TOUCHKIT=y
54CONFIG_SERIO_ARC_PS2=y 53CONFIG_SERIO_ARC_PS2=y
55# CONFIG_LEGACY_PTYS is not set 54# CONFIG_LEGACY_PTYS is not set
56# CONFIG_DEVKMEM is not set
57CONFIG_SERIAL_8250=y 55CONFIG_SERIAL_8250=y
58CONFIG_SERIAL_8250_CONSOLE=y 56CONFIG_SERIAL_8250_CONSOLE=y
59CONFIG_SERIAL_8250_DW=y 57CONFIG_SERIAL_8250_DW=y
diff --git a/arch/arc/configs/vdk_hs38_smp_defconfig b/arch/arc/configs/vdk_hs38_smp_defconfig
index 21f0ca26a05d..a8ac5e917d9a 100644
--- a/arch/arc/configs/vdk_hs38_smp_defconfig
+++ b/arch/arc/configs/vdk_hs38_smp_defconfig
@@ -1,5 +1,4 @@
1# CONFIG_LOCALVERSION_AUTO is not set 1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_DEFAULT_HOSTNAME="ARCLinux"
3# CONFIG_CROSS_MEMORY_ATTACH is not set 2# CONFIG_CROSS_MEMORY_ATTACH is not set
4CONFIG_HIGH_RES_TIMERS=y 3CONFIG_HIGH_RES_TIMERS=y
5CONFIG_IKCONFIG=y 4CONFIG_IKCONFIG=y
diff --git a/arch/arc/include/asm/atomic.h b/arch/arc/include/asm/atomic.h
index 4e0072730241..158af079838d 100644
--- a/arch/arc/include/asm/atomic.h
+++ b/arch/arc/include/asm/atomic.h
@@ -84,7 +84,7 @@ static inline int atomic_fetch_##op(int i, atomic_t *v) \
84 "1: llock %[orig], [%[ctr]] \n" \ 84 "1: llock %[orig], [%[ctr]] \n" \
85 " " #asm_op " %[val], %[orig], %[i] \n" \ 85 " " #asm_op " %[val], %[orig], %[i] \n" \
86 " scond %[val], [%[ctr]] \n" \ 86 " scond %[val], [%[ctr]] \n" \
87 " \n" \ 87 " bnz 1b \n" \
88 : [val] "=&r" (val), \ 88 : [val] "=&r" (val), \
89 [orig] "=&r" (orig) \ 89 [orig] "=&r" (orig) \
90 : [ctr] "r" (&v->counter), \ 90 : [ctr] "r" (&v->counter), \
diff --git a/arch/arc/include/asm/dma-mapping.h b/arch/arc/include/asm/dma-mapping.h
new file mode 100644
index 000000000000..c946c0a83e76
--- /dev/null
+++ b/arch/arc/include/asm/dma-mapping.h
@@ -0,0 +1,13 @@
1// SPDX-License-Identifier: GPL-2.0
2// (C) 2018 Synopsys, Inc. (www.synopsys.com)
3
4#ifndef ASM_ARC_DMA_MAPPING_H
5#define ASM_ARC_DMA_MAPPING_H
6
7#include <asm-generic/dma-mapping.h>
8
9void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
10 const struct iommu_ops *iommu, bool coherent);
11#define arch_setup_dma_ops arch_setup_dma_ops
12
13#endif
diff --git a/arch/arc/kernel/troubleshoot.c b/arch/arc/kernel/troubleshoot.c
index 783b20354f8b..e8d9fb452346 100644
--- a/arch/arc/kernel/troubleshoot.c
+++ b/arch/arc/kernel/troubleshoot.c
@@ -83,9 +83,6 @@ done:
83static void show_faulting_vma(unsigned long address, char *buf) 83static void show_faulting_vma(unsigned long address, char *buf)
84{ 84{
85 struct vm_area_struct *vma; 85 struct vm_area_struct *vma;
86 struct inode *inode;
87 unsigned long ino = 0;
88 dev_t dev = 0;
89 char *nm = buf; 86 char *nm = buf;
90 struct mm_struct *active_mm = current->active_mm; 87 struct mm_struct *active_mm = current->active_mm;
91 88
@@ -99,12 +96,10 @@ static void show_faulting_vma(unsigned long address, char *buf)
99 * if the container VMA is not found 96 * if the container VMA is not found
100 */ 97 */
101 if (vma && (vma->vm_start <= address)) { 98 if (vma && (vma->vm_start <= address)) {
102 struct file *file = vma->vm_file; 99 if (vma->vm_file) {
103 if (file) { 100 nm = file_path(vma->vm_file, buf, PAGE_SIZE - 1);
104 nm = file_path(file, buf, PAGE_SIZE - 1); 101 if (IS_ERR(nm))
105 inode = file_inode(vma->vm_file); 102 nm = "?";
106 dev = inode->i_sb->s_dev;
107 ino = inode->i_ino;
108 } 103 }
109 pr_info(" @off 0x%lx in [%s]\n" 104 pr_info(" @off 0x%lx in [%s]\n"
110 " VMA: 0x%08lx to 0x%08lx\n", 105 " VMA: 0x%08lx to 0x%08lx\n",
diff --git a/arch/arc/mm/cache.c b/arch/arc/mm/cache.c
index 25c631942500..f2701c13a66b 100644
--- a/arch/arc/mm/cache.c
+++ b/arch/arc/mm/cache.c
@@ -65,7 +65,7 @@ char *arc_cache_mumbojumbo(int c, char *buf, int len)
65 65
66 n += scnprintf(buf + n, len - n, "Peripherals\t: %#lx%s%s\n", 66 n += scnprintf(buf + n, len - n, "Peripherals\t: %#lx%s%s\n",
67 perip_base, 67 perip_base,
68 IS_AVAIL3(ioc_exists, ioc_enable, ", IO-Coherency ")); 68 IS_AVAIL3(ioc_exists, ioc_enable, ", IO-Coherency (per-device) "));
69 69
70 return buf; 70 return buf;
71} 71}
@@ -897,15 +897,6 @@ static void __dma_cache_wback_slc(phys_addr_t start, unsigned long sz)
897} 897}
898 898
899/* 899/*
900 * DMA ops for systems with IOC
901 * IOC hardware snoops all DMA traffic keeping the caches consistent with
902 * memory - eliding need for any explicit cache maintenance of DMA buffers
903 */
904static void __dma_cache_wback_inv_ioc(phys_addr_t start, unsigned long sz) {}
905static void __dma_cache_inv_ioc(phys_addr_t start, unsigned long sz) {}
906static void __dma_cache_wback_ioc(phys_addr_t start, unsigned long sz) {}
907
908/*
909 * Exported DMA API 900 * Exported DMA API
910 */ 901 */
911void dma_cache_wback_inv(phys_addr_t start, unsigned long sz) 902void dma_cache_wback_inv(phys_addr_t start, unsigned long sz)
@@ -1153,6 +1144,19 @@ noinline void __init arc_ioc_setup(void)
1153{ 1144{
1154 unsigned int ioc_base, mem_sz; 1145 unsigned int ioc_base, mem_sz;
1155 1146
1147 /*
1148 * As for today we don't support both IOC and ZONE_HIGHMEM enabled
1149 * simultaneously. This happens because as of today IOC aperture covers
1150 * only ZONE_NORMAL (low mem) and any dma transactions outside this
1151 * region won't be HW coherent.
1152 * If we want to use both IOC and ZONE_HIGHMEM we can use
1153 * bounce_buffer to handle dma transactions to HIGHMEM.
1154 * Also it is possible to modify dma_direct cache ops or increase IOC
1155 * aperture size if we are planning to use HIGHMEM without PAE.
1156 */
1157 if (IS_ENABLED(CONFIG_HIGHMEM))
1158 panic("IOC and HIGHMEM can't be used simultaneously");
1159
1156 /* Flush + invalidate + disable L1 dcache */ 1160 /* Flush + invalidate + disable L1 dcache */
1157 __dc_disable(); 1161 __dc_disable();
1158 1162
@@ -1264,11 +1268,7 @@ void __init arc_cache_init_master(void)
1264 if (is_isa_arcv2() && ioc_enable) 1268 if (is_isa_arcv2() && ioc_enable)
1265 arc_ioc_setup(); 1269 arc_ioc_setup();
1266 1270
1267 if (is_isa_arcv2() && ioc_enable) { 1271 if (is_isa_arcv2() && l2_line_sz && slc_enable) {
1268 __dma_cache_wback_inv = __dma_cache_wback_inv_ioc;
1269 __dma_cache_inv = __dma_cache_inv_ioc;
1270 __dma_cache_wback = __dma_cache_wback_ioc;
1271 } else if (is_isa_arcv2() && l2_line_sz && slc_enable) {
1272 __dma_cache_wback_inv = __dma_cache_wback_inv_slc; 1272 __dma_cache_wback_inv = __dma_cache_wback_inv_slc;
1273 __dma_cache_inv = __dma_cache_inv_slc; 1273 __dma_cache_inv = __dma_cache_inv_slc;
1274 __dma_cache_wback = __dma_cache_wback_slc; 1274 __dma_cache_wback = __dma_cache_wback_slc;
@@ -1277,6 +1277,12 @@ void __init arc_cache_init_master(void)
1277 __dma_cache_inv = __dma_cache_inv_l1; 1277 __dma_cache_inv = __dma_cache_inv_l1;
1278 __dma_cache_wback = __dma_cache_wback_l1; 1278 __dma_cache_wback = __dma_cache_wback_l1;
1279 } 1279 }
1280 /*
1281 * In case of IOC (say IOC+SLC case), pointers above could still be set
1282 * but end up not being relevant as the first function in chain is not
1283 * called at all for @dma_direct_ops
1284 * arch_sync_dma_for_cpu() -> dma_cache_*() -> __dma_cache_*()
1285 */
1280} 1286}
1281 1287
1282void __ref arc_cache_init(void) 1288void __ref arc_cache_init(void)
diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c
index ec47e6079f5d..c75d5c3470e3 100644
--- a/arch/arc/mm/dma.c
+++ b/arch/arc/mm/dma.c
@@ -6,20 +6,17 @@
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8 8
9/*
10 * DMA Coherent API Notes
11 *
12 * I/O is inherently non-coherent on ARC. So a coherent DMA buffer is
13 * implemented by accessing it using a kernel virtual address, with
14 * Cache bit off in the TLB entry.
15 *
16 * The default DMA address == Phy address which is 0x8000_0000 based.
17 */
18
19#include <linux/dma-noncoherent.h> 9#include <linux/dma-noncoherent.h>
20#include <asm/cache.h> 10#include <asm/cache.h>
21#include <asm/cacheflush.h> 11#include <asm/cacheflush.h>
22 12
13/*
14 * ARCH specific callbacks for generic noncoherent DMA ops (dma/noncoherent.c)
15 * - hardware IOC not available (or "dma-coherent" not set for device in DT)
16 * - But still handle both coherent and non-coherent requests from caller
17 *
18 * For DMA coherent hardware (IOC) generic code suffices
19 */
23void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, 20void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
24 gfp_t gfp, unsigned long attrs) 21 gfp_t gfp, unsigned long attrs)
25{ 22{
@@ -27,42 +24,29 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
27 struct page *page; 24 struct page *page;
28 phys_addr_t paddr; 25 phys_addr_t paddr;
29 void *kvaddr; 26 void *kvaddr;
30 int need_coh = 1, need_kvaddr = 0; 27 bool need_coh = !(attrs & DMA_ATTR_NON_CONSISTENT);
31
32 page = alloc_pages(gfp, order);
33 if (!page)
34 return NULL;
35 28
36 /* 29 /*
37 * IOC relies on all data (even coherent DMA data) being in cache 30 * __GFP_HIGHMEM flag is cleared by upper layer functions
38 * Thus allocate normal cached memory 31 * (in include/linux/dma-mapping.h) so we should never get a
39 * 32 * __GFP_HIGHMEM here.
40 * The gains with IOC are two pronged:
41 * -For streaming data, elides need for cache maintenance, saving
42 * cycles in flush code, and bus bandwidth as all the lines of a
43 * buffer need to be flushed out to memory
44 * -For coherent data, Read/Write to buffers terminate early in cache
45 * (vs. always going to memory - thus are faster)
46 */ 33 */
47 if ((is_isa_arcv2() && ioc_enable) || 34 BUG_ON(gfp & __GFP_HIGHMEM);
48 (attrs & DMA_ATTR_NON_CONSISTENT))
49 need_coh = 0;
50 35
51 /* 36 page = alloc_pages(gfp, order);
52 * - A coherent buffer needs MMU mapping to enforce non-cachability 37 if (!page)
53 * - A highmem page needs a virtual handle (hence MMU mapping) 38 return NULL;
54 * independent of cachability
55 */
56 if (PageHighMem(page) || need_coh)
57 need_kvaddr = 1;
58 39
59 /* This is linear addr (0x8000_0000 based) */ 40 /* This is linear addr (0x8000_0000 based) */
60 paddr = page_to_phys(page); 41 paddr = page_to_phys(page);
61 42
62 *dma_handle = paddr; 43 *dma_handle = paddr;
63 44
64 /* This is kernel Virtual address (0x7000_0000 based) */ 45 /*
65 if (need_kvaddr) { 46 * A coherent buffer needs MMU mapping to enforce non-cachability.
47 * kvaddr is kernel Virtual address (0x7000_0000 based).
48 */
49 if (need_coh) {
66 kvaddr = ioremap_nocache(paddr, size); 50 kvaddr = ioremap_nocache(paddr, size);
67 if (kvaddr == NULL) { 51 if (kvaddr == NULL) {
68 __free_pages(page, order); 52 __free_pages(page, order);
@@ -93,12 +77,8 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr,
93{ 77{
94 phys_addr_t paddr = dma_handle; 78 phys_addr_t paddr = dma_handle;
95 struct page *page = virt_to_page(paddr); 79 struct page *page = virt_to_page(paddr);
96 int is_non_coh = 1;
97
98 is_non_coh = (attrs & DMA_ATTR_NON_CONSISTENT) ||
99 (is_isa_arcv2() && ioc_enable);
100 80
101 if (PageHighMem(page) || !is_non_coh) 81 if (!(attrs & DMA_ATTR_NON_CONSISTENT))
102 iounmap((void __force __iomem *)vaddr); 82 iounmap((void __force __iomem *)vaddr);
103 83
104 __free_pages(page, get_order(size)); 84 __free_pages(page, get_order(size));
@@ -185,3 +165,23 @@ void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
185 break; 165 break;
186 } 166 }
187} 167}
168
169/*
170 * Plug in coherent or noncoherent dma ops
171 */
172void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
173 const struct iommu_ops *iommu, bool coherent)
174{
175 /*
176 * IOC hardware snoops all DMA traffic keeping the caches consistent
177 * with memory - eliding need for any explicit cache maintenance of
178 * DMA buffers - so we can use dma_direct cache ops.
179 */
180 if (is_isa_arcv2() && ioc_enable && coherent) {
181 set_dma_ops(dev, &dma_direct_ops);
182 dev_info(dev, "use dma_direct_ops cache ops\n");
183 } else {
184 set_dma_ops(dev, &dma_noncoherent_ops);
185 dev_info(dev, "use dma_noncoherent_ops cache ops\n");
186 }
187}
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index ed94cf7e3157..d1516f85f25d 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -43,12 +43,12 @@ ifeq ($(CONFIG_CPU_BIG_ENDIAN),y)
43KBUILD_CPPFLAGS += -mbig-endian 43KBUILD_CPPFLAGS += -mbig-endian
44CHECKFLAGS += -D__ARMEB__ 44CHECKFLAGS += -D__ARMEB__
45AS += -EB 45AS += -EB
46LDFLAGS += -EB 46KBUILD_LDFLAGS += -EB
47else 47else
48KBUILD_CPPFLAGS += -mlittle-endian 48KBUILD_CPPFLAGS += -mlittle-endian
49CHECKFLAGS += -D__ARMEL__ 49CHECKFLAGS += -D__ARMEL__
50AS += -EL 50AS += -EL
51LDFLAGS += -EL 51KBUILD_LDFLAGS += -EL
52endif 52endif
53 53
54# 54#
diff --git a/arch/arm/boot/dts/am335x-osd3358-sm-red.dts b/arch/arm/boot/dts/am335x-osd3358-sm-red.dts
index 4d969013f99a..4d969013f99a 100755..100644
--- a/arch/arm/boot/dts/am335x-osd3358-sm-red.dts
+++ b/arch/arm/boot/dts/am335x-osd3358-sm-red.dts
diff --git a/arch/arm/boot/dts/am4372.dtsi b/arch/arm/boot/dts/am4372.dtsi
index f0cbd86312dc..d4b7c59eec68 100644
--- a/arch/arm/boot/dts/am4372.dtsi
+++ b/arch/arm/boot/dts/am4372.dtsi
@@ -469,6 +469,7 @@
469 ti,hwmods = "rtc"; 469 ti,hwmods = "rtc";
470 clocks = <&clk_32768_ck>; 470 clocks = <&clk_32768_ck>;
471 clock-names = "int-clk"; 471 clock-names = "int-clk";
472 system-power-controller;
472 status = "disabled"; 473 status = "disabled";
473 }; 474 };
474 475
diff --git a/arch/arm/boot/dts/imx23-evk.dts b/arch/arm/boot/dts/imx23-evk.dts
index 9fb47724b9c1..ad2ae25b7b4d 100644
--- a/arch/arm/boot/dts/imx23-evk.dts
+++ b/arch/arm/boot/dts/imx23-evk.dts
@@ -13,6 +13,43 @@
13 reg = <0x40000000 0x08000000>; 13 reg = <0x40000000 0x08000000>;
14 }; 14 };
15 15
16 reg_vddio_sd0: regulator-vddio-sd0 {
17 compatible = "regulator-fixed";
18 regulator-name = "vddio-sd0";
19 regulator-min-microvolt = <3300000>;
20 regulator-max-microvolt = <3300000>;
21 gpio = <&gpio1 29 0>;
22 };
23
24 reg_lcd_3v3: regulator-lcd-3v3 {
25 compatible = "regulator-fixed";
26 regulator-name = "lcd-3v3";
27 regulator-min-microvolt = <3300000>;
28 regulator-max-microvolt = <3300000>;
29 gpio = <&gpio1 18 0>;
30 enable-active-high;
31 };
32
33 reg_lcd_5v: regulator-lcd-5v {
34 compatible = "regulator-fixed";
35 regulator-name = "lcd-5v";
36 regulator-min-microvolt = <5000000>;
37 regulator-max-microvolt = <5000000>;
38 };
39
40 panel {
41 compatible = "sii,43wvf1g";
42 backlight = <&backlight_display>;
43 dvdd-supply = <&reg_lcd_3v3>;
44 avdd-supply = <&reg_lcd_5v>;
45
46 port {
47 panel_in: endpoint {
48 remote-endpoint = <&display_out>;
49 };
50 };
51 };
52
16 apb@80000000 { 53 apb@80000000 {
17 apbh@80000000 { 54 apbh@80000000 {
18 gpmi-nand@8000c000 { 55 gpmi-nand@8000c000 {
@@ -52,31 +89,11 @@
52 lcdif@80030000 { 89 lcdif@80030000 {
53 pinctrl-names = "default"; 90 pinctrl-names = "default";
54 pinctrl-0 = <&lcdif_24bit_pins_a>; 91 pinctrl-0 = <&lcdif_24bit_pins_a>;
55 lcd-supply = <&reg_lcd_3v3>;
56 display = <&display0>;
57 status = "okay"; 92 status = "okay";
58 93
59 display0: display0 { 94 port {
60 bits-per-pixel = <32>; 95 display_out: endpoint {
61 bus-width = <24>; 96 remote-endpoint = <&panel_in>;
62
63 display-timings {
64 native-mode = <&timing0>;
65 timing0: timing0 {
66 clock-frequency = <9200000>;
67 hactive = <480>;
68 vactive = <272>;
69 hback-porch = <15>;
70 hfront-porch = <8>;
71 vback-porch = <12>;
72 vfront-porch = <4>;
73 hsync-len = <1>;
74 vsync-len = <1>;
75 hsync-active = <0>;
76 vsync-active = <0>;
77 de-active = <1>;
78 pixelclk-active = <0>;
79 };
80 }; 97 };
81 }; 98 };
82 }; 99 };
@@ -118,32 +135,7 @@
118 }; 135 };
119 }; 136 };
120 137
121 regulators { 138 backlight_display: backlight {
122 compatible = "simple-bus";
123 #address-cells = <1>;
124 #size-cells = <0>;
125
126 reg_vddio_sd0: regulator@0 {
127 compatible = "regulator-fixed";
128 reg = <0>;
129 regulator-name = "vddio-sd0";
130 regulator-min-microvolt = <3300000>;
131 regulator-max-microvolt = <3300000>;
132 gpio = <&gpio1 29 0>;
133 };
134
135 reg_lcd_3v3: regulator@1 {
136 compatible = "regulator-fixed";
137 reg = <1>;
138 regulator-name = "lcd-3v3";
139 regulator-min-microvolt = <3300000>;
140 regulator-max-microvolt = <3300000>;
141 gpio = <&gpio1 18 0>;
142 enable-active-high;
143 };
144 };
145
146 backlight {
147 compatible = "pwm-backlight"; 139 compatible = "pwm-backlight";
148 pwms = <&pwm 2 5000000>; 140 pwms = <&pwm 2 5000000>;
149 brightness-levels = <0 4 8 16 32 64 128 255>; 141 brightness-levels = <0 4 8 16 32 64 128 255>;
diff --git a/arch/arm/boot/dts/imx28-evk.dts b/arch/arm/boot/dts/imx28-evk.dts
index 6b0ae667640f..93ab5bdfe068 100644
--- a/arch/arm/boot/dts/imx28-evk.dts
+++ b/arch/arm/boot/dts/imx28-evk.dts
@@ -13,6 +13,87 @@
13 reg = <0x40000000 0x08000000>; 13 reg = <0x40000000 0x08000000>;
14 }; 14 };
15 15
16
17 reg_3p3v: regulator-3p3v {
18 compatible = "regulator-fixed";
19 regulator-name = "3P3V";
20 regulator-min-microvolt = <3300000>;
21 regulator-max-microvolt = <3300000>;
22 regulator-always-on;
23 };
24
25 reg_vddio_sd0: regulator-vddio-sd0 {
26 compatible = "regulator-fixed";
27 regulator-name = "vddio-sd0";
28 regulator-min-microvolt = <3300000>;
29 regulator-max-microvolt = <3300000>;
30 gpio = <&gpio3 28 0>;
31 };
32
33 reg_fec_3v3: regulator-fec-3v3 {
34 compatible = "regulator-fixed";
35 regulator-name = "fec-3v3";
36 regulator-min-microvolt = <3300000>;
37 regulator-max-microvolt = <3300000>;
38 gpio = <&gpio2 15 0>;
39 };
40
41 reg_usb0_vbus: regulator-usb0-vbus {
42 compatible = "regulator-fixed";
43 regulator-name = "usb0_vbus";
44 regulator-min-microvolt = <5000000>;
45 regulator-max-microvolt = <5000000>;
46 gpio = <&gpio3 9 0>;
47 enable-active-high;
48 };
49
50 reg_usb1_vbus: regulator-usb1-vbus {
51 compatible = "regulator-fixed";
52 regulator-name = "usb1_vbus";
53 regulator-min-microvolt = <5000000>;
54 regulator-max-microvolt = <5000000>;
55 gpio = <&gpio3 8 0>;
56 enable-active-high;
57 };
58
59 reg_lcd_3v3: regulator-lcd-3v3 {
60 compatible = "regulator-fixed";
61 regulator-name = "lcd-3v3";
62 regulator-min-microvolt = <3300000>;
63 regulator-max-microvolt = <3300000>;
64 gpio = <&gpio3 30 0>;
65 enable-active-high;
66 };
67
68 reg_can_3v3: regulator-can-3v3 {
69 compatible = "regulator-fixed";
70 regulator-name = "can-3v3";
71 regulator-min-microvolt = <3300000>;
72 regulator-max-microvolt = <3300000>;
73 gpio = <&gpio2 13 0>;
74 enable-active-high;
75 };
76
77 reg_lcd_5v: regulator-lcd-5v {
78 compatible = "regulator-fixed";
79 regulator-name = "lcd-5v";
80 regulator-min-microvolt = <5000000>;
81 regulator-max-microvolt = <5000000>;
82 };
83
84 panel {
85 compatible = "sii,43wvf1g";
86 backlight = <&backlight_display>;
87 dvdd-supply = <&reg_lcd_3v3>;
88 avdd-supply = <&reg_lcd_5v>;
89
90 port {
91 panel_in: endpoint {
92 remote-endpoint = <&display_out>;
93 };
94 };
95 };
96
16 apb@80000000 { 97 apb@80000000 {
17 apbh@80000000 { 98 apbh@80000000 {
18 gpmi-nand@8000c000 { 99 gpmi-nand@8000c000 {
@@ -116,31 +197,11 @@
116 pinctrl-names = "default"; 197 pinctrl-names = "default";
117 pinctrl-0 = <&lcdif_24bit_pins_a 198 pinctrl-0 = <&lcdif_24bit_pins_a
118 &lcdif_pins_evk>; 199 &lcdif_pins_evk>;
119 lcd-supply = <&reg_lcd_3v3>;
120 display = <&display0>;
121 status = "okay"; 200 status = "okay";
122 201
123 display0: display0 { 202 port {
124 bits-per-pixel = <32>; 203 display_out: endpoint {
125 bus-width = <24>; 204 remote-endpoint = <&panel_in>;
126
127 display-timings {
128 native-mode = <&timing0>;
129 timing0: timing0 {
130 clock-frequency = <33500000>;
131 hactive = <800>;
132 vactive = <480>;
133 hback-porch = <89>;
134 hfront-porch = <164>;
135 vback-porch = <23>;
136 vfront-porch = <10>;
137 hsync-len = <10>;
138 vsync-len = <10>;
139 hsync-active = <0>;
140 vsync-active = <0>;
141 de-active = <1>;
142 pixelclk-active = <0>;
143 };
144 }; 205 };
145 }; 206 };
146 }; 207 };
@@ -269,80 +330,6 @@
269 }; 330 };
270 }; 331 };
271 332
272 regulators {
273 compatible = "simple-bus";
274 #address-cells = <1>;
275 #size-cells = <0>;
276
277 reg_3p3v: regulator@0 {
278 compatible = "regulator-fixed";
279 reg = <0>;
280 regulator-name = "3P3V";
281 regulator-min-microvolt = <3300000>;
282 regulator-max-microvolt = <3300000>;
283 regulator-always-on;
284 };
285
286 reg_vddio_sd0: regulator@1 {
287 compatible = "regulator-fixed";
288 reg = <1>;
289 regulator-name = "vddio-sd0";
290 regulator-min-microvolt = <3300000>;
291 regulator-max-microvolt = <3300000>;
292 gpio = <&gpio3 28 0>;
293 };
294
295 reg_fec_3v3: regulator@2 {
296 compatible = "regulator-fixed";
297 reg = <2>;
298 regulator-name = "fec-3v3";
299 regulator-min-microvolt = <3300000>;
300 regulator-max-microvolt = <3300000>;
301 gpio = <&gpio2 15 0>;
302 };
303
304 reg_usb0_vbus: regulator@3 {
305 compatible = "regulator-fixed";
306 reg = <3>;
307 regulator-name = "usb0_vbus";
308 regulator-min-microvolt = <5000000>;
309 regulator-max-microvolt = <5000000>;
310 gpio = <&gpio3 9 0>;
311 enable-active-high;
312 };
313
314 reg_usb1_vbus: regulator@4 {
315 compatible = "regulator-fixed";
316 reg = <4>;
317 regulator-name = "usb1_vbus";
318 regulator-min-microvolt = <5000000>;
319 regulator-max-microvolt = <5000000>;
320 gpio = <&gpio3 8 0>;
321 enable-active-high;
322 };
323
324 reg_lcd_3v3: regulator@5 {
325 compatible = "regulator-fixed";
326 reg = <5>;
327 regulator-name = "lcd-3v3";
328 regulator-min-microvolt = <3300000>;
329 regulator-max-microvolt = <3300000>;
330 gpio = <&gpio3 30 0>;
331 enable-active-high;
332 };
333
334 reg_can_3v3: regulator@6 {
335 compatible = "regulator-fixed";
336 reg = <6>;
337 regulator-name = "can-3v3";
338 regulator-min-microvolt = <3300000>;
339 regulator-max-microvolt = <3300000>;
340 gpio = <&gpio2 13 0>;
341 enable-active-high;
342 };
343
344 };
345
346 sound { 333 sound {
347 compatible = "fsl,imx28-evk-sgtl5000", 334 compatible = "fsl,imx28-evk-sgtl5000",
348 "fsl,mxs-audio-sgtl5000"; 335 "fsl,mxs-audio-sgtl5000";
@@ -363,7 +350,7 @@
363 }; 350 };
364 }; 351 };
365 352
366 backlight { 353 backlight_display: backlight {
367 compatible = "pwm-backlight"; 354 compatible = "pwm-backlight";
368 pwms = <&pwm 2 5000000>; 355 pwms = <&pwm 2 5000000>;
369 brightness-levels = <0 4 8 16 32 64 128 255>; 356 brightness-levels = <0 4 8 16 32 64 128 255>;
diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index 7cbc2ffa4b3a..7234e8330a57 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -126,10 +126,14 @@
126 interrupt-names = "msi"; 126 interrupt-names = "msi";
127 #interrupt-cells = <1>; 127 #interrupt-cells = <1>;
128 interrupt-map-mask = <0 0 0 0x7>; 128 interrupt-map-mask = <0 0 0 0x7>;
129 interrupt-map = <0 0 0 1 &intc GIC_SPI 122 IRQ_TYPE_LEVEL_HIGH>, 129 /*
130 <0 0 0 2 &intc GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>, 130 * Reference manual lists pci irqs incorrectly
131 <0 0 0 3 &intc GIC_SPI 124 IRQ_TYPE_LEVEL_HIGH>, 131 * Real hardware ordering is same as imx6: D+MSI, C, B, A
132 <0 0 0 4 &intc GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>; 132 */
133 interrupt-map = <0 0 0 1 &intc GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>,
134 <0 0 0 2 &intc GIC_SPI 124 IRQ_TYPE_LEVEL_HIGH>,
135 <0 0 0 3 &intc GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>,
136 <0 0 0 4 &intc GIC_SPI 122 IRQ_TYPE_LEVEL_HIGH>;
133 clocks = <&clks IMX7D_PCIE_CTRL_ROOT_CLK>, 137 clocks = <&clks IMX7D_PCIE_CTRL_ROOT_CLK>,
134 <&clks IMX7D_PLL_ENET_MAIN_100M_CLK>, 138 <&clks IMX7D_PLL_ENET_MAIN_100M_CLK>,
135 <&clks IMX7D_PCIE_PHY_ROOT_CLK>; 139 <&clks IMX7D_PCIE_PHY_ROOT_CLK>;
diff --git a/arch/arm/boot/dts/omap4-droid4-xt894.dts b/arch/arm/boot/dts/omap4-droid4-xt894.dts
index 12d6822f0057..04758a2a87f0 100644
--- a/arch/arm/boot/dts/omap4-droid4-xt894.dts
+++ b/arch/arm/boot/dts/omap4-droid4-xt894.dts
@@ -354,7 +354,7 @@
354&mmc2 { 354&mmc2 {
355 vmmc-supply = <&vsdio>; 355 vmmc-supply = <&vsdio>;
356 bus-width = <8>; 356 bus-width = <8>;
357 non-removable; 357 ti,non-removable;
358}; 358};
359 359
360&mmc3 { 360&mmc3 {
@@ -621,15 +621,6 @@
621 OMAP4_IOPAD(0x10c, PIN_INPUT | MUX_MODE1) /* abe_mcbsp3_fsx */ 621 OMAP4_IOPAD(0x10c, PIN_INPUT | MUX_MODE1) /* abe_mcbsp3_fsx */
622 >; 622 >;
623 }; 623 };
624};
625
626&omap4_pmx_wkup {
627 usb_gpio_mux_sel2: pinmux_usb_gpio_mux_sel2_pins {
628 /* gpio_wk0 */
629 pinctrl-single,pins = <
630 OMAP4_IOPAD(0x040, PIN_OUTPUT_PULLDOWN | MUX_MODE3)
631 >;
632 };
633 624
634 vibrator_direction_pin: pinmux_vibrator_direction_pin { 625 vibrator_direction_pin: pinmux_vibrator_direction_pin {
635 pinctrl-single,pins = < 626 pinctrl-single,pins = <
@@ -644,6 +635,15 @@
644 }; 635 };
645}; 636};
646 637
638&omap4_pmx_wkup {
639 usb_gpio_mux_sel2: pinmux_usb_gpio_mux_sel2_pins {
640 /* gpio_wk0 */
641 pinctrl-single,pins = <
642 OMAP4_IOPAD(0x040, PIN_OUTPUT_PULLDOWN | MUX_MODE3)
643 >;
644 };
645};
646
647/* 647/*
648 * As uart1 is wired to mdm6600 with rts and cts, we can use the cts pin for 648 * As uart1 is wired to mdm6600 with rts and cts, we can use the cts pin for
649 * uart1 wakeirq. 649 * uart1 wakeirq.
diff --git a/arch/arm/configs/imx_v6_v7_defconfig b/arch/arm/configs/imx_v6_v7_defconfig
index e2c127608bcc..7eca43ff69bb 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -257,6 +257,7 @@ CONFIG_IMX_IPUV3_CORE=y
257CONFIG_DRM=y 257CONFIG_DRM=y
258CONFIG_DRM_PANEL_LVDS=y 258CONFIG_DRM_PANEL_LVDS=y
259CONFIG_DRM_PANEL_SIMPLE=y 259CONFIG_DRM_PANEL_SIMPLE=y
260CONFIG_DRM_PANEL_SEIKO_43WVF1G=y
260CONFIG_DRM_DW_HDMI_AHB_AUDIO=m 261CONFIG_DRM_DW_HDMI_AHB_AUDIO=m
261CONFIG_DRM_DW_HDMI_CEC=y 262CONFIG_DRM_DW_HDMI_CEC=y
262CONFIG_DRM_IMX=y 263CONFIG_DRM_IMX=y
diff --git a/arch/arm/configs/mxs_defconfig b/arch/arm/configs/mxs_defconfig
index 148226e36152..7b8212857535 100644
--- a/arch/arm/configs/mxs_defconfig
+++ b/arch/arm/configs/mxs_defconfig
@@ -95,6 +95,7 @@ CONFIG_MFD_MXS_LRADC=y
95CONFIG_REGULATOR=y 95CONFIG_REGULATOR=y
96CONFIG_REGULATOR_FIXED_VOLTAGE=y 96CONFIG_REGULATOR_FIXED_VOLTAGE=y
97CONFIG_DRM=y 97CONFIG_DRM=y
98CONFIG_DRM_PANEL_SEIKO_43WVF1G=y
98CONFIG_DRM_MXSFB=y 99CONFIG_DRM_MXSFB=y
99CONFIG_FB_MODE_HELPERS=y 100CONFIG_FB_MODE_HELPERS=y
100CONFIG_BACKLIGHT_LCD_SUPPORT=y 101CONFIG_BACKLIGHT_LCD_SUPPORT=y
diff --git a/arch/arm/configs/versatile_defconfig b/arch/arm/configs/versatile_defconfig
index df68dc4056e5..5282324c7cef 100644
--- a/arch/arm/configs/versatile_defconfig
+++ b/arch/arm/configs/versatile_defconfig
@@ -5,19 +5,19 @@ CONFIG_HIGH_RES_TIMERS=y
5CONFIG_LOG_BUF_SHIFT=14 5CONFIG_LOG_BUF_SHIFT=14
6CONFIG_BLK_DEV_INITRD=y 6CONFIG_BLK_DEV_INITRD=y
7CONFIG_SLAB=y 7CONFIG_SLAB=y
8CONFIG_MODULES=y
9CONFIG_MODULE_UNLOAD=y
10CONFIG_PARTITION_ADVANCED=y
11# CONFIG_ARCH_MULTI_V7 is not set 8# CONFIG_ARCH_MULTI_V7 is not set
12CONFIG_ARCH_VERSATILE=y 9CONFIG_ARCH_VERSATILE=y
13CONFIG_AEABI=y 10CONFIG_AEABI=y
14CONFIG_OABI_COMPAT=y 11CONFIG_OABI_COMPAT=y
15CONFIG_CMA=y
16CONFIG_ZBOOT_ROM_TEXT=0x0 12CONFIG_ZBOOT_ROM_TEXT=0x0
17CONFIG_ZBOOT_ROM_BSS=0x0 13CONFIG_ZBOOT_ROM_BSS=0x0
18CONFIG_CMDLINE="root=1f03 mem=32M" 14CONFIG_CMDLINE="root=1f03 mem=32M"
19CONFIG_FPE_NWFPE=y 15CONFIG_FPE_NWFPE=y
20CONFIG_VFP=y 16CONFIG_VFP=y
17CONFIG_MODULES=y
18CONFIG_MODULE_UNLOAD=y
19CONFIG_PARTITION_ADVANCED=y
20CONFIG_CMA=y
21CONFIG_NET=y 21CONFIG_NET=y
22CONFIG_PACKET=y 22CONFIG_PACKET=y
23CONFIG_UNIX=y 23CONFIG_UNIX=y
@@ -59,6 +59,7 @@ CONFIG_GPIO_PL061=y
59CONFIG_DRM=y 59CONFIG_DRM=y
60CONFIG_DRM_PANEL_ARM_VERSATILE=y 60CONFIG_DRM_PANEL_ARM_VERSATILE=y
61CONFIG_DRM_PANEL_SIMPLE=y 61CONFIG_DRM_PANEL_SIMPLE=y
62CONFIG_DRM_DUMB_VGA_DAC=y
62CONFIG_DRM_PL111=y 63CONFIG_DRM_PL111=y
63CONFIG_FB_MODE_HELPERS=y 64CONFIG_FB_MODE_HELPERS=y
64CONFIG_BACKLIGHT_LCD_SUPPORT=y 65CONFIG_BACKLIGHT_LCD_SUPPORT=y
@@ -89,9 +90,10 @@ CONFIG_NFSD=y
89CONFIG_NFSD_V3=y 90CONFIG_NFSD_V3=y
90CONFIG_NLS_CODEPAGE_850=m 91CONFIG_NLS_CODEPAGE_850=m
91CONFIG_NLS_ISO8859_1=m 92CONFIG_NLS_ISO8859_1=m
93CONFIG_FONTS=y
94CONFIG_FONT_ACORN_8x8=y
95CONFIG_DEBUG_FS=y
92CONFIG_MAGIC_SYSRQ=y 96CONFIG_MAGIC_SYSRQ=y
93CONFIG_DEBUG_KERNEL=y 97CONFIG_DEBUG_KERNEL=y
94CONFIG_DEBUG_USER=y 98CONFIG_DEBUG_USER=y
95CONFIG_DEBUG_LL=y 99CONFIG_DEBUG_LL=y
96CONFIG_FONTS=y
97CONFIG_FONT_ACORN_8x8=y
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 79906cecb091..3ad482d2f1eb 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -223,7 +223,6 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
223 struct kvm_vcpu_events *events); 223 struct kvm_vcpu_events *events);
224 224
225#define KVM_ARCH_WANT_MMU_NOTIFIER 225#define KVM_ARCH_WANT_MMU_NOTIFIER
226int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
227int kvm_unmap_hva_range(struct kvm *kvm, 226int kvm_unmap_hva_range(struct kvm *kvm,
228 unsigned long start, unsigned long end); 227 unsigned long start, unsigned long end);
229void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); 228void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 2ceffd85dd3d..cd65ea4e9c54 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -2161,6 +2161,37 @@ static int of_dev_hwmod_lookup(struct device_node *np,
2161} 2161}
2162 2162
2163/** 2163/**
2164 * omap_hwmod_fix_mpu_rt_idx - fix up mpu_rt_idx register offsets
2165 *
2166 * @oh: struct omap_hwmod *
2167 * @np: struct device_node *
2168 *
2169 * Fix up module register offsets for modules with mpu_rt_idx.
2170 * Only needed for cpsw with interconnect target module defined
2171 * in device tree while still using legacy hwmod platform data
2172 * for rev, sysc and syss registers.
2173 *
2174 * Can be removed when all cpsw hwmod platform data has been
2175 * dropped.
2176 */
2177static void omap_hwmod_fix_mpu_rt_idx(struct omap_hwmod *oh,
2178 struct device_node *np,
2179 struct resource *res)
2180{
2181 struct device_node *child = NULL;
2182 int error;
2183
2184 child = of_get_next_child(np, child);
2185 if (!child)
2186 return;
2187
2188 error = of_address_to_resource(child, oh->mpu_rt_idx, res);
2189 if (error)
2190 pr_err("%s: error mapping mpu_rt_idx: %i\n",
2191 __func__, error);
2192}
2193
2194/**
2164 * omap_hwmod_parse_module_range - map module IO range from device tree 2195 * omap_hwmod_parse_module_range - map module IO range from device tree
2165 * @oh: struct omap_hwmod * 2196 * @oh: struct omap_hwmod *
2166 * @np: struct device_node * 2197 * @np: struct device_node *
@@ -2220,7 +2251,13 @@ int omap_hwmod_parse_module_range(struct omap_hwmod *oh,
2220 size = be32_to_cpup(ranges); 2251 size = be32_to_cpup(ranges);
2221 2252
2222 pr_debug("omap_hwmod: %s %s at 0x%llx size 0x%llx\n", 2253 pr_debug("omap_hwmod: %s %s at 0x%llx size 0x%llx\n",
2223 oh->name, np->name, base, size); 2254 oh ? oh->name : "", np->name, base, size);
2255
2256 if (oh && oh->mpu_rt_idx) {
2257 omap_hwmod_fix_mpu_rt_idx(oh, np, res);
2258
2259 return 0;
2260 }
2224 2261
2225 res->start = base; 2262 res->start = base;
2226 res->end = base + size - 1; 2263 res->end = base + size - 1;
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index fafd3d7f9f8c..8ca926522026 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -17,6 +17,7 @@ config ARCH_ROCKCHIP
17 select ARM_GLOBAL_TIMER 17 select ARM_GLOBAL_TIMER
18 select CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK 18 select CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK
19 select ZONE_DMA if ARM_LPAE 19 select ZONE_DMA if ARM_LPAE
20 select PM
20 help 21 help
21 Support for Rockchip's Cortex-A9 Single-to-Quad-Core-SoCs 22 Support for Rockchip's Cortex-A9 Single-to-Quad-Core-SoCs
22 containing the RK2928, RK30xx and RK31xx series. 23 containing the RK2928, RK30xx and RK31xx series.
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 29e75b47becd..1b1a0e95c751 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -763,7 +763,6 @@ config NEED_PER_CPU_EMBED_FIRST_CHUNK
763 763
764config HOLES_IN_ZONE 764config HOLES_IN_ZONE
765 def_bool y 765 def_bool y
766 depends on NUMA
767 766
768source kernel/Kconfig.hz 767source kernel/Kconfig.hz
769 768
diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms
index 35f2e6e1be23..393d2b524284 100644
--- a/arch/arm64/Kconfig.platforms
+++ b/arch/arm64/Kconfig.platforms
@@ -158,6 +158,7 @@ config ARCH_ROCKCHIP
158 select GPIOLIB 158 select GPIOLIB
159 select PINCTRL 159 select PINCTRL
160 select PINCTRL_ROCKCHIP 160 select PINCTRL_ROCKCHIP
161 select PM
161 select ROCKCHIP_TIMER 162 select ROCKCHIP_TIMER
162 help 163 help
163 This enables support for the ARMv8 based Rockchip chipsets, 164 This enables support for the ARMv8 based Rockchip chipsets,
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index efe61a2e4b5e..106039d25e2f 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -62,14 +62,14 @@ CHECKFLAGS += -D__AARCH64EB__
62AS += -EB 62AS += -EB
63# Prefer the baremetal ELF build target, but not all toolchains include 63# Prefer the baremetal ELF build target, but not all toolchains include
64# it so fall back to the standard linux version if needed. 64# it so fall back to the standard linux version if needed.
65LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb) 65KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb)
66UTS_MACHINE := aarch64_be 66UTS_MACHINE := aarch64_be
67else 67else
68KBUILD_CPPFLAGS += -mlittle-endian 68KBUILD_CPPFLAGS += -mlittle-endian
69CHECKFLAGS += -D__AARCH64EL__ 69CHECKFLAGS += -D__AARCH64EL__
70AS += -EL 70AS += -EL
71# Same as above, prefer ELF but fall back to linux target if needed. 71# Same as above, prefer ELF but fall back to linux target if needed.
72LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux) 72KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux)
73UTS_MACHINE := aarch64 73UTS_MACHINE := aarch64
74endif 74endif
75 75
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts b/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts
index ceffc40810ee..48daec7f78ba 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts
@@ -46,6 +46,7 @@
46 pinctrl-0 = <&mmc0_pins>; 46 pinctrl-0 = <&mmc0_pins>;
47 vmmc-supply = <&reg_cldo1>; 47 vmmc-supply = <&reg_cldo1>;
48 cd-gpios = <&pio 5 6 GPIO_ACTIVE_LOW>; 48 cd-gpios = <&pio 5 6 GPIO_ACTIVE_LOW>;
49 bus-width = <4>;
49 status = "okay"; 50 status = "okay";
50}; 51};
51 52
@@ -56,6 +57,7 @@
56 vqmmc-supply = <&reg_bldo2>; 57 vqmmc-supply = <&reg_bldo2>;
57 non-removable; 58 non-removable;
58 cap-mmc-hw-reset; 59 cap-mmc-hw-reset;
60 bus-width = <8>;
59 status = "okay"; 61 status = "okay";
60}; 62};
61 63
diff --git a/arch/arm64/boot/dts/arm/juno-r1.dts b/arch/arm64/boot/dts/arm/juno-r1.dts
index 2c5db03f226c..b2b7ced633cf 100644
--- a/arch/arm64/boot/dts/arm/juno-r1.dts
+++ b/arch/arm64/boot/dts/arm/juno-r1.dts
@@ -63,7 +63,7 @@
63 }; 63 };
64 64
65 idle-states { 65 idle-states {
66 entry-method = "arm,psci"; 66 entry-method = "psci";
67 67
68 CPU_SLEEP_0: cpu-sleep-0 { 68 CPU_SLEEP_0: cpu-sleep-0 {
69 compatible = "arm,idle-state"; 69 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/arm/juno-r2.dts b/arch/arm64/boot/dts/arm/juno-r2.dts
index c51950f4a1b6..ab77adb4f3c2 100644
--- a/arch/arm64/boot/dts/arm/juno-r2.dts
+++ b/arch/arm64/boot/dts/arm/juno-r2.dts
@@ -63,7 +63,7 @@
63 }; 63 };
64 64
65 idle-states { 65 idle-states {
66 entry-method = "arm,psci"; 66 entry-method = "psci";
67 67
68 CPU_SLEEP_0: cpu-sleep-0 { 68 CPU_SLEEP_0: cpu-sleep-0 {
69 compatible = "arm,idle-state"; 69 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/arm/juno.dts b/arch/arm64/boot/dts/arm/juno.dts
index 2b2bf39c30ef..1fb5c5a0f32e 100644
--- a/arch/arm64/boot/dts/arm/juno.dts
+++ b/arch/arm64/boot/dts/arm/juno.dts
@@ -62,7 +62,7 @@
62 }; 62 };
63 63
64 idle-states { 64 idle-states {
65 entry-method = "arm,psci"; 65 entry-method = "psci";
66 66
67 CPU_SLEEP_0: cpu-sleep-0 { 67 CPU_SLEEP_0: cpu-sleep-0 {
68 compatible = "arm,idle-state"; 68 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi
index 4c558a2133e2..68ac78c4564d 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi
@@ -43,7 +43,7 @@
43 * PSCI node is not added default, U-boot will add missing 43 * PSCI node is not added default, U-boot will add missing
44 * parts if it determines to use PSCI. 44 * parts if it determines to use PSCI.
45 */ 45 */
46 entry-method = "arm,psci"; 46 entry-method = "psci";
47 47
48 CPU_PH20: cpu-ph20 { 48 CPU_PH20: cpu-ph20 {
49 compatible = "arm,idle-state"; 49 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
index b9f5d2ff4ff2..7881e3d81a9a 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
@@ -87,7 +87,7 @@
87 * PSCI node is not added default, U-boot will add missing 87 * PSCI node is not added default, U-boot will add missing
88 * parts if it determines to use PSCI. 88 * parts if it determines to use PSCI.
89 */ 89 */
90 entry-method = "arm,psci"; 90 entry-method = "psci";
91 91
92 CPU_PH20: cpu-ph20 { 92 CPU_PH20: cpu-ph20 {
93 compatible = "arm,idle-state"; 93 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
index 65ce1c3cb568..ef83786b8b90 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
@@ -83,7 +83,7 @@
83 * PSCI node is not added default, U-boot will add missing 83 * PSCI node is not added default, U-boot will add missing
84 * parts if it determines to use PSCI. 84 * parts if it determines to use PSCI.
85 */ 85 */
86 entry-method = "arm,psci"; 86 entry-method = "psci";
87 87
88 CPU_PH20: cpu-ph20 { 88 CPU_PH20: cpu-ph20 {
89 compatible = "arm,idle-state"; 89 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/mediatek/mt2712e.dtsi b/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
index 6d8532af8346..75cc0f7cc088 100644
--- a/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
@@ -119,7 +119,7 @@
119 }; 119 };
120 120
121 idle-states { 121 idle-states {
122 entry-method = "arm,psci"; 122 entry-method = "psci";
123 123
124 CPU_SLEEP_0: cpu-sleep-0 { 124 CPU_SLEEP_0: cpu-sleep-0 {
125 compatible = "arm,idle-state"; 125 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/sprd/sc9860.dtsi b/arch/arm64/boot/dts/sprd/sc9860.dtsi
index 3f5160d2f130..48f5928ed45c 100644
--- a/arch/arm64/boot/dts/sprd/sc9860.dtsi
+++ b/arch/arm64/boot/dts/sprd/sc9860.dtsi
@@ -114,7 +114,7 @@
114 }; 114 };
115 115
116 idle-states{ 116 idle-states{
117 entry-method = "arm,psci"; 117 entry-method = "psci";
118 118
119 CORE_PD: core_pd { 119 CORE_PD: core_pd {
120 compatible = "arm,idle-state"; 120 compatible = "arm,idle-state";
diff --git a/arch/arm64/boot/dts/xilinx/zynqmp.dtsi b/arch/arm64/boot/dts/xilinx/zynqmp.dtsi
index a091e6f03014..29ce23422acf 100644
--- a/arch/arm64/boot/dts/xilinx/zynqmp.dtsi
+++ b/arch/arm64/boot/dts/xilinx/zynqmp.dtsi
@@ -58,7 +58,7 @@
58 }; 58 };
59 59
60 idle-states { 60 idle-states {
61 entry-method = "arm,psci"; 61 entry-method = "psci";
62 62
63 CPU_SLEEP_0: cpu-sleep-0 { 63 CPU_SLEEP_0: cpu-sleep-0 {
64 compatible = "arm,idle-state"; 64 compatible = "arm,idle-state";
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index f67e8d5e93ad..db8d364f8476 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -38,6 +38,7 @@ CONFIG_ARCH_BCM_IPROC=y
38CONFIG_ARCH_BERLIN=y 38CONFIG_ARCH_BERLIN=y
39CONFIG_ARCH_BRCMSTB=y 39CONFIG_ARCH_BRCMSTB=y
40CONFIG_ARCH_EXYNOS=y 40CONFIG_ARCH_EXYNOS=y
41CONFIG_ARCH_K3=y
41CONFIG_ARCH_LAYERSCAPE=y 42CONFIG_ARCH_LAYERSCAPE=y
42CONFIG_ARCH_LG1K=y 43CONFIG_ARCH_LG1K=y
43CONFIG_ARCH_HISI=y 44CONFIG_ARCH_HISI=y
@@ -605,6 +606,8 @@ CONFIG_ARCH_TEGRA_132_SOC=y
605CONFIG_ARCH_TEGRA_210_SOC=y 606CONFIG_ARCH_TEGRA_210_SOC=y
606CONFIG_ARCH_TEGRA_186_SOC=y 607CONFIG_ARCH_TEGRA_186_SOC=y
607CONFIG_ARCH_TEGRA_194_SOC=y 608CONFIG_ARCH_TEGRA_194_SOC=y
609CONFIG_ARCH_K3_AM6_SOC=y
610CONFIG_SOC_TI=y
608CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND=y 611CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND=y
609CONFIG_EXTCON_USB_GPIO=y 612CONFIG_EXTCON_USB_GPIO=y
610CONFIG_EXTCON_USBC_CROS_EC=y 613CONFIG_EXTCON_USBC_CROS_EC=y
diff --git a/arch/arm64/crypto/ghash-ce-glue.c b/arch/arm64/crypto/ghash-ce-glue.c
index 6e9f33d14930..067d8937d5af 100644
--- a/arch/arm64/crypto/ghash-ce-glue.c
+++ b/arch/arm64/crypto/ghash-ce-glue.c
@@ -417,7 +417,7 @@ static int gcm_encrypt(struct aead_request *req)
417 __aes_arm64_encrypt(ctx->aes_key.key_enc, tag, iv, nrounds); 417 __aes_arm64_encrypt(ctx->aes_key.key_enc, tag, iv, nrounds);
418 put_unaligned_be32(2, iv + GCM_IV_SIZE); 418 put_unaligned_be32(2, iv + GCM_IV_SIZE);
419 419
420 while (walk.nbytes >= AES_BLOCK_SIZE) { 420 while (walk.nbytes >= (2 * AES_BLOCK_SIZE)) {
421 int blocks = walk.nbytes / AES_BLOCK_SIZE; 421 int blocks = walk.nbytes / AES_BLOCK_SIZE;
422 u8 *dst = walk.dst.virt.addr; 422 u8 *dst = walk.dst.virt.addr;
423 u8 *src = walk.src.virt.addr; 423 u8 *src = walk.src.virt.addr;
@@ -437,11 +437,18 @@ static int gcm_encrypt(struct aead_request *req)
437 NULL); 437 NULL);
438 438
439 err = skcipher_walk_done(&walk, 439 err = skcipher_walk_done(&walk,
440 walk.nbytes % AES_BLOCK_SIZE); 440 walk.nbytes % (2 * AES_BLOCK_SIZE));
441 } 441 }
442 if (walk.nbytes) 442 if (walk.nbytes) {
443 __aes_arm64_encrypt(ctx->aes_key.key_enc, ks, iv, 443 __aes_arm64_encrypt(ctx->aes_key.key_enc, ks, iv,
444 nrounds); 444 nrounds);
445 if (walk.nbytes > AES_BLOCK_SIZE) {
446 crypto_inc(iv, AES_BLOCK_SIZE);
447 __aes_arm64_encrypt(ctx->aes_key.key_enc,
448 ks + AES_BLOCK_SIZE, iv,
449 nrounds);
450 }
451 }
445 } 452 }
446 453
447 /* handle the tail */ 454 /* handle the tail */
@@ -545,7 +552,7 @@ static int gcm_decrypt(struct aead_request *req)
545 __aes_arm64_encrypt(ctx->aes_key.key_enc, tag, iv, nrounds); 552 __aes_arm64_encrypt(ctx->aes_key.key_enc, tag, iv, nrounds);
546 put_unaligned_be32(2, iv + GCM_IV_SIZE); 553 put_unaligned_be32(2, iv + GCM_IV_SIZE);
547 554
548 while (walk.nbytes >= AES_BLOCK_SIZE) { 555 while (walk.nbytes >= (2 * AES_BLOCK_SIZE)) {
549 int blocks = walk.nbytes / AES_BLOCK_SIZE; 556 int blocks = walk.nbytes / AES_BLOCK_SIZE;
550 u8 *dst = walk.dst.virt.addr; 557 u8 *dst = walk.dst.virt.addr;
551 u8 *src = walk.src.virt.addr; 558 u8 *src = walk.src.virt.addr;
@@ -564,11 +571,21 @@ static int gcm_decrypt(struct aead_request *req)
564 } while (--blocks > 0); 571 } while (--blocks > 0);
565 572
566 err = skcipher_walk_done(&walk, 573 err = skcipher_walk_done(&walk,
567 walk.nbytes % AES_BLOCK_SIZE); 574 walk.nbytes % (2 * AES_BLOCK_SIZE));
568 } 575 }
569 if (walk.nbytes) 576 if (walk.nbytes) {
577 if (walk.nbytes > AES_BLOCK_SIZE) {
578 u8 *iv2 = iv + AES_BLOCK_SIZE;
579
580 memcpy(iv2, iv, AES_BLOCK_SIZE);
581 crypto_inc(iv2, AES_BLOCK_SIZE);
582
583 __aes_arm64_encrypt(ctx->aes_key.key_enc, iv2,
584 iv2, nrounds);
585 }
570 __aes_arm64_encrypt(ctx->aes_key.key_enc, iv, iv, 586 __aes_arm64_encrypt(ctx->aes_key.key_enc, iv, iv,
571 nrounds); 587 nrounds);
588 }
572 } 589 }
573 590
574 /* handle the tail */ 591 /* handle the tail */
diff --git a/arch/arm64/crypto/sm4-ce-glue.c b/arch/arm64/crypto/sm4-ce-glue.c
index b7fb5274b250..0c4fc223f225 100644
--- a/arch/arm64/crypto/sm4-ce-glue.c
+++ b/arch/arm64/crypto/sm4-ce-glue.c
@@ -69,5 +69,5 @@ static void __exit sm4_ce_mod_fini(void)
69 crypto_unregister_alg(&sm4_ce_alg); 69 crypto_unregister_alg(&sm4_ce_alg);
70} 70}
71 71
72module_cpu_feature_match(SM3, sm4_ce_mod_init); 72module_cpu_feature_match(SM4, sm4_ce_mod_init);
73module_exit(sm4_ce_mod_fini); 73module_exit(sm4_ce_mod_fini);
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index f26055f2306e..3d6d7336f871 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -61,8 +61,7 @@ struct kvm_arch {
61 u64 vmid_gen; 61 u64 vmid_gen;
62 u32 vmid; 62 u32 vmid;
63 63
64 /* 1-level 2nd stage table and lock */ 64 /* 1-level 2nd stage table, protected by kvm->mmu_lock */
65 spinlock_t pgd_lock;
66 pgd_t *pgd; 65 pgd_t *pgd;
67 66
68 /* VTTBR value associated with above pgd and vmid */ 67 /* VTTBR value associated with above pgd and vmid */
@@ -357,7 +356,6 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
357 struct kvm_vcpu_events *events); 356 struct kvm_vcpu_events *events);
358 357
359#define KVM_ARCH_WANT_MMU_NOTIFIER 358#define KVM_ARCH_WANT_MMU_NOTIFIER
360int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
361int kvm_unmap_hva_range(struct kvm *kvm, 359int kvm_unmap_hva_range(struct kvm *kvm,
362 unsigned long start, unsigned long end); 360 unsigned long start, unsigned long end);
363void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); 361void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index d496ef579859..ca46153d7915 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -98,8 +98,10 @@ static void activate_traps_vhe(struct kvm_vcpu *vcpu)
98 val = read_sysreg(cpacr_el1); 98 val = read_sysreg(cpacr_el1);
99 val |= CPACR_EL1_TTA; 99 val |= CPACR_EL1_TTA;
100 val &= ~CPACR_EL1_ZEN; 100 val &= ~CPACR_EL1_ZEN;
101 if (!update_fp_enabled(vcpu)) 101 if (!update_fp_enabled(vcpu)) {
102 val &= ~CPACR_EL1_FPEN; 102 val &= ~CPACR_EL1_FPEN;
103 __activate_traps_fpsimd32(vcpu);
104 }
103 105
104 write_sysreg(val, cpacr_el1); 106 write_sysreg(val, cpacr_el1);
105 107
@@ -114,8 +116,10 @@ static void __hyp_text __activate_traps_nvhe(struct kvm_vcpu *vcpu)
114 116
115 val = CPTR_EL2_DEFAULT; 117 val = CPTR_EL2_DEFAULT;
116 val |= CPTR_EL2_TTA | CPTR_EL2_TZ; 118 val |= CPTR_EL2_TTA | CPTR_EL2_TZ;
117 if (!update_fp_enabled(vcpu)) 119 if (!update_fp_enabled(vcpu)) {
118 val |= CPTR_EL2_TFP; 120 val |= CPTR_EL2_TFP;
121 __activate_traps_fpsimd32(vcpu);
122 }
119 123
120 write_sysreg(val, cptr_el2); 124 write_sysreg(val, cptr_el2);
121} 125}
@@ -129,7 +133,6 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu)
129 if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE)) 133 if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE))
130 write_sysreg_s(vcpu->arch.vsesr_el2, SYS_VSESR_EL2); 134 write_sysreg_s(vcpu->arch.vsesr_el2, SYS_VSESR_EL2);
131 135
132 __activate_traps_fpsimd32(vcpu);
133 if (has_vhe()) 136 if (has_vhe())
134 activate_traps_vhe(vcpu); 137 activate_traps_vhe(vcpu);
135 else 138 else
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 65f86271f02b..8080c9f489c3 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -985,8 +985,9 @@ int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr)
985 985
986 pmd = READ_ONCE(*pmdp); 986 pmd = READ_ONCE(*pmdp);
987 987
988 /* No-op for empty entry and WARN_ON for valid entry */ 988 if (!pmd_present(pmd))
989 if (!pmd_present(pmd) || !pmd_table(pmd)) { 989 return 1;
990 if (!pmd_table(pmd)) {
990 VM_WARN_ON(!pmd_table(pmd)); 991 VM_WARN_ON(!pmd_table(pmd));
991 return 1; 992 return 1;
992 } 993 }
@@ -1007,8 +1008,9 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr)
1007 1008
1008 pud = READ_ONCE(*pudp); 1009 pud = READ_ONCE(*pudp);
1009 1010
1010 /* No-op for empty entry and WARN_ON for valid entry */ 1011 if (!pud_present(pud))
1011 if (!pud_present(pud) || !pud_table(pud)) { 1012 return 1;
1013 if (!pud_table(pud)) {
1012 VM_WARN_ON(!pud_table(pud)); 1014 VM_WARN_ON(!pud_table(pud));
1013 return 1; 1015 return 1;
1014 } 1016 }
diff --git a/arch/c6x/Makefile b/arch/c6x/Makefile
index 6ab942e6c534..3fe8a948e94c 100644
--- a/arch/c6x/Makefile
+++ b/arch/c6x/Makefile
@@ -23,8 +23,7 @@ ifdef CONFIG_CPU_BIG_ENDIAN
23KBUILD_CFLAGS += -mbig-endian 23KBUILD_CFLAGS += -mbig-endian
24KBUILD_AFLAGS += -mbig-endian 24KBUILD_AFLAGS += -mbig-endian
25LINKFLAGS += -mbig-endian 25LINKFLAGS += -mbig-endian
26KBUILD_LDFLAGS += -mbig-endian 26KBUILD_LDFLAGS += -mbig-endian -EB
27LDFLAGS += -EB
28CHECKFLAGS += -D_BIG_ENDIAN 27CHECKFLAGS += -D_BIG_ENDIAN
29endif 28endif
30 29
diff --git a/arch/h8300/Makefile b/arch/h8300/Makefile
index cc12b162c222..58634e6bae92 100644
--- a/arch/h8300/Makefile
+++ b/arch/h8300/Makefile
@@ -22,7 +22,7 @@ KBUILD_CFLAGS += -mint32 -fno-builtin
22KBUILD_CFLAGS += -D__linux__ 22KBUILD_CFLAGS += -D__linux__
23KBUILD_CFLAGS += -DUTS_SYSNAME=\"uClinux\" 23KBUILD_CFLAGS += -DUTS_SYSNAME=\"uClinux\"
24KBUILD_AFLAGS += $(aflags-y) 24KBUILD_AFLAGS += $(aflags-y)
25LDFLAGS += $(ldflags-y) 25KBUILD_LDFLAGS += $(ldflags-y)
26 26
27CHECKFLAGS += -msize-long 27CHECKFLAGS += -msize-long
28 28
diff --git a/arch/hexagon/Makefile b/arch/hexagon/Makefile
index 2efaa18e995a..4c5858b80f0e 100644
--- a/arch/hexagon/Makefile
+++ b/arch/hexagon/Makefile
@@ -22,9 +22,7 @@ ldflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION})
22 22
23KBUILD_CFLAGS += $(cflags-y) 23KBUILD_CFLAGS += $(cflags-y)
24KBUILD_AFLAGS += $(aflags-y) 24KBUILD_AFLAGS += $(aflags-y)
25 25KBUILD_LDFLAGS += $(ldflags-y)
26# no KBUILD_LDFLAGS?
27LDFLAGS += $(ldflags-y)
28 26
29# Thread-info register will be r19. This value is not configureable; 27# Thread-info register will be r19. This value is not configureable;
30# it is hard-coded in several files. 28# it is hard-coded in several files.
diff --git a/arch/hexagon/include/asm/bitops.h b/arch/hexagon/include/asm/bitops.h
index 5e4a59b3ec1b..2691a1857d20 100644
--- a/arch/hexagon/include/asm/bitops.h
+++ b/arch/hexagon/include/asm/bitops.h
@@ -211,7 +211,7 @@ static inline long ffz(int x)
211 * This is defined the same way as ffs. 211 * This is defined the same way as ffs.
212 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. 212 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
213 */ 213 */
214static inline long fls(int x) 214static inline int fls(int x)
215{ 215{
216 int r; 216 int r;
217 217
@@ -232,7 +232,7 @@ static inline long fls(int x)
232 * the libc and compiler builtin ffs routines, therefore 232 * the libc and compiler builtin ffs routines, therefore
233 * differs in spirit from the above ffz (man ffs). 233 * differs in spirit from the above ffz (man ffs).
234 */ 234 */
235static inline long ffs(int x) 235static inline int ffs(int x)
236{ 236{
237 int r; 237 int r;
238 238
diff --git a/arch/hexagon/kernel/dma.c b/arch/hexagon/kernel/dma.c
index 77459df34e2e..7ebe7ad19d15 100644
--- a/arch/hexagon/kernel/dma.c
+++ b/arch/hexagon/kernel/dma.c
@@ -60,7 +60,7 @@ static void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
60 panic("Can't create %s() memory pool!", __func__); 60 panic("Can't create %s() memory pool!", __func__);
61 else 61 else
62 gen_pool_add(coherent_pool, 62 gen_pool_add(coherent_pool,
63 pfn_to_virt(max_low_pfn), 63 (unsigned long)pfn_to_virt(max_low_pfn),
64 hexagon_coherent_pool_size, -1); 64 hexagon_coherent_pool_size, -1);
65 } 65 }
66 66
diff --git a/arch/m68k/Makefile b/arch/m68k/Makefile
index f0dd9fc84002..997c9f20ea0f 100644
--- a/arch/m68k/Makefile
+++ b/arch/m68k/Makefile
@@ -69,7 +69,7 @@ KBUILD_CFLAGS += -D__uClinux__
69KBUILD_AFLAGS += -D__uClinux__ 69KBUILD_AFLAGS += -D__uClinux__
70endif 70endif
71 71
72LDFLAGS := -m m68kelf 72KBUILD_LDFLAGS := -m m68kelf
73KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/m68k/kernel/module.lds 73KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/m68k/kernel/module.lds
74 74
75ifdef CONFIG_SUN3 75ifdef CONFIG_SUN3
diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index 3534aa6a4dc2..1b083c500b9a 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -98,11 +98,10 @@ static time64_t pmu_read_time(void)
98 98
99 if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) 99 if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
100 return 0; 100 return 0;
101 while (!req.complete) 101 pmu_wait_complete(&req);
102 pmu_poll();
103 102
104 time = (u32)((req.reply[1] << 24) | (req.reply[2] << 16) | 103 time = (u32)((req.reply[0] << 24) | (req.reply[1] << 16) |
105 (req.reply[3] << 8) | req.reply[4]); 104 (req.reply[2] << 8) | req.reply[3]);
106 105
107 return time - RTC_OFFSET; 106 return time - RTC_OFFSET;
108} 107}
@@ -116,8 +115,7 @@ static void pmu_write_time(time64_t time)
116 (data >> 24) & 0xFF, (data >> 16) & 0xFF, 115 (data >> 24) & 0xFF, (data >> 16) & 0xFF,
117 (data >> 8) & 0xFF, data & 0xFF) < 0) 116 (data >> 8) & 0xFF, data & 0xFF) < 0)
118 return; 117 return;
119 while (!req.complete) 118 pmu_wait_complete(&req);
120 pmu_poll();
121} 119}
122 120
123static __u8 pmu_read_pram(int offset) 121static __u8 pmu_read_pram(int offset)
diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
index 70dde040779b..f5453d944ff5 100644
--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -172,7 +172,7 @@ void __init cf_bootmem_alloc(void)
172 high_memory = (void *)_ramend; 172 high_memory = (void *)_ramend;
173 173
174 /* Reserve kernel text/data/bss */ 174 /* Reserve kernel text/data/bss */
175 memblock_reserve(memstart, memstart - _rambase); 175 memblock_reserve(_rambase, memstart - _rambase);
176 176
177 m68k_virt_to_node_shift = fls(_ramend - 1) - 6; 177 m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
178 module_fixup(NULL, __start_fixup, __stop_fixup); 178 module_fixup(NULL, __start_fixup, __stop_fixup);
diff --git a/arch/microblaze/Makefile b/arch/microblaze/Makefile
index 73330360a8e6..4f3ab5707265 100644
--- a/arch/microblaze/Makefile
+++ b/arch/microblaze/Makefile
@@ -40,11 +40,11 @@ CPUFLAGS-$(CONFIG_XILINX_MICROBLAZE0_USE_PCMP_INSTR) += -mxl-pattern-compare
40ifdef CONFIG_CPU_BIG_ENDIAN 40ifdef CONFIG_CPU_BIG_ENDIAN
41KBUILD_CFLAGS += -mbig-endian 41KBUILD_CFLAGS += -mbig-endian
42KBUILD_AFLAGS += -mbig-endian 42KBUILD_AFLAGS += -mbig-endian
43LDFLAGS += -EB 43KBUILD_LDFLAGS += -EB
44else 44else
45KBUILD_CFLAGS += -mlittle-endian 45KBUILD_CFLAGS += -mlittle-endian
46KBUILD_AFLAGS += -mlittle-endian 46KBUILD_AFLAGS += -mlittle-endian
47LDFLAGS += -EL 47KBUILD_LDFLAGS += -EL
48endif 48endif
49 49
50CPUFLAGS-1 += $(call cc-option,-mcpu=v$(CPU_VER)) 50CPUFLAGS-1 += $(call cc-option,-mcpu=v$(CPU_VER))
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 5425df002a6b..d74b3742fa5d 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -309,7 +309,7 @@ endif
309# instead of .eh_frame so we don't discard them. 309# instead of .eh_frame so we don't discard them.
310KBUILD_CFLAGS += -fno-asynchronous-unwind-tables 310KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
311 311
312LDFLAGS += -m $(ld-emul) 312KBUILD_LDFLAGS += -m $(ld-emul)
313 313
314ifdef CONFIG_MIPS 314ifdef CONFIG_MIPS
315CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ 315CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index abe77add8789..3c453a1f1ff1 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -92,7 +92,7 @@ UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS)
92vmlinuzobjs-y += $(obj)/piggy.o 92vmlinuzobjs-y += $(obj)/piggy.o
93 93
94quiet_cmd_zld = LD $@ 94quiet_cmd_zld = LD $@
95 cmd_zld = $(LD) $(LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@ 95 cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@
96quiet_cmd_strip = STRIP $@ 96quiet_cmd_strip = STRIP $@
97 cmd_strip = $(STRIP) -s $@ 97 cmd_strip = $(STRIP) -s $@
98vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr 98vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr
diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index a9af1d2dcd69..2c1c53d12179 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -931,7 +931,6 @@ enum kvm_mips_fault_result kvm_trap_emul_gva_fault(struct kvm_vcpu *vcpu,
931 bool write); 931 bool write);
932 932
933#define KVM_ARCH_WANT_MMU_NOTIFIER 933#define KVM_ARCH_WANT_MMU_NOTIFIER
934int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
935int kvm_unmap_hva_range(struct kvm *kvm, 934int kvm_unmap_hva_range(struct kvm *kvm,
936 unsigned long start, unsigned long end); 935 unsigned long start, unsigned long end);
937void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); 936void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
diff --git a/arch/mips/include/asm/mach-lantiq/xway/xway_dma.h b/arch/mips/include/asm/mach-lantiq/xway/xway_dma.h
index 4901833498f7..8441b2698e64 100644
--- a/arch/mips/include/asm/mach-lantiq/xway/xway_dma.h
+++ b/arch/mips/include/asm/mach-lantiq/xway/xway_dma.h
@@ -40,6 +40,7 @@ struct ltq_dma_channel {
40 int desc; /* the current descriptor */ 40 int desc; /* the current descriptor */
41 struct ltq_dma_desc *desc_base; /* the descriptor base */ 41 struct ltq_dma_desc *desc_base; /* the descriptor base */
42 int phys; /* physical addr */ 42 int phys; /* physical addr */
43 struct device *dev;
43}; 44};
44 45
45enum { 46enum {
diff --git a/arch/mips/kernel/vdso.c b/arch/mips/kernel/vdso.c
index 019035d7225c..8f845f6e5f42 100644
--- a/arch/mips/kernel/vdso.c
+++ b/arch/mips/kernel/vdso.c
@@ -13,6 +13,7 @@
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/ioport.h> 15#include <linux/ioport.h>
16#include <linux/kernel.h>
16#include <linux/mm.h> 17#include <linux/mm.h>
17#include <linux/sched.h> 18#include <linux/sched.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
@@ -20,6 +21,7 @@
20 21
21#include <asm/abi.h> 22#include <asm/abi.h>
22#include <asm/mips-cps.h> 23#include <asm/mips-cps.h>
24#include <asm/page.h>
23#include <asm/vdso.h> 25#include <asm/vdso.h>
24 26
25/* Kernel-provided data used by the VDSO. */ 27/* Kernel-provided data used by the VDSO. */
@@ -128,12 +130,30 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
128 vvar_size = gic_size + PAGE_SIZE; 130 vvar_size = gic_size + PAGE_SIZE;
129 size = vvar_size + image->size; 131 size = vvar_size + image->size;
130 132
133 /*
134 * Find a region that's large enough for us to perform the
135 * colour-matching alignment below.
136 */
137 if (cpu_has_dc_aliases)
138 size += shm_align_mask + 1;
139
131 base = get_unmapped_area(NULL, 0, size, 0, 0); 140 base = get_unmapped_area(NULL, 0, size, 0, 0);
132 if (IS_ERR_VALUE(base)) { 141 if (IS_ERR_VALUE(base)) {
133 ret = base; 142 ret = base;
134 goto out; 143 goto out;
135 } 144 }
136 145
146 /*
147 * If we suffer from dcache aliasing, ensure that the VDSO data page
148 * mapping is coloured the same as the kernel's mapping of that memory.
149 * This ensures that when the kernel updates the VDSO data userland
150 * will observe it without requiring cache invalidations.
151 */
152 if (cpu_has_dc_aliases) {
153 base = __ALIGN_MASK(base, shm_align_mask);
154 base += ((unsigned long)&vdso_data - gic_size) & shm_align_mask;
155 }
156
137 data_addr = base + gic_size; 157 data_addr = base + gic_size;
138 vdso_addr = data_addr + PAGE_SIZE; 158 vdso_addr = data_addr + PAGE_SIZE;
139 159
diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c
index ee64db032793..d8dcdb350405 100644
--- a/arch/mips/kvm/mmu.c
+++ b/arch/mips/kvm/mmu.c
@@ -512,16 +512,6 @@ static int kvm_unmap_hva_handler(struct kvm *kvm, gfn_t gfn, gfn_t gfn_end,
512 return 1; 512 return 1;
513} 513}
514 514
515int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
516{
517 unsigned long end = hva + PAGE_SIZE;
518
519 handle_hva_to_gpa(kvm, hva, end, &kvm_unmap_hva_handler, NULL);
520
521 kvm_mips_callbacks->flush_shadow_all(kvm);
522 return 0;
523}
524
525int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) 515int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end)
526{ 516{
527 handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, NULL); 517 handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, NULL);
diff --git a/arch/mips/lantiq/xway/dma.c b/arch/mips/lantiq/xway/dma.c
index 4b9fbb6744ad..664f2f7f55c1 100644
--- a/arch/mips/lantiq/xway/dma.c
+++ b/arch/mips/lantiq/xway/dma.c
@@ -130,7 +130,7 @@ ltq_dma_alloc(struct ltq_dma_channel *ch)
130 unsigned long flags; 130 unsigned long flags;
131 131
132 ch->desc = 0; 132 ch->desc = 0;
133 ch->desc_base = dma_zalloc_coherent(NULL, 133 ch->desc_base = dma_zalloc_coherent(ch->dev,
134 LTQ_DESC_NUM * LTQ_DESC_SIZE, 134 LTQ_DESC_NUM * LTQ_DESC_SIZE,
135 &ch->phys, GFP_ATOMIC); 135 &ch->phys, GFP_ATOMIC);
136 136
@@ -182,7 +182,7 @@ ltq_dma_free(struct ltq_dma_channel *ch)
182 if (!ch->desc_base) 182 if (!ch->desc_base)
183 return; 183 return;
184 ltq_dma_close(ch); 184 ltq_dma_close(ch);
185 dma_free_coherent(NULL, LTQ_DESC_NUM * LTQ_DESC_SIZE, 185 dma_free_coherent(ch->dev, LTQ_DESC_NUM * LTQ_DESC_SIZE,
186 ch->desc_base, ch->phys); 186 ch->desc_base, ch->phys);
187} 187}
188EXPORT_SYMBOL_GPL(ltq_dma_free); 188EXPORT_SYMBOL_GPL(ltq_dma_free);
diff --git a/arch/mips/lasat/image/Makefile b/arch/mips/lasat/image/Makefile
index 9ab1326f57c9..78ce4cff1012 100644
--- a/arch/mips/lasat/image/Makefile
+++ b/arch/mips/lasat/image/Makefile
@@ -38,7 +38,7 @@ $(obj)/rom.bin: $(obj)/rom
38 38
39# Rule to make the bootloader 39# Rule to make the bootloader
40$(obj)/rom: $(addprefix $(obj)/,$(OBJECTS)) 40$(obj)/rom: $(addprefix $(obj)/,$(OBJECTS))
41 $(LD) $(LDFLAGS) $(LDSCRIPT) -o $@ $^ 41 $(LD) $(KBUILD_LDFLAGS) $(LDSCRIPT) -o $@ $^
42 42
43$(obj)/%.o: $(obj)/%.gz 43$(obj)/%.o: $(obj)/%.gz
44 $(LD) -r -o $@ -b binary $< 44 $(LD) -r -o $@ -b binary $<
diff --git a/arch/nds32/Kconfig b/arch/nds32/Kconfig
index 1d4248fa55e9..7068f341133d 100644
--- a/arch/nds32/Kconfig
+++ b/arch/nds32/Kconfig
@@ -40,6 +40,10 @@ config NDS32
40 select NO_IOPORT_MAP 40 select NO_IOPORT_MAP
41 select RTC_LIB 41 select RTC_LIB
42 select THREAD_INFO_IN_TASK 42 select THREAD_INFO_IN_TASK
43 select HAVE_FUNCTION_TRACER
44 select HAVE_FUNCTION_GRAPH_TRACER
45 select HAVE_FTRACE_MCOUNT_RECORD
46 select HAVE_DYNAMIC_FTRACE
43 help 47 help
44 Andes(nds32) Linux support. 48 Andes(nds32) Linux support.
45 49
diff --git a/arch/nds32/Makefile b/arch/nds32/Makefile
index 031c676821ff..3509fac10491 100644
--- a/arch/nds32/Makefile
+++ b/arch/nds32/Makefile
@@ -5,6 +5,10 @@ KBUILD_DEFCONFIG := defconfig
5 5
6comma = , 6comma = ,
7 7
8ifdef CONFIG_FUNCTION_TRACER
9arch-y += -malways-save-lp -mno-relax
10endif
11
8KBUILD_CFLAGS += $(call cc-option, -mno-sched-prolog-epilog) 12KBUILD_CFLAGS += $(call cc-option, -mno-sched-prolog-epilog)
9KBUILD_CFLAGS += -mcmodel=large 13KBUILD_CFLAGS += -mcmodel=large
10 14
@@ -33,12 +37,12 @@ endif
33ifdef CONFIG_CPU_LITTLE_ENDIAN 37ifdef CONFIG_CPU_LITTLE_ENDIAN
34KBUILD_CFLAGS += $(call cc-option, -EL) 38KBUILD_CFLAGS += $(call cc-option, -EL)
35KBUILD_AFLAGS += $(call cc-option, -EL) 39KBUILD_AFLAGS += $(call cc-option, -EL)
36LDFLAGS += $(call cc-option, -EL) 40KBUILD_LDFLAGS += $(call cc-option, -EL)
37CHECKFLAGS += -D__NDS32_EL__ 41CHECKFLAGS += -D__NDS32_EL__
38else 42else
39KBUILD_CFLAGS += $(call cc-option, -EB) 43KBUILD_CFLAGS += $(call cc-option, -EB)
40KBUILD_AFLAGS += $(call cc-option, -EB) 44KBUILD_AFLAGS += $(call cc-option, -EB)
41LDFLAGS += $(call cc-option, -EB) 45KBUILD_LDFLAGS += $(call cc-option, -EB)
42CHECKFLAGS += -D__NDS32_EB__ 46CHECKFLAGS += -D__NDS32_EB__
43endif 47endif
44 48
diff --git a/arch/nds32/include/asm/elf.h b/arch/nds32/include/asm/elf.h
index 56c479058802..f5f9cf7e0544 100644
--- a/arch/nds32/include/asm/elf.h
+++ b/arch/nds32/include/asm/elf.h
@@ -121,9 +121,9 @@ struct elf32_hdr;
121 */ 121 */
122#define ELF_CLASS ELFCLASS32 122#define ELF_CLASS ELFCLASS32
123#ifdef __NDS32_EB__ 123#ifdef __NDS32_EB__
124#define ELF_DATA ELFDATA2MSB; 124#define ELF_DATA ELFDATA2MSB
125#else 125#else
126#define ELF_DATA ELFDATA2LSB; 126#define ELF_DATA ELFDATA2LSB
127#endif 127#endif
128#define ELF_ARCH EM_NDS32 128#define ELF_ARCH EM_NDS32
129#define USE_ELF_CORE_DUMP 129#define USE_ELF_CORE_DUMP
diff --git a/arch/nds32/include/asm/ftrace.h b/arch/nds32/include/asm/ftrace.h
new file mode 100644
index 000000000000..2f96cc96aa35
--- /dev/null
+++ b/arch/nds32/include/asm/ftrace.h
@@ -0,0 +1,46 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef __ASM_NDS32_FTRACE_H
4#define __ASM_NDS32_FTRACE_H
5
6#ifdef CONFIG_FUNCTION_TRACER
7
8#define HAVE_FUNCTION_GRAPH_FP_TEST
9
10#define MCOUNT_ADDR ((unsigned long)(_mcount))
11/* mcount call is composed of three instructions:
12 * sethi + ori + jral
13 */
14#define MCOUNT_INSN_SIZE 12
15
16extern void _mcount(unsigned long parent_ip);
17
18#ifdef CONFIG_DYNAMIC_FTRACE
19
20#define FTRACE_ADDR ((unsigned long)_ftrace_caller)
21
22#ifdef __NDS32_EL__
23#define INSN_NOP 0x09000040
24#define INSN_SIZE(insn) (((insn & 0x00000080) == 0) ? 4 : 2)
25#define IS_SETHI(insn) ((insn & 0x000000fe) == 0x00000046)
26#define ENDIAN_CONVERT(insn) be32_to_cpu(insn)
27#else /* __NDS32_EB__ */
28#define INSN_NOP 0x40000009
29#define INSN_SIZE(insn) (((insn & 0x80000000) == 0) ? 4 : 2)
30#define IS_SETHI(insn) ((insn & 0xfe000000) == 0x46000000)
31#define ENDIAN_CONVERT(insn) (insn)
32#endif
33
34extern void _ftrace_caller(unsigned long parent_ip);
35static inline unsigned long ftrace_call_adjust(unsigned long addr)
36{
37 return addr;
38}
39struct dyn_arch_ftrace {
40};
41
42#endif /* CONFIG_DYNAMIC_FTRACE */
43
44#endif /* CONFIG_FUNCTION_TRACER */
45
46#endif /* __ASM_NDS32_FTRACE_H */
diff --git a/arch/nds32/include/asm/nds32.h b/arch/nds32/include/asm/nds32.h
index 19b19394a936..68c38151c3e4 100644
--- a/arch/nds32/include/asm/nds32.h
+++ b/arch/nds32/include/asm/nds32.h
@@ -17,6 +17,7 @@
17#else 17#else
18#define FP_OFFSET (-2) 18#define FP_OFFSET (-2)
19#endif 19#endif
20#define LP_OFFSET (-1)
20 21
21extern void __init early_trap_init(void); 22extern void __init early_trap_init(void);
22static inline void GIE_ENABLE(void) 23static inline void GIE_ENABLE(void)
diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uaccess.h
index 18a009f3804d..362a32d9bd16 100644
--- a/arch/nds32/include/asm/uaccess.h
+++ b/arch/nds32/include/asm/uaccess.h
@@ -38,7 +38,7 @@ struct exception_table_entry {
38extern int fixup_exception(struct pt_regs *regs); 38extern int fixup_exception(struct pt_regs *regs);
39 39
40#define KERNEL_DS ((mm_segment_t) { ~0UL }) 40#define KERNEL_DS ((mm_segment_t) { ~0UL })
41#define USER_DS ((mm_segment_t) {TASK_SIZE - 1}) 41#define USER_DS ((mm_segment_t) {TASK_SIZE - 1})
42 42
43#define get_ds() (KERNEL_DS) 43#define get_ds() (KERNEL_DS)
44#define get_fs() (current_thread_info()->addr_limit) 44#define get_fs() (current_thread_info()->addr_limit)
@@ -49,11 +49,11 @@ static inline void set_fs(mm_segment_t fs)
49 current_thread_info()->addr_limit = fs; 49 current_thread_info()->addr_limit = fs;
50} 50}
51 51
52#define segment_eq(a, b) ((a) == (b)) 52#define segment_eq(a, b) ((a) == (b))
53 53
54#define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs() -size)) 54#define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs() -size))
55 55
56#define access_ok(type, addr, size) \ 56#define access_ok(type, addr, size) \
57 __range_ok((unsigned long)addr, (unsigned long)size) 57 __range_ok((unsigned long)addr, (unsigned long)size)
58/* 58/*
59 * Single-value transfer routines. They automatically use the right 59 * Single-value transfer routines. They automatically use the right
@@ -75,70 +75,73 @@ static inline void set_fs(mm_segment_t fs)
75 * versions are void (ie, don't return a value as such). 75 * versions are void (ie, don't return a value as such).
76 */ 76 */
77 77
78#define get_user(x,p) \ 78#define get_user __get_user \
79({ \ 79
80 long __e = -EFAULT; \ 80#define __get_user(x, ptr) \
81 if(likely(access_ok(VERIFY_READ, p, sizeof(*p)))) { \
82 __e = __get_user(x,p); \
83 } else \
84 x = 0; \
85 __e; \
86})
87#define __get_user(x,ptr) \
88({ \ 81({ \
89 long __gu_err = 0; \ 82 long __gu_err = 0; \
90 __get_user_err((x),(ptr),__gu_err); \ 83 __get_user_check((x), (ptr), __gu_err); \
91 __gu_err; \ 84 __gu_err; \
92}) 85})
93 86
94#define __get_user_error(x,ptr,err) \ 87#define __get_user_error(x, ptr, err) \
95({ \ 88({ \
96 __get_user_err((x),(ptr),err); \ 89 __get_user_check((x), (ptr), (err)); \
97 (void) 0; \ 90 (void)0; \
98}) 91})
99 92
100#define __get_user_err(x,ptr,err) \ 93#define __get_user_check(x, ptr, err) \
94({ \
95 const __typeof__(*(ptr)) __user *__p = (ptr); \
96 might_fault(); \
97 if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \
98 __get_user_err((x), __p, (err)); \
99 } else { \
100 (x) = 0; (err) = -EFAULT; \
101 } \
102})
103
104#define __get_user_err(x, ptr, err) \
101do { \ 105do { \
102 unsigned long __gu_addr = (unsigned long)(ptr); \
103 unsigned long __gu_val; \ 106 unsigned long __gu_val; \
104 __chk_user_ptr(ptr); \ 107 __chk_user_ptr(ptr); \
105 switch (sizeof(*(ptr))) { \ 108 switch (sizeof(*(ptr))) { \
106 case 1: \ 109 case 1: \
107 __get_user_asm("lbi",__gu_val,__gu_addr,err); \ 110 __get_user_asm("lbi", __gu_val, (ptr), (err)); \
108 break; \ 111 break; \
109 case 2: \ 112 case 2: \
110 __get_user_asm("lhi",__gu_val,__gu_addr,err); \ 113 __get_user_asm("lhi", __gu_val, (ptr), (err)); \
111 break; \ 114 break; \
112 case 4: \ 115 case 4: \
113 __get_user_asm("lwi",__gu_val,__gu_addr,err); \ 116 __get_user_asm("lwi", __gu_val, (ptr), (err)); \
114 break; \ 117 break; \
115 case 8: \ 118 case 8: \
116 __get_user_asm_dword(__gu_val,__gu_addr,err); \ 119 __get_user_asm_dword(__gu_val, (ptr), (err)); \
117 break; \ 120 break; \
118 default: \ 121 default: \
119 BUILD_BUG(); \ 122 BUILD_BUG(); \
120 break; \ 123 break; \
121 } \ 124 } \
122 (x) = (__typeof__(*(ptr)))__gu_val; \ 125 (x) = (__force __typeof__(*(ptr)))__gu_val; \
123} while (0) 126} while (0)
124 127
125#define __get_user_asm(inst,x,addr,err) \ 128#define __get_user_asm(inst, x, addr, err) \
126 asm volatile( \ 129 __asm__ __volatile__ ( \
127 "1: "inst" %1,[%2]\n" \ 130 "1: "inst" %1,[%2]\n" \
128 "2:\n" \ 131 "2:\n" \
129 " .section .fixup,\"ax\"\n" \ 132 " .section .fixup,\"ax\"\n" \
130 " .align 2\n" \ 133 " .align 2\n" \
131 "3: move %0, %3\n" \ 134 "3: move %0, %3\n" \
132 " move %1, #0\n" \ 135 " move %1, #0\n" \
133 " b 2b\n" \ 136 " b 2b\n" \
134 " .previous\n" \ 137 " .previous\n" \
135 " .section __ex_table,\"a\"\n" \ 138 " .section __ex_table,\"a\"\n" \
136 " .align 3\n" \ 139 " .align 3\n" \
137 " .long 1b, 3b\n" \ 140 " .long 1b, 3b\n" \
138 " .previous" \ 141 " .previous" \
139 : "+r" (err), "=&r" (x) \ 142 : "+r" (err), "=&r" (x) \
140 : "r" (addr), "i" (-EFAULT) \ 143 : "r" (addr), "i" (-EFAULT) \
141 : "cc") 144 : "cc")
142 145
143#ifdef __NDS32_EB__ 146#ifdef __NDS32_EB__
144#define __gu_reg_oper0 "%H1" 147#define __gu_reg_oper0 "%H1"
@@ -149,61 +152,66 @@ do { \
149#endif 152#endif
150 153
151#define __get_user_asm_dword(x, addr, err) \ 154#define __get_user_asm_dword(x, addr, err) \
152 asm volatile( \ 155 __asm__ __volatile__ ( \
153 "\n1:\tlwi " __gu_reg_oper0 ",[%2]\n" \ 156 "\n1:\tlwi " __gu_reg_oper0 ",[%2]\n" \
154 "\n2:\tlwi " __gu_reg_oper1 ",[%2+4]\n" \ 157 "\n2:\tlwi " __gu_reg_oper1 ",[%2+4]\n" \
155 "3:\n" \ 158 "3:\n" \
156 " .section .fixup,\"ax\"\n" \ 159 " .section .fixup,\"ax\"\n" \
157 " .align 2\n" \ 160 " .align 2\n" \
158 "4: move %0, %3\n" \ 161 "4: move %0, %3\n" \
159 " b 3b\n" \ 162 " b 3b\n" \
160 " .previous\n" \ 163 " .previous\n" \
161 " .section __ex_table,\"a\"\n" \ 164 " .section __ex_table,\"a\"\n" \
162 " .align 3\n" \ 165 " .align 3\n" \
163 " .long 1b, 4b\n" \ 166 " .long 1b, 4b\n" \
164 " .long 2b, 4b\n" \ 167 " .long 2b, 4b\n" \
165 " .previous" \ 168 " .previous" \
166 : "+r"(err), "=&r"(x) \ 169 : "+r"(err), "=&r"(x) \
167 : "r"(addr), "i"(-EFAULT) \ 170 : "r"(addr), "i"(-EFAULT) \
168 : "cc") 171 : "cc")
169#define put_user(x,p) \ 172
170({ \ 173#define put_user __put_user \
171 long __e = -EFAULT; \ 174
172 if(likely(access_ok(VERIFY_WRITE, p, sizeof(*p)))) { \ 175#define __put_user(x, ptr) \
173 __e = __put_user(x,p); \
174 } \
175 __e; \
176})
177#define __put_user(x,ptr) \
178({ \ 176({ \
179 long __pu_err = 0; \ 177 long __pu_err = 0; \
180 __put_user_err((x),(ptr),__pu_err); \ 178 __put_user_err((x), (ptr), __pu_err); \
181 __pu_err; \ 179 __pu_err; \
182}) 180})
183 181
184#define __put_user_error(x,ptr,err) \ 182#define __put_user_error(x, ptr, err) \
183({ \
184 __put_user_err((x), (ptr), (err)); \
185 (void)0; \
186})
187
188#define __put_user_check(x, ptr, err) \
185({ \ 189({ \
186 __put_user_err((x),(ptr),err); \ 190 __typeof__(*(ptr)) __user *__p = (ptr); \
187 (void) 0; \ 191 might_fault(); \
192 if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \
193 __put_user_err((x), __p, (err)); \
194 } else { \
195 (err) = -EFAULT; \
196 } \
188}) 197})
189 198
190#define __put_user_err(x,ptr,err) \ 199#define __put_user_err(x, ptr, err) \
191do { \ 200do { \
192 unsigned long __pu_addr = (unsigned long)(ptr); \
193 __typeof__(*(ptr)) __pu_val = (x); \ 201 __typeof__(*(ptr)) __pu_val = (x); \
194 __chk_user_ptr(ptr); \ 202 __chk_user_ptr(ptr); \
195 switch (sizeof(*(ptr))) { \ 203 switch (sizeof(*(ptr))) { \
196 case 1: \ 204 case 1: \
197 __put_user_asm("sbi",__pu_val,__pu_addr,err); \ 205 __put_user_asm("sbi", __pu_val, (ptr), (err)); \
198 break; \ 206 break; \
199 case 2: \ 207 case 2: \
200 __put_user_asm("shi",__pu_val,__pu_addr,err); \ 208 __put_user_asm("shi", __pu_val, (ptr), (err)); \
201 break; \ 209 break; \
202 case 4: \ 210 case 4: \
203 __put_user_asm("swi",__pu_val,__pu_addr,err); \ 211 __put_user_asm("swi", __pu_val, (ptr), (err)); \
204 break; \ 212 break; \
205 case 8: \ 213 case 8: \
206 __put_user_asm_dword(__pu_val,__pu_addr,err); \ 214 __put_user_asm_dword(__pu_val, (ptr), (err)); \
207 break; \ 215 break; \
208 default: \ 216 default: \
209 BUILD_BUG(); \ 217 BUILD_BUG(); \
@@ -211,22 +219,22 @@ do { \
211 } \ 219 } \
212} while (0) 220} while (0)
213 221
214#define __put_user_asm(inst,x,addr,err) \ 222#define __put_user_asm(inst, x, addr, err) \
215 asm volatile( \ 223 __asm__ __volatile__ ( \
216 "1: "inst" %1,[%2]\n" \ 224 "1: "inst" %1,[%2]\n" \
217 "2:\n" \ 225 "2:\n" \
218 " .section .fixup,\"ax\"\n" \ 226 " .section .fixup,\"ax\"\n" \
219 " .align 2\n" \ 227 " .align 2\n" \
220 "3: move %0, %3\n" \ 228 "3: move %0, %3\n" \
221 " b 2b\n" \ 229 " b 2b\n" \
222 " .previous\n" \ 230 " .previous\n" \
223 " .section __ex_table,\"a\"\n" \ 231 " .section __ex_table,\"a\"\n" \
224 " .align 3\n" \ 232 " .align 3\n" \
225 " .long 1b, 3b\n" \ 233 " .long 1b, 3b\n" \
226 " .previous" \ 234 " .previous" \
227 : "+r" (err) \ 235 : "+r" (err) \
228 : "r" (x), "r" (addr), "i" (-EFAULT) \ 236 : "r" (x), "r" (addr), "i" (-EFAULT) \
229 : "cc") 237 : "cc")
230 238
231#ifdef __NDS32_EB__ 239#ifdef __NDS32_EB__
232#define __pu_reg_oper0 "%H2" 240#define __pu_reg_oper0 "%H2"
@@ -237,23 +245,24 @@ do { \
237#endif 245#endif
238 246
239#define __put_user_asm_dword(x, addr, err) \ 247#define __put_user_asm_dword(x, addr, err) \
240 asm volatile( \ 248 __asm__ __volatile__ ( \
241 "\n1:\tswi " __pu_reg_oper0 ",[%1]\n" \ 249 "\n1:\tswi " __pu_reg_oper0 ",[%1]\n" \
242 "\n2:\tswi " __pu_reg_oper1 ",[%1+4]\n" \ 250 "\n2:\tswi " __pu_reg_oper1 ",[%1+4]\n" \
243 "3:\n" \ 251 "3:\n" \
244 " .section .fixup,\"ax\"\n" \ 252 " .section .fixup,\"ax\"\n" \
245 " .align 2\n" \ 253 " .align 2\n" \
246 "4: move %0, %3\n" \ 254 "4: move %0, %3\n" \
247 " b 3b\n" \ 255 " b 3b\n" \
248 " .previous\n" \ 256 " .previous\n" \
249 " .section __ex_table,\"a\"\n" \ 257 " .section __ex_table,\"a\"\n" \
250 " .align 3\n" \ 258 " .align 3\n" \
251 " .long 1b, 4b\n" \ 259 " .long 1b, 4b\n" \
252 " .long 2b, 4b\n" \ 260 " .long 2b, 4b\n" \
253 " .previous" \ 261 " .previous" \
254 : "+r"(err) \ 262 : "+r"(err) \
255 : "r"(addr), "r"(x), "i"(-EFAULT) \ 263 : "r"(addr), "r"(x), "i"(-EFAULT) \
256 : "cc") 264 : "cc")
265
257extern unsigned long __arch_clear_user(void __user * addr, unsigned long n); 266extern unsigned long __arch_clear_user(void __user * addr, unsigned long n);
258extern long strncpy_from_user(char *dest, const char __user * src, long count); 267extern long strncpy_from_user(char *dest, const char __user * src, long count);
259extern __must_check long strlen_user(const char __user * str); 268extern __must_check long strlen_user(const char __user * str);
diff --git a/arch/nds32/kernel/Makefile b/arch/nds32/kernel/Makefile
index 42792743e8b9..27cded39fa66 100644
--- a/arch/nds32/kernel/Makefile
+++ b/arch/nds32/kernel/Makefile
@@ -21,3 +21,9 @@ extra-y := head.o vmlinux.lds
21 21
22 22
23obj-y += vdso/ 23obj-y += vdso/
24
25obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o
26
27ifdef CONFIG_FUNCTION_TRACER
28CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
29endif
diff --git a/arch/nds32/kernel/atl2c.c b/arch/nds32/kernel/atl2c.c
index 0c6d031a1c4a..0c5386e72098 100644
--- a/arch/nds32/kernel/atl2c.c
+++ b/arch/nds32/kernel/atl2c.c
@@ -9,7 +9,8 @@
9 9
10void __iomem *atl2c_base; 10void __iomem *atl2c_base;
11static const struct of_device_id atl2c_ids[] __initconst = { 11static const struct of_device_id atl2c_ids[] __initconst = {
12 {.compatible = "andestech,atl2c",} 12 {.compatible = "andestech,atl2c",},
13 {}
13}; 14};
14 15
15static int __init atl2c_of_init(void) 16static int __init atl2c_of_init(void)
diff --git a/arch/nds32/kernel/ex-entry.S b/arch/nds32/kernel/ex-entry.S
index b8ae4e9a6b93..21a144071566 100644
--- a/arch/nds32/kernel/ex-entry.S
+++ b/arch/nds32/kernel/ex-entry.S
@@ -118,7 +118,7 @@ common_exception_handler:
118 /* interrupt */ 118 /* interrupt */
1192: 1192:
120#ifdef CONFIG_TRACE_IRQFLAGS 120#ifdef CONFIG_TRACE_IRQFLAGS
121 jal trace_hardirqs_off 121 jal __trace_hardirqs_off
122#endif 122#endif
123 move $r0, $sp 123 move $r0, $sp
124 sethi $lp, hi20(ret_from_intr) 124 sethi $lp, hi20(ret_from_intr)
diff --git a/arch/nds32/kernel/ex-exit.S b/arch/nds32/kernel/ex-exit.S
index 03e4f7788a18..f00af92f7e22 100644
--- a/arch/nds32/kernel/ex-exit.S
+++ b/arch/nds32/kernel/ex-exit.S
@@ -138,8 +138,8 @@ no_work_pending:
138#ifdef CONFIG_TRACE_IRQFLAGS 138#ifdef CONFIG_TRACE_IRQFLAGS
139 lwi $p0, [$sp+(#IPSW_OFFSET)] 139 lwi $p0, [$sp+(#IPSW_OFFSET)]
140 andi $p0, $p0, #0x1 140 andi $p0, $p0, #0x1
141 la $r10, trace_hardirqs_off 141 la $r10, __trace_hardirqs_off
142 la $r9, trace_hardirqs_on 142 la $r9, __trace_hardirqs_on
143 cmovz $r9, $p0, $r10 143 cmovz $r9, $p0, $r10
144 jral $r9 144 jral $r9
145#endif 145#endif
diff --git a/arch/nds32/kernel/ftrace.c b/arch/nds32/kernel/ftrace.c
new file mode 100644
index 000000000000..a0a9679ad5de
--- /dev/null
+++ b/arch/nds32/kernel/ftrace.c
@@ -0,0 +1,309 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/ftrace.h>
4#include <linux/uaccess.h>
5#include <asm/cacheflush.h>
6
7#ifndef CONFIG_DYNAMIC_FTRACE
8extern void (*ftrace_trace_function)(unsigned long, unsigned long,
9 struct ftrace_ops*, struct pt_regs*);
10extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
11extern void ftrace_graph_caller(void);
12
13noinline void __naked ftrace_stub(unsigned long ip, unsigned long parent_ip,
14 struct ftrace_ops *op, struct pt_regs *regs)
15{
16 __asm__ (""); /* avoid to optimize as pure function */
17}
18
19noinline void _mcount(unsigned long parent_ip)
20{
21 /* save all state by the compiler prologue */
22
23 unsigned long ip = (unsigned long)__builtin_return_address(0);
24
25 if (ftrace_trace_function != ftrace_stub)
26 ftrace_trace_function(ip - MCOUNT_INSN_SIZE, parent_ip,
27 NULL, NULL);
28
29#ifdef CONFIG_FUNCTION_GRAPH_TRACER
30 if (ftrace_graph_return != (trace_func_graph_ret_t)ftrace_stub
31 || ftrace_graph_entry != ftrace_graph_entry_stub)
32 ftrace_graph_caller();
33#endif
34
35 /* restore all state by the compiler epilogue */
36}
37EXPORT_SYMBOL(_mcount);
38
39#else /* CONFIG_DYNAMIC_FTRACE */
40
41noinline void __naked ftrace_stub(unsigned long ip, unsigned long parent_ip,
42 struct ftrace_ops *op, struct pt_regs *regs)
43{
44 __asm__ (""); /* avoid to optimize as pure function */
45}
46
47noinline void __naked _mcount(unsigned long parent_ip)
48{
49 __asm__ (""); /* avoid to optimize as pure function */
50}
51EXPORT_SYMBOL(_mcount);
52
53#define XSTR(s) STR(s)
54#define STR(s) #s
55void _ftrace_caller(unsigned long parent_ip)
56{
57 /* save all state needed by the compiler prologue */
58
59 /*
60 * prepare arguments for real tracing function
61 * first arg : __builtin_return_address(0) - MCOUNT_INSN_SIZE
62 * second arg : parent_ip
63 */
64 __asm__ __volatile__ (
65 "move $r1, %0 \n\t"
66 "addi $r0, %1, #-" XSTR(MCOUNT_INSN_SIZE) "\n\t"
67 :
68 : "r" (parent_ip), "r" (__builtin_return_address(0)));
69
70 /* a placeholder for the call to a real tracing function */
71 __asm__ __volatile__ (
72 "ftrace_call: \n\t"
73 "nop \n\t"
74 "nop \n\t"
75 "nop \n\t");
76
77#ifdef CONFIG_FUNCTION_GRAPH_TRACER
78 /* a placeholder for the call to ftrace_graph_caller */
79 __asm__ __volatile__ (
80 "ftrace_graph_call: \n\t"
81 "nop \n\t"
82 "nop \n\t"
83 "nop \n\t");
84#endif
85 /* restore all state needed by the compiler epilogue */
86}
87
88int __init ftrace_dyn_arch_init(void)
89{
90 return 0;
91}
92
93int ftrace_arch_code_modify_prepare(void)
94{
95 set_all_modules_text_rw();
96 return 0;
97}
98
99int ftrace_arch_code_modify_post_process(void)
100{
101 set_all_modules_text_ro();
102 return 0;
103}
104
105static unsigned long gen_sethi_insn(unsigned long addr)
106{
107 unsigned long opcode = 0x46000000;
108 unsigned long imm = addr >> 12;
109 unsigned long rt_num = 0xf << 20;
110
111 return ENDIAN_CONVERT(opcode | rt_num | imm);
112}
113
114static unsigned long gen_ori_insn(unsigned long addr)
115{
116 unsigned long opcode = 0x58000000;
117 unsigned long imm = addr & 0x0000fff;
118 unsigned long rt_num = 0xf << 20;
119 unsigned long ra_num = 0xf << 15;
120
121 return ENDIAN_CONVERT(opcode | rt_num | ra_num | imm);
122}
123
124static unsigned long gen_jral_insn(unsigned long addr)
125{
126 unsigned long opcode = 0x4a000001;
127 unsigned long rt_num = 0x1e << 20;
128 unsigned long rb_num = 0xf << 10;
129
130 return ENDIAN_CONVERT(opcode | rt_num | rb_num);
131}
132
133static void ftrace_gen_call_insn(unsigned long *call_insns,
134 unsigned long addr)
135{
136 call_insns[0] = gen_sethi_insn(addr); /* sethi $r15, imm20u */
137 call_insns[1] = gen_ori_insn(addr); /* ori $r15, $r15, imm15u */
138 call_insns[2] = gen_jral_insn(addr); /* jral $lp, $r15 */
139}
140
141static int __ftrace_modify_code(unsigned long pc, unsigned long *old_insn,
142 unsigned long *new_insn, bool validate)
143{
144 unsigned long orig_insn[3];
145
146 if (validate) {
147 if (probe_kernel_read(orig_insn, (void *)pc, MCOUNT_INSN_SIZE))
148 return -EFAULT;
149 if (memcmp(orig_insn, old_insn, MCOUNT_INSN_SIZE))
150 return -EINVAL;
151 }
152
153 if (probe_kernel_write((void *)pc, new_insn, MCOUNT_INSN_SIZE))
154 return -EPERM;
155
156 return 0;
157}
158
159static int ftrace_modify_code(unsigned long pc, unsigned long *old_insn,
160 unsigned long *new_insn, bool validate)
161{
162 int ret;
163
164 ret = __ftrace_modify_code(pc, old_insn, new_insn, validate);
165 if (ret)
166 return ret;
167
168 flush_icache_range(pc, pc + MCOUNT_INSN_SIZE);
169
170 return ret;
171}
172
173int ftrace_update_ftrace_func(ftrace_func_t func)
174{
175 unsigned long pc = (unsigned long)&ftrace_call;
176 unsigned long old_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
177 unsigned long new_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
178
179 if (func != ftrace_stub)
180 ftrace_gen_call_insn(new_insn, (unsigned long)func);
181
182 return ftrace_modify_code(pc, old_insn, new_insn, false);
183}
184
185int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
186{
187 unsigned long pc = rec->ip;
188 unsigned long nop_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
189 unsigned long call_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
190
191 ftrace_gen_call_insn(call_insn, addr);
192
193 return ftrace_modify_code(pc, nop_insn, call_insn, true);
194}
195
196int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
197 unsigned long addr)
198{
199 unsigned long pc = rec->ip;
200 unsigned long nop_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
201 unsigned long call_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
202
203 ftrace_gen_call_insn(call_insn, addr);
204
205 return ftrace_modify_code(pc, call_insn, nop_insn, true);
206}
207#endif /* CONFIG_DYNAMIC_FTRACE */
208
209#ifdef CONFIG_FUNCTION_GRAPH_TRACER
210void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
211 unsigned long frame_pointer)
212{
213 unsigned long return_hooker = (unsigned long)&return_to_handler;
214 struct ftrace_graph_ent trace;
215 unsigned long old;
216 int err;
217
218 if (unlikely(atomic_read(&current->tracing_graph_pause)))
219 return;
220
221 old = *parent;
222
223 trace.func = self_addr;
224 trace.depth = current->curr_ret_stack + 1;
225
226 /* Only trace if the calling function expects to */
227 if (!ftrace_graph_entry(&trace))
228 return;
229
230 err = ftrace_push_return_trace(old, self_addr, &trace.depth,
231 frame_pointer, NULL);
232
233 if (err == -EBUSY)
234 return;
235
236 *parent = return_hooker;
237}
238
239noinline void ftrace_graph_caller(void)
240{
241 unsigned long *parent_ip =
242 (unsigned long *)(__builtin_frame_address(2) - 4);
243
244 unsigned long selfpc =
245 (unsigned long)(__builtin_return_address(1) - MCOUNT_INSN_SIZE);
246
247 unsigned long frame_pointer =
248 (unsigned long)__builtin_frame_address(3);
249
250 prepare_ftrace_return(parent_ip, selfpc, frame_pointer);
251}
252
253extern unsigned long ftrace_return_to_handler(unsigned long frame_pointer);
254void __naked return_to_handler(void)
255{
256 __asm__ __volatile__ (
257 /* save state needed by the ABI */
258 "smw.adm $r0,[$sp],$r1,#0x0 \n\t"
259
260 /* get original return address */
261 "move $r0, $fp \n\t"
262 "bal ftrace_return_to_handler\n\t"
263 "move $lp, $r0 \n\t"
264
265 /* restore state nedded by the ABI */
266 "lmw.bim $r0,[$sp],$r1,#0x0 \n\t");
267}
268
269#ifdef CONFIG_DYNAMIC_FTRACE
270extern unsigned long ftrace_graph_call;
271
272static int ftrace_modify_graph_caller(bool enable)
273{
274 unsigned long pc = (unsigned long)&ftrace_graph_call;
275 unsigned long nop_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
276 unsigned long call_insn[3] = {INSN_NOP, INSN_NOP, INSN_NOP};
277
278 ftrace_gen_call_insn(call_insn, (unsigned long)ftrace_graph_caller);
279
280 if (enable)
281 return ftrace_modify_code(pc, nop_insn, call_insn, true);
282 else
283 return ftrace_modify_code(pc, call_insn, nop_insn, true);
284}
285
286int ftrace_enable_ftrace_graph_caller(void)
287{
288 return ftrace_modify_graph_caller(true);
289}
290
291int ftrace_disable_ftrace_graph_caller(void)
292{
293 return ftrace_modify_graph_caller(false);
294}
295#endif /* CONFIG_DYNAMIC_FTRACE */
296
297#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
298
299
300#ifdef CONFIG_TRACE_IRQFLAGS
301noinline void __trace_hardirqs_off(void)
302{
303 trace_hardirqs_off();
304}
305noinline void __trace_hardirqs_on(void)
306{
307 trace_hardirqs_on();
308}
309#endif /* CONFIG_TRACE_IRQFLAGS */
diff --git a/arch/nds32/kernel/module.c b/arch/nds32/kernel/module.c
index 4167283d8293..1e31829cbc2a 100644
--- a/arch/nds32/kernel/module.c
+++ b/arch/nds32/kernel/module.c
@@ -40,7 +40,7 @@ void do_reloc16(unsigned int val, unsigned int *loc, unsigned int val_mask,
40 40
41 tmp2 = tmp & loc_mask; 41 tmp2 = tmp & loc_mask;
42 if (partial_in_place) { 42 if (partial_in_place) {
43 tmp &= (!loc_mask); 43 tmp &= (~loc_mask);
44 tmp = 44 tmp =
45 tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask); 45 tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
46 } else { 46 } else {
@@ -70,7 +70,7 @@ void do_reloc32(unsigned int val, unsigned int *loc, unsigned int val_mask,
70 70
71 tmp2 = tmp & loc_mask; 71 tmp2 = tmp & loc_mask;
72 if (partial_in_place) { 72 if (partial_in_place) {
73 tmp &= (!loc_mask); 73 tmp &= (~loc_mask);
74 tmp = 74 tmp =
75 tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask); 75 tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
76 } else { 76 } else {
diff --git a/arch/nds32/kernel/stacktrace.c b/arch/nds32/kernel/stacktrace.c
index 8b231e910ea6..d974c0c1c65f 100644
--- a/arch/nds32/kernel/stacktrace.c
+++ b/arch/nds32/kernel/stacktrace.c
@@ -4,6 +4,7 @@
4#include <linux/sched/debug.h> 4#include <linux/sched/debug.h>
5#include <linux/sched/task_stack.h> 5#include <linux/sched/task_stack.h>
6#include <linux/stacktrace.h> 6#include <linux/stacktrace.h>
7#include <linux/ftrace.h>
7 8
8void save_stack_trace(struct stack_trace *trace) 9void save_stack_trace(struct stack_trace *trace)
9{ 10{
@@ -16,6 +17,7 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
16 unsigned long *fpn; 17 unsigned long *fpn;
17 int skip = trace->skip; 18 int skip = trace->skip;
18 int savesched; 19 int savesched;
20 int graph_idx = 0;
19 21
20 if (tsk == current) { 22 if (tsk == current) {
21 __asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn)); 23 __asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
@@ -29,10 +31,12 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
29 && (fpn >= (unsigned long *)TASK_SIZE)) { 31 && (fpn >= (unsigned long *)TASK_SIZE)) {
30 unsigned long lpp, fpp; 32 unsigned long lpp, fpp;
31 33
32 lpp = fpn[-1]; 34 lpp = fpn[LP_OFFSET];
33 fpp = fpn[FP_OFFSET]; 35 fpp = fpn[FP_OFFSET];
34 if (!__kernel_text_address(lpp)) 36 if (!__kernel_text_address(lpp))
35 break; 37 break;
38 else
39 lpp = ftrace_graph_ret_addr(tsk, &graph_idx, lpp, NULL);
36 40
37 if (savesched || !in_sched_functions(lpp)) { 41 if (savesched || !in_sched_functions(lpp)) {
38 if (skip) { 42 if (skip) {
diff --git a/arch/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c
index a6205fd4db52..1496aab48998 100644
--- a/arch/nds32/kernel/traps.c
+++ b/arch/nds32/kernel/traps.c
@@ -8,6 +8,7 @@
8#include <linux/kdebug.h> 8#include <linux/kdebug.h>
9#include <linux/sched/task_stack.h> 9#include <linux/sched/task_stack.h>
10#include <linux/uaccess.h> 10#include <linux/uaccess.h>
11#include <linux/ftrace.h>
11 12
12#include <asm/proc-fns.h> 13#include <asm/proc-fns.h>
13#include <asm/unistd.h> 14#include <asm/unistd.h>
@@ -94,28 +95,6 @@ static void dump_instr(struct pt_regs *regs)
94 set_fs(fs); 95 set_fs(fs);
95} 96}
96 97
97#ifdef CONFIG_FUNCTION_GRAPH_TRACER
98#include <linux/ftrace.h>
99static void
100get_real_ret_addr(unsigned long *addr, struct task_struct *tsk, int *graph)
101{
102 if (*addr == (unsigned long)return_to_handler) {
103 int index = tsk->curr_ret_stack;
104
105 if (tsk->ret_stack && index >= *graph) {
106 index -= *graph;
107 *addr = tsk->ret_stack[index].ret;
108 (*graph)++;
109 }
110 }
111}
112#else
113static inline void
114get_real_ret_addr(unsigned long *addr, struct task_struct *tsk, int *graph)
115{
116}
117#endif
118
119#define LOOP_TIMES (100) 98#define LOOP_TIMES (100)
120static void __dump(struct task_struct *tsk, unsigned long *base_reg) 99static void __dump(struct task_struct *tsk, unsigned long *base_reg)
121{ 100{
@@ -126,7 +105,8 @@ static void __dump(struct task_struct *tsk, unsigned long *base_reg)
126 while (!kstack_end(base_reg)) { 105 while (!kstack_end(base_reg)) {
127 ret_addr = *base_reg++; 106 ret_addr = *base_reg++;
128 if (__kernel_text_address(ret_addr)) { 107 if (__kernel_text_address(ret_addr)) {
129 get_real_ret_addr(&ret_addr, tsk, &graph); 108 ret_addr = ftrace_graph_ret_addr(
109 tsk, &graph, ret_addr, NULL);
130 print_ip_sym(ret_addr); 110 print_ip_sym(ret_addr);
131 } 111 }
132 if (--cnt < 0) 112 if (--cnt < 0)
@@ -137,15 +117,12 @@ static void __dump(struct task_struct *tsk, unsigned long *base_reg)
137 !((unsigned long)base_reg & 0x3) && 117 !((unsigned long)base_reg & 0x3) &&
138 ((unsigned long)base_reg >= TASK_SIZE)) { 118 ((unsigned long)base_reg >= TASK_SIZE)) {
139 unsigned long next_fp; 119 unsigned long next_fp;
140#if !defined(NDS32_ABI_2) 120 ret_addr = base_reg[LP_OFFSET];
141 ret_addr = base_reg[0];
142 next_fp = base_reg[1];
143#else
144 ret_addr = base_reg[-1];
145 next_fp = base_reg[FP_OFFSET]; 121 next_fp = base_reg[FP_OFFSET];
146#endif
147 if (__kernel_text_address(ret_addr)) { 122 if (__kernel_text_address(ret_addr)) {
148 get_real_ret_addr(&ret_addr, tsk, &graph); 123
124 ret_addr = ftrace_graph_ret_addr(
125 tsk, &graph, ret_addr, NULL);
149 print_ip_sym(ret_addr); 126 print_ip_sym(ret_addr);
150 } 127 }
151 if (--cnt < 0) 128 if (--cnt < 0)
@@ -196,11 +173,10 @@ void die(const char *str, struct pt_regs *regs, int err)
196 pr_emerg("CPU: %i\n", smp_processor_id()); 173 pr_emerg("CPU: %i\n", smp_processor_id());
197 show_regs(regs); 174 show_regs(regs);
198 pr_emerg("Process %s (pid: %d, stack limit = 0x%p)\n", 175 pr_emerg("Process %s (pid: %d, stack limit = 0x%p)\n",
199 tsk->comm, tsk->pid, task_thread_info(tsk) + 1); 176 tsk->comm, tsk->pid, end_of_stack(tsk));
200 177
201 if (!user_mode(regs) || in_interrupt()) { 178 if (!user_mode(regs) || in_interrupt()) {
202 dump_mem("Stack: ", regs->sp, 179 dump_mem("Stack: ", regs->sp, (regs->sp + PAGE_SIZE) & PAGE_MASK);
203 THREAD_SIZE + (unsigned long)task_thread_info(tsk));
204 dump_instr(regs); 180 dump_instr(regs);
205 dump_stack(); 181 dump_stack();
206 } 182 }
diff --git a/arch/nds32/kernel/vmlinux.lds.S b/arch/nds32/kernel/vmlinux.lds.S
index 288313b886ef..9e90f30a181d 100644
--- a/arch/nds32/kernel/vmlinux.lds.S
+++ b/arch/nds32/kernel/vmlinux.lds.S
@@ -13,14 +13,26 @@ OUTPUT_ARCH(nds32)
13ENTRY(_stext_lma) 13ENTRY(_stext_lma)
14jiffies = jiffies_64; 14jiffies = jiffies_64;
15 15
16#if defined(CONFIG_GCOV_KERNEL)
17#define NDS32_EXIT_KEEP(x) x
18#else
19#define NDS32_EXIT_KEEP(x)
20#endif
21
16SECTIONS 22SECTIONS
17{ 23{
18 _stext_lma = TEXTADDR - LOAD_OFFSET; 24 _stext_lma = TEXTADDR - LOAD_OFFSET;
19 . = TEXTADDR; 25 . = TEXTADDR;
20 __init_begin = .; 26 __init_begin = .;
21 HEAD_TEXT_SECTION 27 HEAD_TEXT_SECTION
28 .exit.text : {
29 NDS32_EXIT_KEEP(EXIT_TEXT)
30 }
22 INIT_TEXT_SECTION(PAGE_SIZE) 31 INIT_TEXT_SECTION(PAGE_SIZE)
23 INIT_DATA_SECTION(16) 32 INIT_DATA_SECTION(16)
33 .exit.data : {
34 NDS32_EXIT_KEEP(EXIT_DATA)
35 }
24 PERCPU_SECTION(L1_CACHE_BYTES) 36 PERCPU_SECTION(L1_CACHE_BYTES)
25 __init_end = .; 37 __init_end = .;
26 38
diff --git a/arch/nios2/Kconfig.debug b/arch/nios2/Kconfig.debug
index 7a49f0d28d14..f1da8a7b17ff 100644
--- a/arch/nios2/Kconfig.debug
+++ b/arch/nios2/Kconfig.debug
@@ -3,15 +3,6 @@
3config TRACE_IRQFLAGS_SUPPORT 3config TRACE_IRQFLAGS_SUPPORT
4 def_bool y 4 def_bool y
5 5
6config DEBUG_STACK_USAGE
7 bool "Enable stack utilization instrumentation"
8 depends on DEBUG_KERNEL
9 help
10 Enables the display of the minimum amount of free stack which each
11 task has ever had available in the sysrq-T and sysrq-P debug output.
12
13 This option will slow down process creation somewhat.
14
15config EARLY_PRINTK 6config EARLY_PRINTK
16 bool "Activate early kernel debugging" 7 bool "Activate early kernel debugging"
17 default y 8 default y
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index db0b6eebbfa5..a80669209155 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -177,7 +177,6 @@ config PPC
177 select HAVE_ARCH_KGDB 177 select HAVE_ARCH_KGDB
178 select HAVE_ARCH_MMAP_RND_BITS 178 select HAVE_ARCH_MMAP_RND_BITS
179 select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT 179 select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
180 select HAVE_ARCH_PREL32_RELOCATIONS
181 select HAVE_ARCH_SECCOMP_FILTER 180 select HAVE_ARCH_SECCOMP_FILTER
182 select HAVE_ARCH_TRACEHOOK 181 select HAVE_ARCH_TRACEHOOK
183 select HAVE_CBPF_JIT if !PPC64 182 select HAVE_CBPF_JIT if !PPC64
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 8397c7bd5880..11a1acba164a 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -76,14 +76,14 @@ endif
76 76
77ifdef CONFIG_CPU_LITTLE_ENDIAN 77ifdef CONFIG_CPU_LITTLE_ENDIAN
78KBUILD_CFLAGS += -mlittle-endian 78KBUILD_CFLAGS += -mlittle-endian
79LDFLAGS += -EL 79KBUILD_LDFLAGS += -EL
80LDEMULATION := lppc 80LDEMULATION := lppc
81GNUTARGET := powerpcle 81GNUTARGET := powerpcle
82MULTIPLEWORD := -mno-multiple 82MULTIPLEWORD := -mno-multiple
83KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect) 83KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
84else 84else
85KBUILD_CFLAGS += $(call cc-option,-mbig-endian) 85KBUILD_CFLAGS += $(call cc-option,-mbig-endian)
86LDFLAGS += -EB 86KBUILD_LDFLAGS += -EB
87LDEMULATION := ppc 87LDEMULATION := ppc
88GNUTARGET := powerpc 88GNUTARGET := powerpc
89MULTIPLEWORD := -mmultiple 89MULTIPLEWORD := -mmultiple
@@ -108,7 +108,7 @@ aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
108ifeq ($(HAS_BIARCH),y) 108ifeq ($(HAS_BIARCH),y)
109KBUILD_CFLAGS += -m$(BITS) 109KBUILD_CFLAGS += -m$(BITS)
110KBUILD_AFLAGS += -m$(BITS) -Wl,-a$(BITS) 110KBUILD_AFLAGS += -m$(BITS) -Wl,-a$(BITS)
111LDFLAGS += -m elf$(BITS)$(LDEMULATION) 111KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION)
112KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET) 112KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET)
113endif 113endif
114 114
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 3c0e8fb2b773..68e14afecac8 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -358,7 +358,7 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,
358 unsigned long pp, key; 358 unsigned long pp, key;
359 unsigned long v, orig_v, gr; 359 unsigned long v, orig_v, gr;
360 __be64 *hptep; 360 __be64 *hptep;
361 int index; 361 long int index;
362 int virtmode = vcpu->arch.shregs.msr & (data ? MSR_DR : MSR_IR); 362 int virtmode = vcpu->arch.shregs.msr & (data ? MSR_DR : MSR_IR);
363 363
364 if (kvm_is_radix(vcpu->kvm)) 364 if (kvm_is_radix(vcpu->kvm))
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index 0af1c0aea1fe..fd6e8c13685f 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -725,10 +725,10 @@ int kvm_unmap_radix(struct kvm *kvm, struct kvm_memory_slot *memslot,
725 gpa, shift); 725 gpa, shift);
726 kvmppc_radix_tlbie_page(kvm, gpa, shift); 726 kvmppc_radix_tlbie_page(kvm, gpa, shift);
727 if ((old & _PAGE_DIRTY) && memslot->dirty_bitmap) { 727 if ((old & _PAGE_DIRTY) && memslot->dirty_bitmap) {
728 unsigned long npages = 1; 728 unsigned long psize = PAGE_SIZE;
729 if (shift) 729 if (shift)
730 npages = 1ul << (shift - PAGE_SHIFT); 730 psize = 1ul << shift;
731 kvmppc_update_dirty_map(memslot, gfn, npages); 731 kvmppc_update_dirty_map(memslot, gfn, psize);
732 } 732 }
733 } 733 }
734 return 0; 734 return 0;
diff --git a/arch/powerpc/mm/mmu_context_book3s64.c b/arch/powerpc/mm/mmu_context_book3s64.c
index 4a892d894a0f..dbd8f762140b 100644
--- a/arch/powerpc/mm/mmu_context_book3s64.c
+++ b/arch/powerpc/mm/mmu_context_book3s64.c
@@ -26,48 +26,16 @@
26#include <asm/mmu_context.h> 26#include <asm/mmu_context.h>
27#include <asm/pgalloc.h> 27#include <asm/pgalloc.h>
28 28
29static DEFINE_SPINLOCK(mmu_context_lock);
30static DEFINE_IDA(mmu_context_ida); 29static DEFINE_IDA(mmu_context_ida);
31 30
32static int alloc_context_id(int min_id, int max_id) 31static int alloc_context_id(int min_id, int max_id)
33{ 32{
34 int index, err; 33 return ida_alloc_range(&mmu_context_ida, min_id, max_id, GFP_KERNEL);
35
36again:
37 if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL))
38 return -ENOMEM;
39
40 spin_lock(&mmu_context_lock);
41 err = ida_get_new_above(&mmu_context_ida, min_id, &index);
42 spin_unlock(&mmu_context_lock);
43
44 if (err == -EAGAIN)
45 goto again;
46 else if (err)
47 return err;
48
49 if (index > max_id) {
50 spin_lock(&mmu_context_lock);
51 ida_remove(&mmu_context_ida, index);
52 spin_unlock(&mmu_context_lock);
53 return -ENOMEM;
54 }
55
56 return index;
57} 34}
58 35
59void hash__reserve_context_id(int id) 36void hash__reserve_context_id(int id)
60{ 37{
61 int rc, result = 0; 38 int result = ida_alloc_range(&mmu_context_ida, id, id, GFP_KERNEL);
62
63 do {
64 if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL))
65 break;
66
67 spin_lock(&mmu_context_lock);
68 rc = ida_get_new_above(&mmu_context_ida, id, &result);
69 spin_unlock(&mmu_context_lock);
70 } while (rc == -EAGAIN);
71 39
72 WARN(result != id, "mmu: Failed to reserve context id %d (rc %d)\n", id, result); 40 WARN(result != id, "mmu: Failed to reserve context id %d (rc %d)\n", id, result);
73} 41}
@@ -172,9 +140,7 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
172 140
173void __destroy_context(int context_id) 141void __destroy_context(int context_id)
174{ 142{
175 spin_lock(&mmu_context_lock); 143 ida_free(&mmu_context_ida, context_id);
176 ida_remove(&mmu_context_ida, context_id);
177 spin_unlock(&mmu_context_lock);
178} 144}
179EXPORT_SYMBOL_GPL(__destroy_context); 145EXPORT_SYMBOL_GPL(__destroy_context);
180 146
@@ -182,13 +148,11 @@ static void destroy_contexts(mm_context_t *ctx)
182{ 148{
183 int index, context_id; 149 int index, context_id;
184 150
185 spin_lock(&mmu_context_lock);
186 for (index = 0; index < ARRAY_SIZE(ctx->extended_id); index++) { 151 for (index = 0; index < ARRAY_SIZE(ctx->extended_id); index++) {
187 context_id = ctx->extended_id[index]; 152 context_id = ctx->extended_id[index];
188 if (context_id) 153 if (context_id)
189 ida_remove(&mmu_context_ida, context_id); 154 ida_free(&mmu_context_ida, context_id);
190 } 155 }
191 spin_unlock(&mmu_context_lock);
192} 156}
193 157
194static void pte_frag_destroy(void *pte_frag) 158static void pte_frag_destroy(void *pte_frag)
diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
index ff9f48812331..e59e0e60e5b5 100644
--- a/arch/powerpc/platforms/powernv/vas-window.c
+++ b/arch/powerpc/platforms/powernv/vas-window.c
@@ -515,35 +515,17 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx)
515 return 0; 515 return 0;
516} 516}
517 517
518static DEFINE_SPINLOCK(vas_ida_lock);
519
520static void vas_release_window_id(struct ida *ida, int winid) 518static void vas_release_window_id(struct ida *ida, int winid)
521{ 519{
522 spin_lock(&vas_ida_lock); 520 ida_free(ida, winid);
523 ida_remove(ida, winid);
524 spin_unlock(&vas_ida_lock);
525} 521}
526 522
527static int vas_assign_window_id(struct ida *ida) 523static int vas_assign_window_id(struct ida *ida)
528{ 524{
529 int rc, winid; 525 int winid = ida_alloc_max(ida, VAS_WINDOWS_PER_CHIP - 1, GFP_KERNEL);
530
531 do {
532 rc = ida_pre_get(ida, GFP_KERNEL);
533 if (!rc)
534 return -EAGAIN;
535
536 spin_lock(&vas_ida_lock);
537 rc = ida_get_new(ida, &winid);
538 spin_unlock(&vas_ida_lock);
539 } while (rc == -EAGAIN);
540
541 if (rc)
542 return rc;
543 526
544 if (winid > VAS_WINDOWS_PER_CHIP) { 527 if (winid == -ENOSPC) {
545 pr_err("Too many (%d) open windows\n", winid); 528 pr_err("Too many (%d) open windows\n", VAS_WINDOWS_PER_CHIP);
546 vas_release_window_id(ida, winid);
547 return -EAGAIN; 529 return -EAGAIN;
548 } 530 }
549 531
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 9ddd88bb30b7..61ec42405ec9 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -29,7 +29,7 @@ ifeq ($(CONFIG_ARCH_RV64I),y)
29 KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128) 29 KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128)
30 30
31 KBUILD_MARCH = rv64im 31 KBUILD_MARCH = rv64im
32 LDFLAGS += -melf64lriscv 32 KBUILD_LDFLAGS += -melf64lriscv
33else 33else
34 BITS := 32 34 BITS := 32
35 UTS_MACHINE := riscv32 35 UTS_MACHINE := riscv32
@@ -37,7 +37,7 @@ else
37 KBUILD_CFLAGS += -mabi=ilp32 37 KBUILD_CFLAGS += -mabi=ilp32
38 KBUILD_AFLAGS += -mabi=ilp32 38 KBUILD_AFLAGS += -mabi=ilp32
39 KBUILD_MARCH = rv32im 39 KBUILD_MARCH = rv32im
40 LDFLAGS += -melf32lriscv 40 KBUILD_LDFLAGS += -melf32lriscv
41endif 41endif
42 42
43KBUILD_CFLAGS += -Wall 43KBUILD_CFLAGS += -Wall
diff --git a/arch/riscv/include/asm/tlb.h b/arch/riscv/include/asm/tlb.h
index c229509288ea..439dc7072e05 100644
--- a/arch/riscv/include/asm/tlb.h
+++ b/arch/riscv/include/asm/tlb.h
@@ -14,6 +14,10 @@
14#ifndef _ASM_RISCV_TLB_H 14#ifndef _ASM_RISCV_TLB_H
15#define _ASM_RISCV_TLB_H 15#define _ASM_RISCV_TLB_H
16 16
17struct mmu_gather;
18
19static void tlb_flush(struct mmu_gather *tlb);
20
17#include <asm-generic/tlb.h> 21#include <asm-generic/tlb.h>
18 22
19static inline void tlb_flush(struct mmu_gather *tlb) 23static inline void tlb_flush(struct mmu_gather *tlb)
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index db20dc630e7e..aee603123030 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -85,15 +85,8 @@ atomic_t hart_lottery;
85#ifdef CONFIG_BLK_DEV_INITRD 85#ifdef CONFIG_BLK_DEV_INITRD
86static void __init setup_initrd(void) 86static void __init setup_initrd(void)
87{ 87{
88 extern char __initramfs_start[];
89 extern unsigned long __initramfs_size;
90 unsigned long size; 88 unsigned long size;
91 89
92 if (__initramfs_size > 0) {
93 initrd_start = (unsigned long)(&__initramfs_start);
94 initrd_end = initrd_start + __initramfs_size;
95 }
96
97 if (initrd_start >= initrd_end) { 90 if (initrd_start >= initrd_end) {
98 printk(KERN_INFO "initrd not found or empty"); 91 printk(KERN_INFO "initrd not found or empty");
99 goto disable; 92 goto disable;
diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c
index 568026ccf6e8..fb03a4482ad6 100644
--- a/arch/riscv/kernel/sys_riscv.c
+++ b/arch/riscv/kernel/sys_riscv.c
@@ -65,24 +65,11 @@ SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
65SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end, 65SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end,
66 uintptr_t, flags) 66 uintptr_t, flags)
67{ 67{
68#ifdef CONFIG_SMP
69 struct mm_struct *mm = current->mm;
70 bool local = (flags & SYS_RISCV_FLUSH_ICACHE_LOCAL) != 0;
71#endif
72
73 /* Check the reserved flags. */ 68 /* Check the reserved flags. */
74 if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_ALL)) 69 if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_ALL))
75 return -EINVAL; 70 return -EINVAL;
76 71
77 /* 72 flush_icache_mm(current->mm, flags & SYS_RISCV_FLUSH_ICACHE_LOCAL);
78 * Without CONFIG_SMP flush_icache_mm is a just a flush_icache_all(),
79 * which generates unused variable warnings all over this function.
80 */
81#ifdef CONFIG_SMP
82 flush_icache_mm(mm, local);
83#else
84 flush_icache_all();
85#endif
86 73
87 return 0; 74 return 0;
88} 75}
diff --git a/arch/s390/Makefile b/arch/s390/Makefile
index ba6d122526fb..ee65185bbc80 100644
--- a/arch/s390/Makefile
+++ b/arch/s390/Makefile
@@ -11,7 +11,7 @@
11# 11#
12 12
13LD_BFD := elf64-s390 13LD_BFD := elf64-s390
14LDFLAGS := -m elf64_s390 14KBUILD_LDFLAGS := -m elf64_s390
15KBUILD_AFLAGS_MODULE += -fPIC 15KBUILD_AFLAGS_MODULE += -fPIC
16KBUILD_CFLAGS_MODULE += -fPIC 16KBUILD_CFLAGS_MODULE += -fPIC
17KBUILD_AFLAGS += -m64 17KBUILD_AFLAGS += -m64
diff --git a/arch/s390/crypto/paes_s390.c b/arch/s390/crypto/paes_s390.c
index 80b27294c1de..ab9a0ebecc19 100644
--- a/arch/s390/crypto/paes_s390.c
+++ b/arch/s390/crypto/paes_s390.c
@@ -208,7 +208,7 @@ static int cbc_paes_crypt(struct blkcipher_desc *desc, unsigned long modifier,
208 walk->dst.virt.addr, walk->src.virt.addr, n); 208 walk->dst.virt.addr, walk->src.virt.addr, n);
209 if (k) 209 if (k)
210 ret = blkcipher_walk_done(desc, walk, nbytes - k); 210 ret = blkcipher_walk_done(desc, walk, nbytes - k);
211 if (n < k) { 211 if (k < n) {
212 if (__cbc_paes_set_key(ctx) != 0) 212 if (__cbc_paes_set_key(ctx) != 0)
213 return blkcipher_walk_done(desc, walk, -EIO); 213 return blkcipher_walk_done(desc, walk, -EIO);
214 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE); 214 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
diff --git a/arch/s390/include/asm/mmu.h b/arch/s390/include/asm/mmu.h
index f31a15044c24..a8418e1379eb 100644
--- a/arch/s390/include/asm/mmu.h
+++ b/arch/s390/include/asm/mmu.h
@@ -16,7 +16,13 @@ typedef struct {
16 unsigned long asce; 16 unsigned long asce;
17 unsigned long asce_limit; 17 unsigned long asce_limit;
18 unsigned long vdso_base; 18 unsigned long vdso_base;
19 /* The mmu context allocates 4K page tables. */ 19 /*
20 * The following bitfields need a down_write on the mm
21 * semaphore when they are written to. As they are only
22 * written once, they can be read without a lock.
23 *
24 * The mmu context allocates 4K page tables.
25 */
20 unsigned int alloc_pgste:1; 26 unsigned int alloc_pgste:1;
21 /* The mmu context uses extended page tables. */ 27 /* The mmu context uses extended page tables. */
22 unsigned int has_pgste:1; 28 unsigned int has_pgste:1;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 91ad4a9425c0..f69333fd2fa3 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -695,7 +695,9 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap)
695 r = -EINVAL; 695 r = -EINVAL;
696 else { 696 else {
697 r = 0; 697 r = 0;
698 down_write(&kvm->mm->mmap_sem);
698 kvm->mm->context.allow_gmap_hpage_1m = 1; 699 kvm->mm->context.allow_gmap_hpage_1m = 1;
700 up_write(&kvm->mm->mmap_sem);
699 /* 701 /*
700 * We might have to create fake 4k page 702 * We might have to create fake 4k page
701 * tables. To avoid that the hardware works on 703 * tables. To avoid that the hardware works on
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index d68f10441a16..8679bd74d337 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -280,9 +280,11 @@ retry:
280 goto retry; 280 goto retry;
281 } 281 }
282 } 282 }
283 if (rc)
284 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
285 up_read(&current->mm->mmap_sem); 283 up_read(&current->mm->mmap_sem);
284 if (rc == -EFAULT)
285 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
286 if (rc < 0)
287 return rc;
286 vcpu->run->s.regs.gprs[reg1] &= ~0xff; 288 vcpu->run->s.regs.gprs[reg1] &= ~0xff;
287 vcpu->run->s.regs.gprs[reg1] |= key; 289 vcpu->run->s.regs.gprs[reg1] |= key;
288 return 0; 290 return 0;
@@ -324,9 +326,11 @@ retry:
324 goto retry; 326 goto retry;
325 } 327 }
326 } 328 }
327 if (rc < 0)
328 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
329 up_read(&current->mm->mmap_sem); 329 up_read(&current->mm->mmap_sem);
330 if (rc == -EFAULT)
331 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
332 if (rc < 0)
333 return rc;
330 kvm_s390_set_psw_cc(vcpu, rc); 334 kvm_s390_set_psw_cc(vcpu, rc);
331 return 0; 335 return 0;
332} 336}
@@ -390,12 +394,12 @@ static int handle_sske(struct kvm_vcpu *vcpu)
390 FAULT_FLAG_WRITE, &unlocked); 394 FAULT_FLAG_WRITE, &unlocked);
391 rc = !rc ? -EAGAIN : rc; 395 rc = !rc ? -EAGAIN : rc;
392 } 396 }
397 up_read(&current->mm->mmap_sem);
393 if (rc == -EFAULT) 398 if (rc == -EFAULT)
394 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); 399 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
395 400 if (rc < 0)
396 up_read(&current->mm->mmap_sem); 401 return rc;
397 if (rc >= 0) 402 start += PAGE_SIZE;
398 start += PAGE_SIZE;
399 } 403 }
400 404
401 if (m3 & (SSKE_MC | SSKE_MR)) { 405 if (m3 & (SSKE_MC | SSKE_MR)) {
@@ -1002,13 +1006,15 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
1002 FAULT_FLAG_WRITE, &unlocked); 1006 FAULT_FLAG_WRITE, &unlocked);
1003 rc = !rc ? -EAGAIN : rc; 1007 rc = !rc ? -EAGAIN : rc;
1004 } 1008 }
1009 up_read(&current->mm->mmap_sem);
1005 if (rc == -EFAULT) 1010 if (rc == -EFAULT)
1006 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); 1011 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
1007 1012 if (rc == -EAGAIN)
1008 up_read(&current->mm->mmap_sem); 1013 continue;
1009 if (rc >= 0) 1014 if (rc < 0)
1010 start += PAGE_SIZE; 1015 return rc;
1011 } 1016 }
1017 start += PAGE_SIZE;
1012 } 1018 }
1013 if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) { 1019 if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) {
1014 if (psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_BITS_AMODE_64BIT) { 1020 if (psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_BITS_AMODE_64BIT) {
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 63844b95c22c..a2b28cd1e3fe 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
173 return set_validity_icpt(scb_s, 0x0039U); 173 return set_validity_icpt(scb_s, 0x0039U);
174 174
175 /* copy only the wrapping keys */ 175 /* copy only the wrapping keys */
176 if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56)) 176 if (read_guest_real(vcpu, crycb_addr + 72,
177 vsie_page->crycb.dea_wrapping_key_mask, 56))
177 return set_validity_icpt(scb_s, 0x0035U); 178 return set_validity_icpt(scb_s, 0x0035U);
178 179
179 scb_s->ecb3 |= ecb3_flags; 180 scb_s->ecb3 |= ecb3_flags;
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index 65300193b99f..c521ade2557c 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -122,11 +122,11 @@ endif
122ifdef CONFIG_CPU_LITTLE_ENDIAN 122ifdef CONFIG_CPU_LITTLE_ENDIAN
123ld-bfd := elf32-$(UTS_MACHINE)-linux 123ld-bfd := elf32-$(UTS_MACHINE)-linux
124LDFLAGS_vmlinux += --defsym jiffies=jiffies_64 --oformat $(ld-bfd) 124LDFLAGS_vmlinux += --defsym jiffies=jiffies_64 --oformat $(ld-bfd)
125LDFLAGS += -EL 125KBUILD_LDFLAGS += -EL
126else 126else
127ld-bfd := elf32-$(UTS_MACHINE)big-linux 127ld-bfd := elf32-$(UTS_MACHINE)big-linux
128LDFLAGS_vmlinux += --defsym jiffies=jiffies_64+4 --oformat $(ld-bfd) 128LDFLAGS_vmlinux += --defsym jiffies=jiffies_64+4 --oformat $(ld-bfd)
129LDFLAGS += -EB 129KBUILD_LDFLAGS += -EB
130endif 130endif
131 131
132export ld-bfd BITS 132export ld-bfd BITS
diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
index e32ef20de567..048a033d6102 100644
--- a/arch/sparc/Makefile
+++ b/arch/sparc/Makefile
@@ -21,7 +21,7 @@ ifeq ($(CONFIG_SPARC32),y)
21# 21#
22 22
23CHECKFLAGS += -D__sparc__ 23CHECKFLAGS += -D__sparc__
24LDFLAGS := -m elf32_sparc 24KBUILD_LDFLAGS := -m elf32_sparc
25export BITS := 32 25export BITS := 32
26UTS_MACHINE := sparc 26UTS_MACHINE := sparc
27 27
@@ -40,7 +40,7 @@ else
40# 40#
41 41
42CHECKFLAGS += -D__sparc__ -D__sparc_v9__ -D__arch64__ 42CHECKFLAGS += -D__sparc__ -D__sparc_v9__ -D__arch64__
43LDFLAGS := -m elf64_sparc 43KBUILD_LDFLAGS := -m elf64_sparc
44export BITS := 64 44export BITS := 64
45UTS_MACHINE := sparc64 45UTS_MACHINE := sparc64
46 46
diff --git a/arch/sparc/kernel/of_device_32.c b/arch/sparc/kernel/of_device_32.c
index 3641a294ed54..e4abe9b8f97a 100644
--- a/arch/sparc/kernel/of_device_32.c
+++ b/arch/sparc/kernel/of_device_32.c
@@ -9,6 +9,7 @@
9#include <linux/irq.h> 9#include <linux/irq.h>
10#include <linux/of_device.h> 10#include <linux/of_device.h>
11#include <linux/of_platform.h> 11#include <linux/of_platform.h>
12#include <linux/dma-mapping.h>
12#include <asm/leon.h> 13#include <asm/leon.h>
13#include <asm/leon_amba.h> 14#include <asm/leon_amba.h>
14 15
@@ -381,6 +382,9 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
381 else 382 else
382 dev_set_name(&op->dev, "%08x", dp->phandle); 383 dev_set_name(&op->dev, "%08x", dp->phandle);
383 384
385 op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
386 op->dev.dma_mask = &op->dev.coherent_dma_mask;
387
384 if (of_device_register(op)) { 388 if (of_device_register(op)) {
385 printk("%s: Could not register of device.\n", 389 printk("%s: Could not register of device.\n",
386 dp->full_name); 390 dp->full_name);
diff --git a/arch/sparc/kernel/of_device_64.c b/arch/sparc/kernel/of_device_64.c
index 44e4d4435bed..6df6086968c6 100644
--- a/arch/sparc/kernel/of_device_64.c
+++ b/arch/sparc/kernel/of_device_64.c
@@ -2,6 +2,7 @@
2#include <linux/string.h> 2#include <linux/string.h>
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/of.h> 4#include <linux/of.h>
5#include <linux/dma-mapping.h>
5#include <linux/init.h> 6#include <linux/init.h>
6#include <linux/export.h> 7#include <linux/export.h>
7#include <linux/mod_devicetable.h> 8#include <linux/mod_devicetable.h>
@@ -675,6 +676,8 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
675 dev_set_name(&op->dev, "root"); 676 dev_set_name(&op->dev, "root");
676 else 677 else
677 dev_set_name(&op->dev, "%08x", dp->phandle); 678 dev_set_name(&op->dev, "%08x", dp->phandle);
679 op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
680 op->dev.dma_mask = &op->dev.coherent_dma_mask;
678 681
679 if (of_device_register(op)) { 682 if (of_device_register(op)) {
680 printk("%s: Could not register of device.\n", 683 printk("%s: Could not register of device.\n",
diff --git a/arch/um/Makefile b/arch/um/Makefile
index 44ddc3e8fa66..ab1066c38944 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -133,7 +133,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
133# The wrappers will select whether using "malloc" or the kernel allocator. 133# The wrappers will select whether using "malloc" or the kernel allocator.
134LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc 134LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
135 135
136LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) 136LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt))
137 137
138# Used by link-vmlinux.sh which has special support for um link 138# Used by link-vmlinux.sh which has special support for um link
139export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) 139export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index c5ff296bc5d1..1a0be022f91d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2843,7 +2843,7 @@ config X86_SYSFB
2843 This option, if enabled, marks VGA/VBE/EFI framebuffers as generic 2843 This option, if enabled, marks VGA/VBE/EFI framebuffers as generic
2844 framebuffers so the new generic system-framebuffer drivers can be 2844 framebuffers so the new generic system-framebuffer drivers can be
2845 used on x86. If the framebuffer is not compatible with the generic 2845 used on x86. If the framebuffer is not compatible with the generic
2846 modes, it is adverticed as fallback platform framebuffer so legacy 2846 modes, it is advertised as fallback platform framebuffer so legacy
2847 drivers like efifb, vesafb and uvesafb can pick it up. 2847 drivers like efifb, vesafb and uvesafb can pick it up.
2848 If this option is not selected, all system framebuffers are always 2848 If this option is not selected, all system framebuffers are always
2849 marked as fallback platform framebuffers as usual. 2849 marked as fallback platform framebuffers as usual.
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 7e3c07d6ad42..8f6e7eb8ae9f 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -175,22 +175,6 @@ ifdef CONFIG_FUNCTION_GRAPH_TRACER
175 endif 175 endif
176endif 176endif
177 177
178ifndef CC_HAVE_ASM_GOTO
179 $(error Compiler lacks asm-goto support.)
180endif
181
182#
183# Jump labels need '-maccumulate-outgoing-args' for gcc < 4.5.2 to prevent a
184# GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46226). There's no way
185# to test for this bug at compile-time because the test case needs to execute,
186# which is a no-go for cross compilers. So check the GCC version instead.
187#
188ifdef CONFIG_JUMP_LABEL
189 ifneq ($(ACCUMULATE_OUTGOING_ARGS), 1)
190 ACCUMULATE_OUTGOING_ARGS = $(call cc-if-fullversion, -lt, 040502, 1)
191 endif
192endif
193
194ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1) 178ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
195 # This compiler flag is not supported by Clang: 179 # This compiler flag is not supported by Clang:
196 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,) 180 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
@@ -219,7 +203,7 @@ sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA2
219KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) 203KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
220KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) 204KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
221 205
222LDFLAGS := -m elf_$(UTS_MACHINE) 206KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
223 207
224# 208#
225# The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to 209# The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to
@@ -227,7 +211,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE)
227# by the linker. 211# by the linker.
228# 212#
229ifdef CONFIG_X86_64 213ifdef CONFIG_X86_64
230LDFLAGS += $(call ld-option, -z max-page-size=0x200000) 214KBUILD_LDFLAGS += $(call ld-option, -z max-page-size=0x200000)
231endif 215endif
232 216
233# Speed up the build 217# Speed up the build
@@ -312,6 +296,13 @@ PHONY += vdso_install
312vdso_install: 296vdso_install:
313 $(Q)$(MAKE) $(build)=arch/x86/entry/vdso $@ 297 $(Q)$(MAKE) $(build)=arch/x86/entry/vdso $@
314 298
299archprepare: checkbin
300checkbin:
301ifndef CC_HAVE_ASM_GOTO
302 @echo Compiler lacks asm-goto support.
303 @exit 1
304endif
305
315archclean: 306archclean:
316 $(Q)rm -rf $(objtree)/arch/i386 307 $(Q)rm -rf $(objtree)/arch/i386
317 $(Q)rm -rf $(objtree)/arch/x86_64 308 $(Q)rm -rf $(objtree)/arch/x86_64
diff --git a/arch/x86/Makefile.um b/arch/x86/Makefile.um
index 5296f8c9e7f0..91085a08de6c 100644
--- a/arch/x86/Makefile.um
+++ b/arch/x86/Makefile.um
@@ -4,7 +4,7 @@ core-y += arch/x86/crypto/
4ifeq ($(CONFIG_X86_32),y) 4ifeq ($(CONFIG_X86_32),y)
5START := 0x8048000 5START := 0x8048000
6 6
7LDFLAGS += -m elf_i386 7KBUILD_LDFLAGS += -m elf_i386
8ELF_ARCH := i386 8ELF_ARCH := i386
9ELF_FORMAT := elf32-i386 9ELF_FORMAT := elf32-i386
10CHECKFLAGS += -D__i386__ 10CHECKFLAGS += -D__i386__
@@ -43,7 +43,7 @@ KBUILD_CFLAGS += -fno-builtin -m64
43 43
44CHECKFLAGS += -m64 -D__x86_64__ 44CHECKFLAGS += -m64 -D__x86_64__
45KBUILD_AFLAGS += -m64 45KBUILD_AFLAGS += -m64
46LDFLAGS += -m elf_x86_64 46KBUILD_LDFLAGS += -m elf_x86_64
47KBUILD_CPPFLAGS += -m64 47KBUILD_CPPFLAGS += -m64
48 48
49ELF_ARCH := i386:x86-64 49ELF_ARCH := i386:x86-64
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 169c2feda14a..28764dacf018 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -42,16 +42,16 @@ KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
42GCOV_PROFILE := n 42GCOV_PROFILE := n
43UBSAN_SANITIZE :=n 43UBSAN_SANITIZE :=n
44 44
45LDFLAGS := -m elf_$(UTS_MACHINE) 45KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
46# Compressed kernel should be built as PIE since it may be loaded at any 46# Compressed kernel should be built as PIE since it may be loaded at any
47# address by the bootloader. 47# address by the bootloader.
48ifeq ($(CONFIG_X86_32),y) 48ifeq ($(CONFIG_X86_32),y)
49LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) 49KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
50else 50else
51# To build 64-bit compressed kernel as PIE, we disable relocation 51# To build 64-bit compressed kernel as PIE, we disable relocation
52# overflow check to avoid relocation overflow error with a new linker 52# overflow check to avoid relocation overflow error with a new linker
53# command-line option, -z noreloc-overflow. 53# command-line option, -z noreloc-overflow.
54LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ 54KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
55 && echo "-z noreloc-overflow -pie --no-dynamic-linker") 55 && echo "-z noreloc-overflow -pie --no-dynamic-linker")
56endif 56endif
57LDFLAGS_vmlinux := -T 57LDFLAGS_vmlinux := -T
diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
index 9bd139569b41..cb2deb61c5d9 100644
--- a/arch/x86/crypto/aesni-intel_asm.S
+++ b/arch/x86/crypto/aesni-intel_asm.S
@@ -223,34 +223,34 @@ ALL_F: .octa 0xffffffffffffffffffffffffffffffff
223 pcmpeqd TWOONE(%rip), \TMP2 223 pcmpeqd TWOONE(%rip), \TMP2
224 pand POLY(%rip), \TMP2 224 pand POLY(%rip), \TMP2
225 pxor \TMP2, \TMP3 225 pxor \TMP2, \TMP3
226 movdqa \TMP3, HashKey(%arg2) 226 movdqu \TMP3, HashKey(%arg2)
227 227
228 movdqa \TMP3, \TMP5 228 movdqa \TMP3, \TMP5
229 pshufd $78, \TMP3, \TMP1 229 pshufd $78, \TMP3, \TMP1
230 pxor \TMP3, \TMP1 230 pxor \TMP3, \TMP1
231 movdqa \TMP1, HashKey_k(%arg2) 231 movdqu \TMP1, HashKey_k(%arg2)
232 232
233 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7 233 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
234# TMP5 = HashKey^2<<1 (mod poly) 234# TMP5 = HashKey^2<<1 (mod poly)
235 movdqa \TMP5, HashKey_2(%arg2) 235 movdqu \TMP5, HashKey_2(%arg2)
236# HashKey_2 = HashKey^2<<1 (mod poly) 236# HashKey_2 = HashKey^2<<1 (mod poly)
237 pshufd $78, \TMP5, \TMP1 237 pshufd $78, \TMP5, \TMP1
238 pxor \TMP5, \TMP1 238 pxor \TMP5, \TMP1
239 movdqa \TMP1, HashKey_2_k(%arg2) 239 movdqu \TMP1, HashKey_2_k(%arg2)
240 240
241 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7 241 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
242# TMP5 = HashKey^3<<1 (mod poly) 242# TMP5 = HashKey^3<<1 (mod poly)
243 movdqa \TMP5, HashKey_3(%arg2) 243 movdqu \TMP5, HashKey_3(%arg2)
244 pshufd $78, \TMP5, \TMP1 244 pshufd $78, \TMP5, \TMP1
245 pxor \TMP5, \TMP1 245 pxor \TMP5, \TMP1
246 movdqa \TMP1, HashKey_3_k(%arg2) 246 movdqu \TMP1, HashKey_3_k(%arg2)
247 247
248 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7 248 GHASH_MUL \TMP5, \TMP3, \TMP1, \TMP2, \TMP4, \TMP6, \TMP7
249# TMP5 = HashKey^3<<1 (mod poly) 249# TMP5 = HashKey^3<<1 (mod poly)
250 movdqa \TMP5, HashKey_4(%arg2) 250 movdqu \TMP5, HashKey_4(%arg2)
251 pshufd $78, \TMP5, \TMP1 251 pshufd $78, \TMP5, \TMP1
252 pxor \TMP5, \TMP1 252 pxor \TMP5, \TMP1
253 movdqa \TMP1, HashKey_4_k(%arg2) 253 movdqu \TMP1, HashKey_4_k(%arg2)
254.endm 254.endm
255 255
256# GCM_INIT initializes a gcm_context struct to prepare for encoding/decoding. 256# GCM_INIT initializes a gcm_context struct to prepare for encoding/decoding.
@@ -271,7 +271,7 @@ ALL_F: .octa 0xffffffffffffffffffffffffffffffff
271 movdqu %xmm0, CurCount(%arg2) # ctx_data.current_counter = iv 271 movdqu %xmm0, CurCount(%arg2) # ctx_data.current_counter = iv
272 272
273 PRECOMPUTE \SUBKEY, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, 273 PRECOMPUTE \SUBKEY, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
274 movdqa HashKey(%arg2), %xmm13 274 movdqu HashKey(%arg2), %xmm13
275 275
276 CALC_AAD_HASH %xmm13, \AAD, \AADLEN, %xmm0, %xmm1, %xmm2, %xmm3, \ 276 CALC_AAD_HASH %xmm13, \AAD, \AADLEN, %xmm0, %xmm1, %xmm2, %xmm3, \
277 %xmm4, %xmm5, %xmm6 277 %xmm4, %xmm5, %xmm6
@@ -997,7 +997,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
997 pshufd $78, \XMM5, \TMP6 997 pshufd $78, \XMM5, \TMP6
998 pxor \XMM5, \TMP6 998 pxor \XMM5, \TMP6
999 paddd ONE(%rip), \XMM0 # INCR CNT 999 paddd ONE(%rip), \XMM0 # INCR CNT
1000 movdqa HashKey_4(%arg2), \TMP5 1000 movdqu HashKey_4(%arg2), \TMP5
1001 PCLMULQDQ 0x11, \TMP5, \TMP4 # TMP4 = a1*b1 1001 PCLMULQDQ 0x11, \TMP5, \TMP4 # TMP4 = a1*b1
1002 movdqa \XMM0, \XMM1 1002 movdqa \XMM0, \XMM1
1003 paddd ONE(%rip), \XMM0 # INCR CNT 1003 paddd ONE(%rip), \XMM0 # INCR CNT
@@ -1016,7 +1016,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1016 pxor (%arg1), \XMM2 1016 pxor (%arg1), \XMM2
1017 pxor (%arg1), \XMM3 1017 pxor (%arg1), \XMM3
1018 pxor (%arg1), \XMM4 1018 pxor (%arg1), \XMM4
1019 movdqa HashKey_4_k(%arg2), \TMP5 1019 movdqu HashKey_4_k(%arg2), \TMP5
1020 PCLMULQDQ 0x00, \TMP5, \TMP6 # TMP6 = (a1+a0)*(b1+b0) 1020 PCLMULQDQ 0x00, \TMP5, \TMP6 # TMP6 = (a1+a0)*(b1+b0)
1021 movaps 0x10(%arg1), \TMP1 1021 movaps 0x10(%arg1), \TMP1
1022 AESENC \TMP1, \XMM1 # Round 1 1022 AESENC \TMP1, \XMM1 # Round 1
@@ -1031,7 +1031,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1031 movdqa \XMM6, \TMP1 1031 movdqa \XMM6, \TMP1
1032 pshufd $78, \XMM6, \TMP2 1032 pshufd $78, \XMM6, \TMP2
1033 pxor \XMM6, \TMP2 1033 pxor \XMM6, \TMP2
1034 movdqa HashKey_3(%arg2), \TMP5 1034 movdqu HashKey_3(%arg2), \TMP5
1035 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1 * b1 1035 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1 * b1
1036 movaps 0x30(%arg1), \TMP3 1036 movaps 0x30(%arg1), \TMP3
1037 AESENC \TMP3, \XMM1 # Round 3 1037 AESENC \TMP3, \XMM1 # Round 3
@@ -1044,7 +1044,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1044 AESENC \TMP3, \XMM2 1044 AESENC \TMP3, \XMM2
1045 AESENC \TMP3, \XMM3 1045 AESENC \TMP3, \XMM3
1046 AESENC \TMP3, \XMM4 1046 AESENC \TMP3, \XMM4
1047 movdqa HashKey_3_k(%arg2), \TMP5 1047 movdqu HashKey_3_k(%arg2), \TMP5
1048 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1048 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1049 movaps 0x50(%arg1), \TMP3 1049 movaps 0x50(%arg1), \TMP3
1050 AESENC \TMP3, \XMM1 # Round 5 1050 AESENC \TMP3, \XMM1 # Round 5
@@ -1058,7 +1058,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1058 movdqa \XMM7, \TMP1 1058 movdqa \XMM7, \TMP1
1059 pshufd $78, \XMM7, \TMP2 1059 pshufd $78, \XMM7, \TMP2
1060 pxor \XMM7, \TMP2 1060 pxor \XMM7, \TMP2
1061 movdqa HashKey_2(%arg2), \TMP5 1061 movdqu HashKey_2(%arg2), \TMP5
1062 1062
1063 # Multiply TMP5 * HashKey using karatsuba 1063 # Multiply TMP5 * HashKey using karatsuba
1064 1064
@@ -1074,7 +1074,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1074 AESENC \TMP3, \XMM2 1074 AESENC \TMP3, \XMM2
1075 AESENC \TMP3, \XMM3 1075 AESENC \TMP3, \XMM3
1076 AESENC \TMP3, \XMM4 1076 AESENC \TMP3, \XMM4
1077 movdqa HashKey_2_k(%arg2), \TMP5 1077 movdqu HashKey_2_k(%arg2), \TMP5
1078 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1078 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1079 movaps 0x80(%arg1), \TMP3 1079 movaps 0x80(%arg1), \TMP3
1080 AESENC \TMP3, \XMM1 # Round 8 1080 AESENC \TMP3, \XMM1 # Round 8
@@ -1092,7 +1092,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1092 movdqa \XMM8, \TMP1 1092 movdqa \XMM8, \TMP1
1093 pshufd $78, \XMM8, \TMP2 1093 pshufd $78, \XMM8, \TMP2
1094 pxor \XMM8, \TMP2 1094 pxor \XMM8, \TMP2
1095 movdqa HashKey(%arg2), \TMP5 1095 movdqu HashKey(%arg2), \TMP5
1096 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1 1096 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1097 movaps 0x90(%arg1), \TMP3 1097 movaps 0x90(%arg1), \TMP3
1098 AESENC \TMP3, \XMM1 # Round 9 1098 AESENC \TMP3, \XMM1 # Round 9
@@ -1121,7 +1121,7 @@ aes_loop_par_enc_done\@:
1121 AESENCLAST \TMP3, \XMM2 1121 AESENCLAST \TMP3, \XMM2
1122 AESENCLAST \TMP3, \XMM3 1122 AESENCLAST \TMP3, \XMM3
1123 AESENCLAST \TMP3, \XMM4 1123 AESENCLAST \TMP3, \XMM4
1124 movdqa HashKey_k(%arg2), \TMP5 1124 movdqu HashKey_k(%arg2), \TMP5
1125 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1125 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1126 movdqu (%arg4,%r11,1), \TMP3 1126 movdqu (%arg4,%r11,1), \TMP3
1127 pxor \TMP3, \XMM1 # Ciphertext/Plaintext XOR EK 1127 pxor \TMP3, \XMM1 # Ciphertext/Plaintext XOR EK
@@ -1205,7 +1205,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1205 pshufd $78, \XMM5, \TMP6 1205 pshufd $78, \XMM5, \TMP6
1206 pxor \XMM5, \TMP6 1206 pxor \XMM5, \TMP6
1207 paddd ONE(%rip), \XMM0 # INCR CNT 1207 paddd ONE(%rip), \XMM0 # INCR CNT
1208 movdqa HashKey_4(%arg2), \TMP5 1208 movdqu HashKey_4(%arg2), \TMP5
1209 PCLMULQDQ 0x11, \TMP5, \TMP4 # TMP4 = a1*b1 1209 PCLMULQDQ 0x11, \TMP5, \TMP4 # TMP4 = a1*b1
1210 movdqa \XMM0, \XMM1 1210 movdqa \XMM0, \XMM1
1211 paddd ONE(%rip), \XMM0 # INCR CNT 1211 paddd ONE(%rip), \XMM0 # INCR CNT
@@ -1224,7 +1224,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1224 pxor (%arg1), \XMM2 1224 pxor (%arg1), \XMM2
1225 pxor (%arg1), \XMM3 1225 pxor (%arg1), \XMM3
1226 pxor (%arg1), \XMM4 1226 pxor (%arg1), \XMM4
1227 movdqa HashKey_4_k(%arg2), \TMP5 1227 movdqu HashKey_4_k(%arg2), \TMP5
1228 PCLMULQDQ 0x00, \TMP5, \TMP6 # TMP6 = (a1+a0)*(b1+b0) 1228 PCLMULQDQ 0x00, \TMP5, \TMP6 # TMP6 = (a1+a0)*(b1+b0)
1229 movaps 0x10(%arg1), \TMP1 1229 movaps 0x10(%arg1), \TMP1
1230 AESENC \TMP1, \XMM1 # Round 1 1230 AESENC \TMP1, \XMM1 # Round 1
@@ -1239,7 +1239,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1239 movdqa \XMM6, \TMP1 1239 movdqa \XMM6, \TMP1
1240 pshufd $78, \XMM6, \TMP2 1240 pshufd $78, \XMM6, \TMP2
1241 pxor \XMM6, \TMP2 1241 pxor \XMM6, \TMP2
1242 movdqa HashKey_3(%arg2), \TMP5 1242 movdqu HashKey_3(%arg2), \TMP5
1243 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1 * b1 1243 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1 * b1
1244 movaps 0x30(%arg1), \TMP3 1244 movaps 0x30(%arg1), \TMP3
1245 AESENC \TMP3, \XMM1 # Round 3 1245 AESENC \TMP3, \XMM1 # Round 3
@@ -1252,7 +1252,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1252 AESENC \TMP3, \XMM2 1252 AESENC \TMP3, \XMM2
1253 AESENC \TMP3, \XMM3 1253 AESENC \TMP3, \XMM3
1254 AESENC \TMP3, \XMM4 1254 AESENC \TMP3, \XMM4
1255 movdqa HashKey_3_k(%arg2), \TMP5 1255 movdqu HashKey_3_k(%arg2), \TMP5
1256 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1256 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1257 movaps 0x50(%arg1), \TMP3 1257 movaps 0x50(%arg1), \TMP3
1258 AESENC \TMP3, \XMM1 # Round 5 1258 AESENC \TMP3, \XMM1 # Round 5
@@ -1266,7 +1266,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1266 movdqa \XMM7, \TMP1 1266 movdqa \XMM7, \TMP1
1267 pshufd $78, \XMM7, \TMP2 1267 pshufd $78, \XMM7, \TMP2
1268 pxor \XMM7, \TMP2 1268 pxor \XMM7, \TMP2
1269 movdqa HashKey_2(%arg2), \TMP5 1269 movdqu HashKey_2(%arg2), \TMP5
1270 1270
1271 # Multiply TMP5 * HashKey using karatsuba 1271 # Multiply TMP5 * HashKey using karatsuba
1272 1272
@@ -1282,7 +1282,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1282 AESENC \TMP3, \XMM2 1282 AESENC \TMP3, \XMM2
1283 AESENC \TMP3, \XMM3 1283 AESENC \TMP3, \XMM3
1284 AESENC \TMP3, \XMM4 1284 AESENC \TMP3, \XMM4
1285 movdqa HashKey_2_k(%arg2), \TMP5 1285 movdqu HashKey_2_k(%arg2), \TMP5
1286 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1286 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1287 movaps 0x80(%arg1), \TMP3 1287 movaps 0x80(%arg1), \TMP3
1288 AESENC \TMP3, \XMM1 # Round 8 1288 AESENC \TMP3, \XMM1 # Round 8
@@ -1300,7 +1300,7 @@ TMP6 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 operation
1300 movdqa \XMM8, \TMP1 1300 movdqa \XMM8, \TMP1
1301 pshufd $78, \XMM8, \TMP2 1301 pshufd $78, \XMM8, \TMP2
1302 pxor \XMM8, \TMP2 1302 pxor \XMM8, \TMP2
1303 movdqa HashKey(%arg2), \TMP5 1303 movdqu HashKey(%arg2), \TMP5
1304 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1 1304 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1305 movaps 0x90(%arg1), \TMP3 1305 movaps 0x90(%arg1), \TMP3
1306 AESENC \TMP3, \XMM1 # Round 9 1306 AESENC \TMP3, \XMM1 # Round 9
@@ -1329,7 +1329,7 @@ aes_loop_par_dec_done\@:
1329 AESENCLAST \TMP3, \XMM2 1329 AESENCLAST \TMP3, \XMM2
1330 AESENCLAST \TMP3, \XMM3 1330 AESENCLAST \TMP3, \XMM3
1331 AESENCLAST \TMP3, \XMM4 1331 AESENCLAST \TMP3, \XMM4
1332 movdqa HashKey_k(%arg2), \TMP5 1332 movdqu HashKey_k(%arg2), \TMP5
1333 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1333 PCLMULQDQ 0x00, \TMP5, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1334 movdqu (%arg4,%r11,1), \TMP3 1334 movdqu (%arg4,%r11,1), \TMP3
1335 pxor \TMP3, \XMM1 # Ciphertext/Plaintext XOR EK 1335 pxor \TMP3, \XMM1 # Ciphertext/Plaintext XOR EK
@@ -1405,10 +1405,10 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
1405 movdqa \XMM1, \TMP6 1405 movdqa \XMM1, \TMP6
1406 pshufd $78, \XMM1, \TMP2 1406 pshufd $78, \XMM1, \TMP2
1407 pxor \XMM1, \TMP2 1407 pxor \XMM1, \TMP2
1408 movdqa HashKey_4(%arg2), \TMP5 1408 movdqu HashKey_4(%arg2), \TMP5
1409 PCLMULQDQ 0x11, \TMP5, \TMP6 # TMP6 = a1*b1 1409 PCLMULQDQ 0x11, \TMP5, \TMP6 # TMP6 = a1*b1
1410 PCLMULQDQ 0x00, \TMP5, \XMM1 # XMM1 = a0*b0 1410 PCLMULQDQ 0x00, \TMP5, \XMM1 # XMM1 = a0*b0
1411 movdqa HashKey_4_k(%arg2), \TMP4 1411 movdqu HashKey_4_k(%arg2), \TMP4
1412 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1412 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1413 movdqa \XMM1, \XMMDst 1413 movdqa \XMM1, \XMMDst
1414 movdqa \TMP2, \XMM1 # result in TMP6, XMMDst, XMM1 1414 movdqa \TMP2, \XMM1 # result in TMP6, XMMDst, XMM1
@@ -1418,10 +1418,10 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
1418 movdqa \XMM2, \TMP1 1418 movdqa \XMM2, \TMP1
1419 pshufd $78, \XMM2, \TMP2 1419 pshufd $78, \XMM2, \TMP2
1420 pxor \XMM2, \TMP2 1420 pxor \XMM2, \TMP2
1421 movdqa HashKey_3(%arg2), \TMP5 1421 movdqu HashKey_3(%arg2), \TMP5
1422 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1 1422 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1423 PCLMULQDQ 0x00, \TMP5, \XMM2 # XMM2 = a0*b0 1423 PCLMULQDQ 0x00, \TMP5, \XMM2 # XMM2 = a0*b0
1424 movdqa HashKey_3_k(%arg2), \TMP4 1424 movdqu HashKey_3_k(%arg2), \TMP4
1425 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1425 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1426 pxor \TMP1, \TMP6 1426 pxor \TMP1, \TMP6
1427 pxor \XMM2, \XMMDst 1427 pxor \XMM2, \XMMDst
@@ -1433,10 +1433,10 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
1433 movdqa \XMM3, \TMP1 1433 movdqa \XMM3, \TMP1
1434 pshufd $78, \XMM3, \TMP2 1434 pshufd $78, \XMM3, \TMP2
1435 pxor \XMM3, \TMP2 1435 pxor \XMM3, \TMP2
1436 movdqa HashKey_2(%arg2), \TMP5 1436 movdqu HashKey_2(%arg2), \TMP5
1437 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1 1437 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1438 PCLMULQDQ 0x00, \TMP5, \XMM3 # XMM3 = a0*b0 1438 PCLMULQDQ 0x00, \TMP5, \XMM3 # XMM3 = a0*b0
1439 movdqa HashKey_2_k(%arg2), \TMP4 1439 movdqu HashKey_2_k(%arg2), \TMP4
1440 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1440 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1441 pxor \TMP1, \TMP6 1441 pxor \TMP1, \TMP6
1442 pxor \XMM3, \XMMDst 1442 pxor \XMM3, \XMMDst
@@ -1446,10 +1446,10 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
1446 movdqa \XMM4, \TMP1 1446 movdqa \XMM4, \TMP1
1447 pshufd $78, \XMM4, \TMP2 1447 pshufd $78, \XMM4, \TMP2
1448 pxor \XMM4, \TMP2 1448 pxor \XMM4, \TMP2
1449 movdqa HashKey(%arg2), \TMP5 1449 movdqu HashKey(%arg2), \TMP5
1450 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1 1450 PCLMULQDQ 0x11, \TMP5, \TMP1 # TMP1 = a1*b1
1451 PCLMULQDQ 0x00, \TMP5, \XMM4 # XMM4 = a0*b0 1451 PCLMULQDQ 0x00, \TMP5, \XMM4 # XMM4 = a0*b0
1452 movdqa HashKey_k(%arg2), \TMP4 1452 movdqu HashKey_k(%arg2), \TMP4
1453 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0) 1453 PCLMULQDQ 0x00, \TMP4, \TMP2 # TMP2 = (a1+a0)*(b1+b0)
1454 pxor \TMP1, \TMP6 1454 pxor \TMP1, \TMP6
1455 pxor \XMM4, \XMMDst 1455 pxor \XMM4, \XMMDst
diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index 9f695f517747..fa3f439f0a92 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -68,9 +68,9 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
68CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \ 68CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
69 $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \ 69 $(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
70 -fno-omit-frame-pointer -foptimize-sibling-calls \ 70 -fno-omit-frame-pointer -foptimize-sibling-calls \
71 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO 71 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO $(RETPOLINE_VDSO_CFLAGS)
72 72
73$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) 73$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
74 74
75# 75#
76# vDSO code runs in userspace and -pg doesn't help with profiling anyway. 76# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
@@ -132,11 +132,13 @@ KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
132KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) 132KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
133KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) 133KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
134KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) 134KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
135KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
135KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic 136KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
136KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) 137KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
137KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) 138KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
138KBUILD_CFLAGS_32 += -fno-omit-frame-pointer 139KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
139KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING 140KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
141KBUILD_CFLAGS_32 += $(RETPOLINE_VDSO_CFLAGS)
140$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) 142$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
141 143
142$(obj)/vdso32.so.dbg: FORCE \ 144$(obj)/vdso32.so.dbg: FORCE \
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 5f4829f10129..dfb2f7c0d019 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2465,7 +2465,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
2465 2465
2466 perf_callchain_store(entry, regs->ip); 2466 perf_callchain_store(entry, regs->ip);
2467 2467
2468 if (!current->mm) 2468 if (!nmi_uaccess_okay())
2469 return; 2469 return;
2470 2470
2471 if (perf_callchain_user32(regs, entry)) 2471 if (perf_callchain_user32(regs, entry))
diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index b143717b92b3..ce84388e540c 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -80,11 +80,11 @@ static __always_inline void arch_atomic_sub(int i, atomic_t *v)
80 * true if the result is zero, or false for all 80 * true if the result is zero, or false for all
81 * other cases. 81 * other cases.
82 */ 82 */
83#define arch_atomic_sub_and_test arch_atomic_sub_and_test
84static __always_inline bool arch_atomic_sub_and_test(int i, atomic_t *v) 83static __always_inline bool arch_atomic_sub_and_test(int i, atomic_t *v)
85{ 84{
86 GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", e); 85 GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", e);
87} 86}
87#define arch_atomic_sub_and_test arch_atomic_sub_and_test
88 88
89/** 89/**
90 * arch_atomic_inc - increment atomic variable 90 * arch_atomic_inc - increment atomic variable
@@ -92,12 +92,12 @@ static __always_inline bool arch_atomic_sub_and_test(int i, atomic_t *v)
92 * 92 *
93 * Atomically increments @v by 1. 93 * Atomically increments @v by 1.
94 */ 94 */
95#define arch_atomic_inc arch_atomic_inc
96static __always_inline void arch_atomic_inc(atomic_t *v) 95static __always_inline void arch_atomic_inc(atomic_t *v)
97{ 96{
98 asm volatile(LOCK_PREFIX "incl %0" 97 asm volatile(LOCK_PREFIX "incl %0"
99 : "+m" (v->counter)); 98 : "+m" (v->counter));
100} 99}
100#define arch_atomic_inc arch_atomic_inc
101 101
102/** 102/**
103 * arch_atomic_dec - decrement atomic variable 103 * arch_atomic_dec - decrement atomic variable
@@ -105,12 +105,12 @@ static __always_inline void arch_atomic_inc(atomic_t *v)
105 * 105 *
106 * Atomically decrements @v by 1. 106 * Atomically decrements @v by 1.
107 */ 107 */
108#define arch_atomic_dec arch_atomic_dec
109static __always_inline void arch_atomic_dec(atomic_t *v) 108static __always_inline void arch_atomic_dec(atomic_t *v)
110{ 109{
111 asm volatile(LOCK_PREFIX "decl %0" 110 asm volatile(LOCK_PREFIX "decl %0"
112 : "+m" (v->counter)); 111 : "+m" (v->counter));
113} 112}
113#define arch_atomic_dec arch_atomic_dec
114 114
115/** 115/**
116 * arch_atomic_dec_and_test - decrement and test 116 * arch_atomic_dec_and_test - decrement and test
@@ -120,11 +120,11 @@ static __always_inline void arch_atomic_dec(atomic_t *v)
120 * returns true if the result is 0, or false for all other 120 * returns true if the result is 0, or false for all other
121 * cases. 121 * cases.
122 */ 122 */
123#define arch_atomic_dec_and_test arch_atomic_dec_and_test
124static __always_inline bool arch_atomic_dec_and_test(atomic_t *v) 123static __always_inline bool arch_atomic_dec_and_test(atomic_t *v)
125{ 124{
126 GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", e); 125 GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", e);
127} 126}
127#define arch_atomic_dec_and_test arch_atomic_dec_and_test
128 128
129/** 129/**
130 * arch_atomic_inc_and_test - increment and test 130 * arch_atomic_inc_and_test - increment and test
@@ -134,11 +134,11 @@ static __always_inline bool arch_atomic_dec_and_test(atomic_t *v)
134 * and returns true if the result is zero, or false for all 134 * and returns true if the result is zero, or false for all
135 * other cases. 135 * other cases.
136 */ 136 */
137#define arch_atomic_inc_and_test arch_atomic_inc_and_test
138static __always_inline bool arch_atomic_inc_and_test(atomic_t *v) 137static __always_inline bool arch_atomic_inc_and_test(atomic_t *v)
139{ 138{
140 GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", e); 139 GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", e);
141} 140}
141#define arch_atomic_inc_and_test arch_atomic_inc_and_test
142 142
143/** 143/**
144 * arch_atomic_add_negative - add and test if negative 144 * arch_atomic_add_negative - add and test if negative
@@ -149,11 +149,11 @@ static __always_inline bool arch_atomic_inc_and_test(atomic_t *v)
149 * if the result is negative, or false when 149 * if the result is negative, or false when
150 * result is greater than or equal to zero. 150 * result is greater than or equal to zero.
151 */ 151 */
152#define arch_atomic_add_negative arch_atomic_add_negative
153static __always_inline bool arch_atomic_add_negative(int i, atomic_t *v) 152static __always_inline bool arch_atomic_add_negative(int i, atomic_t *v)
154{ 153{
155 GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", s); 154 GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", s);
156} 155}
156#define arch_atomic_add_negative arch_atomic_add_negative
157 157
158/** 158/**
159 * arch_atomic_add_return - add integer and return 159 * arch_atomic_add_return - add integer and return
diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
index ef959f02d070..6a5b0ec460da 100644
--- a/arch/x86/include/asm/atomic64_32.h
+++ b/arch/x86/include/asm/atomic64_32.h
@@ -205,12 +205,12 @@ static inline long long arch_atomic64_sub(long long i, atomic64_t *v)
205 * 205 *
206 * Atomically increments @v by 1. 206 * Atomically increments @v by 1.
207 */ 207 */
208#define arch_atomic64_inc arch_atomic64_inc
209static inline void arch_atomic64_inc(atomic64_t *v) 208static inline void arch_atomic64_inc(atomic64_t *v)
210{ 209{
211 __alternative_atomic64(inc, inc_return, /* no output */, 210 __alternative_atomic64(inc, inc_return, /* no output */,
212 "S" (v) : "memory", "eax", "ecx", "edx"); 211 "S" (v) : "memory", "eax", "ecx", "edx");
213} 212}
213#define arch_atomic64_inc arch_atomic64_inc
214 214
215/** 215/**
216 * arch_atomic64_dec - decrement atomic64 variable 216 * arch_atomic64_dec - decrement atomic64 variable
@@ -218,12 +218,12 @@ static inline void arch_atomic64_inc(atomic64_t *v)
218 * 218 *
219 * Atomically decrements @v by 1. 219 * Atomically decrements @v by 1.
220 */ 220 */
221#define arch_atomic64_dec arch_atomic64_dec
222static inline void arch_atomic64_dec(atomic64_t *v) 221static inline void arch_atomic64_dec(atomic64_t *v)
223{ 222{
224 __alternative_atomic64(dec, dec_return, /* no output */, 223 __alternative_atomic64(dec, dec_return, /* no output */,
225 "S" (v) : "memory", "eax", "ecx", "edx"); 224 "S" (v) : "memory", "eax", "ecx", "edx");
226} 225}
226#define arch_atomic64_dec arch_atomic64_dec
227 227
228/** 228/**
229 * arch_atomic64_add_unless - add unless the number is a given value 229 * arch_atomic64_add_unless - add unless the number is a given value
@@ -245,7 +245,6 @@ static inline int arch_atomic64_add_unless(atomic64_t *v, long long a,
245 return (int)a; 245 return (int)a;
246} 246}
247 247
248#define arch_atomic64_inc_not_zero arch_atomic64_inc_not_zero
249static inline int arch_atomic64_inc_not_zero(atomic64_t *v) 248static inline int arch_atomic64_inc_not_zero(atomic64_t *v)
250{ 249{
251 int r; 250 int r;
@@ -253,8 +252,8 @@ static inline int arch_atomic64_inc_not_zero(atomic64_t *v)
253 "S" (v) : "ecx", "edx", "memory"); 252 "S" (v) : "ecx", "edx", "memory");
254 return r; 253 return r;
255} 254}
255#define arch_atomic64_inc_not_zero arch_atomic64_inc_not_zero
256 256
257#define arch_atomic64_dec_if_positive arch_atomic64_dec_if_positive
258static inline long long arch_atomic64_dec_if_positive(atomic64_t *v) 257static inline long long arch_atomic64_dec_if_positive(atomic64_t *v)
259{ 258{
260 long long r; 259 long long r;
@@ -262,6 +261,7 @@ static inline long long arch_atomic64_dec_if_positive(atomic64_t *v)
262 "S" (v) : "ecx", "memory"); 261 "S" (v) : "ecx", "memory");
263 return r; 262 return r;
264} 263}
264#define arch_atomic64_dec_if_positive arch_atomic64_dec_if_positive
265 265
266#undef alternative_atomic64 266#undef alternative_atomic64
267#undef __alternative_atomic64 267#undef __alternative_atomic64
diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
index 4343d9b4f30e..5f851d92eecd 100644
--- a/arch/x86/include/asm/atomic64_64.h
+++ b/arch/x86/include/asm/atomic64_64.h
@@ -71,11 +71,11 @@ static inline void arch_atomic64_sub(long i, atomic64_t *v)
71 * true if the result is zero, or false for all 71 * true if the result is zero, or false for all
72 * other cases. 72 * other cases.
73 */ 73 */
74#define arch_atomic64_sub_and_test arch_atomic64_sub_and_test
75static inline bool arch_atomic64_sub_and_test(long i, atomic64_t *v) 74static inline bool arch_atomic64_sub_and_test(long i, atomic64_t *v)
76{ 75{
77 GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", e); 76 GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", e);
78} 77}
78#define arch_atomic64_sub_and_test arch_atomic64_sub_and_test
79 79
80/** 80/**
81 * arch_atomic64_inc - increment atomic64 variable 81 * arch_atomic64_inc - increment atomic64 variable
@@ -83,13 +83,13 @@ static inline bool arch_atomic64_sub_and_test(long i, atomic64_t *v)
83 * 83 *
84 * Atomically increments @v by 1. 84 * Atomically increments @v by 1.
85 */ 85 */
86#define arch_atomic64_inc arch_atomic64_inc
87static __always_inline void arch_atomic64_inc(atomic64_t *v) 86static __always_inline void arch_atomic64_inc(atomic64_t *v)
88{ 87{
89 asm volatile(LOCK_PREFIX "incq %0" 88 asm volatile(LOCK_PREFIX "incq %0"
90 : "=m" (v->counter) 89 : "=m" (v->counter)
91 : "m" (v->counter)); 90 : "m" (v->counter));
92} 91}
92#define arch_atomic64_inc arch_atomic64_inc
93 93
94/** 94/**
95 * arch_atomic64_dec - decrement atomic64 variable 95 * arch_atomic64_dec - decrement atomic64 variable
@@ -97,13 +97,13 @@ static __always_inline void arch_atomic64_inc(atomic64_t *v)
97 * 97 *
98 * Atomically decrements @v by 1. 98 * Atomically decrements @v by 1.
99 */ 99 */
100#define arch_atomic64_dec arch_atomic64_dec
101static __always_inline void arch_atomic64_dec(atomic64_t *v) 100static __always_inline void arch_atomic64_dec(atomic64_t *v)
102{ 101{
103 asm volatile(LOCK_PREFIX "decq %0" 102 asm volatile(LOCK_PREFIX "decq %0"
104 : "=m" (v->counter) 103 : "=m" (v->counter)
105 : "m" (v->counter)); 104 : "m" (v->counter));
106} 105}
106#define arch_atomic64_dec arch_atomic64_dec
107 107
108/** 108/**
109 * arch_atomic64_dec_and_test - decrement and test 109 * arch_atomic64_dec_and_test - decrement and test
@@ -113,11 +113,11 @@ static __always_inline void arch_atomic64_dec(atomic64_t *v)
113 * returns true if the result is 0, or false for all other 113 * returns true if the result is 0, or false for all other
114 * cases. 114 * cases.
115 */ 115 */
116#define arch_atomic64_dec_and_test arch_atomic64_dec_and_test
117static inline bool arch_atomic64_dec_and_test(atomic64_t *v) 116static inline bool arch_atomic64_dec_and_test(atomic64_t *v)
118{ 117{
119 GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", e); 118 GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", e);
120} 119}
120#define arch_atomic64_dec_and_test arch_atomic64_dec_and_test
121 121
122/** 122/**
123 * arch_atomic64_inc_and_test - increment and test 123 * arch_atomic64_inc_and_test - increment and test
@@ -127,11 +127,11 @@ static inline bool arch_atomic64_dec_and_test(atomic64_t *v)
127 * and returns true if the result is zero, or false for all 127 * and returns true if the result is zero, or false for all
128 * other cases. 128 * other cases.
129 */ 129 */
130#define arch_atomic64_inc_and_test arch_atomic64_inc_and_test
131static inline bool arch_atomic64_inc_and_test(atomic64_t *v) 130static inline bool arch_atomic64_inc_and_test(atomic64_t *v)
132{ 131{
133 GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", e); 132 GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", e);
134} 133}
134#define arch_atomic64_inc_and_test arch_atomic64_inc_and_test
135 135
136/** 136/**
137 * arch_atomic64_add_negative - add and test if negative 137 * arch_atomic64_add_negative - add and test if negative
@@ -142,11 +142,11 @@ static inline bool arch_atomic64_inc_and_test(atomic64_t *v)
142 * if the result is negative, or false when 142 * if the result is negative, or false when
143 * result is greater than or equal to zero. 143 * result is greater than or equal to zero.
144 */ 144 */
145#define arch_atomic64_add_negative arch_atomic64_add_negative
146static inline bool arch_atomic64_add_negative(long i, atomic64_t *v) 145static inline bool arch_atomic64_add_negative(long i, atomic64_t *v)
147{ 146{
148 GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", s); 147 GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", s);
149} 148}
149#define arch_atomic64_add_negative arch_atomic64_add_negative
150 150
151/** 151/**
152 * arch_atomic64_add_return - add and return 152 * arch_atomic64_add_return - add and return
diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index c14f2a74b2be..15450a675031 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -33,7 +33,8 @@ extern inline unsigned long native_save_fl(void)
33 return flags; 33 return flags;
34} 34}
35 35
36static inline void native_restore_fl(unsigned long flags) 36extern inline void native_restore_fl(unsigned long flags);
37extern inline void native_restore_fl(unsigned long flags)
37{ 38{
38 asm volatile("push %0 ; popf" 39 asm volatile("push %0 ; popf"
39 : /* no output */ 40 : /* no output */
diff --git a/arch/x86/include/asm/kdebug.h b/arch/x86/include/asm/kdebug.h
index 395c9631e000..75f1e35e7c15 100644
--- a/arch/x86/include/asm/kdebug.h
+++ b/arch/x86/include/asm/kdebug.h
@@ -22,10 +22,20 @@ enum die_val {
22 DIE_NMIUNKNOWN, 22 DIE_NMIUNKNOWN,
23}; 23};
24 24
25enum show_regs_mode {
26 SHOW_REGS_SHORT,
27 /*
28 * For when userspace crashed, but we don't think it's our fault, and
29 * therefore don't print kernel registers.
30 */
31 SHOW_REGS_USER,
32 SHOW_REGS_ALL
33};
34
25extern void die(const char *, struct pt_regs *,long); 35extern void die(const char *, struct pt_regs *,long);
26extern int __must_check __die(const char *, struct pt_regs *, long); 36extern int __must_check __die(const char *, struct pt_regs *, long);
27extern void show_stack_regs(struct pt_regs *regs); 37extern void show_stack_regs(struct pt_regs *regs);
28extern void __show_regs(struct pt_regs *regs, int all); 38extern void __show_regs(struct pt_regs *regs, enum show_regs_mode);
29extern void show_iret_regs(struct pt_regs *regs); 39extern void show_iret_regs(struct pt_regs *regs);
30extern unsigned long oops_begin(void); 40extern unsigned long oops_begin(void);
31extern void oops_end(unsigned long, struct pt_regs *, int signr); 41extern void oops_end(unsigned long, struct pt_regs *, int signr);
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 00ddb0c9e612..8e90488c3d56 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1237,19 +1237,12 @@ enum emulation_result {
1237#define EMULTYPE_NO_DECODE (1 << 0) 1237#define EMULTYPE_NO_DECODE (1 << 0)
1238#define EMULTYPE_TRAP_UD (1 << 1) 1238#define EMULTYPE_TRAP_UD (1 << 1)
1239#define EMULTYPE_SKIP (1 << 2) 1239#define EMULTYPE_SKIP (1 << 2)
1240#define EMULTYPE_RETRY (1 << 3) 1240#define EMULTYPE_ALLOW_RETRY (1 << 3)
1241#define EMULTYPE_NO_REEXECUTE (1 << 4) 1241#define EMULTYPE_NO_UD_ON_FAIL (1 << 4)
1242#define EMULTYPE_NO_UD_ON_FAIL (1 << 5) 1242#define EMULTYPE_VMWARE (1 << 5)
1243#define EMULTYPE_VMWARE (1 << 6) 1243int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type);
1244int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2, 1244int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
1245 int emulation_type, void *insn, int insn_len); 1245 void *insn, int insn_len);
1246
1247static inline int emulate_instruction(struct kvm_vcpu *vcpu,
1248 int emulation_type)
1249{
1250 return x86_emulate_instruction(vcpu, 0,
1251 emulation_type | EMULTYPE_NO_REEXECUTE, NULL, 0);
1252}
1253 1246
1254void kvm_enable_efer_bits(u64); 1247void kvm_enable_efer_bits(u64);
1255bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer); 1248bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
@@ -1450,7 +1443,6 @@ asmlinkage void kvm_spurious_fault(void);
1450 ____kvm_handle_fault_on_reboot(insn, "") 1443 ____kvm_handle_fault_on_reboot(insn, "")
1451 1444
1452#define KVM_ARCH_WANT_MMU_NOTIFIER 1445#define KVM_ARCH_WANT_MMU_NOTIFIER
1453int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
1454int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); 1446int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end);
1455int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); 1447int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
1456int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); 1448int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
@@ -1463,7 +1455,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event);
1463void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu); 1455void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu);
1464 1456
1465int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low, 1457int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
1466 unsigned long ipi_bitmap_high, int min, 1458 unsigned long ipi_bitmap_high, u32 min,
1467 unsigned long icr, int op_64_bit); 1459 unsigned long icr, int op_64_bit);
1468 1460
1469u64 kvm_get_arch_capabilities(void); 1461u64 kvm_get_arch_capabilities(void);
diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
index 8c7b3e5a2d01..3a17107594c8 100644
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -148,6 +148,7 @@ enum mce_notifier_prios {
148 MCE_PRIO_LOWEST = 0, 148 MCE_PRIO_LOWEST = 0,
149}; 149};
150 150
151struct notifier_block;
151extern void mce_register_decode_chain(struct notifier_block *nb); 152extern void mce_register_decode_chain(struct notifier_block *nb);
152extern void mce_unregister_decode_chain(struct notifier_block *nb); 153extern void mce_unregister_decode_chain(struct notifier_block *nb);
153 154
diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
index a564084c6141..f8b1ad2c3828 100644
--- a/arch/x86/include/asm/pgtable-3level.h
+++ b/arch/x86/include/asm/pgtable-3level.h
@@ -2,6 +2,8 @@
2#ifndef _ASM_X86_PGTABLE_3LEVEL_H 2#ifndef _ASM_X86_PGTABLE_3LEVEL_H
3#define _ASM_X86_PGTABLE_3LEVEL_H 3#define _ASM_X86_PGTABLE_3LEVEL_H
4 4
5#include <asm/atomic64_32.h>
6
5/* 7/*
6 * Intel Physical Address Extension (PAE) Mode - three-level page 8 * Intel Physical Address Extension (PAE) Mode - three-level page
7 * tables on PPro+ CPUs. 9 * tables on PPro+ CPUs.
@@ -150,10 +152,7 @@ static inline pte_t native_ptep_get_and_clear(pte_t *ptep)
150{ 152{
151 pte_t res; 153 pte_t res;
152 154
153 /* xchg acts as a barrier before the setting of the high bits */ 155 res.pte = (pteval_t)arch_atomic64_xchg((atomic64_t *)ptep, 0);
154 res.pte_low = xchg(&ptep->pte_low, 0);
155 res.pte_high = ptep->pte_high;
156 ptep->pte_high = 0;
157 156
158 return res; 157 return res;
159} 158}
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index e4ffa565a69f..690c0307afed 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1195,7 +1195,7 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
1195 return xchg(pmdp, pmd); 1195 return xchg(pmdp, pmd);
1196 } else { 1196 } else {
1197 pmd_t old = *pmdp; 1197 pmd_t old = *pmdp;
1198 *pmdp = pmd; 1198 WRITE_ONCE(*pmdp, pmd);
1199 return old; 1199 return old;
1200 } 1200 }
1201} 1201}
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index f773d5e6c8cc..ce2b59047cb8 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -55,15 +55,15 @@ struct mm_struct;
55void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte); 55void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte);
56void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte); 56void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
57 57
58static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr, 58static inline void native_set_pte(pte_t *ptep, pte_t pte)
59 pte_t *ptep)
60{ 59{
61 *ptep = native_make_pte(0); 60 WRITE_ONCE(*ptep, pte);
62} 61}
63 62
64static inline void native_set_pte(pte_t *ptep, pte_t pte) 63static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
64 pte_t *ptep)
65{ 65{
66 *ptep = pte; 66 native_set_pte(ptep, native_make_pte(0));
67} 67}
68 68
69static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte) 69static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
@@ -73,7 +73,7 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
73 73
74static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd) 74static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
75{ 75{
76 *pmdp = pmd; 76 WRITE_ONCE(*pmdp, pmd);
77} 77}
78 78
79static inline void native_pmd_clear(pmd_t *pmd) 79static inline void native_pmd_clear(pmd_t *pmd)
@@ -109,7 +109,7 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
109 109
110static inline void native_set_pud(pud_t *pudp, pud_t pud) 110static inline void native_set_pud(pud_t *pudp, pud_t pud)
111{ 111{
112 *pudp = pud; 112 WRITE_ONCE(*pudp, pud);
113} 113}
114 114
115static inline void native_pud_clear(pud_t *pud) 115static inline void native_pud_clear(pud_t *pud)
@@ -137,13 +137,13 @@ static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d)
137 pgd_t pgd; 137 pgd_t pgd;
138 138
139 if (pgtable_l5_enabled() || !IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION)) { 139 if (pgtable_l5_enabled() || !IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION)) {
140 *p4dp = p4d; 140 WRITE_ONCE(*p4dp, p4d);
141 return; 141 return;
142 } 142 }
143 143
144 pgd = native_make_pgd(native_p4d_val(p4d)); 144 pgd = native_make_pgd(native_p4d_val(p4d));
145 pgd = pti_set_user_pgtbl((pgd_t *)p4dp, pgd); 145 pgd = pti_set_user_pgtbl((pgd_t *)p4dp, pgd);
146 *p4dp = native_make_p4d(native_pgd_val(pgd)); 146 WRITE_ONCE(*p4dp, native_make_p4d(native_pgd_val(pgd)));
147} 147}
148 148
149static inline void native_p4d_clear(p4d_t *p4d) 149static inline void native_p4d_clear(p4d_t *p4d)
@@ -153,7 +153,7 @@ static inline void native_p4d_clear(p4d_t *p4d)
153 153
154static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd) 154static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
155{ 155{
156 *pgdp = pti_set_user_pgtbl(pgdp, pgd); 156 WRITE_ONCE(*pgdp, pti_set_user_pgtbl(pgdp, pgd));
157} 157}
158 158
159static inline void native_pgd_clear(pgd_t *pgd) 159static inline void native_pgd_clear(pgd_t *pgd)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 682286aca881..d53c54b842da 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -132,6 +132,8 @@ struct cpuinfo_x86 {
132 /* Index into per_cpu list: */ 132 /* Index into per_cpu list: */
133 u16 cpu_index; 133 u16 cpu_index;
134 u32 microcode; 134 u32 microcode;
135 /* Address space bits used by the cache internally */
136 u8 x86_cache_bits;
135 unsigned initialized : 1; 137 unsigned initialized : 1;
136} __randomize_layout; 138} __randomize_layout;
137 139
@@ -181,9 +183,9 @@ extern const struct seq_operations cpuinfo_op;
181 183
182extern void cpu_detect(struct cpuinfo_x86 *c); 184extern void cpu_detect(struct cpuinfo_x86 *c);
183 185
184static inline unsigned long l1tf_pfn_limit(void) 186static inline unsigned long long l1tf_pfn_limit(void)
185{ 187{
186 return BIT(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1; 188 return BIT_ULL(boot_cpu_data.x86_cache_bits - 1 - PAGE_SHIFT);
187} 189}
188 190
189extern void early_cpu_init(void); 191extern void early_cpu_init(void);
diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h
index 34cffcef7375..07a25753e85c 100644
--- a/arch/x86/include/asm/set_memory.h
+++ b/arch/x86/include/asm/set_memory.h
@@ -89,4 +89,46 @@ extern int kernel_set_to_readonly;
89void set_kernel_text_rw(void); 89void set_kernel_text_rw(void);
90void set_kernel_text_ro(void); 90void set_kernel_text_ro(void);
91 91
92#ifdef CONFIG_X86_64
93static inline int set_mce_nospec(unsigned long pfn)
94{
95 unsigned long decoy_addr;
96 int rc;
97
98 /*
99 * Mark the linear address as UC to make sure we don't log more
100 * errors because of speculative access to the page.
101 * We would like to just call:
102 * set_memory_uc((unsigned long)pfn_to_kaddr(pfn), 1);
103 * but doing that would radically increase the odds of a
104 * speculative access to the poison page because we'd have
105 * the virtual address of the kernel 1:1 mapping sitting
106 * around in registers.
107 * Instead we get tricky. We create a non-canonical address
108 * that looks just like the one we want, but has bit 63 flipped.
109 * This relies on set_memory_uc() properly sanitizing any __pa()
110 * results with __PHYSICAL_MASK or PTE_PFN_MASK.
111 */
112 decoy_addr = (pfn << PAGE_SHIFT) + (PAGE_OFFSET ^ BIT(63));
113
114 rc = set_memory_uc(decoy_addr, 1);
115 if (rc)
116 pr_warn("Could not invalidate pfn=0x%lx from 1:1 map\n", pfn);
117 return rc;
118}
119#define set_mce_nospec set_mce_nospec
120
121/* Restore full speculative operation to the pfn. */
122static inline int clear_mce_nospec(unsigned long pfn)
123{
124 return set_memory_wb((unsigned long) pfn_to_kaddr(pfn), 1);
125}
126#define clear_mce_nospec clear_mce_nospec
127#else
128/*
129 * Few people would run a 32-bit kernel on a machine that supports
130 * recoverable errors because they have too much memory to boot 32-bit.
131 */
132#endif
133
92#endif /* _ASM_X86_SET_MEMORY_H */ 134#endif /* _ASM_X86_SET_MEMORY_H */
diff --git a/arch/x86/include/asm/signal.h b/arch/x86/include/asm/signal.h
index 5f9012ff52ed..33d3c88a7225 100644
--- a/arch/x86/include/asm/signal.h
+++ b/arch/x86/include/asm/signal.h
@@ -39,6 +39,7 @@ extern void do_signal(struct pt_regs *regs);
39 39
40#define __ARCH_HAS_SA_RESTORER 40#define __ARCH_HAS_SA_RESTORER
41 41
42#include <asm/asm.h>
42#include <uapi/asm/sigcontext.h> 43#include <uapi/asm/sigcontext.h>
43 44
44#ifdef __i386__ 45#ifdef __i386__
@@ -86,9 +87,9 @@ static inline int __const_sigismember(sigset_t *set, int _sig)
86 87
87static inline int __gen_sigismember(sigset_t *set, int _sig) 88static inline int __gen_sigismember(sigset_t *set, int _sig)
88{ 89{
89 unsigned char ret; 90 bool ret;
90 asm("btl %2,%1\n\tsetc %0" 91 asm("btl %2,%1" CC_SET(c)
91 : "=qm"(ret) : "m"(*set), "Ir"(_sig-1) : "cc"); 92 : CC_OUT(c) (ret) : "m"(*set), "Ir"(_sig-1));
92 return ret; 93 return ret;
93} 94}
94 95
diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
index b6dc698f992a..f335aad404a4 100644
--- a/arch/x86/include/asm/stacktrace.h
+++ b/arch/x86/include/asm/stacktrace.h
@@ -111,6 +111,6 @@ static inline unsigned long caller_frame_pointer(void)
111 return (unsigned long)frame; 111 return (unsigned long)frame;
112} 112}
113 113
114void show_opcodes(u8 *rip, const char *loglvl); 114void show_opcodes(struct pt_regs *regs, const char *loglvl);
115void show_ip(struct pt_regs *regs, const char *loglvl); 115void show_ip(struct pt_regs *regs, const char *loglvl);
116#endif /* _ASM_X86_STACKTRACE_H */ 116#endif /* _ASM_X86_STACKTRACE_H */
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 29c9da6c62fc..58ce5288878e 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -175,8 +175,16 @@ struct tlb_state {
175 * are on. This means that it may not match current->active_mm, 175 * are on. This means that it may not match current->active_mm,
176 * which will contain the previous user mm when we're in lazy TLB 176 * which will contain the previous user mm when we're in lazy TLB
177 * mode even if we've already switched back to swapper_pg_dir. 177 * mode even if we've already switched back to swapper_pg_dir.
178 *
179 * During switch_mm_irqs_off(), loaded_mm will be set to
180 * LOADED_MM_SWITCHING during the brief interrupts-off window
181 * when CR3 and loaded_mm would otherwise be inconsistent. This
182 * is for nmi_uaccess_okay()'s benefit.
178 */ 183 */
179 struct mm_struct *loaded_mm; 184 struct mm_struct *loaded_mm;
185
186#define LOADED_MM_SWITCHING ((struct mm_struct *)1)
187
180 u16 loaded_mm_asid; 188 u16 loaded_mm_asid;
181 u16 next_asid; 189 u16 next_asid;
182 /* last user mm's ctx id */ 190 /* last user mm's ctx id */
@@ -246,6 +254,38 @@ struct tlb_state {
246}; 254};
247DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate); 255DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);
248 256
257/*
258 * Blindly accessing user memory from NMI context can be dangerous
259 * if we're in the middle of switching the current user task or
260 * switching the loaded mm. It can also be dangerous if we
261 * interrupted some kernel code that was temporarily using a
262 * different mm.
263 */
264static inline bool nmi_uaccess_okay(void)
265{
266 struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm);
267 struct mm_struct *current_mm = current->mm;
268
269 VM_WARN_ON_ONCE(!loaded_mm);
270
271 /*
272 * The condition we want to check is
273 * current_mm->pgd == __va(read_cr3_pa()). This may be slow, though,
274 * if we're running in a VM with shadow paging, and nmi_uaccess_okay()
275 * is supposed to be reasonably fast.
276 *
277 * Instead, we check the almost equivalent but somewhat conservative
278 * condition below, and we rely on the fact that switch_mm_irqs_off()
279 * sets loaded_mm to LOADED_MM_SWITCHING before writing to CR3.
280 */
281 if (loaded_mm != current_mm)
282 return false;
283
284 VM_WARN_ON_ONCE(current_mm->pgd != __va(read_cr3_pa()));
285
286 return true;
287}
288
249/* Initialize cr4 shadow for this CPU. */ 289/* Initialize cr4 shadow for this CPU. */
250static inline void cr4_init_shadow(void) 290static inline void cr4_init_shadow(void)
251{ 291{
diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
index fb856c9f0449..53748541c487 100644
--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -93,7 +93,7 @@ static inline unsigned int __getcpu(void)
93 * 93 *
94 * If RDPID is available, use it. 94 * If RDPID is available, use it.
95 */ 95 */
96 alternative_io ("lsl %[p],%[seg]", 96 alternative_io ("lsl %[seg],%[p]",
97 ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */ 97 ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
98 X86_FEATURE_RDPID, 98 X86_FEATURE_RDPID,
99 [p] "=a" (p), [seg] "r" (__PER_CPU_SEG)); 99 [p] "=a" (p), [seg] "r" (__PER_CPU_SEG));
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 014f214da581..b9d5e7c9ef43 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -684,8 +684,6 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
684 * It means the size must be writable atomically and the address must be aligned 684 * It means the size must be writable atomically and the address must be aligned
685 * in a way that permits an atomic write. It also makes sure we fit on a single 685 * in a way that permits an atomic write. It also makes sure we fit on a single
686 * page. 686 * page.
687 *
688 * Note: Must be called under text_mutex.
689 */ 687 */
690void *text_poke(void *addr, const void *opcode, size_t len) 688void *text_poke(void *addr, const void *opcode, size_t len)
691{ 689{
@@ -700,6 +698,8 @@ void *text_poke(void *addr, const void *opcode, size_t len)
700 */ 698 */
701 BUG_ON(!after_bootmem); 699 BUG_ON(!after_bootmem);
702 700
701 lockdep_assert_held(&text_mutex);
702
703 if (!core_kernel_text((unsigned long)addr)) { 703 if (!core_kernel_text((unsigned long)addr)) {
704 pages[0] = vmalloc_to_page(addr); 704 pages[0] = vmalloc_to_page(addr);
705 pages[1] = vmalloc_to_page(addr + PAGE_SIZE); 705 pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
@@ -782,8 +782,6 @@ int poke_int3_handler(struct pt_regs *regs)
782 * - replace the first byte (int3) by the first byte of 782 * - replace the first byte (int3) by the first byte of
783 * replacing opcode 783 * replacing opcode
784 * - sync cores 784 * - sync cores
785 *
786 * Note: must be called under text_mutex.
787 */ 785 */
788void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler) 786void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
789{ 787{
@@ -792,6 +790,9 @@ void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
792 bp_int3_handler = handler; 790 bp_int3_handler = handler;
793 bp_int3_addr = (u8 *)addr + sizeof(int3); 791 bp_int3_addr = (u8 *)addr + sizeof(int3);
794 bp_patching_in_progress = true; 792 bp_patching_in_progress = true;
793
794 lockdep_assert_held(&text_mutex);
795
795 /* 796 /*
796 * Corresponding read barrier in int3 notifier for making sure the 797 * Corresponding read barrier in int3 notifier for making sure the
797 * in_progress and handler are correctly ordered wrt. patching. 798 * in_progress and handler are correctly ordered wrt. patching.
diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c
index 9f148e3d45b4..7654febd5102 100644
--- a/arch/x86/kernel/apic/vector.c
+++ b/arch/x86/kernel/apic/vector.c
@@ -413,7 +413,7 @@ static int activate_managed(struct irq_data *irqd)
413 if (WARN_ON_ONCE(cpumask_empty(vector_searchmask))) { 413 if (WARN_ON_ONCE(cpumask_empty(vector_searchmask))) {
414 /* Something in the core code broke! Survive gracefully */ 414 /* Something in the core code broke! Survive gracefully */
415 pr_err("Managed startup for irq %u, but no CPU\n", irqd->irq); 415 pr_err("Managed startup for irq %u, but no CPU\n", irqd->irq);
416 return EINVAL; 416 return -EINVAL;
417 } 417 }
418 418
419 ret = assign_managed_vector(irqd, vector_searchmask); 419 ret = assign_managed_vector(irqd, vector_searchmask);
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index cb4a16292aa7..40bdaea97fe7 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -668,6 +668,45 @@ EXPORT_SYMBOL_GPL(l1tf_mitigation);
668enum vmx_l1d_flush_state l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO; 668enum vmx_l1d_flush_state l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO;
669EXPORT_SYMBOL_GPL(l1tf_vmx_mitigation); 669EXPORT_SYMBOL_GPL(l1tf_vmx_mitigation);
670 670
671/*
672 * These CPUs all support 44bits physical address space internally in the
673 * cache but CPUID can report a smaller number of physical address bits.
674 *
675 * The L1TF mitigation uses the top most address bit for the inversion of
676 * non present PTEs. When the installed memory reaches into the top most
677 * address bit due to memory holes, which has been observed on machines
678 * which report 36bits physical address bits and have 32G RAM installed,
679 * then the mitigation range check in l1tf_select_mitigation() triggers.
680 * This is a false positive because the mitigation is still possible due to
681 * the fact that the cache uses 44bit internally. Use the cache bits
682 * instead of the reported physical bits and adjust them on the affected
683 * machines to 44bit if the reported bits are less than 44.
684 */
685static void override_cache_bits(struct cpuinfo_x86 *c)
686{
687 if (c->x86 != 6)
688 return;
689
690 switch (c->x86_model) {
691 case INTEL_FAM6_NEHALEM:
692 case INTEL_FAM6_WESTMERE:
693 case INTEL_FAM6_SANDYBRIDGE:
694 case INTEL_FAM6_IVYBRIDGE:
695 case INTEL_FAM6_HASWELL_CORE:
696 case INTEL_FAM6_HASWELL_ULT:
697 case INTEL_FAM6_HASWELL_GT3E:
698 case INTEL_FAM6_BROADWELL_CORE:
699 case INTEL_FAM6_BROADWELL_GT3E:
700 case INTEL_FAM6_SKYLAKE_MOBILE:
701 case INTEL_FAM6_SKYLAKE_DESKTOP:
702 case INTEL_FAM6_KABYLAKE_MOBILE:
703 case INTEL_FAM6_KABYLAKE_DESKTOP:
704 if (c->x86_cache_bits < 44)
705 c->x86_cache_bits = 44;
706 break;
707 }
708}
709
671static void __init l1tf_select_mitigation(void) 710static void __init l1tf_select_mitigation(void)
672{ 711{
673 u64 half_pa; 712 u64 half_pa;
@@ -675,6 +714,8 @@ static void __init l1tf_select_mitigation(void)
675 if (!boot_cpu_has_bug(X86_BUG_L1TF)) 714 if (!boot_cpu_has_bug(X86_BUG_L1TF))
676 return; 715 return;
677 716
717 override_cache_bits(&boot_cpu_data);
718
678 switch (l1tf_mitigation) { 719 switch (l1tf_mitigation) {
679 case L1TF_MITIGATION_OFF: 720 case L1TF_MITIGATION_OFF:
680 case L1TF_MITIGATION_FLUSH_NOWARN: 721 case L1TF_MITIGATION_FLUSH_NOWARN:
@@ -694,14 +735,13 @@ static void __init l1tf_select_mitigation(void)
694 return; 735 return;
695#endif 736#endif
696 737
697 /*
698 * This is extremely unlikely to happen because almost all
699 * systems have far more MAX_PA/2 than RAM can be fit into
700 * DIMM slots.
701 */
702 half_pa = (u64)l1tf_pfn_limit() << PAGE_SHIFT; 738 half_pa = (u64)l1tf_pfn_limit() << PAGE_SHIFT;
703 if (e820__mapped_any(half_pa, ULLONG_MAX - half_pa, E820_TYPE_RAM)) { 739 if (e820__mapped_any(half_pa, ULLONG_MAX - half_pa, E820_TYPE_RAM)) {
704 pr_warn("System has more than MAX_PA/2 memory. L1TF mitigation not effective.\n"); 740 pr_warn("System has more than MAX_PA/2 memory. L1TF mitigation not effective.\n");
741 pr_info("You may make it effective by booting the kernel with mem=%llu parameter.\n",
742 half_pa);
743 pr_info("However, doing so will make a part of your RAM unusable.\n");
744 pr_info("Reading https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html might help you decide.\n");
705 return; 745 return;
706 } 746 }
707 747
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 84dee5ab745a..44c4ef3d989b 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -919,6 +919,7 @@ void get_cpu_address_sizes(struct cpuinfo_x86 *c)
919 else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36)) 919 else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
920 c->x86_phys_bits = 36; 920 c->x86_phys_bits = 36;
921#endif 921#endif
922 c->x86_cache_bits = c->x86_phys_bits;
922} 923}
923 924
924static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c) 925static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 401e8c133108..fc3c07fe7df5 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -150,6 +150,9 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
150 if (cpu_has(c, X86_FEATURE_HYPERVISOR)) 150 if (cpu_has(c, X86_FEATURE_HYPERVISOR))
151 return false; 151 return false;
152 152
153 if (c->x86 != 6)
154 return false;
155
153 for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) { 156 for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) {
154 if (c->x86_model == spectre_bad_microcodes[i].model && 157 if (c->x86_model == spectre_bad_microcodes[i].model &&
155 c->x86_stepping == spectre_bad_microcodes[i].stepping) 158 c->x86_stepping == spectre_bad_microcodes[i].stepping)
diff --git a/arch/x86/kernel/cpu/mcheck/mce-internal.h b/arch/x86/kernel/cpu/mcheck/mce-internal.h
index 374d1aa66952..ceb67cd5918f 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-internal.h
+++ b/arch/x86/kernel/cpu/mcheck/mce-internal.h
@@ -113,21 +113,6 @@ static inline void mce_register_injector_chain(struct notifier_block *nb) { }
113static inline void mce_unregister_injector_chain(struct notifier_block *nb) { } 113static inline void mce_unregister_injector_chain(struct notifier_block *nb) { }
114#endif 114#endif
115 115
116#ifndef CONFIG_X86_64
117/*
118 * On 32-bit systems it would be difficult to safely unmap a poison page
119 * from the kernel 1:1 map because there are no non-canonical addresses that
120 * we can use to refer to the address without risking a speculative access.
121 * However, this isn't much of an issue because:
122 * 1) Few unmappable pages are in the 1:1 map. Most are in HIGHMEM which
123 * are only mapped into the kernel as needed
124 * 2) Few people would run a 32-bit kernel on a machine that supports
125 * recoverable errors because they have too much memory to boot 32-bit.
126 */
127static inline void mce_unmap_kpfn(unsigned long pfn) {}
128#define mce_unmap_kpfn mce_unmap_kpfn
129#endif
130
131struct mca_config { 116struct mca_config {
132 bool dont_log_ce; 117 bool dont_log_ce;
133 bool cmci_disabled; 118 bool cmci_disabled;
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 4b767284b7f5..953b3ce92dcc 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -42,6 +42,7 @@
42#include <linux/irq_work.h> 42#include <linux/irq_work.h>
43#include <linux/export.h> 43#include <linux/export.h>
44#include <linux/jump_label.h> 44#include <linux/jump_label.h>
45#include <linux/set_memory.h>
45 46
46#include <asm/intel-family.h> 47#include <asm/intel-family.h>
47#include <asm/processor.h> 48#include <asm/processor.h>
@@ -50,7 +51,6 @@
50#include <asm/mce.h> 51#include <asm/mce.h>
51#include <asm/msr.h> 52#include <asm/msr.h>
52#include <asm/reboot.h> 53#include <asm/reboot.h>
53#include <asm/set_memory.h>
54 54
55#include "mce-internal.h" 55#include "mce-internal.h"
56 56
@@ -108,10 +108,6 @@ static struct irq_work mce_irq_work;
108 108
109static void (*quirk_no_way_out)(int bank, struct mce *m, struct pt_regs *regs); 109static void (*quirk_no_way_out)(int bank, struct mce *m, struct pt_regs *regs);
110 110
111#ifndef mce_unmap_kpfn
112static void mce_unmap_kpfn(unsigned long pfn);
113#endif
114
115/* 111/*
116 * CPU/chipset specific EDAC code can register a notifier call here to print 112 * CPU/chipset specific EDAC code can register a notifier call here to print
117 * MCE errors in a human-readable form. 113 * MCE errors in a human-readable form.
@@ -602,7 +598,7 @@ static int srao_decode_notifier(struct notifier_block *nb, unsigned long val,
602 if (mce_usable_address(mce) && (mce->severity == MCE_AO_SEVERITY)) { 598 if (mce_usable_address(mce) && (mce->severity == MCE_AO_SEVERITY)) {
603 pfn = mce->addr >> PAGE_SHIFT; 599 pfn = mce->addr >> PAGE_SHIFT;
604 if (!memory_failure(pfn, 0)) 600 if (!memory_failure(pfn, 0))
605 mce_unmap_kpfn(pfn); 601 set_mce_nospec(pfn);
606 } 602 }
607 603
608 return NOTIFY_OK; 604 return NOTIFY_OK;
@@ -1072,38 +1068,10 @@ static int do_memory_failure(struct mce *m)
1072 if (ret) 1068 if (ret)
1073 pr_err("Memory error not recovered"); 1069 pr_err("Memory error not recovered");
1074 else 1070 else
1075 mce_unmap_kpfn(m->addr >> PAGE_SHIFT); 1071 set_mce_nospec(m->addr >> PAGE_SHIFT);
1076 return ret; 1072 return ret;
1077} 1073}
1078 1074
1079#ifndef mce_unmap_kpfn
1080static void mce_unmap_kpfn(unsigned long pfn)
1081{
1082 unsigned long decoy_addr;
1083
1084 /*
1085 * Unmap this page from the kernel 1:1 mappings to make sure
1086 * we don't log more errors because of speculative access to
1087 * the page.
1088 * We would like to just call:
1089 * set_memory_np((unsigned long)pfn_to_kaddr(pfn), 1);
1090 * but doing that would radically increase the odds of a
1091 * speculative access to the poison page because we'd have
1092 * the virtual address of the kernel 1:1 mapping sitting
1093 * around in registers.
1094 * Instead we get tricky. We create a non-canonical address
1095 * that looks just like the one we want, but has bit 63 flipped.
1096 * This relies on set_memory_np() not checking whether we passed
1097 * a legal address.
1098 */
1099
1100 decoy_addr = (pfn << PAGE_SHIFT) + (PAGE_OFFSET ^ BIT(63));
1101
1102 if (set_memory_np(decoy_addr, 1))
1103 pr_warn("Could not invalidate pfn=0x%lx from 1:1 map\n", pfn);
1104}
1105#endif
1106
1107 1075
1108/* 1076/*
1109 * Cases where we avoid rendezvous handler timeout: 1077 * Cases where we avoid rendezvous handler timeout:
diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 0624957aa068..07b5fc00b188 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -504,6 +504,7 @@ static enum ucode_state apply_microcode_amd(int cpu)
504 struct microcode_amd *mc_amd; 504 struct microcode_amd *mc_amd;
505 struct ucode_cpu_info *uci; 505 struct ucode_cpu_info *uci;
506 struct ucode_patch *p; 506 struct ucode_patch *p;
507 enum ucode_state ret;
507 u32 rev, dummy; 508 u32 rev, dummy;
508 509
509 BUG_ON(raw_smp_processor_id() != cpu); 510 BUG_ON(raw_smp_processor_id() != cpu);
@@ -521,9 +522,8 @@ static enum ucode_state apply_microcode_amd(int cpu)
521 522
522 /* need to apply patch? */ 523 /* need to apply patch? */
523 if (rev >= mc_amd->hdr.patch_id) { 524 if (rev >= mc_amd->hdr.patch_id) {
524 c->microcode = rev; 525 ret = UCODE_OK;
525 uci->cpu_sig.rev = rev; 526 goto out;
526 return UCODE_OK;
527 } 527 }
528 528
529 if (__apply_microcode_amd(mc_amd)) { 529 if (__apply_microcode_amd(mc_amd)) {
@@ -531,13 +531,21 @@ static enum ucode_state apply_microcode_amd(int cpu)
531 cpu, mc_amd->hdr.patch_id); 531 cpu, mc_amd->hdr.patch_id);
532 return UCODE_ERROR; 532 return UCODE_ERROR;
533 } 533 }
534 pr_info("CPU%d: new patch_level=0x%08x\n", cpu,
535 mc_amd->hdr.patch_id);
536 534
537 uci->cpu_sig.rev = mc_amd->hdr.patch_id; 535 rev = mc_amd->hdr.patch_id;
538 c->microcode = mc_amd->hdr.patch_id; 536 ret = UCODE_UPDATED;
537
538 pr_info("CPU%d: new patch_level=0x%08x\n", cpu, rev);
539 539
540 return UCODE_UPDATED; 540out:
541 uci->cpu_sig.rev = rev;
542 c->microcode = rev;
543
544 /* Update boot_cpu_data's revision too, if we're on the BSP: */
545 if (c->cpu_index == boot_cpu_data.cpu_index)
546 boot_cpu_data.microcode = rev;
547
548 return ret;
541} 549}
542 550
543static int install_equiv_cpu_table(const u8 *buf) 551static int install_equiv_cpu_table(const u8 *buf)
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index 97ccf4c3b45b..16936a24795c 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -795,6 +795,7 @@ static enum ucode_state apply_microcode_intel(int cpu)
795 struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 795 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
796 struct cpuinfo_x86 *c = &cpu_data(cpu); 796 struct cpuinfo_x86 *c = &cpu_data(cpu);
797 struct microcode_intel *mc; 797 struct microcode_intel *mc;
798 enum ucode_state ret;
798 static int prev_rev; 799 static int prev_rev;
799 u32 rev; 800 u32 rev;
800 801
@@ -817,9 +818,8 @@ static enum ucode_state apply_microcode_intel(int cpu)
817 */ 818 */
818 rev = intel_get_microcode_revision(); 819 rev = intel_get_microcode_revision();
819 if (rev >= mc->hdr.rev) { 820 if (rev >= mc->hdr.rev) {
820 uci->cpu_sig.rev = rev; 821 ret = UCODE_OK;
821 c->microcode = rev; 822 goto out;
822 return UCODE_OK;
823 } 823 }
824 824
825 /* 825 /*
@@ -848,10 +848,17 @@ static enum ucode_state apply_microcode_intel(int cpu)
848 prev_rev = rev; 848 prev_rev = rev;
849 } 849 }
850 850
851 ret = UCODE_UPDATED;
852
853out:
851 uci->cpu_sig.rev = rev; 854 uci->cpu_sig.rev = rev;
852 c->microcode = rev; 855 c->microcode = rev;
856
857 /* Update boot_cpu_data's revision too, if we're on the BSP: */
858 if (c->cpu_index == boot_cpu_data.cpu_index)
859 boot_cpu_data.microcode = rev;
853 860
854 return UCODE_UPDATED; 861 return ret;
855} 862}
856 863
857static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size, 864static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 9c8652974f8e..2b5886401e5f 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -17,6 +17,7 @@
17#include <linux/bug.h> 17#include <linux/bug.h>
18#include <linux/nmi.h> 18#include <linux/nmi.h>
19#include <linux/sysfs.h> 19#include <linux/sysfs.h>
20#include <linux/kasan.h>
20 21
21#include <asm/cpu_entry_area.h> 22#include <asm/cpu_entry_area.h>
22#include <asm/stacktrace.h> 23#include <asm/stacktrace.h>
@@ -89,14 +90,24 @@ static void printk_stack_address(unsigned long address, int reliable,
89 * Thus, the 2/3rds prologue and 64 byte OPCODE_BUFSIZE is just a random 90 * Thus, the 2/3rds prologue and 64 byte OPCODE_BUFSIZE is just a random
90 * guesstimate in attempt to achieve all of the above. 91 * guesstimate in attempt to achieve all of the above.
91 */ 92 */
92void show_opcodes(u8 *rip, const char *loglvl) 93void show_opcodes(struct pt_regs *regs, const char *loglvl)
93{ 94{
94#define PROLOGUE_SIZE 42 95#define PROLOGUE_SIZE 42
95#define EPILOGUE_SIZE 21 96#define EPILOGUE_SIZE 21
96#define OPCODE_BUFSIZE (PROLOGUE_SIZE + 1 + EPILOGUE_SIZE) 97#define OPCODE_BUFSIZE (PROLOGUE_SIZE + 1 + EPILOGUE_SIZE)
97 u8 opcodes[OPCODE_BUFSIZE]; 98 u8 opcodes[OPCODE_BUFSIZE];
99 unsigned long prologue = regs->ip - PROLOGUE_SIZE;
100 bool bad_ip;
98 101
99 if (probe_kernel_read(opcodes, rip - PROLOGUE_SIZE, OPCODE_BUFSIZE)) { 102 /*
103 * Make sure userspace isn't trying to trick us into dumping kernel
104 * memory by pointing the userspace instruction pointer at it.
105 */
106 bad_ip = user_mode(regs) &&
107 __chk_range_not_ok(prologue, OPCODE_BUFSIZE, TASK_SIZE_MAX);
108
109 if (bad_ip || probe_kernel_read(opcodes, (u8 *)prologue,
110 OPCODE_BUFSIZE)) {
100 printk("%sCode: Bad RIP value.\n", loglvl); 111 printk("%sCode: Bad RIP value.\n", loglvl);
101 } else { 112 } else {
102 printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %" 113 printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %"
@@ -112,7 +123,7 @@ void show_ip(struct pt_regs *regs, const char *loglvl)
112#else 123#else
113 printk("%sRIP: %04x:%pS\n", loglvl, (int)regs->cs, (void *)regs->ip); 124 printk("%sRIP: %04x:%pS\n", loglvl, (int)regs->cs, (void *)regs->ip);
114#endif 125#endif
115 show_opcodes((u8 *)regs->ip, loglvl); 126 show_opcodes(regs, loglvl);
116} 127}
117 128
118void show_iret_regs(struct pt_regs *regs) 129void show_iret_regs(struct pt_regs *regs)
@@ -135,7 +146,7 @@ static void show_regs_if_on_stack(struct stack_info *info, struct pt_regs *regs,
135 * they can be printed in the right context. 146 * they can be printed in the right context.
136 */ 147 */
137 if (!partial && on_stack(info, regs, sizeof(*regs))) { 148 if (!partial && on_stack(info, regs, sizeof(*regs))) {
138 __show_regs(regs, 0); 149 __show_regs(regs, SHOW_REGS_SHORT);
139 150
140 } else if (partial && on_stack(info, (void *)regs + IRET_FRAME_OFFSET, 151 } else if (partial && on_stack(info, (void *)regs + IRET_FRAME_OFFSET,
141 IRET_FRAME_SIZE)) { 152 IRET_FRAME_SIZE)) {
@@ -333,7 +344,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
333 oops_exit(); 344 oops_exit();
334 345
335 /* Executive summary in case the oops scrolled away */ 346 /* Executive summary in case the oops scrolled away */
336 __show_regs(&exec_summary_regs, true); 347 __show_regs(&exec_summary_regs, SHOW_REGS_ALL);
337 348
338 if (!signr) 349 if (!signr)
339 return; 350 return;
@@ -346,7 +357,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
346 * We're not going to return, but we might be on an IST stack or 357 * We're not going to return, but we might be on an IST stack or
347 * have very little stack space left. Rewind the stack and kill 358 * have very little stack space left. Rewind the stack and kill
348 * the task. 359 * the task.
360 * Before we rewind the stack, we have to tell KASAN that we're going to
361 * reuse the task stack and that existing poisons are invalid.
349 */ 362 */
363 kasan_unpoison_task_stack(current);
350 rewind_stack_do_exit(signr); 364 rewind_stack_do_exit(signr);
351} 365}
352NOKPROBE_SYMBOL(oops_end); 366NOKPROBE_SYMBOL(oops_end);
@@ -393,14 +407,9 @@ void die(const char *str, struct pt_regs *regs, long err)
393 407
394void show_regs(struct pt_regs *regs) 408void show_regs(struct pt_regs *regs)
395{ 409{
396 bool all = true;
397
398 show_regs_print_info(KERN_DEFAULT); 410 show_regs_print_info(KERN_DEFAULT);
399 411
400 if (IS_ENABLED(CONFIG_X86_32)) 412 __show_regs(regs, user_mode(regs) ? SHOW_REGS_USER : SHOW_REGS_ALL);
401 all = !user_mode(regs);
402
403 __show_regs(regs, all);
404 413
405 /* 414 /*
406 * When in-kernel, we also print out the stack at the time of the fault.. 415 * When in-kernel, we also print out the stack at the time of the fault..
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 2924fd447e61..5046a3c9dec2 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -59,7 +59,7 @@
59#include <asm/intel_rdt_sched.h> 59#include <asm/intel_rdt_sched.h>
60#include <asm/proto.h> 60#include <asm/proto.h>
61 61
62void __show_regs(struct pt_regs *regs, int all) 62void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
63{ 63{
64 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L; 64 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
65 unsigned long d0, d1, d2, d3, d6, d7; 65 unsigned long d0, d1, d2, d3, d6, d7;
@@ -85,7 +85,7 @@ void __show_regs(struct pt_regs *regs, int all)
85 printk(KERN_DEFAULT "DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x EFLAGS: %08lx\n", 85 printk(KERN_DEFAULT "DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x EFLAGS: %08lx\n",
86 (u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss, regs->flags); 86 (u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss, regs->flags);
87 87
88 if (!all) 88 if (mode != SHOW_REGS_ALL)
89 return; 89 return;
90 90
91 cr0 = read_cr0(); 91 cr0 = read_cr0();
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 476e3ddf8890..ea5ea850348d 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -62,7 +62,7 @@
62__visible DEFINE_PER_CPU(unsigned long, rsp_scratch); 62__visible DEFINE_PER_CPU(unsigned long, rsp_scratch);
63 63
64/* Prints also some state that isn't saved in the pt_regs */ 64/* Prints also some state that isn't saved in the pt_regs */
65void __show_regs(struct pt_regs *regs, int all) 65void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
66{ 66{
67 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs; 67 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
68 unsigned long d0, d1, d2, d3, d6, d7; 68 unsigned long d0, d1, d2, d3, d6, d7;
@@ -87,9 +87,17 @@ void __show_regs(struct pt_regs *regs, int all)
87 printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n", 87 printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
88 regs->r13, regs->r14, regs->r15); 88 regs->r13, regs->r14, regs->r15);
89 89
90 if (!all) 90 if (mode == SHOW_REGS_SHORT)
91 return; 91 return;
92 92
93 if (mode == SHOW_REGS_USER) {
94 rdmsrl(MSR_FS_BASE, fs);
95 rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
96 printk(KERN_DEFAULT "FS: %016lx GS: %016lx\n",
97 fs, shadowgs);
98 return;
99 }
100
93 asm("movl %%ds,%0" : "=r" (ds)); 101 asm("movl %%ds,%0" : "=r" (ds));
94 asm("movl %%cs,%0" : "=r" (cs)); 102 asm("movl %%cs,%0" : "=r" (cs));
95 asm("movl %%es,%0" : "=r" (es)); 103 asm("movl %%es,%0" : "=r" (es));
@@ -384,6 +392,7 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
384 start_thread_common(regs, new_ip, new_sp, 392 start_thread_common(regs, new_ip, new_sp,
385 __USER_CS, __USER_DS, 0); 393 __USER_CS, __USER_DS, 0);
386} 394}
395EXPORT_SYMBOL_GPL(start_thread);
387 396
388#ifdef CONFIG_COMPAT 397#ifdef CONFIG_COMPAT
389void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp) 398void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 1463468ba9a0..6490f618e096 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -1415,7 +1415,7 @@ static bool __init determine_cpu_tsc_frequencies(bool early)
1415 1415
1416static unsigned long __init get_loops_per_jiffy(void) 1416static unsigned long __init get_loops_per_jiffy(void)
1417{ 1417{
1418 unsigned long lpj = tsc_khz * KHZ; 1418 u64 lpj = (u64)tsc_khz * KHZ;
1419 1419
1420 do_div(lpj, HZ); 1420 do_div(lpj, HZ);
1421 return lpj; 1421 return lpj;
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 0cefba28c864..17c0472c5b34 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -548,7 +548,7 @@ int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
548} 548}
549 549
550int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low, 550int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
551 unsigned long ipi_bitmap_high, int min, 551 unsigned long ipi_bitmap_high, u32 min,
552 unsigned long icr, int op_64_bit) 552 unsigned long icr, int op_64_bit)
553{ 553{
554 int i; 554 int i;
@@ -571,18 +571,31 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
571 rcu_read_lock(); 571 rcu_read_lock();
572 map = rcu_dereference(kvm->arch.apic_map); 572 map = rcu_dereference(kvm->arch.apic_map);
573 573
574 if (min > map->max_apic_id)
575 goto out;
574 /* Bits above cluster_size are masked in the caller. */ 576 /* Bits above cluster_size are masked in the caller. */
575 for_each_set_bit(i, &ipi_bitmap_low, BITS_PER_LONG) { 577 for_each_set_bit(i, &ipi_bitmap_low,
576 vcpu = map->phys_map[min + i]->vcpu; 578 min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
577 count += kvm_apic_set_irq(vcpu, &irq, NULL); 579 if (map->phys_map[min + i]) {
580 vcpu = map->phys_map[min + i]->vcpu;
581 count += kvm_apic_set_irq(vcpu, &irq, NULL);
582 }
578 } 583 }
579 584
580 min += cluster_size; 585 min += cluster_size;
581 for_each_set_bit(i, &ipi_bitmap_high, BITS_PER_LONG) { 586
582 vcpu = map->phys_map[min + i]->vcpu; 587 if (min > map->max_apic_id)
583 count += kvm_apic_set_irq(vcpu, &irq, NULL); 588 goto out;
589
590 for_each_set_bit(i, &ipi_bitmap_high,
591 min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
592 if (map->phys_map[min + i]) {
593 vcpu = map->phys_map[min + i]->vcpu;
594 count += kvm_apic_set_irq(vcpu, &irq, NULL);
595 }
584 } 596 }
585 597
598out:
586 rcu_read_unlock(); 599 rcu_read_unlock();
587 return count; 600 return count;
588} 601}
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index a282321329b5..e24ea7067373 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1853,11 +1853,6 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
1853 return kvm_handle_hva_range(kvm, hva, hva + 1, data, handler); 1853 return kvm_handle_hva_range(kvm, hva, hva + 1, data, handler);
1854} 1854}
1855 1855
1856int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
1857{
1858 return kvm_handle_hva(kvm, hva, 0, kvm_unmap_rmapp);
1859}
1860
1861int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) 1856int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end)
1862{ 1857{
1863 return kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp); 1858 return kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp);
@@ -5217,7 +5212,7 @@ static int make_mmu_pages_available(struct kvm_vcpu *vcpu)
5217int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code, 5212int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code,
5218 void *insn, int insn_len) 5213 void *insn, int insn_len)
5219{ 5214{
5220 int r, emulation_type = EMULTYPE_RETRY; 5215 int r, emulation_type = 0;
5221 enum emulation_result er; 5216 enum emulation_result er;
5222 bool direct = vcpu->arch.mmu.direct_map; 5217 bool direct = vcpu->arch.mmu.direct_map;
5223 5218
@@ -5230,10 +5225,8 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code,
5230 r = RET_PF_INVALID; 5225 r = RET_PF_INVALID;
5231 if (unlikely(error_code & PFERR_RSVD_MASK)) { 5226 if (unlikely(error_code & PFERR_RSVD_MASK)) {
5232 r = handle_mmio_page_fault(vcpu, cr2, direct); 5227 r = handle_mmio_page_fault(vcpu, cr2, direct);
5233 if (r == RET_PF_EMULATE) { 5228 if (r == RET_PF_EMULATE)
5234 emulation_type = 0;
5235 goto emulate; 5229 goto emulate;
5236 }
5237 } 5230 }
5238 5231
5239 if (r == RET_PF_INVALID) { 5232 if (r == RET_PF_INVALID) {
@@ -5260,8 +5253,19 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code,
5260 return 1; 5253 return 1;
5261 } 5254 }
5262 5255
5263 if (mmio_info_in_cache(vcpu, cr2, direct)) 5256 /*
5264 emulation_type = 0; 5257 * vcpu->arch.mmu.page_fault returned RET_PF_EMULATE, but we can still
5258 * optimistically try to just unprotect the page and let the processor
5259 * re-execute the instruction that caused the page fault. Do not allow
5260 * retrying MMIO emulation, as it's not only pointless but could also
5261 * cause us to enter an infinite loop because the processor will keep
5262 * faulting on the non-existent MMIO address. Retrying an instruction
5263 * from a nested guest is also pointless and dangerous as we are only
5264 * explicitly shadowing L1's page tables, i.e. unprotecting something
5265 * for L1 isn't going to magically fix whatever issue cause L2 to fail.
5266 */
5267 if (!mmio_info_in_cache(vcpu, cr2, direct) && !is_guest_mode(vcpu))
5268 emulation_type = EMULTYPE_ALLOW_RETRY;
5265emulate: 5269emulate:
5266 /* 5270 /*
5267 * On AMD platforms, under certain conditions insn_len may be zero on #NPF. 5271 * On AMD platforms, under certain conditions insn_len may be zero on #NPF.
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 6276140044d0..89c4c5aa15f1 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -776,7 +776,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
776 } 776 }
777 777
778 if (!svm->next_rip) { 778 if (!svm->next_rip) {
779 if (emulate_instruction(vcpu, EMULTYPE_SKIP) != 779 if (kvm_emulate_instruction(vcpu, EMULTYPE_SKIP) !=
780 EMULATE_DONE) 780 EMULATE_DONE)
781 printk(KERN_DEBUG "%s: NOP\n", __func__); 781 printk(KERN_DEBUG "%s: NOP\n", __func__);
782 return; 782 return;
@@ -2715,7 +2715,7 @@ static int gp_interception(struct vcpu_svm *svm)
2715 2715
2716 WARN_ON_ONCE(!enable_vmware_backdoor); 2716 WARN_ON_ONCE(!enable_vmware_backdoor);
2717 2717
2718 er = emulate_instruction(vcpu, 2718 er = kvm_emulate_instruction(vcpu,
2719 EMULTYPE_VMWARE | EMULTYPE_NO_UD_ON_FAIL); 2719 EMULTYPE_VMWARE | EMULTYPE_NO_UD_ON_FAIL);
2720 if (er == EMULATE_USER_EXIT) 2720 if (er == EMULATE_USER_EXIT)
2721 return 0; 2721 return 0;
@@ -2819,7 +2819,7 @@ static int io_interception(struct vcpu_svm *svm)
2819 string = (io_info & SVM_IOIO_STR_MASK) != 0; 2819 string = (io_info & SVM_IOIO_STR_MASK) != 0;
2820 in = (io_info & SVM_IOIO_TYPE_MASK) != 0; 2820 in = (io_info & SVM_IOIO_TYPE_MASK) != 0;
2821 if (string) 2821 if (string)
2822 return emulate_instruction(vcpu, 0) == EMULATE_DONE; 2822 return kvm_emulate_instruction(vcpu, 0) == EMULATE_DONE;
2823 2823
2824 port = io_info >> 16; 2824 port = io_info >> 16;
2825 size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT; 2825 size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT;
@@ -3861,7 +3861,7 @@ static int iret_interception(struct vcpu_svm *svm)
3861static int invlpg_interception(struct vcpu_svm *svm) 3861static int invlpg_interception(struct vcpu_svm *svm)
3862{ 3862{
3863 if (!static_cpu_has(X86_FEATURE_DECODEASSISTS)) 3863 if (!static_cpu_has(X86_FEATURE_DECODEASSISTS))
3864 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE; 3864 return kvm_emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
3865 3865
3866 kvm_mmu_invlpg(&svm->vcpu, svm->vmcb->control.exit_info_1); 3866 kvm_mmu_invlpg(&svm->vcpu, svm->vmcb->control.exit_info_1);
3867 return kvm_skip_emulated_instruction(&svm->vcpu); 3867 return kvm_skip_emulated_instruction(&svm->vcpu);
@@ -3869,13 +3869,13 @@ static int invlpg_interception(struct vcpu_svm *svm)
3869 3869
3870static int emulate_on_interception(struct vcpu_svm *svm) 3870static int emulate_on_interception(struct vcpu_svm *svm)
3871{ 3871{
3872 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE; 3872 return kvm_emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
3873} 3873}
3874 3874
3875static int rsm_interception(struct vcpu_svm *svm) 3875static int rsm_interception(struct vcpu_svm *svm)
3876{ 3876{
3877 return x86_emulate_instruction(&svm->vcpu, 0, 0, 3877 return kvm_emulate_instruction_from_buffer(&svm->vcpu,
3878 rsm_ins_bytes, 2) == EMULATE_DONE; 3878 rsm_ins_bytes, 2) == EMULATE_DONE;
3879} 3879}
3880 3880
3881static int rdpmc_interception(struct vcpu_svm *svm) 3881static int rdpmc_interception(struct vcpu_svm *svm)
@@ -4700,7 +4700,7 @@ static int avic_unaccelerated_access_interception(struct vcpu_svm *svm)
4700 ret = avic_unaccel_trap_write(svm); 4700 ret = avic_unaccel_trap_write(svm);
4701 } else { 4701 } else {
4702 /* Handling Fault */ 4702 /* Handling Fault */
4703 ret = (emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE); 4703 ret = (kvm_emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE);
4704 } 4704 }
4705 4705
4706 return ret; 4706 return ret;
@@ -6747,7 +6747,7 @@ e_free:
6747static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec) 6747static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
6748{ 6748{
6749 unsigned long vaddr, vaddr_end, next_vaddr; 6749 unsigned long vaddr, vaddr_end, next_vaddr;
6750 unsigned long dst_vaddr, dst_vaddr_end; 6750 unsigned long dst_vaddr;
6751 struct page **src_p, **dst_p; 6751 struct page **src_p, **dst_p;
6752 struct kvm_sev_dbg debug; 6752 struct kvm_sev_dbg debug;
6753 unsigned long n; 6753 unsigned long n;
@@ -6763,7 +6763,6 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
6763 size = debug.len; 6763 size = debug.len;
6764 vaddr_end = vaddr + size; 6764 vaddr_end = vaddr + size;
6765 dst_vaddr = debug.dst_uaddr; 6765 dst_vaddr = debug.dst_uaddr;
6766 dst_vaddr_end = dst_vaddr + size;
6767 6766
6768 for (; vaddr < vaddr_end; vaddr = next_vaddr) { 6767 for (; vaddr < vaddr_end; vaddr = next_vaddr) {
6769 int len, s_off, d_off; 6768 int len, s_off, d_off;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 8dae47e7267a..533a327372c8 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6983,7 +6983,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
6983 * Cause the #SS fault with 0 error code in VM86 mode. 6983 * Cause the #SS fault with 0 error code in VM86 mode.
6984 */ 6984 */
6985 if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0) { 6985 if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0) {
6986 if (emulate_instruction(vcpu, 0) == EMULATE_DONE) { 6986 if (kvm_emulate_instruction(vcpu, 0) == EMULATE_DONE) {
6987 if (vcpu->arch.halt_request) { 6987 if (vcpu->arch.halt_request) {
6988 vcpu->arch.halt_request = 0; 6988 vcpu->arch.halt_request = 0;
6989 return kvm_vcpu_halt(vcpu); 6989 return kvm_vcpu_halt(vcpu);
@@ -7054,7 +7054,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
7054 7054
7055 if (!vmx->rmode.vm86_active && is_gp_fault(intr_info)) { 7055 if (!vmx->rmode.vm86_active && is_gp_fault(intr_info)) {
7056 WARN_ON_ONCE(!enable_vmware_backdoor); 7056 WARN_ON_ONCE(!enable_vmware_backdoor);
7057 er = emulate_instruction(vcpu, 7057 er = kvm_emulate_instruction(vcpu,
7058 EMULTYPE_VMWARE | EMULTYPE_NO_UD_ON_FAIL); 7058 EMULTYPE_VMWARE | EMULTYPE_NO_UD_ON_FAIL);
7059 if (er == EMULATE_USER_EXIT) 7059 if (er == EMULATE_USER_EXIT)
7060 return 0; 7060 return 0;
@@ -7157,7 +7157,7 @@ static int handle_io(struct kvm_vcpu *vcpu)
7157 ++vcpu->stat.io_exits; 7157 ++vcpu->stat.io_exits;
7158 7158
7159 if (string) 7159 if (string)
7160 return emulate_instruction(vcpu, 0) == EMULATE_DONE; 7160 return kvm_emulate_instruction(vcpu, 0) == EMULATE_DONE;
7161 7161
7162 port = exit_qualification >> 16; 7162 port = exit_qualification >> 16;
7163 size = (exit_qualification & 7) + 1; 7163 size = (exit_qualification & 7) + 1;
@@ -7231,7 +7231,7 @@ static int handle_set_cr4(struct kvm_vcpu *vcpu, unsigned long val)
7231static int handle_desc(struct kvm_vcpu *vcpu) 7231static int handle_desc(struct kvm_vcpu *vcpu)
7232{ 7232{
7233 WARN_ON(!(vcpu->arch.cr4 & X86_CR4_UMIP)); 7233 WARN_ON(!(vcpu->arch.cr4 & X86_CR4_UMIP));
7234 return emulate_instruction(vcpu, 0) == EMULATE_DONE; 7234 return kvm_emulate_instruction(vcpu, 0) == EMULATE_DONE;
7235} 7235}
7236 7236
7237static int handle_cr(struct kvm_vcpu *vcpu) 7237static int handle_cr(struct kvm_vcpu *vcpu)
@@ -7480,7 +7480,7 @@ static int handle_vmcall(struct kvm_vcpu *vcpu)
7480 7480
7481static int handle_invd(struct kvm_vcpu *vcpu) 7481static int handle_invd(struct kvm_vcpu *vcpu)
7482{ 7482{
7483 return emulate_instruction(vcpu, 0) == EMULATE_DONE; 7483 return kvm_emulate_instruction(vcpu, 0) == EMULATE_DONE;
7484} 7484}
7485 7485
7486static int handle_invlpg(struct kvm_vcpu *vcpu) 7486static int handle_invlpg(struct kvm_vcpu *vcpu)
@@ -7547,7 +7547,7 @@ static int handle_apic_access(struct kvm_vcpu *vcpu)
7547 return kvm_skip_emulated_instruction(vcpu); 7547 return kvm_skip_emulated_instruction(vcpu);
7548 } 7548 }
7549 } 7549 }
7550 return emulate_instruction(vcpu, 0) == EMULATE_DONE; 7550 return kvm_emulate_instruction(vcpu, 0) == EMULATE_DONE;
7551} 7551}
7552 7552
7553static int handle_apic_eoi_induced(struct kvm_vcpu *vcpu) 7553static int handle_apic_eoi_induced(struct kvm_vcpu *vcpu)
@@ -7704,8 +7704,8 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
7704 if (!static_cpu_has(X86_FEATURE_HYPERVISOR)) 7704 if (!static_cpu_has(X86_FEATURE_HYPERVISOR))
7705 return kvm_skip_emulated_instruction(vcpu); 7705 return kvm_skip_emulated_instruction(vcpu);
7706 else 7706 else
7707 return x86_emulate_instruction(vcpu, gpa, EMULTYPE_SKIP, 7707 return kvm_emulate_instruction(vcpu, EMULTYPE_SKIP) ==
7708 NULL, 0) == EMULATE_DONE; 7708 EMULATE_DONE;
7709 } 7709 }
7710 7710
7711 return kvm_mmu_page_fault(vcpu, gpa, PFERR_RSVD_MASK, NULL, 0); 7711 return kvm_mmu_page_fault(vcpu, gpa, PFERR_RSVD_MASK, NULL, 0);
@@ -7748,7 +7748,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
7748 if (kvm_test_request(KVM_REQ_EVENT, vcpu)) 7748 if (kvm_test_request(KVM_REQ_EVENT, vcpu))
7749 return 1; 7749 return 1;
7750 7750
7751 err = emulate_instruction(vcpu, 0); 7751 err = kvm_emulate_instruction(vcpu, 0);
7752 7752
7753 if (err == EMULATE_USER_EXIT) { 7753 if (err == EMULATE_USER_EXIT) {
7754 ++vcpu->stat.mmio_exits; 7754 ++vcpu->stat.mmio_exits;
@@ -10131,9 +10131,6 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
10131 * information but as all relevant affected CPUs have 32KiB L1D cache size 10131 * information but as all relevant affected CPUs have 32KiB L1D cache size
10132 * there is no point in doing so. 10132 * there is no point in doing so.
10133 */ 10133 */
10134#define L1D_CACHE_ORDER 4
10135static void *vmx_l1d_flush_pages;
10136
10137static void vmx_l1d_flush(struct kvm_vcpu *vcpu) 10134static void vmx_l1d_flush(struct kvm_vcpu *vcpu)
10138{ 10135{
10139 int size = PAGE_SIZE << L1D_CACHE_ORDER; 10136 int size = PAGE_SIZE << L1D_CACHE_ORDER;
@@ -12540,8 +12537,11 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, u32 *exit_qual)
12540 struct vmcs12 *vmcs12 = get_vmcs12(vcpu); 12537 struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
12541 bool from_vmentry = !!exit_qual; 12538 bool from_vmentry = !!exit_qual;
12542 u32 dummy_exit_qual; 12539 u32 dummy_exit_qual;
12540 u32 vmcs01_cpu_exec_ctrl;
12543 int r = 0; 12541 int r = 0;
12544 12542
12543 vmcs01_cpu_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
12544
12545 enter_guest_mode(vcpu); 12545 enter_guest_mode(vcpu);
12546 12546
12547 if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS)) 12547 if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
@@ -12578,6 +12578,25 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, u32 *exit_qual)
12578 } 12578 }
12579 12579
12580 /* 12580 /*
12581 * If L1 had a pending IRQ/NMI until it executed
12582 * VMLAUNCH/VMRESUME which wasn't delivered because it was
12583 * disallowed (e.g. interrupts disabled), L0 needs to
12584 * evaluate if this pending event should cause an exit from L2
12585 * to L1 or delivered directly to L2 (e.g. In case L1 don't
12586 * intercept EXTERNAL_INTERRUPT).
12587 *
12588 * Usually this would be handled by L0 requesting a
12589 * IRQ/NMI window by setting VMCS accordingly. However,
12590 * this setting was done on VMCS01 and now VMCS02 is active
12591 * instead. Thus, we force L0 to perform pending event
12592 * evaluation by requesting a KVM_REQ_EVENT.
12593 */
12594 if (vmcs01_cpu_exec_ctrl &
12595 (CPU_BASED_VIRTUAL_INTR_PENDING | CPU_BASED_VIRTUAL_NMI_PENDING)) {
12596 kvm_make_request(KVM_REQ_EVENT, vcpu);
12597 }
12598
12599 /*
12581 * Note no nested_vmx_succeed or nested_vmx_fail here. At this point 12600 * Note no nested_vmx_succeed or nested_vmx_fail here. At this point
12582 * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet 12601 * we are no longer running L1, and VMLAUNCH/VMRESUME has not yet
12583 * returned as far as L1 is concerned. It will only return (and set 12602 * returned as far as L1 is concerned. It will only return (and set
@@ -13991,9 +14010,6 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
13991 check_vmentry_postreqs(vcpu, vmcs12, &exit_qual)) 14010 check_vmentry_postreqs(vcpu, vmcs12, &exit_qual))
13992 return -EINVAL; 14011 return -EINVAL;
13993 14012
13994 if (kvm_state->flags & KVM_STATE_NESTED_RUN_PENDING)
13995 vmx->nested.nested_run_pending = 1;
13996
13997 vmx->nested.dirty_vmcs12 = true; 14013 vmx->nested.dirty_vmcs12 = true;
13998 ret = enter_vmx_non_root_mode(vcpu, NULL); 14014 ret = enter_vmx_non_root_mode(vcpu, NULL);
13999 if (ret) 14015 if (ret)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 506bd2b4b8bb..542f6315444d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4987,7 +4987,7 @@ int handle_ud(struct kvm_vcpu *vcpu)
4987 emul_type = 0; 4987 emul_type = 0;
4988 } 4988 }
4989 4989
4990 er = emulate_instruction(vcpu, emul_type); 4990 er = kvm_emulate_instruction(vcpu, emul_type);
4991 if (er == EMULATE_USER_EXIT) 4991 if (er == EMULATE_USER_EXIT)
4992 return 0; 4992 return 0;
4993 if (er != EMULATE_DONE) 4993 if (er != EMULATE_DONE)
@@ -5870,7 +5870,10 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t cr2,
5870 gpa_t gpa = cr2; 5870 gpa_t gpa = cr2;
5871 kvm_pfn_t pfn; 5871 kvm_pfn_t pfn;
5872 5872
5873 if (emulation_type & EMULTYPE_NO_REEXECUTE) 5873 if (!(emulation_type & EMULTYPE_ALLOW_RETRY))
5874 return false;
5875
5876 if (WARN_ON_ONCE(is_guest_mode(vcpu)))
5874 return false; 5877 return false;
5875 5878
5876 if (!vcpu->arch.mmu.direct_map) { 5879 if (!vcpu->arch.mmu.direct_map) {
@@ -5958,7 +5961,10 @@ static bool retry_instruction(struct x86_emulate_ctxt *ctxt,
5958 */ 5961 */
5959 vcpu->arch.last_retry_eip = vcpu->arch.last_retry_addr = 0; 5962 vcpu->arch.last_retry_eip = vcpu->arch.last_retry_addr = 0;
5960 5963
5961 if (!(emulation_type & EMULTYPE_RETRY)) 5964 if (!(emulation_type & EMULTYPE_ALLOW_RETRY))
5965 return false;
5966
5967 if (WARN_ON_ONCE(is_guest_mode(vcpu)))
5962 return false; 5968 return false;
5963 5969
5964 if (x86_page_table_writing_insn(ctxt)) 5970 if (x86_page_table_writing_insn(ctxt))
@@ -6276,7 +6282,19 @@ restart:
6276 6282
6277 return r; 6283 return r;
6278} 6284}
6279EXPORT_SYMBOL_GPL(x86_emulate_instruction); 6285
6286int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type)
6287{
6288 return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0);
6289}
6290EXPORT_SYMBOL_GPL(kvm_emulate_instruction);
6291
6292int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
6293 void *insn, int insn_len)
6294{
6295 return x86_emulate_instruction(vcpu, 0, 0, insn, insn_len);
6296}
6297EXPORT_SYMBOL_GPL(kvm_emulate_instruction_from_buffer);
6280 6298
6281static int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, 6299static int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size,
6282 unsigned short port) 6300 unsigned short port)
@@ -7734,7 +7752,7 @@ static inline int complete_emulated_io(struct kvm_vcpu *vcpu)
7734{ 7752{
7735 int r; 7753 int r;
7736 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 7754 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
7737 r = emulate_instruction(vcpu, EMULTYPE_NO_DECODE); 7755 r = kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE);
7738 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); 7756 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
7739 if (r != EMULATE_DONE) 7757 if (r != EMULATE_DONE)
7740 return 0; 7758 return 0;
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 257f27620bc2..67b9568613f3 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -274,6 +274,8 @@ int kvm_mtrr_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
274bool kvm_mtrr_check_gfn_range_consistency(struct kvm_vcpu *vcpu, gfn_t gfn, 274bool kvm_mtrr_check_gfn_range_consistency(struct kvm_vcpu *vcpu, gfn_t gfn,
275 int page_num); 275 int page_num);
276bool kvm_vector_hashing_enabled(void); 276bool kvm_vector_hashing_enabled(void);
277int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2,
278 int emulation_type, void *insn, int insn_len);
277 279
278#define KVM_SUPPORTED_XCR0 (XFEATURE_MASK_FP | XFEATURE_MASK_SSE \ 280#define KVM_SUPPORTED_XCR0 (XFEATURE_MASK_FP | XFEATURE_MASK_SSE \
279 | XFEATURE_MASK_YMM | XFEATURE_MASK_BNDREGS \ 281 | XFEATURE_MASK_YMM | XFEATURE_MASK_BNDREGS \
diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c
index c8c6ad0d58b8..3f435d7fca5e 100644
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -7,6 +7,8 @@
7#include <linux/uaccess.h> 7#include <linux/uaccess.h>
8#include <linux/export.h> 8#include <linux/export.h>
9 9
10#include <asm/tlbflush.h>
11
10/* 12/*
11 * We rely on the nested NMI work to allow atomic faults from the NMI path; the 13 * We rely on the nested NMI work to allow atomic faults from the NMI path; the
12 * nested NMI paths are careful to preserve CR2. 14 * nested NMI paths are careful to preserve CR2.
@@ -19,6 +21,9 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
19 if (__range_not_ok(from, n, TASK_SIZE)) 21 if (__range_not_ok(from, n, TASK_SIZE))
20 return n; 22 return n;
21 23
24 if (!nmi_uaccess_okay())
25 return n;
26
22 /* 27 /*
23 * Even though this function is typically called from NMI/IRQ context 28 * Even though this function is typically called from NMI/IRQ context
24 * disable pagefaults so that its behaviour is consistent even when 29 * disable pagefaults so that its behaviour is consistent even when
diff --git a/arch/x86/mm/cpu_entry_area.c b/arch/x86/mm/cpu_entry_area.c
index b45f5aaefd74..076ebdce9bd4 100644
--- a/arch/x86/mm/cpu_entry_area.c
+++ b/arch/x86/mm/cpu_entry_area.c
@@ -2,6 +2,8 @@
2 2
3#include <linux/spinlock.h> 3#include <linux/spinlock.h>
4#include <linux/percpu.h> 4#include <linux/percpu.h>
5#include <linux/kallsyms.h>
6#include <linux/kcore.h>
5 7
6#include <asm/cpu_entry_area.h> 8#include <asm/cpu_entry_area.h>
7#include <asm/pgtable.h> 9#include <asm/pgtable.h>
@@ -13,6 +15,7 @@ static DEFINE_PER_CPU_PAGE_ALIGNED(struct entry_stack_page, entry_stack_storage)
13#ifdef CONFIG_X86_64 15#ifdef CONFIG_X86_64
14static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks 16static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks
15 [(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]); 17 [(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]);
18static DEFINE_PER_CPU(struct kcore_list, kcore_entry_trampoline);
16#endif 19#endif
17 20
18struct cpu_entry_area *get_cpu_entry_area(int cpu) 21struct cpu_entry_area *get_cpu_entry_area(int cpu)
@@ -146,10 +149,40 @@ static void __init setup_cpu_entry_area(int cpu)
146 149
147 cea_set_pte(&get_cpu_entry_area(cpu)->entry_trampoline, 150 cea_set_pte(&get_cpu_entry_area(cpu)->entry_trampoline,
148 __pa_symbol(_entry_trampoline), PAGE_KERNEL_RX); 151 __pa_symbol(_entry_trampoline), PAGE_KERNEL_RX);
152 /*
153 * The cpu_entry_area alias addresses are not in the kernel binary
154 * so they do not show up in /proc/kcore normally. This adds entries
155 * for them manually.
156 */
157 kclist_add_remap(&per_cpu(kcore_entry_trampoline, cpu),
158 _entry_trampoline,
159 &get_cpu_entry_area(cpu)->entry_trampoline, PAGE_SIZE);
149#endif 160#endif
150 percpu_setup_debug_store(cpu); 161 percpu_setup_debug_store(cpu);
151} 162}
152 163
164#ifdef CONFIG_X86_64
165int arch_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
166 char *name)
167{
168 unsigned int cpu, ncpu = 0;
169
170 if (symnum >= num_possible_cpus())
171 return -EINVAL;
172
173 for_each_possible_cpu(cpu) {
174 if (ncpu++ >= symnum)
175 break;
176 }
177
178 *value = (unsigned long)&get_cpu_entry_area(cpu)->entry_trampoline;
179 *type = 't';
180 strlcpy(name, "__entry_SYSCALL_64_trampoline", KSYM_NAME_LEN);
181
182 return 0;
183}
184#endif
185
153static __init void setup_cpu_entry_area_ptes(void) 186static __init void setup_cpu_entry_area_ptes(void)
154{ 187{
155#ifdef CONFIG_X86_32 188#ifdef CONFIG_X86_32
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index b9123c497e0a..47bebfe6efa7 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -837,7 +837,7 @@ show_signal_msg(struct pt_regs *regs, unsigned long error_code,
837 837
838 printk(KERN_CONT "\n"); 838 printk(KERN_CONT "\n");
839 839
840 show_opcodes((u8 *)regs->ip, loglvl); 840 show_opcodes(regs, loglvl);
841} 841}
842 842
843static void 843static void
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 5c32a7665492..7a8fc26c1115 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -930,7 +930,7 @@ unsigned long max_swapfile_size(void)
930 930
931 if (boot_cpu_has_bug(X86_BUG_L1TF)) { 931 if (boot_cpu_has_bug(X86_BUG_L1TF)) {
932 /* Limit the swap file size to MAX_PA/2 for L1TF workaround */ 932 /* Limit the swap file size to MAX_PA/2 for L1TF workaround */
933 unsigned long l1tf_limit = l1tf_pfn_limit() + 1; 933 unsigned long long l1tf_limit = l1tf_pfn_limit();
934 /* 934 /*
935 * We encode swap offsets also with 3 bits below those for pfn 935 * We encode swap offsets also with 3 bits below those for pfn
936 * which makes the usable limit higher. 936 * which makes the usable limit higher.
@@ -938,7 +938,7 @@ unsigned long max_swapfile_size(void)
938#if CONFIG_PGTABLE_LEVELS > 2 938#if CONFIG_PGTABLE_LEVELS > 2
939 l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT; 939 l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT;
940#endif 940#endif
941 pages = min_t(unsigned long, l1tf_limit, pages); 941 pages = min_t(unsigned long long, l1tf_limit, pages);
942 } 942 }
943 return pages; 943 return pages;
944} 944}
diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index f40ab8185d94..1e95d57760cf 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -257,7 +257,7 @@ bool pfn_modify_allowed(unsigned long pfn, pgprot_t prot)
257 /* If it's real memory always allow */ 257 /* If it's real memory always allow */
258 if (pfn_valid(pfn)) 258 if (pfn_valid(pfn))
259 return true; 259 return true;
260 if (pfn > l1tf_pfn_limit() && !capable(CAP_SYS_ADMIN)) 260 if (pfn >= l1tf_pfn_limit() && !capable(CAP_SYS_ADMIN))
261 return false; 261 return false;
262 return true; 262 return true;
263} 263}
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 8d6c34fe49be..51a5a69ecac9 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -1420,6 +1420,29 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
1420 return 0; 1420 return 0;
1421} 1421}
1422 1422
1423/*
1424 * Machine check recovery code needs to change cache mode of poisoned
1425 * pages to UC to avoid speculative access logging another error. But
1426 * passing the address of the 1:1 mapping to set_memory_uc() is a fine
1427 * way to encourage a speculative access. So we cheat and flip the top
1428 * bit of the address. This works fine for the code that updates the
1429 * page tables. But at the end of the process we need to flush the cache
1430 * and the non-canonical address causes a #GP fault when used by the
1431 * CLFLUSH instruction.
1432 *
1433 * But in the common case we already have a canonical address. This code
1434 * will fix the top bit if needed and is a no-op otherwise.
1435 */
1436static inline unsigned long make_addr_canonical_again(unsigned long addr)
1437{
1438#ifdef CONFIG_X86_64
1439 return (long)(addr << 1) >> 1;
1440#else
1441 return addr;
1442#endif
1443}
1444
1445
1423static int change_page_attr_set_clr(unsigned long *addr, int numpages, 1446static int change_page_attr_set_clr(unsigned long *addr, int numpages,
1424 pgprot_t mask_set, pgprot_t mask_clr, 1447 pgprot_t mask_set, pgprot_t mask_clr,
1425 int force_split, int in_flag, 1448 int force_split, int in_flag,
@@ -1465,7 +1488,7 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
1465 * Save address for cache flush. *addr is modified in the call 1488 * Save address for cache flush. *addr is modified in the call
1466 * to __change_page_attr_set_clr() below. 1489 * to __change_page_attr_set_clr() below.
1467 */ 1490 */
1468 baddr = *addr; 1491 baddr = make_addr_canonical_again(*addr);
1469 } 1492 }
1470 1493
1471 /* Must avoid aliasing mappings in the highmem code */ 1494 /* Must avoid aliasing mappings in the highmem code */
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index 1555bd7d3449..3d0c83ef6aab 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -512,6 +512,17 @@ static int free_ram_pages_type(u64 start, u64 end)
512 return 0; 512 return 0;
513} 513}
514 514
515static u64 sanitize_phys(u64 address)
516{
517 /*
518 * When changing the memtype for pages containing poison allow
519 * for a "decoy" virtual address (bit 63 clear) passed to
520 * set_memory_X(). __pa() on a "decoy" address results in a
521 * physical address with bit 63 set.
522 */
523 return address & __PHYSICAL_MASK;
524}
525
515/* 526/*
516 * req_type typically has one of the: 527 * req_type typically has one of the:
517 * - _PAGE_CACHE_MODE_WB 528 * - _PAGE_CACHE_MODE_WB
@@ -533,6 +544,8 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,
533 int is_range_ram; 544 int is_range_ram;
534 int err = 0; 545 int err = 0;
535 546
547 start = sanitize_phys(start);
548 end = sanitize_phys(end);
536 BUG_ON(start >= end); /* end is exclusive */ 549 BUG_ON(start >= end); /* end is exclusive */
537 550
538 if (!pat_enabled()) { 551 if (!pat_enabled()) {
@@ -609,6 +622,9 @@ int free_memtype(u64 start, u64 end)
609 if (!pat_enabled()) 622 if (!pat_enabled())
610 return 0; 623 return 0;
611 624
625 start = sanitize_phys(start);
626 end = sanitize_phys(end);
627
612 /* Low ISA region is always mapped WB. No need to track */ 628 /* Low ISA region is always mapped WB. No need to track */
613 if (x86_platform.is_untracked_pat_range(start, end)) 629 if (x86_platform.is_untracked_pat_range(start, end))
614 return 0; 630 return 0;
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index e848a4811785..ae394552fb94 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -269,7 +269,7 @@ static void mop_up_one_pmd(struct mm_struct *mm, pgd_t *pgdp)
269 if (pgd_val(pgd) != 0) { 269 if (pgd_val(pgd) != 0) {
270 pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd); 270 pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
271 271
272 *pgdp = native_make_pgd(0); 272 pgd_clear(pgdp);
273 273
274 paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT); 274 paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
275 pmd_free(mm, pmd); 275 pmd_free(mm, pmd);
@@ -494,7 +494,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
494 int changed = !pte_same(*ptep, entry); 494 int changed = !pte_same(*ptep, entry);
495 495
496 if (changed && dirty) 496 if (changed && dirty)
497 *ptep = entry; 497 set_pte(ptep, entry);
498 498
499 return changed; 499 return changed;
500} 500}
@@ -509,7 +509,7 @@ int pmdp_set_access_flags(struct vm_area_struct *vma,
509 VM_BUG_ON(address & ~HPAGE_PMD_MASK); 509 VM_BUG_ON(address & ~HPAGE_PMD_MASK);
510 510
511 if (changed && dirty) { 511 if (changed && dirty) {
512 *pmdp = entry; 512 set_pmd(pmdp, entry);
513 /* 513 /*
514 * We had a write-protection fault here and changed the pmd 514 * We had a write-protection fault here and changed the pmd
515 * to to more permissive. No need to flush the TLB for that, 515 * to to more permissive. No need to flush the TLB for that,
@@ -529,7 +529,7 @@ int pudp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
529 VM_BUG_ON(address & ~HPAGE_PUD_MASK); 529 VM_BUG_ON(address & ~HPAGE_PUD_MASK);
530 530
531 if (changed && dirty) { 531 if (changed && dirty) {
532 *pudp = entry; 532 set_pud(pudp, entry);
533 /* 533 /*
534 * We had a write-protection fault here and changed the pud 534 * We had a write-protection fault here and changed the pud
535 * to to more permissive. No need to flush the TLB for that, 535 * to to more permissive. No need to flush the TLB for that,
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 31341ae7309f..c1fc1ae6b429 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -248,7 +248,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)
248 * 248 *
249 * Returns a pointer to a PTE on success, or NULL on failure. 249 * Returns a pointer to a PTE on success, or NULL on failure.
250 */ 250 */
251static __init pte_t *pti_user_pagetable_walk_pte(unsigned long address) 251static pte_t *pti_user_pagetable_walk_pte(unsigned long address)
252{ 252{
253 gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO); 253 gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
254 pmd_t *pmd; 254 pmd_t *pmd;
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 9517d1b2a281..e96b99eb800c 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -305,6 +305,10 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
305 305
306 choose_new_asid(next, next_tlb_gen, &new_asid, &need_flush); 306 choose_new_asid(next, next_tlb_gen, &new_asid, &need_flush);
307 307
308 /* Let nmi_uaccess_okay() know that we're changing CR3. */
309 this_cpu_write(cpu_tlbstate.loaded_mm, LOADED_MM_SWITCHING);
310 barrier();
311
308 if (need_flush) { 312 if (need_flush) {
309 this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id); 313 this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id);
310 this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen); 314 this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen);
@@ -335,6 +339,9 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
335 if (next != &init_mm) 339 if (next != &init_mm)
336 this_cpu_write(cpu_tlbstate.last_ctx_id, next->context.ctx_id); 340 this_cpu_write(cpu_tlbstate.last_ctx_id, next->context.ctx_id);
337 341
342 /* Make sure we write CR3 before loaded_mm. */
343 barrier();
344
338 this_cpu_write(cpu_tlbstate.loaded_mm, next); 345 this_cpu_write(cpu_tlbstate.loaded_mm, next);
339 this_cpu_write(cpu_tlbstate.loaded_mm_asid, new_asid); 346 this_cpu_write(cpu_tlbstate.loaded_mm_asid, new_asid);
340 } 347 }
diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
index 324b93328b37..05ca14222463 100644
--- a/arch/x86/platform/efi/efi_32.c
+++ b/arch/x86/platform/efi/efi_32.c
@@ -85,14 +85,10 @@ pgd_t * __init efi_call_phys_prolog(void)
85 85
86void __init efi_call_phys_epilog(pgd_t *save_pgd) 86void __init efi_call_phys_epilog(pgd_t *save_pgd)
87{ 87{
88 struct desc_ptr gdt_descr;
89
90 gdt_descr.address = (unsigned long)get_cpu_gdt_rw(0);
91 gdt_descr.size = GDT_SIZE - 1;
92 load_gdt(&gdt_descr);
93
94 load_cr3(save_pgd); 88 load_cr3(save_pgd);
95 __flush_tlb_all(); 89 __flush_tlb_all();
90
91 load_fixmap_gdt(0);
96} 92}
97 93
98void __init efi_runtime_update_mappings(void) 94void __init efi_runtime_update_mappings(void)
diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 45b700ac5fe7..2fe5c9b1816b 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -435,14 +435,13 @@ static void xen_set_pud(pud_t *ptr, pud_t val)
435static void xen_set_pte_atomic(pte_t *ptep, pte_t pte) 435static void xen_set_pte_atomic(pte_t *ptep, pte_t pte)
436{ 436{
437 trace_xen_mmu_set_pte_atomic(ptep, pte); 437 trace_xen_mmu_set_pte_atomic(ptep, pte);
438 set_64bit((u64 *)ptep, native_pte_val(pte)); 438 __xen_set_pte(ptep, pte);
439} 439}
440 440
441static void xen_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) 441static void xen_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
442{ 442{
443 trace_xen_mmu_pte_clear(mm, addr, ptep); 443 trace_xen_mmu_pte_clear(mm, addr, ptep);
444 if (!xen_batched_set_pte(ptep, native_make_pte(0))) 444 __xen_set_pte(ptep, native_make_pte(0));
445 native_pte_clear(mm, addr, ptep);
446} 445}
447 446
448static void xen_pmd_clear(pmd_t *pmdp) 447static void xen_pmd_clear(pmd_t *pmdp)
@@ -1570,7 +1569,7 @@ static void __init xen_set_pte_init(pte_t *ptep, pte_t pte)
1570 pte = __pte_ma(((pte_val_ma(*ptep) & _PAGE_RW) | ~_PAGE_RW) & 1569 pte = __pte_ma(((pte_val_ma(*ptep) & _PAGE_RW) | ~_PAGE_RW) &
1571 pte_val_ma(pte)); 1570 pte_val_ma(pte));
1572#endif 1571#endif
1573 native_set_pte(ptep, pte); 1572 __xen_set_pte(ptep, pte);
1574} 1573}
1575 1574
1576/* Early in boot, while setting up the initial pagetable, assume 1575/* Early in boot, while setting up the initial pagetable, assume
@@ -2061,7 +2060,6 @@ void __init xen_relocate_p2m(void)
2061 pud_t *pud; 2060 pud_t *pud;
2062 pgd_t *pgd; 2061 pgd_t *pgd;
2063 unsigned long *new_p2m; 2062 unsigned long *new_p2m;
2064 int save_pud;
2065 2063
2066 size = PAGE_ALIGN(xen_start_info->nr_pages * sizeof(unsigned long)); 2064 size = PAGE_ALIGN(xen_start_info->nr_pages * sizeof(unsigned long));
2067 n_pte = roundup(size, PAGE_SIZE) >> PAGE_SHIFT; 2065 n_pte = roundup(size, PAGE_SIZE) >> PAGE_SHIFT;
@@ -2091,7 +2089,6 @@ void __init xen_relocate_p2m(void)
2091 2089
2092 pgd = __va(read_cr3_pa()); 2090 pgd = __va(read_cr3_pa());
2093 new_p2m = (unsigned long *)(2 * PGDIR_SIZE); 2091 new_p2m = (unsigned long *)(2 * PGDIR_SIZE);
2094 save_pud = n_pud;
2095 for (idx_pud = 0; idx_pud < n_pud; idx_pud++) { 2092 for (idx_pud = 0; idx_pud < n_pud; idx_pud++) {
2096 pud = early_memremap(pud_phys, PAGE_SIZE); 2093 pud = early_memremap(pud_phys, PAGE_SIZE);
2097 clear_page(pud); 2094 clear_page(pud);
diff --git a/arch/xtensa/Makefile b/arch/xtensa/Makefile
index 3a934b72a272..295c120ed099 100644
--- a/arch/xtensa/Makefile
+++ b/arch/xtensa/Makefile
@@ -49,7 +49,7 @@ KBUILD_CFLAGS += $(call cc-option,-mno-serialize-volatile,)
49KBUILD_AFLAGS += -mlongcalls -mtext-section-literals 49KBUILD_AFLAGS += -mlongcalls -mtext-section-literals
50 50
51ifneq ($(CONFIG_LD_NO_RELAX),) 51ifneq ($(CONFIG_LD_NO_RELAX),)
52LDFLAGS := --no-relax 52KBUILD_LDFLAGS := --no-relax
53endif 53endif
54 54
55ifeq ($(shell echo __XTENSA_EB__ | $(CC) -E - | grep -v "\#"),1) 55ifeq ($(shell echo __XTENSA_EB__ | $(CC) -E - | grep -v "\#"),1)
diff --git a/arch/xtensa/boot/boot-elf/Makefile b/arch/xtensa/boot/boot-elf/Makefile
index 521471981356..12ae1e91cb75 100644
--- a/arch/xtensa/boot/boot-elf/Makefile
+++ b/arch/xtensa/boot/boot-elf/Makefile
@@ -25,7 +25,7 @@ $(obj)/Image.o: vmlinux.bin $(OBJS)
25 $(OBJS) $@ 25 $(OBJS) $@
26 26
27$(obj)/../Image.elf: $(obj)/Image.o $(obj)/boot.lds 27$(obj)/../Image.elf: $(obj)/Image.o $(obj)/boot.lds
28 $(Q)$(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) \ 28 $(Q)$(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) \
29 -T $(obj)/boot.lds \ 29 -T $(obj)/boot.lds \
30 --build-id=none \ 30 --build-id=none \
31 -o $@ $(obj)/Image.o 31 -o $@ $(obj)/Image.o
diff --git a/certs/system_certificates.S b/certs/system_certificates.S
index 3918ff7235ed..8f29058adf93 100644
--- a/certs/system_certificates.S
+++ b/certs/system_certificates.S
@@ -5,8 +5,8 @@
5 __INITRODATA 5 __INITRODATA
6 6
7 .align 8 7 .align 8
8 .globl VMLINUX_SYMBOL(system_certificate_list) 8 .globl system_certificate_list
9VMLINUX_SYMBOL(system_certificate_list): 9system_certificate_list:
10__cert_list_start: 10__cert_list_start:
11#ifdef CONFIG_MODULE_SIG 11#ifdef CONFIG_MODULE_SIG
12 .incbin "certs/signing_key.x509" 12 .incbin "certs/signing_key.x509"
@@ -15,21 +15,21 @@ __cert_list_start:
15__cert_list_end: 15__cert_list_end:
16 16
17#ifdef CONFIG_SYSTEM_EXTRA_CERTIFICATE 17#ifdef CONFIG_SYSTEM_EXTRA_CERTIFICATE
18 .globl VMLINUX_SYMBOL(system_extra_cert) 18 .globl system_extra_cert
19 .size system_extra_cert, CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE 19 .size system_extra_cert, CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE
20VMLINUX_SYMBOL(system_extra_cert): 20system_extra_cert:
21 .fill CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE, 1, 0 21 .fill CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE, 1, 0
22 22
23 .align 4 23 .align 4
24 .globl VMLINUX_SYMBOL(system_extra_cert_used) 24 .globl system_extra_cert_used
25VMLINUX_SYMBOL(system_extra_cert_used): 25system_extra_cert_used:
26 .int 0 26 .int 0
27 27
28#endif /* CONFIG_SYSTEM_EXTRA_CERTIFICATE */ 28#endif /* CONFIG_SYSTEM_EXTRA_CERTIFICATE */
29 29
30 .align 8 30 .align 8
31 .globl VMLINUX_SYMBOL(system_certificate_list_size) 31 .globl system_certificate_list_size
32VMLINUX_SYMBOL(system_certificate_list_size): 32system_certificate_list_size:
33#ifdef CONFIG_64BIT 33#ifdef CONFIG_64BIT
34 .quad __cert_list_end - __cert_list_start 34 .quad __cert_list_end - __cert_list_start
35#else 35#else
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 9706613eecf9..bf64cfa30feb 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -879,7 +879,7 @@ static void acpi_lpss_dismiss(struct device *dev)
879#define LPSS_GPIODEF0_DMA_LLP BIT(13) 879#define LPSS_GPIODEF0_DMA_LLP BIT(13)
880 880
881static DEFINE_MUTEX(lpss_iosf_mutex); 881static DEFINE_MUTEX(lpss_iosf_mutex);
882static bool lpss_iosf_d3_entered; 882static bool lpss_iosf_d3_entered = true;
883 883
884static void lpss_iosf_enter_d3_state(void) 884static void lpss_iosf_enter_d3_state(void)
885{ 885{
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 292088fcc624..d2e29a19890d 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -35,11 +35,11 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#ifdef CONFIG_X86 36#ifdef CONFIG_X86
37#include <asm/mpspec.h> 37#include <asm/mpspec.h>
38#include <linux/dmi.h>
38#endif 39#endif
39#include <linux/acpi_iort.h> 40#include <linux/acpi_iort.h>
40#include <linux/pci.h> 41#include <linux/pci.h>
41#include <acpi/apei.h> 42#include <acpi/apei.h>
42#include <linux/dmi.h>
43#include <linux/suspend.h> 43#include <linux/suspend.h>
44 44
45#include "internal.h" 45#include "internal.h"
@@ -82,10 +82,6 @@ static const struct dmi_system_id dsdt_dmi_table[] __initconst = {
82 }, 82 },
83 {} 83 {}
84}; 84};
85#else
86static const struct dmi_system_id dsdt_dmi_table[] __initconst = {
87 {}
88};
89#endif 85#endif
90 86
91/* -------------------------------------------------------------------------- 87/* --------------------------------------------------------------------------
@@ -1033,11 +1029,16 @@ void __init acpi_early_init(void)
1033 1029
1034 acpi_permanent_mmap = true; 1030 acpi_permanent_mmap = true;
1035 1031
1032#ifdef CONFIG_X86
1036 /* 1033 /*
1037 * If the machine falls into the DMI check table, 1034 * If the machine falls into the DMI check table,
1038 * DSDT will be copied to memory 1035 * DSDT will be copied to memory.
1036 * Note that calling dmi_check_system() here on other architectures
1037 * would not be OK because only x86 initializes dmi early enough.
1038 * Thankfully only x86 systems need such quirks for now.
1039 */ 1039 */
1040 dmi_check_system(dsdt_dmi_table); 1040 dmi_check_system(dsdt_dmi_table);
1041#endif
1041 1042
1042 status = acpi_reallocate_root_table(); 1043 status = acpi_reallocate_root_table();
1043 if (ACPI_FAILURE(status)) { 1044 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 7c479002e798..b072cfc5f20e 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -1699,7 +1699,7 @@ static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
1699{ 1699{
1700 struct acpi_device *adev, *adev_dimm; 1700 struct acpi_device *adev, *adev_dimm;
1701 struct device *dev = acpi_desc->dev; 1701 struct device *dev = acpi_desc->dev;
1702 unsigned long dsm_mask; 1702 unsigned long dsm_mask, label_mask;
1703 const guid_t *guid; 1703 const guid_t *guid;
1704 int i; 1704 int i;
1705 int family = -1; 1705 int family = -1;
@@ -1771,6 +1771,16 @@ static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
1771 1ULL << i)) 1771 1ULL << i))
1772 set_bit(i, &nfit_mem->dsm_mask); 1772 set_bit(i, &nfit_mem->dsm_mask);
1773 1773
1774 /*
1775 * Prefer the NVDIMM_FAMILY_INTEL label read commands if present
1776 * due to their better semantics handling locked capacity.
1777 */
1778 label_mask = 1 << ND_CMD_GET_CONFIG_SIZE | 1 << ND_CMD_GET_CONFIG_DATA
1779 | 1 << ND_CMD_SET_CONFIG_DATA;
1780 if (family == NVDIMM_FAMILY_INTEL
1781 && (dsm_mask & label_mask) == label_mask)
1782 return 0;
1783
1774 if (acpi_nvdimm_has_method(adev_dimm, "_LSI") 1784 if (acpi_nvdimm_has_method(adev_dimm, "_LSI")
1775 && acpi_nvdimm_has_method(adev_dimm, "_LSR")) { 1785 && acpi_nvdimm_has_method(adev_dimm, "_LSR")) {
1776 dev_dbg(dev, "%s: has _LSR\n", dev_name(&adev_dimm->dev)); 1786 dev_dbg(dev, "%s: has _LSR\n", dev_name(&adev_dimm->dev));
@@ -2559,7 +2569,12 @@ static void ars_complete(struct acpi_nfit_desc *acpi_desc,
2559 test_bit(ARS_SHORT, &nfit_spa->ars_state) 2569 test_bit(ARS_SHORT, &nfit_spa->ars_state)
2560 ? "short" : "long"); 2570 ? "short" : "long");
2561 clear_bit(ARS_SHORT, &nfit_spa->ars_state); 2571 clear_bit(ARS_SHORT, &nfit_spa->ars_state);
2562 set_bit(ARS_DONE, &nfit_spa->ars_state); 2572 if (test_and_clear_bit(ARS_REQ_REDO, &nfit_spa->ars_state)) {
2573 set_bit(ARS_SHORT, &nfit_spa->ars_state);
2574 set_bit(ARS_REQ, &nfit_spa->ars_state);
2575 dev_dbg(dev, "ARS: processing scrub request received while in progress\n");
2576 } else
2577 set_bit(ARS_DONE, &nfit_spa->ars_state);
2563} 2578}
2564 2579
2565static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc) 2580static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc)
@@ -3256,9 +3271,10 @@ int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc, unsigned long flags)
3256 if (test_bit(ARS_FAILED, &nfit_spa->ars_state)) 3271 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
3257 continue; 3272 continue;
3258 3273
3259 if (test_and_set_bit(ARS_REQ, &nfit_spa->ars_state)) 3274 if (test_and_set_bit(ARS_REQ, &nfit_spa->ars_state)) {
3260 busy++; 3275 busy++;
3261 else { 3276 set_bit(ARS_REQ_REDO, &nfit_spa->ars_state);
3277 } else {
3262 if (test_bit(ARS_SHORT, &flags)) 3278 if (test_bit(ARS_SHORT, &flags))
3263 set_bit(ARS_SHORT, &nfit_spa->ars_state); 3279 set_bit(ARS_SHORT, &nfit_spa->ars_state);
3264 scheduled++; 3280 scheduled++;
diff --git a/drivers/acpi/nfit/nfit.h b/drivers/acpi/nfit/nfit.h
index a97ff42fe311..d1274ea2d251 100644
--- a/drivers/acpi/nfit/nfit.h
+++ b/drivers/acpi/nfit/nfit.h
@@ -119,6 +119,7 @@ enum nfit_dimm_notifiers {
119 119
120enum nfit_ars_state { 120enum nfit_ars_state {
121 ARS_REQ, 121 ARS_REQ,
122 ARS_REQ_REDO,
122 ARS_DONE, 123 ARS_DONE,
123 ARS_SHORT, 124 ARS_SHORT,
124 ARS_FAILED, 125 ARS_FAILED,
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 172e32840256..599e01bcdef2 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -7394,4 +7394,4 @@ EXPORT_SYMBOL_GPL(ata_cable_unknown);
7394EXPORT_SYMBOL_GPL(ata_cable_ignore); 7394EXPORT_SYMBOL_GPL(ata_cable_ignore);
7395EXPORT_SYMBOL_GPL(ata_cable_sata); 7395EXPORT_SYMBOL_GPL(ata_cable_sata);
7396EXPORT_SYMBOL_GPL(ata_host_get); 7396EXPORT_SYMBOL_GPL(ata_host_get);
7397EXPORT_SYMBOL_GPL(ata_host_put); \ No newline at end of file 7397EXPORT_SYMBOL_GPL(ata_host_put);
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index c8a1cb0b6136..817320c7c4c1 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -417,25 +417,23 @@ static ssize_t show_valid_zones(struct device *dev,
417 int nid; 417 int nid;
418 418
419 /* 419 /*
420 * The block contains more than one zone can not be offlined.
421 * This can happen e.g. for ZONE_DMA and ZONE_DMA32
422 */
423 if (!test_pages_in_a_zone(start_pfn, start_pfn + nr_pages, &valid_start_pfn, &valid_end_pfn))
424 return sprintf(buf, "none\n");
425
426 start_pfn = valid_start_pfn;
427 nr_pages = valid_end_pfn - start_pfn;
428
429 /*
430 * Check the existing zone. Make sure that we do that only on the 420 * Check the existing zone. Make sure that we do that only on the
431 * online nodes otherwise the page_zone is not reliable 421 * online nodes otherwise the page_zone is not reliable
432 */ 422 */
433 if (mem->state == MEM_ONLINE) { 423 if (mem->state == MEM_ONLINE) {
424 /*
425 * The block contains more than one zone can not be offlined.
426 * This can happen e.g. for ZONE_DMA and ZONE_DMA32
427 */
428 if (!test_pages_in_a_zone(start_pfn, start_pfn + nr_pages,
429 &valid_start_pfn, &valid_end_pfn))
430 return sprintf(buf, "none\n");
431 start_pfn = valid_start_pfn;
434 strcat(buf, page_zone(pfn_to_page(start_pfn))->name); 432 strcat(buf, page_zone(pfn_to_page(start_pfn))->name);
435 goto out; 433 goto out;
436 } 434 }
437 435
438 nid = pfn_to_nid(start_pfn); 436 nid = mem->nid;
439 default_zone = zone_for_pfn_range(MMOP_ONLINE_KEEP, nid, start_pfn, nr_pages); 437 default_zone = zone_for_pfn_range(MMOP_ONLINE_KEEP, nid, start_pfn, nr_pages);
440 strcat(buf, default_zone->name); 438 strcat(buf, default_zone->name);
441 439
diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index 8e2e4757adcb..5a42ae4078c2 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -185,7 +185,7 @@ EXPORT_SYMBOL_GPL(of_pm_clk_add_clk);
185int of_pm_clk_add_clks(struct device *dev) 185int of_pm_clk_add_clks(struct device *dev)
186{ 186{
187 struct clk **clks; 187 struct clk **clks;
188 unsigned int i, count; 188 int i, count;
189 int ret; 189 int ret;
190 190
191 if (!dev || !dev->of_node) 191 if (!dev || !dev->of_node)
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index db253cd5b32a..d0666f5ce003 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -118,7 +118,6 @@ static struct dentry *dfs_device_status;
118 118
119static u32 cpu_use[NR_CPUS]; 119static u32 cpu_use[NR_CPUS];
120 120
121static DEFINE_SPINLOCK(rssd_index_lock);
122static DEFINE_IDA(rssd_index_ida); 121static DEFINE_IDA(rssd_index_ida);
123 122
124static int mtip_block_initialize(struct driver_data *dd); 123static int mtip_block_initialize(struct driver_data *dd);
@@ -3767,20 +3766,10 @@ static int mtip_block_initialize(struct driver_data *dd)
3767 goto alloc_disk_error; 3766 goto alloc_disk_error;
3768 } 3767 }
3769 3768
3770 /* Generate the disk name, implemented same as in sd.c */ 3769 rv = ida_alloc(&rssd_index_ida, GFP_KERNEL);
3771 do { 3770 if (rv < 0)
3772 if (!ida_pre_get(&rssd_index_ida, GFP_KERNEL)) {
3773 rv = -ENOMEM;
3774 goto ida_get_error;
3775 }
3776
3777 spin_lock(&rssd_index_lock);
3778 rv = ida_get_new(&rssd_index_ida, &index);
3779 spin_unlock(&rssd_index_lock);
3780 } while (rv == -EAGAIN);
3781
3782 if (rv)
3783 goto ida_get_error; 3771 goto ida_get_error;
3772 index = rv;
3784 3773
3785 rv = rssd_disk_name_format("rssd", 3774 rv = rssd_disk_name_format("rssd",
3786 index, 3775 index,
@@ -3922,9 +3911,7 @@ block_queue_alloc_init_error:
3922block_queue_alloc_tag_error: 3911block_queue_alloc_tag_error:
3923 mtip_hw_debugfs_exit(dd); 3912 mtip_hw_debugfs_exit(dd);
3924disk_index_error: 3913disk_index_error:
3925 spin_lock(&rssd_index_lock); 3914 ida_free(&rssd_index_ida, index);
3926 ida_remove(&rssd_index_ida, index);
3927 spin_unlock(&rssd_index_lock);
3928 3915
3929ida_get_error: 3916ida_get_error:
3930 put_disk(dd->disk); 3917 put_disk(dd->disk);
@@ -4012,9 +3999,7 @@ static int mtip_block_remove(struct driver_data *dd)
4012 } 3999 }
4013 dd->disk = NULL; 4000 dd->disk = NULL;
4014 4001
4015 spin_lock(&rssd_index_lock); 4002 ida_free(&rssd_index_ida, dd->index);
4016 ida_remove(&rssd_index_ida, dd->index);
4017 spin_unlock(&rssd_index_lock);
4018 4003
4019 /* De-initialize the protocol layer. */ 4004 /* De-initialize the protocol layer. */
4020 mtip_hw_exit(dd); 4005 mtip_hw_exit(dd);
@@ -4054,9 +4039,7 @@ static int mtip_block_shutdown(struct driver_data *dd)
4054 dd->queue = NULL; 4039 dd->queue = NULL;
4055 } 4040 }
4056 4041
4057 spin_lock(&rssd_index_lock); 4042 ida_free(&rssd_index_ida, dd->index);
4058 ida_remove(&rssd_index_ida, dd->index);
4059 spin_unlock(&rssd_index_lock);
4060 return 0; 4043 return 0;
4061} 4044}
4062 4045
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 7915f3b03736..73ed5f3a862d 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -4207,11 +4207,13 @@ static ssize_t rbd_parent_show(struct device *dev,
4207 4207
4208 count += sprintf(&buf[count], "%s" 4208 count += sprintf(&buf[count], "%s"
4209 "pool_id %llu\npool_name %s\n" 4209 "pool_id %llu\npool_name %s\n"
4210 "pool_ns %s\n"
4210 "image_id %s\nimage_name %s\n" 4211 "image_id %s\nimage_name %s\n"
4211 "snap_id %llu\nsnap_name %s\n" 4212 "snap_id %llu\nsnap_name %s\n"
4212 "overlap %llu\n", 4213 "overlap %llu\n",
4213 !count ? "" : "\n", /* first? */ 4214 !count ? "" : "\n", /* first? */
4214 spec->pool_id, spec->pool_name, 4215 spec->pool_id, spec->pool_name,
4216 spec->pool_ns ?: "",
4215 spec->image_id, spec->image_name ?: "(unknown)", 4217 spec->image_id, spec->image_name ?: "(unknown)",
4216 spec->snap_id, spec->snap_name, 4218 spec->snap_id, spec->snap_name,
4217 rbd_dev->parent_overlap); 4219 rbd_dev->parent_overlap);
@@ -4584,47 +4586,177 @@ static int rbd_dev_v2_features(struct rbd_device *rbd_dev)
4584 &rbd_dev->header.features); 4586 &rbd_dev->header.features);
4585} 4587}
4586 4588
4589struct parent_image_info {
4590 u64 pool_id;
4591 const char *pool_ns;
4592 const char *image_id;
4593 u64 snap_id;
4594
4595 bool has_overlap;
4596 u64 overlap;
4597};
4598
4599/*
4600 * The caller is responsible for @pii.
4601 */
4602static int decode_parent_image_spec(void **p, void *end,
4603 struct parent_image_info *pii)
4604{
4605 u8 struct_v;
4606 u32 struct_len;
4607 int ret;
4608
4609 ret = ceph_start_decoding(p, end, 1, "ParentImageSpec",
4610 &struct_v, &struct_len);
4611 if (ret)
4612 return ret;
4613
4614 ceph_decode_64_safe(p, end, pii->pool_id, e_inval);
4615 pii->pool_ns = ceph_extract_encoded_string(p, end, NULL, GFP_KERNEL);
4616 if (IS_ERR(pii->pool_ns)) {
4617 ret = PTR_ERR(pii->pool_ns);
4618 pii->pool_ns = NULL;
4619 return ret;
4620 }
4621 pii->image_id = ceph_extract_encoded_string(p, end, NULL, GFP_KERNEL);
4622 if (IS_ERR(pii->image_id)) {
4623 ret = PTR_ERR(pii->image_id);
4624 pii->image_id = NULL;
4625 return ret;
4626 }
4627 ceph_decode_64_safe(p, end, pii->snap_id, e_inval);
4628 return 0;
4629
4630e_inval:
4631 return -EINVAL;
4632}
4633
4634static int __get_parent_info(struct rbd_device *rbd_dev,
4635 struct page *req_page,
4636 struct page *reply_page,
4637 struct parent_image_info *pii)
4638{
4639 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
4640 size_t reply_len = PAGE_SIZE;
4641 void *p, *end;
4642 int ret;
4643
4644 ret = ceph_osdc_call(osdc, &rbd_dev->header_oid, &rbd_dev->header_oloc,
4645 "rbd", "parent_get", CEPH_OSD_FLAG_READ,
4646 req_page, sizeof(u64), reply_page, &reply_len);
4647 if (ret)
4648 return ret == -EOPNOTSUPP ? 1 : ret;
4649
4650 p = page_address(reply_page);
4651 end = p + reply_len;
4652 ret = decode_parent_image_spec(&p, end, pii);
4653 if (ret)
4654 return ret;
4655
4656 ret = ceph_osdc_call(osdc, &rbd_dev->header_oid, &rbd_dev->header_oloc,
4657 "rbd", "parent_overlap_get", CEPH_OSD_FLAG_READ,
4658 req_page, sizeof(u64), reply_page, &reply_len);
4659 if (ret)
4660 return ret;
4661
4662 p = page_address(reply_page);
4663 end = p + reply_len;
4664 ceph_decode_8_safe(&p, end, pii->has_overlap, e_inval);
4665 if (pii->has_overlap)
4666 ceph_decode_64_safe(&p, end, pii->overlap, e_inval);
4667
4668 return 0;
4669
4670e_inval:
4671 return -EINVAL;
4672}
4673
4674/*
4675 * The caller is responsible for @pii.
4676 */
4677static int __get_parent_info_legacy(struct rbd_device *rbd_dev,
4678 struct page *req_page,
4679 struct page *reply_page,
4680 struct parent_image_info *pii)
4681{
4682 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
4683 size_t reply_len = PAGE_SIZE;
4684 void *p, *end;
4685 int ret;
4686
4687 ret = ceph_osdc_call(osdc, &rbd_dev->header_oid, &rbd_dev->header_oloc,
4688 "rbd", "get_parent", CEPH_OSD_FLAG_READ,
4689 req_page, sizeof(u64), reply_page, &reply_len);
4690 if (ret)
4691 return ret;
4692
4693 p = page_address(reply_page);
4694 end = p + reply_len;
4695 ceph_decode_64_safe(&p, end, pii->pool_id, e_inval);
4696 pii->image_id = ceph_extract_encoded_string(&p, end, NULL, GFP_KERNEL);
4697 if (IS_ERR(pii->image_id)) {
4698 ret = PTR_ERR(pii->image_id);
4699 pii->image_id = NULL;
4700 return ret;
4701 }
4702 ceph_decode_64_safe(&p, end, pii->snap_id, e_inval);
4703 pii->has_overlap = true;
4704 ceph_decode_64_safe(&p, end, pii->overlap, e_inval);
4705
4706 return 0;
4707
4708e_inval:
4709 return -EINVAL;
4710}
4711
4712static int get_parent_info(struct rbd_device *rbd_dev,
4713 struct parent_image_info *pii)
4714{
4715 struct page *req_page, *reply_page;
4716 void *p;
4717 int ret;
4718
4719 req_page = alloc_page(GFP_KERNEL);
4720 if (!req_page)
4721 return -ENOMEM;
4722
4723 reply_page = alloc_page(GFP_KERNEL);
4724 if (!reply_page) {
4725 __free_page(req_page);
4726 return -ENOMEM;
4727 }
4728
4729 p = page_address(req_page);
4730 ceph_encode_64(&p, rbd_dev->spec->snap_id);
4731 ret = __get_parent_info(rbd_dev, req_page, reply_page, pii);
4732 if (ret > 0)
4733 ret = __get_parent_info_legacy(rbd_dev, req_page, reply_page,
4734 pii);
4735
4736 __free_page(req_page);
4737 __free_page(reply_page);
4738 return ret;
4739}
4740
4587static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) 4741static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
4588{ 4742{
4589 struct rbd_spec *parent_spec; 4743 struct rbd_spec *parent_spec;
4590 size_t size; 4744 struct parent_image_info pii = { 0 };
4591 void *reply_buf = NULL;
4592 __le64 snapid;
4593 void *p;
4594 void *end;
4595 u64 pool_id;
4596 char *image_id;
4597 u64 snap_id;
4598 u64 overlap;
4599 int ret; 4745 int ret;
4600 4746
4601 parent_spec = rbd_spec_alloc(); 4747 parent_spec = rbd_spec_alloc();
4602 if (!parent_spec) 4748 if (!parent_spec)
4603 return -ENOMEM; 4749 return -ENOMEM;
4604 4750
4605 size = sizeof (__le64) + /* pool_id */ 4751 ret = get_parent_info(rbd_dev, &pii);
4606 sizeof (__le32) + RBD_IMAGE_ID_LEN_MAX + /* image_id */ 4752 if (ret)
4607 sizeof (__le64) + /* snap_id */
4608 sizeof (__le64); /* overlap */
4609 reply_buf = kmalloc(size, GFP_KERNEL);
4610 if (!reply_buf) {
4611 ret = -ENOMEM;
4612 goto out_err; 4753 goto out_err;
4613 }
4614 4754
4615 snapid = cpu_to_le64(rbd_dev->spec->snap_id); 4755 dout("%s pool_id %llu pool_ns %s image_id %s snap_id %llu has_overlap %d overlap %llu\n",
4616 ret = rbd_obj_method_sync(rbd_dev, &rbd_dev->header_oid, 4756 __func__, pii.pool_id, pii.pool_ns, pii.image_id, pii.snap_id,
4617 &rbd_dev->header_oloc, "get_parent", 4757 pii.has_overlap, pii.overlap);
4618 &snapid, sizeof(snapid), reply_buf, size);
4619 dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret);
4620 if (ret < 0)
4621 goto out_err;
4622 4758
4623 p = reply_buf; 4759 if (pii.pool_id == CEPH_NOPOOL || !pii.has_overlap) {
4624 end = reply_buf + ret;
4625 ret = -ERANGE;
4626 ceph_decode_64_safe(&p, end, pool_id, out_err);
4627 if (pool_id == CEPH_NOPOOL) {
4628 /* 4760 /*
4629 * Either the parent never existed, or we have 4761 * Either the parent never existed, or we have
4630 * record of it but the image got flattened so it no 4762 * record of it but the image got flattened so it no
@@ -4633,6 +4765,10 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
4633 * overlap to 0. The effect of this is that all new 4765 * overlap to 0. The effect of this is that all new
4634 * requests will be treated as if the image had no 4766 * requests will be treated as if the image had no
4635 * parent. 4767 * parent.
4768 *
4769 * If !pii.has_overlap, the parent image spec is not
4770 * applicable. It's there to avoid duplication in each
4771 * snapshot record.
4636 */ 4772 */
4637 if (rbd_dev->parent_overlap) { 4773 if (rbd_dev->parent_overlap) {
4638 rbd_dev->parent_overlap = 0; 4774 rbd_dev->parent_overlap = 0;
@@ -4647,51 +4783,36 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
4647 /* The ceph file layout needs to fit pool id in 32 bits */ 4783 /* The ceph file layout needs to fit pool id in 32 bits */
4648 4784
4649 ret = -EIO; 4785 ret = -EIO;
4650 if (pool_id > (u64)U32_MAX) { 4786 if (pii.pool_id > (u64)U32_MAX) {
4651 rbd_warn(NULL, "parent pool id too large (%llu > %u)", 4787 rbd_warn(NULL, "parent pool id too large (%llu > %u)",
4652 (unsigned long long)pool_id, U32_MAX); 4788 (unsigned long long)pii.pool_id, U32_MAX);
4653 goto out_err; 4789 goto out_err;
4654 } 4790 }
4655 4791
4656 image_id = ceph_extract_encoded_string(&p, end, NULL, GFP_KERNEL);
4657 if (IS_ERR(image_id)) {
4658 ret = PTR_ERR(image_id);
4659 goto out_err;
4660 }
4661 ceph_decode_64_safe(&p, end, snap_id, out_err);
4662 ceph_decode_64_safe(&p, end, overlap, out_err);
4663
4664 /* 4792 /*
4665 * The parent won't change (except when the clone is 4793 * The parent won't change (except when the clone is
4666 * flattened, already handled that). So we only need to 4794 * flattened, already handled that). So we only need to
4667 * record the parent spec we have not already done so. 4795 * record the parent spec we have not already done so.
4668 */ 4796 */
4669 if (!rbd_dev->parent_spec) { 4797 if (!rbd_dev->parent_spec) {
4670 parent_spec->pool_id = pool_id; 4798 parent_spec->pool_id = pii.pool_id;
4671 parent_spec->image_id = image_id; 4799 if (pii.pool_ns && *pii.pool_ns) {
4672 parent_spec->snap_id = snap_id; 4800 parent_spec->pool_ns = pii.pool_ns;
4673 4801 pii.pool_ns = NULL;
4674 /* TODO: support cloning across namespaces */
4675 if (rbd_dev->spec->pool_ns) {
4676 parent_spec->pool_ns = kstrdup(rbd_dev->spec->pool_ns,
4677 GFP_KERNEL);
4678 if (!parent_spec->pool_ns) {
4679 ret = -ENOMEM;
4680 goto out_err;
4681 }
4682 } 4802 }
4803 parent_spec->image_id = pii.image_id;
4804 pii.image_id = NULL;
4805 parent_spec->snap_id = pii.snap_id;
4683 4806
4684 rbd_dev->parent_spec = parent_spec; 4807 rbd_dev->parent_spec = parent_spec;
4685 parent_spec = NULL; /* rbd_dev now owns this */ 4808 parent_spec = NULL; /* rbd_dev now owns this */
4686 } else {
4687 kfree(image_id);
4688 } 4809 }
4689 4810
4690 /* 4811 /*
4691 * We always update the parent overlap. If it's zero we issue 4812 * We always update the parent overlap. If it's zero we issue
4692 * a warning, as we will proceed as if there was no parent. 4813 * a warning, as we will proceed as if there was no parent.
4693 */ 4814 */
4694 if (!overlap) { 4815 if (!pii.overlap) {
4695 if (parent_spec) { 4816 if (parent_spec) {
4696 /* refresh, careful to warn just once */ 4817 /* refresh, careful to warn just once */
4697 if (rbd_dev->parent_overlap) 4818 if (rbd_dev->parent_overlap)
@@ -4702,14 +4823,14 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
4702 rbd_warn(rbd_dev, "clone is standalone (overlap 0)"); 4823 rbd_warn(rbd_dev, "clone is standalone (overlap 0)");
4703 } 4824 }
4704 } 4825 }
4705 rbd_dev->parent_overlap = overlap; 4826 rbd_dev->parent_overlap = pii.overlap;
4706 4827
4707out: 4828out:
4708 ret = 0; 4829 ret = 0;
4709out_err: 4830out_err:
4710 kfree(reply_buf); 4831 kfree(pii.pool_ns);
4832 kfree(pii.image_id);
4711 rbd_spec_put(parent_spec); 4833 rbd_spec_put(parent_spec);
4712
4713 return ret; 4834 return ret;
4714} 4835}
4715 4836
diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index b7d71914a32a..f2c631ce793c 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -58,7 +58,6 @@ MODULE_PARM_DESC(sync_start, "On by Default: Driver load will not complete "
58 "until the card startup has completed."); 58 "until the card startup has completed.");
59 59
60static DEFINE_IDA(rsxx_disk_ida); 60static DEFINE_IDA(rsxx_disk_ida);
61static DEFINE_SPINLOCK(rsxx_ida_lock);
62 61
63/* --------------------Debugfs Setup ------------------- */ 62/* --------------------Debugfs Setup ------------------- */
64 63
@@ -771,19 +770,10 @@ static int rsxx_pci_probe(struct pci_dev *dev,
771 card->dev = dev; 770 card->dev = dev;
772 pci_set_drvdata(dev, card); 771 pci_set_drvdata(dev, card);
773 772
774 do { 773 st = ida_alloc(&rsxx_disk_ida, GFP_KERNEL);
775 if (!ida_pre_get(&rsxx_disk_ida, GFP_KERNEL)) { 774 if (st < 0)
776 st = -ENOMEM;
777 goto failed_ida_get;
778 }
779
780 spin_lock(&rsxx_ida_lock);
781 st = ida_get_new(&rsxx_disk_ida, &card->disk_id);
782 spin_unlock(&rsxx_ida_lock);
783 } while (st == -EAGAIN);
784
785 if (st)
786 goto failed_ida_get; 775 goto failed_ida_get;
776 card->disk_id = st;
787 777
788 st = pci_enable_device(dev); 778 st = pci_enable_device(dev);
789 if (st) 779 if (st)
@@ -985,9 +975,7 @@ failed_request_regions:
985failed_dma_mask: 975failed_dma_mask:
986 pci_disable_device(dev); 976 pci_disable_device(dev);
987failed_enable: 977failed_enable:
988 spin_lock(&rsxx_ida_lock); 978 ida_free(&rsxx_disk_ida, card->disk_id);
989 ida_remove(&rsxx_disk_ida, card->disk_id);
990 spin_unlock(&rsxx_ida_lock);
991failed_ida_get: 979failed_ida_get:
992 kfree(card); 980 kfree(card);
993 981
@@ -1050,6 +1038,7 @@ static void rsxx_pci_remove(struct pci_dev *dev)
1050 pci_disable_device(dev); 1038 pci_disable_device(dev);
1051 pci_release_regions(dev); 1039 pci_release_regions(dev);
1052 1040
1041 ida_free(&rsxx_disk_ida, card->disk_id);
1053 kfree(card); 1042 kfree(card);
1054} 1043}
1055 1044
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 2df11cc08a46..845b0314ce3a 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -200,6 +200,7 @@ config BT_HCIUART_RTL
200 depends on BT_HCIUART 200 depends on BT_HCIUART
201 depends on BT_HCIUART_SERDEV 201 depends on BT_HCIUART_SERDEV
202 depends on GPIOLIB 202 depends on GPIOLIB
203 depends on ACPI
203 select BT_HCIUART_3WIRE 204 select BT_HCIUART_3WIRE
204 select BT_RTL 205 select BT_RTL
205 help 206 help
diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
index ed2a5c7cb77f..4593baff2bc9 100644
--- a/drivers/bluetooth/btmtkuart.c
+++ b/drivers/bluetooth/btmtkuart.c
@@ -144,8 +144,10 @@ static int mtk_setup_fw(struct hci_dev *hdev)
144 fw_size = fw->size; 144 fw_size = fw->size;
145 145
146 /* The size of patch header is 30 bytes, should be skip */ 146 /* The size of patch header is 30 bytes, should be skip */
147 if (fw_size < 30) 147 if (fw_size < 30) {
148 return -EINVAL; 148 err = -EINVAL;
149 goto free_fw;
150 }
149 151
150 fw_size -= 30; 152 fw_size -= 30;
151 fw_ptr += 30; 153 fw_ptr += 30;
@@ -172,8 +174,8 @@ static int mtk_setup_fw(struct hci_dev *hdev)
172 fw_ptr += dlen; 174 fw_ptr += dlen;
173 } 175 }
174 176
177free_fw:
175 release_firmware(fw); 178 release_firmware(fw);
176
177 return err; 179 return err;
178} 180}
179 181
diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c
index c9bac9dc4637..e4fe954e63a9 100644
--- a/drivers/bus/ti-sysc.c
+++ b/drivers/bus/ti-sysc.c
@@ -498,32 +498,29 @@ static int sysc_check_registers(struct sysc *ddata)
498 498
499/** 499/**
500 * syc_ioremap - ioremap register space for the interconnect target module 500 * syc_ioremap - ioremap register space for the interconnect target module
501 * @ddata: deviec driver data 501 * @ddata: device driver data
502 * 502 *
503 * Note that the interconnect target module registers can be anywhere 503 * Note that the interconnect target module registers can be anywhere
504 * within the first child device address space. For example, SGX has 504 * within the interconnect target module range. For example, SGX has
505 * them at offset 0x1fc00 in the 32MB module address space. We just 505 * them at offset 0x1fc00 in the 32MB module address space. And cpsw
506 * what we need around the interconnect target module registers. 506 * has them at offset 0x1200 in the CPSW_WR child. Usually the
507 * the interconnect target module registers are at the beginning of
508 * the module range though.
507 */ 509 */
508static int sysc_ioremap(struct sysc *ddata) 510static int sysc_ioremap(struct sysc *ddata)
509{ 511{
510 u32 size = 0; 512 int size;
511
512 if (ddata->offsets[SYSC_SYSSTATUS] >= 0)
513 size = ddata->offsets[SYSC_SYSSTATUS];
514 else if (ddata->offsets[SYSC_SYSCONFIG] >= 0)
515 size = ddata->offsets[SYSC_SYSCONFIG];
516 else if (ddata->offsets[SYSC_REVISION] >= 0)
517 size = ddata->offsets[SYSC_REVISION];
518 else
519 return -EINVAL;
520 513
521 size &= 0xfff00; 514 size = max3(ddata->offsets[SYSC_REVISION],
522 size += SZ_256; 515 ddata->offsets[SYSC_SYSCONFIG],
516 ddata->offsets[SYSC_SYSSTATUS]);
517
518 if (size < 0 || (size + sizeof(u32)) > ddata->module_size)
519 return -EINVAL;
523 520
524 ddata->module_va = devm_ioremap(ddata->dev, 521 ddata->module_va = devm_ioremap(ddata->dev,
525 ddata->module_pa, 522 ddata->module_pa,
526 size); 523 size + sizeof(u32));
527 if (!ddata->module_va) 524 if (!ddata->module_va)
528 return -EIO; 525 return -EIO;
529 526
@@ -1224,10 +1221,10 @@ static int sysc_child_suspend_noirq(struct device *dev)
1224 if (!pm_runtime_status_suspended(dev)) { 1221 if (!pm_runtime_status_suspended(dev)) {
1225 error = pm_generic_runtime_suspend(dev); 1222 error = pm_generic_runtime_suspend(dev);
1226 if (error) { 1223 if (error) {
1227 dev_err(dev, "%s error at %i: %i\n", 1224 dev_warn(dev, "%s busy at %i: %i\n",
1228 __func__, __LINE__, error); 1225 __func__, __LINE__, error);
1229 1226
1230 return error; 1227 return 0;
1231 } 1228 }
1232 1229
1233 error = sysc_runtime_suspend(ddata->dev); 1230 error = sysc_runtime_suspend(ddata->dev);
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index ce277ee0a28a..40728491f37b 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -566,5 +566,5 @@ config RANDOM_TRUST_CPU
566 that CPU manufacturer (perhaps with the insistence or mandate 566 that CPU manufacturer (perhaps with the insistence or mandate
567 of a Nation State's intelligence or law enforcement agencies) 567 of a Nation State's intelligence or law enforcement agencies)
568 has not installed a hidden back door to compromise the CPU's 568 has not installed a hidden back door to compromise the CPU's
569 random number generation facilities. 569 random number generation facilities. This can also be configured
570 570 at boot with "random.trust_cpu=on/off".
diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c
index a3397664f800..97d6856c9c0f 100644
--- a/drivers/char/ipmi/ipmi_bt_sm.c
+++ b/drivers/char/ipmi/ipmi_bt_sm.c
@@ -59,8 +59,6 @@ enum bt_states {
59 BT_STATE_RESET3, 59 BT_STATE_RESET3,
60 BT_STATE_RESTART, 60 BT_STATE_RESTART,
61 BT_STATE_PRINTME, 61 BT_STATE_PRINTME,
62 BT_STATE_CAPABILITIES_BEGIN,
63 BT_STATE_CAPABILITIES_END,
64 BT_STATE_LONG_BUSY /* BT doesn't get hosed :-) */ 62 BT_STATE_LONG_BUSY /* BT doesn't get hosed :-) */
65}; 63};
66 64
@@ -86,7 +84,6 @@ struct si_sm_data {
86 int error_retries; /* end of "common" fields */ 84 int error_retries; /* end of "common" fields */
87 int nonzero_status; /* hung BMCs stay all 0 */ 85 int nonzero_status; /* hung BMCs stay all 0 */
88 enum bt_states complete; /* to divert the state machine */ 86 enum bt_states complete; /* to divert the state machine */
89 int BT_CAP_outreqs;
90 long BT_CAP_req2rsp; 87 long BT_CAP_req2rsp;
91 int BT_CAP_retries; /* Recommended retries */ 88 int BT_CAP_retries; /* Recommended retries */
92}; 89};
@@ -137,8 +134,6 @@ static char *state2txt(unsigned char state)
137 case BT_STATE_RESET3: return("RESET3"); 134 case BT_STATE_RESET3: return("RESET3");
138 case BT_STATE_RESTART: return("RESTART"); 135 case BT_STATE_RESTART: return("RESTART");
139 case BT_STATE_LONG_BUSY: return("LONG_BUSY"); 136 case BT_STATE_LONG_BUSY: return("LONG_BUSY");
140 case BT_STATE_CAPABILITIES_BEGIN: return("CAP_BEGIN");
141 case BT_STATE_CAPABILITIES_END: return("CAP_END");
142 } 137 }
143 return("BAD STATE"); 138 return("BAD STATE");
144} 139}
@@ -185,7 +180,6 @@ static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io)
185 bt->complete = BT_STATE_IDLE; /* end here */ 180 bt->complete = BT_STATE_IDLE; /* end here */
186 bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * USEC_PER_SEC; 181 bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * USEC_PER_SEC;
187 bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT; 182 bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT;
188 /* BT_CAP_outreqs == zero is a flag to read BT Capabilities */
189 return 3; /* We claim 3 bytes of space; ought to check SPMI table */ 183 return 3; /* We claim 3 bytes of space; ought to check SPMI table */
190} 184}
191 185
@@ -451,7 +445,7 @@ static enum si_sm_result error_recovery(struct si_sm_data *bt,
451 445
452static enum si_sm_result bt_event(struct si_sm_data *bt, long time) 446static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
453{ 447{
454 unsigned char status, BT_CAP[8]; 448 unsigned char status;
455 static enum bt_states last_printed = BT_STATE_PRINTME; 449 static enum bt_states last_printed = BT_STATE_PRINTME;
456 int i; 450 int i;
457 451
@@ -504,12 +498,6 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
504 if (status & BT_H_BUSY) /* clear a leftover H_BUSY */ 498 if (status & BT_H_BUSY) /* clear a leftover H_BUSY */
505 BT_CONTROL(BT_H_BUSY); 499 BT_CONTROL(BT_H_BUSY);
506 500
507 bt->timeout = bt->BT_CAP_req2rsp;
508
509 /* Read BT capabilities if it hasn't been done yet */
510 if (!bt->BT_CAP_outreqs)
511 BT_STATE_CHANGE(BT_STATE_CAPABILITIES_BEGIN,
512 SI_SM_CALL_WITHOUT_DELAY);
513 BT_SI_SM_RETURN(SI_SM_IDLE); 501 BT_SI_SM_RETURN(SI_SM_IDLE);
514 502
515 case BT_STATE_XACTION_START: 503 case BT_STATE_XACTION_START:
@@ -614,37 +602,6 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
614 BT_STATE_CHANGE(BT_STATE_XACTION_START, 602 BT_STATE_CHANGE(BT_STATE_XACTION_START,
615 SI_SM_CALL_WITH_DELAY); 603 SI_SM_CALL_WITH_DELAY);
616 604
617 /*
618 * Get BT Capabilities, using timing of upper level state machine.
619 * Set outreqs to prevent infinite loop on timeout.
620 */
621 case BT_STATE_CAPABILITIES_BEGIN:
622 bt->BT_CAP_outreqs = 1;
623 {
624 unsigned char GetBT_CAP[] = { 0x18, 0x36 };
625 bt->state = BT_STATE_IDLE;
626 bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP));
627 }
628 bt->complete = BT_STATE_CAPABILITIES_END;
629 BT_STATE_CHANGE(BT_STATE_XACTION_START,
630 SI_SM_CALL_WITH_DELAY);
631
632 case BT_STATE_CAPABILITIES_END:
633 i = bt_get_result(bt, BT_CAP, sizeof(BT_CAP));
634 bt_init_data(bt, bt->io);
635 if ((i == 8) && !BT_CAP[2]) {
636 bt->BT_CAP_outreqs = BT_CAP[3];
637 bt->BT_CAP_req2rsp = BT_CAP[6] * USEC_PER_SEC;
638 bt->BT_CAP_retries = BT_CAP[7];
639 } else
640 printk(KERN_WARNING "IPMI BT: using default values\n");
641 if (!bt->BT_CAP_outreqs)
642 bt->BT_CAP_outreqs = 1;
643 printk(KERN_WARNING "IPMI BT: req2rsp=%ld secs retries=%d\n",
644 bt->BT_CAP_req2rsp / USEC_PER_SEC, bt->BT_CAP_retries);
645 bt->timeout = bt->BT_CAP_req2rsp;
646 return SI_SM_CALL_WITHOUT_DELAY;
647
648 default: /* should never occur */ 605 default: /* should never occur */
649 return error_recovery(bt, 606 return error_recovery(bt,
650 status, 607 status,
@@ -655,6 +612,11 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
655 612
656static int bt_detect(struct si_sm_data *bt) 613static int bt_detect(struct si_sm_data *bt)
657{ 614{
615 unsigned char GetBT_CAP[] = { 0x18, 0x36 };
616 unsigned char BT_CAP[8];
617 enum si_sm_result smi_result;
618 int rv;
619
658 /* 620 /*
659 * It's impossible for the BT status and interrupt registers to be 621 * It's impossible for the BT status and interrupt registers to be
660 * all 1's, (assuming a properly functioning, self-initialized BMC) 622 * all 1's, (assuming a properly functioning, self-initialized BMC)
@@ -665,6 +627,48 @@ static int bt_detect(struct si_sm_data *bt)
665 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF)) 627 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF))
666 return 1; 628 return 1;
667 reset_flags(bt); 629 reset_flags(bt);
630
631 /*
632 * Try getting the BT capabilities here.
633 */
634 rv = bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP));
635 if (rv) {
636 dev_warn(bt->io->dev,
637 "Can't start capabilities transaction: %d\n", rv);
638 goto out_no_bt_cap;
639 }
640
641 smi_result = SI_SM_CALL_WITHOUT_DELAY;
642 for (;;) {
643 if (smi_result == SI_SM_CALL_WITH_DELAY ||
644 smi_result == SI_SM_CALL_WITH_TICK_DELAY) {
645 schedule_timeout_uninterruptible(1);
646 smi_result = bt_event(bt, jiffies_to_usecs(1));
647 } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) {
648 smi_result = bt_event(bt, 0);
649 } else
650 break;
651 }
652
653 rv = bt_get_result(bt, BT_CAP, sizeof(BT_CAP));
654 bt_init_data(bt, bt->io);
655 if (rv < 8) {
656 dev_warn(bt->io->dev, "bt cap response too short: %d\n", rv);
657 goto out_no_bt_cap;
658 }
659
660 if (BT_CAP[2]) {
661 dev_warn(bt->io->dev, "Error fetching bt cap: %x\n", BT_CAP[2]);
662out_no_bt_cap:
663 dev_warn(bt->io->dev, "using default values\n");
664 } else {
665 bt->BT_CAP_req2rsp = BT_CAP[6] * USEC_PER_SEC;
666 bt->BT_CAP_retries = BT_CAP[7];
667 }
668
669 dev_info(bt->io->dev, "req2rsp=%ld secs retries=%d\n",
670 bt->BT_CAP_req2rsp / USEC_PER_SEC, bt->BT_CAP_retries);
671
668 return 0; 672 return 0;
669} 673}
670 674
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 51832b8a2c62..7fc9612070a1 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -3381,39 +3381,45 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
3381 3381
3382 rv = handlers->start_processing(send_info, intf); 3382 rv = handlers->start_processing(send_info, intf);
3383 if (rv) 3383 if (rv)
3384 goto out; 3384 goto out_err;
3385 3385
3386 rv = __bmc_get_device_id(intf, NULL, &id, NULL, NULL, i); 3386 rv = __bmc_get_device_id(intf, NULL, &id, NULL, NULL, i);
3387 if (rv) { 3387 if (rv) {
3388 dev_err(si_dev, "Unable to get the device id: %d\n", rv); 3388 dev_err(si_dev, "Unable to get the device id: %d\n", rv);
3389 goto out; 3389 goto out_err_started;
3390 } 3390 }
3391 3391
3392 mutex_lock(&intf->bmc_reg_mutex); 3392 mutex_lock(&intf->bmc_reg_mutex);
3393 rv = __scan_channels(intf, &id); 3393 rv = __scan_channels(intf, &id);
3394 mutex_unlock(&intf->bmc_reg_mutex); 3394 mutex_unlock(&intf->bmc_reg_mutex);
3395 if (rv)
3396 goto out_err_bmc_reg;
3395 3397
3396 out: 3398 /*
3397 if (rv) { 3399 * Keep memory order straight for RCU readers. Make
3398 ipmi_bmc_unregister(intf); 3400 * sure everything else is committed to memory before
3399 list_del_rcu(&intf->link); 3401 * setting intf_num to mark the interface valid.
3400 mutex_unlock(&ipmi_interfaces_mutex); 3402 */
3401 synchronize_srcu(&ipmi_interfaces_srcu); 3403 smp_wmb();
3402 cleanup_srcu_struct(&intf->users_srcu); 3404 intf->intf_num = i;
3403 kref_put(&intf->refcount, intf_free); 3405 mutex_unlock(&ipmi_interfaces_mutex);
3404 } else {
3405 /*
3406 * Keep memory order straight for RCU readers. Make
3407 * sure everything else is committed to memory before
3408 * setting intf_num to mark the interface valid.
3409 */
3410 smp_wmb();
3411 intf->intf_num = i;
3412 mutex_unlock(&ipmi_interfaces_mutex);
3413 3406
3414 /* After this point the interface is legal to use. */ 3407 /* After this point the interface is legal to use. */
3415 call_smi_watchers(i, intf->si_dev); 3408 call_smi_watchers(i, intf->si_dev);
3416 } 3409
3410 return 0;
3411
3412 out_err_bmc_reg:
3413 ipmi_bmc_unregister(intf);
3414 out_err_started:
3415 if (intf->handlers->shutdown)
3416 intf->handlers->shutdown(intf->send_info);
3417 out_err:
3418 list_del_rcu(&intf->link);
3419 mutex_unlock(&ipmi_interfaces_mutex);
3420 synchronize_srcu(&ipmi_interfaces_srcu);
3421 cleanup_srcu_struct(&intf->users_srcu);
3422 kref_put(&intf->refcount, intf_free);
3417 3423
3418 return rv; 3424 return rv;
3419} 3425}
@@ -3504,7 +3510,8 @@ void ipmi_unregister_smi(struct ipmi_smi *intf)
3504 } 3510 }
3505 srcu_read_unlock(&intf->users_srcu, index); 3511 srcu_read_unlock(&intf->users_srcu, index);
3506 3512
3507 intf->handlers->shutdown(intf->send_info); 3513 if (intf->handlers->shutdown)
3514 intf->handlers->shutdown(intf->send_info);
3508 3515
3509 cleanup_smi_msgs(intf); 3516 cleanup_smi_msgs(intf);
3510 3517
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 90ec010bffbd..5faa917df1b6 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -2083,18 +2083,9 @@ static int try_smi_init(struct smi_info *new_smi)
2083 si_to_str[new_smi->io.si_type]); 2083 si_to_str[new_smi->io.si_type]);
2084 2084
2085 WARN_ON(new_smi->io.dev->init_name != NULL); 2085 WARN_ON(new_smi->io.dev->init_name != NULL);
2086 kfree(init_name);
2087
2088 return 0;
2089
2090out_err:
2091 if (new_smi->intf) {
2092 ipmi_unregister_smi(new_smi->intf);
2093 new_smi->intf = NULL;
2094 }
2095 2086
2087 out_err:
2096 kfree(init_name); 2088 kfree(init_name);
2097
2098 return rv; 2089 return rv;
2099} 2090}
2100 2091
@@ -2227,6 +2218,8 @@ static void shutdown_smi(void *send_info)
2227 2218
2228 kfree(smi_info->si_sm); 2219 kfree(smi_info->si_sm);
2229 smi_info->si_sm = NULL; 2220 smi_info->si_sm = NULL;
2221
2222 smi_info->intf = NULL;
2230} 2223}
2231 2224
2232/* 2225/*
@@ -2240,10 +2233,8 @@ static void cleanup_one_si(struct smi_info *smi_info)
2240 2233
2241 list_del(&smi_info->link); 2234 list_del(&smi_info->link);
2242 2235
2243 if (smi_info->intf) { 2236 if (smi_info->intf)
2244 ipmi_unregister_smi(smi_info->intf); 2237 ipmi_unregister_smi(smi_info->intf);
2245 smi_info->intf = NULL;
2246 }
2247 2238
2248 if (smi_info->pdev) { 2239 if (smi_info->pdev) {
2249 if (smi_info->pdev_registered) 2240 if (smi_info->pdev_registered)
diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 18e4650c233b..29e67a80fb20 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -181,6 +181,8 @@ struct ssif_addr_info {
181 struct device *dev; 181 struct device *dev;
182 struct i2c_client *client; 182 struct i2c_client *client;
183 183
184 struct i2c_client *added_client;
185
184 struct mutex clients_mutex; 186 struct mutex clients_mutex;
185 struct list_head clients; 187 struct list_head clients;
186 188
@@ -1214,18 +1216,11 @@ static void shutdown_ssif(void *send_info)
1214 complete(&ssif_info->wake_thread); 1216 complete(&ssif_info->wake_thread);
1215 kthread_stop(ssif_info->thread); 1217 kthread_stop(ssif_info->thread);
1216 } 1218 }
1217
1218 /*
1219 * No message can be outstanding now, we have removed the
1220 * upper layer and it permitted us to do so.
1221 */
1222 kfree(ssif_info);
1223} 1219}
1224 1220
1225static int ssif_remove(struct i2c_client *client) 1221static int ssif_remove(struct i2c_client *client)
1226{ 1222{
1227 struct ssif_info *ssif_info = i2c_get_clientdata(client); 1223 struct ssif_info *ssif_info = i2c_get_clientdata(client);
1228 struct ipmi_smi *intf;
1229 struct ssif_addr_info *addr_info; 1224 struct ssif_addr_info *addr_info;
1230 1225
1231 if (!ssif_info) 1226 if (!ssif_info)
@@ -1235,9 +1230,7 @@ static int ssif_remove(struct i2c_client *client)
1235 * After this point, we won't deliver anything asychronously 1230 * After this point, we won't deliver anything asychronously
1236 * to the message handler. We can unregister ourself. 1231 * to the message handler. We can unregister ourself.
1237 */ 1232 */
1238 intf = ssif_info->intf; 1233 ipmi_unregister_smi(ssif_info->intf);
1239 ssif_info->intf = NULL;
1240 ipmi_unregister_smi(intf);
1241 1234
1242 list_for_each_entry(addr_info, &ssif_infos, link) { 1235 list_for_each_entry(addr_info, &ssif_infos, link) {
1243 if (addr_info->client == client) { 1236 if (addr_info->client == client) {
@@ -1246,6 +1239,8 @@ static int ssif_remove(struct i2c_client *client)
1246 } 1239 }
1247 } 1240 }
1248 1241
1242 kfree(ssif_info);
1243
1249 return 0; 1244 return 0;
1250} 1245}
1251 1246
@@ -1648,15 +1643,9 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
1648 1643
1649 out: 1644 out:
1650 if (rv) { 1645 if (rv) {
1651 /* 1646 if (addr_info)
1652 * Note that if addr_info->client is assigned, we 1647 addr_info->client = NULL;
1653 * leave it. The i2c client hangs around even if we 1648
1654 * return a failure here, and the failure here is not
1655 * propagated back to the i2c code. This seems to be
1656 * design intent, strange as it may be. But if we
1657 * don't leave it, ssif_platform_remove will not remove
1658 * the client like it should.
1659 */
1660 dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv); 1649 dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv);
1661 kfree(ssif_info); 1650 kfree(ssif_info);
1662 } 1651 }
@@ -1676,7 +1665,8 @@ static int ssif_adapter_handler(struct device *adev, void *opaque)
1676 if (adev->type != &i2c_adapter_type) 1665 if (adev->type != &i2c_adapter_type)
1677 return 0; 1666 return 0;
1678 1667
1679 i2c_new_device(to_i2c_adapter(adev), &addr_info->binfo); 1668 addr_info->added_client = i2c_new_device(to_i2c_adapter(adev),
1669 &addr_info->binfo);
1680 1670
1681 if (!addr_info->adapter_name) 1671 if (!addr_info->adapter_name)
1682 return 1; /* Only try the first I2C adapter by default. */ 1672 return 1; /* Only try the first I2C adapter by default. */
@@ -1849,7 +1839,7 @@ static int ssif_platform_remove(struct platform_device *dev)
1849 return 0; 1839 return 0;
1850 1840
1851 mutex_lock(&ssif_infos_mutex); 1841 mutex_lock(&ssif_infos_mutex);
1852 i2c_unregister_device(addr_info->client); 1842 i2c_unregister_device(addr_info->added_client);
1853 1843
1854 list_del(&addr_info->link); 1844 list_del(&addr_info->link);
1855 kfree(addr_info); 1845 kfree(addr_info);
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index bb882ab161fe..e6124bd548df 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -16,6 +16,8 @@
16 16
17#include "kcs_bmc.h" 17#include "kcs_bmc.h"
18 18
19#define DEVICE_NAME "ipmi-kcs"
20
19#define KCS_MSG_BUFSIZ 1000 21#define KCS_MSG_BUFSIZ 1000
20 22
21#define KCS_ZERO_DATA 0 23#define KCS_ZERO_DATA 0
@@ -429,8 +431,6 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
429 if (!kcs_bmc) 431 if (!kcs_bmc)
430 return NULL; 432 return NULL;
431 433
432 dev_set_name(dev, "ipmi-kcs%u", channel);
433
434 spin_lock_init(&kcs_bmc->lock); 434 spin_lock_init(&kcs_bmc->lock);
435 kcs_bmc->channel = channel; 435 kcs_bmc->channel = channel;
436 436
@@ -444,7 +444,8 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
444 return NULL; 444 return NULL;
445 445
446 kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR; 446 kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR;
447 kcs_bmc->miscdev.name = dev_name(dev); 447 kcs_bmc->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s%u",
448 DEVICE_NAME, channel);
448 kcs_bmc->miscdev.fops = &kcs_bmc_fops; 449 kcs_bmc->miscdev.fops = &kcs_bmc_fops;
449 450
450 return kcs_bmc; 451 return kcs_bmc;
diff --git a/drivers/char/random.c b/drivers/char/random.c
index bf5f99fc36f1..c75b6cdf0053 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -779,6 +779,13 @@ static struct crng_state **crng_node_pool __read_mostly;
779 779
780static void invalidate_batched_entropy(void); 780static void invalidate_batched_entropy(void);
781 781
782static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
783static int __init parse_trust_cpu(char *arg)
784{
785 return kstrtobool(arg, &trust_cpu);
786}
787early_param("random.trust_cpu", parse_trust_cpu);
788
782static void crng_initialize(struct crng_state *crng) 789static void crng_initialize(struct crng_state *crng)
783{ 790{
784 int i; 791 int i;
@@ -799,12 +806,10 @@ static void crng_initialize(struct crng_state *crng)
799 } 806 }
800 crng->state[i] ^= rv; 807 crng->state[i] ^= rv;
801 } 808 }
802#ifdef CONFIG_RANDOM_TRUST_CPU 809 if (trust_cpu && arch_init) {
803 if (arch_init) {
804 crng_init = 2; 810 crng_init = 2;
805 pr_notice("random: crng done (trusting CPU's manufacturer)\n"); 811 pr_notice("random: crng done (trusting CPU's manufacturer)\n");
806 } 812 }
807#endif
808 crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1; 813 crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
809} 814}
810 815
diff --git a/drivers/clk/clk-npcm7xx.c b/drivers/clk/clk-npcm7xx.c
index 740af90a9508..c5edf8f2fd19 100644
--- a/drivers/clk/clk-npcm7xx.c
+++ b/drivers/clk/clk-npcm7xx.c
@@ -558,8 +558,8 @@ static void __init npcm7xx_clk_init(struct device_node *clk_np)
558 if (!clk_base) 558 if (!clk_base)
559 goto npcm7xx_init_error; 559 goto npcm7xx_init_error;
560 560
561 npcm7xx_clk_data = kzalloc(sizeof(*npcm7xx_clk_data->hws) * 561 npcm7xx_clk_data = kzalloc(struct_size(npcm7xx_clk_data, hws,
562 NPCM7XX_NUM_CLOCKS + sizeof(npcm7xx_clk_data), GFP_KERNEL); 562 NPCM7XX_NUM_CLOCKS), GFP_KERNEL);
563 if (!npcm7xx_clk_data) 563 if (!npcm7xx_clk_data)
564 goto npcm7xx_init_np_err; 564 goto npcm7xx_init_np_err;
565 565
diff --git a/drivers/clk/x86/clk-st.c b/drivers/clk/x86/clk-st.c
index fb62f3938008..3a0996f2d556 100644
--- a/drivers/clk/x86/clk-st.c
+++ b/drivers/clk/x86/clk-st.c
@@ -46,7 +46,7 @@ static int st_clk_probe(struct platform_device *pdev)
46 clk_oscout1_parents, ARRAY_SIZE(clk_oscout1_parents), 46 clk_oscout1_parents, ARRAY_SIZE(clk_oscout1_parents),
47 0, st_data->base + CLKDRVSTR2, OSCOUT1CLK25MHZ, 3, 0, NULL); 47 0, st_data->base + CLKDRVSTR2, OSCOUT1CLK25MHZ, 3, 0, NULL);
48 48
49 clk_set_parent(hws[ST_CLK_MUX]->clk, hws[ST_CLK_25M]->clk); 49 clk_set_parent(hws[ST_CLK_MUX]->clk, hws[ST_CLK_48M]->clk);
50 50
51 hws[ST_CLK_GATE] = clk_hw_register_gate(NULL, "oscout1", "oscout1_mux", 51 hws[ST_CLK_GATE] = clk_hw_register_gate(NULL, "oscout1", "oscout1_mux",
52 0, st_data->base + MISCCLKCNTL1, OSCCLKENB, 52 0, st_data->base + MISCCLKCNTL1, OSCCLKENB,
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 110483f0e3fb..e26a40971b26 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -379,9 +379,20 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
379 if (idx == -1) 379 if (idx == -1)
380 idx = i; /* first enabled state */ 380 idx = i; /* first enabled state */
381 if (s->target_residency > data->predicted_us) { 381 if (s->target_residency > data->predicted_us) {
382 if (!tick_nohz_tick_stopped()) 382 if (data->predicted_us < TICK_USEC)
383 break; 383 break;
384 384
385 if (!tick_nohz_tick_stopped()) {
386 /*
387 * If the state selected so far is shallow,
388 * waking up early won't hurt, so retain the
389 * tick in that case and let the governor run
390 * again in the next iteration of the loop.
391 */
392 expected_interval = drv->states[idx].target_residency;
393 break;
394 }
395
385 /* 396 /*
386 * If the state selected so far is shallow and this 397 * If the state selected so far is shallow and this
387 * state's target residency matches the time till the 398 * state's target residency matches the time till the
diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c
index 6e61cc93c2b0..d7aa7d7ff102 100644
--- a/drivers/crypto/caam/caamalg_qi.c
+++ b/drivers/crypto/caam/caamalg_qi.c
@@ -679,10 +679,8 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
679 int ret = 0; 679 int ret = 0;
680 680
681 if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { 681 if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
682 crypto_ablkcipher_set_flags(ablkcipher,
683 CRYPTO_TFM_RES_BAD_KEY_LEN);
684 dev_err(jrdev, "key size mismatch\n"); 682 dev_err(jrdev, "key size mismatch\n");
685 return -EINVAL; 683 goto badkey;
686 } 684 }
687 685
688 ctx->cdata.keylen = keylen; 686 ctx->cdata.keylen = keylen;
@@ -715,7 +713,7 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
715 return ret; 713 return ret;
716badkey: 714badkey:
717 crypto_ablkcipher_set_flags(ablkcipher, CRYPTO_TFM_RES_BAD_KEY_LEN); 715 crypto_ablkcipher_set_flags(ablkcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
718 return 0; 716 return -EINVAL;
719} 717}
720 718
721/* 719/*
diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 578ea63a3109..f26d62e5533a 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -71,8 +71,8 @@ static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc *edesc,
71 dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE); 71 dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
72 dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE); 72 dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
73 dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE); 73 dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
74 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE); 74 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
75 dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_TO_DEVICE); 75 dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_BIDIRECTIONAL);
76} 76}
77 77
78static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc, 78static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc,
@@ -90,8 +90,8 @@ static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc,
90 dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE); 90 dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE);
91 dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE); 91 dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE);
92 dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE); 92 dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
93 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE); 93 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
94 dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_TO_DEVICE); 94 dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_BIDIRECTIONAL);
95} 95}
96 96
97/* RSA Job Completion handler */ 97/* RSA Job Completion handler */
@@ -417,13 +417,13 @@ static int set_rsa_priv_f2_pdb(struct akcipher_request *req,
417 goto unmap_p; 417 goto unmap_p;
418 } 418 }
419 419
420 pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_TO_DEVICE); 420 pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_BIDIRECTIONAL);
421 if (dma_mapping_error(dev, pdb->tmp1_dma)) { 421 if (dma_mapping_error(dev, pdb->tmp1_dma)) {
422 dev_err(dev, "Unable to map RSA tmp1 memory\n"); 422 dev_err(dev, "Unable to map RSA tmp1 memory\n");
423 goto unmap_q; 423 goto unmap_q;
424 } 424 }
425 425
426 pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_TO_DEVICE); 426 pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_BIDIRECTIONAL);
427 if (dma_mapping_error(dev, pdb->tmp2_dma)) { 427 if (dma_mapping_error(dev, pdb->tmp2_dma)) {
428 dev_err(dev, "Unable to map RSA tmp2 memory\n"); 428 dev_err(dev, "Unable to map RSA tmp2 memory\n");
429 goto unmap_tmp1; 429 goto unmap_tmp1;
@@ -451,7 +451,7 @@ static int set_rsa_priv_f2_pdb(struct akcipher_request *req,
451 return 0; 451 return 0;
452 452
453unmap_tmp1: 453unmap_tmp1:
454 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE); 454 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
455unmap_q: 455unmap_q:
456 dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE); 456 dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
457unmap_p: 457unmap_p:
@@ -504,13 +504,13 @@ static int set_rsa_priv_f3_pdb(struct akcipher_request *req,
504 goto unmap_dq; 504 goto unmap_dq;
505 } 505 }
506 506
507 pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_TO_DEVICE); 507 pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_BIDIRECTIONAL);
508 if (dma_mapping_error(dev, pdb->tmp1_dma)) { 508 if (dma_mapping_error(dev, pdb->tmp1_dma)) {
509 dev_err(dev, "Unable to map RSA tmp1 memory\n"); 509 dev_err(dev, "Unable to map RSA tmp1 memory\n");
510 goto unmap_qinv; 510 goto unmap_qinv;
511 } 511 }
512 512
513 pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_TO_DEVICE); 513 pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_BIDIRECTIONAL);
514 if (dma_mapping_error(dev, pdb->tmp2_dma)) { 514 if (dma_mapping_error(dev, pdb->tmp2_dma)) {
515 dev_err(dev, "Unable to map RSA tmp2 memory\n"); 515 dev_err(dev, "Unable to map RSA tmp2 memory\n");
516 goto unmap_tmp1; 516 goto unmap_tmp1;
@@ -538,7 +538,7 @@ static int set_rsa_priv_f3_pdb(struct akcipher_request *req,
538 return 0; 538 return 0;
539 539
540unmap_tmp1: 540unmap_tmp1:
541 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_TO_DEVICE); 541 dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
542unmap_qinv: 542unmap_qinv:
543 dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE); 543 dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
544unmap_dq: 544unmap_dq:
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index f4f258075b89..acdd72016ffe 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -190,7 +190,8 @@ static void caam_jr_dequeue(unsigned long devarg)
190 BUG_ON(CIRC_CNT(head, tail + i, JOBR_DEPTH) <= 0); 190 BUG_ON(CIRC_CNT(head, tail + i, JOBR_DEPTH) <= 0);
191 191
192 /* Unmap just-run descriptor so we can post-process */ 192 /* Unmap just-run descriptor so we can post-process */
193 dma_unmap_single(dev, jrp->outring[hw_idx].desc, 193 dma_unmap_single(dev,
194 caam_dma_to_cpu(jrp->outring[hw_idx].desc),
194 jrp->entinfo[sw_idx].desc_size, 195 jrp->entinfo[sw_idx].desc_size,
195 DMA_TO_DEVICE); 196 DMA_TO_DEVICE);
196 197
diff --git a/drivers/crypto/cavium/nitrox/nitrox_dev.h b/drivers/crypto/cavium/nitrox/nitrox_dev.h
index 9a476bb6d4c7..af596455b420 100644
--- a/drivers/crypto/cavium/nitrox/nitrox_dev.h
+++ b/drivers/crypto/cavium/nitrox/nitrox_dev.h
@@ -35,6 +35,7 @@ struct nitrox_cmdq {
35 /* requests in backlog queues */ 35 /* requests in backlog queues */
36 atomic_t backlog_count; 36 atomic_t backlog_count;
37 37
38 int write_idx;
38 /* command size 32B/64B */ 39 /* command size 32B/64B */
39 u8 instr_size; 40 u8 instr_size;
40 u8 qno; 41 u8 qno;
@@ -87,7 +88,7 @@ struct nitrox_bh {
87 struct bh_data *slc; 88 struct bh_data *slc;
88}; 89};
89 90
90/* NITROX-5 driver state */ 91/* NITROX-V driver state */
91#define NITROX_UCODE_LOADED 0 92#define NITROX_UCODE_LOADED 0
92#define NITROX_READY 1 93#define NITROX_READY 1
93 94
diff --git a/drivers/crypto/cavium/nitrox/nitrox_lib.c b/drivers/crypto/cavium/nitrox/nitrox_lib.c
index ebe267379ac9..4d31df07777f 100644
--- a/drivers/crypto/cavium/nitrox/nitrox_lib.c
+++ b/drivers/crypto/cavium/nitrox/nitrox_lib.c
@@ -36,6 +36,7 @@ static int cmdq_common_init(struct nitrox_cmdq *cmdq)
36 cmdq->head = PTR_ALIGN(cmdq->head_unaligned, PKT_IN_ALIGN); 36 cmdq->head = PTR_ALIGN(cmdq->head_unaligned, PKT_IN_ALIGN);
37 cmdq->dma = PTR_ALIGN(cmdq->dma_unaligned, PKT_IN_ALIGN); 37 cmdq->dma = PTR_ALIGN(cmdq->dma_unaligned, PKT_IN_ALIGN);
38 cmdq->qsize = (qsize + PKT_IN_ALIGN); 38 cmdq->qsize = (qsize + PKT_IN_ALIGN);
39 cmdq->write_idx = 0;
39 40
40 spin_lock_init(&cmdq->response_lock); 41 spin_lock_init(&cmdq->response_lock);
41 spin_lock_init(&cmdq->cmdq_lock); 42 spin_lock_init(&cmdq->cmdq_lock);
diff --git a/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c b/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
index deaefd532aaa..4a362fc22f62 100644
--- a/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
+++ b/drivers/crypto/cavium/nitrox/nitrox_reqmgr.c
@@ -42,6 +42,16 @@
42 * Invalid flag options in AES-CCM IV. 42 * Invalid flag options in AES-CCM IV.
43 */ 43 */
44 44
45static inline int incr_index(int index, int count, int max)
46{
47 if ((index + count) >= max)
48 index = index + count - max;
49 else
50 index += count;
51
52 return index;
53}
54
45/** 55/**
46 * dma_free_sglist - unmap and free the sg lists. 56 * dma_free_sglist - unmap and free the sg lists.
47 * @ndev: N5 device 57 * @ndev: N5 device
@@ -426,30 +436,29 @@ static void post_se_instr(struct nitrox_softreq *sr,
426 struct nitrox_cmdq *cmdq) 436 struct nitrox_cmdq *cmdq)
427{ 437{
428 struct nitrox_device *ndev = sr->ndev; 438 struct nitrox_device *ndev = sr->ndev;
429 union nps_pkt_in_instr_baoff_dbell pkt_in_baoff_dbell; 439 int idx;
430 u64 offset;
431 u8 *ent; 440 u8 *ent;
432 441
433 spin_lock_bh(&cmdq->cmdq_lock); 442 spin_lock_bh(&cmdq->cmdq_lock);
434 443
435 /* get the next write offset */ 444 idx = cmdq->write_idx;
436 offset = NPS_PKT_IN_INSTR_BAOFF_DBELLX(cmdq->qno);
437 pkt_in_baoff_dbell.value = nitrox_read_csr(ndev, offset);
438 /* copy the instruction */ 445 /* copy the instruction */
439 ent = cmdq->head + pkt_in_baoff_dbell.s.aoff; 446 ent = cmdq->head + (idx * cmdq->instr_size);
440 memcpy(ent, &sr->instr, cmdq->instr_size); 447 memcpy(ent, &sr->instr, cmdq->instr_size);
441 /* flush the command queue updates */
442 dma_wmb();
443 448
444 sr->tstamp = jiffies;
445 atomic_set(&sr->status, REQ_POSTED); 449 atomic_set(&sr->status, REQ_POSTED);
446 response_list_add(sr, cmdq); 450 response_list_add(sr, cmdq);
451 sr->tstamp = jiffies;
452 /* flush the command queue updates */
453 dma_wmb();
447 454
448 /* Ring doorbell with count 1 */ 455 /* Ring doorbell with count 1 */
449 writeq(1, cmdq->dbell_csr_addr); 456 writeq(1, cmdq->dbell_csr_addr);
450 /* orders the doorbell rings */ 457 /* orders the doorbell rings */
451 mmiowb(); 458 mmiowb();
452 459
460 cmdq->write_idx = incr_index(idx, 1, ndev->qlen);
461
453 spin_unlock_bh(&cmdq->cmdq_lock); 462 spin_unlock_bh(&cmdq->cmdq_lock);
454} 463}
455 464
@@ -459,6 +468,9 @@ static int post_backlog_cmds(struct nitrox_cmdq *cmdq)
459 struct nitrox_softreq *sr, *tmp; 468 struct nitrox_softreq *sr, *tmp;
460 int ret = 0; 469 int ret = 0;
461 470
471 if (!atomic_read(&cmdq->backlog_count))
472 return 0;
473
462 spin_lock_bh(&cmdq->backlog_lock); 474 spin_lock_bh(&cmdq->backlog_lock);
463 475
464 list_for_each_entry_safe(sr, tmp, &cmdq->backlog_head, backlog) { 476 list_for_each_entry_safe(sr, tmp, &cmdq->backlog_head, backlog) {
@@ -466,7 +478,7 @@ static int post_backlog_cmds(struct nitrox_cmdq *cmdq)
466 478
467 /* submit until space available */ 479 /* submit until space available */
468 if (unlikely(cmdq_full(cmdq, ndev->qlen))) { 480 if (unlikely(cmdq_full(cmdq, ndev->qlen))) {
469 ret = -EBUSY; 481 ret = -ENOSPC;
470 break; 482 break;
471 } 483 }
472 /* delete from backlog list */ 484 /* delete from backlog list */
@@ -491,23 +503,20 @@ static int nitrox_enqueue_request(struct nitrox_softreq *sr)
491{ 503{
492 struct nitrox_cmdq *cmdq = sr->cmdq; 504 struct nitrox_cmdq *cmdq = sr->cmdq;
493 struct nitrox_device *ndev = sr->ndev; 505 struct nitrox_device *ndev = sr->ndev;
494 int ret = -EBUSY; 506
507 /* try to post backlog requests */
508 post_backlog_cmds(cmdq);
495 509
496 if (unlikely(cmdq_full(cmdq, ndev->qlen))) { 510 if (unlikely(cmdq_full(cmdq, ndev->qlen))) {
497 if (!(sr->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) 511 if (!(sr->flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
498 return -EAGAIN; 512 return -ENOSPC;
499 513 /* add to backlog list */
500 backlog_list_add(sr, cmdq); 514 backlog_list_add(sr, cmdq);
501 } else { 515 return -EBUSY;
502 ret = post_backlog_cmds(cmdq);
503 if (ret) {
504 backlog_list_add(sr, cmdq);
505 return ret;
506 }
507 post_se_instr(sr, cmdq);
508 ret = -EINPROGRESS;
509 } 516 }
510 return ret; 517 post_se_instr(sr, cmdq);
518
519 return -EINPROGRESS;
511} 520}
512 521
513/** 522/**
@@ -624,11 +633,9 @@ int nitrox_process_se_request(struct nitrox_device *ndev,
624 */ 633 */
625 sr->instr.fdata[0] = *((u64 *)&req->gph); 634 sr->instr.fdata[0] = *((u64 *)&req->gph);
626 sr->instr.fdata[1] = 0; 635 sr->instr.fdata[1] = 0;
627 /* flush the soft_req changes before posting the cmd */
628 wmb();
629 636
630 ret = nitrox_enqueue_request(sr); 637 ret = nitrox_enqueue_request(sr);
631 if (ret == -EAGAIN) 638 if (ret == -ENOSPC)
632 goto send_fail; 639 goto send_fail;
633 640
634 return ret; 641 return ret;
diff --git a/drivers/crypto/chelsio/chtls/chtls.h b/drivers/crypto/chelsio/chtls/chtls.h
index a53a0e6ba024..7725b6ee14ef 100644
--- a/drivers/crypto/chelsio/chtls/chtls.h
+++ b/drivers/crypto/chelsio/chtls/chtls.h
@@ -96,6 +96,10 @@ enum csk_flags {
96 CSK_CONN_INLINE, /* Connection on HW */ 96 CSK_CONN_INLINE, /* Connection on HW */
97}; 97};
98 98
99enum chtls_cdev_state {
100 CHTLS_CDEV_STATE_UP = 1
101};
102
99struct listen_ctx { 103struct listen_ctx {
100 struct sock *lsk; 104 struct sock *lsk;
101 struct chtls_dev *cdev; 105 struct chtls_dev *cdev;
@@ -146,6 +150,7 @@ struct chtls_dev {
146 unsigned int send_page_order; 150 unsigned int send_page_order;
147 int max_host_sndbuf; 151 int max_host_sndbuf;
148 struct key_map kmap; 152 struct key_map kmap;
153 unsigned int cdev_state;
149}; 154};
150 155
151struct chtls_hws { 156struct chtls_hws {
diff --git a/drivers/crypto/chelsio/chtls/chtls_main.c b/drivers/crypto/chelsio/chtls/chtls_main.c
index 9b07f9165658..f59b044ebd25 100644
--- a/drivers/crypto/chelsio/chtls/chtls_main.c
+++ b/drivers/crypto/chelsio/chtls/chtls_main.c
@@ -160,6 +160,7 @@ static void chtls_register_dev(struct chtls_dev *cdev)
160 tlsdev->hash = chtls_create_hash; 160 tlsdev->hash = chtls_create_hash;
161 tlsdev->unhash = chtls_destroy_hash; 161 tlsdev->unhash = chtls_destroy_hash;
162 tls_register_device(&cdev->tlsdev); 162 tls_register_device(&cdev->tlsdev);
163 cdev->cdev_state = CHTLS_CDEV_STATE_UP;
163} 164}
164 165
165static void chtls_unregister_dev(struct chtls_dev *cdev) 166static void chtls_unregister_dev(struct chtls_dev *cdev)
@@ -281,8 +282,10 @@ static void chtls_free_all_uld(void)
281 struct chtls_dev *cdev, *tmp; 282 struct chtls_dev *cdev, *tmp;
282 283
283 mutex_lock(&cdev_mutex); 284 mutex_lock(&cdev_mutex);
284 list_for_each_entry_safe(cdev, tmp, &cdev_list, list) 285 list_for_each_entry_safe(cdev, tmp, &cdev_list, list) {
285 chtls_free_uld(cdev); 286 if (cdev->cdev_state == CHTLS_CDEV_STATE_UP)
287 chtls_free_uld(cdev);
288 }
286 mutex_unlock(&cdev_mutex); 289 mutex_unlock(&cdev_mutex);
287} 290}
288 291
diff --git a/drivers/crypto/vmx/aes_cbc.c b/drivers/crypto/vmx/aes_cbc.c
index 5285ece4f33a..b71895871be3 100644
--- a/drivers/crypto/vmx/aes_cbc.c
+++ b/drivers/crypto/vmx/aes_cbc.c
@@ -107,24 +107,23 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
107 ret = crypto_skcipher_encrypt(req); 107 ret = crypto_skcipher_encrypt(req);
108 skcipher_request_zero(req); 108 skcipher_request_zero(req);
109 } else { 109 } else {
110 preempt_disable();
111 pagefault_disable();
112 enable_kernel_vsx();
113
114 blkcipher_walk_init(&walk, dst, src, nbytes); 110 blkcipher_walk_init(&walk, dst, src, nbytes);
115 ret = blkcipher_walk_virt(desc, &walk); 111 ret = blkcipher_walk_virt(desc, &walk);
116 while ((nbytes = walk.nbytes)) { 112 while ((nbytes = walk.nbytes)) {
113 preempt_disable();
114 pagefault_disable();
115 enable_kernel_vsx();
117 aes_p8_cbc_encrypt(walk.src.virt.addr, 116 aes_p8_cbc_encrypt(walk.src.virt.addr,
118 walk.dst.virt.addr, 117 walk.dst.virt.addr,
119 nbytes & AES_BLOCK_MASK, 118 nbytes & AES_BLOCK_MASK,
120 &ctx->enc_key, walk.iv, 1); 119 &ctx->enc_key, walk.iv, 1);
120 disable_kernel_vsx();
121 pagefault_enable();
122 preempt_enable();
123
121 nbytes &= AES_BLOCK_SIZE - 1; 124 nbytes &= AES_BLOCK_SIZE - 1;
122 ret = blkcipher_walk_done(desc, &walk, nbytes); 125 ret = blkcipher_walk_done(desc, &walk, nbytes);
123 } 126 }
124
125 disable_kernel_vsx();
126 pagefault_enable();
127 preempt_enable();
128 } 127 }
129 128
130 return ret; 129 return ret;
@@ -147,24 +146,23 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
147 ret = crypto_skcipher_decrypt(req); 146 ret = crypto_skcipher_decrypt(req);
148 skcipher_request_zero(req); 147 skcipher_request_zero(req);
149 } else { 148 } else {
150 preempt_disable();
151 pagefault_disable();
152 enable_kernel_vsx();
153
154 blkcipher_walk_init(&walk, dst, src, nbytes); 149 blkcipher_walk_init(&walk, dst, src, nbytes);
155 ret = blkcipher_walk_virt(desc, &walk); 150 ret = blkcipher_walk_virt(desc, &walk);
156 while ((nbytes = walk.nbytes)) { 151 while ((nbytes = walk.nbytes)) {
152 preempt_disable();
153 pagefault_disable();
154 enable_kernel_vsx();
157 aes_p8_cbc_encrypt(walk.src.virt.addr, 155 aes_p8_cbc_encrypt(walk.src.virt.addr,
158 walk.dst.virt.addr, 156 walk.dst.virt.addr,
159 nbytes & AES_BLOCK_MASK, 157 nbytes & AES_BLOCK_MASK,
160 &ctx->dec_key, walk.iv, 0); 158 &ctx->dec_key, walk.iv, 0);
159 disable_kernel_vsx();
160 pagefault_enable();
161 preempt_enable();
162
161 nbytes &= AES_BLOCK_SIZE - 1; 163 nbytes &= AES_BLOCK_SIZE - 1;
162 ret = blkcipher_walk_done(desc, &walk, nbytes); 164 ret = blkcipher_walk_done(desc, &walk, nbytes);
163 } 165 }
164
165 disable_kernel_vsx();
166 pagefault_enable();
167 preempt_enable();
168 } 166 }
169 167
170 return ret; 168 return ret;
diff --git a/drivers/crypto/vmx/aes_xts.c b/drivers/crypto/vmx/aes_xts.c
index 8bd9aff0f55f..e9954a7d4694 100644
--- a/drivers/crypto/vmx/aes_xts.c
+++ b/drivers/crypto/vmx/aes_xts.c
@@ -116,32 +116,39 @@ static int p8_aes_xts_crypt(struct blkcipher_desc *desc,
116 ret = enc? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req); 116 ret = enc? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
117 skcipher_request_zero(req); 117 skcipher_request_zero(req);
118 } else { 118 } else {
119 blkcipher_walk_init(&walk, dst, src, nbytes);
120
121 ret = blkcipher_walk_virt(desc, &walk);
122
119 preempt_disable(); 123 preempt_disable();
120 pagefault_disable(); 124 pagefault_disable();
121 enable_kernel_vsx(); 125 enable_kernel_vsx();
122 126
123 blkcipher_walk_init(&walk, dst, src, nbytes);
124
125 ret = blkcipher_walk_virt(desc, &walk);
126 iv = walk.iv; 127 iv = walk.iv;
127 memset(tweak, 0, AES_BLOCK_SIZE); 128 memset(tweak, 0, AES_BLOCK_SIZE);
128 aes_p8_encrypt(iv, tweak, &ctx->tweak_key); 129 aes_p8_encrypt(iv, tweak, &ctx->tweak_key);
129 130
131 disable_kernel_vsx();
132 pagefault_enable();
133 preempt_enable();
134
130 while ((nbytes = walk.nbytes)) { 135 while ((nbytes = walk.nbytes)) {
136 preempt_disable();
137 pagefault_disable();
138 enable_kernel_vsx();
131 if (enc) 139 if (enc)
132 aes_p8_xts_encrypt(walk.src.virt.addr, walk.dst.virt.addr, 140 aes_p8_xts_encrypt(walk.src.virt.addr, walk.dst.virt.addr,
133 nbytes & AES_BLOCK_MASK, &ctx->enc_key, NULL, tweak); 141 nbytes & AES_BLOCK_MASK, &ctx->enc_key, NULL, tweak);
134 else 142 else
135 aes_p8_xts_decrypt(walk.src.virt.addr, walk.dst.virt.addr, 143 aes_p8_xts_decrypt(walk.src.virt.addr, walk.dst.virt.addr,
136 nbytes & AES_BLOCK_MASK, &ctx->dec_key, NULL, tweak); 144 nbytes & AES_BLOCK_MASK, &ctx->dec_key, NULL, tweak);
145 disable_kernel_vsx();
146 pagefault_enable();
147 preempt_enable();
137 148
138 nbytes &= AES_BLOCK_SIZE - 1; 149 nbytes &= AES_BLOCK_SIZE - 1;
139 ret = blkcipher_walk_done(desc, &walk, nbytes); 150 ret = blkcipher_walk_done(desc, &walk, nbytes);
140 } 151 }
141
142 disable_kernel_vsx();
143 pagefault_enable();
144 preempt_enable();
145 } 152 }
146 return ret; 153 return ret;
147} 154}
diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 0a2acd7993f0..bbe4d72ca105 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -248,13 +248,12 @@ __weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
248 return -1; 248 return -1;
249} 249}
250 250
251static int __dev_dax_pte_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) 251static vm_fault_t __dev_dax_pte_fault(struct dev_dax *dev_dax,
252 struct vm_fault *vmf, pfn_t *pfn)
252{ 253{
253 struct device *dev = &dev_dax->dev; 254 struct device *dev = &dev_dax->dev;
254 struct dax_region *dax_region; 255 struct dax_region *dax_region;
255 int rc = VM_FAULT_SIGBUS;
256 phys_addr_t phys; 256 phys_addr_t phys;
257 pfn_t pfn;
258 unsigned int fault_size = PAGE_SIZE; 257 unsigned int fault_size = PAGE_SIZE;
259 258
260 if (check_vma(dev_dax, vmf->vma, __func__)) 259 if (check_vma(dev_dax, vmf->vma, __func__))
@@ -276,26 +275,19 @@ static int __dev_dax_pte_fault(struct dev_dax *dev_dax, struct vm_fault *vmf)
276 return VM_FAULT_SIGBUS; 275 return VM_FAULT_SIGBUS;
277 } 276 }
278 277
279 pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); 278 *pfn = phys_to_pfn_t(phys, dax_region->pfn_flags);
280
281 rc = vm_insert_mixed(vmf->vma, vmf->address, pfn);
282
283 if (rc == -ENOMEM)
284 return VM_FAULT_OOM;
285 if (rc < 0 && rc != -EBUSY)
286 return VM_FAULT_SIGBUS;
287 279
288 return VM_FAULT_NOPAGE; 280 return vmf_insert_mixed(vmf->vma, vmf->address, *pfn);
289} 281}
290 282
291static int __dev_dax_pmd_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) 283static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax,
284 struct vm_fault *vmf, pfn_t *pfn)
292{ 285{
293 unsigned long pmd_addr = vmf->address & PMD_MASK; 286 unsigned long pmd_addr = vmf->address & PMD_MASK;
294 struct device *dev = &dev_dax->dev; 287 struct device *dev = &dev_dax->dev;
295 struct dax_region *dax_region; 288 struct dax_region *dax_region;
296 phys_addr_t phys; 289 phys_addr_t phys;
297 pgoff_t pgoff; 290 pgoff_t pgoff;
298 pfn_t pfn;
299 unsigned int fault_size = PMD_SIZE; 291 unsigned int fault_size = PMD_SIZE;
300 292
301 if (check_vma(dev_dax, vmf->vma, __func__)) 293 if (check_vma(dev_dax, vmf->vma, __func__))
@@ -331,21 +323,21 @@ static int __dev_dax_pmd_fault(struct dev_dax *dev_dax, struct vm_fault *vmf)
331 return VM_FAULT_SIGBUS; 323 return VM_FAULT_SIGBUS;
332 } 324 }
333 325
334 pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); 326 *pfn = phys_to_pfn_t(phys, dax_region->pfn_flags);
335 327
336 return vmf_insert_pfn_pmd(vmf->vma, vmf->address, vmf->pmd, pfn, 328 return vmf_insert_pfn_pmd(vmf->vma, vmf->address, vmf->pmd, *pfn,
337 vmf->flags & FAULT_FLAG_WRITE); 329 vmf->flags & FAULT_FLAG_WRITE);
338} 330}
339 331
340#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD 332#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
341static int __dev_dax_pud_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) 333static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax,
334 struct vm_fault *vmf, pfn_t *pfn)
342{ 335{
343 unsigned long pud_addr = vmf->address & PUD_MASK; 336 unsigned long pud_addr = vmf->address & PUD_MASK;
344 struct device *dev = &dev_dax->dev; 337 struct device *dev = &dev_dax->dev;
345 struct dax_region *dax_region; 338 struct dax_region *dax_region;
346 phys_addr_t phys; 339 phys_addr_t phys;
347 pgoff_t pgoff; 340 pgoff_t pgoff;
348 pfn_t pfn;
349 unsigned int fault_size = PUD_SIZE; 341 unsigned int fault_size = PUD_SIZE;
350 342
351 343
@@ -382,23 +374,27 @@ static int __dev_dax_pud_fault(struct dev_dax *dev_dax, struct vm_fault *vmf)
382 return VM_FAULT_SIGBUS; 374 return VM_FAULT_SIGBUS;
383 } 375 }
384 376
385 pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); 377 *pfn = phys_to_pfn_t(phys, dax_region->pfn_flags);
386 378
387 return vmf_insert_pfn_pud(vmf->vma, vmf->address, vmf->pud, pfn, 379 return vmf_insert_pfn_pud(vmf->vma, vmf->address, vmf->pud, *pfn,
388 vmf->flags & FAULT_FLAG_WRITE); 380 vmf->flags & FAULT_FLAG_WRITE);
389} 381}
390#else 382#else
391static int __dev_dax_pud_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) 383static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax,
384 struct vm_fault *vmf, pfn_t *pfn)
392{ 385{
393 return VM_FAULT_FALLBACK; 386 return VM_FAULT_FALLBACK;
394} 387}
395#endif /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ 388#endif /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */
396 389
397static int dev_dax_huge_fault(struct vm_fault *vmf, 390static vm_fault_t dev_dax_huge_fault(struct vm_fault *vmf,
398 enum page_entry_size pe_size) 391 enum page_entry_size pe_size)
399{ 392{
400 int rc, id;
401 struct file *filp = vmf->vma->vm_file; 393 struct file *filp = vmf->vma->vm_file;
394 unsigned long fault_size;
395 vm_fault_t rc = VM_FAULT_SIGBUS;
396 int id;
397 pfn_t pfn;
402 struct dev_dax *dev_dax = filp->private_data; 398 struct dev_dax *dev_dax = filp->private_data;
403 399
404 dev_dbg(&dev_dax->dev, "%s: %s (%#lx - %#lx) size = %d\n", current->comm, 400 dev_dbg(&dev_dax->dev, "%s: %s (%#lx - %#lx) size = %d\n", current->comm,
@@ -408,23 +404,49 @@ static int dev_dax_huge_fault(struct vm_fault *vmf,
408 id = dax_read_lock(); 404 id = dax_read_lock();
409 switch (pe_size) { 405 switch (pe_size) {
410 case PE_SIZE_PTE: 406 case PE_SIZE_PTE:
411 rc = __dev_dax_pte_fault(dev_dax, vmf); 407 fault_size = PAGE_SIZE;
408 rc = __dev_dax_pte_fault(dev_dax, vmf, &pfn);
412 break; 409 break;
413 case PE_SIZE_PMD: 410 case PE_SIZE_PMD:
414 rc = __dev_dax_pmd_fault(dev_dax, vmf); 411 fault_size = PMD_SIZE;
412 rc = __dev_dax_pmd_fault(dev_dax, vmf, &pfn);
415 break; 413 break;
416 case PE_SIZE_PUD: 414 case PE_SIZE_PUD:
417 rc = __dev_dax_pud_fault(dev_dax, vmf); 415 fault_size = PUD_SIZE;
416 rc = __dev_dax_pud_fault(dev_dax, vmf, &pfn);
418 break; 417 break;
419 default: 418 default:
420 rc = VM_FAULT_SIGBUS; 419 rc = VM_FAULT_SIGBUS;
421 } 420 }
421
422 if (rc == VM_FAULT_NOPAGE) {
423 unsigned long i;
424 pgoff_t pgoff;
425
426 /*
427 * In the device-dax case the only possibility for a
428 * VM_FAULT_NOPAGE result is when device-dax capacity is
429 * mapped. No need to consider the zero page, or racing
430 * conflicting mappings.
431 */
432 pgoff = linear_page_index(vmf->vma, vmf->address
433 & ~(fault_size - 1));
434 for (i = 0; i < fault_size / PAGE_SIZE; i++) {
435 struct page *page;
436
437 page = pfn_to_page(pfn_t_to_pfn(pfn) + i);
438 if (page->mapping)
439 continue;
440 page->mapping = filp->f_mapping;
441 page->index = pgoff + i;
442 }
443 }
422 dax_read_unlock(id); 444 dax_read_unlock(id);
423 445
424 return rc; 446 return rc;
425} 447}
426 448
427static int dev_dax_fault(struct vm_fault *vmf) 449static vm_fault_t dev_dax_fault(struct vm_fault *vmf)
428{ 450{
429 return dev_dax_huge_fault(vmf, PE_SIZE_PTE); 451 return dev_dax_huge_fault(vmf, PE_SIZE_PTE);
430} 452}
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index fd49b24fd6af..99e2aace8078 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -105,15 +105,19 @@ static int dax_pmem_probe(struct device *dev)
105 if (rc) 105 if (rc)
106 return rc; 106 return rc;
107 107
108 rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit, 108 rc = devm_add_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
109 &dax_pmem->ref); 109 if (rc) {
110 if (rc) 110 percpu_ref_exit(&dax_pmem->ref);
111 return rc; 111 return rc;
112 }
112 113
113 dax_pmem->pgmap.ref = &dax_pmem->ref; 114 dax_pmem->pgmap.ref = &dax_pmem->ref;
114 addr = devm_memremap_pages(dev, &dax_pmem->pgmap); 115 addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
115 if (IS_ERR(addr)) 116 if (IS_ERR(addr)) {
117 devm_remove_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
118 percpu_ref_exit(&dax_pmem->ref);
116 return PTR_ERR(addr); 119 return PTR_ERR(addr);
120 }
117 121
118 rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill, 122 rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill,
119 &dax_pmem->ref); 123 &dax_pmem->ref);
diff --git a/drivers/dax/super.c b/drivers/dax/super.c
index 45276abf03aa..6e928f37d084 100644
--- a/drivers/dax/super.c
+++ b/drivers/dax/super.c
@@ -89,7 +89,6 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize)
89 struct request_queue *q; 89 struct request_queue *q;
90 pgoff_t pgoff; 90 pgoff_t pgoff;
91 int err, id; 91 int err, id;
92 void *kaddr;
93 pfn_t pfn; 92 pfn_t pfn;
94 long len; 93 long len;
95 char buf[BDEVNAME_SIZE]; 94 char buf[BDEVNAME_SIZE];
@@ -122,7 +121,7 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize)
122 } 121 }
123 122
124 id = dax_read_lock(); 123 id = dax_read_lock();
125 len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn); 124 len = dax_direct_access(dax_dev, pgoff, 1, NULL, &pfn);
126 dax_read_unlock(id); 125 dax_read_unlock(id);
127 126
128 put_dax(dax_dev); 127 put_dax(dax_dev);
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 272bed6c8ba7..f1a441ab395d 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -161,9 +161,7 @@ static void chan_dev_release(struct device *dev)
161 161
162 chan_dev = container_of(dev, typeof(*chan_dev), device); 162 chan_dev = container_of(dev, typeof(*chan_dev), device);
163 if (atomic_dec_and_test(chan_dev->idr_ref)) { 163 if (atomic_dec_and_test(chan_dev->idr_ref)) {
164 mutex_lock(&dma_list_mutex); 164 ida_free(&dma_ida, chan_dev->dev_id);
165 ida_remove(&dma_ida, chan_dev->dev_id);
166 mutex_unlock(&dma_list_mutex);
167 kfree(chan_dev->idr_ref); 165 kfree(chan_dev->idr_ref);
168 } 166 }
169 kfree(chan_dev); 167 kfree(chan_dev);
@@ -898,17 +896,12 @@ static bool device_has_all_tx_types(struct dma_device *device)
898 896
899static int get_dma_id(struct dma_device *device) 897static int get_dma_id(struct dma_device *device)
900{ 898{
901 int rc; 899 int rc = ida_alloc(&dma_ida, GFP_KERNEL);
902
903 do {
904 if (!ida_pre_get(&dma_ida, GFP_KERNEL))
905 return -ENOMEM;
906 mutex_lock(&dma_list_mutex);
907 rc = ida_get_new(&dma_ida, &device->dev_id);
908 mutex_unlock(&dma_list_mutex);
909 } while (rc == -EAGAIN);
910 900
911 return rc; 901 if (rc < 0)
902 return rc;
903 device->dev_id = rc;
904 return 0;
912} 905}
913 906
914/** 907/**
@@ -1092,9 +1085,7 @@ int dma_async_device_register(struct dma_device *device)
1092err_out: 1085err_out:
1093 /* if we never registered a channel just release the idr */ 1086 /* if we never registered a channel just release the idr */
1094 if (atomic_read(idr_ref) == 0) { 1087 if (atomic_read(idr_ref) == 0) {
1095 mutex_lock(&dma_list_mutex); 1088 ida_free(&dma_ida, device->dev_id);
1096 ida_remove(&dma_ida, device->dev_id);
1097 mutex_unlock(&dma_list_mutex);
1098 kfree(idr_ref); 1089 kfree(idr_ref);
1099 return rc; 1090 return rc;
1100 } 1091 }
diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
index 721e6c57beae..64342944d917 100644
--- a/drivers/firmware/arm_scmi/perf.c
+++ b/drivers/firmware/arm_scmi/perf.c
@@ -166,7 +166,13 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
166 le32_to_cpu(attr->sustained_freq_khz); 166 le32_to_cpu(attr->sustained_freq_khz);
167 dom_info->sustained_perf_level = 167 dom_info->sustained_perf_level =
168 le32_to_cpu(attr->sustained_perf_level); 168 le32_to_cpu(attr->sustained_perf_level);
169 dom_info->mult_factor = (dom_info->sustained_freq_khz * 1000) / 169 if (!dom_info->sustained_freq_khz ||
170 !dom_info->sustained_perf_level)
171 /* CPUFreq converts to kHz, hence default 1000 */
172 dom_info->mult_factor = 1000;
173 else
174 dom_info->mult_factor =
175 (dom_info->sustained_freq_khz * 1000) /
170 dom_info->sustained_perf_level; 176 dom_info->sustained_perf_level;
171 memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE); 177 memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
172 } 178 }
diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c
index 3530ccd17e04..da9781a2ef4a 100644
--- a/drivers/gpio/gpio-adp5588.c
+++ b/drivers/gpio/gpio-adp5588.c
@@ -41,6 +41,8 @@ struct adp5588_gpio {
41 uint8_t int_en[3]; 41 uint8_t int_en[3];
42 uint8_t irq_mask[3]; 42 uint8_t irq_mask[3];
43 uint8_t irq_stat[3]; 43 uint8_t irq_stat[3];
44 uint8_t int_input_en[3];
45 uint8_t int_lvl_cached[3];
44}; 46};
45 47
46static int adp5588_gpio_read(struct i2c_client *client, u8 reg) 48static int adp5588_gpio_read(struct i2c_client *client, u8 reg)
@@ -173,12 +175,28 @@ static void adp5588_irq_bus_sync_unlock(struct irq_data *d)
173 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d); 175 struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d);
174 int i; 176 int i;
175 177
176 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) 178 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
179 if (dev->int_input_en[i]) {
180 mutex_lock(&dev->lock);
181 dev->dir[i] &= ~dev->int_input_en[i];
182 dev->int_input_en[i] = 0;
183 adp5588_gpio_write(dev->client, GPIO_DIR1 + i,
184 dev->dir[i]);
185 mutex_unlock(&dev->lock);
186 }
187
188 if (dev->int_lvl_cached[i] != dev->int_lvl[i]) {
189 dev->int_lvl_cached[i] = dev->int_lvl[i];
190 adp5588_gpio_write(dev->client, GPIO_INT_LVL1 + i,
191 dev->int_lvl[i]);
192 }
193
177 if (dev->int_en[i] ^ dev->irq_mask[i]) { 194 if (dev->int_en[i] ^ dev->irq_mask[i]) {
178 dev->int_en[i] = dev->irq_mask[i]; 195 dev->int_en[i] = dev->irq_mask[i];
179 adp5588_gpio_write(dev->client, GPIO_INT_EN1 + i, 196 adp5588_gpio_write(dev->client, GPIO_INT_EN1 + i,
180 dev->int_en[i]); 197 dev->int_en[i]);
181 } 198 }
199 }
182 200
183 mutex_unlock(&dev->irq_lock); 201 mutex_unlock(&dev->irq_lock);
184} 202}
@@ -221,9 +239,7 @@ static int adp5588_irq_set_type(struct irq_data *d, unsigned int type)
221 else 239 else
222 return -EINVAL; 240 return -EINVAL;
223 241
224 adp5588_gpio_direction_input(&dev->gpio_chip, gpio); 242 dev->int_input_en[bank] |= bit;
225 adp5588_gpio_write(dev->client, GPIO_INT_LVL1 + bank,
226 dev->int_lvl[bank]);
227 243
228 return 0; 244 return 0;
229} 245}
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 28da700f5f52..044888fd96a1 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -728,6 +728,7 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
728out_unregister: 728out_unregister:
729 dwapb_gpio_unregister(gpio); 729 dwapb_gpio_unregister(gpio);
730 dwapb_irq_teardown(gpio); 730 dwapb_irq_teardown(gpio);
731 clk_disable_unprepare(gpio->clk);
731 732
732 return err; 733 return err;
733} 734}
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index c48ed9d89ff5..8b9d7e42c600 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -25,7 +25,6 @@
25 25
26struct acpi_gpio_event { 26struct acpi_gpio_event {
27 struct list_head node; 27 struct list_head node;
28 struct list_head initial_sync_list;
29 acpi_handle handle; 28 acpi_handle handle;
30 unsigned int pin; 29 unsigned int pin;
31 unsigned int irq; 30 unsigned int irq;
@@ -49,10 +48,19 @@ struct acpi_gpio_chip {
49 struct mutex conn_lock; 48 struct mutex conn_lock;
50 struct gpio_chip *chip; 49 struct gpio_chip *chip;
51 struct list_head events; 50 struct list_head events;
51 struct list_head deferred_req_irqs_list_entry;
52}; 52};
53 53
54static LIST_HEAD(acpi_gpio_initial_sync_list); 54/*
55static DEFINE_MUTEX(acpi_gpio_initial_sync_list_lock); 55 * For gpiochips which call acpi_gpiochip_request_interrupts() before late_init
56 * (so builtin drivers) we register the ACPI GpioInt event handlers from a
57 * late_initcall_sync handler, so that other builtin drivers can register their
58 * OpRegions before the event handlers can run. This list contains gpiochips
59 * for which the acpi_gpiochip_request_interrupts() has been deferred.
60 */
61static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);
62static LIST_HEAD(acpi_gpio_deferred_req_irqs_list);
63static bool acpi_gpio_deferred_req_irqs_done;
56 64
57static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) 65static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
58{ 66{
@@ -89,21 +97,6 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
89 return gpiochip_get_desc(chip, pin); 97 return gpiochip_get_desc(chip, pin);
90} 98}
91 99
92static void acpi_gpio_add_to_initial_sync_list(struct acpi_gpio_event *event)
93{
94 mutex_lock(&acpi_gpio_initial_sync_list_lock);
95 list_add(&event->initial_sync_list, &acpi_gpio_initial_sync_list);
96 mutex_unlock(&acpi_gpio_initial_sync_list_lock);
97}
98
99static void acpi_gpio_del_from_initial_sync_list(struct acpi_gpio_event *event)
100{
101 mutex_lock(&acpi_gpio_initial_sync_list_lock);
102 if (!list_empty(&event->initial_sync_list))
103 list_del_init(&event->initial_sync_list);
104 mutex_unlock(&acpi_gpio_initial_sync_list_lock);
105}
106
107static irqreturn_t acpi_gpio_irq_handler(int irq, void *data) 100static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
108{ 101{
109 struct acpi_gpio_event *event = data; 102 struct acpi_gpio_event *event = data;
@@ -186,7 +179,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
186 179
187 gpiod_direction_input(desc); 180 gpiod_direction_input(desc);
188 181
189 value = gpiod_get_value(desc); 182 value = gpiod_get_value_cansleep(desc);
190 183
191 ret = gpiochip_lock_as_irq(chip, pin); 184 ret = gpiochip_lock_as_irq(chip, pin);
192 if (ret) { 185 if (ret) {
@@ -229,7 +222,6 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
229 event->irq = irq; 222 event->irq = irq;
230 event->pin = pin; 223 event->pin = pin;
231 event->desc = desc; 224 event->desc = desc;
232 INIT_LIST_HEAD(&event->initial_sync_list);
233 225
234 ret = request_threaded_irq(event->irq, NULL, handler, irqflags, 226 ret = request_threaded_irq(event->irq, NULL, handler, irqflags,
235 "ACPI:Event", event); 227 "ACPI:Event", event);
@@ -251,10 +243,9 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
251 * may refer to OperationRegions from other (builtin) drivers which 243 * may refer to OperationRegions from other (builtin) drivers which
252 * may be probed after us. 244 * may be probed after us.
253 */ 245 */
254 if (handler == acpi_gpio_irq_handler && 246 if (((irqflags & IRQF_TRIGGER_RISING) && value == 1) ||
255 (((irqflags & IRQF_TRIGGER_RISING) && value == 1) || 247 ((irqflags & IRQF_TRIGGER_FALLING) && value == 0))
256 ((irqflags & IRQF_TRIGGER_FALLING) && value == 0))) 248 handler(event->irq, event);
257 acpi_gpio_add_to_initial_sync_list(event);
258 249
259 return AE_OK; 250 return AE_OK;
260 251
@@ -283,6 +274,7 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
283 struct acpi_gpio_chip *acpi_gpio; 274 struct acpi_gpio_chip *acpi_gpio;
284 acpi_handle handle; 275 acpi_handle handle;
285 acpi_status status; 276 acpi_status status;
277 bool defer;
286 278
287 if (!chip->parent || !chip->to_irq) 279 if (!chip->parent || !chip->to_irq)
288 return; 280 return;
@@ -295,6 +287,16 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
295 if (ACPI_FAILURE(status)) 287 if (ACPI_FAILURE(status))
296 return; 288 return;
297 289
290 mutex_lock(&acpi_gpio_deferred_req_irqs_lock);
291 defer = !acpi_gpio_deferred_req_irqs_done;
292 if (defer)
293 list_add(&acpi_gpio->deferred_req_irqs_list_entry,
294 &acpi_gpio_deferred_req_irqs_list);
295 mutex_unlock(&acpi_gpio_deferred_req_irqs_lock);
296
297 if (defer)
298 return;
299
298 acpi_walk_resources(handle, "_AEI", 300 acpi_walk_resources(handle, "_AEI",
299 acpi_gpiochip_request_interrupt, acpi_gpio); 301 acpi_gpiochip_request_interrupt, acpi_gpio);
300} 302}
@@ -325,11 +327,14 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
325 if (ACPI_FAILURE(status)) 327 if (ACPI_FAILURE(status))
326 return; 328 return;
327 329
330 mutex_lock(&acpi_gpio_deferred_req_irqs_lock);
331 if (!list_empty(&acpi_gpio->deferred_req_irqs_list_entry))
332 list_del_init(&acpi_gpio->deferred_req_irqs_list_entry);
333 mutex_unlock(&acpi_gpio_deferred_req_irqs_lock);
334
328 list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) { 335 list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) {
329 struct gpio_desc *desc; 336 struct gpio_desc *desc;
330 337
331 acpi_gpio_del_from_initial_sync_list(event);
332
333 if (irqd_is_wakeup_set(irq_get_irq_data(event->irq))) 338 if (irqd_is_wakeup_set(irq_get_irq_data(event->irq)))
334 disable_irq_wake(event->irq); 339 disable_irq_wake(event->irq);
335 340
@@ -1052,6 +1057,7 @@ void acpi_gpiochip_add(struct gpio_chip *chip)
1052 1057
1053 acpi_gpio->chip = chip; 1058 acpi_gpio->chip = chip;
1054 INIT_LIST_HEAD(&acpi_gpio->events); 1059 INIT_LIST_HEAD(&acpi_gpio->events);
1060 INIT_LIST_HEAD(&acpi_gpio->deferred_req_irqs_list_entry);
1055 1061
1056 status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio); 1062 status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio);
1057 if (ACPI_FAILURE(status)) { 1063 if (ACPI_FAILURE(status)) {
@@ -1198,20 +1204,28 @@ bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id)
1198 return con_id == NULL; 1204 return con_id == NULL;
1199} 1205}
1200 1206
1201/* Sync the initial state of handlers after all builtin drivers have probed */ 1207/* Run deferred acpi_gpiochip_request_interrupts() */
1202static int acpi_gpio_initial_sync(void) 1208static int acpi_gpio_handle_deferred_request_interrupts(void)
1203{ 1209{
1204 struct acpi_gpio_event *event, *ep; 1210 struct acpi_gpio_chip *acpi_gpio, *tmp;
1211
1212 mutex_lock(&acpi_gpio_deferred_req_irqs_lock);
1213 list_for_each_entry_safe(acpi_gpio, tmp,
1214 &acpi_gpio_deferred_req_irqs_list,
1215 deferred_req_irqs_list_entry) {
1216 acpi_handle handle;
1205 1217
1206 mutex_lock(&acpi_gpio_initial_sync_list_lock); 1218 handle = ACPI_HANDLE(acpi_gpio->chip->parent);
1207 list_for_each_entry_safe(event, ep, &acpi_gpio_initial_sync_list, 1219 acpi_walk_resources(handle, "_AEI",
1208 initial_sync_list) { 1220 acpi_gpiochip_request_interrupt, acpi_gpio);
1209 acpi_evaluate_object(event->handle, NULL, NULL, NULL); 1221
1210 list_del_init(&event->initial_sync_list); 1222 list_del_init(&acpi_gpio->deferred_req_irqs_list_entry);
1211 } 1223 }
1212 mutex_unlock(&acpi_gpio_initial_sync_list_lock); 1224
1225 acpi_gpio_deferred_req_irqs_done = true;
1226 mutex_unlock(&acpi_gpio_deferred_req_irqs_lock);
1213 1227
1214 return 0; 1228 return 0;
1215} 1229}
1216/* We must use _sync so that this runs after the first deferred_probe run */ 1230/* We must use _sync so that this runs after the first deferred_probe run */
1217late_initcall_sync(acpi_gpio_initial_sync); 1231late_initcall_sync(acpi_gpio_handle_deferred_request_interrupts);
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index a4f1157d6aa0..d4e7a09598fa 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -31,6 +31,7 @@ static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
31 struct of_phandle_args *gpiospec = data; 31 struct of_phandle_args *gpiospec = data;
32 32
33 return chip->gpiodev->dev.of_node == gpiospec->np && 33 return chip->gpiodev->dev.of_node == gpiospec->np &&
34 chip->of_xlate &&
34 chip->of_xlate(chip, gpiospec, NULL) >= 0; 35 chip->of_xlate(chip, gpiospec, NULL) >= 0;
35} 36}
36 37
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 502b94fb116a..b31d121a876b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -39,6 +39,7 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
39{ 39{
40 struct drm_gem_object *gobj; 40 struct drm_gem_object *gobj;
41 unsigned long size; 41 unsigned long size;
42 int r;
42 43
43 gobj = drm_gem_object_lookup(p->filp, data->handle); 44 gobj = drm_gem_object_lookup(p->filp, data->handle);
44 if (gobj == NULL) 45 if (gobj == NULL)
@@ -50,20 +51,26 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
50 p->uf_entry.tv.shared = true; 51 p->uf_entry.tv.shared = true;
51 p->uf_entry.user_pages = NULL; 52 p->uf_entry.user_pages = NULL;
52 53
53 size = amdgpu_bo_size(p->uf_entry.robj);
54 if (size != PAGE_SIZE || (data->offset + 8) > size)
55 return -EINVAL;
56
57 *offset = data->offset;
58
59 drm_gem_object_put_unlocked(gobj); 54 drm_gem_object_put_unlocked(gobj);
60 55
56 size = amdgpu_bo_size(p->uf_entry.robj);
57 if (size != PAGE_SIZE || (data->offset + 8) > size) {
58 r = -EINVAL;
59 goto error_unref;
60 }
61
61 if (amdgpu_ttm_tt_get_usermm(p->uf_entry.robj->tbo.ttm)) { 62 if (amdgpu_ttm_tt_get_usermm(p->uf_entry.robj->tbo.ttm)) {
62 amdgpu_bo_unref(&p->uf_entry.robj); 63 r = -EINVAL;
63 return -EINVAL; 64 goto error_unref;
64 } 65 }
65 66
67 *offset = data->offset;
68
66 return 0; 69 return 0;
70
71error_unref:
72 amdgpu_bo_unref(&p->uf_entry.robj);
73 return r;
67} 74}
68 75
69static int amdgpu_cs_bo_handles_chunk(struct amdgpu_cs_parser *p, 76static int amdgpu_cs_bo_handles_chunk(struct amdgpu_cs_parser *p,
@@ -1012,13 +1019,9 @@ static int amdgpu_cs_ib_fill(struct amdgpu_device *adev,
1012 if (r) 1019 if (r)
1013 return r; 1020 return r;
1014 1021
1015 if (chunk_ib->flags & AMDGPU_IB_FLAG_PREAMBLE) { 1022 if (chunk_ib->flags & AMDGPU_IB_FLAG_PREAMBLE)
1016 parser->job->preamble_status |= AMDGPU_PREAMBLE_IB_PRESENT; 1023 parser->job->preamble_status |=
1017 if (!parser->ctx->preamble_presented) { 1024 AMDGPU_PREAMBLE_IB_PRESENT;
1018 parser->job->preamble_status |= AMDGPU_PREAMBLE_IB_PRESENT_FIRST;
1019 parser->ctx->preamble_presented = true;
1020 }
1021 }
1022 1025
1023 if (parser->ring && parser->ring != ring) 1026 if (parser->ring && parser->ring != ring)
1024 return -EINVAL; 1027 return -EINVAL;
@@ -1207,26 +1210,24 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
1207 1210
1208 int r; 1211 int r;
1209 1212
1213 job = p->job;
1214 p->job = NULL;
1215
1216 r = drm_sched_job_init(&job->base, entity, p->filp);
1217 if (r)
1218 goto error_unlock;
1219
1220 /* No memory allocation is allowed while holding the mn lock */
1210 amdgpu_mn_lock(p->mn); 1221 amdgpu_mn_lock(p->mn);
1211 amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) { 1222 amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
1212 struct amdgpu_bo *bo = e->robj; 1223 struct amdgpu_bo *bo = e->robj;
1213 1224
1214 if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) { 1225 if (amdgpu_ttm_tt_userptr_needs_pages(bo->tbo.ttm)) {
1215 amdgpu_mn_unlock(p->mn); 1226 r = -ERESTARTSYS;
1216 return -ERESTARTSYS; 1227 goto error_abort;
1217 } 1228 }
1218 } 1229 }
1219 1230
1220 job = p->job;
1221 p->job = NULL;
1222
1223 r = drm_sched_job_init(&job->base, entity, p->filp);
1224 if (r) {
1225 amdgpu_job_free(job);
1226 amdgpu_mn_unlock(p->mn);
1227 return r;
1228 }
1229
1230 job->owner = p->filp; 1231 job->owner = p->filp;
1231 p->fence = dma_fence_get(&job->base.s_fence->finished); 1232 p->fence = dma_fence_get(&job->base.s_fence->finished);
1232 1233
@@ -1241,6 +1242,12 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
1241 1242
1242 amdgpu_cs_post_dependencies(p); 1243 amdgpu_cs_post_dependencies(p);
1243 1244
1245 if ((job->preamble_status & AMDGPU_PREAMBLE_IB_PRESENT) &&
1246 !p->ctx->preamble_presented) {
1247 job->preamble_status |= AMDGPU_PREAMBLE_IB_PRESENT_FIRST;
1248 p->ctx->preamble_presented = true;
1249 }
1250
1244 cs->out.handle = seq; 1251 cs->out.handle = seq;
1245 job->uf_sequence = seq; 1252 job->uf_sequence = seq;
1246 1253
@@ -1258,6 +1265,15 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
1258 amdgpu_mn_unlock(p->mn); 1265 amdgpu_mn_unlock(p->mn);
1259 1266
1260 return 0; 1267 return 0;
1268
1269error_abort:
1270 dma_fence_put(&job->base.s_fence->finished);
1271 job->base.s_fence = NULL;
1272 amdgpu_mn_unlock(p->mn);
1273
1274error_unlock:
1275 amdgpu_job_free(job);
1276 return r;
1261} 1277}
1262 1278
1263int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) 1279int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 8ab5ccbc14ac..39bf2ce548c6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2063,6 +2063,7 @@ static int amdgpu_device_ip_reinit_early_sriov(struct amdgpu_device *adev)
2063 static enum amd_ip_block_type ip_order[] = { 2063 static enum amd_ip_block_type ip_order[] = {
2064 AMD_IP_BLOCK_TYPE_GMC, 2064 AMD_IP_BLOCK_TYPE_GMC,
2065 AMD_IP_BLOCK_TYPE_COMMON, 2065 AMD_IP_BLOCK_TYPE_COMMON,
2066 AMD_IP_BLOCK_TYPE_PSP,
2066 AMD_IP_BLOCK_TYPE_IH, 2067 AMD_IP_BLOCK_TYPE_IH,
2067 }; 2068 };
2068 2069
@@ -2093,7 +2094,6 @@ static int amdgpu_device_ip_reinit_late_sriov(struct amdgpu_device *adev)
2093 2094
2094 static enum amd_ip_block_type ip_order[] = { 2095 static enum amd_ip_block_type ip_order[] = {
2095 AMD_IP_BLOCK_TYPE_SMC, 2096 AMD_IP_BLOCK_TYPE_SMC,
2096 AMD_IP_BLOCK_TYPE_PSP,
2097 AMD_IP_BLOCK_TYPE_DCE, 2097 AMD_IP_BLOCK_TYPE_DCE,
2098 AMD_IP_BLOCK_TYPE_GFX, 2098 AMD_IP_BLOCK_TYPE_GFX,
2099 AMD_IP_BLOCK_TYPE_SDMA, 2099 AMD_IP_BLOCK_TYPE_SDMA,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 5518e623fed2..51b5e977ca88 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -164,8 +164,10 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
164 return r; 164 return r;
165 } 165 }
166 166
167 need_ctx_switch = ring->current_ctx != fence_ctx;
167 if (ring->funcs->emit_pipeline_sync && job && 168 if (ring->funcs->emit_pipeline_sync && job &&
168 ((tmp = amdgpu_sync_get_fence(&job->sched_sync, NULL)) || 169 ((tmp = amdgpu_sync_get_fence(&job->sched_sync, NULL)) ||
170 (amdgpu_sriov_vf(adev) && need_ctx_switch) ||
169 amdgpu_vm_need_pipeline_sync(ring, job))) { 171 amdgpu_vm_need_pipeline_sync(ring, job))) {
170 need_pipe_sync = true; 172 need_pipe_sync = true;
171 dma_fence_put(tmp); 173 dma_fence_put(tmp);
@@ -196,7 +198,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
196 } 198 }
197 199
198 skip_preamble = ring->current_ctx == fence_ctx; 200 skip_preamble = ring->current_ctx == fence_ctx;
199 need_ctx_switch = ring->current_ctx != fence_ctx;
200 if (job && ring->funcs->emit_cntxcntl) { 201 if (job && ring->funcs->emit_cntxcntl) {
201 if (need_ctx_switch) 202 if (need_ctx_switch)
202 status |= AMDGPU_HAVE_CTX_SWITCH; 203 status |= AMDGPU_HAVE_CTX_SWITCH;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 8f98629fbe59..7b4e657a95c7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1932,14 +1932,6 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
1932 amdgpu_fence_wait_empty(ring); 1932 amdgpu_fence_wait_empty(ring);
1933 } 1933 }
1934 1934
1935 mutex_lock(&adev->pm.mutex);
1936 /* update battery/ac status */
1937 if (power_supply_is_system_supplied() > 0)
1938 adev->pm.ac_power = true;
1939 else
1940 adev->pm.ac_power = false;
1941 mutex_unlock(&adev->pm.mutex);
1942
1943 if (adev->powerplay.pp_funcs->dispatch_tasks) { 1935 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1944 if (!amdgpu_device_has_dc_support(adev)) { 1936 if (!amdgpu_device_has_dc_support(adev)) {
1945 mutex_lock(&adev->pm.mutex); 1937 mutex_lock(&adev->pm.mutex);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index ece0ac703e27..b17771dd5ce7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -172,6 +172,7 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
172 * is validated on next vm use to avoid fault. 172 * is validated on next vm use to avoid fault.
173 * */ 173 * */
174 list_move_tail(&base->vm_status, &vm->evicted); 174 list_move_tail(&base->vm_status, &vm->evicted);
175 base->moved = true;
175} 176}
176 177
177/** 178/**
@@ -369,7 +370,6 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
369 uint64_t addr; 370 uint64_t addr;
370 int r; 371 int r;
371 372
372 addr = amdgpu_bo_gpu_offset(bo);
373 entries = amdgpu_bo_size(bo) / 8; 373 entries = amdgpu_bo_size(bo) / 8;
374 374
375 if (pte_support_ats) { 375 if (pte_support_ats) {
@@ -401,6 +401,7 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
401 if (r) 401 if (r)
402 goto error; 402 goto error;
403 403
404 addr = amdgpu_bo_gpu_offset(bo);
404 if (ats_entries) { 405 if (ats_entries) {
405 uint64_t ats_value; 406 uint64_t ats_value;
406 407
@@ -2483,28 +2484,52 @@ static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size)
2483 * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size 2484 * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size
2484 * 2485 *
2485 * @adev: amdgpu_device pointer 2486 * @adev: amdgpu_device pointer
2486 * @vm_size: the default vm size if it's set auto 2487 * @min_vm_size: the minimum vm size in GB if it's set auto
2487 * @fragment_size_default: Default PTE fragment size 2488 * @fragment_size_default: Default PTE fragment size
2488 * @max_level: max VMPT level 2489 * @max_level: max VMPT level
2489 * @max_bits: max address space size in bits 2490 * @max_bits: max address space size in bits
2490 * 2491 *
2491 */ 2492 */
2492void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size, 2493void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
2493 uint32_t fragment_size_default, unsigned max_level, 2494 uint32_t fragment_size_default, unsigned max_level,
2494 unsigned max_bits) 2495 unsigned max_bits)
2495{ 2496{
2497 unsigned int max_size = 1 << (max_bits - 30);
2498 unsigned int vm_size;
2496 uint64_t tmp; 2499 uint64_t tmp;
2497 2500
2498 /* adjust vm size first */ 2501 /* adjust vm size first */
2499 if (amdgpu_vm_size != -1) { 2502 if (amdgpu_vm_size != -1) {
2500 unsigned max_size = 1 << (max_bits - 30);
2501
2502 vm_size = amdgpu_vm_size; 2503 vm_size = amdgpu_vm_size;
2503 if (vm_size > max_size) { 2504 if (vm_size > max_size) {
2504 dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n", 2505 dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n",
2505 amdgpu_vm_size, max_size); 2506 amdgpu_vm_size, max_size);
2506 vm_size = max_size; 2507 vm_size = max_size;
2507 } 2508 }
2509 } else {
2510 struct sysinfo si;
2511 unsigned int phys_ram_gb;
2512
2513 /* Optimal VM size depends on the amount of physical
2514 * RAM available. Underlying requirements and
2515 * assumptions:
2516 *
2517 * - Need to map system memory and VRAM from all GPUs
2518 * - VRAM from other GPUs not known here
2519 * - Assume VRAM <= system memory
2520 * - On GFX8 and older, VM space can be segmented for
2521 * different MTYPEs
2522 * - Need to allow room for fragmentation, guard pages etc.
2523 *
2524 * This adds up to a rough guess of system memory x3.
2525 * Round up to power of two to maximize the available
2526 * VM size with the given page table size.
2527 */
2528 si_meminfo(&si);
2529 phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit +
2530 (1 << 30) - 1) >> 30;
2531 vm_size = roundup_pow_of_two(
2532 min(max(phys_ram_gb * 3, min_vm_size), max_size));
2508 } 2533 }
2509 2534
2510 adev->vm_manager.max_pfn = (uint64_t)vm_size << 18; 2535 adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 67a15d439ac0..9fa9df0c5e7f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -321,7 +321,7 @@ struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
321void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket); 321void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
322void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, 322void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
323 struct amdgpu_bo_va *bo_va); 323 struct amdgpu_bo_va *bo_va);
324void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size, 324void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
325 uint32_t fragment_size_default, unsigned max_level, 325 uint32_t fragment_size_default, unsigned max_level,
326 unsigned max_bits); 326 unsigned max_bits);
327int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 327int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 5cd45210113f..5a9534a82d40 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -5664,6 +5664,11 @@ static int gfx_v8_0_set_powergating_state(void *handle,
5664 if (amdgpu_sriov_vf(adev)) 5664 if (amdgpu_sriov_vf(adev))
5665 return 0; 5665 return 0;
5666 5666
5667 if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
5668 AMD_PG_SUPPORT_RLC_SMU_HS |
5669 AMD_PG_SUPPORT_CP |
5670 AMD_PG_SUPPORT_GFX_DMG))
5671 adev->gfx.rlc.funcs->enter_safe_mode(adev);
5667 switch (adev->asic_type) { 5672 switch (adev->asic_type) {
5668 case CHIP_CARRIZO: 5673 case CHIP_CARRIZO:
5669 case CHIP_STONEY: 5674 case CHIP_STONEY:
@@ -5713,7 +5718,11 @@ static int gfx_v8_0_set_powergating_state(void *handle,
5713 default: 5718 default:
5714 break; 5719 break;
5715 } 5720 }
5716 5721 if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
5722 AMD_PG_SUPPORT_RLC_SMU_HS |
5723 AMD_PG_SUPPORT_CP |
5724 AMD_PG_SUPPORT_GFX_DMG))
5725 adev->gfx.rlc.funcs->exit_safe_mode(adev);
5717 return 0; 5726 return 0;
5718} 5727}
5719 5728
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index 75317f283c69..ad151fefa41f 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -632,12 +632,6 @@ static void gmc_v6_0_gart_disable(struct amdgpu_device *adev)
632 amdgpu_gart_table_vram_unpin(adev); 632 amdgpu_gart_table_vram_unpin(adev);
633} 633}
634 634
635static void gmc_v6_0_gart_fini(struct amdgpu_device *adev)
636{
637 amdgpu_gart_table_vram_free(adev);
638 amdgpu_gart_fini(adev);
639}
640
641static void gmc_v6_0_vm_decode_fault(struct amdgpu_device *adev, 635static void gmc_v6_0_vm_decode_fault(struct amdgpu_device *adev,
642 u32 status, u32 addr, u32 mc_client) 636 u32 status, u32 addr, u32 mc_client)
643{ 637{
@@ -935,8 +929,9 @@ static int gmc_v6_0_sw_fini(void *handle)
935 929
936 amdgpu_gem_force_release(adev); 930 amdgpu_gem_force_release(adev);
937 amdgpu_vm_manager_fini(adev); 931 amdgpu_vm_manager_fini(adev);
938 gmc_v6_0_gart_fini(adev); 932 amdgpu_gart_table_vram_free(adev);
939 amdgpu_bo_fini(adev); 933 amdgpu_bo_fini(adev);
934 amdgpu_gart_fini(adev);
940 release_firmware(adev->gmc.fw); 935 release_firmware(adev->gmc.fw);
941 adev->gmc.fw = NULL; 936 adev->gmc.fw = NULL;
942 937
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 36dc367c4b45..f8d8a3a73e42 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -747,19 +747,6 @@ static void gmc_v7_0_gart_disable(struct amdgpu_device *adev)
747} 747}
748 748
749/** 749/**
750 * gmc_v7_0_gart_fini - vm fini callback
751 *
752 * @adev: amdgpu_device pointer
753 *
754 * Tears down the driver GART/VM setup (CIK).
755 */
756static void gmc_v7_0_gart_fini(struct amdgpu_device *adev)
757{
758 amdgpu_gart_table_vram_free(adev);
759 amdgpu_gart_fini(adev);
760}
761
762/**
763 * gmc_v7_0_vm_decode_fault - print human readable fault info 750 * gmc_v7_0_vm_decode_fault - print human readable fault info
764 * 751 *
765 * @adev: amdgpu_device pointer 752 * @adev: amdgpu_device pointer
@@ -1095,8 +1082,9 @@ static int gmc_v7_0_sw_fini(void *handle)
1095 amdgpu_gem_force_release(adev); 1082 amdgpu_gem_force_release(adev);
1096 amdgpu_vm_manager_fini(adev); 1083 amdgpu_vm_manager_fini(adev);
1097 kfree(adev->gmc.vm_fault_info); 1084 kfree(adev->gmc.vm_fault_info);
1098 gmc_v7_0_gart_fini(adev); 1085 amdgpu_gart_table_vram_free(adev);
1099 amdgpu_bo_fini(adev); 1086 amdgpu_bo_fini(adev);
1087 amdgpu_gart_fini(adev);
1100 release_firmware(adev->gmc.fw); 1088 release_firmware(adev->gmc.fw);
1101 adev->gmc.fw = NULL; 1089 adev->gmc.fw = NULL;
1102 1090
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 70fc97b59b4f..9333109b210d 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -969,19 +969,6 @@ static void gmc_v8_0_gart_disable(struct amdgpu_device *adev)
969} 969}
970 970
971/** 971/**
972 * gmc_v8_0_gart_fini - vm fini callback
973 *
974 * @adev: amdgpu_device pointer
975 *
976 * Tears down the driver GART/VM setup (CIK).
977 */
978static void gmc_v8_0_gart_fini(struct amdgpu_device *adev)
979{
980 amdgpu_gart_table_vram_free(adev);
981 amdgpu_gart_fini(adev);
982}
983
984/**
985 * gmc_v8_0_vm_decode_fault - print human readable fault info 972 * gmc_v8_0_vm_decode_fault - print human readable fault info
986 * 973 *
987 * @adev: amdgpu_device pointer 974 * @adev: amdgpu_device pointer
@@ -1199,8 +1186,9 @@ static int gmc_v8_0_sw_fini(void *handle)
1199 amdgpu_gem_force_release(adev); 1186 amdgpu_gem_force_release(adev);
1200 amdgpu_vm_manager_fini(adev); 1187 amdgpu_vm_manager_fini(adev);
1201 kfree(adev->gmc.vm_fault_info); 1188 kfree(adev->gmc.vm_fault_info);
1202 gmc_v8_0_gart_fini(adev); 1189 amdgpu_gart_table_vram_free(adev);
1203 amdgpu_bo_fini(adev); 1190 amdgpu_bo_fini(adev);
1191 amdgpu_gart_fini(adev);
1204 release_firmware(adev->gmc.fw); 1192 release_firmware(adev->gmc.fw);
1205 adev->gmc.fw = NULL; 1193 adev->gmc.fw = NULL;
1206 1194
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 399a5db27649..72f8018fa2a8 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -942,26 +942,12 @@ static int gmc_v9_0_sw_init(void *handle)
942 return 0; 942 return 0;
943} 943}
944 944
945/**
946 * gmc_v9_0_gart_fini - vm fini callback
947 *
948 * @adev: amdgpu_device pointer
949 *
950 * Tears down the driver GART/VM setup (CIK).
951 */
952static void gmc_v9_0_gart_fini(struct amdgpu_device *adev)
953{
954 amdgpu_gart_table_vram_free(adev);
955 amdgpu_gart_fini(adev);
956}
957
958static int gmc_v9_0_sw_fini(void *handle) 945static int gmc_v9_0_sw_fini(void *handle)
959{ 946{
960 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 947 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
961 948
962 amdgpu_gem_force_release(adev); 949 amdgpu_gem_force_release(adev);
963 amdgpu_vm_manager_fini(adev); 950 amdgpu_vm_manager_fini(adev);
964 gmc_v9_0_gart_fini(adev);
965 951
966 /* 952 /*
967 * TODO: 953 * TODO:
@@ -974,7 +960,9 @@ static int gmc_v9_0_sw_fini(void *handle)
974 */ 960 */
975 amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL); 961 amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
976 962
963 amdgpu_gart_table_vram_free(adev);
977 amdgpu_bo_fini(adev); 964 amdgpu_bo_fini(adev);
965 amdgpu_gart_fini(adev);
978 966
979 return 0; 967 return 0;
980} 968}
diff --git a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
index 3f57f6463dc8..cb79a93c2eb7 100644
--- a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
@@ -65,8 +65,6 @@ static int kv_set_thermal_temperature_range(struct amdgpu_device *adev,
65 int min_temp, int max_temp); 65 int min_temp, int max_temp);
66static int kv_init_fps_limits(struct amdgpu_device *adev); 66static int kv_init_fps_limits(struct amdgpu_device *adev);
67 67
68static void kv_dpm_powergate_uvd(void *handle, bool gate);
69static void kv_dpm_powergate_vce(struct amdgpu_device *adev, bool gate);
70static void kv_dpm_powergate_samu(struct amdgpu_device *adev, bool gate); 68static void kv_dpm_powergate_samu(struct amdgpu_device *adev, bool gate);
71static void kv_dpm_powergate_acp(struct amdgpu_device *adev, bool gate); 69static void kv_dpm_powergate_acp(struct amdgpu_device *adev, bool gate);
72 70
@@ -1354,8 +1352,6 @@ static int kv_dpm_enable(struct amdgpu_device *adev)
1354 return ret; 1352 return ret;
1355 } 1353 }
1356 1354
1357 kv_update_current_ps(adev, adev->pm.dpm.boot_ps);
1358
1359 if (adev->irq.installed && 1355 if (adev->irq.installed &&
1360 amdgpu_is_internal_thermal_sensor(adev->pm.int_thermal_type)) { 1356 amdgpu_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
1361 ret = kv_set_thermal_temperature_range(adev, KV_TEMP_RANGE_MIN, KV_TEMP_RANGE_MAX); 1357 ret = kv_set_thermal_temperature_range(adev, KV_TEMP_RANGE_MIN, KV_TEMP_RANGE_MAX);
@@ -1374,6 +1370,8 @@ static int kv_dpm_enable(struct amdgpu_device *adev)
1374 1370
1375static void kv_dpm_disable(struct amdgpu_device *adev) 1371static void kv_dpm_disable(struct amdgpu_device *adev)
1376{ 1372{
1373 struct kv_power_info *pi = kv_get_pi(adev);
1374
1377 amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq, 1375 amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq,
1378 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH); 1376 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH);
1379 amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq, 1377 amdgpu_irq_put(adev, &adev->pm.dpm.thermal.irq,
@@ -1387,8 +1385,10 @@ static void kv_dpm_disable(struct amdgpu_device *adev)
1387 /* powerup blocks */ 1385 /* powerup blocks */
1388 kv_dpm_powergate_acp(adev, false); 1386 kv_dpm_powergate_acp(adev, false);
1389 kv_dpm_powergate_samu(adev, false); 1387 kv_dpm_powergate_samu(adev, false);
1390 kv_dpm_powergate_vce(adev, false); 1388 if (pi->caps_vce_pg) /* power on the VCE block */
1391 kv_dpm_powergate_uvd(adev, false); 1389 amdgpu_kv_notify_message_to_smu(adev, PPSMC_MSG_VCEPowerON);
1390 if (pi->caps_uvd_pg) /* power on the UVD block */
1391 amdgpu_kv_notify_message_to_smu(adev, PPSMC_MSG_UVDPowerON);
1392 1392
1393 kv_enable_smc_cac(adev, false); 1393 kv_enable_smc_cac(adev, false);
1394 kv_enable_didt(adev, false); 1394 kv_enable_didt(adev, false);
@@ -1551,7 +1551,6 @@ static int kv_update_vce_dpm(struct amdgpu_device *adev,
1551 int ret; 1551 int ret;
1552 1552
1553 if (amdgpu_new_state->evclk > 0 && amdgpu_current_state->evclk == 0) { 1553 if (amdgpu_new_state->evclk > 0 && amdgpu_current_state->evclk == 0) {
1554 kv_dpm_powergate_vce(adev, false);
1555 if (pi->caps_stable_p_state) 1554 if (pi->caps_stable_p_state)
1556 pi->vce_boot_level = table->count - 1; 1555 pi->vce_boot_level = table->count - 1;
1557 else 1556 else
@@ -1573,7 +1572,6 @@ static int kv_update_vce_dpm(struct amdgpu_device *adev,
1573 kv_enable_vce_dpm(adev, true); 1572 kv_enable_vce_dpm(adev, true);
1574 } else if (amdgpu_new_state->evclk == 0 && amdgpu_current_state->evclk > 0) { 1573 } else if (amdgpu_new_state->evclk == 0 && amdgpu_current_state->evclk > 0) {
1575 kv_enable_vce_dpm(adev, false); 1574 kv_enable_vce_dpm(adev, false);
1576 kv_dpm_powergate_vce(adev, true);
1577 } 1575 }
1578 1576
1579 return 0; 1577 return 0;
@@ -1702,24 +1700,32 @@ static void kv_dpm_powergate_uvd(void *handle, bool gate)
1702 } 1700 }
1703} 1701}
1704 1702
1705static void kv_dpm_powergate_vce(struct amdgpu_device *adev, bool gate) 1703static void kv_dpm_powergate_vce(void *handle, bool gate)
1706{ 1704{
1705 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1707 struct kv_power_info *pi = kv_get_pi(adev); 1706 struct kv_power_info *pi = kv_get_pi(adev);
1708 1707 int ret;
1709 if (pi->vce_power_gated == gate)
1710 return;
1711 1708
1712 pi->vce_power_gated = gate; 1709 pi->vce_power_gated = gate;
1713 1710
1714 if (!pi->caps_vce_pg) 1711 if (gate) {
1715 return; 1712 /* stop the VCE block */
1716 1713 ret = amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
1717 if (gate) 1714 AMD_PG_STATE_GATE);
1718 amdgpu_kv_notify_message_to_smu(adev, PPSMC_MSG_VCEPowerOFF); 1715 kv_enable_vce_dpm(adev, false);
1719 else 1716 if (pi->caps_vce_pg) /* power off the VCE block */
1720 amdgpu_kv_notify_message_to_smu(adev, PPSMC_MSG_VCEPowerON); 1717 amdgpu_kv_notify_message_to_smu(adev, PPSMC_MSG_VCEPowerOFF);
1718 } else {
1719 if (pi->caps_vce_pg) /* power on the VCE block */
1720 amdgpu_kv_notify_message_to_smu(adev, PPSMC_MSG_VCEPowerON);
1721 kv_enable_vce_dpm(adev, true);
1722 /* re-init the VCE block */
1723 ret = amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
1724 AMD_PG_STATE_UNGATE);
1725 }
1721} 1726}
1722 1727
1728
1723static void kv_dpm_powergate_samu(struct amdgpu_device *adev, bool gate) 1729static void kv_dpm_powergate_samu(struct amdgpu_device *adev, bool gate)
1724{ 1730{
1725 struct kv_power_info *pi = kv_get_pi(adev); 1731 struct kv_power_info *pi = kv_get_pi(adev);
@@ -3061,7 +3067,7 @@ static int kv_dpm_hw_init(void *handle)
3061 else 3067 else
3062 adev->pm.dpm_enabled = true; 3068 adev->pm.dpm_enabled = true;
3063 mutex_unlock(&adev->pm.mutex); 3069 mutex_unlock(&adev->pm.mutex);
3064 3070 amdgpu_pm_compute_clocks(adev);
3065 return ret; 3071 return ret;
3066} 3072}
3067 3073
@@ -3313,6 +3319,9 @@ static int kv_set_powergating_by_smu(void *handle,
3313 case AMD_IP_BLOCK_TYPE_UVD: 3319 case AMD_IP_BLOCK_TYPE_UVD:
3314 kv_dpm_powergate_uvd(handle, gate); 3320 kv_dpm_powergate_uvd(handle, gate);
3315 break; 3321 break;
3322 case AMD_IP_BLOCK_TYPE_VCE:
3323 kv_dpm_powergate_vce(handle, gate);
3324 break;
3316 default: 3325 default:
3317 break; 3326 break;
3318 } 3327 }
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
index e7ca4623cfb9..7c3b634d8d5f 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
@@ -70,6 +70,7 @@ static const struct soc15_reg_golden golden_settings_sdma_4[] = {
70 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_IB_CNTL, 0x800f0100, 0x00000100), 70 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_IB_CNTL, 0x800f0100, 0x00000100),
71 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000), 71 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
72 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_PAGE, 0x000003ff, 0x000003c0), 72 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_PAGE, 0x000003ff, 0x000003c0),
73 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_WATERMK, 0xfc000000, 0x00000000),
73 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CHICKEN_BITS, 0xfe931f07, 0x02831f07), 74 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CHICKEN_BITS, 0xfe931f07, 0x02831f07),
74 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CLK_CTRL, 0xffffffff, 0x3f000100), 75 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CLK_CTRL, 0xffffffff, 0x3f000100),
75 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GFX_IB_CNTL, 0x800f0100, 0x00000100), 76 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GFX_IB_CNTL, 0x800f0100, 0x00000100),
@@ -81,7 +82,8 @@ static const struct soc15_reg_golden golden_settings_sdma_4[] = {
81 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC0_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000), 82 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC0_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
82 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_IB_CNTL, 0x800f0100, 0x00000100), 83 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_IB_CNTL, 0x800f0100, 0x00000100),
83 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000), 84 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
84 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_UTCL1_PAGE, 0x000003ff, 0x000003c0) 85 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_UTCL1_PAGE, 0x000003ff, 0x000003c0),
86 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_UTCL1_WATERMK, 0xfc000000, 0x00000000)
85}; 87};
86 88
87static const struct soc15_reg_golden golden_settings_sdma_vg10[] = { 89static const struct soc15_reg_golden golden_settings_sdma_vg10[] = {
@@ -109,7 +111,8 @@ static const struct soc15_reg_golden golden_settings_sdma_4_1[] =
109 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000), 111 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
110 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_IB_CNTL, 0x800f0111, 0x00000100), 112 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_IB_CNTL, 0x800f0111, 0x00000100),
111 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000), 113 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
112 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_PAGE, 0x000003ff, 0x000003c0) 114 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_PAGE, 0x000003ff, 0x000003c0),
115 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_WATERMK, 0xfc000000, 0x00000000)
113}; 116};
114 117
115static const struct soc15_reg_golden golden_settings_sdma_4_2[] = 118static const struct soc15_reg_golden golden_settings_sdma_4_2[] =
diff --git a/drivers/gpu/drm/amd/amdgpu/si_dpm.c b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
index db327b412562..1de96995e690 100644
--- a/drivers/gpu/drm/amd/amdgpu/si_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
@@ -6887,7 +6887,6 @@ static int si_dpm_enable(struct amdgpu_device *adev)
6887 6887
6888 si_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, true); 6888 si_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
6889 si_thermal_start_thermal_controller(adev); 6889 si_thermal_start_thermal_controller(adev);
6890 ni_update_current_ps(adev, boot_ps);
6891 6890
6892 return 0; 6891 return 0;
6893} 6892}
@@ -7763,7 +7762,7 @@ static int si_dpm_hw_init(void *handle)
7763 else 7762 else
7764 adev->pm.dpm_enabled = true; 7763 adev->pm.dpm_enabled = true;
7765 mutex_unlock(&adev->pm.mutex); 7764 mutex_unlock(&adev->pm.mutex);
7766 7765 amdgpu_pm_compute_clocks(adev);
7767 return ret; 7766 return ret;
7768} 7767}
7769 7768
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c
index fbe878ae1e8c..4ba0003a9d32 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c
@@ -480,12 +480,20 @@ void pp_rv_set_display_requirement(struct pp_smu *pp,
480{ 480{
481 struct dc_context *ctx = pp->ctx; 481 struct dc_context *ctx = pp->ctx;
482 struct amdgpu_device *adev = ctx->driver_context; 482 struct amdgpu_device *adev = ctx->driver_context;
483 void *pp_handle = adev->powerplay.pp_handle;
483 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs; 484 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
485 struct pp_display_clock_request clock = {0};
484 486
485 if (!pp_funcs || !pp_funcs->display_configuration_changed) 487 if (!pp_funcs || !pp_funcs->display_clock_voltage_request)
486 return; 488 return;
487 489
488 amdgpu_dpm_display_configuration_changed(adev); 490 clock.clock_type = amd_pp_dcf_clock;
491 clock.clock_freq_in_khz = req->hard_min_dcefclk_khz;
492 pp_funcs->display_clock_voltage_request(pp_handle, &clock);
493
494 clock.clock_type = amd_pp_f_clock;
495 clock.clock_freq_in_khz = req->hard_min_fclk_khz;
496 pp_funcs->display_clock_voltage_request(pp_handle, &clock);
489} 497}
490 498
491void pp_rv_set_wm_ranges(struct pp_smu *pp, 499void pp_rv_set_wm_ranges(struct pp_smu *pp,
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 567867915d32..37eaf72ace54 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
@@ -754,8 +754,12 @@ bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
754 * fail-safe mode 754 * fail-safe mode
755 */ 755 */
756 if (dc_is_hdmi_signal(link->connector_signal) || 756 if (dc_is_hdmi_signal(link->connector_signal) ||
757 dc_is_dvi_signal(link->connector_signal)) 757 dc_is_dvi_signal(link->connector_signal)) {
758 if (prev_sink != NULL)
759 dc_sink_release(prev_sink);
760
758 return false; 761 return false;
762 }
759 default: 763 default:
760 break; 764 break;
761 } 765 }
diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 6e3f56684f4e..51ed99a37803 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -170,20 +170,22 @@ static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev,
170 unsigned int tiling_mode = 0; 170 unsigned int tiling_mode = 0;
171 unsigned int stride = 0; 171 unsigned int stride = 0;
172 172
173 switch (info->drm_format_mod << 10) { 173 switch (info->drm_format_mod) {
174 case PLANE_CTL_TILED_LINEAR: 174 case DRM_FORMAT_MOD_LINEAR:
175 tiling_mode = I915_TILING_NONE; 175 tiling_mode = I915_TILING_NONE;
176 break; 176 break;
177 case PLANE_CTL_TILED_X: 177 case I915_FORMAT_MOD_X_TILED:
178 tiling_mode = I915_TILING_X; 178 tiling_mode = I915_TILING_X;
179 stride = info->stride; 179 stride = info->stride;
180 break; 180 break;
181 case PLANE_CTL_TILED_Y: 181 case I915_FORMAT_MOD_Y_TILED:
182 case I915_FORMAT_MOD_Yf_TILED:
182 tiling_mode = I915_TILING_Y; 183 tiling_mode = I915_TILING_Y;
183 stride = info->stride; 184 stride = info->stride;
184 break; 185 break;
185 default: 186 default:
186 gvt_dbg_core("not supported tiling mode\n"); 187 gvt_dbg_core("invalid drm_format_mod %llx for tiling\n",
188 info->drm_format_mod);
187 } 189 }
188 obj->tiling_and_stride = tiling_mode | stride; 190 obj->tiling_and_stride = tiling_mode | stride;
189 } else { 191 } else {
@@ -222,9 +224,26 @@ static int vgpu_get_plane_info(struct drm_device *dev,
222 info->height = p.height; 224 info->height = p.height;
223 info->stride = p.stride; 225 info->stride = p.stride;
224 info->drm_format = p.drm_format; 226 info->drm_format = p.drm_format;
225 info->drm_format_mod = p.tiled; 227
228 switch (p.tiled) {
229 case PLANE_CTL_TILED_LINEAR:
230 info->drm_format_mod = DRM_FORMAT_MOD_LINEAR;
231 break;
232 case PLANE_CTL_TILED_X:
233 info->drm_format_mod = I915_FORMAT_MOD_X_TILED;
234 break;
235 case PLANE_CTL_TILED_Y:
236 info->drm_format_mod = I915_FORMAT_MOD_Y_TILED;
237 break;
238 case PLANE_CTL_TILED_YF:
239 info->drm_format_mod = I915_FORMAT_MOD_Yf_TILED;
240 break;
241 default:
242 gvt_vgpu_err("invalid tiling mode: %x\n", p.tiled);
243 }
244
226 info->size = (((p.stride * p.height * p.bpp) / 8) + 245 info->size = (((p.stride * p.height * p.bpp) / 8) +
227 (PAGE_SIZE - 1)) >> PAGE_SHIFT; 246 (PAGE_SIZE - 1)) >> PAGE_SHIFT;
228 } else if (plane_id == DRM_PLANE_TYPE_CURSOR) { 247 } else if (plane_id == DRM_PLANE_TYPE_CURSOR) {
229 ret = intel_vgpu_decode_cursor_plane(vgpu, &c); 248 ret = intel_vgpu_decode_cursor_plane(vgpu, &c);
230 if (ret) 249 if (ret)
diff --git a/drivers/gpu/drm/i915/gvt/fb_decoder.c b/drivers/gpu/drm/i915/gvt/fb_decoder.c
index face664be3e8..481896fb712a 100644
--- a/drivers/gpu/drm/i915/gvt/fb_decoder.c
+++ b/drivers/gpu/drm/i915/gvt/fb_decoder.c
@@ -220,8 +220,7 @@ int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu,
220 if (IS_SKYLAKE(dev_priv) 220 if (IS_SKYLAKE(dev_priv)
221 || IS_KABYLAKE(dev_priv) 221 || IS_KABYLAKE(dev_priv)
222 || IS_BROXTON(dev_priv)) { 222 || IS_BROXTON(dev_priv)) {
223 plane->tiled = (val & PLANE_CTL_TILED_MASK) >> 223 plane->tiled = val & PLANE_CTL_TILED_MASK;
224 _PLANE_CTL_TILED_SHIFT;
225 fmt = skl_format_to_drm( 224 fmt = skl_format_to_drm(
226 val & PLANE_CTL_FORMAT_MASK, 225 val & PLANE_CTL_FORMAT_MASK,
227 val & PLANE_CTL_ORDER_RGBX, 226 val & PLANE_CTL_ORDER_RGBX,
@@ -260,7 +259,7 @@ int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu,
260 return -EINVAL; 259 return -EINVAL;
261 } 260 }
262 261
263 plane->stride = intel_vgpu_get_stride(vgpu, pipe, (plane->tiled << 10), 262 plane->stride = intel_vgpu_get_stride(vgpu, pipe, plane->tiled,
264 (IS_SKYLAKE(dev_priv) 263 (IS_SKYLAKE(dev_priv)
265 || IS_KABYLAKE(dev_priv) 264 || IS_KABYLAKE(dev_priv)
266 || IS_BROXTON(dev_priv)) ? 265 || IS_BROXTON(dev_priv)) ?
diff --git a/drivers/gpu/drm/i915/gvt/fb_decoder.h b/drivers/gpu/drm/i915/gvt/fb_decoder.h
index cb055f3c81a2..60c155085029 100644
--- a/drivers/gpu/drm/i915/gvt/fb_decoder.h
+++ b/drivers/gpu/drm/i915/gvt/fb_decoder.h
@@ -101,7 +101,7 @@ struct intel_gvt;
101/* color space conversion and gamma correction are not included */ 101/* color space conversion and gamma correction are not included */
102struct intel_vgpu_primary_plane_format { 102struct intel_vgpu_primary_plane_format {
103 u8 enabled; /* plane is enabled */ 103 u8 enabled; /* plane is enabled */
104 u8 tiled; /* X-tiled */ 104 u32 tiled; /* tiling mode: linear, X-tiled, Y tiled, etc */
105 u8 bpp; /* bits per pixel */ 105 u8 bpp; /* bits per pixel */
106 u32 hw_format; /* format field in the PRI_CTL register */ 106 u32 hw_format; /* format field in the PRI_CTL register */
107 u32 drm_format; /* format in DRM definition */ 107 u32 drm_format; /* format in DRM definition */
diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c
index 7a58ca555197..72afa518edd9 100644
--- a/drivers/gpu/drm/i915/gvt/handlers.c
+++ b/drivers/gpu/drm/i915/gvt/handlers.c
@@ -1296,6 +1296,19 @@ static int power_well_ctl_mmio_write(struct intel_vgpu *vgpu,
1296 return 0; 1296 return 0;
1297} 1297}
1298 1298
1299static int gen9_dbuf_ctl_mmio_write(struct intel_vgpu *vgpu,
1300 unsigned int offset, void *p_data, unsigned int bytes)
1301{
1302 write_vreg(vgpu, offset, p_data, bytes);
1303
1304 if (vgpu_vreg(vgpu, offset) & DBUF_POWER_REQUEST)
1305 vgpu_vreg(vgpu, offset) |= DBUF_POWER_STATE;
1306 else
1307 vgpu_vreg(vgpu, offset) &= ~DBUF_POWER_STATE;
1308
1309 return 0;
1310}
1311
1299static int fpga_dbg_mmio_write(struct intel_vgpu *vgpu, 1312static int fpga_dbg_mmio_write(struct intel_vgpu *vgpu,
1300 unsigned int offset, void *p_data, unsigned int bytes) 1313 unsigned int offset, void *p_data, unsigned int bytes)
1301{ 1314{
@@ -1525,9 +1538,15 @@ static int bxt_phy_ctl_family_write(struct intel_vgpu *vgpu,
1525 u32 v = *(u32 *)p_data; 1538 u32 v = *(u32 *)p_data;
1526 u32 data = v & COMMON_RESET_DIS ? BXT_PHY_LANE_ENABLED : 0; 1539 u32 data = v & COMMON_RESET_DIS ? BXT_PHY_LANE_ENABLED : 0;
1527 1540
1528 vgpu_vreg(vgpu, _BXT_PHY_CTL_DDI_A) = data; 1541 switch (offset) {
1529 vgpu_vreg(vgpu, _BXT_PHY_CTL_DDI_B) = data; 1542 case _PHY_CTL_FAMILY_EDP:
1530 vgpu_vreg(vgpu, _BXT_PHY_CTL_DDI_C) = data; 1543 vgpu_vreg(vgpu, _BXT_PHY_CTL_DDI_A) = data;
1544 break;
1545 case _PHY_CTL_FAMILY_DDI:
1546 vgpu_vreg(vgpu, _BXT_PHY_CTL_DDI_B) = data;
1547 vgpu_vreg(vgpu, _BXT_PHY_CTL_DDI_C) = data;
1548 break;
1549 }
1531 1550
1532 vgpu_vreg(vgpu, offset) = v; 1551 vgpu_vreg(vgpu, offset) = v;
1533 1552
@@ -2812,6 +2831,8 @@ static int init_skl_mmio_info(struct intel_gvt *gvt)
2812 MMIO_DH(HSW_PWR_WELL_CTL_DRIVER(SKL_DISP_PW_MISC_IO), D_SKL_PLUS, NULL, 2831 MMIO_DH(HSW_PWR_WELL_CTL_DRIVER(SKL_DISP_PW_MISC_IO), D_SKL_PLUS, NULL,
2813 skl_power_well_ctl_write); 2832 skl_power_well_ctl_write);
2814 2833
2834 MMIO_DH(DBUF_CTL, D_SKL_PLUS, NULL, gen9_dbuf_ctl_mmio_write);
2835
2815 MMIO_D(_MMIO(0xa210), D_SKL_PLUS); 2836 MMIO_D(_MMIO(0xa210), D_SKL_PLUS);
2816 MMIO_D(GEN9_MEDIA_PG_IDLE_HYSTERESIS, D_SKL_PLUS); 2837 MMIO_D(GEN9_MEDIA_PG_IDLE_HYSTERESIS, D_SKL_PLUS);
2817 MMIO_D(GEN9_RENDER_PG_IDLE_HYSTERESIS, D_SKL_PLUS); 2838 MMIO_D(GEN9_RENDER_PG_IDLE_HYSTERESIS, D_SKL_PLUS);
@@ -2987,8 +3008,6 @@ static int init_skl_mmio_info(struct intel_gvt *gvt)
2987 NULL, gen9_trtte_write); 3008 NULL, gen9_trtte_write);
2988 MMIO_DH(_MMIO(0x4dfc), D_SKL_PLUS, NULL, gen9_trtt_chicken_write); 3009 MMIO_DH(_MMIO(0x4dfc), D_SKL_PLUS, NULL, gen9_trtt_chicken_write);
2989 3010
2990 MMIO_D(_MMIO(0x45008), D_SKL_PLUS);
2991
2992 MMIO_D(_MMIO(0x46430), D_SKL_PLUS); 3011 MMIO_D(_MMIO(0x46430), D_SKL_PLUS);
2993 3012
2994 MMIO_D(_MMIO(0x46520), D_SKL_PLUS); 3013 MMIO_D(_MMIO(0x46520), D_SKL_PLUS);
@@ -3025,7 +3044,9 @@ static int init_skl_mmio_info(struct intel_gvt *gvt)
3025 MMIO_D(_MMIO(0x44500), D_SKL_PLUS); 3044 MMIO_D(_MMIO(0x44500), D_SKL_PLUS);
3026 MMIO_DFH(GEN9_CSFE_CHICKEN1_RCS, D_SKL_PLUS, F_CMD_ACCESS, NULL, NULL); 3045 MMIO_DFH(GEN9_CSFE_CHICKEN1_RCS, D_SKL_PLUS, F_CMD_ACCESS, NULL, NULL);
3027 MMIO_DFH(GEN8_HDC_CHICKEN1, D_SKL_PLUS, F_MODE_MASK | F_CMD_ACCESS, 3046 MMIO_DFH(GEN8_HDC_CHICKEN1, D_SKL_PLUS, F_MODE_MASK | F_CMD_ACCESS,
3028 NULL, NULL); 3047 NULL, NULL);
3048 MMIO_DFH(GEN9_WM_CHICKEN3, D_SKL_PLUS, F_MODE_MASK | F_CMD_ACCESS,
3049 NULL, NULL);
3029 3050
3030 MMIO_D(_MMIO(0x4ab8), D_KBL); 3051 MMIO_D(_MMIO(0x4ab8), D_KBL);
3031 MMIO_D(_MMIO(0x2248), D_KBL | D_SKL); 3052 MMIO_D(_MMIO(0x2248), D_KBL | D_SKL);
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index a45f46d8537f..c7afee37b2b8 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -32,6 +32,7 @@
32#include <linux/device.h> 32#include <linux/device.h>
33#include <linux/mm.h> 33#include <linux/mm.h>
34#include <linux/mmu_context.h> 34#include <linux/mmu_context.h>
35#include <linux/sched/mm.h>
35#include <linux/types.h> 36#include <linux/types.h>
36#include <linux/list.h> 37#include <linux/list.h>
37#include <linux/rbtree.h> 38#include <linux/rbtree.h>
@@ -1792,16 +1793,21 @@ static int kvmgt_rw_gpa(unsigned long handle, unsigned long gpa,
1792 info = (struct kvmgt_guest_info *)handle; 1793 info = (struct kvmgt_guest_info *)handle;
1793 kvm = info->kvm; 1794 kvm = info->kvm;
1794 1795
1795 if (kthread) 1796 if (kthread) {
1797 if (!mmget_not_zero(kvm->mm))
1798 return -EFAULT;
1796 use_mm(kvm->mm); 1799 use_mm(kvm->mm);
1800 }
1797 1801
1798 idx = srcu_read_lock(&kvm->srcu); 1802 idx = srcu_read_lock(&kvm->srcu);
1799 ret = write ? kvm_write_guest(kvm, gpa, buf, len) : 1803 ret = write ? kvm_write_guest(kvm, gpa, buf, len) :
1800 kvm_read_guest(kvm, gpa, buf, len); 1804 kvm_read_guest(kvm, gpa, buf, len);
1801 srcu_read_unlock(&kvm->srcu, idx); 1805 srcu_read_unlock(&kvm->srcu, idx);
1802 1806
1803 if (kthread) 1807 if (kthread) {
1804 unuse_mm(kvm->mm); 1808 unuse_mm(kvm->mm);
1809 mmput(kvm->mm);
1810 }
1805 1811
1806 return ret; 1812 return ret;
1807} 1813}
diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.c b/drivers/gpu/drm/i915/gvt/mmio_context.c
index 42e1e6bdcc2c..e872f4847fbe 100644
--- a/drivers/gpu/drm/i915/gvt/mmio_context.c
+++ b/drivers/gpu/drm/i915/gvt/mmio_context.c
@@ -562,11 +562,9 @@ void intel_gvt_switch_mmio(struct intel_vgpu *pre,
562 * performace for batch mmio read/write, so we need 562 * performace for batch mmio read/write, so we need
563 * handle forcewake mannually. 563 * handle forcewake mannually.
564 */ 564 */
565 intel_runtime_pm_get(dev_priv);
566 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); 565 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
567 switch_mmio(pre, next, ring_id); 566 switch_mmio(pre, next, ring_id);
568 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); 567 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
569 intel_runtime_pm_put(dev_priv);
570} 568}
571 569
572/** 570/**
diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
index fa75a2eead90..b0d3a43ccd03 100644
--- a/drivers/gpu/drm/i915/gvt/opregion.c
+++ b/drivers/gpu/drm/i915/gvt/opregion.c
@@ -42,8 +42,6 @@
42#define DEVICE_TYPE_EFP3 0x20 42#define DEVICE_TYPE_EFP3 0x20
43#define DEVICE_TYPE_EFP4 0x10 43#define DEVICE_TYPE_EFP4 0x10
44 44
45#define DEV_SIZE 38
46
47struct opregion_header { 45struct opregion_header {
48 u8 signature[16]; 46 u8 signature[16];
49 u32 size; 47 u32 size;
@@ -63,6 +61,10 @@ struct bdb_data_header {
63 u16 size; /* data size */ 61 u16 size; /* data size */
64} __packed; 62} __packed;
65 63
64/* For supporting windows guest with opregion, here hardcode the emulated
65 * bdb header version as '186', and the corresponding child_device_config
66 * length should be '33' but not '38'.
67 */
66struct efp_child_device_config { 68struct efp_child_device_config {
67 u16 handle; 69 u16 handle;
68 u16 device_type; 70 u16 device_type;
@@ -109,12 +111,6 @@ struct efp_child_device_config {
109 u8 mipi_bridge_type; /* 171 */ 111 u8 mipi_bridge_type; /* 171 */
110 u16 device_class_ext; 112 u16 device_class_ext;
111 u8 dvo_function; 113 u8 dvo_function;
112 u8 dp_usb_type_c:1; /* 195 */
113 u8 skip6:7;
114 u8 dp_usb_type_c_2x_gpio_index; /* 195 */
115 u16 dp_usb_type_c_2x_gpio_pin; /* 195 */
116 u8 iboost_dp:4; /* 196 */
117 u8 iboost_hdmi:4; /* 196 */
118} __packed; 114} __packed;
119 115
120struct vbt { 116struct vbt {
@@ -155,7 +151,7 @@ static void virt_vbt_generation(struct vbt *v)
155 v->header.bdb_offset = offsetof(struct vbt, bdb_header); 151 v->header.bdb_offset = offsetof(struct vbt, bdb_header);
156 152
157 strcpy(&v->bdb_header.signature[0], "BIOS_DATA_BLOCK"); 153 strcpy(&v->bdb_header.signature[0], "BIOS_DATA_BLOCK");
158 v->bdb_header.version = 186; /* child_dev_size = 38 */ 154 v->bdb_header.version = 186; /* child_dev_size = 33 */
159 v->bdb_header.header_size = sizeof(v->bdb_header); 155 v->bdb_header.header_size = sizeof(v->bdb_header);
160 156
161 v->bdb_header.bdb_size = sizeof(struct vbt) - sizeof(struct vbt_header) 157 v->bdb_header.bdb_size = sizeof(struct vbt) - sizeof(struct vbt_header)
@@ -169,11 +165,13 @@ static void virt_vbt_generation(struct vbt *v)
169 165
170 /* child device */ 166 /* child device */
171 num_child = 4; /* each port has one child */ 167 num_child = 4; /* each port has one child */
168 v->general_definitions.child_dev_size =
169 sizeof(struct efp_child_device_config);
172 v->general_definitions_header.id = BDB_GENERAL_DEFINITIONS; 170 v->general_definitions_header.id = BDB_GENERAL_DEFINITIONS;
173 /* size will include child devices */ 171 /* size will include child devices */
174 v->general_definitions_header.size = 172 v->general_definitions_header.size =
175 sizeof(struct bdb_general_definitions) + num_child * DEV_SIZE; 173 sizeof(struct bdb_general_definitions) +
176 v->general_definitions.child_dev_size = DEV_SIZE; 174 num_child * v->general_definitions.child_dev_size;
177 175
178 /* portA */ 176 /* portA */
179 v->child0.handle = DEVICE_TYPE_EFP1; 177 v->child0.handle = DEVICE_TYPE_EFP1;
diff --git a/drivers/gpu/drm/i915/gvt/sched_policy.c b/drivers/gpu/drm/i915/gvt/sched_policy.c
index 09d7bb72b4ff..c32e7d5e8629 100644
--- a/drivers/gpu/drm/i915/gvt/sched_policy.c
+++ b/drivers/gpu/drm/i915/gvt/sched_policy.c
@@ -47,11 +47,15 @@ static bool vgpu_has_pending_workload(struct intel_vgpu *vgpu)
47 return false; 47 return false;
48} 48}
49 49
50/* We give 2 seconds higher prio for vGPU during start */
51#define GVT_SCHED_VGPU_PRI_TIME 2
52
50struct vgpu_sched_data { 53struct vgpu_sched_data {
51 struct list_head lru_list; 54 struct list_head lru_list;
52 struct intel_vgpu *vgpu; 55 struct intel_vgpu *vgpu;
53 bool active; 56 bool active;
54 57 bool pri_sched;
58 ktime_t pri_time;
55 ktime_t sched_in_time; 59 ktime_t sched_in_time;
56 ktime_t sched_time; 60 ktime_t sched_time;
57 ktime_t left_ts; 61 ktime_t left_ts;
@@ -183,6 +187,14 @@ static struct intel_vgpu *find_busy_vgpu(struct gvt_sched_data *sched_data)
183 if (!vgpu_has_pending_workload(vgpu_data->vgpu)) 187 if (!vgpu_has_pending_workload(vgpu_data->vgpu))
184 continue; 188 continue;
185 189
190 if (vgpu_data->pri_sched) {
191 if (ktime_before(ktime_get(), vgpu_data->pri_time)) {
192 vgpu = vgpu_data->vgpu;
193 break;
194 } else
195 vgpu_data->pri_sched = false;
196 }
197
186 /* Return the vGPU only if it has time slice left */ 198 /* Return the vGPU only if it has time slice left */
187 if (vgpu_data->left_ts > 0) { 199 if (vgpu_data->left_ts > 0) {
188 vgpu = vgpu_data->vgpu; 200 vgpu = vgpu_data->vgpu;
@@ -202,6 +214,7 @@ static void tbs_sched_func(struct gvt_sched_data *sched_data)
202 struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; 214 struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler;
203 struct vgpu_sched_data *vgpu_data; 215 struct vgpu_sched_data *vgpu_data;
204 struct intel_vgpu *vgpu = NULL; 216 struct intel_vgpu *vgpu = NULL;
217
205 /* no active vgpu or has already had a target */ 218 /* no active vgpu or has already had a target */
206 if (list_empty(&sched_data->lru_runq_head) || scheduler->next_vgpu) 219 if (list_empty(&sched_data->lru_runq_head) || scheduler->next_vgpu)
207 goto out; 220 goto out;
@@ -209,12 +222,13 @@ static void tbs_sched_func(struct gvt_sched_data *sched_data)
209 vgpu = find_busy_vgpu(sched_data); 222 vgpu = find_busy_vgpu(sched_data);
210 if (vgpu) { 223 if (vgpu) {
211 scheduler->next_vgpu = vgpu; 224 scheduler->next_vgpu = vgpu;
212
213 /* Move the last used vGPU to the tail of lru_list */
214 vgpu_data = vgpu->sched_data; 225 vgpu_data = vgpu->sched_data;
215 list_del_init(&vgpu_data->lru_list); 226 if (!vgpu_data->pri_sched) {
216 list_add_tail(&vgpu_data->lru_list, 227 /* Move the last used vGPU to the tail of lru_list */
217 &sched_data->lru_runq_head); 228 list_del_init(&vgpu_data->lru_list);
229 list_add_tail(&vgpu_data->lru_list,
230 &sched_data->lru_runq_head);
231 }
218 } else { 232 } else {
219 scheduler->next_vgpu = gvt->idle_vgpu; 233 scheduler->next_vgpu = gvt->idle_vgpu;
220 } 234 }
@@ -328,11 +342,17 @@ static void tbs_sched_start_schedule(struct intel_vgpu *vgpu)
328{ 342{
329 struct gvt_sched_data *sched_data = vgpu->gvt->scheduler.sched_data; 343 struct gvt_sched_data *sched_data = vgpu->gvt->scheduler.sched_data;
330 struct vgpu_sched_data *vgpu_data = vgpu->sched_data; 344 struct vgpu_sched_data *vgpu_data = vgpu->sched_data;
345 ktime_t now;
331 346
332 if (!list_empty(&vgpu_data->lru_list)) 347 if (!list_empty(&vgpu_data->lru_list))
333 return; 348 return;
334 349
335 list_add_tail(&vgpu_data->lru_list, &sched_data->lru_runq_head); 350 now = ktime_get();
351 vgpu_data->pri_time = ktime_add(now,
352 ktime_set(GVT_SCHED_VGPU_PRI_TIME, 0));
353 vgpu_data->pri_sched = true;
354
355 list_add(&vgpu_data->lru_list, &sched_data->lru_runq_head);
336 356
337 if (!hrtimer_active(&sched_data->timer)) 357 if (!hrtimer_active(&sched_data->timer))
338 hrtimer_start(&sched_data->timer, ktime_add_ns(ktime_get(), 358 hrtimer_start(&sched_data->timer, ktime_add_ns(ktime_get(),
@@ -426,6 +446,7 @@ void intel_vgpu_stop_schedule(struct intel_vgpu *vgpu)
426 &vgpu->gvt->scheduler; 446 &vgpu->gvt->scheduler;
427 int ring_id; 447 int ring_id;
428 struct vgpu_sched_data *vgpu_data = vgpu->sched_data; 448 struct vgpu_sched_data *vgpu_data = vgpu->sched_data;
449 struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv;
429 450
430 if (!vgpu_data->active) 451 if (!vgpu_data->active)
431 return; 452 return;
@@ -444,6 +465,7 @@ void intel_vgpu_stop_schedule(struct intel_vgpu *vgpu)
444 scheduler->current_vgpu = NULL; 465 scheduler->current_vgpu = NULL;
445 } 466 }
446 467
468 intel_runtime_pm_get(dev_priv);
447 spin_lock_bh(&scheduler->mmio_context_lock); 469 spin_lock_bh(&scheduler->mmio_context_lock);
448 for (ring_id = 0; ring_id < I915_NUM_ENGINES; ring_id++) { 470 for (ring_id = 0; ring_id < I915_NUM_ENGINES; ring_id++) {
449 if (scheduler->engine_owner[ring_id] == vgpu) { 471 if (scheduler->engine_owner[ring_id] == vgpu) {
@@ -452,5 +474,6 @@ void intel_vgpu_stop_schedule(struct intel_vgpu *vgpu)
452 } 474 }
453 } 475 }
454 spin_unlock_bh(&scheduler->mmio_context_lock); 476 spin_unlock_bh(&scheduler->mmio_context_lock);
477 intel_runtime_pm_put(dev_priv);
455 mutex_unlock(&vgpu->gvt->sched_lock); 478 mutex_unlock(&vgpu->gvt->sched_lock);
456} 479}
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 08ec7446282e..9e63cd47b60f 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -10422,7 +10422,7 @@ enum skl_power_gate {
10422 _ICL_DSC0_PICTURE_PARAMETER_SET_4_PB, \ 10422 _ICL_DSC0_PICTURE_PARAMETER_SET_4_PB, \
10423 _ICL_DSC0_PICTURE_PARAMETER_SET_4_PC) 10423 _ICL_DSC0_PICTURE_PARAMETER_SET_4_PC)
10424#define ICL_DSC1_PICTURE_PARAMETER_SET_4(pipe) _MMIO_PIPE((pipe) - PIPE_B, \ 10424#define ICL_DSC1_PICTURE_PARAMETER_SET_4(pipe) _MMIO_PIPE((pipe) - PIPE_B, \
10425 _ICL_DSC0_PICTURE_PARAMETER_SET_4_PB, \ 10425 _ICL_DSC1_PICTURE_PARAMETER_SET_4_PB, \
10426 _ICL_DSC1_PICTURE_PARAMETER_SET_4_PC) 10426 _ICL_DSC1_PICTURE_PARAMETER_SET_4_PC)
10427#define DSC_INITIAL_DEC_DELAY(dec_delay) ((dec_delay) << 16) 10427#define DSC_INITIAL_DEC_DELAY(dec_delay) ((dec_delay) << 16)
10428#define DSC_INITIAL_XMIT_DELAY(xmit_delay) ((xmit_delay) << 0) 10428#define DSC_INITIAL_XMIT_DELAY(xmit_delay) ((xmit_delay) << 0)
@@ -10437,7 +10437,7 @@ enum skl_power_gate {
10437 _ICL_DSC0_PICTURE_PARAMETER_SET_5_PB, \ 10437 _ICL_DSC0_PICTURE_PARAMETER_SET_5_PB, \
10438 _ICL_DSC0_PICTURE_PARAMETER_SET_5_PC) 10438 _ICL_DSC0_PICTURE_PARAMETER_SET_5_PC)
10439#define ICL_DSC1_PICTURE_PARAMETER_SET_5(pipe) _MMIO_PIPE((pipe) - PIPE_B, \ 10439#define ICL_DSC1_PICTURE_PARAMETER_SET_5(pipe) _MMIO_PIPE((pipe) - PIPE_B, \
10440 _ICL_DSC1_PICTURE_PARAMETER_SET_5_PC, \ 10440 _ICL_DSC1_PICTURE_PARAMETER_SET_5_PB, \
10441 _ICL_DSC1_PICTURE_PARAMETER_SET_5_PC) 10441 _ICL_DSC1_PICTURE_PARAMETER_SET_5_PC)
10442#define DSC_SCALE_DEC_INTINT(scale_dec) ((scale_dec) << 16) 10442#define DSC_SCALE_DEC_INTINT(scale_dec) ((scale_dec) << 16)
10443#define DSC_SCALE_INC_INT(scale_inc) ((scale_inc) << 0) 10443#define DSC_SCALE_INC_INT(scale_inc) ((scale_inc) << 0)
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 11d834f94220..98358b4b36de 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -199,7 +199,6 @@ vma_create(struct drm_i915_gem_object *obj,
199 vma->flags |= I915_VMA_GGTT; 199 vma->flags |= I915_VMA_GGTT;
200 list_add(&vma->obj_link, &obj->vma_list); 200 list_add(&vma->obj_link, &obj->vma_list);
201 } else { 201 } else {
202 i915_ppgtt_get(i915_vm_to_ppgtt(vm));
203 list_add_tail(&vma->obj_link, &obj->vma_list); 202 list_add_tail(&vma->obj_link, &obj->vma_list);
204 } 203 }
205 204
@@ -807,9 +806,6 @@ static void __i915_vma_destroy(struct i915_vma *vma)
807 if (vma->obj) 806 if (vma->obj)
808 rb_erase(&vma->obj_node, &vma->obj->vma_tree); 807 rb_erase(&vma->obj_node, &vma->obj->vma_tree);
809 808
810 if (!i915_vma_is_ggtt(vma))
811 i915_ppgtt_put(i915_vm_to_ppgtt(vma->vm));
812
813 rbtree_postorder_for_each_entry_safe(iter, n, &vma->active, node) { 809 rbtree_postorder_for_each_entry_safe(iter, n, &vma->active, node) {
814 GEM_BUG_ON(i915_gem_active_isset(&iter->base)); 810 GEM_BUG_ON(i915_gem_active_isset(&iter->base));
815 kfree(iter); 811 kfree(iter);
diff --git a/drivers/gpu/drm/i915/intel_audio.c b/drivers/gpu/drm/i915/intel_audio.c
index b725835b47ef..769f3f586661 100644
--- a/drivers/gpu/drm/i915/intel_audio.c
+++ b/drivers/gpu/drm/i915/intel_audio.c
@@ -962,9 +962,6 @@ void i915_audio_component_init(struct drm_i915_private *dev_priv)
962{ 962{
963 int ret; 963 int ret;
964 964
965 if (INTEL_INFO(dev_priv)->num_pipes == 0)
966 return;
967
968 ret = component_add(dev_priv->drm.dev, &i915_audio_component_bind_ops); 965 ret = component_add(dev_priv->drm.dev, &i915_audio_component_bind_ops);
969 if (ret < 0) { 966 if (ret < 0) {
970 DRM_ERROR("failed to add audio component (%d)\n", ret); 967 DRM_ERROR("failed to add audio component (%d)\n", ret);
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index 8761513f3532..c9af34861d9e 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -2708,7 +2708,8 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
2708 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9) 2708 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
2709 intel_dp_stop_link_train(intel_dp); 2709 intel_dp_stop_link_train(intel_dp);
2710 2710
2711 intel_ddi_enable_pipe_clock(crtc_state); 2711 if (!is_mst)
2712 intel_ddi_enable_pipe_clock(crtc_state);
2712} 2713}
2713 2714
2714static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder, 2715static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
@@ -2810,14 +2811,14 @@ static void intel_ddi_post_disable_dp(struct intel_encoder *encoder,
2810 bool is_mst = intel_crtc_has_type(old_crtc_state, 2811 bool is_mst = intel_crtc_has_type(old_crtc_state,
2811 INTEL_OUTPUT_DP_MST); 2812 INTEL_OUTPUT_DP_MST);
2812 2813
2813 intel_ddi_disable_pipe_clock(old_crtc_state); 2814 if (!is_mst) {
2814 2815 intel_ddi_disable_pipe_clock(old_crtc_state);
2815 /* 2816 /*
2816 * Power down sink before disabling the port, otherwise we end 2817 * Power down sink before disabling the port, otherwise we end
2817 * up getting interrupts from the sink on detecting link loss. 2818 * up getting interrupts from the sink on detecting link loss.
2818 */ 2819 */
2819 if (!is_mst)
2820 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 2820 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2821 }
2821 2822
2822 intel_disable_ddi_buf(encoder); 2823 intel_disable_ddi_buf(encoder);
2823 2824
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index ed3fa1c8a983..d2951096bca0 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2988,6 +2988,7 @@ static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
2988 int w = drm_rect_width(&plane_state->base.src) >> 16; 2988 int w = drm_rect_width(&plane_state->base.src) >> 16;
2989 int h = drm_rect_height(&plane_state->base.src) >> 16; 2989 int h = drm_rect_height(&plane_state->base.src) >> 16;
2990 int dst_x = plane_state->base.dst.x1; 2990 int dst_x = plane_state->base.dst.x1;
2991 int dst_w = drm_rect_width(&plane_state->base.dst);
2991 int pipe_src_w = crtc_state->pipe_src_w; 2992 int pipe_src_w = crtc_state->pipe_src_w;
2992 int max_width = skl_max_plane_width(fb, 0, rotation); 2993 int max_width = skl_max_plane_width(fb, 0, rotation);
2993 int max_height = 4096; 2994 int max_height = 4096;
@@ -3009,10 +3010,10 @@ static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
3009 * screen may cause FIFO underflow and display corruption. 3010 * screen may cause FIFO underflow and display corruption.
3010 */ 3011 */
3011 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && 3012 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
3012 (dst_x + w < 4 || dst_x > pipe_src_w - 4)) { 3013 (dst_x + dst_w < 4 || dst_x > pipe_src_w - 4)) {
3013 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n", 3014 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
3014 dst_x + w < 4 ? "end" : "start", 3015 dst_x + dst_w < 4 ? "end" : "start",
3015 dst_x + w < 4 ? dst_x + w : dst_x, 3016 dst_x + dst_w < 4 ? dst_x + dst_w : dst_x,
3016 4, pipe_src_w - 4); 3017 4, pipe_src_w - 4);
3017 return -ERANGE; 3018 return -ERANGE;
3018 } 3019 }
@@ -5078,10 +5079,14 @@ void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5078 mutex_lock(&dev_priv->pcu_lock); 5079 mutex_lock(&dev_priv->pcu_lock);
5079 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); 5080 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5080 mutex_unlock(&dev_priv->pcu_lock); 5081 mutex_unlock(&dev_priv->pcu_lock);
5081 /* wait for pcode to finish disabling IPS, which may take up to 42ms */ 5082 /*
5083 * Wait for PCODE to finish disabling IPS. The BSpec specified
5084 * 42ms timeout value leads to occasional timeouts so use 100ms
5085 * instead.
5086 */
5082 if (intel_wait_for_register(dev_priv, 5087 if (intel_wait_for_register(dev_priv,
5083 IPS_CTL, IPS_ENABLE, 0, 5088 IPS_CTL, IPS_ENABLE, 0,
5084 42)) 5089 100))
5085 DRM_ERROR("Timed out waiting for IPS disable\n"); 5090 DRM_ERROR("Timed out waiting for IPS disable\n");
5086 } else { 5091 } else {
5087 I915_WRITE(IPS_CTL, 0); 5092 I915_WRITE(IPS_CTL, 0);
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index cd0f649b57a5..1193202766a2 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -4160,18 +4160,6 @@ intel_dp_needs_link_retrain(struct intel_dp *intel_dp)
4160 return !drm_dp_channel_eq_ok(link_status, intel_dp->lane_count); 4160 return !drm_dp_channel_eq_ok(link_status, intel_dp->lane_count);
4161} 4161}
4162 4162
4163/*
4164 * If display is now connected check links status,
4165 * there has been known issues of link loss triggering
4166 * long pulse.
4167 *
4168 * Some sinks (eg. ASUS PB287Q) seem to perform some
4169 * weird HPD ping pong during modesets. So we can apparently
4170 * end up with HPD going low during a modeset, and then
4171 * going back up soon after. And once that happens we must
4172 * retrain the link to get a picture. That's in case no
4173 * userspace component reacted to intermittent HPD dip.
4174 */
4175int intel_dp_retrain_link(struct intel_encoder *encoder, 4163int intel_dp_retrain_link(struct intel_encoder *encoder,
4176 struct drm_modeset_acquire_ctx *ctx) 4164 struct drm_modeset_acquire_ctx *ctx)
4177{ 4165{
@@ -4661,7 +4649,8 @@ intel_dp_unset_edid(struct intel_dp *intel_dp)
4661} 4649}
4662 4650
4663static int 4651static int
4664intel_dp_long_pulse(struct intel_connector *connector) 4652intel_dp_long_pulse(struct intel_connector *connector,
4653 struct drm_modeset_acquire_ctx *ctx)
4665{ 4654{
4666 struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 4655 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
4667 struct intel_dp *intel_dp = intel_attached_dp(&connector->base); 4656 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
@@ -4720,6 +4709,22 @@ intel_dp_long_pulse(struct intel_connector *connector)
4720 */ 4709 */
4721 status = connector_status_disconnected; 4710 status = connector_status_disconnected;
4722 goto out; 4711 goto out;
4712 } else {
4713 /*
4714 * If display is now connected check links status,
4715 * there has been known issues of link loss triggering
4716 * long pulse.
4717 *
4718 * Some sinks (eg. ASUS PB287Q) seem to perform some
4719 * weird HPD ping pong during modesets. So we can apparently
4720 * end up with HPD going low during a modeset, and then
4721 * going back up soon after. And once that happens we must
4722 * retrain the link to get a picture. That's in case no
4723 * userspace component reacted to intermittent HPD dip.
4724 */
4725 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4726
4727 intel_dp_retrain_link(encoder, ctx);
4723 } 4728 }
4724 4729
4725 /* 4730 /*
@@ -4781,7 +4786,7 @@ intel_dp_detect(struct drm_connector *connector,
4781 return ret; 4786 return ret;
4782 } 4787 }
4783 4788
4784 status = intel_dp_long_pulse(intel_dp->attached_connector); 4789 status = intel_dp_long_pulse(intel_dp->attached_connector, ctx);
4785 } 4790 }
4786 4791
4787 intel_dp->detect_done = false; 4792 intel_dp->detect_done = false;
diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
index 7e3e01607643..4ecd65375603 100644
--- a/drivers/gpu/drm/i915/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/intel_dp_mst.c
@@ -166,6 +166,8 @@ static void intel_mst_post_disable_dp(struct intel_encoder *encoder,
166 struct intel_connector *connector = 166 struct intel_connector *connector =
167 to_intel_connector(old_conn_state->connector); 167 to_intel_connector(old_conn_state->connector);
168 168
169 intel_ddi_disable_pipe_clock(old_crtc_state);
170
169 /* this can fail */ 171 /* this can fail */
170 drm_dp_check_act_status(&intel_dp->mst_mgr); 172 drm_dp_check_act_status(&intel_dp->mst_mgr);
171 /* and this can also fail */ 173 /* and this can also fail */
@@ -252,6 +254,8 @@ static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
252 I915_WRITE(DP_TP_STATUS(port), temp); 254 I915_WRITE(DP_TP_STATUS(port), temp);
253 255
254 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr); 256 ret = drm_dp_update_payload_part1(&intel_dp->mst_mgr);
257
258 intel_ddi_enable_pipe_clock(pipe_config);
255} 259}
256 260
257static void intel_mst_enable_dp(struct intel_encoder *encoder, 261static void intel_mst_enable_dp(struct intel_encoder *encoder,
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index a9076402dcb0..192972a7d287 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -943,8 +943,12 @@ static int intel_hdmi_hdcp_write(struct intel_digital_port *intel_dig_port,
943 943
944 ret = i2c_transfer(adapter, &msg, 1); 944 ret = i2c_transfer(adapter, &msg, 1);
945 if (ret == 1) 945 if (ret == 1)
946 return 0; 946 ret = 0;
947 return ret >= 0 ? -EIO : ret; 947 else if (ret >= 0)
948 ret = -EIO;
949
950 kfree(write_buf);
951 return ret;
948} 952}
949 953
950static 954static
diff --git a/drivers/gpu/drm/i915/intel_lspcon.c b/drivers/gpu/drm/i915/intel_lspcon.c
index 5dae16ccd9f1..3e085c5f2b81 100644
--- a/drivers/gpu/drm/i915/intel_lspcon.c
+++ b/drivers/gpu/drm/i915/intel_lspcon.c
@@ -74,7 +74,7 @@ static enum drm_lspcon_mode lspcon_wait_mode(struct intel_lspcon *lspcon,
74 DRM_DEBUG_KMS("Waiting for LSPCON mode %s to settle\n", 74 DRM_DEBUG_KMS("Waiting for LSPCON mode %s to settle\n",
75 lspcon_mode_name(mode)); 75 lspcon_mode_name(mode));
76 76
77 wait_for((current_mode = lspcon_get_current_mode(lspcon)) == mode, 100); 77 wait_for((current_mode = lspcon_get_current_mode(lspcon)) == mode, 400);
78 if (current_mode != mode) 78 if (current_mode != mode)
79 DRM_ERROR("LSPCON mode hasn't settled\n"); 79 DRM_ERROR("LSPCON mode hasn't settled\n");
80 80
diff --git a/drivers/gpu/drm/i915/intel_overlay.c b/drivers/gpu/drm/i915/intel_overlay.c
index c2f10d899329..443dfaefd7a6 100644
--- a/drivers/gpu/drm/i915/intel_overlay.c
+++ b/drivers/gpu/drm/i915/intel_overlay.c
@@ -181,8 +181,9 @@ struct intel_overlay {
181 u32 brightness, contrast, saturation; 181 u32 brightness, contrast, saturation;
182 u32 old_xscale, old_yscale; 182 u32 old_xscale, old_yscale;
183 /* register access */ 183 /* register access */
184 u32 flip_addr;
185 struct drm_i915_gem_object *reg_bo; 184 struct drm_i915_gem_object *reg_bo;
185 struct overlay_registers __iomem *regs;
186 u32 flip_addr;
186 /* flip handling */ 187 /* flip handling */
187 struct i915_gem_active last_flip; 188 struct i915_gem_active last_flip;
188}; 189};
@@ -210,29 +211,6 @@ static void i830_overlay_clock_gating(struct drm_i915_private *dev_priv,
210 PCI_DEVFN(0, 0), I830_CLOCK_GATE, val); 211 PCI_DEVFN(0, 0), I830_CLOCK_GATE, val);
211} 212}
212 213
213static struct overlay_registers __iomem *
214intel_overlay_map_regs(struct intel_overlay *overlay)
215{
216 struct drm_i915_private *dev_priv = overlay->i915;
217 struct overlay_registers __iomem *regs;
218
219 if (OVERLAY_NEEDS_PHYSICAL(dev_priv))
220 regs = (struct overlay_registers __iomem *)overlay->reg_bo->phys_handle->vaddr;
221 else
222 regs = io_mapping_map_wc(&dev_priv->ggtt.iomap,
223 overlay->flip_addr,
224 PAGE_SIZE);
225
226 return regs;
227}
228
229static void intel_overlay_unmap_regs(struct intel_overlay *overlay,
230 struct overlay_registers __iomem *regs)
231{
232 if (!OVERLAY_NEEDS_PHYSICAL(overlay->i915))
233 io_mapping_unmap(regs);
234}
235
236static void intel_overlay_submit_request(struct intel_overlay *overlay, 214static void intel_overlay_submit_request(struct intel_overlay *overlay,
237 struct i915_request *rq, 215 struct i915_request *rq,
238 i915_gem_retire_fn retire) 216 i915_gem_retire_fn retire)
@@ -784,13 +762,13 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay,
784 struct drm_i915_gem_object *new_bo, 762 struct drm_i915_gem_object *new_bo,
785 struct put_image_params *params) 763 struct put_image_params *params)
786{ 764{
787 int ret, tmp_width; 765 struct overlay_registers __iomem *regs = overlay->regs;
788 struct overlay_registers __iomem *regs;
789 bool scale_changed = false;
790 struct drm_i915_private *dev_priv = overlay->i915; 766 struct drm_i915_private *dev_priv = overlay->i915;
791 u32 swidth, swidthsw, sheight, ostride; 767 u32 swidth, swidthsw, sheight, ostride;
792 enum pipe pipe = overlay->crtc->pipe; 768 enum pipe pipe = overlay->crtc->pipe;
769 bool scale_changed = false;
793 struct i915_vma *vma; 770 struct i915_vma *vma;
771 int ret, tmp_width;
794 772
795 lockdep_assert_held(&dev_priv->drm.struct_mutex); 773 lockdep_assert_held(&dev_priv->drm.struct_mutex);
796 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex)); 774 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
@@ -815,30 +793,19 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay,
815 793
816 if (!overlay->active) { 794 if (!overlay->active) {
817 u32 oconfig; 795 u32 oconfig;
818 regs = intel_overlay_map_regs(overlay); 796
819 if (!regs) {
820 ret = -ENOMEM;
821 goto out_unpin;
822 }
823 oconfig = OCONF_CC_OUT_8BIT; 797 oconfig = OCONF_CC_OUT_8BIT;
824 if (IS_GEN4(dev_priv)) 798 if (IS_GEN4(dev_priv))
825 oconfig |= OCONF_CSC_MODE_BT709; 799 oconfig |= OCONF_CSC_MODE_BT709;
826 oconfig |= pipe == 0 ? 800 oconfig |= pipe == 0 ?
827 OCONF_PIPE_A : OCONF_PIPE_B; 801 OCONF_PIPE_A : OCONF_PIPE_B;
828 iowrite32(oconfig, &regs->OCONFIG); 802 iowrite32(oconfig, &regs->OCONFIG);
829 intel_overlay_unmap_regs(overlay, regs);
830 803
831 ret = intel_overlay_on(overlay); 804 ret = intel_overlay_on(overlay);
832 if (ret != 0) 805 if (ret != 0)
833 goto out_unpin; 806 goto out_unpin;
834 } 807 }
835 808
836 regs = intel_overlay_map_regs(overlay);
837 if (!regs) {
838 ret = -ENOMEM;
839 goto out_unpin;
840 }
841
842 iowrite32((params->dst_y << 16) | params->dst_x, &regs->DWINPOS); 809 iowrite32((params->dst_y << 16) | params->dst_x, &regs->DWINPOS);
843 iowrite32((params->dst_h << 16) | params->dst_w, &regs->DWINSZ); 810 iowrite32((params->dst_h << 16) | params->dst_w, &regs->DWINSZ);
844 811
@@ -882,8 +849,6 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay,
882 849
883 iowrite32(overlay_cmd_reg(params), &regs->OCMD); 850 iowrite32(overlay_cmd_reg(params), &regs->OCMD);
884 851
885 intel_overlay_unmap_regs(overlay, regs);
886
887 ret = intel_overlay_continue(overlay, vma, scale_changed); 852 ret = intel_overlay_continue(overlay, vma, scale_changed);
888 if (ret) 853 if (ret)
889 goto out_unpin; 854 goto out_unpin;
@@ -901,7 +866,6 @@ out_pin_section:
901int intel_overlay_switch_off(struct intel_overlay *overlay) 866int intel_overlay_switch_off(struct intel_overlay *overlay)
902{ 867{
903 struct drm_i915_private *dev_priv = overlay->i915; 868 struct drm_i915_private *dev_priv = overlay->i915;
904 struct overlay_registers __iomem *regs;
905 int ret; 869 int ret;
906 870
907 lockdep_assert_held(&dev_priv->drm.struct_mutex); 871 lockdep_assert_held(&dev_priv->drm.struct_mutex);
@@ -918,9 +882,7 @@ int intel_overlay_switch_off(struct intel_overlay *overlay)
918 if (ret != 0) 882 if (ret != 0)
919 return ret; 883 return ret;
920 884
921 regs = intel_overlay_map_regs(overlay); 885 iowrite32(0, &overlay->regs->OCMD);
922 iowrite32(0, &regs->OCMD);
923 intel_overlay_unmap_regs(overlay, regs);
924 886
925 return intel_overlay_off(overlay); 887 return intel_overlay_off(overlay);
926} 888}
@@ -1305,7 +1267,6 @@ int intel_overlay_attrs_ioctl(struct drm_device *dev, void *data,
1305 struct drm_intel_overlay_attrs *attrs = data; 1267 struct drm_intel_overlay_attrs *attrs = data;
1306 struct drm_i915_private *dev_priv = to_i915(dev); 1268 struct drm_i915_private *dev_priv = to_i915(dev);
1307 struct intel_overlay *overlay; 1269 struct intel_overlay *overlay;
1308 struct overlay_registers __iomem *regs;
1309 int ret; 1270 int ret;
1310 1271
1311 overlay = dev_priv->overlay; 1272 overlay = dev_priv->overlay;
@@ -1345,15 +1306,7 @@ int intel_overlay_attrs_ioctl(struct drm_device *dev, void *data,
1345 overlay->contrast = attrs->contrast; 1306 overlay->contrast = attrs->contrast;
1346 overlay->saturation = attrs->saturation; 1307 overlay->saturation = attrs->saturation;
1347 1308
1348 regs = intel_overlay_map_regs(overlay); 1309 update_reg_attrs(overlay, overlay->regs);
1349 if (!regs) {
1350 ret = -ENOMEM;
1351 goto out_unlock;
1352 }
1353
1354 update_reg_attrs(overlay, regs);
1355
1356 intel_overlay_unmap_regs(overlay, regs);
1357 1310
1358 if (attrs->flags & I915_OVERLAY_UPDATE_GAMMA) { 1311 if (attrs->flags & I915_OVERLAY_UPDATE_GAMMA) {
1359 if (IS_GEN2(dev_priv)) 1312 if (IS_GEN2(dev_priv))
@@ -1386,12 +1339,47 @@ out_unlock:
1386 return ret; 1339 return ret;
1387} 1340}
1388 1341
1342static int get_registers(struct intel_overlay *overlay, bool use_phys)
1343{
1344 struct drm_i915_gem_object *obj;
1345 struct i915_vma *vma;
1346 int err;
1347
1348 obj = i915_gem_object_create_stolen(overlay->i915, PAGE_SIZE);
1349 if (obj == NULL)
1350 obj = i915_gem_object_create_internal(overlay->i915, PAGE_SIZE);
1351 if (IS_ERR(obj))
1352 return PTR_ERR(obj);
1353
1354 vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE);
1355 if (IS_ERR(vma)) {
1356 err = PTR_ERR(vma);
1357 goto err_put_bo;
1358 }
1359
1360 if (use_phys)
1361 overlay->flip_addr = sg_dma_address(obj->mm.pages->sgl);
1362 else
1363 overlay->flip_addr = i915_ggtt_offset(vma);
1364 overlay->regs = i915_vma_pin_iomap(vma);
1365 i915_vma_unpin(vma);
1366
1367 if (IS_ERR(overlay->regs)) {
1368 err = PTR_ERR(overlay->regs);
1369 goto err_put_bo;
1370 }
1371
1372 overlay->reg_bo = obj;
1373 return 0;
1374
1375err_put_bo:
1376 i915_gem_object_put(obj);
1377 return err;
1378}
1379
1389void intel_setup_overlay(struct drm_i915_private *dev_priv) 1380void intel_setup_overlay(struct drm_i915_private *dev_priv)
1390{ 1381{
1391 struct intel_overlay *overlay; 1382 struct intel_overlay *overlay;
1392 struct drm_i915_gem_object *reg_bo;
1393 struct overlay_registers __iomem *regs;
1394 struct i915_vma *vma = NULL;
1395 int ret; 1383 int ret;
1396 1384
1397 if (!HAS_OVERLAY(dev_priv)) 1385 if (!HAS_OVERLAY(dev_priv))
@@ -1401,46 +1389,8 @@ void intel_setup_overlay(struct drm_i915_private *dev_priv)
1401 if (!overlay) 1389 if (!overlay)
1402 return; 1390 return;
1403 1391
1404 mutex_lock(&dev_priv->drm.struct_mutex);
1405 if (WARN_ON(dev_priv->overlay))
1406 goto out_free;
1407
1408 overlay->i915 = dev_priv; 1392 overlay->i915 = dev_priv;
1409 1393
1410 reg_bo = NULL;
1411 if (!OVERLAY_NEEDS_PHYSICAL(dev_priv))
1412 reg_bo = i915_gem_object_create_stolen(dev_priv, PAGE_SIZE);
1413 if (reg_bo == NULL)
1414 reg_bo = i915_gem_object_create(dev_priv, PAGE_SIZE);
1415 if (IS_ERR(reg_bo))
1416 goto out_free;
1417 overlay->reg_bo = reg_bo;
1418
1419 if (OVERLAY_NEEDS_PHYSICAL(dev_priv)) {
1420 ret = i915_gem_object_attach_phys(reg_bo, PAGE_SIZE);
1421 if (ret) {
1422 DRM_ERROR("failed to attach phys overlay regs\n");
1423 goto out_free_bo;
1424 }
1425 overlay->flip_addr = reg_bo->phys_handle->busaddr;
1426 } else {
1427 vma = i915_gem_object_ggtt_pin(reg_bo, NULL,
1428 0, PAGE_SIZE, PIN_MAPPABLE);
1429 if (IS_ERR(vma)) {
1430 DRM_ERROR("failed to pin overlay register bo\n");
1431 ret = PTR_ERR(vma);
1432 goto out_free_bo;
1433 }
1434 overlay->flip_addr = i915_ggtt_offset(vma);
1435
1436 ret = i915_gem_object_set_to_gtt_domain(reg_bo, true);
1437 if (ret) {
1438 DRM_ERROR("failed to move overlay register bo into the GTT\n");
1439 goto out_unpin_bo;
1440 }
1441 }
1442
1443 /* init all values */
1444 overlay->color_key = 0x0101fe; 1394 overlay->color_key = 0x0101fe;
1445 overlay->color_key_enabled = true; 1395 overlay->color_key_enabled = true;
1446 overlay->brightness = -19; 1396 overlay->brightness = -19;
@@ -1449,44 +1399,51 @@ void intel_setup_overlay(struct drm_i915_private *dev_priv)
1449 1399
1450 init_request_active(&overlay->last_flip, NULL); 1400 init_request_active(&overlay->last_flip, NULL);
1451 1401
1452 regs = intel_overlay_map_regs(overlay); 1402 mutex_lock(&dev_priv->drm.struct_mutex);
1453 if (!regs) 1403
1454 goto out_unpin_bo; 1404 ret = get_registers(overlay, OVERLAY_NEEDS_PHYSICAL(dev_priv));
1405 if (ret)
1406 goto out_free;
1407
1408 ret = i915_gem_object_set_to_gtt_domain(overlay->reg_bo, true);
1409 if (ret)
1410 goto out_reg_bo;
1455 1411
1456 memset_io(regs, 0, sizeof(struct overlay_registers)); 1412 mutex_unlock(&dev_priv->drm.struct_mutex);
1457 update_polyphase_filter(regs);
1458 update_reg_attrs(overlay, regs);
1459 1413
1460 intel_overlay_unmap_regs(overlay, regs); 1414 memset_io(overlay->regs, 0, sizeof(struct overlay_registers));
1415 update_polyphase_filter(overlay->regs);
1416 update_reg_attrs(overlay, overlay->regs);
1461 1417
1462 dev_priv->overlay = overlay; 1418 dev_priv->overlay = overlay;
1463 mutex_unlock(&dev_priv->drm.struct_mutex); 1419 DRM_INFO("Initialized overlay support.\n");
1464 DRM_INFO("initialized overlay support\n");
1465 return; 1420 return;
1466 1421
1467out_unpin_bo: 1422out_reg_bo:
1468 if (vma) 1423 i915_gem_object_put(overlay->reg_bo);
1469 i915_vma_unpin(vma);
1470out_free_bo:
1471 i915_gem_object_put(reg_bo);
1472out_free: 1424out_free:
1473 mutex_unlock(&dev_priv->drm.struct_mutex); 1425 mutex_unlock(&dev_priv->drm.struct_mutex);
1474 kfree(overlay); 1426 kfree(overlay);
1475 return;
1476} 1427}
1477 1428
1478void intel_cleanup_overlay(struct drm_i915_private *dev_priv) 1429void intel_cleanup_overlay(struct drm_i915_private *dev_priv)
1479{ 1430{
1480 if (!dev_priv->overlay) 1431 struct intel_overlay *overlay;
1432
1433 overlay = fetch_and_zero(&dev_priv->overlay);
1434 if (!overlay)
1481 return; 1435 return;
1482 1436
1483 /* The bo's should be free'd by the generic code already. 1437 /*
1438 * The bo's should be free'd by the generic code already.
1484 * Furthermore modesetting teardown happens beforehand so the 1439 * Furthermore modesetting teardown happens beforehand so the
1485 * hardware should be off already */ 1440 * hardware should be off already.
1486 WARN_ON(dev_priv->overlay->active); 1441 */
1442 WARN_ON(overlay->active);
1443
1444 i915_gem_object_put(overlay->reg_bo);
1487 1445
1488 i915_gem_object_put(dev_priv->overlay->reg_bo); 1446 kfree(overlay);
1489 kfree(dev_priv->overlay);
1490} 1447}
1491 1448
1492#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) 1449#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
@@ -1498,37 +1455,11 @@ struct intel_overlay_error_state {
1498 u32 isr; 1455 u32 isr;
1499}; 1456};
1500 1457
1501static struct overlay_registers __iomem *
1502intel_overlay_map_regs_atomic(struct intel_overlay *overlay)
1503{
1504 struct drm_i915_private *dev_priv = overlay->i915;
1505 struct overlay_registers __iomem *regs;
1506
1507 if (OVERLAY_NEEDS_PHYSICAL(dev_priv))
1508 /* Cast to make sparse happy, but it's wc memory anyway, so
1509 * equivalent to the wc io mapping on X86. */
1510 regs = (struct overlay_registers __iomem *)
1511 overlay->reg_bo->phys_handle->vaddr;
1512 else
1513 regs = io_mapping_map_atomic_wc(&dev_priv->ggtt.iomap,
1514 overlay->flip_addr);
1515
1516 return regs;
1517}
1518
1519static void intel_overlay_unmap_regs_atomic(struct intel_overlay *overlay,
1520 struct overlay_registers __iomem *regs)
1521{
1522 if (!OVERLAY_NEEDS_PHYSICAL(overlay->i915))
1523 io_mapping_unmap_atomic(regs);
1524}
1525
1526struct intel_overlay_error_state * 1458struct intel_overlay_error_state *
1527intel_overlay_capture_error_state(struct drm_i915_private *dev_priv) 1459intel_overlay_capture_error_state(struct drm_i915_private *dev_priv)
1528{ 1460{
1529 struct intel_overlay *overlay = dev_priv->overlay; 1461 struct intel_overlay *overlay = dev_priv->overlay;
1530 struct intel_overlay_error_state *error; 1462 struct intel_overlay_error_state *error;
1531 struct overlay_registers __iomem *regs;
1532 1463
1533 if (!overlay || !overlay->active) 1464 if (!overlay || !overlay->active)
1534 return NULL; 1465 return NULL;
@@ -1541,18 +1472,9 @@ intel_overlay_capture_error_state(struct drm_i915_private *dev_priv)
1541 error->isr = I915_READ(ISR); 1472 error->isr = I915_READ(ISR);
1542 error->base = overlay->flip_addr; 1473 error->base = overlay->flip_addr;
1543 1474
1544 regs = intel_overlay_map_regs_atomic(overlay); 1475 memcpy_fromio(&error->regs, overlay->regs, sizeof(error->regs));
1545 if (!regs)
1546 goto err;
1547
1548 memcpy_fromio(&error->regs, regs, sizeof(struct overlay_registers));
1549 intel_overlay_unmap_regs_atomic(overlay, regs);
1550 1476
1551 return error; 1477 return error;
1552
1553err:
1554 kfree(error);
1555 return NULL;
1556} 1478}
1557 1479
1558void 1480void
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
index 978782a77629..28d191192945 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
@@ -132,6 +132,11 @@ static void mtk_ovl_config(struct mtk_ddp_comp *comp, unsigned int w,
132 writel(0x0, comp->regs + DISP_REG_OVL_RST); 132 writel(0x0, comp->regs + DISP_REG_OVL_RST);
133} 133}
134 134
135static unsigned int mtk_ovl_layer_nr(struct mtk_ddp_comp *comp)
136{
137 return 4;
138}
139
135static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx) 140static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx)
136{ 141{
137 unsigned int reg; 142 unsigned int reg;
@@ -157,6 +162,11 @@ static void mtk_ovl_layer_off(struct mtk_ddp_comp *comp, unsigned int idx)
157 162
158static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt) 163static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt)
159{ 164{
165 /* The return value in switch "MEM_MODE_INPUT_FORMAT_XXX"
166 * is defined in mediatek HW data sheet.
167 * The alphabet order in XXX is no relation to data
168 * arrangement in memory.
169 */
160 switch (fmt) { 170 switch (fmt) {
161 default: 171 default:
162 case DRM_FORMAT_RGB565: 172 case DRM_FORMAT_RGB565:
@@ -221,6 +231,7 @@ static const struct mtk_ddp_comp_funcs mtk_disp_ovl_funcs = {
221 .stop = mtk_ovl_stop, 231 .stop = mtk_ovl_stop,
222 .enable_vblank = mtk_ovl_enable_vblank, 232 .enable_vblank = mtk_ovl_enable_vblank,
223 .disable_vblank = mtk_ovl_disable_vblank, 233 .disable_vblank = mtk_ovl_disable_vblank,
234 .layer_nr = mtk_ovl_layer_nr,
224 .layer_on = mtk_ovl_layer_on, 235 .layer_on = mtk_ovl_layer_on,
225 .layer_off = mtk_ovl_layer_off, 236 .layer_off = mtk_ovl_layer_off,
226 .layer_config = mtk_ovl_layer_config, 237 .layer_config = mtk_ovl_layer_config,
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
index 585943c81e1f..b0a5cffe345a 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
@@ -31,14 +31,31 @@
31#define RDMA_REG_UPDATE_INT BIT(0) 31#define RDMA_REG_UPDATE_INT BIT(0)
32#define DISP_REG_RDMA_GLOBAL_CON 0x0010 32#define DISP_REG_RDMA_GLOBAL_CON 0x0010
33#define RDMA_ENGINE_EN BIT(0) 33#define RDMA_ENGINE_EN BIT(0)
34#define RDMA_MODE_MEMORY BIT(1)
34#define DISP_REG_RDMA_SIZE_CON_0 0x0014 35#define DISP_REG_RDMA_SIZE_CON_0 0x0014
36#define RDMA_MATRIX_ENABLE BIT(17)
37#define RDMA_MATRIX_INT_MTX_SEL GENMASK(23, 20)
38#define RDMA_MATRIX_INT_MTX_BT601_to_RGB (6 << 20)
35#define DISP_REG_RDMA_SIZE_CON_1 0x0018 39#define DISP_REG_RDMA_SIZE_CON_1 0x0018
36#define DISP_REG_RDMA_TARGET_LINE 0x001c 40#define DISP_REG_RDMA_TARGET_LINE 0x001c
41#define DISP_RDMA_MEM_CON 0x0024
42#define MEM_MODE_INPUT_FORMAT_RGB565 (0x000 << 4)
43#define MEM_MODE_INPUT_FORMAT_RGB888 (0x001 << 4)
44#define MEM_MODE_INPUT_FORMAT_RGBA8888 (0x002 << 4)
45#define MEM_MODE_INPUT_FORMAT_ARGB8888 (0x003 << 4)
46#define MEM_MODE_INPUT_FORMAT_UYVY (0x004 << 4)
47#define MEM_MODE_INPUT_FORMAT_YUYV (0x005 << 4)
48#define MEM_MODE_INPUT_SWAP BIT(8)
49#define DISP_RDMA_MEM_SRC_PITCH 0x002c
50#define DISP_RDMA_MEM_GMC_SETTING_0 0x0030
37#define DISP_REG_RDMA_FIFO_CON 0x0040 51#define DISP_REG_RDMA_FIFO_CON 0x0040
38#define RDMA_FIFO_UNDERFLOW_EN BIT(31) 52#define RDMA_FIFO_UNDERFLOW_EN BIT(31)
39#define RDMA_FIFO_PSEUDO_SIZE(bytes) (((bytes) / 16) << 16) 53#define RDMA_FIFO_PSEUDO_SIZE(bytes) (((bytes) / 16) << 16)
40#define RDMA_OUTPUT_VALID_FIFO_THRESHOLD(bytes) ((bytes) / 16) 54#define RDMA_OUTPUT_VALID_FIFO_THRESHOLD(bytes) ((bytes) / 16)
41#define RDMA_FIFO_SIZE(rdma) ((rdma)->data->fifo_size) 55#define RDMA_FIFO_SIZE(rdma) ((rdma)->data->fifo_size)
56#define DISP_RDMA_MEM_START_ADDR 0x0f00
57
58#define RDMA_MEM_GMC 0x40402020
42 59
43struct mtk_disp_rdma_data { 60struct mtk_disp_rdma_data {
44 unsigned int fifo_size; 61 unsigned int fifo_size;
@@ -138,12 +155,87 @@ static void mtk_rdma_config(struct mtk_ddp_comp *comp, unsigned int width,
138 writel(reg, comp->regs + DISP_REG_RDMA_FIFO_CON); 155 writel(reg, comp->regs + DISP_REG_RDMA_FIFO_CON);
139} 156}
140 157
158static unsigned int rdma_fmt_convert(struct mtk_disp_rdma *rdma,
159 unsigned int fmt)
160{
161 /* The return value in switch "MEM_MODE_INPUT_FORMAT_XXX"
162 * is defined in mediatek HW data sheet.
163 * The alphabet order in XXX is no relation to data
164 * arrangement in memory.
165 */
166 switch (fmt) {
167 default:
168 case DRM_FORMAT_RGB565:
169 return MEM_MODE_INPUT_FORMAT_RGB565;
170 case DRM_FORMAT_BGR565:
171 return MEM_MODE_INPUT_FORMAT_RGB565 | MEM_MODE_INPUT_SWAP;
172 case DRM_FORMAT_RGB888:
173 return MEM_MODE_INPUT_FORMAT_RGB888;
174 case DRM_FORMAT_BGR888:
175 return MEM_MODE_INPUT_FORMAT_RGB888 | MEM_MODE_INPUT_SWAP;
176 case DRM_FORMAT_RGBX8888:
177 case DRM_FORMAT_RGBA8888:
178 return MEM_MODE_INPUT_FORMAT_ARGB8888;
179 case DRM_FORMAT_BGRX8888:
180 case DRM_FORMAT_BGRA8888:
181 return MEM_MODE_INPUT_FORMAT_ARGB8888 | MEM_MODE_INPUT_SWAP;
182 case DRM_FORMAT_XRGB8888:
183 case DRM_FORMAT_ARGB8888:
184 return MEM_MODE_INPUT_FORMAT_RGBA8888;
185 case DRM_FORMAT_XBGR8888:
186 case DRM_FORMAT_ABGR8888:
187 return MEM_MODE_INPUT_FORMAT_RGBA8888 | MEM_MODE_INPUT_SWAP;
188 case DRM_FORMAT_UYVY:
189 return MEM_MODE_INPUT_FORMAT_UYVY;
190 case DRM_FORMAT_YUYV:
191 return MEM_MODE_INPUT_FORMAT_YUYV;
192 }
193}
194
195static unsigned int mtk_rdma_layer_nr(struct mtk_ddp_comp *comp)
196{
197 return 1;
198}
199
200static void mtk_rdma_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
201 struct mtk_plane_state *state)
202{
203 struct mtk_disp_rdma *rdma = comp_to_rdma(comp);
204 struct mtk_plane_pending_state *pending = &state->pending;
205 unsigned int addr = pending->addr;
206 unsigned int pitch = pending->pitch & 0xffff;
207 unsigned int fmt = pending->format;
208 unsigned int con;
209
210 con = rdma_fmt_convert(rdma, fmt);
211 writel_relaxed(con, comp->regs + DISP_RDMA_MEM_CON);
212
213 if (fmt == DRM_FORMAT_UYVY || fmt == DRM_FORMAT_YUYV) {
214 rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0,
215 RDMA_MATRIX_ENABLE, RDMA_MATRIX_ENABLE);
216 rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0,
217 RDMA_MATRIX_INT_MTX_SEL,
218 RDMA_MATRIX_INT_MTX_BT601_to_RGB);
219 } else {
220 rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0,
221 RDMA_MATRIX_ENABLE, 0);
222 }
223
224 writel_relaxed(addr, comp->regs + DISP_RDMA_MEM_START_ADDR);
225 writel_relaxed(pitch, comp->regs + DISP_RDMA_MEM_SRC_PITCH);
226 writel(RDMA_MEM_GMC, comp->regs + DISP_RDMA_MEM_GMC_SETTING_0);
227 rdma_update_bits(comp, DISP_REG_RDMA_GLOBAL_CON,
228 RDMA_MODE_MEMORY, RDMA_MODE_MEMORY);
229}
230
141static const struct mtk_ddp_comp_funcs mtk_disp_rdma_funcs = { 231static const struct mtk_ddp_comp_funcs mtk_disp_rdma_funcs = {
142 .config = mtk_rdma_config, 232 .config = mtk_rdma_config,
143 .start = mtk_rdma_start, 233 .start = mtk_rdma_start,
144 .stop = mtk_rdma_stop, 234 .stop = mtk_rdma_stop,
145 .enable_vblank = mtk_rdma_enable_vblank, 235 .enable_vblank = mtk_rdma_enable_vblank,
146 .disable_vblank = mtk_rdma_disable_vblank, 236 .disable_vblank = mtk_rdma_disable_vblank,
237 .layer_nr = mtk_rdma_layer_nr,
238 .layer_config = mtk_rdma_layer_config,
147}; 239};
148 240
149static int mtk_disp_rdma_bind(struct device *dev, struct device *master, 241static int mtk_disp_rdma_bind(struct device *dev, struct device *master,
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index 2d6aa150a9ff..0b976dfd04df 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -45,7 +45,8 @@ struct mtk_drm_crtc {
45 bool pending_needs_vblank; 45 bool pending_needs_vblank;
46 struct drm_pending_vblank_event *event; 46 struct drm_pending_vblank_event *event;
47 47
48 struct drm_plane planes[OVL_LAYER_NR]; 48 struct drm_plane *planes;
49 unsigned int layer_nr;
49 bool pending_planes; 50 bool pending_planes;
50 51
51 void __iomem *config_regs; 52 void __iomem *config_regs;
@@ -171,9 +172,9 @@ static void mtk_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
171static int mtk_drm_crtc_enable_vblank(struct drm_crtc *crtc) 172static int mtk_drm_crtc_enable_vblank(struct drm_crtc *crtc)
172{ 173{
173 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc); 174 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
174 struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0]; 175 struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
175 176
176 mtk_ddp_comp_enable_vblank(ovl, &mtk_crtc->base); 177 mtk_ddp_comp_enable_vblank(comp, &mtk_crtc->base);
177 178
178 return 0; 179 return 0;
179} 180}
@@ -181,9 +182,9 @@ static int mtk_drm_crtc_enable_vblank(struct drm_crtc *crtc)
181static void mtk_drm_crtc_disable_vblank(struct drm_crtc *crtc) 182static void mtk_drm_crtc_disable_vblank(struct drm_crtc *crtc)
182{ 183{
183 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc); 184 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
184 struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0]; 185 struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
185 186
186 mtk_ddp_comp_disable_vblank(ovl); 187 mtk_ddp_comp_disable_vblank(comp);
187} 188}
188 189
189static int mtk_crtc_ddp_clk_enable(struct mtk_drm_crtc *mtk_crtc) 190static int mtk_crtc_ddp_clk_enable(struct mtk_drm_crtc *mtk_crtc)
@@ -286,7 +287,7 @@ static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)
286 } 287 }
287 288
288 /* Initially configure all planes */ 289 /* Initially configure all planes */
289 for (i = 0; i < OVL_LAYER_NR; i++) { 290 for (i = 0; i < mtk_crtc->layer_nr; i++) {
290 struct drm_plane *plane = &mtk_crtc->planes[i]; 291 struct drm_plane *plane = &mtk_crtc->planes[i];
291 struct mtk_plane_state *plane_state; 292 struct mtk_plane_state *plane_state;
292 293
@@ -334,7 +335,7 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
334{ 335{
335 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc); 336 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
336 struct mtk_crtc_state *state = to_mtk_crtc_state(mtk_crtc->base.state); 337 struct mtk_crtc_state *state = to_mtk_crtc_state(mtk_crtc->base.state);
337 struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0]; 338 struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
338 unsigned int i; 339 unsigned int i;
339 340
340 /* 341 /*
@@ -343,7 +344,7 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
343 * queue update module registers on vblank. 344 * queue update module registers on vblank.
344 */ 345 */
345 if (state->pending_config) { 346 if (state->pending_config) {
346 mtk_ddp_comp_config(ovl, state->pending_width, 347 mtk_ddp_comp_config(comp, state->pending_width,
347 state->pending_height, 348 state->pending_height,
348 state->pending_vrefresh, 0); 349 state->pending_vrefresh, 0);
349 350
@@ -351,14 +352,14 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
351 } 352 }
352 353
353 if (mtk_crtc->pending_planes) { 354 if (mtk_crtc->pending_planes) {
354 for (i = 0; i < OVL_LAYER_NR; i++) { 355 for (i = 0; i < mtk_crtc->layer_nr; i++) {
355 struct drm_plane *plane = &mtk_crtc->planes[i]; 356 struct drm_plane *plane = &mtk_crtc->planes[i];
356 struct mtk_plane_state *plane_state; 357 struct mtk_plane_state *plane_state;
357 358
358 plane_state = to_mtk_plane_state(plane->state); 359 plane_state = to_mtk_plane_state(plane->state);
359 360
360 if (plane_state->pending.config) { 361 if (plane_state->pending.config) {
361 mtk_ddp_comp_layer_config(ovl, i, plane_state); 362 mtk_ddp_comp_layer_config(comp, i, plane_state);
362 plane_state->pending.config = false; 363 plane_state->pending.config = false;
363 } 364 }
364 } 365 }
@@ -370,12 +371,12 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
370 struct drm_crtc_state *old_state) 371 struct drm_crtc_state *old_state)
371{ 372{
372 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc); 373 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
373 struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0]; 374 struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
374 int ret; 375 int ret;
375 376
376 DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id); 377 DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
377 378
378 ret = mtk_smi_larb_get(ovl->larb_dev); 379 ret = mtk_smi_larb_get(comp->larb_dev);
379 if (ret) { 380 if (ret) {
380 DRM_ERROR("Failed to get larb: %d\n", ret); 381 DRM_ERROR("Failed to get larb: %d\n", ret);
381 return; 382 return;
@@ -383,7 +384,7 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
383 384
384 ret = mtk_crtc_ddp_hw_init(mtk_crtc); 385 ret = mtk_crtc_ddp_hw_init(mtk_crtc);
385 if (ret) { 386 if (ret) {
386 mtk_smi_larb_put(ovl->larb_dev); 387 mtk_smi_larb_put(comp->larb_dev);
387 return; 388 return;
388 } 389 }
389 390
@@ -395,7 +396,7 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
395 struct drm_crtc_state *old_state) 396 struct drm_crtc_state *old_state)
396{ 397{
397 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc); 398 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
398 struct mtk_ddp_comp *ovl = mtk_crtc->ddp_comp[0]; 399 struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
399 int i; 400 int i;
400 401
401 DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id); 402 DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
@@ -403,7 +404,7 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
403 return; 404 return;
404 405
405 /* Set all pending plane state to disabled */ 406 /* Set all pending plane state to disabled */
406 for (i = 0; i < OVL_LAYER_NR; i++) { 407 for (i = 0; i < mtk_crtc->layer_nr; i++) {
407 struct drm_plane *plane = &mtk_crtc->planes[i]; 408 struct drm_plane *plane = &mtk_crtc->planes[i];
408 struct mtk_plane_state *plane_state; 409 struct mtk_plane_state *plane_state;
409 410
@@ -418,7 +419,7 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
418 419
419 drm_crtc_vblank_off(crtc); 420 drm_crtc_vblank_off(crtc);
420 mtk_crtc_ddp_hw_fini(mtk_crtc); 421 mtk_crtc_ddp_hw_fini(mtk_crtc);
421 mtk_smi_larb_put(ovl->larb_dev); 422 mtk_smi_larb_put(comp->larb_dev);
422 423
423 mtk_crtc->enabled = false; 424 mtk_crtc->enabled = false;
424} 425}
@@ -450,7 +451,7 @@ static void mtk_drm_crtc_atomic_flush(struct drm_crtc *crtc,
450 451
451 if (mtk_crtc->event) 452 if (mtk_crtc->event)
452 mtk_crtc->pending_needs_vblank = true; 453 mtk_crtc->pending_needs_vblank = true;
453 for (i = 0; i < OVL_LAYER_NR; i++) { 454 for (i = 0; i < mtk_crtc->layer_nr; i++) {
454 struct drm_plane *plane = &mtk_crtc->planes[i]; 455 struct drm_plane *plane = &mtk_crtc->planes[i];
455 struct mtk_plane_state *plane_state; 456 struct mtk_plane_state *plane_state;
456 457
@@ -516,7 +517,7 @@ err_cleanup_crtc:
516 return ret; 517 return ret;
517} 518}
518 519
519void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *ovl) 520void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp)
520{ 521{
521 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc); 522 struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
522 struct mtk_drm_private *priv = crtc->dev->dev_private; 523 struct mtk_drm_private *priv = crtc->dev->dev_private;
@@ -598,7 +599,12 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
598 mtk_crtc->ddp_comp[i] = comp; 599 mtk_crtc->ddp_comp[i] = comp;
599 } 600 }
600 601
601 for (zpos = 0; zpos < OVL_LAYER_NR; zpos++) { 602 mtk_crtc->layer_nr = mtk_ddp_comp_layer_nr(mtk_crtc->ddp_comp[0]);
603 mtk_crtc->planes = devm_kzalloc(dev, mtk_crtc->layer_nr *
604 sizeof(struct drm_plane),
605 GFP_KERNEL);
606
607 for (zpos = 0; zpos < mtk_crtc->layer_nr; zpos++) {
602 type = (zpos == 0) ? DRM_PLANE_TYPE_PRIMARY : 608 type = (zpos == 0) ? DRM_PLANE_TYPE_PRIMARY :
603 (zpos == 1) ? DRM_PLANE_TYPE_CURSOR : 609 (zpos == 1) ? DRM_PLANE_TYPE_CURSOR :
604 DRM_PLANE_TYPE_OVERLAY; 610 DRM_PLANE_TYPE_OVERLAY;
@@ -609,7 +615,8 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
609 } 615 }
610 616
611 ret = mtk_drm_crtc_init(drm_dev, mtk_crtc, &mtk_crtc->planes[0], 617 ret = mtk_drm_crtc_init(drm_dev, mtk_crtc, &mtk_crtc->planes[0],
612 &mtk_crtc->planes[1], pipe); 618 mtk_crtc->layer_nr > 1 ? &mtk_crtc->planes[1] :
619 NULL, pipe);
613 if (ret < 0) 620 if (ret < 0)
614 goto unprepare; 621 goto unprepare;
615 drm_mode_crtc_set_gamma_size(&mtk_crtc->base, MTK_LUT_SIZE); 622 drm_mode_crtc_set_gamma_size(&mtk_crtc->base, MTK_LUT_SIZE);
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.h b/drivers/gpu/drm/mediatek/mtk_drm_crtc.h
index 9d9410c67ae9..091adb2087eb 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.h
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.h
@@ -18,13 +18,12 @@
18#include "mtk_drm_ddp_comp.h" 18#include "mtk_drm_ddp_comp.h"
19#include "mtk_drm_plane.h" 19#include "mtk_drm_plane.h"
20 20
21#define OVL_LAYER_NR 4
22#define MTK_LUT_SIZE 512 21#define MTK_LUT_SIZE 512
23#define MTK_MAX_BPC 10 22#define MTK_MAX_BPC 10
24#define MTK_MIN_BPC 3 23#define MTK_MIN_BPC 3
25 24
26void mtk_drm_crtc_commit(struct drm_crtc *crtc); 25void mtk_drm_crtc_commit(struct drm_crtc *crtc);
27void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *ovl); 26void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp);
28int mtk_drm_crtc_create(struct drm_device *drm_dev, 27int mtk_drm_crtc_create(struct drm_device *drm_dev,
29 const enum mtk_ddp_comp_id *path, 28 const enum mtk_ddp_comp_id *path,
30 unsigned int path_len); 29 unsigned int path_len);
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
index 87e4191c250e..546b3e3b300b 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp.c
@@ -106,6 +106,8 @@
106#define OVL1_MOUT_EN_COLOR1 0x1 106#define OVL1_MOUT_EN_COLOR1 0x1
107#define GAMMA_MOUT_EN_RDMA1 0x1 107#define GAMMA_MOUT_EN_RDMA1 0x1
108#define RDMA0_SOUT_DPI0 0x2 108#define RDMA0_SOUT_DPI0 0x2
109#define RDMA0_SOUT_DPI1 0x3
110#define RDMA0_SOUT_DSI1 0x1
109#define RDMA0_SOUT_DSI2 0x4 111#define RDMA0_SOUT_DSI2 0x4
110#define RDMA0_SOUT_DSI3 0x5 112#define RDMA0_SOUT_DSI3 0x5
111#define RDMA1_SOUT_DPI0 0x2 113#define RDMA1_SOUT_DPI0 0x2
@@ -122,6 +124,8 @@
122#define DPI0_SEL_IN_RDMA2 0x3 124#define DPI0_SEL_IN_RDMA2 0x3
123#define DPI1_SEL_IN_RDMA1 (0x1 << 8) 125#define DPI1_SEL_IN_RDMA1 (0x1 << 8)
124#define DPI1_SEL_IN_RDMA2 (0x3 << 8) 126#define DPI1_SEL_IN_RDMA2 (0x3 << 8)
127#define DSI0_SEL_IN_RDMA1 0x1
128#define DSI0_SEL_IN_RDMA2 0x4
125#define DSI1_SEL_IN_RDMA1 0x1 129#define DSI1_SEL_IN_RDMA1 0x1
126#define DSI1_SEL_IN_RDMA2 0x4 130#define DSI1_SEL_IN_RDMA2 0x4
127#define DSI2_SEL_IN_RDMA1 (0x1 << 16) 131#define DSI2_SEL_IN_RDMA1 (0x1 << 16)
@@ -224,6 +228,12 @@ static unsigned int mtk_ddp_mout_en(enum mtk_ddp_comp_id cur,
224 } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DPI0) { 228 } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DPI0) {
225 *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN; 229 *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
226 value = RDMA0_SOUT_DPI0; 230 value = RDMA0_SOUT_DPI0;
231 } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DPI1) {
232 *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
233 value = RDMA0_SOUT_DPI1;
234 } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI1) {
235 *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
236 value = RDMA0_SOUT_DSI1;
227 } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI2) { 237 } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI2) {
228 *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN; 238 *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
229 value = RDMA0_SOUT_DSI2; 239 value = RDMA0_SOUT_DSI2;
@@ -282,6 +292,9 @@ static unsigned int mtk_ddp_sel_in(enum mtk_ddp_comp_id cur,
282 } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI1) { 292 } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI1) {
283 *addr = DISP_REG_CONFIG_DPI_SEL_IN; 293 *addr = DISP_REG_CONFIG_DPI_SEL_IN;
284 value = DPI1_SEL_IN_RDMA1; 294 value = DPI1_SEL_IN_RDMA1;
295 } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI0) {
296 *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
297 value = DSI0_SEL_IN_RDMA1;
285 } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI1) { 298 } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI1) {
286 *addr = DISP_REG_CONFIG_DSIO_SEL_IN; 299 *addr = DISP_REG_CONFIG_DSIO_SEL_IN;
287 value = DSI1_SEL_IN_RDMA1; 300 value = DSI1_SEL_IN_RDMA1;
@@ -297,8 +310,11 @@ static unsigned int mtk_ddp_sel_in(enum mtk_ddp_comp_id cur,
297 } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI1) { 310 } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI1) {
298 *addr = DISP_REG_CONFIG_DPI_SEL_IN; 311 *addr = DISP_REG_CONFIG_DPI_SEL_IN;
299 value = DPI1_SEL_IN_RDMA2; 312 value = DPI1_SEL_IN_RDMA2;
300 } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI1) { 313 } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI0) {
301 *addr = DISP_REG_CONFIG_DSIE_SEL_IN; 314 *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
315 value = DSI0_SEL_IN_RDMA2;
316 } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI1) {
317 *addr = DISP_REG_CONFIG_DSIO_SEL_IN;
302 value = DSI1_SEL_IN_RDMA2; 318 value = DSI1_SEL_IN_RDMA2;
303 } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI2) { 319 } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI2) {
304 *addr = DISP_REG_CONFIG_DSIE_SEL_IN; 320 *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
index 7413ffeb3c9d..8399229e6ad2 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
@@ -78,6 +78,7 @@ struct mtk_ddp_comp_funcs {
78 void (*stop)(struct mtk_ddp_comp *comp); 78 void (*stop)(struct mtk_ddp_comp *comp);
79 void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc); 79 void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
80 void (*disable_vblank)(struct mtk_ddp_comp *comp); 80 void (*disable_vblank)(struct mtk_ddp_comp *comp);
81 unsigned int (*layer_nr)(struct mtk_ddp_comp *comp);
81 void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx); 82 void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx);
82 void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx); 83 void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx);
83 void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx, 84 void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx,
@@ -128,6 +129,14 @@ static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
128 comp->funcs->disable_vblank(comp); 129 comp->funcs->disable_vblank(comp);
129} 130}
130 131
132static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
133{
134 if (comp->funcs && comp->funcs->layer_nr)
135 return comp->funcs->layer_nr(comp);
136
137 return 0;
138}
139
131static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp, 140static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp,
132 unsigned int idx) 141 unsigned int idx)
133{ 142{
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 39721119713b..47ec604289b7 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -381,7 +381,7 @@ static int mtk_drm_bind(struct device *dev)
381err_deinit: 381err_deinit:
382 mtk_drm_kms_deinit(drm); 382 mtk_drm_kms_deinit(drm);
383err_free: 383err_free:
384 drm_dev_unref(drm); 384 drm_dev_put(drm);
385 return ret; 385 return ret;
386} 386}
387 387
@@ -390,7 +390,7 @@ static void mtk_drm_unbind(struct device *dev)
390 struct mtk_drm_private *private = dev_get_drvdata(dev); 390 struct mtk_drm_private *private = dev_get_drvdata(dev);
391 391
392 drm_dev_unregister(private->drm); 392 drm_dev_unregister(private->drm);
393 drm_dev_unref(private->drm); 393 drm_dev_put(private->drm);
394 private->drm = NULL; 394 private->drm = NULL;
395} 395}
396 396
@@ -564,7 +564,7 @@ static int mtk_drm_remove(struct platform_device *pdev)
564 564
565 drm_dev_unregister(drm); 565 drm_dev_unregister(drm);
566 mtk_drm_kms_deinit(drm); 566 mtk_drm_kms_deinit(drm);
567 drm_dev_unref(drm); 567 drm_dev_put(drm);
568 568
569 component_master_del(&pdev->dev, &mtk_drm_ops); 569 component_master_del(&pdev->dev, &mtk_drm_ops);
570 pm_runtime_disable(&pdev->dev); 570 pm_runtime_disable(&pdev->dev);
@@ -580,29 +580,24 @@ static int mtk_drm_sys_suspend(struct device *dev)
580{ 580{
581 struct mtk_drm_private *private = dev_get_drvdata(dev); 581 struct mtk_drm_private *private = dev_get_drvdata(dev);
582 struct drm_device *drm = private->drm; 582 struct drm_device *drm = private->drm;
583 int ret;
583 584
584 drm_kms_helper_poll_disable(drm); 585 ret = drm_mode_config_helper_suspend(drm);
585
586 private->suspend_state = drm_atomic_helper_suspend(drm);
587 if (IS_ERR(private->suspend_state)) {
588 drm_kms_helper_poll_enable(drm);
589 return PTR_ERR(private->suspend_state);
590 }
591
592 DRM_DEBUG_DRIVER("mtk_drm_sys_suspend\n"); 586 DRM_DEBUG_DRIVER("mtk_drm_sys_suspend\n");
593 return 0; 587
588 return ret;
594} 589}
595 590
596static int mtk_drm_sys_resume(struct device *dev) 591static int mtk_drm_sys_resume(struct device *dev)
597{ 592{
598 struct mtk_drm_private *private = dev_get_drvdata(dev); 593 struct mtk_drm_private *private = dev_get_drvdata(dev);
599 struct drm_device *drm = private->drm; 594 struct drm_device *drm = private->drm;
595 int ret;
600 596
601 drm_atomic_helper_resume(drm, private->suspend_state); 597 ret = drm_mode_config_helper_resume(drm);
602 drm_kms_helper_poll_enable(drm);
603
604 DRM_DEBUG_DRIVER("mtk_drm_sys_resume\n"); 598 DRM_DEBUG_DRIVER("mtk_drm_sys_resume\n");
605 return 0; 599
600 return ret;
606} 601}
607#endif 602#endif
608 603
diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c b/drivers/gpu/drm/nouveau/dispnv50/disp.c
index 8412119bd940..5691dfa1db6f 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
@@ -1123,17 +1123,21 @@ nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state)
1123 int ret; 1123 int ret;
1124 1124
1125 if (dpcd >= 0x12) { 1125 if (dpcd >= 0x12) {
1126 ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CTRL, &dpcd); 1126 /* Even if we're enabling MST, start with disabling the
1127 * branching unit to clear any sink-side MST topology state
1128 * that wasn't set by us
1129 */
1130 ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, 0);
1127 if (ret < 0) 1131 if (ret < 0)
1128 return ret; 1132 return ret;
1129 1133
1130 dpcd &= ~DP_MST_EN; 1134 if (state) {
1131 if (state) 1135 /* Now, start initializing */
1132 dpcd |= DP_MST_EN; 1136 ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL,
1133 1137 DP_MST_EN);
1134 ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, dpcd); 1138 if (ret < 0)
1135 if (ret < 0) 1139 return ret;
1136 return ret; 1140 }
1137 } 1141 }
1138 1142
1139 return nvif_mthd(disp, 0, &args, sizeof(args)); 1143 return nvif_mthd(disp, 0, &args, sizeof(args));
@@ -1142,31 +1146,58 @@ nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state)
1142int 1146int
1143nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow) 1147nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow)
1144{ 1148{
1145 int ret, state = 0; 1149 struct drm_dp_aux *aux;
1150 int ret;
1151 bool old_state, new_state;
1152 u8 mstm_ctrl;
1146 1153
1147 if (!mstm) 1154 if (!mstm)
1148 return 0; 1155 return 0;
1149 1156
1150 if (dpcd[0] >= 0x12) { 1157 mutex_lock(&mstm->mgr.lock);
1151 ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CAP, &dpcd[1]); 1158
1159 old_state = mstm->mgr.mst_state;
1160 new_state = old_state;
1161 aux = mstm->mgr.aux;
1162
1163 if (old_state) {
1164 /* Just check that the MST hub is still as we expect it */
1165 ret = drm_dp_dpcd_readb(aux, DP_MSTM_CTRL, &mstm_ctrl);
1166 if (ret < 0 || !(mstm_ctrl & DP_MST_EN)) {
1167 DRM_DEBUG_KMS("Hub gone, disabling MST topology\n");
1168 new_state = false;
1169 }
1170 } else if (dpcd[0] >= 0x12) {
1171 ret = drm_dp_dpcd_readb(aux, DP_MSTM_CAP, &dpcd[1]);
1152 if (ret < 0) 1172 if (ret < 0)
1153 return ret; 1173 goto probe_error;
1154 1174
1155 if (!(dpcd[1] & DP_MST_CAP)) 1175 if (!(dpcd[1] & DP_MST_CAP))
1156 dpcd[0] = 0x11; 1176 dpcd[0] = 0x11;
1157 else 1177 else
1158 state = allow; 1178 new_state = allow;
1179 }
1180
1181 if (new_state == old_state) {
1182 mutex_unlock(&mstm->mgr.lock);
1183 return new_state;
1159 } 1184 }
1160 1185
1161 ret = nv50_mstm_enable(mstm, dpcd[0], state); 1186 ret = nv50_mstm_enable(mstm, dpcd[0], new_state);
1162 if (ret) 1187 if (ret)
1163 return ret; 1188 goto probe_error;
1189
1190 mutex_unlock(&mstm->mgr.lock);
1164 1191
1165 ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, state); 1192 ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, new_state);
1166 if (ret) 1193 if (ret)
1167 return nv50_mstm_enable(mstm, dpcd[0], 0); 1194 return nv50_mstm_enable(mstm, dpcd[0], 0);
1168 1195
1169 return mstm->mgr.mst_state; 1196 return new_state;
1197
1198probe_error:
1199 mutex_unlock(&mstm->mgr.lock);
1200 return ret;
1170} 1201}
1171 1202
1172static void 1203static void
@@ -2074,7 +2105,7 @@ nv50_disp_atomic_state_alloc(struct drm_device *dev)
2074static const struct drm_mode_config_funcs 2105static const struct drm_mode_config_funcs
2075nv50_disp_func = { 2106nv50_disp_func = {
2076 .fb_create = nouveau_user_framebuffer_create, 2107 .fb_create = nouveau_user_framebuffer_create,
2077 .output_poll_changed = drm_fb_helper_output_poll_changed, 2108 .output_poll_changed = nouveau_fbcon_output_poll_changed,
2078 .atomic_check = nv50_disp_atomic_check, 2109 .atomic_check = nv50_disp_atomic_check,
2079 .atomic_commit = nv50_disp_atomic_commit, 2110 .atomic_commit = nv50_disp_atomic_commit,
2080 .atomic_state_alloc = nv50_disp_atomic_state_alloc, 2111 .atomic_state_alloc = nv50_disp_atomic_state_alloc,
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 51932c72334e..247f72cc4d10 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -409,59 +409,45 @@ static struct nouveau_encoder *
409nouveau_connector_ddc_detect(struct drm_connector *connector) 409nouveau_connector_ddc_detect(struct drm_connector *connector)
410{ 410{
411 struct drm_device *dev = connector->dev; 411 struct drm_device *dev = connector->dev;
412 struct nouveau_connector *nv_connector = nouveau_connector(connector); 412 struct nouveau_encoder *nv_encoder = NULL, *found = NULL;
413 struct nouveau_drm *drm = nouveau_drm(dev);
414 struct nvkm_gpio *gpio = nvxx_gpio(&drm->client.device);
415 struct nouveau_encoder *nv_encoder = NULL;
416 struct drm_encoder *encoder; 413 struct drm_encoder *encoder;
417 int i, panel = -ENODEV; 414 int i, ret;
418 415 bool switcheroo_ddc = false;
419 /* eDP panels need powering on by us (if the VBIOS doesn't default it
420 * to on) before doing any AUX channel transactions. LVDS panel power
421 * is handled by the SOR itself, and not required for LVDS DDC.
422 */
423 if (nv_connector->type == DCB_CONNECTOR_eDP) {
424 panel = nvkm_gpio_get(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff);
425 if (panel == 0) {
426 nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 1);
427 msleep(300);
428 }
429 }
430 416
431 drm_connector_for_each_possible_encoder(connector, encoder, i) { 417 drm_connector_for_each_possible_encoder(connector, encoder, i) {
432 nv_encoder = nouveau_encoder(encoder); 418 nv_encoder = nouveau_encoder(encoder);
433 419
434 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) { 420 switch (nv_encoder->dcb->type) {
435 int ret = nouveau_dp_detect(nv_encoder); 421 case DCB_OUTPUT_DP:
422 ret = nouveau_dp_detect(nv_encoder);
436 if (ret == NOUVEAU_DP_MST) 423 if (ret == NOUVEAU_DP_MST)
437 return NULL; 424 return NULL;
438 if (ret == NOUVEAU_DP_SST) 425 else if (ret == NOUVEAU_DP_SST)
439 break; 426 found = nv_encoder;
440 } else 427
441 if ((vga_switcheroo_handler_flags() & 428 break;
442 VGA_SWITCHEROO_CAN_SWITCH_DDC) && 429 case DCB_OUTPUT_LVDS:
443 nv_encoder->dcb->type == DCB_OUTPUT_LVDS && 430 switcheroo_ddc = !!(vga_switcheroo_handler_flags() &
444 nv_encoder->i2c) { 431 VGA_SWITCHEROO_CAN_SWITCH_DDC);
445 int ret; 432 /* fall-through */
446 vga_switcheroo_lock_ddc(dev->pdev); 433 default:
447 ret = nvkm_probe_i2c(nv_encoder->i2c, 0x50); 434 if (!nv_encoder->i2c)
448 vga_switcheroo_unlock_ddc(dev->pdev);
449 if (ret)
450 break; 435 break;
451 } else 436
452 if (nv_encoder->i2c) { 437 if (switcheroo_ddc)
438 vga_switcheroo_lock_ddc(dev->pdev);
453 if (nvkm_probe_i2c(nv_encoder->i2c, 0x50)) 439 if (nvkm_probe_i2c(nv_encoder->i2c, 0x50))
454 break; 440 found = nv_encoder;
441 if (switcheroo_ddc)
442 vga_switcheroo_unlock_ddc(dev->pdev);
443
444 break;
455 } 445 }
446 if (found)
447 break;
456 } 448 }
457 449
458 /* eDP panel not detected, restore panel power GPIO to previous 450 return found;
459 * state to avoid confusing the SOR for other output types.
460 */
461 if (!nv_encoder && panel == 0)
462 nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, panel);
463
464 return nv_encoder;
465} 451}
466 452
467static struct nouveau_encoder * 453static struct nouveau_encoder *
@@ -555,12 +541,16 @@ nouveau_connector_detect(struct drm_connector *connector, bool force)
555 nv_connector->edid = NULL; 541 nv_connector->edid = NULL;
556 } 542 }
557 543
558 /* Outputs are only polled while runtime active, so acquiring a 544 /* Outputs are only polled while runtime active, so resuming the
559 * runtime PM ref here is unnecessary (and would deadlock upon 545 * device here is unnecessary (and would deadlock upon runtime suspend
560 * runtime suspend because it waits for polling to finish). 546 * because it waits for polling to finish). We do however, want to
547 * prevent the autosuspend timer from elapsing during this operation
548 * if possible.
561 */ 549 */
562 if (!drm_kms_helper_is_poll_worker()) { 550 if (drm_kms_helper_is_poll_worker()) {
563 ret = pm_runtime_get_sync(connector->dev->dev); 551 pm_runtime_get_noresume(dev->dev);
552 } else {
553 ret = pm_runtime_get_sync(dev->dev);
564 if (ret < 0 && ret != -EACCES) 554 if (ret < 0 && ret != -EACCES)
565 return conn_status; 555 return conn_status;
566 } 556 }
@@ -638,10 +628,8 @@ detect_analog:
638 628
639 out: 629 out:
640 630
641 if (!drm_kms_helper_is_poll_worker()) { 631 pm_runtime_mark_last_busy(dev->dev);
642 pm_runtime_mark_last_busy(connector->dev->dev); 632 pm_runtime_put_autosuspend(dev->dev);
643 pm_runtime_put_autosuspend(connector->dev->dev);
644 }
645 633
646 return conn_status; 634 return conn_status;
647} 635}
@@ -1105,6 +1093,26 @@ nouveau_connector_hotplug(struct nvif_notify *notify)
1105 const struct nvif_notify_conn_rep_v0 *rep = notify->data; 1093 const struct nvif_notify_conn_rep_v0 *rep = notify->data;
1106 const char *name = connector->name; 1094 const char *name = connector->name;
1107 struct nouveau_encoder *nv_encoder; 1095 struct nouveau_encoder *nv_encoder;
1096 int ret;
1097
1098 ret = pm_runtime_get(drm->dev->dev);
1099 if (ret == 0) {
1100 /* We can't block here if there's a pending PM request
1101 * running, as we'll deadlock nouveau_display_fini() when it
1102 * calls nvif_put() on our nvif_notify struct. So, simply
1103 * defer the hotplug event until the device finishes resuming
1104 */
1105 NV_DEBUG(drm, "Deferring HPD on %s until runtime resume\n",
1106 name);
1107 schedule_work(&drm->hpd_work);
1108
1109 pm_runtime_put_noidle(drm->dev->dev);
1110 return NVIF_NOTIFY_KEEP;
1111 } else if (ret != 1 && ret != -EACCES) {
1112 NV_WARN(drm, "HPD on %s dropped due to RPM failure: %d\n",
1113 name, ret);
1114 return NVIF_NOTIFY_DROP;
1115 }
1108 1116
1109 if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) { 1117 if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) {
1110 NV_DEBUG(drm, "service %s\n", name); 1118 NV_DEBUG(drm, "service %s\n", name);
@@ -1122,6 +1130,8 @@ nouveau_connector_hotplug(struct nvif_notify *notify)
1122 drm_helper_hpd_irq_event(connector->dev); 1130 drm_helper_hpd_irq_event(connector->dev);
1123 } 1131 }
1124 1132
1133 pm_runtime_mark_last_busy(drm->dev->dev);
1134 pm_runtime_put_autosuspend(drm->dev->dev);
1125 return NVIF_NOTIFY_KEEP; 1135 return NVIF_NOTIFY_KEEP;
1126} 1136}
1127 1137
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c
index 139368b31916..540c0cbbfcee 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -293,7 +293,7 @@ nouveau_user_framebuffer_create(struct drm_device *dev,
293 293
294static const struct drm_mode_config_funcs nouveau_mode_config_funcs = { 294static const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
295 .fb_create = nouveau_user_framebuffer_create, 295 .fb_create = nouveau_user_framebuffer_create,
296 .output_poll_changed = drm_fb_helper_output_poll_changed, 296 .output_poll_changed = nouveau_fbcon_output_poll_changed,
297}; 297};
298 298
299 299
@@ -355,8 +355,6 @@ nouveau_display_hpd_work(struct work_struct *work)
355 pm_runtime_get_sync(drm->dev->dev); 355 pm_runtime_get_sync(drm->dev->dev);
356 356
357 drm_helper_hpd_irq_event(drm->dev); 357 drm_helper_hpd_irq_event(drm->dev);
358 /* enable polling for external displays */
359 drm_kms_helper_poll_enable(drm->dev);
360 358
361 pm_runtime_mark_last_busy(drm->dev->dev); 359 pm_runtime_mark_last_busy(drm->dev->dev);
362 pm_runtime_put_sync(drm->dev->dev); 360 pm_runtime_put_sync(drm->dev->dev);
@@ -379,15 +377,29 @@ nouveau_display_acpi_ntfy(struct notifier_block *nb, unsigned long val,
379{ 377{
380 struct nouveau_drm *drm = container_of(nb, typeof(*drm), acpi_nb); 378 struct nouveau_drm *drm = container_of(nb, typeof(*drm), acpi_nb);
381 struct acpi_bus_event *info = data; 379 struct acpi_bus_event *info = data;
380 int ret;
382 381
383 if (!strcmp(info->device_class, ACPI_VIDEO_CLASS)) { 382 if (!strcmp(info->device_class, ACPI_VIDEO_CLASS)) {
384 if (info->type == ACPI_VIDEO_NOTIFY_PROBE) { 383 if (info->type == ACPI_VIDEO_NOTIFY_PROBE) {
385 /* 384 ret = pm_runtime_get(drm->dev->dev);
386 * This may be the only indication we receive of a 385 if (ret == 1 || ret == -EACCES) {
387 * connector hotplug on a runtime suspended GPU, 386 /* If the GPU is already awake, or in a state
388 * schedule hpd_work to check. 387 * where we can't wake it up, it can handle
389 */ 388 * it's own hotplug events.
390 schedule_work(&drm->hpd_work); 389 */
390 pm_runtime_put_autosuspend(drm->dev->dev);
391 } else if (ret == 0) {
392 /* This may be the only indication we receive
393 * of a connector hotplug on a runtime
394 * suspended GPU, schedule hpd_work to check.
395 */
396 NV_DEBUG(drm, "ACPI requested connector reprobe\n");
397 schedule_work(&drm->hpd_work);
398 pm_runtime_put_noidle(drm->dev->dev);
399 } else {
400 NV_WARN(drm, "Dropped ACPI reprobe event due to RPM error: %d\n",
401 ret);
402 }
391 403
392 /* acpi-video should not generate keypresses for this */ 404 /* acpi-video should not generate keypresses for this */
393 return NOTIFY_BAD; 405 return NOTIFY_BAD;
@@ -411,6 +423,11 @@ nouveau_display_init(struct drm_device *dev)
411 if (ret) 423 if (ret)
412 return ret; 424 return ret;
413 425
426 /* enable connector detection and polling for connectors without HPD
427 * support
428 */
429 drm_kms_helper_poll_enable(dev);
430
414 /* enable hotplug interrupts */ 431 /* enable hotplug interrupts */
415 drm_connector_list_iter_begin(dev, &conn_iter); 432 drm_connector_list_iter_begin(dev, &conn_iter);
416 nouveau_for_each_non_mst_connector_iter(connector, &conn_iter) { 433 nouveau_for_each_non_mst_connector_iter(connector, &conn_iter) {
@@ -425,7 +442,7 @@ nouveau_display_init(struct drm_device *dev)
425} 442}
426 443
427void 444void
428nouveau_display_fini(struct drm_device *dev, bool suspend) 445nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime)
429{ 446{
430 struct nouveau_display *disp = nouveau_display(dev); 447 struct nouveau_display *disp = nouveau_display(dev);
431 struct nouveau_drm *drm = nouveau_drm(dev); 448 struct nouveau_drm *drm = nouveau_drm(dev);
@@ -450,6 +467,9 @@ nouveau_display_fini(struct drm_device *dev, bool suspend)
450 } 467 }
451 drm_connector_list_iter_end(&conn_iter); 468 drm_connector_list_iter_end(&conn_iter);
452 469
470 if (!runtime)
471 cancel_work_sync(&drm->hpd_work);
472
453 drm_kms_helper_poll_disable(dev); 473 drm_kms_helper_poll_disable(dev);
454 disp->fini(dev); 474 disp->fini(dev);
455} 475}
@@ -618,11 +638,11 @@ nouveau_display_suspend(struct drm_device *dev, bool runtime)
618 } 638 }
619 } 639 }
620 640
621 nouveau_display_fini(dev, true); 641 nouveau_display_fini(dev, true, runtime);
622 return 0; 642 return 0;
623 } 643 }
624 644
625 nouveau_display_fini(dev, true); 645 nouveau_display_fini(dev, true, runtime);
626 646
627 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 647 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
628 struct nouveau_framebuffer *nouveau_fb; 648 struct nouveau_framebuffer *nouveau_fb;
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.h b/drivers/gpu/drm/nouveau/nouveau_display.h
index 54aa7c3fa42d..ff92b54ce448 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.h
+++ b/drivers/gpu/drm/nouveau/nouveau_display.h
@@ -62,7 +62,7 @@ nouveau_display(struct drm_device *dev)
62int nouveau_display_create(struct drm_device *dev); 62int nouveau_display_create(struct drm_device *dev);
63void nouveau_display_destroy(struct drm_device *dev); 63void nouveau_display_destroy(struct drm_device *dev);
64int nouveau_display_init(struct drm_device *dev); 64int nouveau_display_init(struct drm_device *dev);
65void nouveau_display_fini(struct drm_device *dev, bool suspend); 65void nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime);
66int nouveau_display_suspend(struct drm_device *dev, bool runtime); 66int nouveau_display_suspend(struct drm_device *dev, bool runtime);
67void nouveau_display_resume(struct drm_device *dev, bool runtime); 67void nouveau_display_resume(struct drm_device *dev, bool runtime);
68int nouveau_display_vblank_enable(struct drm_device *, unsigned int); 68int nouveau_display_vblank_enable(struct drm_device *, unsigned int);
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index c7ec86d6c3c9..74d2283f2c28 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -230,7 +230,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
230 mutex_unlock(&drm->master.lock); 230 mutex_unlock(&drm->master.lock);
231 } 231 }
232 if (ret) { 232 if (ret) {
233 NV_ERROR(drm, "Client allocation failed: %d\n", ret); 233 NV_PRINTK(err, cli, "Client allocation failed: %d\n", ret);
234 goto done; 234 goto done;
235 } 235 }
236 236
@@ -240,37 +240,37 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
240 }, sizeof(struct nv_device_v0), 240 }, sizeof(struct nv_device_v0),
241 &cli->device); 241 &cli->device);
242 if (ret) { 242 if (ret) {
243 NV_ERROR(drm, "Device allocation failed: %d\n", ret); 243 NV_PRINTK(err, cli, "Device allocation failed: %d\n", ret);
244 goto done; 244 goto done;
245 } 245 }
246 246
247 ret = nvif_mclass(&cli->device.object, mmus); 247 ret = nvif_mclass(&cli->device.object, mmus);
248 if (ret < 0) { 248 if (ret < 0) {
249 NV_ERROR(drm, "No supported MMU class\n"); 249 NV_PRINTK(err, cli, "No supported MMU class\n");
250 goto done; 250 goto done;
251 } 251 }
252 252
253 ret = nvif_mmu_init(&cli->device.object, mmus[ret].oclass, &cli->mmu); 253 ret = nvif_mmu_init(&cli->device.object, mmus[ret].oclass, &cli->mmu);
254 if (ret) { 254 if (ret) {
255 NV_ERROR(drm, "MMU allocation failed: %d\n", ret); 255 NV_PRINTK(err, cli, "MMU allocation failed: %d\n", ret);
256 goto done; 256 goto done;
257 } 257 }
258 258
259 ret = nvif_mclass(&cli->mmu.object, vmms); 259 ret = nvif_mclass(&cli->mmu.object, vmms);
260 if (ret < 0) { 260 if (ret < 0) {
261 NV_ERROR(drm, "No supported VMM class\n"); 261 NV_PRINTK(err, cli, "No supported VMM class\n");
262 goto done; 262 goto done;
263 } 263 }
264 264
265 ret = nouveau_vmm_init(cli, vmms[ret].oclass, &cli->vmm); 265 ret = nouveau_vmm_init(cli, vmms[ret].oclass, &cli->vmm);
266 if (ret) { 266 if (ret) {
267 NV_ERROR(drm, "VMM allocation failed: %d\n", ret); 267 NV_PRINTK(err, cli, "VMM allocation failed: %d\n", ret);
268 goto done; 268 goto done;
269 } 269 }
270 270
271 ret = nvif_mclass(&cli->mmu.object, mems); 271 ret = nvif_mclass(&cli->mmu.object, mems);
272 if (ret < 0) { 272 if (ret < 0) {
273 NV_ERROR(drm, "No supported MEM class\n"); 273 NV_PRINTK(err, cli, "No supported MEM class\n");
274 goto done; 274 goto done;
275 } 275 }
276 276
@@ -592,10 +592,8 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags)
592 pm_runtime_allow(dev->dev); 592 pm_runtime_allow(dev->dev);
593 pm_runtime_mark_last_busy(dev->dev); 593 pm_runtime_mark_last_busy(dev->dev);
594 pm_runtime_put(dev->dev); 594 pm_runtime_put(dev->dev);
595 } else {
596 /* enable polling for external displays */
597 drm_kms_helper_poll_enable(dev);
598 } 595 }
596
599 return 0; 597 return 0;
600 598
601fail_dispinit: 599fail_dispinit:
@@ -629,7 +627,7 @@ nouveau_drm_unload(struct drm_device *dev)
629 nouveau_debugfs_fini(drm); 627 nouveau_debugfs_fini(drm);
630 628
631 if (dev->mode_config.num_crtc) 629 if (dev->mode_config.num_crtc)
632 nouveau_display_fini(dev, false); 630 nouveau_display_fini(dev, false, false);
633 nouveau_display_destroy(dev); 631 nouveau_display_destroy(dev);
634 632
635 nouveau_bios_takedown(dev); 633 nouveau_bios_takedown(dev);
@@ -835,7 +833,6 @@ nouveau_pmops_runtime_suspend(struct device *dev)
835 return -EBUSY; 833 return -EBUSY;
836 } 834 }
837 835
838 drm_kms_helper_poll_disable(drm_dev);
839 nouveau_switcheroo_optimus_dsm(); 836 nouveau_switcheroo_optimus_dsm();
840 ret = nouveau_do_suspend(drm_dev, true); 837 ret = nouveau_do_suspend(drm_dev, true);
841 pci_save_state(pdev); 838 pci_save_state(pdev);
diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
index 844498c4267c..0f64c0a1d4b3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
@@ -466,6 +466,7 @@ nouveau_fbcon_set_suspend_work(struct work_struct *work)
466 console_unlock(); 466 console_unlock();
467 467
468 if (state == FBINFO_STATE_RUNNING) { 468 if (state == FBINFO_STATE_RUNNING) {
469 nouveau_fbcon_hotplug_resume(drm->fbcon);
469 pm_runtime_mark_last_busy(drm->dev->dev); 470 pm_runtime_mark_last_busy(drm->dev->dev);
470 pm_runtime_put_sync(drm->dev->dev); 471 pm_runtime_put_sync(drm->dev->dev);
471 } 472 }
@@ -487,6 +488,61 @@ nouveau_fbcon_set_suspend(struct drm_device *dev, int state)
487 schedule_work(&drm->fbcon_work); 488 schedule_work(&drm->fbcon_work);
488} 489}
489 490
491void
492nouveau_fbcon_output_poll_changed(struct drm_device *dev)
493{
494 struct nouveau_drm *drm = nouveau_drm(dev);
495 struct nouveau_fbdev *fbcon = drm->fbcon;
496 int ret;
497
498 if (!fbcon)
499 return;
500
501 mutex_lock(&fbcon->hotplug_lock);
502
503 ret = pm_runtime_get(dev->dev);
504 if (ret == 1 || ret == -EACCES) {
505 drm_fb_helper_hotplug_event(&fbcon->helper);
506
507 pm_runtime_mark_last_busy(dev->dev);
508 pm_runtime_put_autosuspend(dev->dev);
509 } else if (ret == 0) {
510 /* If the GPU was already in the process of suspending before
511 * this event happened, then we can't block here as we'll
512 * deadlock the runtime pmops since they wait for us to
513 * finish. So, just defer this event for when we runtime
514 * resume again. It will be handled by fbcon_work.
515 */
516 NV_DEBUG(drm, "fbcon HPD event deferred until runtime resume\n");
517 fbcon->hotplug_waiting = true;
518 pm_runtime_put_noidle(drm->dev->dev);
519 } else {
520 DRM_WARN("fbcon HPD event lost due to RPM failure: %d\n",
521 ret);
522 }
523
524 mutex_unlock(&fbcon->hotplug_lock);
525}
526
527void
528nouveau_fbcon_hotplug_resume(struct nouveau_fbdev *fbcon)
529{
530 struct nouveau_drm *drm;
531
532 if (!fbcon)
533 return;
534 drm = nouveau_drm(fbcon->helper.dev);
535
536 mutex_lock(&fbcon->hotplug_lock);
537 if (fbcon->hotplug_waiting) {
538 fbcon->hotplug_waiting = false;
539
540 NV_DEBUG(drm, "Handling deferred fbcon HPD events\n");
541 drm_fb_helper_hotplug_event(&fbcon->helper);
542 }
543 mutex_unlock(&fbcon->hotplug_lock);
544}
545
490int 546int
491nouveau_fbcon_init(struct drm_device *dev) 547nouveau_fbcon_init(struct drm_device *dev)
492{ 548{
@@ -505,6 +561,7 @@ nouveau_fbcon_init(struct drm_device *dev)
505 561
506 drm->fbcon = fbcon; 562 drm->fbcon = fbcon;
507 INIT_WORK(&drm->fbcon_work, nouveau_fbcon_set_suspend_work); 563 INIT_WORK(&drm->fbcon_work, nouveau_fbcon_set_suspend_work);
564 mutex_init(&fbcon->hotplug_lock);
508 565
509 drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs); 566 drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs);
510 567
diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.h b/drivers/gpu/drm/nouveau/nouveau_fbcon.h
index a6f192ea3fa6..db9d52047ef8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fbcon.h
+++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.h
@@ -41,6 +41,9 @@ struct nouveau_fbdev {
41 struct nvif_object gdi; 41 struct nvif_object gdi;
42 struct nvif_object blit; 42 struct nvif_object blit;
43 struct nvif_object twod; 43 struct nvif_object twod;
44
45 struct mutex hotplug_lock;
46 bool hotplug_waiting;
44}; 47};
45 48
46void nouveau_fbcon_restore(void); 49void nouveau_fbcon_restore(void);
@@ -68,6 +71,8 @@ void nouveau_fbcon_set_suspend(struct drm_device *dev, int state);
68void nouveau_fbcon_accel_save_disable(struct drm_device *dev); 71void nouveau_fbcon_accel_save_disable(struct drm_device *dev);
69void nouveau_fbcon_accel_restore(struct drm_device *dev); 72void nouveau_fbcon_accel_restore(struct drm_device *dev);
70 73
74void nouveau_fbcon_output_poll_changed(struct drm_device *dev);
75void nouveau_fbcon_hotplug_resume(struct nouveau_fbdev *fbcon);
71extern int nouveau_nofbaccel; 76extern int nouveau_nofbaccel;
72 77
73#endif /* __NV50_FBCON_H__ */ 78#endif /* __NV50_FBCON_H__ */
diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
index 3da5a4305aa4..8f1ce4833230 100644
--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
@@ -46,12 +46,10 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev,
46 pr_err("VGA switcheroo: switched nouveau on\n"); 46 pr_err("VGA switcheroo: switched nouveau on\n");
47 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; 47 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
48 nouveau_pmops_resume(&pdev->dev); 48 nouveau_pmops_resume(&pdev->dev);
49 drm_kms_helper_poll_enable(dev);
50 dev->switch_power_state = DRM_SWITCH_POWER_ON; 49 dev->switch_power_state = DRM_SWITCH_POWER_ON;
51 } else { 50 } else {
52 pr_err("VGA switcheroo: switched nouveau off\n"); 51 pr_err("VGA switcheroo: switched nouveau off\n");
53 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; 52 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
54 drm_kms_helper_poll_disable(dev);
55 nouveau_switcheroo_optimus_dsm(); 53 nouveau_switcheroo_optimus_dsm();
56 nouveau_pmops_suspend(&pdev->dev); 54 nouveau_pmops_suspend(&pdev->dev);
57 dev->switch_power_state = DRM_SWITCH_POWER_OFF; 55 dev->switch_power_state = DRM_SWITCH_POWER_OFF;
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/base.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/base.c
index 32fa94a9773f..cbd33e87b799 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/base.c
@@ -275,6 +275,7 @@ nvkm_disp_oneinit(struct nvkm_engine *engine)
275 struct nvkm_outp *outp, *outt, *pair; 275 struct nvkm_outp *outp, *outt, *pair;
276 struct nvkm_conn *conn; 276 struct nvkm_conn *conn;
277 struct nvkm_head *head; 277 struct nvkm_head *head;
278 struct nvkm_ior *ior;
278 struct nvbios_connE connE; 279 struct nvbios_connE connE;
279 struct dcb_output dcbE; 280 struct dcb_output dcbE;
280 u8 hpd = 0, ver, hdr; 281 u8 hpd = 0, ver, hdr;
@@ -399,6 +400,19 @@ nvkm_disp_oneinit(struct nvkm_engine *engine)
399 return ret; 400 return ret;
400 } 401 }
401 402
403 /* Enforce identity-mapped SOR assignment for panels, which have
404 * certain bits (ie. backlight controls) wired to a specific SOR.
405 */
406 list_for_each_entry(outp, &disp->outp, head) {
407 if (outp->conn->info.type == DCB_CONNECTOR_LVDS ||
408 outp->conn->info.type == DCB_CONNECTOR_eDP) {
409 ior = nvkm_ior_find(disp, SOR, ffs(outp->info.or) - 1);
410 if (!WARN_ON(!ior))
411 ior->identity = true;
412 outp->identity = true;
413 }
414 }
415
402 i = 0; 416 i = 0;
403 list_for_each_entry(head, &disp->head, head) 417 list_for_each_entry(head, &disp->head, head)
404 i = max(i, head->id + 1); 418 i = max(i, head->id + 1);
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/dp.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/dp.c
index 7c5bed29ffef..5f301e632599 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/dp.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/dp.c
@@ -28,6 +28,7 @@
28 28
29#include <subdev/bios.h> 29#include <subdev/bios.h>
30#include <subdev/bios/init.h> 30#include <subdev/bios/init.h>
31#include <subdev/gpio.h>
31#include <subdev/i2c.h> 32#include <subdev/i2c.h>
32 33
33#include <nvif/event.h> 34#include <nvif/event.h>
@@ -412,14 +413,10 @@ nvkm_dp_train(struct nvkm_dp *dp, u32 dataKBps)
412} 413}
413 414
414static void 415static void
415nvkm_dp_release(struct nvkm_outp *outp, struct nvkm_ior *ior) 416nvkm_dp_disable(struct nvkm_outp *outp, struct nvkm_ior *ior)
416{ 417{
417 struct nvkm_dp *dp = nvkm_dp(outp); 418 struct nvkm_dp *dp = nvkm_dp(outp);
418 419
419 /* Prevent link from being retrained if sink sends an IRQ. */
420 atomic_set(&dp->lt.done, 0);
421 ior->dp.nr = 0;
422
423 /* Execute DisableLT script from DP Info Table. */ 420 /* Execute DisableLT script from DP Info Table. */
424 nvbios_init(&ior->disp->engine.subdev, dp->info.script[4], 421 nvbios_init(&ior->disp->engine.subdev, dp->info.script[4],
425 init.outp = &dp->outp.info; 422 init.outp = &dp->outp.info;
@@ -428,6 +425,16 @@ nvkm_dp_release(struct nvkm_outp *outp, struct nvkm_ior *ior)
428 ); 425 );
429} 426}
430 427
428static void
429nvkm_dp_release(struct nvkm_outp *outp)
430{
431 struct nvkm_dp *dp = nvkm_dp(outp);
432
433 /* Prevent link from being retrained if sink sends an IRQ. */
434 atomic_set(&dp->lt.done, 0);
435 dp->outp.ior->dp.nr = 0;
436}
437
431static int 438static int
432nvkm_dp_acquire(struct nvkm_outp *outp) 439nvkm_dp_acquire(struct nvkm_outp *outp)
433{ 440{
@@ -491,7 +498,7 @@ done:
491 return ret; 498 return ret;
492} 499}
493 500
494static void 501static bool
495nvkm_dp_enable(struct nvkm_dp *dp, bool enable) 502nvkm_dp_enable(struct nvkm_dp *dp, bool enable)
496{ 503{
497 struct nvkm_i2c_aux *aux = dp->aux; 504 struct nvkm_i2c_aux *aux = dp->aux;
@@ -505,7 +512,7 @@ nvkm_dp_enable(struct nvkm_dp *dp, bool enable)
505 512
506 if (!nvkm_rdaux(aux, DPCD_RC00_DPCD_REV, dp->dpcd, 513 if (!nvkm_rdaux(aux, DPCD_RC00_DPCD_REV, dp->dpcd,
507 sizeof(dp->dpcd))) 514 sizeof(dp->dpcd)))
508 return; 515 return true;
509 } 516 }
510 517
511 if (dp->present) { 518 if (dp->present) {
@@ -515,6 +522,7 @@ nvkm_dp_enable(struct nvkm_dp *dp, bool enable)
515 } 522 }
516 523
517 atomic_set(&dp->lt.done, 0); 524 atomic_set(&dp->lt.done, 0);
525 return false;
518} 526}
519 527
520static int 528static int
@@ -555,9 +563,38 @@ nvkm_dp_fini(struct nvkm_outp *outp)
555static void 563static void
556nvkm_dp_init(struct nvkm_outp *outp) 564nvkm_dp_init(struct nvkm_outp *outp)
557{ 565{
566 struct nvkm_gpio *gpio = outp->disp->engine.subdev.device->gpio;
558 struct nvkm_dp *dp = nvkm_dp(outp); 567 struct nvkm_dp *dp = nvkm_dp(outp);
568
559 nvkm_notify_put(&dp->outp.conn->hpd); 569 nvkm_notify_put(&dp->outp.conn->hpd);
560 nvkm_dp_enable(dp, true); 570
571 /* eDP panels need powering on by us (if the VBIOS doesn't default it
572 * to on) before doing any AUX channel transactions. LVDS panel power
573 * is handled by the SOR itself, and not required for LVDS DDC.
574 */
575 if (dp->outp.conn->info.type == DCB_CONNECTOR_eDP) {
576 int power = nvkm_gpio_get(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff);
577 if (power == 0)
578 nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 1);
579
580 /* We delay here unconditionally, even if already powered,
581 * because some laptop panels having a significant resume
582 * delay before the panel begins responding.
583 *
584 * This is likely a bit of a hack, but no better idea for
585 * handling this at the moment.
586 */
587 msleep(300);
588
589 /* If the eDP panel can't be detected, we need to restore
590 * the panel power GPIO to avoid breaking another output.
591 */
592 if (!nvkm_dp_enable(dp, true) && power == 0)
593 nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 0);
594 } else {
595 nvkm_dp_enable(dp, true);
596 }
597
561 nvkm_notify_get(&dp->hpd); 598 nvkm_notify_get(&dp->hpd);
562} 599}
563 600
@@ -576,6 +613,7 @@ nvkm_dp_func = {
576 .fini = nvkm_dp_fini, 613 .fini = nvkm_dp_fini,
577 .acquire = nvkm_dp_acquire, 614 .acquire = nvkm_dp_acquire,
578 .release = nvkm_dp_release, 615 .release = nvkm_dp_release,
616 .disable = nvkm_dp_disable,
579}; 617};
580 618
581static int 619static int
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h b/drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h
index e0b4e0c5704e..19911211a12a 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h
@@ -16,6 +16,7 @@ struct nvkm_ior {
16 char name[8]; 16 char name[8];
17 17
18 struct list_head head; 18 struct list_head head;
19 bool identity;
19 20
20 struct nvkm_ior_state { 21 struct nvkm_ior_state {
21 struct nvkm_outp *outp; 22 struct nvkm_outp *outp;
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
index f89c7b977aa5..def005dd5fda 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
@@ -501,11 +501,11 @@ nv50_disp_super_2_0(struct nv50_disp *disp, struct nvkm_head *head)
501 nv50_disp_super_ied_off(head, ior, 2); 501 nv50_disp_super_ied_off(head, ior, 2);
502 502
503 /* If we're shutting down the OR's only active head, execute 503 /* If we're shutting down the OR's only active head, execute
504 * the output path's release function. 504 * the output path's disable function.
505 */ 505 */
506 if (ior->arm.head == (1 << head->id)) { 506 if (ior->arm.head == (1 << head->id)) {
507 if ((outp = ior->arm.outp) && outp->func->release) 507 if ((outp = ior->arm.outp) && outp->func->disable)
508 outp->func->release(outp, ior); 508 outp->func->disable(outp, ior);
509 } 509 }
510} 510}
511 511
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c
index be9e7f8c3b23..c62030c96fba 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c
@@ -93,6 +93,8 @@ nvkm_outp_release(struct nvkm_outp *outp, u8 user)
93 if (ior) { 93 if (ior) {
94 outp->acquired &= ~user; 94 outp->acquired &= ~user;
95 if (!outp->acquired) { 95 if (!outp->acquired) {
96 if (outp->func->release && outp->ior)
97 outp->func->release(outp);
96 outp->ior->asy.outp = NULL; 98 outp->ior->asy.outp = NULL;
97 outp->ior = NULL; 99 outp->ior = NULL;
98 } 100 }
@@ -127,17 +129,26 @@ nvkm_outp_acquire(struct nvkm_outp *outp, u8 user)
127 if (proto == UNKNOWN) 129 if (proto == UNKNOWN)
128 return -ENOSYS; 130 return -ENOSYS;
129 131
132 /* Deal with panels requiring identity-mapped SOR assignment. */
133 if (outp->identity) {
134 ior = nvkm_ior_find(outp->disp, SOR, ffs(outp->info.or) - 1);
135 if (WARN_ON(!ior))
136 return -ENOSPC;
137 return nvkm_outp_acquire_ior(outp, user, ior);
138 }
139
130 /* First preference is to reuse the OR that is currently armed 140 /* First preference is to reuse the OR that is currently armed
131 * on HW, if any, in order to prevent unnecessary switching. 141 * on HW, if any, in order to prevent unnecessary switching.
132 */ 142 */
133 list_for_each_entry(ior, &outp->disp->ior, head) { 143 list_for_each_entry(ior, &outp->disp->ior, head) {
134 if (!ior->asy.outp && ior->arm.outp == outp) 144 if (!ior->identity && !ior->asy.outp && ior->arm.outp == outp)
135 return nvkm_outp_acquire_ior(outp, user, ior); 145 return nvkm_outp_acquire_ior(outp, user, ior);
136 } 146 }
137 147
138 /* Failing that, a completely unused OR is the next best thing. */ 148 /* Failing that, a completely unused OR is the next best thing. */
139 list_for_each_entry(ior, &outp->disp->ior, head) { 149 list_for_each_entry(ior, &outp->disp->ior, head) {
140 if (!ior->asy.outp && ior->type == type && !ior->arm.outp && 150 if (!ior->identity &&
151 !ior->asy.outp && ior->type == type && !ior->arm.outp &&
141 (ior->func->route.set || ior->id == __ffs(outp->info.or))) 152 (ior->func->route.set || ior->id == __ffs(outp->info.or)))
142 return nvkm_outp_acquire_ior(outp, user, ior); 153 return nvkm_outp_acquire_ior(outp, user, ior);
143 } 154 }
@@ -146,7 +157,7 @@ nvkm_outp_acquire(struct nvkm_outp *outp, u8 user)
146 * but will be released during the next modeset. 157 * but will be released during the next modeset.
147 */ 158 */
148 list_for_each_entry(ior, &outp->disp->ior, head) { 159 list_for_each_entry(ior, &outp->disp->ior, head) {
149 if (!ior->asy.outp && ior->type == type && 160 if (!ior->identity && !ior->asy.outp && ior->type == type &&
150 (ior->func->route.set || ior->id == __ffs(outp->info.or))) 161 (ior->func->route.set || ior->id == __ffs(outp->info.or)))
151 return nvkm_outp_acquire_ior(outp, user, ior); 162 return nvkm_outp_acquire_ior(outp, user, ior);
152 } 163 }
@@ -245,7 +256,6 @@ nvkm_outp_ctor(const struct nvkm_outp_func *func, struct nvkm_disp *disp,
245 outp->index = index; 256 outp->index = index;
246 outp->info = *dcbE; 257 outp->info = *dcbE;
247 outp->i2c = nvkm_i2c_bus_find(i2c, dcbE->i2c_index); 258 outp->i2c = nvkm_i2c_bus_find(i2c, dcbE->i2c_index);
248 outp->or = ffs(outp->info.or) - 1;
249 259
250 OUTP_DBG(outp, "type %02x loc %d or %d link %d con %x " 260 OUTP_DBG(outp, "type %02x loc %d or %d link %d con %x "
251 "edid %x bus %d head %x", 261 "edid %x bus %d head %x",
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.h b/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.h
index ea84d7d5741a..6c8aa5cfed9d 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.h
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.h
@@ -13,10 +13,10 @@ struct nvkm_outp {
13 struct dcb_output info; 13 struct dcb_output info;
14 14
15 struct nvkm_i2c_bus *i2c; 15 struct nvkm_i2c_bus *i2c;
16 int or;
17 16
18 struct list_head head; 17 struct list_head head;
19 struct nvkm_conn *conn; 18 struct nvkm_conn *conn;
19 bool identity;
20 20
21 /* Assembly state. */ 21 /* Assembly state. */
22#define NVKM_OUTP_PRIV 1 22#define NVKM_OUTP_PRIV 1
@@ -41,7 +41,8 @@ struct nvkm_outp_func {
41 void (*init)(struct nvkm_outp *); 41 void (*init)(struct nvkm_outp *);
42 void (*fini)(struct nvkm_outp *); 42 void (*fini)(struct nvkm_outp *);
43 int (*acquire)(struct nvkm_outp *); 43 int (*acquire)(struct nvkm_outp *);
44 void (*release)(struct nvkm_outp *, struct nvkm_ior *); 44 void (*release)(struct nvkm_outp *);
45 void (*disable)(struct nvkm_outp *, struct nvkm_ior *);
45}; 46};
46 47
47#define OUTP_MSG(o,l,f,a...) do { \ 48#define OUTP_MSG(o,l,f,a...) do { \
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm200.c b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm200.c
index b80618e35491..17235e940ca9 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm200.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm200.c
@@ -86,10 +86,8 @@ pmu_load(struct nv50_devinit *init, u8 type, bool post,
86 struct nvkm_bios *bios = subdev->device->bios; 86 struct nvkm_bios *bios = subdev->device->bios;
87 struct nvbios_pmuR pmu; 87 struct nvbios_pmuR pmu;
88 88
89 if (!nvbios_pmuRm(bios, type, &pmu)) { 89 if (!nvbios_pmuRm(bios, type, &pmu))
90 nvkm_error(subdev, "VBIOS PMU fuc %02x not found\n", type);
91 return -EINVAL; 90 return -EINVAL;
92 }
93 91
94 if (!post) 92 if (!post)
95 return 0; 93 return 0;
@@ -124,29 +122,30 @@ gm200_devinit_post(struct nvkm_devinit *base, bool post)
124 return -EINVAL; 122 return -EINVAL;
125 } 123 }
126 124
125 /* Upload DEVINIT application from VBIOS onto PMU. */
127 ret = pmu_load(init, 0x04, post, &exec, &args); 126 ret = pmu_load(init, 0x04, post, &exec, &args);
128 if (ret) 127 if (ret) {
128 nvkm_error(subdev, "VBIOS PMU/DEVINIT not found\n");
129 return ret; 129 return ret;
130 }
130 131
131 /* upload first chunk of init data */ 132 /* Upload tables required by opcodes in boot scripts. */
132 if (post) { 133 if (post) {
133 // devinit tables
134 u32 pmu = pmu_args(init, args + 0x08, 0x08); 134 u32 pmu = pmu_args(init, args + 0x08, 0x08);
135 u32 img = nvbios_rd16(bios, bit_I.offset + 0x14); 135 u32 img = nvbios_rd16(bios, bit_I.offset + 0x14);
136 u32 len = nvbios_rd16(bios, bit_I.offset + 0x16); 136 u32 len = nvbios_rd16(bios, bit_I.offset + 0x16);
137 pmu_data(init, pmu, img, len); 137 pmu_data(init, pmu, img, len);
138 } 138 }
139 139
140 /* upload second chunk of init data */ 140 /* Upload boot scripts. */
141 if (post) { 141 if (post) {
142 // devinit boot scripts
143 u32 pmu = pmu_args(init, args + 0x08, 0x10); 142 u32 pmu = pmu_args(init, args + 0x08, 0x10);
144 u32 img = nvbios_rd16(bios, bit_I.offset + 0x18); 143 u32 img = nvbios_rd16(bios, bit_I.offset + 0x18);
145 u32 len = nvbios_rd16(bios, bit_I.offset + 0x1a); 144 u32 len = nvbios_rd16(bios, bit_I.offset + 0x1a);
146 pmu_data(init, pmu, img, len); 145 pmu_data(init, pmu, img, len);
147 } 146 }
148 147
149 /* execute init tables */ 148 /* Execute DEVINIT. */
150 if (post) { 149 if (post) {
151 nvkm_wr32(device, 0x10a040, 0x00005000); 150 nvkm_wr32(device, 0x10a040, 0x00005000);
152 pmu_exec(init, exec); 151 pmu_exec(init, exec);
@@ -157,8 +156,11 @@ gm200_devinit_post(struct nvkm_devinit *base, bool post)
157 return -ETIMEDOUT; 156 return -ETIMEDOUT;
158 } 157 }
159 158
160 /* load and execute some other ucode image (bios therm?) */ 159 /* Optional: Execute PRE_OS application on PMU, which should at
161 return pmu_load(init, 0x01, post, NULL, NULL); 160 * least take care of fans until a full PMU has been loaded.
161 */
162 pmu_load(init, 0x01, post, NULL, NULL);
163 return 0;
162} 164}
163 165
164static const struct nvkm_devinit_func 166static const struct nvkm_devinit_func
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
index de269eb482dd..7459def78d50 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c
@@ -1423,7 +1423,7 @@ nvkm_vmm_get(struct nvkm_vmm *vmm, u8 page, u64 size, struct nvkm_vma **pvma)
1423void 1423void
1424nvkm_vmm_part(struct nvkm_vmm *vmm, struct nvkm_memory *inst) 1424nvkm_vmm_part(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
1425{ 1425{
1426 if (vmm->func->part && inst) { 1426 if (inst && vmm->func->part) {
1427 mutex_lock(&vmm->mutex); 1427 mutex_lock(&vmm->mutex);
1428 vmm->func->part(vmm, inst); 1428 vmm->func->part(vmm, inst);
1429 mutex_unlock(&vmm->mutex); 1429 mutex_unlock(&vmm->mutex);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index ddb1e9365a3e..b93c558dd86e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -51,51 +51,34 @@ static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man,
51{ 51{
52 struct vmwgfx_gmrid_man *gman = 52 struct vmwgfx_gmrid_man *gman =
53 (struct vmwgfx_gmrid_man *)man->priv; 53 (struct vmwgfx_gmrid_man *)man->priv;
54 int ret = 0;
55 int id; 54 int id;
56 55
57 mem->mm_node = NULL; 56 mem->mm_node = NULL;
58 57
58 id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
59 if (id < 0)
60 return id;
61
59 spin_lock(&gman->lock); 62 spin_lock(&gman->lock);
60 63
61 if (gman->max_gmr_pages > 0) { 64 if (gman->max_gmr_pages > 0) {
62 gman->used_gmr_pages += bo->num_pages; 65 gman->used_gmr_pages += bo->num_pages;
63 if (unlikely(gman->used_gmr_pages > gman->max_gmr_pages)) 66 if (unlikely(gman->used_gmr_pages > gman->max_gmr_pages))
64 goto out_err_locked; 67 goto nospace;
65 } 68 }
66 69
67 do { 70 mem->mm_node = gman;
68 spin_unlock(&gman->lock); 71 mem->start = id;
69 if (unlikely(ida_pre_get(&gman->gmr_ida, GFP_KERNEL) == 0)) { 72 mem->num_pages = bo->num_pages;
70 ret = -ENOMEM;
71 goto out_err;
72 }
73 spin_lock(&gman->lock);
74
75 ret = ida_get_new(&gman->gmr_ida, &id);
76 if (unlikely(ret == 0 && id >= gman->max_gmr_ids)) {
77 ida_remove(&gman->gmr_ida, id);
78 ret = 0;
79 goto out_err_locked;
80 }
81 } while (ret == -EAGAIN);
82
83 if (likely(ret == 0)) {
84 mem->mm_node = gman;
85 mem->start = id;
86 mem->num_pages = bo->num_pages;
87 } else
88 goto out_err_locked;
89 73
90 spin_unlock(&gman->lock); 74 spin_unlock(&gman->lock);
91 return 0; 75 return 0;
92 76
93out_err: 77nospace:
94 spin_lock(&gman->lock);
95out_err_locked:
96 gman->used_gmr_pages -= bo->num_pages; 78 gman->used_gmr_pages -= bo->num_pages;
97 spin_unlock(&gman->lock); 79 spin_unlock(&gman->lock);
98 return ret; 80 ida_free(&gman->gmr_ida, id);
81 return 0;
99} 82}
100 83
101static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man, 84static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man,
@@ -105,8 +88,8 @@ static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man,
105 (struct vmwgfx_gmrid_man *)man->priv; 88 (struct vmwgfx_gmrid_man *)man->priv;
106 89
107 if (mem->mm_node) { 90 if (mem->mm_node) {
91 ida_free(&gman->gmr_ida, mem->start);
108 spin_lock(&gman->lock); 92 spin_lock(&gman->lock);
109 ida_remove(&gman->gmr_ida, mem->start);
110 gman->used_gmr_pages -= mem->num_pages; 93 gman->used_gmr_pages -= mem->num_pages;
111 spin_unlock(&gman->lock); 94 spin_unlock(&gman->lock);
112 mem->mm_node = NULL; 95 mem->mm_node = NULL;
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 25b7bd56ae11..1cb41992aaa1 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -335,7 +335,8 @@ static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
335 struct hid_field *field, struct hid_usage *usage, 335 struct hid_field *field, struct hid_usage *usage,
336 unsigned long **bit, int *max) 336 unsigned long **bit, int *max)
337{ 337{
338 if (usage->hid == (HID_UP_CUSTOM | 0x0003)) { 338 if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
339 usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
339 /* The fn key on Apple USB keyboards */ 340 /* The fn key on Apple USB keyboards */
340 set_bit(EV_REP, hi->input->evbit); 341 set_bit(EV_REP, hi->input->evbit);
341 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN); 342 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
@@ -472,6 +473,12 @@ static const struct hid_device_id apple_devices[] = {
472 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 473 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
473 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI), 474 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
474 .driver_data = APPLE_HAS_FN }, 475 .driver_data = APPLE_HAS_FN },
476 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
477 .driver_data = APPLE_HAS_FN },
478 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
479 .driver_data = APPLE_HAS_FN },
480 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
481 .driver_data = APPLE_HAS_FN },
475 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), 482 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
476 .driver_data = APPLE_HAS_FN }, 483 .driver_data = APPLE_HAS_FN },
477 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO), 484 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 3da354af7a0a..44564f61e9cc 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1000,7 +1000,7 @@ int hid_open_report(struct hid_device *device)
1000 parser = vzalloc(sizeof(struct hid_parser)); 1000 parser = vzalloc(sizeof(struct hid_parser));
1001 if (!parser) { 1001 if (!parser) {
1002 ret = -ENOMEM; 1002 ret = -ENOMEM;
1003 goto err; 1003 goto alloc_err;
1004 } 1004 }
1005 1005
1006 parser->device = device; 1006 parser->device = device;
@@ -1039,6 +1039,7 @@ int hid_open_report(struct hid_device *device)
1039 hid_err(device, "unbalanced delimiter at end of report description\n"); 1039 hid_err(device, "unbalanced delimiter at end of report description\n");
1040 goto err; 1040 goto err;
1041 } 1041 }
1042 kfree(parser->collection_stack);
1042 vfree(parser); 1043 vfree(parser);
1043 device->status |= HID_STAT_PARSED; 1044 device->status |= HID_STAT_PARSED;
1044 return 0; 1045 return 0;
@@ -1047,6 +1048,8 @@ int hid_open_report(struct hid_device *device)
1047 1048
1048 hid_err(device, "item fetching failed at offset %d\n", (int)(end - start)); 1049 hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
1049err: 1050err:
1051 kfree(parser->collection_stack);
1052alloc_err:
1050 vfree(parser); 1053 vfree(parser);
1051 hid_close_report(device); 1054 hid_close_report(device);
1052 return ret; 1055 return ret;
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..5146ee029db4 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,6 +88,7 @@
88#define USB_DEVICE_ID_ANTON_TOUCH_PAD 0x3101 88#define USB_DEVICE_ID_ANTON_TOUCH_PAD 0x3101
89 89
90#define USB_VENDOR_ID_APPLE 0x05ac 90#define USB_VENDOR_ID_APPLE 0x05ac
91#define BT_VENDOR_ID_APPLE 0x004c
91#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 92#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
92#define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d 93#define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
93#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD 0x030e 94#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD 0x030e
@@ -157,6 +158,7 @@
157#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256 158#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256
158#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS 0x0257 159#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS 0x0257
159#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI 0x0267 160#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI 0x0267
161#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI 0x026c
160#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290 162#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290
161#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291 163#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291
162#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292 164#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292
@@ -528,9 +530,6 @@
528#define I2C_VENDOR_ID_HANTICK 0x0911 530#define I2C_VENDOR_ID_HANTICK 0x0911
529#define I2C_PRODUCT_ID_HANTICK_5288 0x5288 531#define I2C_PRODUCT_ID_HANTICK_5288 0x5288
530 532
531#define I2C_VENDOR_ID_RAYD 0x2386
532#define I2C_PRODUCT_ID_RAYD_3118 0x3118
533
534#define USB_VENDOR_ID_HANWANG 0x0b57 533#define USB_VENDOR_ID_HANWANG 0x0b57
535#define USB_DEVICE_ID_HANWANG_TABLET_FIRST 0x5000 534#define USB_DEVICE_ID_HANWANG_TABLET_FIRST 0x5000
536#define USB_DEVICE_ID_HANWANG_TABLET_LAST 0x8fff 535#define USB_DEVICE_ID_HANWANG_TABLET_LAST 0x8fff
@@ -950,6 +949,7 @@
950#define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17 949#define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
951#define USB_DEVICE_ID_SAITEK_PS1000 0x0621 950#define USB_DEVICE_ID_SAITEK_PS1000 0x0621
952#define USB_DEVICE_ID_SAITEK_RAT7_OLD 0x0ccb 951#define USB_DEVICE_ID_SAITEK_RAT7_OLD 0x0ccb
952#define USB_DEVICE_ID_SAITEK_RAT7_CONTAGION 0x0ccd
953#define USB_DEVICE_ID_SAITEK_RAT7 0x0cd7 953#define USB_DEVICE_ID_SAITEK_RAT7 0x0cd7
954#define USB_DEVICE_ID_SAITEK_RAT9 0x0cfa 954#define USB_DEVICE_ID_SAITEK_RAT9 0x0cfa
955#define USB_DEVICE_ID_SAITEK_MMO7 0x0cd0 955#define USB_DEVICE_ID_SAITEK_MMO7 0x0cd0
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 4e94ea3e280a..a481eaf39e88 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1582,6 +1582,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid,
1582 input_dev->dev.parent = &hid->dev; 1582 input_dev->dev.parent = &hid->dev;
1583 1583
1584 hidinput->input = input_dev; 1584 hidinput->input = input_dev;
1585 hidinput->application = application;
1585 list_add_tail(&hidinput->list, &hid->inputs); 1586 list_add_tail(&hidinput->list, &hid->inputs);
1586 1587
1587 INIT_LIST_HEAD(&hidinput->reports); 1588 INIT_LIST_HEAD(&hidinput->reports);
@@ -1677,8 +1678,7 @@ static struct hid_input *hidinput_match_application(struct hid_report *report)
1677 struct hid_input *hidinput; 1678 struct hid_input *hidinput;
1678 1679
1679 list_for_each_entry(hidinput, &hid->inputs, list) { 1680 list_for_each_entry(hidinput, &hid->inputs, list) {
1680 if (hidinput->report && 1681 if (hidinput->application == report->application)
1681 hidinput->report->application == report->application)
1682 return hidinput; 1682 return hidinput;
1683 } 1683 }
1684 1684
@@ -1815,6 +1815,7 @@ void hidinput_disconnect(struct hid_device *hid)
1815 input_unregister_device(hidinput->input); 1815 input_unregister_device(hidinput->input);
1816 else 1816 else
1817 input_free_device(hidinput->input); 1817 input_free_device(hidinput->input);
1818 kfree(hidinput->name);
1818 kfree(hidinput); 1819 kfree(hidinput);
1819 } 1820 }
1820 1821
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 40fbb7c52723..da954f3f4da7 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -1375,7 +1375,8 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
1375 struct hid_usage *usage, 1375 struct hid_usage *usage,
1376 enum latency_mode latency, 1376 enum latency_mode latency,
1377 bool surface_switch, 1377 bool surface_switch,
1378 bool button_switch) 1378 bool button_switch,
1379 bool *inputmode_found)
1379{ 1380{
1380 struct mt_device *td = hid_get_drvdata(hdev); 1381 struct mt_device *td = hid_get_drvdata(hdev);
1381 struct mt_class *cls = &td->mtclass; 1382 struct mt_class *cls = &td->mtclass;
@@ -1387,6 +1388,14 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
1387 1388
1388 switch (usage->hid) { 1389 switch (usage->hid) {
1389 case HID_DG_INPUTMODE: 1390 case HID_DG_INPUTMODE:
1391 /*
1392 * Some elan panels wrongly declare 2 input mode features,
1393 * and silently ignore when we set the value in the second
1394 * field. Skip the second feature and hope for the best.
1395 */
1396 if (*inputmode_found)
1397 return false;
1398
1390 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) { 1399 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
1391 report_len = hid_report_len(report); 1400 report_len = hid_report_len(report);
1392 buf = hid_alloc_report_buf(report, GFP_KERNEL); 1401 buf = hid_alloc_report_buf(report, GFP_KERNEL);
@@ -1402,6 +1411,7 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
1402 } 1411 }
1403 1412
1404 field->value[index] = td->inputmode_value; 1413 field->value[index] = td->inputmode_value;
1414 *inputmode_found = true;
1405 return true; 1415 return true;
1406 1416
1407 case HID_DG_CONTACTMAX: 1417 case HID_DG_CONTACTMAX:
@@ -1439,6 +1449,7 @@ static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1439 struct hid_usage *usage; 1449 struct hid_usage *usage;
1440 int i, j; 1450 int i, j;
1441 bool update_report; 1451 bool update_report;
1452 bool inputmode_found = false;
1442 1453
1443 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; 1454 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1444 list_for_each_entry(rep, &rep_enum->report_list, list) { 1455 list_for_each_entry(rep, &rep_enum->report_list, list) {
@@ -1457,7 +1468,8 @@ static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1457 usage, 1468 usage,
1458 latency, 1469 latency,
1459 surface_switch, 1470 surface_switch,
1460 button_switch)) 1471 button_switch,
1472 &inputmode_found))
1461 update_report = true; 1473 update_report = true;
1462 } 1474 }
1463 } 1475 }
@@ -1685,6 +1697,9 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1685 */ 1697 */
1686 hdev->quirks |= HID_QUIRK_INPUT_PER_APP; 1698 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1687 1699
1700 if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
1701 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1702
1688 timer_setup(&td->release_timer, mt_expired_timeout, 0); 1703 timer_setup(&td->release_timer, mt_expired_timeout, 0);
1689 1704
1690 ret = hid_parse(hdev); 1705 ret = hid_parse(hdev);
diff --git a/drivers/hid/hid-saitek.c b/drivers/hid/hid-saitek.c
index 39e642686ff0..683861f324e3 100644
--- a/drivers/hid/hid-saitek.c
+++ b/drivers/hid/hid-saitek.c
@@ -183,6 +183,8 @@ static const struct hid_device_id saitek_devices[] = {
183 .driver_data = SAITEK_RELEASE_MODE_RAT7 }, 183 .driver_data = SAITEK_RELEASE_MODE_RAT7 },
184 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7), 184 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7),
185 .driver_data = SAITEK_RELEASE_MODE_RAT7 }, 185 .driver_data = SAITEK_RELEASE_MODE_RAT7 },
186 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7_CONTAGION),
187 .driver_data = SAITEK_RELEASE_MODE_RAT7 },
186 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT9), 188 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT9),
187 .driver_data = SAITEK_RELEASE_MODE_RAT7 }, 189 .driver_data = SAITEK_RELEASE_MODE_RAT7 },
188 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9), 190 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9),
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 50af72baa5ca..2b63487057c2 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -579,6 +579,28 @@ void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev)
579} 579}
580EXPORT_SYMBOL_GPL(sensor_hub_device_close); 580EXPORT_SYMBOL_GPL(sensor_hub_device_close);
581 581
582static __u8 *sensor_hub_report_fixup(struct hid_device *hdev, __u8 *rdesc,
583 unsigned int *rsize)
584{
585 /*
586 * Checks if the report descriptor of Thinkpad Helix 2 has a logical
587 * minimum for magnetic flux axis greater than the maximum.
588 */
589 if (hdev->product == USB_DEVICE_ID_TEXAS_INSTRUMENTS_LENOVO_YOGA &&
590 *rsize == 2558 && rdesc[913] == 0x17 && rdesc[914] == 0x40 &&
591 rdesc[915] == 0x81 && rdesc[916] == 0x08 &&
592 rdesc[917] == 0x00 && rdesc[918] == 0x27 &&
593 rdesc[921] == 0x07 && rdesc[922] == 0x00) {
594 /* Sets negative logical minimum for mag x, y and z */
595 rdesc[914] = rdesc[935] = rdesc[956] = 0xc0;
596 rdesc[915] = rdesc[936] = rdesc[957] = 0x7e;
597 rdesc[916] = rdesc[937] = rdesc[958] = 0xf7;
598 rdesc[917] = rdesc[938] = rdesc[959] = 0xff;
599 }
600
601 return rdesc;
602}
603
582static int sensor_hub_probe(struct hid_device *hdev, 604static int sensor_hub_probe(struct hid_device *hdev,
583 const struct hid_device_id *id) 605 const struct hid_device_id *id)
584{ 606{
@@ -743,6 +765,7 @@ static struct hid_driver sensor_hub_driver = {
743 .probe = sensor_hub_probe, 765 .probe = sensor_hub_probe,
744 .remove = sensor_hub_remove, 766 .remove = sensor_hub_remove,
745 .raw_event = sensor_hub_raw_event, 767 .raw_event = sensor_hub_raw_event,
768 .report_fixup = sensor_hub_report_fixup,
746#ifdef CONFIG_PM 769#ifdef CONFIG_PM
747 .suspend = sensor_hub_suspend, 770 .suspend = sensor_hub_suspend,
748 .resume = sensor_hub_resume, 771 .resume = sensor_hub_resume,
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 2ce194a84868..f3076659361a 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -170,8 +170,6 @@ static const struct i2c_hid_quirks {
170 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV }, 170 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
171 { I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288, 171 { I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288,
172 I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, 172 I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
173 { I2C_VENDOR_ID_RAYD, I2C_PRODUCT_ID_RAYD_3118,
174 I2C_HID_QUIRK_RESEND_REPORT_DESCR },
175 { USB_VENDOR_ID_SIS_TOUCH, USB_DEVICE_ID_SIS10FB_TOUCH, 173 { USB_VENDOR_ID_SIS_TOUCH, USB_DEVICE_ID_SIS10FB_TOUCH,
176 I2C_HID_QUIRK_RESEND_REPORT_DESCR }, 174 I2C_HID_QUIRK_RESEND_REPORT_DESCR },
177 { 0, 0 } 175 { 0, 0 }
@@ -1235,11 +1233,16 @@ static int i2c_hid_resume(struct device *dev)
1235 pm_runtime_enable(dev); 1233 pm_runtime_enable(dev);
1236 1234
1237 enable_irq(client->irq); 1235 enable_irq(client->irq);
1238 ret = i2c_hid_hwreset(client); 1236
1237 /* Instead of resetting device, simply powers the device on. This
1238 * solves "incomplete reports" on Raydium devices 2386:3118 and
1239 * 2386:4B33
1240 */
1241 ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
1239 if (ret) 1242 if (ret)
1240 return ret; 1243 return ret;
1241 1244
1242 /* RAYDIUM device (2386:3118) need to re-send report descr cmd 1245 /* Some devices need to re-send report descr cmd
1243 * after resume, after this it will be back normal. 1246 * after resume, after this it will be back normal.
1244 * otherwise it issues too many incomplete reports. 1247 * otherwise it issues too many incomplete reports.
1245 */ 1248 */
diff --git a/drivers/hid/intel-ish-hid/ipc/hw-ish.h b/drivers/hid/intel-ish-hid/ipc/hw-ish.h
index 97869b7410eb..da133716bed0 100644
--- a/drivers/hid/intel-ish-hid/ipc/hw-ish.h
+++ b/drivers/hid/intel-ish-hid/ipc/hw-ish.h
@@ -29,6 +29,7 @@
29#define CNL_Ax_DEVICE_ID 0x9DFC 29#define CNL_Ax_DEVICE_ID 0x9DFC
30#define GLK_Ax_DEVICE_ID 0x31A2 30#define GLK_Ax_DEVICE_ID 0x31A2
31#define CNL_H_DEVICE_ID 0xA37C 31#define CNL_H_DEVICE_ID 0xA37C
32#define SPT_H_DEVICE_ID 0xA135
32 33
33#define REVISION_ID_CHT_A0 0x6 34#define REVISION_ID_CHT_A0 0x6
34#define REVISION_ID_CHT_Ax_SI 0x0 35#define REVISION_ID_CHT_Ax_SI 0x0
diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
index 050f9872f5c0..a1125a5c7965 100644
--- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
+++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
@@ -38,6 +38,7 @@ static const struct pci_device_id ish_pci_tbl[] = {
38 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CNL_Ax_DEVICE_ID)}, 38 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CNL_Ax_DEVICE_ID)},
39 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, GLK_Ax_DEVICE_ID)}, 39 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, GLK_Ax_DEVICE_ID)},
40 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CNL_H_DEVICE_ID)}, 40 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CNL_H_DEVICE_ID)},
41 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, SPT_H_DEVICE_ID)},
41 {0, } 42 {0, }
42}; 43};
43MODULE_DEVICE_TABLE(pci, ish_pci_tbl); 44MODULE_DEVICE_TABLE(pci, ish_pci_tbl);
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 90837f7c7d0f..f4c7516eb989 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -302,14 +302,18 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
302 return clamp_val(reg, 0, 1023) & (0xff << 2); 302 return clamp_val(reg, 0, 1023) & (0xff << 2);
303} 303}
304 304
305static u16 adt7475_read_word(struct i2c_client *client, int reg) 305static int adt7475_read_word(struct i2c_client *client, int reg)
306{ 306{
307 u16 val; 307 int val1, val2;
308 308
309 val = i2c_smbus_read_byte_data(client, reg); 309 val1 = i2c_smbus_read_byte_data(client, reg);
310 val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8); 310 if (val1 < 0)
311 return val1;
312 val2 = i2c_smbus_read_byte_data(client, reg + 1);
313 if (val2 < 0)
314 return val2;
311 315
312 return val; 316 return val1 | (val2 << 8);
313} 317}
314 318
315static void adt7475_write_word(struct i2c_client *client, int reg, u16 val) 319static void adt7475_write_word(struct i2c_client *client, int reg, u16 val)
@@ -962,13 +966,14 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
962{ 966{
963 struct adt7475_data *data = adt7475_update_device(dev); 967 struct adt7475_data *data = adt7475_update_device(dev);
964 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 968 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
965 int i = clamp_val(data->range[sattr->index] & 0xf, 0, 969 int idx;
966 ARRAY_SIZE(pwmfreq_table) - 1);
967 970
968 if (IS_ERR(data)) 971 if (IS_ERR(data))
969 return PTR_ERR(data); 972 return PTR_ERR(data);
973 idx = clamp_val(data->range[sattr->index] & 0xf, 0,
974 ARRAY_SIZE(pwmfreq_table) - 1);
970 975
971 return sprintf(buf, "%d\n", pwmfreq_table[i]); 976 return sprintf(buf, "%d\n", pwmfreq_table[idx]);
972} 977}
973 978
974static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, 979static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
@@ -1004,6 +1009,10 @@ static ssize_t pwm_use_point2_pwm_at_crit_show(struct device *dev,
1004 char *buf) 1009 char *buf)
1005{ 1010{
1006 struct adt7475_data *data = adt7475_update_device(dev); 1011 struct adt7475_data *data = adt7475_update_device(dev);
1012
1013 if (IS_ERR(data))
1014 return PTR_ERR(data);
1015
1007 return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY)); 1016 return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
1008} 1017}
1009 1018
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index e9e6aeabbf84..71d3445ba869 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -17,7 +17,7 @@
17 * Bi-directional Current/Power Monitor with I2C Interface 17 * Bi-directional Current/Power Monitor with I2C Interface
18 * Datasheet: http://www.ti.com/product/ina230 18 * Datasheet: http://www.ti.com/product/ina230
19 * 19 *
20 * Copyright (C) 2012 Lothar Felten <l-felten@ti.com> 20 * Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com>
21 * Thanks to Jan Volkering 21 * Thanks to Jan Volkering
22 * 22 *
23 * This program is free software; you can redistribute it and/or modify 23 * This program is free software; you can redistribute it and/or modify
@@ -329,6 +329,15 @@ static int ina2xx_set_shunt(struct ina2xx_data *data, long val)
329 return 0; 329 return 0;
330} 330}
331 331
332static ssize_t ina2xx_show_shunt(struct device *dev,
333 struct device_attribute *da,
334 char *buf)
335{
336 struct ina2xx_data *data = dev_get_drvdata(dev);
337
338 return snprintf(buf, PAGE_SIZE, "%li\n", data->rshunt);
339}
340
332static ssize_t ina2xx_store_shunt(struct device *dev, 341static ssize_t ina2xx_store_shunt(struct device *dev,
333 struct device_attribute *da, 342 struct device_attribute *da,
334 const char *buf, size_t count) 343 const char *buf, size_t count)
@@ -403,7 +412,7 @@ static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina2xx_show_value, NULL,
403 412
404/* shunt resistance */ 413/* shunt resistance */
405static SENSOR_DEVICE_ATTR(shunt_resistor, S_IRUGO | S_IWUSR, 414static SENSOR_DEVICE_ATTR(shunt_resistor, S_IRUGO | S_IWUSR,
406 ina2xx_show_value, ina2xx_store_shunt, 415 ina2xx_show_shunt, ina2xx_store_shunt,
407 INA2XX_CALIBRATION); 416 INA2XX_CALIBRATION);
408 417
409/* update interval (ina226 only) */ 418/* update interval (ina226 only) */
diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index c6bd61e4695a..944f5b63aecd 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -63,6 +63,7 @@
63#include <linux/bitops.h> 63#include <linux/bitops.h>
64#include <linux/dmi.h> 64#include <linux/dmi.h>
65#include <linux/io.h> 65#include <linux/io.h>
66#include <linux/nospec.h>
66#include "lm75.h" 67#include "lm75.h"
67 68
68#define USE_ALTERNATE 69#define USE_ALTERNATE
@@ -2689,6 +2690,7 @@ store_pwm_weight_temp_sel(struct device *dev, struct device_attribute *attr,
2689 return err; 2690 return err;
2690 if (val > NUM_TEMP) 2691 if (val > NUM_TEMP)
2691 return -EINVAL; 2692 return -EINVAL;
2693 val = array_index_nospec(val, NUM_TEMP + 1);
2692 if (val && (!(data->have_temp & BIT(val - 1)) || 2694 if (val && (!(data->have_temp & BIT(val - 1)) ||
2693 !data->temp_src[val - 1])) 2695 !data->temp_src[val - 1]))
2694 return -EINVAL; 2696 return -EINVAL;
diff --git a/drivers/hwmon/raspberrypi-hwmon.c b/drivers/hwmon/raspberrypi-hwmon.c
index fb4e4a6bb1f6..be5ba4690895 100644
--- a/drivers/hwmon/raspberrypi-hwmon.c
+++ b/drivers/hwmon/raspberrypi-hwmon.c
@@ -164,3 +164,4 @@ module_platform_driver(rpi_hwmon_driver);
164MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>"); 164MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>");
165MODULE_DESCRIPTION("Raspberry Pi voltage sensor driver"); 165MODULE_DESCRIPTION("Raspberry Pi voltage sensor driver");
166MODULE_LICENSE("GPL v2"); 166MODULE_LICENSE("GPL v2");
167MODULE_ALIAS("platform:raspberrypi-hwmon");
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 6ec65adaba49..c33dcfb87993 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -110,8 +110,8 @@ static int sclhi(struct i2c_algo_bit_data *adap)
110 } 110 }
111#ifdef DEBUG 111#ifdef DEBUG
112 if (jiffies != start && i2c_debug >= 3) 112 if (jiffies != start && i2c_debug >= 3)
113 pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go " 113 pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go high\n",
114 "high\n", jiffies - start); 114 jiffies - start);
115#endif 115#endif
116 116
117done: 117done:
@@ -171,8 +171,9 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
171 setsda(adap, sb); 171 setsda(adap, sb);
172 udelay((adap->udelay + 1) / 2); 172 udelay((adap->udelay + 1) / 2);
173 if (sclhi(adap) < 0) { /* timed out */ 173 if (sclhi(adap) < 0) { /* timed out */
174 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " 174 bit_dbg(1, &i2c_adap->dev,
175 "timeout at bit #%d\n", (int)c, i); 175 "i2c_outb: 0x%02x, timeout at bit #%d\n",
176 (int)c, i);
176 return -ETIMEDOUT; 177 return -ETIMEDOUT;
177 } 178 }
178 /* FIXME do arbitration here: 179 /* FIXME do arbitration here:
@@ -185,8 +186,8 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
185 } 186 }
186 sdahi(adap); 187 sdahi(adap);
187 if (sclhi(adap) < 0) { /* timeout */ 188 if (sclhi(adap) < 0) { /* timeout */
188 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " 189 bit_dbg(1, &i2c_adap->dev,
189 "timeout at ack\n", (int)c); 190 "i2c_outb: 0x%02x, timeout at ack\n", (int)c);
190 return -ETIMEDOUT; 191 return -ETIMEDOUT;
191 } 192 }
192 193
@@ -215,8 +216,9 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
215 sdahi(adap); 216 sdahi(adap);
216 for (i = 0; i < 8; i++) { 217 for (i = 0; i < 8; i++) {
217 if (sclhi(adap) < 0) { /* timeout */ 218 if (sclhi(adap) < 0) { /* timeout */
218 bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit " 219 bit_dbg(1, &i2c_adap->dev,
219 "#%d\n", 7 - i); 220 "i2c_inb: timeout at bit #%d\n",
221 7 - i);
220 return -ETIMEDOUT; 222 return -ETIMEDOUT;
221 } 223 }
222 indata *= 2; 224 indata *= 2;
@@ -265,8 +267,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
265 goto bailout; 267 goto bailout;
266 } 268 }
267 if (!scl) { 269 if (!scl) {
268 printk(KERN_WARNING "%s: SCL unexpected low " 270 printk(KERN_WARNING
269 "while pulling SDA low!\n", name); 271 "%s: SCL unexpected low while pulling SDA low!\n",
272 name);
270 goto bailout; 273 goto bailout;
271 } 274 }
272 275
@@ -278,8 +281,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
278 goto bailout; 281 goto bailout;
279 } 282 }
280 if (!scl) { 283 if (!scl) {
281 printk(KERN_WARNING "%s: SCL unexpected low " 284 printk(KERN_WARNING
282 "while pulling SDA high!\n", name); 285 "%s: SCL unexpected low while pulling SDA high!\n",
286 name);
283 goto bailout; 287 goto bailout;
284 } 288 }
285 289
@@ -291,8 +295,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
291 goto bailout; 295 goto bailout;
292 } 296 }
293 if (!sda) { 297 if (!sda) {
294 printk(KERN_WARNING "%s: SDA unexpected low " 298 printk(KERN_WARNING
295 "while pulling SCL low!\n", name); 299 "%s: SDA unexpected low while pulling SCL low!\n",
300 name);
296 goto bailout; 301 goto bailout;
297 } 302 }
298 303
@@ -304,8 +309,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
304 goto bailout; 309 goto bailout;
305 } 310 }
306 if (!sda) { 311 if (!sda) {
307 printk(KERN_WARNING "%s: SDA unexpected low " 312 printk(KERN_WARNING
308 "while pulling SCL high!\n", name); 313 "%s: SDA unexpected low while pulling SCL high!\n",
314 name);
309 goto bailout; 315 goto bailout;
310 } 316 }
311 317
@@ -352,8 +358,8 @@ static int try_address(struct i2c_adapter *i2c_adap,
352 i2c_start(adap); 358 i2c_start(adap);
353 } 359 }
354 if (i && ret) 360 if (i && ret)
355 bit_dbg(1, &i2c_adap->dev, "Used %d tries to %s client at " 361 bit_dbg(1, &i2c_adap->dev,
356 "0x%02x: %s\n", i + 1, 362 "Used %d tries to %s client at 0x%02x: %s\n", i + 1,
357 addr & 1 ? "read from" : "write to", addr >> 1, 363 addr & 1 ? "read from" : "write to", addr >> 1,
358 ret == 1 ? "success" : "failed, timeout?"); 364 ret == 1 ? "success" : "failed, timeout?");
359 return ret; 365 return ret;
@@ -442,8 +448,9 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
442 if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) { 448 if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) {
443 if (!(flags & I2C_M_NO_RD_ACK)) 449 if (!(flags & I2C_M_NO_RD_ACK))
444 acknak(i2c_adap, 0); 450 acknak(i2c_adap, 0);
445 dev_err(&i2c_adap->dev, "readbytes: invalid " 451 dev_err(&i2c_adap->dev,
446 "block length (%d)\n", inval); 452 "readbytes: invalid block length (%d)\n",
453 inval);
447 return -EPROTO; 454 return -EPROTO;
448 } 455 }
449 /* The original count value accounts for the extra 456 /* The original count value accounts for the extra
@@ -506,8 +513,8 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
506 return -ENXIO; 513 return -ENXIO;
507 } 514 }
508 if (flags & I2C_M_RD) { 515 if (flags & I2C_M_RD) {
509 bit_dbg(3, &i2c_adap->dev, "emitting repeated " 516 bit_dbg(3, &i2c_adap->dev,
510 "start condition\n"); 517 "emitting repeated start condition\n");
511 i2c_repstart(adap); 518 i2c_repstart(adap);
512 /* okay, now switch into reading mode */ 519 /* okay, now switch into reading mode */
513 addr |= 0x01; 520 addr |= 0x01;
@@ -564,8 +571,8 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
564 } 571 }
565 ret = bit_doAddress(i2c_adap, pmsg); 572 ret = bit_doAddress(i2c_adap, pmsg);
566 if ((ret != 0) && !nak_ok) { 573 if ((ret != 0) && !nak_ok) {
567 bit_dbg(1, &i2c_adap->dev, "NAK from " 574 bit_dbg(1, &i2c_adap->dev,
568 "device addr 0x%02x msg #%d\n", 575 "NAK from device addr 0x%02x msg #%d\n",
569 msgs[i].addr, i); 576 msgs[i].addr, i);
570 goto bailout; 577 goto bailout;
571 } 578 }
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index e18442b9973a..94d94b4a9a0d 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -708,7 +708,6 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
708 i2c_set_adapdata(adap, dev); 708 i2c_set_adapdata(adap, dev);
709 709
710 if (dev->pm_disabled) { 710 if (dev->pm_disabled) {
711 dev_pm_syscore_device(dev->dev, true);
712 irq_flags = IRQF_NO_SUSPEND; 711 irq_flags = IRQF_NO_SUSPEND;
713 } else { 712 } else {
714 irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND; 713 irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND;
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 1a8d2da5b000..b5750fd85125 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -434,6 +434,9 @@ static int dw_i2c_plat_suspend(struct device *dev)
434{ 434{
435 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 435 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev);
436 436
437 if (i_dev->pm_disabled)
438 return 0;
439
437 i_dev->disable(i_dev); 440 i_dev->disable(i_dev);
438 i2c_dw_prepare_clk(i_dev, false); 441 i2c_dw_prepare_clk(i_dev, false);
439 442
@@ -444,7 +447,9 @@ static int dw_i2c_plat_resume(struct device *dev)
444{ 447{
445 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 448 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev);
446 449
447 i2c_dw_prepare_clk(i_dev, true); 450 if (!i_dev->pm_disabled)
451 i2c_dw_prepare_clk(i_dev, true);
452
448 i_dev->init(i_dev); 453 i_dev->init(i_dev);
449 454
450 return 0; 455 return 0;
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 941c223f6491..c91e145ef5a5 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -140,6 +140,7 @@
140 140
141#define SBREG_BAR 0x10 141#define SBREG_BAR 0x10
142#define SBREG_SMBCTRL 0xc6000c 142#define SBREG_SMBCTRL 0xc6000c
143#define SBREG_SMBCTRL_DNV 0xcf000c
143 144
144/* Host status bits for SMBPCISTS */ 145/* Host status bits for SMBPCISTS */
145#define SMBPCISTS_INTS BIT(3) 146#define SMBPCISTS_INTS BIT(3)
@@ -1399,7 +1400,11 @@ static void i801_add_tco(struct i801_priv *priv)
1399 spin_unlock(&p2sb_spinlock); 1400 spin_unlock(&p2sb_spinlock);
1400 1401
1401 res = &tco_res[ICH_RES_MEM_OFF]; 1402 res = &tco_res[ICH_RES_MEM_OFF];
1402 res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL; 1403 if (pci_dev->device == PCI_DEVICE_ID_INTEL_DNV_SMBUS)
1404 res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL_DNV;
1405 else
1406 res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL;
1407
1403 res->end = res->start + 3; 1408 res->end = res->start + 3;
1404 res->flags = IORESOURCE_MEM; 1409 res->flags = IORESOURCE_MEM;
1405 1410
@@ -1415,6 +1420,13 @@ static void i801_add_tco(struct i801_priv *priv)
1415} 1420}
1416 1421
1417#ifdef CONFIG_ACPI 1422#ifdef CONFIG_ACPI
1423static bool i801_acpi_is_smbus_ioport(const struct i801_priv *priv,
1424 acpi_physical_address address)
1425{
1426 return address >= priv->smba &&
1427 address <= pci_resource_end(priv->pci_dev, SMBBAR);
1428}
1429
1418static acpi_status 1430static acpi_status
1419i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits, 1431i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
1420 u64 *value, void *handler_context, void *region_context) 1432 u64 *value, void *handler_context, void *region_context)
@@ -1430,7 +1442,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
1430 */ 1442 */
1431 mutex_lock(&priv->acpi_lock); 1443 mutex_lock(&priv->acpi_lock);
1432 1444
1433 if (!priv->acpi_reserved) { 1445 if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) {
1434 priv->acpi_reserved = true; 1446 priv->acpi_reserved = true;
1435 1447
1436 dev_warn(&pdev->dev, "BIOS is accessing SMBus registers\n"); 1448 dev_warn(&pdev->dev, "BIOS is accessing SMBus registers\n");
diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index 6d975f5221ca..06c4c767af32 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -538,7 +538,6 @@ static const struct i2c_algorithm lpi2c_imx_algo = {
538 538
539static const struct of_device_id lpi2c_imx_of_match[] = { 539static const struct of_device_id lpi2c_imx_of_match[] = {
540 { .compatible = "fsl,imx7ulp-lpi2c" }, 540 { .compatible = "fsl,imx7ulp-lpi2c" },
541 { .compatible = "fsl,imx8dv-lpi2c" },
542 { }, 541 { },
543}; 542};
544MODULE_DEVICE_TABLE(of, lpi2c_imx_of_match); 543MODULE_DEVICE_TABLE(of, lpi2c_imx_of_match);
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 439e8778f849..818cab14e87c 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -507,8 +507,6 @@ static void sh_mobile_i2c_dma_callback(void *data)
507 pd->pos = pd->msg->len; 507 pd->pos = pd->msg->len;
508 pd->stop_after_dma = true; 508 pd->stop_after_dma = true;
509 509
510 i2c_release_dma_safe_msg_buf(pd->msg, pd->dma_buf);
511
512 iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE); 510 iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE);
513} 511}
514 512
@@ -602,8 +600,8 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)
602 dma_async_issue_pending(chan); 600 dma_async_issue_pending(chan);
603} 601}
604 602
605static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg, 603static void start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
606 bool do_init) 604 bool do_init)
607{ 605{
608 if (do_init) { 606 if (do_init) {
609 /* Initialize channel registers */ 607 /* Initialize channel registers */
@@ -627,7 +625,6 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
627 625
628 /* Enable all interrupts to begin with */ 626 /* Enable all interrupts to begin with */
629 iic_wr(pd, ICIC, ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); 627 iic_wr(pd, ICIC, ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
630 return 0;
631} 628}
632 629
633static int poll_dte(struct sh_mobile_i2c_data *pd) 630static int poll_dte(struct sh_mobile_i2c_data *pd)
@@ -698,9 +695,7 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
698 pd->send_stop = i == num - 1 || msg->flags & I2C_M_STOP; 695 pd->send_stop = i == num - 1 || msg->flags & I2C_M_STOP;
699 pd->stop_after_dma = false; 696 pd->stop_after_dma = false;
700 697
701 err = start_ch(pd, msg, do_start); 698 start_ch(pd, msg, do_start);
702 if (err)
703 break;
704 699
705 if (do_start) 700 if (do_start)
706 i2c_op(pd, OP_START, 0); 701 i2c_op(pd, OP_START, 0);
@@ -709,6 +704,10 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
709 timeout = wait_event_timeout(pd->wait, 704 timeout = wait_event_timeout(pd->wait,
710 pd->sr & (ICSR_TACK | SW_DONE), 705 pd->sr & (ICSR_TACK | SW_DONE),
711 adapter->timeout); 706 adapter->timeout);
707
708 /* 'stop_after_dma' tells if DMA transfer was complete */
709 i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg, pd->stop_after_dma);
710
712 if (!timeout) { 711 if (!timeout) {
713 dev_err(pd->dev, "Transfer request timed out\n"); 712 dev_err(pd->dev, "Transfer request timed out\n");
714 if (pd->dma_direction != DMA_NONE) 713 if (pd->dma_direction != DMA_NONE)
diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c
index 9918bdd81619..a403e8579b65 100644
--- a/drivers/i2c/busses/i2c-uniphier-f.c
+++ b/drivers/i2c/busses/i2c-uniphier-f.c
@@ -401,11 +401,8 @@ static int uniphier_fi2c_master_xfer(struct i2c_adapter *adap,
401 return ret; 401 return ret;
402 402
403 for (msg = msgs; msg < emsg; msg++) { 403 for (msg = msgs; msg < emsg; msg++) {
404 /* If next message is read, skip the stop condition */ 404 /* Emit STOP if it is the last message or I2C_M_STOP is set. */
405 bool stop = !(msg + 1 < emsg && msg[1].flags & I2C_M_RD); 405 bool stop = (msg + 1 == emsg) || (msg->flags & I2C_M_STOP);
406 /* but, force it if I2C_M_STOP is set */
407 if (msg->flags & I2C_M_STOP)
408 stop = true;
409 406
410 ret = uniphier_fi2c_master_xfer_one(adap, msg, stop); 407 ret = uniphier_fi2c_master_xfer_one(adap, msg, stop);
411 if (ret) 408 if (ret)
diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c
index bb181b088291..454f914ae66d 100644
--- a/drivers/i2c/busses/i2c-uniphier.c
+++ b/drivers/i2c/busses/i2c-uniphier.c
@@ -248,11 +248,8 @@ static int uniphier_i2c_master_xfer(struct i2c_adapter *adap,
248 return ret; 248 return ret;
249 249
250 for (msg = msgs; msg < emsg; msg++) { 250 for (msg = msgs; msg < emsg; msg++) {
251 /* If next message is read, skip the stop condition */ 251 /* Emit STOP if it is the last message or I2C_M_STOP is set. */
252 bool stop = !(msg + 1 < emsg && msg[1].flags & I2C_M_RD); 252 bool stop = (msg + 1 == emsg) || (msg->flags & I2C_M_STOP);
253 /* but, force it if I2C_M_STOP is set */
254 if (msg->flags & I2C_M_STOP)
255 stop = true;
256 253
257 ret = uniphier_i2c_master_xfer_one(adap, msg, stop); 254 ret = uniphier_i2c_master_xfer_one(adap, msg, stop);
258 if (ret) 255 if (ret)
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 9a71e50d21f1..0c51c0ffdda9 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -532,6 +532,7 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
532{ 532{
533 u8 rx_watermark; 533 u8 rx_watermark;
534 struct i2c_msg *msg = i2c->rx_msg = i2c->tx_msg; 534 struct i2c_msg *msg = i2c->rx_msg = i2c->tx_msg;
535 unsigned long flags;
535 536
536 /* Clear and enable Rx full interrupt. */ 537 /* Clear and enable Rx full interrupt. */
537 xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | XIIC_INTR_TX_ERROR_MASK); 538 xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | XIIC_INTR_TX_ERROR_MASK);
@@ -547,6 +548,7 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
547 rx_watermark = IIC_RX_FIFO_DEPTH; 548 rx_watermark = IIC_RX_FIFO_DEPTH;
548 xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rx_watermark - 1); 549 xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rx_watermark - 1);
549 550
551 local_irq_save(flags);
550 if (!(msg->flags & I2C_M_NOSTART)) 552 if (!(msg->flags & I2C_M_NOSTART))
551 /* write the address */ 553 /* write the address */
552 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 554 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET,
@@ -556,6 +558,8 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
556 558
557 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 559 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET,
558 msg->len | ((i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0)); 560 msg->len | ((i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0));
561 local_irq_restore(flags);
562
559 if (i2c->nmsgs == 1) 563 if (i2c->nmsgs == 1)
560 /* very last, enable bus not busy as well */ 564 /* very last, enable bus not busy as well */
561 xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); 565 xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK);
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index f15737763608..9ee9a15e7134 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -2293,21 +2293,22 @@ u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
2293EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf); 2293EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf);
2294 2294
2295/** 2295/**
2296 * i2c_release_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg 2296 * i2c_put_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg
2297 * @msg: the message to be synced with
2298 * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL. 2297 * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL.
2298 * @msg: the message which the buffer corresponds to
2299 * @xferred: bool saying if the message was transferred
2299 */ 2300 */
2300void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf) 2301void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred)
2301{ 2302{
2302 if (!buf || buf == msg->buf) 2303 if (!buf || buf == msg->buf)
2303 return; 2304 return;
2304 2305
2305 if (msg->flags & I2C_M_RD) 2306 if (xferred && msg->flags & I2C_M_RD)
2306 memcpy(msg->buf, buf, msg->len); 2307 memcpy(msg->buf, buf, msg->len);
2307 2308
2308 kfree(buf); 2309 kfree(buf);
2309} 2310}
2310EXPORT_SYMBOL_GPL(i2c_release_dma_safe_msg_buf); 2311EXPORT_SYMBOL_GPL(i2c_put_dma_safe_msg_buf);
2311 2312
2312MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); 2313MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
2313MODULE_DESCRIPTION("I2C-Bus main module"); 2314MODULE_DESCRIPTION("I2C-Bus main module");
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index f72677291b69..a36c94930c31 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -724,6 +724,7 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
724 dgid = (union ib_gid *) &addr->sib_addr; 724 dgid = (union ib_gid *) &addr->sib_addr;
725 pkey = ntohs(addr->sib_pkey); 725 pkey = ntohs(addr->sib_pkey);
726 726
727 mutex_lock(&lock);
727 list_for_each_entry(cur_dev, &dev_list, list) { 728 list_for_each_entry(cur_dev, &dev_list, list) {
728 for (p = 1; p <= cur_dev->device->phys_port_cnt; ++p) { 729 for (p = 1; p <= cur_dev->device->phys_port_cnt; ++p) {
729 if (!rdma_cap_af_ib(cur_dev->device, p)) 730 if (!rdma_cap_af_ib(cur_dev->device, p))
@@ -750,18 +751,19 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
750 cma_dev = cur_dev; 751 cma_dev = cur_dev;
751 sgid = gid; 752 sgid = gid;
752 id_priv->id.port_num = p; 753 id_priv->id.port_num = p;
754 goto found;
753 } 755 }
754 } 756 }
755 } 757 }
756 } 758 }
757 759 mutex_unlock(&lock);
758 if (!cma_dev) 760 return -ENODEV;
759 return -ENODEV;
760 761
761found: 762found:
762 cma_attach_to_dev(id_priv, cma_dev); 763 cma_attach_to_dev(id_priv, cma_dev);
763 addr = (struct sockaddr_ib *) cma_src_addr(id_priv); 764 mutex_unlock(&lock);
764 memcpy(&addr->sib_addr, &sgid, sizeof sgid); 765 addr = (struct sockaddr_ib *)cma_src_addr(id_priv);
766 memcpy(&addr->sib_addr, &sgid, sizeof(sgid));
765 cma_translate_ib(addr, &id_priv->id.route.addr.dev_addr); 767 cma_translate_ib(addr, &id_priv->id.route.addr.dev_addr);
766 return 0; 768 return 0;
767} 769}
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index 6eb64c6f0802..c4118bcd5103 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -882,6 +882,8 @@ static int __uverbs_cleanup_ufile(struct ib_uverbs_file *ufile,
882 WARN_ON(uverbs_try_lock_object(obj, UVERBS_LOOKUP_WRITE)); 882 WARN_ON(uverbs_try_lock_object(obj, UVERBS_LOOKUP_WRITE));
883 if (!uverbs_destroy_uobject(obj, reason)) 883 if (!uverbs_destroy_uobject(obj, reason))
884 ret = 0; 884 ret = 0;
885 else
886 atomic_set(&obj->usecnt, 0);
885 } 887 }
886 return ret; 888 return ret;
887} 889}
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index ec8fb289621f..5f437d1570fb 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -124,6 +124,8 @@ static DEFINE_MUTEX(mut);
124static DEFINE_IDR(ctx_idr); 124static DEFINE_IDR(ctx_idr);
125static DEFINE_IDR(multicast_idr); 125static DEFINE_IDR(multicast_idr);
126 126
127static const struct file_operations ucma_fops;
128
127static inline struct ucma_context *_ucma_find_context(int id, 129static inline struct ucma_context *_ucma_find_context(int id,
128 struct ucma_file *file) 130 struct ucma_file *file)
129{ 131{
@@ -1581,6 +1583,10 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
1581 f = fdget(cmd.fd); 1583 f = fdget(cmd.fd);
1582 if (!f.file) 1584 if (!f.file)
1583 return -ENOENT; 1585 return -ENOENT;
1586 if (f.file->f_op != &ucma_fops) {
1587 ret = -EINVAL;
1588 goto file_put;
1589 }
1584 1590
1585 /* Validate current fd and prevent destruction of id. */ 1591 /* Validate current fd and prevent destruction of id. */
1586 ctx = ucma_get_ctx(f.file->private_data, cmd.id); 1592 ctx = ucma_get_ctx(f.file->private_data, cmd.id);
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 823beca448e1..6d974e2363df 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -1050,7 +1050,7 @@ static void ib_uverbs_add_one(struct ib_device *device)
1050 uverbs_dev->num_comp_vectors = device->num_comp_vectors; 1050 uverbs_dev->num_comp_vectors = device->num_comp_vectors;
1051 1051
1052 if (ib_uverbs_create_uapi(device, uverbs_dev)) 1052 if (ib_uverbs_create_uapi(device, uverbs_dev))
1053 goto err; 1053 goto err_uapi;
1054 1054
1055 cdev_init(&uverbs_dev->cdev, NULL); 1055 cdev_init(&uverbs_dev->cdev, NULL);
1056 uverbs_dev->cdev.owner = THIS_MODULE; 1056 uverbs_dev->cdev.owner = THIS_MODULE;
@@ -1077,11 +1077,10 @@ static void ib_uverbs_add_one(struct ib_device *device)
1077 1077
1078err_class: 1078err_class:
1079 device_destroy(uverbs_class, uverbs_dev->cdev.dev); 1079 device_destroy(uverbs_class, uverbs_dev->cdev.dev);
1080
1081err_cdev: 1080err_cdev:
1082 cdev_del(&uverbs_dev->cdev); 1081 cdev_del(&uverbs_dev->cdev);
1082err_uapi:
1083 clear_bit(devnum, dev_map); 1083 clear_bit(devnum, dev_map);
1084
1085err: 1084err:
1086 if (atomic_dec_and_test(&uverbs_dev->refcount)) 1085 if (atomic_dec_and_test(&uverbs_dev->refcount))
1087 ib_uverbs_comp_dev(uverbs_dev); 1086 ib_uverbs_comp_dev(uverbs_dev);
diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
index bbfb86eb2d24..bc2b9e038439 100644
--- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c
+++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
@@ -833,6 +833,8 @@ int bnxt_re_destroy_qp(struct ib_qp *ib_qp)
833 "Failed to destroy Shadow QP"); 833 "Failed to destroy Shadow QP");
834 return rc; 834 return rc;
835 } 835 }
836 bnxt_qplib_free_qp_res(&rdev->qplib_res,
837 &rdev->qp1_sqp->qplib_qp);
836 mutex_lock(&rdev->qp_lock); 838 mutex_lock(&rdev->qp_lock);
837 list_del(&rdev->qp1_sqp->list); 839 list_del(&rdev->qp1_sqp->list);
838 atomic_dec(&rdev->qp_count); 840 atomic_dec(&rdev->qp_count);
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.c b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
index e426b990c1dd..6ad0d46ab879 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
@@ -196,7 +196,7 @@ static int bnxt_qplib_alloc_qp_hdr_buf(struct bnxt_qplib_res *res,
196 struct bnxt_qplib_qp *qp) 196 struct bnxt_qplib_qp *qp)
197{ 197{
198 struct bnxt_qplib_q *rq = &qp->rq; 198 struct bnxt_qplib_q *rq = &qp->rq;
199 struct bnxt_qplib_q *sq = &qp->rq; 199 struct bnxt_qplib_q *sq = &qp->sq;
200 int rc = 0; 200 int rc = 0;
201 201
202 if (qp->sq_hdr_buf_size && sq->hwq.max_elements) { 202 if (qp->sq_hdr_buf_size && sq->hwq.max_elements) {
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index b3203afa3b1d..347fe18b1a41 100644
--- a/drivers/infiniband/hw/cxgb4/qp.c
+++ b/drivers/infiniband/hw/cxgb4/qp.c
@@ -1685,6 +1685,12 @@ static void flush_qp(struct c4iw_qp *qhp)
1685 schp = to_c4iw_cq(qhp->ibqp.send_cq); 1685 schp = to_c4iw_cq(qhp->ibqp.send_cq);
1686 1686
1687 if (qhp->ibqp.uobject) { 1687 if (qhp->ibqp.uobject) {
1688
1689 /* for user qps, qhp->wq.flushed is protected by qhp->mutex */
1690 if (qhp->wq.flushed)
1691 return;
1692
1693 qhp->wq.flushed = 1;
1688 t4_set_wq_in_error(&qhp->wq, 0); 1694 t4_set_wq_in_error(&qhp->wq, 0);
1689 t4_set_cq_in_error(&rchp->cq); 1695 t4_set_cq_in_error(&rchp->cq);
1690 spin_lock_irqsave(&rchp->comp_handler_lock, flag); 1696 spin_lock_irqsave(&rchp->comp_handler_lock, flag);
diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c
index eec83757d55f..6c967dde58e7 100644
--- a/drivers/infiniband/hw/hfi1/pcie.c
+++ b/drivers/infiniband/hw/hfi1/pcie.c
@@ -893,14 +893,11 @@ static int trigger_sbr(struct hfi1_devdata *dd)
893 } 893 }
894 894
895 /* 895 /*
896 * A secondary bus reset (SBR) issues a hot reset to our device. 896 * This is an end around to do an SBR during probe time. A new API needs
897 * The following routine does a 1s wait after the reset is dropped 897 * to be implemented to have cleaner interface but this fixes the
898 * per PCI Trhfa (recovery time). PCIe 3.0 section 6.6.1 - 898 * current brokenness
899 * Conventional Reset, paragraph 3, line 35 also says that a 1s
900 * delay after a reset is required. Per spec requirements,
901 * the link is either working or not after that point.
902 */ 899 */
903 return pci_reset_bus(dev); 900 return pci_bridge_secondary_bus_reset(dev->bus->self);
904} 901}
905 902
906/* 903/*
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index ca0f1ee26091..0bbeaaae47e0 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -517,9 +517,11 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
517 props->page_size_cap = dev->dev->caps.page_size_cap; 517 props->page_size_cap = dev->dev->caps.page_size_cap;
518 props->max_qp = dev->dev->quotas.qp; 518 props->max_qp = dev->dev->quotas.qp;
519 props->max_qp_wr = dev->dev->caps.max_wqes - MLX4_IB_SQ_MAX_SPARE; 519 props->max_qp_wr = dev->dev->caps.max_wqes - MLX4_IB_SQ_MAX_SPARE;
520 props->max_send_sge = dev->dev->caps.max_sq_sg; 520 props->max_send_sge =
521 props->max_recv_sge = dev->dev->caps.max_rq_sg; 521 min(dev->dev->caps.max_sq_sg, dev->dev->caps.max_rq_sg);
522 props->max_sge_rd = MLX4_MAX_SGE_RD; 522 props->max_recv_sge =
523 min(dev->dev->caps.max_sq_sg, dev->dev->caps.max_rq_sg);
524 props->max_sge_rd = MLX4_MAX_SGE_RD;
523 props->max_cq = dev->dev->quotas.cq; 525 props->max_cq = dev->dev->quotas.cq;
524 props->max_cqe = dev->dev->caps.max_cqes; 526 props->max_cqe = dev->dev->caps.max_cqes;
525 props->max_mr = dev->dev->quotas.mpt; 527 props->max_mr = dev->dev->quotas.mpt;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index ea01b8dd2be6..3d5424f335cb 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -1027,12 +1027,14 @@ static int ipoib_cm_rep_handler(struct ib_cm_id *cm_id,
1027 1027
1028 skb_queue_head_init(&skqueue); 1028 skb_queue_head_init(&skqueue);
1029 1029
1030 netif_tx_lock_bh(p->dev);
1030 spin_lock_irq(&priv->lock); 1031 spin_lock_irq(&priv->lock);
1031 set_bit(IPOIB_FLAG_OPER_UP, &p->flags); 1032 set_bit(IPOIB_FLAG_OPER_UP, &p->flags);
1032 if (p->neigh) 1033 if (p->neigh)
1033 while ((skb = __skb_dequeue(&p->neigh->queue))) 1034 while ((skb = __skb_dequeue(&p->neigh->queue)))
1034 __skb_queue_tail(&skqueue, skb); 1035 __skb_queue_tail(&skqueue, skb);
1035 spin_unlock_irq(&priv->lock); 1036 spin_unlock_irq(&priv->lock);
1037 netif_tx_unlock_bh(p->dev);
1036 1038
1037 while ((skb = __skb_dequeue(&skqueue))) { 1039 while ((skb = __skb_dequeue(&skqueue))) {
1038 skb->dev = p->dev; 1040 skb->dev = p->dev;
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index d393160e3e38..258115b10fa9 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -521,10 +521,11 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id)
521 u32 int_status; 521 u32 int_status;
522 dma_addr_t iova; 522 dma_addr_t iova;
523 irqreturn_t ret = IRQ_NONE; 523 irqreturn_t ret = IRQ_NONE;
524 int i; 524 int i, err;
525 525
526 if (WARN_ON(!pm_runtime_get_if_in_use(iommu->dev))) 526 err = pm_runtime_get_if_in_use(iommu->dev);
527 return 0; 527 if (WARN_ON_ONCE(err <= 0))
528 return ret;
528 529
529 if (WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks))) 530 if (WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks)))
530 goto out; 531 goto out;
@@ -620,11 +621,15 @@ static void rk_iommu_zap_iova(struct rk_iommu_domain *rk_domain,
620 spin_lock_irqsave(&rk_domain->iommus_lock, flags); 621 spin_lock_irqsave(&rk_domain->iommus_lock, flags);
621 list_for_each(pos, &rk_domain->iommus) { 622 list_for_each(pos, &rk_domain->iommus) {
622 struct rk_iommu *iommu; 623 struct rk_iommu *iommu;
624 int ret;
623 625
624 iommu = list_entry(pos, struct rk_iommu, node); 626 iommu = list_entry(pos, struct rk_iommu, node);
625 627
626 /* Only zap TLBs of IOMMUs that are powered on. */ 628 /* Only zap TLBs of IOMMUs that are powered on. */
627 if (pm_runtime_get_if_in_use(iommu->dev)) { 629 ret = pm_runtime_get_if_in_use(iommu->dev);
630 if (WARN_ON_ONCE(ret < 0))
631 continue;
632 if (ret) {
628 WARN_ON(clk_bulk_enable(iommu->num_clocks, 633 WARN_ON(clk_bulk_enable(iommu->num_clocks,
629 iommu->clocks)); 634 iommu->clocks));
630 rk_iommu_zap_lines(iommu, iova, size); 635 rk_iommu_zap_lines(iommu, iova, size);
@@ -891,6 +896,7 @@ static void rk_iommu_detach_device(struct iommu_domain *domain,
891 struct rk_iommu *iommu; 896 struct rk_iommu *iommu;
892 struct rk_iommu_domain *rk_domain = to_rk_domain(domain); 897 struct rk_iommu_domain *rk_domain = to_rk_domain(domain);
893 unsigned long flags; 898 unsigned long flags;
899 int ret;
894 900
895 /* Allow 'virtual devices' (eg drm) to detach from domain */ 901 /* Allow 'virtual devices' (eg drm) to detach from domain */
896 iommu = rk_iommu_from_dev(dev); 902 iommu = rk_iommu_from_dev(dev);
@@ -909,7 +915,9 @@ static void rk_iommu_detach_device(struct iommu_domain *domain,
909 list_del_init(&iommu->node); 915 list_del_init(&iommu->node);
910 spin_unlock_irqrestore(&rk_domain->iommus_lock, flags); 916 spin_unlock_irqrestore(&rk_domain->iommus_lock, flags);
911 917
912 if (pm_runtime_get_if_in_use(iommu->dev)) { 918 ret = pm_runtime_get_if_in_use(iommu->dev);
919 WARN_ON_ONCE(ret < 0);
920 if (ret > 0) {
913 rk_iommu_disable(iommu); 921 rk_iommu_disable(iommu);
914 pm_runtime_put(iommu->dev); 922 pm_runtime_put(iommu->dev);
915 } 923 }
@@ -946,7 +954,8 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,
946 list_add_tail(&iommu->node, &rk_domain->iommus); 954 list_add_tail(&iommu->node, &rk_domain->iommus);
947 spin_unlock_irqrestore(&rk_domain->iommus_lock, flags); 955 spin_unlock_irqrestore(&rk_domain->iommus_lock, flags);
948 956
949 if (!pm_runtime_get_if_in_use(iommu->dev)) 957 ret = pm_runtime_get_if_in_use(iommu->dev);
958 if (!ret || WARN_ON_ONCE(ret < 0))
950 return 0; 959 return 0;
951 960
952 ret = rk_iommu_enable(iommu); 961 ret = rk_iommu_enable(iommu);
@@ -1151,17 +1160,6 @@ static int rk_iommu_probe(struct platform_device *pdev)
1151 if (iommu->num_mmu == 0) 1160 if (iommu->num_mmu == 0)
1152 return PTR_ERR(iommu->bases[0]); 1161 return PTR_ERR(iommu->bases[0]);
1153 1162
1154 i = 0;
1155 while ((irq = platform_get_irq(pdev, i++)) != -ENXIO) {
1156 if (irq < 0)
1157 return irq;
1158
1159 err = devm_request_irq(iommu->dev, irq, rk_iommu_irq,
1160 IRQF_SHARED, dev_name(dev), iommu);
1161 if (err)
1162 return err;
1163 }
1164
1165 iommu->reset_disabled = device_property_read_bool(dev, 1163 iommu->reset_disabled = device_property_read_bool(dev,
1166 "rockchip,disable-mmu-reset"); 1164 "rockchip,disable-mmu-reset");
1167 1165
@@ -1218,6 +1216,19 @@ static int rk_iommu_probe(struct platform_device *pdev)
1218 1216
1219 pm_runtime_enable(dev); 1217 pm_runtime_enable(dev);
1220 1218
1219 i = 0;
1220 while ((irq = platform_get_irq(pdev, i++)) != -ENXIO) {
1221 if (irq < 0)
1222 return irq;
1223
1224 err = devm_request_irq(iommu->dev, irq, rk_iommu_irq,
1225 IRQF_SHARED, dev_name(dev), iommu);
1226 if (err) {
1227 pm_runtime_disable(dev);
1228 goto err_remove_sysfs;
1229 }
1230 }
1231
1221 return 0; 1232 return 0;
1222err_remove_sysfs: 1233err_remove_sysfs:
1223 iommu_device_sysfs_remove(&iommu->iommu); 1234 iommu_device_sysfs_remove(&iommu->iommu);
diff --git a/drivers/irqchip/irq-bcm7038-l1.c b/drivers/irqchip/irq-bcm7038-l1.c
index faf734ff4cf3..0f6e30e9009d 100644
--- a/drivers/irqchip/irq-bcm7038-l1.c
+++ b/drivers/irqchip/irq-bcm7038-l1.c
@@ -217,6 +217,7 @@ static int bcm7038_l1_set_affinity(struct irq_data *d,
217 return 0; 217 return 0;
218} 218}
219 219
220#ifdef CONFIG_SMP
220static void bcm7038_l1_cpu_offline(struct irq_data *d) 221static void bcm7038_l1_cpu_offline(struct irq_data *d)
221{ 222{
222 struct cpumask *mask = irq_data_get_affinity_mask(d); 223 struct cpumask *mask = irq_data_get_affinity_mask(d);
@@ -241,6 +242,7 @@ static void bcm7038_l1_cpu_offline(struct irq_data *d)
241 } 242 }
242 irq_set_affinity_locked(d, &new_affinity, false); 243 irq_set_affinity_locked(d, &new_affinity, false);
243} 244}
245#endif
244 246
245static int __init bcm7038_l1_init_one(struct device_node *dn, 247static int __init bcm7038_l1_init_one(struct device_node *dn,
246 unsigned int idx, 248 unsigned int idx,
@@ -293,7 +295,9 @@ static struct irq_chip bcm7038_l1_irq_chip = {
293 .irq_mask = bcm7038_l1_mask, 295 .irq_mask = bcm7038_l1_mask,
294 .irq_unmask = bcm7038_l1_unmask, 296 .irq_unmask = bcm7038_l1_unmask,
295 .irq_set_affinity = bcm7038_l1_set_affinity, 297 .irq_set_affinity = bcm7038_l1_set_affinity,
298#ifdef CONFIG_SMP
296 .irq_cpu_offline = bcm7038_l1_cpu_offline, 299 .irq_cpu_offline = bcm7038_l1_cpu_offline,
300#endif
297}; 301};
298 302
299static int bcm7038_l1_map(struct irq_domain *d, unsigned int virq, 303static int bcm7038_l1_map(struct irq_domain *d, unsigned int virq,
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 316a57530f6d..c2df341ff6fa 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1439,6 +1439,7 @@ static struct irq_chip its_irq_chip = {
1439 * The consequence of the above is that allocation is cost is low, but 1439 * The consequence of the above is that allocation is cost is low, but
1440 * freeing is expensive. We assumes that freeing rarely occurs. 1440 * freeing is expensive. We assumes that freeing rarely occurs.
1441 */ 1441 */
1442#define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */
1442 1443
1443static DEFINE_MUTEX(lpi_range_lock); 1444static DEFINE_MUTEX(lpi_range_lock);
1444static LIST_HEAD(lpi_range_list); 1445static LIST_HEAD(lpi_range_list);
@@ -1625,7 +1626,8 @@ static int __init its_alloc_lpi_tables(void)
1625{ 1626{
1626 phys_addr_t paddr; 1627 phys_addr_t paddr;
1627 1628
1628 lpi_id_bits = GICD_TYPER_ID_BITS(gic_rdists->gicd_typer); 1629 lpi_id_bits = min_t(u32, GICD_TYPER_ID_BITS(gic_rdists->gicd_typer),
1630 ITS_MAX_LPI_NRBITS);
1629 gic_rdists->prop_page = its_allocate_prop_table(GFP_NOWAIT); 1631 gic_rdists->prop_page = its_allocate_prop_table(GFP_NOWAIT);
1630 if (!gic_rdists->prop_page) { 1632 if (!gic_rdists->prop_page) {
1631 pr_err("Failed to allocate PROPBASE\n"); 1633 pr_err("Failed to allocate PROPBASE\n");
diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index e214181b77b7..d5912f1ec884 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -861,7 +861,9 @@ static struct irq_chip gic_chip = {
861 .irq_set_affinity = gic_set_affinity, 861 .irq_set_affinity = gic_set_affinity,
862 .irq_get_irqchip_state = gic_irq_get_irqchip_state, 862 .irq_get_irqchip_state = gic_irq_get_irqchip_state,
863 .irq_set_irqchip_state = gic_irq_set_irqchip_state, 863 .irq_set_irqchip_state = gic_irq_set_irqchip_state,
864 .flags = IRQCHIP_SET_TYPE_MASKED, 864 .flags = IRQCHIP_SET_TYPE_MASKED |
865 IRQCHIP_SKIP_SET_WAKE |
866 IRQCHIP_MASK_ON_SUSPEND,
865}; 867};
866 868
867static struct irq_chip gic_eoimode1_chip = { 869static struct irq_chip gic_eoimode1_chip = {
@@ -874,7 +876,9 @@ static struct irq_chip gic_eoimode1_chip = {
874 .irq_get_irqchip_state = gic_irq_get_irqchip_state, 876 .irq_get_irqchip_state = gic_irq_get_irqchip_state,
875 .irq_set_irqchip_state = gic_irq_set_irqchip_state, 877 .irq_set_irqchip_state = gic_irq_set_irqchip_state,
876 .irq_set_vcpu_affinity = gic_irq_set_vcpu_affinity, 878 .irq_set_vcpu_affinity = gic_irq_set_vcpu_affinity,
877 .flags = IRQCHIP_SET_TYPE_MASKED, 879 .flags = IRQCHIP_SET_TYPE_MASKED |
880 IRQCHIP_SKIP_SET_WAKE |
881 IRQCHIP_MASK_ON_SUSPEND,
878}; 882};
879 883
880#define GIC_ID_NR (1U << GICD_TYPER_ID_BITS(gic_data.rdists.gicd_typer)) 884#define GIC_ID_NR (1U << GICD_TYPER_ID_BITS(gic_data.rdists.gicd_typer))
diff --git a/drivers/irqchip/irq-s3c24xx.c b/drivers/irqchip/irq-s3c24xx.c
index f6fd57ebe6e6..c19766fe8a1a 100644
--- a/drivers/irqchip/irq-s3c24xx.c
+++ b/drivers/irqchip/irq-s3c24xx.c
@@ -250,7 +250,7 @@ static int s3c_irqext0_type(struct irq_data *data, unsigned int type)
250 void __iomem *gpcon_reg; 250 void __iomem *gpcon_reg;
251 unsigned long gpcon_offset, extint_offset; 251 unsigned long gpcon_offset, extint_offset;
252 252
253 if ((data->hwirq >= 0) && (data->hwirq <= 3)) { 253 if (data->hwirq <= 3) {
254 gpcon_reg = S3C2410_GPFCON; 254 gpcon_reg = S3C2410_GPFCON;
255 extint_reg = S3C24XX_EXTINT0; 255 extint_reg = S3C24XX_EXTINT0;
256 gpcon_offset = (data->hwirq) * 2; 256 gpcon_offset = (data->hwirq) * 2;
diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-exti.c
index 3df527fcf4e1..0a2088e12d96 100644
--- a/drivers/irqchip/irq-stm32-exti.c
+++ b/drivers/irqchip/irq-stm32-exti.c
@@ -603,17 +603,24 @@ stm32_exti_host_data *stm32_exti_host_init(const struct stm32_exti_drv_data *dd,
603 sizeof(struct stm32_exti_chip_data), 603 sizeof(struct stm32_exti_chip_data),
604 GFP_KERNEL); 604 GFP_KERNEL);
605 if (!host_data->chips_data) 605 if (!host_data->chips_data)
606 return NULL; 606 goto free_host_data;
607 607
608 host_data->base = of_iomap(node, 0); 608 host_data->base = of_iomap(node, 0);
609 if (!host_data->base) { 609 if (!host_data->base) {
610 pr_err("%pOF: Unable to map registers\n", node); 610 pr_err("%pOF: Unable to map registers\n", node);
611 return NULL; 611 goto free_chips_data;
612 } 612 }
613 613
614 stm32_host_data = host_data; 614 stm32_host_data = host_data;
615 615
616 return host_data; 616 return host_data;
617
618free_chips_data:
619 kfree(host_data->chips_data);
620free_host_data:
621 kfree(host_data);
622
623 return NULL;
617} 624}
618 625
619static struct 626static struct
@@ -665,10 +672,8 @@ static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data,
665 struct irq_domain *domain; 672 struct irq_domain *domain;
666 673
667 host_data = stm32_exti_host_init(drv_data, node); 674 host_data = stm32_exti_host_init(drv_data, node);
668 if (!host_data) { 675 if (!host_data)
669 ret = -ENOMEM; 676 return -ENOMEM;
670 goto out_free_mem;
671 }
672 677
673 domain = irq_domain_add_linear(node, drv_data->bank_nr * IRQS_PER_BANK, 678 domain = irq_domain_add_linear(node, drv_data->bank_nr * IRQS_PER_BANK,
674 &irq_exti_domain_ops, NULL); 679 &irq_exti_domain_ops, NULL);
@@ -725,7 +730,6 @@ out_free_domain:
725 irq_domain_remove(domain); 730 irq_domain_remove(domain);
726out_unmap: 731out_unmap:
727 iounmap(host_data->base); 732 iounmap(host_data->base);
728out_free_mem:
729 kfree(host_data->chips_data); 733 kfree(host_data->chips_data);
730 kfree(host_data); 734 kfree(host_data);
731 return ret; 735 return ret;
@@ -752,10 +756,8 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data,
752 } 756 }
753 757
754 host_data = stm32_exti_host_init(drv_data, node); 758 host_data = stm32_exti_host_init(drv_data, node);
755 if (!host_data) { 759 if (!host_data)
756 ret = -ENOMEM; 760 return -ENOMEM;
757 goto out_free_mem;
758 }
759 761
760 for (i = 0; i < drv_data->bank_nr; i++) 762 for (i = 0; i < drv_data->bank_nr; i++)
761 stm32_exti_chip_init(host_data, i, node); 763 stm32_exti_chip_init(host_data, i, node);
@@ -777,7 +779,6 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data,
777 779
778out_unmap: 780out_unmap:
779 iounmap(host_data->base); 781 iounmap(host_data->base);
780out_free_mem:
781 kfree(host_data->chips_data); 782 kfree(host_data->chips_data);
782 kfree(host_data); 783 kfree(host_data);
783 return ret; 784 return ret;
diff --git a/drivers/irqchip/irq-tango.c b/drivers/irqchip/irq-tango.c
index 0c085303a583..580e2d72b9ba 100644
--- a/drivers/irqchip/irq-tango.c
+++ b/drivers/irqchip/irq-tango.c
@@ -205,8 +205,7 @@ static int __init tangox_irq_init(void __iomem *base, struct resource *baseres,
205 205
206 tangox_irq_domain_init(dom); 206 tangox_irq_domain_init(dom);
207 207
208 irq_set_chained_handler(irq, tangox_irq_handler); 208 irq_set_chained_handler_and_data(irq, tangox_irq_handler, dom);
209 irq_set_handler_data(irq, dom);
210 209
211 return 0; 210 return 0;
212} 211}
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index f266c81f396f..0481223b1deb 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -332,7 +332,7 @@ static int crypt_iv_essiv_init(struct crypt_config *cc)
332 int err; 332 int err;
333 333
334 desc->tfm = essiv->hash_tfm; 334 desc->tfm = essiv->hash_tfm;
335 desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 335 desc->flags = 0;
336 336
337 err = crypto_shash_digest(desc, cc->key, cc->key_size, essiv->salt); 337 err = crypto_shash_digest(desc, cc->key, cc->key_size, essiv->salt);
338 shash_desc_zero(desc); 338 shash_desc_zero(desc);
@@ -606,7 +606,7 @@ static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
606 int i, r; 606 int i, r;
607 607
608 desc->tfm = lmk->hash_tfm; 608 desc->tfm = lmk->hash_tfm;
609 desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 609 desc->flags = 0;
610 610
611 r = crypto_shash_init(desc); 611 r = crypto_shash_init(desc);
612 if (r) 612 if (r)
@@ -768,7 +768,7 @@ static int crypt_iv_tcw_whitening(struct crypt_config *cc,
768 768
769 /* calculate crc32 for every 32bit part and xor it */ 769 /* calculate crc32 for every 32bit part and xor it */
770 desc->tfm = tcw->crc32_tfm; 770 desc->tfm = tcw->crc32_tfm;
771 desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 771 desc->flags = 0;
772 for (i = 0; i < 4; i++) { 772 for (i = 0; i < 4; i++) {
773 r = crypto_shash_init(desc); 773 r = crypto_shash_init(desc);
774 if (r) 774 if (r)
@@ -1251,7 +1251,7 @@ static void crypt_alloc_req_skcipher(struct crypt_config *cc,
1251 * requests if driver request queue is full. 1251 * requests if driver request queue is full.
1252 */ 1252 */
1253 skcipher_request_set_callback(ctx->r.req, 1253 skcipher_request_set_callback(ctx->r.req,
1254 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, 1254 CRYPTO_TFM_REQ_MAY_BACKLOG,
1255 kcryptd_async_done, dmreq_of_req(cc, ctx->r.req)); 1255 kcryptd_async_done, dmreq_of_req(cc, ctx->r.req));
1256} 1256}
1257 1257
@@ -1268,7 +1268,7 @@ static void crypt_alloc_req_aead(struct crypt_config *cc,
1268 * requests if driver request queue is full. 1268 * requests if driver request queue is full.
1269 */ 1269 */
1270 aead_request_set_callback(ctx->r.req_aead, 1270 aead_request_set_callback(ctx->r.req_aead,
1271 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, 1271 CRYPTO_TFM_REQ_MAY_BACKLOG,
1272 kcryptd_async_done, dmreq_of_req(cc, ctx->r.req_aead)); 1272 kcryptd_async_done, dmreq_of_req(cc, ctx->r.req_aead));
1273} 1273}
1274 1274
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 378878599466..89ccb64342de 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -532,7 +532,7 @@ static void section_mac(struct dm_integrity_c *ic, unsigned section, __u8 result
532 unsigned j, size; 532 unsigned j, size;
533 533
534 desc->tfm = ic->journal_mac; 534 desc->tfm = ic->journal_mac;
535 desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 535 desc->flags = 0;
536 536
537 r = crypto_shash_init(desc); 537 r = crypto_shash_init(desc);
538 if (unlikely(r)) { 538 if (unlikely(r)) {
@@ -676,7 +676,7 @@ static void complete_journal_encrypt(struct crypto_async_request *req, int err)
676static bool do_crypt(bool encrypt, struct skcipher_request *req, struct journal_completion *comp) 676static bool do_crypt(bool encrypt, struct skcipher_request *req, struct journal_completion *comp)
677{ 677{
678 int r; 678 int r;
679 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, 679 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
680 complete_journal_encrypt, comp); 680 complete_journal_encrypt, comp);
681 if (likely(encrypt)) 681 if (likely(encrypt))
682 r = crypto_skcipher_encrypt(req); 682 r = crypto_skcipher_encrypt(req);
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index cae689de75fd..5ba067fa0c72 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2010-2011 Neil Brown 2 * Copyright (C) 2010-2011 Neil Brown
3 * Copyright (C) 2010-2017 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This file is released under the GPL. 5 * This file is released under the GPL.
6 */ 6 */
@@ -29,9 +29,6 @@
29 */ 29 */
30#define MIN_RAID456_JOURNAL_SPACE (4*2048) 30#define MIN_RAID456_JOURNAL_SPACE (4*2048)
31 31
32/* Global list of all raid sets */
33static LIST_HEAD(raid_sets);
34
35static bool devices_handle_discard_safely = false; 32static bool devices_handle_discard_safely = false;
36 33
37/* 34/*
@@ -227,7 +224,6 @@ struct rs_layout {
227 224
228struct raid_set { 225struct raid_set {
229 struct dm_target *ti; 226 struct dm_target *ti;
230 struct list_head list;
231 227
232 uint32_t stripe_cache_entries; 228 uint32_t stripe_cache_entries;
233 unsigned long ctr_flags; 229 unsigned long ctr_flags;
@@ -273,19 +269,6 @@ static void rs_config_restore(struct raid_set *rs, struct rs_layout *l)
273 mddev->new_chunk_sectors = l->new_chunk_sectors; 269 mddev->new_chunk_sectors = l->new_chunk_sectors;
274} 270}
275 271
276/* Find any raid_set in active slot for @rs on global list */
277static struct raid_set *rs_find_active(struct raid_set *rs)
278{
279 struct raid_set *r;
280 struct mapped_device *md = dm_table_get_md(rs->ti->table);
281
282 list_for_each_entry(r, &raid_sets, list)
283 if (r != rs && dm_table_get_md(r->ti->table) == md)
284 return r;
285
286 return NULL;
287}
288
289/* raid10 algorithms (i.e. formats) */ 272/* raid10 algorithms (i.e. formats) */
290#define ALGORITHM_RAID10_DEFAULT 0 273#define ALGORITHM_RAID10_DEFAULT 0
291#define ALGORITHM_RAID10_NEAR 1 274#define ALGORITHM_RAID10_NEAR 1
@@ -764,7 +747,6 @@ static struct raid_set *raid_set_alloc(struct dm_target *ti, struct raid_type *r
764 747
765 mddev_init(&rs->md); 748 mddev_init(&rs->md);
766 749
767 INIT_LIST_HEAD(&rs->list);
768 rs->raid_disks = raid_devs; 750 rs->raid_disks = raid_devs;
769 rs->delta_disks = 0; 751 rs->delta_disks = 0;
770 752
@@ -782,9 +764,6 @@ static struct raid_set *raid_set_alloc(struct dm_target *ti, struct raid_type *r
782 for (i = 0; i < raid_devs; i++) 764 for (i = 0; i < raid_devs; i++)
783 md_rdev_init(&rs->dev[i].rdev); 765 md_rdev_init(&rs->dev[i].rdev);
784 766
785 /* Add @rs to global list. */
786 list_add(&rs->list, &raid_sets);
787
788 /* 767 /*
789 * Remaining items to be initialized by further RAID params: 768 * Remaining items to be initialized by further RAID params:
790 * rs->md.persistent 769 * rs->md.persistent
@@ -797,7 +776,7 @@ static struct raid_set *raid_set_alloc(struct dm_target *ti, struct raid_type *r
797 return rs; 776 return rs;
798} 777}
799 778
800/* Free all @rs allocations and remove it from global list. */ 779/* Free all @rs allocations */
801static void raid_set_free(struct raid_set *rs) 780static void raid_set_free(struct raid_set *rs)
802{ 781{
803 int i; 782 int i;
@@ -815,8 +794,6 @@ static void raid_set_free(struct raid_set *rs)
815 dm_put_device(rs->ti, rs->dev[i].data_dev); 794 dm_put_device(rs->ti, rs->dev[i].data_dev);
816 } 795 }
817 796
818 list_del(&rs->list);
819
820 kfree(rs); 797 kfree(rs);
821} 798}
822 799
@@ -2649,7 +2626,7 @@ static int rs_adjust_data_offsets(struct raid_set *rs)
2649 return 0; 2626 return 0;
2650 } 2627 }
2651 2628
2652 /* HM FIXME: get InSync raid_dev? */ 2629 /* HM FIXME: get In_Sync raid_dev? */
2653 rdev = &rs->dev[0].rdev; 2630 rdev = &rs->dev[0].rdev;
2654 2631
2655 if (rs->delta_disks < 0) { 2632 if (rs->delta_disks < 0) {
@@ -3149,6 +3126,11 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3149 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); 3126 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags);
3150 rs_set_new(rs); 3127 rs_set_new(rs);
3151 } else if (rs_is_recovering(rs)) { 3128 } else if (rs_is_recovering(rs)) {
3129 /* Rebuild particular devices */
3130 if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) {
3131 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags);
3132 rs_setup_recovery(rs, MaxSector);
3133 }
3152 /* A recovering raid set may be resized */ 3134 /* A recovering raid set may be resized */
3153 ; /* skip setup rs */ 3135 ; /* skip setup rs */
3154 } else if (rs_is_reshaping(rs)) { 3136 } else if (rs_is_reshaping(rs)) {
@@ -3242,6 +3224,8 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3242 /* Start raid set read-only and assumed clean to change in raid_resume() */ 3224 /* Start raid set read-only and assumed clean to change in raid_resume() */
3243 rs->md.ro = 1; 3225 rs->md.ro = 1;
3244 rs->md.in_sync = 1; 3226 rs->md.in_sync = 1;
3227
3228 /* Keep array frozen */
3245 set_bit(MD_RECOVERY_FROZEN, &rs->md.recovery); 3229 set_bit(MD_RECOVERY_FROZEN, &rs->md.recovery);
3246 3230
3247 /* Has to be held on running the array */ 3231 /* Has to be held on running the array */
@@ -3265,7 +3249,7 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3265 rs->callbacks.congested_fn = raid_is_congested; 3249 rs->callbacks.congested_fn = raid_is_congested;
3266 dm_table_add_target_callbacks(ti->table, &rs->callbacks); 3250 dm_table_add_target_callbacks(ti->table, &rs->callbacks);
3267 3251
3268 /* If raid4/5/6 journal mode explictely requested (only possible with journal dev) -> set it */ 3252 /* If raid4/5/6 journal mode explicitly requested (only possible with journal dev) -> set it */
3269 if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) { 3253 if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) {
3270 r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode); 3254 r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode);
3271 if (r) { 3255 if (r) {
@@ -3350,32 +3334,53 @@ static int raid_map(struct dm_target *ti, struct bio *bio)
3350 return DM_MAPIO_SUBMITTED; 3334 return DM_MAPIO_SUBMITTED;
3351} 3335}
3352 3336
3353/* Return string describing the current sync action of @mddev */ 3337/* Return sync state string for @state */
3354static const char *decipher_sync_action(struct mddev *mddev, unsigned long recovery) 3338enum sync_state { st_frozen, st_reshape, st_resync, st_check, st_repair, st_recover, st_idle };
3339static const char *sync_str(enum sync_state state)
3340{
3341 /* Has to be in above sync_state order! */
3342 static const char *sync_strs[] = {
3343 "frozen",
3344 "reshape",
3345 "resync",
3346 "check",
3347 "repair",
3348 "recover",
3349 "idle"
3350 };
3351
3352 return __within_range(state, 0, ARRAY_SIZE(sync_strs) - 1) ? sync_strs[state] : "undef";
3353};
3354
3355/* Return enum sync_state for @mddev derived from @recovery flags */
3356static const enum sync_state decipher_sync_action(struct mddev *mddev, unsigned long recovery)
3355{ 3357{
3356 if (test_bit(MD_RECOVERY_FROZEN, &recovery)) 3358 if (test_bit(MD_RECOVERY_FROZEN, &recovery))
3357 return "frozen"; 3359 return st_frozen;
3358 3360
3359 /* The MD sync thread can be done with io but still be running */ 3361 /* The MD sync thread can be done with io or be interrupted but still be running */
3360 if (!test_bit(MD_RECOVERY_DONE, &recovery) && 3362 if (!test_bit(MD_RECOVERY_DONE, &recovery) &&
3361 (test_bit(MD_RECOVERY_RUNNING, &recovery) || 3363 (test_bit(MD_RECOVERY_RUNNING, &recovery) ||
3362 (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &recovery)))) { 3364 (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &recovery)))) {
3363 if (test_bit(MD_RECOVERY_RESHAPE, &recovery)) 3365 if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
3364 return "reshape"; 3366 return st_reshape;
3365 3367
3366 if (test_bit(MD_RECOVERY_SYNC, &recovery)) { 3368 if (test_bit(MD_RECOVERY_SYNC, &recovery)) {
3367 if (!test_bit(MD_RECOVERY_REQUESTED, &recovery)) 3369 if (!test_bit(MD_RECOVERY_REQUESTED, &recovery))
3368 return "resync"; 3370 return st_resync;
3369 else if (test_bit(MD_RECOVERY_CHECK, &recovery)) 3371 if (test_bit(MD_RECOVERY_CHECK, &recovery))
3370 return "check"; 3372 return st_check;
3371 return "repair"; 3373 return st_repair;
3372 } 3374 }
3373 3375
3374 if (test_bit(MD_RECOVERY_RECOVER, &recovery)) 3376 if (test_bit(MD_RECOVERY_RECOVER, &recovery))
3375 return "recover"; 3377 return st_recover;
3378
3379 if (mddev->reshape_position != MaxSector)
3380 return st_reshape;
3376 } 3381 }
3377 3382
3378 return "idle"; 3383 return st_idle;
3379} 3384}
3380 3385
3381/* 3386/*
@@ -3409,6 +3414,7 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
3409 sector_t resync_max_sectors) 3414 sector_t resync_max_sectors)
3410{ 3415{
3411 sector_t r; 3416 sector_t r;
3417 enum sync_state state;
3412 struct mddev *mddev = &rs->md; 3418 struct mddev *mddev = &rs->md;
3413 3419
3414 clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); 3420 clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags);
@@ -3419,20 +3425,14 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
3419 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); 3425 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags);
3420 3426
3421 } else { 3427 } else {
3422 if (!test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags) && 3428 state = decipher_sync_action(mddev, recovery);
3423 !test_bit(MD_RECOVERY_INTR, &recovery) && 3429
3424 (test_bit(MD_RECOVERY_NEEDED, &recovery) || 3430 if (state == st_idle && !test_bit(MD_RECOVERY_INTR, &recovery))
3425 test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
3426 test_bit(MD_RECOVERY_RUNNING, &recovery)))
3427 r = mddev->curr_resync_completed;
3428 else
3429 r = mddev->recovery_cp; 3431 r = mddev->recovery_cp;
3432 else
3433 r = mddev->curr_resync_completed;
3430 3434
3431 if (r >= resync_max_sectors && 3435 if (state == st_idle && r >= resync_max_sectors) {
3432 (!test_bit(MD_RECOVERY_REQUESTED, &recovery) ||
3433 (!test_bit(MD_RECOVERY_FROZEN, &recovery) &&
3434 !test_bit(MD_RECOVERY_NEEDED, &recovery) &&
3435 !test_bit(MD_RECOVERY_RUNNING, &recovery)))) {
3436 /* 3436 /*
3437 * Sync complete. 3437 * Sync complete.
3438 */ 3438 */
@@ -3440,24 +3440,20 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
3440 if (test_bit(MD_RECOVERY_RECOVER, &recovery)) 3440 if (test_bit(MD_RECOVERY_RECOVER, &recovery))
3441 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); 3441 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags);
3442 3442
3443 } else if (test_bit(MD_RECOVERY_RECOVER, &recovery)) { 3443 } else if (state == st_recover)
3444 /* 3444 /*
3445 * In case we are recovering, the array is not in sync 3445 * In case we are recovering, the array is not in sync
3446 * and health chars should show the recovering legs. 3446 * and health chars should show the recovering legs.
3447 */ 3447 */
3448 ; 3448 ;
3449 3449 else if (state == st_resync)
3450 } else if (test_bit(MD_RECOVERY_SYNC, &recovery) &&
3451 !test_bit(MD_RECOVERY_REQUESTED, &recovery)) {
3452 /* 3450 /*
3453 * If "resync" is occurring, the raid set 3451 * If "resync" is occurring, the raid set
3454 * is or may be out of sync hence the health 3452 * is or may be out of sync hence the health
3455 * characters shall be 'a'. 3453 * characters shall be 'a'.
3456 */ 3454 */
3457 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); 3455 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags);
3458 3456 else if (state == st_reshape)
3459 } else if (test_bit(MD_RECOVERY_RESHAPE, &recovery) &&
3460 !test_bit(MD_RECOVERY_REQUESTED, &recovery)) {
3461 /* 3457 /*
3462 * If "reshape" is occurring, the raid set 3458 * If "reshape" is occurring, the raid set
3463 * is or may be out of sync hence the health 3459 * is or may be out of sync hence the health
@@ -3465,7 +3461,7 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
3465 */ 3461 */
3466 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); 3462 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags);
3467 3463
3468 } else if (test_bit(MD_RECOVERY_REQUESTED, &recovery)) { 3464 else if (state == st_check || state == st_repair)
3469 /* 3465 /*
3470 * If "check" or "repair" is occurring, the raid set has 3466 * If "check" or "repair" is occurring, the raid set has
3471 * undergone an initial sync and the health characters 3467 * undergone an initial sync and the health characters
@@ -3473,12 +3469,12 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
3473 */ 3469 */
3474 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); 3470 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags);
3475 3471
3476 } else { 3472 else {
3477 struct md_rdev *rdev; 3473 struct md_rdev *rdev;
3478 3474
3479 /* 3475 /*
3480 * We are idle and recovery is needed, prevent 'A' chars race 3476 * We are idle and recovery is needed, prevent 'A' chars race
3481 * caused by components still set to in-sync by constrcuctor. 3477 * caused by components still set to in-sync by constructor.
3482 */ 3478 */
3483 if (test_bit(MD_RECOVERY_NEEDED, &recovery)) 3479 if (test_bit(MD_RECOVERY_NEEDED, &recovery))
3484 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); 3480 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags);
@@ -3542,7 +3538,7 @@ static void raid_status(struct dm_target *ti, status_type_t type,
3542 progress = rs_get_progress(rs, recovery, resync_max_sectors); 3538 progress = rs_get_progress(rs, recovery, resync_max_sectors);
3543 resync_mismatches = (mddev->last_sync_action && !strcasecmp(mddev->last_sync_action, "check")) ? 3539 resync_mismatches = (mddev->last_sync_action && !strcasecmp(mddev->last_sync_action, "check")) ?
3544 atomic64_read(&mddev->resync_mismatches) : 0; 3540 atomic64_read(&mddev->resync_mismatches) : 0;
3545 sync_action = decipher_sync_action(&rs->md, recovery); 3541 sync_action = sync_str(decipher_sync_action(&rs->md, recovery));
3546 3542
3547 /* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */ 3543 /* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */
3548 for (i = 0; i < rs->raid_disks; i++) 3544 for (i = 0; i < rs->raid_disks; i++)
@@ -3892,14 +3888,13 @@ static int rs_start_reshape(struct raid_set *rs)
3892 struct mddev *mddev = &rs->md; 3888 struct mddev *mddev = &rs->md;
3893 struct md_personality *pers = mddev->pers; 3889 struct md_personality *pers = mddev->pers;
3894 3890
3891 /* Don't allow the sync thread to work until the table gets reloaded. */
3892 set_bit(MD_RECOVERY_WAIT, &mddev->recovery);
3893
3895 r = rs_setup_reshape(rs); 3894 r = rs_setup_reshape(rs);
3896 if (r) 3895 if (r)
3897 return r; 3896 return r;
3898 3897
3899 /* Need to be resumed to be able to start reshape, recovery is frozen until raid_resume() though */
3900 if (test_and_clear_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags))
3901 mddev_resume(mddev);
3902
3903 /* 3898 /*
3904 * Check any reshape constraints enforced by the personalility 3899 * Check any reshape constraints enforced by the personalility
3905 * 3900 *
@@ -3923,10 +3918,6 @@ static int rs_start_reshape(struct raid_set *rs)
3923 } 3918 }
3924 } 3919 }
3925 3920
3926 /* Suspend because a resume will happen in raid_resume() */
3927 set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags);
3928 mddev_suspend(mddev);
3929
3930 /* 3921 /*
3931 * Now reshape got set up, update superblocks to 3922 * Now reshape got set up, update superblocks to
3932 * reflect the fact so that a table reload will 3923 * reflect the fact so that a table reload will
@@ -3947,29 +3938,6 @@ static int raid_preresume(struct dm_target *ti)
3947 if (test_and_set_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags)) 3938 if (test_and_set_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags))
3948 return 0; 3939 return 0;
3949 3940
3950 if (!test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) {
3951 struct raid_set *rs_active = rs_find_active(rs);
3952
3953 if (rs_active) {
3954 /*
3955 * In case no rebuilds have been requested
3956 * and an active table slot exists, copy
3957 * current resynchonization completed and
3958 * reshape position pointers across from
3959 * suspended raid set in the active slot.
3960 *
3961 * This resumes the new mapping at current
3962 * offsets to continue recover/reshape without
3963 * necessarily redoing a raid set partially or
3964 * causing data corruption in case of a reshape.
3965 */
3966 if (rs_active->md.curr_resync_completed != MaxSector)
3967 mddev->curr_resync_completed = rs_active->md.curr_resync_completed;
3968 if (rs_active->md.reshape_position != MaxSector)
3969 mddev->reshape_position = rs_active->md.reshape_position;
3970 }
3971 }
3972
3973 /* 3941 /*
3974 * The superblocks need to be updated on disk if the 3942 * The superblocks need to be updated on disk if the
3975 * array is new or new devices got added (thus zeroed 3943 * array is new or new devices got added (thus zeroed
@@ -4046,7 +4014,7 @@ static void raid_resume(struct dm_target *ti)
4046 4014
4047static struct target_type raid_target = { 4015static struct target_type raid_target = {
4048 .name = "raid", 4016 .name = "raid",
4049 .version = {1, 13, 2}, 4017 .version = {1, 14, 0},
4050 .module = THIS_MODULE, 4018 .module = THIS_MODULE,
4051 .ctr = raid_ctr, 4019 .ctr = raid_ctr,
4052 .dtr = raid_dtr, 4020 .dtr = raid_dtr,
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index 72142021b5c9..74f6770c70b1 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -189,6 +189,12 @@ struct dm_pool_metadata {
189 sector_t data_block_size; 189 sector_t data_block_size;
190 190
191 /* 191 /*
192 * We reserve a section of the metadata for commit overhead.
193 * All reported space does *not* include this.
194 */
195 dm_block_t metadata_reserve;
196
197 /*
192 * Set if a transaction has to be aborted but the attempt to roll back 198 * Set if a transaction has to be aborted but the attempt to roll back
193 * to the previous (good) transaction failed. The only pool metadata 199 * to the previous (good) transaction failed. The only pool metadata
194 * operation possible in this state is the closing of the device. 200 * operation possible in this state is the closing of the device.
@@ -816,6 +822,22 @@ static int __commit_transaction(struct dm_pool_metadata *pmd)
816 return dm_tm_commit(pmd->tm, sblock); 822 return dm_tm_commit(pmd->tm, sblock);
817} 823}
818 824
825static void __set_metadata_reserve(struct dm_pool_metadata *pmd)
826{
827 int r;
828 dm_block_t total;
829 dm_block_t max_blocks = 4096; /* 16M */
830
831 r = dm_sm_get_nr_blocks(pmd->metadata_sm, &total);
832 if (r) {
833 DMERR("could not get size of metadata device");
834 pmd->metadata_reserve = max_blocks;
835 } else {
836 sector_div(total, 10);
837 pmd->metadata_reserve = min(max_blocks, total);
838 }
839}
840
819struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev, 841struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
820 sector_t data_block_size, 842 sector_t data_block_size,
821 bool format_device) 843 bool format_device)
@@ -849,6 +871,8 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
849 return ERR_PTR(r); 871 return ERR_PTR(r);
850 } 872 }
851 873
874 __set_metadata_reserve(pmd);
875
852 return pmd; 876 return pmd;
853} 877}
854 878
@@ -1820,6 +1844,13 @@ int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
1820 down_read(&pmd->root_lock); 1844 down_read(&pmd->root_lock);
1821 if (!pmd->fail_io) 1845 if (!pmd->fail_io)
1822 r = dm_sm_get_nr_free(pmd->metadata_sm, result); 1846 r = dm_sm_get_nr_free(pmd->metadata_sm, result);
1847
1848 if (!r) {
1849 if (*result < pmd->metadata_reserve)
1850 *result = 0;
1851 else
1852 *result -= pmd->metadata_reserve;
1853 }
1823 up_read(&pmd->root_lock); 1854 up_read(&pmd->root_lock);
1824 1855
1825 return r; 1856 return r;
@@ -1932,8 +1963,11 @@ int dm_pool_resize_metadata_dev(struct dm_pool_metadata *pmd, dm_block_t new_cou
1932 int r = -EINVAL; 1963 int r = -EINVAL;
1933 1964
1934 down_write(&pmd->root_lock); 1965 down_write(&pmd->root_lock);
1935 if (!pmd->fail_io) 1966 if (!pmd->fail_io) {
1936 r = __resize_space_map(pmd->metadata_sm, new_count); 1967 r = __resize_space_map(pmd->metadata_sm, new_count);
1968 if (!r)
1969 __set_metadata_reserve(pmd);
1970 }
1937 up_write(&pmd->root_lock); 1971 up_write(&pmd->root_lock);
1938 1972
1939 return r; 1973 return r;
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 7bd60a150f8f..aaf1ad481ee8 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -200,7 +200,13 @@ struct dm_thin_new_mapping;
200enum pool_mode { 200enum pool_mode {
201 PM_WRITE, /* metadata may be changed */ 201 PM_WRITE, /* metadata may be changed */
202 PM_OUT_OF_DATA_SPACE, /* metadata may be changed, though data may not be allocated */ 202 PM_OUT_OF_DATA_SPACE, /* metadata may be changed, though data may not be allocated */
203
204 /*
205 * Like READ_ONLY, except may switch back to WRITE on metadata resize. Reported as READ_ONLY.
206 */
207 PM_OUT_OF_METADATA_SPACE,
203 PM_READ_ONLY, /* metadata may not be changed */ 208 PM_READ_ONLY, /* metadata may not be changed */
209
204 PM_FAIL, /* all I/O fails */ 210 PM_FAIL, /* all I/O fails */
205}; 211};
206 212
@@ -1371,7 +1377,35 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
1371 1377
1372static void requeue_bios(struct pool *pool); 1378static void requeue_bios(struct pool *pool);
1373 1379
1374static void check_for_space(struct pool *pool) 1380static bool is_read_only_pool_mode(enum pool_mode mode)
1381{
1382 return (mode == PM_OUT_OF_METADATA_SPACE || mode == PM_READ_ONLY);
1383}
1384
1385static bool is_read_only(struct pool *pool)
1386{
1387 return is_read_only_pool_mode(get_pool_mode(pool));
1388}
1389
1390static void check_for_metadata_space(struct pool *pool)
1391{
1392 int r;
1393 const char *ooms_reason = NULL;
1394 dm_block_t nr_free;
1395
1396 r = dm_pool_get_free_metadata_block_count(pool->pmd, &nr_free);
1397 if (r)
1398 ooms_reason = "Could not get free metadata blocks";
1399 else if (!nr_free)
1400 ooms_reason = "No free metadata blocks";
1401
1402 if (ooms_reason && !is_read_only(pool)) {
1403 DMERR("%s", ooms_reason);
1404 set_pool_mode(pool, PM_OUT_OF_METADATA_SPACE);
1405 }
1406}
1407
1408static void check_for_data_space(struct pool *pool)
1375{ 1409{
1376 int r; 1410 int r;
1377 dm_block_t nr_free; 1411 dm_block_t nr_free;
@@ -1397,14 +1431,16 @@ static int commit(struct pool *pool)
1397{ 1431{
1398 int r; 1432 int r;
1399 1433
1400 if (get_pool_mode(pool) >= PM_READ_ONLY) 1434 if (get_pool_mode(pool) >= PM_OUT_OF_METADATA_SPACE)
1401 return -EINVAL; 1435 return -EINVAL;
1402 1436
1403 r = dm_pool_commit_metadata(pool->pmd); 1437 r = dm_pool_commit_metadata(pool->pmd);
1404 if (r) 1438 if (r)
1405 metadata_operation_failed(pool, "dm_pool_commit_metadata", r); 1439 metadata_operation_failed(pool, "dm_pool_commit_metadata", r);
1406 else 1440 else {
1407 check_for_space(pool); 1441 check_for_metadata_space(pool);
1442 check_for_data_space(pool);
1443 }
1408 1444
1409 return r; 1445 return r;
1410} 1446}
@@ -1470,6 +1506,19 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
1470 return r; 1506 return r;
1471 } 1507 }
1472 1508
1509 r = dm_pool_get_free_metadata_block_count(pool->pmd, &free_blocks);
1510 if (r) {
1511 metadata_operation_failed(pool, "dm_pool_get_free_metadata_block_count", r);
1512 return r;
1513 }
1514
1515 if (!free_blocks) {
1516 /* Let's commit before we use up the metadata reserve. */
1517 r = commit(pool);
1518 if (r)
1519 return r;
1520 }
1521
1473 return 0; 1522 return 0;
1474} 1523}
1475 1524
@@ -1501,6 +1550,7 @@ static blk_status_t should_error_unserviceable_bio(struct pool *pool)
1501 case PM_OUT_OF_DATA_SPACE: 1550 case PM_OUT_OF_DATA_SPACE:
1502 return pool->pf.error_if_no_space ? BLK_STS_NOSPC : 0; 1551 return pool->pf.error_if_no_space ? BLK_STS_NOSPC : 0;
1503 1552
1553 case PM_OUT_OF_METADATA_SPACE:
1504 case PM_READ_ONLY: 1554 case PM_READ_ONLY:
1505 case PM_FAIL: 1555 case PM_FAIL:
1506 return BLK_STS_IOERR; 1556 return BLK_STS_IOERR;
@@ -2464,8 +2514,9 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
2464 error_retry_list(pool); 2514 error_retry_list(pool);
2465 break; 2515 break;
2466 2516
2517 case PM_OUT_OF_METADATA_SPACE:
2467 case PM_READ_ONLY: 2518 case PM_READ_ONLY:
2468 if (old_mode != new_mode) 2519 if (!is_read_only_pool_mode(old_mode))
2469 notify_of_pool_mode_change(pool, "read-only"); 2520 notify_of_pool_mode_change(pool, "read-only");
2470 dm_pool_metadata_read_only(pool->pmd); 2521 dm_pool_metadata_read_only(pool->pmd);
2471 pool->process_bio = process_bio_read_only; 2522 pool->process_bio = process_bio_read_only;
@@ -3403,6 +3454,10 @@ static int maybe_resize_metadata_dev(struct dm_target *ti, bool *need_commit)
3403 DMINFO("%s: growing the metadata device from %llu to %llu blocks", 3454 DMINFO("%s: growing the metadata device from %llu to %llu blocks",
3404 dm_device_name(pool->pool_md), 3455 dm_device_name(pool->pool_md),
3405 sb_metadata_dev_size, metadata_dev_size); 3456 sb_metadata_dev_size, metadata_dev_size);
3457
3458 if (get_pool_mode(pool) == PM_OUT_OF_METADATA_SPACE)
3459 set_pool_mode(pool, PM_WRITE);
3460
3406 r = dm_pool_resize_metadata_dev(pool->pmd, metadata_dev_size); 3461 r = dm_pool_resize_metadata_dev(pool->pmd, metadata_dev_size);
3407 if (r) { 3462 if (r) {
3408 metadata_operation_failed(pool, "dm_pool_resize_metadata_dev", r); 3463 metadata_operation_failed(pool, "dm_pool_resize_metadata_dev", r);
@@ -3707,7 +3762,7 @@ static int pool_message(struct dm_target *ti, unsigned argc, char **argv,
3707 struct pool_c *pt = ti->private; 3762 struct pool_c *pt = ti->private;
3708 struct pool *pool = pt->pool; 3763 struct pool *pool = pt->pool;
3709 3764
3710 if (get_pool_mode(pool) >= PM_READ_ONLY) { 3765 if (get_pool_mode(pool) >= PM_OUT_OF_METADATA_SPACE) {
3711 DMERR("%s: unable to service pool target messages in READ_ONLY or FAIL mode", 3766 DMERR("%s: unable to service pool target messages in READ_ONLY or FAIL mode",
3712 dm_device_name(pool->pool_md)); 3767 dm_device_name(pool->pool_md));
3713 return -EOPNOTSUPP; 3768 return -EOPNOTSUPP;
@@ -3781,6 +3836,7 @@ static void pool_status(struct dm_target *ti, status_type_t type,
3781 dm_block_t nr_blocks_data; 3836 dm_block_t nr_blocks_data;
3782 dm_block_t nr_blocks_metadata; 3837 dm_block_t nr_blocks_metadata;
3783 dm_block_t held_root; 3838 dm_block_t held_root;
3839 enum pool_mode mode;
3784 char buf[BDEVNAME_SIZE]; 3840 char buf[BDEVNAME_SIZE];
3785 char buf2[BDEVNAME_SIZE]; 3841 char buf2[BDEVNAME_SIZE];
3786 struct pool_c *pt = ti->private; 3842 struct pool_c *pt = ti->private;
@@ -3851,9 +3907,10 @@ static void pool_status(struct dm_target *ti, status_type_t type,
3851 else 3907 else
3852 DMEMIT("- "); 3908 DMEMIT("- ");
3853 3909
3854 if (pool->pf.mode == PM_OUT_OF_DATA_SPACE) 3910 mode = get_pool_mode(pool);
3911 if (mode == PM_OUT_OF_DATA_SPACE)
3855 DMEMIT("out_of_data_space "); 3912 DMEMIT("out_of_data_space ");
3856 else if (pool->pf.mode == PM_READ_ONLY) 3913 else if (is_read_only_pool_mode(mode))
3857 DMEMIT("ro "); 3914 DMEMIT("ro ");
3858 else 3915 else
3859 DMEMIT("rw "); 3916 DMEMIT("rw ");
diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 12decdbd722d..fc65f0dedf7f 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -99,10 +99,26 @@ static int verity_hash_update(struct dm_verity *v, struct ahash_request *req,
99{ 99{
100 struct scatterlist sg; 100 struct scatterlist sg;
101 101
102 sg_init_one(&sg, data, len); 102 if (likely(!is_vmalloc_addr(data))) {
103 ahash_request_set_crypt(req, &sg, NULL, len); 103 sg_init_one(&sg, data, len);
104 104 ahash_request_set_crypt(req, &sg, NULL, len);
105 return crypto_wait_req(crypto_ahash_update(req), wait); 105 return crypto_wait_req(crypto_ahash_update(req), wait);
106 } else {
107 do {
108 int r;
109 size_t this_step = min_t(size_t, len, PAGE_SIZE - offset_in_page(data));
110 flush_kernel_vmap_range((void *)data, this_step);
111 sg_init_table(&sg, 1);
112 sg_set_page(&sg, vmalloc_to_page(data), this_step, offset_in_page(data));
113 ahash_request_set_crypt(req, &sg, NULL, this_step);
114 r = crypto_wait_req(crypto_ahash_update(req), wait);
115 if (unlikely(r))
116 return r;
117 data += this_step;
118 len -= this_step;
119 } while (len);
120 return 0;
121 }
106} 122}
107 123
108/* 124/*
diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 3a28a68f184c..5f1f80d424dd 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -268,9 +268,8 @@ static int persistent_memory_claim(struct dm_writecache *wc)
268 i = 0; 268 i = 0;
269 do { 269 do {
270 long daa; 270 long daa;
271 void *dummy_addr;
272 daa = dax_direct_access(wc->ssd_dev->dax_dev, i, p - i, 271 daa = dax_direct_access(wc->ssd_dev->dax_dev, i, p - i,
273 &dummy_addr, &pfn); 272 NULL, &pfn);
274 if (daa <= 0) { 273 if (daa <= 0) {
275 r = daa ? daa : -EINVAL; 274 r = daa ? daa : -EINVAL;
276 goto err3; 275 goto err3;
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 94329e03001e..0b2af6e74fc3 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1276,18 +1276,18 @@ static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)
1276static int resync_finish(struct mddev *mddev) 1276static int resync_finish(struct mddev *mddev)
1277{ 1277{
1278 struct md_cluster_info *cinfo = mddev->cluster_info; 1278 struct md_cluster_info *cinfo = mddev->cluster_info;
1279 int ret = 0;
1279 1280
1280 clear_bit(MD_RESYNCING_REMOTE, &mddev->recovery); 1281 clear_bit(MD_RESYNCING_REMOTE, &mddev->recovery);
1281 dlm_unlock_sync(cinfo->resync_lockres);
1282 1282
1283 /* 1283 /*
1284 * If resync thread is interrupted so we can't say resync is finished, 1284 * If resync thread is interrupted so we can't say resync is finished,
1285 * another node will launch resync thread to continue. 1285 * another node will launch resync thread to continue.
1286 */ 1286 */
1287 if (test_bit(MD_CLOSING, &mddev->flags)) 1287 if (!test_bit(MD_CLOSING, &mddev->flags))
1288 return 0; 1288 ret = resync_info_update(mddev, 0, 0);
1289 else 1289 dlm_unlock_sync(cinfo->resync_lockres);
1290 return resync_info_update(mddev, 0, 0); 1290 return ret;
1291} 1291}
1292 1292
1293static int area_resyncing(struct mddev *mddev, int direction, 1293static int area_resyncing(struct mddev *mddev, int direction,
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 981898049491..d6f7978b4449 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -4529,11 +4529,12 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,
4529 allow_barrier(conf); 4529 allow_barrier(conf);
4530 } 4530 }
4531 4531
4532 raise_barrier(conf, 0);
4532read_more: 4533read_more:
4533 /* Now schedule reads for blocks from sector_nr to last */ 4534 /* Now schedule reads for blocks from sector_nr to last */
4534 r10_bio = raid10_alloc_init_r10buf(conf); 4535 r10_bio = raid10_alloc_init_r10buf(conf);
4535 r10_bio->state = 0; 4536 r10_bio->state = 0;
4536 raise_barrier(conf, sectors_done != 0); 4537 raise_barrier(conf, 1);
4537 atomic_set(&r10_bio->remaining, 0); 4538 atomic_set(&r10_bio->remaining, 0);
4538 r10_bio->mddev = mddev; 4539 r10_bio->mddev = mddev;
4539 r10_bio->sector = sector_nr; 4540 r10_bio->sector = sector_nr;
@@ -4629,6 +4630,8 @@ read_more:
4629 if (sector_nr <= last) 4630 if (sector_nr <= last)
4630 goto read_more; 4631 goto read_more;
4631 4632
4633 lower_barrier(conf);
4634
4632 /* Now that we have done the whole section we can 4635 /* Now that we have done the whole section we can
4633 * update reshape_progress 4636 * update reshape_progress
4634 */ 4637 */
diff --git a/drivers/md/raid5-log.h b/drivers/md/raid5-log.h
index a001808a2b77..bfb811407061 100644
--- a/drivers/md/raid5-log.h
+++ b/drivers/md/raid5-log.h
@@ -46,6 +46,11 @@ extern 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);
48 48
49static inline bool raid5_has_log(struct r5conf *conf)
50{
51 return test_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
52}
53
49static inline bool raid5_has_ppl(struct r5conf *conf) 54static inline bool raid5_has_ppl(struct r5conf *conf)
50{ 55{
51 return test_bit(MD_HAS_PPL, &conf->mddev->flags); 56 return test_bit(MD_HAS_PPL, &conf->mddev->flags);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 4ce0d7502fad..e4e98f47865d 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -733,7 +733,7 @@ static bool stripe_can_batch(struct stripe_head *sh)
733{ 733{
734 struct r5conf *conf = sh->raid_conf; 734 struct r5conf *conf = sh->raid_conf;
735 735
736 if (conf->log || raid5_has_ppl(conf)) 736 if (raid5_has_log(conf) || raid5_has_ppl(conf))
737 return false; 737 return false;
738 return test_bit(STRIPE_BATCH_READY, &sh->state) && 738 return test_bit(STRIPE_BATCH_READY, &sh->state) &&
739 !test_bit(STRIPE_BITMAP_PENDING, &sh->state) && 739 !test_bit(STRIPE_BITMAP_PENDING, &sh->state) &&
@@ -7737,7 +7737,7 @@ static int raid5_resize(struct mddev *mddev, sector_t sectors)
7737 sector_t newsize; 7737 sector_t newsize;
7738 struct r5conf *conf = mddev->private; 7738 struct r5conf *conf = mddev->private;
7739 7739
7740 if (conf->log || raid5_has_ppl(conf)) 7740 if (raid5_has_log(conf) || raid5_has_ppl(conf))
7741 return -EINVAL; 7741 return -EINVAL;
7742 sectors &= ~((sector_t)conf->chunk_sectors - 1); 7742 sectors &= ~((sector_t)conf->chunk_sectors - 1);
7743 newsize = raid5_size(mddev, sectors, mddev->raid_disks); 7743 newsize = raid5_size(mddev, sectors, mddev->raid_disks);
@@ -7788,7 +7788,7 @@ static int check_reshape(struct mddev *mddev)
7788{ 7788{
7789 struct r5conf *conf = mddev->private; 7789 struct r5conf *conf = mddev->private;
7790 7790
7791 if (conf->log || raid5_has_ppl(conf)) 7791 if (raid5_has_log(conf) || raid5_has_ppl(conf))
7792 return -EINVAL; 7792 return -EINVAL;
7793 if (mddev->delta_disks == 0 && 7793 if (mddev->delta_disks == 0 &&
7794 mddev->new_layout == mddev->layout && 7794 mddev->new_layout == mddev->layout &&
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index fcdf3d5dc4b6..3bae24b15eaa 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -585,18 +585,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
585 entity->num_links = 0; 585 entity->num_links = 0;
586 entity->num_backlinks = 0; 586 entity->num_backlinks = 0;
587 587
588 if (!ida_pre_get(&mdev->entity_internal_idx, GFP_KERNEL)) 588 ret = ida_alloc_min(&mdev->entity_internal_idx, 1, GFP_KERNEL);
589 return -ENOMEM; 589 if (ret < 0)
590
591 mutex_lock(&mdev->graph_mutex);
592
593 ret = ida_get_new_above(&mdev->entity_internal_idx, 1,
594 &entity->internal_idx);
595 if (ret < 0) {
596 mutex_unlock(&mdev->graph_mutex);
597 return ret; 590 return ret;
598 } 591 entity->internal_idx = ret;
599 592
593 mutex_lock(&mdev->graph_mutex);
600 mdev->entity_internal_idx_max = 594 mdev->entity_internal_idx_max =
601 max(mdev->entity_internal_idx_max, entity->internal_idx); 595 max(mdev->entity_internal_idx_max, entity->internal_idx);
602 596
@@ -642,7 +636,7 @@ static void __media_device_unregister_entity(struct media_entity *entity)
642 struct media_interface *intf; 636 struct media_interface *intf;
643 unsigned int i; 637 unsigned int i;
644 638
645 ida_simple_remove(&mdev->entity_internal_idx, entity->internal_idx); 639 ida_free(&mdev->entity_internal_idx, entity->internal_idx);
646 640
647 /* Remove all interface links pointing to this entity */ 641 /* Remove all interface links pointing to this entity */
648 list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) { 642 list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
diff --git a/drivers/memory/ti-aemif.c b/drivers/memory/ti-aemif.c
index 31112f622b88..475e5b3790ed 100644
--- a/drivers/memory/ti-aemif.c
+++ b/drivers/memory/ti-aemif.c
@@ -411,7 +411,7 @@ static int aemif_probe(struct platform_device *pdev)
411 if (ret < 0) 411 if (ret < 0)
412 goto error; 412 goto error;
413 } 413 }
414 } else { 414 } else if (pdata) {
415 for (i = 0; i < pdata->num_sub_devices; i++) { 415 for (i = 0; i < pdata->num_sub_devices; i++) {
416 pdata->sub_devices[i].dev.parent = dev; 416 pdata->sub_devices[i].dev.parent = dev;
417 ret = platform_device_register(&pdata->sub_devices[i]); 417 ret = platform_device_register(&pdata->sub_devices[i]);
diff --git a/drivers/misc/cb710/core.c b/drivers/misc/cb710/core.c
index 4d4acf763b65..2c43fd09d602 100644
--- a/drivers/misc/cb710/core.c
+++ b/drivers/misc/cb710/core.c
@@ -16,7 +16,6 @@
16#include <linux/gfp.h> 16#include <linux/gfp.h>
17 17
18static DEFINE_IDA(cb710_ida); 18static DEFINE_IDA(cb710_ida);
19static DEFINE_SPINLOCK(cb710_ida_lock);
20 19
21void cb710_pci_update_config_reg(struct pci_dev *pdev, 20void cb710_pci_update_config_reg(struct pci_dev *pdev,
22 int reg, uint32_t mask, uint32_t xor) 21 int reg, uint32_t mask, uint32_t xor)
@@ -205,7 +204,6 @@ static int cb710_probe(struct pci_dev *pdev,
205 const struct pci_device_id *ent) 204 const struct pci_device_id *ent)
206{ 205{
207 struct cb710_chip *chip; 206 struct cb710_chip *chip;
208 unsigned long flags;
209 u32 val; 207 u32 val;
210 int err; 208 int err;
211 int n = 0; 209 int n = 0;
@@ -256,18 +254,10 @@ static int cb710_probe(struct pci_dev *pdev,
256 if (err) 254 if (err)
257 return err; 255 return err;
258 256
259 do { 257 err = ida_alloc(&cb710_ida, GFP_KERNEL);
260 if (!ida_pre_get(&cb710_ida, GFP_KERNEL)) 258 if (err < 0)
261 return -ENOMEM; 259 return err;
262 260 chip->platform_id = err;
263 spin_lock_irqsave(&cb710_ida_lock, flags);
264 err = ida_get_new(&cb710_ida, &chip->platform_id);
265 spin_unlock_irqrestore(&cb710_ida_lock, flags);
266
267 if (err && err != -EAGAIN)
268 return err;
269 } while (err);
270
271 261
272 dev_info(&pdev->dev, "id %d, IO 0x%p, IRQ %d\n", 262 dev_info(&pdev->dev, "id %d, IO 0x%p, IRQ %d\n",
273 chip->platform_id, chip->iobase, pdev->irq); 263 chip->platform_id, chip->iobase, pdev->irq);
@@ -308,7 +298,6 @@ unreg_mmc:
308static void cb710_remove_one(struct pci_dev *pdev) 298static void cb710_remove_one(struct pci_dev *pdev)
309{ 299{
310 struct cb710_chip *chip = pci_get_drvdata(pdev); 300 struct cb710_chip *chip = pci_get_drvdata(pdev);
311 unsigned long flags;
312 301
313 cb710_unregister_slot(chip, CB710_SLOT_SM); 302 cb710_unregister_slot(chip, CB710_SLOT_SM);
314 cb710_unregister_slot(chip, CB710_SLOT_MS); 303 cb710_unregister_slot(chip, CB710_SLOT_MS);
@@ -317,9 +306,7 @@ static void cb710_remove_one(struct pci_dev *pdev)
317 BUG_ON(atomic_read(&chip->slot_refs_count) != 0); 306 BUG_ON(atomic_read(&chip->slot_refs_count) != 0);
318#endif 307#endif
319 308
320 spin_lock_irqsave(&cb710_ida_lock, flags); 309 ida_free(&cb710_ida, chip->platform_id);
321 ida_remove(&cb710_ida, chip->platform_id);
322 spin_unlock_irqrestore(&cb710_ida_lock, flags);
323} 310}
324 311
325static const struct pci_device_id cb710_pci_tbl[] = { 312static const struct pci_device_id cb710_pci_tbl[] = {
diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
index 648eb6743ed5..6edffeed9953 100644
--- a/drivers/mmc/core/queue.c
+++ b/drivers/mmc/core/queue.c
@@ -238,10 +238,6 @@ static void mmc_mq_exit_request(struct blk_mq_tag_set *set, struct request *req,
238 mmc_exit_request(mq->queue, req); 238 mmc_exit_request(mq->queue, req);
239} 239}
240 240
241/*
242 * We use BLK_MQ_F_BLOCKING and have only 1 hardware queue, which means requests
243 * will not be dispatched in parallel.
244 */
245static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx, 241static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
246 const struct blk_mq_queue_data *bd) 242 const struct blk_mq_queue_data *bd)
247{ 243{
@@ -264,7 +260,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
264 260
265 spin_lock_irq(q->queue_lock); 261 spin_lock_irq(q->queue_lock);
266 262
267 if (mq->recovery_needed) { 263 if (mq->recovery_needed || mq->busy) {
268 spin_unlock_irq(q->queue_lock); 264 spin_unlock_irq(q->queue_lock);
269 return BLK_STS_RESOURCE; 265 return BLK_STS_RESOURCE;
270 } 266 }
@@ -291,6 +287,9 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
291 break; 287 break;
292 } 288 }
293 289
290 /* Parallel dispatch of requests is not supported at the moment */
291 mq->busy = true;
292
294 mq->in_flight[issue_type] += 1; 293 mq->in_flight[issue_type] += 1;
295 get_card = (mmc_tot_in_flight(mq) == 1); 294 get_card = (mmc_tot_in_flight(mq) == 1);
296 cqe_retune_ok = (mmc_cqe_qcnt(mq) == 1); 295 cqe_retune_ok = (mmc_cqe_qcnt(mq) == 1);
@@ -333,9 +332,12 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
333 mq->in_flight[issue_type] -= 1; 332 mq->in_flight[issue_type] -= 1;
334 if (mmc_tot_in_flight(mq) == 0) 333 if (mmc_tot_in_flight(mq) == 0)
335 put_card = true; 334 put_card = true;
335 mq->busy = false;
336 spin_unlock_irq(q->queue_lock); 336 spin_unlock_irq(q->queue_lock);
337 if (put_card) 337 if (put_card)
338 mmc_put_card(card, &mq->ctx); 338 mmc_put_card(card, &mq->ctx);
339 } else {
340 WRITE_ONCE(mq->busy, false);
339 } 341 }
340 342
341 return ret; 343 return ret;
diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h
index 17e59d50b496..9bf3c9245075 100644
--- a/drivers/mmc/core/queue.h
+++ b/drivers/mmc/core/queue.h
@@ -81,6 +81,7 @@ struct mmc_queue {
81 unsigned int cqe_busy; 81 unsigned int cqe_busy;
82#define MMC_CQE_DCMD_BUSY BIT(0) 82#define MMC_CQE_DCMD_BUSY BIT(0)
83#define MMC_CQE_QUEUE_FULL BIT(1) 83#define MMC_CQE_QUEUE_FULL BIT(1)
84 bool busy;
84 bool use_cqe; 85 bool use_cqe;
85 bool recovery_needed; 86 bool recovery_needed;
86 bool in_recovery; 87 bool in_recovery;
diff --git a/drivers/mmc/host/android-goldfish.c b/drivers/mmc/host/android-goldfish.c
index 294de177632c..61e4e2a213c9 100644
--- a/drivers/mmc/host/android-goldfish.c
+++ b/drivers/mmc/host/android-goldfish.c
@@ -217,7 +217,7 @@ static void goldfish_mmc_xfer_done(struct goldfish_mmc_host *host,
217 * We don't really have DMA, so we need 217 * We don't really have DMA, so we need
218 * to copy from our platform driver buffer 218 * to copy from our platform driver buffer
219 */ 219 */
220 sg_copy_to_buffer(data->sg, 1, host->virt_base, 220 sg_copy_from_buffer(data->sg, 1, host->virt_base,
221 data->sg->length); 221 data->sg->length);
222 } 222 }
223 host->data->bytes_xfered += data->sg->length; 223 host->data->bytes_xfered += data->sg->length;
@@ -393,7 +393,7 @@ static void goldfish_mmc_prepare_data(struct goldfish_mmc_host *host,
393 * We don't really have DMA, so we need to copy to our 393 * We don't really have DMA, so we need to copy to our
394 * platform driver buffer 394 * platform driver buffer
395 */ 395 */
396 sg_copy_from_buffer(data->sg, 1, host->virt_base, 396 sg_copy_to_buffer(data->sg, 1, host->virt_base,
397 data->sg->length); 397 data->sg->length);
398 } 398 }
399} 399}
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 5aa2c9404e92..be53044086c7 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -1976,7 +1976,7 @@ static void atmci_read_data_pio(struct atmel_mci *host)
1976 do { 1976 do {
1977 value = atmci_readl(host, ATMCI_RDR); 1977 value = atmci_readl(host, ATMCI_RDR);
1978 if (likely(offset + 4 <= sg->length)) { 1978 if (likely(offset + 4 <= sg->length)) {
1979 sg_pcopy_to_buffer(sg, 1, &value, sizeof(u32), offset); 1979 sg_pcopy_from_buffer(sg, 1, &value, sizeof(u32), offset);
1980 1980
1981 offset += 4; 1981 offset += 4;
1982 nbytes += 4; 1982 nbytes += 4;
@@ -1993,7 +1993,7 @@ static void atmci_read_data_pio(struct atmel_mci *host)
1993 } else { 1993 } else {
1994 unsigned int remaining = sg->length - offset; 1994 unsigned int remaining = sg->length - offset;
1995 1995
1996 sg_pcopy_to_buffer(sg, 1, &value, remaining, offset); 1996 sg_pcopy_from_buffer(sg, 1, &value, remaining, offset);
1997 nbytes += remaining; 1997 nbytes += remaining;
1998 1998
1999 flush_dcache_page(sg_page(sg)); 1999 flush_dcache_page(sg_page(sg));
@@ -2003,7 +2003,7 @@ static void atmci_read_data_pio(struct atmel_mci *host)
2003 goto done; 2003 goto done;
2004 2004
2005 offset = 4 - remaining; 2005 offset = 4 - remaining;
2006 sg_pcopy_to_buffer(sg, 1, (u8 *)&value + remaining, 2006 sg_pcopy_from_buffer(sg, 1, (u8 *)&value + remaining,
2007 offset, 0); 2007 offset, 0);
2008 nbytes += offset; 2008 nbytes += offset;
2009 } 2009 }
@@ -2042,7 +2042,7 @@ static void atmci_write_data_pio(struct atmel_mci *host)
2042 2042
2043 do { 2043 do {
2044 if (likely(offset + 4 <= sg->length)) { 2044 if (likely(offset + 4 <= sg->length)) {
2045 sg_pcopy_from_buffer(sg, 1, &value, sizeof(u32), offset); 2045 sg_pcopy_to_buffer(sg, 1, &value, sizeof(u32), offset);
2046 atmci_writel(host, ATMCI_TDR, value); 2046 atmci_writel(host, ATMCI_TDR, value);
2047 2047
2048 offset += 4; 2048 offset += 4;
@@ -2059,7 +2059,7 @@ static void atmci_write_data_pio(struct atmel_mci *host)
2059 unsigned int remaining = sg->length - offset; 2059 unsigned int remaining = sg->length - offset;
2060 2060
2061 value = 0; 2061 value = 0;
2062 sg_pcopy_from_buffer(sg, 1, &value, remaining, offset); 2062 sg_pcopy_to_buffer(sg, 1, &value, remaining, offset);
2063 nbytes += remaining; 2063 nbytes += remaining;
2064 2064
2065 host->sg = sg = sg_next(sg); 2065 host->sg = sg = sg_next(sg);
@@ -2070,7 +2070,7 @@ static void atmci_write_data_pio(struct atmel_mci *host)
2070 } 2070 }
2071 2071
2072 offset = 4 - remaining; 2072 offset = 4 - remaining;
2073 sg_pcopy_from_buffer(sg, 1, (u8 *)&value + remaining, 2073 sg_pcopy_to_buffer(sg, 1, (u8 *)&value + remaining,
2074 offset, 0); 2074 offset, 0);
2075 atmci_writel(host, ATMCI_TDR, value); 2075 atmci_writel(host, ATMCI_TDR, value);
2076 nbytes += offset; 2076 nbytes += offset;
diff --git a/drivers/mmc/host/meson-mx-sdio.c b/drivers/mmc/host/meson-mx-sdio.c
index 09cb89645d06..2cfec33178c1 100644
--- a/drivers/mmc/host/meson-mx-sdio.c
+++ b/drivers/mmc/host/meson-mx-sdio.c
@@ -517,19 +517,23 @@ static struct mmc_host_ops meson_mx_mmc_ops = {
517static struct platform_device *meson_mx_mmc_slot_pdev(struct device *parent) 517static struct platform_device *meson_mx_mmc_slot_pdev(struct device *parent)
518{ 518{
519 struct device_node *slot_node; 519 struct device_node *slot_node;
520 struct platform_device *pdev;
520 521
521 /* 522 /*
522 * TODO: the MMC core framework currently does not support 523 * TODO: the MMC core framework currently does not support
523 * controllers with multiple slots properly. So we only register 524 * controllers with multiple slots properly. So we only register
524 * the first slot for now 525 * the first slot for now
525 */ 526 */
526 slot_node = of_find_compatible_node(parent->of_node, NULL, "mmc-slot"); 527 slot_node = of_get_compatible_child(parent->of_node, "mmc-slot");
527 if (!slot_node) { 528 if (!slot_node) {
528 dev_warn(parent, "no 'mmc-slot' sub-node found\n"); 529 dev_warn(parent, "no 'mmc-slot' sub-node found\n");
529 return ERR_PTR(-ENOENT); 530 return ERR_PTR(-ENOENT);
530 } 531 }
531 532
532 return of_platform_device_create(slot_node, NULL, parent); 533 pdev = of_platform_device_create(slot_node, NULL, parent);
534 of_node_put(slot_node);
535
536 return pdev;
533} 537}
534 538
535static int meson_mx_mmc_add_host(struct meson_mx_mmc_host *host) 539static int meson_mx_mmc_add_host(struct meson_mx_mmc_host *host)
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 071693ebfe18..68760d4a5d3d 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -2177,6 +2177,7 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2177 dma_release_channel(host->tx_chan); 2177 dma_release_channel(host->tx_chan);
2178 dma_release_channel(host->rx_chan); 2178 dma_release_channel(host->rx_chan);
2179 2179
2180 dev_pm_clear_wake_irq(host->dev);
2180 pm_runtime_dont_use_autosuspend(host->dev); 2181 pm_runtime_dont_use_autosuspend(host->dev);
2181 pm_runtime_put_sync(host->dev); 2182 pm_runtime_put_sync(host->dev);
2182 pm_runtime_disable(host->dev); 2183 pm_runtime_disable(host->dev);
diff --git a/drivers/mmc/host/renesas_sdhi_internal_dmac.c b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
index 35cc0de6be67..ca0b43973769 100644
--- a/drivers/mmc/host/renesas_sdhi_internal_dmac.c
+++ b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
@@ -45,14 +45,16 @@
45/* DM_CM_RST */ 45/* DM_CM_RST */
46#define RST_DTRANRST1 BIT(9) 46#define RST_DTRANRST1 BIT(9)
47#define RST_DTRANRST0 BIT(8) 47#define RST_DTRANRST0 BIT(8)
48#define RST_RESERVED_BITS GENMASK_ULL(32, 0) 48#define RST_RESERVED_BITS GENMASK_ULL(31, 0)
49 49
50/* DM_CM_INFO1 and DM_CM_INFO1_MASK */ 50/* DM_CM_INFO1 and DM_CM_INFO1_MASK */
51#define INFO1_CLEAR 0 51#define INFO1_CLEAR 0
52#define INFO1_MASK_CLEAR GENMASK_ULL(31, 0)
52#define INFO1_DTRANEND1 BIT(17) 53#define INFO1_DTRANEND1 BIT(17)
53#define INFO1_DTRANEND0 BIT(16) 54#define INFO1_DTRANEND0 BIT(16)
54 55
55/* DM_CM_INFO2 and DM_CM_INFO2_MASK */ 56/* DM_CM_INFO2 and DM_CM_INFO2_MASK */
57#define INFO2_MASK_CLEAR GENMASK_ULL(31, 0)
56#define INFO2_DTRANERR1 BIT(17) 58#define INFO2_DTRANERR1 BIT(17)
57#define INFO2_DTRANERR0 BIT(16) 59#define INFO2_DTRANERR0 BIT(16)
58 60
@@ -252,6 +254,12 @@ renesas_sdhi_internal_dmac_request_dma(struct tmio_mmc_host *host,
252{ 254{
253 struct renesas_sdhi *priv = host_to_priv(host); 255 struct renesas_sdhi *priv = host_to_priv(host);
254 256
257 /* Disable DMAC interrupts, we don't use them */
258 renesas_sdhi_internal_dmac_dm_write(host, DM_CM_INFO1_MASK,
259 INFO1_MASK_CLEAR);
260 renesas_sdhi_internal_dmac_dm_write(host, DM_CM_INFO2_MASK,
261 INFO2_MASK_CLEAR);
262
255 /* Each value is set to non-zero to assume "enabling" each DMA */ 263 /* Each value is set to non-zero to assume "enabling" each DMA */
256 host->chan_rx = host->chan_tx = (void *)0xdeadbeaf; 264 host->chan_rx = host->chan_tx = (void *)0xdeadbeaf;
257 265
diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c
index ca18612c4201..67b2065e7a19 100644
--- a/drivers/mtd/nand/raw/denali.c
+++ b/drivers/mtd/nand/raw/denali.c
@@ -1338,6 +1338,11 @@ int denali_init(struct denali_nand_info *denali)
1338 1338
1339 denali_enable_irq(denali); 1339 denali_enable_irq(denali);
1340 denali_reset_banks(denali); 1340 denali_reset_banks(denali);
1341 if (!denali->max_banks) {
1342 /* Error out earlier if no chip is found for some reasons. */
1343 ret = -ENODEV;
1344 goto disable_irq;
1345 }
1341 1346
1342 denali->active_bank = DENALI_INVALID_BANK; 1347 denali->active_bank = DENALI_INVALID_BANK;
1343 1348
diff --git a/drivers/mtd/nand/raw/docg4.c b/drivers/mtd/nand/raw/docg4.c
index a3f04315c05c..427fcbc1b71c 100644
--- a/drivers/mtd/nand/raw/docg4.c
+++ b/drivers/mtd/nand/raw/docg4.c
@@ -1218,7 +1218,7 @@ static int docg4_resume(struct platform_device *pdev)
1218 return 0; 1218 return 0;
1219} 1219}
1220 1220
1221static void __init init_mtd_structs(struct mtd_info *mtd) 1221static void init_mtd_structs(struct mtd_info *mtd)
1222{ 1222{
1223 /* initialize mtd and nand data structures */ 1223 /* initialize mtd and nand data structures */
1224 1224
@@ -1290,7 +1290,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
1290 1290
1291} 1291}
1292 1292
1293static int __init read_id_reg(struct mtd_info *mtd) 1293static int read_id_reg(struct mtd_info *mtd)
1294{ 1294{
1295 struct nand_chip *nand = mtd_to_nand(mtd); 1295 struct nand_chip *nand = mtd_to_nand(mtd);
1296 struct docg4_priv *doc = nand_get_controller_data(nand); 1296 struct docg4_priv *doc = nand_get_controller_data(nand);
diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index 17f12c18d225..7635c38e77dd 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -459,12 +459,12 @@ static void ena_com_handle_admin_completion(struct ena_com_admin_queue *admin_qu
459 cqe = &admin_queue->cq.entries[head_masked]; 459 cqe = &admin_queue->cq.entries[head_masked];
460 460
461 /* Go over all the completions */ 461 /* Go over all the completions */
462 while ((cqe->acq_common_descriptor.flags & 462 while ((READ_ONCE(cqe->acq_common_descriptor.flags) &
463 ENA_ADMIN_ACQ_COMMON_DESC_PHASE_MASK) == phase) { 463 ENA_ADMIN_ACQ_COMMON_DESC_PHASE_MASK) == phase) {
464 /* Do not read the rest of the completion entry before the 464 /* Do not read the rest of the completion entry before the
465 * phase bit was validated 465 * phase bit was validated
466 */ 466 */
467 rmb(); 467 dma_rmb();
468 ena_com_handle_single_admin_completion(admin_queue, cqe); 468 ena_com_handle_single_admin_completion(admin_queue, cqe);
469 469
470 head_masked++; 470 head_masked++;
@@ -627,17 +627,10 @@ static u32 ena_com_reg_bar_read32(struct ena_com_dev *ena_dev, u16 offset)
627 mmio_read_reg |= mmio_read->seq_num & 627 mmio_read_reg |= mmio_read->seq_num &
628 ENA_REGS_MMIO_REG_READ_REQ_ID_MASK; 628 ENA_REGS_MMIO_REG_READ_REQ_ID_MASK;
629 629
630 /* make sure read_resp->req_id get updated before the hw can write 630 writel(mmio_read_reg, ena_dev->reg_bar + ENA_REGS_MMIO_REG_READ_OFF);
631 * there
632 */
633 wmb();
634
635 writel_relaxed(mmio_read_reg,
636 ena_dev->reg_bar + ENA_REGS_MMIO_REG_READ_OFF);
637 631
638 mmiowb();
639 for (i = 0; i < timeout; i++) { 632 for (i = 0; i < timeout; i++) {
640 if (read_resp->req_id == mmio_read->seq_num) 633 if (READ_ONCE(read_resp->req_id) == mmio_read->seq_num)
641 break; 634 break;
642 635
643 udelay(1); 636 udelay(1);
@@ -1796,8 +1789,13 @@ void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data)
1796 aenq_common = &aenq_e->aenq_common_desc; 1789 aenq_common = &aenq_e->aenq_common_desc;
1797 1790
1798 /* Go over all the events */ 1791 /* Go over all the events */
1799 while ((aenq_common->flags & ENA_ADMIN_AENQ_COMMON_DESC_PHASE_MASK) == 1792 while ((READ_ONCE(aenq_common->flags) &
1800 phase) { 1793 ENA_ADMIN_AENQ_COMMON_DESC_PHASE_MASK) == phase) {
1794 /* Make sure the phase bit (ownership) is as expected before
1795 * reading the rest of the descriptor.
1796 */
1797 dma_rmb();
1798
1801 pr_debug("AENQ! Group[%x] Syndrom[%x] timestamp: [%llus]\n", 1799 pr_debug("AENQ! Group[%x] Syndrom[%x] timestamp: [%llus]\n",
1802 aenq_common->group, aenq_common->syndrom, 1800 aenq_common->group, aenq_common->syndrom,
1803 (u64)aenq_common->timestamp_low + 1801 (u64)aenq_common->timestamp_low +
diff --git a/drivers/net/ethernet/amazon/ena/ena_eth_com.c b/drivers/net/ethernet/amazon/ena/ena_eth_com.c
index ea149c134e15..1c682b76190f 100644
--- a/drivers/net/ethernet/amazon/ena/ena_eth_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_eth_com.c
@@ -51,6 +51,11 @@ static inline struct ena_eth_io_rx_cdesc_base *ena_com_get_next_rx_cdesc(
51 if (desc_phase != expected_phase) 51 if (desc_phase != expected_phase)
52 return NULL; 52 return NULL;
53 53
54 /* Make sure we read the rest of the descriptor after the phase bit
55 * has been read
56 */
57 dma_rmb();
58
54 return cdesc; 59 return cdesc;
55} 60}
56 61
@@ -493,6 +498,7 @@ int ena_com_tx_comp_req_id_get(struct ena_com_io_cq *io_cq, u16 *req_id)
493 if (cdesc_phase != expected_phase) 498 if (cdesc_phase != expected_phase)
494 return -EAGAIN; 499 return -EAGAIN;
495 500
501 dma_rmb();
496 if (unlikely(cdesc->req_id >= io_cq->q_depth)) { 502 if (unlikely(cdesc->req_id >= io_cq->q_depth)) {
497 pr_err("Invalid req id %d\n", cdesc->req_id); 503 pr_err("Invalid req id %d\n", cdesc->req_id);
498 return -EINVAL; 504 return -EINVAL;
diff --git a/drivers/net/ethernet/amazon/ena/ena_eth_com.h b/drivers/net/ethernet/amazon/ena/ena_eth_com.h
index 6fdc753d9483..2f7657227cfe 100644
--- a/drivers/net/ethernet/amazon/ena/ena_eth_com.h
+++ b/drivers/net/ethernet/amazon/ena/ena_eth_com.h
@@ -107,8 +107,7 @@ static inline int ena_com_sq_empty_space(struct ena_com_io_sq *io_sq)
107 return io_sq->q_depth - 1 - cnt; 107 return io_sq->q_depth - 1 - cnt;
108} 108}
109 109
110static inline int ena_com_write_sq_doorbell(struct ena_com_io_sq *io_sq, 110static inline int ena_com_write_sq_doorbell(struct ena_com_io_sq *io_sq)
111 bool relaxed)
112{ 111{
113 u16 tail; 112 u16 tail;
114 113
@@ -117,10 +116,7 @@ static inline int ena_com_write_sq_doorbell(struct ena_com_io_sq *io_sq,
117 pr_debug("write submission queue doorbell for queue: %d tail: %d\n", 116 pr_debug("write submission queue doorbell for queue: %d tail: %d\n",
118 io_sq->qid, tail); 117 io_sq->qid, tail);
119 118
120 if (relaxed) 119 writel(tail, io_sq->db_addr);
121 writel_relaxed(tail, io_sq->db_addr);
122 else
123 writel(tail, io_sq->db_addr);
124 120
125 return 0; 121 return 0;
126} 122}
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index c673ac2df65b..29b5774dd32d 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -76,7 +76,7 @@ MODULE_DEVICE_TABLE(pci, ena_pci_tbl);
76 76
77static int ena_rss_init_default(struct ena_adapter *adapter); 77static int ena_rss_init_default(struct ena_adapter *adapter);
78static void check_for_admin_com_state(struct ena_adapter *adapter); 78static void check_for_admin_com_state(struct ena_adapter *adapter);
79static void ena_destroy_device(struct ena_adapter *adapter); 79static void ena_destroy_device(struct ena_adapter *adapter, bool graceful);
80static int ena_restore_device(struct ena_adapter *adapter); 80static int ena_restore_device(struct ena_adapter *adapter);
81 81
82static void ena_tx_timeout(struct net_device *dev) 82static void ena_tx_timeout(struct net_device *dev)
@@ -461,7 +461,7 @@ static inline int ena_alloc_rx_page(struct ena_ring *rx_ring,
461 return -ENOMEM; 461 return -ENOMEM;
462 } 462 }
463 463
464 dma = dma_map_page(rx_ring->dev, page, 0, PAGE_SIZE, 464 dma = dma_map_page(rx_ring->dev, page, 0, ENA_PAGE_SIZE,
465 DMA_FROM_DEVICE); 465 DMA_FROM_DEVICE);
466 if (unlikely(dma_mapping_error(rx_ring->dev, dma))) { 466 if (unlikely(dma_mapping_error(rx_ring->dev, dma))) {
467 u64_stats_update_begin(&rx_ring->syncp); 467 u64_stats_update_begin(&rx_ring->syncp);
@@ -478,7 +478,7 @@ static inline int ena_alloc_rx_page(struct ena_ring *rx_ring,
478 rx_info->page_offset = 0; 478 rx_info->page_offset = 0;
479 ena_buf = &rx_info->ena_buf; 479 ena_buf = &rx_info->ena_buf;
480 ena_buf->paddr = dma; 480 ena_buf->paddr = dma;
481 ena_buf->len = PAGE_SIZE; 481 ena_buf->len = ENA_PAGE_SIZE;
482 482
483 return 0; 483 return 0;
484} 484}
@@ -495,7 +495,7 @@ static void ena_free_rx_page(struct ena_ring *rx_ring,
495 return; 495 return;
496 } 496 }
497 497
498 dma_unmap_page(rx_ring->dev, ena_buf->paddr, PAGE_SIZE, 498 dma_unmap_page(rx_ring->dev, ena_buf->paddr, ENA_PAGE_SIZE,
499 DMA_FROM_DEVICE); 499 DMA_FROM_DEVICE);
500 500
501 __free_page(page); 501 __free_page(page);
@@ -551,14 +551,9 @@ static int ena_refill_rx_bufs(struct ena_ring *rx_ring, u32 num)
551 rx_ring->qid, i, num); 551 rx_ring->qid, i, num);
552 } 552 }
553 553
554 if (likely(i)) { 554 /* ena_com_write_sq_doorbell issues a wmb() */
555 /* Add memory barrier to make sure the desc were written before 555 if (likely(i))
556 * issue a doorbell 556 ena_com_write_sq_doorbell(rx_ring->ena_com_io_sq);
557 */
558 wmb();
559 ena_com_write_sq_doorbell(rx_ring->ena_com_io_sq, true);
560 mmiowb();
561 }
562 557
563 rx_ring->next_to_use = next_to_use; 558 rx_ring->next_to_use = next_to_use;
564 559
@@ -916,10 +911,10 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
916 do { 911 do {
917 dma_unmap_page(rx_ring->dev, 912 dma_unmap_page(rx_ring->dev,
918 dma_unmap_addr(&rx_info->ena_buf, paddr), 913 dma_unmap_addr(&rx_info->ena_buf, paddr),
919 PAGE_SIZE, DMA_FROM_DEVICE); 914 ENA_PAGE_SIZE, DMA_FROM_DEVICE);
920 915
921 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_info->page, 916 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_info->page,
922 rx_info->page_offset, len, PAGE_SIZE); 917 rx_info->page_offset, len, ENA_PAGE_SIZE);
923 918
924 netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev, 919 netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
925 "rx skb updated. len %d. data_len %d\n", 920 "rx skb updated. len %d. data_len %d\n",
@@ -1900,7 +1895,7 @@ static int ena_close(struct net_device *netdev)
1900 "Destroy failure, restarting device\n"); 1895 "Destroy failure, restarting device\n");
1901 ena_dump_stats_to_dmesg(adapter); 1896 ena_dump_stats_to_dmesg(adapter);
1902 /* rtnl lock already obtained in dev_ioctl() layer */ 1897 /* rtnl lock already obtained in dev_ioctl() layer */
1903 ena_destroy_device(adapter); 1898 ena_destroy_device(adapter, false);
1904 ena_restore_device(adapter); 1899 ena_restore_device(adapter);
1905 } 1900 }
1906 1901
@@ -2112,12 +2107,6 @@ static netdev_tx_t ena_start_xmit(struct sk_buff *skb, struct net_device *dev)
2112 tx_ring->next_to_use = ENA_TX_RING_IDX_NEXT(next_to_use, 2107 tx_ring->next_to_use = ENA_TX_RING_IDX_NEXT(next_to_use,
2113 tx_ring->ring_size); 2108 tx_ring->ring_size);
2114 2109
2115 /* This WMB is aimed to:
2116 * 1 - perform smp barrier before reading next_to_completion
2117 * 2 - make sure the desc were written before trigger DB
2118 */
2119 wmb();
2120
2121 /* stop the queue when no more space available, the packet can have up 2110 /* stop the queue when no more space available, the packet can have up
2122 * to sgl_size + 2. one for the meta descriptor and one for header 2111 * to sgl_size + 2. one for the meta descriptor and one for header
2123 * (if the header is larger than tx_max_header_size). 2112 * (if the header is larger than tx_max_header_size).
@@ -2136,10 +2125,11 @@ static netdev_tx_t ena_start_xmit(struct sk_buff *skb, struct net_device *dev)
2136 * stop the queue but meanwhile clean_tx_irq updates 2125 * stop the queue but meanwhile clean_tx_irq updates
2137 * next_to_completion and terminates. 2126 * next_to_completion and terminates.
2138 * The queue will remain stopped forever. 2127 * The queue will remain stopped forever.
2139 * To solve this issue this function perform rmb, check 2128 * To solve this issue add a mb() to make sure that
2140 * the wakeup condition and wake up the queue if needed. 2129 * netif_tx_stop_queue() write is vissible before checking if
2130 * there is additional space in the queue.
2141 */ 2131 */
2142 smp_rmb(); 2132 smp_mb();
2143 2133
2144 if (ena_com_sq_empty_space(tx_ring->ena_com_io_sq) 2134 if (ena_com_sq_empty_space(tx_ring->ena_com_io_sq)
2145 > ENA_TX_WAKEUP_THRESH) { 2135 > ENA_TX_WAKEUP_THRESH) {
@@ -2151,8 +2141,10 @@ static netdev_tx_t ena_start_xmit(struct sk_buff *skb, struct net_device *dev)
2151 } 2141 }
2152 2142
2153 if (netif_xmit_stopped(txq) || !skb->xmit_more) { 2143 if (netif_xmit_stopped(txq) || !skb->xmit_more) {
2154 /* trigger the dma engine */ 2144 /* trigger the dma engine. ena_com_write_sq_doorbell()
2155 ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq, false); 2145 * has a mb
2146 */
2147 ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
2156 u64_stats_update_begin(&tx_ring->syncp); 2148 u64_stats_update_begin(&tx_ring->syncp);
2157 tx_ring->tx_stats.doorbells++; 2149 tx_ring->tx_stats.doorbells++;
2158 u64_stats_update_end(&tx_ring->syncp); 2150 u64_stats_update_end(&tx_ring->syncp);
@@ -2550,12 +2542,15 @@ err_disable_msix:
2550 return rc; 2542 return rc;
2551} 2543}
2552 2544
2553static void ena_destroy_device(struct ena_adapter *adapter) 2545static void ena_destroy_device(struct ena_adapter *adapter, bool graceful)
2554{ 2546{
2555 struct net_device *netdev = adapter->netdev; 2547 struct net_device *netdev = adapter->netdev;
2556 struct ena_com_dev *ena_dev = adapter->ena_dev; 2548 struct ena_com_dev *ena_dev = adapter->ena_dev;
2557 bool dev_up; 2549 bool dev_up;
2558 2550
2551 if (!test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
2552 return;
2553
2559 netif_carrier_off(netdev); 2554 netif_carrier_off(netdev);
2560 2555
2561 del_timer_sync(&adapter->timer_service); 2556 del_timer_sync(&adapter->timer_service);
@@ -2563,7 +2558,8 @@ static void ena_destroy_device(struct ena_adapter *adapter)
2563 dev_up = test_bit(ENA_FLAG_DEV_UP, &adapter->flags); 2558 dev_up = test_bit(ENA_FLAG_DEV_UP, &adapter->flags);
2564 adapter->dev_up_before_reset = dev_up; 2559 adapter->dev_up_before_reset = dev_up;
2565 2560
2566 ena_com_set_admin_running_state(ena_dev, false); 2561 if (!graceful)
2562 ena_com_set_admin_running_state(ena_dev, false);
2567 2563
2568 if (test_bit(ENA_FLAG_DEV_UP, &adapter->flags)) 2564 if (test_bit(ENA_FLAG_DEV_UP, &adapter->flags))
2569 ena_down(adapter); 2565 ena_down(adapter);
@@ -2591,6 +2587,7 @@ static void ena_destroy_device(struct ena_adapter *adapter)
2591 adapter->reset_reason = ENA_REGS_RESET_NORMAL; 2587 adapter->reset_reason = ENA_REGS_RESET_NORMAL;
2592 2588
2593 clear_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags); 2589 clear_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
2590 clear_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags);
2594} 2591}
2595 2592
2596static int ena_restore_device(struct ena_adapter *adapter) 2593static int ena_restore_device(struct ena_adapter *adapter)
@@ -2635,6 +2632,7 @@ static int ena_restore_device(struct ena_adapter *adapter)
2635 } 2632 }
2636 } 2633 }
2637 2634
2635 set_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags);
2638 mod_timer(&adapter->timer_service, round_jiffies(jiffies + HZ)); 2636 mod_timer(&adapter->timer_service, round_jiffies(jiffies + HZ));
2639 dev_err(&pdev->dev, "Device reset completed successfully\n"); 2637 dev_err(&pdev->dev, "Device reset completed successfully\n");
2640 2638
@@ -2665,7 +2663,7 @@ static void ena_fw_reset_device(struct work_struct *work)
2665 return; 2663 return;
2666 } 2664 }
2667 rtnl_lock(); 2665 rtnl_lock();
2668 ena_destroy_device(adapter); 2666 ena_destroy_device(adapter, false);
2669 ena_restore_device(adapter); 2667 ena_restore_device(adapter);
2670 rtnl_unlock(); 2668 rtnl_unlock();
2671} 2669}
@@ -3409,30 +3407,24 @@ static void ena_remove(struct pci_dev *pdev)
3409 netdev->rx_cpu_rmap = NULL; 3407 netdev->rx_cpu_rmap = NULL;
3410 } 3408 }
3411#endif /* CONFIG_RFS_ACCEL */ 3409#endif /* CONFIG_RFS_ACCEL */
3412
3413 unregister_netdev(netdev);
3414 del_timer_sync(&adapter->timer_service); 3410 del_timer_sync(&adapter->timer_service);
3415 3411
3416 cancel_work_sync(&adapter->reset_task); 3412 cancel_work_sync(&adapter->reset_task);
3417 3413
3418 /* Reset the device only if the device is running. */ 3414 unregister_netdev(netdev);
3419 if (test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
3420 ena_com_dev_reset(ena_dev, adapter->reset_reason);
3421 3415
3422 ena_free_mgmnt_irq(adapter); 3416 /* If the device is running then we want to make sure the device will be
3417 * reset to make sure no more events will be issued by the device.
3418 */
3419 if (test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
3420 set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
3423 3421
3424 ena_disable_msix(adapter); 3422 rtnl_lock();
3423 ena_destroy_device(adapter, true);
3424 rtnl_unlock();
3425 3425
3426 free_netdev(netdev); 3426 free_netdev(netdev);
3427 3427
3428 ena_com_mmio_reg_read_request_destroy(ena_dev);
3429
3430 ena_com_abort_admin_commands(ena_dev);
3431
3432 ena_com_wait_for_abort_completion(ena_dev);
3433
3434 ena_com_admin_destroy(ena_dev);
3435
3436 ena_com_rss_destroy(ena_dev); 3428 ena_com_rss_destroy(ena_dev);
3437 3429
3438 ena_com_delete_debug_area(ena_dev); 3430 ena_com_delete_debug_area(ena_dev);
@@ -3467,7 +3459,7 @@ static int ena_suspend(struct pci_dev *pdev, pm_message_t state)
3467 "ignoring device reset request as the device is being suspended\n"); 3459 "ignoring device reset request as the device is being suspended\n");
3468 clear_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags); 3460 clear_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
3469 } 3461 }
3470 ena_destroy_device(adapter); 3462 ena_destroy_device(adapter, true);
3471 rtnl_unlock(); 3463 rtnl_unlock();
3472 return 0; 3464 return 0;
3473} 3465}
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index f1972b5ab650..7c7ae56c52cf 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -355,4 +355,15 @@ void ena_dump_stats_to_buf(struct ena_adapter *adapter, u8 *buf);
355 355
356int ena_get_sset_count(struct net_device *netdev, int sset); 356int ena_get_sset_count(struct net_device *netdev, int sset);
357 357
358/* The ENA buffer length fields is 16 bit long. So when PAGE_SIZE == 64kB the
359 * driver passas 0.
360 * Since the max packet size the ENA handles is ~9kB limit the buffer length to
361 * 16kB.
362 */
363#if PAGE_SIZE > SZ_16K
364#define ENA_PAGE_SIZE SZ_16K
365#else
366#define ENA_PAGE_SIZE PAGE_SIZE
367#endif
368
358#endif /* !(ENA_H) */ 369#endif /* !(ENA_H) */
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 8bb1e38b1681..cecbb1d1f587 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -5913,12 +5913,12 @@ unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5913 return bp->hw_resc.max_cp_rings; 5913 return bp->hw_resc.max_cp_rings;
5914} 5914}
5915 5915
5916void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max) 5916unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt *bp)
5917{ 5917{
5918 bp->hw_resc.max_cp_rings = max; 5918 return bp->hw_resc.max_cp_rings - bnxt_get_ulp_msix_num(bp);
5919} 5919}
5920 5920
5921unsigned int bnxt_get_max_func_irqs(struct bnxt *bp) 5921static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
5922{ 5922{
5923 struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 5923 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5924 5924
@@ -6684,6 +6684,8 @@ static int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
6684 hw_resc->resv_rx_rings = 0; 6684 hw_resc->resv_rx_rings = 0;
6685 hw_resc->resv_hw_ring_grps = 0; 6685 hw_resc->resv_hw_ring_grps = 0;
6686 hw_resc->resv_vnics = 0; 6686 hw_resc->resv_vnics = 0;
6687 bp->tx_nr_rings = 0;
6688 bp->rx_nr_rings = 0;
6687 } 6689 }
6688 return rc; 6690 return rc;
6689} 6691}
@@ -8629,7 +8631,8 @@ static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8629 8631
8630 *max_tx = hw_resc->max_tx_rings; 8632 *max_tx = hw_resc->max_tx_rings;
8631 *max_rx = hw_resc->max_rx_rings; 8633 *max_rx = hw_resc->max_rx_rings;
8632 *max_cp = min_t(int, hw_resc->max_irqs, hw_resc->max_cp_rings); 8634 *max_cp = min_t(int, bnxt_get_max_func_cp_rings_for_en(bp),
8635 hw_resc->max_irqs);
8633 *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs); 8636 *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs);
8634 max_ring_grps = hw_resc->max_hw_ring_grps; 8637 max_ring_grps = hw_resc->max_hw_ring_grps;
8635 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) { 8638 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
@@ -8769,20 +8772,25 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp)
8769 if (bp->tx_nr_rings) 8772 if (bp->tx_nr_rings)
8770 return 0; 8773 return 0;
8771 8774
8775 bnxt_ulp_irq_stop(bp);
8776 bnxt_clear_int_mode(bp);
8772 rc = bnxt_set_dflt_rings(bp, true); 8777 rc = bnxt_set_dflt_rings(bp, true);
8773 if (rc) { 8778 if (rc) {
8774 netdev_err(bp->dev, "Not enough rings available.\n"); 8779 netdev_err(bp->dev, "Not enough rings available.\n");
8775 return rc; 8780 goto init_dflt_ring_err;
8776 } 8781 }
8777 rc = bnxt_init_int_mode(bp); 8782 rc = bnxt_init_int_mode(bp);
8778 if (rc) 8783 if (rc)
8779 return rc; 8784 goto init_dflt_ring_err;
8785
8780 bp->tx_nr_rings_per_tc = bp->tx_nr_rings; 8786 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8781 if (bnxt_rfs_supported(bp) && bnxt_rfs_capable(bp)) { 8787 if (bnxt_rfs_supported(bp) && bnxt_rfs_capable(bp)) {
8782 bp->flags |= BNXT_FLAG_RFS; 8788 bp->flags |= BNXT_FLAG_RFS;
8783 bp->dev->features |= NETIF_F_NTUPLE; 8789 bp->dev->features |= NETIF_F_NTUPLE;
8784 } 8790 }
8785 return 0; 8791init_dflt_ring_err:
8792 bnxt_ulp_irq_restart(bp, rc);
8793 return rc;
8786} 8794}
8787 8795
8788int bnxt_restore_pf_fw_resources(struct bnxt *bp) 8796int bnxt_restore_pf_fw_resources(struct bnxt *bp)
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index fefa011320e0..bde384630a75 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -1481,8 +1481,7 @@ int bnxt_hwrm_set_coal(struct bnxt *);
1481unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp); 1481unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);
1482void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max); 1482void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max);
1483unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp); 1483unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp);
1484void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max); 1484unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt *bp);
1485unsigned int bnxt_get_max_func_irqs(struct bnxt *bp);
1486int bnxt_get_avail_msix(struct bnxt *bp, int num); 1485int bnxt_get_avail_msix(struct bnxt *bp, int num);
1487int bnxt_reserve_rings(struct bnxt *bp); 1486int bnxt_reserve_rings(struct bnxt *bp);
1488void bnxt_tx_disable(struct bnxt *bp); 1487void bnxt_tx_disable(struct bnxt *bp);
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c
index 6d583bcd2a81..fcd085a9853a 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c
@@ -451,7 +451,7 @@ static int bnxt_hwrm_func_vf_resc_cfg(struct bnxt *bp, int num_vfs)
451 451
452 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_RESOURCE_CFG, -1, -1); 452 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_RESOURCE_CFG, -1, -1);
453 453
454 vf_cp_rings = hw_resc->max_cp_rings - bp->cp_nr_rings; 454 vf_cp_rings = bnxt_get_max_func_cp_rings_for_en(bp) - bp->cp_nr_rings;
455 vf_stat_ctx = hw_resc->max_stat_ctxs - bp->num_stat_ctxs; 455 vf_stat_ctx = hw_resc->max_stat_ctxs - bp->num_stat_ctxs;
456 if (bp->flags & BNXT_FLAG_AGG_RINGS) 456 if (bp->flags & BNXT_FLAG_AGG_RINGS)
457 vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings * 2; 457 vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings * 2;
@@ -549,7 +549,8 @@ static int bnxt_hwrm_func_cfg(struct bnxt *bp, int num_vfs)
549 max_stat_ctxs = hw_resc->max_stat_ctxs; 549 max_stat_ctxs = hw_resc->max_stat_ctxs;
550 550
551 /* Remaining rings are distributed equally amongs VF's for now */ 551 /* Remaining rings are distributed equally amongs VF's for now */
552 vf_cp_rings = (hw_resc->max_cp_rings - bp->cp_nr_rings) / num_vfs; 552 vf_cp_rings = (bnxt_get_max_func_cp_rings_for_en(bp) -
553 bp->cp_nr_rings) / num_vfs;
553 vf_stat_ctx = (max_stat_ctxs - bp->num_stat_ctxs) / num_vfs; 554 vf_stat_ctx = (max_stat_ctxs - bp->num_stat_ctxs) / num_vfs;
554 if (bp->flags & BNXT_FLAG_AGG_RINGS) 555 if (bp->flags & BNXT_FLAG_AGG_RINGS)
555 vf_rx_rings = (hw_resc->max_rx_rings - bp->rx_nr_rings * 2) / 556 vf_rx_rings = (hw_resc->max_rx_rings - bp->rx_nr_rings * 2) /
@@ -643,7 +644,7 @@ static int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs)
643 */ 644 */
644 vfs_supported = *num_vfs; 645 vfs_supported = *num_vfs;
645 646
646 avail_cp = hw_resc->max_cp_rings - bp->cp_nr_rings; 647 avail_cp = bnxt_get_max_func_cp_rings_for_en(bp) - bp->cp_nr_rings;
647 avail_stat = hw_resc->max_stat_ctxs - bp->num_stat_ctxs; 648 avail_stat = hw_resc->max_stat_ctxs - bp->num_stat_ctxs;
648 avail_cp = min_t(int, avail_cp, avail_stat); 649 avail_cp = min_t(int, avail_cp, avail_stat);
649 650
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
index 139d96c5a023..092c817f8f11 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
@@ -110,16 +110,14 @@ static int bnxt_tc_parse_actions(struct bnxt *bp,
110 struct tcf_exts *tc_exts) 110 struct tcf_exts *tc_exts)
111{ 111{
112 const struct tc_action *tc_act; 112 const struct tc_action *tc_act;
113 LIST_HEAD(tc_actions); 113 int i, rc;
114 int rc;
115 114
116 if (!tcf_exts_has_actions(tc_exts)) { 115 if (!tcf_exts_has_actions(tc_exts)) {
117 netdev_info(bp->dev, "no actions"); 116 netdev_info(bp->dev, "no actions");
118 return -EINVAL; 117 return -EINVAL;
119 } 118 }
120 119
121 tcf_exts_to_list(tc_exts, &tc_actions); 120 tcf_exts_for_each_action(i, tc_act, tc_exts) {
122 list_for_each_entry(tc_act, &tc_actions, list) {
123 /* Drop action */ 121 /* Drop action */
124 if (is_tcf_gact_shot(tc_act)) { 122 if (is_tcf_gact_shot(tc_act)) {
125 actions->flags |= BNXT_TC_ACTION_FLAG_DROP; 123 actions->flags |= BNXT_TC_ACTION_FLAG_DROP;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
index c37b2842f972..beee61292d5e 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
@@ -169,7 +169,6 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, int ulp_id,
169 edev->ulp_tbl[ulp_id].msix_requested = avail_msix; 169 edev->ulp_tbl[ulp_id].msix_requested = avail_msix;
170 } 170 }
171 bnxt_fill_msix_vecs(bp, ent); 171 bnxt_fill_msix_vecs(bp, ent);
172 bnxt_set_max_func_cp_rings(bp, max_cp_rings - avail_msix);
173 edev->flags |= BNXT_EN_FLAG_MSIX_REQUESTED; 172 edev->flags |= BNXT_EN_FLAG_MSIX_REQUESTED;
174 return avail_msix; 173 return avail_msix;
175} 174}
@@ -178,7 +177,6 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, int ulp_id)
178{ 177{
179 struct net_device *dev = edev->net; 178 struct net_device *dev = edev->net;
180 struct bnxt *bp = netdev_priv(dev); 179 struct bnxt *bp = netdev_priv(dev);
181 int max_cp_rings, msix_requested;
182 180
183 ASSERT_RTNL(); 181 ASSERT_RTNL();
184 if (ulp_id != BNXT_ROCE_ULP) 182 if (ulp_id != BNXT_ROCE_ULP)
@@ -187,9 +185,6 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, int ulp_id)
187 if (!(edev->flags & BNXT_EN_FLAG_MSIX_REQUESTED)) 185 if (!(edev->flags & BNXT_EN_FLAG_MSIX_REQUESTED))
188 return 0; 186 return 0;
189 187
190 max_cp_rings = bnxt_get_max_func_cp_rings(bp);
191 msix_requested = edev->ulp_tbl[ulp_id].msix_requested;
192 bnxt_set_max_func_cp_rings(bp, max_cp_rings + msix_requested);
193 edev->ulp_tbl[ulp_id].msix_requested = 0; 188 edev->ulp_tbl[ulp_id].msix_requested = 0;
194 edev->flags &= ~BNXT_EN_FLAG_MSIX_REQUESTED; 189 edev->flags &= ~BNXT_EN_FLAG_MSIX_REQUESTED;
195 if (netif_running(dev)) { 190 if (netif_running(dev)) {
@@ -220,21 +215,6 @@ int bnxt_get_ulp_msix_base(struct bnxt *bp)
220 return 0; 215 return 0;
221} 216}
222 217
223void bnxt_subtract_ulp_resources(struct bnxt *bp, int ulp_id)
224{
225 ASSERT_RTNL();
226 if (bnxt_ulp_registered(bp->edev, ulp_id)) {
227 struct bnxt_en_dev *edev = bp->edev;
228 unsigned int msix_req, max;
229
230 msix_req = edev->ulp_tbl[ulp_id].msix_requested;
231 max = bnxt_get_max_func_cp_rings(bp);
232 bnxt_set_max_func_cp_rings(bp, max - msix_req);
233 max = bnxt_get_max_func_stat_ctxs(bp);
234 bnxt_set_max_func_stat_ctxs(bp, max - 1);
235 }
236}
237
238static int bnxt_send_msg(struct bnxt_en_dev *edev, int ulp_id, 218static int bnxt_send_msg(struct bnxt_en_dev *edev, int ulp_id,
239 struct bnxt_fw_msg *fw_msg) 219 struct bnxt_fw_msg *fw_msg)
240{ 220{
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h
index df48ac71729f..d9bea37cd211 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h
@@ -90,7 +90,6 @@ static inline bool bnxt_ulp_registered(struct bnxt_en_dev *edev, int ulp_id)
90 90
91int bnxt_get_ulp_msix_num(struct bnxt *bp); 91int bnxt_get_ulp_msix_num(struct bnxt *bp);
92int bnxt_get_ulp_msix_base(struct bnxt *bp); 92int bnxt_get_ulp_msix_base(struct bnxt *bp);
93void bnxt_subtract_ulp_resources(struct bnxt *bp, int ulp_id);
94void bnxt_ulp_stop(struct bnxt *bp); 93void bnxt_ulp_stop(struct bnxt *bp);
95void bnxt_ulp_start(struct bnxt *bp); 94void bnxt_ulp_start(struct bnxt *bp);
96void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs); 95void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index b773bc07edf7..14b49612aa86 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -186,6 +186,9 @@ struct bcmgenet_mib_counters {
186#define UMAC_MAC1 0x010 186#define UMAC_MAC1 0x010
187#define UMAC_MAX_FRAME_LEN 0x014 187#define UMAC_MAX_FRAME_LEN 0x014
188 188
189#define UMAC_MODE 0x44
190#define MODE_LINK_STATUS (1 << 5)
191
189#define UMAC_EEE_CTRL 0x064 192#define UMAC_EEE_CTRL 0x064
190#define EN_LPI_RX_PAUSE (1 << 0) 193#define EN_LPI_RX_PAUSE (1 << 0)
191#define EN_LPI_TX_PFC (1 << 1) 194#define EN_LPI_TX_PFC (1 << 1)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
index 5333274a283c..4241ae928d4a 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
@@ -115,8 +115,14 @@ void bcmgenet_mii_setup(struct net_device *dev)
115static int bcmgenet_fixed_phy_link_update(struct net_device *dev, 115static int bcmgenet_fixed_phy_link_update(struct net_device *dev,
116 struct fixed_phy_status *status) 116 struct fixed_phy_status *status)
117{ 117{
118 if (dev && dev->phydev && status) 118 struct bcmgenet_priv *priv;
119 status->link = dev->phydev->link; 119 u32 reg;
120
121 if (dev && dev->phydev && status) {
122 priv = netdev_priv(dev);
123 reg = bcmgenet_umac_readl(priv, UMAC_MODE);
124 status->link = !!(reg & MODE_LINK_STATUS);
125 }
120 126
121 return 0; 127 return 0;
122} 128}
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index dc09f9a8a49b..16e4ef7d7185 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -482,11 +482,6 @@ static int macb_mii_probe(struct net_device *dev)
482 482
483 if (np) { 483 if (np) {
484 if (of_phy_is_fixed_link(np)) { 484 if (of_phy_is_fixed_link(np)) {
485 if (of_phy_register_fixed_link(np) < 0) {
486 dev_err(&bp->pdev->dev,
487 "broken fixed-link specification\n");
488 return -ENODEV;
489 }
490 bp->phy_node = of_node_get(np); 485 bp->phy_node = of_node_get(np);
491 } else { 486 } else {
492 bp->phy_node = of_parse_phandle(np, "phy-handle", 0); 487 bp->phy_node = of_parse_phandle(np, "phy-handle", 0);
@@ -569,7 +564,7 @@ static int macb_mii_init(struct macb *bp)
569{ 564{
570 struct macb_platform_data *pdata; 565 struct macb_platform_data *pdata;
571 struct device_node *np; 566 struct device_node *np;
572 int err; 567 int err = -ENXIO;
573 568
574 /* Enable management port */ 569 /* Enable management port */
575 macb_writel(bp, NCR, MACB_BIT(MPE)); 570 macb_writel(bp, NCR, MACB_BIT(MPE));
@@ -592,12 +587,23 @@ static int macb_mii_init(struct macb *bp)
592 dev_set_drvdata(&bp->dev->dev, bp->mii_bus); 587 dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
593 588
594 np = bp->pdev->dev.of_node; 589 np = bp->pdev->dev.of_node;
595 if (pdata) 590 if (np && of_phy_is_fixed_link(np)) {
596 bp->mii_bus->phy_mask = pdata->phy_mask; 591 if (of_phy_register_fixed_link(np) < 0) {
592 dev_err(&bp->pdev->dev,
593 "broken fixed-link specification %pOF\n", np);
594 goto err_out_free_mdiobus;
595 }
596
597 err = mdiobus_register(bp->mii_bus);
598 } else {
599 if (pdata)
600 bp->mii_bus->phy_mask = pdata->phy_mask;
601
602 err = of_mdiobus_register(bp->mii_bus, np);
603 }
597 604
598 err = of_mdiobus_register(bp->mii_bus, np);
599 if (err) 605 if (err)
600 goto err_out_free_mdiobus; 606 goto err_out_free_fixed_link;
601 607
602 err = macb_mii_probe(bp->dev); 608 err = macb_mii_probe(bp->dev);
603 if (err) 609 if (err)
@@ -607,6 +613,7 @@ static int macb_mii_init(struct macb *bp)
607 613
608err_out_unregister_bus: 614err_out_unregister_bus:
609 mdiobus_unregister(bp->mii_bus); 615 mdiobus_unregister(bp->mii_bus);
616err_out_free_fixed_link:
610 if (np && of_phy_is_fixed_link(np)) 617 if (np && of_phy_is_fixed_link(np))
611 of_phy_deregister_fixed_link(np); 618 of_phy_deregister_fixed_link(np);
612err_out_free_mdiobus: 619err_out_free_mdiobus:
@@ -642,7 +649,7 @@ static int macb_halt_tx(struct macb *bp)
642 if (!(status & MACB_BIT(TGO))) 649 if (!(status & MACB_BIT(TGO)))
643 return 0; 650 return 0;
644 651
645 usleep_range(10, 250); 652 udelay(250);
646 } while (time_before(halt_time, timeout)); 653 } while (time_before(halt_time, timeout));
647 654
648 return -ETIMEDOUT; 655 return -ETIMEDOUT;
@@ -2028,14 +2035,17 @@ static void macb_reset_hw(struct macb *bp)
2028{ 2035{
2029 struct macb_queue *queue; 2036 struct macb_queue *queue;
2030 unsigned int q; 2037 unsigned int q;
2038 u32 ctrl = macb_readl(bp, NCR);
2031 2039
2032 /* Disable RX and TX (XXX: Should we halt the transmission 2040 /* Disable RX and TX (XXX: Should we halt the transmission
2033 * more gracefully?) 2041 * more gracefully?)
2034 */ 2042 */
2035 macb_writel(bp, NCR, 0); 2043 ctrl &= ~(MACB_BIT(RE) | MACB_BIT(TE));
2036 2044
2037 /* Clear the stats registers (XXX: Update stats first?) */ 2045 /* Clear the stats registers (XXX: Update stats first?) */
2038 macb_writel(bp, NCR, MACB_BIT(CLRSTAT)); 2046 ctrl |= MACB_BIT(CLRSTAT);
2047
2048 macb_writel(bp, NCR, ctrl);
2039 2049
2040 /* Clear all status flags */ 2050 /* Clear all status flags */
2041 macb_writel(bp, TSR, -1); 2051 macb_writel(bp, TSR, -1);
@@ -2223,7 +2233,7 @@ static void macb_init_hw(struct macb *bp)
2223 } 2233 }
2224 2234
2225 /* Enable TX and RX */ 2235 /* Enable TX and RX */
2226 macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE)); 2236 macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(RE) | MACB_BIT(TE));
2227} 2237}
2228 2238
2229/* The hash address register is 64 bits long and takes up two 2239/* The hash address register is 64 bits long and takes up two
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
index 623f73dd7738..c116f96956fe 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
@@ -417,10 +417,9 @@ static void cxgb4_process_flow_actions(struct net_device *in,
417 struct ch_filter_specification *fs) 417 struct ch_filter_specification *fs)
418{ 418{
419 const struct tc_action *a; 419 const struct tc_action *a;
420 LIST_HEAD(actions); 420 int i;
421 421
422 tcf_exts_to_list(cls->exts, &actions); 422 tcf_exts_for_each_action(i, a, cls->exts) {
423 list_for_each_entry(a, &actions, list) {
424 if (is_tcf_gact_ok(a)) { 423 if (is_tcf_gact_ok(a)) {
425 fs->action = FILTER_PASS; 424 fs->action = FILTER_PASS;
426 } else if (is_tcf_gact_shot(a)) { 425 } else if (is_tcf_gact_shot(a)) {
@@ -591,10 +590,9 @@ static int cxgb4_validate_flow_actions(struct net_device *dev,
591 bool act_redir = false; 590 bool act_redir = false;
592 bool act_pedit = false; 591 bool act_pedit = false;
593 bool act_vlan = false; 592 bool act_vlan = false;
594 LIST_HEAD(actions); 593 int i;
595 594
596 tcf_exts_to_list(cls->exts, &actions); 595 tcf_exts_for_each_action(i, a, cls->exts) {
597 list_for_each_entry(a, &actions, list) {
598 if (is_tcf_gact_ok(a)) { 596 if (is_tcf_gact_ok(a)) {
599 /* Do nothing */ 597 /* Do nothing */
600 } else if (is_tcf_gact_shot(a)) { 598 } else if (is_tcf_gact_shot(a)) {
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
index 18eb2aedd4cb..c7d2b4dc7568 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
@@ -93,14 +93,13 @@ static int fill_action_fields(struct adapter *adap,
93 unsigned int num_actions = 0; 93 unsigned int num_actions = 0;
94 const struct tc_action *a; 94 const struct tc_action *a;
95 struct tcf_exts *exts; 95 struct tcf_exts *exts;
96 LIST_HEAD(actions); 96 int i;
97 97
98 exts = cls->knode.exts; 98 exts = cls->knode.exts;
99 if (!tcf_exts_has_actions(exts)) 99 if (!tcf_exts_has_actions(exts))
100 return -EINVAL; 100 return -EINVAL;
101 101
102 tcf_exts_to_list(exts, &actions); 102 tcf_exts_for_each_action(i, a, exts) {
103 list_for_each_entry(a, &actions, list) {
104 /* Don't allow more than one action per rule. */ 103 /* Don't allow more than one action per rule. */
105 if (num_actions) 104 if (num_actions)
106 return -EINVAL; 105 return -EINVAL;
diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c
index ff92ab1daeb8..1e9d882c04ef 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -4500,7 +4500,7 @@ int be_cmd_get_profile_config(struct be_adapter *adapter,
4500 port_res->max_vfs += le16_to_cpu(pcie->num_vfs); 4500 port_res->max_vfs += le16_to_cpu(pcie->num_vfs);
4501 } 4501 }
4502 } 4502 }
4503 return status; 4503 goto err;
4504 } 4504 }
4505 4505
4506 pcie = be_get_pcie_desc(resp->func_param, desc_count, 4506 pcie = be_get_pcie_desc(resp->func_param, desc_count,
diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h b/drivers/net/ethernet/hisilicon/hns/hnae.h
index fa5b30f547f6..08a750fb60c4 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -220,10 +220,10 @@ struct hnae_desc_cb {
220 220
221 /* priv data for the desc, e.g. skb when use with ip stack*/ 221 /* priv data for the desc, e.g. skb when use with ip stack*/
222 void *priv; 222 void *priv;
223 u16 page_offset; 223 u32 page_offset;
224 u16 reuse_flag; 224 u32 length; /* length of the buffer */
225 225
226 u16 length; /* length of the buffer */ 226 u16 reuse_flag;
227 227
228 /* desc type, used by the ring user to mark the type of the priv data */ 228 /* desc type, used by the ring user to mark the type of the priv data */
229 u16 type; 229 u16 type;
@@ -486,6 +486,8 @@ struct hnae_ae_ops {
486 u8 *auto_neg, u16 *speed, u8 *duplex); 486 u8 *auto_neg, u16 *speed, u8 *duplex);
487 void (*toggle_ring_irq)(struct hnae_ring *ring, u32 val); 487 void (*toggle_ring_irq)(struct hnae_ring *ring, u32 val);
488 void (*adjust_link)(struct hnae_handle *handle, int speed, int duplex); 488 void (*adjust_link)(struct hnae_handle *handle, int speed, int duplex);
489 bool (*need_adjust_link)(struct hnae_handle *handle,
490 int speed, int duplex);
489 int (*set_loopback)(struct hnae_handle *handle, 491 int (*set_loopback)(struct hnae_handle *handle,
490 enum hnae_loop loop_mode, int en); 492 enum hnae_loop loop_mode, int en);
491 void (*get_ring_bdnum_limit)(struct hnae_queue *queue, 493 void (*get_ring_bdnum_limit)(struct hnae_queue *queue,
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index e6aad30e7e69..b52029e26d15 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -155,6 +155,41 @@ static void hns_ae_put_handle(struct hnae_handle *handle)
155 hns_ae_get_ring_pair(handle->qs[i])->used_by_vf = 0; 155 hns_ae_get_ring_pair(handle->qs[i])->used_by_vf = 0;
156} 156}
157 157
158static int hns_ae_wait_flow_down(struct hnae_handle *handle)
159{
160 struct dsaf_device *dsaf_dev;
161 struct hns_ppe_cb *ppe_cb;
162 struct hnae_vf_cb *vf_cb;
163 int ret;
164 int i;
165
166 for (i = 0; i < handle->q_num; i++) {
167 ret = hns_rcb_wait_tx_ring_clean(handle->qs[i]);
168 if (ret)
169 return ret;
170 }
171
172 ppe_cb = hns_get_ppe_cb(handle);
173 ret = hns_ppe_wait_tx_fifo_clean(ppe_cb);
174 if (ret)
175 return ret;
176
177 dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
178 if (!dsaf_dev)
179 return -EINVAL;
180 ret = hns_dsaf_wait_pkt_clean(dsaf_dev, handle->dport_id);
181 if (ret)
182 return ret;
183
184 vf_cb = hns_ae_get_vf_cb(handle);
185 ret = hns_mac_wait_fifo_clean(vf_cb->mac_cb);
186 if (ret)
187 return ret;
188
189 mdelay(10);
190 return 0;
191}
192
158static void hns_ae_ring_enable_all(struct hnae_handle *handle, int val) 193static void hns_ae_ring_enable_all(struct hnae_handle *handle, int val)
159{ 194{
160 int q_num = handle->q_num; 195 int q_num = handle->q_num;
@@ -399,12 +434,41 @@ static int hns_ae_get_mac_info(struct hnae_handle *handle,
399 return hns_mac_get_port_info(mac_cb, auto_neg, speed, duplex); 434 return hns_mac_get_port_info(mac_cb, auto_neg, speed, duplex);
400} 435}
401 436
437static bool hns_ae_need_adjust_link(struct hnae_handle *handle, int speed,
438 int duplex)
439{
440 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
441
442 return hns_mac_need_adjust_link(mac_cb, speed, duplex);
443}
444
402static void hns_ae_adjust_link(struct hnae_handle *handle, int speed, 445static void hns_ae_adjust_link(struct hnae_handle *handle, int speed,
403 int duplex) 446 int duplex)
404{ 447{
405 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 448 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
406 449
407 hns_mac_adjust_link(mac_cb, speed, duplex); 450 switch (mac_cb->dsaf_dev->dsaf_ver) {
451 case AE_VERSION_1:
452 hns_mac_adjust_link(mac_cb, speed, duplex);
453 break;
454
455 case AE_VERSION_2:
456 /* chip need to clear all pkt inside */
457 hns_mac_disable(mac_cb, MAC_COMM_MODE_RX);
458 if (hns_ae_wait_flow_down(handle)) {
459 hns_mac_enable(mac_cb, MAC_COMM_MODE_RX);
460 break;
461 }
462
463 hns_mac_adjust_link(mac_cb, speed, duplex);
464 hns_mac_enable(mac_cb, MAC_COMM_MODE_RX);
465 break;
466
467 default:
468 break;
469 }
470
471 return;
408} 472}
409 473
410static void hns_ae_get_ring_bdnum_limit(struct hnae_queue *queue, 474static void hns_ae_get_ring_bdnum_limit(struct hnae_queue *queue,
@@ -902,6 +966,7 @@ static struct hnae_ae_ops hns_dsaf_ops = {
902 .get_status = hns_ae_get_link_status, 966 .get_status = hns_ae_get_link_status,
903 .get_info = hns_ae_get_mac_info, 967 .get_info = hns_ae_get_mac_info,
904 .adjust_link = hns_ae_adjust_link, 968 .adjust_link = hns_ae_adjust_link,
969 .need_adjust_link = hns_ae_need_adjust_link,
905 .set_loopback = hns_ae_config_loopback, 970 .set_loopback = hns_ae_config_loopback,
906 .get_ring_bdnum_limit = hns_ae_get_ring_bdnum_limit, 971 .get_ring_bdnum_limit = hns_ae_get_ring_bdnum_limit,
907 .get_pauseparam = hns_ae_get_pauseparam, 972 .get_pauseparam = hns_ae_get_pauseparam,
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 5488c6e89f21..09e4061d1fa6 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -257,6 +257,16 @@ static void hns_gmac_get_pausefrm_cfg(void *mac_drv, u32 *rx_pause_en,
257 *tx_pause_en = dsaf_get_bit(pause_en, GMAC_PAUSE_EN_TX_FDFC_B); 257 *tx_pause_en = dsaf_get_bit(pause_en, GMAC_PAUSE_EN_TX_FDFC_B);
258} 258}
259 259
260static bool hns_gmac_need_adjust_link(void *mac_drv, enum mac_speed speed,
261 int duplex)
262{
263 struct mac_driver *drv = (struct mac_driver *)mac_drv;
264 struct hns_mac_cb *mac_cb = drv->mac_cb;
265
266 return (mac_cb->speed != speed) ||
267 (mac_cb->half_duplex == duplex);
268}
269
260static int hns_gmac_adjust_link(void *mac_drv, enum mac_speed speed, 270static int hns_gmac_adjust_link(void *mac_drv, enum mac_speed speed,
261 u32 full_duplex) 271 u32 full_duplex)
262{ 272{
@@ -309,6 +319,30 @@ static void hns_gmac_set_promisc(void *mac_drv, u8 en)
309 hns_gmac_set_uc_match(mac_drv, en); 319 hns_gmac_set_uc_match(mac_drv, en);
310} 320}
311 321
322int hns_gmac_wait_fifo_clean(void *mac_drv)
323{
324 struct mac_driver *drv = (struct mac_driver *)mac_drv;
325 int wait_cnt;
326 u32 val;
327
328 wait_cnt = 0;
329 while (wait_cnt++ < HNS_MAX_WAIT_CNT) {
330 val = dsaf_read_dev(drv, GMAC_FIFO_STATE_REG);
331 /* bit5~bit0 is not send complete pkts */
332 if ((val & 0x3f) == 0)
333 break;
334 usleep_range(100, 200);
335 }
336
337 if (wait_cnt >= HNS_MAX_WAIT_CNT) {
338 dev_err(drv->dev,
339 "hns ge %d fifo was not idle.\n", drv->mac_id);
340 return -EBUSY;
341 }
342
343 return 0;
344}
345
312static void hns_gmac_init(void *mac_drv) 346static void hns_gmac_init(void *mac_drv)
313{ 347{
314 u32 port; 348 u32 port;
@@ -690,6 +724,7 @@ void *hns_gmac_config(struct hns_mac_cb *mac_cb, struct mac_params *mac_param)
690 mac_drv->mac_disable = hns_gmac_disable; 724 mac_drv->mac_disable = hns_gmac_disable;
691 mac_drv->mac_free = hns_gmac_free; 725 mac_drv->mac_free = hns_gmac_free;
692 mac_drv->adjust_link = hns_gmac_adjust_link; 726 mac_drv->adjust_link = hns_gmac_adjust_link;
727 mac_drv->need_adjust_link = hns_gmac_need_adjust_link;
693 mac_drv->set_tx_auto_pause_frames = hns_gmac_set_tx_auto_pause_frames; 728 mac_drv->set_tx_auto_pause_frames = hns_gmac_set_tx_auto_pause_frames;
694 mac_drv->config_max_frame_length = hns_gmac_config_max_frame_length; 729 mac_drv->config_max_frame_length = hns_gmac_config_max_frame_length;
695 mac_drv->mac_pausefrm_cfg = hns_gmac_pause_frm_cfg; 730 mac_drv->mac_pausefrm_cfg = hns_gmac_pause_frm_cfg;
@@ -717,6 +752,7 @@ void *hns_gmac_config(struct hns_mac_cb *mac_cb, struct mac_params *mac_param)
717 mac_drv->get_strings = hns_gmac_get_strings; 752 mac_drv->get_strings = hns_gmac_get_strings;
718 mac_drv->update_stats = hns_gmac_update_stats; 753 mac_drv->update_stats = hns_gmac_update_stats;
719 mac_drv->set_promiscuous = hns_gmac_set_promisc; 754 mac_drv->set_promiscuous = hns_gmac_set_promisc;
755 mac_drv->wait_fifo_clean = hns_gmac_wait_fifo_clean;
720 756
721 return (void *)mac_drv; 757 return (void *)mac_drv;
722} 758}
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 1c2326bd76e2..6ed6f142427e 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -114,6 +114,26 @@ int hns_mac_get_port_info(struct hns_mac_cb *mac_cb,
114 return 0; 114 return 0;
115} 115}
116 116
117/**
118 *hns_mac_is_adjust_link - check is need change mac speed and duplex register
119 *@mac_cb: mac device
120 *@speed: phy device speed
121 *@duplex:phy device duplex
122 *
123 */
124bool hns_mac_need_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex)
125{
126 struct mac_driver *mac_ctrl_drv;
127
128 mac_ctrl_drv = (struct mac_driver *)(mac_cb->priv.mac);
129
130 if (mac_ctrl_drv->need_adjust_link)
131 return mac_ctrl_drv->need_adjust_link(mac_ctrl_drv,
132 (enum mac_speed)speed, duplex);
133 else
134 return true;
135}
136
117void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex) 137void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex)
118{ 138{
119 int ret; 139 int ret;
@@ -430,6 +450,16 @@ int hns_mac_vm_config_bc_en(struct hns_mac_cb *mac_cb, u32 vmid, bool enable)
430 return 0; 450 return 0;
431} 451}
432 452
453int hns_mac_wait_fifo_clean(struct hns_mac_cb *mac_cb)
454{
455 struct mac_driver *drv = hns_mac_get_drv(mac_cb);
456
457 if (drv->wait_fifo_clean)
458 return drv->wait_fifo_clean(drv);
459
460 return 0;
461}
462
433void hns_mac_reset(struct hns_mac_cb *mac_cb) 463void hns_mac_reset(struct hns_mac_cb *mac_cb)
434{ 464{
435 struct mac_driver *drv = hns_mac_get_drv(mac_cb); 465 struct mac_driver *drv = hns_mac_get_drv(mac_cb);
@@ -998,6 +1028,20 @@ static int hns_mac_get_max_port_num(struct dsaf_device *dsaf_dev)
998 return DSAF_MAX_PORT_NUM; 1028 return DSAF_MAX_PORT_NUM;
999} 1029}
1000 1030
1031void hns_mac_enable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode)
1032{
1033 struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
1034
1035 mac_ctrl_drv->mac_enable(mac_cb->priv.mac, mode);
1036}
1037
1038void hns_mac_disable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode)
1039{
1040 struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
1041
1042 mac_ctrl_drv->mac_disable(mac_cb->priv.mac, mode);
1043}
1044
1001/** 1045/**
1002 * hns_mac_init - init mac 1046 * hns_mac_init - init mac
1003 * @dsaf_dev: dsa fabric device struct pointer 1047 * @dsaf_dev: dsa fabric device struct pointer
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
index bbc0a98e7ca3..fbc75341bef7 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
@@ -356,6 +356,9 @@ struct mac_driver {
356 /*adjust mac mode of port,include speed and duplex*/ 356 /*adjust mac mode of port,include speed and duplex*/
357 int (*adjust_link)(void *mac_drv, enum mac_speed speed, 357 int (*adjust_link)(void *mac_drv, enum mac_speed speed,
358 u32 full_duplex); 358 u32 full_duplex);
359 /* need adjust link */
360 bool (*need_adjust_link)(void *mac_drv, enum mac_speed speed,
361 int duplex);
359 /* config autoegotaite mode of port*/ 362 /* config autoegotaite mode of port*/
360 void (*set_an_mode)(void *mac_drv, u8 enable); 363 void (*set_an_mode)(void *mac_drv, u8 enable);
361 /* config loopbank mode */ 364 /* config loopbank mode */
@@ -394,6 +397,7 @@ struct mac_driver {
394 void (*get_info)(void *mac_drv, struct mac_info *mac_info); 397 void (*get_info)(void *mac_drv, struct mac_info *mac_info);
395 398
396 void (*update_stats)(void *mac_drv); 399 void (*update_stats)(void *mac_drv);
400 int (*wait_fifo_clean)(void *mac_drv);
397 401
398 enum mac_mode mac_mode; 402 enum mac_mode mac_mode;
399 u8 mac_id; 403 u8 mac_id;
@@ -427,6 +431,7 @@ void *hns_xgmac_config(struct hns_mac_cb *mac_cb,
427 431
428int hns_mac_init(struct dsaf_device *dsaf_dev); 432int hns_mac_init(struct dsaf_device *dsaf_dev);
429void mac_adjust_link(struct net_device *net_dev); 433void mac_adjust_link(struct net_device *net_dev);
434bool hns_mac_need_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex);
430void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status); 435void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status);
431int hns_mac_change_vf_addr(struct hns_mac_cb *mac_cb, u32 vmid, char *addr); 436int hns_mac_change_vf_addr(struct hns_mac_cb *mac_cb, u32 vmid, char *addr);
432int hns_mac_set_multi(struct hns_mac_cb *mac_cb, 437int hns_mac_set_multi(struct hns_mac_cb *mac_cb,
@@ -463,5 +468,8 @@ int hns_mac_add_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
463int hns_mac_rm_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id, 468int hns_mac_rm_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
464 const unsigned char *addr); 469 const unsigned char *addr);
465int hns_mac_clr_multicast(struct hns_mac_cb *mac_cb, int vfn); 470int hns_mac_clr_multicast(struct hns_mac_cb *mac_cb, int vfn);
471void hns_mac_enable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode);
472void hns_mac_disable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode);
473int hns_mac_wait_fifo_clean(struct hns_mac_cb *mac_cb);
466 474
467#endif /* _HNS_DSAF_MAC_H */ 475#endif /* _HNS_DSAF_MAC_H */
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index ca50c2553a9c..e557a4ef5996 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2727,6 +2727,35 @@ void hns_dsaf_set_promisc_tcam(struct dsaf_device *dsaf_dev,
2727 soft_mac_entry->index = enable ? entry_index : DSAF_INVALID_ENTRY_IDX; 2727 soft_mac_entry->index = enable ? entry_index : DSAF_INVALID_ENTRY_IDX;
2728} 2728}
2729 2729
2730int hns_dsaf_wait_pkt_clean(struct dsaf_device *dsaf_dev, int port)
2731{
2732 u32 val, val_tmp;
2733 int wait_cnt;
2734
2735 if (port >= DSAF_SERVICE_NW_NUM)
2736 return 0;
2737
2738 wait_cnt = 0;
2739 while (wait_cnt++ < HNS_MAX_WAIT_CNT) {
2740 val = dsaf_read_dev(dsaf_dev, DSAF_VOQ_IN_PKT_NUM_0_REG +
2741 (port + DSAF_XGE_NUM) * 0x40);
2742 val_tmp = dsaf_read_dev(dsaf_dev, DSAF_VOQ_OUT_PKT_NUM_0_REG +
2743 (port + DSAF_XGE_NUM) * 0x40);
2744 if (val == val_tmp)
2745 break;
2746
2747 usleep_range(100, 200);
2748 }
2749
2750 if (wait_cnt >= HNS_MAX_WAIT_CNT) {
2751 dev_err(dsaf_dev->dev, "hns dsaf clean wait timeout(%u - %u).\n",
2752 val, val_tmp);
2753 return -EBUSY;
2754 }
2755
2756 return 0;
2757}
2758
2730/** 2759/**
2731 * dsaf_probe - probo dsaf dev 2760 * dsaf_probe - probo dsaf dev
2732 * @pdev: dasf platform device 2761 * @pdev: dasf platform device
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
index 4507e8222683..0e1cd99831a6 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
@@ -44,6 +44,8 @@ struct hns_mac_cb;
44#define DSAF_ROCE_CREDIT_CHN 8 44#define DSAF_ROCE_CREDIT_CHN 8
45#define DSAF_ROCE_CHAN_MODE 3 45#define DSAF_ROCE_CHAN_MODE 3
46 46
47#define HNS_MAX_WAIT_CNT 10000
48
47enum dsaf_roce_port_mode { 49enum dsaf_roce_port_mode {
48 DSAF_ROCE_6PORT_MODE, 50 DSAF_ROCE_6PORT_MODE,
49 DSAF_ROCE_4PORT_MODE, 51 DSAF_ROCE_4PORT_MODE,
@@ -463,5 +465,6 @@ int hns_dsaf_rm_mac_addr(
463 465
464int hns_dsaf_clr_mac_mc_port(struct dsaf_device *dsaf_dev, 466int hns_dsaf_clr_mac_mc_port(struct dsaf_device *dsaf_dev,
465 u8 mac_id, u8 port_num); 467 u8 mac_id, u8 port_num);
468int hns_dsaf_wait_pkt_clean(struct dsaf_device *dsaf_dev, int port);
466 469
467#endif /* __HNS_DSAF_MAIN_H__ */ 470#endif /* __HNS_DSAF_MAIN_H__ */
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c
index d160d8c9e45b..0942e4916d9d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c
@@ -275,6 +275,29 @@ static void hns_ppe_exc_irq_en(struct hns_ppe_cb *ppe_cb, int en)
275 dsaf_write_dev(ppe_cb, PPE_INTEN_REG, msk_vlue & vld_msk); 275 dsaf_write_dev(ppe_cb, PPE_INTEN_REG, msk_vlue & vld_msk);
276} 276}
277 277
278int hns_ppe_wait_tx_fifo_clean(struct hns_ppe_cb *ppe_cb)
279{
280 int wait_cnt;
281 u32 val;
282
283 wait_cnt = 0;
284 while (wait_cnt++ < HNS_MAX_WAIT_CNT) {
285 val = dsaf_read_dev(ppe_cb, PPE_CURR_TX_FIFO0_REG) & 0x3ffU;
286 if (!val)
287 break;
288
289 usleep_range(100, 200);
290 }
291
292 if (wait_cnt >= HNS_MAX_WAIT_CNT) {
293 dev_err(ppe_cb->dev, "hns ppe tx fifo clean wait timeout, still has %u pkt.\n",
294 val);
295 return -EBUSY;
296 }
297
298 return 0;
299}
300
278/** 301/**
279 * ppe_init_hw - init ppe 302 * ppe_init_hw - init ppe
280 * @ppe_cb: ppe device 303 * @ppe_cb: ppe device
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h
index 9d8e643e8aa6..f670e63a5a01 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h
@@ -100,6 +100,7 @@ struct ppe_common_cb {
100 100
101}; 101};
102 102
103int hns_ppe_wait_tx_fifo_clean(struct hns_ppe_cb *ppe_cb);
103int hns_ppe_init(struct dsaf_device *dsaf_dev); 104int hns_ppe_init(struct dsaf_device *dsaf_dev);
104 105
105void hns_ppe_uninit(struct dsaf_device *dsaf_dev); 106void hns_ppe_uninit(struct dsaf_device *dsaf_dev);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
index 9d76e2e54f9d..5d64519b9b1d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
@@ -66,6 +66,29 @@ void hns_rcb_wait_fbd_clean(struct hnae_queue **qs, int q_num, u32 flag)
66 "queue(%d) wait fbd(%d) clean fail!!\n", i, fbd_num); 66 "queue(%d) wait fbd(%d) clean fail!!\n", i, fbd_num);
67} 67}
68 68
69int hns_rcb_wait_tx_ring_clean(struct hnae_queue *qs)
70{
71 u32 head, tail;
72 int wait_cnt;
73
74 tail = dsaf_read_dev(&qs->tx_ring, RCB_REG_TAIL);
75 wait_cnt = 0;
76 while (wait_cnt++ < HNS_MAX_WAIT_CNT) {
77 head = dsaf_read_dev(&qs->tx_ring, RCB_REG_HEAD);
78 if (tail == head)
79 break;
80
81 usleep_range(100, 200);
82 }
83
84 if (wait_cnt >= HNS_MAX_WAIT_CNT) {
85 dev_err(qs->dev->dev, "rcb wait timeout, head not equal to tail.\n");
86 return -EBUSY;
87 }
88
89 return 0;
90}
91
69/** 92/**
70 *hns_rcb_reset_ring_hw - ring reset 93 *hns_rcb_reset_ring_hw - ring reset
71 *@q: ring struct pointer 94 *@q: ring struct pointer
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h
index 602816498c8d..2319b772a271 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h
@@ -136,6 +136,7 @@ void hns_rcbv2_int_clr_hw(struct hnae_queue *q, u32 flag);
136void hns_rcb_init_hw(struct ring_pair_cb *ring); 136void hns_rcb_init_hw(struct ring_pair_cb *ring);
137void hns_rcb_reset_ring_hw(struct hnae_queue *q); 137void hns_rcb_reset_ring_hw(struct hnae_queue *q);
138void hns_rcb_wait_fbd_clean(struct hnae_queue **qs, int q_num, u32 flag); 138void hns_rcb_wait_fbd_clean(struct hnae_queue **qs, int q_num, u32 flag);
139int hns_rcb_wait_tx_ring_clean(struct hnae_queue *qs);
139u32 hns_rcb_get_rx_coalesced_frames( 140u32 hns_rcb_get_rx_coalesced_frames(
140 struct rcb_common_cb *rcb_common, u32 port_idx); 141 struct rcb_common_cb *rcb_common, u32 port_idx);
141u32 hns_rcb_get_tx_coalesced_frames( 142u32 hns_rcb_get_tx_coalesced_frames(
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
index 886cbbf25761..74d935d82cbc 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
@@ -464,6 +464,7 @@
464#define RCB_RING_INTMSK_TX_OVERTIME_REG 0x000C4 464#define RCB_RING_INTMSK_TX_OVERTIME_REG 0x000C4
465#define RCB_RING_INTSTS_TX_OVERTIME_REG 0x000C8 465#define RCB_RING_INTSTS_TX_OVERTIME_REG 0x000C8
466 466
467#define GMAC_FIFO_STATE_REG 0x0000UL
467#define GMAC_DUPLEX_TYPE_REG 0x0008UL 468#define GMAC_DUPLEX_TYPE_REG 0x0008UL
468#define GMAC_FD_FC_TYPE_REG 0x000CUL 469#define GMAC_FD_FC_TYPE_REG 0x000CUL
469#define GMAC_TX_WATER_LINE_REG 0x0010UL 470#define GMAC_TX_WATER_LINE_REG 0x0010UL
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 9f2b552aee33..f56855e63c96 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -406,113 +406,13 @@ out_net_tx_busy:
406 return NETDEV_TX_BUSY; 406 return NETDEV_TX_BUSY;
407} 407}
408 408
409/**
410 * hns_nic_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
411 * @data: pointer to the start of the headers
412 * @max: total length of section to find headers in
413 *
414 * This function is meant to determine the length of headers that will
415 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
416 * motivation of doing this is to only perform one pull for IPv4 TCP
417 * packets so that we can do basic things like calculating the gso_size
418 * based on the average data per packet.
419 **/
420static unsigned int hns_nic_get_headlen(unsigned char *data, u32 flag,
421 unsigned int max_size)
422{
423 unsigned char *network;
424 u8 hlen;
425
426 /* this should never happen, but better safe than sorry */
427 if (max_size < ETH_HLEN)
428 return max_size;
429
430 /* initialize network frame pointer */
431 network = data;
432
433 /* set first protocol and move network header forward */
434 network += ETH_HLEN;
435
436 /* handle any vlan tag if present */
437 if (hnae_get_field(flag, HNS_RXD_VLAN_M, HNS_RXD_VLAN_S)
438 == HNS_RX_FLAG_VLAN_PRESENT) {
439 if ((typeof(max_size))(network - data) > (max_size - VLAN_HLEN))
440 return max_size;
441
442 network += VLAN_HLEN;
443 }
444
445 /* handle L3 protocols */
446 if (hnae_get_field(flag, HNS_RXD_L3ID_M, HNS_RXD_L3ID_S)
447 == HNS_RX_FLAG_L3ID_IPV4) {
448 if ((typeof(max_size))(network - data) >
449 (max_size - sizeof(struct iphdr)))
450 return max_size;
451
452 /* access ihl as a u8 to avoid unaligned access on ia64 */
453 hlen = (network[0] & 0x0F) << 2;
454
455 /* verify hlen meets minimum size requirements */
456 if (hlen < sizeof(struct iphdr))
457 return network - data;
458
459 /* record next protocol if header is present */
460 } else if (hnae_get_field(flag, HNS_RXD_L3ID_M, HNS_RXD_L3ID_S)
461 == HNS_RX_FLAG_L3ID_IPV6) {
462 if ((typeof(max_size))(network - data) >
463 (max_size - sizeof(struct ipv6hdr)))
464 return max_size;
465
466 /* record next protocol */
467 hlen = sizeof(struct ipv6hdr);
468 } else {
469 return network - data;
470 }
471
472 /* relocate pointer to start of L4 header */
473 network += hlen;
474
475 /* finally sort out TCP/UDP */
476 if (hnae_get_field(flag, HNS_RXD_L4ID_M, HNS_RXD_L4ID_S)
477 == HNS_RX_FLAG_L4ID_TCP) {
478 if ((typeof(max_size))(network - data) >
479 (max_size - sizeof(struct tcphdr)))
480 return max_size;
481
482 /* access doff as a u8 to avoid unaligned access on ia64 */
483 hlen = (network[12] & 0xF0) >> 2;
484
485 /* verify hlen meets minimum size requirements */
486 if (hlen < sizeof(struct tcphdr))
487 return network - data;
488
489 network += hlen;
490 } else if (hnae_get_field(flag, HNS_RXD_L4ID_M, HNS_RXD_L4ID_S)
491 == HNS_RX_FLAG_L4ID_UDP) {
492 if ((typeof(max_size))(network - data) >
493 (max_size - sizeof(struct udphdr)))
494 return max_size;
495
496 network += sizeof(struct udphdr);
497 }
498
499 /* If everything has gone correctly network should be the
500 * data section of the packet and will be the end of the header.
501 * If not then it probably represents the end of the last recognized
502 * header.
503 */
504 if ((typeof(max_size))(network - data) < max_size)
505 return network - data;
506 else
507 return max_size;
508}
509
510static void hns_nic_reuse_page(struct sk_buff *skb, int i, 409static void hns_nic_reuse_page(struct sk_buff *skb, int i,
511 struct hnae_ring *ring, int pull_len, 410 struct hnae_ring *ring, int pull_len,
512 struct hnae_desc_cb *desc_cb) 411 struct hnae_desc_cb *desc_cb)
513{ 412{
514 struct hnae_desc *desc; 413 struct hnae_desc *desc;
515 int truesize, size; 414 u32 truesize;
415 int size;
516 int last_offset; 416 int last_offset;
517 bool twobufs; 417 bool twobufs;
518 418
@@ -530,7 +430,7 @@ static void hns_nic_reuse_page(struct sk_buff *skb, int i,
530 } 430 }
531 431
532 skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len, 432 skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len,
533 size - pull_len, truesize - pull_len); 433 size - pull_len, truesize);
534 434
535 /* avoid re-using remote pages,flag default unreuse */ 435 /* avoid re-using remote pages,flag default unreuse */
536 if (unlikely(page_to_nid(desc_cb->priv) != numa_node_id())) 436 if (unlikely(page_to_nid(desc_cb->priv) != numa_node_id()))
@@ -695,7 +595,7 @@ static int hns_nic_poll_rx_skb(struct hns_nic_ring_data *ring_data,
695 } else { 595 } else {
696 ring->stats.seg_pkt_cnt++; 596 ring->stats.seg_pkt_cnt++;
697 597
698 pull_len = hns_nic_get_headlen(va, bnum_flag, HNS_RX_HEAD_SIZE); 598 pull_len = eth_get_headlen(va, HNS_RX_HEAD_SIZE);
699 memcpy(__skb_put(skb, pull_len), va, 599 memcpy(__skb_put(skb, pull_len), va,
700 ALIGN(pull_len, sizeof(long))); 600 ALIGN(pull_len, sizeof(long)));
701 601
@@ -1212,11 +1112,26 @@ static void hns_nic_adjust_link(struct net_device *ndev)
1212 struct hnae_handle *h = priv->ae_handle; 1112 struct hnae_handle *h = priv->ae_handle;
1213 int state = 1; 1113 int state = 1;
1214 1114
1115 /* If there is no phy, do not need adjust link */
1215 if (ndev->phydev) { 1116 if (ndev->phydev) {
1216 h->dev->ops->adjust_link(h, ndev->phydev->speed, 1117 /* When phy link down, do nothing */
1217 ndev->phydev->duplex); 1118 if (ndev->phydev->link == 0)
1218 state = ndev->phydev->link; 1119 return;
1120
1121 if (h->dev->ops->need_adjust_link(h, ndev->phydev->speed,
1122 ndev->phydev->duplex)) {
1123 /* because Hi161X chip don't support to change gmac
1124 * speed and duplex with traffic. Delay 200ms to
1125 * make sure there is no more data in chip FIFO.
1126 */
1127 netif_carrier_off(ndev);
1128 msleep(200);
1129 h->dev->ops->adjust_link(h, ndev->phydev->speed,
1130 ndev->phydev->duplex);
1131 netif_carrier_on(ndev);
1132 }
1219 } 1133 }
1134
1220 state = state && h->dev->ops->get_status(h); 1135 state = state && h->dev->ops->get_status(h);
1221 1136
1222 if (state != priv->link) { 1137 if (state != priv->link) {
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 08f3c4743f74..774beda040a1 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -243,7 +243,9 @@ static int hns_nic_set_link_ksettings(struct net_device *net_dev,
243 } 243 }
244 244
245 if (h->dev->ops->adjust_link) { 245 if (h->dev->ops->adjust_link) {
246 netif_carrier_off(net_dev);
246 h->dev->ops->adjust_link(h, (int)speed, cmd->base.duplex); 247 h->dev->ops->adjust_link(h, (int)speed, cmd->base.duplex);
248 netif_carrier_on(net_dev);
247 return 0; 249 return 0;
248 } 250 }
249 251
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 3554dca7a680..955c4ab18b03 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2019,7 +2019,8 @@ static void hns3_nic_reuse_page(struct sk_buff *skb, int i,
2019 struct hns3_desc_cb *desc_cb) 2019 struct hns3_desc_cb *desc_cb)
2020{ 2020{
2021 struct hns3_desc *desc; 2021 struct hns3_desc *desc;
2022 int truesize, size; 2022 u32 truesize;
2023 int size;
2023 int last_offset; 2024 int last_offset;
2024 bool twobufs; 2025 bool twobufs;
2025 2026
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index a02a96aee2a2..cb450d7ec8c1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -284,11 +284,11 @@ struct hns3_desc_cb {
284 284
285 /* priv data for the desc, e.g. skb when use with ip stack*/ 285 /* priv data for the desc, e.g. skb when use with ip stack*/
286 void *priv; 286 void *priv;
287 u16 page_offset; 287 u32 page_offset;
288 u16 reuse_flag;
289
290 u32 length; /* length of the buffer */ 288 u32 length; /* length of the buffer */
291 289
290 u16 reuse_flag;
291
292 /* desc type, used by the ring user to mark the type of the priv data */ 292 /* desc type, used by the ring user to mark the type of the priv data */
293 u16 type; 293 u16 type;
294}; 294};
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 354c0982847b..372664686309 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -494,9 +494,6 @@ static u32 __emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_s
494 case 16384: 494 case 16384:
495 ret |= EMAC_MR1_RFS_16K; 495 ret |= EMAC_MR1_RFS_16K;
496 break; 496 break;
497 case 8192:
498 ret |= EMAC4_MR1_RFS_8K;
499 break;
500 case 4096: 497 case 4096:
501 ret |= EMAC_MR1_RFS_4K; 498 ret |= EMAC_MR1_RFS_4K;
502 break; 499 break;
@@ -537,6 +534,9 @@ static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_
537 case 16384: 534 case 16384:
538 ret |= EMAC4_MR1_RFS_16K; 535 ret |= EMAC4_MR1_RFS_16K;
539 break; 536 break;
537 case 8192:
538 ret |= EMAC4_MR1_RFS_8K;
539 break;
540 case 4096: 540 case 4096:
541 ret |= EMAC4_MR1_RFS_4K; 541 ret |= EMAC4_MR1_RFS_4K;
542 break; 542 break;
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index dafdd4ade705..4f0daf67b18d 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -1823,11 +1823,17 @@ static int do_reset(struct ibmvnic_adapter *adapter,
1823 adapter->map_id = 1; 1823 adapter->map_id = 1;
1824 release_rx_pools(adapter); 1824 release_rx_pools(adapter);
1825 release_tx_pools(adapter); 1825 release_tx_pools(adapter);
1826 init_rx_pools(netdev); 1826 rc = init_rx_pools(netdev);
1827 init_tx_pools(netdev); 1827 if (rc)
1828 return rc;
1829 rc = init_tx_pools(netdev);
1830 if (rc)
1831 return rc;
1828 1832
1829 release_napi(adapter); 1833 release_napi(adapter);
1830 init_napi(adapter); 1834 rc = init_napi(adapter);
1835 if (rc)
1836 return rc;
1831 } else { 1837 } else {
1832 rc = reset_tx_pools(adapter); 1838 rc = reset_tx_pools(adapter);
1833 if (rc) 1839 if (rc)
diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
index bdb3f8e65ed4..2569a168334c 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c
@@ -624,14 +624,14 @@ static int e1000_set_ringparam(struct net_device *netdev,
624 adapter->tx_ring = tx_old; 624 adapter->tx_ring = tx_old;
625 e1000_free_all_rx_resources(adapter); 625 e1000_free_all_rx_resources(adapter);
626 e1000_free_all_tx_resources(adapter); 626 e1000_free_all_tx_resources(adapter);
627 kfree(tx_old);
628 kfree(rx_old);
629 adapter->rx_ring = rxdr; 627 adapter->rx_ring = rxdr;
630 adapter->tx_ring = txdr; 628 adapter->tx_ring = txdr;
631 err = e1000_up(adapter); 629 err = e1000_up(adapter);
632 if (err) 630 if (err)
633 goto err_setup; 631 goto err_setup;
634 } 632 }
633 kfree(tx_old);
634 kfree(rx_old);
635 635
636 clear_bit(__E1000_RESETTING, &adapter->flags); 636 clear_bit(__E1000_RESETTING, &adapter->flags);
637 return 0; 637 return 0;
@@ -644,7 +644,8 @@ err_setup_rx:
644err_alloc_rx: 644err_alloc_rx:
645 kfree(txdr); 645 kfree(txdr);
646err_alloc_tx: 646err_alloc_tx:
647 e1000_up(adapter); 647 if (netif_running(adapter->netdev))
648 e1000_up(adapter);
648err_setup: 649err_setup:
649 clear_bit(__E1000_RESETTING, &adapter->flags); 650 clear_bit(__E1000_RESETTING, &adapter->flags);
650 return err; 651 return err;
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
index abcd096ede14..5ff6caa83948 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
@@ -2013,7 +2013,7 @@ static void i40e_get_stat_strings(struct net_device *netdev, u8 *data)
2013 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) 2013 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
2014 i40e_add_stat_strings(&data, i40e_gstrings_pfc_stats, i); 2014 i40e_add_stat_strings(&data, i40e_gstrings_pfc_stats, i);
2015 2015
2016 WARN_ONCE(p - data != i40e_get_stats_count(netdev) * ETH_GSTRING_LEN, 2016 WARN_ONCE(data - p != i40e_get_stats_count(netdev) * ETH_GSTRING_LEN,
2017 "stat strings count mismatch!"); 2017 "stat strings count mismatch!");
2018} 2018}
2019 2019
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index f2c622e78802..ac685ad4d877 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -5122,15 +5122,17 @@ static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
5122 u8 *bw_share) 5122 u8 *bw_share)
5123{ 5123{
5124 struct i40e_aqc_configure_vsi_tc_bw_data bw_data; 5124 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
5125 struct i40e_pf *pf = vsi->back;
5125 i40e_status ret; 5126 i40e_status ret;
5126 int i; 5127 int i;
5127 5128
5128 if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) 5129 /* There is no need to reset BW when mqprio mode is on. */
5130 if (pf->flags & I40E_FLAG_TC_MQPRIO)
5129 return 0; 5131 return 0;
5130 if (!vsi->mqprio_qopt.qopt.hw) { 5132 if (!vsi->mqprio_qopt.qopt.hw && !(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5131 ret = i40e_set_bw_limit(vsi, vsi->seid, 0); 5133 ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
5132 if (ret) 5134 if (ret)
5133 dev_info(&vsi->back->pdev->dev, 5135 dev_info(&pf->pdev->dev,
5134 "Failed to reset tx rate for vsi->seid %u\n", 5136 "Failed to reset tx rate for vsi->seid %u\n",
5135 vsi->seid); 5137 vsi->seid);
5136 return ret; 5138 return ret;
@@ -5139,12 +5141,11 @@ static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
5139 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) 5141 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5140 bw_data.tc_bw_credits[i] = bw_share[i]; 5142 bw_data.tc_bw_credits[i] = bw_share[i];
5141 5143
5142 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, 5144 ret = i40e_aq_config_vsi_tc_bw(&pf->hw, vsi->seid, &bw_data, NULL);
5143 NULL);
5144 if (ret) { 5145 if (ret) {
5145 dev_info(&vsi->back->pdev->dev, 5146 dev_info(&pf->pdev->dev,
5146 "AQ command Config VSI BW allocation per TC failed = %d\n", 5147 "AQ command Config VSI BW allocation per TC failed = %d\n",
5147 vsi->back->hw.aq.asq_last_status); 5148 pf->hw.aq.asq_last_status);
5148 return -EINVAL; 5149 return -EINVAL;
5149 } 5150 }
5150 5151
diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h
index d8b5fff581e7..868f4a1d0f72 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -89,6 +89,13 @@ extern const char ice_drv_ver[];
89#define ice_for_each_rxq(vsi, i) \ 89#define ice_for_each_rxq(vsi, i) \
90 for ((i) = 0; (i) < (vsi)->num_rxq; (i)++) 90 for ((i) = 0; (i) < (vsi)->num_rxq; (i)++)
91 91
92/* Macros for each allocated tx/rx ring whether used or not in a VSI */
93#define ice_for_each_alloc_txq(vsi, i) \
94 for ((i) = 0; (i) < (vsi)->alloc_txq; (i)++)
95
96#define ice_for_each_alloc_rxq(vsi, i) \
97 for ((i) = 0; (i) < (vsi)->alloc_rxq; (i)++)
98
92struct ice_tc_info { 99struct ice_tc_info {
93 u16 qoffset; 100 u16 qoffset;
94 u16 qcount; 101 u16 qcount;
@@ -189,9 +196,9 @@ struct ice_vsi {
189 struct list_head tmp_sync_list; /* MAC filters to be synced */ 196 struct list_head tmp_sync_list; /* MAC filters to be synced */
190 struct list_head tmp_unsync_list; /* MAC filters to be unsynced */ 197 struct list_head tmp_unsync_list; /* MAC filters to be unsynced */
191 198
192 bool irqs_ready; 199 u8 irqs_ready;
193 bool current_isup; /* Sync 'link up' logging */ 200 u8 current_isup; /* Sync 'link up' logging */
194 bool stat_offsets_loaded; 201 u8 stat_offsets_loaded;
195 202
196 /* queue information */ 203 /* queue information */
197 u8 tx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */ 204 u8 tx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
@@ -262,7 +269,7 @@ struct ice_pf {
262 struct ice_hw_port_stats stats; 269 struct ice_hw_port_stats stats;
263 struct ice_hw_port_stats stats_prev; 270 struct ice_hw_port_stats stats_prev;
264 struct ice_hw hw; 271 struct ice_hw hw;
265 bool stat_prev_loaded; /* has previous stats been loaded */ 272 u8 stat_prev_loaded; /* has previous stats been loaded */
266 char int_name[ICE_INT_NAME_STR_LEN]; 273 char int_name[ICE_INT_NAME_STR_LEN];
267}; 274};
268 275
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 7541ec2270b3..a0614f472658 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -329,19 +329,19 @@ struct ice_aqc_vsi_props {
329 /* VLAN section */ 329 /* VLAN section */
330 __le16 pvid; /* VLANS include priority bits */ 330 __le16 pvid; /* VLANS include priority bits */
331 u8 pvlan_reserved[2]; 331 u8 pvlan_reserved[2];
332 u8 port_vlan_flags; 332 u8 vlan_flags;
333#define ICE_AQ_VSI_PVLAN_MODE_S 0 333#define ICE_AQ_VSI_VLAN_MODE_S 0
334#define ICE_AQ_VSI_PVLAN_MODE_M (0x3 << ICE_AQ_VSI_PVLAN_MODE_S) 334#define ICE_AQ_VSI_VLAN_MODE_M (0x3 << ICE_AQ_VSI_VLAN_MODE_S)
335#define ICE_AQ_VSI_PVLAN_MODE_UNTAGGED 0x1 335#define ICE_AQ_VSI_VLAN_MODE_UNTAGGED 0x1
336#define ICE_AQ_VSI_PVLAN_MODE_TAGGED 0x2 336#define ICE_AQ_VSI_VLAN_MODE_TAGGED 0x2
337#define ICE_AQ_VSI_PVLAN_MODE_ALL 0x3 337#define ICE_AQ_VSI_VLAN_MODE_ALL 0x3
338#define ICE_AQ_VSI_PVLAN_INSERT_PVID BIT(2) 338#define ICE_AQ_VSI_PVLAN_INSERT_PVID BIT(2)
339#define ICE_AQ_VSI_PVLAN_EMOD_S 3 339#define ICE_AQ_VSI_VLAN_EMOD_S 3
340#define ICE_AQ_VSI_PVLAN_EMOD_M (0x3 << ICE_AQ_VSI_PVLAN_EMOD_S) 340#define ICE_AQ_VSI_VLAN_EMOD_M (0x3 << ICE_AQ_VSI_VLAN_EMOD_S)
341#define ICE_AQ_VSI_PVLAN_EMOD_STR_BOTH (0x0 << ICE_AQ_VSI_PVLAN_EMOD_S) 341#define ICE_AQ_VSI_VLAN_EMOD_STR_BOTH (0x0 << ICE_AQ_VSI_VLAN_EMOD_S)
342#define ICE_AQ_VSI_PVLAN_EMOD_STR_UP (0x1 << ICE_AQ_VSI_PVLAN_EMOD_S) 342#define ICE_AQ_VSI_VLAN_EMOD_STR_UP (0x1 << ICE_AQ_VSI_VLAN_EMOD_S)
343#define ICE_AQ_VSI_PVLAN_EMOD_STR (0x2 << ICE_AQ_VSI_PVLAN_EMOD_S) 343#define ICE_AQ_VSI_VLAN_EMOD_STR (0x2 << ICE_AQ_VSI_VLAN_EMOD_S)
344#define ICE_AQ_VSI_PVLAN_EMOD_NOTHING (0x3 << ICE_AQ_VSI_PVLAN_EMOD_S) 344#define ICE_AQ_VSI_VLAN_EMOD_NOTHING (0x3 << ICE_AQ_VSI_VLAN_EMOD_S)
345 u8 pvlan_reserved2[3]; 345 u8 pvlan_reserved2[3];
346 /* ingress egress up sections */ 346 /* ingress egress up sections */
347 __le32 ingress_table; /* bitmap, 3 bits per up */ 347 __le32 ingress_table; /* bitmap, 3 bits per up */
@@ -594,6 +594,7 @@ struct ice_sw_rule_lg_act {
594#define ICE_LG_ACT_GENERIC_OFFSET_M (0x7 << ICE_LG_ACT_GENERIC_OFFSET_S) 594#define ICE_LG_ACT_GENERIC_OFFSET_M (0x7 << ICE_LG_ACT_GENERIC_OFFSET_S)
595#define ICE_LG_ACT_GENERIC_PRIORITY_S 22 595#define ICE_LG_ACT_GENERIC_PRIORITY_S 22
596#define ICE_LG_ACT_GENERIC_PRIORITY_M (0x7 << ICE_LG_ACT_GENERIC_PRIORITY_S) 596#define ICE_LG_ACT_GENERIC_PRIORITY_M (0x7 << ICE_LG_ACT_GENERIC_PRIORITY_S)
597#define ICE_LG_ACT_GENERIC_OFF_RX_DESC_PROF_IDX 7
597 598
598 /* Action = 7 - Set Stat count */ 599 /* Action = 7 - Set Stat count */
599#define ICE_LG_ACT_STAT_COUNT 0x7 600#define ICE_LG_ACT_STAT_COUNT 0x7
diff --git a/drivers/net/ethernet/intel/ice/ice_common.c b/drivers/net/ethernet/intel/ice/ice_common.c
index 71d032cc5fa7..661beea6af79 100644
--- a/drivers/net/ethernet/intel/ice/ice_common.c
+++ b/drivers/net/ethernet/intel/ice/ice_common.c
@@ -45,6 +45,9 @@ static enum ice_status ice_set_mac_type(struct ice_hw *hw)
45/** 45/**
46 * ice_clear_pf_cfg - Clear PF configuration 46 * ice_clear_pf_cfg - Clear PF configuration
47 * @hw: pointer to the hardware structure 47 * @hw: pointer to the hardware structure
48 *
49 * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
50 * configuration, flow director filters, etc.).
48 */ 51 */
49enum ice_status ice_clear_pf_cfg(struct ice_hw *hw) 52enum ice_status ice_clear_pf_cfg(struct ice_hw *hw)
50{ 53{
@@ -1483,7 +1486,7 @@ enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up)
1483 struct ice_phy_info *phy_info; 1486 struct ice_phy_info *phy_info;
1484 enum ice_status status = 0; 1487 enum ice_status status = 0;
1485 1488
1486 if (!pi) 1489 if (!pi || !link_up)
1487 return ICE_ERR_PARAM; 1490 return ICE_ERR_PARAM;
1488 1491
1489 phy_info = &pi->phy; 1492 phy_info = &pi->phy;
@@ -1619,20 +1622,23 @@ __ice_aq_get_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
1619 } 1622 }
1620 1623
1621 /* LUT size is only valid for Global and PF table types */ 1624 /* LUT size is only valid for Global and PF table types */
1622 if (lut_size == ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128) { 1625 switch (lut_size) {
1623 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128_FLAG << 1626 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128:
1624 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) & 1627 break;
1625 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M; 1628 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512:
1626 } else if (lut_size == ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512) {
1627 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG << 1629 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG <<
1628 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) & 1630 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
1629 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M; 1631 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
1630 } else if ((lut_size == ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K) && 1632 break;
1631 (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF)) { 1633 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K:
1632 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG << 1634 if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
1633 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) & 1635 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG <<
1634 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M; 1636 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
1635 } else { 1637 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
1638 break;
1639 }
1640 /* fall-through */
1641 default:
1636 status = ICE_ERR_PARAM; 1642 status = ICE_ERR_PARAM;
1637 goto ice_aq_get_set_rss_lut_exit; 1643 goto ice_aq_get_set_rss_lut_exit;
1638 } 1644 }
diff --git a/drivers/net/ethernet/intel/ice/ice_controlq.c b/drivers/net/ethernet/intel/ice/ice_controlq.c
index 7c511f144ed6..62be72fdc8f3 100644
--- a/drivers/net/ethernet/intel/ice/ice_controlq.c
+++ b/drivers/net/ethernet/intel/ice/ice_controlq.c
@@ -597,10 +597,14 @@ static enum ice_status ice_init_check_adminq(struct ice_hw *hw)
597 return 0; 597 return 0;
598 598
599init_ctrlq_free_rq: 599init_ctrlq_free_rq:
600 ice_shutdown_rq(hw, cq); 600 if (cq->rq.head) {
601 ice_shutdown_sq(hw, cq); 601 ice_shutdown_rq(hw, cq);
602 mutex_destroy(&cq->sq_lock); 602 mutex_destroy(&cq->rq_lock);
603 mutex_destroy(&cq->rq_lock); 603 }
604 if (cq->sq.head) {
605 ice_shutdown_sq(hw, cq);
606 mutex_destroy(&cq->sq_lock);
607 }
604 return status; 608 return status;
605} 609}
606 610
@@ -706,10 +710,14 @@ static void ice_shutdown_ctrlq(struct ice_hw *hw, enum ice_ctl_q q_type)
706 return; 710 return;
707 } 711 }
708 712
709 ice_shutdown_sq(hw, cq); 713 if (cq->sq.head) {
710 ice_shutdown_rq(hw, cq); 714 ice_shutdown_sq(hw, cq);
711 mutex_destroy(&cq->sq_lock); 715 mutex_destroy(&cq->sq_lock);
712 mutex_destroy(&cq->rq_lock); 716 }
717 if (cq->rq.head) {
718 ice_shutdown_rq(hw, cq);
719 mutex_destroy(&cq->rq_lock);
720 }
713} 721}
714 722
715/** 723/**
@@ -1057,8 +1065,11 @@ ice_clean_rq_elem(struct ice_hw *hw, struct ice_ctl_q_info *cq,
1057 1065
1058clean_rq_elem_out: 1066clean_rq_elem_out:
1059 /* Set pending if needed, unlock and return */ 1067 /* Set pending if needed, unlock and return */
1060 if (pending) 1068 if (pending) {
1069 /* re-read HW head to calculate actual pending messages */
1070 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1061 *pending = (u16)((ntc > ntu ? cq->rq.count : 0) + (ntu - ntc)); 1071 *pending = (u16)((ntc > ntu ? cq->rq.count : 0) + (ntu - ntc));
1072 }
1062clean_rq_elem_err: 1073clean_rq_elem_err:
1063 mutex_unlock(&cq->rq_lock); 1074 mutex_unlock(&cq->rq_lock);
1064 1075
diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
index 1db304c01d10..c71a9b528d6d 100644
--- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
+++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
@@ -26,7 +26,7 @@ static int ice_q_stats_len(struct net_device *netdev)
26{ 26{
27 struct ice_netdev_priv *np = netdev_priv(netdev); 27 struct ice_netdev_priv *np = netdev_priv(netdev);
28 28
29 return ((np->vsi->num_txq + np->vsi->num_rxq) * 29 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
30 (sizeof(struct ice_q_stats) / sizeof(u64))); 30 (sizeof(struct ice_q_stats) / sizeof(u64)));
31} 31}
32 32
@@ -218,7 +218,7 @@ static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
218 p += ETH_GSTRING_LEN; 218 p += ETH_GSTRING_LEN;
219 } 219 }
220 220
221 ice_for_each_txq(vsi, i) { 221 ice_for_each_alloc_txq(vsi, i) {
222 snprintf(p, ETH_GSTRING_LEN, 222 snprintf(p, ETH_GSTRING_LEN,
223 "tx-queue-%u.tx_packets", i); 223 "tx-queue-%u.tx_packets", i);
224 p += ETH_GSTRING_LEN; 224 p += ETH_GSTRING_LEN;
@@ -226,7 +226,7 @@ static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
226 p += ETH_GSTRING_LEN; 226 p += ETH_GSTRING_LEN;
227 } 227 }
228 228
229 ice_for_each_rxq(vsi, i) { 229 ice_for_each_alloc_rxq(vsi, i) {
230 snprintf(p, ETH_GSTRING_LEN, 230 snprintf(p, ETH_GSTRING_LEN,
231 "rx-queue-%u.rx_packets", i); 231 "rx-queue-%u.rx_packets", i);
232 p += ETH_GSTRING_LEN; 232 p += ETH_GSTRING_LEN;
@@ -253,6 +253,24 @@ static int ice_get_sset_count(struct net_device *netdev, int sset)
253{ 253{
254 switch (sset) { 254 switch (sset) {
255 case ETH_SS_STATS: 255 case ETH_SS_STATS:
256 /* The number (and order) of strings reported *must* remain
257 * constant for a given netdevice. This function must not
258 * report a different number based on run time parameters
259 * (such as the number of queues in use, or the setting of
260 * a private ethtool flag). This is due to the nature of the
261 * ethtool stats API.
262 *
263 * User space programs such as ethtool must make 3 separate
264 * ioctl requests, one for size, one for the strings, and
265 * finally one for the stats. Since these cross into
266 * user space, changes to the number or size could result in
267 * undefined memory access or incorrect string<->value
268 * correlations for statistics.
269 *
270 * Even if it appears to be safe, changes to the size or
271 * order of strings will suffer from race conditions and are
272 * not safe.
273 */
256 return ICE_ALL_STATS_LEN(netdev); 274 return ICE_ALL_STATS_LEN(netdev);
257 default: 275 default:
258 return -EOPNOTSUPP; 276 return -EOPNOTSUPP;
@@ -280,18 +298,26 @@ ice_get_ethtool_stats(struct net_device *netdev,
280 /* populate per queue stats */ 298 /* populate per queue stats */
281 rcu_read_lock(); 299 rcu_read_lock();
282 300
283 ice_for_each_txq(vsi, j) { 301 ice_for_each_alloc_txq(vsi, j) {
284 ring = READ_ONCE(vsi->tx_rings[j]); 302 ring = READ_ONCE(vsi->tx_rings[j]);
285 if (!ring) 303 if (ring) {
286 continue; 304 data[i++] = ring->stats.pkts;
287 data[i++] = ring->stats.pkts; 305 data[i++] = ring->stats.bytes;
288 data[i++] = ring->stats.bytes; 306 } else {
307 data[i++] = 0;
308 data[i++] = 0;
309 }
289 } 310 }
290 311
291 ice_for_each_rxq(vsi, j) { 312 ice_for_each_alloc_rxq(vsi, j) {
292 ring = READ_ONCE(vsi->rx_rings[j]); 313 ring = READ_ONCE(vsi->rx_rings[j]);
293 data[i++] = ring->stats.pkts; 314 if (ring) {
294 data[i++] = ring->stats.bytes; 315 data[i++] = ring->stats.pkts;
316 data[i++] = ring->stats.bytes;
317 } else {
318 data[i++] = 0;
319 data[i++] = 0;
320 }
295 } 321 }
296 322
297 rcu_read_unlock(); 323 rcu_read_unlock();
@@ -519,7 +545,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
519 goto done; 545 goto done;
520 } 546 }
521 547
522 for (i = 0; i < vsi->num_txq; i++) { 548 for (i = 0; i < vsi->alloc_txq; i++) {
523 /* clone ring and setup updated count */ 549 /* clone ring and setup updated count */
524 tx_rings[i] = *vsi->tx_rings[i]; 550 tx_rings[i] = *vsi->tx_rings[i];
525 tx_rings[i].count = new_tx_cnt; 551 tx_rings[i].count = new_tx_cnt;
@@ -551,7 +577,7 @@ process_rx:
551 goto done; 577 goto done;
552 } 578 }
553 579
554 for (i = 0; i < vsi->num_rxq; i++) { 580 for (i = 0; i < vsi->alloc_rxq; i++) {
555 /* clone ring and setup updated count */ 581 /* clone ring and setup updated count */
556 rx_rings[i] = *vsi->rx_rings[i]; 582 rx_rings[i] = *vsi->rx_rings[i];
557 rx_rings[i].count = new_rx_cnt; 583 rx_rings[i].count = new_rx_cnt;
diff --git a/drivers/net/ethernet/intel/ice/ice_hw_autogen.h b/drivers/net/ethernet/intel/ice/ice_hw_autogen.h
index 499904874b3f..6076fc87df9d 100644
--- a/drivers/net/ethernet/intel/ice/ice_hw_autogen.h
+++ b/drivers/net/ethernet/intel/ice/ice_hw_autogen.h
@@ -121,10 +121,6 @@
121#define PFINT_FW_CTL_CAUSE_ENA_S 30 121#define PFINT_FW_CTL_CAUSE_ENA_S 30
122#define PFINT_FW_CTL_CAUSE_ENA_M BIT(PFINT_FW_CTL_CAUSE_ENA_S) 122#define PFINT_FW_CTL_CAUSE_ENA_M BIT(PFINT_FW_CTL_CAUSE_ENA_S)
123#define PFINT_OICR 0x0016CA00 123#define PFINT_OICR 0x0016CA00
124#define PFINT_OICR_HLP_RDY_S 14
125#define PFINT_OICR_HLP_RDY_M BIT(PFINT_OICR_HLP_RDY_S)
126#define PFINT_OICR_CPM_RDY_S 15
127#define PFINT_OICR_CPM_RDY_M BIT(PFINT_OICR_CPM_RDY_S)
128#define PFINT_OICR_ECC_ERR_S 16 124#define PFINT_OICR_ECC_ERR_S 16
129#define PFINT_OICR_ECC_ERR_M BIT(PFINT_OICR_ECC_ERR_S) 125#define PFINT_OICR_ECC_ERR_M BIT(PFINT_OICR_ECC_ERR_S)
130#define PFINT_OICR_MAL_DETECT_S 19 126#define PFINT_OICR_MAL_DETECT_S 19
@@ -133,10 +129,6 @@
133#define PFINT_OICR_GRST_M BIT(PFINT_OICR_GRST_S) 129#define PFINT_OICR_GRST_M BIT(PFINT_OICR_GRST_S)
134#define PFINT_OICR_PCI_EXCEPTION_S 21 130#define PFINT_OICR_PCI_EXCEPTION_S 21
135#define PFINT_OICR_PCI_EXCEPTION_M BIT(PFINT_OICR_PCI_EXCEPTION_S) 131#define PFINT_OICR_PCI_EXCEPTION_M BIT(PFINT_OICR_PCI_EXCEPTION_S)
136#define PFINT_OICR_GPIO_S 22
137#define PFINT_OICR_GPIO_M BIT(PFINT_OICR_GPIO_S)
138#define PFINT_OICR_STORM_DETECT_S 24
139#define PFINT_OICR_STORM_DETECT_M BIT(PFINT_OICR_STORM_DETECT_S)
140#define PFINT_OICR_HMC_ERR_S 26 132#define PFINT_OICR_HMC_ERR_S 26
141#define PFINT_OICR_HMC_ERR_M BIT(PFINT_OICR_HMC_ERR_S) 133#define PFINT_OICR_HMC_ERR_M BIT(PFINT_OICR_HMC_ERR_S)
142#define PFINT_OICR_PE_CRITERR_S 28 134#define PFINT_OICR_PE_CRITERR_S 28
diff --git a/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h b/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
index d23a91665b46..068dbc740b76 100644
--- a/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
+++ b/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
@@ -265,6 +265,7 @@ enum ice_rx_flex_desc_status_error_0_bits {
265struct ice_rlan_ctx { 265struct ice_rlan_ctx {
266 u16 head; 266 u16 head;
267 u16 cpuid; /* bigger than needed, see above for reason */ 267 u16 cpuid; /* bigger than needed, see above for reason */
268#define ICE_RLAN_BASE_S 7
268 u64 base; 269 u64 base;
269 u16 qlen; 270 u16 qlen;
270#define ICE_RLAN_CTX_DBUF_S 7 271#define ICE_RLAN_CTX_DBUF_S 7
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 5299caf55a7f..f1e80eed2fd6 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -901,7 +901,7 @@ static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
901 case ice_aqc_opc_get_link_status: 901 case ice_aqc_opc_get_link_status:
902 if (ice_handle_link_event(pf)) 902 if (ice_handle_link_event(pf))
903 dev_err(&pf->pdev->dev, 903 dev_err(&pf->pdev->dev,
904 "Could not handle link event"); 904 "Could not handle link event\n");
905 break; 905 break;
906 default: 906 default:
907 dev_dbg(&pf->pdev->dev, 907 dev_dbg(&pf->pdev->dev,
@@ -917,13 +917,27 @@ static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
917} 917}
918 918
919/** 919/**
920 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
921 * @hw: pointer to hardware info
922 * @cq: control queue information
923 *
924 * returns true if there are pending messages in a queue, false if there aren't
925 */
926static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
927{
928 u16 ntu;
929
930 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
931 return cq->rq.next_to_clean != ntu;
932}
933
934/**
920 * ice_clean_adminq_subtask - clean the AdminQ rings 935 * ice_clean_adminq_subtask - clean the AdminQ rings
921 * @pf: board private structure 936 * @pf: board private structure
922 */ 937 */
923static void ice_clean_adminq_subtask(struct ice_pf *pf) 938static void ice_clean_adminq_subtask(struct ice_pf *pf)
924{ 939{
925 struct ice_hw *hw = &pf->hw; 940 struct ice_hw *hw = &pf->hw;
926 u32 val;
927 941
928 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state)) 942 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
929 return; 943 return;
@@ -933,9 +947,13 @@ static void ice_clean_adminq_subtask(struct ice_pf *pf)
933 947
934 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state); 948 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
935 949
936 /* re-enable Admin queue interrupt causes */ 950 /* There might be a situation where new messages arrive to a control
937 val = rd32(hw, PFINT_FW_CTL); 951 * queue between processing the last message and clearing the
938 wr32(hw, PFINT_FW_CTL, (val | PFINT_FW_CTL_CAUSE_ENA_M)); 952 * EVENT_PENDING bit. So before exiting, check queue head again (using
953 * ice_ctrlq_pending) and process new messages if any.
954 */
955 if (ice_ctrlq_pending(hw, &hw->adminq))
956 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
939 957
940 ice_flush(hw); 958 ice_flush(hw);
941} 959}
@@ -1295,11 +1313,8 @@ static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
1295 qcount = numq_tc; 1313 qcount = numq_tc;
1296 } 1314 }
1297 1315
1298 /* find higher power-of-2 of qcount */ 1316 /* find the (rounded up) power-of-2 of qcount */
1299 pow = ilog2(qcount); 1317 pow = order_base_2(qcount);
1300
1301 if (!is_power_of_2(qcount))
1302 pow++;
1303 1318
1304 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) { 1319 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
1305 if (!(vsi->tc_cfg.ena_tc & BIT(i))) { 1320 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
@@ -1352,14 +1367,15 @@ static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
1352 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE; 1367 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
1353 /* Traffic from VSI can be sent to LAN */ 1368 /* Traffic from VSI can be sent to LAN */
1354 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA; 1369 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1355 /* Allow all packets untagged/tagged */ 1370
1356 ctxt->info.port_vlan_flags = ((ICE_AQ_VSI_PVLAN_MODE_ALL & 1371 /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
1357 ICE_AQ_VSI_PVLAN_MODE_M) >> 1372 * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
1358 ICE_AQ_VSI_PVLAN_MODE_S); 1373 * packets untagged/tagged.
1359 /* Show VLAN/UP from packets in Rx descriptors */ 1374 */
1360 ctxt->info.port_vlan_flags |= ((ICE_AQ_VSI_PVLAN_EMOD_STR_BOTH & 1375 ctxt->info.vlan_flags = ((ICE_AQ_VSI_VLAN_MODE_ALL &
1361 ICE_AQ_VSI_PVLAN_EMOD_M) >> 1376 ICE_AQ_VSI_VLAN_MODE_M) >>
1362 ICE_AQ_VSI_PVLAN_EMOD_S); 1377 ICE_AQ_VSI_VLAN_MODE_S);
1378
1363 /* Have 1:1 UP mapping for both ingress/egress tables */ 1379 /* Have 1:1 UP mapping for both ingress/egress tables */
1364 table |= ICE_UP_TABLE_TRANSLATE(0, 0); 1380 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
1365 table |= ICE_UP_TABLE_TRANSLATE(1, 1); 1381 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
@@ -1688,15 +1704,12 @@ static void ice_ena_misc_vector(struct ice_pf *pf)
1688 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */ 1704 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1689 rd32(hw, PFINT_OICR); /* read to clear */ 1705 rd32(hw, PFINT_OICR); /* read to clear */
1690 1706
1691 val = (PFINT_OICR_HLP_RDY_M | 1707 val = (PFINT_OICR_ECC_ERR_M |
1692 PFINT_OICR_CPM_RDY_M |
1693 PFINT_OICR_ECC_ERR_M |
1694 PFINT_OICR_MAL_DETECT_M | 1708 PFINT_OICR_MAL_DETECT_M |
1695 PFINT_OICR_GRST_M | 1709 PFINT_OICR_GRST_M |
1696 PFINT_OICR_PCI_EXCEPTION_M | 1710 PFINT_OICR_PCI_EXCEPTION_M |
1697 PFINT_OICR_GPIO_M | 1711 PFINT_OICR_HMC_ERR_M |
1698 PFINT_OICR_STORM_DETECT_M | 1712 PFINT_OICR_PE_CRITERR_M);
1699 PFINT_OICR_HMC_ERR_M);
1700 1713
1701 wr32(hw, PFINT_OICR_ENA, val); 1714 wr32(hw, PFINT_OICR_ENA, val);
1702 1715
@@ -2058,15 +2071,13 @@ static int ice_req_irq_msix_misc(struct ice_pf *pf)
2058skip_req_irq: 2071skip_req_irq:
2059 ice_ena_misc_vector(pf); 2072 ice_ena_misc_vector(pf);
2060 2073
2061 val = (pf->oicr_idx & PFINT_OICR_CTL_MSIX_INDX_M) | 2074 val = ((pf->oicr_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
2062 (ICE_RX_ITR & PFINT_OICR_CTL_ITR_INDX_M) | 2075 PFINT_OICR_CTL_CAUSE_ENA_M);
2063 PFINT_OICR_CTL_CAUSE_ENA_M;
2064 wr32(hw, PFINT_OICR_CTL, val); 2076 wr32(hw, PFINT_OICR_CTL, val);
2065 2077
2066 /* This enables Admin queue Interrupt causes */ 2078 /* This enables Admin queue Interrupt causes */
2067 val = (pf->oicr_idx & PFINT_FW_CTL_MSIX_INDX_M) | 2079 val = ((pf->oicr_idx & PFINT_FW_CTL_MSIX_INDX_M) |
2068 (ICE_RX_ITR & PFINT_FW_CTL_ITR_INDX_M) | 2080 PFINT_FW_CTL_CAUSE_ENA_M);
2069 PFINT_FW_CTL_CAUSE_ENA_M;
2070 wr32(hw, PFINT_FW_CTL, val); 2081 wr32(hw, PFINT_FW_CTL, val);
2071 2082
2072 itr_gran = hw->itr_gran_200; 2083 itr_gran = hw->itr_gran_200;
@@ -3246,8 +3257,10 @@ static void ice_clear_interrupt_scheme(struct ice_pf *pf)
3246 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) 3257 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3247 ice_dis_msix(pf); 3258 ice_dis_msix(pf);
3248 3259
3249 devm_kfree(&pf->pdev->dev, pf->irq_tracker); 3260 if (pf->irq_tracker) {
3250 pf->irq_tracker = NULL; 3261 devm_kfree(&pf->pdev->dev, pf->irq_tracker);
3262 pf->irq_tracker = NULL;
3263 }
3251} 3264}
3252 3265
3253/** 3266/**
@@ -3271,7 +3284,7 @@ static int ice_probe(struct pci_dev *pdev,
3271 3284
3272 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev)); 3285 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
3273 if (err) { 3286 if (err) {
3274 dev_err(&pdev->dev, "I/O map error %d\n", err); 3287 dev_err(&pdev->dev, "BAR0 I/O map error %d\n", err);
3275 return err; 3288 return err;
3276 } 3289 }
3277 3290
@@ -3720,10 +3733,10 @@ static int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
3720 enum ice_status status; 3733 enum ice_status status;
3721 3734
3722 /* Here we are configuring the VSI to let the driver add VLAN tags by 3735 /* Here we are configuring the VSI to let the driver add VLAN tags by
3723 * setting port_vlan_flags to ICE_AQ_VSI_PVLAN_MODE_ALL. The actual VLAN 3736 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
3724 * tag insertion happens in the Tx hot path, in ice_tx_map. 3737 * insertion happens in the Tx hot path, in ice_tx_map.
3725 */ 3738 */
3726 ctxt.info.port_vlan_flags = ICE_AQ_VSI_PVLAN_MODE_ALL; 3739 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
3727 3740
3728 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID); 3741 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
3729 ctxt.vsi_num = vsi->vsi_num; 3742 ctxt.vsi_num = vsi->vsi_num;
@@ -3735,7 +3748,7 @@ static int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
3735 return -EIO; 3748 return -EIO;
3736 } 3749 }
3737 3750
3738 vsi->info.port_vlan_flags = ctxt.info.port_vlan_flags; 3751 vsi->info.vlan_flags = ctxt.info.vlan_flags;
3739 return 0; 3752 return 0;
3740} 3753}
3741 3754
@@ -3757,12 +3770,15 @@ static int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
3757 */ 3770 */
3758 if (ena) { 3771 if (ena) {
3759 /* Strip VLAN tag from Rx packet and put it in the desc */ 3772 /* Strip VLAN tag from Rx packet and put it in the desc */
3760 ctxt.info.port_vlan_flags = ICE_AQ_VSI_PVLAN_EMOD_STR_BOTH; 3773 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
3761 } else { 3774 } else {
3762 /* Disable stripping. Leave tag in packet */ 3775 /* Disable stripping. Leave tag in packet */
3763 ctxt.info.port_vlan_flags = ICE_AQ_VSI_PVLAN_EMOD_NOTHING; 3776 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
3764 } 3777 }
3765 3778
3779 /* Allow all packets untagged/tagged */
3780 ctxt.info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
3781
3766 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID); 3782 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
3767 ctxt.vsi_num = vsi->vsi_num; 3783 ctxt.vsi_num = vsi->vsi_num;
3768 3784
@@ -3773,7 +3789,7 @@ static int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
3773 return -EIO; 3789 return -EIO;
3774 } 3790 }
3775 3791
3776 vsi->info.port_vlan_flags = ctxt.info.port_vlan_flags; 3792 vsi->info.vlan_flags = ctxt.info.vlan_flags;
3777 return 0; 3793 return 0;
3778} 3794}
3779 3795
@@ -3986,7 +4002,7 @@ static int ice_setup_rx_ctx(struct ice_ring *ring)
3986 /* clear the context structure first */ 4002 /* clear the context structure first */
3987 memset(&rlan_ctx, 0, sizeof(rlan_ctx)); 4003 memset(&rlan_ctx, 0, sizeof(rlan_ctx));
3988 4004
3989 rlan_ctx.base = ring->dma >> 7; 4005 rlan_ctx.base = ring->dma >> ICE_RLAN_BASE_S;
3990 4006
3991 rlan_ctx.qlen = ring->count; 4007 rlan_ctx.qlen = ring->count;
3992 4008
@@ -4098,11 +4114,12 @@ static int ice_vsi_cfg(struct ice_vsi *vsi)
4098{ 4114{
4099 int err; 4115 int err;
4100 4116
4101 ice_set_rx_mode(vsi->netdev); 4117 if (vsi->netdev) {
4102 4118 ice_set_rx_mode(vsi->netdev);
4103 err = ice_restore_vlan(vsi); 4119 err = ice_restore_vlan(vsi);
4104 if (err) 4120 if (err)
4105 return err; 4121 return err;
4122 }
4106 4123
4107 err = ice_vsi_cfg_txqs(vsi); 4124 err = ice_vsi_cfg_txqs(vsi);
4108 if (!err) 4125 if (!err)
@@ -4868,7 +4885,7 @@ int ice_down(struct ice_vsi *vsi)
4868 */ 4885 */
4869static int ice_vsi_setup_tx_rings(struct ice_vsi *vsi) 4886static int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
4870{ 4887{
4871 int i, err; 4888 int i, err = 0;
4872 4889
4873 if (!vsi->num_txq) { 4890 if (!vsi->num_txq) {
4874 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n", 4891 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
@@ -4893,7 +4910,7 @@ static int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
4893 */ 4910 */
4894static int ice_vsi_setup_rx_rings(struct ice_vsi *vsi) 4911static int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
4895{ 4912{
4896 int i, err; 4913 int i, err = 0;
4897 4914
4898 if (!vsi->num_rxq) { 4915 if (!vsi->num_rxq) {
4899 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n", 4916 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
@@ -5235,7 +5252,7 @@ static int ice_change_mtu(struct net_device *netdev, int new_mtu)
5235 u8 count = 0; 5252 u8 count = 0;
5236 5253
5237 if (new_mtu == netdev->mtu) { 5254 if (new_mtu == netdev->mtu) {
5238 netdev_warn(netdev, "mtu is already %d\n", netdev->mtu); 5255 netdev_warn(netdev, "mtu is already %u\n", netdev->mtu);
5239 return 0; 5256 return 0;
5240 } 5257 }
5241 5258
diff --git a/drivers/net/ethernet/intel/ice/ice_nvm.c b/drivers/net/ethernet/intel/ice/ice_nvm.c
index 92da0a626ce0..295a8cd87fc1 100644
--- a/drivers/net/ethernet/intel/ice/ice_nvm.c
+++ b/drivers/net/ethernet/intel/ice/ice_nvm.c
@@ -131,9 +131,8 @@ ice_read_sr_word_aq(struct ice_hw *hw, u16 offset, u16 *data)
131 * 131 *
132 * This function will request NVM ownership. 132 * This function will request NVM ownership.
133 */ 133 */
134static enum 134static enum ice_status
135ice_status ice_acquire_nvm(struct ice_hw *hw, 135ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access)
136 enum ice_aq_res_access_type access)
137{ 136{
138 if (hw->nvm.blank_nvm_mode) 137 if (hw->nvm.blank_nvm_mode)
139 return 0; 138 return 0;
diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c b/drivers/net/ethernet/intel/ice/ice_sched.c
index 2e6c1d92cc88..eeae199469b6 100644
--- a/drivers/net/ethernet/intel/ice/ice_sched.c
+++ b/drivers/net/ethernet/intel/ice/ice_sched.c
@@ -1576,8 +1576,7 @@ ice_sched_update_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_id, u8 tc,
1576 return status; 1576 return status;
1577 } 1577 }
1578 1578
1579 if (owner == ICE_SCHED_NODE_OWNER_LAN) 1579 vsi->max_lanq[tc] = new_numqs;
1580 vsi->max_lanq[tc] = new_numqs;
1581 1580
1582 return status; 1581 return status;
1583} 1582}
diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
index 723d15f1e90b..6b7ec2ae5ad6 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.c
+++ b/drivers/net/ethernet/intel/ice/ice_switch.c
@@ -645,14 +645,14 @@ ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
645 act |= (1 << ICE_LG_ACT_GENERIC_VALUE_S) & ICE_LG_ACT_GENERIC_VALUE_M; 645 act |= (1 << ICE_LG_ACT_GENERIC_VALUE_S) & ICE_LG_ACT_GENERIC_VALUE_M;
646 lg_act->pdata.lg_act.act[1] = cpu_to_le32(act); 646 lg_act->pdata.lg_act.act[1] = cpu_to_le32(act);
647 647
648 act = (7 << ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_VALUE_M; 648 act = (ICE_LG_ACT_GENERIC_OFF_RX_DESC_PROF_IDX <<
649 ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_OFFSET_M;
649 650
650 /* Third action Marker value */ 651 /* Third action Marker value */
651 act |= ICE_LG_ACT_GENERIC; 652 act |= ICE_LG_ACT_GENERIC;
652 act |= (sw_marker << ICE_LG_ACT_GENERIC_VALUE_S) & 653 act |= (sw_marker << ICE_LG_ACT_GENERIC_VALUE_S) &
653 ICE_LG_ACT_GENERIC_VALUE_M; 654 ICE_LG_ACT_GENERIC_VALUE_M;
654 655
655 act |= (0 << ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_VALUE_M;
656 lg_act->pdata.lg_act.act[2] = cpu_to_le32(act); 656 lg_act->pdata.lg_act.act[2] = cpu_to_le32(act);
657 657
658 /* call the fill switch rule to fill the lookup tx rx structure */ 658 /* call the fill switch rule to fill the lookup tx rx structure */
diff --git a/drivers/net/ethernet/intel/ice/ice_switch.h b/drivers/net/ethernet/intel/ice/ice_switch.h
index 6f4a0d159dbf..9b8ec128ee31 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.h
+++ b/drivers/net/ethernet/intel/ice/ice_switch.h
@@ -17,7 +17,7 @@ struct ice_vsi_ctx {
17 u16 vsis_unallocated; 17 u16 vsis_unallocated;
18 u16 flags; 18 u16 flags;
19 struct ice_aqc_vsi_props info; 19 struct ice_aqc_vsi_props info;
20 bool alloc_from_pool; 20 u8 alloc_from_pool;
21}; 21};
22 22
23enum ice_sw_fwd_act_type { 23enum ice_sw_fwd_act_type {
@@ -94,8 +94,8 @@ struct ice_fltr_info {
94 u8 qgrp_size; 94 u8 qgrp_size;
95 95
96 /* Rule creations populate these indicators basing on the switch type */ 96 /* Rule creations populate these indicators basing on the switch type */
97 bool lb_en; /* Indicate if packet can be looped back */ 97 u8 lb_en; /* Indicate if packet can be looped back */
98 bool lan_en; /* Indicate if packet can be forwarded to the uplink */ 98 u8 lan_en; /* Indicate if packet can be forwarded to the uplink */
99}; 99};
100 100
101/* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */ 101/* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */
diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.h b/drivers/net/ethernet/intel/ice/ice_txrx.h
index 567067b650c4..31bc998fe200 100644
--- a/drivers/net/ethernet/intel/ice/ice_txrx.h
+++ b/drivers/net/ethernet/intel/ice/ice_txrx.h
@@ -143,7 +143,7 @@ struct ice_ring {
143 u16 next_to_use; 143 u16 next_to_use;
144 u16 next_to_clean; 144 u16 next_to_clean;
145 145
146 bool ring_active; /* is ring online or not */ 146 u8 ring_active; /* is ring online or not */
147 147
148 /* stats structs */ 148 /* stats structs */
149 struct ice_q_stats stats; 149 struct ice_q_stats stats;
diff --git a/drivers/net/ethernet/intel/ice/ice_type.h b/drivers/net/ethernet/intel/ice/ice_type.h
index 99c8a9a71b5e..97c366e0ca59 100644
--- a/drivers/net/ethernet/intel/ice/ice_type.h
+++ b/drivers/net/ethernet/intel/ice/ice_type.h
@@ -83,7 +83,7 @@ struct ice_link_status {
83 u64 phy_type_low; 83 u64 phy_type_low;
84 u16 max_frame_size; 84 u16 max_frame_size;
85 u16 link_speed; 85 u16 link_speed;
86 bool lse_ena; /* Link Status Event notification */ 86 u8 lse_ena; /* Link Status Event notification */
87 u8 link_info; 87 u8 link_info;
88 u8 an_info; 88 u8 an_info;
89 u8 ext_info; 89 u8 ext_info;
@@ -101,7 +101,7 @@ struct ice_phy_info {
101 struct ice_link_status link_info_old; 101 struct ice_link_status link_info_old;
102 u64 phy_type_low; 102 u64 phy_type_low;
103 enum ice_media_type media_type; 103 enum ice_media_type media_type;
104 bool get_link_info; 104 u8 get_link_info;
105}; 105};
106 106
107/* Common HW capabilities for SW use */ 107/* Common HW capabilities for SW use */
@@ -167,7 +167,7 @@ struct ice_nvm_info {
167 u32 oem_ver; /* OEM version info */ 167 u32 oem_ver; /* OEM version info */
168 u16 sr_words; /* Shadow RAM size in words */ 168 u16 sr_words; /* Shadow RAM size in words */
169 u16 ver; /* NVM package version */ 169 u16 ver; /* NVM package version */
170 bool blank_nvm_mode; /* is NVM empty (no FW present) */ 170 u8 blank_nvm_mode; /* is NVM empty (no FW present) */
171}; 171};
172 172
173/* Max number of port to queue branches w.r.t topology */ 173/* Max number of port to queue branches w.r.t topology */
@@ -181,7 +181,7 @@ struct ice_sched_node {
181 struct ice_aqc_txsched_elem_data info; 181 struct ice_aqc_txsched_elem_data info;
182 u32 agg_id; /* aggregator group id */ 182 u32 agg_id; /* aggregator group id */
183 u16 vsi_id; 183 u16 vsi_id;
184 bool in_use; /* suspended or in use */ 184 u8 in_use; /* suspended or in use */
185 u8 tx_sched_layer; /* Logical Layer (1-9) */ 185 u8 tx_sched_layer; /* Logical Layer (1-9) */
186 u8 num_children; 186 u8 num_children;
187 u8 tc_num; 187 u8 tc_num;
@@ -218,7 +218,7 @@ struct ice_sched_vsi_info {
218struct ice_sched_tx_policy { 218struct ice_sched_tx_policy {
219 u16 max_num_vsis; 219 u16 max_num_vsis;
220 u8 max_num_lan_qs_per_tc[ICE_MAX_TRAFFIC_CLASS]; 220 u8 max_num_lan_qs_per_tc[ICE_MAX_TRAFFIC_CLASS];
221 bool rdma_ena; 221 u8 rdma_ena;
222}; 222};
223 223
224struct ice_port_info { 224struct ice_port_info {
@@ -243,7 +243,7 @@ struct ice_port_info {
243 struct list_head agg_list; /* lists all aggregator */ 243 struct list_head agg_list; /* lists all aggregator */
244 u8 lport; 244 u8 lport;
245#define ICE_LPORT_MASK 0xff 245#define ICE_LPORT_MASK 0xff
246 bool is_vf; 246 u8 is_vf;
247}; 247};
248 248
249struct ice_switch_info { 249struct ice_switch_info {
@@ -287,7 +287,7 @@ struct ice_hw {
287 u8 max_cgds; 287 u8 max_cgds;
288 u8 sw_entry_point_layer; 288 u8 sw_entry_point_layer;
289 289
290 bool evb_veb; /* true for VEB, false for VEPA */ 290 u8 evb_veb; /* true for VEB, false for VEPA */
291 struct ice_bus_info bus; 291 struct ice_bus_info bus;
292 struct ice_nvm_info nvm; 292 struct ice_nvm_info nvm;
293 struct ice_hw_dev_caps dev_caps; /* device capabilities */ 293 struct ice_hw_dev_caps dev_caps; /* device capabilities */
@@ -318,7 +318,7 @@ struct ice_hw {
318 u8 itr_gran_100; 318 u8 itr_gran_100;
319 u8 itr_gran_50; 319 u8 itr_gran_50;
320 u8 itr_gran_25; 320 u8 itr_gran_25;
321 bool ucast_shared; /* true if VSIs can share unicast addr */ 321 u8 ucast_shared; /* true if VSIs can share unicast addr */
322 322
323}; 323};
324 324
diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index f92f7918112d..5acf3b743876 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -1649,7 +1649,7 @@ static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1649 if (hw->phy.type == e1000_phy_m88) 1649 if (hw->phy.type == e1000_phy_m88)
1650 igb_phy_disable_receiver(adapter); 1650 igb_phy_disable_receiver(adapter);
1651 1651
1652 mdelay(500); 1652 msleep(500);
1653 return 0; 1653 return 0;
1654} 1654}
1655 1655
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index d03c2f0d7592..a32c576c1e65 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -3873,7 +3873,7 @@ static int igb_sw_init(struct igb_adapter *adapter)
3873 3873
3874 adapter->mac_table = kcalloc(hw->mac.rar_entry_count, 3874 adapter->mac_table = kcalloc(hw->mac.rar_entry_count,
3875 sizeof(struct igb_mac_addr), 3875 sizeof(struct igb_mac_addr),
3876 GFP_ATOMIC); 3876 GFP_KERNEL);
3877 if (!adapter->mac_table) 3877 if (!adapter->mac_table)
3878 return -ENOMEM; 3878 return -ENOMEM;
3879 3879
@@ -3883,7 +3883,7 @@ static int igb_sw_init(struct igb_adapter *adapter)
3883 3883
3884 /* Setup and initialize a copy of the hw vlan table array */ 3884 /* Setup and initialize a copy of the hw vlan table array */
3885 adapter->shadow_vfta = kcalloc(E1000_VLAN_FILTER_TBL_SIZE, sizeof(u32), 3885 adapter->shadow_vfta = kcalloc(E1000_VLAN_FILTER_TBL_SIZE, sizeof(u32),
3886 GFP_ATOMIC); 3886 GFP_KERNEL);
3887 if (!adapter->shadow_vfta) 3887 if (!adapter->shadow_vfta)
3888 return -ENOMEM; 3888 return -ENOMEM;
3889 3889
@@ -5816,7 +5816,8 @@ static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
5816 5816
5817 if (skb->ip_summed != CHECKSUM_PARTIAL) { 5817 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5818csum_failed: 5818csum_failed:
5819 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN)) 5819 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN) &&
5820 !tx_ring->launchtime_enable)
5820 return; 5821 return;
5821 goto no_csum; 5822 goto no_csum;
5822 } 5823 }
diff --git a/drivers/net/ethernet/intel/ixgb/ixgb_main.c b/drivers/net/ethernet/intel/ixgb/ixgb_main.c
index 43664adf7a3c..d3e72d0f66ef 100644
--- a/drivers/net/ethernet/intel/ixgb/ixgb_main.c
+++ b/drivers/net/ethernet/intel/ixgb/ixgb_main.c
@@ -771,14 +771,13 @@ ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
771 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc); 771 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
772 rxdr->size = ALIGN(rxdr->size, 4096); 772 rxdr->size = ALIGN(rxdr->size, 4096);
773 773
774 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma, 774 rxdr->desc = dma_zalloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
775 GFP_KERNEL); 775 GFP_KERNEL);
776 776
777 if (!rxdr->desc) { 777 if (!rxdr->desc) {
778 vfree(rxdr->buffer_info); 778 vfree(rxdr->buffer_info);
779 return -ENOMEM; 779 return -ENOMEM;
780 } 780 }
781 memset(rxdr->desc, 0, rxdr->size);
782 781
783 rxdr->next_to_clean = 0; 782 rxdr->next_to_clean = 0;
784 rxdr->next_to_use = 0; 783 rxdr->next_to_use = 0;
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
index 94b3165ff543..ccd852ad62a4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
@@ -192,7 +192,7 @@ static int ixgbe_fcoe_ddp_setup(struct net_device *netdev, u16 xid,
192 } 192 }
193 193
194 /* alloc the udl from per cpu ddp pool */ 194 /* alloc the udl from per cpu ddp pool */
195 ddp->udl = dma_pool_alloc(ddp_pool->pool, GFP_ATOMIC, &ddp->udp); 195 ddp->udl = dma_pool_alloc(ddp_pool->pool, GFP_KERNEL, &ddp->udp);
196 if (!ddp->udl) { 196 if (!ddp->udl) {
197 e_err(drv, "failed allocated ddp context\n"); 197 e_err(drv, "failed allocated ddp context\n");
198 goto out_noddp_unmap; 198 goto out_noddp_unmap;
@@ -760,7 +760,7 @@ int ixgbe_setup_fcoe_ddp_resources(struct ixgbe_adapter *adapter)
760 return 0; 760 return 0;
761 761
762 /* Extra buffer to be shared by all DDPs for HW work around */ 762 /* Extra buffer to be shared by all DDPs for HW work around */
763 buffer = kmalloc(IXGBE_FCBUFF_MIN, GFP_ATOMIC); 763 buffer = kmalloc(IXGBE_FCBUFF_MIN, GFP_KERNEL);
764 if (!buffer) 764 if (!buffer)
765 return -ENOMEM; 765 return -ENOMEM;
766 766
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 447098005490..9a23d33a47ed 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -6201,7 +6201,7 @@ static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
6201 6201
6202 adapter->mac_table = kcalloc(hw->mac.num_rar_entries, 6202 adapter->mac_table = kcalloc(hw->mac.num_rar_entries,
6203 sizeof(struct ixgbe_mac_addr), 6203 sizeof(struct ixgbe_mac_addr),
6204 GFP_ATOMIC); 6204 GFP_KERNEL);
6205 if (!adapter->mac_table) 6205 if (!adapter->mac_table)
6206 return -ENOMEM; 6206 return -ENOMEM;
6207 6207
@@ -6620,8 +6620,18 @@ static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6620 struct ixgbe_adapter *adapter = netdev_priv(netdev); 6620 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6621 6621
6622 if (adapter->xdp_prog) { 6622 if (adapter->xdp_prog) {
6623 e_warn(probe, "MTU cannot be changed while XDP program is loaded\n"); 6623 int new_frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN +
6624 return -EPERM; 6624 VLAN_HLEN;
6625 int i;
6626
6627 for (i = 0; i < adapter->num_rx_queues; i++) {
6628 struct ixgbe_ring *ring = adapter->rx_ring[i];
6629
6630 if (new_frame_size > ixgbe_rx_bufsz(ring)) {
6631 e_warn(probe, "Requested MTU size is not supported with XDP\n");
6632 return -EINVAL;
6633 }
6634 }
6625 } 6635 }
6626 6636
6627 /* 6637 /*
@@ -8983,6 +8993,15 @@ int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8983 8993
8984#ifdef CONFIG_IXGBE_DCB 8994#ifdef CONFIG_IXGBE_DCB
8985 if (tc) { 8995 if (tc) {
8996 if (adapter->xdp_prog) {
8997 e_warn(probe, "DCB is not supported with XDP\n");
8998
8999 ixgbe_init_interrupt_scheme(adapter);
9000 if (netif_running(dev))
9001 ixgbe_open(dev);
9002 return -EINVAL;
9003 }
9004
8986 netdev_set_num_tc(dev, tc); 9005 netdev_set_num_tc(dev, tc);
8987 ixgbe_set_prio_tc_map(adapter); 9006 ixgbe_set_prio_tc_map(adapter);
8988 9007
@@ -9171,14 +9190,12 @@ static int parse_tc_actions(struct ixgbe_adapter *adapter,
9171 struct tcf_exts *exts, u64 *action, u8 *queue) 9190 struct tcf_exts *exts, u64 *action, u8 *queue)
9172{ 9191{
9173 const struct tc_action *a; 9192 const struct tc_action *a;
9174 LIST_HEAD(actions); 9193 int i;
9175 9194
9176 if (!tcf_exts_has_actions(exts)) 9195 if (!tcf_exts_has_actions(exts))
9177 return -EINVAL; 9196 return -EINVAL;
9178 9197
9179 tcf_exts_to_list(exts, &actions); 9198 tcf_exts_for_each_action(i, a, exts) {
9180 list_for_each_entry(a, &actions, list) {
9181
9182 /* Drop action */ 9199 /* Drop action */
9183 if (is_tcf_gact_shot(a)) { 9200 if (is_tcf_gact_shot(a)) {
9184 *action = IXGBE_FDIR_DROP_QUEUE; 9201 *action = IXGBE_FDIR_DROP_QUEUE;
@@ -9936,6 +9953,11 @@ static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9936 int tcs = adapter->hw_tcs ? : 1; 9953 int tcs = adapter->hw_tcs ? : 1;
9937 int pool, err; 9954 int pool, err;
9938 9955
9956 if (adapter->xdp_prog) {
9957 e_warn(probe, "L2FW offload is not supported with XDP\n");
9958 return ERR_PTR(-EINVAL);
9959 }
9960
9939 /* The hardware supported by ixgbe only filters on the destination MAC 9961 /* The hardware supported by ixgbe only filters on the destination MAC
9940 * address. In order to avoid issues we only support offloading modes 9962 * address. In order to avoid issues we only support offloading modes
9941 * where the hardware can actually provide the functionality. 9963 * where the hardware can actually provide the functionality.
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
index 6f59933cdff7..3c6f01c41b78 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
@@ -53,6 +53,11 @@ static int __ixgbe_enable_sriov(struct ixgbe_adapter *adapter,
53 struct ixgbe_hw *hw = &adapter->hw; 53 struct ixgbe_hw *hw = &adapter->hw;
54 int i; 54 int i;
55 55
56 if (adapter->xdp_prog) {
57 e_warn(probe, "SRIOV is not supported with XDP\n");
58 return -EINVAL;
59 }
60
56 /* Enable VMDq flag so device will be set in VM mode */ 61 /* Enable VMDq flag so device will be set in VM mode */
57 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED | 62 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED |
58 IXGBE_FLAG_VMDQ_ENABLED; 63 IXGBE_FLAG_VMDQ_ENABLED;
@@ -688,8 +693,13 @@ static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
688static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf) 693static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
689{ 694{
690 struct ixgbe_hw *hw = &adapter->hw; 695 struct ixgbe_hw *hw = &adapter->hw;
696 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
691 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; 697 struct vf_data_storage *vfinfo = &adapter->vfinfo[vf];
698 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
692 u8 num_tcs = adapter->hw_tcs; 699 u8 num_tcs = adapter->hw_tcs;
700 u32 reg_val;
701 u32 queue;
702 u32 word;
693 703
694 /* remove VLAN filters beloning to this VF */ 704 /* remove VLAN filters beloning to this VF */
695 ixgbe_clear_vf_vlans(adapter, vf); 705 ixgbe_clear_vf_vlans(adapter, vf);
@@ -726,6 +736,27 @@ static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
726 736
727 /* reset VF api back to unknown */ 737 /* reset VF api back to unknown */
728 adapter->vfinfo[vf].vf_api = ixgbe_mbox_api_10; 738 adapter->vfinfo[vf].vf_api = ixgbe_mbox_api_10;
739
740 /* Restart each queue for given VF */
741 for (queue = 0; queue < q_per_pool; queue++) {
742 unsigned int reg_idx = (vf * q_per_pool) + queue;
743
744 reg_val = IXGBE_READ_REG(hw, IXGBE_PVFTXDCTL(reg_idx));
745
746 /* Re-enabling only configured queues */
747 if (reg_val) {
748 reg_val |= IXGBE_TXDCTL_ENABLE;
749 IXGBE_WRITE_REG(hw, IXGBE_PVFTXDCTL(reg_idx), reg_val);
750 reg_val &= ~IXGBE_TXDCTL_ENABLE;
751 IXGBE_WRITE_REG(hw, IXGBE_PVFTXDCTL(reg_idx), reg_val);
752 }
753 }
754
755 /* Clear VF's mailbox memory */
756 for (word = 0; word < IXGBE_VFMAILBOX_SIZE; word++)
757 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf), word, 0);
758
759 IXGBE_WRITE_FLUSH(hw);
729} 760}
730 761
731static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, 762static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter,
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
index 44cfb2021145..41bcbb337e83 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
@@ -2518,6 +2518,7 @@ enum {
2518/* Translated register #defines */ 2518/* Translated register #defines */
2519#define IXGBE_PVFTDH(P) (0x06010 + (0x40 * (P))) 2519#define IXGBE_PVFTDH(P) (0x06010 + (0x40 * (P)))
2520#define IXGBE_PVFTDT(P) (0x06018 + (0x40 * (P))) 2520#define IXGBE_PVFTDT(P) (0x06018 + (0x40 * (P)))
2521#define IXGBE_PVFTXDCTL(P) (0x06028 + (0x40 * (P)))
2521#define IXGBE_PVFTDWBAL(P) (0x06038 + (0x40 * (P))) 2522#define IXGBE_PVFTDWBAL(P) (0x06038 + (0x40 * (P)))
2522#define IXGBE_PVFTDWBAH(P) (0x0603C + (0x40 * (P))) 2523#define IXGBE_PVFTDWBAH(P) (0x0603C + (0x40 * (P)))
2523 2524
diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index 7a637b51c7d2..e08301d833e2 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -274,6 +274,7 @@ ltq_etop_hw_init(struct net_device *dev)
274 struct ltq_etop_chan *ch = &priv->ch[i]; 274 struct ltq_etop_chan *ch = &priv->ch[i];
275 275
276 ch->idx = ch->dma.nr = i; 276 ch->idx = ch->dma.nr = i;
277 ch->dma.dev = &priv->pdev->dev;
277 278
278 if (IS_TX(i)) { 279 if (IS_TX(i)) {
279 ltq_dma_alloc_tx(&ch->dma); 280 ltq_dma_alloc_tx(&ch->dma);
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 32d785b616e1..28500417843e 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -4803,6 +4803,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
4803 dev->min_mtu = ETH_MIN_MTU; 4803 dev->min_mtu = ETH_MIN_MTU;
4804 /* 9704 == 9728 - 20 and rounding to 8 */ 4804 /* 9704 == 9728 - 20 and rounding to 8 */
4805 dev->max_mtu = MVPP2_BM_JUMBO_PKT_SIZE; 4805 dev->max_mtu = MVPP2_BM_JUMBO_PKT_SIZE;
4806 dev->dev.of_node = port_node;
4806 4807
4807 /* Phylink isn't used w/ ACPI as of now */ 4808 /* Phylink isn't used w/ ACPI as of now */
4808 if (port_node) { 4809 if (port_node) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
index b994b80d5714..37ba7c78859d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
@@ -132,11 +132,11 @@ void mlx5_add_device(struct mlx5_interface *intf, struct mlx5_priv *priv)
132 delayed_event_start(priv); 132 delayed_event_start(priv);
133 133
134 dev_ctx->context = intf->add(dev); 134 dev_ctx->context = intf->add(dev);
135 set_bit(MLX5_INTERFACE_ADDED, &dev_ctx->state);
136 if (intf->attach)
137 set_bit(MLX5_INTERFACE_ATTACHED, &dev_ctx->state);
138
139 if (dev_ctx->context) { 135 if (dev_ctx->context) {
136 set_bit(MLX5_INTERFACE_ADDED, &dev_ctx->state);
137 if (intf->attach)
138 set_bit(MLX5_INTERFACE_ATTACHED, &dev_ctx->state);
139
140 spin_lock_irq(&priv->ctx_lock); 140 spin_lock_irq(&priv->ctx_lock);
141 list_add_tail(&dev_ctx->list, &priv->ctx_list); 141 list_add_tail(&dev_ctx->list, &priv->ctx_list);
142 142
@@ -211,12 +211,17 @@ static void mlx5_attach_interface(struct mlx5_interface *intf, struct mlx5_priv
211 if (intf->attach) { 211 if (intf->attach) {
212 if (test_bit(MLX5_INTERFACE_ATTACHED, &dev_ctx->state)) 212 if (test_bit(MLX5_INTERFACE_ATTACHED, &dev_ctx->state))
213 goto out; 213 goto out;
214 intf->attach(dev, dev_ctx->context); 214 if (intf->attach(dev, dev_ctx->context))
215 goto out;
216
215 set_bit(MLX5_INTERFACE_ATTACHED, &dev_ctx->state); 217 set_bit(MLX5_INTERFACE_ATTACHED, &dev_ctx->state);
216 } else { 218 } else {
217 if (test_bit(MLX5_INTERFACE_ADDED, &dev_ctx->state)) 219 if (test_bit(MLX5_INTERFACE_ADDED, &dev_ctx->state))
218 goto out; 220 goto out;
219 dev_ctx->context = intf->add(dev); 221 dev_ctx->context = intf->add(dev);
222 if (!dev_ctx->context)
223 goto out;
224
220 set_bit(MLX5_INTERFACE_ADDED, &dev_ctx->state); 225 set_bit(MLX5_INTERFACE_ADDED, &dev_ctx->state);
221 } 226 }
222 227
@@ -391,16 +396,17 @@ void mlx5_remove_dev_by_protocol(struct mlx5_core_dev *dev, int protocol)
391 } 396 }
392} 397}
393 398
394static u16 mlx5_gen_pci_id(struct mlx5_core_dev *dev) 399static u32 mlx5_gen_pci_id(struct mlx5_core_dev *dev)
395{ 400{
396 return (u16)((dev->pdev->bus->number << 8) | 401 return (u32)((pci_domain_nr(dev->pdev->bus) << 16) |
402 (dev->pdev->bus->number << 8) |
397 PCI_SLOT(dev->pdev->devfn)); 403 PCI_SLOT(dev->pdev->devfn));
398} 404}
399 405
400/* Must be called with intf_mutex held */ 406/* Must be called with intf_mutex held */
401struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev) 407struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
402{ 408{
403 u16 pci_id = mlx5_gen_pci_id(dev); 409 u32 pci_id = mlx5_gen_pci_id(dev);
404 struct mlx5_core_dev *res = NULL; 410 struct mlx5_core_dev *res = NULL;
405 struct mlx5_core_dev *tmp_dev; 411 struct mlx5_core_dev *tmp_dev;
406 struct mlx5_priv *priv; 412 struct mlx5_priv *priv;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c
index 75bb981e00b7..41cde926cdab 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c
@@ -191,7 +191,7 @@ set_udp(void *headers_c, void *headers_v, __be16 psrc_m, __be16 psrc_v,
191{ 191{
192 if (psrc_m) { 192 if (psrc_m) {
193 MLX5E_FTE_SET(headers_c, udp_sport, 0xffff); 193 MLX5E_FTE_SET(headers_c, udp_sport, 0xffff);
194 MLX5E_FTE_SET(headers_c, udp_sport, ntohs(psrc_v)); 194 MLX5E_FTE_SET(headers_v, udp_sport, ntohs(psrc_v));
195 } 195 }
196 196
197 if (pdst_m) { 197 if (pdst_m) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 9131a1376e7d..9fed54017659 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -1982,14 +1982,15 @@ static bool modify_header_match_supported(struct mlx5_flow_spec *spec,
1982 goto out_ok; 1982 goto out_ok;
1983 1983
1984 modify_ip_header = false; 1984 modify_ip_header = false;
1985 tcf_exts_to_list(exts, &actions); 1985 tcf_exts_for_each_action(i, a, exts) {
1986 list_for_each_entry(a, &actions, list) { 1986 int k;
1987
1987 if (!is_tcf_pedit(a)) 1988 if (!is_tcf_pedit(a))
1988 continue; 1989 continue;
1989 1990
1990 nkeys = tcf_pedit_nkeys(a); 1991 nkeys = tcf_pedit_nkeys(a);
1991 for (i = 0; i < nkeys; i++) { 1992 for (k = 0; k < nkeys; k++) {
1992 htype = tcf_pedit_htype(a, i); 1993 htype = tcf_pedit_htype(a, k);
1993 if (htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 || 1994 if (htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 ||
1994 htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP6) { 1995 htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP6) {
1995 modify_ip_header = true; 1996 modify_ip_header = true;
@@ -2053,15 +2054,14 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
2053 const struct tc_action *a; 2054 const struct tc_action *a;
2054 LIST_HEAD(actions); 2055 LIST_HEAD(actions);
2055 u32 action = 0; 2056 u32 action = 0;
2056 int err; 2057 int err, i;
2057 2058
2058 if (!tcf_exts_has_actions(exts)) 2059 if (!tcf_exts_has_actions(exts))
2059 return -EINVAL; 2060 return -EINVAL;
2060 2061
2061 attr->flow_tag = MLX5_FS_DEFAULT_FLOW_TAG; 2062 attr->flow_tag = MLX5_FS_DEFAULT_FLOW_TAG;
2062 2063
2063 tcf_exts_to_list(exts, &actions); 2064 tcf_exts_for_each_action(i, a, exts) {
2064 list_for_each_entry(a, &actions, list) {
2065 if (is_tcf_gact_shot(a)) { 2065 if (is_tcf_gact_shot(a)) {
2066 action |= MLX5_FLOW_CONTEXT_ACTION_DROP; 2066 action |= MLX5_FLOW_CONTEXT_ACTION_DROP;
2067 if (MLX5_CAP_FLOWTABLE(priv->mdev, 2067 if (MLX5_CAP_FLOWTABLE(priv->mdev,
@@ -2666,7 +2666,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
2666 LIST_HEAD(actions); 2666 LIST_HEAD(actions);
2667 bool encap = false; 2667 bool encap = false;
2668 u32 action = 0; 2668 u32 action = 0;
2669 int err; 2669 int err, i;
2670 2670
2671 if (!tcf_exts_has_actions(exts)) 2671 if (!tcf_exts_has_actions(exts))
2672 return -EINVAL; 2672 return -EINVAL;
@@ -2674,8 +2674,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
2674 attr->in_rep = rpriv->rep; 2674 attr->in_rep = rpriv->rep;
2675 attr->in_mdev = priv->mdev; 2675 attr->in_mdev = priv->mdev;
2676 2676
2677 tcf_exts_to_list(exts, &actions); 2677 tcf_exts_for_each_action(i, a, exts) {
2678 list_for_each_entry(a, &actions, list) {
2679 if (is_tcf_gact_shot(a)) { 2678 if (is_tcf_gact_shot(a)) {
2680 action |= MLX5_FLOW_CONTEXT_ACTION_DROP | 2679 action |= MLX5_FLOW_CONTEXT_ACTION_DROP |
2681 MLX5_FLOW_CONTEXT_ACTION_COUNT; 2680 MLX5_FLOW_CONTEXT_ACTION_COUNT;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index f72b5c9dcfe9..3028e8d90920 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -663,6 +663,7 @@ static int esw_create_offloads_fdb_tables(struct mlx5_eswitch *esw, int nvports)
663 if (err) 663 if (err)
664 goto miss_rule_err; 664 goto miss_rule_err;
665 665
666 kvfree(flow_group_in);
666 return 0; 667 return 0;
667 668
668miss_rule_err: 669miss_rule_err:
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
index f418541af7cf..37d114c668b7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
@@ -1578,6 +1578,33 @@ static u64 matched_fgs_get_version(struct list_head *match_head)
1578 return version; 1578 return version;
1579} 1579}
1580 1580
1581static struct fs_fte *
1582lookup_fte_locked(struct mlx5_flow_group *g,
1583 u32 *match_value,
1584 bool take_write)
1585{
1586 struct fs_fte *fte_tmp;
1587
1588 if (take_write)
1589 nested_down_write_ref_node(&g->node, FS_LOCK_PARENT);
1590 else
1591 nested_down_read_ref_node(&g->node, FS_LOCK_PARENT);
1592 fte_tmp = rhashtable_lookup_fast(&g->ftes_hash, match_value,
1593 rhash_fte);
1594 if (!fte_tmp || !tree_get_node(&fte_tmp->node)) {
1595 fte_tmp = NULL;
1596 goto out;
1597 }
1598
1599 nested_down_write_ref_node(&fte_tmp->node, FS_LOCK_CHILD);
1600out:
1601 if (take_write)
1602 up_write_ref_node(&g->node);
1603 else
1604 up_read_ref_node(&g->node);
1605 return fte_tmp;
1606}
1607
1581static struct mlx5_flow_handle * 1608static struct mlx5_flow_handle *
1582try_add_to_existing_fg(struct mlx5_flow_table *ft, 1609try_add_to_existing_fg(struct mlx5_flow_table *ft,
1583 struct list_head *match_head, 1610 struct list_head *match_head,
@@ -1600,10 +1627,6 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
1600 if (IS_ERR(fte)) 1627 if (IS_ERR(fte))
1601 return ERR_PTR(-ENOMEM); 1628 return ERR_PTR(-ENOMEM);
1602 1629
1603 list_for_each_entry(iter, match_head, list) {
1604 nested_down_read_ref_node(&iter->g->node, FS_LOCK_PARENT);
1605 }
1606
1607search_again_locked: 1630search_again_locked:
1608 version = matched_fgs_get_version(match_head); 1631 version = matched_fgs_get_version(match_head);
1609 /* Try to find a fg that already contains a matching fte */ 1632 /* Try to find a fg that already contains a matching fte */
@@ -1611,20 +1634,9 @@ search_again_locked:
1611 struct fs_fte *fte_tmp; 1634 struct fs_fte *fte_tmp;
1612 1635
1613 g = iter->g; 1636 g = iter->g;
1614 fte_tmp = rhashtable_lookup_fast(&g->ftes_hash, spec->match_value, 1637 fte_tmp = lookup_fte_locked(g, spec->match_value, take_write);
1615 rhash_fte); 1638 if (!fte_tmp)
1616 if (!fte_tmp || !tree_get_node(&fte_tmp->node))
1617 continue; 1639 continue;
1618
1619 nested_down_write_ref_node(&fte_tmp->node, FS_LOCK_CHILD);
1620 if (!take_write) {
1621 list_for_each_entry(iter, match_head, list)
1622 up_read_ref_node(&iter->g->node);
1623 } else {
1624 list_for_each_entry(iter, match_head, list)
1625 up_write_ref_node(&iter->g->node);
1626 }
1627
1628 rule = add_rule_fg(g, spec->match_value, 1640 rule = add_rule_fg(g, spec->match_value,
1629 flow_act, dest, dest_num, fte_tmp); 1641 flow_act, dest, dest_num, fte_tmp);
1630 up_write_ref_node(&fte_tmp->node); 1642 up_write_ref_node(&fte_tmp->node);
@@ -1633,19 +1645,6 @@ search_again_locked:
1633 return rule; 1645 return rule;
1634 } 1646 }
1635 1647
1636 /* No group with matching fte found. Try to add a new fte to any
1637 * matching fg.
1638 */
1639
1640 if (!take_write) {
1641 list_for_each_entry(iter, match_head, list)
1642 up_read_ref_node(&iter->g->node);
1643 list_for_each_entry(iter, match_head, list)
1644 nested_down_write_ref_node(&iter->g->node,
1645 FS_LOCK_PARENT);
1646 take_write = true;
1647 }
1648
1649 /* Check the ft version, for case that new flow group 1648 /* Check the ft version, for case that new flow group
1650 * was added while the fgs weren't locked 1649 * was added while the fgs weren't locked
1651 */ 1650 */
@@ -1657,27 +1656,30 @@ search_again_locked:
1657 /* Check the fgs version, for case the new FTE with the 1656 /* Check the fgs version, for case the new FTE with the
1658 * same values was added while the fgs weren't locked 1657 * same values was added while the fgs weren't locked
1659 */ 1658 */
1660 if (version != matched_fgs_get_version(match_head)) 1659 if (version != matched_fgs_get_version(match_head)) {
1660 take_write = true;
1661 goto search_again_locked; 1661 goto search_again_locked;
1662 }
1662 1663
1663 list_for_each_entry(iter, match_head, list) { 1664 list_for_each_entry(iter, match_head, list) {
1664 g = iter->g; 1665 g = iter->g;
1665 1666
1666 if (!g->node.active) 1667 if (!g->node.active)
1667 continue; 1668 continue;
1669
1670 nested_down_write_ref_node(&g->node, FS_LOCK_PARENT);
1671
1668 err = insert_fte(g, fte); 1672 err = insert_fte(g, fte);
1669 if (err) { 1673 if (err) {
1674 up_write_ref_node(&g->node);
1670 if (err == -ENOSPC) 1675 if (err == -ENOSPC)
1671 continue; 1676 continue;
1672 list_for_each_entry(iter, match_head, list)
1673 up_write_ref_node(&iter->g->node);
1674 kmem_cache_free(steering->ftes_cache, fte); 1677 kmem_cache_free(steering->ftes_cache, fte);
1675 return ERR_PTR(err); 1678 return ERR_PTR(err);
1676 } 1679 }
1677 1680
1678 nested_down_write_ref_node(&fte->node, FS_LOCK_CHILD); 1681 nested_down_write_ref_node(&fte->node, FS_LOCK_CHILD);
1679 list_for_each_entry(iter, match_head, list) 1682 up_write_ref_node(&g->node);
1680 up_write_ref_node(&iter->g->node);
1681 rule = add_rule_fg(g, spec->match_value, 1683 rule = add_rule_fg(g, spec->match_value,
1682 flow_act, dest, dest_num, fte); 1684 flow_act, dest, dest_num, fte);
1683 up_write_ref_node(&fte->node); 1685 up_write_ref_node(&fte->node);
@@ -1686,8 +1688,6 @@ search_again_locked:
1686 } 1688 }
1687 rule = ERR_PTR(-ENOENT); 1689 rule = ERR_PTR(-ENOENT);
1688out: 1690out:
1689 list_for_each_entry(iter, match_head, list)
1690 up_write_ref_node(&iter->g->node);
1691 kmem_cache_free(steering->ftes_cache, fte); 1691 kmem_cache_free(steering->ftes_cache, fte);
1692 return rule; 1692 return rule;
1693} 1693}
@@ -1726,6 +1726,8 @@ search_again_locked:
1726 if (err) { 1726 if (err) {
1727 if (take_write) 1727 if (take_write)
1728 up_write_ref_node(&ft->node); 1728 up_write_ref_node(&ft->node);
1729 else
1730 up_read_ref_node(&ft->node);
1729 return ERR_PTR(err); 1731 return ERR_PTR(err);
1730 } 1732 }
1731 1733
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index d39b0b7011b2..9f39aeca863f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -331,9 +331,17 @@ void mlx5_start_health_poll(struct mlx5_core_dev *dev)
331 add_timer(&health->timer); 331 add_timer(&health->timer);
332} 332}
333 333
334void mlx5_stop_health_poll(struct mlx5_core_dev *dev) 334void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health)
335{ 335{
336 struct mlx5_core_health *health = &dev->priv.health; 336 struct mlx5_core_health *health = &dev->priv.health;
337 unsigned long flags;
338
339 if (disable_health) {
340 spin_lock_irqsave(&health->wq_lock, flags);
341 set_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
342 set_bit(MLX5_DROP_NEW_RECOVERY_WORK, &health->flags);
343 spin_unlock_irqrestore(&health->wq_lock, flags);
344 }
337 345
338 del_timer_sync(&health->timer); 346 del_timer_sync(&health->timer);
339} 347}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index cf3e4a659052..b5e9f664fc66 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -878,8 +878,10 @@ static int mlx5_pci_init(struct mlx5_core_dev *dev, struct mlx5_priv *priv)
878 priv->numa_node = dev_to_node(&dev->pdev->dev); 878 priv->numa_node = dev_to_node(&dev->pdev->dev);
879 879
880 priv->dbg_root = debugfs_create_dir(dev_name(&pdev->dev), mlx5_debugfs_root); 880 priv->dbg_root = debugfs_create_dir(dev_name(&pdev->dev), mlx5_debugfs_root);
881 if (!priv->dbg_root) 881 if (!priv->dbg_root) {
882 dev_err(&pdev->dev, "Cannot create debugfs dir, aborting\n");
882 return -ENOMEM; 883 return -ENOMEM;
884 }
883 885
884 err = mlx5_pci_enable_device(dev); 886 err = mlx5_pci_enable_device(dev);
885 if (err) { 887 if (err) {
@@ -928,7 +930,7 @@ static void mlx5_pci_close(struct mlx5_core_dev *dev, struct mlx5_priv *priv)
928 pci_clear_master(dev->pdev); 930 pci_clear_master(dev->pdev);
929 release_bar(dev->pdev); 931 release_bar(dev->pdev);
930 mlx5_pci_disable_device(dev); 932 mlx5_pci_disable_device(dev);
931 debugfs_remove(priv->dbg_root); 933 debugfs_remove_recursive(priv->dbg_root);
932} 934}
933 935
934static int mlx5_init_once(struct mlx5_core_dev *dev, struct mlx5_priv *priv) 936static int mlx5_init_once(struct mlx5_core_dev *dev, struct mlx5_priv *priv)
@@ -1286,7 +1288,7 @@ err_cleanup_once:
1286 mlx5_cleanup_once(dev); 1288 mlx5_cleanup_once(dev);
1287 1289
1288err_stop_poll: 1290err_stop_poll:
1289 mlx5_stop_health_poll(dev); 1291 mlx5_stop_health_poll(dev, boot);
1290 if (mlx5_cmd_teardown_hca(dev)) { 1292 if (mlx5_cmd_teardown_hca(dev)) {
1291 dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n"); 1293 dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n");
1292 goto out_err; 1294 goto out_err;
@@ -1346,7 +1348,7 @@ static int mlx5_unload_one(struct mlx5_core_dev *dev, struct mlx5_priv *priv,
1346 mlx5_free_irq_vectors(dev); 1348 mlx5_free_irq_vectors(dev);
1347 if (cleanup) 1349 if (cleanup)
1348 mlx5_cleanup_once(dev); 1350 mlx5_cleanup_once(dev);
1349 mlx5_stop_health_poll(dev); 1351 mlx5_stop_health_poll(dev, cleanup);
1350 err = mlx5_cmd_teardown_hca(dev); 1352 err = mlx5_cmd_teardown_hca(dev);
1351 if (err) { 1353 if (err) {
1352 dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n"); 1354 dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n");
@@ -1608,7 +1610,7 @@ static int mlx5_try_fast_unload(struct mlx5_core_dev *dev)
1608 * with the HCA, so the health polll is no longer needed. 1610 * with the HCA, so the health polll is no longer needed.
1609 */ 1611 */
1610 mlx5_drain_health_wq(dev); 1612 mlx5_drain_health_wq(dev);
1611 mlx5_stop_health_poll(dev); 1613 mlx5_stop_health_poll(dev, false);
1612 1614
1613 ret = mlx5_cmd_force_teardown_hca(dev); 1615 ret = mlx5_cmd_force_teardown_hca(dev);
1614 if (ret) { 1616 if (ret) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/wq.c b/drivers/net/ethernet/mellanox/mlx5/core/wq.c
index 86478a6b99c5..68e7f8df2a6d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/wq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/wq.c
@@ -39,9 +39,9 @@ u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq)
39 return (u32)wq->fbc.sz_m1 + 1; 39 return (u32)wq->fbc.sz_m1 + 1;
40} 40}
41 41
42u32 mlx5_wq_cyc_get_frag_size(struct mlx5_wq_cyc *wq) 42u16 mlx5_wq_cyc_get_frag_size(struct mlx5_wq_cyc *wq)
43{ 43{
44 return (u32)wq->fbc.frag_sz_m1 + 1; 44 return wq->fbc.frag_sz_m1 + 1;
45} 45}
46 46
47u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq) 47u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq)
@@ -138,15 +138,16 @@ int mlx5_wq_qp_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
138 void *qpc, struct mlx5_wq_qp *wq, 138 void *qpc, struct mlx5_wq_qp *wq,
139 struct mlx5_wq_ctrl *wq_ctrl) 139 struct mlx5_wq_ctrl *wq_ctrl)
140{ 140{
141 u32 sq_strides_offset; 141 u16 sq_strides_offset;
142 u32 rq_pg_remainder;
142 int err; 143 int err;
143 144
144 mlx5_fill_fbc(MLX5_GET(qpc, qpc, log_rq_stride) + 4, 145 mlx5_fill_fbc(MLX5_GET(qpc, qpc, log_rq_stride) + 4,
145 MLX5_GET(qpc, qpc, log_rq_size), 146 MLX5_GET(qpc, qpc, log_rq_size),
146 &wq->rq.fbc); 147 &wq->rq.fbc);
147 148
148 sq_strides_offset = 149 rq_pg_remainder = mlx5_wq_cyc_get_byte_size(&wq->rq) % PAGE_SIZE;
149 ((wq->rq.fbc.frag_sz_m1 + 1) % PAGE_SIZE) / MLX5_SEND_WQE_BB; 150 sq_strides_offset = rq_pg_remainder / MLX5_SEND_WQE_BB;
150 151
151 mlx5_fill_fbc_offset(ilog2(MLX5_SEND_WQE_BB), 152 mlx5_fill_fbc_offset(ilog2(MLX5_SEND_WQE_BB),
152 MLX5_GET(qpc, qpc, log_sq_size), 153 MLX5_GET(qpc, qpc, log_sq_size),
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/wq.h b/drivers/net/ethernet/mellanox/mlx5/core/wq.h
index 2bd4c3184eba..3a1a170bb2d7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/wq.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/wq.h
@@ -80,7 +80,7 @@ int mlx5_wq_cyc_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
80 void *wqc, struct mlx5_wq_cyc *wq, 80 void *wqc, struct mlx5_wq_cyc *wq,
81 struct mlx5_wq_ctrl *wq_ctrl); 81 struct mlx5_wq_ctrl *wq_ctrl);
82u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq); 82u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq);
83u32 mlx5_wq_cyc_get_frag_size(struct mlx5_wq_cyc *wq); 83u16 mlx5_wq_cyc_get_frag_size(struct mlx5_wq_cyc *wq);
84 84
85int mlx5_wq_qp_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param, 85int mlx5_wq_qp_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
86 void *qpc, struct mlx5_wq_qp *wq, 86 void *qpc, struct mlx5_wq_qp *wq,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 6070d1591d1e..930700413b1d 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -1346,8 +1346,7 @@ static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
1346 return -ENOMEM; 1346 return -ENOMEM;
1347 mall_tc_entry->cookie = f->cookie; 1347 mall_tc_entry->cookie = f->cookie;
1348 1348
1349 tcf_exts_to_list(f->exts, &actions); 1349 a = tcf_exts_first_action(f->exts);
1350 a = list_first_entry(&actions, struct tc_action, list);
1351 1350
1352 if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) { 1351 if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
1353 struct mlxsw_sp_port_mall_mirror_tc_entry *mirror; 1352 struct mlxsw_sp_port_mall_mirror_tc_entry *mirror;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index 3ae930196741..3cdb7aca90b7 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -414,6 +414,8 @@ mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
414void 414void
415mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); 415mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
416void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif); 416void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif);
417void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
418 struct net_device *dev);
417 419
418/* spectrum_kvdl.c */ 420/* spectrum_kvdl.c */
419enum mlxsw_sp_kvdl_entry_type { 421enum mlxsw_sp_kvdl_entry_type {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
index 4327487553c5..3589432d1643 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
@@ -337,14 +337,14 @@ static const struct mlxsw_sp_sb_cm mlxsw_sp_sb_cms_egress[] = {
337 MLXSW_SP_SB_CM(1500, 9, 0), 337 MLXSW_SP_SB_CM(1500, 9, 0),
338 MLXSW_SP_SB_CM(1500, 9, 0), 338 MLXSW_SP_SB_CM(1500, 9, 0),
339 MLXSW_SP_SB_CM(1500, 9, 0), 339 MLXSW_SP_SB_CM(1500, 9, 0),
340 MLXSW_SP_SB_CM(0, 0, 0), 340 MLXSW_SP_SB_CM(0, 140000, 15),
341 MLXSW_SP_SB_CM(0, 0, 0), 341 MLXSW_SP_SB_CM(0, 140000, 15),
342 MLXSW_SP_SB_CM(0, 0, 0), 342 MLXSW_SP_SB_CM(0, 140000, 15),
343 MLXSW_SP_SB_CM(0, 0, 0), 343 MLXSW_SP_SB_CM(0, 140000, 15),
344 MLXSW_SP_SB_CM(0, 0, 0), 344 MLXSW_SP_SB_CM(0, 140000, 15),
345 MLXSW_SP_SB_CM(0, 0, 0), 345 MLXSW_SP_SB_CM(0, 140000, 15),
346 MLXSW_SP_SB_CM(0, 0, 0), 346 MLXSW_SP_SB_CM(0, 140000, 15),
347 MLXSW_SP_SB_CM(0, 0, 0), 347 MLXSW_SP_SB_CM(0, 140000, 15),
348 MLXSW_SP_SB_CM(1, 0xff, 0), 348 MLXSW_SP_SB_CM(1, 0xff, 0),
349}; 349};
350 350
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
index ebd1b24ebaa5..8d211972c5e9 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -21,8 +21,7 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
21 struct netlink_ext_ack *extack) 21 struct netlink_ext_ack *extack)
22{ 22{
23 const struct tc_action *a; 23 const struct tc_action *a;
24 LIST_HEAD(actions); 24 int err, i;
25 int err;
26 25
27 if (!tcf_exts_has_actions(exts)) 26 if (!tcf_exts_has_actions(exts))
28 return 0; 27 return 0;
@@ -32,8 +31,7 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
32 if (err) 31 if (err)
33 return err; 32 return err;
34 33
35 tcf_exts_to_list(exts, &actions); 34 tcf_exts_for_each_action(i, a, exts) {
36 list_for_each_entry(a, &actions, list) {
37 if (is_tcf_gact_ok(a)) { 35 if (is_tcf_gact_ok(a)) {
38 err = mlxsw_sp_acl_rulei_act_terminate(rulei); 36 err = mlxsw_sp_acl_rulei_act_terminate(rulei);
39 if (err) { 37 if (err) {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 3a96307f51b0..2ab9cf25a08a 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -6234,6 +6234,17 @@ void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif)
6234 mlxsw_sp_vr_put(mlxsw_sp, vr); 6234 mlxsw_sp_vr_put(mlxsw_sp, vr);
6235} 6235}
6236 6236
6237void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
6238 struct net_device *dev)
6239{
6240 struct mlxsw_sp_rif *rif;
6241
6242 rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev);
6243 if (!rif)
6244 return;
6245 mlxsw_sp_rif_destroy(rif);
6246}
6247
6237static void 6248static void
6238mlxsw_sp_rif_subport_params_init(struct mlxsw_sp_rif_params *params, 6249mlxsw_sp_rif_subport_params_init(struct mlxsw_sp_rif_params *params,
6239 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan) 6250 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 0d8444aaba01..db715da7bab7 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -127,6 +127,24 @@ bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
127 return !!mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev); 127 return !!mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
128} 128}
129 129
130static int mlxsw_sp_bridge_device_upper_rif_destroy(struct net_device *dev,
131 void *data)
132{
133 struct mlxsw_sp *mlxsw_sp = data;
134
135 mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev);
136 return 0;
137}
138
139static void mlxsw_sp_bridge_device_rifs_destroy(struct mlxsw_sp *mlxsw_sp,
140 struct net_device *dev)
141{
142 mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev);
143 netdev_walk_all_upper_dev_rcu(dev,
144 mlxsw_sp_bridge_device_upper_rif_destroy,
145 mlxsw_sp);
146}
147
130static struct mlxsw_sp_bridge_device * 148static struct mlxsw_sp_bridge_device *
131mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge, 149mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge,
132 struct net_device *br_dev) 150 struct net_device *br_dev)
@@ -165,6 +183,8 @@ static void
165mlxsw_sp_bridge_device_destroy(struct mlxsw_sp_bridge *bridge, 183mlxsw_sp_bridge_device_destroy(struct mlxsw_sp_bridge *bridge,
166 struct mlxsw_sp_bridge_device *bridge_device) 184 struct mlxsw_sp_bridge_device *bridge_device)
167{ 185{
186 mlxsw_sp_bridge_device_rifs_destroy(bridge->mlxsw_sp,
187 bridge_device->dev);
168 list_del(&bridge_device->list); 188 list_del(&bridge_device->list);
169 if (bridge_device->vlan_enabled) 189 if (bridge_device->vlan_enabled)
170 bridge->vlan_enabled_exists = false; 190 bridge->vlan_enabled_exists = false;
diff --git a/drivers/net/ethernet/netronome/nfp/flower/action.c b/drivers/net/ethernet/netronome/nfp/flower/action.c
index 0ba0356ec4e6..46ba0cf257c6 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/action.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/action.c
@@ -52,6 +52,7 @@
52#define NFP_FL_TUNNEL_CSUM cpu_to_be16(0x01) 52#define NFP_FL_TUNNEL_CSUM cpu_to_be16(0x01)
53#define NFP_FL_TUNNEL_KEY cpu_to_be16(0x04) 53#define NFP_FL_TUNNEL_KEY cpu_to_be16(0x04)
54#define NFP_FL_TUNNEL_GENEVE_OPT cpu_to_be16(0x0800) 54#define NFP_FL_TUNNEL_GENEVE_OPT cpu_to_be16(0x0800)
55#define NFP_FL_SUPPORTED_TUNNEL_INFO_FLAGS IP_TUNNEL_INFO_TX
55#define NFP_FL_SUPPORTED_IPV4_UDP_TUN_FLAGS (NFP_FL_TUNNEL_CSUM | \ 56#define NFP_FL_SUPPORTED_IPV4_UDP_TUN_FLAGS (NFP_FL_TUNNEL_CSUM | \
56 NFP_FL_TUNNEL_KEY | \ 57 NFP_FL_TUNNEL_KEY | \
57 NFP_FL_TUNNEL_GENEVE_OPT) 58 NFP_FL_TUNNEL_GENEVE_OPT)
@@ -741,11 +742,16 @@ nfp_flower_loop_action(struct nfp_app *app, const struct tc_action *a,
741 nfp_fl_push_vlan(psh_v, a); 742 nfp_fl_push_vlan(psh_v, a);
742 *a_len += sizeof(struct nfp_fl_push_vlan); 743 *a_len += sizeof(struct nfp_fl_push_vlan);
743 } else if (is_tcf_tunnel_set(a)) { 744 } else if (is_tcf_tunnel_set(a)) {
745 struct ip_tunnel_info *ip_tun = tcf_tunnel_info(a);
744 struct nfp_repr *repr = netdev_priv(netdev); 746 struct nfp_repr *repr = netdev_priv(netdev);
747
745 *tun_type = nfp_fl_get_tun_from_act_l4_port(repr->app, a); 748 *tun_type = nfp_fl_get_tun_from_act_l4_port(repr->app, a);
746 if (*tun_type == NFP_FL_TUNNEL_NONE) 749 if (*tun_type == NFP_FL_TUNNEL_NONE)
747 return -EOPNOTSUPP; 750 return -EOPNOTSUPP;
748 751
752 if (ip_tun->mode & ~NFP_FL_SUPPORTED_TUNNEL_INFO_FLAGS)
753 return -EOPNOTSUPP;
754
749 /* Pre-tunnel action is required for tunnel encap. 755 /* Pre-tunnel action is required for tunnel encap.
750 * This checks for next hop entries on NFP. 756 * This checks for next hop entries on NFP.
751 * If none, the packet falls back before applying other actions. 757 * If none, the packet falls back before applying other actions.
@@ -796,11 +802,10 @@ int nfp_flower_compile_action(struct nfp_app *app,
796 struct net_device *netdev, 802 struct net_device *netdev,
797 struct nfp_fl_payload *nfp_flow) 803 struct nfp_fl_payload *nfp_flow)
798{ 804{
799 int act_len, act_cnt, err, tun_out_cnt, out_cnt; 805 int act_len, act_cnt, err, tun_out_cnt, out_cnt, i;
800 enum nfp_flower_tun_type tun_type; 806 enum nfp_flower_tun_type tun_type;
801 const struct tc_action *a; 807 const struct tc_action *a;
802 u32 csum_updated = 0; 808 u32 csum_updated = 0;
803 LIST_HEAD(actions);
804 809
805 memset(nfp_flow->action_data, 0, NFP_FL_MAX_A_SIZ); 810 memset(nfp_flow->action_data, 0, NFP_FL_MAX_A_SIZ);
806 nfp_flow->meta.act_len = 0; 811 nfp_flow->meta.act_len = 0;
@@ -810,8 +815,7 @@ int nfp_flower_compile_action(struct nfp_app *app,
810 tun_out_cnt = 0; 815 tun_out_cnt = 0;
811 out_cnt = 0; 816 out_cnt = 0;
812 817
813 tcf_exts_to_list(flow->exts, &actions); 818 tcf_exts_for_each_action(i, a, flow->exts) {
814 list_for_each_entry(a, &actions, list) {
815 err = nfp_flower_loop_action(app, a, flow, nfp_flow, &act_len, 819 err = nfp_flower_loop_action(app, a, flow, nfp_flow, &act_len,
816 netdev, &tun_type, &tun_out_cnt, 820 netdev, &tun_type, &tun_out_cnt,
817 &out_cnt, &csum_updated); 821 &out_cnt, &csum_updated);
diff --git a/drivers/net/ethernet/netronome/nfp/flower/main.h b/drivers/net/ethernet/netronome/nfp/flower/main.h
index 85f8209bf007..81d941ab895c 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/main.h
+++ b/drivers/net/ethernet/netronome/nfp/flower/main.h
@@ -70,6 +70,7 @@ struct nfp_app;
70#define NFP_FL_FEATS_GENEVE BIT(0) 70#define NFP_FL_FEATS_GENEVE BIT(0)
71#define NFP_FL_NBI_MTU_SETTING BIT(1) 71#define NFP_FL_NBI_MTU_SETTING BIT(1)
72#define NFP_FL_FEATS_GENEVE_OPT BIT(2) 72#define NFP_FL_FEATS_GENEVE_OPT BIT(2)
73#define NFP_FL_FEATS_VLAN_PCP BIT(3)
73#define NFP_FL_FEATS_LAG BIT(31) 74#define NFP_FL_FEATS_LAG BIT(31)
74 75
75struct nfp_fl_mask_id { 76struct nfp_fl_mask_id {
diff --git a/drivers/net/ethernet/netronome/nfp/flower/match.c b/drivers/net/ethernet/netronome/nfp/flower/match.c
index a0c72f277faa..17acb8cc6044 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/match.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/match.c
@@ -56,7 +56,7 @@ nfp_flower_compile_meta_tci(struct nfp_flower_meta_tci *frame,
56 FLOW_DISSECTOR_KEY_VLAN, 56 FLOW_DISSECTOR_KEY_VLAN,
57 target); 57 target);
58 /* Populate the tci field. */ 58 /* Populate the tci field. */
59 if (flow_vlan->vlan_id) { 59 if (flow_vlan->vlan_id || flow_vlan->vlan_priority) {
60 tmp_tci = FIELD_PREP(NFP_FLOWER_MASK_VLAN_PRIO, 60 tmp_tci = FIELD_PREP(NFP_FLOWER_MASK_VLAN_PRIO,
61 flow_vlan->vlan_priority) | 61 flow_vlan->vlan_priority) |
62 FIELD_PREP(NFP_FLOWER_MASK_VLAN_VID, 62 FIELD_PREP(NFP_FLOWER_MASK_VLAN_VID,
diff --git a/drivers/net/ethernet/netronome/nfp/flower/offload.c b/drivers/net/ethernet/netronome/nfp/flower/offload.c
index 2edab01c3beb..bd19624f10cf 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/offload.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/offload.c
@@ -192,6 +192,17 @@ nfp_flower_calculate_key_layers(struct nfp_app *app,
192 key_size += sizeof(struct nfp_flower_mac_mpls); 192 key_size += sizeof(struct nfp_flower_mac_mpls);
193 } 193 }
194 194
195 if (dissector_uses_key(flow->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
196 struct flow_dissector_key_vlan *flow_vlan;
197
198 flow_vlan = skb_flow_dissector_target(flow->dissector,
199 FLOW_DISSECTOR_KEY_VLAN,
200 flow->mask);
201 if (!(priv->flower_ext_feats & NFP_FL_FEATS_VLAN_PCP) &&
202 flow_vlan->vlan_priority)
203 return -EOPNOTSUPP;
204 }
205
195 if (dissector_uses_key(flow->dissector, 206 if (dissector_uses_key(flow->dissector,
196 FLOW_DISSECTOR_KEY_ENC_CONTROL)) { 207 FLOW_DISSECTOR_KEY_ENC_CONTROL)) {
197 struct flow_dissector_key_ipv4_addrs *mask_ipv4 = NULL; 208 struct flow_dissector_key_ipv4_addrs *mask_ipv4 = NULL;
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index a8b9fbab5f73..253bdaef1505 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -229,29 +229,16 @@ done:
229 spin_unlock_bh(&nn->reconfig_lock); 229 spin_unlock_bh(&nn->reconfig_lock);
230} 230}
231 231
232/** 232static void nfp_net_reconfig_sync_enter(struct nfp_net *nn)
233 * nfp_net_reconfig() - Reconfigure the firmware
234 * @nn: NFP Net device to reconfigure
235 * @update: The value for the update field in the BAR config
236 *
237 * Write the update word to the BAR and ping the reconfig queue. The
238 * poll until the firmware has acknowledged the update by zeroing the
239 * update word.
240 *
241 * Return: Negative errno on error, 0 on success
242 */
243int nfp_net_reconfig(struct nfp_net *nn, u32 update)
244{ 233{
245 bool cancelled_timer = false; 234 bool cancelled_timer = false;
246 u32 pre_posted_requests; 235 u32 pre_posted_requests;
247 int ret;
248 236
249 spin_lock_bh(&nn->reconfig_lock); 237 spin_lock_bh(&nn->reconfig_lock);
250 238
251 nn->reconfig_sync_present = true; 239 nn->reconfig_sync_present = true;
252 240
253 if (nn->reconfig_timer_active) { 241 if (nn->reconfig_timer_active) {
254 del_timer(&nn->reconfig_timer);
255 nn->reconfig_timer_active = false; 242 nn->reconfig_timer_active = false;
256 cancelled_timer = true; 243 cancelled_timer = true;
257 } 244 }
@@ -260,14 +247,43 @@ int nfp_net_reconfig(struct nfp_net *nn, u32 update)
260 247
261 spin_unlock_bh(&nn->reconfig_lock); 248 spin_unlock_bh(&nn->reconfig_lock);
262 249
263 if (cancelled_timer) 250 if (cancelled_timer) {
251 del_timer_sync(&nn->reconfig_timer);
264 nfp_net_reconfig_wait(nn, nn->reconfig_timer.expires); 252 nfp_net_reconfig_wait(nn, nn->reconfig_timer.expires);
253 }
265 254
266 /* Run the posted reconfigs which were issued before we started */ 255 /* Run the posted reconfigs which were issued before we started */
267 if (pre_posted_requests) { 256 if (pre_posted_requests) {
268 nfp_net_reconfig_start(nn, pre_posted_requests); 257 nfp_net_reconfig_start(nn, pre_posted_requests);
269 nfp_net_reconfig_wait(nn, jiffies + HZ * NFP_NET_POLL_TIMEOUT); 258 nfp_net_reconfig_wait(nn, jiffies + HZ * NFP_NET_POLL_TIMEOUT);
270 } 259 }
260}
261
262static void nfp_net_reconfig_wait_posted(struct nfp_net *nn)
263{
264 nfp_net_reconfig_sync_enter(nn);
265
266 spin_lock_bh(&nn->reconfig_lock);
267 nn->reconfig_sync_present = false;
268 spin_unlock_bh(&nn->reconfig_lock);
269}
270
271/**
272 * nfp_net_reconfig() - Reconfigure the firmware
273 * @nn: NFP Net device to reconfigure
274 * @update: The value for the update field in the BAR config
275 *
276 * Write the update word to the BAR and ping the reconfig queue. The
277 * poll until the firmware has acknowledged the update by zeroing the
278 * update word.
279 *
280 * Return: Negative errno on error, 0 on success
281 */
282int nfp_net_reconfig(struct nfp_net *nn, u32 update)
283{
284 int ret;
285
286 nfp_net_reconfig_sync_enter(nn);
271 287
272 nfp_net_reconfig_start(nn, update); 288 nfp_net_reconfig_start(nn, update);
273 ret = nfp_net_reconfig_wait(nn, jiffies + HZ * NFP_NET_POLL_TIMEOUT); 289 ret = nfp_net_reconfig_wait(nn, jiffies + HZ * NFP_NET_POLL_TIMEOUT);
@@ -3633,6 +3649,7 @@ struct nfp_net *nfp_net_alloc(struct pci_dev *pdev, bool needs_netdev,
3633 */ 3649 */
3634void nfp_net_free(struct nfp_net *nn) 3650void nfp_net_free(struct nfp_net *nn)
3635{ 3651{
3652 WARN_ON(timer_pending(&nn->reconfig_timer) || nn->reconfig_posted);
3636 if (nn->dp.netdev) 3653 if (nn->dp.netdev)
3637 free_netdev(nn->dp.netdev); 3654 free_netdev(nn->dp.netdev);
3638 else 3655 else
@@ -3920,4 +3937,5 @@ void nfp_net_clean(struct nfp_net *nn)
3920 return; 3937 return;
3921 3938
3922 unregister_netdev(nn->dp.netdev); 3939 unregister_netdev(nn->dp.netdev);
3940 nfp_net_reconfig_wait_posted(nn);
3923} 3941}
diff --git a/drivers/net/ethernet/qlogic/qed/qed_init_ops.c b/drivers/net/ethernet/qlogic/qed/qed_init_ops.c
index d9ab5add27a8..34193c2f1699 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_init_ops.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_init_ops.c
@@ -407,7 +407,7 @@ static void qed_init_cmd_rd(struct qed_hwfn *p_hwfn,
407 407
408 if (i == QED_INIT_MAX_POLL_COUNT) { 408 if (i == QED_INIT_MAX_POLL_COUNT) {
409 DP_ERR(p_hwfn, 409 DP_ERR(p_hwfn,
410 "Timeout when polling reg: 0x%08x [ Waiting-for: %08x Got: %08x (comparsion %08x)]\n", 410 "Timeout when polling reg: 0x%08x [ Waiting-for: %08x Got: %08x (comparison %08x)]\n",
411 addr, le32_to_cpu(cmd->expected_val), 411 addr, le32_to_cpu(cmd->expected_val),
412 val, le32_to_cpu(cmd->op_data)); 412 val, le32_to_cpu(cmd->op_data));
413 } 413 }
diff --git a/drivers/net/ethernet/qlogic/qed/qed_mcp.c b/drivers/net/ethernet/qlogic/qed/qed_mcp.c
index d89a0e22f6e4..5d37ec7e9b0b 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_mcp.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_mcp.c
@@ -48,7 +48,7 @@
48#include "qed_reg_addr.h" 48#include "qed_reg_addr.h"
49#include "qed_sriov.h" 49#include "qed_sriov.h"
50 50
51#define CHIP_MCP_RESP_ITER_US 10 51#define QED_MCP_RESP_ITER_US 10
52 52
53#define QED_DRV_MB_MAX_RETRIES (500 * 1000) /* Account for 5 sec */ 53#define QED_DRV_MB_MAX_RETRIES (500 * 1000) /* Account for 5 sec */
54#define QED_MCP_RESET_RETRIES (50 * 1000) /* Account for 500 msec */ 54#define QED_MCP_RESET_RETRIES (50 * 1000) /* Account for 500 msec */
@@ -183,18 +183,57 @@ int qed_mcp_free(struct qed_hwfn *p_hwfn)
183 return 0; 183 return 0;
184} 184}
185 185
186/* Maximum of 1 sec to wait for the SHMEM ready indication */
187#define QED_MCP_SHMEM_RDY_MAX_RETRIES 20
188#define QED_MCP_SHMEM_RDY_ITER_MS 50
189
186static int qed_load_mcp_offsets(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 190static int qed_load_mcp_offsets(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
187{ 191{
188 struct qed_mcp_info *p_info = p_hwfn->mcp_info; 192 struct qed_mcp_info *p_info = p_hwfn->mcp_info;
193 u8 cnt = QED_MCP_SHMEM_RDY_MAX_RETRIES;
194 u8 msec = QED_MCP_SHMEM_RDY_ITER_MS;
189 u32 drv_mb_offsize, mfw_mb_offsize; 195 u32 drv_mb_offsize, mfw_mb_offsize;
190 u32 mcp_pf_id = MCP_PF_ID(p_hwfn); 196 u32 mcp_pf_id = MCP_PF_ID(p_hwfn);
191 197
192 p_info->public_base = qed_rd(p_hwfn, p_ptt, MISC_REG_SHARED_MEM_ADDR); 198 p_info->public_base = qed_rd(p_hwfn, p_ptt, MISC_REG_SHARED_MEM_ADDR);
193 if (!p_info->public_base) 199 if (!p_info->public_base) {
194 return 0; 200 DP_NOTICE(p_hwfn,
201 "The address of the MCP scratch-pad is not configured\n");
202 return -EINVAL;
203 }
195 204
196 p_info->public_base |= GRCBASE_MCP; 205 p_info->public_base |= GRCBASE_MCP;
197 206
207 /* Get the MFW MB address and number of supported messages */
208 mfw_mb_offsize = qed_rd(p_hwfn, p_ptt,
209 SECTION_OFFSIZE_ADDR(p_info->public_base,
210 PUBLIC_MFW_MB));
211 p_info->mfw_mb_addr = SECTION_ADDR(mfw_mb_offsize, mcp_pf_id);
212 p_info->mfw_mb_length = (u16)qed_rd(p_hwfn, p_ptt,
213 p_info->mfw_mb_addr +
214 offsetof(struct public_mfw_mb,
215 sup_msgs));
216
217 /* The driver can notify that there was an MCP reset, and might read the
218 * SHMEM values before the MFW has completed initializing them.
219 * To avoid this, the "sup_msgs" field in the MFW mailbox is used as a
220 * data ready indication.
221 */
222 while (!p_info->mfw_mb_length && --cnt) {
223 msleep(msec);
224 p_info->mfw_mb_length =
225 (u16)qed_rd(p_hwfn, p_ptt,
226 p_info->mfw_mb_addr +
227 offsetof(struct public_mfw_mb, sup_msgs));
228 }
229
230 if (!cnt) {
231 DP_NOTICE(p_hwfn,
232 "Failed to get the SHMEM ready notification after %d msec\n",
233 QED_MCP_SHMEM_RDY_MAX_RETRIES * msec);
234 return -EBUSY;
235 }
236
198 /* Calculate the driver and MFW mailbox address */ 237 /* Calculate the driver and MFW mailbox address */
199 drv_mb_offsize = qed_rd(p_hwfn, p_ptt, 238 drv_mb_offsize = qed_rd(p_hwfn, p_ptt,
200 SECTION_OFFSIZE_ADDR(p_info->public_base, 239 SECTION_OFFSIZE_ADDR(p_info->public_base,
@@ -204,13 +243,6 @@ static int qed_load_mcp_offsets(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
204 "drv_mb_offsiz = 0x%x, drv_mb_addr = 0x%x mcp_pf_id = 0x%x\n", 243 "drv_mb_offsiz = 0x%x, drv_mb_addr = 0x%x mcp_pf_id = 0x%x\n",
205 drv_mb_offsize, p_info->drv_mb_addr, mcp_pf_id); 244 drv_mb_offsize, p_info->drv_mb_addr, mcp_pf_id);
206 245
207 /* Set the MFW MB address */
208 mfw_mb_offsize = qed_rd(p_hwfn, p_ptt,
209 SECTION_OFFSIZE_ADDR(p_info->public_base,
210 PUBLIC_MFW_MB));
211 p_info->mfw_mb_addr = SECTION_ADDR(mfw_mb_offsize, mcp_pf_id);
212 p_info->mfw_mb_length = (u16)qed_rd(p_hwfn, p_ptt, p_info->mfw_mb_addr);
213
214 /* Get the current driver mailbox sequence before sending 246 /* Get the current driver mailbox sequence before sending
215 * the first command 247 * the first command
216 */ 248 */
@@ -285,9 +317,15 @@ static void qed_mcp_reread_offsets(struct qed_hwfn *p_hwfn,
285 317
286int qed_mcp_reset(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 318int qed_mcp_reset(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
287{ 319{
288 u32 org_mcp_reset_seq, seq, delay = CHIP_MCP_RESP_ITER_US, cnt = 0; 320 u32 org_mcp_reset_seq, seq, delay = QED_MCP_RESP_ITER_US, cnt = 0;
289 int rc = 0; 321 int rc = 0;
290 322
323 if (p_hwfn->mcp_info->b_block_cmd) {
324 DP_NOTICE(p_hwfn,
325 "The MFW is not responsive. Avoid sending MCP_RESET mailbox command.\n");
326 return -EBUSY;
327 }
328
291 /* Ensure that only a single thread is accessing the mailbox */ 329 /* Ensure that only a single thread is accessing the mailbox */
292 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); 330 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
293 331
@@ -413,14 +451,41 @@ static void __qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
413 (p_mb_params->cmd | seq_num), p_mb_params->param); 451 (p_mb_params->cmd | seq_num), p_mb_params->param);
414} 452}
415 453
454static void qed_mcp_cmd_set_blocking(struct qed_hwfn *p_hwfn, bool block_cmd)
455{
456 p_hwfn->mcp_info->b_block_cmd = block_cmd;
457
458 DP_INFO(p_hwfn, "%s sending of mailbox commands to the MFW\n",
459 block_cmd ? "Block" : "Unblock");
460}
461
462static void qed_mcp_print_cpu_info(struct qed_hwfn *p_hwfn,
463 struct qed_ptt *p_ptt)
464{
465 u32 cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2;
466 u32 delay = QED_MCP_RESP_ITER_US;
467
468 cpu_mode = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
469 cpu_state = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
470 cpu_pc_0 = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
471 udelay(delay);
472 cpu_pc_1 = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
473 udelay(delay);
474 cpu_pc_2 = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
475
476 DP_NOTICE(p_hwfn,
477 "MCP CPU info: mode 0x%08x, state 0x%08x, pc {0x%08x, 0x%08x, 0x%08x}\n",
478 cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2);
479}
480
416static int 481static int
417_qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn, 482_qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
418 struct qed_ptt *p_ptt, 483 struct qed_ptt *p_ptt,
419 struct qed_mcp_mb_params *p_mb_params, 484 struct qed_mcp_mb_params *p_mb_params,
420 u32 max_retries, u32 delay) 485 u32 max_retries, u32 usecs)
421{ 486{
487 u32 cnt = 0, msecs = DIV_ROUND_UP(usecs, 1000);
422 struct qed_mcp_cmd_elem *p_cmd_elem; 488 struct qed_mcp_cmd_elem *p_cmd_elem;
423 u32 cnt = 0;
424 u16 seq_num; 489 u16 seq_num;
425 int rc = 0; 490 int rc = 0;
426 491
@@ -443,7 +508,11 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
443 goto err; 508 goto err;
444 509
445 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); 510 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
446 udelay(delay); 511
512 if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP))
513 msleep(msecs);
514 else
515 udelay(usecs);
447 } while (++cnt < max_retries); 516 } while (++cnt < max_retries);
448 517
449 if (cnt >= max_retries) { 518 if (cnt >= max_retries) {
@@ -472,7 +541,11 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
472 * The spinlock stays locked until the list element is removed. 541 * The spinlock stays locked until the list element is removed.
473 */ 542 */
474 543
475 udelay(delay); 544 if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP))
545 msleep(msecs);
546 else
547 udelay(usecs);
548
476 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); 549 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
477 550
478 if (p_cmd_elem->b_is_completed) 551 if (p_cmd_elem->b_is_completed)
@@ -491,11 +564,15 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
491 DP_NOTICE(p_hwfn, 564 DP_NOTICE(p_hwfn,
492 "The MFW failed to respond to command 0x%08x [param 0x%08x].\n", 565 "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
493 p_mb_params->cmd, p_mb_params->param); 566 p_mb_params->cmd, p_mb_params->param);
567 qed_mcp_print_cpu_info(p_hwfn, p_ptt);
494 568
495 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); 569 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
496 qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem); 570 qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
497 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); 571 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
498 572
573 if (!QED_MB_FLAGS_IS_SET(p_mb_params, AVOID_BLOCK))
574 qed_mcp_cmd_set_blocking(p_hwfn, true);
575
499 return -EAGAIN; 576 return -EAGAIN;
500 } 577 }
501 578
@@ -507,7 +584,7 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
507 "MFW mailbox: response 0x%08x param 0x%08x [after %d.%03d ms]\n", 584 "MFW mailbox: response 0x%08x param 0x%08x [after %d.%03d ms]\n",
508 p_mb_params->mcp_resp, 585 p_mb_params->mcp_resp,
509 p_mb_params->mcp_param, 586 p_mb_params->mcp_param,
510 (cnt * delay) / 1000, (cnt * delay) % 1000); 587 (cnt * usecs) / 1000, (cnt * usecs) % 1000);
511 588
512 /* Clear the sequence number from the MFW response */ 589 /* Clear the sequence number from the MFW response */
513 p_mb_params->mcp_resp &= FW_MSG_CODE_MASK; 590 p_mb_params->mcp_resp &= FW_MSG_CODE_MASK;
@@ -525,7 +602,7 @@ static int qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
525{ 602{
526 size_t union_data_size = sizeof(union drv_union_data); 603 size_t union_data_size = sizeof(union drv_union_data);
527 u32 max_retries = QED_DRV_MB_MAX_RETRIES; 604 u32 max_retries = QED_DRV_MB_MAX_RETRIES;
528 u32 delay = CHIP_MCP_RESP_ITER_US; 605 u32 usecs = QED_MCP_RESP_ITER_US;
529 606
530 /* MCP not initialized */ 607 /* MCP not initialized */
531 if (!qed_mcp_is_init(p_hwfn)) { 608 if (!qed_mcp_is_init(p_hwfn)) {
@@ -533,6 +610,13 @@ static int qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
533 return -EBUSY; 610 return -EBUSY;
534 } 611 }
535 612
613 if (p_hwfn->mcp_info->b_block_cmd) {
614 DP_NOTICE(p_hwfn,
615 "The MFW is not responsive. Avoid sending mailbox command 0x%08x [param 0x%08x].\n",
616 p_mb_params->cmd, p_mb_params->param);
617 return -EBUSY;
618 }
619
536 if (p_mb_params->data_src_size > union_data_size || 620 if (p_mb_params->data_src_size > union_data_size ||
537 p_mb_params->data_dst_size > union_data_size) { 621 p_mb_params->data_dst_size > union_data_size) {
538 DP_ERR(p_hwfn, 622 DP_ERR(p_hwfn,
@@ -542,8 +626,13 @@ static int qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
542 return -EINVAL; 626 return -EINVAL;
543 } 627 }
544 628
629 if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP)) {
630 max_retries = DIV_ROUND_UP(max_retries, 1000);
631 usecs *= 1000;
632 }
633
545 return _qed_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, max_retries, 634 return _qed_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, max_retries,
546 delay); 635 usecs);
547} 636}
548 637
549int qed_mcp_cmd(struct qed_hwfn *p_hwfn, 638int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
@@ -761,6 +850,7 @@ __qed_mcp_load_req(struct qed_hwfn *p_hwfn,
761 mb_params.data_src_size = sizeof(load_req); 850 mb_params.data_src_size = sizeof(load_req);
762 mb_params.p_data_dst = &load_rsp; 851 mb_params.p_data_dst = &load_rsp;
763 mb_params.data_dst_size = sizeof(load_rsp); 852 mb_params.data_dst_size = sizeof(load_rsp);
853 mb_params.flags = QED_MB_FLAG_CAN_SLEEP | QED_MB_FLAG_AVOID_BLOCK;
764 854
765 DP_VERBOSE(p_hwfn, QED_MSG_SP, 855 DP_VERBOSE(p_hwfn, QED_MSG_SP,
766 "Load Request: param 0x%08x [init_hw %d, drv_type %d, hsi_ver %d, pda 0x%04x]\n", 856 "Load Request: param 0x%08x [init_hw %d, drv_type %d, hsi_ver %d, pda 0x%04x]\n",
@@ -982,7 +1072,8 @@ int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
982 1072
983int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 1073int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
984{ 1074{
985 u32 wol_param, mcp_resp, mcp_param; 1075 struct qed_mcp_mb_params mb_params;
1076 u32 wol_param;
986 1077
987 switch (p_hwfn->cdev->wol_config) { 1078 switch (p_hwfn->cdev->wol_config) {
988 case QED_OV_WOL_DISABLED: 1079 case QED_OV_WOL_DISABLED:
@@ -1000,8 +1091,12 @@ int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1000 wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP; 1091 wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP;
1001 } 1092 }
1002 1093
1003 return qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_UNLOAD_REQ, wol_param, 1094 memset(&mb_params, 0, sizeof(mb_params));
1004 &mcp_resp, &mcp_param); 1095 mb_params.cmd = DRV_MSG_CODE_UNLOAD_REQ;
1096 mb_params.param = wol_param;
1097 mb_params.flags = QED_MB_FLAG_CAN_SLEEP | QED_MB_FLAG_AVOID_BLOCK;
1098
1099 return qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1005} 1100}
1006 1101
1007int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 1102int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
@@ -2077,31 +2172,65 @@ qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
2077 return rc; 2172 return rc;
2078} 2173}
2079 2174
2175/* A maximal 100 msec waiting time for the MCP to halt */
2176#define QED_MCP_HALT_SLEEP_MS 10
2177#define QED_MCP_HALT_MAX_RETRIES 10
2178
2080int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 2179int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2081{ 2180{
2082 u32 resp = 0, param = 0; 2181 u32 resp = 0, param = 0, cpu_state, cnt = 0;
2083 int rc; 2182 int rc;
2084 2183
2085 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MCP_HALT, 0, &resp, 2184 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MCP_HALT, 0, &resp,
2086 &param); 2185 &param);
2087 if (rc) 2186 if (rc) {
2088 DP_ERR(p_hwfn, "MCP response failure, aborting\n"); 2187 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2188 return rc;
2189 }
2089 2190
2090 return rc; 2191 do {
2192 msleep(QED_MCP_HALT_SLEEP_MS);
2193 cpu_state = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2194 if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED)
2195 break;
2196 } while (++cnt < QED_MCP_HALT_MAX_RETRIES);
2197
2198 if (cnt == QED_MCP_HALT_MAX_RETRIES) {
2199 DP_NOTICE(p_hwfn,
2200 "Failed to halt the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2201 qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE), cpu_state);
2202 return -EBUSY;
2203 }
2204
2205 qed_mcp_cmd_set_blocking(p_hwfn, true);
2206
2207 return 0;
2091} 2208}
2092 2209
2210#define QED_MCP_RESUME_SLEEP_MS 10
2211
2093int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 2212int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2094{ 2213{
2095 u32 value, cpu_mode; 2214 u32 cpu_mode, cpu_state;
2096 2215
2097 qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_STATE, 0xffffffff); 2216 qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_STATE, 0xffffffff);
2098 2217
2099 value = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
2100 value &= ~MCP_REG_CPU_MODE_SOFT_HALT;
2101 qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_MODE, value);
2102 cpu_mode = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE); 2218 cpu_mode = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
2219 cpu_mode &= ~MCP_REG_CPU_MODE_SOFT_HALT;
2220 qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_MODE, cpu_mode);
2221 msleep(QED_MCP_RESUME_SLEEP_MS);
2222 cpu_state = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2103 2223
2104 return (cpu_mode & MCP_REG_CPU_MODE_SOFT_HALT) ? -EAGAIN : 0; 2224 if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED) {
2225 DP_NOTICE(p_hwfn,
2226 "Failed to resume the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2227 cpu_mode, cpu_state);
2228 return -EBUSY;
2229 }
2230
2231 qed_mcp_cmd_set_blocking(p_hwfn, false);
2232
2233 return 0;
2105} 2234}
2106 2235
2107int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn, 2236int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
diff --git a/drivers/net/ethernet/qlogic/qed/qed_mcp.h b/drivers/net/ethernet/qlogic/qed/qed_mcp.h
index 047976d5c6e9..85e6b3989e7a 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_mcp.h
+++ b/drivers/net/ethernet/qlogic/qed/qed_mcp.h
@@ -635,11 +635,14 @@ struct qed_mcp_info {
635 */ 635 */
636 spinlock_t cmd_lock; 636 spinlock_t cmd_lock;
637 637
638 /* Flag to indicate whether sending a MFW mailbox command is blocked */
639 bool b_block_cmd;
640
638 /* Spinlock used for syncing SW link-changes and link-changes 641 /* Spinlock used for syncing SW link-changes and link-changes
639 * originating from attention context. 642 * originating from attention context.
640 */ 643 */
641 spinlock_t link_lock; 644 spinlock_t link_lock;
642 bool block_mb_sending; 645
643 u32 public_base; 646 u32 public_base;
644 u32 drv_mb_addr; 647 u32 drv_mb_addr;
645 u32 mfw_mb_addr; 648 u32 mfw_mb_addr;
@@ -660,14 +663,20 @@ struct qed_mcp_info {
660}; 663};
661 664
662struct qed_mcp_mb_params { 665struct qed_mcp_mb_params {
663 u32 cmd; 666 u32 cmd;
664 u32 param; 667 u32 param;
665 void *p_data_src; 668 void *p_data_src;
666 u8 data_src_size; 669 void *p_data_dst;
667 void *p_data_dst; 670 u8 data_src_size;
668 u8 data_dst_size; 671 u8 data_dst_size;
669 u32 mcp_resp; 672 u32 mcp_resp;
670 u32 mcp_param; 673 u32 mcp_param;
674 u32 flags;
675#define QED_MB_FLAG_CAN_SLEEP (0x1 << 0)
676#define QED_MB_FLAG_AVOID_BLOCK (0x1 << 1)
677#define QED_MB_FLAGS_IS_SET(params, flag) \
678 ({ typeof(params) __params = (params); \
679 (__params && (__params->flags & QED_MB_FLAG_ ## flag)); })
671}; 680};
672 681
673struct qed_drv_tlv_hdr { 682struct qed_drv_tlv_hdr {
diff --git a/drivers/net/ethernet/qlogic/qed/qed_reg_addr.h b/drivers/net/ethernet/qlogic/qed/qed_reg_addr.h
index d8ad2dcad8d5..f736f70956fd 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_reg_addr.h
+++ b/drivers/net/ethernet/qlogic/qed/qed_reg_addr.h
@@ -562,8 +562,10 @@
562 0 562 0
563#define MCP_REG_CPU_STATE \ 563#define MCP_REG_CPU_STATE \
564 0xe05004UL 564 0xe05004UL
565#define MCP_REG_CPU_STATE_SOFT_HALTED (0x1UL << 10)
565#define MCP_REG_CPU_EVENT_MASK \ 566#define MCP_REG_CPU_EVENT_MASK \
566 0xe05008UL 567 0xe05008UL
568#define MCP_REG_CPU_PROGRAM_COUNTER 0xe0501cUL
567#define PGLUE_B_REG_PF_BAR0_SIZE \ 569#define PGLUE_B_REG_PF_BAR0_SIZE \
568 0x2aae60UL 570 0x2aae60UL
569#define PGLUE_B_REG_PF_BAR1_SIZE \ 571#define PGLUE_B_REG_PF_BAR1_SIZE \
diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c b/drivers/net/ethernet/qlogic/qede/qede_filter.c
index 9673d19308e6..b16ce7d93caf 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_filter.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c
@@ -2006,18 +2006,16 @@ unlock:
2006static int qede_parse_actions(struct qede_dev *edev, 2006static int qede_parse_actions(struct qede_dev *edev,
2007 struct tcf_exts *exts) 2007 struct tcf_exts *exts)
2008{ 2008{
2009 int rc = -EINVAL, num_act = 0; 2009 int rc = -EINVAL, num_act = 0, i;
2010 const struct tc_action *a; 2010 const struct tc_action *a;
2011 bool is_drop = false; 2011 bool is_drop = false;
2012 LIST_HEAD(actions);
2013 2012
2014 if (!tcf_exts_has_actions(exts)) { 2013 if (!tcf_exts_has_actions(exts)) {
2015 DP_NOTICE(edev, "No tc actions received\n"); 2014 DP_NOTICE(edev, "No tc actions received\n");
2016 return rc; 2015 return rc;
2017 } 2016 }
2018 2017
2019 tcf_exts_to_list(exts, &actions); 2018 tcf_exts_for_each_action(i, a, exts) {
2020 list_for_each_entry(a, &actions, list) {
2021 num_act++; 2019 num_act++;
2022 2020
2023 if (is_tcf_gact_shot(a)) 2021 if (is_tcf_gact_shot(a))
diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
index 353f1c129af1..059ba9429e51 100644
--- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c
+++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
@@ -2384,26 +2384,20 @@ static int qlge_update_hw_vlan_features(struct net_device *ndev,
2384 return status; 2384 return status;
2385} 2385}
2386 2386
2387static netdev_features_t qlge_fix_features(struct net_device *ndev,
2388 netdev_features_t features)
2389{
2390 int err;
2391
2392 /* Update the behavior of vlan accel in the adapter */
2393 err = qlge_update_hw_vlan_features(ndev, features);
2394 if (err)
2395 return err;
2396
2397 return features;
2398}
2399
2400static int qlge_set_features(struct net_device *ndev, 2387static int qlge_set_features(struct net_device *ndev,
2401 netdev_features_t features) 2388 netdev_features_t features)
2402{ 2389{
2403 netdev_features_t changed = ndev->features ^ features; 2390 netdev_features_t changed = ndev->features ^ features;
2391 int err;
2392
2393 if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
2394 /* Update the behavior of vlan accel in the adapter */
2395 err = qlge_update_hw_vlan_features(ndev, features);
2396 if (err)
2397 return err;
2404 2398
2405 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
2406 qlge_vlan_mode(ndev, features); 2399 qlge_vlan_mode(ndev, features);
2400 }
2407 2401
2408 return 0; 2402 return 0;
2409} 2403}
@@ -4719,7 +4713,6 @@ static const struct net_device_ops qlge_netdev_ops = {
4719 .ndo_set_mac_address = qlge_set_mac_address, 4713 .ndo_set_mac_address = qlge_set_mac_address,
4720 .ndo_validate_addr = eth_validate_addr, 4714 .ndo_validate_addr = eth_validate_addr,
4721 .ndo_tx_timeout = qlge_tx_timeout, 4715 .ndo_tx_timeout = qlge_tx_timeout,
4722 .ndo_fix_features = qlge_fix_features,
4723 .ndo_set_features = qlge_set_features, 4716 .ndo_set_features = qlge_set_features,
4724 .ndo_vlan_rx_add_vid = qlge_vlan_rx_add_vid, 4717 .ndo_vlan_rx_add_vid = qlge_vlan_rx_add_vid,
4725 .ndo_vlan_rx_kill_vid = qlge_vlan_rx_kill_vid, 4718 .ndo_vlan_rx_kill_vid = qlge_vlan_rx_kill_vid,
diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c b/drivers/net/ethernet/qualcomm/qca_7k.c
index ffe7a16bdfc8..6c8543fb90c0 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -45,34 +45,33 @@ qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result)
45{ 45{
46 __be16 rx_data; 46 __be16 rx_data;
47 __be16 tx_data; 47 __be16 tx_data;
48 struct spi_transfer *transfer; 48 struct spi_transfer transfer[2];
49 struct spi_message *msg; 49 struct spi_message msg;
50 int ret; 50 int ret;
51 51
52 memset(transfer, 0, sizeof(transfer));
53
54 spi_message_init(&msg);
55
52 tx_data = cpu_to_be16(QCA7K_SPI_READ | QCA7K_SPI_INTERNAL | reg); 56 tx_data = cpu_to_be16(QCA7K_SPI_READ | QCA7K_SPI_INTERNAL | reg);
57 *result = 0;
58
59 transfer[0].tx_buf = &tx_data;
60 transfer[0].len = QCASPI_CMD_LEN;
61 transfer[1].rx_buf = &rx_data;
62 transfer[1].len = QCASPI_CMD_LEN;
63
64 spi_message_add_tail(&transfer[0], &msg);
53 65
54 if (qca->legacy_mode) { 66 if (qca->legacy_mode) {
55 msg = &qca->spi_msg1; 67 spi_sync(qca->spi_dev, &msg);
56 transfer = &qca->spi_xfer1; 68 spi_message_init(&msg);
57 transfer->tx_buf = &tx_data;
58 transfer->rx_buf = NULL;
59 transfer->len = QCASPI_CMD_LEN;
60 spi_sync(qca->spi_dev, msg);
61 } else {
62 msg = &qca->spi_msg2;
63 transfer = &qca->spi_xfer2[0];
64 transfer->tx_buf = &tx_data;
65 transfer->rx_buf = NULL;
66 transfer->len = QCASPI_CMD_LEN;
67 transfer = &qca->spi_xfer2[1];
68 } 69 }
69 transfer->tx_buf = NULL; 70 spi_message_add_tail(&transfer[1], &msg);
70 transfer->rx_buf = &rx_data; 71 ret = spi_sync(qca->spi_dev, &msg);
71 transfer->len = QCASPI_CMD_LEN;
72 ret = spi_sync(qca->spi_dev, msg);
73 72
74 if (!ret) 73 if (!ret)
75 ret = msg->status; 74 ret = msg.status;
76 75
77 if (ret) 76 if (ret)
78 qcaspi_spi_error(qca); 77 qcaspi_spi_error(qca);
@@ -86,35 +85,32 @@ int
86qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value) 85qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value)
87{ 86{
88 __be16 tx_data[2]; 87 __be16 tx_data[2];
89 struct spi_transfer *transfer; 88 struct spi_transfer transfer[2];
90 struct spi_message *msg; 89 struct spi_message msg;
91 int ret; 90 int ret;
92 91
92 memset(&transfer, 0, sizeof(transfer));
93
94 spi_message_init(&msg);
95
93 tx_data[0] = cpu_to_be16(QCA7K_SPI_WRITE | QCA7K_SPI_INTERNAL | reg); 96 tx_data[0] = cpu_to_be16(QCA7K_SPI_WRITE | QCA7K_SPI_INTERNAL | reg);
94 tx_data[1] = cpu_to_be16(value); 97 tx_data[1] = cpu_to_be16(value);
95 98
99 transfer[0].tx_buf = &tx_data[0];
100 transfer[0].len = QCASPI_CMD_LEN;
101 transfer[1].tx_buf = &tx_data[1];
102 transfer[1].len = QCASPI_CMD_LEN;
103
104 spi_message_add_tail(&transfer[0], &msg);
96 if (qca->legacy_mode) { 105 if (qca->legacy_mode) {
97 msg = &qca->spi_msg1; 106 spi_sync(qca->spi_dev, &msg);
98 transfer = &qca->spi_xfer1; 107 spi_message_init(&msg);
99 transfer->tx_buf = &tx_data[0];
100 transfer->rx_buf = NULL;
101 transfer->len = QCASPI_CMD_LEN;
102 spi_sync(qca->spi_dev, msg);
103 } else {
104 msg = &qca->spi_msg2;
105 transfer = &qca->spi_xfer2[0];
106 transfer->tx_buf = &tx_data[0];
107 transfer->rx_buf = NULL;
108 transfer->len = QCASPI_CMD_LEN;
109 transfer = &qca->spi_xfer2[1];
110 } 108 }
111 transfer->tx_buf = &tx_data[1]; 109 spi_message_add_tail(&transfer[1], &msg);
112 transfer->rx_buf = NULL; 110 ret = spi_sync(qca->spi_dev, &msg);
113 transfer->len = QCASPI_CMD_LEN;
114 ret = spi_sync(qca->spi_dev, msg);
115 111
116 if (!ret) 112 if (!ret)
117 ret = msg->status; 113 ret = msg.status;
118 114
119 if (ret) 115 if (ret)
120 qcaspi_spi_error(qca); 116 qcaspi_spi_error(qca);
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c b/drivers/net/ethernet/qualcomm/qca_spi.c
index 206f0266463e..66b775d462fd 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -99,22 +99,24 @@ static u32
99qcaspi_write_burst(struct qcaspi *qca, u8 *src, u32 len) 99qcaspi_write_burst(struct qcaspi *qca, u8 *src, u32 len)
100{ 100{
101 __be16 cmd; 101 __be16 cmd;
102 struct spi_message *msg = &qca->spi_msg2; 102 struct spi_message msg;
103 struct spi_transfer *transfer = &qca->spi_xfer2[0]; 103 struct spi_transfer transfer[2];
104 int ret; 104 int ret;
105 105
106 memset(&transfer, 0, sizeof(transfer));
107 spi_message_init(&msg);
108
106 cmd = cpu_to_be16(QCA7K_SPI_WRITE | QCA7K_SPI_EXTERNAL); 109 cmd = cpu_to_be16(QCA7K_SPI_WRITE | QCA7K_SPI_EXTERNAL);
107 transfer->tx_buf = &cmd; 110 transfer[0].tx_buf = &cmd;
108 transfer->rx_buf = NULL; 111 transfer[0].len = QCASPI_CMD_LEN;
109 transfer->len = QCASPI_CMD_LEN; 112 transfer[1].tx_buf = src;
110 transfer = &qca->spi_xfer2[1]; 113 transfer[1].len = len;
111 transfer->tx_buf = src;
112 transfer->rx_buf = NULL;
113 transfer->len = len;
114 114
115 ret = spi_sync(qca->spi_dev, msg); 115 spi_message_add_tail(&transfer[0], &msg);
116 spi_message_add_tail(&transfer[1], &msg);
117 ret = spi_sync(qca->spi_dev, &msg);
116 118
117 if (ret || (msg->actual_length != QCASPI_CMD_LEN + len)) { 119 if (ret || (msg.actual_length != QCASPI_CMD_LEN + len)) {
118 qcaspi_spi_error(qca); 120 qcaspi_spi_error(qca);
119 return 0; 121 return 0;
120 } 122 }
@@ -125,17 +127,20 @@ qcaspi_write_burst(struct qcaspi *qca, u8 *src, u32 len)
125static u32 127static u32
126qcaspi_write_legacy(struct qcaspi *qca, u8 *src, u32 len) 128qcaspi_write_legacy(struct qcaspi *qca, u8 *src, u32 len)
127{ 129{
128 struct spi_message *msg = &qca->spi_msg1; 130 struct spi_message msg;
129 struct spi_transfer *transfer = &qca->spi_xfer1; 131 struct spi_transfer transfer;
130 int ret; 132 int ret;
131 133
132 transfer->tx_buf = src; 134 memset(&transfer, 0, sizeof(transfer));
133 transfer->rx_buf = NULL; 135 spi_message_init(&msg);
134 transfer->len = len; 136
137 transfer.tx_buf = src;
138 transfer.len = len;
135 139
136 ret = spi_sync(qca->spi_dev, msg); 140 spi_message_add_tail(&transfer, &msg);
141 ret = spi_sync(qca->spi_dev, &msg);
137 142
138 if (ret || (msg->actual_length != len)) { 143 if (ret || (msg.actual_length != len)) {
139 qcaspi_spi_error(qca); 144 qcaspi_spi_error(qca);
140 return 0; 145 return 0;
141 } 146 }
@@ -146,23 +151,25 @@ qcaspi_write_legacy(struct qcaspi *qca, u8 *src, u32 len)
146static u32 151static u32
147qcaspi_read_burst(struct qcaspi *qca, u8 *dst, u32 len) 152qcaspi_read_burst(struct qcaspi *qca, u8 *dst, u32 len)
148{ 153{
149 struct spi_message *msg = &qca->spi_msg2; 154 struct spi_message msg;
150 __be16 cmd; 155 __be16 cmd;
151 struct spi_transfer *transfer = &qca->spi_xfer2[0]; 156 struct spi_transfer transfer[2];
152 int ret; 157 int ret;
153 158
159 memset(&transfer, 0, sizeof(transfer));
160 spi_message_init(&msg);
161
154 cmd = cpu_to_be16(QCA7K_SPI_READ | QCA7K_SPI_EXTERNAL); 162 cmd = cpu_to_be16(QCA7K_SPI_READ | QCA7K_SPI_EXTERNAL);
155 transfer->tx_buf = &cmd; 163 transfer[0].tx_buf = &cmd;
156 transfer->rx_buf = NULL; 164 transfer[0].len = QCASPI_CMD_LEN;
157 transfer->len = QCASPI_CMD_LEN; 165 transfer[1].rx_buf = dst;
158 transfer = &qca->spi_xfer2[1]; 166 transfer[1].len = len;
159 transfer->tx_buf = NULL;
160 transfer->rx_buf = dst;
161 transfer->len = len;
162 167
163 ret = spi_sync(qca->spi_dev, msg); 168 spi_message_add_tail(&transfer[0], &msg);
169 spi_message_add_tail(&transfer[1], &msg);
170 ret = spi_sync(qca->spi_dev, &msg);
164 171
165 if (ret || (msg->actual_length != QCASPI_CMD_LEN + len)) { 172 if (ret || (msg.actual_length != QCASPI_CMD_LEN + len)) {
166 qcaspi_spi_error(qca); 173 qcaspi_spi_error(qca);
167 return 0; 174 return 0;
168 } 175 }
@@ -173,17 +180,20 @@ qcaspi_read_burst(struct qcaspi *qca, u8 *dst, u32 len)
173static u32 180static u32
174qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len) 181qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len)
175{ 182{
176 struct spi_message *msg = &qca->spi_msg1; 183 struct spi_message msg;
177 struct spi_transfer *transfer = &qca->spi_xfer1; 184 struct spi_transfer transfer;
178 int ret; 185 int ret;
179 186
180 transfer->tx_buf = NULL; 187 memset(&transfer, 0, sizeof(transfer));
181 transfer->rx_buf = dst; 188 spi_message_init(&msg);
182 transfer->len = len;
183 189
184 ret = spi_sync(qca->spi_dev, msg); 190 transfer.rx_buf = dst;
191 transfer.len = len;
185 192
186 if (ret || (msg->actual_length != len)) { 193 spi_message_add_tail(&transfer, &msg);
194 ret = spi_sync(qca->spi_dev, &msg);
195
196 if (ret || (msg.actual_length != len)) {
187 qcaspi_spi_error(qca); 197 qcaspi_spi_error(qca);
188 return 0; 198 return 0;
189 } 199 }
@@ -195,19 +205,23 @@ static int
195qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd) 205qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
196{ 206{
197 __be16 tx_data; 207 __be16 tx_data;
198 struct spi_message *msg = &qca->spi_msg1; 208 struct spi_message msg;
199 struct spi_transfer *transfer = &qca->spi_xfer1; 209 struct spi_transfer transfer;
200 int ret; 210 int ret;
201 211
212 memset(&transfer, 0, sizeof(transfer));
213
214 spi_message_init(&msg);
215
202 tx_data = cpu_to_be16(cmd); 216 tx_data = cpu_to_be16(cmd);
203 transfer->len = sizeof(tx_data); 217 transfer.len = sizeof(cmd);
204 transfer->tx_buf = &tx_data; 218 transfer.tx_buf = &tx_data;
205 transfer->rx_buf = NULL; 219 spi_message_add_tail(&transfer, &msg);
206 220
207 ret = spi_sync(qca->spi_dev, msg); 221 ret = spi_sync(qca->spi_dev, &msg);
208 222
209 if (!ret) 223 if (!ret)
210 ret = msg->status; 224 ret = msg.status;
211 225
212 if (ret) 226 if (ret)
213 qcaspi_spi_error(qca); 227 qcaspi_spi_error(qca);
@@ -835,16 +849,6 @@ qcaspi_netdev_setup(struct net_device *dev)
835 qca = netdev_priv(dev); 849 qca = netdev_priv(dev);
836 memset(qca, 0, sizeof(struct qcaspi)); 850 memset(qca, 0, sizeof(struct qcaspi));
837 851
838 memset(&qca->spi_xfer1, 0, sizeof(struct spi_transfer));
839 memset(&qca->spi_xfer2, 0, sizeof(struct spi_transfer) * 2);
840
841 spi_message_init(&qca->spi_msg1);
842 spi_message_add_tail(&qca->spi_xfer1, &qca->spi_msg1);
843
844 spi_message_init(&qca->spi_msg2);
845 spi_message_add_tail(&qca->spi_xfer2[0], &qca->spi_msg2);
846 spi_message_add_tail(&qca->spi_xfer2[1], &qca->spi_msg2);
847
848 memset(&qca->txr, 0, sizeof(qca->txr)); 852 memset(&qca->txr, 0, sizeof(qca->txr));
849 qca->txr.count = TX_RING_MAX_LEN; 853 qca->txr.count = TX_RING_MAX_LEN;
850} 854}
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h b/drivers/net/ethernet/qualcomm/qca_spi.h
index fc4beb1b32d1..fc0e98726b36 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -83,11 +83,6 @@ struct qcaspi {
83 struct tx_ring txr; 83 struct tx_ring txr;
84 struct qcaspi_stats stats; 84 struct qcaspi_stats stats;
85 85
86 struct spi_message spi_msg1;
87 struct spi_message spi_msg2;
88 struct spi_transfer spi_xfer1;
89 struct spi_transfer spi_xfer2[2];
90
91 u8 *rx_buffer; 86 u8 *rx_buffer;
92 u32 buffer_size; 87 u32 buffer_size;
93 u8 sync; 88 u8 sync;
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 0efa977c422d..1d8631303b53 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -218,6 +218,7 @@ static const struct pci_device_id rtl8169_pci_tbl[] = {
218 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 }, 218 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 },
219 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, 219 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 },
220 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, 220 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 },
221 { PCI_DEVICE(PCI_VENDOR_ID_NCUBE, 0x8168), 0, 0, RTL_CFG_1 },
221 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, 222 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 },
222 { PCI_VENDOR_ID_DLINK, 0x4300, 223 { PCI_VENDOR_ID_DLINK, 0x4300,
223 PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, 224 PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 },
@@ -630,7 +631,7 @@ struct rtl8169_tc_offsets {
630}; 631};
631 632
632enum rtl_flag { 633enum rtl_flag {
633 RTL_FLAG_TASK_ENABLED, 634 RTL_FLAG_TASK_ENABLED = 0,
634 RTL_FLAG_TASK_SLOW_PENDING, 635 RTL_FLAG_TASK_SLOW_PENDING,
635 RTL_FLAG_TASK_RESET_PENDING, 636 RTL_FLAG_TASK_RESET_PENDING,
636 RTL_FLAG_MAX 637 RTL_FLAG_MAX
@@ -4522,7 +4523,7 @@ static void rtl8169_hw_reset(struct rtl8169_private *tp)
4522 rtl_hw_reset(tp); 4523 rtl_hw_reset(tp);
4523} 4524}
4524 4525
4525static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) 4526static void rtl_set_tx_config_registers(struct rtl8169_private *tp)
4526{ 4527{
4527 /* Set DMA burst size and Interframe Gap Time */ 4528 /* Set DMA burst size and Interframe Gap Time */
4528 RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) | 4529 RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) |
@@ -4633,12 +4634,14 @@ static void rtl_hw_start(struct rtl8169_private *tp)
4633 4634
4634 rtl_set_rx_max_size(tp); 4635 rtl_set_rx_max_size(tp);
4635 rtl_set_rx_tx_desc_registers(tp); 4636 rtl_set_rx_tx_desc_registers(tp);
4636 rtl_set_rx_tx_config_registers(tp);
4637 RTL_W8(tp, Cfg9346, Cfg9346_Lock); 4637 RTL_W8(tp, Cfg9346, Cfg9346_Lock);
4638 4638
4639 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ 4639 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
4640 RTL_R8(tp, IntrMask); 4640 RTL_R8(tp, IntrMask);
4641 RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); 4641 RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
4642 rtl_init_rxcfg(tp);
4643 rtl_set_tx_config_registers(tp);
4644
4642 rtl_set_rx_mode(tp->dev); 4645 rtl_set_rx_mode(tp->dev);
4643 /* no early-rx interrupts */ 4646 /* no early-rx interrupts */
4644 RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); 4647 RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
@@ -6652,7 +6655,8 @@ static int rtl8169_close(struct net_device *dev)
6652 rtl8169_update_counters(tp); 6655 rtl8169_update_counters(tp);
6653 6656
6654 rtl_lock_work(tp); 6657 rtl_lock_work(tp);
6655 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); 6658 /* Clear all task flags */
6659 bitmap_zero(tp->wk.flags, RTL_FLAG_MAX);
6656 6660
6657 rtl8169_down(dev); 6661 rtl8169_down(dev);
6658 rtl_unlock_work(tp); 6662 rtl_unlock_work(tp);
@@ -6835,7 +6839,9 @@ static void rtl8169_net_suspend(struct net_device *dev)
6835 6839
6836 rtl_lock_work(tp); 6840 rtl_lock_work(tp);
6837 napi_disable(&tp->napi); 6841 napi_disable(&tp->napi);
6838 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); 6842 /* Clear all task flags */
6843 bitmap_zero(tp->wk.flags, RTL_FLAG_MAX);
6844
6839 rtl_unlock_work(tp); 6845 rtl_unlock_work(tp);
6840 6846
6841 rtl_pll_power_down(tp); 6847 rtl_pll_power_down(tp);
diff --git a/drivers/net/ethernet/renesas/Kconfig b/drivers/net/ethernet/renesas/Kconfig
index f3f7477043ce..bb0ebdfd4459 100644
--- a/drivers/net/ethernet/renesas/Kconfig
+++ b/drivers/net/ethernet/renesas/Kconfig
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# 2#
2# Renesas device configuration 3# Renesas device configuration
3# 4#
diff --git a/drivers/net/ethernet/renesas/Makefile b/drivers/net/ethernet/renesas/Makefile
index a05102a7df02..f21ab8c02af0 100644
--- a/drivers/net/ethernet/renesas/Makefile
+++ b/drivers/net/ethernet/renesas/Makefile
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1# 2#
2# Makefile for the Renesas device drivers. 3# Makefile for the Renesas device drivers.
3# 4#
diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index b81f4faf7b10..1470fc12282b 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Renesas Ethernet AVB device driver 2/* Renesas Ethernet AVB device driver
2 * 3 *
3 * Copyright (C) 2014-2015 Renesas Electronics Corporation 4 * Copyright (C) 2014-2015 Renesas Electronics Corporation
@@ -5,10 +6,6 @@
5 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com> 6 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com>
6 * 7 *
7 * Based on the SuperH Ethernet driver 8 * Based on the SuperH Ethernet driver
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
12 */ 9 */
13 10
14#ifndef __RAVB_H__ 11#ifndef __RAVB_H__
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index c06f2df895c2..aff5516b781e 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Renesas Ethernet AVB device driver 2/* Renesas Ethernet AVB device driver
2 * 3 *
3 * Copyright (C) 2014-2015 Renesas Electronics Corporation 4 * Copyright (C) 2014-2015 Renesas Electronics Corporation
@@ -5,10 +6,6 @@
5 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com> 6 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com>
6 * 7 *
7 * Based on the SuperH Ethernet driver 8 * Based on the SuperH Ethernet driver
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
12 */ 9 */
13 10
14#include <linux/cache.h> 11#include <linux/cache.h>
diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index eede70ec37f8..0721b5c35d91 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -1,13 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* PTP 1588 clock using the Renesas Ethernet AVB 2/* PTP 1588 clock using the Renesas Ethernet AVB
2 * 3 *
3 * Copyright (C) 2013-2015 Renesas Electronics Corporation 4 * Copyright (C) 2013-2015 Renesas Electronics Corporation
4 * Copyright (C) 2015 Renesas Solutions Corp. 5 * Copyright (C) 2015 Renesas Solutions Corp.
5 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com> 6 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */ 7 */
12 8
13#include "ravb.h" 9#include "ravb.h"
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 5573199c4536..f27a0dc8c563 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* SuperH Ethernet device driver 2/* SuperH Ethernet device driver
2 * 3 *
3 * Copyright (C) 2014 Renesas Electronics Corporation 4 * Copyright (C) 2014 Renesas Electronics Corporation
@@ -5,18 +6,6 @@
5 * Copyright (C) 2008-2014 Renesas Solutions Corp. 6 * Copyright (C) 2008-2014 Renesas Solutions Corp.
6 * Copyright (C) 2013-2017 Cogent Embedded, Inc. 7 * Copyright (C) 2013-2017 Cogent Embedded, Inc.
7 * Copyright (C) 2014 Codethink Limited 8 * Copyright (C) 2014 Codethink Limited
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 */ 9 */
21 10
22#include <linux/module.h> 11#include <linux/module.h>
@@ -809,6 +798,41 @@ static struct sh_eth_cpu_data r8a77980_data = {
809 .magic = 1, 798 .magic = 1,
810 .cexcr = 1, 799 .cexcr = 1,
811}; 800};
801
802/* R7S9210 */
803static struct sh_eth_cpu_data r7s9210_data = {
804 .soft_reset = sh_eth_soft_reset,
805
806 .set_duplex = sh_eth_set_duplex,
807 .set_rate = sh_eth_set_rate_rcar,
808
809 .register_type = SH_ETH_REG_FAST_SH4,
810
811 .edtrr_trns = EDTRR_TRNS_ETHER,
812 .ecsr_value = ECSR_ICD,
813 .ecsipr_value = ECSIPR_ICDIP,
814 .eesipr_value = EESIPR_TWBIP | EESIPR_TABTIP | EESIPR_RABTIP |
815 EESIPR_RFCOFIP | EESIPR_ECIIP | EESIPR_FTCIP |
816 EESIPR_TDEIP | EESIPR_TFUFIP | EESIPR_FRIP |
817 EESIPR_RDEIP | EESIPR_RFOFIP | EESIPR_CNDIP |
818 EESIPR_DLCIP | EESIPR_CDIP | EESIPR_TROIP |
819 EESIPR_RMAFIP | EESIPR_RRFIP | EESIPR_RTLFIP |
820 EESIPR_RTSFIP | EESIPR_PREIP | EESIPR_CERFIP,
821
822 .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_TRO,
823 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
824 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE,
825
826 .fdr_value = 0x0000070f,
827
828 .apr = 1,
829 .mpr = 1,
830 .tpauser = 1,
831 .hw_swap = 1,
832 .rpadir = 1,
833 .no_ade = 1,
834 .xdfar_rw = 1,
835};
812#endif /* CONFIG_OF */ 836#endif /* CONFIG_OF */
813 837
814static void sh_eth_set_rate_sh7724(struct net_device *ndev) 838static void sh_eth_set_rate_sh7724(struct net_device *ndev)
@@ -3132,6 +3156,7 @@ static const struct of_device_id sh_eth_match_table[] = {
3132 { .compatible = "renesas,ether-r8a7794", .data = &rcar_gen2_data }, 3156 { .compatible = "renesas,ether-r8a7794", .data = &rcar_gen2_data },
3133 { .compatible = "renesas,gether-r8a77980", .data = &r8a77980_data }, 3157 { .compatible = "renesas,gether-r8a77980", .data = &r8a77980_data },
3134 { .compatible = "renesas,ether-r7s72100", .data = &r7s72100_data }, 3158 { .compatible = "renesas,ether-r7s72100", .data = &r7s72100_data },
3159 { .compatible = "renesas,ether-r7s9210", .data = &r7s9210_data },
3135 { .compatible = "renesas,rcar-gen1-ether", .data = &rcar_gen1_data }, 3160 { .compatible = "renesas,rcar-gen1-ether", .data = &rcar_gen1_data },
3136 { .compatible = "renesas,rcar-gen2-ether", .data = &rcar_gen2_data }, 3161 { .compatible = "renesas,rcar-gen2-ether", .data = &rcar_gen2_data },
3137 { } 3162 { }
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index f94be99cf400..0c18650bbfe6 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -1,19 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* SuperH Ethernet device driver 2/* SuperH Ethernet device driver
2 * 3 *
3 * Copyright (C) 2006-2012 Nobuhiro Iwamatsu 4 * Copyright (C) 2006-2012 Nobuhiro Iwamatsu
4 * Copyright (C) 2008-2012 Renesas Solutions Corp. 5 * Copyright (C) 2008-2012 Renesas Solutions Corp.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
17 */ 6 */
18 7
19#ifndef __SH_ETH_H__ 8#ifndef __SH_ETH_H__
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index edf20361ea5f..324049eebb9b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -33,7 +33,7 @@ config DWMAC_DWC_QOS_ETH
33 select PHYLIB 33 select PHYLIB
34 select CRC32 34 select CRC32
35 select MII 35 select MII
36 depends on OF && COMMON_CLK && HAS_DMA 36 depends on OF && HAS_DMA
37 help 37 help
38 Support for chips using the snps,dwc-qos-ethernet.txt DT binding. 38 Support for chips using the snps,dwc-qos-ethernet.txt DT binding.
39 39
@@ -57,7 +57,7 @@ config DWMAC_ANARION
57config DWMAC_IPQ806X 57config DWMAC_IPQ806X
58 tristate "QCA IPQ806x DWMAC support" 58 tristate "QCA IPQ806x DWMAC support"
59 default ARCH_QCOM 59 default ARCH_QCOM
60 depends on OF && COMMON_CLK && (ARCH_QCOM || COMPILE_TEST) 60 depends on OF && (ARCH_QCOM || COMPILE_TEST)
61 select MFD_SYSCON 61 select MFD_SYSCON
62 help 62 help
63 Support for QCA IPQ806X DWMAC Ethernet. 63 Support for QCA IPQ806X DWMAC Ethernet.
@@ -100,7 +100,7 @@ config DWMAC_OXNAS
100config DWMAC_ROCKCHIP 100config DWMAC_ROCKCHIP
101 tristate "Rockchip dwmac support" 101 tristate "Rockchip dwmac support"
102 default ARCH_ROCKCHIP 102 default ARCH_ROCKCHIP
103 depends on OF && COMMON_CLK && (ARCH_ROCKCHIP || COMPILE_TEST) 103 depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)
104 select MFD_SYSCON 104 select MFD_SYSCON
105 help 105 help
106 Support for Ethernet controller on Rockchip RK3288 SoC. 106 Support for Ethernet controller on Rockchip RK3288 SoC.
@@ -110,7 +110,7 @@ config DWMAC_ROCKCHIP
110 110
111config DWMAC_SOCFPGA 111config DWMAC_SOCFPGA
112 tristate "SOCFPGA dwmac support" 112 tristate "SOCFPGA dwmac support"
113 default ARCH_SOCFPGA 113 default (ARCH_SOCFPGA || ARCH_STRATIX10)
114 depends on OF && (ARCH_SOCFPGA || ARCH_STRATIX10 || COMPILE_TEST) 114 depends on OF && (ARCH_SOCFPGA || ARCH_STRATIX10 || COMPILE_TEST)
115 select MFD_SYSCON 115 select MFD_SYSCON
116 help 116 help
@@ -123,7 +123,7 @@ config DWMAC_SOCFPGA
123config DWMAC_STI 123config DWMAC_STI
124 tristate "STi GMAC support" 124 tristate "STi GMAC support"
125 default ARCH_STI 125 default ARCH_STI
126 depends on OF && COMMON_CLK && (ARCH_STI || COMPILE_TEST) 126 depends on OF && (ARCH_STI || COMPILE_TEST)
127 select MFD_SYSCON 127 select MFD_SYSCON
128 ---help--- 128 ---help---
129 Support for ethernet controller on STi SOCs. 129 Support for ethernet controller on STi SOCs.
@@ -147,7 +147,7 @@ config DWMAC_STM32
147config DWMAC_SUNXI 147config DWMAC_SUNXI
148 tristate "Allwinner GMAC support" 148 tristate "Allwinner GMAC support"
149 default ARCH_SUNXI 149 default ARCH_SUNXI
150 depends on OF && COMMON_CLK && (ARCH_SUNXI || COMPILE_TEST) 150 depends on OF && (ARCH_SUNXI || COMPILE_TEST)
151 ---help--- 151 ---help---
152 Support for Allwinner A20/A31 GMAC ethernet controllers. 152 Support for Allwinner A20/A31 GMAC ethernet controllers.
153 153
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 76649adf8fb0..c0a855b7ab3b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -112,7 +112,6 @@ struct stmmac_priv {
112 u32 tx_count_frames; 112 u32 tx_count_frames;
113 u32 tx_coal_frames; 113 u32 tx_coal_frames;
114 u32 tx_coal_timer; 114 u32 tx_coal_timer;
115 bool tx_timer_armed;
116 115
117 int tx_coalesce; 116 int tx_coalesce;
118 int hwts_tx_en; 117 int hwts_tx_en;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ff1ffb46198a..9f458bb16f2a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3147,16 +3147,13 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
3147 * element in case of no SG. 3147 * element in case of no SG.
3148 */ 3148 */
3149 priv->tx_count_frames += nfrags + 1; 3149 priv->tx_count_frames += nfrags + 1;
3150 if (likely(priv->tx_coal_frames > priv->tx_count_frames) && 3150 if (likely(priv->tx_coal_frames > priv->tx_count_frames)) {
3151 !priv->tx_timer_armed) {
3152 mod_timer(&priv->txtimer, 3151 mod_timer(&priv->txtimer,
3153 STMMAC_COAL_TIMER(priv->tx_coal_timer)); 3152 STMMAC_COAL_TIMER(priv->tx_coal_timer));
3154 priv->tx_timer_armed = true;
3155 } else { 3153 } else {
3156 priv->tx_count_frames = 0; 3154 priv->tx_count_frames = 0;
3157 stmmac_set_tx_ic(priv, desc); 3155 stmmac_set_tx_ic(priv, desc);
3158 priv->xstats.tx_set_ic_bit++; 3156 priv->xstats.tx_set_ic_bit++;
3159 priv->tx_timer_armed = false;
3160 } 3157 }
3161 3158
3162 skb_tx_timestamp(skb); 3159 skb_tx_timestamp(skb);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index 1a96dd9c1091..531294f4978b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -61,7 +61,7 @@ static int tc_fill_actions(struct stmmac_tc_entry *entry,
61 struct stmmac_tc_entry *action_entry = entry; 61 struct stmmac_tc_entry *action_entry = entry;
62 const struct tc_action *act; 62 const struct tc_action *act;
63 struct tcf_exts *exts; 63 struct tcf_exts *exts;
64 LIST_HEAD(actions); 64 int i;
65 65
66 exts = cls->knode.exts; 66 exts = cls->knode.exts;
67 if (!tcf_exts_has_actions(exts)) 67 if (!tcf_exts_has_actions(exts))
@@ -69,8 +69,7 @@ static int tc_fill_actions(struct stmmac_tc_entry *entry,
69 if (frag) 69 if (frag)
70 action_entry = frag; 70 action_entry = frag;
71 71
72 tcf_exts_to_list(exts, &actions); 72 tcf_exts_for_each_action(i, act, exts) {
73 list_for_each_entry(act, &actions, list) {
74 /* Accept */ 73 /* Accept */
75 if (is_tcf_gact_ok(act)) { 74 if (is_tcf_gact_ok(act)) {
76 action_entry->val.af = 1; 75 action_entry->val.af = 1;
diff --git a/drivers/net/ethernet/ti/cpsw-phy-sel.c b/drivers/net/ethernet/ti/cpsw-phy-sel.c
index 0c1adad7415d..396e1cd10667 100644
--- a/drivers/net/ethernet/ti/cpsw-phy-sel.c
+++ b/drivers/net/ethernet/ti/cpsw-phy-sel.c
@@ -170,10 +170,13 @@ void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave)
170 struct device_node *node; 170 struct device_node *node;
171 struct cpsw_phy_sel_priv *priv; 171 struct cpsw_phy_sel_priv *priv;
172 172
173 node = of_get_child_by_name(dev->of_node, "cpsw-phy-sel"); 173 node = of_parse_phandle(dev->of_node, "cpsw-phy-sel", 0);
174 if (!node) { 174 if (!node) {
175 dev_err(dev, "Phy mode driver DT not found\n"); 175 node = of_get_child_by_name(dev->of_node, "cpsw-phy-sel");
176 return; 176 if (!node) {
177 dev_err(dev, "Phy mode driver DT not found\n");
178 return;
179 }
177 } 180 }
178 181
179 dev = bus_find_device(&platform_bus_type, NULL, node, match); 182 dev = bus_find_device(&platform_bus_type, NULL, node, match);
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 507f68190cb1..70921bbe0e28 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -29,6 +29,7 @@
29#include <linux/netdevice.h> 29#include <linux/netdevice.h>
30#include <linux/inetdevice.h> 30#include <linux/inetdevice.h>
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/pci.h>
32#include <linux/skbuff.h> 33#include <linux/skbuff.h>
33#include <linux/if_vlan.h> 34#include <linux/if_vlan.h>
34#include <linux/in.h> 35#include <linux/in.h>
@@ -2039,12 +2040,16 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
2039{ 2040{
2040 struct net_device *ndev; 2041 struct net_device *ndev;
2041 struct net_device_context *net_device_ctx; 2042 struct net_device_context *net_device_ctx;
2043 struct device *pdev = vf_netdev->dev.parent;
2042 struct netvsc_device *netvsc_dev; 2044 struct netvsc_device *netvsc_dev;
2043 int ret; 2045 int ret;
2044 2046
2045 if (vf_netdev->addr_len != ETH_ALEN) 2047 if (vf_netdev->addr_len != ETH_ALEN)
2046 return NOTIFY_DONE; 2048 return NOTIFY_DONE;
2047 2049
2050 if (!pdev || !dev_is_pci(pdev) || dev_is_pf(pdev))
2051 return NOTIFY_DONE;
2052
2048 /* 2053 /*
2049 * We will use the MAC address to locate the synthetic interface to 2054 * We will use the MAC address to locate the synthetic interface to
2050 * associate with the VF interface. If we don't find a matching 2055 * associate with the VF interface. If we don't find a matching
@@ -2201,6 +2206,16 @@ static int netvsc_probe(struct hv_device *dev,
2201 2206
2202 memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN); 2207 memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
2203 2208
2209 /* We must get rtnl lock before scheduling nvdev->subchan_work,
2210 * otherwise netvsc_subchan_work() can get rtnl lock first and wait
2211 * all subchannels to show up, but that may not happen because
2212 * netvsc_probe() can't get rtnl lock and as a result vmbus_onoffer()
2213 * -> ... -> device_add() -> ... -> __device_attach() can't get
2214 * the device lock, so all the subchannels can't be processed --
2215 * finally netvsc_subchan_work() hangs for ever.
2216 */
2217 rtnl_lock();
2218
2204 if (nvdev->num_chn > 1) 2219 if (nvdev->num_chn > 1)
2205 schedule_work(&nvdev->subchan_work); 2220 schedule_work(&nvdev->subchan_work);
2206 2221
@@ -2219,7 +2234,6 @@ static int netvsc_probe(struct hv_device *dev,
2219 else 2234 else
2220 net->max_mtu = ETH_DATA_LEN; 2235 net->max_mtu = ETH_DATA_LEN;
2221 2236
2222 rtnl_lock();
2223 ret = register_netdevice(net); 2237 ret = register_netdevice(net);
2224 if (ret != 0) { 2238 if (ret != 0) {
2225 pr_err("Unable to register netdev.\n"); 2239 pr_err("Unable to register netdev.\n");
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 4637d980310e..52fffb98fde9 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -398,7 +398,6 @@ static umode_t sfp_hwmon_is_visible(const void *data,
398 switch (type) { 398 switch (type) {
399 case hwmon_temp: 399 case hwmon_temp:
400 switch (attr) { 400 switch (attr) {
401 case hwmon_temp_input:
402 case hwmon_temp_min_alarm: 401 case hwmon_temp_min_alarm:
403 case hwmon_temp_max_alarm: 402 case hwmon_temp_max_alarm:
404 case hwmon_temp_lcrit_alarm: 403 case hwmon_temp_lcrit_alarm:
@@ -407,13 +406,16 @@ static umode_t sfp_hwmon_is_visible(const void *data,
407 case hwmon_temp_max: 406 case hwmon_temp_max:
408 case hwmon_temp_lcrit: 407 case hwmon_temp_lcrit:
409 case hwmon_temp_crit: 408 case hwmon_temp_crit:
409 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
410 return 0;
411 /* fall through */
412 case hwmon_temp_input:
410 return 0444; 413 return 0444;
411 default: 414 default:
412 return 0; 415 return 0;
413 } 416 }
414 case hwmon_in: 417 case hwmon_in:
415 switch (attr) { 418 switch (attr) {
416 case hwmon_in_input:
417 case hwmon_in_min_alarm: 419 case hwmon_in_min_alarm:
418 case hwmon_in_max_alarm: 420 case hwmon_in_max_alarm:
419 case hwmon_in_lcrit_alarm: 421 case hwmon_in_lcrit_alarm:
@@ -422,13 +424,16 @@ static umode_t sfp_hwmon_is_visible(const void *data,
422 case hwmon_in_max: 424 case hwmon_in_max:
423 case hwmon_in_lcrit: 425 case hwmon_in_lcrit:
424 case hwmon_in_crit: 426 case hwmon_in_crit:
427 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
428 return 0;
429 /* fall through */
430 case hwmon_in_input:
425 return 0444; 431 return 0444;
426 default: 432 default:
427 return 0; 433 return 0;
428 } 434 }
429 case hwmon_curr: 435 case hwmon_curr:
430 switch (attr) { 436 switch (attr) {
431 case hwmon_curr_input:
432 case hwmon_curr_min_alarm: 437 case hwmon_curr_min_alarm:
433 case hwmon_curr_max_alarm: 438 case hwmon_curr_max_alarm:
434 case hwmon_curr_lcrit_alarm: 439 case hwmon_curr_lcrit_alarm:
@@ -437,6 +442,10 @@ static umode_t sfp_hwmon_is_visible(const void *data,
437 case hwmon_curr_max: 442 case hwmon_curr_max:
438 case hwmon_curr_lcrit: 443 case hwmon_curr_lcrit:
439 case hwmon_curr_crit: 444 case hwmon_curr_crit:
445 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
446 return 0;
447 /* fall through */
448 case hwmon_curr_input:
440 return 0444; 449 return 0444;
441 default: 450 default:
442 return 0; 451 return 0;
@@ -452,7 +461,6 @@ static umode_t sfp_hwmon_is_visible(const void *data,
452 channel == 1) 461 channel == 1)
453 return 0; 462 return 0;
454 switch (attr) { 463 switch (attr) {
455 case hwmon_power_input:
456 case hwmon_power_min_alarm: 464 case hwmon_power_min_alarm:
457 case hwmon_power_max_alarm: 465 case hwmon_power_max_alarm:
458 case hwmon_power_lcrit_alarm: 466 case hwmon_power_lcrit_alarm:
@@ -461,6 +469,10 @@ static umode_t sfp_hwmon_is_visible(const void *data,
461 case hwmon_power_max: 469 case hwmon_power_max:
462 case hwmon_power_lcrit: 470 case hwmon_power_lcrit:
463 case hwmon_power_crit: 471 case hwmon_power_crit:
472 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN))
473 return 0;
474 /* fall through */
475 case hwmon_power_input:
464 return 0444; 476 return 0444;
465 default: 477 default:
466 return 0; 478 return 0;
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index cb0cc30c3d6a..e3270deecec2 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -967,6 +967,13 @@ static const struct usb_device_id products[] = {
967 USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0x581d, USB_CLASS_VENDOR_SPEC, 1, 7), 967 USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0x581d, USB_CLASS_VENDOR_SPEC, 1, 7),
968 .driver_info = (unsigned long)&qmi_wwan_info, 968 .driver_info = (unsigned long)&qmi_wwan_info,
969 }, 969 },
970 { /* Quectel EP06/EG06/EM06 */
971 USB_DEVICE_AND_INTERFACE_INFO(0x2c7c, 0x0306,
972 USB_CLASS_VENDOR_SPEC,
973 USB_SUBCLASS_VENDOR_SPEC,
974 0xff),
975 .driver_info = (unsigned long)&qmi_wwan_info_quirk_dtr,
976 },
970 977
971 /* 3. Combined interface devices matching on interface number */ 978 /* 3. Combined interface devices matching on interface number */
972 {QMI_FIXED_INTF(0x0408, 0xea42, 4)}, /* Yota / Megafon M100-1 */ 979 {QMI_FIXED_INTF(0x0408, 0xea42, 4)}, /* Yota / Megafon M100-1 */
@@ -1255,7 +1262,6 @@ static const struct usb_device_id products[] = {
1255 {QMI_QUIRK_SET_DTR(0x2c7c, 0x0121, 4)}, /* Quectel EC21 Mini PCIe */ 1262 {QMI_QUIRK_SET_DTR(0x2c7c, 0x0121, 4)}, /* Quectel EC21 Mini PCIe */
1256 {QMI_QUIRK_SET_DTR(0x2c7c, 0x0191, 4)}, /* Quectel EG91 */ 1263 {QMI_QUIRK_SET_DTR(0x2c7c, 0x0191, 4)}, /* Quectel EG91 */
1257 {QMI_FIXED_INTF(0x2c7c, 0x0296, 4)}, /* Quectel BG96 */ 1264 {QMI_FIXED_INTF(0x2c7c, 0x0296, 4)}, /* Quectel BG96 */
1258 {QMI_QUIRK_SET_DTR(0x2c7c, 0x0306, 4)}, /* Quectel EP06 Mini PCIe */
1259 1265
1260 /* 4. Gobi 1000 devices */ 1266 /* 4. Gobi 1000 devices */
1261 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ 1267 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
@@ -1331,6 +1337,19 @@ static bool quectel_ec20_detected(struct usb_interface *intf)
1331 return false; 1337 return false;
1332} 1338}
1333 1339
1340static bool quectel_ep06_diag_detected(struct usb_interface *intf)
1341{
1342 struct usb_device *dev = interface_to_usbdev(intf);
1343 struct usb_interface_descriptor intf_desc = intf->cur_altsetting->desc;
1344
1345 if (le16_to_cpu(dev->descriptor.idVendor) == 0x2c7c &&
1346 le16_to_cpu(dev->descriptor.idProduct) == 0x0306 &&
1347 intf_desc.bNumEndpoints == 2)
1348 return true;
1349
1350 return false;
1351}
1352
1334static int qmi_wwan_probe(struct usb_interface *intf, 1353static int qmi_wwan_probe(struct usb_interface *intf,
1335 const struct usb_device_id *prod) 1354 const struct usb_device_id *prod)
1336{ 1355{
@@ -1365,6 +1384,15 @@ static int qmi_wwan_probe(struct usb_interface *intf,
1365 return -ENODEV; 1384 return -ENODEV;
1366 } 1385 }
1367 1386
1387 /* Quectel EP06/EM06/EG06 supports dynamic interface configuration, so
1388 * we need to match on class/subclass/protocol. These values are
1389 * identical for the diagnostic- and QMI-interface, but bNumEndpoints is
1390 * different. Ignore the current interface if the number of endpoints
1391 * the number for the diag interface (two).
1392 */
1393 if (quectel_ep06_diag_detected(intf))
1394 return -ENODEV;
1395
1368 return usbnet_probe(intf, id); 1396 return usbnet_probe(intf, id);
1369} 1397}
1370 1398
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 97742708460b..2cd71bdb6484 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -5217,8 +5217,8 @@ static int rtl8152_probe(struct usb_interface *intf,
5217 netdev->hw_features &= ~NETIF_F_RXCSUM; 5217 netdev->hw_features &= ~NETIF_F_RXCSUM;
5218 } 5218 }
5219 5219
5220 if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x3011 && 5220 if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x3011 && udev->serial &&
5221 udev->serial && !strcmp(udev->serial, "000001000000")) { 5221 (!strcmp(udev->serial, "000001000000") || !strcmp(udev->serial, "000002000000"))) {
5222 dev_info(&udev->dev, "Dell TB16 Dock, disable RX aggregation"); 5222 dev_info(&udev->dev, "Dell TB16 Dock, disable RX aggregation");
5223 set_bit(DELL_TB_RX_AGG_BUG, &tp->flags); 5223 set_bit(DELL_TB_RX_AGG_BUG, &tp->flags);
5224 } 5224 }
diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
index b4c3a957c102..73969dbeb5c5 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
@@ -985,15 +985,12 @@ iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
985 const u8 *nvm_chan = cfg->nvm_type == IWL_NVM_EXT ? 985 const u8 *nvm_chan = cfg->nvm_type == IWL_NVM_EXT ?
986 iwl_ext_nvm_channels : iwl_nvm_channels; 986 iwl_ext_nvm_channels : iwl_nvm_channels;
987 struct ieee80211_regdomain *regd, *copy_rd; 987 struct ieee80211_regdomain *regd, *copy_rd;
988 int size_of_regd, regd_to_copy, wmms_to_copy; 988 int size_of_regd, regd_to_copy;
989 int size_of_wmms = 0;
990 struct ieee80211_reg_rule *rule; 989 struct ieee80211_reg_rule *rule;
991 struct ieee80211_wmm_rule *wmm_rule, *d_wmm, *s_wmm;
992 struct regdb_ptrs *regdb_ptrs; 990 struct regdb_ptrs *regdb_ptrs;
993 enum nl80211_band band; 991 enum nl80211_band band;
994 int center_freq, prev_center_freq = 0; 992 int center_freq, prev_center_freq = 0;
995 int valid_rules = 0, n_wmms = 0; 993 int valid_rules = 0;
996 int i;
997 bool new_rule; 994 bool new_rule;
998 int max_num_ch = cfg->nvm_type == IWL_NVM_EXT ? 995 int max_num_ch = cfg->nvm_type == IWL_NVM_EXT ?
999 IWL_NVM_NUM_CHANNELS_EXT : IWL_NVM_NUM_CHANNELS; 996 IWL_NVM_NUM_CHANNELS_EXT : IWL_NVM_NUM_CHANNELS;
@@ -1012,11 +1009,7 @@ iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
1012 sizeof(struct ieee80211_regdomain) + 1009 sizeof(struct ieee80211_regdomain) +
1013 num_of_ch * sizeof(struct ieee80211_reg_rule); 1010 num_of_ch * sizeof(struct ieee80211_reg_rule);
1014 1011
1015 if (geo_info & GEO_WMM_ETSI_5GHZ_INFO) 1012 regd = kzalloc(size_of_regd, GFP_KERNEL);
1016 size_of_wmms =
1017 num_of_ch * sizeof(struct ieee80211_wmm_rule);
1018
1019 regd = kzalloc(size_of_regd + size_of_wmms, GFP_KERNEL);
1020 if (!regd) 1013 if (!regd)
1021 return ERR_PTR(-ENOMEM); 1014 return ERR_PTR(-ENOMEM);
1022 1015
@@ -1030,8 +1023,6 @@ iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
1030 regd->alpha2[0] = fw_mcc >> 8; 1023 regd->alpha2[0] = fw_mcc >> 8;
1031 regd->alpha2[1] = fw_mcc & 0xff; 1024 regd->alpha2[1] = fw_mcc & 0xff;
1032 1025
1033 wmm_rule = (struct ieee80211_wmm_rule *)((u8 *)regd + size_of_regd);
1034
1035 for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) { 1026 for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
1036 ch_flags = (u16)__le32_to_cpup(channels + ch_idx); 1027 ch_flags = (u16)__le32_to_cpup(channels + ch_idx);
1037 band = (ch_idx < NUM_2GHZ_CHANNELS) ? 1028 band = (ch_idx < NUM_2GHZ_CHANNELS) ?
@@ -1085,26 +1076,10 @@ iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
1085 band == NL80211_BAND_2GHZ) 1076 band == NL80211_BAND_2GHZ)
1086 continue; 1077 continue;
1087 1078
1088 if (!reg_query_regdb_wmm(regd->alpha2, center_freq, 1079 reg_query_regdb_wmm(regd->alpha2, center_freq, rule);
1089 &regdb_ptrs[n_wmms].token, wmm_rule)) {
1090 /* Add only new rules */
1091 for (i = 0; i < n_wmms; i++) {
1092 if (regdb_ptrs[i].token ==
1093 regdb_ptrs[n_wmms].token) {
1094 rule->wmm_rule = regdb_ptrs[i].rule;
1095 break;
1096 }
1097 }
1098 if (i == n_wmms) {
1099 rule->wmm_rule = wmm_rule;
1100 regdb_ptrs[n_wmms++].rule = wmm_rule;
1101 wmm_rule++;
1102 }
1103 }
1104 } 1080 }
1105 1081
1106 regd->n_reg_rules = valid_rules; 1082 regd->n_reg_rules = valid_rules;
1107 regd->n_wmm_rules = n_wmms;
1108 1083
1109 /* 1084 /*
1110 * Narrow down regdom for unused regulatory rules to prevent hole 1085 * Narrow down regdom for unused regulatory rules to prevent hole
@@ -1113,28 +1088,13 @@ iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
1113 regd_to_copy = sizeof(struct ieee80211_regdomain) + 1088 regd_to_copy = sizeof(struct ieee80211_regdomain) +
1114 valid_rules * sizeof(struct ieee80211_reg_rule); 1089 valid_rules * sizeof(struct ieee80211_reg_rule);
1115 1090
1116 wmms_to_copy = sizeof(struct ieee80211_wmm_rule) * n_wmms; 1091 copy_rd = kzalloc(regd_to_copy, GFP_KERNEL);
1117
1118 copy_rd = kzalloc(regd_to_copy + wmms_to_copy, GFP_KERNEL);
1119 if (!copy_rd) { 1092 if (!copy_rd) {
1120 copy_rd = ERR_PTR(-ENOMEM); 1093 copy_rd = ERR_PTR(-ENOMEM);
1121 goto out; 1094 goto out;
1122 } 1095 }
1123 1096
1124 memcpy(copy_rd, regd, regd_to_copy); 1097 memcpy(copy_rd, regd, regd_to_copy);
1125 memcpy((u8 *)copy_rd + regd_to_copy, (u8 *)regd + size_of_regd,
1126 wmms_to_copy);
1127
1128 d_wmm = (struct ieee80211_wmm_rule *)((u8 *)copy_rd + regd_to_copy);
1129 s_wmm = (struct ieee80211_wmm_rule *)((u8 *)regd + size_of_regd);
1130
1131 for (i = 0; i < regd->n_reg_rules; i++) {
1132 if (!regd->reg_rules[i].wmm_rule)
1133 continue;
1134
1135 copy_rd->reg_rules[i].wmm_rule = d_wmm +
1136 (regd->reg_rules[i].wmm_rule - s_wmm);
1137 }
1138 1098
1139out: 1099out:
1140 kfree(regdb_ptrs); 1100 kfree(regdb_ptrs);
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 998dfac0fcff..1068757ec42e 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -34,6 +34,7 @@
34#include <net/net_namespace.h> 34#include <net/net_namespace.h>
35#include <net/netns/generic.h> 35#include <net/netns/generic.h>
36#include <linux/rhashtable.h> 36#include <linux/rhashtable.h>
37#include <linux/nospec.h>
37#include "mac80211_hwsim.h" 38#include "mac80211_hwsim.h"
38 39
39#define WARN_QUEUE 100 40#define WARN_QUEUE 100
@@ -2820,9 +2821,6 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
2820 IEEE80211_VHT_CAP_SHORT_GI_80 | 2821 IEEE80211_VHT_CAP_SHORT_GI_80 |
2821 IEEE80211_VHT_CAP_SHORT_GI_160 | 2822 IEEE80211_VHT_CAP_SHORT_GI_160 |
2822 IEEE80211_VHT_CAP_TXSTBC | 2823 IEEE80211_VHT_CAP_TXSTBC |
2823 IEEE80211_VHT_CAP_RXSTBC_1 |
2824 IEEE80211_VHT_CAP_RXSTBC_2 |
2825 IEEE80211_VHT_CAP_RXSTBC_3 |
2826 IEEE80211_VHT_CAP_RXSTBC_4 | 2824 IEEE80211_VHT_CAP_RXSTBC_4 |
2827 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; 2825 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
2828 sband->vht_cap.vht_mcs.rx_mcs_map = 2826 sband->vht_cap.vht_mcs.rx_mcs_map =
@@ -3317,6 +3315,11 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
3317 if (info->attrs[HWSIM_ATTR_CHANNELS]) 3315 if (info->attrs[HWSIM_ATTR_CHANNELS])
3318 param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]); 3316 param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]);
3319 3317
3318 if (param.channels < 1) {
3319 GENL_SET_ERR_MSG(info, "must have at least one channel");
3320 return -EINVAL;
3321 }
3322
3320 if (param.channels > CFG80211_MAX_NUM_DIFFERENT_CHANNELS) { 3323 if (param.channels > CFG80211_MAX_NUM_DIFFERENT_CHANNELS) {
3321 GENL_SET_ERR_MSG(info, "too many channels specified"); 3324 GENL_SET_ERR_MSG(info, "too many channels specified");
3322 return -EINVAL; 3325 return -EINVAL;
@@ -3350,6 +3353,9 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
3350 kfree(hwname); 3353 kfree(hwname);
3351 return -EINVAL; 3354 return -EINVAL;
3352 } 3355 }
3356
3357 idx = array_index_nospec(idx,
3358 ARRAY_SIZE(hwsim_world_regdom_custom));
3353 param.regd = hwsim_world_regdom_custom[idx]; 3359 param.regd = hwsim_world_regdom_custom[idx];
3354 } 3360 }
3355 3361
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 73f596a90c69..9407acbd19a9 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -87,8 +87,7 @@ struct netfront_cb {
87/* IRQ name is queue name with "-tx" or "-rx" appended */ 87/* IRQ name is queue name with "-tx" or "-rx" appended */
88#define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3) 88#define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3)
89 89
90static DECLARE_WAIT_QUEUE_HEAD(module_load_q); 90static DECLARE_WAIT_QUEUE_HEAD(module_wq);
91static DECLARE_WAIT_QUEUE_HEAD(module_unload_q);
92 91
93struct netfront_stats { 92struct netfront_stats {
94 u64 packets; 93 u64 packets;
@@ -1332,11 +1331,11 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
1332 netif_carrier_off(netdev); 1331 netif_carrier_off(netdev);
1333 1332
1334 xenbus_switch_state(dev, XenbusStateInitialising); 1333 xenbus_switch_state(dev, XenbusStateInitialising);
1335 wait_event(module_load_q, 1334 wait_event(module_wq,
1336 xenbus_read_driver_state(dev->otherend) != 1335 xenbus_read_driver_state(dev->otherend) !=
1337 XenbusStateClosed && 1336 XenbusStateClosed &&
1338 xenbus_read_driver_state(dev->otherend) != 1337 xenbus_read_driver_state(dev->otherend) !=
1339 XenbusStateUnknown); 1338 XenbusStateUnknown);
1340 return netdev; 1339 return netdev;
1341 1340
1342 exit: 1341 exit:
@@ -2010,15 +2009,14 @@ static void netback_changed(struct xenbus_device *dev,
2010 2009
2011 dev_dbg(&dev->dev, "%s\n", xenbus_strstate(backend_state)); 2010 dev_dbg(&dev->dev, "%s\n", xenbus_strstate(backend_state));
2012 2011
2012 wake_up_all(&module_wq);
2013
2013 switch (backend_state) { 2014 switch (backend_state) {
2014 case XenbusStateInitialising: 2015 case XenbusStateInitialising:
2015 case XenbusStateInitialised: 2016 case XenbusStateInitialised:
2016 case XenbusStateReconfiguring: 2017 case XenbusStateReconfiguring:
2017 case XenbusStateReconfigured: 2018 case XenbusStateReconfigured:
2018 break;
2019
2020 case XenbusStateUnknown: 2019 case XenbusStateUnknown:
2021 wake_up_all(&module_unload_q);
2022 break; 2020 break;
2023 2021
2024 case XenbusStateInitWait: 2022 case XenbusStateInitWait:
@@ -2034,12 +2032,10 @@ static void netback_changed(struct xenbus_device *dev,
2034 break; 2032 break;
2035 2033
2036 case XenbusStateClosed: 2034 case XenbusStateClosed:
2037 wake_up_all(&module_unload_q);
2038 if (dev->state == XenbusStateClosed) 2035 if (dev->state == XenbusStateClosed)
2039 break; 2036 break;
2040 /* Missed the backend's CLOSING state -- fallthrough */ 2037 /* Missed the backend's CLOSING state -- fallthrough */
2041 case XenbusStateClosing: 2038 case XenbusStateClosing:
2042 wake_up_all(&module_unload_q);
2043 xenbus_frontend_closed(dev); 2039 xenbus_frontend_closed(dev);
2044 break; 2040 break;
2045 } 2041 }
@@ -2147,14 +2143,14 @@ static int xennet_remove(struct xenbus_device *dev)
2147 2143
2148 if (xenbus_read_driver_state(dev->otherend) != XenbusStateClosed) { 2144 if (xenbus_read_driver_state(dev->otherend) != XenbusStateClosed) {
2149 xenbus_switch_state(dev, XenbusStateClosing); 2145 xenbus_switch_state(dev, XenbusStateClosing);
2150 wait_event(module_unload_q, 2146 wait_event(module_wq,
2151 xenbus_read_driver_state(dev->otherend) == 2147 xenbus_read_driver_state(dev->otherend) ==
2152 XenbusStateClosing || 2148 XenbusStateClosing ||
2153 xenbus_read_driver_state(dev->otherend) == 2149 xenbus_read_driver_state(dev->otherend) ==
2154 XenbusStateUnknown); 2150 XenbusStateUnknown);
2155 2151
2156 xenbus_switch_state(dev, XenbusStateClosed); 2152 xenbus_switch_state(dev, XenbusStateClosed);
2157 wait_event(module_unload_q, 2153 wait_event(module_wq,
2158 xenbus_read_driver_state(dev->otherend) == 2154 xenbus_read_driver_state(dev->otherend) ==
2159 XenbusStateClosed || 2155 XenbusStateClosed ||
2160 xenbus_read_driver_state(dev->otherend) == 2156 xenbus_read_driver_state(dev->otherend) ==
diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 27902a8799b1..8aae6dcc839f 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -812,9 +812,9 @@ u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
812 * overshoots the remainder by 4 bytes, assume it was 812 * overshoots the remainder by 4 bytes, assume it was
813 * including 'status'. 813 * including 'status'.
814 */ 814 */
815 if (out_field[1] - 8 == remainder) 815 if (out_field[1] - 4 == remainder)
816 return remainder; 816 return remainder;
817 return out_field[1] - 4; 817 return out_field[1] - 8;
818 } else if (cmd == ND_CMD_CALL) { 818 } else if (cmd == ND_CMD_CALL) {
819 struct nd_cmd_pkg *pkg = (struct nd_cmd_pkg *) in_field; 819 struct nd_cmd_pkg *pkg = (struct nd_cmd_pkg *) in_field;
820 820
diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c
index 233907889f96..6c8fb7590838 100644
--- a/drivers/nvdimm/dimm.c
+++ b/drivers/nvdimm/dimm.c
@@ -34,6 +34,9 @@ static int nvdimm_probe(struct device *dev)
34 return rc; 34 return rc;
35 } 35 }
36 36
37 /* reset locked, to be validated below... */
38 nvdimm_clear_locked(dev);
39
37 ndd = kzalloc(sizeof(*ndd), GFP_KERNEL); 40 ndd = kzalloc(sizeof(*ndd), GFP_KERNEL);
38 if (!ndd) 41 if (!ndd)
39 return -ENOMEM; 42 return -ENOMEM;
@@ -48,12 +51,30 @@ static int nvdimm_probe(struct device *dev)
48 get_device(dev); 51 get_device(dev);
49 kref_init(&ndd->kref); 52 kref_init(&ndd->kref);
50 53
54 /*
55 * EACCES failures reading the namespace label-area-properties
56 * are interpreted as the DIMM capacity being locked but the
57 * namespace labels themselves being accessible.
58 */
51 rc = nvdimm_init_nsarea(ndd); 59 rc = nvdimm_init_nsarea(ndd);
52 if (rc == -EACCES) 60 if (rc == -EACCES) {
61 /*
62 * See nvdimm_namespace_common_probe() where we fail to
63 * allow namespaces to probe while the DIMM is locked,
64 * but we do allow for namespace enumeration.
65 */
53 nvdimm_set_locked(dev); 66 nvdimm_set_locked(dev);
67 rc = 0;
68 }
54 if (rc) 69 if (rc)
55 goto err; 70 goto err;
56 71
72 /*
73 * EACCES failures reading the namespace label-data are
74 * interpreted as the label area being locked in addition to the
75 * DIMM capacity. We fail the dimm probe to prevent regions from
76 * attempting to parse the label area.
77 */
57 rc = nvdimm_init_config_data(ndd); 78 rc = nvdimm_init_config_data(ndd);
58 if (rc == -EACCES) 79 if (rc == -EACCES)
59 nvdimm_set_locked(dev); 80 nvdimm_set_locked(dev);
@@ -72,7 +93,6 @@ static int nvdimm_probe(struct device *dev)
72 if (rc == 0) 93 if (rc == 0)
73 nvdimm_set_aliasing(dev); 94 nvdimm_set_aliasing(dev);
74 } 95 }
75 nvdimm_clear_locked(dev);
76 nvdimm_bus_unlock(dev); 96 nvdimm_bus_unlock(dev);
77 97
78 if (rc) 98 if (rc)
diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c
index 8d348b22ba45..863cabc35215 100644
--- a/drivers/nvdimm/dimm_devs.c
+++ b/drivers/nvdimm/dimm_devs.c
@@ -537,6 +537,37 @@ resource_size_t nd_blk_available_dpa(struct nd_region *nd_region)
537} 537}
538 538
539/** 539/**
540 * nd_pmem_max_contiguous_dpa - For the given dimm+region, return the max
541 * contiguous unallocated dpa range.
542 * @nd_region: constrain available space check to this reference region
543 * @nd_mapping: container of dpa-resource-root + labels
544 */
545resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
546 struct nd_mapping *nd_mapping)
547{
548 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
549 struct nvdimm_bus *nvdimm_bus;
550 resource_size_t max = 0;
551 struct resource *res;
552
553 /* if a dimm is disabled the available capacity is zero */
554 if (!ndd)
555 return 0;
556
557 nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
558 if (__reserve_free_pmem(&nd_region->dev, nd_mapping->nvdimm))
559 return 0;
560 for_each_dpa_resource(ndd, res) {
561 if (strcmp(res->name, "pmem-reserve") != 0)
562 continue;
563 if (resource_size(res) > max)
564 max = resource_size(res);
565 }
566 release_free_pmem(nvdimm_bus, nd_mapping);
567 return max;
568}
569
570/**
540 * nd_pmem_available_dpa - for the given dimm+region account unallocated dpa 571 * nd_pmem_available_dpa - for the given dimm+region account unallocated dpa
541 * @nd_mapping: container of dpa-resource-root + labels 572 * @nd_mapping: container of dpa-resource-root + labels
542 * @nd_region: constrain available space check to this reference region 573 * @nd_region: constrain available space check to this reference region
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 28afdd668905..4a4266250c28 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -799,7 +799,7 @@ static int merge_dpa(struct nd_region *nd_region,
799 return 0; 799 return 0;
800} 800}
801 801
802static int __reserve_free_pmem(struct device *dev, void *data) 802int __reserve_free_pmem(struct device *dev, void *data)
803{ 803{
804 struct nvdimm *nvdimm = data; 804 struct nvdimm *nvdimm = data;
805 struct nd_region *nd_region; 805 struct nd_region *nd_region;
@@ -836,7 +836,7 @@ static int __reserve_free_pmem(struct device *dev, void *data)
836 return 0; 836 return 0;
837} 837}
838 838
839static void release_free_pmem(struct nvdimm_bus *nvdimm_bus, 839void release_free_pmem(struct nvdimm_bus *nvdimm_bus,
840 struct nd_mapping *nd_mapping) 840 struct nd_mapping *nd_mapping)
841{ 841{
842 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); 842 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
@@ -1032,7 +1032,7 @@ static ssize_t __size_store(struct device *dev, unsigned long long val)
1032 1032
1033 allocated += nvdimm_allocated_dpa(ndd, &label_id); 1033 allocated += nvdimm_allocated_dpa(ndd, &label_id);
1034 } 1034 }
1035 available = nd_region_available_dpa(nd_region); 1035 available = nd_region_allocatable_dpa(nd_region);
1036 1036
1037 if (val > available + allocated) 1037 if (val > available + allocated)
1038 return -ENOSPC; 1038 return -ENOSPC;
@@ -1144,6 +1144,26 @@ resource_size_t nvdimm_namespace_capacity(struct nd_namespace_common *ndns)
1144} 1144}
1145EXPORT_SYMBOL(nvdimm_namespace_capacity); 1145EXPORT_SYMBOL(nvdimm_namespace_capacity);
1146 1146
1147bool nvdimm_namespace_locked(struct nd_namespace_common *ndns)
1148{
1149 int i;
1150 bool locked = false;
1151 struct device *dev = &ndns->dev;
1152 struct nd_region *nd_region = to_nd_region(dev->parent);
1153
1154 for (i = 0; i < nd_region->ndr_mappings; i++) {
1155 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
1156 struct nvdimm *nvdimm = nd_mapping->nvdimm;
1157
1158 if (test_bit(NDD_LOCKED, &nvdimm->flags)) {
1159 dev_dbg(dev, "%s locked\n", nvdimm_name(nvdimm));
1160 locked = true;
1161 }
1162 }
1163 return locked;
1164}
1165EXPORT_SYMBOL(nvdimm_namespace_locked);
1166
1147static ssize_t size_show(struct device *dev, 1167static ssize_t size_show(struct device *dev,
1148 struct device_attribute *attr, char *buf) 1168 struct device_attribute *attr, char *buf)
1149{ 1169{
@@ -1695,6 +1715,9 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev)
1695 } 1715 }
1696 } 1716 }
1697 1717
1718 if (nvdimm_namespace_locked(ndns))
1719 return ERR_PTR(-EACCES);
1720
1698 size = nvdimm_namespace_capacity(ndns); 1721 size = nvdimm_namespace_capacity(ndns);
1699 if (size < ND_MIN_NAMESPACE_SIZE) { 1722 if (size < ND_MIN_NAMESPACE_SIZE) {
1700 dev_dbg(&ndns->dev, "%pa, too small must be at least %#x\n", 1723 dev_dbg(&ndns->dev, "%pa, too small must be at least %#x\n",
diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h
index 79274ead54fb..ac68072fb8cd 100644
--- a/drivers/nvdimm/nd-core.h
+++ b/drivers/nvdimm/nd-core.h
@@ -100,6 +100,14 @@ struct nd_region;
100struct nvdimm_drvdata; 100struct nvdimm_drvdata;
101struct nd_mapping; 101struct nd_mapping;
102void nd_mapping_free_labels(struct nd_mapping *nd_mapping); 102void nd_mapping_free_labels(struct nd_mapping *nd_mapping);
103
104int __reserve_free_pmem(struct device *dev, void *data);
105void release_free_pmem(struct nvdimm_bus *nvdimm_bus,
106 struct nd_mapping *nd_mapping);
107
108resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
109 struct nd_mapping *nd_mapping);
110resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region);
103resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region, 111resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
104 struct nd_mapping *nd_mapping, resource_size_t *overlap); 112 struct nd_mapping *nd_mapping, resource_size_t *overlap);
105resource_size_t nd_blk_available_dpa(struct nd_region *nd_region); 113resource_size_t nd_blk_available_dpa(struct nd_region *nd_region);
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index 6ee7fd7e4bbd..98317e7ce5b5 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -357,6 +357,7 @@ struct resource *nvdimm_allocate_dpa(struct nvdimm_drvdata *ndd,
357 struct nd_label_id *label_id, resource_size_t start, 357 struct nd_label_id *label_id, resource_size_t start,
358 resource_size_t n); 358 resource_size_t n);
359resource_size_t nvdimm_namespace_capacity(struct nd_namespace_common *ndns); 359resource_size_t nvdimm_namespace_capacity(struct nd_namespace_common *ndns);
360bool nvdimm_namespace_locked(struct nd_namespace_common *ndns);
360struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev); 361struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev);
361int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns); 362int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns);
362int nvdimm_namespace_detach_btt(struct nd_btt *nd_btt); 363int nvdimm_namespace_detach_btt(struct nd_btt *nd_btt);
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index dd17acd8fe68..6071e2942053 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -20,6 +20,7 @@
20#include <linux/hdreg.h> 20#include <linux/hdreg.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/set_memory.h>
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
25#include <linux/badblocks.h> 26#include <linux/badblocks.h>
@@ -51,6 +52,30 @@ static struct nd_region *to_region(struct pmem_device *pmem)
51 return to_nd_region(to_dev(pmem)->parent); 52 return to_nd_region(to_dev(pmem)->parent);
52} 53}
53 54
55static void hwpoison_clear(struct pmem_device *pmem,
56 phys_addr_t phys, unsigned int len)
57{
58 unsigned long pfn_start, pfn_end, pfn;
59
60 /* only pmem in the linear map supports HWPoison */
61 if (is_vmalloc_addr(pmem->virt_addr))
62 return;
63
64 pfn_start = PHYS_PFN(phys);
65 pfn_end = pfn_start + PHYS_PFN(len);
66 for (pfn = pfn_start; pfn < pfn_end; pfn++) {
67 struct page *page = pfn_to_page(pfn);
68
69 /*
70 * Note, no need to hold a get_dev_pagemap() reference
71 * here since we're in the driver I/O path and
72 * outstanding I/O requests pin the dev_pagemap.
73 */
74 if (test_and_clear_pmem_poison(page))
75 clear_mce_nospec(pfn);
76 }
77}
78
54static blk_status_t pmem_clear_poison(struct pmem_device *pmem, 79static blk_status_t pmem_clear_poison(struct pmem_device *pmem,
55 phys_addr_t offset, unsigned int len) 80 phys_addr_t offset, unsigned int len)
56{ 81{
@@ -65,6 +90,7 @@ static blk_status_t pmem_clear_poison(struct pmem_device *pmem,
65 if (cleared < len) 90 if (cleared < len)
66 rc = BLK_STS_IOERR; 91 rc = BLK_STS_IOERR;
67 if (cleared > 0 && cleared / 512) { 92 if (cleared > 0 && cleared / 512) {
93 hwpoison_clear(pmem, pmem->phys_addr + offset, cleared);
68 cleared /= 512; 94 cleared /= 512;
69 dev_dbg(dev, "%#llx clear %ld sector%s\n", 95 dev_dbg(dev, "%#llx clear %ld sector%s\n",
70 (unsigned long long) sector, cleared, 96 (unsigned long long) sector, cleared,
@@ -226,8 +252,11 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
226 if (unlikely(is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512, 252 if (unlikely(is_bad_pmem(&pmem->bb, PFN_PHYS(pgoff) / 512,
227 PFN_PHYS(nr_pages)))) 253 PFN_PHYS(nr_pages))))
228 return -EIO; 254 return -EIO;
229 *kaddr = pmem->virt_addr + offset; 255
230 *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags); 256 if (kaddr)
257 *kaddr = pmem->virt_addr + offset;
258 if (pfn)
259 *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags);
231 260
232 /* 261 /*
233 * If badblocks are present, limit known good range to the 262 * If badblocks are present, limit known good range to the
diff --git a/drivers/nvdimm/pmem.h b/drivers/nvdimm/pmem.h
index a64ebc78b5df..59cfe13ea8a8 100644
--- a/drivers/nvdimm/pmem.h
+++ b/drivers/nvdimm/pmem.h
@@ -1,6 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __NVDIMM_PMEM_H__ 2#ifndef __NVDIMM_PMEM_H__
3#define __NVDIMM_PMEM_H__ 3#define __NVDIMM_PMEM_H__
4#include <linux/page-flags.h>
4#include <linux/badblocks.h> 5#include <linux/badblocks.h>
5#include <linux/types.h> 6#include <linux/types.h>
6#include <linux/pfn_t.h> 7#include <linux/pfn_t.h>
@@ -27,4 +28,16 @@ struct pmem_device {
27 28
28long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, 29long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
29 long nr_pages, void **kaddr, pfn_t *pfn); 30 long nr_pages, void **kaddr, pfn_t *pfn);
31
32#ifdef CONFIG_MEMORY_FAILURE
33static inline bool test_and_clear_pmem_poison(struct page *page)
34{
35 return TestClearPageHWPoison(page);
36}
37#else
38static inline bool test_and_clear_pmem_poison(struct page *page)
39{
40 return false;
41}
42#endif
30#endif /* __NVDIMM_PMEM_H__ */ 43#endif /* __NVDIMM_PMEM_H__ */
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index ec3543b83330..fa37afcd43ff 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -389,6 +389,30 @@ resource_size_t nd_region_available_dpa(struct nd_region *nd_region)
389 return available; 389 return available;
390} 390}
391 391
392resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region)
393{
394 resource_size_t available = 0;
395 int i;
396
397 if (is_memory(&nd_region->dev))
398 available = PHYS_ADDR_MAX;
399
400 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
401 for (i = 0; i < nd_region->ndr_mappings; i++) {
402 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
403
404 if (is_memory(&nd_region->dev))
405 available = min(available,
406 nd_pmem_max_contiguous_dpa(nd_region,
407 nd_mapping));
408 else if (is_nd_blk(&nd_region->dev))
409 available += nd_blk_available_dpa(nd_region);
410 }
411 if (is_memory(&nd_region->dev))
412 return available * nd_region->ndr_mappings;
413 return available;
414}
415
392static ssize_t available_size_show(struct device *dev, 416static ssize_t available_size_show(struct device *dev,
393 struct device_attribute *attr, char *buf) 417 struct device_attribute *attr, char *buf)
394{ 418{
@@ -410,6 +434,21 @@ static ssize_t available_size_show(struct device *dev,
410} 434}
411static DEVICE_ATTR_RO(available_size); 435static DEVICE_ATTR_RO(available_size);
412 436
437static ssize_t max_available_extent_show(struct device *dev,
438 struct device_attribute *attr, char *buf)
439{
440 struct nd_region *nd_region = to_nd_region(dev);
441 unsigned long long available = 0;
442
443 nvdimm_bus_lock(dev);
444 wait_nvdimm_bus_probe_idle(dev);
445 available = nd_region_allocatable_dpa(nd_region);
446 nvdimm_bus_unlock(dev);
447
448 return sprintf(buf, "%llu\n", available);
449}
450static DEVICE_ATTR_RO(max_available_extent);
451
413static ssize_t init_namespaces_show(struct device *dev, 452static ssize_t init_namespaces_show(struct device *dev,
414 struct device_attribute *attr, char *buf) 453 struct device_attribute *attr, char *buf)
415{ 454{
@@ -561,6 +600,7 @@ static struct attribute *nd_region_attributes[] = {
561 &dev_attr_read_only.attr, 600 &dev_attr_read_only.attr,
562 &dev_attr_set_cookie.attr, 601 &dev_attr_set_cookie.attr,
563 &dev_attr_available_size.attr, 602 &dev_attr_available_size.attr,
603 &dev_attr_max_available_extent.attr,
564 &dev_attr_namespace_seed.attr, 604 &dev_attr_namespace_seed.attr,
565 &dev_attr_init_namespaces.attr, 605 &dev_attr_init_namespaces.attr,
566 &dev_attr_badblocks.attr, 606 &dev_attr_badblocks.attr,
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 466e3c8582f0..9095b8290150 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex);
54 */ 54 */
55DEFINE_RAW_SPINLOCK(devtree_lock); 55DEFINE_RAW_SPINLOCK(devtree_lock);
56 56
57bool of_node_name_eq(const struct device_node *np, const char *name)
58{
59 const char *node_name;
60 size_t len;
61
62 if (!np)
63 return false;
64
65 node_name = kbasename(np->full_name);
66 len = strchrnul(node_name, '@') - node_name;
67
68 return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
69}
70
71bool of_node_name_prefix(const struct device_node *np, const char *prefix)
72{
73 if (!np)
74 return false;
75
76 return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0;
77}
78
57int of_n_addr_cells(struct device_node *np) 79int of_n_addr_cells(struct device_node *np)
58{ 80{
59 u32 cells; 81 u32 cells;
@@ -720,6 +742,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
720EXPORT_SYMBOL(of_get_next_available_child); 742EXPORT_SYMBOL(of_get_next_available_child);
721 743
722/** 744/**
745 * of_get_compatible_child - Find compatible child node
746 * @parent: parent node
747 * @compatible: compatible string
748 *
749 * Lookup child node whose compatible property contains the given compatible
750 * string.
751 *
752 * Returns a node pointer with refcount incremented, use of_node_put() on it
753 * when done; or NULL if not found.
754 */
755struct device_node *of_get_compatible_child(const struct device_node *parent,
756 const char *compatible)
757{
758 struct device_node *child;
759
760 for_each_child_of_node(parent, child) {
761 if (of_device_is_compatible(child, compatible))
762 break;
763 }
764
765 return child;
766}
767EXPORT_SYMBOL(of_get_compatible_child);
768
769/**
723 * of_get_child_by_name - Find the child node by name for a given parent 770 * of_get_child_by_name - Find the child node by name for a given parent
724 * @node: parent node 771 * @node: parent node
725 * @name: child name to look for. 772 * @name: child name to look for.
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7ba90c290a42..6c59673933e9 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -241,6 +241,10 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
241 if (!dev) 241 if (!dev)
242 goto err_clear_flag; 242 goto err_clear_flag;
243 243
244 /* AMBA devices only support a single DMA mask */
245 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
246 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
247
244 /* setup generic device info */ 248 /* setup generic device info */
245 dev->dev.of_node = of_node_get(node); 249 dev->dev.of_node = of_node_get(node);
246 dev->dev.fwnode = &node->fwnode; 250 dev->dev.fwnode = &node->fwnode;
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 7136e3430925..a938abdb41ce 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -496,7 +496,7 @@ int pciehp_power_on_slot(struct slot *slot)
496 u16 slot_status; 496 u16 slot_status;
497 int retval; 497 int retval;
498 498
499 /* Clear sticky power-fault bit from previous power failures */ 499 /* Clear power-fault bit from previous power failures */
500 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); 500 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
501 if (slot_status & PCI_EXP_SLTSTA_PFD) 501 if (slot_status & PCI_EXP_SLTSTA_PFD)
502 pcie_capability_write_word(pdev, PCI_EXP_SLTSTA, 502 pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,
@@ -646,6 +646,14 @@ static irqreturn_t pciehp_ist(int irq, void *dev_id)
646 pciehp_handle_button_press(slot); 646 pciehp_handle_button_press(slot);
647 } 647 }
648 648
649 /* Check Power Fault Detected */
650 if ((events & PCI_EXP_SLTSTA_PFD) && !ctrl->power_fault_detected) {
651 ctrl->power_fault_detected = 1;
652 ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(slot));
653 pciehp_set_attention_status(slot, 1);
654 pciehp_green_led_off(slot);
655 }
656
649 /* 657 /*
650 * Disable requests have higher priority than Presence Detect Changed 658 * Disable requests have higher priority than Presence Detect Changed
651 * or Data Link Layer State Changed events. 659 * or Data Link Layer State Changed events.
@@ -657,14 +665,6 @@ static irqreturn_t pciehp_ist(int irq, void *dev_id)
657 pciehp_handle_presence_or_link_change(slot, events); 665 pciehp_handle_presence_or_link_change(slot, events);
658 up_read(&ctrl->reset_lock); 666 up_read(&ctrl->reset_lock);
659 667
660 /* Check Power Fault Detected */
661 if ((events & PCI_EXP_SLTSTA_PFD) && !ctrl->power_fault_detected) {
662 ctrl->power_fault_detected = 1;
663 ctrl_err(ctrl, "Slot(%s): Power fault\n", slot_name(slot));
664 pciehp_set_attention_status(slot, 1);
665 pciehp_green_led_off(slot);
666 }
667
668 pci_config_pm_runtime_put(pdev); 668 pci_config_pm_runtime_put(pdev);
669 wake_up(&ctrl->requester); 669 wake_up(&ctrl->requester);
670 return IRQ_HANDLED; 670 return IRQ_HANDLED;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 29ff9619b5fa..1835f3a7aa8d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4547,6 +4547,7 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev)
4547 4547
4548 return pci_dev_wait(dev, "bus reset", PCIE_RESET_READY_POLL_MS); 4548 return pci_dev_wait(dev, "bus reset", PCIE_RESET_READY_POLL_MS);
4549} 4549}
4550EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset);
4550 4551
4551static int pci_parent_bus_reset(struct pci_dev *dev, int probe) 4552static int pci_parent_bus_reset(struct pci_dev *dev, int probe)
4552{ 4553{
@@ -5200,7 +5201,7 @@ static int __pci_reset_bus(struct pci_bus *bus)
5200 */ 5201 */
5201int pci_reset_bus(struct pci_dev *pdev) 5202int pci_reset_bus(struct pci_dev *pdev)
5202{ 5203{
5203 return pci_probe_reset_slot(pdev->slot) ? 5204 return (!pci_probe_reset_slot(pdev->slot)) ?
5204 __pci_reset_slot(pdev->slot) : __pci_reset_bus(pdev->bus); 5205 __pci_reset_slot(pdev->slot) : __pci_reset_bus(pdev->bus);
5205} 5206}
5206EXPORT_SYMBOL_GPL(pci_reset_bus); 5207EXPORT_SYMBOL_GPL(pci_reset_bus);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ec784009a36b..201f9e5ff55c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2074,6 +2074,7 @@ static void pci_configure_eetlp_prefix(struct pci_dev *dev)
2074{ 2074{
2075#ifdef CONFIG_PCI_PASID 2075#ifdef CONFIG_PCI_PASID
2076 struct pci_dev *bridge; 2076 struct pci_dev *bridge;
2077 int pcie_type;
2077 u32 cap; 2078 u32 cap;
2078 2079
2079 if (!pci_is_pcie(dev)) 2080 if (!pci_is_pcie(dev))
@@ -2083,7 +2084,9 @@ static void pci_configure_eetlp_prefix(struct pci_dev *dev)
2083 if (!(cap & PCI_EXP_DEVCAP2_EE_PREFIX)) 2084 if (!(cap & PCI_EXP_DEVCAP2_EE_PREFIX))
2084 return; 2085 return;
2085 2086
2086 if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) 2087 pcie_type = pci_pcie_type(dev);
2088 if (pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
2089 pcie_type == PCI_EXP_TYPE_RC_END)
2087 dev->eetlp_prefix_path = 1; 2090 dev->eetlp_prefix_path = 1;
2088 else { 2091 else {
2089 bridge = pci_upstream_bridge(dev); 2092 bridge = pci_upstream_bridge(dev);
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index ef7143a274e0..6bc27b7fd452 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -4355,11 +4355,6 @@ static int pci_quirk_qcom_rp_acs(struct pci_dev *dev, u16 acs_flags)
4355 * 4355 *
4356 * 0x9d10-0x9d1b PCI Express Root port #{1-12} 4356 * 0x9d10-0x9d1b PCI Express Root port #{1-12}
4357 * 4357 *
4358 * The 300 series chipset suffers from the same bug so include those root
4359 * ports here as well.
4360 *
4361 * 0xa32c-0xa343 PCI Express Root port #{0-24}
4362 *
4363 * [1] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-2.html 4358 * [1] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-2.html
4364 * [2] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-1.html 4359 * [2] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-1.html
4365 * [3] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-spec-update.html 4360 * [3] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-spec-update.html
@@ -4377,7 +4372,6 @@ static bool pci_quirk_intel_spt_pch_acs_match(struct pci_dev *dev)
4377 case 0xa110 ... 0xa11f: case 0xa167 ... 0xa16a: /* Sunrise Point */ 4372 case 0xa110 ... 0xa11f: case 0xa167 ... 0xa16a: /* Sunrise Point */
4378 case 0xa290 ... 0xa29f: case 0xa2e7 ... 0xa2ee: /* Union Point */ 4373 case 0xa290 ... 0xa29f: case 0xa2e7 ... 0xa2ee: /* Union Point */
4379 case 0x9d10 ... 0x9d1b: /* 7th & 8th Gen Mobile */ 4374 case 0x9d10 ... 0x9d1b: /* 7th & 8th Gen Mobile */
4380 case 0xa32c ... 0xa343: /* 300 series */
4381 return true; 4375 return true;
4382 } 4376 }
4383 4377
diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index 9940cc70f38b..54a8b30dda38 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -14,6 +14,8 @@
14#include <linux/poll.h> 14#include <linux/poll.h>
15#include <linux/wait.h> 15#include <linux/wait.h>
16 16
17#include <linux/nospec.h>
18
17MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver"); 19MODULE_DESCRIPTION("Microsemi Switchtec(tm) PCIe Management Driver");
18MODULE_VERSION("0.1"); 20MODULE_VERSION("0.1");
19MODULE_LICENSE("GPL"); 21MODULE_LICENSE("GPL");
@@ -909,6 +911,8 @@ static int ioctl_port_to_pff(struct switchtec_dev *stdev,
909 default: 911 default:
910 if (p.port > ARRAY_SIZE(pcfg->dsp_pff_inst_id)) 912 if (p.port > ARRAY_SIZE(pcfg->dsp_pff_inst_id))
911 return -EINVAL; 913 return -EINVAL;
914 p.port = array_index_nospec(p.port,
915 ARRAY_SIZE(pcfg->dsp_pff_inst_id) + 1);
912 p.pff = ioread32(&pcfg->dsp_pff_inst_id[p.port - 1]); 916 p.pff = ioread32(&pcfg->dsp_pff_inst_id[p.port - 1]);
913 break; 917 break;
914 } 918 }
diff --git a/drivers/pinctrl/cirrus/pinctrl-madera-core.c b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
index ece41fb2848f..c4f4d904e4a6 100644
--- a/drivers/pinctrl/cirrus/pinctrl-madera-core.c
+++ b/drivers/pinctrl/cirrus/pinctrl-madera-core.c
@@ -1040,7 +1040,7 @@ static int madera_pin_probe(struct platform_device *pdev)
1040 } 1040 }
1041 1041
1042 /* if the configuration is provided through pdata, apply it */ 1042 /* if the configuration is provided through pdata, apply it */
1043 if (pdata) { 1043 if (pdata && pdata->gpio_configs) {
1044 ret = pinctrl_register_mappings(pdata->gpio_configs, 1044 ret = pinctrl_register_mappings(pdata->gpio_configs,
1045 pdata->n_gpio_configs); 1045 pdata->n_gpio_configs);
1046 if (ret) { 1046 if (ret) {
diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c
index 6a1b6058b991..628817c40e3b 100644
--- a/drivers/pinctrl/pinctrl-ingenic.c
+++ b/drivers/pinctrl/pinctrl-ingenic.c
@@ -793,7 +793,7 @@ static int ingenic_pinctrl_probe(struct platform_device *pdev)
793 793
794 err = pinctrl_generic_add_group(jzpc->pctl, group->name, 794 err = pinctrl_generic_add_group(jzpc->pctl, group->name,
795 group->pins, group->num_pins, group->data); 795 group->pins, group->num_pins, group->data);
796 if (err) { 796 if (err < 0) {
797 dev_err(dev, "Failed to register group %s\n", 797 dev_err(dev, "Failed to register group %s\n",
798 group->name); 798 group->name);
799 return err; 799 return err;
@@ -806,7 +806,7 @@ static int ingenic_pinctrl_probe(struct platform_device *pdev)
806 err = pinmux_generic_add_function(jzpc->pctl, func->name, 806 err = pinmux_generic_add_function(jzpc->pctl, func->name,
807 func->group_names, func->num_group_names, 807 func->group_names, func->num_group_names,
808 func->data); 808 func->data);
809 if (err) { 809 if (err < 0) {
810 dev_err(dev, "Failed to register function %s\n", 810 dev_err(dev, "Failed to register function %s\n",
811 func->name); 811 func->name);
812 return err; 812 return err;
diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c
index 2155a30c282b..5d72ffad32c2 100644
--- a/drivers/pinctrl/qcom/pinctrl-msm.c
+++ b/drivers/pinctrl/qcom/pinctrl-msm.c
@@ -634,6 +634,29 @@ static void msm_gpio_irq_mask(struct irq_data *d)
634 raw_spin_lock_irqsave(&pctrl->lock, flags); 634 raw_spin_lock_irqsave(&pctrl->lock, flags);
635 635
636 val = readl(pctrl->regs + g->intr_cfg_reg); 636 val = readl(pctrl->regs + g->intr_cfg_reg);
637 /*
638 * There are two bits that control interrupt forwarding to the CPU. The
639 * RAW_STATUS_EN bit causes the level or edge sensed on the line to be
640 * latched into the interrupt status register when the hardware detects
641 * an irq that it's configured for (either edge for edge type or level
642 * for level type irq). The 'non-raw' status enable bit causes the
643 * hardware to assert the summary interrupt to the CPU if the latched
644 * status bit is set. There's a bug though, the edge detection logic
645 * seems to have a problem where toggling the RAW_STATUS_EN bit may
646 * cause the status bit to latch spuriously when there isn't any edge
647 * so we can't touch that bit for edge type irqs and we have to keep
648 * the bit set anyway so that edges are latched while the line is masked.
649 *
650 * To make matters more complicated, leaving the RAW_STATUS_EN bit
651 * enabled all the time causes level interrupts to re-latch into the
652 * status register because the level is still present on the line after
653 * we ack it. We clear the raw status enable bit during mask here and
654 * set the bit on unmask so the interrupt can't latch into the hardware
655 * while it's masked.
656 */
657 if (irqd_get_trigger_type(d) & IRQ_TYPE_LEVEL_MASK)
658 val &= ~BIT(g->intr_raw_status_bit);
659
637 val &= ~BIT(g->intr_enable_bit); 660 val &= ~BIT(g->intr_enable_bit);
638 writel(val, pctrl->regs + g->intr_cfg_reg); 661 writel(val, pctrl->regs + g->intr_cfg_reg);
639 662
@@ -655,6 +678,7 @@ static void msm_gpio_irq_unmask(struct irq_data *d)
655 raw_spin_lock_irqsave(&pctrl->lock, flags); 678 raw_spin_lock_irqsave(&pctrl->lock, flags);
656 679
657 val = readl(pctrl->regs + g->intr_cfg_reg); 680 val = readl(pctrl->regs + g->intr_cfg_reg);
681 val |= BIT(g->intr_raw_status_bit);
658 val |= BIT(g->intr_enable_bit); 682 val |= BIT(g->intr_enable_bit);
659 writel(val, pctrl->regs + g->intr_cfg_reg); 683 writel(val, pctrl->regs + g->intr_cfg_reg);
660 684
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index a70262cb7e56..13d28fdbdbb5 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -73,6 +73,13 @@ config RESET_MESON
73 help 73 help
74 This enables the reset driver for Amlogic Meson SoCs. 74 This enables the reset driver for Amlogic Meson SoCs.
75 75
76config RESET_MESON_AUDIO_ARB
77 tristate "Meson Audio Memory Arbiter Reset Driver"
78 depends on ARCH_MESON || COMPILE_TEST
79 help
80 This enables the reset driver for Audio Memory Arbiter of
81 Amlogic's A113 based SoCs
82
76config RESET_OXNAS 83config RESET_OXNAS
77 bool 84 bool
78 85
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 0676b6b1976f..4243c38228e2 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
12obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o 12obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o
13obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o 13obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o
14obj-$(CONFIG_RESET_MESON) += reset-meson.o 14obj-$(CONFIG_RESET_MESON) += reset-meson.o
15obj-$(CONFIG_RESET_MESON_AUDIO_ARB) += reset-meson-audio-arb.o
15obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o 16obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o
16obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o 17obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o
17obj-$(CONFIG_RESET_QCOM_AOSS) += reset-qcom-aoss.o 18obj-$(CONFIG_RESET_QCOM_AOSS) += reset-qcom-aoss.o
diff --git a/drivers/reset/reset-imx7.c b/drivers/reset/reset-imx7.c
index 14bc78d28707..97d9f08271c5 100644
--- a/drivers/reset/reset-imx7.c
+++ b/drivers/reset/reset-imx7.c
@@ -81,7 +81,7 @@ static int imx7_reset_set(struct reset_controller_dev *rcdev,
81{ 81{
82 struct imx7_src *imx7src = to_imx7_src(rcdev); 82 struct imx7_src *imx7src = to_imx7_src(rcdev);
83 const struct imx7_src_signal *signal = &imx7_src_signals[id]; 83 const struct imx7_src_signal *signal = &imx7_src_signals[id];
84 unsigned int value = 0; 84 unsigned int value = assert ? signal->bit : 0;
85 85
86 switch (id) { 86 switch (id) {
87 case IMX7_RESET_PCIEPHY: 87 case IMX7_RESET_PCIEPHY:
diff --git a/drivers/reset/reset-meson-audio-arb.c b/drivers/reset/reset-meson-audio-arb.c
new file mode 100644
index 000000000000..91751617b37a
--- /dev/null
+++ b/drivers/reset/reset-meson-audio-arb.c
@@ -0,0 +1,168 @@
1// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2// Copyright (c) 2018 BayLibre, SAS.
3// Author: Jerome Brunet <jbrunet@baylibre.com>
4
5#include <linux/clk.h>
6#include <linux/io.h>
7#include <linux/module.h>
8#include <linux/of_platform.h>
9#include <linux/reset-controller.h>
10#include <linux/spinlock.h>
11
12#include <dt-bindings/reset/amlogic,meson-axg-audio-arb.h>
13
14struct meson_audio_arb_data {
15 struct reset_controller_dev rstc;
16 void __iomem *regs;
17 struct clk *clk;
18 const unsigned int *reset_bits;
19 spinlock_t lock;
20};
21
22#define ARB_GENERAL_BIT 31
23
24static const unsigned int axg_audio_arb_reset_bits[] = {
25 [AXG_ARB_TODDR_A] = 0,
26 [AXG_ARB_TODDR_B] = 1,
27 [AXG_ARB_TODDR_C] = 2,
28 [AXG_ARB_FRDDR_A] = 4,
29 [AXG_ARB_FRDDR_B] = 5,
30 [AXG_ARB_FRDDR_C] = 6,
31};
32
33static int meson_audio_arb_update(struct reset_controller_dev *rcdev,
34 unsigned long id, bool assert)
35{
36 u32 val;
37 struct meson_audio_arb_data *arb =
38 container_of(rcdev, struct meson_audio_arb_data, rstc);
39
40 spin_lock(&arb->lock);
41 val = readl(arb->regs);
42
43 if (assert)
44 val &= ~BIT(arb->reset_bits[id]);
45 else
46 val |= BIT(arb->reset_bits[id]);
47
48 writel(val, arb->regs);
49 spin_unlock(&arb->lock);
50
51 return 0;
52}
53
54static int meson_audio_arb_status(struct reset_controller_dev *rcdev,
55 unsigned long id)
56{
57 u32 val;
58 struct meson_audio_arb_data *arb =
59 container_of(rcdev, struct meson_audio_arb_data, rstc);
60
61 val = readl(arb->regs);
62
63 return !(val & BIT(arb->reset_bits[id]));
64}
65
66static int meson_audio_arb_assert(struct reset_controller_dev *rcdev,
67 unsigned long id)
68{
69 return meson_audio_arb_update(rcdev, id, true);
70}
71
72static int meson_audio_arb_deassert(struct reset_controller_dev *rcdev,
73 unsigned long id)
74{
75 return meson_audio_arb_update(rcdev, id, false);
76}
77
78static const struct reset_control_ops meson_audio_arb_rstc_ops = {
79 .assert = meson_audio_arb_assert,
80 .deassert = meson_audio_arb_deassert,
81 .status = meson_audio_arb_status,
82};
83
84static const struct of_device_id meson_audio_arb_of_match[] = {
85 { .compatible = "amlogic,meson-axg-audio-arb", },
86 {}
87};
88MODULE_DEVICE_TABLE(of, meson_audio_arb_of_match);
89
90static int meson_audio_arb_remove(struct platform_device *pdev)
91{
92 struct meson_audio_arb_data *arb = platform_get_drvdata(pdev);
93
94 /* Disable all access */
95 spin_lock(&arb->lock);
96 writel(0, arb->regs);
97 spin_unlock(&arb->lock);
98
99 clk_disable_unprepare(arb->clk);
100
101 return 0;
102}
103
104static int meson_audio_arb_probe(struct platform_device *pdev)
105{
106 struct device *dev = &pdev->dev;
107 struct meson_audio_arb_data *arb;
108 struct resource *res;
109 int ret;
110
111 arb = devm_kzalloc(dev, sizeof(*arb), GFP_KERNEL);
112 if (!arb)
113 return -ENOMEM;
114 platform_set_drvdata(pdev, arb);
115
116 arb->clk = devm_clk_get(dev, NULL);
117 if (IS_ERR(arb->clk)) {
118 if (PTR_ERR(arb->clk) != -EPROBE_DEFER)
119 dev_err(dev, "failed to get clock\n");
120 return PTR_ERR(arb->clk);
121 }
122
123 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 arb->regs = devm_ioremap_resource(dev, res);
125 if (IS_ERR(arb->regs))
126 return PTR_ERR(arb->regs);
127
128 spin_lock_init(&arb->lock);
129 arb->reset_bits = axg_audio_arb_reset_bits;
130 arb->rstc.nr_resets = ARRAY_SIZE(axg_audio_arb_reset_bits);
131 arb->rstc.ops = &meson_audio_arb_rstc_ops;
132 arb->rstc.of_node = dev->of_node;
133
134 /*
135 * Enable general :
136 * In the initial state, all memory interfaces are disabled
137 * and the general bit is on
138 */
139 ret = clk_prepare_enable(arb->clk);
140 if (ret) {
141 dev_err(dev, "failed to enable arb clock\n");
142 return ret;
143 }
144 writel(BIT(ARB_GENERAL_BIT), arb->regs);
145
146 /* Register reset controller */
147 ret = devm_reset_controller_register(dev, &arb->rstc);
148 if (ret) {
149 dev_err(dev, "failed to register arb reset controller\n");
150 meson_audio_arb_remove(pdev);
151 }
152
153 return ret;
154}
155
156static struct platform_driver meson_audio_arb_pdrv = {
157 .probe = meson_audio_arb_probe,
158 .remove = meson_audio_arb_remove,
159 .driver = {
160 .name = "meson-audio-arb-reset",
161 .of_match_table = meson_audio_arb_of_match,
162 },
163};
164module_platform_driver(meson_audio_arb_pdrv);
165
166MODULE_DESCRIPTION("Amlogic A113 Audio Memory Arbiter");
167MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
168MODULE_LICENSE("GPL v2");
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index ed607288e696..23e526cda5c1 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -922,9 +922,11 @@ __dcssblk_direct_access(struct dcssblk_dev_info *dev_info, pgoff_t pgoff,
922 unsigned long dev_sz; 922 unsigned long dev_sz;
923 923
924 dev_sz = dev_info->end - dev_info->start + 1; 924 dev_sz = dev_info->end - dev_info->start + 1;
925 *kaddr = (void *) dev_info->start + offset; 925 if (kaddr)
926 *pfn = __pfn_to_pfn_t(PFN_DOWN(dev_info->start + offset), 926 *kaddr = (void *) dev_info->start + offset;
927 PFN_DEV|PFN_SPECIAL); 927 if (pfn)
928 *pfn = __pfn_to_pfn_t(PFN_DOWN(dev_info->start + offset),
929 PFN_DEV|PFN_SPECIAL);
928 930
929 return (dev_sz - offset) / PAGE_SIZE; 931 return (dev_sz - offset) / PAGE_SIZE;
930} 932}
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index ec891bc7d10a..f039266b275d 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -872,8 +872,6 @@ static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
872 if (bits & 0x07) 872 if (bits & 0x07)
873 return -EINVAL; 873 return -EINVAL;
874 874
875 memset(bitmap, 0, bits / 8);
876
877 if (str[0] == '0' && str[1] == 'x') 875 if (str[0] == '0' && str[1] == 'x')
878 str++; 876 str++;
879 if (*str == 'x') 877 if (*str == 'x')
@@ -895,25 +893,23 @@ static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
895} 893}
896 894
897/* 895/*
898 * str2clrsetmasks() - parse bitmask argument and set the clear and 896 * modify_bitmap() - parse bitmask argument and modify an existing
899 * the set bitmap mask. A concatenation (done with ',') of these terms 897 * bit mask accordingly. A concatenation (done with ',') of these
900 * is recognized: 898 * terms is recognized:
901 * +<bitnr>[-<bitnr>] or -<bitnr>[-<bitnr>] 899 * +<bitnr>[-<bitnr>] or -<bitnr>[-<bitnr>]
902 * <bitnr> may be any valid number (hex, decimal or octal) in the range 900 * <bitnr> may be any valid number (hex, decimal or octal) in the range
903 * 0...bits-1; the leading + or - is required. Here are some examples: 901 * 0...bits-1; the leading + or - is required. Here are some examples:
904 * +0-15,+32,-128,-0xFF 902 * +0-15,+32,-128,-0xFF
905 * -0-255,+1-16,+0x128 903 * -0-255,+1-16,+0x128
906 * +1,+2,+3,+4,-5,-7-10 904 * +1,+2,+3,+4,-5,-7-10
907 * Returns a clear and a set bitmask. Every positive value in the string 905 * Returns the new bitmap after all changes have been applied. Every
908 * results in a bit set in the set mask and every negative value in the 906 * positive value in the string will set a bit and every negative value
909 * string results in a bit SET in the clear mask. As a bit may be touched 907 * in the string will clear a bit. As a bit may be touched more than once,
910 * more than once, the last 'operation' wins: +0-255,-128 = all but bit 908 * the last 'operation' wins:
911 * 128 set in the set mask, only bit 128 set in the clear mask. 909 * +0-255,-128 = first bits 0-255 will be set, then bit 128 will be
910 * cleared again. All other bits are unmodified.
912 */ 911 */
913static int str2clrsetmasks(const char *str, 912static int modify_bitmap(const char *str, unsigned long *bitmap, int bits)
914 unsigned long *clrmap,
915 unsigned long *setmap,
916 int bits)
917{ 913{
918 int a, i, z; 914 int a, i, z;
919 char *np, sign; 915 char *np, sign;
@@ -922,9 +918,6 @@ static int str2clrsetmasks(const char *str,
922 if (bits & 0x07) 918 if (bits & 0x07)
923 return -EINVAL; 919 return -EINVAL;
924 920
925 memset(clrmap, 0, bits / 8);
926 memset(setmap, 0, bits / 8);
927
928 while (*str) { 921 while (*str) {
929 sign = *str++; 922 sign = *str++;
930 if (sign != '+' && sign != '-') 923 if (sign != '+' && sign != '-')
@@ -940,13 +933,10 @@ static int str2clrsetmasks(const char *str,
940 str = np; 933 str = np;
941 } 934 }
942 for (i = a; i <= z; i++) 935 for (i = a; i <= z; i++)
943 if (sign == '+') { 936 if (sign == '+')
944 set_bit_inv(i, setmap); 937 set_bit_inv(i, bitmap);
945 clear_bit_inv(i, clrmap); 938 else
946 } else { 939 clear_bit_inv(i, bitmap);
947 clear_bit_inv(i, setmap);
948 set_bit_inv(i, clrmap);
949 }
950 while (*str == ',' || *str == '\n') 940 while (*str == ',' || *str == '\n')
951 str++; 941 str++;
952 } 942 }
@@ -970,44 +960,34 @@ static int process_mask_arg(const char *str,
970 unsigned long *bitmap, int bits, 960 unsigned long *bitmap, int bits,
971 struct mutex *lock) 961 struct mutex *lock)
972{ 962{
973 int i; 963 unsigned long *newmap, size;
964 int rc;
974 965
975 /* bits needs to be a multiple of 8 */ 966 /* bits needs to be a multiple of 8 */
976 if (bits & 0x07) 967 if (bits & 0x07)
977 return -EINVAL; 968 return -EINVAL;
978 969
970 size = BITS_TO_LONGS(bits)*sizeof(unsigned long);
971 newmap = kmalloc(size, GFP_KERNEL);
972 if (!newmap)
973 return -ENOMEM;
974 if (mutex_lock_interruptible(lock)) {
975 kfree(newmap);
976 return -ERESTARTSYS;
977 }
978
979 if (*str == '+' || *str == '-') { 979 if (*str == '+' || *str == '-') {
980 DECLARE_BITMAP(clrm, bits); 980 memcpy(newmap, bitmap, size);
981 DECLARE_BITMAP(setm, bits); 981 rc = modify_bitmap(str, newmap, bits);
982
983 i = str2clrsetmasks(str, clrm, setm, bits);
984 if (i)
985 return i;
986 if (mutex_lock_interruptible(lock))
987 return -ERESTARTSYS;
988 for (i = 0; i < bits; i++) {
989 if (test_bit_inv(i, clrm))
990 clear_bit_inv(i, bitmap);
991 if (test_bit_inv(i, setm))
992 set_bit_inv(i, bitmap);
993 }
994 } else { 982 } else {
995 DECLARE_BITMAP(setm, bits); 983 memset(newmap, 0, size);
996 984 rc = hex2bitmap(str, newmap, bits);
997 i = hex2bitmap(str, setm, bits);
998 if (i)
999 return i;
1000 if (mutex_lock_interruptible(lock))
1001 return -ERESTARTSYS;
1002 for (i = 0; i < bits; i++)
1003 if (test_bit_inv(i, setm))
1004 set_bit_inv(i, bitmap);
1005 else
1006 clear_bit_inv(i, bitmap);
1007 } 985 }
986 if (rc == 0)
987 memcpy(bitmap, newmap, size);
1008 mutex_unlock(lock); 988 mutex_unlock(lock);
1009 989 kfree(newmap);
1010 return 0; 990 return rc;
1011} 991}
1012 992
1013/* 993/*
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 49f64eb3eab0..de8282420f96 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -25,6 +25,7 @@
25#include <linux/netdevice.h> 25#include <linux/netdevice.h>
26#include <linux/netdev_features.h> 26#include <linux/netdev_features.h>
27#include <linux/skbuff.h> 27#include <linux/skbuff.h>
28#include <linux/vmalloc.h>
28 29
29#include <net/iucv/af_iucv.h> 30#include <net/iucv/af_iucv.h>
30#include <net/dsfield.h> 31#include <net/dsfield.h>
@@ -4699,7 +4700,7 @@ static int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
4699 4700
4700 priv.buffer_len = oat_data.buffer_len; 4701 priv.buffer_len = oat_data.buffer_len;
4701 priv.response_len = 0; 4702 priv.response_len = 0;
4702 priv.buffer = kzalloc(oat_data.buffer_len, GFP_KERNEL); 4703 priv.buffer = vzalloc(oat_data.buffer_len);
4703 if (!priv.buffer) { 4704 if (!priv.buffer) {
4704 rc = -ENOMEM; 4705 rc = -ENOMEM;
4705 goto out; 4706 goto out;
@@ -4740,7 +4741,7 @@ static int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
4740 rc = -EFAULT; 4741 rc = -EFAULT;
4741 4742
4742out_free: 4743out_free:
4743 kfree(priv.buffer); 4744 vfree(priv.buffer);
4744out: 4745out:
4745 return rc; 4746 return rc;
4746} 4747}
@@ -5706,6 +5707,8 @@ static struct net_device *qeth_alloc_netdev(struct qeth_card *card)
5706 dev->priv_flags &= ~IFF_TX_SKB_SHARING; 5707 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
5707 dev->hw_features |= NETIF_F_SG; 5708 dev->hw_features |= NETIF_F_SG;
5708 dev->vlan_features |= NETIF_F_SG; 5709 dev->vlan_features |= NETIF_F_SG;
5710 if (IS_IQD(card))
5711 dev->features |= NETIF_F_SG;
5709 } 5712 }
5710 5713
5711 return dev; 5714 return dev;
@@ -5768,8 +5771,10 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev)
5768 qeth_update_from_chp_desc(card); 5771 qeth_update_from_chp_desc(card);
5769 5772
5770 card->dev = qeth_alloc_netdev(card); 5773 card->dev = qeth_alloc_netdev(card);
5771 if (!card->dev) 5774 if (!card->dev) {
5775 rc = -ENOMEM;
5772 goto err_card; 5776 goto err_card;
5777 }
5773 5778
5774 qeth_determine_capabilities(card); 5779 qeth_determine_capabilities(card);
5775 enforced_disc = qeth_enforce_discipline(card); 5780 enforced_disc = qeth_enforce_discipline(card);
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 710fa74892ae..b5e38531733f 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -423,7 +423,7 @@ static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
423 default: 423 default:
424 dev_kfree_skb_any(skb); 424 dev_kfree_skb_any(skb);
425 QETH_CARD_TEXT(card, 3, "inbunkno"); 425 QETH_CARD_TEXT(card, 3, "inbunkno");
426 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); 426 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
427 continue; 427 continue;
428 } 428 }
429 work_done++; 429 work_done++;
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 7175086677fb..ada258c01a08 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -1390,7 +1390,7 @@ static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
1390 default: 1390 default:
1391 dev_kfree_skb_any(skb); 1391 dev_kfree_skb_any(skb);
1392 QETH_CARD_TEXT(card, 3, "inbunkno"); 1392 QETH_CARD_TEXT(card, 3, "inbunkno");
1393 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); 1393 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
1394 continue; 1394 continue;
1395 } 1395 }
1396 work_done++; 1396 work_done++;
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 8fc851a9e116..7c097006c54d 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -52,12 +52,12 @@ config SCSI_MQ_DEFAULT
52 default y 52 default y
53 depends on SCSI 53 depends on SCSI
54 ---help--- 54 ---help---
55 This option enables the new blk-mq based I/O path for SCSI 55 This option enables the blk-mq based I/O path for SCSI devices by
56 devices by default. With the option the scsi_mod.use_blk_mq 56 default. With this option the scsi_mod.use_blk_mq module/boot
57 module/boot option defaults to Y, without it to N, but it can 57 option defaults to Y, without it to N, but it can still be
58 still be overridden either way. 58 overridden either way.
59 59
60 If unsure say N. 60 If unsure say Y.
61 61
62config SCSI_PROC_FS 62config SCSI_PROC_FS
63 bool "legacy /proc/scsi/ support" 63 bool "legacy /proc/scsi/ support"
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index 29bf1e60f542..39eb415987fc 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -1346,7 +1346,7 @@ struct fib {
1346struct aac_hba_map_info { 1346struct aac_hba_map_info {
1347 __le32 rmw_nexus; /* nexus for native HBA devices */ 1347 __le32 rmw_nexus; /* nexus for native HBA devices */
1348 u8 devtype; /* device type */ 1348 u8 devtype; /* device type */
1349 u8 reset_state; /* 0 - no reset, 1..x - */ 1349 s8 reset_state; /* 0 - no reset, 1..x - */
1350 /* after xth TM LUN reset */ 1350 /* after xth TM LUN reset */
1351 u16 qd_limit; 1351 u16 qd_limit;
1352 u32 scan_counter; 1352 u32 scan_counter;
diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c
index 23d07e9f87d0..e51923886475 100644
--- a/drivers/scsi/csiostor/csio_hw.c
+++ b/drivers/scsi/csiostor/csio_hw.c
@@ -1602,6 +1602,46 @@ fw_port_cap32_t fwcaps16_to_caps32(fw_port_cap16_t caps16)
1602} 1602}
1603 1603
1604/** 1604/**
1605 * fwcaps32_to_caps16 - convert 32-bit Port Capabilities to 16-bits
1606 * @caps32: a 32-bit Port Capabilities value
1607 *
1608 * Returns the equivalent 16-bit Port Capabilities value. Note that
1609 * not all 32-bit Port Capabilities can be represented in the 16-bit
1610 * Port Capabilities and some fields/values may not make it.
1611 */
1612fw_port_cap16_t fwcaps32_to_caps16(fw_port_cap32_t caps32)
1613{
1614 fw_port_cap16_t caps16 = 0;
1615
1616 #define CAP32_TO_CAP16(__cap) \
1617 do { \
1618 if (caps32 & FW_PORT_CAP32_##__cap) \
1619 caps16 |= FW_PORT_CAP_##__cap; \
1620 } while (0)
1621
1622 CAP32_TO_CAP16(SPEED_100M);
1623 CAP32_TO_CAP16(SPEED_1G);
1624 CAP32_TO_CAP16(SPEED_10G);
1625 CAP32_TO_CAP16(SPEED_25G);
1626 CAP32_TO_CAP16(SPEED_40G);
1627 CAP32_TO_CAP16(SPEED_100G);
1628 CAP32_TO_CAP16(FC_RX);
1629 CAP32_TO_CAP16(FC_TX);
1630 CAP32_TO_CAP16(802_3_PAUSE);
1631 CAP32_TO_CAP16(802_3_ASM_DIR);
1632 CAP32_TO_CAP16(ANEG);
1633 CAP32_TO_CAP16(FORCE_PAUSE);
1634 CAP32_TO_CAP16(MDIAUTO);
1635 CAP32_TO_CAP16(MDISTRAIGHT);
1636 CAP32_TO_CAP16(FEC_RS);
1637 CAP32_TO_CAP16(FEC_BASER_RS);
1638
1639 #undef CAP32_TO_CAP16
1640
1641 return caps16;
1642}
1643
1644/**
1605 * lstatus_to_fwcap - translate old lstatus to 32-bit Port Capabilities 1645 * lstatus_to_fwcap - translate old lstatus to 32-bit Port Capabilities
1606 * @lstatus: old FW_PORT_ACTION_GET_PORT_INFO lstatus value 1646 * @lstatus: old FW_PORT_ACTION_GET_PORT_INFO lstatus value
1607 * 1647 *
@@ -1759,7 +1799,7 @@ csio_enable_ports(struct csio_hw *hw)
1759 val = 1; 1799 val = 1;
1760 1800
1761 csio_mb_params(hw, mbp, CSIO_MB_DEFAULT_TMO, 1801 csio_mb_params(hw, mbp, CSIO_MB_DEFAULT_TMO,
1762 hw->pfn, 0, 1, &param, &val, false, 1802 hw->pfn, 0, 1, &param, &val, true,
1763 NULL); 1803 NULL);
1764 1804
1765 if (csio_mb_issue(hw, mbp)) { 1805 if (csio_mb_issue(hw, mbp)) {
@@ -1769,16 +1809,9 @@ csio_enable_ports(struct csio_hw *hw)
1769 return -EINVAL; 1809 return -EINVAL;
1770 } 1810 }
1771 1811
1772 csio_mb_process_read_params_rsp(hw, mbp, &retval, 1, 1812 csio_mb_process_read_params_rsp(hw, mbp, &retval,
1773 &val); 1813 0, NULL);
1774 if (retval != FW_SUCCESS) { 1814 fw_caps = retval ? FW_CAPS16 : FW_CAPS32;
1775 csio_err(hw, "FW_PARAMS_CMD(r) port:%d failed: 0x%x\n",
1776 portid, retval);
1777 mempool_free(mbp, hw->mb_mempool);
1778 return -EINVAL;
1779 }
1780
1781 fw_caps = val;
1782 } 1815 }
1783 1816
1784 /* Read PORT information */ 1817 /* Read PORT information */
@@ -2364,8 +2397,8 @@ bye:
2364} 2397}
2365 2398
2366/* 2399/*
2367 * Returns -EINVAL if attempts to flash the firmware failed 2400 * Returns -EINVAL if attempts to flash the firmware failed,
2368 * else returns 0, 2401 * -ENOMEM if memory allocation failed else returns 0,
2369 * if flashing was not attempted because the card had the 2402 * if flashing was not attempted because the card had the
2370 * latest firmware ECANCELED is returned 2403 * latest firmware ECANCELED is returned
2371 */ 2404 */
@@ -2393,6 +2426,13 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
2393 return -EINVAL; 2426 return -EINVAL;
2394 } 2427 }
2395 2428
2429 /* allocate memory to read the header of the firmware on the
2430 * card
2431 */
2432 card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL);
2433 if (!card_fw)
2434 return -ENOMEM;
2435
2396 if (csio_is_t5(pci_dev->device & CSIO_HW_CHIP_MASK)) 2436 if (csio_is_t5(pci_dev->device & CSIO_HW_CHIP_MASK))
2397 fw_bin_file = FW_FNAME_T5; 2437 fw_bin_file = FW_FNAME_T5;
2398 else 2438 else
@@ -2406,11 +2446,6 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
2406 fw_size = fw->size; 2446 fw_size = fw->size;
2407 } 2447 }
2408 2448
2409 /* allocate memory to read the header of the firmware on the
2410 * card
2411 */
2412 card_fw = kmalloc(sizeof(*card_fw), GFP_KERNEL);
2413
2414 /* upgrade FW logic */ 2449 /* upgrade FW logic */
2415 ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw, 2450 ret = csio_hw_prep_fw(hw, fw_info, fw_data, fw_size, card_fw,
2416 hw->fw_state, reset); 2451 hw->fw_state, reset);
diff --git a/drivers/scsi/csiostor/csio_hw.h b/drivers/scsi/csiostor/csio_hw.h
index 9e73ef771eb7..e351af6e7c81 100644
--- a/drivers/scsi/csiostor/csio_hw.h
+++ b/drivers/scsi/csiostor/csio_hw.h
@@ -639,6 +639,7 @@ int csio_handle_intr_status(struct csio_hw *, unsigned int,
639 639
640fw_port_cap32_t fwcap_to_fwspeed(fw_port_cap32_t acaps); 640fw_port_cap32_t fwcap_to_fwspeed(fw_port_cap32_t acaps);
641fw_port_cap32_t fwcaps16_to_caps32(fw_port_cap16_t caps16); 641fw_port_cap32_t fwcaps16_to_caps32(fw_port_cap16_t caps16);
642fw_port_cap16_t fwcaps32_to_caps16(fw_port_cap32_t caps32);
642fw_port_cap32_t lstatus_to_fwcap(u32 lstatus); 643fw_port_cap32_t lstatus_to_fwcap(u32 lstatus);
643 644
644int csio_hw_start(struct csio_hw *); 645int csio_hw_start(struct csio_hw *);
diff --git a/drivers/scsi/csiostor/csio_mb.c b/drivers/scsi/csiostor/csio_mb.c
index c026417269c3..6f13673d6aa0 100644
--- a/drivers/scsi/csiostor/csio_mb.c
+++ b/drivers/scsi/csiostor/csio_mb.c
@@ -368,7 +368,7 @@ csio_mb_port(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
368 FW_CMD_LEN16_V(sizeof(*cmdp) / 16)); 368 FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
369 369
370 if (fw_caps == FW_CAPS16) 370 if (fw_caps == FW_CAPS16)
371 cmdp->u.l1cfg.rcap = cpu_to_be32(fc); 371 cmdp->u.l1cfg.rcap = cpu_to_be32(fwcaps32_to_caps16(fc));
372 else 372 else
373 cmdp->u.l1cfg32.rcap32 = cpu_to_be32(fc); 373 cmdp->u.l1cfg32.rcap32 = cpu_to_be32(fc);
374} 374}
@@ -395,8 +395,8 @@ csio_mb_process_read_port_rsp(struct csio_hw *hw, struct csio_mb *mbp,
395 *pcaps = fwcaps16_to_caps32(ntohs(rsp->u.info.pcap)); 395 *pcaps = fwcaps16_to_caps32(ntohs(rsp->u.info.pcap));
396 *acaps = fwcaps16_to_caps32(ntohs(rsp->u.info.acap)); 396 *acaps = fwcaps16_to_caps32(ntohs(rsp->u.info.acap));
397 } else { 397 } else {
398 *pcaps = ntohs(rsp->u.info32.pcaps32); 398 *pcaps = be32_to_cpu(rsp->u.info32.pcaps32);
399 *acaps = ntohs(rsp->u.info32.acaps32); 399 *acaps = be32_to_cpu(rsp->u.info32.acaps32);
400 } 400 }
401 } 401 }
402} 402}
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index f02dcc875a09..ea4b0bb0c1cd 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -563,35 +563,13 @@ struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost)
563} 563}
564EXPORT_SYMBOL(scsi_host_get); 564EXPORT_SYMBOL(scsi_host_get);
565 565
566struct scsi_host_mq_in_flight {
567 int cnt;
568};
569
570static void scsi_host_check_in_flight(struct request *rq, void *data,
571 bool reserved)
572{
573 struct scsi_host_mq_in_flight *in_flight = data;
574
575 if (blk_mq_request_started(rq))
576 in_flight->cnt++;
577}
578
579/** 566/**
580 * scsi_host_busy - Return the host busy counter 567 * scsi_host_busy - Return the host busy counter
581 * @shost: Pointer to Scsi_Host to inc. 568 * @shost: Pointer to Scsi_Host to inc.
582 **/ 569 **/
583int scsi_host_busy(struct Scsi_Host *shost) 570int scsi_host_busy(struct Scsi_Host *shost)
584{ 571{
585 struct scsi_host_mq_in_flight in_flight = { 572 return atomic_read(&shost->host_busy);
586 .cnt = 0,
587 };
588
589 if (!shost->use_blk_mq)
590 return atomic_read(&shost->host_busy);
591
592 blk_mq_tagset_busy_iter(&shost->tag_set, scsi_host_check_in_flight,
593 &in_flight);
594 return in_flight.cnt;
595} 573}
596EXPORT_SYMBOL(scsi_host_busy); 574EXPORT_SYMBOL(scsi_host_busy);
597 575
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 58bb70b886d7..c120929d4ffe 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -976,7 +976,7 @@ static struct scsi_host_template hpsa_driver_template = {
976#endif 976#endif
977 .sdev_attrs = hpsa_sdev_attrs, 977 .sdev_attrs = hpsa_sdev_attrs,
978 .shost_attrs = hpsa_shost_attrs, 978 .shost_attrs = hpsa_shost_attrs,
979 .max_sectors = 1024, 979 .max_sectors = 2048,
980 .no_write_same = 1, 980 .no_write_same = 1,
981}; 981};
982 982
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index e0d0da5f43d6..43732e8d1347 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -672,7 +672,7 @@ struct lpfc_hba {
672#define LS_NPIV_FAB_SUPPORTED 0x2 /* Fabric supports NPIV */ 672#define LS_NPIV_FAB_SUPPORTED 0x2 /* Fabric supports NPIV */
673#define LS_IGNORE_ERATT 0x4 /* intr handler should ignore ERATT */ 673#define LS_IGNORE_ERATT 0x4 /* intr handler should ignore ERATT */
674#define LS_MDS_LINK_DOWN 0x8 /* MDS Diagnostics Link Down */ 674#define LS_MDS_LINK_DOWN 0x8 /* MDS Diagnostics Link Down */
675#define LS_MDS_LOOPBACK 0x16 /* MDS Diagnostics Link Up (Loopback) */ 675#define LS_MDS_LOOPBACK 0x10 /* MDS Diagnostics Link Up (Loopback) */
676 676
677 uint32_t hba_flag; /* hba generic flags */ 677 uint32_t hba_flag; /* hba generic flags */
678#define HBA_ERATT_HANDLED 0x1 /* This flag is set when eratt handled */ 678#define HBA_ERATT_HANDLED 0x1 /* This flag is set when eratt handled */
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 5a25553415f8..057a60abe664 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -5122,16 +5122,16 @@ LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5122 5122
5123/* 5123/*
5124# lpfc_fdmi_on: Controls FDMI support. 5124# lpfc_fdmi_on: Controls FDMI support.
5125# 0 No FDMI support (default) 5125# 0 No FDMI support
5126# 1 Traditional FDMI support 5126# 1 Traditional FDMI support (default)
5127# Traditional FDMI support means the driver will assume FDMI-2 support; 5127# Traditional FDMI support means the driver will assume FDMI-2 support;
5128# however, if that fails, it will fallback to FDMI-1. 5128# however, if that fails, it will fallback to FDMI-1.
5129# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on. 5129# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5130# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of 5130# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5131# lpfc_fdmi_on. 5131# lpfc_fdmi_on.
5132# Value range [0,1]. Default value is 0. 5132# Value range [0,1]. Default value is 1.
5133*/ 5133*/
5134LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support"); 5134LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5135 5135
5136/* 5136/*
5137# Specifies the maximum number of ELS cmds we can have outstanding (for 5137# Specifies the maximum number of ELS cmds we can have outstanding (for
diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c
index 0e56f1eb05dc..eaf36ccf58db 100644
--- a/drivers/scsi/osd/osd_uld.c
+++ b/drivers/scsi/osd/osd_uld.c
@@ -423,19 +423,11 @@ static int osd_probe(struct device *dev)
423 if (scsi_device->type != TYPE_OSD) 423 if (scsi_device->type != TYPE_OSD)
424 return -ENODEV; 424 return -ENODEV;
425 425
426 do { 426 minor = ida_alloc_max(&osd_minor_ida, SCSI_OSD_MAX_MINOR, GFP_KERNEL);
427 if (!ida_pre_get(&osd_minor_ida, GFP_KERNEL)) 427 if (minor == -ENOSPC)
428 return -ENODEV; 428 return -EBUSY;
429 429 if (minor < 0)
430 error = ida_get_new(&osd_minor_ida, &minor); 430 return -ENODEV;
431 } while (error == -EAGAIN);
432
433 if (error)
434 return error;
435 if (minor >= SCSI_OSD_MAX_MINOR) {
436 error = -EBUSY;
437 goto err_retract_minor;
438 }
439 431
440 error = -ENOMEM; 432 error = -ENOMEM;
441 oud = kzalloc(sizeof(*oud), GFP_KERNEL); 433 oud = kzalloc(sizeof(*oud), GFP_KERNEL);
@@ -499,7 +491,7 @@ static int osd_probe(struct device *dev)
499err_free_osd: 491err_free_osd:
500 put_device(&oud->class_dev); 492 put_device(&oud->class_dev);
501err_retract_minor: 493err_retract_minor:
502 ida_remove(&osd_minor_ida, minor); 494 ida_free(&osd_minor_ida, minor);
503 return error; 495 return error;
504} 496}
505 497
@@ -514,7 +506,7 @@ static int osd_remove(struct device *dev)
514 } 506 }
515 507
516 cdev_device_del(&oud->cdev, &oud->class_dev); 508 cdev_device_del(&oud->cdev, &oud->class_dev);
517 ida_remove(&osd_minor_ida, oud->minor); 509 ida_free(&osd_minor_ida, oud->minor);
518 put_device(&oud->class_dev); 510 put_device(&oud->class_dev);
519 511
520 return 0; 512 return 0;
diff --git a/drivers/scsi/qedi/qedi.h b/drivers/scsi/qedi/qedi.h
index fc3babc15fa3..a6f96b35e971 100644
--- a/drivers/scsi/qedi/qedi.h
+++ b/drivers/scsi/qedi/qedi.h
@@ -77,6 +77,11 @@ enum qedi_nvm_tgts {
77 QEDI_NVM_TGT_SEC, 77 QEDI_NVM_TGT_SEC,
78}; 78};
79 79
80struct qedi_nvm_iscsi_image {
81 struct nvm_iscsi_cfg iscsi_cfg;
82 u32 crc;
83};
84
80struct qedi_uio_ctrl { 85struct qedi_uio_ctrl {
81 /* meta data */ 86 /* meta data */
82 u32 uio_hsi_version; 87 u32 uio_hsi_version;
@@ -294,7 +299,7 @@ struct qedi_ctx {
294 void *bdq_pbl_list; 299 void *bdq_pbl_list;
295 dma_addr_t bdq_pbl_list_dma; 300 dma_addr_t bdq_pbl_list_dma;
296 u8 bdq_pbl_list_num_entries; 301 u8 bdq_pbl_list_num_entries;
297 struct nvm_iscsi_cfg *iscsi_cfg; 302 struct qedi_nvm_iscsi_image *iscsi_image;
298 dma_addr_t nvm_buf_dma; 303 dma_addr_t nvm_buf_dma;
299 void __iomem *bdq_primary_prod; 304 void __iomem *bdq_primary_prod;
300 void __iomem *bdq_secondary_prod; 305 void __iomem *bdq_secondary_prod;
diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index aa96bccb5a96..cc8e64dc65ad 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -1346,23 +1346,26 @@ exit_setup_int:
1346 1346
1347static void qedi_free_nvm_iscsi_cfg(struct qedi_ctx *qedi) 1347static void qedi_free_nvm_iscsi_cfg(struct qedi_ctx *qedi)
1348{ 1348{
1349 if (qedi->iscsi_cfg) 1349 if (qedi->iscsi_image)
1350 dma_free_coherent(&qedi->pdev->dev, 1350 dma_free_coherent(&qedi->pdev->dev,
1351 sizeof(struct nvm_iscsi_cfg), 1351 sizeof(struct qedi_nvm_iscsi_image),
1352 qedi->iscsi_cfg, qedi->nvm_buf_dma); 1352 qedi->iscsi_image, qedi->nvm_buf_dma);
1353} 1353}
1354 1354
1355static int qedi_alloc_nvm_iscsi_cfg(struct qedi_ctx *qedi) 1355static int qedi_alloc_nvm_iscsi_cfg(struct qedi_ctx *qedi)
1356{ 1356{
1357 qedi->iscsi_cfg = dma_zalloc_coherent(&qedi->pdev->dev, 1357 struct qedi_nvm_iscsi_image nvm_image;
1358 sizeof(struct nvm_iscsi_cfg), 1358
1359 &qedi->nvm_buf_dma, GFP_KERNEL); 1359 qedi->iscsi_image = dma_zalloc_coherent(&qedi->pdev->dev,
1360 if (!qedi->iscsi_cfg) { 1360 sizeof(nvm_image),
1361 &qedi->nvm_buf_dma,
1362 GFP_KERNEL);
1363 if (!qedi->iscsi_image) {
1361 QEDI_ERR(&qedi->dbg_ctx, "Could not allocate NVM BUF.\n"); 1364 QEDI_ERR(&qedi->dbg_ctx, "Could not allocate NVM BUF.\n");
1362 return -ENOMEM; 1365 return -ENOMEM;
1363 } 1366 }
1364 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, 1367 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1365 "NVM BUF addr=0x%p dma=0x%llx.\n", qedi->iscsi_cfg, 1368 "NVM BUF addr=0x%p dma=0x%llx.\n", qedi->iscsi_image,
1366 qedi->nvm_buf_dma); 1369 qedi->nvm_buf_dma);
1367 1370
1368 return 0; 1371 return 0;
@@ -1905,7 +1908,7 @@ qedi_get_nvram_block(struct qedi_ctx *qedi)
1905 struct nvm_iscsi_block *block; 1908 struct nvm_iscsi_block *block;
1906 1909
1907 pf = qedi->dev_info.common.abs_pf_id; 1910 pf = qedi->dev_info.common.abs_pf_id;
1908 block = &qedi->iscsi_cfg->block[0]; 1911 block = &qedi->iscsi_image->iscsi_cfg.block[0];
1909 for (i = 0; i < NUM_OF_ISCSI_PF_SUPPORTED; i++, block++) { 1912 for (i = 0; i < NUM_OF_ISCSI_PF_SUPPORTED; i++, block++) {
1910 flags = ((block->id) & NVM_ISCSI_CFG_BLK_CTRL_FLAG_MASK) >> 1913 flags = ((block->id) & NVM_ISCSI_CFG_BLK_CTRL_FLAG_MASK) >>
1911 NVM_ISCSI_CFG_BLK_CTRL_FLAG_OFFSET; 1914 NVM_ISCSI_CFG_BLK_CTRL_FLAG_OFFSET;
@@ -2194,15 +2197,14 @@ static void qedi_boot_release(void *data)
2194static int qedi_get_boot_info(struct qedi_ctx *qedi) 2197static int qedi_get_boot_info(struct qedi_ctx *qedi)
2195{ 2198{
2196 int ret = 1; 2199 int ret = 1;
2197 u16 len; 2200 struct qedi_nvm_iscsi_image nvm_image;
2198
2199 len = sizeof(struct nvm_iscsi_cfg);
2200 2201
2201 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, 2202 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
2202 "Get NVM iSCSI CFG image\n"); 2203 "Get NVM iSCSI CFG image\n");
2203 ret = qedi_ops->common->nvm_get_image(qedi->cdev, 2204 ret = qedi_ops->common->nvm_get_image(qedi->cdev,
2204 QED_NVM_IMAGE_ISCSI_CFG, 2205 QED_NVM_IMAGE_ISCSI_CFG,
2205 (char *)qedi->iscsi_cfg, len); 2206 (char *)qedi->iscsi_image,
2207 sizeof(nvm_image));
2206 if (ret) 2208 if (ret)
2207 QEDI_ERR(&qedi->dbg_ctx, 2209 QEDI_ERR(&qedi->dbg_ctx,
2208 "Could not get NVM image. ret = %d\n", ret); 2210 "Could not get NVM image. ret = %d\n", ret);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 0adfb3bce0fd..eb97d2dd3651 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -345,8 +345,7 @@ static void scsi_dec_host_busy(struct Scsi_Host *shost)
345 unsigned long flags; 345 unsigned long flags;
346 346
347 rcu_read_lock(); 347 rcu_read_lock();
348 if (!shost->use_blk_mq) 348 atomic_dec(&shost->host_busy);
349 atomic_dec(&shost->host_busy);
350 if (unlikely(scsi_host_in_recovery(shost))) { 349 if (unlikely(scsi_host_in_recovery(shost))) {
351 spin_lock_irqsave(shost->host_lock, flags); 350 spin_lock_irqsave(shost->host_lock, flags);
352 if (shost->host_failed || shost->host_eh_scheduled) 351 if (shost->host_failed || shost->host_eh_scheduled)
@@ -445,12 +444,7 @@ static inline bool scsi_target_is_busy(struct scsi_target *starget)
445 444
446static inline bool scsi_host_is_busy(struct Scsi_Host *shost) 445static inline bool scsi_host_is_busy(struct Scsi_Host *shost)
447{ 446{
448 /* 447 if (shost->can_queue > 0 &&
449 * blk-mq can handle host queue busy efficiently via host-wide driver
450 * tag allocation
451 */
452
453 if (!shost->use_blk_mq && shost->can_queue > 0 &&
454 atomic_read(&shost->host_busy) >= shost->can_queue) 448 atomic_read(&shost->host_busy) >= shost->can_queue)
455 return true; 449 return true;
456 if (atomic_read(&shost->host_blocked) > 0) 450 if (atomic_read(&shost->host_blocked) > 0)
@@ -1606,10 +1600,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
1606 if (scsi_host_in_recovery(shost)) 1600 if (scsi_host_in_recovery(shost))
1607 return 0; 1601 return 0;
1608 1602
1609 if (!shost->use_blk_mq) 1603 busy = atomic_inc_return(&shost->host_busy) - 1;
1610 busy = atomic_inc_return(&shost->host_busy) - 1;
1611 else
1612 busy = 0;
1613 if (atomic_read(&shost->host_blocked) > 0) { 1604 if (atomic_read(&shost->host_blocked) > 0) {
1614 if (busy) 1605 if (busy)
1615 goto starved; 1606 goto starved;
@@ -1625,7 +1616,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
1625 "unblocking host at zero depth\n")); 1616 "unblocking host at zero depth\n"));
1626 } 1617 }
1627 1618
1628 if (!shost->use_blk_mq && shost->can_queue > 0 && busy >= shost->can_queue) 1619 if (shost->can_queue > 0 && busy >= shost->can_queue)
1629 goto starved; 1620 goto starved;
1630 if (shost->host_self_blocked) 1621 if (shost->host_self_blocked)
1631 goto starved; 1622 goto starved;
@@ -1711,9 +1702,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
1711 * with the locks as normal issue path does. 1702 * with the locks as normal issue path does.
1712 */ 1703 */
1713 atomic_inc(&sdev->device_busy); 1704 atomic_inc(&sdev->device_busy);
1714 1705 atomic_inc(&shost->host_busy);
1715 if (!shost->use_blk_mq)
1716 atomic_inc(&shost->host_busy);
1717 if (starget->can_queue > 0) 1706 if (starget->can_queue > 0)
1718 atomic_inc(&starget->target_busy); 1707 atomic_inc(&starget->target_busy);
1719 1708
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a58cee7a85f2..b79b366a94f7 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -123,7 +123,6 @@ static void scsi_disk_release(struct device *cdev);
123static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); 123static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
124static void sd_print_result(const struct scsi_disk *, const char *, int); 124static void sd_print_result(const struct scsi_disk *, const char *, int);
125 125
126static DEFINE_SPINLOCK(sd_index_lock);
127static DEFINE_IDA(sd_index_ida); 126static DEFINE_IDA(sd_index_ida);
128 127
129/* This semaphore is used to mediate the 0->1 reference get in the 128/* This semaphore is used to mediate the 0->1 reference get in the
@@ -3340,16 +3339,8 @@ static int sd_probe(struct device *dev)
3340 if (!gd) 3339 if (!gd)
3341 goto out_free; 3340 goto out_free;
3342 3341
3343 do { 3342 index = ida_alloc(&sd_index_ida, GFP_KERNEL);
3344 if (!ida_pre_get(&sd_index_ida, GFP_KERNEL)) 3343 if (index < 0) {
3345 goto out_put;
3346
3347 spin_lock(&sd_index_lock);
3348 error = ida_get_new(&sd_index_ida, &index);
3349 spin_unlock(&sd_index_lock);
3350 } while (error == -EAGAIN);
3351
3352 if (error) {
3353 sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n"); 3344 sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n");
3354 goto out_put; 3345 goto out_put;
3355 } 3346 }
@@ -3393,9 +3384,7 @@ static int sd_probe(struct device *dev)
3393 return 0; 3384 return 0;
3394 3385
3395 out_free_index: 3386 out_free_index:
3396 spin_lock(&sd_index_lock); 3387 ida_free(&sd_index_ida, index);
3397 ida_remove(&sd_index_ida, index);
3398 spin_unlock(&sd_index_lock);
3399 out_put: 3388 out_put:
3400 put_disk(gd); 3389 put_disk(gd);
3401 out_free: 3390 out_free:
@@ -3460,9 +3449,7 @@ static void scsi_disk_release(struct device *dev)
3460 struct scsi_disk *sdkp = to_scsi_disk(dev); 3449 struct scsi_disk *sdkp = to_scsi_disk(dev);
3461 struct gendisk *disk = sdkp->disk; 3450 struct gendisk *disk = sdkp->disk;
3462 3451
3463 spin_lock(&sd_index_lock); 3452 ida_free(&sd_index_ida, sdkp->index);
3464 ida_remove(&sd_index_ida, sdkp->index);
3465 spin_unlock(&sd_index_lock);
3466 3453
3467 disk->private_data = NULL; 3454 disk->private_data = NULL;
3468 put_disk(disk); 3455 put_disk(disk);
diff --git a/drivers/target/iscsi/cxgbit/cxgbit_ddp.c b/drivers/target/iscsi/cxgbit/cxgbit_ddp.c
index 768cce0ccb80..76a262674c8d 100644
--- a/drivers/target/iscsi/cxgbit/cxgbit_ddp.c
+++ b/drivers/target/iscsi/cxgbit/cxgbit_ddp.c
@@ -207,8 +207,8 @@ cxgbit_ddp_reserve(struct cxgbit_sock *csk, struct cxgbi_task_tag_info *ttinfo,
207 ret = dma_map_sg(&ppm->pdev->dev, sgl, sgcnt, DMA_FROM_DEVICE); 207 ret = dma_map_sg(&ppm->pdev->dev, sgl, sgcnt, DMA_FROM_DEVICE);
208 sgl->offset = sg_offset; 208 sgl->offset = sg_offset;
209 if (!ret) { 209 if (!ret) {
210 pr_info("%s: 0x%x, xfer %u, sgl %u dma mapping err.\n", 210 pr_debug("%s: 0x%x, xfer %u, sgl %u dma mapping err.\n",
211 __func__, 0, xferlen, sgcnt); 211 __func__, 0, xferlen, sgcnt);
212 goto rel_ppods; 212 goto rel_ppods;
213 } 213 }
214 214
@@ -250,8 +250,8 @@ cxgbit_get_r2t_ttt(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
250 250
251 ret = cxgbit_ddp_reserve(csk, ttinfo, cmd->se_cmd.data_length); 251 ret = cxgbit_ddp_reserve(csk, ttinfo, cmd->se_cmd.data_length);
252 if (ret < 0) { 252 if (ret < 0) {
253 pr_info("csk 0x%p, cmd 0x%p, xfer len %u, sgcnt %u no ddp.\n", 253 pr_debug("csk 0x%p, cmd 0x%p, xfer len %u, sgcnt %u no ddp.\n",
254 csk, cmd, cmd->se_cmd.data_length, ttinfo->nents); 254 csk, cmd, cmd->se_cmd.data_length, ttinfo->nents);
255 255
256 ttinfo->sgl = NULL; 256 ttinfo->sgl = NULL;
257 ttinfo->nents = 0; 257 ttinfo->nents = 0;
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 8e223799347a..9cdfccbdd06f 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -57,9 +57,8 @@ static DEFINE_SPINLOCK(tiqn_lock);
57static DEFINE_MUTEX(np_lock); 57static DEFINE_MUTEX(np_lock);
58 58
59static struct idr tiqn_idr; 59static struct idr tiqn_idr;
60struct idr sess_idr; 60DEFINE_IDA(sess_ida);
61struct mutex auth_id_lock; 61struct mutex auth_id_lock;
62spinlock_t sess_idr_lock;
63 62
64struct iscsit_global *iscsit_global; 63struct iscsit_global *iscsit_global;
65 64
@@ -700,9 +699,7 @@ static int __init iscsi_target_init_module(void)
700 699
701 spin_lock_init(&iscsit_global->ts_bitmap_lock); 700 spin_lock_init(&iscsit_global->ts_bitmap_lock);
702 mutex_init(&auth_id_lock); 701 mutex_init(&auth_id_lock);
703 spin_lock_init(&sess_idr_lock);
704 idr_init(&tiqn_idr); 702 idr_init(&tiqn_idr);
705 idr_init(&sess_idr);
706 703
707 ret = target_register_template(&iscsi_ops); 704 ret = target_register_template(&iscsi_ops);
708 if (ret) 705 if (ret)
@@ -4211,22 +4208,15 @@ int iscsit_close_connection(
4211 crypto_free_ahash(tfm); 4208 crypto_free_ahash(tfm);
4212 } 4209 }
4213 4210
4214 free_cpumask_var(conn->conn_cpumask);
4215
4216 kfree(conn->conn_ops);
4217 conn->conn_ops = NULL;
4218
4219 if (conn->sock) 4211 if (conn->sock)
4220 sock_release(conn->sock); 4212 sock_release(conn->sock);
4221 4213
4222 if (conn->conn_transport->iscsit_free_conn) 4214 if (conn->conn_transport->iscsit_free_conn)
4223 conn->conn_transport->iscsit_free_conn(conn); 4215 conn->conn_transport->iscsit_free_conn(conn);
4224 4216
4225 iscsit_put_transport(conn->conn_transport);
4226
4227 pr_debug("Moving to TARG_CONN_STATE_FREE.\n"); 4217 pr_debug("Moving to TARG_CONN_STATE_FREE.\n");
4228 conn->conn_state = TARG_CONN_STATE_FREE; 4218 conn->conn_state = TARG_CONN_STATE_FREE;
4229 kfree(conn); 4219 iscsit_free_conn(conn);
4230 4220
4231 spin_lock_bh(&sess->conn_lock); 4221 spin_lock_bh(&sess->conn_lock);
4232 atomic_dec(&sess->nconn); 4222 atomic_dec(&sess->nconn);
@@ -4375,10 +4365,7 @@ int iscsit_close_session(struct iscsi_session *sess)
4375 pr_debug("Decremented number of active iSCSI Sessions on" 4365 pr_debug("Decremented number of active iSCSI Sessions on"
4376 " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); 4366 " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions);
4377 4367
4378 spin_lock(&sess_idr_lock); 4368 ida_free(&sess_ida, sess->session_index);
4379 idr_remove(&sess_idr, sess->session_index);
4380 spin_unlock(&sess_idr_lock);
4381
4382 kfree(sess->sess_ops); 4369 kfree(sess->sess_ops);
4383 sess->sess_ops = NULL; 4370 sess->sess_ops = NULL;
4384 spin_unlock_bh(&se_tpg->session_lock); 4371 spin_unlock_bh(&se_tpg->session_lock);
diff --git a/drivers/target/iscsi/iscsi_target.h b/drivers/target/iscsi/iscsi_target.h
index 42de1843aa40..48bac0acf8c7 100644
--- a/drivers/target/iscsi/iscsi_target.h
+++ b/drivers/target/iscsi/iscsi_target.h
@@ -55,9 +55,7 @@ extern struct kmem_cache *lio_ooo_cache;
55extern struct kmem_cache *lio_qr_cache; 55extern struct kmem_cache *lio_qr_cache;
56extern struct kmem_cache *lio_r2t_cache; 56extern struct kmem_cache *lio_r2t_cache;
57 57
58extern struct idr sess_idr; 58extern struct ida sess_ida;
59extern struct mutex auth_id_lock; 59extern struct mutex auth_id_lock;
60extern spinlock_t sess_idr_lock;
61
62 60
63#endif /*** ISCSI_TARGET_H ***/ 61#endif /*** ISCSI_TARGET_H ***/
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
index 923b1a9fc3dc..bb90c80ff388 100644
--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -67,45 +67,10 @@ static struct iscsi_login *iscsi_login_init_conn(struct iscsi_conn *conn)
67 goto out_req_buf; 67 goto out_req_buf;
68 } 68 }
69 69
70 conn->conn_ops = kzalloc(sizeof(struct iscsi_conn_ops), GFP_KERNEL);
71 if (!conn->conn_ops) {
72 pr_err("Unable to allocate memory for"
73 " struct iscsi_conn_ops.\n");
74 goto out_rsp_buf;
75 }
76
77 init_waitqueue_head(&conn->queues_wq);
78 INIT_LIST_HEAD(&conn->conn_list);
79 INIT_LIST_HEAD(&conn->conn_cmd_list);
80 INIT_LIST_HEAD(&conn->immed_queue_list);
81 INIT_LIST_HEAD(&conn->response_queue_list);
82 init_completion(&conn->conn_post_wait_comp);
83 init_completion(&conn->conn_wait_comp);
84 init_completion(&conn->conn_wait_rcfr_comp);
85 init_completion(&conn->conn_waiting_on_uc_comp);
86 init_completion(&conn->conn_logout_comp);
87 init_completion(&conn->rx_half_close_comp);
88 init_completion(&conn->tx_half_close_comp);
89 init_completion(&conn->rx_login_comp);
90 spin_lock_init(&conn->cmd_lock);
91 spin_lock_init(&conn->conn_usage_lock);
92 spin_lock_init(&conn->immed_queue_lock);
93 spin_lock_init(&conn->nopin_timer_lock);
94 spin_lock_init(&conn->response_queue_lock);
95 spin_lock_init(&conn->state_lock);
96
97 if (!zalloc_cpumask_var(&conn->conn_cpumask, GFP_KERNEL)) {
98 pr_err("Unable to allocate conn->conn_cpumask\n");
99 goto out_conn_ops;
100 }
101 conn->conn_login = login; 70 conn->conn_login = login;
102 71
103 return login; 72 return login;
104 73
105out_conn_ops:
106 kfree(conn->conn_ops);
107out_rsp_buf:
108 kfree(login->rsp_buf);
109out_req_buf: 74out_req_buf:
110 kfree(login->req_buf); 75 kfree(login->req_buf);
111out_login: 76out_login:
@@ -310,11 +275,9 @@ static int iscsi_login_zero_tsih_s1(
310 return -ENOMEM; 275 return -ENOMEM;
311 } 276 }
312 277
313 ret = iscsi_login_set_conn_values(sess, conn, pdu->cid); 278 if (iscsi_login_set_conn_values(sess, conn, pdu->cid))
314 if (unlikely(ret)) { 279 goto free_sess;
315 kfree(sess); 280
316 return ret;
317 }
318 sess->init_task_tag = pdu->itt; 281 sess->init_task_tag = pdu->itt;
319 memcpy(&sess->isid, pdu->isid, 6); 282 memcpy(&sess->isid, pdu->isid, 6);
320 sess->exp_cmd_sn = be32_to_cpu(pdu->cmdsn); 283 sess->exp_cmd_sn = be32_to_cpu(pdu->cmdsn);
@@ -336,22 +299,15 @@ static int iscsi_login_zero_tsih_s1(
336 timer_setup(&sess->time2retain_timer, 299 timer_setup(&sess->time2retain_timer,
337 iscsit_handle_time2retain_timeout, 0); 300 iscsit_handle_time2retain_timeout, 0);
338 301
339 idr_preload(GFP_KERNEL); 302 ret = ida_alloc(&sess_ida, GFP_KERNEL);
340 spin_lock_bh(&sess_idr_lock);
341 ret = idr_alloc(&sess_idr, NULL, 0, 0, GFP_NOWAIT);
342 if (ret >= 0)
343 sess->session_index = ret;
344 spin_unlock_bh(&sess_idr_lock);
345 idr_preload_end();
346
347 if (ret < 0) { 303 if (ret < 0) {
348 pr_err("idr_alloc() for sess_idr failed\n"); 304 pr_err("Session ID allocation failed %d\n", ret);
349 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 305 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
350 ISCSI_LOGIN_STATUS_NO_RESOURCES); 306 ISCSI_LOGIN_STATUS_NO_RESOURCES);
351 kfree(sess); 307 goto free_sess;
352 return -ENOMEM;
353 } 308 }
354 309
310 sess->session_index = ret;
355 sess->creation_time = get_jiffies_64(); 311 sess->creation_time = get_jiffies_64();
356 /* 312 /*
357 * The FFP CmdSN window values will be allocated from the TPG's 313 * The FFP CmdSN window values will be allocated from the TPG's
@@ -365,20 +321,26 @@ static int iscsi_login_zero_tsih_s1(
365 ISCSI_LOGIN_STATUS_NO_RESOURCES); 321 ISCSI_LOGIN_STATUS_NO_RESOURCES);
366 pr_err("Unable to allocate memory for" 322 pr_err("Unable to allocate memory for"
367 " struct iscsi_sess_ops.\n"); 323 " struct iscsi_sess_ops.\n");
368 kfree(sess); 324 goto free_id;
369 return -ENOMEM;
370 } 325 }
371 326
372 sess->se_sess = transport_alloc_session(TARGET_PROT_NORMAL); 327 sess->se_sess = transport_alloc_session(TARGET_PROT_NORMAL);
373 if (IS_ERR(sess->se_sess)) { 328 if (IS_ERR(sess->se_sess)) {
374 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 329 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
375 ISCSI_LOGIN_STATUS_NO_RESOURCES); 330 ISCSI_LOGIN_STATUS_NO_RESOURCES);
376 kfree(sess->sess_ops); 331 goto free_ops;
377 kfree(sess);
378 return -ENOMEM;
379 } 332 }
380 333
381 return 0; 334 return 0;
335
336free_ops:
337 kfree(sess->sess_ops);
338free_id:
339 ida_free(&sess_ida, sess->session_index);
340free_sess:
341 kfree(sess);
342 conn->sess = NULL;
343 return -ENOMEM;
382} 344}
383 345
384static int iscsi_login_zero_tsih_s2( 346static int iscsi_login_zero_tsih_s2(
@@ -1150,6 +1112,75 @@ iscsit_conn_set_transport(struct iscsi_conn *conn, struct iscsit_transport *t)
1150 return 0; 1112 return 0;
1151} 1113}
1152 1114
1115static struct iscsi_conn *iscsit_alloc_conn(struct iscsi_np *np)
1116{
1117 struct iscsi_conn *conn;
1118
1119 conn = kzalloc(sizeof(struct iscsi_conn), GFP_KERNEL);
1120 if (!conn) {
1121 pr_err("Could not allocate memory for new connection\n");
1122 return NULL;
1123 }
1124 pr_debug("Moving to TARG_CONN_STATE_FREE.\n");
1125 conn->conn_state = TARG_CONN_STATE_FREE;
1126
1127 init_waitqueue_head(&conn->queues_wq);
1128 INIT_LIST_HEAD(&conn->conn_list);
1129 INIT_LIST_HEAD(&conn->conn_cmd_list);
1130 INIT_LIST_HEAD(&conn->immed_queue_list);
1131 INIT_LIST_HEAD(&conn->response_queue_list);
1132 init_completion(&conn->conn_post_wait_comp);
1133 init_completion(&conn->conn_wait_comp);
1134 init_completion(&conn->conn_wait_rcfr_comp);
1135 init_completion(&conn->conn_waiting_on_uc_comp);
1136 init_completion(&conn->conn_logout_comp);
1137 init_completion(&conn->rx_half_close_comp);
1138 init_completion(&conn->tx_half_close_comp);
1139 init_completion(&conn->rx_login_comp);
1140 spin_lock_init(&conn->cmd_lock);
1141 spin_lock_init(&conn->conn_usage_lock);
1142 spin_lock_init(&conn->immed_queue_lock);
1143 spin_lock_init(&conn->nopin_timer_lock);
1144 spin_lock_init(&conn->response_queue_lock);
1145 spin_lock_init(&conn->state_lock);
1146
1147 timer_setup(&conn->nopin_response_timer,
1148 iscsit_handle_nopin_response_timeout, 0);
1149 timer_setup(&conn->nopin_timer, iscsit_handle_nopin_timeout, 0);
1150
1151 if (iscsit_conn_set_transport(conn, np->np_transport) < 0)
1152 goto free_conn;
1153
1154 conn->conn_ops = kzalloc(sizeof(struct iscsi_conn_ops), GFP_KERNEL);
1155 if (!conn->conn_ops) {
1156 pr_err("Unable to allocate memory for struct iscsi_conn_ops.\n");
1157 goto put_transport;
1158 }
1159
1160 if (!zalloc_cpumask_var(&conn->conn_cpumask, GFP_KERNEL)) {
1161 pr_err("Unable to allocate conn->conn_cpumask\n");
1162 goto free_mask;
1163 }
1164
1165 return conn;
1166
1167free_mask:
1168 free_cpumask_var(conn->conn_cpumask);
1169put_transport:
1170 iscsit_put_transport(conn->conn_transport);
1171free_conn:
1172 kfree(conn);
1173 return NULL;
1174}
1175
1176void iscsit_free_conn(struct iscsi_conn *conn)
1177{
1178 free_cpumask_var(conn->conn_cpumask);
1179 kfree(conn->conn_ops);
1180 iscsit_put_transport(conn->conn_transport);
1181 kfree(conn);
1182}
1183
1153void iscsi_target_login_sess_out(struct iscsi_conn *conn, 1184void iscsi_target_login_sess_out(struct iscsi_conn *conn,
1154 struct iscsi_np *np, bool zero_tsih, bool new_sess) 1185 struct iscsi_np *np, bool zero_tsih, bool new_sess)
1155{ 1186{
@@ -1161,13 +1192,9 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn,
1161 ISCSI_LOGIN_STATUS_INIT_ERR); 1192 ISCSI_LOGIN_STATUS_INIT_ERR);
1162 if (!zero_tsih || !conn->sess) 1193 if (!zero_tsih || !conn->sess)
1163 goto old_sess_out; 1194 goto old_sess_out;
1164 if (conn->sess->se_sess) 1195
1165 transport_free_session(conn->sess->se_sess); 1196 transport_free_session(conn->sess->se_sess);
1166 if (conn->sess->session_index != 0) { 1197 ida_free(&sess_ida, conn->sess->session_index);
1167 spin_lock_bh(&sess_idr_lock);
1168 idr_remove(&sess_idr, conn->sess->session_index);
1169 spin_unlock_bh(&sess_idr_lock);
1170 }
1171 kfree(conn->sess->sess_ops); 1198 kfree(conn->sess->sess_ops);
1172 kfree(conn->sess); 1199 kfree(conn->sess);
1173 conn->sess = NULL; 1200 conn->sess = NULL;
@@ -1203,10 +1230,6 @@ old_sess_out:
1203 crypto_free_ahash(tfm); 1230 crypto_free_ahash(tfm);
1204 } 1231 }
1205 1232
1206 free_cpumask_var(conn->conn_cpumask);
1207
1208 kfree(conn->conn_ops);
1209
1210 if (conn->param_list) { 1233 if (conn->param_list) {
1211 iscsi_release_param_list(conn->param_list); 1234 iscsi_release_param_list(conn->param_list);
1212 conn->param_list = NULL; 1235 conn->param_list = NULL;
@@ -1224,8 +1247,7 @@ old_sess_out:
1224 if (conn->conn_transport->iscsit_free_conn) 1247 if (conn->conn_transport->iscsit_free_conn)
1225 conn->conn_transport->iscsit_free_conn(conn); 1248 conn->conn_transport->iscsit_free_conn(conn);
1226 1249
1227 iscsit_put_transport(conn->conn_transport); 1250 iscsit_free_conn(conn);
1228 kfree(conn);
1229} 1251}
1230 1252
1231static int __iscsi_target_login_thread(struct iscsi_np *np) 1253static int __iscsi_target_login_thread(struct iscsi_np *np)
@@ -1255,31 +1277,16 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
1255 } 1277 }
1256 spin_unlock_bh(&np->np_thread_lock); 1278 spin_unlock_bh(&np->np_thread_lock);
1257 1279
1258 conn = kzalloc(sizeof(struct iscsi_conn), GFP_KERNEL); 1280 conn = iscsit_alloc_conn(np);
1259 if (!conn) { 1281 if (!conn) {
1260 pr_err("Could not allocate memory for"
1261 " new connection\n");
1262 /* Get another socket */ 1282 /* Get another socket */
1263 return 1; 1283 return 1;
1264 } 1284 }
1265 pr_debug("Moving to TARG_CONN_STATE_FREE.\n");
1266 conn->conn_state = TARG_CONN_STATE_FREE;
1267
1268 timer_setup(&conn->nopin_response_timer,
1269 iscsit_handle_nopin_response_timeout, 0);
1270 timer_setup(&conn->nopin_timer, iscsit_handle_nopin_timeout, 0);
1271
1272 if (iscsit_conn_set_transport(conn, np->np_transport) < 0) {
1273 kfree(conn);
1274 return 1;
1275 }
1276 1285
1277 rc = np->np_transport->iscsit_accept_np(np, conn); 1286 rc = np->np_transport->iscsit_accept_np(np, conn);
1278 if (rc == -ENOSYS) { 1287 if (rc == -ENOSYS) {
1279 complete(&np->np_restart_comp); 1288 complete(&np->np_restart_comp);
1280 iscsit_put_transport(conn->conn_transport); 1289 iscsit_free_conn(conn);
1281 kfree(conn);
1282 conn = NULL;
1283 goto exit; 1290 goto exit;
1284 } else if (rc < 0) { 1291 } else if (rc < 0) {
1285 spin_lock_bh(&np->np_thread_lock); 1292 spin_lock_bh(&np->np_thread_lock);
@@ -1287,17 +1294,13 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
1287 np->np_thread_state = ISCSI_NP_THREAD_ACTIVE; 1294 np->np_thread_state = ISCSI_NP_THREAD_ACTIVE;
1288 spin_unlock_bh(&np->np_thread_lock); 1295 spin_unlock_bh(&np->np_thread_lock);
1289 complete(&np->np_restart_comp); 1296 complete(&np->np_restart_comp);
1290 iscsit_put_transport(conn->conn_transport); 1297 iscsit_free_conn(conn);
1291 kfree(conn);
1292 conn = NULL;
1293 /* Get another socket */ 1298 /* Get another socket */
1294 return 1; 1299 return 1;
1295 } 1300 }
1296 spin_unlock_bh(&np->np_thread_lock); 1301 spin_unlock_bh(&np->np_thread_lock);
1297 iscsit_put_transport(conn->conn_transport); 1302 iscsit_free_conn(conn);
1298 kfree(conn); 1303 return 1;
1299 conn = NULL;
1300 goto out;
1301 } 1304 }
1302 /* 1305 /*
1303 * Perform the remaining iSCSI connection initialization items.. 1306 * Perform the remaining iSCSI connection initialization items..
@@ -1447,7 +1450,6 @@ old_sess_out:
1447 tpg_np = NULL; 1450 tpg_np = NULL;
1448 } 1451 }
1449 1452
1450out:
1451 return 1; 1453 return 1;
1452 1454
1453exit: 1455exit:
diff --git a/drivers/target/iscsi/iscsi_target_login.h b/drivers/target/iscsi/iscsi_target_login.h
index 74ac3abc44a0..3b8e3639ff5d 100644
--- a/drivers/target/iscsi/iscsi_target_login.h
+++ b/drivers/target/iscsi/iscsi_target_login.h
@@ -19,7 +19,7 @@ extern int iscsi_target_setup_login_socket(struct iscsi_np *,
19extern int iscsit_accept_np(struct iscsi_np *, struct iscsi_conn *); 19extern int iscsit_accept_np(struct iscsi_np *, struct iscsi_conn *);
20extern int iscsit_get_login_rx(struct iscsi_conn *, struct iscsi_login *); 20extern int iscsit_get_login_rx(struct iscsi_conn *, struct iscsi_login *);
21extern int iscsit_put_login_tx(struct iscsi_conn *, struct iscsi_login *, u32); 21extern int iscsit_put_login_tx(struct iscsi_conn *, struct iscsi_login *, u32);
22extern void iscsit_free_conn(struct iscsi_np *, struct iscsi_conn *); 22extern void iscsit_free_conn(struct iscsi_conn *);
23extern int iscsit_start_kthreads(struct iscsi_conn *); 23extern int iscsit_start_kthreads(struct iscsi_conn *);
24extern void iscsi_post_login_handler(struct iscsi_np *, struct iscsi_conn *, u8); 24extern void iscsi_post_login_handler(struct iscsi_np *, struct iscsi_conn *, u8);
25extern void iscsi_target_login_sess_out(struct iscsi_conn *, struct iscsi_np *, 25extern void iscsi_target_login_sess_out(struct iscsi_conn *, struct iscsi_np *,
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 977a8307fbb1..4f2816559205 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -260,10 +260,13 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,
260 260
261 mutex_lock(&tz->lock); 261 mutex_lock(&tz->lock);
262 262
263 if (mode == THERMAL_DEVICE_ENABLED) 263 if (mode == THERMAL_DEVICE_ENABLED) {
264 tz->polling_delay = data->polling_delay; 264 tz->polling_delay = data->polling_delay;
265 else 265 tz->passive_delay = data->passive_delay;
266 } else {
266 tz->polling_delay = 0; 267 tz->polling_delay = 0;
268 tz->passive_delay = 0;
269 }
267 270
268 mutex_unlock(&tz->lock); 271 mutex_unlock(&tz->lock);
269 272
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index c866cc165960..450ed66edf58 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -1,16 +1,6 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright 2016 Freescale Semiconductor, Inc. 2//
3 * 3// Copyright 2016 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 */
14 4
15#include <linux/module.h> 5#include <linux/module.h>
16#include <linux/platform_device.h> 6#include <linux/platform_device.h>
@@ -197,7 +187,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
197 int ret; 187 int ret;
198 struct qoriq_tmu_data *data; 188 struct qoriq_tmu_data *data;
199 struct device_node *np = pdev->dev.of_node; 189 struct device_node *np = pdev->dev.of_node;
200 u32 site = 0; 190 u32 site;
201 191
202 if (!np) { 192 if (!np) {
203 dev_err(&pdev->dev, "Device OF-Node is NULL"); 193 dev_err(&pdev->dev, "Device OF-Node is NULL");
@@ -233,8 +223,9 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
233 if (ret < 0) 223 if (ret < 0)
234 goto err_tmu; 224 goto err_tmu;
235 225
236 data->tz = thermal_zone_of_sensor_register(&pdev->dev, data->sensor_id, 226 data->tz = devm_thermal_zone_of_sensor_register(&pdev->dev,
237 data, &tmu_tz_ops); 227 data->sensor_id,
228 data, &tmu_tz_ops);
238 if (IS_ERR(data->tz)) { 229 if (IS_ERR(data->tz)) {
239 ret = PTR_ERR(data->tz); 230 ret = PTR_ERR(data->tz);
240 dev_err(&pdev->dev, 231 dev_err(&pdev->dev,
@@ -243,7 +234,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
243 } 234 }
244 235
245 /* Enable monitoring */ 236 /* Enable monitoring */
246 site |= 0x1 << (15 - data->sensor_id); 237 site = 0x1 << (15 - data->sensor_id);
247 tmu_write(data, site | TMR_ME | TMR_ALPF, &data->regs->tmr); 238 tmu_write(data, site | TMR_ME | TMR_ALPF, &data->regs->tmr);
248 239
249 return 0; 240 return 0;
@@ -261,8 +252,6 @@ static int qoriq_tmu_remove(struct platform_device *pdev)
261{ 252{
262 struct qoriq_tmu_data *data = platform_get_drvdata(pdev); 253 struct qoriq_tmu_data *data = platform_get_drvdata(pdev);
263 254
264 thermal_zone_of_sensor_unregister(&pdev->dev, data->tz);
265
266 /* Disable monitoring */ 255 /* Disable monitoring */
267 tmu_write(data, TMR_DISABLE, &data->regs->tmr); 256 tmu_write(data, TMR_DISABLE, &data->regs->tmr);
268 257
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
index 766521eb7071..7aed5337bdd3 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * R-Car Gen3 THS thermal sensor driver 3 * R-Car Gen3 THS thermal sensor driver
3 * Based on rcar_thermal.c and work from Hien Dang and Khiem Nguyen. 4 * Based on rcar_thermal.c and work from Hien Dang and Khiem Nguyen.
4 * 5 *
5 * Copyright (C) 2016 Renesas Electronics Corporation. 6 * Copyright (C) 2016 Renesas Electronics Corporation.
6 * Copyright (C) 2016 Sang Engineering 7 * Copyright (C) 2016 Sang Engineering
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 */ 8 */
18#include <linux/delay.h> 9#include <linux/delay.h>
19#include <linux/err.h> 10#include <linux/err.h>
diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index e77e63070e99..78f932822d38 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -1,21 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * R-Car THS/TSC thermal sensor driver 3 * R-Car THS/TSC thermal sensor driver
3 * 4 *
4 * Copyright (C) 2012 Renesas Solutions Corp. 5 * Copyright (C) 2012 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 */ 7 */
20#include <linux/delay.h> 8#include <linux/delay.h>
21#include <linux/err.h> 9#include <linux/err.h>
@@ -660,6 +648,6 @@ static struct platform_driver rcar_thermal_driver = {
660}; 648};
661module_platform_driver(rcar_thermal_driver); 649module_platform_driver(rcar_thermal_driver);
662 650
663MODULE_LICENSE("GPL"); 651MODULE_LICENSE("GPL v2");
664MODULE_DESCRIPTION("R-Car THS/TSC thermal sensor driver"); 652MODULE_DESCRIPTION("R-Car THS/TSC thermal sensor driver");
665MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); 653MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 96c1d8400822..b13c6b4b2c66 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -952,7 +952,7 @@ static void vhost_iotlb_notify_vq(struct vhost_dev *d,
952 list_for_each_entry_safe(node, n, &d->pending_list, node) { 952 list_for_each_entry_safe(node, n, &d->pending_list, node) {
953 struct vhost_iotlb_msg *vq_msg = &node->msg.iotlb; 953 struct vhost_iotlb_msg *vq_msg = &node->msg.iotlb;
954 if (msg->iova <= vq_msg->iova && 954 if (msg->iova <= vq_msg->iova &&
955 msg->iova + msg->size - 1 > vq_msg->iova && 955 msg->iova + msg->size - 1 >= vq_msg->iova &&
956 vq_msg->type == VHOST_IOTLB_MISS) { 956 vq_msg->type == VHOST_IOTLB_MISS) {
957 vhost_poll_queue(&node->vq->poll); 957 vhost_poll_queue(&node->vq->poll);
958 list_del(&node->node); 958 list_del(&node->node);
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index f2088838f690..5b471889d723 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -402,10 +402,19 @@ static ssize_t modalias_show(struct device *dev,
402} 402}
403static DEVICE_ATTR_RO(modalias); 403static DEVICE_ATTR_RO(modalias);
404 404
405static ssize_t state_show(struct device *dev,
406 struct device_attribute *attr, char *buf)
407{
408 return sprintf(buf, "%s\n",
409 xenbus_strstate(to_xenbus_device(dev)->state));
410}
411static DEVICE_ATTR_RO(state);
412
405static struct attribute *xenbus_dev_attrs[] = { 413static struct attribute *xenbus_dev_attrs[] = {
406 &dev_attr_nodename.attr, 414 &dev_attr_nodename.attr,
407 &dev_attr_devtype.attr, 415 &dev_attr_devtype.attr,
408 &dev_attr_modalias.attr, 416 &dev_attr_modalias.attr,
417 &dev_attr_state.attr,
409 NULL, 418 NULL,
410}; 419};
411 420
diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 0c3285c8db95..476dcbb79713 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -98,13 +98,13 @@ static int afs_proc_cells_write(struct file *file, char *buf, size_t size)
98 goto inval; 98 goto inval;
99 99
100 args = strchr(name, ' '); 100 args = strchr(name, ' ');
101 if (!args) 101 if (args) {
102 goto inval; 102 do {
103 do { 103 *args++ = 0;
104 *args++ = 0; 104 } while(*args == ' ');
105 } while(*args == ' '); 105 if (!*args)
106 if (!*args) 106 goto inval;
107 goto inval; 107 }
108 108
109 /* determine command to perform */ 109 /* determine command to perform */
110 _debug("cmd=%s name=%s args=%s", buf, name, args); 110 _debug("cmd=%s name=%s args=%s", buf, name, args);
@@ -120,7 +120,6 @@ static int afs_proc_cells_write(struct file *file, char *buf, size_t size)
120 120
121 if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags)) 121 if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags))
122 afs_put_cell(net, cell); 122 afs_put_cell(net, cell);
123 printk("kAFS: Added new cell '%s'\n", name);
124 } else { 123 } else {
125 goto inval; 124 goto inval;
126 } 125 }
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 53af9f5253f4..2cddfe7806a4 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1280,6 +1280,7 @@ struct btrfs_root {
1280 int send_in_progress; 1280 int send_in_progress;
1281 struct btrfs_subvolume_writers *subv_writers; 1281 struct btrfs_subvolume_writers *subv_writers;
1282 atomic_t will_be_snapshotted; 1282 atomic_t will_be_snapshotted;
1283 atomic_t snapshot_force_cow;
1283 1284
1284 /* For qgroup metadata reserved space */ 1285 /* For qgroup metadata reserved space */
1285 spinlock_t qgroup_meta_rsv_lock; 1286 spinlock_t qgroup_meta_rsv_lock;
@@ -3390,9 +3391,9 @@ do { \
3390#define btrfs_debug(fs_info, fmt, args...) \ 3391#define btrfs_debug(fs_info, fmt, args...) \
3391 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 3392 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
3392#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ 3393#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
3393 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 3394 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
3394#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ 3395#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
3395 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 3396 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
3396#define btrfs_debug_rl(fs_info, fmt, args...) \ 3397#define btrfs_debug_rl(fs_info, fmt, args...) \
3397 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 3398 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
3398#endif 3399#endif
@@ -3404,6 +3405,13 @@ do { \
3404 rcu_read_unlock(); \ 3405 rcu_read_unlock(); \
3405} while (0) 3406} while (0)
3406 3407
3408#define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \
3409do { \
3410 rcu_read_lock(); \
3411 btrfs_no_printk(fs_info, fmt, ##args); \
3412 rcu_read_unlock(); \
3413} while (0)
3414
3407#define btrfs_printk_ratelimited(fs_info, fmt, args...) \ 3415#define btrfs_printk_ratelimited(fs_info, fmt, args...) \
3408do { \ 3416do { \
3409 static DEFINE_RATELIMIT_STATE(_rs, \ 3417 static DEFINE_RATELIMIT_STATE(_rs, \
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 5124c15705ce..05dc3c17cb62 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1187,6 +1187,7 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
1187 atomic_set(&root->log_batch, 0); 1187 atomic_set(&root->log_batch, 0);
1188 refcount_set(&root->refs, 1); 1188 refcount_set(&root->refs, 1);
1189 atomic_set(&root->will_be_snapshotted, 0); 1189 atomic_set(&root->will_be_snapshotted, 0);
1190 atomic_set(&root->snapshot_force_cow, 0);
1190 root->log_transid = 0; 1191 root->log_transid = 0;
1191 root->log_transid_committed = -1; 1192 root->log_transid_committed = -1;
1192 root->last_log_commit = 0; 1193 root->last_log_commit = 0;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index de6f75f5547b..2d9074295d7f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5800,7 +5800,7 @@ void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
5800 * root: the root of the parent directory 5800 * root: the root of the parent directory
5801 * rsv: block reservation 5801 * rsv: block reservation
5802 * items: the number of items that we need do reservation 5802 * items: the number of items that we need do reservation
5803 * qgroup_reserved: used to return the reserved size in qgroup 5803 * use_global_rsv: allow fallback to the global block reservation
5804 * 5804 *
5805 * This function is used to reserve the space for snapshot/subvolume 5805 * This function is used to reserve the space for snapshot/subvolume
5806 * creation and deletion. Those operations are different with the 5806 * creation and deletion. Those operations are different with the
@@ -5810,10 +5810,10 @@ void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
5810 * the space reservation mechanism in start_transaction(). 5810 * the space reservation mechanism in start_transaction().
5811 */ 5811 */
5812int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, 5812int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
5813 struct btrfs_block_rsv *rsv, 5813 struct btrfs_block_rsv *rsv, int items,
5814 int items,
5815 bool use_global_rsv) 5814 bool use_global_rsv)
5816{ 5815{
5816 u64 qgroup_num_bytes = 0;
5817 u64 num_bytes; 5817 u64 num_bytes;
5818 int ret; 5818 int ret;
5819 struct btrfs_fs_info *fs_info = root->fs_info; 5819 struct btrfs_fs_info *fs_info = root->fs_info;
@@ -5821,12 +5821,11 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
5821 5821
5822 if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) { 5822 if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) {
5823 /* One for parent inode, two for dir entries */ 5823 /* One for parent inode, two for dir entries */
5824 num_bytes = 3 * fs_info->nodesize; 5824 qgroup_num_bytes = 3 * fs_info->nodesize;
5825 ret = btrfs_qgroup_reserve_meta_prealloc(root, num_bytes, true); 5825 ret = btrfs_qgroup_reserve_meta_prealloc(root,
5826 qgroup_num_bytes, true);
5826 if (ret) 5827 if (ret)
5827 return ret; 5828 return ret;
5828 } else {
5829 num_bytes = 0;
5830 } 5829 }
5831 5830
5832 num_bytes = btrfs_calc_trans_metadata_size(fs_info, items); 5831 num_bytes = btrfs_calc_trans_metadata_size(fs_info, items);
@@ -5838,8 +5837,8 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
5838 if (ret == -ENOSPC && use_global_rsv) 5837 if (ret == -ENOSPC && use_global_rsv)
5839 ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, 1); 5838 ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, 1);
5840 5839
5841 if (ret && num_bytes) 5840 if (ret && qgroup_num_bytes)
5842 btrfs_qgroup_free_meta_prealloc(root, num_bytes); 5841 btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes);
5843 5842
5844 return ret; 5843 return ret;
5845} 5844}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9357a19d2bff..3ea5339603cf 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1271,7 +1271,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
1271 u64 disk_num_bytes; 1271 u64 disk_num_bytes;
1272 u64 ram_bytes; 1272 u64 ram_bytes;
1273 int extent_type; 1273 int extent_type;
1274 int ret, err; 1274 int ret;
1275 int type; 1275 int type;
1276 int nocow; 1276 int nocow;
1277 int check_prev = 1; 1277 int check_prev = 1;
@@ -1403,11 +1403,8 @@ next_slot:
1403 * if there are pending snapshots for this root, 1403 * if there are pending snapshots for this root,
1404 * we fall into common COW way. 1404 * we fall into common COW way.
1405 */ 1405 */
1406 if (!nolock) { 1406 if (!nolock && atomic_read(&root->snapshot_force_cow))
1407 err = btrfs_start_write_no_snapshotting(root); 1407 goto out_check;
1408 if (!err)
1409 goto out_check;
1410 }
1411 /* 1408 /*
1412 * force cow if csum exists in the range. 1409 * force cow if csum exists in the range.
1413 * this ensure that csum for a given extent are 1410 * this ensure that csum for a given extent are
@@ -1416,9 +1413,6 @@ next_slot:
1416 ret = csum_exist_in_range(fs_info, disk_bytenr, 1413 ret = csum_exist_in_range(fs_info, disk_bytenr,
1417 num_bytes); 1414 num_bytes);
1418 if (ret) { 1415 if (ret) {
1419 if (!nolock)
1420 btrfs_end_write_no_snapshotting(root);
1421
1422 /* 1416 /*
1423 * ret could be -EIO if the above fails to read 1417 * ret could be -EIO if the above fails to read
1424 * metadata. 1418 * metadata.
@@ -1431,11 +1425,8 @@ next_slot:
1431 WARN_ON_ONCE(nolock); 1425 WARN_ON_ONCE(nolock);
1432 goto out_check; 1426 goto out_check;
1433 } 1427 }
1434 if (!btrfs_inc_nocow_writers(fs_info, disk_bytenr)) { 1428 if (!btrfs_inc_nocow_writers(fs_info, disk_bytenr))
1435 if (!nolock)
1436 btrfs_end_write_no_snapshotting(root);
1437 goto out_check; 1429 goto out_check;
1438 }
1439 nocow = 1; 1430 nocow = 1;
1440 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { 1431 } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
1441 extent_end = found_key.offset + 1432 extent_end = found_key.offset +
@@ -1448,8 +1439,6 @@ next_slot:
1448out_check: 1439out_check:
1449 if (extent_end <= start) { 1440 if (extent_end <= start) {
1450 path->slots[0]++; 1441 path->slots[0]++;
1451 if (!nolock && nocow)
1452 btrfs_end_write_no_snapshotting(root);
1453 if (nocow) 1442 if (nocow)
1454 btrfs_dec_nocow_writers(fs_info, disk_bytenr); 1443 btrfs_dec_nocow_writers(fs_info, disk_bytenr);
1455 goto next_slot; 1444 goto next_slot;
@@ -1471,8 +1460,6 @@ out_check:
1471 end, page_started, nr_written, 1, 1460 end, page_started, nr_written, 1,
1472 NULL); 1461 NULL);
1473 if (ret) { 1462 if (ret) {
1474 if (!nolock && nocow)
1475 btrfs_end_write_no_snapshotting(root);
1476 if (nocow) 1463 if (nocow)
1477 btrfs_dec_nocow_writers(fs_info, 1464 btrfs_dec_nocow_writers(fs_info,
1478 disk_bytenr); 1465 disk_bytenr);
@@ -1492,8 +1479,6 @@ out_check:
1492 ram_bytes, BTRFS_COMPRESS_NONE, 1479 ram_bytes, BTRFS_COMPRESS_NONE,
1493 BTRFS_ORDERED_PREALLOC); 1480 BTRFS_ORDERED_PREALLOC);
1494 if (IS_ERR(em)) { 1481 if (IS_ERR(em)) {
1495 if (!nolock && nocow)
1496 btrfs_end_write_no_snapshotting(root);
1497 if (nocow) 1482 if (nocow)
1498 btrfs_dec_nocow_writers(fs_info, 1483 btrfs_dec_nocow_writers(fs_info,
1499 disk_bytenr); 1484 disk_bytenr);
@@ -1532,8 +1517,6 @@ out_check:
1532 EXTENT_CLEAR_DATA_RESV, 1517 EXTENT_CLEAR_DATA_RESV,
1533 PAGE_UNLOCK | PAGE_SET_PRIVATE2); 1518 PAGE_UNLOCK | PAGE_SET_PRIVATE2);
1534 1519
1535 if (!nolock && nocow)
1536 btrfs_end_write_no_snapshotting(root);
1537 cur_offset = extent_end; 1520 cur_offset = extent_end;
1538 1521
1539 /* 1522 /*
@@ -6639,6 +6622,8 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
6639 drop_inode = 1; 6622 drop_inode = 1;
6640 } else { 6623 } else {
6641 struct dentry *parent = dentry->d_parent; 6624 struct dentry *parent = dentry->d_parent;
6625 int ret;
6626
6642 err = btrfs_update_inode(trans, root, inode); 6627 err = btrfs_update_inode(trans, root, inode);
6643 if (err) 6628 if (err)
6644 goto fail; 6629 goto fail;
@@ -6652,7 +6637,12 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
6652 goto fail; 6637 goto fail;
6653 } 6638 }
6654 d_instantiate(dentry, inode); 6639 d_instantiate(dentry, inode);
6655 btrfs_log_new_name(trans, BTRFS_I(inode), NULL, parent); 6640 ret = btrfs_log_new_name(trans, BTRFS_I(inode), NULL, parent,
6641 true, NULL);
6642 if (ret == BTRFS_NEED_TRANS_COMMIT) {
6643 err = btrfs_commit_transaction(trans);
6644 trans = NULL;
6645 }
6656 } 6646 }
6657 6647
6658fail: 6648fail:
@@ -9388,14 +9378,21 @@ static int btrfs_rename_exchange(struct inode *old_dir,
9388 u64 new_idx = 0; 9378 u64 new_idx = 0;
9389 u64 root_objectid; 9379 u64 root_objectid;
9390 int ret; 9380 int ret;
9391 int ret2;
9392 bool root_log_pinned = false; 9381 bool root_log_pinned = false;
9393 bool dest_log_pinned = false; 9382 bool dest_log_pinned = false;
9383 struct btrfs_log_ctx ctx_root;
9384 struct btrfs_log_ctx ctx_dest;
9385 bool sync_log_root = false;
9386 bool sync_log_dest = false;
9387 bool commit_transaction = false;
9394 9388
9395 /* we only allow rename subvolume link between subvolumes */ 9389 /* we only allow rename subvolume link between subvolumes */
9396 if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest) 9390 if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest)
9397 return -EXDEV; 9391 return -EXDEV;
9398 9392
9393 btrfs_init_log_ctx(&ctx_root, old_inode);
9394 btrfs_init_log_ctx(&ctx_dest, new_inode);
9395
9399 /* close the race window with snapshot create/destroy ioctl */ 9396 /* close the race window with snapshot create/destroy ioctl */
9400 if (old_ino == BTRFS_FIRST_FREE_OBJECTID) 9397 if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
9401 down_read(&fs_info->subvol_sem); 9398 down_read(&fs_info->subvol_sem);
@@ -9542,15 +9539,29 @@ static int btrfs_rename_exchange(struct inode *old_dir,
9542 9539
9543 if (root_log_pinned) { 9540 if (root_log_pinned) {
9544 parent = new_dentry->d_parent; 9541 parent = new_dentry->d_parent;
9545 btrfs_log_new_name(trans, BTRFS_I(old_inode), BTRFS_I(old_dir), 9542 ret = btrfs_log_new_name(trans, BTRFS_I(old_inode),
9546 parent); 9543 BTRFS_I(old_dir), parent,
9544 false, &ctx_root);
9545 if (ret == BTRFS_NEED_LOG_SYNC)
9546 sync_log_root = true;
9547 else if (ret == BTRFS_NEED_TRANS_COMMIT)
9548 commit_transaction = true;
9549 ret = 0;
9547 btrfs_end_log_trans(root); 9550 btrfs_end_log_trans(root);
9548 root_log_pinned = false; 9551 root_log_pinned = false;
9549 } 9552 }
9550 if (dest_log_pinned) { 9553 if (dest_log_pinned) {
9551 parent = old_dentry->d_parent; 9554 if (!commit_transaction) {
9552 btrfs_log_new_name(trans, BTRFS_I(new_inode), BTRFS_I(new_dir), 9555 parent = old_dentry->d_parent;
9553 parent); 9556 ret = btrfs_log_new_name(trans, BTRFS_I(new_inode),
9557 BTRFS_I(new_dir), parent,
9558 false, &ctx_dest);
9559 if (ret == BTRFS_NEED_LOG_SYNC)
9560 sync_log_dest = true;
9561 else if (ret == BTRFS_NEED_TRANS_COMMIT)
9562 commit_transaction = true;
9563 ret = 0;
9564 }
9554 btrfs_end_log_trans(dest); 9565 btrfs_end_log_trans(dest);
9555 dest_log_pinned = false; 9566 dest_log_pinned = false;
9556 } 9567 }
@@ -9583,8 +9594,26 @@ out_fail:
9583 dest_log_pinned = false; 9594 dest_log_pinned = false;
9584 } 9595 }
9585 } 9596 }
9586 ret2 = btrfs_end_transaction(trans); 9597 if (!ret && sync_log_root && !commit_transaction) {
9587 ret = ret ? ret : ret2; 9598 ret = btrfs_sync_log(trans, BTRFS_I(old_inode)->root,
9599 &ctx_root);
9600 if (ret)
9601 commit_transaction = true;
9602 }
9603 if (!ret && sync_log_dest && !commit_transaction) {
9604 ret = btrfs_sync_log(trans, BTRFS_I(new_inode)->root,
9605 &ctx_dest);
9606 if (ret)
9607 commit_transaction = true;
9608 }
9609 if (commit_transaction) {
9610 ret = btrfs_commit_transaction(trans);
9611 } else {
9612 int ret2;
9613
9614 ret2 = btrfs_end_transaction(trans);
9615 ret = ret ? ret : ret2;
9616 }
9588out_notrans: 9617out_notrans:
9589 if (new_ino == BTRFS_FIRST_FREE_OBJECTID) 9618 if (new_ino == BTRFS_FIRST_FREE_OBJECTID)
9590 up_read(&fs_info->subvol_sem); 9619 up_read(&fs_info->subvol_sem);
@@ -9661,6 +9690,9 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
9661 int ret; 9690 int ret;
9662 u64 old_ino = btrfs_ino(BTRFS_I(old_inode)); 9691 u64 old_ino = btrfs_ino(BTRFS_I(old_inode));
9663 bool log_pinned = false; 9692 bool log_pinned = false;
9693 struct btrfs_log_ctx ctx;
9694 bool sync_log = false;
9695 bool commit_transaction = false;
9664 9696
9665 if (btrfs_ino(BTRFS_I(new_dir)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 9697 if (btrfs_ino(BTRFS_I(new_dir)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)
9666 return -EPERM; 9698 return -EPERM;
@@ -9818,8 +9850,15 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
9818 if (log_pinned) { 9850 if (log_pinned) {
9819 struct dentry *parent = new_dentry->d_parent; 9851 struct dentry *parent = new_dentry->d_parent;
9820 9852
9821 btrfs_log_new_name(trans, BTRFS_I(old_inode), BTRFS_I(old_dir), 9853 btrfs_init_log_ctx(&ctx, old_inode);
9822 parent); 9854 ret = btrfs_log_new_name(trans, BTRFS_I(old_inode),
9855 BTRFS_I(old_dir), parent,
9856 false, &ctx);
9857 if (ret == BTRFS_NEED_LOG_SYNC)
9858 sync_log = true;
9859 else if (ret == BTRFS_NEED_TRANS_COMMIT)
9860 commit_transaction = true;
9861 ret = 0;
9823 btrfs_end_log_trans(root); 9862 btrfs_end_log_trans(root);
9824 log_pinned = false; 9863 log_pinned = false;
9825 } 9864 }
@@ -9856,7 +9895,19 @@ out_fail:
9856 btrfs_end_log_trans(root); 9895 btrfs_end_log_trans(root);
9857 log_pinned = false; 9896 log_pinned = false;
9858 } 9897 }
9859 btrfs_end_transaction(trans); 9898 if (!ret && sync_log) {
9899 ret = btrfs_sync_log(trans, BTRFS_I(old_inode)->root, &ctx);
9900 if (ret)
9901 commit_transaction = true;
9902 }
9903 if (commit_transaction) {
9904 ret = btrfs_commit_transaction(trans);
9905 } else {
9906 int ret2;
9907
9908 ret2 = btrfs_end_transaction(trans);
9909 ret = ret ? ret : ret2;
9910 }
9860out_notrans: 9911out_notrans:
9861 if (old_ino == BTRFS_FIRST_FREE_OBJECTID) 9912 if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
9862 up_read(&fs_info->subvol_sem); 9913 up_read(&fs_info->subvol_sem);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 63600dc2ac4c..d60b6caf09e8 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -747,6 +747,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
747 struct btrfs_pending_snapshot *pending_snapshot; 747 struct btrfs_pending_snapshot *pending_snapshot;
748 struct btrfs_trans_handle *trans; 748 struct btrfs_trans_handle *trans;
749 int ret; 749 int ret;
750 bool snapshot_force_cow = false;
750 751
751 if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) 752 if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state))
752 return -EINVAL; 753 return -EINVAL;
@@ -763,6 +764,11 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
763 goto free_pending; 764 goto free_pending;
764 } 765 }
765 766
767 /*
768 * Force new buffered writes to reserve space even when NOCOW is
769 * possible. This is to avoid later writeback (running dealloc) to
770 * fallback to COW mode and unexpectedly fail with ENOSPC.
771 */
766 atomic_inc(&root->will_be_snapshotted); 772 atomic_inc(&root->will_be_snapshotted);
767 smp_mb__after_atomic(); 773 smp_mb__after_atomic();
768 /* wait for no snapshot writes */ 774 /* wait for no snapshot writes */
@@ -773,6 +779,14 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
773 if (ret) 779 if (ret)
774 goto dec_and_free; 780 goto dec_and_free;
775 781
782 /*
783 * All previous writes have started writeback in NOCOW mode, so now
784 * we force future writes to fallback to COW mode during snapshot
785 * creation.
786 */
787 atomic_inc(&root->snapshot_force_cow);
788 snapshot_force_cow = true;
789
776 btrfs_wait_ordered_extents(root, U64_MAX, 0, (u64)-1); 790 btrfs_wait_ordered_extents(root, U64_MAX, 0, (u64)-1);
777 791
778 btrfs_init_block_rsv(&pending_snapshot->block_rsv, 792 btrfs_init_block_rsv(&pending_snapshot->block_rsv,
@@ -837,6 +851,8 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
837fail: 851fail:
838 btrfs_subvolume_release_metadata(fs_info, &pending_snapshot->block_rsv); 852 btrfs_subvolume_release_metadata(fs_info, &pending_snapshot->block_rsv);
839dec_and_free: 853dec_and_free:
854 if (snapshot_force_cow)
855 atomic_dec(&root->snapshot_force_cow);
840 if (atomic_dec_and_test(&root->will_be_snapshotted)) 856 if (atomic_dec_and_test(&root->will_be_snapshotted))
841 wake_up_var(&root->will_be_snapshotted); 857 wake_up_var(&root->will_be_snapshotted);
842free_pending: 858free_pending:
@@ -3453,6 +3469,25 @@ static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 olen,
3453 3469
3454 same_lock_start = min_t(u64, loff, dst_loff); 3470 same_lock_start = min_t(u64, loff, dst_loff);
3455 same_lock_len = max_t(u64, loff, dst_loff) + len - same_lock_start; 3471 same_lock_len = max_t(u64, loff, dst_loff) + len - same_lock_start;
3472 } else {
3473 /*
3474 * If the source and destination inodes are different, the
3475 * source's range end offset matches the source's i_size, that
3476 * i_size is not a multiple of the sector size, and the
3477 * destination range does not go past the destination's i_size,
3478 * we must round down the length to the nearest sector size
3479 * multiple. If we don't do this adjustment we end replacing
3480 * with zeroes the bytes in the range that starts at the
3481 * deduplication range's end offset and ends at the next sector
3482 * size multiple.
3483 */
3484 if (loff + olen == i_size_read(src) &&
3485 dst_loff + len < i_size_read(dst)) {
3486 const u64 sz = BTRFS_I(src)->root->fs_info->sectorsize;
3487
3488 len = round_down(i_size_read(src), sz) - loff;
3489 olen = len;
3490 }
3456 } 3491 }
3457 3492
3458again: 3493again:
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 4353bb69bb86..d4917c0cddf5 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1019,10 +1019,9 @@ out_add_root:
1019 spin_unlock(&fs_info->qgroup_lock); 1019 spin_unlock(&fs_info->qgroup_lock);
1020 1020
1021 ret = btrfs_commit_transaction(trans); 1021 ret = btrfs_commit_transaction(trans);
1022 if (ret) { 1022 trans = NULL;
1023 trans = NULL; 1023 if (ret)
1024 goto out_free_path; 1024 goto out_free_path;
1025 }
1026 1025
1027 ret = qgroup_rescan_init(fs_info, 0, 1); 1026 ret = qgroup_rescan_init(fs_info, 0, 1);
1028 if (!ret) { 1027 if (!ret) {
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 1650dc44a5e3..3c2ae0e4f25a 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -6025,14 +6025,25 @@ void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
6025 * Call this after adding a new name for a file and it will properly 6025 * Call this after adding a new name for a file and it will properly
6026 * update the log to reflect the new name. 6026 * update the log to reflect the new name.
6027 * 6027 *
6028 * It will return zero if all goes well, and it will return 1 if a 6028 * @ctx can not be NULL when @sync_log is false, and should be NULL when it's
6029 * full transaction commit is required. 6029 * true (because it's not used).
6030 *
6031 * Return value depends on whether @sync_log is true or false.
6032 * When true: returns BTRFS_NEED_TRANS_COMMIT if the transaction needs to be
6033 * committed by the caller, and BTRFS_DONT_NEED_TRANS_COMMIT
6034 * otherwise.
6035 * When false: returns BTRFS_DONT_NEED_LOG_SYNC if the caller does not need to
6036 * to sync the log, BTRFS_NEED_LOG_SYNC if it needs to sync the log,
6037 * or BTRFS_NEED_TRANS_COMMIT if the transaction needs to be
6038 * committed (without attempting to sync the log).
6030 */ 6039 */
6031int btrfs_log_new_name(struct btrfs_trans_handle *trans, 6040int btrfs_log_new_name(struct btrfs_trans_handle *trans,
6032 struct btrfs_inode *inode, struct btrfs_inode *old_dir, 6041 struct btrfs_inode *inode, struct btrfs_inode *old_dir,
6033 struct dentry *parent) 6042 struct dentry *parent,
6043 bool sync_log, struct btrfs_log_ctx *ctx)
6034{ 6044{
6035 struct btrfs_fs_info *fs_info = trans->fs_info; 6045 struct btrfs_fs_info *fs_info = trans->fs_info;
6046 int ret;
6036 6047
6037 /* 6048 /*
6038 * this will force the logging code to walk the dentry chain 6049 * this will force the logging code to walk the dentry chain
@@ -6047,9 +6058,34 @@ int btrfs_log_new_name(struct btrfs_trans_handle *trans,
6047 */ 6058 */
6048 if (inode->logged_trans <= fs_info->last_trans_committed && 6059 if (inode->logged_trans <= fs_info->last_trans_committed &&
6049 (!old_dir || old_dir->logged_trans <= fs_info->last_trans_committed)) 6060 (!old_dir || old_dir->logged_trans <= fs_info->last_trans_committed))
6050 return 0; 6061 return sync_log ? BTRFS_DONT_NEED_TRANS_COMMIT :
6062 BTRFS_DONT_NEED_LOG_SYNC;
6063
6064 if (sync_log) {
6065 struct btrfs_log_ctx ctx2;
6066
6067 btrfs_init_log_ctx(&ctx2, &inode->vfs_inode);
6068 ret = btrfs_log_inode_parent(trans, inode, parent, 0, LLONG_MAX,
6069 LOG_INODE_EXISTS, &ctx2);
6070 if (ret == BTRFS_NO_LOG_SYNC)
6071 return BTRFS_DONT_NEED_TRANS_COMMIT;
6072 else if (ret)
6073 return BTRFS_NEED_TRANS_COMMIT;
6074
6075 ret = btrfs_sync_log(trans, inode->root, &ctx2);
6076 if (ret)
6077 return BTRFS_NEED_TRANS_COMMIT;
6078 return BTRFS_DONT_NEED_TRANS_COMMIT;
6079 }
6080
6081 ASSERT(ctx);
6082 ret = btrfs_log_inode_parent(trans, inode, parent, 0, LLONG_MAX,
6083 LOG_INODE_EXISTS, ctx);
6084 if (ret == BTRFS_NO_LOG_SYNC)
6085 return BTRFS_DONT_NEED_LOG_SYNC;
6086 else if (ret)
6087 return BTRFS_NEED_TRANS_COMMIT;
6051 6088
6052 return btrfs_log_inode_parent(trans, inode, parent, 0, LLONG_MAX, 6089 return BTRFS_NEED_LOG_SYNC;
6053 LOG_INODE_EXISTS, NULL);
6054} 6090}
6055 6091
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
index 122e68b89a5a..7ab9bb88a639 100644
--- a/fs/btrfs/tree-log.h
+++ b/fs/btrfs/tree-log.h
@@ -71,8 +71,16 @@ void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
71 int for_rename); 71 int for_rename);
72void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans, 72void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
73 struct btrfs_inode *dir); 73 struct btrfs_inode *dir);
74/* Return values for btrfs_log_new_name() */
75enum {
76 BTRFS_DONT_NEED_TRANS_COMMIT,
77 BTRFS_NEED_TRANS_COMMIT,
78 BTRFS_DONT_NEED_LOG_SYNC,
79 BTRFS_NEED_LOG_SYNC,
80};
74int btrfs_log_new_name(struct btrfs_trans_handle *trans, 81int btrfs_log_new_name(struct btrfs_trans_handle *trans,
75 struct btrfs_inode *inode, struct btrfs_inode *old_dir, 82 struct btrfs_inode *inode, struct btrfs_inode *old_dir,
76 struct dentry *parent); 83 struct dentry *parent,
84 bool sync_log, struct btrfs_log_ctx *ctx);
77 85
78#endif 86#endif
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index da86706123ff..f4405e430da6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4491,7 +4491,12 @@ again:
4491 4491
4492 /* Now btrfs_update_device() will change the on-disk size. */ 4492 /* Now btrfs_update_device() will change the on-disk size. */
4493 ret = btrfs_update_device(trans, device); 4493 ret = btrfs_update_device(trans, device);
4494 btrfs_end_transaction(trans); 4494 if (ret < 0) {
4495 btrfs_abort_transaction(trans, ret);
4496 btrfs_end_transaction(trans);
4497 } else {
4498 ret = btrfs_commit_transaction(trans);
4499 }
4495done: 4500done:
4496 btrfs_free_path(path); 4501 btrfs_free_path(path);
4497 if (ret) { 4502 if (ret) {
diff --git a/fs/buffer.c b/fs/buffer.c
index 4cc679d5bf58..6f1ae3ac9789 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -39,7 +39,6 @@
39#include <linux/buffer_head.h> 39#include <linux/buffer_head.h>
40#include <linux/task_io_accounting_ops.h> 40#include <linux/task_io_accounting_ops.h>
41#include <linux/bio.h> 41#include <linux/bio.h>
42#include <linux/notifier.h>
43#include <linux/cpu.h> 42#include <linux/cpu.h>
44#include <linux/bitops.h> 43#include <linux/bitops.h>
45#include <linux/mpage.h> 44#include <linux/mpage.h>
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 43ca3b763875..eab1359d0553 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -602,6 +602,8 @@ static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
602 602
603/* 603/*
604 * create a new fs client 604 * create a new fs client
605 *
606 * Success or not, this function consumes @fsopt and @opt.
605 */ 607 */
606static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, 608static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
607 struct ceph_options *opt) 609 struct ceph_options *opt)
@@ -609,17 +611,20 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
609 struct ceph_fs_client *fsc; 611 struct ceph_fs_client *fsc;
610 int page_count; 612 int page_count;
611 size_t size; 613 size_t size;
612 int err = -ENOMEM; 614 int err;
613 615
614 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL); 616 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
615 if (!fsc) 617 if (!fsc) {
616 return ERR_PTR(-ENOMEM); 618 err = -ENOMEM;
619 goto fail;
620 }
617 621
618 fsc->client = ceph_create_client(opt, fsc); 622 fsc->client = ceph_create_client(opt, fsc);
619 if (IS_ERR(fsc->client)) { 623 if (IS_ERR(fsc->client)) {
620 err = PTR_ERR(fsc->client); 624 err = PTR_ERR(fsc->client);
621 goto fail; 625 goto fail;
622 } 626 }
627 opt = NULL; /* fsc->client now owns this */
623 628
624 fsc->client->extra_mon_dispatch = extra_mon_dispatch; 629 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
625 fsc->client->osdc.abort_on_full = true; 630 fsc->client->osdc.abort_on_full = true;
@@ -677,6 +682,9 @@ fail_client:
677 ceph_destroy_client(fsc->client); 682 ceph_destroy_client(fsc->client);
678fail: 683fail:
679 kfree(fsc); 684 kfree(fsc);
685 if (opt)
686 ceph_destroy_options(opt);
687 destroy_mount_options(fsopt);
680 return ERR_PTR(err); 688 return ERR_PTR(err);
681} 689}
682 690
@@ -1042,8 +1050,6 @@ static struct dentry *ceph_mount(struct file_system_type *fs_type,
1042 fsc = create_fs_client(fsopt, opt); 1050 fsc = create_fs_client(fsopt, opt);
1043 if (IS_ERR(fsc)) { 1051 if (IS_ERR(fsc)) {
1044 res = ERR_CAST(fsc); 1052 res = ERR_CAST(fsc);
1045 destroy_mount_options(fsopt);
1046 ceph_destroy_options(opt);
1047 goto out_final; 1053 goto out_final;
1048 } 1054 }
1049 1055
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index b380e0871372..a2b2355e7f01 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -105,9 +105,6 @@ convert_sfm_char(const __u16 src_char, char *target)
105 case SFM_LESSTHAN: 105 case SFM_LESSTHAN:
106 *target = '<'; 106 *target = '<';
107 break; 107 break;
108 case SFM_SLASH:
109 *target = '\\';
110 break;
111 case SFM_SPACE: 108 case SFM_SPACE:
112 *target = ' '; 109 *target = ' ';
113 break; 110 break;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index c832a8a1970a..7aa08dba4719 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -2547,7 +2547,7 @@ cifs_setup_ipc(struct cifs_ses *ses, struct smb_vol *volume_info)
2547 if (tcon == NULL) 2547 if (tcon == NULL)
2548 return -ENOMEM; 2548 return -ENOMEM;
2549 2549
2550 snprintf(unc, sizeof(unc), "\\\\%s\\IPC$", ses->serverName); 2550 snprintf(unc, sizeof(unc), "\\\\%s\\IPC$", ses->server->hostname);
2551 2551
2552 /* cannot fail */ 2552 /* cannot fail */
2553 nls_codepage = load_nls_default(); 2553 nls_codepage = load_nls_default();
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index d32eaa4b2437..6e8765f44508 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -467,6 +467,8 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
467 oparms.cifs_sb = cifs_sb; 467 oparms.cifs_sb = cifs_sb;
468 oparms.desired_access = GENERIC_READ; 468 oparms.desired_access = GENERIC_READ;
469 oparms.create_options = CREATE_NOT_DIR; 469 oparms.create_options = CREATE_NOT_DIR;
470 if (backup_cred(cifs_sb))
471 oparms.create_options |= CREATE_OPEN_BACKUP_INTENT;
470 oparms.disposition = FILE_OPEN; 472 oparms.disposition = FILE_OPEN;
471 oparms.path = path; 473 oparms.path = path;
472 oparms.fid = &fid; 474 oparms.fid = &fid;
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
index db0453660ff6..6a9c47541c53 100644
--- a/fs/cifs/smb2misc.c
+++ b/fs/cifs/smb2misc.c
@@ -248,16 +248,20 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr)
248 * MacOS server pads after SMB2.1 write response with 3 bytes 248 * MacOS server pads after SMB2.1 write response with 3 bytes
249 * of junk. Other servers match RFC1001 len to actual 249 * of junk. Other servers match RFC1001 len to actual
250 * SMB2/SMB3 frame length (header + smb2 response specific data) 250 * SMB2/SMB3 frame length (header + smb2 response specific data)
251 * Some windows servers do too when compounding is used. 251 * Some windows servers also pad up to 8 bytes when compounding.
252 * Log the server error (once), but allow it and continue 252 * If pad is longer than eight bytes, log the server behavior
253 * (once), since may indicate a problem but allow it and continue
253 * since the frame is parseable. 254 * since the frame is parseable.
254 */ 255 */
255 if (clc_len < len) { 256 if (clc_len < len) {
256 printk_once(KERN_WARNING 257 pr_warn_once(
257 "SMB2 server sent bad RFC1001 len %d not %d\n", 258 "srv rsp padded more than expected. Length %d not %d for cmd:%d mid:%llu\n",
258 len, clc_len); 259 len, clc_len, command, mid);
259 return 0; 260 return 0;
260 } 261 }
262 pr_warn_once(
263 "srv rsp too short, len %d not %d. cmd:%d mid:%llu\n",
264 len, clc_len, command, mid);
261 265
262 return 1; 266 return 1;
263 } 267 }
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 247a98e6c856..d954ce36b473 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -630,7 +630,10 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
630 oparms.tcon = tcon; 630 oparms.tcon = tcon;
631 oparms.desired_access = FILE_READ_ATTRIBUTES; 631 oparms.desired_access = FILE_READ_ATTRIBUTES;
632 oparms.disposition = FILE_OPEN; 632 oparms.disposition = FILE_OPEN;
633 oparms.create_options = 0; 633 if (backup_cred(cifs_sb))
634 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
635 else
636 oparms.create_options = 0;
634 oparms.fid = &fid; 637 oparms.fid = &fid;
635 oparms.reconnect = false; 638 oparms.reconnect = false;
636 639
@@ -779,7 +782,10 @@ smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
779 oparms.tcon = tcon; 782 oparms.tcon = tcon;
780 oparms.desired_access = FILE_READ_EA; 783 oparms.desired_access = FILE_READ_EA;
781 oparms.disposition = FILE_OPEN; 784 oparms.disposition = FILE_OPEN;
782 oparms.create_options = 0; 785 if (backup_cred(cifs_sb))
786 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
787 else
788 oparms.create_options = 0;
783 oparms.fid = &fid; 789 oparms.fid = &fid;
784 oparms.reconnect = false; 790 oparms.reconnect = false;
785 791
@@ -858,7 +864,10 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
858 oparms.tcon = tcon; 864 oparms.tcon = tcon;
859 oparms.desired_access = FILE_WRITE_EA; 865 oparms.desired_access = FILE_WRITE_EA;
860 oparms.disposition = FILE_OPEN; 866 oparms.disposition = FILE_OPEN;
861 oparms.create_options = 0; 867 if (backup_cred(cifs_sb))
868 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
869 else
870 oparms.create_options = 0;
862 oparms.fid = &fid; 871 oparms.fid = &fid;
863 oparms.reconnect = false; 872 oparms.reconnect = false;
864 873
@@ -1453,7 +1462,10 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1453 oparms.tcon = tcon; 1462 oparms.tcon = tcon;
1454 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; 1463 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1455 oparms.disposition = FILE_OPEN; 1464 oparms.disposition = FILE_OPEN;
1456 oparms.create_options = 0; 1465 if (backup_cred(cifs_sb))
1466 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1467 else
1468 oparms.create_options = 0;
1457 oparms.fid = fid; 1469 oparms.fid = fid;
1458 oparms.reconnect = false; 1470 oparms.reconnect = false;
1459 1471
@@ -1857,7 +1869,10 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1857 oparms.tcon = tcon; 1869 oparms.tcon = tcon;
1858 oparms.desired_access = FILE_READ_ATTRIBUTES; 1870 oparms.desired_access = FILE_READ_ATTRIBUTES;
1859 oparms.disposition = FILE_OPEN; 1871 oparms.disposition = FILE_OPEN;
1860 oparms.create_options = 0; 1872 if (backup_cred(cifs_sb))
1873 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1874 else
1875 oparms.create_options = 0;
1861 oparms.fid = &fid; 1876 oparms.fid = &fid;
1862 oparms.reconnect = false; 1877 oparms.reconnect = false;
1863 1878
@@ -3639,7 +3654,7 @@ struct smb_version_values smb21_values = {
3639struct smb_version_values smb3any_values = { 3654struct smb_version_values smb3any_values = {
3640 .version_string = SMB3ANY_VERSION_STRING, 3655 .version_string = SMB3ANY_VERSION_STRING,
3641 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ 3656 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3642 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, 3657 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3643 .large_lock_type = 0, 3658 .large_lock_type = 0,
3644 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, 3659 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3645 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, 3660 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
@@ -3660,7 +3675,7 @@ struct smb_version_values smb3any_values = {
3660struct smb_version_values smbdefault_values = { 3675struct smb_version_values smbdefault_values = {
3661 .version_string = SMBDEFAULT_VERSION_STRING, 3676 .version_string = SMBDEFAULT_VERSION_STRING,
3662 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ 3677 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3663 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, 3678 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3664 .large_lock_type = 0, 3679 .large_lock_type = 0,
3665 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, 3680 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3666 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, 3681 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
@@ -3681,7 +3696,7 @@ struct smb_version_values smbdefault_values = {
3681struct smb_version_values smb30_values = { 3696struct smb_version_values smb30_values = {
3682 .version_string = SMB30_VERSION_STRING, 3697 .version_string = SMB30_VERSION_STRING,
3683 .protocol_id = SMB30_PROT_ID, 3698 .protocol_id = SMB30_PROT_ID,
3684 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, 3699 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3685 .large_lock_type = 0, 3700 .large_lock_type = 0,
3686 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, 3701 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3687 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, 3702 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
@@ -3702,7 +3717,7 @@ struct smb_version_values smb30_values = {
3702struct smb_version_values smb302_values = { 3717struct smb_version_values smb302_values = {
3703 .version_string = SMB302_VERSION_STRING, 3718 .version_string = SMB302_VERSION_STRING,
3704 .protocol_id = SMB302_PROT_ID, 3719 .protocol_id = SMB302_PROT_ID,
3705 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, 3720 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3706 .large_lock_type = 0, 3721 .large_lock_type = 0,
3707 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, 3722 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3708 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, 3723 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
@@ -3723,7 +3738,7 @@ struct smb_version_values smb302_values = {
3723struct smb_version_values smb311_values = { 3738struct smb_version_values smb311_values = {
3724 .version_string = SMB311_VERSION_STRING, 3739 .version_string = SMB311_VERSION_STRING,
3725 .protocol_id = SMB311_PROT_ID, 3740 .protocol_id = SMB311_PROT_ID,
3726 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, 3741 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3727 .large_lock_type = 0, 3742 .large_lock_type = 0,
3728 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, 3743 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3729 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, 3744 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 5740aa809be6..c08acfc77abc 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2178,6 +2178,9 @@ SMB2_open_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, __u8 *oplock,
2178 if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) || 2178 if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) ||
2179 *oplock == SMB2_OPLOCK_LEVEL_NONE) 2179 *oplock == SMB2_OPLOCK_LEVEL_NONE)
2180 req->RequestedOplockLevel = *oplock; 2180 req->RequestedOplockLevel = *oplock;
2181 else if (!(server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING) &&
2182 (oparms->create_options & CREATE_NOT_FILE))
2183 req->RequestedOplockLevel = *oplock; /* no srv lease support */
2181 else { 2184 else {
2182 rc = add_lease_context(server, iov, &n_iov, 2185 rc = add_lease_context(server, iov, &n_iov,
2183 oparms->fid->lease_key, oplock); 2186 oparms->fid->lease_key, oplock);
diff --git a/fs/dax.c b/fs/dax.c
index 897b51e41d8f..f32d7125ad0f 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -226,8 +226,8 @@ static inline void *unlock_slot(struct address_space *mapping, void **slot)
226 * 226 *
227 * Must be called with the i_pages lock held. 227 * Must be called with the i_pages lock held.
228 */ 228 */
229static void *get_unlocked_mapping_entry(struct address_space *mapping, 229static void *__get_unlocked_mapping_entry(struct address_space *mapping,
230 pgoff_t index, void ***slotp) 230 pgoff_t index, void ***slotp, bool (*wait_fn)(void))
231{ 231{
232 void *entry, **slot; 232 void *entry, **slot;
233 struct wait_exceptional_entry_queue ewait; 233 struct wait_exceptional_entry_queue ewait;
@@ -237,6 +237,8 @@ static void *get_unlocked_mapping_entry(struct address_space *mapping,
237 ewait.wait.func = wake_exceptional_entry_func; 237 ewait.wait.func = wake_exceptional_entry_func;
238 238
239 for (;;) { 239 for (;;) {
240 bool revalidate;
241
240 entry = __radix_tree_lookup(&mapping->i_pages, index, NULL, 242 entry = __radix_tree_lookup(&mapping->i_pages, index, NULL,
241 &slot); 243 &slot);
242 if (!entry || 244 if (!entry ||
@@ -251,14 +253,31 @@ static void *get_unlocked_mapping_entry(struct address_space *mapping,
251 prepare_to_wait_exclusive(wq, &ewait.wait, 253 prepare_to_wait_exclusive(wq, &ewait.wait,
252 TASK_UNINTERRUPTIBLE); 254 TASK_UNINTERRUPTIBLE);
253 xa_unlock_irq(&mapping->i_pages); 255 xa_unlock_irq(&mapping->i_pages);
254 schedule(); 256 revalidate = wait_fn();
255 finish_wait(wq, &ewait.wait); 257 finish_wait(wq, &ewait.wait);
256 xa_lock_irq(&mapping->i_pages); 258 xa_lock_irq(&mapping->i_pages);
259 if (revalidate)
260 return ERR_PTR(-EAGAIN);
257 } 261 }
258} 262}
259 263
260static void dax_unlock_mapping_entry(struct address_space *mapping, 264static bool entry_wait(void)
261 pgoff_t index) 265{
266 schedule();
267 /*
268 * Never return an ERR_PTR() from
269 * __get_unlocked_mapping_entry(), just keep looping.
270 */
271 return false;
272}
273
274static void *get_unlocked_mapping_entry(struct address_space *mapping,
275 pgoff_t index, void ***slotp)
276{
277 return __get_unlocked_mapping_entry(mapping, index, slotp, entry_wait);
278}
279
280static void unlock_mapping_entry(struct address_space *mapping, pgoff_t index)
262{ 281{
263 void *entry, **slot; 282 void *entry, **slot;
264 283
@@ -277,7 +296,7 @@ static void dax_unlock_mapping_entry(struct address_space *mapping,
277static void put_locked_mapping_entry(struct address_space *mapping, 296static void put_locked_mapping_entry(struct address_space *mapping,
278 pgoff_t index) 297 pgoff_t index)
279{ 298{
280 dax_unlock_mapping_entry(mapping, index); 299 unlock_mapping_entry(mapping, index);
281} 300}
282 301
283/* 302/*
@@ -319,18 +338,27 @@ static unsigned long dax_radix_end_pfn(void *entry)
319 for (pfn = dax_radix_pfn(entry); \ 338 for (pfn = dax_radix_pfn(entry); \
320 pfn < dax_radix_end_pfn(entry); pfn++) 339 pfn < dax_radix_end_pfn(entry); pfn++)
321 340
322static void dax_associate_entry(void *entry, struct address_space *mapping) 341/*
342 * TODO: for reflink+dax we need a way to associate a single page with
343 * multiple address_space instances at different linear_page_index()
344 * offsets.
345 */
346static void dax_associate_entry(void *entry, struct address_space *mapping,
347 struct vm_area_struct *vma, unsigned long address)
323{ 348{
324 unsigned long pfn; 349 unsigned long size = dax_entry_size(entry), pfn, index;
350 int i = 0;
325 351
326 if (IS_ENABLED(CONFIG_FS_DAX_LIMITED)) 352 if (IS_ENABLED(CONFIG_FS_DAX_LIMITED))
327 return; 353 return;
328 354
355 index = linear_page_index(vma, address & ~(size - 1));
329 for_each_mapped_pfn(entry, pfn) { 356 for_each_mapped_pfn(entry, pfn) {
330 struct page *page = pfn_to_page(pfn); 357 struct page *page = pfn_to_page(pfn);
331 358
332 WARN_ON_ONCE(page->mapping); 359 WARN_ON_ONCE(page->mapping);
333 page->mapping = mapping; 360 page->mapping = mapping;
361 page->index = index + i++;
334 } 362 }
335} 363}
336 364
@@ -348,6 +376,7 @@ static void dax_disassociate_entry(void *entry, struct address_space *mapping,
348 WARN_ON_ONCE(trunc && page_ref_count(page) > 1); 376 WARN_ON_ONCE(trunc && page_ref_count(page) > 1);
349 WARN_ON_ONCE(page->mapping && page->mapping != mapping); 377 WARN_ON_ONCE(page->mapping && page->mapping != mapping);
350 page->mapping = NULL; 378 page->mapping = NULL;
379 page->index = 0;
351 } 380 }
352} 381}
353 382
@@ -364,6 +393,84 @@ static struct page *dax_busy_page(void *entry)
364 return NULL; 393 return NULL;
365} 394}
366 395
396static bool entry_wait_revalidate(void)
397{
398 rcu_read_unlock();
399 schedule();
400 rcu_read_lock();
401
402 /*
403 * Tell __get_unlocked_mapping_entry() to take a break, we need
404 * to revalidate page->mapping after dropping locks
405 */
406 return true;
407}
408
409bool dax_lock_mapping_entry(struct page *page)
410{
411 pgoff_t index;
412 struct inode *inode;
413 bool did_lock = false;
414 void *entry = NULL, **slot;
415 struct address_space *mapping;
416
417 rcu_read_lock();
418 for (;;) {
419 mapping = READ_ONCE(page->mapping);
420
421 if (!dax_mapping(mapping))
422 break;
423
424 /*
425 * In the device-dax case there's no need to lock, a
426 * struct dev_pagemap pin is sufficient to keep the
427 * inode alive, and we assume we have dev_pagemap pin
428 * otherwise we would not have a valid pfn_to_page()
429 * translation.
430 */
431 inode = mapping->host;
432 if (S_ISCHR(inode->i_mode)) {
433 did_lock = true;
434 break;
435 }
436
437 xa_lock_irq(&mapping->i_pages);
438 if (mapping != page->mapping) {
439 xa_unlock_irq(&mapping->i_pages);
440 continue;
441 }
442 index = page->index;
443
444 entry = __get_unlocked_mapping_entry(mapping, index, &slot,
445 entry_wait_revalidate);
446 if (!entry) {
447 xa_unlock_irq(&mapping->i_pages);
448 break;
449 } else if (IS_ERR(entry)) {
450 WARN_ON_ONCE(PTR_ERR(entry) != -EAGAIN);
451 continue;
452 }
453 lock_slot(mapping, slot);
454 did_lock = true;
455 xa_unlock_irq(&mapping->i_pages);
456 break;
457 }
458 rcu_read_unlock();
459
460 return did_lock;
461}
462
463void dax_unlock_mapping_entry(struct page *page)
464{
465 struct address_space *mapping = page->mapping;
466 struct inode *inode = mapping->host;
467
468 if (S_ISCHR(inode->i_mode))
469 return;
470
471 unlock_mapping_entry(mapping, page->index);
472}
473
367/* 474/*
368 * Find radix tree entry at given index. If it points to an exceptional entry, 475 * Find radix tree entry at given index. If it points to an exceptional entry,
369 * return it with the radix tree entry locked. If the radix tree doesn't 476 * return it with the radix tree entry locked. If the radix tree doesn't
@@ -655,7 +762,6 @@ static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev,
655{ 762{
656 void *vto, *kaddr; 763 void *vto, *kaddr;
657 pgoff_t pgoff; 764 pgoff_t pgoff;
658 pfn_t pfn;
659 long rc; 765 long rc;
660 int id; 766 int id;
661 767
@@ -664,7 +770,7 @@ static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev,
664 return rc; 770 return rc;
665 771
666 id = dax_read_lock(); 772 id = dax_read_lock();
667 rc = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size), &kaddr, &pfn); 773 rc = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size), &kaddr, NULL);
668 if (rc < 0) { 774 if (rc < 0) {
669 dax_read_unlock(id); 775 dax_read_unlock(id);
670 return rc; 776 return rc;
@@ -709,7 +815,7 @@ static void *dax_insert_mapping_entry(struct address_space *mapping,
709 new_entry = dax_radix_locked_entry(pfn, flags); 815 new_entry = dax_radix_locked_entry(pfn, flags);
710 if (dax_entry_size(entry) != dax_entry_size(new_entry)) { 816 if (dax_entry_size(entry) != dax_entry_size(new_entry)) {
711 dax_disassociate_entry(entry, mapping, false); 817 dax_disassociate_entry(entry, mapping, false);
712 dax_associate_entry(new_entry, mapping); 818 dax_associate_entry(new_entry, mapping, vmf->vma, vmf->address);
713 } 819 }
714 820
715 if (dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) { 821 if (dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) {
@@ -975,7 +1081,6 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
975{ 1081{
976 const sector_t sector = dax_iomap_sector(iomap, pos); 1082 const sector_t sector = dax_iomap_sector(iomap, pos);
977 pgoff_t pgoff; 1083 pgoff_t pgoff;
978 void *kaddr;
979 int id, rc; 1084 int id, rc;
980 long length; 1085 long length;
981 1086
@@ -984,7 +1089,7 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
984 return rc; 1089 return rc;
985 id = dax_read_lock(); 1090 id = dax_read_lock();
986 length = dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size), 1091 length = dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size),
987 &kaddr, pfnp); 1092 NULL, pfnp);
988 if (length < 0) { 1093 if (length < 0) {
989 rc = length; 1094 rc = length;
990 goto out; 1095 goto out;
@@ -1060,15 +1165,13 @@ int __dax_zero_page_range(struct block_device *bdev,
1060 pgoff_t pgoff; 1165 pgoff_t pgoff;
1061 long rc, id; 1166 long rc, id;
1062 void *kaddr; 1167 void *kaddr;
1063 pfn_t pfn;
1064 1168
1065 rc = bdev_dax_pgoff(bdev, sector, PAGE_SIZE, &pgoff); 1169 rc = bdev_dax_pgoff(bdev, sector, PAGE_SIZE, &pgoff);
1066 if (rc) 1170 if (rc)
1067 return rc; 1171 return rc;
1068 1172
1069 id = dax_read_lock(); 1173 id = dax_read_lock();
1070 rc = dax_direct_access(dax_dev, pgoff, 1, &kaddr, 1174 rc = dax_direct_access(dax_dev, pgoff, 1, &kaddr, NULL);
1071 &pfn);
1072 if (rc < 0) { 1175 if (rc < 0) {
1073 dax_read_unlock(id); 1176 dax_read_unlock(id);
1074 return rc; 1177 return rc;
@@ -1124,7 +1227,6 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
1124 ssize_t map_len; 1227 ssize_t map_len;
1125 pgoff_t pgoff; 1228 pgoff_t pgoff;
1126 void *kaddr; 1229 void *kaddr;
1127 pfn_t pfn;
1128 1230
1129 if (fatal_signal_pending(current)) { 1231 if (fatal_signal_pending(current)) {
1130 ret = -EINTR; 1232 ret = -EINTR;
@@ -1136,7 +1238,7 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
1136 break; 1238 break;
1137 1239
1138 map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size), 1240 map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size),
1139 &kaddr, &pfn); 1241 &kaddr, NULL);
1140 if (map_len < 0) { 1242 if (map_len < 0) {
1141 ret = map_len; 1243 ret = map_len;
1142 break; 1244 break;
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index e072e955ce33..c53814539070 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -46,7 +46,7 @@ static int pty_limit = NR_UNIX98_PTY_DEFAULT;
46static int pty_reserve = NR_UNIX98_PTY_RESERVE; 46static int pty_reserve = NR_UNIX98_PTY_RESERVE;
47static int pty_limit_min; 47static int pty_limit_min;
48static int pty_limit_max = INT_MAX; 48static int pty_limit_max = INT_MAX;
49static int pty_count; 49static atomic_t pty_count = ATOMIC_INIT(0);
50 50
51static struct ctl_table pty_table[] = { 51static struct ctl_table pty_table[] = {
52 { 52 {
@@ -93,8 +93,6 @@ static struct ctl_table pty_root_table[] = {
93 {} 93 {}
94}; 94};
95 95
96static DEFINE_MUTEX(allocated_ptys_lock);
97
98struct pts_mount_opts { 96struct pts_mount_opts {
99 int setuid; 97 int setuid;
100 int setgid; 98 int setgid;
@@ -533,44 +531,25 @@ static struct file_system_type devpts_fs_type = {
533 531
534int devpts_new_index(struct pts_fs_info *fsi) 532int devpts_new_index(struct pts_fs_info *fsi)
535{ 533{
536 int index; 534 int index = -ENOSPC;
537 int ida_ret;
538
539retry:
540 if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL))
541 return -ENOMEM;
542
543 mutex_lock(&allocated_ptys_lock);
544 if (pty_count >= (pty_limit -
545 (fsi->mount_opts.reserve ? 0 : pty_reserve))) {
546 mutex_unlock(&allocated_ptys_lock);
547 return -ENOSPC;
548 }
549 535
550 ida_ret = ida_get_new(&fsi->allocated_ptys, &index); 536 if (atomic_inc_return(&pty_count) >= (pty_limit -
551 if (ida_ret < 0) { 537 (fsi->mount_opts.reserve ? 0 : pty_reserve)))
552 mutex_unlock(&allocated_ptys_lock); 538 goto out;
553 if (ida_ret == -EAGAIN)
554 goto retry;
555 return -EIO;
556 }
557 539
558 if (index >= fsi->mount_opts.max) { 540 index = ida_alloc_max(&fsi->allocated_ptys, fsi->mount_opts.max - 1,
559 ida_remove(&fsi->allocated_ptys, index); 541 GFP_KERNEL);
560 mutex_unlock(&allocated_ptys_lock); 542
561 return -ENOSPC; 543out:
562 } 544 if (index < 0)
563 pty_count++; 545 atomic_dec(&pty_count);
564 mutex_unlock(&allocated_ptys_lock);
565 return index; 546 return index;
566} 547}
567 548
568void devpts_kill_index(struct pts_fs_info *fsi, int idx) 549void devpts_kill_index(struct pts_fs_info *fsi, int idx)
569{ 550{
570 mutex_lock(&allocated_ptys_lock); 551 ida_free(&fsi->allocated_ptys, idx);
571 ida_remove(&fsi->allocated_ptys, idx); 552 atomic_dec(&pty_count);
572 pty_count--;
573 mutex_unlock(&allocated_ptys_lock);
574} 553}
575 554
576/** 555/**
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index ec3fba7d492f..488a9e7f8f66 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -24,6 +24,7 @@
24#include <linux/mpage.h> 24#include <linux/mpage.h>
25#include <linux/user_namespace.h> 25#include <linux/user_namespace.h>
26#include <linux/seq_file.h> 26#include <linux/seq_file.h>
27#include <linux/blkdev.h>
27 28
28#include "isofs.h" 29#include "isofs.h"
29#include "zisofs.h" 30#include "zisofs.h"
@@ -653,6 +654,12 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
653 /* 654 /*
654 * What if bugger tells us to go beyond page size? 655 * What if bugger tells us to go beyond page size?
655 */ 656 */
657 if (bdev_logical_block_size(s->s_bdev) > 2048) {
658 printk(KERN_WARNING
659 "ISOFS: unsupported/invalid hardware sector size %d\n",
660 bdev_logical_block_size(s->s_bdev));
661 goto out_freesbi;
662 }
656 opt.blocksize = sb_min_blocksize(s, opt.blocksize); 663 opt.blocksize = sb_min_blocksize(s, opt.blocksize);
657 664
658 sbi->s_high_sierra = 0; /* default is iso9660 */ 665 sbi->s_high_sierra = 0; /* default is iso9660 */
diff --git a/fs/namespace.c b/fs/namespace.c
index 725d6935fab9..99186556f8d3 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -61,9 +61,6 @@ __setup("mphash_entries=", set_mphash_entries);
61static u64 event; 61static u64 event;
62static DEFINE_IDA(mnt_id_ida); 62static DEFINE_IDA(mnt_id_ida);
63static DEFINE_IDA(mnt_group_ida); 63static DEFINE_IDA(mnt_group_ida);
64static DEFINE_SPINLOCK(mnt_id_lock);
65static int mnt_id_start = 0;
66static int mnt_group_start = 1;
67 64
68static struct hlist_head *mount_hashtable __read_mostly; 65static struct hlist_head *mount_hashtable __read_mostly;
69static struct hlist_head *mountpoint_hashtable __read_mostly; 66static struct hlist_head *mountpoint_hashtable __read_mostly;
@@ -101,50 +98,30 @@ static inline struct hlist_head *mp_hash(struct dentry *dentry)
101 98
102static int mnt_alloc_id(struct mount *mnt) 99static int mnt_alloc_id(struct mount *mnt)
103{ 100{
104 int res; 101 int res = ida_alloc(&mnt_id_ida, GFP_KERNEL);
105 102
106retry: 103 if (res < 0)
107 ida_pre_get(&mnt_id_ida, GFP_KERNEL); 104 return res;
108 spin_lock(&mnt_id_lock); 105 mnt->mnt_id = res;
109 res = ida_get_new_above(&mnt_id_ida, mnt_id_start, &mnt->mnt_id); 106 return 0;
110 if (!res)
111 mnt_id_start = mnt->mnt_id + 1;
112 spin_unlock(&mnt_id_lock);
113 if (res == -EAGAIN)
114 goto retry;
115
116 return res;
117} 107}
118 108
119static void mnt_free_id(struct mount *mnt) 109static void mnt_free_id(struct mount *mnt)
120{ 110{
121 int id = mnt->mnt_id; 111 ida_free(&mnt_id_ida, mnt->mnt_id);
122 spin_lock(&mnt_id_lock);
123 ida_remove(&mnt_id_ida, id);
124 if (mnt_id_start > id)
125 mnt_id_start = id;
126 spin_unlock(&mnt_id_lock);
127} 112}
128 113
129/* 114/*
130 * Allocate a new peer group ID 115 * Allocate a new peer group ID
131 *
132 * mnt_group_ida is protected by namespace_sem
133 */ 116 */
134static int mnt_alloc_group_id(struct mount *mnt) 117static int mnt_alloc_group_id(struct mount *mnt)
135{ 118{
136 int res; 119 int res = ida_alloc_min(&mnt_group_ida, 1, GFP_KERNEL);
137 120
138 if (!ida_pre_get(&mnt_group_ida, GFP_KERNEL)) 121 if (res < 0)
139 return -ENOMEM; 122 return res;
140 123 mnt->mnt_group_id = res;
141 res = ida_get_new_above(&mnt_group_ida, 124 return 0;
142 mnt_group_start,
143 &mnt->mnt_group_id);
144 if (!res)
145 mnt_group_start = mnt->mnt_group_id + 1;
146
147 return res;
148} 125}
149 126
150/* 127/*
@@ -152,10 +129,7 @@ static int mnt_alloc_group_id(struct mount *mnt)
152 */ 129 */
153void mnt_release_group_id(struct mount *mnt) 130void mnt_release_group_id(struct mount *mnt)
154{ 131{
155 int id = mnt->mnt_group_id; 132 ida_free(&mnt_group_ida, mnt->mnt_group_id);
156 ida_remove(&mnt_group_ida, id);
157 if (mnt_group_start > id)
158 mnt_group_start = id;
159 mnt->mnt_group_id = 0; 133 mnt->mnt_group_id = 0;
160} 134}
161 135
diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c
index 03b8ba933eb2..235b959fc2b3 100644
--- a/fs/nilfs2/alloc.c
+++ b/fs/nilfs2/alloc.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * alloc.c - NILFS dat/inode allocator 3 * alloc.c - NILFS dat/inode allocator
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Originally written by Koji Sato. 7 * Originally written by Koji Sato.
17 * Two allocators were unified by Ryusuke Konishi and Amagai Yoshiji. 8 * Two allocators were unified by Ryusuke Konishi and Amagai Yoshiji.
18 */ 9 */
diff --git a/fs/nilfs2/alloc.h b/fs/nilfs2/alloc.h
index 05149e606a78..0303c3968cee 100644
--- a/fs/nilfs2/alloc.h
+++ b/fs/nilfs2/alloc.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * alloc.h - persistent object (dat entry/disk inode) allocator/deallocator 3 * alloc.h - persistent object (dat entry/disk inode) allocator/deallocator
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Originally written by Koji Sato. 7 * Originally written by Koji Sato.
17 * Two allocators were unified by Ryusuke Konishi and Amagai Yoshiji. 8 * Two allocators were unified by Ryusuke Konishi and Amagai Yoshiji.
18 */ 9 */
diff --git a/fs/nilfs2/bmap.c b/fs/nilfs2/bmap.c
index 01fb1831ca25..fb5a9a8a13cf 100644
--- a/fs/nilfs2/bmap.c
+++ b/fs/nilfs2/bmap.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * bmap.c - NILFS block mapping. 3 * bmap.c - NILFS block mapping.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/bmap.h b/fs/nilfs2/bmap.h
index 2b6ffbe5997a..2c63858e81c9 100644
--- a/fs/nilfs2/bmap.h
+++ b/fs/nilfs2/bmap.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * bmap.h - NILFS block mapping. 3 * bmap.h - NILFS block mapping.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c
index dec98cab729d..ebb24a314f43 100644
--- a/fs/nilfs2/btnode.c
+++ b/fs/nilfs2/btnode.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * btnode.c - NILFS B-tree node cache 3 * btnode.c - NILFS B-tree node cache
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Originally written by Seiji Kihara. 7 * Originally written by Seiji Kihara.
17 * Fully revised by Ryusuke Konishi for stabilization and simplification. 8 * Fully revised by Ryusuke Konishi for stabilization and simplification.
18 * 9 *
diff --git a/fs/nilfs2/btnode.h b/fs/nilfs2/btnode.h
index 4e8aaa1aeb65..0f88dbc9bcb3 100644
--- a/fs/nilfs2/btnode.h
+++ b/fs/nilfs2/btnode.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * btnode.h - NILFS B-tree node cache 3 * btnode.h - NILFS B-tree node cache
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Seiji Kihara. 7 * Written by Seiji Kihara.
17 * Revised by Ryusuke Konishi. 8 * Revised by Ryusuke Konishi.
18 */ 9 */
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index 16a7a67a11c9..23e043eca237 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * btree.c - NILFS B-tree. 3 * btree.c - NILFS B-tree.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/btree.h b/fs/nilfs2/btree.h
index 2184e47fa4bf..d1421b646ce4 100644
--- a/fs/nilfs2/btree.h
+++ b/fs/nilfs2/btree.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * btree.h - NILFS B-tree. 3 * btree.h - NILFS B-tree.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c
index a15a1601e931..8d41311b5db4 100644
--- a/fs/nilfs2/cpfile.c
+++ b/fs/nilfs2/cpfile.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * cpfile.c - NILFS checkpoint file. 3 * cpfile.c - NILFS checkpoint file.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/cpfile.h b/fs/nilfs2/cpfile.h
index 6eca972f9673..6336222df24a 100644
--- a/fs/nilfs2/cpfile.h
+++ b/fs/nilfs2/cpfile.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * cpfile.h - NILFS checkpoint file. 3 * cpfile.h - NILFS checkpoint file.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c
index dffedb2f8817..6f4066636be9 100644
--- a/fs/nilfs2/dat.c
+++ b/fs/nilfs2/dat.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * dat.c - NILFS disk address translation. 3 * dat.c - NILFS disk address translation.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/dat.h b/fs/nilfs2/dat.h
index 57dc6cf466d0..b17ee34580ae 100644
--- a/fs/nilfs2/dat.h
+++ b/fs/nilfs2/dat.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * dat.h - NILFS disk address translation. 3 * dat.h - NILFS disk address translation.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c
index 582831ab3eb9..81394e22d0a0 100644
--- a/fs/nilfs2/dir.c
+++ b/fs/nilfs2/dir.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * dir.c - NILFS directory entry operations 3 * dir.c - NILFS directory entry operations
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Modified for NILFS by Amagai Yoshiji. 7 * Modified for NILFS by Amagai Yoshiji.
17 */ 8 */
18/* 9/*
diff --git a/fs/nilfs2/direct.c b/fs/nilfs2/direct.c
index 96e3ed0d9652..533e24ea3a88 100644
--- a/fs/nilfs2/direct.c
+++ b/fs/nilfs2/direct.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * direct.c - NILFS direct block pointer. 3 * direct.c - NILFS direct block pointer.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/direct.h b/fs/nilfs2/direct.h
index cfe85e848bba..ec9a23c77994 100644
--- a/fs/nilfs2/direct.h
+++ b/fs/nilfs2/direct.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * direct.h - NILFS direct block pointer. 3 * direct.h - NILFS direct block pointer.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index 7da0fac71dc2..64bc81363c6c 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * file.c - NILFS regular file handling primitives including fsync(). 3 * file.c - NILFS regular file handling primitives including fsync().
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Amagai Yoshiji and Ryusuke Konishi. 7 * Written by Amagai Yoshiji and Ryusuke Konishi.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/gcinode.c b/fs/nilfs2/gcinode.c
index 853a831dcde0..aa3c328ee189 100644
--- a/fs/nilfs2/gcinode.c
+++ b/fs/nilfs2/gcinode.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * gcinode.c - dummy inodes to buffer blocks for garbage collection 3 * gcinode.c - dummy inodes to buffer blocks for garbage collection
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Seiji Kihara, Amagai Yoshiji, and Ryusuke Konishi. 7 * Written by Seiji Kihara, Amagai Yoshiji, and Ryusuke Konishi.
17 * Revised by Ryusuke Konishi. 8 * Revised by Ryusuke Konishi.
18 * 9 *
diff --git a/fs/nilfs2/ifile.c b/fs/nilfs2/ifile.c
index b8fa45c20c63..4140d232cadc 100644
--- a/fs/nilfs2/ifile.c
+++ b/fs/nilfs2/ifile.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * ifile.c - NILFS inode file 3 * ifile.c - NILFS inode file
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Amagai Yoshiji. 7 * Written by Amagai Yoshiji.
17 * Revised by Ryusuke Konishi. 8 * Revised by Ryusuke Konishi.
18 * 9 *
diff --git a/fs/nilfs2/ifile.h b/fs/nilfs2/ifile.h
index 188b94fe0ec5..a1e1e5711a05 100644
--- a/fs/nilfs2/ifile.h
+++ b/fs/nilfs2/ifile.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * ifile.h - NILFS inode file 3 * ifile.h - NILFS inode file
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Amagai Yoshiji. 7 * Written by Amagai Yoshiji.
17 * Revised by Ryusuke Konishi. 8 * Revised by Ryusuke Konishi.
18 * 9 *
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 6a612d832e7d..671085512e0f 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * inode.c - NILFS inode operations. 3 * inode.c - NILFS inode operations.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 * 8 *
18 */ 9 */
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 1d2c3d7711fe..9b96d79eea6c 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * ioctl.c - NILFS ioctl operations. 3 * ioctl.c - NILFS ioctl operations.
3 * 4 *
4 * Copyright (C) 2007, 2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2007, 2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
index c6bc1033e7d2..700870a92bc4 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * mdt.c - meta data file for NILFS 3 * mdt.c - meta data file for NILFS
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/mdt.h b/fs/nilfs2/mdt.h
index 3f67f3932097..e77aea4bb921 100644
--- a/fs/nilfs2/mdt.h
+++ b/fs/nilfs2/mdt.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * mdt.h - NILFS meta data file prototype and definitions 3 * mdt.h - NILFS meta data file prototype and definitions
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index dd52d3f82e8d..9fe6d4ab74f0 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * namei.c - NILFS pathname lookup operations. 3 * namei.c - NILFS pathname lookup operations.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Modified for NILFS by Amagai Yoshiji and Ryusuke Konishi. 7 * Modified for NILFS by Amagai Yoshiji and Ryusuke Konishi.
17 */ 8 */
18/* 9/*
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h
index 33f8c8fc96e8..a2f247b6a209 100644
--- a/fs/nilfs2/nilfs.h
+++ b/fs/nilfs2/nilfs.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * nilfs.h - NILFS local header file. 3 * nilfs.h - NILFS local header file.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato and Ryusuke Konishi. 7 * Written by Koji Sato and Ryusuke Konishi.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c
index 4cb850a6f1c2..329a056b73b1 100644
--- a/fs/nilfs2/page.c
+++ b/fs/nilfs2/page.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * page.c - buffer/page management specific to NILFS 3 * page.c - buffer/page management specific to NILFS
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi and Seiji Kihara. 7 * Written by Ryusuke Konishi and Seiji Kihara.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/page.h b/fs/nilfs2/page.h
index f3687c958fa8..62b9bb469e92 100644
--- a/fs/nilfs2/page.h
+++ b/fs/nilfs2/page.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * page.h - buffer/page management specific to NILFS 3 * page.h - buffer/page management specific to NILFS
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi and Seiji Kihara. 7 * Written by Ryusuke Konishi and Seiji Kihara.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c
index 5139efed1888..140b663e91c7 100644
--- a/fs/nilfs2/recovery.c
+++ b/fs/nilfs2/recovery.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * recovery.c - NILFS recovery logic 3 * recovery.c - NILFS recovery logic
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 68cb9e4740b4..20c479b5e41b 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * segbuf.c - NILFS segment buffer 3 * segbuf.c - NILFS segment buffer
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 * 8 *
18 */ 9 */
diff --git a/fs/nilfs2/segbuf.h b/fs/nilfs2/segbuf.h
index 10e16935fff6..9bea1bd59041 100644
--- a/fs/nilfs2/segbuf.h
+++ b/fs/nilfs2/segbuf.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * segbuf.h - NILFS Segment buffer prototypes and definitions 3 * segbuf.h - NILFS Segment buffer prototypes and definitions
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 * 8 *
18 */ 9 */
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 0953635e7d48..445eef41bfaf 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * segment.c - NILFS segment constructor. 3 * segment.c - NILFS segment constructor.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 * 8 *
18 */ 9 */
diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h
index 04634e3e3d58..f5cf5308f3fc 100644
--- a/fs/nilfs2/segment.h
+++ b/fs/nilfs2/segment.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * segment.h - NILFS Segment constructor prototypes and definitions 3 * segment.h - NILFS Segment constructor prototypes and definitions
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 * 8 *
18 */ 9 */
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c
index c7fa139d50e8..bf3f8f05c89b 100644
--- a/fs/nilfs2/sufile.c
+++ b/fs/nilfs2/sufile.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * sufile.c - NILFS segment usage file. 3 * sufile.c - NILFS segment usage file.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 * Revised by Ryusuke Konishi. 8 * Revised by Ryusuke Konishi.
18 */ 9 */
diff --git a/fs/nilfs2/sufile.h b/fs/nilfs2/sufile.h
index 673a891350f4..c4e2c7a7add1 100644
--- a/fs/nilfs2/sufile.h
+++ b/fs/nilfs2/sufile.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * sufile.h - NILFS segment usage file. 3 * sufile.h - NILFS segment usage file.
3 * 4 *
4 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Koji Sato. 7 * Written by Koji Sato.
17 */ 8 */
18 9
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 1b9067cf4511..26290aa1023f 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * super.c - NILFS module and super block management. 3 * super.c - NILFS module and super block management.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 */ 8 */
18/* 9/*
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
index 4b25837e7724..e60be7bb55b0 100644
--- a/fs/nilfs2/sysfs.c
+++ b/fs/nilfs2/sysfs.c
@@ -1,19 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * sysfs.c - sysfs support implementation. 3 * sysfs.c - sysfs support implementation.
3 * 4 *
4 * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
5 * Copyright (C) 2014 HGST, Inc., a Western Digital Company. 6 * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com> 8 * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>
18 */ 9 */
19 10
diff --git a/fs/nilfs2/sysfs.h b/fs/nilfs2/sysfs.h
index 648cedf9c06e..d001eb862dae 100644
--- a/fs/nilfs2/sysfs.h
+++ b/fs/nilfs2/sysfs.h
@@ -1,19 +1,10 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * sysfs.h - sysfs support declarations. 3 * sysfs.h - sysfs support declarations.
3 * 4 *
4 * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
5 * Copyright (C) 2014 HGST, Inc., a Western Digital Company. 6 * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com> 8 * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>
18 */ 9 */
19 10
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index 1a85317e83f0..484785cdf96e 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -1,18 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * the_nilfs.c - the_nilfs shared structure. 3 * the_nilfs.c - the_nilfs shared structure.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 * 8 *
18 */ 9 */
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h
index 36da1779f976..380a543c5b19 100644
--- a/fs/nilfs2/the_nilfs.h
+++ b/fs/nilfs2/the_nilfs.h
@@ -1,18 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * the_nilfs.h - the_nilfs shared structure. 3 * the_nilfs.h - the_nilfs shared structure.
3 * 4 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 5 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Written by Ryusuke Konishi. 7 * Written by Ryusuke Konishi.
17 * 8 *
18 */ 9 */
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index f174397b63a0..ababdbfab537 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -351,16 +351,9 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
351 351
352 iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu); 352 iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu);
353 353
354 if ((mask & FS_MODIFY) || 354 iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] =
355 (test_mask & to_tell->i_fsnotify_mask)) { 355 fsnotify_first_mark(&to_tell->i_fsnotify_marks);
356 iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] = 356 if (mnt) {
357 fsnotify_first_mark(&to_tell->i_fsnotify_marks);
358 }
359
360 if (mnt && ((mask & FS_MODIFY) ||
361 (test_mask & mnt->mnt_fsnotify_mask))) {
362 iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] =
363 fsnotify_first_mark(&to_tell->i_fsnotify_marks);
364 iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] = 357 iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] =
365 fsnotify_first_mark(&mnt->mnt_fsnotify_marks); 358 fsnotify_first_mark(&mnt->mnt_fsnotify_marks);
366 } 359 }
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 05506d60131c..59cdb27826de 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -132,13 +132,13 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
132 struct fsnotify_mark *mark; 132 struct fsnotify_mark *mark;
133 133
134 assert_spin_locked(&conn->lock); 134 assert_spin_locked(&conn->lock);
135 /* We can get detached connector here when inode is getting unlinked. */
136 if (!fsnotify_valid_obj_type(conn->type))
137 return;
135 hlist_for_each_entry(mark, &conn->list, obj_list) { 138 hlist_for_each_entry(mark, &conn->list, obj_list) {
136 if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) 139 if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED)
137 new_mask |= mark->mask; 140 new_mask |= mark->mask;
138 } 141 }
139 if (WARN_ON(!fsnotify_valid_obj_type(conn->type)))
140 return;
141
142 *fsnotify_conn_mask_p(conn) = new_mask; 142 *fsnotify_conn_mask_p(conn) = new_mask;
143} 143}
144 144
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 80464432dfe6..ad72261ee3fe 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -359,8 +359,11 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
359 phdr->p_type = PT_LOAD; 359 phdr->p_type = PT_LOAD;
360 phdr->p_flags = PF_R | PF_W | PF_X; 360 phdr->p_flags = PF_R | PF_W | PF_X;
361 phdr->p_offset = kc_vaddr_to_offset(m->addr) + data_offset; 361 phdr->p_offset = kc_vaddr_to_offset(m->addr) + data_offset;
362 phdr->p_vaddr = (size_t)m->addr; 362 if (m->type == KCORE_REMAP)
363 if (m->type == KCORE_RAM) 363 phdr->p_vaddr = (size_t)m->vaddr;
364 else
365 phdr->p_vaddr = (size_t)m->addr;
366 if (m->type == KCORE_RAM || m->type == KCORE_REMAP)
364 phdr->p_paddr = __pa(m->addr); 367 phdr->p_paddr = __pa(m->addr);
365 else if (m->type == KCORE_TEXT) 368 else if (m->type == KCORE_TEXT)
366 phdr->p_paddr = __pa_symbol(m->addr); 369 phdr->p_paddr = __pa_symbol(m->addr);
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index 951a14edcf51..0792595ebcfb 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -429,7 +429,12 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
429 vaddr = vmap(pages, page_count, VM_MAP, prot); 429 vaddr = vmap(pages, page_count, VM_MAP, prot);
430 kfree(pages); 430 kfree(pages);
431 431
432 return vaddr; 432 /*
433 * Since vmap() uses page granularity, we must add the offset
434 * into the page here, to get the byte granularity address
435 * into the mapping to represent the actual "start" location.
436 */
437 return vaddr + offset_in_page(start);
433} 438}
434 439
435static void *persistent_ram_iomap(phys_addr_t start, size_t size, 440static void *persistent_ram_iomap(phys_addr_t start, size_t size,
@@ -448,6 +453,11 @@ static void *persistent_ram_iomap(phys_addr_t start, size_t size,
448 else 453 else
449 va = ioremap_wc(start, size); 454 va = ioremap_wc(start, size);
450 455
456 /*
457 * Since request_mem_region() and ioremap() are byte-granularity
458 * there is no need handle anything special like we do when the
459 * vmap() case in persistent_ram_vmap() above.
460 */
451 return va; 461 return va;
452} 462}
453 463
@@ -468,7 +478,7 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
468 return -ENOMEM; 478 return -ENOMEM;
469 } 479 }
470 480
471 prz->buffer = prz->vaddr + offset_in_page(start); 481 prz->buffer = prz->vaddr;
472 prz->buffer_size = size - sizeof(struct persistent_ram_buffer); 482 prz->buffer_size = size - sizeof(struct persistent_ram_buffer);
473 483
474 return 0; 484 return 0;
@@ -515,7 +525,8 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
515 525
516 if (prz->vaddr) { 526 if (prz->vaddr) {
517 if (pfn_valid(prz->paddr >> PAGE_SHIFT)) { 527 if (pfn_valid(prz->paddr >> PAGE_SHIFT)) {
518 vunmap(prz->vaddr); 528 /* We must vunmap() at page-granularity. */
529 vunmap(prz->vaddr - offset_in_page(prz->paddr));
519 } else { 530 } else {
520 iounmap(prz->vaddr); 531 iounmap(prz->vaddr);
521 release_mem_region(prz->paddr, prz->size); 532 release_mem_region(prz->paddr, prz->size);
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 860bfbe7a07a..f0cbf58ad4da 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -18,6 +18,7 @@
18#include <linux/quotaops.h> 18#include <linux/quotaops.h>
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/writeback.h> 20#include <linux/writeback.h>
21#include <linux/nospec.h>
21 22
22static int check_quotactl_permission(struct super_block *sb, int type, int cmd, 23static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
23 qid_t id) 24 qid_t id)
@@ -120,8 +121,6 @@ static int quota_getinfo(struct super_block *sb, int type, void __user *addr)
120 struct if_dqinfo uinfo; 121 struct if_dqinfo uinfo;
121 int ret; 122 int ret;
122 123
123 /* This checks whether qc_state has enough entries... */
124 BUILD_BUG_ON(MAXQUOTAS > XQM_MAXQUOTAS);
125 if (!sb->s_qcop->get_state) 124 if (!sb->s_qcop->get_state)
126 return -ENOSYS; 125 return -ENOSYS;
127 ret = sb->s_qcop->get_state(sb, &state); 126 ret = sb->s_qcop->get_state(sb, &state);
@@ -354,10 +353,10 @@ static int quota_getstate(struct super_block *sb, struct fs_quota_stat *fqs)
354 * GETXSTATE quotactl has space for just one set of time limits so 353 * GETXSTATE quotactl has space for just one set of time limits so
355 * report them for the first enabled quota type 354 * report them for the first enabled quota type
356 */ 355 */
357 for (type = 0; type < XQM_MAXQUOTAS; type++) 356 for (type = 0; type < MAXQUOTAS; type++)
358 if (state.s_state[type].flags & QCI_ACCT_ENABLED) 357 if (state.s_state[type].flags & QCI_ACCT_ENABLED)
359 break; 358 break;
360 BUG_ON(type == XQM_MAXQUOTAS); 359 BUG_ON(type == MAXQUOTAS);
361 fqs->qs_btimelimit = state.s_state[type].spc_timelimit; 360 fqs->qs_btimelimit = state.s_state[type].spc_timelimit;
362 fqs->qs_itimelimit = state.s_state[type].ino_timelimit; 361 fqs->qs_itimelimit = state.s_state[type].ino_timelimit;
363 fqs->qs_rtbtimelimit = state.s_state[type].rt_spc_timelimit; 362 fqs->qs_rtbtimelimit = state.s_state[type].rt_spc_timelimit;
@@ -427,10 +426,10 @@ static int quota_getstatev(struct super_block *sb, struct fs_quota_statv *fqs)
427 * GETXSTATV quotactl has space for just one set of time limits so 426 * GETXSTATV quotactl has space for just one set of time limits so
428 * report them for the first enabled quota type 427 * report them for the first enabled quota type
429 */ 428 */
430 for (type = 0; type < XQM_MAXQUOTAS; type++) 429 for (type = 0; type < MAXQUOTAS; type++)
431 if (state.s_state[type].flags & QCI_ACCT_ENABLED) 430 if (state.s_state[type].flags & QCI_ACCT_ENABLED)
432 break; 431 break;
433 BUG_ON(type == XQM_MAXQUOTAS); 432 BUG_ON(type == MAXQUOTAS);
434 fqs->qs_btimelimit = state.s_state[type].spc_timelimit; 433 fqs->qs_btimelimit = state.s_state[type].spc_timelimit;
435 fqs->qs_itimelimit = state.s_state[type].ino_timelimit; 434 fqs->qs_itimelimit = state.s_state[type].ino_timelimit;
436 fqs->qs_rtbtimelimit = state.s_state[type].rt_spc_timelimit; 435 fqs->qs_rtbtimelimit = state.s_state[type].rt_spc_timelimit;
@@ -701,8 +700,9 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
701{ 700{
702 int ret; 701 int ret;
703 702
704 if (type >= (XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS)) 703 if (type >= MAXQUOTAS)
705 return -EINVAL; 704 return -EINVAL;
705 type = array_index_nospec(type, MAXQUOTAS);
706 /* 706 /*
707 * Quota not supported on this fs? Check this before s_quota_types 707 * Quota not supported on this fs? Check this before s_quota_types
708 * since they needn't be set if quota is not supported at all. 708 * since they needn't be set if quota is not supported at all.
diff --git a/fs/super.c b/fs/super.c
index 7429588d6b49..f3a8c008e164 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -981,58 +981,42 @@ void emergency_thaw_all(void)
981 } 981 }
982} 982}
983 983
984/*
985 * Unnamed block devices are dummy devices used by virtual
986 * filesystems which don't use real block-devices. -- jrs
987 */
988
989static DEFINE_IDA(unnamed_dev_ida); 984static DEFINE_IDA(unnamed_dev_ida);
990static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */
991/* Many userspace utilities consider an FSID of 0 invalid.
992 * Always return at least 1 from get_anon_bdev.
993 */
994static int unnamed_dev_start = 1;
995 985
986/**
987 * get_anon_bdev - Allocate a block device for filesystems which don't have one.
988 * @p: Pointer to a dev_t.
989 *
990 * Filesystems which don't use real block devices can call this function
991 * to allocate a virtual block device.
992 *
993 * Context: Any context. Frequently called while holding sb_lock.
994 * Return: 0 on success, -EMFILE if there are no anonymous bdevs left
995 * or -ENOMEM if memory allocation failed.
996 */
996int get_anon_bdev(dev_t *p) 997int get_anon_bdev(dev_t *p)
997{ 998{
998 int dev; 999 int dev;
999 int error;
1000 1000
1001 retry: 1001 /*
1002 if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0) 1002 * Many userspace utilities consider an FSID of 0 invalid.
1003 return -ENOMEM; 1003 * Always return at least 1 from get_anon_bdev.
1004 spin_lock(&unnamed_dev_lock); 1004 */
1005 error = ida_get_new_above(&unnamed_dev_ida, unnamed_dev_start, &dev); 1005 dev = ida_alloc_range(&unnamed_dev_ida, 1, (1 << MINORBITS) - 1,
1006 if (!error) 1006 GFP_ATOMIC);
1007 unnamed_dev_start = dev + 1; 1007 if (dev == -ENOSPC)
1008 spin_unlock(&unnamed_dev_lock); 1008 dev = -EMFILE;
1009 if (error == -EAGAIN) 1009 if (dev < 0)
1010 /* We raced and lost with another CPU. */ 1010 return dev;
1011 goto retry; 1011
1012 else if (error) 1012 *p = MKDEV(0, dev);
1013 return -EAGAIN;
1014
1015 if (dev >= (1 << MINORBITS)) {
1016 spin_lock(&unnamed_dev_lock);
1017 ida_remove(&unnamed_dev_ida, dev);
1018 if (unnamed_dev_start > dev)
1019 unnamed_dev_start = dev;
1020 spin_unlock(&unnamed_dev_lock);
1021 return -EMFILE;
1022 }
1023 *p = MKDEV(0, dev & MINORMASK);
1024 return 0; 1013 return 0;
1025} 1014}
1026EXPORT_SYMBOL(get_anon_bdev); 1015EXPORT_SYMBOL(get_anon_bdev);
1027 1016
1028void free_anon_bdev(dev_t dev) 1017void free_anon_bdev(dev_t dev)
1029{ 1018{
1030 int slot = MINOR(dev); 1019 ida_free(&unnamed_dev_ida, MINOR(dev));
1031 spin_lock(&unnamed_dev_lock);
1032 ida_remove(&unnamed_dev_ida, slot);
1033 if (slot < unnamed_dev_start)
1034 unnamed_dev_start = slot;
1035 spin_unlock(&unnamed_dev_lock);
1036} 1020}
1037EXPORT_SYMBOL(free_anon_bdev); 1021EXPORT_SYMBOL(free_anon_bdev);
1038 1022
@@ -1040,7 +1024,6 @@ int set_anon_super(struct super_block *s, void *data)
1040{ 1024{
1041 return get_anon_bdev(&s->s_dev); 1025 return get_anon_bdev(&s->s_dev);
1042} 1026}
1043
1044EXPORT_SYMBOL(set_anon_super); 1027EXPORT_SYMBOL(set_anon_super);
1045 1028
1046void kill_anon_super(struct super_block *sb) 1029void kill_anon_super(struct super_block *sb)
@@ -1049,7 +1032,6 @@ void kill_anon_super(struct super_block *sb)
1049 generic_shutdown_super(sb); 1032 generic_shutdown_super(sb);
1050 free_anon_bdev(dev); 1033 free_anon_bdev(dev);
1051} 1034}
1052
1053EXPORT_SYMBOL(kill_anon_super); 1035EXPORT_SYMBOL(kill_anon_super);
1054 1036
1055void kill_litter_super(struct super_block *sb) 1037void kill_litter_super(struct super_block *sb)
@@ -1058,7 +1040,6 @@ void kill_litter_super(struct super_block *sb)
1058 d_genocide(sb->s_root); 1040 d_genocide(sb->s_root);
1059 kill_anon_super(sb); 1041 kill_anon_super(sb);
1060} 1042}
1061
1062EXPORT_SYMBOL(kill_litter_super); 1043EXPORT_SYMBOL(kill_litter_super);
1063 1044
1064static int ns_test_super(struct super_block *sb, void *data) 1045static int ns_test_super(struct super_block *sb, void *data)
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 3040dc2a32f6..6f515651a2c2 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -764,9 +764,7 @@ static int udf_find_fileset(struct super_block *sb,
764 struct kernel_lb_addr *root) 764 struct kernel_lb_addr *root)
765{ 765{
766 struct buffer_head *bh = NULL; 766 struct buffer_head *bh = NULL;
767 long lastblock;
768 uint16_t ident; 767 uint16_t ident;
769 struct udf_sb_info *sbi;
770 768
771 if (fileset->logicalBlockNum != 0xFFFFFFFF || 769 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
772 fileset->partitionReferenceNum != 0xFFFF) { 770 fileset->partitionReferenceNum != 0xFFFF) {
@@ -779,69 +777,11 @@ static int udf_find_fileset(struct super_block *sb,
779 return 1; 777 return 1;
780 } 778 }
781 779
782 }
783
784 sbi = UDF_SB(sb);
785 if (!bh) {
786 /* Search backwards through the partitions */
787 struct kernel_lb_addr newfileset;
788
789/* --> cvg: FIXME - is it reasonable? */
790 return 1;
791
792 for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
793 (newfileset.partitionReferenceNum != 0xFFFF &&
794 fileset->logicalBlockNum == 0xFFFFFFFF &&
795 fileset->partitionReferenceNum == 0xFFFF);
796 newfileset.partitionReferenceNum--) {
797 lastblock = sbi->s_partmaps
798 [newfileset.partitionReferenceNum]
799 .s_partition_len;
800 newfileset.logicalBlockNum = 0;
801
802 do {
803 bh = udf_read_ptagged(sb, &newfileset, 0,
804 &ident);
805 if (!bh) {
806 newfileset.logicalBlockNum++;
807 continue;
808 }
809
810 switch (ident) {
811 case TAG_IDENT_SBD:
812 {
813 struct spaceBitmapDesc *sp;
814 sp = (struct spaceBitmapDesc *)
815 bh->b_data;
816 newfileset.logicalBlockNum += 1 +
817 ((le32_to_cpu(sp->numOfBytes) +
818 sizeof(struct spaceBitmapDesc)
819 - 1) >> sb->s_blocksize_bits);
820 brelse(bh);
821 break;
822 }
823 case TAG_IDENT_FSD:
824 *fileset = newfileset;
825 break;
826 default:
827 newfileset.logicalBlockNum++;
828 brelse(bh);
829 bh = NULL;
830 break;
831 }
832 } while (newfileset.logicalBlockNum < lastblock &&
833 fileset->logicalBlockNum == 0xFFFFFFFF &&
834 fileset->partitionReferenceNum == 0xFFFF);
835 }
836 }
837
838 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
839 fileset->partitionReferenceNum != 0xFFFF) && bh) {
840 udf_debug("Fileset at block=%u, partition=%u\n", 780 udf_debug("Fileset at block=%u, partition=%u\n",
841 fileset->logicalBlockNum, 781 fileset->logicalBlockNum,
842 fileset->partitionReferenceNum); 782 fileset->partitionReferenceNum);
843 783
844 sbi->s_partition = fileset->partitionReferenceNum; 784 UDF_SB(sb)->s_partition = fileset->partitionReferenceNum;
845 udf_load_fileset(sb, bh, root); 785 udf_load_fileset(sb, bh, root);
846 brelse(bh); 786 brelse(bh);
847 return 0; 787 return 0;
@@ -1570,10 +1510,16 @@ static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_
1570 */ 1510 */
1571#define PART_DESC_ALLOC_STEP 32 1511#define PART_DESC_ALLOC_STEP 32
1572 1512
1513struct part_desc_seq_scan_data {
1514 struct udf_vds_record rec;
1515 u32 partnum;
1516};
1517
1573struct desc_seq_scan_data { 1518struct desc_seq_scan_data {
1574 struct udf_vds_record vds[VDS_POS_LENGTH]; 1519 struct udf_vds_record vds[VDS_POS_LENGTH];
1575 unsigned int size_part_descs; 1520 unsigned int size_part_descs;
1576 struct udf_vds_record *part_descs_loc; 1521 unsigned int num_part_descs;
1522 struct part_desc_seq_scan_data *part_descs_loc;
1577}; 1523};
1578 1524
1579static struct udf_vds_record *handle_partition_descriptor( 1525static struct udf_vds_record *handle_partition_descriptor(
@@ -1582,10 +1528,14 @@ static struct udf_vds_record *handle_partition_descriptor(
1582{ 1528{
1583 struct partitionDesc *desc = (struct partitionDesc *)bh->b_data; 1529 struct partitionDesc *desc = (struct partitionDesc *)bh->b_data;
1584 int partnum; 1530 int partnum;
1531 int i;
1585 1532
1586 partnum = le16_to_cpu(desc->partitionNumber); 1533 partnum = le16_to_cpu(desc->partitionNumber);
1587 if (partnum >= data->size_part_descs) { 1534 for (i = 0; i < data->num_part_descs; i++)
1588 struct udf_vds_record *new_loc; 1535 if (partnum == data->part_descs_loc[i].partnum)
1536 return &(data->part_descs_loc[i].rec);
1537 if (data->num_part_descs >= data->size_part_descs) {
1538 struct part_desc_seq_scan_data *new_loc;
1589 unsigned int new_size = ALIGN(partnum, PART_DESC_ALLOC_STEP); 1539 unsigned int new_size = ALIGN(partnum, PART_DESC_ALLOC_STEP);
1590 1540
1591 new_loc = kcalloc(new_size, sizeof(*new_loc), GFP_KERNEL); 1541 new_loc = kcalloc(new_size, sizeof(*new_loc), GFP_KERNEL);
@@ -1597,7 +1547,7 @@ static struct udf_vds_record *handle_partition_descriptor(
1597 data->part_descs_loc = new_loc; 1547 data->part_descs_loc = new_loc;
1598 data->size_part_descs = new_size; 1548 data->size_part_descs = new_size;
1599 } 1549 }
1600 return &(data->part_descs_loc[partnum]); 1550 return &(data->part_descs_loc[data->num_part_descs++].rec);
1601} 1551}
1602 1552
1603 1553
@@ -1647,6 +1597,7 @@ static noinline int udf_process_sequence(
1647 1597
1648 memset(data.vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); 1598 memset(data.vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1649 data.size_part_descs = PART_DESC_ALLOC_STEP; 1599 data.size_part_descs = PART_DESC_ALLOC_STEP;
1600 data.num_part_descs = 0;
1650 data.part_descs_loc = kcalloc(data.size_part_descs, 1601 data.part_descs_loc = kcalloc(data.size_part_descs,
1651 sizeof(*data.part_descs_loc), 1602 sizeof(*data.part_descs_loc),
1652 GFP_KERNEL); 1603 GFP_KERNEL);
@@ -1658,7 +1609,6 @@ static noinline int udf_process_sequence(
1658 * are in it. 1609 * are in it.
1659 */ 1610 */
1660 for (; (!done && block <= lastblock); block++) { 1611 for (; (!done && block <= lastblock); block++) {
1661
1662 bh = udf_read_tagged(sb, block, block, &ident); 1612 bh = udf_read_tagged(sb, block, block, &ident);
1663 if (!bh) 1613 if (!bh)
1664 break; 1614 break;
@@ -1730,13 +1680,10 @@ static noinline int udf_process_sequence(
1730 } 1680 }
1731 1681
1732 /* Now handle prevailing Partition Descriptors */ 1682 /* Now handle prevailing Partition Descriptors */
1733 for (i = 0; i < data.size_part_descs; i++) { 1683 for (i = 0; i < data.num_part_descs; i++) {
1734 if (data.part_descs_loc[i].block) { 1684 ret = udf_load_partdesc(sb, data.part_descs_loc[i].rec.block);
1735 ret = udf_load_partdesc(sb, 1685 if (ret < 0)
1736 data.part_descs_loc[i].block); 1686 return ret;
1737 if (ret < 0)
1738 return ret;
1739 }
1740 } 1687 }
1741 1688
1742 return 0; 1689 return 0;
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index f173b5f30dbe..7b75ff6e2fce 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -54,8 +54,6 @@
54#define LOAD_OFFSET 0 54#define LOAD_OFFSET 0
55#endif 55#endif
56 56
57#include <linux/export.h>
58
59/* Align . to a 8 byte boundary equals to maximum function alignment. */ 57/* Align . to a 8 byte boundary equals to maximum function alignment. */
60#define ALIGN_FUNCTION() . = ALIGN(8) 58#define ALIGN_FUNCTION() . = ALIGN(8)
61 59
diff --git a/include/dt-bindings/reset/amlogic,meson-axg-audio-arb.h b/include/dt-bindings/reset/amlogic,meson-axg-audio-arb.h
new file mode 100644
index 000000000000..05c36367875c
--- /dev/null
+++ b/include/dt-bindings/reset/amlogic,meson-axg-audio-arb.h
@@ -0,0 +1,17 @@
1/* SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 *
3 * Copyright (c) 2018 Baylibre SAS.
4 * Author: Jerome Brunet <jbrunet@baylibre.com>
5 */
6
7#ifndef _DT_BINDINGS_AMLOGIC_MESON_AXG_AUDIO_ARB_H
8#define _DT_BINDINGS_AMLOGIC_MESON_AXG_AUDIO_ARB_H
9
10#define AXG_ARB_TODDR_A 0
11#define AXG_ARB_TODDR_B 1
12#define AXG_ARB_TODDR_C 2
13#define AXG_ARB_FRDDR_A 3
14#define AXG_ARB_FRDDR_B 4
15#define AXG_ARB_FRDDR_C 5
16
17#endif /* _DT_BINDINGS_AMLOGIC_MESON_AXG_AUDIO_ARB_H */
diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h
index ca1d2cc2cdfa..18863d56273c 100644
--- a/include/linux/arm-smccc.h
+++ b/include/linux/arm-smccc.h
@@ -199,47 +199,57 @@ asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1,
199 199
200#define __declare_arg_0(a0, res) \ 200#define __declare_arg_0(a0, res) \
201 struct arm_smccc_res *___res = res; \ 201 struct arm_smccc_res *___res = res; \
202 register u32 r0 asm("r0") = a0; \ 202 register unsigned long r0 asm("r0") = (u32)a0; \
203 register unsigned long r1 asm("r1"); \ 203 register unsigned long r1 asm("r1"); \
204 register unsigned long r2 asm("r2"); \ 204 register unsigned long r2 asm("r2"); \
205 register unsigned long r3 asm("r3") 205 register unsigned long r3 asm("r3")
206 206
207#define __declare_arg_1(a0, a1, res) \ 207#define __declare_arg_1(a0, a1, res) \
208 typeof(a1) __a1 = a1; \
208 struct arm_smccc_res *___res = res; \ 209 struct arm_smccc_res *___res = res; \
209 register u32 r0 asm("r0") = a0; \ 210 register unsigned long r0 asm("r0") = (u32)a0; \
210 register typeof(a1) r1 asm("r1") = a1; \ 211 register unsigned long r1 asm("r1") = __a1; \
211 register unsigned long r2 asm("r2"); \ 212 register unsigned long r2 asm("r2"); \
212 register unsigned long r3 asm("r3") 213 register unsigned long r3 asm("r3")
213 214
214#define __declare_arg_2(a0, a1, a2, res) \ 215#define __declare_arg_2(a0, a1, a2, res) \
216 typeof(a1) __a1 = a1; \
217 typeof(a2) __a2 = a2; \
215 struct arm_smccc_res *___res = res; \ 218 struct arm_smccc_res *___res = res; \
216 register u32 r0 asm("r0") = a0; \ 219 register unsigned long r0 asm("r0") = (u32)a0; \
217 register typeof(a1) r1 asm("r1") = a1; \ 220 register unsigned long r1 asm("r1") = __a1; \
218 register typeof(a2) r2 asm("r2") = a2; \ 221 register unsigned long r2 asm("r2") = __a2; \
219 register unsigned long r3 asm("r3") 222 register unsigned long r3 asm("r3")
220 223
221#define __declare_arg_3(a0, a1, a2, a3, res) \ 224#define __declare_arg_3(a0, a1, a2, a3, res) \
225 typeof(a1) __a1 = a1; \
226 typeof(a2) __a2 = a2; \
227 typeof(a3) __a3 = a3; \
222 struct arm_smccc_res *___res = res; \ 228 struct arm_smccc_res *___res = res; \
223 register u32 r0 asm("r0") = a0; \ 229 register unsigned long r0 asm("r0") = (u32)a0; \
224 register typeof(a1) r1 asm("r1") = a1; \ 230 register unsigned long r1 asm("r1") = __a1; \
225 register typeof(a2) r2 asm("r2") = a2; \ 231 register unsigned long r2 asm("r2") = __a2; \
226 register typeof(a3) r3 asm("r3") = a3 232 register unsigned long r3 asm("r3") = __a3
227 233
228#define __declare_arg_4(a0, a1, a2, a3, a4, res) \ 234#define __declare_arg_4(a0, a1, a2, a3, a4, res) \
235 typeof(a4) __a4 = a4; \
229 __declare_arg_3(a0, a1, a2, a3, res); \ 236 __declare_arg_3(a0, a1, a2, a3, res); \
230 register typeof(a4) r4 asm("r4") = a4 237 register unsigned long r4 asm("r4") = __a4
231 238
232#define __declare_arg_5(a0, a1, a2, a3, a4, a5, res) \ 239#define __declare_arg_5(a0, a1, a2, a3, a4, a5, res) \
240 typeof(a5) __a5 = a5; \
233 __declare_arg_4(a0, a1, a2, a3, a4, res); \ 241 __declare_arg_4(a0, a1, a2, a3, a4, res); \
234 register typeof(a5) r5 asm("r5") = a5 242 register unsigned long r5 asm("r5") = __a5
235 243
236#define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res) \ 244#define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res) \
245 typeof(a6) __a6 = a6; \
237 __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ 246 __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \
238 register typeof(a6) r6 asm("r6") = a6 247 register unsigned long r6 asm("r6") = __a6
239 248
240#define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res) \ 249#define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res) \
250 typeof(a7) __a7 = a7; \
241 __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ 251 __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \
242 register typeof(a7) r7 asm("r7") = a7 252 register unsigned long r7 asm("r7") = __a7
243 253
244#define ___declare_args(count, ...) __declare_arg_ ## count(__VA_ARGS__) 254#define ___declare_args(count, ...) __declare_arg_ ## count(__VA_ARGS__)
245#define __declare_args(count, ...) ___declare_args(count, __VA_ARGS__) 255#define __declare_args(count, ...) ___declare_args(count, __VA_ARGS__)
diff --git a/include/linux/dax.h b/include/linux/dax.h
index deb0f663252f..450b28db9533 100644
--- a/include/linux/dax.h
+++ b/include/linux/dax.h
@@ -88,6 +88,8 @@ int dax_writeback_mapping_range(struct address_space *mapping,
88 struct block_device *bdev, struct writeback_control *wbc); 88 struct block_device *bdev, struct writeback_control *wbc);
89 89
90struct page *dax_layout_busy_page(struct address_space *mapping); 90struct page *dax_layout_busy_page(struct address_space *mapping);
91bool dax_lock_mapping_entry(struct page *page);
92void dax_unlock_mapping_entry(struct page *page);
91#else 93#else
92static inline bool bdev_dax_supported(struct block_device *bdev, 94static inline bool bdev_dax_supported(struct block_device *bdev,
93 int blocksize) 95 int blocksize)
@@ -119,6 +121,17 @@ static inline int dax_writeback_mapping_range(struct address_space *mapping,
119{ 121{
120 return -EOPNOTSUPP; 122 return -EOPNOTSUPP;
121} 123}
124
125static inline bool dax_lock_mapping_entry(struct page *page)
126{
127 if (IS_DAX(page->mapping->host))
128 return true;
129 return false;
130}
131
132static inline void dax_unlock_mapping_entry(struct page *page)
133{
134}
122#endif 135#endif
123 136
124int dax_read_lock(void); 137int dax_read_lock(void);
diff --git a/include/linux/export.h b/include/linux/export.h
index ae072bc5aacf..ce764a5d2ee4 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -10,13 +10,6 @@
10 * hackers place grumpy comments in header files. 10 * hackers place grumpy comments in header files.
11 */ 11 */
12 12
13#define __VMLINUX_SYMBOL(x) x
14#define __VMLINUX_SYMBOL_STR(x) #x
15
16/* Indirect, so macros are expanded before pasting. */
17#define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x)
18#define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x)
19
20#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
21#ifdef MODULE 14#ifdef MODULE
22extern struct module __this_module; 15extern struct module __this_module;
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 834e6461a690..d44a78362942 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -526,6 +526,7 @@ struct hid_input {
526 const char *name; 526 const char *name;
527 bool registered; 527 bool registered;
528 struct list_head reports; /* the list of reports */ 528 struct list_head reports; /* the list of reports */
529 unsigned int application; /* application usage for this input */
529}; 530};
530 531
531enum hid_type { 532enum hid_type {
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 27e3e32135a8..99c19b06d9a4 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -3,6 +3,7 @@
3#define _LINUX_HUGE_MM_H 3#define _LINUX_HUGE_MM_H
4 4
5#include <linux/sched/coredump.h> 5#include <linux/sched/coredump.h>
6#include <linux/mm_types.h>
6 7
7#include <linux/fs.h> /* only for vma_is_dax() */ 8#include <linux/fs.h> /* only for vma_is_dax() */
8 9
@@ -46,9 +47,9 @@ extern bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
46extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, 47extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
47 unsigned long addr, pgprot_t newprot, 48 unsigned long addr, pgprot_t newprot,
48 int prot_numa); 49 int prot_numa);
49int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr, 50vm_fault_t vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
50 pmd_t *pmd, pfn_t pfn, bool write); 51 pmd_t *pmd, pfn_t pfn, bool write);
51int vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr, 52vm_fault_t vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
52 pud_t *pud, pfn_t pfn, bool write); 53 pud_t *pud, pfn_t pfn, bool write);
53enum transparent_hugepage_flag { 54enum transparent_hugepage_flag {
54 TRANSPARENT_HUGEPAGE_FLAG, 55 TRANSPARENT_HUGEPAGE_FLAG,
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index b79387fd57da..65b4eaed1d96 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -855,7 +855,7 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
855} 855}
856 856
857u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold); 857u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
858void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf); 858void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
859 859
860int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr); 860int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
861/** 861/**
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 3e8215b2c371..3ec8628ce17f 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -236,34 +236,74 @@ struct ida {
236} 236}
237#define DEFINE_IDA(name) struct ida name = IDA_INIT(name) 237#define DEFINE_IDA(name) struct ida name = IDA_INIT(name)
238 238
239int ida_pre_get(struct ida *ida, gfp_t gfp_mask); 239int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t);
240int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); 240void ida_free(struct ida *, unsigned int id);
241void ida_remove(struct ida *ida, int id);
242void ida_destroy(struct ida *ida); 241void ida_destroy(struct ida *ida);
243 242
244int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, 243/**
245 gfp_t gfp_mask); 244 * ida_alloc() - Allocate an unused ID.
246void ida_simple_remove(struct ida *ida, unsigned int id); 245 * @ida: IDA handle.
246 * @gfp: Memory allocation flags.
247 *
248 * Allocate an ID between 0 and %INT_MAX, inclusive.
249 *
250 * Context: Any context.
251 * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
252 * or %-ENOSPC if there are no free IDs.
253 */
254static inline int ida_alloc(struct ida *ida, gfp_t gfp)
255{
256 return ida_alloc_range(ida, 0, ~0, gfp);
257}
247 258
248static inline void ida_init(struct ida *ida) 259/**
260 * ida_alloc_min() - Allocate an unused ID.
261 * @ida: IDA handle.
262 * @min: Lowest ID to allocate.
263 * @gfp: Memory allocation flags.
264 *
265 * Allocate an ID between @min and %INT_MAX, inclusive.
266 *
267 * Context: Any context.
268 * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
269 * or %-ENOSPC if there are no free IDs.
270 */
271static inline int ida_alloc_min(struct ida *ida, unsigned int min, gfp_t gfp)
249{ 272{
250 INIT_RADIX_TREE(&ida->ida_rt, IDR_RT_MARKER | GFP_NOWAIT); 273 return ida_alloc_range(ida, min, ~0, gfp);
251} 274}
252 275
253/** 276/**
254 * ida_get_new - allocate new ID 277 * ida_alloc_max() - Allocate an unused ID.
255 * @ida: idr handle 278 * @ida: IDA handle.
256 * @p_id: pointer to the allocated handle 279 * @max: Highest ID to allocate.
280 * @gfp: Memory allocation flags.
281 *
282 * Allocate an ID between 0 and @max, inclusive.
257 * 283 *
258 * Simple wrapper around ida_get_new_above() w/ @starting_id of zero. 284 * Context: Any context.
285 * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
286 * or %-ENOSPC if there are no free IDs.
259 */ 287 */
260static inline int ida_get_new(struct ida *ida, int *p_id) 288static inline int ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp)
261{ 289{
262 return ida_get_new_above(ida, 0, p_id); 290 return ida_alloc_range(ida, 0, max, gfp);
263} 291}
264 292
293static inline void ida_init(struct ida *ida)
294{
295 INIT_RADIX_TREE(&ida->ida_rt, IDR_RT_MARKER | GFP_NOWAIT);
296}
297
298#define ida_simple_get(ida, start, end, gfp) \
299 ida_alloc_range(ida, start, (end) - 1, gfp)
300#define ida_simple_remove(ida, id) ida_free(ida, id)
301
265static inline bool ida_is_empty(const struct ida *ida) 302static inline bool ida_is_empty(const struct ida *ida)
266{ 303{
267 return radix_tree_empty(&ida->ida_rt); 304 return radix_tree_empty(&ida->ida_rt);
268} 305}
306
307/* in lib/radix-tree.c */
308int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
269#endif /* __IDR_H__ */ 309#endif /* __IDR_H__ */
diff --git a/include/linux/kcore.h b/include/linux/kcore.h
index c20f296438fb..8c3f8c14eeaa 100644
--- a/include/linux/kcore.h
+++ b/include/linux/kcore.h
@@ -12,11 +12,13 @@ enum kcore_type {
12 KCORE_VMEMMAP, 12 KCORE_VMEMMAP,
13 KCORE_USER, 13 KCORE_USER,
14 KCORE_OTHER, 14 KCORE_OTHER,
15 KCORE_REMAP,
15}; 16};
16 17
17struct kcore_list { 18struct kcore_list {
18 struct list_head list; 19 struct list_head list;
19 unsigned long addr; 20 unsigned long addr;
21 unsigned long vaddr;
20 size_t size; 22 size_t size;
21 int type; 23 int type;
22}; 24};
@@ -36,11 +38,22 @@ struct vmcoredd_node {
36 38
37#ifdef CONFIG_PROC_KCORE 39#ifdef CONFIG_PROC_KCORE
38void __init kclist_add(struct kcore_list *, void *, size_t, int type); 40void __init kclist_add(struct kcore_list *, void *, size_t, int type);
41static inline
42void kclist_add_remap(struct kcore_list *m, void *addr, void *vaddr, size_t sz)
43{
44 m->vaddr = (unsigned long)vaddr;
45 kclist_add(m, addr, sz, KCORE_REMAP);
46}
39#else 47#else
40static inline 48static inline
41void kclist_add(struct kcore_list *new, void *addr, size_t size, int type) 49void kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
42{ 50{
43} 51}
52
53static inline
54void kclist_add_remap(struct kcore_list *m, void *addr, void *vaddr, size_t sz)
55{
56}
44#endif 57#endif
45 58
46#endif /* _LINUX_KCORE_H */ 59#endif /* _LINUX_KCORE_H */
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 7a452716de4b..66d94b4557cf 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -362,8 +362,8 @@ struct mlx5_frag_buf {
362struct mlx5_frag_buf_ctrl { 362struct mlx5_frag_buf_ctrl {
363 struct mlx5_frag_buf frag_buf; 363 struct mlx5_frag_buf frag_buf;
364 u32 sz_m1; 364 u32 sz_m1;
365 u32 frag_sz_m1; 365 u16 frag_sz_m1;
366 u32 strides_offset; 366 u16 strides_offset;
367 u8 log_sz; 367 u8 log_sz;
368 u8 log_stride; 368 u8 log_stride;
369 u8 log_frag_strides; 369 u8 log_frag_strides;
@@ -995,7 +995,7 @@ static inline u32 mlx5_base_mkey(const u32 key)
995} 995}
996 996
997static inline void mlx5_fill_fbc_offset(u8 log_stride, u8 log_sz, 997static inline void mlx5_fill_fbc_offset(u8 log_stride, u8 log_sz,
998 u32 strides_offset, 998 u16 strides_offset,
999 struct mlx5_frag_buf_ctrl *fbc) 999 struct mlx5_frag_buf_ctrl *fbc)
1000{ 1000{
1001 fbc->log_stride = log_stride; 1001 fbc->log_stride = log_stride;
@@ -1052,7 +1052,7 @@ int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
1052void mlx5_health_cleanup(struct mlx5_core_dev *dev); 1052void mlx5_health_cleanup(struct mlx5_core_dev *dev);
1053int mlx5_health_init(struct mlx5_core_dev *dev); 1053int mlx5_health_init(struct mlx5_core_dev *dev);
1054void mlx5_start_health_poll(struct mlx5_core_dev *dev); 1054void mlx5_start_health_poll(struct mlx5_core_dev *dev);
1055void mlx5_stop_health_poll(struct mlx5_core_dev *dev); 1055void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health);
1056void mlx5_drain_health_wq(struct mlx5_core_dev *dev); 1056void mlx5_drain_health_wq(struct mlx5_core_dev *dev);
1057void mlx5_trigger_health_work(struct mlx5_core_dev *dev); 1057void mlx5_trigger_health_work(struct mlx5_core_dev *dev);
1058void mlx5_drain_health_recovery(struct mlx5_core_dev *dev); 1058void mlx5_drain_health_recovery(struct mlx5_core_dev *dev);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8fcc36660de6..a61ebe8ad4ca 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2731,6 +2731,7 @@ enum mf_action_page_type {
2731 MF_MSG_TRUNCATED_LRU, 2731 MF_MSG_TRUNCATED_LRU,
2732 MF_MSG_BUDDY, 2732 MF_MSG_BUDDY,
2733 MF_MSG_BUDDY_2ND, 2733 MF_MSG_BUDDY_2ND,
2734 MF_MSG_DAX,
2734 MF_MSG_UNKNOWN, 2735 MF_MSG_UNKNOWN,
2735}; 2736};
2736 2737
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index cd2bc939efd0..5ed8f6292a53 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -341,7 +341,7 @@ struct mm_struct {
341 struct { 341 struct {
342 struct vm_area_struct *mmap; /* list of VMAs */ 342 struct vm_area_struct *mmap; /* list of VMAs */
343 struct rb_root mm_rb; 343 struct rb_root mm_rb;
344 u32 vmacache_seqnum; /* per-thread vmacache */ 344 u64 vmacache_seqnum; /* per-thread vmacache */
345#ifdef CONFIG_MMU 345#ifdef CONFIG_MMU
346 unsigned long (*get_unmapped_area) (struct file *filp, 346 unsigned long (*get_unmapped_area) (struct file *filp,
347 unsigned long addr, unsigned long len, 347 unsigned long addr, unsigned long len,
diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
index 5fe87687664c..d7016dcb245e 100644
--- a/include/linux/mm_types_task.h
+++ b/include/linux/mm_types_task.h
@@ -32,7 +32,7 @@
32#define VMACACHE_MASK (VMACACHE_SIZE - 1) 32#define VMACACHE_MASK (VMACACHE_SIZE - 1)
33 33
34struct vmacache { 34struct vmacache {
35 u32 seqnum; 35 u64 seqnum;
36 struct vm_area_struct *vmas[VMACACHE_SIZE]; 36 struct vm_area_struct *vmas[VMACACHE_SIZE];
37}; 37};
38 38
diff --git a/include/linux/of.h b/include/linux/of.h
index 4d25e4f952d9..99b0ebf49632 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -256,6 +256,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
256#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) 256#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
257#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) 257#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
258 258
259extern bool of_node_name_eq(const struct device_node *np, const char *name);
260extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);
261
259static inline const char *of_node_full_name(const struct device_node *np) 262static inline const char *of_node_full_name(const struct device_node *np)
260{ 263{
261 return np ? np->full_name : "<no-node>"; 264 return np ? np->full_name : "<no-node>";
@@ -290,6 +293,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
290extern struct device_node *of_get_next_available_child( 293extern struct device_node *of_get_next_available_child(
291 const struct device_node *node, struct device_node *prev); 294 const struct device_node *node, struct device_node *prev);
292 295
296extern struct device_node *of_get_compatible_child(const struct device_node *parent,
297 const char *compatible);
293extern struct device_node *of_get_child_by_name(const struct device_node *node, 298extern struct device_node *of_get_child_by_name(const struct device_node *node,
294 const char *name); 299 const char *name);
295 300
@@ -561,6 +566,16 @@ static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
561 return NULL; 566 return NULL;
562} 567}
563 568
569static inline bool of_node_name_eq(const struct device_node *np, const char *name)
570{
571 return false;
572}
573
574static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
575{
576 return false;
577}
578
564static inline const char* of_node_full_name(const struct device_node *np) 579static inline const char* of_node_full_name(const struct device_node *np)
565{ 580{
566 return "<no-node>"; 581 return "<no-node>";
@@ -632,6 +647,12 @@ static inline bool of_have_populated_dt(void)
632 return false; 647 return false;
633} 648}
634 649
650static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
651 const char *compatible)
652{
653 return NULL;
654}
655
635static inline struct device_node *of_get_child_by_name( 656static inline struct device_node *of_get_child_by_name(
636 const struct device_node *node, 657 const struct device_node *node,
637 const char *name) 658 const char *name)
@@ -967,6 +988,18 @@ static inline struct device_node *of_find_matching_node(
967 return of_find_matching_node_and_match(from, matches, NULL); 988 return of_find_matching_node_and_match(from, matches, NULL);
968} 989}
969 990
991static inline const char *of_node_get_device_type(const struct device_node *np)
992{
993 return of_get_property(np, "type", NULL);
994}
995
996static inline bool of_node_is_type(const struct device_node *np, const char *type)
997{
998 const char *match = of_node_get_device_type(np);
999
1000 return np && match && type && !strcmp(match, type);
1001}
1002
970/** 1003/**
971 * of_property_count_u8_elems - Count the number of u8 elements in a property 1004 * of_property_count_u8_elems - Count the number of u8 elements in a property
972 * 1005 *
diff --git a/include/linux/pci.h b/include/linux/pci.h
index e72ca8dd6241..6925828f9f25 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1235,6 +1235,9 @@ void pci_bus_remove_resources(struct pci_bus *bus);
1235int devm_request_pci_bus_resources(struct device *dev, 1235int devm_request_pci_bus_resources(struct device *dev,
1236 struct list_head *resources); 1236 struct list_head *resources);
1237 1237
1238/* Temporary until new and working PCI SBR API in place */
1239int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
1240
1238#define pci_bus_for_each_resource(bus, res, i) \ 1241#define pci_bus_for_each_resource(bus, res, i) \
1239 for (i = 0; \ 1242 for (i = 0; \
1240 (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \ 1243 (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 99d366cb0e9f..d157983b84cf 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -3084,4 +3084,6 @@
3084 3084
3085#define PCI_VENDOR_ID_OCZ 0x1b85 3085#define PCI_VENDOR_ID_OCZ 0x1b85
3086 3086
3087#define PCI_VENDOR_ID_NCUBE 0x10ff
3088
3087#endif /* _LINUX_PCI_IDS_H */ 3089#endif /* _LINUX_PCI_IDS_H */
diff --git a/include/linux/platform_data/ina2xx.h b/include/linux/platform_data/ina2xx.h
index 9abc0ca7259b..9f0aa1b48c78 100644
--- a/include/linux/platform_data/ina2xx.h
+++ b/include/linux/platform_data/ina2xx.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for Texas Instruments INA219, INA226 power monitor chips 2 * Driver for Texas Instruments INA219, INA226 power monitor chips
3 * 3 *
4 * Copyright (C) 2012 Lothar Felten <l-felten@ti.com> 4 * Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
diff --git a/include/linux/quota.h b/include/linux/quota.h
index ca9772c8e48b..f32dd270b8e3 100644
--- a/include/linux/quota.h
+++ b/include/linux/quota.h
@@ -408,13 +408,7 @@ struct qc_type_state {
408 408
409struct qc_state { 409struct qc_state {
410 unsigned int s_incoredqs; /* Number of dquots in core */ 410 unsigned int s_incoredqs; /* Number of dquots in core */
411 /* 411 struct qc_type_state s_state[MAXQUOTAS]; /* Per quota type information */
412 * Per quota type information. The array should really have
413 * max(MAXQUOTAS, XQM_MAXQUOTAS) entries. BUILD_BUG_ON in
414 * quota_getinfo() makes sure XQM_MAXQUOTAS is large enough. Once VFS
415 * supports project quotas, this can be changed to MAXQUOTAS
416 */
417 struct qc_type_state s_state[XQM_MAXQUOTAS];
418}; 412};
419 413
420/* Structure for communicating via ->set_info */ 414/* Structure for communicating via ->set_info */
diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h
index da5178216da5..2a986d282a97 100644
--- a/include/linux/set_memory.h
+++ b/include/linux/set_memory.h
@@ -17,6 +17,20 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }
17static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } 17static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
18#endif 18#endif
19 19
20#ifndef set_mce_nospec
21static inline int set_mce_nospec(unsigned long pfn)
22{
23 return 0;
24}
25#endif
26
27#ifndef clear_mce_nospec
28static inline int clear_mce_nospec(unsigned long pfn)
29{
30 return 0;
31}
32#endif
33
20#ifndef CONFIG_ARCH_HAS_MEM_ENCRYPT 34#ifndef CONFIG_ARCH_HAS_MEM_ENCRYPT
21static inline int set_memory_encrypted(unsigned long addr, int numpages) 35static inline int set_memory_encrypted(unsigned long addr, int numpages)
22{ 36{
diff --git a/include/linux/time32.h b/include/linux/time32.h
index 0b14f936100a..d1ae43c13e25 100644
--- a/include/linux/time32.h
+++ b/include/linux/time32.h
@@ -207,4 +207,19 @@ static inline s64 timeval_to_ns(const struct timeval *tv)
207extern struct timeval ns_to_timeval(const s64 nsec); 207extern struct timeval ns_to_timeval(const s64 nsec);
208extern struct __kernel_old_timeval ns_to_kernel_old_timeval(s64 nsec); 208extern struct __kernel_old_timeval ns_to_kernel_old_timeval(s64 nsec);
209 209
210/*
211 * New aliases for compat time functions. These will be used to replace
212 * the compat code so it can be shared between 32-bit and 64-bit builds
213 * both of which provide compatibility with old 32-bit tasks.
214 */
215#define old_time32_t compat_time_t
216#define old_timeval32 compat_timeval
217#define old_timespec32 compat_timespec
218#define old_itimerspec32 compat_itimerspec
219#define ns_to_old_timeval32 ns_to_compat_timeval
220#define get_old_itimerspec32 get_compat_itimerspec64
221#define put_old_itimerspec32 put_compat_itimerspec64
222#define get_old_timespec32 compat_get_timespec64
223#define put_old_timespec32 compat_put_timespec64
224
210#endif 225#endif
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 5d738804e3d6..a5a3cfc3c2fa 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -258,8 +258,8 @@ extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot);
258extern int persistent_clock_is_local; 258extern int persistent_clock_is_local;
259 259
260extern void read_persistent_clock64(struct timespec64 *ts); 260extern void read_persistent_clock64(struct timespec64 *ts);
261void read_persistent_clock_and_boot_offset(struct timespec64 *wall_clock, 261void read_persistent_wall_and_boot_offset(struct timespec64 *wall_clock,
262 struct timespec64 *boot_offset); 262 struct timespec64 *boot_offset);
263extern int update_persistent_clock64(struct timespec64 now); 263extern int update_persistent_clock64(struct timespec64 now);
264 264
265/* 265/*
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index 7f2e16e76ac4..041f7e56a289 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -158,8 +158,10 @@ extern void syscall_unregfunc(void);
158 * For rcuidle callers, use srcu since sched-rcu \ 158 * For rcuidle callers, use srcu since sched-rcu \
159 * doesn't work from the idle path. \ 159 * doesn't work from the idle path. \
160 */ \ 160 */ \
161 if (rcuidle) \ 161 if (rcuidle) { \
162 idx = srcu_read_lock_notrace(&tracepoint_srcu); \ 162 idx = srcu_read_lock_notrace(&tracepoint_srcu); \
163 rcu_irq_enter_irqson(); \
164 } \
163 \ 165 \
164 it_func_ptr = rcu_dereference_raw((tp)->funcs); \ 166 it_func_ptr = rcu_dereference_raw((tp)->funcs); \
165 \ 167 \
@@ -171,8 +173,10 @@ extern void syscall_unregfunc(void);
171 } while ((++it_func_ptr)->func); \ 173 } while ((++it_func_ptr)->func); \
172 } \ 174 } \
173 \ 175 \
174 if (rcuidle) \ 176 if (rcuidle) { \
177 rcu_irq_exit_irqson(); \
175 srcu_read_unlock_notrace(&tracepoint_srcu, idx);\ 178 srcu_read_unlock_notrace(&tracepoint_srcu, idx);\
179 } \
176 \ 180 \
177 preempt_enable_notrace(); \ 181 preempt_enable_notrace(); \
178 } while (0) 182 } while (0)
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 5c7f010676a7..47a3441cf4c4 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -105,7 +105,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
105#ifdef CONFIG_DEBUG_VM_VMACACHE 105#ifdef CONFIG_DEBUG_VM_VMACACHE
106 VMACACHE_FIND_CALLS, 106 VMACACHE_FIND_CALLS,
107 VMACACHE_FIND_HITS, 107 VMACACHE_FIND_HITS,
108 VMACACHE_FULL_FLUSHES,
109#endif 108#endif
110#ifdef CONFIG_SWAP 109#ifdef CONFIG_SWAP
111 SWAP_RA, 110 SWAP_RA,
diff --git a/include/linux/vmacache.h b/include/linux/vmacache.h
index 3e9a963edd6a..6fce268a4588 100644
--- a/include/linux/vmacache.h
+++ b/include/linux/vmacache.h
@@ -10,7 +10,6 @@ static inline void vmacache_flush(struct task_struct *tsk)
10 memset(tsk->vmacache.vmas, 0, sizeof(tsk->vmacache.vmas)); 10 memset(tsk->vmacache.vmas, 0, sizeof(tsk->vmacache.vmas));
11} 11}
12 12
13extern void vmacache_flush_all(struct mm_struct *mm);
14extern void vmacache_update(unsigned long addr, struct vm_area_struct *newvma); 13extern void vmacache_update(unsigned long addr, struct vm_area_struct *newvma);
15extern struct vm_area_struct *vmacache_find(struct mm_struct *mm, 14extern struct vm_area_struct *vmacache_find(struct mm_struct *mm,
16 unsigned long addr); 15 unsigned long addr);
@@ -24,10 +23,6 @@ extern struct vm_area_struct *vmacache_find_exact(struct mm_struct *mm,
24static inline void vmacache_invalidate(struct mm_struct *mm) 23static inline void vmacache_invalidate(struct mm_struct *mm)
25{ 24{
26 mm->vmacache_seqnum++; 25 mm->vmacache_seqnum++;
27
28 /* deal with overflows */
29 if (unlikely(mm->vmacache_seqnum == 0))
30 vmacache_flush_all(mm);
31} 26}
32 27
33#endif /* __LINUX_VMACACHE_H */ 28#endif /* __LINUX_VMACACHE_H */
diff --git a/include/net/act_api.h b/include/net/act_api.h
index 1ad5b19e83a9..970303448c90 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -23,13 +23,11 @@ struct tc_action {
23 const struct tc_action_ops *ops; 23 const struct tc_action_ops *ops;
24 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ 24 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
25 __u32 order; 25 __u32 order;
26 struct list_head list;
27 struct tcf_idrinfo *idrinfo; 26 struct tcf_idrinfo *idrinfo;
28 27
29 u32 tcfa_index; 28 u32 tcfa_index;
30 refcount_t tcfa_refcnt; 29 refcount_t tcfa_refcnt;
31 atomic_t tcfa_bindcnt; 30 atomic_t tcfa_bindcnt;
32 u32 tcfa_capab;
33 int tcfa_action; 31 int tcfa_action;
34 struct tcf_t tcfa_tm; 32 struct tcf_t tcfa_tm;
35 struct gnet_stats_basic_packed tcfa_bstats; 33 struct gnet_stats_basic_packed tcfa_bstats;
@@ -44,7 +42,6 @@ struct tc_action {
44#define tcf_index common.tcfa_index 42#define tcf_index common.tcfa_index
45#define tcf_refcnt common.tcfa_refcnt 43#define tcf_refcnt common.tcfa_refcnt
46#define tcf_bindcnt common.tcfa_bindcnt 44#define tcf_bindcnt common.tcfa_bindcnt
47#define tcf_capab common.tcfa_capab
48#define tcf_action common.tcfa_action 45#define tcf_action common.tcfa_action
49#define tcf_tm common.tcfa_tm 46#define tcf_tm common.tcfa_tm
50#define tcf_bstats common.tcfa_bstats 47#define tcf_bstats common.tcfa_bstats
@@ -102,7 +99,6 @@ struct tc_action_ops {
102 size_t (*get_fill_size)(const struct tc_action *act); 99 size_t (*get_fill_size)(const struct tc_action *act);
103 struct net_device *(*get_dev)(const struct tc_action *a); 100 struct net_device *(*get_dev)(const struct tc_action *a);
104 void (*put_dev)(struct net_device *dev); 101 void (*put_dev)(struct net_device *dev);
105 int (*delete)(struct net *net, u32 index);
106}; 102};
107 103
108struct tc_action_net { 104struct tc_action_net {
@@ -148,8 +144,6 @@ int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
148 const struct tc_action_ops *ops, 144 const struct tc_action_ops *ops,
149 struct netlink_ext_ack *extack); 145 struct netlink_ext_ack *extack);
150int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index); 146int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index);
151bool tcf_idr_check(struct tc_action_net *tn, u32 index, struct tc_action **a,
152 int bind);
153int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, 147int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
154 struct tc_action **a, const struct tc_action_ops *ops, 148 struct tc_action **a, const struct tc_action_ops *ops,
155 int bind, bool cpustats); 149 int bind, bool cpustats);
@@ -158,7 +152,6 @@ void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a);
158void tcf_idr_cleanup(struct tc_action_net *tn, u32 index); 152void tcf_idr_cleanup(struct tc_action_net *tn, u32 index);
159int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index, 153int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,
160 struct tc_action **a, int bind); 154 struct tc_action **a, int bind);
161int tcf_idr_delete_index(struct tc_action_net *tn, u32 index);
162int __tcf_idr_release(struct tc_action *a, bool bind, bool strict); 155int __tcf_idr_release(struct tc_action *a, bool bind, bool strict);
163 156
164static inline int tcf_idr_release(struct tc_action *a, bool bind) 157static inline int tcf_idr_release(struct tc_action *a, bool bind)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 9a850973e09a..8ebabc9873d1 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -4865,8 +4865,8 @@ const char *reg_initiator_name(enum nl80211_reg_initiator initiator);
4865 * 4865 *
4866 * Return: 0 on success. -ENODATA. 4866 * Return: 0 on success. -ENODATA.
4867 */ 4867 */
4868int reg_query_regdb_wmm(char *alpha2, int freq, u32 *ptr, 4868int reg_query_regdb_wmm(char *alpha2, int freq,
4869 struct ieee80211_wmm_rule *rule); 4869 struct ieee80211_reg_rule *rule);
4870 4870
4871/* 4871/*
4872 * callbacks for asynchronous cfg80211 methods, notification 4872 * callbacks for asynchronous cfg80211 methods, notification
diff --git a/include/net/netfilter/nf_conntrack_timeout.h b/include/net/netfilter/nf_conntrack_timeout.h
index d5f62cc6c2ae..3394d75e1c80 100644
--- a/include/net/netfilter/nf_conntrack_timeout.h
+++ b/include/net/netfilter/nf_conntrack_timeout.h
@@ -30,7 +30,7 @@ struct nf_conn_timeout {
30}; 30};
31 31
32static inline unsigned int * 32static inline unsigned int *
33nf_ct_timeout_data(struct nf_conn_timeout *t) 33nf_ct_timeout_data(const struct nf_conn_timeout *t)
34{ 34{
35 struct nf_ct_timeout *timeout; 35 struct nf_ct_timeout *timeout;
36 36
diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index ef727f71336e..75a3f3fdb359 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -298,19 +298,13 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)
298#endif 298#endif
299} 299}
300 300
301static inline void tcf_exts_to_list(const struct tcf_exts *exts,
302 struct list_head *actions)
303{
304#ifdef CONFIG_NET_CLS_ACT 301#ifdef CONFIG_NET_CLS_ACT
305 int i; 302#define tcf_exts_for_each_action(i, a, exts) \
306 303 for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = (exts)->actions[i]); i++)
307 for (i = 0; i < exts->nr_actions; i++) { 304#else
308 struct tc_action *a = exts->actions[i]; 305#define tcf_exts_for_each_action(i, a, exts) \
309 306 for (; 0; (void)(i), (void)(a), (void)(exts))
310 list_add_tail(&a->list, actions);
311 }
312#endif 307#endif
313}
314 308
315static inline void 309static inline void
316tcf_exts_stats_update(const struct tcf_exts *exts, 310tcf_exts_stats_update(const struct tcf_exts *exts,
@@ -361,6 +355,15 @@ static inline bool tcf_exts_has_one_action(struct tcf_exts *exts)
361#endif 355#endif
362} 356}
363 357
358static inline struct tc_action *tcf_exts_first_action(struct tcf_exts *exts)
359{
360#ifdef CONFIG_NET_CLS_ACT
361 return exts->actions[0];
362#else
363 return NULL;
364#endif
365}
366
364/** 367/**
365 * tcf_exts_exec - execute tc filter extensions 368 * tcf_exts_exec - execute tc filter extensions
366 * @skb: socket buffer 369 * @skb: socket buffer
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index 60f8cc86a447..3469750df0f4 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -217,15 +217,15 @@ struct ieee80211_wmm_rule {
217struct ieee80211_reg_rule { 217struct ieee80211_reg_rule {
218 struct ieee80211_freq_range freq_range; 218 struct ieee80211_freq_range freq_range;
219 struct ieee80211_power_rule power_rule; 219 struct ieee80211_power_rule power_rule;
220 struct ieee80211_wmm_rule *wmm_rule; 220 struct ieee80211_wmm_rule wmm_rule;
221 u32 flags; 221 u32 flags;
222 u32 dfs_cac_ms; 222 u32 dfs_cac_ms;
223 bool has_wmm;
223}; 224};
224 225
225struct ieee80211_regdomain { 226struct ieee80211_regdomain {
226 struct rcu_head rcu_head; 227 struct rcu_head rcu_head;
227 u32 n_reg_rules; 228 u32 n_reg_rules;
228 u32 n_wmm_rules;
229 char alpha2[3]; 229 char alpha2[3];
230 enum nl80211_dfs_regions dfs_region; 230 enum nl80211_dfs_regions dfs_region;
231 struct ieee80211_reg_rule reg_rules[]; 231 struct ieee80211_reg_rule reg_rules[];
diff --git a/include/uapi/linux/keyctl.h b/include/uapi/linux/keyctl.h
index 7b8c9e19bad1..910cc4334b21 100644
--- a/include/uapi/linux/keyctl.h
+++ b/include/uapi/linux/keyctl.h
@@ -65,7 +65,7 @@
65 65
66/* keyctl structures */ 66/* keyctl structures */
67struct keyctl_dh_params { 67struct keyctl_dh_params {
68 __s32 private; 68 __s32 dh_private;
69 __s32 prime; 69 __s32 prime;
70 __s32 base; 70 __s32 base;
71}; 71};
diff --git a/include/uapi/linux/rds.h b/include/uapi/linux/rds.h
index dc520e1a4123..8b73cb603c5f 100644
--- a/include/uapi/linux/rds.h
+++ b/include/uapi/linux/rds.h
@@ -37,6 +37,7 @@
37 37
38#include <linux/types.h> 38#include <linux/types.h>
39#include <linux/socket.h> /* For __kernel_sockaddr_storage. */ 39#include <linux/socket.h> /* For __kernel_sockaddr_storage. */
40#include <linux/in6.h> /* For struct in6_addr. */
40 41
41#define RDS_IB_ABI_VERSION 0x301 42#define RDS_IB_ABI_VERSION 0x301
42 43
diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
index b1e22c40c4b6..84c3de89696a 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -176,7 +176,7 @@ struct vhost_memory {
176#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 176#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
177 177
178#define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) 178#define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
179#define VHOST_GET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x26, __u64) 179#define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
180 180
181/* VHOST_NET specific defines */ 181/* VHOST_NET specific defines */
182 182
diff --git a/init/Kconfig b/init/Kconfig
index 641dd7dd7c8a..1e234e2f1cba 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1097,6 +1097,8 @@ config LD_DEAD_CODE_DATA_ELIMINATION
1097 bool "Dead code and data elimination (EXPERIMENTAL)" 1097 bool "Dead code and data elimination (EXPERIMENTAL)"
1098 depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION 1098 depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION
1099 depends on EXPERT 1099 depends on EXPERT
1100 depends on $(cc-option,-ffunction-sections -fdata-sections)
1101 depends on $(ld-option,--gc-sections)
1100 help 1102 help
1101 Enable this if you want to do dead code and data elimination with 1103 Enable this if you want to do dead code and data elimination with
1102 the linker by compiling with -ffunction-sections -fdata-sections, 1104 the linker by compiling with -ffunction-sections -fdata-sections,
diff --git a/ipc/shm.c b/ipc/shm.c
index b0eb3757ab89..4cd402e4cfeb 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -199,6 +199,7 @@ static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id)
199 } 199 }
200 200
201 ipc_unlock_object(ipcp); 201 ipc_unlock_object(ipcp);
202 ipcp = ERR_PTR(-EIDRM);
202err: 203err:
203 rcu_read_unlock(); 204 rcu_read_unlock();
204 /* 205 /*
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 04b8eda94e7d..03cc59ee9c95 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -15,6 +15,7 @@
15#include <linux/jhash.h> 15#include <linux/jhash.h>
16#include <linux/filter.h> 16#include <linux/filter.h>
17#include <linux/rculist_nulls.h> 17#include <linux/rculist_nulls.h>
18#include <linux/random.h>
18#include <uapi/linux/btf.h> 19#include <uapi/linux/btf.h>
19#include "percpu_freelist.h" 20#include "percpu_freelist.h"
20#include "bpf_lru_list.h" 21#include "bpf_lru_list.h"
@@ -41,6 +42,7 @@ struct bpf_htab {
41 atomic_t count; /* number of elements in this hashtable */ 42 atomic_t count; /* number of elements in this hashtable */
42 u32 n_buckets; /* number of hash buckets */ 43 u32 n_buckets; /* number of hash buckets */
43 u32 elem_size; /* size of each element in bytes */ 44 u32 elem_size; /* size of each element in bytes */
45 u32 hashrnd;
44}; 46};
45 47
46/* each htab element is struct htab_elem + key + value */ 48/* each htab element is struct htab_elem + key + value */
@@ -371,6 +373,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
371 if (!htab->buckets) 373 if (!htab->buckets)
372 goto free_htab; 374 goto free_htab;
373 375
376 htab->hashrnd = get_random_int();
374 for (i = 0; i < htab->n_buckets; i++) { 377 for (i = 0; i < htab->n_buckets; i++) {
375 INIT_HLIST_NULLS_HEAD(&htab->buckets[i].head, i); 378 INIT_HLIST_NULLS_HEAD(&htab->buckets[i].head, i);
376 raw_spin_lock_init(&htab->buckets[i].lock); 379 raw_spin_lock_init(&htab->buckets[i].lock);
@@ -402,9 +405,9 @@ free_htab:
402 return ERR_PTR(err); 405 return ERR_PTR(err);
403} 406}
404 407
405static inline u32 htab_map_hash(const void *key, u32 key_len) 408static inline u32 htab_map_hash(const void *key, u32 key_len, u32 hashrnd)
406{ 409{
407 return jhash(key, key_len, 0); 410 return jhash(key, key_len, hashrnd);
408} 411}
409 412
410static inline struct bucket *__select_bucket(struct bpf_htab *htab, u32 hash) 413static inline struct bucket *__select_bucket(struct bpf_htab *htab, u32 hash)
@@ -470,7 +473,7 @@ static void *__htab_map_lookup_elem(struct bpf_map *map, void *key)
470 473
471 key_size = map->key_size; 474 key_size = map->key_size;
472 475
473 hash = htab_map_hash(key, key_size); 476 hash = htab_map_hash(key, key_size, htab->hashrnd);
474 477
475 head = select_bucket(htab, hash); 478 head = select_bucket(htab, hash);
476 479
@@ -597,7 +600,7 @@ static int htab_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
597 if (!key) 600 if (!key)
598 goto find_first_elem; 601 goto find_first_elem;
599 602
600 hash = htab_map_hash(key, key_size); 603 hash = htab_map_hash(key, key_size, htab->hashrnd);
601 604
602 head = select_bucket(htab, hash); 605 head = select_bucket(htab, hash);
603 606
@@ -824,7 +827,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
824 827
825 key_size = map->key_size; 828 key_size = map->key_size;
826 829
827 hash = htab_map_hash(key, key_size); 830 hash = htab_map_hash(key, key_size, htab->hashrnd);
828 831
829 b = __select_bucket(htab, hash); 832 b = __select_bucket(htab, hash);
830 head = &b->head; 833 head = &b->head;
@@ -880,7 +883,7 @@ static int htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value,
880 883
881 key_size = map->key_size; 884 key_size = map->key_size;
882 885
883 hash = htab_map_hash(key, key_size); 886 hash = htab_map_hash(key, key_size, htab->hashrnd);
884 887
885 b = __select_bucket(htab, hash); 888 b = __select_bucket(htab, hash);
886 head = &b->head; 889 head = &b->head;
@@ -945,7 +948,7 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
945 948
946 key_size = map->key_size; 949 key_size = map->key_size;
947 950
948 hash = htab_map_hash(key, key_size); 951 hash = htab_map_hash(key, key_size, htab->hashrnd);
949 952
950 b = __select_bucket(htab, hash); 953 b = __select_bucket(htab, hash);
951 head = &b->head; 954 head = &b->head;
@@ -998,7 +1001,7 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
998 1001
999 key_size = map->key_size; 1002 key_size = map->key_size;
1000 1003
1001 hash = htab_map_hash(key, key_size); 1004 hash = htab_map_hash(key, key_size, htab->hashrnd);
1002 1005
1003 b = __select_bucket(htab, hash); 1006 b = __select_bucket(htab, hash);
1004 head = &b->head; 1007 head = &b->head;
@@ -1071,7 +1074,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key)
1071 1074
1072 key_size = map->key_size; 1075 key_size = map->key_size;
1073 1076
1074 hash = htab_map_hash(key, key_size); 1077 hash = htab_map_hash(key, key_size, htab->hashrnd);
1075 b = __select_bucket(htab, hash); 1078 b = __select_bucket(htab, hash);
1076 head = &b->head; 1079 head = &b->head;
1077 1080
@@ -1103,7 +1106,7 @@ static int htab_lru_map_delete_elem(struct bpf_map *map, void *key)
1103 1106
1104 key_size = map->key_size; 1107 key_size = map->key_size;
1105 1108
1106 hash = htab_map_hash(key, key_size); 1109 hash = htab_map_hash(key, key_size, htab->hashrnd);
1107 b = __select_bucket(htab, hash); 1110 b = __select_bucket(htab, hash);
1108 head = &b->head; 1111 head = &b->head;
1109 1112
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 98e621a29e8e..488ef9663c01 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -236,7 +236,7 @@ static int bpf_tcp_init(struct sock *sk)
236} 236}
237 237
238static void smap_release_sock(struct smap_psock *psock, struct sock *sock); 238static void smap_release_sock(struct smap_psock *psock, struct sock *sock);
239static int free_start_sg(struct sock *sk, struct sk_msg_buff *md); 239static int free_start_sg(struct sock *sk, struct sk_msg_buff *md, bool charge);
240 240
241static void bpf_tcp_release(struct sock *sk) 241static void bpf_tcp_release(struct sock *sk)
242{ 242{
@@ -248,7 +248,7 @@ static void bpf_tcp_release(struct sock *sk)
248 goto out; 248 goto out;
249 249
250 if (psock->cork) { 250 if (psock->cork) {
251 free_start_sg(psock->sock, psock->cork); 251 free_start_sg(psock->sock, psock->cork, true);
252 kfree(psock->cork); 252 kfree(psock->cork);
253 psock->cork = NULL; 253 psock->cork = NULL;
254 } 254 }
@@ -330,14 +330,14 @@ static void bpf_tcp_close(struct sock *sk, long timeout)
330 close_fun = psock->save_close; 330 close_fun = psock->save_close;
331 331
332 if (psock->cork) { 332 if (psock->cork) {
333 free_start_sg(psock->sock, psock->cork); 333 free_start_sg(psock->sock, psock->cork, true);
334 kfree(psock->cork); 334 kfree(psock->cork);
335 psock->cork = NULL; 335 psock->cork = NULL;
336 } 336 }
337 337
338 list_for_each_entry_safe(md, mtmp, &psock->ingress, list) { 338 list_for_each_entry_safe(md, mtmp, &psock->ingress, list) {
339 list_del(&md->list); 339 list_del(&md->list);
340 free_start_sg(psock->sock, md); 340 free_start_sg(psock->sock, md, true);
341 kfree(md); 341 kfree(md);
342 } 342 }
343 343
@@ -369,7 +369,7 @@ static void bpf_tcp_close(struct sock *sk, long timeout)
369 /* If another thread deleted this object skip deletion. 369 /* If another thread deleted this object skip deletion.
370 * The refcnt on psock may or may not be zero. 370 * The refcnt on psock may or may not be zero.
371 */ 371 */
372 if (l) { 372 if (l && l == link) {
373 hlist_del_rcu(&link->hash_node); 373 hlist_del_rcu(&link->hash_node);
374 smap_release_sock(psock, link->sk); 374 smap_release_sock(psock, link->sk);
375 free_htab_elem(htab, link); 375 free_htab_elem(htab, link);
@@ -570,14 +570,16 @@ static void free_bytes_sg(struct sock *sk, int bytes,
570 md->sg_start = i; 570 md->sg_start = i;
571} 571}
572 572
573static int free_sg(struct sock *sk, int start, struct sk_msg_buff *md) 573static int free_sg(struct sock *sk, int start,
574 struct sk_msg_buff *md, bool charge)
574{ 575{
575 struct scatterlist *sg = md->sg_data; 576 struct scatterlist *sg = md->sg_data;
576 int i = start, free = 0; 577 int i = start, free = 0;
577 578
578 while (sg[i].length) { 579 while (sg[i].length) {
579 free += sg[i].length; 580 free += sg[i].length;
580 sk_mem_uncharge(sk, sg[i].length); 581 if (charge)
582 sk_mem_uncharge(sk, sg[i].length);
581 if (!md->skb) 583 if (!md->skb)
582 put_page(sg_page(&sg[i])); 584 put_page(sg_page(&sg[i]));
583 sg[i].length = 0; 585 sg[i].length = 0;
@@ -594,9 +596,9 @@ static int free_sg(struct sock *sk, int start, struct sk_msg_buff *md)
594 return free; 596 return free;
595} 597}
596 598
597static int free_start_sg(struct sock *sk, struct sk_msg_buff *md) 599static int free_start_sg(struct sock *sk, struct sk_msg_buff *md, bool charge)
598{ 600{
599 int free = free_sg(sk, md->sg_start, md); 601 int free = free_sg(sk, md->sg_start, md, charge);
600 602
601 md->sg_start = md->sg_end; 603 md->sg_start = md->sg_end;
602 return free; 604 return free;
@@ -604,7 +606,7 @@ static int free_start_sg(struct sock *sk, struct sk_msg_buff *md)
604 606
605static int free_curr_sg(struct sock *sk, struct sk_msg_buff *md) 607static int free_curr_sg(struct sock *sk, struct sk_msg_buff *md)
606{ 608{
607 return free_sg(sk, md->sg_curr, md); 609 return free_sg(sk, md->sg_curr, md, true);
608} 610}
609 611
610static int bpf_map_msg_verdict(int _rc, struct sk_msg_buff *md) 612static int bpf_map_msg_verdict(int _rc, struct sk_msg_buff *md)
@@ -718,7 +720,7 @@ static int bpf_tcp_ingress(struct sock *sk, int apply_bytes,
718 list_add_tail(&r->list, &psock->ingress); 720 list_add_tail(&r->list, &psock->ingress);
719 sk->sk_data_ready(sk); 721 sk->sk_data_ready(sk);
720 } else { 722 } else {
721 free_start_sg(sk, r); 723 free_start_sg(sk, r, true);
722 kfree(r); 724 kfree(r);
723 } 725 }
724 726
@@ -752,14 +754,10 @@ static int bpf_tcp_sendmsg_do_redirect(struct sock *sk, int send,
752 release_sock(sk); 754 release_sock(sk);
753 } 755 }
754 smap_release_sock(psock, sk); 756 smap_release_sock(psock, sk);
755 if (unlikely(err)) 757 return err;
756 goto out;
757 return 0;
758out_rcu: 758out_rcu:
759 rcu_read_unlock(); 759 rcu_read_unlock();
760out: 760 return 0;
761 free_bytes_sg(NULL, send, md, false);
762 return err;
763} 761}
764 762
765static inline void bpf_md_init(struct smap_psock *psock) 763static inline void bpf_md_init(struct smap_psock *psock)
@@ -822,7 +820,7 @@ more_data:
822 case __SK_PASS: 820 case __SK_PASS:
823 err = bpf_tcp_push(sk, send, m, flags, true); 821 err = bpf_tcp_push(sk, send, m, flags, true);
824 if (unlikely(err)) { 822 if (unlikely(err)) {
825 *copied -= free_start_sg(sk, m); 823 *copied -= free_start_sg(sk, m, true);
826 break; 824 break;
827 } 825 }
828 826
@@ -845,16 +843,17 @@ more_data:
845 lock_sock(sk); 843 lock_sock(sk);
846 844
847 if (unlikely(err < 0)) { 845 if (unlikely(err < 0)) {
848 free_start_sg(sk, m); 846 int free = free_start_sg(sk, m, false);
847
849 psock->sg_size = 0; 848 psock->sg_size = 0;
850 if (!cork) 849 if (!cork)
851 *copied -= send; 850 *copied -= free;
852 } else { 851 } else {
853 psock->sg_size -= send; 852 psock->sg_size -= send;
854 } 853 }
855 854
856 if (cork) { 855 if (cork) {
857 free_start_sg(sk, m); 856 free_start_sg(sk, m, true);
858 psock->sg_size = 0; 857 psock->sg_size = 0;
859 kfree(m); 858 kfree(m);
860 m = NULL; 859 m = NULL;
@@ -912,6 +911,8 @@ static int bpf_tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
912 911
913 if (unlikely(flags & MSG_ERRQUEUE)) 912 if (unlikely(flags & MSG_ERRQUEUE))
914 return inet_recv_error(sk, msg, len, addr_len); 913 return inet_recv_error(sk, msg, len, addr_len);
914 if (!skb_queue_empty(&sk->sk_receive_queue))
915 return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len);
915 916
916 rcu_read_lock(); 917 rcu_read_lock();
917 psock = smap_psock_sk(sk); 918 psock = smap_psock_sk(sk);
@@ -922,9 +923,6 @@ static int bpf_tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
922 goto out; 923 goto out;
923 rcu_read_unlock(); 924 rcu_read_unlock();
924 925
925 if (!skb_queue_empty(&sk->sk_receive_queue))
926 return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len);
927
928 lock_sock(sk); 926 lock_sock(sk);
929bytes_ready: 927bytes_ready:
930 while (copied != len) { 928 while (copied != len) {
@@ -1122,7 +1120,7 @@ wait_for_memory:
1122 err = sk_stream_wait_memory(sk, &timeo); 1120 err = sk_stream_wait_memory(sk, &timeo);
1123 if (err) { 1121 if (err) {
1124 if (m && m != psock->cork) 1122 if (m && m != psock->cork)
1125 free_start_sg(sk, m); 1123 free_start_sg(sk, m, true);
1126 goto out_err; 1124 goto out_err;
1127 } 1125 }
1128 } 1126 }
@@ -1427,12 +1425,15 @@ out:
1427static void smap_write_space(struct sock *sk) 1425static void smap_write_space(struct sock *sk)
1428{ 1426{
1429 struct smap_psock *psock; 1427 struct smap_psock *psock;
1428 void (*write_space)(struct sock *sk);
1430 1429
1431 rcu_read_lock(); 1430 rcu_read_lock();
1432 psock = smap_psock_sk(sk); 1431 psock = smap_psock_sk(sk);
1433 if (likely(psock && test_bit(SMAP_TX_RUNNING, &psock->state))) 1432 if (likely(psock && test_bit(SMAP_TX_RUNNING, &psock->state)))
1434 schedule_work(&psock->tx_work); 1433 schedule_work(&psock->tx_work);
1434 write_space = psock->save_write_space;
1435 rcu_read_unlock(); 1435 rcu_read_unlock();
1436 write_space(sk);
1436} 1437}
1437 1438
1438static void smap_stop_sock(struct smap_psock *psock, struct sock *sk) 1439static void smap_stop_sock(struct smap_psock *psock, struct sock *sk)
@@ -1461,10 +1462,16 @@ static void smap_destroy_psock(struct rcu_head *rcu)
1461 schedule_work(&psock->gc_work); 1462 schedule_work(&psock->gc_work);
1462} 1463}
1463 1464
1465static bool psock_is_smap_sk(struct sock *sk)
1466{
1467 return inet_csk(sk)->icsk_ulp_ops == &bpf_tcp_ulp_ops;
1468}
1469
1464static void smap_release_sock(struct smap_psock *psock, struct sock *sock) 1470static void smap_release_sock(struct smap_psock *psock, struct sock *sock)
1465{ 1471{
1466 if (refcount_dec_and_test(&psock->refcnt)) { 1472 if (refcount_dec_and_test(&psock->refcnt)) {
1467 tcp_cleanup_ulp(sock); 1473 if (psock_is_smap_sk(sock))
1474 tcp_cleanup_ulp(sock);
1468 write_lock_bh(&sock->sk_callback_lock); 1475 write_lock_bh(&sock->sk_callback_lock);
1469 smap_stop_sock(psock, sock); 1476 smap_stop_sock(psock, sock);
1470 write_unlock_bh(&sock->sk_callback_lock); 1477 write_unlock_bh(&sock->sk_callback_lock);
@@ -1578,13 +1585,13 @@ static void smap_gc_work(struct work_struct *w)
1578 bpf_prog_put(psock->bpf_tx_msg); 1585 bpf_prog_put(psock->bpf_tx_msg);
1579 1586
1580 if (psock->cork) { 1587 if (psock->cork) {
1581 free_start_sg(psock->sock, psock->cork); 1588 free_start_sg(psock->sock, psock->cork, true);
1582 kfree(psock->cork); 1589 kfree(psock->cork);
1583 } 1590 }
1584 1591
1585 list_for_each_entry_safe(md, mtmp, &psock->ingress, list) { 1592 list_for_each_entry_safe(md, mtmp, &psock->ingress, list) {
1586 list_del(&md->list); 1593 list_del(&md->list);
1587 free_start_sg(psock->sock, md); 1594 free_start_sg(psock->sock, md, true);
1588 kfree(md); 1595 kfree(md);
1589 } 1596 }
1590 1597
@@ -1891,6 +1898,10 @@ static int __sock_map_ctx_update_elem(struct bpf_map *map,
1891 * doesn't update user data. 1898 * doesn't update user data.
1892 */ 1899 */
1893 if (psock) { 1900 if (psock) {
1901 if (!psock_is_smap_sk(sock)) {
1902 err = -EBUSY;
1903 goto out_progs;
1904 }
1894 if (READ_ONCE(psock->bpf_parse) && parse) { 1905 if (READ_ONCE(psock->bpf_parse) && parse) {
1895 err = -EBUSY; 1906 err = -EBUSY;
1896 goto out_progs; 1907 goto out_progs;
@@ -2140,7 +2151,9 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
2140 return ERR_PTR(-EPERM); 2151 return ERR_PTR(-EPERM);
2141 2152
2142 /* check sanity of attributes */ 2153 /* check sanity of attributes */
2143 if (attr->max_entries == 0 || attr->value_size != 4 || 2154 if (attr->max_entries == 0 ||
2155 attr->key_size == 0 ||
2156 attr->value_size != 4 ||
2144 attr->map_flags & ~SOCK_CREATE_FLAG_MASK) 2157 attr->map_flags & ~SOCK_CREATE_FLAG_MASK)
2145 return ERR_PTR(-EINVAL); 2158 return ERR_PTR(-EINVAL);
2146 2159
@@ -2267,8 +2280,10 @@ static struct htab_elem *alloc_sock_hash_elem(struct bpf_htab *htab,
2267 } 2280 }
2268 l_new = kmalloc_node(htab->elem_size, GFP_ATOMIC | __GFP_NOWARN, 2281 l_new = kmalloc_node(htab->elem_size, GFP_ATOMIC | __GFP_NOWARN,
2269 htab->map.numa_node); 2282 htab->map.numa_node);
2270 if (!l_new) 2283 if (!l_new) {
2284 atomic_dec(&htab->count);
2271 return ERR_PTR(-ENOMEM); 2285 return ERR_PTR(-ENOMEM);
2286 }
2272 2287
2273 memcpy(l_new->key, key, key_size); 2288 memcpy(l_new->key, key, key_size);
2274 l_new->sk = sk; 2289 l_new->sk = sk;
diff --git a/kernel/cpu.c b/kernel/cpu.c
index ed44d7d34c2d..0097acec1c71 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -102,8 +102,6 @@ static inline void cpuhp_lock_release(bool bringup) { }
102 * @name: Name of the step 102 * @name: Name of the step
103 * @startup: Startup function of the step 103 * @startup: Startup function of the step
104 * @teardown: Teardown function of the step 104 * @teardown: Teardown function of the step
105 * @skip_onerr: Do not invoke the functions on error rollback
106 * Will go away once the notifiers are gone
107 * @cant_stop: Bringup/teardown can't be stopped at this step 105 * @cant_stop: Bringup/teardown can't be stopped at this step
108 */ 106 */
109struct cpuhp_step { 107struct cpuhp_step {
@@ -119,7 +117,6 @@ struct cpuhp_step {
119 struct hlist_node *node); 117 struct hlist_node *node);
120 } teardown; 118 } teardown;
121 struct hlist_head list; 119 struct hlist_head list;
122 bool skip_onerr;
123 bool cant_stop; 120 bool cant_stop;
124 bool multi_instance; 121 bool multi_instance;
125}; 122};
@@ -550,12 +547,8 @@ static int bringup_cpu(unsigned int cpu)
550 547
551static void undo_cpu_up(unsigned int cpu, struct cpuhp_cpu_state *st) 548static void undo_cpu_up(unsigned int cpu, struct cpuhp_cpu_state *st)
552{ 549{
553 for (st->state--; st->state > st->target; st->state--) { 550 for (st->state--; st->state > st->target; st->state--)
554 struct cpuhp_step *step = cpuhp_get_step(st->state); 551 cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL);
555
556 if (!step->skip_onerr)
557 cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL);
558 }
559} 552}
560 553
561static int cpuhp_up_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st, 554static int cpuhp_up_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
@@ -614,15 +607,15 @@ static void cpuhp_thread_fun(unsigned int cpu)
614 bool bringup = st->bringup; 607 bool bringup = st->bringup;
615 enum cpuhp_state state; 608 enum cpuhp_state state;
616 609
610 if (WARN_ON_ONCE(!st->should_run))
611 return;
612
617 /* 613 /*
618 * ACQUIRE for the cpuhp_should_run() load of ->should_run. Ensures 614 * ACQUIRE for the cpuhp_should_run() load of ->should_run. Ensures
619 * that if we see ->should_run we also see the rest of the state. 615 * that if we see ->should_run we also see the rest of the state.
620 */ 616 */
621 smp_mb(); 617 smp_mb();
622 618
623 if (WARN_ON_ONCE(!st->should_run))
624 return;
625
626 cpuhp_lock_acquire(bringup); 619 cpuhp_lock_acquire(bringup);
627 620
628 if (st->single) { 621 if (st->single) {
@@ -644,12 +637,6 @@ static void cpuhp_thread_fun(unsigned int cpu)
644 637
645 WARN_ON_ONCE(!cpuhp_is_ap_state(state)); 638 WARN_ON_ONCE(!cpuhp_is_ap_state(state));
646 639
647 if (st->rollback) {
648 struct cpuhp_step *step = cpuhp_get_step(state);
649 if (step->skip_onerr)
650 goto next;
651 }
652
653 if (cpuhp_is_atomic_state(state)) { 640 if (cpuhp_is_atomic_state(state)) {
654 local_irq_disable(); 641 local_irq_disable();
655 st->result = cpuhp_invoke_callback(cpu, state, bringup, st->node, &st->last); 642 st->result = cpuhp_invoke_callback(cpu, state, bringup, st->node, &st->last);
@@ -673,7 +660,6 @@ static void cpuhp_thread_fun(unsigned int cpu)
673 st->should_run = false; 660 st->should_run = false;
674 } 661 }
675 662
676next:
677 cpuhp_lock_release(bringup); 663 cpuhp_lock_release(bringup);
678 664
679 if (!st->should_run) 665 if (!st->should_run)
@@ -916,12 +902,8 @@ void cpuhp_report_idle_dead(void)
916 902
917static void undo_cpu_down(unsigned int cpu, struct cpuhp_cpu_state *st) 903static void undo_cpu_down(unsigned int cpu, struct cpuhp_cpu_state *st)
918{ 904{
919 for (st->state++; st->state < st->target; st->state++) { 905 for (st->state++; st->state < st->target; st->state++)
920 struct cpuhp_step *step = cpuhp_get_step(st->state); 906 cpuhp_invoke_callback(cpu, st->state, true, NULL, NULL);
921
922 if (!step->skip_onerr)
923 cpuhp_invoke_callback(cpu, st->state, true, NULL, NULL);
924 }
925} 907}
926 908
927static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st, 909static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
@@ -934,7 +916,8 @@ static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
934 ret = cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL); 916 ret = cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL);
935 if (ret) { 917 if (ret) {
936 st->target = prev_state; 918 st->target = prev_state;
937 undo_cpu_down(cpu, st); 919 if (st->state < prev_state)
920 undo_cpu_down(cpu, st);
938 break; 921 break;
939 } 922 }
940 } 923 }
@@ -987,7 +970,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
987 * to do the further cleanups. 970 * to do the further cleanups.
988 */ 971 */
989 ret = cpuhp_down_callbacks(cpu, st, target); 972 ret = cpuhp_down_callbacks(cpu, st, target);
990 if (ret && st->state > CPUHP_TEARDOWN_CPU && st->state < prev_state) { 973 if (ret && st->state == CPUHP_TEARDOWN_CPU && st->state < prev_state) {
991 cpuhp_reset_state(st, prev_state); 974 cpuhp_reset_state(st, prev_state);
992 __cpuhp_kick_ap(st); 975 __cpuhp_kick_ap(st);
993 } 976 }
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 1c35b7b945d0..de87b0282e74 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -168,7 +168,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
168int dma_direct_supported(struct device *dev, u64 mask) 168int dma_direct_supported(struct device *dev, u64 mask)
169{ 169{
170#ifdef CONFIG_ZONE_DMA 170#ifdef CONFIG_ZONE_DMA
171 if (mask < DMA_BIT_MASK(ARCH_ZONE_DMA_BITS)) 171 if (mask < phys_to_dma(dev, DMA_BIT_MASK(ARCH_ZONE_DMA_BITS)))
172 return 0; 172 return 0;
173#else 173#else
174 /* 174 /*
@@ -177,7 +177,7 @@ int dma_direct_supported(struct device *dev, u64 mask)
177 * memory, or by providing a ZONE_DMA32. If neither is the case, the 177 * memory, or by providing a ZONE_DMA32. If neither is the case, the
178 * architecture needs to use an IOMMU instead of the direct mapping. 178 * architecture needs to use an IOMMU instead of the direct mapping.
179 */ 179 */
180 if (mask < DMA_BIT_MASK(32)) 180 if (mask < phys_to_dma(dev, DMA_BIT_MASK(32)))
181 return 0; 181 return 0;
182#endif 182#endif
183 /* 183 /*
diff --git a/kernel/fork.c b/kernel/fork.c
index d896e9ca38b0..f0b58479534f 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -550,8 +550,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
550 goto out; 550 goto out;
551 } 551 }
552 /* a new mm has just been created */ 552 /* a new mm has just been created */
553 arch_dup_mmap(oldmm, mm); 553 retval = arch_dup_mmap(oldmm, mm);
554 retval = 0;
555out: 554out:
556 up_write(&mm->mmap_sem); 555 up_write(&mm->mmap_sem);
557 flush_tlb_mm(oldmm); 556 flush_tlb_mm(oldmm);
diff --git a/kernel/futex.c b/kernel/futex.c
index 1f450e092c74..11fc3bb456d6 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3523,10 +3523,12 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
3523 switch (cmd) { 3523 switch (cmd) {
3524 case FUTEX_WAIT: 3524 case FUTEX_WAIT:
3525 val3 = FUTEX_BITSET_MATCH_ANY; 3525 val3 = FUTEX_BITSET_MATCH_ANY;
3526 /* fall through */
3526 case FUTEX_WAIT_BITSET: 3527 case FUTEX_WAIT_BITSET:
3527 return futex_wait(uaddr, flags, val, timeout, val3); 3528 return futex_wait(uaddr, flags, val, timeout, val3);
3528 case FUTEX_WAKE: 3529 case FUTEX_WAKE:
3529 val3 = FUTEX_BITSET_MATCH_ANY; 3530 val3 = FUTEX_BITSET_MATCH_ANY;
3531 /* fall through */
3530 case FUTEX_WAKE_BITSET: 3532 case FUTEX_WAKE_BITSET:
3531 return futex_wake(uaddr, flags, val, val3); 3533 return futex_wake(uaddr, flags, val, val3);
3532 case FUTEX_REQUEUE: 3534 case FUTEX_REQUEUE:
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index a23e21ada81b..02a0b01380d8 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -432,6 +432,7 @@ int sprint_backtrace(char *buffer, unsigned long address)
432/* To avoid using get_symbol_offset for every symbol, we carry prefix along. */ 432/* To avoid using get_symbol_offset for every symbol, we carry prefix along. */
433struct kallsym_iter { 433struct kallsym_iter {
434 loff_t pos; 434 loff_t pos;
435 loff_t pos_arch_end;
435 loff_t pos_mod_end; 436 loff_t pos_mod_end;
436 loff_t pos_ftrace_mod_end; 437 loff_t pos_ftrace_mod_end;
437 unsigned long value; 438 unsigned long value;
@@ -443,9 +444,29 @@ struct kallsym_iter {
443 int show_value; 444 int show_value;
444}; 445};
445 446
447int __weak arch_get_kallsym(unsigned int symnum, unsigned long *value,
448 char *type, char *name)
449{
450 return -EINVAL;
451}
452
453static int get_ksymbol_arch(struct kallsym_iter *iter)
454{
455 int ret = arch_get_kallsym(iter->pos - kallsyms_num_syms,
456 &iter->value, &iter->type,
457 iter->name);
458
459 if (ret < 0) {
460 iter->pos_arch_end = iter->pos;
461 return 0;
462 }
463
464 return 1;
465}
466
446static int get_ksymbol_mod(struct kallsym_iter *iter) 467static int get_ksymbol_mod(struct kallsym_iter *iter)
447{ 468{
448 int ret = module_get_kallsym(iter->pos - kallsyms_num_syms, 469 int ret = module_get_kallsym(iter->pos - iter->pos_arch_end,
449 &iter->value, &iter->type, 470 &iter->value, &iter->type,
450 iter->name, iter->module_name, 471 iter->name, iter->module_name,
451 &iter->exported); 472 &iter->exported);
@@ -501,32 +522,34 @@ static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
501 iter->nameoff = get_symbol_offset(new_pos); 522 iter->nameoff = get_symbol_offset(new_pos);
502 iter->pos = new_pos; 523 iter->pos = new_pos;
503 if (new_pos == 0) { 524 if (new_pos == 0) {
525 iter->pos_arch_end = 0;
504 iter->pos_mod_end = 0; 526 iter->pos_mod_end = 0;
505 iter->pos_ftrace_mod_end = 0; 527 iter->pos_ftrace_mod_end = 0;
506 } 528 }
507} 529}
508 530
531/*
532 * The end position (last + 1) of each additional kallsyms section is recorded
533 * in iter->pos_..._end as each section is added, and so can be used to
534 * determine which get_ksymbol_...() function to call next.
535 */
509static int update_iter_mod(struct kallsym_iter *iter, loff_t pos) 536static int update_iter_mod(struct kallsym_iter *iter, loff_t pos)
510{ 537{
511 iter->pos = pos; 538 iter->pos = pos;
512 539
513 if (iter->pos_ftrace_mod_end > 0 && 540 if ((!iter->pos_arch_end || iter->pos_arch_end > pos) &&
514 iter->pos_ftrace_mod_end < iter->pos) 541 get_ksymbol_arch(iter))
515 return get_ksymbol_bpf(iter); 542 return 1;
516 543
517 if (iter->pos_mod_end > 0 && 544 if ((!iter->pos_mod_end || iter->pos_mod_end > pos) &&
518 iter->pos_mod_end < iter->pos) { 545 get_ksymbol_mod(iter))
519 if (!get_ksymbol_ftrace_mod(iter))
520 return get_ksymbol_bpf(iter);
521 return 1; 546 return 1;
522 }
523 547
524 if (!get_ksymbol_mod(iter)) { 548 if ((!iter->pos_ftrace_mod_end || iter->pos_ftrace_mod_end > pos) &&
525 if (!get_ksymbol_ftrace_mod(iter)) 549 get_ksymbol_ftrace_mod(iter))
526 return get_ksymbol_bpf(iter); 550 return 1;
527 }
528 551
529 return 1; 552 return get_ksymbol_bpf(iter);
530} 553}
531 554
532/* Returns false if pos at or past end of file. */ 555/* Returns false if pos at or past end of file. */
diff --git a/kernel/memremap.c b/kernel/memremap.c
index d57d58f77409..5b8600d39931 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -365,7 +365,6 @@ void __put_devmap_managed_page(struct page *page)
365 __ClearPageActive(page); 365 __ClearPageActive(page);
366 __ClearPageWaiters(page); 366 __ClearPageWaiters(page);
367 367
368 page->mapping = NULL;
369 mem_cgroup_uncharge(page); 368 mem_cgroup_uncharge(page);
370 369
371 page->pgmap->page_free(page, page->pgmap->data); 370 page->pgmap->page_free(page, page->pgmap->data);
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 924e37fb1620..fd6f8ed28e01 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -38,7 +38,6 @@
38#include <linux/kmsg_dump.h> 38#include <linux/kmsg_dump.h>
39#include <linux/syslog.h> 39#include <linux/syslog.h>
40#include <linux/cpu.h> 40#include <linux/cpu.h>
41#include <linux/notifier.h>
42#include <linux/rculist.h> 41#include <linux/rculist.h>
43#include <linux/poll.h> 42#include <linux/poll.h>
44#include <linux/irq_work.h> 43#include <linux/irq_work.h>
diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c
index a0a74c533e4b..0913b4d385de 100644
--- a/kernel/printk/printk_safe.c
+++ b/kernel/printk/printk_safe.c
@@ -306,12 +306,12 @@ static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args)
306 return printk_safe_log_store(s, fmt, args); 306 return printk_safe_log_store(s, fmt, args);
307} 307}
308 308
309void printk_nmi_enter(void) 309void notrace printk_nmi_enter(void)
310{ 310{
311 this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK); 311 this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK);
312} 312}
313 313
314void printk_nmi_exit(void) 314void notrace printk_nmi_exit(void)
315{ 315{
316 this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK); 316 this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK);
317} 317}
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index f74fb00d8064..0e6e97a01942 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -133,19 +133,40 @@ static void inline clocksource_watchdog_unlock(unsigned long *flags)
133 spin_unlock_irqrestore(&watchdog_lock, *flags); 133 spin_unlock_irqrestore(&watchdog_lock, *flags);
134} 134}
135 135
136static int clocksource_watchdog_kthread(void *data);
137static void __clocksource_change_rating(struct clocksource *cs, int rating);
138
136/* 139/*
137 * Interval: 0.5sec Threshold: 0.0625s 140 * Interval: 0.5sec Threshold: 0.0625s
138 */ 141 */
139#define WATCHDOG_INTERVAL (HZ >> 1) 142#define WATCHDOG_INTERVAL (HZ >> 1)
140#define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4) 143#define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4)
141 144
145static void clocksource_watchdog_work(struct work_struct *work)
146{
147 /*
148 * We cannot directly run clocksource_watchdog_kthread() here, because
149 * clocksource_select() calls timekeeping_notify() which uses
150 * stop_machine(). One cannot use stop_machine() from a workqueue() due
151 * lock inversions wrt CPU hotplug.
152 *
153 * Also, we only ever run this work once or twice during the lifetime
154 * of the kernel, so there is no point in creating a more permanent
155 * kthread for this.
156 *
157 * If kthread_run fails the next watchdog scan over the
158 * watchdog_list will find the unstable clock again.
159 */
160 kthread_run(clocksource_watchdog_kthread, NULL, "kwatchdog");
161}
162
142static void __clocksource_unstable(struct clocksource *cs) 163static void __clocksource_unstable(struct clocksource *cs)
143{ 164{
144 cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG); 165 cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG);
145 cs->flags |= CLOCK_SOURCE_UNSTABLE; 166 cs->flags |= CLOCK_SOURCE_UNSTABLE;
146 167
147 /* 168 /*
148 * If the clocksource is registered clocksource_watchdog_work() will 169 * If the clocksource is registered clocksource_watchdog_kthread() will
149 * re-rate and re-select. 170 * re-rate and re-select.
150 */ 171 */
151 if (list_empty(&cs->list)) { 172 if (list_empty(&cs->list)) {
@@ -156,7 +177,7 @@ static void __clocksource_unstable(struct clocksource *cs)
156 if (cs->mark_unstable) 177 if (cs->mark_unstable)
157 cs->mark_unstable(cs); 178 cs->mark_unstable(cs);
158 179
159 /* kick clocksource_watchdog_work() */ 180 /* kick clocksource_watchdog_kthread() */
160 if (finished_booting) 181 if (finished_booting)
161 schedule_work(&watchdog_work); 182 schedule_work(&watchdog_work);
162} 183}
@@ -166,7 +187,7 @@ static void __clocksource_unstable(struct clocksource *cs)
166 * @cs: clocksource to be marked unstable 187 * @cs: clocksource to be marked unstable
167 * 188 *
168 * This function is called by the x86 TSC code to mark clocksources as unstable; 189 * This function is called by the x86 TSC code to mark clocksources as unstable;
169 * it defers demotion and re-selection to a work. 190 * it defers demotion and re-selection to a kthread.
170 */ 191 */
171void clocksource_mark_unstable(struct clocksource *cs) 192void clocksource_mark_unstable(struct clocksource *cs)
172{ 193{
@@ -391,9 +412,7 @@ static void clocksource_dequeue_watchdog(struct clocksource *cs)
391 } 412 }
392} 413}
393 414
394static void __clocksource_change_rating(struct clocksource *cs, int rating); 415static int __clocksource_watchdog_kthread(void)
395
396static int __clocksource_watchdog_work(void)
397{ 416{
398 struct clocksource *cs, *tmp; 417 struct clocksource *cs, *tmp;
399 unsigned long flags; 418 unsigned long flags;
@@ -418,12 +437,13 @@ static int __clocksource_watchdog_work(void)
418 return select; 437 return select;
419} 438}
420 439
421static void clocksource_watchdog_work(struct work_struct *work) 440static int clocksource_watchdog_kthread(void *data)
422{ 441{
423 mutex_lock(&clocksource_mutex); 442 mutex_lock(&clocksource_mutex);
424 if (__clocksource_watchdog_work()) 443 if (__clocksource_watchdog_kthread())
425 clocksource_select(); 444 clocksource_select();
426 mutex_unlock(&clocksource_mutex); 445 mutex_unlock(&clocksource_mutex);
446 return 0;
427} 447}
428 448
429static bool clocksource_is_watchdog(struct clocksource *cs) 449static bool clocksource_is_watchdog(struct clocksource *cs)
@@ -442,7 +462,7 @@ static void clocksource_enqueue_watchdog(struct clocksource *cs)
442static void clocksource_select_watchdog(bool fallback) { } 462static void clocksource_select_watchdog(bool fallback) { }
443static inline void clocksource_dequeue_watchdog(struct clocksource *cs) { } 463static inline void clocksource_dequeue_watchdog(struct clocksource *cs) { }
444static inline void clocksource_resume_watchdog(void) { } 464static inline void clocksource_resume_watchdog(void) { }
445static inline int __clocksource_watchdog_work(void) { return 0; } 465static inline int __clocksource_watchdog_kthread(void) { return 0; }
446static bool clocksource_is_watchdog(struct clocksource *cs) { return false; } 466static bool clocksource_is_watchdog(struct clocksource *cs) { return false; }
447void clocksource_mark_unstable(struct clocksource *cs) { } 467void clocksource_mark_unstable(struct clocksource *cs) { }
448 468
@@ -810,7 +830,7 @@ static int __init clocksource_done_booting(void)
810 /* 830 /*
811 * Run the watchdog first to eliminate unstable clock sources 831 * Run the watchdog first to eliminate unstable clock sources
812 */ 832 */
813 __clocksource_watchdog_work(); 833 __clocksource_watchdog_kthread();
814 clocksource_select(); 834 clocksource_select();
815 mutex_unlock(&clocksource_mutex); 835 mutex_unlock(&clocksource_mutex);
816 return 0; 836 return 0;
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 5470dce212c0..977918d5d350 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -261,7 +261,7 @@ static void __touch_watchdog(void)
261 * entering idle state. This should only be used for scheduler events. 261 * entering idle state. This should only be used for scheduler events.
262 * Use touch_softlockup_watchdog() for everything else. 262 * Use touch_softlockup_watchdog() for everything else.
263 */ 263 */
264void touch_softlockup_watchdog_sched(void) 264notrace void touch_softlockup_watchdog_sched(void)
265{ 265{
266 /* 266 /*
267 * Preemption can be enabled. It doesn't matter which CPU's timestamp 267 * Preemption can be enabled. It doesn't matter which CPU's timestamp
@@ -270,7 +270,7 @@ void touch_softlockup_watchdog_sched(void)
270 raw_cpu_write(watchdog_touch_ts, 0); 270 raw_cpu_write(watchdog_touch_ts, 0);
271} 271}
272 272
273void touch_softlockup_watchdog(void) 273notrace void touch_softlockup_watchdog(void)
274{ 274{
275 touch_softlockup_watchdog_sched(); 275 touch_softlockup_watchdog_sched();
276 wq_watchdog_touch(raw_smp_processor_id()); 276 wq_watchdog_touch(raw_smp_processor_id());
diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c
index 1f7020d65d0a..71381168dede 100644
--- a/kernel/watchdog_hld.c
+++ b/kernel/watchdog_hld.c
@@ -29,7 +29,7 @@ static struct cpumask dead_events_mask;
29static unsigned long hardlockup_allcpu_dumped; 29static unsigned long hardlockup_allcpu_dumped;
30static atomic_t watchdog_cpus = ATOMIC_INIT(0); 30static atomic_t watchdog_cpus = ATOMIC_INIT(0);
31 31
32void arch_touch_nmi_watchdog(void) 32notrace void arch_touch_nmi_watchdog(void)
33{ 33{
34 /* 34 /*
35 * Using __raw here because some code paths have 35 * Using __raw here because some code paths have
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 60e80198c3df..0280deac392e 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5574,7 +5574,7 @@ static void wq_watchdog_timer_fn(struct timer_list *unused)
5574 mod_timer(&wq_watchdog_timer, jiffies + thresh); 5574 mod_timer(&wq_watchdog_timer, jiffies + thresh);
5575} 5575}
5576 5576
5577void wq_watchdog_touch(int cpu) 5577notrace void wq_watchdog_touch(int cpu)
5578{ 5578{
5579 if (cpu >= 0) 5579 if (cpu >= 0)
5580 per_cpu(wq_watchdog_touched_cpu, cpu) = jiffies; 5580 per_cpu(wq_watchdog_touched_cpu, cpu) = jiffies;
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 3589765141a8..4966c4fbe7f7 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1277,13 +1277,13 @@ config WARN_ALL_UNSEEDED_RANDOM
1277 time. This is really bad from a security perspective, and 1277 time. This is really bad from a security perspective, and
1278 so architecture maintainers really need to do what they can 1278 so architecture maintainers really need to do what they can
1279 to get the CRNG seeded sooner after the system is booted. 1279 to get the CRNG seeded sooner after the system is booted.
1280 However, since users can not do anything actionble to 1280 However, since users cannot do anything actionable to
1281 address this, by default the kernel will issue only a single 1281 address this, by default the kernel will issue only a single
1282 warning for the first use of unseeded randomness. 1282 warning for the first use of unseeded randomness.
1283 1283
1284 Say Y here if you want to receive warnings for all uses of 1284 Say Y here if you want to receive warnings for all uses of
1285 unseeded randomness. This will be of use primarily for 1285 unseeded randomness. This will be of use primarily for
1286 those developers interersted in improving the security of 1286 those developers interested in improving the security of
1287 Linux kernels running on their architecture (or 1287 Linux kernels running on their architecture (or
1288 subarchitecture). 1288 subarchitecture).
1289 1289
@@ -1833,6 +1833,9 @@ config TEST_HASH
1833 This is intended to help people writing architecture-specific 1833 This is intended to help people writing architecture-specific
1834 optimized versions. If unsure, say N. 1834 optimized versions. If unsure, say N.
1835 1835
1836config TEST_IDA
1837 tristate "Perform selftest on IDA functions"
1838
1836config TEST_PARMAN 1839config TEST_PARMAN
1837 tristate "Perform selftest on priority array manager" 1840 tristate "Perform selftest on priority array manager"
1838 depends on PARMAN 1841 depends on PARMAN
diff --git a/lib/Makefile b/lib/Makefile
index 9baefb6cb1a1..ca3f7ebb900d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_TEST_BPF) += test_bpf.o
50obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o 50obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
51obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o 51obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
52obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o 52obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o
53obj-$(CONFIG_TEST_IDA) += test_ida.o
53obj-$(CONFIG_TEST_KASAN) += test_kasan.o 54obj-$(CONFIG_TEST_KASAN) += test_kasan.o
54CFLAGS_test_kasan.o += -fno-builtin 55CFLAGS_test_kasan.o += -fno-builtin
55obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o 56obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
diff --git a/lib/idr.c b/lib/idr.c
index ed9c169c12bd..fab2fd5bc326 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -317,18 +317,12 @@ EXPORT_SYMBOL(idr_replace);
317 * bit per ID, and so is more space efficient than an IDR. To use an IDA, 317 * bit per ID, and so is more space efficient than an IDR. To use an IDA,
318 * define it using DEFINE_IDA() (or embed a &struct ida in a data structure, 318 * define it using DEFINE_IDA() (or embed a &struct ida in a data structure,
319 * then initialise it using ida_init()). To allocate a new ID, call 319 * then initialise it using ida_init()). To allocate a new ID, call
320 * ida_simple_get(). To free an ID, call ida_simple_remove(). 320 * ida_alloc(), ida_alloc_min(), ida_alloc_max() or ida_alloc_range().
321 * To free an ID, call ida_free().
321 * 322 *
322 * If you have more complex locking requirements, use a loop around 323 * ida_destroy() can be used to dispose of an IDA without needing to
323 * ida_pre_get() and ida_get_new() to allocate a new ID. Then use 324 * free the individual IDs in it. You can use ida_is_empty() to find
324 * ida_remove() to free an ID. You must make sure that ida_get_new() and 325 * out whether the IDA has any IDs currently allocated.
325 * ida_remove() cannot be called at the same time as each other for the
326 * same IDA.
327 *
328 * You can also use ida_get_new_above() if you need an ID to be allocated
329 * above a particular number. ida_destroy() can be used to dispose of an
330 * IDA without needing to free the individual IDs in it. You can use
331 * ida_is_empty() to find out whether the IDA has any IDs currently allocated.
332 * 326 *
333 * IDs are currently limited to the range [0-INT_MAX]. If this is an awkward 327 * IDs are currently limited to the range [0-INT_MAX]. If this is an awkward
334 * limitation, it should be quite straightforward to raise the maximum. 328 * limitation, it should be quite straightforward to raise the maximum.
@@ -369,25 +363,7 @@ EXPORT_SYMBOL(idr_replace);
369 363
370#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1) 364#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1)
371 365
372/** 366static int ida_get_new_above(struct ida *ida, int start)
373 * ida_get_new_above - allocate new ID above or equal to a start id
374 * @ida: ida handle
375 * @start: id to start search at
376 * @id: pointer to the allocated handle
377 *
378 * Allocate new ID above or equal to @start. It should be called
379 * with any required locks to ensure that concurrent calls to
380 * ida_get_new_above() / ida_get_new() / ida_remove() are not allowed.
381 * Consider using ida_simple_get() if you do not have complex locking
382 * requirements.
383 *
384 * If memory is required, it will return %-EAGAIN, you should unlock
385 * and go back to the ida_pre_get() call. If the ida is full, it will
386 * return %-ENOSPC. On success, it will return 0.
387 *
388 * @id returns a value in the range @start ... %0x7fffffff.
389 */
390int ida_get_new_above(struct ida *ida, int start, int *id)
391{ 367{
392 struct radix_tree_root *root = &ida->ida_rt; 368 struct radix_tree_root *root = &ida->ida_rt;
393 void __rcu **slot; 369 void __rcu **slot;
@@ -426,8 +402,8 @@ int ida_get_new_above(struct ida *ida, int start, int *id)
426 if (ebit < BITS_PER_LONG) { 402 if (ebit < BITS_PER_LONG) {
427 tmp |= 1UL << ebit; 403 tmp |= 1UL << ebit;
428 rcu_assign_pointer(*slot, (void *)tmp); 404 rcu_assign_pointer(*slot, (void *)tmp);
429 *id = new + ebit - RADIX_TREE_EXCEPTIONAL_SHIFT; 405 return new + ebit -
430 return 0; 406 RADIX_TREE_EXCEPTIONAL_SHIFT;
431 } 407 }
432 bitmap = this_cpu_xchg(ida_bitmap, NULL); 408 bitmap = this_cpu_xchg(ida_bitmap, NULL);
433 if (!bitmap) 409 if (!bitmap)
@@ -458,8 +434,7 @@ int ida_get_new_above(struct ida *ida, int start, int *id)
458 RADIX_TREE_EXCEPTIONAL_ENTRY); 434 RADIX_TREE_EXCEPTIONAL_ENTRY);
459 radix_tree_iter_replace(root, &iter, slot, 435 radix_tree_iter_replace(root, &iter, slot,
460 bitmap); 436 bitmap);
461 *id = new; 437 return new;
462 return 0;
463 } 438 }
464 bitmap = this_cpu_xchg(ida_bitmap, NULL); 439 bitmap = this_cpu_xchg(ida_bitmap, NULL);
465 if (!bitmap) 440 if (!bitmap)
@@ -468,20 +443,11 @@ int ida_get_new_above(struct ida *ida, int start, int *id)
468 radix_tree_iter_replace(root, &iter, slot, bitmap); 443 radix_tree_iter_replace(root, &iter, slot, bitmap);
469 } 444 }
470 445
471 *id = new; 446 return new;
472 return 0;
473 } 447 }
474} 448}
475EXPORT_SYMBOL(ida_get_new_above);
476 449
477/** 450static void ida_remove(struct ida *ida, int id)
478 * ida_remove - Free the given ID
479 * @ida: ida handle
480 * @id: ID to free
481 *
482 * This function should not be called at the same time as ida_get_new_above().
483 */
484void ida_remove(struct ida *ida, int id)
485{ 451{
486 unsigned long index = id / IDA_BITMAP_BITS; 452 unsigned long index = id / IDA_BITMAP_BITS;
487 unsigned offset = id % IDA_BITMAP_BITS; 453 unsigned offset = id % IDA_BITMAP_BITS;
@@ -518,99 +484,90 @@ void ida_remove(struct ida *ida, int id)
518 } 484 }
519 return; 485 return;
520 err: 486 err:
521 WARN(1, "ida_remove called for id=%d which is not allocated.\n", id); 487 WARN(1, "ida_free called for id=%d which is not allocated.\n", id);
522} 488}
523EXPORT_SYMBOL(ida_remove);
524 489
525/** 490/**
526 * ida_destroy - Free the contents of an ida 491 * ida_destroy() - Free all IDs.
527 * @ida: ida handle 492 * @ida: IDA handle.
493 *
494 * Calling this function frees all IDs and releases all resources used
495 * by an IDA. When this call returns, the IDA is empty and can be reused
496 * or freed. If the IDA is already empty, there is no need to call this
497 * function.
528 * 498 *
529 * Calling this function releases all resources associated with an IDA. When 499 * Context: Any context.
530 * this call returns, the IDA is empty and can be reused or freed. The caller
531 * should not allow ida_remove() or ida_get_new_above() to be called at the
532 * same time.
533 */ 500 */
534void ida_destroy(struct ida *ida) 501void ida_destroy(struct ida *ida)
535{ 502{
503 unsigned long flags;
536 struct radix_tree_iter iter; 504 struct radix_tree_iter iter;
537 void __rcu **slot; 505 void __rcu **slot;
538 506
507 xa_lock_irqsave(&ida->ida_rt, flags);
539 radix_tree_for_each_slot(slot, &ida->ida_rt, &iter, 0) { 508 radix_tree_for_each_slot(slot, &ida->ida_rt, &iter, 0) {
540 struct ida_bitmap *bitmap = rcu_dereference_raw(*slot); 509 struct ida_bitmap *bitmap = rcu_dereference_raw(*slot);
541 if (!radix_tree_exception(bitmap)) 510 if (!radix_tree_exception(bitmap))
542 kfree(bitmap); 511 kfree(bitmap);
543 radix_tree_iter_delete(&ida->ida_rt, &iter, slot); 512 radix_tree_iter_delete(&ida->ida_rt, &iter, slot);
544 } 513 }
514 xa_unlock_irqrestore(&ida->ida_rt, flags);
545} 515}
546EXPORT_SYMBOL(ida_destroy); 516EXPORT_SYMBOL(ida_destroy);
547 517
548/** 518/**
549 * ida_simple_get - get a new id. 519 * ida_alloc_range() - Allocate an unused ID.
550 * @ida: the (initialized) ida. 520 * @ida: IDA handle.
551 * @start: the minimum id (inclusive, < 0x8000000) 521 * @min: Lowest ID to allocate.
552 * @end: the maximum id (exclusive, < 0x8000000 or 0) 522 * @max: Highest ID to allocate.
553 * @gfp_mask: memory allocation flags 523 * @gfp: Memory allocation flags.
554 *
555 * Allocates an id in the range start <= id < end, or returns -ENOSPC.
556 * On memory allocation failure, returns -ENOMEM.
557 * 524 *
558 * Compared to ida_get_new_above() this function does its own locking, and 525 * Allocate an ID between @min and @max, inclusive. The allocated ID will
559 * should be used unless there are special requirements. 526 * not exceed %INT_MAX, even if @max is larger.
560 * 527 *
561 * Use ida_simple_remove() to get rid of an id. 528 * Context: Any context.
529 * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
530 * or %-ENOSPC if there are no free IDs.
562 */ 531 */
563int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, 532int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,
564 gfp_t gfp_mask) 533 gfp_t gfp)
565{ 534{
566 int ret, id; 535 int id = 0;
567 unsigned int max;
568 unsigned long flags; 536 unsigned long flags;
569 537
570 BUG_ON((int)start < 0); 538 if ((int)min < 0)
571 BUG_ON((int)end < 0); 539 return -ENOSPC;
572 540
573 if (end == 0) 541 if ((int)max < 0)
574 max = 0x80000000; 542 max = INT_MAX;
575 else {
576 BUG_ON(end < start);
577 max = end - 1;
578 }
579 543
580again: 544again:
581 if (!ida_pre_get(ida, gfp_mask))
582 return -ENOMEM;
583
584 xa_lock_irqsave(&ida->ida_rt, flags); 545 xa_lock_irqsave(&ida->ida_rt, flags);
585 ret = ida_get_new_above(ida, start, &id); 546 id = ida_get_new_above(ida, min);
586 if (!ret) { 547 if (id > (int)max) {
587 if (id > max) { 548 ida_remove(ida, id);
588 ida_remove(ida, id); 549 id = -ENOSPC;
589 ret = -ENOSPC;
590 } else {
591 ret = id;
592 }
593 } 550 }
594 xa_unlock_irqrestore(&ida->ida_rt, flags); 551 xa_unlock_irqrestore(&ida->ida_rt, flags);
595 552
596 if (unlikely(ret == -EAGAIN)) 553 if (unlikely(id == -EAGAIN)) {
554 if (!ida_pre_get(ida, gfp))
555 return -ENOMEM;
597 goto again; 556 goto again;
557 }
598 558
599 return ret; 559 return id;
600} 560}
601EXPORT_SYMBOL(ida_simple_get); 561EXPORT_SYMBOL(ida_alloc_range);
602 562
603/** 563/**
604 * ida_simple_remove - remove an allocated id. 564 * ida_free() - Release an allocated ID.
605 * @ida: the (initialized) ida. 565 * @ida: IDA handle.
606 * @id: the id returned by ida_simple_get. 566 * @id: Previously allocated ID.
607 *
608 * Use to release an id allocated with ida_simple_get().
609 * 567 *
610 * Compared to ida_remove() this function does its own locking, and should be 568 * Context: Any context.
611 * used unless there are special requirements.
612 */ 569 */
613void ida_simple_remove(struct ida *ida, unsigned int id) 570void ida_free(struct ida *ida, unsigned int id)
614{ 571{
615 unsigned long flags; 572 unsigned long flags;
616 573
@@ -619,4 +576,4 @@ void ida_simple_remove(struct ida *ida, unsigned int id)
619 ida_remove(ida, id); 576 ida_remove(ida, id);
620 xa_unlock_irqrestore(&ida->ida_rt, flags); 577 xa_unlock_irqrestore(&ida->ida_rt, flags);
621} 578}
622EXPORT_SYMBOL(ida_simple_remove); 579EXPORT_SYMBOL(ida_free);
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index c72577e472f2..a66595ba5543 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -4,7 +4,6 @@
4 */ 4 */
5 5
6#include <linux/percpu_counter.h> 6#include <linux/percpu_counter.h>
7#include <linux/notifier.h>
8#include <linux/mutex.h> 7#include <linux/mutex.h>
9#include <linux/init.h> 8#include <linux/init.h>
10#include <linux/cpu.h> 9#include <linux/cpu.h>
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index a9e41aed6de4..bc03ecc4dfd2 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -120,7 +120,7 @@ bool is_sibling_entry(const struct radix_tree_node *parent, void *node)
120static inline unsigned long 120static inline unsigned long
121get_slot_offset(const struct radix_tree_node *parent, void __rcu **slot) 121get_slot_offset(const struct radix_tree_node *parent, void __rcu **slot)
122{ 122{
123 return slot - parent->slots; 123 return parent ? slot - parent->slots : 0;
124} 124}
125 125
126static unsigned int radix_tree_descend(const struct radix_tree_node *parent, 126static unsigned int radix_tree_descend(const struct radix_tree_node *parent,
@@ -2106,14 +2106,6 @@ void idr_preload(gfp_t gfp_mask)
2106} 2106}
2107EXPORT_SYMBOL(idr_preload); 2107EXPORT_SYMBOL(idr_preload);
2108 2108
2109/**
2110 * ida_pre_get - reserve resources for ida allocation
2111 * @ida: ida handle
2112 * @gfp: memory allocation flags
2113 *
2114 * This function should be called before calling ida_get_new_above(). If it
2115 * is unable to allocate memory, it will return %0. On success, it returns %1.
2116 */
2117int ida_pre_get(struct ida *ida, gfp_t gfp) 2109int ida_pre_get(struct ida *ida, gfp_t gfp)
2118{ 2110{
2119 /* 2111 /*
@@ -2134,7 +2126,6 @@ int ida_pre_get(struct ida *ida, gfp_t gfp)
2134 2126
2135 return 1; 2127 return 1;
2136} 2128}
2137EXPORT_SYMBOL(ida_pre_get);
2138 2129
2139void __rcu **idr_get_free(struct radix_tree_root *root, 2130void __rcu **idr_get_free(struct radix_tree_root *root,
2140 struct radix_tree_iter *iter, gfp_t gfp, 2131 struct radix_tree_iter *iter, gfp_t gfp,
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 310e29b51507..30526afa8343 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -28,7 +28,6 @@
28#include <linux/rhashtable.h> 28#include <linux/rhashtable.h>
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/export.h> 30#include <linux/export.h>
31#include <linux/rhashtable.h>
32 31
33#define HASH_DEFAULT_SIZE 64UL 32#define HASH_DEFAULT_SIZE 64UL
34#define HASH_MIN_SIZE 4U 33#define HASH_MIN_SIZE 4U
diff --git a/lib/test_ida.c b/lib/test_ida.c
new file mode 100644
index 000000000000..2d1637d8136b
--- /dev/null
+++ b/lib/test_ida.c
@@ -0,0 +1,177 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * test_ida.c: Test the IDA API
4 * Copyright (c) 2016-2018 Microsoft Corporation
5 * Copyright (c) 2018 Oracle Corporation
6 * Author: Matthew Wilcox <willy@infradead.org>
7 */
8
9#include <linux/idr.h>
10#include <linux/module.h>
11
12static unsigned int tests_run;
13static unsigned int tests_passed;
14
15#ifdef __KERNEL__
16void ida_dump(struct ida *ida) { }
17#endif
18#define IDA_BUG_ON(ida, x) do { \
19 tests_run++; \
20 if (x) { \
21 ida_dump(ida); \
22 dump_stack(); \
23 } else { \
24 tests_passed++; \
25 } \
26} while (0)
27
28/*
29 * Straightforward checks that allocating and freeing IDs work.
30 */
31static void ida_check_alloc(struct ida *ida)
32{
33 int i, id;
34
35 for (i = 0; i < 10000; i++)
36 IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i);
37
38 ida_free(ida, 20);
39 ida_free(ida, 21);
40 for (i = 0; i < 3; i++) {
41 id = ida_alloc(ida, GFP_KERNEL);
42 IDA_BUG_ON(ida, id < 0);
43 if (i == 2)
44 IDA_BUG_ON(ida, id != 10000);
45 }
46
47 for (i = 0; i < 5000; i++)
48 ida_free(ida, i);
49
50 IDA_BUG_ON(ida, ida_alloc_min(ida, 5000, GFP_KERNEL) != 10001);
51 ida_destroy(ida);
52
53 IDA_BUG_ON(ida, !ida_is_empty(ida));
54}
55
56/* Destroy an IDA with a single entry at @base */
57static void ida_check_destroy_1(struct ida *ida, unsigned int base)
58{
59 IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) != base);
60 IDA_BUG_ON(ida, ida_is_empty(ida));
61 ida_destroy(ida);
62 IDA_BUG_ON(ida, !ida_is_empty(ida));
63}
64
65/* Check that ida_destroy and ida_is_empty work */
66static void ida_check_destroy(struct ida *ida)
67{
68 /* Destroy an already-empty IDA */
69 IDA_BUG_ON(ida, !ida_is_empty(ida));
70 ida_destroy(ida);
71 IDA_BUG_ON(ida, !ida_is_empty(ida));
72
73 ida_check_destroy_1(ida, 0);
74 ida_check_destroy_1(ida, 1);
75 ida_check_destroy_1(ida, 1023);
76 ida_check_destroy_1(ida, 1024);
77 ida_check_destroy_1(ida, 12345678);
78}
79
80/*
81 * Check what happens when we fill a leaf and then delete it. This may
82 * discover mishandling of IDR_FREE.
83 */
84static void ida_check_leaf(struct ida *ida, unsigned int base)
85{
86 unsigned long i;
87
88 for (i = 0; i < IDA_BITMAP_BITS; i++) {
89 IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) !=
90 base + i);
91 }
92
93 ida_destroy(ida);
94 IDA_BUG_ON(ida, !ida_is_empty(ida));
95
96 IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != 0);
97 IDA_BUG_ON(ida, ida_is_empty(ida));
98 ida_free(ida, 0);
99 IDA_BUG_ON(ida, !ida_is_empty(ida));
100}
101
102/*
103 * Check allocations up to and slightly above the maximum allowed (2^31-1) ID.
104 * Allocating up to 2^31-1 should succeed, and then allocating the next one
105 * should fail.
106 */
107static void ida_check_max(struct ida *ida)
108{
109 unsigned long i, j;
110
111 for (j = 1; j < 65537; j *= 2) {
112 unsigned long base = (1UL << 31) - j;
113 for (i = 0; i < j; i++) {
114 IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) !=
115 base + i);
116 }
117 IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) !=
118 -ENOSPC);
119 ida_destroy(ida);
120 IDA_BUG_ON(ida, !ida_is_empty(ida));
121 }
122}
123
124/*
125 * Check handling of conversions between exceptional entries and full bitmaps.
126 */
127static void ida_check_conv(struct ida *ida)
128{
129 unsigned long i;
130
131 for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) {
132 IDA_BUG_ON(ida, ida_alloc_min(ida, i + 1, GFP_KERNEL) != i + 1);
133 IDA_BUG_ON(ida, ida_alloc_min(ida, i + BITS_PER_LONG,
134 GFP_KERNEL) != i + BITS_PER_LONG);
135 ida_free(ida, i + 1);
136 ida_free(ida, i + BITS_PER_LONG);
137 IDA_BUG_ON(ida, !ida_is_empty(ida));
138 }
139
140 for (i = 0; i < IDA_BITMAP_BITS * 2; i++)
141 IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i);
142 for (i = IDA_BITMAP_BITS * 2; i > 0; i--)
143 ida_free(ida, i - 1);
144 IDA_BUG_ON(ida, !ida_is_empty(ida));
145
146 for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++)
147 IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i);
148 for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--)
149 ida_free(ida, i - 1);
150 IDA_BUG_ON(ida, !ida_is_empty(ida));
151}
152
153static int ida_checks(void)
154{
155 DEFINE_IDA(ida);
156
157 IDA_BUG_ON(&ida, !ida_is_empty(&ida));
158 ida_check_alloc(&ida);
159 ida_check_destroy(&ida);
160 ida_check_leaf(&ida, 0);
161 ida_check_leaf(&ida, 1024);
162 ida_check_leaf(&ida, 1024 * 64);
163 ida_check_max(&ida);
164 ida_check_conv(&ida);
165
166 printk("IDA: %u of %u tests passed\n", tests_passed, tests_run);
167 return (tests_run != tests_passed) ? 0 : -EINVAL;
168}
169
170static void ida_exit(void)
171{
172}
173
174module_init(ida_checks);
175module_exit(ida_exit);
176MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
177MODULE_LICENSE("GPL");
diff --git a/mm/debug.c b/mm/debug.c
index 38c926520c97..bd10aad8539a 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -114,7 +114,7 @@ EXPORT_SYMBOL(dump_vma);
114 114
115void dump_mm(const struct mm_struct *mm) 115void dump_mm(const struct mm_struct *mm)
116{ 116{
117 pr_emerg("mm %px mmap %px seqnum %d task_size %lu\n" 117 pr_emerg("mm %px mmap %px seqnum %llu task_size %lu\n"
118#ifdef CONFIG_MMU 118#ifdef CONFIG_MMU
119 "get_unmapped_area %px\n" 119 "get_unmapped_area %px\n"
120#endif 120#endif
@@ -142,7 +142,7 @@ void dump_mm(const struct mm_struct *mm)
142 "tlb_flush_pending %d\n" 142 "tlb_flush_pending %d\n"
143 "def_flags: %#lx(%pGv)\n", 143 "def_flags: %#lx(%pGv)\n",
144 144
145 mm, mm->mmap, mm->vmacache_seqnum, mm->task_size, 145 mm, mm->mmap, (long long) mm->vmacache_seqnum, mm->task_size,
146#ifdef CONFIG_MMU 146#ifdef CONFIG_MMU
147 mm->get_unmapped_area, 147 mm->get_unmapped_area,
148#endif 148#endif
diff --git a/mm/hmm.c b/mm/hmm.c
index 0b0554591610..c968e49f7a0c 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -968,6 +968,8 @@ static void hmm_devmem_free(struct page *page, void *data)
968{ 968{
969 struct hmm_devmem *devmem = data; 969 struct hmm_devmem *devmem = data;
970 970
971 page->mapping = NULL;
972
971 devmem->ops->free(devmem, page); 973 devmem->ops->free(devmem, page);
972} 974}
973 975
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 08b544383d74..533f9b00147d 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -752,7 +752,7 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
752 spin_unlock(ptl); 752 spin_unlock(ptl);
753} 753}
754 754
755int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr, 755vm_fault_t vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
756 pmd_t *pmd, pfn_t pfn, bool write) 756 pmd_t *pmd, pfn_t pfn, bool write)
757{ 757{
758 pgprot_t pgprot = vma->vm_page_prot; 758 pgprot_t pgprot = vma->vm_page_prot;
@@ -812,7 +812,7 @@ static void insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
812 spin_unlock(ptl); 812 spin_unlock(ptl);
813} 813}
814 814
815int vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr, 815vm_fault_t vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
816 pud_t *pud, pfn_t pfn, bool write) 816 pud_t *pud, pfn_t pfn, bool write)
817{ 817{
818 pgprot_t pgprot = vma->vm_page_prot; 818 pgprot_t pgprot = vma->vm_page_prot;
@@ -821,11 +821,11 @@ int vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
821 * but we need to be consistent with PTEs and architectures that 821 * but we need to be consistent with PTEs and architectures that
822 * can't support a 'special' bit. 822 * can't support a 'special' bit.
823 */ 823 */
824 BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))); 824 BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) &&
825 !pfn_t_devmap(pfn));
825 BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) == 826 BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) ==
826 (VM_PFNMAP|VM_MIXEDMAP)); 827 (VM_PFNMAP|VM_MIXEDMAP));
827 BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags)); 828 BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags));
828 BUG_ON(!pfn_t_devmap(pfn));
829 829
830 if (addr < vma->vm_start || addr >= vma->vm_end) 830 if (addr < vma->vm_start || addr >= vma->vm_end)
831 return VM_FAULT_SIGBUS; 831 return VM_FAULT_SIGBUS;
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 9a085d525bbc..17dd883198ae 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -2097,6 +2097,11 @@ static int __init kmemleak_late_init(void)
2097 2097
2098 kmemleak_initialized = 1; 2098 kmemleak_initialized = 1;
2099 2099
2100 dentry = debugfs_create_file("kmemleak", 0644, NULL, NULL,
2101 &kmemleak_fops);
2102 if (!dentry)
2103 pr_warn("Failed to create the debugfs kmemleak file\n");
2104
2100 if (kmemleak_error) { 2105 if (kmemleak_error) {
2101 /* 2106 /*
2102 * Some error occurred and kmemleak was disabled. There is a 2107 * Some error occurred and kmemleak was disabled. There is a
@@ -2108,10 +2113,6 @@ static int __init kmemleak_late_init(void)
2108 return -ENOMEM; 2113 return -ENOMEM;
2109 } 2114 }
2110 2115
2111 dentry = debugfs_create_file("kmemleak", 0644, NULL, NULL,
2112 &kmemleak_fops);
2113 if (!dentry)
2114 pr_warn("Failed to create the debugfs kmemleak file\n");
2115 mutex_lock(&scan_mutex); 2116 mutex_lock(&scan_mutex);
2116 start_scan_thread(); 2117 start_scan_thread();
2117 mutex_unlock(&scan_mutex); 2118 mutex_unlock(&scan_mutex);
diff --git a/mm/madvise.c b/mm/madvise.c
index 4d3c922ea1a1..972a9eaa898b 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -631,11 +631,13 @@ static int madvise_inject_error(int behavior,
631 631
632 632
633 for (; start < end; start += PAGE_SIZE << order) { 633 for (; start < end; start += PAGE_SIZE << order) {
634 unsigned long pfn;
634 int ret; 635 int ret;
635 636
636 ret = get_user_pages_fast(start, 1, 0, &page); 637 ret = get_user_pages_fast(start, 1, 0, &page);
637 if (ret != 1) 638 if (ret != 1)
638 return ret; 639 return ret;
640 pfn = page_to_pfn(page);
639 641
640 /* 642 /*
641 * When soft offlining hugepages, after migrating the page 643 * When soft offlining hugepages, after migrating the page
@@ -651,17 +653,25 @@ static int madvise_inject_error(int behavior,
651 653
652 if (behavior == MADV_SOFT_OFFLINE) { 654 if (behavior == MADV_SOFT_OFFLINE) {
653 pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n", 655 pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n",
654 page_to_pfn(page), start); 656 pfn, start);
655 657
656 ret = soft_offline_page(page, MF_COUNT_INCREASED); 658 ret = soft_offline_page(page, MF_COUNT_INCREASED);
657 if (ret) 659 if (ret)
658 return ret; 660 return ret;
659 continue; 661 continue;
660 } 662 }
663
661 pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n", 664 pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n",
662 page_to_pfn(page), start); 665 pfn, start);
663 666
664 ret = memory_failure(page_to_pfn(page), MF_COUNT_INCREASED); 667 /*
668 * Drop the page reference taken by get_user_pages_fast(). In
669 * the absence of MF_COUNT_INCREASED the memory_failure()
670 * routine is responsible for pinning the page to prevent it
671 * from being released back to the page allocator.
672 */
673 put_page(page);
674 ret = memory_failure(pfn, 0);
665 if (ret) 675 if (ret)
666 return ret; 676 return ret;
667 } 677 }
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4ead5a4817de..e79cb59552d9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1701,8 +1701,6 @@ static enum oom_status mem_cgroup_oom(struct mem_cgroup *memcg, gfp_t mask, int
1701 if (mem_cgroup_out_of_memory(memcg, mask, order)) 1701 if (mem_cgroup_out_of_memory(memcg, mask, order))
1702 return OOM_SUCCESS; 1702 return OOM_SUCCESS;
1703 1703
1704 WARN(1,"Memory cgroup charge failed because of no reclaimable memory! "
1705 "This looks like a misconfiguration or a kernel bug.");
1706 return OOM_FAILED; 1704 return OOM_FAILED;
1707} 1705}
1708 1706
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 192d0bbfc9ea..0cd3de3550f0 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -55,6 +55,7 @@
55#include <linux/hugetlb.h> 55#include <linux/hugetlb.h>
56#include <linux/memory_hotplug.h> 56#include <linux/memory_hotplug.h>
57#include <linux/mm_inline.h> 57#include <linux/mm_inline.h>
58#include <linux/memremap.h>
58#include <linux/kfifo.h> 59#include <linux/kfifo.h>
59#include <linux/ratelimit.h> 60#include <linux/ratelimit.h>
60#include <linux/page-isolation.h> 61#include <linux/page-isolation.h>
@@ -175,22 +176,51 @@ int hwpoison_filter(struct page *p)
175EXPORT_SYMBOL_GPL(hwpoison_filter); 176EXPORT_SYMBOL_GPL(hwpoison_filter);
176 177
177/* 178/*
179 * Kill all processes that have a poisoned page mapped and then isolate
180 * the page.
181 *
182 * General strategy:
183 * Find all processes having the page mapped and kill them.
184 * But we keep a page reference around so that the page is not
185 * actually freed yet.
186 * Then stash the page away
187 *
188 * There's no convenient way to get back to mapped processes
189 * from the VMAs. So do a brute-force search over all
190 * running processes.
191 *
192 * Remember that machine checks are not common (or rather
193 * if they are common you have other problems), so this shouldn't
194 * be a performance issue.
195 *
196 * Also there are some races possible while we get from the
197 * error detection to actually handle it.
198 */
199
200struct to_kill {
201 struct list_head nd;
202 struct task_struct *tsk;
203 unsigned long addr;
204 short size_shift;
205 char addr_valid;
206};
207
208/*
178 * Send all the processes who have the page mapped a signal. 209 * Send all the processes who have the page mapped a signal.
179 * ``action optional'' if they are not immediately affected by the error 210 * ``action optional'' if they are not immediately affected by the error
180 * ``action required'' if error happened in current execution context 211 * ``action required'' if error happened in current execution context
181 */ 212 */
182static int kill_proc(struct task_struct *t, unsigned long addr, 213static int kill_proc(struct to_kill *tk, unsigned long pfn, int flags)
183 unsigned long pfn, struct page *page, int flags)
184{ 214{
185 short addr_lsb; 215 struct task_struct *t = tk->tsk;
216 short addr_lsb = tk->size_shift;
186 int ret; 217 int ret;
187 218
188 pr_err("Memory failure: %#lx: Killing %s:%d due to hardware memory corruption\n", 219 pr_err("Memory failure: %#lx: Killing %s:%d due to hardware memory corruption\n",
189 pfn, t->comm, t->pid); 220 pfn, t->comm, t->pid);
190 addr_lsb = compound_order(compound_head(page)) + PAGE_SHIFT;
191 221
192 if ((flags & MF_ACTION_REQUIRED) && t->mm == current->mm) { 222 if ((flags & MF_ACTION_REQUIRED) && t->mm == current->mm) {
193 ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)addr, 223 ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)tk->addr,
194 addr_lsb, current); 224 addr_lsb, current);
195 } else { 225 } else {
196 /* 226 /*
@@ -199,7 +229,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr,
199 * This could cause a loop when the user sets SIGBUS 229 * This could cause a loop when the user sets SIGBUS
200 * to SIG_IGN, but hopefully no one will do that? 230 * to SIG_IGN, but hopefully no one will do that?
201 */ 231 */
202 ret = send_sig_mceerr(BUS_MCEERR_AO, (void __user *)addr, 232 ret = send_sig_mceerr(BUS_MCEERR_AO, (void __user *)tk->addr,
203 addr_lsb, t); /* synchronous? */ 233 addr_lsb, t); /* synchronous? */
204 } 234 }
205 if (ret < 0) 235 if (ret < 0)
@@ -235,34 +265,39 @@ void shake_page(struct page *p, int access)
235} 265}
236EXPORT_SYMBOL_GPL(shake_page); 266EXPORT_SYMBOL_GPL(shake_page);
237 267
238/* 268static unsigned long dev_pagemap_mapping_shift(struct page *page,
239 * Kill all processes that have a poisoned page mapped and then isolate 269 struct vm_area_struct *vma)
240 * the page. 270{
241 * 271 unsigned long address = vma_address(page, vma);
242 * General strategy: 272 pgd_t *pgd;
243 * Find all processes having the page mapped and kill them. 273 p4d_t *p4d;
244 * But we keep a page reference around so that the page is not 274 pud_t *pud;
245 * actually freed yet. 275 pmd_t *pmd;
246 * Then stash the page away 276 pte_t *pte;
247 * 277
248 * There's no convenient way to get back to mapped processes 278 pgd = pgd_offset(vma->vm_mm, address);
249 * from the VMAs. So do a brute-force search over all 279 if (!pgd_present(*pgd))
250 * running processes. 280 return 0;
251 * 281 p4d = p4d_offset(pgd, address);
252 * Remember that machine checks are not common (or rather 282 if (!p4d_present(*p4d))
253 * if they are common you have other problems), so this shouldn't 283 return 0;
254 * be a performance issue. 284 pud = pud_offset(p4d, address);
255 * 285 if (!pud_present(*pud))
256 * Also there are some races possible while we get from the 286 return 0;
257 * error detection to actually handle it. 287 if (pud_devmap(*pud))
258 */ 288 return PUD_SHIFT;
259 289 pmd = pmd_offset(pud, address);
260struct to_kill { 290 if (!pmd_present(*pmd))
261 struct list_head nd; 291 return 0;
262 struct task_struct *tsk; 292 if (pmd_devmap(*pmd))
263 unsigned long addr; 293 return PMD_SHIFT;
264 char addr_valid; 294 pte = pte_offset_map(pmd, address);
265}; 295 if (!pte_present(*pte))
296 return 0;
297 if (pte_devmap(*pte))
298 return PAGE_SHIFT;
299 return 0;
300}
266 301
267/* 302/*
268 * Failure handling: if we can't find or can't kill a process there's 303 * Failure handling: if we can't find or can't kill a process there's
@@ -293,6 +328,10 @@ static void add_to_kill(struct task_struct *tsk, struct page *p,
293 } 328 }
294 tk->addr = page_address_in_vma(p, vma); 329 tk->addr = page_address_in_vma(p, vma);
295 tk->addr_valid = 1; 330 tk->addr_valid = 1;
331 if (is_zone_device_page(p))
332 tk->size_shift = dev_pagemap_mapping_shift(p, vma);
333 else
334 tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT;
296 335
297 /* 336 /*
298 * In theory we don't have to kill when the page was 337 * In theory we don't have to kill when the page was
@@ -300,7 +339,7 @@ static void add_to_kill(struct task_struct *tsk, struct page *p,
300 * likely very rare kill anyways just out of paranoia, but use 339 * likely very rare kill anyways just out of paranoia, but use
301 * a SIGKILL because the error is not contained anymore. 340 * a SIGKILL because the error is not contained anymore.
302 */ 341 */
303 if (tk->addr == -EFAULT) { 342 if (tk->addr == -EFAULT || tk->size_shift == 0) {
304 pr_info("Memory failure: Unable to find user space address %lx in %s\n", 343 pr_info("Memory failure: Unable to find user space address %lx in %s\n",
305 page_to_pfn(p), tsk->comm); 344 page_to_pfn(p), tsk->comm);
306 tk->addr_valid = 0; 345 tk->addr_valid = 0;
@@ -318,9 +357,8 @@ static void add_to_kill(struct task_struct *tsk, struct page *p,
318 * Also when FAIL is set do a force kill because something went 357 * Also when FAIL is set do a force kill because something went
319 * wrong earlier. 358 * wrong earlier.
320 */ 359 */
321static void kill_procs(struct list_head *to_kill, int forcekill, 360static void kill_procs(struct list_head *to_kill, int forcekill, bool fail,
322 bool fail, struct page *page, unsigned long pfn, 361 unsigned long pfn, int flags)
323 int flags)
324{ 362{
325 struct to_kill *tk, *next; 363 struct to_kill *tk, *next;
326 364
@@ -343,8 +381,7 @@ static void kill_procs(struct list_head *to_kill, int forcekill,
343 * check for that, but we need to tell the 381 * check for that, but we need to tell the
344 * process anyways. 382 * process anyways.
345 */ 383 */
346 else if (kill_proc(tk->tsk, tk->addr, 384 else if (kill_proc(tk, pfn, flags) < 0)
347 pfn, page, flags) < 0)
348 pr_err("Memory failure: %#lx: Cannot send advisory machine check signal to %s:%d\n", 385 pr_err("Memory failure: %#lx: Cannot send advisory machine check signal to %s:%d\n",
349 pfn, tk->tsk->comm, tk->tsk->pid); 386 pfn, tk->tsk->comm, tk->tsk->pid);
350 } 387 }
@@ -516,6 +553,7 @@ static const char * const action_page_types[] = {
516 [MF_MSG_TRUNCATED_LRU] = "already truncated LRU page", 553 [MF_MSG_TRUNCATED_LRU] = "already truncated LRU page",
517 [MF_MSG_BUDDY] = "free buddy page", 554 [MF_MSG_BUDDY] = "free buddy page",
518 [MF_MSG_BUDDY_2ND] = "free buddy page (2nd try)", 555 [MF_MSG_BUDDY_2ND] = "free buddy page (2nd try)",
556 [MF_MSG_DAX] = "dax page",
519 [MF_MSG_UNKNOWN] = "unknown page", 557 [MF_MSG_UNKNOWN] = "unknown page",
520}; 558};
521 559
@@ -1013,7 +1051,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
1013 * any accesses to the poisoned memory. 1051 * any accesses to the poisoned memory.
1014 */ 1052 */
1015 forcekill = PageDirty(hpage) || (flags & MF_MUST_KILL); 1053 forcekill = PageDirty(hpage) || (flags & MF_MUST_KILL);
1016 kill_procs(&tokill, forcekill, !unmap_success, p, pfn, flags); 1054 kill_procs(&tokill, forcekill, !unmap_success, pfn, flags);
1017 1055
1018 return unmap_success; 1056 return unmap_success;
1019} 1057}
@@ -1113,6 +1151,83 @@ out:
1113 return res; 1151 return res;
1114} 1152}
1115 1153
1154static int memory_failure_dev_pagemap(unsigned long pfn, int flags,
1155 struct dev_pagemap *pgmap)
1156{
1157 struct page *page = pfn_to_page(pfn);
1158 const bool unmap_success = true;
1159 unsigned long size = 0;
1160 struct to_kill *tk;
1161 LIST_HEAD(tokill);
1162 int rc = -EBUSY;
1163 loff_t start;
1164
1165 /*
1166 * Prevent the inode from being freed while we are interrogating
1167 * the address_space, typically this would be handled by
1168 * lock_page(), but dax pages do not use the page lock. This
1169 * also prevents changes to the mapping of this pfn until
1170 * poison signaling is complete.
1171 */
1172 if (!dax_lock_mapping_entry(page))
1173 goto out;
1174
1175 if (hwpoison_filter(page)) {
1176 rc = 0;
1177 goto unlock;
1178 }
1179
1180 switch (pgmap->type) {
1181 case MEMORY_DEVICE_PRIVATE:
1182 case MEMORY_DEVICE_PUBLIC:
1183 /*
1184 * TODO: Handle HMM pages which may need coordination
1185 * with device-side memory.
1186 */
1187 goto unlock;
1188 default:
1189 break;
1190 }
1191
1192 /*
1193 * Use this flag as an indication that the dax page has been
1194 * remapped UC to prevent speculative consumption of poison.
1195 */
1196 SetPageHWPoison(page);
1197
1198 /*
1199 * Unlike System-RAM there is no possibility to swap in a
1200 * different physical page at a given virtual address, so all
1201 * userspace consumption of ZONE_DEVICE memory necessitates
1202 * SIGBUS (i.e. MF_MUST_KILL)
1203 */
1204 flags |= MF_ACTION_REQUIRED | MF_MUST_KILL;
1205 collect_procs(page, &tokill, flags & MF_ACTION_REQUIRED);
1206
1207 list_for_each_entry(tk, &tokill, nd)
1208 if (tk->size_shift)
1209 size = max(size, 1UL << tk->size_shift);
1210 if (size) {
1211 /*
1212 * Unmap the largest mapping to avoid breaking up
1213 * device-dax mappings which are constant size. The
1214 * actual size of the mapping being torn down is
1215 * communicated in siginfo, see kill_proc()
1216 */
1217 start = (page->index << PAGE_SHIFT) & ~(size - 1);
1218 unmap_mapping_range(page->mapping, start, start + size, 0);
1219 }
1220 kill_procs(&tokill, flags & MF_MUST_KILL, !unmap_success, pfn, flags);
1221 rc = 0;
1222unlock:
1223 dax_unlock_mapping_entry(page);
1224out:
1225 /* drop pgmap ref acquired in caller */
1226 put_dev_pagemap(pgmap);
1227 action_result(pfn, MF_MSG_DAX, rc ? MF_FAILED : MF_RECOVERED);
1228 return rc;
1229}
1230
1116/** 1231/**
1117 * memory_failure - Handle memory failure of a page. 1232 * memory_failure - Handle memory failure of a page.
1118 * @pfn: Page Number of the corrupted page 1233 * @pfn: Page Number of the corrupted page
@@ -1135,6 +1250,7 @@ int memory_failure(unsigned long pfn, int flags)
1135 struct page *p; 1250 struct page *p;
1136 struct page *hpage; 1251 struct page *hpage;
1137 struct page *orig_head; 1252 struct page *orig_head;
1253 struct dev_pagemap *pgmap;
1138 int res; 1254 int res;
1139 unsigned long page_flags; 1255 unsigned long page_flags;
1140 1256
@@ -1147,6 +1263,10 @@ int memory_failure(unsigned long pfn, int flags)
1147 return -ENXIO; 1263 return -ENXIO;
1148 } 1264 }
1149 1265
1266 pgmap = get_dev_pagemap(pfn, NULL);
1267 if (pgmap)
1268 return memory_failure_dev_pagemap(pfn, flags, pgmap);
1269
1150 p = pfn_to_page(pfn); 1270 p = pfn_to_page(pfn);
1151 if (PageHuge(p)) 1271 if (PageHuge(p))
1152 return memory_failure_hugetlb(pfn, flags); 1272 return memory_failure_hugetlb(pfn, flags);
@@ -1777,6 +1897,14 @@ int soft_offline_page(struct page *page, int flags)
1777 int ret; 1897 int ret;
1778 unsigned long pfn = page_to_pfn(page); 1898 unsigned long pfn = page_to_pfn(page);
1779 1899
1900 if (is_zone_device_page(page)) {
1901 pr_debug_ratelimited("soft_offline: %#lx page is device page\n",
1902 pfn);
1903 if (flags & MF_COUNT_INCREASED)
1904 put_page(page);
1905 return -EIO;
1906 }
1907
1780 if (PageHWPoison(page)) { 1908 if (PageHWPoison(page)) {
1781 pr_info("soft offline: %#lx page already poisoned\n", pfn); 1909 pr_info("soft offline: %#lx page already poisoned\n", pfn);
1782 if (flags & MF_COUNT_INCREASED) 1910 if (flags & MF_COUNT_INCREASED)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 9eea6e809a4e..38d94b703e9d 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1333,7 +1333,8 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
1333 if (__PageMovable(page)) 1333 if (__PageMovable(page))
1334 return pfn; 1334 return pfn;
1335 if (PageHuge(page)) { 1335 if (PageHuge(page)) {
1336 if (page_huge_active(page)) 1336 if (hugepage_migration_supported(page_hstate(page)) &&
1337 page_huge_active(page))
1337 return pfn; 1338 return pfn;
1338 else 1339 else
1339 pfn = round_up(pfn + 1, 1340 pfn = round_up(pfn + 1,
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index b5b25e4dcbbb..f10aa5360616 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -522,6 +522,7 @@ bool __oom_reap_task_mm(struct mm_struct *mm)
522 522
523 tlb_gather_mmu(&tlb, mm, start, end); 523 tlb_gather_mmu(&tlb, mm, start, end);
524 if (mmu_notifier_invalidate_range_start_nonblock(mm, start, end)) { 524 if (mmu_notifier_invalidate_range_start_nonblock(mm, start, end)) {
525 tlb_finish_mmu(&tlb, start, end);
525 ret = false; 526 ret = false;
526 continue; 527 continue;
527 } 528 }
@@ -1103,10 +1104,17 @@ bool out_of_memory(struct oom_control *oc)
1103 } 1104 }
1104 1105
1105 select_bad_process(oc); 1106 select_bad_process(oc);
1106 /* Found nothing?!?! Either we hang forever, or we panic. */ 1107 /* Found nothing?!?! */
1107 if (!oc->chosen && !is_sysrq_oom(oc) && !is_memcg_oom(oc)) { 1108 if (!oc->chosen) {
1108 dump_header(oc, NULL); 1109 dump_header(oc, NULL);
1109 panic("Out of memory and no killable processes...\n"); 1110 pr_warn("Out of memory and no killable processes...\n");
1111 /*
1112 * If we got here due to an actual allocation at the
1113 * system level, we cannot survive this and will enter
1114 * an endless loop in the allocator. Bail out now.
1115 */
1116 if (!is_sysrq_oom(oc) && !is_memcg_oom(oc))
1117 panic("System is deadlocked on memory\n");
1110 } 1118 }
1111 if (oc->chosen && oc->chosen != (void *)-1UL) 1119 if (oc->chosen && oc->chosen != (void *)-1UL)
1112 oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" : 1120 oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" :
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 6551d3b0dc30..84ae9bf5858a 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -27,7 +27,6 @@
27#include <linux/mpage.h> 27#include <linux/mpage.h>
28#include <linux/rmap.h> 28#include <linux/rmap.h>
29#include <linux/percpu.h> 29#include <linux/percpu.h>
30#include <linux/notifier.h>
31#include <linux/smp.h> 30#include <linux/smp.h>
32#include <linux/sysctl.h> 31#include <linux/sysctl.h>
33#include <linux/cpu.h> 32#include <linux/cpu.h>
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e75865d58ba7..89d2a2ab3fe6 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -32,7 +32,6 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/ratelimit.h> 33#include <linux/ratelimit.h>
34#include <linux/oom.h> 34#include <linux/oom.h>
35#include <linux/notifier.h>
36#include <linux/topology.h> 35#include <linux/topology.h>
37#include <linux/sysctl.h> 36#include <linux/sysctl.h>
38#include <linux/cpu.h> 37#include <linux/cpu.h>
@@ -7709,6 +7708,10 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
7709 * handle each tail page individually in migration. 7708 * handle each tail page individually in migration.
7710 */ 7709 */
7711 if (PageHuge(page)) { 7710 if (PageHuge(page)) {
7711
7712 if (!hugepage_migration_supported(page_hstate(page)))
7713 goto unmovable;
7714
7712 iter = round_up(iter + 1, 1<<compound_order(page)) - 1; 7715 iter = round_up(iter + 1, 1<<compound_order(page)) - 1;
7713 continue; 7716 continue;
7714 } 7717 }
diff --git a/mm/slub.c b/mm/slub.c
index ce2b9e5cea77..8da34a8af53d 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -19,7 +19,6 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include "slab.h" 20#include "slab.h"
21#include <linux/proc_fs.h> 21#include <linux/proc_fs.h>
22#include <linux/notifier.h>
23#include <linux/seq_file.h> 22#include <linux/seq_file.h>
24#include <linux/kasan.h> 23#include <linux/kasan.h>
25#include <linux/cpu.h> 24#include <linux/cpu.h>
diff --git a/mm/util.c b/mm/util.c
index d2890a407332..9e3ebd2ef65f 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -435,11 +435,14 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
435EXPORT_SYMBOL(kvmalloc_node); 435EXPORT_SYMBOL(kvmalloc_node);
436 436
437/** 437/**
438 * kvfree - free memory allocated with kvmalloc 438 * kvfree() - Free memory.
439 * @addr: pointer returned by kvmalloc 439 * @addr: Pointer to allocated memory.
440 * 440 *
441 * If the memory is allocated from vmalloc area it is freed with vfree(). 441 * kvfree frees memory allocated by any of vmalloc(), kmalloc() or kvmalloc().
442 * Otherwise kfree() is used. 442 * It is slightly more efficient to use kfree() or vfree() if you are certain
443 * that you know which one to use.
444 *
445 * Context: Any context except NMI.
443 */ 446 */
444void kvfree(const void *addr) 447void kvfree(const void *addr)
445{ 448{
diff --git a/mm/vmacache.c b/mm/vmacache.c
index ea517bef7dc5..cdc32a3b02fa 100644
--- a/mm/vmacache.c
+++ b/mm/vmacache.c
@@ -20,44 +20,6 @@
20#define VMACACHE_HASH(addr) ((addr >> VMACACHE_SHIFT) & VMACACHE_MASK) 20#define VMACACHE_HASH(addr) ((addr >> VMACACHE_SHIFT) & VMACACHE_MASK)
21 21
22/* 22/*
23 * Flush vma caches for threads that share a given mm.
24 *
25 * The operation is safe because the caller holds the mmap_sem
26 * exclusively and other threads accessing the vma cache will
27 * have mmap_sem held at least for read, so no extra locking
28 * is required to maintain the vma cache.
29 */
30void vmacache_flush_all(struct mm_struct *mm)
31{
32 struct task_struct *g, *p;
33
34 count_vm_vmacache_event(VMACACHE_FULL_FLUSHES);
35
36 /*
37 * Single threaded tasks need not iterate the entire
38 * list of process. We can avoid the flushing as well
39 * since the mm's seqnum was increased and don't have
40 * to worry about other threads' seqnum. Current's
41 * flush will occur upon the next lookup.
42 */
43 if (atomic_read(&mm->mm_users) == 1)
44 return;
45
46 rcu_read_lock();
47 for_each_process_thread(g, p) {
48 /*
49 * Only flush the vmacache pointers as the
50 * mm seqnum is already set and curr's will
51 * be set upon invalidation when the next
52 * lookup is done.
53 */
54 if (mm == p->mm)
55 vmacache_flush(p);
56 }
57 rcu_read_unlock();
58}
59
60/*
61 * This task may be accessing a foreign mm via (for example) 23 * This task may be accessing a foreign mm via (for example)
62 * get_user_pages()->find_vma(). The vmacache is task-local and this 24 * get_user_pages()->find_vma(). The vmacache is task-local and this
63 * task's vmacache pertains to a different mm (ie, its own). There is 25 * task's vmacache pertains to a different mm (ie, its own). There is
diff --git a/net/core/dev.c b/net/core/dev.c
index 325fc5088370..82114e1111e6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -93,7 +93,6 @@
93#include <linux/netdevice.h> 93#include <linux/netdevice.h>
94#include <linux/etherdevice.h> 94#include <linux/etherdevice.h>
95#include <linux/ethtool.h> 95#include <linux/ethtool.h>
96#include <linux/notifier.h>
97#include <linux/skbuff.h> 96#include <linux/skbuff.h>
98#include <linux/bpf.h> 97#include <linux/bpf.h>
99#include <linux/bpf_trace.h> 98#include <linux/bpf_trace.h>
diff --git a/net/core/filter.c b/net/core/filter.c
index c25eb36f1320..aecdeba052d3 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2282,14 +2282,21 @@ static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
2282 .arg2_type = ARG_ANYTHING, 2282 .arg2_type = ARG_ANYTHING,
2283}; 2283};
2284 2284
2285#define sk_msg_iter_var(var) \
2286 do { \
2287 var++; \
2288 if (var == MAX_SKB_FRAGS) \
2289 var = 0; \
2290 } while (0)
2291
2285BPF_CALL_4(bpf_msg_pull_data, 2292BPF_CALL_4(bpf_msg_pull_data,
2286 struct sk_msg_buff *, msg, u32, start, u32, end, u64, flags) 2293 struct sk_msg_buff *, msg, u32, start, u32, end, u64, flags)
2287{ 2294{
2288 unsigned int len = 0, offset = 0, copy = 0; 2295 unsigned int len = 0, offset = 0, copy = 0, poffset = 0;
2296 int bytes = end - start, bytes_sg_total;
2289 struct scatterlist *sg = msg->sg_data; 2297 struct scatterlist *sg = msg->sg_data;
2290 int first_sg, last_sg, i, shift; 2298 int first_sg, last_sg, i, shift;
2291 unsigned char *p, *to, *from; 2299 unsigned char *p, *to, *from;
2292 int bytes = end - start;
2293 struct page *page; 2300 struct page *page;
2294 2301
2295 if (unlikely(flags || end <= start)) 2302 if (unlikely(flags || end <= start))
@@ -2299,21 +2306,22 @@ BPF_CALL_4(bpf_msg_pull_data,
2299 i = msg->sg_start; 2306 i = msg->sg_start;
2300 do { 2307 do {
2301 len = sg[i].length; 2308 len = sg[i].length;
2302 offset += len;
2303 if (start < offset + len) 2309 if (start < offset + len)
2304 break; 2310 break;
2305 i++; 2311 offset += len;
2306 if (i == MAX_SKB_FRAGS) 2312 sk_msg_iter_var(i);
2307 i = 0;
2308 } while (i != msg->sg_end); 2313 } while (i != msg->sg_end);
2309 2314
2310 if (unlikely(start >= offset + len)) 2315 if (unlikely(start >= offset + len))
2311 return -EINVAL; 2316 return -EINVAL;
2312 2317
2313 if (!msg->sg_copy[i] && bytes <= len)
2314 goto out;
2315
2316 first_sg = i; 2318 first_sg = i;
2319 /* The start may point into the sg element so we need to also
2320 * account for the headroom.
2321 */
2322 bytes_sg_total = start - offset + bytes;
2323 if (!msg->sg_copy[i] && bytes_sg_total <= len)
2324 goto out;
2317 2325
2318 /* At this point we need to linearize multiple scatterlist 2326 /* At this point we need to linearize multiple scatterlist
2319 * elements or a single shared page. Either way we need to 2327 * elements or a single shared page. Either way we need to
@@ -2327,37 +2335,32 @@ BPF_CALL_4(bpf_msg_pull_data,
2327 */ 2335 */
2328 do { 2336 do {
2329 copy += sg[i].length; 2337 copy += sg[i].length;
2330 i++; 2338 sk_msg_iter_var(i);
2331 if (i == MAX_SKB_FRAGS) 2339 if (bytes_sg_total <= copy)
2332 i = 0;
2333 if (bytes < copy)
2334 break; 2340 break;
2335 } while (i != msg->sg_end); 2341 } while (i != msg->sg_end);
2336 last_sg = i; 2342 last_sg = i;
2337 2343
2338 if (unlikely(copy < end - start)) 2344 if (unlikely(bytes_sg_total > copy))
2339 return -EINVAL; 2345 return -EINVAL;
2340 2346
2341 page = alloc_pages(__GFP_NOWARN | GFP_ATOMIC, get_order(copy)); 2347 page = alloc_pages(__GFP_NOWARN | GFP_ATOMIC, get_order(copy));
2342 if (unlikely(!page)) 2348 if (unlikely(!page))
2343 return -ENOMEM; 2349 return -ENOMEM;
2344 p = page_address(page); 2350 p = page_address(page);
2345 offset = 0;
2346 2351
2347 i = first_sg; 2352 i = first_sg;
2348 do { 2353 do {
2349 from = sg_virt(&sg[i]); 2354 from = sg_virt(&sg[i]);
2350 len = sg[i].length; 2355 len = sg[i].length;
2351 to = p + offset; 2356 to = p + poffset;
2352 2357
2353 memcpy(to, from, len); 2358 memcpy(to, from, len);
2354 offset += len; 2359 poffset += len;
2355 sg[i].length = 0; 2360 sg[i].length = 0;
2356 put_page(sg_page(&sg[i])); 2361 put_page(sg_page(&sg[i]));
2357 2362
2358 i++; 2363 sk_msg_iter_var(i);
2359 if (i == MAX_SKB_FRAGS)
2360 i = 0;
2361 } while (i != last_sg); 2364 } while (i != last_sg);
2362 2365
2363 sg[first_sg].length = copy; 2366 sg[first_sg].length = copy;
@@ -2367,11 +2370,15 @@ BPF_CALL_4(bpf_msg_pull_data,
2367 * had a single entry though we can just replace it and 2370 * had a single entry though we can just replace it and
2368 * be done. Otherwise walk the ring and shift the entries. 2371 * be done. Otherwise walk the ring and shift the entries.
2369 */ 2372 */
2370 shift = last_sg - first_sg - 1; 2373 WARN_ON_ONCE(last_sg == first_sg);
2374 shift = last_sg > first_sg ?
2375 last_sg - first_sg - 1 :
2376 MAX_SKB_FRAGS - first_sg + last_sg - 1;
2371 if (!shift) 2377 if (!shift)
2372 goto out; 2378 goto out;
2373 2379
2374 i = first_sg + 1; 2380 i = first_sg;
2381 sk_msg_iter_var(i);
2375 do { 2382 do {
2376 int move_from; 2383 int move_from;
2377 2384
@@ -2388,15 +2395,13 @@ BPF_CALL_4(bpf_msg_pull_data,
2388 sg[move_from].page_link = 0; 2395 sg[move_from].page_link = 0;
2389 sg[move_from].offset = 0; 2396 sg[move_from].offset = 0;
2390 2397
2391 i++; 2398 sk_msg_iter_var(i);
2392 if (i == MAX_SKB_FRAGS)
2393 i = 0;
2394 } while (1); 2399 } while (1);
2395 msg->sg_end -= shift; 2400 msg->sg_end -= shift;
2396 if (msg->sg_end < 0) 2401 if (msg->sg_end < 0)
2397 msg->sg_end += MAX_SKB_FRAGS; 2402 msg->sg_end += MAX_SKB_FRAGS;
2398out: 2403out:
2399 msg->data = sg_virt(&sg[i]) + start - offset; 2404 msg->data = sg_virt(&sg[first_sg]) + start - offset;
2400 msg->data_end = msg->data + bytes; 2405 msg->data_end = msg->data + bytes;
2401 2406
2402 return 0; 2407 return 0;
@@ -7281,7 +7286,7 @@ static u32 sk_reuseport_convert_ctx_access(enum bpf_access_type type,
7281 break; 7286 break;
7282 7287
7283 case offsetof(struct sk_reuseport_md, ip_protocol): 7288 case offsetof(struct sk_reuseport_md, ip_protocol):
7284 BUILD_BUG_ON(hweight_long(SK_FL_PROTO_MASK) != BITS_PER_BYTE); 7289 BUILD_BUG_ON(HWEIGHT32(SK_FL_PROTO_MASK) != BITS_PER_BYTE);
7285 SK_REUSEPORT_LOAD_SK_FIELD_SIZE_OFF(__sk_flags_offset, 7290 SK_REUSEPORT_LOAD_SK_FIELD_SIZE_OFF(__sk_flags_offset,
7286 BPF_W, 0); 7291 BPF_W, 0);
7287 *insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, SK_FL_PROTO_MASK); 7292 *insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, SK_FL_PROTO_MASK);
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 738871af5efa..670c84b1bfc2 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -1001,22 +1001,18 @@ static int register_pernet_operations(struct list_head *list,
1001 int error; 1001 int error;
1002 1002
1003 if (ops->id) { 1003 if (ops->id) {
1004again: 1004 error = ida_alloc_min(&net_generic_ids, MIN_PERNET_OPS_ID,
1005 error = ida_get_new_above(&net_generic_ids, MIN_PERNET_OPS_ID, ops->id); 1005 GFP_KERNEL);
1006 if (error < 0) { 1006 if (error < 0)
1007 if (error == -EAGAIN) {
1008 ida_pre_get(&net_generic_ids, GFP_KERNEL);
1009 goto again;
1010 }
1011 return error; 1007 return error;
1012 } 1008 *ops->id = error;
1013 max_gen_ptrs = max(max_gen_ptrs, *ops->id + 1); 1009 max_gen_ptrs = max(max_gen_ptrs, *ops->id + 1);
1014 } 1010 }
1015 error = __register_pernet_operations(list, ops); 1011 error = __register_pernet_operations(list, ops);
1016 if (error) { 1012 if (error) {
1017 rcu_barrier(); 1013 rcu_barrier();
1018 if (ops->id) 1014 if (ops->id)
1019 ida_remove(&net_generic_ids, *ops->id); 1015 ida_free(&net_generic_ids, *ops->id);
1020 } 1016 }
1021 1017
1022 return error; 1018 return error;
@@ -1027,7 +1023,7 @@ static void unregister_pernet_operations(struct pernet_operations *ops)
1027 __unregister_pernet_operations(ops); 1023 __unregister_pernet_operations(ops);
1028 rcu_barrier(); 1024 rcu_barrier();
1029 if (ops->id) 1025 if (ops->id)
1030 ida_remove(&net_generic_ids, *ops->id); 1026 ida_free(&net_generic_ids, *ops->id);
1031} 1027}
1032 1028
1033/** 1029/**
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 24431e578310..60c928894a78 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -324,6 +324,10 @@ void rtnl_unregister_all(int protocol)
324 324
325 rtnl_lock(); 325 rtnl_lock();
326 tab = rtnl_msg_handlers[protocol]; 326 tab = rtnl_msg_handlers[protocol];
327 if (!tab) {
328 rtnl_unlock();
329 return;
330 }
327 RCU_INIT_POINTER(rtnl_msg_handlers[protocol], NULL); 331 RCU_INIT_POINTER(rtnl_msg_handlers[protocol], NULL);
328 for (msgindex = 0; msgindex < RTM_NR_MSGTYPES; msgindex++) { 332 for (msgindex = 0; msgindex < RTM_NR_MSGTYPES; msgindex++) {
329 link = tab[msgindex]; 333 link = tab[msgindex];
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index c996c09d095f..b2c807f67aba 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -939,9 +939,6 @@ struct ubuf_info *sock_zerocopy_alloc(struct sock *sk, size_t size)
939 939
940 WARN_ON_ONCE(!in_task()); 940 WARN_ON_ONCE(!in_task());
941 941
942 if (!sock_flag(sk, SOCK_ZEROCOPY))
943 return NULL;
944
945 skb = sock_omalloc(sk, 0, GFP_KERNEL); 942 skb = sock_omalloc(sk, 0, GFP_KERNEL);
946 if (!skb) 943 if (!skb)
947 return NULL; 944 return NULL;
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index e63c554e0623..9f3209ff7ffd 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -19,12 +19,10 @@
19#include <linux/of_mdio.h> 19#include <linux/of_mdio.h>
20#include <linux/of_platform.h> 20#include <linux/of_platform.h>
21#include <linux/of_net.h> 21#include <linux/of_net.h>
22#include <linux/of_gpio.h>
23#include <linux/netdevice.h> 22#include <linux/netdevice.h>
24#include <linux/sysfs.h> 23#include <linux/sysfs.h>
25#include <linux/phy_fixed.h> 24#include <linux/phy_fixed.h>
26#include <linux/ptp_classify.h> 25#include <linux/ptp_classify.h>
27#include <linux/gpio/consumer.h>
28#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
29 27
30#include "dsa_priv.h" 28#include "dsa_priv.h"
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 962c4fd338ba..1c45c1d6d241 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -767,7 +767,6 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,
767 const struct tc_action *a; 767 const struct tc_action *a;
768 struct dsa_port *to_dp; 768 struct dsa_port *to_dp;
769 int err = -EOPNOTSUPP; 769 int err = -EOPNOTSUPP;
770 LIST_HEAD(actions);
771 770
772 if (!ds->ops->port_mirror_add) 771 if (!ds->ops->port_mirror_add)
773 return err; 772 return err;
@@ -775,8 +774,7 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,
775 if (!tcf_exts_has_one_action(cls->exts)) 774 if (!tcf_exts_has_one_action(cls->exts))
776 return err; 775 return err;
777 776
778 tcf_exts_to_list(cls->exts, &actions); 777 a = tcf_exts_first_action(cls->exts);
779 a = list_first_entry(&actions, struct tc_action, list);
780 778
781 if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) { 779 if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
782 struct dsa_mall_mirror_tc_entry *mirror; 780 struct dsa_mall_mirror_tc_entry *mirror;
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index cf75f8944b05..4da39446da2d 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -820,10 +820,9 @@ static void igmp_timer_expire(struct timer_list *t)
820 spin_lock(&im->lock); 820 spin_lock(&im->lock);
821 im->tm_running = 0; 821 im->tm_running = 0;
822 822
823 if (im->unsolicit_count) { 823 if (im->unsolicit_count && --im->unsolicit_count)
824 im->unsolicit_count--;
825 igmp_start_timer(im, unsolicited_report_interval(in_dev)); 824 igmp_start_timer(im, unsolicited_report_interval(in_dev));
826 } 825
827 im->reporter = 1; 826 im->reporter = 1;
828 spin_unlock(&im->lock); 827 spin_unlock(&im->lock);
829 828
@@ -1308,6 +1307,8 @@ static void igmp_group_added(struct ip_mc_list *im)
1308 1307
1309 if (in_dev->dead) 1308 if (in_dev->dead)
1310 return; 1309 return;
1310
1311 im->unsolicit_count = net->ipv4.sysctl_igmp_qrv;
1311 if (IGMP_V1_SEEN(in_dev) || IGMP_V2_SEEN(in_dev)) { 1312 if (IGMP_V1_SEEN(in_dev) || IGMP_V2_SEEN(in_dev)) {
1312 spin_lock_bh(&im->lock); 1313 spin_lock_bh(&im->lock);
1313 igmp_start_timer(im, IGMP_INITIAL_REPORT_DELAY); 1314 igmp_start_timer(im, IGMP_INITIAL_REPORT_DELAY);
@@ -1391,9 +1392,6 @@ static void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
1391 unsigned int mode) 1392 unsigned int mode)
1392{ 1393{
1393 struct ip_mc_list *im; 1394 struct ip_mc_list *im;
1394#ifdef CONFIG_IP_MULTICAST
1395 struct net *net = dev_net(in_dev->dev);
1396#endif
1397 1395
1398 ASSERT_RTNL(); 1396 ASSERT_RTNL();
1399 1397
@@ -1420,7 +1418,6 @@ static void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
1420 spin_lock_init(&im->lock); 1418 spin_lock_init(&im->lock);
1421#ifdef CONFIG_IP_MULTICAST 1419#ifdef CONFIG_IP_MULTICAST
1422 timer_setup(&im->timer, igmp_timer_expire, 0); 1420 timer_setup(&im->timer, igmp_timer_expire, 0);
1423 im->unsolicit_count = net->ipv4.sysctl_igmp_qrv;
1424#endif 1421#endif
1425 1422
1426 im->next_rcu = in_dev->mc_list; 1423 im->next_rcu = in_dev->mc_list;
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 88281fbce88c..e7227128df2c 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -599,6 +599,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *skb,
599 nextp = &fp->next; 599 nextp = &fp->next;
600 fp->prev = NULL; 600 fp->prev = NULL;
601 memset(&fp->rbnode, 0, sizeof(fp->rbnode)); 601 memset(&fp->rbnode, 0, sizeof(fp->rbnode));
602 fp->sk = NULL;
602 head->data_len += fp->len; 603 head->data_len += fp->len;
603 head->len += fp->len; 604 head->len += fp->len;
604 if (head->ip_summed != fp->ip_summed) 605 if (head->ip_summed != fp->ip_summed)
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 51a5d06085ac..8cce0e9ea08c 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -178,6 +178,9 @@ static void ipgre_err(struct sk_buff *skb, u32 info,
178 178
179 if (tpi->proto == htons(ETH_P_TEB)) 179 if (tpi->proto == htons(ETH_P_TEB))
180 itn = net_generic(net, gre_tap_net_id); 180 itn = net_generic(net, gre_tap_net_id);
181 else if (tpi->proto == htons(ETH_P_ERSPAN) ||
182 tpi->proto == htons(ETH_P_ERSPAN2))
183 itn = net_generic(net, erspan_net_id);
181 else 184 else
182 itn = net_generic(net, ipgre_net_id); 185 itn = net_generic(net, ipgre_net_id);
183 186
@@ -328,6 +331,8 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
328 ip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error); 331 ip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
329 return PACKET_RCVD; 332 return PACKET_RCVD;
330 } 333 }
334 return PACKET_REJECT;
335
331drop: 336drop:
332 kfree_skb(skb); 337 kfree_skb(skb);
333 return PACKET_RCVD; 338 return PACKET_RCVD;
@@ -1508,11 +1513,14 @@ nla_put_failure:
1508 1513
1509static void erspan_setup(struct net_device *dev) 1514static void erspan_setup(struct net_device *dev)
1510{ 1515{
1516 struct ip_tunnel *t = netdev_priv(dev);
1517
1511 ether_setup(dev); 1518 ether_setup(dev);
1512 dev->netdev_ops = &erspan_netdev_ops; 1519 dev->netdev_ops = &erspan_netdev_ops;
1513 dev->priv_flags &= ~IFF_TX_SKB_SHARING; 1520 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
1514 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 1521 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
1515 ip_tunnel_setup(dev, erspan_net_id); 1522 ip_tunnel_setup(dev, erspan_net_id);
1523 t->erspan_ver = 1;
1516} 1524}
1517 1525
1518static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = { 1526static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index d9504adc47b3..184bf2e0a1ed 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -106,6 +106,10 @@ config NF_NAT_IPV4
106 106
107if NF_NAT_IPV4 107if NF_NAT_IPV4
108 108
109config NF_NAT_MASQUERADE_IPV4
110 bool
111
112if NF_TABLES
109config NFT_CHAIN_NAT_IPV4 113config NFT_CHAIN_NAT_IPV4
110 depends on NF_TABLES_IPV4 114 depends on NF_TABLES_IPV4
111 tristate "IPv4 nf_tables nat chain support" 115 tristate "IPv4 nf_tables nat chain support"
@@ -115,9 +119,6 @@ config NFT_CHAIN_NAT_IPV4
115 packet transformations such as the source, destination address and 119 packet transformations such as the source, destination address and
116 source and destination ports. 120 source and destination ports.
117 121
118config NF_NAT_MASQUERADE_IPV4
119 bool
120
121config NFT_MASQ_IPV4 122config NFT_MASQ_IPV4
122 tristate "IPv4 masquerading support for nf_tables" 123 tristate "IPv4 masquerading support for nf_tables"
123 depends on NF_TABLES_IPV4 124 depends on NF_TABLES_IPV4
@@ -135,6 +136,7 @@ config NFT_REDIR_IPV4
135 help 136 help
136 This is the expression that provides IPv4 redirect support for 137 This is the expression that provides IPv4 redirect support for
137 nf_tables. 138 nf_tables.
139endif # NF_TABLES
138 140
139config NF_NAT_SNMP_BASIC 141config NF_NAT_SNMP_BASIC
140 tristate "Basic SNMP-ALG support" 142 tristate "Basic SNMP-ALG support"
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index b8af2fec5ad5..10c6246396cc 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1185,7 +1185,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
1185 1185
1186 flags = msg->msg_flags; 1186 flags = msg->msg_flags;
1187 1187
1188 if (flags & MSG_ZEROCOPY && size) { 1188 if (flags & MSG_ZEROCOPY && size && sock_flag(sk, SOCK_ZEROCOPY)) {
1189 if (sk->sk_state != TCP_ESTABLISHED) { 1189 if (sk->sk_state != TCP_ESTABLISHED) {
1190 err = -EINVAL; 1190 err = -EINVAL;
1191 goto out_err; 1191 goto out_err;
diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c
index 13d34427ca3d..02ff2dde9609 100644
--- a/net/ipv4/tcp_bbr.c
+++ b/net/ipv4/tcp_bbr.c
@@ -95,11 +95,10 @@ struct bbr {
95 u32 mode:3, /* current bbr_mode in state machine */ 95 u32 mode:3, /* current bbr_mode in state machine */
96 prev_ca_state:3, /* CA state on previous ACK */ 96 prev_ca_state:3, /* CA state on previous ACK */
97 packet_conservation:1, /* use packet conservation? */ 97 packet_conservation:1, /* use packet conservation? */
98 restore_cwnd:1, /* decided to revert cwnd to old value */
99 round_start:1, /* start of packet-timed tx->ack round? */ 98 round_start:1, /* start of packet-timed tx->ack round? */
100 idle_restart:1, /* restarting after idle? */ 99 idle_restart:1, /* restarting after idle? */
101 probe_rtt_round_done:1, /* a BBR_PROBE_RTT round at 4 pkts? */ 100 probe_rtt_round_done:1, /* a BBR_PROBE_RTT round at 4 pkts? */
102 unused:12, 101 unused:13,
103 lt_is_sampling:1, /* taking long-term ("LT") samples now? */ 102 lt_is_sampling:1, /* taking long-term ("LT") samples now? */
104 lt_rtt_cnt:7, /* round trips in long-term interval */ 103 lt_rtt_cnt:7, /* round trips in long-term interval */
105 lt_use_bw:1; /* use lt_bw as our bw estimate? */ 104 lt_use_bw:1; /* use lt_bw as our bw estimate? */
@@ -175,6 +174,8 @@ static const u32 bbr_lt_bw_diff = 4000 / 8;
175/* If we estimate we're policed, use lt_bw for this many round trips: */ 174/* If we estimate we're policed, use lt_bw for this many round trips: */
176static const u32 bbr_lt_bw_max_rtts = 48; 175static const u32 bbr_lt_bw_max_rtts = 48;
177 176
177static void bbr_check_probe_rtt_done(struct sock *sk);
178
178/* Do we estimate that STARTUP filled the pipe? */ 179/* Do we estimate that STARTUP filled the pipe? */
179static bool bbr_full_bw_reached(const struct sock *sk) 180static bool bbr_full_bw_reached(const struct sock *sk)
180{ 181{
@@ -309,6 +310,8 @@ static void bbr_cwnd_event(struct sock *sk, enum tcp_ca_event event)
309 */ 310 */
310 if (bbr->mode == BBR_PROBE_BW) 311 if (bbr->mode == BBR_PROBE_BW)
311 bbr_set_pacing_rate(sk, bbr_bw(sk), BBR_UNIT); 312 bbr_set_pacing_rate(sk, bbr_bw(sk), BBR_UNIT);
313 else if (bbr->mode == BBR_PROBE_RTT)
314 bbr_check_probe_rtt_done(sk);
312 } 315 }
313} 316}
314 317
@@ -396,17 +399,11 @@ static bool bbr_set_cwnd_to_recover_or_restore(
396 cwnd = tcp_packets_in_flight(tp) + acked; 399 cwnd = tcp_packets_in_flight(tp) + acked;
397 } else if (prev_state >= TCP_CA_Recovery && state < TCP_CA_Recovery) { 400 } else if (prev_state >= TCP_CA_Recovery && state < TCP_CA_Recovery) {
398 /* Exiting loss recovery; restore cwnd saved before recovery. */ 401 /* Exiting loss recovery; restore cwnd saved before recovery. */
399 bbr->restore_cwnd = 1; 402 cwnd = max(cwnd, bbr->prior_cwnd);
400 bbr->packet_conservation = 0; 403 bbr->packet_conservation = 0;
401 } 404 }
402 bbr->prev_ca_state = state; 405 bbr->prev_ca_state = state;
403 406
404 if (bbr->restore_cwnd) {
405 /* Restore cwnd after exiting loss recovery or PROBE_RTT. */
406 cwnd = max(cwnd, bbr->prior_cwnd);
407 bbr->restore_cwnd = 0;
408 }
409
410 if (bbr->packet_conservation) { 407 if (bbr->packet_conservation) {
411 *new_cwnd = max(cwnd, tcp_packets_in_flight(tp) + acked); 408 *new_cwnd = max(cwnd, tcp_packets_in_flight(tp) + acked);
412 return true; /* yes, using packet conservation */ 409 return true; /* yes, using packet conservation */
@@ -423,10 +420,10 @@ static void bbr_set_cwnd(struct sock *sk, const struct rate_sample *rs,
423{ 420{
424 struct tcp_sock *tp = tcp_sk(sk); 421 struct tcp_sock *tp = tcp_sk(sk);
425 struct bbr *bbr = inet_csk_ca(sk); 422 struct bbr *bbr = inet_csk_ca(sk);
426 u32 cwnd = 0, target_cwnd = 0; 423 u32 cwnd = tp->snd_cwnd, target_cwnd = 0;
427 424
428 if (!acked) 425 if (!acked)
429 return; 426 goto done; /* no packet fully ACKed; just apply caps */
430 427
431 if (bbr_set_cwnd_to_recover_or_restore(sk, rs, acked, &cwnd)) 428 if (bbr_set_cwnd_to_recover_or_restore(sk, rs, acked, &cwnd))
432 goto done; 429 goto done;
@@ -748,6 +745,20 @@ static void bbr_check_drain(struct sock *sk, const struct rate_sample *rs)
748 bbr_reset_probe_bw_mode(sk); /* we estimate queue is drained */ 745 bbr_reset_probe_bw_mode(sk); /* we estimate queue is drained */
749} 746}
750 747
748static void bbr_check_probe_rtt_done(struct sock *sk)
749{
750 struct tcp_sock *tp = tcp_sk(sk);
751 struct bbr *bbr = inet_csk_ca(sk);
752
753 if (!(bbr->probe_rtt_done_stamp &&
754 after(tcp_jiffies32, bbr->probe_rtt_done_stamp)))
755 return;
756
757 bbr->min_rtt_stamp = tcp_jiffies32; /* wait a while until PROBE_RTT */
758 tp->snd_cwnd = max(tp->snd_cwnd, bbr->prior_cwnd);
759 bbr_reset_mode(sk);
760}
761
751/* The goal of PROBE_RTT mode is to have BBR flows cooperatively and 762/* The goal of PROBE_RTT mode is to have BBR flows cooperatively and
752 * periodically drain the bottleneck queue, to converge to measure the true 763 * periodically drain the bottleneck queue, to converge to measure the true
753 * min_rtt (unloaded propagation delay). This allows the flows to keep queues 764 * min_rtt (unloaded propagation delay). This allows the flows to keep queues
@@ -806,12 +817,8 @@ static void bbr_update_min_rtt(struct sock *sk, const struct rate_sample *rs)
806 } else if (bbr->probe_rtt_done_stamp) { 817 } else if (bbr->probe_rtt_done_stamp) {
807 if (bbr->round_start) 818 if (bbr->round_start)
808 bbr->probe_rtt_round_done = 1; 819 bbr->probe_rtt_round_done = 1;
809 if (bbr->probe_rtt_round_done && 820 if (bbr->probe_rtt_round_done)
810 after(tcp_jiffies32, bbr->probe_rtt_done_stamp)) { 821 bbr_check_probe_rtt_done(sk);
811 bbr->min_rtt_stamp = tcp_jiffies32;
812 bbr->restore_cwnd = 1; /* snap to prior_cwnd */
813 bbr_reset_mode(sk);
814 }
815 } 822 }
816 } 823 }
817 /* Restart after idle ends only once we process a new S/ACK for data */ 824 /* Restart after idle ends only once we process a new S/ACK for data */
@@ -862,7 +869,6 @@ static void bbr_init(struct sock *sk)
862 bbr->has_seen_rtt = 0; 869 bbr->has_seen_rtt = 0;
863 bbr_init_pacing_rate_from_rtt(sk); 870 bbr_init_pacing_rate_from_rtt(sk);
864 871
865 bbr->restore_cwnd = 0;
866 bbr->round_start = 0; 872 bbr->round_start = 0;
867 bbr->idle_restart = 0; 873 bbr->idle_restart = 0;
868 bbr->full_bw_reached = 0; 874 bbr->full_bw_reached = 0;
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 4c2dd9f863f7..4cf2f7bb2802 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6367,8 +6367,8 @@ static bool tcp_syn_flood_action(const struct sock *sk,
6367 if (!queue->synflood_warned && 6367 if (!queue->synflood_warned &&
6368 net->ipv4.sysctl_tcp_syncookies != 2 && 6368 net->ipv4.sysctl_tcp_syncookies != 2 &&
6369 xchg(&queue->synflood_warned, 1) == 0) 6369 xchg(&queue->synflood_warned, 1) == 0)
6370 pr_info("%s: Possible SYN flooding on port %d. %s. Check SNMP counters.\n", 6370 net_info_ratelimited("%s: Possible SYN flooding on port %d. %s. Check SNMP counters.\n",
6371 proto, ntohs(tcp_hdr(skb)->dest), msg); 6371 proto, ntohs(tcp_hdr(skb)->dest), msg);
6372 6372
6373 return want_cookie; 6373 return want_cookie;
6374} 6374}
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 9e041fa5c545..44c09eddbb78 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2517,6 +2517,12 @@ static int __net_init tcp_sk_init(struct net *net)
2517 if (res) 2517 if (res)
2518 goto fail; 2518 goto fail;
2519 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); 2519 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE);
2520
2521 /* Please enforce IP_DF and IPID==0 for RST and
2522 * ACK sent in SYN-RECV and TIME-WAIT state.
2523 */
2524 inet_sk(sk)->pmtudisc = IP_PMTUDISC_DO;
2525
2520 *per_cpu_ptr(net->ipv4.tcp_sk, cpu) = sk; 2526 *per_cpu_ptr(net->ipv4.tcp_sk, cpu) = sk;
2521 } 2527 }
2522 2528
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 75ef332a7caf..12affb7864d9 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -184,8 +184,9 @@ kill:
184 inet_twsk_deschedule_put(tw); 184 inet_twsk_deschedule_put(tw);
185 return TCP_TW_SUCCESS; 185 return TCP_TW_SUCCESS;
186 } 186 }
187 } else {
188 inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN);
187 } 189 }
188 inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN);
189 190
190 if (tmp_opt.saw_tstamp) { 191 if (tmp_opt.saw_tstamp) {
191 tcptw->tw_ts_recent = tmp_opt.rcv_tsval; 192 tcptw->tw_ts_recent = tmp_opt.rcv_tsval;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 2fac4ad74867..d51a8c0b3372 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2398,7 +2398,7 @@ static void addrconf_add_mroute(struct net_device *dev)
2398 2398
2399 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); 2399 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
2400 2400
2401 ip6_route_add(&cfg, GFP_ATOMIC, NULL); 2401 ip6_route_add(&cfg, GFP_KERNEL, NULL);
2402} 2402}
2403 2403
2404static struct inet6_dev *addrconf_add_dev(struct net_device *dev) 2404static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
@@ -3062,7 +3062,7 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
3062 if (addr.s6_addr32[3]) { 3062 if (addr.s6_addr32[3]) {
3063 add_addr(idev, &addr, plen, scope); 3063 add_addr(idev, &addr, plen, scope);
3064 addrconf_prefix_route(&addr, plen, 0, idev->dev, 0, pflags, 3064 addrconf_prefix_route(&addr, plen, 0, idev->dev, 0, pflags,
3065 GFP_ATOMIC); 3065 GFP_KERNEL);
3066 return; 3066 return;
3067 } 3067 }
3068 3068
@@ -3087,7 +3087,7 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
3087 3087
3088 add_addr(idev, &addr, plen, flag); 3088 add_addr(idev, &addr, plen, flag);
3089 addrconf_prefix_route(&addr, plen, 0, idev->dev, 3089 addrconf_prefix_route(&addr, plen, 0, idev->dev,
3090 0, pflags, GFP_ATOMIC); 3090 0, pflags, GFP_KERNEL);
3091 } 3091 }
3092 } 3092 }
3093 } 3093 }
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 673bba31eb18..9a4261e50272 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -938,14 +938,14 @@ static int __init inet6_init(void)
938 938
939 err = proto_register(&pingv6_prot, 1); 939 err = proto_register(&pingv6_prot, 1);
940 if (err) 940 if (err)
941 goto out_unregister_ping_proto; 941 goto out_unregister_raw_proto;
942 942
943 /* We MUST register RAW sockets before we create the ICMP6, 943 /* We MUST register RAW sockets before we create the ICMP6,
944 * IGMP6, or NDISC control sockets. 944 * IGMP6, or NDISC control sockets.
945 */ 945 */
946 err = rawv6_init(); 946 err = rawv6_init();
947 if (err) 947 if (err)
948 goto out_unregister_raw_proto; 948 goto out_unregister_ping_proto;
949 949
950 /* Register the family here so that the init calls below will 950 /* Register the family here so that the init calls below will
951 * be able to create sockets. (?? is this dangerous ??) 951 * be able to create sockets. (?? is this dangerous ??)
@@ -1113,11 +1113,11 @@ netfilter_fail:
1113igmp_fail: 1113igmp_fail:
1114 ndisc_cleanup(); 1114 ndisc_cleanup();
1115ndisc_fail: 1115ndisc_fail:
1116 ip6_mr_cleanup(); 1116 icmpv6_cleanup();
1117icmp_fail: 1117icmp_fail:
1118 unregister_pernet_subsys(&inet6_net_ops); 1118 ip6_mr_cleanup();
1119ipmr_fail: 1119ipmr_fail:
1120 icmpv6_cleanup(); 1120 unregister_pernet_subsys(&inet6_net_ops);
1121register_pernet_fail: 1121register_pernet_fail:
1122 sock_unregister(PF_INET6); 1122 sock_unregister(PF_INET6);
1123 rtnl_unregister_all(PF_INET6); 1123 rtnl_unregister_all(PF_INET6);
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index d212738e9d10..5516f55e214b 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -198,6 +198,8 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
198 } 198 }
199 } 199 }
200 200
201 lwtstate_put(f6i->fib6_nh.nh_lwtstate);
202
201 if (f6i->fib6_nh.nh_dev) 203 if (f6i->fib6_nh.nh_dev)
202 dev_put(f6i->fib6_nh.nh_dev); 204 dev_put(f6i->fib6_nh.nh_dev);
203 205
@@ -987,7 +989,10 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
987 fib6_clean_expires(iter); 989 fib6_clean_expires(iter);
988 else 990 else
989 fib6_set_expires(iter, rt->expires); 991 fib6_set_expires(iter, rt->expires);
990 fib6_metric_set(iter, RTAX_MTU, rt->fib6_pmtu); 992
993 if (rt->fib6_pmtu)
994 fib6_metric_set(iter, RTAX_MTU,
995 rt->fib6_pmtu);
991 return -EEXIST; 996 return -EEXIST;
992 } 997 }
993 /* If we have the same destination and the same metric, 998 /* If we have the same destination and the same metric,
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 18a3794b0f52..e493b041d4ac 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1778,6 +1778,7 @@ static void ip6gre_netlink_parms(struct nlattr *data[],
1778 if (data[IFLA_GRE_COLLECT_METADATA]) 1778 if (data[IFLA_GRE_COLLECT_METADATA])
1779 parms->collect_md = true; 1779 parms->collect_md = true;
1780 1780
1781 parms->erspan_ver = 1;
1781 if (data[IFLA_GRE_ERSPAN_VER]) 1782 if (data[IFLA_GRE_ERSPAN_VER])
1782 parms->erspan_ver = nla_get_u8(data[IFLA_GRE_ERSPAN_VER]); 1783 parms->erspan_ver = nla_get_u8(data[IFLA_GRE_ERSPAN_VER]);
1783 1784
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 5df2a58d945c..419960b0ba16 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1188,7 +1188,15 @@ route_lookup:
1188 init_tel_txopt(&opt, encap_limit); 1188 init_tel_txopt(&opt, encap_limit);
1189 ipv6_push_frag_opts(skb, &opt.ops, &proto); 1189 ipv6_push_frag_opts(skb, &opt.ops, &proto);
1190 } 1190 }
1191 hop_limit = hop_limit ? : ip6_dst_hoplimit(dst); 1191
1192 if (hop_limit == 0) {
1193 if (skb->protocol == htons(ETH_P_IP))
1194 hop_limit = ip_hdr(skb)->ttl;
1195 else if (skb->protocol == htons(ETH_P_IPV6))
1196 hop_limit = ipv6_hdr(skb)->hop_limit;
1197 else
1198 hop_limit = ip6_dst_hoplimit(dst);
1199 }
1192 1200
1193 /* Calculate max headroom for all the headers and adjust 1201 /* Calculate max headroom for all the headers and adjust
1194 * needed_headroom if necessary. 1202 * needed_headroom if necessary.
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
index 38dec9da90d3..eeaf7455d51e 100644
--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -481,7 +481,7 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
481 } 481 }
482 482
483 mtu = dst_mtu(dst); 483 mtu = dst_mtu(dst);
484 if (!skb->ignore_df && skb->len > mtu) { 484 if (skb->len > mtu) {
485 skb_dst_update_pmtu(skb, mtu); 485 skb_dst_update_pmtu(skb, mtu);
486 486
487 if (skb->protocol == htons(ETH_P_IPV6)) { 487 if (skb->protocol == htons(ETH_P_IPV6)) {
@@ -1094,7 +1094,8 @@ static void __net_exit vti6_destroy_tunnels(struct vti6_net *ip6n,
1094 } 1094 }
1095 1095
1096 t = rtnl_dereference(ip6n->tnls_wc[0]); 1096 t = rtnl_dereference(ip6n->tnls_wc[0]);
1097 unregister_netdevice_queue(t->dev, list); 1097 if (t)
1098 unregister_netdevice_queue(t->dev, list);
1098} 1099}
1099 1100
1100static int __net_init vti6_init_net(struct net *net) 1101static int __net_init vti6_init_net(struct net *net)
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 2a14d8b65924..8f68a518d9db 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -445,6 +445,7 @@ nf_ct_frag6_reasm(struct frag_queue *fq, struct sk_buff *prev, struct net_devic
445 else if (head->ip_summed == CHECKSUM_COMPLETE) 445 else if (head->ip_summed == CHECKSUM_COMPLETE)
446 head->csum = csum_add(head->csum, fp->csum); 446 head->csum = csum_add(head->csum, fp->csum);
447 head->truesize += fp->truesize; 447 head->truesize += fp->truesize;
448 fp->sk = NULL;
448 } 449 }
449 sub_frag_mem_limit(fq->q.net, head->truesize); 450 sub_frag_mem_limit(fq->q.net, head->truesize);
450 451
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 7208c16302f6..18e00ce1719a 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -956,7 +956,7 @@ static void ip6_rt_init_dst(struct rt6_info *rt, struct fib6_info *ort)
956 rt->dst.error = 0; 956 rt->dst.error = 0;
957 rt->dst.output = ip6_output; 957 rt->dst.output = ip6_output;
958 958
959 if (ort->fib6_type == RTN_LOCAL) { 959 if (ort->fib6_type == RTN_LOCAL || ort->fib6_type == RTN_ANYCAST) {
960 rt->dst.input = ip6_input; 960 rt->dst.input = ip6_input;
961 } else if (ipv6_addr_type(&ort->fib6_dst.addr) & IPV6_ADDR_MULTICAST) { 961 } else if (ipv6_addr_type(&ort->fib6_dst.addr) & IPV6_ADDR_MULTICAST) {
962 rt->dst.input = ip6_mc_input; 962 rt->dst.input = ip6_mc_input;
@@ -996,7 +996,6 @@ static void ip6_rt_copy_init(struct rt6_info *rt, struct fib6_info *ort)
996 rt->rt6i_src = ort->fib6_src; 996 rt->rt6i_src = ort->fib6_src;
997#endif 997#endif
998 rt->rt6i_prefsrc = ort->fib6_prefsrc; 998 rt->rt6i_prefsrc = ort->fib6_prefsrc;
999 rt->dst.lwtstate = lwtstate_get(ort->fib6_nh.nh_lwtstate);
1000} 999}
1001 1000
1002static struct fib6_node* fib6_backtrack(struct fib6_node *fn, 1001static struct fib6_node* fib6_backtrack(struct fib6_node *fn,
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index a21d8ed0a325..e2f16a0173a9 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -351,20 +351,28 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
351 memcpy(&phs_hdr->iucv_hdr, imsg, sizeof(struct iucv_message)); 351 memcpy(&phs_hdr->iucv_hdr, imsg, sizeof(struct iucv_message));
352 352
353 skb->dev = iucv->hs_dev; 353 skb->dev = iucv->hs_dev;
354 if (!skb->dev) 354 if (!skb->dev) {
355 return -ENODEV; 355 err = -ENODEV;
356 if (!(skb->dev->flags & IFF_UP) || !netif_carrier_ok(skb->dev)) 356 goto err_free;
357 return -ENETDOWN; 357 }
358 if (!(skb->dev->flags & IFF_UP) || !netif_carrier_ok(skb->dev)) {
359 err = -ENETDOWN;
360 goto err_free;
361 }
358 if (skb->len > skb->dev->mtu) { 362 if (skb->len > skb->dev->mtu) {
359 if (sock->sk_type == SOCK_SEQPACKET) 363 if (sock->sk_type == SOCK_SEQPACKET) {
360 return -EMSGSIZE; 364 err = -EMSGSIZE;
361 else 365 goto err_free;
362 skb_trim(skb, skb->dev->mtu); 366 }
367 skb_trim(skb, skb->dev->mtu);
363 } 368 }
364 skb->protocol = cpu_to_be16(ETH_P_AF_IUCV); 369 skb->protocol = cpu_to_be16(ETH_P_AF_IUCV);
365 nskb = skb_clone(skb, GFP_ATOMIC); 370 nskb = skb_clone(skb, GFP_ATOMIC);
366 if (!nskb) 371 if (!nskb) {
367 return -ENOMEM; 372 err = -ENOMEM;
373 goto err_free;
374 }
375
368 skb_queue_tail(&iucv->send_skb_q, nskb); 376 skb_queue_tail(&iucv->send_skb_q, nskb);
369 err = dev_queue_xmit(skb); 377 err = dev_queue_xmit(skb);
370 if (net_xmit_eval(err)) { 378 if (net_xmit_eval(err)) {
@@ -375,6 +383,10 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
375 WARN_ON(atomic_read(&iucv->msg_recv) < 0); 383 WARN_ON(atomic_read(&iucv->msg_recv) < 0);
376 } 384 }
377 return net_xmit_eval(err); 385 return net_xmit_eval(err);
386
387err_free:
388 kfree_skb(skb);
389 return err;
378} 390}
379 391
380static struct sock *__iucv_get_sock_by_name(char *nm) 392static struct sock *__iucv_get_sock_by_name(char *nm)
@@ -1167,7 +1179,7 @@ static int iucv_sock_sendmsg(struct socket *sock, struct msghdr *msg,
1167 err = afiucv_hs_send(&txmsg, sk, skb, 0); 1179 err = afiucv_hs_send(&txmsg, sk, skb, 0);
1168 if (err) { 1180 if (err) {
1169 atomic_dec(&iucv->msg_sent); 1181 atomic_dec(&iucv->msg_sent);
1170 goto fail; 1182 goto out;
1171 } 1183 }
1172 } else { /* Classic VM IUCV transport */ 1184 } else { /* Classic VM IUCV transport */
1173 skb_queue_tail(&iucv->send_skb_q, skb); 1185 skb_queue_tail(&iucv->send_skb_q, skb);
@@ -2155,8 +2167,8 @@ static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,
2155 struct sock *sk; 2167 struct sock *sk;
2156 struct iucv_sock *iucv; 2168 struct iucv_sock *iucv;
2157 struct af_iucv_trans_hdr *trans_hdr; 2169 struct af_iucv_trans_hdr *trans_hdr;
2170 int err = NET_RX_SUCCESS;
2158 char nullstring[8]; 2171 char nullstring[8];
2159 int err = 0;
2160 2172
2161 if (skb->len < (ETH_HLEN + sizeof(struct af_iucv_trans_hdr))) { 2173 if (skb->len < (ETH_HLEN + sizeof(struct af_iucv_trans_hdr))) {
2162 WARN_ONCE(1, "AF_IUCV too short skb, len=%d, min=%d", 2174 WARN_ONCE(1, "AF_IUCV too short skb, len=%d, min=%d",
@@ -2254,7 +2266,7 @@ static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,
2254 err = afiucv_hs_callback_rx(sk, skb); 2266 err = afiucv_hs_callback_rx(sk, skb);
2255 break; 2267 break;
2256 default: 2268 default:
2257 ; 2269 kfree_skb(skb);
2258 } 2270 }
2259 2271
2260 return err; 2272 return err;
diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
index 8f7ef167c45a..eb502c6290c2 100644
--- a/net/iucv/iucv.c
+++ b/net/iucv/iucv.c
@@ -1874,7 +1874,7 @@ static void iucv_pm_complete(struct device *dev)
1874 * Returns 0 if there are still iucv pathes defined 1874 * Returns 0 if there are still iucv pathes defined
1875 * 1 if there are no iucv pathes defined 1875 * 1 if there are no iucv pathes defined
1876 */ 1876 */
1877int iucv_path_table_empty(void) 1877static int iucv_path_table_empty(void)
1878{ 1878{
1879 int i; 1879 int i;
1880 1880
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 6449a1c2283b..f0f5fedb8caa 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -947,8 +947,8 @@ static void ieee80211_rx_mgmt_deauth_ibss(struct ieee80211_sub_if_data *sdata,
947 if (len < IEEE80211_DEAUTH_FRAME_LEN) 947 if (len < IEEE80211_DEAUTH_FRAME_LEN)
948 return; 948 return;
949 949
950 ibss_dbg(sdata, "RX DeAuth SA=%pM DA=%pM BSSID=%pM (reason: %d)\n", 950 ibss_dbg(sdata, "RX DeAuth SA=%pM DA=%pM\n", mgmt->sa, mgmt->da);
951 mgmt->sa, mgmt->da, mgmt->bssid, reason); 951 ibss_dbg(sdata, "\tBSSID=%pM (reason: %d)\n", mgmt->bssid, reason);
952 sta_info_destroy_addr(sdata, mgmt->sa); 952 sta_info_destroy_addr(sdata, mgmt->sa);
953} 953}
954 954
@@ -966,9 +966,9 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
966 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); 966 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
967 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); 967 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
968 968
969 ibss_dbg(sdata, 969 ibss_dbg(sdata, "RX Auth SA=%pM DA=%pM\n", mgmt->sa, mgmt->da);
970 "RX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=%d)\n", 970 ibss_dbg(sdata, "\tBSSID=%pM (auth_transaction=%d)\n",
971 mgmt->sa, mgmt->da, mgmt->bssid, auth_transaction); 971 mgmt->bssid, auth_transaction);
972 972
973 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) 973 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1)
974 return; 974 return;
@@ -1175,10 +1175,10 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1175 rx_timestamp = drv_get_tsf(local, sdata); 1175 rx_timestamp = drv_get_tsf(local, sdata);
1176 } 1176 }
1177 1177
1178 ibss_dbg(sdata, 1178 ibss_dbg(sdata, "RX beacon SA=%pM BSSID=%pM TSF=0x%llx\n",
1179 "RX beacon SA=%pM BSSID=%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
1180 mgmt->sa, mgmt->bssid, 1179 mgmt->sa, mgmt->bssid,
1181 (unsigned long long)rx_timestamp, 1180 (unsigned long long)rx_timestamp);
1181 ibss_dbg(sdata, "\tBCN=0x%llx diff=%lld @%lu\n",
1182 (unsigned long long)beacon_timestamp, 1182 (unsigned long long)beacon_timestamp,
1183 (unsigned long long)(rx_timestamp - beacon_timestamp), 1183 (unsigned long long)(rx_timestamp - beacon_timestamp),
1184 jiffies); 1184 jiffies);
@@ -1537,9 +1537,9 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
1537 1537
1538 tx_last_beacon = drv_tx_last_beacon(local); 1538 tx_last_beacon = drv_tx_last_beacon(local);
1539 1539
1540 ibss_dbg(sdata, 1540 ibss_dbg(sdata, "RX ProbeReq SA=%pM DA=%pM\n", mgmt->sa, mgmt->da);
1541 "RX ProbeReq SA=%pM DA=%pM BSSID=%pM (tx_last_beacon=%d)\n", 1541 ibss_dbg(sdata, "\tBSSID=%pM (tx_last_beacon=%d)\n",
1542 mgmt->sa, mgmt->da, mgmt->bssid, tx_last_beacon); 1542 mgmt->bssid, tx_last_beacon);
1543 1543
1544 if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da)) 1544 if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da))
1545 return; 1545 return;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 4fb2709cb527..513627896204 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -256,8 +256,27 @@ static void ieee80211_restart_work(struct work_struct *work)
256 256
257 flush_work(&local->radar_detected_work); 257 flush_work(&local->radar_detected_work);
258 rtnl_lock(); 258 rtnl_lock();
259 list_for_each_entry(sdata, &local->interfaces, list) 259 list_for_each_entry(sdata, &local->interfaces, list) {
260 /*
261 * XXX: there may be more work for other vif types and even
262 * for station mode: a good thing would be to run most of
263 * the iface type's dependent _stop (ieee80211_mg_stop,
264 * ieee80211_ibss_stop) etc...
265 * For now, fix only the specific bug that was seen: race
266 * between csa_connection_drop_work and us.
267 */
268 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
269 /*
270 * This worker is scheduled from the iface worker that
271 * runs on mac80211's workqueue, so we can't be
272 * scheduling this worker after the cancel right here.
273 * The exception is ieee80211_chswitch_done.
274 * Then we can have a race...
275 */
276 cancel_work_sync(&sdata->u.mgd.csa_connection_drop_work);
277 }
260 flush_delayed_work(&sdata->dec_tailroom_needed_wk); 278 flush_delayed_work(&sdata->dec_tailroom_needed_wk);
279 }
261 ieee80211_scan_cancel(local); 280 ieee80211_scan_cancel(local);
262 281
263 /* make sure any new ROC will consider local->in_reconfig */ 282 /* make sure any new ROC will consider local->in_reconfig */
@@ -471,10 +490,7 @@ static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
471 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC | 490 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
472 IEEE80211_VHT_CAP_SHORT_GI_80 | 491 IEEE80211_VHT_CAP_SHORT_GI_80 |
473 IEEE80211_VHT_CAP_SHORT_GI_160 | 492 IEEE80211_VHT_CAP_SHORT_GI_160 |
474 IEEE80211_VHT_CAP_RXSTBC_1 | 493 IEEE80211_VHT_CAP_RXSTBC_MASK |
475 IEEE80211_VHT_CAP_RXSTBC_2 |
476 IEEE80211_VHT_CAP_RXSTBC_3 |
477 IEEE80211_VHT_CAP_RXSTBC_4 |
478 IEEE80211_VHT_CAP_TXSTBC | 494 IEEE80211_VHT_CAP_TXSTBC |
479 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | 495 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
480 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | 496 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
@@ -1208,6 +1224,7 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1208#if IS_ENABLED(CONFIG_IPV6) 1224#if IS_ENABLED(CONFIG_IPV6)
1209 unregister_inet6addr_notifier(&local->ifa6_notifier); 1225 unregister_inet6addr_notifier(&local->ifa6_notifier);
1210#endif 1226#endif
1227 ieee80211_txq_teardown_flows(local);
1211 1228
1212 rtnl_lock(); 1229 rtnl_lock();
1213 1230
@@ -1236,7 +1253,6 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1236 skb_queue_purge(&local->skb_queue); 1253 skb_queue_purge(&local->skb_queue);
1237 skb_queue_purge(&local->skb_queue_unreliable); 1254 skb_queue_purge(&local->skb_queue_unreliable);
1238 skb_queue_purge(&local->skb_queue_tdls_chsw); 1255 skb_queue_purge(&local->skb_queue_tdls_chsw);
1239 ieee80211_txq_teardown_flows(local);
1240 1256
1241 destroy_workqueue(local->workqueue); 1257 destroy_workqueue(local->workqueue);
1242 wiphy_unregister(local->hw.wiphy); 1258 wiphy_unregister(local->hw.wiphy);
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index 35ad3983ae4b..daf9db3c8f24 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -572,6 +572,10 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
572 forward = false; 572 forward = false;
573 reply = true; 573 reply = true;
574 target_metric = 0; 574 target_metric = 0;
575
576 if (SN_GT(target_sn, ifmsh->sn))
577 ifmsh->sn = target_sn;
578
575 if (time_after(jiffies, ifmsh->last_sn_update + 579 if (time_after(jiffies, ifmsh->last_sn_update +
576 net_traversal_jiffies(sdata)) || 580 net_traversal_jiffies(sdata)) ||
577 time_before(jiffies, ifmsh->last_sn_update)) { 581 time_before(jiffies, ifmsh->last_sn_update)) {
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 7fb9957359a3..3dbecae4be73 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1073,6 +1073,10 @@ static void ieee80211_chswitch_work(struct work_struct *work)
1073 */ 1073 */
1074 1074
1075 if (sdata->reserved_chanctx) { 1075 if (sdata->reserved_chanctx) {
1076 struct ieee80211_supported_band *sband = NULL;
1077 struct sta_info *mgd_sta = NULL;
1078 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1079
1076 /* 1080 /*
1077 * with multi-vif csa driver may call ieee80211_csa_finish() 1081 * with multi-vif csa driver may call ieee80211_csa_finish()
1078 * many times while waiting for other interfaces to use their 1082 * many times while waiting for other interfaces to use their
@@ -1081,6 +1085,48 @@ static void ieee80211_chswitch_work(struct work_struct *work)
1081 if (sdata->reserved_ready) 1085 if (sdata->reserved_ready)
1082 goto out; 1086 goto out;
1083 1087
1088 if (sdata->vif.bss_conf.chandef.width !=
1089 sdata->csa_chandef.width) {
1090 /*
1091 * For managed interface, we need to also update the AP
1092 * station bandwidth and align the rate scale algorithm
1093 * on the bandwidth change. Here we only consider the
1094 * bandwidth of the new channel definition (as channel
1095 * switch flow does not have the full HT/VHT/HE
1096 * information), assuming that if additional changes are
1097 * required they would be done as part of the processing
1098 * of the next beacon from the AP.
1099 */
1100 switch (sdata->csa_chandef.width) {
1101 case NL80211_CHAN_WIDTH_20_NOHT:
1102 case NL80211_CHAN_WIDTH_20:
1103 default:
1104 bw = IEEE80211_STA_RX_BW_20;
1105 break;
1106 case NL80211_CHAN_WIDTH_40:
1107 bw = IEEE80211_STA_RX_BW_40;
1108 break;
1109 case NL80211_CHAN_WIDTH_80:
1110 bw = IEEE80211_STA_RX_BW_80;
1111 break;
1112 case NL80211_CHAN_WIDTH_80P80:
1113 case NL80211_CHAN_WIDTH_160:
1114 bw = IEEE80211_STA_RX_BW_160;
1115 break;
1116 }
1117
1118 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1119 sband =
1120 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1121 }
1122
1123 if (sdata->vif.bss_conf.chandef.width >
1124 sdata->csa_chandef.width) {
1125 mgd_sta->sta.bandwidth = bw;
1126 rate_control_rate_update(local, sband, mgd_sta,
1127 IEEE80211_RC_BW_CHANGED);
1128 }
1129
1084 ret = ieee80211_vif_use_reserved_context(sdata); 1130 ret = ieee80211_vif_use_reserved_context(sdata);
1085 if (ret) { 1131 if (ret) {
1086 sdata_info(sdata, 1132 sdata_info(sdata,
@@ -1091,6 +1137,13 @@ static void ieee80211_chswitch_work(struct work_struct *work)
1091 goto out; 1137 goto out;
1092 } 1138 }
1093 1139
1140 if (sdata->vif.bss_conf.chandef.width <
1141 sdata->csa_chandef.width) {
1142 mgd_sta->sta.bandwidth = bw;
1143 rate_control_rate_update(local, sband, mgd_sta,
1144 IEEE80211_RC_BW_CHANGED);
1145 }
1146
1094 goto out; 1147 goto out;
1095 } 1148 }
1096 1149
@@ -1312,6 +1365,16 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1312 cbss->beacon_interval)); 1365 cbss->beacon_interval));
1313 return; 1366 return;
1314 drop_connection: 1367 drop_connection:
1368 /*
1369 * This is just so that the disconnect flow will know that
1370 * we were trying to switch channel and failed. In case the
1371 * mode is 1 (we are not allowed to Tx), we will know not to
1372 * send a deauthentication frame. Those two fields will be
1373 * reset when the disconnection worker runs.
1374 */
1375 sdata->vif.csa_active = true;
1376 sdata->csa_block_tx = csa_ie.mode;
1377
1315 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work); 1378 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1316 mutex_unlock(&local->chanctx_mtx); 1379 mutex_unlock(&local->chanctx_mtx);
1317 mutex_unlock(&local->mtx); 1380 mutex_unlock(&local->mtx);
@@ -2522,6 +2585,7 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2522 struct ieee80211_local *local = sdata->local; 2585 struct ieee80211_local *local = sdata->local;
2523 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2586 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2524 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 2587 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2588 bool tx;
2525 2589
2526 sdata_lock(sdata); 2590 sdata_lock(sdata);
2527 if (!ifmgd->associated) { 2591 if (!ifmgd->associated) {
@@ -2529,6 +2593,8 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2529 return; 2593 return;
2530 } 2594 }
2531 2595
2596 tx = !sdata->csa_block_tx;
2597
2532 /* AP is probably out of range (or not reachable for another reason) so 2598 /* AP is probably out of range (or not reachable for another reason) so
2533 * remove the bss struct for that AP. 2599 * remove the bss struct for that AP.
2534 */ 2600 */
@@ -2536,7 +2602,7 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2536 2602
2537 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 2603 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2538 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 2604 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2539 true, frame_buf); 2605 tx, frame_buf);
2540 mutex_lock(&local->mtx); 2606 mutex_lock(&local->mtx);
2541 sdata->vif.csa_active = false; 2607 sdata->vif.csa_active = false;
2542 ifmgd->csa_waiting_bcn = false; 2608 ifmgd->csa_waiting_bcn = false;
@@ -2547,7 +2613,7 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2547 } 2613 }
2548 mutex_unlock(&local->mtx); 2614 mutex_unlock(&local->mtx);
2549 2615
2550 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, 2616 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2551 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); 2617 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2552 2618
2553 sdata_unlock(sdata); 2619 sdata_unlock(sdata);
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 64742f2765c4..96611d5dfadb 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1728,6 +1728,7 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1728 */ 1728 */
1729 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) && 1729 if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1730 !ieee80211_has_morefrags(hdr->frame_control) && 1730 !ieee80211_has_morefrags(hdr->frame_control) &&
1731 !is_multicast_ether_addr(hdr->addr1) &&
1731 (ieee80211_is_mgmt(hdr->frame_control) || 1732 (ieee80211_is_mgmt(hdr->frame_control) ||
1732 ieee80211_is_data(hdr->frame_control)) && 1733 ieee80211_is_data(hdr->frame_control)) &&
1733 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) && 1734 !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index cd332e3e1134..f353d9db54bc 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -3078,27 +3078,18 @@ void ieee80211_clear_fast_xmit(struct sta_info *sta)
3078} 3078}
3079 3079
3080static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local, 3080static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local,
3081 struct sk_buff *skb, int headroom, 3081 struct sk_buff *skb, int headroom)
3082 int *subframe_len)
3083{ 3082{
3084 int amsdu_len = *subframe_len + sizeof(struct ethhdr); 3083 if (skb_headroom(skb) < headroom) {
3085 int padding = (4 - amsdu_len) & 3;
3086
3087 if (skb_headroom(skb) < headroom || skb_tailroom(skb) < padding) {
3088 I802_DEBUG_INC(local->tx_expand_skb_head); 3084 I802_DEBUG_INC(local->tx_expand_skb_head);
3089 3085
3090 if (pskb_expand_head(skb, headroom, padding, GFP_ATOMIC)) { 3086 if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
3091 wiphy_debug(local->hw.wiphy, 3087 wiphy_debug(local->hw.wiphy,
3092 "failed to reallocate TX buffer\n"); 3088 "failed to reallocate TX buffer\n");
3093 return false; 3089 return false;
3094 } 3090 }
3095 } 3091 }
3096 3092
3097 if (padding) {
3098 *subframe_len += padding;
3099 skb_put_zero(skb, padding);
3100 }
3101
3102 return true; 3093 return true;
3103} 3094}
3104 3095
@@ -3122,8 +3113,7 @@ static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
3122 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU) 3113 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
3123 return true; 3114 return true;
3124 3115
3125 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(*amsdu_hdr), 3116 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(*amsdu_hdr)))
3126 &subframe_len))
3127 return false; 3117 return false;
3128 3118
3129 data = skb_push(skb, sizeof(*amsdu_hdr)); 3119 data = skb_push(skb, sizeof(*amsdu_hdr));
@@ -3189,7 +3179,8 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3189 void *data; 3179 void *data;
3190 bool ret = false; 3180 bool ret = false;
3191 unsigned int orig_len; 3181 unsigned int orig_len;
3192 int n = 1, nfrags; 3182 int n = 2, nfrags, pad = 0;
3183 u16 hdrlen;
3193 3184
3194 if (!ieee80211_hw_check(&local->hw, TX_AMSDU)) 3185 if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
3195 return false; 3186 return false;
@@ -3222,9 +3213,6 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3222 if (skb->len + head->len > max_amsdu_len) 3213 if (skb->len + head->len > max_amsdu_len)
3223 goto out; 3214 goto out;
3224 3215
3225 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3226 goto out;
3227
3228 nfrags = 1 + skb_shinfo(skb)->nr_frags; 3216 nfrags = 1 + skb_shinfo(skb)->nr_frags;
3229 nfrags += 1 + skb_shinfo(head)->nr_frags; 3217 nfrags += 1 + skb_shinfo(head)->nr_frags;
3230 frag_tail = &skb_shinfo(head)->frag_list; 3218 frag_tail = &skb_shinfo(head)->frag_list;
@@ -3240,10 +3228,24 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3240 if (max_frags && nfrags > max_frags) 3228 if (max_frags && nfrags > max_frags)
3241 goto out; 3229 goto out;
3242 3230
3243 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) + 2, 3231 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3244 &subframe_len))
3245 goto out; 3232 goto out;
3246 3233
3234 /*
3235 * Pad out the previous subframe to a multiple of 4 by adding the
3236 * padding to the next one, that's being added. Note that head->len
3237 * is the length of the full A-MSDU, but that works since each time
3238 * we add a new subframe we pad out the previous one to a multiple
3239 * of 4 and thus it no longer matters in the next round.
3240 */
3241 hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header);
3242 if ((head->len - hdrlen) & 3)
3243 pad = 4 - ((head->len - hdrlen) & 3);
3244
3245 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
3246 2 + pad))
3247 goto out_recalc;
3248
3247 ret = true; 3249 ret = true;
3248 data = skb_push(skb, ETH_ALEN + 2); 3250 data = skb_push(skb, ETH_ALEN + 2);
3249 memmove(data, data + ETH_ALEN + 2, 2 * ETH_ALEN); 3251 memmove(data, data + ETH_ALEN + 2, 2 * ETH_ALEN);
@@ -3253,15 +3255,19 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3253 memcpy(data, &len, 2); 3255 memcpy(data, &len, 2);
3254 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header)); 3256 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header));
3255 3257
3258 memset(skb_push(skb, pad), 0, pad);
3259
3256 head->len += skb->len; 3260 head->len += skb->len;
3257 head->data_len += skb->len; 3261 head->data_len += skb->len;
3258 *frag_tail = skb; 3262 *frag_tail = skb;
3259 3263
3260 flow->backlog += head->len - orig_len; 3264out_recalc:
3261 tin->backlog_bytes += head->len - orig_len; 3265 if (head->len != orig_len) {
3262 3266 flow->backlog += head->len - orig_len;
3263 fq_recalc_backlog(fq, tin, flow); 3267 tin->backlog_bytes += head->len - orig_len;
3264 3268
3269 fq_recalc_backlog(fq, tin, flow);
3270 }
3265out: 3271out:
3266 spin_unlock_bh(&fq->lock); 3272 spin_unlock_bh(&fq->lock);
3267 3273
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 88efda7c9f8a..716cd6442d86 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -1135,7 +1135,7 @@ void ieee80211_regulatory_limit_wmm_params(struct ieee80211_sub_if_data *sdata,
1135{ 1135{
1136 struct ieee80211_chanctx_conf *chanctx_conf; 1136 struct ieee80211_chanctx_conf *chanctx_conf;
1137 const struct ieee80211_reg_rule *rrule; 1137 const struct ieee80211_reg_rule *rrule;
1138 struct ieee80211_wmm_ac *wmm_ac; 1138 const struct ieee80211_wmm_ac *wmm_ac;
1139 u16 center_freq = 0; 1139 u16 center_freq = 0;
1140 1140
1141 if (sdata->vif.type != NL80211_IFTYPE_AP && 1141 if (sdata->vif.type != NL80211_IFTYPE_AP &&
@@ -1154,20 +1154,19 @@ void ieee80211_regulatory_limit_wmm_params(struct ieee80211_sub_if_data *sdata,
1154 1154
1155 rrule = freq_reg_info(sdata->wdev.wiphy, MHZ_TO_KHZ(center_freq)); 1155 rrule = freq_reg_info(sdata->wdev.wiphy, MHZ_TO_KHZ(center_freq));
1156 1156
1157 if (IS_ERR_OR_NULL(rrule) || !rrule->wmm_rule) { 1157 if (IS_ERR_OR_NULL(rrule) || !rrule->has_wmm) {
1158 rcu_read_unlock(); 1158 rcu_read_unlock();
1159 return; 1159 return;
1160 } 1160 }
1161 1161
1162 if (sdata->vif.type == NL80211_IFTYPE_AP) 1162 if (sdata->vif.type == NL80211_IFTYPE_AP)
1163 wmm_ac = &rrule->wmm_rule->ap[ac]; 1163 wmm_ac = &rrule->wmm_rule.ap[ac];
1164 else 1164 else
1165 wmm_ac = &rrule->wmm_rule->client[ac]; 1165 wmm_ac = &rrule->wmm_rule.client[ac];
1166 qparam->cw_min = max_t(u16, qparam->cw_min, wmm_ac->cw_min); 1166 qparam->cw_min = max_t(u16, qparam->cw_min, wmm_ac->cw_min);
1167 qparam->cw_max = max_t(u16, qparam->cw_max, wmm_ac->cw_max); 1167 qparam->cw_max = max_t(u16, qparam->cw_max, wmm_ac->cw_max);
1168 qparam->aifs = max_t(u8, qparam->aifs, wmm_ac->aifsn); 1168 qparam->aifs = max_t(u8, qparam->aifs, wmm_ac->aifsn);
1169 qparam->txop = !qparam->txop ? wmm_ac->cot / 32 : 1169 qparam->txop = min_t(u16, qparam->txop, wmm_ac->cot / 32);
1170 min_t(u16, qparam->txop, wmm_ac->cot / 32);
1171 rcu_read_unlock(); 1170 rcu_read_unlock();
1172} 1171}
1173 1172
diff --git a/net/ncsi/ncsi-netlink.c b/net/ncsi/ncsi-netlink.c
index 82e6edf9c5d9..45f33d6dedf7 100644
--- a/net/ncsi/ncsi-netlink.c
+++ b/net/ncsi/ncsi-netlink.c
@@ -100,7 +100,7 @@ static int ncsi_write_package_info(struct sk_buff *skb,
100 bool found; 100 bool found;
101 int rc; 101 int rc;
102 102
103 if (id > ndp->package_num) { 103 if (id > ndp->package_num - 1) {
104 netdev_info(ndp->ndev.dev, "NCSI: No package with id %u\n", id); 104 netdev_info(ndp->ndev.dev, "NCSI: No package with id %u\n", id);
105 return -ENODEV; 105 return -ENODEV;
106 } 106 }
@@ -240,7 +240,7 @@ static int ncsi_pkg_info_all_nl(struct sk_buff *skb,
240 return 0; /* done */ 240 return 0; /* done */
241 241
242 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, 242 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
243 &ncsi_genl_family, 0, NCSI_CMD_PKG_INFO); 243 &ncsi_genl_family, NLM_F_MULTI, NCSI_CMD_PKG_INFO);
244 if (!hdr) { 244 if (!hdr) {
245 rc = -EMSGSIZE; 245 rc = -EMSGSIZE;
246 goto err; 246 goto err;
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 71709c104081..f61c306de1d0 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -771,13 +771,13 @@ config NETFILTER_XT_TARGET_CHECKSUM
771 depends on NETFILTER_ADVANCED 771 depends on NETFILTER_ADVANCED
772 ---help--- 772 ---help---
773 This option adds a `CHECKSUM' target, which can be used in the iptables mangle 773 This option adds a `CHECKSUM' target, which can be used in the iptables mangle
774 table. 774 table to work around buggy DHCP clients in virtualized environments.
775 775
776 You can use this target to compute and fill in the checksum in 776 Some old DHCP clients drop packets because they are not aware
777 a packet that lacks a checksum. This is particularly useful, 777 that the checksum would normally be offloaded to hardware and
778 if you need to work around old applications such as dhcp clients, 778 thus should be considered valid.
779 that do not work well with checksum offloads, but don't want to disable 779 This target can be used to fill in the checksum using iptables
780 checksum offload in your device. 780 when such packets are sent via a virtual network device.
781 781
782 To compile it as a module, choose M here. If unsure, say N. 782 To compile it as a module, choose M here. If unsure, say N.
783 783
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index 9f14b0df6960..51c5d7eec0a3 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -776,9 +776,26 @@ static const struct nf_hook_ops ipv6_conntrack_ops[] = {
776}; 776};
777#endif 777#endif
778 778
779static int nf_ct_tcp_fixup(struct nf_conn *ct, void *_nfproto)
780{
781 u8 nfproto = (unsigned long)_nfproto;
782
783 if (nf_ct_l3num(ct) != nfproto)
784 return 0;
785
786 if (nf_ct_protonum(ct) == IPPROTO_TCP &&
787 ct->proto.tcp.state == TCP_CONNTRACK_ESTABLISHED) {
788 ct->proto.tcp.seen[0].td_maxwin = 0;
789 ct->proto.tcp.seen[1].td_maxwin = 0;
790 }
791
792 return 0;
793}
794
779static int nf_ct_netns_do_get(struct net *net, u8 nfproto) 795static int nf_ct_netns_do_get(struct net *net, u8 nfproto)
780{ 796{
781 struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id); 797 struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id);
798 bool fixup_needed = false;
782 int err = 0; 799 int err = 0;
783 800
784 mutex_lock(&nf_ct_proto_mutex); 801 mutex_lock(&nf_ct_proto_mutex);
@@ -798,6 +815,8 @@ static int nf_ct_netns_do_get(struct net *net, u8 nfproto)
798 ARRAY_SIZE(ipv4_conntrack_ops)); 815 ARRAY_SIZE(ipv4_conntrack_ops));
799 if (err) 816 if (err)
800 cnet->users4 = 0; 817 cnet->users4 = 0;
818 else
819 fixup_needed = true;
801 break; 820 break;
802#if IS_ENABLED(CONFIG_IPV6) 821#if IS_ENABLED(CONFIG_IPV6)
803 case NFPROTO_IPV6: 822 case NFPROTO_IPV6:
@@ -814,6 +833,8 @@ static int nf_ct_netns_do_get(struct net *net, u8 nfproto)
814 ARRAY_SIZE(ipv6_conntrack_ops)); 833 ARRAY_SIZE(ipv6_conntrack_ops));
815 if (err) 834 if (err)
816 cnet->users6 = 0; 835 cnet->users6 = 0;
836 else
837 fixup_needed = true;
817 break; 838 break;
818#endif 839#endif
819 default: 840 default:
@@ -822,6 +843,11 @@ static int nf_ct_netns_do_get(struct net *net, u8 nfproto)
822 } 843 }
823 out_unlock: 844 out_unlock:
824 mutex_unlock(&nf_ct_proto_mutex); 845 mutex_unlock(&nf_ct_proto_mutex);
846
847 if (fixup_needed)
848 nf_ct_iterate_cleanup_net(net, nf_ct_tcp_fixup,
849 (void *)(unsigned long)nfproto, 0, 0);
850
825 return err; 851 return err;
826} 852}
827 853
diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
index 8c58f96b59e7..f3f91ed2c21a 100644
--- a/net/netfilter/nf_conntrack_proto_dccp.c
+++ b/net/netfilter/nf_conntrack_proto_dccp.c
@@ -675,7 +675,7 @@ static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
675} 675}
676#endif 676#endif
677 677
678#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 678#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
679 679
680#include <linux/netfilter/nfnetlink.h> 680#include <linux/netfilter/nfnetlink.h>
681#include <linux/netfilter/nfnetlink_cttimeout.h> 681#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -697,6 +697,8 @@ static int dccp_timeout_nlattr_to_obj(struct nlattr *tb[],
697 timeouts[i] = ntohl(nla_get_be32(tb[i])) * HZ; 697 timeouts[i] = ntohl(nla_get_be32(tb[i])) * HZ;
698 } 698 }
699 } 699 }
700
701 timeouts[CTA_TIMEOUT_DCCP_UNSPEC] = timeouts[CTA_TIMEOUT_DCCP_REQUEST];
700 return 0; 702 return 0;
701} 703}
702 704
@@ -726,7 +728,7 @@ dccp_timeout_nla_policy[CTA_TIMEOUT_DCCP_MAX+1] = {
726 [CTA_TIMEOUT_DCCP_CLOSING] = { .type = NLA_U32 }, 728 [CTA_TIMEOUT_DCCP_CLOSING] = { .type = NLA_U32 },
727 [CTA_TIMEOUT_DCCP_TIMEWAIT] = { .type = NLA_U32 }, 729 [CTA_TIMEOUT_DCCP_TIMEWAIT] = { .type = NLA_U32 },
728}; 730};
729#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 731#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
730 732
731#ifdef CONFIG_SYSCTL 733#ifdef CONFIG_SYSCTL
732/* template, data assigned later */ 734/* template, data assigned later */
@@ -827,6 +829,11 @@ static int dccp_init_net(struct net *net, u_int16_t proto)
827 dn->dccp_timeout[CT_DCCP_CLOSEREQ] = 64 * HZ; 829 dn->dccp_timeout[CT_DCCP_CLOSEREQ] = 64 * HZ;
828 dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ; 830 dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ;
829 dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL; 831 dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL;
832
833 /* timeouts[0] is unused, make it same as SYN_SENT so
834 * ->timeouts[0] contains 'new' timeout, like udp or icmp.
835 */
836 dn->dccp_timeout[CT_DCCP_NONE] = dn->dccp_timeout[CT_DCCP_REQUEST];
830 } 837 }
831 838
832 return dccp_kmemdup_sysctl_table(net, pn, dn); 839 return dccp_kmemdup_sysctl_table(net, pn, dn);
@@ -856,7 +863,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4 = {
856 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, 863 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
857 .nla_policy = nf_ct_port_nla_policy, 864 .nla_policy = nf_ct_port_nla_policy,
858#endif 865#endif
859#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 866#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
860 .ctnl_timeout = { 867 .ctnl_timeout = {
861 .nlattr_to_obj = dccp_timeout_nlattr_to_obj, 868 .nlattr_to_obj = dccp_timeout_nlattr_to_obj,
862 .obj_to_nlattr = dccp_timeout_obj_to_nlattr, 869 .obj_to_nlattr = dccp_timeout_obj_to_nlattr,
@@ -864,7 +871,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4 = {
864 .obj_size = sizeof(unsigned int) * CT_DCCP_MAX, 871 .obj_size = sizeof(unsigned int) * CT_DCCP_MAX,
865 .nla_policy = dccp_timeout_nla_policy, 872 .nla_policy = dccp_timeout_nla_policy,
866 }, 873 },
867#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 874#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
868 .init_net = dccp_init_net, 875 .init_net = dccp_init_net,
869 .get_net_proto = dccp_get_net_proto, 876 .get_net_proto = dccp_get_net_proto,
870}; 877};
@@ -889,7 +896,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6 = {
889 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, 896 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
890 .nla_policy = nf_ct_port_nla_policy, 897 .nla_policy = nf_ct_port_nla_policy,
891#endif 898#endif
892#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 899#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
893 .ctnl_timeout = { 900 .ctnl_timeout = {
894 .nlattr_to_obj = dccp_timeout_nlattr_to_obj, 901 .nlattr_to_obj = dccp_timeout_nlattr_to_obj,
895 .obj_to_nlattr = dccp_timeout_obj_to_nlattr, 902 .obj_to_nlattr = dccp_timeout_obj_to_nlattr,
@@ -897,7 +904,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6 = {
897 .obj_size = sizeof(unsigned int) * CT_DCCP_MAX, 904 .obj_size = sizeof(unsigned int) * CT_DCCP_MAX,
898 .nla_policy = dccp_timeout_nla_policy, 905 .nla_policy = dccp_timeout_nla_policy,
899 }, 906 },
900#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 907#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
901 .init_net = dccp_init_net, 908 .init_net = dccp_init_net,
902 .get_net_proto = dccp_get_net_proto, 909 .get_net_proto = dccp_get_net_proto,
903}; 910};
diff --git a/net/netfilter/nf_conntrack_proto_generic.c b/net/netfilter/nf_conntrack_proto_generic.c
index ac4a0b296dcd..1df3244ecd07 100644
--- a/net/netfilter/nf_conntrack_proto_generic.c
+++ b/net/netfilter/nf_conntrack_proto_generic.c
@@ -70,7 +70,7 @@ static bool generic_new(struct nf_conn *ct, const struct sk_buff *skb,
70 return ret; 70 return ret;
71} 71}
72 72
73#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 73#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
74 74
75#include <linux/netfilter/nfnetlink.h> 75#include <linux/netfilter/nfnetlink.h>
76#include <linux/netfilter/nfnetlink_cttimeout.h> 76#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -113,7 +113,7 @@ static const struct nla_policy
113generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = { 113generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = {
114 [CTA_TIMEOUT_GENERIC_TIMEOUT] = { .type = NLA_U32 }, 114 [CTA_TIMEOUT_GENERIC_TIMEOUT] = { .type = NLA_U32 },
115}; 115};
116#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 116#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
117 117
118#ifdef CONFIG_SYSCTL 118#ifdef CONFIG_SYSCTL
119static struct ctl_table generic_sysctl_table[] = { 119static struct ctl_table generic_sysctl_table[] = {
@@ -164,7 +164,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic =
164 .pkt_to_tuple = generic_pkt_to_tuple, 164 .pkt_to_tuple = generic_pkt_to_tuple,
165 .packet = generic_packet, 165 .packet = generic_packet,
166 .new = generic_new, 166 .new = generic_new,
167#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 167#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
168 .ctnl_timeout = { 168 .ctnl_timeout = {
169 .nlattr_to_obj = generic_timeout_nlattr_to_obj, 169 .nlattr_to_obj = generic_timeout_nlattr_to_obj,
170 .obj_to_nlattr = generic_timeout_obj_to_nlattr, 170 .obj_to_nlattr = generic_timeout_obj_to_nlattr,
@@ -172,7 +172,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic =
172 .obj_size = sizeof(unsigned int), 172 .obj_size = sizeof(unsigned int),
173 .nla_policy = generic_timeout_nla_policy, 173 .nla_policy = generic_timeout_nla_policy,
174 }, 174 },
175#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 175#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
176 .init_net = generic_init_net, 176 .init_net = generic_init_net,
177 .get_net_proto = generic_get_net_proto, 177 .get_net_proto = generic_get_net_proto,
178}; 178};
diff --git a/net/netfilter/nf_conntrack_proto_gre.c b/net/netfilter/nf_conntrack_proto_gre.c
index d1632252bf5b..650eb4fba2c5 100644
--- a/net/netfilter/nf_conntrack_proto_gre.c
+++ b/net/netfilter/nf_conntrack_proto_gre.c
@@ -285,7 +285,7 @@ static void gre_destroy(struct nf_conn *ct)
285 nf_ct_gre_keymap_destroy(master); 285 nf_ct_gre_keymap_destroy(master);
286} 286}
287 287
288#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 288#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
289 289
290#include <linux/netfilter/nfnetlink.h> 290#include <linux/netfilter/nfnetlink.h>
291#include <linux/netfilter/nfnetlink_cttimeout.h> 291#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -334,7 +334,7 @@ gre_timeout_nla_policy[CTA_TIMEOUT_GRE_MAX+1] = {
334 [CTA_TIMEOUT_GRE_UNREPLIED] = { .type = NLA_U32 }, 334 [CTA_TIMEOUT_GRE_UNREPLIED] = { .type = NLA_U32 },
335 [CTA_TIMEOUT_GRE_REPLIED] = { .type = NLA_U32 }, 335 [CTA_TIMEOUT_GRE_REPLIED] = { .type = NLA_U32 },
336}; 336};
337#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 337#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
338 338
339static int gre_init_net(struct net *net, u_int16_t proto) 339static int gre_init_net(struct net *net, u_int16_t proto)
340{ 340{
@@ -367,7 +367,7 @@ static const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 = {
367 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, 367 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
368 .nla_policy = nf_ct_port_nla_policy, 368 .nla_policy = nf_ct_port_nla_policy,
369#endif 369#endif
370#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 370#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
371 .ctnl_timeout = { 371 .ctnl_timeout = {
372 .nlattr_to_obj = gre_timeout_nlattr_to_obj, 372 .nlattr_to_obj = gre_timeout_nlattr_to_obj,
373 .obj_to_nlattr = gre_timeout_obj_to_nlattr, 373 .obj_to_nlattr = gre_timeout_obj_to_nlattr,
@@ -375,7 +375,7 @@ static const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 = {
375 .obj_size = sizeof(unsigned int) * GRE_CT_MAX, 375 .obj_size = sizeof(unsigned int) * GRE_CT_MAX,
376 .nla_policy = gre_timeout_nla_policy, 376 .nla_policy = gre_timeout_nla_policy,
377 }, 377 },
378#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 378#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
379 .net_id = &proto_gre_net_id, 379 .net_id = &proto_gre_net_id,
380 .init_net = gre_init_net, 380 .init_net = gre_init_net,
381}; 381};
diff --git a/net/netfilter/nf_conntrack_proto_icmp.c b/net/netfilter/nf_conntrack_proto_icmp.c
index 036670b38282..43c7e1a217b9 100644
--- a/net/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/netfilter/nf_conntrack_proto_icmp.c
@@ -273,7 +273,7 @@ static unsigned int icmp_nlattr_tuple_size(void)
273} 273}
274#endif 274#endif
275 275
276#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 276#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
277 277
278#include <linux/netfilter/nfnetlink.h> 278#include <linux/netfilter/nfnetlink.h>
279#include <linux/netfilter/nfnetlink_cttimeout.h> 279#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -313,7 +313,7 @@ static const struct nla_policy
313icmp_timeout_nla_policy[CTA_TIMEOUT_ICMP_MAX+1] = { 313icmp_timeout_nla_policy[CTA_TIMEOUT_ICMP_MAX+1] = {
314 [CTA_TIMEOUT_ICMP_TIMEOUT] = { .type = NLA_U32 }, 314 [CTA_TIMEOUT_ICMP_TIMEOUT] = { .type = NLA_U32 },
315}; 315};
316#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 316#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
317 317
318#ifdef CONFIG_SYSCTL 318#ifdef CONFIG_SYSCTL
319static struct ctl_table icmp_sysctl_table[] = { 319static struct ctl_table icmp_sysctl_table[] = {
@@ -374,7 +374,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp =
374 .nlattr_to_tuple = icmp_nlattr_to_tuple, 374 .nlattr_to_tuple = icmp_nlattr_to_tuple,
375 .nla_policy = icmp_nla_policy, 375 .nla_policy = icmp_nla_policy,
376#endif 376#endif
377#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 377#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
378 .ctnl_timeout = { 378 .ctnl_timeout = {
379 .nlattr_to_obj = icmp_timeout_nlattr_to_obj, 379 .nlattr_to_obj = icmp_timeout_nlattr_to_obj,
380 .obj_to_nlattr = icmp_timeout_obj_to_nlattr, 380 .obj_to_nlattr = icmp_timeout_obj_to_nlattr,
@@ -382,7 +382,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp =
382 .obj_size = sizeof(unsigned int), 382 .obj_size = sizeof(unsigned int),
383 .nla_policy = icmp_timeout_nla_policy, 383 .nla_policy = icmp_timeout_nla_policy,
384 }, 384 },
385#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 385#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
386 .init_net = icmp_init_net, 386 .init_net = icmp_init_net,
387 .get_net_proto = icmp_get_net_proto, 387 .get_net_proto = icmp_get_net_proto,
388}; 388};
diff --git a/net/netfilter/nf_conntrack_proto_icmpv6.c b/net/netfilter/nf_conntrack_proto_icmpv6.c
index bed07b998a10..97e40f77d678 100644
--- a/net/netfilter/nf_conntrack_proto_icmpv6.c
+++ b/net/netfilter/nf_conntrack_proto_icmpv6.c
@@ -274,7 +274,7 @@ static unsigned int icmpv6_nlattr_tuple_size(void)
274} 274}
275#endif 275#endif
276 276
277#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 277#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
278 278
279#include <linux/netfilter/nfnetlink.h> 279#include <linux/netfilter/nfnetlink.h>
280#include <linux/netfilter/nfnetlink_cttimeout.h> 280#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -314,7 +314,7 @@ static const struct nla_policy
314icmpv6_timeout_nla_policy[CTA_TIMEOUT_ICMPV6_MAX+1] = { 314icmpv6_timeout_nla_policy[CTA_TIMEOUT_ICMPV6_MAX+1] = {
315 [CTA_TIMEOUT_ICMPV6_TIMEOUT] = { .type = NLA_U32 }, 315 [CTA_TIMEOUT_ICMPV6_TIMEOUT] = { .type = NLA_U32 },
316}; 316};
317#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 317#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
318 318
319#ifdef CONFIG_SYSCTL 319#ifdef CONFIG_SYSCTL
320static struct ctl_table icmpv6_sysctl_table[] = { 320static struct ctl_table icmpv6_sysctl_table[] = {
@@ -373,7 +373,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
373 .nlattr_to_tuple = icmpv6_nlattr_to_tuple, 373 .nlattr_to_tuple = icmpv6_nlattr_to_tuple,
374 .nla_policy = icmpv6_nla_policy, 374 .nla_policy = icmpv6_nla_policy,
375#endif 375#endif
376#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 376#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
377 .ctnl_timeout = { 377 .ctnl_timeout = {
378 .nlattr_to_obj = icmpv6_timeout_nlattr_to_obj, 378 .nlattr_to_obj = icmpv6_timeout_nlattr_to_obj,
379 .obj_to_nlattr = icmpv6_timeout_obj_to_nlattr, 379 .obj_to_nlattr = icmpv6_timeout_obj_to_nlattr,
@@ -381,7 +381,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
381 .obj_size = sizeof(unsigned int), 381 .obj_size = sizeof(unsigned int),
382 .nla_policy = icmpv6_timeout_nla_policy, 382 .nla_policy = icmpv6_timeout_nla_policy,
383 }, 383 },
384#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 384#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
385 .init_net = icmpv6_init_net, 385 .init_net = icmpv6_init_net,
386 .get_net_proto = icmpv6_get_net_proto, 386 .get_net_proto = icmpv6_get_net_proto,
387}; 387};
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index 8d1e085fc14a..e4d738d34cd0 100644
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -591,7 +591,7 @@ static int nlattr_to_sctp(struct nlattr *cda[], struct nf_conn *ct)
591} 591}
592#endif 592#endif
593 593
594#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 594#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
595 595
596#include <linux/netfilter/nfnetlink.h> 596#include <linux/netfilter/nfnetlink.h>
597#include <linux/netfilter/nfnetlink_cttimeout.h> 597#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -613,6 +613,8 @@ static int sctp_timeout_nlattr_to_obj(struct nlattr *tb[],
613 timeouts[i] = ntohl(nla_get_be32(tb[i])) * HZ; 613 timeouts[i] = ntohl(nla_get_be32(tb[i])) * HZ;
614 } 614 }
615 } 615 }
616
617 timeouts[CTA_TIMEOUT_SCTP_UNSPEC] = timeouts[CTA_TIMEOUT_SCTP_CLOSED];
616 return 0; 618 return 0;
617} 619}
618 620
@@ -644,7 +646,7 @@ sctp_timeout_nla_policy[CTA_TIMEOUT_SCTP_MAX+1] = {
644 [CTA_TIMEOUT_SCTP_HEARTBEAT_SENT] = { .type = NLA_U32 }, 646 [CTA_TIMEOUT_SCTP_HEARTBEAT_SENT] = { .type = NLA_U32 },
645 [CTA_TIMEOUT_SCTP_HEARTBEAT_ACKED] = { .type = NLA_U32 }, 647 [CTA_TIMEOUT_SCTP_HEARTBEAT_ACKED] = { .type = NLA_U32 },
646}; 648};
647#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 649#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
648 650
649 651
650#ifdef CONFIG_SYSCTL 652#ifdef CONFIG_SYSCTL
@@ -743,6 +745,11 @@ static int sctp_init_net(struct net *net, u_int16_t proto)
743 745
744 for (i = 0; i < SCTP_CONNTRACK_MAX; i++) 746 for (i = 0; i < SCTP_CONNTRACK_MAX; i++)
745 sn->timeouts[i] = sctp_timeouts[i]; 747 sn->timeouts[i] = sctp_timeouts[i];
748
749 /* timeouts[0] is unused, init it so ->timeouts[0] contains
750 * 'new' timeout, like udp or icmp.
751 */
752 sn->timeouts[0] = sctp_timeouts[SCTP_CONNTRACK_CLOSED];
746 } 753 }
747 754
748 return sctp_kmemdup_sysctl_table(pn, sn); 755 return sctp_kmemdup_sysctl_table(pn, sn);
@@ -773,7 +780,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 = {
773 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, 780 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
774 .nla_policy = nf_ct_port_nla_policy, 781 .nla_policy = nf_ct_port_nla_policy,
775#endif 782#endif
776#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 783#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
777 .ctnl_timeout = { 784 .ctnl_timeout = {
778 .nlattr_to_obj = sctp_timeout_nlattr_to_obj, 785 .nlattr_to_obj = sctp_timeout_nlattr_to_obj,
779 .obj_to_nlattr = sctp_timeout_obj_to_nlattr, 786 .obj_to_nlattr = sctp_timeout_obj_to_nlattr,
@@ -781,7 +788,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 = {
781 .obj_size = sizeof(unsigned int) * SCTP_CONNTRACK_MAX, 788 .obj_size = sizeof(unsigned int) * SCTP_CONNTRACK_MAX,
782 .nla_policy = sctp_timeout_nla_policy, 789 .nla_policy = sctp_timeout_nla_policy,
783 }, 790 },
784#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 791#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
785 .init_net = sctp_init_net, 792 .init_net = sctp_init_net,
786 .get_net_proto = sctp_get_net_proto, 793 .get_net_proto = sctp_get_net_proto,
787}; 794};
@@ -806,7 +813,8 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 = {
806 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, 813 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
807 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple, 814 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
808 .nla_policy = nf_ct_port_nla_policy, 815 .nla_policy = nf_ct_port_nla_policy,
809#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 816#endif
817#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
810 .ctnl_timeout = { 818 .ctnl_timeout = {
811 .nlattr_to_obj = sctp_timeout_nlattr_to_obj, 819 .nlattr_to_obj = sctp_timeout_nlattr_to_obj,
812 .obj_to_nlattr = sctp_timeout_obj_to_nlattr, 820 .obj_to_nlattr = sctp_timeout_obj_to_nlattr,
@@ -814,8 +822,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 = {
814 .obj_size = sizeof(unsigned int) * SCTP_CONNTRACK_MAX, 822 .obj_size = sizeof(unsigned int) * SCTP_CONNTRACK_MAX,
815 .nla_policy = sctp_timeout_nla_policy, 823 .nla_policy = sctp_timeout_nla_policy,
816 }, 824 },
817#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 825#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
818#endif
819 .init_net = sctp_init_net, 826 .init_net = sctp_init_net,
820 .get_net_proto = sctp_get_net_proto, 827 .get_net_proto = sctp_get_net_proto,
821}; 828};
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index d80d322b9d8b..b4bdf9eda7b7 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -1279,7 +1279,7 @@ static unsigned int tcp_nlattr_tuple_size(void)
1279} 1279}
1280#endif 1280#endif
1281 1281
1282#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 1282#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1283 1283
1284#include <linux/netfilter/nfnetlink.h> 1284#include <linux/netfilter/nfnetlink.h>
1285#include <linux/netfilter/nfnetlink_cttimeout.h> 1285#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -1301,6 +1301,7 @@ static int tcp_timeout_nlattr_to_obj(struct nlattr *tb[],
1301 timeouts[TCP_CONNTRACK_SYN_SENT] = 1301 timeouts[TCP_CONNTRACK_SYN_SENT] =
1302 ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_SYN_SENT]))*HZ; 1302 ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_SYN_SENT]))*HZ;
1303 } 1303 }
1304
1304 if (tb[CTA_TIMEOUT_TCP_SYN_RECV]) { 1305 if (tb[CTA_TIMEOUT_TCP_SYN_RECV]) {
1305 timeouts[TCP_CONNTRACK_SYN_RECV] = 1306 timeouts[TCP_CONNTRACK_SYN_RECV] =
1306 ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_SYN_RECV]))*HZ; 1307 ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_SYN_RECV]))*HZ;
@@ -1341,6 +1342,8 @@ static int tcp_timeout_nlattr_to_obj(struct nlattr *tb[],
1341 timeouts[TCP_CONNTRACK_UNACK] = 1342 timeouts[TCP_CONNTRACK_UNACK] =
1342 ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_UNACK]))*HZ; 1343 ntohl(nla_get_be32(tb[CTA_TIMEOUT_TCP_UNACK]))*HZ;
1343 } 1344 }
1345
1346 timeouts[CTA_TIMEOUT_TCP_UNSPEC] = timeouts[CTA_TIMEOUT_TCP_SYN_SENT];
1344 return 0; 1347 return 0;
1345} 1348}
1346 1349
@@ -1391,7 +1394,7 @@ static const struct nla_policy tcp_timeout_nla_policy[CTA_TIMEOUT_TCP_MAX+1] = {
1391 [CTA_TIMEOUT_TCP_RETRANS] = { .type = NLA_U32 }, 1394 [CTA_TIMEOUT_TCP_RETRANS] = { .type = NLA_U32 },
1392 [CTA_TIMEOUT_TCP_UNACK] = { .type = NLA_U32 }, 1395 [CTA_TIMEOUT_TCP_UNACK] = { .type = NLA_U32 },
1393}; 1396};
1394#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 1397#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
1395 1398
1396#ifdef CONFIG_SYSCTL 1399#ifdef CONFIG_SYSCTL
1397static struct ctl_table tcp_sysctl_table[] = { 1400static struct ctl_table tcp_sysctl_table[] = {
@@ -1518,6 +1521,10 @@ static int tcp_init_net(struct net *net, u_int16_t proto)
1518 for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++) 1521 for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++)
1519 tn->timeouts[i] = tcp_timeouts[i]; 1522 tn->timeouts[i] = tcp_timeouts[i];
1520 1523
1524 /* timeouts[0] is unused, make it same as SYN_SENT so
1525 * ->timeouts[0] contains 'new' timeout, like udp or icmp.
1526 */
1527 tn->timeouts[0] = tcp_timeouts[TCP_CONNTRACK_SYN_SENT];
1521 tn->tcp_loose = nf_ct_tcp_loose; 1528 tn->tcp_loose = nf_ct_tcp_loose;
1522 tn->tcp_be_liberal = nf_ct_tcp_be_liberal; 1529 tn->tcp_be_liberal = nf_ct_tcp_be_liberal;
1523 tn->tcp_max_retrans = nf_ct_tcp_max_retrans; 1530 tn->tcp_max_retrans = nf_ct_tcp_max_retrans;
@@ -1551,7 +1558,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 =
1551 .nlattr_size = TCP_NLATTR_SIZE, 1558 .nlattr_size = TCP_NLATTR_SIZE,
1552 .nla_policy = nf_ct_port_nla_policy, 1559 .nla_policy = nf_ct_port_nla_policy,
1553#endif 1560#endif
1554#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 1561#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1555 .ctnl_timeout = { 1562 .ctnl_timeout = {
1556 .nlattr_to_obj = tcp_timeout_nlattr_to_obj, 1563 .nlattr_to_obj = tcp_timeout_nlattr_to_obj,
1557 .obj_to_nlattr = tcp_timeout_obj_to_nlattr, 1564 .obj_to_nlattr = tcp_timeout_obj_to_nlattr,
@@ -1560,7 +1567,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 =
1560 TCP_CONNTRACK_TIMEOUT_MAX, 1567 TCP_CONNTRACK_TIMEOUT_MAX,
1561 .nla_policy = tcp_timeout_nla_policy, 1568 .nla_policy = tcp_timeout_nla_policy,
1562 }, 1569 },
1563#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 1570#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
1564 .init_net = tcp_init_net, 1571 .init_net = tcp_init_net,
1565 .get_net_proto = tcp_get_net_proto, 1572 .get_net_proto = tcp_get_net_proto,
1566}; 1573};
@@ -1586,7 +1593,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 =
1586 .nlattr_tuple_size = tcp_nlattr_tuple_size, 1593 .nlattr_tuple_size = tcp_nlattr_tuple_size,
1587 .nla_policy = nf_ct_port_nla_policy, 1594 .nla_policy = nf_ct_port_nla_policy,
1588#endif 1595#endif
1589#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 1596#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1590 .ctnl_timeout = { 1597 .ctnl_timeout = {
1591 .nlattr_to_obj = tcp_timeout_nlattr_to_obj, 1598 .nlattr_to_obj = tcp_timeout_nlattr_to_obj,
1592 .obj_to_nlattr = tcp_timeout_obj_to_nlattr, 1599 .obj_to_nlattr = tcp_timeout_obj_to_nlattr,
@@ -1595,7 +1602,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 =
1595 TCP_CONNTRACK_TIMEOUT_MAX, 1602 TCP_CONNTRACK_TIMEOUT_MAX,
1596 .nla_policy = tcp_timeout_nla_policy, 1603 .nla_policy = tcp_timeout_nla_policy,
1597 }, 1604 },
1598#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 1605#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
1599 .init_net = tcp_init_net, 1606 .init_net = tcp_init_net,
1600 .get_net_proto = tcp_get_net_proto, 1607 .get_net_proto = tcp_get_net_proto,
1601}; 1608};
diff --git a/net/netfilter/nf_conntrack_proto_udp.c b/net/netfilter/nf_conntrack_proto_udp.c
index 7a1b8988a931..3065fb8ef91b 100644
--- a/net/netfilter/nf_conntrack_proto_udp.c
+++ b/net/netfilter/nf_conntrack_proto_udp.c
@@ -171,7 +171,7 @@ static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
171 return NF_ACCEPT; 171 return NF_ACCEPT;
172} 172}
173 173
174#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 174#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
175 175
176#include <linux/netfilter/nfnetlink.h> 176#include <linux/netfilter/nfnetlink.h>
177#include <linux/netfilter/nfnetlink_cttimeout.h> 177#include <linux/netfilter/nfnetlink_cttimeout.h>
@@ -221,7 +221,7 @@ udp_timeout_nla_policy[CTA_TIMEOUT_UDP_MAX+1] = {
221 [CTA_TIMEOUT_UDP_UNREPLIED] = { .type = NLA_U32 }, 221 [CTA_TIMEOUT_UDP_UNREPLIED] = { .type = NLA_U32 },
222 [CTA_TIMEOUT_UDP_REPLIED] = { .type = NLA_U32 }, 222 [CTA_TIMEOUT_UDP_REPLIED] = { .type = NLA_U32 },
223}; 223};
224#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 224#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
225 225
226#ifdef CONFIG_SYSCTL 226#ifdef CONFIG_SYSCTL
227static struct ctl_table udp_sysctl_table[] = { 227static struct ctl_table udp_sysctl_table[] = {
@@ -292,7 +292,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 =
292 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, 292 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
293 .nla_policy = nf_ct_port_nla_policy, 293 .nla_policy = nf_ct_port_nla_policy,
294#endif 294#endif
295#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 295#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
296 .ctnl_timeout = { 296 .ctnl_timeout = {
297 .nlattr_to_obj = udp_timeout_nlattr_to_obj, 297 .nlattr_to_obj = udp_timeout_nlattr_to_obj,
298 .obj_to_nlattr = udp_timeout_obj_to_nlattr, 298 .obj_to_nlattr = udp_timeout_obj_to_nlattr,
@@ -300,7 +300,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 =
300 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX, 300 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
301 .nla_policy = udp_timeout_nla_policy, 301 .nla_policy = udp_timeout_nla_policy,
302 }, 302 },
303#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 303#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
304 .init_net = udp_init_net, 304 .init_net = udp_init_net,
305 .get_net_proto = udp_get_net_proto, 305 .get_net_proto = udp_get_net_proto,
306}; 306};
@@ -321,7 +321,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 =
321 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, 321 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
322 .nla_policy = nf_ct_port_nla_policy, 322 .nla_policy = nf_ct_port_nla_policy,
323#endif 323#endif
324#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 324#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
325 .ctnl_timeout = { 325 .ctnl_timeout = {
326 .nlattr_to_obj = udp_timeout_nlattr_to_obj, 326 .nlattr_to_obj = udp_timeout_nlattr_to_obj,
327 .obj_to_nlattr = udp_timeout_obj_to_nlattr, 327 .obj_to_nlattr = udp_timeout_obj_to_nlattr,
@@ -329,7 +329,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 =
329 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX, 329 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
330 .nla_policy = udp_timeout_nla_policy, 330 .nla_policy = udp_timeout_nla_policy,
331 }, 331 },
332#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 332#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
333 .init_net = udp_init_net, 333 .init_net = udp_init_net,
334 .get_net_proto = udp_get_net_proto, 334 .get_net_proto = udp_get_net_proto,
335}; 335};
@@ -350,7 +350,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 =
350 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, 350 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
351 .nla_policy = nf_ct_port_nla_policy, 351 .nla_policy = nf_ct_port_nla_policy,
352#endif 352#endif
353#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 353#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
354 .ctnl_timeout = { 354 .ctnl_timeout = {
355 .nlattr_to_obj = udp_timeout_nlattr_to_obj, 355 .nlattr_to_obj = udp_timeout_nlattr_to_obj,
356 .obj_to_nlattr = udp_timeout_obj_to_nlattr, 356 .obj_to_nlattr = udp_timeout_obj_to_nlattr,
@@ -358,7 +358,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 =
358 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX, 358 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
359 .nla_policy = udp_timeout_nla_policy, 359 .nla_policy = udp_timeout_nla_policy,
360 }, 360 },
361#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 361#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
362 .init_net = udp_init_net, 362 .init_net = udp_init_net,
363 .get_net_proto = udp_get_net_proto, 363 .get_net_proto = udp_get_net_proto,
364}; 364};
@@ -379,7 +379,7 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 =
379 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size, 379 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
380 .nla_policy = nf_ct_port_nla_policy, 380 .nla_policy = nf_ct_port_nla_policy,
381#endif 381#endif
382#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) 382#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
383 .ctnl_timeout = { 383 .ctnl_timeout = {
384 .nlattr_to_obj = udp_timeout_nlattr_to_obj, 384 .nlattr_to_obj = udp_timeout_nlattr_to_obj,
385 .obj_to_nlattr = udp_timeout_obj_to_nlattr, 385 .obj_to_nlattr = udp_timeout_obj_to_nlattr,
@@ -387,10 +387,9 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 =
387 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX, 387 .obj_size = sizeof(unsigned int) * CTA_TIMEOUT_UDP_MAX,
388 .nla_policy = udp_timeout_nla_policy, 388 .nla_policy = udp_timeout_nla_policy,
389 }, 389 },
390#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 390#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
391 .init_net = udp_init_net, 391 .init_net = udp_init_net,
392 .get_net_proto = udp_get_net_proto, 392 .get_net_proto = udp_get_net_proto,
393}; 393};
394EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udplite6); 394EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udplite6);
395#endif 395#endif
396#include <net/netfilter/nf_conntrack_timeout.h>
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 1dca5683f59f..2cfb173cd0b2 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -4637,6 +4637,7 @@ static int nft_flush_set(const struct nft_ctx *ctx,
4637 } 4637 }
4638 set->ndeact++; 4638 set->ndeact++;
4639 4639
4640 nft_set_elem_deactivate(ctx->net, set, elem);
4640 nft_trans_elem_set(trans) = set; 4641 nft_trans_elem_set(trans) = set;
4641 nft_trans_elem(trans) = *elem; 4642 nft_trans_elem(trans) = *elem;
4642 list_add_tail(&trans->list, &ctx->net->nft.commit_list); 4643 list_add_tail(&trans->list, &ctx->net->nft.commit_list);
diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c
index d46a236cdf31..a30f8ba4b89a 100644
--- a/net/netfilter/nfnetlink_cttimeout.c
+++ b/net/netfilter/nfnetlink_cttimeout.c
@@ -489,8 +489,8 @@ err:
489 return err; 489 return err;
490} 490}
491 491
492static struct ctnl_timeout * 492static struct nf_ct_timeout *ctnl_timeout_find_get(struct net *net,
493ctnl_timeout_find_get(struct net *net, const char *name) 493 const char *name)
494{ 494{
495 struct ctnl_timeout *timeout, *matching = NULL; 495 struct ctnl_timeout *timeout, *matching = NULL;
496 496
@@ -509,7 +509,7 @@ ctnl_timeout_find_get(struct net *net, const char *name)
509 break; 509 break;
510 } 510 }
511err: 511err:
512 return matching; 512 return matching ? &matching->timeout : NULL;
513} 513}
514 514
515static void ctnl_timeout_put(struct nf_ct_timeout *t) 515static void ctnl_timeout_put(struct nf_ct_timeout *t)
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index ea4ba551abb2..d33094f4ec41 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -233,6 +233,7 @@ static void nfqnl_reinject(struct nf_queue_entry *entry, unsigned int verdict)
233 int err; 233 int err;
234 234
235 if (verdict == NF_ACCEPT || 235 if (verdict == NF_ACCEPT ||
236 verdict == NF_REPEAT ||
236 verdict == NF_STOP) { 237 verdict == NF_STOP) {
237 rcu_read_lock(); 238 rcu_read_lock();
238 ct_hook = rcu_dereference(nf_ct_hook); 239 ct_hook = rcu_dereference(nf_ct_hook);
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index 26a8baebd072..5dd87748afa8 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -799,7 +799,7 @@ err:
799} 799}
800 800
801struct nft_ct_timeout_obj { 801struct nft_ct_timeout_obj {
802 struct nf_conn *tmpl; 802 struct nf_ct_timeout *timeout;
803 u8 l4proto; 803 u8 l4proto;
804}; 804};
805 805
@@ -809,26 +809,42 @@ static void nft_ct_timeout_obj_eval(struct nft_object *obj,
809{ 809{
810 const struct nft_ct_timeout_obj *priv = nft_obj_data(obj); 810 const struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
811 struct nf_conn *ct = (struct nf_conn *)skb_nfct(pkt->skb); 811 struct nf_conn *ct = (struct nf_conn *)skb_nfct(pkt->skb);
812 struct sk_buff *skb = pkt->skb; 812 struct nf_conn_timeout *timeout;
813 const unsigned int *values;
814
815 if (priv->l4proto != pkt->tprot)
816 return;
813 817
814 if (ct || 818 if (!ct || nf_ct_is_template(ct) || nf_ct_is_confirmed(ct))
815 priv->l4proto != pkt->tprot)
816 return; 819 return;
817 820
818 nf_ct_set(skb, priv->tmpl, IP_CT_NEW); 821 timeout = nf_ct_timeout_find(ct);
822 if (!timeout) {
823 timeout = nf_ct_timeout_ext_add(ct, priv->timeout, GFP_ATOMIC);
824 if (!timeout) {
825 regs->verdict.code = NF_DROP;
826 return;
827 }
828 }
829
830 rcu_assign_pointer(timeout->timeout, priv->timeout);
831
832 /* adjust the timeout as per 'new' state. ct is unconfirmed,
833 * so the current timestamp must not be added.
834 */
835 values = nf_ct_timeout_data(timeout);
836 if (values)
837 nf_ct_refresh(ct, pkt->skb, values[0]);
819} 838}
820 839
821static int nft_ct_timeout_obj_init(const struct nft_ctx *ctx, 840static int nft_ct_timeout_obj_init(const struct nft_ctx *ctx,
822 const struct nlattr * const tb[], 841 const struct nlattr * const tb[],
823 struct nft_object *obj) 842 struct nft_object *obj)
824{ 843{
825 const struct nf_conntrack_zone *zone = &nf_ct_zone_dflt;
826 struct nft_ct_timeout_obj *priv = nft_obj_data(obj); 844 struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
827 const struct nf_conntrack_l4proto *l4proto; 845 const struct nf_conntrack_l4proto *l4proto;
828 struct nf_conn_timeout *timeout_ext;
829 struct nf_ct_timeout *timeout; 846 struct nf_ct_timeout *timeout;
830 int l3num = ctx->family; 847 int l3num = ctx->family;
831 struct nf_conn *tmpl;
832 __u8 l4num; 848 __u8 l4num;
833 int ret; 849 int ret;
834 850
@@ -863,28 +879,14 @@ static int nft_ct_timeout_obj_init(const struct nft_ctx *ctx,
863 879
864 timeout->l3num = l3num; 880 timeout->l3num = l3num;
865 timeout->l4proto = l4proto; 881 timeout->l4proto = l4proto;
866 tmpl = nf_ct_tmpl_alloc(ctx->net, zone, GFP_ATOMIC);
867 if (!tmpl) {
868 ret = -ENOMEM;
869 goto err_free_timeout;
870 }
871
872 timeout_ext = nf_ct_timeout_ext_add(tmpl, timeout, GFP_ATOMIC);
873 if (!timeout_ext) {
874 ret = -ENOMEM;
875 goto err_free_tmpl;
876 }
877 882
878 ret = nf_ct_netns_get(ctx->net, ctx->family); 883 ret = nf_ct_netns_get(ctx->net, ctx->family);
879 if (ret < 0) 884 if (ret < 0)
880 goto err_free_tmpl; 885 goto err_free_timeout;
881
882 priv->tmpl = tmpl;
883 886
887 priv->timeout = timeout;
884 return 0; 888 return 0;
885 889
886err_free_tmpl:
887 nf_ct_tmpl_free(tmpl);
888err_free_timeout: 890err_free_timeout:
889 kfree(timeout); 891 kfree(timeout);
890err_proto_put: 892err_proto_put:
@@ -896,22 +898,19 @@ static void nft_ct_timeout_obj_destroy(const struct nft_ctx *ctx,
896 struct nft_object *obj) 898 struct nft_object *obj)
897{ 899{
898 struct nft_ct_timeout_obj *priv = nft_obj_data(obj); 900 struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
899 struct nf_conn_timeout *t = nf_ct_timeout_find(priv->tmpl); 901 struct nf_ct_timeout *timeout = priv->timeout;
900 struct nf_ct_timeout *timeout;
901 902
902 timeout = rcu_dereference_raw(t->timeout);
903 nf_ct_untimeout(ctx->net, timeout); 903 nf_ct_untimeout(ctx->net, timeout);
904 nf_ct_l4proto_put(timeout->l4proto); 904 nf_ct_l4proto_put(timeout->l4proto);
905 nf_ct_netns_put(ctx->net, ctx->family); 905 nf_ct_netns_put(ctx->net, ctx->family);
906 nf_ct_tmpl_free(priv->tmpl); 906 kfree(priv->timeout);
907} 907}
908 908
909static int nft_ct_timeout_obj_dump(struct sk_buff *skb, 909static int nft_ct_timeout_obj_dump(struct sk_buff *skb,
910 struct nft_object *obj, bool reset) 910 struct nft_object *obj, bool reset)
911{ 911{
912 const struct nft_ct_timeout_obj *priv = nft_obj_data(obj); 912 const struct nft_ct_timeout_obj *priv = nft_obj_data(obj);
913 const struct nf_conn_timeout *t = nf_ct_timeout_find(priv->tmpl); 913 const struct nf_ct_timeout *timeout = priv->timeout;
914 const struct nf_ct_timeout *timeout = rcu_dereference_raw(t->timeout);
915 struct nlattr *nest_params; 914 struct nlattr *nest_params;
916 int ret; 915 int ret;
917 916
diff --git a/net/netfilter/xt_CHECKSUM.c b/net/netfilter/xt_CHECKSUM.c
index 9f4151ec3e06..6c7aa6a0a0d2 100644
--- a/net/netfilter/xt_CHECKSUM.c
+++ b/net/netfilter/xt_CHECKSUM.c
@@ -16,6 +16,9 @@
16#include <linux/netfilter/x_tables.h> 16#include <linux/netfilter/x_tables.h>
17#include <linux/netfilter/xt_CHECKSUM.h> 17#include <linux/netfilter/xt_CHECKSUM.h>
18 18
19#include <linux/netfilter_ipv4/ip_tables.h>
20#include <linux/netfilter_ipv6/ip6_tables.h>
21
19MODULE_LICENSE("GPL"); 22MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Michael S. Tsirkin <mst@redhat.com>"); 23MODULE_AUTHOR("Michael S. Tsirkin <mst@redhat.com>");
21MODULE_DESCRIPTION("Xtables: checksum modification"); 24MODULE_DESCRIPTION("Xtables: checksum modification");
@@ -25,7 +28,7 @@ MODULE_ALIAS("ip6t_CHECKSUM");
25static unsigned int 28static unsigned int
26checksum_tg(struct sk_buff *skb, const struct xt_action_param *par) 29checksum_tg(struct sk_buff *skb, const struct xt_action_param *par)
27{ 30{
28 if (skb->ip_summed == CHECKSUM_PARTIAL) 31 if (skb->ip_summed == CHECKSUM_PARTIAL && !skb_is_gso(skb))
29 skb_checksum_help(skb); 32 skb_checksum_help(skb);
30 33
31 return XT_CONTINUE; 34 return XT_CONTINUE;
@@ -34,6 +37,8 @@ checksum_tg(struct sk_buff *skb, const struct xt_action_param *par)
34static int checksum_tg_check(const struct xt_tgchk_param *par) 37static int checksum_tg_check(const struct xt_tgchk_param *par)
35{ 38{
36 const struct xt_CHECKSUM_info *einfo = par->targinfo; 39 const struct xt_CHECKSUM_info *einfo = par->targinfo;
40 const struct ip6t_ip6 *i6 = par->entryinfo;
41 const struct ipt_ip *i4 = par->entryinfo;
37 42
38 if (einfo->operation & ~XT_CHECKSUM_OP_FILL) { 43 if (einfo->operation & ~XT_CHECKSUM_OP_FILL) {
39 pr_info_ratelimited("unsupported CHECKSUM operation %x\n", 44 pr_info_ratelimited("unsupported CHECKSUM operation %x\n",
@@ -43,6 +48,21 @@ static int checksum_tg_check(const struct xt_tgchk_param *par)
43 if (!einfo->operation) 48 if (!einfo->operation)
44 return -EINVAL; 49 return -EINVAL;
45 50
51 switch (par->family) {
52 case NFPROTO_IPV4:
53 if (i4->proto == IPPROTO_UDP &&
54 (i4->invflags & XT_INV_PROTO) == 0)
55 return 0;
56 break;
57 case NFPROTO_IPV6:
58 if ((i6->flags & IP6T_F_PROTO) &&
59 i6->proto == IPPROTO_UDP &&
60 (i6->invflags & XT_INV_PROTO) == 0)
61 return 0;
62 break;
63 }
64
65 pr_warn_once("CHECKSUM should be avoided. If really needed, restrict with \"-p udp\" and only use in OUTPUT\n");
46 return 0; 66 return 0;
47} 67}
48 68
diff --git a/net/netfilter/xt_cluster.c b/net/netfilter/xt_cluster.c
index dfbdbb2fc0ed..51d0c257e7a5 100644
--- a/net/netfilter/xt_cluster.c
+++ b/net/netfilter/xt_cluster.c
@@ -125,6 +125,7 @@ xt_cluster_mt(const struct sk_buff *skb, struct xt_action_param *par)
125static int xt_cluster_mt_checkentry(const struct xt_mtchk_param *par) 125static int xt_cluster_mt_checkentry(const struct xt_mtchk_param *par)
126{ 126{
127 struct xt_cluster_match_info *info = par->matchinfo; 127 struct xt_cluster_match_info *info = par->matchinfo;
128 int ret;
128 129
129 if (info->total_nodes > XT_CLUSTER_NODES_MAX) { 130 if (info->total_nodes > XT_CLUSTER_NODES_MAX) {
130 pr_info_ratelimited("you have exceeded the maximum number of cluster nodes (%u > %u)\n", 131 pr_info_ratelimited("you have exceeded the maximum number of cluster nodes (%u > %u)\n",
@@ -135,7 +136,17 @@ static int xt_cluster_mt_checkentry(const struct xt_mtchk_param *par)
135 pr_info_ratelimited("node mask cannot exceed total number of nodes\n"); 136 pr_info_ratelimited("node mask cannot exceed total number of nodes\n");
136 return -EDOM; 137 return -EDOM;
137 } 138 }
138 return 0; 139
140 ret = nf_ct_netns_get(par->net, par->family);
141 if (ret < 0)
142 pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
143 par->family);
144 return ret;
145}
146
147static void xt_cluster_mt_destroy(const struct xt_mtdtor_param *par)
148{
149 nf_ct_netns_put(par->net, par->family);
139} 150}
140 151
141static struct xt_match xt_cluster_match __read_mostly = { 152static struct xt_match xt_cluster_match __read_mostly = {
@@ -144,6 +155,7 @@ static struct xt_match xt_cluster_match __read_mostly = {
144 .match = xt_cluster_mt, 155 .match = xt_cluster_mt,
145 .checkentry = xt_cluster_mt_checkentry, 156 .checkentry = xt_cluster_mt_checkentry,
146 .matchsize = sizeof(struct xt_cluster_match_info), 157 .matchsize = sizeof(struct xt_cluster_match_info),
158 .destroy = xt_cluster_mt_destroy,
147 .me = THIS_MODULE, 159 .me = THIS_MODULE,
148}; 160};
149 161
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 9b16402f29af..3e7d259e5d8d 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -1057,7 +1057,7 @@ static struct xt_match hashlimit_mt_reg[] __read_mostly = {
1057static void *dl_seq_start(struct seq_file *s, loff_t *pos) 1057static void *dl_seq_start(struct seq_file *s, loff_t *pos)
1058 __acquires(htable->lock) 1058 __acquires(htable->lock)
1059{ 1059{
1060 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private)); 1060 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->file));
1061 unsigned int *bucket; 1061 unsigned int *bucket;
1062 1062
1063 spin_lock_bh(&htable->lock); 1063 spin_lock_bh(&htable->lock);
@@ -1074,7 +1074,7 @@ static void *dl_seq_start(struct seq_file *s, loff_t *pos)
1074 1074
1075static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos) 1075static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
1076{ 1076{
1077 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private)); 1077 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->file));
1078 unsigned int *bucket = v; 1078 unsigned int *bucket = v;
1079 1079
1080 *pos = ++(*bucket); 1080 *pos = ++(*bucket);
@@ -1088,7 +1088,7 @@ static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
1088static void dl_seq_stop(struct seq_file *s, void *v) 1088static void dl_seq_stop(struct seq_file *s, void *v)
1089 __releases(htable->lock) 1089 __releases(htable->lock)
1090{ 1090{
1091 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private)); 1091 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->file));
1092 unsigned int *bucket = v; 1092 unsigned int *bucket = v;
1093 1093
1094 if (!IS_ERR(bucket)) 1094 if (!IS_ERR(bucket))
@@ -1130,7 +1130,7 @@ static void dl_seq_print(struct dsthash_ent *ent, u_int8_t family,
1130static int dl_seq_real_show_v2(struct dsthash_ent *ent, u_int8_t family, 1130static int dl_seq_real_show_v2(struct dsthash_ent *ent, u_int8_t family,
1131 struct seq_file *s) 1131 struct seq_file *s)
1132{ 1132{
1133 struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->private)); 1133 struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->file));
1134 1134
1135 spin_lock(&ent->lock); 1135 spin_lock(&ent->lock);
1136 /* recalculate to show accurate numbers */ 1136 /* recalculate to show accurate numbers */
@@ -1145,7 +1145,7 @@ static int dl_seq_real_show_v2(struct dsthash_ent *ent, u_int8_t family,
1145static int dl_seq_real_show_v1(struct dsthash_ent *ent, u_int8_t family, 1145static int dl_seq_real_show_v1(struct dsthash_ent *ent, u_int8_t family,
1146 struct seq_file *s) 1146 struct seq_file *s)
1147{ 1147{
1148 struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->private)); 1148 struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->file));
1149 1149
1150 spin_lock(&ent->lock); 1150 spin_lock(&ent->lock);
1151 /* recalculate to show accurate numbers */ 1151 /* recalculate to show accurate numbers */
@@ -1160,7 +1160,7 @@ static int dl_seq_real_show_v1(struct dsthash_ent *ent, u_int8_t family,
1160static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family, 1160static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family,
1161 struct seq_file *s) 1161 struct seq_file *s)
1162{ 1162{
1163 struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->private)); 1163 struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->file));
1164 1164
1165 spin_lock(&ent->lock); 1165 spin_lock(&ent->lock);
1166 /* recalculate to show accurate numbers */ 1166 /* recalculate to show accurate numbers */
@@ -1174,7 +1174,7 @@ static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family,
1174 1174
1175static int dl_seq_show_v2(struct seq_file *s, void *v) 1175static int dl_seq_show_v2(struct seq_file *s, void *v)
1176{ 1176{
1177 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private)); 1177 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->file));
1178 unsigned int *bucket = (unsigned int *)v; 1178 unsigned int *bucket = (unsigned int *)v;
1179 struct dsthash_ent *ent; 1179 struct dsthash_ent *ent;
1180 1180
@@ -1188,7 +1188,7 @@ static int dl_seq_show_v2(struct seq_file *s, void *v)
1188 1188
1189static int dl_seq_show_v1(struct seq_file *s, void *v) 1189static int dl_seq_show_v1(struct seq_file *s, void *v)
1190{ 1190{
1191 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private)); 1191 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->file));
1192 unsigned int *bucket = v; 1192 unsigned int *bucket = v;
1193 struct dsthash_ent *ent; 1193 struct dsthash_ent *ent;
1194 1194
@@ -1202,7 +1202,7 @@ static int dl_seq_show_v1(struct seq_file *s, void *v)
1202 1202
1203static int dl_seq_show(struct seq_file *s, void *v) 1203static int dl_seq_show(struct seq_file *s, void *v)
1204{ 1204{
1205 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private)); 1205 struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->file));
1206 unsigned int *bucket = v; 1206 unsigned int *bucket = v;
1207 struct dsthash_ent *ent; 1207 struct dsthash_ent *ent;
1208 1208
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 5610061e7f2e..75c92a87e7b2 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4137,36 +4137,52 @@ static const struct vm_operations_struct packet_mmap_ops = {
4137 .close = packet_mm_close, 4137 .close = packet_mm_close,
4138}; 4138};
4139 4139
4140static void free_pg_vec(struct pgv *pg_vec, unsigned int len) 4140static void free_pg_vec(struct pgv *pg_vec, unsigned int order,
4141 unsigned int len)
4141{ 4142{
4142 int i; 4143 int i;
4143 4144
4144 for (i = 0; i < len; i++) { 4145 for (i = 0; i < len; i++) {
4145 if (likely(pg_vec[i].buffer)) { 4146 if (likely(pg_vec[i].buffer)) {
4146 kvfree(pg_vec[i].buffer); 4147 if (is_vmalloc_addr(pg_vec[i].buffer))
4148 vfree(pg_vec[i].buffer);
4149 else
4150 free_pages((unsigned long)pg_vec[i].buffer,
4151 order);
4147 pg_vec[i].buffer = NULL; 4152 pg_vec[i].buffer = NULL;
4148 } 4153 }
4149 } 4154 }
4150 kfree(pg_vec); 4155 kfree(pg_vec);
4151} 4156}
4152 4157
4153static char *alloc_one_pg_vec_page(unsigned long size) 4158static char *alloc_one_pg_vec_page(unsigned long order)
4154{ 4159{
4155 char *buffer; 4160 char *buffer;
4161 gfp_t gfp_flags = GFP_KERNEL | __GFP_COMP |
4162 __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY;
4156 4163
4157 buffer = kvzalloc(size, GFP_KERNEL); 4164 buffer = (char *) __get_free_pages(gfp_flags, order);
4158 if (buffer) 4165 if (buffer)
4159 return buffer; 4166 return buffer;
4160 4167
4161 buffer = kvzalloc(size, GFP_KERNEL | __GFP_RETRY_MAYFAIL); 4168 /* __get_free_pages failed, fall back to vmalloc */
4169 buffer = vzalloc(array_size((1 << order), PAGE_SIZE));
4170 if (buffer)
4171 return buffer;
4162 4172
4163 return buffer; 4173 /* vmalloc failed, lets dig into swap here */
4174 gfp_flags &= ~__GFP_NORETRY;
4175 buffer = (char *) __get_free_pages(gfp_flags, order);
4176 if (buffer)
4177 return buffer;
4178
4179 /* complete and utter failure */
4180 return NULL;
4164} 4181}
4165 4182
4166static struct pgv *alloc_pg_vec(struct tpacket_req *req) 4183static struct pgv *alloc_pg_vec(struct tpacket_req *req, int order)
4167{ 4184{
4168 unsigned int block_nr = req->tp_block_nr; 4185 unsigned int block_nr = req->tp_block_nr;
4169 unsigned long size = req->tp_block_size;
4170 struct pgv *pg_vec; 4186 struct pgv *pg_vec;
4171 int i; 4187 int i;
4172 4188
@@ -4175,7 +4191,7 @@ static struct pgv *alloc_pg_vec(struct tpacket_req *req)
4175 goto out; 4191 goto out;
4176 4192
4177 for (i = 0; i < block_nr; i++) { 4193 for (i = 0; i < block_nr; i++) {
4178 pg_vec[i].buffer = alloc_one_pg_vec_page(size); 4194 pg_vec[i].buffer = alloc_one_pg_vec_page(order);
4179 if (unlikely(!pg_vec[i].buffer)) 4195 if (unlikely(!pg_vec[i].buffer))
4180 goto out_free_pgvec; 4196 goto out_free_pgvec;
4181 } 4197 }
@@ -4184,7 +4200,7 @@ out:
4184 return pg_vec; 4200 return pg_vec;
4185 4201
4186out_free_pgvec: 4202out_free_pgvec:
4187 free_pg_vec(pg_vec, block_nr); 4203 free_pg_vec(pg_vec, order, block_nr);
4188 pg_vec = NULL; 4204 pg_vec = NULL;
4189 goto out; 4205 goto out;
4190} 4206}
@@ -4194,9 +4210,9 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4194{ 4210{
4195 struct pgv *pg_vec = NULL; 4211 struct pgv *pg_vec = NULL;
4196 struct packet_sock *po = pkt_sk(sk); 4212 struct packet_sock *po = pkt_sk(sk);
4213 int was_running, order = 0;
4197 struct packet_ring_buffer *rb; 4214 struct packet_ring_buffer *rb;
4198 struct sk_buff_head *rb_queue; 4215 struct sk_buff_head *rb_queue;
4199 int was_running;
4200 __be16 num; 4216 __be16 num;
4201 int err = -EINVAL; 4217 int err = -EINVAL;
4202 /* Added to avoid minimal code churn */ 4218 /* Added to avoid minimal code churn */
@@ -4258,7 +4274,8 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4258 goto out; 4274 goto out;
4259 4275
4260 err = -ENOMEM; 4276 err = -ENOMEM;
4261 pg_vec = alloc_pg_vec(req); 4277 order = get_order(req->tp_block_size);
4278 pg_vec = alloc_pg_vec(req, order);
4262 if (unlikely(!pg_vec)) 4279 if (unlikely(!pg_vec))
4263 goto out; 4280 goto out;
4264 switch (po->tp_version) { 4281 switch (po->tp_version) {
@@ -4312,6 +4329,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4312 rb->frame_size = req->tp_frame_size; 4329 rb->frame_size = req->tp_frame_size;
4313 spin_unlock_bh(&rb_queue->lock); 4330 spin_unlock_bh(&rb_queue->lock);
4314 4331
4332 swap(rb->pg_vec_order, order);
4315 swap(rb->pg_vec_len, req->tp_block_nr); 4333 swap(rb->pg_vec_len, req->tp_block_nr);
4316 4334
4317 rb->pg_vec_pages = req->tp_block_size/PAGE_SIZE; 4335 rb->pg_vec_pages = req->tp_block_size/PAGE_SIZE;
@@ -4337,7 +4355,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4337 } 4355 }
4338 4356
4339 if (pg_vec) 4357 if (pg_vec)
4340 free_pg_vec(pg_vec, req->tp_block_nr); 4358 free_pg_vec(pg_vec, order, req->tp_block_nr);
4341out: 4359out:
4342 return err; 4360 return err;
4343} 4361}
diff --git a/net/packet/internal.h b/net/packet/internal.h
index 8f50036f62f0..3bb7c5fb3bff 100644
--- a/net/packet/internal.h
+++ b/net/packet/internal.h
@@ -64,6 +64,7 @@ struct packet_ring_buffer {
64 unsigned int frame_size; 64 unsigned int frame_size;
65 unsigned int frame_max; 65 unsigned int frame_max;
66 66
67 unsigned int pg_vec_order;
67 unsigned int pg_vec_pages; 68 unsigned int pg_vec_pages;
68 unsigned int pg_vec_len; 69 unsigned int pg_vec_len;
69 70
diff --git a/net/rds/Kconfig b/net/rds/Kconfig
index 01b3bd6a3708..b9092111bc45 100644
--- a/net/rds/Kconfig
+++ b/net/rds/Kconfig
@@ -1,6 +1,6 @@
1 1
2config RDS 2config RDS
3 tristate "The RDS Protocol" 3 tristate "The Reliable Datagram Sockets Protocol"
4 depends on INET 4 depends on INET
5 ---help--- 5 ---help---
6 The RDS (Reliable Datagram Sockets) protocol provides reliable, 6 The RDS (Reliable Datagram Sockets) protocol provides reliable,
diff --git a/net/rds/bind.c b/net/rds/bind.c
index 3ab55784b637..762d2c6788a3 100644
--- a/net/rds/bind.c
+++ b/net/rds/bind.c
@@ -76,11 +76,13 @@ struct rds_sock *rds_find_bound(const struct in6_addr *addr, __be16 port,
76 struct rds_sock *rs; 76 struct rds_sock *rs;
77 77
78 __rds_create_bind_key(key, addr, port, scope_id); 78 __rds_create_bind_key(key, addr, port, scope_id);
79 rs = rhashtable_lookup_fast(&bind_hash_table, key, ht_parms); 79 rcu_read_lock();
80 rs = rhashtable_lookup(&bind_hash_table, key, ht_parms);
80 if (rs && !sock_flag(rds_rs_to_sk(rs), SOCK_DEAD)) 81 if (rs && !sock_flag(rds_rs_to_sk(rs), SOCK_DEAD))
81 rds_sock_addref(rs); 82 rds_sock_addref(rs);
82 else 83 else
83 rs = NULL; 84 rs = NULL;
85 rcu_read_unlock();
84 86
85 rdsdebug("returning rs %p for %pI6c:%u\n", rs, addr, 87 rdsdebug("returning rs %p for %pI6c:%u\n", rs, addr,
86 ntohs(port)); 88 ntohs(port));
@@ -235,6 +237,7 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
235 goto out; 237 goto out;
236 } 238 }
237 239
240 sock_set_flag(sk, SOCK_RCU_FREE);
238 ret = rds_add_bound(rs, binding_addr, &port, scope_id); 241 ret = rds_add_bound(rs, binding_addr, &port, scope_id);
239 if (ret) 242 if (ret)
240 goto out; 243 goto out;
diff --git a/net/rds/ib.c b/net/rds/ib.c
index c1d97640c0be..eba75c1ba359 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -341,15 +341,10 @@ static int rds6_ib_conn_info_visitor(struct rds_connection *conn,
341 341
342 if (rds_conn_state(conn) == RDS_CONN_UP) { 342 if (rds_conn_state(conn) == RDS_CONN_UP) {
343 struct rds_ib_device *rds_ibdev; 343 struct rds_ib_device *rds_ibdev;
344 struct rdma_dev_addr *dev_addr;
345 344
346 ic = conn->c_transport_data; 345 ic = conn->c_transport_data;
347 dev_addr = &ic->i_cm_id->route.addr.dev_addr; 346 rdma_read_gids(ic->i_cm_id, (union ib_gid *)&iinfo6->src_gid,
348 rdma_addr_get_sgid(dev_addr, 347 (union ib_gid *)&iinfo6->dst_gid);
349 (union ib_gid *)&iinfo6->src_gid);
350 rdma_addr_get_dgid(dev_addr,
351 (union ib_gid *)&iinfo6->dst_gid);
352
353 rds_ibdev = ic->rds_ibdev; 348 rds_ibdev = ic->rds_ibdev;
354 iinfo6->max_send_wr = ic->i_send_ring.w_nr; 349 iinfo6->max_send_wr = ic->i_send_ring.w_nr;
355 iinfo6->max_recv_wr = ic->i_recv_ring.w_nr; 350 iinfo6->max_recv_wr = ic->i_recv_ring.w_nr;
diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index 2c7b7c352d3e..b9bbcf3d6c63 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -37,7 +37,6 @@
37#include <net/tcp.h> 37#include <net/tcp.h>
38#include <net/net_namespace.h> 38#include <net/net_namespace.h>
39#include <net/netns/generic.h> 39#include <net/netns/generic.h>
40#include <net/tcp.h>
41#include <net/addrconf.h> 40#include <net/addrconf.h>
42 41
43#include "rds.h" 42#include "rds.h"
diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
index 00192a996be0..0f8465852254 100644
--- a/net/rfkill/rfkill-gpio.c
+++ b/net/rfkill/rfkill-gpio.c
@@ -20,6 +20,7 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/mod_devicetable.h>
23#include <linux/rfkill.h> 24#include <linux/rfkill.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
25#include <linux/clk.h> 26#include <linux/clk.h>
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 229d63c99be2..e12f8ef7baa4 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -300,21 +300,17 @@ int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
300} 300}
301EXPORT_SYMBOL(tcf_generic_walker); 301EXPORT_SYMBOL(tcf_generic_walker);
302 302
303static bool __tcf_idr_check(struct tc_action_net *tn, u32 index, 303int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
304 struct tc_action **a, int bind)
305{ 304{
306 struct tcf_idrinfo *idrinfo = tn->idrinfo; 305 struct tcf_idrinfo *idrinfo = tn->idrinfo;
307 struct tc_action *p; 306 struct tc_action *p;
308 307
309 spin_lock(&idrinfo->lock); 308 spin_lock(&idrinfo->lock);
310 p = idr_find(&idrinfo->action_idr, index); 309 p = idr_find(&idrinfo->action_idr, index);
311 if (IS_ERR(p)) { 310 if (IS_ERR(p))
312 p = NULL; 311 p = NULL;
313 } else if (p) { 312 else if (p)
314 refcount_inc(&p->tcfa_refcnt); 313 refcount_inc(&p->tcfa_refcnt);
315 if (bind)
316 atomic_inc(&p->tcfa_bindcnt);
317 }
318 spin_unlock(&idrinfo->lock); 314 spin_unlock(&idrinfo->lock);
319 315
320 if (p) { 316 if (p) {
@@ -323,23 +319,10 @@ static bool __tcf_idr_check(struct tc_action_net *tn, u32 index,
323 } 319 }
324 return false; 320 return false;
325} 321}
326
327int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index)
328{
329 return __tcf_idr_check(tn, index, a, 0);
330}
331EXPORT_SYMBOL(tcf_idr_search); 322EXPORT_SYMBOL(tcf_idr_search);
332 323
333bool tcf_idr_check(struct tc_action_net *tn, u32 index, struct tc_action **a, 324static int tcf_idr_delete_index(struct tcf_idrinfo *idrinfo, u32 index)
334 int bind)
335{ 325{
336 return __tcf_idr_check(tn, index, a, bind);
337}
338EXPORT_SYMBOL(tcf_idr_check);
339
340int tcf_idr_delete_index(struct tc_action_net *tn, u32 index)
341{
342 struct tcf_idrinfo *idrinfo = tn->idrinfo;
343 struct tc_action *p; 326 struct tc_action *p;
344 int ret = 0; 327 int ret = 0;
345 328
@@ -370,7 +353,6 @@ int tcf_idr_delete_index(struct tc_action_net *tn, u32 index)
370 spin_unlock(&idrinfo->lock); 353 spin_unlock(&idrinfo->lock);
371 return ret; 354 return ret;
372} 355}
373EXPORT_SYMBOL(tcf_idr_delete_index);
374 356
375int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, 357int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
376 struct tc_action **a, const struct tc_action_ops *ops, 358 struct tc_action **a, const struct tc_action_ops *ops,
@@ -409,7 +391,6 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
409 391
410 p->idrinfo = idrinfo; 392 p->idrinfo = idrinfo;
411 p->ops = ops; 393 p->ops = ops;
412 INIT_LIST_HEAD(&p->list);
413 *a = p; 394 *a = p;
414 return 0; 395 return 0;
415err3: 396err3:
@@ -681,19 +662,30 @@ int tcf_action_destroy(struct tc_action *actions[], int bind)
681 return ret; 662 return ret;
682} 663}
683 664
665static int tcf_action_destroy_1(struct tc_action *a, int bind)
666{
667 struct tc_action *actions[] = { a, NULL };
668
669 return tcf_action_destroy(actions, bind);
670}
671
684static int tcf_action_put(struct tc_action *p) 672static int tcf_action_put(struct tc_action *p)
685{ 673{
686 return __tcf_action_put(p, false); 674 return __tcf_action_put(p, false);
687} 675}
688 676
677/* Put all actions in this array, skip those NULL's. */
689static void tcf_action_put_many(struct tc_action *actions[]) 678static void tcf_action_put_many(struct tc_action *actions[])
690{ 679{
691 int i; 680 int i;
692 681
693 for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) { 682 for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
694 struct tc_action *a = actions[i]; 683 struct tc_action *a = actions[i];
695 const struct tc_action_ops *ops = a->ops; 684 const struct tc_action_ops *ops;
696 685
686 if (!a)
687 continue;
688 ops = a->ops;
697 if (tcf_action_put(a)) 689 if (tcf_action_put(a))
698 module_put(ops->owner); 690 module_put(ops->owner);
699 } 691 }
@@ -896,17 +888,16 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
896 if (TC_ACT_EXT_CMP(a->tcfa_action, TC_ACT_GOTO_CHAIN)) { 888 if (TC_ACT_EXT_CMP(a->tcfa_action, TC_ACT_GOTO_CHAIN)) {
897 err = tcf_action_goto_chain_init(a, tp); 889 err = tcf_action_goto_chain_init(a, tp);
898 if (err) { 890 if (err) {
899 struct tc_action *actions[] = { a, NULL }; 891 tcf_action_destroy_1(a, bind);
900
901 tcf_action_destroy(actions, bind);
902 NL_SET_ERR_MSG(extack, "Failed to init TC action chain"); 892 NL_SET_ERR_MSG(extack, "Failed to init TC action chain");
903 return ERR_PTR(err); 893 return ERR_PTR(err);
904 } 894 }
905 } 895 }
906 896
907 if (!tcf_action_valid(a->tcfa_action)) { 897 if (!tcf_action_valid(a->tcfa_action)) {
908 NL_SET_ERR_MSG(extack, "invalid action value, using TC_ACT_UNSPEC instead"); 898 tcf_action_destroy_1(a, bind);
909 a->tcfa_action = TC_ACT_UNSPEC; 899 NL_SET_ERR_MSG(extack, "Invalid control action value");
900 return ERR_PTR(-EINVAL);
910 } 901 }
911 902
912 return a; 903 return a;
@@ -1175,41 +1166,38 @@ err_out:
1175 return err; 1166 return err;
1176} 1167}
1177 1168
1178static int tcf_action_delete(struct net *net, struct tc_action *actions[], 1169static int tcf_action_delete(struct net *net, struct tc_action *actions[])
1179 int *acts_deleted, struct netlink_ext_ack *extack)
1180{ 1170{
1181 u32 act_index; 1171 int i;
1182 int ret, i;
1183 1172
1184 for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) { 1173 for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
1185 struct tc_action *a = actions[i]; 1174 struct tc_action *a = actions[i];
1186 const struct tc_action_ops *ops = a->ops; 1175 const struct tc_action_ops *ops = a->ops;
1187
1188 /* Actions can be deleted concurrently so we must save their 1176 /* Actions can be deleted concurrently so we must save their
1189 * type and id to search again after reference is released. 1177 * type and id to search again after reference is released.
1190 */ 1178 */
1191 act_index = a->tcfa_index; 1179 struct tcf_idrinfo *idrinfo = a->idrinfo;
1180 u32 act_index = a->tcfa_index;
1192 1181
1182 actions[i] = NULL;
1193 if (tcf_action_put(a)) { 1183 if (tcf_action_put(a)) {
1194 /* last reference, action was deleted concurrently */ 1184 /* last reference, action was deleted concurrently */
1195 module_put(ops->owner); 1185 module_put(ops->owner);
1196 } else { 1186 } else {
1187 int ret;
1188
1197 /* now do the delete */ 1189 /* now do the delete */
1198 ret = ops->delete(net, act_index); 1190 ret = tcf_idr_delete_index(idrinfo, act_index);
1199 if (ret < 0) { 1191 if (ret < 0)
1200 *acts_deleted = i + 1;
1201 return ret; 1192 return ret;
1202 }
1203 } 1193 }
1204 } 1194 }
1205 *acts_deleted = i;
1206 return 0; 1195 return 0;
1207} 1196}
1208 1197
1209static int 1198static int
1210tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], 1199tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[],
1211 int *acts_deleted, u32 portid, size_t attr_size, 1200 u32 portid, size_t attr_size, struct netlink_ext_ack *extack)
1212 struct netlink_ext_ack *extack)
1213{ 1201{
1214 int ret; 1202 int ret;
1215 struct sk_buff *skb; 1203 struct sk_buff *skb;
@@ -1227,7 +1215,7 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[],
1227 } 1215 }
1228 1216
1229 /* now do the delete */ 1217 /* now do the delete */
1230 ret = tcf_action_delete(net, actions, acts_deleted, extack); 1218 ret = tcf_action_delete(net, actions);
1231 if (ret < 0) { 1219 if (ret < 0) {
1232 NL_SET_ERR_MSG(extack, "Failed to delete TC action"); 1220 NL_SET_ERR_MSG(extack, "Failed to delete TC action");
1233 kfree_skb(skb); 1221 kfree_skb(skb);
@@ -1249,8 +1237,7 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
1249 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1]; 1237 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
1250 struct tc_action *act; 1238 struct tc_action *act;
1251 size_t attr_size = 0; 1239 size_t attr_size = 0;
1252 struct tc_action *actions[TCA_ACT_MAX_PRIO + 1] = {}; 1240 struct tc_action *actions[TCA_ACT_MAX_PRIO] = {};
1253 int acts_deleted = 0;
1254 1241
1255 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL, extack); 1242 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL, extack);
1256 if (ret < 0) 1243 if (ret < 0)
@@ -1280,14 +1267,13 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
1280 if (event == RTM_GETACTION) 1267 if (event == RTM_GETACTION)
1281 ret = tcf_get_notify(net, portid, n, actions, event, extack); 1268 ret = tcf_get_notify(net, portid, n, actions, event, extack);
1282 else { /* delete */ 1269 else { /* delete */
1283 ret = tcf_del_notify(net, n, actions, &acts_deleted, portid, 1270 ret = tcf_del_notify(net, n, actions, portid, attr_size, extack);
1284 attr_size, extack);
1285 if (ret) 1271 if (ret)
1286 goto err; 1272 goto err;
1287 return ret; 1273 return 0;
1288 } 1274 }
1289err: 1275err:
1290 tcf_action_put_many(&actions[acts_deleted]); 1276 tcf_action_put_many(actions);
1291 return ret; 1277 return ret;
1292} 1278}
1293 1279
diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c
index d30b23e42436..0c68bc9cf0b4 100644
--- a/net/sched/act_bpf.c
+++ b/net/sched/act_bpf.c
@@ -395,13 +395,6 @@ static int tcf_bpf_search(struct net *net, struct tc_action **a, u32 index,
395 return tcf_idr_search(tn, a, index); 395 return tcf_idr_search(tn, a, index);
396} 396}
397 397
398static int tcf_bpf_delete(struct net *net, u32 index)
399{
400 struct tc_action_net *tn = net_generic(net, bpf_net_id);
401
402 return tcf_idr_delete_index(tn, index);
403}
404
405static struct tc_action_ops act_bpf_ops __read_mostly = { 398static struct tc_action_ops act_bpf_ops __read_mostly = {
406 .kind = "bpf", 399 .kind = "bpf",
407 .type = TCA_ACT_BPF, 400 .type = TCA_ACT_BPF,
@@ -412,7 +405,6 @@ static struct tc_action_ops act_bpf_ops __read_mostly = {
412 .init = tcf_bpf_init, 405 .init = tcf_bpf_init,
413 .walk = tcf_bpf_walker, 406 .walk = tcf_bpf_walker,
414 .lookup = tcf_bpf_search, 407 .lookup = tcf_bpf_search,
415 .delete = tcf_bpf_delete,
416 .size = sizeof(struct tcf_bpf), 408 .size = sizeof(struct tcf_bpf),
417}; 409};
418 410
diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c
index 54c0bf54f2ac..6f0f273f1139 100644
--- a/net/sched/act_connmark.c
+++ b/net/sched/act_connmark.c
@@ -198,13 +198,6 @@ static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index,
198 return tcf_idr_search(tn, a, index); 198 return tcf_idr_search(tn, a, index);
199} 199}
200 200
201static int tcf_connmark_delete(struct net *net, u32 index)
202{
203 struct tc_action_net *tn = net_generic(net, connmark_net_id);
204
205 return tcf_idr_delete_index(tn, index);
206}
207
208static struct tc_action_ops act_connmark_ops = { 201static struct tc_action_ops act_connmark_ops = {
209 .kind = "connmark", 202 .kind = "connmark",
210 .type = TCA_ACT_CONNMARK, 203 .type = TCA_ACT_CONNMARK,
@@ -214,7 +207,6 @@ static struct tc_action_ops act_connmark_ops = {
214 .init = tcf_connmark_init, 207 .init = tcf_connmark_init,
215 .walk = tcf_connmark_walker, 208 .walk = tcf_connmark_walker,
216 .lookup = tcf_connmark_search, 209 .lookup = tcf_connmark_search,
217 .delete = tcf_connmark_delete,
218 .size = sizeof(struct tcf_connmark_info), 210 .size = sizeof(struct tcf_connmark_info),
219}; 211};
220 212
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index e698d3fe2080..b8a67ae3105a 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -659,13 +659,6 @@ static size_t tcf_csum_get_fill_size(const struct tc_action *act)
659 return nla_total_size(sizeof(struct tc_csum)); 659 return nla_total_size(sizeof(struct tc_csum));
660} 660}
661 661
662static int tcf_csum_delete(struct net *net, u32 index)
663{
664 struct tc_action_net *tn = net_generic(net, csum_net_id);
665
666 return tcf_idr_delete_index(tn, index);
667}
668
669static struct tc_action_ops act_csum_ops = { 662static struct tc_action_ops act_csum_ops = {
670 .kind = "csum", 663 .kind = "csum",
671 .type = TCA_ACT_CSUM, 664 .type = TCA_ACT_CSUM,
@@ -677,7 +670,6 @@ static struct tc_action_ops act_csum_ops = {
677 .walk = tcf_csum_walker, 670 .walk = tcf_csum_walker,
678 .lookup = tcf_csum_search, 671 .lookup = tcf_csum_search,
679 .get_fill_size = tcf_csum_get_fill_size, 672 .get_fill_size = tcf_csum_get_fill_size,
680 .delete = tcf_csum_delete,
681 .size = sizeof(struct tcf_csum), 673 .size = sizeof(struct tcf_csum),
682}; 674};
683 675
diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
index 6a3f25a8ffb3..cd1d9bd32ef9 100644
--- a/net/sched/act_gact.c
+++ b/net/sched/act_gact.c
@@ -243,13 +243,6 @@ static size_t tcf_gact_get_fill_size(const struct tc_action *act)
243 return sz; 243 return sz;
244} 244}
245 245
246static int tcf_gact_delete(struct net *net, u32 index)
247{
248 struct tc_action_net *tn = net_generic(net, gact_net_id);
249
250 return tcf_idr_delete_index(tn, index);
251}
252
253static struct tc_action_ops act_gact_ops = { 246static struct tc_action_ops act_gact_ops = {
254 .kind = "gact", 247 .kind = "gact",
255 .type = TCA_ACT_GACT, 248 .type = TCA_ACT_GACT,
@@ -261,7 +254,6 @@ static struct tc_action_ops act_gact_ops = {
261 .walk = tcf_gact_walker, 254 .walk = tcf_gact_walker,
262 .lookup = tcf_gact_search, 255 .lookup = tcf_gact_search,
263 .get_fill_size = tcf_gact_get_fill_size, 256 .get_fill_size = tcf_gact_get_fill_size,
264 .delete = tcf_gact_delete,
265 .size = sizeof(struct tcf_gact), 257 .size = sizeof(struct tcf_gact),
266}; 258};
267 259
diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index d1081bdf1bdb..06a3d4801878 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -167,16 +167,16 @@ static struct tcf_meta_ops *find_ife_oplist(u16 metaid)
167{ 167{
168 struct tcf_meta_ops *o; 168 struct tcf_meta_ops *o;
169 169
170 read_lock_bh(&ife_mod_lock); 170 read_lock(&ife_mod_lock);
171 list_for_each_entry(o, &ifeoplist, list) { 171 list_for_each_entry(o, &ifeoplist, list) {
172 if (o->metaid == metaid) { 172 if (o->metaid == metaid) {
173 if (!try_module_get(o->owner)) 173 if (!try_module_get(o->owner))
174 o = NULL; 174 o = NULL;
175 read_unlock_bh(&ife_mod_lock); 175 read_unlock(&ife_mod_lock);
176 return o; 176 return o;
177 } 177 }
178 } 178 }
179 read_unlock_bh(&ife_mod_lock); 179 read_unlock(&ife_mod_lock);
180 180
181 return NULL; 181 return NULL;
182} 182}
@@ -190,12 +190,12 @@ int register_ife_op(struct tcf_meta_ops *mops)
190 !mops->get || !mops->alloc) 190 !mops->get || !mops->alloc)
191 return -EINVAL; 191 return -EINVAL;
192 192
193 write_lock_bh(&ife_mod_lock); 193 write_lock(&ife_mod_lock);
194 194
195 list_for_each_entry(m, &ifeoplist, list) { 195 list_for_each_entry(m, &ifeoplist, list) {
196 if (m->metaid == mops->metaid || 196 if (m->metaid == mops->metaid ||
197 (strcmp(mops->name, m->name) == 0)) { 197 (strcmp(mops->name, m->name) == 0)) {
198 write_unlock_bh(&ife_mod_lock); 198 write_unlock(&ife_mod_lock);
199 return -EEXIST; 199 return -EEXIST;
200 } 200 }
201 } 201 }
@@ -204,7 +204,7 @@ int register_ife_op(struct tcf_meta_ops *mops)
204 mops->release = ife_release_meta_gen; 204 mops->release = ife_release_meta_gen;
205 205
206 list_add_tail(&mops->list, &ifeoplist); 206 list_add_tail(&mops->list, &ifeoplist);
207 write_unlock_bh(&ife_mod_lock); 207 write_unlock(&ife_mod_lock);
208 return 0; 208 return 0;
209} 209}
210EXPORT_SYMBOL_GPL(unregister_ife_op); 210EXPORT_SYMBOL_GPL(unregister_ife_op);
@@ -214,7 +214,7 @@ int unregister_ife_op(struct tcf_meta_ops *mops)
214 struct tcf_meta_ops *m; 214 struct tcf_meta_ops *m;
215 int err = -ENOENT; 215 int err = -ENOENT;
216 216
217 write_lock_bh(&ife_mod_lock); 217 write_lock(&ife_mod_lock);
218 list_for_each_entry(m, &ifeoplist, list) { 218 list_for_each_entry(m, &ifeoplist, list) {
219 if (m->metaid == mops->metaid) { 219 if (m->metaid == mops->metaid) {
220 list_del(&mops->list); 220 list_del(&mops->list);
@@ -222,7 +222,7 @@ int unregister_ife_op(struct tcf_meta_ops *mops)
222 break; 222 break;
223 } 223 }
224 } 224 }
225 write_unlock_bh(&ife_mod_lock); 225 write_unlock(&ife_mod_lock);
226 226
227 return err; 227 return err;
228} 228}
@@ -265,11 +265,8 @@ static const char *ife_meta_id2name(u32 metaid)
265#endif 265#endif
266 266
267/* called when adding new meta information 267/* called when adding new meta information
268 * under ife->tcf_lock for existing action
269*/ 268*/
270static int load_metaops_and_vet(struct tcf_ife_info *ife, u32 metaid, 269static int load_metaops_and_vet(u32 metaid, void *val, int len, bool rtnl_held)
271 void *val, int len, bool exists,
272 bool rtnl_held)
273{ 270{
274 struct tcf_meta_ops *ops = find_ife_oplist(metaid); 271 struct tcf_meta_ops *ops = find_ife_oplist(metaid);
275 int ret = 0; 272 int ret = 0;
@@ -277,15 +274,11 @@ static int load_metaops_and_vet(struct tcf_ife_info *ife, u32 metaid,
277 if (!ops) { 274 if (!ops) {
278 ret = -ENOENT; 275 ret = -ENOENT;
279#ifdef CONFIG_MODULES 276#ifdef CONFIG_MODULES
280 if (exists)
281 spin_unlock_bh(&ife->tcf_lock);
282 if (rtnl_held) 277 if (rtnl_held)
283 rtnl_unlock(); 278 rtnl_unlock();
284 request_module("ife-meta-%s", ife_meta_id2name(metaid)); 279 request_module("ife-meta-%s", ife_meta_id2name(metaid));
285 if (rtnl_held) 280 if (rtnl_held)
286 rtnl_lock(); 281 rtnl_lock();
287 if (exists)
288 spin_lock_bh(&ife->tcf_lock);
289 ops = find_ife_oplist(metaid); 282 ops = find_ife_oplist(metaid);
290#endif 283#endif
291 } 284 }
@@ -302,24 +295,17 @@ static int load_metaops_and_vet(struct tcf_ife_info *ife, u32 metaid,
302} 295}
303 296
304/* called when adding new meta information 297/* called when adding new meta information
305 * under ife->tcf_lock for existing action
306*/ 298*/
307static int add_metainfo(struct tcf_ife_info *ife, u32 metaid, void *metaval, 299static int __add_metainfo(const struct tcf_meta_ops *ops,
308 int len, bool atomic) 300 struct tcf_ife_info *ife, u32 metaid, void *metaval,
301 int len, bool atomic, bool exists)
309{ 302{
310 struct tcf_meta_info *mi = NULL; 303 struct tcf_meta_info *mi = NULL;
311 struct tcf_meta_ops *ops = find_ife_oplist(metaid);
312 int ret = 0; 304 int ret = 0;
313 305
314 if (!ops)
315 return -ENOENT;
316
317 mi = kzalloc(sizeof(*mi), atomic ? GFP_ATOMIC : GFP_KERNEL); 306 mi = kzalloc(sizeof(*mi), atomic ? GFP_ATOMIC : GFP_KERNEL);
318 if (!mi) { 307 if (!mi)
319 /*put back what find_ife_oplist took */
320 module_put(ops->owner);
321 return -ENOMEM; 308 return -ENOMEM;
322 }
323 309
324 mi->metaid = metaid; 310 mi->metaid = metaid;
325 mi->ops = ops; 311 mi->ops = ops;
@@ -327,29 +313,61 @@ static int add_metainfo(struct tcf_ife_info *ife, u32 metaid, void *metaval,
327 ret = ops->alloc(mi, metaval, atomic ? GFP_ATOMIC : GFP_KERNEL); 313 ret = ops->alloc(mi, metaval, atomic ? GFP_ATOMIC : GFP_KERNEL);
328 if (ret != 0) { 314 if (ret != 0) {
329 kfree(mi); 315 kfree(mi);
330 module_put(ops->owner);
331 return ret; 316 return ret;
332 } 317 }
333 } 318 }
334 319
320 if (exists)
321 spin_lock_bh(&ife->tcf_lock);
335 list_add_tail(&mi->metalist, &ife->metalist); 322 list_add_tail(&mi->metalist, &ife->metalist);
323 if (exists)
324 spin_unlock_bh(&ife->tcf_lock);
325
326 return ret;
327}
328
329static int add_metainfo_and_get_ops(const struct tcf_meta_ops *ops,
330 struct tcf_ife_info *ife, u32 metaid,
331 bool exists)
332{
333 int ret;
334
335 if (!try_module_get(ops->owner))
336 return -ENOENT;
337 ret = __add_metainfo(ops, ife, metaid, NULL, 0, true, exists);
338 if (ret)
339 module_put(ops->owner);
340 return ret;
341}
342
343static int add_metainfo(struct tcf_ife_info *ife, u32 metaid, void *metaval,
344 int len, bool exists)
345{
346 const struct tcf_meta_ops *ops = find_ife_oplist(metaid);
347 int ret;
336 348
349 if (!ops)
350 return -ENOENT;
351 ret = __add_metainfo(ops, ife, metaid, metaval, len, false, exists);
352 if (ret)
353 /*put back what find_ife_oplist took */
354 module_put(ops->owner);
337 return ret; 355 return ret;
338} 356}
339 357
340static int use_all_metadata(struct tcf_ife_info *ife) 358static int use_all_metadata(struct tcf_ife_info *ife, bool exists)
341{ 359{
342 struct tcf_meta_ops *o; 360 struct tcf_meta_ops *o;
343 int rc = 0; 361 int rc = 0;
344 int installed = 0; 362 int installed = 0;
345 363
346 read_lock_bh(&ife_mod_lock); 364 read_lock(&ife_mod_lock);
347 list_for_each_entry(o, &ifeoplist, list) { 365 list_for_each_entry(o, &ifeoplist, list) {
348 rc = add_metainfo(ife, o->metaid, NULL, 0, true); 366 rc = add_metainfo_and_get_ops(o, ife, o->metaid, exists);
349 if (rc == 0) 367 if (rc == 0)
350 installed += 1; 368 installed += 1;
351 } 369 }
352 read_unlock_bh(&ife_mod_lock); 370 read_unlock(&ife_mod_lock);
353 371
354 if (installed) 372 if (installed)
355 return 0; 373 return 0;
@@ -396,7 +414,6 @@ static void _tcf_ife_cleanup(struct tc_action *a)
396 struct tcf_meta_info *e, *n; 414 struct tcf_meta_info *e, *n;
397 415
398 list_for_each_entry_safe(e, n, &ife->metalist, metalist) { 416 list_for_each_entry_safe(e, n, &ife->metalist, metalist) {
399 module_put(e->ops->owner);
400 list_del(&e->metalist); 417 list_del(&e->metalist);
401 if (e->metaval) { 418 if (e->metaval) {
402 if (e->ops->release) 419 if (e->ops->release)
@@ -404,6 +421,7 @@ static void _tcf_ife_cleanup(struct tc_action *a)
404 else 421 else
405 kfree(e->metaval); 422 kfree(e->metaval);
406 } 423 }
424 module_put(e->ops->owner);
407 kfree(e); 425 kfree(e);
408 } 426 }
409} 427}
@@ -422,7 +440,6 @@ static void tcf_ife_cleanup(struct tc_action *a)
422 kfree_rcu(p, rcu); 440 kfree_rcu(p, rcu);
423} 441}
424 442
425/* under ife->tcf_lock for existing action */
426static int populate_metalist(struct tcf_ife_info *ife, struct nlattr **tb, 443static int populate_metalist(struct tcf_ife_info *ife, struct nlattr **tb,
427 bool exists, bool rtnl_held) 444 bool exists, bool rtnl_held)
428{ 445{
@@ -436,8 +453,7 @@ static int populate_metalist(struct tcf_ife_info *ife, struct nlattr **tb,
436 val = nla_data(tb[i]); 453 val = nla_data(tb[i]);
437 len = nla_len(tb[i]); 454 len = nla_len(tb[i]);
438 455
439 rc = load_metaops_and_vet(ife, i, val, len, exists, 456 rc = load_metaops_and_vet(i, val, len, rtnl_held);
440 rtnl_held);
441 if (rc != 0) 457 if (rc != 0)
442 return rc; 458 return rc;
443 459
@@ -540,8 +556,6 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
540 p->eth_type = ife_type; 556 p->eth_type = ife_type;
541 } 557 }
542 558
543 if (exists)
544 spin_lock_bh(&ife->tcf_lock);
545 559
546 if (ret == ACT_P_CREATED) 560 if (ret == ACT_P_CREATED)
547 INIT_LIST_HEAD(&ife->metalist); 561 INIT_LIST_HEAD(&ife->metalist);
@@ -551,10 +565,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
551 NULL, NULL); 565 NULL, NULL);
552 if (err) { 566 if (err) {
553metadata_parse_err: 567metadata_parse_err:
554 if (exists)
555 spin_unlock_bh(&ife->tcf_lock);
556 tcf_idr_release(*a, bind); 568 tcf_idr_release(*a, bind);
557
558 kfree(p); 569 kfree(p);
559 return err; 570 return err;
560 } 571 }
@@ -569,17 +580,16 @@ metadata_parse_err:
569 * as we can. You better have at least one else we are 580 * as we can. You better have at least one else we are
570 * going to bail out 581 * going to bail out
571 */ 582 */
572 err = use_all_metadata(ife); 583 err = use_all_metadata(ife, exists);
573 if (err) { 584 if (err) {
574 if (exists)
575 spin_unlock_bh(&ife->tcf_lock);
576 tcf_idr_release(*a, bind); 585 tcf_idr_release(*a, bind);
577
578 kfree(p); 586 kfree(p);
579 return err; 587 return err;
580 } 588 }
581 } 589 }
582 590
591 if (exists)
592 spin_lock_bh(&ife->tcf_lock);
583 ife->tcf_action = parm->action; 593 ife->tcf_action = parm->action;
584 /* protected by tcf_lock when modifying existing action */ 594 /* protected by tcf_lock when modifying existing action */
585 rcu_swap_protected(ife->params, p, 1); 595 rcu_swap_protected(ife->params, p, 1);
@@ -853,13 +863,6 @@ static int tcf_ife_search(struct net *net, struct tc_action **a, u32 index,
853 return tcf_idr_search(tn, a, index); 863 return tcf_idr_search(tn, a, index);
854} 864}
855 865
856static int tcf_ife_delete(struct net *net, u32 index)
857{
858 struct tc_action_net *tn = net_generic(net, ife_net_id);
859
860 return tcf_idr_delete_index(tn, index);
861}
862
863static struct tc_action_ops act_ife_ops = { 866static struct tc_action_ops act_ife_ops = {
864 .kind = "ife", 867 .kind = "ife",
865 .type = TCA_ACT_IFE, 868 .type = TCA_ACT_IFE,
@@ -870,7 +873,6 @@ static struct tc_action_ops act_ife_ops = {
870 .init = tcf_ife_init, 873 .init = tcf_ife_init,
871 .walk = tcf_ife_walker, 874 .walk = tcf_ife_walker,
872 .lookup = tcf_ife_search, 875 .lookup = tcf_ife_search,
873 .delete = tcf_ife_delete,
874 .size = sizeof(struct tcf_ife_info), 876 .size = sizeof(struct tcf_ife_info),
875}; 877};
876 878
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 51f235bbeb5b..23273b5303fd 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -337,13 +337,6 @@ static int tcf_ipt_search(struct net *net, struct tc_action **a, u32 index,
337 return tcf_idr_search(tn, a, index); 337 return tcf_idr_search(tn, a, index);
338} 338}
339 339
340static int tcf_ipt_delete(struct net *net, u32 index)
341{
342 struct tc_action_net *tn = net_generic(net, ipt_net_id);
343
344 return tcf_idr_delete_index(tn, index);
345}
346
347static struct tc_action_ops act_ipt_ops = { 340static struct tc_action_ops act_ipt_ops = {
348 .kind = "ipt", 341 .kind = "ipt",
349 .type = TCA_ACT_IPT, 342 .type = TCA_ACT_IPT,
@@ -354,7 +347,6 @@ static struct tc_action_ops act_ipt_ops = {
354 .init = tcf_ipt_init, 347 .init = tcf_ipt_init,
355 .walk = tcf_ipt_walker, 348 .walk = tcf_ipt_walker,
356 .lookup = tcf_ipt_search, 349 .lookup = tcf_ipt_search,
357 .delete = tcf_ipt_delete,
358 .size = sizeof(struct tcf_ipt), 350 .size = sizeof(struct tcf_ipt),
359}; 351};
360 352
@@ -395,13 +387,6 @@ static int tcf_xt_search(struct net *net, struct tc_action **a, u32 index,
395 return tcf_idr_search(tn, a, index); 387 return tcf_idr_search(tn, a, index);
396} 388}
397 389
398static int tcf_xt_delete(struct net *net, u32 index)
399{
400 struct tc_action_net *tn = net_generic(net, xt_net_id);
401
402 return tcf_idr_delete_index(tn, index);
403}
404
405static struct tc_action_ops act_xt_ops = { 390static struct tc_action_ops act_xt_ops = {
406 .kind = "xt", 391 .kind = "xt",
407 .type = TCA_ACT_XT, 392 .type = TCA_ACT_XT,
@@ -412,7 +397,6 @@ static struct tc_action_ops act_xt_ops = {
412 .init = tcf_xt_init, 397 .init = tcf_xt_init,
413 .walk = tcf_xt_walker, 398 .walk = tcf_xt_walker,
414 .lookup = tcf_xt_search, 399 .lookup = tcf_xt_search,
415 .delete = tcf_xt_delete,
416 .size = sizeof(struct tcf_ipt), 400 .size = sizeof(struct tcf_ipt),
417}; 401};
418 402
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 38fd20f10f67..8bf66d0a6800 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -395,13 +395,6 @@ static void tcf_mirred_put_dev(struct net_device *dev)
395 dev_put(dev); 395 dev_put(dev);
396} 396}
397 397
398static int tcf_mirred_delete(struct net *net, u32 index)
399{
400 struct tc_action_net *tn = net_generic(net, mirred_net_id);
401
402 return tcf_idr_delete_index(tn, index);
403}
404
405static struct tc_action_ops act_mirred_ops = { 398static struct tc_action_ops act_mirred_ops = {
406 .kind = "mirred", 399 .kind = "mirred",
407 .type = TCA_ACT_MIRRED, 400 .type = TCA_ACT_MIRRED,
@@ -416,7 +409,6 @@ static struct tc_action_ops act_mirred_ops = {
416 .size = sizeof(struct tcf_mirred), 409 .size = sizeof(struct tcf_mirred),
417 .get_dev = tcf_mirred_get_dev, 410 .get_dev = tcf_mirred_get_dev,
418 .put_dev = tcf_mirred_put_dev, 411 .put_dev = tcf_mirred_put_dev,
419 .delete = tcf_mirred_delete,
420}; 412};
421 413
422static __net_init int mirred_init_net(struct net *net) 414static __net_init int mirred_init_net(struct net *net)
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index 822e903bfc25..4313aa102440 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -300,13 +300,6 @@ static int tcf_nat_search(struct net *net, struct tc_action **a, u32 index,
300 return tcf_idr_search(tn, a, index); 300 return tcf_idr_search(tn, a, index);
301} 301}
302 302
303static int tcf_nat_delete(struct net *net, u32 index)
304{
305 struct tc_action_net *tn = net_generic(net, nat_net_id);
306
307 return tcf_idr_delete_index(tn, index);
308}
309
310static struct tc_action_ops act_nat_ops = { 303static struct tc_action_ops act_nat_ops = {
311 .kind = "nat", 304 .kind = "nat",
312 .type = TCA_ACT_NAT, 305 .type = TCA_ACT_NAT,
@@ -316,7 +309,6 @@ static struct tc_action_ops act_nat_ops = {
316 .init = tcf_nat_init, 309 .init = tcf_nat_init,
317 .walk = tcf_nat_walker, 310 .walk = tcf_nat_walker,
318 .lookup = tcf_nat_search, 311 .lookup = tcf_nat_search,
319 .delete = tcf_nat_delete,
320 .size = sizeof(struct tcf_nat), 312 .size = sizeof(struct tcf_nat),
321}; 313};
322 314
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 8a7a7cb94e83..ad99a99f11f6 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -109,16 +109,18 @@ static int tcf_pedit_key_ex_dump(struct sk_buff *skb,
109{ 109{
110 struct nlattr *keys_start = nla_nest_start(skb, TCA_PEDIT_KEYS_EX); 110 struct nlattr *keys_start = nla_nest_start(skb, TCA_PEDIT_KEYS_EX);
111 111
112 if (!keys_start)
113 goto nla_failure;
112 for (; n > 0; n--) { 114 for (; n > 0; n--) {
113 struct nlattr *key_start; 115 struct nlattr *key_start;
114 116
115 key_start = nla_nest_start(skb, TCA_PEDIT_KEY_EX); 117 key_start = nla_nest_start(skb, TCA_PEDIT_KEY_EX);
118 if (!key_start)
119 goto nla_failure;
116 120
117 if (nla_put_u16(skb, TCA_PEDIT_KEY_EX_HTYPE, keys_ex->htype) || 121 if (nla_put_u16(skb, TCA_PEDIT_KEY_EX_HTYPE, keys_ex->htype) ||
118 nla_put_u16(skb, TCA_PEDIT_KEY_EX_CMD, keys_ex->cmd)) { 122 nla_put_u16(skb, TCA_PEDIT_KEY_EX_CMD, keys_ex->cmd))
119 nlmsg_trim(skb, keys_start); 123 goto nla_failure;
120 return -EINVAL;
121 }
122 124
123 nla_nest_end(skb, key_start); 125 nla_nest_end(skb, key_start);
124 126
@@ -128,6 +130,9 @@ static int tcf_pedit_key_ex_dump(struct sk_buff *skb,
128 nla_nest_end(skb, keys_start); 130 nla_nest_end(skb, keys_start);
129 131
130 return 0; 132 return 0;
133nla_failure:
134 nla_nest_cancel(skb, keys_start);
135 return -EINVAL;
131} 136}
132 137
133static int tcf_pedit_init(struct net *net, struct nlattr *nla, 138static int tcf_pedit_init(struct net *net, struct nlattr *nla,
@@ -418,7 +423,10 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,
418 opt->bindcnt = atomic_read(&p->tcf_bindcnt) - bind; 423 opt->bindcnt = atomic_read(&p->tcf_bindcnt) - bind;
419 424
420 if (p->tcfp_keys_ex) { 425 if (p->tcfp_keys_ex) {
421 tcf_pedit_key_ex_dump(skb, p->tcfp_keys_ex, p->tcfp_nkeys); 426 if (tcf_pedit_key_ex_dump(skb,
427 p->tcfp_keys_ex,
428 p->tcfp_nkeys))
429 goto nla_put_failure;
422 430
423 if (nla_put(skb, TCA_PEDIT_PARMS_EX, s, opt)) 431 if (nla_put(skb, TCA_PEDIT_PARMS_EX, s, opt))
424 goto nla_put_failure; 432 goto nla_put_failure;
@@ -460,13 +468,6 @@ static int tcf_pedit_search(struct net *net, struct tc_action **a, u32 index,
460 return tcf_idr_search(tn, a, index); 468 return tcf_idr_search(tn, a, index);
461} 469}
462 470
463static int tcf_pedit_delete(struct net *net, u32 index)
464{
465 struct tc_action_net *tn = net_generic(net, pedit_net_id);
466
467 return tcf_idr_delete_index(tn, index);
468}
469
470static struct tc_action_ops act_pedit_ops = { 471static struct tc_action_ops act_pedit_ops = {
471 .kind = "pedit", 472 .kind = "pedit",
472 .type = TCA_ACT_PEDIT, 473 .type = TCA_ACT_PEDIT,
@@ -477,7 +478,6 @@ static struct tc_action_ops act_pedit_ops = {
477 .init = tcf_pedit_init, 478 .init = tcf_pedit_init,
478 .walk = tcf_pedit_walker, 479 .walk = tcf_pedit_walker,
479 .lookup = tcf_pedit_search, 480 .lookup = tcf_pedit_search,
480 .delete = tcf_pedit_delete,
481 .size = sizeof(struct tcf_pedit), 481 .size = sizeof(struct tcf_pedit),
482}; 482};
483 483
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 06f0742db593..5d8bfa878477 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -320,13 +320,6 @@ static int tcf_police_search(struct net *net, struct tc_action **a, u32 index,
320 return tcf_idr_search(tn, a, index); 320 return tcf_idr_search(tn, a, index);
321} 321}
322 322
323static int tcf_police_delete(struct net *net, u32 index)
324{
325 struct tc_action_net *tn = net_generic(net, police_net_id);
326
327 return tcf_idr_delete_index(tn, index);
328}
329
330MODULE_AUTHOR("Alexey Kuznetsov"); 323MODULE_AUTHOR("Alexey Kuznetsov");
331MODULE_DESCRIPTION("Policing actions"); 324MODULE_DESCRIPTION("Policing actions");
332MODULE_LICENSE("GPL"); 325MODULE_LICENSE("GPL");
@@ -340,7 +333,6 @@ static struct tc_action_ops act_police_ops = {
340 .init = tcf_police_init, 333 .init = tcf_police_init,
341 .walk = tcf_police_walker, 334 .walk = tcf_police_walker,
342 .lookup = tcf_police_search, 335 .lookup = tcf_police_search,
343 .delete = tcf_police_delete,
344 .size = sizeof(struct tcf_police), 336 .size = sizeof(struct tcf_police),
345}; 337};
346 338
diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c
index 207b4132d1b0..44e9c00657bc 100644
--- a/net/sched/act_sample.c
+++ b/net/sched/act_sample.c
@@ -232,13 +232,6 @@ static int tcf_sample_search(struct net *net, struct tc_action **a, u32 index,
232 return tcf_idr_search(tn, a, index); 232 return tcf_idr_search(tn, a, index);
233} 233}
234 234
235static int tcf_sample_delete(struct net *net, u32 index)
236{
237 struct tc_action_net *tn = net_generic(net, sample_net_id);
238
239 return tcf_idr_delete_index(tn, index);
240}
241
242static struct tc_action_ops act_sample_ops = { 235static struct tc_action_ops act_sample_ops = {
243 .kind = "sample", 236 .kind = "sample",
244 .type = TCA_ACT_SAMPLE, 237 .type = TCA_ACT_SAMPLE,
@@ -249,7 +242,6 @@ static struct tc_action_ops act_sample_ops = {
249 .cleanup = tcf_sample_cleanup, 242 .cleanup = tcf_sample_cleanup,
250 .walk = tcf_sample_walker, 243 .walk = tcf_sample_walker,
251 .lookup = tcf_sample_search, 244 .lookup = tcf_sample_search,
252 .delete = tcf_sample_delete,
253 .size = sizeof(struct tcf_sample), 245 .size = sizeof(struct tcf_sample),
254}; 246};
255 247
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index e616523ba3c1..52400d49f81f 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -196,13 +196,6 @@ static int tcf_simp_search(struct net *net, struct tc_action **a, u32 index,
196 return tcf_idr_search(tn, a, index); 196 return tcf_idr_search(tn, a, index);
197} 197}
198 198
199static int tcf_simp_delete(struct net *net, u32 index)
200{
201 struct tc_action_net *tn = net_generic(net, simp_net_id);
202
203 return tcf_idr_delete_index(tn, index);
204}
205
206static struct tc_action_ops act_simp_ops = { 199static struct tc_action_ops act_simp_ops = {
207 .kind = "simple", 200 .kind = "simple",
208 .type = TCA_ACT_SIMP, 201 .type = TCA_ACT_SIMP,
@@ -213,7 +206,6 @@ static struct tc_action_ops act_simp_ops = {
213 .init = tcf_simp_init, 206 .init = tcf_simp_init,
214 .walk = tcf_simp_walker, 207 .walk = tcf_simp_walker,
215 .lookup = tcf_simp_search, 208 .lookup = tcf_simp_search,
216 .delete = tcf_simp_delete,
217 .size = sizeof(struct tcf_defact), 209 .size = sizeof(struct tcf_defact),
218}; 210};
219 211
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 926d7bc4a89d..73e44ce2a883 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -299,13 +299,6 @@ static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index,
299 return tcf_idr_search(tn, a, index); 299 return tcf_idr_search(tn, a, index);
300} 300}
301 301
302static int tcf_skbedit_delete(struct net *net, u32 index)
303{
304 struct tc_action_net *tn = net_generic(net, skbedit_net_id);
305
306 return tcf_idr_delete_index(tn, index);
307}
308
309static struct tc_action_ops act_skbedit_ops = { 302static struct tc_action_ops act_skbedit_ops = {
310 .kind = "skbedit", 303 .kind = "skbedit",
311 .type = TCA_ACT_SKBEDIT, 304 .type = TCA_ACT_SKBEDIT,
@@ -316,7 +309,6 @@ static struct tc_action_ops act_skbedit_ops = {
316 .cleanup = tcf_skbedit_cleanup, 309 .cleanup = tcf_skbedit_cleanup,
317 .walk = tcf_skbedit_walker, 310 .walk = tcf_skbedit_walker,
318 .lookup = tcf_skbedit_search, 311 .lookup = tcf_skbedit_search,
319 .delete = tcf_skbedit_delete,
320 .size = sizeof(struct tcf_skbedit), 312 .size = sizeof(struct tcf_skbedit),
321}; 313};
322 314
diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c
index d6a1af0c4171..588077fafd6c 100644
--- a/net/sched/act_skbmod.c
+++ b/net/sched/act_skbmod.c
@@ -259,13 +259,6 @@ static int tcf_skbmod_search(struct net *net, struct tc_action **a, u32 index,
259 return tcf_idr_search(tn, a, index); 259 return tcf_idr_search(tn, a, index);
260} 260}
261 261
262static int tcf_skbmod_delete(struct net *net, u32 index)
263{
264 struct tc_action_net *tn = net_generic(net, skbmod_net_id);
265
266 return tcf_idr_delete_index(tn, index);
267}
268
269static struct tc_action_ops act_skbmod_ops = { 262static struct tc_action_ops act_skbmod_ops = {
270 .kind = "skbmod", 263 .kind = "skbmod",
271 .type = TCA_ACT_SKBMOD, 264 .type = TCA_ACT_SKBMOD,
@@ -276,7 +269,6 @@ static struct tc_action_ops act_skbmod_ops = {
276 .cleanup = tcf_skbmod_cleanup, 269 .cleanup = tcf_skbmod_cleanup,
277 .walk = tcf_skbmod_walker, 270 .walk = tcf_skbmod_walker,
278 .lookup = tcf_skbmod_search, 271 .lookup = tcf_skbmod_search,
279 .delete = tcf_skbmod_delete,
280 .size = sizeof(struct tcf_skbmod), 272 .size = sizeof(struct tcf_skbmod),
281}; 273};
282 274
diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index 8f09cf08d8fe..681f6f04e7da 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -317,7 +317,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
317 &metadata->u.tun_info, 317 &metadata->u.tun_info,
318 opts_len, extack); 318 opts_len, extack);
319 if (ret < 0) 319 if (ret < 0)
320 goto err_out; 320 goto release_tun_meta;
321 } 321 }
322 322
323 metadata->u.tun_info.mode |= IP_TUNNEL_INFO_TX; 323 metadata->u.tun_info.mode |= IP_TUNNEL_INFO_TX;
@@ -333,23 +333,24 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
333 &act_tunnel_key_ops, bind, true); 333 &act_tunnel_key_ops, bind, true);
334 if (ret) { 334 if (ret) {
335 NL_SET_ERR_MSG(extack, "Cannot create TC IDR"); 335 NL_SET_ERR_MSG(extack, "Cannot create TC IDR");
336 goto err_out; 336 goto release_tun_meta;
337 } 337 }
338 338
339 ret = ACT_P_CREATED; 339 ret = ACT_P_CREATED;
340 } else if (!ovr) { 340 } else if (!ovr) {
341 tcf_idr_release(*a, bind);
342 NL_SET_ERR_MSG(extack, "TC IDR already exists"); 341 NL_SET_ERR_MSG(extack, "TC IDR already exists");
343 return -EEXIST; 342 ret = -EEXIST;
343 goto release_tun_meta;
344 } 344 }
345 345
346 t = to_tunnel_key(*a); 346 t = to_tunnel_key(*a);
347 347
348 params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); 348 params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
349 if (unlikely(!params_new)) { 349 if (unlikely(!params_new)) {
350 tcf_idr_release(*a, bind);
351 NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters"); 350 NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters");
352 return -ENOMEM; 351 ret = -ENOMEM;
352 exists = true;
353 goto release_tun_meta;
353 } 354 }
354 params_new->tcft_action = parm->t_action; 355 params_new->tcft_action = parm->t_action;
355 params_new->tcft_enc_metadata = metadata; 356 params_new->tcft_enc_metadata = metadata;
@@ -367,6 +368,9 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
367 368
368 return ret; 369 return ret;
369 370
371release_tun_meta:
372 dst_release(&metadata->dst);
373
370err_out: 374err_out:
371 if (exists) 375 if (exists)
372 tcf_idr_release(*a, bind); 376 tcf_idr_release(*a, bind);
@@ -408,8 +412,10 @@ static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
408 nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE, 412 nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE,
409 opt->type) || 413 opt->type) ||
410 nla_put(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA, 414 nla_put(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA,
411 opt->length * 4, opt + 1)) 415 opt->length * 4, opt + 1)) {
416 nla_nest_cancel(skb, start);
412 return -EMSGSIZE; 417 return -EMSGSIZE;
418 }
413 419
414 len -= sizeof(struct geneve_opt) + opt->length * 4; 420 len -= sizeof(struct geneve_opt) + opt->length * 4;
415 src += sizeof(struct geneve_opt) + opt->length * 4; 421 src += sizeof(struct geneve_opt) + opt->length * 4;
@@ -423,7 +429,7 @@ static int tunnel_key_opts_dump(struct sk_buff *skb,
423 const struct ip_tunnel_info *info) 429 const struct ip_tunnel_info *info)
424{ 430{
425 struct nlattr *start; 431 struct nlattr *start;
426 int err; 432 int err = -EINVAL;
427 433
428 if (!info->options_len) 434 if (!info->options_len)
429 return 0; 435 return 0;
@@ -435,9 +441,11 @@ static int tunnel_key_opts_dump(struct sk_buff *skb,
435 if (info->key.tun_flags & TUNNEL_GENEVE_OPT) { 441 if (info->key.tun_flags & TUNNEL_GENEVE_OPT) {
436 err = tunnel_key_geneve_opts_dump(skb, info); 442 err = tunnel_key_geneve_opts_dump(skb, info);
437 if (err) 443 if (err)
438 return err; 444 goto err_out;
439 } else { 445 } else {
440 return -EINVAL; 446err_out:
447 nla_nest_cancel(skb, start);
448 return err;
441 } 449 }
442 450
443 nla_nest_end(skb, start); 451 nla_nest_end(skb, start);
@@ -548,13 +556,6 @@ static int tunnel_key_search(struct net *net, struct tc_action **a, u32 index,
548 return tcf_idr_search(tn, a, index); 556 return tcf_idr_search(tn, a, index);
549} 557}
550 558
551static int tunnel_key_delete(struct net *net, u32 index)
552{
553 struct tc_action_net *tn = net_generic(net, tunnel_key_net_id);
554
555 return tcf_idr_delete_index(tn, index);
556}
557
558static struct tc_action_ops act_tunnel_key_ops = { 559static struct tc_action_ops act_tunnel_key_ops = {
559 .kind = "tunnel_key", 560 .kind = "tunnel_key",
560 .type = TCA_ACT_TUNNEL_KEY, 561 .type = TCA_ACT_TUNNEL_KEY,
@@ -565,7 +566,6 @@ static struct tc_action_ops act_tunnel_key_ops = {
565 .cleanup = tunnel_key_release, 566 .cleanup = tunnel_key_release,
566 .walk = tunnel_key_walker, 567 .walk = tunnel_key_walker,
567 .lookup = tunnel_key_search, 568 .lookup = tunnel_key_search,
568 .delete = tunnel_key_delete,
569 .size = sizeof(struct tcf_tunnel_key), 569 .size = sizeof(struct tcf_tunnel_key),
570}; 570};
571 571
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 209e70ad2c09..033d273afe50 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -296,13 +296,6 @@ static int tcf_vlan_search(struct net *net, struct tc_action **a, u32 index,
296 return tcf_idr_search(tn, a, index); 296 return tcf_idr_search(tn, a, index);
297} 297}
298 298
299static int tcf_vlan_delete(struct net *net, u32 index)
300{
301 struct tc_action_net *tn = net_generic(net, vlan_net_id);
302
303 return tcf_idr_delete_index(tn, index);
304}
305
306static struct tc_action_ops act_vlan_ops = { 299static struct tc_action_ops act_vlan_ops = {
307 .kind = "vlan", 300 .kind = "vlan",
308 .type = TCA_ACT_VLAN, 301 .type = TCA_ACT_VLAN,
@@ -313,7 +306,6 @@ static struct tc_action_ops act_vlan_ops = {
313 .cleanup = tcf_vlan_cleanup, 306 .cleanup = tcf_vlan_cleanup,
314 .walk = tcf_vlan_walker, 307 .walk = tcf_vlan_walker,
315 .lookup = tcf_vlan_search, 308 .lookup = tcf_vlan_search,
316 .delete = tcf_vlan_delete,
317 .size = sizeof(struct tcf_vlan), 309 .size = sizeof(struct tcf_vlan),
318}; 310};
319 311
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 31bd1439cf60..1a67af8a6e8c 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -1252,7 +1252,7 @@ replay:
1252 } 1252 }
1253 chain = tcf_chain_get(block, chain_index, true); 1253 chain = tcf_chain_get(block, chain_index, true);
1254 if (!chain) { 1254 if (!chain) {
1255 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain"); 1255 NL_SET_ERR_MSG(extack, "Cannot create specified filter chain");
1256 err = -ENOMEM; 1256 err = -ENOMEM;
1257 goto errout; 1257 goto errout;
1258 } 1258 }
@@ -1399,7 +1399,7 @@ static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
1399 goto errout; 1399 goto errout;
1400 } 1400 }
1401 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain"); 1401 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
1402 err = -EINVAL; 1402 err = -ENOENT;
1403 goto errout; 1403 goto errout;
1404 } 1404 }
1405 1405
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index d5d2a6dc3921..f218ccf1e2d9 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -914,6 +914,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
914 struct nlattr *opt = tca[TCA_OPTIONS]; 914 struct nlattr *opt = tca[TCA_OPTIONS];
915 struct nlattr *tb[TCA_U32_MAX + 1]; 915 struct nlattr *tb[TCA_U32_MAX + 1];
916 u32 htid, flags = 0; 916 u32 htid, flags = 0;
917 size_t sel_size;
917 int err; 918 int err;
918#ifdef CONFIG_CLS_U32_PERF 919#ifdef CONFIG_CLS_U32_PERF
919 size_t size; 920 size_t size;
@@ -1076,8 +1077,13 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
1076 } 1077 }
1077 1078
1078 s = nla_data(tb[TCA_U32_SEL]); 1079 s = nla_data(tb[TCA_U32_SEL]);
1080 sel_size = struct_size(s, keys, s->nkeys);
1081 if (nla_len(tb[TCA_U32_SEL]) < sel_size) {
1082 err = -EINVAL;
1083 goto erridr;
1084 }
1079 1085
1080 n = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), GFP_KERNEL); 1086 n = kzalloc(offsetof(typeof(*n), sel) + sel_size, GFP_KERNEL);
1081 if (n == NULL) { 1087 if (n == NULL) {
1082 err = -ENOBUFS; 1088 err = -ENOBUFS;
1083 goto erridr; 1089 goto erridr;
@@ -1092,7 +1098,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
1092 } 1098 }
1093#endif 1099#endif
1094 1100
1095 memcpy(&n->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)); 1101 memcpy(&n->sel, s, sel_size);
1096 RCU_INIT_POINTER(n->ht_up, ht); 1102 RCU_INIT_POINTER(n->ht_up, ht);
1097 n->handle = handle; 1103 n->handle = handle;
1098 n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0; 1104 n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;
diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
index 35fc7252187c..c07c30b916d5 100644
--- a/net/sched/sch_cake.c
+++ b/net/sched/sch_cake.c
@@ -64,7 +64,6 @@
64#include <linux/vmalloc.h> 64#include <linux/vmalloc.h>
65#include <linux/reciprocal_div.h> 65#include <linux/reciprocal_div.h>
66#include <net/netlink.h> 66#include <net/netlink.h>
67#include <linux/version.h>
68#include <linux/if_vlan.h> 67#include <linux/if_vlan.h>
69#include <net/pkt_sched.h> 68#include <net/pkt_sched.h>
70#include <net/pkt_cls.h> 69#include <net/pkt_cls.h>
@@ -621,15 +620,20 @@ static bool cake_ddst(int flow_mode)
621} 620}
622 621
623static u32 cake_hash(struct cake_tin_data *q, const struct sk_buff *skb, 622static u32 cake_hash(struct cake_tin_data *q, const struct sk_buff *skb,
624 int flow_mode) 623 int flow_mode, u16 flow_override, u16 host_override)
625{ 624{
626 u32 flow_hash = 0, srchost_hash, dsthost_hash; 625 u32 flow_hash = 0, srchost_hash = 0, dsthost_hash = 0;
627 u16 reduced_hash, srchost_idx, dsthost_idx; 626 u16 reduced_hash, srchost_idx, dsthost_idx;
628 struct flow_keys keys, host_keys; 627 struct flow_keys keys, host_keys;
629 628
630 if (unlikely(flow_mode == CAKE_FLOW_NONE)) 629 if (unlikely(flow_mode == CAKE_FLOW_NONE))
631 return 0; 630 return 0;
632 631
632 /* If both overrides are set we can skip packet dissection entirely */
633 if ((flow_override || !(flow_mode & CAKE_FLOW_FLOWS)) &&
634 (host_override || !(flow_mode & CAKE_FLOW_HOSTS)))
635 goto skip_hash;
636
633 skb_flow_dissect_flow_keys(skb, &keys, 637 skb_flow_dissect_flow_keys(skb, &keys,
634 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL); 638 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
635 639
@@ -676,6 +680,14 @@ static u32 cake_hash(struct cake_tin_data *q, const struct sk_buff *skb,
676 if (flow_mode & CAKE_FLOW_FLOWS) 680 if (flow_mode & CAKE_FLOW_FLOWS)
677 flow_hash = flow_hash_from_keys(&keys); 681 flow_hash = flow_hash_from_keys(&keys);
678 682
683skip_hash:
684 if (flow_override)
685 flow_hash = flow_override - 1;
686 if (host_override) {
687 dsthost_hash = host_override - 1;
688 srchost_hash = host_override - 1;
689 }
690
679 if (!(flow_mode & CAKE_FLOW_FLOWS)) { 691 if (!(flow_mode & CAKE_FLOW_FLOWS)) {
680 if (flow_mode & CAKE_FLOW_SRC_IP) 692 if (flow_mode & CAKE_FLOW_SRC_IP)
681 flow_hash ^= srchost_hash; 693 flow_hash ^= srchost_hash;
@@ -1571,7 +1583,7 @@ static u32 cake_classify(struct Qdisc *sch, struct cake_tin_data **t,
1571 struct cake_sched_data *q = qdisc_priv(sch); 1583 struct cake_sched_data *q = qdisc_priv(sch);
1572 struct tcf_proto *filter; 1584 struct tcf_proto *filter;
1573 struct tcf_result res; 1585 struct tcf_result res;
1574 u32 flow = 0; 1586 u16 flow = 0, host = 0;
1575 int result; 1587 int result;
1576 1588
1577 filter = rcu_dereference_bh(q->filter_list); 1589 filter = rcu_dereference_bh(q->filter_list);
@@ -1595,10 +1607,12 @@ static u32 cake_classify(struct Qdisc *sch, struct cake_tin_data **t,
1595#endif 1607#endif
1596 if (TC_H_MIN(res.classid) <= CAKE_QUEUES) 1608 if (TC_H_MIN(res.classid) <= CAKE_QUEUES)
1597 flow = TC_H_MIN(res.classid); 1609 flow = TC_H_MIN(res.classid);
1610 if (TC_H_MAJ(res.classid) <= (CAKE_QUEUES << 16))
1611 host = TC_H_MAJ(res.classid) >> 16;
1598 } 1612 }
1599hash: 1613hash:
1600 *t = cake_select_tin(sch, skb); 1614 *t = cake_select_tin(sch, skb);
1601 return flow ?: cake_hash(*t, skb, flow_mode) + 1; 1615 return cake_hash(*t, skb, flow_mode, flow, host) + 1;
1602} 1616}
1603 1617
1604static void cake_reconfigure(struct Qdisc *sch); 1618static void cake_reconfigure(struct Qdisc *sch);
diff --git a/net/sctp/proc.c b/net/sctp/proc.c
index ef5c9a82d4e8..a644292f9faf 100644
--- a/net/sctp/proc.c
+++ b/net/sctp/proc.c
@@ -215,7 +215,6 @@ static const struct seq_operations sctp_eps_ops = {
215struct sctp_ht_iter { 215struct sctp_ht_iter {
216 struct seq_net_private p; 216 struct seq_net_private p;
217 struct rhashtable_iter hti; 217 struct rhashtable_iter hti;
218 int start_fail;
219}; 218};
220 219
221static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos) 220static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
@@ -224,7 +223,6 @@ static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
224 223
225 sctp_transport_walk_start(&iter->hti); 224 sctp_transport_walk_start(&iter->hti);
226 225
227 iter->start_fail = 0;
228 return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos); 226 return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos);
229} 227}
230 228
@@ -232,8 +230,6 @@ static void sctp_transport_seq_stop(struct seq_file *seq, void *v)
232{ 230{
233 struct sctp_ht_iter *iter = seq->private; 231 struct sctp_ht_iter *iter = seq->private;
234 232
235 if (iter->start_fail)
236 return;
237 sctp_transport_walk_stop(&iter->hti); 233 sctp_transport_walk_stop(&iter->hti);
238} 234}
239 235
@@ -264,8 +260,6 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
264 } 260 }
265 261
266 transport = (struct sctp_transport *)v; 262 transport = (struct sctp_transport *)v;
267 if (!sctp_transport_hold(transport))
268 return 0;
269 assoc = transport->asoc; 263 assoc = transport->asoc;
270 epb = &assoc->base; 264 epb = &assoc->base;
271 sk = epb->sk; 265 sk = epb->sk;
@@ -322,8 +316,6 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
322 } 316 }
323 317
324 transport = (struct sctp_transport *)v; 318 transport = (struct sctp_transport *)v;
325 if (!sctp_transport_hold(transport))
326 return 0;
327 assoc = transport->asoc; 319 assoc = transport->asoc;
328 320
329 list_for_each_entry_rcu(tsp, &assoc->peer.transport_addr_list, 321 list_for_each_entry_rcu(tsp, &assoc->peer.transport_addr_list,
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index e96b15a66aba..f73e9d38d5ba 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2658,20 +2658,23 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
2658 } 2658 }
2659 2659
2660 if (params->spp_flags & SPP_IPV6_FLOWLABEL) { 2660 if (params->spp_flags & SPP_IPV6_FLOWLABEL) {
2661 if (trans && trans->ipaddr.sa.sa_family == AF_INET6) { 2661 if (trans) {
2662 trans->flowlabel = params->spp_ipv6_flowlabel & 2662 if (trans->ipaddr.sa.sa_family == AF_INET6) {
2663 SCTP_FLOWLABEL_VAL_MASK;
2664 trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
2665 } else if (asoc) {
2666 list_for_each_entry(trans,
2667 &asoc->peer.transport_addr_list,
2668 transports) {
2669 if (trans->ipaddr.sa.sa_family != AF_INET6)
2670 continue;
2671 trans->flowlabel = params->spp_ipv6_flowlabel & 2663 trans->flowlabel = params->spp_ipv6_flowlabel &
2672 SCTP_FLOWLABEL_VAL_MASK; 2664 SCTP_FLOWLABEL_VAL_MASK;
2673 trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK; 2665 trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
2674 } 2666 }
2667 } else if (asoc) {
2668 struct sctp_transport *t;
2669
2670 list_for_each_entry(t, &asoc->peer.transport_addr_list,
2671 transports) {
2672 if (t->ipaddr.sa.sa_family != AF_INET6)
2673 continue;
2674 t->flowlabel = params->spp_ipv6_flowlabel &
2675 SCTP_FLOWLABEL_VAL_MASK;
2676 t->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
2677 }
2675 asoc->flowlabel = params->spp_ipv6_flowlabel & 2678 asoc->flowlabel = params->spp_ipv6_flowlabel &
2676 SCTP_FLOWLABEL_VAL_MASK; 2679 SCTP_FLOWLABEL_VAL_MASK;
2677 asoc->flowlabel |= SCTP_FLOWLABEL_SET_MASK; 2680 asoc->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
@@ -2687,12 +2690,13 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
2687 trans->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; 2690 trans->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
2688 trans->dscp |= SCTP_DSCP_SET_MASK; 2691 trans->dscp |= SCTP_DSCP_SET_MASK;
2689 } else if (asoc) { 2692 } else if (asoc) {
2690 list_for_each_entry(trans, 2693 struct sctp_transport *t;
2691 &asoc->peer.transport_addr_list, 2694
2695 list_for_each_entry(t, &asoc->peer.transport_addr_list,
2692 transports) { 2696 transports) {
2693 trans->dscp = params->spp_dscp & 2697 t->dscp = params->spp_dscp &
2694 SCTP_DSCP_VAL_MASK; 2698 SCTP_DSCP_VAL_MASK;
2695 trans->dscp |= SCTP_DSCP_SET_MASK; 2699 t->dscp |= SCTP_DSCP_SET_MASK;
2696 } 2700 }
2697 asoc->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; 2701 asoc->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
2698 asoc->dscp |= SCTP_DSCP_SET_MASK; 2702 asoc->dscp |= SCTP_DSCP_SET_MASK;
@@ -5005,9 +5009,14 @@ struct sctp_transport *sctp_transport_get_next(struct net *net,
5005 break; 5009 break;
5006 } 5010 }
5007 5011
5012 if (!sctp_transport_hold(t))
5013 continue;
5014
5008 if (net_eq(sock_net(t->asoc->base.sk), net) && 5015 if (net_eq(sock_net(t->asoc->base.sk), net) &&
5009 t->asoc->peer.primary_path == t) 5016 t->asoc->peer.primary_path == t)
5010 break; 5017 break;
5018
5019 sctp_transport_put(t);
5011 } 5020 }
5012 5021
5013 return t; 5022 return t;
@@ -5017,13 +5026,18 @@ struct sctp_transport *sctp_transport_get_idx(struct net *net,
5017 struct rhashtable_iter *iter, 5026 struct rhashtable_iter *iter,
5018 int pos) 5027 int pos)
5019{ 5028{
5020 void *obj = SEQ_START_TOKEN; 5029 struct sctp_transport *t;
5021 5030
5022 while (pos && (obj = sctp_transport_get_next(net, iter)) && 5031 if (!pos)
5023 !IS_ERR(obj)) 5032 return SEQ_START_TOKEN;
5024 pos--;
5025 5033
5026 return obj; 5034 while ((t = sctp_transport_get_next(net, iter)) && !IS_ERR(t)) {
5035 if (!--pos)
5036 break;
5037 sctp_transport_put(t);
5038 }
5039
5040 return t;
5027} 5041}
5028 5042
5029int sctp_for_each_endpoint(int (*cb)(struct sctp_endpoint *, void *), 5043int sctp_for_each_endpoint(int (*cb)(struct sctp_endpoint *, void *),
@@ -5082,8 +5096,6 @@ again:
5082 5096
5083 tsp = sctp_transport_get_idx(net, &hti, *pos + 1); 5097 tsp = sctp_transport_get_idx(net, &hti, *pos + 1);
5084 for (; !IS_ERR_OR_NULL(tsp); tsp = sctp_transport_get_next(net, &hti)) { 5098 for (; !IS_ERR_OR_NULL(tsp); tsp = sctp_transport_get_next(net, &hti)) {
5085 if (!sctp_transport_hold(tsp))
5086 continue;
5087 ret = cb(tsp, p); 5099 ret = cb(tsp, p);
5088 if (ret) 5100 if (ret)
5089 break; 5101 break;
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 9ee6cfea56dd..d8026543bf4c 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -51,12 +51,12 @@ const char tipc_bclink_name[] = "broadcast-link";
51 * struct tipc_bc_base - base structure for keeping broadcast send state 51 * struct tipc_bc_base - base structure for keeping broadcast send state
52 * @link: broadcast send link structure 52 * @link: broadcast send link structure
53 * @inputq: data input queue; will only carry SOCK_WAKEUP messages 53 * @inputq: data input queue; will only carry SOCK_WAKEUP messages
54 * @dest: array keeping number of reachable destinations per bearer 54 * @dests: array keeping number of reachable destinations per bearer
55 * @primary_bearer: a bearer having links to all broadcast destinations, if any 55 * @primary_bearer: a bearer having links to all broadcast destinations, if any
56 * @bcast_support: indicates if primary bearer, if any, supports broadcast 56 * @bcast_support: indicates if primary bearer, if any, supports broadcast
57 * @rcast_support: indicates if all peer nodes support replicast 57 * @rcast_support: indicates if all peer nodes support replicast
58 * @rc_ratio: dest count as percentage of cluster size where send method changes 58 * @rc_ratio: dest count as percentage of cluster size where send method changes
59 * @bc_threshold: calculated drom rc_ratio; if dests > threshold use broadcast 59 * @bc_threshold: calculated from rc_ratio; if dests > threshold use broadcast
60 */ 60 */
61struct tipc_bc_base { 61struct tipc_bc_base {
62 struct tipc_link *link; 62 struct tipc_link *link;
diff --git a/net/tipc/diag.c b/net/tipc/diag.c
index aaabb0b776dd..73137f4aeb68 100644
--- a/net/tipc/diag.c
+++ b/net/tipc/diag.c
@@ -84,7 +84,9 @@ static int tipc_sock_diag_handler_dump(struct sk_buff *skb,
84 84
85 if (h->nlmsg_flags & NLM_F_DUMP) { 85 if (h->nlmsg_flags & NLM_F_DUMP) {
86 struct netlink_dump_control c = { 86 struct netlink_dump_control c = {
87 .start = tipc_dump_start,
87 .dump = tipc_diag_dump, 88 .dump = tipc_diag_dump,
89 .done = tipc_dump_done,
88 }; 90 };
89 netlink_dump_start(net->diag_nlsk, skb, h, &c); 91 netlink_dump_start(net->diag_nlsk, skb, h, &c);
90 return 0; 92 return 0;
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 88f027b502f6..66d5b2c5987a 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -980,20 +980,17 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb)
980 980
981struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port) 981struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port)
982{ 982{
983 u64 value = (u64)node << 32 | port;
984 struct tipc_dest *dst; 983 struct tipc_dest *dst;
985 984
986 list_for_each_entry(dst, l, list) { 985 list_for_each_entry(dst, l, list) {
987 if (dst->value != value) 986 if (dst->node == node && dst->port == port)
988 continue; 987 return dst;
989 return dst;
990 } 988 }
991 return NULL; 989 return NULL;
992} 990}
993 991
994bool tipc_dest_push(struct list_head *l, u32 node, u32 port) 992bool tipc_dest_push(struct list_head *l, u32 node, u32 port)
995{ 993{
996 u64 value = (u64)node << 32 | port;
997 struct tipc_dest *dst; 994 struct tipc_dest *dst;
998 995
999 if (tipc_dest_find(l, node, port)) 996 if (tipc_dest_find(l, node, port))
@@ -1002,7 +999,8 @@ bool tipc_dest_push(struct list_head *l, u32 node, u32 port)
1002 dst = kmalloc(sizeof(*dst), GFP_ATOMIC); 999 dst = kmalloc(sizeof(*dst), GFP_ATOMIC);
1003 if (unlikely(!dst)) 1000 if (unlikely(!dst))
1004 return false; 1001 return false;
1005 dst->value = value; 1002 dst->node = node;
1003 dst->port = port;
1006 list_add(&dst->list, l); 1004 list_add(&dst->list, l);
1007 return true; 1005 return true;
1008} 1006}
diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h
index 0febba41da86..892bd750b85f 100644
--- a/net/tipc/name_table.h
+++ b/net/tipc/name_table.h
@@ -133,13 +133,8 @@ void tipc_nametbl_stop(struct net *net);
133 133
134struct tipc_dest { 134struct tipc_dest {
135 struct list_head list; 135 struct list_head list;
136 union { 136 u32 port;
137 struct { 137 u32 node;
138 u32 port;
139 u32 node;
140 };
141 u64 value;
142 };
143}; 138};
144 139
145struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port); 140struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port);
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index 6ff2254088f6..99ee419210ba 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -167,7 +167,9 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
167 }, 167 },
168 { 168 {
169 .cmd = TIPC_NL_SOCK_GET, 169 .cmd = TIPC_NL_SOCK_GET,
170 .start = tipc_dump_start,
170 .dumpit = tipc_nl_sk_dump, 171 .dumpit = tipc_nl_sk_dump,
172 .done = tipc_dump_done,
171 .policy = tipc_nl_policy, 173 .policy = tipc_nl_policy,
172 }, 174 },
173 { 175 {
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index a2f76743c73a..6376467e78f8 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -185,6 +185,10 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
185 return -ENOMEM; 185 return -ENOMEM;
186 186
187 buf->sk = msg->dst_sk; 187 buf->sk = msg->dst_sk;
188 if (__tipc_dump_start(&cb, msg->net)) {
189 kfree_skb(buf);
190 return -ENOMEM;
191 }
188 192
189 do { 193 do {
190 int rem; 194 int rem;
@@ -216,6 +220,7 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
216 err = 0; 220 err = 0;
217 221
218err_out: 222err_out:
223 tipc_dump_done(&cb);
219 kfree_skb(buf); 224 kfree_skb(buf);
220 225
221 if (err == -EMSGSIZE) { 226 if (err == -EMSGSIZE) {
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index c1e93c9515bc..3f03ddd0e35b 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -576,6 +576,7 @@ static int tipc_release(struct socket *sock)
576 sk_stop_timer(sk, &sk->sk_timer); 576 sk_stop_timer(sk, &sk->sk_timer);
577 tipc_sk_remove(tsk); 577 tipc_sk_remove(tsk);
578 578
579 sock_orphan(sk);
579 /* Reject any messages that accumulated in backlog queue */ 580 /* Reject any messages that accumulated in backlog queue */
580 release_sock(sk); 581 release_sock(sk);
581 tipc_dest_list_purge(&tsk->cong_links); 582 tipc_dest_list_purge(&tsk->cong_links);
@@ -2672,6 +2673,8 @@ void tipc_sk_reinit(struct net *net)
2672 2673
2673 rhashtable_walk_stop(&iter); 2674 rhashtable_walk_stop(&iter);
2674 } while (tsk == ERR_PTR(-EAGAIN)); 2675 } while (tsk == ERR_PTR(-EAGAIN));
2676
2677 rhashtable_walk_exit(&iter);
2675} 2678}
2676 2679
2677static struct tipc_sock *tipc_sk_lookup(struct net *net, u32 portid) 2680static struct tipc_sock *tipc_sk_lookup(struct net *net, u32 portid)
@@ -3227,45 +3230,74 @@ int tipc_nl_sk_walk(struct sk_buff *skb, struct netlink_callback *cb,
3227 struct netlink_callback *cb, 3230 struct netlink_callback *cb,
3228 struct tipc_sock *tsk)) 3231 struct tipc_sock *tsk))
3229{ 3232{
3230 struct net *net = sock_net(skb->sk); 3233 struct rhashtable_iter *iter = (void *)cb->args[4];
3231 struct tipc_net *tn = tipc_net(net);
3232 const struct bucket_table *tbl;
3233 u32 prev_portid = cb->args[1];
3234 u32 tbl_id = cb->args[0];
3235 struct rhash_head *pos;
3236 struct tipc_sock *tsk; 3234 struct tipc_sock *tsk;
3237 int err; 3235 int err;
3238 3236
3239 rcu_read_lock(); 3237 rhashtable_walk_start(iter);
3240 tbl = rht_dereference_rcu((&tn->sk_rht)->tbl, &tn->sk_rht); 3238 while ((tsk = rhashtable_walk_next(iter)) != NULL) {
3241 for (; tbl_id < tbl->size; tbl_id++) { 3239 if (IS_ERR(tsk)) {
3242 rht_for_each_entry_rcu(tsk, pos, tbl, tbl_id, node) { 3240 err = PTR_ERR(tsk);
3243 spin_lock_bh(&tsk->sk.sk_lock.slock); 3241 if (err == -EAGAIN) {
3244 if (prev_portid && prev_portid != tsk->portid) { 3242 err = 0;
3245 spin_unlock_bh(&tsk->sk.sk_lock.slock);
3246 continue; 3243 continue;
3247 } 3244 }
3245 break;
3246 }
3248 3247
3249 err = skb_handler(skb, cb, tsk); 3248 sock_hold(&tsk->sk);
3250 if (err) { 3249 rhashtable_walk_stop(iter);
3251 prev_portid = tsk->portid; 3250 lock_sock(&tsk->sk);
3252 spin_unlock_bh(&tsk->sk.sk_lock.slock); 3251 err = skb_handler(skb, cb, tsk);
3253 goto out; 3252 if (err) {
3254 } 3253 release_sock(&tsk->sk);
3255 3254 sock_put(&tsk->sk);
3256 prev_portid = 0; 3255 goto out;
3257 spin_unlock_bh(&tsk->sk.sk_lock.slock);
3258 } 3256 }
3257 release_sock(&tsk->sk);
3258 rhashtable_walk_start(iter);
3259 sock_put(&tsk->sk);
3259 } 3260 }
3261 rhashtable_walk_stop(iter);
3260out: 3262out:
3261 rcu_read_unlock();
3262 cb->args[0] = tbl_id;
3263 cb->args[1] = prev_portid;
3264
3265 return skb->len; 3263 return skb->len;
3266} 3264}
3267EXPORT_SYMBOL(tipc_nl_sk_walk); 3265EXPORT_SYMBOL(tipc_nl_sk_walk);
3268 3266
3267int tipc_dump_start(struct netlink_callback *cb)
3268{
3269 return __tipc_dump_start(cb, sock_net(cb->skb->sk));
3270}
3271EXPORT_SYMBOL(tipc_dump_start);
3272
3273int __tipc_dump_start(struct netlink_callback *cb, struct net *net)
3274{
3275 /* tipc_nl_name_table_dump() uses cb->args[0...3]. */
3276 struct rhashtable_iter *iter = (void *)cb->args[4];
3277 struct tipc_net *tn = tipc_net(net);
3278
3279 if (!iter) {
3280 iter = kmalloc(sizeof(*iter), GFP_KERNEL);
3281 if (!iter)
3282 return -ENOMEM;
3283
3284 cb->args[4] = (long)iter;
3285 }
3286
3287 rhashtable_walk_enter(&tn->sk_rht, iter);
3288 return 0;
3289}
3290
3291int tipc_dump_done(struct netlink_callback *cb)
3292{
3293 struct rhashtable_iter *hti = (void *)cb->args[4];
3294
3295 rhashtable_walk_exit(hti);
3296 kfree(hti);
3297 return 0;
3298}
3299EXPORT_SYMBOL(tipc_dump_done);
3300
3269int tipc_sk_fill_sock_diag(struct sk_buff *skb, struct netlink_callback *cb, 3301int tipc_sk_fill_sock_diag(struct sk_buff *skb, struct netlink_callback *cb,
3270 struct tipc_sock *tsk, u32 sk_filter_state, 3302 struct tipc_sock *tsk, u32 sk_filter_state,
3271 u64 (*tipc_diag_gen_cookie)(struct sock *sk)) 3303 u64 (*tipc_diag_gen_cookie)(struct sock *sk))
diff --git a/net/tipc/socket.h b/net/tipc/socket.h
index aff9b2ae5a1f..5e575f205afe 100644
--- a/net/tipc/socket.h
+++ b/net/tipc/socket.h
@@ -68,4 +68,7 @@ int tipc_nl_sk_walk(struct sk_buff *skb, struct netlink_callback *cb,
68 int (*skb_handler)(struct sk_buff *skb, 68 int (*skb_handler)(struct sk_buff *skb,
69 struct netlink_callback *cb, 69 struct netlink_callback *cb,
70 struct tipc_sock *tsk)); 70 struct tipc_sock *tsk));
71int tipc_dump_start(struct netlink_callback *cb);
72int __tipc_dump_start(struct netlink_callback *cb, struct net *net);
73int tipc_dump_done(struct netlink_callback *cb);
71#endif 74#endif
diff --git a/net/tipc/topsrv.c b/net/tipc/topsrv.c
index c8e34ef22c30..2627b5d812e9 100644
--- a/net/tipc/topsrv.c
+++ b/net/tipc/topsrv.c
@@ -313,8 +313,8 @@ static void tipc_conn_send_work(struct work_struct *work)
313 conn_put(con); 313 conn_put(con);
314} 314}
315 315
316/* tipc_conn_queue_evt() - interrupt level call from a subscription instance 316/* tipc_topsrv_queue_evt() - interrupt level call from a subscription instance
317 * The queued work is launched into tipc_send_work()->tipc_send_to_sock() 317 * The queued work is launched into tipc_conn_send_work()->tipc_conn_send_to_sock()
318 */ 318 */
319void tipc_topsrv_queue_evt(struct net *net, int conid, 319void tipc_topsrv_queue_evt(struct net *net, int conid,
320 u32 event, struct tipc_event *evt) 320 u32 event, struct tipc_event *evt)
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 93c0c225ab34..180b6640e531 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -213,9 +213,14 @@ static void tls_write_space(struct sock *sk)
213{ 213{
214 struct tls_context *ctx = tls_get_ctx(sk); 214 struct tls_context *ctx = tls_get_ctx(sk);
215 215
216 /* We are already sending pages, ignore notification */ 216 /* If in_tcp_sendpages call lower protocol write space handler
217 if (ctx->in_tcp_sendpages) 217 * to ensure we wake up any waiting operations there. For example
218 * if do_tcp_sendpages where to call sk_wait_event.
219 */
220 if (ctx->in_tcp_sendpages) {
221 ctx->sk_write_space(sk);
218 return; 222 return;
223 }
219 224
220 if (!sk->sk_write_pending && tls_is_pending_closed_record(ctx)) { 225 if (!sk->sk_write_pending && tls_is_pending_closed_record(ctx)) {
221 gfp_t sk_allocation = sk->sk_allocation; 226 gfp_t sk_allocation = sk->sk_allocation;
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 52fbe727d7c1..e28a6ff25d96 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -125,6 +125,9 @@ static int alloc_encrypted_sg(struct sock *sk, int len)
125 &ctx->sg_encrypted_num_elem, 125 &ctx->sg_encrypted_num_elem,
126 &ctx->sg_encrypted_size, 0); 126 &ctx->sg_encrypted_size, 0);
127 127
128 if (rc == -ENOSPC)
129 ctx->sg_encrypted_num_elem = ARRAY_SIZE(ctx->sg_encrypted_data);
130
128 return rc; 131 return rc;
129} 132}
130 133
@@ -138,6 +141,9 @@ static int alloc_plaintext_sg(struct sock *sk, int len)
138 &ctx->sg_plaintext_num_elem, &ctx->sg_plaintext_size, 141 &ctx->sg_plaintext_num_elem, &ctx->sg_plaintext_size,
139 tls_ctx->pending_open_record_frags); 142 tls_ctx->pending_open_record_frags);
140 143
144 if (rc == -ENOSPC)
145 ctx->sg_plaintext_num_elem = ARRAY_SIZE(ctx->sg_plaintext_data);
146
141 return rc; 147 return rc;
142} 148}
143 149
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 5fb9b7dd9831..4b8ec659e797 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -669,13 +669,13 @@ static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
669 goto nla_put_failure; 669 goto nla_put_failure;
670 670
671 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, 671 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
672 rule->wmm_rule->client[j].cw_min) || 672 rule->wmm_rule.client[j].cw_min) ||
673 nla_put_u16(msg, NL80211_WMMR_CW_MAX, 673 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
674 rule->wmm_rule->client[j].cw_max) || 674 rule->wmm_rule.client[j].cw_max) ||
675 nla_put_u8(msg, NL80211_WMMR_AIFSN, 675 nla_put_u8(msg, NL80211_WMMR_AIFSN,
676 rule->wmm_rule->client[j].aifsn) || 676 rule->wmm_rule.client[j].aifsn) ||
677 nla_put_u8(msg, NL80211_WMMR_TXOP, 677 nla_put_u16(msg, NL80211_WMMR_TXOP,
678 rule->wmm_rule->client[j].cot)) 678 rule->wmm_rule.client[j].cot))
679 goto nla_put_failure; 679 goto nla_put_failure;
680 680
681 nla_nest_end(msg, nl_wmm_rule); 681 nla_nest_end(msg, nl_wmm_rule);
@@ -766,9 +766,9 @@ static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
766 766
767 if (large) { 767 if (large) {
768 const struct ieee80211_reg_rule *rule = 768 const struct ieee80211_reg_rule *rule =
769 freq_reg_info(wiphy, chan->center_freq); 769 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
770 770
771 if (!IS_ERR(rule) && rule->wmm_rule) { 771 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
772 if (nl80211_msg_put_wmm_rules(msg, rule)) 772 if (nl80211_msg_put_wmm_rules(msg, rule))
773 goto nla_put_failure; 773 goto nla_put_failure;
774 } 774 }
@@ -12205,6 +12205,7 @@ static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12205 return -EOPNOTSUPP; 12205 return -EOPNOTSUPP;
12206 12206
12207 if (!info->attrs[NL80211_ATTR_MDID] || 12207 if (!info->attrs[NL80211_ATTR_MDID] ||
12208 !info->attrs[NL80211_ATTR_IE] ||
12208 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) 12209 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
12209 return -EINVAL; 12210 return -EINVAL;
12210 12211
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 4fc66a117b7d..2f702adf2912 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -425,36 +425,23 @@ static const struct ieee80211_regdomain *
425reg_copy_regd(const struct ieee80211_regdomain *src_regd) 425reg_copy_regd(const struct ieee80211_regdomain *src_regd)
426{ 426{
427 struct ieee80211_regdomain *regd; 427 struct ieee80211_regdomain *regd;
428 int size_of_regd, size_of_wmms; 428 int size_of_regd;
429 unsigned int i; 429 unsigned int i;
430 struct ieee80211_wmm_rule *d_wmm, *s_wmm;
431 430
432 size_of_regd = 431 size_of_regd =
433 sizeof(struct ieee80211_regdomain) + 432 sizeof(struct ieee80211_regdomain) +
434 src_regd->n_reg_rules * sizeof(struct ieee80211_reg_rule); 433 src_regd->n_reg_rules * sizeof(struct ieee80211_reg_rule);
435 size_of_wmms = src_regd->n_wmm_rules *
436 sizeof(struct ieee80211_wmm_rule);
437 434
438 regd = kzalloc(size_of_regd + size_of_wmms, GFP_KERNEL); 435 regd = kzalloc(size_of_regd, GFP_KERNEL);
439 if (!regd) 436 if (!regd)
440 return ERR_PTR(-ENOMEM); 437 return ERR_PTR(-ENOMEM);
441 438
442 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); 439 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
443 440
444 d_wmm = (struct ieee80211_wmm_rule *)((u8 *)regd + size_of_regd); 441 for (i = 0; i < src_regd->n_reg_rules; i++)
445 s_wmm = (struct ieee80211_wmm_rule *)((u8 *)src_regd + size_of_regd);
446 memcpy(d_wmm, s_wmm, size_of_wmms);
447
448 for (i = 0; i < src_regd->n_reg_rules; i++) {
449 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i], 442 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
450 sizeof(struct ieee80211_reg_rule)); 443 sizeof(struct ieee80211_reg_rule));
451 if (!src_regd->reg_rules[i].wmm_rule)
452 continue;
453 444
454 regd->reg_rules[i].wmm_rule = d_wmm +
455 (src_regd->reg_rules[i].wmm_rule - s_wmm) /
456 sizeof(struct ieee80211_wmm_rule);
457 }
458 return regd; 445 return regd;
459} 446}
460 447
@@ -860,9 +847,10 @@ static bool valid_regdb(const u8 *data, unsigned int size)
860 return true; 847 return true;
861} 848}
862 849
863static void set_wmm_rule(struct ieee80211_wmm_rule *rule, 850static void set_wmm_rule(struct ieee80211_reg_rule *rrule,
864 struct fwdb_wmm_rule *wmm) 851 struct fwdb_wmm_rule *wmm)
865{ 852{
853 struct ieee80211_wmm_rule *rule = &rrule->wmm_rule;
866 unsigned int i; 854 unsigned int i;
867 855
868 for (i = 0; i < IEEE80211_NUM_ACS; i++) { 856 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
@@ -876,11 +864,13 @@ static void set_wmm_rule(struct ieee80211_wmm_rule *rule,
876 rule->ap[i].aifsn = wmm->ap[i].aifsn; 864 rule->ap[i].aifsn = wmm->ap[i].aifsn;
877 rule->ap[i].cot = 1000 * be16_to_cpu(wmm->ap[i].cot); 865 rule->ap[i].cot = 1000 * be16_to_cpu(wmm->ap[i].cot);
878 } 866 }
867
868 rrule->has_wmm = true;
879} 869}
880 870
881static int __regdb_query_wmm(const struct fwdb_header *db, 871static int __regdb_query_wmm(const struct fwdb_header *db,
882 const struct fwdb_country *country, int freq, 872 const struct fwdb_country *country, int freq,
883 u32 *dbptr, struct ieee80211_wmm_rule *rule) 873 struct ieee80211_reg_rule *rule)
884{ 874{
885 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; 875 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2;
886 struct fwdb_collection *coll = (void *)((u8 *)db + ptr); 876 struct fwdb_collection *coll = (void *)((u8 *)db + ptr);
@@ -901,8 +891,6 @@ static int __regdb_query_wmm(const struct fwdb_header *db,
901 wmm_ptr = be16_to_cpu(rrule->wmm_ptr) << 2; 891 wmm_ptr = be16_to_cpu(rrule->wmm_ptr) << 2;
902 wmm = (void *)((u8 *)db + wmm_ptr); 892 wmm = (void *)((u8 *)db + wmm_ptr);
903 set_wmm_rule(rule, wmm); 893 set_wmm_rule(rule, wmm);
904 if (dbptr)
905 *dbptr = wmm_ptr;
906 return 0; 894 return 0;
907 } 895 }
908 } 896 }
@@ -910,8 +898,7 @@ static int __regdb_query_wmm(const struct fwdb_header *db,
910 return -ENODATA; 898 return -ENODATA;
911} 899}
912 900
913int reg_query_regdb_wmm(char *alpha2, int freq, u32 *dbptr, 901int reg_query_regdb_wmm(char *alpha2, int freq, struct ieee80211_reg_rule *rule)
914 struct ieee80211_wmm_rule *rule)
915{ 902{
916 const struct fwdb_header *hdr = regdb; 903 const struct fwdb_header *hdr = regdb;
917 const struct fwdb_country *country; 904 const struct fwdb_country *country;
@@ -925,8 +912,7 @@ int reg_query_regdb_wmm(char *alpha2, int freq, u32 *dbptr,
925 country = &hdr->country[0]; 912 country = &hdr->country[0];
926 while (country->coll_ptr) { 913 while (country->coll_ptr) {
927 if (alpha2_equal(alpha2, country->alpha2)) 914 if (alpha2_equal(alpha2, country->alpha2))
928 return __regdb_query_wmm(regdb, country, freq, dbptr, 915 return __regdb_query_wmm(regdb, country, freq, rule);
929 rule);
930 916
931 country++; 917 country++;
932 } 918 }
@@ -935,32 +921,13 @@ int reg_query_regdb_wmm(char *alpha2, int freq, u32 *dbptr,
935} 921}
936EXPORT_SYMBOL(reg_query_regdb_wmm); 922EXPORT_SYMBOL(reg_query_regdb_wmm);
937 923
938struct wmm_ptrs {
939 struct ieee80211_wmm_rule *rule;
940 u32 ptr;
941};
942
943static struct ieee80211_wmm_rule *find_wmm_ptr(struct wmm_ptrs *wmm_ptrs,
944 u32 wmm_ptr, int n_wmms)
945{
946 int i;
947
948 for (i = 0; i < n_wmms; i++) {
949 if (wmm_ptrs[i].ptr == wmm_ptr)
950 return wmm_ptrs[i].rule;
951 }
952 return NULL;
953}
954
955static int regdb_query_country(const struct fwdb_header *db, 924static int regdb_query_country(const struct fwdb_header *db,
956 const struct fwdb_country *country) 925 const struct fwdb_country *country)
957{ 926{
958 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; 927 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2;
959 struct fwdb_collection *coll = (void *)((u8 *)db + ptr); 928 struct fwdb_collection *coll = (void *)((u8 *)db + ptr);
960 struct ieee80211_regdomain *regdom; 929 struct ieee80211_regdomain *regdom;
961 struct ieee80211_regdomain *tmp_rd; 930 unsigned int size_of_regd, i;
962 unsigned int size_of_regd, i, n_wmms = 0;
963 struct wmm_ptrs *wmm_ptrs;
964 931
965 size_of_regd = sizeof(struct ieee80211_regdomain) + 932 size_of_regd = sizeof(struct ieee80211_regdomain) +
966 coll->n_rules * sizeof(struct ieee80211_reg_rule); 933 coll->n_rules * sizeof(struct ieee80211_reg_rule);
@@ -969,12 +936,6 @@ static int regdb_query_country(const struct fwdb_header *db,
969 if (!regdom) 936 if (!regdom)
970 return -ENOMEM; 937 return -ENOMEM;
971 938
972 wmm_ptrs = kcalloc(coll->n_rules, sizeof(*wmm_ptrs), GFP_KERNEL);
973 if (!wmm_ptrs) {
974 kfree(regdom);
975 return -ENOMEM;
976 }
977
978 regdom->n_reg_rules = coll->n_rules; 939 regdom->n_reg_rules = coll->n_rules;
979 regdom->alpha2[0] = country->alpha2[0]; 940 regdom->alpha2[0] = country->alpha2[0];
980 regdom->alpha2[1] = country->alpha2[1]; 941 regdom->alpha2[1] = country->alpha2[1];
@@ -1013,37 +974,11 @@ static int regdb_query_country(const struct fwdb_header *db,
1013 1000 * be16_to_cpu(rule->cac_timeout); 974 1000 * be16_to_cpu(rule->cac_timeout);
1014 if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) { 975 if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) {
1015 u32 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; 976 u32 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2;
1016 struct ieee80211_wmm_rule *wmm_pos = 977 struct fwdb_wmm_rule *wmm = (void *)((u8 *)db + wmm_ptr);
1017 find_wmm_ptr(wmm_ptrs, wmm_ptr, n_wmms);
1018 struct fwdb_wmm_rule *wmm;
1019 struct ieee80211_wmm_rule *wmm_rule;
1020
1021 if (wmm_pos) {
1022 rrule->wmm_rule = wmm_pos;
1023 continue;
1024 }
1025 wmm = (void *)((u8 *)db + wmm_ptr);
1026 tmp_rd = krealloc(regdom, size_of_regd + (n_wmms + 1) *
1027 sizeof(struct ieee80211_wmm_rule),
1028 GFP_KERNEL);
1029
1030 if (!tmp_rd) {
1031 kfree(regdom);
1032 kfree(wmm_ptrs);
1033 return -ENOMEM;
1034 }
1035 regdom = tmp_rd;
1036
1037 wmm_rule = (struct ieee80211_wmm_rule *)
1038 ((u8 *)regdom + size_of_regd + n_wmms *
1039 sizeof(struct ieee80211_wmm_rule));
1040 978
1041 set_wmm_rule(wmm_rule, wmm); 979 set_wmm_rule(rrule, wmm);
1042 wmm_ptrs[n_wmms].ptr = wmm_ptr;
1043 wmm_ptrs[n_wmms++].rule = wmm_rule;
1044 } 980 }
1045 } 981 }
1046 kfree(wmm_ptrs);
1047 982
1048 return reg_schedule_apply(regdom); 983 return reg_schedule_apply(regdom);
1049} 984}
diff --git a/net/wireless/util.c b/net/wireless/util.c
index e0825a019e9f..959ed3acd240 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -1456,7 +1456,7 @@ bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
1456 u8 *op_class) 1456 u8 *op_class)
1457{ 1457{
1458 u8 vht_opclass; 1458 u8 vht_opclass;
1459 u16 freq = chandef->center_freq1; 1459 u32 freq = chandef->center_freq1;
1460 1460
1461 if (freq >= 2412 && freq <= 2472) { 1461 if (freq >= 2412 && freq <= 2472) {
1462 if (chandef->width > NL80211_CHAN_WIDTH_40) 1462 if (chandef->width > NL80211_CHAN_WIDTH_40)
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index 911ca6d3cb5a..bfe2dbea480b 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -74,14 +74,14 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
74 return 0; 74 return 0;
75 75
76 if (!dev->netdev_ops->ndo_bpf || !dev->netdev_ops->ndo_xsk_async_xmit) 76 if (!dev->netdev_ops->ndo_bpf || !dev->netdev_ops->ndo_xsk_async_xmit)
77 return force_zc ? -ENOTSUPP : 0; /* fail or fallback */ 77 return force_zc ? -EOPNOTSUPP : 0; /* fail or fallback */
78 78
79 bpf.command = XDP_QUERY_XSK_UMEM; 79 bpf.command = XDP_QUERY_XSK_UMEM;
80 80
81 rtnl_lock(); 81 rtnl_lock();
82 err = xdp_umem_query(dev, queue_id); 82 err = xdp_umem_query(dev, queue_id);
83 if (err) { 83 if (err) {
84 err = err < 0 ? -ENOTSUPP : -EBUSY; 84 err = err < 0 ? -EOPNOTSUPP : -EBUSY;
85 goto err_rtnl_unlock; 85 goto err_rtnl_unlock;
86 } 86 }
87 87
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 7c98f60e2266..ce53639a864a 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -153,18 +153,14 @@ cc-fullversion = $(shell $(CONFIG_SHELL) \
153# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) 153# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
154cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4)) 154cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4))
155 155
156# cc-if-fullversion
157# Usage: EXTRA_CFLAGS += $(call cc-if-fullversion, -lt, 040502, -O1)
158cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo $(4))
159
160# cc-ldoption 156# cc-ldoption
161# Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) 157# Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
162cc-ldoption = $(call try-run,\ 158cc-ldoption = $(call try-run,\
163 $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) 159 $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
164 160
165# ld-option 161# ld-option
166# Usage: LDFLAGS += $(call ld-option, -X, -Y) 162# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
167ld-option = $(call try-run, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2),$(3)) 163ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
168 164
169# ar-option 165# ar-option
170# Usage: KBUILD_ARFLAGS := $(call ar-option,D) 166# Usage: KBUILD_ARFLAGS := $(call ar-option,D)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 93b8e24b0e15..5a2d1c9578a0 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -190,7 +190,7 @@ cmd_modversions_c = \
190 $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 190 $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
191 > $(@D)/.tmp_$(@F:.o=.ver); \ 191 > $(@D)/.tmp_$(@F:.o=.ver); \
192 \ 192 \
193 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 193 $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
194 -T $(@D)/.tmp_$(@F:.o=.ver); \ 194 -T $(@D)/.tmp_$(@F:.o=.ver); \
195 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ 195 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
196 else \ 196 else \
@@ -220,7 +220,7 @@ sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH
220 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ 220 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
221 "$(if $(CONFIG_64BIT),64,32)" \ 221 "$(if $(CONFIG_64BIT),64,32)" \
222 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \ 222 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \
223 "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ 223 "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
224 "$(if $(part-of-module),1,0)" "$(@)"; 224 "$(if $(part-of-module),1,0)" "$(@)";
225recordmcount_source := $(srctree)/scripts/recordmcount.pl 225recordmcount_source := $(srctree)/scripts/recordmcount.pl
226endif # BUILD_C_RECORDMCOUNT 226endif # BUILD_C_RECORDMCOUNT
@@ -246,8 +246,6 @@ objtool_args += --no-fp
246endif 246endif
247ifdef CONFIG_GCOV_KERNEL 247ifdef CONFIG_GCOV_KERNEL
248objtool_args += --no-unreachable 248objtool_args += --no-unreachable
249else
250objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable)
251endif 249endif
252ifdef CONFIG_RETPOLINE 250ifdef CONFIG_RETPOLINE
253ifneq ($(RETPOLINE_CFLAGS),) 251ifneq ($(RETPOLINE_CFLAGS),)
@@ -394,7 +392,7 @@ cmd_modversions_S = \
394 $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 392 $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
395 > $(@D)/.tmp_$(@F:.o=.ver); \ 393 > $(@D)/.tmp_$(@F:.o=.ver); \
396 \ 394 \
397 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 395 $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
398 -T $(@D)/.tmp_$(@F:.o=.ver); \ 396 -T $(@D)/.tmp_$(@F:.o=.ver); \
399 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ 397 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
400 else \ 398 else \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index df0fff252619..61e596650ed3 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -162,7 +162,7 @@ a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
162cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 162cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
163 $(__cpp_flags) 163 $(__cpp_flags)
164 164
165ld_flags = $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) 165ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
166 166
167DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes 167DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
168 168
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index dd92dbbbaa68..7d4af0d0accb 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -120,7 +120,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
120# Step 6), final link of the modules with optional arch pass after final link 120# Step 6), final link of the modules with optional arch pass after final link
121quiet_cmd_ld_ko_o = LD [M] $@ 121quiet_cmd_ld_ko_o = LD [M] $@
122 cmd_ld_ko_o = \ 122 cmd_ld_ko_o = \
123 $(LD) -r $(LDFLAGS) \ 123 $(LD) -r $(KBUILD_LDFLAGS) \
124 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ 124 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
125 -o $@ $(filter-out FORCE,$^) ; \ 125 -o $@ $(filter-out FORCE,$^) ; \
126 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 126 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5219280bf7ff..161b0224d6ae 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -380,6 +380,7 @@ our $Attribute = qr{
380 __noclone| 380 __noclone|
381 __deprecated| 381 __deprecated|
382 __read_mostly| 382 __read_mostly|
383 __ro_after_init|
383 __kprobes| 384 __kprobes|
384 $InitAttribute| 385 $InitAttribute|
385 ____cacheline_aligned| 386 ____cacheline_aligned|
@@ -3311,7 +3312,7 @@ sub process {
3311 # known declaration macros 3312 # known declaration macros
3312 $sline =~ /^\+\s+$declaration_macros/ || 3313 $sline =~ /^\+\s+$declaration_macros/ ||
3313 # start of struct or union or enum 3314 # start of struct or union or enum
3314 $sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ || 3315 $sline =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
3315 # start or end of block or continuation of declaration 3316 # start or end of block or continuation of declaration
3316 $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ || 3317 $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
3317 # bitfield continuation 3318 # bitfield continuation
diff --git a/scripts/clang-version.sh b/scripts/clang-version.sh
index dbf0a31eb111..e65fbc3079d4 100755
--- a/scripts/clang-version.sh
+++ b/scripts/clang-version.sh
@@ -12,7 +12,7 @@
12 12
13compiler="$*" 13compiler="$*"
14 14
15if !( $compiler --version | grep -q clang) ; then 15if ! ( $compiler --version | grep -q clang) ; then
16 echo 0 16 echo 0
17 exit 1 17 exit 1
18fi 18fi
diff --git a/scripts/coccinelle/api/alloc/zalloc-simple.cocci b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
index 92b20913055f..d819275b7fde 100644
--- a/scripts/coccinelle/api/alloc/zalloc-simple.cocci
+++ b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
@@ -35,8 +35,7 @@ statement S;
35 35
36* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\| 36* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\|
37 kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\| 37 kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\|
38 devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\| 38 devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|kvmalloc_node(E1,...)\);
39 kvmalloc_node(E1,...)\);
40 if ((x==NULL) || ...) S 39 if ((x==NULL) || ...) S
41* memset((T2)x,0,E1); 40* memset((T2)x,0,E1);
42 41
@@ -124,15 +123,6 @@ statement S;
124- x = (T)kvmalloc(E1,E2); 123- x = (T)kvmalloc(E1,E2);
125+ x = (T)kvzalloc(E1,E2); 124+ x = (T)kvzalloc(E1,E2);
126| 125|
127- x = pci_alloc_consistent(E2,E1,E3);
128+ x = pci_zalloc_consistent(E2,E1,E3);
129|
130- x = (T *)pci_alloc_consistent(E2,E1,E3);
131+ x = pci_zalloc_consistent(E2,E1,E3);
132|
133- x = (T)pci_alloc_consistent(E2,E1,E3);
134+ x = (T)pci_zalloc_consistent(E2,E1,E3);
135|
136- x = kvmalloc_node(E1,E2,E3); 126- x = kvmalloc_node(E1,E2,E3);
137+ x = kvzalloc_node(E1,E2,E3); 127+ x = kvzalloc_node(E1,E2,E3);
138| 128|
@@ -389,35 +379,6 @@ msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x)
389coccilib.report.print_report(p[0], msg) 379coccilib.report.print_report(p[0], msg)
390 380
391//----------------------------------------------------------------- 381//-----------------------------------------------------------------
392@r8 depends on org || report@
393type T, T2;
394expression x;
395expression E1,E2,E3;
396statement S;
397position p;
398@@
399
400 x = (T)pci_alloc_consistent@p(E2,E1,E3);
401 if ((x==NULL) || ...) S
402 memset((T2)x,0,E1);
403
404@script:python depends on org@
405p << r8.p;
406x << r8.x;
407@@
408
409msg="%s" % (x)
410msg_safe=msg.replace("[","@(").replace("]",")")
411coccilib.org.print_todo(p[0], msg_safe)
412
413@script:python depends on report@
414p << r8.p;
415x << r8.x;
416@@
417
418msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x)
419coccilib.report.print_report(p[0], msg)
420//-----------------------------------------------------------------
421@r9 depends on org || report@ 382@r9 depends on org || report@
422type T, T2; 383type T, T2;
423expression x; 384expression x;
diff --git a/scripts/depmod.sh b/scripts/depmod.sh
index 999d585eaa73..e083bcae343f 100755
--- a/scripts/depmod.sh
+++ b/scripts/depmod.sh
@@ -11,13 +11,14 @@ DEPMOD=$1
11KERNELRELEASE=$2 11KERNELRELEASE=$2
12 12
13if ! test -r System.map ; then 13if ! test -r System.map ; then
14 echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2
14 exit 0 15 exit 0
15fi 16fi
16 17
17if [ -z $(command -v $DEPMOD) ]; then 18if [ -z $(command -v $DEPMOD) ]; then
18 echo "'make modules_install' requires $DEPMOD. Please install it." >&2 19 echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2
19 echo "This is probably in the kmod package." >&2 20 echo "This is probably in the kmod package." >&2
20 exit 1 21 exit 0
21fi 22fi
22 23
23# older versions of depmod require the version string to start with three 24# older versions of depmod require the version string to start with three
diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile
index 9cac65b7419c..1c943e03eaf2 100644
--- a/scripts/dtc/Makefile
+++ b/scripts/dtc/Makefile
@@ -9,21 +9,11 @@ dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \
9dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o 9dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o
10 10
11# Source files need to get at the userspace version of libfdt_env.h to compile 11# Source files need to get at the userspace version of libfdt_env.h to compile
12HOST_EXTRACFLAGS := -I$(src)/libfdt
12 13
13HOSTCFLAGS_DTC := -I$(src) -I$(src)/libfdt 14# Generated files need one more search path to include headers in source tree
14 15HOSTCFLAGS_dtc-lexer.lex.o := -I$(src)
15HOSTCFLAGS_checks.o := $(HOSTCFLAGS_DTC) 16HOSTCFLAGS_dtc-parser.tab.o := -I$(src)
16HOSTCFLAGS_data.o := $(HOSTCFLAGS_DTC)
17HOSTCFLAGS_dtc.o := $(HOSTCFLAGS_DTC)
18HOSTCFLAGS_flattree.o := $(HOSTCFLAGS_DTC)
19HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC)
20HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC)
21HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC)
22HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC)
23HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC)
24
25HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC)
26HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)
27 17
28# dependencies on generated files need to be listed explicitly 18# dependencies on generated files need to be listed explicitly
29$(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h 19$(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
diff --git a/scripts/gcc-plugins/Kconfig b/scripts/gcc-plugins/Kconfig
index 7430a7c77a4a..cb0c889e13aa 100644
--- a/scripts/gcc-plugins/Kconfig
+++ b/scripts/gcc-plugins/Kconfig
@@ -2,7 +2,7 @@ preferred-plugin-hostcc := $(if-success,[ $(gcc-version) -ge 40800 ],$(HOSTCXX),
2 2
3config PLUGIN_HOSTCC 3config PLUGIN_HOSTCC
4 string 4 string
5 default "$(shell,$(srctree)/scripts/gcc-plugin.sh "$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")" 5 default "$(shell,$(srctree)/scripts/gcc-plugin.sh "$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")" if CC_IS_GCC
6 help 6 help
7 Host compiler used to build GCC plugins. This can be $(HOSTCXX), 7 Host compiler used to build GCC plugins. This can be $(HOSTCXX),
8 $(HOSTCC), or a null string if GCC plugin is unsupported. 8 $(HOSTCC), or a null string if GCC plugin is unsupported.
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 8d8791069abf..67ed9f6ccdf8 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -3,7 +3,8 @@
3# Kernel configuration targets 3# Kernel configuration targets
4# These targets are used from top-level makefile 4# These targets are used from top-level makefile
5 5
6PHONY += xconfig gconfig menuconfig config localmodconfig localyesconfig 6PHONY += xconfig gconfig menuconfig config localmodconfig localyesconfig \
7 build_menuconfig build_nconfig build_gconfig build_xconfig
7 8
8ifdef KBUILD_KCONFIG 9ifdef KBUILD_KCONFIG
9Kconfig := $(KBUILD_KCONFIG) 10Kconfig := $(KBUILD_KCONFIG)
@@ -33,6 +34,14 @@ config: $(obj)/conf
33nconfig: $(obj)/nconf 34nconfig: $(obj)/nconf
34 $< $(silent) $(Kconfig) 35 $< $(silent) $(Kconfig)
35 36
37build_menuconfig: $(obj)/mconf
38
39build_nconfig: $(obj)/nconf
40
41build_gconfig: $(obj)/gconf
42
43build_xconfig: $(obj)/qconf
44
36localyesconfig localmodconfig: $(obj)/conf 45localyesconfig localmodconfig: $(obj)/conf
37 $(Q)perl $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config 46 $(Q)perl $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config
38 $(Q)if [ -f .config ]; then \ 47 $(Q)if [ -f .config ]; then \
@@ -169,7 +178,7 @@ HOSTLDLIBS_nconf = $(shell . $(obj)/.nconf-cfg && echo $$libs)
169HOSTCFLAGS_nconf.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags) 178HOSTCFLAGS_nconf.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags)
170HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags) 179HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags)
171 180
172$(obj)/nconf.o: $(obj)/.nconf-cfg 181$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/.nconf-cfg
173 182
174# mconf: Used for the menuconfig target based on lxdialog 183# mconf: Used for the menuconfig target based on lxdialog
175hostprogs-y += mconf 184hostprogs-y += mconf
@@ -180,7 +189,8 @@ HOSTLDLIBS_mconf = $(shell . $(obj)/.mconf-cfg && echo $$libs)
180$(foreach f, mconf.o $(lxdialog), \ 189$(foreach f, mconf.o $(lxdialog), \
181 $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/.mconf-cfg && echo $$$$cflags))) 190 $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/.mconf-cfg && echo $$$$cflags)))
182 191
183$(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/.mconf-cfg 192$(obj)/mconf.o: $(obj)/.mconf-cfg
193$(addprefix $(obj)/lxdialog/, $(lxdialog)): $(obj)/.mconf-cfg
184 194
185# qconf: Used for the xconfig target based on Qt 195# qconf: Used for the xconfig target based on Qt
186hostprogs-y += qconf 196hostprogs-y += qconf
@@ -211,7 +221,6 @@ $(obj)/zconf.tab.o: $(obj)/zconf.lex.c
211 221
212# check if necessary packages are available, and configure build flags 222# check if necessary packages are available, and configure build flags
213define filechk_conf_cfg 223define filechk_conf_cfg
214 $(CONFIG_SHELL) $(srctree)/scripts/kconfig/check-pkgconfig.sh; \
215 $(CONFIG_SHELL) $< 224 $(CONFIG_SHELL) $<
216endef 225endef
217 226
diff --git a/scripts/kconfig/check-pkgconfig.sh b/scripts/kconfig/check-pkgconfig.sh
deleted file mode 100644
index 7a1c40bfb58c..000000000000
--- a/scripts/kconfig/check-pkgconfig.sh
+++ /dev/null
@@ -1,8 +0,0 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# Check for pkg-config presence
4
5if [ -z $(command -v pkg-config) ]; then
6 echo "'make *config' requires 'pkg-config'. Please install it." 1>&2
7 exit 1
8fi
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index b35cc9303979..7b2b37260669 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -508,6 +508,11 @@ int main(int ac, char **av)
508 input_mode = (enum input_mode)opt; 508 input_mode = (enum input_mode)opt;
509 switch (opt) { 509 switch (opt) {
510 case syncconfig: 510 case syncconfig:
511 /*
512 * syncconfig is invoked during the build stage.
513 * Suppress distracting "configuration written to ..."
514 */
515 conf_set_message_callback(NULL);
511 sync_kconfig = 1; 516 sync_kconfig = 1;
512 break; 517 break;
513 case defconfig: 518 case defconfig:
diff --git a/scripts/kconfig/gconf-cfg.sh b/scripts/kconfig/gconf-cfg.sh
index 533b3d8f8f08..480ecd8b9f41 100755
--- a/scripts/kconfig/gconf-cfg.sh
+++ b/scripts/kconfig/gconf-cfg.sh
@@ -3,6 +3,13 @@
3 3
4PKG="gtk+-2.0 gmodule-2.0 libglade-2.0" 4PKG="gtk+-2.0 gmodule-2.0 libglade-2.0"
5 5
6if [ -z "$(command -v pkg-config)" ]; then
7 echo >&2 "*"
8 echo >&2 "* 'make gconfig' requires 'pkg-config'. Please install it."
9 echo >&2 "*"
10 exit 1
11fi
12
6if ! pkg-config --exists $PKG; then 13if ! pkg-config --exists $PKG; then
7 echo >&2 "*" 14 echo >&2 "*"
8 echo >&2 "* Unable to find the GTK+ installation. Please make sure that" 15 echo >&2 "* Unable to find the GTK+ installation. Please make sure that"
diff --git a/scripts/kconfig/mconf-cfg.sh b/scripts/kconfig/mconf-cfg.sh
index e6f9facd0077..c812872d7f9d 100755
--- a/scripts/kconfig/mconf-cfg.sh
+++ b/scripts/kconfig/mconf-cfg.sh
@@ -4,20 +4,23 @@
4PKG="ncursesw" 4PKG="ncursesw"
5PKG2="ncurses" 5PKG2="ncurses"
6 6
7if pkg-config --exists $PKG; then 7if [ -n "$(command -v pkg-config)" ]; then
8 echo cflags=\"$(pkg-config --cflags $PKG)\" 8 if pkg-config --exists $PKG; then
9 echo libs=\"$(pkg-config --libs $PKG)\" 9 echo cflags=\"$(pkg-config --cflags $PKG)\"
10 exit 0 10 echo libs=\"$(pkg-config --libs $PKG)\"
11fi 11 exit 0
12 fi
12 13
13if pkg-config --exists $PKG2; then 14 if pkg-config --exists $PKG2; then
14 echo cflags=\"$(pkg-config --cflags $PKG2)\" 15 echo cflags=\"$(pkg-config --cflags $PKG2)\"
15 echo libs=\"$(pkg-config --libs $PKG2)\" 16 echo libs=\"$(pkg-config --libs $PKG2)\"
16 exit 0 17 exit 0
18 fi
17fi 19fi
18 20
19# Unfortunately, some distributions (e.g. openSUSE) cannot find ncurses 21# Check the default paths in case pkg-config is not installed.
20# by pkg-config. 22# (Even if it is installed, some distributions such as openSUSE cannot
23# find ncurses by pkg-config.)
21if [ -f /usr/include/ncursesw/ncurses.h ]; then 24if [ -f /usr/include/ncursesw/ncurses.h ]; then
22 echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\" 25 echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\"
23 echo libs=\"-lncursesw\" 26 echo libs=\"-lncursesw\"
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 83b5836615fb..143c05fec161 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -490,7 +490,6 @@ static void build_conf(struct menu *menu)
490 switch (prop->type) { 490 switch (prop->type) {
491 case P_MENU: 491 case P_MENU:
492 child_count++; 492 child_count++;
493 prompt = prompt;
494 if (single_menu_mode) { 493 if (single_menu_mode) {
495 item_make("%s%*c%s", 494 item_make("%s%*c%s",
496 menu->data ? "-->" : "++>", 495 menu->data ? "-->" : "++>",
diff --git a/scripts/kconfig/nconf-cfg.sh b/scripts/kconfig/nconf-cfg.sh
index 42f5ac73548e..001559ef0a60 100644
--- a/scripts/kconfig/nconf-cfg.sh
+++ b/scripts/kconfig/nconf-cfg.sh
@@ -4,20 +4,23 @@
4PKG="ncursesw menuw panelw" 4PKG="ncursesw menuw panelw"
5PKG2="ncurses menu panel" 5PKG2="ncurses menu panel"
6 6
7if pkg-config --exists $PKG; then 7if [ -n "$(command -v pkg-config)" ]; then
8 echo cflags=\"$(pkg-config --cflags $PKG)\" 8 if pkg-config --exists $PKG; then
9 echo libs=\"$(pkg-config --libs $PKG)\" 9 echo cflags=\"$(pkg-config --cflags $PKG)\"
10 exit 0 10 echo libs=\"$(pkg-config --libs $PKG)\"
11fi 11 exit 0
12 fi
12 13
13if pkg-config --exists $PKG2; then 14 if pkg-config --exists $PKG2; then
14 echo cflags=\"$(pkg-config --cflags $PKG2)\" 15 echo cflags=\"$(pkg-config --cflags $PKG2)\"
15 echo libs=\"$(pkg-config --libs $PKG2)\" 16 echo libs=\"$(pkg-config --libs $PKG2)\"
16 exit 0 17 exit 0
18 fi
17fi 19fi
18 20
19# Unfortunately, some distributions (e.g. openSUSE) cannot find ncurses 21# Check the default paths in case pkg-config is not installed.
20# by pkg-config. 22# (Even if it is installed, some distributions such as openSUSE cannot
23# find ncurses by pkg-config.)
21if [ -f /usr/include/ncursesw/ncurses.h ]; then 24if [ -f /usr/include/ncursesw/ncurses.h ]; then
22 echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\" 25 echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\"
23 echo libs=\"-lncursesw -lmenuw -lpanelw\" 26 echo libs=\"-lncursesw -lmenuw -lpanelw\"
diff --git a/scripts/kconfig/qconf-cfg.sh b/scripts/kconfig/qconf-cfg.sh
index 0862e1562536..02ccc0ae1031 100755
--- a/scripts/kconfig/qconf-cfg.sh
+++ b/scripts/kconfig/qconf-cfg.sh
@@ -4,6 +4,13 @@
4PKG="Qt5Core Qt5Gui Qt5Widgets" 4PKG="Qt5Core Qt5Gui Qt5Widgets"
5PKG2="QtCore QtGui" 5PKG2="QtCore QtGui"
6 6
7if [ -z "$(command -v pkg-config)" ]; then
8 echo >&2 "*"
9 echo >&2 "* 'make xconfig' requires 'pkg-config'. Please install it."
10 echo >&2 "*"
11 exit 1
12fi
13
7if pkg-config --exists $PKG; then 14if pkg-config --exists $PKG; then
8 echo cflags=\"-std=c++11 -fPIC $(pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)\" 15 echo cflags=\"-std=c++11 -fPIC $(pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)\"
9 echo libs=\"$(pkg-config --libs $PKG)\" 16 echo libs=\"$(pkg-config --libs $PKG)\"
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 4ec8b1f0d42c..703b9b899ee9 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -1011,7 +1011,7 @@ static struct dep_stack {
1011 struct dep_stack *prev, *next; 1011 struct dep_stack *prev, *next;
1012 struct symbol *sym; 1012 struct symbol *sym;
1013 struct property *prop; 1013 struct property *prop;
1014 struct expr *expr; 1014 struct expr **expr;
1015} *check_top; 1015} *check_top;
1016 1016
1017static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym) 1017static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym)
@@ -1076,31 +1076,42 @@ static void sym_check_print_recursive(struct symbol *last_sym)
1076 fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", 1076 fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
1077 prop->file->name, prop->lineno); 1077 prop->file->name, prop->lineno);
1078 1078
1079 if (stack->expr) { 1079 if (sym_is_choice(sym)) {
1080 fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", 1080 fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
1081 prop->file->name, prop->lineno, 1081 menu->file->name, menu->lineno,
1082 sym->name ? sym->name : "<choice>", 1082 sym->name ? sym->name : "<choice>",
1083 prop_get_type_name(prop->type),
1084 next_sym->name ? next_sym->name : "<choice>"); 1083 next_sym->name ? next_sym->name : "<choice>");
1085 } else if (stack->prop) { 1084 } else if (sym_is_choice_value(sym)) {
1085 fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
1086 menu->file->name, menu->lineno,
1087 sym->name ? sym->name : "<choice>",
1088 next_sym->name ? next_sym->name : "<choice>");
1089 } else if (stack->expr == &sym->dir_dep.expr) {
1086 fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", 1090 fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
1087 prop->file->name, prop->lineno, 1091 prop->file->name, prop->lineno,
1088 sym->name ? sym->name : "<choice>", 1092 sym->name ? sym->name : "<choice>",
1089 next_sym->name ? next_sym->name : "<choice>"); 1093 next_sym->name ? next_sym->name : "<choice>");
1090 } else if (sym_is_choice(sym)) { 1094 } else if (stack->expr == &sym->rev_dep.expr) {
1091 fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", 1095 fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
1092 menu->file->name, menu->lineno, 1096 prop->file->name, prop->lineno,
1093 sym->name ? sym->name : "<choice>", 1097 sym->name ? sym->name : "<choice>",
1094 next_sym->name ? next_sym->name : "<choice>"); 1098 next_sym->name ? next_sym->name : "<choice>");
1095 } else if (sym_is_choice_value(sym)) { 1099 } else if (stack->expr == &sym->implied.expr) {
1096 fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n", 1100 fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n",
1097 menu->file->name, menu->lineno, 1101 prop->file->name, prop->lineno,
1102 sym->name ? sym->name : "<choice>",
1103 next_sym->name ? next_sym->name : "<choice>");
1104 } else if (stack->expr) {
1105 fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
1106 prop->file->name, prop->lineno,
1098 sym->name ? sym->name : "<choice>", 1107 sym->name ? sym->name : "<choice>",
1108 prop_get_type_name(prop->type),
1099 next_sym->name ? next_sym->name : "<choice>"); 1109 next_sym->name ? next_sym->name : "<choice>");
1100 } else { 1110 } else {
1101 fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", 1111 fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
1102 prop->file->name, prop->lineno, 1112 prop->file->name, prop->lineno,
1103 sym->name ? sym->name : "<choice>", 1113 sym->name ? sym->name : "<choice>",
1114 prop_get_type_name(prop->type),
1104 next_sym->name ? next_sym->name : "<choice>"); 1115 next_sym->name ? next_sym->name : "<choice>");
1105 } 1116 }
1106 } 1117 }
@@ -1157,12 +1168,26 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
1157 1168
1158 dep_stack_insert(&stack, sym); 1169 dep_stack_insert(&stack, sym);
1159 1170
1171 stack.expr = &sym->dir_dep.expr;
1172 sym2 = sym_check_expr_deps(sym->dir_dep.expr);
1173 if (sym2)
1174 goto out;
1175
1176 stack.expr = &sym->rev_dep.expr;
1160 sym2 = sym_check_expr_deps(sym->rev_dep.expr); 1177 sym2 = sym_check_expr_deps(sym->rev_dep.expr);
1161 if (sym2) 1178 if (sym2)
1162 goto out; 1179 goto out;
1163 1180
1181 stack.expr = &sym->implied.expr;
1182 sym2 = sym_check_expr_deps(sym->implied.expr);
1183 if (sym2)
1184 goto out;
1185
1186 stack.expr = NULL;
1187
1164 for (prop = sym->prop; prop; prop = prop->next) { 1188 for (prop = sym->prop; prop; prop = prop->next) {
1165 if (prop->type == P_CHOICE || prop->type == P_SELECT) 1189 if (prop->type == P_CHOICE || prop->type == P_SELECT ||
1190 prop->type == P_IMPLY)
1166 continue; 1191 continue;
1167 stack.prop = prop; 1192 stack.prop = prop;
1168 sym2 = sym_check_expr_deps(prop->visible.expr); 1193 sym2 = sym_check_expr_deps(prop->visible.expr);
@@ -1170,7 +1195,7 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
1170 break; 1195 break;
1171 if (prop->type != P_DEFAULT || sym_is_choice(sym)) 1196 if (prop->type != P_DEFAULT || sym_is_choice(sym))
1172 continue; 1197 continue;
1173 stack.expr = prop->expr; 1198 stack.expr = &prop->expr;
1174 sym2 = sym_check_expr_deps(prop->expr); 1199 sym2 = sym_check_expr_deps(prop->expr);
1175 if (sym2) 1200 if (sym2)
1176 break; 1201 break;
@@ -1248,9 +1273,6 @@ struct symbol *sym_check_deps(struct symbol *sym)
1248 sym->flags &= ~SYMBOL_CHECK; 1273 sym->flags &= ~SYMBOL_CHECK;
1249 } 1274 }
1250 1275
1251 if (sym2 && sym2 == sym)
1252 sym2 = NULL;
1253
1254 return sym2; 1276 return sym2;
1255} 1277}
1256 1278
diff --git a/scripts/kconfig/tests/warn_recursive_dep/Kconfig b/scripts/kconfig/tests/err_recursive_dep/Kconfig
index a65bfcb7137e..ebdb3ffd8717 100644
--- a/scripts/kconfig/tests/warn_recursive_dep/Kconfig
+++ b/scripts/kconfig/tests/err_recursive_dep/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1# depends on itself 3# depends on itself
2 4
3config A 5config A
@@ -31,7 +33,6 @@ config D2
31 bool 33 bool
32 34
33# depends on and imply 35# depends on and imply
34# This is not recursive dependency
35 36
36config E1 37config E1
37 bool "E1" 38 bool "E1"
diff --git a/scripts/kconfig/tests/err_recursive_dep/__init__.py b/scripts/kconfig/tests/err_recursive_dep/__init__.py
new file mode 100644
index 000000000000..5f3821b43ce6
--- /dev/null
+++ b/scripts/kconfig/tests/err_recursive_dep/__init__.py
@@ -0,0 +1,10 @@
1# SPDX-License-Identifier: GPL-2.0
2"""
3Detect recursive dependency error.
4
5Recursive dependency should be treated as an error.
6"""
7
8def test(conf):
9 assert conf.oldaskconfig() == 1
10 assert conf.stderr_contains('expected_stderr')
diff --git a/scripts/kconfig/tests/err_recursive_dep/expected_stderr b/scripts/kconfig/tests/err_recursive_dep/expected_stderr
new file mode 100644
index 000000000000..84679b104655
--- /dev/null
+++ b/scripts/kconfig/tests/err_recursive_dep/expected_stderr
@@ -0,0 +1,38 @@
1Kconfig:11:error: recursive dependency detected!
2Kconfig:11: symbol B is selected by B
3For a resolution refer to Documentation/kbuild/kconfig-language.txt
4subsection "Kconfig recursive dependency limitations"
5
6Kconfig:5:error: recursive dependency detected!
7Kconfig:5: symbol A depends on A
8For a resolution refer to Documentation/kbuild/kconfig-language.txt
9subsection "Kconfig recursive dependency limitations"
10
11Kconfig:17:error: recursive dependency detected!
12Kconfig:17: symbol C1 depends on C2
13Kconfig:21: symbol C2 depends on C1
14For a resolution refer to Documentation/kbuild/kconfig-language.txt
15subsection "Kconfig recursive dependency limitations"
16
17Kconfig:32:error: recursive dependency detected!
18Kconfig:32: symbol D2 is selected by D1
19Kconfig:27: symbol D1 depends on D2
20For a resolution refer to Documentation/kbuild/kconfig-language.txt
21subsection "Kconfig recursive dependency limitations"
22
23Kconfig:37:error: recursive dependency detected!
24Kconfig:37: symbol E1 depends on E2
25Kconfig:42: symbol E2 is implied by E1
26For a resolution refer to Documentation/kbuild/kconfig-language.txt
27subsection "Kconfig recursive dependency limitations"
28
29Kconfig:60:error: recursive dependency detected!
30Kconfig:60: symbol G depends on G
31For a resolution refer to Documentation/kbuild/kconfig-language.txt
32subsection "Kconfig recursive dependency limitations"
33
34Kconfig:51:error: recursive dependency detected!
35Kconfig:51: symbol F2 depends on F1
36Kconfig:49: symbol F1 default value contains F2
37For a resolution refer to Documentation/kbuild/kconfig-language.txt
38subsection "Kconfig recursive dependency limitations"
diff --git a/scripts/kconfig/tests/warn_recursive_dep/__init__.py b/scripts/kconfig/tests/warn_recursive_dep/__init__.py
deleted file mode 100644
index adb21951ba41..000000000000
--- a/scripts/kconfig/tests/warn_recursive_dep/__init__.py
+++ /dev/null
@@ -1,9 +0,0 @@
1"""
2Warn recursive inclusion.
3
4Recursive dependency should be warned.
5"""
6
7def test(conf):
8 assert conf.oldaskconfig() == 0
9 assert conf.stderr_contains('expected_stderr')
diff --git a/scripts/kconfig/tests/warn_recursive_dep/expected_stderr b/scripts/kconfig/tests/warn_recursive_dep/expected_stderr
deleted file mode 100644
index 3de807dd9cb2..000000000000
--- a/scripts/kconfig/tests/warn_recursive_dep/expected_stderr
+++ /dev/null
@@ -1,30 +0,0 @@
1Kconfig:9:error: recursive dependency detected!
2Kconfig:9: symbol B is selected by B
3For a resolution refer to Documentation/kbuild/kconfig-language.txt
4subsection "Kconfig recursive dependency limitations"
5
6Kconfig:3:error: recursive dependency detected!
7Kconfig:3: symbol A depends on A
8For a resolution refer to Documentation/kbuild/kconfig-language.txt
9subsection "Kconfig recursive dependency limitations"
10
11Kconfig:15:error: recursive dependency detected!
12Kconfig:15: symbol C1 depends on C2
13Kconfig:19: symbol C2 depends on C1
14For a resolution refer to Documentation/kbuild/kconfig-language.txt
15subsection "Kconfig recursive dependency limitations"
16
17Kconfig:30:error: recursive dependency detected!
18Kconfig:30: symbol D2 is selected by D1
19Kconfig:25: symbol D1 depends on D2
20For a resolution refer to Documentation/kbuild/kconfig-language.txt
21subsection "Kconfig recursive dependency limitations"
22
23Kconfig:59:error: recursive dependency detected!
24Kconfig:59: symbol G depends on G
25For a resolution refer to Documentation/kbuild/kconfig-language.txt
26subsection "Kconfig recursive dependency limitations"
27
28Kconfig:50:error: recursive dependency detected!
29Kconfig:50: symbol F2 depends on F1
30Kconfig:48: symbol F1 default value contains F2
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 4bf811c09f59..c8cf45362bd6 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -75,7 +75,7 @@ modpost_link()
75 ${KBUILD_VMLINUX_LIBS} \ 75 ${KBUILD_VMLINUX_LIBS} \
76 --end-group" 76 --end-group"
77 77
78 ${LD} ${LDFLAGS} -r -o ${1} ${objects} 78 ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${objects}
79} 79}
80 80
81# Link of vmlinux 81# Link of vmlinux
@@ -95,7 +95,7 @@ vmlinux_link()
95 --end-group \ 95 --end-group \
96 ${1}" 96 ${1}"
97 97
98 ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ 98 ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \
99 -T ${lds} ${objects} 99 -T ${lds} ${objects}
100 else 100 else
101 objects="-Wl,--whole-archive \ 101 objects="-Wl,--whole-archive \
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index dc6d714e4dcb..0d998c54564d 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -672,7 +672,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
672 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) 672 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
673 break; 673 break;
674 if (symname[0] == '.') { 674 if (symname[0] == '.') {
675 char *munged = strdup(symname); 675 char *munged = NOFAIL(strdup(symname));
676 munged[0] = '_'; 676 munged[0] = '_';
677 munged[1] = toupper(munged[1]); 677 munged[1] = toupper(munged[1]);
678 symname = munged; 678 symname = munged;
@@ -1318,7 +1318,7 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1318static char *sec2annotation(const char *s) 1318static char *sec2annotation(const char *s)
1319{ 1319{
1320 if (match(s, init_exit_sections)) { 1320 if (match(s, init_exit_sections)) {
1321 char *p = malloc(20); 1321 char *p = NOFAIL(malloc(20));
1322 char *r = p; 1322 char *r = p;
1323 1323
1324 *p++ = '_'; 1324 *p++ = '_';
@@ -1338,7 +1338,7 @@ static char *sec2annotation(const char *s)
1338 strcat(p, " "); 1338 strcat(p, " ");
1339 return r; 1339 return r;
1340 } else { 1340 } else {
1341 return strdup(""); 1341 return NOFAIL(strdup(""));
1342 } 1342 }
1343} 1343}
1344 1344
@@ -2036,7 +2036,7 @@ void buf_write(struct buffer *buf, const char *s, int len)
2036{ 2036{
2037 if (buf->size - buf->pos < len) { 2037 if (buf->size - buf->pos < len) {
2038 buf->size += len + SZ; 2038 buf->size += len + SZ;
2039 buf->p = realloc(buf->p, buf->size); 2039 buf->p = NOFAIL(realloc(buf->p, buf->size));
2040 } 2040 }
2041 strncpy(buf->p + buf->pos, s, len); 2041 strncpy(buf->p + buf->pos, s, len);
2042 buf->pos += len; 2042 buf->pos += len;
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index fe06e77c15eb..f599031260d5 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -389,6 +389,9 @@ if ($arch eq "x86_64") {
389 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL\\s_mcount\$"; 389 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL\\s_mcount\$";
390 $type = ".quad"; 390 $type = ".quad";
391 $alignment = 2; 391 $alignment = 2;
392} elsif ($arch eq "nds32") {
393 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_NDS32_HI20_RELA\\s+_mcount\$";
394 $alignment = 2;
392} else { 395} else {
393 die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD"; 396 die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD";
394} 397}
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 71f39410691b..79f7dd57d571 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -74,7 +74,7 @@ scm_version()
74 fi 74 fi
75 75
76 # Check for uncommitted changes 76 # Check for uncommitted changes
77 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then 77 if git status -uno --porcelain | grep -qv '^.. scripts/package'; then
78 printf '%s' -dirty 78 printf '%s' -dirty
79 fi 79 fi
80 80
diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c
index f2f22d00db18..4ccec1bcf6f5 100644
--- a/security/apparmor/secid.c
+++ b/security/apparmor/secid.c
@@ -79,7 +79,6 @@ int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
79 struct aa_label *label = aa_secid_to_label(secid); 79 struct aa_label *label = aa_secid_to_label(secid);
80 int len; 80 int len;
81 81
82 AA_BUG(!secdata);
83 AA_BUG(!seclen); 82 AA_BUG(!seclen);
84 83
85 if (!label) 84 if (!label)
diff --git a/security/keys/dh.c b/security/keys/dh.c
index 711e89d8c415..3b602a1e27fa 100644
--- a/security/keys/dh.c
+++ b/security/keys/dh.c
@@ -300,7 +300,7 @@ long __keyctl_dh_compute(struct keyctl_dh_params __user *params,
300 } 300 }
301 dh_inputs.g_size = dlen; 301 dh_inputs.g_size = dlen;
302 302
303 dlen = dh_data_from_key(pcopy.private, &dh_inputs.key); 303 dlen = dh_data_from_key(pcopy.dh_private, &dh_inputs.key);
304 if (dlen < 0) { 304 if (dlen < 0) {
305 ret = dlen; 305 ret = dlen;
306 goto out2; 306 goto out2;
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 69517e18ef07..08d5662039e3 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -129,7 +129,7 @@ static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
129 runtime->avail = 0; 129 runtime->avail = 0;
130 else 130 else
131 runtime->avail = runtime->buffer_size; 131 runtime->avail = runtime->buffer_size;
132 runtime->buffer = kvmalloc(runtime->buffer_size, GFP_KERNEL); 132 runtime->buffer = kvzalloc(runtime->buffer_size, GFP_KERNEL);
133 if (!runtime->buffer) { 133 if (!runtime->buffer) {
134 kfree(runtime); 134 kfree(runtime);
135 return -ENOMEM; 135 return -ENOMEM;
@@ -655,7 +655,7 @@ static int resize_runtime_buffer(struct snd_rawmidi_runtime *runtime,
655 if (params->avail_min < 1 || params->avail_min > params->buffer_size) 655 if (params->avail_min < 1 || params->avail_min > params->buffer_size)
656 return -EINVAL; 656 return -EINVAL;
657 if (params->buffer_size != runtime->buffer_size) { 657 if (params->buffer_size != runtime->buffer_size) {
658 newbuf = kvmalloc(params->buffer_size, GFP_KERNEL); 658 newbuf = kvzalloc(params->buffer_size, GFP_KERNEL);
659 if (!newbuf) 659 if (!newbuf)
660 return -ENOMEM; 660 return -ENOMEM;
661 spin_lock_irq(&runtime->lock); 661 spin_lock_irq(&runtime->lock);
diff --git a/sound/hda/ext/hdac_ext_stream.c b/sound/hda/ext/hdac_ext_stream.c
index 1bd27576db98..a835558ddbc9 100644
--- a/sound/hda/ext/hdac_ext_stream.c
+++ b/sound/hda/ext/hdac_ext_stream.c
@@ -146,7 +146,8 @@ EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_decouple);
146 */ 146 */
147void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *stream) 147void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *stream)
148{ 148{
149 snd_hdac_updatel(stream->pplc_addr, AZX_REG_PPLCCTL, 0, AZX_PPLCCTL_RUN); 149 snd_hdac_updatel(stream->pplc_addr, AZX_REG_PPLCCTL,
150 AZX_PPLCCTL_RUN, AZX_PPLCCTL_RUN);
150} 151}
151EXPORT_SYMBOL_GPL(snd_hdac_ext_link_stream_start); 152EXPORT_SYMBOL_GPL(snd_hdac_ext_link_stream_start);
152 153
@@ -171,7 +172,8 @@ void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *stream)
171 172
172 snd_hdac_ext_link_stream_clear(stream); 173 snd_hdac_ext_link_stream_clear(stream);
173 174
174 snd_hdac_updatel(stream->pplc_addr, AZX_REG_PPLCCTL, 0, AZX_PPLCCTL_STRST); 175 snd_hdac_updatel(stream->pplc_addr, AZX_REG_PPLCCTL,
176 AZX_PPLCCTL_STRST, AZX_PPLCCTL_STRST);
175 udelay(3); 177 udelay(3);
176 timeout = 50; 178 timeout = 50;
177 do { 179 do {
@@ -242,7 +244,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_ext_link_set_stream_id);
242void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link, 244void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
243 int stream) 245 int stream)
244{ 246{
245 snd_hdac_updatew(link->ml_addr, AZX_REG_ML_LOSIDV, 0, (1 << stream)); 247 snd_hdac_updatew(link->ml_addr, AZX_REG_ML_LOSIDV, (1 << stream), 0);
246} 248}
247EXPORT_SYMBOL_GPL(snd_hdac_ext_link_clear_stream_id); 249EXPORT_SYMBOL_GPL(snd_hdac_ext_link_clear_stream_id);
248 250
@@ -415,7 +417,6 @@ void snd_hdac_ext_stream_spbcap_enable(struct hdac_bus *bus,
415 bool enable, int index) 417 bool enable, int index)
416{ 418{
417 u32 mask = 0; 419 u32 mask = 0;
418 u32 register_mask = 0;
419 420
420 if (!bus->spbcap) { 421 if (!bus->spbcap) {
421 dev_err(bus->dev, "Address of SPB capability is NULL\n"); 422 dev_err(bus->dev, "Address of SPB capability is NULL\n");
@@ -424,12 +425,8 @@ void snd_hdac_ext_stream_spbcap_enable(struct hdac_bus *bus,
424 425
425 mask |= (1 << index); 426 mask |= (1 << index);
426 427
427 register_mask = readl(bus->spbcap + AZX_REG_SPB_SPBFCCTL);
428
429 mask |= register_mask;
430
431 if (enable) 428 if (enable)
432 snd_hdac_updatel(bus->spbcap, AZX_REG_SPB_SPBFCCTL, 0, mask); 429 snd_hdac_updatel(bus->spbcap, AZX_REG_SPB_SPBFCCTL, mask, mask);
433 else 430 else
434 snd_hdac_updatel(bus->spbcap, AZX_REG_SPB_SPBFCCTL, mask, 0); 431 snd_hdac_updatel(bus->spbcap, AZX_REG_SPB_SPBFCCTL, mask, 0);
435} 432}
@@ -503,7 +500,6 @@ void snd_hdac_ext_stream_drsm_enable(struct hdac_bus *bus,
503 bool enable, int index) 500 bool enable, int index)
504{ 501{
505 u32 mask = 0; 502 u32 mask = 0;
506 u32 register_mask = 0;
507 503
508 if (!bus->drsmcap) { 504 if (!bus->drsmcap) {
509 dev_err(bus->dev, "Address of DRSM capability is NULL\n"); 505 dev_err(bus->dev, "Address of DRSM capability is NULL\n");
@@ -512,12 +508,8 @@ void snd_hdac_ext_stream_drsm_enable(struct hdac_bus *bus,
512 508
513 mask |= (1 << index); 509 mask |= (1 << index);
514 510
515 register_mask = readl(bus->drsmcap + AZX_REG_SPB_SPBFCCTL);
516
517 mask |= register_mask;
518
519 if (enable) 511 if (enable)
520 snd_hdac_updatel(bus->drsmcap, AZX_REG_DRSM_CTL, 0, mask); 512 snd_hdac_updatel(bus->drsmcap, AZX_REG_DRSM_CTL, mask, mask);
521 else 513 else
522 snd_hdac_updatel(bus->drsmcap, AZX_REG_DRSM_CTL, mask, 0); 514 snd_hdac_updatel(bus->drsmcap, AZX_REG_DRSM_CTL, mask, 0);
523} 515}
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 0a5085537034..26d348b47867 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -3935,7 +3935,8 @@ void snd_hda_bus_reset_codecs(struct hda_bus *bus)
3935 3935
3936 list_for_each_codec(codec, bus) { 3936 list_for_each_codec(codec, bus) {
3937 /* FIXME: maybe a better way needed for forced reset */ 3937 /* FIXME: maybe a better way needed for forced reset */
3938 cancel_delayed_work_sync(&codec->jackpoll_work); 3938 if (current_work() != &codec->jackpoll_work.work)
3939 cancel_delayed_work_sync(&codec->jackpoll_work);
3939#ifdef CONFIG_PM 3940#ifdef CONFIG_PM
3940 if (hda_codec_is_power_on(codec)) { 3941 if (hda_codec_is_power_on(codec)) {
3941 hda_call_codec_suspend(codec); 3942 hda_call_codec_suspend(codec);
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 64aaa3f5f36c..89a048c2faec 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -220,6 +220,7 @@
220#define X86_FEATURE_STIBP ( 7*32+27) /* Single Thread Indirect Branch Predictors */ 220#define X86_FEATURE_STIBP ( 7*32+27) /* Single Thread Indirect Branch Predictors */
221#define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU is AMD family 0x17 (Zen) */ 221#define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU is AMD family 0x17 (Zen) */
222#define X86_FEATURE_L1TF_PTEINV ( 7*32+29) /* "" L1TF workaround PTE inversion */ 222#define X86_FEATURE_L1TF_PTEINV ( 7*32+29) /* "" L1TF workaround PTE inversion */
223#define X86_FEATURE_IBRS_ENHANCED ( 7*32+30) /* Enhanced IBRS */
223 224
224/* Virtualization flags: Linux defined, word 8 */ 225/* Virtualization flags: Linux defined, word 8 */
225#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ 226#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */
@@ -230,7 +231,7 @@
230 231
231#define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer VMMCALL to VMCALL */ 232#define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer VMMCALL to VMCALL */
232#define X86_FEATURE_XENPV ( 8*32+16) /* "" Xen paravirtual guest */ 233#define X86_FEATURE_XENPV ( 8*32+16) /* "" Xen paravirtual guest */
233 234#define X86_FEATURE_EPT_AD ( 8*32+17) /* Intel Extended Page Table access-dirty bit */
234 235
235/* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ 236/* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */
236#define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/ 237#define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/
diff --git a/tools/arch/x86/lib/memcpy_64.S b/tools/arch/x86/lib/memcpy_64.S
index 298ef1479240..3b24dc05251c 100644
--- a/tools/arch/x86/lib/memcpy_64.S
+++ b/tools/arch/x86/lib/memcpy_64.S
@@ -256,7 +256,7 @@ ENTRY(__memcpy_mcsafe)
256 256
257 /* Copy successful. Return zero */ 257 /* Copy successful. Return zero */
258.L_done_memcpy_trap: 258.L_done_memcpy_trap:
259 xorq %rax, %rax 259 xorl %eax, %eax
260 ret 260 ret
261ENDPROC(__memcpy_mcsafe) 261ENDPROC(__memcpy_mcsafe)
262EXPORT_SYMBOL_GPL(__memcpy_mcsafe) 262EXPORT_SYMBOL_GPL(__memcpy_mcsafe)
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index b2ec20e562bd..b455930a3eaf 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -68,6 +68,7 @@ static const char * const map_type_name[] = {
68 [BPF_MAP_TYPE_DEVMAP] = "devmap", 68 [BPF_MAP_TYPE_DEVMAP] = "devmap",
69 [BPF_MAP_TYPE_SOCKMAP] = "sockmap", 69 [BPF_MAP_TYPE_SOCKMAP] = "sockmap",
70 [BPF_MAP_TYPE_CPUMAP] = "cpumap", 70 [BPF_MAP_TYPE_CPUMAP] = "cpumap",
71 [BPF_MAP_TYPE_XSKMAP] = "xskmap",
71 [BPF_MAP_TYPE_SOCKHASH] = "sockhash", 72 [BPF_MAP_TYPE_SOCKHASH] = "sockhash",
72 [BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage", 73 [BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage",
73}; 74};
diff --git a/tools/bpf/bpftool/map_perf_ring.c b/tools/bpf/bpftool/map_perf_ring.c
index 1832100d1b27..6d41323be291 100644
--- a/tools/bpf/bpftool/map_perf_ring.c
+++ b/tools/bpf/bpftool/map_perf_ring.c
@@ -194,8 +194,10 @@ int do_event_pipe(int argc, char **argv)
194 } 194 }
195 195
196 while (argc) { 196 while (argc) {
197 if (argc < 2) 197 if (argc < 2) {
198 BAD_ARG(); 198 BAD_ARG();
199 goto err_close_map;
200 }
199 201
200 if (is_prefix(*argv, "cpu")) { 202 if (is_prefix(*argv, "cpu")) {
201 char *endptr; 203 char *endptr;
@@ -221,6 +223,7 @@ int do_event_pipe(int argc, char **argv)
221 NEXT_ARG(); 223 NEXT_ARG();
222 } else { 224 } else {
223 BAD_ARG(); 225 BAD_ARG();
226 goto err_close_map;
224 } 227 }
225 228
226 do_all = false; 229 do_all = false;
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 56c4b3f8a01b..439b8a27488d 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -759,12 +759,18 @@ class DebugfsProvider(Provider):
759 if len(vms) == 0: 759 if len(vms) == 0:
760 self.do_read = False 760 self.do_read = False
761 761
762 self.paths = filter(lambda x: "{}-".format(pid) in x, vms) 762 self.paths = list(filter(lambda x: "{}-".format(pid) in x, vms))
763 763
764 else: 764 else:
765 self.paths = [] 765 self.paths = []
766 self.do_read = True 766 self.do_read = True
767 self.reset() 767
768 def _verify_paths(self):
769 """Remove invalid paths"""
770 for path in self.paths:
771 if not os.path.exists(os.path.join(PATH_DEBUGFS_KVM, path)):
772 self.paths.remove(path)
773 continue
768 774
769 def read(self, reset=0, by_guest=0): 775 def read(self, reset=0, by_guest=0):
770 """Returns a dict with format:'file name / field -> current value'. 776 """Returns a dict with format:'file name / field -> current value'.
@@ -780,6 +786,7 @@ class DebugfsProvider(Provider):
780 # If no debugfs filtering support is available, then don't read. 786 # If no debugfs filtering support is available, then don't read.
781 if not self.do_read: 787 if not self.do_read:
782 return results 788 return results
789 self._verify_paths()
783 790
784 paths = self.paths 791 paths = self.paths
785 if self._pid == 0: 792 if self._pid == 0:
@@ -1096,15 +1103,16 @@ class Tui(object):
1096 pid = self.stats.pid_filter 1103 pid = self.stats.pid_filter
1097 self.screen.erase() 1104 self.screen.erase()
1098 gname = self.get_gname_from_pid(pid) 1105 gname = self.get_gname_from_pid(pid)
1106 self._gname = gname
1099 if gname: 1107 if gname:
1100 gname = ('({})'.format(gname[:MAX_GUEST_NAME_LEN] + '...' 1108 gname = ('({})'.format(gname[:MAX_GUEST_NAME_LEN] + '...'
1101 if len(gname) > MAX_GUEST_NAME_LEN 1109 if len(gname) > MAX_GUEST_NAME_LEN
1102 else gname)) 1110 else gname))
1103 if pid > 0: 1111 if pid > 0:
1104 self.screen.addstr(0, 0, 'kvm statistics - pid {0} {1}' 1112 self._headline = 'kvm statistics - pid {0} {1}'.format(pid, gname)
1105 .format(pid, gname), curses.A_BOLD)
1106 else: 1113 else:
1107 self.screen.addstr(0, 0, 'kvm statistics - summary', curses.A_BOLD) 1114 self._headline = 'kvm statistics - summary'
1115 self.screen.addstr(0, 0, self._headline, curses.A_BOLD)
1108 if self.stats.fields_filter: 1116 if self.stats.fields_filter:
1109 regex = self.stats.fields_filter 1117 regex = self.stats.fields_filter
1110 if len(regex) > MAX_REGEX_LEN: 1118 if len(regex) > MAX_REGEX_LEN:
@@ -1162,6 +1170,19 @@ class Tui(object):
1162 1170
1163 return sorted_items 1171 return sorted_items
1164 1172
1173 if not self._is_running_guest(self.stats.pid_filter):
1174 if self._gname:
1175 try: # ...to identify the guest by name in case it's back
1176 pids = self.get_pid_from_gname(self._gname)
1177 if len(pids) == 1:
1178 self._refresh_header(pids[0])
1179 self._update_pid(pids[0])
1180 return
1181 except:
1182 pass
1183 self._display_guest_dead()
1184 # leave final data on screen
1185 return
1165 row = 3 1186 row = 3
1166 self.screen.move(row, 0) 1187 self.screen.move(row, 0)
1167 self.screen.clrtobot() 1188 self.screen.clrtobot()
@@ -1184,6 +1205,7 @@ class Tui(object):
1184 # print events 1205 # print events
1185 tavg = 0 1206 tavg = 0
1186 tcur = 0 1207 tcur = 0
1208 guest_removed = False
1187 for key, values in get_sorted_events(self, stats): 1209 for key, values in get_sorted_events(self, stats):
1188 if row >= self.screen.getmaxyx()[0] - 1 or values == (0, 0): 1210 if row >= self.screen.getmaxyx()[0] - 1 or values == (0, 0):
1189 break 1211 break
@@ -1191,7 +1213,10 @@ class Tui(object):
1191 key = self.get_gname_from_pid(key) 1213 key = self.get_gname_from_pid(key)
1192 if not key: 1214 if not key:
1193 continue 1215 continue
1194 cur = int(round(values.delta / sleeptime)) if values.delta else '' 1216 cur = int(round(values.delta / sleeptime)) if values.delta else 0
1217 if cur < 0:
1218 guest_removed = True
1219 continue
1195 if key[0] != ' ': 1220 if key[0] != ' ':
1196 if values.delta: 1221 if values.delta:
1197 tcur += values.delta 1222 tcur += values.delta
@@ -1204,13 +1229,21 @@ class Tui(object):
1204 values.value * 100 / float(ltotal), cur)) 1229 values.value * 100 / float(ltotal), cur))
1205 row += 1 1230 row += 1
1206 if row == 3: 1231 if row == 3:
1207 self.screen.addstr(4, 1, 'No matching events reported yet') 1232 if guest_removed:
1233 self.screen.addstr(4, 1, 'Guest removed, updating...')
1234 else:
1235 self.screen.addstr(4, 1, 'No matching events reported yet')
1208 if row > 4: 1236 if row > 4:
1209 tavg = int(round(tcur / sleeptime)) if tcur > 0 else '' 1237 tavg = int(round(tcur / sleeptime)) if tcur > 0 else ''
1210 self.screen.addstr(row, 1, '%-40s %10d %8s' % 1238 self.screen.addstr(row, 1, '%-40s %10d %8s' %
1211 ('Total', total, tavg), curses.A_BOLD) 1239 ('Total', total, tavg), curses.A_BOLD)
1212 self.screen.refresh() 1240 self.screen.refresh()
1213 1241
1242 def _display_guest_dead(self):
1243 marker = ' Guest is DEAD '
1244 y = min(len(self._headline), 80 - len(marker))
1245 self.screen.addstr(0, y, marker, curses.A_BLINK | curses.A_STANDOUT)
1246
1214 def _show_msg(self, text): 1247 def _show_msg(self, text):
1215 """Display message centered text and exit on key press""" 1248 """Display message centered text and exit on key press"""
1216 hint = 'Press any key to continue' 1249 hint = 'Press any key to continue'
@@ -1219,10 +1252,10 @@ class Tui(object):
1219 (x, term_width) = self.screen.getmaxyx() 1252 (x, term_width) = self.screen.getmaxyx()
1220 row = 2 1253 row = 2
1221 for line in text: 1254 for line in text:
1222 start = (term_width - len(line)) / 2 1255 start = (term_width - len(line)) // 2
1223 self.screen.addstr(row, start, line) 1256 self.screen.addstr(row, start, line)
1224 row += 1 1257 row += 1
1225 self.screen.addstr(row + 1, (term_width - len(hint)) / 2, hint, 1258 self.screen.addstr(row + 1, (term_width - len(hint)) // 2, hint,
1226 curses.A_STANDOUT) 1259 curses.A_STANDOUT)
1227 self.screen.getkey() 1260 self.screen.getkey()
1228 1261
@@ -1319,6 +1352,12 @@ class Tui(object):
1319 msg = '"' + str(val) + '": Invalid value' 1352 msg = '"' + str(val) + '": Invalid value'
1320 self._refresh_header() 1353 self._refresh_header()
1321 1354
1355 def _is_running_guest(self, pid):
1356 """Check if pid is still a running process."""
1357 if not pid:
1358 return True
1359 return os.path.isdir(os.path.join('/proc/', str(pid)))
1360
1322 def _show_vm_selection_by_guest(self): 1361 def _show_vm_selection_by_guest(self):
1323 """Draws guest selection mask. 1362 """Draws guest selection mask.
1324 1363
@@ -1346,7 +1385,7 @@ class Tui(object):
1346 if not guest or guest == '0': 1385 if not guest or guest == '0':
1347 break 1386 break
1348 if guest.isdigit(): 1387 if guest.isdigit():
1349 if not os.path.isdir(os.path.join('/proc/', guest)): 1388 if not self._is_running_guest(guest):
1350 msg = '"' + guest + '": Not a running process' 1389 msg = '"' + guest + '": Not a running process'
1351 continue 1390 continue
1352 pid = int(guest) 1391 pid = int(guest)
diff --git a/tools/lib/lockdep/Makefile b/tools/lib/lockdep/Makefile
index 9b0ca3ad1ef3..9dafb8cb752f 100644
--- a/tools/lib/lockdep/Makefile
+++ b/tools/lib/lockdep/Makefile
@@ -129,12 +129,12 @@ $(OUTPUT)liblockdep.a: $(LIB_IN)
129tags: force 129tags: force
130 $(RM) tags 130 $(RM) tags
131 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 131 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
132 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' 132 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
133 133
134TAGS: force 134TAGS: force
135 $(RM) TAGS 135 $(RM) TAGS
136 find . -name '*.[ch]' | xargs etags \ 136 find . -name '*.[ch]' | xargs etags \
137 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' 137 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
138 138
139define do_install 139define do_install
140 $(print_install) \ 140 $(print_install) \
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
index 46cd5f871ad7..0b4e833088a4 100644
--- a/tools/lib/traceevent/Makefile
+++ b/tools/lib/traceevent/Makefile
@@ -233,12 +233,12 @@ endef
233tags: force 233tags: force
234 $(RM) tags 234 $(RM) tags
235 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 235 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
236 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' 236 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
237 237
238TAGS: force 238TAGS: force
239 $(RM) TAGS 239 $(RM) TAGS
240 find . -name '*.[ch]' | xargs etags \ 240 find . -name '*.[ch]' | xargs etags \
241 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' 241 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
242 242
243define do_install_mkdir 243define do_install_mkdir
244 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 244 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index e5f2acbb70cc..ce1e20227c64 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -1,21 +1,7 @@
1// SPDX-License-Identifier: LGPL-2.1
1/* 2/*
2 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 * 4 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 * 5 *
20 * The parts for function graph printing was taken and modified from the 6 * The parts for function graph printing was taken and modified from the
21 * Linux Kernel that were written by 7 * Linux Kernel that were written by
@@ -73,12 +59,12 @@ static void init_input_buf(const char *buf, unsigned long long size)
73 input_buf_ptr = 0; 59 input_buf_ptr = 0;
74} 60}
75 61
76const char *pevent_get_input_buf(void) 62const char *tep_get_input_buf(void)
77{ 63{
78 return input_buf; 64 return input_buf;
79} 65}
80 66
81unsigned long long pevent_get_input_buf_ptr(void) 67unsigned long long tep_get_input_buf_ptr(void)
82{ 68{
83 return input_buf_ptr; 69 return input_buf_ptr;
84} 70}
@@ -88,21 +74,21 @@ struct event_handler {
88 int id; 74 int id;
89 const char *sys_name; 75 const char *sys_name;
90 const char *event_name; 76 const char *event_name;
91 pevent_event_handler_func func; 77 tep_event_handler_func func;
92 void *context; 78 void *context;
93}; 79};
94 80
95struct pevent_func_params { 81struct func_params {
96 struct pevent_func_params *next; 82 struct func_params *next;
97 enum pevent_func_arg_type type; 83 enum tep_func_arg_type type;
98}; 84};
99 85
100struct pevent_function_handler { 86struct tep_function_handler {
101 struct pevent_function_handler *next; 87 struct tep_function_handler *next;
102 enum pevent_func_arg_type ret_type; 88 enum tep_func_arg_type ret_type;
103 char *name; 89 char *name;
104 pevent_func_handler func; 90 tep_func_handler func;
105 struct pevent_func_params *params; 91 struct func_params *params;
106 int nr_args; 92 int nr_args;
107}; 93};
108 94
@@ -110,17 +96,17 @@ static unsigned long long
110process_defined_func(struct trace_seq *s, void *data, int size, 96process_defined_func(struct trace_seq *s, void *data, int size,
111 struct event_format *event, struct print_arg *arg); 97 struct event_format *event, struct print_arg *arg);
112 98
113static void free_func_handle(struct pevent_function_handler *func); 99static void free_func_handle(struct tep_function_handler *func);
114 100
115/** 101/**
116 * pevent_buffer_init - init buffer for parsing 102 * tep_buffer_init - init buffer for parsing
117 * @buf: buffer to parse 103 * @buf: buffer to parse
118 * @size: the size of the buffer 104 * @size: the size of the buffer
119 * 105 *
120 * For use with pevent_read_token(), this initializes the internal 106 * For use with tep_read_token(), this initializes the internal
121 * buffer that pevent_read_token() will parse. 107 * buffer that tep_read_token() will parse.
122 */ 108 */
123void pevent_buffer_init(const char *buf, unsigned long long size) 109void tep_buffer_init(const char *buf, unsigned long long size)
124{ 110{
125 init_input_buf(buf, size); 111 init_input_buf(buf, size);
126} 112}
@@ -160,7 +146,7 @@ struct cmdline_list {
160 int pid; 146 int pid;
161}; 147};
162 148
163static int cmdline_init(struct pevent *pevent) 149static int cmdline_init(struct tep_handle *pevent)
164{ 150{
165 struct cmdline_list *cmdlist = pevent->cmdlist; 151 struct cmdline_list *cmdlist = pevent->cmdlist;
166 struct cmdline_list *item; 152 struct cmdline_list *item;
@@ -189,7 +175,7 @@ static int cmdline_init(struct pevent *pevent)
189 return 0; 175 return 0;
190} 176}
191 177
192static const char *find_cmdline(struct pevent *pevent, int pid) 178static const char *find_cmdline(struct tep_handle *pevent, int pid)
193{ 179{
194 const struct cmdline *comm; 180 const struct cmdline *comm;
195 struct cmdline key; 181 struct cmdline key;
@@ -211,14 +197,14 @@ static const char *find_cmdline(struct pevent *pevent, int pid)
211} 197}
212 198
213/** 199/**
214 * pevent_pid_is_registered - return if a pid has a cmdline registered 200 * tep_pid_is_registered - return if a pid has a cmdline registered
215 * @pevent: handle for the pevent 201 * @pevent: handle for the pevent
216 * @pid: The pid to check if it has a cmdline registered with. 202 * @pid: The pid to check if it has a cmdline registered with.
217 * 203 *
218 * Returns 1 if the pid has a cmdline mapped to it 204 * Returns 1 if the pid has a cmdline mapped to it
219 * 0 otherwise. 205 * 0 otherwise.
220 */ 206 */
221int pevent_pid_is_registered(struct pevent *pevent, int pid) 207int tep_pid_is_registered(struct tep_handle *pevent, int pid)
222{ 208{
223 const struct cmdline *comm; 209 const struct cmdline *comm;
224 struct cmdline key; 210 struct cmdline key;
@@ -244,7 +230,7 @@ int pevent_pid_is_registered(struct pevent *pevent, int pid)
244 * we must add this pid. This is much slower than when cmdlines 230 * we must add this pid. This is much slower than when cmdlines
245 * are added before the array is initialized. 231 * are added before the array is initialized.
246 */ 232 */
247static int add_new_comm(struct pevent *pevent, const char *comm, int pid) 233static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid)
248{ 234{
249 struct cmdline *cmdlines = pevent->cmdlines; 235 struct cmdline *cmdlines = pevent->cmdlines;
250 const struct cmdline *cmdline; 236 const struct cmdline *cmdline;
@@ -288,7 +274,7 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
288} 274}
289 275
290/** 276/**
291 * pevent_register_comm - register a pid / comm mapping 277 * tep_register_comm - register a pid / comm mapping
292 * @pevent: handle for the pevent 278 * @pevent: handle for the pevent
293 * @comm: the command line to register 279 * @comm: the command line to register
294 * @pid: the pid to map the command line to 280 * @pid: the pid to map the command line to
@@ -296,7 +282,7 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
296 * This adds a mapping to search for command line names with 282 * This adds a mapping to search for command line names with
297 * a given pid. The comm is duplicated. 283 * a given pid. The comm is duplicated.
298 */ 284 */
299int pevent_register_comm(struct pevent *pevent, const char *comm, int pid) 285int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid)
300{ 286{
301 struct cmdline_list *item; 287 struct cmdline_list *item;
302 288
@@ -324,7 +310,7 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
324 return 0; 310 return 0;
325} 311}
326 312
327int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock) 313int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock)
328{ 314{
329 pevent->trace_clock = strdup(trace_clock); 315 pevent->trace_clock = strdup(trace_clock);
330 if (!pevent->trace_clock) { 316 if (!pevent->trace_clock) {
@@ -381,7 +367,7 @@ static int func_bcmp(const void *a, const void *b)
381 return 1; 367 return 1;
382} 368}
383 369
384static int func_map_init(struct pevent *pevent) 370static int func_map_init(struct tep_handle *pevent)
385{ 371{
386 struct func_list *funclist; 372 struct func_list *funclist;
387 struct func_list *item; 373 struct func_list *item;
@@ -421,7 +407,7 @@ static int func_map_init(struct pevent *pevent)
421} 407}
422 408
423static struct func_map * 409static struct func_map *
424__find_func(struct pevent *pevent, unsigned long long addr) 410__find_func(struct tep_handle *pevent, unsigned long long addr)
425{ 411{
426 struct func_map *func; 412 struct func_map *func;
427 struct func_map key; 413 struct func_map key;
@@ -438,13 +424,13 @@ __find_func(struct pevent *pevent, unsigned long long addr)
438} 424}
439 425
440struct func_resolver { 426struct func_resolver {
441 pevent_func_resolver_t *func; 427 tep_func_resolver_t *func;
442 void *priv; 428 void *priv;
443 struct func_map map; 429 struct func_map map;
444}; 430};
445 431
446/** 432/**
447 * pevent_set_function_resolver - set an alternative function resolver 433 * tep_set_function_resolver - set an alternative function resolver
448 * @pevent: handle for the pevent 434 * @pevent: handle for the pevent
449 * @resolver: function to be used 435 * @resolver: function to be used
450 * @priv: resolver function private state. 436 * @priv: resolver function private state.
@@ -453,8 +439,8 @@ struct func_resolver {
453 * keep using it instead of duplicating all the entries inside 439 * keep using it instead of duplicating all the entries inside
454 * pevent->funclist. 440 * pevent->funclist.
455 */ 441 */
456int pevent_set_function_resolver(struct pevent *pevent, 442int tep_set_function_resolver(struct tep_handle *pevent,
457 pevent_func_resolver_t *func, void *priv) 443 tep_func_resolver_t *func, void *priv)
458{ 444{
459 struct func_resolver *resolver = malloc(sizeof(*resolver)); 445 struct func_resolver *resolver = malloc(sizeof(*resolver));
460 446
@@ -471,20 +457,20 @@ int pevent_set_function_resolver(struct pevent *pevent,
471} 457}
472 458
473/** 459/**
474 * pevent_reset_function_resolver - reset alternative function resolver 460 * tep_reset_function_resolver - reset alternative function resolver
475 * @pevent: handle for the pevent 461 * @pevent: handle for the pevent
476 * 462 *
477 * Stop using whatever alternative resolver was set, use the default 463 * Stop using whatever alternative resolver was set, use the default
478 * one instead. 464 * one instead.
479 */ 465 */
480void pevent_reset_function_resolver(struct pevent *pevent) 466void tep_reset_function_resolver(struct tep_handle *pevent)
481{ 467{
482 free(pevent->func_resolver); 468 free(pevent->func_resolver);
483 pevent->func_resolver = NULL; 469 pevent->func_resolver = NULL;
484} 470}
485 471
486static struct func_map * 472static struct func_map *
487find_func(struct pevent *pevent, unsigned long long addr) 473find_func(struct tep_handle *pevent, unsigned long long addr)
488{ 474{
489 struct func_map *map; 475 struct func_map *map;
490 476
@@ -503,7 +489,7 @@ find_func(struct pevent *pevent, unsigned long long addr)
503} 489}
504 490
505/** 491/**
506 * pevent_find_function - find a function by a given address 492 * tep_find_function - find a function by a given address
507 * @pevent: handle for the pevent 493 * @pevent: handle for the pevent
508 * @addr: the address to find the function with 494 * @addr: the address to find the function with
509 * 495 *
@@ -511,7 +497,7 @@ find_func(struct pevent *pevent, unsigned long long addr)
511 * address. Note, the address does not have to be exact, it 497 * address. Note, the address does not have to be exact, it
512 * will select the function that would contain the address. 498 * will select the function that would contain the address.
513 */ 499 */
514const char *pevent_find_function(struct pevent *pevent, unsigned long long addr) 500const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr)
515{ 501{
516 struct func_map *map; 502 struct func_map *map;
517 503
@@ -523,16 +509,16 @@ const char *pevent_find_function(struct pevent *pevent, unsigned long long addr)
523} 509}
524 510
525/** 511/**
526 * pevent_find_function_address - find a function address by a given address 512 * tep_find_function_address - find a function address by a given address
527 * @pevent: handle for the pevent 513 * @pevent: handle for the pevent
528 * @addr: the address to find the function with 514 * @addr: the address to find the function with
529 * 515 *
530 * Returns the address the function starts at. This can be used in 516 * Returns the address the function starts at. This can be used in
531 * conjunction with pevent_find_function to print both the function 517 * conjunction with tep_find_function to print both the function
532 * name and the function offset. 518 * name and the function offset.
533 */ 519 */
534unsigned long long 520unsigned long long
535pevent_find_function_address(struct pevent *pevent, unsigned long long addr) 521tep_find_function_address(struct tep_handle *pevent, unsigned long long addr)
536{ 522{
537 struct func_map *map; 523 struct func_map *map;
538 524
@@ -544,7 +530,7 @@ pevent_find_function_address(struct pevent *pevent, unsigned long long addr)
544} 530}
545 531
546/** 532/**
547 * pevent_register_function - register a function with a given address 533 * tep_register_function - register a function with a given address
548 * @pevent: handle for the pevent 534 * @pevent: handle for the pevent
549 * @function: the function name to register 535 * @function: the function name to register
550 * @addr: the address the function starts at 536 * @addr: the address the function starts at
@@ -553,8 +539,8 @@ pevent_find_function_address(struct pevent *pevent, unsigned long long addr)
553 * This registers a function name with an address and module. 539 * This registers a function name with an address and module.
554 * The @func passed in is duplicated. 540 * The @func passed in is duplicated.
555 */ 541 */
556int pevent_register_function(struct pevent *pevent, char *func, 542int tep_register_function(struct tep_handle *pevent, char *func,
557 unsigned long long addr, char *mod) 543 unsigned long long addr, char *mod)
558{ 544{
559 struct func_list *item = malloc(sizeof(*item)); 545 struct func_list *item = malloc(sizeof(*item));
560 546
@@ -589,12 +575,12 @@ out_free:
589} 575}
590 576
591/** 577/**
592 * pevent_print_funcs - print out the stored functions 578 * tep_print_funcs - print out the stored functions
593 * @pevent: handle for the pevent 579 * @pevent: handle for the pevent
594 * 580 *
595 * This prints out the stored functions. 581 * This prints out the stored functions.
596 */ 582 */
597void pevent_print_funcs(struct pevent *pevent) 583void tep_print_funcs(struct tep_handle *pevent)
598{ 584{
599 int i; 585 int i;
600 586
@@ -636,7 +622,7 @@ static int printk_cmp(const void *a, const void *b)
636 return 0; 622 return 0;
637} 623}
638 624
639static int printk_map_init(struct pevent *pevent) 625static int printk_map_init(struct tep_handle *pevent)
640{ 626{
641 struct printk_list *printklist; 627 struct printk_list *printklist;
642 struct printk_list *item; 628 struct printk_list *item;
@@ -668,7 +654,7 @@ static int printk_map_init(struct pevent *pevent)
668} 654}
669 655
670static struct printk_map * 656static struct printk_map *
671find_printk(struct pevent *pevent, unsigned long long addr) 657find_printk(struct tep_handle *pevent, unsigned long long addr)
672{ 658{
673 struct printk_map *printk; 659 struct printk_map *printk;
674 struct printk_map key; 660 struct printk_map key;
@@ -685,7 +671,7 @@ find_printk(struct pevent *pevent, unsigned long long addr)
685} 671}
686 672
687/** 673/**
688 * pevent_register_print_string - register a string by its address 674 * tep_register_print_string - register a string by its address
689 * @pevent: handle for the pevent 675 * @pevent: handle for the pevent
690 * @fmt: the string format to register 676 * @fmt: the string format to register
691 * @addr: the address the string was located at 677 * @addr: the address the string was located at
@@ -693,8 +679,8 @@ find_printk(struct pevent *pevent, unsigned long long addr)
693 * This registers a string by the address it was stored in the kernel. 679 * This registers a string by the address it was stored in the kernel.
694 * The @fmt passed in is duplicated. 680 * The @fmt passed in is duplicated.
695 */ 681 */
696int pevent_register_print_string(struct pevent *pevent, const char *fmt, 682int tep_register_print_string(struct tep_handle *pevent, const char *fmt,
697 unsigned long long addr) 683 unsigned long long addr)
698{ 684{
699 struct printk_list *item = malloc(sizeof(*item)); 685 struct printk_list *item = malloc(sizeof(*item));
700 char *p; 686 char *p;
@@ -732,12 +718,12 @@ out_free:
732} 718}
733 719
734/** 720/**
735 * pevent_print_printk - print out the stored strings 721 * tep_print_printk - print out the stored strings
736 * @pevent: handle for the pevent 722 * @pevent: handle for the pevent
737 * 723 *
738 * This prints the string formats that were stored. 724 * This prints the string formats that were stored.
739 */ 725 */
740void pevent_print_printk(struct pevent *pevent) 726void tep_print_printk(struct tep_handle *pevent)
741{ 727{
742 int i; 728 int i;
743 729
@@ -756,7 +742,7 @@ static struct event_format *alloc_event(void)
756 return calloc(1, sizeof(struct event_format)); 742 return calloc(1, sizeof(struct event_format));
757} 743}
758 744
759static int add_event(struct pevent *pevent, struct event_format *event) 745static int add_event(struct tep_handle *pevent, struct event_format *event)
760{ 746{
761 int i; 747 int i;
762 struct event_format **events = realloc(pevent->events, sizeof(event) * 748 struct event_format **events = realloc(pevent->events, sizeof(event) *
@@ -913,11 +899,11 @@ static int __peek_char(void)
913} 899}
914 900
915/** 901/**
916 * pevent_peek_char - peek at the next character that will be read 902 * tep_peek_char - peek at the next character that will be read
917 * 903 *
918 * Returns the next character read, or -1 if end of buffer. 904 * Returns the next character read, or -1 if end of buffer.
919 */ 905 */
920int pevent_peek_char(void) 906int tep_peek_char(void)
921{ 907{
922 return __peek_char(); 908 return __peek_char();
923} 909}
@@ -1157,24 +1143,24 @@ static enum event_type read_token(char **tok)
1157} 1143}
1158 1144
1159/** 1145/**
1160 * pevent_read_token - access to utilites to use the pevent parser 1146 * tep_read_token - access to utilites to use the pevent parser
1161 * @tok: The token to return 1147 * @tok: The token to return
1162 * 1148 *
1163 * This will parse tokens from the string given by 1149 * This will parse tokens from the string given by
1164 * pevent_init_data(). 1150 * tep_init_data().
1165 * 1151 *
1166 * Returns the token type. 1152 * Returns the token type.
1167 */ 1153 */
1168enum event_type pevent_read_token(char **tok) 1154enum event_type tep_read_token(char **tok)
1169{ 1155{
1170 return read_token(tok); 1156 return read_token(tok);
1171} 1157}
1172 1158
1173/** 1159/**
1174 * pevent_free_token - free a token returned by pevent_read_token 1160 * tep_free_token - free a token returned by tep_read_token
1175 * @token: the token to free 1161 * @token: the token to free
1176 */ 1162 */
1177void pevent_free_token(char *token) 1163void tep_free_token(char *token)
1178{ 1164{
1179 free_token(token); 1165 free_token(token);
1180} 1166}
@@ -2101,11 +2087,11 @@ process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
2101 arg->field.name = field; 2087 arg->field.name = field;
2102 2088
2103 if (is_flag_field) { 2089 if (is_flag_field) {
2104 arg->field.field = pevent_find_any_field(event, arg->field.name); 2090 arg->field.field = tep_find_any_field(event, arg->field.name);
2105 arg->field.field->flags |= FIELD_IS_FLAG; 2091 arg->field.field->flags |= FIELD_IS_FLAG;
2106 is_flag_field = 0; 2092 is_flag_field = 0;
2107 } else if (is_symbolic_field) { 2093 } else if (is_symbolic_field) {
2108 arg->field.field = pevent_find_any_field(event, arg->field.name); 2094 arg->field.field = tep_find_any_field(event, arg->field.name);
2109 arg->field.field->flags |= FIELD_IS_SYMBOLIC; 2095 arg->field.field->flags |= FIELD_IS_SYMBOLIC;
2110 is_symbolic_field = 0; 2096 is_symbolic_field = 0;
2111 } 2097 }
@@ -2714,7 +2700,7 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
2714 2700
2715 /* Find the field */ 2701 /* Find the field */
2716 2702
2717 field = pevent_find_field(event, token); 2703 field = tep_find_field(event, token);
2718 if (!field) 2704 if (!field)
2719 goto out_free; 2705 goto out_free;
2720 2706
@@ -2771,7 +2757,7 @@ process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
2771 arg->type = PRINT_DYNAMIC_ARRAY_LEN; 2757 arg->type = PRINT_DYNAMIC_ARRAY_LEN;
2772 2758
2773 /* Find the field */ 2759 /* Find the field */
2774 field = pevent_find_field(event, token); 2760 field = tep_find_field(event, token);
2775 if (!field) 2761 if (!field)
2776 goto out_free; 2762 goto out_free;
2777 2763
@@ -2914,10 +2900,10 @@ process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg
2914 return EVENT_ERROR; 2900 return EVENT_ERROR;
2915} 2901}
2916 2902
2917static struct pevent_function_handler * 2903static struct tep_function_handler *
2918find_func_handler(struct pevent *pevent, char *func_name) 2904find_func_handler(struct tep_handle *pevent, char *func_name)
2919{ 2905{
2920 struct pevent_function_handler *func; 2906 struct tep_function_handler *func;
2921 2907
2922 if (!pevent) 2908 if (!pevent)
2923 return NULL; 2909 return NULL;
@@ -2930,10 +2916,10 @@ find_func_handler(struct pevent *pevent, char *func_name)
2930 return func; 2916 return func;
2931} 2917}
2932 2918
2933static void remove_func_handler(struct pevent *pevent, char *func_name) 2919static void remove_func_handler(struct tep_handle *pevent, char *func_name)
2934{ 2920{
2935 struct pevent_function_handler *func; 2921 struct tep_function_handler *func;
2936 struct pevent_function_handler **next; 2922 struct tep_function_handler **next;
2937 2923
2938 next = &pevent->func_handlers; 2924 next = &pevent->func_handlers;
2939 while ((func = *next)) { 2925 while ((func = *next)) {
@@ -2947,7 +2933,7 @@ static void remove_func_handler(struct pevent *pevent, char *func_name)
2947} 2933}
2948 2934
2949static enum event_type 2935static enum event_type
2950process_func_handler(struct event_format *event, struct pevent_function_handler *func, 2936process_func_handler(struct event_format *event, struct tep_function_handler *func,
2951 struct print_arg *arg, char **tok) 2937 struct print_arg *arg, char **tok)
2952{ 2938{
2953 struct print_arg **next_arg; 2939 struct print_arg **next_arg;
@@ -3008,7 +2994,7 @@ static enum event_type
3008process_function(struct event_format *event, struct print_arg *arg, 2994process_function(struct event_format *event, struct print_arg *arg,
3009 char *token, char **tok) 2995 char *token, char **tok)
3010{ 2996{
3011 struct pevent_function_handler *func; 2997 struct tep_function_handler *func;
3012 2998
3013 if (strcmp(token, "__print_flags") == 0) { 2999 if (strcmp(token, "__print_flags") == 0) {
3014 free_token(token); 3000 free_token(token);
@@ -3265,7 +3251,7 @@ static int event_read_print(struct event_format *event)
3265} 3251}
3266 3252
3267/** 3253/**
3268 * pevent_find_common_field - return a common field by event 3254 * tep_find_common_field - return a common field by event
3269 * @event: handle for the event 3255 * @event: handle for the event
3270 * @name: the name of the common field to return 3256 * @name: the name of the common field to return
3271 * 3257 *
@@ -3273,7 +3259,7 @@ static int event_read_print(struct event_format *event)
3273 * This only searchs the common fields and not all field. 3259 * This only searchs the common fields and not all field.
3274 */ 3260 */
3275struct format_field * 3261struct format_field *
3276pevent_find_common_field(struct event_format *event, const char *name) 3262tep_find_common_field(struct event_format *event, const char *name)
3277{ 3263{
3278 struct format_field *format; 3264 struct format_field *format;
3279 3265
@@ -3287,7 +3273,7 @@ pevent_find_common_field(struct event_format *event, const char *name)
3287} 3273}
3288 3274
3289/** 3275/**
3290 * pevent_find_field - find a non-common field 3276 * tep_find_field - find a non-common field
3291 * @event: handle for the event 3277 * @event: handle for the event
3292 * @name: the name of the non-common field 3278 * @name: the name of the non-common field
3293 * 3279 *
@@ -3295,7 +3281,7 @@ pevent_find_common_field(struct event_format *event, const char *name)
3295 * This does not search common fields. 3281 * This does not search common fields.
3296 */ 3282 */
3297struct format_field * 3283struct format_field *
3298pevent_find_field(struct event_format *event, const char *name) 3284tep_find_field(struct event_format *event, const char *name)
3299{ 3285{
3300 struct format_field *format; 3286 struct format_field *format;
3301 3287
@@ -3309,7 +3295,7 @@ pevent_find_field(struct event_format *event, const char *name)
3309} 3295}
3310 3296
3311/** 3297/**
3312 * pevent_find_any_field - find any field by name 3298 * tep_find_any_field - find any field by name
3313 * @event: handle for the event 3299 * @event: handle for the event
3314 * @name: the name of the field 3300 * @name: the name of the field
3315 * 3301 *
@@ -3318,18 +3304,18 @@ pevent_find_field(struct event_format *event, const char *name)
3318 * the non-common ones if a common one was not found. 3304 * the non-common ones if a common one was not found.
3319 */ 3305 */
3320struct format_field * 3306struct format_field *
3321pevent_find_any_field(struct event_format *event, const char *name) 3307tep_find_any_field(struct event_format *event, const char *name)
3322{ 3308{
3323 struct format_field *format; 3309 struct format_field *format;
3324 3310
3325 format = pevent_find_common_field(event, name); 3311 format = tep_find_common_field(event, name);
3326 if (format) 3312 if (format)
3327 return format; 3313 return format;
3328 return pevent_find_field(event, name); 3314 return tep_find_field(event, name);
3329} 3315}
3330 3316
3331/** 3317/**
3332 * pevent_read_number - read a number from data 3318 * tep_read_number - read a number from data
3333 * @pevent: handle for the pevent 3319 * @pevent: handle for the pevent
3334 * @ptr: the raw data 3320 * @ptr: the raw data
3335 * @size: the size of the data that holds the number 3321 * @size: the size of the data that holds the number
@@ -3337,8 +3323,8 @@ pevent_find_any_field(struct event_format *event, const char *name)
3337 * Returns the number (converted to host) from the 3323 * Returns the number (converted to host) from the
3338 * raw data. 3324 * raw data.
3339 */ 3325 */
3340unsigned long long pevent_read_number(struct pevent *pevent, 3326unsigned long long tep_read_number(struct tep_handle *pevent,
3341 const void *ptr, int size) 3327 const void *ptr, int size)
3342{ 3328{
3343 switch (size) { 3329 switch (size) {
3344 case 1: 3330 case 1:
@@ -3356,7 +3342,7 @@ unsigned long long pevent_read_number(struct pevent *pevent,
3356} 3342}
3357 3343
3358/** 3344/**
3359 * pevent_read_number_field - read a number from data 3345 * tep_read_number_field - read a number from data
3360 * @field: a handle to the field 3346 * @field: a handle to the field
3361 * @data: the raw data to read 3347 * @data: the raw data to read
3362 * @value: the value to place the number in 3348 * @value: the value to place the number in
@@ -3366,8 +3352,8 @@ unsigned long long pevent_read_number(struct pevent *pevent,
3366 * 3352 *
3367 * Returns 0 on success, -1 otherwise. 3353 * Returns 0 on success, -1 otherwise.
3368 */ 3354 */
3369int pevent_read_number_field(struct format_field *field, const void *data, 3355int tep_read_number_field(struct format_field *field, const void *data,
3370 unsigned long long *value) 3356 unsigned long long *value)
3371{ 3357{
3372 if (!field) 3358 if (!field)
3373 return -1; 3359 return -1;
@@ -3376,15 +3362,15 @@ int pevent_read_number_field(struct format_field *field, const void *data,
3376 case 2: 3362 case 2:
3377 case 4: 3363 case 4:
3378 case 8: 3364 case 8:
3379 *value = pevent_read_number(field->event->pevent, 3365 *value = tep_read_number(field->event->pevent,
3380 data + field->offset, field->size); 3366 data + field->offset, field->size);
3381 return 0; 3367 return 0;
3382 default: 3368 default:
3383 return -1; 3369 return -1;
3384 } 3370 }
3385} 3371}
3386 3372
3387static int get_common_info(struct pevent *pevent, 3373static int get_common_info(struct tep_handle *pevent,
3388 const char *type, int *offset, int *size) 3374 const char *type, int *offset, int *size)
3389{ 3375{
3390 struct event_format *event; 3376 struct event_format *event;
@@ -3400,7 +3386,7 @@ static int get_common_info(struct pevent *pevent,
3400 } 3386 }
3401 3387
3402 event = pevent->events[0]; 3388 event = pevent->events[0];
3403 field = pevent_find_common_field(event, type); 3389 field = tep_find_common_field(event, type);
3404 if (!field) 3390 if (!field)
3405 return -1; 3391 return -1;
3406 3392
@@ -3410,7 +3396,7 @@ static int get_common_info(struct pevent *pevent,
3410 return 0; 3396 return 0;
3411} 3397}
3412 3398
3413static int __parse_common(struct pevent *pevent, void *data, 3399static int __parse_common(struct tep_handle *pevent, void *data,
3414 int *size, int *offset, const char *name) 3400 int *size, int *offset, const char *name)
3415{ 3401{
3416 int ret; 3402 int ret;
@@ -3420,45 +3406,45 @@ static int __parse_common(struct pevent *pevent, void *data,
3420 if (ret < 0) 3406 if (ret < 0)
3421 return ret; 3407 return ret;
3422 } 3408 }
3423 return pevent_read_number(pevent, data + *offset, *size); 3409 return tep_read_number(pevent, data + *offset, *size);
3424} 3410}
3425 3411
3426static int trace_parse_common_type(struct pevent *pevent, void *data) 3412static int trace_parse_common_type(struct tep_handle *pevent, void *data)
3427{ 3413{
3428 return __parse_common(pevent, data, 3414 return __parse_common(pevent, data,
3429 &pevent->type_size, &pevent->type_offset, 3415 &pevent->type_size, &pevent->type_offset,
3430 "common_type"); 3416 "common_type");
3431} 3417}
3432 3418
3433static int parse_common_pid(struct pevent *pevent, void *data) 3419static int parse_common_pid(struct tep_handle *pevent, void *data)
3434{ 3420{
3435 return __parse_common(pevent, data, 3421 return __parse_common(pevent, data,
3436 &pevent->pid_size, &pevent->pid_offset, 3422 &pevent->pid_size, &pevent->pid_offset,
3437 "common_pid"); 3423 "common_pid");
3438} 3424}
3439 3425
3440static int parse_common_pc(struct pevent *pevent, void *data) 3426static int parse_common_pc(struct tep_handle *pevent, void *data)
3441{ 3427{
3442 return __parse_common(pevent, data, 3428 return __parse_common(pevent, data,
3443 &pevent->pc_size, &pevent->pc_offset, 3429 &pevent->pc_size, &pevent->pc_offset,
3444 "common_preempt_count"); 3430 "common_preempt_count");
3445} 3431}
3446 3432
3447static int parse_common_flags(struct pevent *pevent, void *data) 3433static int parse_common_flags(struct tep_handle *pevent, void *data)
3448{ 3434{
3449 return __parse_common(pevent, data, 3435 return __parse_common(pevent, data,
3450 &pevent->flags_size, &pevent->flags_offset, 3436 &pevent->flags_size, &pevent->flags_offset,
3451 "common_flags"); 3437 "common_flags");
3452} 3438}
3453 3439
3454static int parse_common_lock_depth(struct pevent *pevent, void *data) 3440static int parse_common_lock_depth(struct tep_handle *pevent, void *data)
3455{ 3441{
3456 return __parse_common(pevent, data, 3442 return __parse_common(pevent, data,
3457 &pevent->ld_size, &pevent->ld_offset, 3443 &pevent->ld_size, &pevent->ld_offset,
3458 "common_lock_depth"); 3444 "common_lock_depth");
3459} 3445}
3460 3446
3461static int parse_common_migrate_disable(struct pevent *pevent, void *data) 3447static int parse_common_migrate_disable(struct tep_handle *pevent, void *data)
3462{ 3448{
3463 return __parse_common(pevent, data, 3449 return __parse_common(pevent, data,
3464 &pevent->ld_size, &pevent->ld_offset, 3450 &pevent->ld_size, &pevent->ld_offset,
@@ -3468,13 +3454,13 @@ static int parse_common_migrate_disable(struct pevent *pevent, void *data)
3468static int events_id_cmp(const void *a, const void *b); 3454static int events_id_cmp(const void *a, const void *b);
3469 3455
3470/** 3456/**
3471 * pevent_find_event - find an event by given id 3457 * tep_find_event - find an event by given id
3472 * @pevent: a handle to the pevent 3458 * @pevent: a handle to the pevent
3473 * @id: the id of the event 3459 * @id: the id of the event
3474 * 3460 *
3475 * Returns an event that has a given @id. 3461 * Returns an event that has a given @id.
3476 */ 3462 */
3477struct event_format *pevent_find_event(struct pevent *pevent, int id) 3463struct event_format *tep_find_event(struct tep_handle *pevent, int id)
3478{ 3464{
3479 struct event_format **eventptr; 3465 struct event_format **eventptr;
3480 struct event_format key; 3466 struct event_format key;
@@ -3498,7 +3484,7 @@ struct event_format *pevent_find_event(struct pevent *pevent, int id)
3498} 3484}
3499 3485
3500/** 3486/**
3501 * pevent_find_event_by_name - find an event by given name 3487 * tep_find_event_by_name - find an event by given name
3502 * @pevent: a handle to the pevent 3488 * @pevent: a handle to the pevent
3503 * @sys: the system name to search for 3489 * @sys: the system name to search for
3504 * @name: the name of the event to search for 3490 * @name: the name of the event to search for
@@ -3507,8 +3493,8 @@ struct event_format *pevent_find_event(struct pevent *pevent, int id)
3507 * @sys. If @sys is NULL the first event with @name is returned. 3493 * @sys. If @sys is NULL the first event with @name is returned.
3508 */ 3494 */
3509struct event_format * 3495struct event_format *
3510pevent_find_event_by_name(struct pevent *pevent, 3496tep_find_event_by_name(struct tep_handle *pevent,
3511 const char *sys, const char *name) 3497 const char *sys, const char *name)
3512{ 3498{
3513 struct event_format *event; 3499 struct event_format *event;
3514 int i; 3500 int i;
@@ -3537,7 +3523,7 @@ pevent_find_event_by_name(struct pevent *pevent,
3537static unsigned long long 3523static unsigned long long
3538eval_num_arg(void *data, int size, struct event_format *event, struct print_arg *arg) 3524eval_num_arg(void *data, int size, struct event_format *event, struct print_arg *arg)
3539{ 3525{
3540 struct pevent *pevent = event->pevent; 3526 struct tep_handle *pevent = event->pevent;
3541 unsigned long long val = 0; 3527 unsigned long long val = 0;
3542 unsigned long long left, right; 3528 unsigned long long left, right;
3543 struct print_arg *typearg = NULL; 3529 struct print_arg *typearg = NULL;
@@ -3553,14 +3539,14 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3553 return strtoull(arg->atom.atom, NULL, 0); 3539 return strtoull(arg->atom.atom, NULL, 0);
3554 case PRINT_FIELD: 3540 case PRINT_FIELD:
3555 if (!arg->field.field) { 3541 if (!arg->field.field) {
3556 arg->field.field = pevent_find_any_field(event, arg->field.name); 3542 arg->field.field = tep_find_any_field(event, arg->field.name);
3557 if (!arg->field.field) 3543 if (!arg->field.field)
3558 goto out_warning_field; 3544 goto out_warning_field;
3559 3545
3560 } 3546 }
3561 /* must be a number */ 3547 /* must be a number */
3562 val = pevent_read_number(pevent, data + arg->field.field->offset, 3548 val = tep_read_number(pevent, data + arg->field.field->offset,
3563 arg->field.field->size); 3549 arg->field.field->size);
3564 break; 3550 break;
3565 case PRINT_FLAGS: 3551 case PRINT_FLAGS:
3566 case PRINT_SYMBOL: 3552 case PRINT_SYMBOL:
@@ -3603,7 +3589,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3603 3589
3604 switch (larg->type) { 3590 switch (larg->type) {
3605 case PRINT_DYNAMIC_ARRAY: 3591 case PRINT_DYNAMIC_ARRAY:
3606 offset = pevent_read_number(pevent, 3592 offset = tep_read_number(pevent,
3607 data + larg->dynarray.field->offset, 3593 data + larg->dynarray.field->offset,
3608 larg->dynarray.field->size); 3594 larg->dynarray.field->size);
3609 if (larg->dynarray.field->elementsize) 3595 if (larg->dynarray.field->elementsize)
@@ -3619,7 +3605,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3619 case PRINT_FIELD: 3605 case PRINT_FIELD:
3620 if (!larg->field.field) { 3606 if (!larg->field.field) {
3621 larg->field.field = 3607 larg->field.field =
3622 pevent_find_any_field(event, larg->field.name); 3608 tep_find_any_field(event, larg->field.name);
3623 if (!larg->field.field) { 3609 if (!larg->field.field) {
3624 arg = larg; 3610 arg = larg;
3625 goto out_warning_field; 3611 goto out_warning_field;
@@ -3632,8 +3618,8 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3632 default: 3618 default:
3633 goto default_op; /* oops, all bets off */ 3619 goto default_op; /* oops, all bets off */
3634 } 3620 }
3635 val = pevent_read_number(pevent, 3621 val = tep_read_number(pevent,
3636 data + offset, field_size); 3622 data + offset, field_size);
3637 if (typearg) 3623 if (typearg)
3638 val = eval_type(val, typearg, 1); 3624 val = eval_type(val, typearg, 1);
3639 break; 3625 break;
@@ -3733,9 +3719,9 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3733 } 3719 }
3734 break; 3720 break;
3735 case PRINT_DYNAMIC_ARRAY_LEN: 3721 case PRINT_DYNAMIC_ARRAY_LEN:
3736 offset = pevent_read_number(pevent, 3722 offset = tep_read_number(pevent,
3737 data + arg->dynarray.field->offset, 3723 data + arg->dynarray.field->offset,
3738 arg->dynarray.field->size); 3724 arg->dynarray.field->size);
3739 /* 3725 /*
3740 * The total allocated length of the dynamic array is 3726 * The total allocated length of the dynamic array is
3741 * stored in the top half of the field, and the offset 3727 * stored in the top half of the field, and the offset
@@ -3745,9 +3731,9 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3745 break; 3731 break;
3746 case PRINT_DYNAMIC_ARRAY: 3732 case PRINT_DYNAMIC_ARRAY:
3747 /* Without [], we pass the address to the dynamic data */ 3733 /* Without [], we pass the address to the dynamic data */
3748 offset = pevent_read_number(pevent, 3734 offset = tep_read_number(pevent,
3749 data + arg->dynarray.field->offset, 3735 data + arg->dynarray.field->offset,
3750 arg->dynarray.field->size); 3736 arg->dynarray.field->size);
3751 /* 3737 /*
3752 * The total allocated length of the dynamic array is 3738 * The total allocated length of the dynamic array is
3753 * stored in the top half of the field, and the offset 3739 * stored in the top half of the field, and the offset
@@ -3820,7 +3806,7 @@ static void print_str_to_seq(struct trace_seq *s, const char *format,
3820 trace_seq_printf(s, format, str); 3806 trace_seq_printf(s, format, str);
3821} 3807}
3822 3808
3823static void print_bitmask_to_seq(struct pevent *pevent, 3809static void print_bitmask_to_seq(struct tep_handle *pevent,
3824 struct trace_seq *s, const char *format, 3810 struct trace_seq *s, const char *format,
3825 int len_arg, const void *data, int size) 3811 int len_arg, const void *data, int size)
3826{ 3812{
@@ -3878,7 +3864,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3878 struct event_format *event, const char *format, 3864 struct event_format *event, const char *format,
3879 int len_arg, struct print_arg *arg) 3865 int len_arg, struct print_arg *arg)
3880{ 3866{
3881 struct pevent *pevent = event->pevent; 3867 struct tep_handle *pevent = event->pevent;
3882 struct print_flag_sym *flag; 3868 struct print_flag_sym *flag;
3883 struct format_field *field; 3869 struct format_field *field;
3884 struct printk_map *printk; 3870 struct printk_map *printk;
@@ -3899,7 +3885,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3899 case PRINT_FIELD: 3885 case PRINT_FIELD:
3900 field = arg->field.field; 3886 field = arg->field.field;
3901 if (!field) { 3887 if (!field) {
3902 field = pevent_find_any_field(event, arg->field.name); 3888 field = tep_find_any_field(event, arg->field.name);
3903 if (!field) { 3889 if (!field) {
3904 str = arg->field.name; 3890 str = arg->field.name;
3905 goto out_warning_field; 3891 goto out_warning_field;
@@ -3992,7 +3978,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3992 case PRINT_HEX_STR: 3978 case PRINT_HEX_STR:
3993 if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) { 3979 if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
3994 unsigned long offset; 3980 unsigned long offset;
3995 offset = pevent_read_number(pevent, 3981 offset = tep_read_number(pevent,
3996 data + arg->hex.field->dynarray.field->offset, 3982 data + arg->hex.field->dynarray.field->offset,
3997 arg->hex.field->dynarray.field->size); 3983 arg->hex.field->dynarray.field->size);
3998 hex = data + (offset & 0xffff); 3984 hex = data + (offset & 0xffff);
@@ -4000,7 +3986,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
4000 field = arg->hex.field->field.field; 3986 field = arg->hex.field->field.field;
4001 if (!field) { 3987 if (!field) {
4002 str = arg->hex.field->field.name; 3988 str = arg->hex.field->field.name;
4003 field = pevent_find_any_field(event, str); 3989 field = tep_find_any_field(event, str);
4004 if (!field) 3990 if (!field)
4005 goto out_warning_field; 3991 goto out_warning_field;
4006 arg->hex.field->field.field = field; 3992 arg->hex.field->field.field = field;
@@ -4023,15 +4009,15 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
4023 unsigned long offset; 4009 unsigned long offset;
4024 struct format_field *field = 4010 struct format_field *field =
4025 arg->int_array.field->dynarray.field; 4011 arg->int_array.field->dynarray.field;
4026 offset = pevent_read_number(pevent, 4012 offset = tep_read_number(pevent,
4027 data + field->offset, 4013 data + field->offset,
4028 field->size); 4014 field->size);
4029 num = data + (offset & 0xffff); 4015 num = data + (offset & 0xffff);
4030 } else { 4016 } else {
4031 field = arg->int_array.field->field.field; 4017 field = arg->int_array.field->field.field;
4032 if (!field) { 4018 if (!field) {
4033 str = arg->int_array.field->field.name; 4019 str = arg->int_array.field->field.name;
4034 field = pevent_find_any_field(event, str); 4020 field = tep_find_any_field(event, str);
4035 if (!field) 4021 if (!field)
4036 goto out_warning_field; 4022 goto out_warning_field;
4037 arg->int_array.field->field.field = field; 4023 arg->int_array.field->field.field = field;
@@ -4071,7 +4057,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
4071 if (arg->string.offset == -1) { 4057 if (arg->string.offset == -1) {
4072 struct format_field *f; 4058 struct format_field *f;
4073 4059
4074 f = pevent_find_any_field(event, arg->string.string); 4060 f = tep_find_any_field(event, arg->string.string);
4075 arg->string.offset = f->offset; 4061 arg->string.offset = f->offset;
4076 } 4062 }
4077 str_offset = data2host4(pevent, data + arg->string.offset); 4063 str_offset = data2host4(pevent, data + arg->string.offset);
@@ -4089,7 +4075,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
4089 if (arg->bitmask.offset == -1) { 4075 if (arg->bitmask.offset == -1) {
4090 struct format_field *f; 4076 struct format_field *f;
4091 4077
4092 f = pevent_find_any_field(event, arg->bitmask.bitmask); 4078 f = tep_find_any_field(event, arg->bitmask.bitmask);
4093 arg->bitmask.offset = f->offset; 4079 arg->bitmask.offset = f->offset;
4094 } 4080 }
4095 bitmask_offset = data2host4(pevent, data + arg->bitmask.offset); 4081 bitmask_offset = data2host4(pevent, data + arg->bitmask.offset);
@@ -4132,8 +4118,8 @@ static unsigned long long
4132process_defined_func(struct trace_seq *s, void *data, int size, 4118process_defined_func(struct trace_seq *s, void *data, int size,
4133 struct event_format *event, struct print_arg *arg) 4119 struct event_format *event, struct print_arg *arg)
4134{ 4120{
4135 struct pevent_function_handler *func_handle = arg->func.func; 4121 struct tep_function_handler *func_handle = arg->func.func;
4136 struct pevent_func_params *param; 4122 struct func_params *param;
4137 unsigned long long *args; 4123 unsigned long long *args;
4138 unsigned long long ret; 4124 unsigned long long ret;
4139 struct print_arg *farg; 4125 struct print_arg *farg;
@@ -4159,12 +4145,12 @@ process_defined_func(struct trace_seq *s, void *data, int size,
4159 4145
4160 for (i = 0; i < func_handle->nr_args; i++) { 4146 for (i = 0; i < func_handle->nr_args; i++) {
4161 switch (param->type) { 4147 switch (param->type) {
4162 case PEVENT_FUNC_ARG_INT: 4148 case TEP_FUNC_ARG_INT:
4163 case PEVENT_FUNC_ARG_LONG: 4149 case TEP_FUNC_ARG_LONG:
4164 case PEVENT_FUNC_ARG_PTR: 4150 case TEP_FUNC_ARG_PTR:
4165 args[i] = eval_num_arg(data, size, event, farg); 4151 args[i] = eval_num_arg(data, size, event, farg);
4166 break; 4152 break;
4167 case PEVENT_FUNC_ARG_STRING: 4153 case TEP_FUNC_ARG_STRING:
4168 trace_seq_init(&str); 4154 trace_seq_init(&str);
4169 print_str_arg(&str, data, size, event, "%s", -1, farg); 4155 print_str_arg(&str, data, size, event, "%s", -1, farg);
4170 trace_seq_terminate(&str); 4156 trace_seq_terminate(&str);
@@ -4227,7 +4213,7 @@ static void free_args(struct print_arg *args)
4227 4213
4228static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event) 4214static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event)
4229{ 4215{
4230 struct pevent *pevent = event->pevent; 4216 struct tep_handle *pevent = event->pevent;
4231 struct format_field *field, *ip_field; 4217 struct format_field *field, *ip_field;
4232 struct print_arg *args, *arg, **next; 4218 struct print_arg *args, *arg, **next;
4233 unsigned long long ip, val; 4219 unsigned long long ip, val;
@@ -4239,12 +4225,12 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
4239 ip_field = pevent->bprint_ip_field; 4225 ip_field = pevent->bprint_ip_field;
4240 4226
4241 if (!field) { 4227 if (!field) {
4242 field = pevent_find_field(event, "buf"); 4228 field = tep_find_field(event, "buf");
4243 if (!field) { 4229 if (!field) {
4244 do_warning_event(event, "can't find buffer field for binary printk"); 4230 do_warning_event(event, "can't find buffer field for binary printk");
4245 return NULL; 4231 return NULL;
4246 } 4232 }
4247 ip_field = pevent_find_field(event, "ip"); 4233 ip_field = tep_find_field(event, "ip");
4248 if (!ip_field) { 4234 if (!ip_field) {
4249 do_warning_event(event, "can't find ip field for binary printk"); 4235 do_warning_event(event, "can't find ip field for binary printk");
4250 return NULL; 4236 return NULL;
@@ -4253,7 +4239,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
4253 pevent->bprint_ip_field = ip_field; 4239 pevent->bprint_ip_field = ip_field;
4254 } 4240 }
4255 4241
4256 ip = pevent_read_number(pevent, data + ip_field->offset, ip_field->size); 4242 ip = tep_read_number(pevent, data + ip_field->offset, ip_field->size);
4257 4243
4258 /* 4244 /*
4259 * The first arg is the IP pointer. 4245 * The first arg is the IP pointer.
@@ -4347,7 +4333,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
4347 /* the pointers are always 4 bytes aligned */ 4333 /* the pointers are always 4 bytes aligned */
4348 bptr = (void *)(((unsigned long)bptr + 3) & 4334 bptr = (void *)(((unsigned long)bptr + 3) &
4349 ~3); 4335 ~3);
4350 val = pevent_read_number(pevent, bptr, vsize); 4336 val = tep_read_number(pevent, bptr, vsize);
4351 bptr += vsize; 4337 bptr += vsize;
4352 arg = alloc_arg(); 4338 arg = alloc_arg();
4353 if (!arg) { 4339 if (!arg) {
@@ -4404,7 +4390,7 @@ static char *
4404get_bprint_format(void *data, int size __maybe_unused, 4390get_bprint_format(void *data, int size __maybe_unused,
4405 struct event_format *event) 4391 struct event_format *event)
4406{ 4392{
4407 struct pevent *pevent = event->pevent; 4393 struct tep_handle *pevent = event->pevent;
4408 unsigned long long addr; 4394 unsigned long long addr;
4409 struct format_field *field; 4395 struct format_field *field;
4410 struct printk_map *printk; 4396 struct printk_map *printk;
@@ -4413,7 +4399,7 @@ get_bprint_format(void *data, int size __maybe_unused,
4413 field = pevent->bprint_fmt_field; 4399 field = pevent->bprint_fmt_field;
4414 4400
4415 if (!field) { 4401 if (!field) {
4416 field = pevent_find_field(event, "fmt"); 4402 field = tep_find_field(event, "fmt");
4417 if (!field) { 4403 if (!field) {
4418 do_warning_event(event, "can't find format field for binary printk"); 4404 do_warning_event(event, "can't find format field for binary printk");
4419 return NULL; 4405 return NULL;
@@ -4421,7 +4407,7 @@ get_bprint_format(void *data, int size __maybe_unused,
4421 pevent->bprint_fmt_field = field; 4407 pevent->bprint_fmt_field = field;
4422 } 4408 }
4423 4409
4424 addr = pevent_read_number(pevent, data + field->offset, field->size); 4410 addr = tep_read_number(pevent, data + field->offset, field->size);
4425 4411
4426 printk = find_printk(pevent, addr); 4412 printk = find_printk(pevent, addr);
4427 if (!printk) { 4413 if (!printk) {
@@ -4457,7 +4443,7 @@ static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
4457 fmt = "%.2x%.2x%.2x%.2x%.2x%.2x"; 4443 fmt = "%.2x%.2x%.2x%.2x%.2x%.2x";
4458 if (!arg->field.field) { 4444 if (!arg->field.field) {
4459 arg->field.field = 4445 arg->field.field =
4460 pevent_find_any_field(event, arg->field.name); 4446 tep_find_any_field(event, arg->field.name);
4461 if (!arg->field.field) { 4447 if (!arg->field.field) {
4462 do_warning_event(event, "%s: field %s not found", 4448 do_warning_event(event, "%s: field %s not found",
4463 __func__, arg->field.name); 4449 __func__, arg->field.name);
@@ -4607,7 +4593,7 @@ static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i,
4607 4593
4608 if (!arg->field.field) { 4594 if (!arg->field.field) {
4609 arg->field.field = 4595 arg->field.field =
4610 pevent_find_any_field(event, arg->field.name); 4596 tep_find_any_field(event, arg->field.name);
4611 if (!arg->field.field) { 4597 if (!arg->field.field) {
4612 do_warning("%s: field %s not found", 4598 do_warning("%s: field %s not found",
4613 __func__, arg->field.name); 4599 __func__, arg->field.name);
@@ -4653,7 +4639,7 @@ static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
4653 4639
4654 if (!arg->field.field) { 4640 if (!arg->field.field) {
4655 arg->field.field = 4641 arg->field.field =
4656 pevent_find_any_field(event, arg->field.name); 4642 tep_find_any_field(event, arg->field.name);
4657 if (!arg->field.field) { 4643 if (!arg->field.field) {
4658 do_warning("%s: field %s not found", 4644 do_warning("%s: field %s not found",
4659 __func__, arg->field.name); 4645 __func__, arg->field.name);
@@ -4711,7 +4697,7 @@ static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
4711 4697
4712 if (!arg->field.field) { 4698 if (!arg->field.field) {
4713 arg->field.field = 4699 arg->field.field =
4714 pevent_find_any_field(event, arg->field.name); 4700 tep_find_any_field(event, arg->field.name);
4715 if (!arg->field.field) { 4701 if (!arg->field.field) {
4716 do_warning("%s: field %s not found", 4702 do_warning("%s: field %s not found",
4717 __func__, arg->field.name); 4703 __func__, arg->field.name);
@@ -4800,18 +4786,18 @@ static int is_printable_array(char *p, unsigned int len)
4800 return 1; 4786 return 1;
4801} 4787}
4802 4788
4803void pevent_print_field(struct trace_seq *s, void *data, 4789void tep_print_field(struct trace_seq *s, void *data,
4804 struct format_field *field) 4790 struct format_field *field)
4805{ 4791{
4806 unsigned long long val; 4792 unsigned long long val;
4807 unsigned int offset, len, i; 4793 unsigned int offset, len, i;
4808 struct pevent *pevent = field->event->pevent; 4794 struct tep_handle *pevent = field->event->pevent;
4809 4795
4810 if (field->flags & FIELD_IS_ARRAY) { 4796 if (field->flags & FIELD_IS_ARRAY) {
4811 offset = field->offset; 4797 offset = field->offset;
4812 len = field->size; 4798 len = field->size;
4813 if (field->flags & FIELD_IS_DYNAMIC) { 4799 if (field->flags & FIELD_IS_DYNAMIC) {
4814 val = pevent_read_number(pevent, data + offset, len); 4800 val = tep_read_number(pevent, data + offset, len);
4815 offset = val; 4801 offset = val;
4816 len = offset >> 16; 4802 len = offset >> 16;
4817 offset &= 0xffff; 4803 offset &= 0xffff;
@@ -4831,8 +4817,8 @@ void pevent_print_field(struct trace_seq *s, void *data,
4831 field->flags &= ~FIELD_IS_STRING; 4817 field->flags &= ~FIELD_IS_STRING;
4832 } 4818 }
4833 } else { 4819 } else {
4834 val = pevent_read_number(pevent, data + field->offset, 4820 val = tep_read_number(pevent, data + field->offset,
4835 field->size); 4821 field->size);
4836 if (field->flags & FIELD_IS_POINTER) { 4822 if (field->flags & FIELD_IS_POINTER) {
4837 trace_seq_printf(s, "0x%llx", val); 4823 trace_seq_printf(s, "0x%llx", val);
4838 } else if (field->flags & FIELD_IS_SIGNED) { 4824 } else if (field->flags & FIELD_IS_SIGNED) {
@@ -4865,22 +4851,22 @@ void pevent_print_field(struct trace_seq *s, void *data,
4865 } 4851 }
4866} 4852}
4867 4853
4868void pevent_print_fields(struct trace_seq *s, void *data, 4854void tep_print_fields(struct trace_seq *s, void *data,
4869 int size __maybe_unused, struct event_format *event) 4855 int size __maybe_unused, struct event_format *event)
4870{ 4856{
4871 struct format_field *field; 4857 struct format_field *field;
4872 4858
4873 field = event->format.fields; 4859 field = event->format.fields;
4874 while (field) { 4860 while (field) {
4875 trace_seq_printf(s, " %s=", field->name); 4861 trace_seq_printf(s, " %s=", field->name);
4876 pevent_print_field(s, data, field); 4862 tep_print_field(s, data, field);
4877 field = field->next; 4863 field = field->next;
4878 } 4864 }
4879} 4865}
4880 4866
4881static void pretty_print(struct trace_seq *s, void *data, int size, struct event_format *event) 4867static void pretty_print(struct trace_seq *s, void *data, int size, struct event_format *event)
4882{ 4868{
4883 struct pevent *pevent = event->pevent; 4869 struct tep_handle *pevent = event->pevent;
4884 struct print_fmt *print_fmt = &event->print_fmt; 4870 struct print_fmt *print_fmt = &event->print_fmt;
4885 struct print_arg *arg = print_fmt->args; 4871 struct print_arg *arg = print_fmt->args;
4886 struct print_arg *args = NULL; 4872 struct print_arg *args = NULL;
@@ -4899,7 +4885,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4899 4885
4900 if (event->flags & EVENT_FL_FAILED) { 4886 if (event->flags & EVENT_FL_FAILED) {
4901 trace_seq_printf(s, "[FAILED TO PARSE]"); 4887 trace_seq_printf(s, "[FAILED TO PARSE]");
4902 pevent_print_fields(s, data, size, event); 4888 tep_print_fields(s, data, size, event);
4903 return; 4889 return;
4904 } 4890 }
4905 4891
@@ -5140,7 +5126,7 @@ out_failed:
5140} 5126}
5141 5127
5142/** 5128/**
5143 * pevent_data_lat_fmt - parse the data for the latency format 5129 * tep_data_lat_fmt - parse the data for the latency format
5144 * @pevent: a handle to the pevent 5130 * @pevent: a handle to the pevent
5145 * @s: the trace_seq to write to 5131 * @s: the trace_seq to write to
5146 * @record: the record to read from 5132 * @record: the record to read from
@@ -5149,8 +5135,8 @@ out_failed:
5149 * need rescheduling, in hard/soft interrupt, preempt count 5135 * need rescheduling, in hard/soft interrupt, preempt count
5150 * and lock depth) and places it into the trace_seq. 5136 * and lock depth) and places it into the trace_seq.
5151 */ 5137 */
5152void pevent_data_lat_fmt(struct pevent *pevent, 5138void tep_data_lat_fmt(struct tep_handle *pevent,
5153 struct trace_seq *s, struct pevent_record *record) 5139 struct trace_seq *s, struct tep_record *record)
5154{ 5140{
5155 static int check_lock_depth = 1; 5141 static int check_lock_depth = 1;
5156 static int check_migrate_disable = 1; 5142 static int check_migrate_disable = 1;
@@ -5223,55 +5209,55 @@ void pevent_data_lat_fmt(struct pevent *pevent,
5223} 5209}
5224 5210
5225/** 5211/**
5226 * pevent_data_type - parse out the given event type 5212 * tep_data_type - parse out the given event type
5227 * @pevent: a handle to the pevent 5213 * @pevent: a handle to the pevent
5228 * @rec: the record to read from 5214 * @rec: the record to read from
5229 * 5215 *
5230 * This returns the event id from the @rec. 5216 * This returns the event id from the @rec.
5231 */ 5217 */
5232int pevent_data_type(struct pevent *pevent, struct pevent_record *rec) 5218int tep_data_type(struct tep_handle *pevent, struct tep_record *rec)
5233{ 5219{
5234 return trace_parse_common_type(pevent, rec->data); 5220 return trace_parse_common_type(pevent, rec->data);
5235} 5221}
5236 5222
5237/** 5223/**
5238 * pevent_data_event_from_type - find the event by a given type 5224 * tep_data_event_from_type - find the event by a given type
5239 * @pevent: a handle to the pevent 5225 * @pevent: a handle to the pevent
5240 * @type: the type of the event. 5226 * @type: the type of the event.
5241 * 5227 *
5242 * This returns the event form a given @type; 5228 * This returns the event form a given @type;
5243 */ 5229 */
5244struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type) 5230struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type)
5245{ 5231{
5246 return pevent_find_event(pevent, type); 5232 return tep_find_event(pevent, type);
5247} 5233}
5248 5234
5249/** 5235/**
5250 * pevent_data_pid - parse the PID from record 5236 * tep_data_pid - parse the PID from record
5251 * @pevent: a handle to the pevent 5237 * @pevent: a handle to the pevent
5252 * @rec: the record to parse 5238 * @rec: the record to parse
5253 * 5239 *
5254 * This returns the PID from a record. 5240 * This returns the PID from a record.
5255 */ 5241 */
5256int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec) 5242int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec)
5257{ 5243{
5258 return parse_common_pid(pevent, rec->data); 5244 return parse_common_pid(pevent, rec->data);
5259} 5245}
5260 5246
5261/** 5247/**
5262 * pevent_data_preempt_count - parse the preempt count from the record 5248 * tep_data_preempt_count - parse the preempt count from the record
5263 * @pevent: a handle to the pevent 5249 * @pevent: a handle to the pevent
5264 * @rec: the record to parse 5250 * @rec: the record to parse
5265 * 5251 *
5266 * This returns the preempt count from a record. 5252 * This returns the preempt count from a record.
5267 */ 5253 */
5268int pevent_data_preempt_count(struct pevent *pevent, struct pevent_record *rec) 5254int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec)
5269{ 5255{
5270 return parse_common_pc(pevent, rec->data); 5256 return parse_common_pc(pevent, rec->data);
5271} 5257}
5272 5258
5273/** 5259/**
5274 * pevent_data_flags - parse the latency flags from the record 5260 * tep_data_flags - parse the latency flags from the record
5275 * @pevent: a handle to the pevent 5261 * @pevent: a handle to the pevent
5276 * @rec: the record to parse 5262 * @rec: the record to parse
5277 * 5263 *
@@ -5279,20 +5265,20 @@ int pevent_data_preempt_count(struct pevent *pevent, struct pevent_record *rec)
5279 * 5265 *
5280 * Use trace_flag_type enum for the flags (see event-parse.h). 5266 * Use trace_flag_type enum for the flags (see event-parse.h).
5281 */ 5267 */
5282int pevent_data_flags(struct pevent *pevent, struct pevent_record *rec) 5268int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec)
5283{ 5269{
5284 return parse_common_flags(pevent, rec->data); 5270 return parse_common_flags(pevent, rec->data);
5285} 5271}
5286 5272
5287/** 5273/**
5288 * pevent_data_comm_from_pid - return the command line from PID 5274 * tep_data_comm_from_pid - return the command line from PID
5289 * @pevent: a handle to the pevent 5275 * @pevent: a handle to the pevent
5290 * @pid: the PID of the task to search for 5276 * @pid: the PID of the task to search for
5291 * 5277 *
5292 * This returns a pointer to the command line that has the given 5278 * This returns a pointer to the command line that has the given
5293 * @pid. 5279 * @pid.
5294 */ 5280 */
5295const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid) 5281const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid)
5296{ 5282{
5297 const char *comm; 5283 const char *comm;
5298 5284
@@ -5301,7 +5287,7 @@ const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid)
5301} 5287}
5302 5288
5303static struct cmdline * 5289static struct cmdline *
5304pid_from_cmdlist(struct pevent *pevent, const char *comm, struct cmdline *next) 5290pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct cmdline *next)
5305{ 5291{
5306 struct cmdline_list *cmdlist = (struct cmdline_list *)next; 5292 struct cmdline_list *cmdlist = (struct cmdline_list *)next;
5307 5293
@@ -5317,7 +5303,7 @@ pid_from_cmdlist(struct pevent *pevent, const char *comm, struct cmdline *next)
5317} 5303}
5318 5304
5319/** 5305/**
5320 * pevent_data_pid_from_comm - return the pid from a given comm 5306 * tep_data_pid_from_comm - return the pid from a given comm
5321 * @pevent: a handle to the pevent 5307 * @pevent: a handle to the pevent
5322 * @comm: the cmdline to find the pid from 5308 * @comm: the cmdline to find the pid from
5323 * @next: the cmdline structure to find the next comm 5309 * @next: the cmdline structure to find the next comm
@@ -5329,8 +5315,8 @@ pid_from_cmdlist(struct pevent *pevent, const char *comm, struct cmdline *next)
5329 * next pid. 5315 * next pid.
5330 * Also, it does a linear seach, so it may be slow. 5316 * Also, it does a linear seach, so it may be slow.
5331 */ 5317 */
5332struct cmdline *pevent_data_pid_from_comm(struct pevent *pevent, const char *comm, 5318struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm,
5333 struct cmdline *next) 5319 struct cmdline *next)
5334{ 5320{
5335 struct cmdline *cmdline; 5321 struct cmdline *cmdline;
5336 5322
@@ -5365,13 +5351,13 @@ struct cmdline *pevent_data_pid_from_comm(struct pevent *pevent, const char *com
5365} 5351}
5366 5352
5367/** 5353/**
5368 * pevent_cmdline_pid - return the pid associated to a given cmdline 5354 * tep_cmdline_pid - return the pid associated to a given cmdline
5369 * @cmdline: The cmdline structure to get the pid from 5355 * @cmdline: The cmdline structure to get the pid from
5370 * 5356 *
5371 * Returns the pid for a give cmdline. If @cmdline is NULL, then 5357 * Returns the pid for a give cmdline. If @cmdline is NULL, then
5372 * -1 is returned. 5358 * -1 is returned.
5373 */ 5359 */
5374int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline) 5360int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline)
5375{ 5361{
5376 struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline; 5362 struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline;
5377 5363
@@ -5391,7 +5377,7 @@ int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline)
5391} 5377}
5392 5378
5393/** 5379/**
5394 * pevent_data_comm_from_pid - parse the data into the print format 5380 * tep_event_info - parse the data into the print format
5395 * @s: the trace_seq to write to 5381 * @s: the trace_seq to write to
5396 * @event: the handle to the event 5382 * @event: the handle to the event
5397 * @record: the record to read from 5383 * @record: the record to read from
@@ -5399,13 +5385,13 @@ int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline)
5399 * This parses the raw @data using the given @event information and 5385 * This parses the raw @data using the given @event information and
5400 * writes the print format into the trace_seq. 5386 * writes the print format into the trace_seq.
5401 */ 5387 */
5402void pevent_event_info(struct trace_seq *s, struct event_format *event, 5388void tep_event_info(struct trace_seq *s, struct event_format *event,
5403 struct pevent_record *record) 5389 struct tep_record *record)
5404{ 5390{
5405 int print_pretty = 1; 5391 int print_pretty = 1;
5406 5392
5407 if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW)) 5393 if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
5408 pevent_print_fields(s, record->data, record->size, event); 5394 tep_print_fields(s, record->data, record->size, event);
5409 else { 5395 else {
5410 5396
5411 if (event->handler && !(event->flags & EVENT_FL_NOHANDLE)) 5397 if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
@@ -5433,7 +5419,7 @@ static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
5433} 5419}
5434 5420
5435/** 5421/**
5436 * pevent_find_event_by_record - return the event from a given record 5422 * tep_find_event_by_record - return the event from a given record
5437 * @pevent: a handle to the pevent 5423 * @pevent: a handle to the pevent
5438 * @record: The record to get the event from 5424 * @record: The record to get the event from
5439 * 5425 *
@@ -5441,7 +5427,7 @@ static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
5441 * is found. 5427 * is found.
5442 */ 5428 */
5443struct event_format * 5429struct event_format *
5444pevent_find_event_by_record(struct pevent *pevent, struct pevent_record *record) 5430tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record)
5445{ 5431{
5446 int type; 5432 int type;
5447 5433
@@ -5452,11 +5438,11 @@ pevent_find_event_by_record(struct pevent *pevent, struct pevent_record *record)
5452 5438
5453 type = trace_parse_common_type(pevent, record->data); 5439 type = trace_parse_common_type(pevent, record->data);
5454 5440
5455 return pevent_find_event(pevent, type); 5441 return tep_find_event(pevent, type);
5456} 5442}
5457 5443
5458/** 5444/**
5459 * pevent_print_event_task - Write the event task comm, pid and CPU 5445 * tep_print_event_task - Write the event task comm, pid and CPU
5460 * @pevent: a handle to the pevent 5446 * @pevent: a handle to the pevent
5461 * @s: the trace_seq to write to 5447 * @s: the trace_seq to write to
5462 * @event: the handle to the record's event 5448 * @event: the handle to the record's event
@@ -5464,9 +5450,9 @@ pevent_find_event_by_record(struct pevent *pevent, struct pevent_record *record)
5464 * 5450 *
5465 * Writes the tasks comm, pid and CPU to @s. 5451 * Writes the tasks comm, pid and CPU to @s.
5466 */ 5452 */
5467void pevent_print_event_task(struct pevent *pevent, struct trace_seq *s, 5453void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
5468 struct event_format *event, 5454 struct event_format *event,
5469 struct pevent_record *record) 5455 struct tep_record *record)
5470{ 5456{
5471 void *data = record->data; 5457 void *data = record->data;
5472 const char *comm; 5458 const char *comm;
@@ -5483,7 +5469,7 @@ void pevent_print_event_task(struct pevent *pevent, struct trace_seq *s,
5483} 5469}
5484 5470
5485/** 5471/**
5486 * pevent_print_event_time - Write the event timestamp 5472 * tep_print_event_time - Write the event timestamp
5487 * @pevent: a handle to the pevent 5473 * @pevent: a handle to the pevent
5488 * @s: the trace_seq to write to 5474 * @s: the trace_seq to write to
5489 * @event: the handle to the record's event 5475 * @event: the handle to the record's event
@@ -5492,10 +5478,10 @@ void pevent_print_event_task(struct pevent *pevent, struct trace_seq *s,
5492 * 5478 *
5493 * Writes the timestamp of the record into @s. 5479 * Writes the timestamp of the record into @s.
5494 */ 5480 */
5495void pevent_print_event_time(struct pevent *pevent, struct trace_seq *s, 5481void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
5496 struct event_format *event, 5482 struct event_format *event,
5497 struct pevent_record *record, 5483 struct tep_record *record,
5498 bool use_trace_clock) 5484 bool use_trace_clock)
5499{ 5485{
5500 unsigned long secs; 5486 unsigned long secs;
5501 unsigned long usecs; 5487 unsigned long usecs;
@@ -5511,11 +5497,11 @@ void pevent_print_event_time(struct pevent *pevent, struct trace_seq *s,
5511 } 5497 }
5512 5498
5513 if (pevent->latency_format) { 5499 if (pevent->latency_format) {
5514 pevent_data_lat_fmt(pevent, s, record); 5500 tep_data_lat_fmt(pevent, s, record);
5515 } 5501 }
5516 5502
5517 if (use_usec_format) { 5503 if (use_usec_format) {
5518 if (pevent->flags & PEVENT_NSEC_OUTPUT) { 5504 if (pevent->flags & TEP_NSEC_OUTPUT) {
5519 usecs = nsecs; 5505 usecs = nsecs;
5520 p = 9; 5506 p = 9;
5521 } else { 5507 } else {
@@ -5534,7 +5520,7 @@ void pevent_print_event_time(struct pevent *pevent, struct trace_seq *s,
5534} 5520}
5535 5521
5536/** 5522/**
5537 * pevent_print_event_data - Write the event data section 5523 * tep_print_event_data - Write the event data section
5538 * @pevent: a handle to the pevent 5524 * @pevent: a handle to the pevent
5539 * @s: the trace_seq to write to 5525 * @s: the trace_seq to write to
5540 * @event: the handle to the record's event 5526 * @event: the handle to the record's event
@@ -5542,9 +5528,9 @@ void pevent_print_event_time(struct pevent *pevent, struct trace_seq *s,
5542 * 5528 *
5543 * Writes the parsing of the record's data to @s. 5529 * Writes the parsing of the record's data to @s.
5544 */ 5530 */
5545void pevent_print_event_data(struct pevent *pevent, struct trace_seq *s, 5531void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
5546 struct event_format *event, 5532 struct event_format *event,
5547 struct pevent_record *record) 5533 struct tep_record *record)
5548{ 5534{
5549 static const char *spaces = " "; /* 20 spaces */ 5535 static const char *spaces = " "; /* 20 spaces */
5550 int len; 5536 int len;
@@ -5556,15 +5542,15 @@ void pevent_print_event_data(struct pevent *pevent, struct trace_seq *s,
5556 if (len < 20) 5542 if (len < 20)
5557 trace_seq_printf(s, "%.*s", 20 - len, spaces); 5543 trace_seq_printf(s, "%.*s", 20 - len, spaces);
5558 5544
5559 pevent_event_info(s, event, record); 5545 tep_event_info(s, event, record);
5560} 5546}
5561 5547
5562void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 5548void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
5563 struct pevent_record *record, bool use_trace_clock) 5549 struct tep_record *record, bool use_trace_clock)
5564{ 5550{
5565 struct event_format *event; 5551 struct event_format *event;
5566 5552
5567 event = pevent_find_event_by_record(pevent, record); 5553 event = tep_find_event_by_record(pevent, record);
5568 if (!event) { 5554 if (!event) {
5569 int i; 5555 int i;
5570 int type = trace_parse_common_type(pevent, record->data); 5556 int type = trace_parse_common_type(pevent, record->data);
@@ -5577,9 +5563,9 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
5577 return; 5563 return;
5578 } 5564 }
5579 5565
5580 pevent_print_event_task(pevent, s, event, record); 5566 tep_print_event_task(pevent, s, event, record);
5581 pevent_print_event_time(pevent, s, event, record, use_trace_clock); 5567 tep_print_event_time(pevent, s, event, record, use_trace_clock);
5582 pevent_print_event_data(pevent, s, event, record); 5568 tep_print_event_data(pevent, s, event, record);
5583} 5569}
5584 5570
5585static int events_id_cmp(const void *a, const void *b) 5571static int events_id_cmp(const void *a, const void *b)
@@ -5630,7 +5616,7 @@ static int events_system_cmp(const void *a, const void *b)
5630 return events_id_cmp(a, b); 5616 return events_id_cmp(a, b);
5631} 5617}
5632 5618
5633struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type sort_type) 5619struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type sort_type)
5634{ 5620{
5635 struct event_format **events; 5621 struct event_format **events;
5636 int (*sort)(const void *a, const void *b); 5622 int (*sort)(const void *a, const void *b);
@@ -5709,13 +5695,13 @@ get_event_fields(const char *type, const char *name,
5709} 5695}
5710 5696
5711/** 5697/**
5712 * pevent_event_common_fields - return a list of common fields for an event 5698 * tep_event_common_fields - return a list of common fields for an event
5713 * @event: the event to return the common fields of. 5699 * @event: the event to return the common fields of.
5714 * 5700 *
5715 * Returns an allocated array of fields. The last item in the array is NULL. 5701 * Returns an allocated array of fields. The last item in the array is NULL.
5716 * The array must be freed with free(). 5702 * The array must be freed with free().
5717 */ 5703 */
5718struct format_field **pevent_event_common_fields(struct event_format *event) 5704struct format_field **tep_event_common_fields(struct event_format *event)
5719{ 5705{
5720 return get_event_fields("common", event->name, 5706 return get_event_fields("common", event->name,
5721 event->format.nr_common, 5707 event->format.nr_common,
@@ -5723,13 +5709,13 @@ struct format_field **pevent_event_common_fields(struct event_format *event)
5723} 5709}
5724 5710
5725/** 5711/**
5726 * pevent_event_fields - return a list of event specific fields for an event 5712 * tep_event_fields - return a list of event specific fields for an event
5727 * @event: the event to return the fields of. 5713 * @event: the event to return the fields of.
5728 * 5714 *
5729 * Returns an allocated array of fields. The last item in the array is NULL. 5715 * Returns an allocated array of fields. The last item in the array is NULL.
5730 * The array must be freed with free(). 5716 * The array must be freed with free().
5731 */ 5717 */
5732struct format_field **pevent_event_fields(struct event_format *event) 5718struct format_field **tep_event_fields(struct event_format *event)
5733{ 5719{
5734 return get_event_fields("event", event->name, 5720 return get_event_fields("event", event->name,
5735 event->format.nr_fields, 5721 event->format.nr_fields,
@@ -5930,7 +5916,7 @@ static void parse_header_field(const char *field,
5930} 5916}
5931 5917
5932/** 5918/**
5933 * pevent_parse_header_page - parse the data stored in the header page 5919 * tep_parse_header_page - parse the data stored in the header page
5934 * @pevent: the handle to the pevent 5920 * @pevent: the handle to the pevent
5935 * @buf: the buffer storing the header page format string 5921 * @buf: the buffer storing the header page format string
5936 * @size: the size of @buf 5922 * @size: the size of @buf
@@ -5941,8 +5927,8 @@ static void parse_header_field(const char *field,
5941 * 5927 *
5942 * /sys/kernel/debug/tracing/events/header_page 5928 * /sys/kernel/debug/tracing/events/header_page
5943 */ 5929 */
5944int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size, 5930int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long size,
5945 int long_size) 5931 int long_size)
5946{ 5932{
5947 int ignore; 5933 int ignore;
5948 5934
@@ -5994,7 +5980,7 @@ static void free_handler(struct event_handler *handle)
5994 free(handle); 5980 free(handle);
5995} 5981}
5996 5982
5997static int find_event_handle(struct pevent *pevent, struct event_format *event) 5983static int find_event_handle(struct tep_handle *pevent, struct event_format *event)
5998{ 5984{
5999 struct event_handler *handle, **next; 5985 struct event_handler *handle, **next;
6000 5986
@@ -6023,7 +6009,7 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
6023} 6009}
6024 6010
6025/** 6011/**
6026 * __pevent_parse_format - parse the event format 6012 * __tep_parse_format - parse the event format
6027 * @buf: the buffer storing the event format string 6013 * @buf: the buffer storing the event format string
6028 * @size: the size of @buf 6014 * @size: the size of @buf
6029 * @sys: the system the event belongs to 6015 * @sys: the system the event belongs to
@@ -6035,9 +6021,9 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
6035 * 6021 *
6036 * /sys/kernel/debug/tracing/events/.../.../format 6022 * /sys/kernel/debug/tracing/events/.../.../format
6037 */ 6023 */
6038enum pevent_errno __pevent_parse_format(struct event_format **eventp, 6024enum tep_errno __tep_parse_format(struct event_format **eventp,
6039 struct pevent *pevent, const char *buf, 6025 struct tep_handle *pevent, const char *buf,
6040 unsigned long size, const char *sys) 6026 unsigned long size, const char *sys)
6041{ 6027{
6042 struct event_format *event; 6028 struct event_format *event;
6043 int ret; 6029 int ret;
@@ -6046,12 +6032,12 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
6046 6032
6047 *eventp = event = alloc_event(); 6033 *eventp = event = alloc_event();
6048 if (!event) 6034 if (!event)
6049 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 6035 return TEP_ERRNO__MEM_ALLOC_FAILED;
6050 6036
6051 event->name = event_read_name(); 6037 event->name = event_read_name();
6052 if (!event->name) { 6038 if (!event->name) {
6053 /* Bad event? */ 6039 /* Bad event? */
6054 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED; 6040 ret = TEP_ERRNO__MEM_ALLOC_FAILED;
6055 goto event_alloc_failed; 6041 goto event_alloc_failed;
6056 } 6042 }
6057 6043
@@ -6064,7 +6050,7 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
6064 6050
6065 event->id = event_read_id(); 6051 event->id = event_read_id();
6066 if (event->id < 0) { 6052 if (event->id < 0) {
6067 ret = PEVENT_ERRNO__READ_ID_FAILED; 6053 ret = TEP_ERRNO__READ_ID_FAILED;
6068 /* 6054 /*
6069 * This isn't an allocation error actually. 6055 * This isn't an allocation error actually.
6070 * But as the ID is critical, just bail out. 6056 * But as the ID is critical, just bail out.
@@ -6074,7 +6060,7 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
6074 6060
6075 event->system = strdup(sys); 6061 event->system = strdup(sys);
6076 if (!event->system) { 6062 if (!event->system) {
6077 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED; 6063 ret = TEP_ERRNO__MEM_ALLOC_FAILED;
6078 goto event_alloc_failed; 6064 goto event_alloc_failed;
6079 } 6065 }
6080 6066
@@ -6083,7 +6069,7 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
6083 6069
6084 ret = event_read_format(event); 6070 ret = event_read_format(event);
6085 if (ret < 0) { 6071 if (ret < 0) {
6086 ret = PEVENT_ERRNO__READ_FORMAT_FAILED; 6072 ret = TEP_ERRNO__READ_FORMAT_FAILED;
6087 goto event_parse_failed; 6073 goto event_parse_failed;
6088 } 6074 }
6089 6075
@@ -6098,7 +6084,7 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
6098 show_warning = 1; 6084 show_warning = 1;
6099 6085
6100 if (ret < 0) { 6086 if (ret < 0) {
6101 ret = PEVENT_ERRNO__READ_PRINT_FAILED; 6087 ret = TEP_ERRNO__READ_PRINT_FAILED;
6102 goto event_parse_failed; 6088 goto event_parse_failed;
6103 } 6089 }
6104 6090
@@ -6112,14 +6098,14 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
6112 arg = alloc_arg(); 6098 arg = alloc_arg();
6113 if (!arg) { 6099 if (!arg) {
6114 event->flags |= EVENT_FL_FAILED; 6100 event->flags |= EVENT_FL_FAILED;
6115 return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED; 6101 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
6116 } 6102 }
6117 arg->type = PRINT_FIELD; 6103 arg->type = PRINT_FIELD;
6118 arg->field.name = strdup(field->name); 6104 arg->field.name = strdup(field->name);
6119 if (!arg->field.name) { 6105 if (!arg->field.name) {
6120 event->flags |= EVENT_FL_FAILED; 6106 event->flags |= EVENT_FL_FAILED;
6121 free_arg(arg); 6107 free_arg(arg);
6122 return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED; 6108 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
6123 } 6109 }
6124 arg->field.field = field; 6110 arg->field.field = field;
6125 *list = arg; 6111 *list = arg;
@@ -6142,20 +6128,20 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
6142 return ret; 6128 return ret;
6143} 6129}
6144 6130
6145static enum pevent_errno 6131static enum tep_errno
6146__pevent_parse_event(struct pevent *pevent, 6132__parse_event(struct tep_handle *pevent,
6147 struct event_format **eventp, 6133 struct event_format **eventp,
6148 const char *buf, unsigned long size, 6134 const char *buf, unsigned long size,
6149 const char *sys) 6135 const char *sys)
6150{ 6136{
6151 int ret = __pevent_parse_format(eventp, pevent, buf, size, sys); 6137 int ret = __tep_parse_format(eventp, pevent, buf, size, sys);
6152 struct event_format *event = *eventp; 6138 struct event_format *event = *eventp;
6153 6139
6154 if (event == NULL) 6140 if (event == NULL)
6155 return ret; 6141 return ret;
6156 6142
6157 if (pevent && add_event(pevent, event)) { 6143 if (pevent && add_event(pevent, event)) {
6158 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED; 6144 ret = TEP_ERRNO__MEM_ALLOC_FAILED;
6159 goto event_add_failed; 6145 goto event_add_failed;
6160 } 6146 }
6161 6147
@@ -6166,12 +6152,12 @@ __pevent_parse_event(struct pevent *pevent,
6166 return 0; 6152 return 0;
6167 6153
6168event_add_failed: 6154event_add_failed:
6169 pevent_free_format(event); 6155 tep_free_format(event);
6170 return ret; 6156 return ret;
6171} 6157}
6172 6158
6173/** 6159/**
6174 * pevent_parse_format - parse the event format 6160 * tep_parse_format - parse the event format
6175 * @pevent: the handle to the pevent 6161 * @pevent: the handle to the pevent
6176 * @eventp: returned format 6162 * @eventp: returned format
6177 * @buf: the buffer storing the event format string 6163 * @buf: the buffer storing the event format string
@@ -6185,16 +6171,16 @@ event_add_failed:
6185 * 6171 *
6186 * /sys/kernel/debug/tracing/events/.../.../format 6172 * /sys/kernel/debug/tracing/events/.../.../format
6187 */ 6173 */
6188enum pevent_errno pevent_parse_format(struct pevent *pevent, 6174enum tep_errno tep_parse_format(struct tep_handle *pevent,
6189 struct event_format **eventp, 6175 struct event_format **eventp,
6190 const char *buf, 6176 const char *buf,
6191 unsigned long size, const char *sys) 6177 unsigned long size, const char *sys)
6192{ 6178{
6193 return __pevent_parse_event(pevent, eventp, buf, size, sys); 6179 return __parse_event(pevent, eventp, buf, size, sys);
6194} 6180}
6195 6181
6196/** 6182/**
6197 * pevent_parse_event - parse the event format 6183 * tep_parse_event - parse the event format
6198 * @pevent: the handle to the pevent 6184 * @pevent: the handle to the pevent
6199 * @buf: the buffer storing the event format string 6185 * @buf: the buffer storing the event format string
6200 * @size: the size of @buf 6186 * @size: the size of @buf
@@ -6207,22 +6193,22 @@ enum pevent_errno pevent_parse_format(struct pevent *pevent,
6207 * 6193 *
6208 * /sys/kernel/debug/tracing/events/.../.../format 6194 * /sys/kernel/debug/tracing/events/.../.../format
6209 */ 6195 */
6210enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, 6196enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
6211 unsigned long size, const char *sys) 6197 unsigned long size, const char *sys)
6212{ 6198{
6213 struct event_format *event = NULL; 6199 struct event_format *event = NULL;
6214 return __pevent_parse_event(pevent, &event, buf, size, sys); 6200 return __parse_event(pevent, &event, buf, size, sys);
6215} 6201}
6216 6202
6217#undef _PE 6203#undef _PE
6218#define _PE(code, str) str 6204#define _PE(code, str) str
6219static const char * const pevent_error_str[] = { 6205static const char * const tep_error_str[] = {
6220 PEVENT_ERRORS 6206 TEP_ERRORS
6221}; 6207};
6222#undef _PE 6208#undef _PE
6223 6209
6224int pevent_strerror(struct pevent *pevent __maybe_unused, 6210int tep_strerror(struct tep_handle *pevent __maybe_unused,
6225 enum pevent_errno errnum, char *buf, size_t buflen) 6211 enum tep_errno errnum, char *buf, size_t buflen)
6226{ 6212{
6227 int idx; 6213 int idx;
6228 const char *msg; 6214 const char *msg;
@@ -6232,19 +6218,19 @@ int pevent_strerror(struct pevent *pevent __maybe_unused,
6232 return 0; 6218 return 0;
6233 } 6219 }
6234 6220
6235 if (errnum <= __PEVENT_ERRNO__START || 6221 if (errnum <= __TEP_ERRNO__START ||
6236 errnum >= __PEVENT_ERRNO__END) 6222 errnum >= __TEP_ERRNO__END)
6237 return -1; 6223 return -1;
6238 6224
6239 idx = errnum - __PEVENT_ERRNO__START - 1; 6225 idx = errnum - __TEP_ERRNO__START - 1;
6240 msg = pevent_error_str[idx]; 6226 msg = tep_error_str[idx];
6241 snprintf(buf, buflen, "%s", msg); 6227 snprintf(buf, buflen, "%s", msg);
6242 6228
6243 return 0; 6229 return 0;
6244} 6230}
6245 6231
6246int get_field_val(struct trace_seq *s, struct format_field *field, 6232int get_field_val(struct trace_seq *s, struct format_field *field,
6247 const char *name, struct pevent_record *record, 6233 const char *name, struct tep_record *record,
6248 unsigned long long *val, int err) 6234 unsigned long long *val, int err)
6249{ 6235{
6250 if (!field) { 6236 if (!field) {
@@ -6253,7 +6239,7 @@ int get_field_val(struct trace_seq *s, struct format_field *field,
6253 return -1; 6239 return -1;
6254 } 6240 }
6255 6241
6256 if (pevent_read_number_field(field, record->data, val)) { 6242 if (tep_read_number_field(field, record->data, val)) {
6257 if (err) 6243 if (err)
6258 trace_seq_printf(s, " %s=INVALID", name); 6244 trace_seq_printf(s, " %s=INVALID", name);
6259 return -1; 6245 return -1;
@@ -6263,7 +6249,7 @@ int get_field_val(struct trace_seq *s, struct format_field *field,
6263} 6249}
6264 6250
6265/** 6251/**
6266 * pevent_get_field_raw - return the raw pointer into the data field 6252 * tep_get_field_raw - return the raw pointer into the data field
6267 * @s: The seq to print to on error 6253 * @s: The seq to print to on error
6268 * @event: the event that the field is for 6254 * @event: the event that the field is for
6269 * @name: The name of the field 6255 * @name: The name of the field
@@ -6276,9 +6262,9 @@ int get_field_val(struct trace_seq *s, struct format_field *field,
6276 * 6262 *
6277 * On failure, it returns NULL. 6263 * On failure, it returns NULL.
6278 */ 6264 */
6279void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event, 6265void *tep_get_field_raw(struct trace_seq *s, struct event_format *event,
6280 const char *name, struct pevent_record *record, 6266 const char *name, struct tep_record *record,
6281 int *len, int err) 6267 int *len, int err)
6282{ 6268{
6283 struct format_field *field; 6269 struct format_field *field;
6284 void *data = record->data; 6270 void *data = record->data;
@@ -6288,7 +6274,7 @@ void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
6288 if (!event) 6274 if (!event)
6289 return NULL; 6275 return NULL;
6290 6276
6291 field = pevent_find_field(event, name); 6277 field = tep_find_field(event, name);
6292 6278
6293 if (!field) { 6279 if (!field) {
6294 if (err) 6280 if (err)
@@ -6302,7 +6288,7 @@ void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
6302 6288
6303 offset = field->offset; 6289 offset = field->offset;
6304 if (field->flags & FIELD_IS_DYNAMIC) { 6290 if (field->flags & FIELD_IS_DYNAMIC) {
6305 offset = pevent_read_number(event->pevent, 6291 offset = tep_read_number(event->pevent,
6306 data + offset, field->size); 6292 data + offset, field->size);
6307 *len = offset >> 16; 6293 *len = offset >> 16;
6308 offset &= 0xffff; 6294 offset &= 0xffff;
@@ -6313,7 +6299,7 @@ void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
6313} 6299}
6314 6300
6315/** 6301/**
6316 * pevent_get_field_val - find a field and return its value 6302 * tep_get_field_val - find a field and return its value
6317 * @s: The seq to print to on error 6303 * @s: The seq to print to on error
6318 * @event: the event that the field is for 6304 * @event: the event that the field is for
6319 * @name: The name of the field 6305 * @name: The name of the field
@@ -6323,22 +6309,22 @@ void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
6323 * 6309 *
6324 * Returns 0 on success -1 on field not found. 6310 * Returns 0 on success -1 on field not found.
6325 */ 6311 */
6326int pevent_get_field_val(struct trace_seq *s, struct event_format *event, 6312int tep_get_field_val(struct trace_seq *s, struct event_format *event,
6327 const char *name, struct pevent_record *record, 6313 const char *name, struct tep_record *record,
6328 unsigned long long *val, int err) 6314 unsigned long long *val, int err)
6329{ 6315{
6330 struct format_field *field; 6316 struct format_field *field;
6331 6317
6332 if (!event) 6318 if (!event)
6333 return -1; 6319 return -1;
6334 6320
6335 field = pevent_find_field(event, name); 6321 field = tep_find_field(event, name);
6336 6322
6337 return get_field_val(s, field, name, record, val, err); 6323 return get_field_val(s, field, name, record, val, err);
6338} 6324}
6339 6325
6340/** 6326/**
6341 * pevent_get_common_field_val - find a common field and return its value 6327 * tep_get_common_field_val - find a common field and return its value
6342 * @s: The seq to print to on error 6328 * @s: The seq to print to on error
6343 * @event: the event that the field is for 6329 * @event: the event that the field is for
6344 * @name: The name of the field 6330 * @name: The name of the field
@@ -6348,22 +6334,22 @@ int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
6348 * 6334 *
6349 * Returns 0 on success -1 on field not found. 6335 * Returns 0 on success -1 on field not found.
6350 */ 6336 */
6351int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event, 6337int tep_get_common_field_val(struct trace_seq *s, struct event_format *event,
6352 const char *name, struct pevent_record *record, 6338 const char *name, struct tep_record *record,
6353 unsigned long long *val, int err) 6339 unsigned long long *val, int err)
6354{ 6340{
6355 struct format_field *field; 6341 struct format_field *field;
6356 6342
6357 if (!event) 6343 if (!event)
6358 return -1; 6344 return -1;
6359 6345
6360 field = pevent_find_common_field(event, name); 6346 field = tep_find_common_field(event, name);
6361 6347
6362 return get_field_val(s, field, name, record, val, err); 6348 return get_field_val(s, field, name, record, val, err);
6363} 6349}
6364 6350
6365/** 6351/**
6366 * pevent_get_any_field_val - find a any field and return its value 6352 * tep_get_any_field_val - find a any field and return its value
6367 * @s: The seq to print to on error 6353 * @s: The seq to print to on error
6368 * @event: the event that the field is for 6354 * @event: the event that the field is for
6369 * @name: The name of the field 6355 * @name: The name of the field
@@ -6373,22 +6359,22 @@ int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
6373 * 6359 *
6374 * Returns 0 on success -1 on field not found. 6360 * Returns 0 on success -1 on field not found.
6375 */ 6361 */
6376int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event, 6362int tep_get_any_field_val(struct trace_seq *s, struct event_format *event,
6377 const char *name, struct pevent_record *record, 6363 const char *name, struct tep_record *record,
6378 unsigned long long *val, int err) 6364 unsigned long long *val, int err)
6379{ 6365{
6380 struct format_field *field; 6366 struct format_field *field;
6381 6367
6382 if (!event) 6368 if (!event)
6383 return -1; 6369 return -1;
6384 6370
6385 field = pevent_find_any_field(event, name); 6371 field = tep_find_any_field(event, name);
6386 6372
6387 return get_field_val(s, field, name, record, val, err); 6373 return get_field_val(s, field, name, record, val, err);
6388} 6374}
6389 6375
6390/** 6376/**
6391 * pevent_print_num_field - print a field and a format 6377 * tep_print_num_field - print a field and a format
6392 * @s: The seq to print to 6378 * @s: The seq to print to
6393 * @fmt: The printf format to print the field with. 6379 * @fmt: The printf format to print the field with.
6394 * @event: the event that the field is for 6380 * @event: the event that the field is for
@@ -6398,17 +6384,17 @@ int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
6398 * 6384 *
6399 * Returns: 0 on success, -1 field not found, or 1 if buffer is full. 6385 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
6400 */ 6386 */
6401int pevent_print_num_field(struct trace_seq *s, const char *fmt, 6387int tep_print_num_field(struct trace_seq *s, const char *fmt,
6402 struct event_format *event, const char *name, 6388 struct event_format *event, const char *name,
6403 struct pevent_record *record, int err) 6389 struct tep_record *record, int err)
6404{ 6390{
6405 struct format_field *field = pevent_find_field(event, name); 6391 struct format_field *field = tep_find_field(event, name);
6406 unsigned long long val; 6392 unsigned long long val;
6407 6393
6408 if (!field) 6394 if (!field)
6409 goto failed; 6395 goto failed;
6410 6396
6411 if (pevent_read_number_field(field, record->data, &val)) 6397 if (tep_read_number_field(field, record->data, &val))
6412 goto failed; 6398 goto failed;
6413 6399
6414 return trace_seq_printf(s, fmt, val); 6400 return trace_seq_printf(s, fmt, val);
@@ -6420,7 +6406,7 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
6420} 6406}
6421 6407
6422/** 6408/**
6423 * pevent_print_func_field - print a field and a format for function pointers 6409 * tep_print_func_field - print a field and a format for function pointers
6424 * @s: The seq to print to 6410 * @s: The seq to print to
6425 * @fmt: The printf format to print the field with. 6411 * @fmt: The printf format to print the field with.
6426 * @event: the event that the field is for 6412 * @event: the event that the field is for
@@ -6430,12 +6416,12 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
6430 * 6416 *
6431 * Returns: 0 on success, -1 field not found, or 1 if buffer is full. 6417 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
6432 */ 6418 */
6433int pevent_print_func_field(struct trace_seq *s, const char *fmt, 6419int tep_print_func_field(struct trace_seq *s, const char *fmt,
6434 struct event_format *event, const char *name, 6420 struct event_format *event, const char *name,
6435 struct pevent_record *record, int err) 6421 struct tep_record *record, int err)
6436{ 6422{
6437 struct format_field *field = pevent_find_field(event, name); 6423 struct format_field *field = tep_find_field(event, name);
6438 struct pevent *pevent = event->pevent; 6424 struct tep_handle *pevent = event->pevent;
6439 unsigned long long val; 6425 unsigned long long val;
6440 struct func_map *func; 6426 struct func_map *func;
6441 char tmp[128]; 6427 char tmp[128];
@@ -6443,7 +6429,7 @@ int pevent_print_func_field(struct trace_seq *s, const char *fmt,
6443 if (!field) 6429 if (!field)
6444 goto failed; 6430 goto failed;
6445 6431
6446 if (pevent_read_number_field(field, record->data, &val)) 6432 if (tep_read_number_field(field, record->data, &val))
6447 goto failed; 6433 goto failed;
6448 6434
6449 func = find_func(pevent, val); 6435 func = find_func(pevent, val);
@@ -6461,9 +6447,9 @@ int pevent_print_func_field(struct trace_seq *s, const char *fmt,
6461 return -1; 6447 return -1;
6462} 6448}
6463 6449
6464static void free_func_handle(struct pevent_function_handler *func) 6450static void free_func_handle(struct tep_function_handler *func)
6465{ 6451{
6466 struct pevent_func_params *params; 6452 struct func_params *params;
6467 6453
6468 free(func->name); 6454 free(func->name);
6469 6455
@@ -6477,29 +6463,29 @@ static void free_func_handle(struct pevent_function_handler *func)
6477} 6463}
6478 6464
6479/** 6465/**
6480 * pevent_register_print_function - register a helper function 6466 * tep_register_print_function - register a helper function
6481 * @pevent: the handle to the pevent 6467 * @pevent: the handle to the pevent
6482 * @func: the function to process the helper function 6468 * @func: the function to process the helper function
6483 * @ret_type: the return type of the helper function 6469 * @ret_type: the return type of the helper function
6484 * @name: the name of the helper function 6470 * @name: the name of the helper function
6485 * @parameters: A list of enum pevent_func_arg_type 6471 * @parameters: A list of enum tep_func_arg_type
6486 * 6472 *
6487 * Some events may have helper functions in the print format arguments. 6473 * Some events may have helper functions in the print format arguments.
6488 * This allows a plugin to dynamically create a way to process one 6474 * This allows a plugin to dynamically create a way to process one
6489 * of these functions. 6475 * of these functions.
6490 * 6476 *
6491 * The @parameters is a variable list of pevent_func_arg_type enums that 6477 * The @parameters is a variable list of tep_func_arg_type enums that
6492 * must end with PEVENT_FUNC_ARG_VOID. 6478 * must end with TEP_FUNC_ARG_VOID.
6493 */ 6479 */
6494int pevent_register_print_function(struct pevent *pevent, 6480int tep_register_print_function(struct tep_handle *pevent,
6495 pevent_func_handler func, 6481 tep_func_handler func,
6496 enum pevent_func_arg_type ret_type, 6482 enum tep_func_arg_type ret_type,
6497 char *name, ...) 6483 char *name, ...)
6498{ 6484{
6499 struct pevent_function_handler *func_handle; 6485 struct tep_function_handler *func_handle;
6500 struct pevent_func_params **next_param; 6486 struct func_params **next_param;
6501 struct pevent_func_params *param; 6487 struct func_params *param;
6502 enum pevent_func_arg_type type; 6488 enum tep_func_arg_type type;
6503 va_list ap; 6489 va_list ap;
6504 int ret; 6490 int ret;
6505 6491
@@ -6517,7 +6503,7 @@ int pevent_register_print_function(struct pevent *pevent,
6517 func_handle = calloc(1, sizeof(*func_handle)); 6503 func_handle = calloc(1, sizeof(*func_handle));
6518 if (!func_handle) { 6504 if (!func_handle) {
6519 do_warning("Failed to allocate function handler"); 6505 do_warning("Failed to allocate function handler");
6520 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 6506 return TEP_ERRNO__MEM_ALLOC_FAILED;
6521 } 6507 }
6522 6508
6523 func_handle->ret_type = ret_type; 6509 func_handle->ret_type = ret_type;
@@ -6526,26 +6512,26 @@ int pevent_register_print_function(struct pevent *pevent,
6526 if (!func_handle->name) { 6512 if (!func_handle->name) {
6527 do_warning("Failed to allocate function name"); 6513 do_warning("Failed to allocate function name");
6528 free(func_handle); 6514 free(func_handle);
6529 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 6515 return TEP_ERRNO__MEM_ALLOC_FAILED;
6530 } 6516 }
6531 6517
6532 next_param = &(func_handle->params); 6518 next_param = &(func_handle->params);
6533 va_start(ap, name); 6519 va_start(ap, name);
6534 for (;;) { 6520 for (;;) {
6535 type = va_arg(ap, enum pevent_func_arg_type); 6521 type = va_arg(ap, enum tep_func_arg_type);
6536 if (type == PEVENT_FUNC_ARG_VOID) 6522 if (type == TEP_FUNC_ARG_VOID)
6537 break; 6523 break;
6538 6524
6539 if (type >= PEVENT_FUNC_ARG_MAX_TYPES) { 6525 if (type >= TEP_FUNC_ARG_MAX_TYPES) {
6540 do_warning("Invalid argument type %d", type); 6526 do_warning("Invalid argument type %d", type);
6541 ret = PEVENT_ERRNO__INVALID_ARG_TYPE; 6527 ret = TEP_ERRNO__INVALID_ARG_TYPE;
6542 goto out_free; 6528 goto out_free;
6543 } 6529 }
6544 6530
6545 param = malloc(sizeof(*param)); 6531 param = malloc(sizeof(*param));
6546 if (!param) { 6532 if (!param) {
6547 do_warning("Failed to allocate function param"); 6533 do_warning("Failed to allocate function param");
6548 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED; 6534 ret = TEP_ERRNO__MEM_ALLOC_FAILED;
6549 goto out_free; 6535 goto out_free;
6550 } 6536 }
6551 param->type = type; 6537 param->type = type;
@@ -6569,7 +6555,7 @@ int pevent_register_print_function(struct pevent *pevent,
6569} 6555}
6570 6556
6571/** 6557/**
6572 * pevent_unregister_print_function - unregister a helper function 6558 * tep_unregister_print_function - unregister a helper function
6573 * @pevent: the handle to the pevent 6559 * @pevent: the handle to the pevent
6574 * @func: the function to process the helper function 6560 * @func: the function to process the helper function
6575 * @name: the name of the helper function 6561 * @name: the name of the helper function
@@ -6578,10 +6564,10 @@ int pevent_register_print_function(struct pevent *pevent,
6578 * 6564 *
6579 * Returns 0 if the handler was removed successully, -1 otherwise. 6565 * Returns 0 if the handler was removed successully, -1 otherwise.
6580 */ 6566 */
6581int pevent_unregister_print_function(struct pevent *pevent, 6567int tep_unregister_print_function(struct tep_handle *pevent,
6582 pevent_func_handler func, char *name) 6568 tep_func_handler func, char *name)
6583{ 6569{
6584 struct pevent_function_handler *func_handle; 6570 struct tep_function_handler *func_handle;
6585 6571
6586 func_handle = find_func_handler(pevent, name); 6572 func_handle = find_func_handler(pevent, name);
6587 if (func_handle && func_handle->func == func) { 6573 if (func_handle && func_handle->func == func) {
@@ -6591,15 +6577,15 @@ int pevent_unregister_print_function(struct pevent *pevent,
6591 return -1; 6577 return -1;
6592} 6578}
6593 6579
6594static struct event_format *pevent_search_event(struct pevent *pevent, int id, 6580static struct event_format *search_event(struct tep_handle *pevent, int id,
6595 const char *sys_name, 6581 const char *sys_name,
6596 const char *event_name) 6582 const char *event_name)
6597{ 6583{
6598 struct event_format *event; 6584 struct event_format *event;
6599 6585
6600 if (id >= 0) { 6586 if (id >= 0) {
6601 /* search by id */ 6587 /* search by id */
6602 event = pevent_find_event(pevent, id); 6588 event = tep_find_event(pevent, id);
6603 if (!event) 6589 if (!event)
6604 return NULL; 6590 return NULL;
6605 if (event_name && (strcmp(event_name, event->name) != 0)) 6591 if (event_name && (strcmp(event_name, event->name) != 0))
@@ -6607,7 +6593,7 @@ static struct event_format *pevent_search_event(struct pevent *pevent, int id,
6607 if (sys_name && (strcmp(sys_name, event->system) != 0)) 6593 if (sys_name && (strcmp(sys_name, event->system) != 0))
6608 return NULL; 6594 return NULL;
6609 } else { 6595 } else {
6610 event = pevent_find_event_by_name(pevent, sys_name, event_name); 6596 event = tep_find_event_by_name(pevent, sys_name, event_name);
6611 if (!event) 6597 if (!event)
6612 return NULL; 6598 return NULL;
6613 } 6599 }
@@ -6615,7 +6601,7 @@ static struct event_format *pevent_search_event(struct pevent *pevent, int id,
6615} 6601}
6616 6602
6617/** 6603/**
6618 * pevent_register_event_handler - register a way to parse an event 6604 * tep_register_event_handler - register a way to parse an event
6619 * @pevent: the handle to the pevent 6605 * @pevent: the handle to the pevent
6620 * @id: the id of the event to register 6606 * @id: the id of the event to register
6621 * @sys_name: the system name the event belongs to 6607 * @sys_name: the system name the event belongs to
@@ -6631,14 +6617,14 @@ static struct event_format *pevent_search_event(struct pevent *pevent, int id,
6631 * If @id is >= 0, then it is used to find the event. 6617 * If @id is >= 0, then it is used to find the event.
6632 * else @sys_name and @event_name are used. 6618 * else @sys_name and @event_name are used.
6633 */ 6619 */
6634int pevent_register_event_handler(struct pevent *pevent, int id, 6620int tep_register_event_handler(struct tep_handle *pevent, int id,
6635 const char *sys_name, const char *event_name, 6621 const char *sys_name, const char *event_name,
6636 pevent_event_handler_func func, void *context) 6622 tep_event_handler_func func, void *context)
6637{ 6623{
6638 struct event_format *event; 6624 struct event_format *event;
6639 struct event_handler *handle; 6625 struct event_handler *handle;
6640 6626
6641 event = pevent_search_event(pevent, id, sys_name, event_name); 6627 event = search_event(pevent, id, sys_name, event_name);
6642 if (event == NULL) 6628 if (event == NULL)
6643 goto not_found; 6629 goto not_found;
6644 6630
@@ -6654,7 +6640,7 @@ int pevent_register_event_handler(struct pevent *pevent, int id,
6654 handle = calloc(1, sizeof(*handle)); 6640 handle = calloc(1, sizeof(*handle));
6655 if (!handle) { 6641 if (!handle) {
6656 do_warning("Failed to allocate event handler"); 6642 do_warning("Failed to allocate event handler");
6657 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 6643 return TEP_ERRNO__MEM_ALLOC_FAILED;
6658 } 6644 }
6659 6645
6660 handle->id = id; 6646 handle->id = id;
@@ -6669,7 +6655,7 @@ int pevent_register_event_handler(struct pevent *pevent, int id,
6669 free((void *)handle->event_name); 6655 free((void *)handle->event_name);
6670 free((void *)handle->sys_name); 6656 free((void *)handle->sys_name);
6671 free(handle); 6657 free(handle);
6672 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 6658 return TEP_ERRNO__MEM_ALLOC_FAILED;
6673 } 6659 }
6674 6660
6675 handle->func = func; 6661 handle->func = func;
@@ -6682,7 +6668,7 @@ int pevent_register_event_handler(struct pevent *pevent, int id,
6682 6668
6683static int handle_matches(struct event_handler *handler, int id, 6669static int handle_matches(struct event_handler *handler, int id,
6684 const char *sys_name, const char *event_name, 6670 const char *sys_name, const char *event_name,
6685 pevent_event_handler_func func, void *context) 6671 tep_event_handler_func func, void *context)
6686{ 6672{
6687 if (id >= 0 && id != handler->id) 6673 if (id >= 0 && id != handler->id)
6688 return 0; 6674 return 0;
@@ -6700,7 +6686,7 @@ static int handle_matches(struct event_handler *handler, int id,
6700} 6686}
6701 6687
6702/** 6688/**
6703 * pevent_unregister_event_handler - unregister an existing event handler 6689 * tep_unregister_event_handler - unregister an existing event handler
6704 * @pevent: the handle to the pevent 6690 * @pevent: the handle to the pevent
6705 * @id: the id of the event to unregister 6691 * @id: the id of the event to unregister
6706 * @sys_name: the system name the handler belongs to 6692 * @sys_name: the system name the handler belongs to
@@ -6715,15 +6701,15 @@ static int handle_matches(struct event_handler *handler, int id,
6715 * 6701 *
6716 * Returns 0 if handler was removed successfully, -1 if event was not found. 6702 * Returns 0 if handler was removed successfully, -1 if event was not found.
6717 */ 6703 */
6718int pevent_unregister_event_handler(struct pevent *pevent, int id, 6704int tep_unregister_event_handler(struct tep_handle *pevent, int id,
6719 const char *sys_name, const char *event_name, 6705 const char *sys_name, const char *event_name,
6720 pevent_event_handler_func func, void *context) 6706 tep_event_handler_func func, void *context)
6721{ 6707{
6722 struct event_format *event; 6708 struct event_format *event;
6723 struct event_handler *handle; 6709 struct event_handler *handle;
6724 struct event_handler **next; 6710 struct event_handler **next;
6725 6711
6726 event = pevent_search_event(pevent, id, sys_name, event_name); 6712 event = search_event(pevent, id, sys_name, event_name);
6727 if (event == NULL) 6713 if (event == NULL)
6728 goto not_found; 6714 goto not_found;
6729 6715
@@ -6754,11 +6740,11 @@ not_found:
6754} 6740}
6755 6741
6756/** 6742/**
6757 * pevent_alloc - create a pevent handle 6743 * tep_alloc - create a pevent handle
6758 */ 6744 */
6759struct pevent *pevent_alloc(void) 6745struct tep_handle *tep_alloc(void)
6760{ 6746{
6761 struct pevent *pevent = calloc(1, sizeof(*pevent)); 6747 struct tep_handle *pevent = calloc(1, sizeof(*pevent));
6762 6748
6763 if (pevent) 6749 if (pevent)
6764 pevent->ref_count = 1; 6750 pevent->ref_count = 1;
@@ -6766,12 +6752,12 @@ struct pevent *pevent_alloc(void)
6766 return pevent; 6752 return pevent;
6767} 6753}
6768 6754
6769void pevent_ref(struct pevent *pevent) 6755void tep_ref(struct tep_handle *pevent)
6770{ 6756{
6771 pevent->ref_count++; 6757 pevent->ref_count++;
6772} 6758}
6773 6759
6774void pevent_free_format_field(struct format_field *field) 6760void tep_free_format_field(struct format_field *field)
6775{ 6761{
6776 free(field->type); 6762 free(field->type);
6777 if (field->alias != field->name) 6763 if (field->alias != field->name)
@@ -6786,7 +6772,7 @@ static void free_format_fields(struct format_field *field)
6786 6772
6787 while (field) { 6773 while (field) {
6788 next = field->next; 6774 next = field->next;
6789 pevent_free_format_field(field); 6775 tep_free_format_field(field);
6790 field = next; 6776 field = next;
6791 } 6777 }
6792} 6778}
@@ -6797,7 +6783,7 @@ static void free_formats(struct format *format)
6797 free_format_fields(format->fields); 6783 free_format_fields(format->fields);
6798} 6784}
6799 6785
6800void pevent_free_format(struct event_format *event) 6786void tep_free_format(struct event_format *event)
6801{ 6787{
6802 free(event->name); 6788 free(event->name);
6803 free(event->system); 6789 free(event->system);
@@ -6811,15 +6797,15 @@ void pevent_free_format(struct event_format *event)
6811} 6797}
6812 6798
6813/** 6799/**
6814 * pevent_free - free a pevent handle 6800 * tep_free - free a pevent handle
6815 * @pevent: the pevent handle to free 6801 * @pevent: the pevent handle to free
6816 */ 6802 */
6817void pevent_free(struct pevent *pevent) 6803void tep_free(struct tep_handle *pevent)
6818{ 6804{
6819 struct cmdline_list *cmdlist, *cmdnext; 6805 struct cmdline_list *cmdlist, *cmdnext;
6820 struct func_list *funclist, *funcnext; 6806 struct func_list *funclist, *funcnext;
6821 struct printk_list *printklist, *printknext; 6807 struct printk_list *printklist, *printknext;
6822 struct pevent_function_handler *func_handler; 6808 struct tep_function_handler *func_handler;
6823 struct event_handler *handle; 6809 struct event_handler *handle;
6824 int i; 6810 int i;
6825 6811
@@ -6883,7 +6869,7 @@ void pevent_free(struct pevent *pevent)
6883 } 6869 }
6884 6870
6885 for (i = 0; i < pevent->nr_events; i++) 6871 for (i = 0; i < pevent->nr_events; i++)
6886 pevent_free_format(pevent->events[i]); 6872 tep_free_format(pevent->events[i]);
6887 6873
6888 while (pevent->handlers) { 6874 while (pevent->handlers) {
6889 handle = pevent->handlers; 6875 handle = pevent->handlers;
@@ -6899,7 +6885,7 @@ void pevent_free(struct pevent *pevent)
6899 free(pevent); 6885 free(pevent);
6900} 6886}
6901 6887
6902void pevent_unref(struct pevent *pevent) 6888void tep_unref(struct tep_handle *pevent)
6903{ 6889{
6904 pevent_free(pevent); 6890 tep_free(pevent);
6905} 6891}
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 0c03538df74c..44b7c2d41f9f 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -41,7 +41,7 @@
41#define DEBUG_RECORD 0 41#define DEBUG_RECORD 0
42#endif 42#endif
43 43
44struct pevent_record { 44struct tep_record {
45 unsigned long long ts; 45 unsigned long long ts;
46 unsigned long long offset; 46 unsigned long long offset;
47 long long missed_events; /* buffer dropped events before */ 47 long long missed_events; /* buffer dropped events before */
@@ -53,8 +53,8 @@ struct pevent_record {
53 int locked; /* Do not free, even if ref_count is zero */ 53 int locked; /* Do not free, even if ref_count is zero */
54 void *priv; 54 void *priv;
55#if DEBUG_RECORD 55#if DEBUG_RECORD
56 struct pevent_record *prev; 56 struct tep_record *prev;
57 struct pevent_record *next; 57 struct tep_record *next;
58 long alloc_addr; 58 long alloc_addr;
59#endif 59#endif
60}; 60};
@@ -98,19 +98,19 @@ extern int trace_seq_do_printf(struct trace_seq *s);
98 98
99/* ----------------------- pevent ----------------------- */ 99/* ----------------------- pevent ----------------------- */
100 100
101struct pevent; 101struct tep_handle;
102struct event_format; 102struct event_format;
103 103
104typedef int (*pevent_event_handler_func)(struct trace_seq *s, 104typedef int (*tep_event_handler_func)(struct trace_seq *s,
105 struct pevent_record *record, 105 struct tep_record *record,
106 struct event_format *event, 106 struct event_format *event,
107 void *context); 107 void *context);
108 108
109typedef int (*pevent_plugin_load_func)(struct pevent *pevent); 109typedef int (*tep_plugin_load_func)(struct tep_handle *pevent);
110typedef int (*pevent_plugin_unload_func)(struct pevent *pevent); 110typedef int (*tep_plugin_unload_func)(struct tep_handle *pevent);
111 111
112struct pevent_plugin_option { 112struct tep_plugin_option {
113 struct pevent_plugin_option *next; 113 struct tep_plugin_option *next;
114 void *handle; 114 void *handle;
115 char *file; 115 char *file;
116 char *name; 116 char *name;
@@ -124,20 +124,20 @@ struct pevent_plugin_option {
124/* 124/*
125 * Plugin hooks that can be called: 125 * Plugin hooks that can be called:
126 * 126 *
127 * PEVENT_PLUGIN_LOADER: (required) 127 * TEP_PLUGIN_LOADER: (required)
128 * The function name to initialized the plugin. 128 * The function name to initialized the plugin.
129 * 129 *
130 * int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 130 * int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
131 * 131 *
132 * PEVENT_PLUGIN_UNLOADER: (optional) 132 * TEP_PLUGIN_UNLOADER: (optional)
133 * The function called just before unloading 133 * The function called just before unloading
134 * 134 *
135 * int PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 135 * int TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
136 * 136 *
137 * PEVENT_PLUGIN_OPTIONS: (optional) 137 * TEP_PLUGIN_OPTIONS: (optional)
138 * Plugin options that can be set before loading 138 * Plugin options that can be set before loading
139 * 139 *
140 * struct pevent_plugin_option PEVENT_PLUGIN_OPTIONS[] = { 140 * struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = {
141 * { 141 * {
142 * .name = "option-name", 142 * .name = "option-name",
143 * .plugin_alias = "override-file-name", (optional) 143 * .plugin_alias = "override-file-name", (optional)
@@ -158,19 +158,19 @@ struct pevent_plugin_option {
158 * .set will be processed. If .value is defined, then it is considered 158 * .set will be processed. If .value is defined, then it is considered
159 * a string option and .set will be ignored. 159 * a string option and .set will be ignored.
160 * 160 *
161 * PEVENT_PLUGIN_ALIAS: (optional) 161 * TEP_PLUGIN_ALIAS: (optional)
162 * The name to use for finding options (uses filename if not defined) 162 * The name to use for finding options (uses filename if not defined)
163 */ 163 */
164#define PEVENT_PLUGIN_LOADER pevent_plugin_loader 164#define TEP_PLUGIN_LOADER tep_plugin_loader
165#define PEVENT_PLUGIN_UNLOADER pevent_plugin_unloader 165#define TEP_PLUGIN_UNLOADER tep_plugin_unloader
166#define PEVENT_PLUGIN_OPTIONS pevent_plugin_options 166#define TEP_PLUGIN_OPTIONS tep_plugin_options
167#define PEVENT_PLUGIN_ALIAS pevent_plugin_alias 167#define TEP_PLUGIN_ALIAS tep_plugin_alias
168#define _MAKE_STR(x) #x 168#define _MAKE_STR(x) #x
169#define MAKE_STR(x) _MAKE_STR(x) 169#define MAKE_STR(x) _MAKE_STR(x)
170#define PEVENT_PLUGIN_LOADER_NAME MAKE_STR(PEVENT_PLUGIN_LOADER) 170#define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER)
171#define PEVENT_PLUGIN_UNLOADER_NAME MAKE_STR(PEVENT_PLUGIN_UNLOADER) 171#define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER)
172#define PEVENT_PLUGIN_OPTIONS_NAME MAKE_STR(PEVENT_PLUGIN_OPTIONS) 172#define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
173#define PEVENT_PLUGIN_ALIAS_NAME MAKE_STR(PEVENT_PLUGIN_ALIAS) 173#define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
174 174
175enum format_flags { 175enum format_flags {
176 FIELD_IS_ARRAY = 1, 176 FIELD_IS_ARRAY = 1,
@@ -269,10 +269,10 @@ struct print_arg_op {
269 struct print_arg *right; 269 struct print_arg *right;
270}; 270};
271 271
272struct pevent_function_handler; 272struct tep_function_handler;
273 273
274struct print_arg_func { 274struct print_arg_func {
275 struct pevent_function_handler *func; 275 struct tep_function_handler *func;
276 struct print_arg *args; 276 struct print_arg *args;
277}; 277};
278 278
@@ -320,14 +320,14 @@ struct print_fmt {
320}; 320};
321 321
322struct event_format { 322struct event_format {
323 struct pevent *pevent; 323 struct tep_handle *pevent;
324 char *name; 324 char *name;
325 int id; 325 int id;
326 int flags; 326 int flags;
327 struct format format; 327 struct format format;
328 struct print_fmt print_fmt; 328 struct print_fmt print_fmt;
329 char *system; 329 char *system;
330 pevent_event_handler_func handler; 330 tep_event_handler_func handler;
331 void *context; 331 void *context;
332}; 332};
333 333
@@ -361,25 +361,25 @@ enum event_type {
361 EVENT_SQUOTE, 361 EVENT_SQUOTE,
362}; 362};
363 363
364typedef unsigned long long (*pevent_func_handler)(struct trace_seq *s, 364typedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
365 unsigned long long *args); 365 unsigned long long *args);
366 366
367enum pevent_func_arg_type { 367enum tep_func_arg_type {
368 PEVENT_FUNC_ARG_VOID, 368 TEP_FUNC_ARG_VOID,
369 PEVENT_FUNC_ARG_INT, 369 TEP_FUNC_ARG_INT,
370 PEVENT_FUNC_ARG_LONG, 370 TEP_FUNC_ARG_LONG,
371 PEVENT_FUNC_ARG_STRING, 371 TEP_FUNC_ARG_STRING,
372 PEVENT_FUNC_ARG_PTR, 372 TEP_FUNC_ARG_PTR,
373 PEVENT_FUNC_ARG_MAX_TYPES 373 TEP_FUNC_ARG_MAX_TYPES
374}; 374};
375 375
376enum pevent_flag { 376enum tep_flag {
377 PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */ 377 TEP_NSEC_OUTPUT = 1, /* output in NSECS */
378 PEVENT_DISABLE_SYS_PLUGINS = 1 << 1, 378 TEP_DISABLE_SYS_PLUGINS = 1 << 1,
379 PEVENT_DISABLE_PLUGINS = 1 << 2, 379 TEP_DISABLE_PLUGINS = 1 << 2,
380}; 380};
381 381
382#define PEVENT_ERRORS \ 382#define TEP_ERRORS \
383 _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \ 383 _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \
384 _PE(PARSE_EVENT_FAILED, "failed to parse event"), \ 384 _PE(PARSE_EVENT_FAILED, "failed to parse event"), \
385 _PE(READ_ID_FAILED, "failed to read event id"), \ 385 _PE(READ_ID_FAILED, "failed to read event id"), \
@@ -411,10 +411,10 @@ enum pevent_flag {
411 _PE(FILTER_MISS, "record does not match to filter") 411 _PE(FILTER_MISS, "record does not match to filter")
412 412
413#undef _PE 413#undef _PE
414#define _PE(__code, __str) PEVENT_ERRNO__ ## __code 414#define _PE(__code, __str) TEP_ERRNO__ ## __code
415enum pevent_errno { 415enum tep_errno {
416 PEVENT_ERRNO__SUCCESS = 0, 416 TEP_ERRNO__SUCCESS = 0,
417 PEVENT_ERRNO__FILTER_MATCH = PEVENT_ERRNO__SUCCESS, 417 TEP_ERRNO__FILTER_MATCH = TEP_ERRNO__SUCCESS,
418 418
419 /* 419 /*
420 * Choose an arbitrary negative big number not to clash with standard 420 * Choose an arbitrary negative big number not to clash with standard
@@ -423,11 +423,11 @@ enum pevent_errno {
423 * 423 *
424 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html 424 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
425 */ 425 */
426 __PEVENT_ERRNO__START = -100000, 426 __TEP_ERRNO__START = -100000,
427 427
428 PEVENT_ERRORS, 428 TEP_ERRORS,
429 429
430 __PEVENT_ERRNO__END, 430 __TEP_ERRNO__END,
431}; 431};
432#undef _PE 432#undef _PE
433 433
@@ -435,17 +435,17 @@ struct plugin_list;
435 435
436#define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1)) 436#define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1))
437 437
438struct plugin_list *traceevent_load_plugins(struct pevent *pevent); 438struct plugin_list *tep_load_plugins(struct tep_handle *pevent);
439void traceevent_unload_plugins(struct plugin_list *plugin_list, 439void tep_unload_plugins(struct plugin_list *plugin_list,
440 struct pevent *pevent); 440 struct tep_handle *pevent);
441char **traceevent_plugin_list_options(void); 441char **tep_plugin_list_options(void);
442void traceevent_plugin_free_options_list(char **list); 442void tep_plugin_free_options_list(char **list);
443int traceevent_plugin_add_options(const char *name, 443int tep_plugin_add_options(const char *name,
444 struct pevent_plugin_option *options); 444 struct tep_plugin_option *options);
445void traceevent_plugin_remove_options(struct pevent_plugin_option *options); 445void tep_plugin_remove_options(struct tep_plugin_option *options);
446void traceevent_print_plugins(struct trace_seq *s, 446void tep_print_plugins(struct trace_seq *s,
447 const char *prefix, const char *suffix, 447 const char *prefix, const char *suffix,
448 const struct plugin_list *list); 448 const struct plugin_list *list);
449 449
450struct cmdline; 450struct cmdline;
451struct cmdline_list; 451struct cmdline_list;
@@ -454,10 +454,10 @@ struct func_list;
454struct event_handler; 454struct event_handler;
455struct func_resolver; 455struct func_resolver;
456 456
457typedef char *(pevent_func_resolver_t)(void *priv, 457typedef char *(tep_func_resolver_t)(void *priv,
458 unsigned long long *addrp, char **modp); 458 unsigned long long *addrp, char **modp);
459 459
460struct pevent { 460struct tep_handle {
461 int ref_count; 461 int ref_count;
462 462
463 int header_page_ts_offset; 463 int header_page_ts_offset;
@@ -524,7 +524,7 @@ struct pevent {
524 struct format_field *bprint_buf_field; 524 struct format_field *bprint_buf_field;
525 525
526 struct event_handler *handlers; 526 struct event_handler *handlers;
527 struct pevent_function_handler *func_handlers; 527 struct tep_function_handler *func_handlers;
528 528
529 /* cache */ 529 /* cache */
530 struct event_format *last_event; 530 struct event_format *last_event;
@@ -532,13 +532,13 @@ struct pevent {
532 char *trace_clock; 532 char *trace_clock;
533}; 533};
534 534
535static inline void pevent_set_flag(struct pevent *pevent, int flag) 535static inline void tep_set_flag(struct tep_handle *pevent, int flag)
536{ 536{
537 pevent->flags |= flag; 537 pevent->flags |= flag;
538} 538}
539 539
540static inline unsigned short 540static inline unsigned short
541__data2host2(struct pevent *pevent, unsigned short data) 541__data2host2(struct tep_handle *pevent, unsigned short data)
542{ 542{
543 unsigned short swap; 543 unsigned short swap;
544 544
@@ -552,7 +552,7 @@ __data2host2(struct pevent *pevent, unsigned short data)
552} 552}
553 553
554static inline unsigned int 554static inline unsigned int
555__data2host4(struct pevent *pevent, unsigned int data) 555__data2host4(struct tep_handle *pevent, unsigned int data)
556{ 556{
557 unsigned int swap; 557 unsigned int swap;
558 558
@@ -568,7 +568,7 @@ __data2host4(struct pevent *pevent, unsigned int data)
568} 568}
569 569
570static inline unsigned long long 570static inline unsigned long long
571__data2host8(struct pevent *pevent, unsigned long long data) 571__data2host8(struct tep_handle *pevent, unsigned long long data)
572{ 572{
573 unsigned long long swap; 573 unsigned long long swap;
574 574
@@ -597,7 +597,7 @@ __data2host8(struct pevent *pevent, unsigned long long data)
597 __data2host8(pevent, __val); \ 597 __data2host8(pevent, __val); \
598}) 598})
599 599
600static inline int traceevent_host_bigendian(void) 600static inline int tep_host_bigendian(void)
601{ 601{
602 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 }; 602 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
603 unsigned int val; 603 unsigned int val;
@@ -615,198 +615,198 @@ enum trace_flag_type {
615 TRACE_FLAG_SOFTIRQ = 0x10, 615 TRACE_FLAG_SOFTIRQ = 0x10,
616}; 616};
617 617
618int pevent_set_function_resolver(struct pevent *pevent, 618int tep_set_function_resolver(struct tep_handle *pevent,
619 pevent_func_resolver_t *func, void *priv); 619 tep_func_resolver_t *func, void *priv);
620void pevent_reset_function_resolver(struct pevent *pevent); 620void tep_reset_function_resolver(struct tep_handle *pevent);
621int pevent_register_comm(struct pevent *pevent, const char *comm, int pid); 621int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid);
622int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock); 622int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock);
623int pevent_register_function(struct pevent *pevent, char *name, 623int tep_register_function(struct tep_handle *pevent, char *name,
624 unsigned long long addr, char *mod); 624 unsigned long long addr, char *mod);
625int pevent_register_print_string(struct pevent *pevent, const char *fmt, 625int tep_register_print_string(struct tep_handle *pevent, const char *fmt,
626 unsigned long long addr); 626 unsigned long long addr);
627int pevent_pid_is_registered(struct pevent *pevent, int pid); 627int tep_pid_is_registered(struct tep_handle *pevent, int pid);
628 628
629void pevent_print_event_task(struct pevent *pevent, struct trace_seq *s, 629void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
630 struct event_format *event, 630 struct event_format *event,
631 struct pevent_record *record); 631 struct tep_record *record);
632void pevent_print_event_time(struct pevent *pevent, struct trace_seq *s, 632void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
633 struct event_format *event, 633 struct event_format *event,
634 struct pevent_record *record, 634 struct tep_record *record,
635 bool use_trace_clock); 635 bool use_trace_clock);
636void pevent_print_event_data(struct pevent *pevent, struct trace_seq *s, 636void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
637 struct event_format *event, 637 struct event_format *event,
638 struct pevent_record *record); 638 struct tep_record *record);
639void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 639void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
640 struct pevent_record *record, bool use_trace_clock); 640 struct tep_record *record, bool use_trace_clock);
641 641
642int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size, 642int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long size,
643 int long_size); 643 int long_size);
644 644
645enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, 645enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
646 unsigned long size, const char *sys); 646 unsigned long size, const char *sys);
647enum pevent_errno pevent_parse_format(struct pevent *pevent, 647enum tep_errno tep_parse_format(struct tep_handle *pevent,
648 struct event_format **eventp, 648 struct event_format **eventp,
649 const char *buf, 649 const char *buf,
650 unsigned long size, const char *sys); 650 unsigned long size, const char *sys);
651void pevent_free_format(struct event_format *event); 651void tep_free_format(struct event_format *event);
652void pevent_free_format_field(struct format_field *field); 652void tep_free_format_field(struct format_field *field);
653 653
654void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event, 654void *tep_get_field_raw(struct trace_seq *s, struct event_format *event,
655 const char *name, struct pevent_record *record, 655 const char *name, struct tep_record *record,
656 int *len, int err); 656 int *len, int err);
657 657
658int pevent_get_field_val(struct trace_seq *s, struct event_format *event, 658int tep_get_field_val(struct trace_seq *s, struct event_format *event,
659 const char *name, struct pevent_record *record, 659 const char *name, struct tep_record *record,
660 unsigned long long *val, int err); 660 unsigned long long *val, int err);
661int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event, 661int tep_get_common_field_val(struct trace_seq *s, struct event_format *event,
662 const char *name, struct pevent_record *record, 662 const char *name, struct tep_record *record,
663 unsigned long long *val, int err);
664int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
665 const char *name, struct pevent_record *record,
666 unsigned long long *val, int err); 663 unsigned long long *val, int err);
664int tep_get_any_field_val(struct trace_seq *s, struct event_format *event,
665 const char *name, struct tep_record *record,
666 unsigned long long *val, int err);
667 667
668int pevent_print_num_field(struct trace_seq *s, const char *fmt, 668int tep_print_num_field(struct trace_seq *s, const char *fmt,
669 struct event_format *event, const char *name, 669 struct event_format *event, const char *name,
670 struct pevent_record *record, int err); 670 struct tep_record *record, int err);
671 671
672int pevent_print_func_field(struct trace_seq *s, const char *fmt, 672int tep_print_func_field(struct trace_seq *s, const char *fmt,
673 struct event_format *event, const char *name, 673 struct event_format *event, const char *name,
674 struct pevent_record *record, int err); 674 struct tep_record *record, int err);
675 675
676int pevent_register_event_handler(struct pevent *pevent, int id, 676int tep_register_event_handler(struct tep_handle *pevent, int id,
677 const char *sys_name, const char *event_name, 677 const char *sys_name, const char *event_name,
678 pevent_event_handler_func func, void *context); 678 tep_event_handler_func func, void *context);
679int pevent_unregister_event_handler(struct pevent *pevent, int id, 679int tep_unregister_event_handler(struct tep_handle *pevent, int id,
680 const char *sys_name, const char *event_name, 680 const char *sys_name, const char *event_name,
681 pevent_event_handler_func func, void *context); 681 tep_event_handler_func func, void *context);
682int pevent_register_print_function(struct pevent *pevent, 682int tep_register_print_function(struct tep_handle *pevent,
683 pevent_func_handler func, 683 tep_func_handler func,
684 enum pevent_func_arg_type ret_type, 684 enum tep_func_arg_type ret_type,
685 char *name, ...); 685 char *name, ...);
686int pevent_unregister_print_function(struct pevent *pevent, 686int tep_unregister_print_function(struct tep_handle *pevent,
687 pevent_func_handler func, char *name); 687 tep_func_handler func, char *name);
688 688
689struct format_field *pevent_find_common_field(struct event_format *event, const char *name); 689struct format_field *tep_find_common_field(struct event_format *event, const char *name);
690struct format_field *pevent_find_field(struct event_format *event, const char *name); 690struct format_field *tep_find_field(struct event_format *event, const char *name);
691struct format_field *pevent_find_any_field(struct event_format *event, const char *name); 691struct format_field *tep_find_any_field(struct event_format *event, const char *name);
692 692
693const char *pevent_find_function(struct pevent *pevent, unsigned long long addr); 693const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr);
694unsigned long long 694unsigned long long
695pevent_find_function_address(struct pevent *pevent, unsigned long long addr); 695tep_find_function_address(struct tep_handle *pevent, unsigned long long addr);
696unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr, int size); 696unsigned long long tep_read_number(struct tep_handle *pevent, const void *ptr, int size);
697int pevent_read_number_field(struct format_field *field, const void *data, 697int tep_read_number_field(struct format_field *field, const void *data,
698 unsigned long long *value); 698 unsigned long long *value);
699 699
700struct event_format *pevent_find_event(struct pevent *pevent, int id); 700struct event_format *tep_find_event(struct tep_handle *pevent, int id);
701 701
702struct event_format * 702struct event_format *
703pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name); 703tep_find_event_by_name(struct tep_handle *pevent, const char *sys, const char *name);
704 704
705struct event_format * 705struct event_format *
706pevent_find_event_by_record(struct pevent *pevent, struct pevent_record *record); 706tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record);
707 707
708void pevent_data_lat_fmt(struct pevent *pevent, 708void tep_data_lat_fmt(struct tep_handle *pevent,
709 struct trace_seq *s, struct pevent_record *record); 709 struct trace_seq *s, struct tep_record *record);
710int pevent_data_type(struct pevent *pevent, struct pevent_record *rec); 710int tep_data_type(struct tep_handle *pevent, struct tep_record *rec);
711struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type); 711struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type);
712int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec); 712int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec);
713int pevent_data_preempt_count(struct pevent *pevent, struct pevent_record *rec); 713int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec);
714int pevent_data_flags(struct pevent *pevent, struct pevent_record *rec); 714int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec);
715const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid); 715const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid);
716struct cmdline; 716struct cmdline;
717struct cmdline *pevent_data_pid_from_comm(struct pevent *pevent, const char *comm, 717struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm,
718 struct cmdline *next); 718 struct cmdline *next);
719int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline); 719int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline);
720 720
721void pevent_print_field(struct trace_seq *s, void *data, 721void tep_print_field(struct trace_seq *s, void *data,
722 struct format_field *field); 722 struct format_field *field);
723void pevent_print_fields(struct trace_seq *s, void *data, 723void tep_print_fields(struct trace_seq *s, void *data,
724 int size __maybe_unused, struct event_format *event); 724 int size __maybe_unused, struct event_format *event);
725void pevent_event_info(struct trace_seq *s, struct event_format *event, 725void tep_event_info(struct trace_seq *s, struct event_format *event,
726 struct pevent_record *record); 726 struct tep_record *record);
727int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum, 727int tep_strerror(struct tep_handle *pevent, enum tep_errno errnum,
728 char *buf, size_t buflen); 728 char *buf, size_t buflen);
729 729
730struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type); 730struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type);
731struct format_field **pevent_event_common_fields(struct event_format *event); 731struct format_field **tep_event_common_fields(struct event_format *event);
732struct format_field **pevent_event_fields(struct event_format *event); 732struct format_field **tep_event_fields(struct event_format *event);
733 733
734static inline int pevent_get_cpus(struct pevent *pevent) 734static inline int tep_get_cpus(struct tep_handle *pevent)
735{ 735{
736 return pevent->cpus; 736 return pevent->cpus;
737} 737}
738 738
739static inline void pevent_set_cpus(struct pevent *pevent, int cpus) 739static inline void tep_set_cpus(struct tep_handle *pevent, int cpus)
740{ 740{
741 pevent->cpus = cpus; 741 pevent->cpus = cpus;
742} 742}
743 743
744static inline int pevent_get_long_size(struct pevent *pevent) 744static inline int tep_get_long_size(struct tep_handle *pevent)
745{ 745{
746 return pevent->long_size; 746 return pevent->long_size;
747} 747}
748 748
749static inline void pevent_set_long_size(struct pevent *pevent, int long_size) 749static inline void tep_set_long_size(struct tep_handle *pevent, int long_size)
750{ 750{
751 pevent->long_size = long_size; 751 pevent->long_size = long_size;
752} 752}
753 753
754static inline int pevent_get_page_size(struct pevent *pevent) 754static inline int tep_get_page_size(struct tep_handle *pevent)
755{ 755{
756 return pevent->page_size; 756 return pevent->page_size;
757} 757}
758 758
759static inline void pevent_set_page_size(struct pevent *pevent, int _page_size) 759static inline void tep_set_page_size(struct tep_handle *pevent, int _page_size)
760{ 760{
761 pevent->page_size = _page_size; 761 pevent->page_size = _page_size;
762} 762}
763 763
764static inline int pevent_is_file_bigendian(struct pevent *pevent) 764static inline int tep_is_file_bigendian(struct tep_handle *pevent)
765{ 765{
766 return pevent->file_bigendian; 766 return pevent->file_bigendian;
767} 767}
768 768
769static inline void pevent_set_file_bigendian(struct pevent *pevent, int endian) 769static inline void tep_set_file_bigendian(struct tep_handle *pevent, int endian)
770{ 770{
771 pevent->file_bigendian = endian; 771 pevent->file_bigendian = endian;
772} 772}
773 773
774static inline int pevent_is_host_bigendian(struct pevent *pevent) 774static inline int tep_is_host_bigendian(struct tep_handle *pevent)
775{ 775{
776 return pevent->host_bigendian; 776 return pevent->host_bigendian;
777} 777}
778 778
779static inline void pevent_set_host_bigendian(struct pevent *pevent, int endian) 779static inline void tep_set_host_bigendian(struct tep_handle *pevent, int endian)
780{ 780{
781 pevent->host_bigendian = endian; 781 pevent->host_bigendian = endian;
782} 782}
783 783
784static inline int pevent_is_latency_format(struct pevent *pevent) 784static inline int tep_is_latency_format(struct tep_handle *pevent)
785{ 785{
786 return pevent->latency_format; 786 return pevent->latency_format;
787} 787}
788 788
789static inline void pevent_set_latency_format(struct pevent *pevent, int lat) 789static inline void tep_set_latency_format(struct tep_handle *pevent, int lat)
790{ 790{
791 pevent->latency_format = lat; 791 pevent->latency_format = lat;
792} 792}
793 793
794struct pevent *pevent_alloc(void); 794struct tep_handle *tep_alloc(void);
795void pevent_free(struct pevent *pevent); 795void tep_free(struct tep_handle *pevent);
796void pevent_ref(struct pevent *pevent); 796void tep_ref(struct tep_handle *pevent);
797void pevent_unref(struct pevent *pevent); 797void tep_unref(struct tep_handle *pevent);
798 798
799/* access to the internal parser */ 799/* access to the internal parser */
800void pevent_buffer_init(const char *buf, unsigned long long size); 800void tep_buffer_init(const char *buf, unsigned long long size);
801enum event_type pevent_read_token(char **tok); 801enum event_type tep_read_token(char **tok);
802void pevent_free_token(char *token); 802void tep_free_token(char *token);
803int pevent_peek_char(void); 803int tep_peek_char(void);
804const char *pevent_get_input_buf(void); 804const char *tep_get_input_buf(void);
805unsigned long long pevent_get_input_buf_ptr(void); 805unsigned long long tep_get_input_buf_ptr(void);
806 806
807/* for debugging */ 807/* for debugging */
808void pevent_print_funcs(struct pevent *pevent); 808void tep_print_funcs(struct tep_handle *pevent);
809void pevent_print_printk(struct pevent *pevent); 809void tep_print_printk(struct tep_handle *pevent);
810 810
811/* ----------------------- filtering ----------------------- */ 811/* ----------------------- filtering ----------------------- */
812 812
@@ -930,22 +930,22 @@ struct filter_type {
930 struct filter_arg *filter; 930 struct filter_arg *filter;
931}; 931};
932 932
933#define PEVENT_FILTER_ERROR_BUFSZ 1024 933#define TEP_FILTER_ERROR_BUFSZ 1024
934 934
935struct event_filter { 935struct event_filter {
936 struct pevent *pevent; 936 struct tep_handle *pevent;
937 int filters; 937 int filters;
938 struct filter_type *event_filters; 938 struct filter_type *event_filters;
939 char error_buffer[PEVENT_FILTER_ERROR_BUFSZ]; 939 char error_buffer[TEP_FILTER_ERROR_BUFSZ];
940}; 940};
941 941
942struct event_filter *pevent_filter_alloc(struct pevent *pevent); 942struct event_filter *tep_filter_alloc(struct tep_handle *pevent);
943 943
944/* for backward compatibility */ 944/* for backward compatibility */
945#define FILTER_NONE PEVENT_ERRNO__NO_FILTER 945#define FILTER_NONE TEP_ERRNO__NO_FILTER
946#define FILTER_NOEXIST PEVENT_ERRNO__FILTER_NOT_FOUND 946#define FILTER_NOEXIST TEP_ERRNO__FILTER_NOT_FOUND
947#define FILTER_MISS PEVENT_ERRNO__FILTER_MISS 947#define FILTER_MISS TEP_ERRNO__FILTER_MISS
948#define FILTER_MATCH PEVENT_ERRNO__FILTER_MATCH 948#define FILTER_MATCH TEP_ERRNO__FILTER_MATCH
949 949
950enum filter_trivial_type { 950enum filter_trivial_type {
951 FILTER_TRIVIAL_FALSE, 951 FILTER_TRIVIAL_FALSE,
@@ -953,39 +953,39 @@ enum filter_trivial_type {
953 FILTER_TRIVIAL_BOTH, 953 FILTER_TRIVIAL_BOTH,
954}; 954};
955 955
956enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter, 956enum tep_errno tep_filter_add_filter_str(struct event_filter *filter,
957 const char *filter_str); 957 const char *filter_str);
958 958
959enum pevent_errno pevent_filter_match(struct event_filter *filter, 959enum tep_errno tep_filter_match(struct event_filter *filter,
960 struct pevent_record *record); 960 struct tep_record *record);
961 961
962int pevent_filter_strerror(struct event_filter *filter, enum pevent_errno err, 962int tep_filter_strerror(struct event_filter *filter, enum tep_errno err,
963 char *buf, size_t buflen); 963 char *buf, size_t buflen);
964 964
965int pevent_event_filtered(struct event_filter *filter, 965int tep_event_filtered(struct event_filter *filter,
966 int event_id); 966 int event_id);
967 967
968void pevent_filter_reset(struct event_filter *filter); 968void tep_filter_reset(struct event_filter *filter);
969 969
970int pevent_filter_clear_trivial(struct event_filter *filter, 970int tep_filter_clear_trivial(struct event_filter *filter,
971 enum filter_trivial_type type); 971 enum filter_trivial_type type);
972 972
973void pevent_filter_free(struct event_filter *filter); 973void tep_filter_free(struct event_filter *filter);
974 974
975char *pevent_filter_make_string(struct event_filter *filter, int event_id); 975char *tep_filter_make_string(struct event_filter *filter, int event_id);
976 976
977int pevent_filter_remove_event(struct event_filter *filter, 977int tep_filter_remove_event(struct event_filter *filter,
978 int event_id); 978 int event_id);
979 979
980int pevent_filter_event_has_trivial(struct event_filter *filter, 980int tep_filter_event_has_trivial(struct event_filter *filter,
981 int event_id, 981 int event_id,
982 enum filter_trivial_type type); 982 enum filter_trivial_type type);
983 983
984int pevent_filter_copy(struct event_filter *dest, struct event_filter *source); 984int tep_filter_copy(struct event_filter *dest, struct event_filter *source);
985 985
986int pevent_update_trivial(struct event_filter *dest, struct event_filter *source, 986int tep_update_trivial(struct event_filter *dest, struct event_filter *source,
987 enum filter_trivial_type type); 987 enum filter_trivial_type type);
988 988
989int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2); 989int tep_filter_compare(struct event_filter *filter1, struct event_filter *filter2);
990 990
991#endif /* _PARSE_EVENTS_H */ 991#endif /* _PARSE_EVENTS_H */
diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index d542cb60ca1a..f17e25097e1e 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -1,21 +1,7 @@
1// SPDX-License-Identifier: LGPL-2.1
1/* 2/*
2 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 * 4 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */ 5 */
20 6
21#include <ctype.h> 7#include <ctype.h>
@@ -34,7 +20,7 @@
34 20
35static struct registered_plugin_options { 21static struct registered_plugin_options {
36 struct registered_plugin_options *next; 22 struct registered_plugin_options *next;
37 struct pevent_plugin_option *options; 23 struct tep_plugin_option *options;
38} *registered_options; 24} *registered_options;
39 25
40static struct trace_plugin_options { 26static struct trace_plugin_options {
@@ -58,7 +44,7 @@ static void lower_case(char *str)
58 *str = tolower(*str); 44 *str = tolower(*str);
59} 45}
60 46
61static int update_option_value(struct pevent_plugin_option *op, const char *val) 47static int update_option_value(struct tep_plugin_option *op, const char *val)
62{ 48{
63 char *op_val; 49 char *op_val;
64 50
@@ -97,7 +83,7 @@ static int update_option_value(struct pevent_plugin_option *op, const char *val)
97} 83}
98 84
99/** 85/**
100 * traceevent_plugin_list_options - get list of plugin options 86 * tep_plugin_list_options - get list of plugin options
101 * 87 *
102 * Returns an array of char strings that list the currently registered 88 * Returns an array of char strings that list the currently registered
103 * plugin options in the format of <plugin>:<option>. This list can be 89 * plugin options in the format of <plugin>:<option>. This list can be
@@ -106,12 +92,12 @@ static int update_option_value(struct pevent_plugin_option *op, const char *val)
106 * Returns NULL if there's no options registered. On error it returns 92 * Returns NULL if there's no options registered. On error it returns
107 * INVALID_PLUGIN_LIST_OPTION 93 * INVALID_PLUGIN_LIST_OPTION
108 * 94 *
109 * Must be freed with traceevent_plugin_free_options_list(). 95 * Must be freed with tep_plugin_free_options_list().
110 */ 96 */
111char **traceevent_plugin_list_options(void) 97char **tep_plugin_list_options(void)
112{ 98{
113 struct registered_plugin_options *reg; 99 struct registered_plugin_options *reg;
114 struct pevent_plugin_option *op; 100 struct tep_plugin_option *op;
115 char **list = NULL; 101 char **list = NULL;
116 char *name; 102 char *name;
117 int count = 0; 103 int count = 0;
@@ -146,7 +132,7 @@ char **traceevent_plugin_list_options(void)
146 return INVALID_PLUGIN_LIST_OPTION; 132 return INVALID_PLUGIN_LIST_OPTION;
147} 133}
148 134
149void traceevent_plugin_free_options_list(char **list) 135void tep_plugin_free_options_list(char **list)
150{ 136{
151 int i; 137 int i;
152 138
@@ -163,7 +149,7 @@ void traceevent_plugin_free_options_list(char **list)
163} 149}
164 150
165static int 151static int
166update_option(const char *file, struct pevent_plugin_option *option) 152update_option(const char *file, struct tep_plugin_option *option)
167{ 153{
168 struct trace_plugin_options *op; 154 struct trace_plugin_options *op;
169 char *plugin; 155 char *plugin;
@@ -215,14 +201,14 @@ update_option(const char *file, struct pevent_plugin_option *option)
215} 201}
216 202
217/** 203/**
218 * traceevent_plugin_add_options - Add a set of options by a plugin 204 * tep_plugin_add_options - Add a set of options by a plugin
219 * @name: The name of the plugin adding the options 205 * @name: The name of the plugin adding the options
220 * @options: The set of options being loaded 206 * @options: The set of options being loaded
221 * 207 *
222 * Sets the options with the values that have been added by user. 208 * Sets the options with the values that have been added by user.
223 */ 209 */
224int traceevent_plugin_add_options(const char *name, 210int tep_plugin_add_options(const char *name,
225 struct pevent_plugin_option *options) 211 struct tep_plugin_option *options)
226{ 212{
227 struct registered_plugin_options *reg; 213 struct registered_plugin_options *reg;
228 214
@@ -241,10 +227,10 @@ int traceevent_plugin_add_options(const char *name,
241} 227}
242 228
243/** 229/**
244 * traceevent_plugin_remove_options - remove plugin options that were registered 230 * tep_plugin_remove_options - remove plugin options that were registered
245 * @options: Options to removed that were registered with traceevent_plugin_add_options 231 * @options: Options to removed that were registered with tep_plugin_add_options
246 */ 232 */
247void traceevent_plugin_remove_options(struct pevent_plugin_option *options) 233void tep_plugin_remove_options(struct tep_plugin_option *options)
248{ 234{
249 struct registered_plugin_options **last; 235 struct registered_plugin_options **last;
250 struct registered_plugin_options *reg; 236 struct registered_plugin_options *reg;
@@ -260,19 +246,19 @@ void traceevent_plugin_remove_options(struct pevent_plugin_option *options)
260} 246}
261 247
262/** 248/**
263 * traceevent_print_plugins - print out the list of plugins loaded 249 * tep_print_plugins - print out the list of plugins loaded
264 * @s: the trace_seq descripter to write to 250 * @s: the trace_seq descripter to write to
265 * @prefix: The prefix string to add before listing the option name 251 * @prefix: The prefix string to add before listing the option name
266 * @suffix: The suffix string ot append after the option name 252 * @suffix: The suffix string ot append after the option name
267 * @list: The list of plugins (usually returned by traceevent_load_plugins() 253 * @list: The list of plugins (usually returned by tep_load_plugins()
268 * 254 *
269 * Writes to the trace_seq @s the list of plugins (files) that is 255 * Writes to the trace_seq @s the list of plugins (files) that is
270 * returned by traceevent_load_plugins(). Use @prefix and @suffix for formating: 256 * returned by tep_load_plugins(). Use @prefix and @suffix for formating:
271 * @prefix = " ", @suffix = "\n". 257 * @prefix = " ", @suffix = "\n".
272 */ 258 */
273void traceevent_print_plugins(struct trace_seq *s, 259void tep_print_plugins(struct trace_seq *s,
274 const char *prefix, const char *suffix, 260 const char *prefix, const char *suffix,
275 const struct plugin_list *list) 261 const struct plugin_list *list)
276{ 262{
277 while (list) { 263 while (list) {
278 trace_seq_printf(s, "%s%s%s", prefix, list->name, suffix); 264 trace_seq_printf(s, "%s%s%s", prefix, list->name, suffix);
@@ -281,11 +267,11 @@ void traceevent_print_plugins(struct trace_seq *s,
281} 267}
282 268
283static void 269static void
284load_plugin(struct pevent *pevent, const char *path, 270load_plugin(struct tep_handle *pevent, const char *path,
285 const char *file, void *data) 271 const char *file, void *data)
286{ 272{
287 struct plugin_list **plugin_list = data; 273 struct plugin_list **plugin_list = data;
288 pevent_plugin_load_func func; 274 tep_plugin_load_func func;
289 struct plugin_list *list; 275 struct plugin_list *list;
290 const char *alias; 276 const char *alias;
291 char *plugin; 277 char *plugin;
@@ -305,14 +291,14 @@ load_plugin(struct pevent *pevent, const char *path,
305 goto out_free; 291 goto out_free;
306 } 292 }
307 293
308 alias = dlsym(handle, PEVENT_PLUGIN_ALIAS_NAME); 294 alias = dlsym(handle, TEP_PLUGIN_ALIAS_NAME);
309 if (!alias) 295 if (!alias)
310 alias = file; 296 alias = file;
311 297
312 func = dlsym(handle, PEVENT_PLUGIN_LOADER_NAME); 298 func = dlsym(handle, TEP_PLUGIN_LOADER_NAME);
313 if (!func) { 299 if (!func) {
314 warning("could not find func '%s' in plugin '%s'\n%s\n", 300 warning("could not find func '%s' in plugin '%s'\n%s\n",
315 PEVENT_PLUGIN_LOADER_NAME, plugin, dlerror()); 301 TEP_PLUGIN_LOADER_NAME, plugin, dlerror());
316 goto out_free; 302 goto out_free;
317 } 303 }
318 304
@@ -336,9 +322,9 @@ load_plugin(struct pevent *pevent, const char *path,
336} 322}
337 323
338static void 324static void
339load_plugins_dir(struct pevent *pevent, const char *suffix, 325load_plugins_dir(struct tep_handle *pevent, const char *suffix,
340 const char *path, 326 const char *path,
341 void (*load_plugin)(struct pevent *pevent, 327 void (*load_plugin)(struct tep_handle *pevent,
342 const char *path, 328 const char *path,
343 const char *name, 329 const char *name,
344 void *data), 330 void *data),
@@ -378,8 +364,8 @@ load_plugins_dir(struct pevent *pevent, const char *suffix,
378} 364}
379 365
380static void 366static void
381load_plugins(struct pevent *pevent, const char *suffix, 367load_plugins(struct tep_handle *pevent, const char *suffix,
382 void (*load_plugin)(struct pevent *pevent, 368 void (*load_plugin)(struct tep_handle *pevent,
383 const char *path, 369 const char *path,
384 const char *name, 370 const char *name,
385 void *data), 371 void *data),
@@ -390,7 +376,7 @@ load_plugins(struct pevent *pevent, const char *suffix,
390 char *envdir; 376 char *envdir;
391 int ret; 377 int ret;
392 378
393 if (pevent->flags & PEVENT_DISABLE_PLUGINS) 379 if (pevent->flags & TEP_DISABLE_PLUGINS)
394 return; 380 return;
395 381
396 /* 382 /*
@@ -398,7 +384,7 @@ load_plugins(struct pevent *pevent, const char *suffix,
398 * check that first. 384 * check that first.
399 */ 385 */
400#ifdef PLUGIN_DIR 386#ifdef PLUGIN_DIR
401 if (!(pevent->flags & PEVENT_DISABLE_SYS_PLUGINS)) 387 if (!(pevent->flags & TEP_DISABLE_SYS_PLUGINS))
402 load_plugins_dir(pevent, suffix, PLUGIN_DIR, 388 load_plugins_dir(pevent, suffix, PLUGIN_DIR,
403 load_plugin, data); 389 load_plugin, data);
404#endif 390#endif
@@ -431,7 +417,7 @@ load_plugins(struct pevent *pevent, const char *suffix,
431} 417}
432 418
433struct plugin_list* 419struct plugin_list*
434traceevent_load_plugins(struct pevent *pevent) 420tep_load_plugins(struct tep_handle *pevent)
435{ 421{
436 struct plugin_list *list = NULL; 422 struct plugin_list *list = NULL;
437 423
@@ -440,15 +426,15 @@ traceevent_load_plugins(struct pevent *pevent)
440} 426}
441 427
442void 428void
443traceevent_unload_plugins(struct plugin_list *plugin_list, struct pevent *pevent) 429tep_unload_plugins(struct plugin_list *plugin_list, struct tep_handle *pevent)
444{ 430{
445 pevent_plugin_unload_func func; 431 tep_plugin_unload_func func;
446 struct plugin_list *list; 432 struct plugin_list *list;
447 433
448 while (plugin_list) { 434 while (plugin_list) {
449 list = plugin_list; 435 list = plugin_list;
450 plugin_list = list->next; 436 plugin_list = list->next;
451 func = dlsym(list->handle, PEVENT_PLUGIN_UNLOADER_NAME); 437 func = dlsym(list->handle, TEP_PLUGIN_UNLOADER_NAME);
452 if (func) 438 if (func)
453 func(pevent); 439 func(pevent);
454 dlclose(list->handle); 440 dlclose(list->handle);
diff --git a/tools/lib/traceevent/event-utils.h b/tools/lib/traceevent/event-utils.h
index d1dc2170e402..0560b96a31d1 100644
--- a/tools/lib/traceevent/event-utils.h
+++ b/tools/lib/traceevent/event-utils.h
@@ -1,21 +1,7 @@
1/* SPDX-License-Identifier: LGPL-2.1 */
1/* 2/*
2 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 * 4 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */ 5 */
20#ifndef __UTIL_H 6#ifndef __UTIL_H
21#define __UTIL_H 7#define __UTIL_H
diff --git a/tools/lib/traceevent/kbuffer-parse.c b/tools/lib/traceevent/kbuffer-parse.c
index ca424b157e46..af2a1f3b7424 100644
--- a/tools/lib/traceevent/kbuffer-parse.c
+++ b/tools/lib/traceevent/kbuffer-parse.c
@@ -1,22 +1,7 @@
1// SPDX-License-Identifier: LGPL-2.1
1/* 2/*
2 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 * 4 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 */ 5 */
21#include <stdio.h> 6#include <stdio.h>
22#include <stdlib.h> 7#include <stdlib.h>
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index 431e8b309f6e..e76154c02ee7 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -1,21 +1,7 @@
1// SPDX-License-Identifier: LGPL-2.1
1/* 2/*
2 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 * 4 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */ 5 */
20#include <stdio.h> 6#include <stdio.h>
21#include <stdlib.h> 7#include <stdlib.h>
@@ -51,8 +37,8 @@ static void show_error(char *error_buf, const char *fmt, ...)
51 int len; 37 int len;
52 int i; 38 int i;
53 39
54 input = pevent_get_input_buf(); 40 input = tep_get_input_buf();
55 index = pevent_get_input_buf_ptr(); 41 index = tep_get_input_buf_ptr();
56 len = input ? strlen(input) : 0; 42 len = input ? strlen(input) : 0;
57 43
58 if (len) { 44 if (len) {
@@ -66,13 +52,13 @@ static void show_error(char *error_buf, const char *fmt, ...)
66 } 52 }
67 53
68 va_start(ap, fmt); 54 va_start(ap, fmt);
69 vsnprintf(error_buf + len, PEVENT_FILTER_ERROR_BUFSZ - len, fmt, ap); 55 vsnprintf(error_buf + len, TEP_FILTER_ERROR_BUFSZ - len, fmt, ap);
70 va_end(ap); 56 va_end(ap);
71} 57}
72 58
73static void free_token(char *token) 59static void free_token(char *token)
74{ 60{
75 pevent_free_token(token); 61 tep_free_token(token);
76} 62}
77 63
78static enum event_type read_token(char **tok) 64static enum event_type read_token(char **tok)
@@ -82,13 +68,13 @@ static enum event_type read_token(char **tok)
82 68
83 do { 69 do {
84 free_token(token); 70 free_token(token);
85 type = pevent_read_token(&token); 71 type = tep_read_token(&token);
86 } while (type == EVENT_NEWLINE || type == EVENT_SPACE); 72 } while (type == EVENT_NEWLINE || type == EVENT_SPACE);
87 73
88 /* If token is = or ! check to see if the next char is ~ */ 74 /* If token is = or ! check to see if the next char is ~ */
89 if (token && 75 if (token &&
90 (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) && 76 (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) &&
91 pevent_peek_char() == '~') { 77 tep_peek_char() == '~') {
92 /* append it */ 78 /* append it */
93 *tok = malloc(3); 79 *tok = malloc(3);
94 if (*tok == NULL) { 80 if (*tok == NULL) {
@@ -98,7 +84,7 @@ static enum event_type read_token(char **tok)
98 sprintf(*tok, "%c%c", *token, '~'); 84 sprintf(*tok, "%c%c", *token, '~');
99 free_token(token); 85 free_token(token);
100 /* Now remove the '~' from the buffer */ 86 /* Now remove the '~' from the buffer */
101 pevent_read_token(&token); 87 tep_read_token(&token);
102 free_token(token); 88 free_token(token);
103 } else 89 } else
104 *tok = token; 90 *tok = token;
@@ -167,7 +153,7 @@ add_filter_type(struct event_filter *filter, int id)
167 153
168 filter_type = &filter->event_filters[i]; 154 filter_type = &filter->event_filters[i];
169 filter_type->event_id = id; 155 filter_type->event_id = id;
170 filter_type->event = pevent_find_event(filter->pevent, id); 156 filter_type->event = tep_find_event(filter->pevent, id);
171 filter_type->filter = NULL; 157 filter_type->filter = NULL;
172 158
173 filter->filters++; 159 filter->filters++;
@@ -176,10 +162,10 @@ add_filter_type(struct event_filter *filter, int id)
176} 162}
177 163
178/** 164/**
179 * pevent_filter_alloc - create a new event filter 165 * tep_filter_alloc - create a new event filter
180 * @pevent: The pevent that this filter is associated with 166 * @pevent: The pevent that this filter is associated with
181 */ 167 */
182struct event_filter *pevent_filter_alloc(struct pevent *pevent) 168struct event_filter *tep_filter_alloc(struct tep_handle *pevent)
183{ 169{
184 struct event_filter *filter; 170 struct event_filter *filter;
185 171
@@ -189,7 +175,7 @@ struct event_filter *pevent_filter_alloc(struct pevent *pevent)
189 175
190 memset(filter, 0, sizeof(*filter)); 176 memset(filter, 0, sizeof(*filter));
191 filter->pevent = pevent; 177 filter->pevent = pevent;
192 pevent_ref(pevent); 178 tep_ref(pevent);
193 179
194 return filter; 180 return filter;
195} 181}
@@ -268,8 +254,8 @@ static int event_match(struct event_format *event,
268 !regexec(ereg, event->name, 0, NULL, 0); 254 !regexec(ereg, event->name, 0, NULL, 0);
269} 255}
270 256
271static enum pevent_errno 257static enum tep_errno
272find_event(struct pevent *pevent, struct event_list **events, 258find_event(struct tep_handle *pevent, struct event_list **events,
273 char *sys_name, char *event_name) 259 char *sys_name, char *event_name)
274{ 260{
275 struct event_format *event; 261 struct event_format *event;
@@ -289,26 +275,26 @@ find_event(struct pevent *pevent, struct event_list **events,
289 275
290 ret = asprintf(&reg, "^%s$", event_name); 276 ret = asprintf(&reg, "^%s$", event_name);
291 if (ret < 0) 277 if (ret < 0)
292 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 278 return TEP_ERRNO__MEM_ALLOC_FAILED;
293 279
294 ret = regcomp(&ereg, reg, REG_ICASE|REG_NOSUB); 280 ret = regcomp(&ereg, reg, REG_ICASE|REG_NOSUB);
295 free(reg); 281 free(reg);
296 282
297 if (ret) 283 if (ret)
298 return PEVENT_ERRNO__INVALID_EVENT_NAME; 284 return TEP_ERRNO__INVALID_EVENT_NAME;
299 285
300 if (sys_name) { 286 if (sys_name) {
301 ret = asprintf(&reg, "^%s$", sys_name); 287 ret = asprintf(&reg, "^%s$", sys_name);
302 if (ret < 0) { 288 if (ret < 0) {
303 regfree(&ereg); 289 regfree(&ereg);
304 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 290 return TEP_ERRNO__MEM_ALLOC_FAILED;
305 } 291 }
306 292
307 ret = regcomp(&sreg, reg, REG_ICASE|REG_NOSUB); 293 ret = regcomp(&sreg, reg, REG_ICASE|REG_NOSUB);
308 free(reg); 294 free(reg);
309 if (ret) { 295 if (ret) {
310 regfree(&ereg); 296 regfree(&ereg);
311 return PEVENT_ERRNO__INVALID_EVENT_NAME; 297 return TEP_ERRNO__INVALID_EVENT_NAME;
312 } 298 }
313 } 299 }
314 300
@@ -328,9 +314,9 @@ find_event(struct pevent *pevent, struct event_list **events,
328 regfree(&sreg); 314 regfree(&sreg);
329 315
330 if (!match) 316 if (!match)
331 return PEVENT_ERRNO__EVENT_NOT_FOUND; 317 return TEP_ERRNO__EVENT_NOT_FOUND;
332 if (fail) 318 if (fail)
333 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 319 return TEP_ERRNO__MEM_ALLOC_FAILED;
334 320
335 return 0; 321 return 0;
336} 322}
@@ -346,7 +332,7 @@ static void free_events(struct event_list *events)
346 } 332 }
347} 333}
348 334
349static enum pevent_errno 335static enum tep_errno
350create_arg_item(struct event_format *event, const char *token, 336create_arg_item(struct event_format *event, const char *token,
351 enum event_type type, struct filter_arg **parg, char *error_str) 337 enum event_type type, struct filter_arg **parg, char *error_str)
352{ 338{
@@ -356,7 +342,7 @@ create_arg_item(struct event_format *event, const char *token,
356 arg = allocate_arg(); 342 arg = allocate_arg();
357 if (arg == NULL) { 343 if (arg == NULL) {
358 show_error(error_str, "failed to allocate filter arg"); 344 show_error(error_str, "failed to allocate filter arg");
359 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 345 return TEP_ERRNO__MEM_ALLOC_FAILED;
360 } 346 }
361 347
362 switch (type) { 348 switch (type) {
@@ -370,7 +356,7 @@ create_arg_item(struct event_format *event, const char *token,
370 if (!arg->value.str) { 356 if (!arg->value.str) {
371 free_arg(arg); 357 free_arg(arg);
372 show_error(error_str, "failed to allocate string filter arg"); 358 show_error(error_str, "failed to allocate string filter arg");
373 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 359 return TEP_ERRNO__MEM_ALLOC_FAILED;
374 } 360 }
375 break; 361 break;
376 case EVENT_ITEM: 362 case EVENT_ITEM:
@@ -382,7 +368,7 @@ create_arg_item(struct event_format *event, const char *token,
382 break; 368 break;
383 } 369 }
384 /* Consider this a field */ 370 /* Consider this a field */
385 field = pevent_find_any_field(event, token); 371 field = tep_find_any_field(event, token);
386 if (!field) { 372 if (!field) {
387 /* If token is 'COMM' or 'CPU' then it is special */ 373 /* If token is 'COMM' or 'CPU' then it is special */
388 if (strcmp(token, COMM) == 0) { 374 if (strcmp(token, COMM) == 0) {
@@ -402,7 +388,7 @@ create_arg_item(struct event_format *event, const char *token,
402 default: 388 default:
403 free_arg(arg); 389 free_arg(arg);
404 show_error(error_str, "expected a value but found %s", token); 390 show_error(error_str, "expected a value but found %s", token);
405 return PEVENT_ERRNO__UNEXPECTED_TYPE; 391 return TEP_ERRNO__UNEXPECTED_TYPE;
406 } 392 }
407 *parg = arg; 393 *parg = arg;
408 return 0; 394 return 0;
@@ -454,7 +440,7 @@ create_arg_cmp(enum filter_cmp_type ctype)
454 return arg; 440 return arg;
455} 441}
456 442
457static enum pevent_errno 443static enum tep_errno
458add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str) 444add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
459{ 445{
460 struct filter_arg *left; 446 struct filter_arg *left;
@@ -487,7 +473,7 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
487 break; 473 break;
488 default: 474 default:
489 show_error(error_str, "Illegal rvalue"); 475 show_error(error_str, "Illegal rvalue");
490 return PEVENT_ERRNO__ILLEGAL_RVALUE; 476 return TEP_ERRNO__ILLEGAL_RVALUE;
491 } 477 }
492 478
493 /* 479 /*
@@ -534,7 +520,7 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
534 if (left->type != FILTER_ARG_FIELD) { 520 if (left->type != FILTER_ARG_FIELD) {
535 show_error(error_str, 521 show_error(error_str,
536 "Illegal lvalue for string comparison"); 522 "Illegal lvalue for string comparison");
537 return PEVENT_ERRNO__ILLEGAL_LVALUE; 523 return TEP_ERRNO__ILLEGAL_LVALUE;
538 } 524 }
539 525
540 /* Make sure this is a valid string compare */ 526 /* Make sure this is a valid string compare */
@@ -553,13 +539,13 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
553 show_error(error_str, 539 show_error(error_str,
554 "RegEx '%s' did not compute", 540 "RegEx '%s' did not compute",
555 str); 541 str);
556 return PEVENT_ERRNO__INVALID_REGEX; 542 return TEP_ERRNO__INVALID_REGEX;
557 } 543 }
558 break; 544 break;
559 default: 545 default:
560 show_error(error_str, 546 show_error(error_str,
561 "Illegal comparison for string"); 547 "Illegal comparison for string");
562 return PEVENT_ERRNO__ILLEGAL_STRING_CMP; 548 return TEP_ERRNO__ILLEGAL_STRING_CMP;
563 } 549 }
564 550
565 op->type = FILTER_ARG_STR; 551 op->type = FILTER_ARG_STR;
@@ -568,7 +554,7 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
568 op->str.val = strdup(str); 554 op->str.val = strdup(str);
569 if (!op->str.val) { 555 if (!op->str.val) {
570 show_error(error_str, "Failed to allocate string filter"); 556 show_error(error_str, "Failed to allocate string filter");
571 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 557 return TEP_ERRNO__MEM_ALLOC_FAILED;
572 } 558 }
573 /* 559 /*
574 * Need a buffer to copy data for tests 560 * Need a buffer to copy data for tests
@@ -576,7 +562,7 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
576 op->str.buffer = malloc(op->str.field->size + 1); 562 op->str.buffer = malloc(op->str.field->size + 1);
577 if (!op->str.buffer) { 563 if (!op->str.buffer) {
578 show_error(error_str, "Failed to allocate string filter"); 564 show_error(error_str, "Failed to allocate string filter");
579 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 565 return TEP_ERRNO__MEM_ALLOC_FAILED;
580 } 566 }
581 /* Null terminate this buffer */ 567 /* Null terminate this buffer */
582 op->str.buffer[op->str.field->size] = 0; 568 op->str.buffer[op->str.field->size] = 0;
@@ -595,7 +581,7 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
595 case FILTER_CMP_NOT_REGEX: 581 case FILTER_CMP_NOT_REGEX:
596 show_error(error_str, 582 show_error(error_str,
597 "Op not allowed with integers"); 583 "Op not allowed with integers");
598 return PEVENT_ERRNO__ILLEGAL_INTEGER_CMP; 584 return TEP_ERRNO__ILLEGAL_INTEGER_CMP;
599 585
600 default: 586 default:
601 break; 587 break;
@@ -616,7 +602,7 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
616 602
617 out_fail: 603 out_fail:
618 show_error(error_str, "Syntax error"); 604 show_error(error_str, "Syntax error");
619 return PEVENT_ERRNO__SYNTAX_ERROR; 605 return TEP_ERRNO__SYNTAX_ERROR;
620} 606}
621 607
622static struct filter_arg * 608static struct filter_arg *
@@ -629,7 +615,7 @@ rotate_op_right(struct filter_arg *a, struct filter_arg *b)
629 return arg; 615 return arg;
630} 616}
631 617
632static enum pevent_errno add_left(struct filter_arg *op, struct filter_arg *arg) 618static enum tep_errno add_left(struct filter_arg *op, struct filter_arg *arg)
633{ 619{
634 switch (op->type) { 620 switch (op->type) {
635 case FILTER_ARG_EXP: 621 case FILTER_ARG_EXP:
@@ -648,11 +634,11 @@ static enum pevent_errno add_left(struct filter_arg *op, struct filter_arg *arg)
648 /* left arg of compares must be a field */ 634 /* left arg of compares must be a field */
649 if (arg->type != FILTER_ARG_FIELD && 635 if (arg->type != FILTER_ARG_FIELD &&
650 arg->type != FILTER_ARG_BOOLEAN) 636 arg->type != FILTER_ARG_BOOLEAN)
651 return PEVENT_ERRNO__INVALID_ARG_TYPE; 637 return TEP_ERRNO__INVALID_ARG_TYPE;
652 op->num.left = arg; 638 op->num.left = arg;
653 break; 639 break;
654 default: 640 default:
655 return PEVENT_ERRNO__INVALID_ARG_TYPE; 641 return TEP_ERRNO__INVALID_ARG_TYPE;
656 } 642 }
657 return 0; 643 return 0;
658} 644}
@@ -765,7 +751,7 @@ enum filter_vals {
765 FILTER_VAL_TRUE, 751 FILTER_VAL_TRUE,
766}; 752};
767 753
768static enum pevent_errno 754static enum tep_errno
769reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child, 755reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child,
770 struct filter_arg *arg, char *error_str) 756 struct filter_arg *arg, char *error_str)
771{ 757{
@@ -775,7 +761,7 @@ reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child,
775 if (parent->type != FILTER_ARG_OP && 761 if (parent->type != FILTER_ARG_OP &&
776 arg->type != FILTER_ARG_OP) { 762 arg->type != FILTER_ARG_OP) {
777 show_error(error_str, "can not reparent other than OP"); 763 show_error(error_str, "can not reparent other than OP");
778 return PEVENT_ERRNO__REPARENT_NOT_OP; 764 return TEP_ERRNO__REPARENT_NOT_OP;
779 } 765 }
780 766
781 /* Get the sibling */ 767 /* Get the sibling */
@@ -787,7 +773,7 @@ reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child,
787 other_child = old_child->op.right; 773 other_child = old_child->op.right;
788 } else { 774 } else {
789 show_error(error_str, "Error in reparent op, find other child"); 775 show_error(error_str, "Error in reparent op, find other child");
790 return PEVENT_ERRNO__REPARENT_FAILED; 776 return TEP_ERRNO__REPARENT_FAILED;
791 } 777 }
792 778
793 /* Detach arg from old_child */ 779 /* Detach arg from old_child */
@@ -808,7 +794,7 @@ reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child,
808 ptr = &parent->op.left; 794 ptr = &parent->op.left;
809 else { 795 else {
810 show_error(error_str, "Error in reparent op"); 796 show_error(error_str, "Error in reparent op");
811 return PEVENT_ERRNO__REPARENT_FAILED; 797 return TEP_ERRNO__REPARENT_FAILED;
812 } 798 }
813 799
814 *ptr = arg; 800 *ptr = arg;
@@ -817,7 +803,7 @@ reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child,
817 return 0; 803 return 0;
818} 804}
819 805
820/* Returns either filter_vals (success) or pevent_errno (failfure) */ 806/* Returns either filter_vals (success) or tep_errno (failfure) */
821static int test_arg(struct filter_arg *parent, struct filter_arg *arg, 807static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
822 char *error_str) 808 char *error_str)
823{ 809{
@@ -912,7 +898,7 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
912 return rval; 898 return rval;
913 default: 899 default:
914 show_error(error_str, "bad arg in filter tree"); 900 show_error(error_str, "bad arg in filter tree");
915 return PEVENT_ERRNO__BAD_FILTER_ARG; 901 return TEP_ERRNO__BAD_FILTER_ARG;
916 } 902 }
917 return FILTER_VAL_NORM; 903 return FILTER_VAL_NORM;
918} 904}
@@ -937,7 +923,7 @@ static int collapse_tree(struct filter_arg *arg,
937 arg->boolean.value = ret == FILTER_VAL_TRUE; 923 arg->boolean.value = ret == FILTER_VAL_TRUE;
938 } else { 924 } else {
939 show_error(error_str, "Failed to allocate filter arg"); 925 show_error(error_str, "Failed to allocate filter arg");
940 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED; 926 ret = TEP_ERRNO__MEM_ALLOC_FAILED;
941 } 927 }
942 break; 928 break;
943 929
@@ -952,7 +938,7 @@ static int collapse_tree(struct filter_arg *arg,
952 return ret; 938 return ret;
953} 939}
954 940
955static enum pevent_errno 941static enum tep_errno
956process_filter(struct event_format *event, struct filter_arg **parg, 942process_filter(struct event_format *event, struct filter_arg **parg,
957 char *error_str, int not) 943 char *error_str, int not)
958{ 944{
@@ -966,7 +952,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
966 enum filter_op_type btype; 952 enum filter_op_type btype;
967 enum filter_exp_type etype; 953 enum filter_exp_type etype;
968 enum filter_cmp_type ctype; 954 enum filter_cmp_type ctype;
969 enum pevent_errno ret; 955 enum tep_errno ret;
970 956
971 *parg = NULL; 957 *parg = NULL;
972 958
@@ -1004,7 +990,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1004 case EVENT_DELIM: 990 case EVENT_DELIM:
1005 if (*token == ',') { 991 if (*token == ',') {
1006 show_error(error_str, "Illegal token ','"); 992 show_error(error_str, "Illegal token ','");
1007 ret = PEVENT_ERRNO__ILLEGAL_TOKEN; 993 ret = TEP_ERRNO__ILLEGAL_TOKEN;
1008 goto fail; 994 goto fail;
1009 } 995 }
1010 996
@@ -1012,22 +998,22 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1012 if (left_item) { 998 if (left_item) {
1013 show_error(error_str, 999 show_error(error_str,
1014 "Open paren can not come after item"); 1000 "Open paren can not come after item");
1015 ret = PEVENT_ERRNO__INVALID_PAREN; 1001 ret = TEP_ERRNO__INVALID_PAREN;
1016 goto fail; 1002 goto fail;
1017 } 1003 }
1018 if (current_exp) { 1004 if (current_exp) {
1019 show_error(error_str, 1005 show_error(error_str,
1020 "Open paren can not come after expression"); 1006 "Open paren can not come after expression");
1021 ret = PEVENT_ERRNO__INVALID_PAREN; 1007 ret = TEP_ERRNO__INVALID_PAREN;
1022 goto fail; 1008 goto fail;
1023 } 1009 }
1024 1010
1025 ret = process_filter(event, &arg, error_str, 0); 1011 ret = process_filter(event, &arg, error_str, 0);
1026 if (ret != PEVENT_ERRNO__UNBALANCED_PAREN) { 1012 if (ret != TEP_ERRNO__UNBALANCED_PAREN) {
1027 if (ret == 0) { 1013 if (ret == 0) {
1028 show_error(error_str, 1014 show_error(error_str,
1029 "Unbalanced number of '('"); 1015 "Unbalanced number of '('");
1030 ret = PEVENT_ERRNO__UNBALANCED_PAREN; 1016 ret = TEP_ERRNO__UNBALANCED_PAREN;
1031 } 1017 }
1032 goto fail; 1018 goto fail;
1033 } 1019 }
@@ -1064,7 +1050,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1064 else 1050 else
1065 *parg = current_exp; 1051 *parg = current_exp;
1066 free(token); 1052 free(token);
1067 return PEVENT_ERRNO__UNBALANCED_PAREN; 1053 return TEP_ERRNO__UNBALANCED_PAREN;
1068 } 1054 }
1069 break; 1055 break;
1070 1056
@@ -1091,7 +1077,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1091 case OP_NONE: 1077 case OP_NONE:
1092 show_error(error_str, 1078 show_error(error_str,
1093 "Unknown op token %s", token); 1079 "Unknown op token %s", token);
1094 ret = PEVENT_ERRNO__UNKNOWN_TOKEN; 1080 ret = TEP_ERRNO__UNKNOWN_TOKEN;
1095 goto fail; 1081 goto fail;
1096 } 1082 }
1097 1083
@@ -1179,11 +1165,11 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1179 1165
1180 fail_alloc: 1166 fail_alloc:
1181 show_error(error_str, "failed to allocate filter arg"); 1167 show_error(error_str, "failed to allocate filter arg");
1182 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED; 1168 ret = TEP_ERRNO__MEM_ALLOC_FAILED;
1183 goto fail; 1169 goto fail;
1184 fail_syntax: 1170 fail_syntax:
1185 show_error(error_str, "Syntax error"); 1171 show_error(error_str, "Syntax error");
1186 ret = PEVENT_ERRNO__SYNTAX_ERROR; 1172 ret = TEP_ERRNO__SYNTAX_ERROR;
1187 fail: 1173 fail:
1188 free_arg(current_op); 1174 free_arg(current_op);
1189 free_arg(current_exp); 1175 free_arg(current_exp);
@@ -1192,13 +1178,13 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1192 return ret; 1178 return ret;
1193} 1179}
1194 1180
1195static enum pevent_errno 1181static enum tep_errno
1196process_event(struct event_format *event, const char *filter_str, 1182process_event(struct event_format *event, const char *filter_str,
1197 struct filter_arg **parg, char *error_str) 1183 struct filter_arg **parg, char *error_str)
1198{ 1184{
1199 int ret; 1185 int ret;
1200 1186
1201 pevent_buffer_init(filter_str, strlen(filter_str)); 1187 tep_buffer_init(filter_str, strlen(filter_str));
1202 1188
1203 ret = process_filter(event, parg, error_str, 0); 1189 ret = process_filter(event, parg, error_str, 0);
1204 if (ret < 0) 1190 if (ret < 0)
@@ -1208,7 +1194,7 @@ process_event(struct event_format *event, const char *filter_str,
1208 if (!*parg) { 1194 if (!*parg) {
1209 *parg = allocate_arg(); 1195 *parg = allocate_arg();
1210 if (*parg == NULL) 1196 if (*parg == NULL)
1211 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 1197 return TEP_ERRNO__MEM_ALLOC_FAILED;
1212 1198
1213 (*parg)->type = FILTER_ARG_BOOLEAN; 1199 (*parg)->type = FILTER_ARG_BOOLEAN;
1214 (*parg)->boolean.value = FILTER_FALSE; 1200 (*parg)->boolean.value = FILTER_FALSE;
@@ -1217,13 +1203,13 @@ process_event(struct event_format *event, const char *filter_str,
1217 return 0; 1203 return 0;
1218} 1204}
1219 1205
1220static enum pevent_errno 1206static enum tep_errno
1221filter_event(struct event_filter *filter, struct event_format *event, 1207filter_event(struct event_filter *filter, struct event_format *event,
1222 const char *filter_str, char *error_str) 1208 const char *filter_str, char *error_str)
1223{ 1209{
1224 struct filter_type *filter_type; 1210 struct filter_type *filter_type;
1225 struct filter_arg *arg; 1211 struct filter_arg *arg;
1226 enum pevent_errno ret; 1212 enum tep_errno ret;
1227 1213
1228 if (filter_str) { 1214 if (filter_str) {
1229 ret = process_event(event, filter_str, &arg, error_str); 1215 ret = process_event(event, filter_str, &arg, error_str);
@@ -1234,7 +1220,7 @@ filter_event(struct event_filter *filter, struct event_format *event,
1234 /* just add a TRUE arg */ 1220 /* just add a TRUE arg */
1235 arg = allocate_arg(); 1221 arg = allocate_arg();
1236 if (arg == NULL) 1222 if (arg == NULL)
1237 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 1223 return TEP_ERRNO__MEM_ALLOC_FAILED;
1238 1224
1239 arg->type = FILTER_ARG_BOOLEAN; 1225 arg->type = FILTER_ARG_BOOLEAN;
1240 arg->boolean.value = FILTER_TRUE; 1226 arg->boolean.value = FILTER_TRUE;
@@ -1242,7 +1228,7 @@ filter_event(struct event_filter *filter, struct event_format *event,
1242 1228
1243 filter_type = add_filter_type(filter, event->id); 1229 filter_type = add_filter_type(filter, event->id);
1244 if (filter_type == NULL) 1230 if (filter_type == NULL)
1245 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 1231 return TEP_ERRNO__MEM_ALLOC_FAILED;
1246 1232
1247 if (filter_type->filter) 1233 if (filter_type->filter)
1248 free_arg(filter_type->filter); 1234 free_arg(filter_type->filter);
@@ -1254,23 +1240,23 @@ filter_event(struct event_filter *filter, struct event_format *event,
1254static void filter_init_error_buf(struct event_filter *filter) 1240static void filter_init_error_buf(struct event_filter *filter)
1255{ 1241{
1256 /* clear buffer to reset show error */ 1242 /* clear buffer to reset show error */
1257 pevent_buffer_init("", 0); 1243 tep_buffer_init("", 0);
1258 filter->error_buffer[0] = '\0'; 1244 filter->error_buffer[0] = '\0';
1259} 1245}
1260 1246
1261/** 1247/**
1262 * pevent_filter_add_filter_str - add a new filter 1248 * tep_filter_add_filter_str - add a new filter
1263 * @filter: the event filter to add to 1249 * @filter: the event filter to add to
1264 * @filter_str: the filter string that contains the filter 1250 * @filter_str: the filter string that contains the filter
1265 * 1251 *
1266 * Returns 0 if the filter was successfully added or a 1252 * Returns 0 if the filter was successfully added or a
1267 * negative error code. Use pevent_filter_strerror() to see 1253 * negative error code. Use tep_filter_strerror() to see
1268 * actual error message in case of error. 1254 * actual error message in case of error.
1269 */ 1255 */
1270enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter, 1256enum tep_errno tep_filter_add_filter_str(struct event_filter *filter,
1271 const char *filter_str) 1257 const char *filter_str)
1272{ 1258{
1273 struct pevent *pevent = filter->pevent; 1259 struct tep_handle *pevent = filter->pevent;
1274 struct event_list *event; 1260 struct event_list *event;
1275 struct event_list *events = NULL; 1261 struct event_list *events = NULL;
1276 const char *filter_start; 1262 const char *filter_start;
@@ -1279,7 +1265,7 @@ enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
1279 char *event_name = NULL; 1265 char *event_name = NULL;
1280 char *sys_name = NULL; 1266 char *sys_name = NULL;
1281 char *sp; 1267 char *sp;
1282 enum pevent_errno rtn = 0; /* PEVENT_ERRNO__SUCCESS */ 1268 enum tep_errno rtn = 0; /* TEP_ERRNO__SUCCESS */
1283 int len; 1269 int len;
1284 int ret; 1270 int ret;
1285 1271
@@ -1305,7 +1291,7 @@ enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
1305 if (this_event == NULL) { 1291 if (this_event == NULL) {
1306 /* This can only happen when events is NULL, but still */ 1292 /* This can only happen when events is NULL, but still */
1307 free_events(events); 1293 free_events(events);
1308 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 1294 return TEP_ERRNO__MEM_ALLOC_FAILED;
1309 } 1295 }
1310 memcpy(this_event, filter_str, len); 1296 memcpy(this_event, filter_str, len);
1311 this_event[len] = 0; 1297 this_event[len] = 0;
@@ -1322,7 +1308,7 @@ enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
1322 /* This can only happen when events is NULL, but still */ 1308 /* This can only happen when events is NULL, but still */
1323 free_events(events); 1309 free_events(events);
1324 free(this_event); 1310 free(this_event);
1325 return PEVENT_ERRNO__FILTER_NOT_FOUND; 1311 return TEP_ERRNO__FILTER_NOT_FOUND;
1326 } 1312 }
1327 1313
1328 /* Find this event */ 1314 /* Find this event */
@@ -1349,7 +1335,7 @@ enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter,
1349 1335
1350 if (ret >= 0 && pevent->test_filters) { 1336 if (ret >= 0 && pevent->test_filters) {
1351 char *test; 1337 char *test;
1352 test = pevent_filter_make_string(filter, event->event->id); 1338 test = tep_filter_make_string(filter, event->event->id);
1353 if (test) { 1339 if (test) {
1354 printf(" '%s: %s'\n", event->event->name, test); 1340 printf(" '%s: %s'\n", event->event->name, test);
1355 free(test); 1341 free(test);
@@ -1371,7 +1357,7 @@ static void free_filter_type(struct filter_type *filter_type)
1371} 1357}
1372 1358
1373/** 1359/**
1374 * pevent_filter_strerror - fill error message in a buffer 1360 * tep_filter_strerror - fill error message in a buffer
1375 * @filter: the event filter contains error 1361 * @filter: the event filter contains error
1376 * @err: the error code 1362 * @err: the error code
1377 * @buf: the buffer to be filled in 1363 * @buf: the buffer to be filled in
@@ -1379,10 +1365,10 @@ static void free_filter_type(struct filter_type *filter_type)
1379 * 1365 *
1380 * Returns 0 if message was filled successfully, -1 if error 1366 * Returns 0 if message was filled successfully, -1 if error
1381 */ 1367 */
1382int pevent_filter_strerror(struct event_filter *filter, enum pevent_errno err, 1368int tep_filter_strerror(struct event_filter *filter, enum tep_errno err,
1383 char *buf, size_t buflen) 1369 char *buf, size_t buflen)
1384{ 1370{
1385 if (err <= __PEVENT_ERRNO__START || err >= __PEVENT_ERRNO__END) 1371 if (err <= __TEP_ERRNO__START || err >= __TEP_ERRNO__END)
1386 return -1; 1372 return -1;
1387 1373
1388 if (strlen(filter->error_buffer) > 0) { 1374 if (strlen(filter->error_buffer) > 0) {
@@ -1393,11 +1379,11 @@ int pevent_filter_strerror(struct event_filter *filter, enum pevent_errno err,
1393 return 0; 1379 return 0;
1394 } 1380 }
1395 1381
1396 return pevent_strerror(filter->pevent, err, buf, buflen); 1382 return tep_strerror(filter->pevent, err, buf, buflen);
1397} 1383}
1398 1384
1399/** 1385/**
1400 * pevent_filter_remove_event - remove a filter for an event 1386 * tep_filter_remove_event - remove a filter for an event
1401 * @filter: the event filter to remove from 1387 * @filter: the event filter to remove from
1402 * @event_id: the event to remove a filter for 1388 * @event_id: the event to remove a filter for
1403 * 1389 *
@@ -1407,8 +1393,8 @@ int pevent_filter_strerror(struct event_filter *filter, enum pevent_errno err,
1407 * Returns 1: if an event was removed 1393 * Returns 1: if an event was removed
1408 * 0: if the event was not found 1394 * 0: if the event was not found
1409 */ 1395 */
1410int pevent_filter_remove_event(struct event_filter *filter, 1396int tep_filter_remove_event(struct event_filter *filter,
1411 int event_id) 1397 int event_id)
1412{ 1398{
1413 struct filter_type *filter_type; 1399 struct filter_type *filter_type;
1414 unsigned long len; 1400 unsigned long len;
@@ -1437,12 +1423,12 @@ int pevent_filter_remove_event(struct event_filter *filter,
1437} 1423}
1438 1424
1439/** 1425/**
1440 * pevent_filter_reset - clear all filters in a filter 1426 * tep_filter_reset - clear all filters in a filter
1441 * @filter: the event filter to reset 1427 * @filter: the event filter to reset
1442 * 1428 *
1443 * Removes all filters from a filter and resets it. 1429 * Removes all filters from a filter and resets it.
1444 */ 1430 */
1445void pevent_filter_reset(struct event_filter *filter) 1431void tep_filter_reset(struct event_filter *filter)
1446{ 1432{
1447 int i; 1433 int i;
1448 1434
@@ -1454,11 +1440,11 @@ void pevent_filter_reset(struct event_filter *filter)
1454 filter->event_filters = NULL; 1440 filter->event_filters = NULL;
1455} 1441}
1456 1442
1457void pevent_filter_free(struct event_filter *filter) 1443void tep_filter_free(struct event_filter *filter)
1458{ 1444{
1459 pevent_unref(filter->pevent); 1445 tep_unref(filter->pevent);
1460 1446
1461 pevent_filter_reset(filter); 1447 tep_filter_reset(filter);
1462 1448
1463 free(filter); 1449 free(filter);
1464} 1450}
@@ -1478,7 +1464,7 @@ static int copy_filter_type(struct event_filter *filter,
1478 /* Can't assume that the pevent's are the same */ 1464 /* Can't assume that the pevent's are the same */
1479 sys = filter_type->event->system; 1465 sys = filter_type->event->system;
1480 name = filter_type->event->name; 1466 name = filter_type->event->name;
1481 event = pevent_find_event_by_name(filter->pevent, sys, name); 1467 event = tep_find_event_by_name(filter->pevent, sys, name);
1482 if (!event) 1468 if (!event)
1483 return -1; 1469 return -1;
1484 1470
@@ -1515,18 +1501,18 @@ static int copy_filter_type(struct event_filter *filter,
1515} 1501}
1516 1502
1517/** 1503/**
1518 * pevent_filter_copy - copy a filter using another filter 1504 * tep_filter_copy - copy a filter using another filter
1519 * @dest - the filter to copy to 1505 * @dest - the filter to copy to
1520 * @source - the filter to copy from 1506 * @source - the filter to copy from
1521 * 1507 *
1522 * Returns 0 on success and -1 if not all filters were copied 1508 * Returns 0 on success and -1 if not all filters were copied
1523 */ 1509 */
1524int pevent_filter_copy(struct event_filter *dest, struct event_filter *source) 1510int tep_filter_copy(struct event_filter *dest, struct event_filter *source)
1525{ 1511{
1526 int ret = 0; 1512 int ret = 0;
1527 int i; 1513 int i;
1528 1514
1529 pevent_filter_reset(dest); 1515 tep_filter_reset(dest);
1530 1516
1531 for (i = 0; i < source->filters; i++) { 1517 for (i = 0; i < source->filters; i++) {
1532 if (copy_filter_type(dest, source, &source->event_filters[i])) 1518 if (copy_filter_type(dest, source, &source->event_filters[i]))
@@ -1537,7 +1523,7 @@ int pevent_filter_copy(struct event_filter *dest, struct event_filter *source)
1537 1523
1538 1524
1539/** 1525/**
1540 * pevent_update_trivial - update the trivial filters with the given filter 1526 * tep_update_trivial - update the trivial filters with the given filter
1541 * @dest - the filter to update 1527 * @dest - the filter to update
1542 * @source - the filter as the source of the update 1528 * @source - the filter as the source of the update
1543 * @type - the type of trivial filter to update. 1529 * @type - the type of trivial filter to update.
@@ -1547,11 +1533,11 @@ int pevent_filter_copy(struct event_filter *dest, struct event_filter *source)
1547 * Returns 0 on success and -1 if there was a problem updating, but 1533 * Returns 0 on success and -1 if there was a problem updating, but
1548 * events may have still been updated on error. 1534 * events may have still been updated on error.
1549 */ 1535 */
1550int pevent_update_trivial(struct event_filter *dest, struct event_filter *source, 1536int tep_update_trivial(struct event_filter *dest, struct event_filter *source,
1551 enum filter_trivial_type type) 1537 enum filter_trivial_type type)
1552{ 1538{
1553 struct pevent *src_pevent; 1539 struct tep_handle *src_pevent;
1554 struct pevent *dest_pevent; 1540 struct tep_handle *dest_pevent;
1555 struct event_format *event; 1541 struct event_format *event;
1556 struct filter_type *filter_type; 1542 struct filter_type *filter_type;
1557 struct filter_arg *arg; 1543 struct filter_arg *arg;
@@ -1578,14 +1564,14 @@ int pevent_update_trivial(struct event_filter *dest, struct event_filter *source
1578 1564
1579 if (src_pevent != dest_pevent) { 1565 if (src_pevent != dest_pevent) {
1580 /* do a look up */ 1566 /* do a look up */
1581 event = pevent_find_event_by_name(src_pevent, 1567 event = tep_find_event_by_name(src_pevent,
1582 event->system, 1568 event->system,
1583 event->name); 1569 event->name);
1584 if (!event) 1570 if (!event)
1585 return -1; 1571 return -1;
1586 } 1572 }
1587 1573
1588 str = pevent_filter_make_string(source, event->id); 1574 str = tep_filter_make_string(source, event->id);
1589 if (!str) 1575 if (!str)
1590 continue; 1576 continue;
1591 1577
@@ -1598,7 +1584,7 @@ int pevent_update_trivial(struct event_filter *dest, struct event_filter *source
1598} 1584}
1599 1585
1600/** 1586/**
1601 * pevent_filter_clear_trivial - clear TRUE and FALSE filters 1587 * tep_filter_clear_trivial - clear TRUE and FALSE filters
1602 * @filter: the filter to remove trivial filters from 1588 * @filter: the filter to remove trivial filters from
1603 * @type: remove only true, false, or both 1589 * @type: remove only true, false, or both
1604 * 1590 *
@@ -1606,8 +1592,8 @@ int pevent_update_trivial(struct event_filter *dest, struct event_filter *source
1606 * 1592 *
1607 * Returns 0 on success and -1 if there was a problem. 1593 * Returns 0 on success and -1 if there was a problem.
1608 */ 1594 */
1609int pevent_filter_clear_trivial(struct event_filter *filter, 1595int tep_filter_clear_trivial(struct event_filter *filter,
1610 enum filter_trivial_type type) 1596 enum filter_trivial_type type)
1611{ 1597{
1612 struct filter_type *filter_type; 1598 struct filter_type *filter_type;
1613 int count = 0; 1599 int count = 0;
@@ -1653,14 +1639,14 @@ int pevent_filter_clear_trivial(struct event_filter *filter,
1653 return 0; 1639 return 0;
1654 1640
1655 for (i = 0; i < count; i++) 1641 for (i = 0; i < count; i++)
1656 pevent_filter_remove_event(filter, ids[i]); 1642 tep_filter_remove_event(filter, ids[i]);
1657 1643
1658 free(ids); 1644 free(ids);
1659 return 0; 1645 return 0;
1660} 1646}
1661 1647
1662/** 1648/**
1663 * pevent_filter_event_has_trivial - return true event contains trivial filter 1649 * tep_filter_event_has_trivial - return true event contains trivial filter
1664 * @filter: the filter with the information 1650 * @filter: the filter with the information
1665 * @event_id: the id of the event to test 1651 * @event_id: the id of the event to test
1666 * @type: trivial type to test for (TRUE, FALSE, EITHER) 1652 * @type: trivial type to test for (TRUE, FALSE, EITHER)
@@ -1668,9 +1654,9 @@ int pevent_filter_clear_trivial(struct event_filter *filter,
1668 * Returns 1 if the event contains a matching trivial type 1654 * Returns 1 if the event contains a matching trivial type
1669 * otherwise 0. 1655 * otherwise 0.
1670 */ 1656 */
1671int pevent_filter_event_has_trivial(struct event_filter *filter, 1657int tep_filter_event_has_trivial(struct event_filter *filter,
1672 int event_id, 1658 int event_id,
1673 enum filter_trivial_type type) 1659 enum filter_trivial_type type)
1674{ 1660{
1675 struct filter_type *filter_type; 1661 struct filter_type *filter_type;
1676 1662
@@ -1697,22 +1683,22 @@ int pevent_filter_event_has_trivial(struct event_filter *filter,
1697} 1683}
1698 1684
1699static int test_filter(struct event_format *event, struct filter_arg *arg, 1685static int test_filter(struct event_format *event, struct filter_arg *arg,
1700 struct pevent_record *record, enum pevent_errno *err); 1686 struct tep_record *record, enum tep_errno *err);
1701 1687
1702static const char * 1688static const char *
1703get_comm(struct event_format *event, struct pevent_record *record) 1689get_comm(struct event_format *event, struct tep_record *record)
1704{ 1690{
1705 const char *comm; 1691 const char *comm;
1706 int pid; 1692 int pid;
1707 1693
1708 pid = pevent_data_pid(event->pevent, record); 1694 pid = tep_data_pid(event->pevent, record);
1709 comm = pevent_data_comm_from_pid(event->pevent, pid); 1695 comm = tep_data_comm_from_pid(event->pevent, pid);
1710 return comm; 1696 return comm;
1711} 1697}
1712 1698
1713static unsigned long long 1699static unsigned long long
1714get_value(struct event_format *event, 1700get_value(struct event_format *event,
1715 struct format_field *field, struct pevent_record *record) 1701 struct format_field *field, struct tep_record *record)
1716{ 1702{
1717 unsigned long long val; 1703 unsigned long long val;
1718 1704
@@ -1728,7 +1714,7 @@ get_value(struct event_format *event,
1728 if (field == &cpu) 1714 if (field == &cpu)
1729 return record->cpu; 1715 return record->cpu;
1730 1716
1731 pevent_read_number_field(field, record->data, &val); 1717 tep_read_number_field(field, record->data, &val);
1732 1718
1733 if (!(field->flags & FIELD_IS_SIGNED)) 1719 if (!(field->flags & FIELD_IS_SIGNED))
1734 return val; 1720 return val;
@@ -1748,11 +1734,11 @@ get_value(struct event_format *event,
1748 1734
1749static unsigned long long 1735static unsigned long long
1750get_arg_value(struct event_format *event, struct filter_arg *arg, 1736get_arg_value(struct event_format *event, struct filter_arg *arg,
1751 struct pevent_record *record, enum pevent_errno *err); 1737 struct tep_record *record, enum tep_errno *err);
1752 1738
1753static unsigned long long 1739static unsigned long long
1754get_exp_value(struct event_format *event, struct filter_arg *arg, 1740get_exp_value(struct event_format *event, struct filter_arg *arg,
1755 struct pevent_record *record, enum pevent_errno *err) 1741 struct tep_record *record, enum tep_errno *err)
1756{ 1742{
1757 unsigned long long lval, rval; 1743 unsigned long long lval, rval;
1758 1744
@@ -1800,14 +1786,14 @@ get_exp_value(struct event_format *event, struct filter_arg *arg,
1800 case FILTER_EXP_NOT: 1786 case FILTER_EXP_NOT:
1801 default: 1787 default:
1802 if (!*err) 1788 if (!*err)
1803 *err = PEVENT_ERRNO__INVALID_EXP_TYPE; 1789 *err = TEP_ERRNO__INVALID_EXP_TYPE;
1804 } 1790 }
1805 return 0; 1791 return 0;
1806} 1792}
1807 1793
1808static unsigned long long 1794static unsigned long long
1809get_arg_value(struct event_format *event, struct filter_arg *arg, 1795get_arg_value(struct event_format *event, struct filter_arg *arg,
1810 struct pevent_record *record, enum pevent_errno *err) 1796 struct tep_record *record, enum tep_errno *err)
1811{ 1797{
1812 switch (arg->type) { 1798 switch (arg->type) {
1813 case FILTER_ARG_FIELD: 1799 case FILTER_ARG_FIELD:
@@ -1816,7 +1802,7 @@ get_arg_value(struct event_format *event, struct filter_arg *arg,
1816 case FILTER_ARG_VALUE: 1802 case FILTER_ARG_VALUE:
1817 if (arg->value.type != FILTER_NUMBER) { 1803 if (arg->value.type != FILTER_NUMBER) {
1818 if (!*err) 1804 if (!*err)
1819 *err = PEVENT_ERRNO__NOT_A_NUMBER; 1805 *err = TEP_ERRNO__NOT_A_NUMBER;
1820 } 1806 }
1821 return arg->value.val; 1807 return arg->value.val;
1822 1808
@@ -1825,13 +1811,13 @@ get_arg_value(struct event_format *event, struct filter_arg *arg,
1825 1811
1826 default: 1812 default:
1827 if (!*err) 1813 if (!*err)
1828 *err = PEVENT_ERRNO__INVALID_ARG_TYPE; 1814 *err = TEP_ERRNO__INVALID_ARG_TYPE;
1829 } 1815 }
1830 return 0; 1816 return 0;
1831} 1817}
1832 1818
1833static int test_num(struct event_format *event, struct filter_arg *arg, 1819static int test_num(struct event_format *event, struct filter_arg *arg,
1834 struct pevent_record *record, enum pevent_errno *err) 1820 struct tep_record *record, enum tep_errno *err)
1835{ 1821{
1836 unsigned long long lval, rval; 1822 unsigned long long lval, rval;
1837 1823
@@ -1866,15 +1852,15 @@ static int test_num(struct event_format *event, struct filter_arg *arg,
1866 1852
1867 default: 1853 default:
1868 if (!*err) 1854 if (!*err)
1869 *err = PEVENT_ERRNO__ILLEGAL_INTEGER_CMP; 1855 *err = TEP_ERRNO__ILLEGAL_INTEGER_CMP;
1870 return 0; 1856 return 0;
1871 } 1857 }
1872} 1858}
1873 1859
1874static const char *get_field_str(struct filter_arg *arg, struct pevent_record *record) 1860static const char *get_field_str(struct filter_arg *arg, struct tep_record *record)
1875{ 1861{
1876 struct event_format *event; 1862 struct event_format *event;
1877 struct pevent *pevent; 1863 struct tep_handle *pevent;
1878 unsigned long long addr; 1864 unsigned long long addr;
1879 const char *val = NULL; 1865 const char *val = NULL;
1880 unsigned int size; 1866 unsigned int size;
@@ -1909,7 +1895,7 @@ static const char *get_field_str(struct filter_arg *arg, struct pevent_record *r
1909 1895
1910 if (arg->str.field->flags & (FIELD_IS_POINTER | FIELD_IS_LONG)) 1896 if (arg->str.field->flags & (FIELD_IS_POINTER | FIELD_IS_LONG))
1911 /* convert to a kernel symbol */ 1897 /* convert to a kernel symbol */
1912 val = pevent_find_function(pevent, addr); 1898 val = tep_find_function(pevent, addr);
1913 1899
1914 if (val == NULL) { 1900 if (val == NULL) {
1915 /* just use the hex of the string name */ 1901 /* just use the hex of the string name */
@@ -1922,7 +1908,7 @@ static const char *get_field_str(struct filter_arg *arg, struct pevent_record *r
1922} 1908}
1923 1909
1924static int test_str(struct event_format *event, struct filter_arg *arg, 1910static int test_str(struct event_format *event, struct filter_arg *arg,
1925 struct pevent_record *record, enum pevent_errno *err) 1911 struct tep_record *record, enum tep_errno *err)
1926{ 1912{
1927 const char *val; 1913 const char *val;
1928 1914
@@ -1947,13 +1933,13 @@ static int test_str(struct event_format *event, struct filter_arg *arg,
1947 1933
1948 default: 1934 default:
1949 if (!*err) 1935 if (!*err)
1950 *err = PEVENT_ERRNO__ILLEGAL_STRING_CMP; 1936 *err = TEP_ERRNO__ILLEGAL_STRING_CMP;
1951 return 0; 1937 return 0;
1952 } 1938 }
1953} 1939}
1954 1940
1955static int test_op(struct event_format *event, struct filter_arg *arg, 1941static int test_op(struct event_format *event, struct filter_arg *arg,
1956 struct pevent_record *record, enum pevent_errno *err) 1942 struct tep_record *record, enum tep_errno *err)
1957{ 1943{
1958 switch (arg->op.type) { 1944 switch (arg->op.type) {
1959 case FILTER_OP_AND: 1945 case FILTER_OP_AND:
@@ -1969,13 +1955,13 @@ static int test_op(struct event_format *event, struct filter_arg *arg,
1969 1955
1970 default: 1956 default:
1971 if (!*err) 1957 if (!*err)
1972 *err = PEVENT_ERRNO__INVALID_OP_TYPE; 1958 *err = TEP_ERRNO__INVALID_OP_TYPE;
1973 return 0; 1959 return 0;
1974 } 1960 }
1975} 1961}
1976 1962
1977static int test_filter(struct event_format *event, struct filter_arg *arg, 1963static int test_filter(struct event_format *event, struct filter_arg *arg,
1978 struct pevent_record *record, enum pevent_errno *err) 1964 struct tep_record *record, enum tep_errno *err)
1979{ 1965{
1980 if (*err) { 1966 if (*err) {
1981 /* 1967 /*
@@ -2009,20 +1995,20 @@ static int test_filter(struct event_format *event, struct filter_arg *arg,
2009 1995
2010 default: 1996 default:
2011 if (!*err) 1997 if (!*err)
2012 *err = PEVENT_ERRNO__INVALID_ARG_TYPE; 1998 *err = TEP_ERRNO__INVALID_ARG_TYPE;
2013 return 0; 1999 return 0;
2014 } 2000 }
2015} 2001}
2016 2002
2017/** 2003/**
2018 * pevent_event_filtered - return true if event has filter 2004 * tep_event_filtered - return true if event has filter
2019 * @filter: filter struct with filter information 2005 * @filter: filter struct with filter information
2020 * @event_id: event id to test if filter exists 2006 * @event_id: event id to test if filter exists
2021 * 2007 *
2022 * Returns 1 if filter found for @event_id 2008 * Returns 1 if filter found for @event_id
2023 * otherwise 0; 2009 * otherwise 0;
2024 */ 2010 */
2025int pevent_event_filtered(struct event_filter *filter, int event_id) 2011int tep_event_filtered(struct event_filter *filter, int event_id)
2026{ 2012{
2027 struct filter_type *filter_type; 2013 struct filter_type *filter_type;
2028 2014
@@ -2035,42 +2021,42 @@ int pevent_event_filtered(struct event_filter *filter, int event_id)
2035} 2021}
2036 2022
2037/** 2023/**
2038 * pevent_filter_match - test if a record matches a filter 2024 * tep_filter_match - test if a record matches a filter
2039 * @filter: filter struct with filter information 2025 * @filter: filter struct with filter information
2040 * @record: the record to test against the filter 2026 * @record: the record to test against the filter
2041 * 2027 *
2042 * Returns: match result or error code (prefixed with PEVENT_ERRNO__) 2028 * Returns: match result or error code (prefixed with TEP_ERRNO__)
2043 * FILTER_MATCH - filter found for event and @record matches 2029 * FILTER_MATCH - filter found for event and @record matches
2044 * FILTER_MISS - filter found for event and @record does not match 2030 * FILTER_MISS - filter found for event and @record does not match
2045 * FILTER_NOT_FOUND - no filter found for @record's event 2031 * FILTER_NOT_FOUND - no filter found for @record's event
2046 * NO_FILTER - if no filters exist 2032 * NO_FILTER - if no filters exist
2047 * otherwise - error occurred during test 2033 * otherwise - error occurred during test
2048 */ 2034 */
2049enum pevent_errno pevent_filter_match(struct event_filter *filter, 2035enum tep_errno tep_filter_match(struct event_filter *filter,
2050 struct pevent_record *record) 2036 struct tep_record *record)
2051{ 2037{
2052 struct pevent *pevent = filter->pevent; 2038 struct tep_handle *pevent = filter->pevent;
2053 struct filter_type *filter_type; 2039 struct filter_type *filter_type;
2054 int event_id; 2040 int event_id;
2055 int ret; 2041 int ret;
2056 enum pevent_errno err = 0; 2042 enum tep_errno err = 0;
2057 2043
2058 filter_init_error_buf(filter); 2044 filter_init_error_buf(filter);
2059 2045
2060 if (!filter->filters) 2046 if (!filter->filters)
2061 return PEVENT_ERRNO__NO_FILTER; 2047 return TEP_ERRNO__NO_FILTER;
2062 2048
2063 event_id = pevent_data_type(pevent, record); 2049 event_id = tep_data_type(pevent, record);
2064 2050
2065 filter_type = find_filter_type(filter, event_id); 2051 filter_type = find_filter_type(filter, event_id);
2066 if (!filter_type) 2052 if (!filter_type)
2067 return PEVENT_ERRNO__FILTER_NOT_FOUND; 2053 return TEP_ERRNO__FILTER_NOT_FOUND;
2068 2054
2069 ret = test_filter(filter_type->event, filter_type->filter, record, &err); 2055 ret = test_filter(filter_type->event, filter_type->filter, record, &err);
2070 if (err) 2056 if (err)
2071 return err; 2057 return err;
2072 2058
2073 return ret ? PEVENT_ERRNO__FILTER_MATCH : PEVENT_ERRNO__FILTER_MISS; 2059 return ret ? TEP_ERRNO__FILTER_MATCH : TEP_ERRNO__FILTER_MISS;
2074} 2060}
2075 2061
2076static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) 2062static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
@@ -2364,7 +2350,7 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg)
2364} 2350}
2365 2351
2366/** 2352/**
2367 * pevent_filter_make_string - return a string showing the filter 2353 * tep_filter_make_string - return a string showing the filter
2368 * @filter: filter struct with filter information 2354 * @filter: filter struct with filter information
2369 * @event_id: the event id to return the filter string with 2355 * @event_id: the event id to return the filter string with
2370 * 2356 *
@@ -2373,7 +2359,7 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg)
2373 * NULL is returned if no filter is found or allocation failed. 2359 * NULL is returned if no filter is found or allocation failed.
2374 */ 2360 */
2375char * 2361char *
2376pevent_filter_make_string(struct event_filter *filter, int event_id) 2362tep_filter_make_string(struct event_filter *filter, int event_id)
2377{ 2363{
2378 struct filter_type *filter_type; 2364 struct filter_type *filter_type;
2379 2365
@@ -2389,7 +2375,7 @@ pevent_filter_make_string(struct event_filter *filter, int event_id)
2389} 2375}
2390 2376
2391/** 2377/**
2392 * pevent_filter_compare - compare two filters and return if they are the same 2378 * tep_filter_compare - compare two filters and return if they are the same
2393 * @filter1: Filter to compare with @filter2 2379 * @filter1: Filter to compare with @filter2
2394 * @filter2: Filter to compare with @filter1 2380 * @filter2: Filter to compare with @filter1
2395 * 2381 *
@@ -2397,7 +2383,7 @@ pevent_filter_make_string(struct event_filter *filter, int event_id)
2397 * 1 if the two filters hold the same content. 2383 * 1 if the two filters hold the same content.
2398 * 0 if they do not. 2384 * 0 if they do not.
2399 */ 2385 */
2400int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2) 2386int tep_filter_compare(struct event_filter *filter1, struct event_filter *filter2)
2401{ 2387{
2402 struct filter_type *filter_type1; 2388 struct filter_type *filter_type1;
2403 struct filter_type *filter_type2; 2389 struct filter_type *filter_type2;
diff --git a/tools/lib/traceevent/parse-utils.c b/tools/lib/traceevent/parse-utils.c
index eda07fa31dca..77e4ec6402dd 100644
--- a/tools/lib/traceevent/parse-utils.c
+++ b/tools/lib/traceevent/parse-utils.c
@@ -1,21 +1,7 @@
1// SPDX-License-Identifier: LGPL-2.1
1/* 2/*
2 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 * 4 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */ 5 */
20#include <stdio.h> 6#include <stdio.h>
21#include <stdlib.h> 7#include <stdlib.h>
diff --git a/tools/lib/traceevent/plugin_cfg80211.c b/tools/lib/traceevent/plugin_cfg80211.c
index 8f8586912da7..a51b366f47da 100644
--- a/tools/lib/traceevent/plugin_cfg80211.c
+++ b/tools/lib/traceevent/plugin_cfg80211.c
@@ -25,19 +25,19 @@ process___le16_to_cpup(struct trace_seq *s, unsigned long long *args)
25 return val ? (long long) le16toh(*val) : 0; 25 return val ? (long long) le16toh(*val) : 0;
26} 26}
27 27
28int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 28int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
29{ 29{
30 pevent_register_print_function(pevent, 30 tep_register_print_function(pevent,
31 process___le16_to_cpup, 31 process___le16_to_cpup,
32 PEVENT_FUNC_ARG_INT, 32 TEP_FUNC_ARG_INT,
33 "__le16_to_cpup", 33 "__le16_to_cpup",
34 PEVENT_FUNC_ARG_PTR, 34 TEP_FUNC_ARG_PTR,
35 PEVENT_FUNC_ARG_VOID); 35 TEP_FUNC_ARG_VOID);
36 return 0; 36 return 0;
37} 37}
38 38
39void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 39void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
40{ 40{
41 pevent_unregister_print_function(pevent, process___le16_to_cpup, 41 tep_unregister_print_function(pevent, process___le16_to_cpup,
42 "__le16_to_cpup"); 42 "__le16_to_cpup");
43} 43}
diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c
index 42dbf73758f3..424747475d37 100644
--- a/tools/lib/traceevent/plugin_function.c
+++ b/tools/lib/traceevent/plugin_function.c
@@ -33,7 +33,7 @@ static int cpus = -1;
33 33
34#define STK_BLK 10 34#define STK_BLK 10
35 35
36struct pevent_plugin_option plugin_options[] = 36struct tep_plugin_option plugin_options[] =
37{ 37{
38 { 38 {
39 .name = "parent", 39 .name = "parent",
@@ -53,8 +53,8 @@ struct pevent_plugin_option plugin_options[] =
53 } 53 }
54}; 54};
55 55
56static struct pevent_plugin_option *ftrace_parent = &plugin_options[0]; 56static struct tep_plugin_option *ftrace_parent = &plugin_options[0];
57static struct pevent_plugin_option *ftrace_indent = &plugin_options[1]; 57static struct tep_plugin_option *ftrace_indent = &plugin_options[1];
58 58
59static void add_child(struct func_stack *stack, const char *child, int pos) 59static void add_child(struct func_stack *stack, const char *child, int pos)
60{ 60{
@@ -122,25 +122,25 @@ static int add_and_get_index(const char *parent, const char *child, int cpu)
122 return 0; 122 return 0;
123} 123}
124 124
125static int function_handler(struct trace_seq *s, struct pevent_record *record, 125static int function_handler(struct trace_seq *s, struct tep_record *record,
126 struct event_format *event, void *context) 126 struct event_format *event, void *context)
127{ 127{
128 struct pevent *pevent = event->pevent; 128 struct tep_handle *pevent = event->pevent;
129 unsigned long long function; 129 unsigned long long function;
130 unsigned long long pfunction; 130 unsigned long long pfunction;
131 const char *func; 131 const char *func;
132 const char *parent; 132 const char *parent;
133 int index = 0; 133 int index = 0;
134 134
135 if (pevent_get_field_val(s, event, "ip", record, &function, 1)) 135 if (tep_get_field_val(s, event, "ip", record, &function, 1))
136 return trace_seq_putc(s, '!'); 136 return trace_seq_putc(s, '!');
137 137
138 func = pevent_find_function(pevent, function); 138 func = tep_find_function(pevent, function);
139 139
140 if (pevent_get_field_val(s, event, "parent_ip", record, &pfunction, 1)) 140 if (tep_get_field_val(s, event, "parent_ip", record, &pfunction, 1))
141 return trace_seq_putc(s, '!'); 141 return trace_seq_putc(s, '!');
142 142
143 parent = pevent_find_function(pevent, pfunction); 143 parent = tep_find_function(pevent, pfunction);
144 144
145 if (parent && ftrace_indent->set) 145 if (parent && ftrace_indent->set)
146 index = add_and_get_index(parent, func, record->cpu); 146 index = add_and_get_index(parent, func, record->cpu);
@@ -163,22 +163,22 @@ static int function_handler(struct trace_seq *s, struct pevent_record *record,
163 return 0; 163 return 0;
164} 164}
165 165
166int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 166int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
167{ 167{
168 pevent_register_event_handler(pevent, -1, "ftrace", "function", 168 tep_register_event_handler(pevent, -1, "ftrace", "function",
169 function_handler, NULL); 169 function_handler, NULL);
170 170
171 traceevent_plugin_add_options("ftrace", plugin_options); 171 tep_plugin_add_options("ftrace", plugin_options);
172 172
173 return 0; 173 return 0;
174} 174}
175 175
176void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 176void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
177{ 177{
178 int i, x; 178 int i, x;
179 179
180 pevent_unregister_event_handler(pevent, -1, "ftrace", "function", 180 tep_unregister_event_handler(pevent, -1, "ftrace", "function",
181 function_handler, NULL); 181 function_handler, NULL);
182 182
183 for (i = 0; i <= cpus; i++) { 183 for (i = 0; i <= cpus; i++) {
184 for (x = 0; x < fstack[i].size && fstack[i].stack[x]; x++) 184 for (x = 0; x < fstack[i].size && fstack[i].stack[x]; x++)
@@ -186,7 +186,7 @@ void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent)
186 free(fstack[i].stack); 186 free(fstack[i].stack);
187 } 187 }
188 188
189 traceevent_plugin_remove_options(plugin_options); 189 tep_plugin_remove_options(plugin_options);
190 190
191 free(fstack); 191 free(fstack);
192 fstack = NULL; 192 fstack = NULL;
diff --git a/tools/lib/traceevent/plugin_hrtimer.c b/tools/lib/traceevent/plugin_hrtimer.c
index 12bf14cc1152..b43bfec565d8 100644
--- a/tools/lib/traceevent/plugin_hrtimer.c
+++ b/tools/lib/traceevent/plugin_hrtimer.c
@@ -25,64 +25,64 @@
25#include "event-parse.h" 25#include "event-parse.h"
26 26
27static int timer_expire_handler(struct trace_seq *s, 27static int timer_expire_handler(struct trace_seq *s,
28 struct pevent_record *record, 28 struct tep_record *record,
29 struct event_format *event, void *context) 29 struct event_format *event, void *context)
30{ 30{
31 trace_seq_printf(s, "hrtimer="); 31 trace_seq_printf(s, "hrtimer=");
32 32
33 if (pevent_print_num_field(s, "0x%llx", event, "timer", 33 if (tep_print_num_field(s, "0x%llx", event, "timer",
34 record, 0) == -1) 34 record, 0) == -1)
35 pevent_print_num_field(s, "0x%llx", event, "hrtimer", 35 tep_print_num_field(s, "0x%llx", event, "hrtimer",
36 record, 1); 36 record, 1);
37 37
38 trace_seq_printf(s, " now="); 38 trace_seq_printf(s, " now=");
39 39
40 pevent_print_num_field(s, "%llu", event, "now", record, 1); 40 tep_print_num_field(s, "%llu", event, "now", record, 1);
41 41
42 pevent_print_func_field(s, " function=%s", event, "function", 42 tep_print_func_field(s, " function=%s", event, "function",
43 record, 0); 43 record, 0);
44 return 0; 44 return 0;
45} 45}
46 46
47static int timer_start_handler(struct trace_seq *s, 47static int timer_start_handler(struct trace_seq *s,
48 struct pevent_record *record, 48 struct tep_record *record,
49 struct event_format *event, void *context) 49 struct event_format *event, void *context)
50{ 50{
51 trace_seq_printf(s, "hrtimer="); 51 trace_seq_printf(s, "hrtimer=");
52 52
53 if (pevent_print_num_field(s, "0x%llx", event, "timer", 53 if (tep_print_num_field(s, "0x%llx", event, "timer",
54 record, 0) == -1) 54 record, 0) == -1)
55 pevent_print_num_field(s, "0x%llx", event, "hrtimer", 55 tep_print_num_field(s, "0x%llx", event, "hrtimer",
56 record, 1); 56 record, 1);
57 57
58 pevent_print_func_field(s, " function=%s", event, "function", 58 tep_print_func_field(s, " function=%s", event, "function",
59 record, 0); 59 record, 0);
60 60
61 trace_seq_printf(s, " expires="); 61 trace_seq_printf(s, " expires=");
62 pevent_print_num_field(s, "%llu", event, "expires", record, 1); 62 tep_print_num_field(s, "%llu", event, "expires", record, 1);
63 63
64 trace_seq_printf(s, " softexpires="); 64 trace_seq_printf(s, " softexpires=");
65 pevent_print_num_field(s, "%llu", event, "softexpires", record, 1); 65 tep_print_num_field(s, "%llu", event, "softexpires", record, 1);
66 return 0; 66 return 0;
67} 67}
68 68
69int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 69int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
70{ 70{
71 pevent_register_event_handler(pevent, -1, 71 tep_register_event_handler(pevent, -1,
72 "timer", "hrtimer_expire_entry", 72 "timer", "hrtimer_expire_entry",
73 timer_expire_handler, NULL); 73 timer_expire_handler, NULL);
74 74
75 pevent_register_event_handler(pevent, -1, "timer", "hrtimer_start", 75 tep_register_event_handler(pevent, -1, "timer", "hrtimer_start",
76 timer_start_handler, NULL); 76 timer_start_handler, NULL);
77 return 0; 77 return 0;
78} 78}
79 79
80void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 80void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
81{ 81{
82 pevent_unregister_event_handler(pevent, -1, 82 tep_unregister_event_handler(pevent, -1,
83 "timer", "hrtimer_expire_entry", 83 "timer", "hrtimer_expire_entry",
84 timer_expire_handler, NULL); 84 timer_expire_handler, NULL);
85 85
86 pevent_unregister_event_handler(pevent, -1, "timer", "hrtimer_start", 86 tep_unregister_event_handler(pevent, -1, "timer", "hrtimer_start",
87 timer_start_handler, NULL); 87 timer_start_handler, NULL);
88} 88}
diff --git a/tools/lib/traceevent/plugin_jbd2.c b/tools/lib/traceevent/plugin_jbd2.c
index 5c23d5bd27ce..45a9acd19640 100644
--- a/tools/lib/traceevent/plugin_jbd2.c
+++ b/tools/lib/traceevent/plugin_jbd2.c
@@ -47,29 +47,29 @@ process_jiffies_to_msecs(struct trace_seq *s, unsigned long long *args)
47 return jiffies; 47 return jiffies;
48} 48}
49 49
50int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 50int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
51{ 51{
52 pevent_register_print_function(pevent, 52 tep_register_print_function(pevent,
53 process_jbd2_dev_to_name, 53 process_jbd2_dev_to_name,
54 PEVENT_FUNC_ARG_STRING, 54 TEP_FUNC_ARG_STRING,
55 "jbd2_dev_to_name", 55 "jbd2_dev_to_name",
56 PEVENT_FUNC_ARG_INT, 56 TEP_FUNC_ARG_INT,
57 PEVENT_FUNC_ARG_VOID); 57 TEP_FUNC_ARG_VOID);
58 58
59 pevent_register_print_function(pevent, 59 tep_register_print_function(pevent,
60 process_jiffies_to_msecs, 60 process_jiffies_to_msecs,
61 PEVENT_FUNC_ARG_LONG, 61 TEP_FUNC_ARG_LONG,
62 "jiffies_to_msecs", 62 "jiffies_to_msecs",
63 PEVENT_FUNC_ARG_LONG, 63 TEP_FUNC_ARG_LONG,
64 PEVENT_FUNC_ARG_VOID); 64 TEP_FUNC_ARG_VOID);
65 return 0; 65 return 0;
66} 66}
67 67
68void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 68void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
69{ 69{
70 pevent_unregister_print_function(pevent, process_jbd2_dev_to_name, 70 tep_unregister_print_function(pevent, process_jbd2_dev_to_name,
71 "jbd2_dev_to_name"); 71 "jbd2_dev_to_name");
72 72
73 pevent_unregister_print_function(pevent, process_jiffies_to_msecs, 73 tep_unregister_print_function(pevent, process_jiffies_to_msecs,
74 "jiffies_to_msecs"); 74 "jiffies_to_msecs");
75} 75}
diff --git a/tools/lib/traceevent/plugin_kmem.c b/tools/lib/traceevent/plugin_kmem.c
index 70650ff48d78..73966b05abce 100644
--- a/tools/lib/traceevent/plugin_kmem.c
+++ b/tools/lib/traceevent/plugin_kmem.c
@@ -23,7 +23,7 @@
23 23
24#include "event-parse.h" 24#include "event-parse.h"
25 25
26static int call_site_handler(struct trace_seq *s, struct pevent_record *record, 26static int call_site_handler(struct trace_seq *s, struct tep_record *record,
27 struct event_format *event, void *context) 27 struct event_format *event, void *context)
28{ 28{
29 struct format_field *field; 29 struct format_field *field;
@@ -31,64 +31,64 @@ static int call_site_handler(struct trace_seq *s, struct pevent_record *record,
31 void *data = record->data; 31 void *data = record->data;
32 const char *func; 32 const char *func;
33 33
34 field = pevent_find_field(event, "call_site"); 34 field = tep_find_field(event, "call_site");
35 if (!field) 35 if (!field)
36 return 1; 36 return 1;
37 37
38 if (pevent_read_number_field(field, data, &val)) 38 if (tep_read_number_field(field, data, &val))
39 return 1; 39 return 1;
40 40
41 func = pevent_find_function(event->pevent, val); 41 func = tep_find_function(event->pevent, val);
42 if (!func) 42 if (!func)
43 return 1; 43 return 1;
44 44
45 addr = pevent_find_function_address(event->pevent, val); 45 addr = tep_find_function_address(event->pevent, val);
46 46
47 trace_seq_printf(s, "(%s+0x%x) ", func, (int)(val - addr)); 47 trace_seq_printf(s, "(%s+0x%x) ", func, (int)(val - addr));
48 return 1; 48 return 1;
49} 49}
50 50
51int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 51int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
52{ 52{
53 pevent_register_event_handler(pevent, -1, "kmem", "kfree", 53 tep_register_event_handler(pevent, -1, "kmem", "kfree",
54 call_site_handler, NULL); 54 call_site_handler, NULL);
55 55
56 pevent_register_event_handler(pevent, -1, "kmem", "kmalloc", 56 tep_register_event_handler(pevent, -1, "kmem", "kmalloc",
57 call_site_handler, NULL); 57 call_site_handler, NULL);
58 58
59 pevent_register_event_handler(pevent, -1, "kmem", "kmalloc_node", 59 tep_register_event_handler(pevent, -1, "kmem", "kmalloc_node",
60 call_site_handler, NULL); 60 call_site_handler, NULL);
61 61
62 pevent_register_event_handler(pevent, -1, "kmem", "kmem_cache_alloc", 62 tep_register_event_handler(pevent, -1, "kmem", "kmem_cache_alloc",
63 call_site_handler, NULL); 63 call_site_handler, NULL);
64 64
65 pevent_register_event_handler(pevent, -1, "kmem", 65 tep_register_event_handler(pevent, -1, "kmem",
66 "kmem_cache_alloc_node", 66 "kmem_cache_alloc_node",
67 call_site_handler, NULL); 67 call_site_handler, NULL);
68 68
69 pevent_register_event_handler(pevent, -1, "kmem", "kmem_cache_free", 69 tep_register_event_handler(pevent, -1, "kmem", "kmem_cache_free",
70 call_site_handler, NULL); 70 call_site_handler, NULL);
71 return 0; 71 return 0;
72} 72}
73 73
74void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 74void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
75{ 75{
76 pevent_unregister_event_handler(pevent, -1, "kmem", "kfree", 76 tep_unregister_event_handler(pevent, -1, "kmem", "kfree",
77 call_site_handler, NULL); 77 call_site_handler, NULL);
78 78
79 pevent_unregister_event_handler(pevent, -1, "kmem", "kmalloc", 79 tep_unregister_event_handler(pevent, -1, "kmem", "kmalloc",
80 call_site_handler, NULL); 80 call_site_handler, NULL);
81 81
82 pevent_unregister_event_handler(pevent, -1, "kmem", "kmalloc_node", 82 tep_unregister_event_handler(pevent, -1, "kmem", "kmalloc_node",
83 call_site_handler, NULL); 83 call_site_handler, NULL);
84 84
85 pevent_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_alloc", 85 tep_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_alloc",
86 call_site_handler, NULL); 86 call_site_handler, NULL);
87 87
88 pevent_unregister_event_handler(pevent, -1, "kmem", 88 tep_unregister_event_handler(pevent, -1, "kmem",
89 "kmem_cache_alloc_node", 89 "kmem_cache_alloc_node",
90 call_site_handler, NULL); 90 call_site_handler, NULL);
91 91
92 pevent_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_free", 92 tep_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_free",
93 call_site_handler, NULL); 93 call_site_handler, NULL);
94} 94}
diff --git a/tools/lib/traceevent/plugin_kvm.c b/tools/lib/traceevent/plugin_kvm.c
index 18536f756577..1d0d15906225 100644
--- a/tools/lib/traceevent/plugin_kvm.c
+++ b/tools/lib/traceevent/plugin_kvm.c
@@ -247,17 +247,17 @@ static const char *find_exit_reason(unsigned isa, int val)
247 return strings[i].str; 247 return strings[i].str;
248} 248}
249 249
250static int print_exit_reason(struct trace_seq *s, struct pevent_record *record, 250static int print_exit_reason(struct trace_seq *s, struct tep_record *record,
251 struct event_format *event, const char *field) 251 struct event_format *event, const char *field)
252{ 252{
253 unsigned long long isa; 253 unsigned long long isa;
254 unsigned long long val; 254 unsigned long long val;
255 const char *reason; 255 const char *reason;
256 256
257 if (pevent_get_field_val(s, event, field, record, &val, 1) < 0) 257 if (tep_get_field_val(s, event, field, record, &val, 1) < 0)
258 return -1; 258 return -1;
259 259
260 if (pevent_get_field_val(s, event, "isa", record, &isa, 0) < 0) 260 if (tep_get_field_val(s, event, "isa", record, &isa, 0) < 0)
261 isa = 1; 261 isa = 1;
262 262
263 reason = find_exit_reason(isa, val); 263 reason = find_exit_reason(isa, val);
@@ -268,7 +268,7 @@ static int print_exit_reason(struct trace_seq *s, struct pevent_record *record,
268 return 0; 268 return 0;
269} 269}
270 270
271static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record, 271static int kvm_exit_handler(struct trace_seq *s, struct tep_record *record,
272 struct event_format *event, void *context) 272 struct event_format *event, void *context)
273{ 273{
274 unsigned long long info1 = 0, info2 = 0; 274 unsigned long long info1 = 0, info2 = 0;
@@ -276,10 +276,10 @@ static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
276 if (print_exit_reason(s, record, event, "exit_reason") < 0) 276 if (print_exit_reason(s, record, event, "exit_reason") < 0)
277 return -1; 277 return -1;
278 278
279 pevent_print_num_field(s, " rip 0x%lx", event, "guest_rip", record, 1); 279 tep_print_num_field(s, " rip 0x%lx", event, "guest_rip", record, 1);
280 280
281 if (pevent_get_field_val(s, event, "info1", record, &info1, 0) >= 0 281 if (tep_get_field_val(s, event, "info1", record, &info1, 0) >= 0
282 && pevent_get_field_val(s, event, "info2", record, &info2, 0) >= 0) 282 && tep_get_field_val(s, event, "info2", record, &info2, 0) >= 0)
283 trace_seq_printf(s, " info %llx %llx", info1, info2); 283 trace_seq_printf(s, " info %llx %llx", info1, info2);
284 284
285 return 0; 285 return 0;
@@ -291,7 +291,7 @@ static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
291#define KVM_EMUL_INSN_F_CS_L (1 << 3) 291#define KVM_EMUL_INSN_F_CS_L (1 << 3)
292 292
293static int kvm_emulate_insn_handler(struct trace_seq *s, 293static int kvm_emulate_insn_handler(struct trace_seq *s,
294 struct pevent_record *record, 294 struct tep_record *record,
295 struct event_format *event, void *context) 295 struct event_format *event, void *context)
296{ 296{
297 unsigned long long rip, csbase, len, flags, failed; 297 unsigned long long rip, csbase, len, flags, failed;
@@ -299,22 +299,22 @@ static int kvm_emulate_insn_handler(struct trace_seq *s,
299 uint8_t *insn; 299 uint8_t *insn;
300 const char *disasm; 300 const char *disasm;
301 301
302 if (pevent_get_field_val(s, event, "rip", record, &rip, 1) < 0) 302 if (tep_get_field_val(s, event, "rip", record, &rip, 1) < 0)
303 return -1; 303 return -1;
304 304
305 if (pevent_get_field_val(s, event, "csbase", record, &csbase, 1) < 0) 305 if (tep_get_field_val(s, event, "csbase", record, &csbase, 1) < 0)
306 return -1; 306 return -1;
307 307
308 if (pevent_get_field_val(s, event, "len", record, &len, 1) < 0) 308 if (tep_get_field_val(s, event, "len", record, &len, 1) < 0)
309 return -1; 309 return -1;
310 310
311 if (pevent_get_field_val(s, event, "flags", record, &flags, 1) < 0) 311 if (tep_get_field_val(s, event, "flags", record, &flags, 1) < 0)
312 return -1; 312 return -1;
313 313
314 if (pevent_get_field_val(s, event, "failed", record, &failed, 1) < 0) 314 if (tep_get_field_val(s, event, "failed", record, &failed, 1) < 0)
315 return -1; 315 return -1;
316 316
317 insn = pevent_get_field_raw(s, event, "insn", record, &llen, 1); 317 insn = tep_get_field_raw(s, event, "insn", record, &llen, 1);
318 if (!insn) 318 if (!insn)
319 return -1; 319 return -1;
320 320
@@ -330,24 +330,24 @@ static int kvm_emulate_insn_handler(struct trace_seq *s,
330} 330}
331 331
332 332
333static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct pevent_record *record, 333static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct tep_record *record,
334 struct event_format *event, void *context) 334 struct event_format *event, void *context)
335{ 335{
336 if (print_exit_reason(s, record, event, "exit_code") < 0) 336 if (print_exit_reason(s, record, event, "exit_code") < 0)
337 return -1; 337 return -1;
338 338
339 pevent_print_num_field(s, " info1 %llx", event, "exit_info1", record, 1); 339 tep_print_num_field(s, " info1 %llx", event, "exit_info1", record, 1);
340 pevent_print_num_field(s, " info2 %llx", event, "exit_info2", record, 1); 340 tep_print_num_field(s, " info2 %llx", event, "exit_info2", record, 1);
341 pevent_print_num_field(s, " int_info %llx", event, "exit_int_info", record, 1); 341 tep_print_num_field(s, " int_info %llx", event, "exit_int_info", record, 1);
342 pevent_print_num_field(s, " int_info_err %llx", event, "exit_int_info_err", record, 1); 342 tep_print_num_field(s, " int_info_err %llx", event, "exit_int_info_err", record, 1);
343 343
344 return 0; 344 return 0;
345} 345}
346 346
347static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *record, 347static int kvm_nested_vmexit_handler(struct trace_seq *s, struct tep_record *record,
348 struct event_format *event, void *context) 348 struct event_format *event, void *context)
349{ 349{
350 pevent_print_num_field(s, "rip %llx ", event, "rip", record, 1); 350 tep_print_num_field(s, "rip %llx ", event, "rip", record, 1);
351 351
352 return kvm_nested_vmexit_inject_handler(s, record, event, context); 352 return kvm_nested_vmexit_inject_handler(s, record, event, context);
353} 353}
@@ -370,7 +370,7 @@ union kvm_mmu_page_role {
370 }; 370 };
371}; 371};
372 372
373static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record, 373static int kvm_mmu_print_role(struct trace_seq *s, struct tep_record *record,
374 struct event_format *event, void *context) 374 struct event_format *event, void *context)
375{ 375{
376 unsigned long long val; 376 unsigned long long val;
@@ -379,7 +379,7 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
379 }; 379 };
380 union kvm_mmu_page_role role; 380 union kvm_mmu_page_role role;
381 381
382 if (pevent_get_field_val(s, event, "role", record, &val, 1) < 0) 382 if (tep_get_field_val(s, event, "role", record, &val, 1) < 0)
383 return -1; 383 return -1;
384 384
385 role.word = (int)val; 385 role.word = (int)val;
@@ -388,8 +388,8 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
388 * We can only use the structure if file is of the same 388 * We can only use the structure if file is of the same
389 * endianess. 389 * endianess.
390 */ 390 */
391 if (pevent_is_file_bigendian(event->pevent) == 391 if (tep_is_file_bigendian(event->pevent) ==
392 pevent_is_host_bigendian(event->pevent)) { 392 tep_is_host_bigendian(event->pevent)) {
393 393
394 trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s", 394 trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s",
395 role.level, 395 role.level,
@@ -406,10 +406,10 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
406 } else 406 } else
407 trace_seq_printf(s, "WORD: %08x", role.word); 407 trace_seq_printf(s, "WORD: %08x", role.word);
408 408
409 pevent_print_num_field(s, " root %u ", event, 409 tep_print_num_field(s, " root %u ", event,
410 "root_count", record, 1); 410 "root_count", record, 1);
411 411
412 if (pevent_get_field_val(s, event, "unsync", record, &val, 1) < 0) 412 if (tep_get_field_val(s, event, "unsync", record, &val, 1) < 0)
413 return -1; 413 return -1;
414 414
415 trace_seq_printf(s, "%s%c", val ? "unsync" : "sync", 0); 415 trace_seq_printf(s, "%s%c", val ? "unsync" : "sync", 0);
@@ -417,17 +417,17 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
417} 417}
418 418
419static int kvm_mmu_get_page_handler(struct trace_seq *s, 419static int kvm_mmu_get_page_handler(struct trace_seq *s,
420 struct pevent_record *record, 420 struct tep_record *record,
421 struct event_format *event, void *context) 421 struct event_format *event, void *context)
422{ 422{
423 unsigned long long val; 423 unsigned long long val;
424 424
425 if (pevent_get_field_val(s, event, "created", record, &val, 1) < 0) 425 if (tep_get_field_val(s, event, "created", record, &val, 1) < 0)
426 return -1; 426 return -1;
427 427
428 trace_seq_printf(s, "%s ", val ? "new" : "existing"); 428 trace_seq_printf(s, "%s ", val ? "new" : "existing");
429 429
430 if (pevent_get_field_val(s, event, "gfn", record, &val, 1) < 0) 430 if (tep_get_field_val(s, event, "gfn", record, &val, 1) < 0)
431 return -1; 431 return -1;
432 432
433 trace_seq_printf(s, "sp gfn %llx ", val); 433 trace_seq_printf(s, "sp gfn %llx ", val);
@@ -444,79 +444,79 @@ process_is_writable_pte(struct trace_seq *s, unsigned long long *args)
444 return pte & PT_WRITABLE_MASK; 444 return pte & PT_WRITABLE_MASK;
445} 445}
446 446
447int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 447int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
448{ 448{
449 init_disassembler(); 449 init_disassembler();
450 450
451 pevent_register_event_handler(pevent, -1, "kvm", "kvm_exit", 451 tep_register_event_handler(pevent, -1, "kvm", "kvm_exit",
452 kvm_exit_handler, NULL); 452 kvm_exit_handler, NULL);
453 453
454 pevent_register_event_handler(pevent, -1, "kvm", "kvm_emulate_insn", 454 tep_register_event_handler(pevent, -1, "kvm", "kvm_emulate_insn",
455 kvm_emulate_insn_handler, NULL); 455 kvm_emulate_insn_handler, NULL);
456 456
457 pevent_register_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit", 457 tep_register_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit",
458 kvm_nested_vmexit_handler, NULL); 458 kvm_nested_vmexit_handler, NULL);
459 459
460 pevent_register_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit_inject", 460 tep_register_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit_inject",
461 kvm_nested_vmexit_inject_handler, NULL); 461 kvm_nested_vmexit_inject_handler, NULL);
462 462
463 pevent_register_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_get_page", 463 tep_register_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_get_page",
464 kvm_mmu_get_page_handler, NULL); 464 kvm_mmu_get_page_handler, NULL);
465 465
466 pevent_register_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_sync_page", 466 tep_register_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_sync_page",
467 kvm_mmu_print_role, NULL); 467 kvm_mmu_print_role, NULL);
468 468
469 pevent_register_event_handler(pevent, -1, 469 tep_register_event_handler(pevent, -1,
470 "kvmmmu", "kvm_mmu_unsync_page", 470 "kvmmmu", "kvm_mmu_unsync_page",
471 kvm_mmu_print_role, NULL); 471 kvm_mmu_print_role, NULL);
472 472
473 pevent_register_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_zap_page", 473 tep_register_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_zap_page",
474 kvm_mmu_print_role, NULL); 474 kvm_mmu_print_role, NULL);
475 475
476 pevent_register_event_handler(pevent, -1, "kvmmmu", 476 tep_register_event_handler(pevent, -1, "kvmmmu",
477 "kvm_mmu_prepare_zap_page", kvm_mmu_print_role, 477 "kvm_mmu_prepare_zap_page", kvm_mmu_print_role,
478 NULL); 478 NULL);
479 479
480 pevent_register_print_function(pevent, 480 tep_register_print_function(pevent,
481 process_is_writable_pte, 481 process_is_writable_pte,
482 PEVENT_FUNC_ARG_INT, 482 TEP_FUNC_ARG_INT,
483 "is_writable_pte", 483 "is_writable_pte",
484 PEVENT_FUNC_ARG_LONG, 484 TEP_FUNC_ARG_LONG,
485 PEVENT_FUNC_ARG_VOID); 485 TEP_FUNC_ARG_VOID);
486 return 0; 486 return 0;
487} 487}
488 488
489void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 489void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
490{ 490{
491 pevent_unregister_event_handler(pevent, -1, "kvm", "kvm_exit", 491 tep_unregister_event_handler(pevent, -1, "kvm", "kvm_exit",
492 kvm_exit_handler, NULL); 492 kvm_exit_handler, NULL);
493 493
494 pevent_unregister_event_handler(pevent, -1, "kvm", "kvm_emulate_insn", 494 tep_unregister_event_handler(pevent, -1, "kvm", "kvm_emulate_insn",
495 kvm_emulate_insn_handler, NULL); 495 kvm_emulate_insn_handler, NULL);
496 496
497 pevent_unregister_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit", 497 tep_unregister_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit",
498 kvm_nested_vmexit_handler, NULL); 498 kvm_nested_vmexit_handler, NULL);
499 499
500 pevent_unregister_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit_inject", 500 tep_unregister_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit_inject",
501 kvm_nested_vmexit_inject_handler, NULL); 501 kvm_nested_vmexit_inject_handler, NULL);
502 502
503 pevent_unregister_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_get_page", 503 tep_unregister_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_get_page",
504 kvm_mmu_get_page_handler, NULL); 504 kvm_mmu_get_page_handler, NULL);
505 505
506 pevent_unregister_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_sync_page", 506 tep_unregister_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_sync_page",
507 kvm_mmu_print_role, NULL); 507 kvm_mmu_print_role, NULL);
508 508
509 pevent_unregister_event_handler(pevent, -1, 509 tep_unregister_event_handler(pevent, -1,
510 "kvmmmu", "kvm_mmu_unsync_page", 510 "kvmmmu", "kvm_mmu_unsync_page",
511 kvm_mmu_print_role, NULL); 511 kvm_mmu_print_role, NULL);
512 512
513 pevent_unregister_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_zap_page", 513 tep_unregister_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_zap_page",
514 kvm_mmu_print_role, NULL); 514 kvm_mmu_print_role, NULL);
515 515
516 pevent_unregister_event_handler(pevent, -1, "kvmmmu", 516 tep_unregister_event_handler(pevent, -1, "kvmmmu",
517 "kvm_mmu_prepare_zap_page", kvm_mmu_print_role, 517 "kvm_mmu_prepare_zap_page", kvm_mmu_print_role,
518 NULL); 518 NULL);
519 519
520 pevent_unregister_print_function(pevent, process_is_writable_pte, 520 tep_unregister_print_function(pevent, process_is_writable_pte,
521 "is_writable_pte"); 521 "is_writable_pte");
522} 522}
diff --git a/tools/lib/traceevent/plugin_mac80211.c b/tools/lib/traceevent/plugin_mac80211.c
index 7e15a0f1c2fd..de50a5316203 100644
--- a/tools/lib/traceevent/plugin_mac80211.c
+++ b/tools/lib/traceevent/plugin_mac80211.c
@@ -28,7 +28,7 @@
28static void print_string(struct trace_seq *s, struct event_format *event, 28static void print_string(struct trace_seq *s, struct event_format *event,
29 const char *name, const void *data) 29 const char *name, const void *data)
30{ 30{
31 struct format_field *f = pevent_find_field(event, name); 31 struct format_field *f = tep_find_field(event, name);
32 int offset; 32 int offset;
33 int length; 33 int length;
34 34
@@ -42,7 +42,7 @@ static void print_string(struct trace_seq *s, struct event_format *event,
42 42
43 if (!strncmp(f->type, "__data_loc", 10)) { 43 if (!strncmp(f->type, "__data_loc", 10)) {
44 unsigned long long v; 44 unsigned long long v;
45 if (pevent_read_number_field(f, data, &v)) { 45 if (tep_read_number_field(f, data, &v)) {
46 trace_seq_printf(s, "invalid_data_loc"); 46 trace_seq_printf(s, "invalid_data_loc");
47 return; 47 return;
48 } 48 }
@@ -53,12 +53,12 @@ static void print_string(struct trace_seq *s, struct event_format *event,
53 trace_seq_printf(s, "%.*s", length, (char *)data + offset); 53 trace_seq_printf(s, "%.*s", length, (char *)data + offset);
54} 54}
55 55
56#define SF(fn) pevent_print_num_field(s, fn ":%d", event, fn, record, 0) 56#define SF(fn) tep_print_num_field(s, fn ":%d", event, fn, record, 0)
57#define SFX(fn) pevent_print_num_field(s, fn ":%#x", event, fn, record, 0) 57#define SFX(fn) tep_print_num_field(s, fn ":%#x", event, fn, record, 0)
58#define SP() trace_seq_putc(s, ' ') 58#define SP() trace_seq_putc(s, ' ')
59 59
60static int drv_bss_info_changed(struct trace_seq *s, 60static int drv_bss_info_changed(struct trace_seq *s,
61 struct pevent_record *record, 61 struct tep_record *record,
62 struct event_format *event, void *context) 62 struct event_format *event, void *context)
63{ 63{
64 void *data = record->data; 64 void *data = record->data;
@@ -66,7 +66,7 @@ static int drv_bss_info_changed(struct trace_seq *s,
66 print_string(s, event, "wiphy_name", data); 66 print_string(s, event, "wiphy_name", data);
67 trace_seq_printf(s, " vif:"); 67 trace_seq_printf(s, " vif:");
68 print_string(s, event, "vif_name", data); 68 print_string(s, event, "vif_name", data);
69 pevent_print_num_field(s, "(%d)", event, "vif_type", record, 1); 69 tep_print_num_field(s, "(%d)", event, "vif_type", record, 1);
70 70
71 trace_seq_printf(s, "\n%*s", INDENT, ""); 71 trace_seq_printf(s, "\n%*s", INDENT, "");
72 SF("assoc"); SP(); 72 SF("assoc"); SP();
@@ -86,17 +86,17 @@ static int drv_bss_info_changed(struct trace_seq *s,
86 return 0; 86 return 0;
87} 87}
88 88
89int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 89int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
90{ 90{
91 pevent_register_event_handler(pevent, -1, "mac80211", 91 tep_register_event_handler(pevent, -1, "mac80211",
92 "drv_bss_info_changed", 92 "drv_bss_info_changed",
93 drv_bss_info_changed, NULL); 93 drv_bss_info_changed, NULL);
94 return 0; 94 return 0;
95} 95}
96 96
97void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 97void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
98{ 98{
99 pevent_unregister_event_handler(pevent, -1, "mac80211", 99 tep_unregister_event_handler(pevent, -1, "mac80211",
100 "drv_bss_info_changed", 100 "drv_bss_info_changed",
101 drv_bss_info_changed, NULL); 101 drv_bss_info_changed, NULL);
102} 102}
diff --git a/tools/lib/traceevent/plugin_sched_switch.c b/tools/lib/traceevent/plugin_sched_switch.c
index ec30c2fcbac0..eecb4bd95c11 100644
--- a/tools/lib/traceevent/plugin_sched_switch.c
+++ b/tools/lib/traceevent/plugin_sched_switch.c
@@ -45,7 +45,7 @@ static void write_state(struct trace_seq *s, int val)
45} 45}
46 46
47static void write_and_save_comm(struct format_field *field, 47static void write_and_save_comm(struct format_field *field,
48 struct pevent_record *record, 48 struct tep_record *record,
49 struct trace_seq *s, int pid) 49 struct trace_seq *s, int pid)
50{ 50{
51 const char *comm; 51 const char *comm;
@@ -61,100 +61,100 @@ static void write_and_save_comm(struct format_field *field,
61 comm = &s->buffer[len]; 61 comm = &s->buffer[len];
62 62
63 /* Help out the comm to ids. This will handle dups */ 63 /* Help out the comm to ids. This will handle dups */
64 pevent_register_comm(field->event->pevent, comm, pid); 64 tep_register_comm(field->event->pevent, comm, pid);
65} 65}
66 66
67static int sched_wakeup_handler(struct trace_seq *s, 67static int sched_wakeup_handler(struct trace_seq *s,
68 struct pevent_record *record, 68 struct tep_record *record,
69 struct event_format *event, void *context) 69 struct event_format *event, void *context)
70{ 70{
71 struct format_field *field; 71 struct format_field *field;
72 unsigned long long val; 72 unsigned long long val;
73 73
74 if (pevent_get_field_val(s, event, "pid", record, &val, 1)) 74 if (tep_get_field_val(s, event, "pid", record, &val, 1))
75 return trace_seq_putc(s, '!'); 75 return trace_seq_putc(s, '!');
76 76
77 field = pevent_find_any_field(event, "comm"); 77 field = tep_find_any_field(event, "comm");
78 if (field) { 78 if (field) {
79 write_and_save_comm(field, record, s, val); 79 write_and_save_comm(field, record, s, val);
80 trace_seq_putc(s, ':'); 80 trace_seq_putc(s, ':');
81 } 81 }
82 trace_seq_printf(s, "%lld", val); 82 trace_seq_printf(s, "%lld", val);
83 83
84 if (pevent_get_field_val(s, event, "prio", record, &val, 0) == 0) 84 if (tep_get_field_val(s, event, "prio", record, &val, 0) == 0)
85 trace_seq_printf(s, " [%lld]", val); 85 trace_seq_printf(s, " [%lld]", val);
86 86
87 if (pevent_get_field_val(s, event, "success", record, &val, 1) == 0) 87 if (tep_get_field_val(s, event, "success", record, &val, 1) == 0)
88 trace_seq_printf(s, " success=%lld", val); 88 trace_seq_printf(s, " success=%lld", val);
89 89
90 if (pevent_get_field_val(s, event, "target_cpu", record, &val, 0) == 0) 90 if (tep_get_field_val(s, event, "target_cpu", record, &val, 0) == 0)
91 trace_seq_printf(s, " CPU:%03llu", val); 91 trace_seq_printf(s, " CPU:%03llu", val);
92 92
93 return 0; 93 return 0;
94} 94}
95 95
96static int sched_switch_handler(struct trace_seq *s, 96static int sched_switch_handler(struct trace_seq *s,
97 struct pevent_record *record, 97 struct tep_record *record,
98 struct event_format *event, void *context) 98 struct event_format *event, void *context)
99{ 99{
100 struct format_field *field; 100 struct format_field *field;
101 unsigned long long val; 101 unsigned long long val;
102 102
103 if (pevent_get_field_val(s, event, "prev_pid", record, &val, 1)) 103 if (tep_get_field_val(s, event, "prev_pid", record, &val, 1))
104 return trace_seq_putc(s, '!'); 104 return trace_seq_putc(s, '!');
105 105
106 field = pevent_find_any_field(event, "prev_comm"); 106 field = tep_find_any_field(event, "prev_comm");
107 if (field) { 107 if (field) {
108 write_and_save_comm(field, record, s, val); 108 write_and_save_comm(field, record, s, val);
109 trace_seq_putc(s, ':'); 109 trace_seq_putc(s, ':');
110 } 110 }
111 trace_seq_printf(s, "%lld ", val); 111 trace_seq_printf(s, "%lld ", val);
112 112
113 if (pevent_get_field_val(s, event, "prev_prio", record, &val, 0) == 0) 113 if (tep_get_field_val(s, event, "prev_prio", record, &val, 0) == 0)
114 trace_seq_printf(s, "[%d] ", (int) val); 114 trace_seq_printf(s, "[%d] ", (int) val);
115 115
116 if (pevent_get_field_val(s, event, "prev_state", record, &val, 0) == 0) 116 if (tep_get_field_val(s, event, "prev_state", record, &val, 0) == 0)
117 write_state(s, val); 117 write_state(s, val);
118 118
119 trace_seq_puts(s, " ==> "); 119 trace_seq_puts(s, " ==> ");
120 120
121 if (pevent_get_field_val(s, event, "next_pid", record, &val, 1)) 121 if (tep_get_field_val(s, event, "next_pid", record, &val, 1))
122 return trace_seq_putc(s, '!'); 122 return trace_seq_putc(s, '!');
123 123
124 field = pevent_find_any_field(event, "next_comm"); 124 field = tep_find_any_field(event, "next_comm");
125 if (field) { 125 if (field) {
126 write_and_save_comm(field, record, s, val); 126 write_and_save_comm(field, record, s, val);
127 trace_seq_putc(s, ':'); 127 trace_seq_putc(s, ':');
128 } 128 }
129 trace_seq_printf(s, "%lld", val); 129 trace_seq_printf(s, "%lld", val);
130 130
131 if (pevent_get_field_val(s, event, "next_prio", record, &val, 0) == 0) 131 if (tep_get_field_val(s, event, "next_prio", record, &val, 0) == 0)
132 trace_seq_printf(s, " [%d]", (int) val); 132 trace_seq_printf(s, " [%d]", (int) val);
133 133
134 return 0; 134 return 0;
135} 135}
136 136
137int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 137int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
138{ 138{
139 pevent_register_event_handler(pevent, -1, "sched", "sched_switch", 139 tep_register_event_handler(pevent, -1, "sched", "sched_switch",
140 sched_switch_handler, NULL); 140 sched_switch_handler, NULL);
141 141
142 pevent_register_event_handler(pevent, -1, "sched", "sched_wakeup", 142 tep_register_event_handler(pevent, -1, "sched", "sched_wakeup",
143 sched_wakeup_handler, NULL); 143 sched_wakeup_handler, NULL);
144 144
145 pevent_register_event_handler(pevent, -1, "sched", "sched_wakeup_new", 145 tep_register_event_handler(pevent, -1, "sched", "sched_wakeup_new",
146 sched_wakeup_handler, NULL); 146 sched_wakeup_handler, NULL);
147 return 0; 147 return 0;
148} 148}
149 149
150void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 150void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
151{ 151{
152 pevent_unregister_event_handler(pevent, -1, "sched", "sched_switch", 152 tep_unregister_event_handler(pevent, -1, "sched", "sched_switch",
153 sched_switch_handler, NULL); 153 sched_switch_handler, NULL);
154 154
155 pevent_unregister_event_handler(pevent, -1, "sched", "sched_wakeup", 155 tep_unregister_event_handler(pevent, -1, "sched", "sched_wakeup",
156 sched_wakeup_handler, NULL); 156 sched_wakeup_handler, NULL);
157 157
158 pevent_unregister_event_handler(pevent, -1, "sched", "sched_wakeup_new", 158 tep_unregister_event_handler(pevent, -1, "sched", "sched_wakeup_new",
159 sched_wakeup_handler, NULL); 159 sched_wakeup_handler, NULL);
160} 160}
diff --git a/tools/lib/traceevent/plugin_scsi.c b/tools/lib/traceevent/plugin_scsi.c
index 5e750af2b461..5ec346f6b842 100644
--- a/tools/lib/traceevent/plugin_scsi.c
+++ b/tools/lib/traceevent/plugin_scsi.c
@@ -413,21 +413,21 @@ unsigned long long process_scsi_trace_parse_cdb(struct trace_seq *s,
413 return 0; 413 return 0;
414} 414}
415 415
416int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 416int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
417{ 417{
418 pevent_register_print_function(pevent, 418 tep_register_print_function(pevent,
419 process_scsi_trace_parse_cdb, 419 process_scsi_trace_parse_cdb,
420 PEVENT_FUNC_ARG_STRING, 420 TEP_FUNC_ARG_STRING,
421 "scsi_trace_parse_cdb", 421 "scsi_trace_parse_cdb",
422 PEVENT_FUNC_ARG_PTR, 422 TEP_FUNC_ARG_PTR,
423 PEVENT_FUNC_ARG_PTR, 423 TEP_FUNC_ARG_PTR,
424 PEVENT_FUNC_ARG_INT, 424 TEP_FUNC_ARG_INT,
425 PEVENT_FUNC_ARG_VOID); 425 TEP_FUNC_ARG_VOID);
426 return 0; 426 return 0;
427} 427}
428 428
429void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 429void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
430{ 430{
431 pevent_unregister_print_function(pevent, process_scsi_trace_parse_cdb, 431 tep_unregister_print_function(pevent, process_scsi_trace_parse_cdb,
432 "scsi_trace_parse_cdb"); 432 "scsi_trace_parse_cdb");
433} 433}
diff --git a/tools/lib/traceevent/plugin_xen.c b/tools/lib/traceevent/plugin_xen.c
index 690173bfa13e..b2acbd6e9c86 100644
--- a/tools/lib/traceevent/plugin_xen.c
+++ b/tools/lib/traceevent/plugin_xen.c
@@ -119,19 +119,19 @@ unsigned long long process_xen_hypercall_name(struct trace_seq *s,
119 return 0; 119 return 0;
120} 120}
121 121
122int PEVENT_PLUGIN_LOADER(struct pevent *pevent) 122int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
123{ 123{
124 pevent_register_print_function(pevent, 124 tep_register_print_function(pevent,
125 process_xen_hypercall_name, 125 process_xen_hypercall_name,
126 PEVENT_FUNC_ARG_STRING, 126 TEP_FUNC_ARG_STRING,
127 "xen_hypercall_name", 127 "xen_hypercall_name",
128 PEVENT_FUNC_ARG_INT, 128 TEP_FUNC_ARG_INT,
129 PEVENT_FUNC_ARG_VOID); 129 TEP_FUNC_ARG_VOID);
130 return 0; 130 return 0;
131} 131}
132 132
133void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent) 133void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
134{ 134{
135 pevent_unregister_print_function(pevent, process_xen_hypercall_name, 135 tep_unregister_print_function(pevent, process_xen_hypercall_name,
136 "xen_hypercall_name"); 136 "xen_hypercall_name");
137} 137}
diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index 292dc9f1d233..e3bac4543d3b 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -1,21 +1,7 @@
1// SPDX-License-Identifier: LGPL-2.1
1/* 2/*
2 * Copyright (C) 2009 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2009 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3 * 4 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */ 5 */
20#include <stdio.h> 6#include <stdio.h>
21#include <stdlib.h> 7#include <stdlib.h>
diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
index 749cc6055dac..e8c972f89357 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -118,6 +118,15 @@ OPTIONS
118--group:: 118--group::
119 Show event group information together 119 Show event group information together
120 120
121--percent-type::
122 Set annotation percent type from following choices:
123 global-period, local-period, global-hits, local-hits
124
125 The local/global keywords set if the percentage is computed
126 in the scope of the function (local) or the whole data (global).
127 The period/hits keywords set the base the percentage is computed
128 on - the samples period or the number of samples (hits).
129
121SEE ALSO 130SEE ALSO
122-------- 131--------
123linkperf:perf-record[1], linkperf:perf-report[1] 132linkperf:perf-record[1], linkperf:perf-report[1]
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 917e36fde6d8..474a4941f65d 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -477,6 +477,15 @@ include::itrace.txt[]
477 Display monitored tasks stored in perf data. Displaying pid/tid/ppid 477 Display monitored tasks stored in perf data. Displaying pid/tid/ppid
478 plus the command string aligned to distinguish parent and child tasks. 478 plus the command string aligned to distinguish parent and child tasks.
479 479
480--percent-type::
481 Set annotation percent type from following choices:
482 global-period, local-period, global-hits, local-hits
483
484 The local/global keywords set if the percentage is computed
485 in the scope of the function (local) or the whole data (global).
486 The period/hits keywords set the base the percentage is computed
487 on - the samples period or the number of samples (hits).
488
480include::callchain-overhead-calculation.txt[] 489include::callchain-overhead-calculation.txt[]
481 490
482SEE ALSO 491SEE ALSO
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 225454416ed5..7902a5681fc8 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -84,10 +84,10 @@ endif # has_clean
84endif # MAKECMDGOALS 84endif # MAKECMDGOALS
85 85
86# 86#
87# The clean target is not really parallel, don't print the jobs info: 87# Explicitly disable parallelism for the clean target.
88# 88#
89clean: 89clean:
90 $(make) 90 $(make) -j1
91 91
92# 92#
93# The build-test target is not really parallel, don't print the jobs info, 93# The build-test target is not really parallel, don't print the jobs info,
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 1120e39c1b00..5ccfce87e693 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -194,6 +194,7 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
194 sper->itr.read_finish = arm_spe_read_finish; 194 sper->itr.read_finish = arm_spe_read_finish;
195 sper->itr.alignment = 0; 195 sper->itr.alignment = 0;
196 196
197 *err = 0;
197 return &sper->itr; 198 return &sper->itr;
198} 199}
199 200
diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index 53d83d7e6a09..20e7d74d86cd 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -141,8 +141,10 @@ void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
141 for (i = 0; i < ntevs; i++) { 141 for (i = 0; i < ntevs; i++) {
142 tev = &pev->tevs[i]; 142 tev = &pev->tevs[i];
143 map__for_each_symbol(map, sym, tmp) { 143 map__for_each_symbol(map, sym, tmp) {
144 if (map->unmap_ip(map, sym->start) == tev->point.address) 144 if (map->unmap_ip(map, sym->start) == tev->point.address) {
145 arch__fix_tev_from_maps(pev, tev, map, sym); 145 arch__fix_tev_from_maps(pev, tev, map, sym);
146 break;
147 }
146 } 148 }
147 } 149 }
148} 150}
diff --git a/tools/perf/arch/s390/util/auxtrace.c b/tools/perf/arch/s390/util/auxtrace.c
index 3afe8256eff2..44c857388897 100644
--- a/tools/perf/arch/s390/util/auxtrace.c
+++ b/tools/perf/arch/s390/util/auxtrace.c
@@ -30,6 +30,7 @@ cpumsf_info_fill(struct auxtrace_record *itr __maybe_unused,
30 struct auxtrace_info_event *auxtrace_info __maybe_unused, 30 struct auxtrace_info_event *auxtrace_info __maybe_unused,
31 size_t priv_size __maybe_unused) 31 size_t priv_size __maybe_unused)
32{ 32{
33 auxtrace_info->type = PERF_AUXTRACE_S390_CPUMSF;
33 return 0; 34 return 0;
34} 35}
35 36
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 1a38e78117ce..8cc6642fce7a 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -19,9 +19,6 @@ systbl := $(sys)/syscalltbl.sh
19_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)') 19_dummy := $(shell [ -d '$(out)' ] || mkdir -p '$(out)')
20 20
21$(header): $(sys)/syscall_64.tbl $(systbl) 21$(header): $(sys)/syscall_64.tbl $(systbl)
22 @(test -d ../../kernel -a -d ../../tools -a -d ../perf && ( \
23 (diff -B arch/x86/entry/syscalls/syscall_64.tbl ../../arch/x86/entry/syscalls/syscall_64.tbl >/dev/null) \
24 || echo "Warning: Kernel ABI header at 'tools/perf/arch/x86/entry/syscalls/syscall_64.tbl' differs from latest version at 'arch/x86/entry/syscalls/syscall_64.tbl'" >&2 )) || true
25 $(Q)$(SHELL) '$(systbl)' $(sys)/syscall_64.tbl 'x86_64' > $@ 22 $(Q)$(SHELL) '$(systbl)' $(sys)/syscall_64.tbl 'x86_64' > $@
26 23
27clean:: 24clean::
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 8180319285af..830481b8db26 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -542,6 +542,10 @@ int cmd_annotate(int argc, const char **argv)
542 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode", 542 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
543 "'always' (default), 'never' or 'auto' only applicable to --stdio mode", 543 "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
544 stdio__config_color, "always"), 544 stdio__config_color, "always"),
545 OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period",
546 "Set percent type local/global-period/hits",
547 annotate_parse_percent_type),
548
545 OPT_END() 549 OPT_END()
546 }; 550 };
547 int ret; 551 int ret;
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 54d3f21b0e62..b63bca4b0c2a 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -729,7 +729,7 @@ static char *compact_gfp_string(unsigned long gfp_flags)
729static int parse_gfp_flags(struct perf_evsel *evsel, struct perf_sample *sample, 729static int parse_gfp_flags(struct perf_evsel *evsel, struct perf_sample *sample,
730 unsigned int gfp_flags) 730 unsigned int gfp_flags)
731{ 731{
732 struct pevent_record record = { 732 struct tep_record record = {
733 .cpu = sample->cpu, 733 .cpu = sample->cpu,
734 .data = sample->raw_data, 734 .data = sample->raw_data,
735 .size = sample->raw_size, 735 .size = sample->raw_size,
@@ -747,7 +747,7 @@ static int parse_gfp_flags(struct perf_evsel *evsel, struct perf_sample *sample,
747 } 747 }
748 748
749 trace_seq_init(&seq); 749 trace_seq_init(&seq);
750 pevent_event_info(&seq, evsel->tp_format, &record); 750 tep_event_info(&seq, evsel->tp_format, &record);
751 751
752 str = strtok_r(seq.buffer, " ", &pos); 752 str = strtok_r(seq.buffer, " ", &pos);
753 while (str) { 753 while (str) {
@@ -1974,7 +1974,7 @@ int cmd_kmem(int argc, const char **argv)
1974 goto out_delete; 1974 goto out_delete;
1975 } 1975 }
1976 1976
1977 kmem_page_size = pevent_get_page_size(evsel->tp_format->pevent); 1977 kmem_page_size = tep_get_page_size(evsel->tp_format->pevent);
1978 symbol_conf.use_callchain = true; 1978 symbol_conf.use_callchain = true;
1979 } 1979 }
1980 1980
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 02f7a3c27761..76e12bcd1765 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1124,6 +1124,9 @@ int cmd_report(int argc, const char **argv)
1124 "Time span of interest (start,stop)"), 1124 "Time span of interest (start,stop)"),
1125 OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name, 1125 OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
1126 "Show inline function"), 1126 "Show inline function"),
1127 OPT_CALLBACK(0, "percent-type", &report.annotation_opts, "local-period",
1128 "Set percent type local/global-period/hits",
1129 annotate_parse_percent_type),
1127 OPT_END() 1130 OPT_END()
1128 }; 1131 };
1129 struct perf_data data = { 1132 struct perf_data data = {
@@ -1366,9 +1369,9 @@ repeat:
1366 } 1369 }
1367 1370
1368 if (session->tevent.pevent && 1371 if (session->tevent.pevent &&
1369 pevent_set_function_resolver(session->tevent.pevent, 1372 tep_set_function_resolver(session->tevent.pevent,
1370 machine__resolve_kernel_addr, 1373 machine__resolve_kernel_addr,
1371 &session->machines.host) < 0) { 1374 &session->machines.host) < 0) {
1372 pr_err("%s: failed to set libtraceevent function resolver\n", 1375 pr_err("%s: failed to set libtraceevent function resolver\n",
1373 __func__); 1376 __func__);
1374 return -1; 1377 return -1;
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 568ddfac3213..ba481d73f910 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3429,9 +3429,9 @@ int cmd_script(int argc, const char **argv)
3429 symbol_conf.use_callchain = false; 3429 symbol_conf.use_callchain = false;
3430 3430
3431 if (session->tevent.pevent && 3431 if (session->tevent.pevent &&
3432 pevent_set_function_resolver(session->tevent.pevent, 3432 tep_set_function_resolver(session->tevent.pevent,
3433 machine__resolve_kernel_addr, 3433 machine__resolve_kernel_addr,
3434 &session->machines.host) < 0) { 3434 &session->machines.host) < 0) {
3435 pr_err("%s: failed to set libtraceevent function resolver\n", __func__); 3435 pr_err("%s: failed to set libtraceevent function resolver\n", __func__);
3436 err = -1; 3436 err = -1;
3437 goto out_delete; 3437 goto out_delete;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 88561eed7950..22ab8e67c760 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -77,7 +77,8 @@ struct trace {
77 struct syscall *table; 77 struct syscall *table;
78 struct { 78 struct {
79 struct perf_evsel *sys_enter, 79 struct perf_evsel *sys_enter,
80 *sys_exit; 80 *sys_exit,
81 *augmented;
81 } events; 82 } events;
82 } syscalls; 83 } syscalls;
83 struct record_opts opts; 84 struct record_opts opts;
@@ -121,7 +122,6 @@ struct trace {
121 bool force; 122 bool force;
122 bool vfs_getname; 123 bool vfs_getname;
123 int trace_pgfaults; 124 int trace_pgfaults;
124 int open_id;
125}; 125};
126 126
127struct tp_field { 127struct tp_field {
@@ -157,13 +157,11 @@ TP_UINT_FIELD__SWAPPED(16);
157TP_UINT_FIELD__SWAPPED(32); 157TP_UINT_FIELD__SWAPPED(32);
158TP_UINT_FIELD__SWAPPED(64); 158TP_UINT_FIELD__SWAPPED(64);
159 159
160static int tp_field__init_uint(struct tp_field *field, 160static int __tp_field__init_uint(struct tp_field *field, int size, int offset, bool needs_swap)
161 struct format_field *format_field,
162 bool needs_swap)
163{ 161{
164 field->offset = format_field->offset; 162 field->offset = offset;
165 163
166 switch (format_field->size) { 164 switch (size) {
167 case 1: 165 case 1:
168 field->integer = tp_field__u8; 166 field->integer = tp_field__u8;
169 break; 167 break;
@@ -183,18 +181,28 @@ static int tp_field__init_uint(struct tp_field *field,
183 return 0; 181 return 0;
184} 182}
185 183
184static int tp_field__init_uint(struct tp_field *field, struct format_field *format_field, bool needs_swap)
185{
186 return __tp_field__init_uint(field, format_field->size, format_field->offset, needs_swap);
187}
188
186static void *tp_field__ptr(struct tp_field *field, struct perf_sample *sample) 189static void *tp_field__ptr(struct tp_field *field, struct perf_sample *sample)
187{ 190{
188 return sample->raw_data + field->offset; 191 return sample->raw_data + field->offset;
189} 192}
190 193
191static int tp_field__init_ptr(struct tp_field *field, struct format_field *format_field) 194static int __tp_field__init_ptr(struct tp_field *field, int offset)
192{ 195{
193 field->offset = format_field->offset; 196 field->offset = offset;
194 field->pointer = tp_field__ptr; 197 field->pointer = tp_field__ptr;
195 return 0; 198 return 0;
196} 199}
197 200
201static int tp_field__init_ptr(struct tp_field *field, struct format_field *format_field)
202{
203 return __tp_field__init_ptr(field, format_field->offset);
204}
205
198struct syscall_tp { 206struct syscall_tp {
199 struct tp_field id; 207 struct tp_field id;
200 union { 208 union {
@@ -240,7 +248,47 @@ static void perf_evsel__delete_priv(struct perf_evsel *evsel)
240 perf_evsel__delete(evsel); 248 perf_evsel__delete(evsel);
241} 249}
242 250
243static int perf_evsel__init_syscall_tp(struct perf_evsel *evsel, void *handler) 251static int perf_evsel__init_syscall_tp(struct perf_evsel *evsel)
252{
253 struct syscall_tp *sc = evsel->priv = malloc(sizeof(struct syscall_tp));
254
255 if (evsel->priv != NULL) {
256 if (perf_evsel__init_tp_uint_field(evsel, &sc->id, "__syscall_nr"))
257 goto out_delete;
258 return 0;
259 }
260
261 return -ENOMEM;
262out_delete:
263 zfree(&evsel->priv);
264 return -ENOENT;
265}
266
267static int perf_evsel__init_augmented_syscall_tp(struct perf_evsel *evsel)
268{
269 struct syscall_tp *sc = evsel->priv = malloc(sizeof(struct syscall_tp));
270
271 if (evsel->priv != NULL) { /* field, sizeof_field, offsetof_field */
272 if (__tp_field__init_uint(&sc->id, sizeof(long), sizeof(long long), evsel->needs_swap))
273 goto out_delete;
274
275 return 0;
276 }
277
278 return -ENOMEM;
279out_delete:
280 zfree(&evsel->priv);
281 return -EINVAL;
282}
283
284static int perf_evsel__init_augmented_syscall_tp_args(struct perf_evsel *evsel)
285{
286 struct syscall_tp *sc = evsel->priv;
287
288 return __tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64));
289}
290
291static int perf_evsel__init_raw_syscall_tp(struct perf_evsel *evsel, void *handler)
244{ 292{
245 evsel->priv = malloc(sizeof(struct syscall_tp)); 293 evsel->priv = malloc(sizeof(struct syscall_tp));
246 if (evsel->priv != NULL) { 294 if (evsel->priv != NULL) {
@@ -258,7 +306,7 @@ out_delete:
258 return -ENOENT; 306 return -ENOENT;
259} 307}
260 308
261static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void *handler) 309static struct perf_evsel *perf_evsel__raw_syscall_newtp(const char *direction, void *handler)
262{ 310{
263 struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction); 311 struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction);
264 312
@@ -269,7 +317,7 @@ static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void
269 if (IS_ERR(evsel)) 317 if (IS_ERR(evsel))
270 return NULL; 318 return NULL;
271 319
272 if (perf_evsel__init_syscall_tp(evsel, handler)) 320 if (perf_evsel__init_raw_syscall_tp(evsel, handler))
273 goto out_delete; 321 goto out_delete;
274 322
275 return evsel; 323 return evsel;
@@ -805,12 +853,17 @@ static struct syscall_fmt *syscall_fmt__find(const char *name)
805 return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp); 853 return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp);
806} 854}
807 855
856/*
857 * is_exit: is this "exit" or "exit_group"?
858 * is_open: is this "open" or "openat"? To associate the fd returned in sys_exit with the pathname in sys_enter.
859 */
808struct syscall { 860struct syscall {
809 struct event_format *tp_format; 861 struct event_format *tp_format;
810 int nr_args; 862 int nr_args;
863 bool is_exit;
864 bool is_open;
811 struct format_field *args; 865 struct format_field *args;
812 const char *name; 866 const char *name;
813 bool is_exit;
814 struct syscall_fmt *fmt; 867 struct syscall_fmt *fmt;
815 struct syscall_arg_fmt *arg_fmt; 868 struct syscall_arg_fmt *arg_fmt;
816}; 869};
@@ -1299,6 +1352,7 @@ static int trace__read_syscall_info(struct trace *trace, int id)
1299 } 1352 }
1300 1353
1301 sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); 1354 sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit");
1355 sc->is_open = !strcmp(name, "open") || !strcmp(name, "openat");
1302 1356
1303 return syscall__set_arg_fmts(sc); 1357 return syscall__set_arg_fmts(sc);
1304} 1358}
@@ -1661,6 +1715,37 @@ out_put:
1661 return err; 1715 return err;
1662} 1716}
1663 1717
1718static int trace__fprintf_sys_enter(struct trace *trace, struct perf_evsel *evsel,
1719 struct perf_sample *sample)
1720{
1721 struct thread_trace *ttrace;
1722 struct thread *thread;
1723 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
1724 struct syscall *sc = trace__syscall_info(trace, evsel, id);
1725 char msg[1024];
1726 void *args;
1727
1728 if (sc == NULL)
1729 return -1;
1730
1731 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
1732 ttrace = thread__trace(thread, trace->output);
1733 /*
1734 * We need to get ttrace just to make sure it is there when syscall__scnprintf_args()
1735 * and the rest of the beautifiers accessing it via struct syscall_arg touches it.
1736 */
1737 if (ttrace == NULL)
1738 goto out_put;
1739
1740 args = perf_evsel__sc_tp_ptr(evsel, args, sample);
1741 syscall__scnprintf_args(sc, msg, sizeof(msg), args, trace, thread);
1742 fprintf(trace->output, "%s", msg);
1743 err = 0;
1744out_put:
1745 thread__put(thread);
1746 return err;
1747}
1748
1664static int trace__resolve_callchain(struct trace *trace, struct perf_evsel *evsel, 1749static int trace__resolve_callchain(struct trace *trace, struct perf_evsel *evsel,
1665 struct perf_sample *sample, 1750 struct perf_sample *sample,
1666 struct callchain_cursor *cursor) 1751 struct callchain_cursor *cursor)
@@ -1722,7 +1807,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
1722 1807
1723 ret = perf_evsel__sc_tp_uint(evsel, ret, sample); 1808 ret = perf_evsel__sc_tp_uint(evsel, ret, sample);
1724 1809
1725 if (id == trace->open_id && ret >= 0 && ttrace->filename.pending_open) { 1810 if (sc->is_open && ret >= 0 && ttrace->filename.pending_open) {
1726 trace__set_fd_pathname(thread, ret, ttrace->filename.name); 1811 trace__set_fd_pathname(thread, ret, ttrace->filename.name);
1727 ttrace->filename.pending_open = false; 1812 ttrace->filename.pending_open = false;
1728 ++trace->stats.vfs_getname; 1813 ++trace->stats.vfs_getname;
@@ -1957,11 +2042,17 @@ static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel,
1957 fprintf(trace->output, "%s:", evsel->name); 2042 fprintf(trace->output, "%s:", evsel->name);
1958 2043
1959 if (perf_evsel__is_bpf_output(evsel)) { 2044 if (perf_evsel__is_bpf_output(evsel)) {
1960 bpf_output__fprintf(trace, sample); 2045 if (evsel == trace->syscalls.events.augmented)
2046 trace__fprintf_sys_enter(trace, evsel, sample);
2047 else
2048 bpf_output__fprintf(trace, sample);
1961 } else if (evsel->tp_format) { 2049 } else if (evsel->tp_format) {
1962 event_format__fprintf(evsel->tp_format, sample->cpu, 2050 if (strncmp(evsel->tp_format->name, "sys_enter_", 10) ||
1963 sample->raw_data, sample->raw_size, 2051 trace__fprintf_sys_enter(trace, evsel, sample)) {
1964 trace->output); 2052 event_format__fprintf(evsel->tp_format, sample->cpu,
2053 sample->raw_data, sample->raw_size,
2054 trace->output);
2055 }
1965 } 2056 }
1966 2057
1967 fprintf(trace->output, "\n"); 2058 fprintf(trace->output, "\n");
@@ -2242,14 +2333,14 @@ static int trace__add_syscall_newtp(struct trace *trace)
2242 struct perf_evlist *evlist = trace->evlist; 2333 struct perf_evlist *evlist = trace->evlist;
2243 struct perf_evsel *sys_enter, *sys_exit; 2334 struct perf_evsel *sys_enter, *sys_exit;
2244 2335
2245 sys_enter = perf_evsel__syscall_newtp("sys_enter", trace__sys_enter); 2336 sys_enter = perf_evsel__raw_syscall_newtp("sys_enter", trace__sys_enter);
2246 if (sys_enter == NULL) 2337 if (sys_enter == NULL)
2247 goto out; 2338 goto out;
2248 2339
2249 if (perf_evsel__init_sc_tp_ptr_field(sys_enter, args)) 2340 if (perf_evsel__init_sc_tp_ptr_field(sys_enter, args))
2250 goto out_delete_sys_enter; 2341 goto out_delete_sys_enter;
2251 2342
2252 sys_exit = perf_evsel__syscall_newtp("sys_exit", trace__sys_exit); 2343 sys_exit = perf_evsel__raw_syscall_newtp("sys_exit", trace__sys_exit);
2253 if (sys_exit == NULL) 2344 if (sys_exit == NULL)
2254 goto out_delete_sys_enter; 2345 goto out_delete_sys_enter;
2255 2346
@@ -2671,7 +2762,7 @@ static int trace__replay(struct trace *trace)
2671 "syscalls:sys_enter"); 2762 "syscalls:sys_enter");
2672 2763
2673 if (evsel && 2764 if (evsel &&
2674 (perf_evsel__init_syscall_tp(evsel, trace__sys_enter) < 0 || 2765 (perf_evsel__init_raw_syscall_tp(evsel, trace__sys_enter) < 0 ||
2675 perf_evsel__init_sc_tp_ptr_field(evsel, args))) { 2766 perf_evsel__init_sc_tp_ptr_field(evsel, args))) {
2676 pr_err("Error during initialize raw_syscalls:sys_enter event\n"); 2767 pr_err("Error during initialize raw_syscalls:sys_enter event\n");
2677 goto out; 2768 goto out;
@@ -2683,7 +2774,7 @@ static int trace__replay(struct trace *trace)
2683 evsel = perf_evlist__find_tracepoint_by_name(session->evlist, 2774 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
2684 "syscalls:sys_exit"); 2775 "syscalls:sys_exit");
2685 if (evsel && 2776 if (evsel &&
2686 (perf_evsel__init_syscall_tp(evsel, trace__sys_exit) < 0 || 2777 (perf_evsel__init_raw_syscall_tp(evsel, trace__sys_exit) < 0 ||
2687 perf_evsel__init_sc_tp_uint_field(evsel, ret))) { 2778 perf_evsel__init_sc_tp_uint_field(evsel, ret))) {
2688 pr_err("Error during initialize raw_syscalls:sys_exit event\n"); 2779 pr_err("Error during initialize raw_syscalls:sys_exit event\n");
2689 goto out; 2780 goto out;
@@ -2923,6 +3014,36 @@ static void evlist__set_evsel_handler(struct perf_evlist *evlist, void *handler)
2923 evsel->handler = handler; 3014 evsel->handler = handler;
2924} 3015}
2925 3016
3017static int evlist__set_syscall_tp_fields(struct perf_evlist *evlist)
3018{
3019 struct perf_evsel *evsel;
3020
3021 evlist__for_each_entry(evlist, evsel) {
3022 if (evsel->priv || !evsel->tp_format)
3023 continue;
3024
3025 if (strcmp(evsel->tp_format->system, "syscalls"))
3026 continue;
3027
3028 if (perf_evsel__init_syscall_tp(evsel))
3029 return -1;
3030
3031 if (!strncmp(evsel->tp_format->name, "sys_enter_", 10)) {
3032 struct syscall_tp *sc = evsel->priv;
3033
3034 if (__tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64)))
3035 return -1;
3036 } else if (!strncmp(evsel->tp_format->name, "sys_exit_", 9)) {
3037 struct syscall_tp *sc = evsel->priv;
3038
3039 if (__tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap))
3040 return -1;
3041 }
3042 }
3043
3044 return 0;
3045}
3046
2926/* 3047/*
2927 * XXX: Hackish, just splitting the combined -e+--event (syscalls 3048 * XXX: Hackish, just splitting the combined -e+--event (syscalls
2928 * (raw_syscalls:{sys_{enter,exit}} + events (tracepoints, HW, SW, etc) to use 3049 * (raw_syscalls:{sys_{enter,exit}} + events (tracepoints, HW, SW, etc) to use
@@ -3123,8 +3244,9 @@ int cmd_trace(int argc, const char **argv)
3123 }; 3244 };
3124 bool __maybe_unused max_stack_user_set = true; 3245 bool __maybe_unused max_stack_user_set = true;
3125 bool mmap_pages_user_set = true; 3246 bool mmap_pages_user_set = true;
3247 struct perf_evsel *evsel;
3126 const char * const trace_subcommands[] = { "record", NULL }; 3248 const char * const trace_subcommands[] = { "record", NULL };
3127 int err; 3249 int err = -1;
3128 char bf[BUFSIZ]; 3250 char bf[BUFSIZ];
3129 3251
3130 signal(SIGSEGV, sighandler_dump_stack); 3252 signal(SIGSEGV, sighandler_dump_stack);
@@ -3147,6 +3269,20 @@ int cmd_trace(int argc, const char **argv)
3147 "cgroup monitoring only available in system-wide mode"); 3269 "cgroup monitoring only available in system-wide mode");
3148 } 3270 }
3149 3271
3272 evsel = bpf__setup_output_event(trace.evlist, "__augmented_syscalls__");
3273 if (IS_ERR(evsel)) {
3274 bpf__strerror_setup_output_event(trace.evlist, PTR_ERR(evsel), bf, sizeof(bf));
3275 pr_err("ERROR: Setup trace syscalls enter failed: %s\n", bf);
3276 goto out;
3277 }
3278
3279 if (evsel) {
3280 if (perf_evsel__init_augmented_syscall_tp(evsel) ||
3281 perf_evsel__init_augmented_syscall_tp_args(evsel))
3282 goto out;
3283 trace.syscalls.events.augmented = evsel;
3284 }
3285
3150 err = bpf__setup_stdout(trace.evlist); 3286 err = bpf__setup_stdout(trace.evlist);
3151 if (err) { 3287 if (err) {
3152 bpf__strerror_setup_stdout(trace.evlist, err, bf, sizeof(bf)); 3288 bpf__strerror_setup_stdout(trace.evlist, err, bf, sizeof(bf));
@@ -3182,8 +3318,13 @@ int cmd_trace(int argc, const char **argv)
3182 symbol_conf.use_callchain = true; 3318 symbol_conf.use_callchain = true;
3183 } 3319 }
3184 3320
3185 if (trace.evlist->nr_entries > 0) 3321 if (trace.evlist->nr_entries > 0) {
3186 evlist__set_evsel_handler(trace.evlist, trace__event_handler); 3322 evlist__set_evsel_handler(trace.evlist, trace__event_handler);
3323 if (evlist__set_syscall_tp_fields(trace.evlist)) {
3324 perror("failed to set syscalls:* tracepoint fields");
3325 goto out;
3326 }
3327 }
3187 3328
3188 if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) 3329 if ((argc >= 1) && (strcmp(argv[0], "record") == 0))
3189 return trace__record(&trace, argc-1, &argv[1]); 3330 return trace__record(&trace, argc-1, &argv[1]);
@@ -3205,8 +3346,6 @@ int cmd_trace(int argc, const char **argv)
3205 } 3346 }
3206 } 3347 }
3207 3348
3208 trace.open_id = syscalltbl__id(trace.sctbl, "open");
3209
3210 err = target__validate(&trace.opts.target); 3349 err = target__validate(&trace.opts.target);
3211 if (err) { 3350 if (err) {
3212 target__strerror(&trace.opts.target, err, bf, sizeof(bf)); 3351 target__strerror(&trace.opts.target, err, bf, sizeof(bf));
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index de28466c0186..466540ee8ea7 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -67,8 +67,12 @@ check_2 () {
67 67
68 cmd="diff $* $file1 $file2 > /dev/null" 68 cmd="diff $* $file1 $file2 > /dev/null"
69 69
70 test -f $file2 && 70 test -f $file2 && {
71 eval $cmd || echo "Warning: Kernel ABI header at 'tools/$file' differs from latest version at '$file'" >&2 71 eval $cmd || {
72 echo "Warning: Kernel ABI header at '$file1' differs from latest version at '$file2'" >&2
73 echo diff -u $file1 $file2
74 }
75 }
72} 76}
73 77
74check () { 78check () {
@@ -76,7 +80,7 @@ check () {
76 80
77 shift 81 shift
78 82
79 check_2 ../$file ../../$file $* 83 check_2 tools/$file $file $*
80} 84}
81 85
82# Check if we have the kernel headers (tools/perf/../../include), else 86# Check if we have the kernel headers (tools/perf/../../include), else
@@ -84,6 +88,8 @@ check () {
84# differences. 88# differences.
85test -d ../../include || exit 0 89test -d ../../include || exit 0
86 90
91cd ../..
92
87# simple diff check 93# simple diff check
88for i in $HEADERS; do 94for i in $HEADERS; do
89 check $i -B 95 check $i -B
@@ -94,3 +100,8 @@ check arch/x86/lib/memcpy_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/ex
94check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"' 100check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"'
95check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common.h>"' 101check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common.h>"'
96check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"' 102check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"'
103
104# diff non-symmetric files
105check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl
106
107cd tools/perf
diff --git a/tools/perf/examples/bpf/augmented_syscalls.c b/tools/perf/examples/bpf/augmented_syscalls.c
new file mode 100644
index 000000000000..69a31386d8cd
--- /dev/null
+++ b/tools/perf/examples/bpf/augmented_syscalls.c
@@ -0,0 +1,55 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Augment the openat syscall with the contents of the filename pointer argument.
4 *
5 * Test it with:
6 *
7 * perf trace -e tools/perf/examples/bpf/augmented_syscalls.c cat /etc/passwd > /dev/null
8 *
9 * It'll catch some openat syscalls related to the dynamic linked and
10 * the last one should be the one for '/etc/passwd'.
11 *
12 * This matches what is marshalled into the raw_syscall:sys_enter payload
13 * expected by the 'perf trace' beautifiers, and can be used by them unmodified,
14 * which will be done as that feature is implemented in the next csets, for now
15 * it will appear in a dump done by the default tracepoint handler in 'perf trace',
16 * that uses bpf_output__fprintf() to just dump those contents, as done with
17 * the bpf-output event associated with the __bpf_output__ map declared in
18 * tools/perf/include/bpf/stdio.h.
19 */
20
21#include <stdio.h>
22
23struct bpf_map SEC("maps") __augmented_syscalls__ = {
24 .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
25 .key_size = sizeof(int),
26 .value_size = sizeof(u32),
27 .max_entries = __NR_CPUS__,
28};
29
30struct syscall_enter_openat_args {
31 unsigned long long common_tp_fields;
32 long syscall_nr;
33 long dfd;
34 char *filename_ptr;
35 long flags;
36 long mode;
37};
38
39struct augmented_enter_openat_args {
40 struct syscall_enter_openat_args args;
41 char filename[64];
42};
43
44int syscall_enter(openat)(struct syscall_enter_openat_args *args)
45{
46 struct augmented_enter_openat_args augmented_args;
47
48 probe_read(&augmented_args.args, sizeof(augmented_args.args), args);
49 probe_read_str(&augmented_args.filename, sizeof(augmented_args.filename), args->filename_ptr);
50 perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU,
51 &augmented_args, sizeof(augmented_args));
52 return 1;
53}
54
55license(GPL);
diff --git a/tools/perf/examples/bpf/hello.c b/tools/perf/examples/bpf/hello.c
new file mode 100644
index 000000000000..cf3c2fdc7f79
--- /dev/null
+++ b/tools/perf/examples/bpf/hello.c
@@ -0,0 +1,9 @@
1#include <stdio.h>
2
3int syscall_enter(openat)(void *args)
4{
5 puts("Hello, world\n");
6 return 0;
7}
8
9license(GPL);
diff --git a/tools/perf/examples/bpf/sys_enter_openat.c b/tools/perf/examples/bpf/sys_enter_openat.c
new file mode 100644
index 000000000000..9cd124b09392
--- /dev/null
+++ b/tools/perf/examples/bpf/sys_enter_openat.c
@@ -0,0 +1,33 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Hook into 'openat' syscall entry tracepoint
4 *
5 * Test it with:
6 *
7 * perf trace -e tools/perf/examples/bpf/sys_enter_openat.c cat /etc/passwd > /dev/null
8 *
9 * It'll catch some openat syscalls related to the dynamic linked and
10 * the last one should be the one for '/etc/passwd'.
11 *
12 * The syscall_enter_openat_args can be used to get the syscall fields
13 * and use them for filtering calls, i.e. use in expressions for
14 * the return value.
15 */
16
17#include <bpf.h>
18
19struct syscall_enter_openat_args {
20 unsigned long long unused;
21 long syscall_nr;
22 long dfd;
23 char *filename_ptr;
24 long flags;
25 long mode;
26};
27
28int syscall_enter(openat)(struct syscall_enter_openat_args *args)
29{
30 return 1;
31}
32
33license(GPL);
diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h
index a63aa6241b7f..47897d65e799 100644
--- a/tools/perf/include/bpf/bpf.h
+++ b/tools/perf/include/bpf/bpf.h
@@ -4,13 +4,33 @@
4 4
5#include <uapi/linux/bpf.h> 5#include <uapi/linux/bpf.h>
6 6
7/*
8 * A helper structure used by eBPF C program to describe map attributes to
9 * elf_bpf loader, taken from tools/testing/selftests/bpf/bpf_helpers.h:
10 */
11struct bpf_map {
12 unsigned int type;
13 unsigned int key_size;
14 unsigned int value_size;
15 unsigned int max_entries;
16 unsigned int map_flags;
17 unsigned int inner_map_idx;
18 unsigned int numa_node;
19};
20
7#define SEC(NAME) __attribute__((section(NAME), used)) 21#define SEC(NAME) __attribute__((section(NAME), used))
8 22
9#define probe(function, vars) \ 23#define probe(function, vars) \
10 SEC(#function "=" #function " " #vars) function 24 SEC(#function "=" #function " " #vars) function
11 25
26#define syscall_enter(name) \
27 SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name
28
12#define license(name) \ 29#define license(name) \
13char _license[] SEC("license") = #name; \ 30char _license[] SEC("license") = #name; \
14int _version SEC("version") = LINUX_VERSION_CODE; 31int _version SEC("version") = LINUX_VERSION_CODE;
15 32
33static int (*probe_read)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read;
34static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read_str;
35
16#endif /* _PERF_BPF_H */ 36#endif /* _PERF_BPF_H */
diff --git a/tools/perf/include/bpf/stdio.h b/tools/perf/include/bpf/stdio.h
new file mode 100644
index 000000000000..2899cb7bfed8
--- /dev/null
+++ b/tools/perf/include/bpf/stdio.h
@@ -0,0 +1,19 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include <bpf.h>
4
5struct bpf_map SEC("maps") __bpf_stdout__ = {
6 .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
7 .key_size = sizeof(int),
8 .value_size = sizeof(u32),
9 .max_entries = __NR_CPUS__,
10};
11
12static int (*perf_event_output)(void *, struct bpf_map *, int, void *, unsigned long) =
13 (void *)BPF_FUNC_perf_event_output;
14
15#define puts(from) \
16 ({ const int __len = sizeof(from); \
17 char __from[__len] = from; \
18 perf_event_output(args, &__bpf_stdout__, BPF_F_CURRENT_CPU, \
19 &__from, __len & (sizeof(from) - 1)); })
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json
new file mode 100644
index 000000000000..bc03c06c3918
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json
@@ -0,0 +1,32 @@
1[
2 {
3 "ArchStdEvent": "L1D_CACHE_RD",
4 },
5 {
6 "ArchStdEvent": "L1D_CACHE_WR",
7 },
8 {
9 "ArchStdEvent": "L1D_CACHE_REFILL_RD",
10 },
11 {
12 "ArchStdEvent": "L1D_CACHE_REFILL_WR",
13 },
14 {
15 "ArchStdEvent": "L1D_TLB_REFILL_RD",
16 },
17 {
18 "ArchStdEvent": "L1D_TLB_REFILL_WR",
19 },
20 {
21 "ArchStdEvent": "L1D_TLB_RD",
22 },
23 {
24 "ArchStdEvent": "L1D_TLB_WR",
25 },
26 {
27 "ArchStdEvent": "BUS_ACCESS_RD",
28 },
29 {
30 "ArchStdEvent": "BUS_ACCESS_WR",
31 }
32]
diff --git a/tools/perf/pmu-events/arch/arm64/mapfile.csv b/tools/perf/pmu-events/arch/arm64/mapfile.csv
index f03e26ecb658..59cd8604b0bd 100644
--- a/tools/perf/pmu-events/arch/arm64/mapfile.csv
+++ b/tools/perf/pmu-events/arch/arm64/mapfile.csv
@@ -16,3 +16,4 @@
160x00000000420f5160,v1,cavium/thunderx2,core 160x00000000420f5160,v1,cavium/thunderx2,core
170x00000000430f0af0,v1,cavium/thunderx2,core 170x00000000430f0af0,v1,cavium/thunderx2,core
180x00000000480fd010,v1,hisilicon/hip08,core 180x00000000480fd010,v1,hisilicon/hip08,core
190x00000000500f0000,v1,ampere/emag,core
diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c
index 47bedf25ba69..96e7fc1ad3f9 100644
--- a/tools/perf/tests/bitmap.c
+++ b/tools/perf/tests/bitmap.c
@@ -16,8 +16,6 @@ static unsigned long *get_bitmap(const char *str, int nbits)
16 bm = bitmap_alloc(nbits); 16 bm = bitmap_alloc(nbits);
17 17
18 if (map && bm) { 18 if (map && bm) {
19 bitmap_zero(bm, nbits);
20
21 for (i = 0; i < map->nr; i++) 19 for (i = 0; i < map->nr; i++)
22 set_bit(map->map[i], bm); 20 set_bit(map->map[i], bm);
23 } 21 }
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 4892bd2dc33e..6b049f3f5cf4 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -232,6 +232,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
232 u64 objdump_addr; 232 u64 objdump_addr;
233 const char *objdump_name; 233 const char *objdump_name;
234 char decomp_name[KMOD_DECOMP_LEN]; 234 char decomp_name[KMOD_DECOMP_LEN];
235 bool decomp = false;
235 int ret; 236 int ret;
236 237
237 pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr); 238 pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
@@ -305,6 +306,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
305 return -1; 306 return -1;
306 } 307 }
307 308
309 decomp = true;
308 objdump_name = decomp_name; 310 objdump_name = decomp_name;
309 } 311 }
310 312
@@ -312,7 +314,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
312 objdump_addr = map__rip_2objdump(al.map, al.addr); 314 objdump_addr = map__rip_2objdump(al.map, al.addr);
313 ret = read_via_objdump(objdump_name, objdump_addr, buf2, len); 315 ret = read_via_objdump(objdump_name, objdump_addr, buf2, len);
314 316
315 if (dso__needs_decompress(al.map->dso)) 317 if (decomp)
316 unlink(objdump_name); 318 unlink(objdump_name);
317 319
318 if (ret > 0) { 320 if (ret > 0) {
diff --git a/tools/perf/tests/kmod-path.c b/tools/perf/tests/kmod-path.c
index 148dd31cc201..0579a70bbbff 100644
--- a/tools/perf/tests/kmod-path.c
+++ b/tools/perf/tests/kmod-path.c
@@ -5,34 +5,28 @@
5#include "dso.h" 5#include "dso.h"
6#include "debug.h" 6#include "debug.h"
7 7
8static int test(const char *path, bool alloc_name, bool alloc_ext, 8static int test(const char *path, bool alloc_name, bool kmod,
9 bool kmod, bool comp, const char *name, const char *ext) 9 int comp, const char *name)
10{ 10{
11 struct kmod_path m; 11 struct kmod_path m;
12 12
13 memset(&m, 0x0, sizeof(m)); 13 memset(&m, 0x0, sizeof(m));
14 14
15 TEST_ASSERT_VAL("kmod_path__parse", 15 TEST_ASSERT_VAL("kmod_path__parse",
16 !__kmod_path__parse(&m, path, alloc_name, alloc_ext)); 16 !__kmod_path__parse(&m, path, alloc_name));
17 17
18 pr_debug("%s - alloc name %d, alloc ext %d, kmod %d, comp %d, name '%s', ext '%s'\n", 18 pr_debug("%s - alloc name %d, kmod %d, comp %d, name '%s'\n",
19 path, alloc_name, alloc_ext, m.kmod, m.comp, m.name, m.ext); 19 path, alloc_name, m.kmod, m.comp, m.name);
20 20
21 TEST_ASSERT_VAL("wrong kmod", m.kmod == kmod); 21 TEST_ASSERT_VAL("wrong kmod", m.kmod == kmod);
22 TEST_ASSERT_VAL("wrong comp", m.comp == comp); 22 TEST_ASSERT_VAL("wrong comp", m.comp == comp);
23 23
24 if (ext)
25 TEST_ASSERT_VAL("wrong ext", m.ext && !strcmp(ext, m.ext));
26 else
27 TEST_ASSERT_VAL("wrong ext", !m.ext);
28
29 if (name) 24 if (name)
30 TEST_ASSERT_VAL("wrong name", m.name && !strcmp(name, m.name)); 25 TEST_ASSERT_VAL("wrong name", m.name && !strcmp(name, m.name));
31 else 26 else
32 TEST_ASSERT_VAL("wrong name", !m.name); 27 TEST_ASSERT_VAL("wrong name", !m.name);
33 28
34 free(m.name); 29 free(m.name);
35 free(m.ext);
36 return 0; 30 return 0;
37} 31}
38 32
@@ -45,118 +39,118 @@ static int test_is_kernel_module(const char *path, int cpumode, bool expect)
45 return 0; 39 return 0;
46} 40}
47 41
48#define T(path, an, ae, k, c, n, e) \ 42#define T(path, an, k, c, n) \
49 TEST_ASSERT_VAL("failed", !test(path, an, ae, k, c, n, e)) 43 TEST_ASSERT_VAL("failed", !test(path, an, k, c, n))
50 44
51#define M(path, c, e) \ 45#define M(path, c, e) \
52 TEST_ASSERT_VAL("failed", !test_is_kernel_module(path, c, e)) 46 TEST_ASSERT_VAL("failed", !test_is_kernel_module(path, c, e))
53 47
54int test__kmod_path__parse(struct test *t __maybe_unused, int subtest __maybe_unused) 48int test__kmod_path__parse(struct test *t __maybe_unused, int subtest __maybe_unused)
55{ 49{
56 /* path alloc_name alloc_ext kmod comp name ext */ 50 /* path alloc_name kmod comp name */
57 T("/xxxx/xxxx/x-x.ko", true , true , true, false, "[x_x]", NULL); 51 T("/xxxx/xxxx/x-x.ko", true , true, 0 , "[x_x]");
58 T("/xxxx/xxxx/x-x.ko", false , true , true, false, NULL , NULL); 52 T("/xxxx/xxxx/x-x.ko", false , true, 0 , NULL );
59 T("/xxxx/xxxx/x-x.ko", true , false , true, false, "[x_x]", NULL); 53 T("/xxxx/xxxx/x-x.ko", true , true, 0 , "[x_x]");
60 T("/xxxx/xxxx/x-x.ko", false , false , true, false, NULL , NULL); 54 T("/xxxx/xxxx/x-x.ko", false , true, 0 , NULL );
61 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); 55 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
62 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_KERNEL, true); 56 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_KERNEL, true);
63 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_USER, false); 57 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_USER, false);
64 58
65#ifdef HAVE_ZLIB_SUPPORT 59#ifdef HAVE_ZLIB_SUPPORT
66 /* path alloc_name alloc_ext kmod comp name ext */ 60 /* path alloc_name kmod comp name */
67 T("/xxxx/xxxx/x.ko.gz", true , true , true, true, "[x]", "gz"); 61 T("/xxxx/xxxx/x.ko.gz", true , true, 1 , "[x]");
68 T("/xxxx/xxxx/x.ko.gz", false , true , true, true, NULL , "gz"); 62 T("/xxxx/xxxx/x.ko.gz", false , true, 1 , NULL );
69 T("/xxxx/xxxx/x.ko.gz", true , false , true, true, "[x]", NULL); 63 T("/xxxx/xxxx/x.ko.gz", true , true, 1 , "[x]");
70 T("/xxxx/xxxx/x.ko.gz", false , false , true, true, NULL , NULL); 64 T("/xxxx/xxxx/x.ko.gz", false , true, 1 , NULL );
71 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); 65 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
72 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_KERNEL, true); 66 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_KERNEL, true);
73 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_USER, false); 67 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_USER, false);
74 68
75 /* path alloc_name alloc_ext kmod comp name ext */ 69 /* path alloc_name kmod comp name */
76 T("/xxxx/xxxx/x.gz", true , true , false, true, "x.gz" ,"gz"); 70 T("/xxxx/xxxx/x.gz", true , false, 1 , "x.gz");
77 T("/xxxx/xxxx/x.gz", false , true , false, true, NULL ,"gz"); 71 T("/xxxx/xxxx/x.gz", false , false, 1 , NULL );
78 T("/xxxx/xxxx/x.gz", true , false , false, true, "x.gz" , NULL); 72 T("/xxxx/xxxx/x.gz", true , false, 1 , "x.gz");
79 T("/xxxx/xxxx/x.gz", false , false , false, true, NULL , NULL); 73 T("/xxxx/xxxx/x.gz", false , false, 1 , NULL );
80 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); 74 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
81 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_KERNEL, false); 75 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_KERNEL, false);
82 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_USER, false); 76 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_USER, false);
83 77
84 /* path alloc_name alloc_ext kmod comp name ext */ 78 /* path alloc_name kmod comp name */
85 T("x.gz", true , true , false, true, "x.gz", "gz"); 79 T("x.gz", true , false, 1 , "x.gz");
86 T("x.gz", false , true , false, true, NULL , "gz"); 80 T("x.gz", false , false, 1 , NULL );
87 T("x.gz", true , false , false, true, "x.gz", NULL); 81 T("x.gz", true , false, 1 , "x.gz");
88 T("x.gz", false , false , false, true, NULL , NULL); 82 T("x.gz", false , false, 1 , NULL );
89 M("x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); 83 M("x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
90 M("x.gz", PERF_RECORD_MISC_KERNEL, false); 84 M("x.gz", PERF_RECORD_MISC_KERNEL, false);
91 M("x.gz", PERF_RECORD_MISC_USER, false); 85 M("x.gz", PERF_RECORD_MISC_USER, false);
92 86
93 /* path alloc_name alloc_ext kmod comp name ext */ 87 /* path alloc_name kmod comp name */
94 T("x.ko.gz", true , true , true, true, "[x]", "gz"); 88 T("x.ko.gz", true , true, 1 , "[x]");
95 T("x.ko.gz", false , true , true, true, NULL , "gz"); 89 T("x.ko.gz", false , true, 1 , NULL );
96 T("x.ko.gz", true , false , true, true, "[x]", NULL); 90 T("x.ko.gz", true , true, 1 , "[x]");
97 T("x.ko.gz", false , false , true, true, NULL , NULL); 91 T("x.ko.gz", false , true, 1 , NULL );
98 M("x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); 92 M("x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
99 M("x.ko.gz", PERF_RECORD_MISC_KERNEL, true); 93 M("x.ko.gz", PERF_RECORD_MISC_KERNEL, true);
100 M("x.ko.gz", PERF_RECORD_MISC_USER, false); 94 M("x.ko.gz", PERF_RECORD_MISC_USER, false);
101#endif 95#endif
102 96
103 /* path alloc_name alloc_ext kmod comp name ext */ 97 /* path alloc_name kmod comp name */
104 T("[test_module]", true , true , true, false, "[test_module]", NULL); 98 T("[test_module]", true , true, false, "[test_module]");
105 T("[test_module]", false , true , true, false, NULL , NULL); 99 T("[test_module]", false , true, false, NULL );
106 T("[test_module]", true , false , true, false, "[test_module]", NULL); 100 T("[test_module]", true , true, false, "[test_module]");
107 T("[test_module]", false , false , true, false, NULL , NULL); 101 T("[test_module]", false , true, false, NULL );
108 M("[test_module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); 102 M("[test_module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
109 M("[test_module]", PERF_RECORD_MISC_KERNEL, true); 103 M("[test_module]", PERF_RECORD_MISC_KERNEL, true);
110 M("[test_module]", PERF_RECORD_MISC_USER, false); 104 M("[test_module]", PERF_RECORD_MISC_USER, false);
111 105
112 /* path alloc_name alloc_ext kmod comp name ext */ 106 /* path alloc_name kmod comp name */
113 T("[test.module]", true , true , true, false, "[test.module]", NULL); 107 T("[test.module]", true , true, false, "[test.module]");
114 T("[test.module]", false , true , true, false, NULL , NULL); 108 T("[test.module]", false , true, false, NULL );
115 T("[test.module]", true , false , true, false, "[test.module]", NULL); 109 T("[test.module]", true , true, false, "[test.module]");
116 T("[test.module]", false , false , true, false, NULL , NULL); 110 T("[test.module]", false , true, false, NULL );
117 M("[test.module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); 111 M("[test.module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
118 M("[test.module]", PERF_RECORD_MISC_KERNEL, true); 112 M("[test.module]", PERF_RECORD_MISC_KERNEL, true);
119 M("[test.module]", PERF_RECORD_MISC_USER, false); 113 M("[test.module]", PERF_RECORD_MISC_USER, false);
120 114
121 /* path alloc_name alloc_ext kmod comp name ext */ 115 /* path alloc_name kmod comp name */
122 T("[vdso]", true , true , false, false, "[vdso]", NULL); 116 T("[vdso]", true , false, false, "[vdso]");
123 T("[vdso]", false , true , false, false, NULL , NULL); 117 T("[vdso]", false , false, false, NULL );
124 T("[vdso]", true , false , false, false, "[vdso]", NULL); 118 T("[vdso]", true , false, false, "[vdso]");
125 T("[vdso]", false , false , false, false, NULL , NULL); 119 T("[vdso]", false , false, false, NULL );
126 M("[vdso]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); 120 M("[vdso]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
127 M("[vdso]", PERF_RECORD_MISC_KERNEL, false); 121 M("[vdso]", PERF_RECORD_MISC_KERNEL, false);
128 M("[vdso]", PERF_RECORD_MISC_USER, false); 122 M("[vdso]", PERF_RECORD_MISC_USER, false);
129 123
130 T("[vdso32]", true , true , false, false, "[vdso32]", NULL); 124 T("[vdso32]", true , false, false, "[vdso32]");
131 T("[vdso32]", false , true , false, false, NULL , NULL); 125 T("[vdso32]", false , false, false, NULL );
132 T("[vdso32]", true , false , false, false, "[vdso32]", NULL); 126 T("[vdso32]", true , false, false, "[vdso32]");
133 T("[vdso32]", false , false , false, false, NULL , NULL); 127 T("[vdso32]", false , false, false, NULL );
134 M("[vdso32]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); 128 M("[vdso32]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
135 M("[vdso32]", PERF_RECORD_MISC_KERNEL, false); 129 M("[vdso32]", PERF_RECORD_MISC_KERNEL, false);
136 M("[vdso32]", PERF_RECORD_MISC_USER, false); 130 M("[vdso32]", PERF_RECORD_MISC_USER, false);
137 131
138 T("[vdsox32]", true , true , false, false, "[vdsox32]", NULL); 132 T("[vdsox32]", true , false, false, "[vdsox32]");
139 T("[vdsox32]", false , true , false, false, NULL , NULL); 133 T("[vdsox32]", false , false, false, NULL );
140 T("[vdsox32]", true , false , false, false, "[vdsox32]", NULL); 134 T("[vdsox32]", true , false, false, "[vdsox32]");
141 T("[vdsox32]", false , false , false, false, NULL , NULL); 135 T("[vdsox32]", false , false, false, NULL );
142 M("[vdsox32]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); 136 M("[vdsox32]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
143 M("[vdsox32]", PERF_RECORD_MISC_KERNEL, false); 137 M("[vdsox32]", PERF_RECORD_MISC_KERNEL, false);
144 M("[vdsox32]", PERF_RECORD_MISC_USER, false); 138 M("[vdsox32]", PERF_RECORD_MISC_USER, false);
145 139
146 /* path alloc_name alloc_ext kmod comp name ext */ 140 /* path alloc_name kmod comp name */
147 T("[vsyscall]", true , true , false, false, "[vsyscall]", NULL); 141 T("[vsyscall]", true , false, false, "[vsyscall]");
148 T("[vsyscall]", false , true , false, false, NULL , NULL); 142 T("[vsyscall]", false , false, false, NULL );
149 T("[vsyscall]", true , false , false, false, "[vsyscall]", NULL); 143 T("[vsyscall]", true , false, false, "[vsyscall]");
150 T("[vsyscall]", false , false , false, false, NULL , NULL); 144 T("[vsyscall]", false , false, false, NULL );
151 M("[vsyscall]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); 145 M("[vsyscall]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
152 M("[vsyscall]", PERF_RECORD_MISC_KERNEL, false); 146 M("[vsyscall]", PERF_RECORD_MISC_KERNEL, false);
153 M("[vsyscall]", PERF_RECORD_MISC_USER, false); 147 M("[vsyscall]", PERF_RECORD_MISC_USER, false);
154 148
155 /* path alloc_name alloc_ext kmod comp name ext */ 149 /* path alloc_name kmod comp name */
156 T("[kernel.kallsyms]", true , true , false, false, "[kernel.kallsyms]", NULL); 150 T("[kernel.kallsyms]", true , false, false, "[kernel.kallsyms]");
157 T("[kernel.kallsyms]", false , true , false, false, NULL , NULL); 151 T("[kernel.kallsyms]", false , false, false, NULL );
158 T("[kernel.kallsyms]", true , false , false, false, "[kernel.kallsyms]", NULL); 152 T("[kernel.kallsyms]", true , false, false, "[kernel.kallsyms]");
159 T("[kernel.kallsyms]", false , false , false, false, NULL , NULL); 153 T("[kernel.kallsyms]", false , false, false, NULL );
160 M("[kernel.kallsyms]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); 154 M("[kernel.kallsyms]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
161 M("[kernel.kallsyms]", PERF_RECORD_MISC_KERNEL, false); 155 M("[kernel.kallsyms]", PERF_RECORD_MISC_KERNEL, false);
162 M("[kernel.kallsyms]", PERF_RECORD_MISC_USER, false); 156 M("[kernel.kallsyms]", PERF_RECORD_MISC_USER, false);
diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c
index 0c3c87f86e03..9e9e4d37cc77 100644
--- a/tools/perf/tests/mem2node.c
+++ b/tools/perf/tests/mem2node.c
@@ -24,8 +24,6 @@ static unsigned long *get_bitmap(const char *str, int nbits)
24 bm = bitmap_alloc(nbits); 24 bm = bitmap_alloc(nbits);
25 25
26 if (map && bm) { 26 if (map && bm) {
27 bitmap_zero(bm, nbits);
28
29 for (i = 0; i < map->nr; i++) { 27 for (i = 0; i < map->nr; i++) {
30 set_bit(map->map[i], bm); 28 set_bit(map->map[i], bm);
31 } 29 }
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 3b4f1c10ff57..1d00e5ec7906 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -15,6 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <sys/ttydefaults.h> 17#include <sys/ttydefaults.h>
18#include <asm/bug.h>
18 19
19struct disasm_line_samples { 20struct disasm_line_samples {
20 double percent; 21 double percent;
@@ -115,7 +116,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
115 if (!browser->navkeypressed) 116 if (!browser->navkeypressed)
116 ops.width += 1; 117 ops.width += 1;
117 118
118 annotation_line__write(al, notes, &ops); 119 annotation_line__write(al, notes, &ops, ab->opts);
119 120
120 if (ops.current_entry) 121 if (ops.current_entry)
121 ab->selection = al; 122 ab->selection = al;
@@ -227,10 +228,10 @@ static int disasm__cmp(struct annotation_line *a, struct annotation_line *b)
227{ 228{
228 int i; 229 int i;
229 230
230 for (i = 0; i < a->samples_nr; i++) { 231 for (i = 0; i < a->data_nr; i++) {
231 if (a->samples[i].percent == b->samples[i].percent) 232 if (a->data[i].percent == b->data[i].percent)
232 continue; 233 continue;
233 return a->samples[i].percent < b->samples[i].percent; 234 return a->data[i].percent < b->data[i].percent;
234 } 235 }
235 return 0; 236 return 0;
236} 237}
@@ -314,11 +315,14 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
314 continue; 315 continue;
315 } 316 }
316 317
317 for (i = 0; i < pos->al.samples_nr; i++) { 318 for (i = 0; i < pos->al.data_nr; i++) {
318 struct annotation_data *sample = &pos->al.samples[i]; 319 double percent;
319 320
320 if (max_percent < sample->percent) 321 percent = annotation_data__percent(&pos->al.data[i],
321 max_percent = sample->percent; 322 browser->opts->percent_type);
323
324 if (max_percent < percent)
325 max_percent = percent;
322 } 326 }
323 327
324 if (max_percent < 0.01 && pos->al.ipc == 0) { 328 if (max_percent < 0.01 && pos->al.ipc == 0) {
@@ -380,9 +384,10 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
380#define SYM_TITLE_MAX_SIZE (PATH_MAX + 64) 384#define SYM_TITLE_MAX_SIZE (PATH_MAX + 64)
381 385
382static int sym_title(struct symbol *sym, struct map *map, char *title, 386static int sym_title(struct symbol *sym, struct map *map, char *title,
383 size_t sz) 387 size_t sz, int percent_type)
384{ 388{
385 return snprintf(title, sz, "%s %s", sym->name, map->dso->long_name); 389 return snprintf(title, sz, "%s %s [Percent: %s]", sym->name, map->dso->long_name,
390 percent_type_str(percent_type));
386} 391}
387 392
388/* 393/*
@@ -420,7 +425,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
420 425
421 pthread_mutex_unlock(&notes->lock); 426 pthread_mutex_unlock(&notes->lock);
422 symbol__tui_annotate(dl->ops.target.sym, ms->map, evsel, hbt, browser->opts); 427 symbol__tui_annotate(dl->ops.target.sym, ms->map, evsel, hbt, browser->opts);
423 sym_title(ms->sym, ms->map, title, sizeof(title)); 428 sym_title(ms->sym, ms->map, title, sizeof(title), browser->opts->percent_type);
424 ui_browser__show_title(&browser->b, title); 429 ui_browser__show_title(&browser->b, title);
425 return true; 430 return true;
426} 431}
@@ -595,6 +600,7 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
595 600
596static int annotate_browser__show(struct ui_browser *browser, char *title, const char *help) 601static int annotate_browser__show(struct ui_browser *browser, char *title, const char *help)
597{ 602{
603 struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
598 struct map_symbol *ms = browser->priv; 604 struct map_symbol *ms = browser->priv;
599 struct symbol *sym = ms->sym; 605 struct symbol *sym = ms->sym;
600 char symbol_dso[SYM_TITLE_MAX_SIZE]; 606 char symbol_dso[SYM_TITLE_MAX_SIZE];
@@ -602,7 +608,7 @@ static int annotate_browser__show(struct ui_browser *browser, char *title, const
602 if (ui_browser__show(browser, title, help) < 0) 608 if (ui_browser__show(browser, title, help) < 0)
603 return -1; 609 return -1;
604 610
605 sym_title(sym, ms->map, symbol_dso, sizeof(symbol_dso)); 611 sym_title(sym, ms->map, symbol_dso, sizeof(symbol_dso), ab->opts->percent_type);
606 612
607 ui_browser__gotorc_title(browser, 0, 0); 613 ui_browser__gotorc_title(browser, 0, 0);
608 ui_browser__set_color(browser, HE_COLORSET_ROOT); 614 ui_browser__set_color(browser, HE_COLORSET_ROOT);
@@ -610,6 +616,39 @@ static int annotate_browser__show(struct ui_browser *browser, char *title, const
610 return 0; 616 return 0;
611} 617}
612 618
619static void
620switch_percent_type(struct annotation_options *opts, bool base)
621{
622 switch (opts->percent_type) {
623 case PERCENT_HITS_LOCAL:
624 if (base)
625 opts->percent_type = PERCENT_PERIOD_LOCAL;
626 else
627 opts->percent_type = PERCENT_HITS_GLOBAL;
628 break;
629 case PERCENT_HITS_GLOBAL:
630 if (base)
631 opts->percent_type = PERCENT_PERIOD_GLOBAL;
632 else
633 opts->percent_type = PERCENT_HITS_LOCAL;
634 break;
635 case PERCENT_PERIOD_LOCAL:
636 if (base)
637 opts->percent_type = PERCENT_HITS_LOCAL;
638 else
639 opts->percent_type = PERCENT_PERIOD_GLOBAL;
640 break;
641 case PERCENT_PERIOD_GLOBAL:
642 if (base)
643 opts->percent_type = PERCENT_HITS_GLOBAL;
644 else
645 opts->percent_type = PERCENT_PERIOD_LOCAL;
646 break;
647 default:
648 WARN_ON(1);
649 }
650}
651
613static int annotate_browser__run(struct annotate_browser *browser, 652static int annotate_browser__run(struct annotate_browser *browser,
614 struct perf_evsel *evsel, 653 struct perf_evsel *evsel,
615 struct hist_browser_timer *hbt) 654 struct hist_browser_timer *hbt)
@@ -624,8 +663,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
624 char title[256]; 663 char title[256];
625 int key; 664 int key;
626 665
627 annotation__scnprintf_samples_period(notes, title, sizeof(title), evsel); 666 hists__scnprintf_title(hists, title, sizeof(title));
628
629 if (annotate_browser__show(&browser->b, title, help) < 0) 667 if (annotate_browser__show(&browser->b, title, help) < 0)
630 return -1; 668 return -1;
631 669
@@ -701,6 +739,8 @@ static int annotate_browser__run(struct annotate_browser *browser,
701 "k Toggle line numbers\n" 739 "k Toggle line numbers\n"
702 "P Print to [symbol_name].annotation file.\n" 740 "P Print to [symbol_name].annotation file.\n"
703 "r Run available scripts\n" 741 "r Run available scripts\n"
742 "p Toggle percent type [local/global]\n"
743 "b Toggle percent base [period/hits]\n"
704 "? Search string backwards\n"); 744 "? Search string backwards\n");
705 continue; 745 continue;
706 case 'r': 746 case 'r':
@@ -781,7 +821,7 @@ show_sup_ins:
781 continue; 821 continue;
782 } 822 }
783 case 'P': 823 case 'P':
784 map_symbol__annotation_dump(ms, evsel); 824 map_symbol__annotation_dump(ms, evsel, browser->opts);
785 continue; 825 continue;
786 case 't': 826 case 't':
787 if (notes->options->show_total_period) { 827 if (notes->options->show_total_period) {
@@ -800,6 +840,12 @@ show_sup_ins:
800 notes->options->show_minmax_cycle = true; 840 notes->options->show_minmax_cycle = true;
801 annotation__update_column_widths(notes); 841 annotation__update_column_widths(notes);
802 continue; 842 continue;
843 case 'p':
844 case 'b':
845 switch_percent_type(browser->opts, key == 'b');
846 hists__scnprintf_title(hists, title, sizeof(title));
847 annotate_browser__show(&browser->b, title, help);
848 continue;
803 case K_LEFT: 849 case K_LEFT:
804 case K_ESC: 850 case K_ESC:
805 case 'q': 851 case 'q':
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b604ef334dc9..7efe15b9618d 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -87,6 +87,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o
87libperf-$(CONFIG_AUXTRACE) += intel-bts.o 87libperf-$(CONFIG_AUXTRACE) += intel-bts.o
88libperf-$(CONFIG_AUXTRACE) += arm-spe.o 88libperf-$(CONFIG_AUXTRACE) += arm-spe.o
89libperf-$(CONFIG_AUXTRACE) += arm-spe-pkt-decoder.o 89libperf-$(CONFIG_AUXTRACE) += arm-spe-pkt-decoder.o
90libperf-$(CONFIG_AUXTRACE) += s390-cpumsf.o
90 91
91ifdef CONFIG_LIBOPENCSD 92ifdef CONFIG_LIBOPENCSD
92libperf-$(CONFIG_AUXTRACE) += cs-etm.o 93libperf-$(CONFIG_AUXTRACE) += cs-etm.o
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index f91775b4bc3c..20061cf42288 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -49,6 +49,7 @@ struct annotation_options annotation__default_options = {
49 .jump_arrows = true, 49 .jump_arrows = true,
50 .annotate_src = true, 50 .annotate_src = true,
51 .offset_level = ANNOTATION__OFFSET_JUMP_TARGETS, 51 .offset_level = ANNOTATION__OFFSET_JUMP_TARGETS,
52 .percent_type = PERCENT_PERIOD_LOCAL,
52}; 53};
53 54
54static regex_t file_lineno; 55static regex_t file_lineno;
@@ -1108,7 +1109,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
1108 if (perf_evsel__is_group_event(evsel)) 1109 if (perf_evsel__is_group_event(evsel))
1109 nr = evsel->nr_members; 1110 nr = evsel->nr_members;
1110 1111
1111 size += sizeof(al->samples[0]) * nr; 1112 size += sizeof(al->data[0]) * nr;
1112 1113
1113 al = zalloc(size); 1114 al = zalloc(size);
1114 if (al) { 1115 if (al) {
@@ -1117,7 +1118,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
1117 al->offset = args->offset; 1118 al->offset = args->offset;
1118 al->line = strdup(args->line); 1119 al->line = strdup(args->line);
1119 al->line_nr = args->line_nr; 1120 al->line_nr = args->line_nr;
1120 al->samples_nr = nr; 1121 al->data_nr = nr;
1121 } 1122 }
1122 1123
1123 return al; 1124 return al;
@@ -1297,7 +1298,8 @@ static int disasm_line__print(struct disasm_line *dl, u64 start, int addr_fmt_wi
1297static int 1298static int
1298annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start, 1299annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start,
1299 struct perf_evsel *evsel, u64 len, int min_pcnt, int printed, 1300 struct perf_evsel *evsel, u64 len, int min_pcnt, int printed,
1300 int max_lines, struct annotation_line *queue, int addr_fmt_width) 1301 int max_lines, struct annotation_line *queue, int addr_fmt_width,
1302 int percent_type)
1301{ 1303{
1302 struct disasm_line *dl = container_of(al, struct disasm_line, al); 1304 struct disasm_line *dl = container_of(al, struct disasm_line, al);
1303 static const char *prev_line; 1305 static const char *prev_line;
@@ -1309,15 +1311,18 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
1309 const char *color; 1311 const char *color;
1310 struct annotation *notes = symbol__annotation(sym); 1312 struct annotation *notes = symbol__annotation(sym);
1311 1313
1312 for (i = 0; i < al->samples_nr; i++) { 1314 for (i = 0; i < al->data_nr; i++) {
1313 struct annotation_data *sample = &al->samples[i]; 1315 double percent;
1314 1316
1315 if (sample->percent > max_percent) 1317 percent = annotation_data__percent(&al->data[i],
1316 max_percent = sample->percent; 1318 percent_type);
1319
1320 if (percent > max_percent)
1321 max_percent = percent;
1317 } 1322 }
1318 1323
1319 if (al->samples_nr > nr_percent) 1324 if (al->data_nr > nr_percent)
1320 nr_percent = al->samples_nr; 1325 nr_percent = al->data_nr;
1321 1326
1322 if (max_percent < min_pcnt) 1327 if (max_percent < min_pcnt)
1323 return -1; 1328 return -1;
@@ -1330,7 +1335,8 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
1330 if (queue == al) 1335 if (queue == al)
1331 break; 1336 break;
1332 annotation_line__print(queue, sym, start, evsel, len, 1337 annotation_line__print(queue, sym, start, evsel, len,
1333 0, 0, 1, NULL, addr_fmt_width); 1338 0, 0, 1, NULL, addr_fmt_width,
1339 percent_type);
1334 } 1340 }
1335 } 1341 }
1336 1342
@@ -1351,18 +1357,20 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
1351 } 1357 }
1352 1358
1353 for (i = 0; i < nr_percent; i++) { 1359 for (i = 0; i < nr_percent; i++) {
1354 struct annotation_data *sample = &al->samples[i]; 1360 struct annotation_data *data = &al->data[i];
1361 double percent;
1355 1362
1356 color = get_percent_color(sample->percent); 1363 percent = annotation_data__percent(data, percent_type);
1364 color = get_percent_color(percent);
1357 1365
1358 if (symbol_conf.show_total_period) 1366 if (symbol_conf.show_total_period)
1359 color_fprintf(stdout, color, " %11" PRIu64, 1367 color_fprintf(stdout, color, " %11" PRIu64,
1360 sample->he.period); 1368 data->he.period);
1361 else if (symbol_conf.show_nr_samples) 1369 else if (symbol_conf.show_nr_samples)
1362 color_fprintf(stdout, color, " %7" PRIu64, 1370 color_fprintf(stdout, color, " %7" PRIu64,
1363 sample->he.nr_samples); 1371 data->he.nr_samples);
1364 else 1372 else
1365 color_fprintf(stdout, color, " %7.2f", sample->percent); 1373 color_fprintf(stdout, color, " %7.2f", percent);
1366 } 1374 }
1367 1375
1368 printf(" : "); 1376 printf(" : ");
@@ -1621,6 +1629,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
1621 char symfs_filename[PATH_MAX]; 1629 char symfs_filename[PATH_MAX];
1622 struct kcore_extract kce; 1630 struct kcore_extract kce;
1623 bool delete_extract = false; 1631 bool delete_extract = false;
1632 bool decomp = false;
1624 int stdout_fd[2]; 1633 int stdout_fd[2];
1625 int lineno = 0; 1634 int lineno = 0;
1626 int nline; 1635 int nline;
@@ -1654,6 +1663,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
1654 tmp, sizeof(tmp)) < 0) 1663 tmp, sizeof(tmp)) < 0)
1655 goto out; 1664 goto out;
1656 1665
1666 decomp = true;
1657 strcpy(symfs_filename, tmp); 1667 strcpy(symfs_filename, tmp);
1658 } 1668 }
1659 1669
@@ -1740,7 +1750,7 @@ out_free_command:
1740out_remove_tmp: 1750out_remove_tmp:
1741 close(stdout_fd[0]); 1751 close(stdout_fd[0]);
1742 1752
1743 if (dso__needs_decompress(dso)) 1753 if (decomp)
1744 unlink(symfs_filename); 1754 unlink(symfs_filename);
1745 1755
1746 if (delete_extract) 1756 if (delete_extract)
@@ -1753,34 +1763,45 @@ out_close_stdout:
1753 goto out_free_command; 1763 goto out_free_command;
1754} 1764}
1755 1765
1756static void calc_percent(struct sym_hist *hist, 1766static void calc_percent(struct sym_hist *sym_hist,
1757 struct annotation_data *sample, 1767 struct hists *hists,
1768 struct annotation_data *data,
1758 s64 offset, s64 end) 1769 s64 offset, s64 end)
1759{ 1770{
1760 unsigned int hits = 0; 1771 unsigned int hits = 0;
1761 u64 period = 0; 1772 u64 period = 0;
1762 1773
1763 while (offset < end) { 1774 while (offset < end) {
1764 hits += hist->addr[offset].nr_samples; 1775 hits += sym_hist->addr[offset].nr_samples;
1765 period += hist->addr[offset].period; 1776 period += sym_hist->addr[offset].period;
1766 ++offset; 1777 ++offset;
1767 } 1778 }
1768 1779
1769 if (hist->nr_samples) { 1780 if (sym_hist->nr_samples) {
1770 sample->he.period = period; 1781 data->he.period = period;
1771 sample->he.nr_samples = hits; 1782 data->he.nr_samples = hits;
1772 sample->percent = 100.0 * hits / hist->nr_samples; 1783 data->percent[PERCENT_HITS_LOCAL] = 100.0 * hits / sym_hist->nr_samples;
1773 } 1784 }
1785
1786 if (hists->stats.nr_non_filtered_samples)
1787 data->percent[PERCENT_HITS_GLOBAL] = 100.0 * hits / hists->stats.nr_non_filtered_samples;
1788
1789 if (sym_hist->period)
1790 data->percent[PERCENT_PERIOD_LOCAL] = 100.0 * period / sym_hist->period;
1791
1792 if (hists->stats.total_period)
1793 data->percent[PERCENT_PERIOD_GLOBAL] = 100.0 * period / hists->stats.total_period;
1774} 1794}
1775 1795
1776static void annotation__calc_percent(struct annotation *notes, 1796static void annotation__calc_percent(struct annotation *notes,
1777 struct perf_evsel *evsel, s64 len) 1797 struct perf_evsel *leader, s64 len)
1778{ 1798{
1779 struct annotation_line *al, *next; 1799 struct annotation_line *al, *next;
1800 struct perf_evsel *evsel;
1780 1801
1781 list_for_each_entry(al, &notes->src->source, node) { 1802 list_for_each_entry(al, &notes->src->source, node) {
1782 s64 end; 1803 s64 end;
1783 int i; 1804 int i = 0;
1784 1805
1785 if (al->offset == -1) 1806 if (al->offset == -1)
1786 continue; 1807 continue;
@@ -1788,14 +1809,17 @@ static void annotation__calc_percent(struct annotation *notes,
1788 next = annotation_line__next(al, &notes->src->source); 1809 next = annotation_line__next(al, &notes->src->source);
1789 end = next ? next->offset : len; 1810 end = next ? next->offset : len;
1790 1811
1791 for (i = 0; i < al->samples_nr; i++) { 1812 for_each_group_evsel(evsel, leader) {
1792 struct annotation_data *sample; 1813 struct hists *hists = evsel__hists(evsel);
1793 struct sym_hist *hist; 1814 struct annotation_data *data;
1815 struct sym_hist *sym_hist;
1816
1817 BUG_ON(i >= al->data_nr);
1794 1818
1795 hist = annotation__histogram(notes, evsel->idx + i); 1819 sym_hist = annotation__histogram(notes, evsel->idx);
1796 sample = &al->samples[i]; 1820 data = &al->data[i++];
1797 1821
1798 calc_percent(hist, sample, al->offset, end); 1822 calc_percent(sym_hist, hists, data, al->offset, end);
1799 } 1823 }
1800 } 1824 }
1801} 1825}
@@ -1846,7 +1870,8 @@ int symbol__annotate(struct symbol *sym, struct map *map,
1846 return symbol__disassemble(sym, &args); 1870 return symbol__disassemble(sym, &args);
1847} 1871}
1848 1872
1849static void insert_source_line(struct rb_root *root, struct annotation_line *al) 1873static void insert_source_line(struct rb_root *root, struct annotation_line *al,
1874 struct annotation_options *opts)
1850{ 1875{
1851 struct annotation_line *iter; 1876 struct annotation_line *iter;
1852 struct rb_node **p = &root->rb_node; 1877 struct rb_node **p = &root->rb_node;
@@ -1859,8 +1884,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
1859 1884
1860 ret = strcmp(iter->path, al->path); 1885 ret = strcmp(iter->path, al->path);
1861 if (ret == 0) { 1886 if (ret == 0) {
1862 for (i = 0; i < al->samples_nr; i++) 1887 for (i = 0; i < al->data_nr; i++) {
1863 iter->samples[i].percent_sum += al->samples[i].percent; 1888 iter->data[i].percent_sum += annotation_data__percent(&al->data[i],
1889 opts->percent_type);
1890 }
1864 return; 1891 return;
1865 } 1892 }
1866 1893
@@ -1870,8 +1897,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
1870 p = &(*p)->rb_right; 1897 p = &(*p)->rb_right;
1871 } 1898 }
1872 1899
1873 for (i = 0; i < al->samples_nr; i++) 1900 for (i = 0; i < al->data_nr; i++) {
1874 al->samples[i].percent_sum = al->samples[i].percent; 1901 al->data[i].percent_sum = annotation_data__percent(&al->data[i],
1902 opts->percent_type);
1903 }
1875 1904
1876 rb_link_node(&al->rb_node, parent, p); 1905 rb_link_node(&al->rb_node, parent, p);
1877 rb_insert_color(&al->rb_node, root); 1906 rb_insert_color(&al->rb_node, root);
@@ -1881,10 +1910,10 @@ static int cmp_source_line(struct annotation_line *a, struct annotation_line *b)
1881{ 1910{
1882 int i; 1911 int i;
1883 1912
1884 for (i = 0; i < a->samples_nr; i++) { 1913 for (i = 0; i < a->data_nr; i++) {
1885 if (a->samples[i].percent_sum == b->samples[i].percent_sum) 1914 if (a->data[i].percent_sum == b->data[i].percent_sum)
1886 continue; 1915 continue;
1887 return a->samples[i].percent_sum > b->samples[i].percent_sum; 1916 return a->data[i].percent_sum > b->data[i].percent_sum;
1888 } 1917 }
1889 1918
1890 return 0; 1919 return 0;
@@ -1949,8 +1978,8 @@ static void print_summary(struct rb_root *root, const char *filename)
1949 int i; 1978 int i;
1950 1979
1951 al = rb_entry(node, struct annotation_line, rb_node); 1980 al = rb_entry(node, struct annotation_line, rb_node);
1952 for (i = 0; i < al->samples_nr; i++) { 1981 for (i = 0; i < al->data_nr; i++) {
1953 percent = al->samples[i].percent_sum; 1982 percent = al->data[i].percent_sum;
1954 color = get_percent_color(percent); 1983 color = get_percent_color(percent);
1955 color_fprintf(stdout, color, " %7.2f", percent); 1984 color_fprintf(stdout, color, " %7.2f", percent);
1956 1985
@@ -2029,10 +2058,12 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
2029 evsel_name = buf; 2058 evsel_name = buf;
2030 } 2059 }
2031 2060
2032 graph_dotted_len = printf(" %-*.*s| Source code & Disassembly of %s for %s (%" PRIu64 " samples)\n", 2061 graph_dotted_len = printf(" %-*.*s| Source code & Disassembly of %s for %s (%" PRIu64 " samples, "
2062 "percent: %s)\n",
2033 width, width, symbol_conf.show_total_period ? "Period" : 2063 width, width, symbol_conf.show_total_period ? "Period" :
2034 symbol_conf.show_nr_samples ? "Samples" : "Percent", 2064 symbol_conf.show_nr_samples ? "Samples" : "Percent",
2035 d_filename, evsel_name, h->nr_samples); 2065 d_filename, evsel_name, h->nr_samples,
2066 percent_type_str(opts->percent_type));
2036 2067
2037 printf("%-*.*s----\n", 2068 printf("%-*.*s----\n",
2038 graph_dotted_len, graph_dotted_len, graph_dotted_line); 2069 graph_dotted_len, graph_dotted_len, graph_dotted_line);
@@ -2052,7 +2083,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
2052 2083
2053 err = annotation_line__print(pos, sym, start, evsel, len, 2084 err = annotation_line__print(pos, sym, start, evsel, len,
2054 opts->min_pcnt, printed, opts->max_lines, 2085 opts->min_pcnt, printed, opts->max_lines,
2055 queue, addr_fmt_width); 2086 queue, addr_fmt_width, opts->percent_type);
2056 2087
2057 switch (err) { 2088 switch (err) {
2058 case 0: 2089 case 0:
@@ -2129,10 +2160,11 @@ static void FILE__write_graph(void *fp, int graph)
2129 fputs(s, fp); 2160 fputs(s, fp);
2130} 2161}
2131 2162
2132int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp) 2163static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp,
2164 struct annotation_options *opts)
2133{ 2165{
2134 struct annotation *notes = symbol__annotation(sym); 2166 struct annotation *notes = symbol__annotation(sym);
2135 struct annotation_write_ops ops = { 2167 struct annotation_write_ops wops = {
2136 .first_line = true, 2168 .first_line = true,
2137 .obj = fp, 2169 .obj = fp,
2138 .set_color = FILE__set_color, 2170 .set_color = FILE__set_color,
@@ -2146,15 +2178,16 @@ int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
2146 list_for_each_entry(al, &notes->src->source, node) { 2178 list_for_each_entry(al, &notes->src->source, node) {
2147 if (annotation_line__filter(al, notes)) 2179 if (annotation_line__filter(al, notes))
2148 continue; 2180 continue;
2149 annotation_line__write(al, notes, &ops); 2181 annotation_line__write(al, notes, &wops, opts);
2150 fputc('\n', fp); 2182 fputc('\n', fp);
2151 ops.first_line = false; 2183 wops.first_line = false;
2152 } 2184 }
2153 2185
2154 return 0; 2186 return 0;
2155} 2187}
2156 2188
2157int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel) 2189int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
2190 struct annotation_options *opts)
2158{ 2191{
2159 const char *ev_name = perf_evsel__name(evsel); 2192 const char *ev_name = perf_evsel__name(evsel);
2160 char buf[1024]; 2193 char buf[1024];
@@ -2176,7 +2209,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel)
2176 2209
2177 fprintf(fp, "%s() %s\nEvent: %s\n\n", 2210 fprintf(fp, "%s() %s\nEvent: %s\n\n",
2178 ms->sym->name, ms->map->dso->long_name, ev_name); 2211 ms->sym->name, ms->map->dso->long_name, ev_name);
2179 symbol__annotate_fprintf2(ms->sym, fp); 2212 symbol__annotate_fprintf2(ms->sym, fp, opts);
2180 2213
2181 fclose(fp); 2214 fclose(fp);
2182 err = 0; 2215 err = 0;
@@ -2346,7 +2379,8 @@ void annotation__update_column_widths(struct annotation *notes)
2346} 2379}
2347 2380
2348static void annotation__calc_lines(struct annotation *notes, struct map *map, 2381static void annotation__calc_lines(struct annotation *notes, struct map *map,
2349 struct rb_root *root) 2382 struct rb_root *root,
2383 struct annotation_options *opts)
2350{ 2384{
2351 struct annotation_line *al; 2385 struct annotation_line *al;
2352 struct rb_root tmp_root = RB_ROOT; 2386 struct rb_root tmp_root = RB_ROOT;
@@ -2355,13 +2389,14 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
2355 double percent_max = 0.0; 2389 double percent_max = 0.0;
2356 int i; 2390 int i;
2357 2391
2358 for (i = 0; i < al->samples_nr; i++) { 2392 for (i = 0; i < al->data_nr; i++) {
2359 struct annotation_data *sample; 2393 double percent;
2360 2394
2361 sample = &al->samples[i]; 2395 percent = annotation_data__percent(&al->data[i],
2396 opts->percent_type);
2362 2397
2363 if (sample->percent > percent_max) 2398 if (percent > percent_max)
2364 percent_max = sample->percent; 2399 percent_max = percent;
2365 } 2400 }
2366 2401
2367 if (percent_max <= 0.5) 2402 if (percent_max <= 0.5)
@@ -2369,18 +2404,19 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
2369 2404
2370 al->path = get_srcline(map->dso, notes->start + al->offset, NULL, 2405 al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
2371 false, true, notes->start + al->offset); 2406 false, true, notes->start + al->offset);
2372 insert_source_line(&tmp_root, al); 2407 insert_source_line(&tmp_root, al, opts);
2373 } 2408 }
2374 2409
2375 resort_source_line(root, &tmp_root); 2410 resort_source_line(root, &tmp_root);
2376} 2411}
2377 2412
2378static void symbol__calc_lines(struct symbol *sym, struct map *map, 2413static void symbol__calc_lines(struct symbol *sym, struct map *map,
2379 struct rb_root *root) 2414 struct rb_root *root,
2415 struct annotation_options *opts)
2380{ 2416{
2381 struct annotation *notes = symbol__annotation(sym); 2417 struct annotation *notes = symbol__annotation(sym);
2382 2418
2383 annotation__calc_lines(notes, map, root); 2419 annotation__calc_lines(notes, map, root, opts);
2384} 2420}
2385 2421
2386int symbol__tty_annotate2(struct symbol *sym, struct map *map, 2422int symbol__tty_annotate2(struct symbol *sym, struct map *map,
@@ -2389,7 +2425,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
2389{ 2425{
2390 struct dso *dso = map->dso; 2426 struct dso *dso = map->dso;
2391 struct rb_root source_line = RB_ROOT; 2427 struct rb_root source_line = RB_ROOT;
2392 struct annotation *notes = symbol__annotation(sym); 2428 struct hists *hists = evsel__hists(evsel);
2393 char buf[1024]; 2429 char buf[1024];
2394 2430
2395 if (symbol__annotate2(sym, map, evsel, opts, NULL) < 0) 2431 if (symbol__annotate2(sym, map, evsel, opts, NULL) < 0)
@@ -2397,13 +2433,14 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
2397 2433
2398 if (opts->print_lines) { 2434 if (opts->print_lines) {
2399 srcline_full_filename = opts->full_path; 2435 srcline_full_filename = opts->full_path;
2400 symbol__calc_lines(sym, map, &source_line); 2436 symbol__calc_lines(sym, map, &source_line, opts);
2401 print_summary(&source_line, dso->long_name); 2437 print_summary(&source_line, dso->long_name);
2402 } 2438 }
2403 2439
2404 annotation__scnprintf_samples_period(notes, buf, sizeof(buf), evsel); 2440 hists__scnprintf_title(hists, buf, sizeof(buf));
2405 fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name); 2441 fprintf(stdout, "%s, [percent: %s]\n%s() %s\n",
2406 symbol__annotate_fprintf2(sym, stdout); 2442 buf, percent_type_str(opts->percent_type), sym->name, dso->long_name);
2443 symbol__annotate_fprintf2(sym, stdout, opts);
2407 2444
2408 annotated_source__purge(symbol__annotation(sym)->src); 2445 annotated_source__purge(symbol__annotation(sym)->src);
2409 2446
@@ -2424,7 +2461,7 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map,
2424 2461
2425 if (opts->print_lines) { 2462 if (opts->print_lines) {
2426 srcline_full_filename = opts->full_path; 2463 srcline_full_filename = opts->full_path;
2427 symbol__calc_lines(sym, map, &source_line); 2464 symbol__calc_lines(sym, map, &source_line, opts);
2428 print_summary(&source_line, dso->long_name); 2465 print_summary(&source_line, dso->long_name);
2429 } 2466 }
2430 2467
@@ -2441,14 +2478,21 @@ bool ui__has_annotation(void)
2441} 2478}
2442 2479
2443 2480
2444double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes) 2481static double annotation_line__max_percent(struct annotation_line *al,
2482 struct annotation *notes,
2483 unsigned int percent_type)
2445{ 2484{
2446 double percent_max = 0.0; 2485 double percent_max = 0.0;
2447 int i; 2486 int i;
2448 2487
2449 for (i = 0; i < notes->nr_events; i++) { 2488 for (i = 0; i < notes->nr_events; i++) {
2450 if (al->samples[i].percent > percent_max) 2489 double percent;
2451 percent_max = al->samples[i].percent; 2490
2491 percent = annotation_data__percent(&al->data[i],
2492 percent_type);
2493
2494 if (percent > percent_max)
2495 percent_max = percent;
2452 } 2496 }
2453 2497
2454 return percent_max; 2498 return percent_max;
@@ -2487,7 +2531,7 @@ call_like:
2487 2531
2488static void __annotation_line__write(struct annotation_line *al, struct annotation *notes, 2532static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
2489 bool first_line, bool current_entry, bool change_color, int width, 2533 bool first_line, bool current_entry, bool change_color, int width,
2490 void *obj, 2534 void *obj, unsigned int percent_type,
2491 int (*obj__set_color)(void *obj, int color), 2535 int (*obj__set_color)(void *obj, int color),
2492 void (*obj__set_percent_color)(void *obj, double percent, bool current), 2536 void (*obj__set_percent_color)(void *obj, double percent, bool current),
2493 int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current), 2537 int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
@@ -2495,7 +2539,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
2495 void (*obj__write_graph)(void *obj, int graph)) 2539 void (*obj__write_graph)(void *obj, int graph))
2496 2540
2497{ 2541{
2498 double percent_max = annotation_line__max_percent(al, notes); 2542 double percent_max = annotation_line__max_percent(al, notes, percent_type);
2499 int pcnt_width = annotation__pcnt_width(notes), 2543 int pcnt_width = annotation__pcnt_width(notes),
2500 cycles_width = annotation__cycles_width(notes); 2544 cycles_width = annotation__cycles_width(notes);
2501 bool show_title = false; 2545 bool show_title = false;
@@ -2514,15 +2558,18 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
2514 int i; 2558 int i;
2515 2559
2516 for (i = 0; i < notes->nr_events; i++) { 2560 for (i = 0; i < notes->nr_events; i++) {
2517 obj__set_percent_color(obj, al->samples[i].percent, current_entry); 2561 double percent;
2562
2563 percent = annotation_data__percent(&al->data[i], percent_type);
2564
2565 obj__set_percent_color(obj, percent, current_entry);
2518 if (notes->options->show_total_period) { 2566 if (notes->options->show_total_period) {
2519 obj__printf(obj, "%11" PRIu64 " ", al->samples[i].he.period); 2567 obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period);
2520 } else if (notes->options->show_nr_samples) { 2568 } else if (notes->options->show_nr_samples) {
2521 obj__printf(obj, "%6" PRIu64 " ", 2569 obj__printf(obj, "%6" PRIu64 " ",
2522 al->samples[i].he.nr_samples); 2570 al->data[i].he.nr_samples);
2523 } else { 2571 } else {
2524 obj__printf(obj, "%6.2f ", 2572 obj__printf(obj, "%6.2f ", percent);
2525 al->samples[i].percent);
2526 } 2573 }
2527 } 2574 }
2528 } else { 2575 } else {
@@ -2640,13 +2687,15 @@ print_addr:
2640} 2687}
2641 2688
2642void annotation_line__write(struct annotation_line *al, struct annotation *notes, 2689void annotation_line__write(struct annotation_line *al, struct annotation *notes,
2643 struct annotation_write_ops *ops) 2690 struct annotation_write_ops *wops,
2691 struct annotation_options *opts)
2644{ 2692{
2645 __annotation_line__write(al, notes, ops->first_line, ops->current_entry, 2693 __annotation_line__write(al, notes, wops->first_line, wops->current_entry,
2646 ops->change_color, ops->width, ops->obj, 2694 wops->change_color, wops->width, wops->obj,
2647 ops->set_color, ops->set_percent_color, 2695 opts->percent_type,
2648 ops->set_jumps_percent_color, ops->printf, 2696 wops->set_color, wops->set_percent_color,
2649 ops->write_graph); 2697 wops->set_jumps_percent_color, wops->printf,
2698 wops->write_graph);
2650} 2699}
2651 2700
2652int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel, 2701int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel,
@@ -2688,46 +2737,6 @@ out_free_offsets:
2688 return -1; 2737 return -1;
2689} 2738}
2690 2739
2691int __annotation__scnprintf_samples_period(struct annotation *notes,
2692 char *bf, size_t size,
2693 struct perf_evsel *evsel,
2694 bool show_freq)
2695{
2696 const char *ev_name = perf_evsel__name(evsel);
2697 char buf[1024], ref[30] = " show reference callgraph, ";
2698 char sample_freq_str[64] = "";
2699 unsigned long nr_samples = 0;
2700 int nr_members = 1;
2701 bool enable_ref = false;
2702 u64 nr_events = 0;
2703 char unit;
2704 int i;
2705
2706 if (perf_evsel__is_group_event(evsel)) {
2707 perf_evsel__group_desc(evsel, buf, sizeof(buf));
2708 ev_name = buf;
2709 nr_members = evsel->nr_members;
2710 }
2711
2712 for (i = 0; i < nr_members; i++) {
2713 struct sym_hist *ah = annotation__histogram(notes, evsel->idx + i);
2714
2715 nr_samples += ah->nr_samples;
2716 nr_events += ah->period;
2717 }
2718
2719 if (symbol_conf.show_ref_callgraph && strstr(ev_name, "call-graph=no"))
2720 enable_ref = true;
2721
2722 if (show_freq)
2723 scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->attr.sample_freq);
2724
2725 nr_samples = convert_unit(nr_samples, &unit);
2726 return scnprintf(bf, size, "Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64,
2727 nr_samples, unit, evsel->nr_members > 1 ? "s" : "",
2728 ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events);
2729}
2730
2731#define ANNOTATION__CFG(n) \ 2740#define ANNOTATION__CFG(n) \
2732 { .name = #n, .value = &annotation__default_options.n, } 2741 { .name = #n, .value = &annotation__default_options.n, }
2733 2742
@@ -2792,3 +2801,55 @@ void annotation_config__init(void)
2792 annotation__default_options.show_total_period = symbol_conf.show_total_period; 2801 annotation__default_options.show_total_period = symbol_conf.show_total_period;
2793 annotation__default_options.show_nr_samples = symbol_conf.show_nr_samples; 2802 annotation__default_options.show_nr_samples = symbol_conf.show_nr_samples;
2794} 2803}
2804
2805static unsigned int parse_percent_type(char *str1, char *str2)
2806{
2807 unsigned int type = (unsigned int) -1;
2808
2809 if (!strcmp("period", str1)) {
2810 if (!strcmp("local", str2))
2811 type = PERCENT_PERIOD_LOCAL;
2812 else if (!strcmp("global", str2))
2813 type = PERCENT_PERIOD_GLOBAL;
2814 }
2815
2816 if (!strcmp("hits", str1)) {
2817 if (!strcmp("local", str2))
2818 type = PERCENT_HITS_LOCAL;
2819 else if (!strcmp("global", str2))
2820 type = PERCENT_HITS_GLOBAL;
2821 }
2822
2823 return type;
2824}
2825
2826int annotate_parse_percent_type(const struct option *opt, const char *_str,
2827 int unset __maybe_unused)
2828{
2829 struct annotation_options *opts = opt->value;
2830 unsigned int type;
2831 char *str1, *str2;
2832 int err = -1;
2833
2834 str1 = strdup(_str);
2835 if (!str1)
2836 return -ENOMEM;
2837
2838 str2 = strchr(str1, '-');
2839 if (!str2)
2840 goto out;
2841
2842 *str2++ = 0;
2843
2844 type = parse_percent_type(str1, str2);
2845 if (type == (unsigned int) -1)
2846 type = parse_percent_type(str2, str1);
2847 if (type != (unsigned int) -1) {
2848 opts->percent_type = type;
2849 err = 0;
2850 }
2851
2852out:
2853 free(str1);
2854 return err;
2855}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index a4c0d91907e6..005a5fe8a8c6 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -11,6 +11,7 @@
11#include <linux/list.h> 11#include <linux/list.h>
12#include <linux/rbtree.h> 12#include <linux/rbtree.h>
13#include <pthread.h> 13#include <pthread.h>
14#include <asm/bug.h>
14 15
15struct ins_ops; 16struct ins_ops;
16 17
@@ -82,6 +83,7 @@ struct annotation_options {
82 int context; 83 int context;
83 const char *objdump_path; 84 const char *objdump_path;
84 const char *disassembler_style; 85 const char *disassembler_style;
86 unsigned int percent_type;
85}; 87};
86 88
87enum { 89enum {
@@ -101,8 +103,16 @@ struct sym_hist_entry {
101 u64 period; 103 u64 period;
102}; 104};
103 105
106enum {
107 PERCENT_HITS_LOCAL,
108 PERCENT_HITS_GLOBAL,
109 PERCENT_PERIOD_LOCAL,
110 PERCENT_PERIOD_GLOBAL,
111 PERCENT_MAX,
112};
113
104struct annotation_data { 114struct annotation_data {
105 double percent; 115 double percent[PERCENT_MAX];
106 double percent_sum; 116 double percent_sum;
107 struct sym_hist_entry he; 117 struct sym_hist_entry he;
108}; 118};
@@ -122,8 +132,8 @@ struct annotation_line {
122 char *path; 132 char *path;
123 u32 idx; 133 u32 idx;
124 int idx_asm; 134 int idx_asm;
125 int samples_nr; 135 int data_nr;
126 struct annotation_data samples[0]; 136 struct annotation_data data[0];
127}; 137};
128 138
129struct disasm_line { 139struct disasm_line {
@@ -134,6 +144,27 @@ struct disasm_line {
134 struct annotation_line al; 144 struct annotation_line al;
135}; 145};
136 146
147static inline double annotation_data__percent(struct annotation_data *data,
148 unsigned int which)
149{
150 return which < PERCENT_MAX ? data->percent[which] : -1;
151}
152
153static inline const char *percent_type_str(unsigned int type)
154{
155 static const char *str[PERCENT_MAX] = {
156 "local hits",
157 "global hits",
158 "local period",
159 "global period",
160 };
161
162 if (WARN_ON(type >= PERCENT_MAX))
163 return "N/A";
164
165 return str[type];
166}
167
137static inline struct disasm_line *disasm_line(struct annotation_line *al) 168static inline struct disasm_line *disasm_line(struct annotation_line *al)
138{ 169{
139 return al ? container_of(al, struct disasm_line, al) : NULL; 170 return al ? container_of(al, struct disasm_line, al) : NULL;
@@ -169,22 +200,15 @@ struct annotation_write_ops {
169 void (*write_graph)(void *obj, int graph); 200 void (*write_graph)(void *obj, int graph);
170}; 201};
171 202
172double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes);
173void annotation_line__write(struct annotation_line *al, struct annotation *notes, 203void annotation_line__write(struct annotation_line *al, struct annotation *notes,
174 struct annotation_write_ops *ops); 204 struct annotation_write_ops *ops,
205 struct annotation_options *opts);
175 206
176int __annotation__scnprintf_samples_period(struct annotation *notes, 207int __annotation__scnprintf_samples_period(struct annotation *notes,
177 char *bf, size_t size, 208 char *bf, size_t size,
178 struct perf_evsel *evsel, 209 struct perf_evsel *evsel,
179 bool show_freq); 210 bool show_freq);
180 211
181static inline int annotation__scnprintf_samples_period(struct annotation *notes,
182 char *bf, size_t size,
183 struct perf_evsel *evsel)
184{
185 return __annotation__scnprintf_samples_period(notes, bf, size, evsel, true);
186}
187
188int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); 212int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
189size_t disasm__fprintf(struct list_head *head, FILE *fp); 213size_t disasm__fprintf(struct list_head *head, FILE *fp);
190void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel); 214void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel);
@@ -340,12 +364,12 @@ int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
340int symbol__annotate_printf(struct symbol *sym, struct map *map, 364int symbol__annotate_printf(struct symbol *sym, struct map *map,
341 struct perf_evsel *evsel, 365 struct perf_evsel *evsel,
342 struct annotation_options *options); 366 struct annotation_options *options);
343int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp);
344void symbol__annotate_zero_histogram(struct symbol *sym, int evidx); 367void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
345void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); 368void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
346void annotated_source__purge(struct annotated_source *as); 369void annotated_source__purge(struct annotated_source *as);
347 370
348int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel); 371int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
372 struct annotation_options *opts);
349 373
350bool ui__has_annotation(void); 374bool ui__has_annotation(void);
351 375
@@ -373,4 +397,6 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
373 397
374void annotation_config__init(void); 398void annotation_config__init(void);
375 399
400int annotate_parse_percent_type(const struct option *opt, const char *_str,
401 int unset);
376#endif /* __PERF_ANNOTATE_H */ 402#endif /* __PERF_ANNOTATE_H */
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index d056447520a2..db1511359c5e 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -56,6 +56,7 @@
56#include "intel-pt.h" 56#include "intel-pt.h"
57#include "intel-bts.h" 57#include "intel-bts.h"
58#include "arm-spe.h" 58#include "arm-spe.h"
59#include "s390-cpumsf.h"
59 60
60#include "sane_ctype.h" 61#include "sane_ctype.h"
61#include "symbol/kallsyms.h" 62#include "symbol/kallsyms.h"
@@ -202,6 +203,9 @@ static int auxtrace_queues__grow(struct auxtrace_queues *queues,
202 for (i = 0; i < queues->nr_queues; i++) { 203 for (i = 0; i < queues->nr_queues; i++) {
203 list_splice_tail(&queues->queue_array[i].head, 204 list_splice_tail(&queues->queue_array[i].head,
204 &queue_array[i].head); 205 &queue_array[i].head);
206 queue_array[i].tid = queues->queue_array[i].tid;
207 queue_array[i].cpu = queues->queue_array[i].cpu;
208 queue_array[i].set = queues->queue_array[i].set;
205 queue_array[i].priv = queues->queue_array[i].priv; 209 queue_array[i].priv = queues->queue_array[i].priv;
206 } 210 }
207 211
@@ -920,6 +924,8 @@ int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused,
920 return arm_spe_process_auxtrace_info(event, session); 924 return arm_spe_process_auxtrace_info(event, session);
921 case PERF_AUXTRACE_CS_ETM: 925 case PERF_AUXTRACE_CS_ETM:
922 return cs_etm__process_auxtrace_info(event, session); 926 return cs_etm__process_auxtrace_info(event, session);
927 case PERF_AUXTRACE_S390_CPUMSF:
928 return s390_cpumsf_process_auxtrace_info(event, session);
923 case PERF_AUXTRACE_UNKNOWN: 929 case PERF_AUXTRACE_UNKNOWN:
924 default: 930 default:
925 return -EINVAL; 931 return -EINVAL;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index e731f55da072..71fc3bd74299 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -44,6 +44,7 @@ enum auxtrace_type {
44 PERF_AUXTRACE_INTEL_BTS, 44 PERF_AUXTRACE_INTEL_BTS,
45 PERF_AUXTRACE_CS_ETM, 45 PERF_AUXTRACE_CS_ETM,
46 PERF_AUXTRACE_ARM_SPE, 46 PERF_AUXTRACE_ARM_SPE,
47 PERF_AUXTRACE_S390_CPUMSF,
47}; 48};
48 49
49enum itrace_period_type { 50enum itrace_period_type {
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 3d02ae38ec56..47aac41349a2 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1529,13 +1529,13 @@ int bpf__apply_obj_config(void)
1529 bpf_object__for_each_safe(obj, objtmp) \ 1529 bpf_object__for_each_safe(obj, objtmp) \
1530 bpf_map__for_each(pos, obj) 1530 bpf_map__for_each(pos, obj)
1531 1531
1532#define bpf__for_each_stdout_map(pos, obj, objtmp) \ 1532#define bpf__for_each_map_named(pos, obj, objtmp, name) \
1533 bpf__for_each_map(pos, obj, objtmp) \ 1533 bpf__for_each_map(pos, obj, objtmp) \
1534 if (bpf_map__name(pos) && \ 1534 if (bpf_map__name(pos) && \
1535 (strcmp("__bpf_stdout__", \ 1535 (strcmp(name, \
1536 bpf_map__name(pos)) == 0)) 1536 bpf_map__name(pos)) == 0))
1537 1537
1538int bpf__setup_stdout(struct perf_evlist *evlist) 1538struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const char *name)
1539{ 1539{
1540 struct bpf_map_priv *tmpl_priv = NULL; 1540 struct bpf_map_priv *tmpl_priv = NULL;
1541 struct bpf_object *obj, *tmp; 1541 struct bpf_object *obj, *tmp;
@@ -1544,11 +1544,11 @@ int bpf__setup_stdout(struct perf_evlist *evlist)
1544 int err; 1544 int err;
1545 bool need_init = false; 1545 bool need_init = false;
1546 1546
1547 bpf__for_each_stdout_map(map, obj, tmp) { 1547 bpf__for_each_map_named(map, obj, tmp, name) {
1548 struct bpf_map_priv *priv = bpf_map__priv(map); 1548 struct bpf_map_priv *priv = bpf_map__priv(map);
1549 1549
1550 if (IS_ERR(priv)) 1550 if (IS_ERR(priv))
1551 return -BPF_LOADER_ERRNO__INTERNAL; 1551 return ERR_PTR(-BPF_LOADER_ERRNO__INTERNAL);
1552 1552
1553 /* 1553 /*
1554 * No need to check map type: type should have been 1554 * No need to check map type: type should have been
@@ -1561,49 +1561,61 @@ int bpf__setup_stdout(struct perf_evlist *evlist)
1561 } 1561 }
1562 1562
1563 if (!need_init) 1563 if (!need_init)
1564 return 0; 1564 return NULL;
1565 1565
1566 if (!tmpl_priv) { 1566 if (!tmpl_priv) {
1567 err = parse_events(evlist, "bpf-output/no-inherit=1,name=__bpf_stdout__/", 1567 char *event_definition = NULL;
1568 NULL); 1568
1569 if (asprintf(&event_definition, "bpf-output/no-inherit=1,name=%s/", name) < 0)
1570 return ERR_PTR(-ENOMEM);
1571
1572 err = parse_events(evlist, event_definition, NULL);
1573 free(event_definition);
1574
1569 if (err) { 1575 if (err) {
1570 pr_debug("ERROR: failed to create bpf-output event\n"); 1576 pr_debug("ERROR: failed to create the \"%s\" bpf-output event\n", name);
1571 return -err; 1577 return ERR_PTR(-err);
1572 } 1578 }
1573 1579
1574 evsel = perf_evlist__last(evlist); 1580 evsel = perf_evlist__last(evlist);
1575 } 1581 }
1576 1582
1577 bpf__for_each_stdout_map(map, obj, tmp) { 1583 bpf__for_each_map_named(map, obj, tmp, name) {
1578 struct bpf_map_priv *priv = bpf_map__priv(map); 1584 struct bpf_map_priv *priv = bpf_map__priv(map);
1579 1585
1580 if (IS_ERR(priv)) 1586 if (IS_ERR(priv))
1581 return -BPF_LOADER_ERRNO__INTERNAL; 1587 return ERR_PTR(-BPF_LOADER_ERRNO__INTERNAL);
1582 if (priv) 1588 if (priv)
1583 continue; 1589 continue;
1584 1590
1585 if (tmpl_priv) { 1591 if (tmpl_priv) {
1586 priv = bpf_map_priv__clone(tmpl_priv); 1592 priv = bpf_map_priv__clone(tmpl_priv);
1587 if (!priv) 1593 if (!priv)
1588 return -ENOMEM; 1594 return ERR_PTR(-ENOMEM);
1589 1595
1590 err = bpf_map__set_priv(map, priv, bpf_map_priv__clear); 1596 err = bpf_map__set_priv(map, priv, bpf_map_priv__clear);
1591 if (err) { 1597 if (err) {
1592 bpf_map_priv__clear(map, priv); 1598 bpf_map_priv__clear(map, priv);
1593 return err; 1599 return ERR_PTR(err);
1594 } 1600 }
1595 } else if (evsel) { 1601 } else if (evsel) {
1596 struct bpf_map_op *op; 1602 struct bpf_map_op *op;
1597 1603
1598 op = bpf_map__add_newop(map, NULL); 1604 op = bpf_map__add_newop(map, NULL);
1599 if (IS_ERR(op)) 1605 if (IS_ERR(op))
1600 return PTR_ERR(op); 1606 return ERR_PTR(PTR_ERR(op));
1601 op->op_type = BPF_MAP_OP_SET_EVSEL; 1607 op->op_type = BPF_MAP_OP_SET_EVSEL;
1602 op->v.evsel = evsel; 1608 op->v.evsel = evsel;
1603 } 1609 }
1604 } 1610 }
1605 1611
1606 return 0; 1612 return evsel;
1613}
1614
1615int bpf__setup_stdout(struct perf_evlist *evlist)
1616{
1617 struct perf_evsel *evsel = bpf__setup_output_event(evlist, "__bpf_stdout__");
1618 return IS_ERR(evsel) ? PTR_ERR(evsel) : 0;
1607} 1619}
1608 1620
1609#define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START) 1621#define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START)
@@ -1780,8 +1792,8 @@ int bpf__strerror_apply_obj_config(int err, char *buf, size_t size)
1780 return 0; 1792 return 0;
1781} 1793}
1782 1794
1783int bpf__strerror_setup_stdout(struct perf_evlist *evlist __maybe_unused, 1795int bpf__strerror_setup_output_event(struct perf_evlist *evlist __maybe_unused,
1784 int err, char *buf, size_t size) 1796 int err, char *buf, size_t size)
1785{ 1797{
1786 bpf__strerror_head(err, buf, size); 1798 bpf__strerror_head(err, buf, size);
1787 bpf__strerror_end(buf, size); 1799 bpf__strerror_end(buf, size);
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 5d3aefd6fae7..62d245a90e1d 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -43,6 +43,7 @@ enum bpf_loader_errno {
43 __BPF_LOADER_ERRNO__END, 43 __BPF_LOADER_ERRNO__END,
44}; 44};
45 45
46struct perf_evsel;
46struct bpf_object; 47struct bpf_object;
47struct parse_events_term; 48struct parse_events_term;
48#define PERF_BPF_PROBE_GROUP "perf_bpf_probe" 49#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
@@ -82,9 +83,8 @@ int bpf__apply_obj_config(void);
82int bpf__strerror_apply_obj_config(int err, char *buf, size_t size); 83int bpf__strerror_apply_obj_config(int err, char *buf, size_t size);
83 84
84int bpf__setup_stdout(struct perf_evlist *evlist); 85int bpf__setup_stdout(struct perf_evlist *evlist);
85int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err, 86struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const char *name);
86 char *buf, size_t size); 87int bpf__strerror_setup_output_event(struct perf_evlist *evlist, int err, char *buf, size_t size);
87
88#else 88#else
89#include <errno.h> 89#include <errno.h>
90 90
@@ -138,6 +138,12 @@ bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused)
138 return 0; 138 return 0;
139} 139}
140 140
141static inline struct perf_evsel *
142bpf__setup_output_event(struct perf_evlist *evlist __maybe_unused, const char *name __maybe_unused)
143{
144 return NULL;
145}
146
141static inline int 147static inline int
142__bpf_strerror(char *buf, size_t size) 148__bpf_strerror(char *buf, size_t size)
143{ 149{
@@ -193,11 +199,16 @@ bpf__strerror_apply_obj_config(int err __maybe_unused,
193} 199}
194 200
195static inline int 201static inline int
196bpf__strerror_setup_stdout(struct perf_evlist *evlist __maybe_unused, 202bpf__strerror_setup_output_event(struct perf_evlist *evlist __maybe_unused,
197 int err __maybe_unused, char *buf, 203 int err __maybe_unused, char *buf, size_t size)
198 size_t size)
199{ 204{
200 return __bpf_strerror(buf, size); 205 return __bpf_strerror(buf, size);
201} 206}
207
202#endif 208#endif
209
210static inline int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err, char *buf, size_t size)
211{
212 return bpf__strerror_setup_output_event(evlist, err, buf, size);
213}
203#endif 214#endif
diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h
index ecca688a25fb..892e92e7e7fc 100644
--- a/tools/perf/util/compress.h
+++ b/tools/perf/util/compress.h
@@ -4,10 +4,12 @@
4 4
5#ifdef HAVE_ZLIB_SUPPORT 5#ifdef HAVE_ZLIB_SUPPORT
6int gzip_decompress_to_file(const char *input, int output_fd); 6int gzip_decompress_to_file(const char *input, int output_fd);
7bool gzip_is_compressed(const char *input);
7#endif 8#endif
8 9
9#ifdef HAVE_LZMA_SUPPORT 10#ifdef HAVE_LZMA_SUPPORT
10int lzma_decompress_to_file(const char *input, int output_fd); 11int lzma_decompress_to_file(const char *input, int output_fd);
12bool lzma_is_compressed(const char *input);
11#endif 13#endif
12 14
13#endif /* PERF_COMPRESS_H */ 15#endif /* PERF_COMPRESS_H */
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 5744c12641a5..abd38abf1d91 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -310,8 +310,8 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
310 if (flags & FIELD_IS_DYNAMIC) { 310 if (flags & FIELD_IS_DYNAMIC) {
311 unsigned long long tmp_val; 311 unsigned long long tmp_val;
312 312
313 tmp_val = pevent_read_number(fmtf->event->pevent, 313 tmp_val = tep_read_number(fmtf->event->pevent,
314 data + offset, len); 314 data + offset, len);
315 offset = tmp_val; 315 offset = tmp_val;
316 len = offset >> 16; 316 len = offset >> 16;
317 offset &= 0xffff; 317 offset &= 0xffff;
@@ -353,7 +353,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
353 else { 353 else {
354 unsigned long long value_int; 354 unsigned long long value_int;
355 355
356 value_int = pevent_read_number( 356 value_int = tep_read_number(
357 fmtf->event->pevent, 357 fmtf->event->pevent,
358 data + offset + i * len, len); 358 data + offset + i * len, len);
359 359
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 51cf82cf1882..bbed90e5d9bb 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -189,28 +189,34 @@ int dso__read_binary_type_filename(const struct dso *dso,
189 return ret; 189 return ret;
190} 190}
191 191
192enum {
193 COMP_ID__NONE = 0,
194};
195
192static const struct { 196static const struct {
193 const char *fmt; 197 const char *fmt;
194 int (*decompress)(const char *input, int output); 198 int (*decompress)(const char *input, int output);
199 bool (*is_compressed)(const char *input);
195} compressions[] = { 200} compressions[] = {
201 [COMP_ID__NONE] = { .fmt = NULL, },
196#ifdef HAVE_ZLIB_SUPPORT 202#ifdef HAVE_ZLIB_SUPPORT
197 { "gz", gzip_decompress_to_file }, 203 { "gz", gzip_decompress_to_file, gzip_is_compressed },
198#endif 204#endif
199#ifdef HAVE_LZMA_SUPPORT 205#ifdef HAVE_LZMA_SUPPORT
200 { "xz", lzma_decompress_to_file }, 206 { "xz", lzma_decompress_to_file, lzma_is_compressed },
201#endif 207#endif
202 { NULL, NULL }, 208 { NULL, NULL, NULL },
203}; 209};
204 210
205bool is_supported_compression(const char *ext) 211static int is_supported_compression(const char *ext)
206{ 212{
207 unsigned i; 213 unsigned i;
208 214
209 for (i = 0; compressions[i].fmt; i++) { 215 for (i = 1; compressions[i].fmt; i++) {
210 if (!strcmp(ext, compressions[i].fmt)) 216 if (!strcmp(ext, compressions[i].fmt))
211 return true; 217 return i;
212 } 218 }
213 return false; 219 return COMP_ID__NONE;
214} 220}
215 221
216bool is_kernel_module(const char *pathname, int cpumode) 222bool is_kernel_module(const char *pathname, int cpumode)
@@ -239,80 +245,73 @@ bool is_kernel_module(const char *pathname, int cpumode)
239 return m.kmod; 245 return m.kmod;
240} 246}
241 247
242bool decompress_to_file(const char *ext, const char *filename, int output_fd)
243{
244 unsigned i;
245
246 for (i = 0; compressions[i].fmt; i++) {
247 if (!strcmp(ext, compressions[i].fmt))
248 return !compressions[i].decompress(filename,
249 output_fd);
250 }
251 return false;
252}
253
254bool dso__needs_decompress(struct dso *dso) 248bool dso__needs_decompress(struct dso *dso)
255{ 249{
256 return dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP || 250 return dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
257 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP; 251 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
258} 252}
259 253
260static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf) 254static int decompress_kmodule(struct dso *dso, const char *name,
255 char *pathname, size_t len)
261{ 256{
257 char tmpbuf[] = KMOD_DECOMP_NAME;
262 int fd = -1; 258 int fd = -1;
263 struct kmod_path m;
264 259
265 if (!dso__needs_decompress(dso)) 260 if (!dso__needs_decompress(dso))
266 return -1; 261 return -1;
267 262
268 if (kmod_path__parse_ext(&m, dso->long_name)) 263 if (dso->comp == COMP_ID__NONE)
269 return -1; 264 return -1;
270 265
271 if (!m.comp) 266 /*
272 goto out; 267 * We have proper compression id for DSO and yet the file
268 * behind the 'name' can still be plain uncompressed object.
269 *
270 * The reason is behind the logic we open the DSO object files,
271 * when we try all possible 'debug' objects until we find the
272 * data. So even if the DSO is represented by 'krava.xz' module,
273 * we can end up here opening ~/.debug/....23432432/debug' file
274 * which is not compressed.
275 *
276 * To keep this transparent, we detect this and return the file
277 * descriptor to the uncompressed file.
278 */
279 if (!compressions[dso->comp].is_compressed(name))
280 return open(name, O_RDONLY);
273 281
274 fd = mkstemp(tmpbuf); 282 fd = mkstemp(tmpbuf);
275 if (fd < 0) { 283 if (fd < 0) {
276 dso->load_errno = errno; 284 dso->load_errno = errno;
277 goto out; 285 return -1;
278 } 286 }
279 287
280 if (!decompress_to_file(m.ext, name, fd)) { 288 if (compressions[dso->comp].decompress(name, fd)) {
281 dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE; 289 dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
282 close(fd); 290 close(fd);
283 fd = -1; 291 fd = -1;
284 } 292 }
285 293
286out: 294 if (!pathname || (fd < 0))
287 free(m.ext); 295 unlink(tmpbuf);
296
297 if (pathname && (fd >= 0))
298 strncpy(pathname, tmpbuf, len);
299
288 return fd; 300 return fd;
289} 301}
290 302
291int dso__decompress_kmodule_fd(struct dso *dso, const char *name) 303int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
292{ 304{
293 char tmpbuf[] = KMOD_DECOMP_NAME; 305 return decompress_kmodule(dso, name, NULL, 0);
294 int fd;
295
296 fd = decompress_kmodule(dso, name, tmpbuf);
297 unlink(tmpbuf);
298 return fd;
299} 306}
300 307
301int dso__decompress_kmodule_path(struct dso *dso, const char *name, 308int dso__decompress_kmodule_path(struct dso *dso, const char *name,
302 char *pathname, size_t len) 309 char *pathname, size_t len)
303{ 310{
304 char tmpbuf[] = KMOD_DECOMP_NAME; 311 int fd = decompress_kmodule(dso, name, pathname, len);
305 int fd;
306 312
307 fd = decompress_kmodule(dso, name, tmpbuf);
308 if (fd < 0) {
309 unlink(tmpbuf);
310 return -1;
311 }
312
313 strncpy(pathname, tmpbuf, len);
314 close(fd); 313 close(fd);
315 return 0; 314 return fd >= 0 ? 0 : -1;
316} 315}
317 316
318/* 317/*
@@ -332,7 +331,7 @@ int dso__decompress_kmodule_path(struct dso *dso, const char *name,
332 * Returns 0 if there's no strdup error, -ENOMEM otherwise. 331 * Returns 0 if there's no strdup error, -ENOMEM otherwise.
333 */ 332 */
334int __kmod_path__parse(struct kmod_path *m, const char *path, 333int __kmod_path__parse(struct kmod_path *m, const char *path,
335 bool alloc_name, bool alloc_ext) 334 bool alloc_name)
336{ 335{
337 const char *name = strrchr(path, '/'); 336 const char *name = strrchr(path, '/');
338 const char *ext = strrchr(path, '.'); 337 const char *ext = strrchr(path, '.');
@@ -372,10 +371,9 @@ int __kmod_path__parse(struct kmod_path *m, const char *path,
372 return 0; 371 return 0;
373 } 372 }
374 373
375 if (is_supported_compression(ext + 1)) { 374 m->comp = is_supported_compression(ext + 1);
376 m->comp = true; 375 if (m->comp > COMP_ID__NONE)
377 ext -= 3; 376 ext -= 3;
378 }
379 377
380 /* Check .ko extension only if there's enough name left. */ 378 /* Check .ko extension only if there's enough name left. */
381 if (ext > name) 379 if (ext > name)
@@ -393,14 +391,6 @@ int __kmod_path__parse(struct kmod_path *m, const char *path,
393 strxfrchar(m->name, '-', '_'); 391 strxfrchar(m->name, '-', '_');
394 } 392 }
395 393
396 if (alloc_ext && m->comp) {
397 m->ext = strdup(ext + 4);
398 if (!m->ext) {
399 free((void *) m->name);
400 return -ENOMEM;
401 }
402 }
403
404 return 0; 394 return 0;
405} 395}
406 396
@@ -413,8 +403,10 @@ void dso__set_module_info(struct dso *dso, struct kmod_path *m,
413 dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE; 403 dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
414 404
415 /* _KMODULE_COMP should be next to _KMODULE */ 405 /* _KMODULE_COMP should be next to _KMODULE */
416 if (m->kmod && m->comp) 406 if (m->kmod && m->comp) {
417 dso->symtab_type++; 407 dso->symtab_type++;
408 dso->comp = m->comp;
409 }
418 410
419 dso__set_short_name(dso, strdup(m->name), true); 411 dso__set_short_name(dso, strdup(m->name), true);
420} 412}
@@ -468,6 +460,7 @@ static int __open_dso(struct dso *dso, struct machine *machine)
468 int fd = -EINVAL; 460 int fd = -EINVAL;
469 char *root_dir = (char *)""; 461 char *root_dir = (char *)"";
470 char *name = malloc(PATH_MAX); 462 char *name = malloc(PATH_MAX);
463 bool decomp = false;
471 464
472 if (!name) 465 if (!name)
473 return -ENOMEM; 466 return -ENOMEM;
@@ -491,12 +484,13 @@ static int __open_dso(struct dso *dso, struct machine *machine)
491 goto out; 484 goto out;
492 } 485 }
493 486
487 decomp = true;
494 strcpy(name, newpath); 488 strcpy(name, newpath);
495 } 489 }
496 490
497 fd = do_open(name); 491 fd = do_open(name);
498 492
499 if (dso__needs_decompress(dso)) 493 if (decomp)
500 unlink(name); 494 unlink(name);
501 495
502out: 496out:
@@ -1218,6 +1212,7 @@ struct dso *dso__new(const char *name)
1218 dso->a2l_fails = 1; 1212 dso->a2l_fails = 1;
1219 dso->kernel = DSO_TYPE_USER; 1213 dso->kernel = DSO_TYPE_USER;
1220 dso->needs_swap = DSO_SWAP__UNSET; 1214 dso->needs_swap = DSO_SWAP__UNSET;
1215 dso->comp = COMP_ID__NONE;
1221 RB_CLEAR_NODE(&dso->rb_node); 1216 RB_CLEAR_NODE(&dso->rb_node);
1222 dso->root = NULL; 1217 dso->root = NULL;
1223 INIT_LIST_HEAD(&dso->node); 1218 INIT_LIST_HEAD(&dso->node);
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index ef69de2e69ea..c5380500bed4 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -175,6 +175,7 @@ struct dso {
175 u16 short_name_len; 175 u16 short_name_len;
176 void *dwfl; /* DWARF debug info */ 176 void *dwfl; /* DWARF debug info */
177 struct auxtrace_cache *auxtrace_cache; 177 struct auxtrace_cache *auxtrace_cache;
178 int comp;
178 179
179 /* dso data file */ 180 /* dso data file */
180 struct { 181 struct {
@@ -250,9 +251,7 @@ int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
250char dso__symtab_origin(const struct dso *dso); 251char dso__symtab_origin(const struct dso *dso);
251int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type, 252int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
252 char *root_dir, char *filename, size_t size); 253 char *root_dir, char *filename, size_t size);
253bool is_supported_compression(const char *ext);
254bool is_kernel_module(const char *pathname, int cpumode); 254bool is_kernel_module(const char *pathname, int cpumode);
255bool decompress_to_file(const char *ext, const char *filename, int output_fd);
256bool dso__needs_decompress(struct dso *dso); 255bool dso__needs_decompress(struct dso *dso);
257int dso__decompress_kmodule_fd(struct dso *dso, const char *name); 256int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
258int dso__decompress_kmodule_path(struct dso *dso, const char *name, 257int dso__decompress_kmodule_path(struct dso *dso, const char *name,
@@ -263,17 +262,15 @@ int dso__decompress_kmodule_path(struct dso *dso, const char *name,
263 262
264struct kmod_path { 263struct kmod_path {
265 char *name; 264 char *name;
266 char *ext; 265 int comp;
267 bool comp;
268 bool kmod; 266 bool kmod;
269}; 267};
270 268
271int __kmod_path__parse(struct kmod_path *m, const char *path, 269int __kmod_path__parse(struct kmod_path *m, const char *path,
272 bool alloc_name, bool alloc_ext); 270 bool alloc_name);
273 271
274#define kmod_path__parse(__m, __p) __kmod_path__parse(__m, __p, false, false) 272#define kmod_path__parse(__m, __p) __kmod_path__parse(__m, __p, false)
275#define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true , false) 273#define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true)
276#define kmod_path__parse_ext(__m, __p) __kmod_path__parse(__m, __p, false, true)
277 274
278void dso__set_module_info(struct dso *dso, struct kmod_path *m, 275void dso__set_module_info(struct dso *dso, struct kmod_path *m,
279 struct machine *machine); 276 struct machine *machine);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 0c8ecf0c78a4..0cd42150f712 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -541,10 +541,17 @@ static int __event__synthesize_thread(union perf_event *comm_event,
541 tgid, process, machine) < 0) 541 tgid, process, machine) < 0)
542 return -1; 542 return -1;
543 543
544 /*
545 * send mmap only for thread group leader
546 * see thread__init_map_groups
547 */
548 if (pid == tgid &&
549 perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
550 process, machine, mmap_data,
551 proc_map_timeout))
552 return -1;
544 553
545 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, 554 return 0;
546 process, machine, mmap_data,
547 proc_map_timeout);
548 } 555 }
549 556
550 if (machine__is_default_guest(machine)) 557 if (machine__is_default_guest(machine))
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index e7a4b31a84fb..be440df29615 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -803,7 +803,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
803 if (*output == -1) { 803 if (*output == -1) {
804 *output = fd; 804 *output = fd;
805 805
806 if (perf_mmap__mmap(&maps[idx], mp, *output) < 0) 806 if (perf_mmap__mmap(&maps[idx], mp, *output, evlist_cpu) < 0)
807 return -1; 807 return -1;
808 } else { 808 } else {
809 if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0) 809 if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ddf84b941abf..c980bbff6353 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2683,7 +2683,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
2683 2683
2684struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name) 2684struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name)
2685{ 2685{
2686 return pevent_find_field(evsel->tp_format, name); 2686 return tep_find_field(evsel->tp_format, name);
2687} 2687}
2688 2688
2689void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample, 2689void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 973c03167947..163c960614d3 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -452,11 +452,18 @@ static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
452 return evsel->idx - evsel->leader->idx; 452 return evsel->idx - evsel->leader->idx;
453} 453}
454 454
455/* Iterates group WITHOUT the leader. */
455#define for_each_group_member(_evsel, _leader) \ 456#define for_each_group_member(_evsel, _leader) \
456for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \ 457for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \
457 (_evsel) && (_evsel)->leader == (_leader); \ 458 (_evsel) && (_evsel)->leader == (_leader); \
458 (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node)) 459 (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
459 460
461/* Iterates group WITH the leader. */
462#define for_each_group_evsel(_evsel, _leader) \
463for ((_evsel) = _leader; \
464 (_evsel) && (_evsel)->leader == (_leader); \
465 (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
466
460static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evsel) 467static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evsel)
461{ 468{
462 return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK; 469 return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 5af58aac91ad..3cadc252dd89 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -279,8 +279,6 @@ static int do_read_bitmap(struct feat_fd *ff, unsigned long **pset, u64 *psize)
279 if (!set) 279 if (!set)
280 return -ENOMEM; 280 return -ENOMEM;
281 281
282 bitmap_zero(set, size);
283
284 p = (u64 *) set; 282 p = (u64 *) set;
285 283
286 for (i = 0; (u64) i < BITS_TO_U64(size); i++) { 284 for (i = 0; (u64) i < BITS_TO_U64(size); i++) {
@@ -1285,7 +1283,6 @@ static int memory_node__read(struct memory_node *n, unsigned long idx)
1285 return -ENOMEM; 1283 return -ENOMEM;
1286 } 1284 }
1287 1285
1288 bitmap_zero(n->set, size);
1289 n->node = idx; 1286 n->node = idx;
1290 n->size = size; 1287 n->size = size;
1291 1288
@@ -3207,7 +3204,7 @@ static int read_attr(int fd, struct perf_header *ph,
3207} 3204}
3208 3205
3209static int perf_evsel__prepare_tracepoint_event(struct perf_evsel *evsel, 3206static int perf_evsel__prepare_tracepoint_event(struct perf_evsel *evsel,
3210 struct pevent *pevent) 3207 struct tep_handle *pevent)
3211{ 3208{
3212 struct event_format *event; 3209 struct event_format *event;
3213 char bf[128]; 3210 char bf[128];
@@ -3221,7 +3218,7 @@ static int perf_evsel__prepare_tracepoint_event(struct perf_evsel *evsel,
3221 return -1; 3218 return -1;
3222 } 3219 }
3223 3220
3224 event = pevent_find_event(pevent, evsel->attr.config); 3221 event = tep_find_event(pevent, evsel->attr.config);
3225 if (event == NULL) { 3222 if (event == NULL) {
3226 pr_debug("cannot find event format for %d\n", (int)evsel->attr.config); 3223 pr_debug("cannot find event format for %d\n", (int)evsel->attr.config);
3227 return -1; 3224 return -1;
@@ -3239,7 +3236,7 @@ static int perf_evsel__prepare_tracepoint_event(struct perf_evsel *evsel,
3239} 3236}
3240 3237
3241static int perf_evlist__prepare_tracepoint_events(struct perf_evlist *evlist, 3238static int perf_evlist__prepare_tracepoint_events(struct perf_evlist *evlist,
3242 struct pevent *pevent) 3239 struct tep_handle *pevent)
3243{ 3240{
3244 struct perf_evsel *pos; 3241 struct perf_evsel *pos;
3245 3242
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 5e94857dfca2..19262f98cd4e 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -22,12 +22,14 @@
22 "$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \ 22 "$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \
23 "-Wno-unused-value -Wno-pointer-sign " \ 23 "-Wno-unused-value -Wno-pointer-sign " \
24 "-working-directory $WORKING_DIR " \ 24 "-working-directory $WORKING_DIR " \
25 "-c \"$CLANG_SOURCE\" -target bpf -O2 -o -" 25 "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
26 26
27struct llvm_param llvm_param = { 27struct llvm_param llvm_param = {
28 .clang_path = "clang", 28 .clang_path = "clang",
29 .llc_path = "llc",
29 .clang_bpf_cmd_template = CLANG_BPF_CMD_DEFAULT_TEMPLATE, 30 .clang_bpf_cmd_template = CLANG_BPF_CMD_DEFAULT_TEMPLATE,
30 .clang_opt = NULL, 31 .clang_opt = NULL,
32 .opts = NULL,
31 .kbuild_dir = NULL, 33 .kbuild_dir = NULL,
32 .kbuild_opts = NULL, 34 .kbuild_opts = NULL,
33 .user_set_param = false, 35 .user_set_param = false,
@@ -51,6 +53,8 @@ int perf_llvm_config(const char *var, const char *value)
51 llvm_param.kbuild_opts = strdup(value); 53 llvm_param.kbuild_opts = strdup(value);
52 else if (!strcmp(var, "dump-obj")) 54 else if (!strcmp(var, "dump-obj"))
53 llvm_param.dump_obj = !!perf_config_bool(var, value); 55 llvm_param.dump_obj = !!perf_config_bool(var, value);
56 else if (!strcmp(var, "opts"))
57 llvm_param.opts = strdup(value);
54 else { 58 else {
55 pr_debug("Invalid LLVM config option: %s\n", value); 59 pr_debug("Invalid LLVM config option: %s\n", value);
56 return -1; 60 return -1;
@@ -430,11 +434,13 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
430 unsigned int kernel_version; 434 unsigned int kernel_version;
431 char linux_version_code_str[64]; 435 char linux_version_code_str[64];
432 const char *clang_opt = llvm_param.clang_opt; 436 const char *clang_opt = llvm_param.clang_opt;
433 char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64]; 437 char clang_path[PATH_MAX], llc_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64];
434 char serr[STRERR_BUFSIZE]; 438 char serr[STRERR_BUFSIZE];
435 char *kbuild_dir = NULL, *kbuild_include_opts = NULL, 439 char *kbuild_dir = NULL, *kbuild_include_opts = NULL,
436 *perf_bpf_include_opts = NULL; 440 *perf_bpf_include_opts = NULL;
437 const char *template = llvm_param.clang_bpf_cmd_template; 441 const char *template = llvm_param.clang_bpf_cmd_template;
442 char *pipe_template = NULL;
443 const char *opts = llvm_param.opts;
438 char *command_echo = NULL, *command_out; 444 char *command_echo = NULL, *command_out;
439 char *perf_include_dir = system_path(PERF_INCLUDE_DIR); 445 char *perf_include_dir = system_path(PERF_INCLUDE_DIR);
440 446
@@ -484,6 +490,26 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
484 force_set_env("PERF_BPF_INC_OPTIONS", perf_bpf_include_opts); 490 force_set_env("PERF_BPF_INC_OPTIONS", perf_bpf_include_opts);
485 force_set_env("WORKING_DIR", kbuild_dir ? : "."); 491 force_set_env("WORKING_DIR", kbuild_dir ? : ".");
486 492
493 if (opts) {
494 err = search_program(llvm_param.llc_path, "llc", llc_path);
495 if (err) {
496 pr_err("ERROR:\tunable to find llc.\n"
497 "Hint:\tTry to install latest clang/llvm to support BPF. Check your $PATH\n"
498 " \tand 'llc-path' option in [llvm] section of ~/.perfconfig.\n");
499 version_notice();
500 goto errout;
501 }
502
503 if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
504 template, llc_path, opts) < 0) {
505 pr_err("ERROR:\tnot enough memory to setup command line\n");
506 goto errout;
507 }
508
509 template = pipe_template;
510
511 }
512
487 /* 513 /*
488 * Since we may reset clang's working dir, path of source file 514 * Since we may reset clang's working dir, path of source file
489 * should be transferred into absolute path, except we want 515 * should be transferred into absolute path, except we want
@@ -535,6 +561,7 @@ errout:
535 free(obj_buf); 561 free(obj_buf);
536 free(perf_bpf_include_opts); 562 free(perf_bpf_include_opts);
537 free(perf_include_dir); 563 free(perf_include_dir);
564 free(pipe_template);
538 if (p_obj_buf) 565 if (p_obj_buf)
539 *p_obj_buf = NULL; 566 *p_obj_buf = NULL;
540 if (p_obj_buf_sz) 567 if (p_obj_buf_sz)
diff --git a/tools/perf/util/llvm-utils.h b/tools/perf/util/llvm-utils.h
index d3ad8deb5db4..bf3f3f4c4fe2 100644
--- a/tools/perf/util/llvm-utils.h
+++ b/tools/perf/util/llvm-utils.h
@@ -11,6 +11,8 @@
11struct llvm_param { 11struct llvm_param {
12 /* Path of clang executable */ 12 /* Path of clang executable */
13 const char *clang_path; 13 const char *clang_path;
14 /* Path of llc executable */
15 const char *llc_path;
14 /* 16 /*
15 * Template of clang bpf compiling. 5 env variables 17 * Template of clang bpf compiling. 5 env variables
16 * can be used: 18 * can be used:
@@ -23,6 +25,13 @@ struct llvm_param {
23 const char *clang_bpf_cmd_template; 25 const char *clang_bpf_cmd_template;
24 /* Will be filled in $CLANG_OPTIONS */ 26 /* Will be filled in $CLANG_OPTIONS */
25 const char *clang_opt; 27 const char *clang_opt;
28 /*
29 * If present it'll add -emit-llvm to $CLANG_OPTIONS to pipe
30 * the clang output to llc, useful for new llvm options not
31 * yet selectable via 'clang -mllvm option', such as -mattr=dwarfris
32 * in clang 6.0/llvm 7
33 */
34 const char *opts;
26 /* Where to find kbuild system */ 35 /* Where to find kbuild system */
27 const char *kbuild_dir; 36 const char *kbuild_dir;
28 /* 37 /*
diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c
index 07498eaddc08..b1dd29a9d915 100644
--- a/tools/perf/util/lzma.c
+++ b/tools/perf/util/lzma.c
@@ -3,9 +3,13 @@
3#include <lzma.h> 3#include <lzma.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <linux/compiler.h> 5#include <linux/compiler.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <fcntl.h>
6#include "compress.h" 9#include "compress.h"
7#include "util.h" 10#include "util.h"
8#include "debug.h" 11#include "debug.h"
12#include <unistd.h>
9 13
10#define BUFSIZE 8192 14#define BUFSIZE 8192
11 15
@@ -99,3 +103,19 @@ err_fclose:
99 fclose(infile); 103 fclose(infile);
100 return err; 104 return err;
101} 105}
106
107bool lzma_is_compressed(const char *input)
108{
109 int fd = open(input, O_RDONLY);
110 const uint8_t magic[6] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 };
111 char buf[6] = { 0 };
112 ssize_t rc;
113
114 if (fd < 0)
115 return -1;
116
117 rc = read(fd, buf, sizeof(buf));
118 close(fd);
119 return rc == sizeof(buf) ?
120 memcmp(buf, magic, sizeof(buf)) == 0 : false;
121}
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index b300a3973448..c4acd2001db0 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1212,8 +1212,10 @@ static int map_groups__set_module_path(struct map_groups *mg, const char *path,
1212 * Full name could reveal us kmod compression, so 1212 * Full name could reveal us kmod compression, so
1213 * we need to update the symtab_type if needed. 1213 * we need to update the symtab_type if needed.
1214 */ 1214 */
1215 if (m->comp && is_kmod_dso(map->dso)) 1215 if (m->comp && is_kmod_dso(map->dso)) {
1216 map->dso->symtab_type++; 1216 map->dso->symtab_type++;
1217 map->dso->comp = m->comp;
1218 }
1217 1219
1218 return 0; 1220 return 0;
1219} 1221}
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 1de7660d93e9..d856b85862e2 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -265,7 +265,7 @@ pid_t machine__get_current_tid(struct machine *machine, int cpu);
265int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, 265int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
266 pid_t tid); 266 pid_t tid);
267/* 267/*
268 * For use with libtraceevent's pevent_set_function_resolver() 268 * For use with libtraceevent's tep_set_function_resolver()
269 */ 269 */
270char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp); 270char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp);
271 271
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 89ac5b5dc218..36d0763311ef 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -381,20 +381,6 @@ struct map *map__clone(struct map *from)
381 return map; 381 return map;
382} 382}
383 383
384int map__overlap(struct map *l, struct map *r)
385{
386 if (l->start > r->start) {
387 struct map *t = l;
388 l = r;
389 r = t;
390 }
391
392 if (l->end > r->start)
393 return 1;
394
395 return 0;
396}
397
398size_t map__fprintf(struct map *map, FILE *fp) 384size_t map__fprintf(struct map *map, FILE *fp)
399{ 385{
400 return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n", 386 return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
@@ -675,20 +661,42 @@ static void __map_groups__insert(struct map_groups *mg, struct map *map)
675static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp) 661static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
676{ 662{
677 struct rb_root *root; 663 struct rb_root *root;
678 struct rb_node *next; 664 struct rb_node *next, *first;
679 int err = 0; 665 int err = 0;
680 666
681 down_write(&maps->lock); 667 down_write(&maps->lock);
682 668
683 root = &maps->entries; 669 root = &maps->entries;
684 next = rb_first(root);
685 670
671 /*
672 * Find first map where end > map->start.
673 * Same as find_vma() in kernel.
674 */
675 next = root->rb_node;
676 first = NULL;
677 while (next) {
678 struct map *pos = rb_entry(next, struct map, rb_node);
679
680 if (pos->end > map->start) {
681 first = next;
682 if (pos->start <= map->start)
683 break;
684 next = next->rb_left;
685 } else
686 next = next->rb_right;
687 }
688
689 next = first;
686 while (next) { 690 while (next) {
687 struct map *pos = rb_entry(next, struct map, rb_node); 691 struct map *pos = rb_entry(next, struct map, rb_node);
688 next = rb_next(&pos->rb_node); 692 next = rb_next(&pos->rb_node);
689 693
690 if (!map__overlap(pos, map)) 694 /*
691 continue; 695 * Stop if current map starts after map->end.
696 * Maps are ordered by start: next will not overlap for sure.
697 */
698 if (pos->start >= map->end)
699 break;
692 700
693 if (verbose >= 2) { 701 if (verbose >= 2) {
694 702
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 4cb90f242bed..e0f327b51e66 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -166,7 +166,6 @@ static inline void __map__zput(struct map **map)
166 166
167#define map__zput(map) __map__zput(&map) 167#define map__zput(map) __map__zput(&map)
168 168
169int map__overlap(struct map *l, struct map *r);
170size_t map__fprintf(struct map *map, FILE *fp); 169size_t map__fprintf(struct map *map, FILE *fp);
171size_t map__fprintf_dsoname(struct map *map, FILE *fp); 170size_t map__fprintf_dsoname(struct map *map, FILE *fp);
172char *map__srcline(struct map *map, u64 addr, struct symbol *sym); 171char *map__srcline(struct map *map, u64 addr, struct symbol *sym);
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index fc832676a798..215f69f41672 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -164,7 +164,7 @@ void perf_mmap__munmap(struct perf_mmap *map)
164 auxtrace_mmap__munmap(&map->auxtrace_mmap); 164 auxtrace_mmap__munmap(&map->auxtrace_mmap);
165} 165}
166 166
167int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd) 167int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu)
168{ 168{
169 /* 169 /*
170 * The last one will be done at perf_mmap__consume(), so that we 170 * The last one will be done at perf_mmap__consume(), so that we
@@ -191,6 +191,7 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
191 return -1; 191 return -1;
192 } 192 }
193 map->fd = fd; 193 map->fd = fd;
194 map->cpu = cpu;
194 195
195 if (auxtrace_mmap__mmap(&map->auxtrace_mmap, 196 if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
196 &mp->auxtrace_mp, map->base, fd)) 197 &mp->auxtrace_mp, map->base, fd))
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index d82294db1295..05a6d47c7956 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -18,6 +18,7 @@ struct perf_mmap {
18 void *base; 18 void *base;
19 int mask; 19 int mask;
20 int fd; 20 int fd;
21 int cpu;
21 refcount_t refcnt; 22 refcount_t refcnt;
22 u64 prev; 23 u64 prev;
23 u64 start; 24 u64 start;
@@ -60,7 +61,7 @@ struct mmap_params {
60 struct auxtrace_mmap_params auxtrace_mp; 61 struct auxtrace_mmap_params auxtrace_mp;
61}; 62};
62 63
63int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd); 64int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu);
64void perf_mmap__munmap(struct perf_mmap *map); 65void perf_mmap__munmap(struct perf_mmap *map);
65 66
66void perf_mmap__get(struct perf_mmap *map); 67void perf_mmap__get(struct perf_mmap *map);
diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
index 5be021701f34..cf8bd123cf73 100644
--- a/tools/perf/util/namespaces.c
+++ b/tools/perf/util/namespaces.c
@@ -139,6 +139,9 @@ struct nsinfo *nsinfo__copy(struct nsinfo *nsi)
139{ 139{
140 struct nsinfo *nnsi; 140 struct nsinfo *nnsi;
141 141
142 if (nsi == NULL)
143 return NULL;
144
142 nnsi = calloc(1, sizeof(*nnsi)); 145 nnsi = calloc(1, sizeof(*nnsi));
143 if (nnsi != NULL) { 146 if (nnsi != NULL) {
144 nnsi->pid = nsi->pid; 147 nnsi->pid = nsi->pid;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 15eec49e71a1..f8cd3e7c9186 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1991,8 +1991,11 @@ static int set_filter(struct perf_evsel *evsel, const void *arg)
1991 int nr_addr_filters = 0; 1991 int nr_addr_filters = 0;
1992 struct perf_pmu *pmu = NULL; 1992 struct perf_pmu *pmu = NULL;
1993 1993
1994 if (evsel == NULL) 1994 if (evsel == NULL) {
1995 goto err; 1995 fprintf(stderr,
1996 "--filter option should follow a -e tracepoint or HW tracer option\n");
1997 return -1;
1998 }
1996 1999
1997 if (evsel->attr.type == PERF_TYPE_TRACEPOINT) { 2000 if (evsel->attr.type == PERF_TYPE_TRACEPOINT) {
1998 if (perf_evsel__append_tp_filter(evsel, str) < 0) { 2001 if (perf_evsel__append_tp_filter(evsel, str) < 0) {
@@ -2014,8 +2017,11 @@ static int set_filter(struct perf_evsel *evsel, const void *arg)
2014 perf_pmu__scan_file(pmu, "nr_addr_filters", 2017 perf_pmu__scan_file(pmu, "nr_addr_filters",
2015 "%d", &nr_addr_filters); 2018 "%d", &nr_addr_filters);
2016 2019
2017 if (!nr_addr_filters) 2020 if (!nr_addr_filters) {
2018 goto err; 2021 fprintf(stderr,
2022 "This CPU does not support address filtering\n");
2023 return -1;
2024 }
2019 2025
2020 if (perf_evsel__append_addr_filter(evsel, str) < 0) { 2026 if (perf_evsel__append_addr_filter(evsel, str) < 0) {
2021 fprintf(stderr, 2027 fprintf(stderr,
@@ -2024,12 +2030,6 @@ static int set_filter(struct perf_evsel *evsel, const void *arg)
2024 } 2030 }
2025 2031
2026 return 0; 2032 return 0;
2027
2028err:
2029 fprintf(stderr,
2030 "--filter option should follow a -e tracepoint or HW tracer option\n");
2031
2032 return -1;
2033} 2033}
2034 2034
2035int parse_filter(const struct option *opt, const char *str, 2035int parse_filter(const struct option *opt, const char *str,
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 863b61478edd..ce501ba14b08 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -11,6 +11,7 @@
11#include "cpumap.h" 11#include "cpumap.h"
12#include "print_binary.h" 12#include "print_binary.h"
13#include "thread_map.h" 13#include "thread_map.h"
14#include "mmap.h"
14 15
15#if PY_MAJOR_VERSION < 3 16#if PY_MAJOR_VERSION < 3
16#define _PyUnicode_FromString(arg) \ 17#define _PyUnicode_FromString(arg) \
@@ -341,7 +342,7 @@ static bool is_tracepoint(struct pyrf_event *pevent)
341static PyObject* 342static PyObject*
342tracepoint_field(struct pyrf_event *pe, struct format_field *field) 343tracepoint_field(struct pyrf_event *pe, struct format_field *field)
343{ 344{
344 struct pevent *pevent = field->event->pevent; 345 struct tep_handle *pevent = field->event->pevent;
345 void *data = pe->sample.raw_data; 346 void *data = pe->sample.raw_data;
346 PyObject *ret = NULL; 347 PyObject *ret = NULL;
347 unsigned long long val; 348 unsigned long long val;
@@ -351,7 +352,7 @@ tracepoint_field(struct pyrf_event *pe, struct format_field *field)
351 offset = field->offset; 352 offset = field->offset;
352 len = field->size; 353 len = field->size;
353 if (field->flags & FIELD_IS_DYNAMIC) { 354 if (field->flags & FIELD_IS_DYNAMIC) {
354 val = pevent_read_number(pevent, data + offset, len); 355 val = tep_read_number(pevent, data + offset, len);
355 offset = val; 356 offset = val;
356 len = offset >> 16; 357 len = offset >> 16;
357 offset &= 0xffff; 358 offset &= 0xffff;
@@ -364,8 +365,8 @@ tracepoint_field(struct pyrf_event *pe, struct format_field *field)
364 field->flags &= ~FIELD_IS_STRING; 365 field->flags &= ~FIELD_IS_STRING;
365 } 366 }
366 } else { 367 } else {
367 val = pevent_read_number(pevent, data + field->offset, 368 val = tep_read_number(pevent, data + field->offset,
368 field->size); 369 field->size);
369 if (field->flags & FIELD_IS_POINTER) 370 if (field->flags & FIELD_IS_POINTER)
370 ret = PyLong_FromUnsignedLong((unsigned long) val); 371 ret = PyLong_FromUnsignedLong((unsigned long) val);
371 else if (field->flags & FIELD_IS_SIGNED) 372 else if (field->flags & FIELD_IS_SIGNED)
@@ -394,7 +395,7 @@ get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
394 evsel->tp_format = tp_format; 395 evsel->tp_format = tp_format;
395 } 396 }
396 397
397 field = pevent_find_any_field(evsel->tp_format, str); 398 field = tep_find_any_field(evsel->tp_format, str);
398 if (!field) 399 if (!field)
399 return NULL; 400 return NULL;
400 401
@@ -976,6 +977,20 @@ static PyObject *pyrf_evlist__add(struct pyrf_evlist *pevlist,
976 return Py_BuildValue("i", evlist->nr_entries); 977 return Py_BuildValue("i", evlist->nr_entries);
977} 978}
978 979
980static struct perf_mmap *get_md(struct perf_evlist *evlist, int cpu)
981{
982 int i;
983
984 for (i = 0; i < evlist->nr_mmaps; i++) {
985 struct perf_mmap *md = &evlist->mmap[i];
986
987 if (md->cpu == cpu)
988 return md;
989 }
990
991 return NULL;
992}
993
979static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, 994static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
980 PyObject *args, PyObject *kwargs) 995 PyObject *args, PyObject *kwargs)
981{ 996{
@@ -990,7 +1005,10 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
990 &cpu, &sample_id_all)) 1005 &cpu, &sample_id_all))
991 return NULL; 1006 return NULL;
992 1007
993 md = &evlist->mmap[cpu]; 1008 md = get_md(evlist, cpu);
1009 if (!md)
1010 return NULL;
1011
994 if (perf_mmap__read_init(md) < 0) 1012 if (perf_mmap__read_init(md) < 0)
995 goto end; 1013 goto end;
996 1014
diff --git a/tools/perf/util/s390-cpumsf-kernel.h b/tools/perf/util/s390-cpumsf-kernel.h
new file mode 100644
index 000000000000..de8c7ad0eca8
--- /dev/null
+++ b/tools/perf/util/s390-cpumsf-kernel.h
@@ -0,0 +1,71 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Auxtrace support for s390 CPU measurement sampling facility
4 *
5 * Copyright IBM Corp. 2018
6 * Author(s): Hendrik Brueckner <brueckner@linux.ibm.com>
7 * Thomas Richter <tmricht@linux.ibm.com>
8 */
9#ifndef S390_CPUMSF_KERNEL_H
10#define S390_CPUMSF_KERNEL_H
11
12#define S390_CPUMSF_PAGESZ 4096 /* Size of sample block units */
13#define S390_CPUMSF_DIAG_DEF_FIRST 0x8001 /* Diagnostic entry lowest id */
14
15struct hws_basic_entry {
16 unsigned int def:16; /* 0-15 Data Entry Format */
17 unsigned int R:4; /* 16-19 reserved */
18 unsigned int U:4; /* 20-23 Number of unique instruct. */
19 unsigned int z:2; /* zeros */
20 unsigned int T:1; /* 26 PSW DAT mode */
21 unsigned int W:1; /* 27 PSW wait state */
22 unsigned int P:1; /* 28 PSW Problem state */
23 unsigned int AS:2; /* 29-30 PSW address-space control */
24 unsigned int I:1; /* 31 entry valid or invalid */
25 unsigned int CL:2; /* 32-33 Configuration Level */
26 unsigned int:14;
27 unsigned int prim_asn:16; /* primary ASN */
28 unsigned long long ia; /* Instruction Address */
29 unsigned long long gpp; /* Guest Program Parameter */
30 unsigned long long hpp; /* Host Program Parameter */
31};
32
33struct hws_diag_entry {
34 unsigned int def:16; /* 0-15 Data Entry Format */
35 unsigned int R:15; /* 16-19 and 20-30 reserved */
36 unsigned int I:1; /* 31 entry valid or invalid */
37 u8 data[]; /* Machine-dependent sample data */
38};
39
40struct hws_combined_entry {
41 struct hws_basic_entry basic; /* Basic-sampling data entry */
42 struct hws_diag_entry diag; /* Diagnostic-sampling data entry */
43};
44
45struct hws_trailer_entry {
46 union {
47 struct {
48 unsigned int f:1; /* 0 - Block Full Indicator */
49 unsigned int a:1; /* 1 - Alert request control */
50 unsigned int t:1; /* 2 - Timestamp format */
51 unsigned int:29; /* 3 - 31: Reserved */
52 unsigned int bsdes:16; /* 32-47: size of basic SDE */
53 unsigned int dsdes:16; /* 48-63: size of diagnostic SDE */
54 };
55 unsigned long long flags; /* 0 - 64: All indicators */
56 };
57 unsigned long long overflow; /* 64 - sample Overflow count */
58 unsigned char timestamp[16]; /* 16 - 31 timestamp */
59 unsigned long long reserved1; /* 32 -Reserved */
60 unsigned long long reserved2; /* */
61 union { /* 48 - reserved for programming use */
62 struct {
63 unsigned long long clock_base:1; /* in progusage2 */
64 unsigned long long progusage1:63;
65 unsigned long long progusage2;
66 };
67 unsigned long long progusage[2];
68 };
69};
70
71#endif
diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
new file mode 100644
index 000000000000..d2c78ffd9fee
--- /dev/null
+++ b/tools/perf/util/s390-cpumsf.c
@@ -0,0 +1,945 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright IBM Corp. 2018
4 * Auxtrace support for s390 CPU-Measurement Sampling Facility
5 *
6 * Author(s): Thomas Richter <tmricht@linux.ibm.com>
7 *
8 * Auxiliary traces are collected during 'perf record' using rbd000 event.
9 * Several PERF_RECORD_XXX are generated during recording:
10 *
11 * PERF_RECORD_AUX:
12 * Records that new data landed in the AUX buffer part.
13 * PERF_RECORD_AUXTRACE:
14 * Defines auxtrace data. Followed by the actual data. The contents of
15 * the auxtrace data is dependent on the event and the CPU.
16 * This record is generated by perf record command. For details
17 * see Documentation/perf.data-file-format.txt.
18 * PERF_RECORD_AUXTRACE_INFO:
19 * Defines a table of contains for PERF_RECORD_AUXTRACE records. This
20 * record is generated during 'perf record' command. Each record contains up
21 * to 256 entries describing offset and size of the AUXTRACE data in the
22 * perf.data file.
23 * PERF_RECORD_AUXTRACE_ERROR:
24 * Indicates an error during AUXTRACE collection such as buffer overflow.
25 * PERF_RECORD_FINISHED_ROUND:
26 * Perf events are not necessarily in time stamp order, as they can be
27 * collected in parallel on different CPUs. If the events should be
28 * processed in time order they need to be sorted first.
29 * Perf report guarantees that there is no reordering over a
30 * PERF_RECORD_FINISHED_ROUND boundary event. All perf records with a
31 * time stamp lower than this record are processed (and displayed) before
32 * the succeeding perf record are processed.
33 *
34 * These records are evaluated during perf report command.
35 *
36 * 1. PERF_RECORD_AUXTRACE_INFO is used to set up the infrastructure for
37 * auxiliary trace data processing. See s390_cpumsf_process_auxtrace_info()
38 * below.
39 * Auxiliary trace data is collected per CPU. To merge the data into the report
40 * an auxtrace_queue is created for each CPU. It is assumed that the auxtrace
41 * data is in ascending order.
42 *
43 * Each queue has a double linked list of auxtrace_buffers. This list contains
44 * the offset and size of a CPU's auxtrace data. During auxtrace processing
45 * the data portion is mmap()'ed.
46 *
47 * To sort the queues in chronological order, all queue access is controlled
48 * by the auxtrace_heap. This is basicly a stack, each stack element has two
49 * entries, the queue number and a time stamp. However the stack is sorted by
50 * the time stamps. The highest time stamp is at the bottom the lowest
51 * (nearest) time stamp is at the top. That sort order is maintained at all
52 * times!
53 *
54 * After the auxtrace infrastructure has been setup, the auxtrace queues are
55 * filled with data (offset/size pairs) and the auxtrace_heap is populated.
56 *
57 * 2. PERF_RECORD_XXX processing triggers access to the auxtrace_queues.
58 * Each record is handled by s390_cpumsf_process_event(). The time stamp of
59 * the perf record is compared with the time stamp located on the auxtrace_heap
60 * top element. If that time stamp is lower than the time stamp from the
61 * record sample, the auxtrace queues will be processed. As auxtrace queues
62 * control many auxtrace_buffers and each buffer can be quite large, the
63 * auxtrace buffer might be processed only partially. In this case the
64 * position in the auxtrace_buffer of that queue is remembered and the time
65 * stamp of the last processed entry of the auxtrace_buffer replaces the
66 * current auxtrace_heap top.
67 *
68 * 3. Auxtrace_queues might run of out data and are feeded by the
69 * PERF_RECORD_AUXTRACE handling, see s390_cpumsf_process_auxtrace_event().
70 *
71 * Event Generation
72 * Each sampling-data entry in the auxilary trace data generates a perf sample.
73 * This sample is filled
74 * with data from the auxtrace such as PID/TID, instruction address, CPU state,
75 * etc. This sample is processed with perf_session__deliver_synth_event() to
76 * be included into the GUI.
77 *
78 * 4. PERF_RECORD_FINISHED_ROUND event is used to process all the remaining
79 * auxiliary traces entries until the time stamp of this record is reached
80 * auxtrace_heap top. This is triggered by ordered_event->deliver().
81 *
82 *
83 * Perf event processing.
84 * Event processing of PERF_RECORD_XXX entries relies on time stamp entries.
85 * This is the function call sequence:
86 *
87 * __cmd_report()
88 * |
89 * perf_session__process_events()
90 * |
91 * __perf_session__process_events()
92 * |
93 * perf_session__process_event()
94 * | This functions splits the PERF_RECORD_XXX records.
95 * | - Those generated by perf record command (type number equal or higher
96 * | than PERF_RECORD_USER_TYPE_START) are handled by
97 * | perf_session__process_user_event(see below)
98 * | - Those generated by the kernel are handled by
99 * | perf_evlist__parse_sample_timestamp()
100 * |
101 * perf_evlist__parse_sample_timestamp()
102 * | Extract time stamp from sample data.
103 * |
104 * perf_session__queue_event()
105 * | If timestamp is positive the sample is entered into an ordered_event
106 * | list, sort order is the timestamp. The event processing is deferred until
107 * | later (see perf_session__process_user_event()).
108 * | Other timestamps (0 or -1) are handled immediately by
109 * | perf_session__deliver_event(). These are events generated at start up
110 * | of command perf record. They create PERF_RECORD_COMM and PERF_RECORD_MMAP*
111 * | records. They are needed to create a list of running processes and its
112 * | memory mappings and layout. They are needed at the beginning to enable
113 * | command perf report to create process trees and memory mappings.
114 * |
115 * perf_session__deliver_event()
116 * | Delivers a PERF_RECORD_XXX entry for handling.
117 * |
118 * auxtrace__process_event()
119 * | The timestamp of the PERF_RECORD_XXX entry is taken to correlate with
120 * | time stamps from the auxiliary trace buffers. This enables
121 * | synchronization between auxiliary trace data and the events on the
122 * | perf.data file.
123 * |
124 * machine__deliver_event()
125 * | Handles the PERF_RECORD_XXX event. This depends on the record type.
126 * It might update the process tree, update a process memory map or enter
127 * a sample with IP and call back chain data into GUI data pool.
128 *
129 *
130 * Deferred processing determined by perf_session__process_user_event() is
131 * finally processed when a PERF_RECORD_FINISHED_ROUND is encountered. These
132 * are generated during command perf record.
133 * The timestamp of PERF_RECORD_FINISHED_ROUND event is taken to process all
134 * PERF_RECORD_XXX entries stored in the ordered_event list. This list was
135 * built up while reading the perf.data file.
136 * Each event is now processed by calling perf_session__deliver_event().
137 * This enables time synchronization between the data in the perf.data file and
138 * the data in the auxiliary trace buffers.
139 */
140
141#include <endian.h>
142#include <errno.h>
143#include <byteswap.h>
144#include <inttypes.h>
145#include <linux/kernel.h>
146#include <linux/types.h>
147#include <linux/bitops.h>
148#include <linux/log2.h>
149
150#include "cpumap.h"
151#include "color.h"
152#include "evsel.h"
153#include "evlist.h"
154#include "machine.h"
155#include "session.h"
156#include "util.h"
157#include "thread.h"
158#include "debug.h"
159#include "auxtrace.h"
160#include "s390-cpumsf.h"
161#include "s390-cpumsf-kernel.h"
162
163struct s390_cpumsf {
164 struct auxtrace auxtrace;
165 struct auxtrace_queues queues;
166 struct auxtrace_heap heap;
167 struct perf_session *session;
168 struct machine *machine;
169 u32 auxtrace_type;
170 u32 pmu_type;
171 u16 machine_type;
172 bool data_queued;
173};
174
175struct s390_cpumsf_queue {
176 struct s390_cpumsf *sf;
177 unsigned int queue_nr;
178 struct auxtrace_buffer *buffer;
179 int cpu;
180};
181
182/* Display s390 CPU measurement facility basic-sampling data entry */
183static bool s390_cpumsf_basic_show(const char *color, size_t pos,
184 struct hws_basic_entry *basic)
185{
186 if (basic->def != 1) {
187 pr_err("Invalid AUX trace basic entry [%#08zx]\n", pos);
188 return false;
189 }
190 color_fprintf(stdout, color, " [%#08zx] Basic Def:%04x Inst:%#04x"
191 " %c%c%c%c AS:%d ASN:%#04x IA:%#018llx\n"
192 "\t\tCL:%d HPP:%#018llx GPP:%#018llx\n",
193 pos, basic->def, basic->U,
194 basic->T ? 'T' : ' ',
195 basic->W ? 'W' : ' ',
196 basic->P ? 'P' : ' ',
197 basic->I ? 'I' : ' ',
198 basic->AS, basic->prim_asn, basic->ia, basic->CL,
199 basic->hpp, basic->gpp);
200 return true;
201}
202
203/* Display s390 CPU measurement facility diagnostic-sampling data entry */
204static bool s390_cpumsf_diag_show(const char *color, size_t pos,
205 struct hws_diag_entry *diag)
206{
207 if (diag->def < S390_CPUMSF_DIAG_DEF_FIRST) {
208 pr_err("Invalid AUX trace diagnostic entry [%#08zx]\n", pos);
209 return false;
210 }
211 color_fprintf(stdout, color, " [%#08zx] Diag Def:%04x %c\n",
212 pos, diag->def, diag->I ? 'I' : ' ');
213 return true;
214}
215
216/* Return TOD timestamp contained in an trailer entry */
217static unsigned long long trailer_timestamp(struct hws_trailer_entry *te)
218{
219 /* te->t set: TOD in STCKE format, bytes 8-15
220 * to->t not set: TOD in STCK format, bytes 0-7
221 */
222 unsigned long long ts;
223
224 memcpy(&ts, &te->timestamp[te->t], sizeof(ts));
225 return ts;
226}
227
228/* Display s390 CPU measurement facility trailer entry */
229static bool s390_cpumsf_trailer_show(const char *color, size_t pos,
230 struct hws_trailer_entry *te)
231{
232 if (te->bsdes != sizeof(struct hws_basic_entry)) {
233 pr_err("Invalid AUX trace trailer entry [%#08zx]\n", pos);
234 return false;
235 }
236 color_fprintf(stdout, color, " [%#08zx] Trailer %c%c%c bsdes:%d"
237 " dsdes:%d Overflow:%lld Time:%#llx\n"
238 "\t\tC:%d TOD:%#lx 1:%#llx 2:%#llx\n",
239 pos,
240 te->f ? 'F' : ' ',
241 te->a ? 'A' : ' ',
242 te->t ? 'T' : ' ',
243 te->bsdes, te->dsdes, te->overflow,
244 trailer_timestamp(te), te->clock_base, te->progusage2,
245 te->progusage[0], te->progusage[1]);
246 return true;
247}
248
249/* Test a sample data block. It must be 4KB or a multiple thereof in size and
250 * 4KB page aligned. Each sample data page has a trailer entry at the
251 * end which contains the sample entry data sizes.
252 *
253 * Return true if the sample data block passes the checks and set the
254 * basic set entry size and diagnostic set entry size.
255 *
256 * Return false on failure.
257 *
258 * Note: Old hardware does not set the basic or diagnostic entry sizes
259 * in the trailer entry. Use the type number instead.
260 */
261static bool s390_cpumsf_validate(int machine_type,
262 unsigned char *buf, size_t len,
263 unsigned short *bsdes,
264 unsigned short *dsdes)
265{
266 struct hws_basic_entry *basic = (struct hws_basic_entry *)buf;
267 struct hws_trailer_entry *te;
268
269 *dsdes = *bsdes = 0;
270 if (len & (S390_CPUMSF_PAGESZ - 1)) /* Illegal size */
271 return false;
272 if (basic->def != 1) /* No basic set entry, must be first */
273 return false;
274 /* Check for trailer entry at end of SDB */
275 te = (struct hws_trailer_entry *)(buf + S390_CPUMSF_PAGESZ
276 - sizeof(*te));
277 *bsdes = te->bsdes;
278 *dsdes = te->dsdes;
279 if (!te->bsdes && !te->dsdes) {
280 /* Very old hardware, use CPUID */
281 switch (machine_type) {
282 case 2097:
283 case 2098:
284 *dsdes = 64;
285 *bsdes = 32;
286 break;
287 case 2817:
288 case 2818:
289 *dsdes = 74;
290 *bsdes = 32;
291 break;
292 case 2827:
293 case 2828:
294 *dsdes = 85;
295 *bsdes = 32;
296 break;
297 default:
298 /* Illegal trailer entry */
299 return false;
300 }
301 }
302 return true;
303}
304
305/* Return true if there is room for another entry */
306static bool s390_cpumsf_reached_trailer(size_t entry_sz, size_t pos)
307{
308 size_t payload = S390_CPUMSF_PAGESZ - sizeof(struct hws_trailer_entry);
309
310 if (payload - (pos & (S390_CPUMSF_PAGESZ - 1)) < entry_sz)
311 return false;
312 return true;
313}
314
315/* Dump an auxiliary buffer. These buffers are multiple of
316 * 4KB SDB pages.
317 */
318static void s390_cpumsf_dump(struct s390_cpumsf *sf,
319 unsigned char *buf, size_t len)
320{
321 const char *color = PERF_COLOR_BLUE;
322 struct hws_basic_entry *basic;
323 struct hws_diag_entry *diag;
324 unsigned short bsdes, dsdes;
325 size_t pos = 0;
326
327 color_fprintf(stdout, color,
328 ". ... s390 AUX data: size %zu bytes\n",
329 len);
330
331 if (!s390_cpumsf_validate(sf->machine_type, buf, len, &bsdes,
332 &dsdes)) {
333 pr_err("Invalid AUX trace data block size:%zu"
334 " (type:%d bsdes:%hd dsdes:%hd)\n",
335 len, sf->machine_type, bsdes, dsdes);
336 return;
337 }
338
339 /* s390 kernel always returns 4KB blocks fully occupied,
340 * no partially filled SDBs.
341 */
342 while (pos < len) {
343 /* Handle Basic entry */
344 basic = (struct hws_basic_entry *)(buf + pos);
345 if (s390_cpumsf_basic_show(color, pos, basic))
346 pos += bsdes;
347 else
348 return;
349
350 /* Handle Diagnostic entry */
351 diag = (struct hws_diag_entry *)(buf + pos);
352 if (s390_cpumsf_diag_show(color, pos, diag))
353 pos += dsdes;
354 else
355 return;
356
357 /* Check for trailer entry */
358 if (!s390_cpumsf_reached_trailer(bsdes + dsdes, pos)) {
359 /* Show trailer entry */
360 struct hws_trailer_entry te;
361
362 pos = (pos + S390_CPUMSF_PAGESZ)
363 & ~(S390_CPUMSF_PAGESZ - 1);
364 pos -= sizeof(te);
365 memcpy(&te, buf + pos, sizeof(te));
366 /* Set descriptor sizes in case of old hardware
367 * where these values are not set.
368 */
369 te.bsdes = bsdes;
370 te.dsdes = dsdes;
371 if (s390_cpumsf_trailer_show(color, pos, &te))
372 pos += sizeof(te);
373 else
374 return;
375 }
376 }
377}
378
379static void s390_cpumsf_dump_event(struct s390_cpumsf *sf, unsigned char *buf,
380 size_t len)
381{
382 printf(".\n");
383 s390_cpumsf_dump(sf, buf, len);
384}
385
386#define S390_LPP_PID_MASK 0xffffffff
387
388static bool s390_cpumsf_make_event(size_t pos,
389 struct hws_basic_entry *basic,
390 struct s390_cpumsf_queue *sfq)
391{
392 struct perf_sample sample = {
393 .ip = basic->ia,
394 .pid = basic->hpp & S390_LPP_PID_MASK,
395 .tid = basic->hpp & S390_LPP_PID_MASK,
396 .cpumode = PERF_RECORD_MISC_CPUMODE_UNKNOWN,
397 .cpu = sfq->cpu,
398 .period = 1
399 };
400 union perf_event event;
401
402 memset(&event, 0, sizeof(event));
403 if (basic->CL == 1) /* Native LPAR mode */
404 sample.cpumode = basic->P ? PERF_RECORD_MISC_USER
405 : PERF_RECORD_MISC_KERNEL;
406 else if (basic->CL == 2) /* Guest kernel/user space */
407 sample.cpumode = basic->P ? PERF_RECORD_MISC_GUEST_USER
408 : PERF_RECORD_MISC_GUEST_KERNEL;
409 else if (basic->gpp || basic->prim_asn != 0xffff)
410 /* Use heuristics on old hardware */
411 sample.cpumode = basic->P ? PERF_RECORD_MISC_GUEST_USER
412 : PERF_RECORD_MISC_GUEST_KERNEL;
413 else
414 sample.cpumode = basic->P ? PERF_RECORD_MISC_USER
415 : PERF_RECORD_MISC_KERNEL;
416
417 event.sample.header.type = PERF_RECORD_SAMPLE;
418 event.sample.header.misc = sample.cpumode;
419 event.sample.header.size = sizeof(struct perf_event_header);
420
421 pr_debug4("%s pos:%#zx ip:%#" PRIx64 " P:%d CL:%d pid:%d.%d cpumode:%d cpu:%d\n",
422 __func__, pos, sample.ip, basic->P, basic->CL, sample.pid,
423 sample.tid, sample.cpumode, sample.cpu);
424 if (perf_session__deliver_synth_event(sfq->sf->session, &event,
425 &sample)) {
426 pr_err("s390 Auxiliary Trace: failed to deliver event\n");
427 return false;
428 }
429 return true;
430}
431
432static unsigned long long get_trailer_time(const unsigned char *buf)
433{
434 struct hws_trailer_entry *te;
435 unsigned long long aux_time;
436
437 te = (struct hws_trailer_entry *)(buf + S390_CPUMSF_PAGESZ
438 - sizeof(*te));
439
440 if (!te->clock_base) /* TOD_CLOCK_BASE value missing */
441 return 0;
442
443 /* Correct calculation to convert time stamp in trailer entry to
444 * nano seconds (taken from arch/s390 function tod_to_ns()).
445 * TOD_CLOCK_BASE is stored in trailer entry member progusage2.
446 */
447 aux_time = trailer_timestamp(te) - te->progusage2;
448 aux_time = (aux_time >> 9) * 125 + (((aux_time & 0x1ff) * 125) >> 9);
449 return aux_time;
450}
451
452/* Process the data samples of a single queue. The first parameter is a
453 * pointer to the queue, the second parameter is the time stamp. This
454 * is the time stamp:
455 * - of the event that triggered this processing.
456 * - or the time stamp when the last proccesing of this queue stopped.
457 * In this case it stopped at a 4KB page boundary and record the
458 * position on where to continue processing on the next invocation
459 * (see buffer->use_data and buffer->use_size).
460 *
461 * When this function returns the second parameter is updated to
462 * reflect the time stamp of the last processed auxiliary data entry
463 * (taken from the trailer entry of that page). The caller uses this
464 * returned time stamp to record the last processed entry in this
465 * queue.
466 *
467 * The function returns:
468 * 0: Processing successful. The second parameter returns the
469 * time stamp from the trailer entry until which position
470 * processing took place. Subsequent calls resume from this
471 * position.
472 * <0: An error occurred during processing. The second parameter
473 * returns the maximum time stamp.
474 * >0: Done on this queue. The second parameter returns the
475 * maximum time stamp.
476 */
477static int s390_cpumsf_samples(struct s390_cpumsf_queue *sfq, u64 *ts)
478{
479 struct s390_cpumsf *sf = sfq->sf;
480 unsigned char *buf = sfq->buffer->use_data;
481 size_t len = sfq->buffer->use_size;
482 struct hws_basic_entry *basic;
483 unsigned short bsdes, dsdes;
484 size_t pos = 0;
485 int err = 1;
486 u64 aux_ts;
487
488 if (!s390_cpumsf_validate(sf->machine_type, buf, len, &bsdes,
489 &dsdes)) {
490 *ts = ~0ULL;
491 return -1;
492 }
493
494 /* Get trailer entry time stamp and check if entries in
495 * this auxiliary page are ready for processing. If the
496 * time stamp of the first entry is too high, whole buffer
497 * can be skipped. In this case return time stamp.
498 */
499 aux_ts = get_trailer_time(buf);
500 if (!aux_ts) {
501 pr_err("[%#08" PRIx64 "] Invalid AUX trailer entry TOD clock base\n",
502 sfq->buffer->data_offset);
503 aux_ts = ~0ULL;
504 goto out;
505 }
506 if (aux_ts > *ts) {
507 *ts = aux_ts;
508 return 0;
509 }
510
511 while (pos < len) {
512 /* Handle Basic entry */
513 basic = (struct hws_basic_entry *)(buf + pos);
514 if (s390_cpumsf_make_event(pos, basic, sfq))
515 pos += bsdes;
516 else {
517 err = -EBADF;
518 goto out;
519 }
520
521 pos += dsdes; /* Skip diagnositic entry */
522
523 /* Check for trailer entry */
524 if (!s390_cpumsf_reached_trailer(bsdes + dsdes, pos)) {
525 pos = (pos + S390_CPUMSF_PAGESZ)
526 & ~(S390_CPUMSF_PAGESZ - 1);
527 /* Check existence of next page */
528 if (pos >= len)
529 break;
530 aux_ts = get_trailer_time(buf + pos);
531 if (!aux_ts) {
532 aux_ts = ~0ULL;
533 goto out;
534 }
535 if (aux_ts > *ts) {
536 *ts = aux_ts;
537 sfq->buffer->use_data += pos;
538 sfq->buffer->use_size -= pos;
539 return 0;
540 }
541 }
542 }
543out:
544 *ts = aux_ts;
545 sfq->buffer->use_size = 0;
546 sfq->buffer->use_data = NULL;
547 return err; /* Buffer completely scanned or error */
548}
549
550/* Run the s390 auxiliary trace decoder.
551 * Select the queue buffer to operate on, the caller already selected
552 * the proper queue, depending on second parameter 'ts'.
553 * This is the time stamp until which the auxiliary entries should
554 * be processed. This value is updated by called functions and
555 * returned to the caller.
556 *
557 * Resume processing in the current buffer. If there is no buffer
558 * get a new buffer from the queue and setup start position for
559 * processing.
560 * When a buffer is completely processed remove it from the queue
561 * before returning.
562 *
563 * This function returns
564 * 1: When the queue is empty. Second parameter will be set to
565 * maximum time stamp.
566 * 0: Normal processing done.
567 * <0: Error during queue buffer setup. This causes the caller
568 * to stop processing completely.
569 */
570static int s390_cpumsf_run_decoder(struct s390_cpumsf_queue *sfq,
571 u64 *ts)
572{
573
574 struct auxtrace_buffer *buffer;
575 struct auxtrace_queue *queue;
576 int err;
577
578 queue = &sfq->sf->queues.queue_array[sfq->queue_nr];
579
580 /* Get buffer and last position in buffer to resume
581 * decoding the auxiliary entries. One buffer might be large
582 * and decoding might stop in between. This depends on the time
583 * stamp of the trailer entry in each page of the auxiliary
584 * data and the time stamp of the event triggering the decoding.
585 */
586 if (sfq->buffer == NULL) {
587 sfq->buffer = buffer = auxtrace_buffer__next(queue,
588 sfq->buffer);
589 if (!buffer) {
590 *ts = ~0ULL;
591 return 1; /* Processing done on this queue */
592 }
593 /* Start with a new buffer on this queue */
594 if (buffer->data) {
595 buffer->use_size = buffer->size;
596 buffer->use_data = buffer->data;
597 }
598 } else
599 buffer = sfq->buffer;
600
601 if (!buffer->data) {
602 int fd = perf_data__fd(sfq->sf->session->data);
603
604 buffer->data = auxtrace_buffer__get_data(buffer, fd);
605 if (!buffer->data)
606 return -ENOMEM;
607 buffer->use_size = buffer->size;
608 buffer->use_data = buffer->data;
609 }
610 pr_debug4("%s queue_nr:%d buffer:%" PRId64 " offset:%#" PRIx64 " size:%#zx rest:%#zx\n",
611 __func__, sfq->queue_nr, buffer->buffer_nr, buffer->offset,
612 buffer->size, buffer->use_size);
613 err = s390_cpumsf_samples(sfq, ts);
614
615 /* If non-zero, there is either an error (err < 0) or the buffer is
616 * completely done (err > 0). The error is unrecoverable, usually
617 * some descriptors could not be read successfully, so continue with
618 * the next buffer.
619 * In both cases the parameter 'ts' has been updated.
620 */
621 if (err) {
622 sfq->buffer = NULL;
623 list_del(&buffer->list);
624 auxtrace_buffer__free(buffer);
625 if (err > 0) /* Buffer done, no error */
626 err = 0;
627 }
628 return err;
629}
630
631static struct s390_cpumsf_queue *
632s390_cpumsf_alloc_queue(struct s390_cpumsf *sf, unsigned int queue_nr)
633{
634 struct s390_cpumsf_queue *sfq;
635
636 sfq = zalloc(sizeof(struct s390_cpumsf_queue));
637 if (sfq == NULL)
638 return NULL;
639
640 sfq->sf = sf;
641 sfq->queue_nr = queue_nr;
642 sfq->cpu = -1;
643 return sfq;
644}
645
646static int s390_cpumsf_setup_queue(struct s390_cpumsf *sf,
647 struct auxtrace_queue *queue,
648 unsigned int queue_nr, u64 ts)
649{
650 struct s390_cpumsf_queue *sfq = queue->priv;
651
652 if (list_empty(&queue->head))
653 return 0;
654
655 if (sfq == NULL) {
656 sfq = s390_cpumsf_alloc_queue(sf, queue_nr);
657 if (!sfq)
658 return -ENOMEM;
659 queue->priv = sfq;
660
661 if (queue->cpu != -1)
662 sfq->cpu = queue->cpu;
663 }
664 return auxtrace_heap__add(&sf->heap, queue_nr, ts);
665}
666
667static int s390_cpumsf_setup_queues(struct s390_cpumsf *sf, u64 ts)
668{
669 unsigned int i;
670 int ret = 0;
671
672 for (i = 0; i < sf->queues.nr_queues; i++) {
673 ret = s390_cpumsf_setup_queue(sf, &sf->queues.queue_array[i],
674 i, ts);
675 if (ret)
676 break;
677 }
678 return ret;
679}
680
681static int s390_cpumsf_update_queues(struct s390_cpumsf *sf, u64 ts)
682{
683 if (!sf->queues.new_data)
684 return 0;
685
686 sf->queues.new_data = false;
687 return s390_cpumsf_setup_queues(sf, ts);
688}
689
690static int s390_cpumsf_process_queues(struct s390_cpumsf *sf, u64 timestamp)
691{
692 unsigned int queue_nr;
693 u64 ts;
694 int ret;
695
696 while (1) {
697 struct auxtrace_queue *queue;
698 struct s390_cpumsf_queue *sfq;
699
700 if (!sf->heap.heap_cnt)
701 return 0;
702
703 if (sf->heap.heap_array[0].ordinal >= timestamp)
704 return 0;
705
706 queue_nr = sf->heap.heap_array[0].queue_nr;
707 queue = &sf->queues.queue_array[queue_nr];
708 sfq = queue->priv;
709
710 auxtrace_heap__pop(&sf->heap);
711 if (sf->heap.heap_cnt) {
712 ts = sf->heap.heap_array[0].ordinal + 1;
713 if (ts > timestamp)
714 ts = timestamp;
715 } else {
716 ts = timestamp;
717 }
718
719 ret = s390_cpumsf_run_decoder(sfq, &ts);
720 if (ret < 0) {
721 auxtrace_heap__add(&sf->heap, queue_nr, ts);
722 return ret;
723 }
724 if (!ret) {
725 ret = auxtrace_heap__add(&sf->heap, queue_nr, ts);
726 if (ret < 0)
727 return ret;
728 }
729 }
730 return 0;
731}
732
733static int s390_cpumsf_synth_error(struct s390_cpumsf *sf, int code, int cpu,
734 pid_t pid, pid_t tid, u64 ip)
735{
736 char msg[MAX_AUXTRACE_ERROR_MSG];
737 union perf_event event;
738 int err;
739
740 strncpy(msg, "Lost Auxiliary Trace Buffer", sizeof(msg) - 1);
741 auxtrace_synth_error(&event.auxtrace_error, PERF_AUXTRACE_ERROR_ITRACE,
742 code, cpu, pid, tid, ip, msg);
743
744 err = perf_session__deliver_synth_event(sf->session, &event, NULL);
745 if (err)
746 pr_err("s390 Auxiliary Trace: failed to deliver error event,"
747 "error %d\n", err);
748 return err;
749}
750
751static int s390_cpumsf_lost(struct s390_cpumsf *sf, struct perf_sample *sample)
752{
753 return s390_cpumsf_synth_error(sf, 1, sample->cpu,
754 sample->pid, sample->tid, 0);
755}
756
757static int
758s390_cpumsf_process_event(struct perf_session *session __maybe_unused,
759 union perf_event *event,
760 struct perf_sample *sample,
761 struct perf_tool *tool)
762{
763 struct s390_cpumsf *sf = container_of(session->auxtrace,
764 struct s390_cpumsf,
765 auxtrace);
766 u64 timestamp = sample->time;
767 int err = 0;
768
769 if (dump_trace)
770 return 0;
771
772 if (!tool->ordered_events) {
773 pr_err("s390 Auxiliary Trace requires ordered events\n");
774 return -EINVAL;
775 }
776
777 if (event->header.type == PERF_RECORD_AUX &&
778 event->aux.flags & PERF_AUX_FLAG_TRUNCATED)
779 return s390_cpumsf_lost(sf, sample);
780
781 if (timestamp) {
782 err = s390_cpumsf_update_queues(sf, timestamp);
783 if (!err)
784 err = s390_cpumsf_process_queues(sf, timestamp);
785 }
786 return err;
787}
788
789struct s390_cpumsf_synth {
790 struct perf_tool cpumsf_tool;
791 struct perf_session *session;
792};
793
794static int
795s390_cpumsf_process_auxtrace_event(struct perf_session *session,
796 union perf_event *event __maybe_unused,
797 struct perf_tool *tool __maybe_unused)
798{
799 struct s390_cpumsf *sf = container_of(session->auxtrace,
800 struct s390_cpumsf,
801 auxtrace);
802
803 int fd = perf_data__fd(session->data);
804 struct auxtrace_buffer *buffer;
805 off_t data_offset;
806 int err;
807
808 if (sf->data_queued)
809 return 0;
810
811 if (perf_data__is_pipe(session->data)) {
812 data_offset = 0;
813 } else {
814 data_offset = lseek(fd, 0, SEEK_CUR);
815 if (data_offset == -1)
816 return -errno;
817 }
818
819 err = auxtrace_queues__add_event(&sf->queues, session, event,
820 data_offset, &buffer);
821 if (err)
822 return err;
823
824 /* Dump here after copying piped trace out of the pipe */
825 if (dump_trace) {
826 if (auxtrace_buffer__get_data(buffer, fd)) {
827 s390_cpumsf_dump_event(sf, buffer->data,
828 buffer->size);
829 auxtrace_buffer__put_data(buffer);
830 }
831 }
832 return 0;
833}
834
835static void s390_cpumsf_free_events(struct perf_session *session __maybe_unused)
836{
837}
838
839static int s390_cpumsf_flush(struct perf_session *session __maybe_unused,
840 struct perf_tool *tool __maybe_unused)
841{
842 return 0;
843}
844
845static void s390_cpumsf_free_queues(struct perf_session *session)
846{
847 struct s390_cpumsf *sf = container_of(session->auxtrace,
848 struct s390_cpumsf,
849 auxtrace);
850 struct auxtrace_queues *queues = &sf->queues;
851 unsigned int i;
852
853 for (i = 0; i < queues->nr_queues; i++)
854 zfree(&queues->queue_array[i].priv);
855 auxtrace_queues__free(queues);
856}
857
858static void s390_cpumsf_free(struct perf_session *session)
859{
860 struct s390_cpumsf *sf = container_of(session->auxtrace,
861 struct s390_cpumsf,
862 auxtrace);
863
864 auxtrace_heap__free(&sf->heap);
865 s390_cpumsf_free_queues(session);
866 session->auxtrace = NULL;
867 free(sf);
868}
869
870static int s390_cpumsf_get_type(const char *cpuid)
871{
872 int ret, family = 0;
873
874 ret = sscanf(cpuid, "%*[^,],%u", &family);
875 return (ret == 1) ? family : 0;
876}
877
878/* Check itrace options set on perf report command.
879 * Return true, if none are set or all options specified can be
880 * handled on s390.
881 * Return false otherwise.
882 */
883static bool check_auxtrace_itrace(struct itrace_synth_opts *itops)
884{
885 if (!itops || !itops->set)
886 return true;
887 pr_err("No --itrace options supported\n");
888 return false;
889}
890
891int s390_cpumsf_process_auxtrace_info(union perf_event *event,
892 struct perf_session *session)
893{
894 struct auxtrace_info_event *auxtrace_info = &event->auxtrace_info;
895 struct s390_cpumsf *sf;
896 int err;
897
898 if (auxtrace_info->header.size < sizeof(struct auxtrace_info_event))
899 return -EINVAL;
900
901 sf = zalloc(sizeof(struct s390_cpumsf));
902 if (sf == NULL)
903 return -ENOMEM;
904
905 if (!check_auxtrace_itrace(session->itrace_synth_opts)) {
906 err = -EINVAL;
907 goto err_free;
908 }
909
910 err = auxtrace_queues__init(&sf->queues);
911 if (err)
912 goto err_free;
913
914 sf->session = session;
915 sf->machine = &session->machines.host; /* No kvm support */
916 sf->auxtrace_type = auxtrace_info->type;
917 sf->pmu_type = PERF_TYPE_RAW;
918 sf->machine_type = s390_cpumsf_get_type(session->evlist->env->cpuid);
919
920 sf->auxtrace.process_event = s390_cpumsf_process_event;
921 sf->auxtrace.process_auxtrace_event = s390_cpumsf_process_auxtrace_event;
922 sf->auxtrace.flush_events = s390_cpumsf_flush;
923 sf->auxtrace.free_events = s390_cpumsf_free_events;
924 sf->auxtrace.free = s390_cpumsf_free;
925 session->auxtrace = &sf->auxtrace;
926
927 if (dump_trace)
928 return 0;
929
930 err = auxtrace_queues__process_index(&sf->queues, session);
931 if (err)
932 goto err_free_queues;
933
934 if (sf->queues.populated)
935 sf->data_queued = true;
936
937 return 0;
938
939err_free_queues:
940 auxtrace_queues__free(&sf->queues);
941 session->auxtrace = NULL;
942err_free:
943 free(sf);
944 return err;
945}
diff --git a/tools/perf/util/s390-cpumsf.h b/tools/perf/util/s390-cpumsf.h
new file mode 100644
index 000000000000..fb64d100555c
--- /dev/null
+++ b/tools/perf/util/s390-cpumsf.h
@@ -0,0 +1,21 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright IBM Corp. 2018
4 * Auxtrace support for s390 CPU-Measurement Sampling Facility
5 *
6 * Author(s): Thomas Richter <tmricht@linux.ibm.com>
7 */
8
9#ifndef INCLUDE__PERF_S390_CPUMSF_H
10#define INCLUDE__PERF_S390_CPUMSF_H
11
12union perf_event;
13struct perf_session;
14struct perf_pmu;
15
16struct auxtrace_record *
17s390_cpumsf_recording_init(int *err, struct perf_pmu *s390_cpumsf_pmu);
18
19int s390_cpumsf_process_auxtrace_info(union perf_event *event,
20 struct perf_session *session);
21#endif
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 7b79c413486b..45484f0f7292 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -535,7 +535,7 @@ static int perl_stop_script(void)
535 return 0; 535 return 0;
536} 536}
537 537
538static int perl_generate_script(struct pevent *pevent, const char *outfile) 538static int perl_generate_script(struct tep_handle *pevent, const char *outfile)
539{ 539{
540 struct event_format *event = NULL; 540 struct event_format *event = NULL;
541 struct format_field *f; 541 struct format_field *f;
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index bc32e57d17be..dfc6093f118c 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -871,8 +871,8 @@ static void python_process_tracepoint(struct perf_sample *sample,
871 offset = field->offset; 871 offset = field->offset;
872 len = field->size; 872 len = field->size;
873 if (field->flags & FIELD_IS_DYNAMIC) { 873 if (field->flags & FIELD_IS_DYNAMIC) {
874 val = pevent_read_number(scripting_context->pevent, 874 val = tep_read_number(scripting_context->pevent,
875 data + offset, len); 875 data + offset, len);
876 offset = val; 876 offset = val;
877 len = offset >> 16; 877 len = offset >> 16;
878 offset &= 0xffff; 878 offset &= 0xffff;
@@ -1588,7 +1588,7 @@ static int python_stop_script(void)
1588 return 0; 1588 return 0;
1589} 1589}
1590 1590
1591static int python_generate_script(struct pevent *pevent, const char *outfile) 1591static int python_generate_script(struct tep_handle *pevent, const char *outfile)
1592{ 1592{
1593 struct event_format *event = NULL; 1593 struct event_format *event = NULL;
1594 struct format_field *f; 1594 struct format_field *f;
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 001be4f9d3b9..97efbcad076e 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -1,12 +1,20 @@
1#!/usr/bin/python 1#!/usr/bin/python
2 2
3from os import getenv 3from os import getenv
4from subprocess import Popen, PIPE
5from re import sub
6
7def clang_has_option(option):
8 return [o for o in Popen(['clang', option], stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ]
4 9
5cc = getenv("CC") 10cc = getenv("CC")
6if cc == "clang": 11if cc == "clang":
7 from _sysconfigdata import build_time_vars 12 from _sysconfigdata import build_time_vars
8 from re import sub
9 build_time_vars["CFLAGS"] = sub("-specs=[^ ]+", "", build_time_vars["CFLAGS"]) 13 build_time_vars["CFLAGS"] = sub("-specs=[^ ]+", "", build_time_vars["CFLAGS"])
14 if not clang_has_option("-mcet"):
15 build_time_vars["CFLAGS"] = sub("-mcet", "", build_time_vars["CFLAGS"])
16 if not clang_has_option("-fcf-protection"):
17 build_time_vars["CFLAGS"] = sub("-fcf-protection", "", build_time_vars["CFLAGS"])
10 18
11from distutils.core import setup, Extension 19from distutils.core import setup, Extension
12 20
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index fed2952ab45a..b284276ec963 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -601,7 +601,7 @@ static char *get_trace_output(struct hist_entry *he)
601{ 601{
602 struct trace_seq seq; 602 struct trace_seq seq;
603 struct perf_evsel *evsel; 603 struct perf_evsel *evsel;
604 struct pevent_record rec = { 604 struct tep_record rec = {
605 .data = he->raw_data, 605 .data = he->raw_data,
606 .size = he->raw_size, 606 .size = he->raw_size,
607 }; 607 };
@@ -610,10 +610,10 @@ static char *get_trace_output(struct hist_entry *he)
610 610
611 trace_seq_init(&seq); 611 trace_seq_init(&seq);
612 if (symbol_conf.raw_trace) { 612 if (symbol_conf.raw_trace) {
613 pevent_print_fields(&seq, he->raw_data, he->raw_size, 613 tep_print_fields(&seq, he->raw_data, he->raw_size,
614 evsel->tp_format); 614 evsel->tp_format);
615 } else { 615 } else {
616 pevent_event_info(&seq, evsel->tp_format, &rec); 616 tep_event_info(&seq, evsel->tp_format, &rec);
617 } 617 }
618 /* 618 /*
619 * Trim the buffer, it starts at 4KB and we're not going to 619 * Trim the buffer, it starts at 4KB and we're not going to
@@ -2047,7 +2047,7 @@ static int __sort__hde_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
2047 struct trace_seq seq; 2047 struct trace_seq seq;
2048raw_field: 2048raw_field:
2049 trace_seq_init(&seq); 2049 trace_seq_init(&seq);
2050 pevent_print_field(&seq, he->raw_data, hde->field); 2050 tep_print_field(&seq, he->raw_data, hde->field);
2051 str = seq.buffer; 2051 str = seq.buffer;
2052 } 2052 }
2053 2053
@@ -2074,7 +2074,7 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,
2074 if (field->flags & FIELD_IS_DYNAMIC) { 2074 if (field->flags & FIELD_IS_DYNAMIC) {
2075 unsigned long long dyn; 2075 unsigned long long dyn;
2076 2076
2077 pevent_read_number_field(field, a->raw_data, &dyn); 2077 tep_read_number_field(field, a->raw_data, &dyn);
2078 offset = dyn & 0xffff; 2078 offset = dyn & 0xffff;
2079 size = (dyn >> 16) & 0xffff; 2079 size = (dyn >> 16) & 0xffff;
2080 2080
@@ -2311,7 +2311,7 @@ static int add_all_matching_fields(struct perf_evlist *evlist,
2311 if (evsel->attr.type != PERF_TYPE_TRACEPOINT) 2311 if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
2312 continue; 2312 continue;
2313 2313
2314 field = pevent_find_any_field(evsel->tp_format, field_name); 2314 field = tep_find_any_field(evsel->tp_format, field_name);
2315 if (field == NULL) 2315 if (field == NULL)
2316 continue; 2316 continue;
2317 2317
@@ -2378,7 +2378,7 @@ static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok,
2378 if (!strcmp(field_name, "*")) { 2378 if (!strcmp(field_name, "*")) {
2379 ret = add_evsel_fields(evsel, raw_trace, level); 2379 ret = add_evsel_fields(evsel, raw_trace, level);
2380 } else { 2380 } else {
2381 field = pevent_find_any_field(evsel->tp_format, field_name); 2381 field = tep_find_any_field(evsel->tp_format, field_name);
2382 if (field == NULL) { 2382 if (field == NULL) {
2383 pr_debug("Cannot find event field for %s.%s\n", 2383 pr_debug("Cannot find event field for %s.%s\n",
2384 event_name, field_name); 2384 event_name, field_name);
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 8bf302cafcec..a97cf8e6be86 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -276,7 +276,7 @@ extern struct sort_entry sort_thread;
276extern struct list_head hist_entry__sort_list; 276extern struct list_head hist_entry__sort_list;
277 277
278struct perf_evlist; 278struct perf_evlist;
279struct pevent; 279struct tep_handle;
280int setup_sorting(struct perf_evlist *evlist); 280int setup_sorting(struct perf_evlist *evlist);
281int setup_output_field(void); 281int setup_output_field(void);
282void reset_output_field(void); 282void reset_output_field(void);
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index e0a6e9a6a053..920b1d58a068 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -32,7 +32,7 @@
32static int get_common_field(struct scripting_context *context, 32static int get_common_field(struct scripting_context *context,
33 int *offset, int *size, const char *type) 33 int *offset, int *size, const char *type)
34{ 34{
35 struct pevent *pevent = context->pevent; 35 struct tep_handle *pevent = context->pevent;
36 struct event_format *event; 36 struct event_format *event;
37 struct format_field *field; 37 struct format_field *field;
38 38
@@ -41,14 +41,14 @@ static int get_common_field(struct scripting_context *context,
41 return 0; 41 return 0;
42 42
43 event = pevent->events[0]; 43 event = pevent->events[0];
44 field = pevent_find_common_field(event, type); 44 field = tep_find_common_field(event, type);
45 if (!field) 45 if (!field)
46 return 0; 46 return 0;
47 *offset = field->offset; 47 *offset = field->offset;
48 *size = field->size; 48 *size = field->size;
49 } 49 }
50 50
51 return pevent_read_number(pevent, context->event_data + *offset, *size); 51 return tep_read_number(pevent, context->event_data + *offset, *size);
52} 52}
53 53
54int common_lock_depth(struct scripting_context *context) 54int common_lock_depth(struct scripting_context *context)
@@ -99,24 +99,24 @@ raw_field_value(struct event_format *event, const char *name, void *data)
99 struct format_field *field; 99 struct format_field *field;
100 unsigned long long val; 100 unsigned long long val;
101 101
102 field = pevent_find_any_field(event, name); 102 field = tep_find_any_field(event, name);
103 if (!field) 103 if (!field)
104 return 0ULL; 104 return 0ULL;
105 105
106 pevent_read_number_field(field, data, &val); 106 tep_read_number_field(field, data, &val);
107 107
108 return val; 108 return val;
109} 109}
110 110
111unsigned long long read_size(struct event_format *event, void *ptr, int size) 111unsigned long long read_size(struct event_format *event, void *ptr, int size)
112{ 112{
113 return pevent_read_number(event->pevent, ptr, size); 113 return tep_read_number(event->pevent, ptr, size);
114} 114}
115 115
116void event_format__fprintf(struct event_format *event, 116void event_format__fprintf(struct event_format *event,
117 int cpu, void *data, int size, FILE *fp) 117 int cpu, void *data, int size, FILE *fp)
118{ 118{
119 struct pevent_record record; 119 struct tep_record record;
120 struct trace_seq s; 120 struct trace_seq s;
121 121
122 memset(&record, 0, sizeof(record)); 122 memset(&record, 0, sizeof(record));
@@ -125,7 +125,7 @@ void event_format__fprintf(struct event_format *event,
125 record.data = data; 125 record.data = data;
126 126
127 trace_seq_init(&s); 127 trace_seq_init(&s);
128 pevent_event_info(&s, event, &record); 128 tep_event_info(&s, event, &record);
129 trace_seq_do_fprintf(&s, fp); 129 trace_seq_do_fprintf(&s, fp);
130 trace_seq_destroy(&s); 130 trace_seq_destroy(&s);
131} 131}
@@ -136,7 +136,7 @@ void event_format__print(struct event_format *event,
136 return event_format__fprintf(event, cpu, data, size, stdout); 136 return event_format__fprintf(event, cpu, data, size, stdout);
137} 137}
138 138
139void parse_ftrace_printk(struct pevent *pevent, 139void parse_ftrace_printk(struct tep_handle *pevent,
140 char *file, unsigned int size __maybe_unused) 140 char *file, unsigned int size __maybe_unused)
141{ 141{
142 unsigned long long addr; 142 unsigned long long addr;
@@ -157,11 +157,11 @@ void parse_ftrace_printk(struct pevent *pevent,
157 /* fmt still has a space, skip it */ 157 /* fmt still has a space, skip it */
158 printk = strdup(fmt+1); 158 printk = strdup(fmt+1);
159 line = strtok_r(NULL, "\n", &next); 159 line = strtok_r(NULL, "\n", &next);
160 pevent_register_print_string(pevent, printk, addr); 160 tep_register_print_string(pevent, printk, addr);
161 } 161 }
162} 162}
163 163
164void parse_saved_cmdline(struct pevent *pevent, 164void parse_saved_cmdline(struct tep_handle *pevent,
165 char *file, unsigned int size __maybe_unused) 165 char *file, unsigned int size __maybe_unused)
166{ 166{
167 char *comm; 167 char *comm;
@@ -172,24 +172,24 @@ void parse_saved_cmdline(struct pevent *pevent,
172 line = strtok_r(file, "\n", &next); 172 line = strtok_r(file, "\n", &next);
173 while (line) { 173 while (line) {
174 sscanf(line, "%d %ms", &pid, &comm); 174 sscanf(line, "%d %ms", &pid, &comm);
175 pevent_register_comm(pevent, comm, pid); 175 tep_register_comm(pevent, comm, pid);
176 free(comm); 176 free(comm);
177 line = strtok_r(NULL, "\n", &next); 177 line = strtok_r(NULL, "\n", &next);
178 } 178 }
179} 179}
180 180
181int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size) 181int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size)
182{ 182{
183 return pevent_parse_event(pevent, buf, size, "ftrace"); 183 return tep_parse_event(pevent, buf, size, "ftrace");
184} 184}
185 185
186int parse_event_file(struct pevent *pevent, 186int parse_event_file(struct tep_handle *pevent,
187 char *buf, unsigned long size, char *sys) 187 char *buf, unsigned long size, char *sys)
188{ 188{
189 return pevent_parse_event(pevent, buf, size, sys); 189 return tep_parse_event(pevent, buf, size, sys);
190} 190}
191 191
192struct event_format *trace_find_next_event(struct pevent *pevent, 192struct event_format *trace_find_next_event(struct tep_handle *pevent,
193 struct event_format *event) 193 struct event_format *event)
194{ 194{
195 static int idx; 195 static int idx;
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 40b425949aa3..3dfc1db6b25b 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -96,7 +96,7 @@ static void skip(int size)
96 }; 96 };
97} 97}
98 98
99static unsigned int read4(struct pevent *pevent) 99static unsigned int read4(struct tep_handle *pevent)
100{ 100{
101 unsigned int data; 101 unsigned int data;
102 102
@@ -105,7 +105,7 @@ static unsigned int read4(struct pevent *pevent)
105 return __data2host4(pevent, data); 105 return __data2host4(pevent, data);
106} 106}
107 107
108static unsigned long long read8(struct pevent *pevent) 108static unsigned long long read8(struct tep_handle *pevent)
109{ 109{
110 unsigned long long data; 110 unsigned long long data;
111 111
@@ -158,7 +158,7 @@ out:
158 return str; 158 return str;
159} 159}
160 160
161static int read_proc_kallsyms(struct pevent *pevent) 161static int read_proc_kallsyms(struct tep_handle *pevent)
162{ 162{
163 unsigned int size; 163 unsigned int size;
164 164
@@ -181,7 +181,7 @@ static int read_proc_kallsyms(struct pevent *pevent)
181 return 0; 181 return 0;
182} 182}
183 183
184static int read_ftrace_printk(struct pevent *pevent) 184static int read_ftrace_printk(struct tep_handle *pevent)
185{ 185{
186 unsigned int size; 186 unsigned int size;
187 char *buf; 187 char *buf;
@@ -208,7 +208,7 @@ static int read_ftrace_printk(struct pevent *pevent)
208 return 0; 208 return 0;
209} 209}
210 210
211static int read_header_files(struct pevent *pevent) 211static int read_header_files(struct tep_handle *pevent)
212{ 212{
213 unsigned long long size; 213 unsigned long long size;
214 char *header_page; 214 char *header_page;
@@ -235,13 +235,13 @@ static int read_header_files(struct pevent *pevent)
235 return -1; 235 return -1;
236 } 236 }
237 237
238 if (!pevent_parse_header_page(pevent, header_page, size, 238 if (!tep_parse_header_page(pevent, header_page, size,
239 pevent_get_long_size(pevent))) { 239 tep_get_long_size(pevent))) {
240 /* 240 /*
241 * The commit field in the page is of type long, 241 * The commit field in the page is of type long,
242 * use that instead, since it represents the kernel. 242 * use that instead, since it represents the kernel.
243 */ 243 */
244 pevent_set_long_size(pevent, pevent->header_page_size_size); 244 tep_set_long_size(pevent, pevent->header_page_size_size);
245 } 245 }
246 free(header_page); 246 free(header_page);
247 247
@@ -259,7 +259,7 @@ static int read_header_files(struct pevent *pevent)
259 return ret; 259 return ret;
260} 260}
261 261
262static int read_ftrace_file(struct pevent *pevent, unsigned long long size) 262static int read_ftrace_file(struct tep_handle *pevent, unsigned long long size)
263{ 263{
264 int ret; 264 int ret;
265 char *buf; 265 char *buf;
@@ -284,8 +284,8 @@ out:
284 return ret; 284 return ret;
285} 285}
286 286
287static int read_event_file(struct pevent *pevent, char *sys, 287static int read_event_file(struct tep_handle *pevent, char *sys,
288 unsigned long long size) 288 unsigned long long size)
289{ 289{
290 int ret; 290 int ret;
291 char *buf; 291 char *buf;
@@ -310,7 +310,7 @@ out:
310 return ret; 310 return ret;
311} 311}
312 312
313static int read_ftrace_files(struct pevent *pevent) 313static int read_ftrace_files(struct tep_handle *pevent)
314{ 314{
315 unsigned long long size; 315 unsigned long long size;
316 int count; 316 int count;
@@ -328,7 +328,7 @@ static int read_ftrace_files(struct pevent *pevent)
328 return 0; 328 return 0;
329} 329}
330 330
331static int read_event_files(struct pevent *pevent) 331static int read_event_files(struct tep_handle *pevent)
332{ 332{
333 unsigned long long size; 333 unsigned long long size;
334 char *sys; 334 char *sys;
@@ -356,7 +356,7 @@ static int read_event_files(struct pevent *pevent)
356 return 0; 356 return 0;
357} 357}
358 358
359static int read_saved_cmdline(struct pevent *pevent) 359static int read_saved_cmdline(struct tep_handle *pevent)
360{ 360{
361 unsigned long long size; 361 unsigned long long size;
362 char *buf; 362 char *buf;
@@ -399,7 +399,7 @@ ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
399 int host_bigendian; 399 int host_bigendian;
400 int file_long_size; 400 int file_long_size;
401 int file_page_size; 401 int file_page_size;
402 struct pevent *pevent = NULL; 402 struct tep_handle *pevent = NULL;
403 int err; 403 int err;
404 404
405 repipe = __repipe; 405 repipe = __repipe;
@@ -439,9 +439,9 @@ ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
439 439
440 pevent = tevent->pevent; 440 pevent = tevent->pevent;
441 441
442 pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); 442 tep_set_flag(pevent, TEP_NSEC_OUTPUT);
443 pevent_set_file_bigendian(pevent, file_bigendian); 443 tep_set_file_bigendian(pevent, file_bigendian);
444 pevent_set_host_bigendian(pevent, host_bigendian); 444 tep_set_host_bigendian(pevent, host_bigendian);
445 445
446 if (do_read(buf, 1) < 0) 446 if (do_read(buf, 1) < 0)
447 goto out; 447 goto out;
@@ -451,8 +451,8 @@ ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
451 if (!file_page_size) 451 if (!file_page_size)
452 goto out; 452 goto out;
453 453
454 pevent_set_long_size(pevent, file_long_size); 454 tep_set_long_size(pevent, file_long_size);
455 pevent_set_page_size(pevent, file_page_size); 455 tep_set_page_size(pevent, file_page_size);
456 456
457 err = read_header_files(pevent); 457 err = read_header_files(pevent);
458 if (err) 458 if (err)
@@ -479,9 +479,9 @@ ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
479 repipe = false; 479 repipe = false;
480 480
481 if (show_funcs) { 481 if (show_funcs) {
482 pevent_print_funcs(pevent); 482 tep_print_funcs(pevent);
483 } else if (show_printk) { 483 } else if (show_printk) {
484 pevent_print_printk(pevent); 484 tep_print_printk(pevent);
485 } 485 }
486 486
487 pevent = NULL; 487 pevent = NULL;
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index b1e5c3a2b8e3..b749f812ac70 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -66,7 +66,7 @@ static int python_start_script_unsupported(const char *script __maybe_unused,
66 return -1; 66 return -1;
67} 67}
68 68
69static int python_generate_script_unsupported(struct pevent *pevent 69static int python_generate_script_unsupported(struct tep_handle *pevent
70 __maybe_unused, 70 __maybe_unused,
71 const char *outfile 71 const char *outfile
72 __maybe_unused) 72 __maybe_unused)
@@ -130,7 +130,7 @@ static int perl_start_script_unsupported(const char *script __maybe_unused,
130 return -1; 130 return -1;
131} 131}
132 132
133static int perl_generate_script_unsupported(struct pevent *pevent 133static int perl_generate_script_unsupported(struct tep_handle *pevent
134 __maybe_unused, 134 __maybe_unused,
135 const char *outfile __maybe_unused) 135 const char *outfile __maybe_unused)
136{ 136{
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
index 1aa368603268..58bb72f266f3 100644
--- a/tools/perf/util/trace-event.c
+++ b/tools/perf/util/trace-event.c
@@ -28,10 +28,10 @@ static bool tevent_initialized;
28 28
29int trace_event__init(struct trace_event *t) 29int trace_event__init(struct trace_event *t)
30{ 30{
31 struct pevent *pevent = pevent_alloc(); 31 struct tep_handle *pevent = tep_alloc();
32 32
33 if (pevent) { 33 if (pevent) {
34 t->plugin_list = traceevent_load_plugins(pevent); 34 t->plugin_list = tep_load_plugins(pevent);
35 t->pevent = pevent; 35 t->pevent = pevent;
36 } 36 }
37 37
@@ -40,33 +40,33 @@ int trace_event__init(struct trace_event *t)
40 40
41static int trace_event__init2(void) 41static int trace_event__init2(void)
42{ 42{
43 int be = traceevent_host_bigendian(); 43 int be = tep_host_bigendian();
44 struct pevent *pevent; 44 struct tep_handle *pevent;
45 45
46 if (trace_event__init(&tevent)) 46 if (trace_event__init(&tevent))
47 return -1; 47 return -1;
48 48
49 pevent = tevent.pevent; 49 pevent = tevent.pevent;
50 pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); 50 tep_set_flag(pevent, TEP_NSEC_OUTPUT);
51 pevent_set_file_bigendian(pevent, be); 51 tep_set_file_bigendian(pevent, be);
52 pevent_set_host_bigendian(pevent, be); 52 tep_set_host_bigendian(pevent, be);
53 tevent_initialized = true; 53 tevent_initialized = true;
54 return 0; 54 return 0;
55} 55}
56 56
57int trace_event__register_resolver(struct machine *machine, 57int trace_event__register_resolver(struct machine *machine,
58 pevent_func_resolver_t *func) 58 tep_func_resolver_t *func)
59{ 59{
60 if (!tevent_initialized && trace_event__init2()) 60 if (!tevent_initialized && trace_event__init2())
61 return -1; 61 return -1;
62 62
63 return pevent_set_function_resolver(tevent.pevent, func, machine); 63 return tep_set_function_resolver(tevent.pevent, func, machine);
64} 64}
65 65
66void trace_event__cleanup(struct trace_event *t) 66void trace_event__cleanup(struct trace_event *t)
67{ 67{
68 traceevent_unload_plugins(t->plugin_list, t->pevent); 68 tep_unload_plugins(t->plugin_list, t->pevent);
69 pevent_free(t->pevent); 69 tep_free(t->pevent);
70} 70}
71 71
72/* 72/*
@@ -76,7 +76,7 @@ static struct event_format*
76tp_format(const char *sys, const char *name) 76tp_format(const char *sys, const char *name)
77{ 77{
78 char *tp_dir = get_events_file(sys); 78 char *tp_dir = get_events_file(sys);
79 struct pevent *pevent = tevent.pevent; 79 struct tep_handle *pevent = tevent.pevent;
80 struct event_format *event = NULL; 80 struct event_format *event = NULL;
81 char path[PATH_MAX]; 81 char path[PATH_MAX];
82 size_t size; 82 size_t size;
@@ -93,7 +93,7 @@ tp_format(const char *sys, const char *name)
93 if (err) 93 if (err)
94 return ERR_PTR(err); 94 return ERR_PTR(err);
95 95
96 pevent_parse_format(pevent, &event, data, size, sys); 96 tep_parse_format(pevent, &event, data, size, sys);
97 97
98 free(data); 98 free(data);
99 return event; 99 return event;
@@ -116,5 +116,5 @@ struct event_format *trace_event__tp_format_id(int id)
116 if (!tevent_initialized && trace_event__init2()) 116 if (!tevent_initialized && trace_event__init2())
117 return ERR_PTR(-ENOMEM); 117 return ERR_PTR(-ENOMEM);
118 118
119 return pevent_find_event(tevent.pevent, id); 119 return tep_find_event(tevent.pevent, id);
120} 120}
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index dcbdb53dc702..40204ec3a7a2 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -13,14 +13,14 @@ struct thread;
13struct plugin_list; 13struct plugin_list;
14 14
15struct trace_event { 15struct trace_event {
16 struct pevent *pevent; 16 struct tep_handle *pevent;
17 struct plugin_list *plugin_list; 17 struct plugin_list *plugin_list;
18}; 18};
19 19
20int trace_event__init(struct trace_event *t); 20int trace_event__init(struct trace_event *t);
21void trace_event__cleanup(struct trace_event *t); 21void trace_event__cleanup(struct trace_event *t);
22int trace_event__register_resolver(struct machine *machine, 22int trace_event__register_resolver(struct machine *machine,
23 pevent_func_resolver_t *func); 23 tep_func_resolver_t *func);
24struct event_format* 24struct event_format*
25trace_event__tp_format(const char *sys, const char *name); 25trace_event__tp_format(const char *sys, const char *name);
26 26
@@ -34,20 +34,20 @@ void event_format__fprintf(struct event_format *event,
34void event_format__print(struct event_format *event, 34void event_format__print(struct event_format *event,
35 int cpu, void *data, int size); 35 int cpu, void *data, int size);
36 36
37int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size); 37int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size);
38int parse_event_file(struct pevent *pevent, 38int parse_event_file(struct tep_handle *pevent,
39 char *buf, unsigned long size, char *sys); 39 char *buf, unsigned long size, char *sys);
40 40
41unsigned long long 41unsigned long long
42raw_field_value(struct event_format *event, const char *name, void *data); 42raw_field_value(struct event_format *event, const char *name, void *data);
43 43
44void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size); 44void parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
45void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size); 45void parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
46void parse_saved_cmdline(struct pevent *pevent, char *file, unsigned int size); 46void parse_saved_cmdline(struct tep_handle *pevent, char *file, unsigned int size);
47 47
48ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe); 48ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
49 49
50struct event_format *trace_find_next_event(struct pevent *pevent, 50struct event_format *trace_find_next_event(struct tep_handle *pevent,
51 struct event_format *event); 51 struct event_format *event);
52unsigned long long read_size(struct event_format *event, void *ptr, int size); 52unsigned long long read_size(struct event_format *event, void *ptr, int size);
53unsigned long long eval_flag(const char *flag); 53unsigned long long eval_flag(const char *flag);
@@ -83,7 +83,7 @@ struct scripting_ops {
83 void (*process_stat)(struct perf_stat_config *config, 83 void (*process_stat)(struct perf_stat_config *config,
84 struct perf_evsel *evsel, u64 tstamp); 84 struct perf_evsel *evsel, u64 tstamp);
85 void (*process_stat_interval)(u64 tstamp); 85 void (*process_stat_interval)(u64 tstamp);
86 int (*generate_script) (struct pevent *pevent, const char *outfile); 86 int (*generate_script) (struct tep_handle *pevent, const char *outfile);
87}; 87};
88 88
89extern unsigned int scripting_max_stack; 89extern unsigned int scripting_max_stack;
@@ -94,7 +94,7 @@ void setup_perl_scripting(void);
94void setup_python_scripting(void); 94void setup_python_scripting(void);
95 95
96struct scripting_context { 96struct scripting_context {
97 struct pevent *pevent; 97 struct tep_handle *pevent;
98 void *event_data; 98 void *event_data;
99}; 99};
100 100
diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c
index a725b958cf31..902ce6384f57 100644
--- a/tools/perf/util/zlib.c
+++ b/tools/perf/util/zlib.c
@@ -5,6 +5,8 @@
5#include <sys/stat.h> 5#include <sys/stat.h>
6#include <sys/mman.h> 6#include <sys/mman.h>
7#include <zlib.h> 7#include <zlib.h>
8#include <linux/compiler.h>
9#include <unistd.h>
8 10
9#include "util/compress.h" 11#include "util/compress.h"
10#include "util/util.h" 12#include "util/util.h"
@@ -79,3 +81,19 @@ out_close:
79 81
80 return ret == Z_STREAM_END ? 0 : -1; 82 return ret == Z_STREAM_END ? 0 : -1;
81} 83}
84
85bool gzip_is_compressed(const char *input)
86{
87 int fd = open(input, O_RDONLY);
88 const uint8_t magic[2] = { 0x1f, 0x8b };
89 char buf[2] = { 0 };
90 ssize_t rc;
91
92 if (fd < 0)
93 return -1;
94
95 rc = read(fd, buf, sizeof(buf));
96 close(fd);
97 return rc == sizeof(buf) ?
98 memcmp(buf, magic, sizeof(buf)) == 0 : false;
99}
diff --git a/tools/testing/nvdimm/pmem-dax.c b/tools/testing/nvdimm/pmem-dax.c
index b53596ad601b..2e7fd8227969 100644
--- a/tools/testing/nvdimm/pmem-dax.c
+++ b/tools/testing/nvdimm/pmem-dax.c
@@ -31,17 +31,21 @@ long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
31 if (get_nfit_res(pmem->phys_addr + offset)) { 31 if (get_nfit_res(pmem->phys_addr + offset)) {
32 struct page *page; 32 struct page *page;
33 33
34 *kaddr = pmem->virt_addr + offset; 34 if (kaddr)
35 *kaddr = pmem->virt_addr + offset;
35 page = vmalloc_to_page(pmem->virt_addr + offset); 36 page = vmalloc_to_page(pmem->virt_addr + offset);
36 *pfn = page_to_pfn_t(page); 37 if (pfn)
38 *pfn = page_to_pfn_t(page);
37 pr_debug_ratelimited("%s: pmem: %p pgoff: %#lx pfn: %#lx\n", 39 pr_debug_ratelimited("%s: pmem: %p pgoff: %#lx pfn: %#lx\n",
38 __func__, pmem, pgoff, page_to_pfn(page)); 40 __func__, pmem, pgoff, page_to_pfn(page));
39 41
40 return 1; 42 return 1;
41 } 43 }
42 44
43 *kaddr = pmem->virt_addr + offset; 45 if (kaddr)
44 *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags); 46 *kaddr = pmem->virt_addr + offset;
47 if (pfn)
48 *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags);
45 49
46 /* 50 /*
47 * If badblocks are present, limit known good range to the 51 * If badblocks are present, limit known good range to the
diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c
index e2926f72a821..cffc2c5a778d 100644
--- a/tools/testing/nvdimm/test/nfit.c
+++ b/tools/testing/nvdimm/test/nfit.c
@@ -142,6 +142,28 @@ static u32 handle[] = {
142static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 142static unsigned long dimm_fail_cmd_flags[NUM_DCR];
143static int dimm_fail_cmd_code[NUM_DCR]; 143static int dimm_fail_cmd_code[NUM_DCR];
144 144
145static const struct nd_intel_smart smart_def = {
146 .flags = ND_INTEL_SMART_HEALTH_VALID
147 | ND_INTEL_SMART_SPARES_VALID
148 | ND_INTEL_SMART_ALARM_VALID
149 | ND_INTEL_SMART_USED_VALID
150 | ND_INTEL_SMART_SHUTDOWN_VALID
151 | ND_INTEL_SMART_MTEMP_VALID
152 | ND_INTEL_SMART_CTEMP_VALID,
153 .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH,
154 .media_temperature = 23 * 16,
155 .ctrl_temperature = 25 * 16,
156 .pmic_temperature = 40 * 16,
157 .spares = 75,
158 .alarm_flags = ND_INTEL_SMART_SPARE_TRIP
159 | ND_INTEL_SMART_TEMP_TRIP,
160 .ait_status = 1,
161 .life_used = 5,
162 .shutdown_state = 0,
163 .vendor_size = 0,
164 .shutdown_count = 100,
165};
166
145struct nfit_test_fw { 167struct nfit_test_fw {
146 enum intel_fw_update_state state; 168 enum intel_fw_update_state state;
147 u32 context; 169 u32 context;
@@ -752,15 +774,30 @@ static int nfit_test_cmd_smart_inject(
752 if (buf_len != sizeof(*inj)) 774 if (buf_len != sizeof(*inj))
753 return -EINVAL; 775 return -EINVAL;
754 776
755 if (inj->mtemp_enable) 777 if (inj->flags & ND_INTEL_SMART_INJECT_MTEMP) {
756 smart->media_temperature = inj->media_temperature; 778 if (inj->mtemp_enable)
757 if (inj->spare_enable) 779 smart->media_temperature = inj->media_temperature;
758 smart->spares = inj->spares; 780 else
759 if (inj->fatal_enable) 781 smart->media_temperature = smart_def.media_temperature;
760 smart->health = ND_INTEL_SMART_FATAL_HEALTH; 782 }
761 if (inj->unsafe_shutdown_enable) { 783 if (inj->flags & ND_INTEL_SMART_INJECT_SPARE) {
762 smart->shutdown_state = 1; 784 if (inj->spare_enable)
763 smart->shutdown_count++; 785 smart->spares = inj->spares;
786 else
787 smart->spares = smart_def.spares;
788 }
789 if (inj->flags & ND_INTEL_SMART_INJECT_FATAL) {
790 if (inj->fatal_enable)
791 smart->health = ND_INTEL_SMART_FATAL_HEALTH;
792 else
793 smart->health = ND_INTEL_SMART_NON_CRITICAL_HEALTH;
794 }
795 if (inj->flags & ND_INTEL_SMART_INJECT_SHUTDOWN) {
796 if (inj->unsafe_shutdown_enable) {
797 smart->shutdown_state = 1;
798 smart->shutdown_count++;
799 } else
800 smart->shutdown_state = 0;
764 } 801 }
765 inj->status = 0; 802 inj->status = 0;
766 smart_notify(bus_dev, dimm_dev, smart, thresh); 803 smart_notify(bus_dev, dimm_dev, smart, thresh);
@@ -884,6 +921,16 @@ static int nd_intel_test_cmd_set_lss_status(struct nfit_test *t,
884 return 0; 921 return 0;
885} 922}
886 923
924static int override_return_code(int dimm, unsigned int func, int rc)
925{
926 if ((1 << func) & dimm_fail_cmd_flags[dimm]) {
927 if (dimm_fail_cmd_code[dimm])
928 return dimm_fail_cmd_code[dimm];
929 return -EIO;
930 }
931 return rc;
932}
933
887static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func) 934static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func)
888{ 935{
889 int i; 936 int i;
@@ -894,13 +941,6 @@ static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func)
894 break; 941 break;
895 if (i >= ARRAY_SIZE(handle)) 942 if (i >= ARRAY_SIZE(handle))
896 return -ENXIO; 943 return -ENXIO;
897
898 if ((1 << func) & dimm_fail_cmd_flags[i]) {
899 if (dimm_fail_cmd_code[i])
900 return dimm_fail_cmd_code[i];
901 return -EIO;
902 }
903
904 return i; 944 return i;
905} 945}
906 946
@@ -939,48 +979,59 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
939 979
940 switch (func) { 980 switch (func) {
941 case ND_INTEL_ENABLE_LSS_STATUS: 981 case ND_INTEL_ENABLE_LSS_STATUS:
942 return nd_intel_test_cmd_set_lss_status(t, 982 rc = nd_intel_test_cmd_set_lss_status(t,
943 buf, buf_len); 983 buf, buf_len);
984 break;
944 case ND_INTEL_FW_GET_INFO: 985 case ND_INTEL_FW_GET_INFO:
945 return nd_intel_test_get_fw_info(t, buf, 986 rc = nd_intel_test_get_fw_info(t, buf,
946 buf_len, i - t->dcr_idx); 987 buf_len, i - t->dcr_idx);
988 break;
947 case ND_INTEL_FW_START_UPDATE: 989 case ND_INTEL_FW_START_UPDATE:
948 return nd_intel_test_start_update(t, buf, 990 rc = nd_intel_test_start_update(t, buf,
949 buf_len, i - t->dcr_idx); 991 buf_len, i - t->dcr_idx);
992 break;
950 case ND_INTEL_FW_SEND_DATA: 993 case ND_INTEL_FW_SEND_DATA:
951 return nd_intel_test_send_data(t, buf, 994 rc = nd_intel_test_send_data(t, buf,
952 buf_len, i - t->dcr_idx); 995 buf_len, i - t->dcr_idx);
996 break;
953 case ND_INTEL_FW_FINISH_UPDATE: 997 case ND_INTEL_FW_FINISH_UPDATE:
954 return nd_intel_test_finish_fw(t, buf, 998 rc = nd_intel_test_finish_fw(t, buf,
955 buf_len, i - t->dcr_idx); 999 buf_len, i - t->dcr_idx);
1000 break;
956 case ND_INTEL_FW_FINISH_QUERY: 1001 case ND_INTEL_FW_FINISH_QUERY:
957 return nd_intel_test_finish_query(t, buf, 1002 rc = nd_intel_test_finish_query(t, buf,
958 buf_len, i - t->dcr_idx); 1003 buf_len, i - t->dcr_idx);
1004 break;
959 case ND_INTEL_SMART: 1005 case ND_INTEL_SMART:
960 return nfit_test_cmd_smart(buf, buf_len, 1006 rc = nfit_test_cmd_smart(buf, buf_len,
961 &t->smart[i - t->dcr_idx]); 1007 &t->smart[i - t->dcr_idx]);
1008 break;
962 case ND_INTEL_SMART_THRESHOLD: 1009 case ND_INTEL_SMART_THRESHOLD:
963 return nfit_test_cmd_smart_threshold(buf, 1010 rc = nfit_test_cmd_smart_threshold(buf,
964 buf_len, 1011 buf_len,
965 &t->smart_threshold[i - 1012 &t->smart_threshold[i -
966 t->dcr_idx]); 1013 t->dcr_idx]);
1014 break;
967 case ND_INTEL_SMART_SET_THRESHOLD: 1015 case ND_INTEL_SMART_SET_THRESHOLD:
968 return nfit_test_cmd_smart_set_threshold(buf, 1016 rc = nfit_test_cmd_smart_set_threshold(buf,
969 buf_len, 1017 buf_len,
970 &t->smart_threshold[i - 1018 &t->smart_threshold[i -
971 t->dcr_idx], 1019 t->dcr_idx],
972 &t->smart[i - t->dcr_idx], 1020 &t->smart[i - t->dcr_idx],
973 &t->pdev.dev, t->dimm_dev[i]); 1021 &t->pdev.dev, t->dimm_dev[i]);
1022 break;
974 case ND_INTEL_SMART_INJECT: 1023 case ND_INTEL_SMART_INJECT:
975 return nfit_test_cmd_smart_inject(buf, 1024 rc = nfit_test_cmd_smart_inject(buf,
976 buf_len, 1025 buf_len,
977 &t->smart_threshold[i - 1026 &t->smart_threshold[i -
978 t->dcr_idx], 1027 t->dcr_idx],
979 &t->smart[i - t->dcr_idx], 1028 &t->smart[i - t->dcr_idx],
980 &t->pdev.dev, t->dimm_dev[i]); 1029 &t->pdev.dev, t->dimm_dev[i]);
1030 break;
981 default: 1031 default:
982 return -ENOTTY; 1032 return -ENOTTY;
983 } 1033 }
1034 return override_return_code(i, func, rc);
984 } 1035 }
985 1036
986 if (!test_bit(cmd, &cmd_mask) 1037 if (!test_bit(cmd, &cmd_mask)
@@ -1006,6 +1057,7 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
1006 default: 1057 default:
1007 return -ENOTTY; 1058 return -ENOTTY;
1008 } 1059 }
1060 return override_return_code(i, func, rc);
1009 } else { 1061 } else {
1010 struct ars_state *ars_state = &t->ars_state; 1062 struct ars_state *ars_state = &t->ars_state;
1011 struct nd_cmd_pkg *call_pkg = buf; 1063 struct nd_cmd_pkg *call_pkg = buf;
@@ -1302,29 +1354,9 @@ static void smart_init(struct nfit_test *t)
1302 .ctrl_temperature = 30 * 16, 1354 .ctrl_temperature = 30 * 16,
1303 .spares = 5, 1355 .spares = 5,
1304 }; 1356 };
1305 const struct nd_intel_smart smart_data = {
1306 .flags = ND_INTEL_SMART_HEALTH_VALID
1307 | ND_INTEL_SMART_SPARES_VALID
1308 | ND_INTEL_SMART_ALARM_VALID
1309 | ND_INTEL_SMART_USED_VALID
1310 | ND_INTEL_SMART_SHUTDOWN_VALID
1311 | ND_INTEL_SMART_MTEMP_VALID,
1312 .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH,
1313 .media_temperature = 23 * 16,
1314 .ctrl_temperature = 25 * 16,
1315 .pmic_temperature = 40 * 16,
1316 .spares = 75,
1317 .alarm_flags = ND_INTEL_SMART_SPARE_TRIP
1318 | ND_INTEL_SMART_TEMP_TRIP,
1319 .ait_status = 1,
1320 .life_used = 5,
1321 .shutdown_state = 0,
1322 .vendor_size = 0,
1323 .shutdown_count = 100,
1324 };
1325 1357
1326 for (i = 0; i < t->num_dcr; i++) { 1358 for (i = 0; i < t->num_dcr; i++) {
1327 memcpy(&t->smart[i], &smart_data, sizeof(smart_data)); 1359 memcpy(&t->smart[i], &smart_def, sizeof(smart_def));
1328 memcpy(&t->smart_threshold[i], &smart_t_data, 1360 memcpy(&t->smart_threshold[i], &smart_t_data,
1329 sizeof(smart_t_data)); 1361 sizeof(smart_t_data));
1330 } 1362 }
diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree/Makefile
index db66f8a0d4be..37baecc3766f 100644
--- a/tools/testing/radix-tree/Makefile
+++ b/tools/testing/radix-tree/Makefile
@@ -1,7 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2 2
3CFLAGS += -I. -I../../include -g -O2 -Wall -D_LGPL_SOURCE -fsanitize=address 3CFLAGS += -I. -I../../include -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address \
4LDFLAGS += -fsanitize=address 4 -fsanitize=undefined
5LDFLAGS += -fsanitize=address -fsanitize=undefined
5LDLIBS+= -lpthread -lurcu 6LDLIBS+= -lpthread -lurcu
6TARGETS = main idr-test multiorder 7TARGETS = main idr-test multiorder
7CORE_OFILES := radix-tree.o idr.o linux.o test.o find_bit.o 8CORE_OFILES := radix-tree.o idr.o linux.o test.o find_bit.o
@@ -21,6 +22,7 @@ targets: generated/map-shift.h $(TARGETS)
21 22
22main: $(OFILES) 23main: $(OFILES)
23 24
25idr-test.o: ../../../lib/test_ida.c
24idr-test: idr-test.o $(CORE_OFILES) 26idr-test: idr-test.o $(CORE_OFILES)
25 27
26multiorder: multiorder.o $(CORE_OFILES) 28multiorder: multiorder.o $(CORE_OFILES)
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
index ee820fcc29b0..321ba92c70d2 100644
--- a/tools/testing/radix-tree/idr-test.c
+++ b/tools/testing/radix-tree/idr-test.c
@@ -309,141 +309,61 @@ void idr_checks(void)
309 idr_u32_test(0); 309 idr_u32_test(0);
310} 310}
311 311
312#define module_init(x)
313#define module_exit(x)
314#define MODULE_AUTHOR(x)
315#define MODULE_LICENSE(x)
316#define dump_stack() assert(0)
317void ida_dump(struct ida *);
318
319#include "../../../lib/test_ida.c"
320
312/* 321/*
313 * Check that we get the correct error when we run out of memory doing 322 * Check that we get the correct error when we run out of memory doing
314 * allocations. To ensure we run out of memory, just "forget" to preload. 323 * allocations. In userspace, GFP_NOWAIT will always fail an allocation.
315 * The first test is for not having a bitmap available, and the second test 324 * The first test is for not having a bitmap available, and the second test
316 * is for not being able to allocate a level of the radix tree. 325 * is for not being able to allocate a level of the radix tree.
317 */ 326 */
318void ida_check_nomem(void) 327void ida_check_nomem(void)
319{ 328{
320 DEFINE_IDA(ida); 329 DEFINE_IDA(ida);
321 int id, err;
322
323 err = ida_get_new_above(&ida, 256, &id);
324 assert(err == -EAGAIN);
325 err = ida_get_new_above(&ida, 1UL << 30, &id);
326 assert(err == -EAGAIN);
327}
328
329/*
330 * Check what happens when we fill a leaf and then delete it. This may
331 * discover mishandling of IDR_FREE.
332 */
333void ida_check_leaf(void)
334{
335 DEFINE_IDA(ida);
336 int id; 330 int id;
337 unsigned long i;
338 331
339 for (i = 0; i < IDA_BITMAP_BITS; i++) { 332 id = ida_alloc_min(&ida, 256, GFP_NOWAIT);
340 assert(ida_pre_get(&ida, GFP_KERNEL)); 333 IDA_BUG_ON(&ida, id != -ENOMEM);
341 assert(!ida_get_new(&ida, &id)); 334 id = ida_alloc_min(&ida, 1UL << 30, GFP_NOWAIT);
342 assert(id == i); 335 IDA_BUG_ON(&ida, id != -ENOMEM);
343 } 336 IDA_BUG_ON(&ida, !ida_is_empty(&ida));
344
345 ida_destroy(&ida);
346 assert(ida_is_empty(&ida));
347
348 assert(ida_pre_get(&ida, GFP_KERNEL));
349 assert(!ida_get_new(&ida, &id));
350 assert(id == 0);
351 ida_destroy(&ida);
352 assert(ida_is_empty(&ida));
353} 337}
354 338
355/* 339/*
356 * Check handling of conversions between exceptional entries and full bitmaps. 340 * Check handling of conversions between exceptional entries and full bitmaps.
357 */ 341 */
358void ida_check_conv(void) 342void ida_check_conv_user(void)
359{ 343{
360 DEFINE_IDA(ida); 344 DEFINE_IDA(ida);
361 int id;
362 unsigned long i; 345 unsigned long i;
363 346
364 for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) {
365 assert(ida_pre_get(&ida, GFP_KERNEL));
366 assert(!ida_get_new_above(&ida, i + 1, &id));
367 assert(id == i + 1);
368 assert(!ida_get_new_above(&ida, i + BITS_PER_LONG, &id));
369 assert(id == i + BITS_PER_LONG);
370 ida_remove(&ida, i + 1);
371 ida_remove(&ida, i + BITS_PER_LONG);
372 assert(ida_is_empty(&ida));
373 }
374
375 assert(ida_pre_get(&ida, GFP_KERNEL));
376
377 for (i = 0; i < IDA_BITMAP_BITS * 2; i++) {
378 assert(ida_pre_get(&ida, GFP_KERNEL));
379 assert(!ida_get_new(&ida, &id));
380 assert(id == i);
381 }
382
383 for (i = IDA_BITMAP_BITS * 2; i > 0; i--) {
384 ida_remove(&ida, i - 1);
385 }
386 assert(ida_is_empty(&ida));
387
388 for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++) {
389 assert(ida_pre_get(&ida, GFP_KERNEL));
390 assert(!ida_get_new(&ida, &id));
391 assert(id == i);
392 }
393
394 for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--) {
395 ida_remove(&ida, i - 1);
396 }
397 assert(ida_is_empty(&ida));
398
399 radix_tree_cpu_dead(1); 347 radix_tree_cpu_dead(1);
400 for (i = 0; i < 1000000; i++) { 348 for (i = 0; i < 1000000; i++) {
401 int err = ida_get_new(&ida, &id); 349 int id = ida_alloc(&ida, GFP_NOWAIT);
402 if (err == -EAGAIN) { 350 if (id == -ENOMEM) {
403 assert((i % IDA_BITMAP_BITS) == (BITS_PER_LONG - 2)); 351 IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) !=
404 assert(ida_pre_get(&ida, GFP_KERNEL)); 352 BITS_PER_LONG - 2);
405 err = ida_get_new(&ida, &id); 353 id = ida_alloc(&ida, GFP_KERNEL);
406 } else { 354 } else {
407 assert((i % IDA_BITMAP_BITS) != (BITS_PER_LONG - 2)); 355 IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) ==
356 BITS_PER_LONG - 2);
408 } 357 }
409 assert(!err); 358 IDA_BUG_ON(&ida, id != i);
410 assert(id == i);
411 } 359 }
412 ida_destroy(&ida); 360 ida_destroy(&ida);
413} 361}
414 362
415/*
416 * Check allocations up to and slightly above the maximum allowed (2^31-1) ID.
417 * Allocating up to 2^31-1 should succeed, and then allocating the next one
418 * should fail.
419 */
420void ida_check_max(void)
421{
422 DEFINE_IDA(ida);
423 int id, err;
424 unsigned long i, j;
425
426 for (j = 1; j < 65537; j *= 2) {
427 unsigned long base = (1UL << 31) - j;
428 for (i = 0; i < j; i++) {
429 assert(ida_pre_get(&ida, GFP_KERNEL));
430 assert(!ida_get_new_above(&ida, base, &id));
431 assert(id == base + i);
432 }
433 assert(ida_pre_get(&ida, GFP_KERNEL));
434 err = ida_get_new_above(&ida, base, &id);
435 assert(err == -ENOSPC);
436 ida_destroy(&ida);
437 assert(ida_is_empty(&ida));
438 rcu_barrier();
439 }
440}
441
442void ida_check_random(void) 363void ida_check_random(void)
443{ 364{
444 DEFINE_IDA(ida); 365 DEFINE_IDA(ida);
445 DECLARE_BITMAP(bitmap, 2048); 366 DECLARE_BITMAP(bitmap, 2048);
446 int id, err;
447 unsigned int i; 367 unsigned int i;
448 time_t s = time(NULL); 368 time_t s = time(NULL);
449 369
@@ -454,15 +374,11 @@ void ida_check_random(void)
454 int bit = i & 2047; 374 int bit = i & 2047;
455 if (test_bit(bit, bitmap)) { 375 if (test_bit(bit, bitmap)) {
456 __clear_bit(bit, bitmap); 376 __clear_bit(bit, bitmap);
457 ida_remove(&ida, bit); 377 ida_free(&ida, bit);
458 } else { 378 } else {
459 __set_bit(bit, bitmap); 379 __set_bit(bit, bitmap);
460 do { 380 IDA_BUG_ON(&ida, ida_alloc_min(&ida, bit, GFP_KERNEL)
461 ida_pre_get(&ida, GFP_KERNEL); 381 != bit);
462 err = ida_get_new_above(&ida, bit, &id);
463 } while (err == -EAGAIN);
464 assert(!err);
465 assert(id == bit);
466 } 382 }
467 } 383 }
468 ida_destroy(&ida); 384 ida_destroy(&ida);
@@ -488,71 +404,12 @@ void ida_simple_get_remove_test(void)
488 ida_destroy(&ida); 404 ida_destroy(&ida);
489} 405}
490 406
491void ida_checks(void) 407void user_ida_checks(void)
492{ 408{
493 DEFINE_IDA(ida);
494 int id;
495 unsigned long i;
496
497 radix_tree_cpu_dead(1); 409 radix_tree_cpu_dead(1);
498 ida_check_nomem();
499
500 for (i = 0; i < 10000; i++) {
501 assert(ida_pre_get(&ida, GFP_KERNEL));
502 assert(!ida_get_new(&ida, &id));
503 assert(id == i);
504 }
505
506 ida_remove(&ida, 20);
507 ida_remove(&ida, 21);
508 for (i = 0; i < 3; i++) {
509 assert(ida_pre_get(&ida, GFP_KERNEL));
510 assert(!ida_get_new(&ida, &id));
511 if (i == 2)
512 assert(id == 10000);
513 }
514
515 for (i = 0; i < 5000; i++)
516 ida_remove(&ida, i);
517
518 assert(ida_pre_get(&ida, GFP_KERNEL));
519 assert(!ida_get_new_above(&ida, 5000, &id));
520 assert(id == 10001);
521
522 ida_destroy(&ida);
523
524 assert(ida_is_empty(&ida));
525 410
526 assert(ida_pre_get(&ida, GFP_KERNEL)); 411 ida_check_nomem();
527 assert(!ida_get_new_above(&ida, 1, &id)); 412 ida_check_conv_user();
528 assert(id == 1);
529
530 ida_remove(&ida, id);
531 assert(ida_is_empty(&ida));
532 ida_destroy(&ida);
533 assert(ida_is_empty(&ida));
534
535 assert(ida_pre_get(&ida, GFP_KERNEL));
536 assert(!ida_get_new_above(&ida, 1, &id));
537 ida_destroy(&ida);
538 assert(ida_is_empty(&ida));
539
540 assert(ida_pre_get(&ida, GFP_KERNEL));
541 assert(!ida_get_new_above(&ida, 1, &id));
542 assert(id == 1);
543 assert(ida_pre_get(&ida, GFP_KERNEL));
544 assert(!ida_get_new_above(&ida, 1025, &id));
545 assert(id == 1025);
546 assert(ida_pre_get(&ida, GFP_KERNEL));
547 assert(!ida_get_new_above(&ida, 10000, &id));
548 assert(id == 10000);
549 ida_remove(&ida, 1025);
550 ida_destroy(&ida);
551 assert(ida_is_empty(&ida));
552
553 ida_check_leaf();
554 ida_check_max();
555 ida_check_conv();
556 ida_check_random(); 413 ida_check_random();
557 ida_simple_get_remove_test(); 414 ida_simple_get_remove_test();
558 415
@@ -582,12 +439,19 @@ void ida_thread_tests(void)
582 pthread_join(threads[i], NULL); 439 pthread_join(threads[i], NULL);
583} 440}
584 441
442void ida_tests(void)
443{
444 user_ida_checks();
445 ida_checks();
446 ida_exit();
447 ida_thread_tests();
448}
449
585int __weak main(void) 450int __weak main(void)
586{ 451{
587 radix_tree_init(); 452 radix_tree_init();
588 idr_checks(); 453 idr_checks();
589 ida_checks(); 454 ida_tests();
590 ida_thread_tests();
591 radix_tree_cpu_dead(1); 455 radix_tree_cpu_dead(1);
592 rcu_barrier(); 456 rcu_barrier();
593 if (nr_allocated) 457 if (nr_allocated)
diff --git a/tools/testing/radix-tree/linux/xarray.h b/tools/testing/radix-tree/linux/xarray.h
new file mode 100644
index 000000000000..df3812cda376
--- /dev/null
+++ b/tools/testing/radix-tree/linux/xarray.h
@@ -0,0 +1,2 @@
1#include "generated/map-shift.h"
2#include "../../../../include/linux/xarray.h"
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c
index 257f3f8aacaa..b741686e53d6 100644
--- a/tools/testing/radix-tree/main.c
+++ b/tools/testing/radix-tree/main.c
@@ -27,20 +27,22 @@ void __gang_check(unsigned long middle, long down, long up, int chunk, int hop)
27 item_check_present(&tree, middle + idx); 27 item_check_present(&tree, middle + idx);
28 item_check_absent(&tree, middle + up); 28 item_check_absent(&tree, middle + up);
29 29
30 item_gang_check_present(&tree, middle - down, 30 if (chunk > 0) {
31 up + down, chunk, hop); 31 item_gang_check_present(&tree, middle - down, up + down,
32 item_full_scan(&tree, middle - down, down + up, chunk); 32 chunk, hop);
33 item_full_scan(&tree, middle - down, down + up, chunk);
34 }
33 item_kill_tree(&tree); 35 item_kill_tree(&tree);
34} 36}
35 37
36void gang_check(void) 38void gang_check(void)
37{ 39{
38 __gang_check(1 << 30, 128, 128, 35, 2); 40 __gang_check(1UL << 30, 128, 128, 35, 2);
39 __gang_check(1 << 31, 128, 128, 32, 32); 41 __gang_check(1UL << 31, 128, 128, 32, 32);
40 __gang_check(1 << 31, 128, 128, 32, 100); 42 __gang_check(1UL << 31, 128, 128, 32, 100);
41 __gang_check(1 << 31, 128, 128, 17, 7); 43 __gang_check(1UL << 31, 128, 128, 17, 7);
42 __gang_check(0xffff0000, 0, 65536, 17, 7); 44 __gang_check(0xffff0000UL, 0, 65536, 17, 7);
43 __gang_check(0xfffffffe, 1, 1, 17, 7); 45 __gang_check(0xfffffffeUL, 1, 1, 17, 7);
44} 46}
45 47
46void __big_gang_check(void) 48void __big_gang_check(void)
@@ -322,7 +324,7 @@ static void single_thread_tests(bool long_run)
322 printv(2, "after dynamic_height_check: %d allocated, preempt %d\n", 324 printv(2, "after dynamic_height_check: %d allocated, preempt %d\n",
323 nr_allocated, preempt_count); 325 nr_allocated, preempt_count);
324 idr_checks(); 326 idr_checks();
325 ida_checks(); 327 ida_tests();
326 rcu_barrier(); 328 rcu_barrier();
327 printv(2, "after idr_checks: %d allocated, preempt %d\n", 329 printv(2, "after idr_checks: %d allocated, preempt %d\n",
328 nr_allocated, preempt_count); 330 nr_allocated, preempt_count);
@@ -369,7 +371,6 @@ int main(int argc, char **argv)
369 iteration_test(0, 10 + 90 * long_run); 371 iteration_test(0, 10 + 90 * long_run);
370 iteration_test(7, 10 + 90 * long_run); 372 iteration_test(7, 10 + 90 * long_run);
371 single_thread_tests(long_run); 373 single_thread_tests(long_run);
372 ida_thread_tests();
373 374
374 /* Free any remaining preallocated nodes */ 375 /* Free any remaining preallocated nodes */
375 radix_tree_cpu_dead(0); 376 radix_tree_cpu_dead(0);
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h
index 31f1d9b6f506..92d901eacf49 100644
--- a/tools/testing/radix-tree/test.h
+++ b/tools/testing/radix-tree/test.h
@@ -39,8 +39,7 @@ void multiorder_checks(void);
39void iteration_test(unsigned order, unsigned duration); 39void iteration_test(unsigned order, unsigned duration);
40void benchmark(void); 40void benchmark(void);
41void idr_checks(void); 41void idr_checks(void);
42void ida_checks(void); 42void ida_tests(void);
43void ida_thread_tests(void);
44 43
45struct item * 44struct item *
46item_tag_set(struct radix_tree_root *root, unsigned long index, int tag); 45item_tag_set(struct radix_tree_root *root, unsigned long index, int tag);
diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh
index f8cc38afffa2..32a194e3e07a 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -46,6 +46,9 @@
46# Kselftest framework requirement - SKIP code is 4. 46# Kselftest framework requirement - SKIP code is 4.
47ksft_skip=4 47ksft_skip=4
48 48
49# Some systems don't have a ping6 binary anymore
50which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
51
49tests=" 52tests="
50 pmtu_vti6_exception vti6: PMTU exceptions 53 pmtu_vti6_exception vti6: PMTU exceptions
51 pmtu_vti4_exception vti4: PMTU exceptions 54 pmtu_vti4_exception vti4: PMTU exceptions
@@ -274,7 +277,7 @@ test_pmtu_vti6_exception() {
274 mtu "${ns_b}" veth_b 4000 277 mtu "${ns_b}" veth_b 4000
275 mtu "${ns_a}" vti6_a 5000 278 mtu "${ns_a}" vti6_a 5000
276 mtu "${ns_b}" vti6_b 5000 279 mtu "${ns_b}" vti6_b 5000
277 ${ns_a} ping6 -q -i 0.1 -w 2 -s 60000 ${vti6_b_addr} > /dev/null 280 ${ns_a} ${ping6} -q -i 0.1 -w 2 -s 60000 ${vti6_b_addr} > /dev/null
278 281
279 # Check that exception was created 282 # Check that exception was created
280 if [ "$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" = "" ]; then 283 if [ "$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" = "" ]; then
@@ -334,7 +337,7 @@ test_pmtu_vti4_link_add_mtu() {
334 fail=0 337 fail=0
335 338
336 min=68 339 min=68
337 max=$((65528 - 20)) 340 max=$((65535 - 20))
338 # Check invalid values first 341 # Check invalid values first
339 for v in $((min - 1)) $((max + 1)); do 342 for v in $((min - 1)) $((max + 1)); do
340 ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 2>/dev/null 343 ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10 2>/dev/null
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/police.json b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
index f03763d81617..30f9b54bd666 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json
@@ -313,6 +313,54 @@
313 ] 313 ]
314 }, 314 },
315 { 315 {
316 "id": "6aaf",
317 "name": "Add police actions with conform-exceed control pass/pipe [with numeric values]",
318 "category": [
319 "actions",
320 "police"
321 ],
322 "setup": [
323 [
324 "$TC actions flush action police",
325 0,
326 1,
327 255
328 ]
329 ],
330 "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed 0/3 index 1",
331 "expExitCode": "0",
332 "verifyCmd": "$TC actions get action police index 1",
333 "matchPattern": "action order [0-9]*: police 0x1 rate 3Mbit burst 250Kb mtu 2Kb action pass/pipe",
334 "matchCount": "1",
335 "teardown": [
336 "$TC actions flush action police"
337 ]
338 },
339 {
340 "id": "29b1",
341 "name": "Add police actions with conform-exceed control <invalid>/drop",
342 "category": [
343 "actions",
344 "police"
345 ],
346 "setup": [
347 [
348 "$TC actions flush action police",
349 0,
350 1,
351 255
352 ]
353 ],
354 "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed 10/drop index 1",
355 "expExitCode": "255",
356 "verifyCmd": "$TC actions ls action police",
357 "matchPattern": "action order [0-9]*: police 0x1 rate 3Mbit burst 250Kb mtu 2Kb action ",
358 "matchCount": "0",
359 "teardown": [
360 "$TC actions flush action police"
361 ]
362 },
363 {
316 "id": "c26f", 364 "id": "c26f",
317 "name": "Add police action with invalid peakrate value", 365 "name": "Add police action with invalid peakrate value",
318 "category": [ 366 "category": [
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c
index 30cb0a0713ff..37908a83ddc2 100644
--- a/tools/vm/page-types.c
+++ b/tools/vm/page-types.c
@@ -159,12 +159,6 @@ static const char * const page_flag_names[] = {
159}; 159};
160 160
161 161
162static const char * const debugfs_known_mountpoints[] = {
163 "/sys/kernel/debug",
164 "/debug",
165 0,
166};
167
168/* 162/*
169 * data structures 163 * data structures
170 */ 164 */
diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c
index f82c2eaa859d..334b16db0ebb 100644
--- a/tools/vm/slabinfo.c
+++ b/tools/vm/slabinfo.c
@@ -30,8 +30,8 @@ struct slabinfo {
30 int alias; 30 int alias;
31 int refs; 31 int refs;
32 int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu; 32 int aliases, align, cache_dma, cpu_slabs, destroy_by_rcu;
33 int hwcache_align, object_size, objs_per_slab; 33 unsigned int hwcache_align, object_size, objs_per_slab;
34 int sanity_checks, slab_size, store_user, trace; 34 unsigned int sanity_checks, slab_size, store_user, trace;
35 int order, poison, reclaim_account, red_zone; 35 int order, poison, reclaim_account, red_zone;
36 unsigned long partial, objects, slabs, objects_partial, objects_total; 36 unsigned long partial, objects, slabs, objects_partial, objects_total;
37 unsigned long alloc_fastpath, alloc_slowpath; 37 unsigned long alloc_fastpath, alloc_slowpath;
diff --git a/usr/Makefile b/usr/Makefile
index 237a028693ce..748f6a60bb1e 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -24,7 +24,7 @@ $(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
24# Generate the initramfs cpio archive 24# Generate the initramfs cpio archive
25 25
26hostprogs-y := gen_init_cpio 26hostprogs-y := gen_init_cpio
27initramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh 27initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs_list.sh
28ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \ 28ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
29 $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d) 29 $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
30ramfs-args := \ 30ramfs-args := \
diff --git a/scripts/gen_initramfs_list.sh b/usr/gen_initramfs_list.sh
index 10e528b3a08f..0aad760fcd8c 100755
--- a/scripts/gen_initramfs_list.sh
+++ b/usr/gen_initramfs_list.sh
@@ -174,7 +174,7 @@ dir_filelist() {
174 ${dep_list}header "$1" 174 ${dep_list}header "$1"
175 175
176 srcdir=$(echo "$1" | sed -e 's://*:/:g') 176 srcdir=$(echo "$1" | sed -e 's://*:/:g')
177 dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | sort) 177 dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort)
178 178
179 # If $dirlist is only one line, then the directory is empty 179 # If $dirlist is only one line, then the directory is empty
180 if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then 180 if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then
diff --git a/usr/initramfs_data.S b/usr/initramfs_data.S
index b28da799f6a6..d07648f05bbf 100644
--- a/usr/initramfs_data.S
+++ b/usr/initramfs_data.S
@@ -30,8 +30,8 @@ __irf_start:
30.incbin __stringify(INITRAMFS_IMAGE) 30.incbin __stringify(INITRAMFS_IMAGE)
31__irf_end: 31__irf_end:
32.section .init.ramfs.info,"a" 32.section .init.ramfs.info,"a"
33.globl VMLINUX_SYMBOL(__initramfs_size) 33.globl __initramfs_size
34VMLINUX_SYMBOL(__initramfs_size): 34__initramfs_size:
35#ifdef CONFIG_64BIT 35#ifdef CONFIG_64BIT
36 .quad __irf_end - __irf_start 36 .quad __irf_end - __irf_start
37#else 37#else
diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
index 91aaf73b00df..ed162a6c57c5 100644
--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -1817,18 +1817,6 @@ static int kvm_unmap_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *dat
1817 return 0; 1817 return 0;
1818} 1818}
1819 1819
1820int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
1821{
1822 unsigned long end = hva + PAGE_SIZE;
1823
1824 if (!kvm->arch.pgd)
1825 return 0;
1826
1827 trace_kvm_unmap_hva(hva);
1828 handle_hva_to_gpa(kvm, hva, end, &kvm_unmap_hva_handler, NULL);
1829 return 0;
1830}
1831
1832int kvm_unmap_hva_range(struct kvm *kvm, 1820int kvm_unmap_hva_range(struct kvm *kvm,
1833 unsigned long start, unsigned long end) 1821 unsigned long start, unsigned long end)
1834{ 1822{
@@ -1860,13 +1848,20 @@ static int kvm_set_spte_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data
1860void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) 1848void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte)
1861{ 1849{
1862 unsigned long end = hva + PAGE_SIZE; 1850 unsigned long end = hva + PAGE_SIZE;
1851 kvm_pfn_t pfn = pte_pfn(pte);
1863 pte_t stage2_pte; 1852 pte_t stage2_pte;
1864 1853
1865 if (!kvm->arch.pgd) 1854 if (!kvm->arch.pgd)
1866 return; 1855 return;
1867 1856
1868 trace_kvm_set_spte_hva(hva); 1857 trace_kvm_set_spte_hva(hva);
1869 stage2_pte = pfn_pte(pte_pfn(pte), PAGE_S2); 1858
1859 /*
1860 * We've moved a page around, probably through CoW, so let's treat it
1861 * just like a translation fault and clean the cache to the PoC.
1862 */
1863 clean_dcache_guest_page(pfn, PAGE_SIZE);
1864 stage2_pte = pfn_pte(pfn, PAGE_S2);
1870 handle_hva_to_gpa(kvm, hva, end, &kvm_set_spte_handler, &stage2_pte); 1865 handle_hva_to_gpa(kvm, hva, end, &kvm_set_spte_handler, &stage2_pte);
1871} 1866}
1872 1867
diff --git a/virt/kvm/arm/trace.h b/virt/kvm/arm/trace.h
index e53b596f483b..57b3edebbb40 100644
--- a/virt/kvm/arm/trace.h
+++ b/virt/kvm/arm/trace.h
@@ -134,21 +134,6 @@ TRACE_EVENT(kvm_mmio_emulate,
134 __entry->vcpu_pc, __entry->instr, __entry->cpsr) 134 __entry->vcpu_pc, __entry->instr, __entry->cpsr)
135); 135);
136 136
137TRACE_EVENT(kvm_unmap_hva,
138 TP_PROTO(unsigned long hva),
139 TP_ARGS(hva),
140
141 TP_STRUCT__entry(
142 __field( unsigned long, hva )
143 ),
144
145 TP_fast_assign(
146 __entry->hva = hva;
147 ),
148
149 TP_printk("mmu notifier unmap hva: %#08lx", __entry->hva)
150);
151
152TRACE_EVENT(kvm_unmap_hva_range, 137TRACE_EVENT(kvm_unmap_hva_range,
153 TP_PROTO(unsigned long start, unsigned long end), 138 TP_PROTO(unsigned long start, unsigned long end),
154 TP_ARGS(start, end), 139 TP_ARGS(start, end),