aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/PCI/MSI-HOWTO.txt24
-rw-r--r--Documentation/arm64/silicon-errata.txt1
-rw-r--r--Documentation/block/queue-sysfs.txt18
-rw-r--r--Documentation/conf.py2
-rw-r--r--Documentation/devicetree/bindings/sound/omap-mcpdm.txt10
-rw-r--r--Documentation/devicetree/bindings/thermal/thermal.txt10
-rw-r--r--Documentation/hwmon/ftsteutates4
-rw-r--r--Documentation/kernel-documentation.rst6
-rw-r--r--Documentation/kernel-parameters.txt4
-rw-r--r--Documentation/networking/rxrpc.txt21
-rw-r--r--Documentation/power/basic-pm-debugging.txt27
-rw-r--r--Documentation/power/interface.txt151
-rw-r--r--Documentation/sphinx-static/theme_overrides.css3
-rw-r--r--MAINTAINERS18
-rw-r--r--Makefile2
-rw-r--r--arch/arc/include/asm/entry.h4
-rw-r--r--arch/arc/include/asm/irqflags-compact.h2
-rw-r--r--arch/arc/include/asm/pgtable.h2
-rw-r--r--arch/arc/include/uapi/asm/elf.h11
-rw-r--r--arch/arc/kernel/arcksyms.c2
-rw-r--r--arch/arc/kernel/process.c2
-rw-r--r--arch/arc/kernel/setup.c6
-rw-r--r--arch/arc/mm/cache.c9
-rw-r--r--arch/arc/mm/highmem.c1
-rw-r--r--arch/arm/Makefile2
-rw-r--r--arch/arm/boot/dts/arm-realview-pbx-a9.dts9
-rw-r--r--arch/arm/boot/dts/integratorap.dts2
-rw-r--r--arch/arm/boot/dts/integratorcp.dts2
-rw-r--r--arch/arm/boot/dts/keystone.dtsi8
-rw-r--r--arch/arm/boot/dts/tegra124-jetson-tk1.dts4
-rw-r--r--arch/arm/configs/aspeed_g4_defconfig2
-rw-r--r--arch/arm/configs/aspeed_g5_defconfig2
-rw-r--r--arch/arm/kernel/entry-armv.S1
-rw-r--r--arch/arm/kernel/sys_oabi-compat.c8
-rw-r--r--arch/arm/kvm/arm.c6
-rw-r--r--arch/arm/kvm/mmu.c2
-rw-r--r--arch/arm/mach-clps711x/Kconfig2
-rw-r--r--arch/arm/mach-imx/gpc.c6
-rw-r--r--arch/arm/mach-mvebu/Makefile3
-rw-r--r--arch/arm/mach-oxnas/Kconfig2
-rw-r--r--arch/arm/mach-pxa/corgi.c1
-rw-r--r--arch/arm/mach-pxa/spitz.c1
-rw-r--r--arch/arm/mach-realview/Makefile3
-rw-r--r--arch/arm/mach-s5pv210/Makefile2
-rw-r--r--arch/arm/mach-shmobile/platsmp.c3
-rw-r--r--arch/arm/mm/mmu.c21
-rw-r--r--arch/arm/xen/enlighten.c2
-rw-r--r--arch/arm64/Kconfig.platforms4
-rw-r--r--arch/arm64/boot/dts/exynos/exynos7-espresso.dts3
-rw-r--r--arch/arm64/configs/defconfig53
-rw-r--r--arch/arm64/include/asm/kprobes.h2
-rw-r--r--arch/arm64/kernel/entry.S7
-rw-r--r--arch/arm64/kernel/head.S3
-rw-r--r--arch/arm64/kernel/hibernate.c82
-rw-r--r--arch/arm64/kernel/probes/kprobes.c31
-rw-r--r--arch/arm64/kernel/sleep.S10
-rw-r--r--arch/arm64/kernel/smp.c8
-rw-r--r--arch/arm64/kvm/hyp/switch.c2
-rw-r--r--arch/arm64/kvm/sys_regs.c10
-rw-r--r--arch/arm64/mm/dump.c6
-rw-r--r--arch/arm64/mm/fault.c14
-rw-r--r--arch/arm64/mm/numa.c2
-rw-r--r--arch/h8300/include/asm/io.h2
-rw-r--r--arch/m68k/kernel/signal.c1
-rw-r--r--arch/metag/mm/init.c1
-rw-r--r--arch/mips/include/asm/page.h4
-rw-r--r--arch/mips/kvm/emulate.c35
-rw-r--r--arch/mips/kvm/mmu.c70
-rw-r--r--arch/parisc/include/uapi/asm/errno.h4
-rw-r--r--arch/parisc/kernel/processor.c8
-rw-r--r--arch/parisc/kernel/time.c12
-rw-r--r--arch/powerpc/Makefile22
-rw-r--r--arch/powerpc/crypto/crc32c-vpmsum_glue.c3
-rw-r--r--arch/powerpc/include/asm/cpuidle.h13
-rw-r--r--arch/powerpc/include/asm/feature-fixups.h1
-rw-r--r--arch/powerpc/include/asm/switch_to.h8
-rw-r--r--arch/powerpc/include/asm/xics.h2
-rw-r--r--arch/powerpc/kernel/eeh.c4
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S69
-rw-r--r--arch/powerpc/kernel/idle_book3s.S17
-rw-r--r--arch/powerpc/kernel/mce.c3
-rw-r--r--arch/powerpc/kernel/pci-common.c7
-rw-r--r--arch/powerpc/kernel/process.c20
-rw-r--r--arch/powerpc/kernel/prom_init.c2
-rw-r--r--arch/powerpc/kernel/ptrace.c19
-rw-r--r--arch/powerpc/kernel/setup_32.c9
-rw-r--r--arch/powerpc/kernel/setup_64.c1
-rw-r--r--arch/powerpc/kernel/vdso.c1
-rw-r--r--arch/powerpc/kernel/vdso32/Makefile6
-rw-r--r--arch/powerpc/kernel/vdso64/Makefile6
-rw-r--r--arch/powerpc/kvm/book3s_xics.c12
-rw-r--r--arch/powerpc/lib/checksum_32.S7
-rw-r--r--arch/powerpc/lib/feature-fixups.c3
-rw-r--r--arch/powerpc/platforms/cell/spufs/inode.c4
-rw-r--r--arch/powerpc/platforms/pasemi/iommu.c5
-rw-r--r--arch/powerpc/platforms/powernv/opal-irqchip.c3
-rw-r--r--arch/powerpc/platforms/powernv/opal.c1
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c32
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-memory.c26
-rw-r--r--arch/powerpc/sysdev/xics/Kconfig1
-rw-r--r--arch/powerpc/sysdev/xics/ics-opal.c4
-rw-r--r--arch/powerpc/sysdev/xics/ics-rtas.c4
-rw-r--r--arch/powerpc/sysdev/xics/xics-common.c59
-rw-r--r--arch/s390/Kconfig13
-rw-r--r--arch/s390/boot/compressed/head.S11
-rw-r--r--arch/s390/configs/default_defconfig2
-rw-r--r--arch/s390/configs/gcov_defconfig2
-rw-r--r--arch/s390/configs/performance_defconfig2
-rw-r--r--arch/s390/crypto/crc32-vx.c6
-rw-r--r--arch/s390/defconfig2
-rw-r--r--arch/s390/kernel/head.S4
-rw-r--r--arch/s390/kernel/setup.c6
-rw-r--r--arch/s390/kvm/kvm-s390.c5
-rw-r--r--arch/s390/lib/string.c16
-rw-r--r--arch/s390/mm/pageattr.c2
-rw-r--r--arch/um/include/asm/common.lds.S2
-rw-r--r--arch/unicore32/include/asm/mmu_context.h2
-rw-r--r--arch/x86/crypto/sha256-mb/sha256_mb.c4
-rw-r--r--arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S7
-rw-r--r--arch/x86/crypto/sha512-mb/sha512_mb.c4
-rw-r--r--arch/x86/entry/Makefile2
-rw-r--r--arch/x86/entry/entry_64.S25
-rw-r--r--arch/x86/events/intel/uncore_snb.c14
-rw-r--r--arch/x86/events/intel/uncore_snbep.c10
-rw-r--r--arch/x86/include/asm/apic.h2
-rw-r--r--arch/x86/include/asm/hardirq.h4
-rw-r--r--arch/x86/include/asm/init.h4
-rw-r--r--arch/x86/include/asm/pgtable_64.h4
-rw-r--r--arch/x86/include/asm/realmode.h10
-rw-r--r--arch/x86/include/asm/tlbflush.h7
-rw-r--r--arch/x86/include/asm/uv/bios.h5
-rw-r--r--arch/x86/kernel/apic/apic.c31
-rw-r--r--arch/x86/kernel/apic/x2apic_cluster.c13
-rw-r--r--arch/x86/kernel/apic/x2apic_uv_x.c42
-rw-r--r--arch/x86/kernel/cpu/microcode/amd.c9
-rw-r--r--arch/x86/kernel/fpu/xstate.c138
-rw-r--r--arch/x86/kernel/head32.c2
-rw-r--r--arch/x86/kernel/head64.c1
-rw-r--r--arch/x86/kernel/hpet.c2
-rw-r--r--arch/x86/kernel/irq.c3
-rw-r--r--arch/x86/kernel/setup.c27
-rw-r--r--arch/x86/kernel/smpboot.c25
-rw-r--r--arch/x86/kernel/tsc.c4
-rw-r--r--arch/x86/kernel/uprobes.c22
-rw-r--r--arch/x86/kvm/vmx.c136
-rw-r--r--arch/x86/lib/kaslr.c2
-rw-r--r--arch/x86/mm/ident_map.c19
-rw-r--r--arch/x86/mm/init.c14
-rw-r--r--arch/x86/mm/kaslr.c4
-rw-r--r--arch/x86/pci/vmd.c10
-rw-r--r--arch/x86/platform/efi/quirks.c21
-rw-r--r--arch/x86/platform/uv/bios_uv.c11
-rw-r--r--arch/x86/power/hibernate_64.c4
-rw-r--r--arch/x86/realmode/init.c47
-rw-r--r--arch/x86/xen/enlighten.c2
-rw-r--r--block/bio.c21
-rw-r--r--block/blk-core.c4
-rw-r--r--block/blk-merge.c55
-rw-r--r--block/blk-mq.c60
-rw-r--r--block/elevator.c2
-rw-r--r--crypto/Kconfig2
-rw-r--r--crypto/sha3_generic.c16
-rw-r--r--drivers/acpi/nfit/core.c3
-rw-r--r--drivers/block/floppy.c27
-rw-r--r--drivers/block/rbd.c10
-rw-r--r--drivers/block/virtio_blk.c26
-rw-r--r--drivers/block/xen-blkfront.c97
-rw-r--r--drivers/clocksource/arm_arch_timer.c26
-rw-r--r--drivers/clocksource/bcm_kona_timer.c16
-rw-r--r--drivers/clocksource/mips-gic-timer.c2
-rw-r--r--drivers/clocksource/pxa_timer.c2
-rw-r--r--drivers/clocksource/sun4i_timer.c9
-rw-r--r--drivers/clocksource/time-armada-370-xp.c1
-rw-r--r--drivers/clocksource/time-pistachio.c8
-rw-r--r--drivers/clocksource/timer-atmel-pit.c6
-rw-r--r--drivers/cpufreq/powernv-cpufreq.c21
-rw-r--r--drivers/crypto/caam/caamalg.c13
-rw-r--r--drivers/crypto/caam/caamhash.c1
-rw-r--r--drivers/dax/pmem.c3
-rw-r--r--drivers/edac/Kconfig8
-rw-r--r--drivers/edac/Makefile1
-rw-r--r--drivers/edac/sb_edac.c15
-rw-r--r--drivers/edac/skx_edac.c1121
-rw-r--r--drivers/firmware/efi/capsule-loader.c8
-rw-r--r--drivers/firmware/efi/capsule.c6
-rw-r--r--drivers/gpio/Kconfig11
-rw-r--r--drivers/gpio/gpio-max730x.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c13
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c9
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c5
-rw-r--r--drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c2
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c2
-rw-r--r--drivers/gpu/drm/amd/scheduler/gpu_scheduler.c2
-rw-r--r--drivers/gpu/drm/drm_atomic.c6
-rw-r--r--drivers/gpu/drm/drm_crtc.c3
-rw-r--r--drivers/gpu/drm/drm_fb_helper.c2
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_gpu.c10
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h14
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c10
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c13
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c1
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h14
-rw-r--r--drivers/gpu/drm/i915/intel_audio.c6
-rw-r--r--drivers/gpu/drm/i915/intel_csr.c8
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c91
-rw-r--r--drivers/gpu/drm/i915/intel_display.c181
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h3
-rw-r--r--drivers/gpu/drm/i915/intel_fbc.c20
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c276
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.c8
-rw-r--r--drivers/gpu/drm/mediatek/Kconfig3
-rw-r--r--drivers/gpu/drm/qxl/qxl_fb.c4
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_atpx_handler.c9
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c4
-rw-r--r--drivers/gpu/drm/tegra/dsi.c43
-rw-r--r--drivers/gpu/drm/udl/udl_fb.c4
-rw-r--r--drivers/gpu/host1x/mipi.c63
-rw-r--r--drivers/hwmon/it87.c2
-rw-r--r--drivers/i2c/busses/i2c-at91.c24
-rw-r--r--drivers/i2c/busses/i2c-bcm-iproc.c2
-rw-r--r--drivers/i2c/busses/i2c-bcm-kona.c2
-rw-r--r--drivers/i2c/busses/i2c-brcmstb.c2
-rw-r--r--drivers/i2c/busses/i2c-cros-ec-tunnel.c2
-rw-r--r--drivers/i2c/busses/i2c-meson.c6
-rw-r--r--drivers/i2c/busses/i2c-ocores.c14
-rw-r--r--drivers/i2c/muxes/i2c-demux-pinctrl.c4
-rw-r--r--drivers/infiniband/core/cma.c18
-rw-r--r--drivers/infiniband/hw/cxgb4/cm.c6
-rw-r--r--drivers/infiniband/hw/cxgb4/cq.c10
-rw-r--r--drivers/infiniband/hw/cxgb4/t4.h5
-rw-r--r--drivers/infiniband/hw/hfi1/affinity.c21
-rw-r--r--drivers/infiniband/hw/hfi1/debugfs.c14
-rw-r--r--drivers/infiniband/hw/hfi1/driver.c11
-rw-r--r--drivers/infiniband/hw/hfi1/file_ops.c4
-rw-r--r--drivers/infiniband/hw/hfi1/hfi.h20
-rw-r--r--drivers/infiniband/hw/hfi1/init.c2
-rw-r--r--drivers/infiniband/hw/hfi1/mad.c14
-rw-r--r--drivers/infiniband/hw/hfi1/qp.c4
-rw-r--r--drivers/infiniband/hw/hfi1/qsfp.c32
-rw-r--r--drivers/infiniband/hw/hfi1/qsfp.h3
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw.h4
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_cm.c26
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_main.c4
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_utils.c5
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_verbs.c4
-rw-r--r--drivers/infiniband/hw/mlx4/cq.c20
-rw-r--r--drivers/infiniband/hw/mlx5/main.c1
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_hw.c14
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_sli.h12
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_verbs.c4
-rw-r--r--drivers/infiniband/hw/qib/qib_debugfs.c12
-rw-r--r--drivers/infiniband/hw/qib/qib_fs.c26
-rw-r--r--drivers/infiniband/hw/qib/qib_qp.c4
-rw-r--r--drivers/infiniband/hw/usnic/usnic_ib_main.c3
-rw-r--r--drivers/infiniband/sw/rdmavt/qp.c3
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c2
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c9
-rw-r--r--drivers/input/keyboard/tegra-kbc.c2
-rw-r--r--drivers/input/rmi4/rmi_driver.c3
-rw-r--r--drivers/input/serio/i8042.c1
-rw-r--r--drivers/input/touchscreen/ads7846.c1
-rw-r--r--drivers/input/touchscreen/silead.c2
-rw-r--r--drivers/iommu/arm-smmu-v3.c7
-rw-r--r--drivers/iommu/arm-smmu.c34
-rw-r--r--drivers/iommu/dma-iommu.c14
-rw-r--r--drivers/iommu/io-pgtable-arm-v7s.c4
-rw-r--r--drivers/iommu/mtk_iommu.h6
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c7
-rw-r--r--drivers/irqchip/irq-gic-v3.c11
-rw-r--r--drivers/irqchip/irq-gic.c7
-rw-r--r--drivers/irqchip/irq-mips-gic.c18
-rw-r--r--drivers/md/bcache/super.c14
-rw-r--r--drivers/md/dm-crypt.c2
-rw-r--r--drivers/md/dm-flakey.c27
-rw-r--r--drivers/md/dm-log.c11
-rw-r--r--drivers/md/dm-raid.c82
-rw-r--r--drivers/md/dm-round-robin.c7
-rw-r--r--drivers/misc/cxl/context.c3
-rw-r--r--drivers/misc/cxl/cxl.h2
-rw-r--r--drivers/misc/cxl/native.c2
-rw-r--r--drivers/misc/cxl/pci.c12
-rw-r--r--drivers/misc/cxl/vphb.c2
-rw-r--r--drivers/mmc/card/block.c5
-rw-r--r--drivers/mmc/card/queue.c7
-rw-r--r--drivers/mmc/card/queue.h4
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/dsa/b53/b53_regs.h2
-rw-r--r--drivers/net/dsa/mv88e6xxx/chip.c2
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_hw.c2
-rw-r--r--drivers/net/ethernet/arc/emac_main.c6
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c5
-rw-r--r--drivers/net/ethernet/cadence/macb.h2
-rw-r--r--drivers/net/ethernet/davicom/dm9000.c8
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c2
-rw-r--r--drivers/net/ethernet/intel/e1000e/82571.c6
-rw-r--r--drivers/net/ethernet/intel/e1000e/e1000.h1
-rw-r--r--drivers/net/ethernet/intel/e1000e/ich8lan.c3
-rw-r--r--drivers/net/ethernet/intel/e1000e/netdev.c66
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_main.c35
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ptp.c26
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c23
-rw-r--r--drivers/net/ethernet/mediatek/mtk_eth_soc.c49
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tc.c12
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/reg.h11
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.c115
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.h2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_dcb.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c42
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/trap.h4
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_dcbx.c223
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_hsi.h8
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic.h4
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c2
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov.h9
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c95
-rw-r--r--drivers/net/ethernet/ti/cpsw.c2
-rw-r--r--drivers/net/ethernet/tundra/tsi108_eth.c2
-rw-r--r--drivers/net/hyperv/hyperv_net.h24
-rw-r--r--drivers/net/hyperv/netvsc.c19
-rw-r--r--drivers/net/hyperv/netvsc_drv.c105
-rw-r--r--drivers/net/macsec.c52
-rw-r--r--drivers/net/macvlan.c2
-rw-r--r--drivers/net/macvtap.c5
-rw-r--r--drivers/net/phy/micrel.c27
-rw-r--r--drivers/net/vxlan.c34
-rw-r--r--drivers/net/wireless/ti/wlcore/main.c5
-rw-r--r--drivers/nvdimm/btt.c1
-rw-r--r--drivers/nvdimm/btt_devs.c20
-rw-r--r--drivers/nvdimm/nd.h1
-rw-r--r--drivers/nvme/host/core.c11
-rw-r--r--drivers/nvme/host/pci.c20
-rw-r--r--drivers/nvme/host/rdma.c83
-rw-r--r--drivers/nvme/target/admin-cmd.c6
-rw-r--r--drivers/nvme/target/core.c4
-rw-r--r--drivers/nvme/target/loop.c4
-rw-r--r--drivers/nvme/target/nvmet.h1
-rw-r--r--drivers/nvme/target/rdma.c100
-rw-r--r--drivers/of/base.c14
-rw-r--r--drivers/of/fdt.c2
-rw-r--r--drivers/of/irq.c5
-rw-r--r--drivers/of/platform.c2
-rw-r--r--drivers/pci/msi.c20
-rw-r--r--drivers/perf/arm_pmu.c25
-rw-r--r--drivers/pinctrl/intel/pinctrl-merrifield.c1
-rw-r--r--drivers/pinctrl/meson/pinctrl-meson.c8
-rw-r--r--drivers/pinctrl/pinctrl-amd.c20
-rw-r--r--drivers/pinctrl/pinctrl-pistachio.c9
-rw-r--r--drivers/power/max17042_battery.c15
-rw-r--r--drivers/power/reset/Kconfig2
-rw-r--r--drivers/power/reset/hisi-reboot.c5
-rw-r--r--drivers/power/tps65217_charger.c1
-rw-r--r--drivers/rapidio/rio_cm.c24
-rw-r--r--drivers/s390/block/dasd.c10
-rw-r--r--drivers/s390/block/dasd_eckd.c10
-rw-r--r--drivers/s390/cio/device.c2
-rw-r--r--drivers/s390/cio/device_status.c7
-rw-r--r--drivers/s390/cio/io_sch.h1
-rw-r--r--drivers/s390/cio/qdio_main.c113
-rw-r--r--drivers/s390/virtio/Makefile6
-rw-r--r--drivers/s390/virtio/kvm_virtio.c4
-rw-r--r--drivers/scsi/aacraid/commctrl.c13
-rw-r--r--drivers/scsi/fcoe/fcoe_ctlr.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c6
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.c2
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_base.c22
-rw-r--r--drivers/scsi/ses.c3
-rw-r--r--drivers/thermal/clock_cooling.c1
-rw-r--r--drivers/thermal/cpu_cooling.c21
-rw-r--r--drivers/thermal/fair_share.c2
-rw-r--r--drivers/thermal/gov_bang_bang.c2
-rw-r--r--drivers/thermal/imx_thermal.c4
-rw-r--r--drivers/thermal/int340x_thermal/int3406_thermal.c1
-rw-r--r--drivers/thermal/intel_pch_thermal.c60
-rw-r--r--drivers/thermal/intel_powerclamp.c11
-rw-r--r--drivers/thermal/power_allocator.c2
-rw-r--r--drivers/thermal/step_wise.c2
-rw-r--r--drivers/thermal/thermal_core.c10
-rw-r--r--drivers/thermal/thermal_hwmon.c2
-rw-r--r--drivers/usb/class/cdc-acm.c5
-rw-r--r--drivers/usb/class/cdc-acm.h1
-rw-r--r--drivers/usb/core/config.c66
-rw-r--r--drivers/usb/core/devio.c7
-rw-r--r--drivers/usb/core/hub.c23
-rw-r--r--drivers/usb/dwc3/dwc3-of-simple.c1
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c2
-rw-r--r--drivers/usb/dwc3/gadget.c55
-rw-r--r--drivers/usb/gadget/composite.c6
-rw-r--r--drivers/usb/gadget/configfs.c2
-rw-r--r--drivers/usb/gadget/function/rndis.c6
-rw-r--r--drivers/usb/gadget/function/u_ether.c3
-rw-r--r--drivers/usb/gadget/function/uvc_configfs.c2
-rw-r--r--drivers/usb/gadget/legacy/inode.c4
-rw-r--r--drivers/usb/gadget/udc/core.c5
-rw-r--r--drivers/usb/gadget/udc/fsl_qe_udc.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c4
-rw-r--r--drivers/usb/host/max3421-hcd.c2
-rw-r--r--drivers/usb/host/xhci-hub.c3
-rw-r--r--drivers/usb/host/xhci-pci.c3
-rw-r--r--drivers/usb/host/xhci-ring.c16
-rw-r--r--drivers/usb/misc/ftdi-elan.c10
-rw-r--r--drivers/usb/misc/usbtest.c9
-rw-r--r--drivers/usb/phy/phy-omap-otg.c2
-rw-r--r--drivers/usb/renesas_usbhs/common.c3
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c4
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c7
-rw-r--r--drivers/usb/serial/ftdi_sio.c3
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h12
-rw-r--r--drivers/usb/serial/option.c22
-rw-r--r--drivers/usb/serial/usb-serial.c4
-rw-r--r--drivers/vfio/pci/vfio_pci_intrs.c85
-rw-r--r--drivers/vhost/scsi.c6
-rw-r--r--drivers/vhost/test.c8
-rw-r--r--drivers/vhost/vsock.c6
-rw-r--r--drivers/virtio/virtio_ring.c3
-rw-r--r--drivers/xen/xenbus/xenbus_dev_frontend.c2
-rw-r--r--fs/afs/cmservice.c78
-rw-r--r--fs/afs/fsclient.c221
-rw-r--r--fs/afs/internal.h14
-rw-r--r--fs/afs/rxrpc.c73
-rw-r--r--fs/afs/vlclient.c11
-rw-r--r--fs/block_dev.c5
-rw-r--r--fs/btrfs/backref.c1
-rw-r--r--fs/btrfs/ctree.h5
-rw-r--r--fs/btrfs/delayed-ref.c34
-rw-r--r--fs/btrfs/delayed-ref.h3
-rw-r--r--fs/btrfs/disk-io.c56
-rw-r--r--fs/btrfs/disk-io.h2
-rw-r--r--fs/btrfs/extent-tree.c185
-rw-r--r--fs/btrfs/extent_io.h1
-rw-r--r--fs/btrfs/file.c36
-rw-r--r--fs/btrfs/inode-map.c3
-rw-r--r--fs/btrfs/inode.c83
-rw-r--r--fs/btrfs/ioctl.c2
-rw-r--r--fs/btrfs/qgroup.c62
-rw-r--r--fs/btrfs/qgroup.h36
-rw-r--r--fs/btrfs/relocation.c126
-rw-r--r--fs/btrfs/root-tree.c27
-rw-r--r--fs/btrfs/send.c173
-rw-r--r--fs/btrfs/super.c16
-rw-r--r--fs/btrfs/transaction.c7
-rw-r--r--fs/btrfs/tree-log.c106
-rw-r--r--fs/btrfs/tree-log.h5
-rw-r--r--fs/btrfs/volumes.c27
-rw-r--r--fs/ceph/caps.c5
-rw-r--r--fs/ceph/mds_client.c1
-rw-r--r--fs/dlm/debug_fs.c62
-rw-r--r--fs/f2fs/data.c2
-rw-r--r--fs/f2fs/f2fs.h12
-rw-r--r--fs/f2fs/file.c13
-rw-r--r--fs/f2fs/node.c47
-rw-r--r--fs/f2fs/super.c6
-rw-r--r--fs/fs-writeback.c6
-rw-r--r--fs/iomap.c21
-rw-r--r--fs/nfs/nfs42proc.c2
-rw-r--r--fs/nfs/nfs4_fs.h4
-rw-r--r--fs/nfs/nfs4proc.c9
-rw-r--r--fs/nfs/nfs4renewd.c20
-rw-r--r--fs/nfs/nfs4state.c9
-rw-r--r--fs/nfsd/nfs4state.c65
-rw-r--r--fs/nfsd/vfs.c9
-rw-r--r--fs/proc/meminfo.c2
-rw-r--r--fs/seq_file.c4
-rw-r--r--fs/ubifs/tnc_commit.c2
-rw-r--r--fs/ubifs/xattr.c5
-rw-r--r--fs/xfs/libxfs/xfs_alloc.c14
-rw-r--r--fs/xfs/libxfs/xfs_format.h11
-rw-r--r--fs/xfs/libxfs/xfs_rmap_btree.c6
-rw-r--r--fs/xfs/xfs_buf.c1
-rw-r--r--fs/xfs/xfs_file.c13
-rw-r--r--fs/xfs/xfs_fsops.c1
-rw-r--r--fs/xfs/xfs_iomap.c69
-rw-r--r--fs/xfs/xfs_iomap.h1
-rw-r--r--fs/xfs/xfs_iops.c9
-rw-r--r--fs/xfs/xfs_trace.h1
-rw-r--r--include/asm-generic/qrwlock.h27
-rw-r--r--include/linux/bio.h10
-rw-r--r--include/linux/blkdev.h6
-rw-r--r--include/linux/bvec.h3
-rw-r--r--include/linux/compiler-gcc.h8
-rw-r--r--include/linux/compiler.h6
-rw-r--r--include/linux/host1x.h2
-rw-r--r--include/linux/irqchip/arm-gic-v3.h1
-rw-r--r--include/linux/kvm_host.h12
-rw-r--r--include/linux/msi.h2
-rw-r--r--include/linux/netdevice.h3
-rw-r--r--include/linux/pci.h10
-rw-r--r--include/linux/perf_event.h4
-rw-r--r--include/linux/qed/qed_if.h8
-rw-r--r--include/linux/sctp.h64
-rw-r--r--include/linux/skbuff.h52
-rw-r--r--include/linux/sunrpc/clnt.h2
-rw-r--r--include/linux/sunrpc/xprt.h3
-rw-r--r--include/linux/sysctl.h2
-rw-r--r--include/net/act_api.h23
-rw-r--r--include/net/af_rxrpc.h2
-rw-r--r--include/net/gre.h1
-rw-r--r--include/net/inet_ecn.h3
-rw-r--r--include/net/mac80211.h3
-rw-r--r--include/net/pkt_cls.h41
-rw-r--r--include/rdma/ib_verbs.h11
-rw-r--r--include/uapi/linux/bpf.h4
-rw-r--r--include/uapi/linux/netfilter/nf_tables.h2
-rw-r--r--include/uapi/linux/sctp.h64
-rw-r--r--include/uapi/linux/virtio_vsock.h2
-rw-r--r--include/uapi/misc/cxl.h4
-rw-r--r--include/xen/xen-ops.h4
-rw-r--r--kernel/bpf/hashtab.c84
-rw-r--r--kernel/bpf/verifier.c7
-rw-r--r--kernel/events/core.c174
-rw-r--r--kernel/events/uprobes.c5
-rw-r--r--kernel/futex.c23
-rw-r--r--kernel/irq/affinity.c2
-rw-r--r--kernel/irq/chip.c11
-rw-r--r--kernel/irq/manage.c8
-rw-r--r--kernel/irq/msi.c11
-rw-r--r--kernel/locking/qspinlock_paravirt.h2
-rw-r--r--kernel/locking/qspinlock_stat.h1
-rw-r--r--kernel/power/hibernate.c4
-rw-r--r--kernel/power/snapshot.c10
-rw-r--r--kernel/printk/braille.c4
-rw-r--r--kernel/sched/core.c19
-rw-r--r--kernel/sched/cpudeadline.c2
-rw-r--r--kernel/sched/cputime.c41
-rw-r--r--kernel/sched/deadline.c5
-rw-r--r--kernel/sched/fair.c2
-rw-r--r--kernel/sysctl.c45
-rw-r--r--kernel/time/timekeeping.c5
-rw-r--r--kernel/time/timekeeping_debug.c9
-rw-r--r--kernel/time/timer.c5
-rw-r--r--kernel/trace/blktrace.c2
-rw-r--r--lib/rhashtable.c13
-rw-r--r--lib/test_rhashtable.c2
-rw-r--r--mm/Kconfig9
-rw-r--r--mm/huge_memory.c7
-rw-r--r--mm/hugetlb.c1
-rw-r--r--mm/kasan/quarantine.c7
-rw-r--r--mm/memcontrol.c68
-rw-r--r--mm/memory_hotplug.c2
-rw-r--r--mm/oom_kill.c2
-rw-r--r--mm/page_alloc.c52
-rw-r--r--mm/readahead.c9
-rw-r--r--mm/rmap.c7
-rw-r--r--mm/shmem.c4
-rw-r--r--mm/slub.c6
-rw-r--r--mm/usercopy.c4
-rw-r--r--net/8021q/vlan.c2
-rw-r--r--net/9p/trans_virtio.c4
-rw-r--r--net/bridge/br_fdb.c52
-rw-r--r--net/ceph/mon_client.c2
-rw-r--r--net/ceph/osd_client.c2
-rw-r--r--net/ceph/string_table.c8
-rw-r--r--net/core/dev.c10
-rw-r--r--net/core/filter.c109
-rw-r--r--net/ipv4/fib_trie.c8
-rw-r--r--net/ipv4/ip_gre.c1
-rw-r--r--net/ipv4/ip_vti.c31
-rw-r--r--net/ipv6/addrconf.c4
-rw-r--r--net/ipv6/calipso.c4
-rw-r--r--net/ipv6/ip6_gre.c2
-rw-r--r--net/ipv6/ping.c33
-rw-r--r--net/irda/iriap.c8
-rw-r--r--net/mac80211/cfg.c2
-rw-r--r--net/mac80211/driver-ops.h2
-rw-r--r--net/mac80211/mesh.c10
-rw-r--r--net/mac80211/rx.c2
-rw-r--r--net/mac80211/status.c14
-rw-r--r--net/mac80211/tx.c6
-rw-r--r--net/netfilter/nf_conntrack_expect.c2
-rw-r--r--net/netfilter/nf_conntrack_h323_main.c3
-rw-r--r--net/netfilter/nf_conntrack_netlink.c10
-rw-r--r--net/netfilter/nf_conntrack_sip.c4
-rw-r--r--net/netfilter/nfnetlink_queue.c6
-rw-r--r--net/netfilter/nft_exthdr.c11
-rw-r--r--net/netfilter/nft_rbtree.c10
-rw-r--r--net/openvswitch/conntrack.c8
-rw-r--r--net/openvswitch/vport-geneve.c9
-rw-r--r--net/openvswitch/vport-gre.c11
-rw-r--r--net/openvswitch/vport-internal_dev.c2
-rw-r--r--net/openvswitch/vport-vxlan.c9
-rw-r--r--net/rxrpc/ar-internal.h1
-rw-r--r--net/rxrpc/call_accept.c1
-rw-r--r--net/rxrpc/call_event.c7
-rw-r--r--net/rxrpc/call_object.c11
-rw-r--r--net/rxrpc/input.c39
-rw-r--r--net/rxrpc/recvmsg.c25
-rw-r--r--net/rxrpc/skbuff.c41
-rw-r--r--net/sched/act_api.c34
-rw-r--r--net/sched/act_police.c62
-rw-r--r--net/sched/cls_api.c51
-rw-r--r--net/sctp/proc.c1
-rw-r--r--net/sctp/sctp_diag.c18
-rw-r--r--net/sctp/ulpevent.c4
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c8
-rw-r--r--net/sunrpc/clnt.c24
-rw-r--r--net/sunrpc/xprt.c26
-rw-r--r--net/sunrpc/xprtsock.c60
-rw-r--r--net/tipc/monitor.c3
-rw-r--r--net/tipc/socket.c3
-rw-r--r--net/vmw_vsock/virtio_transport.c10
-rw-r--r--net/wireless/chan.c1
-rw-r--r--net/wireless/nl80211.c34
-rw-r--r--samples/bpf/bpf_helpers.h4
-rw-r--r--samples/bpf/test_cgrp2_tc_kern.c2
-rw-r--r--samples/bpf/test_maps.c15
-rwxr-xr-xscripts/get_maintainer.pl6
-rw-r--r--security/Kconfig1
-rw-r--r--sound/pci/hda/hda_intel.c32
-rw-r--r--sound/pci/hda/patch_realtek.c7
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c5
-rw-r--r--sound/soc/codecs/da7213.c4
-rw-r--r--sound/soc/codecs/max98371.c1
-rw-r--r--sound/soc/codecs/nau8825.c78
-rw-r--r--sound/soc/codecs/wm2000.c2
-rw-r--r--sound/soc/generic/Makefile6
-rw-r--r--sound/soc/generic/simple-card-utils.c6
-rw-r--r--sound/soc/intel/skylake/skl-sst-utils.c5
-rw-r--r--sound/soc/intel/skylake/skl.c4
-rw-r--r--sound/soc/omap/omap-abe-twl6040.c61
-rw-r--r--sound/soc/omap/omap-mcpdm.c22
-rw-r--r--sound/soc/samsung/s3c24xx_uda134x.c7
-rw-r--r--sound/soc/sh/rcar/src.c6
-rw-r--r--sound/soc/soc-compress.c4
-rw-r--r--sound/soc/soc-core.c5
-rw-r--r--sound/soc/soc-dapm.c10
-rw-r--r--sound/usb/line6/pcm.c3
-rw-r--r--sound/usb/line6/pod.c12
-rw-r--r--sound/usb/quirks.c2
-rw-r--r--tools/arch/arm64/include/uapi/asm/kvm.h2
-rw-r--r--tools/arch/s390/include/uapi/asm/kvm.h41
-rw-r--r--tools/arch/s390/include/uapi/asm/sie.h1
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h9
-rw-r--r--tools/arch/x86/include/asm/disabled-features.h2
-rw-r--r--tools/arch/x86/include/asm/required-features.h2
-rw-r--r--tools/arch/x86/include/uapi/asm/vmx.h4
-rw-r--r--tools/gpio/gpio-event-mon.c2
-rw-r--r--tools/include/linux/string.h6
-rw-r--r--tools/include/uapi/linux/bpf.h86
-rw-r--r--tools/perf/Documentation/perf-probe.txt10
-rw-r--r--tools/perf/Documentation/perf-script.txt4
-rw-r--r--tools/perf/arch/powerpc/util/sym-handling.c29
-rw-r--r--tools/perf/arch/x86/util/intel-pt.c6
-rw-r--r--tools/perf/builtin-mem.c3
-rw-r--r--tools/perf/builtin-script.c15
-rw-r--r--tools/perf/builtin-stat.c31
-rw-r--r--tools/perf/util/evsel.c6
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-decoder.c44
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c24
-rw-r--r--tools/perf/util/jitdump.c1
-rw-r--r--tools/perf/util/probe-event.c60
-rw-r--r--tools/perf/util/probe-event.h6
-rw-r--r--tools/perf/util/probe-file.c36
-rw-r--r--tools/perf/util/probe-finder.c15
-rw-r--r--tools/perf/util/sort.c6
-rw-r--r--tools/perf/util/symbol-elf.c3
-rw-r--r--tools/perf/util/unwind-libdw.c2
-rw-r--r--tools/perf/util/unwind-libunwind-local.c2
-rw-r--r--tools/testing/nvdimm/test/nfit.c2
-rw-r--r--tools/testing/selftests/powerpc/Makefile2
-rw-r--r--tools/virtio/linux/dma-mapping.h16
-rw-r--r--tools/virtio/linux/kernel.h14
-rw-r--r--tools/virtio/linux/slab.h4
-rw-r--r--tools/virtio/linux/virtio.h6
-rw-r--r--tools/virtio/linux/virtio_config.h13
-rw-r--r--tools/virtio/ringtest/ptr_ring.c1
-rw-r--r--virt/kvm/arm/arch_timer.c11
-rw-r--r--virt/kvm/arm/vgic/vgic-init.c17
-rw-r--r--virt/kvm/arm/vgic/vgic-its.c158
-rw-r--r--virt/kvm/arm/vgic/vgic-mmio-v3.c26
-rw-r--r--virt/kvm/arm/vgic/vgic-v3.c8
-rw-r--r--virt/kvm/arm/vgic/vgic.c10
-rw-r--r--virt/kvm/arm/vgic/vgic.h6
-rw-r--r--virt/kvm/kvm_main.c16
679 files changed, 8258 insertions, 3851 deletions
diff --git a/Documentation/PCI/MSI-HOWTO.txt b/Documentation/PCI/MSI-HOWTO.txt
index c55df2911136..cd9c9f6a7cd9 100644
--- a/Documentation/PCI/MSI-HOWTO.txt
+++ b/Documentation/PCI/MSI-HOWTO.txt
@@ -94,14 +94,11 @@ has a requirements for a minimum number of vectors the driver can pass a
94min_vecs argument set to this limit, and the PCI core will return -ENOSPC 94min_vecs argument set to this limit, and the PCI core will return -ENOSPC
95if it can't meet the minimum number of vectors. 95if it can't meet the minimum number of vectors.
96 96
97The flags argument should normally be set to 0, but can be used to pass the 97The flags argument is used to specify which type of interrupt can be used
98PCI_IRQ_NOMSI and PCI_IRQ_NOMSIX flag in case a device claims to support 98by the device and the driver (PCI_IRQ_LEGACY, PCI_IRQ_MSI, PCI_IRQ_MSIX).
99MSI or MSI-X, but the support is broken, or to pass PCI_IRQ_NOLEGACY in 99A convenient short-hand (PCI_IRQ_ALL_TYPES) is also available to ask for
100case the device does not support legacy interrupt lines. 100any possible kind of interrupt. If the PCI_IRQ_AFFINITY flag is set,
101 101pci_alloc_irq_vectors() will spread the interrupts around the available CPUs.
102By default this function will spread the interrupts around the available
103CPUs, but this feature can be disabled by passing the PCI_IRQ_NOAFFINITY
104flag.
105 102
106To get the Linux IRQ numbers passed to request_irq() and free_irq() and the 103To get the Linux IRQ numbers passed to request_irq() and free_irq() and the
107vectors, use the following function: 104vectors, use the following function:
@@ -131,7 +128,7 @@ larger than the number supported by the device it will automatically be
131capped to the supported limit, so there is no need to query the number of 128capped to the supported limit, so there is no need to query the number of
132vectors supported beforehand: 129vectors supported beforehand:
133 130
134 nvec = pci_alloc_irq_vectors(pdev, 1, nvec, 0); 131 nvec = pci_alloc_irq_vectors(pdev, 1, nvec, PCI_IRQ_ALL_TYPES)
135 if (nvec < 0) 132 if (nvec < 0)
136 goto out_err; 133 goto out_err;
137 134
@@ -140,7 +137,7 @@ interrupts it can request a particular number of interrupts by passing that
140number to pci_alloc_irq_vectors() function as both 'min_vecs' and 137number to pci_alloc_irq_vectors() function as both 'min_vecs' and
141'max_vecs' parameters: 138'max_vecs' parameters:
142 139
143 ret = pci_alloc_irq_vectors(pdev, nvec, nvec, 0); 140 ret = pci_alloc_irq_vectors(pdev, nvec, nvec, PCI_IRQ_ALL_TYPES);
144 if (ret < 0) 141 if (ret < 0)
145 goto out_err; 142 goto out_err;
146 143
@@ -148,15 +145,14 @@ The most notorious example of the request type described above is enabling
148the single MSI mode for a device. It could be done by passing two 1s as 145the single MSI mode for a device. It could be done by passing two 1s as
149'min_vecs' and 'max_vecs': 146'min_vecs' and 'max_vecs':
150 147
151 ret = pci_alloc_irq_vectors(pdev, 1, 1, 0); 148 ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
152 if (ret < 0) 149 if (ret < 0)
153 goto out_err; 150 goto out_err;
154 151
155Some devices might not support using legacy line interrupts, in which case 152Some devices might not support using legacy line interrupts, in which case
156the PCI_IRQ_NOLEGACY flag can be used to fail the request if the platform 153the driver can specify that only MSI or MSI-X is acceptable:
157can't provide MSI or MSI-X interrupts:
158 154
159 nvec = pci_alloc_irq_vectors(pdev, 1, nvec, PCI_IRQ_NOLEGACY); 155 nvec = pci_alloc_irq_vectors(pdev, 1, nvec, PCI_IRQ_MSI | PCI_IRQ_MSIX);
160 if (nvec < 0) 156 if (nvec < 0)
161 goto out_err; 157 goto out_err;
162 158
diff --git a/Documentation/arm64/silicon-errata.txt b/Documentation/arm64/silicon-errata.txt
index 4da60b463995..ccc60324e738 100644
--- a/Documentation/arm64/silicon-errata.txt
+++ b/Documentation/arm64/silicon-errata.txt
@@ -53,6 +53,7 @@ stable kernels.
53| ARM | Cortex-A57 | #832075 | ARM64_ERRATUM_832075 | 53| ARM | Cortex-A57 | #832075 | ARM64_ERRATUM_832075 |
54| ARM | Cortex-A57 | #852523 | N/A | 54| ARM | Cortex-A57 | #852523 | N/A |
55| ARM | Cortex-A57 | #834220 | ARM64_ERRATUM_834220 | 55| ARM | Cortex-A57 | #834220 | ARM64_ERRATUM_834220 |
56| ARM | Cortex-A72 | #853709 | N/A |
56| ARM | MMU-500 | #841119,#826419 | N/A | 57| ARM | MMU-500 | #841119,#826419 | N/A |
57| | | | | 58| | | | |
58| Cavium | ThunderX ITS | #22375, #24313 | CAVIUM_ERRATUM_22375 | 59| Cavium | ThunderX ITS | #22375, #24313 | CAVIUM_ERRATUM_22375 |
diff --git a/Documentation/block/queue-sysfs.txt b/Documentation/block/queue-sysfs.txt
index d515d58962b9..2a3904030dea 100644
--- a/Documentation/block/queue-sysfs.txt
+++ b/Documentation/block/queue-sysfs.txt
@@ -14,6 +14,12 @@ add_random (RW)
14This file allows to turn off the disk entropy contribution. Default 14This file allows to turn off the disk entropy contribution. Default
15value of this file is '1'(on). 15value of this file is '1'(on).
16 16
17dax (RO)
18--------
19This file indicates whether the device supports Direct Access (DAX),
20used by CPU-addressable storage to bypass the pagecache. It shows '1'
21if true, '0' if not.
22
17discard_granularity (RO) 23discard_granularity (RO)
18----------------------- 24-----------------------
19This shows the size of internal allocation of the device in bytes, if 25This shows the size of internal allocation of the device in bytes, if
@@ -46,6 +52,12 @@ hw_sector_size (RO)
46------------------- 52-------------------
47This is the hardware sector size of the device, in bytes. 53This is the hardware sector size of the device, in bytes.
48 54
55io_poll (RW)
56------------
57When read, this file shows the total number of block IO polls and how
58many returned success. Writing '0' to this file will disable polling
59for this device. Writing any non-zero value will enable this feature.
60
49iostats (RW) 61iostats (RW)
50------------- 62-------------
51This file is used to control (on/off) the iostats accounting of the 63This file is used to control (on/off) the iostats accounting of the
@@ -151,5 +163,11 @@ device state. This means that it might not be safe to toggle the
151setting from "write back" to "write through", since that will also 163setting from "write back" to "write through", since that will also
152eliminate cache flushes issued by the kernel. 164eliminate cache flushes issued by the kernel.
153 165
166write_same_max_bytes (RO)
167-------------------------
168This is the number of bytes the device can write in a single write-same
169command. A value of '0' means write-same is not supported by this
170device.
171
154 172
155Jens Axboe <jens.axboe@oracle.com>, February 2009 173Jens Axboe <jens.axboe@oracle.com>, February 2009
diff --git a/Documentation/conf.py b/Documentation/conf.py
index 96b7aa66c89c..106ae9c740b9 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -131,7 +131,7 @@ pygments_style = 'sphinx'
131todo_include_todos = False 131todo_include_todos = False
132 132
133primary_domain = 'C' 133primary_domain = 'C'
134highlight_language = 'C' 134highlight_language = 'guess'
135 135
136# -- Options for HTML output ---------------------------------------------- 136# -- Options for HTML output ----------------------------------------------
137 137
diff --git a/Documentation/devicetree/bindings/sound/omap-mcpdm.txt b/Documentation/devicetree/bindings/sound/omap-mcpdm.txt
index 6f6c2f8e908d..0741dff048dd 100644
--- a/Documentation/devicetree/bindings/sound/omap-mcpdm.txt
+++ b/Documentation/devicetree/bindings/sound/omap-mcpdm.txt
@@ -8,8 +8,6 @@ Required properties:
8- interrupts: Interrupt number for McPDM 8- interrupts: Interrupt number for McPDM
9- interrupt-parent: The parent interrupt controller 9- interrupt-parent: The parent interrupt controller
10- ti,hwmods: Name of the hwmod associated to the McPDM 10- ti,hwmods: Name of the hwmod associated to the McPDM
11- clocks: phandle for the pdmclk provider, likely <&twl6040>
12- clock-names: Must be "pdmclk"
13 11
14Example: 12Example:
15 13
@@ -21,11 +19,3 @@ mcpdm: mcpdm@40132000 {
21 interrupt-parent = <&gic>; 19 interrupt-parent = <&gic>;
22 ti,hwmods = "mcpdm"; 20 ti,hwmods = "mcpdm";
23}; 21};
24
25In board DTS file the pdmclk needs to be added:
26
27&mcpdm {
28 clocks = <&twl6040>;
29 clock-names = "pdmclk";
30 status = "okay";
31};
diff --git a/Documentation/devicetree/bindings/thermal/thermal.txt b/Documentation/devicetree/bindings/thermal/thermal.txt
index 41b817f7b670..88b6ea1ad290 100644
--- a/Documentation/devicetree/bindings/thermal/thermal.txt
+++ b/Documentation/devicetree/bindings/thermal/thermal.txt
@@ -62,7 +62,7 @@ For more examples of cooling devices, refer to the example sections below.
62Required properties: 62Required properties:
63- #cooling-cells: Used to provide cooling device specific information 63- #cooling-cells: Used to provide cooling device specific information
64 Type: unsigned while referring to it. Must be at least 2, in order 64 Type: unsigned while referring to it. Must be at least 2, in order
65 Size: one cell to specify minimum and maximum cooling state used 65 Size: one cell to specify minimum and maximum cooling state used
66 in the reference. The first cell is the minimum 66 in the reference. The first cell is the minimum
67 cooling state requested and the second cell is 67 cooling state requested and the second cell is
68 the maximum cooling state requested in the reference. 68 the maximum cooling state requested in the reference.
@@ -119,7 +119,7 @@ Required properties:
119Optional property: 119Optional property:
120- contribution: The cooling contribution to the thermal zone of the 120- contribution: The cooling contribution to the thermal zone of the
121 Type: unsigned referred cooling device at the referred trip point. 121 Type: unsigned referred cooling device at the referred trip point.
122 Size: one cell The contribution is a ratio of the sum 122 Size: one cell The contribution is a ratio of the sum
123 of all cooling contributions within a thermal zone. 123 of all cooling contributions within a thermal zone.
124 124
125Note: Using the THERMAL_NO_LIMIT (-1UL) constant in the cooling-device phandle 125Note: Using the THERMAL_NO_LIMIT (-1UL) constant in the cooling-device phandle
@@ -145,7 +145,7 @@ Required properties:
145 Size: one cell 145 Size: one cell
146 146
147- thermal-sensors: A list of thermal sensor phandles and sensor specifier 147- thermal-sensors: A list of thermal sensor phandles and sensor specifier
148 Type: list of used while monitoring the thermal zone. 148 Type: list of used while monitoring the thermal zone.
149 phandles + sensor 149 phandles + sensor
150 specifier 150 specifier
151 151
@@ -473,7 +473,7 @@ thermal-zones {
473 <&adc>; /* pcb north */ 473 <&adc>; /* pcb north */
474 474
475 /* hotspot = 100 * bandgap - 120 * adc + 484 */ 475 /* hotspot = 100 * bandgap - 120 * adc + 484 */
476 coefficients = <100 -120 484>; 476 coefficients = <100 -120 484>;
477 477
478 trips { 478 trips {
479 ... 479 ...
@@ -502,7 +502,7 @@ from the ADC sensor. The binding would be then:
502 thermal-sensors = <&adc>; 502 thermal-sensors = <&adc>;
503 503
504 /* hotspot = 1 * adc + 6000 */ 504 /* hotspot = 1 * adc + 6000 */
505 coefficients = <1 6000>; 505 coefficients = <1 6000>;
506 506
507(d) - Board thermal 507(d) - Board thermal
508 508
diff --git a/Documentation/hwmon/ftsteutates b/Documentation/hwmon/ftsteutates
index 2a1bf69c6a26..8c10a916de20 100644
--- a/Documentation/hwmon/ftsteutates
+++ b/Documentation/hwmon/ftsteutates
@@ -19,5 +19,5 @@ enhancements. It can monitor up to 4 voltages, 16 temperatures and
19implemented in this driver. 19implemented in this driver.
20 20
21Specification of the chip can be found here: 21Specification of the chip can be found here:
22ftp:///pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/BMC-Teutates_Specification_V1.21.pdf 22ftp://ftp.ts.fujitsu.com/pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/BMC-Teutates_Specification_V1.21.pdf
23ftp:///pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/Fujitsu_mainboards-1-Sensors_HowTo-en-US.pdf 23ftp://ftp.ts.fujitsu.com/pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/Fujitsu_mainboards-1-Sensors_HowTo-en-US.pdf
diff --git a/Documentation/kernel-documentation.rst b/Documentation/kernel-documentation.rst
index c4eb5049da39..391decc66a18 100644
--- a/Documentation/kernel-documentation.rst
+++ b/Documentation/kernel-documentation.rst
@@ -366,8 +366,6 @@ Domain`_ references.
366Cross-referencing from reStructuredText 366Cross-referencing from reStructuredText
367~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 367~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
368 368
369.. highlight:: none
370
371To cross-reference the functions and types defined in the kernel-doc comments 369To cross-reference the functions and types defined in the kernel-doc comments
372from reStructuredText documents, please use the `Sphinx C Domain`_ 370from reStructuredText documents, please use the `Sphinx C Domain`_
373references. For example:: 371references. For example::
@@ -390,8 +388,6 @@ For further details, please refer to the `Sphinx C Domain`_ documentation.
390Function documentation 388Function documentation
391---------------------- 389----------------------
392 390
393.. highlight:: c
394
395The general format of a function and function-like macro kernel-doc comment is:: 391The general format of a function and function-like macro kernel-doc comment is::
396 392
397 /** 393 /**
@@ -572,8 +568,6 @@ DocBook XML [DEPRECATED]
572Converting DocBook to Sphinx 568Converting DocBook to Sphinx
573---------------------------- 569----------------------------
574 570
575.. highlight:: none
576
577Over time, we expect all of the documents under ``Documentation/DocBook`` to be 571Over time, we expect all of the documents under ``Documentation/DocBook`` to be
578converted to Sphinx and reStructuredText. For most DocBook XML documents, a good 572converted to Sphinx and reStructuredText. For most DocBook XML documents, a good
579enough solution is to use the simple ``Documentation/sphinx/tmplcvt`` script, 573enough solution is to use the simple ``Documentation/sphinx/tmplcvt`` script,
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 46c030a49186..a4f4d693e2c1 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3032,6 +3032,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
3032 PAGE_SIZE is used as alignment. 3032 PAGE_SIZE is used as alignment.
3033 PCI-PCI bridge can be specified, if resource 3033 PCI-PCI bridge can be specified, if resource
3034 windows need to be expanded. 3034 windows need to be expanded.
3035 To specify the alignment for several
3036 instances of a device, the PCI vendor,
3037 device, subvendor, and subdevice may be
3038 specified, e.g., 4096@pci:8086:9c22:103c:198f
3035 ecrc= Enable/disable PCIe ECRC (transaction layer 3039 ecrc= Enable/disable PCIe ECRC (transaction layer
3036 end-to-end CRC checking). 3040 end-to-end CRC checking).
3037 bios: Use BIOS/firmware settings. This is the 3041 bios: Use BIOS/firmware settings. This is the
diff --git a/Documentation/networking/rxrpc.txt b/Documentation/networking/rxrpc.txt
index 16a924c486bf..70c926ae212d 100644
--- a/Documentation/networking/rxrpc.txt
+++ b/Documentation/networking/rxrpc.txt
@@ -790,13 +790,12 @@ The kernel interface functions are as follows:
790 Data messages can have their contents extracted with the usual bunch of 790 Data messages can have their contents extracted with the usual bunch of
791 socket buffer manipulation functions. A data message can be determined to 791 socket buffer manipulation functions. A data message can be determined to
792 be the last one in a sequence with rxrpc_kernel_is_data_last(). When a 792 be the last one in a sequence with rxrpc_kernel_is_data_last(). When a
793 data message has been used up, rxrpc_kernel_data_delivered() should be 793 data message has been used up, rxrpc_kernel_data_consumed() should be
794 called on it.. 794 called on it.
795 795
796 Non-data messages should be handled to rxrpc_kernel_free_skb() to dispose 796 Messages should be handled to rxrpc_kernel_free_skb() to dispose of. It
797 of. It is possible to get extra refs on all types of message for later 797 is possible to get extra refs on all types of message for later freeing,
798 freeing, but this may pin the state of a call until the message is finally 798 but this may pin the state of a call until the message is finally freed.
799 freed.
800 799
801 (*) Accept an incoming call. 800 (*) Accept an incoming call.
802 801
@@ -821,12 +820,14 @@ The kernel interface functions are as follows:
821 Other errors may be returned if the call had been aborted (-ECONNABORTED) 820 Other errors may be returned if the call had been aborted (-ECONNABORTED)
822 or had timed out (-ETIME). 821 or had timed out (-ETIME).
823 822
824 (*) Record the delivery of a data message and free it. 823 (*) Record the delivery of a data message.
825 824
826 void rxrpc_kernel_data_delivered(struct sk_buff *skb); 825 void rxrpc_kernel_data_consumed(struct rxrpc_call *call,
826 struct sk_buff *skb);
827 827
828 This is used to record a data message as having been delivered and to 828 This is used to record a data message as having been consumed and to
829 update the ACK state for the call. The socket buffer will be freed. 829 update the ACK state for the call. The message must still be passed to
830 rxrpc_kernel_free_skb() for disposal by the caller.
830 831
831 (*) Free a message. 832 (*) Free a message.
832 833
diff --git a/Documentation/power/basic-pm-debugging.txt b/Documentation/power/basic-pm-debugging.txt
index b96098ccfe69..708f87f78a75 100644
--- a/Documentation/power/basic-pm-debugging.txt
+++ b/Documentation/power/basic-pm-debugging.txt
@@ -164,7 +164,32 @@ load n/2 modules more and try again.
164Again, if you find the offending module(s), it(they) must be unloaded every time 164Again, if you find the offending module(s), it(they) must be unloaded every time
165before hibernation, and please report the problem with it(them). 165before hibernation, and please report the problem with it(them).
166 166
167c) Advanced debugging 167c) Using the "test_resume" hibernation option
168
169/sys/power/disk generally tells the kernel what to do after creating a
170hibernation image. One of the available options is "test_resume" which
171causes the just created image to be used for immediate restoration. Namely,
172after doing:
173
174# echo test_resume > /sys/power/disk
175# echo disk > /sys/power/state
176
177a hibernation image will be created and a resume from it will be triggered
178immediately without involving the platform firmware in any way.
179
180That test can be used to check if failures to resume from hibernation are
181related to bad interactions with the platform firmware. That is, if the above
182works every time, but resume from actual hibernation does not work or is
183unreliable, the platform firmware may be responsible for the failures.
184
185On architectures and platforms that support using different kernels to restore
186hibernation images (that is, the kernel used to read the image from storage and
187load it into memory is different from the one included in the image) or support
188kernel address space randomization, it also can be used to check if failures
189to resume may be related to the differences between the restore and image
190kernels.
191
192d) Advanced debugging
168 193
169In case that hibernation does not work on your system even in the minimal 194In case that hibernation does not work on your system even in the minimal
170configuration and compiling more drivers as modules is not practical or some 195configuration and compiling more drivers as modules is not practical or some
diff --git a/Documentation/power/interface.txt b/Documentation/power/interface.txt
index f1f0f59a7c47..974916ff6608 100644
--- a/Documentation/power/interface.txt
+++ b/Documentation/power/interface.txt
@@ -1,75 +1,76 @@
1Power Management Interface 1Power Management Interface for System Sleep
2 2
3 3Copyright (c) 2016 Intel Corp., Rafael J. Wysocki <rafael.j.wysocki@intel.com>
4The power management subsystem provides a unified sysfs interface to 4
5userspace, regardless of what architecture or platform one is 5The power management subsystem provides userspace with a unified sysfs interface
6running. The interface exists in /sys/power/ directory (assuming sysfs 6for system sleep regardless of the underlying system architecture or platform.
7is mounted at /sys). 7The interface is located in the /sys/power/ directory (assuming that sysfs is
8 8mounted at /sys).
9/sys/power/state controls system power state. Reading from this file 9
10returns what states are supported, which is hard-coded to 'freeze', 10/sys/power/state is the system sleep state control file.
11'standby' (Power-On Suspend), 'mem' (Suspend-to-RAM), and 'disk' 11
12(Suspend-to-Disk). 12Reading from it returns a list of supported sleep states, encoded as:
13 13
14Writing to this file one of those strings causes the system to 14'freeze' (Suspend-to-Idle)
15transition into that state. Please see the file 15'standby' (Power-On Suspend)
16Documentation/power/states.txt for a description of each of those 16'mem' (Suspend-to-RAM)
17states. 17'disk' (Suspend-to-Disk)
18 18
19 19Suspend-to-Idle is always supported. Suspend-to-Disk is always supported
20/sys/power/disk controls the operating mode of the suspend-to-disk 20too as long the kernel has been configured to support hibernation at all
21mechanism. Suspend-to-disk can be handled in several ways. We have a 21(ie. CONFIG_HIBERNATION is set in the kernel configuration file). Support
22few options for putting the system to sleep - using the platform driver 22for Suspend-to-RAM and Power-On Suspend depends on the capabilities of the
23(e.g. ACPI or other suspend_ops), powering off the system or rebooting the 23platform.
24system (for testing). 24
25 25If one of the strings listed in /sys/power/state is written to it, the system
26Additionally, /sys/power/disk can be used to turn on one of the two testing 26will attempt to transition into the corresponding sleep state. Refer to
27modes of the suspend-to-disk mechanism: 'testproc' or 'test'. If the 27Documentation/power/states.txt for a description of each of those states.
28suspend-to-disk mechanism is in the 'testproc' mode, writing 'disk' to 28
29/sys/power/state will cause the kernel to disable nonboot CPUs and freeze 29/sys/power/disk controls the operating mode of hibernation (Suspend-to-Disk).
30tasks, wait for 5 seconds, unfreeze tasks and enable nonboot CPUs. If it is 30Specifically, it tells the kernel what to do after creating a hibernation image.
31in the 'test' mode, writing 'disk' to /sys/power/state will cause the kernel 31
32to disable nonboot CPUs and freeze tasks, shrink memory, suspend devices, wait 32Reading from it returns a list of supported options encoded as:
33for 5 seconds, resume devices, unfreeze tasks and enable nonboot CPUs. Then, 33
34we are able to look in the log messages and work out, for example, which code 34'platform' (put the system into sleep using a platform-provided method)
35is being slow and which device drivers are misbehaving. 35'shutdown' (shut the system down)
36 36'reboot' (reboot the system)
37Reading from this file will display all supported modes and the currently 37'suspend' (trigger a Suspend-to-RAM transition)
38selected one in brackets, for example 38'test_resume' (resume-after-hibernation test mode)
39 39
40 [shutdown] reboot test testproc 40The currently selected option is printed in square brackets.
41 41
42Writing to this file will accept one of 42The 'platform' option is only available if the platform provides a special
43 43mechanism to put the system to sleep after creating a hibernation image (ACPI
44 'platform' (only if the platform supports it) 44does that, for example). The 'suspend' option is available if Suspend-to-RAM
45 'shutdown' 45is supported. Refer to Documentation/power/basic_pm_debugging.txt for the
46 'reboot' 46description of the 'test_resume' option.
47 'testproc' 47
48 'test' 48To select an option, write the string representing it to /sys/power/disk.
49 49
50/sys/power/image_size controls the size of the image created by 50/sys/power/image_size controls the size of hibernation images.
51the suspend-to-disk mechanism. It can be written a string 51
52representing a non-negative integer that will be used as an upper 52It can be written a string representing a non-negative integer that will be
53limit of the image size, in bytes. The suspend-to-disk mechanism will 53used as a best-effort upper limit of the image size, in bytes. The hibernation
54do its best to ensure the image size will not exceed that number. However, 54core will do its best to ensure that the image size will not exceed that number.
55if this turns out to be impossible, it will try to suspend anyway using the 55However, if that turns out to be impossible to achieve, a hibernation image will
56smallest image possible. In particular, if "0" is written to this file, the 56still be created and its size will be as small as possible. In particular,
57suspend image will be as small as possible. 57writing '0' to this file will enforce hibernation images to be as small as
58 58possible.
59Reading from this file will display the current image size limit, which 59
60is set to 2/5 of available RAM by default. 60Reading from this file returns the current image size limit, which is set to
61 61around 2/5 of available RAM by default.
62/sys/power/pm_trace controls the code which saves the last PM event point in 62
63the RTC across reboots, so that you can debug a machine that just hangs 63/sys/power/pm_trace controls the PM trace mechanism saving the last suspend
64during suspend (or more commonly, during resume). Namely, the RTC is only 64or resume event point in the RTC across reboots.
65used to save the last PM event point if this file contains '1'. Initially it 65
66contains '0' which may be changed to '1' by writing a string representing a 66It helps to debug hard lockups or reboots due to device driver failures that
67nonzero integer into it. 67occur during system suspend or resume (which is more common) more effectively.
68 68
69To use this debugging feature you should attempt to suspend the machine, then 69If /sys/power/pm_trace contains '1', the fingerprint of each suspend/resume
70reboot it and run 70event point in turn will be stored in the RTC memory (overwriting the actual
71 71RTC information), so it will survive a system crash if one occurs right after
72 dmesg -s 1000000 | grep 'hash matches' 72storing it and it can be used later to identify the driver that caused the crash
73 73to happen (see Documentation/power/s2ram.txt for more information).
74CAUTION: Using it will cause your machine's real-time (CMOS) clock to be 74
75set to a random invalid time after a resume. 75Initially it contains '0' which may be changed to '1' by writing a string
76representing a nonzero integer into it.
diff --git a/Documentation/sphinx-static/theme_overrides.css b/Documentation/sphinx-static/theme_overrides.css
index 3a2ac4bcfd78..e88461c4c1e6 100644
--- a/Documentation/sphinx-static/theme_overrides.css
+++ b/Documentation/sphinx-static/theme_overrides.css
@@ -42,11 +42,12 @@
42 caption a.headerlink { opacity: 0; } 42 caption a.headerlink { opacity: 0; }
43 caption a.headerlink:hover { opacity: 1; } 43 caption a.headerlink:hover { opacity: 1; }
44 44
45 /* inline literal: drop the borderbox and red color */ 45 /* inline literal: drop the borderbox, padding and red color */
46 46
47 code, .rst-content tt, .rst-content code { 47 code, .rst-content tt, .rst-content code {
48 color: inherit; 48 color: inherit;
49 border: none; 49 border: none;
50 padding: unset;
50 background: inherit; 51 background: inherit;
51 font-size: 85%; 52 font-size: 85%;
52 } 53 }
diff --git a/MAINTAINERS b/MAINTAINERS
index 20bb1d00098c..71aa5daeae8f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -881,6 +881,15 @@ S: Supported
881F: drivers/gpu/drm/arc/ 881F: drivers/gpu/drm/arc/
882F: Documentation/devicetree/bindings/display/snps,arcpgu.txt 882F: Documentation/devicetree/bindings/display/snps,arcpgu.txt
883 883
884ARM ARCHITECTED TIMER DRIVER
885M: Mark Rutland <mark.rutland@arm.com>
886M: Marc Zyngier <marc.zyngier@arm.com>
887L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
888S: Maintained
889F: arch/arm/include/asm/arch_timer.h
890F: arch/arm64/include/asm/arch_timer.h
891F: drivers/clocksource/arm_arch_timer.c
892
884ARM HDLCD DRM DRIVER 893ARM HDLCD DRM DRIVER
885M: Liviu Dudau <liviu.dudau@arm.com> 894M: Liviu Dudau <liviu.dudau@arm.com>
886S: Supported 895S: Supported
@@ -1004,6 +1013,7 @@ N: meson
1004ARM/Annapurna Labs ALPINE ARCHITECTURE 1013ARM/Annapurna Labs ALPINE ARCHITECTURE
1005M: Tsahee Zidenberg <tsahee@annapurnalabs.com> 1014M: Tsahee Zidenberg <tsahee@annapurnalabs.com>
1006M: Antoine Tenart <antoine.tenart@free-electrons.com> 1015M: Antoine Tenart <antoine.tenart@free-electrons.com>
1016L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1007S: Maintained 1017S: Maintained
1008F: arch/arm/mach-alpine/ 1018F: arch/arm/mach-alpine/
1009F: arch/arm/boot/dts/alpine* 1019F: arch/arm/boot/dts/alpine*
@@ -4524,6 +4534,12 @@ L: linux-edac@vger.kernel.org
4524S: Maintained 4534S: Maintained
4525F: drivers/edac/sb_edac.c 4535F: drivers/edac/sb_edac.c
4526 4536
4537EDAC-SKYLAKE
4538M: Tony Luck <tony.luck@intel.com>
4539L: linux-edac@vger.kernel.org
4540S: Maintained
4541F: drivers/edac/skx_edac.c
4542
4527EDAC-XGENE 4543EDAC-XGENE
4528APPLIED MICRO (APM) X-GENE SOC EDAC 4544APPLIED MICRO (APM) X-GENE SOC EDAC
4529M: Loc Ho <lho@apm.com> 4545M: Loc Ho <lho@apm.com>
@@ -7654,7 +7670,7 @@ L: linux-rdma@vger.kernel.org
7654S: Supported 7670S: Supported
7655W: https://github.com/SoftRoCE/rxe-dev/wiki/rxe-dev:-Home 7671W: https://github.com/SoftRoCE/rxe-dev/wiki/rxe-dev:-Home
7656Q: http://patchwork.kernel.org/project/linux-rdma/list/ 7672Q: http://patchwork.kernel.org/project/linux-rdma/list/
7657F: drivers/infiniband/hw/rxe/ 7673F: drivers/infiniband/sw/rxe/
7658F: include/uapi/rdma/rdma_user_rxe.h 7674F: include/uapi/rdma/rdma_user_rxe.h
7659 7675
7660MEMBARRIER SUPPORT 7676MEMBARRIER SUPPORT
diff --git a/Makefile b/Makefile
index 8c504f324154..67f42d57e6e7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 4 1VERSION = 4
2PATCHLEVEL = 8 2PATCHLEVEL = 8
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc1 4EXTRAVERSION = -rc4
5NAME = Psychotic Stoned Sheep 5NAME = Psychotic Stoned Sheep
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arc/include/asm/entry.h b/arch/arc/include/asm/entry.h
index ad7860c5ce15..51597f344a62 100644
--- a/arch/arc/include/asm/entry.h
+++ b/arch/arc/include/asm/entry.h
@@ -142,7 +142,7 @@
142 142
143#ifdef CONFIG_ARC_CURR_IN_REG 143#ifdef CONFIG_ARC_CURR_IN_REG
144 ; Retrieve orig r25 and save it with rest of callee_regs 144 ; Retrieve orig r25 and save it with rest of callee_regs
145 ld.as r12, [r12, PT_user_r25] 145 ld r12, [r12, PT_user_r25]
146 PUSH r12 146 PUSH r12
147#else 147#else
148 PUSH r25 148 PUSH r25
@@ -198,7 +198,7 @@
198 198
199 ; SP is back to start of pt_regs 199 ; SP is back to start of pt_regs
200#ifdef CONFIG_ARC_CURR_IN_REG 200#ifdef CONFIG_ARC_CURR_IN_REG
201 st.as r12, [sp, PT_user_r25] 201 st r12, [sp, PT_user_r25]
202#endif 202#endif
203.endm 203.endm
204 204
diff --git a/arch/arc/include/asm/irqflags-compact.h b/arch/arc/include/asm/irqflags-compact.h
index c1d36458bfb7..4c6eed80cd8b 100644
--- a/arch/arc/include/asm/irqflags-compact.h
+++ b/arch/arc/include/asm/irqflags-compact.h
@@ -188,10 +188,10 @@ static inline int arch_irqs_disabled(void)
188.endm 188.endm
189 189
190.macro IRQ_ENABLE scratch 190.macro IRQ_ENABLE scratch
191 TRACE_ASM_IRQ_ENABLE
191 lr \scratch, [status32] 192 lr \scratch, [status32]
192 or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK) 193 or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
193 flag \scratch 194 flag \scratch
194 TRACE_ASM_IRQ_ENABLE
195.endm 195.endm
196 196
197#endif /* __ASSEMBLY__ */ 197#endif /* __ASSEMBLY__ */
diff --git a/arch/arc/include/asm/pgtable.h b/arch/arc/include/asm/pgtable.h
index 0f92d97432a2..89eeb3720051 100644
--- a/arch/arc/include/asm/pgtable.h
+++ b/arch/arc/include/asm/pgtable.h
@@ -280,7 +280,7 @@ static inline void pmd_set(pmd_t *pmdp, pte_t *ptep)
280 280
281#define pte_page(pte) pfn_to_page(pte_pfn(pte)) 281#define pte_page(pte) pfn_to_page(pte_pfn(pte))
282#define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot) 282#define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot)
283#define pfn_pte(pfn, prot) (__pte(((pte_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot))) 283#define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
284 284
285/* Don't use virt_to_pfn for macros below: could cause truncations for PAE40*/ 285/* Don't use virt_to_pfn for macros below: could cause truncations for PAE40*/
286#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT) 286#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
diff --git a/arch/arc/include/uapi/asm/elf.h b/arch/arc/include/uapi/asm/elf.h
index 0f99ac8fcbb2..0037a587320d 100644
--- a/arch/arc/include/uapi/asm/elf.h
+++ b/arch/arc/include/uapi/asm/elf.h
@@ -13,8 +13,15 @@
13 13
14/* Machine specific ELF Hdr flags */ 14/* Machine specific ELF Hdr flags */
15#define EF_ARC_OSABI_MSK 0x00000f00 15#define EF_ARC_OSABI_MSK 0x00000f00
16#define EF_ARC_OSABI_ORIG 0x00000000 /* MUST be zero for back-compat */ 16
17#define EF_ARC_OSABI_CURRENT 0x00000300 /* v3 (no legacy syscalls) */ 17#define EF_ARC_OSABI_V3 0x00000300 /* v3 (no legacy syscalls) */
18#define EF_ARC_OSABI_V4 0x00000400 /* v4 (64bit data any reg align) */
19
20#if __GNUC__ < 6
21#define EF_ARC_OSABI_CURRENT EF_ARC_OSABI_V3
22#else
23#define EF_ARC_OSABI_CURRENT EF_ARC_OSABI_V4
24#endif
18 25
19typedef unsigned long elf_greg_t; 26typedef unsigned long elf_greg_t;
20typedef unsigned long elf_fpregset_t; 27typedef unsigned long elf_fpregset_t;
diff --git a/arch/arc/kernel/arcksyms.c b/arch/arc/kernel/arcksyms.c
index 4d9e77724bed..000dd041ab42 100644
--- a/arch/arc/kernel/arcksyms.c
+++ b/arch/arc/kernel/arcksyms.c
@@ -28,6 +28,7 @@ extern void __muldf3(void);
28extern void __divdf3(void); 28extern void __divdf3(void);
29extern void __floatunsidf(void); 29extern void __floatunsidf(void);
30extern void __floatunsisf(void); 30extern void __floatunsisf(void);
31extern void __udivdi3(void);
31 32
32EXPORT_SYMBOL(__ashldi3); 33EXPORT_SYMBOL(__ashldi3);
33EXPORT_SYMBOL(__ashrdi3); 34EXPORT_SYMBOL(__ashrdi3);
@@ -45,6 +46,7 @@ EXPORT_SYMBOL(__muldf3);
45EXPORT_SYMBOL(__divdf3); 46EXPORT_SYMBOL(__divdf3);
46EXPORT_SYMBOL(__floatunsidf); 47EXPORT_SYMBOL(__floatunsidf);
47EXPORT_SYMBOL(__floatunsisf); 48EXPORT_SYMBOL(__floatunsisf);
49EXPORT_SYMBOL(__udivdi3);
48 50
49/* ARC optimised assembler routines */ 51/* ARC optimised assembler routines */
50EXPORT_SYMBOL(memset); 52EXPORT_SYMBOL(memset);
diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c
index b5db9e7fd649..be1972bd2729 100644
--- a/arch/arc/kernel/process.c
+++ b/arch/arc/kernel/process.c
@@ -199,7 +199,7 @@ int elf_check_arch(const struct elf32_hdr *x)
199 } 199 }
200 200
201 eflags = x->e_flags; 201 eflags = x->e_flags;
202 if ((eflags & EF_ARC_OSABI_MSK) < EF_ARC_OSABI_CURRENT) { 202 if ((eflags & EF_ARC_OSABI_MSK) != EF_ARC_OSABI_CURRENT) {
203 pr_err("ABI mismatch - you need newer toolchain\n"); 203 pr_err("ABI mismatch - you need newer toolchain\n");
204 force_sigsegv(SIGSEGV, current); 204 force_sigsegv(SIGSEGV, current);
205 return 0; 205 return 0;
diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c
index a946400a86d0..f52a0d0dc462 100644
--- a/arch/arc/kernel/setup.c
+++ b/arch/arc/kernel/setup.c
@@ -291,8 +291,10 @@ static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
291 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz), 291 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
292 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz)); 292 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
293 293
294 n += scnprintf(buf + n, len - n, 294 n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
295 "OS ABI [v3]\t: no-legacy-syscalls\n"); 295 EF_ARC_OSABI_CURRENT >> 8,
296 EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
297 "no-legacy-syscalls" : "64-bit data any register aligned");
296 298
297 return buf; 299 return buf;
298} 300}
diff --git a/arch/arc/mm/cache.c b/arch/arc/mm/cache.c
index 5a294b2c3cb3..0b10efe3a6a7 100644
--- a/arch/arc/mm/cache.c
+++ b/arch/arc/mm/cache.c
@@ -921,6 +921,15 @@ void arc_cache_init(void)
921 921
922 printk(arc_cache_mumbojumbo(0, str, sizeof(str))); 922 printk(arc_cache_mumbojumbo(0, str, sizeof(str)));
923 923
924 /*
925 * Only master CPU needs to execute rest of function:
926 * - Assume SMP so all cores will have same cache config so
927 * any geomtry checks will be same for all
928 * - IOC setup / dma callbacks only need to be setup once
929 */
930 if (cpu)
931 return;
932
924 if (IS_ENABLED(CONFIG_ARC_HAS_ICACHE)) { 933 if (IS_ENABLED(CONFIG_ARC_HAS_ICACHE)) {
925 struct cpuinfo_arc_cache *ic = &cpuinfo_arc700[cpu].icache; 934 struct cpuinfo_arc_cache *ic = &cpuinfo_arc700[cpu].icache;
926 935
diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c
index 04f83322c9fd..77ff64a874a1 100644
--- a/arch/arc/mm/highmem.c
+++ b/arch/arc/mm/highmem.c
@@ -61,6 +61,7 @@ void *kmap(struct page *page)
61 61
62 return kmap_high(page); 62 return kmap_high(page);
63} 63}
64EXPORT_SYMBOL(kmap);
64 65
65void *kmap_atomic(struct page *page) 66void *kmap_atomic(struct page *page)
66{ 67{
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 56ea5c60b318..61f6ccc19cfa 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -260,12 +260,14 @@ machdirs := $(patsubst %,arch/arm/mach-%/,$(machine-y))
260platdirs := $(patsubst %,arch/arm/plat-%/,$(sort $(plat-y))) 260platdirs := $(patsubst %,arch/arm/plat-%/,$(sort $(plat-y)))
261 261
262ifneq ($(CONFIG_ARCH_MULTIPLATFORM),y) 262ifneq ($(CONFIG_ARCH_MULTIPLATFORM),y)
263ifneq ($(CONFIG_ARM_SINGLE_ARMV7M),y)
263ifeq ($(KBUILD_SRC),) 264ifeq ($(KBUILD_SRC),)
264KBUILD_CPPFLAGS += $(patsubst %,-I%include,$(machdirs) $(platdirs)) 265KBUILD_CPPFLAGS += $(patsubst %,-I%include,$(machdirs) $(platdirs))
265else 266else
266KBUILD_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs) $(platdirs)) 267KBUILD_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs) $(platdirs))
267endif 268endif
268endif 269endif
270endif
269 271
270export TEXT_OFFSET GZFLAGS MMUEXT 272export TEXT_OFFSET GZFLAGS MMUEXT
271 273
diff --git a/arch/arm/boot/dts/arm-realview-pbx-a9.dts b/arch/arm/boot/dts/arm-realview-pbx-a9.dts
index db808f92dd79..90d00b407f85 100644
--- a/arch/arm/boot/dts/arm-realview-pbx-a9.dts
+++ b/arch/arm/boot/dts/arm-realview-pbx-a9.dts
@@ -70,13 +70,12 @@
70 * associativity as these may be erroneously set 70 * associativity as these may be erroneously set
71 * up by boot loader(s). 71 * up by boot loader(s).
72 */ 72 */
73 cache-size = <1048576>; // 1MB 73 cache-size = <131072>; // 128KB
74 cache-sets = <4096>; 74 cache-sets = <512>;
75 cache-line-size = <32>; 75 cache-line-size = <32>;
76 arm,parity-disable; 76 arm,parity-disable;
77 arm,tag-latency = <1>; 77 arm,tag-latency = <1 1 1>;
78 arm,data-latency = <1 1>; 78 arm,data-latency = <1 1 1>;
79 arm,dirty-latency = <1>;
80 }; 79 };
81 80
82 scu: scu@1f000000 { 81 scu: scu@1f000000 {
diff --git a/arch/arm/boot/dts/integratorap.dts b/arch/arm/boot/dts/integratorap.dts
index cf06e32ee108..4b34b54e09a1 100644
--- a/arch/arm/boot/dts/integratorap.dts
+++ b/arch/arm/boot/dts/integratorap.dts
@@ -42,7 +42,7 @@
42 }; 42 };
43 43
44 syscon { 44 syscon {
45 compatible = "arm,integrator-ap-syscon"; 45 compatible = "arm,integrator-ap-syscon", "syscon";
46 reg = <0x11000000 0x100>; 46 reg = <0x11000000 0x100>;
47 interrupt-parent = <&pic>; 47 interrupt-parent = <&pic>;
48 /* These are the logical module IRQs */ 48 /* These are the logical module IRQs */
diff --git a/arch/arm/boot/dts/integratorcp.dts b/arch/arm/boot/dts/integratorcp.dts
index d43f15b4f79a..79430fbfec3b 100644
--- a/arch/arm/boot/dts/integratorcp.dts
+++ b/arch/arm/boot/dts/integratorcp.dts
@@ -94,7 +94,7 @@
94 }; 94 };
95 95
96 syscon { 96 syscon {
97 compatible = "arm,integrator-cp-syscon"; 97 compatible = "arm,integrator-cp-syscon", "syscon";
98 reg = <0xcb000000 0x100>; 98 reg = <0xcb000000 0x100>;
99 }; 99 };
100 100
diff --git a/arch/arm/boot/dts/keystone.dtsi b/arch/arm/boot/dts/keystone.dtsi
index 00cb314d5e4d..e23f46d15c80 100644
--- a/arch/arm/boot/dts/keystone.dtsi
+++ b/arch/arm/boot/dts/keystone.dtsi
@@ -70,14 +70,6 @@
70 cpu_on = <0x84000003>; 70 cpu_on = <0x84000003>;
71 }; 71 };
72 72
73 psci {
74 compatible = "arm,psci";
75 method = "smc";
76 cpu_suspend = <0x84000001>;
77 cpu_off = <0x84000002>;
78 cpu_on = <0x84000003>;
79 };
80
81 soc { 73 soc {
82 #address-cells = <1>; 74 #address-cells = <1>;
83 #size-cells = <1>; 75 #size-cells = <1>;
diff --git a/arch/arm/boot/dts/tegra124-jetson-tk1.dts b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
index e52b82449a79..6403e0de540e 100644
--- a/arch/arm/boot/dts/tegra124-jetson-tk1.dts
+++ b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
@@ -1382,7 +1382,7 @@
1382 * Pin 41: BR_UART1_TXD 1382 * Pin 41: BR_UART1_TXD
1383 * Pin 44: BR_UART1_RXD 1383 * Pin 44: BR_UART1_RXD
1384 */ 1384 */
1385 serial@70006000 { 1385 serial@0,70006000 {
1386 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart"; 1386 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart";
1387 status = "okay"; 1387 status = "okay";
1388 }; 1388 };
@@ -1394,7 +1394,7 @@
1394 * Pin 71: UART2_CTS_L 1394 * Pin 71: UART2_CTS_L
1395 * Pin 74: UART2_RTS_L 1395 * Pin 74: UART2_RTS_L
1396 */ 1396 */
1397 serial@70006040 { 1397 serial@0,70006040 {
1398 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart"; 1398 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart";
1399 status = "okay"; 1399 status = "okay";
1400 }; 1400 };
diff --git a/arch/arm/configs/aspeed_g4_defconfig b/arch/arm/configs/aspeed_g4_defconfig
index b6e54ee9bdbd..ca39c04fec6b 100644
--- a/arch/arm/configs/aspeed_g4_defconfig
+++ b/arch/arm/configs/aspeed_g4_defconfig
@@ -58,7 +58,7 @@ CONFIG_SERIAL_OF_PLATFORM=y
58# CONFIG_IOMMU_SUPPORT is not set 58# CONFIG_IOMMU_SUPPORT is not set
59CONFIG_FIRMWARE_MEMMAP=y 59CONFIG_FIRMWARE_MEMMAP=y
60CONFIG_FANOTIFY=y 60CONFIG_FANOTIFY=y
61CONFIG_PRINTK_TIME=1 61CONFIG_PRINTK_TIME=y
62CONFIG_DYNAMIC_DEBUG=y 62CONFIG_DYNAMIC_DEBUG=y
63CONFIG_STRIP_ASM_SYMS=y 63CONFIG_STRIP_ASM_SYMS=y
64CONFIG_PAGE_POISONING=y 64CONFIG_PAGE_POISONING=y
diff --git a/arch/arm/configs/aspeed_g5_defconfig b/arch/arm/configs/aspeed_g5_defconfig
index 892605167357..4f366b0370e9 100644
--- a/arch/arm/configs/aspeed_g5_defconfig
+++ b/arch/arm/configs/aspeed_g5_defconfig
@@ -59,7 +59,7 @@ CONFIG_SERIAL_OF_PLATFORM=y
59# CONFIG_IOMMU_SUPPORT is not set 59# CONFIG_IOMMU_SUPPORT is not set
60CONFIG_FIRMWARE_MEMMAP=y 60CONFIG_FIRMWARE_MEMMAP=y
61CONFIG_FANOTIFY=y 61CONFIG_FANOTIFY=y
62CONFIG_PRINTK_TIME=1 62CONFIG_PRINTK_TIME=y
63CONFIG_DYNAMIC_DEBUG=y 63CONFIG_DYNAMIC_DEBUG=y
64CONFIG_STRIP_ASM_SYMS=y 64CONFIG_STRIP_ASM_SYMS=y
65CONFIG_PAGE_POISONING=y 65CONFIG_PAGE_POISONING=y
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index bc5f50799d75..9f157e7c51e7 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -295,6 +295,7 @@ __und_svc_fault:
295 bl __und_fault 295 bl __und_fault
296 296
297__und_svc_finish: 297__und_svc_finish:
298 get_thread_info tsk
298 ldr r5, [sp, #S_PSR] @ Get SVC cpsr 299 ldr r5, [sp, #S_PSR] @ Get SVC cpsr
299 svc_exit r5 @ return from exception 300 svc_exit r5 @ return from exception
300 UNWIND(.fnend ) 301 UNWIND(.fnend )
diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c
index 087acb569b63..5f221acd21ae 100644
--- a/arch/arm/kernel/sys_oabi-compat.c
+++ b/arch/arm/kernel/sys_oabi-compat.c
@@ -279,8 +279,12 @@ asmlinkage long sys_oabi_epoll_wait(int epfd,
279 mm_segment_t fs; 279 mm_segment_t fs;
280 long ret, err, i; 280 long ret, err, i;
281 281
282 if (maxevents <= 0 || maxevents > (INT_MAX/sizeof(struct epoll_event))) 282 if (maxevents <= 0 ||
283 maxevents > (INT_MAX/sizeof(*kbuf)) ||
284 maxevents > (INT_MAX/sizeof(*events)))
283 return -EINVAL; 285 return -EINVAL;
286 if (!access_ok(VERIFY_WRITE, events, sizeof(*events) * maxevents))
287 return -EFAULT;
284 kbuf = kmalloc(sizeof(*kbuf) * maxevents, GFP_KERNEL); 288 kbuf = kmalloc(sizeof(*kbuf) * maxevents, GFP_KERNEL);
285 if (!kbuf) 289 if (!kbuf)
286 return -ENOMEM; 290 return -ENOMEM;
@@ -317,6 +321,8 @@ asmlinkage long sys_oabi_semtimedop(int semid,
317 321
318 if (nsops < 1 || nsops > SEMOPM) 322 if (nsops < 1 || nsops > SEMOPM)
319 return -EINVAL; 323 return -EINVAL;
324 if (!access_ok(VERIFY_READ, tsops, sizeof(*tsops) * nsops))
325 return -EFAULT;
320 sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL); 326 sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL);
321 if (!sops) 327 if (!sops)
322 return -ENOMEM; 328 return -ENOMEM;
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index d94bb9093ead..75f130ef6504 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -1009,9 +1009,13 @@ long kvm_arch_vm_ioctl(struct file *filp,
1009 1009
1010 switch (ioctl) { 1010 switch (ioctl) {
1011 case KVM_CREATE_IRQCHIP: { 1011 case KVM_CREATE_IRQCHIP: {
1012 int ret;
1012 if (!vgic_present) 1013 if (!vgic_present)
1013 return -ENXIO; 1014 return -ENXIO;
1014 return kvm_vgic_create(kvm, KVM_DEV_TYPE_ARM_VGIC_V2); 1015 mutex_lock(&kvm->lock);
1016 ret = kvm_vgic_create(kvm, KVM_DEV_TYPE_ARM_VGIC_V2);
1017 mutex_unlock(&kvm->lock);
1018 return ret;
1015 } 1019 }
1016 case KVM_ARM_SET_DEVICE_ADDR: { 1020 case KVM_ARM_SET_DEVICE_ADDR: {
1017 struct kvm_arm_device_addr dev_addr; 1021 struct kvm_arm_device_addr dev_addr;
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index bda27b6b1aa2..29d0b23af2a9 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -1309,7 +1309,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
1309 smp_rmb(); 1309 smp_rmb();
1310 1310
1311 pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable); 1311 pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable);
1312 if (is_error_pfn(pfn)) 1312 if (is_error_noslot_pfn(pfn))
1313 return -EFAULT; 1313 return -EFAULT;
1314 1314
1315 if (kvm_is_device_pfn(pfn)) { 1315 if (kvm_is_device_pfn(pfn)) {
diff --git a/arch/arm/mach-clps711x/Kconfig b/arch/arm/mach-clps711x/Kconfig
index dc7c6edeab39..61284b9389cf 100644
--- a/arch/arm/mach-clps711x/Kconfig
+++ b/arch/arm/mach-clps711x/Kconfig
@@ -1,13 +1,13 @@
1menuconfig ARCH_CLPS711X 1menuconfig ARCH_CLPS711X
2 bool "Cirrus Logic EP721x/EP731x-based" 2 bool "Cirrus Logic EP721x/EP731x-based"
3 depends on ARCH_MULTI_V4T 3 depends on ARCH_MULTI_V4T
4 select ARCH_REQUIRE_GPIOLIB
5 select AUTO_ZRELADDR 4 select AUTO_ZRELADDR
6 select CLKSRC_OF 5 select CLKSRC_OF
7 select CLPS711X_TIMER 6 select CLPS711X_TIMER
8 select COMMON_CLK 7 select COMMON_CLK
9 select CPU_ARM720T 8 select CPU_ARM720T
10 select GENERIC_CLOCKEVENTS 9 select GENERIC_CLOCKEVENTS
10 select GPIOLIB
11 select MFD_SYSCON 11 select MFD_SYSCON
12 select OF_IRQ 12 select OF_IRQ
13 select USE_OF 13 select USE_OF
diff --git a/arch/arm/mach-imx/gpc.c b/arch/arm/mach-imx/gpc.c
index fd8720532471..0df062d8b2c9 100644
--- a/arch/arm/mach-imx/gpc.c
+++ b/arch/arm/mach-imx/gpc.c
@@ -271,6 +271,12 @@ static int __init imx_gpc_init(struct device_node *node,
271 for (i = 0; i < IMR_NUM; i++) 271 for (i = 0; i < IMR_NUM; i++)
272 writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4); 272 writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4);
273 273
274 /*
275 * Clear the OF_POPULATED flag set in of_irq_init so that
276 * later the GPC power domain driver will not be skipped.
277 */
278 of_node_clear_flag(node, OF_POPULATED);
279
274 return 0; 280 return 0;
275} 281}
276IRQCHIP_DECLARE(imx_gpc, "fsl,imx6q-gpc", imx_gpc_init); 282IRQCHIP_DECLARE(imx_gpc, "fsl,imx6q-gpc", imx_gpc_init);
diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
index e53c6cfcab51..6c6497e80a7b 100644
--- a/arch/arm/mach-mvebu/Makefile
+++ b/arch/arm/mach-mvebu/Makefile
@@ -1,5 +1,4 @@
1ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \ 1ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/arch/arm/plat-orion/include
2 -I$(srctree)/arch/arm/plat-orion/include
3 2
4AFLAGS_coherency_ll.o := -Wa,-march=armv7-a 3AFLAGS_coherency_ll.o := -Wa,-march=armv7-a
5CFLAGS_pmsu.o := -march=armv7-a 4CFLAGS_pmsu.o := -march=armv7-a
diff --git a/arch/arm/mach-oxnas/Kconfig b/arch/arm/mach-oxnas/Kconfig
index 567496bd250a..29100beb2e7f 100644
--- a/arch/arm/mach-oxnas/Kconfig
+++ b/arch/arm/mach-oxnas/Kconfig
@@ -11,11 +11,13 @@ if ARCH_OXNAS
11 11
12config MACH_OX810SE 12config MACH_OX810SE
13 bool "Support OX810SE Based Products" 13 bool "Support OX810SE Based Products"
14 select ARCH_HAS_RESET_CONTROLLER
14 select COMMON_CLK_OXNAS 15 select COMMON_CLK_OXNAS
15 select CPU_ARM926T 16 select CPU_ARM926T
16 select MFD_SYSCON 17 select MFD_SYSCON
17 select OXNAS_RPS_TIMER 18 select OXNAS_RPS_TIMER
18 select PINCTRL_OXNAS 19 select PINCTRL_OXNAS
20 select RESET_CONTROLLER
19 select RESET_OXNAS 21 select RESET_OXNAS
20 select VERSATILE_FPGA_IRQ 22 select VERSATILE_FPGA_IRQ
21 help 23 help
diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c
index dc109dc3a622..10bfdb169366 100644
--- a/arch/arm/mach-pxa/corgi.c
+++ b/arch/arm/mach-pxa/corgi.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> /* symbol_get ; symbol_put */
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/platform_device.h> 18#include <linux/platform_device.h>
18#include <linux/major.h> 19#include <linux/major.h>
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 1080580b1343..2c150bfc0cd5 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> /* symbol_get ; symbol_put */
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <linux/gpio_keys.h> 19#include <linux/gpio_keys.h>
diff --git a/arch/arm/mach-realview/Makefile b/arch/arm/mach-realview/Makefile
index dae8d86ef4cc..404882130956 100644
--- a/arch/arm/mach-realview/Makefile
+++ b/arch/arm/mach-realview/Makefile
@@ -1,8 +1,7 @@
1# 1#
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \ 4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/arch/arm/plat-versatile/include
5 -I$(srctree)/arch/arm/plat-versatile/include
6 5
7obj-y := core.o 6obj-y := core.o
8obj-$(CONFIG_REALVIEW_DT) += realview-dt.o 7obj-$(CONFIG_REALVIEW_DT) += realview-dt.o
diff --git a/arch/arm/mach-s5pv210/Makefile b/arch/arm/mach-s5pv210/Makefile
index 72b9e9671507..fa7fb716e388 100644
--- a/arch/arm/mach-s5pv210/Makefile
+++ b/arch/arm/mach-s5pv210/Makefile
@@ -5,7 +5,7 @@
5# 5#
6# Licensed under GPLv2 6# Licensed under GPLv2
7 7
8ccflags-$(CONFIG_ARCH_MULTIPLATFORM) += -I$(srctree)/$(src)/include -I$(srctree)/arch/arm/plat-samsung/include 8ccflags-$(CONFIG_ARCH_MULTIPLATFORM) += -I$(srctree)/arch/arm/plat-samsung/include
9 9
10# Core 10# Core
11 11
diff --git a/arch/arm/mach-shmobile/platsmp.c b/arch/arm/mach-shmobile/platsmp.c
index f3dba6f356e2..02e21bceb085 100644
--- a/arch/arm/mach-shmobile/platsmp.c
+++ b/arch/arm/mach-shmobile/platsmp.c
@@ -40,5 +40,8 @@ bool shmobile_smp_cpu_can_disable(unsigned int cpu)
40bool __init shmobile_smp_init_fallback_ops(void) 40bool __init shmobile_smp_init_fallback_ops(void)
41{ 41{
42 /* fallback on PSCI/smp_ops if no other DT based method is detected */ 42 /* fallback on PSCI/smp_ops if no other DT based method is detected */
43 if (!IS_ENABLED(CONFIG_SMP))
44 return false;
45
43 return platform_can_secondary_boot() ? true : false; 46 return platform_can_secondary_boot() ? true : false;
44} 47}
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 62f4d01941f7..6344913f0804 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -728,7 +728,8 @@ static void *__init late_alloc(unsigned long sz)
728{ 728{
729 void *ptr = (void *)__get_free_pages(PGALLOC_GFP, get_order(sz)); 729 void *ptr = (void *)__get_free_pages(PGALLOC_GFP, get_order(sz));
730 730
731 BUG_ON(!ptr); 731 if (!ptr || !pgtable_page_ctor(virt_to_page(ptr)))
732 BUG();
732 return ptr; 733 return ptr;
733} 734}
734 735
@@ -1155,10 +1156,19 @@ void __init sanity_check_meminfo(void)
1155{ 1156{
1156 phys_addr_t memblock_limit = 0; 1157 phys_addr_t memblock_limit = 0;
1157 int highmem = 0; 1158 int highmem = 0;
1158 phys_addr_t vmalloc_limit = __pa(vmalloc_min - 1) + 1; 1159 u64 vmalloc_limit;
1159 struct memblock_region *reg; 1160 struct memblock_region *reg;
1160 bool should_use_highmem = false; 1161 bool should_use_highmem = false;
1161 1162
1163 /*
1164 * Let's use our own (unoptimized) equivalent of __pa() that is
1165 * not affected by wrap-arounds when sizeof(phys_addr_t) == 4.
1166 * The result is used as the upper bound on physical memory address
1167 * and may itself be outside the valid range for which phys_addr_t
1168 * and therefore __pa() is defined.
1169 */
1170 vmalloc_limit = (u64)(uintptr_t)vmalloc_min - PAGE_OFFSET + PHYS_OFFSET;
1171
1162 for_each_memblock(memory, reg) { 1172 for_each_memblock(memory, reg) {
1163 phys_addr_t block_start = reg->base; 1173 phys_addr_t block_start = reg->base;
1164 phys_addr_t block_end = reg->base + reg->size; 1174 phys_addr_t block_end = reg->base + reg->size;
@@ -1183,10 +1193,11 @@ void __init sanity_check_meminfo(void)
1183 if (reg->size > size_limit) { 1193 if (reg->size > size_limit) {
1184 phys_addr_t overlap_size = reg->size - size_limit; 1194 phys_addr_t overlap_size = reg->size - size_limit;
1185 1195
1186 pr_notice("Truncating RAM at %pa-%pa to -%pa", 1196 pr_notice("Truncating RAM at %pa-%pa",
1187 &block_start, &block_end, &vmalloc_limit); 1197 &block_start, &block_end);
1188 memblock_remove(vmalloc_limit, overlap_size);
1189 block_end = vmalloc_limit; 1198 block_end = vmalloc_limit;
1199 pr_cont(" to -%pa", &block_end);
1200 memblock_remove(vmalloc_limit, overlap_size);
1190 should_use_highmem = true; 1201 should_use_highmem = true;
1191 } 1202 }
1192 } 1203 }
diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index b0b82f5ea338..3d2cef6488ea 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
50static struct vcpu_info __percpu *xen_vcpu_info; 50static struct vcpu_info __percpu *xen_vcpu_info;
51 51
52/* Linux <-> Xen vCPU id mapping */ 52/* Linux <-> Xen vCPU id mapping */
53DEFINE_PER_CPU(int, xen_vcpu_id) = -1; 53DEFINE_PER_CPU(uint32_t, xen_vcpu_id);
54EXPORT_PER_CPU_SYMBOL(xen_vcpu_id); 54EXPORT_PER_CPU_SYMBOL(xen_vcpu_id);
55 55
56/* These are unused until we support booting "pre-ballooned" */ 56/* These are unused until we support booting "pre-ballooned" */
diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms
index bb2616b16157..be5d824ebdba 100644
--- a/arch/arm64/Kconfig.platforms
+++ b/arch/arm64/Kconfig.platforms
@@ -8,7 +8,7 @@ config ARCH_SUNXI
8 8
9config ARCH_ALPINE 9config ARCH_ALPINE
10 bool "Annapurna Labs Alpine platform" 10 bool "Annapurna Labs Alpine platform"
11 select ALPINE_MSI 11 select ALPINE_MSI if PCI
12 help 12 help
13 This enables support for the Annapurna Labs Alpine 13 This enables support for the Annapurna Labs Alpine
14 Soc family. 14 Soc family.
@@ -66,7 +66,7 @@ config ARCH_LG1K
66config ARCH_HISI 66config ARCH_HISI
67 bool "Hisilicon SoC Family" 67 bool "Hisilicon SoC Family"
68 select ARM_TIMER_SP804 68 select ARM_TIMER_SP804
69 select HISILICON_IRQ_MBIGEN 69 select HISILICON_IRQ_MBIGEN if PCI
70 help 70 help
71 This enables support for Hisilicon ARMv8 SoC family 71 This enables support for Hisilicon ARMv8 SoC family
72 72
diff --git a/arch/arm64/boot/dts/exynos/exynos7-espresso.dts b/arch/arm64/boot/dts/exynos/exynos7-espresso.dts
index 299f3ce969ab..c528dd52ba2d 100644
--- a/arch/arm64/boot/dts/exynos/exynos7-espresso.dts
+++ b/arch/arm64/boot/dts/exynos/exynos7-espresso.dts
@@ -12,6 +12,7 @@
12/dts-v1/; 12/dts-v1/;
13#include "exynos7.dtsi" 13#include "exynos7.dtsi"
14#include <dt-bindings/interrupt-controller/irq.h> 14#include <dt-bindings/interrupt-controller/irq.h>
15#include <dt-bindings/clock/samsung,s2mps11.h>
15 16
16/ { 17/ {
17 model = "Samsung Exynos7 Espresso board based on EXYNOS7"; 18 model = "Samsung Exynos7 Espresso board based on EXYNOS7";
@@ -43,6 +44,8 @@
43 44
44&rtc { 45&rtc {
45 status = "okay"; 46 status = "okay";
47 clocks = <&clock_ccore PCLK_RTC>, <&s2mps15_osc S2MPS11_CLK_AP>;
48 clock-names = "rtc", "rtc_src";
46}; 49};
47 50
48&watchdog { 51&watchdog {
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 0555b7caaf2c..eadf4855ad2d 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -1,4 +1,3 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
3CONFIG_POSIX_MQUEUE=y 2CONFIG_POSIX_MQUEUE=y
4CONFIG_AUDIT=y 3CONFIG_AUDIT=y
@@ -15,10 +14,14 @@ CONFIG_IKCONFIG_PROC=y
15CONFIG_LOG_BUF_SHIFT=14 14CONFIG_LOG_BUF_SHIFT=14
16CONFIG_MEMCG=y 15CONFIG_MEMCG=y
17CONFIG_MEMCG_SWAP=y 16CONFIG_MEMCG_SWAP=y
17CONFIG_BLK_CGROUP=y
18CONFIG_CGROUP_PIDS=y
18CONFIG_CGROUP_HUGETLB=y 19CONFIG_CGROUP_HUGETLB=y
19# CONFIG_UTS_NS is not set 20CONFIG_CPUSETS=y
20# CONFIG_IPC_NS is not set 21CONFIG_CGROUP_DEVICE=y
21# CONFIG_NET_NS is not set 22CONFIG_CGROUP_CPUACCT=y
23CONFIG_CGROUP_PERF=y
24CONFIG_USER_NS=y
22CONFIG_SCHED_AUTOGROUP=y 25CONFIG_SCHED_AUTOGROUP=y
23CONFIG_BLK_DEV_INITRD=y 26CONFIG_BLK_DEV_INITRD=y
24CONFIG_KALLSYMS_ALL=y 27CONFIG_KALLSYMS_ALL=y
@@ -71,6 +74,7 @@ CONFIG_PREEMPT=y
71CONFIG_KSM=y 74CONFIG_KSM=y
72CONFIG_TRANSPARENT_HUGEPAGE=y 75CONFIG_TRANSPARENT_HUGEPAGE=y
73CONFIG_CMA=y 76CONFIG_CMA=y
77CONFIG_SECCOMP=y
74CONFIG_XEN=y 78CONFIG_XEN=y
75CONFIG_KEXEC=y 79CONFIG_KEXEC=y
76# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 80# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
@@ -84,10 +88,37 @@ CONFIG_NET=y
84CONFIG_PACKET=y 88CONFIG_PACKET=y
85CONFIG_UNIX=y 89CONFIG_UNIX=y
86CONFIG_INET=y 90CONFIG_INET=y
91CONFIG_IP_MULTICAST=y
87CONFIG_IP_PNP=y 92CONFIG_IP_PNP=y
88CONFIG_IP_PNP_DHCP=y 93CONFIG_IP_PNP_DHCP=y
89CONFIG_IP_PNP_BOOTP=y 94CONFIG_IP_PNP_BOOTP=y
90# CONFIG_IPV6 is not set 95CONFIG_IPV6=m
96CONFIG_NETFILTER=y
97CONFIG_NF_CONNTRACK=m
98CONFIG_NF_CONNTRACK_EVENTS=y
99CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
100CONFIG_NETFILTER_XT_TARGET_LOG=m
101CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
102CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
103CONFIG_NF_CONNTRACK_IPV4=m
104CONFIG_IP_NF_IPTABLES=m
105CONFIG_IP_NF_FILTER=m
106CONFIG_IP_NF_TARGET_REJECT=m
107CONFIG_IP_NF_NAT=m
108CONFIG_IP_NF_TARGET_MASQUERADE=m
109CONFIG_IP_NF_MANGLE=m
110CONFIG_NF_CONNTRACK_IPV6=m
111CONFIG_IP6_NF_IPTABLES=m
112CONFIG_IP6_NF_FILTER=m
113CONFIG_IP6_NF_TARGET_REJECT=m
114CONFIG_IP6_NF_MANGLE=m
115CONFIG_IP6_NF_NAT=m
116CONFIG_IP6_NF_TARGET_MASQUERADE=m
117CONFIG_BRIDGE=m
118CONFIG_BRIDGE_VLAN_FILTERING=y
119CONFIG_VLAN_8021Q=m
120CONFIG_VLAN_8021Q_GVRP=y
121CONFIG_VLAN_8021Q_MVRP=y
91CONFIG_BPF_JIT=y 122CONFIG_BPF_JIT=y
92CONFIG_CFG80211=m 123CONFIG_CFG80211=m
93CONFIG_MAC80211=m 124CONFIG_MAC80211=m
@@ -103,6 +134,7 @@ CONFIG_MTD=y
103CONFIG_MTD_M25P80=y 134CONFIG_MTD_M25P80=y
104CONFIG_MTD_SPI_NOR=y 135CONFIG_MTD_SPI_NOR=y
105CONFIG_BLK_DEV_LOOP=y 136CONFIG_BLK_DEV_LOOP=y
137CONFIG_BLK_DEV_NBD=m
106CONFIG_VIRTIO_BLK=y 138CONFIG_VIRTIO_BLK=y
107CONFIG_SRAM=y 139CONFIG_SRAM=y
108# CONFIG_SCSI_PROC_FS is not set 140# CONFIG_SCSI_PROC_FS is not set
@@ -120,7 +152,10 @@ CONFIG_SATA_SIL24=y
120CONFIG_PATA_PLATFORM=y 152CONFIG_PATA_PLATFORM=y
121CONFIG_PATA_OF_PLATFORM=y 153CONFIG_PATA_OF_PLATFORM=y
122CONFIG_NETDEVICES=y 154CONFIG_NETDEVICES=y
155CONFIG_MACVLAN=m
156CONFIG_MACVTAP=m
123CONFIG_TUN=y 157CONFIG_TUN=y
158CONFIG_VETH=m
124CONFIG_VIRTIO_NET=y 159CONFIG_VIRTIO_NET=y
125CONFIG_AMD_XGBE=y 160CONFIG_AMD_XGBE=y
126CONFIG_NET_XGENE=y 161CONFIG_NET_XGENE=y
@@ -350,12 +385,16 @@ CONFIG_EXYNOS_ADC=y
350CONFIG_PWM_SAMSUNG=y 385CONFIG_PWM_SAMSUNG=y
351CONFIG_EXT2_FS=y 386CONFIG_EXT2_FS=y
352CONFIG_EXT3_FS=y 387CONFIG_EXT3_FS=y
388CONFIG_EXT4_FS_POSIX_ACL=y
389CONFIG_BTRFS_FS=m
390CONFIG_BTRFS_FS_POSIX_ACL=y
353CONFIG_FANOTIFY=y 391CONFIG_FANOTIFY=y
354CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y 392CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y
355CONFIG_QUOTA=y 393CONFIG_QUOTA=y
356CONFIG_AUTOFS4_FS=y 394CONFIG_AUTOFS4_FS=y
357CONFIG_FUSE_FS=y 395CONFIG_FUSE_FS=m
358CONFIG_CUSE=y 396CONFIG_CUSE=m
397CONFIG_OVERLAY_FS=m
359CONFIG_VFAT_FS=y 398CONFIG_VFAT_FS=y
360CONFIG_TMPFS=y 399CONFIG_TMPFS=y
361CONFIG_HUGETLBFS=y 400CONFIG_HUGETLBFS=y
diff --git a/arch/arm64/include/asm/kprobes.h b/arch/arm64/include/asm/kprobes.h
index 61b49150dfa3..1737aecfcc5e 100644
--- a/arch/arm64/include/asm/kprobes.h
+++ b/arch/arm64/include/asm/kprobes.h
@@ -22,7 +22,6 @@
22 22
23#define __ARCH_WANT_KPROBES_INSN_SLOT 23#define __ARCH_WANT_KPROBES_INSN_SLOT
24#define MAX_INSN_SIZE 1 24#define MAX_INSN_SIZE 1
25#define MAX_STACK_SIZE 128
26 25
27#define flush_insn_slot(p) do { } while (0) 26#define flush_insn_slot(p) do { } while (0)
28#define kretprobe_blacklist_size 0 27#define kretprobe_blacklist_size 0
@@ -47,7 +46,6 @@ struct kprobe_ctlblk {
47 struct prev_kprobe prev_kprobe; 46 struct prev_kprobe prev_kprobe;
48 struct kprobe_step_ctx ss_ctx; 47 struct kprobe_step_ctx ss_ctx;
49 struct pt_regs jprobe_saved_regs; 48 struct pt_regs jprobe_saved_regs;
50 char jprobes_stack[MAX_STACK_SIZE];
51}; 49};
52 50
53void arch_remove_kprobe(struct kprobe *); 51void arch_remove_kprobe(struct kprobe *);
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 96e4a2b64cc1..441420ca7d08 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -353,6 +353,8 @@ el1_sync:
353 lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class 353 lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class
354 cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1 354 cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1
355 b.eq el1_da 355 b.eq el1_da
356 cmp x24, #ESR_ELx_EC_IABT_CUR // instruction abort in EL1
357 b.eq el1_ia
356 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap 358 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap
357 b.eq el1_undef 359 b.eq el1_undef
358 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception 360 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception
@@ -364,6 +366,11 @@ el1_sync:
364 cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1 366 cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1
365 b.ge el1_dbg 367 b.ge el1_dbg
366 b el1_inv 368 b el1_inv
369
370el1_ia:
371 /*
372 * Fall through to the Data abort case
373 */
367el1_da: 374el1_da:
368 /* 375 /*
369 * Data abort handling 376 * Data abort handling
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index b77f58355da1..3e7b050e99dc 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -757,6 +757,9 @@ ENTRY(__enable_mmu)
757 isb 757 isb
758 bl __create_page_tables // recreate kernel mapping 758 bl __create_page_tables // recreate kernel mapping
759 759
760 tlbi vmalle1 // Remove any stale TLB entries
761 dsb nsh
762
760 msr sctlr_el1, x19 // re-enable the MMU 763 msr sctlr_el1, x19 // re-enable the MMU
761 isb 764 isb
762 ic iallu // flush instructions fetched 765 ic iallu // flush instructions fetched
diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
index 21ab5df9fa76..65d81f965e74 100644
--- a/arch/arm64/kernel/hibernate.c
+++ b/arch/arm64/kernel/hibernate.c
@@ -35,6 +35,7 @@
35#include <asm/sections.h> 35#include <asm/sections.h>
36#include <asm/smp.h> 36#include <asm/smp.h>
37#include <asm/suspend.h> 37#include <asm/suspend.h>
38#include <asm/sysreg.h>
38#include <asm/virt.h> 39#include <asm/virt.h>
39 40
40/* 41/*
@@ -217,12 +218,22 @@ static int create_safe_exec_page(void *src_start, size_t length,
217 set_pte(pte, __pte(virt_to_phys((void *)dst) | 218 set_pte(pte, __pte(virt_to_phys((void *)dst) |
218 pgprot_val(PAGE_KERNEL_EXEC))); 219 pgprot_val(PAGE_KERNEL_EXEC)));
219 220
220 /* Load our new page tables */ 221 /*
221 asm volatile("msr ttbr0_el1, %0;" 222 * Load our new page tables. A strict BBM approach requires that we
222 "isb;" 223 * ensure that TLBs are free of any entries that may overlap with the
223 "tlbi vmalle1is;" 224 * global mappings we are about to install.
224 "dsb ish;" 225 *
225 "isb" : : "r"(virt_to_phys(pgd))); 226 * For a real hibernate/resume cycle TTBR0 currently points to a zero
227 * page, but TLBs may contain stale ASID-tagged entries (e.g. for EFI
228 * runtime services), while for a userspace-driven test_resume cycle it
229 * points to userspace page tables (and we must point it at a zero page
230 * ourselves). Elsewhere we only (un)install the idmap with preemption
231 * disabled, so T0SZ should be as required regardless.
232 */
233 cpu_set_reserved_ttbr0();
234 local_flush_tlb_all();
235 write_sysreg(virt_to_phys(pgd), ttbr0_el1);
236 isb();
226 237
227 *phys_dst_addr = virt_to_phys((void *)dst); 238 *phys_dst_addr = virt_to_phys((void *)dst);
228 239
@@ -394,6 +405,38 @@ int swsusp_arch_resume(void)
394 void *, phys_addr_t, phys_addr_t); 405 void *, phys_addr_t, phys_addr_t);
395 406
396 /* 407 /*
408 * Restoring the memory image will overwrite the ttbr1 page tables.
409 * Create a second copy of just the linear map, and use this when
410 * restoring.
411 */
412 tmp_pg_dir = (pgd_t *)get_safe_page(GFP_ATOMIC);
413 if (!tmp_pg_dir) {
414 pr_err("Failed to allocate memory for temporary page tables.");
415 rc = -ENOMEM;
416 goto out;
417 }
418 rc = copy_page_tables(tmp_pg_dir, PAGE_OFFSET, 0);
419 if (rc)
420 goto out;
421
422 /*
423 * Since we only copied the linear map, we need to find restore_pblist's
424 * linear map address.
425 */
426 lm_restore_pblist = LMADDR(restore_pblist);
427
428 /*
429 * We need a zero page that is zero before & after resume in order to
430 * to break before make on the ttbr1 page tables.
431 */
432 zero_page = (void *)get_safe_page(GFP_ATOMIC);
433 if (!zero_page) {
434 pr_err("Failed to allocate zero page.");
435 rc = -ENOMEM;
436 goto out;
437 }
438
439 /*
397 * Locate the exit code in the bottom-but-one page, so that *NULL 440 * Locate the exit code in the bottom-but-one page, so that *NULL
398 * still has disastrous affects. 441 * still has disastrous affects.
399 */ 442 */
@@ -419,27 +462,6 @@ int swsusp_arch_resume(void)
419 __flush_dcache_area(hibernate_exit, exit_size); 462 __flush_dcache_area(hibernate_exit, exit_size);
420 463
421 /* 464 /*
422 * Restoring the memory image will overwrite the ttbr1 page tables.
423 * Create a second copy of just the linear map, and use this when
424 * restoring.
425 */
426 tmp_pg_dir = (pgd_t *)get_safe_page(GFP_ATOMIC);
427 if (!tmp_pg_dir) {
428 pr_err("Failed to allocate memory for temporary page tables.");
429 rc = -ENOMEM;
430 goto out;
431 }
432 rc = copy_page_tables(tmp_pg_dir, PAGE_OFFSET, 0);
433 if (rc)
434 goto out;
435
436 /*
437 * Since we only copied the linear map, we need to find restore_pblist's
438 * linear map address.
439 */
440 lm_restore_pblist = LMADDR(restore_pblist);
441
442 /*
443 * KASLR will cause the el2 vectors to be in a different location in 465 * KASLR will cause the el2 vectors to be in a different location in
444 * the resumed kernel. Load hibernate's temporary copy into el2. 466 * the resumed kernel. Load hibernate's temporary copy into el2.
445 * 467 *
@@ -453,12 +475,6 @@ int swsusp_arch_resume(void)
453 __hyp_set_vectors(el2_vectors); 475 __hyp_set_vectors(el2_vectors);
454 } 476 }
455 477
456 /*
457 * We need a zero page that is zero before & after resume in order to
458 * to break before make on the ttbr1 page tables.
459 */
460 zero_page = (void *)get_safe_page(GFP_ATOMIC);
461
462 hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1, 478 hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1,
463 resume_hdr.reenter_kernel, lm_restore_pblist, 479 resume_hdr.reenter_kernel, lm_restore_pblist,
464 resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page)); 480 resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page));
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index bf9768588288..c6b0f40620d8 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -41,18 +41,6 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
41static void __kprobes 41static void __kprobes
42post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *); 42post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
43 43
44static inline unsigned long min_stack_size(unsigned long addr)
45{
46 unsigned long size;
47
48 if (on_irq_stack(addr, raw_smp_processor_id()))
49 size = IRQ_STACK_PTR(raw_smp_processor_id()) - addr;
50 else
51 size = (unsigned long)current_thread_info() + THREAD_START_SP - addr;
52
53 return min(size, FIELD_SIZEOF(struct kprobe_ctlblk, jprobes_stack));
54}
55
56static void __kprobes arch_prepare_ss_slot(struct kprobe *p) 44static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
57{ 45{
58 /* prepare insn slot */ 46 /* prepare insn slot */
@@ -489,20 +477,15 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
489{ 477{
490 struct jprobe *jp = container_of(p, struct jprobe, kp); 478 struct jprobe *jp = container_of(p, struct jprobe, kp);
491 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 479 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
492 long stack_ptr = kernel_stack_pointer(regs);
493 480
494 kcb->jprobe_saved_regs = *regs; 481 kcb->jprobe_saved_regs = *regs;
495 /* 482 /*
496 * As Linus pointed out, gcc assumes that the callee 483 * Since we can't be sure where in the stack frame "stacked"
497 * owns the argument space and could overwrite it, e.g. 484 * pass-by-value arguments are stored we just don't try to
498 * tailcall optimization. So, to be absolutely safe 485 * duplicate any of the stack. Do not use jprobes on functions that
499 * we also save and restore enough stack bytes to cover 486 * use more than 64 bytes (after padding each to an 8 byte boundary)
500 * the argument area. 487 * of arguments, or pass individual arguments larger than 16 bytes.
501 */ 488 */
502 kasan_disable_current();
503 memcpy(kcb->jprobes_stack, (void *)stack_ptr,
504 min_stack_size(stack_ptr));
505 kasan_enable_current();
506 489
507 instruction_pointer_set(regs, (unsigned long) jp->entry); 490 instruction_pointer_set(regs, (unsigned long) jp->entry);
508 preempt_disable(); 491 preempt_disable();
@@ -554,10 +537,6 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
554 } 537 }
555 unpause_graph_tracing(); 538 unpause_graph_tracing();
556 *regs = kcb->jprobe_saved_regs; 539 *regs = kcb->jprobe_saved_regs;
557 kasan_disable_current();
558 memcpy((void *)stack_addr, kcb->jprobes_stack,
559 min_stack_size(stack_addr));
560 kasan_enable_current();
561 preempt_enable_no_resched(); 540 preempt_enable_no_resched();
562 return 1; 541 return 1;
563} 542}
diff --git a/arch/arm64/kernel/sleep.S b/arch/arm64/kernel/sleep.S
index 9a3aec97ac09..ccf79d849e0a 100644
--- a/arch/arm64/kernel/sleep.S
+++ b/arch/arm64/kernel/sleep.S
@@ -101,12 +101,20 @@ ENTRY(cpu_resume)
101 bl el2_setup // if in EL2 drop to EL1 cleanly 101 bl el2_setup // if in EL2 drop to EL1 cleanly
102 /* enable the MMU early - so we can access sleep_save_stash by va */ 102 /* enable the MMU early - so we can access sleep_save_stash by va */
103 adr_l lr, __enable_mmu /* __cpu_setup will return here */ 103 adr_l lr, __enable_mmu /* __cpu_setup will return here */
104 ldr x27, =_cpu_resume /* __enable_mmu will branch here */ 104 adr_l x27, _resume_switched /* __enable_mmu will branch here */
105 adrp x25, idmap_pg_dir 105 adrp x25, idmap_pg_dir
106 adrp x26, swapper_pg_dir 106 adrp x26, swapper_pg_dir
107 b __cpu_setup 107 b __cpu_setup
108ENDPROC(cpu_resume) 108ENDPROC(cpu_resume)
109 109
110 .pushsection ".idmap.text", "ax"
111_resume_switched:
112 ldr x8, =_cpu_resume
113 br x8
114ENDPROC(_resume_switched)
115 .ltorg
116 .popsection
117
110ENTRY(_cpu_resume) 118ENTRY(_cpu_resume)
111 mrs x1, mpidr_el1 119 mrs x1, mpidr_el1
112 adrp x8, mpidr_hash 120 adrp x8, mpidr_hash
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 76a6d9263908..d93d43352504 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
661 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, 661 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
662 acpi_parse_gic_cpu_interface, 0); 662 acpi_parse_gic_cpu_interface, 0);
663 663
664 if (cpu_count > NR_CPUS) 664 if (cpu_count > nr_cpu_ids)
665 pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n", 665 pr_warn("Number of cores (%d) exceeds configured maximum of %d - clipping\n",
666 cpu_count, NR_CPUS); 666 cpu_count, nr_cpu_ids);
667 667
668 if (!bootcpu_valid) { 668 if (!bootcpu_valid) {
669 pr_err("missing boot CPU MPIDR, not enabling secondaries\n"); 669 pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
@@ -677,7 +677,7 @@ void __init smp_init_cpus(void)
677 * with entries in cpu_logical_map while initializing the cpus. 677 * with entries in cpu_logical_map while initializing the cpus.
678 * If the cpu set-up fails, invalidate the cpu_logical_map entry. 678 * If the cpu set-up fails, invalidate the cpu_logical_map entry.
679 */ 679 */
680 for (i = 1; i < NR_CPUS; i++) { 680 for (i = 1; i < nr_cpu_ids; i++) {
681 if (cpu_logical_map(i) != INVALID_HWID) { 681 if (cpu_logical_map(i) != INVALID_HWID) {
682 if (smp_cpu_setup(i)) 682 if (smp_cpu_setup(i))
683 cpu_logical_map(i) = INVALID_HWID; 683 cpu_logical_map(i) = INVALID_HWID;
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index ae7855f16ec2..5a84b4562603 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -256,7 +256,7 @@ static int __hyp_text __guest_run(struct kvm_vcpu *vcpu)
256 256
257 /* 257 /*
258 * We must restore the 32-bit state before the sysregs, thanks 258 * We must restore the 32-bit state before the sysregs, thanks
259 * to Cortex-A57 erratum #852523. 259 * to erratum #852523 (Cortex-A57) or #853709 (Cortex-A72).
260 */ 260 */
261 __sysreg32_restore_state(vcpu); 261 __sysreg32_restore_state(vcpu);
262 __sysreg_restore_guest_state(guest_ctxt); 262 __sysreg_restore_guest_state(guest_ctxt);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index b0b225ceca18..e51367d159d0 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -823,14 +823,6 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
823 * Architected system registers. 823 * Architected system registers.
824 * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 824 * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2
825 * 825 *
826 * We could trap ID_DFR0 and tell the guest we don't support performance
827 * monitoring. Unfortunately the patch to make the kernel check ID_DFR0 was
828 * NAKed, so it will read the PMCR anyway.
829 *
830 * Therefore we tell the guest we have 0 counters. Unfortunately, we
831 * must always support PMCCNTR (the cycle counter): we just RAZ/WI for
832 * all PM registers, which doesn't crash the guest kernel at least.
833 *
834 * Debug handling: We do trap most, if not all debug related system 826 * Debug handling: We do trap most, if not all debug related system
835 * registers. The implementation is good enough to ensure that a guest 827 * registers. The implementation is good enough to ensure that a guest
836 * can use these with minimal performance degradation. The drawback is 828 * can use these with minimal performance degradation. The drawback is
@@ -1360,7 +1352,7 @@ static const struct sys_reg_desc cp15_regs[] = {
1360 { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 }, 1352 { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 },
1361 1353
1362 /* ICC_SRE */ 1354 /* ICC_SRE */
1363 { Op1( 0), CRn(12), CRm(12), Op2( 5), trap_raz_wi }, 1355 { Op1( 0), CRn(12), CRm(12), Op2( 5), access_gic_sre },
1364 1356
1365 { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID }, 1357 { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID },
1366 1358
diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c
index f94b80eb295d..9c3e75df2180 100644
--- a/arch/arm64/mm/dump.c
+++ b/arch/arm64/mm/dump.c
@@ -242,7 +242,7 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level,
242 242
243static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start) 243static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start)
244{ 244{
245 pte_t *pte = pte_offset_kernel(pmd, 0); 245 pte_t *pte = pte_offset_kernel(pmd, 0UL);
246 unsigned long addr; 246 unsigned long addr;
247 unsigned i; 247 unsigned i;
248 248
@@ -254,7 +254,7 @@ static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start)
254 254
255static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start) 255static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)
256{ 256{
257 pmd_t *pmd = pmd_offset(pud, 0); 257 pmd_t *pmd = pmd_offset(pud, 0UL);
258 unsigned long addr; 258 unsigned long addr;
259 unsigned i; 259 unsigned i;
260 260
@@ -271,7 +271,7 @@ static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)
271 271
272static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start) 272static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start)
273{ 273{
274 pud_t *pud = pud_offset(pgd, 0); 274 pud_t *pud = pud_offset(pgd, 0UL);
275 unsigned long addr; 275 unsigned long addr;
276 unsigned i; 276 unsigned i;
277 277
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index c8beaa0da7df..05d2bd776c69 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -153,6 +153,11 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
153} 153}
154#endif 154#endif
155 155
156static bool is_el1_instruction_abort(unsigned int esr)
157{
158 return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_CUR;
159}
160
156/* 161/*
157 * The kernel tried to access some page that wasn't present. 162 * The kernel tried to access some page that wasn't present.
158 */ 163 */
@@ -161,8 +166,9 @@ static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr,
161{ 166{
162 /* 167 /*
163 * Are we prepared to handle this kernel fault? 168 * Are we prepared to handle this kernel fault?
169 * We are almost certainly not prepared to handle instruction faults.
164 */ 170 */
165 if (fixup_exception(regs)) 171 if (!is_el1_instruction_abort(esr) && fixup_exception(regs))
166 return; 172 return;
167 173
168 /* 174 /*
@@ -267,7 +273,8 @@ static inline bool is_permission_fault(unsigned int esr)
267 unsigned int ec = ESR_ELx_EC(esr); 273 unsigned int ec = ESR_ELx_EC(esr);
268 unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE; 274 unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE;
269 275
270 return (ec == ESR_ELx_EC_DABT_CUR && fsc_type == ESR_ELx_FSC_PERM); 276 return (ec == ESR_ELx_EC_DABT_CUR && fsc_type == ESR_ELx_FSC_PERM) ||
277 (ec == ESR_ELx_EC_IABT_CUR && fsc_type == ESR_ELx_FSC_PERM);
271} 278}
272 279
273static bool is_el0_instruction_abort(unsigned int esr) 280static bool is_el0_instruction_abort(unsigned int esr)
@@ -312,6 +319,9 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
312 if (regs->orig_addr_limit == KERNEL_DS) 319 if (regs->orig_addr_limit == KERNEL_DS)
313 die("Accessing user space memory with fs=KERNEL_DS", regs, esr); 320 die("Accessing user space memory with fs=KERNEL_DS", regs, esr);
314 321
322 if (is_el1_instruction_abort(esr))
323 die("Attempting to execute userspace memory", regs, esr);
324
315 if (!search_exception_tables(regs->pc)) 325 if (!search_exception_tables(regs->pc))
316 die("Accessing user space memory outside uaccess.h routines", regs, esr); 326 die("Accessing user space memory outside uaccess.h routines", regs, esr);
317 } 327 }
diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c
index c7fe3ec70774..5bb15eab6f00 100644
--- a/arch/arm64/mm/numa.c
+++ b/arch/arm64/mm/numa.c
@@ -23,6 +23,8 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/of.h> 24#include <linux/of.h>
25 25
26#include <asm/acpi.h>
27
26struct pglist_data *node_data[MAX_NUMNODES] __read_mostly; 28struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
27EXPORT_SYMBOL(node_data); 29EXPORT_SYMBOL(node_data);
28nodemask_t numa_nodes_parsed __initdata; 30nodemask_t numa_nodes_parsed __initdata;
diff --git a/arch/h8300/include/asm/io.h b/arch/h8300/include/asm/io.h
index 2e221c5f0203..f86918aed9e1 100644
--- a/arch/h8300/include/asm/io.h
+++ b/arch/h8300/include/asm/io.h
@@ -3,6 +3,8 @@
3 3
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#include <linux/types.h>
7
6/* H8/300 internal I/O functions */ 8/* H8/300 internal I/O functions */
7 9
8#define __raw_readb __raw_readb 10#define __raw_readb __raw_readb
diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
index 2dcee3a88867..9202f82dfce6 100644
--- a/arch/m68k/kernel/signal.c
+++ b/arch/m68k/kernel/signal.c
@@ -213,7 +213,6 @@ static inline int frame_extra_sizes(int f)
213 213
214static inline void adjustformat(struct pt_regs *regs) 214static inline void adjustformat(struct pt_regs *regs)
215{ 215{
216 ((struct switch_stack *)regs - 1)->a5 = current->mm->start_data;
217 /* 216 /*
218 * set format byte to make stack appear modulo 4, which it will 217 * set format byte to make stack appear modulo 4, which it will
219 * be when doing the rte 218 * be when doing the rte
diff --git a/arch/metag/mm/init.c b/arch/metag/mm/init.c
index 11fa51c89617..c0ec116b3993 100644
--- a/arch/metag/mm/init.c
+++ b/arch/metag/mm/init.c
@@ -390,7 +390,6 @@ void __init mem_init(void)
390 390
391 free_all_bootmem(); 391 free_all_bootmem();
392 mem_init_print_info(NULL); 392 mem_init_print_info(NULL);
393 show_mem(0);
394} 393}
395 394
396void free_initmem(void) 395void free_initmem(void)
diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
index ea0cd9773914..5f987598054f 100644
--- a/arch/mips/include/asm/page.h
+++ b/arch/mips/include/asm/page.h
@@ -164,7 +164,7 @@ typedef struct { unsigned long pgprot; } pgprot_t;
164 */ 164 */
165static inline unsigned long ___pa(unsigned long x) 165static inline unsigned long ___pa(unsigned long x)
166{ 166{
167 if (config_enabled(CONFIG_64BIT)) { 167 if (IS_ENABLED(CONFIG_64BIT)) {
168 /* 168 /*
169 * For MIPS64 the virtual address may either be in one of 169 * For MIPS64 the virtual address may either be in one of
170 * the compatibility segements ckseg0 or ckseg1, or it may 170 * the compatibility segements ckseg0 or ckseg1, or it may
@@ -173,7 +173,7 @@ static inline unsigned long ___pa(unsigned long x)
173 return x < CKSEG0 ? XPHYSADDR(x) : CPHYSADDR(x); 173 return x < CKSEG0 ? XPHYSADDR(x) : CPHYSADDR(x);
174 } 174 }
175 175
176 if (!config_enabled(CONFIG_EVA)) { 176 if (!IS_ENABLED(CONFIG_EVA)) {
177 /* 177 /*
178 * We're using the standard MIPS32 legacy memory map, ie. 178 * We're using the standard MIPS32 legacy memory map, ie.
179 * the address x is going to be in kseg0 or kseg1. We can 179 * the address x is going to be in kseg0 or kseg1. We can
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 6eb52b9c9818..e788515f766b 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1642,8 +1642,14 @@ enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
1642 1642
1643 preempt_disable(); 1643 preempt_disable();
1644 if (KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG0) { 1644 if (KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG0) {
1645 if (kvm_mips_host_tlb_lookup(vcpu, va) < 0) 1645 if (kvm_mips_host_tlb_lookup(vcpu, va) < 0 &&
1646 kvm_mips_handle_kseg0_tlb_fault(va, vcpu); 1646 kvm_mips_handle_kseg0_tlb_fault(va, vcpu)) {
1647 kvm_err("%s: handling mapped kseg0 tlb fault for %lx, vcpu: %p, ASID: %#lx\n",
1648 __func__, va, vcpu, read_c0_entryhi());
1649 er = EMULATE_FAIL;
1650 preempt_enable();
1651 goto done;
1652 }
1647 } else if ((KVM_GUEST_KSEGX(va) < KVM_GUEST_KSEG0) || 1653 } else if ((KVM_GUEST_KSEGX(va) < KVM_GUEST_KSEG0) ||
1648 KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG23) { 1654 KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG23) {
1649 int index; 1655 int index;
@@ -1680,12 +1686,18 @@ enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
1680 run, vcpu); 1686 run, vcpu);
1681 preempt_enable(); 1687 preempt_enable();
1682 goto dont_update_pc; 1688 goto dont_update_pc;
1683 } else { 1689 }
1684 /* 1690 /*
1685 * We fault an entry from the guest tlb to the 1691 * We fault an entry from the guest tlb to the
1686 * shadow host TLB 1692 * shadow host TLB
1687 */ 1693 */
1688 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb); 1694 if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb)) {
1695 kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
1696 __func__, va, index, vcpu,
1697 read_c0_entryhi());
1698 er = EMULATE_FAIL;
1699 preempt_enable();
1700 goto done;
1689 } 1701 }
1690 } 1702 }
1691 } else { 1703 } else {
@@ -2659,7 +2671,12 @@ enum emulation_result kvm_mips_handle_tlbmiss(u32 cause,
2659 * OK we have a Guest TLB entry, now inject it into the 2671 * OK we have a Guest TLB entry, now inject it into the
2660 * shadow host TLB 2672 * shadow host TLB
2661 */ 2673 */
2662 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb); 2674 if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb)) {
2675 kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
2676 __func__, va, index, vcpu,
2677 read_c0_entryhi());
2678 er = EMULATE_FAIL;
2679 }
2663 } 2680 }
2664 } 2681 }
2665 2682
diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c
index 57319ee57c4f..121008c0fcc9 100644
--- a/arch/mips/kvm/mmu.c
+++ b/arch/mips/kvm/mmu.c
@@ -40,7 +40,7 @@ static int kvm_mips_map_page(struct kvm *kvm, gfn_t gfn)
40 srcu_idx = srcu_read_lock(&kvm->srcu); 40 srcu_idx = srcu_read_lock(&kvm->srcu);
41 pfn = gfn_to_pfn(kvm, gfn); 41 pfn = gfn_to_pfn(kvm, gfn);
42 42
43 if (is_error_pfn(pfn)) { 43 if (is_error_noslot_pfn(pfn)) {
44 kvm_err("Couldn't get pfn for gfn %#llx!\n", gfn); 44 kvm_err("Couldn't get pfn for gfn %#llx!\n", gfn);
45 err = -EFAULT; 45 err = -EFAULT;
46 goto out; 46 goto out;
@@ -99,7 +99,7 @@ int kvm_mips_handle_kseg0_tlb_fault(unsigned long badvaddr,
99 } 99 }
100 100
101 gfn = (KVM_GUEST_CPHYSADDR(badvaddr) >> PAGE_SHIFT); 101 gfn = (KVM_GUEST_CPHYSADDR(badvaddr) >> PAGE_SHIFT);
102 if (gfn >= kvm->arch.guest_pmap_npages) { 102 if ((gfn | 1) >= kvm->arch.guest_pmap_npages) {
103 kvm_err("%s: Invalid gfn: %#llx, BadVaddr: %#lx\n", __func__, 103 kvm_err("%s: Invalid gfn: %#llx, BadVaddr: %#lx\n", __func__,
104 gfn, badvaddr); 104 gfn, badvaddr);
105 kvm_mips_dump_host_tlbs(); 105 kvm_mips_dump_host_tlbs();
@@ -138,35 +138,49 @@ int kvm_mips_handle_mapped_seg_tlb_fault(struct kvm_vcpu *vcpu,
138 unsigned long entryhi = 0, entrylo0 = 0, entrylo1 = 0; 138 unsigned long entryhi = 0, entrylo0 = 0, entrylo1 = 0;
139 struct kvm *kvm = vcpu->kvm; 139 struct kvm *kvm = vcpu->kvm;
140 kvm_pfn_t pfn0, pfn1; 140 kvm_pfn_t pfn0, pfn1;
141 gfn_t gfn0, gfn1;
142 long tlb_lo[2];
141 int ret; 143 int ret;
142 144
143 if ((tlb->tlb_hi & VPN2_MASK) == 0) { 145 tlb_lo[0] = tlb->tlb_lo[0];
144 pfn0 = 0; 146 tlb_lo[1] = tlb->tlb_lo[1];
145 pfn1 = 0; 147
146 } else { 148 /*
147 if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo[0]) 149 * The commpage address must not be mapped to anything else if the guest
148 >> PAGE_SHIFT) < 0) 150 * TLB contains entries nearby, or commpage accesses will break.
149 return -1; 151 */
150 152 if (!((tlb->tlb_hi ^ KVM_GUEST_COMMPAGE_ADDR) &
151 if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo[1]) 153 VPN2_MASK & (PAGE_MASK << 1)))
152 >> PAGE_SHIFT) < 0) 154 tlb_lo[(KVM_GUEST_COMMPAGE_ADDR >> PAGE_SHIFT) & 1] = 0;
153 return -1; 155
154 156 gfn0 = mips3_tlbpfn_to_paddr(tlb_lo[0]) >> PAGE_SHIFT;
155 pfn0 = kvm->arch.guest_pmap[ 157 gfn1 = mips3_tlbpfn_to_paddr(tlb_lo[1]) >> PAGE_SHIFT;
156 mips3_tlbpfn_to_paddr(tlb->tlb_lo[0]) >> PAGE_SHIFT]; 158 if (gfn0 >= kvm->arch.guest_pmap_npages ||
157 pfn1 = kvm->arch.guest_pmap[ 159 gfn1 >= kvm->arch.guest_pmap_npages) {
158 mips3_tlbpfn_to_paddr(tlb->tlb_lo[1]) >> PAGE_SHIFT]; 160 kvm_err("%s: Invalid gfn: [%#llx, %#llx], EHi: %#lx\n",
161 __func__, gfn0, gfn1, tlb->tlb_hi);
162 kvm_mips_dump_guest_tlbs(vcpu);
163 return -1;
159 } 164 }
160 165
166 if (kvm_mips_map_page(kvm, gfn0) < 0)
167 return -1;
168
169 if (kvm_mips_map_page(kvm, gfn1) < 0)
170 return -1;
171
172 pfn0 = kvm->arch.guest_pmap[gfn0];
173 pfn1 = kvm->arch.guest_pmap[gfn1];
174
161 /* Get attributes from the Guest TLB */ 175 /* Get attributes from the Guest TLB */
162 entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) | 176 entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) |
163 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) | 177 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) |
164 (tlb->tlb_lo[0] & ENTRYLO_D) | 178 (tlb_lo[0] & ENTRYLO_D) |
165 (tlb->tlb_lo[0] & ENTRYLO_V); 179 (tlb_lo[0] & ENTRYLO_V);
166 entrylo1 = mips3_paddr_to_tlbpfn(pfn1 << PAGE_SHIFT) | 180 entrylo1 = mips3_paddr_to_tlbpfn(pfn1 << PAGE_SHIFT) |
167 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) | 181 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) |
168 (tlb->tlb_lo[1] & ENTRYLO_D) | 182 (tlb_lo[1] & ENTRYLO_D) |
169 (tlb->tlb_lo[1] & ENTRYLO_V); 183 (tlb_lo[1] & ENTRYLO_V);
170 184
171 kvm_debug("@ %#lx tlb_lo0: 0x%08lx tlb_lo1: 0x%08lx\n", vcpu->arch.pc, 185 kvm_debug("@ %#lx tlb_lo0: 0x%08lx tlb_lo1: 0x%08lx\n", vcpu->arch.pc,
172 tlb->tlb_lo[0], tlb->tlb_lo[1]); 186 tlb->tlb_lo[0], tlb->tlb_lo[1]);
@@ -354,9 +368,15 @@ u32 kvm_get_inst(u32 *opc, struct kvm_vcpu *vcpu)
354 local_irq_restore(flags); 368 local_irq_restore(flags);
355 return KVM_INVALID_INST; 369 return KVM_INVALID_INST;
356 } 370 }
357 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, 371 if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu,
358 &vcpu->arch. 372 &vcpu->arch.guest_tlb[index])) {
359 guest_tlb[index]); 373 kvm_err("%s: handling mapped seg tlb fault failed for %p, index: %u, vcpu: %p, ASID: %#lx\n",
374 __func__, opc, index, vcpu,
375 read_c0_entryhi());
376 kvm_mips_dump_guest_tlbs(vcpu);
377 local_irq_restore(flags);
378 return KVM_INVALID_INST;
379 }
360 inst = *(opc); 380 inst = *(opc);
361 } 381 }
362 local_irq_restore(flags); 382 local_irq_restore(flags);
diff --git a/arch/parisc/include/uapi/asm/errno.h b/arch/parisc/include/uapi/asm/errno.h
index c0ae62520d15..274d5bc6ecce 100644
--- a/arch/parisc/include/uapi/asm/errno.h
+++ b/arch/parisc/include/uapi/asm/errno.h
@@ -97,10 +97,10 @@
97#define ENOTCONN 235 /* Transport endpoint is not connected */ 97#define ENOTCONN 235 /* Transport endpoint is not connected */
98#define ESHUTDOWN 236 /* Cannot send after transport endpoint shutdown */ 98#define ESHUTDOWN 236 /* Cannot send after transport endpoint shutdown */
99#define ETOOMANYREFS 237 /* Too many references: cannot splice */ 99#define ETOOMANYREFS 237 /* Too many references: cannot splice */
100#define EREFUSED ECONNREFUSED /* for HP's NFS apparently */
101#define ETIMEDOUT 238 /* Connection timed out */ 100#define ETIMEDOUT 238 /* Connection timed out */
102#define ECONNREFUSED 239 /* Connection refused */ 101#define ECONNREFUSED 239 /* Connection refused */
103#define EREMOTERELEASE 240 /* Remote peer released connection */ 102#define EREFUSED ECONNREFUSED /* for HP's NFS apparently */
103#define EREMOTERELEASE 240 /* Remote peer released connection */
104#define EHOSTDOWN 241 /* Host is down */ 104#define EHOSTDOWN 241 /* Host is down */
105#define EHOSTUNREACH 242 /* No route to host */ 105#define EHOSTUNREACH 242 /* No route to host */
106 106
diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c
index 5adc339eb7c8..0c2a94a0f751 100644
--- a/arch/parisc/kernel/processor.c
+++ b/arch/parisc/kernel/processor.c
@@ -51,8 +51,6 @@ EXPORT_SYMBOL(_parisc_requires_coherency);
51 51
52DEFINE_PER_CPU(struct cpuinfo_parisc, cpu_data); 52DEFINE_PER_CPU(struct cpuinfo_parisc, cpu_data);
53 53
54extern int update_cr16_clocksource(void); /* from time.c */
55
56/* 54/*
57** PARISC CPU driver - claim "device" and initialize CPU data structures. 55** PARISC CPU driver - claim "device" and initialize CPU data structures.
58** 56**
@@ -228,12 +226,6 @@ static int processor_probe(struct parisc_device *dev)
228 } 226 }
229#endif 227#endif
230 228
231 /* If we've registered more than one cpu,
232 * we'll use the jiffies clocksource since cr16
233 * is not synchronized between CPUs.
234 */
235 update_cr16_clocksource();
236
237 return 0; 229 return 0;
238} 230}
239 231
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
index 505cf1ac5af2..4b0b963d52a7 100644
--- a/arch/parisc/kernel/time.c
+++ b/arch/parisc/kernel/time.c
@@ -221,18 +221,6 @@ static struct clocksource clocksource_cr16 = {
221 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 221 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
222}; 222};
223 223
224int update_cr16_clocksource(void)
225{
226 /* since the cr16 cycle counters are not synchronized across CPUs,
227 we'll check if we should switch to a safe clocksource: */
228 if (clocksource_cr16.rating != 0 && num_online_cpus() > 1) {
229 clocksource_change_rating(&clocksource_cr16, 0);
230 return 1;
231 }
232
233 return 0;
234}
235
236void __init start_cpu_itimer(void) 224void __init start_cpu_itimer(void)
237{ 225{
238 unsigned int cpu = smp_processor_id(); 226 unsigned int cpu = smp_processor_id();
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index ca254546cd05..1934707bf321 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -66,29 +66,28 @@ endif
66UTS_MACHINE := $(OLDARCH) 66UTS_MACHINE := $(OLDARCH)
67 67
68ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) 68ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
69override CC += -mlittle-endian
70ifneq ($(cc-name),clang)
71override CC += -mno-strict-align
72endif
73override AS += -mlittle-endian
74override LD += -EL 69override LD += -EL
75override CROSS32CC += -mlittle-endian
76override CROSS32AS += -mlittle-endian 70override CROSS32AS += -mlittle-endian
77LDEMULATION := lppc 71LDEMULATION := lppc
78GNUTARGET := powerpcle 72GNUTARGET := powerpcle
79MULTIPLEWORD := -mno-multiple 73MULTIPLEWORD := -mno-multiple
80KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect) 74KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
81else 75else
82ifeq ($(call cc-option-yn,-mbig-endian),y)
83override CC += -mbig-endian
84override AS += -mbig-endian
85endif
86override LD += -EB 76override LD += -EB
87LDEMULATION := ppc 77LDEMULATION := ppc
88GNUTARGET := powerpc 78GNUTARGET := powerpc
89MULTIPLEWORD := -mmultiple 79MULTIPLEWORD := -mmultiple
90endif 80endif
91 81
82cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
83cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
84ifneq ($(cc-name),clang)
85 cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mno-strict-align
86endif
87
88aflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
89aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
90
92ifeq ($(HAS_BIARCH),y) 91ifeq ($(HAS_BIARCH),y)
93override AS += -a$(CONFIG_WORD_SIZE) 92override AS += -a$(CONFIG_WORD_SIZE)
94override LD += -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION) 93override LD += -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION)
@@ -232,6 +231,9 @@ cpu-as-$(CONFIG_E200) += -Wa,-me200
232KBUILD_AFLAGS += $(cpu-as-y) 231KBUILD_AFLAGS += $(cpu-as-y)
233KBUILD_CFLAGS += $(cpu-as-y) 232KBUILD_CFLAGS += $(cpu-as-y)
234 233
234KBUILD_AFLAGS += $(aflags-y)
235KBUILD_CFLAGS += $(cflags-y)
236
235head-y := arch/powerpc/kernel/head_$(CONFIG_WORD_SIZE).o 237head-y := arch/powerpc/kernel/head_$(CONFIG_WORD_SIZE).o
236head-$(CONFIG_8xx) := arch/powerpc/kernel/head_8xx.o 238head-$(CONFIG_8xx) := arch/powerpc/kernel/head_8xx.o
237head-$(CONFIG_40x) := arch/powerpc/kernel/head_40x.o 239head-$(CONFIG_40x) := arch/powerpc/kernel/head_40x.o
diff --git a/arch/powerpc/crypto/crc32c-vpmsum_glue.c b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
index bfe3d37a24ef..9fa046d56eba 100644
--- a/arch/powerpc/crypto/crc32c-vpmsum_glue.c
+++ b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
@@ -4,6 +4,7 @@
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/string.h> 5#include <linux/string.h>
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/cpufeature.h>
7#include <asm/switch_to.h> 8#include <asm/switch_to.h>
8 9
9#define CHKSUM_BLOCK_SIZE 1 10#define CHKSUM_BLOCK_SIZE 1
@@ -157,7 +158,7 @@ static void __exit crc32c_vpmsum_mod_fini(void)
157 crypto_unregister_shash(&alg); 158 crypto_unregister_shash(&alg);
158} 159}
159 160
160module_init(crc32c_vpmsum_mod_init); 161module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, crc32c_vpmsum_mod_init);
161module_exit(crc32c_vpmsum_mod_fini); 162module_exit(crc32c_vpmsum_mod_fini);
162 163
163MODULE_AUTHOR("Anton Blanchard <anton@samba.org>"); 164MODULE_AUTHOR("Anton Blanchard <anton@samba.org>");
diff --git a/arch/powerpc/include/asm/cpuidle.h b/arch/powerpc/include/asm/cpuidle.h
index 3d7fc06532a1..01b8a13f0224 100644
--- a/arch/powerpc/include/asm/cpuidle.h
+++ b/arch/powerpc/include/asm/cpuidle.h
@@ -19,4 +19,17 @@ extern u64 pnv_first_deep_stop_state;
19 19
20#endif 20#endif
21 21
22/* Idle state entry routines */
23#ifdef CONFIG_PPC_P7_NAP
24#define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
25 /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
26 std r0,0(r1); \
27 ptesync; \
28 ld r0,0(r1); \
291: cmp cr0,r0,r0; \
30 bne 1b; \
31 IDLE_INST; \
32 b .
33#endif /* CONFIG_PPC_P7_NAP */
34
22#endif 35#endif
diff --git a/arch/powerpc/include/asm/feature-fixups.h b/arch/powerpc/include/asm/feature-fixups.h
index 57fec8ac7b92..ddf54f5bbdd1 100644
--- a/arch/powerpc/include/asm/feature-fixups.h
+++ b/arch/powerpc/include/asm/feature-fixups.h
@@ -186,6 +186,7 @@ label##3: \
186 186
187#ifndef __ASSEMBLY__ 187#ifndef __ASSEMBLY__
188void apply_feature_fixups(void); 188void apply_feature_fixups(void);
189void setup_feature_keys(void);
189#endif 190#endif
190 191
191#endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */ 192#endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */
diff --git a/arch/powerpc/include/asm/switch_to.h b/arch/powerpc/include/asm/switch_to.h
index 0a74ebe934e1..17c8380673a6 100644
--- a/arch/powerpc/include/asm/switch_to.h
+++ b/arch/powerpc/include/asm/switch_to.h
@@ -75,14 +75,6 @@ static inline void disable_kernel_spe(void)
75static inline void __giveup_spe(struct task_struct *t) { } 75static inline void __giveup_spe(struct task_struct *t) { }
76#endif 76#endif
77 77
78#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
79extern void flush_tmregs_to_thread(struct task_struct *);
80#else
81static inline void flush_tmregs_to_thread(struct task_struct *t)
82{
83}
84#endif
85
86static inline void clear_task_ebb(struct task_struct *t) 78static inline void clear_task_ebb(struct task_struct *t)
87{ 79{
88#ifdef CONFIG_PPC_BOOK3S_64 80#ifdef CONFIG_PPC_BOOK3S_64
diff --git a/arch/powerpc/include/asm/xics.h b/arch/powerpc/include/asm/xics.h
index f5f729c11578..f0b238516e9b 100644
--- a/arch/powerpc/include/asm/xics.h
+++ b/arch/powerpc/include/asm/xics.h
@@ -159,6 +159,8 @@ extern void xics_teardown_cpu(void);
159extern void xics_kexec_teardown_cpu(int secondary); 159extern void xics_kexec_teardown_cpu(int secondary);
160extern void xics_migrate_irqs_away(void); 160extern void xics_migrate_irqs_away(void);
161extern void icp_native_eoi(struct irq_data *d); 161extern void icp_native_eoi(struct irq_data *d);
162extern int xics_set_irq_type(struct irq_data *d, unsigned int flow_type);
163extern int xics_retrigger(struct irq_data *data);
162#ifdef CONFIG_SMP 164#ifdef CONFIG_SMP
163extern int xics_get_irq_server(unsigned int virq, const struct cpumask *cpumask, 165extern int xics_get_irq_server(unsigned int virq, const struct cpumask *cpumask,
164 unsigned int strict_check); 166 unsigned int strict_check);
diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
index c9bc78e9c610..7429556eb8df 100644
--- a/arch/powerpc/kernel/eeh.c
+++ b/arch/powerpc/kernel/eeh.c
@@ -168,10 +168,10 @@ static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
168 int n = 0, l = 0; 168 int n = 0, l = 0;
169 char buffer[128]; 169 char buffer[128];
170 170
171 n += scnprintf(buf+n, len-n, "%04x:%02x:%02x:%01x\n", 171 n += scnprintf(buf+n, len-n, "%04x:%02x:%02x.%01x\n",
172 edev->phb->global_number, pdn->busno, 172 edev->phb->global_number, pdn->busno,
173 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn)); 173 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
174 pr_warn("EEH: of node=%04x:%02x:%02x:%01x\n", 174 pr_warn("EEH: of node=%04x:%02x:%02x.%01x\n",
175 edev->phb->global_number, pdn->busno, 175 edev->phb->global_number, pdn->busno,
176 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn)); 176 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
177 177
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 41091fdf9bd8..df6d45eb4115 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -144,29 +144,14 @@ machine_check_pSeries_1:
144 * vector 144 * vector
145 */ 145 */
146 SET_SCRATCH0(r13) /* save r13 */ 146 SET_SCRATCH0(r13) /* save r13 */
147#ifdef CONFIG_PPC_P7_NAP 147 /*
148BEGIN_FTR_SECTION 148 * Running native on arch 2.06 or later, we may wakeup from winkle
149 /* Running native on arch 2.06 or later, check if we are 149 * inside machine check. If yes, then last bit of HSPGR0 would be set
150 * waking up from nap. We only handle no state loss and 150 * to 1. Hence clear it unconditionally.
151 * supervisor state loss. We do -not- handle hypervisor
152 * state loss at this time.
153 */ 151 */
154 mfspr r13,SPRN_SRR1 152 GET_PACA(r13)
155 rlwinm. r13,r13,47-31,30,31 153 clrrdi r13,r13,1
156 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) 154 SET_PACA(r13)
157 beq 9f
158
159 mfspr r13,SPRN_SRR1
160 rlwinm. r13,r13,47-31,30,31
161 /* waking up from powersave (nap) state */
162 cmpwi cr1,r13,2
163 /* Total loss of HV state is fatal. let's just stay stuck here */
164 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
165 bgt cr1,.
1669:
167 OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
168END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
169#endif /* CONFIG_PPC_P7_NAP */
170 EXCEPTION_PROLOG_0(PACA_EXMC) 155 EXCEPTION_PROLOG_0(PACA_EXMC)
171BEGIN_FTR_SECTION 156BEGIN_FTR_SECTION
172 b machine_check_powernv_early 157 b machine_check_powernv_early
@@ -1273,25 +1258,51 @@ machine_check_handle_early:
1273 * Check if thread was in power saving mode. We come here when any 1258 * Check if thread was in power saving mode. We come here when any
1274 * of the following is true: 1259 * of the following is true:
1275 * a. thread wasn't in power saving mode 1260 * a. thread wasn't in power saving mode
1276 * b. thread was in power saving mode with no state loss or 1261 * b. thread was in power saving mode with no state loss,
1277 * supervisor state loss 1262 * supervisor state loss or hypervisor state loss.
1278 * 1263 *
1279 * Go back to nap again if (b) is true. 1264 * Go back to nap/sleep/winkle mode again if (b) is true.
1280 */ 1265 */
1281 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */ 1266 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
1282 beq 4f /* No, it wasn;t */ 1267 beq 4f /* No, it wasn;t */
1283 /* Thread was in power saving mode. Go back to nap again. */ 1268 /* Thread was in power saving mode. Go back to nap again. */
1284 cmpwi r11,2 1269 cmpwi r11,2
1285 bne 3f 1270 blt 3f
1286 /* Supervisor state loss */ 1271 /* Supervisor/Hypervisor state loss */
1287 li r0,1 1272 li r0,1
1288 stb r0,PACA_NAPSTATELOST(r13) 1273 stb r0,PACA_NAPSTATELOST(r13)
12893: bl machine_check_queue_event 12743: bl machine_check_queue_event
1290 MACHINE_CHECK_HANDLER_WINDUP 1275 MACHINE_CHECK_HANDLER_WINDUP
1291 GET_PACA(r13) 1276 GET_PACA(r13)
1292 ld r1,PACAR1(r13) 1277 ld r1,PACAR1(r13)
1293 li r3,PNV_THREAD_NAP 1278 /*
1294 b pnv_enter_arch207_idle_mode 1279 * Check what idle state this CPU was in and go back to same mode
1280 * again.
1281 */
1282 lbz r3,PACA_THREAD_IDLE_STATE(r13)
1283 cmpwi r3,PNV_THREAD_NAP
1284 bgt 10f
1285 IDLE_STATE_ENTER_SEQ(PPC_NAP)
1286 /* No return */
128710:
1288 cmpwi r3,PNV_THREAD_SLEEP
1289 bgt 2f
1290 IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
1291 /* No return */
1292
12932:
1294 /*
1295 * Go back to winkle. Please note that this thread was woken up in
1296 * machine check from winkle and have not restored the per-subcore
1297 * state. Hence before going back to winkle, set last bit of HSPGR0
1298 * to 1. This will make sure that if this thread gets woken up
1299 * again at reset vector 0x100 then it will get chance to restore
1300 * the subcore state.
1301 */
1302 ori r13,r13,1
1303 SET_PACA(r13)
1304 IDLE_STATE_ENTER_SEQ(PPC_WINKLE)
1305 /* No return */
12954: 13064:
1296#endif 1307#endif
1297 /* 1308 /*
diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
index ba79d15f4ddd..2265c6398a17 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -44,18 +44,6 @@
44 PSSCR_PSLL_MASK | PSSCR_TR_MASK | \ 44 PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
45 PSSCR_MTL_MASK 45 PSSCR_MTL_MASK
46 46
47/* Idle state entry routines */
48
49#define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
50 /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
51 std r0,0(r1); \
52 ptesync; \
53 ld r0,0(r1); \
541: cmp cr0,r0,r0; \
55 bne 1b; \
56 IDLE_INST; \
57 b .
58
59 .text 47 .text
60 48
61/* 49/*
@@ -363,8 +351,8 @@ _GLOBAL(power9_idle_stop)
363 * cr3 - set to gt if waking up with partial/complete hypervisor state loss 351 * cr3 - set to gt if waking up with partial/complete hypervisor state loss
364 */ 352 */
365_GLOBAL(pnv_restore_hyp_resource) 353_GLOBAL(pnv_restore_hyp_resource)
366 ld r2,PACATOC(r13);
367BEGIN_FTR_SECTION 354BEGIN_FTR_SECTION
355 ld r2,PACATOC(r13);
368 /* 356 /*
369 * POWER ISA 3. Use PSSCR to determine if we 357 * POWER ISA 3. Use PSSCR to determine if we
370 * are waking up from deep idle state 358 * are waking up from deep idle state
@@ -395,6 +383,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
395 */ 383 */
396 clrldi r5,r13,63 384 clrldi r5,r13,63
397 clrrdi r13,r13,1 385 clrrdi r13,r13,1
386
387 /* Now that we are sure r13 is corrected, load TOC */
388 ld r2,PACATOC(r13);
398 cmpwi cr4,r5,1 389 cmpwi cr4,r5,1
399 mtspr SPRN_HSPRG0,r13 390 mtspr SPRN_HSPRG0,r13
400 391
diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index ef267fd9dd22..5e7ece0fda9f 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -92,7 +92,8 @@ void save_mce_event(struct pt_regs *regs, long handled,
92 mce->in_use = 1; 92 mce->in_use = 1;
93 93
94 mce->initiator = MCE_INITIATOR_CPU; 94 mce->initiator = MCE_INITIATOR_CPU;
95 if (handled) 95 /* Mark it recovered if we have handled it and MSR(RI=1). */
96 if (handled && (regs->msr & MSR_RI))
96 mce->disposition = MCE_DISPOSITION_RECOVERED; 97 mce->disposition = MCE_DISPOSITION_RECOVERED;
97 else 98 else
98 mce->disposition = MCE_DISPOSITION_NOT_RECOVERED; 99 mce->disposition = MCE_DISPOSITION_NOT_RECOVERED;
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index a5c0153ede37..7fdf324d5b51 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -78,6 +78,7 @@ EXPORT_SYMBOL(get_pci_dma_ops);
78static int get_phb_number(struct device_node *dn) 78static int get_phb_number(struct device_node *dn)
79{ 79{
80 int ret, phb_id = -1; 80 int ret, phb_id = -1;
81 u32 prop_32;
81 u64 prop; 82 u64 prop;
82 83
83 /* 84 /*
@@ -86,8 +87,10 @@ static int get_phb_number(struct device_node *dn)
86 * reading "ibm,opal-phbid", only present in OPAL environment. 87 * reading "ibm,opal-phbid", only present in OPAL environment.
87 */ 88 */
88 ret = of_property_read_u64(dn, "ibm,opal-phbid", &prop); 89 ret = of_property_read_u64(dn, "ibm,opal-phbid", &prop);
89 if (ret) 90 if (ret) {
90 ret = of_property_read_u32_index(dn, "reg", 1, (u32 *)&prop); 91 ret = of_property_read_u32_index(dn, "reg", 1, &prop_32);
92 prop = prop_32;
93 }
91 94
92 if (!ret) 95 if (!ret)
93 phb_id = (int)(prop & (MAX_PHBS - 1)); 96 phb_id = (int)(prop & (MAX_PHBS - 1));
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 58ccf86415b4..9ee2623e0f67 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1074,26 +1074,6 @@ static inline void restore_sprs(struct thread_struct *old_thread,
1074#endif 1074#endif
1075} 1075}
1076 1076
1077#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1078void flush_tmregs_to_thread(struct task_struct *tsk)
1079{
1080 /*
1081 * Process self tracing is not yet supported through
1082 * ptrace interface. Ptrace generic code should have
1083 * prevented this from happening in the first place.
1084 * Warn once here with the message, if some how it
1085 * is attempted.
1086 */
1087 WARN_ONCE(tsk == current,
1088 "Not expecting ptrace on self: TM regs may be incorrect\n");
1089
1090 /*
1091 * If task is not current, it should have been flushed
1092 * already to it's thread_struct during __switch_to().
1093 */
1094}
1095#endif
1096
1097struct task_struct *__switch_to(struct task_struct *prev, 1077struct task_struct *__switch_to(struct task_struct *prev,
1098 struct task_struct *new) 1078 struct task_struct *new)
1099{ 1079{
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 6ee4b72cda42..4e74fc588a3f 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -2940,7 +2940,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
2940 2940
2941 /* Don't print anything after quiesce under OPAL, it crashes OFW */ 2941 /* Don't print anything after quiesce under OPAL, it crashes OFW */
2942 if (of_platform != PLATFORM_OPAL) { 2942 if (of_platform != PLATFORM_OPAL) {
2943 prom_printf("Booting Linux via __start() ...\n"); 2943 prom_printf("Booting Linux via __start() @ 0x%lx ...\n", kbase);
2944 prom_debug("->dt_header_start=0x%x\n", hdr); 2944 prom_debug("->dt_header_start=0x%x\n", hdr);
2945 } 2945 }
2946 2946
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 4f3c5756cc09..bf91658a8a40 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -38,6 +38,7 @@
38#include <asm/page.h> 38#include <asm/page.h>
39#include <asm/pgtable.h> 39#include <asm/pgtable.h>
40#include <asm/switch_to.h> 40#include <asm/switch_to.h>
41#include <asm/tm.h>
41 42
42#define CREATE_TRACE_POINTS 43#define CREATE_TRACE_POINTS
43#include <trace/events/syscalls.h> 44#include <trace/events/syscalls.h>
@@ -118,6 +119,24 @@ static const struct pt_regs_offset regoffset_table[] = {
118 REG_OFFSET_END, 119 REG_OFFSET_END,
119}; 120};
120 121
122#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
123static void flush_tmregs_to_thread(struct task_struct *tsk)
124{
125 /*
126 * If task is not current, it will have been flushed already to
127 * it's thread_struct during __switch_to().
128 *
129 * A reclaim flushes ALL the state.
130 */
131
132 if (tsk == current && MSR_TM_SUSPENDED(mfmsr()))
133 tm_reclaim_current(TM_CAUSE_SIGNAL);
134
135}
136#else
137static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
138#endif
139
121/** 140/**
122 * regs_query_register_offset() - query register offset from its name 141 * regs_query_register_offset() - query register offset from its name
123 * @name: the name of a register 142 * @name: the name of a register
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index c3e861df4b20..24ec3ea4b3a2 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -93,15 +93,16 @@ notrace unsigned long __init early_init(unsigned long dt_ptr)
93 * and we are running with enough of the MMU enabled to have our 93 * and we are running with enough of the MMU enabled to have our
94 * proper kernel virtual addresses 94 * proper kernel virtual addresses
95 * 95 *
96 * Find out what kind of machine we're on and save any data we need 96 * We do the initial parsing of the flat device-tree and prepares
97 * from the early boot process (devtree is copied on pmac by prom_init()). 97 * for the MMU to be fully initialized.
98 * This is called very early on the boot process, after a minimal
99 * MMU environment has been set up but before MMU_init is called.
100 */ 98 */
101extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */ 99extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */
102 100
103notrace void __init machine_init(u64 dt_ptr) 101notrace void __init machine_init(u64 dt_ptr)
104{ 102{
103 /* Configure static keys first, now that we're relocated. */
104 setup_feature_keys();
105
105 /* Enable early debugging if any specified (see udbg.h) */ 106 /* Enable early debugging if any specified (see udbg.h) */
106 udbg_early_init(); 107 udbg_early_init();
107 108
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index eafb9a79e011..7ac8e6eaab5b 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -300,6 +300,7 @@ void __init early_setup(unsigned long dt_ptr)
300 300
301 /* Apply all the dynamic patching */ 301 /* Apply all the dynamic patching */
302 apply_feature_fixups(); 302 apply_feature_fixups();
303 setup_feature_keys();
303 304
304 /* Initialize the hash table or TLB handling */ 305 /* Initialize the hash table or TLB handling */
305 early_init_mmu(); 306 early_init_mmu();
diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index 6767605ea8da..4111d30badfa 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -22,6 +22,7 @@
22#include <linux/security.h> 22#include <linux/security.h>
23#include <linux/memblock.h> 23#include <linux/memblock.h>
24 24
25#include <asm/cpu_has_feature.h>
25#include <asm/pgtable.h> 26#include <asm/pgtable.h>
26#include <asm/processor.h> 27#include <asm/processor.h>
27#include <asm/mmu.h> 28#include <asm/mmu.h>
diff --git a/arch/powerpc/kernel/vdso32/Makefile b/arch/powerpc/kernel/vdso32/Makefile
index cbabd143acae..78a7449bf489 100644
--- a/arch/powerpc/kernel/vdso32/Makefile
+++ b/arch/powerpc/kernel/vdso32/Makefile
@@ -30,7 +30,7 @@ CPPFLAGS_vdso32.lds += -P -C -Upowerpc
30$(obj)/vdso32_wrapper.o : $(obj)/vdso32.so 30$(obj)/vdso32_wrapper.o : $(obj)/vdso32.so
31 31
32# link rule for the .so file, .lds has to be first 32# link rule for the .so file, .lds has to be first
33$(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) 33$(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) FORCE
34 $(call if_changed,vdso32ld) 34 $(call if_changed,vdso32ld)
35 35
36# strip rule for the .so file 36# strip rule for the .so file
@@ -39,12 +39,12 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE
39 $(call if_changed,objcopy) 39 $(call if_changed,objcopy)
40 40
41# assembly rules for the .S files 41# assembly rules for the .S files
42$(obj-vdso32): %.o: %.S 42$(obj-vdso32): %.o: %.S FORCE
43 $(call if_changed_dep,vdso32as) 43 $(call if_changed_dep,vdso32as)
44 44
45# actual build commands 45# actual build commands
46quiet_cmd_vdso32ld = VDSO32L $@ 46quiet_cmd_vdso32ld = VDSO32L $@
47 cmd_vdso32ld = $(CROSS32CC) $(c_flags) -Wl,-T $^ -o $@ 47 cmd_vdso32ld = $(CROSS32CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^)
48quiet_cmd_vdso32as = VDSO32A $@ 48quiet_cmd_vdso32as = VDSO32A $@
49 cmd_vdso32as = $(CROSS32CC) $(a_flags) -c -o $@ $< 49 cmd_vdso32as = $(CROSS32CC) $(a_flags) -c -o $@ $<
50 50
diff --git a/arch/powerpc/kernel/vdso64/Makefile b/arch/powerpc/kernel/vdso64/Makefile
index c710802b8fb6..366ae09b14c1 100644
--- a/arch/powerpc/kernel/vdso64/Makefile
+++ b/arch/powerpc/kernel/vdso64/Makefile
@@ -23,7 +23,7 @@ CPPFLAGS_vdso64.lds += -P -C -U$(ARCH)
23$(obj)/vdso64_wrapper.o : $(obj)/vdso64.so 23$(obj)/vdso64_wrapper.o : $(obj)/vdso64.so
24 24
25# link rule for the .so file, .lds has to be first 25# link rule for the .so file, .lds has to be first
26$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) 26$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) FORCE
27 $(call if_changed,vdso64ld) 27 $(call if_changed,vdso64ld)
28 28
29# strip rule for the .so file 29# strip rule for the .so file
@@ -32,12 +32,12 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE
32 $(call if_changed,objcopy) 32 $(call if_changed,objcopy)
33 33
34# assembly rules for the .S files 34# assembly rules for the .S files
35$(obj-vdso64): %.o: %.S 35$(obj-vdso64): %.o: %.S FORCE
36 $(call if_changed_dep,vdso64as) 36 $(call if_changed_dep,vdso64as)
37 37
38# actual build commands 38# actual build commands
39quiet_cmd_vdso64ld = VDSO64L $@ 39quiet_cmd_vdso64ld = VDSO64L $@
40 cmd_vdso64ld = $(CC) $(c_flags) -Wl,-T $^ -o $@ 40 cmd_vdso64ld = $(CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^)
41quiet_cmd_vdso64as = VDSO64A $@ 41quiet_cmd_vdso64as = VDSO64A $@
42 cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $< 42 cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $<
43 43
diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index a75ba38a2d81..05aa11399a78 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -1329,20 +1329,16 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)
1329 xics->kvm = kvm; 1329 xics->kvm = kvm;
1330 1330
1331 /* Already there ? */ 1331 /* Already there ? */
1332 mutex_lock(&kvm->lock);
1333 if (kvm->arch.xics) 1332 if (kvm->arch.xics)
1334 ret = -EEXIST; 1333 ret = -EEXIST;
1335 else 1334 else
1336 kvm->arch.xics = xics; 1335 kvm->arch.xics = xics;
1337 mutex_unlock(&kvm->lock);
1338 1336
1339 if (ret) { 1337 if (ret) {
1340 kfree(xics); 1338 kfree(xics);
1341 return ret; 1339 return ret;
1342 } 1340 }
1343 1341
1344 xics_debugfs_init(xics);
1345
1346#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 1342#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
1347 if (cpu_has_feature(CPU_FTR_ARCH_206)) { 1343 if (cpu_has_feature(CPU_FTR_ARCH_206)) {
1348 /* Enable real mode support */ 1344 /* Enable real mode support */
@@ -1354,9 +1350,17 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)
1354 return 0; 1350 return 0;
1355} 1351}
1356 1352
1353static void kvmppc_xics_init(struct kvm_device *dev)
1354{
1355 struct kvmppc_xics *xics = (struct kvmppc_xics *)dev->private;
1356
1357 xics_debugfs_init(xics);
1358}
1359
1357struct kvm_device_ops kvm_xics_ops = { 1360struct kvm_device_ops kvm_xics_ops = {
1358 .name = "kvm-xics", 1361 .name = "kvm-xics",
1359 .create = kvmppc_xics_create, 1362 .create = kvmppc_xics_create,
1363 .init = kvmppc_xics_init,
1360 .destroy = kvmppc_xics_free, 1364 .destroy = kvmppc_xics_free,
1361 .set_attr = xics_set_attr, 1365 .set_attr = xics_set_attr,
1362 .get_attr = xics_get_attr, 1366 .get_attr = xics_get_attr,
diff --git a/arch/powerpc/lib/checksum_32.S b/arch/powerpc/lib/checksum_32.S
index d90870a66b60..0a57fe6d49cc 100644
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -127,8 +127,9 @@ _GLOBAL(csum_partial_copy_generic)
127 stw r7,12(r1) 127 stw r7,12(r1)
128 stw r8,8(r1) 128 stw r8,8(r1)
129 129
130 andi. r0,r4,1 /* is destination address even ? */ 130 rlwinm r0,r4,3,0x8
131 cmplwi cr7,r0,0 131 rlwnm r6,r6,r0,0,31 /* odd destination address: rotate one byte */
132 cmplwi cr7,r0,0 /* is destination address even ? */
132 addic r12,r6,0 133 addic r12,r6,0
133 addi r6,r4,-4 134 addi r6,r4,-4
134 neg r0,r4 135 neg r0,r4
@@ -237,7 +238,7 @@ _GLOBAL(csum_partial_copy_generic)
23766: addze r3,r12 23866: addze r3,r12
238 addi r1,r1,16 239 addi r1,r1,16
239 beqlr+ cr7 240 beqlr+ cr7
240 rlwinm r3,r3,8,0,31 /* swap bytes for odd destination */ 241 rlwinm r3,r3,8,0,31 /* odd destination address: rotate one byte */
241 blr 242 blr
242 243
243/* read fault */ 244/* read fault */
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index 74145f02ad41..043415f0bdb1 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -188,7 +188,10 @@ void __init apply_feature_fixups(void)
188 &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup); 188 &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup);
189#endif 189#endif
190 do_final_fixups(); 190 do_final_fixups();
191}
191 192
193void __init setup_feature_keys(void)
194{
192 /* 195 /*
193 * Initialise jump label. This causes all the cpu/mmu_has_feature() 196 * Initialise jump label. This causes all the cpu/mmu_has_feature()
194 * checks to take on their correct polarity based on the current set of 197 * checks to take on their correct polarity based on the current set of
diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c
index 5be15cff758d..2975754c65ea 100644
--- a/arch/powerpc/platforms/cell/spufs/inode.c
+++ b/arch/powerpc/platforms/cell/spufs/inode.c
@@ -496,8 +496,10 @@ spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
496 gang = alloc_spu_gang(); 496 gang = alloc_spu_gang();
497 SPUFS_I(inode)->i_ctx = NULL; 497 SPUFS_I(inode)->i_ctx = NULL;
498 SPUFS_I(inode)->i_gang = gang; 498 SPUFS_I(inode)->i_gang = gang;
499 if (!gang) 499 if (!gang) {
500 ret = -ENOMEM;
500 goto out_iput; 501 goto out_iput;
502 }
501 503
502 inode->i_op = &simple_dir_inode_operations; 504 inode->i_op = &simple_dir_inode_operations;
503 inode->i_fop = &simple_dir_operations; 505 inode->i_fop = &simple_dir_operations;
diff --git a/arch/powerpc/platforms/pasemi/iommu.c b/arch/powerpc/platforms/pasemi/iommu.c
index 309d9ccccd50..c61667e8bb06 100644
--- a/arch/powerpc/platforms/pasemi/iommu.c
+++ b/arch/powerpc/platforms/pasemi/iommu.c
@@ -187,6 +187,11 @@ static void pci_dma_dev_setup_pasemi(struct pci_dev *dev)
187 if (dev->vendor == 0x1959 && dev->device == 0xa007 && 187 if (dev->vendor == 0x1959 && dev->device == 0xa007 &&
188 !firmware_has_feature(FW_FEATURE_LPAR)) { 188 !firmware_has_feature(FW_FEATURE_LPAR)) {
189 dev->dev.archdata.dma_ops = &dma_direct_ops; 189 dev->dev.archdata.dma_ops = &dma_direct_ops;
190 /*
191 * Set the coherent DMA mask to prevent the iommu
192 * being used unnecessarily
193 */
194 dev->dev.coherent_dma_mask = DMA_BIT_MASK(44);
190 return; 195 return;
191 } 196 }
192#endif 197#endif
diff --git a/arch/powerpc/platforms/powernv/opal-irqchip.c b/arch/powerpc/platforms/powernv/opal-irqchip.c
index e505223b4ec5..ed8bba68a162 100644
--- a/arch/powerpc/platforms/powernv/opal-irqchip.c
+++ b/arch/powerpc/platforms/powernv/opal-irqchip.c
@@ -228,7 +228,8 @@ int __init opal_event_init(void)
228 } 228 }
229 229
230 /* Install interrupt handler */ 230 /* Install interrupt handler */
231 rc = request_irq(virq, opal_interrupt, 0, "opal", NULL); 231 rc = request_irq(virq, opal_interrupt, IRQF_TRIGGER_LOW,
232 "opal", NULL);
232 if (rc) { 233 if (rc) {
233 irq_dispose_mapping(virq); 234 irq_dispose_mapping(virq);
234 pr_warn("Error %d requesting irq %d (0x%x)\n", 235 pr_warn("Error %d requesting irq %d (0x%x)\n",
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 8b4fc68cebcb..6c9a65b52e63 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -399,6 +399,7 @@ static int opal_recover_mce(struct pt_regs *regs,
399 399
400 if (!(regs->msr & MSR_RI)) { 400 if (!(regs->msr & MSR_RI)) {
401 /* If MSR_RI isn't set, we cannot recover */ 401 /* If MSR_RI isn't set, we cannot recover */
402 pr_err("Machine check interrupt unrecoverable: MSR(RI=0)\n");
402 recovered = 0; 403 recovered = 0;
403 } else if (evt->disposition == MCE_DISPOSITION_RECOVERED) { 404 } else if (evt->disposition == MCE_DISPOSITION_RECOVERED) {
404 /* Platform corrected itself */ 405 /* Platform corrected itself */
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 6b9528307f62..fd9444f9fb0c 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -111,10 +111,17 @@ static int __init iommu_setup(char *str)
111} 111}
112early_param("iommu", iommu_setup); 112early_param("iommu", iommu_setup);
113 113
114static inline bool pnv_pci_is_mem_pref_64(unsigned long flags) 114static inline bool pnv_pci_is_m64(struct pnv_phb *phb, struct resource *r)
115{ 115{
116 return ((flags & (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH)) == 116 /*
117 (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH)); 117 * WARNING: We cannot rely on the resource flags. The Linux PCI
118 * allocation code sometimes decides to put a 64-bit prefetchable
119 * BAR in the 32-bit window, so we have to compare the addresses.
120 *
121 * For simplicity we only test resource start.
122 */
123 return (r->start >= phb->ioda.m64_base &&
124 r->start < (phb->ioda.m64_base + phb->ioda.m64_size));
118} 125}
119 126
120static struct pnv_ioda_pe *pnv_ioda_init_pe(struct pnv_phb *phb, int pe_no) 127static struct pnv_ioda_pe *pnv_ioda_init_pe(struct pnv_phb *phb, int pe_no)
@@ -229,7 +236,7 @@ static void pnv_ioda_reserve_dev_m64_pe(struct pci_dev *pdev,
229 sgsz = phb->ioda.m64_segsize; 236 sgsz = phb->ioda.m64_segsize;
230 for (i = 0; i <= PCI_ROM_RESOURCE; i++) { 237 for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
231 r = &pdev->resource[i]; 238 r = &pdev->resource[i];
232 if (!r->parent || !pnv_pci_is_mem_pref_64(r->flags)) 239 if (!r->parent || !pnv_pci_is_m64(phb, r))
233 continue; 240 continue;
234 241
235 start = _ALIGN_DOWN(r->start - base, sgsz); 242 start = _ALIGN_DOWN(r->start - base, sgsz);
@@ -1877,7 +1884,7 @@ static void pnv_pci_phb3_tce_invalidate(struct pnv_ioda_pe *pe, bool rm,
1877 unsigned shift, unsigned long index, 1884 unsigned shift, unsigned long index,
1878 unsigned long npages) 1885 unsigned long npages)
1879{ 1886{
1880 __be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb, false); 1887 __be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb, rm);
1881 unsigned long start, end, inc; 1888 unsigned long start, end, inc;
1882 1889
1883 /* We'll invalidate DMA address in PE scope */ 1890 /* We'll invalidate DMA address in PE scope */
@@ -2863,7 +2870,7 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)
2863 res = &pdev->resource[i + PCI_IOV_RESOURCES]; 2870 res = &pdev->resource[i + PCI_IOV_RESOURCES];
2864 if (!res->flags || res->parent) 2871 if (!res->flags || res->parent)
2865 continue; 2872 continue;
2866 if (!pnv_pci_is_mem_pref_64(res->flags)) { 2873 if (!pnv_pci_is_m64(phb, res)) {
2867 dev_warn(&pdev->dev, "Don't support SR-IOV with" 2874 dev_warn(&pdev->dev, "Don't support SR-IOV with"
2868 " non M64 VF BAR%d: %pR. \n", 2875 " non M64 VF BAR%d: %pR. \n",
2869 i, res); 2876 i, res);
@@ -2958,7 +2965,7 @@ static void pnv_ioda_setup_pe_res(struct pnv_ioda_pe *pe,
2958 index++; 2965 index++;
2959 } 2966 }
2960 } else if ((res->flags & IORESOURCE_MEM) && 2967 } else if ((res->flags & IORESOURCE_MEM) &&
2961 !pnv_pci_is_mem_pref_64(res->flags)) { 2968 !pnv_pci_is_m64(phb, res)) {
2962 region.start = res->start - 2969 region.start = res->start -
2963 phb->hose->mem_offset[0] - 2970 phb->hose->mem_offset[0] -
2964 phb->ioda.m32_pci_base; 2971 phb->ioda.m32_pci_base;
@@ -3083,9 +3090,12 @@ static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
3083 bridge = bridge->bus->self; 3090 bridge = bridge->bus->self;
3084 } 3091 }
3085 3092
3086 /* We fail back to M32 if M64 isn't supported */ 3093 /*
3087 if (phb->ioda.m64_segsize && 3094 * We fall back to M32 if M64 isn't supported. We enforce the M64
3088 pnv_pci_is_mem_pref_64(type)) 3095 * alignment for any 64-bit resource, PCIe doesn't care and
3096 * bridges only do 64-bit prefetchable anyway.
3097 */
3098 if (phb->ioda.m64_segsize && (type & IORESOURCE_MEM_64))
3089 return phb->ioda.m64_segsize; 3099 return phb->ioda.m64_segsize;
3090 if (type & IORESOURCE_MEM) 3100 if (type & IORESOURCE_MEM)
3091 return phb->ioda.m32_segsize; 3101 return phb->ioda.m32_segsize;
@@ -3125,7 +3135,7 @@ static void pnv_pci_fixup_bridge_resources(struct pci_bus *bus,
3125 w = NULL; 3135 w = NULL;
3126 if (r->flags & type & IORESOURCE_IO) 3136 if (r->flags & type & IORESOURCE_IO)
3127 w = &hose->io_resource; 3137 w = &hose->io_resource;
3128 else if (pnv_pci_is_mem_pref_64(r->flags) && 3138 else if (pnv_pci_is_m64(phb, r) &&
3129 (type & IORESOURCE_PREFETCH) && 3139 (type & IORESOURCE_PREFETCH) &&
3130 phb->ioda.m64_segsize) 3140 phb->ioda.m64_segsize)
3131 w = &hose->mem_resources[1]; 3141 w = &hose->mem_resources[1];
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 43f7beb2902d..76ec104e88be 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -320,19 +320,6 @@ static int dlpar_remove_device_tree_lmb(struct of_drconf_cell *lmb)
320 return dlpar_update_device_tree_lmb(lmb); 320 return dlpar_update_device_tree_lmb(lmb);
321} 321}
322 322
323static struct memory_block *lmb_to_memblock(struct of_drconf_cell *lmb)
324{
325 unsigned long section_nr;
326 struct mem_section *mem_sect;
327 struct memory_block *mem_block;
328
329 section_nr = pfn_to_section_nr(PFN_DOWN(lmb->base_addr));
330 mem_sect = __nr_to_section(section_nr);
331
332 mem_block = find_memory_block(mem_sect);
333 return mem_block;
334}
335
336#ifdef CONFIG_MEMORY_HOTREMOVE 323#ifdef CONFIG_MEMORY_HOTREMOVE
337static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) 324static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size)
338{ 325{
@@ -420,6 +407,19 @@ static bool lmb_is_removable(struct of_drconf_cell *lmb)
420 407
421static int dlpar_add_lmb(struct of_drconf_cell *); 408static int dlpar_add_lmb(struct of_drconf_cell *);
422 409
410static struct memory_block *lmb_to_memblock(struct of_drconf_cell *lmb)
411{
412 unsigned long section_nr;
413 struct mem_section *mem_sect;
414 struct memory_block *mem_block;
415
416 section_nr = pfn_to_section_nr(PFN_DOWN(lmb->base_addr));
417 mem_sect = __nr_to_section(section_nr);
418
419 mem_block = find_memory_block(mem_sect);
420 return mem_block;
421}
422
423static int dlpar_remove_lmb(struct of_drconf_cell *lmb) 423static int dlpar_remove_lmb(struct of_drconf_cell *lmb)
424{ 424{
425 struct memory_block *mem_block; 425 struct memory_block *mem_block;
diff --git a/arch/powerpc/sysdev/xics/Kconfig b/arch/powerpc/sysdev/xics/Kconfig
index 0031eda320c3..385e7aa9e273 100644
--- a/arch/powerpc/sysdev/xics/Kconfig
+++ b/arch/powerpc/sysdev/xics/Kconfig
@@ -1,6 +1,7 @@
1config PPC_XICS 1config PPC_XICS
2 def_bool n 2 def_bool n
3 select PPC_SMP_MUXED_IPI 3 select PPC_SMP_MUXED_IPI
4 select HARDIRQS_SW_RESEND
4 5
5config PPC_ICP_NATIVE 6config PPC_ICP_NATIVE
6 def_bool n 7 def_bool n
diff --git a/arch/powerpc/sysdev/xics/ics-opal.c b/arch/powerpc/sysdev/xics/ics-opal.c
index 27c936c080a6..1c6bf4b66f56 100644
--- a/arch/powerpc/sysdev/xics/ics-opal.c
+++ b/arch/powerpc/sysdev/xics/ics-opal.c
@@ -156,7 +156,9 @@ static struct irq_chip ics_opal_irq_chip = {
156 .irq_mask = ics_opal_mask_irq, 156 .irq_mask = ics_opal_mask_irq,
157 .irq_unmask = ics_opal_unmask_irq, 157 .irq_unmask = ics_opal_unmask_irq,
158 .irq_eoi = NULL, /* Patched at init time */ 158 .irq_eoi = NULL, /* Patched at init time */
159 .irq_set_affinity = ics_opal_set_affinity 159 .irq_set_affinity = ics_opal_set_affinity,
160 .irq_set_type = xics_set_irq_type,
161 .irq_retrigger = xics_retrigger,
160}; 162};
161 163
162static int ics_opal_map(struct ics *ics, unsigned int virq); 164static int ics_opal_map(struct ics *ics, unsigned int virq);
diff --git a/arch/powerpc/sysdev/xics/ics-rtas.c b/arch/powerpc/sysdev/xics/ics-rtas.c
index 3854dd41558d..78ee5c778ef8 100644
--- a/arch/powerpc/sysdev/xics/ics-rtas.c
+++ b/arch/powerpc/sysdev/xics/ics-rtas.c
@@ -163,7 +163,9 @@ static struct irq_chip ics_rtas_irq_chip = {
163 .irq_mask = ics_rtas_mask_irq, 163 .irq_mask = ics_rtas_mask_irq,
164 .irq_unmask = ics_rtas_unmask_irq, 164 .irq_unmask = ics_rtas_unmask_irq,
165 .irq_eoi = NULL, /* Patched at init time */ 165 .irq_eoi = NULL, /* Patched at init time */
166 .irq_set_affinity = ics_rtas_set_affinity 166 .irq_set_affinity = ics_rtas_set_affinity,
167 .irq_set_type = xics_set_irq_type,
168 .irq_retrigger = xics_retrigger,
167}; 169};
168 170
169static int ics_rtas_map(struct ics *ics, unsigned int virq) 171static int ics_rtas_map(struct ics *ics, unsigned int virq)
diff --git a/arch/powerpc/sysdev/xics/xics-common.c b/arch/powerpc/sysdev/xics/xics-common.c
index a795a5f0301c..9d530f479588 100644
--- a/arch/powerpc/sysdev/xics/xics-common.c
+++ b/arch/powerpc/sysdev/xics/xics-common.c
@@ -328,8 +328,12 @@ static int xics_host_map(struct irq_domain *h, unsigned int virq,
328 328
329 pr_devel("xics: map virq %d, hwirq 0x%lx\n", virq, hw); 329 pr_devel("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
330 330
331 /* They aren't all level sensitive but we just don't really know */ 331 /*
332 irq_set_status_flags(virq, IRQ_LEVEL); 332 * Mark interrupts as edge sensitive by default so that resend
333 * actually works. The device-tree parsing will turn the LSIs
334 * back to level.
335 */
336 irq_clear_status_flags(virq, IRQ_LEVEL);
333 337
334 /* Don't call into ICS for IPIs */ 338 /* Don't call into ICS for IPIs */
335 if (hw == XICS_IPI) { 339 if (hw == XICS_IPI) {
@@ -351,13 +355,54 @@ static int xics_host_xlate(struct irq_domain *h, struct device_node *ct,
351 irq_hw_number_t *out_hwirq, unsigned int *out_flags) 355 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
352 356
353{ 357{
354 /* Current xics implementation translates everything
355 * to level. It is not technically right for MSIs but this
356 * is irrelevant at this point. We might get smarter in the future
357 */
358 *out_hwirq = intspec[0]; 358 *out_hwirq = intspec[0];
359 *out_flags = IRQ_TYPE_LEVEL_LOW;
360 359
360 /*
361 * If intsize is at least 2, we look for the type in the second cell,
362 * we assume the LSB indicates a level interrupt.
363 */
364 if (intsize > 1) {
365 if (intspec[1] & 1)
366 *out_flags = IRQ_TYPE_LEVEL_LOW;
367 else
368 *out_flags = IRQ_TYPE_EDGE_RISING;
369 } else
370 *out_flags = IRQ_TYPE_LEVEL_LOW;
371
372 return 0;
373}
374
375int xics_set_irq_type(struct irq_data *d, unsigned int flow_type)
376{
377 /*
378 * We only support these. This has really no effect other than setting
379 * the corresponding descriptor bits mind you but those will in turn
380 * affect the resend function when re-enabling an edge interrupt.
381 *
382 * Set set the default to edge as explained in map().
383 */
384 if (flow_type == IRQ_TYPE_DEFAULT || flow_type == IRQ_TYPE_NONE)
385 flow_type = IRQ_TYPE_EDGE_RISING;
386
387 if (flow_type != IRQ_TYPE_EDGE_RISING &&
388 flow_type != IRQ_TYPE_LEVEL_LOW)
389 return -EINVAL;
390
391 irqd_set_trigger_type(d, flow_type);
392
393 return IRQ_SET_MASK_OK_NOCOPY;
394}
395
396int xics_retrigger(struct irq_data *data)
397{
398 /*
399 * We need to push a dummy CPPR when retriggering, since the subsequent
400 * EOI will try to pop it. Passing 0 works, as the function hard codes
401 * the priority value anyway.
402 */
403 xics_push_cppr(0);
404
405 /* Tell the core to do a soft retrigger */
361 return 0; 406 return 0;
362} 407}
363 408
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 0e348781327b..e751fe25d6ab 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -872,4 +872,17 @@ config S390_GUEST
872 Select this option if you want to run the kernel as a guest under 872 Select this option if you want to run the kernel as a guest under
873 the KVM hypervisor. 873 the KVM hypervisor.
874 874
875config S390_GUEST_OLD_TRANSPORT
876 def_bool y
877 prompt "Guest support for old s390 virtio transport (DEPRECATED)"
878 depends on S390_GUEST
879 help
880 Enable this option to add support for the old s390-virtio
881 transport (i.e. virtio devices NOT based on virtio-ccw). This
882 type of virtio devices is only available on the experimental
883 kuli userspace or with old (< 2.6) qemu. If you are running
884 with a modern version of qemu (which supports virtio-ccw since
885 1.4 and uses it by default since version 2.4), you probably won't
886 need this.
887
875endmenu 888endmenu
diff --git a/arch/s390/boot/compressed/head.S b/arch/s390/boot/compressed/head.S
index f86a4eef28a9..28c4f96a2d9c 100644
--- a/arch/s390/boot/compressed/head.S
+++ b/arch/s390/boot/compressed/head.S
@@ -21,16 +21,21 @@ ENTRY(startup_continue)
21 lg %r15,.Lstack-.LPG1(%r13) 21 lg %r15,.Lstack-.LPG1(%r13)
22 aghi %r15,-160 22 aghi %r15,-160
23 brasl %r14,decompress_kernel 23 brasl %r14,decompress_kernel
24 # setup registers for memory mover & branch to target 24 # Set up registers for memory mover. We move the decompressed image to
25 # 0x11000, starting at offset 0x11000 in the decompressed image so
26 # that code living at 0x11000 in the image will end up at 0x11000 in
27 # memory.
25 lgr %r4,%r2 28 lgr %r4,%r2
26 lg %r2,.Loffset-.LPG1(%r13) 29 lg %r2,.Loffset-.LPG1(%r13)
27 la %r4,0(%r2,%r4) 30 la %r4,0(%r2,%r4)
28 lg %r3,.Lmvsize-.LPG1(%r13) 31 lg %r3,.Lmvsize-.LPG1(%r13)
29 lgr %r5,%r3 32 lgr %r5,%r3
30 # move the memory mover someplace safe 33 # Move the memory mover someplace safe so it doesn't overwrite itself.
31 la %r1,0x200 34 la %r1,0x200
32 mvc 0(mover_end-mover,%r1),mover-.LPG1(%r13) 35 mvc 0(mover_end-mover,%r1),mover-.LPG1(%r13)
33 # decompress image is started at 0x11000 36 # When the memory mover is done we pass control to
37 # arch/s390/kernel/head64.S:startup_continue which lives at 0x11000 in
38 # the decompressed image.
34 lgr %r6,%r2 39 lgr %r6,%r2
35 br %r1 40 br %r1
36mover: 41mover:
diff --git a/arch/s390/configs/default_defconfig b/arch/s390/configs/default_defconfig
index 889ea3450210..26e0c7f08814 100644
--- a/arch/s390/configs/default_defconfig
+++ b/arch/s390/configs/default_defconfig
@@ -678,7 +678,7 @@ CONFIG_CRYPTO_SHA512_S390=m
678CONFIG_CRYPTO_DES_S390=m 678CONFIG_CRYPTO_DES_S390=m
679CONFIG_CRYPTO_AES_S390=m 679CONFIG_CRYPTO_AES_S390=m
680CONFIG_CRYPTO_GHASH_S390=m 680CONFIG_CRYPTO_GHASH_S390=m
681CONFIG_CRYPTO_CRC32_S390=m 681CONFIG_CRYPTO_CRC32_S390=y
682CONFIG_ASYMMETRIC_KEY_TYPE=y 682CONFIG_ASYMMETRIC_KEY_TYPE=y
683CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m 683CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
684CONFIG_X509_CERTIFICATE_PARSER=m 684CONFIG_X509_CERTIFICATE_PARSER=m
diff --git a/arch/s390/configs/gcov_defconfig b/arch/s390/configs/gcov_defconfig
index 1bcfd764910a..24879dab47bc 100644
--- a/arch/s390/configs/gcov_defconfig
+++ b/arch/s390/configs/gcov_defconfig
@@ -616,7 +616,7 @@ CONFIG_CRYPTO_SHA512_S390=m
616CONFIG_CRYPTO_DES_S390=m 616CONFIG_CRYPTO_DES_S390=m
617CONFIG_CRYPTO_AES_S390=m 617CONFIG_CRYPTO_AES_S390=m
618CONFIG_CRYPTO_GHASH_S390=m 618CONFIG_CRYPTO_GHASH_S390=m
619CONFIG_CRYPTO_CRC32_S390=m 619CONFIG_CRYPTO_CRC32_S390=y
620CONFIG_ASYMMETRIC_KEY_TYPE=y 620CONFIG_ASYMMETRIC_KEY_TYPE=y
621CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m 621CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
622CONFIG_X509_CERTIFICATE_PARSER=m 622CONFIG_X509_CERTIFICATE_PARSER=m
diff --git a/arch/s390/configs/performance_defconfig b/arch/s390/configs/performance_defconfig
index 13ff090139c8..a5c1e5f2a0ca 100644
--- a/arch/s390/configs/performance_defconfig
+++ b/arch/s390/configs/performance_defconfig
@@ -615,7 +615,7 @@ CONFIG_CRYPTO_SHA512_S390=m
615CONFIG_CRYPTO_DES_S390=m 615CONFIG_CRYPTO_DES_S390=m
616CONFIG_CRYPTO_AES_S390=m 616CONFIG_CRYPTO_AES_S390=m
617CONFIG_CRYPTO_GHASH_S390=m 617CONFIG_CRYPTO_GHASH_S390=m
618CONFIG_CRYPTO_CRC32_S390=m 618CONFIG_CRYPTO_CRC32_S390=y
619CONFIG_ASYMMETRIC_KEY_TYPE=y 619CONFIG_ASYMMETRIC_KEY_TYPE=y
620CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m 620CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
621CONFIG_X509_CERTIFICATE_PARSER=m 621CONFIG_X509_CERTIFICATE_PARSER=m
diff --git a/arch/s390/crypto/crc32-vx.c b/arch/s390/crypto/crc32-vx.c
index 577ae1d4ae89..2bad9d837029 100644
--- a/arch/s390/crypto/crc32-vx.c
+++ b/arch/s390/crypto/crc32-vx.c
@@ -51,6 +51,9 @@ u32 crc32c_le_vgfm_16(u32 crc, unsigned char const *buf, size_t size);
51 struct kernel_fpu vxstate; \ 51 struct kernel_fpu vxstate; \
52 unsigned long prealign, aligned, remaining; \ 52 unsigned long prealign, aligned, remaining; \
53 \ 53 \
54 if (datalen < VX_MIN_LEN + VX_ALIGN_MASK) \
55 return ___crc32_sw(crc, data, datalen); \
56 \
54 if ((unsigned long)data & VX_ALIGN_MASK) { \ 57 if ((unsigned long)data & VX_ALIGN_MASK) { \
55 prealign = VX_ALIGNMENT - \ 58 prealign = VX_ALIGNMENT - \
56 ((unsigned long)data & VX_ALIGN_MASK); \ 59 ((unsigned long)data & VX_ALIGN_MASK); \
@@ -59,9 +62,6 @@ u32 crc32c_le_vgfm_16(u32 crc, unsigned char const *buf, size_t size);
59 data = (void *)((unsigned long)data + prealign); \ 62 data = (void *)((unsigned long)data + prealign); \
60 } \ 63 } \
61 \ 64 \
62 if (datalen < VX_MIN_LEN) \
63 return ___crc32_sw(crc, data, datalen); \
64 \
65 aligned = datalen & ~VX_ALIGN_MASK; \ 65 aligned = datalen & ~VX_ALIGN_MASK; \
66 remaining = datalen & VX_ALIGN_MASK; \ 66 remaining = datalen & VX_ALIGN_MASK; \
67 \ 67 \
diff --git a/arch/s390/defconfig b/arch/s390/defconfig
index ccccebeeaaf6..73610f2e3b4f 100644
--- a/arch/s390/defconfig
+++ b/arch/s390/defconfig
@@ -234,7 +234,7 @@ CONFIG_CRYPTO_SHA256_S390=m
234CONFIG_CRYPTO_SHA512_S390=m 234CONFIG_CRYPTO_SHA512_S390=m
235CONFIG_CRYPTO_DES_S390=m 235CONFIG_CRYPTO_DES_S390=m
236CONFIG_CRYPTO_AES_S390=m 236CONFIG_CRYPTO_AES_S390=m
237CONFIG_CRYPTO_CRC32_S390=m 237CONFIG_CRYPTO_CRC32_S390=y
238CONFIG_CRC7=m 238CONFIG_CRC7=m
239# CONFIG_XZ_DEC_X86 is not set 239# CONFIG_XZ_DEC_X86 is not set
240# CONFIG_XZ_DEC_POWERPC is not set 240# CONFIG_XZ_DEC_POWERPC is not set
diff --git a/arch/s390/kernel/head.S b/arch/s390/kernel/head.S
index 56e4d8234ef2..4431905f8cfa 100644
--- a/arch/s390/kernel/head.S
+++ b/arch/s390/kernel/head.S
@@ -309,7 +309,9 @@ ENTRY(startup_kdump)
309 l %r15,.Lstack-.LPG0(%r13) 309 l %r15,.Lstack-.LPG0(%r13)
310 ahi %r15,-STACK_FRAME_OVERHEAD 310 ahi %r15,-STACK_FRAME_OVERHEAD
311 brasl %r14,verify_facilities 311 brasl %r14,verify_facilities
312 /* Continue with startup code in head64.S */ 312# For uncompressed images, continue in
313# arch/s390/kernel/head64.S. For compressed images, continue in
314# arch/s390/boot/compressed/head.S.
313 jg startup_continue 315 jg startup_continue
314 316
315.Lstack: 317.Lstack:
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index ba5f456edaa9..7f7ba5f23f13 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -204,11 +204,9 @@ static void __init conmode_default(void)
204#endif 204#endif
205 } 205 }
206 } else if (MACHINE_IS_KVM) { 206 } else if (MACHINE_IS_KVM) {
207 if (sclp.has_vt220 && 207 if (sclp.has_vt220 && IS_ENABLED(CONFIG_SCLP_VT220_CONSOLE))
208 config_enabled(CONFIG_SCLP_VT220_CONSOLE))
209 SET_CONSOLE_VT220; 208 SET_CONSOLE_VT220;
210 else if (sclp.has_linemode && 209 else if (sclp.has_linemode && IS_ENABLED(CONFIG_SCLP_CONSOLE))
211 config_enabled(CONFIG_SCLP_CONSOLE))
212 SET_CONSOLE_SCLP; 210 SET_CONSOLE_SCLP;
213 else 211 else
214 SET_CONSOLE_HVC; 212 SET_CONSOLE_HVC;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 3f3ae4865d57..f142215ed30d 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1672,6 +1672,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
1672 KVM_SYNC_CRS | 1672 KVM_SYNC_CRS |
1673 KVM_SYNC_ARCH0 | 1673 KVM_SYNC_ARCH0 |
1674 KVM_SYNC_PFAULT; 1674 KVM_SYNC_PFAULT;
1675 kvm_s390_set_prefix(vcpu, 0);
1675 if (test_kvm_facility(vcpu->kvm, 64)) 1676 if (test_kvm_facility(vcpu->kvm, 64))
1676 vcpu->run->kvm_valid_regs |= KVM_SYNC_RICCB; 1677 vcpu->run->kvm_valid_regs |= KVM_SYNC_RICCB;
1677 /* fprs can be synchronized via vrs, even if the guest has no vx. With 1678 /* fprs can be synchronized via vrs, even if the guest has no vx. With
@@ -2361,8 +2362,10 @@ retry:
2361 rc = gmap_mprotect_notify(vcpu->arch.gmap, 2362 rc = gmap_mprotect_notify(vcpu->arch.gmap,
2362 kvm_s390_get_prefix(vcpu), 2363 kvm_s390_get_prefix(vcpu),
2363 PAGE_SIZE * 2, PROT_WRITE); 2364 PAGE_SIZE * 2, PROT_WRITE);
2364 if (rc) 2365 if (rc) {
2366 kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
2365 return rc; 2367 return rc;
2368 }
2366 goto retry; 2369 goto retry;
2367 } 2370 }
2368 2371
diff --git a/arch/s390/lib/string.c b/arch/s390/lib/string.c
index e390bbb16443..48352bffbc92 100644
--- a/arch/s390/lib/string.c
+++ b/arch/s390/lib/string.c
@@ -237,11 +237,10 @@ char * strrchr(const char * s, int c)
237EXPORT_SYMBOL(strrchr); 237EXPORT_SYMBOL(strrchr);
238 238
239static inline int clcle(const char *s1, unsigned long l1, 239static inline int clcle(const char *s1, unsigned long l1,
240 const char *s2, unsigned long l2, 240 const char *s2, unsigned long l2)
241 int *diff)
242{ 241{
243 register unsigned long r2 asm("2") = (unsigned long) s1; 242 register unsigned long r2 asm("2") = (unsigned long) s1;
244 register unsigned long r3 asm("3") = (unsigned long) l2; 243 register unsigned long r3 asm("3") = (unsigned long) l1;
245 register unsigned long r4 asm("4") = (unsigned long) s2; 244 register unsigned long r4 asm("4") = (unsigned long) s2;
246 register unsigned long r5 asm("5") = (unsigned long) l2; 245 register unsigned long r5 asm("5") = (unsigned long) l2;
247 int cc; 246 int cc;
@@ -252,7 +251,6 @@ static inline int clcle(const char *s1, unsigned long l1,
252 " srl %0,28" 251 " srl %0,28"
253 : "=&d" (cc), "+a" (r2), "+a" (r3), 252 : "=&d" (cc), "+a" (r2), "+a" (r3),
254 "+a" (r4), "+a" (r5) : : "cc"); 253 "+a" (r4), "+a" (r5) : : "cc");
255 *diff = *(char *)r2 - *(char *)r4;
256 return cc; 254 return cc;
257} 255}
258 256
@@ -270,9 +268,9 @@ char * strstr(const char * s1,const char * s2)
270 return (char *) s1; 268 return (char *) s1;
271 l1 = __strend(s1) - s1; 269 l1 = __strend(s1) - s1;
272 while (l1-- >= l2) { 270 while (l1-- >= l2) {
273 int cc, dummy; 271 int cc;
274 272
275 cc = clcle(s1, l1, s2, l2, &dummy); 273 cc = clcle(s1, l2, s2, l2);
276 if (!cc) 274 if (!cc)
277 return (char *) s1; 275 return (char *) s1;
278 s1++; 276 s1++;
@@ -313,11 +311,11 @@ EXPORT_SYMBOL(memchr);
313 */ 311 */
314int memcmp(const void *cs, const void *ct, size_t n) 312int memcmp(const void *cs, const void *ct, size_t n)
315{ 313{
316 int ret, diff; 314 int ret;
317 315
318 ret = clcle(cs, n, ct, n, &diff); 316 ret = clcle(cs, n, ct, n);
319 if (ret) 317 if (ret)
320 ret = diff; 318 ret = ret == 1 ? -1 : 1;
321 return ret; 319 return ret;
322} 320}
323EXPORT_SYMBOL(memcmp); 321EXPORT_SYMBOL(memcmp);
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c
index 7104ffb5a67f..af7cf28cf97e 100644
--- a/arch/s390/mm/pageattr.c
+++ b/arch/s390/mm/pageattr.c
@@ -252,6 +252,8 @@ static int change_page_attr(unsigned long addr, unsigned long end,
252 int rc = -EINVAL; 252 int rc = -EINVAL;
253 pgd_t *pgdp; 253 pgd_t *pgdp;
254 254
255 if (addr == end)
256 return 0;
255 if (end >= MODULES_END) 257 if (end >= MODULES_END)
256 return -EINVAL; 258 return -EINVAL;
257 mutex_lock(&cpa_mutex); 259 mutex_lock(&cpa_mutex);
diff --git a/arch/um/include/asm/common.lds.S b/arch/um/include/asm/common.lds.S
index 1dd5bd8a8c59..133055311dce 100644
--- a/arch/um/include/asm/common.lds.S
+++ b/arch/um/include/asm/common.lds.S
@@ -81,7 +81,7 @@
81 .altinstr_replacement : { *(.altinstr_replacement) } 81 .altinstr_replacement : { *(.altinstr_replacement) }
82 /* .exit.text is discard at runtime, not link time, to deal with references 82 /* .exit.text is discard at runtime, not link time, to deal with references
83 from .altinstructions and .eh_frame */ 83 from .altinstructions and .eh_frame */
84 .exit.text : { *(.exit.text) } 84 .exit.text : { EXIT_TEXT }
85 .exit.data : { *(.exit.data) } 85 .exit.data : { *(.exit.data) }
86 86
87 .preinit_array : { 87 .preinit_array : {
diff --git a/arch/unicore32/include/asm/mmu_context.h b/arch/unicore32/include/asm/mmu_context.h
index e35632ef23c7..62dfc644c908 100644
--- a/arch/unicore32/include/asm/mmu_context.h
+++ b/arch/unicore32/include/asm/mmu_context.h
@@ -98,7 +98,7 @@ static inline void arch_bprm_mm_init(struct mm_struct *mm,
98} 98}
99 99
100static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, 100static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
101 bool write, bool foreign) 101 bool write, bool execute, bool foreign)
102{ 102{
103 /* by default, allow everything */ 103 /* by default, allow everything */
104 return true; 104 return true;
diff --git a/arch/x86/crypto/sha256-mb/sha256_mb.c b/arch/x86/crypto/sha256-mb/sha256_mb.c
index 89fa85e8b10c..6f97fb33ae21 100644
--- a/arch/x86/crypto/sha256-mb/sha256_mb.c
+++ b/arch/x86/crypto/sha256-mb/sha256_mb.c
@@ -485,10 +485,10 @@ static int sha_complete_job(struct mcryptd_hash_request_ctx *rctx,
485 485
486 req = cast_mcryptd_ctx_to_req(req_ctx); 486 req = cast_mcryptd_ctx_to_req(req_ctx);
487 if (irqs_disabled()) 487 if (irqs_disabled())
488 rctx->complete(&req->base, ret); 488 req_ctx->complete(&req->base, ret);
489 else { 489 else {
490 local_bh_disable(); 490 local_bh_disable();
491 rctx->complete(&req->base, ret); 491 req_ctx->complete(&req->base, ret);
492 local_bh_enable(); 492 local_bh_enable();
493 } 493 }
494 } 494 }
diff --git a/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S b/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S
index b691da981cd9..a78a0694ddef 100644
--- a/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S
+++ b/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S
@@ -265,13 +265,14 @@ ENTRY(sha256_mb_mgr_get_comp_job_avx2)
265 vpinsrd $1, _args_digest+1*32(state, idx, 4), %xmm0, %xmm0 265 vpinsrd $1, _args_digest+1*32(state, idx, 4), %xmm0, %xmm0
266 vpinsrd $2, _args_digest+2*32(state, idx, 4), %xmm0, %xmm0 266 vpinsrd $2, _args_digest+2*32(state, idx, 4), %xmm0, %xmm0
267 vpinsrd $3, _args_digest+3*32(state, idx, 4), %xmm0, %xmm0 267 vpinsrd $3, _args_digest+3*32(state, idx, 4), %xmm0, %xmm0
268 movl _args_digest+4*32(state, idx, 4), tmp2_w 268 vmovd _args_digest(state , idx, 4) , %xmm0
269 vpinsrd $1, _args_digest+5*32(state, idx, 4), %xmm1, %xmm1 269 vpinsrd $1, _args_digest+5*32(state, idx, 4), %xmm1, %xmm1
270 vpinsrd $2, _args_digest+6*32(state, idx, 4), %xmm1, %xmm1 270 vpinsrd $2, _args_digest+6*32(state, idx, 4), %xmm1, %xmm1
271 vpinsrd $3, _args_digest+7*32(state, idx, 4), %xmm1, %xmm1 271 vpinsrd $3, _args_digest+7*32(state, idx, 4), %xmm1, %xmm1
272 272
273 vmovdqu %xmm0, _result_digest(job_rax) 273 vmovdqu %xmm0, _result_digest(job_rax)
274 movl tmp2_w, _result_digest+1*16(job_rax) 274 offset = (_result_digest + 1*16)
275 vmovdqu %xmm1, offset(job_rax)
275 276
276 pop %rbx 277 pop %rbx
277 278
diff --git a/arch/x86/crypto/sha512-mb/sha512_mb.c b/arch/x86/crypto/sha512-mb/sha512_mb.c
index f4cf5b78fd36..d210174a52b0 100644
--- a/arch/x86/crypto/sha512-mb/sha512_mb.c
+++ b/arch/x86/crypto/sha512-mb/sha512_mb.c
@@ -497,10 +497,10 @@ static int sha_complete_job(struct mcryptd_hash_request_ctx *rctx,
497 497
498 req = cast_mcryptd_ctx_to_req(req_ctx); 498 req = cast_mcryptd_ctx_to_req(req_ctx);
499 if (irqs_disabled()) 499 if (irqs_disabled())
500 rctx->complete(&req->base, ret); 500 req_ctx->complete(&req->base, ret);
501 else { 501 else {
502 local_bh_disable(); 502 local_bh_disable();
503 rctx->complete(&req->base, ret); 503 req_ctx->complete(&req->base, ret);
504 local_bh_enable(); 504 local_bh_enable();
505 } 505 }
506 } 506 }
diff --git a/arch/x86/entry/Makefile b/arch/x86/entry/Makefile
index fe91c25092da..77f28ce9c646 100644
--- a/arch/x86/entry/Makefile
+++ b/arch/x86/entry/Makefile
@@ -5,6 +5,8 @@
5OBJECT_FILES_NON_STANDARD_entry_$(BITS).o := y 5OBJECT_FILES_NON_STANDARD_entry_$(BITS).o := y
6OBJECT_FILES_NON_STANDARD_entry_64_compat.o := y 6OBJECT_FILES_NON_STANDARD_entry_64_compat.o := y
7 7
8CFLAGS_syscall_64.o += -Wno-override-init
9CFLAGS_syscall_32.o += -Wno-override-init
8obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o 10obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o
9obj-y += common.o 11obj-y += common.o
10 12
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index b846875aeea6..d172c619c449 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -288,11 +288,15 @@ return_from_SYSCALL_64:
288 jne opportunistic_sysret_failed 288 jne opportunistic_sysret_failed
289 289
290 /* 290 /*
291 * SYSRET can't restore RF. SYSRET can restore TF, but unlike IRET, 291 * SYSCALL clears RF when it saves RFLAGS in R11 and SYSRET cannot
292 * restoring TF results in a trap from userspace immediately after 292 * restore RF properly. If the slowpath sets it for whatever reason, we
293 * SYSRET. This would cause an infinite loop whenever #DB happens 293 * need to restore it correctly.
294 * with register state that satisfies the opportunistic SYSRET 294 *
295 * conditions. For example, single-stepping this user code: 295 * SYSRET can restore TF, but unlike IRET, restoring TF results in a
296 * trap from userspace immediately after SYSRET. This would cause an
297 * infinite loop whenever #DB happens with register state that satisfies
298 * the opportunistic SYSRET conditions. For example, single-stepping
299 * this user code:
296 * 300 *
297 * movq $stuck_here, %rcx 301 * movq $stuck_here, %rcx
298 * pushfq 302 * pushfq
@@ -601,9 +605,20 @@ apicinterrupt3 \num trace(\sym) smp_trace(\sym)
601.endm 605.endm
602#endif 606#endif
603 607
608/* Make sure APIC interrupt handlers end up in the irqentry section: */
609#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
610# define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax"
611# define POP_SECTION_IRQENTRY .popsection
612#else
613# define PUSH_SECTION_IRQENTRY
614# define POP_SECTION_IRQENTRY
615#endif
616
604.macro apicinterrupt num sym do_sym 617.macro apicinterrupt num sym do_sym
618PUSH_SECTION_IRQENTRY
605apicinterrupt3 \num \sym \do_sym 619apicinterrupt3 \num \sym \do_sym
606trace_apicinterrupt \num \sym 620trace_apicinterrupt \num \sym
621POP_SECTION_IRQENTRY
607.endm 622.endm
608 623
609#ifdef CONFIG_SMP 624#ifdef CONFIG_SMP
diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
index 97a69dbba649..9d35ec0cb8fc 100644
--- a/arch/x86/events/intel/uncore_snb.c
+++ b/arch/x86/events/intel/uncore_snb.c
@@ -100,6 +100,12 @@ static void snb_uncore_msr_init_box(struct intel_uncore_box *box)
100 } 100 }
101} 101}
102 102
103static void snb_uncore_msr_enable_box(struct intel_uncore_box *box)
104{
105 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL,
106 SNB_UNC_GLOBAL_CTL_EN | SNB_UNC_GLOBAL_CTL_CORE_ALL);
107}
108
103static void snb_uncore_msr_exit_box(struct intel_uncore_box *box) 109static void snb_uncore_msr_exit_box(struct intel_uncore_box *box)
104{ 110{
105 if (box->pmu->pmu_idx == 0) 111 if (box->pmu->pmu_idx == 0)
@@ -127,6 +133,7 @@ static struct attribute_group snb_uncore_format_group = {
127 133
128static struct intel_uncore_ops snb_uncore_msr_ops = { 134static struct intel_uncore_ops snb_uncore_msr_ops = {
129 .init_box = snb_uncore_msr_init_box, 135 .init_box = snb_uncore_msr_init_box,
136 .enable_box = snb_uncore_msr_enable_box,
130 .exit_box = snb_uncore_msr_exit_box, 137 .exit_box = snb_uncore_msr_exit_box,
131 .disable_event = snb_uncore_msr_disable_event, 138 .disable_event = snb_uncore_msr_disable_event,
132 .enable_event = snb_uncore_msr_enable_event, 139 .enable_event = snb_uncore_msr_enable_event,
@@ -192,6 +199,12 @@ static void skl_uncore_msr_init_box(struct intel_uncore_box *box)
192 } 199 }
193} 200}
194 201
202static void skl_uncore_msr_enable_box(struct intel_uncore_box *box)
203{
204 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL,
205 SNB_UNC_GLOBAL_CTL_EN | SKL_UNC_GLOBAL_CTL_CORE_ALL);
206}
207
195static void skl_uncore_msr_exit_box(struct intel_uncore_box *box) 208static void skl_uncore_msr_exit_box(struct intel_uncore_box *box)
196{ 209{
197 if (box->pmu->pmu_idx == 0) 210 if (box->pmu->pmu_idx == 0)
@@ -200,6 +213,7 @@ static void skl_uncore_msr_exit_box(struct intel_uncore_box *box)
200 213
201static struct intel_uncore_ops skl_uncore_msr_ops = { 214static struct intel_uncore_ops skl_uncore_msr_ops = {
202 .init_box = skl_uncore_msr_init_box, 215 .init_box = skl_uncore_msr_init_box,
216 .enable_box = skl_uncore_msr_enable_box,
203 .exit_box = skl_uncore_msr_exit_box, 217 .exit_box = skl_uncore_msr_exit_box,
204 .disable_event = snb_uncore_msr_disable_event, 218 .disable_event = snb_uncore_msr_disable_event,
205 .enable_event = snb_uncore_msr_enable_event, 219 .enable_event = snb_uncore_msr_enable_event,
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 824e54086e07..8aee83bcf71f 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -2626,7 +2626,7 @@ void hswep_uncore_cpu_init(void)
2626 2626
2627static struct intel_uncore_type hswep_uncore_ha = { 2627static struct intel_uncore_type hswep_uncore_ha = {
2628 .name = "ha", 2628 .name = "ha",
2629 .num_counters = 5, 2629 .num_counters = 4,
2630 .num_boxes = 2, 2630 .num_boxes = 2,
2631 .perf_ctr_bits = 48, 2631 .perf_ctr_bits = 48,
2632 SNBEP_UNCORE_PCI_COMMON_INIT(), 2632 SNBEP_UNCORE_PCI_COMMON_INIT(),
@@ -2645,7 +2645,7 @@ static struct uncore_event_desc hswep_uncore_imc_events[] = {
2645 2645
2646static struct intel_uncore_type hswep_uncore_imc = { 2646static struct intel_uncore_type hswep_uncore_imc = {
2647 .name = "imc", 2647 .name = "imc",
2648 .num_counters = 5, 2648 .num_counters = 4,
2649 .num_boxes = 8, 2649 .num_boxes = 8,
2650 .perf_ctr_bits = 48, 2650 .perf_ctr_bits = 48,
2651 .fixed_ctr_bits = 48, 2651 .fixed_ctr_bits = 48,
@@ -2691,7 +2691,7 @@ static struct intel_uncore_type hswep_uncore_irp = {
2691 2691
2692static struct intel_uncore_type hswep_uncore_qpi = { 2692static struct intel_uncore_type hswep_uncore_qpi = {
2693 .name = "qpi", 2693 .name = "qpi",
2694 .num_counters = 5, 2694 .num_counters = 4,
2695 .num_boxes = 3, 2695 .num_boxes = 3,
2696 .perf_ctr_bits = 48, 2696 .perf_ctr_bits = 48,
2697 .perf_ctr = SNBEP_PCI_PMON_CTR0, 2697 .perf_ctr = SNBEP_PCI_PMON_CTR0,
@@ -2773,7 +2773,7 @@ static struct event_constraint hswep_uncore_r3qpi_constraints[] = {
2773 2773
2774static struct intel_uncore_type hswep_uncore_r3qpi = { 2774static struct intel_uncore_type hswep_uncore_r3qpi = {
2775 .name = "r3qpi", 2775 .name = "r3qpi",
2776 .num_counters = 4, 2776 .num_counters = 3,
2777 .num_boxes = 3, 2777 .num_boxes = 3,
2778 .perf_ctr_bits = 44, 2778 .perf_ctr_bits = 44,
2779 .constraints = hswep_uncore_r3qpi_constraints, 2779 .constraints = hswep_uncore_r3qpi_constraints,
@@ -2972,7 +2972,7 @@ static struct intel_uncore_type bdx_uncore_ha = {
2972 2972
2973static struct intel_uncore_type bdx_uncore_imc = { 2973static struct intel_uncore_type bdx_uncore_imc = {
2974 .name = "imc", 2974 .name = "imc",
2975 .num_counters = 5, 2975 .num_counters = 4,
2976 .num_boxes = 8, 2976 .num_boxes = 8,
2977 .perf_ctr_bits = 48, 2977 .perf_ctr_bits = 48,
2978 .fixed_ctr_bits = 48, 2978 .fixed_ctr_bits = 48,
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index f5befd4945f2..124357773ffa 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -135,6 +135,7 @@ extern void init_apic_mappings(void);
135void register_lapic_address(unsigned long address); 135void register_lapic_address(unsigned long address);
136extern void setup_boot_APIC_clock(void); 136extern void setup_boot_APIC_clock(void);
137extern void setup_secondary_APIC_clock(void); 137extern void setup_secondary_APIC_clock(void);
138extern void lapic_update_tsc_freq(void);
138extern int APIC_init_uniprocessor(void); 139extern int APIC_init_uniprocessor(void);
139 140
140#ifdef CONFIG_X86_64 141#ifdef CONFIG_X86_64
@@ -170,6 +171,7 @@ static inline void init_apic_mappings(void) { }
170static inline void disable_local_APIC(void) { } 171static inline void disable_local_APIC(void) { }
171# define setup_boot_APIC_clock x86_init_noop 172# define setup_boot_APIC_clock x86_init_noop
172# define setup_secondary_APIC_clock x86_init_noop 173# define setup_secondary_APIC_clock x86_init_noop
174static inline void lapic_update_tsc_freq(void) { }
173#endif /* !CONFIG_X86_LOCAL_APIC */ 175#endif /* !CONFIG_X86_LOCAL_APIC */
174 176
175#ifdef CONFIG_X86_X2APIC 177#ifdef CONFIG_X86_X2APIC
diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h
index 7178043b0e1d..59405a248fc2 100644
--- a/arch/x86/include/asm/hardirq.h
+++ b/arch/x86/include/asm/hardirq.h
@@ -22,10 +22,6 @@ typedef struct {
22#ifdef CONFIG_SMP 22#ifdef CONFIG_SMP
23 unsigned int irq_resched_count; 23 unsigned int irq_resched_count;
24 unsigned int irq_call_count; 24 unsigned int irq_call_count;
25 /*
26 * irq_tlb_count is double-counted in irq_call_count, so it must be
27 * subtracted from irq_call_count when displaying irq_call_count
28 */
29 unsigned int irq_tlb_count; 25 unsigned int irq_tlb_count;
30#endif 26#endif
31#ifdef CONFIG_X86_THERMAL_VECTOR 27#ifdef CONFIG_X86_THERMAL_VECTOR
diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h
index 223042086f4e..737da62bfeb0 100644
--- a/arch/x86/include/asm/init.h
+++ b/arch/x86/include/asm/init.h
@@ -5,10 +5,10 @@ struct x86_mapping_info {
5 void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ 5 void *(*alloc_pgt_page)(void *); /* allocate buf for page table */
6 void *context; /* context for alloc_pgt_page */ 6 void *context; /* context for alloc_pgt_page */
7 unsigned long pmd_flag; /* page flag for PMD entry */ 7 unsigned long pmd_flag; /* page flag for PMD entry */
8 bool kernel_mapping; /* kernel mapping or ident mapping */ 8 unsigned long offset; /* ident mapping offset */
9}; 9};
10 10
11int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, 11int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,
12 unsigned long addr, unsigned long end); 12 unsigned long pstart, unsigned long pend);
13 13
14#endif /* _ASM_X86_INIT_H */ 14#endif /* _ASM_X86_INIT_H */
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 7e8ec7ae10fa..1cc82ece9ac1 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -145,7 +145,7 @@ static inline int pgd_large(pgd_t pgd) { return 0; }
145 * 145 *
146 * | ... | 11| 10| 9|8|7|6|5| 4| 3|2|1|0| <- bit number 146 * | ... | 11| 10| 9|8|7|6|5| 4| 3|2|1|0| <- bit number
147 * | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U|W|P| <- bit names 147 * | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U|W|P| <- bit names
148 * | OFFSET (14->63) | TYPE (10-13) |0|X|X|X| X| X|X|X|0| <- swp entry 148 * | OFFSET (14->63) | TYPE (9-13) |0|X|X|X| X| X|X|X|0| <- swp entry
149 * 149 *
150 * G (8) is aliased and used as a PROT_NONE indicator for 150 * G (8) is aliased and used as a PROT_NONE indicator for
151 * !present ptes. We need to start storing swap entries above 151 * !present ptes. We need to start storing swap entries above
@@ -156,7 +156,7 @@ static inline int pgd_large(pgd_t pgd) { return 0; }
156#define SWP_TYPE_FIRST_BIT (_PAGE_BIT_PROTNONE + 1) 156#define SWP_TYPE_FIRST_BIT (_PAGE_BIT_PROTNONE + 1)
157#define SWP_TYPE_BITS 5 157#define SWP_TYPE_BITS 5
158/* Place the offset above the type: */ 158/* Place the offset above the type: */
159#define SWP_OFFSET_FIRST_BIT (SWP_TYPE_FIRST_BIT + SWP_TYPE_BITS + 1) 159#define SWP_OFFSET_FIRST_BIT (SWP_TYPE_FIRST_BIT + SWP_TYPE_BITS)
160 160
161#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS) 161#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
162 162
diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
index 9c6b890d5e7a..b2988c0ed829 100644
--- a/arch/x86/include/asm/realmode.h
+++ b/arch/x86/include/asm/realmode.h
@@ -58,7 +58,15 @@ extern unsigned char boot_gdt[];
58extern unsigned char secondary_startup_64[]; 58extern unsigned char secondary_startup_64[];
59#endif 59#endif
60 60
61static inline size_t real_mode_size_needed(void)
62{
63 if (real_mode_header)
64 return 0; /* already allocated. */
65
66 return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE);
67}
68
69void set_real_mode_mem(phys_addr_t mem, size_t size);
61void reserve_real_mode(void); 70void reserve_real_mode(void);
62void setup_real_mode(void);
63 71
64#endif /* _ARCH_X86_REALMODE_H */ 72#endif /* _ARCH_X86_REALMODE_H */
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 4e5be94e079a..6fa85944af83 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -135,7 +135,14 @@ static inline void cr4_set_bits_and_update_boot(unsigned long mask)
135 135
136static inline void __native_flush_tlb(void) 136static inline void __native_flush_tlb(void)
137{ 137{
138 /*
139 * If current->mm == NULL then we borrow a mm which may change during a
140 * task switch and therefore we must not be preempted while we write CR3
141 * back:
142 */
143 preempt_disable();
138 native_write_cr3(native_read_cr3()); 144 native_write_cr3(native_read_cr3());
145 preempt_enable();
139} 146}
140 147
141static inline void __native_flush_tlb_global_irq_disabled(void) 148static inline void __native_flush_tlb_global_irq_disabled(void)
diff --git a/arch/x86/include/asm/uv/bios.h b/arch/x86/include/asm/uv/bios.h
index c852590254d5..e652a7cc6186 100644
--- a/arch/x86/include/asm/uv/bios.h
+++ b/arch/x86/include/asm/uv/bios.h
@@ -79,7 +79,7 @@ struct uv_gam_range_entry {
79 u16 nasid; /* HNasid */ 79 u16 nasid; /* HNasid */
80 u16 sockid; /* Socket ID, high bits of APIC ID */ 80 u16 sockid; /* Socket ID, high bits of APIC ID */
81 u16 pnode; /* Index to MMR and GRU spaces */ 81 u16 pnode; /* Index to MMR and GRU spaces */
82 u32 pxm; /* ACPI proximity domain number */ 82 u32 unused2;
83 u32 limit; /* PA bits 56:26 (UV_GAM_RANGE_SHFT) */ 83 u32 limit; /* PA bits 56:26 (UV_GAM_RANGE_SHFT) */
84}; 84};
85 85
@@ -88,7 +88,8 @@ struct uv_gam_range_entry {
88#define UV_SYSTAB_VERSION_UV4 0x400 /* UV4 BIOS base version */ 88#define UV_SYSTAB_VERSION_UV4 0x400 /* UV4 BIOS base version */
89#define UV_SYSTAB_VERSION_UV4_1 0x401 /* + gpa_shift */ 89#define UV_SYSTAB_VERSION_UV4_1 0x401 /* + gpa_shift */
90#define UV_SYSTAB_VERSION_UV4_2 0x402 /* + TYPE_NVRAM/WINDOW/MBOX */ 90#define UV_SYSTAB_VERSION_UV4_2 0x402 /* + TYPE_NVRAM/WINDOW/MBOX */
91#define UV_SYSTAB_VERSION_UV4_LATEST UV_SYSTAB_VERSION_UV4_2 91#define UV_SYSTAB_VERSION_UV4_3 0x403 /* - GAM Range PXM Value */
92#define UV_SYSTAB_VERSION_UV4_LATEST UV_SYSTAB_VERSION_UV4_3
92 93
93#define UV_SYSTAB_TYPE_UNUSED 0 /* End of table (offset == 0) */ 94#define UV_SYSTAB_TYPE_UNUSED 0 /* End of table (offset == 0) */
94#define UV_SYSTAB_TYPE_GAM_PARAMS 1 /* GAM PARAM conversions */ 95#define UV_SYSTAB_TYPE_GAM_PARAMS 1 /* GAM PARAM conversions */
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 20abd912f0e4..50c95af0f017 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -313,7 +313,7 @@ int lapic_get_maxlvt(void)
313 313
314/* Clock divisor */ 314/* Clock divisor */
315#define APIC_DIVISOR 16 315#define APIC_DIVISOR 16
316#define TSC_DIVISOR 32 316#define TSC_DIVISOR 8
317 317
318/* 318/*
319 * This function sets up the local APIC timer, with a timeout of 319 * This function sets up the local APIC timer, with a timeout of
@@ -565,13 +565,37 @@ static void setup_APIC_timer(void)
565 CLOCK_EVT_FEAT_DUMMY); 565 CLOCK_EVT_FEAT_DUMMY);
566 levt->set_next_event = lapic_next_deadline; 566 levt->set_next_event = lapic_next_deadline;
567 clockevents_config_and_register(levt, 567 clockevents_config_and_register(levt,
568 (tsc_khz / TSC_DIVISOR) * 1000, 568 tsc_khz * (1000 / TSC_DIVISOR),
569 0xF, ~0UL); 569 0xF, ~0UL);
570 } else 570 } else
571 clockevents_register_device(levt); 571 clockevents_register_device(levt);
572} 572}
573 573
574/* 574/*
575 * Install the updated TSC frequency from recalibration at the TSC
576 * deadline clockevent devices.
577 */
578static void __lapic_update_tsc_freq(void *info)
579{
580 struct clock_event_device *levt = this_cpu_ptr(&lapic_events);
581
582 if (!this_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER))
583 return;
584
585 clockevents_update_freq(levt, tsc_khz * (1000 / TSC_DIVISOR));
586}
587
588void lapic_update_tsc_freq(void)
589{
590 /*
591 * The clockevent device's ->mult and ->shift can both be
592 * changed. In order to avoid races, schedule the frequency
593 * update code on each CPU.
594 */
595 on_each_cpu(__lapic_update_tsc_freq, NULL, 0);
596}
597
598/*
575 * In this functions we calibrate APIC bus clocks to the external timer. 599 * In this functions we calibrate APIC bus clocks to the external timer.
576 * 600 *
577 * We want to do the calibration only once since we want to have local timer 601 * We want to do the calibration only once since we want to have local timer
@@ -1599,6 +1623,9 @@ void __init enable_IR_x2apic(void)
1599 unsigned long flags; 1623 unsigned long flags;
1600 int ret, ir_stat; 1624 int ret, ir_stat;
1601 1625
1626 if (skip_ioapic_setup)
1627 return;
1628
1602 ir_stat = irq_remapping_prepare(); 1629 ir_stat = irq_remapping_prepare();
1603 if (ir_stat < 0 && !x2apic_supported()) 1630 if (ir_stat < 0 && !x2apic_supported())
1604 return; 1631 return;
diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
index 6368fa69d2af..54f35d988025 100644
--- a/arch/x86/kernel/apic/x2apic_cluster.c
+++ b/arch/x86/kernel/apic/x2apic_cluster.c
@@ -155,7 +155,7 @@ static void init_x2apic_ldr(void)
155/* 155/*
156 * At CPU state changes, update the x2apic cluster sibling info. 156 * At CPU state changes, update the x2apic cluster sibling info.
157 */ 157 */
158int x2apic_prepare_cpu(unsigned int cpu) 158static int x2apic_prepare_cpu(unsigned int cpu)
159{ 159{
160 if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL)) 160 if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL))
161 return -ENOMEM; 161 return -ENOMEM;
@@ -168,7 +168,7 @@ int x2apic_prepare_cpu(unsigned int cpu)
168 return 0; 168 return 0;
169} 169}
170 170
171int x2apic_dead_cpu(unsigned int this_cpu) 171static int x2apic_dead_cpu(unsigned int this_cpu)
172{ 172{
173 int cpu; 173 int cpu;
174 174
@@ -186,13 +186,18 @@ int x2apic_dead_cpu(unsigned int this_cpu)
186static int x2apic_cluster_probe(void) 186static int x2apic_cluster_probe(void)
187{ 187{
188 int cpu = smp_processor_id(); 188 int cpu = smp_processor_id();
189 int ret;
189 190
190 if (!x2apic_mode) 191 if (!x2apic_mode)
191 return 0; 192 return 0;
192 193
194 ret = cpuhp_setup_state(CPUHP_X2APIC_PREPARE, "X2APIC_PREPARE",
195 x2apic_prepare_cpu, x2apic_dead_cpu);
196 if (ret < 0) {
197 pr_err("Failed to register X2APIC_PREPARE\n");
198 return 0;
199 }
193 cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu)); 200 cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu));
194 cpuhp_setup_state(CPUHP_X2APIC_PREPARE, "X2APIC_PREPARE",
195 x2apic_prepare_cpu, x2apic_dead_cpu);
196 return 1; 201 return 1;
197} 202}
198 203
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 09b59adaea3f..cb0673c1e940 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -223,6 +223,11 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
223 if (strncmp(oem_id, "SGI", 3) != 0) 223 if (strncmp(oem_id, "SGI", 3) != 0)
224 return 0; 224 return 0;
225 225
226 if (numa_off) {
227 pr_err("UV: NUMA is off, disabling UV support\n");
228 return 0;
229 }
230
226 /* Setup early hub type field in uv_hub_info for Node 0 */ 231 /* Setup early hub type field in uv_hub_info for Node 0 */
227 uv_cpu_info->p_uv_hub_info = &uv_hub_info_node0; 232 uv_cpu_info->p_uv_hub_info = &uv_hub_info_node0;
228 233
@@ -325,7 +330,7 @@ static __init void build_uv_gr_table(void)
325 struct uv_gam_range_entry *gre = uv_gre_table; 330 struct uv_gam_range_entry *gre = uv_gre_table;
326 struct uv_gam_range_s *grt; 331 struct uv_gam_range_s *grt;
327 unsigned long last_limit = 0, ram_limit = 0; 332 unsigned long last_limit = 0, ram_limit = 0;
328 int bytes, i, sid, lsid = -1; 333 int bytes, i, sid, lsid = -1, indx = 0, lindx = -1;
329 334
330 if (!gre) 335 if (!gre)
331 return; 336 return;
@@ -356,11 +361,12 @@ static __init void build_uv_gr_table(void)
356 } 361 }
357 sid = gre->sockid - _min_socket; 362 sid = gre->sockid - _min_socket;
358 if (lsid < sid) { /* new range */ 363 if (lsid < sid) { /* new range */
359 grt = &_gr_table[sid]; 364 grt = &_gr_table[indx];
360 grt->base = lsid; 365 grt->base = lindx;
361 grt->nasid = gre->nasid; 366 grt->nasid = gre->nasid;
362 grt->limit = last_limit = gre->limit; 367 grt->limit = last_limit = gre->limit;
363 lsid = sid; 368 lsid = sid;
369 lindx = indx++;
364 continue; 370 continue;
365 } 371 }
366 if (lsid == sid && !ram_limit) { /* update range */ 372 if (lsid == sid && !ram_limit) { /* update range */
@@ -371,7 +377,7 @@ static __init void build_uv_gr_table(void)
371 } 377 }
372 if (!ram_limit) { /* non-contiguous ram range */ 378 if (!ram_limit) { /* non-contiguous ram range */
373 grt++; 379 grt++;
374 grt->base = sid - 1; 380 grt->base = lindx;
375 grt->nasid = gre->nasid; 381 grt->nasid = gre->nasid;
376 grt->limit = last_limit = gre->limit; 382 grt->limit = last_limit = gre->limit;
377 continue; 383 continue;
@@ -1155,19 +1161,18 @@ static void __init decode_gam_rng_tbl(unsigned long ptr)
1155 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) { 1161 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
1156 if (!index) { 1162 if (!index) {
1157 pr_info("UV: GAM Range Table...\n"); 1163 pr_info("UV: GAM Range Table...\n");
1158 pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s %3s\n", 1164 pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s\n",
1159 "Range", "", "Size", "Type", "NASID", 1165 "Range", "", "Size", "Type", "NASID",
1160 "SID", "PN", "PXM"); 1166 "SID", "PN");
1161 } 1167 }
1162 pr_info( 1168 pr_info(
1163 "UV: %2d: 0x%014lx-0x%014lx %5luG %3d %04x %02x %02x %3d\n", 1169 "UV: %2d: 0x%014lx-0x%014lx %5luG %3d %04x %02x %02x\n",
1164 index++, 1170 index++,
1165 (unsigned long)lgre << UV_GAM_RANGE_SHFT, 1171 (unsigned long)lgre << UV_GAM_RANGE_SHFT,
1166 (unsigned long)gre->limit << UV_GAM_RANGE_SHFT, 1172 (unsigned long)gre->limit << UV_GAM_RANGE_SHFT,
1167 ((unsigned long)(gre->limit - lgre)) >> 1173 ((unsigned long)(gre->limit - lgre)) >>
1168 (30 - UV_GAM_RANGE_SHFT), /* 64M -> 1G */ 1174 (30 - UV_GAM_RANGE_SHFT), /* 64M -> 1G */
1169 gre->type, gre->nasid, gre->sockid, 1175 gre->type, gre->nasid, gre->sockid, gre->pnode);
1170 gre->pnode, gre->pxm);
1171 1176
1172 lgre = gre->limit; 1177 lgre = gre->limit;
1173 if (sock_min > gre->sockid) 1178 if (sock_min > gre->sockid)
@@ -1286,7 +1291,7 @@ static void __init build_socket_tables(void)
1286 _pnode_to_socket[i] = SOCK_EMPTY; 1291 _pnode_to_socket[i] = SOCK_EMPTY;
1287 1292
1288 /* fill in pnode/node/addr conversion list values */ 1293 /* fill in pnode/node/addr conversion list values */
1289 pr_info("UV: GAM Building socket/pnode/pxm conversion tables\n"); 1294 pr_info("UV: GAM Building socket/pnode conversion tables\n");
1290 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) { 1295 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
1291 if (gre->type == UV_GAM_RANGE_TYPE_HOLE) 1296 if (gre->type == UV_GAM_RANGE_TYPE_HOLE)
1292 continue; 1297 continue;
@@ -1294,20 +1299,18 @@ static void __init build_socket_tables(void)
1294 if (_socket_to_pnode[i] != SOCK_EMPTY) 1299 if (_socket_to_pnode[i] != SOCK_EMPTY)
1295 continue; /* duplicate */ 1300 continue; /* duplicate */
1296 _socket_to_pnode[i] = gre->pnode; 1301 _socket_to_pnode[i] = gre->pnode;
1297 _socket_to_node[i] = gre->pxm;
1298 1302
1299 i = gre->pnode - minpnode; 1303 i = gre->pnode - minpnode;
1300 _pnode_to_socket[i] = gre->sockid; 1304 _pnode_to_socket[i] = gre->sockid;
1301 1305
1302 pr_info( 1306 pr_info(
1303 "UV: sid:%02x type:%d nasid:%04x pn:%02x pxm:%2d pn2s:%2x\n", 1307 "UV: sid:%02x type:%d nasid:%04x pn:%02x pn2s:%2x\n",
1304 gre->sockid, gre->type, gre->nasid, 1308 gre->sockid, gre->type, gre->nasid,
1305 _socket_to_pnode[gre->sockid - minsock], 1309 _socket_to_pnode[gre->sockid - minsock],
1306 _socket_to_node[gre->sockid - minsock],
1307 _pnode_to_socket[gre->pnode - minpnode]); 1310 _pnode_to_socket[gre->pnode - minpnode]);
1308 } 1311 }
1309 1312
1310 /* check socket -> node values */ 1313 /* Set socket -> node values */
1311 lnid = -1; 1314 lnid = -1;
1312 for_each_present_cpu(cpu) { 1315 for_each_present_cpu(cpu) {
1313 int nid = cpu_to_node(cpu); 1316 int nid = cpu_to_node(cpu);
@@ -1318,14 +1321,9 @@ static void __init build_socket_tables(void)
1318 lnid = nid; 1321 lnid = nid;
1319 apicid = per_cpu(x86_cpu_to_apicid, cpu); 1322 apicid = per_cpu(x86_cpu_to_apicid, cpu);
1320 sockid = apicid >> uv_cpuid.socketid_shift; 1323 sockid = apicid >> uv_cpuid.socketid_shift;
1321 i = sockid - minsock; 1324 _socket_to_node[sockid - minsock] = nid;
1322 1325 pr_info("UV: sid:%02x: apicid:%04x node:%2d\n",
1323 if (nid != _socket_to_node[i]) { 1326 sockid, apicid, nid);
1324 pr_warn(
1325 "UV: %02x: type:%d socket:%02x PXM:%02x != node:%2d\n",
1326 i, sockid, gre->type, _socket_to_node[i], nid);
1327 _socket_to_node[i] = nid;
1328 }
1329 } 1327 }
1330 1328
1331 /* Setup physical blade to pnode translation from GAM Range Table */ 1329 /* Setup physical blade to pnode translation from GAM Range Table */
diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 27a0228c9cae..b816971f5da4 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -355,6 +355,7 @@ void load_ucode_amd_ap(void)
355 unsigned int cpu = smp_processor_id(); 355 unsigned int cpu = smp_processor_id();
356 struct equiv_cpu_entry *eq; 356 struct equiv_cpu_entry *eq;
357 struct microcode_amd *mc; 357 struct microcode_amd *mc;
358 u8 *cont = container;
358 u32 rev, eax; 359 u32 rev, eax;
359 u16 eq_id; 360 u16 eq_id;
360 361
@@ -371,8 +372,11 @@ void load_ucode_amd_ap(void)
371 if (check_current_patch_level(&rev, false)) 372 if (check_current_patch_level(&rev, false))
372 return; 373 return;
373 374
375 /* Add CONFIG_RANDOMIZE_MEMORY offset. */
376 cont += PAGE_OFFSET - __PAGE_OFFSET_BASE;
377
374 eax = cpuid_eax(0x00000001); 378 eax = cpuid_eax(0x00000001);
375 eq = (struct equiv_cpu_entry *)(container + CONTAINER_HDR_SZ); 379 eq = (struct equiv_cpu_entry *)(cont + CONTAINER_HDR_SZ);
376 380
377 eq_id = find_equiv_id(eq, eax); 381 eq_id = find_equiv_id(eq, eax);
378 if (!eq_id) 382 if (!eq_id)
@@ -434,6 +438,9 @@ int __init save_microcode_in_initrd_amd(void)
434 else 438 else
435 container = cont_va; 439 container = cont_va;
436 440
441 /* Add CONFIG_RANDOMIZE_MEMORY offset. */
442 container += PAGE_OFFSET - __PAGE_OFFSET_BASE;
443
437 eax = cpuid_eax(0x00000001); 444 eax = cpuid_eax(0x00000001);
438 eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); 445 eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff);
439 446
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 680049aa4593..01567aa87503 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -866,105 +866,17 @@ const void *get_xsave_field_ptr(int xsave_state)
866 return get_xsave_addr(&fpu->state.xsave, xsave_state); 866 return get_xsave_addr(&fpu->state.xsave, xsave_state);
867} 867}
868 868
869
870/*
871 * Set xfeatures (aka XSTATE_BV) bit for a feature that we want
872 * to take out of its "init state". This will ensure that an
873 * XRSTOR actually restores the state.
874 */
875static void fpu__xfeature_set_non_init(struct xregs_state *xsave,
876 int xstate_feature_mask)
877{
878 xsave->header.xfeatures |= xstate_feature_mask;
879}
880
881/*
882 * This function is safe to call whether the FPU is in use or not.
883 *
884 * Note that this only works on the current task.
885 *
886 * Inputs:
887 * @xsave_state: state which is defined in xsave.h (e.g. XFEATURE_MASK_FP,
888 * XFEATURE_MASK_SSE, etc...)
889 * @xsave_state_ptr: a pointer to a copy of the state that you would
890 * like written in to the current task's FPU xsave state. This pointer
891 * must not be located in the current tasks's xsave area.
892 * Output:
893 * address of the state in the xsave area or NULL if the state
894 * is not present or is in its 'init state'.
895 */
896static void fpu__xfeature_set_state(int xstate_feature_mask,
897 void *xstate_feature_src, size_t len)
898{
899 struct xregs_state *xsave = &current->thread.fpu.state.xsave;
900 struct fpu *fpu = &current->thread.fpu;
901 void *dst;
902
903 if (!boot_cpu_has(X86_FEATURE_XSAVE)) {
904 WARN_ONCE(1, "%s() attempted with no xsave support", __func__);
905 return;
906 }
907
908 /*
909 * Tell the FPU code that we need the FPU state to be in
910 * 'fpu' (not in the registers), and that we need it to
911 * be stable while we write to it.
912 */
913 fpu__current_fpstate_write_begin();
914
915 /*
916 * This method *WILL* *NOT* work for compact-format
917 * buffers. If the 'xstate_feature_mask' is unset in
918 * xcomp_bv then we may need to move other feature state
919 * "up" in the buffer.
920 */
921 if (xsave->header.xcomp_bv & xstate_feature_mask) {
922 WARN_ON_ONCE(1);
923 goto out;
924 }
925
926 /* find the location in the xsave buffer of the desired state */
927 dst = __raw_xsave_addr(&fpu->state.xsave, xstate_feature_mask);
928
929 /*
930 * Make sure that the pointer being passed in did not
931 * come from the xsave buffer itself.
932 */
933 WARN_ONCE(xstate_feature_src == dst, "set from xsave buffer itself");
934
935 /* put the caller-provided data in the location */
936 memcpy(dst, xstate_feature_src, len);
937
938 /*
939 * Mark the xfeature so that the CPU knows there is state
940 * in the buffer now.
941 */
942 fpu__xfeature_set_non_init(xsave, xstate_feature_mask);
943out:
944 /*
945 * We are done writing to the 'fpu'. Reenable preeption
946 * and (possibly) move the fpstate back in to the fpregs.
947 */
948 fpu__current_fpstate_write_end();
949}
950
951#define NR_VALID_PKRU_BITS (CONFIG_NR_PROTECTION_KEYS * 2) 869#define NR_VALID_PKRU_BITS (CONFIG_NR_PROTECTION_KEYS * 2)
952#define PKRU_VALID_MASK (NR_VALID_PKRU_BITS - 1) 870#define PKRU_VALID_MASK (NR_VALID_PKRU_BITS - 1)
953 871
954/* 872/*
955 * This will go out and modify the XSAVE buffer so that PKRU is 873 * This will go out and modify PKRU register to set the access
956 * set to a particular state for access to 'pkey'. 874 * rights for @pkey to @init_val.
957 *
958 * PKRU state does affect kernel access to user memory. We do
959 * not modfiy PKRU *itself* here, only the XSAVE state that will
960 * be restored in to PKRU when we return back to userspace.
961 */ 875 */
962int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, 876int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
963 unsigned long init_val) 877 unsigned long init_val)
964{ 878{
965 struct xregs_state *xsave = &tsk->thread.fpu.state.xsave; 879 u32 old_pkru;
966 struct pkru_state *old_pkru_state;
967 struct pkru_state new_pkru_state;
968 int pkey_shift = (pkey * PKRU_BITS_PER_PKEY); 880 int pkey_shift = (pkey * PKRU_BITS_PER_PKEY);
969 u32 new_pkru_bits = 0; 881 u32 new_pkru_bits = 0;
970 882
@@ -974,6 +886,15 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
974 */ 886 */
975 if (!boot_cpu_has(X86_FEATURE_OSPKE)) 887 if (!boot_cpu_has(X86_FEATURE_OSPKE))
976 return -EINVAL; 888 return -EINVAL;
889 /*
890 * For most XSAVE components, this would be an arduous task:
891 * brining fpstate up to date with fpregs, updating fpstate,
892 * then re-populating fpregs. But, for components that are
893 * never lazily managed, we can just access the fpregs
894 * directly. PKRU is never managed lazily, so we can just
895 * manipulate it directly. Make sure it stays that way.
896 */
897 WARN_ON_ONCE(!use_eager_fpu());
977 898
978 /* Set the bits we need in PKRU: */ 899 /* Set the bits we need in PKRU: */
979 if (init_val & PKEY_DISABLE_ACCESS) 900 if (init_val & PKEY_DISABLE_ACCESS)
@@ -984,37 +905,12 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
984 /* Shift the bits in to the correct place in PKRU for pkey: */ 905 /* Shift the bits in to the correct place in PKRU for pkey: */
985 new_pkru_bits <<= pkey_shift; 906 new_pkru_bits <<= pkey_shift;
986 907
987 /* Locate old copy of the state in the xsave buffer: */ 908 /* Get old PKRU and mask off any old bits in place: */
988 old_pkru_state = get_xsave_addr(xsave, XFEATURE_MASK_PKRU); 909 old_pkru = read_pkru();
989 910 old_pkru &= ~((PKRU_AD_BIT|PKRU_WD_BIT) << pkey_shift);
990 /*
991 * When state is not in the buffer, it is in the init
992 * state, set it manually. Otherwise, copy out the old
993 * state.
994 */
995 if (!old_pkru_state)
996 new_pkru_state.pkru = 0;
997 else
998 new_pkru_state.pkru = old_pkru_state->pkru;
999
1000 /* Mask off any old bits in place: */
1001 new_pkru_state.pkru &= ~((PKRU_AD_BIT|PKRU_WD_BIT) << pkey_shift);
1002
1003 /* Set the newly-requested bits: */
1004 new_pkru_state.pkru |= new_pkru_bits;
1005
1006 /*
1007 * We could theoretically live without zeroing pkru.pad.
1008 * The current XSAVE feature state definition says that
1009 * only bytes 0->3 are used. But we do not want to
1010 * chance leaking kernel stack out to userspace in case a
1011 * memcpy() of the whole xsave buffer was done.
1012 *
1013 * They're in the same cacheline anyway.
1014 */
1015 new_pkru_state.pad = 0;
1016 911
1017 fpu__xfeature_set_state(XFEATURE_MASK_PKRU, &new_pkru_state, sizeof(new_pkru_state)); 912 /* Write old part along with new part: */
913 write_pkru(old_pkru | new_pkru_bits);
1018 914
1019 return 0; 915 return 0;
1020} 916}
diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
index 2dda0bc4576e..f16c55bfc090 100644
--- a/arch/x86/kernel/head32.c
+++ b/arch/x86/kernel/head32.c
@@ -25,8 +25,6 @@ static void __init i386_default_early_setup(void)
25 /* Initialize 32bit specific setup functions */ 25 /* Initialize 32bit specific setup functions */
26 x86_init.resources.reserve_resources = i386_reserve_resources; 26 x86_init.resources.reserve_resources = i386_reserve_resources;
27 x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc; 27 x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
28
29 reserve_bios_regions();
30} 28}
31 29
32asmlinkage __visible void __init i386_start_kernel(void) 30asmlinkage __visible void __init i386_start_kernel(void)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 99d48e7d2974..54a2372f5dbb 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -183,7 +183,6 @@ void __init x86_64_start_reservations(char *real_mode_data)
183 copy_bootdata(__va(real_mode_data)); 183 copy_bootdata(__va(real_mode_data));
184 184
185 x86_early_init_platform_quirks(); 185 x86_early_init_platform_quirks();
186 reserve_bios_regions();
187 186
188 switch (boot_params.hdr.hardware_subarch) { 187 switch (boot_params.hdr.hardware_subarch) {
189 case X86_SUBARCH_INTEL_MID: 188 case X86_SUBARCH_INTEL_MID:
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index ed16e58658a4..c6dfd801df97 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -1242,7 +1242,7 @@ irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
1242 memset(&curr_time, 0, sizeof(struct rtc_time)); 1242 memset(&curr_time, 0, sizeof(struct rtc_time));
1243 1243
1244 if (hpet_rtc_flags & (RTC_UIE | RTC_AIE)) 1244 if (hpet_rtc_flags & (RTC_UIE | RTC_AIE))
1245 mc146818_set_time(&curr_time); 1245 mc146818_get_time(&curr_time);
1246 1246
1247 if (hpet_rtc_flags & RTC_UIE && 1247 if (hpet_rtc_flags & RTC_UIE &&
1248 curr_time.tm_sec != hpet_prev_update_sec) { 1248 curr_time.tm_sec != hpet_prev_update_sec) {
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index 61521dc19c10..9f669fdd2010 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -102,8 +102,7 @@ int arch_show_interrupts(struct seq_file *p, int prec)
102 seq_puts(p, " Rescheduling interrupts\n"); 102 seq_puts(p, " Rescheduling interrupts\n");
103 seq_printf(p, "%*s: ", prec, "CAL"); 103 seq_printf(p, "%*s: ", prec, "CAL");
104 for_each_online_cpu(j) 104 for_each_online_cpu(j)
105 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count - 105 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
106 irq_stats(j)->irq_tlb_count);
107 seq_puts(p, " Function call interrupts\n"); 106 seq_puts(p, " Function call interrupts\n");
108 seq_printf(p, "%*s: ", prec, "TLB"); 107 seq_printf(p, "%*s: ", prec, "TLB");
109 for_each_online_cpu(j) 108 for_each_online_cpu(j)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 991b77986d57..0fa60f5f5a16 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p)
936 936
937 x86_init.oem.arch_setup(); 937 x86_init.oem.arch_setup();
938 938
939 kernel_randomize_memory();
940
941 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 939 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
942 setup_memory_map(); 940 setup_memory_map();
943 parse_setup_data(); 941 parse_setup_data();
@@ -1055,6 +1053,12 @@ void __init setup_arch(char **cmdline_p)
1055 1053
1056 max_possible_pfn = max_pfn; 1054 max_possible_pfn = max_pfn;
1057 1055
1056 /*
1057 * Define random base addresses for memory sections after max_pfn is
1058 * defined and before each memory section base is used.
1059 */
1060 kernel_randomize_memory();
1061
1058#ifdef CONFIG_X86_32 1062#ifdef CONFIG_X86_32
1059 /* max_low_pfn get updated here */ 1063 /* max_low_pfn get updated here */
1060 find_low_pfn_range(); 1064 find_low_pfn_range();
@@ -1097,6 +1101,8 @@ void __init setup_arch(char **cmdline_p)
1097 efi_find_mirror(); 1101 efi_find_mirror();
1098 } 1102 }
1099 1103
1104 reserve_bios_regions();
1105
1100 /* 1106 /*
1101 * The EFI specification says that boot service code won't be called 1107 * The EFI specification says that boot service code won't be called
1102 * after ExitBootServices(). This is, in fact, a lie. 1108 * after ExitBootServices(). This is, in fact, a lie.
@@ -1125,7 +1131,15 @@ void __init setup_arch(char **cmdline_p)
1125 1131
1126 early_trap_pf_init(); 1132 early_trap_pf_init();
1127 1133
1128 setup_real_mode(); 1134 /*
1135 * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features)
1136 * with the current CR4 value. This may not be necessary, but
1137 * auditing all the early-boot CR4 manipulation would be needed to
1138 * rule it out.
1139 */
1140 if (boot_cpu_data.cpuid_level >= 0)
1141 /* A CPU has %cr4 if and only if it has CPUID. */
1142 mmu_cr4_features = __read_cr4();
1129 1143
1130 memblock_set_current_limit(get_max_mapped()); 1144 memblock_set_current_limit(get_max_mapped());
1131 1145
@@ -1174,13 +1188,6 @@ void __init setup_arch(char **cmdline_p)
1174 1188
1175 kasan_init(); 1189 kasan_init();
1176 1190
1177 if (boot_cpu_data.cpuid_level >= 0) {
1178 /* A CPU has %cr4 if and only if it has CPUID */
1179 mmu_cr4_features = __read_cr4();
1180 if (trampoline_cr4_features)
1181 *trampoline_cr4_features = mmu_cr4_features;
1182 }
1183
1184#ifdef CONFIG_X86_32 1191#ifdef CONFIG_X86_32
1185 /* sync back kernel address range */ 1192 /* sync back kernel address range */
1186 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY, 1193 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 067de612d3fa..26b473dc3f82 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -100,10 +100,11 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
100/* Logical package management. We might want to allocate that dynamically */ 100/* Logical package management. We might want to allocate that dynamically */
101static int *physical_to_logical_pkg __read_mostly; 101static int *physical_to_logical_pkg __read_mostly;
102static unsigned long *physical_package_map __read_mostly;; 102static unsigned long *physical_package_map __read_mostly;;
103static unsigned long *logical_package_map __read_mostly;
104static unsigned int max_physical_pkg_id __read_mostly; 103static unsigned int max_physical_pkg_id __read_mostly;
105unsigned int __max_logical_packages __read_mostly; 104unsigned int __max_logical_packages __read_mostly;
106EXPORT_SYMBOL(__max_logical_packages); 105EXPORT_SYMBOL(__max_logical_packages);
106static unsigned int logical_packages __read_mostly;
107static bool logical_packages_frozen __read_mostly;
107 108
108/* Maximum number of SMT threads on any online core */ 109/* Maximum number of SMT threads on any online core */
109int __max_smt_threads __read_mostly; 110int __max_smt_threads __read_mostly;
@@ -277,14 +278,14 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu)
277 if (test_and_set_bit(pkg, physical_package_map)) 278 if (test_and_set_bit(pkg, physical_package_map))
278 goto found; 279 goto found;
279 280
280 new = find_first_zero_bit(logical_package_map, __max_logical_packages); 281 if (logical_packages_frozen) {
281 if (new >= __max_logical_packages) {
282 physical_to_logical_pkg[pkg] = -1; 282 physical_to_logical_pkg[pkg] = -1;
283 pr_warn("APIC(%x) Package %u exceeds logical package map\n", 283 pr_warn("APIC(%x) Package %u exceeds logical package max\n",
284 apicid, pkg); 284 apicid, pkg);
285 return -ENOSPC; 285 return -ENOSPC;
286 } 286 }
287 set_bit(new, logical_package_map); 287
288 new = logical_packages++;
288 pr_info("APIC(%x) Converting physical %u to logical package %u\n", 289 pr_info("APIC(%x) Converting physical %u to logical package %u\n",
289 apicid, pkg, new); 290 apicid, pkg, new);
290 physical_to_logical_pkg[pkg] = new; 291 physical_to_logical_pkg[pkg] = new;
@@ -341,6 +342,7 @@ static void __init smp_init_package_map(void)
341 } 342 }
342 343
343 __max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus); 344 __max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus);
345 logical_packages = 0;
344 346
345 /* 347 /*
346 * Possibly larger than what we need as the number of apic ids per 348 * Possibly larger than what we need as the number of apic ids per
@@ -352,10 +354,6 @@ static void __init smp_init_package_map(void)
352 memset(physical_to_logical_pkg, 0xff, size); 354 memset(physical_to_logical_pkg, 0xff, size);
353 size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long); 355 size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long);
354 physical_package_map = kzalloc(size, GFP_KERNEL); 356 physical_package_map = kzalloc(size, GFP_KERNEL);
355 size = BITS_TO_LONGS(__max_logical_packages) * sizeof(unsigned long);
356 logical_package_map = kzalloc(size, GFP_KERNEL);
357
358 pr_info("Max logical packages: %u\n", __max_logical_packages);
359 357
360 for_each_present_cpu(cpu) { 358 for_each_present_cpu(cpu) {
361 unsigned int apicid = apic->cpu_present_to_apicid(cpu); 359 unsigned int apicid = apic->cpu_present_to_apicid(cpu);
@@ -369,6 +367,15 @@ static void __init smp_init_package_map(void)
369 set_cpu_possible(cpu, false); 367 set_cpu_possible(cpu, false);
370 set_cpu_present(cpu, false); 368 set_cpu_present(cpu, false);
371 } 369 }
370
371 if (logical_packages > __max_logical_packages) {
372 pr_warn("Detected more packages (%u), then computed by BIOS data (%u).\n",
373 logical_packages, __max_logical_packages);
374 logical_packages_frozen = true;
375 __max_logical_packages = logical_packages;
376 }
377
378 pr_info("Max logical packages: %u\n", __max_logical_packages);
372} 379}
373 380
374void __init smp_store_boot_cpu_info(void) 381void __init smp_store_boot_cpu_info(void)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 1ef87e887051..78b9cb5a26af 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -22,6 +22,7 @@
22#include <asm/nmi.h> 22#include <asm/nmi.h>
23#include <asm/x86_init.h> 23#include <asm/x86_init.h>
24#include <asm/geode.h> 24#include <asm/geode.h>
25#include <asm/apic.h>
25 26
26unsigned int __read_mostly cpu_khz; /* TSC clocks / usec, not used here */ 27unsigned int __read_mostly cpu_khz; /* TSC clocks / usec, not used here */
27EXPORT_SYMBOL(cpu_khz); 28EXPORT_SYMBOL(cpu_khz);
@@ -1249,6 +1250,9 @@ static void tsc_refine_calibration_work(struct work_struct *work)
1249 (unsigned long)tsc_khz / 1000, 1250 (unsigned long)tsc_khz / 1000,
1250 (unsigned long)tsc_khz % 1000); 1251 (unsigned long)tsc_khz % 1000);
1251 1252
1253 /* Inform the TSC deadline clockevent devices about the recalibration */
1254 lapic_update_tsc_freq();
1255
1252out: 1256out:
1253 if (boot_cpu_has(X86_FEATURE_ART)) 1257 if (boot_cpu_has(X86_FEATURE_ART))
1254 art_related_clocksource = &clocksource_tsc; 1258 art_related_clocksource = &clocksource_tsc;
diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 6c1ff31d99ff..495c776de4b4 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -357,20 +357,22 @@ static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn)
357 *cursor &= 0xfe; 357 *cursor &= 0xfe;
358 } 358 }
359 /* 359 /*
360 * Similar treatment for VEX3 prefix. 360 * Similar treatment for VEX3/EVEX prefix.
361 * TODO: add XOP/EVEX treatment when insn decoder supports them 361 * TODO: add XOP treatment when insn decoder supports them
362 */ 362 */
363 if (insn->vex_prefix.nbytes == 3) { 363 if (insn->vex_prefix.nbytes >= 3) {
364 /* 364 /*
365 * vex2: c5 rvvvvLpp (has no b bit) 365 * vex2: c5 rvvvvLpp (has no b bit)
366 * vex3/xop: c4/8f rxbmmmmm wvvvvLpp 366 * vex3/xop: c4/8f rxbmmmmm wvvvvLpp
367 * evex: 62 rxbR00mm wvvvv1pp zllBVaaa 367 * evex: 62 rxbR00mm wvvvv1pp zllBVaaa
368 * (evex will need setting of both b and x since 368 * Setting VEX3.b (setting because it has inverted meaning).
369 * in non-sib encoding evex.x is 4th bit of MODRM.rm) 369 * Setting EVEX.x since (in non-SIB encoding) EVEX.x
370 * Setting VEX3.b (setting because it has inverted meaning): 370 * is the 4th bit of MODRM.rm, and needs the same treatment.
371 * For VEX3-encoded insns, VEX3.x value has no effect in
372 * non-SIB encoding, the change is superfluous but harmless.
371 */ 373 */
372 cursor = auprobe->insn + insn_offset_vex_prefix(insn) + 1; 374 cursor = auprobe->insn + insn_offset_vex_prefix(insn) + 1;
373 *cursor |= 0x20; 375 *cursor |= 0x60;
374 } 376 }
375 377
376 /* 378 /*
@@ -415,12 +417,10 @@ static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn)
415 417
416 reg = MODRM_REG(insn); /* Fetch modrm.reg */ 418 reg = MODRM_REG(insn); /* Fetch modrm.reg */
417 reg2 = 0xff; /* Fetch vex.vvvv */ 419 reg2 = 0xff; /* Fetch vex.vvvv */
418 if (insn->vex_prefix.nbytes == 2) 420 if (insn->vex_prefix.nbytes)
419 reg2 = insn->vex_prefix.bytes[1];
420 else if (insn->vex_prefix.nbytes == 3)
421 reg2 = insn->vex_prefix.bytes[2]; 421 reg2 = insn->vex_prefix.bytes[2];
422 /* 422 /*
423 * TODO: add XOP, EXEV vvvv reading. 423 * TODO: add XOP vvvv reading.
424 * 424 *
425 * vex.vvvv field is in bits 6-3, bits are inverted. 425 * vex.vvvv field is in bits 6-3, bits are inverted.
426 * But in 32-bit mode, high-order bit may be ignored. 426 * But in 32-bit mode, high-order bit may be ignored.
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index a45d8580f91e..5cede40e2552 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -422,6 +422,7 @@ struct nested_vmx {
422 struct list_head vmcs02_pool; 422 struct list_head vmcs02_pool;
423 int vmcs02_num; 423 int vmcs02_num;
424 u64 vmcs01_tsc_offset; 424 u64 vmcs01_tsc_offset;
425 bool change_vmcs01_virtual_x2apic_mode;
425 /* L2 must run next, and mustn't decide to exit to L1. */ 426 /* L2 must run next, and mustn't decide to exit to L1. */
426 bool nested_run_pending; 427 bool nested_run_pending;
427 /* 428 /*
@@ -435,6 +436,8 @@ struct nested_vmx {
435 bool pi_pending; 436 bool pi_pending;
436 u16 posted_intr_nv; 437 u16 posted_intr_nv;
437 438
439 unsigned long *msr_bitmap;
440
438 struct hrtimer preemption_timer; 441 struct hrtimer preemption_timer;
439 bool preemption_timer_expired; 442 bool preemption_timer_expired;
440 443
@@ -924,7 +927,6 @@ static unsigned long *vmx_msr_bitmap_legacy;
924static unsigned long *vmx_msr_bitmap_longmode; 927static unsigned long *vmx_msr_bitmap_longmode;
925static unsigned long *vmx_msr_bitmap_legacy_x2apic; 928static unsigned long *vmx_msr_bitmap_legacy_x2apic;
926static unsigned long *vmx_msr_bitmap_longmode_x2apic; 929static unsigned long *vmx_msr_bitmap_longmode_x2apic;
927static unsigned long *vmx_msr_bitmap_nested;
928static unsigned long *vmx_vmread_bitmap; 930static unsigned long *vmx_vmread_bitmap;
929static unsigned long *vmx_vmwrite_bitmap; 931static unsigned long *vmx_vmwrite_bitmap;
930 932
@@ -2198,6 +2200,12 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
2198 new.control) != old.control); 2200 new.control) != old.control);
2199} 2201}
2200 2202
2203static void decache_tsc_multiplier(struct vcpu_vmx *vmx)
2204{
2205 vmx->current_tsc_ratio = vmx->vcpu.arch.tsc_scaling_ratio;
2206 vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio);
2207}
2208
2201/* 2209/*
2202 * Switches to specified vcpu, until a matching vcpu_put(), but assumes 2210 * Switches to specified vcpu, until a matching vcpu_put(), but assumes
2203 * vcpu mutex is already taken. 2211 * vcpu mutex is already taken.
@@ -2256,10 +2264,8 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
2256 2264
2257 /* Setup TSC multiplier */ 2265 /* Setup TSC multiplier */
2258 if (kvm_has_tsc_control && 2266 if (kvm_has_tsc_control &&
2259 vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) { 2267 vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio)
2260 vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio; 2268 decache_tsc_multiplier(vmx);
2261 vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio);
2262 }
2263 2269
2264 vmx_vcpu_pi_load(vcpu, cpu); 2270 vmx_vcpu_pi_load(vcpu, cpu);
2265 vmx->host_pkru = read_pkru(); 2271 vmx->host_pkru = read_pkru();
@@ -2508,7 +2514,7 @@ static void vmx_set_msr_bitmap(struct kvm_vcpu *vcpu)
2508 unsigned long *msr_bitmap; 2514 unsigned long *msr_bitmap;
2509 2515
2510 if (is_guest_mode(vcpu)) 2516 if (is_guest_mode(vcpu))
2511 msr_bitmap = vmx_msr_bitmap_nested; 2517 msr_bitmap = to_vmx(vcpu)->nested.msr_bitmap;
2512 else if (cpu_has_secondary_exec_ctrls() && 2518 else if (cpu_has_secondary_exec_ctrls() &&
2513 (vmcs_read32(SECONDARY_VM_EXEC_CONTROL) & 2519 (vmcs_read32(SECONDARY_VM_EXEC_CONTROL) &
2514 SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE)) { 2520 SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE)) {
@@ -6363,13 +6369,6 @@ static __init int hardware_setup(void)
6363 if (!vmx_msr_bitmap_longmode_x2apic) 6369 if (!vmx_msr_bitmap_longmode_x2apic)
6364 goto out4; 6370 goto out4;
6365 6371
6366 if (nested) {
6367 vmx_msr_bitmap_nested =
6368 (unsigned long *)__get_free_page(GFP_KERNEL);
6369 if (!vmx_msr_bitmap_nested)
6370 goto out5;
6371 }
6372
6373 vmx_vmread_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL); 6372 vmx_vmread_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL);
6374 if (!vmx_vmread_bitmap) 6373 if (!vmx_vmread_bitmap)
6375 goto out6; 6374 goto out6;
@@ -6392,8 +6391,6 @@ static __init int hardware_setup(void)
6392 6391
6393 memset(vmx_msr_bitmap_legacy, 0xff, PAGE_SIZE); 6392 memset(vmx_msr_bitmap_legacy, 0xff, PAGE_SIZE);
6394 memset(vmx_msr_bitmap_longmode, 0xff, PAGE_SIZE); 6393 memset(vmx_msr_bitmap_longmode, 0xff, PAGE_SIZE);
6395 if (nested)
6396 memset(vmx_msr_bitmap_nested, 0xff, PAGE_SIZE);
6397 6394
6398 if (setup_vmcs_config(&vmcs_config) < 0) { 6395 if (setup_vmcs_config(&vmcs_config) < 0) {
6399 r = -EIO; 6396 r = -EIO;
@@ -6529,9 +6526,6 @@ out8:
6529out7: 6526out7:
6530 free_page((unsigned long)vmx_vmread_bitmap); 6527 free_page((unsigned long)vmx_vmread_bitmap);
6531out6: 6528out6:
6532 if (nested)
6533 free_page((unsigned long)vmx_msr_bitmap_nested);
6534out5:
6535 free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic); 6529 free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic);
6536out4: 6530out4:
6537 free_page((unsigned long)vmx_msr_bitmap_longmode); 6531 free_page((unsigned long)vmx_msr_bitmap_longmode);
@@ -6557,8 +6551,6 @@ static __exit void hardware_unsetup(void)
6557 free_page((unsigned long)vmx_io_bitmap_a); 6551 free_page((unsigned long)vmx_io_bitmap_a);
6558 free_page((unsigned long)vmx_vmwrite_bitmap); 6552 free_page((unsigned long)vmx_vmwrite_bitmap);
6559 free_page((unsigned long)vmx_vmread_bitmap); 6553 free_page((unsigned long)vmx_vmread_bitmap);
6560 if (nested)
6561 free_page((unsigned long)vmx_msr_bitmap_nested);
6562 6554
6563 free_kvm_area(); 6555 free_kvm_area();
6564} 6556}
@@ -6995,16 +6987,21 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
6995 return 1; 6987 return 1;
6996 } 6988 }
6997 6989
6990 if (cpu_has_vmx_msr_bitmap()) {
6991 vmx->nested.msr_bitmap =
6992 (unsigned long *)__get_free_page(GFP_KERNEL);
6993 if (!vmx->nested.msr_bitmap)
6994 goto out_msr_bitmap;
6995 }
6996
6998 vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL); 6997 vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL);
6999 if (!vmx->nested.cached_vmcs12) 6998 if (!vmx->nested.cached_vmcs12)
7000 return -ENOMEM; 6999 goto out_cached_vmcs12;
7001 7000
7002 if (enable_shadow_vmcs) { 7001 if (enable_shadow_vmcs) {
7003 shadow_vmcs = alloc_vmcs(); 7002 shadow_vmcs = alloc_vmcs();
7004 if (!shadow_vmcs) { 7003 if (!shadow_vmcs)
7005 kfree(vmx->nested.cached_vmcs12); 7004 goto out_shadow_vmcs;
7006 return -ENOMEM;
7007 }
7008 /* mark vmcs as shadow */ 7005 /* mark vmcs as shadow */
7009 shadow_vmcs->revision_id |= (1u << 31); 7006 shadow_vmcs->revision_id |= (1u << 31);
7010 /* init shadow vmcs */ 7007 /* init shadow vmcs */
@@ -7024,6 +7021,15 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
7024 skip_emulated_instruction(vcpu); 7021 skip_emulated_instruction(vcpu);
7025 nested_vmx_succeed(vcpu); 7022 nested_vmx_succeed(vcpu);
7026 return 1; 7023 return 1;
7024
7025out_shadow_vmcs:
7026 kfree(vmx->nested.cached_vmcs12);
7027
7028out_cached_vmcs12:
7029 free_page((unsigned long)vmx->nested.msr_bitmap);
7030
7031out_msr_bitmap:
7032 return -ENOMEM;
7027} 7033}
7028 7034
7029/* 7035/*
@@ -7098,6 +7104,10 @@ static void free_nested(struct vcpu_vmx *vmx)
7098 vmx->nested.vmxon = false; 7104 vmx->nested.vmxon = false;
7099 free_vpid(vmx->nested.vpid02); 7105 free_vpid(vmx->nested.vpid02);
7100 nested_release_vmcs12(vmx); 7106 nested_release_vmcs12(vmx);
7107 if (vmx->nested.msr_bitmap) {
7108 free_page((unsigned long)vmx->nested.msr_bitmap);
7109 vmx->nested.msr_bitmap = NULL;
7110 }
7101 if (enable_shadow_vmcs) 7111 if (enable_shadow_vmcs)
7102 free_vmcs(vmx->nested.current_shadow_vmcs); 7112 free_vmcs(vmx->nested.current_shadow_vmcs);
7103 kfree(vmx->nested.cached_vmcs12); 7113 kfree(vmx->nested.cached_vmcs12);
@@ -8419,6 +8429,12 @@ static void vmx_set_virtual_x2apic_mode(struct kvm_vcpu *vcpu, bool set)
8419{ 8429{
8420 u32 sec_exec_control; 8430 u32 sec_exec_control;
8421 8431
8432 /* Postpone execution until vmcs01 is the current VMCS. */
8433 if (is_guest_mode(vcpu)) {
8434 to_vmx(vcpu)->nested.change_vmcs01_virtual_x2apic_mode = true;
8435 return;
8436 }
8437
8422 /* 8438 /*
8423 * There is not point to enable virtualize x2apic without enable 8439 * There is not point to enable virtualize x2apic without enable
8424 * apicv 8440 * apicv
@@ -9472,8 +9488,10 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu,
9472{ 9488{
9473 int msr; 9489 int msr;
9474 struct page *page; 9490 struct page *page;
9475 unsigned long *msr_bitmap; 9491 unsigned long *msr_bitmap_l1;
9492 unsigned long *msr_bitmap_l0 = to_vmx(vcpu)->nested.msr_bitmap;
9476 9493
9494 /* This shortcut is ok because we support only x2APIC MSRs so far. */
9477 if (!nested_cpu_has_virt_x2apic_mode(vmcs12)) 9495 if (!nested_cpu_has_virt_x2apic_mode(vmcs12))
9478 return false; 9496 return false;
9479 9497
@@ -9482,63 +9500,37 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu,
9482 WARN_ON(1); 9500 WARN_ON(1);
9483 return false; 9501 return false;
9484 } 9502 }
9485 msr_bitmap = (unsigned long *)kmap(page); 9503 msr_bitmap_l1 = (unsigned long *)kmap(page);
9486 if (!msr_bitmap) { 9504 if (!msr_bitmap_l1) {
9487 nested_release_page_clean(page); 9505 nested_release_page_clean(page);
9488 WARN_ON(1); 9506 WARN_ON(1);
9489 return false; 9507 return false;
9490 } 9508 }
9491 9509
9510 memset(msr_bitmap_l0, 0xff, PAGE_SIZE);
9511
9492 if (nested_cpu_has_virt_x2apic_mode(vmcs12)) { 9512 if (nested_cpu_has_virt_x2apic_mode(vmcs12)) {
9493 if (nested_cpu_has_apic_reg_virt(vmcs12)) 9513 if (nested_cpu_has_apic_reg_virt(vmcs12))
9494 for (msr = 0x800; msr <= 0x8ff; msr++) 9514 for (msr = 0x800; msr <= 0x8ff; msr++)
9495 nested_vmx_disable_intercept_for_msr( 9515 nested_vmx_disable_intercept_for_msr(
9496 msr_bitmap, 9516 msr_bitmap_l1, msr_bitmap_l0,
9497 vmx_msr_bitmap_nested,
9498 msr, MSR_TYPE_R); 9517 msr, MSR_TYPE_R);
9499 /* TPR is allowed */ 9518
9500 nested_vmx_disable_intercept_for_msr(msr_bitmap, 9519 nested_vmx_disable_intercept_for_msr(
9501 vmx_msr_bitmap_nested, 9520 msr_bitmap_l1, msr_bitmap_l0,
9502 APIC_BASE_MSR + (APIC_TASKPRI >> 4), 9521 APIC_BASE_MSR + (APIC_TASKPRI >> 4),
9503 MSR_TYPE_R | MSR_TYPE_W); 9522 MSR_TYPE_R | MSR_TYPE_W);
9523
9504 if (nested_cpu_has_vid(vmcs12)) { 9524 if (nested_cpu_has_vid(vmcs12)) {
9505 /* EOI and self-IPI are allowed */
9506 nested_vmx_disable_intercept_for_msr( 9525 nested_vmx_disable_intercept_for_msr(
9507 msr_bitmap, 9526 msr_bitmap_l1, msr_bitmap_l0,
9508 vmx_msr_bitmap_nested,
9509 APIC_BASE_MSR + (APIC_EOI >> 4), 9527 APIC_BASE_MSR + (APIC_EOI >> 4),
9510 MSR_TYPE_W); 9528 MSR_TYPE_W);
9511 nested_vmx_disable_intercept_for_msr( 9529 nested_vmx_disable_intercept_for_msr(
9512 msr_bitmap, 9530 msr_bitmap_l1, msr_bitmap_l0,
9513 vmx_msr_bitmap_nested,
9514 APIC_BASE_MSR + (APIC_SELF_IPI >> 4), 9531 APIC_BASE_MSR + (APIC_SELF_IPI >> 4),
9515 MSR_TYPE_W); 9532 MSR_TYPE_W);
9516 } 9533 }
9517 } else {
9518 /*
9519 * Enable reading intercept of all the x2apic
9520 * MSRs. We should not rely on vmcs12 to do any
9521 * optimizations here, it may have been modified
9522 * by L1.
9523 */
9524 for (msr = 0x800; msr <= 0x8ff; msr++)
9525 __vmx_enable_intercept_for_msr(
9526 vmx_msr_bitmap_nested,
9527 msr,
9528 MSR_TYPE_R);
9529
9530 __vmx_enable_intercept_for_msr(
9531 vmx_msr_bitmap_nested,
9532 APIC_BASE_MSR + (APIC_TASKPRI >> 4),
9533 MSR_TYPE_W);
9534 __vmx_enable_intercept_for_msr(
9535 vmx_msr_bitmap_nested,
9536 APIC_BASE_MSR + (APIC_EOI >> 4),
9537 MSR_TYPE_W);
9538 __vmx_enable_intercept_for_msr(
9539 vmx_msr_bitmap_nested,
9540 APIC_BASE_MSR + (APIC_SELF_IPI >> 4),
9541 MSR_TYPE_W);
9542 } 9534 }
9543 kunmap(page); 9535 kunmap(page);
9544 nested_release_page_clean(page); 9536 nested_release_page_clean(page);
@@ -9957,10 +9949,10 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
9957 } 9949 }
9958 9950
9959 if (cpu_has_vmx_msr_bitmap() && 9951 if (cpu_has_vmx_msr_bitmap() &&
9960 exec_control & CPU_BASED_USE_MSR_BITMAPS) { 9952 exec_control & CPU_BASED_USE_MSR_BITMAPS &&
9961 nested_vmx_merge_msr_bitmap(vcpu, vmcs12); 9953 nested_vmx_merge_msr_bitmap(vcpu, vmcs12))
9962 /* MSR_BITMAP will be set by following vmx_set_efer. */ 9954 ; /* MSR_BITMAP will be set by following vmx_set_efer. */
9963 } else 9955 else
9964 exec_control &= ~CPU_BASED_USE_MSR_BITMAPS; 9956 exec_control &= ~CPU_BASED_USE_MSR_BITMAPS;
9965 9957
9966 /* 9958 /*
@@ -10011,6 +10003,8 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
10011 vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset); 10003 vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset);
10012 else 10004 else
10013 vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset); 10005 vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);
10006 if (kvm_has_tsc_control)
10007 decache_tsc_multiplier(vmx);
10014 10008
10015 if (enable_vpid) { 10009 if (enable_vpid) {
10016 /* 10010 /*
@@ -10767,6 +10761,14 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
10767 else 10761 else
10768 vmcs_set_bits(PIN_BASED_VM_EXEC_CONTROL, 10762 vmcs_set_bits(PIN_BASED_VM_EXEC_CONTROL,
10769 PIN_BASED_VMX_PREEMPTION_TIMER); 10763 PIN_BASED_VMX_PREEMPTION_TIMER);
10764 if (kvm_has_tsc_control)
10765 decache_tsc_multiplier(vmx);
10766
10767 if (vmx->nested.change_vmcs01_virtual_x2apic_mode) {
10768 vmx->nested.change_vmcs01_virtual_x2apic_mode = false;
10769 vmx_set_virtual_x2apic_mode(vcpu,
10770 vcpu->arch.apic_base & X2APIC_ENABLE);
10771 }
10770 10772
10771 /* This is needed for same reason as it was needed in prepare_vmcs02 */ 10773 /* This is needed for same reason as it was needed in prepare_vmcs02 */
10772 vmx->host_rsp = 0; 10774 vmx->host_rsp = 0;
diff --git a/arch/x86/lib/kaslr.c b/arch/x86/lib/kaslr.c
index f7dfeda83e5c..121f59c6ee54 100644
--- a/arch/x86/lib/kaslr.c
+++ b/arch/x86/lib/kaslr.c
@@ -19,7 +19,7 @@
19#include <asm/cpufeature.h> 19#include <asm/cpufeature.h>
20#include <asm/setup.h> 20#include <asm/setup.h>
21 21
22#define debug_putstr(v) early_printk(v) 22#define debug_putstr(v) early_printk("%s", v)
23#define has_cpuflag(f) boot_cpu_has(f) 23#define has_cpuflag(f) boot_cpu_has(f)
24#define get_boot_seed() kaslr_offset() 24#define get_boot_seed() kaslr_offset()
25#endif 25#endif
diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c
index ec21796ac5fd..4473cb4f8b90 100644
--- a/arch/x86/mm/ident_map.c
+++ b/arch/x86/mm/ident_map.c
@@ -3,15 +3,17 @@
3 * included by both the compressed kernel and the regular kernel. 3 * included by both the compressed kernel and the regular kernel.
4 */ 4 */
5 5
6static void ident_pmd_init(unsigned long pmd_flag, pmd_t *pmd_page, 6static void ident_pmd_init(struct x86_mapping_info *info, pmd_t *pmd_page,
7 unsigned long addr, unsigned long end) 7 unsigned long addr, unsigned long end)
8{ 8{
9 addr &= PMD_MASK; 9 addr &= PMD_MASK;
10 for (; addr < end; addr += PMD_SIZE) { 10 for (; addr < end; addr += PMD_SIZE) {
11 pmd_t *pmd = pmd_page + pmd_index(addr); 11 pmd_t *pmd = pmd_page + pmd_index(addr);
12 12
13 if (!pmd_present(*pmd)) 13 if (pmd_present(*pmd))
14 set_pmd(pmd, __pmd(addr | pmd_flag)); 14 continue;
15
16 set_pmd(pmd, __pmd((addr - info->offset) | info->pmd_flag));
15 } 17 }
16} 18}
17 19
@@ -30,13 +32,13 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
30 32
31 if (pud_present(*pud)) { 33 if (pud_present(*pud)) {
32 pmd = pmd_offset(pud, 0); 34 pmd = pmd_offset(pud, 0);
33 ident_pmd_init(info->pmd_flag, pmd, addr, next); 35 ident_pmd_init(info, pmd, addr, next);
34 continue; 36 continue;
35 } 37 }
36 pmd = (pmd_t *)info->alloc_pgt_page(info->context); 38 pmd = (pmd_t *)info->alloc_pgt_page(info->context);
37 if (!pmd) 39 if (!pmd)
38 return -ENOMEM; 40 return -ENOMEM;
39 ident_pmd_init(info->pmd_flag, pmd, addr, next); 41 ident_pmd_init(info, pmd, addr, next);
40 set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); 42 set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE));
41 } 43 }
42 44
@@ -44,14 +46,15 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
44} 46}
45 47
46int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, 48int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,
47 unsigned long addr, unsigned long end) 49 unsigned long pstart, unsigned long pend)
48{ 50{
51 unsigned long addr = pstart + info->offset;
52 unsigned long end = pend + info->offset;
49 unsigned long next; 53 unsigned long next;
50 int result; 54 int result;
51 int off = info->kernel_mapping ? pgd_index(__PAGE_OFFSET) : 0;
52 55
53 for (; addr < end; addr = next) { 56 for (; addr < end; addr = next) {
54 pgd_t *pgd = pgd_page + pgd_index(addr) + off; 57 pgd_t *pgd = pgd_page + pgd_index(addr);
55 pud_t *pud; 58 pud_t *pud;
56 59
57 next = (addr & PGDIR_MASK) + PGDIR_SIZE; 60 next = (addr & PGDIR_MASK) + PGDIR_SIZE;
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 620928903be3..d28a2d741f9e 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -122,8 +122,18 @@ __ref void *alloc_low_pages(unsigned int num)
122 return __va(pfn << PAGE_SHIFT); 122 return __va(pfn << PAGE_SHIFT);
123} 123}
124 124
125/* need 3 4k for initial PMD_SIZE, 3 4k for 0-ISA_END_ADDRESS */ 125/*
126#define INIT_PGT_BUF_SIZE (6 * PAGE_SIZE) 126 * By default need 3 4k for initial PMD_SIZE, 3 4k for 0-ISA_END_ADDRESS.
127 * With KASLR memory randomization, depending on the machine e820 memory
128 * and the PUD alignment. We may need twice more pages when KASLR memory
129 * randomization is enabled.
130 */
131#ifndef CONFIG_RANDOMIZE_MEMORY
132#define INIT_PGD_PAGE_COUNT 6
133#else
134#define INIT_PGD_PAGE_COUNT 12
135#endif
136#define INIT_PGT_BUF_SIZE (INIT_PGD_PAGE_COUNT * PAGE_SIZE)
127RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE); 137RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);
128void __init early_alloc_pgt_buf(void) 138void __init early_alloc_pgt_buf(void)
129{ 139{
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 26dccd6c0df1..bda8d5eef04d 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -77,7 +77,7 @@ static inline unsigned long get_padding(struct kaslr_memory_region *region)
77 */ 77 */
78static inline bool kaslr_memory_enabled(void) 78static inline bool kaslr_memory_enabled(void)
79{ 79{
80 return kaslr_enabled() && !config_enabled(CONFIG_KASAN); 80 return kaslr_enabled() && !IS_ENABLED(CONFIG_KASAN);
81} 81}
82 82
83/* Initialize base and padding for each memory region randomized with KASLR */ 83/* Initialize base and padding for each memory region randomized with KASLR */
@@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void)
97 * add padding if needed (especially for memory hotplug support). 97 * add padding if needed (especially for memory hotplug support).
98 */ 98 */
99 BUG_ON(kaslr_regions[0].base != &page_offset_base); 99 BUG_ON(kaslr_regions[0].base != &page_offset_base);
100 memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) + 100 memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
101 CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING; 101 CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
102 102
103 /* Adapt phyiscal memory region size based on available memory */ 103 /* Adapt phyiscal memory region size based on available memory */
diff --git a/arch/x86/pci/vmd.c b/arch/x86/pci/vmd.c
index b814ca675131..7948be342ee9 100644
--- a/arch/x86/pci/vmd.c
+++ b/arch/x86/pci/vmd.c
@@ -41,6 +41,7 @@ static DEFINE_RAW_SPINLOCK(list_lock);
41 * @node: list item for parent traversal. 41 * @node: list item for parent traversal.
42 * @rcu: RCU callback item for freeing. 42 * @rcu: RCU callback item for freeing.
43 * @irq: back pointer to parent. 43 * @irq: back pointer to parent.
44 * @enabled: true if driver enabled IRQ
44 * @virq: the virtual IRQ value provided to the requesting driver. 45 * @virq: the virtual IRQ value provided to the requesting driver.
45 * 46 *
46 * Every MSI/MSI-X IRQ requested for a device in a VMD domain will be mapped to 47 * Every MSI/MSI-X IRQ requested for a device in a VMD domain will be mapped to
@@ -50,6 +51,7 @@ struct vmd_irq {
50 struct list_head node; 51 struct list_head node;
51 struct rcu_head rcu; 52 struct rcu_head rcu;
52 struct vmd_irq_list *irq; 53 struct vmd_irq_list *irq;
54 bool enabled;
53 unsigned int virq; 55 unsigned int virq;
54}; 56};
55 57
@@ -122,7 +124,9 @@ static void vmd_irq_enable(struct irq_data *data)
122 unsigned long flags; 124 unsigned long flags;
123 125
124 raw_spin_lock_irqsave(&list_lock, flags); 126 raw_spin_lock_irqsave(&list_lock, flags);
127 WARN_ON(vmdirq->enabled);
125 list_add_tail_rcu(&vmdirq->node, &vmdirq->irq->irq_list); 128 list_add_tail_rcu(&vmdirq->node, &vmdirq->irq->irq_list);
129 vmdirq->enabled = true;
126 raw_spin_unlock_irqrestore(&list_lock, flags); 130 raw_spin_unlock_irqrestore(&list_lock, flags);
127 131
128 data->chip->irq_unmask(data); 132 data->chip->irq_unmask(data);
@@ -136,8 +140,10 @@ static void vmd_irq_disable(struct irq_data *data)
136 data->chip->irq_mask(data); 140 data->chip->irq_mask(data);
137 141
138 raw_spin_lock_irqsave(&list_lock, flags); 142 raw_spin_lock_irqsave(&list_lock, flags);
139 list_del_rcu(&vmdirq->node); 143 if (vmdirq->enabled) {
140 INIT_LIST_HEAD_RCU(&vmdirq->node); 144 list_del_rcu(&vmdirq->node);
145 vmdirq->enabled = false;
146 }
141 raw_spin_unlock_irqrestore(&list_lock, flags); 147 raw_spin_unlock_irqrestore(&list_lock, flags);
142} 148}
143 149
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 4480c06cade7..89d1146f5a6f 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -254,6 +254,7 @@ void __init efi_free_boot_services(void)
254 for_each_efi_memory_desc(md) { 254 for_each_efi_memory_desc(md) {
255 unsigned long long start = md->phys_addr; 255 unsigned long long start = md->phys_addr;
256 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; 256 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
257 size_t rm_size;
257 258
258 if (md->type != EFI_BOOT_SERVICES_CODE && 259 if (md->type != EFI_BOOT_SERVICES_CODE &&
259 md->type != EFI_BOOT_SERVICES_DATA) 260 md->type != EFI_BOOT_SERVICES_DATA)
@@ -263,6 +264,26 @@ void __init efi_free_boot_services(void)
263 if (md->attribute & EFI_MEMORY_RUNTIME) 264 if (md->attribute & EFI_MEMORY_RUNTIME)
264 continue; 265 continue;
265 266
267 /*
268 * Nasty quirk: if all sub-1MB memory is used for boot
269 * services, we can get here without having allocated the
270 * real mode trampoline. It's too late to hand boot services
271 * memory back to the memblock allocator, so instead
272 * try to manually allocate the trampoline if needed.
273 *
274 * I've seen this on a Dell XPS 13 9350 with firmware
275 * 1.4.4 with SGX enabled booting Linux via Fedora 24's
276 * grub2-efi on a hard disk. (And no, I don't know why
277 * this happened, but Linux should still try to boot rather
278 * panicing early.)
279 */
280 rm_size = real_mode_size_needed();
281 if (rm_size && (start + rm_size) < (1<<20) && size >= rm_size) {
282 set_real_mode_mem(start, rm_size);
283 start += rm_size;
284 size -= rm_size;
285 }
286
266 free_bootmem_late(start, size); 287 free_bootmem_late(start, size);
267 } 288 }
268 289
diff --git a/arch/x86/platform/uv/bios_uv.c b/arch/x86/platform/uv/bios_uv.c
index 66b2166ea4a1..23f2f3e41c7f 100644
--- a/arch/x86/platform/uv/bios_uv.c
+++ b/arch/x86/platform/uv/bios_uv.c
@@ -187,7 +187,8 @@ EXPORT_SYMBOL_GPL(uv_bios_set_legacy_vga_target);
187void uv_bios_init(void) 187void uv_bios_init(void)
188{ 188{
189 uv_systab = NULL; 189 uv_systab = NULL;
190 if ((efi.uv_systab == EFI_INVALID_TABLE_ADDR) || !efi.uv_systab) { 190 if ((efi.uv_systab == EFI_INVALID_TABLE_ADDR) ||
191 !efi.uv_systab || efi_runtime_disabled()) {
191 pr_crit("UV: UVsystab: missing\n"); 192 pr_crit("UV: UVsystab: missing\n");
192 return; 193 return;
193 } 194 }
@@ -199,12 +200,14 @@ void uv_bios_init(void)
199 return; 200 return;
200 } 201 }
201 202
203 /* Starting with UV4 the UV systab size is variable */
202 if (uv_systab->revision >= UV_SYSTAB_VERSION_UV4) { 204 if (uv_systab->revision >= UV_SYSTAB_VERSION_UV4) {
205 int size = uv_systab->size;
206
203 iounmap(uv_systab); 207 iounmap(uv_systab);
204 uv_systab = ioremap(efi.uv_systab, uv_systab->size); 208 uv_systab = ioremap(efi.uv_systab, size);
205 if (!uv_systab) { 209 if (!uv_systab) {
206 pr_err("UV: UVsystab: ioremap(%d) failed!\n", 210 pr_err("UV: UVsystab: ioremap(%d) failed!\n", size);
207 uv_systab->size);
208 return; 211 return;
209 } 212 }
210 } 213 }
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index f0b5f2d402af..9634557a5444 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -87,7 +87,7 @@ static int set_up_temporary_mappings(void)
87 struct x86_mapping_info info = { 87 struct x86_mapping_info info = {
88 .alloc_pgt_page = alloc_pgt_page, 88 .alloc_pgt_page = alloc_pgt_page,
89 .pmd_flag = __PAGE_KERNEL_LARGE_EXEC, 89 .pmd_flag = __PAGE_KERNEL_LARGE_EXEC,
90 .kernel_mapping = true, 90 .offset = __PAGE_OFFSET,
91 }; 91 };
92 unsigned long mstart, mend; 92 unsigned long mstart, mend;
93 pgd_t *pgd; 93 pgd_t *pgd;
@@ -113,7 +113,7 @@ static int set_up_temporary_mappings(void)
113 return result; 113 return result;
114 } 114 }
115 115
116 temp_level4_pgt = (unsigned long)pgd - __PAGE_OFFSET; 116 temp_level4_pgt = __pa(pgd);
117 return 0; 117 return 0;
118} 118}
119 119
diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
index 705e3fffb4a1..5db706f14111 100644
--- a/arch/x86/realmode/init.c
+++ b/arch/x86/realmode/init.c
@@ -1,9 +1,11 @@
1#include <linux/io.h> 1#include <linux/io.h>
2#include <linux/slab.h>
2#include <linux/memblock.h> 3#include <linux/memblock.h>
3 4
4#include <asm/cacheflush.h> 5#include <asm/cacheflush.h>
5#include <asm/pgtable.h> 6#include <asm/pgtable.h>
6#include <asm/realmode.h> 7#include <asm/realmode.h>
8#include <asm/tlbflush.h>
7 9
8struct real_mode_header *real_mode_header; 10struct real_mode_header *real_mode_header;
9u32 *trampoline_cr4_features; 11u32 *trampoline_cr4_features;
@@ -11,25 +13,37 @@ u32 *trampoline_cr4_features;
11/* Hold the pgd entry used on booting additional CPUs */ 13/* Hold the pgd entry used on booting additional CPUs */
12pgd_t trampoline_pgd_entry; 14pgd_t trampoline_pgd_entry;
13 15
16void __init set_real_mode_mem(phys_addr_t mem, size_t size)
17{
18 void *base = __va(mem);
19
20 real_mode_header = (struct real_mode_header *) base;
21 printk(KERN_DEBUG "Base memory trampoline at [%p] %llx size %zu\n",
22 base, (unsigned long long)mem, size);
23}
24
14void __init reserve_real_mode(void) 25void __init reserve_real_mode(void)
15{ 26{
16 phys_addr_t mem; 27 phys_addr_t mem;
17 unsigned char *base; 28 size_t size = real_mode_size_needed();
18 size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob); 29
30 if (!size)
31 return;
32
33 WARN_ON(slab_is_available());
19 34
20 /* Has to be under 1M so we can execute real-mode AP code. */ 35 /* Has to be under 1M so we can execute real-mode AP code. */
21 mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE); 36 mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE);
22 if (!mem) 37 if (!mem) {
23 panic("Cannot allocate trampoline\n"); 38 pr_info("No sub-1M memory is available for the trampoline\n");
39 return;
40 }
24 41
25 base = __va(mem);
26 memblock_reserve(mem, size); 42 memblock_reserve(mem, size);
27 real_mode_header = (struct real_mode_header *) base; 43 set_real_mode_mem(mem, size);
28 printk(KERN_DEBUG "Base memory trampoline at [%p] %llx size %zu\n",
29 base, (unsigned long long)mem, size);
30} 44}
31 45
32void __init setup_real_mode(void) 46static void __init setup_real_mode(void)
33{ 47{
34 u16 real_mode_seg; 48 u16 real_mode_seg;
35 const u32 *rel; 49 const u32 *rel;
@@ -84,7 +98,7 @@ void __init setup_real_mode(void)
84 98
85 trampoline_header->start = (u64) secondary_startup_64; 99 trampoline_header->start = (u64) secondary_startup_64;
86 trampoline_cr4_features = &trampoline_header->cr4; 100 trampoline_cr4_features = &trampoline_header->cr4;
87 *trampoline_cr4_features = __read_cr4(); 101 *trampoline_cr4_features = mmu_cr4_features;
88 102
89 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd); 103 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
90 trampoline_pgd[0] = trampoline_pgd_entry.pgd; 104 trampoline_pgd[0] = trampoline_pgd_entry.pgd;
@@ -100,7 +114,7 @@ void __init setup_real_mode(void)
100 * need to mark it executable at do_pre_smp_initcalls() at least, 114 * need to mark it executable at do_pre_smp_initcalls() at least,
101 * thus run it as a early_initcall(). 115 * thus run it as a early_initcall().
102 */ 116 */
103static int __init set_real_mode_permissions(void) 117static void __init set_real_mode_permissions(void)
104{ 118{
105 unsigned char *base = (unsigned char *) real_mode_header; 119 unsigned char *base = (unsigned char *) real_mode_header;
106 size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob); 120 size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob);
@@ -119,7 +133,16 @@ static int __init set_real_mode_permissions(void)
119 set_memory_nx((unsigned long) base, size >> PAGE_SHIFT); 133 set_memory_nx((unsigned long) base, size >> PAGE_SHIFT);
120 set_memory_ro((unsigned long) base, ro_size >> PAGE_SHIFT); 134 set_memory_ro((unsigned long) base, ro_size >> PAGE_SHIFT);
121 set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT); 135 set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT);
136}
137
138static int __init init_real_mode(void)
139{
140 if (!real_mode_header)
141 panic("Real mode trampoline was not allocated");
142
143 setup_real_mode();
144 set_real_mode_permissions();
122 145
123 return 0; 146 return 0;
124} 147}
125early_initcall(set_real_mode_permissions); 148early_initcall(init_real_mode);
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 8ffb089b19a5..b86ebb1a9a7f 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -118,7 +118,7 @@ DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
118DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info); 118DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
119 119
120/* Linux <-> Xen vCPU id mapping */ 120/* Linux <-> Xen vCPU id mapping */
121DEFINE_PER_CPU(int, xen_vcpu_id) = -1; 121DEFINE_PER_CPU(uint32_t, xen_vcpu_id);
122EXPORT_PER_CPU_SYMBOL(xen_vcpu_id); 122EXPORT_PER_CPU_SYMBOL(xen_vcpu_id);
123 123
124enum xen_domain_type xen_domain_type = XEN_NATIVE; 124enum xen_domain_type xen_domain_type = XEN_NATIVE;
diff --git a/block/bio.c b/block/bio.c
index f39477538fef..aa7354088008 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -667,18 +667,19 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,
667 bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; 667 bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector;
668 bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; 668 bio->bi_iter.bi_size = bio_src->bi_iter.bi_size;
669 669
670 if (bio_op(bio) == REQ_OP_DISCARD) 670 switch (bio_op(bio)) {
671 goto integrity_clone; 671 case REQ_OP_DISCARD:
672 672 case REQ_OP_SECURE_ERASE:
673 if (bio_op(bio) == REQ_OP_WRITE_SAME) { 673 break;
674 case REQ_OP_WRITE_SAME:
674 bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0]; 675 bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0];
675 goto integrity_clone; 676 break;
677 default:
678 bio_for_each_segment(bv, bio_src, iter)
679 bio->bi_io_vec[bio->bi_vcnt++] = bv;
680 break;
676 } 681 }
677 682
678 bio_for_each_segment(bv, bio_src, iter)
679 bio->bi_io_vec[bio->bi_vcnt++] = bv;
680
681integrity_clone:
682 if (bio_integrity(bio_src)) { 683 if (bio_integrity(bio_src)) {
683 int ret; 684 int ret;
684 685
@@ -1788,7 +1789,7 @@ struct bio *bio_split(struct bio *bio, int sectors,
1788 * Discards need a mutable bio_vec to accommodate the payload 1789 * Discards need a mutable bio_vec to accommodate the payload
1789 * required by the DSM TRIM and UNMAP commands. 1790 * required by the DSM TRIM and UNMAP commands.
1790 */ 1791 */
1791 if (bio_op(bio) == REQ_OP_DISCARD) 1792 if (bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_SECURE_ERASE)
1792 split = bio_clone_bioset(bio, gfp, bs); 1793 split = bio_clone_bioset(bio, gfp, bs);
1793 else 1794 else
1794 split = bio_clone_fast(bio, gfp, bs); 1795 split = bio_clone_fast(bio, gfp, bs);
diff --git a/block/blk-core.c b/block/blk-core.c
index 999442ec4601..36c7ac328d8c 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -515,7 +515,9 @@ EXPORT_SYMBOL_GPL(blk_queue_bypass_end);
515 515
516void blk_set_queue_dying(struct request_queue *q) 516void blk_set_queue_dying(struct request_queue *q)
517{ 517{
518 queue_flag_set_unlocked(QUEUE_FLAG_DYING, q); 518 spin_lock_irq(q->queue_lock);
519 queue_flag_set(QUEUE_FLAG_DYING, q);
520 spin_unlock_irq(q->queue_lock);
519 521
520 if (q->mq_ops) 522 if (q->mq_ops)
521 blk_mq_wake_waiters(q); 523 blk_mq_wake_waiters(q);
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 3eec75a9e91d..2642e5fc8b69 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -94,9 +94,31 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
94 bool do_split = true; 94 bool do_split = true;
95 struct bio *new = NULL; 95 struct bio *new = NULL;
96 const unsigned max_sectors = get_max_io_size(q, bio); 96 const unsigned max_sectors = get_max_io_size(q, bio);
97 unsigned bvecs = 0;
97 98
98 bio_for_each_segment(bv, bio, iter) { 99 bio_for_each_segment(bv, bio, iter) {
99 /* 100 /*
101 * With arbitrary bio size, the incoming bio may be very
102 * big. We have to split the bio into small bios so that
103 * each holds at most BIO_MAX_PAGES bvecs because
104 * bio_clone() can fail to allocate big bvecs.
105 *
106 * It should have been better to apply the limit per
107 * request queue in which bio_clone() is involved,
108 * instead of globally. The biggest blocker is the
109 * bio_clone() in bio bounce.
110 *
111 * If bio is splitted by this reason, we should have
112 * allowed to continue bios merging, but don't do
113 * that now for making the change simple.
114 *
115 * TODO: deal with bio bounce's bio_clone() gracefully
116 * and convert the global limit into per-queue limit.
117 */
118 if (bvecs++ >= BIO_MAX_PAGES)
119 goto split;
120
121 /*
100 * If the queue doesn't support SG gaps and adding this 122 * If the queue doesn't support SG gaps and adding this
101 * offset would create a gap, disallow it. 123 * offset would create a gap, disallow it.
102 */ 124 */
@@ -172,12 +194,18 @@ void blk_queue_split(struct request_queue *q, struct bio **bio,
172 struct bio *split, *res; 194 struct bio *split, *res;
173 unsigned nsegs; 195 unsigned nsegs;
174 196
175 if (bio_op(*bio) == REQ_OP_DISCARD) 197 switch (bio_op(*bio)) {
198 case REQ_OP_DISCARD:
199 case REQ_OP_SECURE_ERASE:
176 split = blk_bio_discard_split(q, *bio, bs, &nsegs); 200 split = blk_bio_discard_split(q, *bio, bs, &nsegs);
177 else if (bio_op(*bio) == REQ_OP_WRITE_SAME) 201 break;
202 case REQ_OP_WRITE_SAME:
178 split = blk_bio_write_same_split(q, *bio, bs, &nsegs); 203 split = blk_bio_write_same_split(q, *bio, bs, &nsegs);
179 else 204 break;
205 default:
180 split = blk_bio_segment_split(q, *bio, q->bio_split, &nsegs); 206 split = blk_bio_segment_split(q, *bio, q->bio_split, &nsegs);
207 break;
208 }
181 209
182 /* physical segments can be figured out during splitting */ 210 /* physical segments can be figured out during splitting */
183 res = split ? split : *bio; 211 res = split ? split : *bio;
@@ -213,7 +241,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
213 * This should probably be returning 0, but blk_add_request_payload() 241 * This should probably be returning 0, but blk_add_request_payload()
214 * (Christoph!!!!) 242 * (Christoph!!!!)
215 */ 243 */
216 if (bio_op(bio) == REQ_OP_DISCARD) 244 if (bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_SECURE_ERASE)
217 return 1; 245 return 1;
218 246
219 if (bio_op(bio) == REQ_OP_WRITE_SAME) 247 if (bio_op(bio) == REQ_OP_WRITE_SAME)
@@ -385,7 +413,9 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
385 nsegs = 0; 413 nsegs = 0;
386 cluster = blk_queue_cluster(q); 414 cluster = blk_queue_cluster(q);
387 415
388 if (bio_op(bio) == REQ_OP_DISCARD) { 416 switch (bio_op(bio)) {
417 case REQ_OP_DISCARD:
418 case REQ_OP_SECURE_ERASE:
389 /* 419 /*
390 * This is a hack - drivers should be neither modifying the 420 * This is a hack - drivers should be neither modifying the
391 * biovec, nor relying on bi_vcnt - but because of 421 * biovec, nor relying on bi_vcnt - but because of
@@ -393,19 +423,16 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
393 * a payload we need to set up here (thank you Christoph) and 423 * a payload we need to set up here (thank you Christoph) and
394 * bi_vcnt is really the only way of telling if we need to. 424 * bi_vcnt is really the only way of telling if we need to.
395 */ 425 */
396 426 if (!bio->bi_vcnt)
397 if (bio->bi_vcnt) 427 return 0;
398 goto single_segment; 428 /* Fall through */
399 429 case REQ_OP_WRITE_SAME:
400 return 0;
401 }
402
403 if (bio_op(bio) == REQ_OP_WRITE_SAME) {
404single_segment:
405 *sg = sglist; 430 *sg = sglist;
406 bvec = bio_iovec(bio); 431 bvec = bio_iovec(bio);
407 sg_set_page(*sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset); 432 sg_set_page(*sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset);
408 return 1; 433 return 1;
434 default:
435 break;
409 } 436 }
410 437
411 for_each_bio(bio) 438 for_each_bio(bio)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index e931a0e8e73d..13f5a6c1de76 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -793,11 +793,12 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
793 struct list_head *dptr; 793 struct list_head *dptr;
794 int queued; 794 int queued;
795 795
796 WARN_ON(!cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask));
797
798 if (unlikely(test_bit(BLK_MQ_S_STOPPED, &hctx->state))) 796 if (unlikely(test_bit(BLK_MQ_S_STOPPED, &hctx->state)))
799 return; 797 return;
800 798
799 WARN_ON(!cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask) &&
800 cpu_online(hctx->next_cpu));
801
801 hctx->run++; 802 hctx->run++;
802 803
803 /* 804 /*
@@ -1036,10 +1037,11 @@ void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs)
1036EXPORT_SYMBOL(blk_mq_delay_queue); 1037EXPORT_SYMBOL(blk_mq_delay_queue);
1037 1038
1038static inline void __blk_mq_insert_req_list(struct blk_mq_hw_ctx *hctx, 1039static inline void __blk_mq_insert_req_list(struct blk_mq_hw_ctx *hctx,
1039 struct blk_mq_ctx *ctx,
1040 struct request *rq, 1040 struct request *rq,
1041 bool at_head) 1041 bool at_head)
1042{ 1042{
1043 struct blk_mq_ctx *ctx = rq->mq_ctx;
1044
1043 trace_block_rq_insert(hctx->queue, rq); 1045 trace_block_rq_insert(hctx->queue, rq);
1044 1046
1045 if (at_head) 1047 if (at_head)
@@ -1053,20 +1055,16 @@ static void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx,
1053{ 1055{
1054 struct blk_mq_ctx *ctx = rq->mq_ctx; 1056 struct blk_mq_ctx *ctx = rq->mq_ctx;
1055 1057
1056 __blk_mq_insert_req_list(hctx, ctx, rq, at_head); 1058 __blk_mq_insert_req_list(hctx, rq, at_head);
1057 blk_mq_hctx_mark_pending(hctx, ctx); 1059 blk_mq_hctx_mark_pending(hctx, ctx);
1058} 1060}
1059 1061
1060void blk_mq_insert_request(struct request *rq, bool at_head, bool run_queue, 1062void blk_mq_insert_request(struct request *rq, bool at_head, bool run_queue,
1061 bool async) 1063 bool async)
1062{ 1064{
1065 struct blk_mq_ctx *ctx = rq->mq_ctx;
1063 struct request_queue *q = rq->q; 1066 struct request_queue *q = rq->q;
1064 struct blk_mq_hw_ctx *hctx; 1067 struct blk_mq_hw_ctx *hctx;
1065 struct blk_mq_ctx *ctx = rq->mq_ctx, *current_ctx;
1066
1067 current_ctx = blk_mq_get_ctx(q);
1068 if (!cpu_online(ctx->cpu))
1069 rq->mq_ctx = ctx = current_ctx;
1070 1068
1071 hctx = q->mq_ops->map_queue(q, ctx->cpu); 1069 hctx = q->mq_ops->map_queue(q, ctx->cpu);
1072 1070
@@ -1076,8 +1074,6 @@ void blk_mq_insert_request(struct request *rq, bool at_head, bool run_queue,
1076 1074
1077 if (run_queue) 1075 if (run_queue)
1078 blk_mq_run_hw_queue(hctx, async); 1076 blk_mq_run_hw_queue(hctx, async);
1079
1080 blk_mq_put_ctx(current_ctx);
1081} 1077}
1082 1078
1083static void blk_mq_insert_requests(struct request_queue *q, 1079static void blk_mq_insert_requests(struct request_queue *q,
@@ -1088,14 +1084,9 @@ static void blk_mq_insert_requests(struct request_queue *q,
1088 1084
1089{ 1085{
1090 struct blk_mq_hw_ctx *hctx; 1086 struct blk_mq_hw_ctx *hctx;
1091 struct blk_mq_ctx *current_ctx;
1092 1087
1093 trace_block_unplug(q, depth, !from_schedule); 1088 trace_block_unplug(q, depth, !from_schedule);
1094 1089
1095 current_ctx = blk_mq_get_ctx(q);
1096
1097 if (!cpu_online(ctx->cpu))
1098 ctx = current_ctx;
1099 hctx = q->mq_ops->map_queue(q, ctx->cpu); 1090 hctx = q->mq_ops->map_queue(q, ctx->cpu);
1100 1091
1101 /* 1092 /*
@@ -1107,15 +1098,14 @@ static void blk_mq_insert_requests(struct request_queue *q,
1107 struct request *rq; 1098 struct request *rq;
1108 1099
1109 rq = list_first_entry(list, struct request, queuelist); 1100 rq = list_first_entry(list, struct request, queuelist);
1101 BUG_ON(rq->mq_ctx != ctx);
1110 list_del_init(&rq->queuelist); 1102 list_del_init(&rq->queuelist);
1111 rq->mq_ctx = ctx; 1103 __blk_mq_insert_req_list(hctx, rq, false);
1112 __blk_mq_insert_req_list(hctx, ctx, rq, false);
1113 } 1104 }
1114 blk_mq_hctx_mark_pending(hctx, ctx); 1105 blk_mq_hctx_mark_pending(hctx, ctx);
1115 spin_unlock(&ctx->lock); 1106 spin_unlock(&ctx->lock);
1116 1107
1117 blk_mq_run_hw_queue(hctx, from_schedule); 1108 blk_mq_run_hw_queue(hctx, from_schedule);
1118 blk_mq_put_ctx(current_ctx);
1119} 1109}
1120 1110
1121static int plug_ctx_cmp(void *priv, struct list_head *a, struct list_head *b) 1111static int plug_ctx_cmp(void *priv, struct list_head *a, struct list_head *b)
@@ -1630,16 +1620,17 @@ static int blk_mq_alloc_bitmap(struct blk_mq_ctxmap *bitmap, int node)
1630 return 0; 1620 return 0;
1631} 1621}
1632 1622
1623/*
1624 * 'cpu' is going away. splice any existing rq_list entries from this
1625 * software queue to the hw queue dispatch list, and ensure that it
1626 * gets run.
1627 */
1633static int blk_mq_hctx_cpu_offline(struct blk_mq_hw_ctx *hctx, int cpu) 1628static int blk_mq_hctx_cpu_offline(struct blk_mq_hw_ctx *hctx, int cpu)
1634{ 1629{
1635 struct request_queue *q = hctx->queue;
1636 struct blk_mq_ctx *ctx; 1630 struct blk_mq_ctx *ctx;
1637 LIST_HEAD(tmp); 1631 LIST_HEAD(tmp);
1638 1632
1639 /* 1633 ctx = __blk_mq_get_ctx(hctx->queue, cpu);
1640 * Move ctx entries to new CPU, if this one is going away.
1641 */
1642 ctx = __blk_mq_get_ctx(q, cpu);
1643 1634
1644 spin_lock(&ctx->lock); 1635 spin_lock(&ctx->lock);
1645 if (!list_empty(&ctx->rq_list)) { 1636 if (!list_empty(&ctx->rq_list)) {
@@ -1651,24 +1642,11 @@ static int blk_mq_hctx_cpu_offline(struct blk_mq_hw_ctx *hctx, int cpu)
1651 if (list_empty(&tmp)) 1642 if (list_empty(&tmp))
1652 return NOTIFY_OK; 1643 return NOTIFY_OK;
1653 1644
1654 ctx = blk_mq_get_ctx(q); 1645 spin_lock(&hctx->lock);
1655 spin_lock(&ctx->lock); 1646 list_splice_tail_init(&tmp, &hctx->dispatch);
1656 1647 spin_unlock(&hctx->lock);
1657 while (!list_empty(&tmp)) {
1658 struct request *rq;
1659
1660 rq = list_first_entry(&tmp, struct request, queuelist);
1661 rq->mq_ctx = ctx;
1662 list_move_tail(&rq->queuelist, &ctx->rq_list);
1663 }
1664
1665 hctx = q->mq_ops->map_queue(q, ctx->cpu);
1666 blk_mq_hctx_mark_pending(hctx, ctx);
1667
1668 spin_unlock(&ctx->lock);
1669 1648
1670 blk_mq_run_hw_queue(hctx, true); 1649 blk_mq_run_hw_queue(hctx, true);
1671 blk_mq_put_ctx(ctx);
1672 return NOTIFY_OK; 1650 return NOTIFY_OK;
1673} 1651}
1674 1652
diff --git a/block/elevator.c b/block/elevator.c
index 7096c22041e7..f7d973a56fd7 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -366,7 +366,7 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
366 list_for_each_prev(entry, &q->queue_head) { 366 list_for_each_prev(entry, &q->queue_head) {
367 struct request *pos = list_entry_rq(entry); 367 struct request *pos = list_entry_rq(entry);
368 368
369 if ((req_op(rq) == REQ_OP_DISCARD) != (req_op(pos) == REQ_OP_DISCARD)) 369 if (req_op(rq) != req_op(pos))
370 break; 370 break;
371 if (rq_data_dir(rq) != rq_data_dir(pos)) 371 if (rq_data_dir(rq) != rq_data_dir(pos))
372 break; 372 break;
diff --git a/crypto/Kconfig b/crypto/Kconfig
index a9377bef25e3..84d71482bf08 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -439,7 +439,7 @@ config CRYPTO_CRC32C_INTEL
439 439
440config CRYPT_CRC32C_VPMSUM 440config CRYPT_CRC32C_VPMSUM
441 tristate "CRC32c CRC algorithm (powerpc64)" 441 tristate "CRC32c CRC algorithm (powerpc64)"
442 depends on PPC64 442 depends on PPC64 && ALTIVEC
443 select CRYPTO_HASH 443 select CRYPTO_HASH
444 select CRC32 444 select CRC32
445 help 445 help
diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c
index 62264397a2d2..7e8ed96236ce 100644
--- a/crypto/sha3_generic.c
+++ b/crypto/sha3_generic.c
@@ -24,14 +24,14 @@
24#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 24#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))
25 25
26static const u64 keccakf_rndc[24] = { 26static const u64 keccakf_rndc[24] = {
27 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 27 0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL,
28 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 28 0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL,
29 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 29 0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL,
30 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 30 0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL,
31 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 31 0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL,
32 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 32 0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL,
33 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 33 0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL,
34 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 34 0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL
35}; 35};
36 36
37static const int keccakf_rotc[24] = { 37static const int keccakf_rotc[24] = {
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 8c234dd9b8bc..80cc7c089a15 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -1527,11 +1527,12 @@ static u32 read_blk_stat(struct nfit_blk *nfit_blk, unsigned int bw)
1527{ 1527{
1528 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR]; 1528 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR];
1529 u64 offset = nfit_blk->stat_offset + mmio->size * bw; 1529 u64 offset = nfit_blk->stat_offset + mmio->size * bw;
1530 const u32 STATUS_MASK = 0x80000037;
1530 1531
1531 if (mmio->num_lines) 1532 if (mmio->num_lines)
1532 offset = to_interleave_offset(offset, mmio); 1533 offset = to_interleave_offset(offset, mmio);
1533 1534
1534 return readl(mmio->addr.base + offset); 1535 return readl(mmio->addr.base + offset) & STATUS_MASK;
1535} 1536}
1536 1537
1537static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw, 1538static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw,
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b71a9c767009..e3d8e4ced4a2 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3706,22 +3706,21 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3706 if (UFDCS->rawcmd == 1) 3706 if (UFDCS->rawcmd == 1)
3707 UFDCS->rawcmd = 2; 3707 UFDCS->rawcmd = 2;
3708 3708
3709 if (mode & (FMODE_READ|FMODE_WRITE)) { 3709 if (!(mode & FMODE_NDELAY)) {
3710 UDRS->last_checked = 0; 3710 if (mode & (FMODE_READ|FMODE_WRITE)) {
3711 clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags); 3711 UDRS->last_checked = 0;
3712 check_disk_change(bdev); 3712 clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
3713 if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags)) 3713 check_disk_change(bdev);
3714 goto out; 3714 if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
3715 if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags)) 3715 goto out;
3716 if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
3717 goto out;
3718 }
3719 res = -EROFS;
3720 if ((mode & FMODE_WRITE) &&
3721 !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
3716 goto out; 3722 goto out;
3717 } 3723 }
3718
3719 res = -EROFS;
3720
3721 if ((mode & FMODE_WRITE) &&
3722 !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
3723 goto out;
3724
3725 mutex_unlock(&open_lock); 3724 mutex_unlock(&open_lock);
3726 mutex_unlock(&floppy_mutex); 3725 mutex_unlock(&floppy_mutex);
3727 return 0; 3726 return 0;
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 1a04af6d2421..6c6519f6492a 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3950,6 +3950,7 @@ static void rbd_dev_release(struct device *dev)
3950 bool need_put = !!rbd_dev->opts; 3950 bool need_put = !!rbd_dev->opts;
3951 3951
3952 ceph_oid_destroy(&rbd_dev->header_oid); 3952 ceph_oid_destroy(&rbd_dev->header_oid);
3953 ceph_oloc_destroy(&rbd_dev->header_oloc);
3953 3954
3954 rbd_put_client(rbd_dev->rbd_client); 3955 rbd_put_client(rbd_dev->rbd_client);
3955 rbd_spec_put(rbd_dev->spec); 3956 rbd_spec_put(rbd_dev->spec);
@@ -5336,15 +5337,6 @@ static ssize_t do_rbd_add(struct bus_type *bus,
5336 } 5337 }
5337 spec->pool_id = (u64)rc; 5338 spec->pool_id = (u64)rc;
5338 5339
5339 /* The ceph file layout needs to fit pool id in 32 bits */
5340
5341 if (spec->pool_id > (u64)U32_MAX) {
5342 rbd_warn(NULL, "pool id too large (%llu > %u)",
5343 (unsigned long long)spec->pool_id, U32_MAX);
5344 rc = -EIO;
5345 goto err_out_client;
5346 }
5347
5348 rbd_dev = rbd_dev_create(rbdc, spec, rbd_opts); 5340 rbd_dev = rbd_dev_create(rbdc, spec, rbd_opts);
5349 if (!rbd_dev) { 5341 if (!rbd_dev) {
5350 rc = -ENOMEM; 5342 rc = -ENOMEM;
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 1523e05c46fc..93b1aaa5ba3b 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -391,22 +391,16 @@ static int init_vq(struct virtio_blk *vblk)
391 num_vqs = 1; 391 num_vqs = 1;
392 392
393 vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL); 393 vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL);
394 if (!vblk->vqs) { 394 if (!vblk->vqs)
395 err = -ENOMEM; 395 return -ENOMEM;
396 goto out;
397 }
398 396
399 names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL); 397 names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL);
400 if (!names)
401 goto err_names;
402
403 callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL); 398 callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL);
404 if (!callbacks)
405 goto err_callbacks;
406
407 vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL); 399 vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL);
408 if (!vqs) 400 if (!names || !callbacks || !vqs) {
409 goto err_vqs; 401 err = -ENOMEM;
402 goto out;
403 }
410 404
411 for (i = 0; i < num_vqs; i++) { 405 for (i = 0; i < num_vqs; i++) {
412 callbacks[i] = virtblk_done; 406 callbacks[i] = virtblk_done;
@@ -417,7 +411,7 @@ static int init_vq(struct virtio_blk *vblk)
417 /* Discover virtqueues and write information to configuration. */ 411 /* Discover virtqueues and write information to configuration. */
418 err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names); 412 err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names);
419 if (err) 413 if (err)
420 goto err_find_vqs; 414 goto out;
421 415
422 for (i = 0; i < num_vqs; i++) { 416 for (i = 0; i < num_vqs; i++) {
423 spin_lock_init(&vblk->vqs[i].lock); 417 spin_lock_init(&vblk->vqs[i].lock);
@@ -425,16 +419,12 @@ static int init_vq(struct virtio_blk *vblk)
425 } 419 }
426 vblk->num_vqs = num_vqs; 420 vblk->num_vqs = num_vqs;
427 421
428 err_find_vqs: 422out:
429 kfree(vqs); 423 kfree(vqs);
430 err_vqs:
431 kfree(callbacks); 424 kfree(callbacks);
432 err_callbacks:
433 kfree(names); 425 kfree(names);
434 err_names:
435 if (err) 426 if (err)
436 kfree(vblk->vqs); 427 kfree(vblk->vqs);
437 out:
438 return err; 428 return err;
439} 429}
440 430
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index be4fea6a5dd3..88ef6d4729b4 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -189,6 +189,8 @@ struct blkfront_info
189 struct mutex mutex; 189 struct mutex mutex;
190 struct xenbus_device *xbdev; 190 struct xenbus_device *xbdev;
191 struct gendisk *gd; 191 struct gendisk *gd;
192 u16 sector_size;
193 unsigned int physical_sector_size;
192 int vdevice; 194 int vdevice;
193 blkif_vdev_t handle; 195 blkif_vdev_t handle;
194 enum blkif_state connected; 196 enum blkif_state connected;
@@ -910,9 +912,45 @@ static struct blk_mq_ops blkfront_mq_ops = {
910 .map_queue = blk_mq_map_queue, 912 .map_queue = blk_mq_map_queue,
911}; 913};
912 914
915static void blkif_set_queue_limits(struct blkfront_info *info)
916{
917 struct request_queue *rq = info->rq;
918 struct gendisk *gd = info->gd;
919 unsigned int segments = info->max_indirect_segments ? :
920 BLKIF_MAX_SEGMENTS_PER_REQUEST;
921
922 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq);
923
924 if (info->feature_discard) {
925 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, rq);
926 blk_queue_max_discard_sectors(rq, get_capacity(gd));
927 rq->limits.discard_granularity = info->discard_granularity;
928 rq->limits.discard_alignment = info->discard_alignment;
929 if (info->feature_secdiscard)
930 queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, rq);
931 }
932
933 /* Hard sector size and max sectors impersonate the equiv. hardware. */
934 blk_queue_logical_block_size(rq, info->sector_size);
935 blk_queue_physical_block_size(rq, info->physical_sector_size);
936 blk_queue_max_hw_sectors(rq, (segments * XEN_PAGE_SIZE) / 512);
937
938 /* Each segment in a request is up to an aligned page in size. */
939 blk_queue_segment_boundary(rq, PAGE_SIZE - 1);
940 blk_queue_max_segment_size(rq, PAGE_SIZE);
941
942 /* Ensure a merged request will fit in a single I/O ring slot. */
943 blk_queue_max_segments(rq, segments / GRANTS_PER_PSEG);
944
945 /* Make sure buffer addresses are sector-aligned. */
946 blk_queue_dma_alignment(rq, 511);
947
948 /* Make sure we don't use bounce buffers. */
949 blk_queue_bounce_limit(rq, BLK_BOUNCE_ANY);
950}
951
913static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size, 952static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size,
914 unsigned int physical_sector_size, 953 unsigned int physical_sector_size)
915 unsigned int segments)
916{ 954{
917 struct request_queue *rq; 955 struct request_queue *rq;
918 struct blkfront_info *info = gd->private_data; 956 struct blkfront_info *info = gd->private_data;
@@ -944,36 +982,11 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size,
944 } 982 }
945 983
946 rq->queuedata = info; 984 rq->queuedata = info;
947 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq); 985 info->rq = gd->queue = rq;
948 986 info->gd = gd;
949 if (info->feature_discard) { 987 info->sector_size = sector_size;
950 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, rq); 988 info->physical_sector_size = physical_sector_size;
951 blk_queue_max_discard_sectors(rq, get_capacity(gd)); 989 blkif_set_queue_limits(info);
952 rq->limits.discard_granularity = info->discard_granularity;
953 rq->limits.discard_alignment = info->discard_alignment;
954 if (info->feature_secdiscard)
955 queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, rq);
956 }
957
958 /* Hard sector size and max sectors impersonate the equiv. hardware. */
959 blk_queue_logical_block_size(rq, sector_size);
960 blk_queue_physical_block_size(rq, physical_sector_size);
961 blk_queue_max_hw_sectors(rq, (segments * XEN_PAGE_SIZE) / 512);
962
963 /* Each segment in a request is up to an aligned page in size. */
964 blk_queue_segment_boundary(rq, PAGE_SIZE - 1);
965 blk_queue_max_segment_size(rq, PAGE_SIZE);
966
967 /* Ensure a merged request will fit in a single I/O ring slot. */
968 blk_queue_max_segments(rq, segments / GRANTS_PER_PSEG);
969
970 /* Make sure buffer addresses are sector-aligned. */
971 blk_queue_dma_alignment(rq, 511);
972
973 /* Make sure we don't use bounce buffers. */
974 blk_queue_bounce_limit(rq, BLK_BOUNCE_ANY);
975
976 gd->queue = rq;
977 990
978 return 0; 991 return 0;
979} 992}
@@ -1136,16 +1149,11 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity,
1136 gd->private_data = info; 1149 gd->private_data = info;
1137 set_capacity(gd, capacity); 1150 set_capacity(gd, capacity);
1138 1151
1139 if (xlvbd_init_blk_queue(gd, sector_size, physical_sector_size, 1152 if (xlvbd_init_blk_queue(gd, sector_size, physical_sector_size)) {
1140 info->max_indirect_segments ? :
1141 BLKIF_MAX_SEGMENTS_PER_REQUEST)) {
1142 del_gendisk(gd); 1153 del_gendisk(gd);
1143 goto release; 1154 goto release;
1144 } 1155 }
1145 1156
1146 info->rq = gd->queue;
1147 info->gd = gd;
1148
1149 xlvbd_flush(info); 1157 xlvbd_flush(info);
1150 1158
1151 if (vdisk_info & VDISK_READONLY) 1159 if (vdisk_info & VDISK_READONLY)
@@ -1315,7 +1323,7 @@ free_shadow:
1315 rinfo->ring_ref[i] = GRANT_INVALID_REF; 1323 rinfo->ring_ref[i] = GRANT_INVALID_REF;
1316 } 1324 }
1317 } 1325 }
1318 free_pages((unsigned long)rinfo->ring.sring, get_order(info->nr_ring_pages * PAGE_SIZE)); 1326 free_pages((unsigned long)rinfo->ring.sring, get_order(info->nr_ring_pages * XEN_PAGE_SIZE));
1319 rinfo->ring.sring = NULL; 1327 rinfo->ring.sring = NULL;
1320 1328
1321 if (rinfo->irq) 1329 if (rinfo->irq)
@@ -2007,8 +2015,10 @@ static int blkif_recover(struct blkfront_info *info)
2007 struct split_bio *split_bio; 2015 struct split_bio *split_bio;
2008 2016
2009 blkfront_gather_backend_features(info); 2017 blkfront_gather_backend_features(info);
2018 /* Reset limits changed by blk_mq_update_nr_hw_queues(). */
2019 blkif_set_queue_limits(info);
2010 segs = info->max_indirect_segments ? : BLKIF_MAX_SEGMENTS_PER_REQUEST; 2020 segs = info->max_indirect_segments ? : BLKIF_MAX_SEGMENTS_PER_REQUEST;
2011 blk_queue_max_segments(info->rq, segs); 2021 blk_queue_max_segments(info->rq, segs / GRANTS_PER_PSEG);
2012 2022
2013 for (r_index = 0; r_index < info->nr_rings; r_index++) { 2023 for (r_index = 0; r_index < info->nr_rings; r_index++) {
2014 struct blkfront_ring_info *rinfo = &info->rinfo[r_index]; 2024 struct blkfront_ring_info *rinfo = &info->rinfo[r_index];
@@ -2432,7 +2442,7 @@ static void blkfront_connect(struct blkfront_info *info)
2432 if (err) { 2442 if (err) {
2433 xenbus_dev_fatal(info->xbdev, err, "xlvbd_add at %s", 2443 xenbus_dev_fatal(info->xbdev, err, "xlvbd_add at %s",
2434 info->xbdev->otherend); 2444 info->xbdev->otherend);
2435 return; 2445 goto fail;
2436 } 2446 }
2437 2447
2438 xenbus_switch_state(info->xbdev, XenbusStateConnected); 2448 xenbus_switch_state(info->xbdev, XenbusStateConnected);
@@ -2445,6 +2455,11 @@ static void blkfront_connect(struct blkfront_info *info)
2445 device_add_disk(&info->xbdev->dev, info->gd); 2455 device_add_disk(&info->xbdev->dev, info->gd);
2446 2456
2447 info->is_ready = 1; 2457 info->is_ready = 1;
2458 return;
2459
2460fail:
2461 blkif_free(info, 0);
2462 return;
2448} 2463}
2449 2464
2450/** 2465/**
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 28bce3f4f81d..57700541f951 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -8,6 +8,9 @@
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11
12#define pr_fmt(fmt) "arm_arch_timer: " fmt
13
11#include <linux/init.h> 14#include <linux/init.h>
12#include <linux/kernel.h> 15#include <linux/kernel.h>
13#include <linux/device.h> 16#include <linux/device.h>
@@ -370,16 +373,33 @@ static bool arch_timer_has_nonsecure_ppi(void)
370 arch_timer_ppi[PHYS_NONSECURE_PPI]); 373 arch_timer_ppi[PHYS_NONSECURE_PPI]);
371} 374}
372 375
376static u32 check_ppi_trigger(int irq)
377{
378 u32 flags = irq_get_trigger_type(irq);
379
380 if (flags != IRQF_TRIGGER_HIGH && flags != IRQF_TRIGGER_LOW) {
381 pr_warn("WARNING: Invalid trigger for IRQ%d, assuming level low\n", irq);
382 pr_warn("WARNING: Please fix your firmware\n");
383 flags = IRQF_TRIGGER_LOW;
384 }
385
386 return flags;
387}
388
373static int arch_timer_starting_cpu(unsigned int cpu) 389static int arch_timer_starting_cpu(unsigned int cpu)
374{ 390{
375 struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt); 391 struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt);
392 u32 flags;
376 393
377 __arch_timer_setup(ARCH_CP15_TIMER, clk); 394 __arch_timer_setup(ARCH_CP15_TIMER, clk);
378 395
379 enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], 0); 396 flags = check_ppi_trigger(arch_timer_ppi[arch_timer_uses_ppi]);
397 enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], flags);
380 398
381 if (arch_timer_has_nonsecure_ppi()) 399 if (arch_timer_has_nonsecure_ppi()) {
382 enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], 0); 400 flags = check_ppi_trigger(arch_timer_ppi[PHYS_NONSECURE_PPI]);
401 enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], flags);
402 }
383 403
384 arch_counter_set_user_access(); 404 arch_counter_set_user_access();
385 if (evtstrm_enable) 405 if (evtstrm_enable)
diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
index 7e3fd375a627..92f6e4deee74 100644
--- a/drivers/clocksource/bcm_kona_timer.c
+++ b/drivers/clocksource/bcm_kona_timer.c
@@ -66,10 +66,10 @@ static void kona_timer_disable_and_clear(void __iomem *base)
66 66
67} 67}
68 68
69static void 69static int
70kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw) 70kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
71{ 71{
72 int loop_limit = 4; 72 int loop_limit = 3;
73 73
74 /* 74 /*
75 * Read 64-bit free running counter 75 * Read 64-bit free running counter
@@ -83,18 +83,19 @@ kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
83 * if new hi-word is equal to previously read hi-word then stop. 83 * if new hi-word is equal to previously read hi-word then stop.
84 */ 84 */
85 85
86 while (--loop_limit) { 86 do {
87 *msw = readl(timer_base + KONA_GPTIMER_STCHI_OFFSET); 87 *msw = readl(timer_base + KONA_GPTIMER_STCHI_OFFSET);
88 *lsw = readl(timer_base + KONA_GPTIMER_STCLO_OFFSET); 88 *lsw = readl(timer_base + KONA_GPTIMER_STCLO_OFFSET);
89 if (*msw == readl(timer_base + KONA_GPTIMER_STCHI_OFFSET)) 89 if (*msw == readl(timer_base + KONA_GPTIMER_STCHI_OFFSET))
90 break; 90 break;
91 } 91 } while (--loop_limit);
92 if (!loop_limit) { 92 if (!loop_limit) {
93 pr_err("bcm_kona_timer: getting counter failed.\n"); 93 pr_err("bcm_kona_timer: getting counter failed.\n");
94 pr_err(" Timer will be impacted\n"); 94 pr_err(" Timer will be impacted\n");
95 return -ETIMEDOUT;
95 } 96 }
96 97
97 return; 98 return 0;
98} 99}
99 100
100static int kona_timer_set_next_event(unsigned long clc, 101static int kona_timer_set_next_event(unsigned long clc,
@@ -112,8 +113,11 @@ static int kona_timer_set_next_event(unsigned long clc,
112 113
113 uint32_t lsw, msw; 114 uint32_t lsw, msw;
114 uint32_t reg; 115 uint32_t reg;
116 int ret;
115 117
116 kona_timer_get_counter(timers.tmr_regs, &msw, &lsw); 118 ret = kona_timer_get_counter(timers.tmr_regs, &msw, &lsw);
119 if (ret)
120 return ret;
117 121
118 /* Load the "next" event tick value */ 122 /* Load the "next" event tick value */
119 writel(lsw + clc, timers.tmr_regs + KONA_GPTIMER_STCM0_OFFSET); 123 writel(lsw + clc, timers.tmr_regs + KONA_GPTIMER_STCM0_OFFSET);
diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c
index d91e8725917c..b4b3ab5a11ad 100644
--- a/drivers/clocksource/mips-gic-timer.c
+++ b/drivers/clocksource/mips-gic-timer.c
@@ -164,7 +164,7 @@ void __init gic_clocksource_init(unsigned int frequency)
164 gic_start_count(); 164 gic_start_count();
165} 165}
166 166
167static void __init gic_clocksource_of_init(struct device_node *node) 167static int __init gic_clocksource_of_init(struct device_node *node)
168{ 168{
169 struct clk *clk; 169 struct clk *clk;
170 int ret; 170 int ret;
diff --git a/drivers/clocksource/pxa_timer.c b/drivers/clocksource/pxa_timer.c
index 937e10b84d58..3e1cb512f3ce 100644
--- a/drivers/clocksource/pxa_timer.c
+++ b/drivers/clocksource/pxa_timer.c
@@ -21,6 +21,8 @@
21#include <linux/of_irq.h> 21#include <linux/of_irq.h>
22#include <linux/sched_clock.h> 22#include <linux/sched_clock.h>
23 23
24#include <clocksource/pxa.h>
25
24#include <asm/div64.h> 26#include <asm/div64.h>
25 27
26#define OSMR0 0x00 /* OS Timer 0 Match Register */ 28#define OSMR0 0x00 /* OS Timer 0 Match Register */
diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c
index 97669ee4df2a..c83452cacb41 100644
--- a/drivers/clocksource/sun4i_timer.c
+++ b/drivers/clocksource/sun4i_timer.c
@@ -123,12 +123,16 @@ static struct clock_event_device sun4i_clockevent = {
123 .set_next_event = sun4i_clkevt_next_event, 123 .set_next_event = sun4i_clkevt_next_event,
124}; 124};
125 125
126static void sun4i_timer_clear_interrupt(void)
127{
128 writel(TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_ST_REG);
129}
126 130
127static irqreturn_t sun4i_timer_interrupt(int irq, void *dev_id) 131static irqreturn_t sun4i_timer_interrupt(int irq, void *dev_id)
128{ 132{
129 struct clock_event_device *evt = (struct clock_event_device *)dev_id; 133 struct clock_event_device *evt = (struct clock_event_device *)dev_id;
130 134
131 writel(0x1, timer_base + TIMER_IRQ_ST_REG); 135 sun4i_timer_clear_interrupt();
132 evt->event_handler(evt); 136 evt->event_handler(evt);
133 137
134 return IRQ_HANDLED; 138 return IRQ_HANDLED;
@@ -208,6 +212,9 @@ static int __init sun4i_timer_init(struct device_node *node)
208 /* Make sure timer is stopped before playing with interrupts */ 212 /* Make sure timer is stopped before playing with interrupts */
209 sun4i_clkevt_time_stop(0); 213 sun4i_clkevt_time_stop(0);
210 214
215 /* clear timer0 interrupt */
216 sun4i_timer_clear_interrupt();
217
211 sun4i_clockevent.cpumask = cpu_possible_mask; 218 sun4i_clockevent.cpumask = cpu_possible_mask;
212 sun4i_clockevent.irq = irq; 219 sun4i_clockevent.irq = irq;
213 220
diff --git a/drivers/clocksource/time-armada-370-xp.c b/drivers/clocksource/time-armada-370-xp.c
index 719b478d136e..3c39e6f45971 100644
--- a/drivers/clocksource/time-armada-370-xp.c
+++ b/drivers/clocksource/time-armada-370-xp.c
@@ -338,7 +338,6 @@ static int __init armada_xp_timer_init(struct device_node *np)
338 struct clk *clk = of_clk_get_by_name(np, "fixed"); 338 struct clk *clk = of_clk_get_by_name(np, "fixed");
339 int ret; 339 int ret;
340 340
341 clk = of_clk_get(np, 0);
342 if (IS_ERR(clk)) { 341 if (IS_ERR(clk)) {
343 pr_err("Failed to get clock"); 342 pr_err("Failed to get clock");
344 return PTR_ERR(clk); 343 return PTR_ERR(clk);
diff --git a/drivers/clocksource/time-pistachio.c b/drivers/clocksource/time-pistachio.c
index a7d9a08e4b0e..a8e6c7df853d 100644
--- a/drivers/clocksource/time-pistachio.c
+++ b/drivers/clocksource/time-pistachio.c
@@ -202,10 +202,10 @@ static int __init pistachio_clksrc_of_init(struct device_node *node)
202 rate = clk_get_rate(fast_clk); 202 rate = clk_get_rate(fast_clk);
203 203
204 /* Disable irq's for clocksource usage */ 204 /* Disable irq's for clocksource usage */
205 gpt_writel(&pcs_gpt.base, 0, TIMER_IRQ_MASK, 0); 205 gpt_writel(pcs_gpt.base, 0, TIMER_IRQ_MASK, 0);
206 gpt_writel(&pcs_gpt.base, 0, TIMER_IRQ_MASK, 1); 206 gpt_writel(pcs_gpt.base, 0, TIMER_IRQ_MASK, 1);
207 gpt_writel(&pcs_gpt.base, 0, TIMER_IRQ_MASK, 2); 207 gpt_writel(pcs_gpt.base, 0, TIMER_IRQ_MASK, 2);
208 gpt_writel(&pcs_gpt.base, 0, TIMER_IRQ_MASK, 3); 208 gpt_writel(pcs_gpt.base, 0, TIMER_IRQ_MASK, 3);
209 209
210 /* Enable timer block */ 210 /* Enable timer block */
211 writel(TIMER_ME_GLOBAL, pcs_gpt.base); 211 writel(TIMER_ME_GLOBAL, pcs_gpt.base);
diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index 1ffac0cb0cb7..3494bc5a21d5 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -261,6 +261,12 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
261 return PTR_ERR(data->mck); 261 return PTR_ERR(data->mck);
262 } 262 }
263 263
264 ret = clk_prepare_enable(data->mck);
265 if (ret) {
266 pr_err("Unable to enable mck\n");
267 return ret;
268 }
269
264 /* Get the interrupts property */ 270 /* Get the interrupts property */
265 data->irq = irq_of_parse_and_map(node, 0); 271 data->irq = irq_of_parse_and_map(node, 0);
266 if (!data->irq) { 272 if (!data->irq) {
diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 87796e0864e9..d3ffde806629 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -145,11 +145,30 @@ static struct powernv_pstate_info {
145/* Use following macros for conversions between pstate_id and index */ 145/* Use following macros for conversions between pstate_id and index */
146static inline int idx_to_pstate(unsigned int i) 146static inline int idx_to_pstate(unsigned int i)
147{ 147{
148 if (unlikely(i >= powernv_pstate_info.nr_pstates)) {
149 pr_warn_once("index %u is out of bound\n", i);
150 return powernv_freqs[powernv_pstate_info.nominal].driver_data;
151 }
152
148 return powernv_freqs[i].driver_data; 153 return powernv_freqs[i].driver_data;
149} 154}
150 155
151static inline unsigned int pstate_to_idx(int pstate) 156static inline unsigned int pstate_to_idx(int pstate)
152{ 157{
158 int min = powernv_freqs[powernv_pstate_info.min].driver_data;
159 int max = powernv_freqs[powernv_pstate_info.max].driver_data;
160
161 if (min > 0) {
162 if (unlikely((pstate < max) || (pstate > min))) {
163 pr_warn_once("pstate %d is out of bound\n", pstate);
164 return powernv_pstate_info.nominal;
165 }
166 } else {
167 if (unlikely((pstate > max) || (pstate < min))) {
168 pr_warn_once("pstate %d is out of bound\n", pstate);
169 return powernv_pstate_info.nominal;
170 }
171 }
153 /* 172 /*
154 * abs() is deliberately used so that is works with 173 * abs() is deliberately used so that is works with
155 * both monotonically increasing and decreasing 174 * both monotonically increasing and decreasing
@@ -593,7 +612,7 @@ void gpstate_timer_handler(unsigned long data)
593 } else { 612 } else {
594 gpstate_idx = calc_global_pstate(gpstates->elapsed_time, 613 gpstate_idx = calc_global_pstate(gpstates->elapsed_time,
595 gpstates->highest_lpstate_idx, 614 gpstates->highest_lpstate_idx,
596 freq_data.pstate_id); 615 gpstates->last_lpstate_idx);
597 } 616 }
598 617
599 /* 618 /*
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index ea8189f4b021..6dc597126b79 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -441,6 +441,9 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
441 OP_ALG_AAI_CTR_MOD128); 441 OP_ALG_AAI_CTR_MOD128);
442 const bool is_rfc3686 = alg->caam.rfc3686; 442 const bool is_rfc3686 = alg->caam.rfc3686;
443 443
444 if (!ctx->authsize)
445 return 0;
446
444 /* NULL encryption / decryption */ 447 /* NULL encryption / decryption */
445 if (!ctx->enckeylen) 448 if (!ctx->enckeylen)
446 return aead_null_set_sh_desc(aead); 449 return aead_null_set_sh_desc(aead);
@@ -614,7 +617,7 @@ skip_enc:
614 keys_fit_inline = true; 617 keys_fit_inline = true;
615 618
616 /* aead_givencrypt shared descriptor */ 619 /* aead_givencrypt shared descriptor */
617 desc = ctx->sh_desc_givenc; 620 desc = ctx->sh_desc_enc;
618 621
619 /* Note: Context registers are saved. */ 622 /* Note: Context registers are saved. */
620 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686); 623 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
@@ -645,13 +648,13 @@ copy_iv:
645 append_operation(desc, ctx->class2_alg_type | 648 append_operation(desc, ctx->class2_alg_type |
646 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT); 649 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
647 650
648 /* ivsize + cryptlen = seqoutlen - authsize */
649 append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize);
650
651 /* Read and write assoclen bytes */ 651 /* Read and write assoclen bytes */
652 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ); 652 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
653 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ); 653 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
654 654
655 /* ivsize + cryptlen = seqoutlen - authsize */
656 append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize);
657
655 /* Skip assoc data */ 658 /* Skip assoc data */
656 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF); 659 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
657 660
@@ -697,7 +700,7 @@ copy_iv:
697 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc, 700 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
698 desc_bytes(desc), 701 desc_bytes(desc),
699 DMA_TO_DEVICE); 702 DMA_TO_DEVICE);
700 if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) { 703 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
701 dev_err(jrdev, "unable to map shared descriptor\n"); 704 dev_err(jrdev, "unable to map shared descriptor\n");
702 return -ENOMEM; 705 return -ENOMEM;
703 } 706 }
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index f1ecc8df8d41..36365b3efdfd 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1898,6 +1898,7 @@ caam_hash_alloc(struct caam_hash_template *template,
1898 template->name); 1898 template->name);
1899 snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", 1899 snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
1900 template->driver_name); 1900 template->driver_name);
1901 t_alg->ahash_alg.setkey = NULL;
1901 } 1902 }
1902 alg->cra_module = THIS_MODULE; 1903 alg->cra_module = THIS_MODULE;
1903 alg->cra_init = caam_hash_cra_init; 1904 alg->cra_init = caam_hash_cra_init;
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index dfb168568af1..1f01e98c83c7 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -116,6 +116,9 @@ static int dax_pmem_probe(struct device *dev)
116 if (rc) 116 if (rc)
117 return rc; 117 return rc;
118 118
119 /* adjust the dax_region resource to the start of data */
120 res.start += le64_to_cpu(pfn_sb->dataoff);
121
119 nd_region = to_nd_region(dev->parent); 122 nd_region = to_nd_region(dev->parent);
120 dax_region = alloc_dax_region(dev, nd_region->id, &res, 123 dax_region = alloc_dax_region(dev, nd_region->id, &res,
121 le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP); 124 le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP);
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index d0c1dab9b435..dff1a4a6dc1b 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -251,6 +251,14 @@ config EDAC_SBRIDGE
251 Support for error detection and correction the Intel 251 Support for error detection and correction the Intel
252 Sandy Bridge, Ivy Bridge and Haswell Integrated Memory Controllers. 252 Sandy Bridge, Ivy Bridge and Haswell Integrated Memory Controllers.
253 253
254config EDAC_SKX
255 tristate "Intel Skylake server Integrated MC"
256 depends on EDAC_MM_EDAC && PCI && X86_64 && X86_MCE_INTEL
257 depends on PCI_MMCONFIG
258 help
259 Support for error detection and correction the Intel
260 Skylake server Integrated Memory Controllers.
261
254config EDAC_MPC85XX 262config EDAC_MPC85XX
255 tristate "Freescale MPC83xx / MPC85xx" 263 tristate "Freescale MPC83xx / MPC85xx"
256 depends on EDAC_MM_EDAC && FSL_SOC 264 depends on EDAC_MM_EDAC && FSL_SOC
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index f9e4a3e0e6e9..986049925b08 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_EDAC_I5400) += i5400_edac.o
31obj-$(CONFIG_EDAC_I7300) += i7300_edac.o 31obj-$(CONFIG_EDAC_I7300) += i7300_edac.o
32obj-$(CONFIG_EDAC_I7CORE) += i7core_edac.o 32obj-$(CONFIG_EDAC_I7CORE) += i7core_edac.o
33obj-$(CONFIG_EDAC_SBRIDGE) += sb_edac.o 33obj-$(CONFIG_EDAC_SBRIDGE) += sb_edac.o
34obj-$(CONFIG_EDAC_SKX) += skx_edac.o
34obj-$(CONFIG_EDAC_E7XXX) += e7xxx_edac.o 35obj-$(CONFIG_EDAC_E7XXX) += e7xxx_edac.o
35obj-$(CONFIG_EDAC_E752X) += e752x_edac.o 36obj-$(CONFIG_EDAC_E752X) += e752x_edac.o
36obj-$(CONFIG_EDAC_I82443BXGX) += i82443bxgx_edac.o 37obj-$(CONFIG_EDAC_I82443BXGX) += i82443bxgx_edac.o
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index 4fb2eb7c800d..ce0067b7a2f6 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -552,9 +552,9 @@ static const struct pci_id_table pci_dev_descr_haswell_table[] = {
552/* Knight's Landing Support */ 552/* Knight's Landing Support */
553/* 553/*
554 * KNL's memory channels are swizzled between memory controllers. 554 * KNL's memory channels are swizzled between memory controllers.
555 * MC0 is mapped to CH3,5,6 and MC1 is mapped to CH0,1,2 555 * MC0 is mapped to CH3,4,5 and MC1 is mapped to CH0,1,2
556 */ 556 */
557#define knl_channel_remap(channel) ((channel + 3) % 6) 557#define knl_channel_remap(mc, chan) ((mc) ? (chan) : (chan) + 3)
558 558
559/* Memory controller, TAD tables, error injection - 2-8-0, 2-9-0 (2 of these) */ 559/* Memory controller, TAD tables, error injection - 2-8-0, 2-9-0 (2 of these) */
560#define PCI_DEVICE_ID_INTEL_KNL_IMC_MC 0x7840 560#define PCI_DEVICE_ID_INTEL_KNL_IMC_MC 0x7840
@@ -1286,7 +1286,7 @@ static u32 knl_get_mc_route(int entry, u32 reg)
1286 mc = GET_BITFIELD(reg, entry*3, (entry*3)+2); 1286 mc = GET_BITFIELD(reg, entry*3, (entry*3)+2);
1287 chan = GET_BITFIELD(reg, (entry*2) + 18, (entry*2) + 18 + 1); 1287 chan = GET_BITFIELD(reg, (entry*2) + 18, (entry*2) + 18 + 1);
1288 1288
1289 return knl_channel_remap(mc*3 + chan); 1289 return knl_channel_remap(mc, chan);
1290} 1290}
1291 1291
1292/* 1292/*
@@ -2997,8 +2997,15 @@ static void sbridge_mce_output_error(struct mem_ctl_info *mci,
2997 } else { 2997 } else {
2998 char A = *("A"); 2998 char A = *("A");
2999 2999
3000 channel = knl_channel_remap(channel); 3000 /*
3001 * Reported channel is in range 0-2, so we can't map it
3002 * back to mc. To figure out mc we check machine check
3003 * bank register that reported this error.
3004 * bank15 means mc0 and bank16 means mc1.
3005 */
3006 channel = knl_channel_remap(m->bank == 16, channel);
3001 channel_mask = 1 << channel; 3007 channel_mask = 1 << channel;
3008
3002 snprintf(msg, sizeof(msg), 3009 snprintf(msg, sizeof(msg),
3003 "%s%s err_code:%04x:%04x channel:%d (DIMM_%c)", 3010 "%s%s err_code:%04x:%04x channel:%d (DIMM_%c)",
3004 overflow ? " OVERFLOW" : "", 3011 overflow ? " OVERFLOW" : "",
diff --git a/drivers/edac/skx_edac.c b/drivers/edac/skx_edac.c
new file mode 100644
index 000000000000..0ff4878c2aa1
--- /dev/null
+++ b/drivers/edac/skx_edac.c
@@ -0,0 +1,1121 @@
1/*
2 * EDAC driver for Intel(R) Xeon(R) Skylake processors
3 * Copyright (c) 2016, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/pci.h>
18#include <linux/pci_ids.h>
19#include <linux/slab.h>
20#include <linux/delay.h>
21#include <linux/edac.h>
22#include <linux/mmzone.h>
23#include <linux/smp.h>
24#include <linux/bitmap.h>
25#include <linux/math64.h>
26#include <linux/mod_devicetable.h>
27#include <asm/cpu_device_id.h>
28#include <asm/processor.h>
29#include <asm/mce.h>
30
31#include "edac_core.h"
32
33#define SKX_REVISION " Ver: 1.0 "
34
35/*
36 * Debug macros
37 */
38#define skx_printk(level, fmt, arg...) \
39 edac_printk(level, "skx", fmt, ##arg)
40
41#define skx_mc_printk(mci, level, fmt, arg...) \
42 edac_mc_chipset_printk(mci, level, "skx", fmt, ##arg)
43
44/*
45 * Get a bit field at register value <v>, from bit <lo> to bit <hi>
46 */
47#define GET_BITFIELD(v, lo, hi) \
48 (((v) & GENMASK_ULL((hi), (lo))) >> (lo))
49
50static LIST_HEAD(skx_edac_list);
51
52static u64 skx_tolm, skx_tohm;
53
54#define NUM_IMC 2 /* memory controllers per socket */
55#define NUM_CHANNELS 3 /* channels per memory controller */
56#define NUM_DIMMS 2 /* Max DIMMS per channel */
57
58#define MASK26 0x3FFFFFF /* Mask for 2^26 */
59#define MASK29 0x1FFFFFFF /* Mask for 2^29 */
60
61/*
62 * Each cpu socket contains some pci devices that provide global
63 * information, and also some that are local to each of the two
64 * memory controllers on the die.
65 */
66struct skx_dev {
67 struct list_head list;
68 u8 bus[4];
69 struct pci_dev *sad_all;
70 struct pci_dev *util_all;
71 u32 mcroute;
72 struct skx_imc {
73 struct mem_ctl_info *mci;
74 u8 mc; /* system wide mc# */
75 u8 lmc; /* socket relative mc# */
76 u8 src_id, node_id;
77 struct skx_channel {
78 struct pci_dev *cdev;
79 struct skx_dimm {
80 u8 close_pg;
81 u8 bank_xor_enable;
82 u8 fine_grain_bank;
83 u8 rowbits;
84 u8 colbits;
85 } dimms[NUM_DIMMS];
86 } chan[NUM_CHANNELS];
87 } imc[NUM_IMC];
88};
89static int skx_num_sockets;
90
91struct skx_pvt {
92 struct skx_imc *imc;
93};
94
95struct decoded_addr {
96 struct skx_dev *dev;
97 u64 addr;
98 int socket;
99 int imc;
100 int channel;
101 u64 chan_addr;
102 int sktways;
103 int chanways;
104 int dimm;
105 int rank;
106 int channel_rank;
107 u64 rank_address;
108 int row;
109 int column;
110 int bank_address;
111 int bank_group;
112};
113
114static struct skx_dev *get_skx_dev(u8 bus, u8 idx)
115{
116 struct skx_dev *d;
117
118 list_for_each_entry(d, &skx_edac_list, list) {
119 if (d->bus[idx] == bus)
120 return d;
121 }
122
123 return NULL;
124}
125
126enum munittype {
127 CHAN0, CHAN1, CHAN2, SAD_ALL, UTIL_ALL, SAD
128};
129
130struct munit {
131 u16 did;
132 u16 devfn[NUM_IMC];
133 u8 busidx;
134 u8 per_socket;
135 enum munittype mtype;
136};
137
138/*
139 * List of PCI device ids that we need together with some device
140 * number and function numbers to tell which memory controller the
141 * device belongs to.
142 */
143static const struct munit skx_all_munits[] = {
144 { 0x2054, { }, 1, 1, SAD_ALL },
145 { 0x2055, { }, 1, 1, UTIL_ALL },
146 { 0x2040, { PCI_DEVFN(10, 0), PCI_DEVFN(12, 0) }, 2, 2, CHAN0 },
147 { 0x2044, { PCI_DEVFN(10, 4), PCI_DEVFN(12, 4) }, 2, 2, CHAN1 },
148 { 0x2048, { PCI_DEVFN(11, 0), PCI_DEVFN(13, 0) }, 2, 2, CHAN2 },
149 { 0x208e, { }, 1, 0, SAD },
150 { }
151};
152
153/*
154 * We use the per-socket device 0x2016 to count how many sockets are present,
155 * and to detemine which PCI buses are associated with each socket. Allocate
156 * and build the full list of all the skx_dev structures that we need here.
157 */
158static int get_all_bus_mappings(void)
159{
160 struct pci_dev *pdev, *prev;
161 struct skx_dev *d;
162 u32 reg;
163 int ndev = 0;
164
165 prev = NULL;
166 for (;;) {
167 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2016, prev);
168 if (!pdev)
169 break;
170 ndev++;
171 d = kzalloc(sizeof(*d), GFP_KERNEL);
172 if (!d) {
173 pci_dev_put(pdev);
174 return -ENOMEM;
175 }
176 pci_read_config_dword(pdev, 0xCC, &reg);
177 d->bus[0] = GET_BITFIELD(reg, 0, 7);
178 d->bus[1] = GET_BITFIELD(reg, 8, 15);
179 d->bus[2] = GET_BITFIELD(reg, 16, 23);
180 d->bus[3] = GET_BITFIELD(reg, 24, 31);
181 edac_dbg(2, "busses: %x, %x, %x, %x\n",
182 d->bus[0], d->bus[1], d->bus[2], d->bus[3]);
183 list_add_tail(&d->list, &skx_edac_list);
184 skx_num_sockets++;
185 prev = pdev;
186 }
187
188 return ndev;
189}
190
191static int get_all_munits(const struct munit *m)
192{
193 struct pci_dev *pdev, *prev;
194 struct skx_dev *d;
195 u32 reg;
196 int i = 0, ndev = 0;
197
198 prev = NULL;
199 for (;;) {
200 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, m->did, prev);
201 if (!pdev)
202 break;
203 ndev++;
204 if (m->per_socket == NUM_IMC) {
205 for (i = 0; i < NUM_IMC; i++)
206 if (m->devfn[i] == pdev->devfn)
207 break;
208 if (i == NUM_IMC)
209 goto fail;
210 }
211 d = get_skx_dev(pdev->bus->number, m->busidx);
212 if (!d)
213 goto fail;
214
215 /* Be sure that the device is enabled */
216 if (unlikely(pci_enable_device(pdev) < 0)) {
217 skx_printk(KERN_ERR,
218 "Couldn't enable %04x:%04x\n", PCI_VENDOR_ID_INTEL, m->did);
219 goto fail;
220 }
221
222 switch (m->mtype) {
223 case CHAN0: case CHAN1: case CHAN2:
224 pci_dev_get(pdev);
225 d->imc[i].chan[m->mtype].cdev = pdev;
226 break;
227 case SAD_ALL:
228 pci_dev_get(pdev);
229 d->sad_all = pdev;
230 break;
231 case UTIL_ALL:
232 pci_dev_get(pdev);
233 d->util_all = pdev;
234 break;
235 case SAD:
236 /*
237 * one of these devices per core, including cores
238 * that don't exist on this SKU. Ignore any that
239 * read a route table of zero, make sure all the
240 * non-zero values match.
241 */
242 pci_read_config_dword(pdev, 0xB4, &reg);
243 if (reg != 0) {
244 if (d->mcroute == 0)
245 d->mcroute = reg;
246 else if (d->mcroute != reg) {
247 skx_printk(KERN_ERR,
248 "mcroute mismatch\n");
249 goto fail;
250 }
251 }
252 ndev--;
253 break;
254 }
255
256 prev = pdev;
257 }
258
259 return ndev;
260fail:
261 pci_dev_put(pdev);
262 return -ENODEV;
263}
264
265const struct x86_cpu_id skx_cpuids[] = {
266 { X86_VENDOR_INTEL, 6, 0x55, 0, 0 }, /* Skylake */
267 { }
268};
269MODULE_DEVICE_TABLE(x86cpu, skx_cpuids);
270
271static u8 get_src_id(struct skx_dev *d)
272{
273 u32 reg;
274
275 pci_read_config_dword(d->util_all, 0xF0, &reg);
276
277 return GET_BITFIELD(reg, 12, 14);
278}
279
280static u8 skx_get_node_id(struct skx_dev *d)
281{
282 u32 reg;
283
284 pci_read_config_dword(d->util_all, 0xF4, &reg);
285
286 return GET_BITFIELD(reg, 0, 2);
287}
288
289static int get_dimm_attr(u32 reg, int lobit, int hibit, int add, int minval,
290 int maxval, char *name)
291{
292 u32 val = GET_BITFIELD(reg, lobit, hibit);
293
294 if (val < minval || val > maxval) {
295 edac_dbg(2, "bad %s = %d (raw=%x)\n", name, val, reg);
296 return -EINVAL;
297 }
298 return val + add;
299}
300
301#define IS_DIMM_PRESENT(mtr) GET_BITFIELD((mtr), 15, 15)
302
303#define numrank(reg) get_dimm_attr((reg), 12, 13, 0, 1, 2, "ranks")
304#define numrow(reg) get_dimm_attr((reg), 2, 4, 12, 1, 6, "rows")
305#define numcol(reg) get_dimm_attr((reg), 0, 1, 10, 0, 2, "cols")
306
307static int get_width(u32 mtr)
308{
309 switch (GET_BITFIELD(mtr, 8, 9)) {
310 case 0:
311 return DEV_X4;
312 case 1:
313 return DEV_X8;
314 case 2:
315 return DEV_X16;
316 }
317 return DEV_UNKNOWN;
318}
319
320static int skx_get_hi_lo(void)
321{
322 struct pci_dev *pdev;
323 u32 reg;
324
325 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2034, NULL);
326 if (!pdev) {
327 edac_dbg(0, "Can't get tolm/tohm\n");
328 return -ENODEV;
329 }
330
331 pci_read_config_dword(pdev, 0xD0, &reg);
332 skx_tolm = reg;
333 pci_read_config_dword(pdev, 0xD4, &reg);
334 skx_tohm = reg;
335 pci_read_config_dword(pdev, 0xD8, &reg);
336 skx_tohm |= (u64)reg << 32;
337
338 pci_dev_put(pdev);
339 edac_dbg(2, "tolm=%llx tohm=%llx\n", skx_tolm, skx_tohm);
340
341 return 0;
342}
343
344static int get_dimm_info(u32 mtr, u32 amap, struct dimm_info *dimm,
345 struct skx_imc *imc, int chan, int dimmno)
346{
347 int banks = 16, ranks, rows, cols, npages;
348 u64 size;
349
350 if (!IS_DIMM_PRESENT(mtr))
351 return 0;
352 ranks = numrank(mtr);
353 rows = numrow(mtr);
354 cols = numcol(mtr);
355
356 /*
357 * Compute size in 8-byte (2^3) words, then shift to MiB (2^20)
358 */
359 size = ((1ull << (rows + cols + ranks)) * banks) >> (20 - 3);
360 npages = MiB_TO_PAGES(size);
361
362 edac_dbg(0, "mc#%d: channel %d, dimm %d, %lld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n",
363 imc->mc, chan, dimmno, size, npages,
364 banks, ranks, rows, cols);
365
366 imc->chan[chan].dimms[dimmno].close_pg = GET_BITFIELD(mtr, 0, 0);
367 imc->chan[chan].dimms[dimmno].bank_xor_enable = GET_BITFIELD(mtr, 9, 9);
368 imc->chan[chan].dimms[dimmno].fine_grain_bank = GET_BITFIELD(amap, 0, 0);
369 imc->chan[chan].dimms[dimmno].rowbits = rows;
370 imc->chan[chan].dimms[dimmno].colbits = cols;
371
372 dimm->nr_pages = npages;
373 dimm->grain = 32;
374 dimm->dtype = get_width(mtr);
375 dimm->mtype = MEM_DDR4;
376 dimm->edac_mode = EDAC_SECDED; /* likely better than this */
377 snprintf(dimm->label, sizeof(dimm->label), "CPU_SrcID#%u_MC#%u_Chan#%u_DIMM#%u",
378 imc->src_id, imc->lmc, chan, dimmno);
379
380 return 1;
381}
382
383#define SKX_GET_MTMTR(dev, reg) \
384 pci_read_config_dword((dev), 0x87c, &reg)
385
386static bool skx_check_ecc(struct pci_dev *pdev)
387{
388 u32 mtmtr;
389
390 SKX_GET_MTMTR(pdev, mtmtr);
391
392 return !!GET_BITFIELD(mtmtr, 2, 2);
393}
394
395static int skx_get_dimm_config(struct mem_ctl_info *mci)
396{
397 struct skx_pvt *pvt = mci->pvt_info;
398 struct skx_imc *imc = pvt->imc;
399 struct dimm_info *dimm;
400 int i, j;
401 u32 mtr, amap;
402 int ndimms;
403
404 for (i = 0; i < NUM_CHANNELS; i++) {
405 ndimms = 0;
406 pci_read_config_dword(imc->chan[i].cdev, 0x8C, &amap);
407 for (j = 0; j < NUM_DIMMS; j++) {
408 dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
409 mci->n_layers, i, j, 0);
410 pci_read_config_dword(imc->chan[i].cdev,
411 0x80 + 4*j, &mtr);
412 ndimms += get_dimm_info(mtr, amap, dimm, imc, i, j);
413 }
414 if (ndimms && !skx_check_ecc(imc->chan[0].cdev)) {
415 skx_printk(KERN_ERR, "ECC is disabled on imc %d\n", imc->mc);
416 return -ENODEV;
417 }
418 }
419
420 return 0;
421}
422
423static void skx_unregister_mci(struct skx_imc *imc)
424{
425 struct mem_ctl_info *mci = imc->mci;
426
427 if (!mci)
428 return;
429
430 edac_dbg(0, "MC%d: mci = %p\n", imc->mc, mci);
431
432 /* Remove MC sysfs nodes */
433 edac_mc_del_mc(mci->pdev);
434
435 edac_dbg(1, "%s: free mci struct\n", mci->ctl_name);
436 kfree(mci->ctl_name);
437 edac_mc_free(mci);
438}
439
440static int skx_register_mci(struct skx_imc *imc)
441{
442 struct mem_ctl_info *mci;
443 struct edac_mc_layer layers[2];
444 struct pci_dev *pdev = imc->chan[0].cdev;
445 struct skx_pvt *pvt;
446 int rc;
447
448 /* allocate a new MC control structure */
449 layers[0].type = EDAC_MC_LAYER_CHANNEL;
450 layers[0].size = NUM_CHANNELS;
451 layers[0].is_virt_csrow = false;
452 layers[1].type = EDAC_MC_LAYER_SLOT;
453 layers[1].size = NUM_DIMMS;
454 layers[1].is_virt_csrow = true;
455 mci = edac_mc_alloc(imc->mc, ARRAY_SIZE(layers), layers,
456 sizeof(struct skx_pvt));
457
458 if (unlikely(!mci))
459 return -ENOMEM;
460
461 edac_dbg(0, "MC#%d: mci = %p\n", imc->mc, mci);
462
463 /* Associate skx_dev and mci for future usage */
464 imc->mci = mci;
465 pvt = mci->pvt_info;
466 pvt->imc = imc;
467
468 mci->ctl_name = kasprintf(GFP_KERNEL, "Skylake Socket#%d IMC#%d",
469 imc->node_id, imc->lmc);
470 mci->mtype_cap = MEM_FLAG_DDR4;
471 mci->edac_ctl_cap = EDAC_FLAG_NONE;
472 mci->edac_cap = EDAC_FLAG_NONE;
473 mci->mod_name = "skx_edac.c";
474 mci->dev_name = pci_name(imc->chan[0].cdev);
475 mci->mod_ver = SKX_REVISION;
476 mci->ctl_page_to_phys = NULL;
477
478 rc = skx_get_dimm_config(mci);
479 if (rc < 0)
480 goto fail;
481
482 /* record ptr to the generic device */
483 mci->pdev = &pdev->dev;
484
485 /* add this new MC control structure to EDAC's list of MCs */
486 if (unlikely(edac_mc_add_mc(mci))) {
487 edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
488 rc = -EINVAL;
489 goto fail;
490 }
491
492 return 0;
493
494fail:
495 kfree(mci->ctl_name);
496 edac_mc_free(mci);
497 imc->mci = NULL;
498 return rc;
499}
500
501#define SKX_MAX_SAD 24
502
503#define SKX_GET_SAD(d, i, reg) \
504 pci_read_config_dword((d)->sad_all, 0x60 + 8 * (i), &reg)
505#define SKX_GET_ILV(d, i, reg) \
506 pci_read_config_dword((d)->sad_all, 0x64 + 8 * (i), &reg)
507
508#define SKX_SAD_MOD3MODE(sad) GET_BITFIELD((sad), 30, 31)
509#define SKX_SAD_MOD3(sad) GET_BITFIELD((sad), 27, 27)
510#define SKX_SAD_LIMIT(sad) (((u64)GET_BITFIELD((sad), 7, 26) << 26) | MASK26)
511#define SKX_SAD_MOD3ASMOD2(sad) GET_BITFIELD((sad), 5, 6)
512#define SKX_SAD_ATTR(sad) GET_BITFIELD((sad), 3, 4)
513#define SKX_SAD_INTERLEAVE(sad) GET_BITFIELD((sad), 1, 2)
514#define SKX_SAD_ENABLE(sad) GET_BITFIELD((sad), 0, 0)
515
516#define SKX_ILV_REMOTE(tgt) (((tgt) & 8) == 0)
517#define SKX_ILV_TARGET(tgt) ((tgt) & 7)
518
519static bool skx_sad_decode(struct decoded_addr *res)
520{
521 struct skx_dev *d = list_first_entry(&skx_edac_list, typeof(*d), list);
522 u64 addr = res->addr;
523 int i, idx, tgt, lchan, shift;
524 u32 sad, ilv;
525 u64 limit, prev_limit;
526 int remote = 0;
527
528 /* Simple sanity check for I/O space or out of range */
529 if (addr >= skx_tohm || (addr >= skx_tolm && addr < BIT_ULL(32))) {
530 edac_dbg(0, "Address %llx out of range\n", addr);
531 return false;
532 }
533
534restart:
535 prev_limit = 0;
536 for (i = 0; i < SKX_MAX_SAD; i++) {
537 SKX_GET_SAD(d, i, sad);
538 limit = SKX_SAD_LIMIT(sad);
539 if (SKX_SAD_ENABLE(sad)) {
540 if (addr >= prev_limit && addr <= limit)
541 goto sad_found;
542 }
543 prev_limit = limit + 1;
544 }
545 edac_dbg(0, "No SAD entry for %llx\n", addr);
546 return false;
547
548sad_found:
549 SKX_GET_ILV(d, i, ilv);
550
551 switch (SKX_SAD_INTERLEAVE(sad)) {
552 case 0:
553 idx = GET_BITFIELD(addr, 6, 8);
554 break;
555 case 1:
556 idx = GET_BITFIELD(addr, 8, 10);
557 break;
558 case 2:
559 idx = GET_BITFIELD(addr, 12, 14);
560 break;
561 case 3:
562 idx = GET_BITFIELD(addr, 30, 32);
563 break;
564 }
565
566 tgt = GET_BITFIELD(ilv, 4 * idx, 4 * idx + 3);
567
568 /* If point to another node, find it and start over */
569 if (SKX_ILV_REMOTE(tgt)) {
570 if (remote) {
571 edac_dbg(0, "Double remote!\n");
572 return false;
573 }
574 remote = 1;
575 list_for_each_entry(d, &skx_edac_list, list) {
576 if (d->imc[0].src_id == SKX_ILV_TARGET(tgt))
577 goto restart;
578 }
579 edac_dbg(0, "Can't find node %d\n", SKX_ILV_TARGET(tgt));
580 return false;
581 }
582
583 if (SKX_SAD_MOD3(sad) == 0)
584 lchan = SKX_ILV_TARGET(tgt);
585 else {
586 switch (SKX_SAD_MOD3MODE(sad)) {
587 case 0:
588 shift = 6;
589 break;
590 case 1:
591 shift = 8;
592 break;
593 case 2:
594 shift = 12;
595 break;
596 default:
597 edac_dbg(0, "illegal mod3mode\n");
598 return false;
599 }
600 switch (SKX_SAD_MOD3ASMOD2(sad)) {
601 case 0:
602 lchan = (addr >> shift) % 3;
603 break;
604 case 1:
605 lchan = (addr >> shift) % 2;
606 break;
607 case 2:
608 lchan = (addr >> shift) % 2;
609 lchan = (lchan << 1) | ~lchan;
610 break;
611 case 3:
612 lchan = ((addr >> shift) % 2) << 1;
613 break;
614 }
615 lchan = (lchan << 1) | (SKX_ILV_TARGET(tgt) & 1);
616 }
617
618 res->dev = d;
619 res->socket = d->imc[0].src_id;
620 res->imc = GET_BITFIELD(d->mcroute, lchan * 3, lchan * 3 + 2);
621 res->channel = GET_BITFIELD(d->mcroute, lchan * 2 + 18, lchan * 2 + 19);
622
623 edac_dbg(2, "%llx: socket=%d imc=%d channel=%d\n",
624 res->addr, res->socket, res->imc, res->channel);
625 return true;
626}
627
628#define SKX_MAX_TAD 8
629
630#define SKX_GET_TADBASE(d, mc, i, reg) \
631 pci_read_config_dword((d)->imc[mc].chan[0].cdev, 0x850 + 4 * (i), &reg)
632#define SKX_GET_TADWAYNESS(d, mc, i, reg) \
633 pci_read_config_dword((d)->imc[mc].chan[0].cdev, 0x880 + 4 * (i), &reg)
634#define SKX_GET_TADCHNILVOFFSET(d, mc, ch, i, reg) \
635 pci_read_config_dword((d)->imc[mc].chan[ch].cdev, 0x90 + 4 * (i), &reg)
636
637#define SKX_TAD_BASE(b) ((u64)GET_BITFIELD((b), 12, 31) << 26)
638#define SKX_TAD_SKT_GRAN(b) GET_BITFIELD((b), 4, 5)
639#define SKX_TAD_CHN_GRAN(b) GET_BITFIELD((b), 6, 7)
640#define SKX_TAD_LIMIT(b) (((u64)GET_BITFIELD((b), 12, 31) << 26) | MASK26)
641#define SKX_TAD_OFFSET(b) ((u64)GET_BITFIELD((b), 4, 23) << 26)
642#define SKX_TAD_SKTWAYS(b) (1 << GET_BITFIELD((b), 10, 11))
643#define SKX_TAD_CHNWAYS(b) (GET_BITFIELD((b), 8, 9) + 1)
644
645/* which bit used for both socket and channel interleave */
646static int skx_granularity[] = { 6, 8, 12, 30 };
647
648static u64 skx_do_interleave(u64 addr, int shift, int ways, u64 lowbits)
649{
650 addr >>= shift;
651 addr /= ways;
652 addr <<= shift;
653
654 return addr | (lowbits & ((1ull << shift) - 1));
655}
656
657static bool skx_tad_decode(struct decoded_addr *res)
658{
659 int i;
660 u32 base, wayness, chnilvoffset;
661 int skt_interleave_bit, chn_interleave_bit;
662 u64 channel_addr;
663
664 for (i = 0; i < SKX_MAX_TAD; i++) {
665 SKX_GET_TADBASE(res->dev, res->imc, i, base);
666 SKX_GET_TADWAYNESS(res->dev, res->imc, i, wayness);
667 if (SKX_TAD_BASE(base) <= res->addr && res->addr <= SKX_TAD_LIMIT(wayness))
668 goto tad_found;
669 }
670 edac_dbg(0, "No TAD entry for %llx\n", res->addr);
671 return false;
672
673tad_found:
674 res->sktways = SKX_TAD_SKTWAYS(wayness);
675 res->chanways = SKX_TAD_CHNWAYS(wayness);
676 skt_interleave_bit = skx_granularity[SKX_TAD_SKT_GRAN(base)];
677 chn_interleave_bit = skx_granularity[SKX_TAD_CHN_GRAN(base)];
678
679 SKX_GET_TADCHNILVOFFSET(res->dev, res->imc, res->channel, i, chnilvoffset);
680 channel_addr = res->addr - SKX_TAD_OFFSET(chnilvoffset);
681
682 if (res->chanways == 3 && skt_interleave_bit > chn_interleave_bit) {
683 /* Must handle channel first, then socket */
684 channel_addr = skx_do_interleave(channel_addr, chn_interleave_bit,
685 res->chanways, channel_addr);
686 channel_addr = skx_do_interleave(channel_addr, skt_interleave_bit,
687 res->sktways, channel_addr);
688 } else {
689 /* Handle socket then channel. Preserve low bits from original address */
690 channel_addr = skx_do_interleave(channel_addr, skt_interleave_bit,
691 res->sktways, res->addr);
692 channel_addr = skx_do_interleave(channel_addr, chn_interleave_bit,
693 res->chanways, res->addr);
694 }
695
696 res->chan_addr = channel_addr;
697
698 edac_dbg(2, "%llx: chan_addr=%llx sktways=%d chanways=%d\n",
699 res->addr, res->chan_addr, res->sktways, res->chanways);
700 return true;
701}
702
703#define SKX_MAX_RIR 4
704
705#define SKX_GET_RIRWAYNESS(d, mc, ch, i, reg) \
706 pci_read_config_dword((d)->imc[mc].chan[ch].cdev, \
707 0x108 + 4 * (i), &reg)
708#define SKX_GET_RIRILV(d, mc, ch, idx, i, reg) \
709 pci_read_config_dword((d)->imc[mc].chan[ch].cdev, \
710 0x120 + 16 * idx + 4 * (i), &reg)
711
712#define SKX_RIR_VALID(b) GET_BITFIELD((b), 31, 31)
713#define SKX_RIR_LIMIT(b) (((u64)GET_BITFIELD((b), 1, 11) << 29) | MASK29)
714#define SKX_RIR_WAYS(b) (1 << GET_BITFIELD((b), 28, 29))
715#define SKX_RIR_CHAN_RANK(b) GET_BITFIELD((b), 16, 19)
716#define SKX_RIR_OFFSET(b) ((u64)(GET_BITFIELD((b), 2, 15) << 26))
717
718static bool skx_rir_decode(struct decoded_addr *res)
719{
720 int i, idx, chan_rank;
721 int shift;
722 u32 rirway, rirlv;
723 u64 rank_addr, prev_limit = 0, limit;
724
725 if (res->dev->imc[res->imc].chan[res->channel].dimms[0].close_pg)
726 shift = 6;
727 else
728 shift = 13;
729
730 for (i = 0; i < SKX_MAX_RIR; i++) {
731 SKX_GET_RIRWAYNESS(res->dev, res->imc, res->channel, i, rirway);
732 limit = SKX_RIR_LIMIT(rirway);
733 if (SKX_RIR_VALID(rirway)) {
734 if (prev_limit <= res->chan_addr &&
735 res->chan_addr <= limit)
736 goto rir_found;
737 }
738 prev_limit = limit;
739 }
740 edac_dbg(0, "No RIR entry for %llx\n", res->addr);
741 return false;
742
743rir_found:
744 rank_addr = res->chan_addr >> shift;
745 rank_addr /= SKX_RIR_WAYS(rirway);
746 rank_addr <<= shift;
747 rank_addr |= res->chan_addr & GENMASK_ULL(shift - 1, 0);
748
749 res->rank_address = rank_addr;
750 idx = (res->chan_addr >> shift) % SKX_RIR_WAYS(rirway);
751
752 SKX_GET_RIRILV(res->dev, res->imc, res->channel, idx, i, rirlv);
753 res->rank_address = rank_addr - SKX_RIR_OFFSET(rirlv);
754 chan_rank = SKX_RIR_CHAN_RANK(rirlv);
755 res->channel_rank = chan_rank;
756 res->dimm = chan_rank / 4;
757 res->rank = chan_rank % 4;
758
759 edac_dbg(2, "%llx: dimm=%d rank=%d chan_rank=%d rank_addr=%llx\n",
760 res->addr, res->dimm, res->rank,
761 res->channel_rank, res->rank_address);
762 return true;
763}
764
765static u8 skx_close_row[] = {
766 15, 16, 17, 18, 20, 21, 22, 28, 10, 11, 12, 13, 29, 30, 31, 32, 33
767};
768static u8 skx_close_column[] = {
769 3, 4, 5, 14, 19, 23, 24, 25, 26, 27
770};
771static u8 skx_open_row[] = {
772 14, 15, 16, 20, 28, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33
773};
774static u8 skx_open_column[] = {
775 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
776};
777static u8 skx_open_fine_column[] = {
778 3, 4, 5, 7, 8, 9, 10, 11, 12, 13
779};
780
781static int skx_bits(u64 addr, int nbits, u8 *bits)
782{
783 int i, res = 0;
784
785 for (i = 0; i < nbits; i++)
786 res |= ((addr >> bits[i]) & 1) << i;
787 return res;
788}
789
790static int skx_bank_bits(u64 addr, int b0, int b1, int do_xor, int x0, int x1)
791{
792 int ret = GET_BITFIELD(addr, b0, b0) | (GET_BITFIELD(addr, b1, b1) << 1);
793
794 if (do_xor)
795 ret ^= GET_BITFIELD(addr, x0, x0) | (GET_BITFIELD(addr, x1, x1) << 1);
796
797 return ret;
798}
799
800static bool skx_mad_decode(struct decoded_addr *r)
801{
802 struct skx_dimm *dimm = &r->dev->imc[r->imc].chan[r->channel].dimms[r->dimm];
803 int bg0 = dimm->fine_grain_bank ? 6 : 13;
804
805 if (dimm->close_pg) {
806 r->row = skx_bits(r->rank_address, dimm->rowbits, skx_close_row);
807 r->column = skx_bits(r->rank_address, dimm->colbits, skx_close_column);
808 r->column |= 0x400; /* C10 is autoprecharge, always set */
809 r->bank_address = skx_bank_bits(r->rank_address, 8, 9, dimm->bank_xor_enable, 22, 28);
810 r->bank_group = skx_bank_bits(r->rank_address, 6, 7, dimm->bank_xor_enable, 20, 21);
811 } else {
812 r->row = skx_bits(r->rank_address, dimm->rowbits, skx_open_row);
813 if (dimm->fine_grain_bank)
814 r->column = skx_bits(r->rank_address, dimm->colbits, skx_open_fine_column);
815 else
816 r->column = skx_bits(r->rank_address, dimm->colbits, skx_open_column);
817 r->bank_address = skx_bank_bits(r->rank_address, 18, 19, dimm->bank_xor_enable, 22, 23);
818 r->bank_group = skx_bank_bits(r->rank_address, bg0, 17, dimm->bank_xor_enable, 20, 21);
819 }
820 r->row &= (1u << dimm->rowbits) - 1;
821
822 edac_dbg(2, "%llx: row=%x col=%x bank_addr=%d bank_group=%d\n",
823 r->addr, r->row, r->column, r->bank_address,
824 r->bank_group);
825 return true;
826}
827
828static bool skx_decode(struct decoded_addr *res)
829{
830
831 return skx_sad_decode(res) && skx_tad_decode(res) &&
832 skx_rir_decode(res) && skx_mad_decode(res);
833}
834
835#ifdef CONFIG_EDAC_DEBUG
836/*
837 * Debug feature. Make /sys/kernel/debug/skx_edac_test/addr.
838 * Write an address to this file to exercise the address decode
839 * logic in this driver.
840 */
841static struct dentry *skx_test;
842static u64 skx_fake_addr;
843
844static int debugfs_u64_set(void *data, u64 val)
845{
846 struct decoded_addr res;
847
848 res.addr = val;
849 skx_decode(&res);
850
851 return 0;
852}
853
854DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");
855
856static struct dentry *mydebugfs_create(const char *name, umode_t mode,
857 struct dentry *parent, u64 *value)
858{
859 return debugfs_create_file(name, mode, parent, value, &fops_u64_wo);
860}
861
862static void setup_skx_debug(void)
863{
864 skx_test = debugfs_create_dir("skx_edac_test", NULL);
865 mydebugfs_create("addr", S_IWUSR, skx_test, &skx_fake_addr);
866}
867
868static void teardown_skx_debug(void)
869{
870 debugfs_remove_recursive(skx_test);
871}
872#else
873static void setup_skx_debug(void)
874{
875}
876
877static void teardown_skx_debug(void)
878{
879}
880#endif /*CONFIG_EDAC_DEBUG*/
881
882static void skx_mce_output_error(struct mem_ctl_info *mci,
883 const struct mce *m,
884 struct decoded_addr *res)
885{
886 enum hw_event_mc_err_type tp_event;
887 char *type, *optype, msg[256];
888 bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0);
889 bool overflow = GET_BITFIELD(m->status, 62, 62);
890 bool uncorrected_error = GET_BITFIELD(m->status, 61, 61);
891 bool recoverable;
892 u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52);
893 u32 mscod = GET_BITFIELD(m->status, 16, 31);
894 u32 errcode = GET_BITFIELD(m->status, 0, 15);
895 u32 optypenum = GET_BITFIELD(m->status, 4, 6);
896
897 recoverable = GET_BITFIELD(m->status, 56, 56);
898
899 if (uncorrected_error) {
900 if (ripv) {
901 type = "FATAL";
902 tp_event = HW_EVENT_ERR_FATAL;
903 } else {
904 type = "NON_FATAL";
905 tp_event = HW_EVENT_ERR_UNCORRECTED;
906 }
907 } else {
908 type = "CORRECTED";
909 tp_event = HW_EVENT_ERR_CORRECTED;
910 }
911
912 /*
913 * According with Table 15-9 of the Intel Architecture spec vol 3A,
914 * memory errors should fit in this mask:
915 * 000f 0000 1mmm cccc (binary)
916 * where:
917 * f = Correction Report Filtering Bit. If 1, subsequent errors
918 * won't be shown
919 * mmm = error type
920 * cccc = channel
921 * If the mask doesn't match, report an error to the parsing logic
922 */
923 if (!((errcode & 0xef80) == 0x80)) {
924 optype = "Can't parse: it is not a mem";
925 } else {
926 switch (optypenum) {
927 case 0:
928 optype = "generic undef request error";
929 break;
930 case 1:
931 optype = "memory read error";
932 break;
933 case 2:
934 optype = "memory write error";
935 break;
936 case 3:
937 optype = "addr/cmd error";
938 break;
939 case 4:
940 optype = "memory scrubbing error";
941 break;
942 default:
943 optype = "reserved";
944 break;
945 }
946 }
947
948 snprintf(msg, sizeof(msg),
949 "%s%s err_code:%04x:%04x socket:%d imc:%d rank:%d bg:%d ba:%d row:%x col:%x",
950 overflow ? " OVERFLOW" : "",
951 (uncorrected_error && recoverable) ? " recoverable" : "",
952 mscod, errcode,
953 res->socket, res->imc, res->rank,
954 res->bank_group, res->bank_address, res->row, res->column);
955
956 edac_dbg(0, "%s\n", msg);
957
958 /* Call the helper to output message */
959 edac_mc_handle_error(tp_event, mci, core_err_cnt,
960 m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0,
961 res->channel, res->dimm, -1,
962 optype, msg);
963}
964
965static int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
966 void *data)
967{
968 struct mce *mce = (struct mce *)data;
969 struct decoded_addr res;
970 struct mem_ctl_info *mci;
971 char *type;
972
973 if (get_edac_report_status() == EDAC_REPORTING_DISABLED)
974 return NOTIFY_DONE;
975
976 /* ignore unless this is memory related with an address */
977 if ((mce->status & 0xefff) >> 7 != 1 || !(mce->status & MCI_STATUS_ADDRV))
978 return NOTIFY_DONE;
979
980 res.addr = mce->addr;
981 if (!skx_decode(&res))
982 return NOTIFY_DONE;
983 mci = res.dev->imc[res.imc].mci;
984
985 if (mce->mcgstatus & MCG_STATUS_MCIP)
986 type = "Exception";
987 else
988 type = "Event";
989
990 skx_mc_printk(mci, KERN_DEBUG, "HANDLING MCE MEMORY ERROR\n");
991
992 skx_mc_printk(mci, KERN_DEBUG, "CPU %d: Machine Check %s: %Lx "
993 "Bank %d: %016Lx\n", mce->extcpu, type,
994 mce->mcgstatus, mce->bank, mce->status);
995 skx_mc_printk(mci, KERN_DEBUG, "TSC %llx ", mce->tsc);
996 skx_mc_printk(mci, KERN_DEBUG, "ADDR %llx ", mce->addr);
997 skx_mc_printk(mci, KERN_DEBUG, "MISC %llx ", mce->misc);
998
999 skx_mc_printk(mci, KERN_DEBUG, "PROCESSOR %u:%x TIME %llu SOCKET "
1000 "%u APIC %x\n", mce->cpuvendor, mce->cpuid,
1001 mce->time, mce->socketid, mce->apicid);
1002
1003 skx_mce_output_error(mci, mce, &res);
1004
1005 return NOTIFY_DONE;
1006}
1007
1008static struct notifier_block skx_mce_dec = {
1009 .notifier_call = skx_mce_check_error,
1010};
1011
1012static void skx_remove(void)
1013{
1014 int i, j;
1015 struct skx_dev *d, *tmp;
1016
1017 edac_dbg(0, "\n");
1018
1019 list_for_each_entry_safe(d, tmp, &skx_edac_list, list) {
1020 list_del(&d->list);
1021 for (i = 0; i < NUM_IMC; i++) {
1022 skx_unregister_mci(&d->imc[i]);
1023 for (j = 0; j < NUM_CHANNELS; j++)
1024 pci_dev_put(d->imc[i].chan[j].cdev);
1025 }
1026 pci_dev_put(d->util_all);
1027 pci_dev_put(d->sad_all);
1028
1029 kfree(d);
1030 }
1031}
1032
1033/*
1034 * skx_init:
1035 * make sure we are running on the correct cpu model
1036 * search for all the devices we need
1037 * check which DIMMs are present.
1038 */
1039int __init skx_init(void)
1040{
1041 const struct x86_cpu_id *id;
1042 const struct munit *m;
1043 int rc = 0, i;
1044 u8 mc = 0, src_id, node_id;
1045 struct skx_dev *d;
1046
1047 edac_dbg(2, "\n");
1048
1049 id = x86_match_cpu(skx_cpuids);
1050 if (!id)
1051 return -ENODEV;
1052
1053 rc = skx_get_hi_lo();
1054 if (rc)
1055 return rc;
1056
1057 rc = get_all_bus_mappings();
1058 if (rc < 0)
1059 goto fail;
1060 if (rc == 0) {
1061 edac_dbg(2, "No memory controllers found\n");
1062 return -ENODEV;
1063 }
1064
1065 for (m = skx_all_munits; m->did; m++) {
1066 rc = get_all_munits(m);
1067 if (rc < 0)
1068 goto fail;
1069 if (rc != m->per_socket * skx_num_sockets) {
1070 edac_dbg(2, "Expected %d, got %d of %x\n",
1071 m->per_socket * skx_num_sockets, rc, m->did);
1072 rc = -ENODEV;
1073 goto fail;
1074 }
1075 }
1076
1077 list_for_each_entry(d, &skx_edac_list, list) {
1078 src_id = get_src_id(d);
1079 node_id = skx_get_node_id(d);
1080 edac_dbg(2, "src_id=%d node_id=%d\n", src_id, node_id);
1081 for (i = 0; i < NUM_IMC; i++) {
1082 d->imc[i].mc = mc++;
1083 d->imc[i].lmc = i;
1084 d->imc[i].src_id = src_id;
1085 d->imc[i].node_id = node_id;
1086 rc = skx_register_mci(&d->imc[i]);
1087 if (rc < 0)
1088 goto fail;
1089 }
1090 }
1091
1092 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1093 opstate_init();
1094
1095 setup_skx_debug();
1096
1097 mce_register_decode_chain(&skx_mce_dec);
1098
1099 return 0;
1100fail:
1101 skx_remove();
1102 return rc;
1103}
1104
1105static void __exit skx_exit(void)
1106{
1107 edac_dbg(2, "\n");
1108 mce_unregister_decode_chain(&skx_mce_dec);
1109 skx_remove();
1110 teardown_skx_debug();
1111}
1112
1113module_init(skx_init);
1114module_exit(skx_exit);
1115
1116module_param(edac_op_state, int, 0444);
1117MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1118
1119MODULE_LICENSE("GPL v2");
1120MODULE_AUTHOR("Tony Luck");
1121MODULE_DESCRIPTION("MC Driver for Intel Skylake server processors");
diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c
index c99c24bc79b0..9ae6c116c474 100644
--- a/drivers/firmware/efi/capsule-loader.c
+++ b/drivers/firmware/efi/capsule-loader.c
@@ -16,6 +16,7 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/efi.h> 18#include <linux/efi.h>
19#include <linux/vmalloc.h>
19 20
20#define NO_FURTHER_WRITE_ACTION -1 21#define NO_FURTHER_WRITE_ACTION -1
21 22
@@ -108,14 +109,15 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info)
108 int ret; 109 int ret;
109 void *cap_hdr_temp; 110 void *cap_hdr_temp;
110 111
111 cap_hdr_temp = kmap(cap_info->pages[0]); 112 cap_hdr_temp = vmap(cap_info->pages, cap_info->index,
113 VM_MAP, PAGE_KERNEL);
112 if (!cap_hdr_temp) { 114 if (!cap_hdr_temp) {
113 pr_debug("%s: kmap() failed\n", __func__); 115 pr_debug("%s: vmap() failed\n", __func__);
114 return -EFAULT; 116 return -EFAULT;
115 } 117 }
116 118
117 ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); 119 ret = efi_capsule_update(cap_hdr_temp, cap_info->pages);
118 kunmap(cap_info->pages[0]); 120 vunmap(cap_hdr_temp);
119 if (ret) { 121 if (ret) {
120 pr_err("%s: efi_capsule_update() failed\n", __func__); 122 pr_err("%s: efi_capsule_update() failed\n", __func__);
121 return ret; 123 return ret;
diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c
index 53b9fd2293ee..6eedff45e6d7 100644
--- a/drivers/firmware/efi/capsule.c
+++ b/drivers/firmware/efi/capsule.c
@@ -190,9 +190,9 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule,
190 * map the capsule described by @capsule with its data in @pages and 190 * map the capsule described by @capsule with its data in @pages and
191 * send it to the firmware via the UpdateCapsule() runtime service. 191 * send it to the firmware via the UpdateCapsule() runtime service.
192 * 192 *
193 * @capsule must be a virtual mapping of the first page in @pages 193 * @capsule must be a virtual mapping of the complete capsule update in the
194 * (@pages[0]) in the kernel address space. That is, a 194 * kernel address space, as the capsule can be consumed immediately.
195 * capsule_header_t that describes the entire contents of the capsule 195 * A capsule_header_t that describes the entire contents of the capsule
196 * must be at the start of the first data page. 196 * must be at the start of the first data page.
197 * 197 *
198 * Even though this function will validate that the firmware supports 198 * Even though this function will validate that the firmware supports
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 98dd47a30fc7..66a94103798b 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -50,6 +50,7 @@ config GPIO_DEVRES
50config OF_GPIO 50config OF_GPIO
51 def_bool y 51 def_bool y
52 depends on OF 52 depends on OF
53 depends on HAS_IOMEM
53 54
54config GPIO_ACPI 55config GPIO_ACPI
55 def_bool y 56 def_bool y
@@ -188,7 +189,7 @@ config GPIO_EP93XX
188config GPIO_ETRAXFS 189config GPIO_ETRAXFS
189 bool "Axis ETRAX FS General I/O" 190 bool "Axis ETRAX FS General I/O"
190 depends on CRIS || COMPILE_TEST 191 depends on CRIS || COMPILE_TEST
191 depends on OF 192 depends on OF_GPIO
192 select GPIO_GENERIC 193 select GPIO_GENERIC
193 select GPIOLIB_IRQCHIP 194 select GPIOLIB_IRQCHIP
194 help 195 help
@@ -214,7 +215,7 @@ config GPIO_GENERIC_PLATFORM
214 215
215config GPIO_GRGPIO 216config GPIO_GRGPIO
216 tristate "Aeroflex Gaisler GRGPIO support" 217 tristate "Aeroflex Gaisler GRGPIO support"
217 depends on OF 218 depends on OF_GPIO
218 select GPIO_GENERIC 219 select GPIO_GENERIC
219 select IRQ_DOMAIN 220 select IRQ_DOMAIN
220 help 221 help
@@ -312,7 +313,7 @@ config GPIO_MPC8XXX
312config GPIO_MVEBU 313config GPIO_MVEBU
313 def_bool y 314 def_bool y
314 depends on PLAT_ORION 315 depends on PLAT_ORION
315 depends on OF 316 depends on OF_GPIO
316 select GENERIC_IRQ_CHIP 317 select GENERIC_IRQ_CHIP
317 318
318config GPIO_MXC 319config GPIO_MXC
@@ -405,7 +406,7 @@ config GPIO_TEGRA
405 bool "NVIDIA Tegra GPIO support" 406 bool "NVIDIA Tegra GPIO support"
406 default ARCH_TEGRA 407 default ARCH_TEGRA
407 depends on ARCH_TEGRA || COMPILE_TEST 408 depends on ARCH_TEGRA || COMPILE_TEST
408 depends on OF 409 depends on OF_GPIO
409 help 410 help
410 Say yes here to support GPIO pins on NVIDIA Tegra SoCs. 411 Say yes here to support GPIO pins on NVIDIA Tegra SoCs.
411 412
@@ -1099,7 +1100,7 @@ menu "SPI GPIO expanders"
1099 1100
1100config GPIO_74X164 1101config GPIO_74X164
1101 tristate "74x164 serial-in/parallel-out 8-bits shift register" 1102 tristate "74x164 serial-in/parallel-out 8-bits shift register"
1102 depends on OF 1103 depends on OF_GPIO
1103 help 1104 help
1104 Driver for 74x164 compatible serial-in/parallel-out 8-outputs 1105 Driver for 74x164 compatible serial-in/parallel-out 8-outputs
1105 shift registers. This driver can be used to provide access 1106 shift registers. This driver can be used to provide access
diff --git a/drivers/gpio/gpio-max730x.c b/drivers/gpio/gpio-max730x.c
index 08807368f007..946d09195598 100644
--- a/drivers/gpio/gpio-max730x.c
+++ b/drivers/gpio/gpio-max730x.c
@@ -192,6 +192,10 @@ int __max730x_probe(struct max7301 *ts)
192 ts->chip.parent = dev; 192 ts->chip.parent = dev;
193 ts->chip.owner = THIS_MODULE; 193 ts->chip.owner = THIS_MODULE;
194 194
195 ret = gpiochip_add_data(&ts->chip, ts);
196 if (ret)
197 goto exit_destroy;
198
195 /* 199 /*
196 * initialize pullups according to platform data and cache the 200 * initialize pullups according to platform data and cache the
197 * register values for later use. 201 * register values for later use.
@@ -213,10 +217,6 @@ int __max730x_probe(struct max7301 *ts)
213 } 217 }
214 } 218 }
215 219
216 ret = gpiochip_add_data(&ts->chip, ts);
217 if (ret)
218 goto exit_destroy;
219
220 return ret; 220 return ret;
221 221
222exit_destroy: 222exit_destroy:
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 8ebc5f1eb4c0..700c56baf2de 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -426,6 +426,8 @@ struct amdgpu_mman {
426 426
427 /* custom LRU management */ 427 /* custom LRU management */
428 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE]; 428 struct amdgpu_mman_lru log2_size[AMDGPU_TTM_LRU_SIZE];
429 /* guard for log2_size array, don't add anything in between */
430 struct amdgpu_mman_lru guard;
429}; 431};
430 432
431int amdgpu_copy_buffer(struct amdgpu_ring *ring, 433int amdgpu_copy_buffer(struct amdgpu_ring *ring,
@@ -646,9 +648,9 @@ int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
646void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev); 648void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
647int amdgpu_gart_init(struct amdgpu_device *adev); 649int amdgpu_gart_init(struct amdgpu_device *adev);
648void amdgpu_gart_fini(struct amdgpu_device *adev); 650void amdgpu_gart_fini(struct amdgpu_device *adev);
649void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset, 651void amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
650 int pages); 652 int pages);
651int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset, 653int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
652 int pages, struct page **pagelist, 654 int pages, struct page **pagelist,
653 dma_addr_t *dma_addr, uint32_t flags); 655 dma_addr_t *dma_addr, uint32_t flags);
654 656
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
index 983175363b06..fe872b82e619 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
@@ -321,6 +321,19 @@ bool amdgpu_atombios_get_connector_info_from_object_table(struct amdgpu_device *
321 (le16_to_cpu(path->usConnObjectId) & 321 (le16_to_cpu(path->usConnObjectId) &
322 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT; 322 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
323 323
324 /* Skip TV/CV support */
325 if ((le16_to_cpu(path->usDeviceTag) ==
326 ATOM_DEVICE_TV1_SUPPORT) ||
327 (le16_to_cpu(path->usDeviceTag) ==
328 ATOM_DEVICE_CV_SUPPORT))
329 continue;
330
331 if (con_obj_id >= ARRAY_SIZE(object_connector_convert)) {
332 DRM_ERROR("invalid con_obj_id %d for device tag 0x%04x\n",
333 con_obj_id, le16_to_cpu(path->usDeviceTag));
334 continue;
335 }
336
324 connector_type = 337 connector_type =
325 object_connector_convert[con_obj_id]; 338 object_connector_convert[con_obj_id];
326 connector_object_id = con_obj_id; 339 connector_object_id = con_obj_id;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
index 49de92600074..10b5ddf2c588 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
@@ -200,16 +200,7 @@ static int amdgpu_atpx_validate(struct amdgpu_atpx *atpx)
200 atpx->is_hybrid = false; 200 atpx->is_hybrid = false;
201 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) { 201 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
202 printk("ATPX Hybrid Graphics\n"); 202 printk("ATPX Hybrid Graphics\n");
203#if 1
204 /* This is a temporary hack until the D3 cold support
205 * makes it upstream. The ATPX power_control method seems
206 * to still work on even if the system should be using
207 * the new standardized hybrid D3 cold ACPI interface.
208 */
209 atpx->functions.power_cntl = true;
210#else
211 atpx->functions.power_cntl = false; 203 atpx->functions.power_cntl = false;
212#endif
213 atpx->is_hybrid = true; 204 atpx->is_hybrid = true;
214 } 205 }
215 206
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index 921bce2df0b0..0feea347f680 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -221,7 +221,7 @@ void amdgpu_gart_table_vram_free(struct amdgpu_device *adev)
221 * Unbinds the requested pages from the gart page table and 221 * Unbinds the requested pages from the gart page table and
222 * replaces them with the dummy page (all asics). 222 * replaces them with the dummy page (all asics).
223 */ 223 */
224void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset, 224void amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
225 int pages) 225 int pages)
226{ 226{
227 unsigned t; 227 unsigned t;
@@ -268,7 +268,7 @@ void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
268 * (all asics). 268 * (all asics).
269 * Returns 0 for success, -EINVAL for failure. 269 * Returns 0 for success, -EINVAL for failure.
270 */ 270 */
271int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset, 271int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
272 int pages, struct page **pagelist, dma_addr_t *dma_addr, 272 int pages, struct page **pagelist, dma_addr_t *dma_addr,
273 uint32_t flags) 273 uint32_t flags)
274{ 274{
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 9b61c8ba7aaf..716f2afeb6a9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -251,8 +251,8 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo,
251 251
252 adev = amdgpu_get_adev(bo->bdev); 252 adev = amdgpu_get_adev(bo->bdev);
253 ring = adev->mman.buffer_funcs_ring; 253 ring = adev->mman.buffer_funcs_ring;
254 old_start = old_mem->start << PAGE_SHIFT; 254 old_start = (u64)old_mem->start << PAGE_SHIFT;
255 new_start = new_mem->start << PAGE_SHIFT; 255 new_start = (u64)new_mem->start << PAGE_SHIFT;
256 256
257 switch (old_mem->mem_type) { 257 switch (old_mem->mem_type) {
258 case TTM_PL_VRAM: 258 case TTM_PL_VRAM:
@@ -950,6 +950,8 @@ static struct list_head *amdgpu_ttm_lru_tail(struct ttm_buffer_object *tbo)
950 struct list_head *res = lru->lru[tbo->mem.mem_type]; 950 struct list_head *res = lru->lru[tbo->mem.mem_type];
951 951
952 lru->lru[tbo->mem.mem_type] = &tbo->lru; 952 lru->lru[tbo->mem.mem_type] = &tbo->lru;
953 while ((++lru)->lru[tbo->mem.mem_type] == res)
954 lru->lru[tbo->mem.mem_type] = &tbo->lru;
953 955
954 return res; 956 return res;
955} 957}
@@ -960,6 +962,8 @@ static struct list_head *amdgpu_ttm_swap_lru_tail(struct ttm_buffer_object *tbo)
960 struct list_head *res = lru->swap_lru; 962 struct list_head *res = lru->swap_lru;
961 963
962 lru->swap_lru = &tbo->swap; 964 lru->swap_lru = &tbo->swap;
965 while ((++lru)->swap_lru == res)
966 lru->swap_lru = &tbo->swap;
963 967
964 return res; 968 return res;
965} 969}
@@ -1011,6 +1015,10 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
1011 lru->swap_lru = &adev->mman.bdev.glob->swap_lru; 1015 lru->swap_lru = &adev->mman.bdev.glob->swap_lru;
1012 } 1016 }
1013 1017
1018 for (j = 0; j < TTM_NUM_MEM_TYPES; ++j)
1019 adev->mman.guard.lru[j] = NULL;
1020 adev->mman.guard.swap_lru = NULL;
1021
1014 adev->mman.initialized = true; 1022 adev->mman.initialized = true;
1015 r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_VRAM, 1023 r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_VRAM,
1016 adev->mc.real_vram_size >> PAGE_SHIFT); 1024 adev->mc.real_vram_size >> PAGE_SHIFT);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index b11f4e8868d7..4aa993d19018 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -1187,7 +1187,8 @@ int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout)
1187 r = 0; 1187 r = 0;
1188 } 1188 }
1189 1189
1190error:
1191 fence_put(fence); 1190 fence_put(fence);
1191
1192error:
1192 return r; 1193 return r;
1193} 1194}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 8e642fc48df4..80120fa4092c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1535,7 +1535,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
1535 r = amd_sched_entity_init(&ring->sched, &vm->entity, 1535 r = amd_sched_entity_init(&ring->sched, &vm->entity,
1536 rq, amdgpu_sched_jobs); 1536 rq, amdgpu_sched_jobs);
1537 if (r) 1537 if (r)
1538 return r; 1538 goto err;
1539 1539
1540 vm->page_directory_fence = NULL; 1540 vm->page_directory_fence = NULL;
1541 1541
@@ -1565,6 +1565,9 @@ error_free_page_directory:
1565error_free_sched_entity: 1565error_free_sched_entity:
1566 amd_sched_entity_fini(&ring->sched, &vm->entity); 1566 amd_sched_entity_fini(&ring->sched, &vm->entity);
1567 1567
1568err:
1569 drm_free_large(vm->page_tables);
1570
1568 return r; 1571 return r;
1569} 1572}
1570 1573
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
index 1351c7e834a2..a64715d90503 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
@@ -714,7 +714,7 @@ static int sdma_v2_4_ring_test_ib(struct amdgpu_ring *ring, long timeout)
714 DRM_ERROR("amdgpu: IB test timed out\n"); 714 DRM_ERROR("amdgpu: IB test timed out\n");
715 r = -ETIMEDOUT; 715 r = -ETIMEDOUT;
716 goto err1; 716 goto err1;
717 } else if (r) { 717 } else if (r < 0) {
718 DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r); 718 DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
719 goto err1; 719 goto err1;
720 } 720 }
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c b/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c
index e621eba63126..a7d3cb3fead0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c
@@ -184,7 +184,7 @@ u32 __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
184 sizeof(u32)) + inx; 184 sizeof(u32)) + inx;
185 185
186 pr_debug("kfd: get kernel queue doorbell\n" 186 pr_debug("kfd: get kernel queue doorbell\n"
187 " doorbell offset == 0x%08d\n" 187 " doorbell offset == 0x%08X\n"
188 " kernel address == 0x%08lX\n", 188 " kernel address == 0x%08lX\n",
189 *doorbell_off, (uintptr_t)(kfd->doorbell_kernel_ptr + inx)); 189 *doorbell_off, (uintptr_t)(kfd->doorbell_kernel_ptr + inx));
190 190
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
index ef312bb75fda..963a24d46a93 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
@@ -405,7 +405,7 @@ void amd_sched_job_recovery(struct amd_gpu_scheduler *sched)
405 spin_lock(&sched->job_list_lock); 405 spin_lock(&sched->job_list_lock);
406 s_job = list_first_entry_or_null(&sched->ring_mirror_list, 406 s_job = list_first_entry_or_null(&sched->ring_mirror_list,
407 struct amd_sched_job, node); 407 struct amd_sched_job, node);
408 if (s_job) 408 if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
409 schedule_delayed_work(&s_job->work_tdr, sched->timeout); 409 schedule_delayed_work(&s_job->work_tdr, sched->timeout);
410 410
411 list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) { 411 list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index fa3930757972..2a3ded44cf2a 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -475,7 +475,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
475 val, 475 val,
476 -1, 476 -1,
477 &replaced); 477 &replaced);
478 state->color_mgmt_changed = replaced; 478 state->color_mgmt_changed |= replaced;
479 return ret; 479 return ret;
480 } else if (property == config->ctm_property) { 480 } else if (property == config->ctm_property) {
481 ret = drm_atomic_replace_property_blob_from_id(crtc, 481 ret = drm_atomic_replace_property_blob_from_id(crtc,
@@ -483,7 +483,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
483 val, 483 val,
484 sizeof(struct drm_color_ctm), 484 sizeof(struct drm_color_ctm),
485 &replaced); 485 &replaced);
486 state->color_mgmt_changed = replaced; 486 state->color_mgmt_changed |= replaced;
487 return ret; 487 return ret;
488 } else if (property == config->gamma_lut_property) { 488 } else if (property == config->gamma_lut_property) {
489 ret = drm_atomic_replace_property_blob_from_id(crtc, 489 ret = drm_atomic_replace_property_blob_from_id(crtc,
@@ -491,7 +491,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
491 val, 491 val,
492 -1, 492 -1,
493 &replaced); 493 &replaced);
494 state->color_mgmt_changed = replaced; 494 state->color_mgmt_changed |= replaced;
495 return ret; 495 return ret;
496 } else if (crtc->funcs->atomic_set_property) 496 } else if (crtc->funcs->atomic_set_property)
497 return crtc->funcs->atomic_set_property(crtc, state, property, val); 497 return crtc->funcs->atomic_set_property(crtc, state, property, val);
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index b1dbb60af99f..ddebe54cd5ca 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -5404,6 +5404,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
5404 struct drm_pending_vblank_event *e = NULL; 5404 struct drm_pending_vblank_event *e = NULL;
5405 int ret = -EINVAL; 5405 int ret = -EINVAL;
5406 5406
5407 if (!drm_core_check_feature(dev, DRIVER_MODESET))
5408 return -EINVAL;
5409
5407 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || 5410 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
5408 page_flip->reserved != 0) 5411 page_flip->reserved != 0)
5409 return -EINVAL; 5412 return -EINVAL;
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index ce54e985d91b..0a06f9120b5a 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -464,7 +464,7 @@ static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
464 464
465 /* Sometimes user space wants everything disabled, so don't steal the 465 /* Sometimes user space wants everything disabled, so don't steal the
466 * display if there's a master. */ 466 * display if there's a master. */
467 if (lockless_dereference(dev->master)) 467 if (READ_ONCE(dev->master))
468 return false; 468 return false;
469 469
470 drm_for_each_crtc(crtc, dev) { 470 drm_for_each_crtc(crtc, dev) {
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
index 87ef34150d46..b382cf505262 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
@@ -1333,8 +1333,6 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
1333 if (ret < 0) 1333 if (ret < 0)
1334 return ret; 1334 return ret;
1335 1335
1336 mutex_lock(&gpu->lock);
1337
1338 /* 1336 /*
1339 * TODO 1337 * TODO
1340 * 1338 *
@@ -1348,16 +1346,18 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
1348 if (unlikely(event == ~0U)) { 1346 if (unlikely(event == ~0U)) {
1349 DRM_ERROR("no free event\n"); 1347 DRM_ERROR("no free event\n");
1350 ret = -EBUSY; 1348 ret = -EBUSY;
1351 goto out_unlock; 1349 goto out_pm_put;
1352 } 1350 }
1353 1351
1354 fence = etnaviv_gpu_fence_alloc(gpu); 1352 fence = etnaviv_gpu_fence_alloc(gpu);
1355 if (!fence) { 1353 if (!fence) {
1356 event_free(gpu, event); 1354 event_free(gpu, event);
1357 ret = -ENOMEM; 1355 ret = -ENOMEM;
1358 goto out_unlock; 1356 goto out_pm_put;
1359 } 1357 }
1360 1358
1359 mutex_lock(&gpu->lock);
1360
1361 gpu->event[event].fence = fence; 1361 gpu->event[event].fence = fence;
1362 submit->fence = fence->seqno; 1362 submit->fence = fence->seqno;
1363 gpu->active_fence = submit->fence; 1363 gpu->active_fence = submit->fence;
@@ -1395,9 +1395,9 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
1395 hangcheck_timer_reset(gpu); 1395 hangcheck_timer_reset(gpu);
1396 ret = 0; 1396 ret = 0;
1397 1397
1398out_unlock:
1399 mutex_unlock(&gpu->lock); 1398 mutex_unlock(&gpu->lock);
1400 1399
1400out_pm_put:
1401 etnaviv_gpu_pm_put(gpu); 1401 etnaviv_gpu_pm_put(gpu);
1402 1402
1403 return ret; 1403 return ret;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 21f939074abc..f68c78918d63 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -882,11 +882,12 @@ struct i915_gem_context {
882 882
883 struct i915_ctx_hang_stats hang_stats; 883 struct i915_ctx_hang_stats hang_stats;
884 884
885 /* Unique identifier for this context, used by the hw for tracking */
886 unsigned long flags; 885 unsigned long flags;
887#define CONTEXT_NO_ZEROMAP BIT(0) 886#define CONTEXT_NO_ZEROMAP BIT(0)
888#define CONTEXT_NO_ERROR_CAPTURE BIT(1) 887#define CONTEXT_NO_ERROR_CAPTURE BIT(1)
889 unsigned hw_id; 888
889 /* Unique identifier for this context, used by the hw for tracking */
890 unsigned int hw_id;
890 u32 user_handle; 891 u32 user_handle;
891 892
892 u32 ggtt_alignment; 893 u32 ggtt_alignment;
@@ -1854,6 +1855,7 @@ struct drm_i915_private {
1854 enum modeset_restore modeset_restore; 1855 enum modeset_restore modeset_restore;
1855 struct mutex modeset_restore_lock; 1856 struct mutex modeset_restore_lock;
1856 struct drm_atomic_state *modeset_restore_state; 1857 struct drm_atomic_state *modeset_restore_state;
1858 struct drm_modeset_acquire_ctx reset_ctx;
1857 1859
1858 struct list_head vm_list; /* Global list of all address spaces */ 1860 struct list_head vm_list; /* Global list of all address spaces */
1859 struct i915_ggtt ggtt; /* VM representing the global address space */ 1861 struct i915_ggtt ggtt; /* VM representing the global address space */
@@ -1962,6 +1964,13 @@ struct drm_i915_private {
1962 struct i915_suspend_saved_registers regfile; 1964 struct i915_suspend_saved_registers regfile;
1963 struct vlv_s0ix_state vlv_s0ix_state; 1965 struct vlv_s0ix_state vlv_s0ix_state;
1964 1966
1967 enum {
1968 I915_SKL_SAGV_UNKNOWN = 0,
1969 I915_SKL_SAGV_DISABLED,
1970 I915_SKL_SAGV_ENABLED,
1971 I915_SKL_SAGV_NOT_CONTROLLED
1972 } skl_sagv_status;
1973
1965 struct { 1974 struct {
1966 /* 1975 /*
1967 * Raw watermark latency values: 1976 * Raw watermark latency values:
@@ -3590,6 +3599,7 @@ int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
3590/* belongs in i915_gem_gtt.h */ 3599/* belongs in i915_gem_gtt.h */
3591static inline void i915_gem_chipset_flush(struct drm_i915_private *dev_priv) 3600static inline void i915_gem_chipset_flush(struct drm_i915_private *dev_priv)
3592{ 3601{
3602 wmb();
3593 if (INTEL_GEN(dev_priv) < 6) 3603 if (INTEL_GEN(dev_priv) < 6)
3594 intel_gtt_chipset_flush(); 3604 intel_gtt_chipset_flush();
3595} 3605}
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 11681501d7b1..a77ce9983f69 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -879,9 +879,12 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
879 ret = i915_gem_shmem_pread(dev, obj, args, file); 879 ret = i915_gem_shmem_pread(dev, obj, args, file);
880 880
881 /* pread for non shmem backed objects */ 881 /* pread for non shmem backed objects */
882 if (ret == -EFAULT || ret == -ENODEV) 882 if (ret == -EFAULT || ret == -ENODEV) {
883 intel_runtime_pm_get(to_i915(dev));
883 ret = i915_gem_gtt_pread(dev, obj, args->size, 884 ret = i915_gem_gtt_pread(dev, obj, args->size,
884 args->offset, args->data_ptr); 885 args->offset, args->data_ptr);
886 intel_runtime_pm_put(to_i915(dev));
887 }
885 888
886out: 889out:
887 drm_gem_object_unreference(&obj->base); 890 drm_gem_object_unreference(&obj->base);
@@ -1306,7 +1309,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
1306 * textures). Fallback to the shmem path in that case. */ 1309 * textures). Fallback to the shmem path in that case. */
1307 } 1310 }
1308 1311
1309 if (ret == -EFAULT) { 1312 if (ret == -EFAULT || ret == -ENOSPC) {
1310 if (obj->phys_handle) 1313 if (obj->phys_handle)
1311 ret = i915_gem_phys_pwrite(obj, args, file); 1314 ret = i915_gem_phys_pwrite(obj, args, file);
1312 else if (i915_gem_object_has_struct_page(obj)) 1315 else if (i915_gem_object_has_struct_page(obj))
@@ -3169,6 +3172,8 @@ static void i915_gem_reset_engine_cleanup(struct intel_engine_cs *engine)
3169 } 3172 }
3170 3173
3171 intel_ring_init_seqno(engine, engine->last_submitted_seqno); 3174 intel_ring_init_seqno(engine, engine->last_submitted_seqno);
3175
3176 engine->i915->gt.active_engines &= ~intel_engine_flag(engine);
3172} 3177}
3173 3178
3174void i915_gem_reset(struct drm_device *dev) 3179void i915_gem_reset(struct drm_device *dev)
@@ -3186,6 +3191,7 @@ void i915_gem_reset(struct drm_device *dev)
3186 3191
3187 for_each_engine(engine, dev_priv) 3192 for_each_engine(engine, dev_priv)
3188 i915_gem_reset_engine_cleanup(engine); 3193 i915_gem_reset_engine_cleanup(engine);
3194 mod_delayed_work(dev_priv->wq, &dev_priv->gt.idle_work, 0);
3189 3195
3190 i915_gem_context_reset(dev); 3196 i915_gem_context_reset(dev);
3191 3197
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 1978633e7549..b35e5b6475b2 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -943,8 +943,6 @@ i915_gem_execbuffer_move_to_gpu(struct drm_i915_gem_request *req,
943{ 943{
944 const unsigned other_rings = ~intel_engine_flag(req->engine); 944 const unsigned other_rings = ~intel_engine_flag(req->engine);
945 struct i915_vma *vma; 945 struct i915_vma *vma;
946 uint32_t flush_domains = 0;
947 bool flush_chipset = false;
948 int ret; 946 int ret;
949 947
950 list_for_each_entry(vma, vmas, exec_list) { 948 list_for_each_entry(vma, vmas, exec_list) {
@@ -957,16 +955,11 @@ i915_gem_execbuffer_move_to_gpu(struct drm_i915_gem_request *req,
957 } 955 }
958 956
959 if (obj->base.write_domain & I915_GEM_DOMAIN_CPU) 957 if (obj->base.write_domain & I915_GEM_DOMAIN_CPU)
960 flush_chipset |= i915_gem_clflush_object(obj, false); 958 i915_gem_clflush_object(obj, false);
961
962 flush_domains |= obj->base.write_domain;
963 } 959 }
964 960
965 if (flush_chipset) 961 /* Unconditionally flush any chipset caches (for streaming writes). */
966 i915_gem_chipset_flush(req->engine->i915); 962 i915_gem_chipset_flush(req->engine->i915);
967
968 if (flush_domains & I915_GEM_DOMAIN_GTT)
969 wmb();
970 963
971 /* Unconditionally invalidate gpu caches and ensure that we do flush 964 /* Unconditionally invalidate gpu caches and ensure that we do flush
972 * any residual writes from the previous batch. 965 * any residual writes from the previous batch.
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 10f1e32767e6..7a30af79d799 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -2873,6 +2873,7 @@ void i915_ggtt_cleanup_hw(struct drm_device *dev)
2873 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt; 2873 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2874 2874
2875 ppgtt->base.cleanup(&ppgtt->base); 2875 ppgtt->base.cleanup(&ppgtt->base);
2876 kfree(ppgtt);
2876 } 2877 }
2877 2878
2878 i915_gem_cleanup_stolen(dev); 2879 i915_gem_cleanup_stolen(dev);
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index ce14fe09d962..bf2cad3f9e1f 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -1536,6 +1536,7 @@ enum skl_disp_power_wells {
1536#define BALANCE_LEG_MASK(port) (7<<(8+3*(port))) 1536#define BALANCE_LEG_MASK(port) (7<<(8+3*(port)))
1537/* Balance leg disable bits */ 1537/* Balance leg disable bits */
1538#define BALANCE_LEG_DISABLE_SHIFT 23 1538#define BALANCE_LEG_DISABLE_SHIFT 23
1539#define BALANCE_LEG_DISABLE(port) (1 << (23 + (port)))
1539 1540
1540/* 1541/*
1541 * Fence registers 1542 * Fence registers
@@ -7144,6 +7145,15 @@ enum {
7144 7145
7145#define GEN6_PCODE_MAILBOX _MMIO(0x138124) 7146#define GEN6_PCODE_MAILBOX _MMIO(0x138124)
7146#define GEN6_PCODE_READY (1<<31) 7147#define GEN6_PCODE_READY (1<<31)
7148#define GEN6_PCODE_ERROR_MASK 0xFF
7149#define GEN6_PCODE_SUCCESS 0x0
7150#define GEN6_PCODE_ILLEGAL_CMD 0x1
7151#define GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE 0x2
7152#define GEN6_PCODE_TIMEOUT 0x3
7153#define GEN6_PCODE_UNIMPLEMENTED_CMD 0xFF
7154#define GEN7_PCODE_TIMEOUT 0x2
7155#define GEN7_PCODE_ILLEGAL_DATA 0x3
7156#define GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE 0x10
7147#define GEN6_PCODE_WRITE_RC6VIDS 0x4 7157#define GEN6_PCODE_WRITE_RC6VIDS 0x4
7148#define GEN6_PCODE_READ_RC6VIDS 0x5 7158#define GEN6_PCODE_READ_RC6VIDS 0x5
7149#define GEN6_ENCODE_RC6_VID(mv) (((mv) - 245) / 5) 7159#define GEN6_ENCODE_RC6_VID(mv) (((mv) - 245) / 5)
@@ -7165,6 +7175,10 @@ enum {
7165#define HSW_PCODE_DE_WRITE_FREQ_REQ 0x17 7175#define HSW_PCODE_DE_WRITE_FREQ_REQ 0x17
7166#define DISPLAY_IPS_CONTROL 0x19 7176#define DISPLAY_IPS_CONTROL 0x19
7167#define HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL 0x1A 7177#define HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL 0x1A
7178#define GEN9_PCODE_SAGV_CONTROL 0x21
7179#define GEN9_SAGV_DISABLE 0x0
7180#define GEN9_SAGV_IS_DISABLED 0x1
7181#define GEN9_SAGV_ENABLE 0x3
7168#define GEN6_PCODE_DATA _MMIO(0x138128) 7182#define GEN6_PCODE_DATA _MMIO(0x138128)
7169#define GEN6_PCODE_FREQ_IA_RATIO_SHIFT 8 7183#define GEN6_PCODE_FREQ_IA_RATIO_SHIFT 8
7170#define GEN6_PCODE_FREQ_RING_RATIO_SHIFT 16 7184#define GEN6_PCODE_FREQ_RING_RATIO_SHIFT 16
diff --git a/drivers/gpu/drm/i915/intel_audio.c b/drivers/gpu/drm/i915/intel_audio.c
index 6700a7be7f78..d32f586f9c05 100644
--- a/drivers/gpu/drm/i915/intel_audio.c
+++ b/drivers/gpu/drm/i915/intel_audio.c
@@ -600,6 +600,8 @@ static void i915_audio_component_codec_wake_override(struct device *dev,
600 if (!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv)) 600 if (!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv))
601 return; 601 return;
602 602
603 i915_audio_component_get_power(dev);
604
603 /* 605 /*
604 * Enable/disable generating the codec wake signal, overriding the 606 * Enable/disable generating the codec wake signal, overriding the
605 * internal logic to generate the codec wake to controller. 607 * internal logic to generate the codec wake to controller.
@@ -615,6 +617,8 @@ static void i915_audio_component_codec_wake_override(struct device *dev,
615 I915_WRITE(HSW_AUD_CHICKENBIT, tmp); 617 I915_WRITE(HSW_AUD_CHICKENBIT, tmp);
616 usleep_range(1000, 1500); 618 usleep_range(1000, 1500);
617 } 619 }
620
621 i915_audio_component_put_power(dev);
618} 622}
619 623
620/* Get CDCLK in kHz */ 624/* Get CDCLK in kHz */
@@ -648,6 +652,7 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
648 !IS_HASWELL(dev_priv)) 652 !IS_HASWELL(dev_priv))
649 return 0; 653 return 0;
650 654
655 i915_audio_component_get_power(dev);
651 mutex_lock(&dev_priv->av_mutex); 656 mutex_lock(&dev_priv->av_mutex);
652 /* 1. get the pipe */ 657 /* 1. get the pipe */
653 intel_encoder = dev_priv->dig_port_map[port]; 658 intel_encoder = dev_priv->dig_port_map[port];
@@ -698,6 +703,7 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
698 703
699 unlock: 704 unlock:
700 mutex_unlock(&dev_priv->av_mutex); 705 mutex_unlock(&dev_priv->av_mutex);
706 i915_audio_component_put_power(dev);
701 return err; 707 return err;
702} 708}
703 709
diff --git a/drivers/gpu/drm/i915/intel_csr.c b/drivers/gpu/drm/i915/intel_csr.c
index 3edb9580928e..c3b33a10c15c 100644
--- a/drivers/gpu/drm/i915/intel_csr.c
+++ b/drivers/gpu/drm/i915/intel_csr.c
@@ -41,15 +41,15 @@
41 * be moved to FW_FAILED. 41 * be moved to FW_FAILED.
42 */ 42 */
43 43
44#define I915_CSR_KBL "i915/kbl_dmc_ver1.bin" 44#define I915_CSR_KBL "i915/kbl_dmc_ver1_01.bin"
45MODULE_FIRMWARE(I915_CSR_KBL); 45MODULE_FIRMWARE(I915_CSR_KBL);
46#define KBL_CSR_VERSION_REQUIRED CSR_VERSION(1, 1) 46#define KBL_CSR_VERSION_REQUIRED CSR_VERSION(1, 1)
47 47
48#define I915_CSR_SKL "i915/skl_dmc_ver1.bin" 48#define I915_CSR_SKL "i915/skl_dmc_ver1_26.bin"
49MODULE_FIRMWARE(I915_CSR_SKL); 49MODULE_FIRMWARE(I915_CSR_SKL);
50#define SKL_CSR_VERSION_REQUIRED CSR_VERSION(1, 23) 50#define SKL_CSR_VERSION_REQUIRED CSR_VERSION(1, 26)
51 51
52#define I915_CSR_BXT "i915/bxt_dmc_ver1.bin" 52#define I915_CSR_BXT "i915/bxt_dmc_ver1_07.bin"
53MODULE_FIRMWARE(I915_CSR_BXT); 53MODULE_FIRMWARE(I915_CSR_BXT);
54#define BXT_CSR_VERSION_REQUIRED CSR_VERSION(1, 7) 54#define BXT_CSR_VERSION_REQUIRED CSR_VERSION(1, 7)
55 55
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index dd1d6fe12297..1a7efac65fd5 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -145,7 +145,7 @@ static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
145static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = { 145static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
146 { 0x0000201B, 0x000000A2, 0x0 }, 146 { 0x0000201B, 0x000000A2, 0x0 },
147 { 0x00005012, 0x00000088, 0x0 }, 147 { 0x00005012, 0x00000088, 0x0 },
148 { 0x80007011, 0x000000CD, 0x0 }, 148 { 0x80007011, 0x000000CD, 0x1 },
149 { 0x80009010, 0x000000C0, 0x1 }, 149 { 0x80009010, 0x000000C0, 0x1 },
150 { 0x0000201B, 0x0000009D, 0x0 }, 150 { 0x0000201B, 0x0000009D, 0x0 },
151 { 0x80005012, 0x000000C0, 0x1 }, 151 { 0x80005012, 0x000000C0, 0x1 },
@@ -158,7 +158,7 @@ static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
158static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = { 158static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
159 { 0x00000018, 0x000000A2, 0x0 }, 159 { 0x00000018, 0x000000A2, 0x0 },
160 { 0x00005012, 0x00000088, 0x0 }, 160 { 0x00005012, 0x00000088, 0x0 },
161 { 0x80007011, 0x000000CD, 0x0 }, 161 { 0x80007011, 0x000000CD, 0x3 },
162 { 0x80009010, 0x000000C0, 0x3 }, 162 { 0x80009010, 0x000000C0, 0x3 },
163 { 0x00000018, 0x0000009D, 0x0 }, 163 { 0x00000018, 0x0000009D, 0x0 },
164 { 0x80005012, 0x000000C0, 0x3 }, 164 { 0x80005012, 0x000000C0, 0x3 },
@@ -388,6 +388,40 @@ skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
388 } 388 }
389} 389}
390 390
391static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
392{
393 int n_hdmi_entries;
394 int hdmi_level;
395 int hdmi_default_entry;
396
397 hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
398
399 if (IS_BROXTON(dev_priv))
400 return hdmi_level;
401
402 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
403 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
404 hdmi_default_entry = 8;
405 } else if (IS_BROADWELL(dev_priv)) {
406 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
407 hdmi_default_entry = 7;
408 } else if (IS_HASWELL(dev_priv)) {
409 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
410 hdmi_default_entry = 6;
411 } else {
412 WARN(1, "ddi translation table missing\n");
413 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
414 hdmi_default_entry = 7;
415 }
416
417 /* Choose a good default if VBT is badly populated */
418 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
419 hdmi_level >= n_hdmi_entries)
420 hdmi_level = hdmi_default_entry;
421
422 return hdmi_level;
423}
424
391/* 425/*
392 * Starting with Haswell, DDI port buffers must be programmed with correct 426 * Starting with Haswell, DDI port buffers must be programmed with correct
393 * values in advance. The buffer values are different for FDI and DP modes, 427 * values in advance. The buffer values are different for FDI and DP modes,
@@ -399,7 +433,7 @@ void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
399{ 433{
400 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 434 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
401 u32 iboost_bit = 0; 435 u32 iboost_bit = 0;
402 int i, n_hdmi_entries, n_dp_entries, n_edp_entries, hdmi_default_entry, 436 int i, n_hdmi_entries, n_dp_entries, n_edp_entries,
403 size; 437 size;
404 int hdmi_level; 438 int hdmi_level;
405 enum port port; 439 enum port port;
@@ -410,7 +444,7 @@ void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
410 const struct ddi_buf_trans *ddi_translations; 444 const struct ddi_buf_trans *ddi_translations;
411 445
412 port = intel_ddi_get_encoder_port(encoder); 446 port = intel_ddi_get_encoder_port(encoder);
413 hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift; 447 hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
414 448
415 if (IS_BROXTON(dev_priv)) { 449 if (IS_BROXTON(dev_priv)) {
416 if (encoder->type != INTEL_OUTPUT_HDMI) 450 if (encoder->type != INTEL_OUTPUT_HDMI)
@@ -430,7 +464,6 @@ void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
430 skl_get_buf_trans_edp(dev_priv, &n_edp_entries); 464 skl_get_buf_trans_edp(dev_priv, &n_edp_entries);
431 ddi_translations_hdmi = 465 ddi_translations_hdmi =
432 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries); 466 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
433 hdmi_default_entry = 8;
434 /* If we're boosting the current, set bit 31 of trans1 */ 467 /* If we're boosting the current, set bit 31 of trans1 */
435 if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level || 468 if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level ||
436 dev_priv->vbt.ddi_port_info[port].dp_boost_level) 469 dev_priv->vbt.ddi_port_info[port].dp_boost_level)
@@ -456,7 +489,6 @@ void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
456 489
457 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 490 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
458 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); 491 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
459 hdmi_default_entry = 7;
460 } else if (IS_HASWELL(dev_priv)) { 492 } else if (IS_HASWELL(dev_priv)) {
461 ddi_translations_fdi = hsw_ddi_translations_fdi; 493 ddi_translations_fdi = hsw_ddi_translations_fdi;
462 ddi_translations_dp = hsw_ddi_translations_dp; 494 ddi_translations_dp = hsw_ddi_translations_dp;
@@ -464,7 +496,6 @@ void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
464 ddi_translations_hdmi = hsw_ddi_translations_hdmi; 496 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
465 n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp); 497 n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
466 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); 498 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
467 hdmi_default_entry = 6;
468 } else { 499 } else {
469 WARN(1, "ddi translation table missing\n"); 500 WARN(1, "ddi translation table missing\n");
470 ddi_translations_edp = bdw_ddi_translations_dp; 501 ddi_translations_edp = bdw_ddi_translations_dp;
@@ -474,7 +505,6 @@ void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
474 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp); 505 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
475 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 506 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
476 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); 507 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
477 hdmi_default_entry = 7;
478 } 508 }
479 509
480 switch (encoder->type) { 510 switch (encoder->type) {
@@ -505,11 +535,6 @@ void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
505 if (encoder->type != INTEL_OUTPUT_HDMI) 535 if (encoder->type != INTEL_OUTPUT_HDMI)
506 return; 536 return;
507 537
508 /* Choose a good default if VBT is badly populated */
509 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
510 hdmi_level >= n_hdmi_entries)
511 hdmi_level = hdmi_default_entry;
512
513 /* Entry 9 is for HDMI: */ 538 /* Entry 9 is for HDMI: */
514 I915_WRITE(DDI_BUF_TRANS_LO(port, i), 539 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
515 ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit); 540 ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
@@ -1379,14 +1404,30 @@ void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1379 TRANS_CLK_SEL_DISABLED); 1404 TRANS_CLK_SEL_DISABLED);
1380} 1405}
1381 1406
1382static void skl_ddi_set_iboost(struct drm_i915_private *dev_priv, 1407static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1383 u32 level, enum port port, int type) 1408 enum port port, uint8_t iboost)
1384{ 1409{
1410 u32 tmp;
1411
1412 tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
1413 tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
1414 if (iboost)
1415 tmp |= iboost << BALANCE_LEG_SHIFT(port);
1416 else
1417 tmp |= BALANCE_LEG_DISABLE(port);
1418 I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
1419}
1420
1421static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
1422{
1423 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
1424 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
1425 enum port port = intel_dig_port->port;
1426 int type = encoder->type;
1385 const struct ddi_buf_trans *ddi_translations; 1427 const struct ddi_buf_trans *ddi_translations;
1386 uint8_t iboost; 1428 uint8_t iboost;
1387 uint8_t dp_iboost, hdmi_iboost; 1429 uint8_t dp_iboost, hdmi_iboost;
1388 int n_entries; 1430 int n_entries;
1389 u32 reg;
1390 1431
1391 /* VBT may override standard boost values */ 1432 /* VBT may override standard boost values */
1392 dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level; 1433 dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
@@ -1428,16 +1469,10 @@ static void skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1428 return; 1469 return;
1429 } 1470 }
1430 1471
1431 reg = I915_READ(DISPIO_CR_TX_BMU_CR0); 1472 _skl_ddi_set_iboost(dev_priv, port, iboost);
1432 reg &= ~BALANCE_LEG_MASK(port);
1433 reg &= ~(1 << (BALANCE_LEG_DISABLE_SHIFT + port));
1434
1435 if (iboost)
1436 reg |= iboost << BALANCE_LEG_SHIFT(port);
1437 else
1438 reg |= 1 << (BALANCE_LEG_DISABLE_SHIFT + port);
1439 1473
1440 I915_WRITE(DISPIO_CR_TX_BMU_CR0, reg); 1474 if (port == PORT_A && intel_dig_port->max_lanes == 4)
1475 _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
1441} 1476}
1442 1477
1443static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv, 1478static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
@@ -1568,7 +1603,7 @@ uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
1568 level = translate_signal_level(signal_levels); 1603 level = translate_signal_level(signal_levels);
1569 1604
1570 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) 1605 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
1571 skl_ddi_set_iboost(dev_priv, level, port, encoder->type); 1606 skl_ddi_set_iboost(encoder, level);
1572 else if (IS_BROXTON(dev_priv)) 1607 else if (IS_BROXTON(dev_priv))
1573 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type); 1608 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
1574 1609
@@ -1637,6 +1672,10 @@ static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
1637 intel_dp_stop_link_train(intel_dp); 1672 intel_dp_stop_link_train(intel_dp);
1638 } else if (type == INTEL_OUTPUT_HDMI) { 1673 } else if (type == INTEL_OUTPUT_HDMI) {
1639 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1674 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1675 int level = intel_ddi_hdmi_level(dev_priv, port);
1676
1677 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
1678 skl_ddi_set_iboost(intel_encoder, level);
1640 1679
1641 intel_hdmi->set_infoframes(encoder, 1680 intel_hdmi->set_infoframes(encoder,
1642 crtc->config->has_hdmi_sink, 1681 crtc->config->has_hdmi_sink,
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index dcf93b3d4fb6..175595fc3e45 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -3093,40 +3093,110 @@ static void intel_update_primary_planes(struct drm_device *dev)
3093 3093
3094 for_each_crtc(dev, crtc) { 3094 for_each_crtc(dev, crtc) {
3095 struct intel_plane *plane = to_intel_plane(crtc->primary); 3095 struct intel_plane *plane = to_intel_plane(crtc->primary);
3096 struct intel_plane_state *plane_state; 3096 struct intel_plane_state *plane_state =
3097 3097 to_intel_plane_state(plane->base.state);
3098 drm_modeset_lock_crtc(crtc, &plane->base);
3099 plane_state = to_intel_plane_state(plane->base.state);
3100 3098
3101 if (plane_state->visible) 3099 if (plane_state->visible)
3102 plane->update_plane(&plane->base, 3100 plane->update_plane(&plane->base,
3103 to_intel_crtc_state(crtc->state), 3101 to_intel_crtc_state(crtc->state),
3104 plane_state); 3102 plane_state);
3103 }
3104}
3105
3106static int
3107__intel_display_resume(struct drm_device *dev,
3108 struct drm_atomic_state *state)
3109{
3110 struct drm_crtc_state *crtc_state;
3111 struct drm_crtc *crtc;
3112 int i, ret;
3113
3114 intel_modeset_setup_hw_state(dev);
3115 i915_redisable_vga(dev);
3105 3116
3106 drm_modeset_unlock_crtc(crtc); 3117 if (!state)
3118 return 0;
3119
3120 for_each_crtc_in_state(state, crtc, crtc_state, i) {
3121 /*
3122 * Force recalculation even if we restore
3123 * current state. With fast modeset this may not result
3124 * in a modeset when the state is compatible.
3125 */
3126 crtc_state->mode_changed = true;
3107 } 3127 }
3128
3129 /* ignore any reset values/BIOS leftovers in the WM registers */
3130 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3131
3132 ret = drm_atomic_commit(state);
3133
3134 WARN_ON(ret == -EDEADLK);
3135 return ret;
3108} 3136}
3109 3137
3110void intel_prepare_reset(struct drm_i915_private *dev_priv) 3138void intel_prepare_reset(struct drm_i915_private *dev_priv)
3111{ 3139{
3140 struct drm_device *dev = &dev_priv->drm;
3141 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3142 struct drm_atomic_state *state;
3143 int ret;
3144
3112 /* no reset support for gen2 */ 3145 /* no reset support for gen2 */
3113 if (IS_GEN2(dev_priv)) 3146 if (IS_GEN2(dev_priv))
3114 return; 3147 return;
3115 3148
3116 /* reset doesn't touch the display */ 3149 /*
3150 * Need mode_config.mutex so that we don't
3151 * trample ongoing ->detect() and whatnot.
3152 */
3153 mutex_lock(&dev->mode_config.mutex);
3154 drm_modeset_acquire_init(ctx, 0);
3155 while (1) {
3156 ret = drm_modeset_lock_all_ctx(dev, ctx);
3157 if (ret != -EDEADLK)
3158 break;
3159
3160 drm_modeset_backoff(ctx);
3161 }
3162
3163 /* reset doesn't touch the display, but flips might get nuked anyway, */
3117 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) 3164 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
3118 return; 3165 return;
3119 3166
3120 drm_modeset_lock_all(&dev_priv->drm);
3121 /* 3167 /*
3122 * Disabling the crtcs gracefully seems nicer. Also the 3168 * Disabling the crtcs gracefully seems nicer. Also the
3123 * g33 docs say we should at least disable all the planes. 3169 * g33 docs say we should at least disable all the planes.
3124 */ 3170 */
3125 intel_display_suspend(&dev_priv->drm); 3171 state = drm_atomic_helper_duplicate_state(dev, ctx);
3172 if (IS_ERR(state)) {
3173 ret = PTR_ERR(state);
3174 state = NULL;
3175 DRM_ERROR("Duplicating state failed with %i\n", ret);
3176 goto err;
3177 }
3178
3179 ret = drm_atomic_helper_disable_all(dev, ctx);
3180 if (ret) {
3181 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3182 goto err;
3183 }
3184
3185 dev_priv->modeset_restore_state = state;
3186 state->acquire_ctx = ctx;
3187 return;
3188
3189err:
3190 drm_atomic_state_free(state);
3126} 3191}
3127 3192
3128void intel_finish_reset(struct drm_i915_private *dev_priv) 3193void intel_finish_reset(struct drm_i915_private *dev_priv)
3129{ 3194{
3195 struct drm_device *dev = &dev_priv->drm;
3196 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3197 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
3198 int ret;
3199
3130 /* 3200 /*
3131 * Flips in the rings will be nuked by the reset, 3201 * Flips in the rings will be nuked by the reset,
3132 * so complete all pending flips so that user space 3202 * so complete all pending flips so that user space
@@ -3138,6 +3208,8 @@ void intel_finish_reset(struct drm_i915_private *dev_priv)
3138 if (IS_GEN2(dev_priv)) 3208 if (IS_GEN2(dev_priv))
3139 return; 3209 return;
3140 3210
3211 dev_priv->modeset_restore_state = NULL;
3212
3141 /* reset doesn't touch the display */ 3213 /* reset doesn't touch the display */
3142 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) { 3214 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) {
3143 /* 3215 /*
@@ -3149,29 +3221,32 @@ void intel_finish_reset(struct drm_i915_private *dev_priv)
3149 * FIXME: Atomic will make this obsolete since we won't schedule 3221 * FIXME: Atomic will make this obsolete since we won't schedule
3150 * CS-based flips (which might get lost in gpu resets) any more. 3222 * CS-based flips (which might get lost in gpu resets) any more.
3151 */ 3223 */
3152 intel_update_primary_planes(&dev_priv->drm); 3224 intel_update_primary_planes(dev);
3153 return; 3225 } else {
3154 } 3226 /*
3155 3227 * The display has been reset as well,
3156 /* 3228 * so need a full re-initialization.
3157 * The display has been reset as well, 3229 */
3158 * so need a full re-initialization. 3230 intel_runtime_pm_disable_interrupts(dev_priv);
3159 */ 3231 intel_runtime_pm_enable_interrupts(dev_priv);
3160 intel_runtime_pm_disable_interrupts(dev_priv);
3161 intel_runtime_pm_enable_interrupts(dev_priv);
3162 3232
3163 intel_modeset_init_hw(&dev_priv->drm); 3233 intel_modeset_init_hw(dev);
3164 3234
3165 spin_lock_irq(&dev_priv->irq_lock); 3235 spin_lock_irq(&dev_priv->irq_lock);
3166 if (dev_priv->display.hpd_irq_setup) 3236 if (dev_priv->display.hpd_irq_setup)
3167 dev_priv->display.hpd_irq_setup(dev_priv); 3237 dev_priv->display.hpd_irq_setup(dev_priv);
3168 spin_unlock_irq(&dev_priv->irq_lock); 3238 spin_unlock_irq(&dev_priv->irq_lock);
3169 3239
3170 intel_display_resume(&dev_priv->drm); 3240 ret = __intel_display_resume(dev, state);
3241 if (ret)
3242 DRM_ERROR("Restoring old state failed with %i\n", ret);
3171 3243
3172 intel_hpd_init(dev_priv); 3244 intel_hpd_init(dev_priv);
3245 }
3173 3246
3174 drm_modeset_unlock_all(&dev_priv->drm); 3247 drm_modeset_drop_locks(ctx);
3248 drm_modeset_acquire_fini(ctx);
3249 mutex_unlock(&dev->mode_config.mutex);
3175} 3250}
3176 3251
3177static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) 3252static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
@@ -13684,6 +13759,13 @@ static void intel_atomic_commit_tail(struct drm_atomic_state *state)
13684 intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco)) 13759 intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco))
13685 dev_priv->display.modeset_commit_cdclk(state); 13760 dev_priv->display.modeset_commit_cdclk(state);
13686 13761
13762 /*
13763 * SKL workaround: bspec recommends we disable the SAGV when we
13764 * have more then one pipe enabled
13765 */
13766 if (IS_SKYLAKE(dev_priv) && !skl_can_enable_sagv(state))
13767 skl_disable_sagv(dev_priv);
13768
13687 intel_modeset_verify_disabled(dev); 13769 intel_modeset_verify_disabled(dev);
13688 } 13770 }
13689 13771
@@ -13757,6 +13839,10 @@ static void intel_atomic_commit_tail(struct drm_atomic_state *state)
13757 intel_modeset_verify_crtc(crtc, old_crtc_state, crtc->state); 13839 intel_modeset_verify_crtc(crtc, old_crtc_state, crtc->state);
13758 } 13840 }
13759 13841
13842 if (IS_SKYLAKE(dev_priv) && intel_state->modeset &&
13843 skl_can_enable_sagv(state))
13844 skl_enable_sagv(dev_priv);
13845
13760 drm_atomic_helper_commit_hw_done(state); 13846 drm_atomic_helper_commit_hw_done(state);
13761 13847
13762 if (intel_state->modeset) 13848 if (intel_state->modeset)
@@ -16156,9 +16242,10 @@ void intel_display_resume(struct drm_device *dev)
16156 struct drm_atomic_state *state = dev_priv->modeset_restore_state; 16242 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
16157 struct drm_modeset_acquire_ctx ctx; 16243 struct drm_modeset_acquire_ctx ctx;
16158 int ret; 16244 int ret;
16159 bool setup = false;
16160 16245
16161 dev_priv->modeset_restore_state = NULL; 16246 dev_priv->modeset_restore_state = NULL;
16247 if (state)
16248 state->acquire_ctx = &ctx;
16162 16249
16163 /* 16250 /*
16164 * This is a cludge because with real atomic modeset mode_config.mutex 16251 * This is a cludge because with real atomic modeset mode_config.mutex
@@ -16169,43 +16256,17 @@ void intel_display_resume(struct drm_device *dev)
16169 mutex_lock(&dev->mode_config.mutex); 16256 mutex_lock(&dev->mode_config.mutex);
16170 drm_modeset_acquire_init(&ctx, 0); 16257 drm_modeset_acquire_init(&ctx, 0);
16171 16258
16172retry: 16259 while (1) {
16173 ret = drm_modeset_lock_all_ctx(dev, &ctx); 16260 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16174 16261 if (ret != -EDEADLK)
16175 if (ret == 0 && !setup) { 16262 break;
16176 setup = true;
16177
16178 intel_modeset_setup_hw_state(dev);
16179 i915_redisable_vga(dev);
16180 }
16181
16182 if (ret == 0 && state) {
16183 struct drm_crtc_state *crtc_state;
16184 struct drm_crtc *crtc;
16185 int i;
16186
16187 state->acquire_ctx = &ctx;
16188
16189 /* ignore any reset values/BIOS leftovers in the WM registers */
16190 to_intel_atomic_state(state)->skip_intermediate_wm = true;
16191
16192 for_each_crtc_in_state(state, crtc, crtc_state, i) {
16193 /*
16194 * Force recalculation even if we restore
16195 * current state. With fast modeset this may not result
16196 * in a modeset when the state is compatible.
16197 */
16198 crtc_state->mode_changed = true;
16199 }
16200
16201 ret = drm_atomic_commit(state);
16202 }
16203 16263
16204 if (ret == -EDEADLK) {
16205 drm_modeset_backoff(&ctx); 16264 drm_modeset_backoff(&ctx);
16206 goto retry;
16207 } 16265 }
16208 16266
16267 if (!ret)
16268 ret = __intel_display_resume(dev, state);
16269
16209 drm_modeset_drop_locks(&ctx); 16270 drm_modeset_drop_locks(&ctx);
16210 drm_modeset_acquire_fini(&ctx); 16271 drm_modeset_acquire_fini(&ctx);
16211 mutex_unlock(&dev->mode_config.mutex); 16272 mutex_unlock(&dev->mode_config.mutex);
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index cc937a19b1ba..ff399b9a5c1f 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1716,6 +1716,9 @@ void ilk_wm_get_hw_state(struct drm_device *dev);
1716void skl_wm_get_hw_state(struct drm_device *dev); 1716void skl_wm_get_hw_state(struct drm_device *dev);
1717void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, 1717void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv,
1718 struct skl_ddb_allocation *ddb /* out */); 1718 struct skl_ddb_allocation *ddb /* out */);
1719bool skl_can_enable_sagv(struct drm_atomic_state *state);
1720int skl_enable_sagv(struct drm_i915_private *dev_priv);
1721int skl_disable_sagv(struct drm_i915_private *dev_priv);
1719uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config); 1722uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config);
1720bool ilk_disable_lp_wm(struct drm_device *dev); 1723bool ilk_disable_lp_wm(struct drm_device *dev);
1721int sanitize_rc6_option(struct drm_i915_private *dev_priv, int enable_rc6); 1724int sanitize_rc6_option(struct drm_i915_private *dev_priv, int enable_rc6);
diff --git a/drivers/gpu/drm/i915/intel_fbc.c b/drivers/gpu/drm/i915/intel_fbc.c
index 6a7ad3ed1463..3836a1c79714 100644
--- a/drivers/gpu/drm/i915/intel_fbc.c
+++ b/drivers/gpu/drm/i915/intel_fbc.c
@@ -1230,12 +1230,29 @@ static int intel_sanitize_fbc_option(struct drm_i915_private *dev_priv)
1230 if (i915.enable_fbc >= 0) 1230 if (i915.enable_fbc >= 0)
1231 return !!i915.enable_fbc; 1231 return !!i915.enable_fbc;
1232 1232
1233 if (!HAS_FBC(dev_priv))
1234 return 0;
1235
1233 if (IS_BROADWELL(dev_priv)) 1236 if (IS_BROADWELL(dev_priv))
1234 return 1; 1237 return 1;
1235 1238
1236 return 0; 1239 return 0;
1237} 1240}
1238 1241
1242static bool need_fbc_vtd_wa(struct drm_i915_private *dev_priv)
1243{
1244#ifdef CONFIG_INTEL_IOMMU
1245 /* WaFbcTurnOffFbcWhenHyperVisorIsUsed:skl,bxt */
1246 if (intel_iommu_gfx_mapped &&
1247 (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))) {
1248 DRM_INFO("Disabling framebuffer compression (FBC) to prevent screen flicker with VT-d enabled\n");
1249 return true;
1250 }
1251#endif
1252
1253 return false;
1254}
1255
1239/** 1256/**
1240 * intel_fbc_init - Initialize FBC 1257 * intel_fbc_init - Initialize FBC
1241 * @dev_priv: the i915 device 1258 * @dev_priv: the i915 device
@@ -1253,6 +1270,9 @@ void intel_fbc_init(struct drm_i915_private *dev_priv)
1253 fbc->active = false; 1270 fbc->active = false;
1254 fbc->work.scheduled = false; 1271 fbc->work.scheduled = false;
1255 1272
1273 if (need_fbc_vtd_wa(dev_priv))
1274 mkwrite_device_info(dev_priv)->has_fbc = false;
1275
1256 i915.enable_fbc = intel_sanitize_fbc_option(dev_priv); 1276 i915.enable_fbc = intel_sanitize_fbc_option(dev_priv);
1257 DRM_DEBUG_KMS("Sanitized enable_fbc value: %d\n", i915.enable_fbc); 1277 DRM_DEBUG_KMS("Sanitized enable_fbc value: %d\n", i915.enable_fbc);
1258 1278
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index 97ba6c8cf907..53e13c10e4ea 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -2852,6 +2852,7 @@ bool ilk_disable_lp_wm(struct drm_device *dev)
2852 2852
2853#define SKL_DDB_SIZE 896 /* in blocks */ 2853#define SKL_DDB_SIZE 896 /* in blocks */
2854#define BXT_DDB_SIZE 512 2854#define BXT_DDB_SIZE 512
2855#define SKL_SAGV_BLOCK_TIME 30 /* µs */
2855 2856
2856/* 2857/*
2857 * Return the index of a plane in the SKL DDB and wm result arrays. Primary 2858 * Return the index of a plane in the SKL DDB and wm result arrays. Primary
@@ -2875,6 +2876,153 @@ skl_wm_plane_id(const struct intel_plane *plane)
2875 } 2876 }
2876} 2877}
2877 2878
2879/*
2880 * SAGV dynamically adjusts the system agent voltage and clock frequencies
2881 * depending on power and performance requirements. The display engine access
2882 * to system memory is blocked during the adjustment time. Because of the
2883 * blocking time, having this enabled can cause full system hangs and/or pipe
2884 * underruns if we don't meet all of the following requirements:
2885 *
2886 * - <= 1 pipe enabled
2887 * - All planes can enable watermarks for latencies >= SAGV engine block time
2888 * - We're not using an interlaced display configuration
2889 */
2890int
2891skl_enable_sagv(struct drm_i915_private *dev_priv)
2892{
2893 int ret;
2894
2895 if (dev_priv->skl_sagv_status == I915_SKL_SAGV_NOT_CONTROLLED ||
2896 dev_priv->skl_sagv_status == I915_SKL_SAGV_ENABLED)
2897 return 0;
2898
2899 DRM_DEBUG_KMS("Enabling the SAGV\n");
2900 mutex_lock(&dev_priv->rps.hw_lock);
2901
2902 ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL,
2903 GEN9_SAGV_ENABLE);
2904
2905 /* We don't need to wait for the SAGV when enabling */
2906 mutex_unlock(&dev_priv->rps.hw_lock);
2907
2908 /*
2909 * Some skl systems, pre-release machines in particular,
2910 * don't actually have an SAGV.
2911 */
2912 if (ret == -ENXIO) {
2913 DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n");
2914 dev_priv->skl_sagv_status = I915_SKL_SAGV_NOT_CONTROLLED;
2915 return 0;
2916 } else if (ret < 0) {
2917 DRM_ERROR("Failed to enable the SAGV\n");
2918 return ret;
2919 }
2920
2921 dev_priv->skl_sagv_status = I915_SKL_SAGV_ENABLED;
2922 return 0;
2923}
2924
2925static int
2926skl_do_sagv_disable(struct drm_i915_private *dev_priv)
2927{
2928 int ret;
2929 uint32_t temp = GEN9_SAGV_DISABLE;
2930
2931 ret = sandybridge_pcode_read(dev_priv, GEN9_PCODE_SAGV_CONTROL,
2932 &temp);
2933 if (ret)
2934 return ret;
2935 else
2936 return temp & GEN9_SAGV_IS_DISABLED;
2937}
2938
2939int
2940skl_disable_sagv(struct drm_i915_private *dev_priv)
2941{
2942 int ret, result;
2943
2944 if (dev_priv->skl_sagv_status == I915_SKL_SAGV_NOT_CONTROLLED ||
2945 dev_priv->skl_sagv_status == I915_SKL_SAGV_DISABLED)
2946 return 0;
2947
2948 DRM_DEBUG_KMS("Disabling the SAGV\n");
2949 mutex_lock(&dev_priv->rps.hw_lock);
2950
2951 /* bspec says to keep retrying for at least 1 ms */
2952 ret = wait_for(result = skl_do_sagv_disable(dev_priv), 1);
2953 mutex_unlock(&dev_priv->rps.hw_lock);
2954
2955 if (ret == -ETIMEDOUT) {
2956 DRM_ERROR("Request to disable SAGV timed out\n");
2957 return -ETIMEDOUT;
2958 }
2959
2960 /*
2961 * Some skl systems, pre-release machines in particular,
2962 * don't actually have an SAGV.
2963 */
2964 if (result == -ENXIO) {
2965 DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n");
2966 dev_priv->skl_sagv_status = I915_SKL_SAGV_NOT_CONTROLLED;
2967 return 0;
2968 } else if (result < 0) {
2969 DRM_ERROR("Failed to disable the SAGV\n");
2970 return result;
2971 }
2972
2973 dev_priv->skl_sagv_status = I915_SKL_SAGV_DISABLED;
2974 return 0;
2975}
2976
2977bool skl_can_enable_sagv(struct drm_atomic_state *state)
2978{
2979 struct drm_device *dev = state->dev;
2980 struct drm_i915_private *dev_priv = to_i915(dev);
2981 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
2982 struct drm_crtc *crtc;
2983 enum pipe pipe;
2984 int level, plane;
2985
2986 /*
2987 * SKL workaround: bspec recommends we disable the SAGV when we have
2988 * more then one pipe enabled
2989 *
2990 * If there are no active CRTCs, no additional checks need be performed
2991 */
2992 if (hweight32(intel_state->active_crtcs) == 0)
2993 return true;
2994 else if (hweight32(intel_state->active_crtcs) > 1)
2995 return false;
2996
2997 /* Since we're now guaranteed to only have one active CRTC... */
2998 pipe = ffs(intel_state->active_crtcs) - 1;
2999 crtc = dev_priv->pipe_to_crtc_mapping[pipe];
3000
3001 if (crtc->state->mode.flags & DRM_MODE_FLAG_INTERLACE)
3002 return false;
3003
3004 for_each_plane(dev_priv, pipe, plane) {
3005 /* Skip this plane if it's not enabled */
3006 if (intel_state->wm_results.plane[pipe][plane][0] == 0)
3007 continue;
3008
3009 /* Find the highest enabled wm level for this plane */
3010 for (level = ilk_wm_max_level(dev);
3011 intel_state->wm_results.plane[pipe][plane][level] == 0; --level)
3012 { }
3013
3014 /*
3015 * If any of the planes on this pipe don't enable wm levels
3016 * that incur memory latencies higher then 30µs we can't enable
3017 * the SAGV
3018 */
3019 if (dev_priv->wm.skl_latency[level] < SKL_SAGV_BLOCK_TIME)
3020 return false;
3021 }
3022
3023 return true;
3024}
3025
2878static void 3026static void
2879skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, 3027skl_ddb_get_pipe_allocation_limits(struct drm_device *dev,
2880 const struct intel_crtc_state *cstate, 3028 const struct intel_crtc_state *cstate,
@@ -3107,8 +3255,6 @@ skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate)
3107 total_data_rate += intel_cstate->wm.skl.plane_y_data_rate[id]; 3255 total_data_rate += intel_cstate->wm.skl.plane_y_data_rate[id];
3108 } 3256 }
3109 3257
3110 WARN_ON(cstate->plane_mask && total_data_rate == 0);
3111
3112 return total_data_rate; 3258 return total_data_rate;
3113} 3259}
3114 3260
@@ -3344,6 +3490,8 @@ static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal,
3344 plane_bytes_per_line *= 4; 3490 plane_bytes_per_line *= 4;
3345 plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); 3491 plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512);
3346 plane_blocks_per_line /= 4; 3492 plane_blocks_per_line /= 4;
3493 } else if (tiling == DRM_FORMAT_MOD_NONE) {
3494 plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512) + 1;
3347 } else { 3495 } else {
3348 plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); 3496 plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512);
3349 } 3497 }
@@ -3910,9 +4058,24 @@ skl_compute_ddb(struct drm_atomic_state *state)
3910 * pretend that all pipes switched active status so that we'll 4058 * pretend that all pipes switched active status so that we'll
3911 * ensure a full DDB recompute. 4059 * ensure a full DDB recompute.
3912 */ 4060 */
3913 if (dev_priv->wm.distrust_bios_wm) 4061 if (dev_priv->wm.distrust_bios_wm) {
4062 ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
4063 state->acquire_ctx);
4064 if (ret)
4065 return ret;
4066
3914 intel_state->active_pipe_changes = ~0; 4067 intel_state->active_pipe_changes = ~0;
3915 4068
4069 /*
4070 * We usually only initialize intel_state->active_crtcs if we
4071 * we're doing a modeset; make sure this field is always
4072 * initialized during the sanitization process that happens
4073 * on the first commit too.
4074 */
4075 if (!intel_state->modeset)
4076 intel_state->active_crtcs = dev_priv->active_crtcs;
4077 }
4078
3916 /* 4079 /*
3917 * If the modeset changes which CRTC's are active, we need to 4080 * If the modeset changes which CRTC's are active, we need to
3918 * recompute the DDB allocation for *all* active pipes, even 4081 * recompute the DDB allocation for *all* active pipes, even
@@ -3941,11 +4104,33 @@ skl_compute_ddb(struct drm_atomic_state *state)
3941 ret = skl_allocate_pipe_ddb(cstate, ddb); 4104 ret = skl_allocate_pipe_ddb(cstate, ddb);
3942 if (ret) 4105 if (ret)
3943 return ret; 4106 return ret;
4107
4108 ret = drm_atomic_add_affected_planes(state, &intel_crtc->base);
4109 if (ret)
4110 return ret;
3944 } 4111 }
3945 4112
3946 return 0; 4113 return 0;
3947} 4114}
3948 4115
4116static void
4117skl_copy_wm_for_pipe(struct skl_wm_values *dst,
4118 struct skl_wm_values *src,
4119 enum pipe pipe)
4120{
4121 dst->wm_linetime[pipe] = src->wm_linetime[pipe];
4122 memcpy(dst->plane[pipe], src->plane[pipe],
4123 sizeof(dst->plane[pipe]));
4124 memcpy(dst->plane_trans[pipe], src->plane_trans[pipe],
4125 sizeof(dst->plane_trans[pipe]));
4126
4127 dst->ddb.pipe[pipe] = src->ddb.pipe[pipe];
4128 memcpy(dst->ddb.y_plane[pipe], src->ddb.y_plane[pipe],
4129 sizeof(dst->ddb.y_plane[pipe]));
4130 memcpy(dst->ddb.plane[pipe], src->ddb.plane[pipe],
4131 sizeof(dst->ddb.plane[pipe]));
4132}
4133
3949static int 4134static int
3950skl_compute_wm(struct drm_atomic_state *state) 4135skl_compute_wm(struct drm_atomic_state *state)
3951{ 4136{
@@ -4018,8 +4203,10 @@ static void skl_update_wm(struct drm_crtc *crtc)
4018 struct drm_device *dev = crtc->dev; 4203 struct drm_device *dev = crtc->dev;
4019 struct drm_i915_private *dev_priv = to_i915(dev); 4204 struct drm_i915_private *dev_priv = to_i915(dev);
4020 struct skl_wm_values *results = &dev_priv->wm.skl_results; 4205 struct skl_wm_values *results = &dev_priv->wm.skl_results;
4206 struct skl_wm_values *hw_vals = &dev_priv->wm.skl_hw;
4021 struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state); 4207 struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state);
4022 struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal; 4208 struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal;
4209 int pipe;
4023 4210
4024 if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0) 4211 if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0)
4025 return; 4212 return;
@@ -4031,8 +4218,12 @@ static void skl_update_wm(struct drm_crtc *crtc)
4031 skl_write_wm_values(dev_priv, results); 4218 skl_write_wm_values(dev_priv, results);
4032 skl_flush_wm_values(dev_priv, results); 4219 skl_flush_wm_values(dev_priv, results);
4033 4220
4034 /* store the new configuration */ 4221 /*
4035 dev_priv->wm.skl_hw = *results; 4222 * Store the new configuration (but only for the pipes that have
4223 * changed; the other values weren't recomputed).
4224 */
4225 for_each_pipe_masked(dev_priv, pipe, results->dirty_pipes)
4226 skl_copy_wm_for_pipe(hw_vals, results, pipe);
4036 4227
4037 mutex_unlock(&dev_priv->wm.wm_mutex); 4228 mutex_unlock(&dev_priv->wm.wm_mutex);
4038} 4229}
@@ -6574,9 +6765,7 @@ void intel_init_gt_powersave(struct drm_i915_private *dev_priv)
6574 6765
6575void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv) 6766void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv)
6576{ 6767{
6577 if (IS_CHERRYVIEW(dev_priv)) 6768 if (IS_VALLEYVIEW(dev_priv))
6578 return;
6579 else if (IS_VALLEYVIEW(dev_priv))
6580 valleyview_cleanup_gt_powersave(dev_priv); 6769 valleyview_cleanup_gt_powersave(dev_priv);
6581 6770
6582 if (!i915.enable_rc6) 6771 if (!i915.enable_rc6)
@@ -7658,8 +7847,53 @@ void intel_init_pm(struct drm_device *dev)
7658 } 7847 }
7659} 7848}
7660 7849
7850static inline int gen6_check_mailbox_status(struct drm_i915_private *dev_priv)
7851{
7852 uint32_t flags =
7853 I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK;
7854
7855 switch (flags) {
7856 case GEN6_PCODE_SUCCESS:
7857 return 0;
7858 case GEN6_PCODE_UNIMPLEMENTED_CMD:
7859 case GEN6_PCODE_ILLEGAL_CMD:
7860 return -ENXIO;
7861 case GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE:
7862 return -EOVERFLOW;
7863 case GEN6_PCODE_TIMEOUT:
7864 return -ETIMEDOUT;
7865 default:
7866 MISSING_CASE(flags)
7867 return 0;
7868 }
7869}
7870
7871static inline int gen7_check_mailbox_status(struct drm_i915_private *dev_priv)
7872{
7873 uint32_t flags =
7874 I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK;
7875
7876 switch (flags) {
7877 case GEN6_PCODE_SUCCESS:
7878 return 0;
7879 case GEN6_PCODE_ILLEGAL_CMD:
7880 return -ENXIO;
7881 case GEN7_PCODE_TIMEOUT:
7882 return -ETIMEDOUT;
7883 case GEN7_PCODE_ILLEGAL_DATA:
7884 return -EINVAL;
7885 case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE:
7886 return -EOVERFLOW;
7887 default:
7888 MISSING_CASE(flags);
7889 return 0;
7890 }
7891}
7892
7661int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val) 7893int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val)
7662{ 7894{
7895 int status;
7896
7663 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); 7897 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
7664 7898
7665 /* GEN6_PCODE_* are outside of the forcewake domain, we can 7899 /* GEN6_PCODE_* are outside of the forcewake domain, we can
@@ -7686,12 +7920,25 @@ int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val
7686 *val = I915_READ_FW(GEN6_PCODE_DATA); 7920 *val = I915_READ_FW(GEN6_PCODE_DATA);
7687 I915_WRITE_FW(GEN6_PCODE_DATA, 0); 7921 I915_WRITE_FW(GEN6_PCODE_DATA, 0);
7688 7922
7923 if (INTEL_GEN(dev_priv) > 6)
7924 status = gen7_check_mailbox_status(dev_priv);
7925 else
7926 status = gen6_check_mailbox_status(dev_priv);
7927
7928 if (status) {
7929 DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed: %d\n",
7930 status);
7931 return status;
7932 }
7933
7689 return 0; 7934 return 0;
7690} 7935}
7691 7936
7692int sandybridge_pcode_write(struct drm_i915_private *dev_priv, 7937int sandybridge_pcode_write(struct drm_i915_private *dev_priv,
7693 u32 mbox, u32 val) 7938 u32 mbox, u32 val)
7694{ 7939{
7940 int status;
7941
7695 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); 7942 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
7696 7943
7697 /* GEN6_PCODE_* are outside of the forcewake domain, we can 7944 /* GEN6_PCODE_* are outside of the forcewake domain, we can
@@ -7716,6 +7963,17 @@ int sandybridge_pcode_write(struct drm_i915_private *dev_priv,
7716 7963
7717 I915_WRITE_FW(GEN6_PCODE_DATA, 0); 7964 I915_WRITE_FW(GEN6_PCODE_DATA, 0);
7718 7965
7966 if (INTEL_GEN(dev_priv) > 6)
7967 status = gen7_check_mailbox_status(dev_priv);
7968 else
7969 status = gen6_check_mailbox_status(dev_priv);
7970
7971 if (status) {
7972 DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed: %d\n",
7973 status);
7974 return status;
7975 }
7976
7719 return 0; 7977 return 0;
7720} 7978}
7721 7979
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index cca7792f26d5..1d3161bbea24 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1178,8 +1178,8 @@ static int bxt_init_workarounds(struct intel_engine_cs *engine)
1178 I915_WRITE(GEN8_L3SQCREG1, L3_GENERAL_PRIO_CREDITS(62) | 1178 I915_WRITE(GEN8_L3SQCREG1, L3_GENERAL_PRIO_CREDITS(62) |
1179 L3_HIGH_PRIO_CREDITS(2)); 1179 L3_HIGH_PRIO_CREDITS(2));
1180 1180
1181 /* WaInsertDummyPushConstPs:bxt */ 1181 /* WaToEnableHwFixForPushConstHWBug:bxt */
1182 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0)) 1182 if (IS_BXT_REVID(dev_priv, BXT_REVID_C0, REVID_FOREVER))
1183 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, 1183 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1184 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); 1184 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
1185 1185
@@ -1222,8 +1222,8 @@ static int kbl_init_workarounds(struct intel_engine_cs *engine)
1222 I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) | 1222 I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) |
1223 GEN8_LQSC_RO_PERF_DIS); 1223 GEN8_LQSC_RO_PERF_DIS);
1224 1224
1225 /* WaInsertDummyPushConstPs:kbl */ 1225 /* WaToEnableHwFixForPushConstHWBug:kbl */
1226 if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) 1226 if (IS_KBL_REVID(dev_priv, KBL_REVID_C0, REVID_FOREVER))
1227 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, 1227 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1228 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); 1228 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
1229 1229
diff --git a/drivers/gpu/drm/mediatek/Kconfig b/drivers/gpu/drm/mediatek/Kconfig
index 23ac8041c562..294de4549922 100644
--- a/drivers/gpu/drm/mediatek/Kconfig
+++ b/drivers/gpu/drm/mediatek/Kconfig
@@ -2,6 +2,9 @@ config DRM_MEDIATEK
2 tristate "DRM Support for Mediatek SoCs" 2 tristate "DRM Support for Mediatek SoCs"
3 depends on DRM 3 depends on DRM
4 depends on ARCH_MEDIATEK || (ARM && COMPILE_TEST) 4 depends on ARCH_MEDIATEK || (ARM && COMPILE_TEST)
5 depends on COMMON_CLK
6 depends on HAVE_ARM_SMCCC
7 depends on OF
5 select DRM_GEM_CMA_HELPER 8 select DRM_GEM_CMA_HELPER
6 select DRM_KMS_HELPER 9 select DRM_KMS_HELPER
7 select DRM_MIPI_DSI 10 select DRM_MIPI_DSI
diff --git a/drivers/gpu/drm/qxl/qxl_fb.c b/drivers/gpu/drm/qxl/qxl_fb.c
index df2657051afd..28c1423049c5 100644
--- a/drivers/gpu/drm/qxl/qxl_fb.c
+++ b/drivers/gpu/drm/qxl/qxl_fb.c
@@ -73,10 +73,12 @@ static void qxl_fb_image_init(struct qxl_fb_image *qxl_fb_image,
73 } 73 }
74} 74}
75 75
76#ifdef CONFIG_DRM_FBDEV_EMULATION
76static struct fb_deferred_io qxl_defio = { 77static struct fb_deferred_io qxl_defio = {
77 .delay = QXL_DIRTY_DELAY, 78 .delay = QXL_DIRTY_DELAY,
78 .deferred_io = drm_fb_helper_deferred_io, 79 .deferred_io = drm_fb_helper_deferred_io,
79}; 80};
81#endif
80 82
81static struct fb_ops qxlfb_ops = { 83static struct fb_ops qxlfb_ops = {
82 .owner = THIS_MODULE, 84 .owner = THIS_MODULE,
@@ -313,8 +315,10 @@ static int qxlfb_create(struct qxl_fbdev *qfbdev,
313 goto out_destroy_fbi; 315 goto out_destroy_fbi;
314 } 316 }
315 317
318#ifdef CONFIG_DRM_FBDEV_EMULATION
316 info->fbdefio = &qxl_defio; 319 info->fbdefio = &qxl_defio;
317 fb_deferred_io_init(info); 320 fb_deferred_io_init(info);
321#endif
318 322
319 qdev->fbdev_info = info; 323 qdev->fbdev_info = info;
320 qdev->fbdev_qfb = &qfbdev->qfb; 324 qdev->fbdev_qfb = &qfbdev->qfb;
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index a97abc8af657..1dcf39084555 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -627,7 +627,9 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc,
627 if (radeon_crtc->ss.refdiv) { 627 if (radeon_crtc->ss.refdiv) {
628 radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV; 628 radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV;
629 radeon_crtc->pll_reference_div = radeon_crtc->ss.refdiv; 629 radeon_crtc->pll_reference_div = radeon_crtc->ss.refdiv;
630 if (rdev->family >= CHIP_RV770) 630 if (ASIC_IS_AVIVO(rdev) &&
631 rdev->family != CHIP_RS780 &&
632 rdev->family != CHIP_RS880)
631 radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; 633 radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV;
632 } 634 }
633 } 635 }
diff --git a/drivers/gpu/drm/radeon/radeon_atpx_handler.c b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
index 6de342861202..ddef0d494084 100644
--- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c
+++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
@@ -198,16 +198,7 @@ static int radeon_atpx_validate(struct radeon_atpx *atpx)
198 atpx->is_hybrid = false; 198 atpx->is_hybrid = false;
199 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) { 199 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
200 printk("ATPX Hybrid Graphics\n"); 200 printk("ATPX Hybrid Graphics\n");
201#if 1
202 /* This is a temporary hack until the D3 cold support
203 * makes it upstream. The ATPX power_control method seems
204 * to still work on even if the system should be using
205 * the new standardized hybrid D3 cold ACPI interface.
206 */
207 atpx->functions.power_cntl = true;
208#else
209 atpx->functions.power_cntl = false; 201 atpx->functions.power_cntl = false;
210#endif
211 atpx->is_hybrid = true; 202 atpx->is_hybrid = true;
212 } 203 }
213 204
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 0c00e192c845..c2e0a1ccdfbc 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -263,8 +263,8 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
263 263
264 rdev = radeon_get_rdev(bo->bdev); 264 rdev = radeon_get_rdev(bo->bdev);
265 ridx = radeon_copy_ring_index(rdev); 265 ridx = radeon_copy_ring_index(rdev);
266 old_start = old_mem->start << PAGE_SHIFT; 266 old_start = (u64)old_mem->start << PAGE_SHIFT;
267 new_start = new_mem->start << PAGE_SHIFT; 267 new_start = (u64)new_mem->start << PAGE_SHIFT;
268 268
269 switch (old_mem->mem_type) { 269 switch (old_mem->mem_type) {
270 case TTM_PL_VRAM: 270 case TTM_PL_VRAM:
diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
index 3d228ad90e0f..3dea1216bafd 100644
--- a/drivers/gpu/drm/tegra/dsi.c
+++ b/drivers/gpu/drm/tegra/dsi.c
@@ -840,6 +840,21 @@ static const struct drm_encoder_funcs tegra_dsi_encoder_funcs = {
840 .destroy = tegra_output_encoder_destroy, 840 .destroy = tegra_output_encoder_destroy,
841}; 841};
842 842
843static void tegra_dsi_unprepare(struct tegra_dsi *dsi)
844{
845 int err;
846
847 if (dsi->slave)
848 tegra_dsi_unprepare(dsi->slave);
849
850 err = tegra_mipi_disable(dsi->mipi);
851 if (err < 0)
852 dev_err(dsi->dev, "failed to disable MIPI calibration: %d\n",
853 err);
854
855 pm_runtime_put(dsi->dev);
856}
857
843static void tegra_dsi_encoder_disable(struct drm_encoder *encoder) 858static void tegra_dsi_encoder_disable(struct drm_encoder *encoder)
844{ 859{
845 struct tegra_output *output = encoder_to_output(encoder); 860 struct tegra_output *output = encoder_to_output(encoder);
@@ -876,7 +891,26 @@ static void tegra_dsi_encoder_disable(struct drm_encoder *encoder)
876 891
877 tegra_dsi_disable(dsi); 892 tegra_dsi_disable(dsi);
878 893
879 pm_runtime_put(dsi->dev); 894 tegra_dsi_unprepare(dsi);
895}
896
897static void tegra_dsi_prepare(struct tegra_dsi *dsi)
898{
899 int err;
900
901 pm_runtime_get_sync(dsi->dev);
902
903 err = tegra_mipi_enable(dsi->mipi);
904 if (err < 0)
905 dev_err(dsi->dev, "failed to enable MIPI calibration: %d\n",
906 err);
907
908 err = tegra_dsi_pad_calibrate(dsi);
909 if (err < 0)
910 dev_err(dsi->dev, "MIPI calibration failed: %d\n", err);
911
912 if (dsi->slave)
913 tegra_dsi_prepare(dsi->slave);
880} 914}
881 915
882static void tegra_dsi_encoder_enable(struct drm_encoder *encoder) 916static void tegra_dsi_encoder_enable(struct drm_encoder *encoder)
@@ -887,13 +921,8 @@ static void tegra_dsi_encoder_enable(struct drm_encoder *encoder)
887 struct tegra_dsi *dsi = to_dsi(output); 921 struct tegra_dsi *dsi = to_dsi(output);
888 struct tegra_dsi_state *state; 922 struct tegra_dsi_state *state;
889 u32 value; 923 u32 value;
890 int err;
891
892 pm_runtime_get_sync(dsi->dev);
893 924
894 err = tegra_dsi_pad_calibrate(dsi); 925 tegra_dsi_prepare(dsi);
895 if (err < 0)
896 dev_err(dsi->dev, "MIPI calibration failed: %d\n", err);
897 926
898 state = tegra_dsi_get_state(dsi); 927 state = tegra_dsi_get_state(dsi);
899 928
diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
index d5df555aeba0..9688bfa92ccd 100644
--- a/drivers/gpu/drm/udl/udl_fb.c
+++ b/drivers/gpu/drm/udl/udl_fb.c
@@ -203,6 +203,7 @@ static int udl_fb_open(struct fb_info *info, int user)
203 203
204 ufbdev->fb_count++; 204 ufbdev->fb_count++;
205 205
206#ifdef CONFIG_DRM_FBDEV_EMULATION
206 if (fb_defio && (info->fbdefio == NULL)) { 207 if (fb_defio && (info->fbdefio == NULL)) {
207 /* enable defio at last moment if not disabled by client */ 208 /* enable defio at last moment if not disabled by client */
208 209
@@ -218,6 +219,7 @@ static int udl_fb_open(struct fb_info *info, int user)
218 info->fbdefio = fbdefio; 219 info->fbdefio = fbdefio;
219 fb_deferred_io_init(info); 220 fb_deferred_io_init(info);
220 } 221 }
222#endif
221 223
222 pr_notice("open /dev/fb%d user=%d fb_info=%p count=%d\n", 224 pr_notice("open /dev/fb%d user=%d fb_info=%p count=%d\n",
223 info->node, user, info, ufbdev->fb_count); 225 info->node, user, info, ufbdev->fb_count);
@@ -235,12 +237,14 @@ static int udl_fb_release(struct fb_info *info, int user)
235 237
236 ufbdev->fb_count--; 238 ufbdev->fb_count--;
237 239
240#ifdef CONFIG_DRM_FBDEV_EMULATION
238 if ((ufbdev->fb_count == 0) && (info->fbdefio)) { 241 if ((ufbdev->fb_count == 0) && (info->fbdefio)) {
239 fb_deferred_io_cleanup(info); 242 fb_deferred_io_cleanup(info);
240 kfree(info->fbdefio); 243 kfree(info->fbdefio);
241 info->fbdefio = NULL; 244 info->fbdefio = NULL;
242 info->fbops->fb_mmap = udl_fb_mmap; 245 info->fbops->fb_mmap = udl_fb_mmap;
243 } 246 }
247#endif
244 248
245 pr_warn("released /dev/fb%d user=%d count=%d\n", 249 pr_warn("released /dev/fb%d user=%d count=%d\n",
246 info->node, user, ufbdev->fb_count); 250 info->node, user, ufbdev->fb_count);
diff --git a/drivers/gpu/host1x/mipi.c b/drivers/gpu/host1x/mipi.c
index 52a6fd224127..e00809d996a2 100644
--- a/drivers/gpu/host1x/mipi.c
+++ b/drivers/gpu/host1x/mipi.c
@@ -242,20 +242,6 @@ struct tegra_mipi_device *tegra_mipi_request(struct device *device)
242 dev->pads = args.args[0]; 242 dev->pads = args.args[0];
243 dev->device = device; 243 dev->device = device;
244 244
245 mutex_lock(&dev->mipi->lock);
246
247 if (dev->mipi->usage_count++ == 0) {
248 err = tegra_mipi_power_up(dev->mipi);
249 if (err < 0) {
250 dev_err(dev->mipi->dev,
251 "failed to power up MIPI bricks: %d\n",
252 err);
253 return ERR_PTR(err);
254 }
255 }
256
257 mutex_unlock(&dev->mipi->lock);
258
259 return dev; 245 return dev;
260 246
261put: 247put:
@@ -270,29 +256,42 @@ EXPORT_SYMBOL(tegra_mipi_request);
270 256
271void tegra_mipi_free(struct tegra_mipi_device *device) 257void tegra_mipi_free(struct tegra_mipi_device *device)
272{ 258{
273 int err; 259 platform_device_put(device->pdev);
260 kfree(device);
261}
262EXPORT_SYMBOL(tegra_mipi_free);
274 263
275 mutex_lock(&device->mipi->lock); 264int tegra_mipi_enable(struct tegra_mipi_device *dev)
265{
266 int err = 0;
276 267
277 if (--device->mipi->usage_count == 0) { 268 mutex_lock(&dev->mipi->lock);
278 err = tegra_mipi_power_down(device->mipi);
279 if (err < 0) {
280 /*
281 * Not much that can be done here, so an error message
282 * will have to do.
283 */
284 dev_err(device->mipi->dev,
285 "failed to power down MIPI bricks: %d\n",
286 err);
287 }
288 }
289 269
290 mutex_unlock(&device->mipi->lock); 270 if (dev->mipi->usage_count++ == 0)
271 err = tegra_mipi_power_up(dev->mipi);
272
273 mutex_unlock(&dev->mipi->lock);
274
275 return err;
291 276
292 platform_device_put(device->pdev);
293 kfree(device);
294} 277}
295EXPORT_SYMBOL(tegra_mipi_free); 278EXPORT_SYMBOL(tegra_mipi_enable);
279
280int tegra_mipi_disable(struct tegra_mipi_device *dev)
281{
282 int err = 0;
283
284 mutex_lock(&dev->mipi->lock);
285
286 if (--dev->mipi->usage_count == 0)
287 err = tegra_mipi_power_down(dev->mipi);
288
289 mutex_unlock(&dev->mipi->lock);
290
291 return err;
292
293}
294EXPORT_SYMBOL(tegra_mipi_disable);
296 295
297static int tegra_mipi_wait(struct tegra_mipi *mipi) 296static int tegra_mipi_wait(struct tegra_mipi *mipi)
298{ 297{
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 730d84028260..d0203a115eff 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -491,7 +491,7 @@ struct it87_sio_data {
491struct it87_data { 491struct it87_data {
492 const struct attribute_group *groups[7]; 492 const struct attribute_group *groups[7];
493 enum chips type; 493 enum chips type;
494 u16 features; 494 u32 features;
495 u8 peci_mask; 495 u8 peci_mask;
496 u8 old_peci_mask; 496 u8 old_peci_mask;
497 497
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index f23372669f77..1bb97f658b47 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -38,6 +38,7 @@
38#define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */ 38#define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */
39#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */ 39#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */
40#define AUTOSUSPEND_TIMEOUT 2000 40#define AUTOSUSPEND_TIMEOUT 2000
41#define AT91_I2C_MAX_ALT_CMD_DATA_SIZE 256
41 42
42/* AT91 TWI register definitions */ 43/* AT91 TWI register definitions */
43#define AT91_TWI_CR 0x0000 /* Control Register */ 44#define AT91_TWI_CR 0x0000 /* Control Register */
@@ -141,6 +142,7 @@ struct at91_twi_dev {
141 unsigned twi_cwgr_reg; 142 unsigned twi_cwgr_reg;
142 struct at91_twi_pdata *pdata; 143 struct at91_twi_pdata *pdata;
143 bool use_dma; 144 bool use_dma;
145 bool use_alt_cmd;
144 bool recv_len_abort; 146 bool recv_len_abort;
145 u32 fifo_size; 147 u32 fifo_size;
146 struct at91_twi_dma dma; 148 struct at91_twi_dma dma;
@@ -269,7 +271,7 @@ static void at91_twi_write_next_byte(struct at91_twi_dev *dev)
269 271
270 /* send stop when last byte has been written */ 272 /* send stop when last byte has been written */
271 if (--dev->buf_len == 0) 273 if (--dev->buf_len == 0)
272 if (!dev->pdata->has_alt_cmd) 274 if (!dev->use_alt_cmd)
273 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); 275 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
274 276
275 dev_dbg(dev->dev, "wrote 0x%x, to go %d\n", *dev->buf, dev->buf_len); 277 dev_dbg(dev->dev, "wrote 0x%x, to go %d\n", *dev->buf, dev->buf_len);
@@ -292,7 +294,7 @@ static void at91_twi_write_data_dma_callback(void *data)
292 * we just have to enable TXCOMP one. 294 * we just have to enable TXCOMP one.
293 */ 295 */
294 at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP); 296 at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP);
295 if (!dev->pdata->has_alt_cmd) 297 if (!dev->use_alt_cmd)
296 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); 298 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
297} 299}
298 300
@@ -410,7 +412,7 @@ static void at91_twi_read_next_byte(struct at91_twi_dev *dev)
410 } 412 }
411 413
412 /* send stop if second but last byte has been read */ 414 /* send stop if second but last byte has been read */
413 if (!dev->pdata->has_alt_cmd && dev->buf_len == 1) 415 if (!dev->use_alt_cmd && dev->buf_len == 1)
414 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); 416 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
415 417
416 dev_dbg(dev->dev, "read 0x%x, to go %d\n", *dev->buf, dev->buf_len); 418 dev_dbg(dev->dev, "read 0x%x, to go %d\n", *dev->buf, dev->buf_len);
@@ -426,7 +428,7 @@ static void at91_twi_read_data_dma_callback(void *data)
426 dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg[0]), 428 dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg[0]),
427 dev->buf_len, DMA_FROM_DEVICE); 429 dev->buf_len, DMA_FROM_DEVICE);
428 430
429 if (!dev->pdata->has_alt_cmd) { 431 if (!dev->use_alt_cmd) {
430 /* The last two bytes have to be read without using dma */ 432 /* The last two bytes have to be read without using dma */
431 dev->buf += dev->buf_len - 2; 433 dev->buf += dev->buf_len - 2;
432 dev->buf_len = 2; 434 dev->buf_len = 2;
@@ -443,7 +445,7 @@ static void at91_twi_read_data_dma(struct at91_twi_dev *dev)
443 struct dma_chan *chan_rx = dma->chan_rx; 445 struct dma_chan *chan_rx = dma->chan_rx;
444 size_t buf_len; 446 size_t buf_len;
445 447
446 buf_len = (dev->pdata->has_alt_cmd) ? dev->buf_len : dev->buf_len - 2; 448 buf_len = (dev->use_alt_cmd) ? dev->buf_len : dev->buf_len - 2;
447 dma->direction = DMA_FROM_DEVICE; 449 dma->direction = DMA_FROM_DEVICE;
448 450
449 /* Keep in mind that we won't use dma to read the last two bytes */ 451 /* Keep in mind that we won't use dma to read the last two bytes */
@@ -651,7 +653,7 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
651 unsigned start_flags = AT91_TWI_START; 653 unsigned start_flags = AT91_TWI_START;
652 654
653 /* if only one byte is to be read, immediately stop transfer */ 655 /* if only one byte is to be read, immediately stop transfer */
654 if (!has_alt_cmd && dev->buf_len <= 1 && 656 if (!dev->use_alt_cmd && dev->buf_len <= 1 &&
655 !(dev->msg->flags & I2C_M_RECV_LEN)) 657 !(dev->msg->flags & I2C_M_RECV_LEN))
656 start_flags |= AT91_TWI_STOP; 658 start_flags |= AT91_TWI_STOP;
657 at91_twi_write(dev, AT91_TWI_CR, start_flags); 659 at91_twi_write(dev, AT91_TWI_CR, start_flags);
@@ -745,7 +747,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
745 int ret; 747 int ret;
746 unsigned int_addr_flag = 0; 748 unsigned int_addr_flag = 0;
747 struct i2c_msg *m_start = msg; 749 struct i2c_msg *m_start = msg;
748 bool is_read, use_alt_cmd = false; 750 bool is_read;
749 751
750 dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num); 752 dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num);
751 753
@@ -768,14 +770,16 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
768 at91_twi_write(dev, AT91_TWI_IADR, internal_address); 770 at91_twi_write(dev, AT91_TWI_IADR, internal_address);
769 } 771 }
770 772
773 dev->use_alt_cmd = false;
771 is_read = (m_start->flags & I2C_M_RD); 774 is_read = (m_start->flags & I2C_M_RD);
772 if (dev->pdata->has_alt_cmd) { 775 if (dev->pdata->has_alt_cmd) {
773 if (m_start->len > 0) { 776 if (m_start->len > 0 &&
777 m_start->len < AT91_I2C_MAX_ALT_CMD_DATA_SIZE) {
774 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMEN); 778 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMEN);
775 at91_twi_write(dev, AT91_TWI_ACR, 779 at91_twi_write(dev, AT91_TWI_ACR,
776 AT91_TWI_ACR_DATAL(m_start->len) | 780 AT91_TWI_ACR_DATAL(m_start->len) |
777 ((is_read) ? AT91_TWI_ACR_DIR : 0)); 781 ((is_read) ? AT91_TWI_ACR_DIR : 0));
778 use_alt_cmd = true; 782 dev->use_alt_cmd = true;
779 } else { 783 } else {
780 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMDIS); 784 at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMDIS);
781 } 785 }
@@ -784,7 +788,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
784 at91_twi_write(dev, AT91_TWI_MMR, 788 at91_twi_write(dev, AT91_TWI_MMR,
785 (m_start->addr << 16) | 789 (m_start->addr << 16) |
786 int_addr_flag | 790 int_addr_flag |
787 ((!use_alt_cmd && is_read) ? AT91_TWI_MREAD : 0)); 791 ((!dev->use_alt_cmd && is_read) ? AT91_TWI_MREAD : 0));
788 792
789 dev->buf_len = m_start->len; 793 dev->buf_len = m_start->len;
790 dev->buf = m_start->buf; 794 dev->buf = m_start->buf;
diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
index 19c843828fe2..95f7cac76f89 100644
--- a/drivers/i2c/busses/i2c-bcm-iproc.c
+++ b/drivers/i2c/busses/i2c-bcm-iproc.c
@@ -158,7 +158,7 @@ static irqreturn_t bcm_iproc_i2c_isr(int irq, void *data)
158 158
159 if (status & BIT(IS_M_START_BUSY_SHIFT)) { 159 if (status & BIT(IS_M_START_BUSY_SHIFT)) {
160 iproc_i2c->xfer_is_done = 1; 160 iproc_i2c->xfer_is_done = 1;
161 complete_all(&iproc_i2c->done); 161 complete(&iproc_i2c->done);
162 } 162 }
163 163
164 writel(status, iproc_i2c->base + IS_OFFSET); 164 writel(status, iproc_i2c->base + IS_OFFSET);
diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c
index ac9f47679c3a..f98743277e3c 100644
--- a/drivers/i2c/busses/i2c-bcm-kona.c
+++ b/drivers/i2c/busses/i2c-bcm-kona.c
@@ -229,7 +229,7 @@ static irqreturn_t bcm_kona_i2c_isr(int irq, void *devid)
229 dev->base + TXFCR_OFFSET); 229 dev->base + TXFCR_OFFSET);
230 230
231 writel(status & ~ISR_RESERVED_MASK, dev->base + ISR_OFFSET); 231 writel(status & ~ISR_RESERVED_MASK, dev->base + ISR_OFFSET);
232 complete_all(&dev->done); 232 complete(&dev->done);
233 233
234 return IRQ_HANDLED; 234 return IRQ_HANDLED;
235} 235}
diff --git a/drivers/i2c/busses/i2c-brcmstb.c b/drivers/i2c/busses/i2c-brcmstb.c
index 3f5a4d71d3bf..385b57bfcb38 100644
--- a/drivers/i2c/busses/i2c-brcmstb.c
+++ b/drivers/i2c/busses/i2c-brcmstb.c
@@ -228,7 +228,7 @@ static irqreturn_t brcmstb_i2c_isr(int irq, void *devid)
228 return IRQ_NONE; 228 return IRQ_NONE;
229 229
230 brcmstb_i2c_enable_disable_irq(dev, INT_DISABLE); 230 brcmstb_i2c_enable_disable_irq(dev, INT_DISABLE);
231 complete_all(&dev->done); 231 complete(&dev->done);
232 232
233 dev_dbg(dev->device, "isr handled"); 233 dev_dbg(dev->device, "isr handled");
234 return IRQ_HANDLED; 234 return IRQ_HANDLED;
diff --git a/drivers/i2c/busses/i2c-cros-ec-tunnel.c b/drivers/i2c/busses/i2c-cros-ec-tunnel.c
index a0d95ff682ae..2d5ff86398d0 100644
--- a/drivers/i2c/busses/i2c-cros-ec-tunnel.c
+++ b/drivers/i2c/busses/i2c-cros-ec-tunnel.c
@@ -215,7 +215,7 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[],
215 msg->outsize = request_len; 215 msg->outsize = request_len;
216 msg->insize = response_len; 216 msg->insize = response_len;
217 217
218 result = cros_ec_cmd_xfer(bus->ec, msg); 218 result = cros_ec_cmd_xfer_status(bus->ec, msg);
219 if (result < 0) { 219 if (result < 0) {
220 dev_err(dev, "Error transferring EC i2c message %d\n", result); 220 dev_err(dev, "Error transferring EC i2c message %d\n", result);
221 goto exit; 221 goto exit;
diff --git a/drivers/i2c/busses/i2c-meson.c b/drivers/i2c/busses/i2c-meson.c
index 71d3929adf54..76e28980904f 100644
--- a/drivers/i2c/busses/i2c-meson.c
+++ b/drivers/i2c/busses/i2c-meson.c
@@ -211,7 +211,7 @@ static void meson_i2c_stop(struct meson_i2c *i2c)
211 meson_i2c_add_token(i2c, TOKEN_STOP); 211 meson_i2c_add_token(i2c, TOKEN_STOP);
212 } else { 212 } else {
213 i2c->state = STATE_IDLE; 213 i2c->state = STATE_IDLE;
214 complete_all(&i2c->done); 214 complete(&i2c->done);
215 } 215 }
216} 216}
217 217
@@ -238,7 +238,7 @@ static irqreturn_t meson_i2c_irq(int irqno, void *dev_id)
238 dev_dbg(i2c->dev, "error bit set\n"); 238 dev_dbg(i2c->dev, "error bit set\n");
239 i2c->error = -ENXIO; 239 i2c->error = -ENXIO;
240 i2c->state = STATE_IDLE; 240 i2c->state = STATE_IDLE;
241 complete_all(&i2c->done); 241 complete(&i2c->done);
242 goto out; 242 goto out;
243 } 243 }
244 244
@@ -269,7 +269,7 @@ static irqreturn_t meson_i2c_irq(int irqno, void *dev_id)
269 break; 269 break;
270 case STATE_STOP: 270 case STATE_STOP:
271 i2c->state = STATE_IDLE; 271 i2c->state = STATE_IDLE;
272 complete_all(&i2c->done); 272 complete(&i2c->done);
273 break; 273 break;
274 case STATE_IDLE: 274 case STATE_IDLE:
275 break; 275 break;
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index dfa7a4b4a91d..ac88a524143e 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -379,6 +379,7 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
379 if (!clock_frequency_present) { 379 if (!clock_frequency_present) {
380 dev_err(&pdev->dev, 380 dev_err(&pdev->dev,
381 "Missing required parameter 'opencores,ip-clock-frequency'\n"); 381 "Missing required parameter 'opencores,ip-clock-frequency'\n");
382 clk_disable_unprepare(i2c->clk);
382 return -ENODEV; 383 return -ENODEV;
383 } 384 }
384 i2c->ip_clock_khz = clock_frequency / 1000; 385 i2c->ip_clock_khz = clock_frequency / 1000;
@@ -467,20 +468,21 @@ static int ocores_i2c_probe(struct platform_device *pdev)
467 default: 468 default:
468 dev_err(&pdev->dev, "Unsupported I/O width (%d)\n", 469 dev_err(&pdev->dev, "Unsupported I/O width (%d)\n",
469 i2c->reg_io_width); 470 i2c->reg_io_width);
470 return -EINVAL; 471 ret = -EINVAL;
472 goto err_clk;
471 } 473 }
472 } 474 }
473 475
474 ret = ocores_init(&pdev->dev, i2c); 476 ret = ocores_init(&pdev->dev, i2c);
475 if (ret) 477 if (ret)
476 return ret; 478 goto err_clk;
477 479
478 init_waitqueue_head(&i2c->wait); 480 init_waitqueue_head(&i2c->wait);
479 ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0, 481 ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0,
480 pdev->name, i2c); 482 pdev->name, i2c);
481 if (ret) { 483 if (ret) {
482 dev_err(&pdev->dev, "Cannot claim IRQ\n"); 484 dev_err(&pdev->dev, "Cannot claim IRQ\n");
483 return ret; 485 goto err_clk;
484 } 486 }
485 487
486 /* hook up driver to tree */ 488 /* hook up driver to tree */
@@ -494,7 +496,7 @@ static int ocores_i2c_probe(struct platform_device *pdev)
494 ret = i2c_add_adapter(&i2c->adap); 496 ret = i2c_add_adapter(&i2c->adap);
495 if (ret) { 497 if (ret) {
496 dev_err(&pdev->dev, "Failed to add adapter\n"); 498 dev_err(&pdev->dev, "Failed to add adapter\n");
497 return ret; 499 goto err_clk;
498 } 500 }
499 501
500 /* add in known devices to the bus */ 502 /* add in known devices to the bus */
@@ -504,6 +506,10 @@ static int ocores_i2c_probe(struct platform_device *pdev)
504 } 506 }
505 507
506 return 0; 508 return 0;
509
510err_clk:
511 clk_disable_unprepare(i2c->clk);
512 return ret;
507} 513}
508 514
509static int ocores_i2c_remove(struct platform_device *pdev) 515static int ocores_i2c_remove(struct platform_device *pdev)
diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c
index 8de073aed001..215ac87f606d 100644
--- a/drivers/i2c/muxes/i2c-demux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c
@@ -68,7 +68,7 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne
68 adap = of_find_i2c_adapter_by_node(priv->chan[new_chan].parent_np); 68 adap = of_find_i2c_adapter_by_node(priv->chan[new_chan].parent_np);
69 if (!adap) { 69 if (!adap) {
70 ret = -ENODEV; 70 ret = -ENODEV;
71 goto err; 71 goto err_with_revert;
72 } 72 }
73 73
74 p = devm_pinctrl_get_select(adap->dev.parent, priv->bus_name); 74 p = devm_pinctrl_get_select(adap->dev.parent, priv->bus_name);
@@ -103,6 +103,8 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne
103 103
104 err_with_put: 104 err_with_put:
105 i2c_put_adapter(adap); 105 i2c_put_adapter(adap);
106 err_with_revert:
107 of_changeset_revert(&priv->chan[new_chan].chgset);
106 err: 108 err:
107 dev_err(priv->dev, "failed to setup demux-adapter %d (%d)\n", new_chan, ret); 109 dev_err(priv->dev, "failed to setup demux-adapter %d (%d)\n", new_chan, ret);
108 return ret; 110 return ret;
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index e6dfa1bd3def..5f65a78b27c9 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -2462,18 +2462,24 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
2462 2462
2463 if (addr->dev_addr.bound_dev_if) { 2463 if (addr->dev_addr.bound_dev_if) {
2464 ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if); 2464 ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if);
2465 if (!ndev) 2465 if (!ndev) {
2466 return -ENODEV; 2466 ret = -ENODEV;
2467 goto err2;
2468 }
2467 2469
2468 if (ndev->flags & IFF_LOOPBACK) { 2470 if (ndev->flags & IFF_LOOPBACK) {
2469 dev_put(ndev); 2471 dev_put(ndev);
2470 if (!id_priv->id.device->get_netdev) 2472 if (!id_priv->id.device->get_netdev) {
2471 return -EOPNOTSUPP; 2473 ret = -EOPNOTSUPP;
2474 goto err2;
2475 }
2472 2476
2473 ndev = id_priv->id.device->get_netdev(id_priv->id.device, 2477 ndev = id_priv->id.device->get_netdev(id_priv->id.device,
2474 id_priv->id.port_num); 2478 id_priv->id.port_num);
2475 if (!ndev) 2479 if (!ndev) {
2476 return -ENODEV; 2480 ret = -ENODEV;
2481 goto err2;
2482 }
2477 } 2483 }
2478 2484
2479 route->path_rec->net = &init_net; 2485 route->path_rec->net = &init_net;
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 3aca7f6171b4..b6a953aed7e8 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1827,8 +1827,12 @@ static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1827 (ep->mpa_pkt + sizeof(*mpa)); 1827 (ep->mpa_pkt + sizeof(*mpa));
1828 ep->ird = ntohs(mpa_v2_params->ird) & 1828 ep->ird = ntohs(mpa_v2_params->ird) &
1829 MPA_V2_IRD_ORD_MASK; 1829 MPA_V2_IRD_ORD_MASK;
1830 ep->ird = min_t(u32, ep->ird,
1831 cur_max_read_depth(ep->com.dev));
1830 ep->ord = ntohs(mpa_v2_params->ord) & 1832 ep->ord = ntohs(mpa_v2_params->ord) &
1831 MPA_V2_IRD_ORD_MASK; 1833 MPA_V2_IRD_ORD_MASK;
1834 ep->ord = min_t(u32, ep->ord,
1835 cur_max_read_depth(ep->com.dev));
1832 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird, 1836 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1833 ep->ord); 1837 ep->ord);
1834 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL) 1838 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
@@ -3136,7 +3140,7 @@ int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3136 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) { 3140 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3137 if (conn_param->ord > ep->ird) { 3141 if (conn_param->ord > ep->ird) {
3138 if (RELAXED_IRD_NEGOTIATION) { 3142 if (RELAXED_IRD_NEGOTIATION) {
3139 ep->ord = ep->ird; 3143 conn_param->ord = ep->ird;
3140 } else { 3144 } else {
3141 ep->ird = conn_param->ird; 3145 ep->ird = conn_param->ird;
3142 ep->ord = conn_param->ord; 3146 ep->ord = conn_param->ord;
diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c
index 812ab7278b8e..ac926c942fee 100644
--- a/drivers/infiniband/hw/cxgb4/cq.c
+++ b/drivers/infiniband/hw/cxgb4/cq.c
@@ -1016,15 +1016,15 @@ int c4iw_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata)
1016int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) 1016int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
1017{ 1017{
1018 struct c4iw_cq *chp; 1018 struct c4iw_cq *chp;
1019 int ret; 1019 int ret = 0;
1020 unsigned long flag; 1020 unsigned long flag;
1021 1021
1022 chp = to_c4iw_cq(ibcq); 1022 chp = to_c4iw_cq(ibcq);
1023 spin_lock_irqsave(&chp->lock, flag); 1023 spin_lock_irqsave(&chp->lock, flag);
1024 ret = t4_arm_cq(&chp->cq, 1024 t4_arm_cq(&chp->cq,
1025 (flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED); 1025 (flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED);
1026 if (flags & IB_CQ_REPORT_MISSED_EVENTS)
1027 ret = t4_cq_notempty(&chp->cq);
1026 spin_unlock_irqrestore(&chp->lock, flag); 1028 spin_unlock_irqrestore(&chp->lock, flag);
1027 if (ret && !(flags & IB_CQ_REPORT_MISSED_EVENTS))
1028 ret = 0;
1029 return ret; 1029 return ret;
1030} 1030}
diff --git a/drivers/infiniband/hw/cxgb4/t4.h b/drivers/infiniband/hw/cxgb4/t4.h
index 6126bbe36095..02173f4315fa 100644
--- a/drivers/infiniband/hw/cxgb4/t4.h
+++ b/drivers/infiniband/hw/cxgb4/t4.h
@@ -634,6 +634,11 @@ static inline int t4_valid_cqe(struct t4_cq *cq, struct t4_cqe *cqe)
634 return (CQE_GENBIT(cqe) == cq->gen); 634 return (CQE_GENBIT(cqe) == cq->gen);
635} 635}
636 636
637static inline int t4_cq_notempty(struct t4_cq *cq)
638{
639 return cq->sw_in_use || t4_valid_cqe(cq, &cq->queue[cq->cidx]);
640}
641
637static inline int t4_next_hw_cqe(struct t4_cq *cq, struct t4_cqe **cqe) 642static inline int t4_next_hw_cqe(struct t4_cq *cq, struct t4_cqe **cqe)
638{ 643{
639 int ret; 644 int ret;
diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/hfi1/affinity.c
index 79575ee873f2..0566393e5aba 100644
--- a/drivers/infiniband/hw/hfi1/affinity.c
+++ b/drivers/infiniband/hw/hfi1/affinity.c
@@ -47,7 +47,6 @@
47#include <linux/topology.h> 47#include <linux/topology.h>
48#include <linux/cpumask.h> 48#include <linux/cpumask.h>
49#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/cpumask.h>
51 50
52#include "hfi.h" 51#include "hfi.h"
53#include "affinity.h" 52#include "affinity.h"
@@ -682,7 +681,7 @@ int hfi1_set_sdma_affinity(struct hfi1_devdata *dd, const char *buf,
682 size_t count) 681 size_t count)
683{ 682{
684 struct hfi1_affinity_node *entry; 683 struct hfi1_affinity_node *entry;
685 struct cpumask mask; 684 cpumask_var_t mask;
686 int ret, i; 685 int ret, i;
687 686
688 spin_lock(&node_affinity.lock); 687 spin_lock(&node_affinity.lock);
@@ -692,19 +691,24 @@ int hfi1_set_sdma_affinity(struct hfi1_devdata *dd, const char *buf,
692 if (!entry) 691 if (!entry)
693 return -EINVAL; 692 return -EINVAL;
694 693
695 ret = cpulist_parse(buf, &mask); 694 ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
695 if (!ret)
696 return -ENOMEM;
697
698 ret = cpulist_parse(buf, mask);
696 if (ret) 699 if (ret)
697 return ret; 700 goto out;
698 701
699 if (!cpumask_subset(&mask, cpu_online_mask) || cpumask_empty(&mask)) { 702 if (!cpumask_subset(mask, cpu_online_mask) || cpumask_empty(mask)) {
700 dd_dev_warn(dd, "Invalid CPU mask\n"); 703 dd_dev_warn(dd, "Invalid CPU mask\n");
701 return -EINVAL; 704 ret = -EINVAL;
705 goto out;
702 } 706 }
703 707
704 mutex_lock(&sdma_affinity_mutex); 708 mutex_lock(&sdma_affinity_mutex);
705 /* reset the SDMA interrupt affinity details */ 709 /* reset the SDMA interrupt affinity details */
706 init_cpu_mask_set(&entry->def_intr); 710 init_cpu_mask_set(&entry->def_intr);
707 cpumask_copy(&entry->def_intr.mask, &mask); 711 cpumask_copy(&entry->def_intr.mask, mask);
708 /* 712 /*
709 * Reassign the affinity for each SDMA interrupt. 713 * Reassign the affinity for each SDMA interrupt.
710 */ 714 */
@@ -720,8 +724,9 @@ int hfi1_set_sdma_affinity(struct hfi1_devdata *dd, const char *buf,
720 if (ret) 724 if (ret)
721 break; 725 break;
722 } 726 }
723
724 mutex_unlock(&sdma_affinity_mutex); 727 mutex_unlock(&sdma_affinity_mutex);
728out:
729 free_cpumask_var(mask);
725 return ret ? ret : strnlen(buf, PAGE_SIZE); 730 return ret ? ret : strnlen(buf, PAGE_SIZE);
726} 731}
727 732
diff --git a/drivers/infiniband/hw/hfi1/debugfs.c b/drivers/infiniband/hw/hfi1/debugfs.c
index dbab9d9cc288..a49cc88f08a2 100644
--- a/drivers/infiniband/hw/hfi1/debugfs.c
+++ b/drivers/infiniband/hw/hfi1/debugfs.c
@@ -223,28 +223,32 @@ DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
223DEBUGFS_FILE_OPS(ctx_stats); 223DEBUGFS_FILE_OPS(ctx_stats);
224 224
225static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos) 225static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
226__acquires(RCU) 226 __acquires(RCU)
227{ 227{
228 struct qp_iter *iter; 228 struct qp_iter *iter;
229 loff_t n = *pos; 229 loff_t n = *pos;
230 230
231 rcu_read_lock();
232 iter = qp_iter_init(s->private); 231 iter = qp_iter_init(s->private);
232
233 /* stop calls rcu_read_unlock */
234 rcu_read_lock();
235
233 if (!iter) 236 if (!iter)
234 return NULL; 237 return NULL;
235 238
236 while (n--) { 239 do {
237 if (qp_iter_next(iter)) { 240 if (qp_iter_next(iter)) {
238 kfree(iter); 241 kfree(iter);
239 return NULL; 242 return NULL;
240 } 243 }
241 } 244 } while (n--);
242 245
243 return iter; 246 return iter;
244} 247}
245 248
246static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr, 249static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
247 loff_t *pos) 250 loff_t *pos)
251 __must_hold(RCU)
248{ 252{
249 struct qp_iter *iter = iter_ptr; 253 struct qp_iter *iter = iter_ptr;
250 254
@@ -259,7 +263,7 @@ static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
259} 263}
260 264
261static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr) 265static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
262__releases(RCU) 266 __releases(RCU)
263{ 267{
264 rcu_read_unlock(); 268 rcu_read_unlock();
265} 269}
diff --git a/drivers/infiniband/hw/hfi1/driver.c b/drivers/infiniband/hw/hfi1/driver.c
index 8246dc7d0573..303f10555729 100644
--- a/drivers/infiniband/hw/hfi1/driver.c
+++ b/drivers/infiniband/hw/hfi1/driver.c
@@ -888,14 +888,15 @@ void set_all_slowpath(struct hfi1_devdata *dd)
888} 888}
889 889
890static inline int set_armed_to_active(struct hfi1_ctxtdata *rcd, 890static inline int set_armed_to_active(struct hfi1_ctxtdata *rcd,
891 struct hfi1_packet packet, 891 struct hfi1_packet *packet,
892 struct hfi1_devdata *dd) 892 struct hfi1_devdata *dd)
893{ 893{
894 struct work_struct *lsaw = &rcd->ppd->linkstate_active_work; 894 struct work_struct *lsaw = &rcd->ppd->linkstate_active_work;
895 struct hfi1_message_header *hdr = hfi1_get_msgheader(packet.rcd->dd, 895 struct hfi1_message_header *hdr = hfi1_get_msgheader(packet->rcd->dd,
896 packet.rhf_addr); 896 packet->rhf_addr);
897 u8 etype = rhf_rcv_type(packet->rhf);
897 898
898 if (hdr2sc(hdr, packet.rhf) != 0xf) { 899 if (etype == RHF_RCV_TYPE_IB && hdr2sc(hdr, packet->rhf) != 0xf) {
899 int hwstate = read_logical_state(dd); 900 int hwstate = read_logical_state(dd);
900 901
901 if (hwstate != LSTATE_ACTIVE) { 902 if (hwstate != LSTATE_ACTIVE) {
@@ -979,7 +980,7 @@ int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
979 /* Auto activate link on non-SC15 packet receive */ 980 /* Auto activate link on non-SC15 packet receive */
980 if (unlikely(rcd->ppd->host_link_state == 981 if (unlikely(rcd->ppd->host_link_state ==
981 HLS_UP_ARMED) && 982 HLS_UP_ARMED) &&
982 set_armed_to_active(rcd, packet, dd)) 983 set_armed_to_active(rcd, &packet, dd))
983 goto bail; 984 goto bail;
984 last = process_rcv_packet(&packet, thread); 985 last = process_rcv_packet(&packet, thread);
985 } 986 }
diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
index 1ecbec192358..7e03ccd2554d 100644
--- a/drivers/infiniband/hw/hfi1/file_ops.c
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
@@ -183,6 +183,7 @@ static int hfi1_file_open(struct inode *inode, struct file *fp)
183 if (fd) { 183 if (fd) {
184 fd->rec_cpu_num = -1; /* no cpu affinity by default */ 184 fd->rec_cpu_num = -1; /* no cpu affinity by default */
185 fd->mm = current->mm; 185 fd->mm = current->mm;
186 atomic_inc(&fd->mm->mm_count);
186 } 187 }
187 188
188 fp->private_data = fd; 189 fp->private_data = fd;
@@ -222,7 +223,7 @@ static long hfi1_file_ioctl(struct file *fp, unsigned int cmd,
222 ret = assign_ctxt(fp, &uinfo); 223 ret = assign_ctxt(fp, &uinfo);
223 if (ret < 0) 224 if (ret < 0)
224 return ret; 225 return ret;
225 setup_ctxt(fp); 226 ret = setup_ctxt(fp);
226 if (ret) 227 if (ret)
227 return ret; 228 return ret;
228 ret = user_init(fp); 229 ret = user_init(fp);
@@ -779,6 +780,7 @@ static int hfi1_file_close(struct inode *inode, struct file *fp)
779 mutex_unlock(&hfi1_mutex); 780 mutex_unlock(&hfi1_mutex);
780 hfi1_free_ctxtdata(dd, uctxt); 781 hfi1_free_ctxtdata(dd, uctxt);
781done: 782done:
783 mmdrop(fdata->mm);
782 kobject_put(&dd->kobj); 784 kobject_put(&dd->kobj);
783 kfree(fdata); 785 kfree(fdata);
784 return 0; 786 return 0;
diff --git a/drivers/infiniband/hw/hfi1/hfi.h b/drivers/infiniband/hw/hfi1/hfi.h
index 1000e0fd96d9..a021e660d482 100644
--- a/drivers/infiniband/hw/hfi1/hfi.h
+++ b/drivers/infiniband/hw/hfi1/hfi.h
@@ -1272,9 +1272,26 @@ static inline int hdr2sc(struct hfi1_message_header *hdr, u64 rhf)
1272 ((!!(rhf_dc_info(rhf))) << 4); 1272 ((!!(rhf_dc_info(rhf))) << 4);
1273} 1273}
1274 1274
1275#define HFI1_JKEY_WIDTH 16
1276#define HFI1_JKEY_MASK (BIT(16) - 1)
1277#define HFI1_ADMIN_JKEY_RANGE 32
1278
1279/*
1280 * J_KEYs are split and allocated in the following groups:
1281 * 0 - 31 - users with administrator privileges
1282 * 32 - 63 - kernel protocols using KDETH packets
1283 * 64 - 65535 - all other users using KDETH packets
1284 */
1275static inline u16 generate_jkey(kuid_t uid) 1285static inline u16 generate_jkey(kuid_t uid)
1276{ 1286{
1277 return from_kuid(current_user_ns(), uid) & 0xffff; 1287 u16 jkey = from_kuid(current_user_ns(), uid) & HFI1_JKEY_MASK;
1288
1289 if (capable(CAP_SYS_ADMIN))
1290 jkey &= HFI1_ADMIN_JKEY_RANGE - 1;
1291 else if (jkey < 64)
1292 jkey |= BIT(HFI1_JKEY_WIDTH - 1);
1293
1294 return jkey;
1278} 1295}
1279 1296
1280/* 1297/*
@@ -1656,7 +1673,6 @@ struct cc_state *get_cc_state_protected(struct hfi1_pportdata *ppd)
1656struct hfi1_devdata *hfi1_init_dd(struct pci_dev *, 1673struct hfi1_devdata *hfi1_init_dd(struct pci_dev *,
1657 const struct pci_device_id *); 1674 const struct pci_device_id *);
1658void hfi1_free_devdata(struct hfi1_devdata *); 1675void hfi1_free_devdata(struct hfi1_devdata *);
1659void cc_state_reclaim(struct rcu_head *rcu);
1660struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra); 1676struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra);
1661 1677
1662/* LED beaconing functions */ 1678/* LED beaconing functions */
diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c
index a358d23ecd54..b7935451093c 100644
--- a/drivers/infiniband/hw/hfi1/init.c
+++ b/drivers/infiniband/hw/hfi1/init.c
@@ -1333,7 +1333,7 @@ static void cleanup_device_data(struct hfi1_devdata *dd)
1333 spin_unlock(&ppd->cc_state_lock); 1333 spin_unlock(&ppd->cc_state_lock);
1334 1334
1335 if (cc_state) 1335 if (cc_state)
1336 call_rcu(&cc_state->rcu, cc_state_reclaim); 1336 kfree_rcu(cc_state, rcu);
1337 } 1337 }
1338 1338
1339 free_credit_return(dd); 1339 free_credit_return(dd);
diff --git a/drivers/infiniband/hw/hfi1/mad.c b/drivers/infiniband/hw/hfi1/mad.c
index 1263abe01999..39e42c373a01 100644
--- a/drivers/infiniband/hw/hfi1/mad.c
+++ b/drivers/infiniband/hw/hfi1/mad.c
@@ -1819,6 +1819,11 @@ static int __subn_get_opa_cable_info(struct opa_smp *smp, u32 am, u8 *data,
1819 u32 len = OPA_AM_CI_LEN(am) + 1; 1819 u32 len = OPA_AM_CI_LEN(am) + 1;
1820 int ret; 1820 int ret;
1821 1821
1822 if (dd->pport->port_type != PORT_TYPE_QSFP) {
1823 smp->status |= IB_SMP_INVALID_FIELD;
1824 return reply((struct ib_mad_hdr *)smp);
1825 }
1826
1822#define __CI_PAGE_SIZE BIT(7) /* 128 bytes */ 1827#define __CI_PAGE_SIZE BIT(7) /* 128 bytes */
1823#define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1) 1828#define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1)
1824#define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK) 1829#define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK)
@@ -3398,7 +3403,7 @@ static void apply_cc_state(struct hfi1_pportdata *ppd)
3398 3403
3399 spin_unlock(&ppd->cc_state_lock); 3404 spin_unlock(&ppd->cc_state_lock);
3400 3405
3401 call_rcu(&old_cc_state->rcu, cc_state_reclaim); 3406 kfree_rcu(old_cc_state, rcu);
3402} 3407}
3403 3408
3404static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data, 3409static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data,
@@ -3553,13 +3558,6 @@ static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
3553 return reply((struct ib_mad_hdr *)smp); 3558 return reply((struct ib_mad_hdr *)smp);
3554} 3559}
3555 3560
3556void cc_state_reclaim(struct rcu_head *rcu)
3557{
3558 struct cc_state *cc_state = container_of(rcu, struct cc_state, rcu);
3559
3560 kfree(cc_state);
3561}
3562
3563static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data, 3561static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
3564 struct ib_device *ibdev, u8 port, 3562 struct ib_device *ibdev, u8 port,
3565 u32 *resp_len) 3563 u32 *resp_len)
diff --git a/drivers/infiniband/hw/hfi1/qp.c b/drivers/infiniband/hw/hfi1/qp.c
index a5aa3517e7d5..4e4d8317c281 100644
--- a/drivers/infiniband/hw/hfi1/qp.c
+++ b/drivers/infiniband/hw/hfi1/qp.c
@@ -656,10 +656,6 @@ struct qp_iter *qp_iter_init(struct hfi1_ibdev *dev)
656 656
657 iter->dev = dev; 657 iter->dev = dev;
658 iter->specials = dev->rdi.ibdev.phys_port_cnt * 2; 658 iter->specials = dev->rdi.ibdev.phys_port_cnt * 2;
659 if (qp_iter_next(iter)) {
660 kfree(iter);
661 return NULL;
662 }
663 659
664 return iter; 660 return iter;
665} 661}
diff --git a/drivers/infiniband/hw/hfi1/qsfp.c b/drivers/infiniband/hw/hfi1/qsfp.c
index a207717ade2a..4e95ad810847 100644
--- a/drivers/infiniband/hw/hfi1/qsfp.c
+++ b/drivers/infiniband/hw/hfi1/qsfp.c
@@ -706,8 +706,8 @@ int get_cable_info(struct hfi1_devdata *dd, u32 port_num, u32 addr, u32 len,
706 u8 *data) 706 u8 *data)
707{ 707{
708 struct hfi1_pportdata *ppd; 708 struct hfi1_pportdata *ppd;
709 u32 excess_len = 0; 709 u32 excess_len = len;
710 int ret = 0; 710 int ret = 0, offset = 0;
711 711
712 if (port_num > dd->num_pports || port_num < 1) { 712 if (port_num > dd->num_pports || port_num < 1) {
713 dd_dev_info(dd, "%s: Invalid port number %d\n", 713 dd_dev_info(dd, "%s: Invalid port number %d\n",
@@ -740,6 +740,34 @@ int get_cable_info(struct hfi1_devdata *dd, u32 port_num, u32 addr, u32 len,
740 } 740 }
741 741
742 memcpy(data, &ppd->qsfp_info.cache[addr], len); 742 memcpy(data, &ppd->qsfp_info.cache[addr], len);
743
744 if (addr <= QSFP_MONITOR_VAL_END &&
745 (addr + len) >= QSFP_MONITOR_VAL_START) {
746 /* Overlap with the dynamic channel monitor range */
747 if (addr < QSFP_MONITOR_VAL_START) {
748 if (addr + len <= QSFP_MONITOR_VAL_END)
749 len = addr + len - QSFP_MONITOR_VAL_START;
750 else
751 len = QSFP_MONITOR_RANGE;
752 offset = QSFP_MONITOR_VAL_START - addr;
753 addr = QSFP_MONITOR_VAL_START;
754 } else if (addr == QSFP_MONITOR_VAL_START) {
755 offset = 0;
756 if (addr + len > QSFP_MONITOR_VAL_END)
757 len = QSFP_MONITOR_RANGE;
758 } else {
759 offset = 0;
760 if (addr + len > QSFP_MONITOR_VAL_END)
761 len = QSFP_MONITOR_VAL_END - addr + 1;
762 }
763 /* Refresh the values of the dynamic monitors from the cable */
764 ret = one_qsfp_read(ppd, dd->hfi1_id, addr, data + offset, len);
765 if (ret != len) {
766 ret = -EAGAIN;
767 goto set_zeroes;
768 }
769 }
770
743 return 0; 771 return 0;
744 772
745set_zeroes: 773set_zeroes:
diff --git a/drivers/infiniband/hw/hfi1/qsfp.h b/drivers/infiniband/hw/hfi1/qsfp.h
index 69275ebd9597..36cf52359848 100644
--- a/drivers/infiniband/hw/hfi1/qsfp.h
+++ b/drivers/infiniband/hw/hfi1/qsfp.h
@@ -74,6 +74,9 @@
74/* Defined fields that Intel requires of qualified cables */ 74/* Defined fields that Intel requires of qualified cables */
75/* Byte 0 is Identifier, not checked */ 75/* Byte 0 is Identifier, not checked */
76/* Byte 1 is reserved "status MSB" */ 76/* Byte 1 is reserved "status MSB" */
77#define QSFP_MONITOR_VAL_START 22
78#define QSFP_MONITOR_VAL_END 81
79#define QSFP_MONITOR_RANGE (QSFP_MONITOR_VAL_END - QSFP_MONITOR_VAL_START + 1)
77#define QSFP_TX_CTRL_BYTE_OFFS 86 80#define QSFP_TX_CTRL_BYTE_OFFS 86
78#define QSFP_PWR_CTRL_BYTE_OFFS 93 81#define QSFP_PWR_CTRL_BYTE_OFFS 93
79#define QSFP_CDR_CTRL_BYTE_OFFS 98 82#define QSFP_CDR_CTRL_BYTE_OFFS 98
diff --git a/drivers/infiniband/hw/i40iw/i40iw.h b/drivers/infiniband/hw/i40iw/i40iw.h
index b738acdb9b02..8ec09e470f84 100644
--- a/drivers/infiniband/hw/i40iw/i40iw.h
+++ b/drivers/infiniband/hw/i40iw/i40iw.h
@@ -232,7 +232,7 @@ struct i40iw_device {
232 struct i40e_client *client; 232 struct i40e_client *client;
233 struct i40iw_hw hw; 233 struct i40iw_hw hw;
234 struct i40iw_cm_core cm_core; 234 struct i40iw_cm_core cm_core;
235 unsigned long *mem_resources; 235 u8 *mem_resources;
236 unsigned long *allocated_qps; 236 unsigned long *allocated_qps;
237 unsigned long *allocated_cqs; 237 unsigned long *allocated_cqs;
238 unsigned long *allocated_mrs; 238 unsigned long *allocated_mrs;
@@ -435,8 +435,8 @@ static inline int i40iw_alloc_resource(struct i40iw_device *iwdev,
435 *next = resource_num + 1; 435 *next = resource_num + 1;
436 if (*next == max_resources) 436 if (*next == max_resources)
437 *next = 0; 437 *next = 0;
438 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
439 *req_resource_num = resource_num; 438 *req_resource_num = resource_num;
439 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
440 440
441 return 0; 441 return 0;
442} 442}
diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c b/drivers/infiniband/hw/i40iw/i40iw_cm.c
index 5026dc79978a..7ca0638579c0 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_cm.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c
@@ -535,8 +535,8 @@ static struct i40iw_puda_buf *i40iw_form_cm_frame(struct i40iw_cm_node *cm_node,
535 buf += hdr_len; 535 buf += hdr_len;
536 } 536 }
537 537
538 if (pd_len) 538 if (pdata && pdata->addr)
539 memcpy(buf, pdata->addr, pd_len); 539 memcpy(buf, pdata->addr, pdata->size);
540 540
541 atomic_set(&sqbuf->refcount, 1); 541 atomic_set(&sqbuf->refcount, 1);
542 542
@@ -3347,26 +3347,6 @@ int i40iw_cm_disconn(struct i40iw_qp *iwqp)
3347} 3347}
3348 3348
3349/** 3349/**
3350 * i40iw_loopback_nop - Send a nop
3351 * @qp: associated hw qp
3352 */
3353static void i40iw_loopback_nop(struct i40iw_sc_qp *qp)
3354{
3355 u64 *wqe;
3356 u64 header;
3357
3358 wqe = qp->qp_uk.sq_base->elem;
3359 set_64bit_val(wqe, 0, 0);
3360 set_64bit_val(wqe, 8, 0);
3361 set_64bit_val(wqe, 16, 0);
3362
3363 header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
3364 LS_64(0, I40IWQPSQ_SIGCOMPL) |
3365 LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
3366 set_64bit_val(wqe, 24, header);
3367}
3368
3369/**
3370 * i40iw_qp_disconnect - free qp and close cm 3350 * i40iw_qp_disconnect - free qp and close cm
3371 * @iwqp: associate qp for the connection 3351 * @iwqp: associate qp for the connection
3372 */ 3352 */
@@ -3638,7 +3618,7 @@ int i40iw_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3638 } else { 3618 } else {
3639 if (iwqp->page) 3619 if (iwqp->page)
3640 iwqp->sc_qp.qp_uk.sq_base = kmap(iwqp->page); 3620 iwqp->sc_qp.qp_uk.sq_base = kmap(iwqp->page);
3641 i40iw_loopback_nop(&iwqp->sc_qp); 3621 dev->iw_priv_qp_ops->qp_send_lsmm(&iwqp->sc_qp, NULL, 0, 0);
3642 } 3622 }
3643 3623
3644 if (iwqp->page) 3624 if (iwqp->page)
diff --git a/drivers/infiniband/hw/i40iw/i40iw_main.c b/drivers/infiniband/hw/i40iw/i40iw_main.c
index 6e9081380a27..0cbbe4038298 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_main.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_main.c
@@ -1558,6 +1558,10 @@ static int i40iw_open(struct i40e_info *ldev, struct i40e_client *client)
1558 enum i40iw_status_code status; 1558 enum i40iw_status_code status;
1559 struct i40iw_handler *hdl; 1559 struct i40iw_handler *hdl;
1560 1560
1561 hdl = i40iw_find_netdev(ldev->netdev);
1562 if (hdl)
1563 return 0;
1564
1561 hdl = kzalloc(sizeof(*hdl), GFP_KERNEL); 1565 hdl = kzalloc(sizeof(*hdl), GFP_KERNEL);
1562 if (!hdl) 1566 if (!hdl)
1563 return -ENOMEM; 1567 return -ENOMEM;
diff --git a/drivers/infiniband/hw/i40iw/i40iw_utils.c b/drivers/infiniband/hw/i40iw/i40iw_utils.c
index 0e8db0a35141..6fd043b1d714 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_utils.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_utils.c
@@ -673,8 +673,11 @@ enum i40iw_status_code i40iw_free_virt_mem(struct i40iw_hw *hw,
673{ 673{
674 if (!mem) 674 if (!mem)
675 return I40IW_ERR_PARAM; 675 return I40IW_ERR_PARAM;
676 /*
677 * mem->va points to the parent of mem, so both mem and mem->va
678 * can not be touched once mem->va is freed
679 */
676 kfree(mem->va); 680 kfree(mem->va);
677 mem->va = NULL;
678 return 0; 681 return 0;
679} 682}
680 683
diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
index 2360338877bf..6329c971c22f 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
@@ -794,7 +794,6 @@ static struct ib_qp *i40iw_create_qp(struct ib_pd *ibpd,
794 return &iwqp->ibqp; 794 return &iwqp->ibqp;
795error: 795error:
796 i40iw_free_qp_resources(iwdev, iwqp, qp_num); 796 i40iw_free_qp_resources(iwdev, iwqp, qp_num);
797 kfree(mem);
798 return ERR_PTR(err_code); 797 return ERR_PTR(err_code);
799} 798}
800 799
@@ -1926,8 +1925,7 @@ static int i40iw_dereg_mr(struct ib_mr *ib_mr)
1926 } 1925 }
1927 if (iwpbl->pbl_allocated) 1926 if (iwpbl->pbl_allocated)
1928 i40iw_free_pble(iwdev->pble_rsrc, palloc); 1927 i40iw_free_pble(iwdev->pble_rsrc, palloc);
1929 kfree(iwpbl->iwmr); 1928 kfree(iwmr);
1930 iwpbl->iwmr = NULL;
1931 return 0; 1929 return 0;
1932 } 1930 }
1933 1931
diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
index d6fc8a6e8c33..006db6436e3b 100644
--- a/drivers/infiniband/hw/mlx4/cq.c
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -576,8 +576,8 @@ static int mlx4_ib_ipoib_csum_ok(__be16 status, __be16 checksum)
576 checksum == cpu_to_be16(0xffff); 576 checksum == cpu_to_be16(0xffff);
577} 577}
578 578
579static int use_tunnel_data(struct mlx4_ib_qp *qp, struct mlx4_ib_cq *cq, struct ib_wc *wc, 579static void use_tunnel_data(struct mlx4_ib_qp *qp, struct mlx4_ib_cq *cq, struct ib_wc *wc,
580 unsigned tail, struct mlx4_cqe *cqe, int is_eth) 580 unsigned tail, struct mlx4_cqe *cqe, int is_eth)
581{ 581{
582 struct mlx4_ib_proxy_sqp_hdr *hdr; 582 struct mlx4_ib_proxy_sqp_hdr *hdr;
583 583
@@ -600,8 +600,6 @@ static int use_tunnel_data(struct mlx4_ib_qp *qp, struct mlx4_ib_cq *cq, struct
600 wc->slid = be16_to_cpu(hdr->tun.slid_mac_47_32); 600 wc->slid = be16_to_cpu(hdr->tun.slid_mac_47_32);
601 wc->sl = (u8) (be16_to_cpu(hdr->tun.sl_vid) >> 12); 601 wc->sl = (u8) (be16_to_cpu(hdr->tun.sl_vid) >> 12);
602 } 602 }
603
604 return 0;
605} 603}
606 604
607static void mlx4_ib_qp_sw_comp(struct mlx4_ib_qp *qp, int num_entries, 605static void mlx4_ib_qp_sw_comp(struct mlx4_ib_qp *qp, int num_entries,
@@ -692,7 +690,7 @@ repoll:
692 if (unlikely((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) == MLX4_OPCODE_NOP && 690 if (unlikely((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) == MLX4_OPCODE_NOP &&
693 is_send)) { 691 is_send)) {
694 pr_warn("Completion for NOP opcode detected!\n"); 692 pr_warn("Completion for NOP opcode detected!\n");
695 return -EINVAL; 693 return -EAGAIN;
696 } 694 }
697 695
698 /* Resize CQ in progress */ 696 /* Resize CQ in progress */
@@ -723,7 +721,7 @@ repoll:
723 if (unlikely(!mqp)) { 721 if (unlikely(!mqp)) {
724 pr_warn("CQ %06x with entry for unknown QPN %06x\n", 722 pr_warn("CQ %06x with entry for unknown QPN %06x\n",
725 cq->mcq.cqn, be32_to_cpu(cqe->vlan_my_qpn) & MLX4_CQE_QPN_MASK); 723 cq->mcq.cqn, be32_to_cpu(cqe->vlan_my_qpn) & MLX4_CQE_QPN_MASK);
726 return -EINVAL; 724 return -EAGAIN;
727 } 725 }
728 726
729 *cur_qp = to_mibqp(mqp); 727 *cur_qp = to_mibqp(mqp);
@@ -741,7 +739,7 @@ repoll:
741 if (unlikely(!msrq)) { 739 if (unlikely(!msrq)) {
742 pr_warn("CQ %06x with entry for unknown SRQN %06x\n", 740 pr_warn("CQ %06x with entry for unknown SRQN %06x\n",
743 cq->mcq.cqn, srq_num); 741 cq->mcq.cqn, srq_num);
744 return -EINVAL; 742 return -EAGAIN;
745 } 743 }
746 } 744 }
747 745
@@ -852,9 +850,11 @@ repoll:
852 if (mlx4_is_mfunc(to_mdev(cq->ibcq.device)->dev)) { 850 if (mlx4_is_mfunc(to_mdev(cq->ibcq.device)->dev)) {
853 if ((*cur_qp)->mlx4_ib_qp_type & 851 if ((*cur_qp)->mlx4_ib_qp_type &
854 (MLX4_IB_QPT_PROXY_SMI_OWNER | 852 (MLX4_IB_QPT_PROXY_SMI_OWNER |
855 MLX4_IB_QPT_PROXY_SMI | MLX4_IB_QPT_PROXY_GSI)) 853 MLX4_IB_QPT_PROXY_SMI | MLX4_IB_QPT_PROXY_GSI)) {
856 return use_tunnel_data(*cur_qp, cq, wc, tail, 854 use_tunnel_data(*cur_qp, cq, wc, tail, cqe,
857 cqe, is_eth); 855 is_eth);
856 return 0;
857 }
858 } 858 }
859 859
860 wc->slid = be16_to_cpu(cqe->rlid); 860 wc->slid = be16_to_cpu(cqe->rlid);
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index a84bb766fc62..1b4094baa2de 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -37,7 +37,6 @@
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/io-mapping.h>
41#if defined(CONFIG_X86) 40#if defined(CONFIG_X86)
42#include <asm/pat.h> 41#include <asm/pat.h>
43#endif 42#endif
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
index 16740dcb876b..67fc0b6857e1 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
@@ -1156,18 +1156,18 @@ static void ocrdma_get_attr(struct ocrdma_dev *dev,
1156 attr->max_srq = 1156 attr->max_srq =
1157 (rsp->max_srq_rpir_qps & OCRDMA_MBX_QUERY_CFG_MAX_SRQ_MASK) >> 1157 (rsp->max_srq_rpir_qps & OCRDMA_MBX_QUERY_CFG_MAX_SRQ_MASK) >>
1158 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_OFFSET; 1158 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_OFFSET;
1159 attr->max_send_sge = ((rsp->max_write_send_sge & 1159 attr->max_send_sge = ((rsp->max_recv_send_sge &
1160 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_MASK) >> 1160 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_MASK) >>
1161 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_SHIFT); 1161 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_SHIFT);
1162 attr->max_recv_sge = (rsp->max_write_send_sge & 1162 attr->max_recv_sge = (rsp->max_recv_send_sge &
1163 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_MASK) >> 1163 OCRDMA_MBX_QUERY_CFG_MAX_RECV_SGE_MASK) >>
1164 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_SHIFT; 1164 OCRDMA_MBX_QUERY_CFG_MAX_RECV_SGE_SHIFT;
1165 attr->max_srq_sge = (rsp->max_srq_rqe_sge & 1165 attr->max_srq_sge = (rsp->max_srq_rqe_sge &
1166 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_MASK) >> 1166 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_MASK) >>
1167 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_OFFSET; 1167 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_OFFSET;
1168 attr->max_rdma_sge = (rsp->max_write_send_sge & 1168 attr->max_rdma_sge = (rsp->max_wr_rd_sge &
1169 OCRDMA_MBX_QUERY_CFG_MAX_WRITE_SGE_MASK) >> 1169 OCRDMA_MBX_QUERY_CFG_MAX_RD_SGE_MASK) >>
1170 OCRDMA_MBX_QUERY_CFG_MAX_WRITE_SGE_SHIFT; 1170 OCRDMA_MBX_QUERY_CFG_MAX_RD_SGE_SHIFT;
1171 attr->max_ord_per_qp = (rsp->max_ird_ord_per_qp & 1171 attr->max_ord_per_qp = (rsp->max_ird_ord_per_qp &
1172 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_MASK) >> 1172 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_MASK) >>
1173 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_SHIFT; 1173 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_SHIFT;
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_sli.h b/drivers/infiniband/hw/ocrdma/ocrdma_sli.h
index 0efc9662c6d8..37df4481bb8f 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_sli.h
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_sli.h
@@ -554,9 +554,9 @@ enum {
554 OCRDMA_MBX_QUERY_CFG_L3_TYPE_MASK = 0x18, 554 OCRDMA_MBX_QUERY_CFG_L3_TYPE_MASK = 0x18,
555 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_SHIFT = 0, 555 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_SHIFT = 0,
556 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_MASK = 0xFFFF, 556 OCRDMA_MBX_QUERY_CFG_MAX_SEND_SGE_MASK = 0xFFFF,
557 OCRDMA_MBX_QUERY_CFG_MAX_WRITE_SGE_SHIFT = 16, 557 OCRDMA_MBX_QUERY_CFG_MAX_RECV_SGE_SHIFT = 16,
558 OCRDMA_MBX_QUERY_CFG_MAX_WRITE_SGE_MASK = 0xFFFF << 558 OCRDMA_MBX_QUERY_CFG_MAX_RECV_SGE_MASK = 0xFFFF <<
559 OCRDMA_MBX_QUERY_CFG_MAX_WRITE_SGE_SHIFT, 559 OCRDMA_MBX_QUERY_CFG_MAX_RECV_SGE_SHIFT,
560 560
561 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_SHIFT = 0, 561 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_SHIFT = 0,
562 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_MASK = 0xFFFF, 562 OCRDMA_MBX_QUERY_CFG_MAX_ORD_PER_QP_MASK = 0xFFFF,
@@ -612,6 +612,8 @@ enum {
612 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_OFFSET = 0, 612 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_OFFSET = 0,
613 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_MASK = 0xFFFF << 613 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_MASK = 0xFFFF <<
614 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_OFFSET, 614 OCRDMA_MBX_QUERY_CFG_MAX_SRQ_SGE_OFFSET,
615 OCRDMA_MBX_QUERY_CFG_MAX_RD_SGE_SHIFT = 0,
616 OCRDMA_MBX_QUERY_CFG_MAX_RD_SGE_MASK = 0xFFFF,
615}; 617};
616 618
617struct ocrdma_mbx_query_config { 619struct ocrdma_mbx_query_config {
@@ -619,7 +621,7 @@ struct ocrdma_mbx_query_config {
619 struct ocrdma_mbx_rsp rsp; 621 struct ocrdma_mbx_rsp rsp;
620 u32 qp_srq_cq_ird_ord; 622 u32 qp_srq_cq_ird_ord;
621 u32 max_pd_ca_ack_delay; 623 u32 max_pd_ca_ack_delay;
622 u32 max_write_send_sge; 624 u32 max_recv_send_sge;
623 u32 max_ird_ord_per_qp; 625 u32 max_ird_ord_per_qp;
624 u32 max_shared_ird_ord; 626 u32 max_shared_ird_ord;
625 u32 max_mr; 627 u32 max_mr;
@@ -639,6 +641,8 @@ struct ocrdma_mbx_query_config {
639 u32 max_wqes_rqes_per_q; 641 u32 max_wqes_rqes_per_q;
640 u32 max_cq_cqes_per_cq; 642 u32 max_cq_cqes_per_cq;
641 u32 max_srq_rqe_sge; 643 u32 max_srq_rqe_sge;
644 u32 max_wr_rd_sge;
645 u32 ird_pgsz_num_pages;
642}; 646};
643 647
644struct ocrdma_fw_ver_rsp { 648struct ocrdma_fw_ver_rsp {
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index b1a3d91fe8b9..0aa854737e74 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -125,8 +125,8 @@ int ocrdma_query_device(struct ib_device *ibdev, struct ib_device_attr *attr,
125 IB_DEVICE_SYS_IMAGE_GUID | 125 IB_DEVICE_SYS_IMAGE_GUID |
126 IB_DEVICE_LOCAL_DMA_LKEY | 126 IB_DEVICE_LOCAL_DMA_LKEY |
127 IB_DEVICE_MEM_MGT_EXTENSIONS; 127 IB_DEVICE_MEM_MGT_EXTENSIONS;
128 attr->max_sge = dev->attr.max_send_sge; 128 attr->max_sge = min(dev->attr.max_send_sge, dev->attr.max_recv_sge);
129 attr->max_sge_rd = attr->max_sge; 129 attr->max_sge_rd = dev->attr.max_rdma_sge;
130 attr->max_cq = dev->attr.max_cq; 130 attr->max_cq = dev->attr.max_cq;
131 attr->max_cqe = dev->attr.max_cqe; 131 attr->max_cqe = dev->attr.max_cqe;
132 attr->max_mr = dev->attr.max_mr; 132 attr->max_mr = dev->attr.max_mr;
diff --git a/drivers/infiniband/hw/qib/qib_debugfs.c b/drivers/infiniband/hw/qib/qib_debugfs.c
index 5e75b43c596b..5bad8e3b40bb 100644
--- a/drivers/infiniband/hw/qib/qib_debugfs.c
+++ b/drivers/infiniband/hw/qib/qib_debugfs.c
@@ -189,27 +189,32 @@ static int _ctx_stats_seq_show(struct seq_file *s, void *v)
189DEBUGFS_FILE(ctx_stats) 189DEBUGFS_FILE(ctx_stats)
190 190
191static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos) 191static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
192 __acquires(RCU)
192{ 193{
193 struct qib_qp_iter *iter; 194 struct qib_qp_iter *iter;
194 loff_t n = *pos; 195 loff_t n = *pos;
195 196
196 rcu_read_lock();
197 iter = qib_qp_iter_init(s->private); 197 iter = qib_qp_iter_init(s->private);
198
199 /* stop calls rcu_read_unlock */
200 rcu_read_lock();
201
198 if (!iter) 202 if (!iter)
199 return NULL; 203 return NULL;
200 204
201 while (n--) { 205 do {
202 if (qib_qp_iter_next(iter)) { 206 if (qib_qp_iter_next(iter)) {
203 kfree(iter); 207 kfree(iter);
204 return NULL; 208 return NULL;
205 } 209 }
206 } 210 } while (n--);
207 211
208 return iter; 212 return iter;
209} 213}
210 214
211static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr, 215static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
212 loff_t *pos) 216 loff_t *pos)
217 __must_hold(RCU)
213{ 218{
214 struct qib_qp_iter *iter = iter_ptr; 219 struct qib_qp_iter *iter = iter_ptr;
215 220
@@ -224,6 +229,7 @@ static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
224} 229}
225 230
226static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr) 231static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
232 __releases(RCU)
227{ 233{
228 rcu_read_unlock(); 234 rcu_read_unlock();
229} 235}
diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
index fcdf37913a26..c3edc033f7c4 100644
--- a/drivers/infiniband/hw/qib/qib_fs.c
+++ b/drivers/infiniband/hw/qib/qib_fs.c
@@ -328,26 +328,12 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
328 328
329 pos = *ppos; 329 pos = *ppos;
330 330
331 if (pos != 0) { 331 if (pos != 0 || count != sizeof(struct qib_flash))
332 ret = -EINVAL; 332 return -EINVAL;
333 goto bail;
334 }
335
336 if (count != sizeof(struct qib_flash)) {
337 ret = -EINVAL;
338 goto bail;
339 }
340
341 tmp = kmalloc(count, GFP_KERNEL);
342 if (!tmp) {
343 ret = -ENOMEM;
344 goto bail;
345 }
346 333
347 if (copy_from_user(tmp, buf, count)) { 334 tmp = memdup_user(buf, count);
348 ret = -EFAULT; 335 if (IS_ERR(tmp))
349 goto bail_tmp; 336 return PTR_ERR(tmp);
350 }
351 337
352 dd = private2dd(file); 338 dd = private2dd(file);
353 if (qib_eeprom_write(dd, pos, tmp, count)) { 339 if (qib_eeprom_write(dd, pos, tmp, count)) {
@@ -361,8 +347,6 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
361 347
362bail_tmp: 348bail_tmp:
363 kfree(tmp); 349 kfree(tmp);
364
365bail:
366 return ret; 350 return ret;
367} 351}
368 352
diff --git a/drivers/infiniband/hw/qib/qib_qp.c b/drivers/infiniband/hw/qib/qib_qp.c
index 9cc0aae1d781..f9b8cd2354d1 100644
--- a/drivers/infiniband/hw/qib/qib_qp.c
+++ b/drivers/infiniband/hw/qib/qib_qp.c
@@ -573,10 +573,6 @@ struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev)
573 return NULL; 573 return NULL;
574 574
575 iter->dev = dev; 575 iter->dev = dev;
576 if (qib_qp_iter_next(iter)) {
577 kfree(iter);
578 return NULL;
579 }
580 576
581 return iter; 577 return iter;
582} 578}
diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c
index c229b9f4a52d..0a89a955550b 100644
--- a/drivers/infiniband/hw/usnic/usnic_ib_main.c
+++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c
@@ -664,7 +664,8 @@ static int __init usnic_ib_init(void)
664 return err; 664 return err;
665 } 665 }
666 666
667 if (pci_register_driver(&usnic_ib_pci_driver)) { 667 err = pci_register_driver(&usnic_ib_pci_driver);
668 if (err) {
668 usnic_err("Unable to register with PCI\n"); 669 usnic_err("Unable to register with PCI\n");
669 goto out_umem_fini; 670 goto out_umem_fini;
670 } 671 }
diff --git a/drivers/infiniband/sw/rdmavt/qp.c b/drivers/infiniband/sw/rdmavt/qp.c
index bdb540f25a88..870b4f212fbc 100644
--- a/drivers/infiniband/sw/rdmavt/qp.c
+++ b/drivers/infiniband/sw/rdmavt/qp.c
@@ -873,7 +873,8 @@ bail_qpn:
873 free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num); 873 free_qpn(&rdi->qp_dev->qpn_table, qp->ibqp.qp_num);
874 874
875bail_rq_wq: 875bail_rq_wq:
876 vfree(qp->r_rq.wq); 876 if (!qp->ip)
877 vfree(qp->r_rq.wq);
877 878
878bail_driver_priv: 879bail_driver_priv:
879 rdi->driver_f.qp_priv_free(rdi, qp); 880 rdi->driver_f.qp_priv_free(rdi, qp);
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index ba6be060a476..7914c14478cd 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -448,7 +448,7 @@ isert_alloc_login_buf(struct isert_conn *isert_conn,
448 448
449 isert_conn->login_rsp_buf = kzalloc(ISER_RX_PAYLOAD_SIZE, GFP_KERNEL); 449 isert_conn->login_rsp_buf = kzalloc(ISER_RX_PAYLOAD_SIZE, GFP_KERNEL);
450 if (!isert_conn->login_rsp_buf) { 450 if (!isert_conn->login_rsp_buf) {
451 isert_err("Unable to allocate isert_conn->login_rspbuf\n"); 451 ret = -ENOMEM;
452 goto out_unmap_login_req_buf; 452 goto out_unmap_login_req_buf;
453 } 453 }
454 454
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index dfa23b075a88..883bbfe08e0e 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -522,6 +522,11 @@ static int srpt_refresh_port(struct srpt_port *sport)
522 if (ret) 522 if (ret)
523 goto err_query_port; 523 goto err_query_port;
524 524
525 snprintf(sport->port_guid, sizeof(sport->port_guid),
526 "0x%016llx%016llx",
527 be64_to_cpu(sport->gid.global.subnet_prefix),
528 be64_to_cpu(sport->gid.global.interface_id));
529
525 if (!sport->mad_agent) { 530 if (!sport->mad_agent) {
526 memset(&reg_req, 0, sizeof(reg_req)); 531 memset(&reg_req, 0, sizeof(reg_req));
527 reg_req.mgmt_class = IB_MGMT_CLASS_DEVICE_MGMT; 532 reg_req.mgmt_class = IB_MGMT_CLASS_DEVICE_MGMT;
@@ -2548,10 +2553,6 @@ static void srpt_add_one(struct ib_device *device)
2548 sdev->device->name, i); 2553 sdev->device->name, i);
2549 goto err_ring; 2554 goto err_ring;
2550 } 2555 }
2551 snprintf(sport->port_guid, sizeof(sport->port_guid),
2552 "0x%016llx%016llx",
2553 be64_to_cpu(sport->gid.global.subnet_prefix),
2554 be64_to_cpu(sport->gid.global.interface_id));
2555 } 2556 }
2556 2557
2557 spin_lock(&srpt_dev_lock); 2558 spin_lock(&srpt_dev_lock);
diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
index 7d61439be5f2..0c07e1023a46 100644
--- a/drivers/input/keyboard/tegra-kbc.c
+++ b/drivers/input/keyboard/tegra-kbc.c
@@ -376,7 +376,7 @@ static int tegra_kbc_start(struct tegra_kbc *kbc)
376 /* Reset the KBC controller to clear all previous status.*/ 376 /* Reset the KBC controller to clear all previous status.*/
377 reset_control_assert(kbc->rst); 377 reset_control_assert(kbc->rst);
378 udelay(100); 378 udelay(100);
379 reset_control_assert(kbc->rst); 379 reset_control_deassert(kbc->rst);
380 udelay(100); 380 udelay(100);
381 381
382 tegra_kbc_config_pins(kbc); 382 tegra_kbc_config_pins(kbc);
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index faa295ec4f31..c83bce89028b 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -553,7 +553,6 @@ int rmi_read_register_desc(struct rmi_device *d, u16 addr,
553 goto free_struct_buff; 553 goto free_struct_buff;
554 554
555 reg = find_first_bit(rdesc->presense_map, RMI_REG_DESC_PRESENSE_BITS); 555 reg = find_first_bit(rdesc->presense_map, RMI_REG_DESC_PRESENSE_BITS);
556 map_offset = 0;
557 for (i = 0; i < rdesc->num_registers; i++) { 556 for (i = 0; i < rdesc->num_registers; i++) {
558 struct rmi_register_desc_item *item = &rdesc->registers[i]; 557 struct rmi_register_desc_item *item = &rdesc->registers[i];
559 int reg_size = struct_buf[offset]; 558 int reg_size = struct_buf[offset];
@@ -576,6 +575,8 @@ int rmi_read_register_desc(struct rmi_device *d, u16 addr,
576 item->reg = reg; 575 item->reg = reg;
577 item->reg_size = reg_size; 576 item->reg_size = reg_size;
578 577
578 map_offset = 0;
579
579 do { 580 do {
580 for (b = 0; b < 7; b++) { 581 for (b = 0; b < 7; b++) {
581 if (struct_buf[offset] & (0x1 << b)) 582 if (struct_buf[offset] & (0x1 << b))
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index b4d34086e73f..405252a884dd 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -1305,6 +1305,7 @@ static int __init i8042_create_aux_port(int idx)
1305 serio->write = i8042_aux_write; 1305 serio->write = i8042_aux_write;
1306 serio->start = i8042_start; 1306 serio->start = i8042_start;
1307 serio->stop = i8042_stop; 1307 serio->stop = i8042_stop;
1308 serio->ps2_cmd_mutex = &i8042_mutex;
1308 serio->port_data = port; 1309 serio->port_data = port;
1309 serio->dev.parent = &i8042_platform_device->dev; 1310 serio->dev.parent = &i8042_platform_device->dev;
1310 if (idx < 0) { 1311 if (idx < 0) {
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index a61b2153ab8c..1ce3ecbe37f8 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -1473,7 +1473,6 @@ static int ads7846_remove(struct spi_device *spi)
1473 1473
1474 ads784x_hwmon_unregister(spi, ts); 1474 ads784x_hwmon_unregister(spi, ts);
1475 1475
1476 regulator_disable(ts->reg);
1477 regulator_put(ts->reg); 1476 regulator_put(ts->reg);
1478 1477
1479 if (!ts->get_pendown_state) { 1478 if (!ts->get_pendown_state) {
diff --git a/drivers/input/touchscreen/silead.c b/drivers/input/touchscreen/silead.c
index 7379fe153cf9..b2744a64e933 100644
--- a/drivers/input/touchscreen/silead.c
+++ b/drivers/input/touchscreen/silead.c
@@ -464,7 +464,7 @@ static int silead_ts_probe(struct i2c_client *client,
464 return -ENODEV; 464 return -ENODEV;
465 465
466 /* Power GPIO pin */ 466 /* Power GPIO pin */
467 data->gpio_power = gpiod_get_optional(dev, "power", GPIOD_OUT_LOW); 467 data->gpio_power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
468 if (IS_ERR(data->gpio_power)) { 468 if (IS_ERR(data->gpio_power)) {
469 if (PTR_ERR(data->gpio_power) != -EPROBE_DEFER) 469 if (PTR_ERR(data->gpio_power) != -EPROBE_DEFER)
470 dev_err(dev, "Shutdown GPIO request failed\n"); 470 dev_err(dev, "Shutdown GPIO request failed\n");
diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index ce801170d5f2..641e88761319 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -879,7 +879,7 @@ static void arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu)
879 * We may have concurrent producers, so we need to be careful 879 * We may have concurrent producers, so we need to be careful
880 * not to touch any of the shadow cmdq state. 880 * not to touch any of the shadow cmdq state.
881 */ 881 */
882 queue_read(cmd, Q_ENT(q, idx), q->ent_dwords); 882 queue_read(cmd, Q_ENT(q, cons), q->ent_dwords);
883 dev_err(smmu->dev, "skipping command in error state:\n"); 883 dev_err(smmu->dev, "skipping command in error state:\n");
884 for (i = 0; i < ARRAY_SIZE(cmd); ++i) 884 for (i = 0; i < ARRAY_SIZE(cmd); ++i)
885 dev_err(smmu->dev, "\t0x%016llx\n", (unsigned long long)cmd[i]); 885 dev_err(smmu->dev, "\t0x%016llx\n", (unsigned long long)cmd[i]);
@@ -890,7 +890,7 @@ static void arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu)
890 return; 890 return;
891 } 891 }
892 892
893 queue_write(cmd, Q_ENT(q, idx), q->ent_dwords); 893 queue_write(Q_ENT(q, cons), cmd, q->ent_dwords);
894} 894}
895 895
896static void arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu, 896static void arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu,
@@ -1034,6 +1034,9 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
1034 case STRTAB_STE_0_CFG_S2_TRANS: 1034 case STRTAB_STE_0_CFG_S2_TRANS:
1035 ste_live = true; 1035 ste_live = true;
1036 break; 1036 break;
1037 case STRTAB_STE_0_CFG_ABORT:
1038 if (disable_bypass)
1039 break;
1037 default: 1040 default:
1038 BUG(); /* STE corruption */ 1041 BUG(); /* STE corruption */
1039 } 1042 }
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 4f49fe29f202..2db74ebc3240 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -686,8 +686,7 @@ static struct iommu_gather_ops arm_smmu_gather_ops = {
686 686
687static irqreturn_t arm_smmu_context_fault(int irq, void *dev) 687static irqreturn_t arm_smmu_context_fault(int irq, void *dev)
688{ 688{
689 int flags, ret; 689 u32 fsr, fsynr;
690 u32 fsr, fsynr, resume;
691 unsigned long iova; 690 unsigned long iova;
692 struct iommu_domain *domain = dev; 691 struct iommu_domain *domain = dev;
693 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); 692 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
@@ -701,34 +700,15 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev)
701 if (!(fsr & FSR_FAULT)) 700 if (!(fsr & FSR_FAULT))
702 return IRQ_NONE; 701 return IRQ_NONE;
703 702
704 if (fsr & FSR_IGN)
705 dev_err_ratelimited(smmu->dev,
706 "Unexpected context fault (fsr 0x%x)\n",
707 fsr);
708
709 fsynr = readl_relaxed(cb_base + ARM_SMMU_CB_FSYNR0); 703 fsynr = readl_relaxed(cb_base + ARM_SMMU_CB_FSYNR0);
710 flags = fsynr & FSYNR0_WNR ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ;
711
712 iova = readq_relaxed(cb_base + ARM_SMMU_CB_FAR); 704 iova = readq_relaxed(cb_base + ARM_SMMU_CB_FAR);
713 if (!report_iommu_fault(domain, smmu->dev, iova, flags)) {
714 ret = IRQ_HANDLED;
715 resume = RESUME_RETRY;
716 } else {
717 dev_err_ratelimited(smmu->dev,
718 "Unhandled context fault: iova=0x%08lx, fsynr=0x%x, cb=%d\n",
719 iova, fsynr, cfg->cbndx);
720 ret = IRQ_NONE;
721 resume = RESUME_TERMINATE;
722 }
723
724 /* Clear the faulting FSR */
725 writel(fsr, cb_base + ARM_SMMU_CB_FSR);
726 705
727 /* Retry or terminate any stalled transactions */ 706 dev_err_ratelimited(smmu->dev,
728 if (fsr & FSR_SS) 707 "Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cb=%d\n",
729 writel_relaxed(resume, cb_base + ARM_SMMU_CB_RESUME); 708 fsr, iova, fsynr, cfg->cbndx);
730 709
731 return ret; 710 writel(fsr, cb_base + ARM_SMMU_CB_FSR);
711 return IRQ_HANDLED;
732} 712}
733 713
734static irqreturn_t arm_smmu_global_fault(int irq, void *dev) 714static irqreturn_t arm_smmu_global_fault(int irq, void *dev)
@@ -837,7 +817,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
837 } 817 }
838 818
839 /* SCTLR */ 819 /* SCTLR */
840 reg = SCTLR_CFCFG | SCTLR_CFIE | SCTLR_CFRE | SCTLR_M | SCTLR_EAE_SBOP; 820 reg = SCTLR_CFIE | SCTLR_CFRE | SCTLR_M | SCTLR_EAE_SBOP;
841 if (stage1) 821 if (stage1)
842 reg |= SCTLR_S1_ASIDPNE; 822 reg |= SCTLR_S1_ASIDPNE;
843#ifdef __BIG_ENDIAN 823#ifdef __BIG_ENDIAN
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 08a1e2f3690f..00c8a08d56e7 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -68,7 +68,8 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
68 if (!iovad) 68 if (!iovad)
69 return; 69 return;
70 70
71 put_iova_domain(iovad); 71 if (iovad->granule)
72 put_iova_domain(iovad);
72 kfree(iovad); 73 kfree(iovad);
73 domain->iova_cookie = NULL; 74 domain->iova_cookie = NULL;
74} 75}
@@ -151,12 +152,15 @@ int dma_direction_to_prot(enum dma_data_direction dir, bool coherent)
151 } 152 }
152} 153}
153 154
154static struct iova *__alloc_iova(struct iova_domain *iovad, size_t size, 155static struct iova *__alloc_iova(struct iommu_domain *domain, size_t size,
155 dma_addr_t dma_limit) 156 dma_addr_t dma_limit)
156{ 157{
158 struct iova_domain *iovad = domain->iova_cookie;
157 unsigned long shift = iova_shift(iovad); 159 unsigned long shift = iova_shift(iovad);
158 unsigned long length = iova_align(iovad, size) >> shift; 160 unsigned long length = iova_align(iovad, size) >> shift;
159 161
162 if (domain->geometry.force_aperture)
163 dma_limit = min(dma_limit, domain->geometry.aperture_end);
160 /* 164 /*
161 * Enforce size-alignment to be safe - there could perhaps be an 165 * Enforce size-alignment to be safe - there could perhaps be an
162 * attribute to control this per-device, or at least per-domain... 166 * attribute to control this per-device, or at least per-domain...
@@ -314,7 +318,7 @@ struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
314 if (!pages) 318 if (!pages)
315 return NULL; 319 return NULL;
316 320
317 iova = __alloc_iova(iovad, size, dev->coherent_dma_mask); 321 iova = __alloc_iova(domain, size, dev->coherent_dma_mask);
318 if (!iova) 322 if (!iova)
319 goto out_free_pages; 323 goto out_free_pages;
320 324
@@ -386,7 +390,7 @@ dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
386 phys_addr_t phys = page_to_phys(page) + offset; 390 phys_addr_t phys = page_to_phys(page) + offset;
387 size_t iova_off = iova_offset(iovad, phys); 391 size_t iova_off = iova_offset(iovad, phys);
388 size_t len = iova_align(iovad, size + iova_off); 392 size_t len = iova_align(iovad, size + iova_off);
389 struct iova *iova = __alloc_iova(iovad, len, dma_get_mask(dev)); 393 struct iova *iova = __alloc_iova(domain, len, dma_get_mask(dev));
390 394
391 if (!iova) 395 if (!iova)
392 return DMA_ERROR_CODE; 396 return DMA_ERROR_CODE;
@@ -538,7 +542,7 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
538 prev = s; 542 prev = s;
539 } 543 }
540 544
541 iova = __alloc_iova(iovad, iova_len, dma_get_mask(dev)); 545 iova = __alloc_iova(domain, iova_len, dma_get_mask(dev));
542 if (!iova) 546 if (!iova)
543 goto out_restore_sg; 547 goto out_restore_sg;
544 548
diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c
index 8c6139986d7d..def8ca1c982d 100644
--- a/drivers/iommu/io-pgtable-arm-v7s.c
+++ b/drivers/iommu/io-pgtable-arm-v7s.c
@@ -286,12 +286,14 @@ static int arm_v7s_pte_to_prot(arm_v7s_iopte pte, int lvl)
286 int prot = IOMMU_READ; 286 int prot = IOMMU_READ;
287 arm_v7s_iopte attr = pte >> ARM_V7S_ATTR_SHIFT(lvl); 287 arm_v7s_iopte attr = pte >> ARM_V7S_ATTR_SHIFT(lvl);
288 288
289 if (attr & ARM_V7S_PTE_AP_RDONLY) 289 if (!(attr & ARM_V7S_PTE_AP_RDONLY))
290 prot |= IOMMU_WRITE; 290 prot |= IOMMU_WRITE;
291 if ((attr & (ARM_V7S_TEX_MASK << ARM_V7S_TEX_SHIFT)) == 0) 291 if ((attr & (ARM_V7S_TEX_MASK << ARM_V7S_TEX_SHIFT)) == 0)
292 prot |= IOMMU_MMIO; 292 prot |= IOMMU_MMIO;
293 else if (pte & ARM_V7S_ATTR_C) 293 else if (pte & ARM_V7S_ATTR_C)
294 prot |= IOMMU_CACHE; 294 prot |= IOMMU_CACHE;
295 if (pte & ARM_V7S_ATTR_XN(lvl))
296 prot |= IOMMU_NOEXEC;
295 297
296 return prot; 298 return prot;
297} 299}
diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h
index 9ed0a8462ccf..3dab13b4a211 100644
--- a/drivers/iommu/mtk_iommu.h
+++ b/drivers/iommu/mtk_iommu.h
@@ -55,19 +55,19 @@ struct mtk_iommu_data {
55 bool enable_4GB; 55 bool enable_4GB;
56}; 56};
57 57
58static int compare_of(struct device *dev, void *data) 58static inline int compare_of(struct device *dev, void *data)
59{ 59{
60 return dev->of_node == data; 60 return dev->of_node == data;
61} 61}
62 62
63static int mtk_iommu_bind(struct device *dev) 63static inline int mtk_iommu_bind(struct device *dev)
64{ 64{
65 struct mtk_iommu_data *data = dev_get_drvdata(dev); 65 struct mtk_iommu_data *data = dev_get_drvdata(dev);
66 66
67 return component_bind_all(dev, &data->smi_imu); 67 return component_bind_all(dev, &data->smi_imu);
68} 68}
69 69
70static void mtk_iommu_unbind(struct device *dev) 70static inline void mtk_iommu_unbind(struct device *dev)
71{ 71{
72 struct mtk_iommu_data *data = dev_get_drvdata(dev); 72 struct mtk_iommu_data *data = dev_get_drvdata(dev);
73 73
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 7ceaba81efb4..36b9c28a5c91 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1545,7 +1545,12 @@ static int its_force_quiescent(void __iomem *base)
1545 u32 val; 1545 u32 val;
1546 1546
1547 val = readl_relaxed(base + GITS_CTLR); 1547 val = readl_relaxed(base + GITS_CTLR);
1548 if (val & GITS_CTLR_QUIESCENT) 1548 /*
1549 * GIC architecture specification requires the ITS to be both
1550 * disabled and quiescent for writes to GITS_BASER<n> or
1551 * GITS_CBASER to not have UNPREDICTABLE results.
1552 */
1553 if ((val & GITS_CTLR_QUIESCENT) && !(val & GITS_CTLR_ENABLE))
1549 return 0; 1554 return 0;
1550 1555
1551 /* Disable the generation of all interrupts to this ITS */ 1556 /* Disable the generation of all interrupts to this ITS */
diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index 6fc56c3466b0..ede5672ab34d 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -667,13 +667,20 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
667#endif 667#endif
668 668
669#ifdef CONFIG_CPU_PM 669#ifdef CONFIG_CPU_PM
670/* Check whether it's single security state view */
671static bool gic_dist_security_disabled(void)
672{
673 return readl_relaxed(gic_data.dist_base + GICD_CTLR) & GICD_CTLR_DS;
674}
675
670static int gic_cpu_pm_notifier(struct notifier_block *self, 676static int gic_cpu_pm_notifier(struct notifier_block *self,
671 unsigned long cmd, void *v) 677 unsigned long cmd, void *v)
672{ 678{
673 if (cmd == CPU_PM_EXIT) { 679 if (cmd == CPU_PM_EXIT) {
674 gic_enable_redist(true); 680 if (gic_dist_security_disabled())
681 gic_enable_redist(true);
675 gic_cpu_sys_reg_init(); 682 gic_cpu_sys_reg_init();
676 } else if (cmd == CPU_PM_ENTER) { 683 } else if (cmd == CPU_PM_ENTER && gic_dist_security_disabled()) {
677 gic_write_grpen1(0); 684 gic_write_grpen1(0);
678 gic_enable_redist(false); 685 gic_enable_redist(false);
679 } 686 }
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index c2cab572c511..390fac59c6bc 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -769,6 +769,13 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
769 int cpu; 769 int cpu;
770 unsigned long flags, map = 0; 770 unsigned long flags, map = 0;
771 771
772 if (unlikely(nr_cpu_ids == 1)) {
773 /* Only one CPU? let's do a self-IPI... */
774 writel_relaxed(2 << 24 | irq,
775 gic_data_dist_base(&gic_data[0]) + GIC_DIST_SOFTINT);
776 return;
777 }
778
772 raw_spin_lock_irqsave(&irq_controller_lock, flags); 779 raw_spin_lock_irqsave(&irq_controller_lock, flags);
773 780
774 /* Convert our logical CPU mask into a physical one. */ 781 /* Convert our logical CPU mask into a physical one. */
diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index c5f33c3bd228..83f498393a7f 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -713,9 +713,6 @@ static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,
713 unsigned long flags; 713 unsigned long flags;
714 int i; 714 int i;
715 715
716 irq_set_chip_and_handler(virq, &gic_level_irq_controller,
717 handle_level_irq);
718
719 spin_lock_irqsave(&gic_lock, flags); 716 spin_lock_irqsave(&gic_lock, flags);
720 gic_map_to_pin(intr, gic_cpu_pin); 717 gic_map_to_pin(intr, gic_cpu_pin);
721 gic_map_to_vpe(intr, mips_cm_vp_id(vpe)); 718 gic_map_to_vpe(intr, mips_cm_vp_id(vpe));
@@ -732,6 +729,10 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
732{ 729{
733 if (GIC_HWIRQ_TO_LOCAL(hw) < GIC_NUM_LOCAL_INTRS) 730 if (GIC_HWIRQ_TO_LOCAL(hw) < GIC_NUM_LOCAL_INTRS)
734 return gic_local_irq_domain_map(d, virq, hw); 731 return gic_local_irq_domain_map(d, virq, hw);
732
733 irq_set_chip_and_handler(virq, &gic_level_irq_controller,
734 handle_level_irq);
735
735 return gic_shared_irq_domain_map(d, virq, hw, 0); 736 return gic_shared_irq_domain_map(d, virq, hw, 0);
736} 737}
737 738
@@ -771,11 +772,13 @@ static int gic_irq_domain_alloc(struct irq_domain *d, unsigned int virq,
771 hwirq = GIC_SHARED_TO_HWIRQ(base_hwirq + i); 772 hwirq = GIC_SHARED_TO_HWIRQ(base_hwirq + i);
772 773
773 ret = irq_domain_set_hwirq_and_chip(d, virq + i, hwirq, 774 ret = irq_domain_set_hwirq_and_chip(d, virq + i, hwirq,
774 &gic_edge_irq_controller, 775 &gic_level_irq_controller,
775 NULL); 776 NULL);
776 if (ret) 777 if (ret)
777 goto error; 778 goto error;
778 779
780 irq_set_handler(virq + i, handle_level_irq);
781
779 ret = gic_shared_irq_domain_map(d, virq + i, hwirq, cpu); 782 ret = gic_shared_irq_domain_map(d, virq + i, hwirq, cpu);
780 if (ret) 783 if (ret)
781 goto error; 784 goto error;
@@ -890,10 +893,17 @@ void gic_dev_domain_free(struct irq_domain *d, unsigned int virq,
890 return; 893 return;
891} 894}
892 895
896static void gic_dev_domain_activate(struct irq_domain *domain,
897 struct irq_data *d)
898{
899 gic_shared_irq_domain_map(domain, d->irq, d->hwirq, 0);
900}
901
893static struct irq_domain_ops gic_dev_domain_ops = { 902static struct irq_domain_ops gic_dev_domain_ops = {
894 .xlate = gic_dev_domain_xlate, 903 .xlate = gic_dev_domain_xlate,
895 .alloc = gic_dev_domain_alloc, 904 .alloc = gic_dev_domain_alloc,
896 .free = gic_dev_domain_free, 905 .free = gic_dev_domain_free,
906 .activate = gic_dev_domain_activate,
897}; 907};
898 908
899static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr, 909static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 95a4ca6ce6ff..849ad441cd76 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -760,7 +760,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
760 if (!d->nr_stripes || 760 if (!d->nr_stripes ||
761 d->nr_stripes > INT_MAX || 761 d->nr_stripes > INT_MAX ||
762 d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) { 762 d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
763 pr_err("nr_stripes too large"); 763 pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)",
764 (unsigned)d->nr_stripes);
764 return -ENOMEM; 765 return -ENOMEM;
765 } 766 }
766 767
@@ -1820,7 +1821,7 @@ static int cache_alloc(struct cache *ca)
1820 free = roundup_pow_of_two(ca->sb.nbuckets) >> 10; 1821 free = roundup_pow_of_two(ca->sb.nbuckets) >> 10;
1821 1822
1822 if (!init_fifo(&ca->free[RESERVE_BTREE], 8, GFP_KERNEL) || 1823 if (!init_fifo(&ca->free[RESERVE_BTREE], 8, GFP_KERNEL) ||
1823 !init_fifo(&ca->free[RESERVE_PRIO], prio_buckets(ca), GFP_KERNEL) || 1824 !init_fifo_exact(&ca->free[RESERVE_PRIO], prio_buckets(ca), GFP_KERNEL) ||
1824 !init_fifo(&ca->free[RESERVE_MOVINGGC], free, GFP_KERNEL) || 1825 !init_fifo(&ca->free[RESERVE_MOVINGGC], free, GFP_KERNEL) ||
1825 !init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL) || 1826 !init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL) ||
1826 !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) || 1827 !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) ||
@@ -1844,7 +1845,7 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
1844 struct block_device *bdev, struct cache *ca) 1845 struct block_device *bdev, struct cache *ca)
1845{ 1846{
1846 char name[BDEVNAME_SIZE]; 1847 char name[BDEVNAME_SIZE];
1847 const char *err = NULL; 1848 const char *err = NULL; /* must be set for any error case */
1848 int ret = 0; 1849 int ret = 0;
1849 1850
1850 memcpy(&ca->sb, sb, sizeof(struct cache_sb)); 1851 memcpy(&ca->sb, sb, sizeof(struct cache_sb));
@@ -1861,8 +1862,13 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
1861 ca->discard = CACHE_DISCARD(&ca->sb); 1862 ca->discard = CACHE_DISCARD(&ca->sb);
1862 1863
1863 ret = cache_alloc(ca); 1864 ret = cache_alloc(ca);
1864 if (ret != 0) 1865 if (ret != 0) {
1866 if (ret == -ENOMEM)
1867 err = "cache_alloc(): -ENOMEM";
1868 else
1869 err = "cache_alloc(): unknown error";
1865 goto err; 1870 goto err;
1871 }
1866 1872
1867 if (kobject_add(&ca->kobj, &part_to_dev(bdev->bd_part)->kobj, "bcache")) { 1873 if (kobject_add(&ca->kobj, &part_to_dev(bdev->bd_part)->kobj, "bcache")) {
1868 err = "error calling kobject_add"; 1874 err = "error calling kobject_add";
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 4e9784b4e0ac..eedba67b0e3e 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -181,7 +181,7 @@ struct crypt_config {
181 u8 key[0]; 181 u8 key[0];
182}; 182};
183 183
184#define MIN_IOS 16 184#define MIN_IOS 64
185 185
186static void clone_init(struct dm_crypt_io *, struct bio *); 186static void clone_init(struct dm_crypt_io *, struct bio *);
187static void kcryptd_queue_crypt(struct dm_crypt_io *io); 187static void kcryptd_queue_crypt(struct dm_crypt_io *io);
diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c
index 97e446d54a15..6a2e8dd44a1b 100644
--- a/drivers/md/dm-flakey.c
+++ b/drivers/md/dm-flakey.c
@@ -289,15 +289,13 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
289 pb->bio_submitted = true; 289 pb->bio_submitted = true;
290 290
291 /* 291 /*
292 * Map reads as normal only if corrupt_bio_byte set. 292 * Error reads if neither corrupt_bio_byte or drop_writes are set.
293 * Otherwise, flakey_end_io() will decide if the reads should be modified.
293 */ 294 */
294 if (bio_data_dir(bio) == READ) { 295 if (bio_data_dir(bio) == READ) {
295 /* If flags were specified, only corrupt those that match. */ 296 if (!fc->corrupt_bio_byte && !test_bit(DROP_WRITES, &fc->flags))
296 if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) &&
297 all_corrupt_bio_flags_match(bio, fc))
298 goto map_bio;
299 else
300 return -EIO; 297 return -EIO;
298 goto map_bio;
301 } 299 }
302 300
303 /* 301 /*
@@ -334,14 +332,21 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio, int error)
334 struct flakey_c *fc = ti->private; 332 struct flakey_c *fc = ti->private;
335 struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data)); 333 struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));
336 334
337 /*
338 * Corrupt successful READs while in down state.
339 */
340 if (!error && pb->bio_submitted && (bio_data_dir(bio) == READ)) { 335 if (!error && pb->bio_submitted && (bio_data_dir(bio) == READ)) {
341 if (fc->corrupt_bio_byte) 336 if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) &&
337 all_corrupt_bio_flags_match(bio, fc)) {
338 /*
339 * Corrupt successful matching READs while in down state.
340 */
342 corrupt_bio_data(bio, fc); 341 corrupt_bio_data(bio, fc);
343 else 342
343 } else if (!test_bit(DROP_WRITES, &fc->flags)) {
344 /*
345 * Error read during the down_interval if drop_writes
346 * wasn't configured.
347 */
344 return -EIO; 348 return -EIO;
349 }
345 } 350 }
346 351
347 return error; 352 return error;
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 4ca2d1df5b44..07fc1ad42ec5 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -291,9 +291,10 @@ static void header_from_disk(struct log_header_core *core, struct log_header_dis
291 core->nr_regions = le64_to_cpu(disk->nr_regions); 291 core->nr_regions = le64_to_cpu(disk->nr_regions);
292} 292}
293 293
294static int rw_header(struct log_c *lc, int rw) 294static int rw_header(struct log_c *lc, int op)
295{ 295{
296 lc->io_req.bi_op = rw; 296 lc->io_req.bi_op = op;
297 lc->io_req.bi_op_flags = 0;
297 298
298 return dm_io(&lc->io_req, 1, &lc->header_location, NULL); 299 return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
299} 300}
@@ -316,7 +317,7 @@ static int read_header(struct log_c *log)
316{ 317{
317 int r; 318 int r;
318 319
319 r = rw_header(log, READ); 320 r = rw_header(log, REQ_OP_READ);
320 if (r) 321 if (r)
321 return r; 322 return r;
322 323
@@ -630,7 +631,7 @@ static int disk_resume(struct dm_dirty_log *log)
630 header_to_disk(&lc->header, lc->disk_header); 631 header_to_disk(&lc->header, lc->disk_header);
631 632
632 /* write the new header */ 633 /* write the new header */
633 r = rw_header(lc, WRITE); 634 r = rw_header(lc, REQ_OP_WRITE);
634 if (!r) { 635 if (!r) {
635 r = flush_header(lc); 636 r = flush_header(lc);
636 if (r) 637 if (r)
@@ -698,7 +699,7 @@ static int disk_flush(struct dm_dirty_log *log)
698 log_clear_bit(lc, lc->clean_bits, i); 699 log_clear_bit(lc, lc->clean_bits, i);
699 } 700 }
700 701
701 r = rw_header(lc, WRITE); 702 r = rw_header(lc, REQ_OP_WRITE);
702 if (r) 703 if (r)
703 fail_log_device(lc); 704 fail_log_device(lc);
704 else { 705 else {
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 1b9795d75ef8..8abde6b8cedc 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -191,7 +191,6 @@ struct raid_dev {
191#define RT_FLAG_RS_BITMAP_LOADED 2 191#define RT_FLAG_RS_BITMAP_LOADED 2
192#define RT_FLAG_UPDATE_SBS 3 192#define RT_FLAG_UPDATE_SBS 3
193#define RT_FLAG_RESHAPE_RS 4 193#define RT_FLAG_RESHAPE_RS 4
194#define RT_FLAG_KEEP_RS_FROZEN 5
195 194
196/* Array elements of 64 bit needed for rebuild/failed disk bits */ 195/* Array elements of 64 bit needed for rebuild/failed disk bits */
197#define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8) 196#define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8)
@@ -861,6 +860,9 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
861{ 860{
862 unsigned long min_region_size = rs->ti->len / (1 << 21); 861 unsigned long min_region_size = rs->ti->len / (1 << 21);
863 862
863 if (rs_is_raid0(rs))
864 return 0;
865
864 if (!region_size) { 866 if (!region_size) {
865 /* 867 /*
866 * Choose a reasonable default. All figures in sectors. 868 * Choose a reasonable default. All figures in sectors.
@@ -930,6 +932,8 @@ static int validate_raid_redundancy(struct raid_set *rs)
930 rebuild_cnt++; 932 rebuild_cnt++;
931 933
932 switch (rs->raid_type->level) { 934 switch (rs->raid_type->level) {
935 case 0:
936 break;
933 case 1: 937 case 1:
934 if (rebuild_cnt >= rs->md.raid_disks) 938 if (rebuild_cnt >= rs->md.raid_disks)
935 goto too_many; 939 goto too_many;
@@ -2335,6 +2339,13 @@ static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs)
2335 case 0: 2339 case 0:
2336 break; 2340 break;
2337 default: 2341 default:
2342 /*
2343 * We have to keep any raid0 data/metadata device pairs or
2344 * the MD raid0 personality will fail to start the array.
2345 */
2346 if (rs_is_raid0(rs))
2347 continue;
2348
2338 dev = container_of(rdev, struct raid_dev, rdev); 2349 dev = container_of(rdev, struct raid_dev, rdev);
2339 if (dev->meta_dev) 2350 if (dev->meta_dev)
2340 dm_put_device(ti, dev->meta_dev); 2351 dm_put_device(ti, dev->meta_dev);
@@ -2579,7 +2590,6 @@ static int rs_prepare_reshape(struct raid_set *rs)
2579 } else { 2590 } else {
2580 /* Process raid1 without delta_disks */ 2591 /* Process raid1 without delta_disks */
2581 mddev->raid_disks = rs->raid_disks; 2592 mddev->raid_disks = rs->raid_disks;
2582 set_bit(RT_FLAG_KEEP_RS_FROZEN, &rs->runtime_flags);
2583 reshape = false; 2593 reshape = false;
2584 } 2594 }
2585 } else { 2595 } else {
@@ -2590,7 +2600,6 @@ static int rs_prepare_reshape(struct raid_set *rs)
2590 if (reshape) { 2600 if (reshape) {
2591 set_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags); 2601 set_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags);
2592 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); 2602 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags);
2593 set_bit(RT_FLAG_KEEP_RS_FROZEN, &rs->runtime_flags);
2594 } else if (mddev->raid_disks < rs->raid_disks) 2603 } else if (mddev->raid_disks < rs->raid_disks)
2595 /* Create new superblocks and bitmaps, if any new disks */ 2604 /* Create new superblocks and bitmaps, if any new disks */
2596 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); 2605 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags);
@@ -2902,7 +2911,6 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
2902 goto bad; 2911 goto bad;
2903 2912
2904 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); 2913 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags);
2905 set_bit(RT_FLAG_KEEP_RS_FROZEN, &rs->runtime_flags);
2906 /* Takeover ain't recovery, so disable recovery */ 2914 /* Takeover ain't recovery, so disable recovery */
2907 rs_setup_recovery(rs, MaxSector); 2915 rs_setup_recovery(rs, MaxSector);
2908 rs_set_new(rs); 2916 rs_set_new(rs);
@@ -3386,21 +3394,28 @@ static void raid_postsuspend(struct dm_target *ti)
3386{ 3394{
3387 struct raid_set *rs = ti->private; 3395 struct raid_set *rs = ti->private;
3388 3396
3389 if (test_and_clear_bit(RT_FLAG_RS_RESUMED, &rs->runtime_flags)) { 3397 if (!rs->md.suspended)
3390 if (!rs->md.suspended) 3398 mddev_suspend(&rs->md);
3391 mddev_suspend(&rs->md); 3399
3392 rs->md.ro = 1; 3400 rs->md.ro = 1;
3393 }
3394} 3401}
3395 3402
3396static void attempt_restore_of_faulty_devices(struct raid_set *rs) 3403static void attempt_restore_of_faulty_devices(struct raid_set *rs)
3397{ 3404{
3398 int i; 3405 int i;
3399 uint64_t failed_devices, cleared_failed_devices = 0; 3406 uint64_t cleared_failed_devices[DISKS_ARRAY_ELEMS];
3400 unsigned long flags; 3407 unsigned long flags;
3408 bool cleared = false;
3401 struct dm_raid_superblock *sb; 3409 struct dm_raid_superblock *sb;
3410 struct mddev *mddev = &rs->md;
3402 struct md_rdev *r; 3411 struct md_rdev *r;
3403 3412
3413 /* RAID personalities have to provide hot add/remove methods or we need to bail out. */
3414 if (!mddev->pers || !mddev->pers->hot_add_disk || !mddev->pers->hot_remove_disk)
3415 return;
3416
3417 memset(cleared_failed_devices, 0, sizeof(cleared_failed_devices));
3418
3404 for (i = 0; i < rs->md.raid_disks; i++) { 3419 for (i = 0; i < rs->md.raid_disks; i++) {
3405 r = &rs->dev[i].rdev; 3420 r = &rs->dev[i].rdev;
3406 if (test_bit(Faulty, &r->flags) && r->sb_page && 3421 if (test_bit(Faulty, &r->flags) && r->sb_page &&
@@ -3420,7 +3435,7 @@ static void attempt_restore_of_faulty_devices(struct raid_set *rs)
3420 * ourselves. 3435 * ourselves.
3421 */ 3436 */
3422 if ((r->raid_disk >= 0) && 3437 if ((r->raid_disk >= 0) &&
3423 (r->mddev->pers->hot_remove_disk(r->mddev, r) != 0)) 3438 (mddev->pers->hot_remove_disk(mddev, r) != 0))
3424 /* Failed to revive this device, try next */ 3439 /* Failed to revive this device, try next */
3425 continue; 3440 continue;
3426 3441
@@ -3430,22 +3445,30 @@ static void attempt_restore_of_faulty_devices(struct raid_set *rs)
3430 clear_bit(Faulty, &r->flags); 3445 clear_bit(Faulty, &r->flags);
3431 clear_bit(WriteErrorSeen, &r->flags); 3446 clear_bit(WriteErrorSeen, &r->flags);
3432 clear_bit(In_sync, &r->flags); 3447 clear_bit(In_sync, &r->flags);
3433 if (r->mddev->pers->hot_add_disk(r->mddev, r)) { 3448 if (mddev->pers->hot_add_disk(mddev, r)) {
3434 r->raid_disk = -1; 3449 r->raid_disk = -1;
3435 r->saved_raid_disk = -1; 3450 r->saved_raid_disk = -1;
3436 r->flags = flags; 3451 r->flags = flags;
3437 } else { 3452 } else {
3438 r->recovery_offset = 0; 3453 r->recovery_offset = 0;
3439 cleared_failed_devices |= 1 << i; 3454 set_bit(i, (void *) cleared_failed_devices);
3455 cleared = true;
3440 } 3456 }
3441 } 3457 }
3442 } 3458 }
3443 if (cleared_failed_devices) { 3459
3460 /* If any failed devices could be cleared, update all sbs failed_devices bits */
3461 if (cleared) {
3462 uint64_t failed_devices[DISKS_ARRAY_ELEMS];
3463
3444 rdev_for_each(r, &rs->md) { 3464 rdev_for_each(r, &rs->md) {
3445 sb = page_address(r->sb_page); 3465 sb = page_address(r->sb_page);
3446 failed_devices = le64_to_cpu(sb->failed_devices); 3466 sb_retrieve_failed_devices(sb, failed_devices);
3447 failed_devices &= ~cleared_failed_devices; 3467
3448 sb->failed_devices = cpu_to_le64(failed_devices); 3468 for (i = 0; i < DISKS_ARRAY_ELEMS; i++)
3469 failed_devices[i] &= ~cleared_failed_devices[i];
3470
3471 sb_update_failed_devices(sb, failed_devices);
3449 } 3472 }
3450 } 3473 }
3451} 3474}
@@ -3610,26 +3633,15 @@ static void raid_resume(struct dm_target *ti)
3610 * devices are reachable again. 3633 * devices are reachable again.
3611 */ 3634 */
3612 attempt_restore_of_faulty_devices(rs); 3635 attempt_restore_of_faulty_devices(rs);
3613 } else { 3636 }
3614 mddev->ro = 0;
3615 mddev->in_sync = 0;
3616 3637
3617 /* 3638 mddev->ro = 0;
3618 * When passing in flags to the ctr, we expect userspace 3639 mddev->in_sync = 0;
3619 * to reset them because they made it to the superblocks
3620 * and reload the mapping anyway.
3621 *
3622 * -> only unfreeze recovery in case of a table reload or
3623 * we'll have a bogus recovery/reshape position
3624 * retrieved from the superblock by the ctr because
3625 * the ongoing recovery/reshape will change it after read.
3626 */
3627 if (!test_bit(RT_FLAG_KEEP_RS_FROZEN, &rs->runtime_flags))
3628 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
3629 3640
3630 if (mddev->suspended) 3641 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
3631 mddev_resume(mddev); 3642
3632 } 3643 if (mddev->suspended)
3644 mddev_resume(mddev);
3633} 3645}
3634 3646
3635static struct target_type raid_target = { 3647static struct target_type raid_target = {
diff --git a/drivers/md/dm-round-robin.c b/drivers/md/dm-round-robin.c
index 4ace1da17db8..6c25213ab38c 100644
--- a/drivers/md/dm-round-robin.c
+++ b/drivers/md/dm-round-robin.c
@@ -210,14 +210,17 @@ static struct dm_path *rr_select_path(struct path_selector *ps, size_t nr_bytes)
210 struct path_info *pi = NULL; 210 struct path_info *pi = NULL;
211 struct dm_path *current_path = NULL; 211 struct dm_path *current_path = NULL;
212 212
213 local_irq_save(flags);
213 current_path = *this_cpu_ptr(s->current_path); 214 current_path = *this_cpu_ptr(s->current_path);
214 if (current_path) { 215 if (current_path) {
215 percpu_counter_dec(&s->repeat_count); 216 percpu_counter_dec(&s->repeat_count);
216 if (percpu_counter_read_positive(&s->repeat_count) > 0) 217 if (percpu_counter_read_positive(&s->repeat_count) > 0) {
218 local_irq_restore(flags);
217 return current_path; 219 return current_path;
220 }
218 } 221 }
219 222
220 spin_lock_irqsave(&s->lock, flags); 223 spin_lock(&s->lock);
221 if (!list_empty(&s->valid_paths)) { 224 if (!list_empty(&s->valid_paths)) {
222 pi = list_entry(s->valid_paths.next, struct path_info, list); 225 pi = list_entry(s->valid_paths.next, struct path_info, list);
223 list_move_tail(&pi->list, &s->valid_paths); 226 list_move_tail(&pi->list, &s->valid_paths);
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index bdee9a01ef35..c466ee2b0c97 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -90,8 +90,7 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
90 */ 90 */
91 mutex_lock(&afu->contexts_lock); 91 mutex_lock(&afu->contexts_lock);
92 idr_preload(GFP_KERNEL); 92 idr_preload(GFP_KERNEL);
93 i = idr_alloc(&ctx->afu->contexts_idr, ctx, 93 i = idr_alloc(&ctx->afu->contexts_idr, ctx, ctx->afu->adapter->min_pe,
94 ctx->afu->adapter->native->sl_ops->min_pe,
95 ctx->afu->num_procs, GFP_NOWAIT); 94 ctx->afu->num_procs, GFP_NOWAIT);
96 idr_preload_end(); 95 idr_preload_end();
97 mutex_unlock(&afu->contexts_lock); 96 mutex_unlock(&afu->contexts_lock);
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index de090533f18c..344a0ff8f8c7 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -561,7 +561,6 @@ struct cxl_service_layer_ops {
561 u64 (*timebase_read)(struct cxl *adapter); 561 u64 (*timebase_read)(struct cxl *adapter);
562 int capi_mode; 562 int capi_mode;
563 bool needs_reset_before_disable; 563 bool needs_reset_before_disable;
564 int min_pe;
565}; 564};
566 565
567struct cxl_native { 566struct cxl_native {
@@ -603,6 +602,7 @@ struct cxl {
603 struct bin_attribute cxl_attr; 602 struct bin_attribute cxl_attr;
604 int adapter_num; 603 int adapter_num;
605 int user_irqs; 604 int user_irqs;
605 int min_pe;
606 u64 ps_size; 606 u64 ps_size;
607 u16 psl_rev; 607 u16 psl_rev;
608 u16 base_image; 608 u16 base_image;
diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c
index 3bcdaee11ba1..e606fdc4bc9c 100644
--- a/drivers/misc/cxl/native.c
+++ b/drivers/misc/cxl/native.c
@@ -924,7 +924,7 @@ static irqreturn_t native_irq_multiplexed(int irq, void *data)
924 return fail_psl_irq(afu, &irq_info); 924 return fail_psl_irq(afu, &irq_info);
925} 925}
926 926
927void native_irq_wait(struct cxl_context *ctx) 927static void native_irq_wait(struct cxl_context *ctx)
928{ 928{
929 u64 dsisr; 929 u64 dsisr;
930 int timeout = 1000; 930 int timeout = 1000;
diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index d152e2de8c93..6f0c4ac4b649 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -379,7 +379,7 @@ static int calc_capp_routing(struct pci_dev *dev, u64 *chipid, u64 *capp_unit_id
379 379
380static int init_implementation_adapter_psl_regs(struct cxl *adapter, struct pci_dev *dev) 380static int init_implementation_adapter_psl_regs(struct cxl *adapter, struct pci_dev *dev)
381{ 381{
382 u64 psl_dsnctl; 382 u64 psl_dsnctl, psl_fircntl;
383 u64 chipid; 383 u64 chipid;
384 u64 capp_unit_id; 384 u64 capp_unit_id;
385 int rc; 385 int rc;
@@ -398,8 +398,11 @@ static int init_implementation_adapter_psl_regs(struct cxl *adapter, struct pci_
398 cxl_p1_write(adapter, CXL_PSL_RESLCKTO, 0x20000000200ULL); 398 cxl_p1_write(adapter, CXL_PSL_RESLCKTO, 0x20000000200ULL);
399 /* snoop write mask */ 399 /* snoop write mask */
400 cxl_p1_write(adapter, CXL_PSL_SNWRALLOC, 0x00000000FFFFFFFFULL); 400 cxl_p1_write(adapter, CXL_PSL_SNWRALLOC, 0x00000000FFFFFFFFULL);
401 /* set fir_accum */ 401 /* set fir_cntl to recommended value for production env */
402 cxl_p1_write(adapter, CXL_PSL_FIR_CNTL, 0x0800000000000000ULL); 402 psl_fircntl = (0x2ULL << (63-3)); /* ce_report */
403 psl_fircntl |= (0x1ULL << (63-6)); /* FIR_report */
404 psl_fircntl |= 0x1ULL; /* ce_thresh */
405 cxl_p1_write(adapter, CXL_PSL_FIR_CNTL, psl_fircntl);
403 /* for debugging with trace arrays */ 406 /* for debugging with trace arrays */
404 cxl_p1_write(adapter, CXL_PSL_TRACE, 0x0000FF7C00000000ULL); 407 cxl_p1_write(adapter, CXL_PSL_TRACE, 0x0000FF7C00000000ULL);
405 408
@@ -1521,14 +1524,15 @@ static const struct cxl_service_layer_ops xsl_ops = {
1521 .write_timebase_ctrl = write_timebase_ctrl_xsl, 1524 .write_timebase_ctrl = write_timebase_ctrl_xsl,
1522 .timebase_read = timebase_read_xsl, 1525 .timebase_read = timebase_read_xsl,
1523 .capi_mode = OPAL_PHB_CAPI_MODE_DMA, 1526 .capi_mode = OPAL_PHB_CAPI_MODE_DMA,
1524 .min_pe = 1, /* Workaround for Mellanox CX4 HW bug */
1525}; 1527};
1526 1528
1527static void set_sl_ops(struct cxl *adapter, struct pci_dev *dev) 1529static void set_sl_ops(struct cxl *adapter, struct pci_dev *dev)
1528{ 1530{
1529 if (dev->vendor == PCI_VENDOR_ID_MELLANOX && dev->device == 0x1013) { 1531 if (dev->vendor == PCI_VENDOR_ID_MELLANOX && dev->device == 0x1013) {
1532 /* Mellanox CX-4 */
1530 dev_info(&adapter->dev, "Device uses an XSL\n"); 1533 dev_info(&adapter->dev, "Device uses an XSL\n");
1531 adapter->native->sl_ops = &xsl_ops; 1534 adapter->native->sl_ops = &xsl_ops;
1535 adapter->min_pe = 1; /* Workaround for CX-4 hardware bug */
1532 } else { 1536 } else {
1533 dev_info(&adapter->dev, "Device uses a PSL\n"); 1537 dev_info(&adapter->dev, "Device uses a PSL\n");
1534 adapter->native->sl_ops = &psl_ops; 1538 adapter->native->sl_ops = &psl_ops;
diff --git a/drivers/misc/cxl/vphb.c b/drivers/misc/cxl/vphb.c
index dee8def1c193..7ada5f1b7bb6 100644
--- a/drivers/misc/cxl/vphb.c
+++ b/drivers/misc/cxl/vphb.c
@@ -221,7 +221,7 @@ int cxl_pci_vphb_add(struct cxl_afu *afu)
221 /* Setup the PHB using arch provided callback */ 221 /* Setup the PHB using arch provided callback */
222 phb->ops = &cxl_pcie_pci_ops; 222 phb->ops = &cxl_pcie_pci_ops;
223 phb->cfg_addr = NULL; 223 phb->cfg_addr = NULL;
224 phb->cfg_data = 0; 224 phb->cfg_data = NULL;
225 phb->private_data = afu; 225 phb->private_data = afu;
226 phb->controller_ops = cxl_pci_controller_ops; 226 phb->controller_ops = cxl_pci_controller_ops;
227 227
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 48a5dd740f3b..2206d4477dbb 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -1726,6 +1726,7 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
1726 break; 1726 break;
1727 1727
1728 if (req_op(next) == REQ_OP_DISCARD || 1728 if (req_op(next) == REQ_OP_DISCARD ||
1729 req_op(next) == REQ_OP_SECURE_ERASE ||
1729 req_op(next) == REQ_OP_FLUSH) 1730 req_op(next) == REQ_OP_FLUSH)
1730 break; 1731 break;
1731 1732
@@ -2150,6 +2151,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
2150 struct mmc_card *card = md->queue.card; 2151 struct mmc_card *card = md->queue.card;
2151 struct mmc_host *host = card->host; 2152 struct mmc_host *host = card->host;
2152 unsigned long flags; 2153 unsigned long flags;
2154 bool req_is_special = mmc_req_is_special(req);
2153 2155
2154 if (req && !mq->mqrq_prev->req) 2156 if (req && !mq->mqrq_prev->req)
2155 /* claim host only for the first request */ 2157 /* claim host only for the first request */
@@ -2190,8 +2192,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
2190 } 2192 }
2191 2193
2192out: 2194out:
2193 if ((!req && !(mq->flags & MMC_QUEUE_NEW_REQUEST)) || 2195 if ((!req && !(mq->flags & MMC_QUEUE_NEW_REQUEST)) || req_is_special)
2194 mmc_req_is_special(req))
2195 /* 2196 /*
2196 * Release host when there are no more requests 2197 * Release host when there are no more requests
2197 * and after special request(discard, flush) is done. 2198 * and after special request(discard, flush) is done.
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index bf14642a576a..708057261b38 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -33,7 +33,8 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
33 /* 33 /*
34 * We only like normal block requests and discards. 34 * We only like normal block requests and discards.
35 */ 35 */
36 if (req->cmd_type != REQ_TYPE_FS && req_op(req) != REQ_OP_DISCARD) { 36 if (req->cmd_type != REQ_TYPE_FS && req_op(req) != REQ_OP_DISCARD &&
37 req_op(req) != REQ_OP_SECURE_ERASE) {
37 blk_dump_rq_flags(req, "MMC bad request"); 38 blk_dump_rq_flags(req, "MMC bad request");
38 return BLKPREP_KILL; 39 return BLKPREP_KILL;
39 } 40 }
@@ -64,6 +65,8 @@ static int mmc_queue_thread(void *d)
64 spin_unlock_irq(q->queue_lock); 65 spin_unlock_irq(q->queue_lock);
65 66
66 if (req || mq->mqrq_prev->req) { 67 if (req || mq->mqrq_prev->req) {
68 bool req_is_special = mmc_req_is_special(req);
69
67 set_current_state(TASK_RUNNING); 70 set_current_state(TASK_RUNNING);
68 mq->issue_fn(mq, req); 71 mq->issue_fn(mq, req);
69 cond_resched(); 72 cond_resched();
@@ -79,7 +82,7 @@ static int mmc_queue_thread(void *d)
79 * has been finished. Do not assign it to previous 82 * has been finished. Do not assign it to previous
80 * request. 83 * request.
81 */ 84 */
82 if (mmc_req_is_special(req)) 85 if (req_is_special)
83 mq->mqrq_cur->req = NULL; 86 mq->mqrq_cur->req = NULL;
84 87
85 mq->mqrq_prev->brq.mrq.data = NULL; 88 mq->mqrq_prev->brq.mrq.data = NULL;
diff --git a/drivers/mmc/card/queue.h b/drivers/mmc/card/queue.h
index d62531124d54..fee5e1271465 100644
--- a/drivers/mmc/card/queue.h
+++ b/drivers/mmc/card/queue.h
@@ -4,7 +4,9 @@
4static inline bool mmc_req_is_special(struct request *req) 4static inline bool mmc_req_is_special(struct request *req)
5{ 5{
6 return req && 6 return req &&
7 (req_op(req) == REQ_OP_FLUSH || req_op(req) == REQ_OP_DISCARD); 7 (req_op(req) == REQ_OP_FLUSH ||
8 req_op(req) == REQ_OP_DISCARD ||
9 req_op(req) == REQ_OP_SECURE_ERASE);
8} 10}
9 11
10struct request; 12struct request;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 1f276fa30ba6..217e8da0628c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -152,7 +152,7 @@ module_param(lacp_rate, charp, 0);
152MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner; " 152MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner; "
153 "0 for slow, 1 for fast"); 153 "0 for slow, 1 for fast");
154module_param(ad_select, charp, 0); 154module_param(ad_select, charp, 0);
155MODULE_PARM_DESC(ad_select, "803.ad aggregation selection logic; " 155MODULE_PARM_DESC(ad_select, "802.3ad aggregation selection logic; "
156 "0 for stable (default), 1 for bandwidth, " 156 "0 for stable (default), 1 for bandwidth, "
157 "2 for count"); 157 "2 for count");
158module_param(min_links, int, 0); 158module_param(min_links, int, 0);
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index 8f12bddd5dc9..a0b453ea34c9 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -258,7 +258,7 @@
258 * BCM5325 and BCM5365 share most definitions below 258 * BCM5325 and BCM5365 share most definitions below
259 */ 259 */
260#define B53_ARLTBL_MAC_VID_ENTRY(n) (0x10 * (n)) 260#define B53_ARLTBL_MAC_VID_ENTRY(n) (0x10 * (n))
261#define ARLTBL_MAC_MASK 0xffffffffffff 261#define ARLTBL_MAC_MASK 0xffffffffffffULL
262#define ARLTBL_VID_S 48 262#define ARLTBL_VID_S 48
263#define ARLTBL_VID_MASK_25 0xff 263#define ARLTBL_VID_MASK_25 0xff
264#define ARLTBL_VID_MASK 0xfff 264#define ARLTBL_VID_MASK 0xfff
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index d36aedde8cb9..d1d9d3cf9139 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -3187,6 +3187,7 @@ static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
3187 return err; 3187 return err;
3188} 3188}
3189 3189
3190#ifdef CONFIG_NET_DSA_HWMON
3190static int mv88e6xxx_mdio_page_read(struct dsa_switch *ds, int port, int page, 3191static int mv88e6xxx_mdio_page_read(struct dsa_switch *ds, int port, int page,
3191 int reg) 3192 int reg)
3192{ 3193{
@@ -3212,6 +3213,7 @@ static int mv88e6xxx_mdio_page_write(struct dsa_switch *ds, int port, int page,
3212 3213
3213 return ret; 3214 return ret;
3214} 3215}
3216#endif
3215 3217
3216static int mv88e6xxx_port_to_mdio_addr(struct mv88e6xxx_chip *chip, int port) 3218static int mv88e6xxx_port_to_mdio_addr(struct mv88e6xxx_chip *chip, int port)
3217{ 3219{
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
index 37a0f463b8de..18bb9556dd00 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
@@ -793,6 +793,8 @@ int xgene_enet_phy_connect(struct net_device *ndev)
793 netdev_err(ndev, "Could not connect to PHY\n"); 793 netdev_err(ndev, "Could not connect to PHY\n");
794 return -ENODEV; 794 return -ENODEV;
795 } 795 }
796#else
797 return -ENODEV;
796#endif 798#endif
797 } 799 }
798 800
diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
index 4bff0f3040df..b0da9693f28a 100644
--- a/drivers/net/ethernet/arc/emac_main.c
+++ b/drivers/net/ethernet/arc/emac_main.c
@@ -771,8 +771,10 @@ int arc_emac_probe(struct net_device *ndev, int interface)
771 priv->dev = dev; 771 priv->dev = dev;
772 772
773 priv->regs = devm_ioremap_resource(dev, &res_regs); 773 priv->regs = devm_ioremap_resource(dev, &res_regs);
774 if (IS_ERR(priv->regs)) 774 if (IS_ERR(priv->regs)) {
775 return PTR_ERR(priv->regs); 775 err = PTR_ERR(priv->regs);
776 goto out_put_node;
777 }
776 778
777 dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs); 779 dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs);
778 780
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index ff300f7cf529..659261218d9f 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -12552,10 +12552,6 @@ static int tg3_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
12552 info->data = TG3_RSS_MAX_NUM_QS; 12552 info->data = TG3_RSS_MAX_NUM_QS;
12553 } 12553 }
12554 12554
12555 /* The first interrupt vector only
12556 * handles link interrupts.
12557 */
12558 info->data -= 1;
12559 return 0; 12555 return 0;
12560 12556
12561 default: 12557 default:
@@ -14014,6 +14010,7 @@ static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
14014 } 14010 }
14015 14011
14016 if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || 14012 if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
14013 (!ec->rx_coalesce_usecs) ||
14017 (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || 14014 (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
14018 (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || 14015 (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
14019 (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || 14016 (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index 36893d8958d4..b6fcf10621b6 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -403,11 +403,11 @@
403#define MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII 0x00000004 403#define MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII 0x00000004
404#define MACB_CAPS_NO_GIGABIT_HALF 0x00000008 404#define MACB_CAPS_NO_GIGABIT_HALF 0x00000008
405#define MACB_CAPS_USRIO_DISABLED 0x00000010 405#define MACB_CAPS_USRIO_DISABLED 0x00000010
406#define MACB_CAPS_JUMBO 0x00000020
406#define MACB_CAPS_FIFO_MODE 0x10000000 407#define MACB_CAPS_FIFO_MODE 0x10000000
407#define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000 408#define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000
408#define MACB_CAPS_SG_DISABLED 0x40000000 409#define MACB_CAPS_SG_DISABLED 0x40000000
409#define MACB_CAPS_MACB_IS_GEM 0x80000000 410#define MACB_CAPS_MACB_IS_GEM 0x80000000
410#define MACB_CAPS_JUMBO 0x00000010
411 411
412/* Bit manipulation macros */ 412/* Bit manipulation macros */
413#define MACB_BIT(name) \ 413#define MACB_BIT(name) \
diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c
index 1471e16ba719..f45385f5c6e5 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -1299,6 +1299,7 @@ static int
1299dm9000_open(struct net_device *dev) 1299dm9000_open(struct net_device *dev)
1300{ 1300{
1301 struct board_info *db = netdev_priv(dev); 1301 struct board_info *db = netdev_priv(dev);
1302 unsigned int irq_flags = irq_get_trigger_type(dev->irq);
1302 1303
1303 if (netif_msg_ifup(db)) 1304 if (netif_msg_ifup(db))
1304 dev_dbg(db->dev, "enabling %s\n", dev->name); 1305 dev_dbg(db->dev, "enabling %s\n", dev->name);
@@ -1306,9 +1307,11 @@ dm9000_open(struct net_device *dev)
1306 /* If there is no IRQ type specified, tell the user that this is a 1307 /* If there is no IRQ type specified, tell the user that this is a
1307 * problem 1308 * problem
1308 */ 1309 */
1309 if (irq_get_trigger_type(dev->irq) == IRQF_TRIGGER_NONE) 1310 if (irq_flags == IRQF_TRIGGER_NONE)
1310 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n"); 1311 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
1311 1312
1313 irq_flags |= IRQF_SHARED;
1314
1312 /* GPIO0 on pre-activate PHY, Reg 1F is not set by reset */ 1315 /* GPIO0 on pre-activate PHY, Reg 1F is not set by reset */
1313 iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */ 1316 iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */
1314 mdelay(1); /* delay needs by DM9000B */ 1317 mdelay(1); /* delay needs by DM9000B */
@@ -1316,8 +1319,7 @@ dm9000_open(struct net_device *dev)
1316 /* Initialize DM9000 board */ 1319 /* Initialize DM9000 board */
1317 dm9000_init_dm9000(dev); 1320 dm9000_init_dm9000(dev);
1318 1321
1319 if (request_irq(dev->irq, dm9000_interrupt, IRQF_SHARED, 1322 if (request_irq(dev->irq, dm9000_interrupt, irq_flags, dev->name, dev))
1320 dev->name, dev))
1321 return -EAGAIN; 1323 return -EAGAIN;
1322 /* Now that we have an interrupt handler hooked up we can unmask 1324 /* Now that we have an interrupt handler hooked up we can unmask
1323 * our interrupts 1325 * our interrupts
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 1235c7f2564b..1e1eb92998fb 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -17,7 +17,7 @@ static const struct mac_stats_string g_gmac_stats_string[] = {
17 {"gmac_rx_octets_total_ok", MAC_STATS_FIELD_OFF(rx_good_bytes)}, 17 {"gmac_rx_octets_total_ok", MAC_STATS_FIELD_OFF(rx_good_bytes)},
18 {"gmac_rx_octets_bad", MAC_STATS_FIELD_OFF(rx_bad_bytes)}, 18 {"gmac_rx_octets_bad", MAC_STATS_FIELD_OFF(rx_bad_bytes)},
19 {"gmac_rx_uc_pkts", MAC_STATS_FIELD_OFF(rx_uc_pkts)}, 19 {"gmac_rx_uc_pkts", MAC_STATS_FIELD_OFF(rx_uc_pkts)},
20 {"gamc_rx_mc_pkts", MAC_STATS_FIELD_OFF(rx_mc_pkts)}, 20 {"gmac_rx_mc_pkts", MAC_STATS_FIELD_OFF(rx_mc_pkts)},
21 {"gmac_rx_bc_pkts", MAC_STATS_FIELD_OFF(rx_bc_pkts)}, 21 {"gmac_rx_bc_pkts", MAC_STATS_FIELD_OFF(rx_bc_pkts)},
22 {"gmac_rx_pkts_64octets", MAC_STATS_FIELD_OFF(rx_64bytes)}, 22 {"gmac_rx_pkts_64octets", MAC_STATS_FIELD_OFF(rx_64bytes)},
23 {"gmac_rx_pkts_65to127", MAC_STATS_FIELD_OFF(rx_65to127)}, 23 {"gmac_rx_pkts_65to127", MAC_STATS_FIELD_OFF(rx_65to127)},
diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
index 7fd4d54599e4..6b03c8553e59 100644
--- a/drivers/net/ethernet/intel/e1000e/82571.c
+++ b/drivers/net/ethernet/intel/e1000e/82571.c
@@ -2032,7 +2032,8 @@ const struct e1000_info e1000_82574_info = {
2032 | FLAG2_DISABLE_ASPM_L0S 2032 | FLAG2_DISABLE_ASPM_L0S
2033 | FLAG2_DISABLE_ASPM_L1 2033 | FLAG2_DISABLE_ASPM_L1
2034 | FLAG2_NO_DISABLE_RX 2034 | FLAG2_NO_DISABLE_RX
2035 | FLAG2_DMA_BURST, 2035 | FLAG2_DMA_BURST
2036 | FLAG2_CHECK_SYSTIM_OVERFLOW,
2036 .pba = 32, 2037 .pba = 32,
2037 .max_hw_frame_size = DEFAULT_JUMBO, 2038 .max_hw_frame_size = DEFAULT_JUMBO,
2038 .get_variants = e1000_get_variants_82571, 2039 .get_variants = e1000_get_variants_82571,
@@ -2053,7 +2054,8 @@ const struct e1000_info e1000_82583_info = {
2053 | FLAG_HAS_CTRLEXT_ON_LOAD, 2054 | FLAG_HAS_CTRLEXT_ON_LOAD,
2054 .flags2 = FLAG2_DISABLE_ASPM_L0S 2055 .flags2 = FLAG2_DISABLE_ASPM_L0S
2055 | FLAG2_DISABLE_ASPM_L1 2056 | FLAG2_DISABLE_ASPM_L1
2056 | FLAG2_NO_DISABLE_RX, 2057 | FLAG2_NO_DISABLE_RX
2058 | FLAG2_CHECK_SYSTIM_OVERFLOW,
2057 .pba = 32, 2059 .pba = 32,
2058 .max_hw_frame_size = DEFAULT_JUMBO, 2060 .max_hw_frame_size = DEFAULT_JUMBO,
2059 .get_variants = e1000_get_variants_82571, 2061 .get_variants = e1000_get_variants_82571,
diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
index ef96cd11d6d2..879cca47b021 100644
--- a/drivers/net/ethernet/intel/e1000e/e1000.h
+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
@@ -452,6 +452,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca);
452#define FLAG2_PCIM2PCI_ARBITER_WA BIT(11) 452#define FLAG2_PCIM2PCI_ARBITER_WA BIT(11)
453#define FLAG2_DFLT_CRC_STRIPPING BIT(12) 453#define FLAG2_DFLT_CRC_STRIPPING BIT(12)
454#define FLAG2_CHECK_RX_HWTSTAMP BIT(13) 454#define FLAG2_CHECK_RX_HWTSTAMP BIT(13)
455#define FLAG2_CHECK_SYSTIM_OVERFLOW BIT(14)
455 456
456#define E1000_RX_DESC_PS(R, i) \ 457#define E1000_RX_DESC_PS(R, i) \
457 (&(((union e1000_rx_desc_packet_split *)((R).desc))[i])) 458 (&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethernet/intel/e1000e/ich8lan.c
index 3e11322d8d58..f3aaca743ea3 100644
--- a/drivers/net/ethernet/intel/e1000e/ich8lan.c
+++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c
@@ -5885,7 +5885,8 @@ const struct e1000_info e1000_pch_lpt_info = {
5885 | FLAG_HAS_JUMBO_FRAMES 5885 | FLAG_HAS_JUMBO_FRAMES
5886 | FLAG_APME_IN_WUC, 5886 | FLAG_APME_IN_WUC,
5887 .flags2 = FLAG2_HAS_PHY_STATS 5887 .flags2 = FLAG2_HAS_PHY_STATS
5888 | FLAG2_HAS_EEE, 5888 | FLAG2_HAS_EEE
5889 | FLAG2_CHECK_SYSTIM_OVERFLOW,
5889 .pba = 26, 5890 .pba = 26,
5890 .max_hw_frame_size = 9022, 5891 .max_hw_frame_size = 9022,
5891 .get_variants = e1000_get_variants_ich8lan, 5892 .get_variants = e1000_get_variants_ich8lan,
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index 02f443958f31..7017281ba2dc 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -4303,6 +4303,42 @@ void e1000e_reinit_locked(struct e1000_adapter *adapter)
4303} 4303}
4304 4304
4305/** 4305/**
4306 * e1000e_sanitize_systim - sanitize raw cycle counter reads
4307 * @hw: pointer to the HW structure
4308 * @systim: cycle_t value read, sanitized and returned
4309 *
4310 * Errata for 82574/82583 possible bad bits read from SYSTIMH/L:
4311 * check to see that the time is incrementing at a reasonable
4312 * rate and is a multiple of incvalue.
4313 **/
4314static cycle_t e1000e_sanitize_systim(struct e1000_hw *hw, cycle_t systim)
4315{
4316 u64 time_delta, rem, temp;
4317 cycle_t systim_next;
4318 u32 incvalue;
4319 int i;
4320
4321 incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
4322 for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
4323 /* latch SYSTIMH on read of SYSTIML */
4324 systim_next = (cycle_t)er32(SYSTIML);
4325 systim_next |= (cycle_t)er32(SYSTIMH) << 32;
4326
4327 time_delta = systim_next - systim;
4328 temp = time_delta;
4329 /* VMWare users have seen incvalue of zero, don't div / 0 */
4330 rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
4331
4332 systim = systim_next;
4333
4334 if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0))
4335 break;
4336 }
4337
4338 return systim;
4339}
4340
4341/**
4306 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter) 4342 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4307 * @cc: cyclecounter structure 4343 * @cc: cyclecounter structure
4308 **/ 4344 **/
@@ -4312,7 +4348,7 @@ static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4312 cc); 4348 cc);
4313 struct e1000_hw *hw = &adapter->hw; 4349 struct e1000_hw *hw = &adapter->hw;
4314 u32 systimel, systimeh; 4350 u32 systimel, systimeh;
4315 cycle_t systim, systim_next; 4351 cycle_t systim;
4316 /* SYSTIMH latching upon SYSTIML read does not work well. 4352 /* SYSTIMH latching upon SYSTIML read does not work well.
4317 * This means that if SYSTIML overflows after we read it but before 4353 * This means that if SYSTIML overflows after we read it but before
4318 * we read SYSTIMH, the value of SYSTIMH has been incremented and we 4354 * we read SYSTIMH, the value of SYSTIMH has been incremented and we
@@ -4335,33 +4371,9 @@ static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4335 systim = (cycle_t)systimel; 4371 systim = (cycle_t)systimel;
4336 systim |= (cycle_t)systimeh << 32; 4372 systim |= (cycle_t)systimeh << 32;
4337 4373
4338 if ((hw->mac.type == e1000_82574) || (hw->mac.type == e1000_82583)) { 4374 if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW)
4339 u64 time_delta, rem, temp; 4375 systim = e1000e_sanitize_systim(hw, systim);
4340 u32 incvalue;
4341 int i;
4342
4343 /* errata for 82574/82583 possible bad bits read from SYSTIMH/L
4344 * check to see that the time is incrementing at a reasonable
4345 * rate and is a multiple of incvalue
4346 */
4347 incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
4348 for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
4349 /* latch SYSTIMH on read of SYSTIML */
4350 systim_next = (cycle_t)er32(SYSTIML);
4351 systim_next |= (cycle_t)er32(SYSTIMH) << 32;
4352
4353 time_delta = systim_next - systim;
4354 temp = time_delta;
4355 /* VMWare users have seen incvalue of zero, don't div / 0 */
4356 rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
4357
4358 systim = systim_next;
4359 4376
4360 if ((time_delta < E1000_82574_SYSTIM_EPSILON) &&
4361 (rem == 0))
4362 break;
4363 }
4364 }
4365 return systim; 4377 return systim;
4366} 4378}
4367 4379
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 81c99e1be708..c6ac7a61812f 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -4554,23 +4554,38 @@ static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4554 **/ 4554 **/
4555static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) 4555static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4556{ 4556{
4557 int i, tc_unused = 0;
4557 u8 num_tc = 0; 4558 u8 num_tc = 0;
4558 int i; 4559 u8 ret = 0;
4559 4560
4560 /* Scan the ETS Config Priority Table to find 4561 /* Scan the ETS Config Priority Table to find
4561 * traffic class enabled for a given priority 4562 * traffic class enabled for a given priority
4562 * and use the traffic class index to get the 4563 * and create a bitmask of enabled TCs
4563 * number of traffic classes enabled
4564 */ 4564 */
4565 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { 4565 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4566 if (dcbcfg->etscfg.prioritytable[i] > num_tc) 4566 num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
4567 num_tc = dcbcfg->etscfg.prioritytable[i];
4568 }
4569 4567
4570 /* Traffic class index starts from zero so 4568 /* Now scan the bitmask to check for
4571 * increment to return the actual count 4569 * contiguous TCs starting with TC0
4572 */ 4570 */
4573 return num_tc + 1; 4571 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4572 if (num_tc & BIT(i)) {
4573 if (!tc_unused) {
4574 ret++;
4575 } else {
4576 pr_err("Non-contiguous TC - Disabling DCB\n");
4577 return 1;
4578 }
4579 } else {
4580 tc_unused = 1;
4581 }
4582 }
4583
4584 /* There is always at least TC0 */
4585 if (!ret)
4586 ret = 1;
4587
4588 return ret;
4574} 4589}
4575 4590
4576/** 4591/**
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index e61b647f5f2a..336c103ae374 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -744,7 +744,8 @@ static void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter)
744 } 744 }
745 } 745 }
746 746
747 shhwtstamps.hwtstamp = ktime_sub_ns(shhwtstamps.hwtstamp, adjust); 747 shhwtstamps.hwtstamp =
748 ktime_add_ns(shhwtstamps.hwtstamp, adjust);
748 749
749 skb_tstamp_tx(adapter->ptp_tx_skb, &shhwtstamps); 750 skb_tstamp_tx(adapter->ptp_tx_skb, &shhwtstamps);
750 dev_kfree_skb_any(adapter->ptp_tx_skb); 751 dev_kfree_skb_any(adapter->ptp_tx_skb);
@@ -767,13 +768,32 @@ void igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector,
767 struct sk_buff *skb) 768 struct sk_buff *skb)
768{ 769{
769 __le64 *regval = (__le64 *)va; 770 __le64 *regval = (__le64 *)va;
771 struct igb_adapter *adapter = q_vector->adapter;
772 int adjust = 0;
770 773
771 /* The timestamp is recorded in little endian format. 774 /* The timestamp is recorded in little endian format.
772 * DWORD: 0 1 2 3 775 * DWORD: 0 1 2 3
773 * Field: Reserved Reserved SYSTIML SYSTIMH 776 * Field: Reserved Reserved SYSTIML SYSTIMH
774 */ 777 */
775 igb_ptp_systim_to_hwtstamp(q_vector->adapter, skb_hwtstamps(skb), 778 igb_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb),
776 le64_to_cpu(regval[1])); 779 le64_to_cpu(regval[1]));
780
781 /* adjust timestamp for the RX latency based on link speed */
782 if (adapter->hw.mac.type == e1000_i210) {
783 switch (adapter->link_speed) {
784 case SPEED_10:
785 adjust = IGB_I210_RX_LATENCY_10;
786 break;
787 case SPEED_100:
788 adjust = IGB_I210_RX_LATENCY_100;
789 break;
790 case SPEED_1000:
791 adjust = IGB_I210_RX_LATENCY_1000;
792 break;
793 }
794 }
795 skb_hwtstamps(skb)->hwtstamp =
796 ktime_sub_ns(skb_hwtstamps(skb)->hwtstamp, adjust);
777} 797}
778 798
779/** 799/**
@@ -825,7 +845,7 @@ void igb_ptp_rx_rgtstamp(struct igb_q_vector *q_vector,
825 } 845 }
826 } 846 }
827 skb_hwtstamps(skb)->hwtstamp = 847 skb_hwtstamps(skb)->hwtstamp =
828 ktime_add_ns(skb_hwtstamps(skb)->hwtstamp, adjust); 848 ktime_sub_ns(skb_hwtstamps(skb)->hwtstamp, adjust);
829 849
830 /* Update the last_rx_timestamp timer in order to enable watchdog check 850 /* Update the last_rx_timestamp timer in order to enable watchdog check
831 * for error case of latched timestamp on a dropped packet. 851 * for error case of latched timestamp on a dropped packet.
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 5418c69a7463..b4f03748adc0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -4100,6 +4100,8 @@ static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4100 struct ixgbe_hw *hw = &adapter->hw; 4100 struct ixgbe_hw *hw = &adapter->hw;
4101 u32 vlnctrl, i; 4101 u32 vlnctrl, i;
4102 4102
4103 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4104
4103 switch (hw->mac.type) { 4105 switch (hw->mac.type) {
4104 case ixgbe_mac_82599EB: 4106 case ixgbe_mac_82599EB:
4105 case ixgbe_mac_X540: 4107 case ixgbe_mac_X540:
@@ -4112,8 +4114,7 @@ static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4112 /* fall through */ 4114 /* fall through */
4113 case ixgbe_mac_82598EB: 4115 case ixgbe_mac_82598EB:
4114 /* legacy case, we can just disable VLAN filtering */ 4116 /* legacy case, we can just disable VLAN filtering */
4115 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); 4117 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
4116 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
4117 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); 4118 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4118 return; 4119 return;
4119 } 4120 }
@@ -4125,6 +4126,10 @@ static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4125 /* Set flag so we don't redo unnecessary work */ 4126 /* Set flag so we don't redo unnecessary work */
4126 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; 4127 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4127 4128
4129 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4130 vlnctrl |= IXGBE_VLNCTRL_VFE;
4131 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4132
4128 /* Add PF to all active pools */ 4133 /* Add PF to all active pools */
4129 for (i = IXGBE_VLVF_ENTRIES; --i;) { 4134 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4130 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); 4135 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
@@ -4191,6 +4196,11 @@ static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4191 struct ixgbe_hw *hw = &adapter->hw; 4196 struct ixgbe_hw *hw = &adapter->hw;
4192 u32 vlnctrl, i; 4197 u32 vlnctrl, i;
4193 4198
4199 /* Set VLAN filtering to enabled */
4200 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4201 vlnctrl |= IXGBE_VLNCTRL_VFE;
4202 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4203
4194 switch (hw->mac.type) { 4204 switch (hw->mac.type) {
4195 case ixgbe_mac_82599EB: 4205 case ixgbe_mac_82599EB:
4196 case ixgbe_mac_X540: 4206 case ixgbe_mac_X540:
@@ -4202,10 +4212,6 @@ static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4202 break; 4212 break;
4203 /* fall through */ 4213 /* fall through */
4204 case ixgbe_mac_82598EB: 4214 case ixgbe_mac_82598EB:
4205 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4206 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
4207 vlnctrl |= IXGBE_VLNCTRL_VFE;
4208 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4209 return; 4215 return;
4210 } 4216 }
4211 4217
@@ -8390,12 +8396,14 @@ static int parse_tc_actions(struct ixgbe_adapter *adapter,
8390 struct tcf_exts *exts, u64 *action, u8 *queue) 8396 struct tcf_exts *exts, u64 *action, u8 *queue)
8391{ 8397{
8392 const struct tc_action *a; 8398 const struct tc_action *a;
8399 LIST_HEAD(actions);
8393 int err; 8400 int err;
8394 8401
8395 if (tc_no_actions(exts)) 8402 if (tc_no_actions(exts))
8396 return -EINVAL; 8403 return -EINVAL;
8397 8404
8398 tc_for_each_action(a, exts) { 8405 tcf_exts_to_list(exts, &actions);
8406 list_for_each_entry(a, &actions, list) {
8399 8407
8400 /* Drop action */ 8408 /* Drop action */
8401 if (is_tcf_gact_shot(a)) { 8409 if (is_tcf_gact_shot(a)) {
@@ -9517,6 +9525,7 @@ skip_sriov:
9517 9525
9518 /* copy netdev features into list of user selectable features */ 9526 /* copy netdev features into list of user selectable features */
9519 netdev->hw_features |= netdev->features | 9527 netdev->hw_features |= netdev->features |
9528 NETIF_F_HW_VLAN_CTAG_FILTER |
9520 NETIF_F_HW_VLAN_CTAG_RX | 9529 NETIF_F_HW_VLAN_CTAG_RX |
9521 NETIF_F_HW_VLAN_CTAG_TX | 9530 NETIF_F_HW_VLAN_CTAG_TX |
9522 NETIF_F_RXALL | 9531 NETIF_F_RXALL |
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index b57ae3afb994..f1609542adf1 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -245,12 +245,16 @@ static int mtk_phy_connect(struct mtk_mac *mac)
245 case PHY_INTERFACE_MODE_MII: 245 case PHY_INTERFACE_MODE_MII:
246 ge_mode = 1; 246 ge_mode = 1;
247 break; 247 break;
248 case PHY_INTERFACE_MODE_RMII: 248 case PHY_INTERFACE_MODE_REVMII:
249 ge_mode = 2; 249 ge_mode = 2;
250 break; 250 break;
251 case PHY_INTERFACE_MODE_RMII:
252 if (!mac->id)
253 goto err_phy;
254 ge_mode = 3;
255 break;
251 default: 256 default:
252 dev_err(eth->dev, "invalid phy_mode\n"); 257 goto err_phy;
253 return -1;
254 } 258 }
255 259
256 /* put the gmac into the right mode */ 260 /* put the gmac into the right mode */
@@ -263,13 +267,25 @@ static int mtk_phy_connect(struct mtk_mac *mac)
263 mac->phy_dev->autoneg = AUTONEG_ENABLE; 267 mac->phy_dev->autoneg = AUTONEG_ENABLE;
264 mac->phy_dev->speed = 0; 268 mac->phy_dev->speed = 0;
265 mac->phy_dev->duplex = 0; 269 mac->phy_dev->duplex = 0;
270
271 if (of_phy_is_fixed_link(mac->of_node))
272 mac->phy_dev->supported |=
273 SUPPORTED_Pause | SUPPORTED_Asym_Pause;
274
266 mac->phy_dev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause | 275 mac->phy_dev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause |
267 SUPPORTED_Asym_Pause; 276 SUPPORTED_Asym_Pause;
268 mac->phy_dev->advertising = mac->phy_dev->supported | 277 mac->phy_dev->advertising = mac->phy_dev->supported |
269 ADVERTISED_Autoneg; 278 ADVERTISED_Autoneg;
270 phy_start_aneg(mac->phy_dev); 279 phy_start_aneg(mac->phy_dev);
271 280
281 of_node_put(np);
282
272 return 0; 283 return 0;
284
285err_phy:
286 of_node_put(np);
287 dev_err(eth->dev, "invalid phy_mode\n");
288 return -EINVAL;
273} 289}
274 290
275static int mtk_mdio_init(struct mtk_eth *eth) 291static int mtk_mdio_init(struct mtk_eth *eth)
@@ -542,15 +558,15 @@ static inline struct mtk_tx_buf *mtk_desc_to_tx_buf(struct mtk_tx_ring *ring,
542 return &ring->buf[idx]; 558 return &ring->buf[idx];
543} 559}
544 560
545static void mtk_tx_unmap(struct device *dev, struct mtk_tx_buf *tx_buf) 561static void mtk_tx_unmap(struct mtk_eth *eth, struct mtk_tx_buf *tx_buf)
546{ 562{
547 if (tx_buf->flags & MTK_TX_FLAGS_SINGLE0) { 563 if (tx_buf->flags & MTK_TX_FLAGS_SINGLE0) {
548 dma_unmap_single(dev, 564 dma_unmap_single(eth->dev,
549 dma_unmap_addr(tx_buf, dma_addr0), 565 dma_unmap_addr(tx_buf, dma_addr0),
550 dma_unmap_len(tx_buf, dma_len0), 566 dma_unmap_len(tx_buf, dma_len0),
551 DMA_TO_DEVICE); 567 DMA_TO_DEVICE);
552 } else if (tx_buf->flags & MTK_TX_FLAGS_PAGE0) { 568 } else if (tx_buf->flags & MTK_TX_FLAGS_PAGE0) {
553 dma_unmap_page(dev, 569 dma_unmap_page(eth->dev,
554 dma_unmap_addr(tx_buf, dma_addr0), 570 dma_unmap_addr(tx_buf, dma_addr0),
555 dma_unmap_len(tx_buf, dma_len0), 571 dma_unmap_len(tx_buf, dma_len0),
556 DMA_TO_DEVICE); 572 DMA_TO_DEVICE);
@@ -595,9 +611,9 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
595 if (skb_vlan_tag_present(skb)) 611 if (skb_vlan_tag_present(skb))
596 txd4 |= TX_DMA_INS_VLAN | skb_vlan_tag_get(skb); 612 txd4 |= TX_DMA_INS_VLAN | skb_vlan_tag_get(skb);
597 613
598 mapped_addr = dma_map_single(&dev->dev, skb->data, 614 mapped_addr = dma_map_single(eth->dev, skb->data,
599 skb_headlen(skb), DMA_TO_DEVICE); 615 skb_headlen(skb), DMA_TO_DEVICE);
600 if (unlikely(dma_mapping_error(&dev->dev, mapped_addr))) 616 if (unlikely(dma_mapping_error(eth->dev, mapped_addr)))
601 return -ENOMEM; 617 return -ENOMEM;
602 618
603 WRITE_ONCE(itxd->txd1, mapped_addr); 619 WRITE_ONCE(itxd->txd1, mapped_addr);
@@ -623,10 +639,10 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
623 639
624 n_desc++; 640 n_desc++;
625 frag_map_size = min(frag_size, MTK_TX_DMA_BUF_LEN); 641 frag_map_size = min(frag_size, MTK_TX_DMA_BUF_LEN);
626 mapped_addr = skb_frag_dma_map(&dev->dev, frag, offset, 642 mapped_addr = skb_frag_dma_map(eth->dev, frag, offset,
627 frag_map_size, 643 frag_map_size,
628 DMA_TO_DEVICE); 644 DMA_TO_DEVICE);
629 if (unlikely(dma_mapping_error(&dev->dev, mapped_addr))) 645 if (unlikely(dma_mapping_error(eth->dev, mapped_addr)))
630 goto err_dma; 646 goto err_dma;
631 647
632 if (i == nr_frags - 1 && 648 if (i == nr_frags - 1 &&
@@ -679,7 +695,7 @@ err_dma:
679 tx_buf = mtk_desc_to_tx_buf(ring, itxd); 695 tx_buf = mtk_desc_to_tx_buf(ring, itxd);
680 696
681 /* unmap dma */ 697 /* unmap dma */
682 mtk_tx_unmap(&dev->dev, tx_buf); 698 mtk_tx_unmap(eth, tx_buf);
683 699
684 itxd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU; 700 itxd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
685 itxd = mtk_qdma_phys_to_virt(ring, itxd->txd2); 701 itxd = mtk_qdma_phys_to_virt(ring, itxd->txd2);
@@ -836,11 +852,11 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
836 netdev->stats.rx_dropped++; 852 netdev->stats.rx_dropped++;
837 goto release_desc; 853 goto release_desc;
838 } 854 }
839 dma_addr = dma_map_single(&eth->netdev[mac]->dev, 855 dma_addr = dma_map_single(eth->dev,
840 new_data + NET_SKB_PAD, 856 new_data + NET_SKB_PAD,
841 ring->buf_size, 857 ring->buf_size,
842 DMA_FROM_DEVICE); 858 DMA_FROM_DEVICE);
843 if (unlikely(dma_mapping_error(&netdev->dev, dma_addr))) { 859 if (unlikely(dma_mapping_error(eth->dev, dma_addr))) {
844 skb_free_frag(new_data); 860 skb_free_frag(new_data);
845 netdev->stats.rx_dropped++; 861 netdev->stats.rx_dropped++;
846 goto release_desc; 862 goto release_desc;
@@ -855,7 +871,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
855 } 871 }
856 skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN); 872 skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
857 873
858 dma_unmap_single(&netdev->dev, trxd.rxd1, 874 dma_unmap_single(eth->dev, trxd.rxd1,
859 ring->buf_size, DMA_FROM_DEVICE); 875 ring->buf_size, DMA_FROM_DEVICE);
860 pktlen = RX_DMA_GET_PLEN0(trxd.rxd2); 876 pktlen = RX_DMA_GET_PLEN0(trxd.rxd2);
861 skb->dev = netdev; 877 skb->dev = netdev;
@@ -937,7 +953,7 @@ static int mtk_poll_tx(struct mtk_eth *eth, int budget)
937 done[mac]++; 953 done[mac]++;
938 budget--; 954 budget--;
939 } 955 }
940 mtk_tx_unmap(eth->dev, tx_buf); 956 mtk_tx_unmap(eth, tx_buf);
941 957
942 ring->last_free = desc; 958 ring->last_free = desc;
943 atomic_inc(&ring->free_count); 959 atomic_inc(&ring->free_count);
@@ -1092,7 +1108,7 @@ static void mtk_tx_clean(struct mtk_eth *eth)
1092 1108
1093 if (ring->buf) { 1109 if (ring->buf) {
1094 for (i = 0; i < MTK_DMA_SIZE; i++) 1110 for (i = 0; i < MTK_DMA_SIZE; i++)
1095 mtk_tx_unmap(eth->dev, &ring->buf[i]); 1111 mtk_tx_unmap(eth, &ring->buf[i]);
1096 kfree(ring->buf); 1112 kfree(ring->buf);
1097 ring->buf = NULL; 1113 ring->buf = NULL;
1098 } 1114 }
@@ -1751,6 +1767,7 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
1751 goto free_netdev; 1767 goto free_netdev;
1752 } 1768 }
1753 spin_lock_init(&mac->hw_stats->stats_lock); 1769 spin_lock_init(&mac->hw_stats->stats_lock);
1770 u64_stats_init(&mac->hw_stats->syncp);
1754 mac->hw_stats->reg_offset = id * MTK_STAT_OFFSET; 1771 mac->hw_stats->reg_offset = id * MTK_STAT_OFFSET;
1755 1772
1756 SET_NETDEV_DEV(eth->netdev[id], eth->dev); 1773 SET_NETDEV_DEV(eth->netdev[id], eth->dev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 0f19b01e3fff..dc8b1cb0fdc8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -318,6 +318,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
318 u32 *action, u32 *flow_tag) 318 u32 *action, u32 *flow_tag)
319{ 319{
320 const struct tc_action *a; 320 const struct tc_action *a;
321 LIST_HEAD(actions);
321 322
322 if (tc_no_actions(exts)) 323 if (tc_no_actions(exts))
323 return -EINVAL; 324 return -EINVAL;
@@ -325,7 +326,8 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
325 *flow_tag = MLX5_FS_DEFAULT_FLOW_TAG; 326 *flow_tag = MLX5_FS_DEFAULT_FLOW_TAG;
326 *action = 0; 327 *action = 0;
327 328
328 tc_for_each_action(a, exts) { 329 tcf_exts_to_list(exts, &actions);
330 list_for_each_entry(a, &actions, list) {
329 /* Only support a single action per rule */ 331 /* Only support a single action per rule */
330 if (*action) 332 if (*action)
331 return -EINVAL; 333 return -EINVAL;
@@ -362,13 +364,15 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
362 u32 *action, u32 *dest_vport) 364 u32 *action, u32 *dest_vport)
363{ 365{
364 const struct tc_action *a; 366 const struct tc_action *a;
367 LIST_HEAD(actions);
365 368
366 if (tc_no_actions(exts)) 369 if (tc_no_actions(exts))
367 return -EINVAL; 370 return -EINVAL;
368 371
369 *action = 0; 372 *action = 0;
370 373
371 tc_for_each_action(a, exts) { 374 tcf_exts_to_list(exts, &actions);
375 list_for_each_entry(a, &actions, list) {
372 /* Only support a single action per rule */ 376 /* Only support a single action per rule */
373 if (*action) 377 if (*action)
374 return -EINVAL; 378 return -EINVAL;
@@ -503,6 +507,7 @@ int mlx5e_stats_flower(struct mlx5e_priv *priv,
503 struct mlx5e_tc_flow *flow; 507 struct mlx5e_tc_flow *flow;
504 struct tc_action *a; 508 struct tc_action *a;
505 struct mlx5_fc *counter; 509 struct mlx5_fc *counter;
510 LIST_HEAD(actions);
506 u64 bytes; 511 u64 bytes;
507 u64 packets; 512 u64 packets;
508 u64 lastuse; 513 u64 lastuse;
@@ -518,7 +523,8 @@ int mlx5e_stats_flower(struct mlx5e_priv *priv,
518 523
519 mlx5_fc_query_cached(counter, &bytes, &packets, &lastuse); 524 mlx5_fc_query_cached(counter, &bytes, &packets, &lastuse);
520 525
521 tc_for_each_action(a, f->exts) 526 tcf_exts_to_list(f->exts, &actions);
527 list_for_each_entry(a, &actions, list)
522 tcf_action_stats_update(a, bytes, packets, lastuse); 528 tcf_action_stats_update(a, bytes, packets, lastuse);
523 529
524 return 0; 530 return 0;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h
index 7ca9201f7dcb..1721098eef13 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/reg.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h
@@ -3383,6 +3383,15 @@ MLXSW_ITEM32(reg, ritr, ipv4_fe, 0x04, 29, 1);
3383 */ 3383 */
3384MLXSW_ITEM32(reg, ritr, ipv6_fe, 0x04, 28, 1); 3384MLXSW_ITEM32(reg, ritr, ipv6_fe, 0x04, 28, 1);
3385 3385
3386/* reg_ritr_lb_en
3387 * Loop-back filter enable for unicast packets.
3388 * If the flag is set then loop-back filter for unicast packets is
3389 * implemented on the RIF. Multicast packets are always subject to
3390 * loop-back filtering.
3391 * Access: RW
3392 */
3393MLXSW_ITEM32(reg, ritr, lb_en, 0x04, 24, 1);
3394
3386/* reg_ritr_virtual_router 3395/* reg_ritr_virtual_router
3387 * Virtual router ID associated with the router interface. 3396 * Virtual router ID associated with the router interface.
3388 * Access: RW 3397 * Access: RW
@@ -3484,6 +3493,7 @@ static inline void mlxsw_reg_ritr_pack(char *payload, bool enable,
3484 mlxsw_reg_ritr_op_set(payload, op); 3493 mlxsw_reg_ritr_op_set(payload, op);
3485 mlxsw_reg_ritr_rif_set(payload, rif); 3494 mlxsw_reg_ritr_rif_set(payload, rif);
3486 mlxsw_reg_ritr_ipv4_fe_set(payload, 1); 3495 mlxsw_reg_ritr_ipv4_fe_set(payload, 1);
3496 mlxsw_reg_ritr_lb_en_set(payload, 1);
3487 mlxsw_reg_ritr_mtu_set(payload, mtu); 3497 mlxsw_reg_ritr_mtu_set(payload, mtu);
3488 mlxsw_reg_ritr_if_mac_memcpy_to(payload, mac); 3498 mlxsw_reg_ritr_if_mac_memcpy_to(payload, mac);
3489} 3499}
@@ -4000,6 +4010,7 @@ static inline void mlxsw_reg_ralue_pack(char *payload,
4000{ 4010{
4001 MLXSW_REG_ZERO(ralue, payload); 4011 MLXSW_REG_ZERO(ralue, payload);
4002 mlxsw_reg_ralue_protocol_set(payload, protocol); 4012 mlxsw_reg_ralue_protocol_set(payload, protocol);
4013 mlxsw_reg_ralue_op_set(payload, op);
4003 mlxsw_reg_ralue_virtual_router_set(payload, virtual_router); 4014 mlxsw_reg_ralue_virtual_router_set(payload, virtual_router);
4004 mlxsw_reg_ralue_prefix_len_set(payload, prefix_len); 4015 mlxsw_reg_ralue_prefix_len_set(payload, prefix_len);
4005 mlxsw_reg_ralue_entry_type_set(payload, 4016 mlxsw_reg_ralue_entry_type_set(payload,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index c3e61500819d..1f8168906811 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -942,8 +942,8 @@ static void mlxsw_sp_port_vport_destroy(struct mlxsw_sp_port *mlxsw_sp_vport)
942 kfree(mlxsw_sp_vport); 942 kfree(mlxsw_sp_vport);
943} 943}
944 944
945int mlxsw_sp_port_add_vid(struct net_device *dev, __be16 __always_unused proto, 945static int mlxsw_sp_port_add_vid(struct net_device *dev,
946 u16 vid) 946 __be16 __always_unused proto, u16 vid)
947{ 947{
948 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); 948 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
949 struct mlxsw_sp_port *mlxsw_sp_vport; 949 struct mlxsw_sp_port *mlxsw_sp_vport;
@@ -956,16 +956,12 @@ int mlxsw_sp_port_add_vid(struct net_device *dev, __be16 __always_unused proto,
956 if (!vid) 956 if (!vid)
957 return 0; 957 return 0;
958 958
959 if (mlxsw_sp_port_vport_find(mlxsw_sp_port, vid)) { 959 if (mlxsw_sp_port_vport_find(mlxsw_sp_port, vid))
960 netdev_warn(dev, "VID=%d already configured\n", vid);
961 return 0; 960 return 0;
962 }
963 961
964 mlxsw_sp_vport = mlxsw_sp_port_vport_create(mlxsw_sp_port, vid); 962 mlxsw_sp_vport = mlxsw_sp_port_vport_create(mlxsw_sp_port, vid);
965 if (!mlxsw_sp_vport) { 963 if (!mlxsw_sp_vport)
966 netdev_err(dev, "Failed to create vPort for VID=%d\n", vid);
967 return -ENOMEM; 964 return -ENOMEM;
968 }
969 965
970 /* When adding the first VLAN interface on a bridged port we need to 966 /* When adding the first VLAN interface on a bridged port we need to
971 * transition all the active 802.1Q bridge VLANs to use explicit 967 * transition all the active 802.1Q bridge VLANs to use explicit
@@ -973,24 +969,17 @@ int mlxsw_sp_port_add_vid(struct net_device *dev, __be16 __always_unused proto,
973 */ 969 */
974 if (list_is_singular(&mlxsw_sp_port->vports_list)) { 970 if (list_is_singular(&mlxsw_sp_port->vports_list)) {
975 err = mlxsw_sp_port_vp_mode_trans(mlxsw_sp_port); 971 err = mlxsw_sp_port_vp_mode_trans(mlxsw_sp_port);
976 if (err) { 972 if (err)
977 netdev_err(dev, "Failed to set to Virtual mode\n");
978 goto err_port_vp_mode_trans; 973 goto err_port_vp_mode_trans;
979 }
980 } 974 }
981 975
982 err = mlxsw_sp_port_vid_learning_set(mlxsw_sp_vport, vid, false); 976 err = mlxsw_sp_port_vid_learning_set(mlxsw_sp_vport, vid, false);
983 if (err) { 977 if (err)
984 netdev_err(dev, "Failed to disable learning for VID=%d\n", vid);
985 goto err_port_vid_learning_set; 978 goto err_port_vid_learning_set;
986 }
987 979
988 err = mlxsw_sp_port_vlan_set(mlxsw_sp_vport, vid, vid, true, untagged); 980 err = mlxsw_sp_port_vlan_set(mlxsw_sp_vport, vid, vid, true, untagged);
989 if (err) { 981 if (err)
990 netdev_err(dev, "Failed to set VLAN membership for VID=%d\n",
991 vid);
992 goto err_port_add_vid; 982 goto err_port_add_vid;
993 }
994 983
995 return 0; 984 return 0;
996 985
@@ -1010,7 +999,6 @@ static int mlxsw_sp_port_kill_vid(struct net_device *dev,
1010 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); 999 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1011 struct mlxsw_sp_port *mlxsw_sp_vport; 1000 struct mlxsw_sp_port *mlxsw_sp_vport;
1012 struct mlxsw_sp_fid *f; 1001 struct mlxsw_sp_fid *f;
1013 int err;
1014 1002
1015 /* VLAN 0 is removed from HW filter when device goes down, but 1003 /* VLAN 0 is removed from HW filter when device goes down, but
1016 * it is reserved in our case, so simply return. 1004 * it is reserved in our case, so simply return.
@@ -1019,23 +1007,12 @@ static int mlxsw_sp_port_kill_vid(struct net_device *dev,
1019 return 0; 1007 return 0;
1020 1008
1021 mlxsw_sp_vport = mlxsw_sp_port_vport_find(mlxsw_sp_port, vid); 1009 mlxsw_sp_vport = mlxsw_sp_port_vport_find(mlxsw_sp_port, vid);
1022 if (!mlxsw_sp_vport) { 1010 if (WARN_ON(!mlxsw_sp_vport))
1023 netdev_warn(dev, "VID=%d does not exist\n", vid);
1024 return 0; 1011 return 0;
1025 }
1026 1012
1027 err = mlxsw_sp_port_vlan_set(mlxsw_sp_vport, vid, vid, false, false); 1013 mlxsw_sp_port_vlan_set(mlxsw_sp_vport, vid, vid, false, false);
1028 if (err) {
1029 netdev_err(dev, "Failed to set VLAN membership for VID=%d\n",
1030 vid);
1031 return err;
1032 }
1033 1014
1034 err = mlxsw_sp_port_vid_learning_set(mlxsw_sp_vport, vid, true); 1015 mlxsw_sp_port_vid_learning_set(mlxsw_sp_vport, vid, true);
1035 if (err) {
1036 netdev_err(dev, "Failed to enable learning for VID=%d\n", vid);
1037 return err;
1038 }
1039 1016
1040 /* Drop FID reference. If this was the last reference the 1017 /* Drop FID reference. If this was the last reference the
1041 * resources will be freed. 1018 * resources will be freed.
@@ -1048,13 +1025,8 @@ static int mlxsw_sp_port_kill_vid(struct net_device *dev,
1048 * transition all active 802.1Q bridge VLANs to use VID to FID 1025 * transition all active 802.1Q bridge VLANs to use VID to FID
1049 * mappings and set port's mode to VLAN mode. 1026 * mappings and set port's mode to VLAN mode.
1050 */ 1027 */
1051 if (list_is_singular(&mlxsw_sp_port->vports_list)) { 1028 if (list_is_singular(&mlxsw_sp_port->vports_list))
1052 err = mlxsw_sp_port_vlan_mode_trans(mlxsw_sp_port); 1029 mlxsw_sp_port_vlan_mode_trans(mlxsw_sp_port);
1053 if (err) {
1054 netdev_err(dev, "Failed to set to VLAN mode\n");
1055 return err;
1056 }
1057 }
1058 1030
1059 mlxsw_sp_port_vport_destroy(mlxsw_sp_vport); 1031 mlxsw_sp_port_vport_destroy(mlxsw_sp_vport);
1060 1032
@@ -1149,6 +1121,7 @@ static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
1149 bool ingress) 1121 bool ingress)
1150{ 1122{
1151 const struct tc_action *a; 1123 const struct tc_action *a;
1124 LIST_HEAD(actions);
1152 int err; 1125 int err;
1153 1126
1154 if (!tc_single_action(cls->exts)) { 1127 if (!tc_single_action(cls->exts)) {
@@ -1156,7 +1129,8 @@ static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
1156 return -ENOTSUPP; 1129 return -ENOTSUPP;
1157 } 1130 }
1158 1131
1159 tc_for_each_action(a, cls->exts) { 1132 tcf_exts_to_list(cls->exts, &actions);
1133 list_for_each_entry(a, &actions, list) {
1160 if (!is_tcf_mirred_mirror(a) || protocol != htons(ETH_P_ALL)) 1134 if (!is_tcf_mirred_mirror(a) || protocol != htons(ETH_P_ALL))
1161 return -ENOTSUPP; 1135 return -ENOTSUPP;
1162 1136
@@ -2076,6 +2050,18 @@ static int mlxsw_sp_port_ets_init(struct mlxsw_sp_port *mlxsw_sp_port)
2076 return 0; 2050 return 0;
2077} 2051}
2078 2052
2053static int mlxsw_sp_port_pvid_vport_create(struct mlxsw_sp_port *mlxsw_sp_port)
2054{
2055 mlxsw_sp_port->pvid = 1;
2056
2057 return mlxsw_sp_port_add_vid(mlxsw_sp_port->dev, 0, 1);
2058}
2059
2060static int mlxsw_sp_port_pvid_vport_destroy(struct mlxsw_sp_port *mlxsw_sp_port)
2061{
2062 return mlxsw_sp_port_kill_vid(mlxsw_sp_port->dev, 0, 1);
2063}
2064
2079static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port, 2065static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
2080 bool split, u8 module, u8 width, u8 lane) 2066 bool split, u8 module, u8 width, u8 lane)
2081{ 2067{
@@ -2191,7 +2177,15 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
2191 goto err_port_dcb_init; 2177 goto err_port_dcb_init;
2192 } 2178 }
2193 2179
2180 err = mlxsw_sp_port_pvid_vport_create(mlxsw_sp_port);
2181 if (err) {
2182 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to create PVID vPort\n",
2183 mlxsw_sp_port->local_port);
2184 goto err_port_pvid_vport_create;
2185 }
2186
2194 mlxsw_sp_port_switchdev_init(mlxsw_sp_port); 2187 mlxsw_sp_port_switchdev_init(mlxsw_sp_port);
2188 mlxsw_sp->ports[local_port] = mlxsw_sp_port;
2195 err = register_netdev(dev); 2189 err = register_netdev(dev);
2196 if (err) { 2190 if (err) {
2197 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to register netdev\n", 2191 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to register netdev\n",
@@ -2208,24 +2202,23 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
2208 goto err_core_port_init; 2202 goto err_core_port_init;
2209 } 2203 }
2210 2204
2211 err = mlxsw_sp_port_vlan_init(mlxsw_sp_port);
2212 if (err)
2213 goto err_port_vlan_init;
2214
2215 mlxsw_sp->ports[local_port] = mlxsw_sp_port;
2216 return 0; 2205 return 0;
2217 2206
2218err_port_vlan_init:
2219 mlxsw_core_port_fini(&mlxsw_sp_port->core_port);
2220err_core_port_init: 2207err_core_port_init:
2221 unregister_netdev(dev); 2208 unregister_netdev(dev);
2222err_register_netdev: 2209err_register_netdev:
2210 mlxsw_sp->ports[local_port] = NULL;
2211 mlxsw_sp_port_switchdev_fini(mlxsw_sp_port);
2212 mlxsw_sp_port_pvid_vport_destroy(mlxsw_sp_port);
2213err_port_pvid_vport_create:
2214 mlxsw_sp_port_dcb_fini(mlxsw_sp_port);
2223err_port_dcb_init: 2215err_port_dcb_init:
2224err_port_ets_init: 2216err_port_ets_init:
2225err_port_buffers_init: 2217err_port_buffers_init:
2226err_port_admin_status_set: 2218err_port_admin_status_set:
2227err_port_mtu_set: 2219err_port_mtu_set:
2228err_port_speed_by_width_set: 2220err_port_speed_by_width_set:
2221 mlxsw_sp_port_swid_set(mlxsw_sp_port, MLXSW_PORT_SWID_DISABLED_PORT);
2229err_port_swid_set: 2222err_port_swid_set:
2230err_port_system_port_mapping_set: 2223err_port_system_port_mapping_set:
2231err_dev_addr_init: 2224err_dev_addr_init:
@@ -2245,12 +2238,12 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u8 local_port)
2245 2238
2246 if (!mlxsw_sp_port) 2239 if (!mlxsw_sp_port)
2247 return; 2240 return;
2248 mlxsw_sp->ports[local_port] = NULL;
2249 mlxsw_core_port_fini(&mlxsw_sp_port->core_port); 2241 mlxsw_core_port_fini(&mlxsw_sp_port->core_port);
2250 unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */ 2242 unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */
2251 mlxsw_sp_port_dcb_fini(mlxsw_sp_port); 2243 mlxsw_sp->ports[local_port] = NULL;
2252 mlxsw_sp_port_kill_vid(mlxsw_sp_port->dev, 0, 1);
2253 mlxsw_sp_port_switchdev_fini(mlxsw_sp_port); 2244 mlxsw_sp_port_switchdev_fini(mlxsw_sp_port);
2245 mlxsw_sp_port_pvid_vport_destroy(mlxsw_sp_port);
2246 mlxsw_sp_port_dcb_fini(mlxsw_sp_port);
2254 mlxsw_sp_port_swid_set(mlxsw_sp_port, MLXSW_PORT_SWID_DISABLED_PORT); 2247 mlxsw_sp_port_swid_set(mlxsw_sp_port, MLXSW_PORT_SWID_DISABLED_PORT);
2255 mlxsw_sp_port_module_unmap(mlxsw_sp, mlxsw_sp_port->local_port); 2248 mlxsw_sp_port_module_unmap(mlxsw_sp, mlxsw_sp_port->local_port);
2256 free_percpu(mlxsw_sp_port->pcpu_stats); 2249 free_percpu(mlxsw_sp_port->pcpu_stats);
@@ -2662,6 +2655,26 @@ static const struct mlxsw_rx_listener mlxsw_sp_rx_listener[] = {
2662 { 2655 {
2663 .func = mlxsw_sp_rx_listener_func, 2656 .func = mlxsw_sp_rx_listener_func,
2664 .local_port = MLXSW_PORT_DONT_CARE, 2657 .local_port = MLXSW_PORT_DONT_CARE,
2658 .trap_id = MLXSW_TRAP_ID_MTUERROR,
2659 },
2660 {
2661 .func = mlxsw_sp_rx_listener_func,
2662 .local_port = MLXSW_PORT_DONT_CARE,
2663 .trap_id = MLXSW_TRAP_ID_TTLERROR,
2664 },
2665 {
2666 .func = mlxsw_sp_rx_listener_func,
2667 .local_port = MLXSW_PORT_DONT_CARE,
2668 .trap_id = MLXSW_TRAP_ID_LBERROR,
2669 },
2670 {
2671 .func = mlxsw_sp_rx_listener_func,
2672 .local_port = MLXSW_PORT_DONT_CARE,
2673 .trap_id = MLXSW_TRAP_ID_OSPF,
2674 },
2675 {
2676 .func = mlxsw_sp_rx_listener_func,
2677 .local_port = MLXSW_PORT_DONT_CARE,
2665 .trap_id = MLXSW_TRAP_ID_IP2ME, 2678 .trap_id = MLXSW_TRAP_ID_IP2ME,
2666 }, 2679 },
2667 { 2680 {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index f69aa37d1521..ab3feb81bd43 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -536,8 +536,6 @@ int mlxsw_sp_port_vid_to_fid_set(struct mlxsw_sp_port *mlxsw_sp_port,
536 u16 vid); 536 u16 vid);
537int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin, 537int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
538 u16 vid_end, bool is_member, bool untagged); 538 u16 vid_end, bool is_member, bool untagged);
539int mlxsw_sp_port_add_vid(struct net_device *dev, __be16 __always_unused proto,
540 u16 vid);
541int mlxsw_sp_vport_flood_set(struct mlxsw_sp_port *mlxsw_sp_vport, u16 fid, 539int mlxsw_sp_vport_flood_set(struct mlxsw_sp_port *mlxsw_sp_vport, u16 fid,
542 bool set); 540 bool set);
543void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port); 541void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
index 074cdda7b6f3..237418a0e6e0 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
@@ -330,7 +330,7 @@ static const struct mlxsw_sp_sb_cm mlxsw_sp_cpu_port_sb_cms[] = {
330 MLXSW_SP_CPU_PORT_SB_CM, 330 MLXSW_SP_CPU_PORT_SB_CM,
331 MLXSW_SP_CPU_PORT_SB_CM, 331 MLXSW_SP_CPU_PORT_SB_CM,
332 MLXSW_SP_CPU_PORT_SB_CM, 332 MLXSW_SP_CPU_PORT_SB_CM,
333 MLXSW_SP_CPU_PORT_SB_CM, 333 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(10000), 0, 0),
334 MLXSW_SP_CPU_PORT_SB_CM, 334 MLXSW_SP_CPU_PORT_SB_CM,
335 MLXSW_SP_CPU_PORT_SB_CM, 335 MLXSW_SP_CPU_PORT_SB_CM,
336 MLXSW_SP_CPU_PORT_SB_CM, 336 MLXSW_SP_CPU_PORT_SB_CM,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dcb.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dcb.c
index 01cfb7512827..b6ed7f7c531e 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dcb.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dcb.c
@@ -341,6 +341,8 @@ static int mlxsw_sp_port_pfc_set(struct mlxsw_sp_port *mlxsw_sp_port,
341 char pfcc_pl[MLXSW_REG_PFCC_LEN]; 341 char pfcc_pl[MLXSW_REG_PFCC_LEN];
342 342
343 mlxsw_reg_pfcc_pack(pfcc_pl, mlxsw_sp_port->local_port); 343 mlxsw_reg_pfcc_pack(pfcc_pl, mlxsw_sp_port->local_port);
344 mlxsw_reg_pfcc_pprx_set(pfcc_pl, mlxsw_sp_port->link.rx_pause);
345 mlxsw_reg_pfcc_pptx_set(pfcc_pl, mlxsw_sp_port->link.tx_pause);
344 mlxsw_reg_pfcc_prio_pack(pfcc_pl, pfc->pfc_en); 346 mlxsw_reg_pfcc_prio_pack(pfcc_pl, pfc->pfc_en);
345 347
346 return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pfcc), 348 return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pfcc),
@@ -351,17 +353,17 @@ static int mlxsw_sp_dcbnl_ieee_setpfc(struct net_device *dev,
351 struct ieee_pfc *pfc) 353 struct ieee_pfc *pfc)
352{ 354{
353 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); 355 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
356 bool pause_en = mlxsw_sp_port_is_pause_en(mlxsw_sp_port);
354 int err; 357 int err;
355 358
356 if ((mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause) && 359 if (pause_en && pfc->pfc_en) {
357 pfc->pfc_en) {
358 netdev_err(dev, "PAUSE frames already enabled on port\n"); 360 netdev_err(dev, "PAUSE frames already enabled on port\n");
359 return -EINVAL; 361 return -EINVAL;
360 } 362 }
361 363
362 err = __mlxsw_sp_port_headroom_set(mlxsw_sp_port, dev->mtu, 364 err = __mlxsw_sp_port_headroom_set(mlxsw_sp_port, dev->mtu,
363 mlxsw_sp_port->dcb.ets->prio_tc, 365 mlxsw_sp_port->dcb.ets->prio_tc,
364 false, pfc); 366 pause_en, pfc);
365 if (err) { 367 if (err) {
366 netdev_err(dev, "Failed to configure port's headroom for PFC\n"); 368 netdev_err(dev, "Failed to configure port's headroom for PFC\n");
367 return err; 369 return err;
@@ -380,7 +382,7 @@ static int mlxsw_sp_dcbnl_ieee_setpfc(struct net_device *dev,
380 382
381err_port_pfc_set: 383err_port_pfc_set:
382 __mlxsw_sp_port_headroom_set(mlxsw_sp_port, dev->mtu, 384 __mlxsw_sp_port_headroom_set(mlxsw_sp_port, dev->mtu,
383 mlxsw_sp_port->dcb.ets->prio_tc, false, 385 mlxsw_sp_port->dcb.ets->prio_tc, pause_en,
384 mlxsw_sp_port->dcb.pfc); 386 mlxsw_sp_port->dcb.pfc);
385 return err; 387 return err;
386} 388}
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 81418d629231..90bb93b037ec 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -1651,9 +1651,10 @@ static void mlxsw_sp_router_fib4_add_info_destroy(void const *data)
1651 const struct mlxsw_sp_router_fib4_add_info *info = data; 1651 const struct mlxsw_sp_router_fib4_add_info *info = data;
1652 struct mlxsw_sp_fib_entry *fib_entry = info->fib_entry; 1652 struct mlxsw_sp_fib_entry *fib_entry = info->fib_entry;
1653 struct mlxsw_sp *mlxsw_sp = info->mlxsw_sp; 1653 struct mlxsw_sp *mlxsw_sp = info->mlxsw_sp;
1654 struct mlxsw_sp_vr *vr = fib_entry->vr;
1654 1655
1655 mlxsw_sp_fib_entry_destroy(fib_entry); 1656 mlxsw_sp_fib_entry_destroy(fib_entry);
1656 mlxsw_sp_vr_put(mlxsw_sp, fib_entry->vr); 1657 mlxsw_sp_vr_put(mlxsw_sp, vr);
1657 kfree(info); 1658 kfree(info);
1658} 1659}
1659 1660
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index a1ad5e6bdfa8..d1b59cdfacc1 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -450,6 +450,8 @@ void mlxsw_sp_fid_destroy(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *f)
450 450
451 kfree(f); 451 kfree(f);
452 452
453 mlxsw_sp_fid_map(mlxsw_sp, fid, false);
454
453 mlxsw_sp_fid_op(mlxsw_sp, fid, false); 455 mlxsw_sp_fid_op(mlxsw_sp, fid, false);
454} 456}
455 457
@@ -997,13 +999,13 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
997} 999}
998 1000
999static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port, 1001static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
1000 u16 vid_begin, u16 vid_end, bool init) 1002 u16 vid_begin, u16 vid_end)
1001{ 1003{
1002 struct net_device *dev = mlxsw_sp_port->dev; 1004 struct net_device *dev = mlxsw_sp_port->dev;
1003 u16 vid, pvid; 1005 u16 vid, pvid;
1004 int err; 1006 int err;
1005 1007
1006 if (!init && !mlxsw_sp_port->bridged) 1008 if (!mlxsw_sp_port->bridged)
1007 return -EINVAL; 1009 return -EINVAL;
1008 1010
1009 err = __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end, 1011 err = __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end,
@@ -1014,9 +1016,6 @@ static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
1014 return err; 1016 return err;
1015 } 1017 }
1016 1018
1017 if (init)
1018 goto out;
1019
1020 pvid = mlxsw_sp_port->pvid; 1019 pvid = mlxsw_sp_port->pvid;
1021 if (pvid >= vid_begin && pvid <= vid_end) { 1020 if (pvid >= vid_begin && pvid <= vid_end) {
1022 err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, 0); 1021 err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, 0);
@@ -1028,7 +1027,6 @@ static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
1028 1027
1029 mlxsw_sp_port_fid_leave(mlxsw_sp_port, vid_begin, vid_end); 1028 mlxsw_sp_port_fid_leave(mlxsw_sp_port, vid_begin, vid_end);
1030 1029
1031out:
1032 /* Changing activity bits only if HW operation succeded */ 1030 /* Changing activity bits only if HW operation succeded */
1033 for (vid = vid_begin; vid <= vid_end; vid++) 1031 for (vid = vid_begin; vid <= vid_end; vid++)
1034 clear_bit(vid, mlxsw_sp_port->active_vlans); 1032 clear_bit(vid, mlxsw_sp_port->active_vlans);
@@ -1039,8 +1037,8 @@ out:
1039static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port, 1037static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
1040 const struct switchdev_obj_port_vlan *vlan) 1038 const struct switchdev_obj_port_vlan *vlan)
1041{ 1039{
1042 return __mlxsw_sp_port_vlans_del(mlxsw_sp_port, 1040 return __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vlan->vid_begin,
1043 vlan->vid_begin, vlan->vid_end, false); 1041 vlan->vid_end);
1044} 1042}
1045 1043
1046void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port) 1044void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port)
@@ -1048,7 +1046,7 @@ void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port)
1048 u16 vid; 1046 u16 vid;
1049 1047
1050 for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID) 1048 for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID)
1051 __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vid, vid, false); 1049 __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vid, vid);
1052} 1050}
1053 1051
1054static int 1052static int
@@ -1546,32 +1544,6 @@ void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp)
1546 mlxsw_sp_fdb_fini(mlxsw_sp); 1544 mlxsw_sp_fdb_fini(mlxsw_sp);
1547} 1545}
1548 1546
1549int mlxsw_sp_port_vlan_init(struct mlxsw_sp_port *mlxsw_sp_port)
1550{
1551 struct net_device *dev = mlxsw_sp_port->dev;
1552 int err;
1553
1554 /* Allow only untagged packets to ingress and tag them internally
1555 * with VID 1.
1556 */
1557 mlxsw_sp_port->pvid = 1;
1558 err = __mlxsw_sp_port_vlans_del(mlxsw_sp_port, 0, VLAN_N_VID - 1,
1559 true);
1560 if (err) {
1561 netdev_err(dev, "Unable to init VLANs\n");
1562 return err;
1563 }
1564
1565 /* Add implicit VLAN interface in the device, so that untagged
1566 * packets will be classified to the default vFID.
1567 */
1568 err = mlxsw_sp_port_add_vid(dev, 0, 1);
1569 if (err)
1570 netdev_err(dev, "Failed to configure default vFID\n");
1571
1572 return err;
1573}
1574
1575void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port) 1547void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port)
1576{ 1548{
1577 mlxsw_sp_port->dev->switchdev_ops = &mlxsw_sp_port_switchdev_ops; 1549 mlxsw_sp_port->dev->switchdev_ops = &mlxsw_sp_port_switchdev_ops;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/trap.h b/drivers/net/ethernet/mellanox/mlxsw/trap.h
index 470d7696e9fe..ed8e30186400 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/trap.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/trap.h
@@ -56,6 +56,10 @@ enum {
56 MLXSW_TRAP_ID_IGMP_V3_REPORT = 0x34, 56 MLXSW_TRAP_ID_IGMP_V3_REPORT = 0x34,
57 MLXSW_TRAP_ID_ARPBC = 0x50, 57 MLXSW_TRAP_ID_ARPBC = 0x50,
58 MLXSW_TRAP_ID_ARPUC = 0x51, 58 MLXSW_TRAP_ID_ARPUC = 0x51,
59 MLXSW_TRAP_ID_MTUERROR = 0x52,
60 MLXSW_TRAP_ID_TTLERROR = 0x53,
61 MLXSW_TRAP_ID_LBERROR = 0x54,
62 MLXSW_TRAP_ID_OSPF = 0x55,
59 MLXSW_TRAP_ID_IP2ME = 0x5F, 63 MLXSW_TRAP_ID_IP2ME = 0x5F,
60 MLXSW_TRAP_ID_RTR_INGRESS0 = 0x70, 64 MLXSW_TRAP_ID_RTR_INGRESS0 = 0x70,
61 MLXSW_TRAP_ID_HOST_MISS_IPV4 = 0x90, 65 MLXSW_TRAP_ID_HOST_MISS_IPV4 = 0x90,
diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
index d0dc28f93c0e..226cb08cc055 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -52,40 +52,94 @@ static bool qed_dcbx_app_ethtype(u32 app_info_bitmap)
52 DCBX_APP_SF_ETHTYPE); 52 DCBX_APP_SF_ETHTYPE);
53} 53}
54 54
55static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
56{
57 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
58
59 /* Old MFW */
60 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
61 return qed_dcbx_app_ethtype(app_info_bitmap);
62
63 return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
64}
65
55static bool qed_dcbx_app_port(u32 app_info_bitmap) 66static bool qed_dcbx_app_port(u32 app_info_bitmap)
56{ 67{
57 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) == 68 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
58 DCBX_APP_SF_PORT); 69 DCBX_APP_SF_PORT);
59} 70}
60 71
61static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id) 72static bool qed_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
62{ 73{
63 return !!(qed_dcbx_app_ethtype(app_info_bitmap) && 74 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
64 proto_id == QED_ETH_TYPE_DEFAULT); 75
76 /* Old MFW */
77 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
78 return qed_dcbx_app_port(app_info_bitmap);
79
80 return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
65} 81}
66 82
67static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id) 83static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
68{ 84{
69 return !!(qed_dcbx_app_port(app_info_bitmap) && 85 bool ethtype;
70 proto_id == QED_TCP_PORT_ISCSI); 86
87 if (ieee)
88 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
89 else
90 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
91
92 return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
71} 93}
72 94
73static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id) 95static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
74{ 96{
75 return !!(qed_dcbx_app_ethtype(app_info_bitmap) && 97 bool port;
76 proto_id == QED_ETH_TYPE_FCOE); 98
99 if (ieee)
100 port = qed_dcbx_ieee_app_port(app_info_bitmap,
101 DCBX_APP_SF_IEEE_TCP_PORT);
102 else
103 port = qed_dcbx_app_port(app_info_bitmap);
104
105 return !!(port && (proto_id == QED_TCP_PORT_ISCSI));
77} 106}
78 107
79static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id) 108static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
80{ 109{
81 return !!(qed_dcbx_app_ethtype(app_info_bitmap) && 110 bool ethtype;
82 proto_id == QED_ETH_TYPE_ROCE); 111
112 if (ieee)
113 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
114 else
115 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
116
117 return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
83} 118}
84 119
85static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id) 120static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
86{ 121{
87 return !!(qed_dcbx_app_port(app_info_bitmap) && 122 bool ethtype;
88 proto_id == QED_UDP_PORT_TYPE_ROCE_V2); 123
124 if (ieee)
125 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
126 else
127 ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
128
129 return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
130}
131
132static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
133{
134 bool port;
135
136 if (ieee)
137 port = qed_dcbx_ieee_app_port(app_info_bitmap,
138 DCBX_APP_SF_IEEE_UDP_PORT);
139 else
140 port = qed_dcbx_app_port(app_info_bitmap);
141
142 return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2));
89} 143}
90 144
91static void 145static void
@@ -164,17 +218,17 @@ qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
164static bool 218static bool
165qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn, 219qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
166 u32 app_prio_bitmap, 220 u32 app_prio_bitmap,
167 u16 id, enum dcbx_protocol_type *type) 221 u16 id, enum dcbx_protocol_type *type, bool ieee)
168{ 222{
169 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id)) { 223 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
170 *type = DCBX_PROTOCOL_FCOE; 224 *type = DCBX_PROTOCOL_FCOE;
171 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id)) { 225 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
172 *type = DCBX_PROTOCOL_ROCE; 226 *type = DCBX_PROTOCOL_ROCE;
173 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id)) { 227 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
174 *type = DCBX_PROTOCOL_ISCSI; 228 *type = DCBX_PROTOCOL_ISCSI;
175 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id)) { 229 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
176 *type = DCBX_PROTOCOL_ETH; 230 *type = DCBX_PROTOCOL_ETH;
177 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id)) { 231 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
178 *type = DCBX_PROTOCOL_ROCE_V2; 232 *type = DCBX_PROTOCOL_ROCE_V2;
179 } else { 233 } else {
180 *type = DCBX_MAX_PROTOCOL_TYPE; 234 *type = DCBX_MAX_PROTOCOL_TYPE;
@@ -194,17 +248,18 @@ static int
194qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn, 248qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
195 struct qed_dcbx_results *p_data, 249 struct qed_dcbx_results *p_data,
196 struct dcbx_app_priority_entry *p_tbl, 250 struct dcbx_app_priority_entry *p_tbl,
197 u32 pri_tc_tbl, int count, bool dcbx_enabled) 251 u32 pri_tc_tbl, int count, u8 dcbx_version)
198{ 252{
199 u8 tc, priority_map; 253 u8 tc, priority_map;
200 enum dcbx_protocol_type type; 254 enum dcbx_protocol_type type;
255 bool enable, ieee;
201 u16 protocol_id; 256 u16 protocol_id;
202 int priority; 257 int priority;
203 bool enable;
204 int i; 258 int i;
205 259
206 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count); 260 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
207 261
262 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
208 /* Parse APP TLV */ 263 /* Parse APP TLV */
209 for (i = 0; i < count; i++) { 264 for (i = 0; i < count; i++) {
210 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry, 265 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
@@ -219,7 +274,7 @@ qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
219 274
220 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority); 275 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
221 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry, 276 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
222 protocol_id, &type)) { 277 protocol_id, &type, ieee)) {
223 /* ETH always have the enable bit reset, as it gets 278 /* ETH always have the enable bit reset, as it gets
224 * vlan information per packet. For other protocols, 279 * vlan information per packet. For other protocols,
225 * should be set according to the dcbx_enabled 280 * should be set according to the dcbx_enabled
@@ -275,15 +330,12 @@ static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
275 struct dcbx_ets_feature *p_ets; 330 struct dcbx_ets_feature *p_ets;
276 struct qed_hw_info *p_info; 331 struct qed_hw_info *p_info;
277 u32 pri_tc_tbl, flags; 332 u32 pri_tc_tbl, flags;
278 bool dcbx_enabled; 333 u8 dcbx_version;
279 int num_entries; 334 int num_entries;
280 int rc = 0; 335 int rc = 0;
281 336
282 /* If DCBx version is non zero, then negotiation was
283 * successfuly performed
284 */
285 flags = p_hwfn->p_dcbx_info->operational.flags; 337 flags = p_hwfn->p_dcbx_info->operational.flags;
286 dcbx_enabled = !!QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION); 338 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
287 339
288 p_app = &p_hwfn->p_dcbx_info->operational.features.app; 340 p_app = &p_hwfn->p_dcbx_info->operational.features.app;
289 p_tbl = p_app->app_pri_tbl; 341 p_tbl = p_app->app_pri_tbl;
@@ -295,13 +347,13 @@ static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
295 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES); 347 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
296 348
297 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl, 349 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
298 num_entries, dcbx_enabled); 350 num_entries, dcbx_version);
299 if (rc) 351 if (rc)
300 return rc; 352 return rc;
301 353
302 p_info->num_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS); 354 p_info->num_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
303 data.pf_id = p_hwfn->rel_pf_id; 355 data.pf_id = p_hwfn->rel_pf_id;
304 data.dcbx_enabled = dcbx_enabled; 356 data.dcbx_enabled = !!dcbx_version;
305 357
306 qed_dcbx_dp_protocol(p_hwfn, &data); 358 qed_dcbx_dp_protocol(p_hwfn, &data);
307 359
@@ -400,7 +452,7 @@ static void
400qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn, 452qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
401 struct dcbx_app_priority_feature *p_app, 453 struct dcbx_app_priority_feature *p_app,
402 struct dcbx_app_priority_entry *p_tbl, 454 struct dcbx_app_priority_entry *p_tbl,
403 struct qed_dcbx_params *p_params) 455 struct qed_dcbx_params *p_params, bool ieee)
404{ 456{
405 struct qed_app_entry *entry; 457 struct qed_app_entry *entry;
406 u8 pri_map; 458 u8 pri_map;
@@ -414,15 +466,46 @@ qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
414 DCBX_APP_NUM_ENTRIES); 466 DCBX_APP_NUM_ENTRIES);
415 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) { 467 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
416 entry = &p_params->app_entry[i]; 468 entry = &p_params->app_entry[i];
417 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry, 469 if (ieee) {
418 DCBX_APP_SF)); 470 u8 sf_ieee;
471 u32 val;
472
473 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
474 DCBX_APP_SF_IEEE);
475 switch (sf_ieee) {
476 case DCBX_APP_SF_IEEE_RESERVED:
477 /* Old MFW */
478 val = QED_MFW_GET_FIELD(p_tbl[i].entry,
479 DCBX_APP_SF);
480 entry->sf_ieee = val ?
481 QED_DCBX_SF_IEEE_TCP_UDP_PORT :
482 QED_DCBX_SF_IEEE_ETHTYPE;
483 break;
484 case DCBX_APP_SF_IEEE_ETHTYPE:
485 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
486 break;
487 case DCBX_APP_SF_IEEE_TCP_PORT:
488 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
489 break;
490 case DCBX_APP_SF_IEEE_UDP_PORT:
491 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
492 break;
493 case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
494 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
495 break;
496 }
497 } else {
498 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
499 DCBX_APP_SF));
500 }
501
419 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP); 502 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
420 entry->prio = ffs(pri_map) - 1; 503 entry->prio = ffs(pri_map) - 1;
421 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry, 504 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
422 DCBX_APP_PROTOCOL_ID); 505 DCBX_APP_PROTOCOL_ID);
423 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry, 506 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
424 entry->proto_id, 507 entry->proto_id,
425 &entry->proto_type); 508 &entry->proto_type, ieee);
426 } 509 }
427 510
428 DP_VERBOSE(p_hwfn, QED_MSG_DCB, 511 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
@@ -483,7 +566,7 @@ qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
483 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]); 566 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
484 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]); 567 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
485 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]); 568 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
486 pri_map = be32_to_cpu(p_ets->pri_tc_tbl[0]); 569 pri_map = p_ets->pri_tc_tbl[0];
487 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) { 570 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
488 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i]; 571 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
489 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i]; 572 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
@@ -500,9 +583,9 @@ qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
500 struct dcbx_app_priority_feature *p_app, 583 struct dcbx_app_priority_feature *p_app,
501 struct dcbx_app_priority_entry *p_tbl, 584 struct dcbx_app_priority_entry *p_tbl,
502 struct dcbx_ets_feature *p_ets, 585 struct dcbx_ets_feature *p_ets,
503 u32 pfc, struct qed_dcbx_params *p_params) 586 u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
504{ 587{
505 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params); 588 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
506 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params); 589 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
507 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params); 590 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
508} 591}
@@ -516,7 +599,7 @@ qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn,
516 p_feat = &p_hwfn->p_dcbx_info->local_admin.features; 599 p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
517 qed_dcbx_get_common_params(p_hwfn, &p_feat->app, 600 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
518 p_feat->app.app_pri_tbl, &p_feat->ets, 601 p_feat->app.app_pri_tbl, &p_feat->ets,
519 p_feat->pfc, &params->local.params); 602 p_feat->pfc, &params->local.params, false);
520 params->local.valid = true; 603 params->local.valid = true;
521} 604}
522 605
@@ -529,7 +612,7 @@ qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn,
529 p_feat = &p_hwfn->p_dcbx_info->remote.features; 612 p_feat = &p_hwfn->p_dcbx_info->remote.features;
530 qed_dcbx_get_common_params(p_hwfn, &p_feat->app, 613 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
531 p_feat->app.app_pri_tbl, &p_feat->ets, 614 p_feat->app.app_pri_tbl, &p_feat->ets,
532 p_feat->pfc, &params->remote.params); 615 p_feat->pfc, &params->remote.params, false);
533 params->remote.valid = true; 616 params->remote.valid = true;
534} 617}
535 618
@@ -574,7 +657,8 @@ qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
574 657
575 qed_dcbx_get_common_params(p_hwfn, &p_feat->app, 658 qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
576 p_feat->app.app_pri_tbl, &p_feat->ets, 659 p_feat->app.app_pri_tbl, &p_feat->ets,
577 p_feat->pfc, &params->operational.params); 660 p_feat->pfc, &params->operational.params,
661 p_operational->ieee);
578 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results); 662 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
579 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR); 663 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
580 p_operational->err = err; 664 p_operational->err = err;
@@ -944,7 +1028,6 @@ qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
944 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4)); 1028 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
945 p_ets->pri_tc_tbl[0] |= val; 1029 p_ets->pri_tc_tbl[0] |= val;
946 } 1030 }
947 p_ets->pri_tc_tbl[0] = cpu_to_be32(p_ets->pri_tc_tbl[0]);
948 for (i = 0; i < 2; i++) { 1031 for (i = 0; i < 2; i++) {
949 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]); 1032 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
950 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]); 1033 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
@@ -954,7 +1037,7 @@ qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
954static void 1037static void
955qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn, 1038qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
956 struct dcbx_app_priority_feature *p_app, 1039 struct dcbx_app_priority_feature *p_app,
957 struct qed_dcbx_params *p_params) 1040 struct qed_dcbx_params *p_params, bool ieee)
958{ 1041{
959 u32 *entry; 1042 u32 *entry;
960 int i; 1043 int i;
@@ -975,12 +1058,36 @@ qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
975 1058
976 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) { 1059 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
977 entry = &p_app->app_pri_tbl[i].entry; 1060 entry = &p_app->app_pri_tbl[i].entry;
978 *entry &= ~DCBX_APP_SF_MASK; 1061 if (ieee) {
979 if (p_params->app_entry[i].ethtype) 1062 *entry &= ~DCBX_APP_SF_IEEE_MASK;
980 *entry |= ((u32)DCBX_APP_SF_ETHTYPE << 1063 switch (p_params->app_entry[i].sf_ieee) {
981 DCBX_APP_SF_SHIFT); 1064 case QED_DCBX_SF_IEEE_ETHTYPE:
982 else 1065 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
983 *entry |= ((u32)DCBX_APP_SF_PORT << DCBX_APP_SF_SHIFT); 1066 DCBX_APP_SF_IEEE_SHIFT);
1067 break;
1068 case QED_DCBX_SF_IEEE_TCP_PORT:
1069 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
1070 DCBX_APP_SF_IEEE_SHIFT);
1071 break;
1072 case QED_DCBX_SF_IEEE_UDP_PORT:
1073 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
1074 DCBX_APP_SF_IEEE_SHIFT);
1075 break;
1076 case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
1077 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
1078 DCBX_APP_SF_IEEE_SHIFT);
1079 break;
1080 }
1081 } else {
1082 *entry &= ~DCBX_APP_SF_MASK;
1083 if (p_params->app_entry[i].ethtype)
1084 *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
1085 DCBX_APP_SF_SHIFT);
1086 else
1087 *entry |= ((u32)DCBX_APP_SF_PORT <<
1088 DCBX_APP_SF_SHIFT);
1089 }
1090
984 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK; 1091 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
985 *entry |= ((u32)p_params->app_entry[i].proto_id << 1092 *entry |= ((u32)p_params->app_entry[i].proto_id <<
986 DCBX_APP_PROTOCOL_ID_SHIFT); 1093 DCBX_APP_PROTOCOL_ID_SHIFT);
@@ -995,15 +1102,19 @@ qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
995 struct dcbx_local_params *local_admin, 1102 struct dcbx_local_params *local_admin,
996 struct qed_dcbx_set *params) 1103 struct qed_dcbx_set *params)
997{ 1104{
1105 bool ieee = false;
1106
998 local_admin->flags = 0; 1107 local_admin->flags = 0;
999 memcpy(&local_admin->features, 1108 memcpy(&local_admin->features,
1000 &p_hwfn->p_dcbx_info->operational.features, 1109 &p_hwfn->p_dcbx_info->operational.features,
1001 sizeof(local_admin->features)); 1110 sizeof(local_admin->features));
1002 1111
1003 if (params->enabled) 1112 if (params->enabled) {
1004 local_admin->config = params->ver_num; 1113 local_admin->config = params->ver_num;
1005 else 1114 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
1115 } else {
1006 local_admin->config = DCBX_CONFIG_VERSION_DISABLED; 1116 local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
1117 }
1007 1118
1008 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG) 1119 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
1009 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc, 1120 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
@@ -1015,7 +1126,7 @@ qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
1015 1126
1016 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG) 1127 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
1017 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app, 1128 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
1018 &params->config.params); 1129 &params->config.params, ieee);
1019} 1130}
1020 1131
1021int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 1132int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
@@ -1596,8 +1707,10 @@ static int qed_dcbnl_setapp(struct qed_dev *cdev,
1596 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) 1707 if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
1597 break; 1708 break;
1598 /* First empty slot */ 1709 /* First empty slot */
1599 if (!entry->proto_id) 1710 if (!entry->proto_id) {
1711 dcbx_set.config.params.num_app_entries++;
1600 break; 1712 break;
1713 }
1601 } 1714 }
1602 1715
1603 if (i == QED_DCBX_MAX_APP_PROTOCOL) { 1716 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
@@ -2117,8 +2230,10 @@ int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
2117 (entry->proto_id == app->protocol)) 2230 (entry->proto_id == app->protocol))
2118 break; 2231 break;
2119 /* First empty slot */ 2232 /* First empty slot */
2120 if (!entry->proto_id) 2233 if (!entry->proto_id) {
2234 dcbx_set.config.params.num_app_entries++;
2121 break; 2235 break;
2236 }
2122 } 2237 }
2123 2238
2124 if (i == QED_DCBX_MAX_APP_PROTOCOL) { 2239 if (i == QED_DCBX_MAX_APP_PROTOCOL) {
diff --git a/drivers/net/ethernet/qlogic/qed/qed_hsi.h b/drivers/net/ethernet/qlogic/qed/qed_hsi.h
index 592784019994..6f9d3b831a2a 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_hsi.h
+++ b/drivers/net/ethernet/qlogic/qed/qed_hsi.h
@@ -6850,6 +6850,14 @@ struct dcbx_app_priority_entry {
6850#define DCBX_APP_SF_SHIFT 8 6850#define DCBX_APP_SF_SHIFT 8
6851#define DCBX_APP_SF_ETHTYPE 0 6851#define DCBX_APP_SF_ETHTYPE 0
6852#define DCBX_APP_SF_PORT 1 6852#define DCBX_APP_SF_PORT 1
6853#define DCBX_APP_SF_IEEE_MASK 0x0000f000
6854#define DCBX_APP_SF_IEEE_SHIFT 12
6855#define DCBX_APP_SF_IEEE_RESERVED 0
6856#define DCBX_APP_SF_IEEE_ETHTYPE 1
6857#define DCBX_APP_SF_IEEE_TCP_PORT 2
6858#define DCBX_APP_SF_IEEE_UDP_PORT 3
6859#define DCBX_APP_SF_IEEE_TCP_UDP_PORT 4
6860
6853#define DCBX_APP_PROTOCOL_ID_MASK 0xffff0000 6861#define DCBX_APP_PROTOCOL_ID_MASK 0xffff0000
6854#define DCBX_APP_PROTOCOL_ID_SHIFT 16 6862#define DCBX_APP_PROTOCOL_ID_SHIFT 16
6855}; 6863};
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h b/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h
index fd973f4f16c7..49bad00a0f8f 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic.h
@@ -37,8 +37,8 @@
37 37
38#define _QLCNIC_LINUX_MAJOR 5 38#define _QLCNIC_LINUX_MAJOR 5
39#define _QLCNIC_LINUX_MINOR 3 39#define _QLCNIC_LINUX_MINOR 3
40#define _QLCNIC_LINUX_SUBVERSION 64 40#define _QLCNIC_LINUX_SUBVERSION 65
41#define QLCNIC_LINUX_VERSIONID "5.3.64" 41#define QLCNIC_LINUX_VERSIONID "5.3.65"
42#define QLCNIC_DRV_IDC_VER 0x01 42#define QLCNIC_DRV_IDC_VER 0x01
43#define QLCNIC_DRIVER_VERSION ((_QLCNIC_LINUX_MAJOR << 16) |\ 43#define QLCNIC_DRIVER_VERSION ((_QLCNIC_LINUX_MAJOR << 16) |\
44 (_QLCNIC_LINUX_MINOR << 8) | (_QLCNIC_LINUX_SUBVERSION)) 44 (_QLCNIC_LINUX_MINOR << 8) | (_QLCNIC_LINUX_SUBVERSION))
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
index 87c642d3b075..fedd7366713c 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
@@ -102,7 +102,6 @@
102#define QLCNIC_RESPONSE_DESC 0x05 102#define QLCNIC_RESPONSE_DESC 0x05
103#define QLCNIC_LRO_DESC 0x12 103#define QLCNIC_LRO_DESC 0x12
104 104
105#define QLCNIC_TX_POLL_BUDGET 128
106#define QLCNIC_TCP_HDR_SIZE 20 105#define QLCNIC_TCP_HDR_SIZE 20
107#define QLCNIC_TCP_TS_OPTION_SIZE 12 106#define QLCNIC_TCP_TS_OPTION_SIZE 12
108#define QLCNIC_FETCH_RING_ID(handle) ((handle) >> 63) 107#define QLCNIC_FETCH_RING_ID(handle) ((handle) >> 63)
@@ -2008,7 +2007,6 @@ static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget)
2008 struct qlcnic_host_tx_ring *tx_ring; 2007 struct qlcnic_host_tx_ring *tx_ring;
2009 struct qlcnic_adapter *adapter; 2008 struct qlcnic_adapter *adapter;
2010 2009
2011 budget = QLCNIC_TX_POLL_BUDGET;
2012 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi); 2010 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
2013 adapter = tx_ring->adapter; 2011 adapter = tx_ring->adapter;
2014 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget); 2012 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov.h b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov.h
index 017d8c2c8285..24061b9b92e8 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov.h
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov.h
@@ -156,10 +156,8 @@ struct qlcnic_vf_info {
156 spinlock_t vlan_list_lock; /* Lock for VLAN list */ 156 spinlock_t vlan_list_lock; /* Lock for VLAN list */
157}; 157};
158 158
159struct qlcnic_async_work_list { 159struct qlcnic_async_cmd {
160 struct list_head list; 160 struct list_head list;
161 struct work_struct work;
162 void *ptr;
163 struct qlcnic_cmd_args *cmd; 161 struct qlcnic_cmd_args *cmd;
164}; 162};
165 163
@@ -168,7 +166,10 @@ struct qlcnic_back_channel {
168 struct workqueue_struct *bc_trans_wq; 166 struct workqueue_struct *bc_trans_wq;
169 struct workqueue_struct *bc_async_wq; 167 struct workqueue_struct *bc_async_wq;
170 struct workqueue_struct *bc_flr_wq; 168 struct workqueue_struct *bc_flr_wq;
171 struct list_head async_list; 169 struct qlcnic_adapter *adapter;
170 struct list_head async_cmd_list;
171 struct work_struct vf_async_work;
172 spinlock_t queue_lock; /* async_cmd_list queue lock */
172}; 173};
173 174
174struct qlcnic_sriov { 175struct qlcnic_sriov {
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
index 7327b729ba2e..d7107055ec60 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
@@ -29,6 +29,7 @@
29#define QLC_83XX_VF_RESET_FAIL_THRESH 8 29#define QLC_83XX_VF_RESET_FAIL_THRESH 8
30#define QLC_BC_CMD_MAX_RETRY_CNT 5 30#define QLC_BC_CMD_MAX_RETRY_CNT 5
31 31
32static void qlcnic_sriov_handle_async_issue_cmd(struct work_struct *work);
32static void qlcnic_sriov_vf_free_mac_list(struct qlcnic_adapter *); 33static void qlcnic_sriov_vf_free_mac_list(struct qlcnic_adapter *);
33static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args *, u32); 34static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args *, u32);
34static void qlcnic_sriov_vf_poll_dev_state(struct work_struct *); 35static void qlcnic_sriov_vf_poll_dev_state(struct work_struct *);
@@ -177,7 +178,10 @@ int qlcnic_sriov_init(struct qlcnic_adapter *adapter, int num_vfs)
177 } 178 }
178 179
179 bc->bc_async_wq = wq; 180 bc->bc_async_wq = wq;
180 INIT_LIST_HEAD(&bc->async_list); 181 INIT_LIST_HEAD(&bc->async_cmd_list);
182 INIT_WORK(&bc->vf_async_work, qlcnic_sriov_handle_async_issue_cmd);
183 spin_lock_init(&bc->queue_lock);
184 bc->adapter = adapter;
181 185
182 for (i = 0; i < num_vfs; i++) { 186 for (i = 0; i < num_vfs; i++) {
183 vf = &sriov->vf_info[i]; 187 vf = &sriov->vf_info[i];
@@ -1517,17 +1521,21 @@ static void qlcnic_vf_add_mc_list(struct net_device *netdev, const u8 *mac,
1517 1521
1518void qlcnic_sriov_cleanup_async_list(struct qlcnic_back_channel *bc) 1522void qlcnic_sriov_cleanup_async_list(struct qlcnic_back_channel *bc)
1519{ 1523{
1520 struct list_head *head = &bc->async_list; 1524 struct list_head *head = &bc->async_cmd_list;
1521 struct qlcnic_async_work_list *entry; 1525 struct qlcnic_async_cmd *entry;
1522 1526
1523 flush_workqueue(bc->bc_async_wq); 1527 flush_workqueue(bc->bc_async_wq);
1528 cancel_work_sync(&bc->vf_async_work);
1529
1530 spin_lock(&bc->queue_lock);
1524 while (!list_empty(head)) { 1531 while (!list_empty(head)) {
1525 entry = list_entry(head->next, struct qlcnic_async_work_list, 1532 entry = list_entry(head->next, struct qlcnic_async_cmd,
1526 list); 1533 list);
1527 cancel_work_sync(&entry->work);
1528 list_del(&entry->list); 1534 list_del(&entry->list);
1535 kfree(entry->cmd);
1529 kfree(entry); 1536 kfree(entry);
1530 } 1537 }
1538 spin_unlock(&bc->queue_lock);
1531} 1539}
1532 1540
1533void qlcnic_sriov_vf_set_multi(struct net_device *netdev) 1541void qlcnic_sriov_vf_set_multi(struct net_device *netdev)
@@ -1587,57 +1595,64 @@ void qlcnic_sriov_vf_set_multi(struct net_device *netdev)
1587 1595
1588static void qlcnic_sriov_handle_async_issue_cmd(struct work_struct *work) 1596static void qlcnic_sriov_handle_async_issue_cmd(struct work_struct *work)
1589{ 1597{
1590 struct qlcnic_async_work_list *entry; 1598 struct qlcnic_async_cmd *entry, *tmp;
1591 struct qlcnic_adapter *adapter; 1599 struct qlcnic_back_channel *bc;
1592 struct qlcnic_cmd_args *cmd; 1600 struct qlcnic_cmd_args *cmd;
1601 struct list_head *head;
1602 LIST_HEAD(del_list);
1603
1604 bc = container_of(work, struct qlcnic_back_channel, vf_async_work);
1605 head = &bc->async_cmd_list;
1606
1607 spin_lock(&bc->queue_lock);
1608 list_splice_init(head, &del_list);
1609 spin_unlock(&bc->queue_lock);
1610
1611 list_for_each_entry_safe(entry, tmp, &del_list, list) {
1612 list_del(&entry->list);
1613 cmd = entry->cmd;
1614 __qlcnic_sriov_issue_cmd(bc->adapter, cmd);
1615 kfree(entry);
1616 }
1617
1618 if (!list_empty(head))
1619 queue_work(bc->bc_async_wq, &bc->vf_async_work);
1593 1620
1594 entry = container_of(work, struct qlcnic_async_work_list, work);
1595 adapter = entry->ptr;
1596 cmd = entry->cmd;
1597 __qlcnic_sriov_issue_cmd(adapter, cmd);
1598 return; 1621 return;
1599} 1622}
1600 1623
1601static struct qlcnic_async_work_list * 1624static struct qlcnic_async_cmd *
1602qlcnic_sriov_get_free_node_async_work(struct qlcnic_back_channel *bc) 1625qlcnic_sriov_alloc_async_cmd(struct qlcnic_back_channel *bc,
1626 struct qlcnic_cmd_args *cmd)
1603{ 1627{
1604 struct list_head *node; 1628 struct qlcnic_async_cmd *entry = NULL;
1605 struct qlcnic_async_work_list *entry = NULL;
1606 u8 empty = 0;
1607 1629
1608 list_for_each(node, &bc->async_list) { 1630 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
1609 entry = list_entry(node, struct qlcnic_async_work_list, list); 1631 if (!entry)
1610 if (!work_pending(&entry->work)) { 1632 return NULL;
1611 empty = 1;
1612 break;
1613 }
1614 }
1615 1633
1616 if (!empty) { 1634 entry->cmd = cmd;
1617 entry = kzalloc(sizeof(struct qlcnic_async_work_list), 1635
1618 GFP_ATOMIC); 1636 spin_lock(&bc->queue_lock);
1619 if (entry == NULL) 1637 list_add_tail(&entry->list, &bc->async_cmd_list);
1620 return NULL; 1638 spin_unlock(&bc->queue_lock);
1621 list_add_tail(&entry->list, &bc->async_list);
1622 }
1623 1639
1624 return entry; 1640 return entry;
1625} 1641}
1626 1642
1627static void qlcnic_sriov_schedule_async_cmd(struct qlcnic_back_channel *bc, 1643static void qlcnic_sriov_schedule_async_cmd(struct qlcnic_back_channel *bc,
1628 work_func_t func, void *data,
1629 struct qlcnic_cmd_args *cmd) 1644 struct qlcnic_cmd_args *cmd)
1630{ 1645{
1631 struct qlcnic_async_work_list *entry = NULL; 1646 struct qlcnic_async_cmd *entry = NULL;
1632 1647
1633 entry = qlcnic_sriov_get_free_node_async_work(bc); 1648 entry = qlcnic_sriov_alloc_async_cmd(bc, cmd);
1634 if (!entry) 1649 if (!entry) {
1650 qlcnic_free_mbx_args(cmd);
1651 kfree(cmd);
1635 return; 1652 return;
1653 }
1636 1654
1637 entry->ptr = data; 1655 queue_work(bc->bc_async_wq, &bc->vf_async_work);
1638 entry->cmd = cmd;
1639 INIT_WORK(&entry->work, func);
1640 queue_work(bc->bc_async_wq, &entry->work);
1641} 1656}
1642 1657
1643static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter *adapter, 1658static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter *adapter,
@@ -1649,8 +1664,8 @@ static int qlcnic_sriov_async_issue_cmd(struct qlcnic_adapter *adapter,
1649 if (adapter->need_fw_reset) 1664 if (adapter->need_fw_reset)
1650 return -EIO; 1665 return -EIO;
1651 1666
1652 qlcnic_sriov_schedule_async_cmd(bc, qlcnic_sriov_handle_async_issue_cmd, 1667 qlcnic_sriov_schedule_async_cmd(bc, cmd);
1653 adapter, cmd); 1668
1654 return 0; 1669 return 0;
1655} 1670}
1656 1671
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index c51f34693eae..f85d605e4560 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -734,6 +734,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
734 netif_receive_skb(skb); 734 netif_receive_skb(skb);
735 ndev->stats.rx_bytes += len; 735 ndev->stats.rx_bytes += len;
736 ndev->stats.rx_packets++; 736 ndev->stats.rx_packets++;
737 kmemleak_not_leak(new_skb);
737 } else { 738 } else {
738 ndev->stats.rx_dropped++; 739 ndev->stats.rx_dropped++;
739 new_skb = skb; 740 new_skb = skb;
@@ -1325,6 +1326,7 @@ static int cpsw_ndo_open(struct net_device *ndev)
1325 kfree_skb(skb); 1326 kfree_skb(skb);
1326 goto err_cleanup; 1327 goto err_cleanup;
1327 } 1328 }
1329 kmemleak_not_leak(skb);
1328 } 1330 }
1329 /* continue even if we didn't manage to submit all 1331 /* continue even if we didn't manage to submit all
1330 * receive descs 1332 * receive descs
diff --git a/drivers/net/ethernet/tundra/tsi108_eth.c b/drivers/net/ethernet/tundra/tsi108_eth.c
index 01a77145a0fa..8fd131207ee1 100644
--- a/drivers/net/ethernet/tundra/tsi108_eth.c
+++ b/drivers/net/ethernet/tundra/tsi108_eth.c
@@ -166,6 +166,7 @@ static struct platform_driver tsi_eth_driver = {
166 166
167static void tsi108_timed_checker(unsigned long dev_ptr); 167static void tsi108_timed_checker(unsigned long dev_ptr);
168 168
169#ifdef DEBUG
169static void dump_eth_one(struct net_device *dev) 170static void dump_eth_one(struct net_device *dev)
170{ 171{
171 struct tsi108_prv_data *data = netdev_priv(dev); 172 struct tsi108_prv_data *data = netdev_priv(dev);
@@ -190,6 +191,7 @@ static void dump_eth_one(struct net_device *dev)
190 TSI_READ(TSI108_EC_RXESTAT), 191 TSI_READ(TSI108_EC_RXESTAT),
191 TSI_READ(TSI108_EC_RXERR), data->rxpending); 192 TSI_READ(TSI108_EC_RXERR), data->rxpending);
192} 193}
194#endif
193 195
194/* Synchronization is needed between the thread and up/down events. 196/* Synchronization is needed between the thread and up/down events.
195 * Note that the PHY is accessed through the same registers for both 197 * Note that the PHY is accessed through the same registers for both
diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 467fb8b4d083..591af71eae56 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -644,12 +644,6 @@ struct netvsc_reconfig {
644 u32 event; 644 u32 event;
645}; 645};
646 646
647struct garp_wrk {
648 struct work_struct dwrk;
649 struct net_device *netdev;
650 struct netvsc_device *netvsc_dev;
651};
652
653/* The context of the netvsc device */ 647/* The context of the netvsc device */
654struct net_device_context { 648struct net_device_context {
655 /* point back to our device context */ 649 /* point back to our device context */
@@ -667,7 +661,6 @@ struct net_device_context {
667 661
668 struct work_struct work; 662 struct work_struct work;
669 u32 msg_enable; /* debug level */ 663 u32 msg_enable; /* debug level */
670 struct garp_wrk gwrk;
671 664
672 struct netvsc_stats __percpu *tx_stats; 665 struct netvsc_stats __percpu *tx_stats;
673 struct netvsc_stats __percpu *rx_stats; 666 struct netvsc_stats __percpu *rx_stats;
@@ -678,6 +671,15 @@ struct net_device_context {
678 671
679 /* the device is going away */ 672 /* the device is going away */
680 bool start_remove; 673 bool start_remove;
674
675 /* State to manage the associated VF interface. */
676 struct net_device *vf_netdev;
677 bool vf_inject;
678 atomic_t vf_use_cnt;
679 /* 1: allocated, serial number is valid. 0: not allocated */
680 u32 vf_alloc;
681 /* Serial number of the VF to team with */
682 u32 vf_serial;
681}; 683};
682 684
683/* Per netvsc device */ 685/* Per netvsc device */
@@ -733,15 +735,7 @@ struct netvsc_device {
733 u32 max_pkt; /* max number of pkt in one send, e.g. 8 */ 735 u32 max_pkt; /* max number of pkt in one send, e.g. 8 */
734 u32 pkt_align; /* alignment bytes, e.g. 8 */ 736 u32 pkt_align; /* alignment bytes, e.g. 8 */
735 737
736 /* 1: allocated, serial number is valid. 0: not allocated */
737 u32 vf_alloc;
738 /* Serial number of the VF to team with */
739 u32 vf_serial;
740 atomic_t open_cnt; 738 atomic_t open_cnt;
741 /* State to manage the associated VF interface. */
742 bool vf_inject;
743 struct net_device *vf_netdev;
744 atomic_t vf_use_cnt;
745}; 739};
746 740
747static inline struct netvsc_device * 741static inline struct netvsc_device *
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 20e09174ff62..410fb8e81376 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -77,13 +77,9 @@ static struct netvsc_device *alloc_net_device(void)
77 init_waitqueue_head(&net_device->wait_drain); 77 init_waitqueue_head(&net_device->wait_drain);
78 net_device->destroy = false; 78 net_device->destroy = false;
79 atomic_set(&net_device->open_cnt, 0); 79 atomic_set(&net_device->open_cnt, 0);
80 atomic_set(&net_device->vf_use_cnt, 0);
81 net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT; 80 net_device->max_pkt = RNDIS_MAX_PKT_DEFAULT;
82 net_device->pkt_align = RNDIS_PKT_ALIGN_DEFAULT; 81 net_device->pkt_align = RNDIS_PKT_ALIGN_DEFAULT;
83 82
84 net_device->vf_netdev = NULL;
85 net_device->vf_inject = false;
86
87 return net_device; 83 return net_device;
88} 84}
89 85
@@ -1106,16 +1102,16 @@ static void netvsc_send_table(struct hv_device *hdev,
1106 nvscdev->send_table[i] = tab[i]; 1102 nvscdev->send_table[i] = tab[i];
1107} 1103}
1108 1104
1109static void netvsc_send_vf(struct netvsc_device *nvdev, 1105static void netvsc_send_vf(struct net_device_context *net_device_ctx,
1110 struct nvsp_message *nvmsg) 1106 struct nvsp_message *nvmsg)
1111{ 1107{
1112 nvdev->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated; 1108 net_device_ctx->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated;
1113 nvdev->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial; 1109 net_device_ctx->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial;
1114} 1110}
1115 1111
1116static inline void netvsc_receive_inband(struct hv_device *hdev, 1112static inline void netvsc_receive_inband(struct hv_device *hdev,
1117 struct netvsc_device *nvdev, 1113 struct net_device_context *net_device_ctx,
1118 struct nvsp_message *nvmsg) 1114 struct nvsp_message *nvmsg)
1119{ 1115{
1120 switch (nvmsg->hdr.msg_type) { 1116 switch (nvmsg->hdr.msg_type) {
1121 case NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE: 1117 case NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE:
@@ -1123,7 +1119,7 @@ static inline void netvsc_receive_inband(struct hv_device *hdev,
1123 break; 1119 break;
1124 1120
1125 case NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION: 1121 case NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION:
1126 netvsc_send_vf(nvdev, nvmsg); 1122 netvsc_send_vf(net_device_ctx, nvmsg);
1127 break; 1123 break;
1128 } 1124 }
1129} 1125}
@@ -1136,6 +1132,7 @@ static void netvsc_process_raw_pkt(struct hv_device *device,
1136 struct vmpacket_descriptor *desc) 1132 struct vmpacket_descriptor *desc)
1137{ 1133{
1138 struct nvsp_message *nvmsg; 1134 struct nvsp_message *nvmsg;
1135 struct net_device_context *net_device_ctx = netdev_priv(ndev);
1139 1136
1140 nvmsg = (struct nvsp_message *)((unsigned long) 1137 nvmsg = (struct nvsp_message *)((unsigned long)
1141 desc + (desc->offset8 << 3)); 1138 desc + (desc->offset8 << 3));
@@ -1150,7 +1147,7 @@ static void netvsc_process_raw_pkt(struct hv_device *device,
1150 break; 1147 break;
1151 1148
1152 case VM_PKT_DATA_INBAND: 1149 case VM_PKT_DATA_INBAND:
1153 netvsc_receive_inband(device, net_device, nvmsg); 1150 netvsc_receive_inband(device, net_device_ctx, nvmsg);
1154 break; 1151 break;
1155 1152
1156 default: 1153 default:
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 41bd952cc28d..3ba29fc80d05 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -658,20 +658,19 @@ int netvsc_recv_callback(struct hv_device *device_obj,
658 struct sk_buff *skb; 658 struct sk_buff *skb;
659 struct sk_buff *vf_skb; 659 struct sk_buff *vf_skb;
660 struct netvsc_stats *rx_stats; 660 struct netvsc_stats *rx_stats;
661 struct netvsc_device *netvsc_dev = net_device_ctx->nvdev;
662 u32 bytes_recvd = packet->total_data_buflen; 661 u32 bytes_recvd = packet->total_data_buflen;
663 int ret = 0; 662 int ret = 0;
664 663
665 if (!net || net->reg_state != NETREG_REGISTERED) 664 if (!net || net->reg_state != NETREG_REGISTERED)
666 return NVSP_STAT_FAIL; 665 return NVSP_STAT_FAIL;
667 666
668 if (READ_ONCE(netvsc_dev->vf_inject)) { 667 if (READ_ONCE(net_device_ctx->vf_inject)) {
669 atomic_inc(&netvsc_dev->vf_use_cnt); 668 atomic_inc(&net_device_ctx->vf_use_cnt);
670 if (!READ_ONCE(netvsc_dev->vf_inject)) { 669 if (!READ_ONCE(net_device_ctx->vf_inject)) {
671 /* 670 /*
672 * We raced; just move on. 671 * We raced; just move on.
673 */ 672 */
674 atomic_dec(&netvsc_dev->vf_use_cnt); 673 atomic_dec(&net_device_ctx->vf_use_cnt);
675 goto vf_injection_done; 674 goto vf_injection_done;
676 } 675 }
677 676
@@ -683,17 +682,19 @@ int netvsc_recv_callback(struct hv_device *device_obj,
683 * the host). Deliver these via the VF interface 682 * the host). Deliver these via the VF interface
684 * in the guest. 683 * in the guest.
685 */ 684 */
686 vf_skb = netvsc_alloc_recv_skb(netvsc_dev->vf_netdev, packet, 685 vf_skb = netvsc_alloc_recv_skb(net_device_ctx->vf_netdev,
687 csum_info, *data, vlan_tci); 686 packet, csum_info, *data,
687 vlan_tci);
688 if (vf_skb != NULL) { 688 if (vf_skb != NULL) {
689 ++netvsc_dev->vf_netdev->stats.rx_packets; 689 ++net_device_ctx->vf_netdev->stats.rx_packets;
690 netvsc_dev->vf_netdev->stats.rx_bytes += bytes_recvd; 690 net_device_ctx->vf_netdev->stats.rx_bytes +=
691 bytes_recvd;
691 netif_receive_skb(vf_skb); 692 netif_receive_skb(vf_skb);
692 } else { 693 } else {
693 ++net->stats.rx_dropped; 694 ++net->stats.rx_dropped;
694 ret = NVSP_STAT_FAIL; 695 ret = NVSP_STAT_FAIL;
695 } 696 }
696 atomic_dec(&netvsc_dev->vf_use_cnt); 697 atomic_dec(&net_device_ctx->vf_use_cnt);
697 return ret; 698 return ret;
698 } 699 }
699 700
@@ -1150,17 +1151,6 @@ static void netvsc_free_netdev(struct net_device *netdev)
1150 free_netdev(netdev); 1151 free_netdev(netdev);
1151} 1152}
1152 1153
1153static void netvsc_notify_peers(struct work_struct *wrk)
1154{
1155 struct garp_wrk *gwrk;
1156
1157 gwrk = container_of(wrk, struct garp_wrk, dwrk);
1158
1159 netdev_notify_peers(gwrk->netdev);
1160
1161 atomic_dec(&gwrk->netvsc_dev->vf_use_cnt);
1162}
1163
1164static struct net_device *get_netvsc_net_device(char *mac) 1154static struct net_device *get_netvsc_net_device(char *mac)
1165{ 1155{
1166 struct net_device *dev, *found = NULL; 1156 struct net_device *dev, *found = NULL;
@@ -1203,7 +1193,7 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
1203 1193
1204 net_device_ctx = netdev_priv(ndev); 1194 net_device_ctx = netdev_priv(ndev);
1205 netvsc_dev = net_device_ctx->nvdev; 1195 netvsc_dev = net_device_ctx->nvdev;
1206 if (netvsc_dev == NULL) 1196 if (!netvsc_dev || net_device_ctx->vf_netdev)
1207 return NOTIFY_DONE; 1197 return NOTIFY_DONE;
1208 1198
1209 netdev_info(ndev, "VF registering: %s\n", vf_netdev->name); 1199 netdev_info(ndev, "VF registering: %s\n", vf_netdev->name);
@@ -1211,10 +1201,23 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
1211 * Take a reference on the module. 1201 * Take a reference on the module.
1212 */ 1202 */
1213 try_module_get(THIS_MODULE); 1203 try_module_get(THIS_MODULE);
1214 netvsc_dev->vf_netdev = vf_netdev; 1204 net_device_ctx->vf_netdev = vf_netdev;
1215 return NOTIFY_OK; 1205 return NOTIFY_OK;
1216} 1206}
1217 1207
1208static void netvsc_inject_enable(struct net_device_context *net_device_ctx)
1209{
1210 net_device_ctx->vf_inject = true;
1211}
1212
1213static void netvsc_inject_disable(struct net_device_context *net_device_ctx)
1214{
1215 net_device_ctx->vf_inject = false;
1216
1217 /* Wait for currently active users to drain out. */
1218 while (atomic_read(&net_device_ctx->vf_use_cnt) != 0)
1219 udelay(50);
1220}
1218 1221
1219static int netvsc_vf_up(struct net_device *vf_netdev) 1222static int netvsc_vf_up(struct net_device *vf_netdev)
1220{ 1223{
@@ -1233,11 +1236,11 @@ static int netvsc_vf_up(struct net_device *vf_netdev)
1233 net_device_ctx = netdev_priv(ndev); 1236 net_device_ctx = netdev_priv(ndev);
1234 netvsc_dev = net_device_ctx->nvdev; 1237 netvsc_dev = net_device_ctx->nvdev;
1235 1238
1236 if ((netvsc_dev == NULL) || (netvsc_dev->vf_netdev == NULL)) 1239 if (!netvsc_dev || !net_device_ctx->vf_netdev)
1237 return NOTIFY_DONE; 1240 return NOTIFY_DONE;
1238 1241
1239 netdev_info(ndev, "VF up: %s\n", vf_netdev->name); 1242 netdev_info(ndev, "VF up: %s\n", vf_netdev->name);
1240 netvsc_dev->vf_inject = true; 1243 netvsc_inject_enable(net_device_ctx);
1241 1244
1242 /* 1245 /*
1243 * Open the device before switching data path. 1246 * Open the device before switching data path.
@@ -1252,15 +1255,8 @@ static int netvsc_vf_up(struct net_device *vf_netdev)
1252 1255
1253 netif_carrier_off(ndev); 1256 netif_carrier_off(ndev);
1254 1257
1255 /* 1258 /* Now notify peers through VF device. */
1256 * Now notify peers. We are scheduling work to 1259 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, vf_netdev);
1257 * notify peers; take a reference to prevent
1258 * the VF interface from vanishing.
1259 */
1260 atomic_inc(&netvsc_dev->vf_use_cnt);
1261 net_device_ctx->gwrk.netdev = vf_netdev;
1262 net_device_ctx->gwrk.netvsc_dev = netvsc_dev;
1263 schedule_work(&net_device_ctx->gwrk.dwrk);
1264 1260
1265 return NOTIFY_OK; 1261 return NOTIFY_OK;
1266} 1262}
@@ -1283,29 +1279,18 @@ static int netvsc_vf_down(struct net_device *vf_netdev)
1283 net_device_ctx = netdev_priv(ndev); 1279 net_device_ctx = netdev_priv(ndev);
1284 netvsc_dev = net_device_ctx->nvdev; 1280 netvsc_dev = net_device_ctx->nvdev;
1285 1281
1286 if ((netvsc_dev == NULL) || (netvsc_dev->vf_netdev == NULL)) 1282 if (!netvsc_dev || !net_device_ctx->vf_netdev)
1287 return NOTIFY_DONE; 1283 return NOTIFY_DONE;
1288 1284
1289 netdev_info(ndev, "VF down: %s\n", vf_netdev->name); 1285 netdev_info(ndev, "VF down: %s\n", vf_netdev->name);
1290 netvsc_dev->vf_inject = false; 1286 netvsc_inject_disable(net_device_ctx);
1291 /*
1292 * Wait for currently active users to
1293 * drain out.
1294 */
1295
1296 while (atomic_read(&netvsc_dev->vf_use_cnt) != 0)
1297 udelay(50);
1298 netvsc_switch_datapath(ndev, false); 1287 netvsc_switch_datapath(ndev, false);
1299 netdev_info(ndev, "Data path switched from VF: %s\n", vf_netdev->name); 1288 netdev_info(ndev, "Data path switched from VF: %s\n", vf_netdev->name);
1300 rndis_filter_close(netvsc_dev); 1289 rndis_filter_close(netvsc_dev);
1301 netif_carrier_on(ndev); 1290 netif_carrier_on(ndev);
1302 /* 1291
1303 * Notify peers. 1292 /* Now notify peers through netvsc device. */
1304 */ 1293 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, ndev);
1305 atomic_inc(&netvsc_dev->vf_use_cnt);
1306 net_device_ctx->gwrk.netdev = ndev;
1307 net_device_ctx->gwrk.netvsc_dev = netvsc_dev;
1308 schedule_work(&net_device_ctx->gwrk.dwrk);
1309 1294
1310 return NOTIFY_OK; 1295 return NOTIFY_OK;
1311} 1296}
@@ -1327,11 +1312,11 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)
1327 1312
1328 net_device_ctx = netdev_priv(ndev); 1313 net_device_ctx = netdev_priv(ndev);
1329 netvsc_dev = net_device_ctx->nvdev; 1314 netvsc_dev = net_device_ctx->nvdev;
1330 if (netvsc_dev == NULL) 1315 if (!netvsc_dev || !net_device_ctx->vf_netdev)
1331 return NOTIFY_DONE; 1316 return NOTIFY_DONE;
1332 netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name); 1317 netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name);
1333 1318 netvsc_inject_disable(net_device_ctx);
1334 netvsc_dev->vf_netdev = NULL; 1319 net_device_ctx->vf_netdev = NULL;
1335 module_put(THIS_MODULE); 1320 module_put(THIS_MODULE);
1336 return NOTIFY_OK; 1321 return NOTIFY_OK;
1337} 1322}
@@ -1377,11 +1362,14 @@ static int netvsc_probe(struct hv_device *dev,
1377 1362
1378 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change); 1363 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change);
1379 INIT_WORK(&net_device_ctx->work, do_set_multicast); 1364 INIT_WORK(&net_device_ctx->work, do_set_multicast);
1380 INIT_WORK(&net_device_ctx->gwrk.dwrk, netvsc_notify_peers);
1381 1365
1382 spin_lock_init(&net_device_ctx->lock); 1366 spin_lock_init(&net_device_ctx->lock);
1383 INIT_LIST_HEAD(&net_device_ctx->reconfig_events); 1367 INIT_LIST_HEAD(&net_device_ctx->reconfig_events);
1384 1368
1369 atomic_set(&net_device_ctx->vf_use_cnt, 0);
1370 net_device_ctx->vf_netdev = NULL;
1371 net_device_ctx->vf_inject = false;
1372
1385 net->netdev_ops = &device_ops; 1373 net->netdev_ops = &device_ops;
1386 1374
1387 net->hw_features = NETVSC_HW_FEATURES; 1375 net->hw_features = NETVSC_HW_FEATURES;
@@ -1494,8 +1482,13 @@ static int netvsc_netdev_event(struct notifier_block *this,
1494{ 1482{
1495 struct net_device *event_dev = netdev_notifier_info_to_dev(ptr); 1483 struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
1496 1484
1497 /* Avoid Vlan, Bonding dev with same MAC registering as VF */ 1485 /* Avoid Vlan dev with same MAC registering as VF */
1498 if (event_dev->priv_flags & (IFF_802_1Q_VLAN | IFF_BONDING)) 1486 if (event_dev->priv_flags & IFF_802_1Q_VLAN)
1487 return NOTIFY_DONE;
1488
1489 /* Avoid Bonding master dev with same MAC registering as VF */
1490 if (event_dev->priv_flags & IFF_BONDING &&
1491 event_dev->flags & IFF_MASTER)
1499 return NOTIFY_DONE; 1492 return NOTIFY_DONE;
1500 1493
1501 switch (event) { 1494 switch (event) {
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index d13e6e15d7b5..351e701eb043 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -270,6 +270,7 @@ struct macsec_dev {
270 struct pcpu_secy_stats __percpu *stats; 270 struct pcpu_secy_stats __percpu *stats;
271 struct list_head secys; 271 struct list_head secys;
272 struct gro_cells gro_cells; 272 struct gro_cells gro_cells;
273 unsigned int nest_level;
273}; 274};
274 275
275/** 276/**
@@ -2699,6 +2700,8 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
2699 2700
2700#define MACSEC_FEATURES \ 2701#define MACSEC_FEATURES \
2701 (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST) 2702 (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
2703static struct lock_class_key macsec_netdev_addr_lock_key;
2704
2702static int macsec_dev_init(struct net_device *dev) 2705static int macsec_dev_init(struct net_device *dev)
2703{ 2706{
2704 struct macsec_dev *macsec = macsec_priv(dev); 2707 struct macsec_dev *macsec = macsec_priv(dev);
@@ -2910,6 +2913,13 @@ static int macsec_get_iflink(const struct net_device *dev)
2910 return macsec_priv(dev)->real_dev->ifindex; 2913 return macsec_priv(dev)->real_dev->ifindex;
2911} 2914}
2912 2915
2916
2917static int macsec_get_nest_level(struct net_device *dev)
2918{
2919 return macsec_priv(dev)->nest_level;
2920}
2921
2922
2913static const struct net_device_ops macsec_netdev_ops = { 2923static const struct net_device_ops macsec_netdev_ops = {
2914 .ndo_init = macsec_dev_init, 2924 .ndo_init = macsec_dev_init,
2915 .ndo_uninit = macsec_dev_uninit, 2925 .ndo_uninit = macsec_dev_uninit,
@@ -2923,6 +2933,7 @@ static const struct net_device_ops macsec_netdev_ops = {
2923 .ndo_start_xmit = macsec_start_xmit, 2933 .ndo_start_xmit = macsec_start_xmit,
2924 .ndo_get_stats64 = macsec_get_stats64, 2934 .ndo_get_stats64 = macsec_get_stats64,
2925 .ndo_get_iflink = macsec_get_iflink, 2935 .ndo_get_iflink = macsec_get_iflink,
2936 .ndo_get_lock_subclass = macsec_get_nest_level,
2926}; 2937};
2927 2938
2928static const struct device_type macsec_type = { 2939static const struct device_type macsec_type = {
@@ -3047,22 +3058,31 @@ static void macsec_del_dev(struct macsec_dev *macsec)
3047 } 3058 }
3048} 3059}
3049 3060
3061static void macsec_common_dellink(struct net_device *dev, struct list_head *head)
3062{
3063 struct macsec_dev *macsec = macsec_priv(dev);
3064 struct net_device *real_dev = macsec->real_dev;
3065
3066 unregister_netdevice_queue(dev, head);
3067 list_del_rcu(&macsec->secys);
3068 macsec_del_dev(macsec);
3069 netdev_upper_dev_unlink(real_dev, dev);
3070
3071 macsec_generation++;
3072}
3073
3050static void macsec_dellink(struct net_device *dev, struct list_head *head) 3074static void macsec_dellink(struct net_device *dev, struct list_head *head)
3051{ 3075{
3052 struct macsec_dev *macsec = macsec_priv(dev); 3076 struct macsec_dev *macsec = macsec_priv(dev);
3053 struct net_device *real_dev = macsec->real_dev; 3077 struct net_device *real_dev = macsec->real_dev;
3054 struct macsec_rxh_data *rxd = macsec_data_rtnl(real_dev); 3078 struct macsec_rxh_data *rxd = macsec_data_rtnl(real_dev);
3055 3079
3056 macsec_generation++; 3080 macsec_common_dellink(dev, head);
3057 3081
3058 unregister_netdevice_queue(dev, head);
3059 list_del_rcu(&macsec->secys);
3060 if (list_empty(&rxd->secys)) { 3082 if (list_empty(&rxd->secys)) {
3061 netdev_rx_handler_unregister(real_dev); 3083 netdev_rx_handler_unregister(real_dev);
3062 kfree(rxd); 3084 kfree(rxd);
3063 } 3085 }
3064
3065 macsec_del_dev(macsec);
3066} 3086}
3067 3087
3068static int register_macsec_dev(struct net_device *real_dev, 3088static int register_macsec_dev(struct net_device *real_dev,
@@ -3181,6 +3201,16 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
3181 3201
3182 dev_hold(real_dev); 3202 dev_hold(real_dev);
3183 3203
3204 macsec->nest_level = dev_get_nest_level(real_dev) + 1;
3205 netdev_lockdep_set_classes(dev);
3206 lockdep_set_class_and_subclass(&dev->addr_list_lock,
3207 &macsec_netdev_addr_lock_key,
3208 macsec_get_nest_level(dev));
3209
3210 err = netdev_upper_dev_link(real_dev, dev);
3211 if (err < 0)
3212 goto unregister;
3213
3184 /* need to be already registered so that ->init has run and 3214 /* need to be already registered so that ->init has run and
3185 * the MAC addr is set 3215 * the MAC addr is set
3186 */ 3216 */
@@ -3193,12 +3223,12 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
3193 3223
3194 if (rx_handler && sci_exists(real_dev, sci)) { 3224 if (rx_handler && sci_exists(real_dev, sci)) {
3195 err = -EBUSY; 3225 err = -EBUSY;
3196 goto unregister; 3226 goto unlink;
3197 } 3227 }
3198 3228
3199 err = macsec_add_dev(dev, sci, icv_len); 3229 err = macsec_add_dev(dev, sci, icv_len);
3200 if (err) 3230 if (err)
3201 goto unregister; 3231 goto unlink;
3202 3232
3203 if (data) 3233 if (data)
3204 macsec_changelink_common(dev, data); 3234 macsec_changelink_common(dev, data);
@@ -3213,6 +3243,8 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
3213 3243
3214del_dev: 3244del_dev:
3215 macsec_del_dev(macsec); 3245 macsec_del_dev(macsec);
3246unlink:
3247 netdev_upper_dev_unlink(real_dev, dev);
3216unregister: 3248unregister:
3217 unregister_netdevice(dev); 3249 unregister_netdevice(dev);
3218 return err; 3250 return err;
@@ -3382,8 +3414,12 @@ static int macsec_notify(struct notifier_block *this, unsigned long event,
3382 3414
3383 rxd = macsec_data_rtnl(real_dev); 3415 rxd = macsec_data_rtnl(real_dev);
3384 list_for_each_entry_safe(m, n, &rxd->secys, secys) { 3416 list_for_each_entry_safe(m, n, &rxd->secys, secys) {
3385 macsec_dellink(m->secy.netdev, &head); 3417 macsec_common_dellink(m->secy.netdev, &head);
3386 } 3418 }
3419
3420 netdev_rx_handler_unregister(real_dev);
3421 kfree(rxd);
3422
3387 unregister_netdevice_many(&head); 3423 unregister_netdevice_many(&head);
3388 break; 3424 break;
3389 } 3425 }
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index cd9b53834bf6..3234fcdea317 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -1315,7 +1315,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
1315 vlan->dev = dev; 1315 vlan->dev = dev;
1316 vlan->port = port; 1316 vlan->port = port;
1317 vlan->set_features = MACVLAN_FEATURES; 1317 vlan->set_features = MACVLAN_FEATURES;
1318 vlan->nest_level = dev_get_nest_level(lowerdev, netif_is_macvlan) + 1; 1318 vlan->nest_level = dev_get_nest_level(lowerdev) + 1;
1319 1319
1320 vlan->mode = MACVLAN_MODE_VEPA; 1320 vlan->mode = MACVLAN_MODE_VEPA;
1321 if (data && data[IFLA_MACVLAN_MODE]) 1321 if (data && data[IFLA_MACVLAN_MODE])
diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index a38c0dac514b..070e3290aa6e 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -275,7 +275,6 @@ static void macvtap_put_queue(struct macvtap_queue *q)
275 rtnl_unlock(); 275 rtnl_unlock();
276 276
277 synchronize_rcu(); 277 synchronize_rcu();
278 skb_array_cleanup(&q->skb_array);
279 sock_put(&q->sk); 278 sock_put(&q->sk);
280} 279}
281 280
@@ -533,10 +532,8 @@ static void macvtap_sock_write_space(struct sock *sk)
533static void macvtap_sock_destruct(struct sock *sk) 532static void macvtap_sock_destruct(struct sock *sk)
534{ 533{
535 struct macvtap_queue *q = container_of(sk, struct macvtap_queue, sk); 534 struct macvtap_queue *q = container_of(sk, struct macvtap_queue, sk);
536 struct sk_buff *skb;
537 535
538 while ((skb = skb_array_consume(&q->skb_array)) != NULL) 536 skb_array_cleanup(&q->skb_array);
539 kfree_skb(skb);
540} 537}
541 538
542static int macvtap_open(struct inode *inode, struct file *file) 539static int macvtap_open(struct inode *inode, struct file *file)
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 1882d9828c99..053e87905b94 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -677,17 +677,28 @@ static void kszphy_get_stats(struct phy_device *phydev,
677 data[i] = kszphy_get_stat(phydev, i); 677 data[i] = kszphy_get_stat(phydev, i);
678} 678}
679 679
680static int kszphy_resume(struct phy_device *phydev) 680static int kszphy_suspend(struct phy_device *phydev)
681{ 681{
682 int value; 682 /* Disable PHY Interrupts */
683 if (phy_interrupt_is_valid(phydev)) {
684 phydev->interrupts = PHY_INTERRUPT_DISABLED;
685 if (phydev->drv->config_intr)
686 phydev->drv->config_intr(phydev);
687 }
683 688
684 mutex_lock(&phydev->lock); 689 return genphy_suspend(phydev);
690}
685 691
686 value = phy_read(phydev, MII_BMCR); 692static int kszphy_resume(struct phy_device *phydev)
687 phy_write(phydev, MII_BMCR, value & ~BMCR_PDOWN); 693{
694 genphy_resume(phydev);
688 695
689 kszphy_config_intr(phydev); 696 /* Enable PHY Interrupts */
690 mutex_unlock(&phydev->lock); 697 if (phy_interrupt_is_valid(phydev)) {
698 phydev->interrupts = PHY_INTERRUPT_ENABLED;
699 if (phydev->drv->config_intr)
700 phydev->drv->config_intr(phydev);
701 }
691 702
692 return 0; 703 return 0;
693} 704}
@@ -900,7 +911,7 @@ static struct phy_driver ksphy_driver[] = {
900 .get_sset_count = kszphy_get_sset_count, 911 .get_sset_count = kszphy_get_sset_count,
901 .get_strings = kszphy_get_strings, 912 .get_strings = kszphy_get_strings,
902 .get_stats = kszphy_get_stats, 913 .get_stats = kszphy_get_stats,
903 .suspend = genphy_suspend, 914 .suspend = kszphy_suspend,
904 .resume = kszphy_resume, 915 .resume = kszphy_resume,
905}, { 916}, {
906 .phy_id = PHY_ID_KSZ8061, 917 .phy_id = PHY_ID_KSZ8061,
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index da4e3d6632f6..c0dda6fc0921 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -1811,7 +1811,7 @@ static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan,
1811 fl4.flowi4_mark = skb->mark; 1811 fl4.flowi4_mark = skb->mark;
1812 fl4.flowi4_proto = IPPROTO_UDP; 1812 fl4.flowi4_proto = IPPROTO_UDP;
1813 fl4.daddr = daddr; 1813 fl4.daddr = daddr;
1814 fl4.saddr = vxlan->cfg.saddr.sin.sin_addr.s_addr; 1814 fl4.saddr = *saddr;
1815 1815
1816 rt = ip_route_output_key(vxlan->net, &fl4); 1816 rt = ip_route_output_key(vxlan->net, &fl4);
1817 if (!IS_ERR(rt)) { 1817 if (!IS_ERR(rt)) {
@@ -1847,7 +1847,7 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
1847 memset(&fl6, 0, sizeof(fl6)); 1847 memset(&fl6, 0, sizeof(fl6));
1848 fl6.flowi6_oif = oif; 1848 fl6.flowi6_oif = oif;
1849 fl6.daddr = *daddr; 1849 fl6.daddr = *daddr;
1850 fl6.saddr = vxlan->cfg.saddr.sin6.sin6_addr; 1850 fl6.saddr = *saddr;
1851 fl6.flowlabel = ip6_make_flowinfo(RT_TOS(tos), label); 1851 fl6.flowlabel = ip6_make_flowinfo(RT_TOS(tos), label);
1852 fl6.flowi6_mark = skb->mark; 1852 fl6.flowi6_mark = skb->mark;
1853 fl6.flowi6_proto = IPPROTO_UDP; 1853 fl6.flowi6_proto = IPPROTO_UDP;
@@ -1920,7 +1920,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1920 struct rtable *rt = NULL; 1920 struct rtable *rt = NULL;
1921 const struct iphdr *old_iph; 1921 const struct iphdr *old_iph;
1922 union vxlan_addr *dst; 1922 union vxlan_addr *dst;
1923 union vxlan_addr remote_ip; 1923 union vxlan_addr remote_ip, local_ip;
1924 union vxlan_addr *src;
1924 struct vxlan_metadata _md; 1925 struct vxlan_metadata _md;
1925 struct vxlan_metadata *md = &_md; 1926 struct vxlan_metadata *md = &_md;
1926 __be16 src_port = 0, dst_port; 1927 __be16 src_port = 0, dst_port;
@@ -1938,6 +1939,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1938 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; 1939 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port;
1939 vni = rdst->remote_vni; 1940 vni = rdst->remote_vni;
1940 dst = &rdst->remote_ip; 1941 dst = &rdst->remote_ip;
1942 src = &vxlan->cfg.saddr;
1941 dst_cache = &rdst->dst_cache; 1943 dst_cache = &rdst->dst_cache;
1942 } else { 1944 } else {
1943 if (!info) { 1945 if (!info) {
@@ -1948,11 +1950,15 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1948 dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; 1950 dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
1949 vni = vxlan_tun_id_to_vni(info->key.tun_id); 1951 vni = vxlan_tun_id_to_vni(info->key.tun_id);
1950 remote_ip.sa.sa_family = ip_tunnel_info_af(info); 1952 remote_ip.sa.sa_family = ip_tunnel_info_af(info);
1951 if (remote_ip.sa.sa_family == AF_INET) 1953 if (remote_ip.sa.sa_family == AF_INET) {
1952 remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst; 1954 remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst;
1953 else 1955 local_ip.sin.sin_addr.s_addr = info->key.u.ipv4.src;
1956 } else {
1954 remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst; 1957 remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst;
1958 local_ip.sin6.sin6_addr = info->key.u.ipv6.src;
1959 }
1955 dst = &remote_ip; 1960 dst = &remote_ip;
1961 src = &local_ip;
1956 dst_cache = &info->dst_cache; 1962 dst_cache = &info->dst_cache;
1957 } 1963 }
1958 1964
@@ -1992,15 +1998,14 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1992 } 1998 }
1993 1999
1994 if (dst->sa.sa_family == AF_INET) { 2000 if (dst->sa.sa_family == AF_INET) {
1995 __be32 saddr;
1996
1997 if (!vxlan->vn4_sock) 2001 if (!vxlan->vn4_sock)
1998 goto drop; 2002 goto drop;
1999 sk = vxlan->vn4_sock->sock->sk; 2003 sk = vxlan->vn4_sock->sock->sk;
2000 2004
2001 rt = vxlan_get_route(vxlan, skb, 2005 rt = vxlan_get_route(vxlan, skb,
2002 rdst ? rdst->remote_ifindex : 0, tos, 2006 rdst ? rdst->remote_ifindex : 0, tos,
2003 dst->sin.sin_addr.s_addr, &saddr, 2007 dst->sin.sin_addr.s_addr,
2008 &src->sin.sin_addr.s_addr,
2004 dst_cache, info); 2009 dst_cache, info);
2005 if (IS_ERR(rt)) { 2010 if (IS_ERR(rt)) {
2006 netdev_dbg(dev, "no route to %pI4\n", 2011 netdev_dbg(dev, "no route to %pI4\n",
@@ -2017,7 +2022,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2017 } 2022 }
2018 2023
2019 /* Bypass encapsulation if the destination is local */ 2024 /* Bypass encapsulation if the destination is local */
2020 if (rt->rt_flags & RTCF_LOCAL && 2025 if (!info && rt->rt_flags & RTCF_LOCAL &&
2021 !(rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) { 2026 !(rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) {
2022 struct vxlan_dev *dst_vxlan; 2027 struct vxlan_dev *dst_vxlan;
2023 2028
@@ -2043,13 +2048,12 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2043 if (err < 0) 2048 if (err < 0)
2044 goto xmit_tx_error; 2049 goto xmit_tx_error;
2045 2050
2046 udp_tunnel_xmit_skb(rt, sk, skb, saddr, 2051 udp_tunnel_xmit_skb(rt, sk, skb, src->sin.sin_addr.s_addr,
2047 dst->sin.sin_addr.s_addr, tos, ttl, df, 2052 dst->sin.sin_addr.s_addr, tos, ttl, df,
2048 src_port, dst_port, xnet, !udp_sum); 2053 src_port, dst_port, xnet, !udp_sum);
2049#if IS_ENABLED(CONFIG_IPV6) 2054#if IS_ENABLED(CONFIG_IPV6)
2050 } else { 2055 } else {
2051 struct dst_entry *ndst; 2056 struct dst_entry *ndst;
2052 struct in6_addr saddr;
2053 u32 rt6i_flags; 2057 u32 rt6i_flags;
2054 2058
2055 if (!vxlan->vn6_sock) 2059 if (!vxlan->vn6_sock)
@@ -2058,7 +2062,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2058 2062
2059 ndst = vxlan6_get_route(vxlan, skb, 2063 ndst = vxlan6_get_route(vxlan, skb,
2060 rdst ? rdst->remote_ifindex : 0, tos, 2064 rdst ? rdst->remote_ifindex : 0, tos,
2061 label, &dst->sin6.sin6_addr, &saddr, 2065 label, &dst->sin6.sin6_addr,
2066 &src->sin6.sin6_addr,
2062 dst_cache, info); 2067 dst_cache, info);
2063 if (IS_ERR(ndst)) { 2068 if (IS_ERR(ndst)) {
2064 netdev_dbg(dev, "no route to %pI6\n", 2069 netdev_dbg(dev, "no route to %pI6\n",
@@ -2077,7 +2082,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2077 2082
2078 /* Bypass encapsulation if the destination is local */ 2083 /* Bypass encapsulation if the destination is local */
2079 rt6i_flags = ((struct rt6_info *)ndst)->rt6i_flags; 2084 rt6i_flags = ((struct rt6_info *)ndst)->rt6i_flags;
2080 if (rt6i_flags & RTF_LOCAL && 2085 if (!info && rt6i_flags & RTF_LOCAL &&
2081 !(rt6i_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) { 2086 !(rt6i_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) {
2082 struct vxlan_dev *dst_vxlan; 2087 struct vxlan_dev *dst_vxlan;
2083 2088
@@ -2104,7 +2109,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2104 return; 2109 return;
2105 } 2110 }
2106 udp_tunnel6_xmit_skb(ndst, sk, skb, dev, 2111 udp_tunnel6_xmit_skb(ndst, sk, skb, dev,
2107 &saddr, &dst->sin6.sin6_addr, tos, ttl, 2112 &src->sin6.sin6_addr,
2113 &dst->sin6.sin6_addr, tos, ttl,
2108 label, src_port, dst_port, !udp_sum); 2114 label, src_port, dst_port, !udp_sum);
2109#endif 2115#endif
2110 } 2116 }
diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index 1d689169da76..9e1f2d9c9865 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -5700,10 +5700,11 @@ out:
5700 mutex_unlock(&wl->mutex); 5700 mutex_unlock(&wl->mutex);
5701} 5701}
5702 5702
5703static u32 wlcore_op_get_expected_throughput(struct ieee80211_sta *sta) 5703static u32 wlcore_op_get_expected_throughput(struct ieee80211_hw *hw,
5704 struct ieee80211_sta *sta)
5704{ 5705{
5705 struct wl1271_station *wl_sta = (struct wl1271_station *)sta->drv_priv; 5706 struct wl1271_station *wl_sta = (struct wl1271_station *)sta->drv_priv;
5706 struct wl1271 *wl = wl_sta->wl; 5707 struct wl1271 *wl = hw->priv;
5707 u8 hlid = wl_sta->hlid; 5708 u8 hlid = wl_sta->hlid;
5708 5709
5709 /* return in units of Kbps */ 5710 /* return in units of Kbps */
diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index 88e91666f145..368795aad5c9 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -1269,6 +1269,7 @@ static int btt_blk_init(struct btt *btt)
1269 } 1269 }
1270 } 1270 }
1271 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9); 1271 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9);
1272 btt->nd_btt->size = btt->nlba * (u64)btt->sector_size;
1272 revalidate_disk(btt->btt_disk); 1273 revalidate_disk(btt->btt_disk);
1273 1274
1274 return 0; 1275 return 0;
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index 3fa7919f94a8..97dd2925ed6e 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -140,10 +140,30 @@ static ssize_t namespace_store(struct device *dev,
140} 140}
141static DEVICE_ATTR_RW(namespace); 141static DEVICE_ATTR_RW(namespace);
142 142
143static ssize_t size_show(struct device *dev,
144 struct device_attribute *attr, char *buf)
145{
146 struct nd_btt *nd_btt = to_nd_btt(dev);
147 ssize_t rc;
148
149 device_lock(dev);
150 if (dev->driver)
151 rc = sprintf(buf, "%llu\n", nd_btt->size);
152 else {
153 /* no size to convey if the btt instance is disabled */
154 rc = -ENXIO;
155 }
156 device_unlock(dev);
157
158 return rc;
159}
160static DEVICE_ATTR_RO(size);
161
143static struct attribute *nd_btt_attributes[] = { 162static struct attribute *nd_btt_attributes[] = {
144 &dev_attr_sector_size.attr, 163 &dev_attr_sector_size.attr,
145 &dev_attr_namespace.attr, 164 &dev_attr_namespace.attr,
146 &dev_attr_uuid.attr, 165 &dev_attr_uuid.attr,
166 &dev_attr_size.attr,
147 NULL, 167 NULL,
148}; 168};
149 169
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index 40476399d227..8024a0ef86d3 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -143,6 +143,7 @@ struct nd_btt {
143 struct nd_namespace_common *ndns; 143 struct nd_namespace_common *ndns;
144 struct btt *btt; 144 struct btt *btt;
145 unsigned long lbasize; 145 unsigned long lbasize;
146 u64 size;
146 u8 *uuid; 147 u8 *uuid;
147 int id; 148 int id;
148}; 149};
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 7ff2e820bbf4..2feacc70bf61 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -81,10 +81,12 @@ EXPORT_SYMBOL_GPL(nvme_cancel_request);
81bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, 81bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
82 enum nvme_ctrl_state new_state) 82 enum nvme_ctrl_state new_state)
83{ 83{
84 enum nvme_ctrl_state old_state = ctrl->state; 84 enum nvme_ctrl_state old_state;
85 bool changed = false; 85 bool changed = false;
86 86
87 spin_lock_irq(&ctrl->lock); 87 spin_lock_irq(&ctrl->lock);
88
89 old_state = ctrl->state;
88 switch (new_state) { 90 switch (new_state) {
89 case NVME_CTRL_LIVE: 91 case NVME_CTRL_LIVE:
90 switch (old_state) { 92 switch (old_state) {
@@ -140,11 +142,12 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
140 default: 142 default:
141 break; 143 break;
142 } 144 }
143 spin_unlock_irq(&ctrl->lock);
144 145
145 if (changed) 146 if (changed)
146 ctrl->state = new_state; 147 ctrl->state = new_state;
147 148
149 spin_unlock_irq(&ctrl->lock);
150
148 return changed; 151 return changed;
149} 152}
150EXPORT_SYMBOL_GPL(nvme_change_ctrl_state); 153EXPORT_SYMBOL_GPL(nvme_change_ctrl_state);
@@ -608,7 +611,7 @@ int nvme_get_features(struct nvme_ctrl *dev, unsigned fid, unsigned nsid,
608 611
609 ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &cqe, NULL, 0, 0, 612 ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &cqe, NULL, 0, 0,
610 NVME_QID_ANY, 0, 0); 613 NVME_QID_ANY, 0, 0);
611 if (ret >= 0) 614 if (ret >= 0 && result)
612 *result = le32_to_cpu(cqe.result); 615 *result = le32_to_cpu(cqe.result);
613 return ret; 616 return ret;
614} 617}
@@ -628,7 +631,7 @@ int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword11,
628 631
629 ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &cqe, NULL, 0, 0, 632 ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &cqe, NULL, 0, 0,
630 NVME_QID_ANY, 0, 0); 633 NVME_QID_ANY, 0, 0);
631 if (ret >= 0) 634 if (ret >= 0 && result)
632 *result = le32_to_cpu(cqe.result); 635 *result = le32_to_cpu(cqe.result);
633 return ret; 636 return ret;
634} 637}
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index d7c33f9361aa..8dcf5a960951 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1543,15 +1543,10 @@ static void nvme_disable_io_queues(struct nvme_dev *dev)
1543 reinit_completion(&dev->ioq_wait); 1543 reinit_completion(&dev->ioq_wait);
1544 retry: 1544 retry:
1545 timeout = ADMIN_TIMEOUT; 1545 timeout = ADMIN_TIMEOUT;
1546 for (; i > 0; i--) { 1546 for (; i > 0; i--, sent++)
1547 struct nvme_queue *nvmeq = dev->queues[i]; 1547 if (nvme_delete_queue(dev->queues[i], opcode))
1548
1549 if (!pass)
1550 nvme_suspend_queue(nvmeq);
1551 if (nvme_delete_queue(nvmeq, opcode))
1552 break; 1548 break;
1553 ++sent; 1549
1554 }
1555 while (sent--) { 1550 while (sent--) {
1556 timeout = wait_for_completion_io_timeout(&dev->ioq_wait, timeout); 1551 timeout = wait_for_completion_io_timeout(&dev->ioq_wait, timeout);
1557 if (timeout == 0) 1552 if (timeout == 0)
@@ -1693,11 +1688,12 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
1693 nvme_stop_queues(&dev->ctrl); 1688 nvme_stop_queues(&dev->ctrl);
1694 csts = readl(dev->bar + NVME_REG_CSTS); 1689 csts = readl(dev->bar + NVME_REG_CSTS);
1695 } 1690 }
1691
1692 for (i = dev->queue_count - 1; i > 0; i--)
1693 nvme_suspend_queue(dev->queues[i]);
1694
1696 if (csts & NVME_CSTS_CFS || !(csts & NVME_CSTS_RDY)) { 1695 if (csts & NVME_CSTS_CFS || !(csts & NVME_CSTS_RDY)) {
1697 for (i = dev->queue_count - 1; i >= 0; i--) { 1696 nvme_suspend_queue(dev->queues[0]);
1698 struct nvme_queue *nvmeq = dev->queues[i];
1699 nvme_suspend_queue(nvmeq);
1700 }
1701 } else { 1697 } else {
1702 nvme_disable_io_queues(dev); 1698 nvme_disable_io_queues(dev);
1703 nvme_disable_admin_queue(dev, shutdown); 1699 nvme_disable_admin_queue(dev, shutdown);
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 3e3ce2b0424e..8d2875b4c56d 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -12,13 +12,11 @@
12 * more details. 12 * more details.
13 */ 13 */
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/delay.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/init.h> 16#include <linux/init.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
19#include <linux/err.h> 18#include <linux/err.h>
20#include <linux/string.h> 19#include <linux/string.h>
21#include <linux/jiffies.h>
22#include <linux/atomic.h> 20#include <linux/atomic.h>
23#include <linux/blk-mq.h> 21#include <linux/blk-mq.h>
24#include <linux/types.h> 22#include <linux/types.h>
@@ -26,7 +24,6 @@
26#include <linux/mutex.h> 24#include <linux/mutex.h>
27#include <linux/scatterlist.h> 25#include <linux/scatterlist.h>
28#include <linux/nvme.h> 26#include <linux/nvme.h>
29#include <linux/t10-pi.h>
30#include <asm/unaligned.h> 27#include <asm/unaligned.h>
31 28
32#include <rdma/ib_verbs.h> 29#include <rdma/ib_verbs.h>
@@ -169,7 +166,6 @@ MODULE_PARM_DESC(register_always,
169static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id, 166static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id,
170 struct rdma_cm_event *event); 167 struct rdma_cm_event *event);
171static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc); 168static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc);
172static int __nvme_rdma_del_ctrl(struct nvme_rdma_ctrl *ctrl);
173 169
174/* XXX: really should move to a generic header sooner or later.. */ 170/* XXX: really should move to a generic header sooner or later.. */
175static inline void put_unaligned_le24(u32 val, u8 *p) 171static inline void put_unaligned_le24(u32 val, u8 *p)
@@ -687,11 +683,6 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl)
687 list_del(&ctrl->list); 683 list_del(&ctrl->list);
688 mutex_unlock(&nvme_rdma_ctrl_mutex); 684 mutex_unlock(&nvme_rdma_ctrl_mutex);
689 685
690 if (ctrl->ctrl.tagset) {
691 blk_cleanup_queue(ctrl->ctrl.connect_q);
692 blk_mq_free_tag_set(&ctrl->tag_set);
693 nvme_rdma_dev_put(ctrl->device);
694 }
695 kfree(ctrl->queues); 686 kfree(ctrl->queues);
696 nvmf_free_options(nctrl->opts); 687 nvmf_free_options(nctrl->opts);
697free_ctrl: 688free_ctrl:
@@ -748,8 +739,11 @@ static void nvme_rdma_reconnect_ctrl_work(struct work_struct *work)
748 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE); 739 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
749 WARN_ON_ONCE(!changed); 740 WARN_ON_ONCE(!changed);
750 741
751 if (ctrl->queue_count > 1) 742 if (ctrl->queue_count > 1) {
752 nvme_start_queues(&ctrl->ctrl); 743 nvme_start_queues(&ctrl->ctrl);
744 nvme_queue_scan(&ctrl->ctrl);
745 nvme_queue_async_events(&ctrl->ctrl);
746 }
753 747
754 dev_info(ctrl->ctrl.device, "Successfully reconnected\n"); 748 dev_info(ctrl->ctrl.device, "Successfully reconnected\n");
755 749
@@ -1269,7 +1263,7 @@ static int nvme_rdma_route_resolved(struct nvme_rdma_queue *queue)
1269{ 1263{
1270 struct nvme_rdma_ctrl *ctrl = queue->ctrl; 1264 struct nvme_rdma_ctrl *ctrl = queue->ctrl;
1271 struct rdma_conn_param param = { }; 1265 struct rdma_conn_param param = { };
1272 struct nvme_rdma_cm_req priv; 1266 struct nvme_rdma_cm_req priv = { };
1273 int ret; 1267 int ret;
1274 1268
1275 param.qp_num = queue->qp->qp_num; 1269 param.qp_num = queue->qp->qp_num;
@@ -1318,37 +1312,39 @@ out_destroy_queue_ib:
1318 * that caught the event. Since we hold the callout until the controller 1312 * that caught the event. Since we hold the callout until the controller
1319 * deletion is completed, we'll deadlock if the controller deletion will 1313 * deletion is completed, we'll deadlock if the controller deletion will
1320 * call rdma_destroy_id on this queue's cm_id. Thus, we claim ownership 1314 * call rdma_destroy_id on this queue's cm_id. Thus, we claim ownership
1321 * of destroying this queue before-hand, destroy the queue resources 1315 * of destroying this queue before-hand, destroy the queue resources,
1322 * after the controller deletion completed with the exception of destroying 1316 * then queue the controller deletion which won't destroy this queue and
1323 * the cm_id implicitely by returning a non-zero rc to the callout. 1317 * we destroy the cm_id implicitely by returning a non-zero rc to the callout.
1324 */ 1318 */
1325static int nvme_rdma_device_unplug(struct nvme_rdma_queue *queue) 1319static int nvme_rdma_device_unplug(struct nvme_rdma_queue *queue)
1326{ 1320{
1327 struct nvme_rdma_ctrl *ctrl = queue->ctrl; 1321 struct nvme_rdma_ctrl *ctrl = queue->ctrl;
1328 int ret, ctrl_deleted = 0; 1322 int ret;
1329 1323
1330 /* First disable the queue so ctrl delete won't free it */ 1324 /* Own the controller deletion */
1331 if (!test_and_clear_bit(NVME_RDMA_Q_CONNECTED, &queue->flags)) 1325 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_DELETING))
1332 goto out; 1326 return 0;
1333 1327
1334 /* delete the controller */ 1328 dev_warn(ctrl->ctrl.device,
1335 ret = __nvme_rdma_del_ctrl(ctrl); 1329 "Got rdma device removal event, deleting ctrl\n");
1336 if (!ret) {
1337 dev_warn(ctrl->ctrl.device,
1338 "Got rdma device removal event, deleting ctrl\n");
1339 flush_work(&ctrl->delete_work);
1340 1330
1341 /* Return non-zero so the cm_id will destroy implicitly */ 1331 /* Get rid of reconnect work if its running */
1342 ctrl_deleted = 1; 1332 cancel_delayed_work_sync(&ctrl->reconnect_work);
1343 1333
1334 /* Disable the queue so ctrl delete won't free it */
1335 if (test_and_clear_bit(NVME_RDMA_Q_CONNECTED, &queue->flags)) {
1344 /* Free this queue ourselves */ 1336 /* Free this queue ourselves */
1345 rdma_disconnect(queue->cm_id); 1337 nvme_rdma_stop_queue(queue);
1346 ib_drain_qp(queue->qp);
1347 nvme_rdma_destroy_queue_ib(queue); 1338 nvme_rdma_destroy_queue_ib(queue);
1339
1340 /* Return non-zero so the cm_id will destroy implicitly */
1341 ret = 1;
1348 } 1342 }
1349 1343
1350out: 1344 /* Queue controller deletion */
1351 return ctrl_deleted; 1345 queue_work(nvme_rdma_wq, &ctrl->delete_work);
1346 flush_work(&ctrl->delete_work);
1347 return ret;
1352} 1348}
1353 1349
1354static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id, 1350static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id,
@@ -1648,7 +1644,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl)
1648 nvme_rdma_free_io_queues(ctrl); 1644 nvme_rdma_free_io_queues(ctrl);
1649 } 1645 }
1650 1646
1651 if (ctrl->ctrl.state == NVME_CTRL_LIVE) 1647 if (test_bit(NVME_RDMA_Q_CONNECTED, &ctrl->queues[0].flags))
1652 nvme_shutdown_ctrl(&ctrl->ctrl); 1648 nvme_shutdown_ctrl(&ctrl->ctrl);
1653 1649
1654 blk_mq_stop_hw_queues(ctrl->ctrl.admin_q); 1650 blk_mq_stop_hw_queues(ctrl->ctrl.admin_q);
@@ -1657,15 +1653,27 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl)
1657 nvme_rdma_destroy_admin_queue(ctrl); 1653 nvme_rdma_destroy_admin_queue(ctrl);
1658} 1654}
1659 1655
1656static void __nvme_rdma_remove_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)
1657{
1658 nvme_uninit_ctrl(&ctrl->ctrl);
1659 if (shutdown)
1660 nvme_rdma_shutdown_ctrl(ctrl);
1661
1662 if (ctrl->ctrl.tagset) {
1663 blk_cleanup_queue(ctrl->ctrl.connect_q);
1664 blk_mq_free_tag_set(&ctrl->tag_set);
1665 nvme_rdma_dev_put(ctrl->device);
1666 }
1667
1668 nvme_put_ctrl(&ctrl->ctrl);
1669}
1670
1660static void nvme_rdma_del_ctrl_work(struct work_struct *work) 1671static void nvme_rdma_del_ctrl_work(struct work_struct *work)
1661{ 1672{
1662 struct nvme_rdma_ctrl *ctrl = container_of(work, 1673 struct nvme_rdma_ctrl *ctrl = container_of(work,
1663 struct nvme_rdma_ctrl, delete_work); 1674 struct nvme_rdma_ctrl, delete_work);
1664 1675
1665 nvme_remove_namespaces(&ctrl->ctrl); 1676 __nvme_rdma_remove_ctrl(ctrl, true);
1666 nvme_rdma_shutdown_ctrl(ctrl);
1667 nvme_uninit_ctrl(&ctrl->ctrl);
1668 nvme_put_ctrl(&ctrl->ctrl);
1669} 1677}
1670 1678
1671static int __nvme_rdma_del_ctrl(struct nvme_rdma_ctrl *ctrl) 1679static int __nvme_rdma_del_ctrl(struct nvme_rdma_ctrl *ctrl)
@@ -1698,9 +1706,7 @@ static void nvme_rdma_remove_ctrl_work(struct work_struct *work)
1698 struct nvme_rdma_ctrl *ctrl = container_of(work, 1706 struct nvme_rdma_ctrl *ctrl = container_of(work,
1699 struct nvme_rdma_ctrl, delete_work); 1707 struct nvme_rdma_ctrl, delete_work);
1700 1708
1701 nvme_remove_namespaces(&ctrl->ctrl); 1709 __nvme_rdma_remove_ctrl(ctrl, false);
1702 nvme_uninit_ctrl(&ctrl->ctrl);
1703 nvme_put_ctrl(&ctrl->ctrl);
1704} 1710}
1705 1711
1706static void nvme_rdma_reset_ctrl_work(struct work_struct *work) 1712static void nvme_rdma_reset_ctrl_work(struct work_struct *work)
@@ -1739,6 +1745,7 @@ static void nvme_rdma_reset_ctrl_work(struct work_struct *work)
1739 if (ctrl->queue_count > 1) { 1745 if (ctrl->queue_count > 1) {
1740 nvme_start_queues(&ctrl->ctrl); 1746 nvme_start_queues(&ctrl->ctrl);
1741 nvme_queue_scan(&ctrl->ctrl); 1747 nvme_queue_scan(&ctrl->ctrl);
1748 nvme_queue_async_events(&ctrl->ctrl);
1742 } 1749 }
1743 1750
1744 return; 1751 return;
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 2fac17a5ad53..47c564b5a289 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -13,7 +13,6 @@
13 */ 13 */
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/random.h>
17#include <generated/utsrelease.h> 16#include <generated/utsrelease.h>
18#include "nvmet.h" 17#include "nvmet.h"
19 18
@@ -83,7 +82,6 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
83{ 82{
84 struct nvmet_ctrl *ctrl = req->sq->ctrl; 83 struct nvmet_ctrl *ctrl = req->sq->ctrl;
85 struct nvme_id_ctrl *id; 84 struct nvme_id_ctrl *id;
86 u64 serial;
87 u16 status = 0; 85 u16 status = 0;
88 86
89 id = kzalloc(sizeof(*id), GFP_KERNEL); 87 id = kzalloc(sizeof(*id), GFP_KERNEL);
@@ -96,10 +94,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
96 id->vid = 0; 94 id->vid = 0;
97 id->ssvid = 0; 95 id->ssvid = 0;
98 96
99 /* generate a random serial number as our controllers are ephemeral: */
100 get_random_bytes(&serial, sizeof(serial));
101 memset(id->sn, ' ', sizeof(id->sn)); 97 memset(id->sn, ' ', sizeof(id->sn));
102 snprintf(id->sn, sizeof(id->sn), "%llx", serial); 98 snprintf(id->sn, sizeof(id->sn), "%llx", ctrl->serial);
103 99
104 memset(id->mn, ' ', sizeof(id->mn)); 100 memset(id->mn, ' ', sizeof(id->mn));
105 strncpy((char *)id->mn, "Linux", sizeof(id->mn)); 101 strncpy((char *)id->mn, "Linux", sizeof(id->mn));
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 8a891ca53367..6559d5afa7bf 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/random.h>
16#include "nvmet.h" 17#include "nvmet.h"
17 18
18static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX]; 19static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
@@ -728,6 +729,9 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
728 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); 729 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
729 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); 730 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE);
730 731
732 /* generate a random serial number as our controllers are ephemeral: */
733 get_random_bytes(&ctrl->serial, sizeof(ctrl->serial));
734
731 kref_init(&ctrl->ref); 735 kref_init(&ctrl->ref);
732 ctrl->subsys = subsys; 736 ctrl->subsys = subsys;
733 737
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c
index 94e782987cc9..7affd40a6b33 100644
--- a/drivers/nvme/target/loop.c
+++ b/drivers/nvme/target/loop.c
@@ -414,9 +414,8 @@ static void nvme_loop_del_ctrl_work(struct work_struct *work)
414 struct nvme_loop_ctrl *ctrl = container_of(work, 414 struct nvme_loop_ctrl *ctrl = container_of(work,
415 struct nvme_loop_ctrl, delete_work); 415 struct nvme_loop_ctrl, delete_work);
416 416
417 nvme_remove_namespaces(&ctrl->ctrl);
418 nvme_loop_shutdown_ctrl(ctrl);
419 nvme_uninit_ctrl(&ctrl->ctrl); 417 nvme_uninit_ctrl(&ctrl->ctrl);
418 nvme_loop_shutdown_ctrl(ctrl);
420 nvme_put_ctrl(&ctrl->ctrl); 419 nvme_put_ctrl(&ctrl->ctrl);
421} 420}
422 421
@@ -501,7 +500,6 @@ out_free_queues:
501 nvme_loop_destroy_admin_queue(ctrl); 500 nvme_loop_destroy_admin_queue(ctrl);
502out_disable: 501out_disable:
503 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); 502 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n");
504 nvme_remove_namespaces(&ctrl->ctrl);
505 nvme_uninit_ctrl(&ctrl->ctrl); 503 nvme_uninit_ctrl(&ctrl->ctrl);
506 nvme_put_ctrl(&ctrl->ctrl); 504 nvme_put_ctrl(&ctrl->ctrl);
507} 505}
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 57dd6d834c28..76b6eedccaf9 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -113,6 +113,7 @@ struct nvmet_ctrl {
113 113
114 struct mutex lock; 114 struct mutex lock;
115 u64 cap; 115 u64 cap;
116 u64 serial;
116 u32 cc; 117 u32 cc;
117 u32 csts; 118 u32 csts;
118 119
diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index e06d504bdf0c..b4d648536c3e 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -77,6 +77,7 @@ enum nvmet_rdma_queue_state {
77 NVMET_RDMA_Q_CONNECTING, 77 NVMET_RDMA_Q_CONNECTING,
78 NVMET_RDMA_Q_LIVE, 78 NVMET_RDMA_Q_LIVE,
79 NVMET_RDMA_Q_DISCONNECTING, 79 NVMET_RDMA_Q_DISCONNECTING,
80 NVMET_RDMA_IN_DEVICE_REMOVAL,
80}; 81};
81 82
82struct nvmet_rdma_queue { 83struct nvmet_rdma_queue {
@@ -615,15 +616,10 @@ static u16 nvmet_rdma_map_sgl_keyed(struct nvmet_rdma_rsp *rsp,
615 if (!len) 616 if (!len)
616 return 0; 617 return 0;
617 618
618 /* use the already allocated data buffer if possible */ 619 status = nvmet_rdma_alloc_sgl(&rsp->req.sg, &rsp->req.sg_cnt,
619 if (len <= NVMET_RDMA_INLINE_DATA_SIZE && rsp->queue->host_qid) { 620 len);
620 nvmet_rdma_use_inline_sg(rsp, len, 0); 621 if (status)
621 } else { 622 return status;
622 status = nvmet_rdma_alloc_sgl(&rsp->req.sg, &rsp->req.sg_cnt,
623 len);
624 if (status)
625 return status;
626 }
627 623
628 ret = rdma_rw_ctx_init(&rsp->rw, cm_id->qp, cm_id->port_num, 624 ret = rdma_rw_ctx_init(&rsp->rw, cm_id->qp, cm_id->port_num,
629 rsp->req.sg, rsp->req.sg_cnt, 0, addr, key, 625 rsp->req.sg, rsp->req.sg_cnt, 0, addr, key,
@@ -984,7 +980,10 @@ static void nvmet_rdma_release_queue_work(struct work_struct *w)
984 struct nvmet_rdma_device *dev = queue->dev; 980 struct nvmet_rdma_device *dev = queue->dev;
985 981
986 nvmet_rdma_free_queue(queue); 982 nvmet_rdma_free_queue(queue);
987 rdma_destroy_id(cm_id); 983
984 if (queue->state != NVMET_RDMA_IN_DEVICE_REMOVAL)
985 rdma_destroy_id(cm_id);
986
988 kref_put(&dev->ref, nvmet_rdma_free_dev); 987 kref_put(&dev->ref, nvmet_rdma_free_dev);
989} 988}
990 989
@@ -1233,8 +1232,9 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue)
1233 switch (queue->state) { 1232 switch (queue->state) {
1234 case NVMET_RDMA_Q_CONNECTING: 1233 case NVMET_RDMA_Q_CONNECTING:
1235 case NVMET_RDMA_Q_LIVE: 1234 case NVMET_RDMA_Q_LIVE:
1236 disconnect = true;
1237 queue->state = NVMET_RDMA_Q_DISCONNECTING; 1235 queue->state = NVMET_RDMA_Q_DISCONNECTING;
1236 case NVMET_RDMA_IN_DEVICE_REMOVAL:
1237 disconnect = true;
1238 break; 1238 break;
1239 case NVMET_RDMA_Q_DISCONNECTING: 1239 case NVMET_RDMA_Q_DISCONNECTING:
1240 break; 1240 break;
@@ -1272,6 +1272,62 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id,
1272 schedule_work(&queue->release_work); 1272 schedule_work(&queue->release_work);
1273} 1273}
1274 1274
1275/**
1276 * nvme_rdma_device_removal() - Handle RDMA device removal
1277 * @queue: nvmet rdma queue (cm id qp_context)
1278 * @addr: nvmet address (cm_id context)
1279 *
1280 * DEVICE_REMOVAL event notifies us that the RDMA device is about
1281 * to unplug so we should take care of destroying our RDMA resources.
1282 * This event will be generated for each allocated cm_id.
1283 *
1284 * Note that this event can be generated on a normal queue cm_id
1285 * and/or a device bound listener cm_id (where in this case
1286 * queue will be null).
1287 *
1288 * we claim ownership on destroying the cm_id. For queues we move
1289 * the queue state to NVMET_RDMA_IN_DEVICE_REMOVAL and for port
1290 * we nullify the priv to prevent double cm_id destruction and destroying
1291 * the cm_id implicitely by returning a non-zero rc to the callout.
1292 */
1293static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id,
1294 struct nvmet_rdma_queue *queue)
1295{
1296 unsigned long flags;
1297
1298 if (!queue) {
1299 struct nvmet_port *port = cm_id->context;
1300
1301 /*
1302 * This is a listener cm_id. Make sure that
1303 * future remove_port won't invoke a double
1304 * cm_id destroy. use atomic xchg to make sure
1305 * we don't compete with remove_port.
1306 */
1307 if (xchg(&port->priv, NULL) != cm_id)
1308 return 0;
1309 } else {
1310 /*
1311 * This is a queue cm_id. Make sure that
1312 * release queue will not destroy the cm_id
1313 * and schedule all ctrl queues removal (only
1314 * if the queue is not disconnecting already).
1315 */
1316 spin_lock_irqsave(&queue->state_lock, flags);
1317 if (queue->state != NVMET_RDMA_Q_DISCONNECTING)
1318 queue->state = NVMET_RDMA_IN_DEVICE_REMOVAL;
1319 spin_unlock_irqrestore(&queue->state_lock, flags);
1320 nvmet_rdma_queue_disconnect(queue);
1321 flush_scheduled_work();
1322 }
1323
1324 /*
1325 * We need to return 1 so that the core will destroy
1326 * it's own ID. What a great API design..
1327 */
1328 return 1;
1329}
1330
1275static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id, 1331static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id,
1276 struct rdma_cm_event *event) 1332 struct rdma_cm_event *event)
1277{ 1333{
@@ -1294,20 +1350,11 @@ static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id,
1294 break; 1350 break;
1295 case RDMA_CM_EVENT_ADDR_CHANGE: 1351 case RDMA_CM_EVENT_ADDR_CHANGE:
1296 case RDMA_CM_EVENT_DISCONNECTED: 1352 case RDMA_CM_EVENT_DISCONNECTED:
1297 case RDMA_CM_EVENT_DEVICE_REMOVAL:
1298 case RDMA_CM_EVENT_TIMEWAIT_EXIT: 1353 case RDMA_CM_EVENT_TIMEWAIT_EXIT:
1299 /* 1354 nvmet_rdma_queue_disconnect(queue);
1300 * We can get the device removal callback even for a 1355 break;
1301 * CM ID that we aren't actually using. In that case 1356 case RDMA_CM_EVENT_DEVICE_REMOVAL:
1302 * the context pointer is NULL, so we shouldn't try 1357 ret = nvmet_rdma_device_removal(cm_id, queue);
1303 * to disconnect a non-existing queue. But we also
1304 * need to return 1 so that the core will destroy
1305 * it's own ID. What a great API design..
1306 */
1307 if (queue)
1308 nvmet_rdma_queue_disconnect(queue);
1309 else
1310 ret = 1;
1311 break; 1358 break;
1312 case RDMA_CM_EVENT_REJECTED: 1359 case RDMA_CM_EVENT_REJECTED:
1313 case RDMA_CM_EVENT_UNREACHABLE: 1360 case RDMA_CM_EVENT_UNREACHABLE:
@@ -1396,9 +1443,10 @@ out_destroy_id:
1396 1443
1397static void nvmet_rdma_remove_port(struct nvmet_port *port) 1444static void nvmet_rdma_remove_port(struct nvmet_port *port)
1398{ 1445{
1399 struct rdma_cm_id *cm_id = port->priv; 1446 struct rdma_cm_id *cm_id = xchg(&port->priv, NULL);
1400 1447
1401 rdma_destroy_id(cm_id); 1448 if (cm_id)
1449 rdma_destroy_id(cm_id);
1402} 1450}
1403 1451
1404static struct nvmet_fabrics_ops nvmet_rdma_ops = { 1452static struct nvmet_fabrics_ops nvmet_rdma_ops = {
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7792266db259..3ce69536a7b3 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1631,8 +1631,7 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
1631 */ 1631 */
1632 1632
1633 err: 1633 err:
1634 if (it.node) 1634 of_node_put(it.node);
1635 of_node_put(it.node);
1636 return rc; 1635 return rc;
1637} 1636}
1638 1637
@@ -2343,20 +2342,13 @@ struct device_node *of_graph_get_endpoint_by_regs(
2343 const struct device_node *parent, int port_reg, int reg) 2342 const struct device_node *parent, int port_reg, int reg)
2344{ 2343{
2345 struct of_endpoint endpoint; 2344 struct of_endpoint endpoint;
2346 struct device_node *node, *prev_node = NULL; 2345 struct device_node *node = NULL;
2347
2348 while (1) {
2349 node = of_graph_get_next_endpoint(parent, prev_node);
2350 of_node_put(prev_node);
2351 if (!node)
2352 break;
2353 2346
2347 for_each_endpoint_of_node(parent, node) {
2354 of_graph_parse_endpoint(node, &endpoint); 2348 of_graph_parse_endpoint(node, &endpoint);
2355 if (((port_reg == -1) || (endpoint.port == port_reg)) && 2349 if (((port_reg == -1) || (endpoint.port == port_reg)) &&
2356 ((reg == -1) || (endpoint.id == reg))) 2350 ((reg == -1) || (endpoint.id == reg)))
2357 return node; 2351 return node;
2358
2359 prev_node = node;
2360 } 2352 }
2361 2353
2362 return NULL; 2354 return NULL;
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 55f1b8391149..085c6389afd1 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -517,7 +517,7 @@ static void *__unflatten_device_tree(const void *blob,
517 pr_warning("End of tree marker overwritten: %08x\n", 517 pr_warning("End of tree marker overwritten: %08x\n",
518 be32_to_cpup(mem + size)); 518 be32_to_cpup(mem + size));
519 519
520 if (detached) { 520 if (detached && mynodes) {
521 of_node_set_flag(*mynodes, OF_DETACHED); 521 of_node_set_flag(*mynodes, OF_DETACHED);
522 pr_debug("unflattened tree is detached\n"); 522 pr_debug("unflattened tree is detached\n");
523 } 523 }
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 89a71c6074fc..a2e68f740eda 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -544,12 +544,15 @@ void __init of_irq_init(const struct of_device_id *matches)
544 544
545 list_del(&desc->list); 545 list_del(&desc->list);
546 546
547 of_node_set_flag(desc->dev, OF_POPULATED);
548
547 pr_debug("of_irq_init: init %s (%p), parent %p\n", 549 pr_debug("of_irq_init: init %s (%p), parent %p\n",
548 desc->dev->full_name, 550 desc->dev->full_name,
549 desc->dev, desc->interrupt_parent); 551 desc->dev, desc->interrupt_parent);
550 ret = desc->irq_init_cb(desc->dev, 552 ret = desc->irq_init_cb(desc->dev,
551 desc->interrupt_parent); 553 desc->interrupt_parent);
552 if (ret) { 554 if (ret) {
555 of_node_clear_flag(desc->dev, OF_POPULATED);
553 kfree(desc); 556 kfree(desc);
554 continue; 557 continue;
555 } 558 }
@@ -559,8 +562,6 @@ void __init of_irq_init(const struct of_device_id *matches)
559 * its children can get processed in a subsequent pass. 562 * its children can get processed in a subsequent pass.
560 */ 563 */
561 list_add_tail(&desc->list, &intc_parent_list); 564 list_add_tail(&desc->list, &intc_parent_list);
562
563 of_node_set_flag(desc->dev, OF_POPULATED);
564 } 565 }
565 566
566 /* Get the next pending parent that might have children */ 567 /* Get the next pending parent that might have children */
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 8aa197691074..f39ccd5aa701 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -497,6 +497,7 @@ int of_platform_default_populate(struct device_node *root,
497} 497}
498EXPORT_SYMBOL_GPL(of_platform_default_populate); 498EXPORT_SYMBOL_GPL(of_platform_default_populate);
499 499
500#ifndef CONFIG_PPC
500static int __init of_platform_default_populate_init(void) 501static int __init of_platform_default_populate_init(void)
501{ 502{
502 struct device_node *node; 503 struct device_node *node;
@@ -521,6 +522,7 @@ static int __init of_platform_default_populate_init(void)
521 return 0; 522 return 0;
522} 523}
523arch_initcall_sync(of_platform_default_populate_init); 524arch_initcall_sync(of_platform_default_populate_init);
525#endif
524 526
525static int of_platform_device_destroy(struct device *dev, void *data) 527static int of_platform_device_destroy(struct device *dev, void *data)
526{ 528{
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index a02981efdad5..98f12223c734 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -1069,7 +1069,7 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
1069 nvec = maxvec; 1069 nvec = maxvec;
1070 1070
1071 for (;;) { 1071 for (;;) {
1072 if (!(flags & PCI_IRQ_NOAFFINITY)) { 1072 if (flags & PCI_IRQ_AFFINITY) {
1073 dev->irq_affinity = irq_create_affinity_mask(&nvec); 1073 dev->irq_affinity = irq_create_affinity_mask(&nvec);
1074 if (nvec < minvec) 1074 if (nvec < minvec)
1075 return -ENOSPC; 1075 return -ENOSPC;
@@ -1105,7 +1105,7 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
1105 **/ 1105 **/
1106int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec) 1106int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec)
1107{ 1107{
1108 return __pci_enable_msi_range(dev, minvec, maxvec, PCI_IRQ_NOAFFINITY); 1108 return __pci_enable_msi_range(dev, minvec, maxvec, 0);
1109} 1109}
1110EXPORT_SYMBOL(pci_enable_msi_range); 1110EXPORT_SYMBOL(pci_enable_msi_range);
1111 1111
@@ -1120,7 +1120,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
1120 return -ERANGE; 1120 return -ERANGE;
1121 1121
1122 for (;;) { 1122 for (;;) {
1123 if (!(flags & PCI_IRQ_NOAFFINITY)) { 1123 if (flags & PCI_IRQ_AFFINITY) {
1124 dev->irq_affinity = irq_create_affinity_mask(&nvec); 1124 dev->irq_affinity = irq_create_affinity_mask(&nvec);
1125 if (nvec < minvec) 1125 if (nvec < minvec)
1126 return -ENOSPC; 1126 return -ENOSPC;
@@ -1160,8 +1160,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
1160int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, 1160int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
1161 int minvec, int maxvec) 1161 int minvec, int maxvec)
1162{ 1162{
1163 return __pci_enable_msix_range(dev, entries, minvec, maxvec, 1163 return __pci_enable_msix_range(dev, entries, minvec, maxvec, 0);
1164 PCI_IRQ_NOAFFINITY);
1165} 1164}
1166EXPORT_SYMBOL(pci_enable_msix_range); 1165EXPORT_SYMBOL(pci_enable_msix_range);
1167 1166
@@ -1187,22 +1186,25 @@ int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
1187{ 1186{
1188 int vecs = -ENOSPC; 1187 int vecs = -ENOSPC;
1189 1188
1190 if (!(flags & PCI_IRQ_NOMSIX)) { 1189 if (flags & PCI_IRQ_MSIX) {
1191 vecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs, 1190 vecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs,
1192 flags); 1191 flags);
1193 if (vecs > 0) 1192 if (vecs > 0)
1194 return vecs; 1193 return vecs;
1195 } 1194 }
1196 1195
1197 if (!(flags & PCI_IRQ_NOMSI)) { 1196 if (flags & PCI_IRQ_MSI) {
1198 vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, flags); 1197 vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, flags);
1199 if (vecs > 0) 1198 if (vecs > 0)
1200 return vecs; 1199 return vecs;
1201 } 1200 }
1202 1201
1203 /* use legacy irq if allowed */ 1202 /* use legacy irq if allowed */
1204 if (!(flags & PCI_IRQ_NOLEGACY) && min_vecs == 1) 1203 if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1) {
1204 pci_intx(dev, 1);
1205 return 1; 1205 return 1;
1206 }
1207
1206 return vecs; 1208 return vecs;
1207} 1209}
1208EXPORT_SYMBOL(pci_alloc_irq_vectors); 1210EXPORT_SYMBOL(pci_alloc_irq_vectors);
@@ -1411,6 +1413,8 @@ struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode,
1411 if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS) 1413 if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS)
1412 pci_msi_domain_update_chip_ops(info); 1414 pci_msi_domain_update_chip_ops(info);
1413 1415
1416 info->flags |= MSI_FLAG_ACTIVATE_EARLY;
1417
1414 domain = msi_create_irq_domain(fwnode, info, parent); 1418 domain = msi_create_irq_domain(fwnode, info, parent);
1415 if (!domain) 1419 if (!domain)
1416 return NULL; 1420 return NULL;
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index 6ccb994bdfcb..c494613c1909 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -688,7 +688,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
688 return 0; 688 return 0;
689} 689}
690 690
691static DEFINE_MUTEX(arm_pmu_mutex); 691static DEFINE_SPINLOCK(arm_pmu_lock);
692static LIST_HEAD(arm_pmu_list); 692static LIST_HEAD(arm_pmu_list);
693 693
694/* 694/*
@@ -701,7 +701,7 @@ static int arm_perf_starting_cpu(unsigned int cpu)
701{ 701{
702 struct arm_pmu *pmu; 702 struct arm_pmu *pmu;
703 703
704 mutex_lock(&arm_pmu_mutex); 704 spin_lock(&arm_pmu_lock);
705 list_for_each_entry(pmu, &arm_pmu_list, entry) { 705 list_for_each_entry(pmu, &arm_pmu_list, entry) {
706 706
707 if (!cpumask_test_cpu(cpu, &pmu->supported_cpus)) 707 if (!cpumask_test_cpu(cpu, &pmu->supported_cpus))
@@ -709,7 +709,7 @@ static int arm_perf_starting_cpu(unsigned int cpu)
709 if (pmu->reset) 709 if (pmu->reset)
710 pmu->reset(pmu); 710 pmu->reset(pmu);
711 } 711 }
712 mutex_unlock(&arm_pmu_mutex); 712 spin_unlock(&arm_pmu_lock);
713 return 0; 713 return 0;
714} 714}
715 715
@@ -821,9 +821,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
821 if (!cpu_hw_events) 821 if (!cpu_hw_events)
822 return -ENOMEM; 822 return -ENOMEM;
823 823
824 mutex_lock(&arm_pmu_mutex); 824 spin_lock(&arm_pmu_lock);
825 list_add_tail(&cpu_pmu->entry, &arm_pmu_list); 825 list_add_tail(&cpu_pmu->entry, &arm_pmu_list);
826 mutex_unlock(&arm_pmu_mutex); 826 spin_unlock(&arm_pmu_lock);
827 827
828 err = cpu_pm_pmu_register(cpu_pmu); 828 err = cpu_pm_pmu_register(cpu_pmu);
829 if (err) 829 if (err)
@@ -859,9 +859,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
859 return 0; 859 return 0;
860 860
861out_unregister: 861out_unregister:
862 mutex_lock(&arm_pmu_mutex); 862 spin_lock(&arm_pmu_lock);
863 list_del(&cpu_pmu->entry); 863 list_del(&cpu_pmu->entry);
864 mutex_unlock(&arm_pmu_mutex); 864 spin_unlock(&arm_pmu_lock);
865 free_percpu(cpu_hw_events); 865 free_percpu(cpu_hw_events);
866 return err; 866 return err;
867} 867}
@@ -869,9 +869,9 @@ out_unregister:
869static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu) 869static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu)
870{ 870{
871 cpu_pm_pmu_unregister(cpu_pmu); 871 cpu_pm_pmu_unregister(cpu_pmu);
872 mutex_lock(&arm_pmu_mutex); 872 spin_lock(&arm_pmu_lock);
873 list_del(&cpu_pmu->entry); 873 list_del(&cpu_pmu->entry);
874 mutex_unlock(&arm_pmu_mutex); 874 spin_unlock(&arm_pmu_lock);
875 free_percpu(cpu_pmu->hw_events); 875 free_percpu(cpu_pmu->hw_events);
876} 876}
877 877
@@ -967,11 +967,12 @@ static int of_pmu_irq_cfg(struct arm_pmu *pmu)
967 967
968 /* If we didn't manage to parse anything, try the interrupt affinity */ 968 /* If we didn't manage to parse anything, try the interrupt affinity */
969 if (cpumask_weight(&pmu->supported_cpus) == 0) { 969 if (cpumask_weight(&pmu->supported_cpus) == 0) {
970 if (!using_spi) { 970 int irq = platform_get_irq(pdev, 0);
971
972 if (irq_is_percpu(irq)) {
971 /* If using PPIs, check the affinity of the partition */ 973 /* If using PPIs, check the affinity of the partition */
972 int ret, irq; 974 int ret;
973 975
974 irq = platform_get_irq(pdev, 0);
975 ret = irq_get_percpu_devid_partition(irq, &pmu->supported_cpus); 976 ret = irq_get_percpu_devid_partition(irq, &pmu->supported_cpus);
976 if (ret) { 977 if (ret) {
977 kfree(irqs); 978 kfree(irqs);
diff --git a/drivers/pinctrl/intel/pinctrl-merrifield.c b/drivers/pinctrl/intel/pinctrl-merrifield.c
index eb4990ff26ca..7fb765642ee7 100644
--- a/drivers/pinctrl/intel/pinctrl-merrifield.c
+++ b/drivers/pinctrl/intel/pinctrl-merrifield.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/bitops.h> 12#include <linux/bitops.h>
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/io.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
16#include <linux/pinctrl/pinconf.h> 17#include <linux/pinctrl/pinconf.h>
diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c
index 11623c6b0cb3..44e69c963f5d 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -727,13 +727,7 @@ static int meson_pinctrl_probe(struct platform_device *pdev)
727 return PTR_ERR(pc->pcdev); 727 return PTR_ERR(pc->pcdev);
728 } 728 }
729 729
730 ret = meson_gpiolib_register(pc); 730 return meson_gpiolib_register(pc);
731 if (ret) {
732 pinctrl_unregister(pc->pcdev);
733 return ret;
734 }
735
736 return 0;
737} 731}
738 732
739static struct platform_driver meson_pinctrl_driver = { 733static struct platform_driver meson_pinctrl_driver = {
diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 634b4d30eefb..b3e772390ab6 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -43,17 +43,6 @@ static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
43 43
44 spin_lock_irqsave(&gpio_dev->lock, flags); 44 spin_lock_irqsave(&gpio_dev->lock, flags);
45 pin_reg = readl(gpio_dev->base + offset * 4); 45 pin_reg = readl(gpio_dev->base + offset * 4);
46 /*
47 * Suppose BIOS or Bootloader sets specific debounce for the
48 * GPIO. if not, set debounce to be 2.75ms and remove glitch.
49 */
50 if ((pin_reg & DB_TMR_OUT_MASK) == 0) {
51 pin_reg |= 0xf;
52 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
53 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
54 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
55 }
56
57 pin_reg &= ~BIT(OUTPUT_ENABLE_OFF); 46 pin_reg &= ~BIT(OUTPUT_ENABLE_OFF);
58 writel(pin_reg, gpio_dev->base + offset * 4); 47 writel(pin_reg, gpio_dev->base + offset * 4);
59 spin_unlock_irqrestore(&gpio_dev->lock, flags); 48 spin_unlock_irqrestore(&gpio_dev->lock, flags);
@@ -326,15 +315,6 @@ static void amd_gpio_irq_enable(struct irq_data *d)
326 315
327 spin_lock_irqsave(&gpio_dev->lock, flags); 316 spin_lock_irqsave(&gpio_dev->lock, flags);
328 pin_reg = readl(gpio_dev->base + (d->hwirq)*4); 317 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
329 /*
330 Suppose BIOS or Bootloader sets specific debounce for the
331 GPIO. if not, set debounce to be 2.75ms.
332 */
333 if ((pin_reg & DB_TMR_OUT_MASK) == 0) {
334 pin_reg |= 0xf;
335 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
336 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
337 }
338 pin_reg |= BIT(INTERRUPT_ENABLE_OFF); 318 pin_reg |= BIT(INTERRUPT_ENABLE_OFF);
339 pin_reg |= BIT(INTERRUPT_MASK_OFF); 319 pin_reg |= BIT(INTERRUPT_MASK_OFF);
340 writel(pin_reg, gpio_dev->base + (d->hwirq)*4); 320 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
diff --git a/drivers/pinctrl/pinctrl-pistachio.c b/drivers/pinctrl/pinctrl-pistachio.c
index c6d410ef8de0..7bad200bd67c 100644
--- a/drivers/pinctrl/pinctrl-pistachio.c
+++ b/drivers/pinctrl/pinctrl-pistachio.c
@@ -1432,7 +1432,6 @@ static int pistachio_pinctrl_probe(struct platform_device *pdev)
1432{ 1432{
1433 struct pistachio_pinctrl *pctl; 1433 struct pistachio_pinctrl *pctl;
1434 struct resource *res; 1434 struct resource *res;
1435 int ret;
1436 1435
1437 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); 1436 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
1438 if (!pctl) 1437 if (!pctl)
@@ -1464,13 +1463,7 @@ static int pistachio_pinctrl_probe(struct platform_device *pdev)
1464 return PTR_ERR(pctl->pctldev); 1463 return PTR_ERR(pctl->pctldev);
1465 } 1464 }
1466 1465
1467 ret = pistachio_gpio_register(pctl); 1466 return pistachio_gpio_register(pctl);
1468 if (ret < 0) {
1469 pinctrl_unregister(pctl->pctldev);
1470 return ret;
1471 }
1472
1473 return 0;
1474} 1467}
1475 1468
1476static struct platform_driver pistachio_pinctrl_driver = { 1469static struct platform_driver pistachio_pinctrl_driver = {
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 9c65f134d447..da7a75f82489 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -457,13 +457,16 @@ static inline void max17042_write_model_data(struct max17042_chip *chip,
457} 457}
458 458
459static inline void max17042_read_model_data(struct max17042_chip *chip, 459static inline void max17042_read_model_data(struct max17042_chip *chip,
460 u8 addr, u32 *data, int size) 460 u8 addr, u16 *data, int size)
461{ 461{
462 struct regmap *map = chip->regmap; 462 struct regmap *map = chip->regmap;
463 int i; 463 int i;
464 u32 tmp;
464 465
465 for (i = 0; i < size; i++) 466 for (i = 0; i < size; i++) {
466 regmap_read(map, addr + i, &data[i]); 467 regmap_read(map, addr + i, &tmp);
468 data[i] = (u16)tmp;
469 }
467} 470}
468 471
469static inline int max17042_model_data_compare(struct max17042_chip *chip, 472static inline int max17042_model_data_compare(struct max17042_chip *chip,
@@ -486,7 +489,7 @@ static int max17042_init_model(struct max17042_chip *chip)
486{ 489{
487 int ret; 490 int ret;
488 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); 491 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
489 u32 *temp_data; 492 u16 *temp_data;
490 493
491 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); 494 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
492 if (!temp_data) 495 if (!temp_data)
@@ -501,7 +504,7 @@ static int max17042_init_model(struct max17042_chip *chip)
501 ret = max17042_model_data_compare( 504 ret = max17042_model_data_compare(
502 chip, 505 chip,
503 chip->pdata->config_data->cell_char_tbl, 506 chip->pdata->config_data->cell_char_tbl,
504 (u16 *)temp_data, 507 temp_data,
505 table_size); 508 table_size);
506 509
507 max10742_lock_model(chip); 510 max10742_lock_model(chip);
@@ -514,7 +517,7 @@ static int max17042_verify_model_lock(struct max17042_chip *chip)
514{ 517{
515 int i; 518 int i;
516 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); 519 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
517 u32 *temp_data; 520 u16 *temp_data;
518 int ret = 0; 521 int ret = 0;
519 522
520 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); 523 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 3bfac539334b..c74c3f67b8da 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -200,8 +200,8 @@ config REBOOT_MODE
200config SYSCON_REBOOT_MODE 200config SYSCON_REBOOT_MODE
201 tristate "Generic SYSCON regmap reboot mode driver" 201 tristate "Generic SYSCON regmap reboot mode driver"
202 depends on OF 202 depends on OF
203 depends on MFD_SYSCON
203 select REBOOT_MODE 204 select REBOOT_MODE
204 select MFD_SYSCON
205 help 205 help
206 Say y here will enable reboot mode driver. This will 206 Say y here will enable reboot mode driver. This will
207 get reboot mode arguments and store it in SYSCON mapped 207 get reboot mode arguments and store it in SYSCON mapped
diff --git a/drivers/power/reset/hisi-reboot.c b/drivers/power/reset/hisi-reboot.c
index 9ab7f562a83b..f69387e12c1e 100644
--- a/drivers/power/reset/hisi-reboot.c
+++ b/drivers/power/reset/hisi-reboot.c
@@ -53,13 +53,16 @@ static int hisi_reboot_probe(struct platform_device *pdev)
53 53
54 if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) { 54 if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
55 pr_err("failed to find reboot-offset property\n"); 55 pr_err("failed to find reboot-offset property\n");
56 iounmap(base);
56 return -EINVAL; 57 return -EINVAL;
57 } 58 }
58 59
59 err = register_restart_handler(&hisi_restart_nb); 60 err = register_restart_handler(&hisi_restart_nb);
60 if (err) 61 if (err) {
61 dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n", 62 dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
62 err); 63 err);
64 iounmap(base);
65 }
63 66
64 return err; 67 return err;
65} 68}
diff --git a/drivers/power/tps65217_charger.c b/drivers/power/tps65217_charger.c
index 73dfae41def8..4c56e54af6ac 100644
--- a/drivers/power/tps65217_charger.c
+++ b/drivers/power/tps65217_charger.c
@@ -206,6 +206,7 @@ static int tps65217_charger_probe(struct platform_device *pdev)
206 if (!charger) 206 if (!charger)
207 return -ENOMEM; 207 return -ENOMEM;
208 208
209 platform_set_drvdata(pdev, charger);
209 charger->tps = tps; 210 charger->tps = tps;
210 charger->dev = &pdev->dev; 211 charger->dev = &pdev->dev;
211 212
diff --git a/drivers/rapidio/rio_cm.c b/drivers/rapidio/rio_cm.c
index cecc15a880de..3fa17ac8df54 100644
--- a/drivers/rapidio/rio_cm.c
+++ b/drivers/rapidio/rio_cm.c
@@ -1080,8 +1080,8 @@ static int riocm_send_ack(struct rio_channel *ch)
1080static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id, 1080static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1081 long timeout) 1081 long timeout)
1082{ 1082{
1083 struct rio_channel *ch = NULL; 1083 struct rio_channel *ch;
1084 struct rio_channel *new_ch = NULL; 1084 struct rio_channel *new_ch;
1085 struct conn_req *req; 1085 struct conn_req *req;
1086 struct cm_peer *peer; 1086 struct cm_peer *peer;
1087 int found = 0; 1087 int found = 0;
@@ -1155,6 +1155,7 @@ static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1155 1155
1156 spin_unlock_bh(&ch->lock); 1156 spin_unlock_bh(&ch->lock);
1157 riocm_put_channel(ch); 1157 riocm_put_channel(ch);
1158 ch = NULL;
1158 kfree(req); 1159 kfree(req);
1159 1160
1160 down_read(&rdev_sem); 1161 down_read(&rdev_sem);
@@ -1172,7 +1173,7 @@ static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1172 if (!found) { 1173 if (!found) {
1173 /* If peer device object not found, simply ignore the request */ 1174 /* If peer device object not found, simply ignore the request */
1174 err = -ENODEV; 1175 err = -ENODEV;
1175 goto err_nodev; 1176 goto err_put_new_ch;
1176 } 1177 }
1177 1178
1178 new_ch->rdev = peer->rdev; 1179 new_ch->rdev = peer->rdev;
@@ -1184,15 +1185,16 @@ static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1184 1185
1185 *new_ch_id = new_ch->id; 1186 *new_ch_id = new_ch->id;
1186 return new_ch; 1187 return new_ch;
1188
1189err_put_new_ch:
1190 spin_lock_bh(&idr_lock);
1191 idr_remove(&ch_idr, new_ch->id);
1192 spin_unlock_bh(&idr_lock);
1193 riocm_put_channel(new_ch);
1194
1187err_put: 1195err_put:
1188 riocm_put_channel(ch); 1196 if (ch)
1189err_nodev: 1197 riocm_put_channel(ch);
1190 if (new_ch) {
1191 spin_lock_bh(&idr_lock);
1192 idr_remove(&ch_idr, new_ch->id);
1193 spin_unlock_bh(&idr_lock);
1194 riocm_put_channel(new_ch);
1195 }
1196 *new_ch_id = 0; 1198 *new_ch_id = 0;
1197 return ERR_PTR(err); 1199 return ERR_PTR(err);
1198} 1200}
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 8973d34ce5ba..fb1b56a71475 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1643,9 +1643,18 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1643 u8 *sense = NULL; 1643 u8 *sense = NULL;
1644 int expires; 1644 int expires;
1645 1645
1646 cqr = (struct dasd_ccw_req *) intparm;
1646 if (IS_ERR(irb)) { 1647 if (IS_ERR(irb)) {
1647 switch (PTR_ERR(irb)) { 1648 switch (PTR_ERR(irb)) {
1648 case -EIO: 1649 case -EIO:
1650 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1651 device = (struct dasd_device *) cqr->startdev;
1652 cqr->status = DASD_CQR_CLEARED;
1653 dasd_device_clear_timer(device);
1654 wake_up(&dasd_flush_wq);
1655 dasd_schedule_device_bh(device);
1656 return;
1657 }
1649 break; 1658 break;
1650 case -ETIMEDOUT: 1659 case -ETIMEDOUT:
1651 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: " 1660 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
@@ -1661,7 +1670,6 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1661 } 1670 }
1662 1671
1663 now = get_tod_clock(); 1672 now = get_tod_clock();
1664 cqr = (struct dasd_ccw_req *) intparm;
1665 /* check for conditions that should be handled immediately */ 1673 /* check for conditions that should be handled immediately */
1666 if (!cqr || 1674 if (!cqr ||
1667 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) && 1675 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index fd2eff440098..98bbec44bcd0 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -5078,6 +5078,8 @@ static int dasd_eckd_read_message_buffer(struct dasd_device *device,
5078 return PTR_ERR(cqr); 5078 return PTR_ERR(cqr);
5079 } 5079 }
5080 5080
5081 cqr->lpm = lpum;
5082retry:
5081 cqr->startdev = device; 5083 cqr->startdev = device;
5082 cqr->memdev = device; 5084 cqr->memdev = device;
5083 cqr->block = NULL; 5085 cqr->block = NULL;
@@ -5122,6 +5124,14 @@ static int dasd_eckd_read_message_buffer(struct dasd_device *device,
5122 (prssdp + 1); 5124 (prssdp + 1);
5123 memcpy(messages, message_buf, 5125 memcpy(messages, message_buf,
5124 sizeof(struct dasd_rssd_messages)); 5126 sizeof(struct dasd_rssd_messages));
5127 } else if (cqr->lpm) {
5128 /*
5129 * on z/VM we might not be able to do I/O on the requested path
5130 * but instead we get the required information on any path
5131 * so retry with open path mask
5132 */
5133 cqr->lpm = 0;
5134 goto retry;
5125 } else 5135 } else
5126 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, 5136 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5127 "Reading messages failed with rc=%d\n" 5137 "Reading messages failed with rc=%d\n"
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 7ada078ffdd0..6a58bc8f46e2 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -762,7 +762,6 @@ static int io_subchannel_initialize_dev(struct subchannel *sch,
762 priv->state = DEV_STATE_NOT_OPER; 762 priv->state = DEV_STATE_NOT_OPER;
763 priv->dev_id.devno = sch->schib.pmcw.dev; 763 priv->dev_id.devno = sch->schib.pmcw.dev;
764 priv->dev_id.ssid = sch->schid.ssid; 764 priv->dev_id.ssid = sch->schid.ssid;
765 priv->schid = sch->schid;
766 765
767 INIT_WORK(&priv->todo_work, ccw_device_todo); 766 INIT_WORK(&priv->todo_work, ccw_device_todo);
768 INIT_LIST_HEAD(&priv->cmb_list); 767 INIT_LIST_HEAD(&priv->cmb_list);
@@ -1000,7 +999,6 @@ static int ccw_device_move_to_sch(struct ccw_device *cdev,
1000 put_device(&old_sch->dev); 999 put_device(&old_sch->dev);
1001 /* Initialize new subchannel. */ 1000 /* Initialize new subchannel. */
1002 spin_lock_irq(sch->lock); 1001 spin_lock_irq(sch->lock);
1003 cdev->private->schid = sch->schid;
1004 cdev->ccwlock = sch->lock; 1002 cdev->ccwlock = sch->lock;
1005 if (!sch_is_pseudo_sch(sch)) 1003 if (!sch_is_pseudo_sch(sch))
1006 sch_set_cdev(sch, cdev); 1004 sch_set_cdev(sch, cdev);
diff --git a/drivers/s390/cio/device_status.c b/drivers/s390/cio/device_status.c
index 15b56a15db15..9bc3512374c9 100644
--- a/drivers/s390/cio/device_status.c
+++ b/drivers/s390/cio/device_status.c
@@ -26,6 +26,7 @@
26static void 26static void
27ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb) 27ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
28{ 28{
29 struct subchannel *sch = to_subchannel(cdev->dev.parent);
29 char dbf_text[15]; 30 char dbf_text[15];
30 31
31 if (!scsw_is_valid_cstat(&irb->scsw) || 32 if (!scsw_is_valid_cstat(&irb->scsw) ||
@@ -36,10 +37,10 @@ ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
36 "received" 37 "received"
37 " ... device %04x on subchannel 0.%x.%04x, dev_stat " 38 " ... device %04x on subchannel 0.%x.%04x, dev_stat "
38 ": %02X sch_stat : %02X\n", 39 ": %02X sch_stat : %02X\n",
39 cdev->private->dev_id.devno, cdev->private->schid.ssid, 40 cdev->private->dev_id.devno, sch->schid.ssid,
40 cdev->private->schid.sch_no, 41 sch->schid.sch_no,
41 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw)); 42 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw));
42 sprintf(dbf_text, "chk%x", cdev->private->schid.sch_no); 43 sprintf(dbf_text, "chk%x", sch->schid.sch_no);
43 CIO_TRACE_EVENT(0, dbf_text); 44 CIO_TRACE_EVENT(0, dbf_text);
44 CIO_HEX_EVENT(0, irb, sizeof(struct irb)); 45 CIO_HEX_EVENT(0, irb, sizeof(struct irb));
45} 46}
diff --git a/drivers/s390/cio/io_sch.h b/drivers/s390/cio/io_sch.h
index 8975060af96c..220f49145b2f 100644
--- a/drivers/s390/cio/io_sch.h
+++ b/drivers/s390/cio/io_sch.h
@@ -120,7 +120,6 @@ struct ccw_device_private {
120 int state; /* device state */ 120 int state; /* device state */
121 atomic_t onoff; 121 atomic_t onoff;
122 struct ccw_dev_id dev_id; /* device id */ 122 struct ccw_dev_id dev_id; /* device id */
123 struct subchannel_id schid; /* subchannel number */
124 struct ccw_request req; /* internal I/O request */ 123 struct ccw_request req; /* internal I/O request */
125 int iretry; 124 int iretry;
126 u8 pgid_valid_mask; /* mask of valid PGIDs */ 125 u8 pgid_valid_mask; /* mask of valid PGIDs */
diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c
index 4bb5262f7aee..71bf9bded485 100644
--- a/drivers/s390/cio/qdio_main.c
+++ b/drivers/s390/cio/qdio_main.c
@@ -686,6 +686,15 @@ static void qdio_kick_handler(struct qdio_q *q)
686 q->qdio_error = 0; 686 q->qdio_error = 0;
687} 687}
688 688
689static inline int qdio_tasklet_schedule(struct qdio_q *q)
690{
691 if (likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE)) {
692 tasklet_schedule(&q->tasklet);
693 return 0;
694 }
695 return -EPERM;
696}
697
689static void __qdio_inbound_processing(struct qdio_q *q) 698static void __qdio_inbound_processing(struct qdio_q *q)
690{ 699{
691 qperf_inc(q, tasklet_inbound); 700 qperf_inc(q, tasklet_inbound);
@@ -698,10 +707,8 @@ static void __qdio_inbound_processing(struct qdio_q *q)
698 if (!qdio_inbound_q_done(q)) { 707 if (!qdio_inbound_q_done(q)) {
699 /* means poll time is not yet over */ 708 /* means poll time is not yet over */
700 qperf_inc(q, tasklet_inbound_resched); 709 qperf_inc(q, tasklet_inbound_resched);
701 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) { 710 if (!qdio_tasklet_schedule(q))
702 tasklet_schedule(&q->tasklet);
703 return; 711 return;
704 }
705 } 712 }
706 713
707 qdio_stop_polling(q); 714 qdio_stop_polling(q);
@@ -711,8 +718,7 @@ static void __qdio_inbound_processing(struct qdio_q *q)
711 */ 718 */
712 if (!qdio_inbound_q_done(q)) { 719 if (!qdio_inbound_q_done(q)) {
713 qperf_inc(q, tasklet_inbound_resched2); 720 qperf_inc(q, tasklet_inbound_resched2);
714 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) 721 qdio_tasklet_schedule(q);
715 tasklet_schedule(&q->tasklet);
716 } 722 }
717} 723}
718 724
@@ -869,16 +875,15 @@ static void __qdio_outbound_processing(struct qdio_q *q)
869 * is noticed and outbound_handler is called after some time. 875 * is noticed and outbound_handler is called after some time.
870 */ 876 */
871 if (qdio_outbound_q_done(q)) 877 if (qdio_outbound_q_done(q))
872 del_timer(&q->u.out.timer); 878 del_timer_sync(&q->u.out.timer);
873 else 879 else
874 if (!timer_pending(&q->u.out.timer)) 880 if (!timer_pending(&q->u.out.timer) &&
881 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
875 mod_timer(&q->u.out.timer, jiffies + 10 * HZ); 882 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
876 return; 883 return;
877 884
878sched: 885sched:
879 if (unlikely(q->irq_ptr->state == QDIO_IRQ_STATE_STOPPED)) 886 qdio_tasklet_schedule(q);
880 return;
881 tasklet_schedule(&q->tasklet);
882} 887}
883 888
884/* outbound tasklet */ 889/* outbound tasklet */
@@ -892,9 +897,7 @@ void qdio_outbound_timer(unsigned long data)
892{ 897{
893 struct qdio_q *q = (struct qdio_q *)data; 898 struct qdio_q *q = (struct qdio_q *)data;
894 899
895 if (unlikely(q->irq_ptr->state == QDIO_IRQ_STATE_STOPPED)) 900 qdio_tasklet_schedule(q);
896 return;
897 tasklet_schedule(&q->tasklet);
898} 901}
899 902
900static inline void qdio_check_outbound_after_thinint(struct qdio_q *q) 903static inline void qdio_check_outbound_after_thinint(struct qdio_q *q)
@@ -907,7 +910,7 @@ static inline void qdio_check_outbound_after_thinint(struct qdio_q *q)
907 910
908 for_each_output_queue(q->irq_ptr, out, i) 911 for_each_output_queue(q->irq_ptr, out, i)
909 if (!qdio_outbound_q_done(out)) 912 if (!qdio_outbound_q_done(out))
910 tasklet_schedule(&out->tasklet); 913 qdio_tasklet_schedule(out);
911} 914}
912 915
913static void __tiqdio_inbound_processing(struct qdio_q *q) 916static void __tiqdio_inbound_processing(struct qdio_q *q)
@@ -929,10 +932,8 @@ static void __tiqdio_inbound_processing(struct qdio_q *q)
929 932
930 if (!qdio_inbound_q_done(q)) { 933 if (!qdio_inbound_q_done(q)) {
931 qperf_inc(q, tasklet_inbound_resched); 934 qperf_inc(q, tasklet_inbound_resched);
932 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) { 935 if (!qdio_tasklet_schedule(q))
933 tasklet_schedule(&q->tasklet);
934 return; 936 return;
935 }
936 } 937 }
937 938
938 qdio_stop_polling(q); 939 qdio_stop_polling(q);
@@ -942,8 +943,7 @@ static void __tiqdio_inbound_processing(struct qdio_q *q)
942 */ 943 */
943 if (!qdio_inbound_q_done(q)) { 944 if (!qdio_inbound_q_done(q)) {
944 qperf_inc(q, tasklet_inbound_resched2); 945 qperf_inc(q, tasklet_inbound_resched2);
945 if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) 946 qdio_tasklet_schedule(q);
946 tasklet_schedule(&q->tasklet);
947 } 947 }
948} 948}
949 949
@@ -977,7 +977,7 @@ static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
977 int i; 977 int i;
978 struct qdio_q *q; 978 struct qdio_q *q;
979 979
980 if (unlikely(irq_ptr->state == QDIO_IRQ_STATE_STOPPED)) 980 if (unlikely(irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
981 return; 981 return;
982 982
983 for_each_input_queue(irq_ptr, q, i) { 983 for_each_input_queue(irq_ptr, q, i) {
@@ -1003,7 +1003,7 @@ static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
1003 continue; 1003 continue;
1004 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q)) 1004 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
1005 qdio_siga_sync_q(q); 1005 qdio_siga_sync_q(q);
1006 tasklet_schedule(&q->tasklet); 1006 qdio_tasklet_schedule(q);
1007 } 1007 }
1008} 1008}
1009 1009
@@ -1066,10 +1066,12 @@ void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1066 struct irb *irb) 1066 struct irb *irb)
1067{ 1067{
1068 struct qdio_irq *irq_ptr = cdev->private->qdio_data; 1068 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1069 struct subchannel_id schid;
1069 int cstat, dstat; 1070 int cstat, dstat;
1070 1071
1071 if (!intparm || !irq_ptr) { 1072 if (!intparm || !irq_ptr) {
1072 DBF_ERROR("qint:%4x", cdev->private->schid.sch_no); 1073 ccw_device_get_schid(cdev, &schid);
1074 DBF_ERROR("qint:%4x", schid.sch_no);
1073 return; 1075 return;
1074 } 1076 }
1075 1077
@@ -1122,12 +1124,14 @@ void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1122int qdio_get_ssqd_desc(struct ccw_device *cdev, 1124int qdio_get_ssqd_desc(struct ccw_device *cdev,
1123 struct qdio_ssqd_desc *data) 1125 struct qdio_ssqd_desc *data)
1124{ 1126{
1127 struct subchannel_id schid;
1125 1128
1126 if (!cdev || !cdev->private) 1129 if (!cdev || !cdev->private)
1127 return -EINVAL; 1130 return -EINVAL;
1128 1131
1129 DBF_EVENT("get ssqd:%4x", cdev->private->schid.sch_no); 1132 ccw_device_get_schid(cdev, &schid);
1130 return qdio_setup_get_ssqd(NULL, &cdev->private->schid, data); 1133 DBF_EVENT("get ssqd:%4x", schid.sch_no);
1134 return qdio_setup_get_ssqd(NULL, &schid, data);
1131} 1135}
1132EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc); 1136EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1133 1137
@@ -1141,7 +1145,7 @@ static void qdio_shutdown_queues(struct ccw_device *cdev)
1141 tasklet_kill(&q->tasklet); 1145 tasklet_kill(&q->tasklet);
1142 1146
1143 for_each_output_queue(irq_ptr, q, i) { 1147 for_each_output_queue(irq_ptr, q, i) {
1144 del_timer(&q->u.out.timer); 1148 del_timer_sync(&q->u.out.timer);
1145 tasklet_kill(&q->tasklet); 1149 tasklet_kill(&q->tasklet);
1146 } 1150 }
1147} 1151}
@@ -1154,14 +1158,15 @@ static void qdio_shutdown_queues(struct ccw_device *cdev)
1154int qdio_shutdown(struct ccw_device *cdev, int how) 1158int qdio_shutdown(struct ccw_device *cdev, int how)
1155{ 1159{
1156 struct qdio_irq *irq_ptr = cdev->private->qdio_data; 1160 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1161 struct subchannel_id schid;
1157 int rc; 1162 int rc;
1158 unsigned long flags;
1159 1163
1160 if (!irq_ptr) 1164 if (!irq_ptr)
1161 return -ENODEV; 1165 return -ENODEV;
1162 1166
1163 WARN_ON_ONCE(irqs_disabled()); 1167 WARN_ON_ONCE(irqs_disabled());
1164 DBF_EVENT("qshutdown:%4x", cdev->private->schid.sch_no); 1168 ccw_device_get_schid(cdev, &schid);
1169 DBF_EVENT("qshutdown:%4x", schid.sch_no);
1165 1170
1166 mutex_lock(&irq_ptr->setup_mutex); 1171 mutex_lock(&irq_ptr->setup_mutex);
1167 /* 1172 /*
@@ -1184,7 +1189,7 @@ int qdio_shutdown(struct ccw_device *cdev, int how)
1184 qdio_shutdown_debug_entries(irq_ptr); 1189 qdio_shutdown_debug_entries(irq_ptr);
1185 1190
1186 /* cleanup subchannel */ 1191 /* cleanup subchannel */
1187 spin_lock_irqsave(get_ccwdev_lock(cdev), flags); 1192 spin_lock_irq(get_ccwdev_lock(cdev));
1188 1193
1189 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR) 1194 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1190 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP); 1195 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
@@ -1198,12 +1203,12 @@ int qdio_shutdown(struct ccw_device *cdev, int how)
1198 } 1203 }
1199 1204
1200 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP); 1205 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1201 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); 1206 spin_unlock_irq(get_ccwdev_lock(cdev));
1202 wait_event_interruptible_timeout(cdev->private->wait_q, 1207 wait_event_interruptible_timeout(cdev->private->wait_q,
1203 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE || 1208 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1204 irq_ptr->state == QDIO_IRQ_STATE_ERR, 1209 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1205 10 * HZ); 1210 10 * HZ);
1206 spin_lock_irqsave(get_ccwdev_lock(cdev), flags); 1211 spin_lock_irq(get_ccwdev_lock(cdev));
1207 1212
1208no_cleanup: 1213no_cleanup:
1209 qdio_shutdown_thinint(irq_ptr); 1214 qdio_shutdown_thinint(irq_ptr);
@@ -1211,7 +1216,7 @@ no_cleanup:
1211 /* restore interrupt handler */ 1216 /* restore interrupt handler */
1212 if ((void *)cdev->handler == (void *)qdio_int_handler) 1217 if ((void *)cdev->handler == (void *)qdio_int_handler)
1213 cdev->handler = irq_ptr->orig_handler; 1218 cdev->handler = irq_ptr->orig_handler;
1214 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); 1219 spin_unlock_irq(get_ccwdev_lock(cdev));
1215 1220
1216 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); 1221 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1217 mutex_unlock(&irq_ptr->setup_mutex); 1222 mutex_unlock(&irq_ptr->setup_mutex);
@@ -1228,11 +1233,13 @@ EXPORT_SYMBOL_GPL(qdio_shutdown);
1228int qdio_free(struct ccw_device *cdev) 1233int qdio_free(struct ccw_device *cdev)
1229{ 1234{
1230 struct qdio_irq *irq_ptr = cdev->private->qdio_data; 1235 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1236 struct subchannel_id schid;
1231 1237
1232 if (!irq_ptr) 1238 if (!irq_ptr)
1233 return -ENODEV; 1239 return -ENODEV;
1234 1240
1235 DBF_EVENT("qfree:%4x", cdev->private->schid.sch_no); 1241 ccw_device_get_schid(cdev, &schid);
1242 DBF_EVENT("qfree:%4x", schid.sch_no);
1236 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned"); 1243 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
1237 mutex_lock(&irq_ptr->setup_mutex); 1244 mutex_lock(&irq_ptr->setup_mutex);
1238 1245
@@ -1251,9 +1258,11 @@ EXPORT_SYMBOL_GPL(qdio_free);
1251 */ 1258 */
1252int qdio_allocate(struct qdio_initialize *init_data) 1259int qdio_allocate(struct qdio_initialize *init_data)
1253{ 1260{
1261 struct subchannel_id schid;
1254 struct qdio_irq *irq_ptr; 1262 struct qdio_irq *irq_ptr;
1255 1263
1256 DBF_EVENT("qallocate:%4x", init_data->cdev->private->schid.sch_no); 1264 ccw_device_get_schid(init_data->cdev, &schid);
1265 DBF_EVENT("qallocate:%4x", schid.sch_no);
1257 1266
1258 if ((init_data->no_input_qs && !init_data->input_handler) || 1267 if ((init_data->no_input_qs && !init_data->input_handler) ||
1259 (init_data->no_output_qs && !init_data->output_handler)) 1268 (init_data->no_output_qs && !init_data->output_handler))
@@ -1331,20 +1340,18 @@ static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1331 */ 1340 */
1332int qdio_establish(struct qdio_initialize *init_data) 1341int qdio_establish(struct qdio_initialize *init_data)
1333{ 1342{
1334 struct qdio_irq *irq_ptr;
1335 struct ccw_device *cdev = init_data->cdev; 1343 struct ccw_device *cdev = init_data->cdev;
1336 unsigned long saveflags; 1344 struct subchannel_id schid;
1345 struct qdio_irq *irq_ptr;
1337 int rc; 1346 int rc;
1338 1347
1339 DBF_EVENT("qestablish:%4x", cdev->private->schid.sch_no); 1348 ccw_device_get_schid(cdev, &schid);
1349 DBF_EVENT("qestablish:%4x", schid.sch_no);
1340 1350
1341 irq_ptr = cdev->private->qdio_data; 1351 irq_ptr = cdev->private->qdio_data;
1342 if (!irq_ptr) 1352 if (!irq_ptr)
1343 return -ENODEV; 1353 return -ENODEV;
1344 1354
1345 if (cdev->private->state != DEV_STATE_ONLINE)
1346 return -EINVAL;
1347
1348 mutex_lock(&irq_ptr->setup_mutex); 1355 mutex_lock(&irq_ptr->setup_mutex);
1349 qdio_setup_irq(init_data); 1356 qdio_setup_irq(init_data);
1350 1357
@@ -1361,17 +1368,14 @@ int qdio_establish(struct qdio_initialize *init_data)
1361 irq_ptr->ccw.count = irq_ptr->equeue.count; 1368 irq_ptr->ccw.count = irq_ptr->equeue.count;
1362 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr); 1369 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1363 1370
1364 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags); 1371 spin_lock_irq(get_ccwdev_lock(cdev));
1365 ccw_device_set_options_mask(cdev, 0); 1372 ccw_device_set_options_mask(cdev, 0);
1366 1373
1367 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0); 1374 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1375 spin_unlock_irq(get_ccwdev_lock(cdev));
1368 if (rc) { 1376 if (rc) {
1369 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no); 1377 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1370 DBF_ERROR("rc:%4x", rc); 1378 DBF_ERROR("rc:%4x", rc);
1371 }
1372 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1373
1374 if (rc) {
1375 mutex_unlock(&irq_ptr->setup_mutex); 1379 mutex_unlock(&irq_ptr->setup_mutex);
1376 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); 1380 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1377 return rc; 1381 return rc;
@@ -1407,19 +1411,17 @@ EXPORT_SYMBOL_GPL(qdio_establish);
1407 */ 1411 */
1408int qdio_activate(struct ccw_device *cdev) 1412int qdio_activate(struct ccw_device *cdev)
1409{ 1413{
1414 struct subchannel_id schid;
1410 struct qdio_irq *irq_ptr; 1415 struct qdio_irq *irq_ptr;
1411 int rc; 1416 int rc;
1412 unsigned long saveflags;
1413 1417
1414 DBF_EVENT("qactivate:%4x", cdev->private->schid.sch_no); 1418 ccw_device_get_schid(cdev, &schid);
1419 DBF_EVENT("qactivate:%4x", schid.sch_no);
1415 1420
1416 irq_ptr = cdev->private->qdio_data; 1421 irq_ptr = cdev->private->qdio_data;
1417 if (!irq_ptr) 1422 if (!irq_ptr)
1418 return -ENODEV; 1423 return -ENODEV;
1419 1424
1420 if (cdev->private->state != DEV_STATE_ONLINE)
1421 return -EINVAL;
1422
1423 mutex_lock(&irq_ptr->setup_mutex); 1425 mutex_lock(&irq_ptr->setup_mutex);
1424 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) { 1426 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1425 rc = -EBUSY; 1427 rc = -EBUSY;
@@ -1431,19 +1433,17 @@ int qdio_activate(struct ccw_device *cdev)
1431 irq_ptr->ccw.count = irq_ptr->aqueue.count; 1433 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1432 irq_ptr->ccw.cda = 0; 1434 irq_ptr->ccw.cda = 0;
1433 1435
1434 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags); 1436 spin_lock_irq(get_ccwdev_lock(cdev));
1435 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL); 1437 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1436 1438
1437 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE, 1439 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1438 0, DOIO_DENY_PREFETCH); 1440 0, DOIO_DENY_PREFETCH);
1441 spin_unlock_irq(get_ccwdev_lock(cdev));
1439 if (rc) { 1442 if (rc) {
1440 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no); 1443 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1441 DBF_ERROR("rc:%4x", rc); 1444 DBF_ERROR("rc:%4x", rc);
1442 }
1443 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1444
1445 if (rc)
1446 goto out; 1445 goto out;
1446 }
1447 1447
1448 if (is_thinint_irq(irq_ptr)) 1448 if (is_thinint_irq(irq_ptr))
1449 tiqdio_add_input_queues(irq_ptr); 1449 tiqdio_add_input_queues(irq_ptr);
@@ -1585,10 +1585,11 @@ static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1585 1585
1586 /* in case of SIGA errors we must process the error immediately */ 1586 /* in case of SIGA errors we must process the error immediately */
1587 if (used >= q->u.out.scan_threshold || rc) 1587 if (used >= q->u.out.scan_threshold || rc)
1588 tasklet_schedule(&q->tasklet); 1588 qdio_tasklet_schedule(q);
1589 else 1589 else
1590 /* free the SBALs in case of no further traffic */ 1590 /* free the SBALs in case of no further traffic */
1591 if (!timer_pending(&q->u.out.timer)) 1591 if (!timer_pending(&q->u.out.timer) &&
1592 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
1592 mod_timer(&q->u.out.timer, jiffies + HZ); 1593 mod_timer(&q->u.out.timer, jiffies + HZ);
1593 return rc; 1594 return rc;
1594} 1595}
diff --git a/drivers/s390/virtio/Makefile b/drivers/s390/virtio/Makefile
index 241891a57caf..df40692a9011 100644
--- a/drivers/s390/virtio/Makefile
+++ b/drivers/s390/virtio/Makefile
@@ -6,4 +6,8 @@
6# it under the terms of the GNU General Public License (version 2 only) 6# it under the terms of the GNU General Public License (version 2 only)
7# as published by the Free Software Foundation. 7# as published by the Free Software Foundation.
8 8
9obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o 9s390-virtio-objs := virtio_ccw.o
10ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
11s390-virtio-objs += kvm_virtio.o
12endif
13obj-$(CONFIG_S390_GUEST) += $(s390-virtio-objs)
diff --git a/drivers/s390/virtio/kvm_virtio.c b/drivers/s390/virtio/kvm_virtio.c
index 1d060fd293a3..5e5c11f37b24 100644
--- a/drivers/s390/virtio/kvm_virtio.c
+++ b/drivers/s390/virtio/kvm_virtio.c
@@ -458,6 +458,8 @@ static int __init kvm_devices_init(void)
458 if (test_devices_support(total_memory_size) < 0) 458 if (test_devices_support(total_memory_size) < 0)
459 return -ENODEV; 459 return -ENODEV;
460 460
461 pr_warn("The s390-virtio transport is deprecated. Please switch to a modern host providing virtio-ccw.\n");
462
461 rc = vmem_add_mapping(total_memory_size, PAGE_SIZE); 463 rc = vmem_add_mapping(total_memory_size, PAGE_SIZE);
462 if (rc) 464 if (rc)
463 return rc; 465 return rc;
@@ -482,7 +484,7 @@ static int __init kvm_devices_init(void)
482} 484}
483 485
484/* code for early console output with virtio_console */ 486/* code for early console output with virtio_console */
485static __init int early_put_chars(u32 vtermno, const char *buf, int count) 487static int early_put_chars(u32 vtermno, const char *buf, int count)
486{ 488{
487 char scratch[17]; 489 char scratch[17];
488 unsigned int len = count; 490 unsigned int len = count;
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index b381b3718a98..5648b715fed9 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -63,7 +63,7 @@ static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
63 struct fib *fibptr; 63 struct fib *fibptr;
64 struct hw_fib * hw_fib = (struct hw_fib *)0; 64 struct hw_fib * hw_fib = (struct hw_fib *)0;
65 dma_addr_t hw_fib_pa = (dma_addr_t)0LL; 65 dma_addr_t hw_fib_pa = (dma_addr_t)0LL;
66 unsigned size; 66 unsigned int size, osize;
67 int retval; 67 int retval;
68 68
69 if (dev->in_reset) { 69 if (dev->in_reset) {
@@ -87,7 +87,8 @@ static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
87 * will not overrun the buffer when we copy the memory. Return 87 * will not overrun the buffer when we copy the memory. Return
88 * an error if we would. 88 * an error if we would.
89 */ 89 */
90 size = le16_to_cpu(kfib->header.Size) + sizeof(struct aac_fibhdr); 90 osize = size = le16_to_cpu(kfib->header.Size) +
91 sizeof(struct aac_fibhdr);
91 if (size < le16_to_cpu(kfib->header.SenderSize)) 92 if (size < le16_to_cpu(kfib->header.SenderSize))
92 size = le16_to_cpu(kfib->header.SenderSize); 93 size = le16_to_cpu(kfib->header.SenderSize);
93 if (size > dev->max_fib_size) { 94 if (size > dev->max_fib_size) {
@@ -118,6 +119,14 @@ static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
118 goto cleanup; 119 goto cleanup;
119 } 120 }
120 121
122 /* Sanity check the second copy */
123 if ((osize != le16_to_cpu(kfib->header.Size) +
124 sizeof(struct aac_fibhdr))
125 || (size < le16_to_cpu(kfib->header.SenderSize))) {
126 retval = -EINVAL;
127 goto cleanup;
128 }
129
121 if (kfib->header.Command == cpu_to_le16(TakeABreakPt)) { 130 if (kfib->header.Command == cpu_to_le16(TakeABreakPt)) {
122 aac_adapter_interrupt(dev); 131 aac_adapter_interrupt(dev);
123 /* 132 /*
diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index a569c65f22b1..dcf36537a767 100644
--- a/drivers/scsi/fcoe/fcoe_ctlr.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -2923,7 +2923,7 @@ static int fcoe_ctlr_vlan_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
2923 mutex_unlock(&fip->ctlr_mutex); 2923 mutex_unlock(&fip->ctlr_mutex);
2924 2924
2925drop: 2925drop:
2926 kfree(skb); 2926 kfree_skb(skb);
2927 return rc; 2927 return rc;
2928} 2928}
2929 2929
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 2dab3dc2aa69..c1ed25adb17e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -5037,7 +5037,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
5037 /* Find first memory bar */ 5037 /* Find first memory bar */
5038 bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); 5038 bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM);
5039 instance->bar = find_first_bit(&bar_list, sizeof(unsigned long)); 5039 instance->bar = find_first_bit(&bar_list, sizeof(unsigned long));
5040 if (pci_request_selected_regions(instance->pdev, instance->bar, 5040 if (pci_request_selected_regions(instance->pdev, 1<<instance->bar,
5041 "megasas: LSI")) { 5041 "megasas: LSI")) {
5042 dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); 5042 dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n");
5043 return -EBUSY; 5043 return -EBUSY;
@@ -5339,7 +5339,7 @@ fail_ready_state:
5339 iounmap(instance->reg_set); 5339 iounmap(instance->reg_set);
5340 5340
5341 fail_ioremap: 5341 fail_ioremap:
5342 pci_release_selected_regions(instance->pdev, instance->bar); 5342 pci_release_selected_regions(instance->pdev, 1<<instance->bar);
5343 5343
5344 return -EINVAL; 5344 return -EINVAL;
5345} 5345}
@@ -5360,7 +5360,7 @@ static void megasas_release_mfi(struct megasas_instance *instance)
5360 5360
5361 iounmap(instance->reg_set); 5361 iounmap(instance->reg_set);
5362 5362
5363 pci_release_selected_regions(instance->pdev, instance->bar); 5363 pci_release_selected_regions(instance->pdev, 1<<instance->bar);
5364} 5364}
5365 5365
5366/** 5366/**
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index ec837544f784..52d8bbf7feb5 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -2603,7 +2603,7 @@ megasas_release_fusion(struct megasas_instance *instance)
2603 2603
2604 iounmap(instance->reg_set); 2604 iounmap(instance->reg_set);
2605 2605
2606 pci_release_selected_regions(instance->pdev, instance->bar); 2606 pci_release_selected_regions(instance->pdev, 1<<instance->bar);
2607} 2607}
2608 2608
2609/** 2609/**
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 751f13edece0..750f82c339d4 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2188,6 +2188,17 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc)
2188 } else 2188 } else
2189 ioc->msix96_vector = 0; 2189 ioc->msix96_vector = 0;
2190 2190
2191 if (ioc->is_warpdrive) {
2192 ioc->reply_post_host_index[0] = (resource_size_t __iomem *)
2193 &ioc->chip->ReplyPostHostIndex;
2194
2195 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
2196 ioc->reply_post_host_index[i] =
2197 (resource_size_t __iomem *)
2198 ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
2199 * 4)));
2200 }
2201
2191 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) 2202 list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
2192 pr_info(MPT3SAS_FMT "%s: IRQ %d\n", 2203 pr_info(MPT3SAS_FMT "%s: IRQ %d\n",
2193 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" : 2204 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
@@ -5280,17 +5291,6 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
5280 if (r) 5291 if (r)
5281 goto out_free_resources; 5292 goto out_free_resources;
5282 5293
5283 if (ioc->is_warpdrive) {
5284 ioc->reply_post_host_index[0] = (resource_size_t __iomem *)
5285 &ioc->chip->ReplyPostHostIndex;
5286
5287 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
5288 ioc->reply_post_host_index[i] =
5289 (resource_size_t __iomem *)
5290 ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
5291 * 4)));
5292 }
5293
5294 pci_set_drvdata(ioc->pdev, ioc->shost); 5294 pci_set_drvdata(ioc->pdev, ioc->shost);
5295 r = _base_get_ioc_facts(ioc, CAN_SLEEP); 5295 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
5296 if (r) 5296 if (r)
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index 53ef1cb6418e..0e8601aa877a 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -778,6 +778,8 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
778 if (!edev) 778 if (!edev)
779 return; 779 return;
780 780
781 enclosure_unregister(edev);
782
781 ses_dev = edev->scratch; 783 ses_dev = edev->scratch;
782 edev->scratch = NULL; 784 edev->scratch = NULL;
783 785
@@ -789,7 +791,6 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
789 kfree(edev->component[0].scratch); 791 kfree(edev->component[0].scratch);
790 792
791 put_device(&edev->edev); 793 put_device(&edev->edev);
792 enclosure_unregister(edev);
793} 794}
794 795
795static void ses_intf_remove(struct device *cdev, 796static void ses_intf_remove(struct device *cdev,
diff --git a/drivers/thermal/clock_cooling.c b/drivers/thermal/clock_cooling.c
index 1b4ff0f4c716..ed5dd0e88657 100644
--- a/drivers/thermal/clock_cooling.c
+++ b/drivers/thermal/clock_cooling.c
@@ -426,6 +426,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
426 if (!ccdev) 426 if (!ccdev)
427 return ERR_PTR(-ENOMEM); 427 return ERR_PTR(-ENOMEM);
428 428
429 mutex_init(&ccdev->lock);
429 ccdev->dev = dev; 430 ccdev->dev = dev;
430 ccdev->clk = devm_clk_get(dev, clock_name); 431 ccdev->clk = devm_clk_get(dev, clock_name);
431 if (IS_ERR(ccdev->clk)) 432 if (IS_ERR(ccdev->clk))
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 3788ed74c9ab..a32b41783b77 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -740,12 +740,22 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
740} 740}
741 741
742/* Bind cpufreq callbacks to thermal cooling device ops */ 742/* Bind cpufreq callbacks to thermal cooling device ops */
743
743static struct thermal_cooling_device_ops cpufreq_cooling_ops = { 744static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
744 .get_max_state = cpufreq_get_max_state, 745 .get_max_state = cpufreq_get_max_state,
745 .get_cur_state = cpufreq_get_cur_state, 746 .get_cur_state = cpufreq_get_cur_state,
746 .set_cur_state = cpufreq_set_cur_state, 747 .set_cur_state = cpufreq_set_cur_state,
747}; 748};
748 749
750static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = {
751 .get_max_state = cpufreq_get_max_state,
752 .get_cur_state = cpufreq_get_cur_state,
753 .set_cur_state = cpufreq_set_cur_state,
754 .get_requested_power = cpufreq_get_requested_power,
755 .state2power = cpufreq_state2power,
756 .power2state = cpufreq_power2state,
757};
758
749/* Notifier for cpufreq policy change */ 759/* Notifier for cpufreq policy change */
750static struct notifier_block thermal_cpufreq_notifier_block = { 760static struct notifier_block thermal_cpufreq_notifier_block = {
751 .notifier_call = cpufreq_thermal_notifier, 761 .notifier_call = cpufreq_thermal_notifier,
@@ -795,6 +805,7 @@ __cpufreq_cooling_register(struct device_node *np,
795 struct cpumask temp_mask; 805 struct cpumask temp_mask;
796 unsigned int freq, i, num_cpus; 806 unsigned int freq, i, num_cpus;
797 int ret; 807 int ret;
808 struct thermal_cooling_device_ops *cooling_ops;
798 809
799 cpumask_and(&temp_mask, clip_cpus, cpu_online_mask); 810 cpumask_and(&temp_mask, clip_cpus, cpu_online_mask);
800 policy = cpufreq_cpu_get(cpumask_first(&temp_mask)); 811 policy = cpufreq_cpu_get(cpumask_first(&temp_mask));
@@ -850,10 +861,6 @@ __cpufreq_cooling_register(struct device_node *np,
850 cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); 861 cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus);
851 862
852 if (capacitance) { 863 if (capacitance) {
853 cpufreq_cooling_ops.get_requested_power =
854 cpufreq_get_requested_power;
855 cpufreq_cooling_ops.state2power = cpufreq_state2power;
856 cpufreq_cooling_ops.power2state = cpufreq_power2state;
857 cpufreq_dev->plat_get_static_power = plat_static_func; 864 cpufreq_dev->plat_get_static_power = plat_static_func;
858 865
859 ret = build_dyn_power_table(cpufreq_dev, capacitance); 866 ret = build_dyn_power_table(cpufreq_dev, capacitance);
@@ -861,6 +868,10 @@ __cpufreq_cooling_register(struct device_node *np,
861 cool_dev = ERR_PTR(ret); 868 cool_dev = ERR_PTR(ret);
862 goto free_table; 869 goto free_table;
863 } 870 }
871
872 cooling_ops = &cpufreq_power_cooling_ops;
873 } else {
874 cooling_ops = &cpufreq_cooling_ops;
864 } 875 }
865 876
866 ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); 877 ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
@@ -885,7 +896,7 @@ __cpufreq_cooling_register(struct device_node *np,
885 cpufreq_dev->id); 896 cpufreq_dev->id);
886 897
887 cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, 898 cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev,
888 &cpufreq_cooling_ops); 899 cooling_ops);
889 if (IS_ERR(cool_dev)) 900 if (IS_ERR(cool_dev))
890 goto remove_idr; 901 goto remove_idr;
891 902
diff --git a/drivers/thermal/fair_share.c b/drivers/thermal/fair_share.c
index 34fe36504a55..68bd1b569118 100644
--- a/drivers/thermal/fair_share.c
+++ b/drivers/thermal/fair_share.c
@@ -116,7 +116,9 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
116 instance->target = get_target_state(tz, cdev, percentage, 116 instance->target = get_target_state(tz, cdev, percentage,
117 cur_trip_level); 117 cur_trip_level);
118 118
119 mutex_lock(&instance->cdev->lock);
119 instance->cdev->updated = false; 120 instance->cdev->updated = false;
121 mutex_unlock(&instance->cdev->lock);
120 thermal_cdev_update(cdev); 122 thermal_cdev_update(cdev);
121 } 123 }
122 return 0; 124 return 0;
diff --git a/drivers/thermal/gov_bang_bang.c b/drivers/thermal/gov_bang_bang.c
index fc52016d4e85..bb118a152cbb 100644
--- a/drivers/thermal/gov_bang_bang.c
+++ b/drivers/thermal/gov_bang_bang.c
@@ -71,7 +71,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
71 dev_dbg(&instance->cdev->device, "target=%d\n", 71 dev_dbg(&instance->cdev->device, "target=%d\n",
72 (int)instance->target); 72 (int)instance->target);
73 73
74 mutex_lock(&instance->cdev->lock);
74 instance->cdev->updated = false; /* cdev needs update */ 75 instance->cdev->updated = false; /* cdev needs update */
76 mutex_unlock(&instance->cdev->lock);
75 } 77 }
76 78
77 mutex_unlock(&tz->lock); 79 mutex_unlock(&tz->lock);
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index c5547bd711db..e473548b5d28 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -471,8 +471,6 @@ MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
471 471
472static int imx_thermal_probe(struct platform_device *pdev) 472static int imx_thermal_probe(struct platform_device *pdev)
473{ 473{
474 const struct of_device_id *of_id =
475 of_match_device(of_imx_thermal_match, &pdev->dev);
476 struct imx_thermal_data *data; 474 struct imx_thermal_data *data;
477 struct regmap *map; 475 struct regmap *map;
478 int measure_freq; 476 int measure_freq;
@@ -490,7 +488,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
490 } 488 }
491 data->tempmon = map; 489 data->tempmon = map;
492 490
493 data->socdata = of_id->data; 491 data->socdata = of_device_get_match_data(&pdev->dev);
494 492
495 /* make sure the IRQ flag is clear before enabling irq on i.MX6SX */ 493 /* make sure the IRQ flag is clear before enabling irq on i.MX6SX */
496 if (data->socdata->version == TEMPMON_IMX6SX) { 494 if (data->socdata->version == TEMPMON_IMX6SX) {
diff --git a/drivers/thermal/int340x_thermal/int3406_thermal.c b/drivers/thermal/int340x_thermal/int3406_thermal.c
index a578cd257db4..1891f34ab7fc 100644
--- a/drivers/thermal/int340x_thermal/int3406_thermal.c
+++ b/drivers/thermal/int340x_thermal/int3406_thermal.c
@@ -225,7 +225,6 @@ static struct platform_driver int3406_thermal_driver = {
225 .remove = int3406_thermal_remove, 225 .remove = int3406_thermal_remove,
226 .driver = { 226 .driver = {
227 .name = "int3406 thermal", 227 .name = "int3406 thermal",
228 .owner = THIS_MODULE,
229 .acpi_match_table = int3406_thermal_match, 228 .acpi_match_table = int3406_thermal_match,
230 }, 229 },
231}; 230};
diff --git a/drivers/thermal/intel_pch_thermal.c b/drivers/thermal/intel_pch_thermal.c
index 6a6ec1c95a7a..9b4815e81b0d 100644
--- a/drivers/thermal/intel_pch_thermal.c
+++ b/drivers/thermal/intel_pch_thermal.c
@@ -21,6 +21,7 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/thermal.h> 23#include <linux/thermal.h>
24#include <linux/pm.h>
24 25
25/* Intel PCH thermal Device IDs */ 26/* Intel PCH thermal Device IDs */
26#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */ 27#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */
@@ -65,6 +66,7 @@ struct pch_thermal_device {
65 unsigned long crt_temp; 66 unsigned long crt_temp;
66 int hot_trip_id; 67 int hot_trip_id;
67 unsigned long hot_temp; 68 unsigned long hot_temp;
69 bool bios_enabled;
68}; 70};
69 71
70static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) 72static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
@@ -75,8 +77,10 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
75 *nr_trips = 0; 77 *nr_trips = 0;
76 78
77 /* Check if BIOS has already enabled thermal sensor */ 79 /* Check if BIOS has already enabled thermal sensor */
78 if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) 80 if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) {
81 ptd->bios_enabled = true;
79 goto read_trips; 82 goto read_trips;
83 }
80 84
81 tsel = readb(ptd->hw_base + WPT_TSEL); 85 tsel = readb(ptd->hw_base + WPT_TSEL);
82 /* 86 /*
@@ -130,9 +134,39 @@ static int pch_wpt_get_temp(struct pch_thermal_device *ptd, int *temp)
130 return 0; 134 return 0;
131} 135}
132 136
137static int pch_wpt_suspend(struct pch_thermal_device *ptd)
138{
139 u8 tsel;
140
141 if (ptd->bios_enabled)
142 return 0;
143
144 tsel = readb(ptd->hw_base + WPT_TSEL);
145
146 writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL);
147
148 return 0;
149}
150
151static int pch_wpt_resume(struct pch_thermal_device *ptd)
152{
153 u8 tsel;
154
155 if (ptd->bios_enabled)
156 return 0;
157
158 tsel = readb(ptd->hw_base + WPT_TSEL);
159
160 writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
161
162 return 0;
163}
164
133struct pch_dev_ops { 165struct pch_dev_ops {
134 int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips); 166 int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips);
135 int (*get_temp)(struct pch_thermal_device *ptd, int *temp); 167 int (*get_temp)(struct pch_thermal_device *ptd, int *temp);
168 int (*suspend)(struct pch_thermal_device *ptd);
169 int (*resume)(struct pch_thermal_device *ptd);
136}; 170};
137 171
138 172
@@ -140,6 +174,8 @@ struct pch_dev_ops {
140static const struct pch_dev_ops pch_dev_ops_wpt = { 174static const struct pch_dev_ops pch_dev_ops_wpt = {
141 .hw_init = pch_wpt_init, 175 .hw_init = pch_wpt_init,
142 .get_temp = pch_wpt_get_temp, 176 .get_temp = pch_wpt_get_temp,
177 .suspend = pch_wpt_suspend,
178 .resume = pch_wpt_resume,
143}; 179};
144 180
145static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp) 181static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
@@ -269,6 +305,22 @@ static void intel_pch_thermal_remove(struct pci_dev *pdev)
269 pci_disable_device(pdev); 305 pci_disable_device(pdev);
270} 306}
271 307
308static int intel_pch_thermal_suspend(struct device *device)
309{
310 struct pci_dev *pdev = to_pci_dev(device);
311 struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
312
313 return ptd->ops->suspend(ptd);
314}
315
316static int intel_pch_thermal_resume(struct device *device)
317{
318 struct pci_dev *pdev = to_pci_dev(device);
319 struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
320
321 return ptd->ops->resume(ptd);
322}
323
272static struct pci_device_id intel_pch_thermal_id[] = { 324static struct pci_device_id intel_pch_thermal_id[] = {
273 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) }, 325 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) },
274 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) }, 326 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) },
@@ -276,11 +328,17 @@ static struct pci_device_id intel_pch_thermal_id[] = {
276}; 328};
277MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id); 329MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);
278 330
331static const struct dev_pm_ops intel_pch_pm_ops = {
332 .suspend = intel_pch_thermal_suspend,
333 .resume = intel_pch_thermal_resume,
334};
335
279static struct pci_driver intel_pch_thermal_driver = { 336static struct pci_driver intel_pch_thermal_driver = {
280 .name = "intel_pch_thermal", 337 .name = "intel_pch_thermal",
281 .id_table = intel_pch_thermal_id, 338 .id_table = intel_pch_thermal_id,
282 .probe = intel_pch_thermal_probe, 339 .probe = intel_pch_thermal_probe,
283 .remove = intel_pch_thermal_remove, 340 .remove = intel_pch_thermal_remove,
341 .driver.pm = &intel_pch_pm_ops,
284}; 342};
285 343
286module_pci_driver(intel_pch_thermal_driver); 344module_pci_driver(intel_pch_thermal_driver);
diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c
index 015ce2eb6eb7..0e4dc0afcfd2 100644
--- a/drivers/thermal/intel_powerclamp.c
+++ b/drivers/thermal/intel_powerclamp.c
@@ -388,7 +388,7 @@ static int clamp_thread(void *arg)
388 int sleeptime; 388 int sleeptime;
389 unsigned long target_jiffies; 389 unsigned long target_jiffies;
390 unsigned int guard; 390 unsigned int guard;
391 unsigned int compensation = 0; 391 unsigned int compensated_ratio;
392 int interval; /* jiffies to sleep for each attempt */ 392 int interval; /* jiffies to sleep for each attempt */
393 unsigned int duration_jiffies = msecs_to_jiffies(duration); 393 unsigned int duration_jiffies = msecs_to_jiffies(duration);
394 unsigned int window_size_now; 394 unsigned int window_size_now;
@@ -409,8 +409,11 @@ static int clamp_thread(void *arg)
409 * c-states, thus we need to compensate the injected idle ratio 409 * c-states, thus we need to compensate the injected idle ratio
410 * to achieve the actual target reported by the HW. 410 * to achieve the actual target reported by the HW.
411 */ 411 */
412 compensation = get_compensation(target_ratio); 412 compensated_ratio = target_ratio +
413 interval = duration_jiffies*100/(target_ratio+compensation); 413 get_compensation(target_ratio);
414 if (compensated_ratio <= 0)
415 compensated_ratio = 1;
416 interval = duration_jiffies * 100 / compensated_ratio;
414 417
415 /* align idle time */ 418 /* align idle time */
416 target_jiffies = roundup(jiffies, interval); 419 target_jiffies = roundup(jiffies, interval);
@@ -647,8 +650,8 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
647 goto exit_set; 650 goto exit_set;
648 } else if (set_target_ratio > 0 && new_target_ratio == 0) { 651 } else if (set_target_ratio > 0 && new_target_ratio == 0) {
649 pr_info("Stop forced idle injection\n"); 652 pr_info("Stop forced idle injection\n");
650 set_target_ratio = 0;
651 end_power_clamp(); 653 end_power_clamp();
654 set_target_ratio = 0;
652 } else /* adjust currently running */ { 655 } else /* adjust currently running */ {
653 set_target_ratio = new_target_ratio; 656 set_target_ratio = new_target_ratio;
654 /* make new set_target_ratio visible to other cpus */ 657 /* make new set_target_ratio visible to other cpus */
diff --git a/drivers/thermal/power_allocator.c b/drivers/thermal/power_allocator.c
index 2f1a863a8e15..b4d3116cfdaf 100644
--- a/drivers/thermal/power_allocator.c
+++ b/drivers/thermal/power_allocator.c
@@ -529,7 +529,9 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
529 continue; 529 continue;
530 530
531 instance->target = 0; 531 instance->target = 0;
532 mutex_lock(&instance->cdev->lock);
532 instance->cdev->updated = false; 533 instance->cdev->updated = false;
534 mutex_unlock(&instance->cdev->lock);
533 thermal_cdev_update(instance->cdev); 535 thermal_cdev_update(instance->cdev);
534 } 536 }
535} 537}
diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c
index ea9366ad3e6b..bcef2e7c4ec9 100644
--- a/drivers/thermal/step_wise.c
+++ b/drivers/thermal/step_wise.c
@@ -175,7 +175,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
175 update_passive_instance(tz, trip_type, -1); 175 update_passive_instance(tz, trip_type, -1);
176 176
177 instance->initialized = true; 177 instance->initialized = true;
178 mutex_lock(&instance->cdev->lock);
178 instance->cdev->updated = false; /* cdev needs update */ 179 instance->cdev->updated = false; /* cdev needs update */
180 mutex_unlock(&instance->cdev->lock);
179 } 181 }
180 182
181 mutex_unlock(&tz->lock); 183 mutex_unlock(&tz->lock);
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 5133cd1e10b7..e2fc6161dded 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1093,7 +1093,9 @@ int power_actor_set_power(struct thermal_cooling_device *cdev,
1093 return ret; 1093 return ret;
1094 1094
1095 instance->target = state; 1095 instance->target = state;
1096 mutex_lock(&cdev->lock);
1096 cdev->updated = false; 1097 cdev->updated = false;
1098 mutex_unlock(&cdev->lock);
1097 thermal_cdev_update(cdev); 1099 thermal_cdev_update(cdev);
1098 1100
1099 return 0; 1101 return 0;
@@ -1623,11 +1625,13 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
1623 struct thermal_instance *instance; 1625 struct thermal_instance *instance;
1624 unsigned long target = 0; 1626 unsigned long target = 0;
1625 1627
1628 mutex_lock(&cdev->lock);
1626 /* cooling device is updated*/ 1629 /* cooling device is updated*/
1627 if (cdev->updated) 1630 if (cdev->updated) {
1631 mutex_unlock(&cdev->lock);
1628 return; 1632 return;
1633 }
1629 1634
1630 mutex_lock(&cdev->lock);
1631 /* Make sure cdev enters the deepest cooling state */ 1635 /* Make sure cdev enters the deepest cooling state */
1632 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { 1636 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
1633 dev_dbg(&cdev->device, "zone%d->target=%lu\n", 1637 dev_dbg(&cdev->device, "zone%d->target=%lu\n",
@@ -1637,9 +1641,9 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
1637 if (instance->target > target) 1641 if (instance->target > target)
1638 target = instance->target; 1642 target = instance->target;
1639 } 1643 }
1640 mutex_unlock(&cdev->lock);
1641 cdev->ops->set_cur_state(cdev, target); 1644 cdev->ops->set_cur_state(cdev, target);
1642 cdev->updated = true; 1645 cdev->updated = true;
1646 mutex_unlock(&cdev->lock);
1643 trace_cdev_update(cdev, target); 1647 trace_cdev_update(cdev, target);
1644 dev_dbg(&cdev->device, "set to state %lu\n", target); 1648 dev_dbg(&cdev->device, "set to state %lu\n", target);
1645} 1649}
diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index 06fd2ed9ef9d..c41c7742903a 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -232,6 +232,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
232 232
233 return result; 233 return result;
234} 234}
235EXPORT_SYMBOL_GPL(thermal_add_hwmon_sysfs);
235 236
236void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) 237void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
237{ 238{
@@ -270,3 +271,4 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
270 hwmon_device_unregister(hwmon->device); 271 hwmon_device_unregister(hwmon->device);
271 kfree(hwmon); 272 kfree(hwmon);
272} 273}
274EXPORT_SYMBOL_GPL(thermal_remove_hwmon_sysfs);
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 71912301ef7f..0f3f62e81e5b 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1354,7 +1354,6 @@ made_compressed_probe:
1354 spin_lock_init(&acm->write_lock); 1354 spin_lock_init(&acm->write_lock);
1355 spin_lock_init(&acm->read_lock); 1355 spin_lock_init(&acm->read_lock);
1356 mutex_init(&acm->mutex); 1356 mutex_init(&acm->mutex);
1357 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
1358 acm->is_int_ep = usb_endpoint_xfer_int(epread); 1357 acm->is_int_ep = usb_endpoint_xfer_int(epread);
1359 if (acm->is_int_ep) 1358 if (acm->is_int_ep)
1360 acm->bInterval = epread->bInterval; 1359 acm->bInterval = epread->bInterval;
@@ -1394,14 +1393,14 @@ made_compressed_probe:
1394 urb->transfer_dma = rb->dma; 1393 urb->transfer_dma = rb->dma;
1395 if (acm->is_int_ep) { 1394 if (acm->is_int_ep) {
1396 usb_fill_int_urb(urb, acm->dev, 1395 usb_fill_int_urb(urb, acm->dev,
1397 acm->rx_endpoint, 1396 usb_rcvintpipe(usb_dev, epread->bEndpointAddress),
1398 rb->base, 1397 rb->base,
1399 acm->readsize, 1398 acm->readsize,
1400 acm_read_bulk_callback, rb, 1399 acm_read_bulk_callback, rb,
1401 acm->bInterval); 1400 acm->bInterval);
1402 } else { 1401 } else {
1403 usb_fill_bulk_urb(urb, acm->dev, 1402 usb_fill_bulk_urb(urb, acm->dev,
1404 acm->rx_endpoint, 1403 usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress),
1405 rb->base, 1404 rb->base,
1406 acm->readsize, 1405 acm->readsize,
1407 acm_read_bulk_callback, rb); 1406 acm_read_bulk_callback, rb);
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 05ce308d5d2a..1f1eabfd8462 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -96,7 +96,6 @@ struct acm {
96 struct acm_rb read_buffers[ACM_NR]; 96 struct acm_rb read_buffers[ACM_NR];
97 struct acm_wb *putbuffer; /* for acm_tty_put_char() */ 97 struct acm_wb *putbuffer; /* for acm_tty_put_char() */
98 int rx_buflimit; 98 int rx_buflimit;
99 int rx_endpoint;
100 spinlock_t read_lock; 99 spinlock_t read_lock;
101 int write_used; /* number of non-empty write buffers */ 100 int write_used; /* number of non-empty write buffers */
102 int transmitting; 101 int transmitting;
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 31ccdccd7a04..051163189810 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -171,6 +171,31 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
171 ep, buffer, size); 171 ep, buffer, size);
172} 172}
173 173
174static const unsigned short low_speed_maxpacket_maxes[4] = {
175 [USB_ENDPOINT_XFER_CONTROL] = 8,
176 [USB_ENDPOINT_XFER_ISOC] = 0,
177 [USB_ENDPOINT_XFER_BULK] = 0,
178 [USB_ENDPOINT_XFER_INT] = 8,
179};
180static const unsigned short full_speed_maxpacket_maxes[4] = {
181 [USB_ENDPOINT_XFER_CONTROL] = 64,
182 [USB_ENDPOINT_XFER_ISOC] = 1023,
183 [USB_ENDPOINT_XFER_BULK] = 64,
184 [USB_ENDPOINT_XFER_INT] = 64,
185};
186static const unsigned short high_speed_maxpacket_maxes[4] = {
187 [USB_ENDPOINT_XFER_CONTROL] = 64,
188 [USB_ENDPOINT_XFER_ISOC] = 1024,
189 [USB_ENDPOINT_XFER_BULK] = 512,
190 [USB_ENDPOINT_XFER_INT] = 1023,
191};
192static const unsigned short super_speed_maxpacket_maxes[4] = {
193 [USB_ENDPOINT_XFER_CONTROL] = 512,
194 [USB_ENDPOINT_XFER_ISOC] = 1024,
195 [USB_ENDPOINT_XFER_BULK] = 1024,
196 [USB_ENDPOINT_XFER_INT] = 1024,
197};
198
174static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, 199static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
175 int asnum, struct usb_host_interface *ifp, int num_ep, 200 int asnum, struct usb_host_interface *ifp, int num_ep,
176 unsigned char *buffer, int size) 201 unsigned char *buffer, int size)
@@ -179,6 +204,8 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
179 struct usb_endpoint_descriptor *d; 204 struct usb_endpoint_descriptor *d;
180 struct usb_host_endpoint *endpoint; 205 struct usb_host_endpoint *endpoint;
181 int n, i, j, retval; 206 int n, i, j, retval;
207 unsigned int maxp;
208 const unsigned short *maxpacket_maxes;
182 209
183 d = (struct usb_endpoint_descriptor *) buffer; 210 d = (struct usb_endpoint_descriptor *) buffer;
184 buffer += d->bLength; 211 buffer += d->bLength;
@@ -286,6 +313,42 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
286 endpoint->desc.wMaxPacketSize = cpu_to_le16(8); 313 endpoint->desc.wMaxPacketSize = cpu_to_le16(8);
287 } 314 }
288 315
316 /* Validate the wMaxPacketSize field */
317 maxp = usb_endpoint_maxp(&endpoint->desc);
318
319 /* Find the highest legal maxpacket size for this endpoint */
320 i = 0; /* additional transactions per microframe */
321 switch (to_usb_device(ddev)->speed) {
322 case USB_SPEED_LOW:
323 maxpacket_maxes = low_speed_maxpacket_maxes;
324 break;
325 case USB_SPEED_FULL:
326 maxpacket_maxes = full_speed_maxpacket_maxes;
327 break;
328 case USB_SPEED_HIGH:
329 /* Bits 12..11 are allowed only for HS periodic endpoints */
330 if (usb_endpoint_xfer_int(d) || usb_endpoint_xfer_isoc(d)) {
331 i = maxp & (BIT(12) | BIT(11));
332 maxp &= ~i;
333 }
334 /* fallthrough */
335 default:
336 maxpacket_maxes = high_speed_maxpacket_maxes;
337 break;
338 case USB_SPEED_SUPER:
339 case USB_SPEED_SUPER_PLUS:
340 maxpacket_maxes = super_speed_maxpacket_maxes;
341 break;
342 }
343 j = maxpacket_maxes[usb_endpoint_type(&endpoint->desc)];
344
345 if (maxp > j) {
346 dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid maxpacket %d, setting to %d\n",
347 cfgno, inum, asnum, d->bEndpointAddress, maxp, j);
348 maxp = j;
349 endpoint->desc.wMaxPacketSize = cpu_to_le16(i | maxp);
350 }
351
289 /* 352 /*
290 * Some buggy high speed devices have bulk endpoints using 353 * Some buggy high speed devices have bulk endpoints using
291 * maxpacket sizes other than 512. High speed HCDs may not 354 * maxpacket sizes other than 512. High speed HCDs may not
@@ -293,9 +356,6 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
293 */ 356 */
294 if (to_usb_device(ddev)->speed == USB_SPEED_HIGH 357 if (to_usb_device(ddev)->speed == USB_SPEED_HIGH
295 && usb_endpoint_xfer_bulk(d)) { 358 && usb_endpoint_xfer_bulk(d)) {
296 unsigned maxp;
297
298 maxp = usb_endpoint_maxp(&endpoint->desc) & 0x07ff;
299 if (maxp != 512) 359 if (maxp != 512)
300 dev_warn(ddev, "config %d interface %d altsetting %d " 360 dev_warn(ddev, "config %d interface %d altsetting %d "
301 "bulk endpoint 0x%X has invalid maxpacket %d\n", 361 "bulk endpoint 0x%X has invalid maxpacket %d\n",
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index e9f5043a2167..e6a6d67c8705 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -241,7 +241,8 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma)
241 goto error_decrease_mem; 241 goto error_decrease_mem;
242 } 242 }
243 243
244 mem = usb_alloc_coherent(ps->dev, size, GFP_USER, &dma_handle); 244 mem = usb_alloc_coherent(ps->dev, size, GFP_USER | __GFP_NOWARN,
245 &dma_handle);
245 if (!mem) { 246 if (!mem) {
246 ret = -ENOMEM; 247 ret = -ENOMEM;
247 goto error_free_usbm; 248 goto error_free_usbm;
@@ -2582,7 +2583,9 @@ static unsigned int usbdev_poll(struct file *file,
2582 if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed)) 2583 if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed))
2583 mask |= POLLOUT | POLLWRNORM; 2584 mask |= POLLOUT | POLLWRNORM;
2584 if (!connected(ps)) 2585 if (!connected(ps))
2585 mask |= POLLERR | POLLHUP; 2586 mask |= POLLHUP;
2587 if (list_empty(&ps->list))
2588 mask |= POLLERR;
2586 return mask; 2589 return mask;
2587} 2590}
2588 2591
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index bee13517676f..1d5fc32d06d0 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1052,14 +1052,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1052 1052
1053 /* Continue a partial initialization */ 1053 /* Continue a partial initialization */
1054 if (type == HUB_INIT2 || type == HUB_INIT3) { 1054 if (type == HUB_INIT2 || type == HUB_INIT3) {
1055 device_lock(hub->intfdev); 1055 device_lock(&hdev->dev);
1056 1056
1057 /* Was the hub disconnected while we were waiting? */ 1057 /* Was the hub disconnected while we were waiting? */
1058 if (hub->disconnected) { 1058 if (hub->disconnected)
1059 device_unlock(hub->intfdev); 1059 goto disconnected;
1060 kref_put(&hub->kref, hub_release);
1061 return;
1062 }
1063 if (type == HUB_INIT2) 1060 if (type == HUB_INIT2)
1064 goto init2; 1061 goto init2;
1065 goto init3; 1062 goto init3;
@@ -1262,7 +1259,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1262 queue_delayed_work(system_power_efficient_wq, 1259 queue_delayed_work(system_power_efficient_wq,
1263 &hub->init_work, 1260 &hub->init_work,
1264 msecs_to_jiffies(delay)); 1261 msecs_to_jiffies(delay));
1265 device_unlock(hub->intfdev); 1262 device_unlock(&hdev->dev);
1266 return; /* Continues at init3: below */ 1263 return; /* Continues at init3: below */
1267 } else { 1264 } else {
1268 msleep(delay); 1265 msleep(delay);
@@ -1281,12 +1278,12 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1281 /* Scan all ports that need attention */ 1278 /* Scan all ports that need attention */
1282 kick_hub_wq(hub); 1279 kick_hub_wq(hub);
1283 1280
1284 /* Allow autosuspend if it was suppressed */ 1281 if (type == HUB_INIT2 || type == HUB_INIT3) {
1285 if (type <= HUB_INIT3) 1282 /* Allow autosuspend if it was suppressed */
1283 disconnected:
1286 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); 1284 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
1287 1285 device_unlock(&hdev->dev);
1288 if (type == HUB_INIT2 || type == HUB_INIT3) 1286 }
1289 device_unlock(hub->intfdev);
1290 1287
1291 kref_put(&hub->kref, hub_release); 1288 kref_put(&hub->kref, hub_release);
1292} 1289}
@@ -1315,8 +1312,6 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
1315 struct usb_device *hdev = hub->hdev; 1312 struct usb_device *hdev = hub->hdev;
1316 int i; 1313 int i;
1317 1314
1318 cancel_delayed_work_sync(&hub->init_work);
1319
1320 /* hub_wq and related activity won't re-trigger */ 1315 /* hub_wq and related activity won't re-trigger */
1321 hub->quiescing = 1; 1316 hub->quiescing = 1;
1322 1317
diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
index 974335377d9f..e56d59b19a0e 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -61,6 +61,7 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
61 if (!simple->clks) 61 if (!simple->clks)
62 return -ENOMEM; 62 return -ENOMEM;
63 63
64 platform_set_drvdata(pdev, simple);
64 simple->dev = dev; 65 simple->dev = dev;
65 66
66 for (i = 0; i < simple->num_clocks; i++) { 67 for (i = 0; i < simple->num_clocks; i++) {
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 45f5a232d9fb..2eb84d6c24a6 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -37,6 +37,7 @@
37#define PCI_DEVICE_ID_INTEL_BXT 0x0aaa 37#define PCI_DEVICE_ID_INTEL_BXT 0x0aaa
38#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa 38#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa
39#define PCI_DEVICE_ID_INTEL_APL 0x5aaa 39#define PCI_DEVICE_ID_INTEL_APL 0x5aaa
40#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0
40 41
41static const struct acpi_gpio_params reset_gpios = { 0, 0, false }; 42static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
42static const struct acpi_gpio_params cs_gpios = { 1, 0, false }; 43static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
@@ -227,6 +228,7 @@ static const struct pci_device_id dwc3_pci_id_table[] = {
227 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), }, 228 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT), },
228 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, 229 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), },
229 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, 230 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
231 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), },
230 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), }, 232 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
231 { } /* Terminating Entry */ 233 { } /* Terminating Entry */
232}; 234};
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8f8c2157910e..1f5597ef945d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -829,7 +829,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
829 if (!req->request.no_interrupt && !chain) 829 if (!req->request.no_interrupt && !chain)
830 trb->ctrl |= DWC3_TRB_CTRL_IOC | DWC3_TRB_CTRL_ISP_IMI; 830 trb->ctrl |= DWC3_TRB_CTRL_IOC | DWC3_TRB_CTRL_ISP_IMI;
831 831
832 if (last) 832 if (last && !usb_endpoint_xfer_isoc(dep->endpoint.desc))
833 trb->ctrl |= DWC3_TRB_CTRL_LST; 833 trb->ctrl |= DWC3_TRB_CTRL_LST;
834 834
835 if (chain) 835 if (chain)
@@ -1955,7 +1955,8 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
1955 1955
1956static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep, 1956static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
1957 struct dwc3_request *req, struct dwc3_trb *trb, 1957 struct dwc3_request *req, struct dwc3_trb *trb,
1958 const struct dwc3_event_depevt *event, int status) 1958 const struct dwc3_event_depevt *event, int status,
1959 int chain)
1959{ 1960{
1960 unsigned int count; 1961 unsigned int count;
1961 unsigned int s_pkt = 0; 1962 unsigned int s_pkt = 0;
@@ -1964,17 +1965,22 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
1964 dep->queued_requests--; 1965 dep->queued_requests--;
1965 trace_dwc3_complete_trb(dep, trb); 1966 trace_dwc3_complete_trb(dep, trb);
1966 1967
1968 /*
1969 * If we're in the middle of series of chained TRBs and we
1970 * receive a short transfer along the way, DWC3 will skip
1971 * through all TRBs including the last TRB in the chain (the
1972 * where CHN bit is zero. DWC3 will also avoid clearing HWO
1973 * bit and SW has to do it manually.
1974 *
1975 * We're going to do that here to avoid problems of HW trying
1976 * to use bogus TRBs for transfers.
1977 */
1978 if (chain && (trb->ctrl & DWC3_TRB_CTRL_HWO))
1979 trb->ctrl &= ~DWC3_TRB_CTRL_HWO;
1980
1967 if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) 1981 if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN)
1968 /* 1982 return 1;
1969 * We continue despite the error. There is not much we 1983
1970 * can do. If we don't clean it up we loop forever. If
1971 * we skip the TRB then it gets overwritten after a
1972 * while since we use them in a ring buffer. A BUG()
1973 * would help. Lets hope that if this occurs, someone
1974 * fixes the root cause instead of looking away :)
1975 */
1976 dev_err(dwc->dev, "%s's TRB (%p) still owned by HW\n",
1977 dep->name, trb);
1978 count = trb->size & DWC3_TRB_SIZE_MASK; 1984 count = trb->size & DWC3_TRB_SIZE_MASK;
1979 1985
1980 if (dep->direction) { 1986 if (dep->direction) {
@@ -2013,15 +2019,7 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
2013 s_pkt = 1; 2019 s_pkt = 1;
2014 } 2020 }
2015 2021
2016 /* 2022 if (s_pkt && !chain)
2017 * We assume here we will always receive the entire data block
2018 * which we should receive. Meaning, if we program RX to
2019 * receive 4K but we receive only 2K, we assume that's all we
2020 * should receive and we simply bounce the request back to the
2021 * gadget driver for further processing.
2022 */
2023 req->request.actual += req->request.length - count;
2024 if (s_pkt)
2025 return 1; 2023 return 1;
2026 if ((event->status & DEPEVT_STATUS_LST) && 2024 if ((event->status & DEPEVT_STATUS_LST) &&
2027 (trb->ctrl & (DWC3_TRB_CTRL_LST | 2025 (trb->ctrl & (DWC3_TRB_CTRL_LST |
@@ -2040,13 +2038,17 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
2040 struct dwc3_trb *trb; 2038 struct dwc3_trb *trb;
2041 unsigned int slot; 2039 unsigned int slot;
2042 unsigned int i; 2040 unsigned int i;
2041 int count = 0;
2043 int ret; 2042 int ret;
2044 2043
2045 do { 2044 do {
2045 int chain;
2046
2046 req = next_request(&dep->started_list); 2047 req = next_request(&dep->started_list);
2047 if (WARN_ON_ONCE(!req)) 2048 if (WARN_ON_ONCE(!req))
2048 return 1; 2049 return 1;
2049 2050
2051 chain = req->request.num_mapped_sgs > 0;
2050 i = 0; 2052 i = 0;
2051 do { 2053 do {
2052 slot = req->first_trb_index + i; 2054 slot = req->first_trb_index + i;
@@ -2054,13 +2056,22 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
2054 slot++; 2056 slot++;
2055 slot %= DWC3_TRB_NUM; 2057 slot %= DWC3_TRB_NUM;
2056 trb = &dep->trb_pool[slot]; 2058 trb = &dep->trb_pool[slot];
2059 count += trb->size & DWC3_TRB_SIZE_MASK;
2057 2060
2058 ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, 2061 ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
2059 event, status); 2062 event, status, chain);
2060 if (ret) 2063 if (ret)
2061 break; 2064 break;
2062 } while (++i < req->request.num_mapped_sgs); 2065 } while (++i < req->request.num_mapped_sgs);
2063 2066
2067 /*
2068 * We assume here we will always receive the entire data block
2069 * which we should receive. Meaning, if we program RX to
2070 * receive 4K but we receive only 2K, we assume that's all we
2071 * should receive and we simply bounce the request back to the
2072 * gadget driver for further processing.
2073 */
2074 req->request.actual += req->request.length - count;
2064 dwc3_gadget_giveback(dep, req, status); 2075 dwc3_gadget_giveback(dep, req, status);
2065 2076
2066 if (ret) 2077 if (ret)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index eb648485a58c..5ebe6af7976e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1913,6 +1913,8 @@ unknown:
1913 break; 1913 break;
1914 1914
1915 case USB_RECIP_ENDPOINT: 1915 case USB_RECIP_ENDPOINT:
1916 if (!cdev->config)
1917 break;
1916 endp = ((w_index & 0x80) >> 3) | (w_index & 0x0f); 1918 endp = ((w_index & 0x80) >> 3) | (w_index & 0x0f);
1917 list_for_each_entry(f, &cdev->config->functions, list) { 1919 list_for_each_entry(f, &cdev->config->functions, list) {
1918 if (test_bit(endp, f->endpoints)) 1920 if (test_bit(endp, f->endpoints))
@@ -2124,14 +2126,14 @@ int composite_os_desc_req_prepare(struct usb_composite_dev *cdev,
2124 2126
2125 cdev->os_desc_req = usb_ep_alloc_request(ep0, GFP_KERNEL); 2127 cdev->os_desc_req = usb_ep_alloc_request(ep0, GFP_KERNEL);
2126 if (!cdev->os_desc_req) { 2128 if (!cdev->os_desc_req) {
2127 ret = PTR_ERR(cdev->os_desc_req); 2129 ret = -ENOMEM;
2128 goto end; 2130 goto end;
2129 } 2131 }
2130 2132
2131 /* OS feature descriptor length <= 4kB */ 2133 /* OS feature descriptor length <= 4kB */
2132 cdev->os_desc_req->buf = kmalloc(4096, GFP_KERNEL); 2134 cdev->os_desc_req->buf = kmalloc(4096, GFP_KERNEL);
2133 if (!cdev->os_desc_req->buf) { 2135 if (!cdev->os_desc_req->buf) {
2134 ret = PTR_ERR(cdev->os_desc_req->buf); 2136 ret = -ENOMEM;
2135 kfree(cdev->os_desc_req); 2137 kfree(cdev->os_desc_req);
2136 goto end; 2138 goto end;
2137 } 2139 }
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 70cf3477f951..f9237fe2be05 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1490,7 +1490,9 @@ void unregister_gadget_item(struct config_item *item)
1490{ 1490{
1491 struct gadget_info *gi = to_gadget_info(item); 1491 struct gadget_info *gi = to_gadget_info(item);
1492 1492
1493 mutex_lock(&gi->lock);
1493 unregister_gadget(gi); 1494 unregister_gadget(gi);
1495 mutex_unlock(&gi->lock);
1494} 1496}
1495EXPORT_SYMBOL_GPL(unregister_gadget_item); 1497EXPORT_SYMBOL_GPL(unregister_gadget_item);
1496 1498
diff --git a/drivers/usb/gadget/function/rndis.c b/drivers/usb/gadget/function/rndis.c
index 943c21aafd3b..ab6ac1b74ac0 100644
--- a/drivers/usb/gadget/function/rndis.c
+++ b/drivers/usb/gadget/function/rndis.c
@@ -680,6 +680,12 @@ static int rndis_reset_response(struct rndis_params *params,
680{ 680{
681 rndis_reset_cmplt_type *resp; 681 rndis_reset_cmplt_type *resp;
682 rndis_resp_t *r; 682 rndis_resp_t *r;
683 u8 *xbuf;
684 u32 length;
685
686 /* drain the response queue */
687 while ((xbuf = rndis_get_next_response(params, &length)))
688 rndis_free_response(params, xbuf);
683 689
684 r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type)); 690 r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type));
685 if (!r) 691 if (!r)
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index a3f7e7c55ebb..5f562c1ec795 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -556,7 +556,8 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
556 /* Multi frame CDC protocols may store the frame for 556 /* Multi frame CDC protocols may store the frame for
557 * later which is not a dropped frame. 557 * later which is not a dropped frame.
558 */ 558 */
559 if (dev->port_usb->supports_multi_frame) 559 if (dev->port_usb &&
560 dev->port_usb->supports_multi_frame)
560 goto multiframe; 561 goto multiframe;
561 goto drop; 562 goto drop;
562 } 563 }
diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
index 66753ba7a42e..31125a4a2658 100644
--- a/drivers/usb/gadget/function/uvc_configfs.c
+++ b/drivers/usb/gadget/function/uvc_configfs.c
@@ -2023,7 +2023,7 @@ static int uvcg_streaming_class_allow_link(struct config_item *src,
2023 if (!data) { 2023 if (!data) {
2024 kfree(*class_array); 2024 kfree(*class_array);
2025 *class_array = NULL; 2025 *class_array = NULL;
2026 ret = PTR_ERR(data); 2026 ret = -ENOMEM;
2027 goto unlock; 2027 goto unlock;
2028 } 2028 }
2029 cl_arr = *class_array; 2029 cl_arr = *class_array;
diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index aa3707bdebb4..16104b5ebdcb 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -542,7 +542,7 @@ static ssize_t ep_aio(struct kiocb *iocb,
542 */ 542 */
543 spin_lock_irq(&epdata->dev->lock); 543 spin_lock_irq(&epdata->dev->lock);
544 value = -ENODEV; 544 value = -ENODEV;
545 if (unlikely(epdata->ep)) 545 if (unlikely(epdata->ep == NULL))
546 goto fail; 546 goto fail;
547 547
548 req = usb_ep_alloc_request(epdata->ep, GFP_ATOMIC); 548 req = usb_ep_alloc_request(epdata->ep, GFP_ATOMIC);
@@ -606,7 +606,7 @@ ep_read_iter(struct kiocb *iocb, struct iov_iter *to)
606 } 606 }
607 if (is_sync_kiocb(iocb)) { 607 if (is_sync_kiocb(iocb)) {
608 value = ep_io(epdata, buf, len); 608 value = ep_io(epdata, buf, len);
609 if (value >= 0 && copy_to_iter(buf, value, to)) 609 if (value >= 0 && (copy_to_iter(buf, value, to) != value))
610 value = -EFAULT; 610 value = -EFAULT;
611 } else { 611 } else {
612 struct kiocb_priv *priv = kzalloc(sizeof *priv, GFP_KERNEL); 612 struct kiocb_priv *priv = kzalloc(sizeof *priv, GFP_KERNEL);
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index ff8685ea7219..934f83881c30 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1145,7 +1145,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1145 if (ret != -EPROBE_DEFER) 1145 if (ret != -EPROBE_DEFER)
1146 list_del(&driver->pending); 1146 list_del(&driver->pending);
1147 if (ret) 1147 if (ret)
1148 goto err4; 1148 goto err5;
1149 break; 1149 break;
1150 } 1150 }
1151 } 1151 }
@@ -1154,6 +1154,9 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1154 1154
1155 return 0; 1155 return 0;
1156 1156
1157err5:
1158 device_del(&udc->dev);
1159
1157err4: 1160err4:
1158 list_del(&udc->list); 1161 list_del(&udc->list);
1159 mutex_unlock(&udc_lock); 1162 mutex_unlock(&udc_lock);
diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c b/drivers/usb/gadget/udc/fsl_qe_udc.c
index 93d28cb00b76..cf8819a5c5b2 100644
--- a/drivers/usb/gadget/udc/fsl_qe_udc.c
+++ b/drivers/usb/gadget/udc/fsl_qe_udc.c
@@ -2053,7 +2053,7 @@ static void setup_received_handle(struct qe_udc *udc,
2053 struct qe_ep *ep; 2053 struct qe_ep *ep;
2054 2054
2055 if (wValue != 0 || wLength != 0 2055 if (wValue != 0 || wLength != 0
2056 || pipe > USB_MAX_ENDPOINTS) 2056 || pipe >= USB_MAX_ENDPOINTS)
2057 break; 2057 break;
2058 ep = &udc->eps[pipe]; 2058 ep = &udc->eps[pipe];
2059 2059
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index a962b89b65a6..1e5f529d51a2 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -332,11 +332,11 @@ static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
332 int port = HCS_N_PORTS(ehci->hcs_params); 332 int port = HCS_N_PORTS(ehci->hcs_params);
333 333
334 while (port--) { 334 while (port--) {
335 ehci_writel(ehci, PORT_RWC_BITS,
336 &ehci->regs->port_status[port]);
337 spin_unlock_irq(&ehci->lock); 335 spin_unlock_irq(&ehci->lock);
338 ehci_port_power(ehci, port, false); 336 ehci_port_power(ehci, port, false);
339 spin_lock_irq(&ehci->lock); 337 spin_lock_irq(&ehci->lock);
338 ehci_writel(ehci, PORT_RWC_BITS,
339 &ehci->regs->port_status[port]);
340 } 340 }
341} 341}
342 342
diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
index c369c29e496d..2f7690092a7f 100644
--- a/drivers/usb/host/max3421-hcd.c
+++ b/drivers/usb/host/max3421-hcd.c
@@ -1675,7 +1675,7 @@ max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value)
1675 if (pin_number > 7) 1675 if (pin_number > 7)
1676 return; 1676 return;
1677 1677
1678 mask = 1u << pin_number; 1678 mask = 1u << (pin_number % 4);
1679 idx = pin_number / 4; 1679 idx = pin_number / 4;
1680 1680
1681 if (value) 1681 if (value)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index d61fcc48099e..730b9fd26685 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -386,6 +386,9 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
386 386
387 ret = 0; 387 ret = 0;
388 virt_dev = xhci->devs[slot_id]; 388 virt_dev = xhci->devs[slot_id];
389 if (!virt_dev)
390 return -ENODEV;
391
389 cmd = xhci_alloc_command(xhci, false, true, GFP_NOIO); 392 cmd = xhci_alloc_command(xhci, false, true, GFP_NOIO);
390 if (!cmd) { 393 if (!cmd) {
391 xhci_dbg(xhci, "Couldn't allocate command structure.\n"); 394 xhci_dbg(xhci, "Couldn't allocate command structure.\n");
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 4fd041bec332..d7b0f97abbad 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -314,11 +314,12 @@ static void xhci_pci_remove(struct pci_dev *dev)
314 usb_remove_hcd(xhci->shared_hcd); 314 usb_remove_hcd(xhci->shared_hcd);
315 usb_put_hcd(xhci->shared_hcd); 315 usb_put_hcd(xhci->shared_hcd);
316 } 316 }
317 usb_hcd_pci_remove(dev);
318 317
319 /* Workaround for spurious wakeups at shutdown with HSW */ 318 /* Workaround for spurious wakeups at shutdown with HSW */
320 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) 319 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
321 pci_set_power_state(dev, PCI_D3hot); 320 pci_set_power_state(dev, PCI_D3hot);
321
322 usb_hcd_pci_remove(dev);
322} 323}
323 324
324#ifdef CONFIG_PM 325#ifdef CONFIG_PM
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 918e0c739b79..fd9fd12e4861 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1334,12 +1334,6 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1334 1334
1335 cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list); 1335 cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list);
1336 1336
1337 if (cmd->command_trb != xhci->cmd_ring->dequeue) {
1338 xhci_err(xhci,
1339 "Command completion event does not match command\n");
1340 return;
1341 }
1342
1343 del_timer(&xhci->cmd_timer); 1337 del_timer(&xhci->cmd_timer);
1344 1338
1345 trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event); 1339 trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event);
@@ -1351,6 +1345,13 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1351 xhci_handle_stopped_cmd_ring(xhci, cmd); 1345 xhci_handle_stopped_cmd_ring(xhci, cmd);
1352 return; 1346 return;
1353 } 1347 }
1348
1349 if (cmd->command_trb != xhci->cmd_ring->dequeue) {
1350 xhci_err(xhci,
1351 "Command completion event does not match command\n");
1352 return;
1353 }
1354
1354 /* 1355 /*
1355 * Host aborted the command ring, check if the current command was 1356 * Host aborted the command ring, check if the current command was
1356 * supposed to be aborted, otherwise continue normally. 1357 * supposed to be aborted, otherwise continue normally.
@@ -3243,7 +3244,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
3243 send_addr = addr; 3244 send_addr = addr;
3244 3245
3245 /* Queue the TRBs, even if they are zero-length */ 3246 /* Queue the TRBs, even if they are zero-length */
3246 for (enqd_len = 0; enqd_len < full_len; enqd_len += trb_buff_len) { 3247 for (enqd_len = 0; first_trb || enqd_len < full_len;
3248 enqd_len += trb_buff_len) {
3247 field = TRB_TYPE(TRB_NORMAL); 3249 field = TRB_TYPE(TRB_NORMAL);
3248 3250
3249 /* TRB buffer should not cross 64KB boundaries */ 3251 /* TRB buffer should not cross 64KB boundaries */
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 52c27cab78c3..9b5b3b2281ca 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -665,7 +665,7 @@ static ssize_t ftdi_elan_read(struct file *file, char __user *buffer,
665{ 665{
666 char data[30 *3 + 4]; 666 char data[30 *3 + 4];
667 char *d = data; 667 char *d = data;
668 int m = (sizeof(data) - 1) / 3; 668 int m = (sizeof(data) - 1) / 3 - 1;
669 int bytes_read = 0; 669 int bytes_read = 0;
670 int retry_on_empty = 10; 670 int retry_on_empty = 10;
671 int retry_on_timeout = 5; 671 int retry_on_timeout = 5;
@@ -1684,7 +1684,7 @@ wait:if (ftdi->disconnected > 0) {
1684 int i = 0; 1684 int i = 0;
1685 char data[30 *3 + 4]; 1685 char data[30 *3 + 4];
1686 char *d = data; 1686 char *d = data;
1687 int m = (sizeof(data) - 1) / 3; 1687 int m = (sizeof(data) - 1) / 3 - 1;
1688 int l = 0; 1688 int l = 0;
1689 struct u132_target *target = &ftdi->target[ed]; 1689 struct u132_target *target = &ftdi->target[ed];
1690 struct u132_command *command = &ftdi->command[ 1690 struct u132_command *command = &ftdi->command[
@@ -1876,7 +1876,7 @@ more:{
1876 if (packet_bytes > 2) { 1876 if (packet_bytes > 2) {
1877 char diag[30 *3 + 4]; 1877 char diag[30 *3 + 4];
1878 char *d = diag; 1878 char *d = diag;
1879 int m = (sizeof(diag) - 1) / 3; 1879 int m = (sizeof(diag) - 1) / 3 - 1;
1880 char *b = ftdi->bulk_in_buffer; 1880 char *b = ftdi->bulk_in_buffer;
1881 int bytes_read = 0; 1881 int bytes_read = 0;
1882 diag[0] = 0; 1882 diag[0] = 0;
@@ -2053,7 +2053,7 @@ static int ftdi_elan_synchronize(struct usb_ftdi *ftdi)
2053 if (packet_bytes > 2) { 2053 if (packet_bytes > 2) {
2054 char diag[30 *3 + 4]; 2054 char diag[30 *3 + 4];
2055 char *d = diag; 2055 char *d = diag;
2056 int m = (sizeof(diag) - 1) / 3; 2056 int m = (sizeof(diag) - 1) / 3 - 1;
2057 char *b = ftdi->bulk_in_buffer; 2057 char *b = ftdi->bulk_in_buffer;
2058 int bytes_read = 0; 2058 int bytes_read = 0;
2059 unsigned char c = 0; 2059 unsigned char c = 0;
@@ -2155,7 +2155,7 @@ more:{
2155 if (packet_bytes > 2) { 2155 if (packet_bytes > 2) {
2156 char diag[30 *3 + 4]; 2156 char diag[30 *3 + 4];
2157 char *d = diag; 2157 char *d = diag;
2158 int m = (sizeof(diag) - 1) / 3; 2158 int m = (sizeof(diag) - 1) / 3 - 1;
2159 char *b = ftdi->bulk_in_buffer; 2159 char *b = ftdi->bulk_in_buffer;
2160 int bytes_read = 0; 2160 int bytes_read = 0;
2161 diag[0] = 0; 2161 diag[0] = 0;
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 6b978f04b8d7..5c8210dc6fd9 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -585,7 +585,6 @@ static void sg_timeout(unsigned long _req)
585{ 585{
586 struct usb_sg_request *req = (struct usb_sg_request *) _req; 586 struct usb_sg_request *req = (struct usb_sg_request *) _req;
587 587
588 req->status = -ETIMEDOUT;
589 usb_sg_cancel(req); 588 usb_sg_cancel(req);
590} 589}
591 590
@@ -616,8 +615,10 @@ static int perform_sglist(
616 mod_timer(&sg_timer, jiffies + 615 mod_timer(&sg_timer, jiffies +
617 msecs_to_jiffies(SIMPLE_IO_TIMEOUT)); 616 msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
618 usb_sg_wait(req); 617 usb_sg_wait(req);
619 del_timer_sync(&sg_timer); 618 if (!del_timer_sync(&sg_timer))
620 retval = req->status; 619 retval = -ETIMEDOUT;
620 else
621 retval = req->status;
621 622
622 /* FIXME check resulting data pattern */ 623 /* FIXME check resulting data pattern */
623 624
@@ -2602,7 +2603,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
2602 ktime_get_ts64(&start); 2603 ktime_get_ts64(&start);
2603 2604
2604 retval = usbtest_do_ioctl(intf, param_32); 2605 retval = usbtest_do_ioctl(intf, param_32);
2605 if (retval) 2606 if (retval < 0)
2606 goto free_mutex; 2607 goto free_mutex;
2607 2608
2608 ktime_get_ts64(&end); 2609 ktime_get_ts64(&end);
diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c
index 6f6d2a7fd5a0..6523af4f8f93 100644
--- a/drivers/usb/phy/phy-omap-otg.c
+++ b/drivers/usb/phy/phy-omap-otg.c
@@ -140,6 +140,8 @@ static int omap_otg_probe(struct platform_device *pdev)
140 (rev >> 4) & 0xf, rev & 0xf, config->extcon, otg_dev->id, 140 (rev >> 4) & 0xf, rev & 0xf, config->extcon, otg_dev->id,
141 otg_dev->vbus); 141 otg_dev->vbus);
142 142
143 platform_set_drvdata(pdev, otg_dev);
144
143 return 0; 145 return 0;
144} 146}
145 147
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
index 8fbbc2d32371..ac67bab9124c 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -514,7 +514,8 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev)
514 if (gpio > 0) 514 if (gpio > 0)
515 dparam->enable_gpio = gpio; 515 dparam->enable_gpio = gpio;
516 516
517 if (dparam->type == USBHS_TYPE_RCAR_GEN2) 517 if (dparam->type == USBHS_TYPE_RCAR_GEN2 ||
518 dparam->type == USBHS_TYPE_RCAR_GEN3)
518 dparam->has_usb_dmac = 1; 519 dparam->has_usb_dmac = 1;
519 520
520 return info; 521 return info;
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 280ed5ff021b..857e78337324 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -871,7 +871,7 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
871 871
872 /* use PIO if packet is less than pio_dma_border or pipe is DCP */ 872 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
873 if ((len < usbhs_get_dparam(priv, pio_dma_border)) || 873 if ((len < usbhs_get_dparam(priv, pio_dma_border)) ||
874 usbhs_pipe_is_dcp(pipe)) 874 usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC))
875 goto usbhsf_pio_prepare_push; 875 goto usbhsf_pio_prepare_push;
876 876
877 /* check data length if this driver don't use USB-DMAC */ 877 /* check data length if this driver don't use USB-DMAC */
@@ -976,7 +976,7 @@ static int usbhsf_dma_prepare_pop_with_usb_dmac(struct usbhs_pkt *pkt,
976 976
977 /* use PIO if packet is less than pio_dma_border or pipe is DCP */ 977 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
978 if ((pkt->length < usbhs_get_dparam(priv, pio_dma_border)) || 978 if ((pkt->length < usbhs_get_dparam(priv, pio_dma_border)) ||
979 usbhs_pipe_is_dcp(pipe)) 979 usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC))
980 goto usbhsf_pio_prepare_pop; 980 goto usbhsf_pio_prepare_pop;
981 981
982 fifo = usbhsf_get_dma_fifo(priv, pkt); 982 fifo = usbhsf_get_dma_fifo(priv, pkt);
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 50f3363cc382..92bc83b92d10 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -617,10 +617,13 @@ static int usbhsg_ep_enable(struct usb_ep *ep,
617 * use dmaengine if possible. 617 * use dmaengine if possible.
618 * It will use pio handler if impossible. 618 * It will use pio handler if impossible.
619 */ 619 */
620 if (usb_endpoint_dir_in(desc)) 620 if (usb_endpoint_dir_in(desc)) {
621 pipe->handler = &usbhs_fifo_dma_push_handler; 621 pipe->handler = &usbhs_fifo_dma_push_handler;
622 else 622 } else {
623 pipe->handler = &usbhs_fifo_dma_pop_handler; 623 pipe->handler = &usbhs_fifo_dma_pop_handler;
624 usbhs_xxxsts_clear(priv, BRDYSTS,
625 usbhs_pipe_number(pipe));
626 }
624 627
625 ret = 0; 628 ret = 0;
626 } 629 }
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 00820809139a..b2d767e743fc 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -648,6 +648,8 @@ static const struct usb_device_id id_table_combined[] = {
648 { USB_DEVICE(FTDI_VID, FTDI_ELV_TFD128_PID) }, 648 { USB_DEVICE(FTDI_VID, FTDI_ELV_TFD128_PID) },
649 { USB_DEVICE(FTDI_VID, FTDI_ELV_FM3RX_PID) }, 649 { USB_DEVICE(FTDI_VID, FTDI_ELV_FM3RX_PID) },
650 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS777_PID) }, 650 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS777_PID) },
651 { USB_DEVICE(FTDI_VID, FTDI_PALMSENS_PID) },
652 { USB_DEVICE(FTDI_VID, FTDI_IVIUM_XSTAT_PID) },
651 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) }, 653 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
652 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) }, 654 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
653 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) }, 655 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
@@ -1008,6 +1010,7 @@ static const struct usb_device_id id_table_combined[] = {
1008 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7560U_PID) }, 1010 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7560U_PID) },
1009 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7561U_PID) }, 1011 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7561U_PID) },
1010 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7563U_PID) }, 1012 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7563U_PID) },
1013 { USB_DEVICE(WICED_VID, WICED_USB20706V2_PID) },
1011 { } /* Terminating entry */ 1014 { } /* Terminating entry */
1012}; 1015};
1013 1016
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index c5d6c1e73e8e..f87a938cf005 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -406,6 +406,12 @@
406#define FTDI_4N_GALAXY_DE_3_PID 0xF3C2 406#define FTDI_4N_GALAXY_DE_3_PID 0xF3C2
407 407
408/* 408/*
409 * Ivium Technologies product IDs
410 */
411#define FTDI_PALMSENS_PID 0xf440
412#define FTDI_IVIUM_XSTAT_PID 0xf441
413
414/*
409 * Linx Technologies product ids 415 * Linx Technologies product ids
410 */ 416 */
411#define LINX_SDMUSBQSS_PID 0xF448 /* Linx SDM-USB-QS-S */ 417#define LINX_SDMUSBQSS_PID 0xF448 /* Linx SDM-USB-QS-S */
@@ -673,6 +679,12 @@
673#define INTREPID_NEOVI_PID 0x0701 679#define INTREPID_NEOVI_PID 0x0701
674 680
675/* 681/*
682 * WICED USB UART
683 */
684#define WICED_VID 0x0A5C
685#define WICED_USB20706V2_PID 0x6422
686
687/*
676 * Definitions for ID TECH (www.idt-net.com) devices 688 * Definitions for ID TECH (www.idt-net.com) devices
677 */ 689 */
678#define IDTECH_VID 0x0ACD /* ID TECH Vendor ID */ 690#define IDTECH_VID 0x0ACD /* ID TECH Vendor ID */
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 8e07536c233a..bc472584a229 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -274,6 +274,12 @@ static void option_instat_callback(struct urb *urb);
274#define TELIT_PRODUCT_LE920 0x1200 274#define TELIT_PRODUCT_LE920 0x1200
275#define TELIT_PRODUCT_LE910 0x1201 275#define TELIT_PRODUCT_LE910 0x1201
276#define TELIT_PRODUCT_LE910_USBCFG4 0x1206 276#define TELIT_PRODUCT_LE910_USBCFG4 0x1206
277#define TELIT_PRODUCT_LE920A4_1207 0x1207
278#define TELIT_PRODUCT_LE920A4_1208 0x1208
279#define TELIT_PRODUCT_LE920A4_1211 0x1211
280#define TELIT_PRODUCT_LE920A4_1212 0x1212
281#define TELIT_PRODUCT_LE920A4_1213 0x1213
282#define TELIT_PRODUCT_LE920A4_1214 0x1214
277 283
278/* ZTE PRODUCTS */ 284/* ZTE PRODUCTS */
279#define ZTE_VENDOR_ID 0x19d2 285#define ZTE_VENDOR_ID 0x19d2
@@ -628,6 +634,11 @@ static const struct option_blacklist_info telit_le920_blacklist = {
628 .reserved = BIT(1) | BIT(5), 634 .reserved = BIT(1) | BIT(5),
629}; 635};
630 636
637static const struct option_blacklist_info telit_le920a4_blacklist_1 = {
638 .sendsetup = BIT(0),
639 .reserved = BIT(1),
640};
641
631static const struct option_blacklist_info telit_le922_blacklist_usbcfg0 = { 642static const struct option_blacklist_info telit_le922_blacklist_usbcfg0 = {
632 .sendsetup = BIT(2), 643 .sendsetup = BIT(2),
633 .reserved = BIT(0) | BIT(1) | BIT(3), 644 .reserved = BIT(0) | BIT(1) | BIT(3),
@@ -1203,6 +1214,16 @@ static const struct usb_device_id option_ids[] = {
1203 .driver_info = (kernel_ulong_t)&telit_le922_blacklist_usbcfg3 }, 1214 .driver_info = (kernel_ulong_t)&telit_le922_blacklist_usbcfg3 },
1204 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920), 1215 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920),
1205 .driver_info = (kernel_ulong_t)&telit_le920_blacklist }, 1216 .driver_info = (kernel_ulong_t)&telit_le920_blacklist },
1217 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1207) },
1218 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1208),
1219 .driver_info = (kernel_ulong_t)&telit_le920a4_blacklist_1 },
1220 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1211),
1221 .driver_info = (kernel_ulong_t)&telit_le922_blacklist_usbcfg3 },
1222 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1212),
1223 .driver_info = (kernel_ulong_t)&telit_le920a4_blacklist_1 },
1224 { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1213, 0xff) },
1225 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1214),
1226 .driver_info = (kernel_ulong_t)&telit_le922_blacklist_usbcfg3 },
1206 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */ 1227 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */
1207 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff), 1228 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff),
1208 .driver_info = (kernel_ulong_t)&net_intf1_blacklist }, 1229 .driver_info = (kernel_ulong_t)&net_intf1_blacklist },
@@ -1966,6 +1987,7 @@ static const struct usb_device_id option_ids[] = {
1966 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 1987 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1967 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */ 1988 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */
1968 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */ 1989 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */
1990 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x7e11, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/A3 */
1969 { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x4000, 0xff) }, /* OLICARD300 - MT6225 */ 1991 { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x4000, 0xff) }, /* OLICARD300 - MT6225 */
1970 { USB_DEVICE(INOVIA_VENDOR_ID, INOVIA_SEW858) }, 1992 { USB_DEVICE(INOVIA_VENDOR_ID, INOVIA_SEW858) },
1971 { USB_DEVICE(VIATELECOM_VENDOR_ID, VIATELECOM_PRODUCT_CDS7) }, 1993 { USB_DEVICE(VIATELECOM_VENDOR_ID, VIATELECOM_PRODUCT_CDS7) },
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index b1b9bac44016..d213cf44a7e4 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1433,7 +1433,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
1433 1433
1434 rc = usb_register(udriver); 1434 rc = usb_register(udriver);
1435 if (rc) 1435 if (rc)
1436 return rc; 1436 goto failed_usb_register;
1437 1437
1438 for (sd = serial_drivers; *sd; ++sd) { 1438 for (sd = serial_drivers; *sd; ++sd) {
1439 (*sd)->usb_driver = udriver; 1439 (*sd)->usb_driver = udriver;
@@ -1451,6 +1451,8 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
1451 while (sd-- > serial_drivers) 1451 while (sd-- > serial_drivers)
1452 usb_serial_deregister(*sd); 1452 usb_serial_deregister(*sd);
1453 usb_deregister(udriver); 1453 usb_deregister(udriver);
1454failed_usb_register:
1455 kfree(udriver);
1454 return rc; 1456 return rc;
1455} 1457}
1456EXPORT_SYMBOL_GPL(usb_serial_register_drivers); 1458EXPORT_SYMBOL_GPL(usb_serial_register_drivers);
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index 15ecfc9c5f6c..152b43822ef1 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -564,67 +564,80 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_device *vdev,
564} 564}
565 565
566static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, 566static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx,
567 uint32_t flags, void *data) 567 unsigned int count, uint32_t flags,
568 void *data)
568{ 569{
569 int32_t fd = *(int32_t *)data;
570
571 if (!(flags & VFIO_IRQ_SET_DATA_TYPE_MASK))
572 return -EINVAL;
573
574 /* DATA_NONE/DATA_BOOL enables loopback testing */ 570 /* DATA_NONE/DATA_BOOL enables loopback testing */
575 if (flags & VFIO_IRQ_SET_DATA_NONE) { 571 if (flags & VFIO_IRQ_SET_DATA_NONE) {
576 if (*ctx) 572 if (*ctx) {
577 eventfd_signal(*ctx, 1); 573 if (count) {
578 return 0; 574 eventfd_signal(*ctx, 1);
575 } else {
576 eventfd_ctx_put(*ctx);
577 *ctx = NULL;
578 }
579 return 0;
580 }
579 } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { 581 } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
580 uint8_t trigger = *(uint8_t *)data; 582 uint8_t trigger;
583
584 if (!count)
585 return -EINVAL;
586
587 trigger = *(uint8_t *)data;
581 if (trigger && *ctx) 588 if (trigger && *ctx)
582 eventfd_signal(*ctx, 1); 589 eventfd_signal(*ctx, 1);
583 return 0;
584 }
585 590
586 /* Handle SET_DATA_EVENTFD */
587 if (fd == -1) {
588 if (*ctx)
589 eventfd_ctx_put(*ctx);
590 *ctx = NULL;
591 return 0; 591 return 0;
592 } else if (fd >= 0) { 592 } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
593 struct eventfd_ctx *efdctx; 593 int32_t fd;
594 efdctx = eventfd_ctx_fdget(fd); 594
595 if (IS_ERR(efdctx)) 595 if (!count)
596 return PTR_ERR(efdctx); 596 return -EINVAL;
597 if (*ctx) 597
598 eventfd_ctx_put(*ctx); 598 fd = *(int32_t *)data;
599 *ctx = efdctx; 599 if (fd == -1) {
600 if (*ctx)
601 eventfd_ctx_put(*ctx);
602 *ctx = NULL;
603 } else if (fd >= 0) {
604 struct eventfd_ctx *efdctx;
605
606 efdctx = eventfd_ctx_fdget(fd);
607 if (IS_ERR(efdctx))
608 return PTR_ERR(efdctx);
609
610 if (*ctx)
611 eventfd_ctx_put(*ctx);
612
613 *ctx = efdctx;
614 }
600 return 0; 615 return 0;
601 } else 616 }
602 return -EINVAL; 617
618 return -EINVAL;
603} 619}
604 620
605static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev, 621static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev,
606 unsigned index, unsigned start, 622 unsigned index, unsigned start,
607 unsigned count, uint32_t flags, void *data) 623 unsigned count, uint32_t flags, void *data)
608{ 624{
609 if (index != VFIO_PCI_ERR_IRQ_INDEX) 625 if (index != VFIO_PCI_ERR_IRQ_INDEX || start != 0 || count > 1)
610 return -EINVAL; 626 return -EINVAL;
611 627
612 /* 628 return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger,
613 * We should sanitize start & count, but that wasn't caught 629 count, flags, data);
614 * originally, so this IRQ index must forever ignore them :-(
615 */
616
617 return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger, flags, data);
618} 630}
619 631
620static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev, 632static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev,
621 unsigned index, unsigned start, 633 unsigned index, unsigned start,
622 unsigned count, uint32_t flags, void *data) 634 unsigned count, uint32_t flags, void *data)
623{ 635{
624 if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count != 1) 636 if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count > 1)
625 return -EINVAL; 637 return -EINVAL;
626 638
627 return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger, flags, data); 639 return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger,
640 count, flags, data);
628} 641}
629 642
630int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags, 643int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags,
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 9d6320e8ff3e..6e29d053843d 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -88,7 +88,7 @@ struct vhost_scsi_cmd {
88 struct scatterlist *tvc_prot_sgl; 88 struct scatterlist *tvc_prot_sgl;
89 struct page **tvc_upages; 89 struct page **tvc_upages;
90 /* Pointer to response header iovec */ 90 /* Pointer to response header iovec */
91 struct iovec *tvc_resp_iov; 91 struct iovec tvc_resp_iov;
92 /* Pointer to vhost_scsi for our device */ 92 /* Pointer to vhost_scsi for our device */
93 struct vhost_scsi *tvc_vhost; 93 struct vhost_scsi *tvc_vhost;
94 /* Pointer to vhost_virtqueue for the cmd */ 94 /* Pointer to vhost_virtqueue for the cmd */
@@ -547,7 +547,7 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
547 memcpy(v_rsp.sense, cmd->tvc_sense_buf, 547 memcpy(v_rsp.sense, cmd->tvc_sense_buf,
548 se_cmd->scsi_sense_length); 548 se_cmd->scsi_sense_length);
549 549
550 iov_iter_init(&iov_iter, READ, cmd->tvc_resp_iov, 550 iov_iter_init(&iov_iter, READ, &cmd->tvc_resp_iov,
551 cmd->tvc_in_iovs, sizeof(v_rsp)); 551 cmd->tvc_in_iovs, sizeof(v_rsp));
552 ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter); 552 ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter);
553 if (likely(ret == sizeof(v_rsp))) { 553 if (likely(ret == sizeof(v_rsp))) {
@@ -1044,7 +1044,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1044 } 1044 }
1045 cmd->tvc_vhost = vs; 1045 cmd->tvc_vhost = vs;
1046 cmd->tvc_vq = vq; 1046 cmd->tvc_vq = vq;
1047 cmd->tvc_resp_iov = &vq->iov[out]; 1047 cmd->tvc_resp_iov = vq->iov[out];
1048 cmd->tvc_in_iovs = in; 1048 cmd->tvc_in_iovs = in;
1049 1049
1050 pr_debug("vhost_scsi got command opcode: %#02x, lun: %d\n", 1050 pr_debug("vhost_scsi got command opcode: %#02x, lun: %d\n",
diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index 388eec4e1a90..97fb2f8fa930 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -220,20 +220,20 @@ static long vhost_test_reset_owner(struct vhost_test *n)
220{ 220{
221 void *priv = NULL; 221 void *priv = NULL;
222 long err; 222 long err;
223 struct vhost_memory *memory; 223 struct vhost_umem *umem;
224 224
225 mutex_lock(&n->dev.mutex); 225 mutex_lock(&n->dev.mutex);
226 err = vhost_dev_check_owner(&n->dev); 226 err = vhost_dev_check_owner(&n->dev);
227 if (err) 227 if (err)
228 goto done; 228 goto done;
229 memory = vhost_dev_reset_owner_prepare(); 229 umem = vhost_dev_reset_owner_prepare();
230 if (!memory) { 230 if (!umem) {
231 err = -ENOMEM; 231 err = -ENOMEM;
232 goto done; 232 goto done;
233 } 233 }
234 vhost_test_stop(n, &priv); 234 vhost_test_stop(n, &priv);
235 vhost_test_flush(n); 235 vhost_test_flush(n);
236 vhost_dev_reset_owner(&n->dev, memory); 236 vhost_dev_reset_owner(&n->dev, umem);
237done: 237done:
238 mutex_unlock(&n->dev.mutex); 238 mutex_unlock(&n->dev.mutex);
239 return err; 239 return err;
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 0ddf3a2dbfc4..e3b30ea9ece5 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -307,6 +307,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
307 307
308 vhost_disable_notify(&vsock->dev, vq); 308 vhost_disable_notify(&vsock->dev, vq);
309 for (;;) { 309 for (;;) {
310 u32 len;
311
310 if (!vhost_vsock_more_replies(vsock)) { 312 if (!vhost_vsock_more_replies(vsock)) {
311 /* Stop tx until the device processes already 313 /* Stop tx until the device processes already
312 * pending replies. Leave tx virtqueue 314 * pending replies. Leave tx virtqueue
@@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
334 continue; 336 continue;
335 } 337 }
336 338
339 len = pkt->len;
340
337 /* Only accept correctly addressed packets */ 341 /* Only accept correctly addressed packets */
338 if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid) 342 if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
339 virtio_transport_recv_pkt(pkt); 343 virtio_transport_recv_pkt(pkt);
340 else 344 else
341 virtio_transport_free_pkt(pkt); 345 virtio_transport_free_pkt(pkt);
342 346
343 vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len); 347 vhost_add_used(vq, head, sizeof(pkt->hdr) + len);
344 added = true; 348 added = true;
345 } 349 }
346 350
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 114a0c88afb8..e383ecdaca59 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -327,6 +327,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
327 * host should service the ring ASAP. */ 327 * host should service the ring ASAP. */
328 if (out_sgs) 328 if (out_sgs)
329 vq->notify(&vq->vq); 329 vq->notify(&vq->vq);
330 if (indirect)
331 kfree(desc);
330 END_USE(vq); 332 END_USE(vq);
331 return -ENOSPC; 333 return -ENOSPC;
332 } 334 }
@@ -426,6 +428,7 @@ unmap_release:
426 if (indirect) 428 if (indirect)
427 kfree(desc); 429 kfree(desc);
428 430
431 END_USE(vq);
429 return -EIO; 432 return -EIO;
430} 433}
431 434
diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
index 7487971f9f78..c1010f018bd8 100644
--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -316,7 +316,7 @@ static int xenbus_write_transaction(unsigned msg_type,
316 rc = -ENOMEM; 316 rc = -ENOMEM;
317 goto out; 317 goto out;
318 } 318 }
319 } else { 319 } else if (msg_type == XS_TRANSACTION_END) {
320 list_for_each_entry(trans, &u->transactions, list) 320 list_for_each_entry(trans, &u->transactions, list)
321 if (trans->handle.id == u->u.msg.tx_id) 321 if (trans->handle.id == u->u.msg.tx_id)
322 break; 322 break;
diff --git a/fs/afs/cmservice.c b/fs/afs/cmservice.c
index 4b0eff6da674..85737e96ab8b 100644
--- a/fs/afs/cmservice.c
+++ b/fs/afs/cmservice.c
@@ -189,11 +189,8 @@ static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
189 case 1: 189 case 1:
190 _debug("extract FID count"); 190 _debug("extract FID count");
191 ret = afs_extract_data(call, skb, last, &call->tmp, 4); 191 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
192 switch (ret) { 192 if (ret < 0)
193 case 0: break; 193 return ret;
194 case -EAGAIN: return 0;
195 default: return ret;
196 }
197 194
198 call->count = ntohl(call->tmp); 195 call->count = ntohl(call->tmp);
199 _debug("FID count: %u", call->count); 196 _debug("FID count: %u", call->count);
@@ -210,11 +207,8 @@ static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
210 _debug("extract FID array"); 207 _debug("extract FID array");
211 ret = afs_extract_data(call, skb, last, call->buffer, 208 ret = afs_extract_data(call, skb, last, call->buffer,
212 call->count * 3 * 4); 209 call->count * 3 * 4);
213 switch (ret) { 210 if (ret < 0)
214 case 0: break; 211 return ret;
215 case -EAGAIN: return 0;
216 default: return ret;
217 }
218 212
219 _debug("unmarshall FID array"); 213 _debug("unmarshall FID array");
220 call->request = kcalloc(call->count, 214 call->request = kcalloc(call->count,
@@ -239,11 +233,8 @@ static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
239 case 3: 233 case 3:
240 _debug("extract CB count"); 234 _debug("extract CB count");
241 ret = afs_extract_data(call, skb, last, &call->tmp, 4); 235 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
242 switch (ret) { 236 if (ret < 0)
243 case 0: break; 237 return ret;
244 case -EAGAIN: return 0;
245 default: return ret;
246 }
247 238
248 tmp = ntohl(call->tmp); 239 tmp = ntohl(call->tmp);
249 _debug("CB count: %u", tmp); 240 _debug("CB count: %u", tmp);
@@ -258,11 +249,8 @@ static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
258 _debug("extract CB array"); 249 _debug("extract CB array");
259 ret = afs_extract_data(call, skb, last, call->request, 250 ret = afs_extract_data(call, skb, last, call->request,
260 call->count * 3 * 4); 251 call->count * 3 * 4);
261 switch (ret) { 252 if (ret < 0)
262 case 0: break; 253 return ret;
263 case -EAGAIN: return 0;
264 default: return ret;
265 }
266 254
267 _debug("unmarshall CB array"); 255 _debug("unmarshall CB array");
268 cb = call->request; 256 cb = call->request;
@@ -278,9 +266,9 @@ static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
278 call->unmarshall++; 266 call->unmarshall++;
279 267
280 case 5: 268 case 5:
281 _debug("trailer"); 269 ret = afs_data_complete(call, skb, last);
282 if (skb->len != 0) 270 if (ret < 0)
283 return -EBADMSG; 271 return ret;
284 272
285 /* Record that the message was unmarshalled successfully so 273 /* Record that the message was unmarshalled successfully so
286 * that the call destructor can know do the callback breaking 274 * that the call destructor can know do the callback breaking
@@ -294,8 +282,6 @@ static int afs_deliver_cb_callback(struct afs_call *call, struct sk_buff *skb,
294 break; 282 break;
295 } 283 }
296 284
297 if (!last)
298 return 0;
299 285
300 call->state = AFS_CALL_REPLYING; 286 call->state = AFS_CALL_REPLYING;
301 287
@@ -335,13 +321,13 @@ static int afs_deliver_cb_init_call_back_state(struct afs_call *call,
335{ 321{
336 struct afs_server *server; 322 struct afs_server *server;
337 struct in_addr addr; 323 struct in_addr addr;
324 int ret;
338 325
339 _enter(",{%u},%d", skb->len, last); 326 _enter(",{%u},%d", skb->len, last);
340 327
341 if (skb->len > 0) 328 ret = afs_data_complete(call, skb, last);
342 return -EBADMSG; 329 if (ret < 0)
343 if (!last) 330 return ret;
344 return 0;
345 331
346 /* no unmarshalling required */ 332 /* no unmarshalling required */
347 call->state = AFS_CALL_REPLYING; 333 call->state = AFS_CALL_REPLYING;
@@ -371,8 +357,10 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call,
371 357
372 _enter(",{%u},%d", skb->len, last); 358 _enter(",{%u},%d", skb->len, last);
373 359
360 /* There are some arguments that we ignore */
361 afs_data_consumed(call, skb);
374 if (!last) 362 if (!last)
375 return 0; 363 return -EAGAIN;
376 364
377 /* no unmarshalling required */ 365 /* no unmarshalling required */
378 call->state = AFS_CALL_REPLYING; 366 call->state = AFS_CALL_REPLYING;
@@ -408,12 +396,13 @@ static void SRXAFSCB_Probe(struct work_struct *work)
408static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb, 396static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
409 bool last) 397 bool last)
410{ 398{
399 int ret;
400
411 _enter(",{%u},%d", skb->len, last); 401 _enter(",{%u},%d", skb->len, last);
412 402
413 if (skb->len > 0) 403 ret = afs_data_complete(call, skb, last);
414 return -EBADMSG; 404 if (ret < 0)
415 if (!last) 405 return ret;
416 return 0;
417 406
418 /* no unmarshalling required */ 407 /* no unmarshalling required */
419 call->state = AFS_CALL_REPLYING; 408 call->state = AFS_CALL_REPLYING;
@@ -460,10 +449,9 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call, struct sk_buff *skb,
460 449
461 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); 450 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
462 451
463 if (skb->len > 0) 452 ret = afs_data_complete(call, skb, last);
464 return -EBADMSG; 453 if (ret < 0)
465 if (!last) 454 return ret;
466 return 0;
467 455
468 switch (call->unmarshall) { 456 switch (call->unmarshall) {
469 case 0: 457 case 0:
@@ -509,8 +497,9 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call, struct sk_buff *skb,
509 break; 497 break;
510 } 498 }
511 499
512 if (!last) 500 ret = afs_data_complete(call, skb, last);
513 return 0; 501 if (ret < 0)
502 return ret;
514 503
515 call->state = AFS_CALL_REPLYING; 504 call->state = AFS_CALL_REPLYING;
516 505
@@ -588,12 +577,13 @@ static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
588static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call, 577static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call,
589 struct sk_buff *skb, bool last) 578 struct sk_buff *skb, bool last)
590{ 579{
580 int ret;
581
591 _enter(",{%u},%d", skb->len, last); 582 _enter(",{%u},%d", skb->len, last);
592 583
593 if (skb->len > 0) 584 ret = afs_data_complete(call, skb, last);
594 return -EBADMSG; 585 if (ret < 0)
595 if (!last) 586 return ret;
596 return 0;
597 587
598 /* no unmarshalling required */ 588 /* no unmarshalling required */
599 call->state = AFS_CALL_REPLYING; 589 call->state = AFS_CALL_REPLYING;
diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c
index c2e930ec2888..9312b92e54be 100644
--- a/fs/afs/fsclient.c
+++ b/fs/afs/fsclient.c
@@ -240,15 +240,13 @@ static int afs_deliver_fs_fetch_status(struct afs_call *call,
240{ 240{
241 struct afs_vnode *vnode = call->reply; 241 struct afs_vnode *vnode = call->reply;
242 const __be32 *bp; 242 const __be32 *bp;
243 int ret;
243 244
244 _enter(",,%u", last); 245 _enter(",,%u", last);
245 246
246 afs_transfer_reply(call, skb); 247 ret = afs_transfer_reply(call, skb, last);
247 if (!last) 248 if (ret < 0)
248 return 0; 249 return ret;
249
250 if (call->reply_size != call->reply_max)
251 return -EBADMSG;
252 250
253 /* unmarshall the reply once we've received all of it */ 251 /* unmarshall the reply once we've received all of it */
254 bp = call->buffer; 252 bp = call->buffer;
@@ -335,11 +333,8 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call,
335 case 1: 333 case 1:
336 _debug("extract data length (MSW)"); 334 _debug("extract data length (MSW)");
337 ret = afs_extract_data(call, skb, last, &call->tmp, 4); 335 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
338 switch (ret) { 336 if (ret < 0)
339 case 0: break; 337 return ret;
340 case -EAGAIN: return 0;
341 default: return ret;
342 }
343 338
344 call->count = ntohl(call->tmp); 339 call->count = ntohl(call->tmp);
345 _debug("DATA length MSW: %u", call->count); 340 _debug("DATA length MSW: %u", call->count);
@@ -353,11 +348,8 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call,
353 case 2: 348 case 2:
354 _debug("extract data length"); 349 _debug("extract data length");
355 ret = afs_extract_data(call, skb, last, &call->tmp, 4); 350 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
356 switch (ret) { 351 if (ret < 0)
357 case 0: break; 352 return ret;
358 case -EAGAIN: return 0;
359 default: return ret;
360 }
361 353
362 call->count = ntohl(call->tmp); 354 call->count = ntohl(call->tmp);
363 _debug("DATA length: %u", call->count); 355 _debug("DATA length: %u", call->count);
@@ -375,11 +367,8 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call,
375 ret = afs_extract_data(call, skb, last, buffer, 367 ret = afs_extract_data(call, skb, last, buffer,
376 call->count); 368 call->count);
377 kunmap_atomic(buffer); 369 kunmap_atomic(buffer);
378 switch (ret) { 370 if (ret < 0)
379 case 0: break; 371 return ret;
380 case -EAGAIN: return 0;
381 default: return ret;
382 }
383 } 372 }
384 373
385 call->offset = 0; 374 call->offset = 0;
@@ -389,11 +378,8 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call,
389 case 4: 378 case 4:
390 ret = afs_extract_data(call, skb, last, call->buffer, 379 ret = afs_extract_data(call, skb, last, call->buffer,
391 (21 + 3 + 6) * 4); 380 (21 + 3 + 6) * 4);
392 switch (ret) { 381 if (ret < 0)
393 case 0: break; 382 return ret;
394 case -EAGAIN: return 0;
395 default: return ret;
396 }
397 383
398 bp = call->buffer; 384 bp = call->buffer;
399 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL); 385 xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
@@ -405,15 +391,12 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call,
405 call->unmarshall++; 391 call->unmarshall++;
406 392
407 case 5: 393 case 5:
408 _debug("trailer"); 394 ret = afs_data_complete(call, skb, last);
409 if (skb->len != 0) 395 if (ret < 0)
410 return -EBADMSG; 396 return ret;
411 break; 397 break;
412 } 398 }
413 399
414 if (!last)
415 return 0;
416
417 if (call->count < PAGE_SIZE) { 400 if (call->count < PAGE_SIZE) {
418 _debug("clear"); 401 _debug("clear");
419 page = call->reply3; 402 page = call->reply3;
@@ -537,9 +520,8 @@ static int afs_deliver_fs_give_up_callbacks(struct afs_call *call,
537{ 520{
538 _enter(",{%u},%d", skb->len, last); 521 _enter(",{%u},%d", skb->len, last);
539 522
540 if (skb->len > 0) 523 /* shouldn't be any reply data */
541 return -EBADMSG; /* shouldn't be any reply data */ 524 return afs_data_complete(call, skb, last);
542 return 0;
543} 525}
544 526
545/* 527/*
@@ -622,15 +604,13 @@ static int afs_deliver_fs_create_vnode(struct afs_call *call,
622{ 604{
623 struct afs_vnode *vnode = call->reply; 605 struct afs_vnode *vnode = call->reply;
624 const __be32 *bp; 606 const __be32 *bp;
607 int ret;
625 608
626 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); 609 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
627 610
628 afs_transfer_reply(call, skb); 611 ret = afs_transfer_reply(call, skb, last);
629 if (!last) 612 if (ret < 0)
630 return 0; 613 return ret;
631
632 if (call->reply_size != call->reply_max)
633 return -EBADMSG;
634 614
635 /* unmarshall the reply once we've received all of it */ 615 /* unmarshall the reply once we've received all of it */
636 bp = call->buffer; 616 bp = call->buffer;
@@ -721,15 +701,13 @@ static int afs_deliver_fs_remove(struct afs_call *call,
721{ 701{
722 struct afs_vnode *vnode = call->reply; 702 struct afs_vnode *vnode = call->reply;
723 const __be32 *bp; 703 const __be32 *bp;
704 int ret;
724 705
725 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); 706 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
726 707
727 afs_transfer_reply(call, skb); 708 ret = afs_transfer_reply(call, skb, last);
728 if (!last) 709 if (ret < 0)
729 return 0; 710 return ret;
730
731 if (call->reply_size != call->reply_max)
732 return -EBADMSG;
733 711
734 /* unmarshall the reply once we've received all of it */ 712 /* unmarshall the reply once we've received all of it */
735 bp = call->buffer; 713 bp = call->buffer;
@@ -804,15 +782,13 @@ static int afs_deliver_fs_link(struct afs_call *call,
804{ 782{
805 struct afs_vnode *dvnode = call->reply, *vnode = call->reply2; 783 struct afs_vnode *dvnode = call->reply, *vnode = call->reply2;
806 const __be32 *bp; 784 const __be32 *bp;
785 int ret;
807 786
808 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); 787 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
809 788
810 afs_transfer_reply(call, skb); 789 ret = afs_transfer_reply(call, skb, last);
811 if (!last) 790 if (ret < 0)
812 return 0; 791 return ret;
813
814 if (call->reply_size != call->reply_max)
815 return -EBADMSG;
816 792
817 /* unmarshall the reply once we've received all of it */ 793 /* unmarshall the reply once we've received all of it */
818 bp = call->buffer; 794 bp = call->buffer;
@@ -892,15 +868,13 @@ static int afs_deliver_fs_symlink(struct afs_call *call,
892{ 868{
893 struct afs_vnode *vnode = call->reply; 869 struct afs_vnode *vnode = call->reply;
894 const __be32 *bp; 870 const __be32 *bp;
871 int ret;
895 872
896 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); 873 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
897 874
898 afs_transfer_reply(call, skb); 875 ret = afs_transfer_reply(call, skb, last);
899 if (!last) 876 if (ret < 0)
900 return 0; 877 return ret;
901
902 if (call->reply_size != call->reply_max)
903 return -EBADMSG;
904 878
905 /* unmarshall the reply once we've received all of it */ 879 /* unmarshall the reply once we've received all of it */
906 bp = call->buffer; 880 bp = call->buffer;
@@ -999,15 +973,13 @@ static int afs_deliver_fs_rename(struct afs_call *call,
999{ 973{
1000 struct afs_vnode *orig_dvnode = call->reply, *new_dvnode = call->reply2; 974 struct afs_vnode *orig_dvnode = call->reply, *new_dvnode = call->reply2;
1001 const __be32 *bp; 975 const __be32 *bp;
976 int ret;
1002 977
1003 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); 978 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
1004 979
1005 afs_transfer_reply(call, skb); 980 ret = afs_transfer_reply(call, skb, last);
1006 if (!last) 981 if (ret < 0)
1007 return 0; 982 return ret;
1008
1009 if (call->reply_size != call->reply_max)
1010 return -EBADMSG;
1011 983
1012 /* unmarshall the reply once we've received all of it */ 984 /* unmarshall the reply once we've received all of it */
1013 bp = call->buffer; 985 bp = call->buffer;
@@ -1105,20 +1077,13 @@ static int afs_deliver_fs_store_data(struct afs_call *call,
1105{ 1077{
1106 struct afs_vnode *vnode = call->reply; 1078 struct afs_vnode *vnode = call->reply;
1107 const __be32 *bp; 1079 const __be32 *bp;
1080 int ret;
1108 1081
1109 _enter(",,%u", last); 1082 _enter(",,%u", last);
1110 1083
1111 afs_transfer_reply(call, skb); 1084 ret = afs_transfer_reply(call, skb, last);
1112 if (!last) { 1085 if (ret < 0)
1113 _leave(" = 0 [more]"); 1086 return ret;
1114 return 0;
1115 }
1116
1117 if (call->reply_size != call->reply_max) {
1118 _leave(" = -EBADMSG [%u != %u]",
1119 call->reply_size, call->reply_max);
1120 return -EBADMSG;
1121 }
1122 1087
1123 /* unmarshall the reply once we've received all of it */ 1088 /* unmarshall the reply once we've received all of it */
1124 bp = call->buffer; 1089 bp = call->buffer;
@@ -1292,20 +1257,13 @@ static int afs_deliver_fs_store_status(struct afs_call *call,
1292 afs_dataversion_t *store_version; 1257 afs_dataversion_t *store_version;
1293 struct afs_vnode *vnode = call->reply; 1258 struct afs_vnode *vnode = call->reply;
1294 const __be32 *bp; 1259 const __be32 *bp;
1260 int ret;
1295 1261
1296 _enter(",,%u", last); 1262 _enter(",,%u", last);
1297 1263
1298 afs_transfer_reply(call, skb); 1264 ret = afs_transfer_reply(call, skb, last);
1299 if (!last) { 1265 if (ret < 0)
1300 _leave(" = 0 [more]"); 1266 return ret;
1301 return 0;
1302 }
1303
1304 if (call->reply_size != call->reply_max) {
1305 _leave(" = -EBADMSG [%u != %u]",
1306 call->reply_size, call->reply_max);
1307 return -EBADMSG;
1308 }
1309 1267
1310 /* unmarshall the reply once we've received all of it */ 1268 /* unmarshall the reply once we've received all of it */
1311 store_version = NULL; 1269 store_version = NULL;
@@ -1504,11 +1462,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1504 _debug("extract status"); 1462 _debug("extract status");
1505 ret = afs_extract_data(call, skb, last, call->buffer, 1463 ret = afs_extract_data(call, skb, last, call->buffer,
1506 12 * 4); 1464 12 * 4);
1507 switch (ret) { 1465 if (ret < 0)
1508 case 0: break; 1466 return ret;
1509 case -EAGAIN: return 0;
1510 default: return ret;
1511 }
1512 1467
1513 bp = call->buffer; 1468 bp = call->buffer;
1514 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply2); 1469 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply2);
@@ -1518,11 +1473,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1518 /* extract the volume name length */ 1473 /* extract the volume name length */
1519 case 2: 1474 case 2:
1520 ret = afs_extract_data(call, skb, last, &call->tmp, 4); 1475 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
1521 switch (ret) { 1476 if (ret < 0)
1522 case 0: break; 1477 return ret;
1523 case -EAGAIN: return 0;
1524 default: return ret;
1525 }
1526 1478
1527 call->count = ntohl(call->tmp); 1479 call->count = ntohl(call->tmp);
1528 _debug("volname length: %u", call->count); 1480 _debug("volname length: %u", call->count);
@@ -1537,11 +1489,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1537 if (call->count > 0) { 1489 if (call->count > 0) {
1538 ret = afs_extract_data(call, skb, last, call->reply3, 1490 ret = afs_extract_data(call, skb, last, call->reply3,
1539 call->count); 1491 call->count);
1540 switch (ret) { 1492 if (ret < 0)
1541 case 0: break; 1493 return ret;
1542 case -EAGAIN: return 0;
1543 default: return ret;
1544 }
1545 } 1494 }
1546 1495
1547 p = call->reply3; 1496 p = call->reply3;
@@ -1561,11 +1510,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1561 case 4: 1510 case 4:
1562 ret = afs_extract_data(call, skb, last, call->buffer, 1511 ret = afs_extract_data(call, skb, last, call->buffer,
1563 call->count); 1512 call->count);
1564 switch (ret) { 1513 if (ret < 0)
1565 case 0: break; 1514 return ret;
1566 case -EAGAIN: return 0;
1567 default: return ret;
1568 }
1569 1515
1570 call->offset = 0; 1516 call->offset = 0;
1571 call->unmarshall++; 1517 call->unmarshall++;
@@ -1574,11 +1520,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1574 /* extract the offline message length */ 1520 /* extract the offline message length */
1575 case 5: 1521 case 5:
1576 ret = afs_extract_data(call, skb, last, &call->tmp, 4); 1522 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
1577 switch (ret) { 1523 if (ret < 0)
1578 case 0: break; 1524 return ret;
1579 case -EAGAIN: return 0;
1580 default: return ret;
1581 }
1582 1525
1583 call->count = ntohl(call->tmp); 1526 call->count = ntohl(call->tmp);
1584 _debug("offline msg length: %u", call->count); 1527 _debug("offline msg length: %u", call->count);
@@ -1593,11 +1536,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1593 if (call->count > 0) { 1536 if (call->count > 0) {
1594 ret = afs_extract_data(call, skb, last, call->reply3, 1537 ret = afs_extract_data(call, skb, last, call->reply3,
1595 call->count); 1538 call->count);
1596 switch (ret) { 1539 if (ret < 0)
1597 case 0: break; 1540 return ret;
1598 case -EAGAIN: return 0;
1599 default: return ret;
1600 }
1601 } 1541 }
1602 1542
1603 p = call->reply3; 1543 p = call->reply3;
@@ -1617,11 +1557,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1617 case 7: 1557 case 7:
1618 ret = afs_extract_data(call, skb, last, call->buffer, 1558 ret = afs_extract_data(call, skb, last, call->buffer,
1619 call->count); 1559 call->count);
1620 switch (ret) { 1560 if (ret < 0)
1621 case 0: break; 1561 return ret;
1622 case -EAGAIN: return 0;
1623 default: return ret;
1624 }
1625 1562
1626 call->offset = 0; 1563 call->offset = 0;
1627 call->unmarshall++; 1564 call->unmarshall++;
@@ -1630,11 +1567,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1630 /* extract the message of the day length */ 1567 /* extract the message of the day length */
1631 case 8: 1568 case 8:
1632 ret = afs_extract_data(call, skb, last, &call->tmp, 4); 1569 ret = afs_extract_data(call, skb, last, &call->tmp, 4);
1633 switch (ret) { 1570 if (ret < 0)
1634 case 0: break; 1571 return ret;
1635 case -EAGAIN: return 0;
1636 default: return ret;
1637 }
1638 1572
1639 call->count = ntohl(call->tmp); 1573 call->count = ntohl(call->tmp);
1640 _debug("motd length: %u", call->count); 1574 _debug("motd length: %u", call->count);
@@ -1649,11 +1583,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1649 if (call->count > 0) { 1583 if (call->count > 0) {
1650 ret = afs_extract_data(call, skb, last, call->reply3, 1584 ret = afs_extract_data(call, skb, last, call->reply3,
1651 call->count); 1585 call->count);
1652 switch (ret) { 1586 if (ret < 0)
1653 case 0: break; 1587 return ret;
1654 case -EAGAIN: return 0;
1655 default: return ret;
1656 }
1657 } 1588 }
1658 1589
1659 p = call->reply3; 1590 p = call->reply3;
@@ -1673,26 +1604,20 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call,
1673 case 10: 1604 case 10:
1674 ret = afs_extract_data(call, skb, last, call->buffer, 1605 ret = afs_extract_data(call, skb, last, call->buffer,
1675 call->count); 1606 call->count);
1676 switch (ret) { 1607 if (ret < 0)
1677 case 0: break; 1608 return ret;
1678 case -EAGAIN: return 0;
1679 default: return ret;
1680 }
1681 1609
1682 call->offset = 0; 1610 call->offset = 0;
1683 call->unmarshall++; 1611 call->unmarshall++;
1684 no_motd_padding: 1612 no_motd_padding:
1685 1613
1686 case 11: 1614 case 11:
1687 _debug("trailer %d", skb->len); 1615 ret = afs_data_complete(call, skb, last);
1688 if (skb->len != 0) 1616 if (ret < 0)
1689 return -EBADMSG; 1617 return ret;
1690 break; 1618 break;
1691 } 1619 }
1692 1620
1693 if (!last)
1694 return 0;
1695
1696 _leave(" = 0 [done]"); 1621 _leave(" = 0 [done]");
1697 return 0; 1622 return 0;
1698} 1623}
@@ -1764,15 +1689,13 @@ static int afs_deliver_fs_xxxx_lock(struct afs_call *call,
1764 struct sk_buff *skb, bool last) 1689 struct sk_buff *skb, bool last)
1765{ 1690{
1766 const __be32 *bp; 1691 const __be32 *bp;
1692 int ret;
1767 1693
1768 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); 1694 _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
1769 1695
1770 afs_transfer_reply(call, skb); 1696 ret = afs_transfer_reply(call, skb, last);
1771 if (!last) 1697 if (ret < 0)
1772 return 0; 1698 return ret;
1773
1774 if (call->reply_size != call->reply_max)
1775 return -EBADMSG;
1776 1699
1777 /* unmarshall the reply once we've received all of it */ 1700 /* unmarshall the reply once we've received all of it */
1778 bp = call->buffer; 1701 bp = call->buffer;
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 71d5982312f3..df976b2a7f40 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -609,17 +609,29 @@ extern void afs_proc_cell_remove(struct afs_cell *);
609 */ 609 */
610extern int afs_open_socket(void); 610extern int afs_open_socket(void);
611extern void afs_close_socket(void); 611extern void afs_close_socket(void);
612extern void afs_data_consumed(struct afs_call *, struct sk_buff *);
612extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t, 613extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t,
613 const struct afs_wait_mode *); 614 const struct afs_wait_mode *);
614extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *, 615extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *,
615 size_t, size_t); 616 size_t, size_t);
616extern void afs_flat_call_destructor(struct afs_call *); 617extern void afs_flat_call_destructor(struct afs_call *);
617extern void afs_transfer_reply(struct afs_call *, struct sk_buff *); 618extern int afs_transfer_reply(struct afs_call *, struct sk_buff *, bool);
618extern void afs_send_empty_reply(struct afs_call *); 619extern void afs_send_empty_reply(struct afs_call *);
619extern void afs_send_simple_reply(struct afs_call *, const void *, size_t); 620extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
620extern int afs_extract_data(struct afs_call *, struct sk_buff *, bool, void *, 621extern int afs_extract_data(struct afs_call *, struct sk_buff *, bool, void *,
621 size_t); 622 size_t);
622 623
624static inline int afs_data_complete(struct afs_call *call, struct sk_buff *skb,
625 bool last)
626{
627 if (skb->len > 0)
628 return -EBADMSG;
629 afs_data_consumed(call, skb);
630 if (!last)
631 return -EAGAIN;
632 return 0;
633}
634
623/* 635/*
624 * security.c 636 * security.c
625 */ 637 */
diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c
index 4832de84d52c..14d04c848465 100644
--- a/fs/afs/rxrpc.c
+++ b/fs/afs/rxrpc.c
@@ -150,10 +150,9 @@ void afs_close_socket(void)
150} 150}
151 151
152/* 152/*
153 * note that the data in a socket buffer is now delivered and that the buffer 153 * Note that the data in a socket buffer is now consumed.
154 * should be freed
155 */ 154 */
156static void afs_data_delivered(struct sk_buff *skb) 155void afs_data_consumed(struct afs_call *call, struct sk_buff *skb)
157{ 156{
158 if (!skb) { 157 if (!skb) {
159 _debug("DLVR NULL [%d]", atomic_read(&afs_outstanding_skbs)); 158 _debug("DLVR NULL [%d]", atomic_read(&afs_outstanding_skbs));
@@ -161,9 +160,7 @@ static void afs_data_delivered(struct sk_buff *skb)
161 } else { 160 } else {
162 _debug("DLVR %p{%u} [%d]", 161 _debug("DLVR %p{%u} [%d]",
163 skb, skb->mark, atomic_read(&afs_outstanding_skbs)); 162 skb, skb->mark, atomic_read(&afs_outstanding_skbs));
164 if (atomic_dec_return(&afs_outstanding_skbs) == -1) 163 rxrpc_kernel_data_consumed(call->rxcall, skb);
165 BUG();
166 rxrpc_kernel_data_delivered(skb);
167 } 164 }
168} 165}
169 166
@@ -489,9 +486,15 @@ static void afs_deliver_to_call(struct afs_call *call)
489 last = rxrpc_kernel_is_data_last(skb); 486 last = rxrpc_kernel_is_data_last(skb);
490 ret = call->type->deliver(call, skb, last); 487 ret = call->type->deliver(call, skb, last);
491 switch (ret) { 488 switch (ret) {
489 case -EAGAIN:
490 if (last) {
491 _debug("short data");
492 goto unmarshal_error;
493 }
494 break;
492 case 0: 495 case 0:
493 if (last && 496 ASSERT(last);
494 call->state == AFS_CALL_AWAIT_REPLY) 497 if (call->state == AFS_CALL_AWAIT_REPLY)
495 call->state = AFS_CALL_COMPLETE; 498 call->state = AFS_CALL_COMPLETE;
496 break; 499 break;
497 case -ENOTCONN: 500 case -ENOTCONN:
@@ -501,6 +504,7 @@ static void afs_deliver_to_call(struct afs_call *call)
501 abort_code = RX_INVALID_OPERATION; 504 abort_code = RX_INVALID_OPERATION;
502 goto do_abort; 505 goto do_abort;
503 default: 506 default:
507 unmarshal_error:
504 abort_code = RXGEN_CC_UNMARSHAL; 508 abort_code = RXGEN_CC_UNMARSHAL;
505 if (call->state != AFS_CALL_AWAIT_REPLY) 509 if (call->state != AFS_CALL_AWAIT_REPLY)
506 abort_code = RXGEN_SS_UNMARSHAL; 510 abort_code = RXGEN_SS_UNMARSHAL;
@@ -511,9 +515,7 @@ static void afs_deliver_to_call(struct afs_call *call)
511 call->state = AFS_CALL_ERROR; 515 call->state = AFS_CALL_ERROR;
512 break; 516 break;
513 } 517 }
514 afs_data_delivered(skb); 518 break;
515 skb = NULL;
516 continue;
517 case RXRPC_SKB_MARK_FINAL_ACK: 519 case RXRPC_SKB_MARK_FINAL_ACK:
518 _debug("Rcv ACK"); 520 _debug("Rcv ACK");
519 call->state = AFS_CALL_COMPLETE; 521 call->state = AFS_CALL_COMPLETE;
@@ -685,15 +687,35 @@ static void afs_process_async_call(struct afs_call *call)
685} 687}
686 688
687/* 689/*
688 * empty a socket buffer into a flat reply buffer 690 * Empty a socket buffer into a flat reply buffer.
689 */ 691 */
690void afs_transfer_reply(struct afs_call *call, struct sk_buff *skb) 692int afs_transfer_reply(struct afs_call *call, struct sk_buff *skb, bool last)
691{ 693{
692 size_t len = skb->len; 694 size_t len = skb->len;
693 695
694 if (skb_copy_bits(skb, 0, call->buffer + call->reply_size, len) < 0) 696 if (len > call->reply_max - call->reply_size) {
695 BUG(); 697 _leave(" = -EBADMSG [%zu > %u]",
696 call->reply_size += len; 698 len, call->reply_max - call->reply_size);
699 return -EBADMSG;
700 }
701
702 if (len > 0) {
703 if (skb_copy_bits(skb, 0, call->buffer + call->reply_size,
704 len) < 0)
705 BUG();
706 call->reply_size += len;
707 }
708
709 afs_data_consumed(call, skb);
710 if (!last)
711 return -EAGAIN;
712
713 if (call->reply_size != call->reply_max) {
714 _leave(" = -EBADMSG [%u != %u]",
715 call->reply_size, call->reply_max);
716 return -EBADMSG;
717 }
718 return 0;
697} 719}
698 720
699/* 721/*
@@ -745,7 +767,8 @@ static void afs_collect_incoming_call(struct work_struct *work)
745} 767}
746 768
747/* 769/*
748 * grab the operation ID from an incoming cache manager call 770 * Grab the operation ID from an incoming cache manager call. The socket
771 * buffer is discarded on error or if we don't yet have sufficient data.
749 */ 772 */
750static int afs_deliver_cm_op_id(struct afs_call *call, struct sk_buff *skb, 773static int afs_deliver_cm_op_id(struct afs_call *call, struct sk_buff *skb,
751 bool last) 774 bool last)
@@ -766,12 +789,9 @@ static int afs_deliver_cm_op_id(struct afs_call *call, struct sk_buff *skb,
766 call->offset += len; 789 call->offset += len;
767 790
768 if (call->offset < 4) { 791 if (call->offset < 4) {
769 if (last) { 792 afs_data_consumed(call, skb);
770 _leave(" = -EBADMSG [op ID short]"); 793 _leave(" = -EAGAIN");
771 return -EBADMSG; 794 return -EAGAIN;
772 }
773 _leave(" = 0 [incomplete]");
774 return 0;
775 } 795 }
776 796
777 call->state = AFS_CALL_AWAIT_REQUEST; 797 call->state = AFS_CALL_AWAIT_REQUEST;
@@ -855,7 +875,7 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
855} 875}
856 876
857/* 877/*
858 * extract a piece of data from the received data socket buffers 878 * Extract a piece of data from the received data socket buffers.
859 */ 879 */
860int afs_extract_data(struct afs_call *call, struct sk_buff *skb, 880int afs_extract_data(struct afs_call *call, struct sk_buff *skb,
861 bool last, void *buf, size_t count) 881 bool last, void *buf, size_t count)
@@ -873,10 +893,7 @@ int afs_extract_data(struct afs_call *call, struct sk_buff *skb,
873 call->offset += len; 893 call->offset += len;
874 894
875 if (call->offset < count) { 895 if (call->offset < count) {
876 if (last) { 896 afs_data_consumed(call, skb);
877 _leave(" = -EBADMSG [%d < %zu]", call->offset, count);
878 return -EBADMSG;
879 }
880 _leave(" = -EAGAIN"); 897 _leave(" = -EAGAIN");
881 return -EAGAIN; 898 return -EAGAIN;
882 } 899 }
diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c
index 340afd0cd182..f94d1abdc3eb 100644
--- a/fs/afs/vlclient.c
+++ b/fs/afs/vlclient.c
@@ -64,16 +64,13 @@ static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call,
64 struct afs_cache_vlocation *entry; 64 struct afs_cache_vlocation *entry;
65 __be32 *bp; 65 __be32 *bp;
66 u32 tmp; 66 u32 tmp;
67 int loop; 67 int loop, ret;
68 68
69 _enter(",,%u", last); 69 _enter(",,%u", last);
70 70
71 afs_transfer_reply(call, skb); 71 ret = afs_transfer_reply(call, skb, last);
72 if (!last) 72 if (ret < 0)
73 return 0; 73 return ret;
74
75 if (call->reply_size != call->reply_max)
76 return -EBADMSG;
77 74
78 /* unmarshall the reply once we've received all of it */ 75 /* unmarshall the reply once we've received all of it */
79 entry = call->reply; 76 entry = call->reply;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index c3cdde87cc8c..08ae99343d92 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -249,7 +249,8 @@ struct super_block *freeze_bdev(struct block_device *bdev)
249 * thaw_bdev drops it. 249 * thaw_bdev drops it.
250 */ 250 */
251 sb = get_super(bdev); 251 sb = get_super(bdev);
252 drop_super(sb); 252 if (sb)
253 drop_super(sb);
253 mutex_unlock(&bdev->bd_fsfreeze_mutex); 254 mutex_unlock(&bdev->bd_fsfreeze_mutex);
254 return sb; 255 return sb;
255 } 256 }
@@ -646,7 +647,7 @@ static struct dentry *bd_mount(struct file_system_type *fs_type,
646{ 647{
647 struct dentry *dent; 648 struct dentry *dent;
648 dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, BDEVFS_MAGIC); 649 dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, BDEVFS_MAGIC);
649 if (dent) 650 if (!IS_ERR(dent))
650 dent->d_sb->s_iflags |= SB_I_CGROUPWB; 651 dent->d_sb->s_iflags |= SB_I_CGROUPWB;
651 return dent; 652 return dent;
652} 653}
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 2b88439c2ee8..455a6b2fd539 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -589,6 +589,7 @@ static void __merge_refs(struct list_head *head, int mode)
589 589
590 list_del(&ref2->list); 590 list_del(&ref2->list);
591 kmem_cache_free(btrfs_prelim_ref_cache, ref2); 591 kmem_cache_free(btrfs_prelim_ref_cache, ref2);
592 cond_resched();
592 } 593 }
593 594
594 } 595 }
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 2fe8f89091a3..eff3993c77b3 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1028,6 +1028,7 @@ struct btrfs_fs_info {
1028 struct btrfs_workqueue *qgroup_rescan_workers; 1028 struct btrfs_workqueue *qgroup_rescan_workers;
1029 struct completion qgroup_rescan_completion; 1029 struct completion qgroup_rescan_completion;
1030 struct btrfs_work qgroup_rescan_work; 1030 struct btrfs_work qgroup_rescan_work;
1031 bool qgroup_rescan_running; /* protected by qgroup_rescan_lock */
1031 1032
1032 /* filesystem state */ 1033 /* filesystem state */
1033 unsigned long fs_state; 1034 unsigned long fs_state;
@@ -1079,6 +1080,8 @@ struct btrfs_fs_info {
1079 struct list_head pinned_chunks; 1080 struct list_head pinned_chunks;
1080 1081
1081 int creating_free_space_tree; 1082 int creating_free_space_tree;
1083 /* Used to record internally whether fs has been frozen */
1084 int fs_frozen;
1082}; 1085};
1083 1086
1084struct btrfs_subvolume_writers { 1087struct btrfs_subvolume_writers {
@@ -2578,7 +2581,7 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
2578 struct btrfs_root *root, 2581 struct btrfs_root *root,
2579 u64 root_objectid, u64 owner, u64 offset, 2582 u64 root_objectid, u64 owner, u64 offset,
2580 struct btrfs_key *ins); 2583 struct btrfs_key *ins);
2581int btrfs_reserve_extent(struct btrfs_root *root, u64 num_bytes, 2584int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes,
2582 u64 min_alloc_size, u64 empty_size, u64 hint_byte, 2585 u64 min_alloc_size, u64 empty_size, u64 hint_byte,
2583 struct btrfs_key *ins, int is_data, int delalloc); 2586 struct btrfs_key *ins, int is_data, int delalloc);
2584int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 2587int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index b6d210e7a993..ac02e041464b 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -541,7 +541,6 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
541 struct btrfs_delayed_ref_head *existing; 541 struct btrfs_delayed_ref_head *existing;
542 struct btrfs_delayed_ref_head *head_ref = NULL; 542 struct btrfs_delayed_ref_head *head_ref = NULL;
543 struct btrfs_delayed_ref_root *delayed_refs; 543 struct btrfs_delayed_ref_root *delayed_refs;
544 struct btrfs_qgroup_extent_record *qexisting;
545 int count_mod = 1; 544 int count_mod = 1;
546 int must_insert_reserved = 0; 545 int must_insert_reserved = 0;
547 546
@@ -606,10 +605,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
606 qrecord->num_bytes = num_bytes; 605 qrecord->num_bytes = num_bytes;
607 qrecord->old_roots = NULL; 606 qrecord->old_roots = NULL;
608 607
609 qexisting = btrfs_qgroup_insert_dirty_extent(fs_info, 608 if(btrfs_qgroup_insert_dirty_extent_nolock(fs_info,
610 delayed_refs, 609 delayed_refs, qrecord))
611 qrecord);
612 if (qexisting)
613 kfree(qrecord); 610 kfree(qrecord);
614 } 611 }
615 612
@@ -862,33 +859,6 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
862 return 0; 859 return 0;
863} 860}
864 861
865int btrfs_add_delayed_qgroup_reserve(struct btrfs_fs_info *fs_info,
866 struct btrfs_trans_handle *trans,
867 u64 ref_root, u64 bytenr, u64 num_bytes)
868{
869 struct btrfs_delayed_ref_root *delayed_refs;
870 struct btrfs_delayed_ref_head *ref_head;
871 int ret = 0;
872
873 if (!fs_info->quota_enabled || !is_fstree(ref_root))
874 return 0;
875
876 delayed_refs = &trans->transaction->delayed_refs;
877
878 spin_lock(&delayed_refs->lock);
879 ref_head = find_ref_head(&delayed_refs->href_root, bytenr, 0);
880 if (!ref_head) {
881 ret = -ENOENT;
882 goto out;
883 }
884 WARN_ON(ref_head->qgroup_reserved || ref_head->qgroup_ref_root);
885 ref_head->qgroup_ref_root = ref_root;
886 ref_head->qgroup_reserved = num_bytes;
887out:
888 spin_unlock(&delayed_refs->lock);
889 return ret;
890}
891
892int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, 862int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
893 struct btrfs_trans_handle *trans, 863 struct btrfs_trans_handle *trans,
894 u64 bytenr, u64 num_bytes, 864 u64 bytenr, u64 num_bytes,
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 5fca9534a271..43f3629760e9 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -250,9 +250,6 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
250 u64 parent, u64 ref_root, 250 u64 parent, u64 ref_root,
251 u64 owner, u64 offset, u64 reserved, int action, 251 u64 owner, u64 offset, u64 reserved, int action,
252 struct btrfs_delayed_extent_op *extent_op); 252 struct btrfs_delayed_extent_op *extent_op);
253int btrfs_add_delayed_qgroup_reserve(struct btrfs_fs_info *fs_info,
254 struct btrfs_trans_handle *trans,
255 u64 ref_root, u64 bytenr, u64 num_bytes);
256int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, 253int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
257 struct btrfs_trans_handle *trans, 254 struct btrfs_trans_handle *trans,
258 u64 bytenr, u64 num_bytes, 255 u64 bytenr, u64 num_bytes,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 59febfb8d04a..54bc8c7c6bcd 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -559,8 +559,29 @@ static noinline int check_leaf(struct btrfs_root *root,
559 u32 nritems = btrfs_header_nritems(leaf); 559 u32 nritems = btrfs_header_nritems(leaf);
560 int slot; 560 int slot;
561 561
562 if (nritems == 0) 562 if (nritems == 0) {
563 struct btrfs_root *check_root;
564
565 key.objectid = btrfs_header_owner(leaf);
566 key.type = BTRFS_ROOT_ITEM_KEY;
567 key.offset = (u64)-1;
568
569 check_root = btrfs_get_fs_root(root->fs_info, &key, false);
570 /*
571 * The only reason we also check NULL here is that during
572 * open_ctree() some roots has not yet been set up.
573 */
574 if (!IS_ERR_OR_NULL(check_root)) {
575 /* if leaf is the root, then it's fine */
576 if (leaf->start !=
577 btrfs_root_bytenr(&check_root->root_item)) {
578 CORRUPT("non-root leaf's nritems is 0",
579 leaf, root, 0);
580 return -EIO;
581 }
582 }
563 return 0; 583 return 0;
584 }
564 585
565 /* Check the 0 item */ 586 /* Check the 0 item */
566 if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) != 587 if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) !=
@@ -612,6 +633,19 @@ static noinline int check_leaf(struct btrfs_root *root,
612 return 0; 633 return 0;
613} 634}
614 635
636static int check_node(struct btrfs_root *root, struct extent_buffer *node)
637{
638 unsigned long nr = btrfs_header_nritems(node);
639
640 if (nr == 0 || nr > BTRFS_NODEPTRS_PER_BLOCK(root)) {
641 btrfs_crit(root->fs_info,
642 "corrupt node: block %llu root %llu nritems %lu",
643 node->start, root->objectid, nr);
644 return -EIO;
645 }
646 return 0;
647}
648
615static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, 649static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
616 u64 phy_offset, struct page *page, 650 u64 phy_offset, struct page *page,
617 u64 start, u64 end, int mirror) 651 u64 start, u64 end, int mirror)
@@ -682,6 +716,9 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
682 ret = -EIO; 716 ret = -EIO;
683 } 717 }
684 718
719 if (found_level > 0 && check_node(root, eb))
720 ret = -EIO;
721
685 if (!ret) 722 if (!ret)
686 set_extent_buffer_uptodate(eb); 723 set_extent_buffer_uptodate(eb);
687err: 724err:
@@ -1618,8 +1655,8 @@ fail:
1618 return ret; 1655 return ret;
1619} 1656}
1620 1657
1621static struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, 1658struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info,
1622 u64 root_id) 1659 u64 root_id)
1623{ 1660{
1624 struct btrfs_root *root; 1661 struct btrfs_root *root;
1625 1662
@@ -2298,6 +2335,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
2298 fs_info->quota_enabled = 0; 2335 fs_info->quota_enabled = 0;
2299 fs_info->pending_quota_state = 0; 2336 fs_info->pending_quota_state = 0;
2300 fs_info->qgroup_ulist = NULL; 2337 fs_info->qgroup_ulist = NULL;
2338 fs_info->qgroup_rescan_running = false;
2301 mutex_init(&fs_info->qgroup_rescan_lock); 2339 mutex_init(&fs_info->qgroup_rescan_lock);
2302} 2340}
2303 2341
@@ -2624,6 +2662,7 @@ int open_ctree(struct super_block *sb,
2624 atomic_set(&fs_info->qgroup_op_seq, 0); 2662 atomic_set(&fs_info->qgroup_op_seq, 0);
2625 atomic_set(&fs_info->reada_works_cnt, 0); 2663 atomic_set(&fs_info->reada_works_cnt, 0);
2626 atomic64_set(&fs_info->tree_mod_seq, 0); 2664 atomic64_set(&fs_info->tree_mod_seq, 0);
2665 fs_info->fs_frozen = 0;
2627 fs_info->sb = sb; 2666 fs_info->sb = sb;
2628 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE; 2667 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE;
2629 fs_info->metadata_ratio = 0; 2668 fs_info->metadata_ratio = 0;
@@ -3739,8 +3778,15 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
3739 if (btrfs_root_refs(&root->root_item) == 0) 3778 if (btrfs_root_refs(&root->root_item) == 0)
3740 synchronize_srcu(&fs_info->subvol_srcu); 3779 synchronize_srcu(&fs_info->subvol_srcu);
3741 3780
3742 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) 3781 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
3743 btrfs_free_log(NULL, root); 3782 btrfs_free_log(NULL, root);
3783 if (root->reloc_root) {
3784 free_extent_buffer(root->reloc_root->node);
3785 free_extent_buffer(root->reloc_root->commit_root);
3786 btrfs_put_fs_root(root->reloc_root);
3787 root->reloc_root = NULL;
3788 }
3789 }
3744 3790
3745 if (root->free_ino_pinned) 3791 if (root->free_ino_pinned)
3746 __btrfs_remove_free_space_cache(root->free_ino_pinned); 3792 __btrfs_remove_free_space_cache(root->free_ino_pinned);
@@ -3851,7 +3897,7 @@ void close_ctree(struct btrfs_root *root)
3851 smp_mb(); 3897 smp_mb();
3852 3898
3853 /* wait for the qgroup rescan worker to stop */ 3899 /* wait for the qgroup rescan worker to stop */
3854 btrfs_qgroup_wait_for_completion(fs_info); 3900 btrfs_qgroup_wait_for_completion(fs_info, false);
3855 3901
3856 /* wait for the uuid_scan task to finish */ 3902 /* wait for the uuid_scan task to finish */
3857 down(&fs_info->uuid_tree_rescan_sem); 3903 down(&fs_info->uuid_tree_rescan_sem);
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index b3207a0e09f7..f19a982f5a4f 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -68,6 +68,8 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
68struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root, 68struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root,
69 struct btrfs_key *location); 69 struct btrfs_key *location);
70int btrfs_init_fs_root(struct btrfs_root *root); 70int btrfs_init_fs_root(struct btrfs_root *root);
71struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info,
72 u64 root_id);
71int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info, 73int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info,
72 struct btrfs_root *root); 74 struct btrfs_root *root);
73void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info); 75void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 61b494e8e604..0450dc410533 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -60,21 +60,6 @@ enum {
60 CHUNK_ALLOC_FORCE = 2, 60 CHUNK_ALLOC_FORCE = 2,
61}; 61};
62 62
63/*
64 * Control how reservations are dealt with.
65 *
66 * RESERVE_FREE - freeing a reservation.
67 * RESERVE_ALLOC - allocating space and we need to update bytes_may_use for
68 * ENOSPC accounting
69 * RESERVE_ALLOC_NO_ACCOUNT - allocating space and we should not update
70 * bytes_may_use as the ENOSPC accounting is done elsewhere
71 */
72enum {
73 RESERVE_FREE = 0,
74 RESERVE_ALLOC = 1,
75 RESERVE_ALLOC_NO_ACCOUNT = 2,
76};
77
78static int update_block_group(struct btrfs_trans_handle *trans, 63static int update_block_group(struct btrfs_trans_handle *trans,
79 struct btrfs_root *root, u64 bytenr, 64 struct btrfs_root *root, u64 bytenr,
80 u64 num_bytes, int alloc); 65 u64 num_bytes, int alloc);
@@ -104,9 +89,10 @@ static int find_next_key(struct btrfs_path *path, int level,
104 struct btrfs_key *key); 89 struct btrfs_key *key);
105static void dump_space_info(struct btrfs_space_info *info, u64 bytes, 90static void dump_space_info(struct btrfs_space_info *info, u64 bytes,
106 int dump_block_groups); 91 int dump_block_groups);
107static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache, 92static int btrfs_add_reserved_bytes(struct btrfs_block_group_cache *cache,
108 u64 num_bytes, int reserve, 93 u64 ram_bytes, u64 num_bytes, int delalloc);
109 int delalloc); 94static int btrfs_free_reserved_bytes(struct btrfs_block_group_cache *cache,
95 u64 num_bytes, int delalloc);
110static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv, 96static int block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv,
111 u64 num_bytes); 97 u64 num_bytes);
112int btrfs_pin_extent(struct btrfs_root *root, 98int btrfs_pin_extent(struct btrfs_root *root,
@@ -3501,7 +3487,6 @@ again:
3501 dcs = BTRFS_DC_SETUP; 3487 dcs = BTRFS_DC_SETUP;
3502 else if (ret == -ENOSPC) 3488 else if (ret == -ENOSPC)
3503 set_bit(BTRFS_TRANS_CACHE_ENOSPC, &trans->transaction->flags); 3489 set_bit(BTRFS_TRANS_CACHE_ENOSPC, &trans->transaction->flags);
3504 btrfs_free_reserved_data_space(inode, 0, num_pages);
3505 3490
3506out_put: 3491out_put:
3507 iput(inode); 3492 iput(inode);
@@ -4472,6 +4457,15 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
4472 } 4457 }
4473} 4458}
4474 4459
4460/*
4461 * If force is CHUNK_ALLOC_FORCE:
4462 * - return 1 if it successfully allocates a chunk,
4463 * - return errors including -ENOSPC otherwise.
4464 * If force is NOT CHUNK_ALLOC_FORCE:
4465 * - return 0 if it doesn't need to allocate a new chunk,
4466 * - return 1 if it successfully allocates a chunk,
4467 * - return errors including -ENOSPC otherwise.
4468 */
4475static int do_chunk_alloc(struct btrfs_trans_handle *trans, 4469static int do_chunk_alloc(struct btrfs_trans_handle *trans,
4476 struct btrfs_root *extent_root, u64 flags, int force) 4470 struct btrfs_root *extent_root, u64 flags, int force)
4477{ 4471{
@@ -4882,7 +4876,7 @@ static int flush_space(struct btrfs_root *root,
4882 btrfs_get_alloc_profile(root, 0), 4876 btrfs_get_alloc_profile(root, 0),
4883 CHUNK_ALLOC_NO_FORCE); 4877 CHUNK_ALLOC_NO_FORCE);
4884 btrfs_end_transaction(trans, root); 4878 btrfs_end_transaction(trans, root);
4885 if (ret == -ENOSPC) 4879 if (ret > 0 || ret == -ENOSPC)
4886 ret = 0; 4880 ret = 0;
4887 break; 4881 break;
4888 case COMMIT_TRANS: 4882 case COMMIT_TRANS:
@@ -6497,19 +6491,15 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg)
6497} 6491}
6498 6492
6499/** 6493/**
6500 * btrfs_update_reserved_bytes - update the block_group and space info counters 6494 * btrfs_add_reserved_bytes - update the block_group and space info counters
6501 * @cache: The cache we are manipulating 6495 * @cache: The cache we are manipulating
6496 * @ram_bytes: The number of bytes of file content, and will be same to
6497 * @num_bytes except for the compress path.
6502 * @num_bytes: The number of bytes in question 6498 * @num_bytes: The number of bytes in question
6503 * @reserve: One of the reservation enums
6504 * @delalloc: The blocks are allocated for the delalloc write 6499 * @delalloc: The blocks are allocated for the delalloc write
6505 * 6500 *
6506 * This is called by the allocator when it reserves space, or by somebody who is 6501 * This is called by the allocator when it reserves space. Metadata
6507 * freeing space that was never actually used on disk. For example if you 6502 * reservations should be called with RESERVE_ALLOC so we do the proper
6508 * reserve some space for a new leaf in transaction A and before transaction A
6509 * commits you free that leaf, you call this with reserve set to 0 in order to
6510 * clear the reservation.
6511 *
6512 * Metadata reservations should be called with RESERVE_ALLOC so we do the proper
6513 * ENOSPC accounting. For data we handle the reservation through clearing the 6503 * ENOSPC accounting. For data we handle the reservation through clearing the
6514 * delalloc bits in the io_tree. We have to do this since we could end up 6504 * delalloc bits in the io_tree. We have to do this since we could end up
6515 * allocating less disk space for the amount of data we have reserved in the 6505 * allocating less disk space for the amount of data we have reserved in the
@@ -6519,44 +6509,63 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg)
6519 * make the reservation and return -EAGAIN, otherwise this function always 6509 * make the reservation and return -EAGAIN, otherwise this function always
6520 * succeeds. 6510 * succeeds.
6521 */ 6511 */
6522static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache, 6512static int btrfs_add_reserved_bytes(struct btrfs_block_group_cache *cache,
6523 u64 num_bytes, int reserve, int delalloc) 6513 u64 ram_bytes, u64 num_bytes, int delalloc)
6524{ 6514{
6525 struct btrfs_space_info *space_info = cache->space_info; 6515 struct btrfs_space_info *space_info = cache->space_info;
6526 int ret = 0; 6516 int ret = 0;
6527 6517
6528 spin_lock(&space_info->lock); 6518 spin_lock(&space_info->lock);
6529 spin_lock(&cache->lock); 6519 spin_lock(&cache->lock);
6530 if (reserve != RESERVE_FREE) { 6520 if (cache->ro) {
6531 if (cache->ro) { 6521 ret = -EAGAIN;
6532 ret = -EAGAIN;
6533 } else {
6534 cache->reserved += num_bytes;
6535 space_info->bytes_reserved += num_bytes;
6536 if (reserve == RESERVE_ALLOC) {
6537 trace_btrfs_space_reservation(cache->fs_info,
6538 "space_info", space_info->flags,
6539 num_bytes, 0);
6540 space_info->bytes_may_use -= num_bytes;
6541 }
6542
6543 if (delalloc)
6544 cache->delalloc_bytes += num_bytes;
6545 }
6546 } else { 6522 } else {
6547 if (cache->ro) 6523 cache->reserved += num_bytes;
6548 space_info->bytes_readonly += num_bytes; 6524 space_info->bytes_reserved += num_bytes;
6549 cache->reserved -= num_bytes;
6550 space_info->bytes_reserved -= num_bytes;
6551 6525
6526 trace_btrfs_space_reservation(cache->fs_info,
6527 "space_info", space_info->flags,
6528 ram_bytes, 0);
6529 space_info->bytes_may_use -= ram_bytes;
6552 if (delalloc) 6530 if (delalloc)
6553 cache->delalloc_bytes -= num_bytes; 6531 cache->delalloc_bytes += num_bytes;
6554 } 6532 }
6555 spin_unlock(&cache->lock); 6533 spin_unlock(&cache->lock);
6556 spin_unlock(&space_info->lock); 6534 spin_unlock(&space_info->lock);
6557 return ret; 6535 return ret;
6558} 6536}
6559 6537
6538/**
6539 * btrfs_free_reserved_bytes - update the block_group and space info counters
6540 * @cache: The cache we are manipulating
6541 * @num_bytes: The number of bytes in question
6542 * @delalloc: The blocks are allocated for the delalloc write
6543 *
6544 * This is called by somebody who is freeing space that was never actually used
6545 * on disk. For example if you reserve some space for a new leaf in transaction
6546 * A and before transaction A commits you free that leaf, you call this with
6547 * reserve set to 0 in order to clear the reservation.
6548 */
6549
6550static int btrfs_free_reserved_bytes(struct btrfs_block_group_cache *cache,
6551 u64 num_bytes, int delalloc)
6552{
6553 struct btrfs_space_info *space_info = cache->space_info;
6554 int ret = 0;
6555
6556 spin_lock(&space_info->lock);
6557 spin_lock(&cache->lock);
6558 if (cache->ro)
6559 space_info->bytes_readonly += num_bytes;
6560 cache->reserved -= num_bytes;
6561 space_info->bytes_reserved -= num_bytes;
6562
6563 if (delalloc)
6564 cache->delalloc_bytes -= num_bytes;
6565 spin_unlock(&cache->lock);
6566 spin_unlock(&space_info->lock);
6567 return ret;
6568}
6560void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, 6569void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
6561 struct btrfs_root *root) 6570 struct btrfs_root *root)
6562{ 6571{
@@ -7191,7 +7200,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
7191 WARN_ON(test_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)); 7200 WARN_ON(test_bit(EXTENT_BUFFER_DIRTY, &buf->bflags));
7192 7201
7193 btrfs_add_free_space(cache, buf->start, buf->len); 7202 btrfs_add_free_space(cache, buf->start, buf->len);
7194 btrfs_update_reserved_bytes(cache, buf->len, RESERVE_FREE, 0); 7203 btrfs_free_reserved_bytes(cache, buf->len, 0);
7195 btrfs_put_block_group(cache); 7204 btrfs_put_block_group(cache);
7196 trace_btrfs_reserved_extent_free(root, buf->start, buf->len); 7205 trace_btrfs_reserved_extent_free(root, buf->start, buf->len);
7197 pin = 0; 7206 pin = 0;
@@ -7416,9 +7425,9 @@ btrfs_release_block_group(struct btrfs_block_group_cache *cache,
7416 * the free space extent currently. 7425 * the free space extent currently.
7417 */ 7426 */
7418static noinline int find_free_extent(struct btrfs_root *orig_root, 7427static noinline int find_free_extent(struct btrfs_root *orig_root,
7419 u64 num_bytes, u64 empty_size, 7428 u64 ram_bytes, u64 num_bytes, u64 empty_size,
7420 u64 hint_byte, struct btrfs_key *ins, 7429 u64 hint_byte, struct btrfs_key *ins,
7421 u64 flags, int delalloc) 7430 u64 flags, int delalloc)
7422{ 7431{
7423 int ret = 0; 7432 int ret = 0;
7424 struct btrfs_root *root = orig_root->fs_info->extent_root; 7433 struct btrfs_root *root = orig_root->fs_info->extent_root;
@@ -7430,8 +7439,6 @@ static noinline int find_free_extent(struct btrfs_root *orig_root,
7430 struct btrfs_space_info *space_info; 7439 struct btrfs_space_info *space_info;
7431 int loop = 0; 7440 int loop = 0;
7432 int index = __get_raid_index(flags); 7441 int index = __get_raid_index(flags);
7433 int alloc_type = (flags & BTRFS_BLOCK_GROUP_DATA) ?
7434 RESERVE_ALLOC_NO_ACCOUNT : RESERVE_ALLOC;
7435 bool failed_cluster_refill = false; 7442 bool failed_cluster_refill = false;
7436 bool failed_alloc = false; 7443 bool failed_alloc = false;
7437 bool use_cluster = true; 7444 bool use_cluster = true;
@@ -7763,8 +7770,8 @@ checks:
7763 search_start - offset); 7770 search_start - offset);
7764 BUG_ON(offset > search_start); 7771 BUG_ON(offset > search_start);
7765 7772
7766 ret = btrfs_update_reserved_bytes(block_group, num_bytes, 7773 ret = btrfs_add_reserved_bytes(block_group, ram_bytes,
7767 alloc_type, delalloc); 7774 num_bytes, delalloc);
7768 if (ret == -EAGAIN) { 7775 if (ret == -EAGAIN) {
7769 btrfs_add_free_space(block_group, offset, num_bytes); 7776 btrfs_add_free_space(block_group, offset, num_bytes);
7770 goto loop; 7777 goto loop;
@@ -7936,7 +7943,7 @@ again:
7936 up_read(&info->groups_sem); 7943 up_read(&info->groups_sem);
7937} 7944}
7938 7945
7939int btrfs_reserve_extent(struct btrfs_root *root, 7946int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes,
7940 u64 num_bytes, u64 min_alloc_size, 7947 u64 num_bytes, u64 min_alloc_size,
7941 u64 empty_size, u64 hint_byte, 7948 u64 empty_size, u64 hint_byte,
7942 struct btrfs_key *ins, int is_data, int delalloc) 7949 struct btrfs_key *ins, int is_data, int delalloc)
@@ -7948,8 +7955,8 @@ int btrfs_reserve_extent(struct btrfs_root *root,
7948 flags = btrfs_get_alloc_profile(root, is_data); 7955 flags = btrfs_get_alloc_profile(root, is_data);
7949again: 7956again:
7950 WARN_ON(num_bytes < root->sectorsize); 7957 WARN_ON(num_bytes < root->sectorsize);
7951 ret = find_free_extent(root, num_bytes, empty_size, hint_byte, ins, 7958 ret = find_free_extent(root, ram_bytes, num_bytes, empty_size,
7952 flags, delalloc); 7959 hint_byte, ins, flags, delalloc);
7953 if (!ret && !is_data) { 7960 if (!ret && !is_data) {
7954 btrfs_dec_block_group_reservations(root->fs_info, 7961 btrfs_dec_block_group_reservations(root->fs_info,
7955 ins->objectid); 7962 ins->objectid);
@@ -7958,6 +7965,7 @@ again:
7958 num_bytes = min(num_bytes >> 1, ins->offset); 7965 num_bytes = min(num_bytes >> 1, ins->offset);
7959 num_bytes = round_down(num_bytes, root->sectorsize); 7966 num_bytes = round_down(num_bytes, root->sectorsize);
7960 num_bytes = max(num_bytes, min_alloc_size); 7967 num_bytes = max(num_bytes, min_alloc_size);
7968 ram_bytes = num_bytes;
7961 if (num_bytes == min_alloc_size) 7969 if (num_bytes == min_alloc_size)
7962 final_tried = true; 7970 final_tried = true;
7963 goto again; 7971 goto again;
@@ -7995,7 +8003,7 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root,
7995 if (btrfs_test_opt(root->fs_info, DISCARD)) 8003 if (btrfs_test_opt(root->fs_info, DISCARD))
7996 ret = btrfs_discard_extent(root, start, len, NULL); 8004 ret = btrfs_discard_extent(root, start, len, NULL);
7997 btrfs_add_free_space(cache, start, len); 8005 btrfs_add_free_space(cache, start, len);
7998 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc); 8006 btrfs_free_reserved_bytes(cache, len, delalloc);
7999 trace_btrfs_reserved_extent_free(root, start, len); 8007 trace_btrfs_reserved_extent_free(root, start, len);
8000 } 8008 }
8001 8009
@@ -8223,8 +8231,8 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
8223 if (!block_group) 8231 if (!block_group)
8224 return -EINVAL; 8232 return -EINVAL;
8225 8233
8226 ret = btrfs_update_reserved_bytes(block_group, ins->offset, 8234 ret = btrfs_add_reserved_bytes(block_group, ins->offset,
8227 RESERVE_ALLOC_NO_ACCOUNT, 0); 8235 ins->offset, 0);
8228 BUG_ON(ret); /* logic error */ 8236 BUG_ON(ret); /* logic error */
8229 ret = alloc_reserved_file_extent(trans, root, 0, root_objectid, 8237 ret = alloc_reserved_file_extent(trans, root, 0, root_objectid,
8230 0, owner, offset, ins, 1); 8238 0, owner, offset, ins, 1);
@@ -8368,7 +8376,7 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
8368 if (IS_ERR(block_rsv)) 8376 if (IS_ERR(block_rsv))
8369 return ERR_CAST(block_rsv); 8377 return ERR_CAST(block_rsv);
8370 8378
8371 ret = btrfs_reserve_extent(root, blocksize, blocksize, 8379 ret = btrfs_reserve_extent(root, blocksize, blocksize, blocksize,
8372 empty_size, hint, &ins, 0, 0); 8380 empty_size, hint, &ins, 0, 0);
8373 if (ret) 8381 if (ret)
8374 goto out_unuse; 8382 goto out_unuse;
@@ -8521,35 +8529,6 @@ reada:
8521 wc->reada_slot = slot; 8529 wc->reada_slot = slot;
8522} 8530}
8523 8531
8524/*
8525 * These may not be seen by the usual inc/dec ref code so we have to
8526 * add them here.
8527 */
8528static int record_one_subtree_extent(struct btrfs_trans_handle *trans,
8529 struct btrfs_root *root, u64 bytenr,
8530 u64 num_bytes)
8531{
8532 struct btrfs_qgroup_extent_record *qrecord;
8533 struct btrfs_delayed_ref_root *delayed_refs;
8534
8535 qrecord = kmalloc(sizeof(*qrecord), GFP_NOFS);
8536 if (!qrecord)
8537 return -ENOMEM;
8538
8539 qrecord->bytenr = bytenr;
8540 qrecord->num_bytes = num_bytes;
8541 qrecord->old_roots = NULL;
8542
8543 delayed_refs = &trans->transaction->delayed_refs;
8544 spin_lock(&delayed_refs->lock);
8545 if (btrfs_qgroup_insert_dirty_extent(trans->fs_info,
8546 delayed_refs, qrecord))
8547 kfree(qrecord);
8548 spin_unlock(&delayed_refs->lock);
8549
8550 return 0;
8551}
8552
8553static int account_leaf_items(struct btrfs_trans_handle *trans, 8532static int account_leaf_items(struct btrfs_trans_handle *trans,
8554 struct btrfs_root *root, 8533 struct btrfs_root *root,
8555 struct extent_buffer *eb) 8534 struct extent_buffer *eb)
@@ -8583,7 +8562,8 @@ static int account_leaf_items(struct btrfs_trans_handle *trans,
8583 8562
8584 num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi); 8563 num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi);
8585 8564
8586 ret = record_one_subtree_extent(trans, root, bytenr, num_bytes); 8565 ret = btrfs_qgroup_insert_dirty_extent(trans, root->fs_info,
8566 bytenr, num_bytes, GFP_NOFS);
8587 if (ret) 8567 if (ret)
8588 return ret; 8568 return ret;
8589 } 8569 }
@@ -8732,8 +8712,9 @@ walk_down:
8732 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 8712 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
8733 path->locks[level] = BTRFS_READ_LOCK_BLOCKING; 8713 path->locks[level] = BTRFS_READ_LOCK_BLOCKING;
8734 8714
8735 ret = record_one_subtree_extent(trans, root, child_bytenr, 8715 ret = btrfs_qgroup_insert_dirty_extent(trans,
8736 root->nodesize); 8716 root->fs_info, child_bytenr,
8717 root->nodesize, GFP_NOFS);
8737 if (ret) 8718 if (ret)
8738 goto out; 8719 goto out;
8739 } 8720 }
@@ -9906,6 +9887,7 @@ static int find_first_block_group(struct btrfs_root *root,
9906 } else { 9887 } else {
9907 ret = 0; 9888 ret = 0;
9908 } 9889 }
9890 free_extent_map(em);
9909 goto out; 9891 goto out;
9910 } 9892 }
9911 path->slots[0]++; 9893 path->slots[0]++;
@@ -9942,6 +9924,7 @@ void btrfs_put_block_group_cache(struct btrfs_fs_info *info)
9942 block_group->iref = 0; 9924 block_group->iref = 0;
9943 block_group->inode = NULL; 9925 block_group->inode = NULL;
9944 spin_unlock(&block_group->lock); 9926 spin_unlock(&block_group->lock);
9927 ASSERT(block_group->io_ctl.inode == NULL);
9945 iput(inode); 9928 iput(inode);
9946 last = block_group->key.objectid + block_group->key.offset; 9929 last = block_group->key.objectid + block_group->key.offset;
9947 btrfs_put_block_group(block_group); 9930 btrfs_put_block_group(block_group);
@@ -9999,6 +9982,10 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
9999 free_excluded_extents(info->extent_root, block_group); 9982 free_excluded_extents(info->extent_root, block_group);
10000 9983
10001 btrfs_remove_free_space_cache(block_group); 9984 btrfs_remove_free_space_cache(block_group);
9985 ASSERT(list_empty(&block_group->dirty_list));
9986 ASSERT(list_empty(&block_group->io_list));
9987 ASSERT(list_empty(&block_group->bg_list));
9988 ASSERT(atomic_read(&block_group->count) == 1);
10002 btrfs_put_block_group(block_group); 9989 btrfs_put_block_group(block_group);
10003 9990
10004 spin_lock(&info->block_group_cache_lock); 9991 spin_lock(&info->block_group_cache_lock);
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index bc2729a7612d..28cd88fccc7e 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -20,6 +20,7 @@
20#define EXTENT_DAMAGED (1U << 14) 20#define EXTENT_DAMAGED (1U << 14)
21#define EXTENT_NORESERVE (1U << 15) 21#define EXTENT_NORESERVE (1U << 15)
22#define EXTENT_QGROUP_RESERVED (1U << 16) 22#define EXTENT_QGROUP_RESERVED (1U << 16)
23#define EXTENT_CLEAR_DATA_RESV (1U << 17)
23#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) 24#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
24#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC) 25#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
25 26
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 9404121fd5f7..fea31a4a6e36 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2033,6 +2033,14 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
2033 */ 2033 */
2034 clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 2034 clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
2035 &BTRFS_I(inode)->runtime_flags); 2035 &BTRFS_I(inode)->runtime_flags);
2036 /*
2037 * An ordered extent might have started before and completed
2038 * already with io errors, in which case the inode was not
2039 * updated and we end up here. So check the inode's mapping
2040 * flags for any errors that might have happened while doing
2041 * writeback of file data.
2042 */
2043 ret = btrfs_inode_check_errors(inode);
2036 inode_unlock(inode); 2044 inode_unlock(inode);
2037 goto out; 2045 goto out;
2038 } 2046 }
@@ -2062,7 +2070,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
2062 } 2070 }
2063 trans->sync = true; 2071 trans->sync = true;
2064 2072
2065 btrfs_init_log_ctx(&ctx); 2073 btrfs_init_log_ctx(&ctx, inode);
2066 2074
2067 ret = btrfs_log_dentry_safe(trans, root, dentry, start, end, &ctx); 2075 ret = btrfs_log_dentry_safe(trans, root, dentry, start, end, &ctx);
2068 if (ret < 0) { 2076 if (ret < 0) {
@@ -2667,6 +2675,7 @@ static long btrfs_fallocate(struct file *file, int mode,
2667 2675
2668 alloc_start = round_down(offset, blocksize); 2676 alloc_start = round_down(offset, blocksize);
2669 alloc_end = round_up(offset + len, blocksize); 2677 alloc_end = round_up(offset + len, blocksize);
2678 cur_offset = alloc_start;
2670 2679
2671 /* Make sure we aren't being give some crap mode */ 2680 /* Make sure we aren't being give some crap mode */
2672 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) 2681 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
@@ -2759,7 +2768,6 @@ static long btrfs_fallocate(struct file *file, int mode,
2759 2768
2760 /* First, check if we exceed the qgroup limit */ 2769 /* First, check if we exceed the qgroup limit */
2761 INIT_LIST_HEAD(&reserve_list); 2770 INIT_LIST_HEAD(&reserve_list);
2762 cur_offset = alloc_start;
2763 while (1) { 2771 while (1) {
2764 em = btrfs_get_extent(inode, NULL, 0, cur_offset, 2772 em = btrfs_get_extent(inode, NULL, 0, cur_offset,
2765 alloc_end - cur_offset, 0); 2773 alloc_end - cur_offset, 0);
@@ -2786,6 +2794,14 @@ static long btrfs_fallocate(struct file *file, int mode,
2786 last_byte - cur_offset); 2794 last_byte - cur_offset);
2787 if (ret < 0) 2795 if (ret < 0)
2788 break; 2796 break;
2797 } else {
2798 /*
2799 * Do not need to reserve unwritten extent for this
2800 * range, free reserved data space first, otherwise
2801 * it'll result in false ENOSPC error.
2802 */
2803 btrfs_free_reserved_data_space(inode, cur_offset,
2804 last_byte - cur_offset);
2789 } 2805 }
2790 free_extent_map(em); 2806 free_extent_map(em);
2791 cur_offset = last_byte; 2807 cur_offset = last_byte;
@@ -2803,6 +2819,9 @@ static long btrfs_fallocate(struct file *file, int mode,
2803 range->start, 2819 range->start,
2804 range->len, 1 << inode->i_blkbits, 2820 range->len, 1 << inode->i_blkbits,
2805 offset + len, &alloc_hint); 2821 offset + len, &alloc_hint);
2822 else
2823 btrfs_free_reserved_data_space(inode, range->start,
2824 range->len);
2806 list_del(&range->list); 2825 list_del(&range->list);
2807 kfree(range); 2826 kfree(range);
2808 } 2827 }
@@ -2837,18 +2856,11 @@ out_unlock:
2837 unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, 2856 unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end,
2838 &cached_state, GFP_KERNEL); 2857 &cached_state, GFP_KERNEL);
2839out: 2858out:
2840 /*
2841 * As we waited the extent range, the data_rsv_map must be empty
2842 * in the range, as written data range will be released from it.
2843 * And for prealloacted extent, it will also be released when
2844 * its metadata is written.
2845 * So this is completely used as cleanup.
2846 */
2847 btrfs_qgroup_free_data(inode, alloc_start, alloc_end - alloc_start);
2848 inode_unlock(inode); 2859 inode_unlock(inode);
2849 /* Let go of our reservation. */ 2860 /* Let go of our reservation. */
2850 btrfs_free_reserved_data_space(inode, alloc_start, 2861 if (ret != 0)
2851 alloc_end - alloc_start); 2862 btrfs_free_reserved_data_space(inode, alloc_start,
2863 alloc_end - cur_offset);
2852 return ret; 2864 return ret;
2853} 2865}
2854 2866
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index aa6fabaee72e..359ee861b5a4 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -495,10 +495,9 @@ again:
495 ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, prealloc, 495 ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, prealloc,
496 prealloc, prealloc, &alloc_hint); 496 prealloc, prealloc, &alloc_hint);
497 if (ret) { 497 if (ret) {
498 btrfs_delalloc_release_space(inode, 0, prealloc); 498 btrfs_delalloc_release_metadata(inode, prealloc);
499 goto out_put; 499 goto out_put;
500 } 500 }
501 btrfs_free_reserved_data_space(inode, 0, prealloc);
502 501
503 ret = btrfs_write_out_ino_cache(root, trans, path, inode); 502 ret = btrfs_write_out_ino_cache(root, trans, path, inode);
504out_put: 503out_put:
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2f5975954ccf..e6811c42e41e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -566,6 +566,8 @@ cont:
566 PAGE_SET_WRITEBACK | 566 PAGE_SET_WRITEBACK |
567 page_error_op | 567 page_error_op |
568 PAGE_END_WRITEBACK); 568 PAGE_END_WRITEBACK);
569 btrfs_free_reserved_data_space_noquota(inode, start,
570 end - start + 1);
569 goto free_pages_out; 571 goto free_pages_out;
570 } 572 }
571 } 573 }
@@ -742,7 +744,7 @@ retry:
742 lock_extent(io_tree, async_extent->start, 744 lock_extent(io_tree, async_extent->start,
743 async_extent->start + async_extent->ram_size - 1); 745 async_extent->start + async_extent->ram_size - 1);
744 746
745 ret = btrfs_reserve_extent(root, 747 ret = btrfs_reserve_extent(root, async_extent->ram_size,
746 async_extent->compressed_size, 748 async_extent->compressed_size,
747 async_extent->compressed_size, 749 async_extent->compressed_size,
748 0, alloc_hint, &ins, 1, 1); 750 0, alloc_hint, &ins, 1, 1);
@@ -969,7 +971,8 @@ static noinline int cow_file_range(struct inode *inode,
969 EXTENT_DEFRAG, PAGE_UNLOCK | 971 EXTENT_DEFRAG, PAGE_UNLOCK |
970 PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK | 972 PAGE_CLEAR_DIRTY | PAGE_SET_WRITEBACK |
971 PAGE_END_WRITEBACK); 973 PAGE_END_WRITEBACK);
972 974 btrfs_free_reserved_data_space_noquota(inode, start,
975 end - start + 1);
973 *nr_written = *nr_written + 976 *nr_written = *nr_written +
974 (end - start + PAGE_SIZE) / PAGE_SIZE; 977 (end - start + PAGE_SIZE) / PAGE_SIZE;
975 *page_started = 1; 978 *page_started = 1;
@@ -989,7 +992,7 @@ static noinline int cow_file_range(struct inode *inode,
989 unsigned long op; 992 unsigned long op;
990 993
991 cur_alloc_size = disk_num_bytes; 994 cur_alloc_size = disk_num_bytes;
992 ret = btrfs_reserve_extent(root, cur_alloc_size, 995 ret = btrfs_reserve_extent(root, cur_alloc_size, cur_alloc_size,
993 root->sectorsize, 0, alloc_hint, 996 root->sectorsize, 0, alloc_hint,
994 &ins, 1, 1); 997 &ins, 1, 1);
995 if (ret < 0) 998 if (ret < 0)
@@ -1489,8 +1492,10 @@ out_check:
1489 extent_clear_unlock_delalloc(inode, cur_offset, 1492 extent_clear_unlock_delalloc(inode, cur_offset,
1490 cur_offset + num_bytes - 1, 1493 cur_offset + num_bytes - 1,
1491 locked_page, EXTENT_LOCKED | 1494 locked_page, EXTENT_LOCKED |
1492 EXTENT_DELALLOC, PAGE_UNLOCK | 1495 EXTENT_DELALLOC |
1493 PAGE_SET_PRIVATE2); 1496 EXTENT_CLEAR_DATA_RESV,
1497 PAGE_UNLOCK | PAGE_SET_PRIVATE2);
1498
1494 if (!nolock && nocow) 1499 if (!nolock && nocow)
1495 btrfs_end_write_no_snapshoting(root); 1500 btrfs_end_write_no_snapshoting(root);
1496 cur_offset = extent_end; 1501 cur_offset = extent_end;
@@ -1807,7 +1812,9 @@ static void btrfs_clear_bit_hook(struct inode *inode,
1807 return; 1812 return;
1808 1813
1809 if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID 1814 if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
1810 && do_list && !(state->state & EXTENT_NORESERVE)) 1815 && do_list && !(state->state & EXTENT_NORESERVE)
1816 && (*bits & (EXTENT_DO_ACCOUNTING |
1817 EXTENT_CLEAR_DATA_RESV)))
1811 btrfs_free_reserved_data_space_noquota(inode, 1818 btrfs_free_reserved_data_space_noquota(inode,
1812 state->start, len); 1819 state->start, len);
1813 1820
@@ -3435,10 +3442,10 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
3435 found_key.offset = 0; 3442 found_key.offset = 0;
3436 inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL); 3443 inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL);
3437 ret = PTR_ERR_OR_ZERO(inode); 3444 ret = PTR_ERR_OR_ZERO(inode);
3438 if (ret && ret != -ESTALE) 3445 if (ret && ret != -ENOENT)
3439 goto out; 3446 goto out;
3440 3447
3441 if (ret == -ESTALE && root == root->fs_info->tree_root) { 3448 if (ret == -ENOENT && root == root->fs_info->tree_root) {
3442 struct btrfs_root *dead_root; 3449 struct btrfs_root *dead_root;
3443 struct btrfs_fs_info *fs_info = root->fs_info; 3450 struct btrfs_fs_info *fs_info = root->fs_info;
3444 int is_dead_root = 0; 3451 int is_dead_root = 0;
@@ -3474,7 +3481,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
3474 * Inode is already gone but the orphan item is still there, 3481 * Inode is already gone but the orphan item is still there,
3475 * kill the orphan item. 3482 * kill the orphan item.
3476 */ 3483 */
3477 if (ret == -ESTALE) { 3484 if (ret == -ENOENT) {
3478 trans = btrfs_start_transaction(root, 1); 3485 trans = btrfs_start_transaction(root, 1);
3479 if (IS_ERR(trans)) { 3486 if (IS_ERR(trans)) {
3480 ret = PTR_ERR(trans); 3487 ret = PTR_ERR(trans);
@@ -3633,7 +3640,7 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
3633/* 3640/*
3634 * read an inode from the btree into the in-memory inode 3641 * read an inode from the btree into the in-memory inode
3635 */ 3642 */
3636static void btrfs_read_locked_inode(struct inode *inode) 3643static int btrfs_read_locked_inode(struct inode *inode)
3637{ 3644{
3638 struct btrfs_path *path; 3645 struct btrfs_path *path;
3639 struct extent_buffer *leaf; 3646 struct extent_buffer *leaf;
@@ -3652,14 +3659,19 @@ static void btrfs_read_locked_inode(struct inode *inode)
3652 filled = true; 3659 filled = true;
3653 3660
3654 path = btrfs_alloc_path(); 3661 path = btrfs_alloc_path();
3655 if (!path) 3662 if (!path) {
3663 ret = -ENOMEM;
3656 goto make_bad; 3664 goto make_bad;
3665 }
3657 3666
3658 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); 3667 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
3659 3668
3660 ret = btrfs_lookup_inode(NULL, root, path, &location, 0); 3669 ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
3661 if (ret) 3670 if (ret) {
3671 if (ret > 0)
3672 ret = -ENOENT;
3662 goto make_bad; 3673 goto make_bad;
3674 }
3663 3675
3664 leaf = path->nodes[0]; 3676 leaf = path->nodes[0];
3665 3677
@@ -3812,11 +3824,12 @@ cache_acl:
3812 } 3824 }
3813 3825
3814 btrfs_update_iflags(inode); 3826 btrfs_update_iflags(inode);
3815 return; 3827 return 0;
3816 3828
3817make_bad: 3829make_bad:
3818 btrfs_free_path(path); 3830 btrfs_free_path(path);
3819 make_bad_inode(inode); 3831 make_bad_inode(inode);
3832 return ret;
3820} 3833}
3821 3834
3822/* 3835/*
@@ -4204,6 +4217,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4204 int err = 0; 4217 int err = 0;
4205 struct btrfs_root *root = BTRFS_I(dir)->root; 4218 struct btrfs_root *root = BTRFS_I(dir)->root;
4206 struct btrfs_trans_handle *trans; 4219 struct btrfs_trans_handle *trans;
4220 u64 last_unlink_trans;
4207 4221
4208 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE) 4222 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
4209 return -ENOTEMPTY; 4223 return -ENOTEMPTY;
@@ -4226,11 +4240,27 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4226 if (err) 4240 if (err)
4227 goto out; 4241 goto out;
4228 4242
4243 last_unlink_trans = BTRFS_I(inode)->last_unlink_trans;
4244
4229 /* now the directory is empty */ 4245 /* now the directory is empty */
4230 err = btrfs_unlink_inode(trans, root, dir, d_inode(dentry), 4246 err = btrfs_unlink_inode(trans, root, dir, d_inode(dentry),
4231 dentry->d_name.name, dentry->d_name.len); 4247 dentry->d_name.name, dentry->d_name.len);
4232 if (!err) 4248 if (!err) {
4233 btrfs_i_size_write(inode, 0); 4249 btrfs_i_size_write(inode, 0);
4250 /*
4251 * Propagate the last_unlink_trans value of the deleted dir to
4252 * its parent directory. This is to prevent an unrecoverable
4253 * log tree in the case we do something like this:
4254 * 1) create dir foo
4255 * 2) create snapshot under dir foo
4256 * 3) delete the snapshot
4257 * 4) rmdir foo
4258 * 5) mkdir foo
4259 * 6) fsync foo or some file inside foo
4260 */
4261 if (last_unlink_trans >= trans->transid)
4262 BTRFS_I(dir)->last_unlink_trans = last_unlink_trans;
4263 }
4234out: 4264out:
4235 btrfs_end_transaction(trans, root); 4265 btrfs_end_transaction(trans, root);
4236 btrfs_btree_balance_dirty(root); 4266 btrfs_btree_balance_dirty(root);
@@ -5606,7 +5636,9 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
5606 return ERR_PTR(-ENOMEM); 5636 return ERR_PTR(-ENOMEM);
5607 5637
5608 if (inode->i_state & I_NEW) { 5638 if (inode->i_state & I_NEW) {
5609 btrfs_read_locked_inode(inode); 5639 int ret;
5640
5641 ret = btrfs_read_locked_inode(inode);
5610 if (!is_bad_inode(inode)) { 5642 if (!is_bad_inode(inode)) {
5611 inode_tree_add(inode); 5643 inode_tree_add(inode);
5612 unlock_new_inode(inode); 5644 unlock_new_inode(inode);
@@ -5615,7 +5647,8 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
5615 } else { 5647 } else {
5616 unlock_new_inode(inode); 5648 unlock_new_inode(inode);
5617 iput(inode); 5649 iput(inode);
5618 inode = ERR_PTR(-ESTALE); 5650 ASSERT(ret < 0);
5651 inode = ERR_PTR(ret < 0 ? ret : -ESTALE);
5619 } 5652 }
5620 } 5653 }
5621 5654
@@ -7225,7 +7258,7 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode,
7225 int ret; 7258 int ret;
7226 7259
7227 alloc_hint = get_extent_allocation_hint(inode, start, len); 7260 alloc_hint = get_extent_allocation_hint(inode, start, len);
7228 ret = btrfs_reserve_extent(root, len, root->sectorsize, 0, 7261 ret = btrfs_reserve_extent(root, len, len, root->sectorsize, 0,
7229 alloc_hint, &ins, 1, 1); 7262 alloc_hint, &ins, 1, 1);
7230 if (ret) 7263 if (ret)
7231 return ERR_PTR(ret); 7264 return ERR_PTR(ret);
@@ -7725,6 +7758,13 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
7725 ret = PTR_ERR(em2); 7758 ret = PTR_ERR(em2);
7726 goto unlock_err; 7759 goto unlock_err;
7727 } 7760 }
7761 /*
7762 * For inode marked NODATACOW or extent marked PREALLOC,
7763 * use the existing or preallocated extent, so does not
7764 * need to adjust btrfs_space_info's bytes_may_use.
7765 */
7766 btrfs_free_reserved_data_space_noquota(inode,
7767 start, len);
7728 goto unlock; 7768 goto unlock;
7729 } 7769 }
7730 } 7770 }
@@ -7759,7 +7799,6 @@ unlock:
7759 i_size_write(inode, start + len); 7799 i_size_write(inode, start + len);
7760 7800
7761 adjust_dio_outstanding_extents(inode, dio_data, len); 7801 adjust_dio_outstanding_extents(inode, dio_data, len);
7762 btrfs_free_reserved_data_space(inode, start, len);
7763 WARN_ON(dio_data->reserve < len); 7802 WARN_ON(dio_data->reserve < len);
7764 dio_data->reserve -= len; 7803 dio_data->reserve -= len;
7765 dio_data->unsubmitted_oe_range_end = start + len; 7804 dio_data->unsubmitted_oe_range_end = start + len;
@@ -10280,6 +10319,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
10280 u64 last_alloc = (u64)-1; 10319 u64 last_alloc = (u64)-1;
10281 int ret = 0; 10320 int ret = 0;
10282 bool own_trans = true; 10321 bool own_trans = true;
10322 u64 end = start + num_bytes - 1;
10283 10323
10284 if (trans) 10324 if (trans)
10285 own_trans = false; 10325 own_trans = false;
@@ -10301,8 +10341,8 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
10301 * sized chunks. 10341 * sized chunks.
10302 */ 10342 */
10303 cur_bytes = min(cur_bytes, last_alloc); 10343 cur_bytes = min(cur_bytes, last_alloc);
10304 ret = btrfs_reserve_extent(root, cur_bytes, min_size, 0, 10344 ret = btrfs_reserve_extent(root, cur_bytes, cur_bytes,
10305 *alloc_hint, &ins, 1, 0); 10345 min_size, 0, *alloc_hint, &ins, 1, 0);
10306 if (ret) { 10346 if (ret) {
10307 if (own_trans) 10347 if (own_trans)
10308 btrfs_end_transaction(trans, root); 10348 btrfs_end_transaction(trans, root);
@@ -10388,6 +10428,9 @@ next:
10388 if (own_trans) 10428 if (own_trans)
10389 btrfs_end_transaction(trans, root); 10429 btrfs_end_transaction(trans, root);
10390 } 10430 }
10431 if (cur_offset < end)
10432 btrfs_free_reserved_data_space(inode, cur_offset,
10433 end - cur_offset + 1);
10391 return ret; 10434 return ret;
10392} 10435}
10393 10436
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 14ed1e9e6bc8..b2a2da5893af 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -5084,7 +5084,7 @@ static long btrfs_ioctl_quota_rescan_wait(struct file *file, void __user *arg)
5084 if (!capable(CAP_SYS_ADMIN)) 5084 if (!capable(CAP_SYS_ADMIN))
5085 return -EPERM; 5085 return -EPERM;
5086 5086
5087 return btrfs_qgroup_wait_for_completion(root->fs_info); 5087 return btrfs_qgroup_wait_for_completion(root->fs_info, true);
5088} 5088}
5089 5089
5090static long _btrfs_ioctl_set_received_subvol(struct file *file, 5090static long _btrfs_ioctl_set_received_subvol(struct file *file,
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 93ee1c18ef9d..8db2e29fdcf4 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -995,7 +995,7 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
995 goto out; 995 goto out;
996 fs_info->quota_enabled = 0; 996 fs_info->quota_enabled = 0;
997 fs_info->pending_quota_state = 0; 997 fs_info->pending_quota_state = 0;
998 btrfs_qgroup_wait_for_completion(fs_info); 998 btrfs_qgroup_wait_for_completion(fs_info, false);
999 spin_lock(&fs_info->qgroup_lock); 999 spin_lock(&fs_info->qgroup_lock);
1000 quota_root = fs_info->quota_root; 1000 quota_root = fs_info->quota_root;
1001 fs_info->quota_root = NULL; 1001 fs_info->quota_root = NULL;
@@ -1453,10 +1453,9 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
1453 return ret; 1453 return ret;
1454} 1454}
1455 1455
1456struct btrfs_qgroup_extent_record * 1456int btrfs_qgroup_insert_dirty_extent_nolock(struct btrfs_fs_info *fs_info,
1457btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info, 1457 struct btrfs_delayed_ref_root *delayed_refs,
1458 struct btrfs_delayed_ref_root *delayed_refs, 1458 struct btrfs_qgroup_extent_record *record)
1459 struct btrfs_qgroup_extent_record *record)
1460{ 1459{
1461 struct rb_node **p = &delayed_refs->dirty_extent_root.rb_node; 1460 struct rb_node **p = &delayed_refs->dirty_extent_root.rb_node;
1462 struct rb_node *parent_node = NULL; 1461 struct rb_node *parent_node = NULL;
@@ -1475,12 +1474,42 @@ btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info,
1475 else if (bytenr > entry->bytenr) 1474 else if (bytenr > entry->bytenr)
1476 p = &(*p)->rb_right; 1475 p = &(*p)->rb_right;
1477 else 1476 else
1478 return entry; 1477 return 1;
1479 } 1478 }
1480 1479
1481 rb_link_node(&record->node, parent_node, p); 1480 rb_link_node(&record->node, parent_node, p);
1482 rb_insert_color(&record->node, &delayed_refs->dirty_extent_root); 1481 rb_insert_color(&record->node, &delayed_refs->dirty_extent_root);
1483 return NULL; 1482 return 0;
1483}
1484
1485int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans,
1486 struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes,
1487 gfp_t gfp_flag)
1488{
1489 struct btrfs_qgroup_extent_record *record;
1490 struct btrfs_delayed_ref_root *delayed_refs;
1491 int ret;
1492
1493 if (!fs_info->quota_enabled || bytenr == 0 || num_bytes == 0)
1494 return 0;
1495 if (WARN_ON(trans == NULL))
1496 return -EINVAL;
1497 record = kmalloc(sizeof(*record), gfp_flag);
1498 if (!record)
1499 return -ENOMEM;
1500
1501 delayed_refs = &trans->transaction->delayed_refs;
1502 record->bytenr = bytenr;
1503 record->num_bytes = num_bytes;
1504 record->old_roots = NULL;
1505
1506 spin_lock(&delayed_refs->lock);
1507 ret = btrfs_qgroup_insert_dirty_extent_nolock(fs_info, delayed_refs,
1508 record);
1509 spin_unlock(&delayed_refs->lock);
1510 if (ret > 0)
1511 kfree(record);
1512 return 0;
1484} 1513}
1485 1514
1486#define UPDATE_NEW 0 1515#define UPDATE_NEW 0
@@ -2303,6 +2332,10 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
2303 int err = -ENOMEM; 2332 int err = -ENOMEM;
2304 int ret = 0; 2333 int ret = 0;
2305 2334
2335 mutex_lock(&fs_info->qgroup_rescan_lock);
2336 fs_info->qgroup_rescan_running = true;
2337 mutex_unlock(&fs_info->qgroup_rescan_lock);
2338
2306 path = btrfs_alloc_path(); 2339 path = btrfs_alloc_path();
2307 if (!path) 2340 if (!path)
2308 goto out; 2341 goto out;
@@ -2369,6 +2402,9 @@ out:
2369 } 2402 }
2370 2403
2371done: 2404done:
2405 mutex_lock(&fs_info->qgroup_rescan_lock);
2406 fs_info->qgroup_rescan_running = false;
2407 mutex_unlock(&fs_info->qgroup_rescan_lock);
2372 complete_all(&fs_info->qgroup_rescan_completion); 2408 complete_all(&fs_info->qgroup_rescan_completion);
2373} 2409}
2374 2410
@@ -2487,20 +2523,26 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info)
2487 return 0; 2523 return 0;
2488} 2524}
2489 2525
2490int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info) 2526int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info,
2527 bool interruptible)
2491{ 2528{
2492 int running; 2529 int running;
2493 int ret = 0; 2530 int ret = 0;
2494 2531
2495 mutex_lock(&fs_info->qgroup_rescan_lock); 2532 mutex_lock(&fs_info->qgroup_rescan_lock);
2496 spin_lock(&fs_info->qgroup_lock); 2533 spin_lock(&fs_info->qgroup_lock);
2497 running = fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN; 2534 running = fs_info->qgroup_rescan_running;
2498 spin_unlock(&fs_info->qgroup_lock); 2535 spin_unlock(&fs_info->qgroup_lock);
2499 mutex_unlock(&fs_info->qgroup_rescan_lock); 2536 mutex_unlock(&fs_info->qgroup_rescan_lock);
2500 2537
2501 if (running) 2538 if (!running)
2539 return 0;
2540
2541 if (interruptible)
2502 ret = wait_for_completion_interruptible( 2542 ret = wait_for_completion_interruptible(
2503 &fs_info->qgroup_rescan_completion); 2543 &fs_info->qgroup_rescan_completion);
2544 else
2545 wait_for_completion(&fs_info->qgroup_rescan_completion);
2504 2546
2505 return ret; 2547 return ret;
2506} 2548}
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h
index 710887c06aaf..1bc64c864b62 100644
--- a/fs/btrfs/qgroup.h
+++ b/fs/btrfs/qgroup.h
@@ -46,7 +46,8 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
46 struct btrfs_fs_info *fs_info); 46 struct btrfs_fs_info *fs_info);
47int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info); 47int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info);
48void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info); 48void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info);
49int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info); 49int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info,
50 bool interruptible);
50int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, 51int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
51 struct btrfs_fs_info *fs_info, u64 src, u64 dst); 52 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
52int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, 53int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
@@ -63,10 +64,35 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
63struct btrfs_delayed_extent_op; 64struct btrfs_delayed_extent_op;
64int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, 65int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
65 struct btrfs_fs_info *fs_info); 66 struct btrfs_fs_info *fs_info);
66struct btrfs_qgroup_extent_record * 67/*
67btrfs_qgroup_insert_dirty_extent(struct btrfs_fs_info *fs_info, 68 * Insert one dirty extent record into @delayed_refs, informing qgroup to
68 struct btrfs_delayed_ref_root *delayed_refs, 69 * account that extent at commit trans time.
69 struct btrfs_qgroup_extent_record *record); 70 *
71 * No lock version, caller must acquire delayed ref lock and allocate memory.
72 *
73 * Return 0 for success insert
74 * Return >0 for existing record, caller can free @record safely.
75 * Error is not possible
76 */
77int btrfs_qgroup_insert_dirty_extent_nolock(
78 struct btrfs_fs_info *fs_info,
79 struct btrfs_delayed_ref_root *delayed_refs,
80 struct btrfs_qgroup_extent_record *record);
81
82/*
83 * Insert one dirty extent record into @delayed_refs, informing qgroup to
84 * account that extent at commit trans time.
85 *
86 * Better encapsulated version.
87 *
88 * Return 0 if the operation is done.
89 * Return <0 for error, like memory allocation failure or invalid parameter
90 * (NULL trans)
91 */
92int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans,
93 struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes,
94 gfp_t gfp_flag);
95
70int 96int
71btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, 97btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
72 struct btrfs_fs_info *fs_info, 98 struct btrfs_fs_info *fs_info,
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b26a5aea41b4..8a2c2a07987b 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -31,6 +31,7 @@
31#include "async-thread.h" 31#include "async-thread.h"
32#include "free-space-cache.h" 32#include "free-space-cache.h"
33#include "inode-map.h" 33#include "inode-map.h"
34#include "qgroup.h"
34 35
35/* 36/*
36 * backref_node, mapping_node and tree_block start with this 37 * backref_node, mapping_node and tree_block start with this
@@ -3037,15 +3038,19 @@ int prealloc_file_extent_cluster(struct inode *inode,
3037 u64 num_bytes; 3038 u64 num_bytes;
3038 int nr = 0; 3039 int nr = 0;
3039 int ret = 0; 3040 int ret = 0;
3041 u64 prealloc_start = cluster->start - offset;
3042 u64 prealloc_end = cluster->end - offset;
3043 u64 cur_offset;
3040 3044
3041 BUG_ON(cluster->start != cluster->boundary[0]); 3045 BUG_ON(cluster->start != cluster->boundary[0]);
3042 inode_lock(inode); 3046 inode_lock(inode);
3043 3047
3044 ret = btrfs_check_data_free_space(inode, cluster->start, 3048 ret = btrfs_check_data_free_space(inode, prealloc_start,
3045 cluster->end + 1 - cluster->start); 3049 prealloc_end + 1 - prealloc_start);
3046 if (ret) 3050 if (ret)
3047 goto out; 3051 goto out;
3048 3052
3053 cur_offset = prealloc_start;
3049 while (nr < cluster->nr) { 3054 while (nr < cluster->nr) {
3050 start = cluster->boundary[nr] - offset; 3055 start = cluster->boundary[nr] - offset;
3051 if (nr + 1 < cluster->nr) 3056 if (nr + 1 < cluster->nr)
@@ -3055,16 +3060,21 @@ int prealloc_file_extent_cluster(struct inode *inode,
3055 3060
3056 lock_extent(&BTRFS_I(inode)->io_tree, start, end); 3061 lock_extent(&BTRFS_I(inode)->io_tree, start, end);
3057 num_bytes = end + 1 - start; 3062 num_bytes = end + 1 - start;
3063 if (cur_offset < start)
3064 btrfs_free_reserved_data_space(inode, cur_offset,
3065 start - cur_offset);
3058 ret = btrfs_prealloc_file_range(inode, 0, start, 3066 ret = btrfs_prealloc_file_range(inode, 0, start,
3059 num_bytes, num_bytes, 3067 num_bytes, num_bytes,
3060 end + 1, &alloc_hint); 3068 end + 1, &alloc_hint);
3069 cur_offset = end + 1;
3061 unlock_extent(&BTRFS_I(inode)->io_tree, start, end); 3070 unlock_extent(&BTRFS_I(inode)->io_tree, start, end);
3062 if (ret) 3071 if (ret)
3063 break; 3072 break;
3064 nr++; 3073 nr++;
3065 } 3074 }
3066 btrfs_free_reserved_data_space(inode, cluster->start, 3075 if (cur_offset < prealloc_end)
3067 cluster->end + 1 - cluster->start); 3076 btrfs_free_reserved_data_space(inode, cur_offset,
3077 prealloc_end + 1 - cur_offset);
3068out: 3078out:
3069 inode_unlock(inode); 3079 inode_unlock(inode);
3070 return ret; 3080 return ret;
@@ -3916,6 +3926,90 @@ int prepare_to_relocate(struct reloc_control *rc)
3916 return 0; 3926 return 0;
3917} 3927}
3918 3928
3929/*
3930 * Qgroup fixer for data chunk relocation.
3931 * The data relocation is done in the following steps
3932 * 1) Copy data extents into data reloc tree
3933 * 2) Create tree reloc tree(special snapshot) for related subvolumes
3934 * 3) Modify file extents in tree reloc tree
3935 * 4) Merge tree reloc tree with original fs tree, by swapping tree blocks
3936 *
3937 * The problem is, data and tree reloc tree are not accounted to qgroup,
3938 * and 4) will only info qgroup to track tree blocks change, not file extents
3939 * in the tree blocks.
3940 *
3941 * The good news is, related data extents are all in data reloc tree, so we
3942 * only need to info qgroup to track all file extents in data reloc tree
3943 * before commit trans.
3944 */
3945static int qgroup_fix_relocated_data_extents(struct btrfs_trans_handle *trans,
3946 struct reloc_control *rc)
3947{
3948 struct btrfs_fs_info *fs_info = rc->extent_root->fs_info;
3949 struct inode *inode = rc->data_inode;
3950 struct btrfs_root *data_reloc_root = BTRFS_I(inode)->root;
3951 struct btrfs_path *path;
3952 struct btrfs_key key;
3953 int ret = 0;
3954
3955 if (!fs_info->quota_enabled)
3956 return 0;
3957
3958 /*
3959 * Only for stage where we update data pointers the qgroup fix is
3960 * valid.
3961 * For MOVING_DATA stage, we will miss the timing of swapping tree
3962 * blocks, and won't fix it.
3963 */
3964 if (!(rc->stage == UPDATE_DATA_PTRS && rc->extents_found))
3965 return 0;
3966
3967 path = btrfs_alloc_path();
3968 if (!path)
3969 return -ENOMEM;
3970 key.objectid = btrfs_ino(inode);
3971 key.type = BTRFS_EXTENT_DATA_KEY;
3972 key.offset = 0;
3973
3974 ret = btrfs_search_slot(NULL, data_reloc_root, &key, path, 0, 0);
3975 if (ret < 0)
3976 goto out;
3977
3978 lock_extent(&BTRFS_I(inode)->io_tree, 0, (u64)-1);
3979 while (1) {
3980 struct btrfs_file_extent_item *fi;
3981
3982 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
3983 if (key.objectid > btrfs_ino(inode))
3984 break;
3985 if (key.type != BTRFS_EXTENT_DATA_KEY)
3986 goto next;
3987 fi = btrfs_item_ptr(path->nodes[0], path->slots[0],
3988 struct btrfs_file_extent_item);
3989 if (btrfs_file_extent_type(path->nodes[0], fi) !=
3990 BTRFS_FILE_EXTENT_REG)
3991 goto next;
3992 ret = btrfs_qgroup_insert_dirty_extent(trans, fs_info,
3993 btrfs_file_extent_disk_bytenr(path->nodes[0], fi),
3994 btrfs_file_extent_disk_num_bytes(path->nodes[0], fi),
3995 GFP_NOFS);
3996 if (ret < 0)
3997 break;
3998next:
3999 ret = btrfs_next_item(data_reloc_root, path);
4000 if (ret < 0)
4001 break;
4002 if (ret > 0) {
4003 ret = 0;
4004 break;
4005 }
4006 }
4007 unlock_extent(&BTRFS_I(inode)->io_tree, 0 , (u64)-1);
4008out:
4009 btrfs_free_path(path);
4010 return ret;
4011}
4012
3919static noinline_for_stack int relocate_block_group(struct reloc_control *rc) 4013static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
3920{ 4014{
3921 struct rb_root blocks = RB_ROOT; 4015 struct rb_root blocks = RB_ROOT;
@@ -4102,10 +4196,16 @@ restart:
4102 4196
4103 /* get rid of pinned extents */ 4197 /* get rid of pinned extents */
4104 trans = btrfs_join_transaction(rc->extent_root); 4198 trans = btrfs_join_transaction(rc->extent_root);
4105 if (IS_ERR(trans)) 4199 if (IS_ERR(trans)) {
4106 err = PTR_ERR(trans); 4200 err = PTR_ERR(trans);
4107 else 4201 goto out_free;
4108 btrfs_commit_transaction(trans, rc->extent_root); 4202 }
4203 err = qgroup_fix_relocated_data_extents(trans, rc);
4204 if (err < 0) {
4205 btrfs_abort_transaction(trans, err);
4206 goto out_free;
4207 }
4208 btrfs_commit_transaction(trans, rc->extent_root);
4109out_free: 4209out_free:
4110 btrfs_free_block_rsv(rc->extent_root, rc->block_rsv); 4210 btrfs_free_block_rsv(rc->extent_root, rc->block_rsv);
4111 btrfs_free_path(path); 4211 btrfs_free_path(path);
@@ -4468,10 +4568,16 @@ int btrfs_recover_relocation(struct btrfs_root *root)
4468 unset_reloc_control(rc); 4568 unset_reloc_control(rc);
4469 4569
4470 trans = btrfs_join_transaction(rc->extent_root); 4570 trans = btrfs_join_transaction(rc->extent_root);
4471 if (IS_ERR(trans)) 4571 if (IS_ERR(trans)) {
4472 err = PTR_ERR(trans); 4572 err = PTR_ERR(trans);
4473 else 4573 goto out_free;
4474 err = btrfs_commit_transaction(trans, rc->extent_root); 4574 }
4575 err = qgroup_fix_relocated_data_extents(trans, rc);
4576 if (err < 0) {
4577 btrfs_abort_transaction(trans, err);
4578 goto out_free;
4579 }
4580 err = btrfs_commit_transaction(trans, rc->extent_root);
4475out_free: 4581out_free:
4476 kfree(rc); 4582 kfree(rc);
4477out: 4583out:
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 7fd7e1830cfe..091296062456 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -272,6 +272,23 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root)
272 root_key.objectid = key.offset; 272 root_key.objectid = key.offset;
273 key.offset++; 273 key.offset++;
274 274
275 /*
276 * The root might have been inserted already, as before we look
277 * for orphan roots, log replay might have happened, which
278 * triggers a transaction commit and qgroup accounting, which
279 * in turn reads and inserts fs roots while doing backref
280 * walking.
281 */
282 root = btrfs_lookup_fs_root(tree_root->fs_info,
283 root_key.objectid);
284 if (root) {
285 WARN_ON(!test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED,
286 &root->state));
287 if (btrfs_root_refs(&root->root_item) == 0)
288 btrfs_add_dead_root(root);
289 continue;
290 }
291
275 root = btrfs_read_fs_root(tree_root, &root_key); 292 root = btrfs_read_fs_root(tree_root, &root_key);
276 err = PTR_ERR_OR_ZERO(root); 293 err = PTR_ERR_OR_ZERO(root);
277 if (err && err != -ENOENT) { 294 if (err && err != -ENOENT) {
@@ -310,16 +327,8 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root)
310 set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state); 327 set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state);
311 328
312 err = btrfs_insert_fs_root(root->fs_info, root); 329 err = btrfs_insert_fs_root(root->fs_info, root);
313 /*
314 * The root might have been inserted already, as before we look
315 * for orphan roots, log replay might have happened, which
316 * triggers a transaction commit and qgroup accounting, which
317 * in turn reads and inserts fs roots while doing backref
318 * walking.
319 */
320 if (err == -EEXIST)
321 err = 0;
322 if (err) { 330 if (err) {
331 BUG_ON(err == -EEXIST);
323 btrfs_free_fs_root(root); 332 btrfs_free_fs_root(root);
324 break; 333 break;
325 } 334 }
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index b71dd298385c..efe129fe2678 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -231,7 +231,6 @@ struct pending_dir_move {
231 u64 parent_ino; 231 u64 parent_ino;
232 u64 ino; 232 u64 ino;
233 u64 gen; 233 u64 gen;
234 bool is_orphan;
235 struct list_head update_refs; 234 struct list_head update_refs;
236}; 235};
237 236
@@ -274,6 +273,39 @@ struct name_cache_entry {
274 char name[]; 273 char name[];
275}; 274};
276 275
276static void inconsistent_snapshot_error(struct send_ctx *sctx,
277 enum btrfs_compare_tree_result result,
278 const char *what)
279{
280 const char *result_string;
281
282 switch (result) {
283 case BTRFS_COMPARE_TREE_NEW:
284 result_string = "new";
285 break;
286 case BTRFS_COMPARE_TREE_DELETED:
287 result_string = "deleted";
288 break;
289 case BTRFS_COMPARE_TREE_CHANGED:
290 result_string = "updated";
291 break;
292 case BTRFS_COMPARE_TREE_SAME:
293 ASSERT(0);
294 result_string = "unchanged";
295 break;
296 default:
297 ASSERT(0);
298 result_string = "unexpected";
299 }
300
301 btrfs_err(sctx->send_root->fs_info,
302 "Send: inconsistent snapshot, found %s %s for inode %llu without updated inode item, send root is %llu, parent root is %llu",
303 result_string, what, sctx->cmp_key->objectid,
304 sctx->send_root->root_key.objectid,
305 (sctx->parent_root ?
306 sctx->parent_root->root_key.objectid : 0));
307}
308
277static int is_waiting_for_move(struct send_ctx *sctx, u64 ino); 309static int is_waiting_for_move(struct send_ctx *sctx, u64 ino);
278 310
279static struct waiting_dir_move * 311static struct waiting_dir_move *
@@ -1861,7 +1893,8 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen,
1861 * was already unlinked/moved, so we can safely assume that we will not 1893 * was already unlinked/moved, so we can safely assume that we will not
1862 * overwrite anything at this point in time. 1894 * overwrite anything at this point in time.
1863 */ 1895 */
1864 if (other_inode > sctx->send_progress) { 1896 if (other_inode > sctx->send_progress ||
1897 is_waiting_for_move(sctx, other_inode)) {
1865 ret = get_inode_info(sctx->parent_root, other_inode, NULL, 1898 ret = get_inode_info(sctx->parent_root, other_inode, NULL,
1866 who_gen, NULL, NULL, NULL, NULL); 1899 who_gen, NULL, NULL, NULL, NULL);
1867 if (ret < 0) 1900 if (ret < 0)
@@ -2502,6 +2535,8 @@ verbose_printk("btrfs: send_utimes %llu\n", ino);
2502 key.type = BTRFS_INODE_ITEM_KEY; 2535 key.type = BTRFS_INODE_ITEM_KEY;
2503 key.offset = 0; 2536 key.offset = 0;
2504 ret = btrfs_search_slot(NULL, sctx->send_root, &key, path, 0, 0); 2537 ret = btrfs_search_slot(NULL, sctx->send_root, &key, path, 0, 0);
2538 if (ret > 0)
2539 ret = -ENOENT;
2505 if (ret < 0) 2540 if (ret < 0)
2506 goto out; 2541 goto out;
2507 2542
@@ -2947,6 +2982,10 @@ static int can_rmdir(struct send_ctx *sctx, u64 dir, u64 dir_gen,
2947 } 2982 }
2948 2983
2949 if (loc.objectid > send_progress) { 2984 if (loc.objectid > send_progress) {
2985 struct orphan_dir_info *odi;
2986
2987 odi = get_orphan_dir_info(sctx, dir);
2988 free_orphan_dir_info(sctx, odi);
2950 ret = 0; 2989 ret = 0;
2951 goto out; 2990 goto out;
2952 } 2991 }
@@ -3047,7 +3086,6 @@ static int add_pending_dir_move(struct send_ctx *sctx,
3047 pm->parent_ino = parent_ino; 3086 pm->parent_ino = parent_ino;
3048 pm->ino = ino; 3087 pm->ino = ino;
3049 pm->gen = ino_gen; 3088 pm->gen = ino_gen;
3050 pm->is_orphan = is_orphan;
3051 INIT_LIST_HEAD(&pm->list); 3089 INIT_LIST_HEAD(&pm->list);
3052 INIT_LIST_HEAD(&pm->update_refs); 3090 INIT_LIST_HEAD(&pm->update_refs);
3053 RB_CLEAR_NODE(&pm->node); 3091 RB_CLEAR_NODE(&pm->node);
@@ -3113,6 +3151,48 @@ static struct pending_dir_move *get_pending_dir_moves(struct send_ctx *sctx,
3113 return NULL; 3151 return NULL;
3114} 3152}
3115 3153
3154static int path_loop(struct send_ctx *sctx, struct fs_path *name,
3155 u64 ino, u64 gen, u64 *ancestor_ino)
3156{
3157 int ret = 0;
3158 u64 parent_inode = 0;
3159 u64 parent_gen = 0;
3160 u64 start_ino = ino;
3161
3162 *ancestor_ino = 0;
3163 while (ino != BTRFS_FIRST_FREE_OBJECTID) {
3164 fs_path_reset(name);
3165
3166 if (is_waiting_for_rm(sctx, ino))
3167 break;
3168 if (is_waiting_for_move(sctx, ino)) {
3169 if (*ancestor_ino == 0)
3170 *ancestor_ino = ino;
3171 ret = get_first_ref(sctx->parent_root, ino,
3172 &parent_inode, &parent_gen, name);
3173 } else {
3174 ret = __get_cur_name_and_parent(sctx, ino, gen,
3175 &parent_inode,
3176 &parent_gen, name);
3177 if (ret > 0) {
3178 ret = 0;
3179 break;
3180 }
3181 }
3182 if (ret < 0)
3183 break;
3184 if (parent_inode == start_ino) {
3185 ret = 1;
3186 if (*ancestor_ino == 0)
3187 *ancestor_ino = ino;
3188 break;
3189 }
3190 ino = parent_inode;
3191 gen = parent_gen;
3192 }
3193 return ret;
3194}
3195
3116static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm) 3196static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3117{ 3197{
3118 struct fs_path *from_path = NULL; 3198 struct fs_path *from_path = NULL;
@@ -3123,6 +3203,8 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3123 u64 parent_ino, parent_gen; 3203 u64 parent_ino, parent_gen;
3124 struct waiting_dir_move *dm = NULL; 3204 struct waiting_dir_move *dm = NULL;
3125 u64 rmdir_ino = 0; 3205 u64 rmdir_ino = 0;
3206 u64 ancestor;
3207 bool is_orphan;
3126 int ret; 3208 int ret;
3127 3209
3128 name = fs_path_alloc(); 3210 name = fs_path_alloc();
@@ -3135,9 +3217,10 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3135 dm = get_waiting_dir_move(sctx, pm->ino); 3217 dm = get_waiting_dir_move(sctx, pm->ino);
3136 ASSERT(dm); 3218 ASSERT(dm);
3137 rmdir_ino = dm->rmdir_ino; 3219 rmdir_ino = dm->rmdir_ino;
3220 is_orphan = dm->orphanized;
3138 free_waiting_dir_move(sctx, dm); 3221 free_waiting_dir_move(sctx, dm);
3139 3222
3140 if (pm->is_orphan) { 3223 if (is_orphan) {
3141 ret = gen_unique_name(sctx, pm->ino, 3224 ret = gen_unique_name(sctx, pm->ino,
3142 pm->gen, from_path); 3225 pm->gen, from_path);
3143 } else { 3226 } else {
@@ -3155,6 +3238,24 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3155 goto out; 3238 goto out;
3156 3239
3157 sctx->send_progress = sctx->cur_ino + 1; 3240 sctx->send_progress = sctx->cur_ino + 1;
3241 ret = path_loop(sctx, name, pm->ino, pm->gen, &ancestor);
3242 if (ret < 0)
3243 goto out;
3244 if (ret) {
3245 LIST_HEAD(deleted_refs);
3246 ASSERT(ancestor > BTRFS_FIRST_FREE_OBJECTID);
3247 ret = add_pending_dir_move(sctx, pm->ino, pm->gen, ancestor,
3248 &pm->update_refs, &deleted_refs,
3249 is_orphan);
3250 if (ret < 0)
3251 goto out;
3252 if (rmdir_ino) {
3253 dm = get_waiting_dir_move(sctx, pm->ino);
3254 ASSERT(dm);
3255 dm->rmdir_ino = rmdir_ino;
3256 }
3257 goto out;
3258 }
3158 fs_path_reset(name); 3259 fs_path_reset(name);
3159 to_path = name; 3260 to_path = name;
3160 name = NULL; 3261 name = NULL;
@@ -3174,7 +3275,7 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3174 /* already deleted */ 3275 /* already deleted */
3175 goto finish; 3276 goto finish;
3176 } 3277 }
3177 ret = can_rmdir(sctx, rmdir_ino, odi->gen, sctx->cur_ino + 1); 3278 ret = can_rmdir(sctx, rmdir_ino, odi->gen, sctx->cur_ino);
3178 if (ret < 0) 3279 if (ret < 0)
3179 goto out; 3280 goto out;
3180 if (!ret) 3281 if (!ret)
@@ -3204,8 +3305,18 @@ finish:
3204 * and old parent(s). 3305 * and old parent(s).
3205 */ 3306 */
3206 list_for_each_entry(cur, &pm->update_refs, list) { 3307 list_for_each_entry(cur, &pm->update_refs, list) {
3207 if (cur->dir == rmdir_ino) 3308 /*
3309 * The parent inode might have been deleted in the send snapshot
3310 */
3311 ret = get_inode_info(sctx->send_root, cur->dir, NULL,
3312 NULL, NULL, NULL, NULL, NULL);
3313 if (ret == -ENOENT) {
3314 ret = 0;
3208 continue; 3315 continue;
3316 }
3317 if (ret < 0)
3318 goto out;
3319
3209 ret = send_utimes(sctx, cur->dir, cur->dir_gen); 3320 ret = send_utimes(sctx, cur->dir, cur->dir_gen);
3210 if (ret < 0) 3321 if (ret < 0)
3211 goto out; 3322 goto out;
@@ -3325,6 +3436,7 @@ static int wait_for_dest_dir_move(struct send_ctx *sctx,
3325 u64 left_gen; 3436 u64 left_gen;
3326 u64 right_gen; 3437 u64 right_gen;
3327 int ret = 0; 3438 int ret = 0;
3439 struct waiting_dir_move *wdm;
3328 3440
3329 if (RB_EMPTY_ROOT(&sctx->waiting_dir_moves)) 3441 if (RB_EMPTY_ROOT(&sctx->waiting_dir_moves))
3330 return 0; 3442 return 0;
@@ -3383,7 +3495,8 @@ static int wait_for_dest_dir_move(struct send_ctx *sctx,
3383 goto out; 3495 goto out;
3384 } 3496 }
3385 3497
3386 if (is_waiting_for_move(sctx, di_key.objectid)) { 3498 wdm = get_waiting_dir_move(sctx, di_key.objectid);
3499 if (wdm && !wdm->orphanized) {
3387 ret = add_pending_dir_move(sctx, 3500 ret = add_pending_dir_move(sctx,
3388 sctx->cur_ino, 3501 sctx->cur_ino,
3389 sctx->cur_inode_gen, 3502 sctx->cur_inode_gen,
@@ -3470,7 +3583,8 @@ static int wait_for_parent_move(struct send_ctx *sctx,
3470 ret = is_ancestor(sctx->parent_root, 3583 ret = is_ancestor(sctx->parent_root,
3471 sctx->cur_ino, sctx->cur_inode_gen, 3584 sctx->cur_ino, sctx->cur_inode_gen,
3472 ino, path_before); 3585 ino, path_before);
3473 break; 3586 if (ret)
3587 break;
3474 } 3588 }
3475 3589
3476 fs_path_reset(path_before); 3590 fs_path_reset(path_before);
@@ -3643,11 +3757,26 @@ verbose_printk("btrfs: process_recorded_refs %llu\n", sctx->cur_ino);
3643 goto out; 3757 goto out;
3644 if (ret) { 3758 if (ret) {
3645 struct name_cache_entry *nce; 3759 struct name_cache_entry *nce;
3760 struct waiting_dir_move *wdm;
3646 3761
3647 ret = orphanize_inode(sctx, ow_inode, ow_gen, 3762 ret = orphanize_inode(sctx, ow_inode, ow_gen,
3648 cur->full_path); 3763 cur->full_path);
3649 if (ret < 0) 3764 if (ret < 0)
3650 goto out; 3765 goto out;
3766
3767 /*
3768 * If ow_inode has its rename operation delayed
3769 * make sure that its orphanized name is used in
3770 * the source path when performing its rename
3771 * operation.
3772 */
3773 if (is_waiting_for_move(sctx, ow_inode)) {
3774 wdm = get_waiting_dir_move(sctx,
3775 ow_inode);
3776 ASSERT(wdm);
3777 wdm->orphanized = true;
3778 }
3779
3651 /* 3780 /*
3652 * Make sure we clear our orphanized inode's 3781 * Make sure we clear our orphanized inode's
3653 * name from the name cache. This is because the 3782 * name from the name cache. This is because the
@@ -3663,6 +3792,19 @@ verbose_printk("btrfs: process_recorded_refs %llu\n", sctx->cur_ino);
3663 name_cache_delete(sctx, nce); 3792 name_cache_delete(sctx, nce);
3664 kfree(nce); 3793 kfree(nce);
3665 } 3794 }
3795
3796 /*
3797 * ow_inode might currently be an ancestor of
3798 * cur_ino, therefore compute valid_path (the
3799 * current path of cur_ino) again because it
3800 * might contain the pre-orphanization name of
3801 * ow_inode, which is no longer valid.
3802 */
3803 fs_path_reset(valid_path);
3804 ret = get_cur_path(sctx, sctx->cur_ino,
3805 sctx->cur_inode_gen, valid_path);
3806 if (ret < 0)
3807 goto out;
3666 } else { 3808 } else {
3667 ret = send_unlink(sctx, cur->full_path); 3809 ret = send_unlink(sctx, cur->full_path);
3668 if (ret < 0) 3810 if (ret < 0)
@@ -5602,7 +5744,10 @@ static int changed_ref(struct send_ctx *sctx,
5602{ 5744{
5603 int ret = 0; 5745 int ret = 0;
5604 5746
5605 BUG_ON(sctx->cur_ino != sctx->cmp_key->objectid); 5747 if (sctx->cur_ino != sctx->cmp_key->objectid) {
5748 inconsistent_snapshot_error(sctx, result, "reference");
5749 return -EIO;
5750 }
5606 5751
5607 if (!sctx->cur_inode_new_gen && 5752 if (!sctx->cur_inode_new_gen &&
5608 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) { 5753 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) {
@@ -5627,7 +5772,10 @@ static int changed_xattr(struct send_ctx *sctx,
5627{ 5772{
5628 int ret = 0; 5773 int ret = 0;
5629 5774
5630 BUG_ON(sctx->cur_ino != sctx->cmp_key->objectid); 5775 if (sctx->cur_ino != sctx->cmp_key->objectid) {
5776 inconsistent_snapshot_error(sctx, result, "xattr");
5777 return -EIO;
5778 }
5631 5779
5632 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { 5780 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) {
5633 if (result == BTRFS_COMPARE_TREE_NEW) 5781 if (result == BTRFS_COMPARE_TREE_NEW)
@@ -5651,7 +5799,10 @@ static int changed_extent(struct send_ctx *sctx,
5651{ 5799{
5652 int ret = 0; 5800 int ret = 0;
5653 5801
5654 BUG_ON(sctx->cur_ino != sctx->cmp_key->objectid); 5802 if (sctx->cur_ino != sctx->cmp_key->objectid) {
5803 inconsistent_snapshot_error(sctx, result, "extent");
5804 return -EIO;
5805 }
5655 5806
5656 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { 5807 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) {
5657 if (result != BTRFS_COMPARE_TREE_DELETED) 5808 if (result != BTRFS_COMPARE_TREE_DELETED)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 864ce334f696..4071fe2bd098 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2241,6 +2241,13 @@ static int btrfs_freeze(struct super_block *sb)
2241 struct btrfs_trans_handle *trans; 2241 struct btrfs_trans_handle *trans;
2242 struct btrfs_root *root = btrfs_sb(sb)->tree_root; 2242 struct btrfs_root *root = btrfs_sb(sb)->tree_root;
2243 2243
2244 root->fs_info->fs_frozen = 1;
2245 /*
2246 * We don't need a barrier here, we'll wait for any transaction that
2247 * could be in progress on other threads (and do delayed iputs that
2248 * we want to avoid on a frozen filesystem), or do the commit
2249 * ourselves.
2250 */
2244 trans = btrfs_attach_transaction_barrier(root); 2251 trans = btrfs_attach_transaction_barrier(root);
2245 if (IS_ERR(trans)) { 2252 if (IS_ERR(trans)) {
2246 /* no transaction, don't bother */ 2253 /* no transaction, don't bother */
@@ -2251,6 +2258,14 @@ static int btrfs_freeze(struct super_block *sb)
2251 return btrfs_commit_transaction(trans, root); 2258 return btrfs_commit_transaction(trans, root);
2252} 2259}
2253 2260
2261static int btrfs_unfreeze(struct super_block *sb)
2262{
2263 struct btrfs_root *root = btrfs_sb(sb)->tree_root;
2264
2265 root->fs_info->fs_frozen = 0;
2266 return 0;
2267}
2268
2254static int btrfs_show_devname(struct seq_file *m, struct dentry *root) 2269static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
2255{ 2270{
2256 struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb); 2271 struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
@@ -2299,6 +2314,7 @@ static const struct super_operations btrfs_super_ops = {
2299 .statfs = btrfs_statfs, 2314 .statfs = btrfs_statfs,
2300 .remount_fs = btrfs_remount, 2315 .remount_fs = btrfs_remount,
2301 .freeze_fs = btrfs_freeze, 2316 .freeze_fs = btrfs_freeze,
2317 .unfreeze_fs = btrfs_unfreeze,
2302}; 2318};
2303 2319
2304static const struct file_operations btrfs_ctl_fops = { 2320static const struct file_operations btrfs_ctl_fops = {
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 9cca0a721961..95d41919d034 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -2278,8 +2278,13 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
2278 2278
2279 kmem_cache_free(btrfs_trans_handle_cachep, trans); 2279 kmem_cache_free(btrfs_trans_handle_cachep, trans);
2280 2280
2281 /*
2282 * If fs has been frozen, we can not handle delayed iputs, otherwise
2283 * it'll result in deadlock about SB_FREEZE_FS.
2284 */
2281 if (current != root->fs_info->transaction_kthread && 2285 if (current != root->fs_info->transaction_kthread &&
2282 current != root->fs_info->cleaner_kthread) 2286 current != root->fs_info->cleaner_kthread &&
2287 !root->fs_info->fs_frozen)
2283 btrfs_run_delayed_iputs(root); 2288 btrfs_run_delayed_iputs(root);
2284 2289
2285 return ret; 2290 return ret;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index d31a0c4f56be..e935035ac034 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -27,6 +27,7 @@
27#include "backref.h" 27#include "backref.h"
28#include "hash.h" 28#include "hash.h"
29#include "compression.h" 29#include "compression.h"
30#include "qgroup.h"
30 31
31/* magic values for the inode_only field in btrfs_log_inode: 32/* magic values for the inode_only field in btrfs_log_inode:
32 * 33 *
@@ -680,6 +681,21 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
680 ins.type = BTRFS_EXTENT_ITEM_KEY; 681 ins.type = BTRFS_EXTENT_ITEM_KEY;
681 offset = key->offset - btrfs_file_extent_offset(eb, item); 682 offset = key->offset - btrfs_file_extent_offset(eb, item);
682 683
684 /*
685 * Manually record dirty extent, as here we did a shallow
686 * file extent item copy and skip normal backref update,
687 * but modifying extent tree all by ourselves.
688 * So need to manually record dirty extent for qgroup,
689 * as the owner of the file extent changed from log tree
690 * (doesn't affect qgroup) to fs/file tree(affects qgroup)
691 */
692 ret = btrfs_qgroup_insert_dirty_extent(trans, root->fs_info,
693 btrfs_file_extent_disk_bytenr(eb, item),
694 btrfs_file_extent_disk_num_bytes(eb, item),
695 GFP_NOFS);
696 if (ret < 0)
697 goto out;
698
683 if (ins.objectid > 0) { 699 if (ins.objectid > 0) {
684 u64 csum_start; 700 u64 csum_start;
685 u64 csum_end; 701 u64 csum_end;
@@ -2807,7 +2823,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2807 */ 2823 */
2808 mutex_unlock(&root->log_mutex); 2824 mutex_unlock(&root->log_mutex);
2809 2825
2810 btrfs_init_log_ctx(&root_log_ctx); 2826 btrfs_init_log_ctx(&root_log_ctx, NULL);
2811 2827
2812 mutex_lock(&log_root_tree->log_mutex); 2828 mutex_lock(&log_root_tree->log_mutex);
2813 atomic_inc(&log_root_tree->log_batch); 2829 atomic_inc(&log_root_tree->log_batch);
@@ -4469,7 +4485,8 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans,
4469static int btrfs_check_ref_name_override(struct extent_buffer *eb, 4485static int btrfs_check_ref_name_override(struct extent_buffer *eb,
4470 const int slot, 4486 const int slot,
4471 const struct btrfs_key *key, 4487 const struct btrfs_key *key,
4472 struct inode *inode) 4488 struct inode *inode,
4489 u64 *other_ino)
4473{ 4490{
4474 int ret; 4491 int ret;
4475 struct btrfs_path *search_path; 4492 struct btrfs_path *search_path;
@@ -4528,7 +4545,16 @@ static int btrfs_check_ref_name_override(struct extent_buffer *eb,
4528 search_path, parent, 4545 search_path, parent,
4529 name, this_name_len, 0); 4546 name, this_name_len, 0);
4530 if (di && !IS_ERR(di)) { 4547 if (di && !IS_ERR(di)) {
4531 ret = 1; 4548 struct btrfs_key di_key;
4549
4550 btrfs_dir_item_key_to_cpu(search_path->nodes[0],
4551 di, &di_key);
4552 if (di_key.type == BTRFS_INODE_ITEM_KEY) {
4553 ret = 1;
4554 *other_ino = di_key.objectid;
4555 } else {
4556 ret = -EAGAIN;
4557 }
4532 goto out; 4558 goto out;
4533 } else if (IS_ERR(di)) { 4559 } else if (IS_ERR(di)) {
4534 ret = PTR_ERR(di); 4560 ret = PTR_ERR(di);
@@ -4722,16 +4748,72 @@ again:
4722 if ((min_key.type == BTRFS_INODE_REF_KEY || 4748 if ((min_key.type == BTRFS_INODE_REF_KEY ||
4723 min_key.type == BTRFS_INODE_EXTREF_KEY) && 4749 min_key.type == BTRFS_INODE_EXTREF_KEY) &&
4724 BTRFS_I(inode)->generation == trans->transid) { 4750 BTRFS_I(inode)->generation == trans->transid) {
4751 u64 other_ino = 0;
4752
4725 ret = btrfs_check_ref_name_override(path->nodes[0], 4753 ret = btrfs_check_ref_name_override(path->nodes[0],
4726 path->slots[0], 4754 path->slots[0],
4727 &min_key, inode); 4755 &min_key, inode,
4756 &other_ino);
4728 if (ret < 0) { 4757 if (ret < 0) {
4729 err = ret; 4758 err = ret;
4730 goto out_unlock; 4759 goto out_unlock;
4731 } else if (ret > 0) { 4760 } else if (ret > 0 && ctx &&
4732 err = 1; 4761 other_ino != btrfs_ino(ctx->inode)) {
4733 btrfs_set_log_full_commit(root->fs_info, trans); 4762 struct btrfs_key inode_key;
4734 goto out_unlock; 4763 struct inode *other_inode;
4764
4765 if (ins_nr > 0) {
4766 ins_nr++;
4767 } else {
4768 ins_nr = 1;
4769 ins_start_slot = path->slots[0];
4770 }
4771 ret = copy_items(trans, inode, dst_path, path,
4772 &last_extent, ins_start_slot,
4773 ins_nr, inode_only,
4774 logged_isize);
4775 if (ret < 0) {
4776 err = ret;
4777 goto out_unlock;
4778 }
4779 ins_nr = 0;
4780 btrfs_release_path(path);
4781 inode_key.objectid = other_ino;
4782 inode_key.type = BTRFS_INODE_ITEM_KEY;
4783 inode_key.offset = 0;
4784 other_inode = btrfs_iget(root->fs_info->sb,
4785 &inode_key, root,
4786 NULL);
4787 /*
4788 * If the other inode that had a conflicting dir
4789 * entry was deleted in the current transaction,
4790 * we don't need to do more work nor fallback to
4791 * a transaction commit.
4792 */
4793 if (IS_ERR(other_inode) &&
4794 PTR_ERR(other_inode) == -ENOENT) {
4795 goto next_key;
4796 } else if (IS_ERR(other_inode)) {
4797 err = PTR_ERR(other_inode);
4798 goto out_unlock;
4799 }
4800 /*
4801 * We are safe logging the other inode without
4802 * acquiring its i_mutex as long as we log with
4803 * the LOG_INODE_EXISTS mode. We're safe against
4804 * concurrent renames of the other inode as well
4805 * because during a rename we pin the log and
4806 * update the log with the new name before we
4807 * unpin it.
4808 */
4809 err = btrfs_log_inode(trans, root, other_inode,
4810 LOG_INODE_EXISTS,
4811 0, LLONG_MAX, ctx);
4812 iput(other_inode);
4813 if (err)
4814 goto out_unlock;
4815 else
4816 goto next_key;
4735 } 4817 }
4736 } 4818 }
4737 4819
@@ -4799,7 +4881,7 @@ next_slot:
4799 ins_nr = 0; 4881 ins_nr = 0;
4800 } 4882 }
4801 btrfs_release_path(path); 4883 btrfs_release_path(path);
4802 4884next_key:
4803 if (min_key.offset < (u64)-1) { 4885 if (min_key.offset < (u64)-1) {
4804 min_key.offset++; 4886 min_key.offset++;
4805 } else if (min_key.type < max_key.type) { 4887 } else if (min_key.type < max_key.type) {
@@ -4993,8 +5075,12 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
4993 if (!parent || d_really_is_negative(parent) || sb != parent->d_sb) 5075 if (!parent || d_really_is_negative(parent) || sb != parent->d_sb)
4994 break; 5076 break;
4995 5077
4996 if (IS_ROOT(parent)) 5078 if (IS_ROOT(parent)) {
5079 inode = d_inode(parent);
5080 if (btrfs_must_commit_transaction(trans, inode))
5081 ret = 1;
4997 break; 5082 break;
5083 }
4998 5084
4999 parent = dget_parent(parent); 5085 parent = dget_parent(parent);
5000 dput(old_parent); 5086 dput(old_parent);
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
index a9f1b75d080d..ab858e31ccbc 100644
--- a/fs/btrfs/tree-log.h
+++ b/fs/btrfs/tree-log.h
@@ -30,15 +30,18 @@ struct btrfs_log_ctx {
30 int log_transid; 30 int log_transid;
31 int io_err; 31 int io_err;
32 bool log_new_dentries; 32 bool log_new_dentries;
33 struct inode *inode;
33 struct list_head list; 34 struct list_head list;
34}; 35};
35 36
36static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx) 37static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
38 struct inode *inode)
37{ 39{
38 ctx->log_ret = 0; 40 ctx->log_ret = 0;
39 ctx->log_transid = 0; 41 ctx->log_transid = 0;
40 ctx->io_err = 0; 42 ctx->io_err = 0;
41 ctx->log_new_dentries = false; 43 ctx->log_new_dentries = false;
44 ctx->inode = inode;
42 INIT_LIST_HEAD(&ctx->list); 45 INIT_LIST_HEAD(&ctx->list);
43} 46}
44 47
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 51f125508771..035efce603a9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -834,10 +834,6 @@ static void __free_device(struct work_struct *work)
834 struct btrfs_device *device; 834 struct btrfs_device *device;
835 835
836 device = container_of(work, struct btrfs_device, rcu_work); 836 device = container_of(work, struct btrfs_device, rcu_work);
837
838 if (device->bdev)
839 blkdev_put(device->bdev, device->mode);
840
841 rcu_string_free(device->name); 837 rcu_string_free(device->name);
842 kfree(device); 838 kfree(device);
843} 839}
@@ -852,6 +848,17 @@ static void free_device(struct rcu_head *head)
852 schedule_work(&device->rcu_work); 848 schedule_work(&device->rcu_work);
853} 849}
854 850
851static void btrfs_close_bdev(struct btrfs_device *device)
852{
853 if (device->bdev && device->writeable) {
854 sync_blockdev(device->bdev);
855 invalidate_bdev(device->bdev);
856 }
857
858 if (device->bdev)
859 blkdev_put(device->bdev, device->mode);
860}
861
855static void btrfs_close_one_device(struct btrfs_device *device) 862static void btrfs_close_one_device(struct btrfs_device *device)
856{ 863{
857 struct btrfs_fs_devices *fs_devices = device->fs_devices; 864 struct btrfs_fs_devices *fs_devices = device->fs_devices;
@@ -870,10 +877,7 @@ static void btrfs_close_one_device(struct btrfs_device *device)
870 if (device->missing) 877 if (device->missing)
871 fs_devices->missing_devices--; 878 fs_devices->missing_devices--;
872 879
873 if (device->bdev && device->writeable) { 880 btrfs_close_bdev(device);
874 sync_blockdev(device->bdev);
875 invalidate_bdev(device->bdev);
876 }
877 881
878 new_device = btrfs_alloc_device(NULL, &device->devid, 882 new_device = btrfs_alloc_device(NULL, &device->devid,
879 device->uuid); 883 device->uuid);
@@ -1932,6 +1936,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
1932 btrfs_sysfs_rm_device_link(root->fs_info->fs_devices, device); 1936 btrfs_sysfs_rm_device_link(root->fs_info->fs_devices, device);
1933 } 1937 }
1934 1938
1939 btrfs_close_bdev(device);
1940
1935 call_rcu(&device->rcu, free_device); 1941 call_rcu(&device->rcu, free_device);
1936 1942
1937 num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1; 1943 num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1;
@@ -2025,6 +2031,9 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info,
2025 /* zero out the old super if it is writable */ 2031 /* zero out the old super if it is writable */
2026 btrfs_scratch_superblocks(srcdev->bdev, srcdev->name->str); 2032 btrfs_scratch_superblocks(srcdev->bdev, srcdev->name->str);
2027 } 2033 }
2034
2035 btrfs_close_bdev(srcdev);
2036
2028 call_rcu(&srcdev->rcu, free_device); 2037 call_rcu(&srcdev->rcu, free_device);
2029 2038
2030 /* 2039 /*
@@ -2080,6 +2089,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
2080 * the device_list_mutex lock. 2089 * the device_list_mutex lock.
2081 */ 2090 */
2082 btrfs_scratch_superblocks(tgtdev->bdev, tgtdev->name->str); 2091 btrfs_scratch_superblocks(tgtdev->bdev, tgtdev->name->str);
2092
2093 btrfs_close_bdev(tgtdev);
2083 call_rcu(&tgtdev->rcu, free_device); 2094 call_rcu(&tgtdev->rcu, free_device);
2084} 2095}
2085 2096
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 99115cae1652..16e6ded0b7f2 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -1347,9 +1347,12 @@ void ceph_flush_snaps(struct ceph_inode_info *ci,
1347{ 1347{
1348 struct inode *inode = &ci->vfs_inode; 1348 struct inode *inode = &ci->vfs_inode;
1349 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; 1349 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
1350 struct ceph_mds_session *session = *psession; 1350 struct ceph_mds_session *session = NULL;
1351 int mds; 1351 int mds;
1352
1352 dout("ceph_flush_snaps %p\n", inode); 1353 dout("ceph_flush_snaps %p\n", inode);
1354 if (psession)
1355 session = *psession;
1353retry: 1356retry:
1354 spin_lock(&ci->i_ceph_lock); 1357 spin_lock(&ci->i_ceph_lock);
1355 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) { 1358 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) {
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index fa59a85226b2..f72d4ae303b2 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2759,6 +2759,7 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
2759 } else { 2759 } else {
2760 path = NULL; 2760 path = NULL;
2761 pathlen = 0; 2761 pathlen = 0;
2762 pathbase = 0;
2762 } 2763 }
2763 2764
2764 spin_lock(&ci->i_ceph_lock); 2765 spin_lock(&ci->i_ceph_lock);
diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index eea64912c9c0..466f7d60edc2 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -607,20 +607,54 @@ static const struct file_operations format2_fops;
607static const struct file_operations format3_fops; 607static const struct file_operations format3_fops;
608static const struct file_operations format4_fops; 608static const struct file_operations format4_fops;
609 609
610static int table_open(struct inode *inode, struct file *file) 610static int table_open1(struct inode *inode, struct file *file)
611{ 611{
612 struct seq_file *seq; 612 struct seq_file *seq;
613 int ret = -1; 613 int ret;
614 614
615 if (file->f_op == &format1_fops) 615 ret = seq_open(file, &format1_seq_ops);
616 ret = seq_open(file, &format1_seq_ops); 616 if (ret)
617 else if (file->f_op == &format2_fops) 617 return ret;
618 ret = seq_open(file, &format2_seq_ops); 618
619 else if (file->f_op == &format3_fops) 619 seq = file->private_data;
620 ret = seq_open(file, &format3_seq_ops); 620 seq->private = inode->i_private; /* the dlm_ls */
621 else if (file->f_op == &format4_fops) 621 return 0;
622 ret = seq_open(file, &format4_seq_ops); 622}
623
624static int table_open2(struct inode *inode, struct file *file)
625{
626 struct seq_file *seq;
627 int ret;
628
629 ret = seq_open(file, &format2_seq_ops);
630 if (ret)
631 return ret;
632
633 seq = file->private_data;
634 seq->private = inode->i_private; /* the dlm_ls */
635 return 0;
636}
637
638static int table_open3(struct inode *inode, struct file *file)
639{
640 struct seq_file *seq;
641 int ret;
642
643 ret = seq_open(file, &format3_seq_ops);
644 if (ret)
645 return ret;
646
647 seq = file->private_data;
648 seq->private = inode->i_private; /* the dlm_ls */
649 return 0;
650}
651
652static int table_open4(struct inode *inode, struct file *file)
653{
654 struct seq_file *seq;
655 int ret;
623 656
657 ret = seq_open(file, &format4_seq_ops);
624 if (ret) 658 if (ret)
625 return ret; 659 return ret;
626 660
@@ -631,7 +665,7 @@ static int table_open(struct inode *inode, struct file *file)
631 665
632static const struct file_operations format1_fops = { 666static const struct file_operations format1_fops = {
633 .owner = THIS_MODULE, 667 .owner = THIS_MODULE,
634 .open = table_open, 668 .open = table_open1,
635 .read = seq_read, 669 .read = seq_read,
636 .llseek = seq_lseek, 670 .llseek = seq_lseek,
637 .release = seq_release 671 .release = seq_release
@@ -639,7 +673,7 @@ static const struct file_operations format1_fops = {
639 673
640static const struct file_operations format2_fops = { 674static const struct file_operations format2_fops = {
641 .owner = THIS_MODULE, 675 .owner = THIS_MODULE,
642 .open = table_open, 676 .open = table_open2,
643 .read = seq_read, 677 .read = seq_read,
644 .llseek = seq_lseek, 678 .llseek = seq_lseek,
645 .release = seq_release 679 .release = seq_release
@@ -647,7 +681,7 @@ static const struct file_operations format2_fops = {
647 681
648static const struct file_operations format3_fops = { 682static const struct file_operations format3_fops = {
649 .owner = THIS_MODULE, 683 .owner = THIS_MODULE,
650 .open = table_open, 684 .open = table_open3,
651 .read = seq_read, 685 .read = seq_read,
652 .llseek = seq_lseek, 686 .llseek = seq_lseek,
653 .release = seq_release 687 .release = seq_release
@@ -655,7 +689,7 @@ static const struct file_operations format3_fops = {
655 689
656static const struct file_operations format4_fops = { 690static const struct file_operations format4_fops = {
657 .owner = THIS_MODULE, 691 .owner = THIS_MODULE,
658 .open = table_open, 692 .open = table_open4,
659 .read = seq_read, 693 .read = seq_read,
660 .llseek = seq_lseek, 694 .llseek = seq_lseek,
661 .release = seq_release 695 .release = seq_release
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index d64d2a515cb2..ccb401eebc11 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1699,11 +1699,11 @@ static int f2fs_write_end(struct file *file,
1699 trace_f2fs_write_end(inode, pos, len, copied); 1699 trace_f2fs_write_end(inode, pos, len, copied);
1700 1700
1701 set_page_dirty(page); 1701 set_page_dirty(page);
1702 f2fs_put_page(page, 1);
1703 1702
1704 if (pos + copied > i_size_read(inode)) 1703 if (pos + copied > i_size_read(inode))
1705 f2fs_i_size_write(inode, pos + copied); 1704 f2fs_i_size_write(inode, pos + copied);
1706 1705
1706 f2fs_put_page(page, 1);
1707 f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1707 f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
1708 return copied; 1708 return copied;
1709} 1709}
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 675fa79d86f6..14f5fe2b841e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -538,7 +538,7 @@ struct f2fs_nm_info {
538 /* NAT cache management */ 538 /* NAT cache management */
539 struct radix_tree_root nat_root;/* root of the nat entry cache */ 539 struct radix_tree_root nat_root;/* root of the nat entry cache */
540 struct radix_tree_root nat_set_root;/* root of the nat set cache */ 540 struct radix_tree_root nat_set_root;/* root of the nat set cache */
541 struct percpu_rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 541 struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
542 struct list_head nat_entries; /* cached nat entry list (clean) */ 542 struct list_head nat_entries; /* cached nat entry list (clean) */
543 unsigned int nat_cnt; /* the # of cached nat entries */ 543 unsigned int nat_cnt; /* the # of cached nat entries */
544 unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 544 unsigned int dirty_nat_cnt; /* total num of nat entries in set */
@@ -787,7 +787,7 @@ struct f2fs_sb_info {
787 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 787 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
788 struct inode *meta_inode; /* cache meta blocks */ 788 struct inode *meta_inode; /* cache meta blocks */
789 struct mutex cp_mutex; /* checkpoint procedure lock */ 789 struct mutex cp_mutex; /* checkpoint procedure lock */
790 struct percpu_rw_semaphore cp_rwsem; /* blocking FS operations */ 790 struct rw_semaphore cp_rwsem; /* blocking FS operations */
791 struct rw_semaphore node_write; /* locking node writes */ 791 struct rw_semaphore node_write; /* locking node writes */
792 wait_queue_head_t cp_wait; 792 wait_queue_head_t cp_wait;
793 unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 793 unsigned long last_time[MAX_TIME]; /* to store time in jiffies */
@@ -1074,22 +1074,22 @@ static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1074 1074
1075static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 1075static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
1076{ 1076{
1077 percpu_down_read(&sbi->cp_rwsem); 1077 down_read(&sbi->cp_rwsem);
1078} 1078}
1079 1079
1080static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 1080static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
1081{ 1081{
1082 percpu_up_read(&sbi->cp_rwsem); 1082 up_read(&sbi->cp_rwsem);
1083} 1083}
1084 1084
1085static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 1085static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
1086{ 1086{
1087 percpu_down_write(&sbi->cp_rwsem); 1087 down_write(&sbi->cp_rwsem);
1088} 1088}
1089 1089
1090static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 1090static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
1091{ 1091{
1092 percpu_up_write(&sbi->cp_rwsem); 1092 up_write(&sbi->cp_rwsem);
1093} 1093}
1094 1094
1095static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1095static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 0e493f63ea41..47abb96098e4 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2086,15 +2086,19 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
2086 if (unlikely(f2fs_readonly(src->i_sb))) 2086 if (unlikely(f2fs_readonly(src->i_sb)))
2087 return -EROFS; 2087 return -EROFS;
2088 2088
2089 if (S_ISDIR(src->i_mode) || S_ISDIR(dst->i_mode)) 2089 if (!S_ISREG(src->i_mode) || !S_ISREG(dst->i_mode))
2090 return -EISDIR; 2090 return -EINVAL;
2091 2091
2092 if (f2fs_encrypted_inode(src) || f2fs_encrypted_inode(dst)) 2092 if (f2fs_encrypted_inode(src) || f2fs_encrypted_inode(dst))
2093 return -EOPNOTSUPP; 2093 return -EOPNOTSUPP;
2094 2094
2095 inode_lock(src); 2095 inode_lock(src);
2096 if (src != dst) 2096 if (src != dst) {
2097 inode_lock(dst); 2097 if (!inode_trylock(dst)) {
2098 ret = -EBUSY;
2099 goto out;
2100 }
2101 }
2098 2102
2099 ret = -EINVAL; 2103 ret = -EINVAL;
2100 if (pos_in + len > src->i_size || pos_in + len < pos_in) 2104 if (pos_in + len > src->i_size || pos_in + len < pos_in)
@@ -2152,6 +2156,7 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
2152out_unlock: 2156out_unlock:
2153 if (src != dst) 2157 if (src != dst)
2154 inode_unlock(dst); 2158 inode_unlock(dst);
2159out:
2155 inode_unlock(src); 2160 inode_unlock(src);
2156 return ret; 2161 return ret;
2157} 2162}
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index b2fa4b615925..f75d197d5beb 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -206,14 +206,14 @@ int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid)
206 struct nat_entry *e; 206 struct nat_entry *e;
207 bool need = false; 207 bool need = false;
208 208
209 percpu_down_read(&nm_i->nat_tree_lock); 209 down_read(&nm_i->nat_tree_lock);
210 e = __lookup_nat_cache(nm_i, nid); 210 e = __lookup_nat_cache(nm_i, nid);
211 if (e) { 211 if (e) {
212 if (!get_nat_flag(e, IS_CHECKPOINTED) && 212 if (!get_nat_flag(e, IS_CHECKPOINTED) &&
213 !get_nat_flag(e, HAS_FSYNCED_INODE)) 213 !get_nat_flag(e, HAS_FSYNCED_INODE))
214 need = true; 214 need = true;
215 } 215 }
216 percpu_up_read(&nm_i->nat_tree_lock); 216 up_read(&nm_i->nat_tree_lock);
217 return need; 217 return need;
218} 218}
219 219
@@ -223,11 +223,11 @@ bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid)
223 struct nat_entry *e; 223 struct nat_entry *e;
224 bool is_cp = true; 224 bool is_cp = true;
225 225
226 percpu_down_read(&nm_i->nat_tree_lock); 226 down_read(&nm_i->nat_tree_lock);
227 e = __lookup_nat_cache(nm_i, nid); 227 e = __lookup_nat_cache(nm_i, nid);
228 if (e && !get_nat_flag(e, IS_CHECKPOINTED)) 228 if (e && !get_nat_flag(e, IS_CHECKPOINTED))
229 is_cp = false; 229 is_cp = false;
230 percpu_up_read(&nm_i->nat_tree_lock); 230 up_read(&nm_i->nat_tree_lock);
231 return is_cp; 231 return is_cp;
232} 232}
233 233
@@ -237,13 +237,13 @@ bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino)
237 struct nat_entry *e; 237 struct nat_entry *e;
238 bool need_update = true; 238 bool need_update = true;
239 239
240 percpu_down_read(&nm_i->nat_tree_lock); 240 down_read(&nm_i->nat_tree_lock);
241 e = __lookup_nat_cache(nm_i, ino); 241 e = __lookup_nat_cache(nm_i, ino);
242 if (e && get_nat_flag(e, HAS_LAST_FSYNC) && 242 if (e && get_nat_flag(e, HAS_LAST_FSYNC) &&
243 (get_nat_flag(e, IS_CHECKPOINTED) || 243 (get_nat_flag(e, IS_CHECKPOINTED) ||
244 get_nat_flag(e, HAS_FSYNCED_INODE))) 244 get_nat_flag(e, HAS_FSYNCED_INODE)))
245 need_update = false; 245 need_update = false;
246 percpu_up_read(&nm_i->nat_tree_lock); 246 up_read(&nm_i->nat_tree_lock);
247 return need_update; 247 return need_update;
248} 248}
249 249
@@ -284,7 +284,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
284 struct f2fs_nm_info *nm_i = NM_I(sbi); 284 struct f2fs_nm_info *nm_i = NM_I(sbi);
285 struct nat_entry *e; 285 struct nat_entry *e;
286 286
287 percpu_down_write(&nm_i->nat_tree_lock); 287 down_write(&nm_i->nat_tree_lock);
288 e = __lookup_nat_cache(nm_i, ni->nid); 288 e = __lookup_nat_cache(nm_i, ni->nid);
289 if (!e) { 289 if (!e) {
290 e = grab_nat_entry(nm_i, ni->nid); 290 e = grab_nat_entry(nm_i, ni->nid);
@@ -334,7 +334,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
334 set_nat_flag(e, HAS_FSYNCED_INODE, true); 334 set_nat_flag(e, HAS_FSYNCED_INODE, true);
335 set_nat_flag(e, HAS_LAST_FSYNC, fsync_done); 335 set_nat_flag(e, HAS_LAST_FSYNC, fsync_done);
336 } 336 }
337 percpu_up_write(&nm_i->nat_tree_lock); 337 up_write(&nm_i->nat_tree_lock);
338} 338}
339 339
340int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink) 340int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink)
@@ -342,7 +342,8 @@ int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink)
342 struct f2fs_nm_info *nm_i = NM_I(sbi); 342 struct f2fs_nm_info *nm_i = NM_I(sbi);
343 int nr = nr_shrink; 343 int nr = nr_shrink;
344 344
345 percpu_down_write(&nm_i->nat_tree_lock); 345 if (!down_write_trylock(&nm_i->nat_tree_lock))
346 return 0;
346 347
347 while (nr_shrink && !list_empty(&nm_i->nat_entries)) { 348 while (nr_shrink && !list_empty(&nm_i->nat_entries)) {
348 struct nat_entry *ne; 349 struct nat_entry *ne;
@@ -351,7 +352,7 @@ int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink)
351 __del_from_nat_cache(nm_i, ne); 352 __del_from_nat_cache(nm_i, ne);
352 nr_shrink--; 353 nr_shrink--;
353 } 354 }
354 percpu_up_write(&nm_i->nat_tree_lock); 355 up_write(&nm_i->nat_tree_lock);
355 return nr - nr_shrink; 356 return nr - nr_shrink;
356} 357}
357 358
@@ -373,13 +374,13 @@ void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni)
373 ni->nid = nid; 374 ni->nid = nid;
374 375
375 /* Check nat cache */ 376 /* Check nat cache */
376 percpu_down_read(&nm_i->nat_tree_lock); 377 down_read(&nm_i->nat_tree_lock);
377 e = __lookup_nat_cache(nm_i, nid); 378 e = __lookup_nat_cache(nm_i, nid);
378 if (e) { 379 if (e) {
379 ni->ino = nat_get_ino(e); 380 ni->ino = nat_get_ino(e);
380 ni->blk_addr = nat_get_blkaddr(e); 381 ni->blk_addr = nat_get_blkaddr(e);
381 ni->version = nat_get_version(e); 382 ni->version = nat_get_version(e);
382 percpu_up_read(&nm_i->nat_tree_lock); 383 up_read(&nm_i->nat_tree_lock);
383 return; 384 return;
384 } 385 }
385 386
@@ -403,11 +404,11 @@ void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni)
403 node_info_from_raw_nat(ni, &ne); 404 node_info_from_raw_nat(ni, &ne);
404 f2fs_put_page(page, 1); 405 f2fs_put_page(page, 1);
405cache: 406cache:
406 percpu_up_read(&nm_i->nat_tree_lock); 407 up_read(&nm_i->nat_tree_lock);
407 /* cache nat entry */ 408 /* cache nat entry */
408 percpu_down_write(&nm_i->nat_tree_lock); 409 down_write(&nm_i->nat_tree_lock);
409 cache_nat_entry(sbi, nid, &ne); 410 cache_nat_entry(sbi, nid, &ne);
410 percpu_up_write(&nm_i->nat_tree_lock); 411 up_write(&nm_i->nat_tree_lock);
411} 412}
412 413
413/* 414/*
@@ -1788,7 +1789,7 @@ void build_free_nids(struct f2fs_sb_info *sbi)
1788 ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, 1789 ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES,
1789 META_NAT, true); 1790 META_NAT, true);
1790 1791
1791 percpu_down_read(&nm_i->nat_tree_lock); 1792 down_read(&nm_i->nat_tree_lock);
1792 1793
1793 while (1) { 1794 while (1) {
1794 struct page *page = get_current_nat_page(sbi, nid); 1795 struct page *page = get_current_nat_page(sbi, nid);
@@ -1820,7 +1821,7 @@ void build_free_nids(struct f2fs_sb_info *sbi)
1820 remove_free_nid(nm_i, nid); 1821 remove_free_nid(nm_i, nid);
1821 } 1822 }
1822 up_read(&curseg->journal_rwsem); 1823 up_read(&curseg->journal_rwsem);
1823 percpu_up_read(&nm_i->nat_tree_lock); 1824 up_read(&nm_i->nat_tree_lock);
1824 1825
1825 ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), 1826 ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid),
1826 nm_i->ra_nid_pages, META_NAT, false); 1827 nm_i->ra_nid_pages, META_NAT, false);
@@ -2209,7 +2210,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
2209 if (!nm_i->dirty_nat_cnt) 2210 if (!nm_i->dirty_nat_cnt)
2210 return; 2211 return;
2211 2212
2212 percpu_down_write(&nm_i->nat_tree_lock); 2213 down_write(&nm_i->nat_tree_lock);
2213 2214
2214 /* 2215 /*
2215 * if there are no enough space in journal to store dirty nat 2216 * if there are no enough space in journal to store dirty nat
@@ -2232,7 +2233,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
2232 list_for_each_entry_safe(set, tmp, &sets, set_list) 2233 list_for_each_entry_safe(set, tmp, &sets, set_list)
2233 __flush_nat_entry_set(sbi, set); 2234 __flush_nat_entry_set(sbi, set);
2234 2235
2235 percpu_up_write(&nm_i->nat_tree_lock); 2236 up_write(&nm_i->nat_tree_lock);
2236 2237
2237 f2fs_bug_on(sbi, nm_i->dirty_nat_cnt); 2238 f2fs_bug_on(sbi, nm_i->dirty_nat_cnt);
2238} 2239}
@@ -2268,8 +2269,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
2268 2269
2269 mutex_init(&nm_i->build_lock); 2270 mutex_init(&nm_i->build_lock);
2270 spin_lock_init(&nm_i->free_nid_list_lock); 2271 spin_lock_init(&nm_i->free_nid_list_lock);
2271 if (percpu_init_rwsem(&nm_i->nat_tree_lock)) 2272 init_rwsem(&nm_i->nat_tree_lock);
2272 return -ENOMEM;
2273 2273
2274 nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid); 2274 nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid);
2275 nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP); 2275 nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP);
@@ -2326,7 +2326,7 @@ void destroy_node_manager(struct f2fs_sb_info *sbi)
2326 spin_unlock(&nm_i->free_nid_list_lock); 2326 spin_unlock(&nm_i->free_nid_list_lock);
2327 2327
2328 /* destroy nat cache */ 2328 /* destroy nat cache */
2329 percpu_down_write(&nm_i->nat_tree_lock); 2329 down_write(&nm_i->nat_tree_lock);
2330 while ((found = __gang_lookup_nat_cache(nm_i, 2330 while ((found = __gang_lookup_nat_cache(nm_i,
2331 nid, NATVEC_SIZE, natvec))) { 2331 nid, NATVEC_SIZE, natvec))) {
2332 unsigned idx; 2332 unsigned idx;
@@ -2351,9 +2351,8 @@ void destroy_node_manager(struct f2fs_sb_info *sbi)
2351 kmem_cache_free(nat_entry_set_slab, setvec[idx]); 2351 kmem_cache_free(nat_entry_set_slab, setvec[idx]);
2352 } 2352 }
2353 } 2353 }
2354 percpu_up_write(&nm_i->nat_tree_lock); 2354 up_write(&nm_i->nat_tree_lock);
2355 2355
2356 percpu_free_rwsem(&nm_i->nat_tree_lock);
2357 kfree(nm_i->nat_bitmap); 2356 kfree(nm_i->nat_bitmap);
2358 sbi->nm_info = NULL; 2357 sbi->nm_info = NULL;
2359 kfree(nm_i); 2358 kfree(nm_i);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 1b86d3f638ef..7f863a645ab1 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -706,8 +706,6 @@ static void destroy_percpu_info(struct f2fs_sb_info *sbi)
706 percpu_counter_destroy(&sbi->nr_pages[i]); 706 percpu_counter_destroy(&sbi->nr_pages[i]);
707 percpu_counter_destroy(&sbi->alloc_valid_block_count); 707 percpu_counter_destroy(&sbi->alloc_valid_block_count);
708 percpu_counter_destroy(&sbi->total_valid_inode_count); 708 percpu_counter_destroy(&sbi->total_valid_inode_count);
709
710 percpu_free_rwsem(&sbi->cp_rwsem);
711} 709}
712 710
713static void f2fs_put_super(struct super_block *sb) 711static void f2fs_put_super(struct super_block *sb)
@@ -1483,9 +1481,6 @@ static int init_percpu_info(struct f2fs_sb_info *sbi)
1483{ 1481{
1484 int i, err; 1482 int i, err;
1485 1483
1486 if (percpu_init_rwsem(&sbi->cp_rwsem))
1487 return -ENOMEM;
1488
1489 for (i = 0; i < NR_COUNT_TYPE; i++) { 1484 for (i = 0; i < NR_COUNT_TYPE; i++) {
1490 err = percpu_counter_init(&sbi->nr_pages[i], 0, GFP_KERNEL); 1485 err = percpu_counter_init(&sbi->nr_pages[i], 0, GFP_KERNEL);
1491 if (err) 1486 if (err)
@@ -1686,6 +1681,7 @@ try_onemore:
1686 sbi->write_io[i].bio = NULL; 1681 sbi->write_io[i].bio = NULL;
1687 } 1682 }
1688 1683
1684 init_rwsem(&sbi->cp_rwsem);
1689 init_waitqueue_head(&sbi->cp_wait); 1685 init_waitqueue_head(&sbi->cp_wait);
1690 init_sb_info(sbi); 1686 init_sb_info(sbi);
1691 1687
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 4d09d4441e3e..05713a5da083 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -1949,6 +1949,12 @@ void wakeup_flusher_threads(long nr_pages, enum wb_reason reason)
1949{ 1949{
1950 struct backing_dev_info *bdi; 1950 struct backing_dev_info *bdi;
1951 1951
1952 /*
1953 * If we are expecting writeback progress we must submit plugged IO.
1954 */
1955 if (blk_needs_flush_plug(current))
1956 blk_schedule_flush_plug(current);
1957
1952 if (!nr_pages) 1958 if (!nr_pages)
1953 nr_pages = get_nr_dirty_pages(); 1959 nr_pages = get_nr_dirty_pages();
1954 1960
diff --git a/fs/iomap.c b/fs/iomap.c
index 48141b8eff5f..0342254646e3 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -84,8 +84,11 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,
84 * Now the data has been copied, commit the range we've copied. This 84 * Now the data has been copied, commit the range we've copied. This
85 * should not fail unless the filesystem has had a fatal error. 85 * should not fail unless the filesystem has had a fatal error.
86 */ 86 */
87 ret = ops->iomap_end(inode, pos, length, written > 0 ? written : 0, 87 if (ops->iomap_end) {
88 flags, &iomap); 88 ret = ops->iomap_end(inode, pos, length,
89 written > 0 ? written : 0,
90 flags, &iomap);
91 }
89 92
90 return written ? written : ret; 93 return written ? written : ret;
91} 94}
@@ -194,12 +197,9 @@ again:
194 if (mapping_writably_mapped(inode->i_mapping)) 197 if (mapping_writably_mapped(inode->i_mapping))
195 flush_dcache_page(page); 198 flush_dcache_page(page);
196 199
197 pagefault_disable();
198 copied = iov_iter_copy_from_user_atomic(page, i, offset, bytes); 200 copied = iov_iter_copy_from_user_atomic(page, i, offset, bytes);
199 pagefault_enable();
200 201
201 flush_dcache_page(page); 202 flush_dcache_page(page);
202 mark_page_accessed(page);
203 203
204 status = iomap_write_end(inode, pos, bytes, copied, page); 204 status = iomap_write_end(inode, pos, bytes, copied, page);
205 if (unlikely(status < 0)) 205 if (unlikely(status < 0))
@@ -470,13 +470,18 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi,
470 if (ret) 470 if (ret)
471 return ret; 471 return ret;
472 472
473 ret = filemap_write_and_wait(inode->i_mapping); 473 if (fi->fi_flags & FIEMAP_FLAG_SYNC) {
474 if (ret) 474 ret = filemap_write_and_wait(inode->i_mapping);
475 return ret; 475 if (ret)
476 return ret;
477 }
476 478
477 while (len > 0) { 479 while (len > 0) {
478 ret = iomap_apply(inode, start, len, 0, ops, &ctx, 480 ret = iomap_apply(inode, start, len, 0, ops, &ctx,
479 iomap_fiemap_actor); 481 iomap_fiemap_actor);
482 /* inode with no (attribute) mapping will give ENOENT */
483 if (ret == -ENOENT)
484 break;
480 if (ret < 0) 485 if (ret < 0)
481 return ret; 486 return ret;
482 if (ret == 0) 487 if (ret == 0)
diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
index 33da841a21bb..6f4752734804 100644
--- a/fs/nfs/nfs42proc.c
+++ b/fs/nfs/nfs42proc.c
@@ -338,6 +338,8 @@ nfs42_layoutstat_done(struct rpc_task *task, void *calldata)
338 case 0: 338 case 0:
339 break; 339 break;
340 case -NFS4ERR_EXPIRED: 340 case -NFS4ERR_EXPIRED:
341 case -NFS4ERR_ADMIN_REVOKED:
342 case -NFS4ERR_DELEG_REVOKED:
341 case -NFS4ERR_STALE_STATEID: 343 case -NFS4ERR_STALE_STATEID:
342 case -NFS4ERR_OLD_STATEID: 344 case -NFS4ERR_OLD_STATEID:
343 case -NFS4ERR_BAD_STATEID: 345 case -NFS4ERR_BAD_STATEID:
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 324bfdc21250..9bf64eacba5b 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -396,6 +396,10 @@ extern void nfs4_schedule_state_renewal(struct nfs_client *);
396extern void nfs4_renewd_prepare_shutdown(struct nfs_server *); 396extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
397extern void nfs4_kill_renewd(struct nfs_client *); 397extern void nfs4_kill_renewd(struct nfs_client *);
398extern void nfs4_renew_state(struct work_struct *); 398extern void nfs4_renew_state(struct work_struct *);
399extern void nfs4_set_lease_period(struct nfs_client *clp,
400 unsigned long lease,
401 unsigned long lastrenewed);
402
399 403
400/* nfs4state.c */ 404/* nfs4state.c */
401struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp); 405struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index a036e93bdf96..1949bbd806eb 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -4237,12 +4237,9 @@ static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, str
4237 err = _nfs4_do_fsinfo(server, fhandle, fsinfo); 4237 err = _nfs4_do_fsinfo(server, fhandle, fsinfo);
4238 trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); 4238 trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err);
4239 if (err == 0) { 4239 if (err == 0) {
4240 struct nfs_client *clp = server->nfs_client; 4240 nfs4_set_lease_period(server->nfs_client,
4241 4241 fsinfo->lease_time * HZ,
4242 spin_lock(&clp->cl_lock); 4242 now);
4243 clp->cl_lease_time = fsinfo->lease_time * HZ;
4244 clp->cl_last_renewal = now;
4245 spin_unlock(&clp->cl_lock);
4246 break; 4243 break;
4247 } 4244 }
4248 err = nfs4_handle_exception(server, err, &exception); 4245 err = nfs4_handle_exception(server, err, &exception);
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c
index e1ba58c3d1ad..82e77198d17e 100644
--- a/fs/nfs/nfs4renewd.c
+++ b/fs/nfs/nfs4renewd.c
@@ -136,6 +136,26 @@ nfs4_kill_renewd(struct nfs_client *clp)
136 cancel_delayed_work_sync(&clp->cl_renewd); 136 cancel_delayed_work_sync(&clp->cl_renewd);
137} 137}
138 138
139/**
140 * nfs4_set_lease_period - Sets the lease period on a nfs_client
141 *
142 * @clp: pointer to nfs_client
143 * @lease: new value for lease period
144 * @lastrenewed: time at which lease was last renewed
145 */
146void nfs4_set_lease_period(struct nfs_client *clp,
147 unsigned long lease,
148 unsigned long lastrenewed)
149{
150 spin_lock(&clp->cl_lock);
151 clp->cl_lease_time = lease;
152 clp->cl_last_renewal = lastrenewed;
153 spin_unlock(&clp->cl_lock);
154
155 /* Cap maximum reconnect timeout at 1/2 lease period */
156 rpc_cap_max_reconnect_timeout(clp->cl_rpcclient, lease >> 1);
157}
158
139/* 159/*
140 * Local variables: 160 * Local variables:
141 * c-basic-offset: 8 161 * c-basic-offset: 8
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 834b875900d6..cada00aa5096 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -277,20 +277,17 @@ static int nfs41_setup_state_renewal(struct nfs_client *clp)
277{ 277{
278 int status; 278 int status;
279 struct nfs_fsinfo fsinfo; 279 struct nfs_fsinfo fsinfo;
280 unsigned long now;
280 281
281 if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) { 282 if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) {
282 nfs4_schedule_state_renewal(clp); 283 nfs4_schedule_state_renewal(clp);
283 return 0; 284 return 0;
284 } 285 }
285 286
287 now = jiffies;
286 status = nfs4_proc_get_lease_time(clp, &fsinfo); 288 status = nfs4_proc_get_lease_time(clp, &fsinfo);
287 if (status == 0) { 289 if (status == 0) {
288 /* Update lease time and schedule renewal */ 290 nfs4_set_lease_period(clp, fsinfo.lease_time * HZ, now);
289 spin_lock(&clp->cl_lock);
290 clp->cl_lease_time = fsinfo.lease_time * HZ;
291 clp->cl_last_renewal = jiffies;
292 spin_unlock(&clp->cl_lock);
293
294 nfs4_schedule_state_renewal(clp); 291 nfs4_schedule_state_renewal(clp);
295 } 292 }
296 293
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 8410ca275db1..a204d7e109d4 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4903,6 +4903,32 @@ nfsd4_test_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4903 return nfs_ok; 4903 return nfs_ok;
4904} 4904}
4905 4905
4906static __be32
4907nfsd4_free_lock_stateid(stateid_t *stateid, struct nfs4_stid *s)
4908{
4909 struct nfs4_ol_stateid *stp = openlockstateid(s);
4910 __be32 ret;
4911
4912 mutex_lock(&stp->st_mutex);
4913
4914 ret = check_stateid_generation(stateid, &s->sc_stateid, 1);
4915 if (ret)
4916 goto out;
4917
4918 ret = nfserr_locks_held;
4919 if (check_for_locks(stp->st_stid.sc_file,
4920 lockowner(stp->st_stateowner)))
4921 goto out;
4922
4923 release_lock_stateid(stp);
4924 ret = nfs_ok;
4925
4926out:
4927 mutex_unlock(&stp->st_mutex);
4928 nfs4_put_stid(s);
4929 return ret;
4930}
4931
4906__be32 4932__be32
4907nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 4933nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4908 struct nfsd4_free_stateid *free_stateid) 4934 struct nfsd4_free_stateid *free_stateid)
@@ -4910,7 +4936,6 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4910 stateid_t *stateid = &free_stateid->fr_stateid; 4936 stateid_t *stateid = &free_stateid->fr_stateid;
4911 struct nfs4_stid *s; 4937 struct nfs4_stid *s;
4912 struct nfs4_delegation *dp; 4938 struct nfs4_delegation *dp;
4913 struct nfs4_ol_stateid *stp;
4914 struct nfs4_client *cl = cstate->session->se_client; 4939 struct nfs4_client *cl = cstate->session->se_client;
4915 __be32 ret = nfserr_bad_stateid; 4940 __be32 ret = nfserr_bad_stateid;
4916 4941
@@ -4929,18 +4954,9 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4929 ret = nfserr_locks_held; 4954 ret = nfserr_locks_held;
4930 break; 4955 break;
4931 case NFS4_LOCK_STID: 4956 case NFS4_LOCK_STID:
4932 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); 4957 atomic_inc(&s->sc_count);
4933 if (ret)
4934 break;
4935 stp = openlockstateid(s);
4936 ret = nfserr_locks_held;
4937 if (check_for_locks(stp->st_stid.sc_file,
4938 lockowner(stp->st_stateowner)))
4939 break;
4940 WARN_ON(!unhash_lock_stateid(stp));
4941 spin_unlock(&cl->cl_lock); 4958 spin_unlock(&cl->cl_lock);
4942 nfs4_put_stid(s); 4959 ret = nfsd4_free_lock_stateid(stateid, s);
4943 ret = nfs_ok;
4944 goto out; 4960 goto out;
4945 case NFS4_REVOKED_DELEG_STID: 4961 case NFS4_REVOKED_DELEG_STID:
4946 dp = delegstateid(s); 4962 dp = delegstateid(s);
@@ -5507,7 +5523,7 @@ static __be32
5507lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, 5523lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
5508 struct nfs4_ol_stateid *ost, 5524 struct nfs4_ol_stateid *ost,
5509 struct nfsd4_lock *lock, 5525 struct nfsd4_lock *lock,
5510 struct nfs4_ol_stateid **lst, bool *new) 5526 struct nfs4_ol_stateid **plst, bool *new)
5511{ 5527{
5512 __be32 status; 5528 __be32 status;
5513 struct nfs4_file *fi = ost->st_stid.sc_file; 5529 struct nfs4_file *fi = ost->st_stid.sc_file;
@@ -5515,7 +5531,9 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
5515 struct nfs4_client *cl = oo->oo_owner.so_client; 5531 struct nfs4_client *cl = oo->oo_owner.so_client;
5516 struct inode *inode = d_inode(cstate->current_fh.fh_dentry); 5532 struct inode *inode = d_inode(cstate->current_fh.fh_dentry);
5517 struct nfs4_lockowner *lo; 5533 struct nfs4_lockowner *lo;
5534 struct nfs4_ol_stateid *lst;
5518 unsigned int strhashval; 5535 unsigned int strhashval;
5536 bool hashed;
5519 5537
5520 lo = find_lockowner_str(cl, &lock->lk_new_owner); 5538 lo = find_lockowner_str(cl, &lock->lk_new_owner);
5521 if (!lo) { 5539 if (!lo) {
@@ -5531,12 +5549,27 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
5531 goto out; 5549 goto out;
5532 } 5550 }
5533 5551
5534 *lst = find_or_create_lock_stateid(lo, fi, inode, ost, new); 5552retry:
5535 if (*lst == NULL) { 5553 lst = find_or_create_lock_stateid(lo, fi, inode, ost, new);
5554 if (lst == NULL) {
5536 status = nfserr_jukebox; 5555 status = nfserr_jukebox;
5537 goto out; 5556 goto out;
5538 } 5557 }
5558
5559 mutex_lock(&lst->st_mutex);
5560
5561 /* See if it's still hashed to avoid race with FREE_STATEID */
5562 spin_lock(&cl->cl_lock);
5563 hashed = !list_empty(&lst->st_perfile);
5564 spin_unlock(&cl->cl_lock);
5565
5566 if (!hashed) {
5567 mutex_unlock(&lst->st_mutex);
5568 nfs4_put_stid(&lst->st_stid);
5569 goto retry;
5570 }
5539 status = nfs_ok; 5571 status = nfs_ok;
5572 *plst = lst;
5540out: 5573out:
5541 nfs4_put_stateowner(&lo->lo_owner); 5574 nfs4_put_stateowner(&lo->lo_owner);
5542 return status; 5575 return status;
@@ -5603,8 +5636,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
5603 goto out; 5636 goto out;
5604 status = lookup_or_create_lock_state(cstate, open_stp, lock, 5637 status = lookup_or_create_lock_state(cstate, open_stp, lock,
5605 &lock_stp, &new); 5638 &lock_stp, &new);
5606 if (status == nfs_ok)
5607 mutex_lock(&lock_stp->st_mutex);
5608 } else { 5639 } else {
5609 status = nfs4_preprocess_seqid_op(cstate, 5640 status = nfs4_preprocess_seqid_op(cstate,
5610 lock->lk_old_lock_seqid, 5641 lock->lk_old_lock_seqid,
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index ba944123167b..ff476e654b8f 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1252,10 +1252,13 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1252 if (IS_ERR(dchild)) 1252 if (IS_ERR(dchild))
1253 return nfserrno(host_err); 1253 return nfserrno(host_err);
1254 err = fh_compose(resfhp, fhp->fh_export, dchild, fhp); 1254 err = fh_compose(resfhp, fhp->fh_export, dchild, fhp);
1255 if (err) { 1255 /*
1256 dput(dchild); 1256 * We unconditionally drop our ref to dchild as fh_compose will have
1257 * already grabbed its own ref for it.
1258 */
1259 dput(dchild);
1260 if (err)
1257 return err; 1261 return err;
1258 }
1259 return nfsd_create_locked(rqstp, fhp, fname, flen, iap, type, 1262 return nfsd_create_locked(rqstp, fhp, fname, flen, iap, type,
1260 rdev, resfhp); 1263 rdev, resfhp);
1261} 1264}
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 09e18fdf61e5..b9a8c813e5e6 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -46,7 +46,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
46 cached = 0; 46 cached = 0;
47 47
48 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 48 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
49 pages[lru] = global_page_state(NR_LRU_BASE + lru); 49 pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
50 50
51 available = si_mem_available(); 51 available = si_mem_available();
52 52
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 19f532e7d35e..6dc4296eed62 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -223,8 +223,10 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
223 size -= n; 223 size -= n;
224 buf += n; 224 buf += n;
225 copied += n; 225 copied += n;
226 if (!m->count) 226 if (!m->count) {
227 m->from = 0;
227 m->index++; 228 m->index++;
229 }
228 if (!size) 230 if (!size)
229 goto Done; 231 goto Done;
230 } 232 }
diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c
index b45345d701e7..51157da3f76e 100644
--- a/fs/ubifs/tnc_commit.c
+++ b/fs/ubifs/tnc_commit.c
@@ -370,7 +370,7 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt)
370 370
371 p = c->gap_lebs; 371 p = c->gap_lebs;
372 do { 372 do {
373 ubifs_assert(p < c->gap_lebs + sizeof(int) * c->lst.idx_lebs); 373 ubifs_assert(p < c->gap_lebs + c->lst.idx_lebs);
374 written = layout_leb_in_gaps(c, p); 374 written = layout_leb_in_gaps(c, p);
375 if (written < 0) { 375 if (written < 0) {
376 err = written; 376 err = written;
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
index e237811f09ce..11a004114eba 100644
--- a/fs/ubifs/xattr.c
+++ b/fs/ubifs/xattr.c
@@ -575,7 +575,8 @@ static int ubifs_xattr_get(const struct xattr_handler *handler,
575 dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name, 575 dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name,
576 inode->i_ino, dentry, size); 576 inode->i_ino, dentry, size);
577 577
578 return __ubifs_getxattr(inode, name, buffer, size); 578 name = xattr_full_name(handler, name);
579 return __ubifs_getxattr(inode, name, buffer, size);
579} 580}
580 581
581static int ubifs_xattr_set(const struct xattr_handler *handler, 582static int ubifs_xattr_set(const struct xattr_handler *handler,
@@ -586,6 +587,8 @@ static int ubifs_xattr_set(const struct xattr_handler *handler,
586 dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd", 587 dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd",
587 name, inode->i_ino, dentry, size); 588 name, inode->i_ino, dentry, size);
588 589
590 name = xattr_full_name(handler, name);
591
589 if (value) 592 if (value)
590 return __ubifs_setxattr(inode, name, value, size, flags); 593 return __ubifs_setxattr(inode, name, value, size, flags);
591 else 594 else
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 776ae2f325d1..3dd8f1d54498 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -1582,6 +1582,7 @@ xfs_alloc_ag_vextent_small(
1582 xfs_extlen_t *flenp, /* result length */ 1582 xfs_extlen_t *flenp, /* result length */
1583 int *stat) /* status: 0-freelist, 1-normal/none */ 1583 int *stat) /* status: 0-freelist, 1-normal/none */
1584{ 1584{
1585 struct xfs_owner_info oinfo;
1585 int error; 1586 int error;
1586 xfs_agblock_t fbno; 1587 xfs_agblock_t fbno;
1587 xfs_extlen_t flen; 1588 xfs_extlen_t flen;
@@ -1624,6 +1625,18 @@ xfs_alloc_ag_vextent_small(
1624 error0); 1625 error0);
1625 args->wasfromfl = 1; 1626 args->wasfromfl = 1;
1626 trace_xfs_alloc_small_freelist(args); 1627 trace_xfs_alloc_small_freelist(args);
1628
1629 /*
1630 * If we're feeding an AGFL block to something that
1631 * doesn't live in the free space, we need to clear
1632 * out the OWN_AG rmap.
1633 */
1634 xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
1635 error = xfs_rmap_free(args->tp, args->agbp, args->agno,
1636 fbno, 1, &oinfo);
1637 if (error)
1638 goto error0;
1639
1627 *stat = 0; 1640 *stat = 0;
1628 return 0; 1641 return 0;
1629 } 1642 }
@@ -2264,6 +2277,7 @@ xfs_alloc_log_agf(
2264 offsetof(xfs_agf_t, agf_longest), 2277 offsetof(xfs_agf_t, agf_longest),
2265 offsetof(xfs_agf_t, agf_btreeblks), 2278 offsetof(xfs_agf_t, agf_btreeblks),
2266 offsetof(xfs_agf_t, agf_uuid), 2279 offsetof(xfs_agf_t, agf_uuid),
2280 offsetof(xfs_agf_t, agf_rmap_blocks),
2267 sizeof(xfs_agf_t) 2281 sizeof(xfs_agf_t)
2268 }; 2282 };
2269 2283
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index f814d42c73b2..e6a8bea0f7ba 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -640,12 +640,15 @@ typedef struct xfs_agf {
640 __be32 agf_btreeblks; /* # of blocks held in AGF btrees */ 640 __be32 agf_btreeblks; /* # of blocks held in AGF btrees */
641 uuid_t agf_uuid; /* uuid of filesystem */ 641 uuid_t agf_uuid; /* uuid of filesystem */
642 642
643 __be32 agf_rmap_blocks; /* rmapbt blocks used */
644 __be32 agf_padding; /* padding */
645
643 /* 646 /*
644 * reserve some contiguous space for future logged fields before we add 647 * reserve some contiguous space for future logged fields before we add
645 * the unlogged fields. This makes the range logging via flags and 648 * the unlogged fields. This makes the range logging via flags and
646 * structure offsets much simpler. 649 * structure offsets much simpler.
647 */ 650 */
648 __be64 agf_spare64[16]; 651 __be64 agf_spare64[15];
649 652
650 /* unlogged fields, written during buffer writeback. */ 653 /* unlogged fields, written during buffer writeback. */
651 __be64 agf_lsn; /* last write sequence */ 654 __be64 agf_lsn; /* last write sequence */
@@ -670,7 +673,8 @@ typedef struct xfs_agf {
670#define XFS_AGF_LONGEST 0x00000400 673#define XFS_AGF_LONGEST 0x00000400
671#define XFS_AGF_BTREEBLKS 0x00000800 674#define XFS_AGF_BTREEBLKS 0x00000800
672#define XFS_AGF_UUID 0x00001000 675#define XFS_AGF_UUID 0x00001000
673#define XFS_AGF_NUM_BITS 13 676#define XFS_AGF_RMAP_BLOCKS 0x00002000
677#define XFS_AGF_NUM_BITS 14
674#define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1) 678#define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
675 679
676#define XFS_AGF_FLAGS \ 680#define XFS_AGF_FLAGS \
@@ -686,7 +690,8 @@ typedef struct xfs_agf {
686 { XFS_AGF_FREEBLKS, "FREEBLKS" }, \ 690 { XFS_AGF_FREEBLKS, "FREEBLKS" }, \
687 { XFS_AGF_LONGEST, "LONGEST" }, \ 691 { XFS_AGF_LONGEST, "LONGEST" }, \
688 { XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \ 692 { XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \
689 { XFS_AGF_UUID, "UUID" } 693 { XFS_AGF_UUID, "UUID" }, \
694 { XFS_AGF_RMAP_BLOCKS, "RMAP_BLOCKS" }
690 695
691/* disk block (xfs_daddr_t) in the AG */ 696/* disk block (xfs_daddr_t) in the AG */
692#define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log)) 697#define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c
index bc1faebc84ec..17b8eeb34ac8 100644
--- a/fs/xfs/libxfs/xfs_rmap_btree.c
+++ b/fs/xfs/libxfs/xfs_rmap_btree.c
@@ -98,6 +98,8 @@ xfs_rmapbt_alloc_block(
98 union xfs_btree_ptr *new, 98 union xfs_btree_ptr *new,
99 int *stat) 99 int *stat)
100{ 100{
101 struct xfs_buf *agbp = cur->bc_private.a.agbp;
102 struct xfs_agf *agf = XFS_BUF_TO_AGF(agbp);
101 int error; 103 int error;
102 xfs_agblock_t bno; 104 xfs_agblock_t bno;
103 105
@@ -124,6 +126,8 @@ xfs_rmapbt_alloc_block(
124 126
125 xfs_trans_agbtree_delta(cur->bc_tp, 1); 127 xfs_trans_agbtree_delta(cur->bc_tp, 1);
126 new->s = cpu_to_be32(bno); 128 new->s = cpu_to_be32(bno);
129 be32_add_cpu(&agf->agf_rmap_blocks, 1);
130 xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_RMAP_BLOCKS);
127 131
128 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT); 132 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
129 *stat = 1; 133 *stat = 1;
@@ -143,6 +147,8 @@ xfs_rmapbt_free_block(
143 bno = xfs_daddr_to_agbno(cur->bc_mp, XFS_BUF_ADDR(bp)); 147 bno = xfs_daddr_to_agbno(cur->bc_mp, XFS_BUF_ADDR(bp));
144 trace_xfs_rmapbt_free_block(cur->bc_mp, cur->bc_private.a.agno, 148 trace_xfs_rmapbt_free_block(cur->bc_mp, cur->bc_private.a.agno,
145 bno, 1); 149 bno, 1);
150 be32_add_cpu(&agf->agf_rmap_blocks, -1);
151 xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_RMAP_BLOCKS);
146 error = xfs_alloc_put_freelist(cur->bc_tp, agbp, NULL, bno, 1); 152 error = xfs_alloc_put_freelist(cur->bc_tp, agbp, NULL, bno, 1);
147 if (error) 153 if (error)
148 return error; 154 return error;
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 47a318ce82e0..607cc29bba21 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -115,7 +115,6 @@ xfs_buf_ioacct_dec(
115 if (!(bp->b_flags & _XBF_IN_FLIGHT)) 115 if (!(bp->b_flags & _XBF_IN_FLIGHT))
116 return; 116 return;
117 117
118 ASSERT(bp->b_flags & XBF_ASYNC);
119 bp->b_flags &= ~_XBF_IN_FLIGHT; 118 bp->b_flags &= ~_XBF_IN_FLIGHT;
120 percpu_counter_dec(&bp->b_target->bt_io_count); 119 percpu_counter_dec(&bp->b_target->bt_io_count);
121} 120}
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index ed95e5bb04e6..e612a0233710 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -741,9 +741,20 @@ xfs_file_dax_write(
741 * page is inserted into the pagecache when we have to serve a write 741 * page is inserted into the pagecache when we have to serve a write
742 * fault on a hole. It should never be dirtied and can simply be 742 * fault on a hole. It should never be dirtied and can simply be
743 * dropped from the pagecache once we get real data for the page. 743 * dropped from the pagecache once we get real data for the page.
744 *
745 * XXX: This is racy against mmap, and there's nothing we can do about
746 * it. dax_do_io() should really do this invalidation internally as
747 * it will know if we've allocated over a holei for this specific IO and
748 * if so it needs to update the mapping tree and invalidate existing
749 * PTEs over the newly allocated range. Remove this invalidation when
750 * dax_do_io() is fixed up.
744 */ 751 */
745 if (mapping->nrpages) { 752 if (mapping->nrpages) {
746 ret = invalidate_inode_pages2(mapping); 753 loff_t end = iocb->ki_pos + iov_iter_count(from) - 1;
754
755 ret = invalidate_inode_pages2_range(mapping,
756 iocb->ki_pos >> PAGE_SHIFT,
757 end >> PAGE_SHIFT);
747 WARN_ON_ONCE(ret); 758 WARN_ON_ONCE(ret);
748 } 759 }
749 760
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 0f96847b90e1..0b7f986745c1 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -248,6 +248,7 @@ xfs_growfs_data_private(
248 agf->agf_roots[XFS_BTNUM_RMAPi] = 248 agf->agf_roots[XFS_BTNUM_RMAPi] =
249 cpu_to_be32(XFS_RMAP_BLOCK(mp)); 249 cpu_to_be32(XFS_RMAP_BLOCK(mp));
250 agf->agf_levels[XFS_BTNUM_RMAPi] = cpu_to_be32(1); 250 agf->agf_levels[XFS_BTNUM_RMAPi] = cpu_to_be32(1);
251 agf->agf_rmap_blocks = cpu_to_be32(1);
251 } 252 }
252 253
253 agf->agf_flfirst = cpu_to_be32(1); 254 agf->agf_flfirst = cpu_to_be32(1);
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 2114d53df433..2af0dda1c978 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -715,12 +715,16 @@ xfs_iomap_write_allocate(
715 * is in the delayed allocation extent on which we sit 715 * is in the delayed allocation extent on which we sit
716 * but before our buffer starts. 716 * but before our buffer starts.
717 */ 717 */
718
719 nimaps = 0; 718 nimaps = 0;
720 while (nimaps == 0) { 719 while (nimaps == 0) {
721 nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); 720 nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
722 721 /*
723 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, nres, 722 * We have already reserved space for the extent and any
723 * indirect blocks when creating the delalloc extent,
724 * there is no need to reserve space in this transaction
725 * again.
726 */
727 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0,
724 0, XFS_TRANS_RESERVE, &tp); 728 0, XFS_TRANS_RESERVE, &tp);
725 if (error) 729 if (error)
726 return error; 730 return error;
@@ -1037,20 +1041,14 @@ xfs_file_iomap_begin(
1037 return error; 1041 return error;
1038 1042
1039 trace_xfs_iomap_alloc(ip, offset, length, 0, &imap); 1043 trace_xfs_iomap_alloc(ip, offset, length, 0, &imap);
1040 xfs_bmbt_to_iomap(ip, iomap, &imap);
1041 } else if (nimaps) {
1042 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1043 trace_xfs_iomap_found(ip, offset, length, 0, &imap);
1044 xfs_bmbt_to_iomap(ip, iomap, &imap);
1045 } else { 1044 } else {
1045 ASSERT(nimaps);
1046
1046 xfs_iunlock(ip, XFS_ILOCK_EXCL); 1047 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1047 trace_xfs_iomap_not_found(ip, offset, length, 0, &imap); 1048 trace_xfs_iomap_found(ip, offset, length, 0, &imap);
1048 iomap->blkno = IOMAP_NULL_BLOCK;
1049 iomap->type = IOMAP_HOLE;
1050 iomap->offset = offset;
1051 iomap->length = length;
1052 } 1049 }
1053 1050
1051 xfs_bmbt_to_iomap(ip, iomap, &imap);
1054 return 0; 1052 return 0;
1055} 1053}
1056 1054
@@ -1112,3 +1110,48 @@ struct iomap_ops xfs_iomap_ops = {
1112 .iomap_begin = xfs_file_iomap_begin, 1110 .iomap_begin = xfs_file_iomap_begin,
1113 .iomap_end = xfs_file_iomap_end, 1111 .iomap_end = xfs_file_iomap_end,
1114}; 1112};
1113
1114static int
1115xfs_xattr_iomap_begin(
1116 struct inode *inode,
1117 loff_t offset,
1118 loff_t length,
1119 unsigned flags,
1120 struct iomap *iomap)
1121{
1122 struct xfs_inode *ip = XFS_I(inode);
1123 struct xfs_mount *mp = ip->i_mount;
1124 xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
1125 xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, offset + length);
1126 struct xfs_bmbt_irec imap;
1127 int nimaps = 1, error = 0;
1128 unsigned lockmode;
1129
1130 if (XFS_FORCED_SHUTDOWN(mp))
1131 return -EIO;
1132
1133 lockmode = xfs_ilock_data_map_shared(ip);
1134
1135 /* if there are no attribute fork or extents, return ENOENT */
1136 if (XFS_IFORK_Q(ip) || !ip->i_d.di_anextents) {
1137 error = -ENOENT;
1138 goto out_unlock;
1139 }
1140
1141 ASSERT(ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL);
1142 error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
1143 &nimaps, XFS_BMAPI_ENTIRE | XFS_BMAPI_ATTRFORK);
1144out_unlock:
1145 xfs_iunlock(ip, lockmode);
1146
1147 if (!error) {
1148 ASSERT(nimaps);
1149 xfs_bmbt_to_iomap(ip, iomap, &imap);
1150 }
1151
1152 return error;
1153}
1154
1155struct iomap_ops xfs_xattr_iomap_ops = {
1156 .iomap_begin = xfs_xattr_iomap_begin,
1157};
diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h
index e066d045e2ff..fb8aca3d69ab 100644
--- a/fs/xfs/xfs_iomap.h
+++ b/fs/xfs/xfs_iomap.h
@@ -35,5 +35,6 @@ void xfs_bmbt_to_iomap(struct xfs_inode *, struct iomap *,
35 struct xfs_bmbt_irec *); 35 struct xfs_bmbt_irec *);
36 36
37extern struct iomap_ops xfs_iomap_ops; 37extern struct iomap_ops xfs_iomap_ops;
38extern struct iomap_ops xfs_xattr_iomap_ops;
38 39
39#endif /* __XFS_IOMAP_H__*/ 40#endif /* __XFS_IOMAP_H__*/
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index ab820f84ed50..b24c3102fa93 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -1009,7 +1009,14 @@ xfs_vn_fiemap(
1009 int error; 1009 int error;
1010 1010
1011 xfs_ilock(XFS_I(inode), XFS_IOLOCK_SHARED); 1011 xfs_ilock(XFS_I(inode), XFS_IOLOCK_SHARED);
1012 error = iomap_fiemap(inode, fieinfo, start, length, &xfs_iomap_ops); 1012 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
1013 fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR;
1014 error = iomap_fiemap(inode, fieinfo, start, length,
1015 &xfs_xattr_iomap_ops);
1016 } else {
1017 error = iomap_fiemap(inode, fieinfo, start, length,
1018 &xfs_iomap_ops);
1019 }
1013 xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED); 1020 xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED);
1014 1021
1015 return error; 1022 return error;
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index 551b7e26980c..7e88bec3f359 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -1298,7 +1298,6 @@ DEFINE_IOMAP_EVENT(xfs_get_blocks_alloc);
1298DEFINE_IOMAP_EVENT(xfs_get_blocks_map_direct); 1298DEFINE_IOMAP_EVENT(xfs_get_blocks_map_direct);
1299DEFINE_IOMAP_EVENT(xfs_iomap_alloc); 1299DEFINE_IOMAP_EVENT(xfs_iomap_alloc);
1300DEFINE_IOMAP_EVENT(xfs_iomap_found); 1300DEFINE_IOMAP_EVENT(xfs_iomap_found);
1301DEFINE_IOMAP_EVENT(xfs_iomap_not_found);
1302 1301
1303DECLARE_EVENT_CLASS(xfs_simple_io_class, 1302DECLARE_EVENT_CLASS(xfs_simple_io_class,
1304 TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count), 1303 TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count),
diff --git a/include/asm-generic/qrwlock.h b/include/asm-generic/qrwlock.h
index 54a8e65e18b6..7d026bf27713 100644
--- a/include/asm-generic/qrwlock.h
+++ b/include/asm-generic/qrwlock.h
@@ -25,7 +25,20 @@
25#include <asm-generic/qrwlock_types.h> 25#include <asm-generic/qrwlock_types.h>
26 26
27/* 27/*
28 * Writer states & reader shift and bias 28 * Writer states & reader shift and bias.
29 *
30 * | +0 | +1 | +2 | +3 |
31 * ----+----+----+----+----+
32 * LE | 78 | 56 | 34 | 12 | 0x12345678
33 * ----+----+----+----+----+
34 * | wr | rd |
35 * +----+----+----+----+
36 *
37 * ----+----+----+----+----+
38 * BE | 12 | 34 | 56 | 78 | 0x12345678
39 * ----+----+----+----+----+
40 * | rd | wr |
41 * +----+----+----+----+
29 */ 42 */
30#define _QW_WAITING 1 /* A writer is waiting */ 43#define _QW_WAITING 1 /* A writer is waiting */
31#define _QW_LOCKED 0xff /* A writer holds the lock */ 44#define _QW_LOCKED 0xff /* A writer holds the lock */
@@ -134,12 +147,22 @@ static inline void queued_read_unlock(struct qrwlock *lock)
134} 147}
135 148
136/** 149/**
150 * __qrwlock_write_byte - retrieve the write byte address of a queue rwlock
151 * @lock : Pointer to queue rwlock structure
152 * Return: the write byte address of a queue rwlock
153 */
154static inline u8 *__qrwlock_write_byte(struct qrwlock *lock)
155{
156 return (u8 *)lock + 3 * IS_BUILTIN(CONFIG_CPU_BIG_ENDIAN);
157}
158
159/**
137 * queued_write_unlock - release write lock of a queue rwlock 160 * queued_write_unlock - release write lock of a queue rwlock
138 * @lock : Pointer to queue rwlock structure 161 * @lock : Pointer to queue rwlock structure
139 */ 162 */
140static inline void queued_write_unlock(struct qrwlock *lock) 163static inline void queued_write_unlock(struct qrwlock *lock)
141{ 164{
142 smp_store_release((u8 *)&lock->cnts, 0); 165 smp_store_release(__qrwlock_write_byte(lock), 0);
143} 166}
144 167
145/* 168/*
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 59ffaa68b11b..23ddf4b46a9b 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -71,7 +71,8 @@ static inline bool bio_has_data(struct bio *bio)
71{ 71{
72 if (bio && 72 if (bio &&
73 bio->bi_iter.bi_size && 73 bio->bi_iter.bi_size &&
74 bio_op(bio) != REQ_OP_DISCARD) 74 bio_op(bio) != REQ_OP_DISCARD &&
75 bio_op(bio) != REQ_OP_SECURE_ERASE)
75 return true; 76 return true;
76 77
77 return false; 78 return false;
@@ -79,7 +80,9 @@ static inline bool bio_has_data(struct bio *bio)
79 80
80static inline bool bio_no_advance_iter(struct bio *bio) 81static inline bool bio_no_advance_iter(struct bio *bio)
81{ 82{
82 return bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_WRITE_SAME; 83 return bio_op(bio) == REQ_OP_DISCARD ||
84 bio_op(bio) == REQ_OP_SECURE_ERASE ||
85 bio_op(bio) == REQ_OP_WRITE_SAME;
83} 86}
84 87
85static inline bool bio_is_rw(struct bio *bio) 88static inline bool bio_is_rw(struct bio *bio)
@@ -199,6 +202,9 @@ static inline unsigned bio_segments(struct bio *bio)
199 if (bio_op(bio) == REQ_OP_DISCARD) 202 if (bio_op(bio) == REQ_OP_DISCARD)
200 return 1; 203 return 1;
201 204
205 if (bio_op(bio) == REQ_OP_SECURE_ERASE)
206 return 1;
207
202 if (bio_op(bio) == REQ_OP_WRITE_SAME) 208 if (bio_op(bio) == REQ_OP_WRITE_SAME)
203 return 1; 209 return 1;
204 210
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 2c210b6a7bcf..e79055c8b577 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -882,7 +882,7 @@ static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
882static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, 882static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
883 int op) 883 int op)
884{ 884{
885 if (unlikely(op == REQ_OP_DISCARD)) 885 if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE))
886 return min(q->limits.max_discard_sectors, UINT_MAX >> 9); 886 return min(q->limits.max_discard_sectors, UINT_MAX >> 9);
887 887
888 if (unlikely(op == REQ_OP_WRITE_SAME)) 888 if (unlikely(op == REQ_OP_WRITE_SAME))
@@ -913,7 +913,9 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
913 if (unlikely(rq->cmd_type != REQ_TYPE_FS)) 913 if (unlikely(rq->cmd_type != REQ_TYPE_FS))
914 return q->limits.max_hw_sectors; 914 return q->limits.max_hw_sectors;
915 915
916 if (!q->limits.chunk_sectors || (req_op(rq) == REQ_OP_DISCARD)) 916 if (!q->limits.chunk_sectors ||
917 req_op(rq) == REQ_OP_DISCARD ||
918 req_op(rq) == REQ_OP_SECURE_ERASE)
917 return blk_queue_get_max_sectors(q, req_op(rq)); 919 return blk_queue_get_max_sectors(q, req_op(rq));
918 920
919 return min(blk_max_size_offset(q, offset), 921 return min(blk_max_size_offset(q, offset),
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 701b64a3b7c5..89b65b82d98f 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -74,7 +74,8 @@ static inline void bvec_iter_advance(const struct bio_vec *bv,
74 "Attempted to advance past end of bvec iter\n"); 74 "Attempted to advance past end of bvec iter\n");
75 75
76 while (bytes) { 76 while (bytes) {
77 unsigned len = min(bytes, bvec_iter_len(bv, *iter)); 77 unsigned iter_len = bvec_iter_len(bv, *iter);
78 unsigned len = min(bytes, iter_len);
78 79
79 bytes -= len; 80 bytes -= len;
80 iter->bi_size -= len; 81 iter->bi_size -= len;
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index e2949397c19b..8dbc8929a6a0 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -242,7 +242,11 @@
242 */ 242 */
243#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) 243#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
244 244
245#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP 245/*
246 * sparse (__CHECKER__) pretends to be gcc, but can't do constant
247 * folding in __builtin_bswap*() (yet), so don't set these for it.
248 */
249#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) && !defined(__CHECKER__)
246#if GCC_VERSION >= 40400 250#if GCC_VERSION >= 40400
247#define __HAVE_BUILTIN_BSWAP32__ 251#define __HAVE_BUILTIN_BSWAP32__
248#define __HAVE_BUILTIN_BSWAP64__ 252#define __HAVE_BUILTIN_BSWAP64__
@@ -250,7 +254,7 @@
250#if GCC_VERSION >= 40800 254#if GCC_VERSION >= 40800
251#define __HAVE_BUILTIN_BSWAP16__ 255#define __HAVE_BUILTIN_BSWAP16__
252#endif 256#endif
253#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ 257#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */
254 258
255#if GCC_VERSION >= 50000 259#if GCC_VERSION >= 50000
256#define KASAN_ABI_VERSION 4 260#define KASAN_ABI_VERSION 4
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 1bb954842725..436aa4e42221 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -527,13 +527,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
527 * object's lifetime is managed by something other than RCU. That 527 * object's lifetime is managed by something other than RCU. That
528 * "something other" might be reference counting or simple immortality. 528 * "something other" might be reference counting or simple immortality.
529 * 529 *
530 * The seemingly unused void * variable is to validate @p is indeed a pointer 530 * The seemingly unused size_t variable is to validate @p is indeed a pointer
531 * type. All pointer types silently cast to void *. 531 * type by making sure it can be dereferenced.
532 */ 532 */
533#define lockless_dereference(p) \ 533#define lockless_dereference(p) \
534({ \ 534({ \
535 typeof(p) _________p1 = READ_ONCE(p); \ 535 typeof(p) _________p1 = READ_ONCE(p); \
536 __maybe_unused const void * const _________p2 = _________p1; \ 536 size_t __maybe_unused __size_of_ptr = sizeof(*(p)); \
537 smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ 537 smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
538 (_________p1); \ 538 (_________p1); \
539}) 539})
diff --git a/include/linux/host1x.h b/include/linux/host1x.h
index d2ba7d334039..1ffbf2a8cb99 100644
--- a/include/linux/host1x.h
+++ b/include/linux/host1x.h
@@ -304,6 +304,8 @@ struct tegra_mipi_device;
304 304
305struct tegra_mipi_device *tegra_mipi_request(struct device *device); 305struct tegra_mipi_device *tegra_mipi_request(struct device *device);
306void tegra_mipi_free(struct tegra_mipi_device *device); 306void tegra_mipi_free(struct tegra_mipi_device *device);
307int tegra_mipi_enable(struct tegra_mipi_device *device);
308int tegra_mipi_disable(struct tegra_mipi_device *device);
307int tegra_mipi_calibrate(struct tegra_mipi_device *device); 309int tegra_mipi_calibrate(struct tegra_mipi_device *device);
308 310
309#endif 311#endif
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index 56b0b7ec66aa..99ac022edc60 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -337,6 +337,7 @@
337 */ 337 */
338#define E_ITS_MOVI_UNMAPPED_INTERRUPT 0x010107 338#define E_ITS_MOVI_UNMAPPED_INTERRUPT 0x010107
339#define E_ITS_MOVI_UNMAPPED_COLLECTION 0x010109 339#define E_ITS_MOVI_UNMAPPED_COLLECTION 0x010109
340#define E_ITS_INT_UNMAPPED_INTERRUPT 0x010307
340#define E_ITS_CLEAR_UNMAPPED_INTERRUPT 0x010507 341#define E_ITS_CLEAR_UNMAPPED_INTERRUPT 0x010507
341#define E_ITS_MAPD_DEVICE_OOR 0x010801 342#define E_ITS_MAPD_DEVICE_OOR 0x010801
342#define E_ITS_MAPC_PROCNUM_OOR 0x010902 343#define E_ITS_MAPC_PROCNUM_OOR 0x010902
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 01e908ac4a39..9c28b4d4c90b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1113,9 +1113,21 @@ struct kvm_device {
1113/* create, destroy, and name are mandatory */ 1113/* create, destroy, and name are mandatory */
1114struct kvm_device_ops { 1114struct kvm_device_ops {
1115 const char *name; 1115 const char *name;
1116
1117 /*
1118 * create is called holding kvm->lock and any operations not suitable
1119 * to do while holding the lock should be deferred to init (see
1120 * below).
1121 */
1116 int (*create)(struct kvm_device *dev, u32 type); 1122 int (*create)(struct kvm_device *dev, u32 type);
1117 1123
1118 /* 1124 /*
1125 * init is called after create if create is successful and is called
1126 * outside of holding kvm->lock.
1127 */
1128 void (*init)(struct kvm_device *dev);
1129
1130 /*
1119 * Destroy is responsible for freeing dev. 1131 * Destroy is responsible for freeing dev.
1120 * 1132 *
1121 * Destroy may be called before or after destructors are called 1133 * Destroy may be called before or after destructors are called
diff --git a/include/linux/msi.h b/include/linux/msi.h
index 4f0bfe5912b2..e8c81fbd5f9c 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -270,6 +270,8 @@ enum {
270 MSI_FLAG_MULTI_PCI_MSI = (1 << 2), 270 MSI_FLAG_MULTI_PCI_MSI = (1 << 2),
271 /* Support PCI MSIX interrupts */ 271 /* Support PCI MSIX interrupts */
272 MSI_FLAG_PCI_MSIX = (1 << 3), 272 MSI_FLAG_PCI_MSIX = (1 << 3),
273 /* Needs early activate, required for PCI */
274 MSI_FLAG_ACTIVATE_EARLY = (1 << 4),
273}; 275};
274 276
275int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask, 277int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 076df5360ba5..3a788bf0affd 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3891,8 +3891,7 @@ void netdev_default_l2upper_neigh_destroy(struct net_device *dev,
3891extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; 3891extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
3892void netdev_rss_key_fill(void *buffer, size_t len); 3892void netdev_rss_key_fill(void *buffer, size_t len);
3893 3893
3894int dev_get_nest_level(struct net_device *dev, 3894int dev_get_nest_level(struct net_device *dev);
3895 bool (*type_check)(const struct net_device *dev));
3896int skb_checksum_help(struct sk_buff *skb); 3895int skb_checksum_help(struct sk_buff *skb);
3897struct sk_buff *__skb_gso_segment(struct sk_buff *skb, 3896struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
3898 netdev_features_t features, bool tx_path); 3897 netdev_features_t features, bool tx_path);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 2599a980340f..fbc1fa625c3e 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1251,10 +1251,12 @@ resource_size_t pcibios_iov_resource_alignment(struct pci_dev *dev, int resno);
1251int pci_set_vga_state(struct pci_dev *pdev, bool decode, 1251int pci_set_vga_state(struct pci_dev *pdev, bool decode,
1252 unsigned int command_bits, u32 flags); 1252 unsigned int command_bits, u32 flags);
1253 1253
1254#define PCI_IRQ_NOLEGACY (1 << 0) /* don't use legacy interrupts */ 1254#define PCI_IRQ_LEGACY (1 << 0) /* allow legacy interrupts */
1255#define PCI_IRQ_NOMSI (1 << 1) /* don't use MSI interrupts */ 1255#define PCI_IRQ_MSI (1 << 1) /* allow MSI interrupts */
1256#define PCI_IRQ_NOMSIX (1 << 2) /* don't use MSI-X interrupts */ 1256#define PCI_IRQ_MSIX (1 << 2) /* allow MSI-X interrupts */
1257#define PCI_IRQ_NOAFFINITY (1 << 3) /* don't auto-assign affinity */ 1257#define PCI_IRQ_AFFINITY (1 << 3) /* auto-assign affinity */
1258#define PCI_IRQ_ALL_TYPES \
1259 (PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
1258 1260
1259/* kmem_cache style wrapper around pci_alloc_consistent() */ 1261/* kmem_cache style wrapper around pci_alloc_consistent() */
1260 1262
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 8ed4326164cc..2b6b43cc0dd5 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -743,7 +743,9 @@ struct perf_event_context {
743 u64 parent_gen; 743 u64 parent_gen;
744 u64 generation; 744 u64 generation;
745 int pin_count; 745 int pin_count;
746#ifdef CONFIG_CGROUP_PERF
746 int nr_cgroups; /* cgroup evts */ 747 int nr_cgroups; /* cgroup evts */
748#endif
747 void *task_ctx_data; /* pmu specific data */ 749 void *task_ctx_data; /* pmu specific data */
748 struct rcu_head rcu_head; 750 struct rcu_head rcu_head;
749}; 751};
@@ -769,7 +771,9 @@ struct perf_cpu_context {
769 unsigned int hrtimer_active; 771 unsigned int hrtimer_active;
770 772
771 struct pmu *unique_pmu; 773 struct pmu *unique_pmu;
774#ifdef CONFIG_CGROUP_PERF
772 struct perf_cgroup *cgrp; 775 struct perf_cgroup *cgrp;
776#endif
773}; 777};
774 778
775struct perf_output_handle { 779struct perf_output_handle {
diff --git a/include/linux/qed/qed_if.h b/include/linux/qed/qed_if.h
index b1e3c57c7117..d6c4177df7cb 100644
--- a/include/linux/qed/qed_if.h
+++ b/include/linux/qed/qed_if.h
@@ -70,8 +70,16 @@ struct qed_dbcx_pfc_params {
70 u8 max_tc; 70 u8 max_tc;
71}; 71};
72 72
73enum qed_dcbx_sf_ieee_type {
74 QED_DCBX_SF_IEEE_ETHTYPE,
75 QED_DCBX_SF_IEEE_TCP_PORT,
76 QED_DCBX_SF_IEEE_UDP_PORT,
77 QED_DCBX_SF_IEEE_TCP_UDP_PORT
78};
79
73struct qed_app_entry { 80struct qed_app_entry {
74 bool ethtype; 81 bool ethtype;
82 enum qed_dcbx_sf_ieee_type sf_ieee;
75 bool enabled; 83 bool enabled;
76 u8 prio; 84 u8 prio;
77 u16 proto_id; 85 u16 proto_id;
diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index de1f64318fc4..fcb4c3646173 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -705,70 +705,6 @@ typedef struct sctp_auth_chunk {
705 sctp_authhdr_t auth_hdr; 705 sctp_authhdr_t auth_hdr;
706} __packed sctp_auth_chunk_t; 706} __packed sctp_auth_chunk_t;
707 707
708struct sctp_info {
709 __u32 sctpi_tag;
710 __u32 sctpi_state;
711 __u32 sctpi_rwnd;
712 __u16 sctpi_unackdata;
713 __u16 sctpi_penddata;
714 __u16 sctpi_instrms;
715 __u16 sctpi_outstrms;
716 __u32 sctpi_fragmentation_point;
717 __u32 sctpi_inqueue;
718 __u32 sctpi_outqueue;
719 __u32 sctpi_overall_error;
720 __u32 sctpi_max_burst;
721 __u32 sctpi_maxseg;
722 __u32 sctpi_peer_rwnd;
723 __u32 sctpi_peer_tag;
724 __u8 sctpi_peer_capable;
725 __u8 sctpi_peer_sack;
726 __u16 __reserved1;
727
728 /* assoc status info */
729 __u64 sctpi_isacks;
730 __u64 sctpi_osacks;
731 __u64 sctpi_opackets;
732 __u64 sctpi_ipackets;
733 __u64 sctpi_rtxchunks;
734 __u64 sctpi_outofseqtsns;
735 __u64 sctpi_idupchunks;
736 __u64 sctpi_gapcnt;
737 __u64 sctpi_ouodchunks;
738 __u64 sctpi_iuodchunks;
739 __u64 sctpi_oodchunks;
740 __u64 sctpi_iodchunks;
741 __u64 sctpi_octrlchunks;
742 __u64 sctpi_ictrlchunks;
743
744 /* primary transport info */
745 struct sockaddr_storage sctpi_p_address;
746 __s32 sctpi_p_state;
747 __u32 sctpi_p_cwnd;
748 __u32 sctpi_p_srtt;
749 __u32 sctpi_p_rto;
750 __u32 sctpi_p_hbinterval;
751 __u32 sctpi_p_pathmaxrxt;
752 __u32 sctpi_p_sackdelay;
753 __u32 sctpi_p_sackfreq;
754 __u32 sctpi_p_ssthresh;
755 __u32 sctpi_p_partial_bytes_acked;
756 __u32 sctpi_p_flight_size;
757 __u16 sctpi_p_error;
758 __u16 __reserved2;
759
760 /* sctp sock info */
761 __u32 sctpi_s_autoclose;
762 __u32 sctpi_s_adaptation_ind;
763 __u32 sctpi_s_pd_point;
764 __u8 sctpi_s_nodelay;
765 __u8 sctpi_s_disable_fragments;
766 __u8 sctpi_s_v4mapped;
767 __u8 sctpi_s_frag_interleave;
768 __u32 sctpi_s_type;
769 __u32 __reserved3;
770};
771
772struct sctp_infox { 708struct sctp_infox {
773 struct sctp_info *sctpinfo; 709 struct sctp_info *sctpinfo;
774 struct sctp_association *asoc; 710 struct sctp_association *asoc;
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 6f0b3e0adc73..0f665cb26b50 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2847,6 +2847,18 @@ static inline int skb_linearize_cow(struct sk_buff *skb)
2847 __skb_linearize(skb) : 0; 2847 __skb_linearize(skb) : 0;
2848} 2848}
2849 2849
2850static __always_inline void
2851__skb_postpull_rcsum(struct sk_buff *skb, const void *start, unsigned int len,
2852 unsigned int off)
2853{
2854 if (skb->ip_summed == CHECKSUM_COMPLETE)
2855 skb->csum = csum_block_sub(skb->csum,
2856 csum_partial(start, len, 0), off);
2857 else if (skb->ip_summed == CHECKSUM_PARTIAL &&
2858 skb_checksum_start_offset(skb) < 0)
2859 skb->ip_summed = CHECKSUM_NONE;
2860}
2861
2850/** 2862/**
2851 * skb_postpull_rcsum - update checksum for received skb after pull 2863 * skb_postpull_rcsum - update checksum for received skb after pull
2852 * @skb: buffer to update 2864 * @skb: buffer to update
@@ -2857,36 +2869,38 @@ static inline int skb_linearize_cow(struct sk_buff *skb)
2857 * update the CHECKSUM_COMPLETE checksum, or set ip_summed to 2869 * update the CHECKSUM_COMPLETE checksum, or set ip_summed to
2858 * CHECKSUM_NONE so that it can be recomputed from scratch. 2870 * CHECKSUM_NONE so that it can be recomputed from scratch.
2859 */ 2871 */
2860
2861static inline void skb_postpull_rcsum(struct sk_buff *skb, 2872static inline void skb_postpull_rcsum(struct sk_buff *skb,
2862 const void *start, unsigned int len) 2873 const void *start, unsigned int len)
2863{ 2874{
2864 if (skb->ip_summed == CHECKSUM_COMPLETE) 2875 __skb_postpull_rcsum(skb, start, len, 0);
2865 skb->csum = csum_sub(skb->csum, csum_partial(start, len, 0));
2866 else if (skb->ip_summed == CHECKSUM_PARTIAL &&
2867 skb_checksum_start_offset(skb) < 0)
2868 skb->ip_summed = CHECKSUM_NONE;
2869} 2876}
2870 2877
2871unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len); 2878static __always_inline void
2879__skb_postpush_rcsum(struct sk_buff *skb, const void *start, unsigned int len,
2880 unsigned int off)
2881{
2882 if (skb->ip_summed == CHECKSUM_COMPLETE)
2883 skb->csum = csum_block_add(skb->csum,
2884 csum_partial(start, len, 0), off);
2885}
2872 2886
2887/**
2888 * skb_postpush_rcsum - update checksum for received skb after push
2889 * @skb: buffer to update
2890 * @start: start of data after push
2891 * @len: length of data pushed
2892 *
2893 * After doing a push on a received packet, you need to call this to
2894 * update the CHECKSUM_COMPLETE checksum.
2895 */
2873static inline void skb_postpush_rcsum(struct sk_buff *skb, 2896static inline void skb_postpush_rcsum(struct sk_buff *skb,
2874 const void *start, unsigned int len) 2897 const void *start, unsigned int len)
2875{ 2898{
2876 /* For performing the reverse operation to skb_postpull_rcsum(), 2899 __skb_postpush_rcsum(skb, start, len, 0);
2877 * we can instead of ...
2878 *
2879 * skb->csum = csum_add(skb->csum, csum_partial(start, len, 0));
2880 *
2881 * ... just use this equivalent version here to save a few
2882 * instructions. Feeding csum of 0 in csum_partial() and later
2883 * on adding skb->csum is equivalent to feed skb->csum in the
2884 * first place.
2885 */
2886 if (skb->ip_summed == CHECKSUM_COMPLETE)
2887 skb->csum = csum_partial(start, len, skb->csum);
2888} 2900}
2889 2901
2902unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len);
2903
2890/** 2904/**
2891 * skb_push_rcsum - push skb and update receive checksum 2905 * skb_push_rcsum - push skb and update receive checksum
2892 * @skb: buffer to update 2906 * @skb: buffer to update
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index b6810c92b8bb..5c02b0691587 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -195,6 +195,8 @@ int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
195 struct rpc_xprt *, 195 struct rpc_xprt *,
196 void *), 196 void *),
197 void *data); 197 void *data);
198void rpc_cap_max_reconnect_timeout(struct rpc_clnt *clnt,
199 unsigned long timeo);
198 200
199const char *rpc_proc_name(const struct rpc_task *task); 201const char *rpc_proc_name(const struct rpc_task *task);
200#endif /* __KERNEL__ */ 202#endif /* __KERNEL__ */
diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index 5e3e1b63dbb3..a16070dd03ee 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -218,7 +218,8 @@ struct rpc_xprt {
218 struct work_struct task_cleanup; 218 struct work_struct task_cleanup;
219 struct timer_list timer; 219 struct timer_list timer;
220 unsigned long last_used, 220 unsigned long last_used,
221 idle_timeout; 221 idle_timeout,
222 max_reconnect_timeout;
222 223
223 /* 224 /*
224 * Send stuff 225 * Send stuff
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 697e160c78d0..a4f7203a9017 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -42,6 +42,8 @@ extern int proc_dostring(struct ctl_table *, int,
42 void __user *, size_t *, loff_t *); 42 void __user *, size_t *, loff_t *);
43extern int proc_dointvec(struct ctl_table *, int, 43extern int proc_dointvec(struct ctl_table *, int,
44 void __user *, size_t *, loff_t *); 44 void __user *, size_t *, loff_t *);
45extern int proc_douintvec(struct ctl_table *, int,
46 void __user *, size_t *, loff_t *);
45extern int proc_dointvec_minmax(struct ctl_table *, int, 47extern int proc_dointvec_minmax(struct ctl_table *, int,
46 void __user *, size_t *, loff_t *); 48 void __user *, size_t *, loff_t *);
47extern int proc_dointvec_jiffies(struct ctl_table *, int, 49extern int proc_dointvec_jiffies(struct ctl_table *, int,
diff --git a/include/net/act_api.h b/include/net/act_api.h
index 41e6a24a44b9..82f3c912a5b1 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -176,8 +176,8 @@ int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops);
176int tcf_unregister_action(struct tc_action_ops *a, 176int tcf_unregister_action(struct tc_action_ops *a,
177 struct pernet_operations *ops); 177 struct pernet_operations *ops);
178int tcf_action_destroy(struct list_head *actions, int bind); 178int tcf_action_destroy(struct list_head *actions, int bind);
179int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions, 179int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
180 struct tcf_result *res); 180 int nr_actions, struct tcf_result *res);
181int tcf_action_init(struct net *net, struct nlattr *nla, 181int tcf_action_init(struct net *net, struct nlattr *nla,
182 struct nlattr *est, char *n, int ovr, 182 struct nlattr *est, char *n, int ovr,
183 int bind, struct list_head *); 183 int bind, struct list_head *);
@@ -189,30 +189,17 @@ int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
189int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int); 189int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
190int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int); 190int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
191 191
192#define tc_no_actions(_exts) \ 192#endif /* CONFIG_NET_CLS_ACT */
193 (list_empty(&(_exts)->actions))
194
195#define tc_for_each_action(_a, _exts) \
196 list_for_each_entry(a, &(_exts)->actions, list)
197
198#define tc_single_action(_exts) \
199 (list_is_singular(&(_exts)->actions))
200 193
201static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes, 194static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
202 u64 packets, u64 lastuse) 195 u64 packets, u64 lastuse)
203{ 196{
197#ifdef CONFIG_NET_CLS_ACT
204 if (!a->ops->stats_update) 198 if (!a->ops->stats_update)
205 return; 199 return;
206 200
207 a->ops->stats_update(a, bytes, packets, lastuse); 201 a->ops->stats_update(a, bytes, packets, lastuse);
202#endif
208} 203}
209 204
210#else /* CONFIG_NET_CLS_ACT */
211
212#define tc_no_actions(_exts) true
213#define tc_for_each_action(_a, _exts) while ((void)(_a), 0)
214#define tc_single_action(_exts) false
215#define tcf_action_stats_update(a, bytes, packets, lastuse)
216
217#endif /* CONFIG_NET_CLS_ACT */
218#endif 205#endif
diff --git a/include/net/af_rxrpc.h b/include/net/af_rxrpc.h
index ac1bc3c49fbd..7b0f88699b25 100644
--- a/include/net/af_rxrpc.h
+++ b/include/net/af_rxrpc.h
@@ -40,12 +40,12 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *,
40 unsigned long, 40 unsigned long,
41 gfp_t); 41 gfp_t);
42int rxrpc_kernel_send_data(struct rxrpc_call *, struct msghdr *, size_t); 42int rxrpc_kernel_send_data(struct rxrpc_call *, struct msghdr *, size_t);
43void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
43void rxrpc_kernel_abort_call(struct rxrpc_call *, u32); 44void rxrpc_kernel_abort_call(struct rxrpc_call *, u32);
44void rxrpc_kernel_end_call(struct rxrpc_call *); 45void rxrpc_kernel_end_call(struct rxrpc_call *);
45bool rxrpc_kernel_is_data_last(struct sk_buff *); 46bool rxrpc_kernel_is_data_last(struct sk_buff *);
46u32 rxrpc_kernel_get_abort_code(struct sk_buff *); 47u32 rxrpc_kernel_get_abort_code(struct sk_buff *);
47int rxrpc_kernel_get_error_number(struct sk_buff *); 48int rxrpc_kernel_get_error_number(struct sk_buff *);
48void rxrpc_kernel_data_delivered(struct sk_buff *);
49void rxrpc_kernel_free_skb(struct sk_buff *); 49void rxrpc_kernel_free_skb(struct sk_buff *);
50struct rxrpc_call *rxrpc_kernel_accept_call(struct socket *, unsigned long); 50struct rxrpc_call *rxrpc_kernel_accept_call(struct socket *, unsigned long);
51int rxrpc_kernel_reject_call(struct socket *); 51int rxrpc_kernel_reject_call(struct socket *);
diff --git a/include/net/gre.h b/include/net/gre.h
index 7a54a31d1d4c..73ea256eb7d7 100644
--- a/include/net/gre.h
+++ b/include/net/gre.h
@@ -104,6 +104,7 @@ static inline void gre_build_header(struct sk_buff *skb, int hdr_len,
104 104
105 skb_push(skb, hdr_len); 105 skb_push(skb, hdr_len);
106 106
107 skb_set_inner_protocol(skb, proto);
107 skb_reset_transport_header(skb); 108 skb_reset_transport_header(skb);
108 greh = (struct gre_base_hdr *)skb->data; 109 greh = (struct gre_base_hdr *)skb->data;
109 greh->flags = gre_tnl_flags_to_gre_flags(flags); 110 greh->flags = gre_tnl_flags_to_gre_flags(flags);
diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h
index 0dc0a51da38f..dce2d586d9ce 100644
--- a/include/net/inet_ecn.h
+++ b/include/net/inet_ecn.h
@@ -128,7 +128,8 @@ static inline int IP6_ECN_set_ce(struct sk_buff *skb, struct ipv6hdr *iph)
128 to = from | htonl(INET_ECN_CE << 20); 128 to = from | htonl(INET_ECN_CE << 20);
129 *(__be32 *)iph = to; 129 *(__be32 *)iph = to;
130 if (skb->ip_summed == CHECKSUM_COMPLETE) 130 if (skb->ip_summed == CHECKSUM_COMPLETE)
131 skb->csum = csum_add(csum_sub(skb->csum, from), to); 131 skb->csum = csum_add(csum_sub(skb->csum, (__force __wsum)from),
132 (__force __wsum)to);
132 return 1; 133 return 1;
133} 134}
134 135
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index b4faadbb4e01..cca510a585c3 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -3620,7 +3620,8 @@ struct ieee80211_ops {
3620 3620
3621 int (*join_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 3621 int (*join_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
3622 void (*leave_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 3622 void (*leave_ibss)(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
3623 u32 (*get_expected_throughput)(struct ieee80211_sta *sta); 3623 u32 (*get_expected_throughput)(struct ieee80211_hw *hw,
3624 struct ieee80211_sta *sta);
3624 int (*get_txpower)(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3625 int (*get_txpower)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3625 int *dbm); 3626 int *dbm);
3626 3627
diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index 6f8d65342d3a..c99508d426cc 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -59,7 +59,8 @@ tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
59struct tcf_exts { 59struct tcf_exts {
60#ifdef CONFIG_NET_CLS_ACT 60#ifdef CONFIG_NET_CLS_ACT
61 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ 61 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
62 struct list_head actions; 62 int nr_actions;
63 struct tc_action **actions;
63#endif 64#endif
64 /* Map to export classifier specific extension TLV types to the 65 /* Map to export classifier specific extension TLV types to the
65 * generic extensions API. Unsupported extensions must be set to 0. 66 * generic extensions API. Unsupported extensions must be set to 0.
@@ -72,7 +73,10 @@ static inline void tcf_exts_init(struct tcf_exts *exts, int action, int police)
72{ 73{
73#ifdef CONFIG_NET_CLS_ACT 74#ifdef CONFIG_NET_CLS_ACT
74 exts->type = 0; 75 exts->type = 0;
75 INIT_LIST_HEAD(&exts->actions); 76 exts->nr_actions = 0;
77 exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *),
78 GFP_KERNEL);
79 WARN_ON(!exts->actions); /* TODO: propagate the error to callers */
76#endif 80#endif
77 exts->action = action; 81 exts->action = action;
78 exts->police = police; 82 exts->police = police;
@@ -89,7 +93,7 @@ static inline int
89tcf_exts_is_predicative(struct tcf_exts *exts) 93tcf_exts_is_predicative(struct tcf_exts *exts)
90{ 94{
91#ifdef CONFIG_NET_CLS_ACT 95#ifdef CONFIG_NET_CLS_ACT
92 return !list_empty(&exts->actions); 96 return exts->nr_actions;
93#else 97#else
94 return 0; 98 return 0;
95#endif 99#endif
@@ -108,6 +112,20 @@ tcf_exts_is_available(struct tcf_exts *exts)
108 return tcf_exts_is_predicative(exts); 112 return tcf_exts_is_predicative(exts);
109} 113}
110 114
115static inline void tcf_exts_to_list(const struct tcf_exts *exts,
116 struct list_head *actions)
117{
118#ifdef CONFIG_NET_CLS_ACT
119 int i;
120
121 for (i = 0; i < exts->nr_actions; i++) {
122 struct tc_action *a = exts->actions[i];
123
124 list_add(&a->list, actions);
125 }
126#endif
127}
128
111/** 129/**
112 * tcf_exts_exec - execute tc filter extensions 130 * tcf_exts_exec - execute tc filter extensions
113 * @skb: socket buffer 131 * @skb: socket buffer
@@ -124,12 +142,25 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
124 struct tcf_result *res) 142 struct tcf_result *res)
125{ 143{
126#ifdef CONFIG_NET_CLS_ACT 144#ifdef CONFIG_NET_CLS_ACT
127 if (!list_empty(&exts->actions)) 145 if (exts->nr_actions)
128 return tcf_action_exec(skb, &exts->actions, res); 146 return tcf_action_exec(skb, exts->actions, exts->nr_actions,
147 res);
129#endif 148#endif
130 return 0; 149 return 0;
131} 150}
132 151
152#ifdef CONFIG_NET_CLS_ACT
153
154#define tc_no_actions(_exts) ((_exts)->nr_actions == 0)
155#define tc_single_action(_exts) ((_exts)->nr_actions == 1)
156
157#else /* CONFIG_NET_CLS_ACT */
158
159#define tc_no_actions(_exts) true
160#define tc_single_action(_exts) false
161
162#endif /* CONFIG_NET_CLS_ACT */
163
133int tcf_exts_validate(struct net *net, struct tcf_proto *tp, 164int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
134 struct nlattr **tb, struct nlattr *rate_tlv, 165 struct nlattr **tb, struct nlattr *rate_tlv,
135 struct tcf_exts *exts, bool ovr); 166 struct tcf_exts *exts, bool ovr);
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 8e90dd28bb75..e1f96737c2a1 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -2115,22 +2115,17 @@ static inline bool ib_is_udata_cleared(struct ib_udata *udata,
2115 size_t len) 2115 size_t len)
2116{ 2116{
2117 const void __user *p = udata->inbuf + offset; 2117 const void __user *p = udata->inbuf + offset;
2118 bool ret = false; 2118 bool ret;
2119 u8 *buf; 2119 u8 *buf;
2120 2120
2121 if (len > USHRT_MAX) 2121 if (len > USHRT_MAX)
2122 return false; 2122 return false;
2123 2123
2124 buf = kmalloc(len, GFP_KERNEL); 2124 buf = memdup_user(p, len);
2125 if (!buf) 2125 if (IS_ERR(buf))
2126 return false; 2126 return false;
2127 2127
2128 if (copy_from_user(buf, p, len))
2129 goto free;
2130
2131 ret = !memchr_inv(buf, 0, len); 2128 ret = !memchr_inv(buf, 0, len);
2132
2133free:
2134 kfree(buf); 2129 kfree(buf);
2135 return ret; 2130 return ret;
2136} 2131}
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index da218fec6056..9e5fc168c8a3 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -339,7 +339,7 @@ enum bpf_func_id {
339 BPF_FUNC_skb_change_type, 339 BPF_FUNC_skb_change_type,
340 340
341 /** 341 /**
342 * bpf_skb_in_cgroup(skb, map, index) - Check cgroup2 membership of skb 342 * bpf_skb_under_cgroup(skb, map, index) - Check cgroup2 membership of skb
343 * @skb: pointer to skb 343 * @skb: pointer to skb
344 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type 344 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
345 * @index: index of the cgroup in the bpf_map 345 * @index: index of the cgroup in the bpf_map
@@ -348,7 +348,7 @@ enum bpf_func_id {
348 * == 1 skb succeeded the cgroup2 descendant test 348 * == 1 skb succeeded the cgroup2 descendant test
349 * < 0 error 349 * < 0 error
350 */ 350 */
351 BPF_FUNC_skb_in_cgroup, 351 BPF_FUNC_skb_under_cgroup,
352 352
353 /** 353 /**
354 * bpf_get_hash_recalc(skb) 354 * bpf_get_hash_recalc(skb)
diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
index 01751faccaf8..c674ba2563b7 100644
--- a/include/uapi/linux/netfilter/nf_tables.h
+++ b/include/uapi/linux/netfilter/nf_tables.h
@@ -24,7 +24,7 @@ enum nft_registers {
24 __NFT_REG_MAX, 24 __NFT_REG_MAX,
25 25
26 NFT_REG32_00 = 8, 26 NFT_REG32_00 = 8,
27 MFT_REG32_01, 27 NFT_REG32_01,
28 NFT_REG32_02, 28 NFT_REG32_02,
29 NFT_REG32_03, 29 NFT_REG32_03,
30 NFT_REG32_04, 30 NFT_REG32_04,
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index d304f4c9792c..a406adcc0793 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -944,4 +944,68 @@ struct sctp_default_prinfo {
944 __u16 pr_policy; 944 __u16 pr_policy;
945}; 945};
946 946
947struct sctp_info {
948 __u32 sctpi_tag;
949 __u32 sctpi_state;
950 __u32 sctpi_rwnd;
951 __u16 sctpi_unackdata;
952 __u16 sctpi_penddata;
953 __u16 sctpi_instrms;
954 __u16 sctpi_outstrms;
955 __u32 sctpi_fragmentation_point;
956 __u32 sctpi_inqueue;
957 __u32 sctpi_outqueue;
958 __u32 sctpi_overall_error;
959 __u32 sctpi_max_burst;
960 __u32 sctpi_maxseg;
961 __u32 sctpi_peer_rwnd;
962 __u32 sctpi_peer_tag;
963 __u8 sctpi_peer_capable;
964 __u8 sctpi_peer_sack;
965 __u16 __reserved1;
966
967 /* assoc status info */
968 __u64 sctpi_isacks;
969 __u64 sctpi_osacks;
970 __u64 sctpi_opackets;
971 __u64 sctpi_ipackets;
972 __u64 sctpi_rtxchunks;
973 __u64 sctpi_outofseqtsns;
974 __u64 sctpi_idupchunks;
975 __u64 sctpi_gapcnt;
976 __u64 sctpi_ouodchunks;
977 __u64 sctpi_iuodchunks;
978 __u64 sctpi_oodchunks;
979 __u64 sctpi_iodchunks;
980 __u64 sctpi_octrlchunks;
981 __u64 sctpi_ictrlchunks;
982
983 /* primary transport info */
984 struct sockaddr_storage sctpi_p_address;
985 __s32 sctpi_p_state;
986 __u32 sctpi_p_cwnd;
987 __u32 sctpi_p_srtt;
988 __u32 sctpi_p_rto;
989 __u32 sctpi_p_hbinterval;
990 __u32 sctpi_p_pathmaxrxt;
991 __u32 sctpi_p_sackdelay;
992 __u32 sctpi_p_sackfreq;
993 __u32 sctpi_p_ssthresh;
994 __u32 sctpi_p_partial_bytes_acked;
995 __u32 sctpi_p_flight_size;
996 __u16 sctpi_p_error;
997 __u16 __reserved2;
998
999 /* sctp sock info */
1000 __u32 sctpi_s_autoclose;
1001 __u32 sctpi_s_adaptation_ind;
1002 __u32 sctpi_s_pd_point;
1003 __u8 sctpi_s_nodelay;
1004 __u8 sctpi_s_disable_fragments;
1005 __u8 sctpi_s_v4mapped;
1006 __u8 sctpi_s_frag_interleave;
1007 __u32 sctpi_s_type;
1008 __u32 __reserved3;
1009};
1010
947#endif /* _UAPI_SCTP_H */ 1011#endif /* _UAPI_SCTP_H */
diff --git a/include/uapi/linux/virtio_vsock.h b/include/uapi/linux/virtio_vsock.h
index 6b011c19b50f..1d57ed3d84d2 100644
--- a/include/uapi/linux/virtio_vsock.h
+++ b/include/uapi/linux/virtio_vsock.h
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#ifndef _UAPI_LINUX_VIRTIO_VSOCK_H 34#ifndef _UAPI_LINUX_VIRTIO_VSOCK_H
35#define _UAPI_LINUX_VIRTIO_VOSCK_H 35#define _UAPI_LINUX_VIRTIO_VSOCK_H
36 36
37#include <linux/types.h> 37#include <linux/types.h>
38#include <linux/virtio_ids.h> 38#include <linux/virtio_ids.h>
diff --git a/include/uapi/misc/cxl.h b/include/uapi/misc/cxl.h
index cbae529b7ce0..180d526a55c3 100644
--- a/include/uapi/misc/cxl.h
+++ b/include/uapi/misc/cxl.h
@@ -136,8 +136,8 @@ struct cxl_event_afu_driver_reserved {
136 * 136 *
137 * Of course the contents will be ABI, but that's up the AFU driver. 137 * Of course the contents will be ABI, but that's up the AFU driver.
138 */ 138 */
139 size_t data_size; 139 __u32 data_size;
140 u8 data[]; 140 __u8 data[];
141}; 141};
142 142
143struct cxl_event { 143struct cxl_event {
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index 9a37c541822f..b5486e648607 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -9,8 +9,8 @@
9 9
10DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu); 10DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
11 11
12DECLARE_PER_CPU(int, xen_vcpu_id); 12DECLARE_PER_CPU(uint32_t, xen_vcpu_id);
13static inline int xen_vcpu_nr(int cpu) 13static inline uint32_t xen_vcpu_nr(int cpu)
14{ 14{
15 return per_cpu(xen_vcpu_id, cpu); 15 return per_cpu(xen_vcpu_id, cpu);
16} 16}
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index fff3650d52fc..570eeca7bdfa 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -26,11 +26,18 @@ struct bpf_htab {
26 struct bucket *buckets; 26 struct bucket *buckets;
27 void *elems; 27 void *elems;
28 struct pcpu_freelist freelist; 28 struct pcpu_freelist freelist;
29 void __percpu *extra_elems;
29 atomic_t count; /* number of elements in this hashtable */ 30 atomic_t count; /* number of elements in this hashtable */
30 u32 n_buckets; /* number of hash buckets */ 31 u32 n_buckets; /* number of hash buckets */
31 u32 elem_size; /* size of each element in bytes */ 32 u32 elem_size; /* size of each element in bytes */
32}; 33};
33 34
35enum extra_elem_state {
36 HTAB_NOT_AN_EXTRA_ELEM = 0,
37 HTAB_EXTRA_ELEM_FREE,
38 HTAB_EXTRA_ELEM_USED
39};
40
34/* each htab element is struct htab_elem + key + value */ 41/* each htab element is struct htab_elem + key + value */
35struct htab_elem { 42struct htab_elem {
36 union { 43 union {
@@ -38,7 +45,10 @@ struct htab_elem {
38 struct bpf_htab *htab; 45 struct bpf_htab *htab;
39 struct pcpu_freelist_node fnode; 46 struct pcpu_freelist_node fnode;
40 }; 47 };
41 struct rcu_head rcu; 48 union {
49 struct rcu_head rcu;
50 enum extra_elem_state state;
51 };
42 u32 hash; 52 u32 hash;
43 char key[0] __aligned(8); 53 char key[0] __aligned(8);
44}; 54};
@@ -113,6 +123,23 @@ free_elems:
113 return err; 123 return err;
114} 124}
115 125
126static int alloc_extra_elems(struct bpf_htab *htab)
127{
128 void __percpu *pptr;
129 int cpu;
130
131 pptr = __alloc_percpu_gfp(htab->elem_size, 8, GFP_USER | __GFP_NOWARN);
132 if (!pptr)
133 return -ENOMEM;
134
135 for_each_possible_cpu(cpu) {
136 ((struct htab_elem *)per_cpu_ptr(pptr, cpu))->state =
137 HTAB_EXTRA_ELEM_FREE;
138 }
139 htab->extra_elems = pptr;
140 return 0;
141}
142
116/* Called from syscall */ 143/* Called from syscall */
117static struct bpf_map *htab_map_alloc(union bpf_attr *attr) 144static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
118{ 145{
@@ -185,6 +212,8 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
185 if (percpu) 212 if (percpu)
186 cost += (u64) round_up(htab->map.value_size, 8) * 213 cost += (u64) round_up(htab->map.value_size, 8) *
187 num_possible_cpus() * htab->map.max_entries; 214 num_possible_cpus() * htab->map.max_entries;
215 else
216 cost += (u64) htab->elem_size * num_possible_cpus();
188 217
189 if (cost >= U32_MAX - PAGE_SIZE) 218 if (cost >= U32_MAX - PAGE_SIZE)
190 /* make sure page count doesn't overflow */ 219 /* make sure page count doesn't overflow */
@@ -212,14 +241,22 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
212 raw_spin_lock_init(&htab->buckets[i].lock); 241 raw_spin_lock_init(&htab->buckets[i].lock);
213 } 242 }
214 243
244 if (!percpu) {
245 err = alloc_extra_elems(htab);
246 if (err)
247 goto free_buckets;
248 }
249
215 if (!(attr->map_flags & BPF_F_NO_PREALLOC)) { 250 if (!(attr->map_flags & BPF_F_NO_PREALLOC)) {
216 err = prealloc_elems_and_freelist(htab); 251 err = prealloc_elems_and_freelist(htab);
217 if (err) 252 if (err)
218 goto free_buckets; 253 goto free_extra_elems;
219 } 254 }
220 255
221 return &htab->map; 256 return &htab->map;
222 257
258free_extra_elems:
259 free_percpu(htab->extra_elems);
223free_buckets: 260free_buckets:
224 kvfree(htab->buckets); 261 kvfree(htab->buckets);
225free_htab: 262free_htab:
@@ -349,7 +386,6 @@ static void htab_elem_free(struct bpf_htab *htab, struct htab_elem *l)
349 if (htab->map.map_type == BPF_MAP_TYPE_PERCPU_HASH) 386 if (htab->map.map_type == BPF_MAP_TYPE_PERCPU_HASH)
350 free_percpu(htab_elem_get_ptr(l, htab->map.key_size)); 387 free_percpu(htab_elem_get_ptr(l, htab->map.key_size));
351 kfree(l); 388 kfree(l);
352
353} 389}
354 390
355static void htab_elem_free_rcu(struct rcu_head *head) 391static void htab_elem_free_rcu(struct rcu_head *head)
@@ -370,6 +406,11 @@ static void htab_elem_free_rcu(struct rcu_head *head)
370 406
371static void free_htab_elem(struct bpf_htab *htab, struct htab_elem *l) 407static void free_htab_elem(struct bpf_htab *htab, struct htab_elem *l)
372{ 408{
409 if (l->state == HTAB_EXTRA_ELEM_USED) {
410 l->state = HTAB_EXTRA_ELEM_FREE;
411 return;
412 }
413
373 if (!(htab->map.map_flags & BPF_F_NO_PREALLOC)) { 414 if (!(htab->map.map_flags & BPF_F_NO_PREALLOC)) {
374 pcpu_freelist_push(&htab->freelist, &l->fnode); 415 pcpu_freelist_push(&htab->freelist, &l->fnode);
375 } else { 416 } else {
@@ -381,25 +422,44 @@ static void free_htab_elem(struct bpf_htab *htab, struct htab_elem *l)
381 422
382static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key, 423static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key,
383 void *value, u32 key_size, u32 hash, 424 void *value, u32 key_size, u32 hash,
384 bool percpu, bool onallcpus) 425 bool percpu, bool onallcpus,
426 bool old_elem_exists)
385{ 427{
386 u32 size = htab->map.value_size; 428 u32 size = htab->map.value_size;
387 bool prealloc = !(htab->map.map_flags & BPF_F_NO_PREALLOC); 429 bool prealloc = !(htab->map.map_flags & BPF_F_NO_PREALLOC);
388 struct htab_elem *l_new; 430 struct htab_elem *l_new;
389 void __percpu *pptr; 431 void __percpu *pptr;
432 int err = 0;
390 433
391 if (prealloc) { 434 if (prealloc) {
392 l_new = (struct htab_elem *)pcpu_freelist_pop(&htab->freelist); 435 l_new = (struct htab_elem *)pcpu_freelist_pop(&htab->freelist);
393 if (!l_new) 436 if (!l_new)
394 return ERR_PTR(-E2BIG); 437 err = -E2BIG;
395 } else { 438 } else {
396 if (atomic_inc_return(&htab->count) > htab->map.max_entries) { 439 if (atomic_inc_return(&htab->count) > htab->map.max_entries) {
397 atomic_dec(&htab->count); 440 atomic_dec(&htab->count);
398 return ERR_PTR(-E2BIG); 441 err = -E2BIG;
442 } else {
443 l_new = kmalloc(htab->elem_size,
444 GFP_ATOMIC | __GFP_NOWARN);
445 if (!l_new)
446 return ERR_PTR(-ENOMEM);
399 } 447 }
400 l_new = kmalloc(htab->elem_size, GFP_ATOMIC | __GFP_NOWARN); 448 }
401 if (!l_new) 449
402 return ERR_PTR(-ENOMEM); 450 if (err) {
451 if (!old_elem_exists)
452 return ERR_PTR(err);
453
454 /* if we're updating the existing element and the hash table
455 * is full, use per-cpu extra elems
456 */
457 l_new = this_cpu_ptr(htab->extra_elems);
458 if (l_new->state != HTAB_EXTRA_ELEM_FREE)
459 return ERR_PTR(-E2BIG);
460 l_new->state = HTAB_EXTRA_ELEM_USED;
461 } else {
462 l_new->state = HTAB_NOT_AN_EXTRA_ELEM;
403 } 463 }
404 464
405 memcpy(l_new->key, key, key_size); 465 memcpy(l_new->key, key, key_size);
@@ -489,7 +549,8 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
489 if (ret) 549 if (ret)
490 goto err; 550 goto err;
491 551
492 l_new = alloc_htab_elem(htab, key, value, key_size, hash, false, false); 552 l_new = alloc_htab_elem(htab, key, value, key_size, hash, false, false,
553 !!l_old);
493 if (IS_ERR(l_new)) { 554 if (IS_ERR(l_new)) {
494 /* all pre-allocated elements are in use or memory exhausted */ 555 /* all pre-allocated elements are in use or memory exhausted */
495 ret = PTR_ERR(l_new); 556 ret = PTR_ERR(l_new);
@@ -563,7 +624,7 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
563 } 624 }
564 } else { 625 } else {
565 l_new = alloc_htab_elem(htab, key, value, key_size, 626 l_new = alloc_htab_elem(htab, key, value, key_size,
566 hash, true, onallcpus); 627 hash, true, onallcpus, false);
567 if (IS_ERR(l_new)) { 628 if (IS_ERR(l_new)) {
568 ret = PTR_ERR(l_new); 629 ret = PTR_ERR(l_new);
569 goto err; 630 goto err;
@@ -652,6 +713,7 @@ static void htab_map_free(struct bpf_map *map)
652 htab_free_elems(htab); 713 htab_free_elems(htab);
653 pcpu_freelist_destroy(&htab->freelist); 714 pcpu_freelist_destroy(&htab->freelist);
654 } 715 }
716 free_percpu(htab->extra_elems);
655 kvfree(htab->buckets); 717 kvfree(htab->buckets);
656 kfree(htab); 718 kfree(htab);
657} 719}
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index f72f23b8fdab..daea765d72e6 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -194,6 +194,7 @@ struct verifier_env {
194 struct verifier_state_list **explored_states; /* search pruning optimization */ 194 struct verifier_state_list **explored_states; /* search pruning optimization */
195 struct bpf_map *used_maps[MAX_USED_MAPS]; /* array of map's used by eBPF program */ 195 struct bpf_map *used_maps[MAX_USED_MAPS]; /* array of map's used by eBPF program */
196 u32 used_map_cnt; /* number of used maps */ 196 u32 used_map_cnt; /* number of used maps */
197 u32 id_gen; /* used to generate unique reg IDs */
197 bool allow_ptr_leaks; 198 bool allow_ptr_leaks;
198}; 199};
199 200
@@ -1052,7 +1053,7 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id)
1052 goto error; 1053 goto error;
1053 break; 1054 break;
1054 case BPF_MAP_TYPE_CGROUP_ARRAY: 1055 case BPF_MAP_TYPE_CGROUP_ARRAY:
1055 if (func_id != BPF_FUNC_skb_in_cgroup) 1056 if (func_id != BPF_FUNC_skb_under_cgroup)
1056 goto error; 1057 goto error;
1057 break; 1058 break;
1058 default: 1059 default:
@@ -1074,7 +1075,7 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id)
1074 if (map->map_type != BPF_MAP_TYPE_STACK_TRACE) 1075 if (map->map_type != BPF_MAP_TYPE_STACK_TRACE)
1075 goto error; 1076 goto error;
1076 break; 1077 break;
1077 case BPF_FUNC_skb_in_cgroup: 1078 case BPF_FUNC_skb_under_cgroup:
1078 if (map->map_type != BPF_MAP_TYPE_CGROUP_ARRAY) 1079 if (map->map_type != BPF_MAP_TYPE_CGROUP_ARRAY)
1079 goto error; 1080 goto error;
1080 break; 1081 break;
@@ -1301,7 +1302,7 @@ add_imm:
1301 /* dst_reg stays as pkt_ptr type and since some positive 1302 /* dst_reg stays as pkt_ptr type and since some positive
1302 * integer value was added to the pointer, increment its 'id' 1303 * integer value was added to the pointer, increment its 'id'
1303 */ 1304 */
1304 dst_reg->id++; 1305 dst_reg->id = ++env->id_gen;
1305 1306
1306 /* something was added to pkt_ptr, set range and off to zero */ 1307 /* something was added to pkt_ptr, set range and off to zero */
1307 dst_reg->off = 0; 1308 dst_reg->off = 0;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index a19550d80ab1..3cfabdf7b942 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -242,18 +242,6 @@ unlock:
242 return ret; 242 return ret;
243} 243}
244 244
245static void event_function_local(struct perf_event *event, event_f func, void *data)
246{
247 struct event_function_struct efs = {
248 .event = event,
249 .func = func,
250 .data = data,
251 };
252
253 int ret = event_function(&efs);
254 WARN_ON_ONCE(ret);
255}
256
257static void event_function_call(struct perf_event *event, event_f func, void *data) 245static void event_function_call(struct perf_event *event, event_f func, void *data)
258{ 246{
259 struct perf_event_context *ctx = event->ctx; 247 struct perf_event_context *ctx = event->ctx;
@@ -303,6 +291,54 @@ again:
303 raw_spin_unlock_irq(&ctx->lock); 291 raw_spin_unlock_irq(&ctx->lock);
304} 292}
305 293
294/*
295 * Similar to event_function_call() + event_function(), but hard assumes IRQs
296 * are already disabled and we're on the right CPU.
297 */
298static void event_function_local(struct perf_event *event, event_f func, void *data)
299{
300 struct perf_event_context *ctx = event->ctx;
301 struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
302 struct task_struct *task = READ_ONCE(ctx->task);
303 struct perf_event_context *task_ctx = NULL;
304
305 WARN_ON_ONCE(!irqs_disabled());
306
307 if (task) {
308 if (task == TASK_TOMBSTONE)
309 return;
310
311 task_ctx = ctx;
312 }
313
314 perf_ctx_lock(cpuctx, task_ctx);
315
316 task = ctx->task;
317 if (task == TASK_TOMBSTONE)
318 goto unlock;
319
320 if (task) {
321 /*
322 * We must be either inactive or active and the right task,
323 * otherwise we're screwed, since we cannot IPI to somewhere
324 * else.
325 */
326 if (ctx->is_active) {
327 if (WARN_ON_ONCE(task != current))
328 goto unlock;
329
330 if (WARN_ON_ONCE(cpuctx->task_ctx != ctx))
331 goto unlock;
332 }
333 } else {
334 WARN_ON_ONCE(&cpuctx->ctx != ctx);
335 }
336
337 func(event, cpuctx, ctx, data);
338unlock:
339 perf_ctx_unlock(cpuctx, task_ctx);
340}
341
306#define PERF_FLAG_ALL (PERF_FLAG_FD_NO_GROUP |\ 342#define PERF_FLAG_ALL (PERF_FLAG_FD_NO_GROUP |\
307 PERF_FLAG_FD_OUTPUT |\ 343 PERF_FLAG_FD_OUTPUT |\
308 PERF_FLAG_PID_CGROUP |\ 344 PERF_FLAG_PID_CGROUP |\
@@ -843,6 +879,32 @@ perf_cgroup_mark_enabled(struct perf_event *event,
843 } 879 }
844 } 880 }
845} 881}
882
883/*
884 * Update cpuctx->cgrp so that it is set when first cgroup event is added and
885 * cleared when last cgroup event is removed.
886 */
887static inline void
888list_update_cgroup_event(struct perf_event *event,
889 struct perf_event_context *ctx, bool add)
890{
891 struct perf_cpu_context *cpuctx;
892
893 if (!is_cgroup_event(event))
894 return;
895
896 if (add && ctx->nr_cgroups++)
897 return;
898 else if (!add && --ctx->nr_cgroups)
899 return;
900 /*
901 * Because cgroup events are always per-cpu events,
902 * this will always be called from the right CPU.
903 */
904 cpuctx = __get_cpu_context(ctx);
905 cpuctx->cgrp = add ? event->cgrp : NULL;
906}
907
846#else /* !CONFIG_CGROUP_PERF */ 908#else /* !CONFIG_CGROUP_PERF */
847 909
848static inline bool 910static inline bool
@@ -920,6 +982,13 @@ perf_cgroup_mark_enabled(struct perf_event *event,
920 struct perf_event_context *ctx) 982 struct perf_event_context *ctx)
921{ 983{
922} 984}
985
986static inline void
987list_update_cgroup_event(struct perf_event *event,
988 struct perf_event_context *ctx, bool add)
989{
990}
991
923#endif 992#endif
924 993
925/* 994/*
@@ -1392,6 +1461,7 @@ ctx_group_list(struct perf_event *event, struct perf_event_context *ctx)
1392static void 1461static void
1393list_add_event(struct perf_event *event, struct perf_event_context *ctx) 1462list_add_event(struct perf_event *event, struct perf_event_context *ctx)
1394{ 1463{
1464
1395 lockdep_assert_held(&ctx->lock); 1465 lockdep_assert_held(&ctx->lock);
1396 1466
1397 WARN_ON_ONCE(event->attach_state & PERF_ATTACH_CONTEXT); 1467 WARN_ON_ONCE(event->attach_state & PERF_ATTACH_CONTEXT);
@@ -1412,8 +1482,7 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
1412 list_add_tail(&event->group_entry, list); 1482 list_add_tail(&event->group_entry, list);
1413 } 1483 }
1414 1484
1415 if (is_cgroup_event(event)) 1485 list_update_cgroup_event(event, ctx, true);
1416 ctx->nr_cgroups++;
1417 1486
1418 list_add_rcu(&event->event_entry, &ctx->event_list); 1487 list_add_rcu(&event->event_entry, &ctx->event_list);
1419 ctx->nr_events++; 1488 ctx->nr_events++;
@@ -1581,8 +1650,6 @@ static void perf_group_attach(struct perf_event *event)
1581static void 1650static void
1582list_del_event(struct perf_event *event, struct perf_event_context *ctx) 1651list_del_event(struct perf_event *event, struct perf_event_context *ctx)
1583{ 1652{
1584 struct perf_cpu_context *cpuctx;
1585
1586 WARN_ON_ONCE(event->ctx != ctx); 1653 WARN_ON_ONCE(event->ctx != ctx);
1587 lockdep_assert_held(&ctx->lock); 1654 lockdep_assert_held(&ctx->lock);
1588 1655
@@ -1594,20 +1661,7 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
1594 1661
1595 event->attach_state &= ~PERF_ATTACH_CONTEXT; 1662 event->attach_state &= ~PERF_ATTACH_CONTEXT;
1596 1663
1597 if (is_cgroup_event(event)) { 1664 list_update_cgroup_event(event, ctx, false);
1598 ctx->nr_cgroups--;
1599 /*
1600 * Because cgroup events are always per-cpu events, this will
1601 * always be called from the right CPU.
1602 */
1603 cpuctx = __get_cpu_context(ctx);
1604 /*
1605 * If there are no more cgroup events then clear cgrp to avoid
1606 * stale pointer in update_cgrp_time_from_cpuctx().
1607 */
1608 if (!ctx->nr_cgroups)
1609 cpuctx->cgrp = NULL;
1610 }
1611 1665
1612 ctx->nr_events--; 1666 ctx->nr_events--;
1613 if (event->attr.inherit_stat) 1667 if (event->attr.inherit_stat)
@@ -1716,8 +1770,8 @@ static inline int pmu_filter_match(struct perf_event *event)
1716static inline int 1770static inline int
1717event_filter_match(struct perf_event *event) 1771event_filter_match(struct perf_event *event)
1718{ 1772{
1719 return (event->cpu == -1 || event->cpu == smp_processor_id()) 1773 return (event->cpu == -1 || event->cpu == smp_processor_id()) &&
1720 && perf_cgroup_match(event) && pmu_filter_match(event); 1774 perf_cgroup_match(event) && pmu_filter_match(event);
1721} 1775}
1722 1776
1723static void 1777static void
@@ -1737,8 +1791,8 @@ event_sched_out(struct perf_event *event,
1737 * maintained, otherwise bogus information is return 1791 * maintained, otherwise bogus information is return
1738 * via read() for time_enabled, time_running: 1792 * via read() for time_enabled, time_running:
1739 */ 1793 */
1740 if (event->state == PERF_EVENT_STATE_INACTIVE 1794 if (event->state == PERF_EVENT_STATE_INACTIVE &&
1741 && !event_filter_match(event)) { 1795 !event_filter_match(event)) {
1742 delta = tstamp - event->tstamp_stopped; 1796 delta = tstamp - event->tstamp_stopped;
1743 event->tstamp_running += delta; 1797 event->tstamp_running += delta;
1744 event->tstamp_stopped = tstamp; 1798 event->tstamp_stopped = tstamp;
@@ -2236,10 +2290,15 @@ perf_install_in_context(struct perf_event_context *ctx,
2236 2290
2237 lockdep_assert_held(&ctx->mutex); 2291 lockdep_assert_held(&ctx->mutex);
2238 2292
2239 event->ctx = ctx;
2240 if (event->cpu != -1) 2293 if (event->cpu != -1)
2241 event->cpu = cpu; 2294 event->cpu = cpu;
2242 2295
2296 /*
2297 * Ensures that if we can observe event->ctx, both the event and ctx
2298 * will be 'complete'. See perf_iterate_sb_cpu().
2299 */
2300 smp_store_release(&event->ctx, ctx);
2301
2243 if (!task) { 2302 if (!task) {
2244 cpu_function_call(cpu, __perf_install_in_context, event); 2303 cpu_function_call(cpu, __perf_install_in_context, event);
2245 return; 2304 return;
@@ -3490,9 +3549,10 @@ static int perf_event_read(struct perf_event *event, bool group)
3490 .group = group, 3549 .group = group,
3491 .ret = 0, 3550 .ret = 0,
3492 }; 3551 };
3493 smp_call_function_single(event->oncpu, 3552 ret = smp_call_function_single(event->oncpu, __perf_event_read, &data, 1);
3494 __perf_event_read, &data, 1); 3553 /* The event must have been read from an online CPU: */
3495 ret = data.ret; 3554 WARN_ON_ONCE(ret);
3555 ret = ret ? : data.ret;
3496 } else if (event->state == PERF_EVENT_STATE_INACTIVE) { 3556 } else if (event->state == PERF_EVENT_STATE_INACTIVE) {
3497 struct perf_event_context *ctx = event->ctx; 3557 struct perf_event_context *ctx = event->ctx;
3498 unsigned long flags; 3558 unsigned long flags;
@@ -5969,6 +6029,14 @@ static void perf_iterate_sb_cpu(perf_iterate_f output, void *data)
5969 struct perf_event *event; 6029 struct perf_event *event;
5970 6030
5971 list_for_each_entry_rcu(event, &pel->list, sb_list) { 6031 list_for_each_entry_rcu(event, &pel->list, sb_list) {
6032 /*
6033 * Skip events that are not fully formed yet; ensure that
6034 * if we observe event->ctx, both event and ctx will be
6035 * complete enough. See perf_install_in_context().
6036 */
6037 if (!smp_load_acquire(&event->ctx))
6038 continue;
6039
5972 if (event->state < PERF_EVENT_STATE_INACTIVE) 6040 if (event->state < PERF_EVENT_STATE_INACTIVE)
5973 continue; 6041 continue;
5974 if (!event_filter_match(event)) 6042 if (!event_filter_match(event))
@@ -6098,7 +6166,7 @@ static int __perf_pmu_output_stop(void *info)
6098{ 6166{
6099 struct perf_event *event = info; 6167 struct perf_event *event = info;
6100 struct pmu *pmu = event->pmu; 6168 struct pmu *pmu = event->pmu;
6101 struct perf_cpu_context *cpuctx = get_cpu_ptr(pmu->pmu_cpu_context); 6169 struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context);
6102 struct remote_output ro = { 6170 struct remote_output ro = {
6103 .rb = event->rb, 6171 .rb = event->rb,
6104 }; 6172 };
@@ -6553,15 +6621,6 @@ got_name:
6553} 6621}
6554 6622
6555/* 6623/*
6556 * Whether this @filter depends on a dynamic object which is not loaded
6557 * yet or its load addresses are not known.
6558 */
6559static bool perf_addr_filter_needs_mmap(struct perf_addr_filter *filter)
6560{
6561 return filter->filter && filter->inode;
6562}
6563
6564/*
6565 * Check whether inode and address range match filter criteria. 6624 * Check whether inode and address range match filter criteria.
6566 */ 6625 */
6567static bool perf_addr_filter_match(struct perf_addr_filter *filter, 6626static bool perf_addr_filter_match(struct perf_addr_filter *filter,
@@ -6622,6 +6681,13 @@ static void perf_addr_filters_adjust(struct vm_area_struct *vma)
6622 struct perf_event_context *ctx; 6681 struct perf_event_context *ctx;
6623 int ctxn; 6682 int ctxn;
6624 6683
6684 /*
6685 * Data tracing isn't supported yet and as such there is no need
6686 * to keep track of anything that isn't related to executable code:
6687 */
6688 if (!(vma->vm_flags & VM_EXEC))
6689 return;
6690
6625 rcu_read_lock(); 6691 rcu_read_lock();
6626 for_each_task_context_nr(ctxn) { 6692 for_each_task_context_nr(ctxn) {
6627 ctx = rcu_dereference(current->perf_event_ctxp[ctxn]); 6693 ctx = rcu_dereference(current->perf_event_ctxp[ctxn]);
@@ -7774,7 +7840,11 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
7774 list_for_each_entry(filter, &ifh->list, entry) { 7840 list_for_each_entry(filter, &ifh->list, entry) {
7775 event->addr_filters_offs[count] = 0; 7841 event->addr_filters_offs[count] = 0;
7776 7842
7777 if (perf_addr_filter_needs_mmap(filter)) 7843 /*
7844 * Adjust base offset if the filter is associated to a binary
7845 * that needs to be mapped:
7846 */
7847 if (filter->inode)
7778 event->addr_filters_offs[count] = 7848 event->addr_filters_offs[count] =
7779 perf_addr_filter_apply(filter, mm); 7849 perf_addr_filter_apply(filter, mm);
7780 7850
@@ -7905,8 +7975,10 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,
7905 goto fail; 7975 goto fail;
7906 } 7976 }
7907 7977
7908 if (token == IF_SRC_FILE) { 7978 if (token == IF_SRC_FILE || token == IF_SRC_FILEADDR) {
7909 filename = match_strdup(&args[2]); 7979 int fpos = filter->range ? 2 : 1;
7980
7981 filename = match_strdup(&args[fpos]);
7910 if (!filename) { 7982 if (!filename) {
7911 ret = -ENOMEM; 7983 ret = -ENOMEM;
7912 goto fail; 7984 goto fail;
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index b7a525ab2083..8c50276b60d1 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -172,8 +172,10 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
172 mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end); 172 mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
173 err = -EAGAIN; 173 err = -EAGAIN;
174 ptep = page_check_address(page, mm, addr, &ptl, 0); 174 ptep = page_check_address(page, mm, addr, &ptl, 0);
175 if (!ptep) 175 if (!ptep) {
176 mem_cgroup_cancel_charge(kpage, memcg, false);
176 goto unlock; 177 goto unlock;
178 }
177 179
178 get_page(kpage); 180 get_page(kpage);
179 page_add_new_anon_rmap(kpage, vma, addr, false); 181 page_add_new_anon_rmap(kpage, vma, addr, false);
@@ -200,7 +202,6 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
200 202
201 err = 0; 203 err = 0;
202 unlock: 204 unlock:
203 mem_cgroup_cancel_charge(kpage, memcg, false);
204 mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end); 205 mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
205 unlock_page(page); 206 unlock_page(page);
206 return err; 207 return err;
diff --git a/kernel/futex.c b/kernel/futex.c
index 33664f70e2d2..46cb3a301bc1 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -179,7 +179,15 @@ int __read_mostly futex_cmpxchg_enabled;
179 * Futex flags used to encode options to functions and preserve them across 179 * Futex flags used to encode options to functions and preserve them across
180 * restarts. 180 * restarts.
181 */ 181 */
182#define FLAGS_SHARED 0x01 182#ifdef CONFIG_MMU
183# define FLAGS_SHARED 0x01
184#else
185/*
186 * NOMMU does not have per process address space. Let the compiler optimize
187 * code away.
188 */
189# define FLAGS_SHARED 0x00
190#endif
183#define FLAGS_CLOCKRT 0x02 191#define FLAGS_CLOCKRT 0x02
184#define FLAGS_HAS_TIMEOUT 0x04 192#define FLAGS_HAS_TIMEOUT 0x04
185 193
@@ -405,6 +413,16 @@ static void get_futex_key_refs(union futex_key *key)
405 if (!key->both.ptr) 413 if (!key->both.ptr)
406 return; 414 return;
407 415
416 /*
417 * On MMU less systems futexes are always "private" as there is no per
418 * process address space. We need the smp wmb nevertheless - yes,
419 * arch/blackfin has MMU less SMP ...
420 */
421 if (!IS_ENABLED(CONFIG_MMU)) {
422 smp_mb(); /* explicit smp_mb(); (B) */
423 return;
424 }
425
408 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) { 426 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) {
409 case FUT_OFF_INODE: 427 case FUT_OFF_INODE:
410 ihold(key->shared.inode); /* implies smp_mb(); (B) */ 428 ihold(key->shared.inode); /* implies smp_mb(); (B) */
@@ -436,6 +454,9 @@ static void drop_futex_key_refs(union futex_key *key)
436 return; 454 return;
437 } 455 }
438 456
457 if (!IS_ENABLED(CONFIG_MMU))
458 return;
459
439 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) { 460 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) {
440 case FUT_OFF_INODE: 461 case FUT_OFF_INODE:
441 iput(key->shared.inode); 462 iput(key->shared.inode);
diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
index f68959341c0f..32f6cfcff212 100644
--- a/kernel/irq/affinity.c
+++ b/kernel/irq/affinity.c
@@ -39,6 +39,7 @@ struct cpumask *irq_create_affinity_mask(unsigned int *nr_vecs)
39 return NULL; 39 return NULL;
40 } 40 }
41 41
42 get_online_cpus();
42 if (max_vecs >= num_online_cpus()) { 43 if (max_vecs >= num_online_cpus()) {
43 cpumask_copy(affinity_mask, cpu_online_mask); 44 cpumask_copy(affinity_mask, cpu_online_mask);
44 *nr_vecs = num_online_cpus(); 45 *nr_vecs = num_online_cpus();
@@ -56,6 +57,7 @@ struct cpumask *irq_create_affinity_mask(unsigned int *nr_vecs)
56 } 57 }
57 *nr_vecs = vecs; 58 *nr_vecs = vecs;
58 } 59 }
60 put_online_cpus();
59 61
60 return affinity_mask; 62 return affinity_mask;
61} 63}
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index b4c1bc7c9ca2..637389088b3f 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -820,6 +820,17 @@ __irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle,
820 desc->name = name; 820 desc->name = name;
821 821
822 if (handle != handle_bad_irq && is_chained) { 822 if (handle != handle_bad_irq && is_chained) {
823 /*
824 * We're about to start this interrupt immediately,
825 * hence the need to set the trigger configuration.
826 * But the .set_type callback may have overridden the
827 * flow handler, ignoring that we're dealing with a
828 * chained interrupt. Reset it immediately because we
829 * do know better.
830 */
831 __irq_set_trigger(desc, irqd_get_trigger_type(&desc->irq_data));
832 desc->handle_irq = handle;
833
823 irq_settings_set_noprobe(desc); 834 irq_settings_set_noprobe(desc);
824 irq_settings_set_norequest(desc); 835 irq_settings_set_norequest(desc);
825 irq_settings_set_nothread(desc); 836 irq_settings_set_nothread(desc);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 73a2b786b5e9..9530fcd27704 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1681,8 +1681,10 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler,
1681 action->dev_id = dev_id; 1681 action->dev_id = dev_id;
1682 1682
1683 retval = irq_chip_pm_get(&desc->irq_data); 1683 retval = irq_chip_pm_get(&desc->irq_data);
1684 if (retval < 0) 1684 if (retval < 0) {
1685 kfree(action);
1685 return retval; 1686 return retval;
1687 }
1686 1688
1687 chip_bus_lock(desc); 1689 chip_bus_lock(desc);
1688 retval = __setup_irq(irq, desc, action); 1690 retval = __setup_irq(irq, desc, action);
@@ -1985,8 +1987,10 @@ int request_percpu_irq(unsigned int irq, irq_handler_t handler,
1985 action->percpu_dev_id = dev_id; 1987 action->percpu_dev_id = dev_id;
1986 1988
1987 retval = irq_chip_pm_get(&desc->irq_data); 1989 retval = irq_chip_pm_get(&desc->irq_data);
1988 if (retval < 0) 1990 if (retval < 0) {
1991 kfree(action);
1989 return retval; 1992 return retval;
1993 }
1990 1994
1991 chip_bus_lock(desc); 1995 chip_bus_lock(desc);
1992 retval = __setup_irq(irq, desc, action); 1996 retval = __setup_irq(irq, desc, action);
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index 54999350162c..19e9dfbe97fa 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -359,6 +359,17 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
359 else 359 else
360 dev_dbg(dev, "irq [%d-%d] for MSI\n", 360 dev_dbg(dev, "irq [%d-%d] for MSI\n",
361 virq, virq + desc->nvec_used - 1); 361 virq, virq + desc->nvec_used - 1);
362 /*
363 * This flag is set by the PCI layer as we need to activate
364 * the MSI entries before the PCI layer enables MSI in the
365 * card. Otherwise the card latches a random msi message.
366 */
367 if (info->flags & MSI_FLAG_ACTIVATE_EARLY) {
368 struct irq_data *irq_data;
369
370 irq_data = irq_domain_get_irq_data(domain, desc->irq);
371 irq_domain_activate_irq(irq_data);
372 }
362 } 373 }
363 374
364 return 0; 375 return 0;
diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
index 37649e69056c..8a99abf58080 100644
--- a/kernel/locking/qspinlock_paravirt.h
+++ b/kernel/locking/qspinlock_paravirt.h
@@ -450,7 +450,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node)
450 goto gotlock; 450 goto gotlock;
451 } 451 }
452 } 452 }
453 WRITE_ONCE(pn->state, vcpu_halted); 453 WRITE_ONCE(pn->state, vcpu_hashed);
454 qstat_inc(qstat_pv_wait_head, true); 454 qstat_inc(qstat_pv_wait_head, true);
455 qstat_inc(qstat_pv_wait_again, waitcnt); 455 qstat_inc(qstat_pv_wait_again, waitcnt);
456 pv_wait(&l->locked, _Q_SLOW_VAL); 456 pv_wait(&l->locked, _Q_SLOW_VAL);
diff --git a/kernel/locking/qspinlock_stat.h b/kernel/locking/qspinlock_stat.h
index 22e025309845..b9d031516254 100644
--- a/kernel/locking/qspinlock_stat.h
+++ b/kernel/locking/qspinlock_stat.h
@@ -153,7 +153,6 @@ static ssize_t qstat_read(struct file *file, char __user *user_buf,
153 */ 153 */
154 if ((counter == qstat_pv_latency_kick) || 154 if ((counter == qstat_pv_latency_kick) ||
155 (counter == qstat_pv_latency_wake)) { 155 (counter == qstat_pv_latency_wake)) {
156 stat = 0;
157 if (kicks) 156 if (kicks)
158 stat = DIV_ROUND_CLOSEST_ULL(stat, kicks); 157 stat = DIV_ROUND_CLOSEST_ULL(stat, kicks);
159 } 158 }
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index a881c6a7ba74..33c79b6105c5 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -300,12 +300,12 @@ static int create_image(int platform_mode)
300 save_processor_state(); 300 save_processor_state();
301 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true); 301 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true);
302 error = swsusp_arch_suspend(); 302 error = swsusp_arch_suspend();
303 /* Restore control flow magically appears here */
304 restore_processor_state();
303 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false); 305 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false);
304 if (error) 306 if (error)
305 printk(KERN_ERR "PM: Error %d creating hibernation image\n", 307 printk(KERN_ERR "PM: Error %d creating hibernation image\n",
306 error); 308 error);
307 /* Restore control flow magically appears here */
308 restore_processor_state();
309 if (!in_suspend) 309 if (!in_suspend)
310 events_check_enabled = false; 310 events_check_enabled = false;
311 311
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 9a0178c2ac1d..b02228411d57 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -835,9 +835,9 @@ static bool memory_bm_pfn_present(struct memory_bitmap *bm, unsigned long pfn)
835 */ 835 */
836static bool rtree_next_node(struct memory_bitmap *bm) 836static bool rtree_next_node(struct memory_bitmap *bm)
837{ 837{
838 bm->cur.node = list_entry(bm->cur.node->list.next, 838 if (!list_is_last(&bm->cur.node->list, &bm->cur.zone->leaves)) {
839 struct rtree_node, list); 839 bm->cur.node = list_entry(bm->cur.node->list.next,
840 if (&bm->cur.node->list != &bm->cur.zone->leaves) { 840 struct rtree_node, list);
841 bm->cur.node_pfn += BM_BITS_PER_BLOCK; 841 bm->cur.node_pfn += BM_BITS_PER_BLOCK;
842 bm->cur.node_bit = 0; 842 bm->cur.node_bit = 0;
843 touch_softlockup_watchdog(); 843 touch_softlockup_watchdog();
@@ -845,9 +845,9 @@ static bool rtree_next_node(struct memory_bitmap *bm)
845 } 845 }
846 846
847 /* No more nodes, goto next zone */ 847 /* No more nodes, goto next zone */
848 bm->cur.zone = list_entry(bm->cur.zone->list.next, 848 if (!list_is_last(&bm->cur.zone->list, &bm->zones)) {
849 bm->cur.zone = list_entry(bm->cur.zone->list.next,
849 struct mem_zone_bm_rtree, list); 850 struct mem_zone_bm_rtree, list);
850 if (&bm->cur.zone->list != &bm->zones) {
851 bm->cur.node = list_entry(bm->cur.zone->leaves.next, 851 bm->cur.node = list_entry(bm->cur.zone->leaves.next,
852 struct rtree_node, list); 852 struct rtree_node, list);
853 bm->cur.node_pfn = 0; 853 bm->cur.node_pfn = 0;
diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
index 276762f3a460..d5760c42f042 100644
--- a/kernel/printk/braille.c
+++ b/kernel/printk/braille.c
@@ -9,10 +9,10 @@
9 9
10char *_braille_console_setup(char **str, char **brl_options) 10char *_braille_console_setup(char **str, char **brl_options)
11{ 11{
12 if (!memcmp(*str, "brl,", 4)) { 12 if (!strncmp(*str, "brl,", 4)) {
13 *brl_options = ""; 13 *brl_options = "";
14 *str += 4; 14 *str += 4;
15 } else if (!memcmp(str, "brl=", 4)) { 15 } else if (!strncmp(*str, "brl=", 4)) {
16 *brl_options = *str + 4; 16 *brl_options = *str + 4;
17 *str = strchr(*brl_options, ','); 17 *str = strchr(*brl_options, ',');
18 if (!*str) 18 if (!*str)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5c883fe8e440..2a906f20fba7 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -74,6 +74,7 @@
74#include <linux/context_tracking.h> 74#include <linux/context_tracking.h>
75#include <linux/compiler.h> 75#include <linux/compiler.h>
76#include <linux/frame.h> 76#include <linux/frame.h>
77#include <linux/prefetch.h>
77 78
78#include <asm/switch_to.h> 79#include <asm/switch_to.h>
79#include <asm/tlb.h> 80#include <asm/tlb.h>
@@ -2972,6 +2973,23 @@ EXPORT_PER_CPU_SYMBOL(kstat);
2972EXPORT_PER_CPU_SYMBOL(kernel_cpustat); 2973EXPORT_PER_CPU_SYMBOL(kernel_cpustat);
2973 2974
2974/* 2975/*
2976 * The function fair_sched_class.update_curr accesses the struct curr
2977 * and its field curr->exec_start; when called from task_sched_runtime(),
2978 * we observe a high rate of cache misses in practice.
2979 * Prefetching this data results in improved performance.
2980 */
2981static inline void prefetch_curr_exec_start(struct task_struct *p)
2982{
2983#ifdef CONFIG_FAIR_GROUP_SCHED
2984 struct sched_entity *curr = (&p->se)->cfs_rq->curr;
2985#else
2986 struct sched_entity *curr = (&task_rq(p)->cfs)->curr;
2987#endif
2988 prefetch(curr);
2989 prefetch(&curr->exec_start);
2990}
2991
2992/*
2975 * Return accounted runtime for the task. 2993 * Return accounted runtime for the task.
2976 * In case the task is currently running, return the runtime plus current's 2994 * In case the task is currently running, return the runtime plus current's
2977 * pending runtime that have not been accounted yet. 2995 * pending runtime that have not been accounted yet.
@@ -3005,6 +3023,7 @@ unsigned long long task_sched_runtime(struct task_struct *p)
3005 * thread, breaking clock_gettime(). 3023 * thread, breaking clock_gettime().
3006 */ 3024 */
3007 if (task_current(rq, p) && task_on_rq_queued(p)) { 3025 if (task_current(rq, p) && task_on_rq_queued(p)) {
3026 prefetch_curr_exec_start(p);
3008 update_rq_clock(rq); 3027 update_rq_clock(rq);
3009 p->sched_class->update_curr(rq); 3028 p->sched_class->update_curr(rq);
3010 } 3029 }
diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index 5be58820465c..d4184498c9f5 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -168,7 +168,7 @@ void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid)
168 168
169 if (old_idx == IDX_INVALID) { 169 if (old_idx == IDX_INVALID) {
170 cp->size++; 170 cp->size++;
171 cp->elements[cp->size - 1].dl = 0; 171 cp->elements[cp->size - 1].dl = dl;
172 cp->elements[cp->size - 1].cpu = cpu; 172 cp->elements[cp->size - 1].cpu = cpu;
173 cp->elements[cpu].idx = cp->size - 1; 173 cp->elements[cpu].idx = cp->size - 1;
174 cpudl_change_key(cp, cp->size - 1, dl); 174 cpudl_change_key(cp, cp->size - 1, dl);
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 1934f658c036..a846cf89eb96 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -263,6 +263,11 @@ void account_idle_time(cputime_t cputime)
263 cpustat[CPUTIME_IDLE] += (__force u64) cputime; 263 cpustat[CPUTIME_IDLE] += (__force u64) cputime;
264} 264}
265 265
266/*
267 * When a guest is interrupted for a longer amount of time, missed clock
268 * ticks are not redelivered later. Due to that, this function may on
269 * occasion account more time than the calling functions think elapsed.
270 */
266static __always_inline cputime_t steal_account_process_time(cputime_t maxtime) 271static __always_inline cputime_t steal_account_process_time(cputime_t maxtime)
267{ 272{
268#ifdef CONFIG_PARAVIRT 273#ifdef CONFIG_PARAVIRT
@@ -371,7 +376,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
371 * idle, or potentially user or system time. Due to rounding, 376 * idle, or potentially user or system time. Due to rounding,
372 * other time can exceed ticks occasionally. 377 * other time can exceed ticks occasionally.
373 */ 378 */
374 other = account_other_time(cputime); 379 other = account_other_time(ULONG_MAX);
375 if (other >= cputime) 380 if (other >= cputime)
376 return; 381 return;
377 cputime -= other; 382 cputime -= other;
@@ -486,7 +491,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
486 } 491 }
487 492
488 cputime = cputime_one_jiffy; 493 cputime = cputime_one_jiffy;
489 steal = steal_account_process_time(cputime); 494 steal = steal_account_process_time(ULONG_MAX);
490 495
491 if (steal >= cputime) 496 if (steal >= cputime)
492 return; 497 return;
@@ -508,13 +513,21 @@ void account_process_tick(struct task_struct *p, int user_tick)
508 */ 513 */
509void account_idle_ticks(unsigned long ticks) 514void account_idle_ticks(unsigned long ticks)
510{ 515{
516 cputime_t cputime, steal;
511 517
512 if (sched_clock_irqtime) { 518 if (sched_clock_irqtime) {
513 irqtime_account_idle_ticks(ticks); 519 irqtime_account_idle_ticks(ticks);
514 return; 520 return;
515 } 521 }
516 522
517 account_idle_time(jiffies_to_cputime(ticks)); 523 cputime = jiffies_to_cputime(ticks);
524 steal = steal_account_process_time(ULONG_MAX);
525
526 if (steal >= cputime)
527 return;
528
529 cputime -= steal;
530 account_idle_time(cputime);
518} 531}
519 532
520/* 533/*
@@ -606,19 +619,25 @@ static void cputime_adjust(struct task_cputime *curr,
606 stime = curr->stime; 619 stime = curr->stime;
607 utime = curr->utime; 620 utime = curr->utime;
608 621
609 if (utime == 0) { 622 /*
610 stime = rtime; 623 * If either stime or both stime and utime are 0, assume all runtime is
624 * userspace. Once a task gets some ticks, the monotonicy code at
625 * 'update' will ensure things converge to the observed ratio.
626 */
627 if (stime == 0) {
628 utime = rtime;
611 goto update; 629 goto update;
612 } 630 }
613 631
614 if (stime == 0) { 632 if (utime == 0) {
615 utime = rtime; 633 stime = rtime;
616 goto update; 634 goto update;
617 } 635 }
618 636
619 stime = scale_stime((__force u64)stime, (__force u64)rtime, 637 stime = scale_stime((__force u64)stime, (__force u64)rtime,
620 (__force u64)(stime + utime)); 638 (__force u64)(stime + utime));
621 639
640update:
622 /* 641 /*
623 * Make sure stime doesn't go backwards; this preserves monotonicity 642 * Make sure stime doesn't go backwards; this preserves monotonicity
624 * for utime because rtime is monotonic. 643 * for utime because rtime is monotonic.
@@ -641,7 +660,6 @@ static void cputime_adjust(struct task_cputime *curr,
641 stime = rtime - utime; 660 stime = rtime - utime;
642 } 661 }
643 662
644update:
645 prev->stime = stime; 663 prev->stime = stime;
646 prev->utime = utime; 664 prev->utime = utime;
647out: 665out:
@@ -686,6 +704,13 @@ static cputime_t get_vtime_delta(struct task_struct *tsk)
686 unsigned long now = READ_ONCE(jiffies); 704 unsigned long now = READ_ONCE(jiffies);
687 cputime_t delta, other; 705 cputime_t delta, other;
688 706
707 /*
708 * Unlike tick based timing, vtime based timing never has lost
709 * ticks, and no need for steal time accounting to make up for
710 * lost ticks. Vtime accounts a rounded version of actual
711 * elapsed time. Limit account_other_time to prevent rounding
712 * errors from causing elapsed vtime to go negative.
713 */
689 delta = jiffies_to_cputime(now - tsk->vtime_snap); 714 delta = jiffies_to_cputime(now - tsk->vtime_snap);
690 other = account_other_time(delta); 715 other = account_other_time(delta);
691 WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE); 716 WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index fcb7f0217ff4..1ce8867283dc 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -658,8 +658,11 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
658 * 658 *
659 * XXX figure out if select_task_rq_dl() deals with offline cpus. 659 * XXX figure out if select_task_rq_dl() deals with offline cpus.
660 */ 660 */
661 if (unlikely(!rq->online)) 661 if (unlikely(!rq->online)) {
662 lockdep_unpin_lock(&rq->lock, rf.cookie);
662 rq = dl_task_offline_migration(rq, p); 663 rq = dl_task_offline_migration(rq, p);
664 rf.cookie = lockdep_pin_lock(&rq->lock);
665 }
663 666
664 /* 667 /*
665 * Queueing this task back might have overloaded rq, check if we need 668 * Queueing this task back might have overloaded rq, check if we need
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 4088eedea763..039de34f1521 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4269,7 +4269,7 @@ static void sync_throttle(struct task_group *tg, int cpu)
4269 pcfs_rq = tg->parent->cfs_rq[cpu]; 4269 pcfs_rq = tg->parent->cfs_rq[cpu];
4270 4270
4271 cfs_rq->throttle_count = pcfs_rq->throttle_count; 4271 cfs_rq->throttle_count = pcfs_rq->throttle_count;
4272 pcfs_rq->throttled_clock_task = rq_clock_task(cpu_rq(cpu)); 4272 cfs_rq->throttled_clock_task = rq_clock_task(cpu_rq(cpu));
4273} 4273}
4274 4274
4275/* conditionally throttle active cfs_rq's from put_prev_entity() */ 4275/* conditionally throttle active cfs_rq's from put_prev_entity() */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index b43d0b27c1fe..a13bbdaab47d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2140,6 +2140,21 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2140 return 0; 2140 return 0;
2141} 2141}
2142 2142
2143static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2144 int *valp,
2145 int write, void *data)
2146{
2147 if (write) {
2148 if (*negp)
2149 return -EINVAL;
2150 *valp = *lvalp;
2151 } else {
2152 unsigned int val = *valp;
2153 *lvalp = (unsigned long)val;
2154 }
2155 return 0;
2156}
2157
2143static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; 2158static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2144 2159
2145static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 2160static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
@@ -2259,8 +2274,27 @@ static int do_proc_dointvec(struct ctl_table *table, int write,
2259int proc_dointvec(struct ctl_table *table, int write, 2274int proc_dointvec(struct ctl_table *table, int write,
2260 void __user *buffer, size_t *lenp, loff_t *ppos) 2275 void __user *buffer, size_t *lenp, loff_t *ppos)
2261{ 2276{
2262 return do_proc_dointvec(table,write,buffer,lenp,ppos, 2277 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2263 NULL,NULL); 2278}
2279
2280/**
2281 * proc_douintvec - read a vector of unsigned integers
2282 * @table: the sysctl table
2283 * @write: %TRUE if this is a write to the sysctl file
2284 * @buffer: the user buffer
2285 * @lenp: the size of the user buffer
2286 * @ppos: file position
2287 *
2288 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2289 * values from/to the user buffer, treated as an ASCII string.
2290 *
2291 * Returns 0 on success.
2292 */
2293int proc_douintvec(struct ctl_table *table, int write,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2295{
2296 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2297 do_proc_douintvec_conv, NULL);
2264} 2298}
2265 2299
2266/* 2300/*
@@ -2858,6 +2892,12 @@ int proc_dointvec(struct ctl_table *table, int write,
2858 return -ENOSYS; 2892 return -ENOSYS;
2859} 2893}
2860 2894
2895int proc_douintvec(struct ctl_table *table, int write,
2896 void __user *buffer, size_t *lenp, loff_t *ppos)
2897{
2898 return -ENOSYS;
2899}
2900
2861int proc_dointvec_minmax(struct ctl_table *table, int write, 2901int proc_dointvec_minmax(struct ctl_table *table, int write,
2862 void __user *buffer, size_t *lenp, loff_t *ppos) 2902 void __user *buffer, size_t *lenp, loff_t *ppos)
2863{ 2903{
@@ -2903,6 +2943,7 @@ int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2903 * exception granted :-) 2943 * exception granted :-)
2904 */ 2944 */
2905EXPORT_SYMBOL(proc_dointvec); 2945EXPORT_SYMBOL(proc_dointvec);
2946EXPORT_SYMBOL(proc_douintvec);
2906EXPORT_SYMBOL(proc_dointvec_jiffies); 2947EXPORT_SYMBOL(proc_dointvec_jiffies);
2907EXPORT_SYMBOL(proc_dointvec_minmax); 2948EXPORT_SYMBOL(proc_dointvec_minmax);
2908EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 2949EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 3b65746c7f15..e07fb093f819 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -401,7 +401,10 @@ static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf)
401 do { 401 do {
402 seq = raw_read_seqcount_latch(&tkf->seq); 402 seq = raw_read_seqcount_latch(&tkf->seq);
403 tkr = tkf->base + (seq & 0x01); 403 tkr = tkf->base + (seq & 0x01);
404 now = ktime_to_ns(tkr->base) + timekeeping_get_ns(tkr); 404 now = ktime_to_ns(tkr->base);
405
406 now += clocksource_delta(tkr->read(tkr->clock),
407 tkr->cycle_last, tkr->mask);
405 } while (read_seqcount_retry(&tkf->seq, seq)); 408 } while (read_seqcount_retry(&tkf->seq, seq));
406 409
407 return now; 410 return now;
diff --git a/kernel/time/timekeeping_debug.c b/kernel/time/timekeeping_debug.c
index f6bd65236712..107310a6f36f 100644
--- a/kernel/time/timekeeping_debug.c
+++ b/kernel/time/timekeeping_debug.c
@@ -23,7 +23,9 @@
23 23
24#include "timekeeping_internal.h" 24#include "timekeeping_internal.h"
25 25
26static unsigned int sleep_time_bin[32] = {0}; 26#define NUM_BINS 32
27
28static unsigned int sleep_time_bin[NUM_BINS] = {0};
27 29
28static int tk_debug_show_sleep_time(struct seq_file *s, void *data) 30static int tk_debug_show_sleep_time(struct seq_file *s, void *data)
29{ 31{
@@ -69,6 +71,9 @@ late_initcall(tk_debug_sleep_time_init);
69 71
70void tk_debug_account_sleep_time(struct timespec64 *t) 72void tk_debug_account_sleep_time(struct timespec64 *t)
71{ 73{
72 sleep_time_bin[fls(t->tv_sec)]++; 74 /* Cap bin index so we don't overflow the array */
75 int bin = min(fls(t->tv_sec), NUM_BINS-1);
76
77 sleep_time_bin[bin]++;
73} 78}
74 79
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 555670a5143c..32bf6f75a8fe 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1496,6 +1496,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1496 struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); 1496 struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
1497 u64 expires = KTIME_MAX; 1497 u64 expires = KTIME_MAX;
1498 unsigned long nextevt; 1498 unsigned long nextevt;
1499 bool is_max_delta;
1499 1500
1500 /* 1501 /*
1501 * Pretend that there is no timer pending if the cpu is offline. 1502 * Pretend that there is no timer pending if the cpu is offline.
@@ -1506,6 +1507,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1506 1507
1507 spin_lock(&base->lock); 1508 spin_lock(&base->lock);
1508 nextevt = __next_timer_interrupt(base); 1509 nextevt = __next_timer_interrupt(base);
1510 is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
1509 base->next_expiry = nextevt; 1511 base->next_expiry = nextevt;
1510 /* 1512 /*
1511 * We have a fresh next event. Check whether we can forward the base: 1513 * We have a fresh next event. Check whether we can forward the base:
@@ -1519,7 +1521,8 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1519 expires = basem; 1521 expires = basem;
1520 base->is_idle = false; 1522 base->is_idle = false;
1521 } else { 1523 } else {
1522 expires = basem + (nextevt - basej) * TICK_NSEC; 1524 if (!is_max_delta)
1525 expires = basem + (nextevt - basej) * TICK_NSEC;
1523 /* 1526 /*
1524 * If we expect to sleep more than a tick, mark the base idle: 1527 * If we expect to sleep more than a tick, mark the base idle:
1525 */ 1528 */
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 7598e6ca817a..dbafc5df03f3 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -223,7 +223,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
223 what |= MASK_TC_BIT(op_flags, META); 223 what |= MASK_TC_BIT(op_flags, META);
224 what |= MASK_TC_BIT(op_flags, PREFLUSH); 224 what |= MASK_TC_BIT(op_flags, PREFLUSH);
225 what |= MASK_TC_BIT(op_flags, FUA); 225 what |= MASK_TC_BIT(op_flags, FUA);
226 if (op == REQ_OP_DISCARD) 226 if (op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)
227 what |= BLK_TC_ACT(BLK_TC_DISCARD); 227 what |= BLK_TC_ACT(BLK_TC_DISCARD);
228 if (op == REQ_OP_FLUSH) 228 if (op == REQ_OP_FLUSH)
229 what |= BLK_TC_ACT(BLK_TC_FLUSH); 229 what |= BLK_TC_ACT(BLK_TC_FLUSH);
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 5d845ffd7982..5ba520b544d7 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -30,7 +30,7 @@
30 30
31#define HASH_DEFAULT_SIZE 64UL 31#define HASH_DEFAULT_SIZE 64UL
32#define HASH_MIN_SIZE 4U 32#define HASH_MIN_SIZE 4U
33#define BUCKET_LOCKS_PER_CPU 128UL 33#define BUCKET_LOCKS_PER_CPU 32UL
34 34
35static u32 head_hashfn(struct rhashtable *ht, 35static u32 head_hashfn(struct rhashtable *ht,
36 const struct bucket_table *tbl, 36 const struct bucket_table *tbl,
@@ -70,7 +70,7 @@ static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl,
70 unsigned int nr_pcpus = num_possible_cpus(); 70 unsigned int nr_pcpus = num_possible_cpus();
71#endif 71#endif
72 72
73 nr_pcpus = min_t(unsigned int, nr_pcpus, 32UL); 73 nr_pcpus = min_t(unsigned int, nr_pcpus, 64UL);
74 size = roundup_pow_of_two(nr_pcpus * ht->p.locks_mul); 74 size = roundup_pow_of_two(nr_pcpus * ht->p.locks_mul);
75 75
76 /* Never allocate more than 0.5 locks per bucket */ 76 /* Never allocate more than 0.5 locks per bucket */
@@ -83,6 +83,9 @@ static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl,
83 tbl->locks = vmalloc(size * sizeof(spinlock_t)); 83 tbl->locks = vmalloc(size * sizeof(spinlock_t));
84 else 84 else
85#endif 85#endif
86 if (gfp != GFP_KERNEL)
87 gfp |= __GFP_NOWARN | __GFP_NORETRY;
88
86 tbl->locks = kmalloc_array(size, sizeof(spinlock_t), 89 tbl->locks = kmalloc_array(size, sizeof(spinlock_t),
87 gfp); 90 gfp);
88 if (!tbl->locks) 91 if (!tbl->locks)
@@ -321,12 +324,14 @@ static int rhashtable_expand(struct rhashtable *ht)
321static int rhashtable_shrink(struct rhashtable *ht) 324static int rhashtable_shrink(struct rhashtable *ht)
322{ 325{
323 struct bucket_table *new_tbl, *old_tbl = rht_dereference(ht->tbl, ht); 326 struct bucket_table *new_tbl, *old_tbl = rht_dereference(ht->tbl, ht);
324 unsigned int size; 327 unsigned int nelems = atomic_read(&ht->nelems);
328 unsigned int size = 0;
325 int err; 329 int err;
326 330
327 ASSERT_RHT_MUTEX(ht); 331 ASSERT_RHT_MUTEX(ht);
328 332
329 size = roundup_pow_of_two(atomic_read(&ht->nelems) * 3 / 2); 333 if (nelems)
334 size = roundup_pow_of_two(nelems * 3 / 2);
330 if (size < ht->p.min_size) 335 if (size < ht->p.min_size)
331 size = ht->p.min_size; 336 size = ht->p.min_size;
332 337
diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
index 297fdb5e74bd..64e899b63337 100644
--- a/lib/test_rhashtable.c
+++ b/lib/test_rhashtable.c
@@ -38,7 +38,7 @@ MODULE_PARM_DESC(runs, "Number of test runs per variant (default: 4)");
38 38
39static int max_size = 0; 39static int max_size = 0;
40module_param(max_size, int, 0); 40module_param(max_size, int, 0);
41MODULE_PARM_DESC(runs, "Maximum table size (default: calculated)"); 41MODULE_PARM_DESC(max_size, "Maximum table size (default: calculated)");
42 42
43static bool shrinking = false; 43static bool shrinking = false;
44module_param(shrinking, bool, 0); 44module_param(shrinking, bool, 0);
diff --git a/mm/Kconfig b/mm/Kconfig
index 78a23c5c302d..be0ee11fa0d9 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -262,7 +262,14 @@ config COMPACTION
262 select MIGRATION 262 select MIGRATION
263 depends on MMU 263 depends on MMU
264 help 264 help
265 Allows the compaction of memory for the allocation of huge pages. 265 Compaction is the only memory management component to form
266 high order (larger physically contiguous) memory blocks
267 reliably. The page allocator relies on compaction heavily and
268 the lack of the feature can lead to unexpected OOM killer
269 invocations for high order memory requests. You shouldn't
270 disable this option unless there really is a strong reason for
271 it and then we would be really interested to hear about that at
272 linux-mm@kvack.org.
266 273
267# 274#
268# support for page migration 275# support for page migration
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 2373f0a7d340..2db2112aa31e 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1512,7 +1512,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
1512 struct page *page; 1512 struct page *page;
1513 pgtable_t pgtable; 1513 pgtable_t pgtable;
1514 pmd_t _pmd; 1514 pmd_t _pmd;
1515 bool young, write, dirty; 1515 bool young, write, dirty, soft_dirty;
1516 unsigned long addr; 1516 unsigned long addr;
1517 int i; 1517 int i;
1518 1518
@@ -1546,6 +1546,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
1546 write = pmd_write(*pmd); 1546 write = pmd_write(*pmd);
1547 young = pmd_young(*pmd); 1547 young = pmd_young(*pmd);
1548 dirty = pmd_dirty(*pmd); 1548 dirty = pmd_dirty(*pmd);
1549 soft_dirty = pmd_soft_dirty(*pmd);
1549 1550
1550 pmdp_huge_split_prepare(vma, haddr, pmd); 1551 pmdp_huge_split_prepare(vma, haddr, pmd);
1551 pgtable = pgtable_trans_huge_withdraw(mm, pmd); 1552 pgtable = pgtable_trans_huge_withdraw(mm, pmd);
@@ -1562,6 +1563,8 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
1562 swp_entry_t swp_entry; 1563 swp_entry_t swp_entry;
1563 swp_entry = make_migration_entry(page + i, write); 1564 swp_entry = make_migration_entry(page + i, write);
1564 entry = swp_entry_to_pte(swp_entry); 1565 entry = swp_entry_to_pte(swp_entry);
1566 if (soft_dirty)
1567 entry = pte_swp_mksoft_dirty(entry);
1565 } else { 1568 } else {
1566 entry = mk_pte(page + i, vma->vm_page_prot); 1569 entry = mk_pte(page + i, vma->vm_page_prot);
1567 entry = maybe_mkwrite(entry, vma); 1570 entry = maybe_mkwrite(entry, vma);
@@ -1569,6 +1572,8 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
1569 entry = pte_wrprotect(entry); 1572 entry = pte_wrprotect(entry);
1570 if (!young) 1573 if (!young)
1571 entry = pte_mkold(entry); 1574 entry = pte_mkold(entry);
1575 if (soft_dirty)
1576 entry = pte_mksoft_dirty(entry);
1572 } 1577 }
1573 if (dirty) 1578 if (dirty)
1574 SetPageDirty(page + i); 1579 SetPageDirty(page + i);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b9aa1b0b38b0..87e11d8ad536 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1448,6 +1448,7 @@ static void dissolve_free_huge_page(struct page *page)
1448 list_del(&page->lru); 1448 list_del(&page->lru);
1449 h->free_huge_pages--; 1449 h->free_huge_pages--;
1450 h->free_huge_pages_node[nid]--; 1450 h->free_huge_pages_node[nid]--;
1451 h->max_huge_pages--;
1451 update_and_free_page(h, page); 1452 update_and_free_page(h, page);
1452 } 1453 }
1453 spin_unlock(&hugetlb_lock); 1454 spin_unlock(&hugetlb_lock);
diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c
index b6728a33a4ac..baabaad4a4aa 100644
--- a/mm/kasan/quarantine.c
+++ b/mm/kasan/quarantine.c
@@ -217,11 +217,8 @@ void quarantine_reduce(void)
217 new_quarantine_size = (READ_ONCE(totalram_pages) << PAGE_SHIFT) / 217 new_quarantine_size = (READ_ONCE(totalram_pages) << PAGE_SHIFT) /
218 QUARANTINE_FRACTION; 218 QUARANTINE_FRACTION;
219 percpu_quarantines = QUARANTINE_PERCPU_SIZE * num_online_cpus(); 219 percpu_quarantines = QUARANTINE_PERCPU_SIZE * num_online_cpus();
220 if (WARN_ONCE(new_quarantine_size < percpu_quarantines, 220 new_quarantine_size = (new_quarantine_size < percpu_quarantines) ?
221 "Too little memory, disabling global KASAN quarantine.\n")) 221 0 : new_quarantine_size - percpu_quarantines;
222 new_quarantine_size = 0;
223 else
224 new_quarantine_size -= percpu_quarantines;
225 WRITE_ONCE(quarantine_size, new_quarantine_size); 222 WRITE_ONCE(quarantine_size, new_quarantine_size);
226 223
227 last = global_quarantine.head; 224 last = global_quarantine.head;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e74d7080ec9e..9a6a51a7c416 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4077,14 +4077,14 @@ static struct cftype mem_cgroup_legacy_files[] = {
4077 4077
4078static DEFINE_IDR(mem_cgroup_idr); 4078static DEFINE_IDR(mem_cgroup_idr);
4079 4079
4080static void mem_cgroup_id_get(struct mem_cgroup *memcg) 4080static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n)
4081{ 4081{
4082 atomic_inc(&memcg->id.ref); 4082 atomic_add(n, &memcg->id.ref);
4083} 4083}
4084 4084
4085static void mem_cgroup_id_put(struct mem_cgroup *memcg) 4085static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n)
4086{ 4086{
4087 if (atomic_dec_and_test(&memcg->id.ref)) { 4087 if (atomic_sub_and_test(n, &memcg->id.ref)) {
4088 idr_remove(&mem_cgroup_idr, memcg->id.id); 4088 idr_remove(&mem_cgroup_idr, memcg->id.id);
4089 memcg->id.id = 0; 4089 memcg->id.id = 0;
4090 4090
@@ -4093,6 +4093,16 @@ static void mem_cgroup_id_put(struct mem_cgroup *memcg)
4093 } 4093 }
4094} 4094}
4095 4095
4096static inline void mem_cgroup_id_get(struct mem_cgroup *memcg)
4097{
4098 mem_cgroup_id_get_many(memcg, 1);
4099}
4100
4101static inline void mem_cgroup_id_put(struct mem_cgroup *memcg)
4102{
4103 mem_cgroup_id_put_many(memcg, 1);
4104}
4105
4096/** 4106/**
4097 * mem_cgroup_from_id - look up a memcg from a memcg id 4107 * mem_cgroup_from_id - look up a memcg from a memcg id
4098 * @id: the memcg id to look up 4108 * @id: the memcg id to look up
@@ -4727,6 +4737,8 @@ static void __mem_cgroup_clear_mc(void)
4727 if (!mem_cgroup_is_root(mc.from)) 4737 if (!mem_cgroup_is_root(mc.from))
4728 page_counter_uncharge(&mc.from->memsw, mc.moved_swap); 4738 page_counter_uncharge(&mc.from->memsw, mc.moved_swap);
4729 4739
4740 mem_cgroup_id_put_many(mc.from, mc.moved_swap);
4741
4730 /* 4742 /*
4731 * we charged both to->memory and to->memsw, so we 4743 * we charged both to->memory and to->memsw, so we
4732 * should uncharge to->memory. 4744 * should uncharge to->memory.
@@ -4734,9 +4746,9 @@ static void __mem_cgroup_clear_mc(void)
4734 if (!mem_cgroup_is_root(mc.to)) 4746 if (!mem_cgroup_is_root(mc.to))
4735 page_counter_uncharge(&mc.to->memory, mc.moved_swap); 4747 page_counter_uncharge(&mc.to->memory, mc.moved_swap);
4736 4748
4737 css_put_many(&mc.from->css, mc.moved_swap); 4749 mem_cgroup_id_get_many(mc.to, mc.moved_swap);
4750 css_put_many(&mc.to->css, mc.moved_swap);
4738 4751
4739 /* we've already done css_get(mc.to) */
4740 mc.moved_swap = 0; 4752 mc.moved_swap = 0;
4741 } 4753 }
4742 memcg_oom_recover(from); 4754 memcg_oom_recover(from);
@@ -5791,6 +5803,24 @@ static int __init mem_cgroup_init(void)
5791subsys_initcall(mem_cgroup_init); 5803subsys_initcall(mem_cgroup_init);
5792 5804
5793#ifdef CONFIG_MEMCG_SWAP 5805#ifdef CONFIG_MEMCG_SWAP
5806static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg)
5807{
5808 while (!atomic_inc_not_zero(&memcg->id.ref)) {
5809 /*
5810 * The root cgroup cannot be destroyed, so it's refcount must
5811 * always be >= 1.
5812 */
5813 if (WARN_ON_ONCE(memcg == root_mem_cgroup)) {
5814 VM_BUG_ON(1);
5815 break;
5816 }
5817 memcg = parent_mem_cgroup(memcg);
5818 if (!memcg)
5819 memcg = root_mem_cgroup;
5820 }
5821 return memcg;
5822}
5823
5794/** 5824/**
5795 * mem_cgroup_swapout - transfer a memsw charge to swap 5825 * mem_cgroup_swapout - transfer a memsw charge to swap
5796 * @page: page whose memsw charge to transfer 5826 * @page: page whose memsw charge to transfer
@@ -5800,7 +5830,7 @@ subsys_initcall(mem_cgroup_init);
5800 */ 5830 */
5801void mem_cgroup_swapout(struct page *page, swp_entry_t entry) 5831void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
5802{ 5832{
5803 struct mem_cgroup *memcg; 5833 struct mem_cgroup *memcg, *swap_memcg;
5804 unsigned short oldid; 5834 unsigned short oldid;
5805 5835
5806 VM_BUG_ON_PAGE(PageLRU(page), page); 5836 VM_BUG_ON_PAGE(PageLRU(page), page);
@@ -5815,16 +5845,27 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
5815 if (!memcg) 5845 if (!memcg)
5816 return; 5846 return;
5817 5847
5818 mem_cgroup_id_get(memcg); 5848 /*
5819 oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg)); 5849 * In case the memcg owning these pages has been offlined and doesn't
5850 * have an ID allocated to it anymore, charge the closest online
5851 * ancestor for the swap instead and transfer the memory+swap charge.
5852 */
5853 swap_memcg = mem_cgroup_id_get_online(memcg);
5854 oldid = swap_cgroup_record(entry, mem_cgroup_id(swap_memcg));
5820 VM_BUG_ON_PAGE(oldid, page); 5855 VM_BUG_ON_PAGE(oldid, page);
5821 mem_cgroup_swap_statistics(memcg, true); 5856 mem_cgroup_swap_statistics(swap_memcg, true);
5822 5857
5823 page->mem_cgroup = NULL; 5858 page->mem_cgroup = NULL;
5824 5859
5825 if (!mem_cgroup_is_root(memcg)) 5860 if (!mem_cgroup_is_root(memcg))
5826 page_counter_uncharge(&memcg->memory, 1); 5861 page_counter_uncharge(&memcg->memory, 1);
5827 5862
5863 if (memcg != swap_memcg) {
5864 if (!mem_cgroup_is_root(swap_memcg))
5865 page_counter_charge(&swap_memcg->memsw, 1);
5866 page_counter_uncharge(&memcg->memsw, 1);
5867 }
5868
5828 /* 5869 /*
5829 * Interrupts should be disabled here because the caller holds the 5870 * Interrupts should be disabled here because the caller holds the
5830 * mapping->tree_lock lock which is taken with interrupts-off. It is 5871 * mapping->tree_lock lock which is taken with interrupts-off. It is
@@ -5863,11 +5904,14 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry)
5863 if (!memcg) 5904 if (!memcg)
5864 return 0; 5905 return 0;
5865 5906
5907 memcg = mem_cgroup_id_get_online(memcg);
5908
5866 if (!mem_cgroup_is_root(memcg) && 5909 if (!mem_cgroup_is_root(memcg) &&
5867 !page_counter_try_charge(&memcg->swap, 1, &counter)) 5910 !page_counter_try_charge(&memcg->swap, 1, &counter)) {
5911 mem_cgroup_id_put(memcg);
5868 return -ENOMEM; 5912 return -ENOMEM;
5913 }
5869 5914
5870 mem_cgroup_id_get(memcg);
5871 oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg)); 5915 oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg));
5872 VM_BUG_ON_PAGE(oldid, page); 5916 VM_BUG_ON_PAGE(oldid, page);
5873 mem_cgroup_swap_statistics(memcg, true); 5917 mem_cgroup_swap_statistics(memcg, true);
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 3894b65b1555..41266dc29f33 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1219,6 +1219,7 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
1219 1219
1220 /* init node's zones as empty zones, we don't have any present pages.*/ 1220 /* init node's zones as empty zones, we don't have any present pages.*/
1221 free_area_init_node(nid, zones_size, start_pfn, zholes_size); 1221 free_area_init_node(nid, zones_size, start_pfn, zholes_size);
1222 pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat);
1222 1223
1223 /* 1224 /*
1224 * The node we allocated has no zone fallback lists. For avoiding 1225 * The node we allocated has no zone fallback lists. For avoiding
@@ -1249,6 +1250,7 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
1249static void rollback_node_hotadd(int nid, pg_data_t *pgdat) 1250static void rollback_node_hotadd(int nid, pg_data_t *pgdat)
1250{ 1251{
1251 arch_refresh_nodedata(nid, NULL); 1252 arch_refresh_nodedata(nid, NULL);
1253 free_percpu(pgdat->per_cpu_nodestats);
1252 arch_free_nodedata(pgdat); 1254 arch_free_nodedata(pgdat);
1253 return; 1255 return;
1254} 1256}
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 7d0a275df822..d53a9aa00977 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -764,7 +764,7 @@ bool task_will_free_mem(struct task_struct *task)
764{ 764{
765 struct mm_struct *mm = task->mm; 765 struct mm_struct *mm = task->mm;
766 struct task_struct *p; 766 struct task_struct *p;
767 bool ret; 767 bool ret = true;
768 768
769 /* 769 /*
770 * Skip tasks without mm because it might have passed its exit_mm and 770 * Skip tasks without mm because it might have passed its exit_mm and
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ee744fa3b93d..3fbe73a6fe4b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4060,7 +4060,7 @@ long si_mem_available(void)
4060 int lru; 4060 int lru;
4061 4061
4062 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 4062 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
4063 pages[lru] = global_page_state(NR_LRU_BASE + lru); 4063 pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
4064 4064
4065 for_each_zone(zone) 4065 for_each_zone(zone)
4066 wmark_low += zone->watermark[WMARK_LOW]; 4066 wmark_low += zone->watermark[WMARK_LOW];
@@ -4757,6 +4757,8 @@ int local_memory_node(int node)
4757} 4757}
4758#endif 4758#endif
4759 4759
4760static void setup_min_unmapped_ratio(void);
4761static void setup_min_slab_ratio(void);
4760#else /* CONFIG_NUMA */ 4762#else /* CONFIG_NUMA */
4761 4763
4762static void set_zonelist_order(void) 4764static void set_zonelist_order(void)
@@ -5878,9 +5880,6 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
5878 zone->managed_pages = is_highmem_idx(j) ? realsize : freesize; 5880 zone->managed_pages = is_highmem_idx(j) ? realsize : freesize;
5879#ifdef CONFIG_NUMA 5881#ifdef CONFIG_NUMA
5880 zone->node = nid; 5882 zone->node = nid;
5881 pgdat->min_unmapped_pages += (freesize*sysctl_min_unmapped_ratio)
5882 / 100;
5883 pgdat->min_slab_pages += (freesize * sysctl_min_slab_ratio) / 100;
5884#endif 5883#endif
5885 zone->name = zone_names[j]; 5884 zone->name = zone_names[j];
5886 zone->zone_pgdat = pgdat; 5885 zone->zone_pgdat = pgdat;
@@ -6801,6 +6800,12 @@ int __meminit init_per_zone_wmark_min(void)
6801 setup_per_zone_wmarks(); 6800 setup_per_zone_wmarks();
6802 refresh_zone_stat_thresholds(); 6801 refresh_zone_stat_thresholds();
6803 setup_per_zone_lowmem_reserve(); 6802 setup_per_zone_lowmem_reserve();
6803
6804#ifdef CONFIG_NUMA
6805 setup_min_unmapped_ratio();
6806 setup_min_slab_ratio();
6807#endif
6808
6804 return 0; 6809 return 0;
6805} 6810}
6806core_initcall(init_per_zone_wmark_min) 6811core_initcall(init_per_zone_wmark_min)
@@ -6842,43 +6847,58 @@ int watermark_scale_factor_sysctl_handler(struct ctl_table *table, int write,
6842} 6847}
6843 6848
6844#ifdef CONFIG_NUMA 6849#ifdef CONFIG_NUMA
6850static void setup_min_unmapped_ratio(void)
6851{
6852 pg_data_t *pgdat;
6853 struct zone *zone;
6854
6855 for_each_online_pgdat(pgdat)
6856 pgdat->min_unmapped_pages = 0;
6857
6858 for_each_zone(zone)
6859 zone->zone_pgdat->min_unmapped_pages += (zone->managed_pages *
6860 sysctl_min_unmapped_ratio) / 100;
6861}
6862
6863
6845int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *table, int write, 6864int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *table, int write,
6846 void __user *buffer, size_t *length, loff_t *ppos) 6865 void __user *buffer, size_t *length, loff_t *ppos)
6847{ 6866{
6848 struct pglist_data *pgdat;
6849 struct zone *zone;
6850 int rc; 6867 int rc;
6851 6868
6852 rc = proc_dointvec_minmax(table, write, buffer, length, ppos); 6869 rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
6853 if (rc) 6870 if (rc)
6854 return rc; 6871 return rc;
6855 6872
6873 setup_min_unmapped_ratio();
6874
6875 return 0;
6876}
6877
6878static void setup_min_slab_ratio(void)
6879{
6880 pg_data_t *pgdat;
6881 struct zone *zone;
6882
6856 for_each_online_pgdat(pgdat) 6883 for_each_online_pgdat(pgdat)
6857 pgdat->min_slab_pages = 0; 6884 pgdat->min_slab_pages = 0;
6858 6885
6859 for_each_zone(zone) 6886 for_each_zone(zone)
6860 zone->zone_pgdat->min_unmapped_pages += (zone->managed_pages * 6887 zone->zone_pgdat->min_slab_pages += (zone->managed_pages *
6861 sysctl_min_unmapped_ratio) / 100; 6888 sysctl_min_slab_ratio) / 100;
6862 return 0;
6863} 6889}
6864 6890
6865int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *table, int write, 6891int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *table, int write,
6866 void __user *buffer, size_t *length, loff_t *ppos) 6892 void __user *buffer, size_t *length, loff_t *ppos)
6867{ 6893{
6868 struct pglist_data *pgdat;
6869 struct zone *zone;
6870 int rc; 6894 int rc;
6871 6895
6872 rc = proc_dointvec_minmax(table, write, buffer, length, ppos); 6896 rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
6873 if (rc) 6897 if (rc)
6874 return rc; 6898 return rc;
6875 6899
6876 for_each_online_pgdat(pgdat) 6900 setup_min_slab_ratio();
6877 pgdat->min_slab_pages = 0;
6878 6901
6879 for_each_zone(zone)
6880 zone->zone_pgdat->min_slab_pages += (zone->managed_pages *
6881 sysctl_min_slab_ratio) / 100;
6882 return 0; 6902 return 0;
6883} 6903}
6884#endif 6904#endif
diff --git a/mm/readahead.c b/mm/readahead.c
index 65ec288dc057..c8a955b1297e 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/dax.h>
11#include <linux/gfp.h> 12#include <linux/gfp.h>
12#include <linux/export.h> 13#include <linux/export.h>
13#include <linux/blkdev.h> 14#include <linux/blkdev.h>
@@ -544,6 +545,14 @@ do_readahead(struct address_space *mapping, struct file *filp,
544 if (!mapping || !mapping->a_ops) 545 if (!mapping || !mapping->a_ops)
545 return -EINVAL; 546 return -EINVAL;
546 547
548 /*
549 * Readahead doesn't make sense for DAX inodes, but we don't want it
550 * to report a failure either. Instead, we just return success and
551 * don't do any work.
552 */
553 if (dax_mapping(mapping))
554 return 0;
555
547 return force_page_cache_readahead(mapping, filp, index, nr); 556 return force_page_cache_readahead(mapping, filp, index, nr);
548} 557}
549 558
diff --git a/mm/rmap.c b/mm/rmap.c
index 709bc83703b1..1ef36404e7b2 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1284,8 +1284,9 @@ void page_add_file_rmap(struct page *page, bool compound)
1284 VM_BUG_ON_PAGE(!PageSwapBacked(page), page); 1284 VM_BUG_ON_PAGE(!PageSwapBacked(page), page);
1285 __inc_node_page_state(page, NR_SHMEM_PMDMAPPED); 1285 __inc_node_page_state(page, NR_SHMEM_PMDMAPPED);
1286 } else { 1286 } else {
1287 if (PageTransCompound(page)) { 1287 if (PageTransCompound(page) && page_mapping(page)) {
1288 VM_BUG_ON_PAGE(!PageLocked(page), page); 1288 VM_WARN_ON_ONCE(!PageLocked(page));
1289
1289 SetPageDoubleMap(compound_head(page)); 1290 SetPageDoubleMap(compound_head(page));
1290 if (PageMlocked(page)) 1291 if (PageMlocked(page))
1291 clear_page_mlock(compound_head(page)); 1292 clear_page_mlock(compound_head(page));
@@ -1303,7 +1304,7 @@ static void page_remove_file_rmap(struct page *page, bool compound)
1303{ 1304{
1304 int i, nr = 1; 1305 int i, nr = 1;
1305 1306
1306 VM_BUG_ON_PAGE(compound && !PageTransHuge(page), page); 1307 VM_BUG_ON_PAGE(compound && !PageHead(page), page);
1307 lock_page_memcg(page); 1308 lock_page_memcg(page);
1308 1309
1309 /* Hugepages are not counted in NR_FILE_MAPPED for now. */ 1310 /* Hugepages are not counted in NR_FILE_MAPPED for now. */
diff --git a/mm/shmem.c b/mm/shmem.c
index 7f7748a0f9e1..fd8b2b5741b1 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3975,7 +3975,9 @@ static ssize_t shmem_enabled_store(struct kobject *kobj,
3975 3975
3976struct kobj_attribute shmem_enabled_attr = 3976struct kobj_attribute shmem_enabled_attr =
3977 __ATTR(shmem_enabled, 0644, shmem_enabled_show, shmem_enabled_store); 3977 __ATTR(shmem_enabled, 0644, shmem_enabled_show, shmem_enabled_store);
3978#endif /* CONFIG_TRANSPARENT_HUGE_PAGECACHE && CONFIG_SYSFS */
3978 3979
3980#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE
3979bool shmem_huge_enabled(struct vm_area_struct *vma) 3981bool shmem_huge_enabled(struct vm_area_struct *vma)
3980{ 3982{
3981 struct inode *inode = file_inode(vma->vm_file); 3983 struct inode *inode = file_inode(vma->vm_file);
@@ -4006,7 +4008,7 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)
4006 return false; 4008 return false;
4007 } 4009 }
4008} 4010}
4009#endif /* CONFIG_TRANSPARENT_HUGE_PAGECACHE && CONFIG_SYSFS */ 4011#endif /* CONFIG_TRANSPARENT_HUGE_PAGECACHE */
4010 4012
4011#else /* !CONFIG_SHMEM */ 4013#else /* !CONFIG_SHMEM */
4012 4014
diff --git a/mm/slub.c b/mm/slub.c
index cead06394e9e..9adae58462f8 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3629,6 +3629,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
3629 */ 3629 */
3630static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) 3630static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
3631{ 3631{
3632 LIST_HEAD(discard);
3632 struct page *page, *h; 3633 struct page *page, *h;
3633 3634
3634 BUG_ON(irqs_disabled()); 3635 BUG_ON(irqs_disabled());
@@ -3636,13 +3637,16 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
3636 list_for_each_entry_safe(page, h, &n->partial, lru) { 3637 list_for_each_entry_safe(page, h, &n->partial, lru) {
3637 if (!page->inuse) { 3638 if (!page->inuse) {
3638 remove_partial(n, page); 3639 remove_partial(n, page);
3639 discard_slab(s, page); 3640 list_add(&page->lru, &discard);
3640 } else { 3641 } else {
3641 list_slab_objects(s, page, 3642 list_slab_objects(s, page,
3642 "Objects remaining in %s on __kmem_cache_shutdown()"); 3643 "Objects remaining in %s on __kmem_cache_shutdown()");
3643 } 3644 }
3644 } 3645 }
3645 spin_unlock_irq(&n->list_lock); 3646 spin_unlock_irq(&n->list_lock);
3647
3648 list_for_each_entry_safe(page, h, &discard, lru)
3649 discard_slab(s, page);
3646} 3650}
3647 3651
3648/* 3652/*
diff --git a/mm/usercopy.c b/mm/usercopy.c
index 8ebae91a6b55..a3cc3052f830 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -83,7 +83,7 @@ static bool overlaps(const void *ptr, unsigned long n, unsigned long low,
83 unsigned long check_high = check_low + n; 83 unsigned long check_high = check_low + n;
84 84
85 /* Does not overlap if entirely above or entirely below. */ 85 /* Does not overlap if entirely above or entirely below. */
86 if (check_low >= high || check_high < low) 86 if (check_low >= high || check_high <= low)
87 return false; 87 return false;
88 88
89 return true; 89 return true;
@@ -124,7 +124,7 @@ static inline const char *check_kernel_text_object(const void *ptr,
124static inline const char *check_bogus_address(const void *ptr, unsigned long n) 124static inline const char *check_bogus_address(const void *ptr, unsigned long n)
125{ 125{
126 /* Reject if object wraps past end of memory. */ 126 /* Reject if object wraps past end of memory. */
127 if (ptr + n < ptr) 127 if ((unsigned long)ptr + n < (unsigned long)ptr)
128 return "<wrapped address>"; 128 return "<wrapped address>";
129 129
130 /* Reject if NULL or ZERO-allocation. */ 130 /* Reject if NULL or ZERO-allocation. */
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 82a116ba590e..8de138d3306b 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -169,7 +169,7 @@ int register_vlan_dev(struct net_device *dev)
169 if (err < 0) 169 if (err < 0)
170 goto out_uninit_mvrp; 170 goto out_uninit_mvrp;
171 171
172 vlan->nest_level = dev_get_nest_level(real_dev, is_vlan_dev) + 1; 172 vlan->nest_level = dev_get_nest_level(real_dev) + 1;
173 err = register_netdevice(dev); 173 err = register_netdevice(dev);
174 if (err < 0) 174 if (err < 0)
175 goto out_uninit_mvrp; 175 goto out_uninit_mvrp;
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 4acb1d5417aa..f24b25c25106 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -507,8 +507,8 @@ err_out:
507 /* wakeup anybody waiting for slots to pin pages */ 507 /* wakeup anybody waiting for slots to pin pages */
508 wake_up(&vp_wq); 508 wake_up(&vp_wq);
509 } 509 }
510 kfree(in_pages); 510 kvfree(in_pages);
511 kfree(out_pages); 511 kvfree(out_pages);
512 return err; 512 return err;
513} 513}
514 514
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index c18080ad4085..cd620fab41b0 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -267,7 +267,7 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
267 267
268 /* If old entry was unassociated with any port, then delete it. */ 268 /* If old entry was unassociated with any port, then delete it. */
269 f = __br_fdb_get(br, br->dev->dev_addr, 0); 269 f = __br_fdb_get(br, br->dev->dev_addr, 0);
270 if (f && f->is_local && !f->dst) 270 if (f && f->is_local && !f->dst && !f->added_by_user)
271 fdb_delete_local(br, NULL, f); 271 fdb_delete_local(br, NULL, f);
272 272
273 fdb_insert(br, NULL, newaddr, 0); 273 fdb_insert(br, NULL, newaddr, 0);
@@ -282,7 +282,7 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
282 if (!br_vlan_should_use(v)) 282 if (!br_vlan_should_use(v))
283 continue; 283 continue;
284 f = __br_fdb_get(br, br->dev->dev_addr, v->vid); 284 f = __br_fdb_get(br, br->dev->dev_addr, v->vid);
285 if (f && f->is_local && !f->dst) 285 if (f && f->is_local && !f->dst && !f->added_by_user)
286 fdb_delete_local(br, NULL, f); 286 fdb_delete_local(br, NULL, f);
287 fdb_insert(br, NULL, newaddr, v->vid); 287 fdb_insert(br, NULL, newaddr, v->vid);
288 } 288 }
@@ -764,20 +764,25 @@ out:
764} 764}
765 765
766/* Update (create or replace) forwarding database entry */ 766/* Update (create or replace) forwarding database entry */
767static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr, 767static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
768 __u16 state, __u16 flags, __u16 vid) 768 const __u8 *addr, __u16 state, __u16 flags, __u16 vid)
769{ 769{
770 struct net_bridge *br = source->br;
771 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)]; 770 struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
772 struct net_bridge_fdb_entry *fdb; 771 struct net_bridge_fdb_entry *fdb;
773 bool modified = false; 772 bool modified = false;
774 773
775 /* If the port cannot learn allow only local and static entries */ 774 /* If the port cannot learn allow only local and static entries */
776 if (!(state & NUD_PERMANENT) && !(state & NUD_NOARP) && 775 if (source && !(state & NUD_PERMANENT) && !(state & NUD_NOARP) &&
777 !(source->state == BR_STATE_LEARNING || 776 !(source->state == BR_STATE_LEARNING ||
778 source->state == BR_STATE_FORWARDING)) 777 source->state == BR_STATE_FORWARDING))
779 return -EPERM; 778 return -EPERM;
780 779
780 if (!source && !(state & NUD_PERMANENT)) {
781 pr_info("bridge: RTM_NEWNEIGH %s without NUD_PERMANENT\n",
782 br->dev->name);
783 return -EINVAL;
784 }
785
781 fdb = fdb_find(head, addr, vid); 786 fdb = fdb_find(head, addr, vid);
782 if (fdb == NULL) { 787 if (fdb == NULL) {
783 if (!(flags & NLM_F_CREATE)) 788 if (!(flags & NLM_F_CREATE))
@@ -832,22 +837,28 @@ static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr,
832 return 0; 837 return 0;
833} 838}
834 839
835static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge_port *p, 840static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
836 const unsigned char *addr, u16 nlh_flags, u16 vid) 841 struct net_bridge_port *p, const unsigned char *addr,
842 u16 nlh_flags, u16 vid)
837{ 843{
838 int err = 0; 844 int err = 0;
839 845
840 if (ndm->ndm_flags & NTF_USE) { 846 if (ndm->ndm_flags & NTF_USE) {
847 if (!p) {
848 pr_info("bridge: RTM_NEWNEIGH %s with NTF_USE is not supported\n",
849 br->dev->name);
850 return -EINVAL;
851 }
841 local_bh_disable(); 852 local_bh_disable();
842 rcu_read_lock(); 853 rcu_read_lock();
843 br_fdb_update(p->br, p, addr, vid, true); 854 br_fdb_update(br, p, addr, vid, true);
844 rcu_read_unlock(); 855 rcu_read_unlock();
845 local_bh_enable(); 856 local_bh_enable();
846 } else { 857 } else {
847 spin_lock_bh(&p->br->hash_lock); 858 spin_lock_bh(&br->hash_lock);
848 err = fdb_add_entry(p, addr, ndm->ndm_state, 859 err = fdb_add_entry(br, p, addr, ndm->ndm_state,
849 nlh_flags, vid); 860 nlh_flags, vid);
850 spin_unlock_bh(&p->br->hash_lock); 861 spin_unlock_bh(&br->hash_lock);
851 } 862 }
852 863
853 return err; 864 return err;
@@ -884,6 +895,7 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
884 dev->name); 895 dev->name);
885 return -EINVAL; 896 return -EINVAL;
886 } 897 }
898 br = p->br;
887 vg = nbp_vlan_group(p); 899 vg = nbp_vlan_group(p);
888 } 900 }
889 901
@@ -895,15 +907,9 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
895 } 907 }
896 908
897 /* VID was specified, so use it. */ 909 /* VID was specified, so use it. */
898 if (dev->priv_flags & IFF_EBRIDGE) 910 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, vid);
899 err = br_fdb_insert(br, NULL, addr, vid);
900 else
901 err = __br_fdb_add(ndm, p, addr, nlh_flags, vid);
902 } else { 911 } else {
903 if (dev->priv_flags & IFF_EBRIDGE) 912 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, 0);
904 err = br_fdb_insert(br, NULL, addr, 0);
905 else
906 err = __br_fdb_add(ndm, p, addr, nlh_flags, 0);
907 if (err || !vg || !vg->num_vlans) 913 if (err || !vg || !vg->num_vlans)
908 goto out; 914 goto out;
909 915
@@ -914,11 +920,7 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
914 list_for_each_entry(v, &vg->vlan_list, vlist) { 920 list_for_each_entry(v, &vg->vlan_list, vlist) {
915 if (!br_vlan_should_use(v)) 921 if (!br_vlan_should_use(v))
916 continue; 922 continue;
917 if (dev->priv_flags & IFF_EBRIDGE) 923 err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v->vid);
918 err = br_fdb_insert(br, NULL, addr, v->vid);
919 else
920 err = __br_fdb_add(ndm, p, addr, nlh_flags,
921 v->vid);
922 if (err) 924 if (err)
923 goto out; 925 goto out;
924 } 926 }
diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
index c83326c5ba58..ef34a02719d7 100644
--- a/net/ceph/mon_client.c
+++ b/net/ceph/mon_client.c
@@ -574,7 +574,7 @@ static void complete_generic_request(struct ceph_mon_generic_request *req)
574 put_generic_request(req); 574 put_generic_request(req);
575} 575}
576 576
577void cancel_generic_request(struct ceph_mon_generic_request *req) 577static void cancel_generic_request(struct ceph_mon_generic_request *req)
578{ 578{
579 struct ceph_mon_client *monc = req->monc; 579 struct ceph_mon_client *monc = req->monc;
580 struct ceph_mon_generic_request *lookup_req; 580 struct ceph_mon_generic_request *lookup_req;
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index b5ec09612ff7..a97e7b506612 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -4220,7 +4220,7 @@ static struct ceph_msg *alloc_msg_with_page_vector(struct ceph_msg_header *hdr)
4220 4220
4221 pages = ceph_alloc_page_vector(calc_pages_for(0, data_len), 4221 pages = ceph_alloc_page_vector(calc_pages_for(0, data_len),
4222 GFP_NOIO); 4222 GFP_NOIO);
4223 if (!pages) { 4223 if (IS_ERR(pages)) {
4224 ceph_msg_put(m); 4224 ceph_msg_put(m);
4225 return NULL; 4225 return NULL;
4226 } 4226 }
diff --git a/net/ceph/string_table.c b/net/ceph/string_table.c
index ca53c8319209..22fb96efcf34 100644
--- a/net/ceph/string_table.c
+++ b/net/ceph/string_table.c
@@ -84,12 +84,6 @@ retry:
84} 84}
85EXPORT_SYMBOL(ceph_find_or_create_string); 85EXPORT_SYMBOL(ceph_find_or_create_string);
86 86
87static void ceph_free_string(struct rcu_head *head)
88{
89 struct ceph_string *cs = container_of(head, struct ceph_string, rcu);
90 kfree(cs);
91}
92
93void ceph_release_string(struct kref *ref) 87void ceph_release_string(struct kref *ref)
94{ 88{
95 struct ceph_string *cs = container_of(ref, struct ceph_string, kref); 89 struct ceph_string *cs = container_of(ref, struct ceph_string, kref);
@@ -101,7 +95,7 @@ void ceph_release_string(struct kref *ref)
101 } 95 }
102 spin_unlock(&string_tree_lock); 96 spin_unlock(&string_tree_lock);
103 97
104 call_rcu(&cs->rcu, ceph_free_string); 98 kfree_rcu(cs, rcu);
105} 99}
106EXPORT_SYMBOL(ceph_release_string); 100EXPORT_SYMBOL(ceph_release_string);
107 101
diff --git a/net/core/dev.c b/net/core/dev.c
index 4ce07dc25573..dd6ce598de89 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6045,8 +6045,7 @@ void *netdev_lower_dev_get_private(struct net_device *dev,
6045EXPORT_SYMBOL(netdev_lower_dev_get_private); 6045EXPORT_SYMBOL(netdev_lower_dev_get_private);
6046 6046
6047 6047
6048int dev_get_nest_level(struct net_device *dev, 6048int dev_get_nest_level(struct net_device *dev)
6049 bool (*type_check)(const struct net_device *dev))
6050{ 6049{
6051 struct net_device *lower = NULL; 6050 struct net_device *lower = NULL;
6052 struct list_head *iter; 6051 struct list_head *iter;
@@ -6056,15 +6055,12 @@ int dev_get_nest_level(struct net_device *dev,
6056 ASSERT_RTNL(); 6055 ASSERT_RTNL();
6057 6056
6058 netdev_for_each_lower_dev(dev, lower, iter) { 6057 netdev_for_each_lower_dev(dev, lower, iter) {
6059 nest = dev_get_nest_level(lower, type_check); 6058 nest = dev_get_nest_level(lower);
6060 if (max_nest < nest) 6059 if (max_nest < nest)
6061 max_nest = nest; 6060 max_nest = nest;
6062 } 6061 }
6063 6062
6064 if (type_check(dev)) 6063 return max_nest + 1;
6065 max_nest++;
6066
6067 return max_nest;
6068} 6064}
6069EXPORT_SYMBOL(dev_get_nest_level); 6065EXPORT_SYMBOL(dev_get_nest_level);
6070 6066
diff --git a/net/core/filter.c b/net/core/filter.c
index 5708999f8a79..cb06aceb512a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1355,56 +1355,47 @@ static inline int bpf_try_make_writable(struct sk_buff *skb,
1355{ 1355{
1356 int err; 1356 int err;
1357 1357
1358 if (!skb_cloned(skb)) 1358 err = skb_ensure_writable(skb, write_len);
1359 return 0; 1359 bpf_compute_data_end(skb);
1360 if (skb_clone_writable(skb, write_len)) 1360
1361 return 0;
1362 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1363 if (!err)
1364 bpf_compute_data_end(skb);
1365 return err; 1361 return err;
1366} 1362}
1367 1363
1364static inline void bpf_push_mac_rcsum(struct sk_buff *skb)
1365{
1366 if (skb_at_tc_ingress(skb))
1367 skb_postpush_rcsum(skb, skb_mac_header(skb), skb->mac_len);
1368}
1369
1370static inline void bpf_pull_mac_rcsum(struct sk_buff *skb)
1371{
1372 if (skb_at_tc_ingress(skb))
1373 skb_postpull_rcsum(skb, skb_mac_header(skb), skb->mac_len);
1374}
1375
1368static u64 bpf_skb_store_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 flags) 1376static u64 bpf_skb_store_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 flags)
1369{ 1377{
1370 struct bpf_scratchpad *sp = this_cpu_ptr(&bpf_sp);
1371 struct sk_buff *skb = (struct sk_buff *) (long) r1; 1378 struct sk_buff *skb = (struct sk_buff *) (long) r1;
1372 int offset = (int) r2; 1379 unsigned int offset = (unsigned int) r2;
1373 void *from = (void *) (long) r3; 1380 void *from = (void *) (long) r3;
1374 unsigned int len = (unsigned int) r4; 1381 unsigned int len = (unsigned int) r4;
1375 void *ptr; 1382 void *ptr;
1376 1383
1377 if (unlikely(flags & ~(BPF_F_RECOMPUTE_CSUM | BPF_F_INVALIDATE_HASH))) 1384 if (unlikely(flags & ~(BPF_F_RECOMPUTE_CSUM | BPF_F_INVALIDATE_HASH)))
1378 return -EINVAL; 1385 return -EINVAL;
1379 1386 if (unlikely(offset > 0xffff))
1380 /* bpf verifier guarantees that:
1381 * 'from' pointer points to bpf program stack
1382 * 'len' bytes of it were initialized
1383 * 'len' > 0
1384 * 'skb' is a valid pointer to 'struct sk_buff'
1385 *
1386 * so check for invalid 'offset' and too large 'len'
1387 */
1388 if (unlikely((u32) offset > 0xffff || len > sizeof(sp->buff)))
1389 return -EFAULT; 1387 return -EFAULT;
1390 if (unlikely(bpf_try_make_writable(skb, offset + len))) 1388 if (unlikely(bpf_try_make_writable(skb, offset + len)))
1391 return -EFAULT; 1389 return -EFAULT;
1392 1390
1393 ptr = skb_header_pointer(skb, offset, len, sp->buff); 1391 ptr = skb->data + offset;
1394 if (unlikely(!ptr))
1395 return -EFAULT;
1396
1397 if (flags & BPF_F_RECOMPUTE_CSUM) 1392 if (flags & BPF_F_RECOMPUTE_CSUM)
1398 skb_postpull_rcsum(skb, ptr, len); 1393 __skb_postpull_rcsum(skb, ptr, len, offset);
1399 1394
1400 memcpy(ptr, from, len); 1395 memcpy(ptr, from, len);
1401 1396
1402 if (ptr == sp->buff)
1403 /* skb_store_bits cannot return -EFAULT here */
1404 skb_store_bits(skb, offset, ptr, len);
1405
1406 if (flags & BPF_F_RECOMPUTE_CSUM) 1397 if (flags & BPF_F_RECOMPUTE_CSUM)
1407 skb_postpush_rcsum(skb, ptr, len); 1398 __skb_postpush_rcsum(skb, ptr, len, offset);
1408 if (flags & BPF_F_INVALIDATE_HASH) 1399 if (flags & BPF_F_INVALIDATE_HASH)
1409 skb_clear_hash(skb); 1400 skb_clear_hash(skb);
1410 1401
@@ -1425,12 +1416,12 @@ static const struct bpf_func_proto bpf_skb_store_bytes_proto = {
1425static u64 bpf_skb_load_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) 1416static u64 bpf_skb_load_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
1426{ 1417{
1427 const struct sk_buff *skb = (const struct sk_buff *)(unsigned long) r1; 1418 const struct sk_buff *skb = (const struct sk_buff *)(unsigned long) r1;
1428 int offset = (int) r2; 1419 unsigned int offset = (unsigned int) r2;
1429 void *to = (void *)(unsigned long) r3; 1420 void *to = (void *)(unsigned long) r3;
1430 unsigned int len = (unsigned int) r4; 1421 unsigned int len = (unsigned int) r4;
1431 void *ptr; 1422 void *ptr;
1432 1423
1433 if (unlikely((u32) offset > 0xffff)) 1424 if (unlikely(offset > 0xffff))
1434 goto err_clear; 1425 goto err_clear;
1435 1426
1436 ptr = skb_header_pointer(skb, offset, len, to); 1427 ptr = skb_header_pointer(skb, offset, len, to);
@@ -1458,20 +1449,17 @@ static const struct bpf_func_proto bpf_skb_load_bytes_proto = {
1458static u64 bpf_l3_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags) 1449static u64 bpf_l3_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags)
1459{ 1450{
1460 struct sk_buff *skb = (struct sk_buff *) (long) r1; 1451 struct sk_buff *skb = (struct sk_buff *) (long) r1;
1461 int offset = (int) r2; 1452 unsigned int offset = (unsigned int) r2;
1462 __sum16 sum, *ptr; 1453 __sum16 *ptr;
1463 1454
1464 if (unlikely(flags & ~(BPF_F_HDR_FIELD_MASK))) 1455 if (unlikely(flags & ~(BPF_F_HDR_FIELD_MASK)))
1465 return -EINVAL; 1456 return -EINVAL;
1466 if (unlikely((u32) offset > 0xffff)) 1457 if (unlikely(offset > 0xffff || offset & 1))
1467 return -EFAULT; 1458 return -EFAULT;
1468 if (unlikely(bpf_try_make_writable(skb, offset + sizeof(sum)))) 1459 if (unlikely(bpf_try_make_writable(skb, offset + sizeof(*ptr))))
1469 return -EFAULT;
1470
1471 ptr = skb_header_pointer(skb, offset, sizeof(sum), &sum);
1472 if (unlikely(!ptr))
1473 return -EFAULT; 1460 return -EFAULT;
1474 1461
1462 ptr = (__sum16 *)(skb->data + offset);
1475 switch (flags & BPF_F_HDR_FIELD_MASK) { 1463 switch (flags & BPF_F_HDR_FIELD_MASK) {
1476 case 0: 1464 case 0:
1477 if (unlikely(from != 0)) 1465 if (unlikely(from != 0))
@@ -1489,10 +1477,6 @@ static u64 bpf_l3_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags)
1489 return -EINVAL; 1477 return -EINVAL;
1490 } 1478 }
1491 1479
1492 if (ptr == &sum)
1493 /* skb_store_bits guaranteed to not return -EFAULT here */
1494 skb_store_bits(skb, offset, ptr, sizeof(sum));
1495
1496 return 0; 1480 return 0;
1497} 1481}
1498 1482
@@ -1512,20 +1496,18 @@ static u64 bpf_l4_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags)
1512 struct sk_buff *skb = (struct sk_buff *) (long) r1; 1496 struct sk_buff *skb = (struct sk_buff *) (long) r1;
1513 bool is_pseudo = flags & BPF_F_PSEUDO_HDR; 1497 bool is_pseudo = flags & BPF_F_PSEUDO_HDR;
1514 bool is_mmzero = flags & BPF_F_MARK_MANGLED_0; 1498 bool is_mmzero = flags & BPF_F_MARK_MANGLED_0;
1515 int offset = (int) r2; 1499 unsigned int offset = (unsigned int) r2;
1516 __sum16 sum, *ptr; 1500 __sum16 *ptr;
1517 1501
1518 if (unlikely(flags & ~(BPF_F_MARK_MANGLED_0 | BPF_F_PSEUDO_HDR | 1502 if (unlikely(flags & ~(BPF_F_MARK_MANGLED_0 | BPF_F_PSEUDO_HDR |
1519 BPF_F_HDR_FIELD_MASK))) 1503 BPF_F_HDR_FIELD_MASK)))
1520 return -EINVAL; 1504 return -EINVAL;
1521 if (unlikely((u32) offset > 0xffff)) 1505 if (unlikely(offset > 0xffff || offset & 1))
1522 return -EFAULT; 1506 return -EFAULT;
1523 if (unlikely(bpf_try_make_writable(skb, offset + sizeof(sum)))) 1507 if (unlikely(bpf_try_make_writable(skb, offset + sizeof(*ptr))))
1524 return -EFAULT; 1508 return -EFAULT;
1525 1509
1526 ptr = skb_header_pointer(skb, offset, sizeof(sum), &sum); 1510 ptr = (__sum16 *)(skb->data + offset);
1527 if (unlikely(!ptr))
1528 return -EFAULT;
1529 if (is_mmzero && !*ptr) 1511 if (is_mmzero && !*ptr)
1530 return 0; 1512 return 0;
1531 1513
@@ -1548,10 +1530,6 @@ static u64 bpf_l4_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags)
1548 1530
1549 if (is_mmzero && !*ptr) 1531 if (is_mmzero && !*ptr)
1550 *ptr = CSUM_MANGLED_0; 1532 *ptr = CSUM_MANGLED_0;
1551 if (ptr == &sum)
1552 /* skb_store_bits guaranteed to not return -EFAULT here */
1553 skb_store_bits(skb, offset, ptr, sizeof(sum));
1554
1555 return 0; 1533 return 0;
1556} 1534}
1557 1535
@@ -1607,9 +1585,6 @@ static const struct bpf_func_proto bpf_csum_diff_proto = {
1607 1585
1608static inline int __bpf_rx_skb(struct net_device *dev, struct sk_buff *skb) 1586static inline int __bpf_rx_skb(struct net_device *dev, struct sk_buff *skb)
1609{ 1587{
1610 if (skb_at_tc_ingress(skb))
1611 skb_postpush_rcsum(skb, skb_mac_header(skb), skb->mac_len);
1612
1613 return dev_forward_skb(dev, skb); 1588 return dev_forward_skb(dev, skb);
1614} 1589}
1615 1590
@@ -1648,6 +1623,8 @@ static u64 bpf_clone_redirect(u64 r1, u64 ifindex, u64 flags, u64 r4, u64 r5)
1648 if (unlikely(!skb)) 1623 if (unlikely(!skb))
1649 return -ENOMEM; 1624 return -ENOMEM;
1650 1625
1626 bpf_push_mac_rcsum(skb);
1627
1651 return flags & BPF_F_INGRESS ? 1628 return flags & BPF_F_INGRESS ?
1652 __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb); 1629 __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb);
1653} 1630}
@@ -1693,6 +1670,8 @@ int skb_do_redirect(struct sk_buff *skb)
1693 return -EINVAL; 1670 return -EINVAL;
1694 } 1671 }
1695 1672
1673 bpf_push_mac_rcsum(skb);
1674
1696 return ri->flags & BPF_F_INGRESS ? 1675 return ri->flags & BPF_F_INGRESS ?
1697 __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb); 1676 __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb);
1698} 1677}
@@ -1756,7 +1735,10 @@ static u64 bpf_skb_vlan_push(u64 r1, u64 r2, u64 vlan_tci, u64 r4, u64 r5)
1756 vlan_proto != htons(ETH_P_8021AD))) 1735 vlan_proto != htons(ETH_P_8021AD)))
1757 vlan_proto = htons(ETH_P_8021Q); 1736 vlan_proto = htons(ETH_P_8021Q);
1758 1737
1738 bpf_push_mac_rcsum(skb);
1759 ret = skb_vlan_push(skb, vlan_proto, vlan_tci); 1739 ret = skb_vlan_push(skb, vlan_proto, vlan_tci);
1740 bpf_pull_mac_rcsum(skb);
1741
1760 bpf_compute_data_end(skb); 1742 bpf_compute_data_end(skb);
1761 return ret; 1743 return ret;
1762} 1744}
@@ -1776,7 +1758,10 @@ static u64 bpf_skb_vlan_pop(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
1776 struct sk_buff *skb = (struct sk_buff *) (long) r1; 1758 struct sk_buff *skb = (struct sk_buff *) (long) r1;
1777 int ret; 1759 int ret;
1778 1760
1761 bpf_push_mac_rcsum(skb);
1779 ret = skb_vlan_pop(skb); 1762 ret = skb_vlan_pop(skb);
1763 bpf_pull_mac_rcsum(skb);
1764
1780 bpf_compute_data_end(skb); 1765 bpf_compute_data_end(skb);
1781 return ret; 1766 return ret;
1782} 1767}
@@ -2298,7 +2283,7 @@ bpf_get_skb_set_tunnel_proto(enum bpf_func_id which)
2298} 2283}
2299 2284
2300#ifdef CONFIG_SOCK_CGROUP_DATA 2285#ifdef CONFIG_SOCK_CGROUP_DATA
2301static u64 bpf_skb_in_cgroup(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) 2286static u64 bpf_skb_under_cgroup(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
2302{ 2287{
2303 struct sk_buff *skb = (struct sk_buff *)(long)r1; 2288 struct sk_buff *skb = (struct sk_buff *)(long)r1;
2304 struct bpf_map *map = (struct bpf_map *)(long)r2; 2289 struct bpf_map *map = (struct bpf_map *)(long)r2;
@@ -2321,8 +2306,8 @@ static u64 bpf_skb_in_cgroup(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
2321 return cgroup_is_descendant(sock_cgroup_ptr(&sk->sk_cgrp_data), cgrp); 2306 return cgroup_is_descendant(sock_cgroup_ptr(&sk->sk_cgrp_data), cgrp);
2322} 2307}
2323 2308
2324static const struct bpf_func_proto bpf_skb_in_cgroup_proto = { 2309static const struct bpf_func_proto bpf_skb_under_cgroup_proto = {
2325 .func = bpf_skb_in_cgroup, 2310 .func = bpf_skb_under_cgroup,
2326 .gpl_only = false, 2311 .gpl_only = false,
2327 .ret_type = RET_INTEGER, 2312 .ret_type = RET_INTEGER,
2328 .arg1_type = ARG_PTR_TO_CTX, 2313 .arg1_type = ARG_PTR_TO_CTX,
@@ -2402,8 +2387,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
2402 case BPF_FUNC_get_smp_processor_id: 2387 case BPF_FUNC_get_smp_processor_id:
2403 return &bpf_get_smp_processor_id_proto; 2388 return &bpf_get_smp_processor_id_proto;
2404#ifdef CONFIG_SOCK_CGROUP_DATA 2389#ifdef CONFIG_SOCK_CGROUP_DATA
2405 case BPF_FUNC_skb_in_cgroup: 2390 case BPF_FUNC_skb_under_cgroup:
2406 return &bpf_skb_in_cgroup_proto; 2391 return &bpf_skb_under_cgroup_proto;
2407#endif 2392#endif
2408 default: 2393 default:
2409 return sk_filter_func_proto(func_id); 2394 return sk_filter_func_proto(func_id);
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index d07fc076bea0..febca0f1008c 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -2452,9 +2452,7 @@ struct fib_route_iter {
2452static struct key_vector *fib_route_get_idx(struct fib_route_iter *iter, 2452static struct key_vector *fib_route_get_idx(struct fib_route_iter *iter,
2453 loff_t pos) 2453 loff_t pos)
2454{ 2454{
2455 struct fib_table *tb = iter->main_tb;
2456 struct key_vector *l, **tp = &iter->tnode; 2455 struct key_vector *l, **tp = &iter->tnode;
2457 struct trie *t;
2458 t_key key; 2456 t_key key;
2459 2457
2460 /* use cache location of next-to-find key */ 2458 /* use cache location of next-to-find key */
@@ -2462,8 +2460,6 @@ static struct key_vector *fib_route_get_idx(struct fib_route_iter *iter,
2462 pos -= iter->pos; 2460 pos -= iter->pos;
2463 key = iter->key; 2461 key = iter->key;
2464 } else { 2462 } else {
2465 t = (struct trie *)tb->tb_data;
2466 iter->tnode = t->kv;
2467 iter->pos = 0; 2463 iter->pos = 0;
2468 key = 0; 2464 key = 0;
2469 } 2465 }
@@ -2504,12 +2500,12 @@ static void *fib_route_seq_start(struct seq_file *seq, loff_t *pos)
2504 return NULL; 2500 return NULL;
2505 2501
2506 iter->main_tb = tb; 2502 iter->main_tb = tb;
2503 t = (struct trie *)tb->tb_data;
2504 iter->tnode = t->kv;
2507 2505
2508 if (*pos != 0) 2506 if (*pos != 0)
2509 return fib_route_get_idx(iter, *pos); 2507 return fib_route_get_idx(iter, *pos);
2510 2508
2511 t = (struct trie *)tb->tb_data;
2512 iter->tnode = t->kv;
2513 iter->pos = 0; 2509 iter->pos = 0;
2514 iter->key = 0; 2510 iter->key = 0;
2515 2511
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 5b1481be0282..113cc43df789 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -370,7 +370,6 @@ static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
370 tunnel->parms.o_flags, proto, tunnel->parms.o_key, 370 tunnel->parms.o_flags, proto, tunnel->parms.o_key,
371 htonl(tunnel->o_seqno)); 371 htonl(tunnel->o_seqno));
372 372
373 skb_set_inner_protocol(skb, proto);
374 ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol); 373 ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol);
375} 374}
376 375
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index a917903d5e97..cc701fa70b12 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -557,6 +557,33 @@ static struct rtnl_link_ops vti_link_ops __read_mostly = {
557 .get_link_net = ip_tunnel_get_link_net, 557 .get_link_net = ip_tunnel_get_link_net,
558}; 558};
559 559
560static bool is_vti_tunnel(const struct net_device *dev)
561{
562 return dev->netdev_ops == &vti_netdev_ops;
563}
564
565static int vti_device_event(struct notifier_block *unused,
566 unsigned long event, void *ptr)
567{
568 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
569 struct ip_tunnel *tunnel = netdev_priv(dev);
570
571 if (!is_vti_tunnel(dev))
572 return NOTIFY_DONE;
573
574 switch (event) {
575 case NETDEV_DOWN:
576 if (!net_eq(tunnel->net, dev_net(dev)))
577 xfrm_garbage_collect(tunnel->net);
578 break;
579 }
580 return NOTIFY_DONE;
581}
582
583static struct notifier_block vti_notifier_block __read_mostly = {
584 .notifier_call = vti_device_event,
585};
586
560static int __init vti_init(void) 587static int __init vti_init(void)
561{ 588{
562 const char *msg; 589 const char *msg;
@@ -564,6 +591,8 @@ static int __init vti_init(void)
564 591
565 pr_info("IPv4 over IPsec tunneling driver\n"); 592 pr_info("IPv4 over IPsec tunneling driver\n");
566 593
594 register_netdevice_notifier(&vti_notifier_block);
595
567 msg = "tunnel device"; 596 msg = "tunnel device";
568 err = register_pernet_device(&vti_net_ops); 597 err = register_pernet_device(&vti_net_ops);
569 if (err < 0) 598 if (err < 0)
@@ -596,6 +625,7 @@ xfrm_proto_ah_failed:
596xfrm_proto_esp_failed: 625xfrm_proto_esp_failed:
597 unregister_pernet_device(&vti_net_ops); 626 unregister_pernet_device(&vti_net_ops);
598pernet_dev_failed: 627pernet_dev_failed:
628 unregister_netdevice_notifier(&vti_notifier_block);
599 pr_err("vti init: failed to register %s\n", msg); 629 pr_err("vti init: failed to register %s\n", msg);
600 return err; 630 return err;
601} 631}
@@ -607,6 +637,7 @@ static void __exit vti_fini(void)
607 xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH); 637 xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
608 xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP); 638 xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP);
609 unregister_pernet_device(&vti_net_ops); 639 unregister_pernet_device(&vti_net_ops);
640 unregister_netdevice_notifier(&vti_notifier_block);
610} 641}
611 642
612module_init(vti_init); 643module_init(vti_init);
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index ab3e796596b1..df8425fcbc2c 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3543,7 +3543,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
3543 /* combine the user config with event to determine if permanent 3543 /* combine the user config with event to determine if permanent
3544 * addresses are to be removed from address hash table 3544 * addresses are to be removed from address hash table
3545 */ 3545 */
3546 keep_addr = !(how || _keep_addr <= 0); 3546 keep_addr = !(how || _keep_addr <= 0 || idev->cnf.disable_ipv6);
3547 3547
3548 /* Step 2: clear hash table */ 3548 /* Step 2: clear hash table */
3549 for (i = 0; i < IN6_ADDR_HSIZE; i++) { 3549 for (i = 0; i < IN6_ADDR_HSIZE; i++) {
@@ -3599,7 +3599,7 @@ restart:
3599 /* re-combine the user config with event to determine if permanent 3599 /* re-combine the user config with event to determine if permanent
3600 * addresses are to be removed from the interface list 3600 * addresses are to be removed from the interface list
3601 */ 3601 */
3602 keep_addr = (!how && _keep_addr > 0); 3602 keep_addr = (!how && _keep_addr > 0 && !idev->cnf.disable_ipv6);
3603 3603
3604 INIT_LIST_HEAD(&del_list); 3604 INIT_LIST_HEAD(&del_list);
3605 list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) { 3605 list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) {
diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c
index c53b92c617c5..37ac9de713c6 100644
--- a/net/ipv6/calipso.c
+++ b/net/ipv6/calipso.c
@@ -952,8 +952,10 @@ calipso_opt_insert(struct ipv6_opt_hdr *hop,
952 memcpy(new, hop, start); 952 memcpy(new, hop, start);
953 ret_val = calipso_genopt((unsigned char *)new, start, buf_len, doi_def, 953 ret_val = calipso_genopt((unsigned char *)new, start, buf_len, doi_def,
954 secattr); 954 secattr);
955 if (ret_val < 0) 955 if (ret_val < 0) {
956 kfree(new);
956 return ERR_PTR(ret_val); 957 return ERR_PTR(ret_val);
958 }
957 959
958 buf_len = start + ret_val; 960 buf_len = start + ret_val;
959 /* At this point buf_len aligns to 4n, so (buf_len & 4) pads to 8n */ 961 /* At this point buf_len aligns to 4n, so (buf_len & 4) pads to 8n */
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 776d145113e1..704274cbd495 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -519,8 +519,6 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
519 gre_build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags, 519 gre_build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags,
520 protocol, tunnel->parms.o_key, htonl(tunnel->o_seqno)); 520 protocol, tunnel->parms.o_key, htonl(tunnel->o_seqno));
521 521
522 skb_set_inner_protocol(skb, protocol);
523
524 return ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu, 522 return ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,
525 NEXTHDR_GRE); 523 NEXTHDR_GRE);
526} 524}
diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index fed40d1ec29b..0900352c924c 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -55,7 +55,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
55 struct icmp6hdr user_icmph; 55 struct icmp6hdr user_icmph;
56 int addr_type; 56 int addr_type;
57 struct in6_addr *daddr; 57 struct in6_addr *daddr;
58 int iif = 0; 58 int oif = 0;
59 struct flowi6 fl6; 59 struct flowi6 fl6;
60 int err; 60 int err;
61 struct dst_entry *dst; 61 struct dst_entry *dst;
@@ -78,25 +78,30 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
78 if (u->sin6_family != AF_INET6) { 78 if (u->sin6_family != AF_INET6) {
79 return -EAFNOSUPPORT; 79 return -EAFNOSUPPORT;
80 } 80 }
81 if (sk->sk_bound_dev_if &&
82 sk->sk_bound_dev_if != u->sin6_scope_id) {
83 return -EINVAL;
84 }
85 daddr = &(u->sin6_addr); 81 daddr = &(u->sin6_addr);
86 iif = u->sin6_scope_id; 82 if (__ipv6_addr_needs_scope_id(ipv6_addr_type(daddr)))
83 oif = u->sin6_scope_id;
87 } else { 84 } else {
88 if (sk->sk_state != TCP_ESTABLISHED) 85 if (sk->sk_state != TCP_ESTABLISHED)
89 return -EDESTADDRREQ; 86 return -EDESTADDRREQ;
90 daddr = &sk->sk_v6_daddr; 87 daddr = &sk->sk_v6_daddr;
91 } 88 }
92 89
93 if (!iif) 90 if (!oif)
94 iif = sk->sk_bound_dev_if; 91 oif = sk->sk_bound_dev_if;
92
93 if (!oif)
94 oif = np->sticky_pktinfo.ipi6_ifindex;
95
96 if (!oif && ipv6_addr_is_multicast(daddr))
97 oif = np->mcast_oif;
98 else if (!oif)
99 oif = np->ucast_oif;
95 100
96 addr_type = ipv6_addr_type(daddr); 101 addr_type = ipv6_addr_type(daddr);
97 if (__ipv6_addr_needs_scope_id(addr_type) && !iif) 102 if ((__ipv6_addr_needs_scope_id(addr_type) && !oif) ||
98 return -EINVAL; 103 (addr_type & IPV6_ADDR_MAPPED) ||
99 if (addr_type & IPV6_ADDR_MAPPED) 104 (oif && sk->sk_bound_dev_if && oif != sk->sk_bound_dev_if))
100 return -EINVAL; 105 return -EINVAL;
101 106
102 /* TODO: use ip6_datagram_send_ctl to get options from cmsg */ 107 /* TODO: use ip6_datagram_send_ctl to get options from cmsg */
@@ -106,16 +111,12 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
106 fl6.flowi6_proto = IPPROTO_ICMPV6; 111 fl6.flowi6_proto = IPPROTO_ICMPV6;
107 fl6.saddr = np->saddr; 112 fl6.saddr = np->saddr;
108 fl6.daddr = *daddr; 113 fl6.daddr = *daddr;
114 fl6.flowi6_oif = oif;
109 fl6.flowi6_mark = sk->sk_mark; 115 fl6.flowi6_mark = sk->sk_mark;
110 fl6.fl6_icmp_type = user_icmph.icmp6_type; 116 fl6.fl6_icmp_type = user_icmph.icmp6_type;
111 fl6.fl6_icmp_code = user_icmph.icmp6_code; 117 fl6.fl6_icmp_code = user_icmph.icmp6_code;
112 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 118 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
113 119
114 if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
115 fl6.flowi6_oif = np->mcast_oif;
116 else if (!fl6.flowi6_oif)
117 fl6.flowi6_oif = np->ucast_oif;
118
119 ipc6.tclass = np->tclass; 120 ipc6.tclass = np->tclass;
120 fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel); 121 fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
121 122
diff --git a/net/irda/iriap.c b/net/irda/iriap.c
index 4a7ae32afa09..1138eaf5c682 100644
--- a/net/irda/iriap.c
+++ b/net/irda/iriap.c
@@ -185,8 +185,12 @@ struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
185 185
186 self->magic = IAS_MAGIC; 186 self->magic = IAS_MAGIC;
187 self->mode = mode; 187 self->mode = mode;
188 if (mode == IAS_CLIENT) 188 if (mode == IAS_CLIENT) {
189 iriap_register_lsap(self, slsap_sel, mode); 189 if (iriap_register_lsap(self, slsap_sel, mode)) {
190 kfree(self);
191 return NULL;
192 }
193 }
190 194
191 self->confirm = callback; 195 self->confirm = callback;
192 self->priv = priv; 196 self->priv = priv;
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 47e99ab8d97a..543b1d4fc33d 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -869,7 +869,7 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
869 869
870 /* free all potentially still buffered bcast frames */ 870 /* free all potentially still buffered bcast frames */
871 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf); 871 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
872 skb_queue_purge(&sdata->u.ap.ps.bc_buf); 872 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
873 873
874 mutex_lock(&local->mtx); 874 mutex_lock(&local->mtx);
875 ieee80211_vif_copy_chanctx_to_vlans(sdata, true); 875 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 184473c257eb..ba5fc1f01e53 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -1094,7 +1094,7 @@ static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
1094 1094
1095 trace_drv_get_expected_throughput(sta); 1095 trace_drv_get_expected_throughput(sta);
1096 if (local->ops->get_expected_throughput) 1096 if (local->ops->get_expected_throughput)
1097 ret = local->ops->get_expected_throughput(sta); 1097 ret = local->ops->get_expected_throughput(&local->hw, sta);
1098 trace_drv_return_u32(local, ret); 1098 trace_drv_return_u32(local, ret);
1099 1099
1100 return ret; 1100 return ret;
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index c66411df9863..42120d965263 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -881,20 +881,22 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
881 881
882 netif_carrier_off(sdata->dev); 882 netif_carrier_off(sdata->dev);
883 883
884 /* flush STAs and mpaths on this iface */
885 sta_info_flush(sdata);
886 mesh_path_flush_by_iface(sdata);
887
884 /* stop the beacon */ 888 /* stop the beacon */
885 ifmsh->mesh_id_len = 0; 889 ifmsh->mesh_id_len = 0;
886 sdata->vif.bss_conf.enable_beacon = false; 890 sdata->vif.bss_conf.enable_beacon = false;
887 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); 891 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
888 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); 892 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
893
894 /* remove beacon */
889 bcn = rcu_dereference_protected(ifmsh->beacon, 895 bcn = rcu_dereference_protected(ifmsh->beacon,
890 lockdep_is_held(&sdata->wdev.mtx)); 896 lockdep_is_held(&sdata->wdev.mtx));
891 RCU_INIT_POINTER(ifmsh->beacon, NULL); 897 RCU_INIT_POINTER(ifmsh->beacon, NULL);
892 kfree_rcu(bcn, rcu_head); 898 kfree_rcu(bcn, rcu_head);
893 899
894 /* flush STAs and mpaths on this iface */
895 sta_info_flush(sdata);
896 mesh_path_flush_by_iface(sdata);
897
898 /* free all potentially still buffered group-addressed frames */ 900 /* free all potentially still buffered group-addressed frames */
899 local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf); 901 local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf);
900 skb_queue_purge(&ifmsh->ps.bc_buf); 902 skb_queue_purge(&ifmsh->ps.bc_buf);
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 2e8a9024625a..9dce3b157908 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1268,7 +1268,7 @@ static void sta_ps_start(struct sta_info *sta)
1268 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) { 1268 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1269 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]); 1269 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
1270 1270
1271 if (!txqi->tin.backlog_packets) 1271 if (txqi->tin.backlog_packets)
1272 set_bit(tid, &sta->txq_buffered_tids); 1272 set_bit(tid, &sta->txq_buffered_tids);
1273 else 1273 else
1274 clear_bit(tid, &sta->txq_buffered_tids); 1274 clear_bit(tid, &sta->txq_buffered_tids);
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index c6d5c724e032..a2a68269675d 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -771,6 +771,13 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
771 clear_sta_flag(sta, WLAN_STA_SP); 771 clear_sta_flag(sta, WLAN_STA_SP);
772 772
773 acked = !!(info->flags & IEEE80211_TX_STAT_ACK); 773 acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
774
775 /* mesh Peer Service Period support */
776 if (ieee80211_vif_is_mesh(&sta->sdata->vif) &&
777 ieee80211_is_data_qos(fc))
778 ieee80211_mpsp_trigger_process(
779 ieee80211_get_qos_ctl(hdr), sta, true, acked);
780
774 if (!acked && test_sta_flag(sta, WLAN_STA_PS_STA)) { 781 if (!acked && test_sta_flag(sta, WLAN_STA_PS_STA)) {
775 /* 782 /*
776 * The STA is in power save mode, so assume 783 * The STA is in power save mode, so assume
@@ -781,13 +788,6 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
781 return; 788 return;
782 } 789 }
783 790
784 /* mesh Peer Service Period support */
785 if (ieee80211_vif_is_mesh(&sta->sdata->vif) &&
786 ieee80211_is_data_qos(fc))
787 ieee80211_mpsp_trigger_process(
788 ieee80211_get_qos_ctl(hdr),
789 sta, true, acked);
790
791 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) && 791 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
792 (ieee80211_is_data(hdr->frame_control)) && 792 (ieee80211_is_data(hdr->frame_control)) &&
793 (rates_idx != -1)) 793 (rates_idx != -1))
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 91461c415525..502396694f47 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -368,7 +368,7 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
368 skb = skb_dequeue(&ps->bc_buf); 368 skb = skb_dequeue(&ps->bc_buf);
369 if (skb) { 369 if (skb) {
370 purged++; 370 purged++;
371 dev_kfree_skb(skb); 371 ieee80211_free_txskb(&local->hw, skb);
372 } 372 }
373 total += skb_queue_len(&ps->bc_buf); 373 total += skb_queue_len(&ps->bc_buf);
374 } 374 }
@@ -451,7 +451,7 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
451 if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) { 451 if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) {
452 ps_dbg(tx->sdata, 452 ps_dbg(tx->sdata,
453 "BC TX buffer full - dropping the oldest frame\n"); 453 "BC TX buffer full - dropping the oldest frame\n");
454 dev_kfree_skb(skb_dequeue(&ps->bc_buf)); 454 ieee80211_free_txskb(&tx->local->hw, skb_dequeue(&ps->bc_buf));
455 } else 455 } else
456 tx->local->total_ps_buffered++; 456 tx->local->total_ps_buffered++;
457 457
@@ -4275,7 +4275,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
4275 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev); 4275 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
4276 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb)) 4276 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
4277 break; 4277 break;
4278 dev_kfree_skb_any(skb); 4278 ieee80211_free_txskb(hw, skb);
4279 } 4279 }
4280 4280
4281 info = IEEE80211_SKB_CB(skb); 4281 info = IEEE80211_SKB_CB(skb);
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 9e3693128313..f8dbacf66795 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -574,7 +574,7 @@ static int exp_seq_show(struct seq_file *s, void *v)
574 helper = rcu_dereference(nfct_help(expect->master)->helper); 574 helper = rcu_dereference(nfct_help(expect->master)->helper);
575 if (helper) { 575 if (helper) {
576 seq_printf(s, "%s%s", expect->flags ? " " : "", helper->name); 576 seq_printf(s, "%s%s", expect->flags ? " " : "", helper->name);
577 if (helper->expect_policy[expect->class].name) 577 if (helper->expect_policy[expect->class].name[0])
578 seq_printf(s, "/%s", 578 seq_printf(s, "/%s",
579 helper->expect_policy[expect->class].name); 579 helper->expect_policy[expect->class].name);
580 } 580 }
diff --git a/net/netfilter/nf_conntrack_h323_main.c b/net/netfilter/nf_conntrack_h323_main.c
index bb77a97961bf..5c0db5c64734 100644
--- a/net/netfilter/nf_conntrack_h323_main.c
+++ b/net/netfilter/nf_conntrack_h323_main.c
@@ -1473,7 +1473,8 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,
1473 "timeout to %u seconds for", 1473 "timeout to %u seconds for",
1474 info->timeout); 1474 info->timeout);
1475 nf_ct_dump_tuple(&exp->tuple); 1475 nf_ct_dump_tuple(&exp->tuple);
1476 mod_timer(&exp->timeout, jiffies + info->timeout * HZ); 1476 mod_timer_pending(&exp->timeout,
1477 jiffies + info->timeout * HZ);
1477 } 1478 }
1478 spin_unlock_bh(&nf_conntrack_expect_lock); 1479 spin_unlock_bh(&nf_conntrack_expect_lock);
1479 } 1480 }
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 050bb3420a6b..fdfc71f416b7 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1894,6 +1894,8 @@ static int ctnetlink_new_conntrack(struct net *net, struct sock *ctnl,
1894 1894
1895 if (!cda[CTA_TUPLE_ORIG] || !cda[CTA_TUPLE_REPLY]) 1895 if (!cda[CTA_TUPLE_ORIG] || !cda[CTA_TUPLE_REPLY])
1896 return -EINVAL; 1896 return -EINVAL;
1897 if (otuple.dst.protonum != rtuple.dst.protonum)
1898 return -EINVAL;
1897 1899
1898 ct = ctnetlink_create_conntrack(net, &zone, cda, &otuple, 1900 ct = ctnetlink_create_conntrack(net, &zone, cda, &otuple,
1899 &rtuple, u3); 1901 &rtuple, u3);
@@ -2362,12 +2364,8 @@ ctnetlink_glue_attach_expect(const struct nlattr *attr, struct nf_conn *ct,
2362 return PTR_ERR(exp); 2364 return PTR_ERR(exp);
2363 2365
2364 err = nf_ct_expect_related_report(exp, portid, report); 2366 err = nf_ct_expect_related_report(exp, portid, report);
2365 if (err < 0) { 2367 nf_ct_expect_put(exp);
2366 nf_ct_expect_put(exp); 2368 return err;
2367 return err;
2368 }
2369
2370 return 0;
2371} 2369}
2372 2370
2373static void ctnetlink_glue_seqadj(struct sk_buff *skb, struct nf_conn *ct, 2371static void ctnetlink_glue_seqadj(struct sk_buff *skb, struct nf_conn *ct,
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
index 8d9db9d4702b..7d77217de6a3 100644
--- a/net/netfilter/nf_conntrack_sip.c
+++ b/net/netfilter/nf_conntrack_sip.c
@@ -1383,7 +1383,7 @@ static int process_sip_response(struct sk_buff *skb, unsigned int protoff,
1383 return NF_DROP; 1383 return NF_DROP;
1384 } 1384 }
1385 cseq = simple_strtoul(*dptr + matchoff, NULL, 10); 1385 cseq = simple_strtoul(*dptr + matchoff, NULL, 10);
1386 if (!cseq) { 1386 if (!cseq && *(*dptr + matchoff) != '0') {
1387 nf_ct_helper_log(skb, ct, "cannot get cseq"); 1387 nf_ct_helper_log(skb, ct, "cannot get cseq");
1388 return NF_DROP; 1388 return NF_DROP;
1389 } 1389 }
@@ -1446,7 +1446,7 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff,
1446 return NF_DROP; 1446 return NF_DROP;
1447 } 1447 }
1448 cseq = simple_strtoul(*dptr + matchoff, NULL, 10); 1448 cseq = simple_strtoul(*dptr + matchoff, NULL, 10);
1449 if (!cseq) { 1449 if (!cseq && *(*dptr + matchoff) != '0') {
1450 nf_ct_helper_log(skb, ct, "cannot get cseq"); 1450 nf_ct_helper_log(skb, ct, "cannot get cseq");
1451 return NF_DROP; 1451 return NF_DROP;
1452 } 1452 }
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 5d36a0926b4a..f49f45081acb 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -1145,10 +1145,8 @@ static int nfqnl_recv_verdict(struct net *net, struct sock *ctnl,
1145 struct nfnl_queue_net *q = nfnl_queue_pernet(net); 1145 struct nfnl_queue_net *q = nfnl_queue_pernet(net);
1146 int err; 1146 int err;
1147 1147
1148 queue = instance_lookup(q, queue_num); 1148 queue = verdict_instance_lookup(q, queue_num,
1149 if (!queue) 1149 NETLINK_CB(skb).portid);
1150 queue = verdict_instance_lookup(q, queue_num,
1151 NETLINK_CB(skb).portid);
1152 if (IS_ERR(queue)) 1150 if (IS_ERR(queue))
1153 return PTR_ERR(queue); 1151 return PTR_ERR(queue);
1154 1152
diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
index ba7aed13e174..82c264e40278 100644
--- a/net/netfilter/nft_exthdr.c
+++ b/net/netfilter/nft_exthdr.c
@@ -59,6 +59,7 @@ static int nft_exthdr_init(const struct nft_ctx *ctx,
59 const struct nlattr * const tb[]) 59 const struct nlattr * const tb[])
60{ 60{
61 struct nft_exthdr *priv = nft_expr_priv(expr); 61 struct nft_exthdr *priv = nft_expr_priv(expr);
62 u32 offset, len;
62 63
63 if (tb[NFTA_EXTHDR_DREG] == NULL || 64 if (tb[NFTA_EXTHDR_DREG] == NULL ||
64 tb[NFTA_EXTHDR_TYPE] == NULL || 65 tb[NFTA_EXTHDR_TYPE] == NULL ||
@@ -66,9 +67,15 @@ static int nft_exthdr_init(const struct nft_ctx *ctx,
66 tb[NFTA_EXTHDR_LEN] == NULL) 67 tb[NFTA_EXTHDR_LEN] == NULL)
67 return -EINVAL; 68 return -EINVAL;
68 69
70 offset = ntohl(nla_get_be32(tb[NFTA_EXTHDR_OFFSET]));
71 len = ntohl(nla_get_be32(tb[NFTA_EXTHDR_LEN]));
72
73 if (offset > U8_MAX || len > U8_MAX)
74 return -ERANGE;
75
69 priv->type = nla_get_u8(tb[NFTA_EXTHDR_TYPE]); 76 priv->type = nla_get_u8(tb[NFTA_EXTHDR_TYPE]);
70 priv->offset = ntohl(nla_get_be32(tb[NFTA_EXTHDR_OFFSET])); 77 priv->offset = offset;
71 priv->len = ntohl(nla_get_be32(tb[NFTA_EXTHDR_LEN])); 78 priv->len = len;
72 priv->dreg = nft_parse_register(tb[NFTA_EXTHDR_DREG]); 79 priv->dreg = nft_parse_register(tb[NFTA_EXTHDR_DREG]);
73 80
74 return nft_validate_register_store(ctx, priv->dreg, NULL, 81 return nft_validate_register_store(ctx, priv->dreg, NULL,
diff --git a/net/netfilter/nft_rbtree.c b/net/netfilter/nft_rbtree.c
index 6473936d05c6..ffe9ae062d23 100644
--- a/net/netfilter/nft_rbtree.c
+++ b/net/netfilter/nft_rbtree.c
@@ -70,7 +70,6 @@ static bool nft_rbtree_lookup(const struct net *net, const struct nft_set *set,
70 } else if (d > 0) 70 } else if (d > 0)
71 parent = parent->rb_right; 71 parent = parent->rb_right;
72 else { 72 else {
73found:
74 if (!nft_set_elem_active(&rbe->ext, genmask)) { 73 if (!nft_set_elem_active(&rbe->ext, genmask)) {
75 parent = parent->rb_left; 74 parent = parent->rb_left;
76 continue; 75 continue;
@@ -84,9 +83,12 @@ found:
84 } 83 }
85 } 84 }
86 85
87 if (set->flags & NFT_SET_INTERVAL && interval != NULL) { 86 if (set->flags & NFT_SET_INTERVAL && interval != NULL &&
88 rbe = interval; 87 nft_set_elem_active(&interval->ext, genmask) &&
89 goto found; 88 !nft_rbtree_interval_end(interval)) {
89 spin_unlock_bh(&nft_rbtree_lock);
90 *ext = &interval->ext;
91 return true;
90 } 92 }
91out: 93out:
92 spin_unlock_bh(&nft_rbtree_lock); 94 spin_unlock_bh(&nft_rbtree_lock);
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index c644c78ed485..e054a748ff25 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -433,7 +433,6 @@ ovs_ct_find_existing(struct net *net, const struct nf_conntrack_zone *zone,
433 struct nf_conntrack_l4proto *l4proto; 433 struct nf_conntrack_l4proto *l4proto;
434 struct nf_conntrack_tuple tuple; 434 struct nf_conntrack_tuple tuple;
435 struct nf_conntrack_tuple_hash *h; 435 struct nf_conntrack_tuple_hash *h;
436 enum ip_conntrack_info ctinfo;
437 struct nf_conn *ct; 436 struct nf_conn *ct;
438 unsigned int dataoff; 437 unsigned int dataoff;
439 u8 protonum; 438 u8 protonum;
@@ -458,13 +457,8 @@ ovs_ct_find_existing(struct net *net, const struct nf_conntrack_zone *zone,
458 457
459 ct = nf_ct_tuplehash_to_ctrack(h); 458 ct = nf_ct_tuplehash_to_ctrack(h);
460 459
461 ctinfo = ovs_ct_get_info(h);
462 if (ctinfo == IP_CT_NEW) {
463 /* This should not happen. */
464 WARN_ONCE(1, "ovs_ct_find_existing: new packet for %p\n", ct);
465 }
466 skb->nfct = &ct->ct_general; 460 skb->nfct = &ct->ct_general;
467 skb->nfctinfo = ctinfo; 461 skb->nfctinfo = ovs_ct_get_info(h);
468 return ct; 462 return ct;
469} 463}
470 464
diff --git a/net/openvswitch/vport-geneve.c b/net/openvswitch/vport-geneve.c
index 1a1fcec88695..5aaf3babfc3f 100644
--- a/net/openvswitch/vport-geneve.c
+++ b/net/openvswitch/vport-geneve.c
@@ -93,7 +93,14 @@ static struct vport *geneve_tnl_create(const struct vport_parms *parms)
93 return ERR_CAST(dev); 93 return ERR_CAST(dev);
94 } 94 }
95 95
96 dev_change_flags(dev, dev->flags | IFF_UP); 96 err = dev_change_flags(dev, dev->flags | IFF_UP);
97 if (err < 0) {
98 rtnl_delete_link(dev);
99 rtnl_unlock();
100 ovs_vport_free(vport);
101 goto error;
102 }
103
97 rtnl_unlock(); 104 rtnl_unlock();
98 return vport; 105 return vport;
99error: 106error:
diff --git a/net/openvswitch/vport-gre.c b/net/openvswitch/vport-gre.c
index 7f8897f33a67..0e72d95b0e8f 100644
--- a/net/openvswitch/vport-gre.c
+++ b/net/openvswitch/vport-gre.c
@@ -54,6 +54,7 @@ static struct vport *gre_tnl_create(const struct vport_parms *parms)
54 struct net *net = ovs_dp_get_net(parms->dp); 54 struct net *net = ovs_dp_get_net(parms->dp);
55 struct net_device *dev; 55 struct net_device *dev;
56 struct vport *vport; 56 struct vport *vport;
57 int err;
57 58
58 vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms); 59 vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms);
59 if (IS_ERR(vport)) 60 if (IS_ERR(vport))
@@ -67,9 +68,15 @@ static struct vport *gre_tnl_create(const struct vport_parms *parms)
67 return ERR_CAST(dev); 68 return ERR_CAST(dev);
68 } 69 }
69 70
70 dev_change_flags(dev, dev->flags | IFF_UP); 71 err = dev_change_flags(dev, dev->flags | IFF_UP);
71 rtnl_unlock(); 72 if (err < 0) {
73 rtnl_delete_link(dev);
74 rtnl_unlock();
75 ovs_vport_free(vport);
76 return ERR_PTR(err);
77 }
72 78
79 rtnl_unlock();
73 return vport; 80 return vport;
74} 81}
75 82
diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
index 434e04c3a189..95c36147a6e1 100644
--- a/net/openvswitch/vport-internal_dev.c
+++ b/net/openvswitch/vport-internal_dev.c
@@ -140,7 +140,7 @@ internal_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
140 140
141static void internal_set_rx_headroom(struct net_device *dev, int new_hr) 141static void internal_set_rx_headroom(struct net_device *dev, int new_hr)
142{ 142{
143 dev->needed_headroom = new_hr; 143 dev->needed_headroom = new_hr < 0 ? 0 : new_hr;
144} 144}
145 145
146static const struct net_device_ops internal_dev_netdev_ops = { 146static const struct net_device_ops internal_dev_netdev_ops = {
diff --git a/net/openvswitch/vport-vxlan.c b/net/openvswitch/vport-vxlan.c
index 5eb7694348b5..7eb955e453e6 100644
--- a/net/openvswitch/vport-vxlan.c
+++ b/net/openvswitch/vport-vxlan.c
@@ -130,7 +130,14 @@ static struct vport *vxlan_tnl_create(const struct vport_parms *parms)
130 return ERR_CAST(dev); 130 return ERR_CAST(dev);
131 } 131 }
132 132
133 dev_change_flags(dev, dev->flags | IFF_UP); 133 err = dev_change_flags(dev, dev->flags | IFF_UP);
134 if (err < 0) {
135 rtnl_delete_link(dev);
136 rtnl_unlock();
137 ovs_vport_free(vport);
138 goto error;
139 }
140
134 rtnl_unlock(); 141 rtnl_unlock();
135 return vport; 142 return vport;
136error: 143error:
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 1bb9e7ac9e14..ff83fb1ddd47 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -425,6 +425,7 @@ struct rxrpc_call {
425 spinlock_t lock; 425 spinlock_t lock;
426 rwlock_t state_lock; /* lock for state transition */ 426 rwlock_t state_lock; /* lock for state transition */
427 atomic_t usage; 427 atomic_t usage;
428 atomic_t skb_count; /* Outstanding packets on this call */
428 atomic_t sequence; /* Tx data packet sequence counter */ 429 atomic_t sequence; /* Tx data packet sequence counter */
429 u32 local_abort; /* local abort code */ 430 u32 local_abort; /* local abort code */
430 u32 remote_abort; /* remote abort code */ 431 u32 remote_abort; /* remote abort code */
diff --git a/net/rxrpc/call_accept.c b/net/rxrpc/call_accept.c
index 0b2832141bd0..9bae21e66d65 100644
--- a/net/rxrpc/call_accept.c
+++ b/net/rxrpc/call_accept.c
@@ -130,6 +130,7 @@ static int rxrpc_accept_incoming_call(struct rxrpc_local *local,
130 call->state = RXRPC_CALL_SERVER_ACCEPTING; 130 call->state = RXRPC_CALL_SERVER_ACCEPTING;
131 list_add_tail(&call->accept_link, &rx->acceptq); 131 list_add_tail(&call->accept_link, &rx->acceptq);
132 rxrpc_get_call(call); 132 rxrpc_get_call(call);
133 atomic_inc(&call->skb_count);
133 nsp = rxrpc_skb(notification); 134 nsp = rxrpc_skb(notification);
134 nsp->call = call; 135 nsp->call = call;
135 136
diff --git a/net/rxrpc/call_event.c b/net/rxrpc/call_event.c
index fc32aa5764a2..e60cf65c2232 100644
--- a/net/rxrpc/call_event.c
+++ b/net/rxrpc/call_event.c
@@ -460,6 +460,7 @@ static void rxrpc_insert_oos_packet(struct rxrpc_call *call,
460 ASSERTCMP(sp->call, ==, NULL); 460 ASSERTCMP(sp->call, ==, NULL);
461 sp->call = call; 461 sp->call = call;
462 rxrpc_get_call(call); 462 rxrpc_get_call(call);
463 atomic_inc(&call->skb_count);
463 464
464 /* insert into the buffer in sequence order */ 465 /* insert into the buffer in sequence order */
465 spin_lock_bh(&call->lock); 466 spin_lock_bh(&call->lock);
@@ -734,6 +735,7 @@ all_acked:
734 skb->mark = RXRPC_SKB_MARK_FINAL_ACK; 735 skb->mark = RXRPC_SKB_MARK_FINAL_ACK;
735 sp->call = call; 736 sp->call = call;
736 rxrpc_get_call(call); 737 rxrpc_get_call(call);
738 atomic_inc(&call->skb_count);
737 spin_lock_bh(&call->lock); 739 spin_lock_bh(&call->lock);
738 if (rxrpc_queue_rcv_skb(call, skb, true, true) < 0) 740 if (rxrpc_queue_rcv_skb(call, skb, true, true) < 0)
739 BUG(); 741 BUG();
@@ -793,6 +795,7 @@ static int rxrpc_post_message(struct rxrpc_call *call, u32 mark, u32 error,
793 sp->error = error; 795 sp->error = error;
794 sp->call = call; 796 sp->call = call;
795 rxrpc_get_call(call); 797 rxrpc_get_call(call);
798 atomic_inc(&call->skb_count);
796 799
797 spin_lock_bh(&call->lock); 800 spin_lock_bh(&call->lock);
798 ret = rxrpc_queue_rcv_skb(call, skb, true, fatal); 801 ret = rxrpc_queue_rcv_skb(call, skb, true, fatal);
@@ -834,6 +837,9 @@ void rxrpc_process_call(struct work_struct *work)
834 return; 837 return;
835 } 838 }
836 839
840 if (!call->conn)
841 goto skip_msg_init;
842
837 /* there's a good chance we're going to have to send a message, so set 843 /* there's a good chance we're going to have to send a message, so set
838 * one up in advance */ 844 * one up in advance */
839 msg.msg_name = &call->conn->params.peer->srx.transport; 845 msg.msg_name = &call->conn->params.peer->srx.transport;
@@ -856,6 +862,7 @@ void rxrpc_process_call(struct work_struct *work)
856 memset(iov, 0, sizeof(iov)); 862 memset(iov, 0, sizeof(iov));
857 iov[0].iov_base = &whdr; 863 iov[0].iov_base = &whdr;
858 iov[0].iov_len = sizeof(whdr); 864 iov[0].iov_len = sizeof(whdr);
865skip_msg_init:
859 866
860 /* deal with events of a final nature */ 867 /* deal with events of a final nature */
861 if (test_bit(RXRPC_CALL_EV_RCVD_ERROR, &call->events)) { 868 if (test_bit(RXRPC_CALL_EV_RCVD_ERROR, &call->events)) {
diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c
index 91287c9d01bb..ae057e0740f3 100644
--- a/net/rxrpc/call_object.c
+++ b/net/rxrpc/call_object.c
@@ -275,6 +275,7 @@ error:
275 list_del_init(&call->link); 275 list_del_init(&call->link);
276 write_unlock_bh(&rxrpc_call_lock); 276 write_unlock_bh(&rxrpc_call_lock);
277 277
278 set_bit(RXRPC_CALL_RELEASED, &call->flags);
278 call->state = RXRPC_CALL_DEAD; 279 call->state = RXRPC_CALL_DEAD;
279 rxrpc_put_call(call); 280 rxrpc_put_call(call);
280 _leave(" = %d", ret); 281 _leave(" = %d", ret);
@@ -287,6 +288,7 @@ error:
287 */ 288 */
288found_user_ID_now_present: 289found_user_ID_now_present:
289 write_unlock(&rx->call_lock); 290 write_unlock(&rx->call_lock);
291 set_bit(RXRPC_CALL_RELEASED, &call->flags);
290 call->state = RXRPC_CALL_DEAD; 292 call->state = RXRPC_CALL_DEAD;
291 rxrpc_put_call(call); 293 rxrpc_put_call(call);
292 _leave(" = -EEXIST [%p]", call); 294 _leave(" = -EEXIST [%p]", call);
@@ -491,15 +493,9 @@ void rxrpc_release_call(struct rxrpc_call *call)
491 spin_lock_bh(&call->lock); 493 spin_lock_bh(&call->lock);
492 while ((skb = skb_dequeue(&call->rx_queue)) || 494 while ((skb = skb_dequeue(&call->rx_queue)) ||
493 (skb = skb_dequeue(&call->rx_oos_queue))) { 495 (skb = skb_dequeue(&call->rx_oos_queue))) {
494 sp = rxrpc_skb(skb);
495 if (sp->call) {
496 ASSERTCMP(sp->call, ==, call);
497 rxrpc_put_call(call);
498 sp->call = NULL;
499 }
500 skb->destructor = NULL;
501 spin_unlock_bh(&call->lock); 496 spin_unlock_bh(&call->lock);
502 497
498 sp = rxrpc_skb(skb);
503 _debug("- zap %s %%%u #%u", 499 _debug("- zap %s %%%u #%u",
504 rxrpc_pkts[sp->hdr.type], 500 rxrpc_pkts[sp->hdr.type],
505 sp->hdr.serial, sp->hdr.seq); 501 sp->hdr.serial, sp->hdr.seq);
@@ -605,6 +601,7 @@ void __rxrpc_put_call(struct rxrpc_call *call)
605 601
606 if (atomic_dec_and_test(&call->usage)) { 602 if (atomic_dec_and_test(&call->usage)) {
607 _debug("call %d dead", call->debug_id); 603 _debug("call %d dead", call->debug_id);
604 WARN_ON(atomic_read(&call->skb_count) != 0);
608 ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD); 605 ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD);
609 rxrpc_queue_work(&call->destroyer); 606 rxrpc_queue_work(&call->destroyer);
610 } 607 }
diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c
index 991a20d25093..70bb77818dea 100644
--- a/net/rxrpc/input.c
+++ b/net/rxrpc/input.c
@@ -55,9 +55,6 @@ int rxrpc_queue_rcv_skb(struct rxrpc_call *call, struct sk_buff *skb,
55 if (test_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags)) { 55 if (test_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags)) {
56 _debug("already terminated"); 56 _debug("already terminated");
57 ASSERTCMP(call->state, >=, RXRPC_CALL_COMPLETE); 57 ASSERTCMP(call->state, >=, RXRPC_CALL_COMPLETE);
58 skb->destructor = NULL;
59 sp->call = NULL;
60 rxrpc_put_call(call);
61 rxrpc_free_skb(skb); 58 rxrpc_free_skb(skb);
62 return 0; 59 return 0;
63 } 60 }
@@ -111,13 +108,7 @@ int rxrpc_queue_rcv_skb(struct rxrpc_call *call, struct sk_buff *skb,
111 ret = 0; 108 ret = 0;
112 109
113out: 110out:
114 /* release the socket buffer */ 111 rxrpc_free_skb(skb);
115 if (skb) {
116 skb->destructor = NULL;
117 sp->call = NULL;
118 rxrpc_put_call(call);
119 rxrpc_free_skb(skb);
120 }
121 112
122 _leave(" = %d", ret); 113 _leave(" = %d", ret);
123 return ret; 114 return ret;
@@ -133,11 +124,15 @@ static int rxrpc_fast_process_data(struct rxrpc_call *call,
133 struct rxrpc_skb_priv *sp; 124 struct rxrpc_skb_priv *sp;
134 bool terminal; 125 bool terminal;
135 int ret, ackbit, ack; 126 int ret, ackbit, ack;
127 u32 serial;
128 u8 flags;
136 129
137 _enter("{%u,%u},,{%u}", call->rx_data_post, call->rx_first_oos, seq); 130 _enter("{%u,%u},,{%u}", call->rx_data_post, call->rx_first_oos, seq);
138 131
139 sp = rxrpc_skb(skb); 132 sp = rxrpc_skb(skb);
140 ASSERTCMP(sp->call, ==, NULL); 133 ASSERTCMP(sp->call, ==, NULL);
134 flags = sp->hdr.flags;
135 serial = sp->hdr.serial;
141 136
142 spin_lock(&call->lock); 137 spin_lock(&call->lock);
143 138
@@ -200,8 +195,9 @@ static int rxrpc_fast_process_data(struct rxrpc_call *call,
200 195
201 sp->call = call; 196 sp->call = call;
202 rxrpc_get_call(call); 197 rxrpc_get_call(call);
203 terminal = ((sp->hdr.flags & RXRPC_LAST_PACKET) && 198 atomic_inc(&call->skb_count);
204 !(sp->hdr.flags & RXRPC_CLIENT_INITIATED)); 199 terminal = ((flags & RXRPC_LAST_PACKET) &&
200 !(flags & RXRPC_CLIENT_INITIATED));
205 ret = rxrpc_queue_rcv_skb(call, skb, false, terminal); 201 ret = rxrpc_queue_rcv_skb(call, skb, false, terminal);
206 if (ret < 0) { 202 if (ret < 0) {
207 if (ret == -ENOMEM || ret == -ENOBUFS) { 203 if (ret == -ENOMEM || ret == -ENOBUFS) {
@@ -213,12 +209,13 @@ static int rxrpc_fast_process_data(struct rxrpc_call *call,
213 } 209 }
214 210
215 skb = NULL; 211 skb = NULL;
212 sp = NULL;
216 213
217 _debug("post #%u", seq); 214 _debug("post #%u", seq);
218 ASSERTCMP(call->rx_data_post, ==, seq); 215 ASSERTCMP(call->rx_data_post, ==, seq);
219 call->rx_data_post++; 216 call->rx_data_post++;
220 217
221 if (sp->hdr.flags & RXRPC_LAST_PACKET) 218 if (flags & RXRPC_LAST_PACKET)
222 set_bit(RXRPC_CALL_RCVD_LAST, &call->flags); 219 set_bit(RXRPC_CALL_RCVD_LAST, &call->flags);
223 220
224 /* if we've reached an out of sequence packet then we need to drain 221 /* if we've reached an out of sequence packet then we need to drain
@@ -234,7 +231,7 @@ static int rxrpc_fast_process_data(struct rxrpc_call *call,
234 231
235 spin_unlock(&call->lock); 232 spin_unlock(&call->lock);
236 atomic_inc(&call->ackr_not_idle); 233 atomic_inc(&call->ackr_not_idle);
237 rxrpc_propose_ACK(call, RXRPC_ACK_DELAY, sp->hdr.serial, false); 234 rxrpc_propose_ACK(call, RXRPC_ACK_DELAY, serial, false);
238 _leave(" = 0 [posted]"); 235 _leave(" = 0 [posted]");
239 return 0; 236 return 0;
240 237
@@ -247,7 +244,7 @@ out:
247 244
248discard_and_ack: 245discard_and_ack:
249 _debug("discard and ACK packet %p", skb); 246 _debug("discard and ACK packet %p", skb);
250 __rxrpc_propose_ACK(call, ack, sp->hdr.serial, true); 247 __rxrpc_propose_ACK(call, ack, serial, true);
251discard: 248discard:
252 spin_unlock(&call->lock); 249 spin_unlock(&call->lock);
253 rxrpc_free_skb(skb); 250 rxrpc_free_skb(skb);
@@ -255,7 +252,7 @@ discard:
255 return 0; 252 return 0;
256 253
257enqueue_and_ack: 254enqueue_and_ack:
258 __rxrpc_propose_ACK(call, ack, sp->hdr.serial, true); 255 __rxrpc_propose_ACK(call, ack, serial, true);
259enqueue_packet: 256enqueue_packet:
260 _net("defer skb %p", skb); 257 _net("defer skb %p", skb);
261 spin_unlock(&call->lock); 258 spin_unlock(&call->lock);
@@ -575,13 +572,13 @@ done:
575 * post connection-level events to the connection 572 * post connection-level events to the connection
576 * - this includes challenges, responses and some aborts 573 * - this includes challenges, responses and some aborts
577 */ 574 */
578static bool rxrpc_post_packet_to_conn(struct rxrpc_connection *conn, 575static void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn,
579 struct sk_buff *skb) 576 struct sk_buff *skb)
580{ 577{
581 _enter("%p,%p", conn, skb); 578 _enter("%p,%p", conn, skb);
582 579
583 skb_queue_tail(&conn->rx_queue, skb); 580 skb_queue_tail(&conn->rx_queue, skb);
584 return rxrpc_queue_conn(conn); 581 rxrpc_queue_conn(conn);
585} 582}
586 583
587/* 584/*
@@ -702,7 +699,6 @@ void rxrpc_data_ready(struct sock *sk)
702 699
703 rcu_read_lock(); 700 rcu_read_lock();
704 701
705retry_find_conn:
706 conn = rxrpc_find_connection_rcu(local, skb); 702 conn = rxrpc_find_connection_rcu(local, skb);
707 if (!conn) 703 if (!conn)
708 goto cant_route_call; 704 goto cant_route_call;
@@ -710,8 +706,7 @@ retry_find_conn:
710 if (sp->hdr.callNumber == 0) { 706 if (sp->hdr.callNumber == 0) {
711 /* Connection-level packet */ 707 /* Connection-level packet */
712 _debug("CONN %p {%d}", conn, conn->debug_id); 708 _debug("CONN %p {%d}", conn, conn->debug_id);
713 if (!rxrpc_post_packet_to_conn(conn, skb)) 709 rxrpc_post_packet_to_conn(conn, skb);
714 goto retry_find_conn;
715 } else { 710 } else {
716 /* Call-bound packets are routed by connection channel. */ 711 /* Call-bound packets are routed by connection channel. */
717 unsigned int channel = sp->hdr.cid & RXRPC_CHANNELMASK; 712 unsigned int channel = sp->hdr.cid & RXRPC_CHANNELMASK;
@@ -749,6 +744,8 @@ cant_route_call:
749 if (sp->hdr.type != RXRPC_PACKET_TYPE_ABORT) { 744 if (sp->hdr.type != RXRPC_PACKET_TYPE_ABORT) {
750 _debug("reject type %d",sp->hdr.type); 745 _debug("reject type %d",sp->hdr.type);
751 rxrpc_reject_packet(local, skb); 746 rxrpc_reject_packet(local, skb);
747 } else {
748 rxrpc_free_skb(skb);
752 } 749 }
753 _leave(" [no call]"); 750 _leave(" [no call]");
754 return; 751 return;
diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c
index a3fa2ed85d63..9ed66d533002 100644
--- a/net/rxrpc/recvmsg.c
+++ b/net/rxrpc/recvmsg.c
@@ -203,6 +203,9 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
203 } 203 }
204 204
205 /* we transferred the whole data packet */ 205 /* we transferred the whole data packet */
206 if (!(flags & MSG_PEEK))
207 rxrpc_kernel_data_consumed(call, skb);
208
206 if (sp->hdr.flags & RXRPC_LAST_PACKET) { 209 if (sp->hdr.flags & RXRPC_LAST_PACKET) {
207 _debug("last"); 210 _debug("last");
208 if (rxrpc_conn_is_client(call->conn)) { 211 if (rxrpc_conn_is_client(call->conn)) {
@@ -360,28 +363,6 @@ wait_error:
360} 363}
361 364
362/** 365/**
363 * rxrpc_kernel_data_delivered - Record delivery of data message
364 * @skb: Message holding data
365 *
366 * Record the delivery of a data message. This permits RxRPC to keep its
367 * tracking correct. The socket buffer will be deleted.
368 */
369void rxrpc_kernel_data_delivered(struct sk_buff *skb)
370{
371 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
372 struct rxrpc_call *call = sp->call;
373
374 ASSERTCMP(sp->hdr.seq, >=, call->rx_data_recv);
375 ASSERTCMP(sp->hdr.seq, <=, call->rx_data_recv + 1);
376 call->rx_data_recv = sp->hdr.seq;
377
378 ASSERTCMP(sp->hdr.seq, >, call->rx_data_eaten);
379 rxrpc_free_skb(skb);
380}
381
382EXPORT_SYMBOL(rxrpc_kernel_data_delivered);
383
384/**
385 * rxrpc_kernel_is_data_last - Determine if data message is last one 366 * rxrpc_kernel_is_data_last - Determine if data message is last one
386 * @skb: Message holding data 367 * @skb: Message holding data
387 * 368 *
diff --git a/net/rxrpc/skbuff.c b/net/rxrpc/skbuff.c
index eee0cfd9ac8c..06c51d4b622d 100644
--- a/net/rxrpc/skbuff.c
+++ b/net/rxrpc/skbuff.c
@@ -98,11 +98,39 @@ static void rxrpc_hard_ACK_data(struct rxrpc_call *call,
98 spin_unlock_bh(&call->lock); 98 spin_unlock_bh(&call->lock);
99} 99}
100 100
101/**
102 * rxrpc_kernel_data_consumed - Record consumption of data message
103 * @call: The call to which the message pertains.
104 * @skb: Message holding data
105 *
106 * Record the consumption of a data message and generate an ACK if appropriate.
107 * The call state is shifted if this was the final packet. The caller must be
108 * in process context with no spinlocks held.
109 *
110 * TODO: Actually generate the ACK here rather than punting this to the
111 * workqueue.
112 */
113void rxrpc_kernel_data_consumed(struct rxrpc_call *call, struct sk_buff *skb)
114{
115 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
116
117 _enter("%d,%p{%u}", call->debug_id, skb, sp->hdr.seq);
118
119 ASSERTCMP(sp->call, ==, call);
120 ASSERTCMP(sp->hdr.type, ==, RXRPC_PACKET_TYPE_DATA);
121
122 /* TODO: Fix the sequence number tracking */
123 ASSERTCMP(sp->hdr.seq, >=, call->rx_data_recv);
124 ASSERTCMP(sp->hdr.seq, <=, call->rx_data_recv + 1);
125 ASSERTCMP(sp->hdr.seq, >, call->rx_data_eaten);
126
127 call->rx_data_recv = sp->hdr.seq;
128 rxrpc_hard_ACK_data(call, sp);
129}
130EXPORT_SYMBOL(rxrpc_kernel_data_consumed);
131
101/* 132/*
102 * destroy a packet that has an RxRPC control buffer 133 * Destroy a packet that has an RxRPC control buffer
103 * - advance the hard-ACK state of the parent call (done here in case something
104 * in the kernel bypasses recvmsg() and steals the packet directly off of the
105 * socket receive queue)
106 */ 134 */
107void rxrpc_packet_destructor(struct sk_buff *skb) 135void rxrpc_packet_destructor(struct sk_buff *skb)
108{ 136{
@@ -112,9 +140,8 @@ void rxrpc_packet_destructor(struct sk_buff *skb)
112 _enter("%p{%p}", skb, call); 140 _enter("%p{%p}", skb, call);
113 141
114 if (call) { 142 if (call) {
115 /* send the final ACK on a client call */ 143 if (atomic_dec_return(&call->skb_count) < 0)
116 if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA) 144 BUG();
117 rxrpc_hard_ACK_data(call, sp);
118 rxrpc_put_call(call); 145 rxrpc_put_call(call);
119 sp->call = NULL; 146 sp->call = NULL;
120 } 147 }
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index e4a5f2607ffa..d09d0687594b 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -64,7 +64,6 @@ int __tcf_hash_release(struct tc_action *p, bool bind, bool strict)
64 if (p->tcfa_bindcnt <= 0 && p->tcfa_refcnt <= 0) { 64 if (p->tcfa_bindcnt <= 0 && p->tcfa_refcnt <= 0) {
65 if (p->ops->cleanup) 65 if (p->ops->cleanup)
66 p->ops->cleanup(p, bind); 66 p->ops->cleanup(p, bind);
67 list_del(&p->list);
68 tcf_hash_destroy(p->hinfo, p); 67 tcf_hash_destroy(p->hinfo, p);
69 ret = ACT_P_DELETED; 68 ret = ACT_P_DELETED;
70 } 69 }
@@ -421,18 +420,19 @@ static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
421 return res; 420 return res;
422} 421}
423 422
424int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions, 423int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
425 struct tcf_result *res) 424 int nr_actions, struct tcf_result *res)
426{ 425{
427 const struct tc_action *a; 426 int ret = -1, i;
428 int ret = -1;
429 427
430 if (skb->tc_verd & TC_NCLS) { 428 if (skb->tc_verd & TC_NCLS) {
431 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd); 429 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
432 ret = TC_ACT_OK; 430 ret = TC_ACT_OK;
433 goto exec_done; 431 goto exec_done;
434 } 432 }
435 list_for_each_entry(a, actions, list) { 433 for (i = 0; i < nr_actions; i++) {
434 const struct tc_action *a = actions[i];
435
436repeat: 436repeat:
437 ret = a->ops->act(skb, a, res); 437 ret = a->ops->act(skb, a, res);
438 if (ret == TC_ACT_REPEAT) 438 if (ret == TC_ACT_REPEAT)
@@ -754,16 +754,6 @@ err_out:
754 return ERR_PTR(err); 754 return ERR_PTR(err);
755} 755}
756 756
757static void cleanup_a(struct list_head *actions)
758{
759 struct tc_action *a, *tmp;
760
761 list_for_each_entry_safe(a, tmp, actions, list) {
762 list_del(&a->list);
763 kfree(a);
764 }
765}
766
767static int tca_action_flush(struct net *net, struct nlattr *nla, 757static int tca_action_flush(struct net *net, struct nlattr *nla,
768 struct nlmsghdr *n, u32 portid) 758 struct nlmsghdr *n, u32 portid)
769{ 759{
@@ -905,7 +895,7 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
905 return ret; 895 return ret;
906 } 896 }
907err: 897err:
908 cleanup_a(&actions); 898 tcf_action_destroy(&actions, 0);
909 return ret; 899 return ret;
910} 900}
911 901
@@ -942,15 +932,9 @@ tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
942 932
943 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions); 933 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions);
944 if (ret) 934 if (ret)
945 goto done; 935 return ret;
946 936
947 /* dump then free all the actions after update; inserted policy 937 return tcf_add_notify(net, n, &actions, portid);
948 * stays intact
949 */
950 ret = tcf_add_notify(net, n, &actions, portid);
951 cleanup_a(&actions);
952done:
953 return ret;
954} 938}
955 939
956static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n) 940static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n)
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index b3c7e975fc9e..8a3be1d99775 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -63,49 +63,8 @@ static int tcf_act_police_walker(struct net *net, struct sk_buff *skb,
63 const struct tc_action_ops *ops) 63 const struct tc_action_ops *ops)
64{ 64{
65 struct tc_action_net *tn = net_generic(net, police_net_id); 65 struct tc_action_net *tn = net_generic(net, police_net_id);
66 struct tcf_hashinfo *hinfo = tn->hinfo;
67 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
68 struct nlattr *nest;
69
70 spin_lock_bh(&hinfo->lock);
71
72 s_i = cb->args[0];
73
74 for (i = 0; i < (POL_TAB_MASK + 1); i++) {
75 struct hlist_head *head;
76 struct tc_action *p;
77
78 head = &hinfo->htab[tcf_hash(i, POL_TAB_MASK)];
79
80 hlist_for_each_entry_rcu(p, head, tcfa_head) {
81 index++;
82 if (index < s_i)
83 continue;
84 nest = nla_nest_start(skb, index);
85 if (nest == NULL)
86 goto nla_put_failure;
87 if (type == RTM_DELACTION)
88 err = tcf_action_dump_1(skb, p, 0, 1);
89 else
90 err = tcf_action_dump_1(skb, p, 0, 0);
91 if (err < 0) {
92 index--;
93 nla_nest_cancel(skb, nest);
94 goto done;
95 }
96 nla_nest_end(skb, nest);
97 n_i++;
98 }
99 }
100done:
101 spin_unlock_bh(&hinfo->lock);
102 if (n_i)
103 cb->args[0] += n_i;
104 return n_i;
105 66
106nla_put_failure: 67 return tcf_generic_walker(tn, skb, cb, type, ops);
107 nla_nest_cancel(skb, nest);
108 goto done;
109} 68}
110 69
111static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = { 70static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = {
@@ -125,6 +84,7 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
125 struct tcf_police *police; 84 struct tcf_police *police;
126 struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; 85 struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL;
127 struct tc_action_net *tn = net_generic(net, police_net_id); 86 struct tc_action_net *tn = net_generic(net, police_net_id);
87 bool exists = false;
128 int size; 88 int size;
129 89
130 if (nla == NULL) 90 if (nla == NULL)
@@ -139,24 +99,24 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
139 size = nla_len(tb[TCA_POLICE_TBF]); 99 size = nla_len(tb[TCA_POLICE_TBF]);
140 if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat)) 100 if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat))
141 return -EINVAL; 101 return -EINVAL;
102
142 parm = nla_data(tb[TCA_POLICE_TBF]); 103 parm = nla_data(tb[TCA_POLICE_TBF]);
104 exists = tcf_hash_check(tn, parm->index, a, bind);
105 if (exists && bind)
106 return 0;
143 107
144 if (parm->index) { 108 if (!exists) {
145 if (tcf_hash_check(tn, parm->index, a, bind)) {
146 if (ovr)
147 goto override;
148 /* not replacing */
149 return -EEXIST;
150 }
151 } else {
152 ret = tcf_hash_create(tn, parm->index, NULL, a, 109 ret = tcf_hash_create(tn, parm->index, NULL, a,
153 &act_police_ops, bind, false); 110 &act_police_ops, bind, false);
154 if (ret) 111 if (ret)
155 return ret; 112 return ret;
156 ret = ACT_P_CREATED; 113 ret = ACT_P_CREATED;
114 } else {
115 tcf_hash_release(*a, bind);
116 if (!ovr)
117 return -EEXIST;
157 } 118 }
158 119
159override:
160 police = to_police(*a); 120 police = to_police(*a);
161 if (parm->rate.rate) { 121 if (parm->rate.rate) {
162 err = -ENOMEM; 122 err = -ENOMEM;
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 843a716a4303..a7c5645373af 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -541,8 +541,12 @@ out:
541void tcf_exts_destroy(struct tcf_exts *exts) 541void tcf_exts_destroy(struct tcf_exts *exts)
542{ 542{
543#ifdef CONFIG_NET_CLS_ACT 543#ifdef CONFIG_NET_CLS_ACT
544 tcf_action_destroy(&exts->actions, TCA_ACT_UNBIND); 544 LIST_HEAD(actions);
545 INIT_LIST_HEAD(&exts->actions); 545
546 tcf_exts_to_list(exts, &actions);
547 tcf_action_destroy(&actions, TCA_ACT_UNBIND);
548 kfree(exts->actions);
549 exts->nr_actions = 0;
546#endif 550#endif
547} 551}
548EXPORT_SYMBOL(tcf_exts_destroy); 552EXPORT_SYMBOL(tcf_exts_destroy);
@@ -554,7 +558,6 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
554 { 558 {
555 struct tc_action *act; 559 struct tc_action *act;
556 560
557 INIT_LIST_HEAD(&exts->actions);
558 if (exts->police && tb[exts->police]) { 561 if (exts->police && tb[exts->police]) {
559 act = tcf_action_init_1(net, tb[exts->police], rate_tlv, 562 act = tcf_action_init_1(net, tb[exts->police], rate_tlv,
560 "police", ovr, 563 "police", ovr,
@@ -563,14 +566,20 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
563 return PTR_ERR(act); 566 return PTR_ERR(act);
564 567
565 act->type = exts->type = TCA_OLD_COMPAT; 568 act->type = exts->type = TCA_OLD_COMPAT;
566 list_add(&act->list, &exts->actions); 569 exts->actions[0] = act;
570 exts->nr_actions = 1;
567 } else if (exts->action && tb[exts->action]) { 571 } else if (exts->action && tb[exts->action]) {
568 int err; 572 LIST_HEAD(actions);
573 int err, i = 0;
574
569 err = tcf_action_init(net, tb[exts->action], rate_tlv, 575 err = tcf_action_init(net, tb[exts->action], rate_tlv,
570 NULL, ovr, 576 NULL, ovr,
571 TCA_ACT_BIND, &exts->actions); 577 TCA_ACT_BIND, &actions);
572 if (err) 578 if (err)
573 return err; 579 return err;
580 list_for_each_entry(act, &actions, list)
581 exts->actions[i++] = act;
582 exts->nr_actions = i;
574 } 583 }
575 } 584 }
576#else 585#else
@@ -587,37 +596,49 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
587 struct tcf_exts *src) 596 struct tcf_exts *src)
588{ 597{
589#ifdef CONFIG_NET_CLS_ACT 598#ifdef CONFIG_NET_CLS_ACT
590 LIST_HEAD(tmp); 599 struct tcf_exts old = *dst;
600
591 tcf_tree_lock(tp); 601 tcf_tree_lock(tp);
592 list_splice_init(&dst->actions, &tmp); 602 dst->nr_actions = src->nr_actions;
593 list_splice(&src->actions, &dst->actions); 603 dst->actions = src->actions;
594 dst->type = src->type; 604 dst->type = src->type;
595 tcf_tree_unlock(tp); 605 tcf_tree_unlock(tp);
596 tcf_action_destroy(&tmp, TCA_ACT_UNBIND); 606
607 tcf_exts_destroy(&old);
597#endif 608#endif
598} 609}
599EXPORT_SYMBOL(tcf_exts_change); 610EXPORT_SYMBOL(tcf_exts_change);
600 611
601#define tcf_exts_first_act(ext) \ 612#ifdef CONFIG_NET_CLS_ACT
602 list_first_entry_or_null(&(exts)->actions, \ 613static struct tc_action *tcf_exts_first_act(struct tcf_exts *exts)
603 struct tc_action, list) 614{
615 if (exts->nr_actions == 0)
616 return NULL;
617 else
618 return exts->actions[0];
619}
620#endif
604 621
605int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts) 622int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
606{ 623{
607#ifdef CONFIG_NET_CLS_ACT 624#ifdef CONFIG_NET_CLS_ACT
608 struct nlattr *nest; 625 struct nlattr *nest;
609 626
610 if (exts->action && !list_empty(&exts->actions)) { 627 if (exts->action && exts->nr_actions) {
611 /* 628 /*
612 * again for backward compatible mode - we want 629 * again for backward compatible mode - we want
613 * to work with both old and new modes of entering 630 * to work with both old and new modes of entering
614 * tc data even if iproute2 was newer - jhs 631 * tc data even if iproute2 was newer - jhs
615 */ 632 */
616 if (exts->type != TCA_OLD_COMPAT) { 633 if (exts->type != TCA_OLD_COMPAT) {
634 LIST_HEAD(actions);
635
617 nest = nla_nest_start(skb, exts->action); 636 nest = nla_nest_start(skb, exts->action);
618 if (nest == NULL) 637 if (nest == NULL)
619 goto nla_put_failure; 638 goto nla_put_failure;
620 if (tcf_action_dump(skb, &exts->actions, 0, 0) < 0) 639
640 tcf_exts_to_list(exts, &actions);
641 if (tcf_action_dump(skb, &actions, 0, 0) < 0)
621 goto nla_put_failure; 642 goto nla_put_failure;
622 nla_nest_end(skb, nest); 643 nla_nest_end(skb, nest);
623 } else if (exts->police) { 644 } else if (exts->police) {
diff --git a/net/sctp/proc.c b/net/sctp/proc.c
index 4cb5aedfe3ee..ef8ba77a5bea 100644
--- a/net/sctp/proc.c
+++ b/net/sctp/proc.c
@@ -293,6 +293,7 @@ static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
293 return ERR_PTR(err); 293 return ERR_PTR(err);
294 } 294 }
295 295
296 iter->start_fail = 0;
296 return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos); 297 return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos);
297} 298}
298 299
diff --git a/net/sctp/sctp_diag.c b/net/sctp/sctp_diag.c
index f69edcf219e5..bb691538adc8 100644
--- a/net/sctp/sctp_diag.c
+++ b/net/sctp/sctp_diag.c
@@ -13,6 +13,7 @@ static void inet_diag_msg_sctpasoc_fill(struct inet_diag_msg *r,
13{ 13{
14 union sctp_addr laddr, paddr; 14 union sctp_addr laddr, paddr;
15 struct dst_entry *dst; 15 struct dst_entry *dst;
16 struct timer_list *t3_rtx = &asoc->peer.primary_path->T3_rtx_timer;
16 17
17 laddr = list_entry(asoc->base.bind_addr.address_list.next, 18 laddr = list_entry(asoc->base.bind_addr.address_list.next,
18 struct sctp_sockaddr_entry, list)->a; 19 struct sctp_sockaddr_entry, list)->a;
@@ -40,10 +41,15 @@ static void inet_diag_msg_sctpasoc_fill(struct inet_diag_msg *r,
40 } 41 }
41 42
42 r->idiag_state = asoc->state; 43 r->idiag_state = asoc->state;
43 r->idiag_timer = SCTP_EVENT_TIMEOUT_T3_RTX; 44 if (timer_pending(t3_rtx)) {
44 r->idiag_retrans = asoc->rtx_data_chunks; 45 r->idiag_timer = SCTP_EVENT_TIMEOUT_T3_RTX;
45 r->idiag_expires = jiffies_to_msecs( 46 r->idiag_retrans = asoc->rtx_data_chunks;
46 asoc->timeouts[SCTP_EVENT_TIMEOUT_T3_RTX] - jiffies); 47 r->idiag_expires = jiffies_to_msecs(t3_rtx->expires - jiffies);
48 } else {
49 r->idiag_timer = 0;
50 r->idiag_retrans = 0;
51 r->idiag_expires = 0;
52 }
47} 53}
48 54
49static int inet_diag_msg_sctpladdrs_fill(struct sk_buff *skb, 55static int inet_diag_msg_sctpladdrs_fill(struct sk_buff *skb,
@@ -350,7 +356,7 @@ static int sctp_ep_dump(struct sctp_endpoint *ep, void *p)
350 if (cb->args[4] < cb->args[1]) 356 if (cb->args[4] < cb->args[1])
351 goto next; 357 goto next;
352 358
353 if ((r->idiag_states & ~TCPF_LISTEN) && !list_empty(&ep->asocs)) 359 if (!(r->idiag_states & TCPF_LISTEN) && !list_empty(&ep->asocs))
354 goto next; 360 goto next;
355 361
356 if (r->sdiag_family != AF_UNSPEC && 362 if (r->sdiag_family != AF_UNSPEC &&
@@ -465,7 +471,7 @@ skip:
465 * 3 : to mark if we have dumped the ep info of the current asoc 471 * 3 : to mark if we have dumped the ep info of the current asoc
466 * 4 : to work as a temporary variable to traversal list 472 * 4 : to work as a temporary variable to traversal list
467 */ 473 */
468 if (!(idiag_states & ~TCPF_LISTEN)) 474 if (!(idiag_states & ~(TCPF_LISTEN | TCPF_CLOSE)))
469 goto done; 475 goto done;
470 sctp_for_each_transport(sctp_tsp_dump, net, cb->args[2], &commp); 476 sctp_for_each_transport(sctp_tsp_dump, net, cb->args[2], &commp);
471done: 477done:
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index 1bc4f71aaba8..d85b803da11d 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -702,14 +702,14 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
702 */ 702 */
703 sctp_ulpevent_init(event, 0, skb->len + sizeof(struct sk_buff)); 703 sctp_ulpevent_init(event, 0, skb->len + sizeof(struct sk_buff));
704 704
705 sctp_ulpevent_receive_data(event, asoc);
706
707 /* And hold the chunk as we need it for getting the IP headers 705 /* And hold the chunk as we need it for getting the IP headers
708 * later in recvmsg 706 * later in recvmsg
709 */ 707 */
710 sctp_chunk_hold(chunk); 708 sctp_chunk_hold(chunk);
711 event->chunk = chunk; 709 event->chunk = chunk;
712 710
711 sctp_ulpevent_receive_data(event, asoc);
712
713 event->stream = ntohs(chunk->subh.data_hdr->stream); 713 event->stream = ntohs(chunk->subh.data_hdr->stream);
714 event->ssn = ntohs(chunk->subh.data_hdr->ssn); 714 event->ssn = ntohs(chunk->subh.data_hdr->ssn);
715 event->ppid = chunk->subh.data_hdr->ppid; 715 event->ppid = chunk->subh.data_hdr->ppid;
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 23c8e7c39656..976c7812bbd5 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -340,12 +340,14 @@ gss_release_msg(struct gss_upcall_msg *gss_msg)
340} 340}
341 341
342static struct gss_upcall_msg * 342static struct gss_upcall_msg *
343__gss_find_upcall(struct rpc_pipe *pipe, kuid_t uid) 343__gss_find_upcall(struct rpc_pipe *pipe, kuid_t uid, const struct gss_auth *auth)
344{ 344{
345 struct gss_upcall_msg *pos; 345 struct gss_upcall_msg *pos;
346 list_for_each_entry(pos, &pipe->in_downcall, list) { 346 list_for_each_entry(pos, &pipe->in_downcall, list) {
347 if (!uid_eq(pos->uid, uid)) 347 if (!uid_eq(pos->uid, uid))
348 continue; 348 continue;
349 if (auth && pos->auth->service != auth->service)
350 continue;
349 atomic_inc(&pos->count); 351 atomic_inc(&pos->count);
350 dprintk("RPC: %s found msg %p\n", __func__, pos); 352 dprintk("RPC: %s found msg %p\n", __func__, pos);
351 return pos; 353 return pos;
@@ -365,7 +367,7 @@ gss_add_msg(struct gss_upcall_msg *gss_msg)
365 struct gss_upcall_msg *old; 367 struct gss_upcall_msg *old;
366 368
367 spin_lock(&pipe->lock); 369 spin_lock(&pipe->lock);
368 old = __gss_find_upcall(pipe, gss_msg->uid); 370 old = __gss_find_upcall(pipe, gss_msg->uid, gss_msg->auth);
369 if (old == NULL) { 371 if (old == NULL) {
370 atomic_inc(&gss_msg->count); 372 atomic_inc(&gss_msg->count);
371 list_add(&gss_msg->list, &pipe->in_downcall); 373 list_add(&gss_msg->list, &pipe->in_downcall);
@@ -714,7 +716,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
714 err = -ENOENT; 716 err = -ENOENT;
715 /* Find a matching upcall */ 717 /* Find a matching upcall */
716 spin_lock(&pipe->lock); 718 spin_lock(&pipe->lock);
717 gss_msg = __gss_find_upcall(pipe, uid); 719 gss_msg = __gss_find_upcall(pipe, uid, NULL);
718 if (gss_msg == NULL) { 720 if (gss_msg == NULL) {
719 spin_unlock(&pipe->lock); 721 spin_unlock(&pipe->lock);
720 goto err_put_ctx; 722 goto err_put_ctx;
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index cb49898a5a58..7f79fb7dc6a0 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -2638,6 +2638,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
2638{ 2638{
2639 struct rpc_xprt_switch *xps; 2639 struct rpc_xprt_switch *xps;
2640 struct rpc_xprt *xprt; 2640 struct rpc_xprt *xprt;
2641 unsigned long reconnect_timeout;
2641 unsigned char resvport; 2642 unsigned char resvport;
2642 int ret = 0; 2643 int ret = 0;
2643 2644
@@ -2649,6 +2650,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
2649 return -EAGAIN; 2650 return -EAGAIN;
2650 } 2651 }
2651 resvport = xprt->resvport; 2652 resvport = xprt->resvport;
2653 reconnect_timeout = xprt->max_reconnect_timeout;
2652 rcu_read_unlock(); 2654 rcu_read_unlock();
2653 2655
2654 xprt = xprt_create_transport(xprtargs); 2656 xprt = xprt_create_transport(xprtargs);
@@ -2657,6 +2659,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
2657 goto out_put_switch; 2659 goto out_put_switch;
2658 } 2660 }
2659 xprt->resvport = resvport; 2661 xprt->resvport = resvport;
2662 xprt->max_reconnect_timeout = reconnect_timeout;
2660 2663
2661 rpc_xprt_switch_set_roundrobin(xps); 2664 rpc_xprt_switch_set_roundrobin(xps);
2662 if (setup) { 2665 if (setup) {
@@ -2673,6 +2676,27 @@ out_put_switch:
2673} 2676}
2674EXPORT_SYMBOL_GPL(rpc_clnt_add_xprt); 2677EXPORT_SYMBOL_GPL(rpc_clnt_add_xprt);
2675 2678
2679static int
2680rpc_xprt_cap_max_reconnect_timeout(struct rpc_clnt *clnt,
2681 struct rpc_xprt *xprt,
2682 void *data)
2683{
2684 unsigned long timeout = *((unsigned long *)data);
2685
2686 if (timeout < xprt->max_reconnect_timeout)
2687 xprt->max_reconnect_timeout = timeout;
2688 return 0;
2689}
2690
2691void
2692rpc_cap_max_reconnect_timeout(struct rpc_clnt *clnt, unsigned long timeo)
2693{
2694 rpc_clnt_iterate_for_each_xprt(clnt,
2695 rpc_xprt_cap_max_reconnect_timeout,
2696 &timeo);
2697}
2698EXPORT_SYMBOL_GPL(rpc_cap_max_reconnect_timeout);
2699
2676#if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 2700#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
2677static void rpc_show_header(void) 2701static void rpc_show_header(void)
2678{ 2702{
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 8313960cac52..ea244b29138b 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -680,6 +680,20 @@ out:
680 spin_unlock_bh(&xprt->transport_lock); 680 spin_unlock_bh(&xprt->transport_lock);
681} 681}
682 682
683static bool
684xprt_has_timer(const struct rpc_xprt *xprt)
685{
686 return xprt->idle_timeout != 0;
687}
688
689static void
690xprt_schedule_autodisconnect(struct rpc_xprt *xprt)
691 __must_hold(&xprt->transport_lock)
692{
693 if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
694 mod_timer(&xprt->timer, xprt->last_used + xprt->idle_timeout);
695}
696
683static void 697static void
684xprt_init_autodisconnect(unsigned long data) 698xprt_init_autodisconnect(unsigned long data)
685{ 699{
@@ -688,6 +702,8 @@ xprt_init_autodisconnect(unsigned long data)
688 spin_lock(&xprt->transport_lock); 702 spin_lock(&xprt->transport_lock);
689 if (!list_empty(&xprt->recv)) 703 if (!list_empty(&xprt->recv))
690 goto out_abort; 704 goto out_abort;
705 /* Reset xprt->last_used to avoid connect/autodisconnect cycling */
706 xprt->last_used = jiffies;
691 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) 707 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
692 goto out_abort; 708 goto out_abort;
693 spin_unlock(&xprt->transport_lock); 709 spin_unlock(&xprt->transport_lock);
@@ -725,6 +741,7 @@ void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie)
725 goto out; 741 goto out;
726 xprt->snd_task =NULL; 742 xprt->snd_task =NULL;
727 xprt->ops->release_xprt(xprt, NULL); 743 xprt->ops->release_xprt(xprt, NULL);
744 xprt_schedule_autodisconnect(xprt);
728out: 745out:
729 spin_unlock_bh(&xprt->transport_lock); 746 spin_unlock_bh(&xprt->transport_lock);
730 wake_up_bit(&xprt->state, XPRT_LOCKED); 747 wake_up_bit(&xprt->state, XPRT_LOCKED);
@@ -888,11 +905,6 @@ static void xprt_timer(struct rpc_task *task)
888 spin_unlock_bh(&xprt->transport_lock); 905 spin_unlock_bh(&xprt->transport_lock);
889} 906}
890 907
891static inline int xprt_has_timer(struct rpc_xprt *xprt)
892{
893 return xprt->idle_timeout != 0;
894}
895
896/** 908/**
897 * xprt_prepare_transmit - reserve the transport before sending a request 909 * xprt_prepare_transmit - reserve the transport before sending a request
898 * @task: RPC task about to send a request 910 * @task: RPC task about to send a request
@@ -1280,9 +1292,7 @@ void xprt_release(struct rpc_task *task)
1280 if (!list_empty(&req->rq_list)) 1292 if (!list_empty(&req->rq_list))
1281 list_del(&req->rq_list); 1293 list_del(&req->rq_list);
1282 xprt->last_used = jiffies; 1294 xprt->last_used = jiffies;
1283 if (list_empty(&xprt->recv) && xprt_has_timer(xprt)) 1295 xprt_schedule_autodisconnect(xprt);
1284 mod_timer(&xprt->timer,
1285 xprt->last_used + xprt->idle_timeout);
1286 spin_unlock_bh(&xprt->transport_lock); 1296 spin_unlock_bh(&xprt->transport_lock);
1287 if (req->rq_buffer) 1297 if (req->rq_buffer)
1288 xprt->ops->buf_free(req->rq_buffer); 1298 xprt->ops->buf_free(req->rq_buffer);
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 111767ab124a..8ede3bc52481 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -177,7 +177,6 @@ static struct ctl_table sunrpc_table[] = {
177 * increase over time if the server is down or not responding. 177 * increase over time if the server is down or not responding.
178 */ 178 */
179#define XS_TCP_INIT_REEST_TO (3U * HZ) 179#define XS_TCP_INIT_REEST_TO (3U * HZ)
180#define XS_TCP_MAX_REEST_TO (5U * 60 * HZ)
181 180
182/* 181/*
183 * TCP idle timeout; client drops the transport socket if it is idle 182 * TCP idle timeout; client drops the transport socket if it is idle
@@ -2173,6 +2172,8 @@ static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2173 write_unlock_bh(&sk->sk_callback_lock); 2172 write_unlock_bh(&sk->sk_callback_lock);
2174 } 2173 }
2175 xs_udp_do_set_buffer_size(xprt); 2174 xs_udp_do_set_buffer_size(xprt);
2175
2176 xprt->stat.connect_start = jiffies;
2176} 2177}
2177 2178
2178static void xs_udp_setup_socket(struct work_struct *work) 2179static void xs_udp_setup_socket(struct work_struct *work)
@@ -2236,6 +2237,7 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2236 unsigned int keepcnt = xprt->timeout->to_retries + 1; 2237 unsigned int keepcnt = xprt->timeout->to_retries + 1;
2237 unsigned int opt_on = 1; 2238 unsigned int opt_on = 1;
2238 unsigned int timeo; 2239 unsigned int timeo;
2240 unsigned int addr_pref = IPV6_PREFER_SRC_PUBLIC;
2239 2241
2240 /* TCP Keepalive options */ 2242 /* TCP Keepalive options */
2241 kernel_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, 2243 kernel_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
@@ -2247,6 +2249,16 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2247 kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT, 2249 kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
2248 (char *)&keepcnt, sizeof(keepcnt)); 2250 (char *)&keepcnt, sizeof(keepcnt));
2249 2251
2252 /* Avoid temporary address, they are bad for long-lived
2253 * connections such as NFS mounts.
2254 * RFC4941, section 3.6 suggests that:
2255 * Individual applications, which have specific
2256 * knowledge about the normal duration of connections,
2257 * MAY override this as appropriate.
2258 */
2259 kernel_setsockopt(sock, SOL_IPV6, IPV6_ADDR_PREFERENCES,
2260 (char *)&addr_pref, sizeof(addr_pref));
2261
2250 /* TCP user timeout (see RFC5482) */ 2262 /* TCP user timeout (see RFC5482) */
2251 timeo = jiffies_to_msecs(xprt->timeout->to_initval) * 2263 timeo = jiffies_to_msecs(xprt->timeout->to_initval) *
2252 (xprt->timeout->to_retries + 1); 2264 (xprt->timeout->to_retries + 1);
@@ -2295,6 +2307,10 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2295 /* SYN_SENT! */ 2307 /* SYN_SENT! */
2296 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO) 2308 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2297 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; 2309 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2310 break;
2311 case -EADDRNOTAVAIL:
2312 /* Source port number is unavailable. Try a new one! */
2313 transport->srcport = 0;
2298 } 2314 }
2299out: 2315out:
2300 return ret; 2316 return ret;
@@ -2369,6 +2385,25 @@ out:
2369 xprt_wake_pending_tasks(xprt, status); 2385 xprt_wake_pending_tasks(xprt, status);
2370} 2386}
2371 2387
2388static unsigned long xs_reconnect_delay(const struct rpc_xprt *xprt)
2389{
2390 unsigned long start, now = jiffies;
2391
2392 start = xprt->stat.connect_start + xprt->reestablish_timeout;
2393 if (time_after(start, now))
2394 return start - now;
2395 return 0;
2396}
2397
2398static void xs_reconnect_backoff(struct rpc_xprt *xprt)
2399{
2400 xprt->reestablish_timeout <<= 1;
2401 if (xprt->reestablish_timeout > xprt->max_reconnect_timeout)
2402 xprt->reestablish_timeout = xprt->max_reconnect_timeout;
2403 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2404 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2405}
2406
2372/** 2407/**
2373 * xs_connect - connect a socket to a remote endpoint 2408 * xs_connect - connect a socket to a remote endpoint
2374 * @xprt: pointer to transport structure 2409 * @xprt: pointer to transport structure
@@ -2386,6 +2421,7 @@ out:
2386static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task) 2421static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
2387{ 2422{
2388 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); 2423 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2424 unsigned long delay = 0;
2389 2425
2390 WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport)); 2426 WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
2391 2427
@@ -2397,19 +2433,15 @@ static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
2397 /* Start by resetting any existing state */ 2433 /* Start by resetting any existing state */
2398 xs_reset_transport(transport); 2434 xs_reset_transport(transport);
2399 2435
2400 queue_delayed_work(xprtiod_workqueue, 2436 delay = xs_reconnect_delay(xprt);
2401 &transport->connect_worker, 2437 xs_reconnect_backoff(xprt);
2402 xprt->reestablish_timeout); 2438
2403 xprt->reestablish_timeout <<= 1; 2439 } else
2404 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2405 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2406 if (xprt->reestablish_timeout > XS_TCP_MAX_REEST_TO)
2407 xprt->reestablish_timeout = XS_TCP_MAX_REEST_TO;
2408 } else {
2409 dprintk("RPC: xs_connect scheduled xprt %p\n", xprt); 2440 dprintk("RPC: xs_connect scheduled xprt %p\n", xprt);
2410 queue_delayed_work(xprtiod_workqueue, 2441
2411 &transport->connect_worker, 0); 2442 queue_delayed_work(xprtiod_workqueue,
2412 } 2443 &transport->connect_worker,
2444 delay);
2413} 2445}
2414 2446
2415/** 2447/**
@@ -2961,6 +2993,8 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
2961 xprt->ops = &xs_tcp_ops; 2993 xprt->ops = &xs_tcp_ops;
2962 xprt->timeout = &xs_tcp_default_timeout; 2994 xprt->timeout = &xs_tcp_default_timeout;
2963 2995
2996 xprt->max_reconnect_timeout = xprt->timeout->to_maxval;
2997
2964 INIT_WORK(&transport->recv_worker, xs_tcp_data_receive_workfn); 2998 INIT_WORK(&transport->recv_worker, xs_tcp_data_receive_workfn);
2965 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket); 2999 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket);
2966 3000
diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c
index b62caa1c770c..ed97a5876ebe 100644
--- a/net/tipc/monitor.c
+++ b/net/tipc/monitor.c
@@ -728,12 +728,13 @@ int tipc_nl_add_monitor_peer(struct net *net, struct tipc_nl_msg *msg,
728 u32 bearer_id, u32 *prev_node) 728 u32 bearer_id, u32 *prev_node)
729{ 729{
730 struct tipc_monitor *mon = tipc_monitor(net, bearer_id); 730 struct tipc_monitor *mon = tipc_monitor(net, bearer_id);
731 struct tipc_peer *peer = mon->self; 731 struct tipc_peer *peer;
732 732
733 if (!mon) 733 if (!mon)
734 return -EINVAL; 734 return -EINVAL;
735 735
736 read_lock_bh(&mon->lock); 736 read_lock_bh(&mon->lock);
737 peer = mon->self;
737 do { 738 do {
738 if (*prev_node) { 739 if (*prev_node) {
739 if (peer->addr == *prev_node) 740 if (peer->addr == *prev_node)
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index c49b8df438cb..f9f5f3c3dab5 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -2180,7 +2180,8 @@ restart:
2180 TIPC_CONN_MSG, SHORT_H_SIZE, 2180 TIPC_CONN_MSG, SHORT_H_SIZE,
2181 0, dnode, onode, dport, oport, 2181 0, dnode, onode, dport, oport,
2182 TIPC_CONN_SHUTDOWN); 2182 TIPC_CONN_SHUTDOWN);
2183 tipc_node_xmit_skb(net, skb, dnode, tsk->portid); 2183 if (skb)
2184 tipc_node_xmit_skb(net, skb, dnode, tsk->portid);
2184 } 2185 }
2185 tsk->connected = 0; 2186 tsk->connected = 0;
2186 sock->state = SS_DISCONNECTING; 2187 sock->state = SS_DISCONNECTING;
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 699dfabdbccd..936d7eee62d0 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -87,9 +87,6 @@ virtio_transport_send_pkt_work(struct work_struct *work)
87 87
88 vq = vsock->vqs[VSOCK_VQ_TX]; 88 vq = vsock->vqs[VSOCK_VQ_TX];
89 89
90 /* Avoid unnecessary interrupts while we're processing the ring */
91 virtqueue_disable_cb(vq);
92
93 for (;;) { 90 for (;;) {
94 struct virtio_vsock_pkt *pkt; 91 struct virtio_vsock_pkt *pkt;
95 struct scatterlist hdr, buf, *sgs[2]; 92 struct scatterlist hdr, buf, *sgs[2];
@@ -99,7 +96,6 @@ virtio_transport_send_pkt_work(struct work_struct *work)
99 spin_lock_bh(&vsock->send_pkt_list_lock); 96 spin_lock_bh(&vsock->send_pkt_list_lock);
100 if (list_empty(&vsock->send_pkt_list)) { 97 if (list_empty(&vsock->send_pkt_list)) {
101 spin_unlock_bh(&vsock->send_pkt_list_lock); 98 spin_unlock_bh(&vsock->send_pkt_list_lock);
102 virtqueue_enable_cb(vq);
103 break; 99 break;
104 } 100 }
105 101
@@ -118,13 +114,13 @@ virtio_transport_send_pkt_work(struct work_struct *work)
118 } 114 }
119 115
120 ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, pkt, GFP_KERNEL); 116 ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, pkt, GFP_KERNEL);
117 /* Usually this means that there is no more space available in
118 * the vq
119 */
121 if (ret < 0) { 120 if (ret < 0) {
122 spin_lock_bh(&vsock->send_pkt_list_lock); 121 spin_lock_bh(&vsock->send_pkt_list_lock);
123 list_add(&pkt->list, &vsock->send_pkt_list); 122 list_add(&pkt->list, &vsock->send_pkt_list);
124 spin_unlock_bh(&vsock->send_pkt_list_lock); 123 spin_unlock_bh(&vsock->send_pkt_list_lock);
125
126 if (!virtqueue_enable_cb(vq) && ret == -ENOSPC)
127 continue; /* retry now that we have more space */
128 break; 124 break;
129 } 125 }
130 126
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index b0e11b6dc994..0f506220a3bd 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -513,6 +513,7 @@ static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy,
513 r = cfg80211_get_chans_dfs_available(wiphy, 513 r = cfg80211_get_chans_dfs_available(wiphy,
514 chandef->center_freq2, 514 chandef->center_freq2,
515 width); 515 width);
516 break;
516 default: 517 default:
517 WARN_ON(chandef->center_freq2); 518 WARN_ON(chandef->center_freq2);
518 break; 519 break;
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 46417f9cce68..f02653a08993 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5380,6 +5380,7 @@ static int nl80211_parse_mesh_config(struct genl_info *info,
5380{ 5380{
5381 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 5381 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
5382 u32 mask = 0; 5382 u32 mask = 0;
5383 u16 ht_opmode;
5383 5384
5384#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ 5385#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5385do { \ 5386do { \
@@ -5471,9 +5472,36 @@ do { \
5471 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, 5472 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
5472 mask, NL80211_MESHCONF_RSSI_THRESHOLD, 5473 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
5473 nl80211_check_s32); 5474 nl80211_check_s32);
5474 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, 5475 /*
5475 mask, NL80211_MESHCONF_HT_OPMODE, 5476 * Check HT operation mode based on
5476 nl80211_check_u16); 5477 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5478 */
5479 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5480 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5481
5482 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5483 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5484 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5485 return -EINVAL;
5486
5487 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5488 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5489 return -EINVAL;
5490
5491 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5492 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5493 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5494 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5495 return -EINVAL;
5496 break;
5497 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5498 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5499 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5500 return -EINVAL;
5501 break;
5502 }
5503 cfg->ht_opmode = ht_opmode;
5504 }
5477 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, 5505 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
5478 1, 65535, mask, 5506 1, 65535, mask,
5479 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 5507 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h
index 217c8d507f2e..7927a090fa0d 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/samples/bpf/bpf_helpers.h
@@ -72,8 +72,8 @@ static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flag
72 (void *) BPF_FUNC_l3_csum_replace; 72 (void *) BPF_FUNC_l3_csum_replace;
73static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) = 73static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) =
74 (void *) BPF_FUNC_l4_csum_replace; 74 (void *) BPF_FUNC_l4_csum_replace;
75static int (*bpf_skb_in_cgroup)(void *ctx, void *map, int index) = 75static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) =
76 (void *) BPF_FUNC_skb_in_cgroup; 76 (void *) BPF_FUNC_skb_under_cgroup;
77 77
78#if defined(__x86_64__) 78#if defined(__x86_64__)
79 79
diff --git a/samples/bpf/test_cgrp2_tc_kern.c b/samples/bpf/test_cgrp2_tc_kern.c
index 2732c37c8d5b..10ff73404e3a 100644
--- a/samples/bpf/test_cgrp2_tc_kern.c
+++ b/samples/bpf/test_cgrp2_tc_kern.c
@@ -57,7 +57,7 @@ int handle_egress(struct __sk_buff *skb)
57 bpf_trace_printk(dont_care_msg, sizeof(dont_care_msg), 57 bpf_trace_printk(dont_care_msg, sizeof(dont_care_msg),
58 eth->h_proto, ip6h->nexthdr); 58 eth->h_proto, ip6h->nexthdr);
59 return TC_ACT_OK; 59 return TC_ACT_OK;
60 } else if (bpf_skb_in_cgroup(skb, &test_cgrp2_array_pin, 0) != 1) { 60 } else if (bpf_skb_under_cgroup(skb, &test_cgrp2_array_pin, 0) != 1) {
61 bpf_trace_printk(pass_msg, sizeof(pass_msg)); 61 bpf_trace_printk(pass_msg, sizeof(pass_msg));
62 return TC_ACT_OK; 62 return TC_ACT_OK;
63 } else { 63 } else {
diff --git a/samples/bpf/test_maps.c b/samples/bpf/test_maps.c
index 47bf0858f9e4..cce2b59751eb 100644
--- a/samples/bpf/test_maps.c
+++ b/samples/bpf/test_maps.c
@@ -68,7 +68,16 @@ static void test_hashmap_sanity(int i, void *data)
68 assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == -1 && 68 assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == -1 &&
69 errno == E2BIG); 69 errno == E2BIG);
70 70
71 /* update existing element, thought the map is full */
72 key = 1;
73 assert(bpf_update_elem(map_fd, &key, &value, BPF_EXIST) == 0);
74 key = 2;
75 assert(bpf_update_elem(map_fd, &key, &value, BPF_ANY) == 0);
76 key = 1;
77 assert(bpf_update_elem(map_fd, &key, &value, BPF_ANY) == 0);
78
71 /* check that key = 0 doesn't exist */ 79 /* check that key = 0 doesn't exist */
80 key = 0;
72 assert(bpf_delete_elem(map_fd, &key) == -1 && errno == ENOENT); 81 assert(bpf_delete_elem(map_fd, &key) == -1 && errno == ENOENT);
73 82
74 /* iterate over two elements */ 83 /* iterate over two elements */
@@ -413,10 +422,12 @@ static void do_work(int fn, void *data)
413 422
414 for (i = fn; i < MAP_SIZE; i += TASKS) { 423 for (i = fn; i < MAP_SIZE; i += TASKS) {
415 key = value = i; 424 key = value = i;
416 if (do_update) 425 if (do_update) {
417 assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == 0); 426 assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == 0);
418 else 427 assert(bpf_update_elem(map_fd, &key, &value, BPF_EXIST) == 0);
428 } else {
419 assert(bpf_delete_elem(map_fd, &key) == 0); 429 assert(bpf_delete_elem(map_fd, &key) == 0);
430 }
420 } 431 }
421} 432}
422 433
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 122fcdaf42c8..aed4511f0304 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -432,7 +432,7 @@ foreach my $file (@ARGV) {
432 die "$P: file '${file}' not found\n"; 432 die "$P: file '${file}' not found\n";
433 } 433 }
434 } 434 }
435 if ($from_filename || vcs_file_exists($file)) { 435 if ($from_filename || ($file ne "&STDIN" && vcs_file_exists($file))) {
436 $file =~ s/^\Q${cur_path}\E//; #strip any absolute path 436 $file =~ s/^\Q${cur_path}\E//; #strip any absolute path
437 $file =~ s/^\Q${lk_path}\E//; #or the path to the lk tree 437 $file =~ s/^\Q${lk_path}\E//; #or the path to the lk tree
438 push(@files, $file); 438 push(@files, $file);
@@ -2136,9 +2136,11 @@ sub vcs_file_exists {
2136 2136
2137 my $cmd = $VCS_cmds{"file_exists_cmd"}; 2137 my $cmd = $VCS_cmds{"file_exists_cmd"};
2138 $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd 2138 $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
2139 2139 $cmd .= " 2>&1";
2140 $exists = &{$VCS_cmds{"execute_cmd"}}($cmd); 2140 $exists = &{$VCS_cmds{"execute_cmd"}}($cmd);
2141 2141
2142 return 0 if ($? != 0);
2143
2142 return $exists; 2144 return $exists;
2143} 2145}
2144 2146
diff --git a/security/Kconfig b/security/Kconfig
index df28f2b6f3e1..da10d9b573a4 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -136,6 +136,7 @@ config HAVE_ARCH_HARDENED_USERCOPY
136config HARDENED_USERCOPY 136config HARDENED_USERCOPY
137 bool "Harden memory copies between kernel and userspace" 137 bool "Harden memory copies between kernel and userspace"
138 depends on HAVE_ARCH_HARDENED_USERCOPY 138 depends on HAVE_ARCH_HARDENED_USERCOPY
139 depends on HAVE_HARDENED_USERCOPY_ALLOCATOR
139 select BUG 140 select BUG
140 help 141 help
141 This option checks for obviously wrong memory regions when 142 This option checks for obviously wrong memory regions when
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 89dacf9b4e6c..160c7f713722 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -906,20 +906,23 @@ static int azx_resume(struct device *dev)
906 struct snd_card *card = dev_get_drvdata(dev); 906 struct snd_card *card = dev_get_drvdata(dev);
907 struct azx *chip; 907 struct azx *chip;
908 struct hda_intel *hda; 908 struct hda_intel *hda;
909 struct hdac_bus *bus;
909 910
910 if (!card) 911 if (!card)
911 return 0; 912 return 0;
912 913
913 chip = card->private_data; 914 chip = card->private_data;
914 hda = container_of(chip, struct hda_intel, chip); 915 hda = container_of(chip, struct hda_intel, chip);
916 bus = azx_bus(chip);
915 if (chip->disabled || hda->init_failed || !chip->running) 917 if (chip->disabled || hda->init_failed || !chip->running)
916 return 0; 918 return 0;
917 919
918 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL 920 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
919 && hda->need_i915_power) { 921 snd_hdac_display_power(bus, true);
920 snd_hdac_display_power(azx_bus(chip), true); 922 if (hda->need_i915_power)
921 snd_hdac_i915_set_bclk(azx_bus(chip)); 923 snd_hdac_i915_set_bclk(bus);
922 } 924 }
925
923 if (chip->msi) 926 if (chip->msi)
924 if (pci_enable_msi(pci) < 0) 927 if (pci_enable_msi(pci) < 0)
925 chip->msi = 0; 928 chip->msi = 0;
@@ -929,6 +932,11 @@ static int azx_resume(struct device *dev)
929 932
930 hda_intel_init_chip(chip, true); 933 hda_intel_init_chip(chip, true);
931 934
935 /* power down again for link-controlled chips */
936 if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
937 !hda->need_i915_power)
938 snd_hdac_display_power(bus, false);
939
932 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 940 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
933 941
934 trace_azx_resume(chip); 942 trace_azx_resume(chip);
@@ -1008,6 +1016,7 @@ static int azx_runtime_resume(struct device *dev)
1008 1016
1009 chip = card->private_data; 1017 chip = card->private_data;
1010 hda = container_of(chip, struct hda_intel, chip); 1018 hda = container_of(chip, struct hda_intel, chip);
1019 bus = azx_bus(chip);
1011 if (chip->disabled || hda->init_failed) 1020 if (chip->disabled || hda->init_failed)
1012 return 0; 1021 return 0;
1013 1022
@@ -1015,15 +1024,9 @@ static int azx_runtime_resume(struct device *dev)
1015 return 0; 1024 return 0;
1016 1025
1017 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 1026 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1018 bus = azx_bus(chip); 1027 snd_hdac_display_power(bus, true);
1019 if (hda->need_i915_power) { 1028 if (hda->need_i915_power)
1020 snd_hdac_display_power(bus, true);
1021 snd_hdac_i915_set_bclk(bus); 1029 snd_hdac_i915_set_bclk(bus);
1022 } else {
1023 /* toggle codec wakeup bit for STATESTS read */
1024 snd_hdac_set_codec_wakeup(bus, true);
1025 snd_hdac_set_codec_wakeup(bus, false);
1026 }
1027 } 1030 }
1028 1031
1029 /* Read STATESTS before controller reset */ 1032 /* Read STATESTS before controller reset */
@@ -1043,6 +1046,11 @@ static int azx_runtime_resume(struct device *dev)
1043 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & 1046 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
1044 ~STATESTS_INT_MASK); 1047 ~STATESTS_INT_MASK);
1045 1048
1049 /* power down again for link-controlled chips */
1050 if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
1051 !hda->need_i915_power)
1052 snd_hdac_display_power(bus, false);
1053
1046 trace_azx_runtime_resume(chip); 1054 trace_azx_runtime_resume(chip);
1047 return 0; 1055 return 0;
1048} 1056}
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 574b1b48996f..7100f05e651a 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4828,7 +4828,7 @@ enum {
4828 ALC293_FIXUP_DELL1_MIC_NO_PRESENCE, 4828 ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
4829 ALC292_FIXUP_TPT440_DOCK, 4829 ALC292_FIXUP_TPT440_DOCK,
4830 ALC292_FIXUP_TPT440, 4830 ALC292_FIXUP_TPT440,
4831 ALC283_FIXUP_BXBT2807_MIC, 4831 ALC283_FIXUP_HEADSET_MIC,
4832 ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED, 4832 ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED,
4833 ALC282_FIXUP_ASPIRE_V5_PINS, 4833 ALC282_FIXUP_ASPIRE_V5_PINS,
4834 ALC280_FIXUP_HP_GPIO4, 4834 ALC280_FIXUP_HP_GPIO4,
@@ -5321,7 +5321,7 @@ static const struct hda_fixup alc269_fixups[] = {
5321 .chained = true, 5321 .chained = true,
5322 .chain_id = ALC292_FIXUP_TPT440_DOCK, 5322 .chain_id = ALC292_FIXUP_TPT440_DOCK,
5323 }, 5323 },
5324 [ALC283_FIXUP_BXBT2807_MIC] = { 5324 [ALC283_FIXUP_HEADSET_MIC] = {
5325 .type = HDA_FIXUP_PINS, 5325 .type = HDA_FIXUP_PINS,
5326 .v.pins = (const struct hda_pintbl[]) { 5326 .v.pins = (const struct hda_pintbl[]) {
5327 { 0x19, 0x04a110f0 }, 5327 { 0x19, 0x04a110f0 },
@@ -5651,7 +5651,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5651 SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN), 5651 SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN),
5652 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC), 5652 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
5653 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC), 5653 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC),
5654 SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_BXBT2807_MIC), 5654 SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_HEADSET_MIC),
5655 SND_PCI_QUIRK(0x1462, 0xb120, "MSI Cubi MS-B120", ALC283_FIXUP_HEADSET_MIC),
5655 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), 5656 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5656 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), 5657 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5657 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), 5658 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index 54c09acd3fed..16e459aedffe 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -299,8 +299,9 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
299 clk_enable(ssc_p->ssc->clk); 299 clk_enable(ssc_p->ssc->clk);
300 ssc_p->mck_rate = clk_get_rate(ssc_p->ssc->clk); 300 ssc_p->mck_rate = clk_get_rate(ssc_p->ssc->clk);
301 301
302 /* Reset the SSC to keep it at a clean status */ 302 /* Reset the SSC unless initialized to keep it in a clean state */
303 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST)); 303 if (!ssc_p->initialized)
304 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
304 305
305 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 306 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
306 dir = 0; 307 dir = 0;
diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c
index e5527bc570ae..bcf1834c5648 100644
--- a/sound/soc/codecs/da7213.c
+++ b/sound/soc/codecs/da7213.c
@@ -1247,8 +1247,8 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1247 return -EINVAL; 1247 return -EINVAL;
1248 } 1248 }
1249 1249
1250 /* By default only 32 BCLK per WCLK is supported */ 1250 /* By default only 64 BCLK per WCLK is supported */
1251 dai_clk_mode |= DA7213_DAI_BCLKS_PER_WCLK_32; 1251 dai_clk_mode |= DA7213_DAI_BCLKS_PER_WCLK_64;
1252 1252
1253 snd_soc_write(codec, DA7213_DAI_CLK_MODE, dai_clk_mode); 1253 snd_soc_write(codec, DA7213_DAI_CLK_MODE, dai_clk_mode);
1254 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_FORMAT_MASK, 1254 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_FORMAT_MASK,
diff --git a/sound/soc/codecs/max98371.c b/sound/soc/codecs/max98371.c
index cf0a39bb631a..02352ed8961c 100644
--- a/sound/soc/codecs/max98371.c
+++ b/sound/soc/codecs/max98371.c
@@ -412,6 +412,7 @@ static int max98371_i2c_remove(struct i2c_client *client)
412 412
413static const struct i2c_device_id max98371_i2c_id[] = { 413static const struct i2c_device_id max98371_i2c_id[] = {
414 { "max98371", 0 }, 414 { "max98371", 0 },
415 { }
415}; 416};
416 417
417MODULE_DEVICE_TABLE(i2c, max98371_i2c_id); 418MODULE_DEVICE_TABLE(i2c, max98371_i2c_id);
diff --git a/sound/soc/codecs/nau8825.c b/sound/soc/codecs/nau8825.c
index 5c9707ac4bbf..2e59a85e360b 100644
--- a/sound/soc/codecs/nau8825.c
+++ b/sound/soc/codecs/nau8825.c
@@ -212,31 +212,6 @@ static const unsigned short logtable[256] = {
212 0xfa2f, 0xfaea, 0xfba5, 0xfc60, 0xfd1a, 0xfdd4, 0xfe8e, 0xff47 212 0xfa2f, 0xfaea, 0xfba5, 0xfc60, 0xfd1a, 0xfdd4, 0xfe8e, 0xff47
213}; 213};
214 214
215static struct snd_soc_dai *nau8825_get_codec_dai(struct nau8825 *nau8825)
216{
217 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(nau8825->dapm);
218 struct snd_soc_component *component = &codec->component;
219 struct snd_soc_dai *codec_dai, *_dai;
220
221 list_for_each_entry_safe(codec_dai, _dai, &component->dai_list, list) {
222 if (!strncmp(codec_dai->name, NUVOTON_CODEC_DAI,
223 strlen(NUVOTON_CODEC_DAI)))
224 return codec_dai;
225 }
226 return NULL;
227}
228
229static bool nau8825_dai_is_active(struct nau8825 *nau8825)
230{
231 struct snd_soc_dai *codec_dai = nau8825_get_codec_dai(nau8825);
232
233 if (codec_dai) {
234 if (codec_dai->playback_active || codec_dai->capture_active)
235 return true;
236 }
237 return false;
238}
239
240/** 215/**
241 * nau8825_sema_acquire - acquire the semaphore of nau88l25 216 * nau8825_sema_acquire - acquire the semaphore of nau88l25
242 * @nau8825: component to register the codec private data with 217 * @nau8825: component to register the codec private data with
@@ -250,19 +225,26 @@ static bool nau8825_dai_is_active(struct nau8825 *nau8825)
250 * Acquires the semaphore without jiffies. If no more tasks are allowed 225 * Acquires the semaphore without jiffies. If no more tasks are allowed
251 * to acquire the semaphore, calling this function will put the task to 226 * to acquire the semaphore, calling this function will put the task to
252 * sleep until the semaphore is released. 227 * sleep until the semaphore is released.
253 * It returns if the semaphore was acquired. 228 * If the semaphore is not released within the specified number of jiffies,
229 * this function returns -ETIME.
230 * If the sleep is interrupted by a signal, this function will return -EINTR.
231 * It returns 0 if the semaphore was acquired successfully.
254 */ 232 */
255static void nau8825_sema_acquire(struct nau8825 *nau8825, long timeout) 233static int nau8825_sema_acquire(struct nau8825 *nau8825, long timeout)
256{ 234{
257 int ret; 235 int ret;
258 236
259 if (timeout) 237 if (timeout) {
260 ret = down_timeout(&nau8825->xtalk_sem, timeout); 238 ret = down_timeout(&nau8825->xtalk_sem, timeout);
261 else 239 if (ret < 0)
240 dev_warn(nau8825->dev, "Acquire semaphone timeout\n");
241 } else {
262 ret = down_interruptible(&nau8825->xtalk_sem); 242 ret = down_interruptible(&nau8825->xtalk_sem);
243 if (ret < 0)
244 dev_warn(nau8825->dev, "Acquire semaphone fail\n");
245 }
263 246
264 if (ret < 0) 247 return ret;
265 dev_warn(nau8825->dev, "Acquire semaphone fail\n");
266} 248}
267 249
268/** 250/**
@@ -1205,6 +1187,8 @@ static int nau8825_hw_params(struct snd_pcm_substream *substream,
1205 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); 1187 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec);
1206 unsigned int val_len = 0; 1188 unsigned int val_len = 0;
1207 1189
1190 nau8825_sema_acquire(nau8825, 2 * HZ);
1191
1208 switch (params_width(params)) { 1192 switch (params_width(params)) {
1209 case 16: 1193 case 16:
1210 val_len |= NAU8825_I2S_DL_16; 1194 val_len |= NAU8825_I2S_DL_16;
@@ -1225,6 +1209,9 @@ static int nau8825_hw_params(struct snd_pcm_substream *substream,
1225 regmap_update_bits(nau8825->regmap, NAU8825_REG_I2S_PCM_CTRL1, 1209 regmap_update_bits(nau8825->regmap, NAU8825_REG_I2S_PCM_CTRL1,
1226 NAU8825_I2S_DL_MASK, val_len); 1210 NAU8825_I2S_DL_MASK, val_len);
1227 1211
1212 /* Release the semaphone. */
1213 nau8825_sema_release(nau8825);
1214
1228 return 0; 1215 return 0;
1229} 1216}
1230 1217
@@ -1234,6 +1221,8 @@ static int nau8825_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1234 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); 1221 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec);
1235 unsigned int ctrl1_val = 0, ctrl2_val = 0; 1222 unsigned int ctrl1_val = 0, ctrl2_val = 0;
1236 1223
1224 nau8825_sema_acquire(nau8825, 2 * HZ);
1225
1237 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1226 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1238 case SND_SOC_DAIFMT_CBM_CFM: 1227 case SND_SOC_DAIFMT_CBM_CFM:
1239 ctrl2_val |= NAU8825_I2S_MS_MASTER; 1228 ctrl2_val |= NAU8825_I2S_MS_MASTER;
@@ -1282,6 +1271,9 @@ static int nau8825_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1282 regmap_update_bits(nau8825->regmap, NAU8825_REG_I2S_PCM_CTRL2, 1271 regmap_update_bits(nau8825->regmap, NAU8825_REG_I2S_PCM_CTRL2,
1283 NAU8825_I2S_MS_MASK, ctrl2_val); 1272 NAU8825_I2S_MS_MASK, ctrl2_val);
1284 1273
1274 /* Release the semaphone. */
1275 nau8825_sema_release(nau8825);
1276
1285 return 0; 1277 return 0;
1286} 1278}
1287 1279
@@ -1611,8 +1603,11 @@ static irqreturn_t nau8825_interrupt(int irq, void *data)
1611 * cess and restore changes if process 1603 * cess and restore changes if process
1612 * is ongoing when ejection. 1604 * is ongoing when ejection.
1613 */ 1605 */
1606 int ret;
1614 nau8825->xtalk_protect = true; 1607 nau8825->xtalk_protect = true;
1615 nau8825_sema_acquire(nau8825, 0); 1608 ret = nau8825_sema_acquire(nau8825, 0);
1609 if (ret < 0)
1610 nau8825->xtalk_protect = false;
1616 } 1611 }
1617 /* Startup cross talk detection process */ 1612 /* Startup cross talk detection process */
1618 nau8825->xtalk_state = NAU8825_XTALK_PREPARE; 1613 nau8825->xtalk_state = NAU8825_XTALK_PREPARE;
@@ -2238,23 +2233,14 @@ static int __maybe_unused nau8825_suspend(struct snd_soc_codec *codec)
2238static int __maybe_unused nau8825_resume(struct snd_soc_codec *codec) 2233static int __maybe_unused nau8825_resume(struct snd_soc_codec *codec)
2239{ 2234{
2240 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec); 2235 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec);
2236 int ret;
2241 2237
2242 regcache_cache_only(nau8825->regmap, false); 2238 regcache_cache_only(nau8825->regmap, false);
2243 regcache_sync(nau8825->regmap); 2239 regcache_sync(nau8825->regmap);
2244 if (nau8825_is_jack_inserted(nau8825->regmap)) { 2240 nau8825->xtalk_protect = true;
2245 /* If the jack is inserted, we need to check whether the play- 2241 ret = nau8825_sema_acquire(nau8825, 0);
2246 * back is active before suspend. If active, the driver has to 2242 if (ret < 0)
2247 * raise the protection for cross talk function to avoid the 2243 nau8825->xtalk_protect = false;
2248 * playback recovers before cross talk process finish. Other-
2249 * wise, the playback will be interfered by cross talk func-
2250 * tion. It is better to apply hardware related parameters
2251 * before starting playback or record.
2252 */
2253 if (nau8825_dai_is_active(nau8825)) {
2254 nau8825->xtalk_protect = true;
2255 nau8825_sema_acquire(nau8825, 0);
2256 }
2257 }
2258 enable_irq(nau8825->irq); 2244 enable_irq(nau8825->irq);
2259 2245
2260 return 0; 2246 return 0;
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index a67ea10f41a1..f2664396be6f 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -581,7 +581,7 @@ static int wm2000_anc_transition(struct wm2000_priv *wm2000,
581 if (anc_transitions[i].dest == ANC_OFF) 581 if (anc_transitions[i].dest == ANC_OFF)
582 clk_disable_unprepare(wm2000->mclk); 582 clk_disable_unprepare(wm2000->mclk);
583 583
584 return ret; 584 return 0;
585} 585}
586 586
587static int wm2000_anc_set_mode(struct wm2000_priv *wm2000) 587static int wm2000_anc_set_mode(struct wm2000_priv *wm2000)
diff --git a/sound/soc/generic/Makefile b/sound/soc/generic/Makefile
index 45602ca8536e..2d53c8d70705 100644
--- a/sound/soc/generic/Makefile
+++ b/sound/soc/generic/Makefile
@@ -1,5 +1,5 @@
1obj-$(CONFIG_SND_SIMPLE_CARD_UTILS) := simple-card-utils.o 1snd-soc-simple-card-utils-objs := simple-card-utils.o
2
3snd-soc-simple-card-objs := simple-card.o 2snd-soc-simple-card-objs := simple-card.o
4 3
5obj-$(CONFIG_SND_SIMPLE_CARD) += snd-soc-simple-card.o 4obj-$(CONFIG_SND_SIMPLE_CARD_UTILS) += snd-soc-simple-card-utils.o
5obj-$(CONFIG_SND_SIMPLE_CARD) += snd-soc-simple-card.o
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index d89a9a1b2471..9599de69a880 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -7,6 +7,7 @@
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
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#include <linux/module.h>
10#include <linux/of.h> 11#include <linux/of.h>
11#include <sound/simple_card_utils.h> 12#include <sound/simple_card_utils.h>
12 13
@@ -95,3 +96,8 @@ int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
95 return 0; 96 return 0;
96} 97}
97EXPORT_SYMBOL_GPL(asoc_simple_card_parse_card_name); 98EXPORT_SYMBOL_GPL(asoc_simple_card_parse_card_name);
99
100/* Module information */
101MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
102MODULE_DESCRIPTION("ALSA SoC Simple Card Utils");
103MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c
index 25fcb796bd86..ddcb52a51854 100644
--- a/sound/soc/intel/skylake/skl-sst-utils.c
+++ b/sound/soc/intel/skylake/skl-sst-utils.c
@@ -123,6 +123,11 @@ int snd_skl_get_module_info(struct skl_sst *ctx, u8 *uuid,
123 123
124 uuid_mod = (uuid_le *)uuid; 124 uuid_mod = (uuid_le *)uuid;
125 125
126 if (list_empty(&ctx->uuid_list)) {
127 dev_err(ctx->dev, "Module list is empty\n");
128 return -EINVAL;
129 }
130
126 list_for_each_entry(module, &ctx->uuid_list, list) { 131 list_for_each_entry(module, &ctx->uuid_list, list) {
127 if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) { 132 if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) {
128 dfw_config->module_id = module->id; 133 dfw_config->module_id = module->id;
diff --git a/sound/soc/intel/skylake/skl.c b/sound/soc/intel/skylake/skl.c
index cd59536a761d..e3e764167765 100644
--- a/sound/soc/intel/skylake/skl.c
+++ b/sound/soc/intel/skylake/skl.c
@@ -672,8 +672,10 @@ static int skl_probe(struct pci_dev *pci,
672 672
673 skl->nhlt = skl_nhlt_init(bus->dev); 673 skl->nhlt = skl_nhlt_init(bus->dev);
674 674
675 if (skl->nhlt == NULL) 675 if (skl->nhlt == NULL) {
676 err = -ENODEV;
676 goto out_free; 677 goto out_free;
678 }
677 679
678 skl_nhlt_update_topology_bin(skl); 680 skl_nhlt_update_topology_bin(skl);
679 681
diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c
index 0843a68f277c..f61b3b58083b 100644
--- a/sound/soc/omap/omap-abe-twl6040.c
+++ b/sound/soc/omap/omap-abe-twl6040.c
@@ -38,10 +38,10 @@
38struct abe_twl6040 { 38struct abe_twl6040 {
39 int jack_detection; /* board can detect jack events */ 39 int jack_detection; /* board can detect jack events */
40 int mclk_freq; /* MCLK frequency speed for twl6040 */ 40 int mclk_freq; /* MCLK frequency speed for twl6040 */
41
42 struct platform_device *dmic_codec_dev;
43}; 41};
44 42
43struct platform_device *dmic_codec_dev;
44
45static int omap_abe_hw_params(struct snd_pcm_substream *substream, 45static int omap_abe_hw_params(struct snd_pcm_substream *substream,
46 struct snd_pcm_hw_params *params) 46 struct snd_pcm_hw_params *params)
47{ 47{
@@ -258,8 +258,6 @@ static int omap_abe_probe(struct platform_device *pdev)
258 if (priv == NULL) 258 if (priv == NULL)
259 return -ENOMEM; 259 return -ENOMEM;
260 260
261 priv->dmic_codec_dev = ERR_PTR(-EINVAL);
262
263 if (snd_soc_of_parse_card_name(card, "ti,model")) { 261 if (snd_soc_of_parse_card_name(card, "ti,model")) {
264 dev_err(&pdev->dev, "Card name is not provided\n"); 262 dev_err(&pdev->dev, "Card name is not provided\n");
265 return -ENODEV; 263 return -ENODEV;
@@ -284,13 +282,6 @@ static int omap_abe_probe(struct platform_device *pdev)
284 num_links = 2; 282 num_links = 2;
285 abe_twl6040_dai_links[1].cpu_of_node = dai_node; 283 abe_twl6040_dai_links[1].cpu_of_node = dai_node;
286 abe_twl6040_dai_links[1].platform_of_node = dai_node; 284 abe_twl6040_dai_links[1].platform_of_node = dai_node;
287
288 priv->dmic_codec_dev = platform_device_register_simple(
289 "dmic-codec", -1, NULL, 0);
290 if (IS_ERR(priv->dmic_codec_dev)) {
291 dev_err(&pdev->dev, "Can't instantiate dmic-codec\n");
292 return PTR_ERR(priv->dmic_codec_dev);
293 }
294 } else { 285 } else {
295 num_links = 1; 286 num_links = 1;
296 } 287 }
@@ -299,16 +290,14 @@ static int omap_abe_probe(struct platform_device *pdev)
299 of_property_read_u32(node, "ti,mclk-freq", &priv->mclk_freq); 290 of_property_read_u32(node, "ti,mclk-freq", &priv->mclk_freq);
300 if (!priv->mclk_freq) { 291 if (!priv->mclk_freq) {
301 dev_err(&pdev->dev, "MCLK frequency not provided\n"); 292 dev_err(&pdev->dev, "MCLK frequency not provided\n");
302 ret = -EINVAL; 293 return -EINVAL;
303 goto err_unregister;
304 } 294 }
305 295
306 card->fully_routed = 1; 296 card->fully_routed = 1;
307 297
308 if (!priv->mclk_freq) { 298 if (!priv->mclk_freq) {
309 dev_err(&pdev->dev, "MCLK frequency missing\n"); 299 dev_err(&pdev->dev, "MCLK frequency missing\n");
310 ret = -ENODEV; 300 return -ENODEV;
311 goto err_unregister;
312 } 301 }
313 302
314 card->dai_link = abe_twl6040_dai_links; 303 card->dai_link = abe_twl6040_dai_links;
@@ -317,17 +306,9 @@ static int omap_abe_probe(struct platform_device *pdev)
317 snd_soc_card_set_drvdata(card, priv); 306 snd_soc_card_set_drvdata(card, priv);
318 307
319 ret = snd_soc_register_card(card); 308 ret = snd_soc_register_card(card);
320 if (ret) { 309 if (ret)
321 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 310 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
322 ret); 311 ret);
323 goto err_unregister;
324 }
325
326 return 0;
327
328err_unregister:
329 if (!IS_ERR(priv->dmic_codec_dev))
330 platform_device_unregister(priv->dmic_codec_dev);
331 312
332 return ret; 313 return ret;
333} 314}
@@ -335,13 +316,9 @@ err_unregister:
335static int omap_abe_remove(struct platform_device *pdev) 316static int omap_abe_remove(struct platform_device *pdev)
336{ 317{
337 struct snd_soc_card *card = platform_get_drvdata(pdev); 318 struct snd_soc_card *card = platform_get_drvdata(pdev);
338 struct abe_twl6040 *priv = snd_soc_card_get_drvdata(card);
339 319
340 snd_soc_unregister_card(card); 320 snd_soc_unregister_card(card);
341 321
342 if (!IS_ERR(priv->dmic_codec_dev))
343 platform_device_unregister(priv->dmic_codec_dev);
344
345 return 0; 322 return 0;
346} 323}
347 324
@@ -361,7 +338,33 @@ static struct platform_driver omap_abe_driver = {
361 .remove = omap_abe_remove, 338 .remove = omap_abe_remove,
362}; 339};
363 340
364module_platform_driver(omap_abe_driver); 341static int __init omap_abe_init(void)
342{
343 int ret;
344
345 dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
346 0);
347 if (IS_ERR(dmic_codec_dev)) {
348 pr_err("%s: dmic-codec device registration failed\n", __func__);
349 return PTR_ERR(dmic_codec_dev);
350 }
351
352 ret = platform_driver_register(&omap_abe_driver);
353 if (ret) {
354 pr_err("%s: platform driver registration failed\n", __func__);
355 platform_device_unregister(dmic_codec_dev);
356 }
357
358 return ret;
359}
360module_init(omap_abe_init);
361
362static void __exit omap_abe_exit(void)
363{
364 platform_driver_unregister(&omap_abe_driver);
365 platform_device_unregister(dmic_codec_dev);
366}
367module_exit(omap_abe_exit);
365 368
366MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>"); 369MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
367MODULE_DESCRIPTION("ALSA SoC for OMAP boards with ABE and twl6040 codec"); 370MODULE_DESCRIPTION("ALSA SoC for OMAP boards with ABE and twl6040 codec");
diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c
index e7cdc51fd806..64609c77a79d 100644
--- a/sound/soc/omap/omap-mcpdm.c
+++ b/sound/soc/omap/omap-mcpdm.c
@@ -31,7 +31,6 @@
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/irq.h> 33#include <linux/irq.h>
34#include <linux/clk.h>
35#include <linux/slab.h> 34#include <linux/slab.h>
36#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
37#include <linux/of_device.h> 36#include <linux/of_device.h>
@@ -55,7 +54,6 @@ struct omap_mcpdm {
55 unsigned long phys_base; 54 unsigned long phys_base;
56 void __iomem *io_base; 55 void __iomem *io_base;
57 int irq; 56 int irq;
58 struct clk *pdmclk;
59 57
60 struct mutex mutex; 58 struct mutex mutex;
61 59
@@ -390,15 +388,14 @@ static int omap_mcpdm_probe(struct snd_soc_dai *dai)
390 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); 388 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
391 int ret; 389 int ret;
392 390
393 clk_prepare_enable(mcpdm->pdmclk);
394 pm_runtime_enable(mcpdm->dev); 391 pm_runtime_enable(mcpdm->dev);
395 392
396 /* Disable lines while request is ongoing */ 393 /* Disable lines while request is ongoing */
397 pm_runtime_get_sync(mcpdm->dev); 394 pm_runtime_get_sync(mcpdm->dev);
398 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, 0x00); 395 omap_mcpdm_write(mcpdm, MCPDM_REG_CTRL, 0x00);
399 396
400 ret = devm_request_irq(mcpdm->dev, mcpdm->irq, omap_mcpdm_irq_handler, 397 ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler, 0, "McPDM",
401 0, "McPDM", (void *)mcpdm); 398 (void *)mcpdm);
402 399
403 pm_runtime_put_sync(mcpdm->dev); 400 pm_runtime_put_sync(mcpdm->dev);
404 401
@@ -423,9 +420,9 @@ static int omap_mcpdm_remove(struct snd_soc_dai *dai)
423{ 420{
424 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); 421 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
425 422
423 free_irq(mcpdm->irq, (void *)mcpdm);
426 pm_runtime_disable(mcpdm->dev); 424 pm_runtime_disable(mcpdm->dev);
427 425
428 clk_disable_unprepare(mcpdm->pdmclk);
429 return 0; 426 return 0;
430} 427}
431 428
@@ -445,8 +442,6 @@ static int omap_mcpdm_suspend(struct snd_soc_dai *dai)
445 mcpdm->pm_active_count++; 442 mcpdm->pm_active_count++;
446 } 443 }
447 444
448 clk_disable_unprepare(mcpdm->pdmclk);
449
450 return 0; 445 return 0;
451} 446}
452 447
@@ -454,8 +449,6 @@ static int omap_mcpdm_resume(struct snd_soc_dai *dai)
454{ 449{
455 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); 450 struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
456 451
457 clk_prepare_enable(mcpdm->pdmclk);
458
459 if (mcpdm->pm_active_count) { 452 if (mcpdm->pm_active_count) {
460 while (mcpdm->pm_active_count--) 453 while (mcpdm->pm_active_count--)
461 pm_runtime_get_sync(mcpdm->dev); 454 pm_runtime_get_sync(mcpdm->dev);
@@ -549,15 +542,6 @@ static int asoc_mcpdm_probe(struct platform_device *pdev)
549 542
550 mcpdm->dev = &pdev->dev; 543 mcpdm->dev = &pdev->dev;
551 544
552 mcpdm->pdmclk = devm_clk_get(&pdev->dev, "pdmclk");
553 if (IS_ERR(mcpdm->pdmclk)) {
554 if (PTR_ERR(mcpdm->pdmclk) == -EPROBE_DEFER)
555 return -EPROBE_DEFER;
556 dev_warn(&pdev->dev, "Error getting pdmclk (%ld)!\n",
557 PTR_ERR(mcpdm->pdmclk));
558 mcpdm->pdmclk = NULL;
559 }
560
561 ret = devm_snd_soc_register_component(&pdev->dev, 545 ret = devm_snd_soc_register_component(&pdev->dev,
562 &omap_mcpdm_component, 546 &omap_mcpdm_component,
563 &omap_mcpdm_dai, 1); 547 &omap_mcpdm_dai, 1);
diff --git a/sound/soc/samsung/s3c24xx_uda134x.c b/sound/soc/samsung/s3c24xx_uda134x.c
index 50849e137fc0..92e88bca386e 100644
--- a/sound/soc/samsung/s3c24xx_uda134x.c
+++ b/sound/soc/samsung/s3c24xx_uda134x.c
@@ -58,10 +58,12 @@ static struct platform_device *s3c24xx_uda134x_snd_device;
58 58
59static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream) 59static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream)
60{ 60{
61 int ret = 0; 61 struct snd_soc_pcm_runtime *rtd = substream->private_data;
62 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
62#ifdef ENFORCE_RATES 63#ifdef ENFORCE_RATES
63 struct snd_pcm_runtime *runtime = substream->runtime; 64 struct snd_pcm_runtime *runtime = substream->runtime;
64#endif 65#endif
66 int ret = 0;
65 67
66 mutex_lock(&clk_lock); 68 mutex_lock(&clk_lock);
67 pr_debug("%s %d\n", __func__, clk_users); 69 pr_debug("%s %d\n", __func__, clk_users);
@@ -71,8 +73,7 @@ static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream)
71 printk(KERN_ERR "%s cannot get xtal\n", __func__); 73 printk(KERN_ERR "%s cannot get xtal\n", __func__);
72 ret = PTR_ERR(xtal); 74 ret = PTR_ERR(xtal);
73 } else { 75 } else {
74 pclk = clk_get(&s3c24xx_uda134x_snd_device->dev, 76 pclk = clk_get(cpu_dai->dev, "iis");
75 "pclk");
76 if (IS_ERR(pclk)) { 77 if (IS_ERR(pclk)) {
77 printk(KERN_ERR "%s cannot get pclk\n", 78 printk(KERN_ERR "%s cannot get pclk\n",
78 __func__); 79 __func__);
diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c
index e39f916d0f2f..969a5169de25 100644
--- a/sound/soc/sh/rcar/src.c
+++ b/sound/soc/sh/rcar/src.c
@@ -226,8 +226,12 @@ static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
226 ifscr = 0; 226 ifscr = 0;
227 fsrate = 0; 227 fsrate = 0;
228 if (fin != fout) { 228 if (fin != fout) {
229 u64 n;
230
229 ifscr = 1; 231 ifscr = 1;
230 fsrate = 0x0400000 / fout * fin; 232 n = (u64)0x0400000 * fin;
233 do_div(n, fout);
234 fsrate = n;
231 } 235 }
232 236
233 /* 237 /*
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index d2df46c14c68..bf7b52fce597 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -121,7 +121,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
121 121
122 dpcm_be_disconnect(fe, stream); 122 dpcm_be_disconnect(fe, stream);
123 fe->dpcm[stream].runtime = NULL; 123 fe->dpcm[stream].runtime = NULL;
124 goto fe_err; 124 goto path_err;
125 } 125 }
126 126
127 dpcm_clear_pending_state(fe, stream); 127 dpcm_clear_pending_state(fe, stream);
@@ -136,6 +136,8 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
136 136
137 return 0; 137 return 0;
138 138
139path_err:
140 dpcm_path_put(&list);
139fe_err: 141fe_err:
140 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) 142 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
141 fe->dai_link->compr_ops->shutdown(cstream); 143 fe->dai_link->compr_ops->shutdown(cstream);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 16369cad4803..4afa8dba5e98 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1056,7 +1056,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card,
1056 if (!rtd->platform) { 1056 if (!rtd->platform) {
1057 dev_err(card->dev, "ASoC: platform %s not registered\n", 1057 dev_err(card->dev, "ASoC: platform %s not registered\n",
1058 dai_link->platform_name); 1058 dai_link->platform_name);
1059 return -EPROBE_DEFER; 1059 goto _err_defer;
1060 } 1060 }
1061 1061
1062 soc_add_pcm_runtime(card, rtd); 1062 soc_add_pcm_runtime(card, rtd);
@@ -2083,14 +2083,13 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
2083 /* remove auxiliary devices */ 2083 /* remove auxiliary devices */
2084 soc_remove_aux_devices(card); 2084 soc_remove_aux_devices(card);
2085 2085
2086 snd_soc_dapm_free(&card->dapm);
2086 soc_cleanup_card_debugfs(card); 2087 soc_cleanup_card_debugfs(card);
2087 2088
2088 /* remove the card */ 2089 /* remove the card */
2089 if (card->remove) 2090 if (card->remove)
2090 card->remove(card); 2091 card->remove(card);
2091 2092
2092 snd_soc_dapm_free(&card->dapm);
2093
2094 snd_card_free(card->snd_card); 2093 snd_card_free(card->snd_card);
2095 return 0; 2094 return 0;
2096 2095
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 8698c26773b3..d908ff8f9755 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3493,6 +3493,7 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3493 const struct snd_soc_pcm_stream *config = w->params + w->params_select; 3493 const struct snd_soc_pcm_stream *config = w->params + w->params_select;
3494 struct snd_pcm_substream substream; 3494 struct snd_pcm_substream substream;
3495 struct snd_pcm_hw_params *params = NULL; 3495 struct snd_pcm_hw_params *params = NULL;
3496 struct snd_pcm_runtime *runtime = NULL;
3496 u64 fmt; 3497 u64 fmt;
3497 int ret; 3498 int ret;
3498 3499
@@ -3541,6 +3542,14 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3541 3542
3542 memset(&substream, 0, sizeof(substream)); 3543 memset(&substream, 0, sizeof(substream));
3543 3544
3545 /* Allocate a dummy snd_pcm_runtime for startup() and other ops() */
3546 runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
3547 if (!runtime) {
3548 ret = -ENOMEM;
3549 goto out;
3550 }
3551 substream.runtime = runtime;
3552
3544 switch (event) { 3553 switch (event) {
3545 case SND_SOC_DAPM_PRE_PMU: 3554 case SND_SOC_DAPM_PRE_PMU:
3546 substream.stream = SNDRV_PCM_STREAM_CAPTURE; 3555 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
@@ -3606,6 +3615,7 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3606 } 3615 }
3607 3616
3608out: 3617out:
3618 kfree(runtime);
3609 kfree(params); 3619 kfree(params);
3610 return ret; 3620 return ret;
3611} 3621}
diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c
index 204cc074adb9..41aa3355e920 100644
--- a/sound/usb/line6/pcm.c
+++ b/sound/usb/line6/pcm.c
@@ -55,7 +55,6 @@ static int snd_line6_impulse_volume_put(struct snd_kcontrol *kcontrol,
55 err = line6_pcm_acquire(line6pcm, LINE6_STREAM_IMPULSE); 55 err = line6_pcm_acquire(line6pcm, LINE6_STREAM_IMPULSE);
56 if (err < 0) { 56 if (err < 0) {
57 line6pcm->impulse_volume = 0; 57 line6pcm->impulse_volume = 0;
58 line6_pcm_release(line6pcm, LINE6_STREAM_IMPULSE);
59 return err; 58 return err;
60 } 59 }
61 } else { 60 } else {
@@ -211,7 +210,9 @@ static void line6_stream_stop(struct snd_line6_pcm *line6pcm, int direction,
211 spin_lock_irqsave(&pstr->lock, flags); 210 spin_lock_irqsave(&pstr->lock, flags);
212 clear_bit(type, &pstr->running); 211 clear_bit(type, &pstr->running);
213 if (!pstr->running) { 212 if (!pstr->running) {
213 spin_unlock_irqrestore(&pstr->lock, flags);
214 line6_unlink_audio_urbs(line6pcm, pstr); 214 line6_unlink_audio_urbs(line6pcm, pstr);
215 spin_lock_irqsave(&pstr->lock, flags);
215 if (direction == SNDRV_PCM_STREAM_CAPTURE) { 216 if (direction == SNDRV_PCM_STREAM_CAPTURE) {
216 line6pcm->prev_fbuf = NULL; 217 line6pcm->prev_fbuf = NULL;
217 line6pcm->prev_fsize = 0; 218 line6pcm->prev_fsize = 0;
diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c
index daf81d169a42..45dd34874f43 100644
--- a/sound/usb/line6/pod.c
+++ b/sound/usb/line6/pod.c
@@ -244,8 +244,8 @@ static int pod_set_system_param_int(struct usb_line6_pod *pod, int value,
244static ssize_t serial_number_show(struct device *dev, 244static ssize_t serial_number_show(struct device *dev,
245 struct device_attribute *attr, char *buf) 245 struct device_attribute *attr, char *buf)
246{ 246{
247 struct usb_interface *interface = to_usb_interface(dev); 247 struct snd_card *card = dev_to_snd_card(dev);
248 struct usb_line6_pod *pod = usb_get_intfdata(interface); 248 struct usb_line6_pod *pod = card->private_data;
249 249
250 return sprintf(buf, "%u\n", pod->serial_number); 250 return sprintf(buf, "%u\n", pod->serial_number);
251} 251}
@@ -256,8 +256,8 @@ static ssize_t serial_number_show(struct device *dev,
256static ssize_t firmware_version_show(struct device *dev, 256static ssize_t firmware_version_show(struct device *dev,
257 struct device_attribute *attr, char *buf) 257 struct device_attribute *attr, char *buf)
258{ 258{
259 struct usb_interface *interface = to_usb_interface(dev); 259 struct snd_card *card = dev_to_snd_card(dev);
260 struct usb_line6_pod *pod = usb_get_intfdata(interface); 260 struct usb_line6_pod *pod = card->private_data;
261 261
262 return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100, 262 return sprintf(buf, "%d.%02d\n", pod->firmware_version / 100,
263 pod->firmware_version % 100); 263 pod->firmware_version % 100);
@@ -269,8 +269,8 @@ static ssize_t firmware_version_show(struct device *dev,
269static ssize_t device_id_show(struct device *dev, 269static ssize_t device_id_show(struct device *dev,
270 struct device_attribute *attr, char *buf) 270 struct device_attribute *attr, char *buf)
271{ 271{
272 struct usb_interface *interface = to_usb_interface(dev); 272 struct snd_card *card = dev_to_snd_card(dev);
273 struct usb_line6_pod *pod = usb_get_intfdata(interface); 273 struct usb_line6_pod *pod = card->private_data;
274 274
275 return sprintf(buf, "%d\n", pod->device_id); 275 return sprintf(buf, "%d\n", pod->device_id);
276} 276}
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 6adde457b602..6cf1f3597455 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1128,6 +1128,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1128{ 1128{
1129 /* devices which do not support reading the sample rate. */ 1129 /* devices which do not support reading the sample rate. */
1130 switch (chip->usb_id) { 1130 switch (chip->usb_id) {
1131 case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
1131 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */ 1132 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
1132 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */ 1133 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
1133 case USB_ID(0x045E, 0x076E): /* MS Lifecam HD-5001 */ 1134 case USB_ID(0x045E, 0x076E): /* MS Lifecam HD-5001 */
@@ -1138,6 +1139,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1138 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */ 1139 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */
1139 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ 1140 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1140 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */ 1141 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
1142 case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
1141 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ 1143 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1142 case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */ 1144 case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */
1143 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */ 1145 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */
diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h
index f209ea151dca..3051f86a9b5f 100644
--- a/tools/arch/arm64/include/uapi/asm/kvm.h
+++ b/tools/arch/arm64/include/uapi/asm/kvm.h
@@ -87,9 +87,11 @@ struct kvm_regs {
87/* Supported VGICv3 address types */ 87/* Supported VGICv3 address types */
88#define KVM_VGIC_V3_ADDR_TYPE_DIST 2 88#define KVM_VGIC_V3_ADDR_TYPE_DIST 2
89#define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 89#define KVM_VGIC_V3_ADDR_TYPE_REDIST 3
90#define KVM_VGIC_ITS_ADDR_TYPE 4
90 91
91#define KVM_VGIC_V3_DIST_SIZE SZ_64K 92#define KVM_VGIC_V3_DIST_SIZE SZ_64K
92#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K) 93#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K)
94#define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K)
93 95
94#define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */ 96#define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */
95#define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */ 97#define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */
diff --git a/tools/arch/s390/include/uapi/asm/kvm.h b/tools/arch/s390/include/uapi/asm/kvm.h
index 3b8e99ef9d58..a2ffec4139ad 100644
--- a/tools/arch/s390/include/uapi/asm/kvm.h
+++ b/tools/arch/s390/include/uapi/asm/kvm.h
@@ -93,6 +93,47 @@ struct kvm_s390_vm_cpu_machine {
93 __u64 fac_list[256]; 93 __u64 fac_list[256];
94}; 94};
95 95
96#define KVM_S390_VM_CPU_PROCESSOR_FEAT 2
97#define KVM_S390_VM_CPU_MACHINE_FEAT 3
98
99#define KVM_S390_VM_CPU_FEAT_NR_BITS 1024
100#define KVM_S390_VM_CPU_FEAT_ESOP 0
101#define KVM_S390_VM_CPU_FEAT_SIEF2 1
102#define KVM_S390_VM_CPU_FEAT_64BSCAO 2
103#define KVM_S390_VM_CPU_FEAT_SIIF 3
104#define KVM_S390_VM_CPU_FEAT_GPERE 4
105#define KVM_S390_VM_CPU_FEAT_GSLS 5
106#define KVM_S390_VM_CPU_FEAT_IB 6
107#define KVM_S390_VM_CPU_FEAT_CEI 7
108#define KVM_S390_VM_CPU_FEAT_IBS 8
109#define KVM_S390_VM_CPU_FEAT_SKEY 9
110#define KVM_S390_VM_CPU_FEAT_CMMA 10
111#define KVM_S390_VM_CPU_FEAT_PFMFI 11
112#define KVM_S390_VM_CPU_FEAT_SIGPIF 12
113struct kvm_s390_vm_cpu_feat {
114 __u64 feat[16];
115};
116
117#define KVM_S390_VM_CPU_PROCESSOR_SUBFUNC 4
118#define KVM_S390_VM_CPU_MACHINE_SUBFUNC 5
119/* for "test bit" instructions MSB 0 bit ordering, for "query" raw blocks */
120struct kvm_s390_vm_cpu_subfunc {
121 __u8 plo[32]; /* always */
122 __u8 ptff[16]; /* with TOD-clock steering */
123 __u8 kmac[16]; /* with MSA */
124 __u8 kmc[16]; /* with MSA */
125 __u8 km[16]; /* with MSA */
126 __u8 kimd[16]; /* with MSA */
127 __u8 klmd[16]; /* with MSA */
128 __u8 pckmo[16]; /* with MSA3 */
129 __u8 kmctr[16]; /* with MSA4 */
130 __u8 kmf[16]; /* with MSA4 */
131 __u8 kmo[16]; /* with MSA4 */
132 __u8 pcc[16]; /* with MSA4 */
133 __u8 ppno[16]; /* with MSA5 */
134 __u8 reserved[1824];
135};
136
96/* kvm attributes for crypto */ 137/* kvm attributes for crypto */
97#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW 0 138#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW 0
98#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW 1 139#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW 1
diff --git a/tools/arch/s390/include/uapi/asm/sie.h b/tools/arch/s390/include/uapi/asm/sie.h
index 8fb5d4a6dd25..3ac634368939 100644
--- a/tools/arch/s390/include/uapi/asm/sie.h
+++ b/tools/arch/s390/include/uapi/asm/sie.h
@@ -140,6 +140,7 @@
140 exit_code_ipa0(0xB2, 0x4c, "TAR"), \ 140 exit_code_ipa0(0xB2, 0x4c, "TAR"), \
141 exit_code_ipa0(0xB2, 0x50, "CSP"), \ 141 exit_code_ipa0(0xB2, 0x50, "CSP"), \
142 exit_code_ipa0(0xB2, 0x54, "MVPG"), \ 142 exit_code_ipa0(0xB2, 0x54, "MVPG"), \
143 exit_code_ipa0(0xB2, 0x56, "STHYI"), \
143 exit_code_ipa0(0xB2, 0x58, "BSG"), \ 144 exit_code_ipa0(0xB2, 0x58, "BSG"), \
144 exit_code_ipa0(0xB2, 0x5a, "BSA"), \ 145 exit_code_ipa0(0xB2, 0x5a, "BSA"), \
145 exit_code_ipa0(0xB2, 0x5f, "CHSC"), \ 146 exit_code_ipa0(0xB2, 0x5f, "CHSC"), \
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 4a413485f9eb..92a8308b96f6 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -225,7 +225,6 @@
225#define X86_FEATURE_RDSEED ( 9*32+18) /* The RDSEED instruction */ 225#define X86_FEATURE_RDSEED ( 9*32+18) /* The RDSEED instruction */
226#define X86_FEATURE_ADX ( 9*32+19) /* The ADCX and ADOX instructions */ 226#define X86_FEATURE_ADX ( 9*32+19) /* The ADCX and ADOX instructions */
227#define X86_FEATURE_SMAP ( 9*32+20) /* Supervisor Mode Access Prevention */ 227#define X86_FEATURE_SMAP ( 9*32+20) /* Supervisor Mode Access Prevention */
228#define X86_FEATURE_PCOMMIT ( 9*32+22) /* PCOMMIT instruction */
229#define X86_FEATURE_CLFLUSHOPT ( 9*32+23) /* CLFLUSHOPT instruction */ 228#define X86_FEATURE_CLFLUSHOPT ( 9*32+23) /* CLFLUSHOPT instruction */
230#define X86_FEATURE_CLWB ( 9*32+24) /* CLWB instruction */ 229#define X86_FEATURE_CLWB ( 9*32+24) /* CLWB instruction */
231#define X86_FEATURE_AVX512PF ( 9*32+26) /* AVX-512 Prefetch */ 230#define X86_FEATURE_AVX512PF ( 9*32+26) /* AVX-512 Prefetch */
@@ -301,10 +300,6 @@
301#define X86_BUG_FXSAVE_LEAK X86_BUG(6) /* FXSAVE leaks FOP/FIP/FOP */ 300#define X86_BUG_FXSAVE_LEAK X86_BUG(6) /* FXSAVE leaks FOP/FIP/FOP */
302#define X86_BUG_CLFLUSH_MONITOR X86_BUG(7) /* AAI65, CLFLUSH required before MONITOR */ 301#define X86_BUG_CLFLUSH_MONITOR X86_BUG(7) /* AAI65, CLFLUSH required before MONITOR */
303#define X86_BUG_SYSRET_SS_ATTRS X86_BUG(8) /* SYSRET doesn't fix up SS attrs */ 302#define X86_BUG_SYSRET_SS_ATTRS X86_BUG(8) /* SYSRET doesn't fix up SS attrs */
304#define X86_BUG_NULL_SEG X86_BUG(9) /* Nulling a selector preserves the base */
305#define X86_BUG_SWAPGS_FENCE X86_BUG(10) /* SWAPGS without input dep on GS */
306
307
308#ifdef CONFIG_X86_32 303#ifdef CONFIG_X86_32
309/* 304/*
310 * 64-bit kernels don't use X86_BUG_ESPFIX. Make the define conditional 305 * 64-bit kernels don't use X86_BUG_ESPFIX. Make the define conditional
@@ -312,5 +307,7 @@
312 */ 307 */
313#define X86_BUG_ESPFIX X86_BUG(9) /* "" IRET to 16-bit SS corrupts ESP/RSP high bits */ 308#define X86_BUG_ESPFIX X86_BUG(9) /* "" IRET to 16-bit SS corrupts ESP/RSP high bits */
314#endif 309#endif
315 310#define X86_BUG_NULL_SEG X86_BUG(10) /* Nulling a selector preserves the base */
311#define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */
312#define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */
316#endif /* _ASM_X86_CPUFEATURES_H */ 313#endif /* _ASM_X86_CPUFEATURES_H */
diff --git a/tools/arch/x86/include/asm/disabled-features.h b/tools/arch/x86/include/asm/disabled-features.h
index 911e9358ceb1..85599ad4d024 100644
--- a/tools/arch/x86/include/asm/disabled-features.h
+++ b/tools/arch/x86/include/asm/disabled-features.h
@@ -56,5 +56,7 @@
56#define DISABLED_MASK14 0 56#define DISABLED_MASK14 0
57#define DISABLED_MASK15 0 57#define DISABLED_MASK15 0
58#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE) 58#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE)
59#define DISABLED_MASK17 0
60#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
59 61
60#endif /* _ASM_X86_DISABLED_FEATURES_H */ 62#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/required-features.h b/tools/arch/x86/include/asm/required-features.h
index 4916144e3c42..fac9a5c0abe9 100644
--- a/tools/arch/x86/include/asm/required-features.h
+++ b/tools/arch/x86/include/asm/required-features.h
@@ -99,5 +99,7 @@
99#define REQUIRED_MASK14 0 99#define REQUIRED_MASK14 0
100#define REQUIRED_MASK15 0 100#define REQUIRED_MASK15 0
101#define REQUIRED_MASK16 0 101#define REQUIRED_MASK16 0
102#define REQUIRED_MASK17 0
103#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
102 104
103#endif /* _ASM_X86_REQUIRED_FEATURES_H */ 105#endif /* _ASM_X86_REQUIRED_FEATURES_H */
diff --git a/tools/arch/x86/include/uapi/asm/vmx.h b/tools/arch/x86/include/uapi/asm/vmx.h
index 5b15d94a33f8..37fee272618f 100644
--- a/tools/arch/x86/include/uapi/asm/vmx.h
+++ b/tools/arch/x86/include/uapi/asm/vmx.h
@@ -78,7 +78,6 @@
78#define EXIT_REASON_PML_FULL 62 78#define EXIT_REASON_PML_FULL 62
79#define EXIT_REASON_XSAVES 63 79#define EXIT_REASON_XSAVES 63
80#define EXIT_REASON_XRSTORS 64 80#define EXIT_REASON_XRSTORS 64
81#define EXIT_REASON_PCOMMIT 65
82 81
83#define VMX_EXIT_REASONS \ 82#define VMX_EXIT_REASONS \
84 { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \ 83 { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
@@ -127,8 +126,7 @@
127 { EXIT_REASON_INVVPID, "INVVPID" }, \ 126 { EXIT_REASON_INVVPID, "INVVPID" }, \
128 { EXIT_REASON_INVPCID, "INVPCID" }, \ 127 { EXIT_REASON_INVPCID, "INVPCID" }, \
129 { EXIT_REASON_XSAVES, "XSAVES" }, \ 128 { EXIT_REASON_XSAVES, "XSAVES" }, \
130 { EXIT_REASON_XRSTORS, "XRSTORS" }, \ 129 { EXIT_REASON_XRSTORS, "XRSTORS" }
131 { EXIT_REASON_PCOMMIT, "PCOMMIT" }
132 130
133#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1 131#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1
134#define VMX_ABORT_LOAD_HOST_MSR_FAIL 4 132#define VMX_ABORT_LOAD_HOST_MSR_FAIL 4
diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c
index 448ed96b3b4f..1c14c2595158 100644
--- a/tools/gpio/gpio-event-mon.c
+++ b/tools/gpio/gpio-event-mon.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * gpio-hammer - example swiss army knife to shake GPIO lines on a system 2 * gpio-event-mon - monitor GPIO line events from userspace
3 * 3 *
4 * Copyright (C) 2016 Linus Walleij 4 * Copyright (C) 2016 Linus Walleij
5 * 5 *
diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index b96879477311..f436d2420a18 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -8,7 +8,11 @@ void *memdup(const void *src, size_t len);
8 8
9int strtobool(const char *s, bool *res); 9int strtobool(const char *s, bool *res);
10 10
11#ifdef __GLIBC__ 11/*
12 * glibc based builds needs the extern while uClibc doesn't.
13 * However uClibc headers also define __GLIBC__ hence the hack below
14 */
15#if defined(__GLIBC__) && !defined(__UCLIBC__)
12extern size_t strlcpy(char *dest, const char *src, size_t size); 16extern size_t strlcpy(char *dest, const char *src, size_t size);
13#endif 17#endif
14 18
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 406459b935a2..da218fec6056 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -84,6 +84,7 @@ enum bpf_map_type {
84 BPF_MAP_TYPE_PERCPU_HASH, 84 BPF_MAP_TYPE_PERCPU_HASH,
85 BPF_MAP_TYPE_PERCPU_ARRAY, 85 BPF_MAP_TYPE_PERCPU_ARRAY,
86 BPF_MAP_TYPE_STACK_TRACE, 86 BPF_MAP_TYPE_STACK_TRACE,
87 BPF_MAP_TYPE_CGROUP_ARRAY,
87}; 88};
88 89
89enum bpf_prog_type { 90enum bpf_prog_type {
@@ -93,6 +94,7 @@ enum bpf_prog_type {
93 BPF_PROG_TYPE_SCHED_CLS, 94 BPF_PROG_TYPE_SCHED_CLS,
94 BPF_PROG_TYPE_SCHED_ACT, 95 BPF_PROG_TYPE_SCHED_ACT,
95 BPF_PROG_TYPE_TRACEPOINT, 96 BPF_PROG_TYPE_TRACEPOINT,
97 BPF_PROG_TYPE_XDP,
96}; 98};
97 99
98#define BPF_PSEUDO_MAP_FD 1 100#define BPF_PSEUDO_MAP_FD 1
@@ -313,6 +315,66 @@ enum bpf_func_id {
313 */ 315 */
314 BPF_FUNC_skb_get_tunnel_opt, 316 BPF_FUNC_skb_get_tunnel_opt,
315 BPF_FUNC_skb_set_tunnel_opt, 317 BPF_FUNC_skb_set_tunnel_opt,
318
319 /**
320 * bpf_skb_change_proto(skb, proto, flags)
321 * Change protocol of the skb. Currently supported is
322 * v4 -> v6, v6 -> v4 transitions. The helper will also
323 * resize the skb. eBPF program is expected to fill the
324 * new headers via skb_store_bytes and lX_csum_replace.
325 * @skb: pointer to skb
326 * @proto: new skb->protocol type
327 * @flags: reserved
328 * Return: 0 on success or negative error
329 */
330 BPF_FUNC_skb_change_proto,
331
332 /**
333 * bpf_skb_change_type(skb, type)
334 * Change packet type of skb.
335 * @skb: pointer to skb
336 * @type: new skb->pkt_type type
337 * Return: 0 on success or negative error
338 */
339 BPF_FUNC_skb_change_type,
340
341 /**
342 * bpf_skb_in_cgroup(skb, map, index) - Check cgroup2 membership of skb
343 * @skb: pointer to skb
344 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
345 * @index: index of the cgroup in the bpf_map
346 * Return:
347 * == 0 skb failed the cgroup2 descendant test
348 * == 1 skb succeeded the cgroup2 descendant test
349 * < 0 error
350 */
351 BPF_FUNC_skb_in_cgroup,
352
353 /**
354 * bpf_get_hash_recalc(skb)
355 * Retrieve and possibly recalculate skb->hash.
356 * @skb: pointer to skb
357 * Return: hash
358 */
359 BPF_FUNC_get_hash_recalc,
360
361 /**
362 * u64 bpf_get_current_task(void)
363 * Returns current task_struct
364 * Return: current
365 */
366 BPF_FUNC_get_current_task,
367
368 /**
369 * bpf_probe_write_user(void *dst, void *src, int len)
370 * safely attempt to write to a location
371 * @dst: destination address in userspace
372 * @src: source address on stack
373 * @len: number of bytes to copy
374 * Return: 0 on success or negative error
375 */
376 BPF_FUNC_probe_write_user,
377
316 __BPF_FUNC_MAX_ID, 378 __BPF_FUNC_MAX_ID,
317}; 379};
318 380
@@ -347,9 +409,11 @@ enum bpf_func_id {
347#define BPF_F_ZERO_CSUM_TX (1ULL << 1) 409#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
348#define BPF_F_DONT_FRAGMENT (1ULL << 2) 410#define BPF_F_DONT_FRAGMENT (1ULL << 2)
349 411
350/* BPF_FUNC_perf_event_output flags. */ 412/* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */
351#define BPF_F_INDEX_MASK 0xffffffffULL 413#define BPF_F_INDEX_MASK 0xffffffffULL
352#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK 414#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
415/* BPF_FUNC_perf_event_output for sk_buff input context. */
416#define BPF_F_CTXLEN_MASK (0xfffffULL << 32)
353 417
354/* user accessible mirror of in-kernel sk_buff. 418/* user accessible mirror of in-kernel sk_buff.
355 * new fields can only be added to the end of this structure 419 * new fields can only be added to the end of this structure
@@ -386,4 +450,24 @@ struct bpf_tunnel_key {
386 __u32 tunnel_label; 450 __u32 tunnel_label;
387}; 451};
388 452
453/* User return codes for XDP prog type.
454 * A valid XDP program must return one of these defined values. All other
455 * return codes are reserved for future use. Unknown return codes will result
456 * in packet drop.
457 */
458enum xdp_action {
459 XDP_ABORTED = 0,
460 XDP_DROP,
461 XDP_PASS,
462 XDP_TX,
463};
464
465/* user accessible metadata for XDP packet hook
466 * new fields must be added to the end of this structure
467 */
468struct xdp_md {
469 __u32 data;
470 __u32 data_end;
471};
472
389#endif /* _UAPI__LINUX_BPF_H__ */ 473#endif /* _UAPI__LINUX_BPF_H__ */
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 736da44596e4..b303bcdd8ed1 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,10 +176,18 @@ Each probe argument follows below syntax.
176 176
177'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) 177'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
178'$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters. 178'$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
179'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type. 179'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
180 180
181On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid. 181On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
182 182
183TYPES
184-----
185Basic types (u8/u16/u32/u64/s8/s16/s32/s64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
186String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
187Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
188
189 b<bit-width>@<bit-offset>/<container-size>
190
183LINE SYNTAX 191LINE SYNTAX
184----------- 192-----------
185Line range is described by following syntax. 193Line range is described by following syntax.
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 1f6c70594f0f..053bbbd84ece 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -116,8 +116,8 @@ OPTIONS
116--fields:: 116--fields::
117 Comma separated list of fields to print. Options are: 117 Comma separated list of fields to print. Options are:
118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, 118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119 srcline, period, iregs, brstack, brstacksym, flags. 119 srcline, period, iregs, brstack, brstacksym, flags, bpf-output,
120 Field list can be prepended with the type, trace, sw or hw, 120 callindent. Field list can be prepended with the type, trace, sw or hw,
121 to indicate to which event type the field list applies. 121 to indicate to which event type the field list applies.
122 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace 122 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
123 123
diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index c6d0f91731a1..35745a733100 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -54,10 +54,6 @@ int arch__compare_symbol_names(const char *namea, const char *nameb)
54#endif 54#endif
55 55
56#if defined(_CALL_ELF) && _CALL_ELF == 2 56#if defined(_CALL_ELF) && _CALL_ELF == 2
57bool arch__prefers_symtab(void)
58{
59 return true;
60}
61 57
62#ifdef HAVE_LIBELF_SUPPORT 58#ifdef HAVE_LIBELF_SUPPORT
63void arch__sym_update(struct symbol *s, GElf_Sym *sym) 59void arch__sym_update(struct symbol *s, GElf_Sym *sym)
@@ -100,4 +96,29 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev,
100 tev->point.offset += lep_offset; 96 tev->point.offset += lep_offset;
101 } 97 }
102} 98}
99
100#ifdef HAVE_LIBELF_SUPPORT
101void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
102 int ntevs)
103{
104 struct probe_trace_event *tev;
105 struct map *map;
106 struct symbol *sym = NULL;
107 struct rb_node *tmp;
108 int i = 0;
109
110 map = get_target_map(pev->target, pev->uprobes);
111 if (!map || map__load(map, NULL) < 0)
112 return;
113
114 for (i = 0; i < ntevs; i++) {
115 tev = &pev->tevs[i];
116 map__for_each_symbol(map, sym, tmp) {
117 if (map->unmap_ip(map, sym->start) == tev->point.address)
118 arch__fix_tev_from_maps(pev, tev, map, sym);
119 }
120 }
121}
122#endif /* HAVE_LIBELF_SUPPORT */
123
103#endif 124#endif
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index fb51457ba338..a2412e9d883b 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -501,7 +501,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
501 struct intel_pt_recording *ptr = 501 struct intel_pt_recording *ptr =
502 container_of(itr, struct intel_pt_recording, itr); 502 container_of(itr, struct intel_pt_recording, itr);
503 struct perf_pmu *intel_pt_pmu = ptr->intel_pt_pmu; 503 struct perf_pmu *intel_pt_pmu = ptr->intel_pt_pmu;
504 bool have_timing_info; 504 bool have_timing_info, need_immediate = false;
505 struct perf_evsel *evsel, *intel_pt_evsel = NULL; 505 struct perf_evsel *evsel, *intel_pt_evsel = NULL;
506 const struct cpu_map *cpus = evlist->cpus; 506 const struct cpu_map *cpus = evlist->cpus;
507 bool privileged = geteuid() == 0 || perf_event_paranoid() < 0; 507 bool privileged = geteuid() == 0 || perf_event_paranoid() < 0;
@@ -655,6 +655,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
655 ptr->have_sched_switch = 3; 655 ptr->have_sched_switch = 3;
656 } else { 656 } else {
657 opts->record_switch_events = true; 657 opts->record_switch_events = true;
658 need_immediate = true;
658 if (cpu_wide) 659 if (cpu_wide)
659 ptr->have_sched_switch = 3; 660 ptr->have_sched_switch = 3;
660 else 661 else
@@ -700,6 +701,9 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
700 tracking_evsel->attr.freq = 0; 701 tracking_evsel->attr.freq = 0;
701 tracking_evsel->attr.sample_period = 1; 702 tracking_evsel->attr.sample_period = 1;
702 703
704 if (need_immediate)
705 tracking_evsel->immediate = true;
706
703 /* In per-cpu case, always need the time of mmap events etc */ 707 /* In per-cpu case, always need the time of mmap events etc */
704 if (!cpu_map__empty(cpus)) { 708 if (!cpu_map__empty(cpus)) {
705 perf_evsel__set_sample_bit(tracking_evsel, TIME); 709 perf_evsel__set_sample_bit(tracking_evsel, TIME);
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index d608a2c9e48c..d1ce29be560e 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -88,6 +88,9 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
88 if (mem->operation & MEM_OPERATION_LOAD) 88 if (mem->operation & MEM_OPERATION_LOAD)
89 perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true; 89 perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true;
90 90
91 if (mem->operation & MEM_OPERATION_STORE)
92 perf_mem_events[PERF_MEM_EVENTS__STORE].record = true;
93
91 if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record) 94 if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record)
92 rec_argv[i++] = "-W"; 95 rec_argv[i++] = "-W";
93 96
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 971ff91b16cb..c859e59dfe3e 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -371,14 +371,16 @@ static int perf_session__check_output_opt(struct perf_session *session)
371 371
372 if (!no_callchain) { 372 if (!no_callchain) {
373 bool use_callchain = false; 373 bool use_callchain = false;
374 bool not_pipe = false;
374 375
375 evlist__for_each_entry(session->evlist, evsel) { 376 evlist__for_each_entry(session->evlist, evsel) {
377 not_pipe = true;
376 if (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) { 378 if (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) {
377 use_callchain = true; 379 use_callchain = true;
378 break; 380 break;
379 } 381 }
380 } 382 }
381 if (!use_callchain) 383 if (not_pipe && !use_callchain)
382 symbol_conf.use_callchain = false; 384 symbol_conf.use_callchain = false;
383 } 385 }
384 386
@@ -1690,8 +1692,13 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
1690 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); 1692 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
1691 1693
1692 scripts_dir = opendir(scripts_path); 1694 scripts_dir = opendir(scripts_path);
1693 if (!scripts_dir) 1695 if (!scripts_dir) {
1694 return -1; 1696 fprintf(stdout,
1697 "open(%s) failed.\n"
1698 "Check \"PERF_EXEC_PATH\" env to set scripts dir.\n",
1699 scripts_path);
1700 exit(-1);
1701 }
1695 1702
1696 for_each_lang(scripts_path, scripts_dir, lang_dirent) { 1703 for_each_lang(scripts_path, scripts_dir, lang_dirent) {
1697 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, 1704 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
@@ -2116,7 +2123,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
2116 "Valid types: hw,sw,trace,raw. " 2123 "Valid types: hw,sw,trace,raw. "
2117 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," 2124 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
2118 "addr,symoff,period,iregs,brstack,brstacksym,flags," 2125 "addr,symoff,period,iregs,brstack,brstacksym,flags,"
2119 "callindent", parse_output_fields), 2126 "bpf-output,callindent", parse_output_fields),
2120 OPT_BOOLEAN('a', "all-cpus", &system_wide, 2127 OPT_BOOLEAN('a', "all-cpus", &system_wide,
2121 "system-wide collection from all CPUs"), 2128 "system-wide collection from all CPUs"),
2122 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", 2129 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 0c16d20d7e32..3c7452b39f57 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -331,7 +331,7 @@ static int read_counter(struct perf_evsel *counter)
331 return 0; 331 return 0;
332} 332}
333 333
334static void read_counters(bool close_counters) 334static void read_counters(void)
335{ 335{
336 struct perf_evsel *counter; 336 struct perf_evsel *counter;
337 337
@@ -341,11 +341,6 @@ static void read_counters(bool close_counters)
341 341
342 if (perf_stat_process_counter(&stat_config, counter)) 342 if (perf_stat_process_counter(&stat_config, counter))
343 pr_warning("failed to process counter %s\n", counter->name); 343 pr_warning("failed to process counter %s\n", counter->name);
344
345 if (close_counters) {
346 perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter),
347 thread_map__nr(evsel_list->threads));
348 }
349 } 344 }
350} 345}
351 346
@@ -353,7 +348,7 @@ static void process_interval(void)
353{ 348{
354 struct timespec ts, rs; 349 struct timespec ts, rs;
355 350
356 read_counters(false); 351 read_counters();
357 352
358 clock_gettime(CLOCK_MONOTONIC, &ts); 353 clock_gettime(CLOCK_MONOTONIC, &ts);
359 diff_timespec(&rs, &ts, &ref_time); 354 diff_timespec(&rs, &ts, &ref_time);
@@ -380,6 +375,17 @@ static void enable_counters(void)
380 perf_evlist__enable(evsel_list); 375 perf_evlist__enable(evsel_list);
381} 376}
382 377
378static void disable_counters(void)
379{
380 /*
381 * If we don't have tracee (attaching to task or cpu), counters may
382 * still be running. To get accurate group ratios, we must stop groups
383 * from counting before reading their constituent counters.
384 */
385 if (!target__none(&target))
386 perf_evlist__disable(evsel_list);
387}
388
383static volatile int workload_exec_errno; 389static volatile int workload_exec_errno;
384 390
385/* 391/*
@@ -657,11 +663,20 @@ try_again:
657 } 663 }
658 } 664 }
659 665
666 disable_counters();
667
660 t1 = rdclock(); 668 t1 = rdclock();
661 669
662 update_stats(&walltime_nsecs_stats, t1 - t0); 670 update_stats(&walltime_nsecs_stats, t1 - t0);
663 671
664 read_counters(true); 672 /*
673 * Closing a group leader splits the group, and as we only disable
674 * group leaders, results in remaining events becoming enabled. To
675 * avoid arbitrary skew, we must read all counters before closing any
676 * group leaders.
677 */
678 read_counters();
679 perf_evlist__close(evsel_list);
665 680
666 return WEXITSTATUS(status); 681 return WEXITSTATUS(status);
667} 682}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d9b80ef881cd..21fd573106ed 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -507,17 +507,17 @@ static int __perf_evsel__hw_cache_name(u64 config, char *bf, size_t size)
507 u8 op, result, type = (config >> 0) & 0xff; 507 u8 op, result, type = (config >> 0) & 0xff;
508 const char *err = "unknown-ext-hardware-cache-type"; 508 const char *err = "unknown-ext-hardware-cache-type";
509 509
510 if (type > PERF_COUNT_HW_CACHE_MAX) 510 if (type >= PERF_COUNT_HW_CACHE_MAX)
511 goto out_err; 511 goto out_err;
512 512
513 op = (config >> 8) & 0xff; 513 op = (config >> 8) & 0xff;
514 err = "unknown-ext-hardware-cache-op"; 514 err = "unknown-ext-hardware-cache-op";
515 if (op > PERF_COUNT_HW_CACHE_OP_MAX) 515 if (op >= PERF_COUNT_HW_CACHE_OP_MAX)
516 goto out_err; 516 goto out_err;
517 517
518 result = (config >> 16) & 0xff; 518 result = (config >> 16) & 0xff;
519 err = "unknown-ext-hardware-cache-result"; 519 err = "unknown-ext-hardware-cache-result";
520 if (result > PERF_COUNT_HW_CACHE_RESULT_MAX) 520 if (result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
521 goto out_err; 521 goto out_err;
522 522
523 err = "invalid-cache"; 523 err = "invalid-cache";
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 9c8f15da86ce..8ff6c6a61291 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -123,8 +123,6 @@ struct intel_pt_decoder {
123 bool have_calc_cyc_to_tsc; 123 bool have_calc_cyc_to_tsc;
124 int exec_mode; 124 int exec_mode;
125 unsigned int insn_bytes; 125 unsigned int insn_bytes;
126 uint64_t sign_bit;
127 uint64_t sign_bits;
128 uint64_t period; 126 uint64_t period;
129 enum intel_pt_period_type period_type; 127 enum intel_pt_period_type period_type;
130 uint64_t tot_insn_cnt; 128 uint64_t tot_insn_cnt;
@@ -191,9 +189,6 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
191 decoder->data = params->data; 189 decoder->data = params->data;
192 decoder->return_compression = params->return_compression; 190 decoder->return_compression = params->return_compression;
193 191
194 decoder->sign_bit = (uint64_t)1 << 47;
195 decoder->sign_bits = ~(((uint64_t)1 << 48) - 1);
196
197 decoder->period = params->period; 192 decoder->period = params->period;
198 decoder->period_type = params->period_type; 193 decoder->period_type = params->period_type;
199 194
@@ -362,21 +357,30 @@ int intel_pt__strerror(int code, char *buf, size_t buflen)
362 return 0; 357 return 0;
363} 358}
364 359
365static uint64_t intel_pt_calc_ip(struct intel_pt_decoder *decoder, 360static uint64_t intel_pt_calc_ip(const struct intel_pt_pkt *packet,
366 const struct intel_pt_pkt *packet,
367 uint64_t last_ip) 361 uint64_t last_ip)
368{ 362{
369 uint64_t ip; 363 uint64_t ip;
370 364
371 switch (packet->count) { 365 switch (packet->count) {
372 case 2: 366 case 1:
373 ip = (last_ip & (uint64_t)0xffffffffffff0000ULL) | 367 ip = (last_ip & (uint64_t)0xffffffffffff0000ULL) |
374 packet->payload; 368 packet->payload;
375 break; 369 break;
376 case 4: 370 case 2:
377 ip = (last_ip & (uint64_t)0xffffffff00000000ULL) | 371 ip = (last_ip & (uint64_t)0xffffffff00000000ULL) |
378 packet->payload; 372 packet->payload;
379 break; 373 break;
374 case 3:
375 ip = packet->payload;
376 /* Sign-extend 6-byte ip */
377 if (ip & (uint64_t)0x800000000000ULL)
378 ip |= (uint64_t)0xffff000000000000ULL;
379 break;
380 case 4:
381 ip = (last_ip & (uint64_t)0xffff000000000000ULL) |
382 packet->payload;
383 break;
380 case 6: 384 case 6:
381 ip = packet->payload; 385 ip = packet->payload;
382 break; 386 break;
@@ -384,16 +388,12 @@ static uint64_t intel_pt_calc_ip(struct intel_pt_decoder *decoder,
384 return 0; 388 return 0;
385 } 389 }
386 390
387 if (ip & decoder->sign_bit)
388 return ip | decoder->sign_bits;
389
390 return ip; 391 return ip;
391} 392}
392 393
393static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder) 394static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder)
394{ 395{
395 decoder->last_ip = intel_pt_calc_ip(decoder, &decoder->packet, 396 decoder->last_ip = intel_pt_calc_ip(&decoder->packet, decoder->last_ip);
396 decoder->last_ip);
397} 397}
398 398
399static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder) 399static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder)
@@ -1657,6 +1657,12 @@ next:
1657 } 1657 }
1658} 1658}
1659 1659
1660static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder)
1661{
1662 return decoder->last_ip || decoder->packet.count == 0 ||
1663 decoder->packet.count == 3 || decoder->packet.count == 6;
1664}
1665
1660/* Walk PSB+ packets to get in sync. */ 1666/* Walk PSB+ packets to get in sync. */
1661static int intel_pt_walk_psb(struct intel_pt_decoder *decoder) 1667static int intel_pt_walk_psb(struct intel_pt_decoder *decoder)
1662{ 1668{
@@ -1677,8 +1683,7 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder)
1677 1683
1678 case INTEL_PT_FUP: 1684 case INTEL_PT_FUP:
1679 decoder->pge = true; 1685 decoder->pge = true;
1680 if (decoder->last_ip || decoder->packet.count == 6 || 1686 if (intel_pt_have_ip(decoder)) {
1681 decoder->packet.count == 0) {
1682 uint64_t current_ip = decoder->ip; 1687 uint64_t current_ip = decoder->ip;
1683 1688
1684 intel_pt_set_ip(decoder); 1689 intel_pt_set_ip(decoder);
@@ -1767,8 +1772,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
1767 case INTEL_PT_TIP_PGE: 1772 case INTEL_PT_TIP_PGE:
1768 case INTEL_PT_TIP: 1773 case INTEL_PT_TIP:
1769 decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD; 1774 decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD;
1770 if (decoder->last_ip || decoder->packet.count == 6 || 1775 if (intel_pt_have_ip(decoder))
1771 decoder->packet.count == 0)
1772 intel_pt_set_ip(decoder); 1776 intel_pt_set_ip(decoder);
1773 if (decoder->ip) 1777 if (decoder->ip)
1774 return 0; 1778 return 0;
@@ -1776,9 +1780,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
1776 1780
1777 case INTEL_PT_FUP: 1781 case INTEL_PT_FUP:
1778 if (decoder->overflow) { 1782 if (decoder->overflow) {
1779 if (decoder->last_ip || 1783 if (intel_pt_have_ip(decoder))
1780 decoder->packet.count == 6 ||
1781 decoder->packet.count == 0)
1782 intel_pt_set_ip(decoder); 1784 intel_pt_set_ip(decoder);
1783 if (decoder->ip) 1785 if (decoder->ip)
1784 return 0; 1786 return 0;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index b1257c816310..4f7b32020487 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -292,36 +292,46 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte,
292 const unsigned char *buf, size_t len, 292 const unsigned char *buf, size_t len,
293 struct intel_pt_pkt *packet) 293 struct intel_pt_pkt *packet)
294{ 294{
295 switch (byte >> 5) { 295 int ip_len;
296
297 packet->count = byte >> 5;
298
299 switch (packet->count) {
296 case 0: 300 case 0:
297 packet->count = 0; 301 ip_len = 0;
298 break; 302 break;
299 case 1: 303 case 1:
300 if (len < 3) 304 if (len < 3)
301 return INTEL_PT_NEED_MORE_BYTES; 305 return INTEL_PT_NEED_MORE_BYTES;
302 packet->count = 2; 306 ip_len = 2;
303 packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1)); 307 packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1));
304 break; 308 break;
305 case 2: 309 case 2:
306 if (len < 5) 310 if (len < 5)
307 return INTEL_PT_NEED_MORE_BYTES; 311 return INTEL_PT_NEED_MORE_BYTES;
308 packet->count = 4; 312 ip_len = 4;
309 packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1)); 313 packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1));
310 break; 314 break;
311 case 3: 315 case 3:
312 case 6: 316 case 4:
313 if (len < 7) 317 if (len < 7)
314 return INTEL_PT_NEED_MORE_BYTES; 318 return INTEL_PT_NEED_MORE_BYTES;
315 packet->count = 6; 319 ip_len = 6;
316 memcpy_le64(&packet->payload, buf + 1, 6); 320 memcpy_le64(&packet->payload, buf + 1, 6);
317 break; 321 break;
322 case 6:
323 if (len < 9)
324 return INTEL_PT_NEED_MORE_BYTES;
325 ip_len = 8;
326 packet->payload = le64_to_cpu(*(uint64_t *)(buf + 1));
327 break;
318 default: 328 default:
319 return INTEL_PT_BAD_PACKET; 329 return INTEL_PT_BAD_PACKET;
320 } 330 }
321 331
322 packet->type = type; 332 packet->type = type;
323 333
324 return packet->count + 1; 334 return ip_len + 1;
325} 335}
326 336
327static int intel_pt_get_mode(const unsigned char *buf, size_t len, 337static int intel_pt_get_mode(const unsigned char *buf, size_t len,
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 9f3305f6b6d5..95f0884aae02 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -1,3 +1,4 @@
1#include <sys/sysmacros.h>
1#include <sys/types.h> 2#include <sys/types.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdlib.h> 4#include <stdlib.h>
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 953dc1ab2ed7..28733962cd80 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -170,15 +170,17 @@ static struct map *kernel_get_module_map(const char *module)
170 module = "kernel"; 170 module = "kernel";
171 171
172 for (pos = maps__first(maps); pos; pos = map__next(pos)) { 172 for (pos = maps__first(maps); pos; pos = map__next(pos)) {
173 /* short_name is "[module]" */
173 if (strncmp(pos->dso->short_name + 1, module, 174 if (strncmp(pos->dso->short_name + 1, module,
174 pos->dso->short_name_len - 2) == 0) { 175 pos->dso->short_name_len - 2) == 0 &&
176 module[pos->dso->short_name_len - 2] == '\0') {
175 return pos; 177 return pos;
176 } 178 }
177 } 179 }
178 return NULL; 180 return NULL;
179} 181}
180 182
181static struct map *get_target_map(const char *target, bool user) 183struct map *get_target_map(const char *target, bool user)
182{ 184{
183 /* Init maps of given executable or kernel */ 185 /* Init maps of given executable or kernel */
184 if (user) 186 if (user)
@@ -385,7 +387,7 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
385 if (uprobes) 387 if (uprobes)
386 address = sym->start; 388 address = sym->start;
387 else 389 else
388 address = map->unmap_ip(map, sym->start); 390 address = map->unmap_ip(map, sym->start) - map->reloc;
389 break; 391 break;
390 } 392 }
391 if (!address) { 393 if (!address) {
@@ -664,22 +666,14 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
664 return ret; 666 return ret;
665} 667}
666 668
667/* Post processing the probe events */ 669static int
668static int post_process_probe_trace_events(struct probe_trace_event *tevs, 670post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
669 int ntevs, const char *module, 671 int ntevs)
670 bool uprobe)
671{ 672{
672 struct ref_reloc_sym *reloc_sym; 673 struct ref_reloc_sym *reloc_sym;
673 char *tmp; 674 char *tmp;
674 int i, skipped = 0; 675 int i, skipped = 0;
675 676
676 if (uprobe)
677 return add_exec_to_probe_trace_events(tevs, ntevs, module);
678
679 /* Note that currently ref_reloc_sym based probe is not for drivers */
680 if (module)
681 return add_module_to_probe_trace_events(tevs, ntevs, module);
682
683 reloc_sym = kernel_get_ref_reloc_sym(); 677 reloc_sym = kernel_get_ref_reloc_sym();
684 if (!reloc_sym) { 678 if (!reloc_sym) {
685 pr_warning("Relocated base symbol is not found!\n"); 679 pr_warning("Relocated base symbol is not found!\n");
@@ -711,6 +705,34 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
711 return skipped; 705 return skipped;
712} 706}
713 707
708void __weak
709arch__post_process_probe_trace_events(struct perf_probe_event *pev __maybe_unused,
710 int ntevs __maybe_unused)
711{
712}
713
714/* Post processing the probe events */
715static int post_process_probe_trace_events(struct perf_probe_event *pev,
716 struct probe_trace_event *tevs,
717 int ntevs, const char *module,
718 bool uprobe)
719{
720 int ret;
721
722 if (uprobe)
723 ret = add_exec_to_probe_trace_events(tevs, ntevs, module);
724 else if (module)
725 /* Currently ref_reloc_sym based probe is not for drivers */
726 ret = add_module_to_probe_trace_events(tevs, ntevs, module);
727 else
728 ret = post_process_kernel_probe_trace_events(tevs, ntevs);
729
730 if (ret >= 0)
731 arch__post_process_probe_trace_events(pev, ntevs);
732
733 return ret;
734}
735
714/* Try to find perf_probe_event with debuginfo */ 736/* Try to find perf_probe_event with debuginfo */
715static int try_to_find_probe_trace_events(struct perf_probe_event *pev, 737static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
716 struct probe_trace_event **tevs) 738 struct probe_trace_event **tevs)
@@ -749,7 +771,7 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
749 771
750 if (ntevs > 0) { /* Succeeded to find trace events */ 772 if (ntevs > 0) { /* Succeeded to find trace events */
751 pr_debug("Found %d probe_trace_events.\n", ntevs); 773 pr_debug("Found %d probe_trace_events.\n", ntevs);
752 ret = post_process_probe_trace_events(*tevs, ntevs, 774 ret = post_process_probe_trace_events(pev, *tevs, ntevs,
753 pev->target, pev->uprobes); 775 pev->target, pev->uprobes);
754 if (ret < 0 || ret == ntevs) { 776 if (ret < 0 || ret == ntevs) {
755 clear_probe_trace_events(*tevs, ntevs); 777 clear_probe_trace_events(*tevs, ntevs);
@@ -2936,8 +2958,6 @@ errout:
2936 return err; 2958 return err;
2937} 2959}
2938 2960
2939bool __weak arch__prefers_symtab(void) { return false; }
2940
2941/* Concatinate two arrays */ 2961/* Concatinate two arrays */
2942static void *memcat(void *a, size_t sz_a, void *b, size_t sz_b) 2962static void *memcat(void *a, size_t sz_a, void *b, size_t sz_b)
2943{ 2963{
@@ -3158,12 +3178,6 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
3158 if (ret > 0 || pev->sdt) /* SDT can be found only in the cache */ 3178 if (ret > 0 || pev->sdt) /* SDT can be found only in the cache */
3159 return ret == 0 ? -ENOENT : ret; /* Found in probe cache */ 3179 return ret == 0 ? -ENOENT : ret; /* Found in probe cache */
3160 3180
3161 if (arch__prefers_symtab() && !perf_probe_event_need_dwarf(pev)) {
3162 ret = find_probe_trace_events_from_map(pev, tevs);
3163 if (ret > 0)
3164 return ret; /* Found in symbol table */
3165 }
3166
3167 /* Convert perf_probe_event with debuginfo */ 3181 /* Convert perf_probe_event with debuginfo */
3168 ret = try_to_find_probe_trace_events(pev, tevs); 3182 ret = try_to_find_probe_trace_events(pev, tevs);
3169 if (ret != 0) 3183 if (ret != 0)
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index e18ea9fe6385..f4f45db77c1c 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -158,7 +158,6 @@ int show_line_range(struct line_range *lr, const char *module, bool user);
158int show_available_vars(struct perf_probe_event *pevs, int npevs, 158int show_available_vars(struct perf_probe_event *pevs, int npevs,
159 struct strfilter *filter); 159 struct strfilter *filter);
160int show_available_funcs(const char *module, struct strfilter *filter, bool user); 160int show_available_funcs(const char *module, struct strfilter *filter, bool user);
161bool arch__prefers_symtab(void);
162void arch__fix_tev_from_maps(struct perf_probe_event *pev, 161void arch__fix_tev_from_maps(struct perf_probe_event *pev,
163 struct probe_trace_event *tev, struct map *map, 162 struct probe_trace_event *tev, struct map *map,
164 struct symbol *sym); 163 struct symbol *sym);
@@ -173,4 +172,9 @@ int e_snprintf(char *str, size_t size, const char *format, ...)
173int copy_to_probe_trace_arg(struct probe_trace_arg *tvar, 172int copy_to_probe_trace_arg(struct probe_trace_arg *tvar,
174 struct perf_probe_arg *pvar); 173 struct perf_probe_arg *pvar);
175 174
175struct map *get_target_map(const char *target, bool user);
176
177void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
178 int ntevs);
179
176#endif /*_PROBE_EVENT_H */ 180#endif /*_PROBE_EVENT_H */
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 9aed9c332da6..9c3b9ed5b3c3 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -133,7 +133,7 @@ int probe_file__open_both(int *kfd, int *ufd, int flag)
133/* Get raw string list of current kprobe_events or uprobe_events */ 133/* Get raw string list of current kprobe_events or uprobe_events */
134struct strlist *probe_file__get_rawlist(int fd) 134struct strlist *probe_file__get_rawlist(int fd)
135{ 135{
136 int ret, idx; 136 int ret, idx, fddup;
137 FILE *fp; 137 FILE *fp;
138 char buf[MAX_CMDLEN]; 138 char buf[MAX_CMDLEN];
139 char *p; 139 char *p;
@@ -143,8 +143,17 @@ struct strlist *probe_file__get_rawlist(int fd)
143 return NULL; 143 return NULL;
144 144
145 sl = strlist__new(NULL, NULL); 145 sl = strlist__new(NULL, NULL);
146 if (sl == NULL)
147 return NULL;
148
149 fddup = dup(fd);
150 if (fddup < 0)
151 goto out_free_sl;
152
153 fp = fdopen(fddup, "r");
154 if (!fp)
155 goto out_close_fddup;
146 156
147 fp = fdopen(dup(fd), "r");
148 while (!feof(fp)) { 157 while (!feof(fp)) {
149 p = fgets(buf, MAX_CMDLEN, fp); 158 p = fgets(buf, MAX_CMDLEN, fp);
150 if (!p) 159 if (!p)
@@ -156,13 +165,21 @@ struct strlist *probe_file__get_rawlist(int fd)
156 ret = strlist__add(sl, buf); 165 ret = strlist__add(sl, buf);
157 if (ret < 0) { 166 if (ret < 0) {
158 pr_debug("strlist__add failed (%d)\n", ret); 167 pr_debug("strlist__add failed (%d)\n", ret);
159 strlist__delete(sl); 168 goto out_close_fp;
160 return NULL;
161 } 169 }
162 } 170 }
163 fclose(fp); 171 fclose(fp);
164 172
165 return sl; 173 return sl;
174
175out_close_fp:
176 fclose(fp);
177 goto out_free_sl;
178out_close_fddup:
179 close(fddup);
180out_free_sl:
181 strlist__delete(sl);
182 return NULL;
166} 183}
167 184
168static struct strlist *__probe_file__get_namelist(int fd, bool include_group) 185static struct strlist *__probe_file__get_namelist(int fd, bool include_group)
@@ -447,12 +464,17 @@ static int probe_cache__load(struct probe_cache *pcache)
447{ 464{
448 struct probe_cache_entry *entry = NULL; 465 struct probe_cache_entry *entry = NULL;
449 char buf[MAX_CMDLEN], *p; 466 char buf[MAX_CMDLEN], *p;
450 int ret = 0; 467 int ret = 0, fddup;
451 FILE *fp; 468 FILE *fp;
452 469
453 fp = fdopen(dup(pcache->fd), "r"); 470 fddup = dup(pcache->fd);
454 if (!fp) 471 if (fddup < 0)
472 return -errno;
473 fp = fdopen(fddup, "r");
474 if (!fp) {
475 close(fddup);
455 return -EINVAL; 476 return -EINVAL;
477 }
456 478
457 while (!feof(fp)) { 479 while (!feof(fp)) {
458 if (!fgets(buf, MAX_CMDLEN, fp)) 480 if (!fgets(buf, MAX_CMDLEN, fp))
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index f2d9ff064e2d..5c290c682afe 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -297,10 +297,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,
297 char sbuf[STRERR_BUFSIZE]; 297 char sbuf[STRERR_BUFSIZE];
298 int bsize, boffs, total; 298 int bsize, boffs, total;
299 int ret; 299 int ret;
300 char sign;
300 301
301 /* TODO: check all types */ 302 /* TODO: check all types */
302 if (cast && strcmp(cast, "string") != 0) { 303 if (cast && strcmp(cast, "string") != 0 &&
304 strcmp(cast, "s") != 0 && strcmp(cast, "u") != 0) {
303 /* Non string type is OK */ 305 /* Non string type is OK */
306 /* and respect signedness cast */
304 tvar->type = strdup(cast); 307 tvar->type = strdup(cast);
305 return (tvar->type == NULL) ? -ENOMEM : 0; 308 return (tvar->type == NULL) ? -ENOMEM : 0;
306 } 309 }
@@ -361,6 +364,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,
361 return (tvar->type == NULL) ? -ENOMEM : 0; 364 return (tvar->type == NULL) ? -ENOMEM : 0;
362 } 365 }
363 366
367 if (cast && (strcmp(cast, "u") == 0))
368 sign = 'u';
369 else if (cast && (strcmp(cast, "s") == 0))
370 sign = 's';
371 else
372 sign = die_is_signed_type(&type) ? 's' : 'u';
373
364 ret = dwarf_bytesize(&type); 374 ret = dwarf_bytesize(&type);
365 if (ret <= 0) 375 if (ret <= 0)
366 /* No size ... try to use default type */ 376 /* No size ... try to use default type */
@@ -373,8 +383,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
373 dwarf_diename(&type), MAX_BASIC_TYPE_BITS); 383 dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
374 ret = MAX_BASIC_TYPE_BITS; 384 ret = MAX_BASIC_TYPE_BITS;
375 } 385 }
376 ret = snprintf(buf, 16, "%c%d", 386 ret = snprintf(buf, 16, "%c%d", sign, ret);
377 die_is_signed_type(&type) ? 's' : 'u', ret);
378 387
379formatted: 388formatted:
380 if (ret < 0 || ret >= 16) { 389 if (ret < 0 || ret >= 16) {
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 947d21f38398..3d3cb8392c86 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -588,7 +588,11 @@ static char *get_trace_output(struct hist_entry *he)
588 } else { 588 } else {
589 pevent_event_info(&seq, evsel->tp_format, &rec); 589 pevent_event_info(&seq, evsel->tp_format, &rec);
590 } 590 }
591 return seq.buffer; 591 /*
592 * Trim the buffer, it starts at 4KB and we're not going to
593 * add anything more to this buffer.
594 */
595 return realloc(seq.buffer, seq.len + 1);
592} 596}
593 597
594static int64_t 598static int64_t
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index a34321e9b44d..a811c13a74d6 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -837,7 +837,8 @@ int dso__load_sym(struct dso *dso, struct map *map,
837 sec = syms_ss->symtab; 837 sec = syms_ss->symtab;
838 shdr = syms_ss->symshdr; 838 shdr = syms_ss->symshdr;
839 839
840 if (elf_section_by_name(elf, &ehdr, &tshdr, ".text", NULL)) 840 if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr,
841 ".text", NULL))
841 dso->text_offset = tshdr.sh_addr - tshdr.sh_offset; 842 dso->text_offset = tshdr.sh_addr - tshdr.sh_offset;
842 843
843 if (runtime_ss->opdsec) 844 if (runtime_ss->opdsec)
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index cf5e250bc78e..783a53fb7a4e 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -66,7 +66,7 @@ static int entry(u64 ip, struct unwind_info *ui)
66 if (__report_module(&al, ip, ui)) 66 if (__report_module(&al, ip, ui))
67 return -1; 67 return -1;
68 68
69 e->ip = ip; 69 e->ip = al.addr;
70 e->map = al.map; 70 e->map = al.map;
71 e->sym = al.sym; 71 e->sym = al.sym;
72 72
diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 97c0f8fc5561..20c2e5743903 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -542,7 +542,7 @@ static int entry(u64 ip, struct thread *thread,
542 thread__find_addr_location(thread, PERF_RECORD_MISC_USER, 542 thread__find_addr_location(thread, PERF_RECORD_MISC_USER,
543 MAP__FUNCTION, ip, &al); 543 MAP__FUNCTION, ip, &al);
544 544
545 e.ip = ip; 545 e.ip = al.addr;
546 e.map = al.map; 546 e.map = al.map;
547 e.sym = al.sym; 547 e.sym = al.sym;
548 548
diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c
index 5404efa578a3..dd48f421844c 100644
--- a/tools/testing/nvdimm/test/nfit.c
+++ b/tools/testing/nvdimm/test/nfit.c
@@ -13,6 +13,7 @@
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/dma-mapping.h> 15#include <linux/dma-mapping.h>
16#include <linux/workqueue.h>
16#include <linux/libnvdimm.h> 17#include <linux/libnvdimm.h>
17#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
18#include <linux/device.h> 19#include <linux/device.h>
@@ -1474,6 +1475,7 @@ static int nfit_test_probe(struct platform_device *pdev)
1474 if (nfit_test->setup != nfit_test0_setup) 1475 if (nfit_test->setup != nfit_test0_setup)
1475 return 0; 1476 return 0;
1476 1477
1478 flush_work(&acpi_desc->work);
1477 nfit_test->setup_hotplug = 1; 1479 nfit_test->setup_hotplug = 1;
1478 nfit_test->setup(nfit_test); 1480 nfit_test->setup(nfit_test);
1479 1481
diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
index 3c40c9d0e6c7..1cc6d64c39b7 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -8,7 +8,7 @@ ifeq ($(ARCH),powerpc)
8 8
9GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown") 9GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown")
10 10
11CFLAGS := -Wall -O2 -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CURDIR) $(CFLAGS) 11CFLAGS := -std=gnu99 -Wall -O2 -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CURDIR) $(CFLAGS)
12 12
13export CFLAGS 13export CFLAGS
14 14
diff --git a/tools/virtio/linux/dma-mapping.h b/tools/virtio/linux/dma-mapping.h
index 4f93af89ae16..18601f6689b9 100644
--- a/tools/virtio/linux/dma-mapping.h
+++ b/tools/virtio/linux/dma-mapping.h
@@ -14,4 +14,20 @@ enum dma_data_direction {
14 DMA_NONE = 3, 14 DMA_NONE = 3,
15}; 15};
16 16
17#define dma_alloc_coherent(d, s, hp, f) ({ \
18 void *__dma_alloc_coherent_p = kmalloc((s), (f)); \
19 *(hp) = (unsigned long)__dma_alloc_coherent_p; \
20 __dma_alloc_coherent_p; \
21})
22
23#define dma_free_coherent(d, s, p, h) kfree(p)
24
25#define dma_map_page(d, p, o, s, dir) (page_to_phys(p) + (o))
26
27#define dma_map_single(d, p, s, dir) (virt_to_phys(p))
28#define dma_mapping_error(...) (0)
29
30#define dma_unmap_single(...) do { } while (0)
31#define dma_unmap_page(...) do { } while (0)
32
17#endif 33#endif
diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h
index 033849948215..d9554fc3f340 100644
--- a/tools/virtio/linux/kernel.h
+++ b/tools/virtio/linux/kernel.h
@@ -20,7 +20,9 @@
20 20
21#define PAGE_SIZE getpagesize() 21#define PAGE_SIZE getpagesize()
22#define PAGE_MASK (~(PAGE_SIZE-1)) 22#define PAGE_MASK (~(PAGE_SIZE-1))
23#define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
23 24
25typedef unsigned long long phys_addr_t;
24typedef unsigned long long dma_addr_t; 26typedef unsigned long long dma_addr_t;
25typedef size_t __kernel_size_t; 27typedef size_t __kernel_size_t;
26typedef unsigned int __wsum; 28typedef unsigned int __wsum;
@@ -57,6 +59,11 @@ static inline void *kzalloc(size_t s, gfp_t gfp)
57 return p; 59 return p;
58} 60}
59 61
62static inline void *alloc_pages_exact(size_t s, gfp_t gfp)
63{
64 return kmalloc(s, gfp);
65}
66
60static inline void kfree(void *p) 67static inline void kfree(void *p)
61{ 68{
62 if (p >= __kfree_ignore_start && p < __kfree_ignore_end) 69 if (p >= __kfree_ignore_start && p < __kfree_ignore_end)
@@ -64,6 +71,11 @@ static inline void kfree(void *p)
64 free(p); 71 free(p);
65} 72}
66 73
74static inline void free_pages_exact(void *p, size_t s)
75{
76 kfree(p);
77}
78
67static inline void *krealloc(void *p, size_t s, gfp_t gfp) 79static inline void *krealloc(void *p, size_t s, gfp_t gfp)
68{ 80{
69 return realloc(p, s); 81 return realloc(p, s);
@@ -105,6 +117,8 @@ static inline void free_page(unsigned long addr)
105#define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) 117#define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
106#define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__) 118#define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
107 119
120#define WARN_ON_ONCE(cond) ((cond) && fprintf (stderr, "WARNING\n"))
121
108#define min(x, y) ({ \ 122#define min(x, y) ({ \
109 typeof(x) _min1 = (x); \ 123 typeof(x) _min1 = (x); \
110 typeof(y) _min2 = (y); \ 124 typeof(y) _min2 = (y); \
diff --git a/tools/virtio/linux/slab.h b/tools/virtio/linux/slab.h
index 81baeac8ae40..7e1c1197d439 100644
--- a/tools/virtio/linux/slab.h
+++ b/tools/virtio/linux/slab.h
@@ -1,2 +1,6 @@
1#ifndef LINUX_SLAB_H 1#ifndef LINUX_SLAB_H
2#define GFP_KERNEL 0
3#define GFP_ATOMIC 0
4#define __GFP_NOWARN 0
5#define __GFP_ZERO 0
2#endif 6#endif
diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h
index ee125e714053..9377c8b4ac16 100644
--- a/tools/virtio/linux/virtio.h
+++ b/tools/virtio/linux/virtio.h
@@ -3,8 +3,12 @@
3#include <linux/scatterlist.h> 3#include <linux/scatterlist.h>
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5 5
6struct device {
7 void *parent;
8};
9
6struct virtio_device { 10struct virtio_device {
7 void *dev; 11 struct device dev;
8 u64 features; 12 u64 features;
9}; 13};
10 14
diff --git a/tools/virtio/linux/virtio_config.h b/tools/virtio/linux/virtio_config.h
index 57a6964a1e35..9ba11815e0a1 100644
--- a/tools/virtio/linux/virtio_config.h
+++ b/tools/virtio/linux/virtio_config.h
@@ -40,6 +40,19 @@ static inline void __virtio_clear_bit(struct virtio_device *vdev,
40#define virtio_has_feature(dev, feature) \ 40#define virtio_has_feature(dev, feature) \
41 (__virtio_test_bit((dev), feature)) 41 (__virtio_test_bit((dev), feature))
42 42
43/**
44 * virtio_has_iommu_quirk - determine whether this device has the iommu quirk
45 * @vdev: the device
46 */
47static inline bool virtio_has_iommu_quirk(const struct virtio_device *vdev)
48{
49 /*
50 * Note the reverse polarity of the quirk feature (compared to most
51 * other features), this is for compatibility with legacy systems.
52 */
53 return !virtio_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
54}
55
43static inline bool virtio_is_little_endian(struct virtio_device *vdev) 56static inline bool virtio_is_little_endian(struct virtio_device *vdev)
44{ 57{
45 return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) || 58 return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) ||
diff --git a/tools/virtio/ringtest/ptr_ring.c b/tools/virtio/ringtest/ptr_ring.c
index 68e4f9f0da3a..bd2ad1d3b7a9 100644
--- a/tools/virtio/ringtest/ptr_ring.c
+++ b/tools/virtio/ringtest/ptr_ring.c
@@ -13,6 +13,7 @@
13#define cache_line_size() SMP_CACHE_BYTES 13#define cache_line_size() SMP_CACHE_BYTES
14#define ____cacheline_aligned_in_smp __attribute__ ((aligned (SMP_CACHE_BYTES))) 14#define ____cacheline_aligned_in_smp __attribute__ ((aligned (SMP_CACHE_BYTES)))
15#define unlikely(x) (__builtin_expect(!!(x), 0)) 15#define unlikely(x) (__builtin_expect(!!(x), 0))
16#define likely(x) (__builtin_expect(!!(x), 1))
16#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a)) 17#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
17typedef pthread_spinlock_t spinlock_t; 18typedef pthread_spinlock_t spinlock_t;
18 19
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index 4fde8c7dfcfe..77e6ccf14901 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -33,6 +33,7 @@
33static struct timecounter *timecounter; 33static struct timecounter *timecounter;
34static struct workqueue_struct *wqueue; 34static struct workqueue_struct *wqueue;
35static unsigned int host_vtimer_irq; 35static unsigned int host_vtimer_irq;
36static u32 host_vtimer_irq_flags;
36 37
37void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu) 38void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu)
38{ 39{
@@ -365,7 +366,7 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
365 366
366static void kvm_timer_init_interrupt(void *info) 367static void kvm_timer_init_interrupt(void *info)
367{ 368{
368 enable_percpu_irq(host_vtimer_irq, 0); 369 enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags);
369} 370}
370 371
371int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) 372int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value)
@@ -432,6 +433,14 @@ int kvm_timer_hyp_init(void)
432 } 433 }
433 host_vtimer_irq = info->virtual_irq; 434 host_vtimer_irq = info->virtual_irq;
434 435
436 host_vtimer_irq_flags = irq_get_trigger_type(host_vtimer_irq);
437 if (host_vtimer_irq_flags != IRQF_TRIGGER_HIGH &&
438 host_vtimer_irq_flags != IRQF_TRIGGER_LOW) {
439 kvm_err("Invalid trigger for IRQ%d, assuming level low\n",
440 host_vtimer_irq);
441 host_vtimer_irq_flags = IRQF_TRIGGER_LOW;
442 }
443
435 err = request_percpu_irq(host_vtimer_irq, kvm_arch_timer_handler, 444 err = request_percpu_irq(host_vtimer_irq, kvm_arch_timer_handler,
436 "kvm guest timer", kvm_get_running_vcpus()); 445 "kvm guest timer", kvm_get_running_vcpus());
437 if (err) { 446 if (err) {
diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c
index fb4b0a79a950..83777c1cbae0 100644
--- a/virt/kvm/arm/vgic/vgic-init.c
+++ b/virt/kvm/arm/vgic/vgic-init.c
@@ -73,12 +73,8 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
73 int i, vcpu_lock_idx = -1, ret; 73 int i, vcpu_lock_idx = -1, ret;
74 struct kvm_vcpu *vcpu; 74 struct kvm_vcpu *vcpu;
75 75
76 mutex_lock(&kvm->lock); 76 if (irqchip_in_kernel(kvm))
77 77 return -EEXIST;
78 if (irqchip_in_kernel(kvm)) {
79 ret = -EEXIST;
80 goto out;
81 }
82 78
83 /* 79 /*
84 * This function is also called by the KVM_CREATE_IRQCHIP handler, 80 * This function is also called by the KVM_CREATE_IRQCHIP handler,
@@ -87,10 +83,8 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
87 * the proper checks already. 83 * the proper checks already.
88 */ 84 */
89 if (type == KVM_DEV_TYPE_ARM_VGIC_V2 && 85 if (type == KVM_DEV_TYPE_ARM_VGIC_V2 &&
90 !kvm_vgic_global_state.can_emulate_gicv2) { 86 !kvm_vgic_global_state.can_emulate_gicv2)
91 ret = -ENODEV; 87 return -ENODEV;
92 goto out;
93 }
94 88
95 /* 89 /*
96 * Any time a vcpu is run, vcpu_load is called which tries to grab the 90 * Any time a vcpu is run, vcpu_load is called which tries to grab the
@@ -138,9 +132,6 @@ out_unlock:
138 vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx); 132 vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
139 mutex_unlock(&vcpu->mutex); 133 mutex_unlock(&vcpu->mutex);
140 } 134 }
141
142out:
143 mutex_unlock(&kvm->lock);
144 return ret; 135 return ret;
145} 136}
146 137
diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
index 07411cf967b9..4660a7d04eea 100644
--- a/virt/kvm/arm/vgic/vgic-its.c
+++ b/virt/kvm/arm/vgic/vgic-its.c
@@ -51,7 +51,7 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid)
51 51
52 irq = kzalloc(sizeof(struct vgic_irq), GFP_KERNEL); 52 irq = kzalloc(sizeof(struct vgic_irq), GFP_KERNEL);
53 if (!irq) 53 if (!irq)
54 return NULL; 54 return ERR_PTR(-ENOMEM);
55 55
56 INIT_LIST_HEAD(&irq->lpi_list); 56 INIT_LIST_HEAD(&irq->lpi_list);
57 INIT_LIST_HEAD(&irq->ap_list); 57 INIT_LIST_HEAD(&irq->ap_list);
@@ -441,39 +441,63 @@ static unsigned long vgic_mmio_read_its_idregs(struct kvm *kvm,
441 * Find the target VCPU and the LPI number for a given devid/eventid pair 441 * Find the target VCPU and the LPI number for a given devid/eventid pair
442 * and make this IRQ pending, possibly injecting it. 442 * and make this IRQ pending, possibly injecting it.
443 * Must be called with the its_lock mutex held. 443 * Must be called with the its_lock mutex held.
444 * Returns 0 on success, a positive error value for any ITS mapping
445 * related errors and negative error values for generic errors.
444 */ 446 */
445static void vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its, 447static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its,
446 u32 devid, u32 eventid) 448 u32 devid, u32 eventid)
447{ 449{
450 struct kvm_vcpu *vcpu;
448 struct its_itte *itte; 451 struct its_itte *itte;
449 452
450 if (!its->enabled) 453 if (!its->enabled)
451 return; 454 return -EBUSY;
452 455
453 itte = find_itte(its, devid, eventid); 456 itte = find_itte(its, devid, eventid);
454 /* Triggering an unmapped IRQ gets silently dropped. */ 457 if (!itte || !its_is_collection_mapped(itte->collection))
455 if (itte && its_is_collection_mapped(itte->collection)) { 458 return E_ITS_INT_UNMAPPED_INTERRUPT;
456 struct kvm_vcpu *vcpu; 459
457 460 vcpu = kvm_get_vcpu(kvm, itte->collection->target_addr);
458 vcpu = kvm_get_vcpu(kvm, itte->collection->target_addr); 461 if (!vcpu)
459 if (vcpu && vcpu->arch.vgic_cpu.lpis_enabled) { 462 return E_ITS_INT_UNMAPPED_INTERRUPT;
460 spin_lock(&itte->irq->irq_lock); 463
461 itte->irq->pending = true; 464 if (!vcpu->arch.vgic_cpu.lpis_enabled)
462 vgic_queue_irq_unlock(kvm, itte->irq); 465 return -EBUSY;
463 } 466
464 } 467 spin_lock(&itte->irq->irq_lock);
468 itte->irq->pending = true;
469 vgic_queue_irq_unlock(kvm, itte->irq);
470
471 return 0;
472}
473
474static struct vgic_io_device *vgic_get_its_iodev(struct kvm_io_device *dev)
475{
476 struct vgic_io_device *iodev;
477
478 if (dev->ops != &kvm_io_gic_ops)
479 return NULL;
480
481 iodev = container_of(dev, struct vgic_io_device, dev);
482
483 if (iodev->iodev_type != IODEV_ITS)
484 return NULL;
485
486 return iodev;
465} 487}
466 488
467/* 489/*
468 * Queries the KVM IO bus framework to get the ITS pointer from the given 490 * Queries the KVM IO bus framework to get the ITS pointer from the given
469 * doorbell address. 491 * doorbell address.
470 * We then call vgic_its_trigger_msi() with the decoded data. 492 * We then call vgic_its_trigger_msi() with the decoded data.
493 * According to the KVM_SIGNAL_MSI API description returns 1 on success.
471 */ 494 */
472int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi) 495int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)
473{ 496{
474 u64 address; 497 u64 address;
475 struct kvm_io_device *kvm_io_dev; 498 struct kvm_io_device *kvm_io_dev;
476 struct vgic_io_device *iodev; 499 struct vgic_io_device *iodev;
500 int ret;
477 501
478 if (!vgic_has_its(kvm)) 502 if (!vgic_has_its(kvm))
479 return -ENODEV; 503 return -ENODEV;
@@ -485,15 +509,28 @@ int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)
485 509
486 kvm_io_dev = kvm_io_bus_get_dev(kvm, KVM_MMIO_BUS, address); 510 kvm_io_dev = kvm_io_bus_get_dev(kvm, KVM_MMIO_BUS, address);
487 if (!kvm_io_dev) 511 if (!kvm_io_dev)
488 return -ENODEV; 512 return -EINVAL;
489 513
490 iodev = container_of(kvm_io_dev, struct vgic_io_device, dev); 514 iodev = vgic_get_its_iodev(kvm_io_dev);
515 if (!iodev)
516 return -EINVAL;
491 517
492 mutex_lock(&iodev->its->its_lock); 518 mutex_lock(&iodev->its->its_lock);
493 vgic_its_trigger_msi(kvm, iodev->its, msi->devid, msi->data); 519 ret = vgic_its_trigger_msi(kvm, iodev->its, msi->devid, msi->data);
494 mutex_unlock(&iodev->its->its_lock); 520 mutex_unlock(&iodev->its->its_lock);
495 521
496 return 0; 522 if (ret < 0)
523 return ret;
524
525 /*
526 * KVM_SIGNAL_MSI demands a return value > 0 for success and 0
527 * if the guest has blocked the MSI. So we map any LPI mapping
528 * related error to that.
529 */
530 if (ret)
531 return 0;
532 else
533 return 1;
497} 534}
498 535
499/* Requires the its_lock to be held. */ 536/* Requires the its_lock to be held. */
@@ -502,7 +539,8 @@ static void its_free_itte(struct kvm *kvm, struct its_itte *itte)
502 list_del(&itte->itte_list); 539 list_del(&itte->itte_list);
503 540
504 /* This put matches the get in vgic_add_lpi. */ 541 /* This put matches the get in vgic_add_lpi. */
505 vgic_put_irq(kvm, itte->irq); 542 if (itte->irq)
543 vgic_put_irq(kvm, itte->irq);
506 544
507 kfree(itte); 545 kfree(itte);
508} 546}
@@ -697,6 +735,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,
697 struct its_device *device; 735 struct its_device *device;
698 struct its_collection *collection, *new_coll = NULL; 736 struct its_collection *collection, *new_coll = NULL;
699 int lpi_nr; 737 int lpi_nr;
738 struct vgic_irq *irq;
700 739
701 device = find_its_device(its, device_id); 740 device = find_its_device(its, device_id);
702 if (!device) 741 if (!device)
@@ -710,6 +749,10 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,
710 lpi_nr >= max_lpis_propbaser(kvm->arch.vgic.propbaser)) 749 lpi_nr >= max_lpis_propbaser(kvm->arch.vgic.propbaser))
711 return E_ITS_MAPTI_PHYSICALID_OOR; 750 return E_ITS_MAPTI_PHYSICALID_OOR;
712 751
752 /* If there is an existing mapping, behavior is UNPREDICTABLE. */
753 if (find_itte(its, device_id, event_id))
754 return 0;
755
713 collection = find_collection(its, coll_id); 756 collection = find_collection(its, coll_id);
714 if (!collection) { 757 if (!collection) {
715 int ret = vgic_its_alloc_collection(its, &collection, coll_id); 758 int ret = vgic_its_alloc_collection(its, &collection, coll_id);
@@ -718,22 +761,28 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,
718 new_coll = collection; 761 new_coll = collection;
719 } 762 }
720 763
721 itte = find_itte(its, device_id, event_id); 764 itte = kzalloc(sizeof(struct its_itte), GFP_KERNEL);
722 if (!itte) { 765 if (!itte) {
723 itte = kzalloc(sizeof(struct its_itte), GFP_KERNEL); 766 if (new_coll)
724 if (!itte) { 767 vgic_its_free_collection(its, coll_id);
725 if (new_coll) 768 return -ENOMEM;
726 vgic_its_free_collection(its, coll_id);
727 return -ENOMEM;
728 }
729
730 itte->event_id = event_id;
731 list_add_tail(&itte->itte_list, &device->itt_head);
732 } 769 }
733 770
771 itte->event_id = event_id;
772 list_add_tail(&itte->itte_list, &device->itt_head);
773
734 itte->collection = collection; 774 itte->collection = collection;
735 itte->lpi = lpi_nr; 775 itte->lpi = lpi_nr;
736 itte->irq = vgic_add_lpi(kvm, lpi_nr); 776
777 irq = vgic_add_lpi(kvm, lpi_nr);
778 if (IS_ERR(irq)) {
779 if (new_coll)
780 vgic_its_free_collection(its, coll_id);
781 its_free_itte(kvm, itte);
782 return PTR_ERR(irq);
783 }
784 itte->irq = irq;
785
737 update_affinity_itte(kvm, itte); 786 update_affinity_itte(kvm, itte);
738 787
739 /* 788 /*
@@ -981,9 +1030,7 @@ static int vgic_its_cmd_handle_int(struct kvm *kvm, struct vgic_its *its,
981 u32 msi_data = its_cmd_get_id(its_cmd); 1030 u32 msi_data = its_cmd_get_id(its_cmd);
982 u64 msi_devid = its_cmd_get_deviceid(its_cmd); 1031 u64 msi_devid = its_cmd_get_deviceid(its_cmd);
983 1032
984 vgic_its_trigger_msi(kvm, its, msi_devid, msi_data); 1033 return vgic_its_trigger_msi(kvm, its, msi_devid, msi_data);
985
986 return 0;
987} 1034}
988 1035
989/* 1036/*
@@ -1288,13 +1335,13 @@ void vgic_enable_lpis(struct kvm_vcpu *vcpu)
1288 its_sync_lpi_pending_table(vcpu); 1335 its_sync_lpi_pending_table(vcpu);
1289} 1336}
1290 1337
1291static int vgic_its_init_its(struct kvm *kvm, struct vgic_its *its) 1338static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its)
1292{ 1339{
1293 struct vgic_io_device *iodev = &its->iodev; 1340 struct vgic_io_device *iodev = &its->iodev;
1294 int ret; 1341 int ret;
1295 1342
1296 if (its->initialized) 1343 if (!its->initialized)
1297 return 0; 1344 return -EBUSY;
1298 1345
1299 if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) 1346 if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base))
1300 return -ENXIO; 1347 return -ENXIO;
@@ -1311,9 +1358,6 @@ static int vgic_its_init_its(struct kvm *kvm, struct vgic_its *its)
1311 KVM_VGIC_V3_ITS_SIZE, &iodev->dev); 1358 KVM_VGIC_V3_ITS_SIZE, &iodev->dev);
1312 mutex_unlock(&kvm->slots_lock); 1359 mutex_unlock(&kvm->slots_lock);
1313 1360
1314 if (!ret)
1315 its->initialized = true;
1316
1317 return ret; 1361 return ret;
1318} 1362}
1319 1363
@@ -1435,9 +1479,6 @@ static int vgic_its_set_attr(struct kvm_device *dev,
1435 if (type != KVM_VGIC_ITS_ADDR_TYPE) 1479 if (type != KVM_VGIC_ITS_ADDR_TYPE)
1436 return -ENODEV; 1480 return -ENODEV;
1437 1481
1438 if (its->initialized)
1439 return -EBUSY;
1440
1441 if (copy_from_user(&addr, uaddr, sizeof(addr))) 1482 if (copy_from_user(&addr, uaddr, sizeof(addr)))
1442 return -EFAULT; 1483 return -EFAULT;
1443 1484
@@ -1453,7 +1494,9 @@ static int vgic_its_set_attr(struct kvm_device *dev,
1453 case KVM_DEV_ARM_VGIC_GRP_CTRL: 1494 case KVM_DEV_ARM_VGIC_GRP_CTRL:
1454 switch (attr->attr) { 1495 switch (attr->attr) {
1455 case KVM_DEV_ARM_VGIC_CTRL_INIT: 1496 case KVM_DEV_ARM_VGIC_CTRL_INIT:
1456 return vgic_its_init_its(dev->kvm, its); 1497 its->initialized = true;
1498
1499 return 0;
1457 } 1500 }
1458 break; 1501 break;
1459 } 1502 }
@@ -1498,3 +1541,30 @@ int kvm_vgic_register_its_device(void)
1498 return kvm_register_device_ops(&kvm_arm_vgic_its_ops, 1541 return kvm_register_device_ops(&kvm_arm_vgic_its_ops,
1499 KVM_DEV_TYPE_ARM_VGIC_ITS); 1542 KVM_DEV_TYPE_ARM_VGIC_ITS);
1500} 1543}
1544
1545/*
1546 * Registers all ITSes with the kvm_io_bus framework.
1547 * To follow the existing VGIC initialization sequence, this has to be
1548 * done as late as possible, just before the first VCPU runs.
1549 */
1550int vgic_register_its_iodevs(struct kvm *kvm)
1551{
1552 struct kvm_device *dev;
1553 int ret = 0;
1554
1555 list_for_each_entry(dev, &kvm->devices, vm_node) {
1556 if (dev->ops != &kvm_arm_vgic_its_ops)
1557 continue;
1558
1559 ret = vgic_register_its_iodev(kvm, dev->private);
1560 if (ret)
1561 return ret;
1562 /*
1563 * We don't need to care about tearing down previously
1564 * registered ITSes, as the kvm_io_bus framework removes
1565 * them for us if the VM gets destroyed.
1566 */
1567 }
1568
1569 return ret;
1570}
diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c
index ff668e0dd586..90d81811fdda 100644
--- a/virt/kvm/arm/vgic/vgic-mmio-v3.c
+++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c
@@ -306,16 +306,19 @@ static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu,
306{ 306{
307 struct vgic_dist *dist = &vcpu->kvm->arch.vgic; 307 struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
308 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 308 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
309 u64 propbaser = dist->propbaser; 309 u64 old_propbaser, propbaser;
310 310
311 /* Storing a value with LPIs already enabled is undefined */ 311 /* Storing a value with LPIs already enabled is undefined */
312 if (vgic_cpu->lpis_enabled) 312 if (vgic_cpu->lpis_enabled)
313 return; 313 return;
314 314
315 propbaser = update_64bit_reg(propbaser, addr & 4, len, val); 315 do {
316 propbaser = vgic_sanitise_propbaser(propbaser); 316 old_propbaser = dist->propbaser;
317 317 propbaser = old_propbaser;
318 dist->propbaser = propbaser; 318 propbaser = update_64bit_reg(propbaser, addr & 4, len, val);
319 propbaser = vgic_sanitise_propbaser(propbaser);
320 } while (cmpxchg64(&dist->propbaser, old_propbaser,
321 propbaser) != old_propbaser);
319} 322}
320 323
321static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu, 324static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu,
@@ -331,16 +334,19 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu,
331 unsigned long val) 334 unsigned long val)
332{ 335{
333 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 336 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
334 u64 pendbaser = vgic_cpu->pendbaser; 337 u64 old_pendbaser, pendbaser;
335 338
336 /* Storing a value with LPIs already enabled is undefined */ 339 /* Storing a value with LPIs already enabled is undefined */
337 if (vgic_cpu->lpis_enabled) 340 if (vgic_cpu->lpis_enabled)
338 return; 341 return;
339 342
340 pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); 343 do {
341 pendbaser = vgic_sanitise_pendbaser(pendbaser); 344 old_pendbaser = vgic_cpu->pendbaser;
342 345 pendbaser = old_pendbaser;
343 vgic_cpu->pendbaser = pendbaser; 346 pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val);
347 pendbaser = vgic_sanitise_pendbaser(pendbaser);
348 } while (cmpxchg64(&vgic_cpu->pendbaser, old_pendbaser,
349 pendbaser) != old_pendbaser);
344} 350}
345 351
346/* 352/*
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c
index 0506543df38a..9f0dae397d9c 100644
--- a/virt/kvm/arm/vgic/vgic-v3.c
+++ b/virt/kvm/arm/vgic/vgic-v3.c
@@ -289,6 +289,14 @@ int vgic_v3_map_resources(struct kvm *kvm)
289 goto out; 289 goto out;
290 } 290 }
291 291
292 if (vgic_has_its(kvm)) {
293 ret = vgic_register_its_iodevs(kvm);
294 if (ret) {
295 kvm_err("Unable to register VGIC ITS MMIO regions\n");
296 goto out;
297 }
298 }
299
292 dist->ready = true; 300 dist->ready = true;
293 301
294out: 302out:
diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c
index e7aeac719e09..e83b7fe4baae 100644
--- a/virt/kvm/arm/vgic/vgic.c
+++ b/virt/kvm/arm/vgic/vgic.c
@@ -117,17 +117,17 @@ static void vgic_irq_release(struct kref *ref)
117 117
118void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) 118void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq)
119{ 119{
120 struct vgic_dist *dist; 120 struct vgic_dist *dist = &kvm->arch.vgic;
121 121
122 if (irq->intid < VGIC_MIN_LPI) 122 if (irq->intid < VGIC_MIN_LPI)
123 return; 123 return;
124 124
125 if (!kref_put(&irq->refcount, vgic_irq_release)) 125 spin_lock(&dist->lpi_list_lock);
126 if (!kref_put(&irq->refcount, vgic_irq_release)) {
127 spin_unlock(&dist->lpi_list_lock);
126 return; 128 return;
129 };
127 130
128 dist = &kvm->arch.vgic;
129
130 spin_lock(&dist->lpi_list_lock);
131 list_del(&irq->lpi_list); 131 list_del(&irq->lpi_list);
132 dist->lpi_list_count--; 132 dist->lpi_list_count--;
133 spin_unlock(&dist->lpi_list_lock); 133 spin_unlock(&dist->lpi_list_lock);
diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h
index 1d8e21d5c13f..6c4625c46368 100644
--- a/virt/kvm/arm/vgic/vgic.h
+++ b/virt/kvm/arm/vgic/vgic.h
@@ -84,6 +84,7 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu);
84int vgic_v3_probe(const struct gic_kvm_info *info); 84int vgic_v3_probe(const struct gic_kvm_info *info);
85int vgic_v3_map_resources(struct kvm *kvm); 85int vgic_v3_map_resources(struct kvm *kvm);
86int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address); 86int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address);
87int vgic_register_its_iodevs(struct kvm *kvm);
87bool vgic_has_its(struct kvm *kvm); 88bool vgic_has_its(struct kvm *kvm);
88int kvm_vgic_register_its_device(void); 89int kvm_vgic_register_its_device(void);
89void vgic_enable_lpis(struct kvm_vcpu *vcpu); 90void vgic_enable_lpis(struct kvm_vcpu *vcpu);
@@ -140,6 +141,11 @@ static inline int vgic_register_redist_iodevs(struct kvm *kvm,
140 return -ENODEV; 141 return -ENODEV;
141} 142}
142 143
144static inline int vgic_register_its_iodevs(struct kvm *kvm)
145{
146 return -ENODEV;
147}
148
143static inline bool vgic_has_its(struct kvm *kvm) 149static inline bool vgic_has_its(struct kvm *kvm)
144{ 150{
145 return false; 151 return false;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cc081ccfcaa3..195078225aa5 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -696,6 +696,11 @@ static void kvm_destroy_devices(struct kvm *kvm)
696{ 696{
697 struct kvm_device *dev, *tmp; 697 struct kvm_device *dev, *tmp;
698 698
699 /*
700 * We do not need to take the kvm->lock here, because nobody else
701 * has a reference to the struct kvm at this point and therefore
702 * cannot access the devices list anyhow.
703 */
699 list_for_each_entry_safe(dev, tmp, &kvm->devices, vm_node) { 704 list_for_each_entry_safe(dev, tmp, &kvm->devices, vm_node) {
700 list_del(&dev->vm_node); 705 list_del(&dev->vm_node);
701 dev->ops->destroy(dev); 706 dev->ops->destroy(dev);
@@ -2832,19 +2837,28 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
2832 dev->ops = ops; 2837 dev->ops = ops;
2833 dev->kvm = kvm; 2838 dev->kvm = kvm;
2834 2839
2840 mutex_lock(&kvm->lock);
2835 ret = ops->create(dev, cd->type); 2841 ret = ops->create(dev, cd->type);
2836 if (ret < 0) { 2842 if (ret < 0) {
2843 mutex_unlock(&kvm->lock);
2837 kfree(dev); 2844 kfree(dev);
2838 return ret; 2845 return ret;
2839 } 2846 }
2847 list_add(&dev->vm_node, &kvm->devices);
2848 mutex_unlock(&kvm->lock);
2849
2850 if (ops->init)
2851 ops->init(dev);
2840 2852
2841 ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC); 2853 ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);
2842 if (ret < 0) { 2854 if (ret < 0) {
2843 ops->destroy(dev); 2855 ops->destroy(dev);
2856 mutex_lock(&kvm->lock);
2857 list_del(&dev->vm_node);
2858 mutex_unlock(&kvm->lock);
2844 return ret; 2859 return ret;
2845 } 2860 }
2846 2861
2847 list_add(&dev->vm_node, &kvm->devices);
2848 kvm_get_kvm(kvm); 2862 kvm_get_kvm(kvm);
2849 cd->fd = ret; 2863 cd->fd = ret;
2850 return 0; 2864 return 0;